Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@libp2p/interface

Package Overview
Dependencies
Maintainers
6
Versions
535
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@libp2p/interface - npm Package Compare versions

Comparing version 0.1.2-f09ac4a7 to 0.1.2-f1053159

4

dist/src/connection-encrypter/index.d.ts

@@ -14,3 +14,3 @@ import type { PeerId } from '../peer-id/index.js';

*/
secureOutbound: (localPeer: PeerId, connection: Duplex<AsyncGenerator<Uint8Array>, Source<Uint8Array>, Promise<void>>, remotePeer?: PeerId) => Promise<SecuredConnection<Extension>>;
secureOutbound(localPeer: PeerId, connection: Duplex<AsyncGenerator<Uint8Array>, Source<Uint8Array>, Promise<void>>, remotePeer?: PeerId): Promise<SecuredConnection<Extension>>;
/**

@@ -21,3 +21,3 @@ * Decrypt incoming data. If the remote PeerId is known,

*/
secureInbound: (localPeer: PeerId, connection: Duplex<AsyncGenerator<Uint8Array>, Source<Uint8Array>, Promise<void>>, remotePeer?: PeerId) => Promise<SecuredConnection<Extension>>;
secureInbound(localPeer: PeerId, connection: Duplex<AsyncGenerator<Uint8Array>, Source<Uint8Array>, Promise<void>>, remotePeer?: PeerId): Promise<SecuredConnection<Extension>>;
}

@@ -24,0 +24,0 @@ export interface SecuredConnection<Extension = unknown> {

@@ -14,3 +14,3 @@ import type { MultiaddrConnection } from '../connection/index.js';

*/
denyDialPeer?: (peerId: PeerId) => Promise<boolean>;
denyDialPeer?(peerId: PeerId): Promise<boolean>;
/**

@@ -25,3 +25,3 @@ * denyDialMultiaddr tests whether we're permitted to dial the specified

*/
denyDialMultiaddr?: (multiaddr: Multiaddr) => Promise<boolean>;
denyDialMultiaddr?(multiaddr: Multiaddr): Promise<boolean>;
/**

@@ -35,3 +35,3 @@ * denyInboundConnection tests whether an incipient inbound connection is allowed.

*/
denyInboundConnection?: (maConn: MultiaddrConnection) => Promise<boolean>;
denyInboundConnection?(maConn: MultiaddrConnection): Promise<boolean>;
/**

@@ -45,3 +45,3 @@ * denyOutboundConnection tests whether an incipient outbound connection is allowed.

*/
denyOutboundConnection?: (peerId: PeerId, maConn: MultiaddrConnection) => Promise<boolean>;
denyOutboundConnection?(peerId: PeerId, maConn: MultiaddrConnection): Promise<boolean>;
/**

@@ -57,3 +57,3 @@ * denyInboundEncryptedConnection tests whether a given connection, now encrypted,

*/
denyInboundEncryptedConnection?: (peerId: PeerId, maConn: MultiaddrConnection) => Promise<boolean>;
denyInboundEncryptedConnection?(peerId: PeerId, maConn: MultiaddrConnection): Promise<boolean>;
/**

@@ -69,3 +69,3 @@ * denyOutboundEncryptedConnection tests whether a given connection, now encrypted,

*/
denyOutboundEncryptedConnection?: (peerId: PeerId, maConn: MultiaddrConnection) => Promise<boolean>;
denyOutboundEncryptedConnection?(peerId: PeerId, maConn: MultiaddrConnection): Promise<boolean>;
/**

@@ -79,3 +79,3 @@ * denyInboundUpgradedConnection tests whether a fully capable connection is allowed.

*/
denyInboundUpgradedConnection?: (peerId: PeerId, maConn: MultiaddrConnection) => Promise<boolean>;
denyInboundUpgradedConnection?(peerId: PeerId, maConn: MultiaddrConnection): Promise<boolean>;
/**

@@ -89,3 +89,3 @@ * denyOutboundUpgradedConnection tests whether a fully capable connection is allowed.

*/
denyOutboundUpgradedConnection?: (peerId: PeerId, maConn: MultiaddrConnection) => Promise<boolean>;
denyOutboundUpgradedConnection?(peerId: PeerId, maConn: MultiaddrConnection): Promise<boolean>;
/**

@@ -97,3 +97,3 @@ * denyInboundRelayReservation tests whether a remote peer is allowed make a

*/
denyInboundRelayReservation?: (source: PeerId) => Promise<boolean>;
denyInboundRelayReservation?(source: PeerId): Promise<boolean>;
/**

@@ -108,3 +108,3 @@ * denyOutboundRelayedConnection tests whether a remote peer is allowed to open a relayed

*/
denyOutboundRelayedConnection?: (source: PeerId, destination: PeerId) => Promise<boolean>;
denyOutboundRelayedConnection?(source: PeerId, destination: PeerId): Promise<boolean>;
/**

@@ -119,3 +119,3 @@ * denyInboundRelayedConnection tests whether a remote peer is allowed to open a relayed

*/
denyInboundRelayedConnection?: (relay: PeerId, remotePeer: PeerId) => Promise<boolean>;
denyInboundRelayedConnection?(relay: PeerId, remotePeer: PeerId): Promise<boolean>;
/**

@@ -126,4 +126,4 @@ * Used by the address book to filter passed addresses.

*/
filterMultiaddrForPeer?: (peer: PeerId, multiaddr: Multiaddr) => Promise<boolean>;
filterMultiaddrForPeer?(peer: PeerId, multiaddr: Multiaddr): Promise<boolean>;
}
//# sourceMappingURL=index.d.ts.map

@@ -90,3 +90,3 @@ import type { AbortOptions } from '../index.js';

*/
close: (options?: AbortOptions) => Promise<void>;
close(options?: AbortOptions): Promise<void>;
/**

@@ -99,3 +99,3 @@ * Closes the stream for **reading**. If iterating over the source of this stream in a `for await of` loop, it will return (exit the loop) after any buffered data has been consumed.

*/
closeRead: (options?: AbortOptions) => Promise<void>;
closeRead(options?: AbortOptions): Promise<void>;
/**

@@ -106,3 +106,3 @@ * Closes the stream for **writing**. If iterating over the source of this stream in a `for await of` loop, it will return (exit the loop) after any buffered data has been consumed.

*/
closeWrite: (options?: AbortOptions) => Promise<void>;
closeWrite(options?: AbortOptions): Promise<void>;
/**

@@ -117,3 +117,3 @@ * Closes the stream for **reading** *and* **writing**. This should be called when a *local error* has occurred.

*/
abort: (err: Error) => void;
abort(err: Error): void;
/**

@@ -132,3 +132,3 @@ * Unique identifier for a stream. Identifiers are not unique across muxers.

/**
* Once a protocol has been negotiated for this stream, it will be set on the stat object
* The protocol negotiated for this stream
*/

@@ -203,7 +203,7 @@ protocol?: string;

/**
* Once a multiplexer has been negotiated for this stream, it will be set on the stat object
* The multiplexer negotiated for this connection
*/
multiplexer?: string;
/**
* Once a connection encrypter has been negotiated for this stream, it will be set on the stat object
* The encryption protocol negotiated for this connection
*/

@@ -225,3 +225,3 @@ encryption?: string;

*/
newStream: (protocols: string | string[], options?: NewStreamOptions) => Promise<Stream>;
newStream(protocols: string | string[], options?: NewStreamOptions): Promise<Stream>;
/**

@@ -231,7 +231,7 @@ * Gracefully close the connection. All queued data will be written to the

*/
close: (options?: AbortOptions) => Promise<void>;
close(options?: AbortOptions): Promise<void>;
/**
* Immediately close the connection, any queued data will be discarded
*/
abort: (err: Error) => void;
abort(err: Error): void;
}

@@ -246,3 +246,3 @@ export declare const symbol: unique symbol;

*/
protect: (connection: MultiaddrConnection) => Promise<MultiaddrConnection>;
protect(connection: MultiaddrConnection): Promise<MultiaddrConnection>;
}

