erebos

erebos

  • Docs
  • Examples
  • API
  • Help
  • GitHub

›Timeline protocol

Docs

  • Introduction
  • Getting started

Swarm examples

  • File storage examples
  • Feeds examples
  • Communications examples

Swarm APIs and CLI

  • Swarm client
  • Individual APIs
  • Bzz API
  • Bzz Feed API
  • Bzz FS API
  • Pss API
  • CLI

Data structures

  • Data structures
  • Feed lists
  • Document synchronization
  • Timeline

Timeline protocol

  • Timeline specification
  • Timeline example
  • Timeline API

Utility libraries

  • Hexadecimal encoding
  • Keccak256 hashing
  • SECP256k1 signing
  • Hierarchical Deterministic wallet

RPC tools

  • RPC clients, handler and transport
  • Base RPC class and types
  • RPC Errors
  • RequestRPC client (stateless)
  • StreamRPC client (stateful)
  • RPC handler
  • RPC client over HTTP
  • RPC client over WebSocket
  • RPC client over IPC
  • RPC client for browsers
  • RPC client for Node
  • RPC client for Electron
  • HTTP transport
  • WebSocket transport
  • IPC transport
  • Electron transport
Edit

Timeline example

Asynchronous messaging

import { BzzFeed } from '@erebos/bzz-feed'
import { BzzNode } from '@erebos/bzz-node'
import { pubKeyToAddress } from '@erebos/keccak256'
import { createKeyPair, sign } from '@erebos/secp256k1'
import { TimelineReader, TimelineWriter } from '@erebos/timeline'

const BZZ_URL = 'http://localhost:8500'
const FEED_NAME = 'alice-bob'

// This setup is meant for demonstration purpose only - keys and signatures security must be handled by the application
const keyPair = createKeyPair()
const signBytes = async bytes => sign(bytes, keyPair)
const bzz = new BzzNode({ url: BZZ_URL })
const bzzFeed = new BzzFeed({ bzz, signBytes })

// In this example we are Alice communicating with Bob
const aliceAddress = pubKeyToAddress(keyPair.getPublic('array'))
const aliceTimeline = new TimelineWriter({
  bzz: bzzFeed,
  feed: { user: aliceAddress, name: FEED_NAME },
})

// The provided metadata will be added to each message
const aliceSend = aliceTimeline.createAddChapter({
  author: aliceAddress,
  type: 'text/plain',
})
// Alice will be able to add messages to her timeline calling this function, it simply abstracts away the underlying Chapter data structure that the updater uses
const sendMessage = async content => {
  await aliceSend({ content })
}

// Alice's address must be known by Bob
const bobTimeline = new TimelineReader({
  bzz: bzzFeed,
  feed: { user: aliceAddress, name: FEED_NAME },
})

// This creates an AsyncIterator that can be used to retrieve previous messages in the timeline
const getPreviousMessage = bobTimeline.createIterator()

// Listen to new messages added to Bob's timeline reader
const bobsNewMessages = bobTimeline
  .live({ interval: 10000 }) // 10 seconds
  .subscribe(chapters => {
    chapters.forEach(c => {
      console.log(`New message from Alice: ${c.content}`)
    })
  })

const getMessageAndSayHello = async () => {
  // Iteration is performed in reverse chronological order
  const latestMessage = await getPreviousMessage.next()
  if (latestMessage != null) {
    console.log(`Latest message from Alice: ${c.content}`)
  }
  await sendMessage('Hello!')
}
← Timeline specificationTimeline API →
  • Asynchronous messaging
Docs
Getting StartedAPI ReferenceCLI
Community
Gitter chatGitHub repositoryStar
Swarm
Official documentationHTTP gatewayDevelopment chat