UNPKG

@anythread/gsoc

Version:

Graffiti Several Owner Chunk implementation on Swarm network

99 lines (98 loc) 3.96 kB
import { SubscriptionHandler } from './http-client'; import { SingleOwnerChunk } from './soc'; import { Bytes, HexString, PostageBatchId, PostageStamp } from './types'; export declare const DEFAULT_RESOURCE_ID = "any"; /** * InformationSignal is for reading and writing a GSOC topic */ export declare class InformationSignal<UserPayload = InformationSignalRecord> { postage: PostageBatchId | PostageStamp; private beeApiUrl; /** Graffiti Identifier */ private consensusHash; private assertGraffitiRecord; constructor(beeApiUrl: string, options?: BaseConstructorOptions<UserPayload>); /** * Subscribe to messages for given topic with GSOC * * **Warning! If connected Bee node is a light node, then it will never receive any message!** * This is because light nodes does not fully participate in the data exchange in Swarm network and hence the message won't arrive to them. * * @param messageHandler hook function on newly received messages * @param resourceID the common topic for the GSOC records. It can be a hex string without 0x prefix to have it without conversation. * @returns close() function on websocket connection and GSOC address */ subscribe(messageHandler: SubscriptionHandler<UserPayload>, resourceId?: string | Uint8Array): { close: () => void; gsocAddress: Bytes<32>; }; /** * Same as subscribe() method but with different name */ listen(messageHandler: SubscriptionHandler<UserPayload>, resourceId?: string | Uint8Array): { close: () => void; gsocAddress: Bytes<32>; }; /** * Write GSOC and upload to the Swarm network * * @param data GSOC payload * @param resourceID the common topic for the GSOC records. It can be a hex string without 0x prefix to have it without conversation. */ write(data: UserPayload, resourceId?: string | Uint8Array): Promise<SingleOwnerChunk>; /** * Same as write() method but with different name */ send(data: UserPayload, resourceId?: string | Uint8Array): Promise<SingleOwnerChunk>; /** * Mine the resource ID respect to the given address of Bee node and storage depth * so that the GSOC will fall within the neighborhood of the Bee node. * * @param beeAddress Bee node 32 bytes address * @param storageDepth the depth of the storage on Swarm network * @returns mined resource ID and GSOC address */ mineResourceId(beeAddress: Uint8Array | HexString, storageDepth: number): { resourceId: Bytes<32>; gsocAddress: Bytes<32>; }; /** * Same as mineResourceId() method but with different name */ mine(beeAddress: Uint8Array | HexString, storageDepth: number): { resourceId: Bytes<32>; gsocAddress: Bytes<32>; }; } type InformationSignalRecord = string; interface BaseConstructorOptions<T = InformationSignalRecord> { consensus?: { /** * The used consensus identifier of the GraffitiFeed * Default: AnyThread:v1 */ id: string; /** * Assertion function that throws an error if the parameter * does not satisfy the structural requirements. * record formats: * - PersonalStorageSignal: record in the personal storage. * - InformationSignal: record in the graffiti feed. * Default: assertAnyThreadComment * @param unknown any object for asserting */ assertRecord: (unknown: unknown) => asserts unknown is T; }; /** * Swarm Postage Batch ID which is only required when write happens * It can be the serialized Postage Stamp as well (envelope API EP) * Default: 000000000000000000000000000000000000000000000 */ postage?: string; /** * API Url of the Ethereum Swarm Bee client * Default: http://localhost:1633 */ beeApiUrl?: string; } export {};