@@ -274,7 +274,7 @@ export interface MultiaddrConnectionTimeline {

*/
close: (options?: AbortOptions) => Promise<void>;
close(options?: AbortOptions): Promise<void>;
/**
* Immediately close the connection, any queued data will be discarded
*/
abort: (err: Error) => void;
abort(err: Error): void;
/**

@@ -281,0 +281,0 @@ * The address of the remote end of the connection

@@ -36,3 +36,3 @@ import type { AbortOptions } from '../index.js';

*/
provide: (cid: CID, options?: AbortOptions) => Promise<void>;
provide(cid: CID, options?: AbortOptions): Promise<void>;
/**

@@ -50,3 +50,3 @@ * Find the providers of the passed CID.

*/
findProviders: (cid: CID, options?: AbortOptions) => AsyncIterable<PeerInfo>;
findProviders(cid: CID, options?: AbortOptions): AsyncIterable<PeerInfo>;
/**

@@ -66,3 +66,3 @@ * Puts a value corresponding to the passed key in a way that can later be

*/
put: (key: Uint8Array, value: Uint8Array, options?: AbortOptions) => Promise<void>;
put(key: Uint8Array, value: Uint8Array, options?: AbortOptions): Promise<void>;
/**

@@ -80,4 +80,4 @@ * Retrieves a value from the network corresponding to the passed key.

*/
get: (key: Uint8Array, options?: AbortOptions) => Promise<Uint8Array>;
get(key: Uint8Array, options?: AbortOptions): Promise<Uint8Array>;
}
//# sourceMappingURL=index.d.ts.map

@@ -383,3 +383,3 @@ /**

*/
getMultiaddrs: () => Multiaddr[];
getMultiaddrs(): Multiaddr[];
/**

@@ -395,3 +395,3 @@ * Returns a list of supported protocols

*/
getProtocols: () => string[];
getProtocols(): string[];
/**

@@ -410,3 +410,3 @@ * Return a list of all connections this node has open, optionally filtering

*/
getConnections: (peerId?: PeerId) => Connection[];
getConnections(peerId?: PeerId): Connection[];
/**

@@ -423,7 +423,7 @@ * Return the list of dials currently in progress or queued to start

*/
getDialQueue: () => PendingDial[];
getDialQueue(): PendingDial[];
/**
* Return a list of all peers we currently have a connection open to
*/
getPeers: () => PeerId[];
getPeers(): PeerId[];
/**

@@ -449,3 +449,3 @@ * Dials to the provided peer. If successful, the known metadata of the

*/
dial: (peer: PeerId | Multiaddr | Multiaddr[], options?: AbortOptions) => Promise<Connection>;
dial(peer: PeerId | Multiaddr | Multiaddr[], options?: AbortOptions): Promise<Connection>;
/**

@@ -467,3 +467,3 @@ * Dials to the provided peer and tries to handshake with the given protocols in order.

*/
dialProtocol: (peer: PeerId | Multiaddr | Multiaddr[], protocols: string | string[], options?: NewStreamOptions) => Promise<Stream>;
dialProtocol(peer: PeerId | Multiaddr | Multiaddr[], protocols: string | string[], options?: NewStreamOptions): Promise<Stream>;
/**

@@ -482,3 +482,3 @@ * Attempts to gracefully close an open connection to the given peer. If the

*/
hangUp: (peer: PeerId | Multiaddr, options?: AbortOptions) => Promise<void>;
hangUp(peer: PeerId | Multiaddr, options?: AbortOptions): Promise<void>;
/**

@@ -504,3 +504,3 @@ * Sets up [multistream-select routing](https://github.com/multiformats/multistream-select) of protocols to their application handlers. Whenever a stream is opened on one of the provided protocols, the handler will be called. `handle` must be called in order to register a handler and support for a given protocol. This also informs other peers of the protocols you support.

*/
handle: (protocol: string | string[], handler: StreamHandler, options?: StreamHandlerOptions) => Promise<void>;
handle(protocol: string | string[], handler: StreamHandler, options?: StreamHandlerOptions): Promise<void>;
/**

@@ -516,3 +516,3 @@ * Removes the handler for each protocol. The protocol

*/
unhandle: (protocols: string[] | string) => Promise<void>;
unhandle(protocols: string[] | string): Promise<void>;
/**

@@ -535,3 +535,3 @@ * Register a topology to be informed when peers are encountered that

*/
register: (protocol: string, topology: Topology) => Promise<string>;
register(protocol: string, topology: Topology): Promise<string>;
/**

@@ -549,3 +549,3 @@ * Unregister topology to no longer be informed when peers connect or

*/
unregister: (id: string) => void;
unregister(id: string): void;
/**

@@ -556,3 +556,3 @@ * Returns the public key for the passed PeerId. If the PeerId is of the 'RSA' type

*/
getPublicKey: (peer: PeerId, options?: AbortOptions) => Promise<Uint8Array>;
getPublicKey(peer: PeerId, options?: AbortOptions): Promise<Uint8Array>;
/**

@@ -559,0 +559,0 @@ * A set of user defined services

@@ -46,3 +46,3 @@ /**

*/
exportKey: (name: string, password: string) => Promise<Multibase<'m'>>;
exportKey(name: string, password: string): Promise<Multibase<'m'>>;
/**

@@ -59,3 +59,3 @@ * Import a new key from a PEM encoded PKCS #8 string.

*/
importKey: (name: string, pem: string, password: string) => Promise<KeyInfo>;
importKey(name: string, pem: string, password: string): Promise<KeyInfo>;
/**

@@ -70,3 +70,3 @@ * Import a new key from a PeerId with a private key component

*/
importPeer: (name: string, peerId: PeerId) => Promise<KeyInfo>;
importPeer(name: string, peerId: PeerId): Promise<KeyInfo>;
/**

@@ -81,3 +81,3 @@ * Export an existing key as a PeerId

*/
exportPeerId: (name: string) => Promise<PeerId>;
exportPeerId(name: string): Promise<PeerId>;
/**

@@ -92,3 +92,3 @@ * Create a key in the keychain.

*/
createKey: (name: string, type: KeyType, size?: number) => Promise<KeyInfo>;
createKey(name: string, type: KeyType, size?: number): Promise<KeyInfo>;
/**

@@ -103,3 +103,3 @@ * List all the keys.

*/
listKeys: () => Promise<KeyInfo[]>;
listKeys(): Promise<KeyInfo[]>;
/**

@@ -115,3 +115,3 @@ * Removes a key from the keychain.

*/
removeKey: (name: string) => Promise<KeyInfo>;
removeKey(name: string): Promise<KeyInfo>;
/**

@@ -127,3 +127,3 @@ * Rename a key in the keychain.

*/
renameKey: (oldName: string, newName: string) => Promise<KeyInfo>;
renameKey(oldName: string, newName: string): Promise<KeyInfo>;
/**

@@ -139,3 +139,3 @@ * Find a key by it's id.

*/
findKeyById: (id: string) => Promise<KeyInfo>;
findKeyById(id: string): Promise<KeyInfo>;
/**

@@ -151,3 +151,3 @@ * Find a key by it's name.

*/
findKeyByName: (name: string) => Promise<KeyInfo>;
findKeyByName(name: string): Promise<KeyInfo>;
/**

@@ -162,4 +162,4 @@ * Rotate keychain password and re-encrypt all associated keys

*/
rotateKeychainPass: (oldPass: string, newPass: string) => Promise<void>;
rotateKeychainPass(oldPass: string, newPass: string): Promise<void>;
}
//# sourceMappingURL=index.d.ts.map
export interface PublicKey {
readonly bytes: Uint8Array;
verify: (data: Uint8Array, sig: Uint8Array) => Promise<boolean>;
marshal: () => Uint8Array;
equals: (key: PublicKey) => boolean;
hash: () => Promise<Uint8Array>;
verify(data: Uint8Array, sig: Uint8Array): Promise<boolean>;
marshal(): Uint8Array;
equals(key: PublicKey): boolean;
hash(): Promise<Uint8Array>;
}

@@ -14,6 +14,6 @@ /**

readonly bytes: Uint8Array;
sign: (data: Uint8Array) => Promise<Uint8Array>;
marshal: () => Uint8Array;
equals: (key: PrivateKey) => boolean;
hash: () => Promise<Uint8Array>;
sign(data: Uint8Array): Promise<Uint8Array>;
marshal(): Uint8Array;
equals(key: PrivateKey): boolean;
hash(): Promise<Uint8Array>;
/**

@@ -26,7 +26,7 @@ * Gets the ID of the key.

*/
id: () => Promise<string>;
id(): Promise<string>;
/**
* Exports the password protected key in the format specified.
*/
export: (password: string, format?: 'pkcs-8' | string) => Promise<string>;
export(password: string, format?: 'pkcs-8' | string): Promise<string>;
}

