UNPKG

@tangle.js/anchors

Version:

Anchoring messages to the Tangle. Powered by IOTA Streams

140 lines (139 loc) 4.15 kB
/// <reference types="node" /> import { IAnchoringResult } from "./models/IAnchoringResult"; import { IChannelDetails } from "./models/IChannelDetails"; import { IChannelOptions } from "./models/IChannelOptions"; import { IFetchResult } from "./models/IFetchResult"; export declare class IotaAnchoringChannel { static readonly DEFAULT_NODE = "https://chrysalis-nodes.iota.org"; private readonly _channelID; private readonly _node; private _seed; private readonly _channelAddress; private readonly _announceMsgID; private _subscriber; private readonly _authorPubKey; private _subscriberPubKey; private constructor(); /** * Creates a new Anchoring Channel * * @param seed Author's seed * @param options The options * @param options.node The node used to create the channel * * @returns The anchoring channel details */ static create(seed: string, options?: IChannelOptions): Promise<IChannelDetails>; /** * Instantiates an existing Anchoring Channel from a Channel ID * * @param channelID in the form of 'channel_address:announce_msg_id' * @param options Channel options * * @returns reference to the channel * */ static fromID(channelID: string, options?: IChannelOptions): IotaAnchoringChannel; /** * Creates a new IotaAnchoringChannel and subscribes to it using the Author's seed * * i.e. Author === Subscriber * A new Seed is automatically generated * * @param options The channel creation options * @returns The Anchoring Channel */ static bindNew(options?: IChannelOptions): Promise<IotaAnchoringChannel>; /** * Binds the channel so that the subscriber is instantiated using the seed passed as parameter * * @param seed The Subscriber (publisher) seed * @returns a Reference to the channel * */ bind(seed: string): Promise<IotaAnchoringChannel>; /** * Returns the channelID ('channelAddress:announce_msg_id') * * @returns channel ID * */ get channelID(): string; /** * Returns the channel's address * * @returns channel address * */ get channelAddr(): string; /** * Returns the channel's first anchorage ID * * @returns anchorageID * */ get firstAnchorageID(): string; /** * Returns the channel's node * * @returns node * */ get node(): string; /** * Returns the channel's publisher seed * * @returns seed * */ get seed(): string; /** * Returns the channel's author Public Key * * @returns the Author's Public key * */ get authorPubKey(): string; /** * Returns the channel's publisher Public Key * * @returns the publisher's Public key * */ get subscriberPubKey(): string; /** * Anchors a message to the anchoring channel * * @param message Message to be anchored * @param anchorageID The anchorage to be used * * @returns The result of the operation * */ anchor(message: Buffer, anchorageID: string): Promise<IAnchoringResult>; /** * Fetches a previously anchored message * * @param anchorageID The anchorage point * @param messageID The expected ID of the anchored message * * @returns The fetch result */ fetch(anchorageID: string, messageID?: string): Promise<IFetchResult>; /** * Fetches the next message anchored to the channel * * @returns The fetch result or undefined if no more messages can be fetched */ fetchNext(): Promise<IFetchResult | undefined>; /** * Receives a previously anchored message * provided its anchorage has already been seen on the channel * * @param messageID The ID of the message * @param anchorageID The expected ID of message's anchorage * * @returns The message received and associated metadata */ receive(messageID: string, anchorageID?: string): Promise<IFetchResult>; }