import 'reflect-metadata'; import './utils/PatchTsyringe'; import { ProxyDirection } from '@streamr/protocol'; import { EthereumAddress } from '@streamr/utils'; import { PublishMetadata } from '../src/publish/Publisher'; import { StreamrClientConfig } from './Config'; import { Message } from './Message'; import { NetworkNodeStub } from './NetworkNodeFacade'; import { Stream, StreamMetadata } from './Stream'; import { GroupKey } from './encryption/GroupKey'; import { UpdateEncryptionKeyOptions } from './encryption/LocalGroupKeyStore'; import { StreamrClientEvents } from './events'; import { PermissionAssignment, PermissionQuery } from './permission'; import { StorageNodeMetadata } from './registry/StorageNodeRegistry'; import { SearchStreamsOrderBy, SearchStreamsPermissionFilter } from './registry/searchStreams'; import { MessageListener, MessageStream } from './subscribe/MessageStream'; import { ResendOptions } from './subscribe/Resends'; import { Subscription } from './subscribe/Subscription'; import { StreamDefinition } from './types'; export type SubscribeOptions = StreamDefinition & ExtraSubscribeOptions; export interface ExtraSubscribeOptions { resend?: ResendOptions; /** * Subscribe raw with validation, permission checking, ordering, gap filling, * and decryption _disabled_. */ raw?: boolean; } /** * The main API used to interact with Streamr. * * @category Important */ export declare class StreamrClient { static readonly generateEthereumAccount: () => { address: string; privateKey: string; }; readonly id: string; private readonly publisher; private readonly subscriber; private readonly resends; private readonly node; private readonly streamRegistry; private readonly streamStorageRegistry; private readonly storageNodeRegistry; private readonly localGroupKeyStore; private readonly streamIdBuilder; private readonly config; private readonly authentication; private readonly eventEmitter; private readonly destroySignal; private readonly loggerFactory; constructor(config?: StreamrClientConfig, /** @internal */ parentContainer?: import("tsyringe").DependencyContainer); /** * Publishes a message to a stream partition in the network. * * @category Important * * @param streamDefinition - the stream or stream partition to publish the message to * @param content - the content (the payload) of the message (must be JSON serializable) * @param metadata - provide additional metadata to be included in the message or to control the publishing process * @returns the published message (note: the field {@link Message.content} is encrypted if the stream is private) */ publish(streamDefinition: StreamDefinition, content: unknown, metadata?: PublishMetadata): Promise; /** * Manually updates the encryption key used when publishing messages to a given stream. */ updateEncryptionKey(opts: UpdateEncryptionKeyOptions): Promise; /** * Adds an encryption key for a given publisher to the key store. * * @remarks Keys will be added to the store automatically by the client as encountered. This method can be used to * manually add some known keys into the store. */ addEncryptionKey(key: GroupKey, publisherId: EthereumAddress): Promise; /** * Subscribes to a stream partition in the network. * * @category Important * * @param options - the stream or stream partition to subscribe to, * additionally a resend can be performed by providing resend options * @param onMessage - callback will be invoked for each message received in subscription * @returns a {@link Subscription} that can be used to manage the subscription etc. */ subscribe(options: SubscribeOptions, onMessage?: MessageListener): Promise; /** * Unsubscribes from streams or stream partitions in the network. * * @remarks no-op if subscription does not exist * * @category Important * * @param streamDefinitionOrSubscription - leave as `undefined` to unsubscribe from all existing subscriptions. */ unsubscribe(streamDefinitionOrSubscription?: StreamDefinition | Subscription): Promise; /** * Returns a list of subscriptions matching the given criteria. * * @category Important * * @param streamDefinition - leave as `undefined` to get all subscriptions */ getSubscriptions(streamDefinition?: StreamDefinition): Promise; /** * Performs a resend of stored historical data. * * @category Important * * @param streamDefinition - the stream partition for which data should be resent * @param options - defines the kind of resend that should be performed * @param onMessage - callback will be invoked for each message retrieved * @returns a {@link MessageStream} that provides an alternative way of iterating messages. Rejects if the stream is * not stored (i.e. is not assigned to a storage node). */ resend(streamDefinition: StreamDefinition, options: ResendOptions, onMessage?: MessageListener): Promise; /** * Waits for a message to be stored by a storage node. * * @param message - the message to be awaited for * @param options - additional options for controlling waiting and message matching * @returns rejects if message was found in storage before timeout */ waitForStorage(message: Message, options?: { /** * Determines how often should storage node be polled. */ interval?: number; /** * Timeout after which to give up if message was not seen. */ timeout?: number; /** * Controls size of internal resend used in polling. */ count?: number; }): Promise; /** * Gets a stream. * * @category Important * * @returns rejects if the stream is not found */ getStream(streamIdOrPath: string): Promise; /** * Creates a new stream. * * @category Important * * @param propsOrStreamIdOrPath - the stream id to be used for the new stream, and optionally, any * associated metadata * * @remarks when creating a stream with an ENS domain, the returned promise can take several minutes to settle */ createStream(propsOrStreamIdOrPath: Partial & { id: string; } | string): Promise; /** * Gets a stream, creating one if it does not exist. * * @category Important * * @param props - the stream id to get or create. Field `partitions` is only used if creating the stream. * * @remarks when creating a stream with an ENS domain, the returned promise can take several minutes to settle */ getOrCreateStream(props: { id: string; partitions?: number; }): Promise; /** * Updates the metadata of a stream. * * @param props - the stream id and the metadata fields to be updated */ updateStream(props: Partial & { id: string; }): Promise; /** * Deletes a stream. */ deleteStream(streamIdOrPath: string): Promise; /** * Searches for streams based on given criteria. * * @param term - a search term that should be part of the stream id of a result * @param permissionFilter - permissions that should be in effect for a result * @param orderBy - the default is ascending order by stream id field */ searchStreams(term: string | undefined, permissionFilter: SearchStreamsPermissionFilter | undefined, orderBy?: SearchStreamsOrderBy): AsyncIterable; /** * Gets all ethereum addresses that have {@link StreamPermission.PUBLISH} permission to the stream. */ getStreamPublishers(streamIdOrPath: string): AsyncIterable; /** * Gets all ethereum addresses that have {@link StreamPermission.SUBSCRIBE} permission to the stream. */ getStreamSubscribers(streamIdOrPath: string): AsyncIterable; /** * Checks whether the given permission is in effect. */ hasPermission(query: PermissionQuery): Promise; /** * Returns the list of all permissions in effect for a given stream. */ getPermissions(streamIdOrPath: string): Promise; /** * Grants permissions on a given stream. */ grantPermissions(streamIdOrPath: string, ...assignments: PermissionAssignment[]): Promise; /** * Revokes permissions on a given stream. */ revokePermissions(streamIdOrPath: string, ...assignments: PermissionAssignment[]): Promise; /** * Sets a list of permissions to be in effect. * * @remarks Can be used to set the permissions of multiple streams in one transaction. Great for doing bulk * operations and saving gas costs. Notice that the behaviour is overwriting, therefore any existing permissions not * defined will be removed (per stream). */ setPermissions(...items: { streamId: string; assignments: PermissionAssignment[]; }[]): Promise; /** * Checks whether a given ethereum address has {@link StreamPermission.PUBLISH} permission to a stream. */ isStreamPublisher(streamIdOrPath: string, userAddress: string): Promise; /** * Checks whether a given ethereum address has {@link StreamPermission.SUBSCRIBE} permission to a stream. */ isStreamSubscriber(streamIdOrPath: string, userAddress: string): Promise; /** * Assigns a stream to a storage node. */ addStreamToStorageNode(streamIdOrPath: string, storageNodeAddress: string): Promise; /** * Unassigns a stream from a storage node. */ removeStreamFromStorageNode(streamIdOrPath: string, storageNodeAddress: string): Promise; /** * Checks whether a stream is assigned to a storage node. */ isStoredStream(streamIdOrPath: string, storageNodeAddress: string): Promise; /** * Gets all streams assigned to a storage node. * * @returns a list of {@link Stream} as well as `blockNumber` of result (i.e. blockchain state) */ getStoredStreams(storageNodeAddress: string): Promise<{ streams: Stream[]; blockNumber: number; }>; /** * Gets a list of storage nodes. * * @param streamIdOrPath - if a stream is given, returns the list of storage nodes the stream has been assigned to; * leave as `undefined` to return all storage nodes */ getStorageNodes(streamIdOrPath?: string): Promise; /** * Sets the metadata of a storage node in the storage node registry. * * @remarks Acts on behalf of the wallet associated with the current {@link StreamrClient} instance. * * @param metadata - if `undefined`, removes the storage node from the registry */ setStorageNodeMetadata(metadata: StorageNodeMetadata | undefined): Promise; /** * Gets the metadata of a storage node from the storage node registry. * * @returns rejects if the storage node is not found */ getStorageNodeMetadata(nodeAddress: string): Promise; /** * Gets the Ethereum address of the wallet associated with the current {@link StreamrClient} instance. */ getAddress(): Promise; /** * @deprecated This in an internal method */ getNode(): Promise; setProxies(streamDefinition: StreamDefinition, nodeIds: string[], direction: ProxyDirection, connectionCount?: number): Promise; /** * Used to manually initialize the network stack and connect to the network. * * @remarks Connecting is handled automatically by the client. Generally this method need not be called by the user. */ connect(): Promise; private _connect; /** * Destroys an instance of a {@link StreamrClient} by disconnecting from peers, clearing any pending tasks, and * freeing up resources. This should be called once a user is done with the instance. * * @remarks As the name implies, the client instance (or any streams or subscriptions returned by it) should _not_ * be used after calling this method. */ destroy(): Promise; private _destroy; /** * Get diagnostic info about the underlying network. Useful for debugging issues. * * @remark returned object's structure can change without semver considerations */ getDiagnosticInfo(): Promise>; /** * Adds an event listener to the client. * @param eventName - event name, see {@link StreamrClientEvents} for options * @param listener - the callback function */ on(eventName: T, listener: StreamrClientEvents[T]): void; /** * Adds an event listener to the client that is invoked only once. * @param eventName - event name, see {@link StreamrClientEvents} for options * @param listener - the callback function */ once(eventName: T, listener: StreamrClientEvents[T]): void; /** * Removes an event listener from the client. * @param eventName - event name, see {@link StreamrClientEvents} for options * @param listener - the callback function to remove */ off(eventName: T, listener: StreamrClientEvents[T]): void; }