@@ -33,0 +33,0 @@ export declare const Ed25519 = "Ed25519";

@@ -47,15 +47,15 @@ import type { MultiaddrConnection, Stream, Connection } from '../connection/index.js';

*/
update: (value: number) => void;
update(value: number): void;
/**
* Increment the metric by the passed value or 1
*/
increment: (value?: number) => void;
increment(value?: number): void;
/**
* Decrement the metric by the passed value or 1
*/
decrement: (value?: number) => void;
decrement(value?: number): void;
/**
* Reset this metric to its default value
*/
reset: () => void;
reset(): void;
/**

@@ -65,3 +65,3 @@ * Start a timed metric, call the returned function to

*/
timer: () => StopTimer;
timer(): StopTimer;
}

@@ -76,3 +76,3 @@ /**

*/
update: (values: Record<string, number>) => void;
update(values: Record<string, number>): void;
/**

@@ -82,3 +82,3 @@ * Increment the metric group keys by the passed number or

*/
increment: (values: Record<string, number | unknown>) => void;
increment(values: Record<string, number | unknown>): void;
/**

@@ -88,3 +88,3 @@ * Decrement the metric group keys by the passed number or

*/
decrement: (values: Record<string, number | unknown>) => void;
decrement(values: Record<string, number | unknown>): void;
/**

@@ -94,3 +94,3 @@ * Reset the passed key in this metric group to its default value

*/
reset: () => void;
reset(): void;
/**

@@ -100,3 +100,3 @@ * Start a timed metric for the named key in the group, call

*/
timer: (key: string) => StopTimer;
timer(key: string): StopTimer;
}

@@ -111,7 +111,7 @@ /**

*/
increment: (value?: number) => void;
increment(value?: number): void;
/**
* Reset this metric to its default value
*/
reset: () => void;
reset(): void;
}

@@ -128,3 +128,3 @@ /**

*/
increment: (values: Record<string, number | unknown>) => void;
increment(values: Record<string, number | unknown>): void;
/**

@@ -134,3 +134,3 @@ * Reset the passed key in this metric group to its default value

*/
reset: () => void;
reset(): void;
}

@@ -146,7 +146,7 @@ /**

*/
trackMultiaddrConnection: (maConn: MultiaddrConnection) => void;
trackMultiaddrConnection(maConn: MultiaddrConnection): void;
/**
* Track a newly opened protocol stream
*/
trackProtocolStream: (stream: Stream, connection: Connection) => void;
trackProtocolStream(stream: Stream, connection: Connection): void;
/**

@@ -153,0 +153,0 @@ * Register an arbitrary metric. Call this to set help/labels for metrics

@@ -9,6 +9,6 @@ import type { CID } from 'multiformats/cid';

readonly publicKey?: Uint8Array;
toString: () => string;
toCID: () => CID;
toBytes: () => Uint8Array;
equals: (other: PeerId | Uint8Array | string) => boolean;
toString(): string;
toCID(): CID;
toBytes(): Uint8Array;
equals(other: PeerId | Uint8Array | string): boolean;
}

@@ -15,0 +15,0 @@ export interface RSAPeerId extends BasePeerId {

@@ -35,3 +35,3 @@ import type { AbortOptions } from '../index.js';

*/
findPeer: (peerId: PeerId, options?: AbortOptions) => Promise<PeerInfo>;
findPeer(peerId: PeerId, options?: AbortOptions): Promise<PeerInfo>;
/**

@@ -50,4 +50,4 @@ * Search the network for peers that are closer to the passed key. Peer

*/
getClosestPeers: (key: Uint8Array, options?: AbortOptions) => AsyncIterable<PeerInfo>;
getClosestPeers(key: Uint8Array, options?: AbortOptions): AsyncIterable<PeerInfo>;
}
//# sourceMappingURL=index.d.ts.map

@@ -141,3 +141,3 @@ import type { PeerId } from '../peer-id/index.js';

*/
forEach: (fn: (peer: Peer) => void, query?: PeerQuery) => Promise<void>;
forEach(fn: (peer: Peer) => void, query?: PeerQuery): Promise<void>;
/**

@@ -154,3 +154,3 @@ * Returns all peers in the peer store.

*/
all: (query?: PeerQuery) => Promise<Peer[]>;
all(query?: PeerQuery): Promise<Peer[]>;
/**

@@ -172,3 +172,3 @@ * Delete all data stored for the passed peer

*/
delete: (peerId: PeerId) => Promise<void>;
delete(peerId: PeerId): Promise<void>;
/**

@@ -187,3 +187,3 @@ * Returns true if the passed PeerId is in the peer store

*/
has: (peerId: PeerId) => Promise<boolean>;
has(peerId: PeerId): Promise<boolean>;
/**

@@ -199,3 +199,3 @@ * Returns all data stored for the passed PeerId

*/
get: (peerId: PeerId) => Promise<Peer>;
get(peerId: PeerId): Promise<Peer>;
/**

@@ -212,3 +212,3 @@ * Adds a peer to the peer store, overwriting any existing data

*/
save: (id: PeerId, data: PeerData) => Promise<Peer>;
save(id: PeerId, data: PeerData): Promise<Peer>;
/**

@@ -225,3 +225,3 @@ * Adds a peer to the peer store, overwriting only the passed fields

*/
patch: (id: PeerId, data: PeerData) => Promise<Peer>;
patch(id: PeerId, data: PeerData): Promise<Peer>;
/**

@@ -238,3 +238,3 @@ * Adds a peer to the peer store, deeply merging any existing data.

*/
merge: (id: PeerId, data: PeerData) => Promise<Peer>;
merge(id: PeerId, data: PeerData): Promise<Peer>;
/**

@@ -253,4 +253,4 @@ * Unmarshal and verify a signed peer record, extract the multiaddrs and

*/
consumePeerRecord: (buf: Uint8Array, expectedPeer?: PeerId) => Promise<boolean>;
consumePeerRecord(buf: Uint8Array, expectedPeer?: PeerId): Promise<boolean>;
}
//# sourceMappingURL=index.d.ts.map

@@ -64,6 +64,6 @@ import type { Stream } from '../connection/index.js';

isWritable: boolean;
close: () => void;
write: (buf: Uint8Array | Uint8ArrayList) => void;
attachInboundStream: (stream: Stream) => AsyncIterable<Uint8ArrayList>;
attachOutboundStream: (stream: Stream) => Promise<Pushable<Uint8ArrayList>>;
close(): void;
write(buf: Uint8Array | Uint8ArrayList): void;
attachInboundStream(stream: Stream): AsyncIterable<Uint8ArrayList>;
attachOutboundStream(stream: Stream): Promise<Pushable<Uint8ArrayList>>;
}

@@ -164,3 +164,3 @@ export interface PubSubInit {

topicValidators: Map<string, TopicValidatorFn>;
getPeers: () => PeerId[];
getPeers(): PeerId[];
/**

@@ -173,3 +173,3 @@ * Gets a list of topics the node is subscribed to.

*/
getTopics: () => string[];
getTopics(): string[];
/**

@@ -192,3 +192,3 @@ * Subscribes to a pubsub topic.

*/
subscribe: (topic: string) => void;
subscribe(topic: string): void;
/**

@@ -209,3 +209,3 @@ * Unsubscribes from a pubsub topic.

*/
unsubscribe: (topic: string) => void;
unsubscribe(topic: string): void;
/**

@@ -220,3 +220,3 @@ * Gets a list of the PeerIds that are subscribed to one topic.

*/
getSubscribers: (topic: string) => PeerId[];
getSubscribers(topic: string): PeerId[];
/**

@@ -234,3 +234,3 @@ * Publishes messages to the given topic.

*/
publish: (topic: string, data: Uint8Array) => Promise<PublishResult>;
publish(topic: string, data: Uint8Array): Promise<PublishResult>;
}

