Postal Services over Swarm (Pss) API
Installation
npm install @erebos/api-pss
Usage
import { Pss } from '@erebos/api-pss'
import { createRPC } from '@erebos/rpc-ws-browser'
// or
import { createRPC } from '@erebos/rpc-ws-node'
// or any other StreamRPC factory
const rpc = createRPC('ws://localhost:8546')
const pss = new Pss(rpc)
Interfaces and types
hexInput
Input value supported by the Hex class exported by the @erebos/hex package.
hexValue
Hexadecimal-encoded string prefixed with 0x. This type is exported by the @erebos/hex package.
Hex
Hex class instance as exported by the @erebos/hex package.
PssEvent
interface PssEvent {
key?: hexValue
msg: Hex
}
Constants
EMPTY_ADDRESS
hexValue of the empty address (0x), can be used to broadcast a message to the entire network.
Pss class
new Pss()
Creates a Pss instance using the provided StreamRPC instance.
Arguments
rpc: StreamRPC
.baseAddr()
Calls pss_baseAddr.
Returns Promise<hexValue>
.getPublicKey()
Calls pss_getPublicKey.
Returns Promise<hexValue>
.sendAsym()
Calls pss_sendAsym with the provided arguments:
Arguments
key: string: public key of the peertopic: string: destination topicmessage: Hex | hexInput
Returns Promise<void>
.sendSym()
Calls pss_sendSym with the provided arguments:
Arguments
keyID: hexValue: symmetric key ID generated usingsetSymmetricKey()topic: hexValue: destination topicmessage: Hex | hexInput
Returns Promise<void>
.sendRaw()
Calls pss_sendRaw with the provided arguments:
Arguments
address: hexValue: full or partial peer addresstopic: hexValue: destination topicmessage: Hex | hexInput
Returns Promise<void>
.setPeerPublicKey()
Calls pss_setPeerPublicKey with the provided arguments:
Arguments
key: hexValue: public key of the peertopic: hexValueaddress: hexValue
Returns Promise<void>
.setSymmetricKey()
Calls pss_setSymmetricKey with the provided arguments:
Arguments
key: hexValue: public key of the peertopic: hexValueaddress: hexValueuseForDecryption: boolean = false
Returns Promise<string>
.stringToTopic()
Calls pss_stringToTopic with the provided string and returns the generated topic.
Arguments
str: string
Returns Promise<string>
.subscribeTopic()
Calls pss_subscribe with the provided topic and returns the subscription handle.
Arguments
topic: hexValuehandleRawMessages?: boolean = false
Returns Promise<hexValue>
.createSubscription()
Creates a RxJS Observable that will emit events matching the provided subscription handle as created by calling subscribeTopic() once subscribed to.
Arguments
subscription: hexValue
Returns Observable<PssEvent>
.createTopicSubscription()
Shortcut for calling subscribeTopic() followed by createSubscription().
Arguments
topic: hexValuehandleRawMessages?: boolean
Returns Promise<Observable<PssEvent>>
