diff --git a/.gitignore b/.gitignore index d6f38cb3a..1d59a1091 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,6 @@ .nyc_output build -dist docs # Dependency directory diff --git a/dist/src/connection/connection.d.ts b/dist/src/connection/connection.d.ts new file mode 100644 index 000000000..27b606a22 --- /dev/null +++ b/dist/src/connection/connection.d.ts @@ -0,0 +1,235 @@ +export = Connection; +/** + * @typedef {import('../stream-muxer/types').MuxedStream} MuxedStream + * @typedef {import('./status').Status} Status + */ +/** + * @typedef {Object} Timeline + * @property {number} open - connection opening timestamp. + * @property {number} [upgraded] - connection upgraded timestamp. + * @property {number} [close] + * + * @typedef {Object} ConectionStat + * @property {'inbound' | 'outbound'} direction - connection establishment direction + * @property {Timeline} timeline - connection relevant events timestamp. + * @property {string} [multiplexer] - connection multiplexing identifier. + * @property {string} [encryption] - connection encryption method identifier. + * + * @typedef {(protocols: string|string[]) => Promise<{stream: MuxedStream, protocol: string}>} CreatedMuxedStream + * + * @typedef {Object} ConnectionOptions + * @property {Multiaddr} [localAddr] - local multiaddr of the connection if known. + * @property {Multiaddr} remoteAddr - remote multiaddr of the connection. + * @property {PeerId} localPeer - local peer-id. + * @property {PeerId} remotePeer - remote peer-id. + * @property {CreatedMuxedStream} newStream - new stream muxer function. + * @property {() => Promise} close - close raw connection function. + * @property {() => MuxedStream[]} getStreams - get streams from muxer function. + * @property {ConectionStat} stat - metadata of the connection. + * + * @typedef {Object} StreamData + * @property {string} protocol - the protocol used by the stream + * @property {Object} [metadata] - metadata of the stream + */ +/** + * An implementation of the js-libp2p connection. + * Any libp2p transport should use an upgrader to return this connection. + */ +declare class Connection { + /** + * Checks if the given value is a `Connection` instance. + * + * @param {any} other + * @returns {other is Connection} + */ + static isConnection(other: any): other is Connection; + /** + * An implementation of the js-libp2p connection. + * Any libp2p transport should use an upgrader to return this connection. + * + * @class + * @param {ConnectionOptions} options + */ + constructor({ localAddr, remoteAddr, localPeer, remotePeer, newStream, close, getStreams, stat }: ConnectionOptions); + /** + * Connection identifier. + */ + id: string; + /** + * Observed multiaddr of the local peer + */ + localAddr: Multiaddr | undefined; + /** + * Observed multiaddr of the remote peer + */ + remoteAddr: Multiaddr; + /** + * Local peer id. + */ + localPeer: PeerId; + /** + * Remote peer id. + */ + remotePeer: PeerId; + /** + * Connection metadata. + * + * @type {ConectionStat & {status: Status}} + */ + _stat: ConectionStat & { + status: Status; + }; + /** + * Reference to the new stream function of the multiplexer + */ + _newStream: CreatedMuxedStream; + /** + * Reference to the close function of the raw connection + */ + _close: () => Promise; + /** + * Reference to the getStreams function of the muxer + */ + _getStreams: () => MuxedStream[]; + /** + * Connection streams registry + */ + registry: Map; + /** + * User provided tags + * + * @type {string[]} + */ + tags: string[]; + get [Symbol.toStringTag](): string; + /** + * Get connection metadata + * + * @this {Connection} + */ + get stat(): ConectionStat & { + status: Status; + }; + /** + * Get all the streams of the muxer. + * + * @this {Connection} + */ + get streams(): import("../stream-muxer/types").MuxedStream[]; + /** + * Create a new stream from this connection + * + * @param {string|string[]} protocols - intended protocol for the stream + * @returns {Promise<{stream: MuxedStream, protocol: string}>} with muxed+multistream-selected stream and selected protocol + */ + newStream(protocols: string | string[]): Promise<{ + stream: MuxedStream; + protocol: string; + }>; + /** + * Add a stream when it is opened to the registry. + * + * @param {MuxedStream} muxedStream - a muxed stream + * @param {StreamData} data - the stream data to be registered + * @returns {void} + */ + addStream(muxedStream: MuxedStream, { protocol, metadata }: StreamData): void; + /** + * Remove stream registry after it is closed. + * + * @param {string} id - identifier of the stream + */ + removeStream(id: string): void; + /** + * Close the connection. + * + * @returns {Promise} + */ + close(): Promise; + _closing: void | undefined; +} +declare namespace Connection { + export { MuxedStream, Status, Timeline, ConectionStat, CreatedMuxedStream, ConnectionOptions, StreamData }; +} +import { Multiaddr } from "multiaddr"; +import PeerId = require("peer-id"); +type ConectionStat = { + /** + * - connection establishment direction + */ + direction: 'inbound' | 'outbound'; + /** + * - connection relevant events timestamp. + */ + timeline: Timeline; + /** + * - connection multiplexing identifier. + */ + multiplexer?: string | undefined; + /** + * - connection encryption method identifier. + */ + encryption?: string | undefined; +}; +type Status = import('./status').Status; +type CreatedMuxedStream = (protocols: string | string[]) => Promise<{ + stream: MuxedStream; + protocol: string; +}>; +type MuxedStream = import('../stream-muxer/types').MuxedStream; +type StreamData = { + /** + * - the protocol used by the stream + */ + protocol: string; + /** + * - metadata of the stream + */ + metadata?: Object | undefined; +}; +type ConnectionOptions = { + /** + * - local multiaddr of the connection if known. + */ + localAddr?: Multiaddr | undefined; + /** + * - remote multiaddr of the connection. + */ + remoteAddr: Multiaddr; + /** + * - local peer-id. + */ + localPeer: PeerId; + /** + * - remote peer-id. + */ + remotePeer: PeerId; + /** + * - new stream muxer function. + */ + newStream: CreatedMuxedStream; + /** + * - close raw connection function. + */ + close: () => Promise; + /** + * - get streams from muxer function. + */ + getStreams: () => MuxedStream[]; + /** + * - metadata of the connection. + */ + stat: ConectionStat; +}; +type Timeline = { + /** + * - connection opening timestamp. + */ + open: number; + /** + * - connection upgraded timestamp. + */ + upgraded?: number | undefined; + close?: number | undefined; +}; +//# sourceMappingURL=connection.d.ts.map \ No newline at end of file diff --git a/dist/src/connection/connection.d.ts.map b/dist/src/connection/connection.d.ts.map new file mode 100644 index 000000000..59eedd049 --- /dev/null +++ b/dist/src/connection/connection.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../../src/connection/connection.js"],"names":[],"mappings":";AASA;;;GAGG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH;;;GAGG;AACH;IAkFE;;;;;OAKG;IACH,2BAHW,GAAG,uBAKb;IAzFD;;;;;;OAMG;IACH,kGAFW,iBAAiB,EAkE3B;IA7DC;;OAEG;IACH,WAA2E;IAE3E;;OAEG;IACH,iCAA0B;IAE1B;;OAEG;IACH,sBAA4B;IAE5B;;OAEG;IACH,kBAA0B;IAE1B;;OAEG;IACH,mBAA4B;IAE5B;;;;OAIG;IACH,OAFU,aAAa,GAAG;QAAC,QAAQ,MAAM,CAAA;KAAC,CAKzC;IAED;;OAEG;IACH,+BAA2B;IAE3B;;OAEG;IACH,cAnEgB,QAAQ,IAAI,CAAC,CAmEV;IAEnB;;OAEG;IACH,mBAvEgB,WAAW,EAAE,CAuEA;IAE7B;;OAEG;IACH,wBAAyB;IAEzB;;;;OAIG;IACH,MAFU,MAAM,EAAE,CAEJ;IAGhB,mCAEC;IAgBD;;;;OAIG;IACH;gBA1DqC,MAAM;MA4D1C;IAED;;;;OAIG;IACH,6DAEC;IAED;;;;;OAKG;IACH,qBAHW,MAAM,GAAC,MAAM,EAAE;gBACI,WAAW;kBAAY,MAAM;OAqB1D;IAED;;;;;;OAMG;IACH,uBAJW,WAAW,0BACX,UAAU,GACR,IAAI,CAQhB;IAED;;;;OAIG;IACH,iBAFW,MAAM,QAIhB;IAED;;;;OAIG;IACH,SAFa,QAAQ,IAAI,CAAC,CAkBzB;IAJC,2BAAmC;CAKtC;;;;;;;;;;eAjNa,SAAS,GAAG,UAAU;;;;cACtB,QAAQ;;;;;;;;;;cAXT,OAAO,UAAU,EAAE,MAAM;sCAeb,MAAM,GAAC,MAAM,EAAE,KAAK,QAAQ;IAAC,MAAM,EAAE,WAAW,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAC,CAAC;mBAhBhF,OAAO,uBAAuB,EAAE,WAAW;;;;;cA6B1C,MAAM;;;;;;;;;;;;;;gBATN,SAAS;;;;eACT,MAAM;;;;gBACN,MAAM;;;;eACN,kBAAkB;;;;WAClB,MAAM,QAAQ,IAAI,CAAC;;;;gBACnB,MAAM,WAAW,EAAE;;;;UACnB,aAAa;;;;;;UApBb,MAAM"} \ No newline at end of file diff --git a/dist/src/connection/index.d.ts b/dist/src/connection/index.d.ts new file mode 100644 index 000000000..8cb5263c4 --- /dev/null +++ b/dist/src/connection/index.d.ts @@ -0,0 +1,2 @@ +export var Connection: typeof import("./connection"); +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/src/connection/index.d.ts.map b/dist/src/connection/index.d.ts.map new file mode 100644 index 000000000..07cb0a178 --- /dev/null +++ b/dist/src/connection/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/connection/index.js"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/src/connection/status.d.ts b/dist/src/connection/status.d.ts new file mode 100644 index 000000000..e9599013a --- /dev/null +++ b/dist/src/connection/status.d.ts @@ -0,0 +1,10 @@ +export type Status = { + OPEN: "open"; + CLOSING: "closing"; + CLOSED: "closed"; +}[keyof { + OPEN: "open"; + CLOSING: "closing"; + CLOSED: "closed"; +}]; +//# sourceMappingURL=status.d.ts.map \ No newline at end of file diff --git a/dist/src/connection/status.d.ts.map b/dist/src/connection/status.d.ts.map new file mode 100644 index 000000000..b3dfef8a0 --- /dev/null +++ b/dist/src/connection/status.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../../../src/connection/status.js"],"names":[],"mappings":"qBAUa;;;;EAAO;;;;CAAY,CAAC"} \ No newline at end of file diff --git a/dist/src/connection/tests/connection.d.ts b/dist/src/connection/tests/connection.d.ts new file mode 100644 index 000000000..fd6b1b10c --- /dev/null +++ b/dist/src/connection/tests/connection.d.ts @@ -0,0 +1,3 @@ +declare function _exports(test: any): void; +export = _exports; +//# sourceMappingURL=connection.d.ts.map \ No newline at end of file diff --git a/dist/src/connection/tests/connection.d.ts.map b/dist/src/connection/tests/connection.d.ts.map new file mode 100644 index 000000000..501d1c742 --- /dev/null +++ b/dist/src/connection/tests/connection.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../../../src/connection/tests/connection.js"],"names":[],"mappings":"AAWiB,2CA4KhB"} \ No newline at end of file diff --git a/dist/src/connection/tests/index.d.ts b/dist/src/connection/tests/index.d.ts new file mode 100644 index 000000000..eceb82ed7 --- /dev/null +++ b/dist/src/connection/tests/index.d.ts @@ -0,0 +1,3 @@ +declare function _exports(test: any): void; +export = _exports; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/src/connection/tests/index.d.ts.map b/dist/src/connection/tests/index.d.ts.map new file mode 100644 index 000000000..59611911f --- /dev/null +++ b/dist/src/connection/tests/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/connection/tests/index.js"],"names":[],"mappings":"AAOiB,2CAEhB"} \ No newline at end of file diff --git a/dist/src/content-routing/types.d.ts b/dist/src/content-routing/types.d.ts new file mode 100644 index 000000000..c8f1b57d8 --- /dev/null +++ b/dist/src/content-routing/types.d.ts @@ -0,0 +1,14 @@ +import PeerId from 'peer-id' +import { Multiaddr } from 'multiaddr' +import CID from 'cids' + +export interface ContentRoutingFactory { + new (options?: any): ContentRouting; +} + +export interface ContentRouting { + provide (cid: CID): Promise; + findProviders (cid: CID, options: Object): AsyncIterable<{ id: PeerId, multiaddrs: Multiaddr[] }>; +} + +export default ContentRouting; diff --git a/dist/src/crypto/errors.d.ts b/dist/src/crypto/errors.d.ts new file mode 100644 index 000000000..63c88a348 --- /dev/null +++ b/dist/src/crypto/errors.d.ts @@ -0,0 +1,13 @@ +export class UnexpectedPeerError extends Error { + static get code(): string; + code: string; +} +export class InvalidCryptoExchangeError extends Error { + static get code(): string; + code: string; +} +export class InvalidCryptoTransmissionError extends Error { + static get code(): string; + code: string; +} +//# sourceMappingURL=errors.d.ts.map \ No newline at end of file diff --git a/dist/src/crypto/errors.d.ts.map b/dist/src/crypto/errors.d.ts.map new file mode 100644 index 000000000..cb68a4e6a --- /dev/null +++ b/dist/src/crypto/errors.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/crypto/errors.js"],"names":[],"mappings":"AAEA;IAME,0BAEC;IALC,aAAoC;CAMvC;AAED;IAME,0BAEC;IALC,aAA2C;CAM9C;AAED;IAME,0BAEC;IALC,aAA+C;CAMlD"} \ No newline at end of file diff --git a/dist/src/crypto/tests/index.d.ts b/dist/src/crypto/tests/index.d.ts new file mode 100644 index 000000000..1c87129c7 --- /dev/null +++ b/dist/src/crypto/tests/index.d.ts @@ -0,0 +1,3 @@ +declare function _exports(common: any): void; +export = _exports; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/src/crypto/tests/index.d.ts.map b/dist/src/crypto/tests/index.d.ts.map new file mode 100644 index 000000000..c52967047 --- /dev/null +++ b/dist/src/crypto/tests/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/crypto/tests/index.js"],"names":[],"mappings":"AAiBiB,6CAwFhB"} \ No newline at end of file diff --git a/dist/src/crypto/types.d.ts b/dist/src/crypto/types.d.ts new file mode 100644 index 000000000..56286d5dd --- /dev/null +++ b/dist/src/crypto/types.d.ts @@ -0,0 +1,24 @@ +import PeerId from 'peer-id' +import { MultiaddrConnection } from '../transport/types' + +/** + * A libp2p crypto module must be compliant to this interface + * to ensure all exchanged data between two peers is encrypted. + */ +export interface Crypto { + protocol: string; + /** + * Encrypt outgoing data to the remote party. + */ + secureOutbound(localPeer: PeerId, connection: MultiaddrConnection, remotePeer: PeerId): Promise; + /** + * Decrypt incoming data. + */ + secureInbound(localPeer: PeerId, connection: MultiaddrConnection, remotePeer?: PeerId): Promise; +} + +export type SecureOutbound = { + conn: MultiaddrConnection; + remoteEarlyData: Buffer; + remotePeer: PeerId; +} diff --git a/dist/src/index.d.ts b/dist/src/index.d.ts new file mode 100644 index 000000000..f36479a73 --- /dev/null +++ b/dist/src/index.d.ts @@ -0,0 +1 @@ +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/src/index.d.ts.map b/dist/src/index.d.ts.map new file mode 100644 index 000000000..4b136e26c --- /dev/null +++ b/dist/src/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.js"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/src/peer-discovery/tests/index.d.ts b/dist/src/peer-discovery/tests/index.d.ts new file mode 100644 index 000000000..1c87129c7 --- /dev/null +++ b/dist/src/peer-discovery/tests/index.d.ts @@ -0,0 +1,3 @@ +declare function _exports(common: any): void; +export = _exports; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/src/peer-discovery/tests/index.d.ts.map b/dist/src/peer-discovery/tests/index.d.ts.map new file mode 100644 index 000000000..66bd9a519 --- /dev/null +++ b/dist/src/peer-discovery/tests/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/peer-discovery/tests/index.js"],"names":[],"mappings":"AAciB,6CA8EhB"} \ No newline at end of file diff --git a/dist/src/peer-discovery/types.d.ts b/dist/src/peer-discovery/types.d.ts new file mode 100644 index 000000000..b5bfc9420 --- /dev/null +++ b/dist/src/peer-discovery/types.d.ts @@ -0,0 +1,13 @@ +import { EventEmitter } from 'events'; + +export interface PeerDiscoveryFactory { + new (options?: any): PeerDiscovery; + tag: string; +} + +export interface PeerDiscovery extends EventEmitter { + start(): void|Promise; + stop(): void|Promise; +} + +export default PeerDiscovery; diff --git a/dist/src/peer-routing/types.d.ts b/dist/src/peer-routing/types.d.ts new file mode 100644 index 000000000..96b448f28 --- /dev/null +++ b/dist/src/peer-routing/types.d.ts @@ -0,0 +1,13 @@ +import PeerId from 'peer-id' +import { Multiaddr } from 'multiaddr' + +export interface PeerRoutingFactory { + new (options?: any): PeerRouting; +} + +export interface PeerRouting { + findPeer (peerId: PeerId, options?: Object): Promise<{ id: PeerId, multiaddrs: Multiaddr[] }>; + getClosestPeers(key: Uint8Array, options?: Object): AsyncIterable<{ id: PeerId, multiaddrs: Multiaddr[] }>; +} + +export default PeerRouting; diff --git a/dist/src/pubsub/errors.d.ts b/dist/src/pubsub/errors.d.ts new file mode 100644 index 000000000..b47b37a5f --- /dev/null +++ b/dist/src/pubsub/errors.d.ts @@ -0,0 +1,12 @@ +export namespace codes { + const ERR_INVALID_SIGNATURE_POLICY: string; + const ERR_UNHANDLED_SIGNATURE_POLICY: string; + const ERR_MISSING_SIGNATURE: string; + const ERR_MISSING_SEQNO: string; + const ERR_INVALID_SIGNATURE: string; + const ERR_UNEXPECTED_FROM: string; + const ERR_UNEXPECTED_SIGNATURE: string; + const ERR_UNEXPECTED_KEY: string; + const ERR_UNEXPECTED_SEQNO: string; +} +//# sourceMappingURL=errors.d.ts.map \ No newline at end of file diff --git a/dist/src/pubsub/errors.d.ts.map b/dist/src/pubsub/errors.d.ts.map new file mode 100644 index 000000000..b1d71c012 --- /dev/null +++ b/dist/src/pubsub/errors.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/pubsub/errors.js"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/src/pubsub/index.d.ts b/dist/src/pubsub/index.d.ts new file mode 100644 index 000000000..d070cf630 --- /dev/null +++ b/dist/src/pubsub/index.d.ts @@ -0,0 +1,378 @@ +export = PubsubBaseProtocol; +/** + * @typedef {any} Libp2p + * @typedef {import('peer-id')} PeerId + * @typedef {import('bl')} BufferList + * @typedef {import('../stream-muxer/types').MuxedStream} MuxedStream + * @typedef {import('../connection/connection')} Connection + * @typedef {import('./signature-policy').SignaturePolicyType} SignaturePolicyType + * @typedef {import('./message/rpc').IRPC} IRPC + * @typedef {import('./message/rpc').RPC.SubOpts} RPCSubOpts + * @typedef {import('./message/rpc').RPC.Message} RPCMessage + */ +/** + * @typedef {Object} InMessage + * @property {string} [from] + * @property {string} receivedFrom + * @property {string[]} topicIDs + * @property {Uint8Array} [seqno] + * @property {Uint8Array} data + * @property {Uint8Array} [signature] + * @property {Uint8Array} [key] + * + * @typedef {Object} PubsubProperties + * @property {string} debugName - log namespace + * @property {Array|string} multicodecs - protocol identificers to connect + * @property {Libp2p} libp2p + * + * @typedef {Object} PubsubOptions + * @property {SignaturePolicyType} [globalSignaturePolicy = SignaturePolicy.StrictSign] - defines how signatures should be handled + * @property {boolean} [canRelayMessage = false] - if can relay messages not subscribed + * @property {boolean} [emitSelf = false] - if publish should emit to self, if subscribed + */ +/** + * PubsubBaseProtocol handles the peers and connections logic for pubsub routers + * and specifies the API that pubsub routers should have. + */ +declare class PubsubBaseProtocol extends EventEmitter { + /** + * @param {PubsubProperties & PubsubOptions} props + * @abstract + */ + constructor({ debugName, multicodecs, libp2p, globalSignaturePolicy, canRelayMessage, emitSelf }: PubsubProperties & PubsubOptions); + log: debug.Debugger & { + err: debug.Debugger; + }; + /** + * @type {Array} + */ + multicodecs: Array; + _libp2p: any; + registrar: any; + /** + * @type {PeerId} + */ + peerId: PeerId; + started: boolean; + /** + * Map of topics to which peers are subscribed to + * + * @type {Map>} + */ + topics: Map>; + /** + * List of our subscriptions + * + * @type {Set} + */ + subscriptions: Set; + /** + * Map of peer streams + * + * @type {Map} + */ + peers: Map; + /** + * The signature policy to follow by default + * + * @type {string} + */ + globalSignaturePolicy: string; + /** + * If router can relay received messages, even if not subscribed + * + * @type {boolean} + */ + canRelayMessage: boolean; + /** + * if publish should emit to self, if subscribed + * + * @type {boolean} + */ + emitSelf: boolean; + /** + * Topic validator function + * + * @typedef {function(string, InMessage): Promise} validator + */ + /** + * Topic validator map + * + * Keyed by topic + * Topic validators are functions with the following input: + * + * @type {Map} + */ + topicValidators: Map; + _registrarId: any; + /** + * On an inbound stream opened. + * + * @protected + * @param {Object} props + * @param {string} props.protocol + * @param {MuxedStream} props.stream + * @param {Connection} props.connection - connection + */ + protected _onIncomingStream({ protocol, stream, connection }: { + protocol: string; + stream: MuxedStream; + connection: Connection; + }): void; + /** + * Registrar notifies an established connection with pubsub protocol. + * + * @protected + * @param {PeerId} peerId - remote peer-id + * @param {Connection} conn - connection to the peer + */ + protected _onPeerConnected(peerId: PeerId, conn: Connection): Promise; + /** + * Registrar notifies a closing connection with pubsub protocol. + * + * @protected + * @param {PeerId} peerId - peerId + * @param {Error} [err] - error for connection end + */ + protected _onPeerDisconnected(peerId: PeerId, err?: Error | undefined): void; + /** + * Register the pubsub protocol onto the libp2p node. + * + * @returns {void} + */ + start(): void; + /** + * Unregister the pubsub protocol and the streams with other peers will be closed. + * + * @returns {void} + */ + stop(): void; + /** + * Notifies the router that a peer has been connected + * + * @protected + * @param {PeerId} peerId + * @param {string} protocol + * @returns {PeerStreams} + */ + protected _addPeer(peerId: PeerId, protocol: string): PeerStreams; + /** + * Notifies the router that a peer has been disconnected. + * + * @protected + * @param {PeerId} peerId + * @returns {PeerStreams | undefined} + */ + protected _removePeer(peerId: PeerId): PeerStreams | undefined; + /** + * Responsible for processing each RPC message received by other peers. + * + * @param {string} idB58Str - peer id string in base58 + * @param {AsyncIterable} stream - inbound stream + * @param {PeerStreams} peerStreams - PubSub peer + * @returns {Promise} + */ + _processMessages(idB58Str: string, stream: AsyncIterable, peerStreams: PeerStreams): Promise; + /** + * Handles an rpc request from a peer + * + * @param {string} idB58Str + * @param {PeerStreams} peerStreams + * @param {RPC} rpc + * @returns {boolean} + */ + _processRpc(idB58Str: string, peerStreams: PeerStreams, rpc: RPC): boolean; + /** + * Handles a subscription change from a peer + * + * @param {string} id + * @param {RPC.ISubOpts} subOpt + */ + _processRpcSubOpt(id: string, subOpt: RPC.ISubOpts): void; + /** + * Handles an message from a peer + * + * @param {InMessage} msg + * @returns {Promise} + */ + _processRpcMessage(msg: InMessage): Promise; + /** + * Emit a message from a peer + * + * @param {InMessage} message + */ + _emitMessage(message: InMessage): void; + /** + * The default msgID implementation + * Child class can override this. + * + * @param {InMessage} msg - the message object + * @returns {Uint8Array} message id as bytes + */ + getMsgId(msg: InMessage): Uint8Array; + /** + * Whether to accept a message from a peer + * Override to create a graylist + * + * @override + * @param {string} id + * @returns {boolean} + */ + _acceptFrom(id: string): boolean; + /** + * Decode Uint8Array into an RPC object. + * This can be override to use a custom router protobuf. + * + * @param {Uint8Array} bytes + * @returns {RPC} + */ + _decodeRpc(bytes: Uint8Array): RPC; + /** + * Encode RPC object into a Uint8Array. + * This can be override to use a custom router protobuf. + * + * @param {IRPC} rpc + * @returns {Uint8Array} + */ + _encodeRpc(rpc: IRPC): Uint8Array; + /** + * Send an rpc object to a peer + * + * @param {string} id - peer id + * @param {IRPC} rpc + * @returns {void} + */ + _sendRpc(id: string, rpc: IRPC): void; + /** + * Send subscroptions to a peer + * + * @param {string} id - peer id + * @param {string[]} topics + * @param {boolean} subscribe - set to false for unsubscriptions + * @returns {void} + */ + _sendSubscriptions(id: string, topics: string[], subscribe: boolean): void; + /** + * Validates the given message. The signature will be checked for authenticity. + * Throws an error on invalid messages + * + * @param {InMessage} message + * @returns {Promise} + */ + validate(message: InMessage): Promise; + /** + * Normalizes the message and signs it, if signing is enabled. + * Should be used by the routers to create the message to send. + * + * @protected + * @param {InMessage} message + * @returns {Promise} + */ + protected _buildMessage(message: InMessage): Promise; + /** + * Get a list of the peer-ids that are subscribed to one topic. + * + * @param {string} topic + * @returns {Array} + */ + getSubscribers(topic: string): Array; + /** + * Publishes messages to all subscribed peers + * + * @override + * @param {string} topic + * @param {Uint8Array} message + * @returns {Promise} + */ + publish(topic: string, message: Uint8Array): Promise; + /** + * Overriding the implementation of publish should handle the appropriate algorithms for the publish/subscriber implementation. + * For example, a Floodsub implementation might simply publish each message to each topic for every peer + * + * @abstract + * @param {InMessage|RPCMessage} message + * @returns {Promise} + * + */ + _publish(message: RPC.Message | InMessage): Promise; + /** + * Subscribes to a given topic. + * + * @abstract + * @param {string} topic + * @returns {void} + */ + subscribe(topic: string): void; + /** + * Unsubscribe from the given topic. + * + * @override + * @param {string} topic + * @returns {void} + */ + unsubscribe(topic: string): void; + /** + * Get the list of topics which the peer is subscribed to. + * + * @override + * @returns {Array} + */ + getTopics(): Array; +} +declare namespace PubsubBaseProtocol { + export { utils, SignaturePolicy, validator, Libp2p, PeerId, BufferList, MuxedStream, Connection, SignaturePolicyType, IRPC, RPCSubOpts, RPCMessage, InMessage, PubsubProperties, PubsubOptions }; +} +import { EventEmitter } from "events"; +import debug = require("debug"); +type PeerId = import('peer-id'); +/** + * Topic validator function + */ +type validator = (arg0: string, arg1: InMessage) => Promise; +type MuxedStream = import('../stream-muxer/types').MuxedStream; +type Connection = import('../connection/connection'); +import PeerStreams = require("./peer-streams"); +type BufferList = import('bl'); +import { RPC } from "./message/rpc"; +type InMessage = { + from?: string | undefined; + receivedFrom: string; + topicIDs: string[]; + seqno?: Uint8Array | undefined; + data: Uint8Array; + signature?: Uint8Array | undefined; + key?: Uint8Array | undefined; +}; +type IRPC = import('./message/rpc').IRPC; +type PubsubProperties = { + /** + * - log namespace + */ + debugName: string; + /** + * - protocol identificers to connect + */ + multicodecs: Array | string; + libp2p: Libp2p; +}; +type PubsubOptions = { + /** + * - defines how signatures should be handled + */ + globalSignaturePolicy?: import("./signature-policy").SignaturePolicyType | undefined; + /** + * - if can relay messages not subscribed + */ + canRelayMessage?: boolean | undefined; + /** + * - if publish should emit to self, if subscribed + */ + emitSelf?: boolean | undefined; +}; +import utils = require("./utils"); +import { SignaturePolicy } from "./signature-policy"; +type Libp2p = any; +type SignaturePolicyType = import('./signature-policy').SignaturePolicyType; +type RPCSubOpts = import('./message/rpc').RPC.SubOpts; +type RPCMessage = import('./message/rpc').RPC.Message; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/src/pubsub/index.d.ts.map b/dist/src/pubsub/index.d.ts.map new file mode 100644 index 000000000..f82f521f6 --- /dev/null +++ b/dist/src/pubsub/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/pubsub/index.js"],"names":[],"mappings":";AAqBA;;;;;;;;;;GAUG;AAEH;;;;;;;;;;;;;;;;;;;GAmBG;AAEH;;;GAGG;AACH;IACE;;;OAGG;IACH,kGAHW,gBAAgB,GAAG,aAAa,EA4G1C;IAnFC;;MAEE;IAEF;;OAEG;IACH,aAFU,MAAM,MAAM,CAAC,CAE0B;IACjD,aAAqB;IACrB,eAAiC;IACjC;;OAEG;IACH,QAFU,MAAM,CAEW;IAE3B,iBAAoB;IAEpB;;;;OAIG;IACH,QAFU,IAAI,MAAM,EAAE,IAAI,MAAM,CAAC,CAAC,CAEX;IAEvB;;;;OAIG;IACH,eAFU,IAAI,MAAM,CAAC,CAES;IAE9B;;;;OAIG;IACH,OAFU,IAAI,MAAM,EAAE,OAAO,gBAAgB,CAAC,CAAC,CAEzB;IAOtB;;;;OAIG;IACH,uBAFU,MAAM,CAEkC;IAElD;;;;OAIG;IACH,iBAFU,OAAO,CAEqB;IAEtC;;;;OAIG;IACH,UAFU,OAAO,CAEO;IAExB;;;;OAIG;IACH;;;;;;;OAOG;IACH,wCAAgC;IAEhC,kBAA6B;IA4D/B;;;;;;;;OAQG;IACH;kBAJW,MAAM;gBACN,WAAW;oBACX,UAAU;aASpB;IAED;;;;;;OAMG;IACH,mCAHW,MAAM,QACN,UAAU,iBAgBpB;IAED;;;;;;OAMG;IACH,sCAHW,MAAM,iCAQhB;IAzGD;;;;OAIG;IACH,SAFa,IAAI,CAyBhB;IAED;;;;OAIG;IACH,QAFa,IAAI,CAiBhB;IAyDD;;;;;;;OAOG;IACH,2BAJW,MAAM,YACN,MAAM,GACJ,WAAW,CAuBvB;IAED;;;;;;OAMG;IACH,8BAHW,MAAM,GACJ,WAAW,GAAG,SAAS,CAsBnC;IAID;;;;;;;OAOG;IACH,2BALW,MAAM,UACN,cAAc,UAAU,GAAC,UAAU,CAAC,eACpC,WAAW,GACT,QAAQ,IAAI,CAAC,CAkBzB;IAED;;;;;;;OAOG;IACH,sBALW,MAAM,eACN,WAAW,OACX,GAAG,GACD,OAAO,CAgCnB;IAED;;;;;OAKG;IACH,sBAHW,MAAM,UACN,IAAI,QAAQ,QAsBtB;IAED;;;;;OAKG;IACH,wBAHW,SAAS,GACP,QAAQ,IAAI,CAAC,CAmBzB;IAED;;;;OAIG;IACH,uCAMC;IAED;;;;;;OAMG;IACH,cAHW,SAAS,GACP,UAAU,CAatB;IAED;;;;;;;OAOG;IACH,gBAHW,MAAM,GACJ,OAAO,CAInB;IAED;;;;;;OAMG;IACH,kBAHW,UAAU,GACR,GAAG,CAIf;IAED;;;;;;OAMG;IACH,gBAHW,IAAI,GACF,UAAU,CAItB;IAED;;;;;;OAMG;IACH,aAJW,MAAM,OACN,IAAI,GACF,IAAI,CAWhB;IAED;;;;;;;OAOG;IACH,uBALW,MAAM,UACN,MAAM,EAAE,aACR,OAAO,GACL,IAAI,CAMhB;IAED;;;;;;OAMG;IACH,kBAHW,SAAS,GACP,QAAQ,IAAI,CAAC,CAwCzB;IAED;;;;;;;OAOG;IACH,iCAHW,SAAS,GACP,QAAQ,SAAS,CAAC,CAc9B;IAID;;;;;OAKG;IACH,sBAHW,MAAM,GACJ,MAAM,MAAM,CAAC,CAgBzB;IAED;;;;;;;OAOG;IACH,eAJW,MAAM,WACN,UAAU,GACR,QAAQ,IAAI,CAAC,CA0BzB;IAED;;;;;;;;OAQG;IACH,4CAHa,QAAQ,IAAI,CAAC,CAKzB;IAED;;;;;;OAMG;IACH,iBAHW,MAAM,GACJ,IAAI,CAWhB;IAED;;;;;;OAMG;IACH,mBAHW,MAAM,GACJ,IAAI,CAWhB;IAED;;;;;OAKG;IACH,aAFa,MAAM,MAAM,CAAC,CAQzB;CACF;;;;;;cArtBY,OAAO,SAAS,CAAC;;;;wBAiIJ,MAAM,QAAE,SAAS,KAAG,QAAQ,IAAI,CAAC;mBA/H9C,OAAO,uBAAuB,EAAE,WAAW;kBAC3C,OAAO,0BAA0B,CAAC;;kBAFlC,OAAO,IAAI,CAAC;;;;kBAYX,MAAM;cACN,MAAM,EAAE;;UAER,UAAU;;;;YAXX,OAAO,eAAe,EAAE,IAAI;;;;;eAgB3B,MAAM;;;;iBACN,MAAM,MAAM,CAAC,GAAC,MAAM;YACpB,MAAM;;;;;;;;;;;;;;;;;;cAxBP,GAAG;2BAKH,OAAO,oBAAoB,EAAE,mBAAmB;kBAEhD,OAAO,eAAe,EAAE,GAAG,CAAC,OAAO;kBACnC,OAAO,eAAe,EAAE,GAAG,CAAC,OAAO"} \ No newline at end of file diff --git a/dist/src/pubsub/message/rpc.d.ts b/dist/src/pubsub/message/rpc.d.ts new file mode 100644 index 000000000..5836c6695 --- /dev/null +++ b/dist/src/pubsub/message/rpc.d.ts @@ -0,0 +1,222 @@ +import * as $protobuf from "protobufjs"; +/** Properties of a RPC. */ +export interface IRPC { + + /** RPC subscriptions */ + subscriptions?: (RPC.ISubOpts[]|null); + + /** RPC msgs */ + msgs?: (RPC.IMessage[]|null); +} + +/** Represents a RPC. */ +export class RPC implements IRPC { + + /** + * Constructs a new RPC. + * @param [p] Properties to set + */ + constructor(p?: IRPC); + + /** RPC subscriptions. */ + public subscriptions: RPC.ISubOpts[]; + + /** RPC msgs. */ + public msgs: RPC.IMessage[]; + + /** + * Encodes the specified RPC message. Does not implicitly {@link RPC.verify|verify} messages. + * @param m RPC message or plain object to encode + * @param [w] Writer to encode to + * @returns Writer + */ + public static encode(m: IRPC, w?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a RPC message from the specified reader or buffer. + * @param r Reader or buffer to decode from + * @param [l] Message length if known beforehand + * @returns RPC + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): RPC; + + /** + * Creates a RPC message from a plain object. Also converts values to their respective internal types. + * @param d Plain object + * @returns RPC + */ + public static fromObject(d: { [k: string]: any }): RPC; + + /** + * Creates a plain object from a RPC message. Also converts values to other types if specified. + * @param m RPC + * @param [o] Conversion options + * @returns Plain object + */ + public static toObject(m: RPC, o?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this RPC to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; +} + +export namespace RPC { + + /** Properties of a SubOpts. */ + interface ISubOpts { + + /** SubOpts subscribe */ + subscribe?: (boolean|null); + + /** SubOpts topicID */ + topicID?: (string|null); + } + + /** Represents a SubOpts. */ + class SubOpts implements ISubOpts { + + /** + * Constructs a new SubOpts. + * @param [p] Properties to set + */ + constructor(p?: RPC.ISubOpts); + + /** SubOpts subscribe. */ + public subscribe: boolean; + + /** SubOpts topicID. */ + public topicID: string; + + /** + * Encodes the specified SubOpts message. Does not implicitly {@link RPC.SubOpts.verify|verify} messages. + * @param m SubOpts message or plain object to encode + * @param [w] Writer to encode to + * @returns Writer + */ + public static encode(m: RPC.ISubOpts, w?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a SubOpts message from the specified reader or buffer. + * @param r Reader or buffer to decode from + * @param [l] Message length if known beforehand + * @returns SubOpts + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): RPC.SubOpts; + + /** + * Creates a SubOpts message from a plain object. Also converts values to their respective internal types. + * @param d Plain object + * @returns SubOpts + */ + public static fromObject(d: { [k: string]: any }): RPC.SubOpts; + + /** + * Creates a plain object from a SubOpts message. Also converts values to other types if specified. + * @param m SubOpts + * @param [o] Conversion options + * @returns Plain object + */ + public static toObject(m: RPC.SubOpts, o?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this SubOpts to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + } + + /** Properties of a Message. */ + interface IMessage { + + /** Message from */ + from?: (Uint8Array|null); + + /** Message data */ + data?: (Uint8Array|null); + + /** Message seqno */ + seqno?: (Uint8Array|null); + + /** Message topicIDs */ + topicIDs?: (string[]|null); + + /** Message signature */ + signature?: (Uint8Array|null); + + /** Message key */ + key?: (Uint8Array|null); + } + + /** Represents a Message. */ + class Message implements IMessage { + + /** + * Constructs a new Message. + * @param [p] Properties to set + */ + constructor(p?: RPC.IMessage); + + /** Message from. */ + public from: Uint8Array; + + /** Message data. */ + public data: Uint8Array; + + /** Message seqno. */ + public seqno: Uint8Array; + + /** Message topicIDs. */ + public topicIDs: string[]; + + /** Message signature. */ + public signature: Uint8Array; + + /** Message key. */ + public key: Uint8Array; + + /** + * Encodes the specified Message message. Does not implicitly {@link RPC.Message.verify|verify} messages. + * @param m Message message or plain object to encode + * @param [w] Writer to encode to + * @returns Writer + */ + public static encode(m: RPC.IMessage, w?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a Message message from the specified reader or buffer. + * @param r Reader or buffer to decode from + * @param [l] Message length if known beforehand + * @returns Message + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): RPC.Message; + + /** + * Creates a Message message from a plain object. Also converts values to their respective internal types. + * @param d Plain object + * @returns Message + */ + public static fromObject(d: { [k: string]: any }): RPC.Message; + + /** + * Creates a plain object from a Message message. Also converts values to other types if specified. + * @param m Message + * @param [o] Conversion options + * @returns Plain object + */ + public static toObject(m: RPC.Message, o?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this Message to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + } +} diff --git a/dist/src/pubsub/message/sign.d.ts b/dist/src/pubsub/message/sign.d.ts new file mode 100644 index 000000000..44040a944 --- /dev/null +++ b/dist/src/pubsub/message/sign.d.ts @@ -0,0 +1,33 @@ +export type InMessage = import('..').InMessage; +export type PublicKey = import('libp2p-crypto').PublicKey; +/** + * Returns the PublicKey associated with the given message. + * If no, valid PublicKey can be retrieved an error will be returned. + * + * @param {InMessage} message + * @returns {Promise} + */ +export function messagePublicKey(message: InMessage): Promise; +/** + * @typedef {import('..').InMessage} + */ +/** + * Signs the provided message with the given `peerId` + * + * @param {PeerId} peerId + * @param {RPC.Message} message + * @returns {Promise} + */ +export function signMessage(peerId: PeerId, message: RPC.Message): Promise; +export type signMessage = import('..').InMessage; +export const SignPrefix: Uint8Array; +/** + * Verifies the signature of the given message + * + * @param {InMessage} message + * @returns {Promise} + */ +export function verifySignature(message: InMessage): Promise; +import PeerId = require("peer-id"); +import { RPC } from "./rpc"; +//# sourceMappingURL=sign.d.ts.map \ No newline at end of file diff --git a/dist/src/pubsub/message/sign.d.ts.map b/dist/src/pubsub/message/sign.d.ts.map new file mode 100644 index 000000000..79c70407f --- /dev/null +++ b/dist/src/pubsub/message/sign.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"sign.d.ts","sourceRoot":"","sources":["../../../../src/pubsub/message/sign.js"],"names":[],"mappings":"wBA+Fa,OAAO,IAAI,EAAE,SAAS;wBACtB,OAAO,eAAe,EAAE,SAAS;AA/B9C;;;;;;GAMG;AACH,0CAHW,SAAS,GACP,QAAQ,SAAS,CAAC,CAsB9B;AApFD;;GAEG;AAEH;;;;;;GAMG;AACH,oCAJW,MAAM,WACN,IAAI,OAAO,GACT,QAAQ,GAAG,CAAC,CAgBxB;0BAxBY,OAAO,IAAI,EAAE,SAAS;AAHnC,oCAAyD;AA6BzD;;;;;GAKG;AACH,yCAHW,SAAS,GACP,QAAQ,OAAO,CAAC,CAwB5B"} \ No newline at end of file diff --git a/dist/src/pubsub/message/topic-descriptor.d.ts b/dist/src/pubsub/message/topic-descriptor.d.ts new file mode 100644 index 000000000..179deba27 --- /dev/null +++ b/dist/src/pubsub/message/topic-descriptor.d.ts @@ -0,0 +1,224 @@ +import * as $protobuf from "protobufjs"; +/** Properties of a TopicDescriptor. */ +export interface ITopicDescriptor { + + /** TopicDescriptor name */ + name?: (string|null); + + /** TopicDescriptor auth */ + auth?: (TopicDescriptor.IAuthOpts|null); + + /** TopicDescriptor enc */ + enc?: (TopicDescriptor.IEncOpts|null); +} + +/** Represents a TopicDescriptor. */ +export class TopicDescriptor implements ITopicDescriptor { + + /** + * Constructs a new TopicDescriptor. + * @param [p] Properties to set + */ + constructor(p?: ITopicDescriptor); + + /** TopicDescriptor name. */ + public name: string; + + /** TopicDescriptor auth. */ + public auth?: (TopicDescriptor.IAuthOpts|null); + + /** TopicDescriptor enc. */ + public enc?: (TopicDescriptor.IEncOpts|null); + + /** + * Encodes the specified TopicDescriptor message. Does not implicitly {@link TopicDescriptor.verify|verify} messages. + * @param m TopicDescriptor message or plain object to encode + * @param [w] Writer to encode to + * @returns Writer + */ + public static encode(m: ITopicDescriptor, w?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a TopicDescriptor message from the specified reader or buffer. + * @param r Reader or buffer to decode from + * @param [l] Message length if known beforehand + * @returns TopicDescriptor + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): TopicDescriptor; + + /** + * Creates a TopicDescriptor message from a plain object. Also converts values to their respective internal types. + * @param d Plain object + * @returns TopicDescriptor + */ + public static fromObject(d: { [k: string]: any }): TopicDescriptor; + + /** + * Creates a plain object from a TopicDescriptor message. Also converts values to other types if specified. + * @param m TopicDescriptor + * @param [o] Conversion options + * @returns Plain object + */ + public static toObject(m: TopicDescriptor, o?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this TopicDescriptor to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; +} + +export namespace TopicDescriptor { + + /** Properties of an AuthOpts. */ + interface IAuthOpts { + + /** AuthOpts mode */ + mode?: (TopicDescriptor.AuthOpts.AuthMode|null); + + /** AuthOpts keys */ + keys?: (Uint8Array[]|null); + } + + /** Represents an AuthOpts. */ + class AuthOpts implements IAuthOpts { + + /** + * Constructs a new AuthOpts. + * @param [p] Properties to set + */ + constructor(p?: TopicDescriptor.IAuthOpts); + + /** AuthOpts mode. */ + public mode: TopicDescriptor.AuthOpts.AuthMode; + + /** AuthOpts keys. */ + public keys: Uint8Array[]; + + /** + * Encodes the specified AuthOpts message. Does not implicitly {@link TopicDescriptor.AuthOpts.verify|verify} messages. + * @param m AuthOpts message or plain object to encode + * @param [w] Writer to encode to + * @returns Writer + */ + public static encode(m: TopicDescriptor.IAuthOpts, w?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes an AuthOpts message from the specified reader or buffer. + * @param r Reader or buffer to decode from + * @param [l] Message length if known beforehand + * @returns AuthOpts + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): TopicDescriptor.AuthOpts; + + /** + * Creates an AuthOpts message from a plain object. Also converts values to their respective internal types. + * @param d Plain object + * @returns AuthOpts + */ + public static fromObject(d: { [k: string]: any }): TopicDescriptor.AuthOpts; + + /** + * Creates a plain object from an AuthOpts message. Also converts values to other types if specified. + * @param m AuthOpts + * @param [o] Conversion options + * @returns Plain object + */ + public static toObject(m: TopicDescriptor.AuthOpts, o?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this AuthOpts to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + } + + namespace AuthOpts { + + /** AuthMode enum. */ + enum AuthMode { + NONE = 0, + KEY = 1, + WOT = 2 + } + } + + /** Properties of an EncOpts. */ + interface IEncOpts { + + /** EncOpts mode */ + mode?: (TopicDescriptor.EncOpts.EncMode|null); + + /** EncOpts keyHashes */ + keyHashes?: (Uint8Array[]|null); + } + + /** Represents an EncOpts. */ + class EncOpts implements IEncOpts { + + /** + * Constructs a new EncOpts. + * @param [p] Properties to set + */ + constructor(p?: TopicDescriptor.IEncOpts); + + /** EncOpts mode. */ + public mode: TopicDescriptor.EncOpts.EncMode; + + /** EncOpts keyHashes. */ + public keyHashes: Uint8Array[]; + + /** + * Encodes the specified EncOpts message. Does not implicitly {@link TopicDescriptor.EncOpts.verify|verify} messages. + * @param m EncOpts message or plain object to encode + * @param [w] Writer to encode to + * @returns Writer + */ + public static encode(m: TopicDescriptor.IEncOpts, w?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes an EncOpts message from the specified reader or buffer. + * @param r Reader or buffer to decode from + * @param [l] Message length if known beforehand + * @returns EncOpts + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): TopicDescriptor.EncOpts; + + /** + * Creates an EncOpts message from a plain object. Also converts values to their respective internal types. + * @param d Plain object + * @returns EncOpts + */ + public static fromObject(d: { [k: string]: any }): TopicDescriptor.EncOpts; + + /** + * Creates a plain object from an EncOpts message. Also converts values to other types if specified. + * @param m EncOpts + * @param [o] Conversion options + * @returns Plain object + */ + public static toObject(m: TopicDescriptor.EncOpts, o?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this EncOpts to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + } + + namespace EncOpts { + + /** EncMode enum. */ + enum EncMode { + NONE = 0, + SHAREDKEY = 1, + WOT = 2 + } + } +} diff --git a/dist/src/pubsub/peer-streams.d.ts b/dist/src/pubsub/peer-streams.d.ts new file mode 100644 index 000000000..d8d5b1fdc --- /dev/null +++ b/dist/src/pubsub/peer-streams.d.ts @@ -0,0 +1,112 @@ +export = PeerStreams; +/** + * @typedef {import('../stream-muxer/types').MuxedStream} MuxedStream + * @typedef {import('peer-id')} PeerId + * @typedef {import('it-pushable').Pushable} PushableStream + */ +/** + * Thin wrapper around a peer's inbound / outbound pubsub streams + */ +declare class PeerStreams extends EventEmitter { + /** + * @param {object} properties - properties of the PeerStreams. + * @param {PeerId} properties.id + * @param {string} properties.protocol + */ + constructor({ id, protocol }: { + id: PeerId; + protocol: string; + }); + /** + * @type {import('peer-id')} + */ + id: import('peer-id'); + /** + * Established protocol + * + * @type {string} + */ + protocol: string; + /** + * The raw outbound stream, as retrieved from conn.newStream + * + * @private + * @type {null|MuxedStream} + */ + private _rawOutboundStream; + /** + * The raw inbound stream, as retrieved from the callback from libp2p.handle + * + * @private + * @type {null|MuxedStream} + */ + private _rawInboundStream; + /** + * An AbortController for controlled shutdown of the inbound stream + * + * @private + * @type {AbortController} + */ + private _inboundAbortController; + /** + * Write stream -- its preferable to use the write method + * + * @type {null|PushableStream} + */ + outboundStream: null | pushable.Pushable; + /** + * Read stream + * + * @type {null| AsyncIterable} + */ + inboundStream: null | AsyncIterable; + /** + * Do we have a connection to read from? + * + * @type {boolean} + */ + get isReadable(): boolean; + /** + * Do we have a connection to write on? + * + * @type {boolean} + */ + get isWritable(): boolean; + /** + * Send a message to this peer. + * Throws if there is no `stream` to write to available. + * + * @param {Uint8Array} data + * @returns {void} + */ + write(data: Uint8Array): void; + /** + * Attach a raw inbound stream and setup a read stream + * + * @param {MuxedStream} stream + * @returns {AsyncIterable} + */ + attachInboundStream(stream: MuxedStream): AsyncIterable; + /** + * Attach a raw outbound stream and setup a write stream + * + * @param {MuxedStream} stream + * @returns {Promise} + */ + attachOutboundStream(stream: MuxedStream): Promise; + /** + * Closes the open connection to peer + * + * @returns {void} + */ + close(): void; +} +declare namespace PeerStreams { + export { MuxedStream, PeerId, PushableStream }; +} +import { EventEmitter } from "events"; +import pushable = require("it-pushable"); +type MuxedStream = import('../stream-muxer/types').MuxedStream; +type PeerId = import('peer-id'); +type PushableStream = import('it-pushable').Pushable; +//# sourceMappingURL=peer-streams.d.ts.map \ No newline at end of file diff --git a/dist/src/pubsub/peer-streams.d.ts.map b/dist/src/pubsub/peer-streams.d.ts.map new file mode 100644 index 000000000..ff2af24a4 --- /dev/null +++ b/dist/src/pubsub/peer-streams.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"peer-streams.d.ts","sourceRoot":"","sources":["../../../src/pubsub/peer-streams.js"],"names":[],"mappings":";AAcA;;;;GAIG;AAEH;;GAEG;AACH;IACE;;;;OAIG;IACH;QAH8B,EAAE,EAArB,MAAM;QACa,QAAQ,EAA3B,MAAM;OAgDhB;IA3CC;;OAEG;IACH,IAFU,OAAO,SAAS,CAAC,CAEf;IACZ;;;;OAIG;IACH,UAFU,MAAM,CAEQ;IACxB;;;;;OAKG;IACH,2BAA8B;IAC9B;;;;;OAKG;IACH,0BAA6B;IAC7B;;;;;OAKG;IACH,gCAAoD;IACpD;;;;OAIG;IACH,gBAFU,IAAI,gCAAe,CAEH;IAC1B;;;;OAIG;IACH,eAFU,IAAI,GAAE,cAAc,UAAU,CAAC,CAEhB;IAG3B;;;;OAIG;IACH,0BAEC;IAED;;;;OAIG;IACH,0BAEC;IAED;;;;;;OAMG;IACH,YAHW,UAAU,GACR,IAAI,CAShB;IAED;;;;;OAKG;IACH,4BAHW,WAAW,GACT,cAAc,UAAU,CAAC,CAmBrC;IAED;;;;;OAKG;IACH,6BAHW,WAAW,GACT,QAAQ,IAAI,CAAC,CAmCzB;IAED;;;;OAIG;IACH,SAFa,IAAI,CAiBhB;CACF;;;;;;mBAvLY,OAAO,uBAAuB,EAAE,WAAW;cAC3C,OAAO,SAAS,CAAC;sBACjB,OAAO,aAAa,EAAE,QAAQ,CAAC,UAAU,CAAC"} \ No newline at end of file diff --git a/dist/src/pubsub/signature-policy.d.ts b/dist/src/pubsub/signature-policy.d.ts new file mode 100644 index 000000000..bdefcae3d --- /dev/null +++ b/dist/src/pubsub/signature-policy.d.ts @@ -0,0 +1,48 @@ +export type SignaturePolicyType = { + /** + * On the producing side: + * * Build messages with the signature, key (from may be enough for certain inlineable public key types), from and seqno fields. + * + * On the consuming side: + * * Enforce the fields to be present, reject otherwise. + * * Propagate only if the fields are valid and signature can be verified, reject otherwise. + */ + StrictSign: "StrictSign"; + /** + * On the producing side: + * * Build messages without the signature, key, from and seqno fields. + * * The corresponding protobuf key-value pairs are absent from the marshalled message, not just empty. + * + * On the consuming side: + * * Enforce the fields to be absent, reject otherwise. + * * Propagate only if the fields are absent, reject otherwise. + * * A message_id function will not be able to use the above fields, and should instead rely on the data field. A commonplace strategy is to calculate a hash. + */ + StrictNoSign: "StrictNoSign"; +}[keyof { + /** + * On the producing side: + * * Build messages with the signature, key (from may be enough for certain inlineable public key types), from and seqno fields. + * + * On the consuming side: + * * Enforce the fields to be present, reject otherwise. + * * Propagate only if the fields are valid and signature can be verified, reject otherwise. + */ + StrictSign: "StrictSign"; + /** + * On the producing side: + * * Build messages without the signature, key, from and seqno fields. + * * The corresponding protobuf key-value pairs are absent from the marshalled message, not just empty. + * + * On the consuming side: + * * Enforce the fields to be absent, reject otherwise. + * * Propagate only if the fields are absent, reject otherwise. + * * A message_id function will not be able to use the above fields, and should instead rely on the data field. A commonplace strategy is to calculate a hash. + */ + StrictNoSign: "StrictNoSign"; +}]; +export namespace SignaturePolicy { + const StrictSign: 'StrictSign'; + const StrictNoSign: 'StrictNoSign'; +} +//# sourceMappingURL=signature-policy.d.ts.map \ No newline at end of file diff --git a/dist/src/pubsub/signature-policy.d.ts.map b/dist/src/pubsub/signature-policy.d.ts.map new file mode 100644 index 000000000..5d1f83a9f --- /dev/null +++ b/dist/src/pubsub/signature-policy.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"signature-policy.d.ts","sourceRoot":"","sources":["../../../src/pubsub/signature-policy.js"],"names":[],"mappings":"kCA+Ba;IAxBX;;;;;;;OAOG;;IAEH;;;;;;;;;OASG;;EAMwB;IAxB3B;;;;;;;OAOG;;IAEH;;;;;;;;;OASG;;CAM6C,CAAC;;sBAhB1B,YAAY;wBAWV,cAAc"} \ No newline at end of file diff --git a/dist/src/pubsub/tests/api.d.ts b/dist/src/pubsub/tests/api.d.ts new file mode 100644 index 000000000..f333ceaa2 --- /dev/null +++ b/dist/src/pubsub/tests/api.d.ts @@ -0,0 +1,3 @@ +declare function _exports(common: any): void; +export = _exports; +//# sourceMappingURL=api.d.ts.map \ No newline at end of file diff --git a/dist/src/pubsub/tests/api.d.ts.map b/dist/src/pubsub/tests/api.d.ts.map new file mode 100644 index 000000000..a0416da3d --- /dev/null +++ b/dist/src/pubsub/tests/api.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../../src/pubsub/tests/api.js"],"names":[],"mappings":"AAeiB,6CA8EhB"} \ No newline at end of file diff --git a/dist/src/pubsub/tests/emit-self.d.ts b/dist/src/pubsub/tests/emit-self.d.ts new file mode 100644 index 000000000..8e675d4d9 --- /dev/null +++ b/dist/src/pubsub/tests/emit-self.d.ts @@ -0,0 +1,3 @@ +declare function _exports(common: any): void; +export = _exports; +//# sourceMappingURL=emit-self.d.ts.map \ No newline at end of file diff --git a/dist/src/pubsub/tests/emit-self.d.ts.map b/dist/src/pubsub/tests/emit-self.d.ts.map new file mode 100644 index 000000000..630cc23f4 --- /dev/null +++ b/dist/src/pubsub/tests/emit-self.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"emit-self.d.ts","sourceRoot":"","sources":["../../../../src/pubsub/tests/emit-self.js"],"names":[],"mappings":"AAciB,6CAuDhB"} \ No newline at end of file diff --git a/dist/src/pubsub/tests/index.d.ts b/dist/src/pubsub/tests/index.d.ts new file mode 100644 index 000000000..1c87129c7 --- /dev/null +++ b/dist/src/pubsub/tests/index.d.ts @@ -0,0 +1,3 @@ +declare function _exports(common: any): void; +export = _exports; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/src/pubsub/tests/index.d.ts.map b/dist/src/pubsub/tests/index.d.ts.map new file mode 100644 index 000000000..e91b31124 --- /dev/null +++ b/dist/src/pubsub/tests/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/pubsub/tests/index.js"],"names":[],"mappings":"AAUiB,6CAQhB"} \ No newline at end of file diff --git a/dist/src/pubsub/tests/messages.d.ts b/dist/src/pubsub/tests/messages.d.ts new file mode 100644 index 000000000..93bbf6910 --- /dev/null +++ b/dist/src/pubsub/tests/messages.d.ts @@ -0,0 +1,3 @@ +declare function _exports(common: any): void; +export = _exports; +//# sourceMappingURL=messages.d.ts.map \ No newline at end of file diff --git a/dist/src/pubsub/tests/messages.d.ts.map b/dist/src/pubsub/tests/messages.d.ts.map new file mode 100644 index 000000000..ebdac5665 --- /dev/null +++ b/dist/src/pubsub/tests/messages.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../../../src/pubsub/tests/messages.js"],"names":[],"mappings":"AAkBiB,6CAiGhB"} \ No newline at end of file diff --git a/dist/src/pubsub/tests/multiple-nodes.d.ts b/dist/src/pubsub/tests/multiple-nodes.d.ts new file mode 100644 index 000000000..34deb5925 --- /dev/null +++ b/dist/src/pubsub/tests/multiple-nodes.d.ts @@ -0,0 +1,3 @@ +declare function _exports(common: any): void; +export = _exports; +//# sourceMappingURL=multiple-nodes.d.ts.map \ No newline at end of file diff --git a/dist/src/pubsub/tests/multiple-nodes.d.ts.map b/dist/src/pubsub/tests/multiple-nodes.d.ts.map new file mode 100644 index 000000000..b29da8749 --- /dev/null +++ b/dist/src/pubsub/tests/multiple-nodes.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"multiple-nodes.d.ts","sourceRoot":"","sources":["../../../../src/pubsub/tests/multiple-nodes.js"],"names":[],"mappings":"AAiBiB,6CAmUhB"} \ No newline at end of file diff --git a/dist/src/pubsub/tests/two-nodes.d.ts b/dist/src/pubsub/tests/two-nodes.d.ts new file mode 100644 index 000000000..e07588ac2 --- /dev/null +++ b/dist/src/pubsub/tests/two-nodes.d.ts @@ -0,0 +1,3 @@ +declare function _exports(common: any): void; +export = _exports; +//# sourceMappingURL=two-nodes.d.ts.map \ No newline at end of file diff --git a/dist/src/pubsub/tests/two-nodes.d.ts.map b/dist/src/pubsub/tests/two-nodes.d.ts.map new file mode 100644 index 000000000..672085a85 --- /dev/null +++ b/dist/src/pubsub/tests/two-nodes.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"two-nodes.d.ts","sourceRoot":"","sources":["../../../../src/pubsub/tests/two-nodes.js"],"names":[],"mappings":"AAyBiB,6CA+MhB"} \ No newline at end of file diff --git a/dist/src/pubsub/tests/utils.d.ts b/dist/src/pubsub/tests/utils.d.ts new file mode 100644 index 000000000..9ea5d1a64 --- /dev/null +++ b/dist/src/pubsub/tests/utils.d.ts @@ -0,0 +1,3 @@ +export function first(map: any): any; +export function expectSet(set: any, subs: any): void; +//# sourceMappingURL=utils.d.ts.map \ No newline at end of file diff --git a/dist/src/pubsub/tests/utils.d.ts.map b/dist/src/pubsub/tests/utils.d.ts.map new file mode 100644 index 000000000..460e55338 --- /dev/null +++ b/dist/src/pubsub/tests/utils.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/pubsub/tests/utils.js"],"names":[],"mappings":"AAKgB,qCAAkC;AAE9B,qDAEnB"} \ No newline at end of file diff --git a/dist/src/pubsub/utils.d.ts b/dist/src/pubsub/utils.d.ts new file mode 100644 index 000000000..7158df098 --- /dev/null +++ b/dist/src/pubsub/utils.d.ts @@ -0,0 +1,73 @@ +export type IMessage = import('./message/rpc').RPC.IMessage; +export type Message = import('./message/rpc').RPC.Message; +export type NormalizedIMessage = import('.').InMessage; +/** + * @typedef {import('./message/rpc').RPC.IMessage} IMessage + * @typedef {import('./message/rpc').RPC.Message} Message + * @typedef {import('.').InMessage} NormalizedIMessage + */ +/** + * Generatea random sequence number. + * + * @returns {Uint8Array} + * @private + */ +export function randomSeqno(): Uint8Array; +/** + * Generate a message id, based on the `from` and `seqno`. + * + * @param {string} from + * @param {Uint8Array} seqno + * @returns {Uint8Array} + * @private + */ +export function msgId(from: string, seqno: Uint8Array): Uint8Array; +/** + * Generate a message id, based on message `data`. + * + * @param {Uint8Array} data + * @returns {Uint8Array} + * @private + */ +export function noSignMsgId(data: Uint8Array): Uint8Array; +/** + * Check if any member of the first set is also a member + * of the second set. + * + * @param {Set|Array} a + * @param {Set|Array} b + * @returns {boolean} + * @private + */ +export function anyMatch(a: Set | Array, b: Set | Array): boolean; +/** + * Make everything an array. + * + * @template T + * @param {T|T[]} maybeArray + * @returns {T[]} + * @private + */ +export function ensureArray(maybeArray: T | T[]): T[]; +/** + * Ensures `message.from` is base58 encoded + * + * @template {{from?:any}} T + * @param {T & IMessage} message + * @param {string} [peerId] + * @returns {NormalizedIMessage} + */ +export function normalizeInRpcMessage(message: T & import("./message/rpc").RPC.IMessage, peerId?: string | undefined): NormalizedIMessage; +/** + * @template {{from?:any, data?:any}} T + * + * @param {T & NormalizedIMessage} message + * @returns {Message} + */ +export function normalizeOutRpcMessage(message: T & import(".").InMessage): Message; +//# sourceMappingURL=utils.d.ts.map \ No newline at end of file diff --git a/dist/src/pubsub/utils.d.ts.map b/dist/src/pubsub/utils.d.ts.map new file mode 100644 index 000000000..46e56dcbb --- /dev/null +++ b/dist/src/pubsub/utils.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/pubsub/utils.js"],"names":[],"mappings":"uBAUa,OAAO,eAAe,EAAE,GAAG,CAAC,QAAQ;sBACpC,OAAO,eAAe,EAAE,GAAG,CAAC,OAAO;iCACnC,OAAO,GAAG,EAAE,SAAS;AAHlC;;;;GAIG;AAEH;;;;;GAKG;AACH,+BAHa,UAAU,CAKtB;AAED;;;;;;;GAOG;AACH,4BALW,MAAM,SACN,UAAU,GACR,UAAU,CAStB;AAED;;;;;;GAMG;AACH,kCAJW,UAAU,GACR,UAAU,CAGyC;AAEhE;;;;;;;;GAQG;AACH,4BALW,IAAI,MAAM,CAAC,GAAC,MAAM,MAAM,CAAC,KACzB,IAAI,MAAM,CAAC,GAAC,MAAM,MAAM,CAAC,GACvB,OAAO,CAwBnB;AAED;;;;;;;GAOG;AACH,yDAMC;AAED;;;;;;;GAOG;AACH;WALqB,GAAG;oFAGX,kBAAkB,CAa9B;AAED;;;;;GAKG;AACH;WALqB,GAAG;WAAQ,GAAG;wCAGtB,OAAO,CAanB"} \ No newline at end of file diff --git a/dist/src/record/tests/index.d.ts b/dist/src/record/tests/index.d.ts new file mode 100644 index 000000000..eceb82ed7 --- /dev/null +++ b/dist/src/record/tests/index.d.ts @@ -0,0 +1,3 @@ +declare function _exports(test: any): void; +export = _exports; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/src/record/tests/index.d.ts.map b/dist/src/record/tests/index.d.ts.map new file mode 100644 index 000000000..91906b445 --- /dev/null +++ b/dist/src/record/tests/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/record/tests/index.js"],"names":[],"mappings":"AASiB,2CA0BhB"} \ No newline at end of file diff --git a/dist/src/record/types.d.ts b/dist/src/record/types.d.ts new file mode 100644 index 000000000..97212a4fd --- /dev/null +++ b/dist/src/record/types.d.ts @@ -0,0 +1,21 @@ +/** + * Record is the base implementation of a record that can be used as the payload of a libp2p envelope. + */ +export interface Record { + /** + * signature domain. + */ + domain: string; + /** + * identifier of the type of record + */ + codec: Uint8Array; + /** + * Marshal a record to be used in an envelope. + */ + marshal(): Uint8Array; + /** + * Verifies if the other provided Record is identical to this one. + */ + equals(other: unknown): boolean +} diff --git a/dist/src/stream-muxer/tests/base-test.d.ts b/dist/src/stream-muxer/tests/base-test.d.ts new file mode 100644 index 000000000..3c1a63cc3 --- /dev/null +++ b/dist/src/stream-muxer/tests/base-test.d.ts @@ -0,0 +1,3 @@ +declare function _exports(common: any): void; +export = _exports; +//# sourceMappingURL=base-test.d.ts.map \ No newline at end of file diff --git a/dist/src/stream-muxer/tests/base-test.d.ts.map b/dist/src/stream-muxer/tests/base-test.d.ts.map new file mode 100644 index 000000000..a4e7cf75e --- /dev/null +++ b/dist/src/stream-muxer/tests/base-test.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"base-test.d.ts","sourceRoot":"","sources":["../../../../src/stream-muxer/tests/base-test.js"],"names":[],"mappings":"AAkCiB,6CAwHhB"} \ No newline at end of file diff --git a/dist/src/stream-muxer/tests/close-test.d.ts b/dist/src/stream-muxer/tests/close-test.d.ts new file mode 100644 index 000000000..27187dd1f --- /dev/null +++ b/dist/src/stream-muxer/tests/close-test.d.ts @@ -0,0 +1,3 @@ +declare function _exports(common: any): void; +export = _exports; +//# sourceMappingURL=close-test.d.ts.map \ No newline at end of file diff --git a/dist/src/stream-muxer/tests/close-test.d.ts.map b/dist/src/stream-muxer/tests/close-test.d.ts.map new file mode 100644 index 000000000..c6ea4ae56 --- /dev/null +++ b/dist/src/stream-muxer/tests/close-test.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"close-test.d.ts","sourceRoot":"","sources":["../../../../src/stream-muxer/tests/close-test.js"],"names":[],"mappings":"AAiCiB,6CAsFhB"} \ No newline at end of file diff --git a/dist/src/stream-muxer/tests/index.d.ts b/dist/src/stream-muxer/tests/index.d.ts new file mode 100644 index 000000000..1c87129c7 --- /dev/null +++ b/dist/src/stream-muxer/tests/index.d.ts @@ -0,0 +1,3 @@ +declare function _exports(common: any): void; +export = _exports; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/src/stream-muxer/tests/index.d.ts.map b/dist/src/stream-muxer/tests/index.d.ts.map new file mode 100644 index 000000000..e5a45894a --- /dev/null +++ b/dist/src/stream-muxer/tests/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/stream-muxer/tests/index.js"],"names":[],"mappings":"AASiB,6CAUhB"} \ No newline at end of file diff --git a/dist/src/stream-muxer/tests/mega-stress-test.d.ts b/dist/src/stream-muxer/tests/mega-stress-test.d.ts new file mode 100644 index 000000000..63ef4ed17 --- /dev/null +++ b/dist/src/stream-muxer/tests/mega-stress-test.d.ts @@ -0,0 +1,3 @@ +declare function _exports(common: any): void; +export = _exports; +//# sourceMappingURL=mega-stress-test.d.ts.map \ No newline at end of file diff --git a/dist/src/stream-muxer/tests/mega-stress-test.d.ts.map b/dist/src/stream-muxer/tests/mega-stress-test.d.ts.map new file mode 100644 index 000000000..dad6f6c41 --- /dev/null +++ b/dist/src/stream-muxer/tests/mega-stress-test.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"mega-stress-test.d.ts","sourceRoot":"","sources":["../../../../src/stream-muxer/tests/mega-stress-test.js"],"names":[],"mappings":"AAMiB,6CAWhB"} \ No newline at end of file diff --git a/dist/src/stream-muxer/tests/spawner.d.ts b/dist/src/stream-muxer/tests/spawner.d.ts new file mode 100644 index 000000000..a2253e812 --- /dev/null +++ b/dist/src/stream-muxer/tests/spawner.d.ts @@ -0,0 +1,3 @@ +declare function _exports(Muxer: any, nStreams: any, nMsg: any, limit: any): Promise; +export = _exports; +//# sourceMappingURL=spawner.d.ts.map \ No newline at end of file diff --git a/dist/src/stream-muxer/tests/spawner.d.ts.map b/dist/src/stream-muxer/tests/spawner.d.ts.map new file mode 100644 index 000000000..3f9278dcd --- /dev/null +++ b/dist/src/stream-muxer/tests/spawner.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"spawner.d.ts","sourceRoot":"","sources":["../../../../src/stream-muxer/tests/spawner.js"],"names":[],"mappings":"AAUiB,2FAoDhB"} \ No newline at end of file diff --git a/dist/src/stream-muxer/tests/stress-test.d.ts b/dist/src/stream-muxer/tests/stress-test.d.ts new file mode 100644 index 000000000..1d786a798 --- /dev/null +++ b/dist/src/stream-muxer/tests/stress-test.d.ts @@ -0,0 +1,3 @@ +declare function _exports(common: any): void; +export = _exports; +//# sourceMappingURL=stress-test.d.ts.map \ No newline at end of file diff --git a/dist/src/stream-muxer/tests/stress-test.d.ts.map b/dist/src/stream-muxer/tests/stress-test.d.ts.map new file mode 100644 index 000000000..4ef4a7253 --- /dev/null +++ b/dist/src/stream-muxer/tests/stress-test.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"stress-test.d.ts","sourceRoot":"","sources":["../../../../src/stream-muxer/tests/stress-test.js"],"names":[],"mappings":"AAMiB,6CAwBhB"} \ No newline at end of file diff --git a/dist/src/stream-muxer/types.d.ts b/dist/src/stream-muxer/types.d.ts new file mode 100644 index 000000000..cf0c6f43a --- /dev/null +++ b/dist/src/stream-muxer/types.d.ts @@ -0,0 +1,51 @@ +import BufferList from 'bl' + +export interface MuxerFactory { + new (options: MuxerOptions): Muxer; + multicodec: string; +} + +/** + * A libp2p stream muxer + */ +export interface Muxer { + readonly streams: Array; + /** + * Initiate a new stream with the given name. If no name is + * provided, the id of th stream will be used. + */ + newStream (name?: string): MuxedStream; + + /** + * A function called when receiving a new stream from the remote. + */ + onStream (stream: MuxedStream): void; + + /** + * A function called when a stream ends. + */ + onStreamEnd (stream: MuxedStream): void; +} + +export type MuxerOptions = { + onStream: (stream: MuxedStream) => void; + onStreamEnd: (stream: MuxedStream) => void; + maxMsgSize?: number; +} + +export type MuxedTimeline = { + open: number; + close?: number; +} + +export interface MuxedStream extends AsyncIterable { + close: () => void; + abort: () => void; + reset: () => void; + sink: Sink; + source: AsyncIterable; + timeline: MuxedTimeline; + id: string; +} + +export type Sink = (source: Uint8Array) => Promise; diff --git a/dist/src/topology/index.d.ts b/dist/src/topology/index.d.ts new file mode 100644 index 000000000..773844dfb --- /dev/null +++ b/dist/src/topology/index.d.ts @@ -0,0 +1,79 @@ +export = Topology; +/** + * @typedef {import('peer-id')} PeerId + */ +/** + * @typedef {Object} Options + * @property {number} [min=0] - minimum needed connections. + * @property {number} [max=Infinity] - maximum needed connections. + * @property {Handlers} [handlers] + * + * @typedef {Object} Handlers + * @property {(peerId: PeerId, conn: Connection) => void} [onConnect] - protocol "onConnect" handler + * @property {(peerId: PeerId, error?:Error) => void} [onDisconnect] - protocol "onDisconnect" handler + * + * @typedef {import('../connection/connection')} Connection + */ +declare class Topology { + /** + * Checks if the given value is a Topology instance. + * + * @param {any} other + * @returns {other is Topology} + */ + static isTopology(other: any): other is Topology; + /** + * @param {Options} options + */ + constructor({ min, max, handlers }: Options); + min: number; + max: number; + _onConnect: (peerId: PeerId, conn: Connection) => void; + _onDisconnect: (peerId: PeerId, error?: Error | undefined) => void; + /** + * Set of peers that support the protocol. + * + * @type {Set} + */ + peers: Set; + get [Symbol.toStringTag](): string; + /** + * @param {any} registrar + */ + set registrar(arg: any); + _registrar: any; + /** + * Notify about peer disconnected event. + * + * @param {PeerId} peerId + * @returns {void} + */ + disconnect(peerId: PeerId): void; +} +declare namespace Topology { + export { PeerId, Options, Handlers, Connection }; +} +type PeerId = import('peer-id'); +type Connection = import('../connection/connection'); +type Options = { + /** + * - minimum needed connections. + */ + min?: number | undefined; + /** + * - maximum needed connections. + */ + max?: number | undefined; + handlers?: Handlers | undefined; +}; +type Handlers = { + /** + * - protocol "onConnect" handler + */ + onConnect?: ((peerId: PeerId, conn: Connection) => void) | undefined; + /** + * - protocol "onDisconnect" handler + */ + onDisconnect?: ((peerId: PeerId, error?: Error | undefined) => void) | undefined; +}; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/src/topology/index.d.ts.map b/dist/src/topology/index.d.ts.map new file mode 100644 index 000000000..ece35a29d --- /dev/null +++ b/dist/src/topology/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/topology/index.js"],"names":[],"mappings":";AAKA;;GAEG;AAEH;;;;;;;;;;;GAWG;AAEH;IAgCE;;;;;OAKG;IACH,yBAHW,GAAG,qBAKb;IAvCD;;OAEG;IACH,oCAFW,OAAO,EAoBjB;IAbC,YAAc;IACd,YAAc;IAGd,qBAnBmB,MAAM,QAAQ,UAAU,KAAK,IAAI,CAmBR;IAC5C,wBAnBmB,MAAM,gCAAmB,IAAI,CAmBE;IAElD;;;;OAIG;IACH,OAFU,IAAI,MAAM,CAAC,CAEC;IAGxB,mCAEC;IAgBD;;OAEG;IACH,wBAEC;IADC,gBAA2B;IAG7B;;;;;OAKG;IACH,mBAHW,MAAM,GACJ,IAAI,CAIhB;CACF;;;;cA1EY,OAAO,SAAS,CAAC;kBAajB,OAAO,0BAA0B,CAAC;;;;;;;;;;;;;;;;0BAHxB,MAAM,QAAQ,UAAU,KAAK,IAAI;;;;6BACjC,MAAM,gCAAmB,IAAI"} \ No newline at end of file diff --git a/dist/src/topology/multicodec-topology.d.ts b/dist/src/topology/multicodec-topology.d.ts new file mode 100644 index 000000000..f5c392e01 --- /dev/null +++ b/dist/src/topology/multicodec-topology.d.ts @@ -0,0 +1,61 @@ +export = MulticodecTopology; +declare class MulticodecTopology extends Topology { + /** + * Checks if the given value is a `MulticodecTopology` instance. + * + * @param {any} other + * @returns {other is MulticodecTopology} + */ + static isMulticodecTopology(other: any): other is MulticodecTopology; + /** + * @param {TopologyOptions & MulticodecOptions} props + */ + constructor({ min, max, multicodecs, handlers }: TopologyOptions & MulticodecOptions); + multicodecs: string[]; + /** + * Check if a new peer support the multicodecs for this topology. + * + * @param {Object} props + * @param {PeerId} props.peerId + * @param {Array} props.protocols + */ + _onProtocolChange({ peerId, protocols }: { + peerId: PeerId; + protocols: Array; + }): void; + /** + * Verify if a new connected peer has a topology multicodec and call _onConnect. + * + * @param {Connection} connection + * @returns {void} + */ + _onPeerConnect(connection: Connection): void; + /** + * Update topology. + * + * @param {Array<{id: PeerId, multiaddrs: Array, protocols: Array}>} peerDataIterable + * @returns {void} + */ + _updatePeers(peerDataIterable: Array<{ + id: PeerId; + multiaddrs: Array; + protocols: Array; + }>): void; +} +declare namespace MulticodecTopology { + export { PeerId, Multiaddr, Connection, TopologyOptions, MulticodecOptions, Handlers }; +} +import Topology = require("./index"); +type PeerId = import('peer-id'); +type Connection = import('../connection/connection'); +type Multiaddr = typeof import("multiaddr"); +type TopologyOptions = import('.').Options; +type MulticodecOptions = { + /** + * - protocol multicodecs + */ + multicodecs: string[]; + handlers: Required; +}; +type Handlers = import('.').Handlers; +//# sourceMappingURL=multicodec-topology.d.ts.map \ No newline at end of file diff --git a/dist/src/topology/multicodec-topology.d.ts.map b/dist/src/topology/multicodec-topology.d.ts.map new file mode 100644 index 000000000..4bd71b922 --- /dev/null +++ b/dist/src/topology/multicodec-topology.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"multicodec-topology.d.ts","sourceRoot":"","sources":["../../../src/topology/multicodec-topology.js"],"names":[],"mappings":";AAKA;IA2CE;;;;;OAKG;IACH,mCAHW,GAAG,+BAKb;IAlDD;;OAEG;IACH,iDAFW,eAAe,GAAG,iBAAiB,EA+B7C;IALC,sBAA2E;IA0D7E;;;;;;OAMG;IACH;QAHyB,MAAM,EAApB,MAAM;QACe,SAAS,EAA9B,MAAM,MAAM,CAAC;aAmBvB;IAED;;;;;OAKG;IACH,2BAHW,UAAU,GACR,IAAI,CAehB;IAlED;;;;;OAKG;IACH,+BAHW,MAAM;QAAC,EAAE,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,SAAS,CAAC,CAAC;QAAC,SAAS,EAAE,MAAM,MAAM,CAAC,CAAA;KAAC,CAAC,GACzE,IAAI,CAehB;CAgDF;;;;;cAGY,OAAO,SAAS,CAAC;kBAEjB,OAAO,0BAA0B,CAAC;;uBAClC,OAAO,GAAG,EAAE,OAAO;;;;;iBAElB,MAAM,EAAE;cACR,SAAS,QAAQ,CAAC;;gBACnB,OAAO,GAAG,EAAE,QAAQ"} \ No newline at end of file diff --git a/dist/src/topology/tests/multicodec-topology.d.ts b/dist/src/topology/tests/multicodec-topology.d.ts new file mode 100644 index 000000000..0eebeed6e --- /dev/null +++ b/dist/src/topology/tests/multicodec-topology.d.ts @@ -0,0 +1,3 @@ +declare function _exports(test: any): void; +export = _exports; +//# sourceMappingURL=multicodec-topology.d.ts.map \ No newline at end of file diff --git a/dist/src/topology/tests/multicodec-topology.d.ts.map b/dist/src/topology/tests/multicodec-topology.d.ts.map new file mode 100644 index 000000000..95389f44f --- /dev/null +++ b/dist/src/topology/tests/multicodec-topology.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"multicodec-topology.d.ts","sourceRoot":"","sources":["../../../../src/topology/tests/multicodec-topology.js"],"names":[],"mappings":"AAciB,2CAuHhB"} \ No newline at end of file diff --git a/dist/src/topology/tests/topology.d.ts b/dist/src/topology/tests/topology.d.ts new file mode 100644 index 000000000..a06009178 --- /dev/null +++ b/dist/src/topology/tests/topology.d.ts @@ -0,0 +1,3 @@ +declare function _exports(test: any): void; +export = _exports; +//# sourceMappingURL=topology.d.ts.map \ No newline at end of file diff --git a/dist/src/topology/tests/topology.d.ts.map b/dist/src/topology/tests/topology.d.ts.map new file mode 100644 index 000000000..c8005d01e --- /dev/null +++ b/dist/src/topology/tests/topology.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"topology.d.ts","sourceRoot":"","sources":["../../../../src/topology/tests/topology.js"],"names":[],"mappings":"AAaiB,2CA+BhB"} \ No newline at end of file diff --git a/dist/src/transport/errors.d.ts b/dist/src/transport/errors.d.ts new file mode 100644 index 000000000..1bf989b16 --- /dev/null +++ b/dist/src/transport/errors.d.ts @@ -0,0 +1,8 @@ +export class AbortError extends Error { + static get code(): string; + static get type(): string; + constructor(); + code: string; + type: string; +} +//# sourceMappingURL=errors.d.ts.map \ No newline at end of file diff --git a/dist/src/transport/errors.d.ts.map b/dist/src/transport/errors.d.ts.map new file mode 100644 index 000000000..fa74234e7 --- /dev/null +++ b/dist/src/transport/errors.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/transport/errors.js"],"names":[],"mappings":"AAEA;IAOE,0BAEC;IAED,0BAEC;IAZD,cAIC;IAFC,aAA2B;IAC3B,aAA2B;CAU9B"} \ No newline at end of file diff --git a/dist/src/transport/tests/dial-test.d.ts b/dist/src/transport/tests/dial-test.d.ts new file mode 100644 index 000000000..d25ebfea9 --- /dev/null +++ b/dist/src/transport/tests/dial-test.d.ts @@ -0,0 +1,3 @@ +declare function _exports(common: any): void; +export = _exports; +//# sourceMappingURL=dial-test.d.ts.map \ No newline at end of file diff --git a/dist/src/transport/tests/dial-test.d.ts.map b/dist/src/transport/tests/dial-test.d.ts.map new file mode 100644 index 000000000..b09b1a8e8 --- /dev/null +++ b/dist/src/transport/tests/dial-test.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"dial-test.d.ts","sourceRoot":"","sources":["../../../../src/transport/tests/dial-test.js"],"names":[],"mappings":"AAiBiB,6CA0LhB"} \ No newline at end of file diff --git a/dist/src/transport/tests/filter-test.d.ts b/dist/src/transport/tests/filter-test.d.ts new file mode 100644 index 000000000..4a1171840 --- /dev/null +++ b/dist/src/transport/tests/filter-test.d.ts @@ -0,0 +1,3 @@ +declare function _exports(common: any): void; +export = _exports; +//# sourceMappingURL=filter-test.d.ts.map \ No newline at end of file diff --git a/dist/src/transport/tests/filter-test.d.ts.map b/dist/src/transport/tests/filter-test.d.ts.map new file mode 100644 index 000000000..fdba9b1b2 --- /dev/null +++ b/dist/src/transport/tests/filter-test.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"filter-test.d.ts","sourceRoot":"","sources":["../../../../src/transport/tests/filter-test.js"],"names":[],"mappings":"AASiB,6CA4BhB"} \ No newline at end of file diff --git a/dist/src/transport/tests/index.d.ts b/dist/src/transport/tests/index.d.ts new file mode 100644 index 000000000..1c87129c7 --- /dev/null +++ b/dist/src/transport/tests/index.d.ts @@ -0,0 +1,3 @@ +declare function _exports(common: any): void; +export = _exports; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/src/transport/tests/index.d.ts.map b/dist/src/transport/tests/index.d.ts.map new file mode 100644 index 000000000..35fb611ca --- /dev/null +++ b/dist/src/transport/tests/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/transport/tests/index.js"],"names":[],"mappings":"AAQiB,6CAMhB"} \ No newline at end of file diff --git a/dist/src/transport/tests/listen-test.d.ts b/dist/src/transport/tests/listen-test.d.ts new file mode 100644 index 000000000..c15df5300 --- /dev/null +++ b/dist/src/transport/tests/listen-test.d.ts @@ -0,0 +1,3 @@ +declare function _exports(common: any): void; +export = _exports; +//# sourceMappingURL=listen-test.d.ts.map \ No newline at end of file diff --git a/dist/src/transport/tests/listen-test.d.ts.map b/dist/src/transport/tests/listen-test.d.ts.map new file mode 100644 index 000000000..1df084d1f --- /dev/null +++ b/dist/src/transport/tests/listen-test.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"listen-test.d.ts","sourceRoot":"","sources":["../../../../src/transport/tests/listen-test.js"],"names":[],"mappings":"AAgBiB,6CAmJhB"} \ No newline at end of file diff --git a/dist/src/transport/tests/utils/index.d.ts b/dist/src/transport/tests/utils/index.d.ts new file mode 100644 index 000000000..43f1d8607 --- /dev/null +++ b/dist/src/transport/tests/utils/index.d.ts @@ -0,0 +1,2 @@ +export function isValidTick(date: number, ms?: number): boolean; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/src/transport/tests/utils/index.d.ts.map b/dist/src/transport/tests/utils/index.d.ts.map new file mode 100644 index 000000000..1ea39b6e5 --- /dev/null +++ b/dist/src/transport/tests/utils/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/transport/tests/utils/index.js"],"names":[],"mappings":"AAWe,gEAIZ"} \ No newline at end of file diff --git a/dist/src/transport/types.d.ts b/dist/src/transport/types.d.ts new file mode 100644 index 000000000..d946ea1fb --- /dev/null +++ b/dist/src/transport/types.d.ts @@ -0,0 +1,72 @@ +import BufferList from 'bl' +import events from 'events' +import { Multiaddr } from 'multiaddr' +import Connection from '../connection/connection' +import { Sink } from '../stream-muxer/types' + +export interface TransportFactory { + new(upgrader: Upgrader): Transport; +} + +/** + * A libp2p transport is understood as something that offers a dial and listen interface to establish connections. + */ +export interface Transport { + /** + * Dial a given multiaddr. + */ + dial(ma: Multiaddr, options?: DialOptions): Promise; + /** + * Create transport listeners. + */ + createListener(options: ListenerOptions, handler?: (connection: Connection) => void): Listener; + /** + * Takes a list of `Multiaddr`s and returns only valid addresses for the transport + */ + filter(multiaddrs: Multiaddr[]): Multiaddr[]; +} + +export interface Listener extends events.EventEmitter { + /** + * Start a listener + */ + listen(multiaddr: Multiaddr): Promise; + /** + * Get listen addresses + */ + getAddrs(): Multiaddr[]; + /** + * Close listener + * + * @returns {Promise} + */ + close(): Promise; +} + +export interface Upgrader { + /** + * Upgrades an outbound connection on `transport.dial`. + */ + upgradeOutbound(maConn: MultiaddrConnection): Promise; + + /** + * Upgrades an inbound connection on transport listener. + */ + upgradeInbound(maConn: MultiaddrConnection): Promise; +} + +export type MultiaddrConnectionTimeline = { + open: number; + upgraded?: number; + close?: number; +} + +export type MultiaddrConnection = { + sink: Sink; + source: AsyncIterable; + close: (err?: Error) => Promise; + conn: unknown; + remoteAddr: Multiaddr; + localAddr?: Multiaddr; + timeline: MultiaddrConnectionTimeline; +} diff --git a/dist/src/types.d.ts b/dist/src/types.d.ts new file mode 100644 index 000000000..f84df7a75 --- /dev/null +++ b/dist/src/types.d.ts @@ -0,0 +1,5 @@ +export type SelectFn = (key: Uint8Array, records: Uint8Array[]) => number +export type ValidateFn = (a: Uint8Array, b: Uint8Array) => Promise + +export type DhtSelectors = { [key: string]: SelectFn } +export type DhtValidators = { [key: string]: { func: ValidateFn } } diff --git a/dist/src/utils/peers.d.ts b/dist/src/utils/peers.d.ts new file mode 100644 index 000000000..f37e07b1d --- /dev/null +++ b/dist/src/utils/peers.d.ts @@ -0,0 +1,376 @@ +declare const _exports: { + [n: number]: { + id: string; + privKey: string; + pubKey: string; + }; + length: number; + toString(): string; + toLocaleString(): string; + pop(): { + id: string; + privKey: string; + pubKey: string; + } | undefined; + push(...items: { + id: string; + privKey: string; + pubKey: string; + }[]): number; + concat(...items: ConcatArray<{ + id: string; + privKey: string; + pubKey: string; + }>[]): { + id: string; + privKey: string; + pubKey: string; + }[]; + concat(...items: ({ + id: string; + privKey: string; + pubKey: string; + } | ConcatArray<{ + id: string; + privKey: string; + pubKey: string; + }>)[]): { + id: string; + privKey: string; + pubKey: string; + }[]; + join(separator?: string | undefined): string; + reverse(): { + id: string; + privKey: string; + pubKey: string; + }[]; + shift(): { + id: string; + privKey: string; + pubKey: string; + } | undefined; + slice(start?: number | undefined, end?: number | undefined): { + id: string; + privKey: string; + pubKey: string; + }[]; + sort(compareFn?: ((a: { + id: string; + privKey: string; + pubKey: string; + }, b: { + id: string; + privKey: string; + pubKey: string; + }) => number) | undefined): { + id: string; + privKey: string; + pubKey: string; + }[]; + splice(start: number, deleteCount?: number | undefined): { + id: string; + privKey: string; + pubKey: string; + }[]; + splice(start: number, deleteCount: number, ...items: { + id: string; + privKey: string; + pubKey: string; + }[]): { + id: string; + privKey: string; + pubKey: string; + }[]; + unshift(...items: { + id: string; + privKey: string; + pubKey: string; + }[]): number; + indexOf(searchElement: { + id: string; + privKey: string; + pubKey: string; + }, fromIndex?: number | undefined): number; + lastIndexOf(searchElement: { + id: string; + privKey: string; + pubKey: string; + }, fromIndex?: number | undefined): number; + every(predicate: (value: { + id: string; + privKey: string; + pubKey: string; + }, index: number, array: { + id: string; + privKey: string; + pubKey: string; + }[]) => value is S, thisArg?: any): this is S[]; + every(predicate: (value: { + id: string; + privKey: string; + pubKey: string; + }, index: number, array: { + id: string; + privKey: string; + pubKey: string; + }[]) => unknown, thisArg?: any): boolean; + some(predicate: (value: { + id: string; + privKey: string; + pubKey: string; + }, index: number, array: { + id: string; + privKey: string; + pubKey: string; + }[]) => unknown, thisArg?: any): boolean; + forEach(callbackfn: (value: { + id: string; + privKey: string; + pubKey: string; + }, index: number, array: { + id: string; + privKey: string; + pubKey: string; + }[]) => void, thisArg?: any): void; + map(callbackfn: (value: { + id: string; + privKey: string; + pubKey: string; + }, index: number, array: { + id: string; + privKey: string; + pubKey: string; + }[]) => U, thisArg?: any): U[]; + filter(predicate: (value: { + id: string; + privKey: string; + pubKey: string; + }, index: number, array: { + id: string; + privKey: string; + pubKey: string; + }[]) => value is S_1, thisArg?: any): S_1[]; + filter(predicate: (value: { + id: string; + privKey: string; + pubKey: string; + }, index: number, array: { + id: string; + privKey: string; + pubKey: string; + }[]) => unknown, thisArg?: any): { + id: string; + privKey: string; + pubKey: string; + }[]; + reduce(callbackfn: (previousValue: { + id: string; + privKey: string; + pubKey: string; + }, currentValue: { + id: string; + privKey: string; + pubKey: string; + }, currentIndex: number, array: { + id: string; + privKey: string; + pubKey: string; + }[]) => { + id: string; + privKey: string; + pubKey: string; + }): { + id: string; + privKey: string; + pubKey: string; + }; + reduce(callbackfn: (previousValue: { + id: string; + privKey: string; + pubKey: string; + }, currentValue: { + id: string; + privKey: string; + pubKey: string; + }, currentIndex: number, array: { + id: string; + privKey: string; + pubKey: string; + }[]) => { + id: string; + privKey: string; + pubKey: string; + }, initialValue: { + id: string; + privKey: string; + pubKey: string; + }): { + id: string; + privKey: string; + pubKey: string; + }; + reduce(callbackfn: (previousValue: U_1, currentValue: { + id: string; + privKey: string; + pubKey: string; + }, currentIndex: number, array: { + id: string; + privKey: string; + pubKey: string; + }[]) => U_1, initialValue: U_1): U_1; + reduceRight(callbackfn: (previousValue: { + id: string; + privKey: string; + pubKey: string; + }, currentValue: { + id: string; + privKey: string; + pubKey: string; + }, currentIndex: number, array: { + id: string; + privKey: string; + pubKey: string; + }[]) => { + id: string; + privKey: string; + pubKey: string; + }): { + id: string; + privKey: string; + pubKey: string; + }; + reduceRight(callbackfn: (previousValue: { + id: string; + privKey: string; + pubKey: string; + }, currentValue: { + id: string; + privKey: string; + pubKey: string; + }, currentIndex: number, array: { + id: string; + privKey: string; + pubKey: string; + }[]) => { + id: string; + privKey: string; + pubKey: string; + }, initialValue: { + id: string; + privKey: string; + pubKey: string; + }): { + id: string; + privKey: string; + pubKey: string; + }; + reduceRight(callbackfn: (previousValue: U_2, currentValue: { + id: string; + privKey: string; + pubKey: string; + }, currentIndex: number, array: { + id: string; + privKey: string; + pubKey: string; + }[]) => U_2, initialValue: U_2): U_2; + find(predicate: (this: void, value: { + id: string; + privKey: string; + pubKey: string; + }, index: number, obj: { + id: string; + privKey: string; + pubKey: string; + }[]) => value is S_2, thisArg?: any): S_2 | undefined; + find(predicate: (value: { + id: string; + privKey: string; + pubKey: string; + }, index: number, obj: { + id: string; + privKey: string; + pubKey: string; + }[]) => unknown, thisArg?: any): { + id: string; + privKey: string; + pubKey: string; + } | undefined; + findIndex(predicate: (value: { + id: string; + privKey: string; + pubKey: string; + }, index: number, obj: { + id: string; + privKey: string; + pubKey: string; + }[]) => unknown, thisArg?: any): number; + fill(value: { + id: string; + privKey: string; + pubKey: string; + }, start?: number | undefined, end?: number | undefined): { + id: string; + privKey: string; + pubKey: string; + }[]; + copyWithin(target: number, start: number, end?: number | undefined): { + id: string; + privKey: string; + pubKey: string; + }[]; + [Symbol.iterator](): IterableIterator<{ + id: string; + privKey: string; + pubKey: string; + }>; + entries(): IterableIterator<[number, { + id: string; + privKey: string; + pubKey: string; + }]>; + keys(): IterableIterator; + values(): IterableIterator<{ + id: string; + privKey: string; + pubKey: string; + }>; + [Symbol.unscopables](): { + copyWithin: boolean; + entries: boolean; + fill: boolean; + find: boolean; + findIndex: boolean; + keys: boolean; + values: boolean; + }; + includes(searchElement: { + id: string; + privKey: string; + pubKey: string; + }, fromIndex?: number | undefined): boolean; + flatMap(callback: (this: This, value: { + id: string; + privKey: string; + pubKey: string; + }, index: number, array: { + id: string; + privKey: string; + pubKey: string; + }[]) => U_3 | readonly U_3[], thisArg?: This | undefined): U_3[]; + flat(this: A, depth?: D | undefined): FlatArray[]; +}; +export = _exports; +//# sourceMappingURL=peers.d.ts.map \ No newline at end of file diff --git a/dist/src/utils/peers.d.ts.map b/dist/src/utils/peers.d.ts.map new file mode 100644 index 000000000..573e8f393 --- /dev/null +++ b/dist/src/utils/peers.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"peers.d.ts","sourceRoot":"","sources":["../../../src/utils/peers.js"],"names":[],"mappings":""} \ No newline at end of file diff --git a/src/content-routing/types.d.ts b/src/content-routing/types.d.ts index 49dba9542..c8f1b57d8 100644 --- a/src/content-routing/types.d.ts +++ b/src/content-routing/types.d.ts @@ -1,11 +1,14 @@ -export = ContentRouting; - import PeerId from 'peer-id' import { Multiaddr } from 'multiaddr' import CID from 'cids' -declare class ContentRouting { - constructor (options: Object); +export interface ContentRoutingFactory { + new (options?: any): ContentRouting; +} + +export interface ContentRouting { provide (cid: CID): Promise; findProviders (cid: CID, options: Object): AsyncIterable<{ id: PeerId, multiaddrs: Multiaddr[] }>; } + +export default ContentRouting; diff --git a/src/peer-discovery/types.d.ts b/src/peer-discovery/types.d.ts index db383cbd3..b5bfc9420 100644 --- a/src/peer-discovery/types.d.ts +++ b/src/peer-discovery/types.d.ts @@ -1,10 +1,13 @@ -export = PeerDiscovery; +import { EventEmitter } from 'events'; -import events from 'events'; - -declare class PeerDiscovery extends events.EventEmitter { - constructor (options: Object); - start (): Promise; - stop (): Promise; +export interface PeerDiscoveryFactory { + new (options?: any): PeerDiscovery; tag: string; } + +export interface PeerDiscovery extends EventEmitter { + start(): void|Promise; + stop(): void|Promise; +} + +export default PeerDiscovery; diff --git a/src/peer-routing/types.d.ts b/src/peer-routing/types.d.ts index df61c2db5..96b448f28 100644 --- a/src/peer-routing/types.d.ts +++ b/src/peer-routing/types.d.ts @@ -1,10 +1,13 @@ -export = PeerRouting; - import PeerId from 'peer-id' import { Multiaddr } from 'multiaddr' -declare class PeerRouting { - constructor (options?: Object); +export interface PeerRoutingFactory { + new (options?: any): PeerRouting; +} + +export interface PeerRouting { findPeer (peerId: PeerId, options?: Object): Promise<{ id: PeerId, multiaddrs: Multiaddr[] }>; getClosestPeers(key: Uint8Array, options?: Object): AsyncIterable<{ id: PeerId, multiaddrs: Multiaddr[] }>; } + +export default PeerRouting; diff --git a/src/pubsub/index.js b/src/pubsub/index.js index e74848469..1697c99aa 100644 --- a/src/pubsub/index.js +++ b/src/pubsub/index.js @@ -1,9 +1,7 @@ 'use strict' const debug = require('debug') -/** @typedef {import('../types').EventEmitterFactory} Events */ -/** @type Events */ -const EventEmitter = require('events') +const { EventEmitter } = require('events') const errcode = require('err-code') const { pipe } = require('it-pipe') diff --git a/src/pubsub/peer-streams.js b/src/pubsub/peer-streams.js index 94ff2622b..d603699a7 100644 --- a/src/pubsub/peer-streams.js +++ b/src/pubsub/peer-streams.js @@ -4,9 +4,7 @@ const debug = require('debug') const log = Object.assign(debug('libp2p-pubsub:peer-streams'), { error: debug('libp2p-pubsub:peer-streams:err') }) -/** @typedef {import('../types').EventEmitterFactory} Events */ -/** @type Events */ -const EventEmitter = require('events') +const { EventEmitter } = require('events') const lp = require('it-length-prefixed') const pushable = require('it-pushable') diff --git a/src/types.d.ts b/src/types.d.ts index bac8dcfd7..f84df7a75 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -3,22 +3,3 @@ export type ValidateFn = (a: Uint8Array, b: Uint8Array) => Promise export type DhtSelectors = { [key: string]: SelectFn } export type DhtValidators = { [key: string]: { func: ValidateFn } } - -export interface EventEmitterFactory { - new(): EventEmitter; -} - -export interface EventEmitter { - addListener(event: string | symbol, listener: (...args: any[]) => void): EventEmitter; - on(event: string | symbol, listener: (...args: any[]) => void): EventEmitter; - once(event: string | symbol, listener: (...args: any[]) => void): EventEmitter; - removeListener(event: string | symbol, listener: (...args: any[]) => void): EventEmitter; - off(event: string | symbol, listener: (...args: any[]) => void): EventEmitter; - removeAllListeners(event?: string | symbol): EventEmitter; - setMaxListeners(n: number): EventEmitter; - getMaxListeners(): number; - listeners(event: string | symbol): Function[]; // eslint-disable-line @typescript-eslint/ban-types - rawListeners(event: string | symbol): Function[]; // eslint-disable-line @typescript-eslint/ban-types - emit(event: string | symbol, ...args: any[]): boolean; - listenerCount(event: string | symbol): number; -}