@@ -237,0 +237,0 @@ export interface PeerStreamEvents {

@@ -18,7 +18,7 @@ import type { PeerId } from '../peer-id/index.js';

*/
marshal: () => Uint8Array;
marshal(): Uint8Array;
/**
* Verifies if the other provided Record is identical to this one.
*/
equals: (other: Record) => boolean;
equals(other: Record): boolean;
}

@@ -30,6 +30,6 @@ export interface Envelope {

signature: Uint8Array | Uint8ArrayList;
marshal: () => Uint8Array;
validate: (domain: string) => Promise<boolean>;
equals: (other: Envelope) => boolean;
marshal(): Uint8Array;
validate(domain: string): Promise<boolean>;
equals(other: Envelope): boolean;
}
//# sourceMappingURL=index.d.ts.map

@@ -5,3 +5,3 @@ /**

export interface Startable {
isStarted: () => boolean;
isStarted(): boolean;
/**

@@ -12,3 +12,3 @@ * If implemented, this method will be invoked before the start method.

*/
beforeStart?: () => void | Promise<void>;
beforeStart?(): void | Promise<void>;
/**

@@ -19,3 +19,3 @@ * This method will be invoked to start the component.

*/
start: () => void | Promise<void>;
start(): void | Promise<void>;
/**

@@ -26,3 +26,3 @@ * If implemented, this method will be invoked after the start method.

*/
afterStart?: () => void | Promise<void>;
afterStart?(): void | Promise<void>;
/**

@@ -33,3 +33,3 @@ * If implemented, this method will be invoked before the stop method.

*/
beforeStop?: () => void | Promise<void>;
beforeStop?(): void | Promise<void>;
/**

@@ -40,3 +40,3 @@ * This method will be invoked to stop the component.

*/
stop: () => void | Promise<void>;
stop(): void | Promise<void>;
/**

@@ -47,3 +47,3 @@ * If implemented, this method will be invoked after the stop method.

*/
afterStop?: () => void | Promise<void>;
afterStop?(): void | Promise<void>;
}

@@ -50,0 +50,0 @@ export declare function isStartable(obj: any): obj is Startable;

@@ -13,3 +13,3 @@ import type { Direction, Stream } from '../connection/index.js';

*/
createStreamMuxer: (init?: StreamMuxerInit) => StreamMuxer;
createStreamMuxer(init?: StreamMuxerInit): StreamMuxer;
}

@@ -32,11 +32,11 @@ /**

*/
newStream: (name?: string) => Stream | Promise<Stream>;
newStream(name?: string): Stream | Promise<Stream>;
/**
* Close or abort all tracked streams and stop the muxer
*/
close: (options?: AbortOptions) => Promise<void>;
close(options?: AbortOptions): Promise<void>;
/**
* Close or abort all tracked streams and stop the muxer
*/
abort: (err: Error) => void;
abort(err: Error): void;
}

@@ -47,7 +47,7 @@ export interface StreamMuxerInit {

*/
onIncomingStream?: (stream: Stream) => void;
onIncomingStream?(stream: Stream): void;
/**
* A callback function invoke every time a stream ends
*/
onStreamEnd?: (stream: Stream) => void;
onStreamEnd?(stream: Stream): void;
/**

@@ -54,0 +54,0 @@ * Outbound stream muxers are opened by the local node, inbound stream muxers are opened by the remote

@@ -7,4 +7,4 @@ import { Uint8ArrayList } from 'uint8arraylist';

(formatter: any, ...args: any[]): void;
error: (formatter: any, ...args: any[]) => void;
trace: (formatter: any, ...args: any[]) => void;
error(formatter: any, ...args: any[]): void;
trace(formatter: any, ...args: any[]): void;
enabled: boolean;

@@ -32,19 +32,19 @@ }

*/
onEnd?: (err?: Error | undefined) => void;
onEnd?(err?: Error | undefined): void;
/**
* Invoked when the readable end of the stream is closed
*/
onCloseRead?: () => void;
onCloseRead?(): void;
/**
* Invoked when the writable end of the stream is closed
*/
onCloseWrite?: () => void;
onCloseWrite?(): void;
/**
* Invoked when the the stream has been reset by the remote
*/
onReset?: () => void;
onReset?(): void;
/**
* Invoked when the the stream has errored
*/
onAbort?: (err: Error) => void;
onAbort?(err: Error): void;
/**

@@ -55,2 +55,7 @@ * How long to wait in ms for stream data to be written to the underlying

closeTimeout?: number;
/**
* After the stream sink has closed, a limit on how long it takes to send
* a close-write message to the remote peer.
*/
sendCloseWriteTimeout?: number;
}

@@ -76,2 +81,3 @@ export declare abstract class AbstractStream implements Stream {

private readonly onAbort?;
private readonly sendCloseWriteTimeout;
protected readonly log: Logger;

@@ -78,0 +84,0 @@ constructor(init: AbstractStreamInit);

import { abortableSource } from 'abortable-iterator';
import { pushable } from 'it-pushable';
import defer, {} from 'p-defer';
import { raceSignal } from 'race-signal';
import { Uint8ArrayList } from 'uint8arraylist';

@@ -8,2 +9,3 @@ import { CodeError } from '../errors.js';

const ERR_SINK_INVALID_STATE = 'ERR_SINK_INVALID_STATE';
const DEFAULT_SEND_CLOSE_WRITE_TIMEOUT = 5000;
function isPromise(res) {

@@ -31,2 +33,3 @@ return res != null && typeof res.then === 'function';

onAbort;
sendCloseWriteTimeout;
log;

@@ -47,2 +50,3 @@ constructor(init) {

};
this.sendCloseWriteTimeout = init.sendCloseWriteTimeout ?? DEFAULT_SEND_CLOSE_WRITE_TIMEOUT;
this.onEnd = init.onEnd;

@@ -61,3 +65,2 @@ this.onCloseRead = init?.onCloseRead;

}
this.readStatus = 'closed';
this.onSourceEnd(err);

@@ -95,6 +98,11 @@ }

}
this.log.trace('sink finished reading from source');
this.writeStatus = 'done';
this.log.trace('sink calling closeWrite');
await this.closeWrite(options);
this.log.trace('sink finished reading from source, write status is "%s"', this.writeStatus);
if (this.writeStatus === 'writing') {
this.writeStatus = 'closing';
this.log.trace('send close write to remote');
await this.sendCloseWrite({
signal: AbortSignal.timeout(this.sendCloseWriteTimeout)
});
this.writeStatus = 'closed';
}
this.onSinkEnd();

@@ -117,2 +125,3 @@ }

this.timeline.closeRead = Date.now();
this.readStatus = 'closed';
if (err != null && this.endErr == null) {

@@ -125,2 +134,5 @@ this.endErr = err;

this.timeline.close = Date.now();
if (this.status !== 'aborted' && this.status !== 'reset') {
this.status = 'closed';
}
if (this.onEnd != null) {

@@ -139,2 +151,3 @@ this.onEnd(this.endErr);

this.timeline.closeWrite = Date.now();
this.writeStatus = 'closed';
if (err != null && this.endErr == null) {

@@ -147,2 +160,5 @@ this.endErr = err;

this.timeline.close = Date.now();
if (this.status !== 'aborted' && this.status !== 'reset') {
this.status = 'closed';
}
if (this.onEnd != null) {

@@ -174,2 +190,6 @@ this.onEnd(this.endErr);

this.readStatus = 'closing';
if (this.status !== 'reset' && this.status !== 'aborted' && this.timeline.closeRead == null) {
this.log.trace('send close read to remote');
await this.sendCloseRead(options);
}
if (readStatus === 'ready') {

@@ -179,6 +199,2 @@ this.log.trace('ending internal source queue');

}
if (this.status !== 'reset' && this.status !== 'aborted' && this.timeline.closeRead == null) {
this.log.trace('send close read to remote');
await this.sendCloseRead(options);
}
this.log.trace('closed readable end of stream');

@@ -191,9 +207,7 @@ }

this.log.trace('closing writable end of stream with starting write status "%s"', this.writeStatus);
const writeStatus = this.writeStatus;
if (this.writeStatus === 'ready') {
this.log.trace('sink was never sunk, sink an empty array');
await this.sink([]);
await raceSignal(this.sink([]), options.signal);
}
this.writeStatus = 'closing';
if (writeStatus === 'writing') {
if (this.writeStatus === 'writing') {
// stop reading from the source passed to `.sink` in the microtask queue

@@ -206,10 +220,7 @@ // - this lets any data queued by the user in the current tick get read

this.sinkController.abort();
this.sinkEnd.promise.then(resolve, reject);
raceSignal(this.sinkEnd.promise, options.signal)
.then(resolve, reject);
});
});
}
if (this.status !== 'reset' && this.status !== 'aborted' && this.timeline.closeWrite == null) {
this.log.trace('send close write to remote');
await this.sendCloseWrite(options);
}
this.writeStatus = 'closed';

@@ -250,2 +261,3 @@ this.log.trace('closed writable end of stream');

this.status = 'reset';
this.timeline.reset = Date.now();
this._closeSinkAndSource(err);

@@ -307,3 +319,3 @@ this.onReset?.();

}
this.log.trace('muxer destroyed');
this.log.trace('stream destroyed');
this._closeSinkAndSource();

@@ -310,0 +322,0 @@ }

@@ -6,5 +6,5 @@ import type { Connection } from '../connection/index.js';

max?: number;
onConnect?: (peerId: PeerId, conn: Connection) => void;
onDisconnect?: (peerId: PeerId) => void;
onConnect?(peerId: PeerId, conn: Connection): void;
onDisconnect?(peerId: PeerId): void;
}
//# sourceMappingURL=index.d.ts.map

@@ -16,7 +16,7 @@ import type { Connection, MultiaddrConnection } from '../connection/index.js';

*/
listen: (multiaddr: Multiaddr) => Promise<void>;
listen(multiaddr: Multiaddr): Promise<void>;
/**
* Get listen addresses
*/
getAddrs: () => Multiaddr[];
getAddrs(): Multiaddr[];
/**

@@ -27,3 +27,3 @@ * Close listener

*/
close: () => Promise<void>;
close(): Promise<void>;
}

@@ -59,7 +59,7 @@ export declare const symbol: unique symbol;

*/
dial: (ma: Multiaddr, options: DialOptions) => Promise<Connection>;
dial(ma: Multiaddr, options: DialOptions): Promise<Connection>;
/**
* Create transport listeners.
*/
createListener: (options: CreateListenerOptions) => Listener;
createListener(options: CreateListenerOptions): Listener;
/**

@@ -98,8 +98,8 @@ * Takes a list of `Multiaddr`s and returns only valid addresses for the transport

*/
upgradeOutbound: (maConn: MultiaddrConnection, opts?: UpgraderOptions) => Promise<Connection>;
upgradeOutbound(maConn: MultiaddrConnection, opts?: UpgraderOptions): Promise<Connection>;
/**
* Upgrades an inbound connection on transport listener.
*/
upgradeInbound: (maConn: MultiaddrConnection, opts?: UpgraderOptions) => Promise<Connection>;
upgradeInbound(maConn: MultiaddrConnection, opts?: UpgraderOptions): Promise<Connection>;
}
//# sourceMappingURL=index.d.ts.map
{
"name": "@libp2p/interface",
"version": "0.1.2-f09ac4a7",
"version": "0.1.2-f1053159",
"description": "The interface implemented by a libp2p node",

@@ -143,2 +143,3 @@ "license": "Apache-2.0 OR MIT",

"parserOptions": {
"project": true,
"sourceType": "module"

@@ -167,2 +168,3 @@ }

"p-defer": "^4.0.0",
"race-signal": "^1.0.0",
"uint8arraylist": "^2.4.3"

@@ -172,3 +174,6 @@ },

"@types/sinon": "^10.0.15",
"aegir": "^40.0.8",
"aegir": "^41.0.2",
"delay": "^6.0.0",
"it-all": "^3.0.3",
"it-drain": "^3.0.3",
"sinon": "^16.0.0",

@@ -175,0 +180,0 @@ "sinon-ts": "^1.0.0"

@@ -16,3 +16,3 @@ import type { PeerId } from '../peer-id/index.js'

*/
secureOutbound: (localPeer: PeerId, connection: Duplex<AsyncGenerator<Uint8Array>, Source<Uint8Array>, Promise<void>>, remotePeer?: PeerId) => Promise<SecuredConnection<Extension>>
secureOutbound(localPeer: PeerId, connection: Duplex<AsyncGenerator<Uint8Array>, Source<Uint8Array>, Promise<void>>, remotePeer?: PeerId): Promise<SecuredConnection<Extension>>

@@ -24,3 +24,3 @@ /**

*/
secureInbound: (localPeer: PeerId, connection: Duplex<AsyncGenerator<Uint8Array>, Source<Uint8Array>, Promise<void>>, remotePeer?: PeerId) => Promise<SecuredConnection<Extension>>
secureInbound(localPeer: PeerId, connection: Duplex<AsyncGenerator<Uint8Array>, Source<Uint8Array>, Promise<void>>, remotePeer?: PeerId): Promise<SecuredConnection<Extension>>
}

@@ -27,0 +27,0 @@

@@ -15,3 +15,3 @@ import type { MultiaddrConnection } from '../connection/index.js'

*/
denyDialPeer?: (peerId: PeerId) => Promise<boolean>
denyDialPeer?(peerId: PeerId): Promise<boolean>

@@ -27,3 +27,3 @@ /**

*/
denyDialMultiaddr?: (multiaddr: Multiaddr) => Promise<boolean>
denyDialMultiaddr?(multiaddr: Multiaddr): Promise<boolean>

@@ -38,3 +38,3 @@ /**

*/
denyInboundConnection?: (maConn: MultiaddrConnection) => Promise<boolean>
denyInboundConnection?(maConn: MultiaddrConnection): Promise<boolean>

@@ -49,3 +49,3 @@ /**

*/
denyOutboundConnection?: (peerId: PeerId, maConn: MultiaddrConnection) => Promise<boolean>
denyOutboundConnection?(peerId: PeerId, maConn: MultiaddrConnection): Promise<boolean>

@@ -62,3 +62,3 @@ /**

*/
denyInboundEncryptedConnection?: (peerId: PeerId, maConn: MultiaddrConnection) => Promise<boolean>
denyInboundEncryptedConnection?(peerId: PeerId, maConn: MultiaddrConnection): Promise<boolean>

@@ -75,3 +75,3 @@ /**

*/
denyOutboundEncryptedConnection?: (peerId: PeerId, maConn: MultiaddrConnection) => Promise<boolean>
denyOutboundEncryptedConnection?(peerId: PeerId, maConn: MultiaddrConnection): Promise<boolean>

@@ -86,3 +86,3 @@ /**

*/
denyInboundUpgradedConnection?: (peerId: PeerId, maConn: MultiaddrConnection) => Promise<boolean>
denyInboundUpgradedConnection?(peerId: PeerId, maConn: MultiaddrConnection): Promise<boolean>

@@ -97,3 +97,3 @@ /**

*/
denyOutboundUpgradedConnection?: (peerId: PeerId, maConn: MultiaddrConnection) => Promise<boolean>
denyOutboundUpgradedConnection?(peerId: PeerId, maConn: MultiaddrConnection): Promise<boolean>

@@ -106,3 +106,3 @@ /**

*/
denyInboundRelayReservation?: (source: PeerId) => Promise<boolean>
denyInboundRelayReservation?(source: PeerId): Promise<boolean>

@@ -118,3 +118,3 @@ /**

*/
denyOutboundRelayedConnection?: (source: PeerId, destination: PeerId) => Promise<boolean>
denyOutboundRelayedConnection?(source: PeerId, destination: PeerId): Promise<boolean>

@@ -130,3 +130,3 @@ /**

*/
denyInboundRelayedConnection?: (relay: PeerId, remotePeer: PeerId) => Promise<boolean>
denyInboundRelayedConnection?(relay: PeerId, remotePeer: PeerId): Promise<boolean>

@@ -138,3 +138,3 @@ /**

*/
filterMultiaddrForPeer?: (peer: PeerId, multiaddr: Multiaddr) => Promise<boolean>
filterMultiaddrForPeer?(peer: PeerId, multiaddr: Multiaddr): Promise<boolean>
}

@@ -104,3 +104,3 @@ import type { AbortOptions } from '../index.js'

*/
close: (options?: AbortOptions) => Promise<void>
close(options?: AbortOptions): Promise<void>

@@ -114,3 +114,3 @@ /**

*/
closeRead: (options?: AbortOptions) => Promise<void>
closeRead(options?: AbortOptions): Promise<void>

@@ -122,3 +122,3 @@ /**

*/
closeWrite: (options?: AbortOptions) => Promise<void>
closeWrite(options?: AbortOptions): Promise<void>

@@ -134,3 +134,3 @@ /**

*/
abort: (err: Error) => void
abort(err: Error): void

@@ -153,3 +153,3 @@ /**

/**
* Once a protocol has been negotiated for this stream, it will be set on the stat object
* The protocol negotiated for this stream
*/

@@ -239,3 +239,3 @@ protocol?: string

/**
* Once a multiplexer has been negotiated for this stream, it will be set on the stat object
* The multiplexer negotiated for this connection
*/

@@ -245,3 +245,3 @@ multiplexer?: string

/**
* Once a connection encrypter has been negotiated for this stream, it will be set on the stat object
* The encryption protocol negotiated for this connection
*/

@@ -266,3 +266,3 @@ encryption?: string

*/
newStream: (protocols: string | string[], options?: NewStreamOptions) => Promise<Stream>
newStream(protocols: string | string[], options?: NewStreamOptions): Promise<Stream>

@@ -273,3 +273,3 @@ /**

*/
close: (options?: AbortOptions) => Promise<void>
close(options?: AbortOptions): Promise<void>

@@ -279,3 +279,3 @@ /**

*/
abort: (err: Error) => void
abort(err: Error): void
}

@@ -295,3 +295,3 @@

*/
protect: (connection: MultiaddrConnection) => Promise<MultiaddrConnection>
protect(connection: MultiaddrConnection): Promise<MultiaddrConnection>
}

@@ -327,3 +327,3 @@

*/
close: (options?: AbortOptions) => Promise<void>
close(options?: AbortOptions): Promise<void>

@@ -333,3 +333,3 @@ /**

*/
abort: (err: Error) => void
abort(err: Error): void

@@ -336,0 +336,0 @@ /**

@@ -38,3 +38,3 @@ import type { AbortOptions } from '../index.js'

*/
provide: (cid: CID, options?: AbortOptions) => Promise<void>
provide(cid: CID, options?: AbortOptions): Promise<void>

@@ -53,3 +53,3 @@ /**

*/
findProviders: (cid: CID, options?: AbortOptions) => AsyncIterable<PeerInfo>
findProviders(cid: CID, options?: AbortOptions): AsyncIterable<PeerInfo>

@@ -70,3 +70,3 @@ /**

*/
put: (key: Uint8Array, value: Uint8Array, options?: AbortOptions) => Promise<void>
put(key: Uint8Array, value: Uint8Array, options?: AbortOptions): Promise<void>

@@ -85,3 +85,3 @@ /**

*/
get: (key: Uint8Array, options?: AbortOptions) => Promise<Uint8Array>
get(key: Uint8Array, options?: AbortOptions): Promise<Uint8Array>
}

@@ -421,3 +421,3 @@ /**

*/
getMultiaddrs: () => Multiaddr[]
getMultiaddrs(): Multiaddr[]

@@ -434,3 +434,3 @@ /**

*/
getProtocols: () => string[]
getProtocols(): string[]

@@ -450,3 +450,3 @@ /**

*/
getConnections: (peerId?: PeerId) => Connection[]
getConnections(peerId?: PeerId): Connection[]

@@ -464,3 +464,3 @@ /**

*/
getDialQueue: () => PendingDial[]
getDialQueue(): PendingDial[]

@@ -470,3 +470,3 @@ /**

*/
getPeers: () => PeerId[]
getPeers(): PeerId[]

@@ -493,3 +493,3 @@ /**

*/
dial: (peer: PeerId | Multiaddr | Multiaddr[], options?: AbortOptions) => Promise<Connection>
dial(peer: PeerId | Multiaddr | Multiaddr[], options?: AbortOptions): Promise<Connection>

@@ -512,3 +512,3 @@ /**

*/
dialProtocol: (peer: PeerId | Multiaddr | Multiaddr[], protocols: string | string[], options?: NewStreamOptions) => Promise<Stream>
dialProtocol(peer: PeerId | Multiaddr | Multiaddr[], protocols: string | string[], options?: NewStreamOptions): Promise<Stream>

@@ -528,3 +528,3 @@ /**

*/
hangUp: (peer: PeerId | Multiaddr, options?: AbortOptions) => Promise<void>
hangUp(peer: PeerId | Multiaddr, options?: AbortOptions): Promise<void>

@@ -551,3 +551,3 @@ /**

*/
handle: (protocol: string | string[], handler: StreamHandler, options?: StreamHandlerOptions) => Promise<void>
handle(protocol: string | string[], handler: StreamHandler, options?: StreamHandlerOptions): Promise<void>

@@ -564,3 +564,3 @@ /**

*/
unhandle: (protocols: string[] | string) => Promise<void>
unhandle(protocols: string[] | string): Promise<void>

@@ -584,3 +584,3 @@ /**

*/
register: (protocol: string, topology: Topology) => Promise<string>
register(protocol: string, topology: Topology): Promise<string>

@@ -599,3 +599,3 @@ /**

*/
unregister: (id: string) => void
unregister(id: string): void

@@ -607,3 +607,3 @@ /**

*/
getPublicKey: (peer: PeerId, options?: AbortOptions) => Promise<Uint8Array>
getPublicKey(peer: PeerId, options?: AbortOptions): Promise<Uint8Array>

@@ -610,0 +610,0 @@ /**

@@ -50,3 +50,3 @@ /**

*/
exportKey: (name: string, password: string) => Promise<Multibase<'m'>>
exportKey(name: string, password: string): Promise<Multibase<'m'>>

@@ -64,3 +64,3 @@ /**

*/
importKey: (name: string, pem: string, password: string) => Promise<KeyInfo>
importKey(name: string, pem: string, password: string): Promise<KeyInfo>

@@ -76,3 +76,3 @@ /**

*/
importPeer: (name: string, peerId: PeerId) => Promise<KeyInfo>
importPeer(name: string, peerId: PeerId): Promise<KeyInfo>

@@ -88,3 +88,3 @@ /**

*/
exportPeerId: (name: string) => Promise<PeerId>
exportPeerId(name: string): Promise<PeerId>

@@ -100,3 +100,3 @@ /**

*/
createKey: (name: string, type: KeyType, size?: number) => Promise<KeyInfo>
createKey(name: string, type: KeyType, size?: number): Promise<KeyInfo>

@@ -112,3 +112,3 @@ /**

*/
listKeys: () => Promise<KeyInfo[]>
listKeys(): Promise<KeyInfo[]>

@@ -125,3 +125,3 @@ /**

*/
removeKey: (name: string) => Promise<KeyInfo>
removeKey(name: string): Promise<KeyInfo>

@@ -138,3 +138,3 @@ /**

*/
renameKey: (oldName: string, newName: string) => Promise<KeyInfo>
renameKey(oldName: string, newName: string): Promise<KeyInfo>

@@ -151,3 +151,3 @@ /**

*/
findKeyById: (id: string) => Promise<KeyInfo>
findKeyById(id: string): Promise<KeyInfo>

@@ -164,3 +164,3 @@ /**

*/
findKeyByName: (name: string) => Promise<KeyInfo>
findKeyByName(name: string): Promise<KeyInfo>

@@ -176,3 +176,3 @@ /**

*/
rotateKeychainPass: (oldPass: string, newPass: string) => Promise<void>
rotateKeychainPass(oldPass: string, newPass: string): Promise<void>
}
export interface PublicKey {
readonly bytes: Uint8Array
verify: (data: Uint8Array, sig: Uint8Array) => Promise<boolean>
marshal: () => Uint8Array
equals: (key: PublicKey) => boolean
hash: () => Promise<Uint8Array>
verify(data: Uint8Array, sig: Uint8Array): Promise<boolean>
marshal(): Uint8Array
equals(key: PublicKey): boolean
hash(): Promise<Uint8Array>
}

@@ -15,6 +15,6 @@

readonly bytes: Uint8Array
sign: (data: Uint8Array) => Promise<Uint8Array>
marshal: () => Uint8Array
equals: (key: PrivateKey) => boolean
hash: () => Promise<Uint8Array>
sign(data: Uint8Array): Promise<Uint8Array>
marshal(): Uint8Array
equals(key: PrivateKey): boolean
hash(): Promise<Uint8Array>
/**

@@ -27,7 +27,7 @@ * Gets the ID of the key.

*/
id: () => Promise<string>
id(): Promise<string>
/**
* Exports the password protected key in the format specified.
*/
export: (password: string, format?: 'pkcs-8' | string) => Promise<string>
export(password: string, format?: 'pkcs-8' | string): Promise<string>
}

@@ -34,0 +34,0 @@

@@ -51,3 +51,3 @@ import type { MultiaddrConnection, Stream, Connection } from '../connection/index.js'

*/
update: (value: number) => void
update(value: number): void

@@ -57,3 +57,3 @@ /**

*/
increment: (value?: number) => void
increment(value?: number): void

@@ -63,3 +63,3 @@ /**

*/
decrement: (value?: number) => void
decrement(value?: number): void

@@ -69,3 +69,3 @@ /**

*/
reset: () => void
reset(): void

@@ -76,3 +76,3 @@ /**

*/
timer: () => StopTimer
timer(): StopTimer
}

@@ -88,3 +88,3 @@

*/
update: (values: Record<string, number>) => void
update(values: Record<string, number>): void

@@ -95,3 +95,3 @@ /**

*/
increment: (values: Record<string, number | unknown>) => void
increment(values: Record<string, number | unknown>): void

@@ -102,3 +102,3 @@ /**

*/
decrement: (values: Record<string, number | unknown>) => void
decrement(values: Record<string, number | unknown>): void

@@ -109,3 +109,3 @@ /**

*/
reset: () => void
reset(): void

@@ -116,3 +116,3 @@ /**

*/
timer: (key: string) => StopTimer
timer(key: string): StopTimer
}

@@ -128,3 +128,3 @@

*/
increment: (value?: number) => void
increment(value?: number): void

@@ -134,3 +134,3 @@ /**

*/
reset: () => void
reset(): void
}

@@ -148,3 +148,3 @@

*/
increment: (values: Record<string, number | unknown>) => void
increment(values: Record<string, number | unknown>): void

@@ -155,3 +155,3 @@ /**

*/
reset: () => void
reset(): void
}

@@ -168,3 +168,3 @@

*/
trackMultiaddrConnection: (maConn: MultiaddrConnection) => void
trackMultiaddrConnection(maConn: MultiaddrConnection): void

@@ -174,3 +174,3 @@ /**

*/
trackProtocolStream: (stream: Stream, connection: Connection) => void
trackProtocolStream(stream: Stream, connection: Connection): void

@@ -177,0 +177,0 @@ /**

@@ -12,6 +12,6 @@ import type { CID } from 'multiformats/cid'

toString: () => string
toCID: () => CID
toBytes: () => Uint8Array
equals: (other: PeerId | Uint8Array | string) => boolean
toString(): string
toCID(): CID
toBytes(): Uint8Array
equals(other: PeerId | Uint8Array | string): boolean
}

@@ -18,0 +18,0 @@

@@ -37,3 +37,3 @@ import type { AbortOptions } from '../index.js'

*/
findPeer: (peerId: PeerId, options?: AbortOptions) => Promise<PeerInfo>
findPeer(peerId: PeerId, options?: AbortOptions): Promise<PeerInfo>

@@ -53,3 +53,3 @@ /**

*/
getClosestPeers: (key: Uint8Array, options?: AbortOptions) => AsyncIterable<PeerInfo>
getClosestPeers(key: Uint8Array, options?: AbortOptions): AsyncIterable<PeerInfo>
}

@@ -159,3 +159,3 @@ import type { PeerId } from '../peer-id/index.js'

*/
forEach: (fn: (peer: Peer) => void, query?: PeerQuery) => Promise<void>
forEach(fn: (peer: Peer) => void, query?: PeerQuery): Promise<void>

@@ -173,3 +173,3 @@ /**

*/
all: (query?: PeerQuery) => Promise<Peer[]>
all(query?: PeerQuery): Promise<Peer[]>

@@ -192,3 +192,3 @@ /**

*/
delete: (peerId: PeerId) => Promise<void>
delete(peerId: PeerId): Promise<void>

@@ -208,3 +208,3 @@ /**

*/
has: (peerId: PeerId) => Promise<boolean>
has(peerId: PeerId): Promise<boolean>

@@ -221,3 +221,3 @@ /**

*/
get: (peerId: PeerId) => Promise<Peer>
get(peerId: PeerId): Promise<Peer>

@@ -235,3 +235,3 @@ /**

*/
save: (id: PeerId, data: PeerData) => Promise<Peer>
save(id: PeerId, data: PeerData): Promise<Peer>

@@ -249,3 +249,3 @@ /**

*/
patch: (id: PeerId, data: PeerData) => Promise<Peer>
patch(id: PeerId, data: PeerData): Promise<Peer>

@@ -263,3 +263,3 @@ /**

*/
merge: (id: PeerId, data: PeerData) => Promise<Peer>
merge(id: PeerId, data: PeerData): Promise<Peer>

@@ -279,3 +279,3 @@ /**

*/
consumePeerRecord: (buf: Uint8Array, expectedPeer?: PeerId) => Promise<boolean>
consumePeerRecord(buf: Uint8Array, expectedPeer?: PeerId): Promise<boolean>
}

@@ -75,6 +75,6 @@ import type { Stream } from '../connection/index.js'

close: () => void
write: (buf: Uint8Array | Uint8ArrayList) => void
attachInboundStream: (stream: Stream) => AsyncIterable<Uint8ArrayList>
attachOutboundStream: (stream: Stream) => Promise<Pushable<Uint8ArrayList>>
close(): void
write(buf: Uint8Array | Uint8ArrayList): void
attachInboundStream(stream: Stream): AsyncIterable<Uint8ArrayList>
attachOutboundStream(stream: Stream): Promise<Pushable<Uint8ArrayList>>
}

@@ -193,3 +193,3 @@

getPeers: () => PeerId[]
getPeers(): PeerId[]

@@ -203,3 +203,3 @@ /**

*/
getTopics: () => string[]
getTopics(): string[]

@@ -223,3 +223,3 @@ /**

*/
subscribe: (topic: string) => void
subscribe(topic: string): void

@@ -241,3 +241,3 @@ /**

*/
unsubscribe: (topic: string) => void
unsubscribe(topic: string): void

@@ -253,3 +253,3 @@ /**

*/
getSubscribers: (topic: string) => PeerId[]
getSubscribers(topic: string): PeerId[]

@@ -268,3 +268,3 @@ /**

*/
publish: (topic: string, data: Uint8Array) => Promise<PublishResult>
publish(topic: string, data: Uint8Array): Promise<PublishResult>
}

@@ -271,0 +271,0 @@

@@ -19,7 +19,7 @@ import type { PeerId } from '../peer-id/index.js'

*/
marshal: () => Uint8Array
marshal(): Uint8Array
/**
* Verifies if the other provided Record is identical to this one.
*/
equals: (other: Record) => boolean
equals(other: Record): boolean
}

@@ -33,5 +33,5 @@

marshal: () => Uint8Array
validate: (domain: string) => Promise<boolean>
equals: (other: Envelope) => boolean
marshal(): Uint8Array
validate(domain: string): Promise<boolean>
equals(other: Envelope): boolean
}

@@ -5,3 +5,3 @@ /**

export interface Startable {
isStarted: () => boolean
isStarted(): boolean

@@ -13,3 +13,3 @@ /**

*/
beforeStart?: () => void | Promise<void>
beforeStart?(): void | Promise<void>

@@ -21,3 +21,3 @@ /**

*/
start: () => void | Promise<void>
start(): void | Promise<void>

@@ -29,3 +29,3 @@ /**

*/
afterStart?: () => void | Promise<void>
afterStart?(): void | Promise<void>

@@ -37,3 +37,3 @@ /**

*/
beforeStop?: () => void | Promise<void>
beforeStop?(): void | Promise<void>

@@ -45,3 +45,3 @@ /**

*/
stop: () => void | Promise<void>
stop(): void | Promise<void>

@@ -53,3 +53,3 @@ /**

*/
afterStop?: () => void | Promise<void>
afterStop?(): void | Promise<void>
}

@@ -56,0 +56,0 @@

@@ -15,3 +15,3 @@ import type { Direction, Stream } from '../connection/index.js'

*/
createStreamMuxer: (init?: StreamMuxerInit) => StreamMuxer
createStreamMuxer(init?: StreamMuxerInit): StreamMuxer
}

@@ -36,3 +36,3 @@

*/
newStream: (name?: string) => Stream | Promise<Stream>
newStream(name?: string): Stream | Promise<Stream>

@@ -42,3 +42,3 @@ /**

*/
close: (options?: AbortOptions) => Promise<void>
close(options?: AbortOptions): Promise<void>

@@ -48,3 +48,3 @@ /**

*/
abort: (err: Error) => void
abort(err: Error): void
}

@@ -56,3 +56,3 @@

*/
onIncomingStream?: (stream: Stream) => void
onIncomingStream?(stream: Stream): void

@@ -62,3 +62,3 @@ /**

*/
onStreamEnd?: (stream: Stream) => void
onStreamEnd?(stream: Stream): void

@@ -65,0 +65,0 @@ /**

import { abortableSource } from 'abortable-iterator'
import { type Pushable, pushable } from 'it-pushable'
import defer, { type DeferredPromise } from 'p-defer'
import { raceSignal } from 'race-signal'
import { Uint8ArrayList } from 'uint8arraylist'

@@ -10,6 +11,7 @@ import { CodeError } from '../errors.js'

// copied from @libp2p/logger to break a circular dependency
interface Logger {
(formatter: any, ...args: any[]): void
error: (formatter: any, ...args: any[]) => void
trace: (formatter: any, ...args: any[]) => void
error(formatter: any, ...args: any[]): void
trace(formatter: any, ...args: any[]): void
enabled: boolean

@@ -20,2 +22,3 @@ }

const ERR_SINK_INVALID_STATE = 'ERR_SINK_INVALID_STATE'
const DEFAULT_SEND_CLOSE_WRITE_TIMEOUT = 5000

@@ -46,3 +49,3 @@ export interface AbstractStreamInit {

*/
onEnd?: (err?: Error | undefined) => void
onEnd?(err?: Error | undefined): void

@@ -52,3 +55,3 @@ /**

*/
onCloseRead?: () => void
onCloseRead?(): void

@@ -58,3 +61,3 @@ /**

*/
onCloseWrite?: () => void
onCloseWrite?(): void

@@ -64,3 +67,3 @@ /**

*/
onReset?: () => void
onReset?(): void

@@ -70,3 +73,3 @@ /**

*/
onAbort?: (err: Error) => void
onAbort?(err: Error): void

@@ -78,2 +81,8 @@ /**

closeTimeout?: number
/**
* After the stream sink has closed, a limit on how long it takes to send
* a close-write message to the remote peer.
*/
sendCloseWriteTimeout?: number
}

@@ -105,2 +114,3 @@

private readonly onAbort?: (err: Error) => void
private readonly sendCloseWriteTimeout: number

@@ -125,2 +135,3 @@ protected readonly log: Logger

}
this.sendCloseWriteTimeout = init.sendCloseWriteTimeout ?? DEFAULT_SEND_CLOSE_WRITE_TIMEOUT

@@ -141,3 +152,2 @@ this.onEnd = init.onEnd

this.readStatus = 'closed'
this.onSourceEnd(err)

@@ -187,7 +197,15 @@ }

this.log.trace('sink finished reading from source')
this.writeStatus = 'done'
this.log.trace('sink finished reading from source, write status is "%s"', this.writeStatus)
this.log.trace('sink calling closeWrite')
await this.closeWrite(options)
if (this.writeStatus === 'writing') {
this.writeStatus = 'closing'
this.log.trace('send close write to remote')
await this.sendCloseWrite({
signal: AbortSignal.timeout(this.sendCloseWriteTimeout)
})
this.writeStatus = 'closed'
}
this.onSinkEnd()

@@ -211,2 +229,3 @@ } catch (err: any) {

this.timeline.closeRead = Date.now()
this.readStatus = 'closed'

@@ -223,2 +242,6 @@ if (err != null && this.endErr == null) {

if (this.status !== 'aborted' && this.status !== 'reset') {
this.status = 'closed'
}
if (this.onEnd != null) {

@@ -238,2 +261,3 @@ this.onEnd(this.endErr)

this.timeline.closeWrite = Date.now()
this.writeStatus = 'closed'

@@ -250,2 +274,6 @@ if (err != null && this.endErr == null) {

if (this.status !== 'aborted' && this.status !== 'reset') {
this.status = 'closed'
}
if (this.onEnd != null) {

@@ -285,2 +313,7 @@ this.onEnd(this.endErr)

if (this.status !== 'reset' && this.status !== 'aborted' && this.timeline.closeRead == null) {
this.log.trace('send close read to remote')
await this.sendCloseRead(options)
}
if (readStatus === 'ready') {

@@ -291,7 +324,2 @@ this.log.trace('ending internal source queue')

if (this.status !== 'reset' && this.status !== 'aborted' && this.timeline.closeRead == null) {
this.log.trace('send close read to remote')
await this.sendCloseRead(options)
}
this.log.trace('closed readable end of stream')

@@ -307,12 +335,9 @@ }

const writeStatus = this.writeStatus
if (this.writeStatus === 'ready') {
this.log.trace('sink was never sunk, sink an empty array')
await this.sink([])
await raceSignal(this.sink([]), options.signal)
}
this.writeStatus = 'closing'
if (writeStatus === 'writing') {
if (this.writeStatus === 'writing') {
// stop reading from the source passed to `.sink` in the microtask queue

@@ -325,3 +350,4 @@ // - this lets any data queued by the user in the current tick get read

this.sinkController.abort()
this.sinkEnd.promise.then(resolve, reject)
raceSignal(this.sinkEnd.promise, options.signal)
.then(resolve, reject)
})

@@ -331,7 +357,2 @@ })

if (this.status !== 'reset' && this.status !== 'aborted' && this.timeline.closeWrite == null) {
this.log.trace('send close write to remote')
await this.sendCloseWrite(options)
}
this.writeStatus = 'closed'

@@ -381,2 +402,3 @@

this.status = 'reset'
this.timeline.reset = Date.now()
this._closeSinkAndSource(err)

@@ -448,3 +470,3 @@ this.onReset?.()

this.log.trace('muxer destroyed')
this.log.trace('stream destroyed')

@@ -451,0 +473,0 @@ this._closeSinkAndSource()

@@ -8,4 +8,4 @@ import type { Connection } from '../connection/index.js'

onConnect?: (peerId: PeerId, conn: Connection) => void
onDisconnect?: (peerId: PeerId) => void
onConnect?(peerId: PeerId, conn: Connection): void
onDisconnect?(peerId: PeerId): void
}

@@ -18,7 +18,7 @@ import type { Connection, MultiaddrConnection } from '../connection/index.js'

*/
listen: (multiaddr: Multiaddr) => Promise<void>
listen(multiaddr: Multiaddr): Promise<void>
/**
* Get listen addresses
*/
getAddrs: () => Multiaddr[]
getAddrs(): Multiaddr[]
/**

@@ -29,3 +29,3 @@ * Close listener

*/
close: () => Promise<void>
close(): Promise<void>
}

@@ -65,3 +65,3 @@

*/
dial: (ma: Multiaddr, options: DialOptions) => Promise<Connection>
dial(ma: Multiaddr, options: DialOptions): Promise<Connection>

@@ -71,3 +71,3 @@ /**

*/
createListener: (options: CreateListenerOptions) => Listener
createListener(options: CreateListenerOptions): Listener

@@ -115,3 +115,3 @@ /**

*/
upgradeOutbound: (maConn: MultiaddrConnection, opts?: UpgraderOptions) => Promise<Connection>
upgradeOutbound(maConn: MultiaddrConnection, opts?: UpgraderOptions): Promise<Connection>

@@ -121,3 +121,3 @@ /**

*/
upgradeInbound: (maConn: MultiaddrConnection, opts?: UpgraderOptions) => Promise<Connection>
upgradeInbound(maConn: MultiaddrConnection, opts?: UpgraderOptions): Promise<Connection>
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc