@helia/interface 6.2.1-73a28eda → 6.2.1-9114743f

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/index.ts", "../../../node_modules/@ipshipyard/crypto/src/index.ts", "../src/blocks.ts", "../src/errors.ts"],
4
- "sourcesContent": ["/**\n * @packageDocumentation\n *\n * The API defined by a {@link Helia} node\n *\n * @example\n *\n * ```typescript\n * import type { Helia } from '@helia/interface'\n *\n * export function doSomething(helia: Helia) {\n * // use helia node functions here\n * }\n * ```\n */\n\nimport type { Blocks } from './blocks.ts'\nimport type { Pins } from './pins.ts'\nimport type { Routing } from './routing.ts'\nimport type { CryptoLoader, Keychain } from '@ipshipyard/keychain'\nimport type { ComponentLogger, Libp2p, Metrics, TypedEventEmitter } from '@libp2p/interface'\nimport type { DNS } from '@multiformats/dns'\nimport type { AbortOptions } from 'abort-error'\nimport type { Datastore } from 'interface-datastore'\nimport type { BlockCodec, MultihashHasher } from 'multiformats'\nimport type { CID } from 'multiformats/cid'\nimport type { ProgressEvent, ProgressOptions } from 'progress-events'\n\nexport interface CodecLoader {\n <T = any, Code extends number = any>(code: Code, options?: AbortOptions): BlockCodec<Code, T> | Promise<BlockCodec<Code, T>>\n}\n\nexport interface HasherLoader {\n (code: number, options?: AbortOptions): MultihashHasher | Promise<MultihashHasher>\n}\n\nexport type { CryptoLoader, Keychain } from '@ipshipyard/keychain'\nexport type { Crypto, PrivateKey, PublicKey } from '@ipshipyard/crypto'\nexport { isPrivateKey, isPublicKey } from '@ipshipyard/crypto'\n\n/**\n * The API presented by a Helia node\n */\nexport interface Helia<T extends Libp2p = Libp2p> {\n /**\n * The libp2p instance\n */\n libp2p: T\n\n /**\n * Where the blocks are stored\n */\n blockstore: Blocks\n\n /**\n * A key/value store\n */\n datastore: Datastore\n\n /**\n * Event emitter for Helia start and stop events\n */\n events: TypedEventEmitter<HeliaEvents<T>>\n\n /**\n * Secure storage for private keys\n */\n keychain: Keychain\n\n /**\n * Pinning operations for blocks in the blockstore\n */\n pins: Pins\n\n /**\n * A logging component that can be reused by consumers\n */\n logger: ComponentLogger\n\n /**\n * The routing component allows performing operations such as looking up\n * content providers, information about peers, etc.\n */\n routing: Routing\n\n /**\n * The DNS property can be used to perform lookups of various record types and\n * will use a resolver appropriate to the current platform.\n */\n dns: DNS\n\n /**\n * A metrics object that can be used to collected arbitrary stats about node\n * usage.\n */\n metrics?: Metrics\n\n /**\n * Starts the Helia node\n */\n start(): Promise<void>\n\n /**\n * Stops the Helia node\n */\n stop(): Promise<void>\n\n /**\n * Remove any unpinned blocks from the blockstore\n */\n gc(options?: GCOptions): Promise<void>\n\n /**\n * Load an IPLD codec. Implementations may return a promise if, for example,\n * the codec is being fetched from the network.\n */\n getCodec: CodecLoader\n\n /**\n * Hashers can be used to hash a piece of data with the specified hashing\n * algorithm. Implementations may return a promise if, for example,\n * the hasher is being fetched from the network.\n */\n getHasher: HasherLoader\n\n /**\n * Cryptography implementations securely sign and verify data\n */\n getCrypto: CryptoLoader\n}\n\nexport type GcEvents =\n ProgressEvent<'helia:gc:deleted', CID> |\n ProgressEvent<'helia:gc:error', Error>\n\nexport interface GCOptions extends AbortOptions, ProgressOptions<GcEvents> {\n\n}\n\nexport interface HeliaEvents<T extends Libp2p = Libp2p> {\n /**\n * This event notifies listeners that the node has started\n *\n * ```TypeScript\n * helia.addEventListener('start', (event) => {\n * console.info(event.detail.libp2p.isStarted()) // true\n * })\n * ```\n */\n start: CustomEvent<Helia<T>>\n\n /**\n * This event notifies listeners that the node has stopped\n *\n * ```TypeScript\n * helia.addEventListener('stop', (event) => {\n * console.info(event.detail.libp2p.isStarted()) // false\n * })\n * ```\n */\n stop: CustomEvent<Helia<T>>\n}\n\nexport * from './blocks.ts'\nexport * from './errors.ts'\nexport * from './pins.ts'\nexport * from './routing.ts'\n", "/**\n * @packageDocumentation\n *\n * WebCrypto-based implementations of ECDSA, Ed25519, and RSA cryptography.\n */\nimport type { AbortOptions } from 'abort-error'\nimport type { CID, MultihashDigest } from 'multiformats/cid'\n\nexport { ecdsaCrypto } from './ecdsa.ts'\nexport { ed25519Crypto } from './ed25519.ts'\nexport { rsaCrypto } from './rsa.ts'\n\nexport interface PublicKey {\n /**\n * The type of the crypto implementation, e.g. `Ed15519`\n */\n readonly type: string\n\n /**\n * The code that is used as the `Type` field in the protobuf representation of\n * the public/private keys\n */\n readonly code: number\n\n /**\n * Return a MultihashDigest that represents this key\n */\n toMultihash (): MultihashDigest\n\n /**\n * Return the libp2p-key CID that represents this key\n */\n toCID (): CID<unknown, 0x72, number, 1>\n\n /**\n * Return this key encoded as a protobuf PublicKey message\n */\n toProtobuf (): Uint8Array<ArrayBuffer>\n\n /**\n * Return this key as a RFC 7517 Json Web Key\n */\n toJWK (): JsonWebKey\n\n /**\n * Verify the passed message against it's signature\n */\n verify(message: Uint8Array, signature: Uint8Array, options?: AbortOptions): boolean | Promise<boolean>\n}\n\nexport function isPublicKey (obj?: any): obj is PublicKey {\n if (obj == null) {\n return false\n }\n\n return typeof obj.type === 'string' && typeof obj.code === 'number' && typeof obj.verify === 'function'\n}\n\nexport interface PrivateKey {\n /**\n * The type of the crypto implementation, e.g. `Ed15519`\n */\n readonly type: string\n\n /**\n * The code that is used as the `Type` field in the protobuf representation of\n * the public/private keys\n */\n readonly code: number\n\n /**\n * The public key that corresponds to this private key\n */\n readonly publicKey: PublicKey\n\n /**\n * Return this key encoded as a protobuf PrivateKey message\n */\n toProtobuf (): Uint8Array<ArrayBuffer>\n\n /**\n * Return this key as a RFC 7517 Json Web Key\n */\n toJWK (): JsonWebKey\n\n /**\n * Sign the passed message and return a signature\n */\n sign(message: Uint8Array, options?: AbortOptions): Uint8Array<ArrayBuffer> | Promise<Uint8Array<ArrayBuffer>>\n}\n\nexport function isPrivateKey (obj?: any): obj is PrivateKey {\n if (obj == null) {\n return false\n }\n\n return typeof obj.type === 'string' && typeof obj.code === 'number' && typeof obj.sign === 'function' && isPublicKey(obj.publicKey)\n}\n\nexport interface Crypto {\n /**\n * The type of the crypto implementation, e.g. `Ed15519`\n */\n type: string\n\n /**\n * The code that is used as the `Type` field in the protobuf representation of\n * the public/private keys\n */\n code: number\n\n /**\n * Create a new private key\n */\n generatePrivateKey(options?: AbortOptions & Record<string, any>): Promise<PrivateKey>\n\n /**\n * Convert the passed bytes into a public key. The bytes come from the `.Data`\n * field of a `PublicKey` protobuf message.\n */\n publicKeyFromProtobuf(buf: Uint8Array, options?: AbortOptions): PublicKey | Promise<PublicKey>\n\n /**\n * Convert the passed bytes into a public key. The bytes come from the `.Data`\n * field of a `PublicKey` protobuf message.\n */\n privateKeyFromProtobuf(buf: Uint8Array, options?: AbortOptions): PrivateKey | Promise<PrivateKey>\n}\n", "import type { RoutingFindProvidersProgressEvents } from './routing.ts'\nimport type { PeerId, AbortOptions } from '@libp2p/interface'\nimport type { Multiaddr } from '@multiformats/multiaddr'\nimport type { Blockstore } from 'interface-blockstore'\nimport type { CID } from 'multiformats/cid'\nimport type { ProgressEvent, ProgressOptions } from 'progress-events'\n\nexport type { Pair, InputPair } from 'interface-blockstore'\n\nexport interface ProviderOptions {\n /**\n * An optional list of peers known to host at least the root block of the DAG\n * that will be fetched.\n *\n * If this list is omitted, or if the peers cannot supply the root or any\n * child blocks, a `findProviders` routing query will be run to find peers\n * that can supply the blocks.\n */\n providers?: Array<PeerId | Multiaddr | Multiaddr[]>\n}\n\n/**\n * A block broker will contact a provider to retrieve a block\n */\nexport interface BlockBrokerConnectProgressEvent {\n broker: string\n type: 'connect'\n provider: PeerId\n cid: CID\n}\n\n/**\n * A block broker has contacted a provider to retrieve a block\n */\nexport interface BlockBrokerConnectedProgressEvent {\n broker: string\n type: 'connected'\n provider: PeerId\n address: Multiaddr\n cid: CID\n}\n\n/**\n * A block broker has retrieved a block from a provider\n */\nexport interface BlockBrokerRequestBlockProgressEvent {\n broker: string\n type: 'request-block'\n provider: PeerId\n cid: CID\n}\n\n/**\n * A block broker has retrieved a block from a provider\n */\nexport interface BlockBrokerReceiveBlockProgressEvent {\n broker: string\n type: 'receive-block'\n provider: PeerId\n cid: CID\n}\n\nexport type BlockBrokerGetBlockProgressEvents = ProgressEvent<'helia:block-broker:connect', BlockBrokerConnectProgressEvent>\n | ProgressEvent<'helia:block-broker:connected', BlockBrokerConnectedProgressEvent>\n | ProgressEvent<'helia:block-broker:request-block', BlockBrokerRequestBlockProgressEvent>\n | ProgressEvent<'helia:block-broker:receive-block', BlockBrokerReceiveBlockProgressEvent>\n\nexport type HasBlockProgressEvents =\n ProgressEvent<'blocks:put:duplicate', CID> |\n ProgressEvent<'blocks:put:providers:notify', CID> |\n ProgressEvent<'blocks:put:blockstore:put', CID>\n\nexport type PutBlockProgressEvents =\n ProgressEvent<'blocks:put:duplicate', CID> |\n ProgressEvent<'blocks:put:providers:notify', CID> |\n ProgressEvent<'blocks:put:blockstore:put', CID>\n\nexport type PutManyBlocksProgressEvents =\n ProgressEvent<'blocks:put-many:duplicate', CID> |\n ProgressEvent<'blocks:put-many:providers:notify', CID> |\n ProgressEvent<'blocks:put-many:blockstore:put-many'>\n\nexport type GetBlockProgressEvents =\n ProgressEvent<'blocks:get:providers:want', CID> |\n ProgressEvent<'blocks:get:blockstore:get', CID> |\n ProgressEvent<'blocks:get:blockstore:put', CID> |\n RoutingFindProvidersProgressEvents |\n BlockBrokerGetBlockProgressEvents\n\nexport type GetManyBlocksProgressEvents =\n ProgressEvent<'blocks:get-many:blockstore:get-many'> |\n ProgressEvent<'blocks:get-many:providers:want', CID> |\n ProgressEvent<'blocks:get-many:blockstore:put', CID>\n\nexport type GetAllBlocksProgressEvents =\n ProgressEvent<'blocks:get-all:blockstore:get-many'>\n\nexport type DeleteBlockProgressEvents =\n ProgressEvent<'blocks:delete:blockstore:delete', CID>\n\nexport type DeleteManyBlocksProgressEvents =\n ProgressEvent<'blocks:delete-many:blockstore:delete-many'>\n\nexport interface GetOfflineOptions {\n /**\n * If true, do not attempt to fetch any missing blocks from the network\n *\n * @default false\n */\n offline?: boolean\n}\n\nexport interface Blocks extends Blockstore<ProgressOptions<HasBlockProgressEvents>,\nProgressOptions<PutBlockProgressEvents>, ProgressOptions<PutManyBlocksProgressEvents>,\nGetOfflineOptions & ProviderOptions & ProgressOptions<GetBlockProgressEvents>,\nGetOfflineOptions & ProviderOptions & ProgressOptions<GetManyBlocksProgressEvents>,\nProgressOptions<GetAllBlocksProgressEvents>,\nProgressOptions<DeleteBlockProgressEvents>, ProgressOptions<DeleteManyBlocksProgressEvents>\n> {\n /**\n * A blockstore session only fetches blocks from a subset of network peers to\n * reduce network traffic and improve performance.\n *\n * The initial set of peers can be specified, alternatively a `findProviders`\n * routing query will occur to populate the set instead.\n */\n createSession(root: CID, options?: CreateSessionOptions<GetBlockProgressEvents>): SessionBlockstore\n}\n\n/**\n * A session blockstore is a special blockstore that only pulls content from a\n * subset of network peers which respond as having the block for the initial\n * root CID.\n *\n * Any blocks written to the blockstore as part of the session will propagate\n * to the blockstore the session was created from.\n *\n */\nexport interface SessionBlockstore extends Blockstore<ProgressOptions<HasBlockProgressEvents>,\nProgressOptions<PutBlockProgressEvents>, ProgressOptions<PutManyBlocksProgressEvents>,\nGetOfflineOptions & ProgressOptions<GetBlockProgressEvents>, GetOfflineOptions & ProgressOptions<GetManyBlocksProgressEvents>, ProgressOptions<GetAllBlocksProgressEvents>,\nProgressOptions<DeleteBlockProgressEvents>, ProgressOptions<DeleteManyBlocksProgressEvents>\n> {\n /**\n * Any in-progress operations will be aborted.\n */\n close(): void\n\n /**\n * Adds a new peer to the session if they are supported and are either\n * not already in the session and have not been evicted previously.\n */\n addPeer (peer: PeerId | Multiaddr | Multiaddr[], options?: AbortOptions): Promise<void>\n}\n\nexport interface BlockRetrievalOptions <ProgressEvents extends ProgressEvent<any, any> = ProgressEvent<any, any>> extends AbortOptions, ProgressOptions<ProgressEvents>, ProviderOptions {\n /**\n * A function that blockBrokers should call prior to returning a block to ensure it can maintain control\n * of the block request flow. e.g. TrustedGatewayBlockBroker will use this to ensure that the block\n * is valid from one of the gateways before assuming its work is done. If the block is not valid, it should try another gateway\n * and WILL consider the gateway that returned the invalid blocks completely unreliable.\n */\n validateFn?(block: Uint8Array): Promise<void>\n\n /**\n * The maximum size a block can be in bytes.\n *\n * Attempts to retrieve a block larger than this will cause an error to be thrown.\n *\n * @default 2_097_152\n */\n maxSize?: number\n}\n\nexport interface BlockAnnounceOptions <ProgressEvents extends ProgressEvent<any, any> = ProgressEvent<any, any>> extends AbortOptions, ProgressOptions<ProgressEvents> {\n\n}\n\nexport interface CreateSessionOptions <ProgressEvents extends ProgressEvent<any, any> = ProgressEvent<any, any>> extends AbortOptions, ProgressOptions<ProgressEvents>, ProviderOptions, GetOfflineOptions {\n /**\n * The minimum number of providers for the root CID that are required for\n * successful session creation.\n *\n * The session will become usable once this many providers have been\n * discovered, up to `maxProviders` providers will continue to be added.\n *\n * @default 1\n */\n minProviders?: number\n\n /**\n * The maximum number of providers for the root CID to be added to a session.\n *\n * @default 5\n */\n maxProviders?: number\n\n /**\n * A scalable cuckoo filter is used to ensure we do not query the same peer\n * multiple times for the same CID. This setting controls how the initial\n * maximum number of peers that are expected to be in the filter.\n *\n * @default 100\n */\n cidPeerFilterSize?: number\n}\n\nexport interface BlockBroker<RetrieveProgressEvents extends ProgressEvent<any, any> = ProgressEvent<any, any>, AnnounceProgressEvents extends ProgressEvent<any, any> = ProgressEvent<any, any>> {\n /**\n * The name of the block broker, used for logging purposes\n */\n name: string\n\n /**\n * Retrieve a block from a source\n */\n retrieve?(cid: CID, options?: BlockRetrievalOptions<RetrieveProgressEvents>): Promise<Uint8Array>\n\n /**\n * Make a new block available to peers\n */\n announce?(cid: CID, options?: BlockAnnounceOptions<AnnounceProgressEvents>): Promise<void>\n\n /**\n * Create a new session\n */\n createSession?(options?: CreateSessionOptions<RetrieveProgressEvents>): SessionBlockBroker<RetrieveProgressEvents, AnnounceProgressEvents>\n}\n\nexport interface SessionBlockBroker<RetrieveProgressEvents extends ProgressEvent<any, any> = ProgressEvent<any, any>, AnnounceProgressEvents extends ProgressEvent<any, any> = ProgressEvent<any, any>> extends BlockBroker<RetrieveProgressEvents, AnnounceProgressEvents> {\n /**\n * Adds a new peer to the session if they are supported and are either\n * not already in the session and have not been evicted previously.\n */\n addPeer (peer: PeerId | Multiaddr | Multiaddr[], options?: AbortOptions): Promise<void>\n}\n\nexport const DEFAULT_SESSION_MIN_PROVIDERS = 1\nexport const DEFAULT_SESSION_MAX_PROVIDERS = 5\nexport const DEFAULT_CID_PEER_FILTER_SIZE = 100\n", "export class InsufficientProvidersError extends Error {\n static name = 'InsufficientProvidersError'\n\n constructor (message = 'Insufficient providers found') {\n super(message)\n this.name = 'InsufficientProvidersError'\n }\n}\n\nexport class NoRoutersAvailableError extends Error {\n static name = 'NoRoutersAvailableError'\n\n constructor (message = 'No routers available') {\n super(message)\n this.name = 'NoRoutersAvailableError'\n }\n}\n\nexport class UnknownHashAlgorithmError extends Error {\n static name = 'UnknownHashAlgorithmError'\n\n constructor (message = 'Unknown hash algorithm') {\n super(message)\n this.name = 'UnknownHashAlgorithmError'\n }\n}\n\nexport class UnknownCodecError extends Error {\n static name = 'UnknownCodecError'\n\n constructor (message = 'Unknown codec') {\n super(message)\n this.name = 'UnknownCodecError'\n }\n}\n\nexport class InvalidCodecError extends Error {\n static name = 'InvalidCodecError'\n\n constructor (message = 'Invalid codec') {\n super(message)\n this.name = 'InvalidCodecError'\n }\n}\n\nexport class UnknownCryptoError extends Error {\n static name = 'UnknownCryptoError'\n name = 'UnknownCryptoError'\n}\n"],
4
+ "sourcesContent": ["/**\n * @packageDocumentation\n *\n * The API defined by a {@link Helia} node\n *\n * @example\n *\n * ```typescript\n * import type { Helia } from '@helia/interface'\n *\n * export function doSomething(helia: Helia) {\n * // use helia node functions here\n * }\n * ```\n */\n\nimport type { BlockBroker, Blocks } from './blocks.ts'\nimport type { Pins } from './pins.ts'\nimport type { Router, Routing } from './routing.ts'\nimport type { CryptoLoader, Keychain } from '@ipshipyard/keychain'\nimport type { Metrics } from '@libp2p/interface'\nimport type { DNS } from '@multiformats/dns'\nimport type { AbortOptions } from 'abort-error'\nimport type { ComponentLogger } from 'birnam'\nimport type { Datastore } from 'interface-datastore'\nimport type { TypedEventEmitter } from 'main-event'\nimport type { BlockCodec, MultihashHasher } from 'multiformats'\nimport type { CID } from 'multiformats/cid'\nimport type { ProgressEvent, ProgressOptions } from 'progress-events'\n\nexport interface CodecLoader {\n <T = any, Code extends number = any>(code: Code, options?: AbortOptions): BlockCodec<Code, T> | Promise<BlockCodec<Code, T>>\n}\n\nexport interface HasherLoader {\n (code: number, options?: AbortOptions): MultihashHasher | Promise<MultihashHasher>\n}\n\nexport type { CryptoLoader, Keychain } from '@ipshipyard/keychain'\nexport type { Crypto, PrivateKey, PublicKey } from '@ipshipyard/crypto'\nexport { isPrivateKey, isPublicKey } from '@ipshipyard/crypto'\n\nexport interface NodeInfo {\n name: string\n version: string\n}\n\nexport interface HeliaMixin<Start extends Helia = Helia, Stop = Start> {\n start?(helia: Start): Promise<void> | void\n stop?(helia: Stop): Promise<void> | void\n}\n\n/**\n * The API presented by a Helia node\n */\nexport interface Helia {\n /**\n * Runtime information about the node\n */\n info: NodeInfo\n\n /**\n * Where the blocks are stored\n */\n blockstore: Blocks\n\n /**\n * A key/value store\n */\n datastore: Datastore\n\n /**\n * Event emitter for Helia start and stop events\n */\n events: TypedEventEmitter<HeliaEvents<this>>\n\n /**\n * Secure storage for private keys\n */\n keychain: Keychain\n\n /**\n * Pinning operations for blocks in the blockstore\n */\n pins: Pins\n\n /**\n * A logging component that can be reused by consumers\n */\n logger: ComponentLogger\n\n /**\n * The routing component allows performing operations such as looking up\n * content providers, information about peers, etc.\n */\n routing: Routing\n\n /**\n * The DNS property can be used to perform lookups of various record types and\n * will use a resolver appropriate to the current platform.\n */\n dns: DNS\n\n /**\n * A metrics object that can be used to collected arbitrary stats about node\n * usage.\n */\n metrics?: Metrics\n\n /**\n * The current status of the Helia node\n */\n status: 'starting' | 'started' | 'stopping' | 'stopped'\n\n /**\n * Starts the Helia node\n */\n start(options?: AbortOptions): Promise<this>\n\n /**\n * Stops the Helia node\n */\n stop(options?: AbortOptions): Promise<this>\n\n /**\n * Remove any unpinned blocks from the blockstore\n */\n gc(options?: GCOptions): Promise<void>\n\n /**\n * Load an IPLD codec. Implementations may return a promise if, for example,\n * the codec is being fetched from the network.\n */\n getCodec: CodecLoader\n\n /**\n * Hashers can be used to hash a piece of data with the specified hashing\n * algorithm. Implementations may return a promise if, for example,\n * the hasher is being fetched from the network.\n */\n getHasher: HasherLoader\n\n /**\n * Cryptography implementations securely sign and verify data\n */\n getCrypto: CryptoLoader\n\n /**\n * Returns `true` if a router with the passed name has been configured\n */\n hasRouter (name: string): boolean\n\n /**\n * Add a router\n */\n addRouter(router: Router): void\n\n /**\n * Returns `true` if a block broker with the passed name has been configured\n */\n hasBlockBroker (name: string): boolean\n\n /**\n * Add a block broker\n */\n addBlockBroker(blockBroker: BlockBroker): void\n\n /**\n * Add a mixin to extend runtime functionality\n */\n addMixin<T extends Helia = Helia & Record<string, any>>(mixin: HeliaMixin<T>): void\n}\n\nexport type GcEvents =\n ProgressEvent<'helia:gc:deleted', CID> |\n ProgressEvent<'helia:gc:error', Error>\n\nexport interface GCOptions extends AbortOptions, ProgressOptions<GcEvents> {\n\n}\n\nexport interface HeliaEvents<H extends Helia = Helia> {\n /**\n * This event notifies listeners that the node has started\n *\n * ```TypeScript\n * helia.addEventListener('start', (event) => {\n * console.info(event.detail.libp2p.isStarted()) // true\n * })\n * ```\n */\n start: CustomEvent<H>\n\n /**\n * This event notifies listeners that the node has stopped\n *\n * ```TypeScript\n * helia.addEventListener('stop', (event) => {\n * console.info(event.detail.libp2p.isStarted()) // false\n * })\n * ```\n */\n stop: CustomEvent<H>\n}\n\nexport * from './blocks.ts'\nexport * from './errors.ts'\nexport * from './graph-walker.ts'\nexport * from './pins.ts'\nexport * from './routing.ts'\n", "/**\n * @packageDocumentation\n *\n * WebCrypto-based implementations of ECDSA, Ed25519, and RSA cryptography.\n */\nimport type { AbortOptions } from 'abort-error'\nimport type { CID, MultihashDigest } from 'multiformats/cid'\n\nexport { ecdsaCrypto } from './ecdsa.ts'\nexport { ed25519Crypto } from './ed25519.ts'\nexport { rsaCrypto } from './rsa.ts'\n\nexport interface PublicKey {\n /**\n * The type of the crypto implementation, e.g. `Ed15519`\n */\n readonly type: string\n\n /**\n * The code that is used as the `Type` field in the protobuf representation of\n * the public/private keys\n */\n readonly code: number\n\n /**\n * Return a MultihashDigest that represents this key\n */\n toMultihash (): MultihashDigest\n\n /**\n * Return the libp2p-key CID that represents this key\n */\n toCID (): CID<unknown, 0x72, number, 1>\n\n /**\n * Return this key encoded as a protobuf PublicKey message\n */\n toProtobuf (): Uint8Array<ArrayBuffer>\n\n /**\n * Return this key as a RFC 7517 Json Web Key\n */\n toJWK (): JsonWebKey\n\n /**\n * Verify the passed message against it's signature\n */\n verify(message: Uint8Array, signature: Uint8Array, options?: AbortOptions): boolean | Promise<boolean>\n}\n\nexport function isPublicKey (obj?: any): obj is PublicKey {\n if (obj == null) {\n return false\n }\n\n return typeof obj.type === 'string' && typeof obj.code === 'number' && typeof obj.verify === 'function'\n}\n\nexport interface PrivateKey {\n /**\n * The type of the crypto implementation, e.g. `Ed15519`\n */\n readonly type: string\n\n /**\n * The code that is used as the `Type` field in the protobuf representation of\n * the public/private keys\n */\n readonly code: number\n\n /**\n * The public key that corresponds to this private key\n */\n readonly publicKey: PublicKey\n\n /**\n * Return this key encoded as a protobuf PrivateKey message\n */\n toProtobuf (): Uint8Array<ArrayBuffer>\n\n /**\n * Return this key as a RFC 7517 Json Web Key\n */\n toJWK (): JsonWebKey\n\n /**\n * Sign the passed message and return a signature\n */\n sign(message: Uint8Array, options?: AbortOptions): Uint8Array<ArrayBuffer> | Promise<Uint8Array<ArrayBuffer>>\n}\n\nexport function isPrivateKey (obj?: any): obj is PrivateKey {\n if (obj == null) {\n return false\n }\n\n return typeof obj.type === 'string' && typeof obj.code === 'number' && typeof obj.sign === 'function' && isPublicKey(obj.publicKey)\n}\n\nexport interface Crypto {\n /**\n * The type of the crypto implementation, e.g. `Ed15519`\n */\n type: string\n\n /**\n * The code that is used as the `Type` field in the protobuf representation of\n * the public/private keys\n */\n code: number\n\n /**\n * Create a new private key\n */\n generatePrivateKey(options?: AbortOptions & Record<string, any>): Promise<PrivateKey>\n\n /**\n * Convert the passed bytes into a public key. The bytes come from the `.Data`\n * field of a `PublicKey` protobuf message.\n */\n publicKeyFromProtobuf(buf: Uint8Array, options?: AbortOptions): PublicKey | Promise<PublicKey>\n\n /**\n * Convert the passed bytes into a public key. The bytes come from the `.Data`\n * field of a `PublicKey` protobuf message.\n */\n privateKeyFromProtobuf(buf: Uint8Array, options?: AbortOptions): PrivateKey | Promise<PrivateKey>\n}\n", "import type { RoutingFindProvidersProgressEvents } from './routing.ts'\nimport type { Multiaddr } from '@multiformats/multiaddr'\nimport type { AbortOptions } from 'abort-error'\nimport type { Blockstore } from 'interface-blockstore'\nimport type { CID } from 'multiformats/cid'\nimport type { ProgressEvent, ProgressOptions } from 'progress-events'\n\nexport type { Pair, InputPair } from 'interface-blockstore'\n\nexport interface ProviderOptions {\n /**\n * An optional list of peers known to host at least the root block of the DAG\n * that will be fetched.\n *\n * If this list is omitted, or if the peers cannot supply the root or any\n * child blocks, a `findProviders` routing query will be run to find peers\n * that can supply the blocks.\n */\n providers?: Array<CID | Multiaddr | Multiaddr[]>\n}\n\n/**\n * A block broker will contact a provider to retrieve a block\n */\nexport interface BlockBrokerConnectProgressEvent {\n broker: string\n type: 'connect'\n provider: CID\n cid: CID\n}\n\n/**\n * A block broker has contacted a provider to retrieve a block\n */\nexport interface BlockBrokerConnectedProgressEvent {\n broker: string\n type: 'connected'\n provider: CID\n address: Multiaddr\n cid: CID\n}\n\n/**\n * A block broker has retrieved a block from a provider\n */\nexport interface BlockBrokerRequestBlockProgressEvent {\n broker: string\n type: 'request-block'\n provider: CID\n cid: CID\n}\n\n/**\n * A block broker has retrieved a block from a provider\n */\nexport interface BlockBrokerReceiveBlockProgressEvent {\n broker: string\n type: 'receive-block'\n provider: CID\n cid: CID\n}\n\nexport type BlockBrokerGetBlockProgressEvents = ProgressEvent<'helia:block-broker:connect', BlockBrokerConnectProgressEvent>\n | ProgressEvent<'helia:block-broker:connected', BlockBrokerConnectedProgressEvent>\n | ProgressEvent<'helia:block-broker:request-block', BlockBrokerRequestBlockProgressEvent>\n | ProgressEvent<'helia:block-broker:receive-block', BlockBrokerReceiveBlockProgressEvent>\n\nexport type HasBlockProgressEvents =\n ProgressEvent<'blocks:put:duplicate', CID> |\n ProgressEvent<'blocks:put:providers:notify', CID> |\n ProgressEvent<'blocks:put:blockstore:put', CID>\n\nexport type PutBlockProgressEvents =\n ProgressEvent<'blocks:put:duplicate', CID> |\n ProgressEvent<'blocks:put:providers:notify', CID> |\n ProgressEvent<'blocks:put:blockstore:put', CID>\n\nexport type PutManyBlocksProgressEvents =\n ProgressEvent<'blocks:put-many:duplicate', CID> |\n ProgressEvent<'blocks:put-many:providers:notify', CID> |\n ProgressEvent<'blocks:put-many:blockstore:put-many'>\n\nexport type GetBlockProgressEvents =\n ProgressEvent<'blocks:get:providers:want', CID> |\n ProgressEvent<'blocks:get:blockstore:get', CID> |\n ProgressEvent<'blocks:get:blockstore:put', CID> |\n RoutingFindProvidersProgressEvents |\n BlockBrokerGetBlockProgressEvents\n\nexport type GetManyBlocksProgressEvents =\n ProgressEvent<'blocks:get-many:blockstore:get-many'> |\n ProgressEvent<'blocks:get-many:providers:want', CID> |\n ProgressEvent<'blocks:get-many:blockstore:put', CID>\n\nexport type GetAllBlocksProgressEvents =\n ProgressEvent<'blocks:get-all:blockstore:get-many'>\n\nexport type DeleteBlockProgressEvents =\n ProgressEvent<'blocks:delete:blockstore:delete', CID>\n\nexport type DeleteManyBlocksProgressEvents =\n ProgressEvent<'blocks:delete-many:blockstore:delete-many'>\n\nexport interface GetOfflineOptions {\n /**\n * If true, do not attempt to fetch any missing blocks from the network\n *\n * @default false\n */\n offline?: boolean\n}\n\nexport interface Blocks extends Blockstore<ProgressOptions<HasBlockProgressEvents>,\nProgressOptions<PutBlockProgressEvents>, ProgressOptions<PutManyBlocksProgressEvents>,\nGetOfflineOptions & ProviderOptions & ProgressOptions<GetBlockProgressEvents>,\nGetOfflineOptions & ProviderOptions & ProgressOptions<GetManyBlocksProgressEvents>,\nProgressOptions<GetAllBlocksProgressEvents>,\nProgressOptions<DeleteBlockProgressEvents>, ProgressOptions<DeleteManyBlocksProgressEvents>\n> {\n /**\n * A blockstore session only fetches blocks from a subset of network peers to\n * reduce network traffic and improve performance.\n *\n * The initial set of peers can be specified, alternatively a `findProviders`\n * routing query will occur to populate the set instead.\n */\n createSession(root: CID, options?: CreateSessionOptions<GetBlockProgressEvents>): SessionBlockstore\n}\n\n/**\n * A session blockstore is a special blockstore that only pulls content from a\n * subset of network peers which respond as having the block for the initial\n * root CID.\n *\n * Any blocks written to the blockstore as part of the session will propagate\n * to the blockstore the session was created from.\n *\n */\nexport interface SessionBlockstore extends Blockstore<ProgressOptions<HasBlockProgressEvents>,\nProgressOptions<PutBlockProgressEvents>, ProgressOptions<PutManyBlocksProgressEvents>,\nGetOfflineOptions & ProgressOptions<GetBlockProgressEvents>, GetOfflineOptions & ProgressOptions<GetManyBlocksProgressEvents>, ProgressOptions<GetAllBlocksProgressEvents>,\nProgressOptions<DeleteBlockProgressEvents>, ProgressOptions<DeleteManyBlocksProgressEvents>\n> {\n /**\n * Any in-progress operations will be aborted.\n */\n close(): void\n\n /**\n * Adds a new peer to the session if they are supported and are either\n * not already in the session and have not been evicted previously.\n */\n addPeer (peer: CID | Multiaddr | Multiaddr[], options?: AbortOptions): Promise<void>\n}\n\nexport interface BlockRetrievalOptions <ProgressEvents extends ProgressEvent<any, any> = ProgressEvent<any, any>> extends AbortOptions, ProgressOptions<ProgressEvents>, ProviderOptions {\n /**\n * A function that blockBrokers should call prior to returning a block to ensure it can maintain control\n * of the block request flow. e.g. TrustedGatewayBlockBroker will use this to ensure that the block\n * is valid from one of the gateways before assuming its work is done. If the block is not valid, it should try another gateway\n * and WILL consider the gateway that returned the invalid blocks completely unreliable.\n */\n validateFn?(block: Uint8Array): Promise<void>\n\n /**\n * The maximum size a block can be in bytes.\n *\n * Attempts to retrieve a block larger than this will cause an error to be thrown.\n *\n * @default 2_097_152\n */\n maxSize?: number\n}\n\nexport interface BlockAnnounceOptions <ProgressEvents extends ProgressEvent<any, any> = ProgressEvent<any, any>> extends AbortOptions, ProgressOptions<ProgressEvents> {\n\n}\n\nexport interface CreateSessionOptions <ProgressEvents extends ProgressEvent<any, any> = ProgressEvent<any, any>> extends AbortOptions, ProgressOptions<ProgressEvents>, ProviderOptions, GetOfflineOptions {\n /**\n * The minimum number of providers for the root CID that are required for\n * successful session creation.\n *\n * The session will become usable once this many providers have been\n * discovered, up to `maxProviders` providers will continue to be added.\n *\n * @default 1\n */\n minProviders?: number\n\n /**\n * The maximum number of providers for the root CID to be added to a session.\n *\n * @default 5\n */\n maxProviders?: number\n\n /**\n * A scalable cuckoo filter is used to ensure we do not query the same peer\n * multiple times for the same CID. This setting controls how the initial\n * maximum number of peers that are expected to be in the filter.\n *\n * @default 100\n */\n cidPeerFilterSize?: number\n}\n\nexport interface BlockBroker<RetrieveProgressEvents extends ProgressEvent<any, any> = ProgressEvent<any, any>, AnnounceProgressEvents extends ProgressEvent<any, any> = ProgressEvent<any, any>> {\n /**\n * The name of the block broker, used for logging purposes\n */\n name: string\n\n /**\n * Retrieve a block from a source\n */\n retrieve?(cid: CID, options?: BlockRetrievalOptions<RetrieveProgressEvents>): Promise<Uint8Array>\n\n /**\n * Make a new block available to peers\n */\n announce?(cid: CID, options?: BlockAnnounceOptions<AnnounceProgressEvents>): Promise<void>\n\n /**\n * Create a new session\n */\n createSession?(options?: CreateSessionOptions<RetrieveProgressEvents>): SessionBlockBroker<RetrieveProgressEvents, AnnounceProgressEvents>\n}\n\nexport interface SessionBlockBroker<RetrieveProgressEvents extends ProgressEvent<any, any> = ProgressEvent<any, any>, AnnounceProgressEvents extends ProgressEvent<any, any> = ProgressEvent<any, any>> extends BlockBroker<RetrieveProgressEvents, AnnounceProgressEvents> {\n /**\n * Adds a new peer to the session if they are supported and are either\n * not already in the session and have not been evicted previously.\n */\n addPeer (peer: CID | Multiaddr | Multiaddr[], options?: AbortOptions): Promise<void>\n}\n\nexport const DEFAULT_SESSION_MIN_PROVIDERS = 1\nexport const DEFAULT_SESSION_MAX_PROVIDERS = 5\nexport const DEFAULT_CID_PEER_FILTER_SIZE = 100\n", "export class InsufficientProvidersError extends Error {\n static name = 'InsufficientProvidersError'\n\n constructor (message = 'Insufficient providers found') {\n super(message)\n this.name = 'InsufficientProvidersError'\n }\n}\n\nexport class NoRoutersAvailableError extends Error {\n static name = 'NoRoutersAvailableError'\n\n constructor (message = 'No routers available') {\n super(message)\n this.name = 'NoRoutersAvailableError'\n }\n}\n\nexport class UnknownHashAlgorithmError extends Error {\n static name = 'UnknownHashAlgorithmError'\n\n constructor (message = 'Unknown hash algorithm') {\n super(message)\n this.name = 'UnknownHashAlgorithmError'\n }\n}\n\nexport class UnknownCodecError extends Error {\n static name = 'UnknownCodecError'\n\n constructor (message = 'Unknown codec') {\n super(message)\n this.name = 'UnknownCodecError'\n }\n}\n\nexport class InvalidCodecError extends Error {\n static name = 'InvalidCodecError'\n\n constructor (message = 'Invalid codec') {\n super(message)\n this.name = 'InvalidCodecError'\n }\n}\n\nexport class UnknownCryptoError extends Error {\n static name = 'UnknownCryptoError'\n name = 'UnknownCryptoError'\n}\n"],
5
5
  "mappings": ";kcAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kCAAAE,EAAA,kCAAAC,EAAA,kCAAAC,EAAA,+BAAAC,EAAA,sBAAAC,EAAA,4BAAAC,EAAA,sBAAAC,EAAA,uBAAAC,EAAA,8BAAAC,EAAA,iBAAAC,EAAA,gBAAAC,ICkDM,SAAUC,EAAaC,EAAS,CACpC,OAAIA,GAAO,KACF,GAGF,OAAOA,EAAI,MAAS,UAAY,OAAOA,EAAI,MAAS,UAAY,OAAOA,EAAI,QAAW,UAC/F,CAmCM,SAAUC,EAAcD,EAAS,CACrC,OAAIA,GAAO,KACF,GAGF,OAAOA,EAAI,MAAS,UAAY,OAAOA,EAAI,MAAS,UAAY,OAAOA,EAAI,MAAS,YAAcD,EAAYC,EAAI,SAAS,CACpI,CC4IO,IAAME,EAAgC,EAChCC,EAAgC,EAChCC,EAA+B,IC/OtC,IAAOC,EAAP,cAA0C,KAAK,CACnD,OAAO,KAAO,6BAEd,YAAaC,EAAU,+BAA8B,CACnD,MAAMA,CAAO,EACb,KAAK,KAAO,4BACd,GAGWC,EAAP,cAAuC,KAAK,CAChD,OAAO,KAAO,0BAEd,YAAaD,EAAU,uBAAsB,CAC3C,MAAMA,CAAO,EACb,KAAK,KAAO,yBACd,GAGWE,EAAP,cAAyC,KAAK,CAClD,OAAO,KAAO,4BAEd,YAAaF,EAAU,yBAAwB,CAC7C,MAAMA,CAAO,EACb,KAAK,KAAO,2BACd,GAGWG,EAAP,cAAiC,KAAK,CAC1C,OAAO,KAAO,oBAEd,YAAaH,EAAU,gBAAe,CACpC,MAAMA,CAAO,EACb,KAAK,KAAO,mBACd,GAGWI,EAAP,cAAiC,KAAK,CAC1C,OAAO,KAAO,oBAEd,YAAaJ,EAAU,gBAAe,CACpC,MAAMA,CAAO,EACb,KAAK,KAAO,mBACd,GAGWK,EAAP,cAAkC,KAAK,CAC3C,OAAO,KAAO,qBACd,KAAO",
6
6
  "names": ["index_exports", "__export", "DEFAULT_CID_PEER_FILTER_SIZE", "DEFAULT_SESSION_MAX_PROVIDERS", "DEFAULT_SESSION_MIN_PROVIDERS", "InsufficientProvidersError", "InvalidCodecError", "NoRoutersAvailableError", "UnknownCodecError", "UnknownCryptoError", "UnknownHashAlgorithmError", "isPrivateKey", "isPublicKey", "isPublicKey", "obj", "isPrivateKey", "DEFAULT_SESSION_MIN_PROVIDERS", "DEFAULT_SESSION_MAX_PROVIDERS", "DEFAULT_CID_PEER_FILTER_SIZE", "InsufficientProvidersError", "message", "NoRoutersAvailableError", "UnknownHashAlgorithmError", "UnknownCodecError", "InvalidCodecError", "UnknownCryptoError"]
7
7
  }
@@ -1,6 +1,6 @@
1
1
  import type { RoutingFindProvidersProgressEvents } from './routing.ts';
2
- import type { PeerId, AbortOptions } from '@libp2p/interface';
3
2
  import type { Multiaddr } from '@multiformats/multiaddr';
3
+ import type { AbortOptions } from 'abort-error';
4
4
  import type { Blockstore } from 'interface-blockstore';
5
5
  import type { CID } from 'multiformats/cid';
6
6
  import type { ProgressEvent, ProgressOptions } from 'progress-events';
@@ -14,7 +14,7 @@ export interface ProviderOptions {
14
14
  * child blocks, a `findProviders` routing query will be run to find peers
15
15
  * that can supply the blocks.
16
16
  */
17
- providers?: Array<PeerId | Multiaddr | Multiaddr[]>;
17
+ providers?: Array<CID | Multiaddr | Multiaddr[]>;
18
18
  }
19
19
  /**
20
20
  * A block broker will contact a provider to retrieve a block
@@ -22,7 +22,7 @@ export interface ProviderOptions {
22
22
  export interface BlockBrokerConnectProgressEvent {
23
23
  broker: string;
24
24
  type: 'connect';
25
- provider: PeerId;
25
+ provider: CID;
26
26
  cid: CID;
27
27
  }
28
28
  /**
@@ -31,7 +31,7 @@ export interface BlockBrokerConnectProgressEvent {
31
31
  export interface BlockBrokerConnectedProgressEvent {
32
32
  broker: string;
33
33
  type: 'connected';
34
- provider: PeerId;
34
+ provider: CID;
35
35
  address: Multiaddr;
36
36
  cid: CID;
37
37
  }
@@ -41,7 +41,7 @@ export interface BlockBrokerConnectedProgressEvent {
41
41
  export interface BlockBrokerRequestBlockProgressEvent {
42
42
  broker: string;
43
43
  type: 'request-block';
44
- provider: PeerId;
44
+ provider: CID;
45
45
  cid: CID;
46
46
  }
47
47
  /**
@@ -50,7 +50,7 @@ export interface BlockBrokerRequestBlockProgressEvent {
50
50
  export interface BlockBrokerReceiveBlockProgressEvent {
51
51
  broker: string;
52
52
  type: 'receive-block';
53
- provider: PeerId;
53
+ provider: CID;
54
54
  cid: CID;
55
55
  }
56
56
  export type BlockBrokerGetBlockProgressEvents = ProgressEvent<'helia:block-broker:connect', BlockBrokerConnectProgressEvent> | ProgressEvent<'helia:block-broker:connected', BlockBrokerConnectedProgressEvent> | ProgressEvent<'helia:block-broker:request-block', BlockBrokerRequestBlockProgressEvent> | ProgressEvent<'helia:block-broker:receive-block', BlockBrokerReceiveBlockProgressEvent>;
@@ -98,7 +98,7 @@ export interface SessionBlockstore extends Blockstore<ProgressOptions<HasBlockPr
98
98
  * Adds a new peer to the session if they are supported and are either
99
99
  * not already in the session and have not been evicted previously.
100
100
  */
101
- addPeer(peer: PeerId | Multiaddr | Multiaddr[], options?: AbortOptions): Promise<void>;
101
+ addPeer(peer: CID | Multiaddr | Multiaddr[], options?: AbortOptions): Promise<void>;
102
102
  }
103
103
  export interface BlockRetrievalOptions<ProgressEvents extends ProgressEvent<any, any> = ProgressEvent<any, any>> extends AbortOptions, ProgressOptions<ProgressEvents>, ProviderOptions {
104
104
  /**
@@ -168,7 +168,7 @@ export interface SessionBlockBroker<RetrieveProgressEvents extends ProgressEvent
168
168
  * Adds a new peer to the session if they are supported and are either
169
169
  * not already in the session and have not been evicted previously.
170
170
  */
171
- addPeer(peer: PeerId | Multiaddr | Multiaddr[], options?: AbortOptions): Promise<void>;
171
+ addPeer(peer: CID | Multiaddr | Multiaddr[], options?: AbortOptions): Promise<void>;
172
172
  }
173
173
  export declare const DEFAULT_SESSION_MIN_PROVIDERS = 1;
174
174
  export declare const DEFAULT_SESSION_MAX_PROVIDERS = 5;
@@ -1 +1 @@
1
- {"version":3,"file":"blocks.d.ts","sourceRoot":"","sources":["../../src/blocks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kCAAkC,EAAE,MAAM,cAAc,CAAA;AACtE,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MA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,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,aAAa,CAAC,GAAG,EAAE,GAAG,CAAC,CAAE,SAAQ,WAAW,CAAC,sBAAsB,EAAE,sBAAsB,CAAC;IACzQ;;;OAGG;IACH,OAAO,CAAE,IAAI,EAAE,GAAG,GAAG,SAAS,GAAG,SAAS,EAAE,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CACrF;AAED,eAAO,MAAM,6BAA6B,IAAI,CAAA;AAC9C,eAAO,MAAM,6BAA6B,IAAI,CAAA;AAC9C,eAAO,MAAM,4BAA4B,MAAM,CAAA"}
@@ -0,0 +1,28 @@
1
+ import type { CodecLoader } from './index.js';
2
+ import type { AbortOptions } from '@libp2p/interface';
3
+ import type { Blockstore } from 'interface-blockstore';
4
+ import type { BlockView, CID, Version } from 'multiformats';
5
+ export interface GraphWalkerComponents {
6
+ blockstore: Blockstore;
7
+ getCodec: CodecLoader;
8
+ }
9
+ export interface GraphWalkerInit {
10
+ }
11
+ export interface GraphNode<T = unknown, C extends number = number, A extends number = number, V extends Version = 0 | 1> {
12
+ block: BlockView<T, C, A, V>;
13
+ depth: number;
14
+ path: CID[];
15
+ }
16
+ export interface WalkOptions<T> extends AbortOptions {
17
+ /**
18
+ * Stop traversal once `node.depth` reaches this value. The root is
19
+ * depth 0. Default: Infinity (walk the entire DAG).
20
+ */
21
+ depth?: number;
22
+ includeChild?(child: CID, parent: BlockView<T, number, number, 0 | 1>): boolean;
23
+ }
24
+ export interface GraphWalker {
25
+ walk<T = any>(cid: CID, options?: WalkOptions<T>): AsyncGenerator<GraphNode<T>>;
26
+ }
27
+ export type GraphWalkerFactory = (components: GraphWalkerComponents) => GraphWalker;
28
+ //# sourceMappingURL=graph-walker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph-walker.d.ts","sourceRoot":"","sources":["../../src/graph-walker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAA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ceMappingURL=graph-walker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph-walker.js","sourceRoot":"","sources":["../../src/graph-walker.ts"],"names":[],"mappings":""}
@@ -13,14 +13,16 @@
13
13
  * }
14
14
  * ```
15
15
  */
16
- import type { Blocks } from './blocks.ts';
16
+ import type { BlockBroker, Blocks } from './blocks.ts';
17
17
  import type { Pins } from './pins.ts';
18
- import type { Routing } from './routing.ts';
18
+ import type { Router, Routing } from './routing.ts';
19
19
  import type { CryptoLoader, Keychain } from '@ipshipyard/keychain';
20
- import type { ComponentLogger, Libp2p, Metrics, TypedEventEmitter } from '@libp2p/interface';
20
+ import type { Metrics } from '@libp2p/interface';
21
21
  import type { DNS } from '@multiformats/dns';
22
22
  import type { AbortOptions } from 'abort-error';
23
+ import type { ComponentLogger } from 'birnam';
23
24
  import type { Datastore } from 'interface-datastore';
25
+ import type { TypedEventEmitter } from 'main-event';
24
26
  import type { BlockCodec, MultihashHasher } from 'multiformats';
25
27
  import type { CID } from 'multiformats/cid';
26
28
  import type { ProgressEvent, ProgressOptions } from 'progress-events';
@@ -33,14 +35,22 @@ export interface HasherLoader {
33
35
  export type { CryptoLoader, Keychain } from '@ipshipyard/keychain';
34
36
  export type { Crypto, PrivateKey, PublicKey } from '@ipshipyard/crypto';
35
37
  export { isPrivateKey, isPublicKey } from '@ipshipyard/crypto';
38
+ export interface NodeInfo {
39
+ name: string;
40
+ version: string;
41
+ }
42
+ export interface HeliaMixin<Start extends Helia = Helia, Stop = Start> {
43
+ start?(helia: Start): Promise<void> | void;
44
+ stop?(helia: Stop): Promise<void> | void;
45
+ }
36
46
  /**
37
47
  * The API presented by a Helia node
38
48
  */
39
- export interface Helia<T extends Libp2p = Libp2p> {
49
+ export interface Helia {
40
50
  /**
41
- * The libp2p instance
51
+ * Runtime information about the node
42
52
  */
43
- libp2p: T;
53
+ info: NodeInfo;
44
54
  /**
45
55
  * Where the blocks are stored
46
56
  */
@@ -52,7 +62,7 @@ export interface Helia<T extends Libp2p = Libp2p> {
52
62
  /**
53
63
  * Event emitter for Helia start and stop events
54
64
  */
55
- events: TypedEventEmitter<HeliaEvents<T>>;
65
+ events: TypedEventEmitter<HeliaEvents<this>>;
56
66
  /**
57
67
  * Secure storage for private keys
58
68
  */
@@ -80,14 +90,18 @@ export interface Helia<T extends Libp2p = Libp2p> {
80
90
  * usage.
81
91
  */
82
92
  metrics?: Metrics;
93
+ /**
94
+ * The current status of the Helia node
95
+ */
96
+ status: 'starting' | 'started' | 'stopping' | 'stopped';
83
97
  /**
84
98
  * Starts the Helia node
85
99
  */
86
- start(): Promise<void>;
100
+ start(options?: AbortOptions): Promise<this>;
87
101
  /**
88
102
  * Stops the Helia node
89
103
  */
90
- stop(): Promise<void>;
104
+ stop(options?: AbortOptions): Promise<this>;
91
105
  /**
92
106
  * Remove any unpinned blocks from the blockstore
93
107
  */
@@ -107,11 +121,31 @@ export interface Helia<T extends Libp2p = Libp2p> {
107
121
  * Cryptography implementations securely sign and verify data
108
122
  */
109
123
  getCrypto: CryptoLoader;
124
+ /**
125
+ * Returns `true` if a router with the passed name has been configured
126
+ */
127
+ hasRouter(name: string): boolean;
128
+ /**
129
+ * Add a router
130
+ */
131
+ addRouter(router: Router): void;
132
+ /**
133
+ * Returns `true` if a block broker with the passed name has been configured
134
+ */
135
+ hasBlockBroker(name: string): boolean;
136
+ /**
137
+ * Add a block broker
138
+ */
139
+ addBlockBroker(blockBroker: BlockBroker): void;
140
+ /**
141
+ * Add a mixin to extend runtime functionality
142
+ */
143
+ addMixin<T extends Helia = Helia & Record<string, any>>(mixin: HeliaMixin<T>): void;
110
144
  }
111
145
  export type GcEvents = ProgressEvent<'helia:gc:deleted', CID> | ProgressEvent<'helia:gc:error', Error>;
112
146
  export interface GCOptions extends AbortOptions, ProgressOptions<GcEvents> {
113
147
  }
114
- export interface HeliaEvents<T extends Libp2p = Libp2p> {
148
+ export interface HeliaEvents<H extends Helia = Helia> {
115
149
  /**
116
150
  * This event notifies listeners that the node has started
117
151
  *
@@ -121,7 +155,7 @@ export interface HeliaEvents<T extends Libp2p = Libp2p> {
121
155
  * })
122
156
  * ```
123
157
  */
124
- start: CustomEvent<Helia<T>>;
158
+ start: CustomEvent<H>;
125
159
  /**
126
160
  * This event notifies listeners that the node has stopped
127
161
  *
@@ -131,10 +165,11 @@ export interface HeliaEvents<T extends Libp2p = Libp2p> {
131
165
  * })
132
166
  * ```
133
167
  */
134
- stop: CustomEvent<Helia<T>>;
168
+ stop: CustomEvent<H>;
135
169
  }
136
170
  export * from './blocks.ts';
137
171
  export * from './errors.ts';
172
+ export * from './graph-walker.ts';
138
173
  export * from './pins.ts';
139
174
  export * from './routing.ts';
140
175
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACrC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAClE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAC5F,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAA;AAC5C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC/D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,M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IAAI,EAAE,MAAM,GAAG,OAAO,CAAA;IAEjC;;OAEG;IACH,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;IAE/B;;OAEG;IACH,cAAc,CAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAA;IAEtC;;OAEG;IACH,cAAc,CAAC,WAAW,EAAE,WAAW,GAAG,IAAI,CAAA;IAE9C;;OAEG;IACH,QAAQ,CAAC,CAAC,SAAS,KAAK,GAAG,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI,CAAA;CACpF;AAED,MAAM,MAAM,QAAQ,GAClB,aAAa,CAAC,kBAAkB,EAAE,GAAG,CAAC,GACtC,aAAa,CAAC,gBAAgB,EAAE,KAAK,CAAC,CAAA;AAExC,MAAM,WAAW,SAAU,SAAQ,YAAY,EAAE,eAAe,CAAC,QAAQ,CAAC;CAEzE;AAED,MAAM,WAAW,WAAW,CAAC,CAAC,SAAS,KAAK,GAAG,KAAK;IAClD;;;;;;;;OAQG;IACH,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,CAAA;IAErB;;;;;;;;OAQG;IACH,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,CAAA;CACrB;AAED,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,mBAAmB,CAAA;AACjC,cAAc,WAAW,CAAA;AACzB,cAAc,cAAc,CAAA"}
package/dist/src/index.js CHANGED
@@ -16,6 +16,7 @@
16
16
  export { isPrivateKey, isPublicKey } from '@ipshipyard/crypto';
17
17
  export * from "./blocks.js";
18
18
  export * from "./errors.js";
19
+ export * from "./graph-walker.js";
19
20
  export * from "./pins.js";
20
21
  export * from "./routing.js";
21
22
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAwBH,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AA6H9D,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,WAAW,CAAA;AACzB,cAAc,cAAc,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AA0BH,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAqK9D,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,mBAAmB,CAAA;AACjC,cAAc,WAAW,CAAA;AACzB,cAAc,cAAc,CAAA"}
@@ -1,5 +1,6 @@
1
1
  import type { GetBlockProgressEvents } from './blocks.ts';
2
- import type { AbortOptions } from '@libp2p/interface';
2
+ import type { GraphWalkerFactory } from './graph-walker.ts';
3
+ import type { AbortOptions } from 'abort-error';
3
4
  import type { CID } from 'multiformats/cid';
4
5
  import type { ProgressEvent, ProgressOptions } from 'progress-events';
5
6
  export type PinType = 'recursive' | 'direct' | 'indirect';
@@ -14,12 +15,20 @@ export interface AddOptions extends AbortOptions, ProgressOptions<AddPinEvents |
14
15
  * How deeply to pin the DAG, defaults to Infinity
15
16
  */
16
17
  depth?: number;
18
+ /**
19
+ * Walker factory used to traverse the DAG. Default: `depthFirstWalker()`.
20
+ */
21
+ walker?: GraphWalkerFactory;
17
22
  /**
18
23
  * Optional user-defined metadata to store with the pin
19
24
  */
20
25
  metadata?: Record<string, string | number | boolean>;
21
26
  }
22
27
  export interface RmOptions extends AbortOptions {
28
+ /**
29
+ * Walker factory used to traverse the DAG. Default: `depthFirstWalker()`.
30
+ */
31
+ walker?: GraphWalkerFactory;
23
32
  }
24
33
  export interface LsOptions extends AbortOptions {
25
34
  cid?: CID;
@@ -1 +1 @@
1
- {"version":3,"file":"pins.d.ts","sourceRoot":"","sources":["../../src/pins.ts"],"names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,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,GAAG,SAAS,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAC9H"}
@@ -1,4 +1,5 @@
1
- import type { AbortOptions, PeerId, PeerInfo, TraceOptions } from '@libp2p/interface';
1
+ import type { Multiaddr } from '@multiformats/multiaddr';
2
+ import type { AbortOptions } from 'abort-error';
2
3
  import type { CID } from 'multiformats/cid';
3
4
  import type { ProgressEvent, ProgressOptions } from 'progress-events';
4
5
  /**
@@ -7,7 +8,7 @@ import type { ProgressEvent, ProgressOptions } from 'progress-events';
7
8
  * local cache that may be used in preference over network calls, for example
8
9
  * when a record has a TTL.
9
10
  */
10
- export interface RoutingOptions<Event extends ProgressEvent = any> extends AbortOptions, ProgressOptions<Event>, TraceOptions {
11
+ export interface RoutingOptions<Event extends ProgressEvent = any> extends AbortOptions, ProgressOptions<Event> {
11
12
  /**
12
13
  * Pass `false` to not use the network
13
14
  *
@@ -26,11 +27,36 @@ export interface RoutingOptions<Event extends ProgressEvent = any> extends Abort
26
27
  * @default true
27
28
  */
28
29
  validate?: boolean;
30
+ /**
31
+ * Where tracing is used, this value carries tracing context
32
+ */
33
+ trace?: any;
34
+ }
35
+ /**
36
+ * A Peer is another node on the network
37
+ */
38
+ export interface Peer {
39
+ /**
40
+ * The identifier of the remote peer
41
+ */
42
+ id: CID;
43
+ /**
44
+ * The multiaddrs a peer is listening on
45
+ */
46
+ multiaddrs: Multiaddr[];
29
47
  }
30
48
  /**
31
49
  * A provider can supply the content for a CID
32
50
  */
33
- export interface Provider extends PeerInfo {
51
+ export interface Provider {
52
+ /**
53
+ * The identifier of the remote peer, a CID
54
+ */
55
+ id: CID;
56
+ /**
57
+ * The multiaddrs a peer is listening on
58
+ */
59
+ multiaddrs: Multiaddr[];
34
60
  /**
35
61
  * If present these are the methods that the peer can supply the content via.
36
62
  *
@@ -61,14 +87,14 @@ export interface RoutingFindProvidersEndEvent {
61
87
  export interface RoutingFindProvidersHttpGatewayProvider {
62
88
  routing: 'http-gateway-router';
63
89
  cid: CID;
64
- provider: PeerInfo & {
90
+ provider: Peer & {
65
91
  protocols: ['transport-ipfs-gateway-http'];
66
92
  };
67
93
  }
68
94
  export interface RoutingFindProvidersDelegatedHttpRoutingProvider {
69
95
  routing: 'delegated-http-router';
70
96
  cid: CID;
71
- provider: PeerInfo & {
97
+ provider: Peer & {
72
98
  routing: 'delegated-http-routing';
73
99
  protocols: string[];
74
100
  };
@@ -76,7 +102,7 @@ export interface RoutingFindProvidersDelegatedHttpRoutingProvider {
76
102
  export interface RoutingFindProvidersLibp2pProvider {
77
103
  routing: 'libp2p-router';
78
104
  cid: CID;
79
- provider: PeerInfo;
105
+ provider: Peer;
80
106
  }
81
107
  export type RoutingFindProvidersProviderEvent = RoutingFindProvidersHttpGatewayProvider | RoutingFindProvidersDelegatedHttpRoutingProvider | RoutingFindProvidersLibp2pProvider;
82
108
  export type RoutingFindProvidersProgressEvents = ProgressEvent<'helia:routing:find-providers:start', RoutingFindProvidersStartEvent> | ProgressEvent<'helia:routing:find-providers:provider', RoutingFindProvidersProviderEvent> | ProgressEvent<'helia:routing:find-providers:end', RoutingFindProvidersEndEvent> | RoutingFindPeerProgressEvents;
@@ -120,11 +146,11 @@ export interface RoutingGetEndEvent {
120
146
  export type RoutingGetProgressEvents = ProgressEvent<'helia:routing:get:start', RoutingGetStartEvent> | ProgressEvent<'helia:routing:get:end', RoutingGetEndEvent>;
121
147
  export interface RoutingFindPeerStartEvent {
122
148
  routing: string;
123
- peerId: PeerId;
149
+ peerId: CID;
124
150
  }
125
151
  export interface RoutingFindPeerEndEvent {
126
152
  routing: string;
127
- peerId: PeerId;
153
+ peerId: CID;
128
154
  }
129
155
  export type RoutingFindPeerProgressEvents = ProgressEvent<'helia:routing:find-peer:start', RoutingFindPeerStartEvent> | ProgressEvent<'helia:routing:find-peer:end', RoutingFindPeerEndEvent>;
130
156
  export interface RoutingGetClosestPeersStartEvent {
@@ -136,7 +162,7 @@ export interface RoutingGetClosestPeersEndEvent {
136
162
  key: Uint8Array;
137
163
  }
138
164
  export type RoutingGetClosestPeersProgressEvents = ProgressEvent<'helia:routing:get-closest-peers:start', RoutingGetClosestPeersStartEvent> | ProgressEvent<'helia:routing:get-closest-peers:end', RoutingGetClosestPeersEndEvent>;
139
- export interface Routing {
165
+ export interface Router {
140
166
  /**
141
167
  * The name of this routing implementation
142
168
  */
@@ -149,10 +175,12 @@ export interface Routing {
149
175
  *
150
176
  * ```js
151
177
  * // ...
152
- * await contentRouting.provide(cid)
178
+ * await contentRouting.provide(cid, {
179
+ * signal: AbortSignal.timeout(5_000)
180
+ * })
153
181
  * ```
154
182
  */
155
- provide(cid: CID, options?: RoutingOptions<RoutingProvideProgressEvents>): Promise<void>;
183
+ provide?(cid: CID, options?: RoutingOptions<RoutingProvideProgressEvents>): Promise<void>;
156
184
  /**
157
185
  * Helia will periodically re-provide every previously provided CID. Use this
158
186
  * method to no longer re-provide the passed CID.
@@ -161,10 +189,12 @@ export interface Routing {
161
189
  *
162
190
  * ```js
163
191
  * // ...
164
- * await contentRouting.cancelReprovide(cid)
192
+ * await contentRouting.cancelReprovide(cid, {
193
+ * signal: AbortSignal.timeout(5_000)
194
+ * })
165
195
  * ```
166
196
  */
167
- cancelReprovide(key: CID, options?: AbortOptions): Promise<void>;
197
+ cancelReprovide?(key: CID, options?: AbortOptions): Promise<void>;
168
198
  /**
169
199
  * Find the providers of the passed CID.
170
200
  *
@@ -172,12 +202,14 @@ export interface Routing {
172
202
  *
173
203
  * ```js
174
204
  * // Iterate over the providers found for the given cid
175
- * for await (const provider of contentRouting.findProviders(cid)) {
205
+ * for await (const provider of contentRouting.findProviders(cid, {
206
+ * signal: AbortSignal.timeout(5_000)
207
+ * })) {
176
208
  * console.log(provider.id, provider.multiaddrs)
177
209
  * }
178
210
  * ```
179
211
  */
180
- findProviders(cid: CID, options?: RoutingOptions<RoutingFindProvidersProgressEvents>): AsyncIterable<Provider>;
212
+ findProviders?(cid: CID, options?: RoutingOptions<RoutingFindProvidersProgressEvents>): AsyncIterable<Provider>;
181
213
  /**
182
214
  * Puts a value corresponding to the passed key in a way that can later be
183
215
  * retrieved by another network peer using the get method.
@@ -186,13 +218,15 @@ export interface Routing {
186
218
  *
187
219
  * ```js
188
220
  * // ...
189
- * const key = '/key'
221
+ * const key = uint8ArrayFromString('/key')
190
222
  * const value = uint8ArrayFromString('oh hello there')
191
223
  *
192
- * await contentRouting.put(key, value)
224
+ * await contentRouting.put(key, value, {
225
+ * signal: AbortSignal.timeout(5_000)
226
+ * })
193
227
  * ```
194
228
  */
195
- put(key: Uint8Array, value: Uint8Array, options?: RoutingOptions<RoutingPutProgressEvents>): Promise<void>;
229
+ put?(key: Uint8Array, value: Uint8Array, options?: RoutingOptions<RoutingPutProgressEvents>): Promise<void>;
196
230
  /**
197
231
  * Retrieves a value from the network corresponding to the passed key.
198
232
  *
@@ -201,11 +235,13 @@ export interface Routing {
201
235
  * ```js
202
236
  * // ...
203
237
  *
204
- * const key = '/key'
205
- * const value = await contentRouting.get(key)
238
+ * const key = uint8ArrayFromString('/key')
239
+ * const value = await contentRouting.get(key, {
240
+ * signal: AbortSignal.timeout(5_000)
241
+ * })
206
242
  * ```
207
243
  */
208
- get(key: Uint8Array, options?: RoutingOptions<RoutingGetProgressEvents>): Promise<Uint8Array>;
244
+ get?(key: Uint8Array, options?: RoutingOptions<RoutingGetProgressEvents>): Promise<Uint8Array>;
209
245
  /**
210
246
  * Searches the network for peer info corresponding to the passed peer id.
211
247
  *
@@ -213,10 +249,12 @@ export interface Routing {
213
249
  *
214
250
  * ```js
215
251
  * // ...
216
- * const peer = await peerRouting.findPeer(peerId, options)
252
+ * const peer = await peerRouting.findPeer(peerId, {
253
+ * signal: AbortSignal.timeout(5_000)
254
+ * })
217
255
  * ```
218
256
  */
219
- findPeer(peerId: PeerId, options?: RoutingOptions<RoutingFindPeerProgressEvents>): Promise<PeerInfo>;
257
+ findPeer?(peer: CID, options?: RoutingOptions<RoutingFindPeerProgressEvents>): Promise<Peer>;
220
258
  /**
221
259
  * Search the network for peers that are closer to the passed key. Peer
222
260
  * info should be yielded in ever-increasing closeness to the key.
@@ -225,11 +263,14 @@ export interface Routing {
225
263
  *
226
264
  * ```js
227
265
  * // Iterate over the closest peers found for the given key
228
- * for await (const peer of peerRouting.getClosestPeers(key)) {
266
+ * for await (const peer of peerRouting.getClosestPeers(key, {
267
+ * signal: AbortSignal.timeout(5_000)
268
+ * })) {
229
269
  * console.log(peer.id, peer.multiaddrs)
230
270
  * }
231
271
  * ```
232
272
  */
233
- getClosestPeers(key: Uint8Array, options?: RoutingOptions<RoutingGetClosestPeersProgressEvents>): AsyncIterable<PeerInfo>;
273
+ getClosestPeers?(key: Uint8Array, options?: RoutingOptions<RoutingGetClosestPeersProgressEvents>): AsyncIterable<Peer>;
234
274
  }
275
+ export type Routing = Required<Omit<Router, 'name'>>;
235
276
  //# sourceMappingURL=routing.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"routing.d.ts","sourceRoot":"","sources":["../../src/routing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACrF,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAErE;;;;;GAKG;AACH,MAAM,WAAW,cAAc,CAAC,KAAK,SAAS,aAAa,GAAG,GAAG,CAAE,SAAQ,YAAY,EAAE,eAAe,CAAC,KAAK,CAAC,EAAE,YAAY;IAC3H;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;IAEpB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAElB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AAC,CAAA;IAE/G;;;;;;;;;;;;;;;OAeG;IACH,GAAG,CAAC,CAAC,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,cAAc,CAAC,wBAAwB,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAE3G;;;;;;;;;;;;;OAaG;IACH,GAAG,CAAC,CAAC,GAAG,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,cAAc,CAAC,wBAAwB,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;IAE9F;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,cAAc,CAAC,6BAA6B,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAE5F;;;;;;;;;;;;;;OAcG;IACH,eAAe,CAAC,CAAC,GAAG,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,cAAc,CAAC,oCAAoC,CAAC,GAAG,aAAa,CAAC,IAAI,CAAC,CAAA;CACvH;AAED,MAAM,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@helia/interface",
3
- "version": "6.2.1-73a28eda",
3
+ "version": "6.2.1-9114743f",
4
4
  "description": "The Helia API",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/ipfs/helia/tree/main/packages/interface#readme",
@@ -74,17 +74,19 @@
74
74
  "dependencies": {
75
75
  "@ipshipyard/crypto": "^1.1.0",
76
76
  "@ipshipyard/keychain": "^1.0.2",
77
- "@libp2p/interface": "^3.2.0",
77
+ "@libp2p/interface": "^3.2.3",
78
78
  "@multiformats/dns": "^1.0.13",
79
- "@multiformats/multiaddr": "^13.0.1",
79
+ "@multiformats/multiaddr": "^13.0.3",
80
80
  "abort-error": "^1.0.2",
81
+ "birnam": "^1.0.0",
81
82
  "interface-blockstore": "^7.0.1",
82
83
  "interface-datastore": "^10.0.1",
84
+ "main-event": "^1.0.4",
83
85
  "multiformats": "^14.0.0",
84
86
  "progress-events": "^1.1.0"
85
87
  },
86
88
  "devDependencies": {
87
- "aegir": "^48.0.4"
89
+ "aegir": "^48.0.11"
88
90
  },
89
91
  "sideEffects": false
90
92
  }
package/src/blocks.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { RoutingFindProvidersProgressEvents } from './routing.ts'
2
- import type { PeerId, AbortOptions } from '@libp2p/interface'
3
2
  import type { Multiaddr } from '@multiformats/multiaddr'
3
+ import type { AbortOptions } from 'abort-error'
4
4
  import type { Blockstore } from 'interface-blockstore'
5
5
  import type { CID } from 'multiformats/cid'
6
6
  import type { ProgressEvent, ProgressOptions } from 'progress-events'
@@ -16,7 +16,7 @@ export interface ProviderOptions {
16
16
  * child blocks, a `findProviders` routing query will be run to find peers
17
17
  * that can supply the blocks.
18
18
  */
19
- providers?: Array<PeerId | Multiaddr | Multiaddr[]>
19
+ providers?: Array<CID | Multiaddr | Multiaddr[]>
20
20
  }
21
21
 
22
22
  /**
@@ -25,7 +25,7 @@ export interface ProviderOptions {
25
25
  export interface BlockBrokerConnectProgressEvent {
26
26
  broker: string
27
27
  type: 'connect'
28
- provider: PeerId
28
+ provider: CID
29
29
  cid: CID
30
30
  }
31
31
 
@@ -35,7 +35,7 @@ export interface BlockBrokerConnectProgressEvent {
35
35
  export interface BlockBrokerConnectedProgressEvent {
36
36
  broker: string
37
37
  type: 'connected'
38
- provider: PeerId
38
+ provider: CID
39
39
  address: Multiaddr
40
40
  cid: CID
41
41
  }
@@ -46,7 +46,7 @@ export interface BlockBrokerConnectedProgressEvent {
46
46
  export interface BlockBrokerRequestBlockProgressEvent {
47
47
  broker: string
48
48
  type: 'request-block'
49
- provider: PeerId
49
+ provider: CID
50
50
  cid: CID
51
51
  }
52
52
 
@@ -56,7 +56,7 @@ export interface BlockBrokerRequestBlockProgressEvent {
56
56
  export interface BlockBrokerReceiveBlockProgressEvent {
57
57
  broker: string
58
58
  type: 'receive-block'
59
- provider: PeerId
59
+ provider: CID
60
60
  cid: CID
61
61
  }
62
62
 
@@ -150,7 +150,7 @@ ProgressOptions<DeleteBlockProgressEvents>, ProgressOptions<DeleteManyBlocksProg
150
150
  * Adds a new peer to the session if they are supported and are either
151
151
  * not already in the session and have not been evicted previously.
152
152
  */
153
- addPeer (peer: PeerId | Multiaddr | Multiaddr[], options?: AbortOptions): Promise<void>
153
+ addPeer (peer: CID | Multiaddr | Multiaddr[], options?: AbortOptions): Promise<void>
154
154
  }
155
155
 
156
156
  export interface BlockRetrievalOptions <ProgressEvents extends ProgressEvent<any, any> = ProgressEvent<any, any>> extends AbortOptions, ProgressOptions<ProgressEvents>, ProviderOptions {
@@ -232,7 +232,7 @@ export interface SessionBlockBroker<RetrieveProgressEvents extends ProgressEvent
232
232
  * Adds a new peer to the session if they are supported and are either
233
233
  * not already in the session and have not been evicted previously.
234
234
  */
235
- addPeer (peer: PeerId | Multiaddr | Multiaddr[], options?: AbortOptions): Promise<void>
235
+ addPeer (peer: CID | Multiaddr | Multiaddr[], options?: AbortOptions): Promise<void>
236
236
  }
237
237
 
238
238
  export const DEFAULT_SESSION_MIN_PROVIDERS = 1
@@ -0,0 +1,38 @@
1
+ import type { CodecLoader } from './index.js'
2
+ import type { AbortOptions } from '@libp2p/interface'
3
+ import type { Blockstore } from 'interface-blockstore'
4
+ import type { BlockView, CID, Version } from 'multiformats'
5
+
6
+ export interface GraphWalkerComponents {
7
+ blockstore: Blockstore
8
+ getCodec: CodecLoader
9
+ }
10
+
11
+ export interface GraphWalkerInit {}
12
+
13
+ export interface GraphNode<
14
+ T = unknown,
15
+ C extends number = number,
16
+ A extends number = number,
17
+ V extends Version = 0 | 1
18
+ > {
19
+ block: BlockView<T, C, A, V>
20
+ depth: number
21
+ path: CID[]
22
+ }
23
+
24
+ export interface WalkOptions<T> extends AbortOptions {
25
+ /**
26
+ * Stop traversal once `node.depth` reaches this value. The root is
27
+ * depth 0. Default: Infinity (walk the entire DAG).
28
+ */
29
+ depth?: number
30
+
31
+ includeChild?(child: CID, parent: BlockView<T, number, number, 0 | 1>): boolean
32
+ }
33
+
34
+ export interface GraphWalker {
35
+ walk<T = any>(cid: CID, options?: WalkOptions<T>): AsyncGenerator<GraphNode<T>>
36
+ }
37
+
38
+ export type GraphWalkerFactory = (components: GraphWalkerComponents) => GraphWalker
package/src/index.ts CHANGED
@@ -14,14 +14,16 @@
14
14
  * ```
15
15
  */
16
16
 
17
- import type { Blocks } from './blocks.ts'
17
+ import type { BlockBroker, Blocks } from './blocks.ts'
18
18
  import type { Pins } from './pins.ts'
19
- import type { Routing } from './routing.ts'
19
+ import type { Router, Routing } from './routing.ts'
20
20
  import type { CryptoLoader, Keychain } from '@ipshipyard/keychain'
21
- import type { ComponentLogger, Libp2p, Metrics, TypedEventEmitter } from '@libp2p/interface'
21
+ import type { Metrics } from '@libp2p/interface'
22
22
  import type { DNS } from '@multiformats/dns'
23
23
  import type { AbortOptions } from 'abort-error'
24
+ import type { ComponentLogger } from 'birnam'
24
25
  import type { Datastore } from 'interface-datastore'
26
+ import type { TypedEventEmitter } from 'main-event'
25
27
  import type { BlockCodec, MultihashHasher } from 'multiformats'
26
28
  import type { CID } from 'multiformats/cid'
27
29
  import type { ProgressEvent, ProgressOptions } from 'progress-events'
@@ -38,14 +40,24 @@ export type { CryptoLoader, Keychain } from '@ipshipyard/keychain'
38
40
  export type { Crypto, PrivateKey, PublicKey } from '@ipshipyard/crypto'
39
41
  export { isPrivateKey, isPublicKey } from '@ipshipyard/crypto'
40
42
 
43
+ export interface NodeInfo {
44
+ name: string
45
+ version: string
46
+ }
47
+
48
+ export interface HeliaMixin<Start extends Helia = Helia, Stop = Start> {
49
+ start?(helia: Start): Promise<void> | void
50
+ stop?(helia: Stop): Promise<void> | void
51
+ }
52
+
41
53
  /**
42
54
  * The API presented by a Helia node
43
55
  */
44
- export interface Helia<T extends Libp2p = Libp2p> {
56
+ export interface Helia {
45
57
  /**
46
- * The libp2p instance
58
+ * Runtime information about the node
47
59
  */
48
- libp2p: T
60
+ info: NodeInfo
49
61
 
50
62
  /**
51
63
  * Where the blocks are stored
@@ -60,7 +72,7 @@ export interface Helia<T extends Libp2p = Libp2p> {
60
72
  /**
61
73
  * Event emitter for Helia start and stop events
62
74
  */
63
- events: TypedEventEmitter<HeliaEvents<T>>
75
+ events: TypedEventEmitter<HeliaEvents<this>>
64
76
 
65
77
  /**
66
78
  * Secure storage for private keys
@@ -95,15 +107,20 @@ export interface Helia<T extends Libp2p = Libp2p> {
95
107
  */
96
108
  metrics?: Metrics
97
109
 
110
+ /**
111
+ * The current status of the Helia node
112
+ */
113
+ status: 'starting' | 'started' | 'stopping' | 'stopped'
114
+
98
115
  /**
99
116
  * Starts the Helia node
100
117
  */
101
- start(): Promise<void>
118
+ start(options?: AbortOptions): Promise<this>
102
119
 
103
120
  /**
104
121
  * Stops the Helia node
105
122
  */
106
- stop(): Promise<void>
123
+ stop(options?: AbortOptions): Promise<this>
107
124
 
108
125
  /**
109
126
  * Remove any unpinned blocks from the blockstore
@@ -127,6 +144,31 @@ export interface Helia<T extends Libp2p = Libp2p> {
127
144
  * Cryptography implementations securely sign and verify data
128
145
  */
129
146
  getCrypto: CryptoLoader
147
+
148
+ /**
149
+ * Returns `true` if a router with the passed name has been configured
150
+ */
151
+ hasRouter (name: string): boolean
152
+
153
+ /**
154
+ * Add a router
155
+ */
156
+ addRouter(router: Router): void
157
+
158
+ /**
159
+ * Returns `true` if a block broker with the passed name has been configured
160
+ */
161
+ hasBlockBroker (name: string): boolean
162
+
163
+ /**
164
+ * Add a block broker
165
+ */
166
+ addBlockBroker(blockBroker: BlockBroker): void
167
+
168
+ /**
169
+ * Add a mixin to extend runtime functionality
170
+ */
171
+ addMixin<T extends Helia = Helia & Record<string, any>>(mixin: HeliaMixin<T>): void
130
172
  }
131
173
 
132
174
  export type GcEvents =
@@ -137,7 +179,7 @@ export interface GCOptions extends AbortOptions, ProgressOptions<GcEvents> {
137
179
 
138
180
  }
139
181
 
140
- export interface HeliaEvents<T extends Libp2p = Libp2p> {
182
+ export interface HeliaEvents<H extends Helia = Helia> {
141
183
  /**
142
184
  * This event notifies listeners that the node has started
143
185
  *
@@ -147,7 +189,7 @@ export interface HeliaEvents<T extends Libp2p = Libp2p> {
147
189
  * })
148
190
  * ```
149
191
  */
150
- start: CustomEvent<Helia<T>>
192
+ start: CustomEvent<H>
151
193
 
152
194
  /**
153
195
  * This event notifies listeners that the node has stopped
@@ -158,10 +200,11 @@ export interface HeliaEvents<T extends Libp2p = Libp2p> {
158
200
  * })
159
201
  * ```
160
202
  */
161
- stop: CustomEvent<Helia<T>>
203
+ stop: CustomEvent<H>
162
204
  }
163
205
 
164
206
  export * from './blocks.ts'
165
207
  export * from './errors.ts'
208
+ export * from './graph-walker.ts'
166
209
  export * from './pins.ts'
167
210
  export * from './routing.ts'
package/src/pins.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { GetBlockProgressEvents } from './blocks.ts'
2
- import type { AbortOptions } from '@libp2p/interface'
2
+ import type { GraphWalkerFactory } from './graph-walker.ts'
3
+ import type { AbortOptions } from 'abort-error'
3
4
  import type { CID } from 'multiformats/cid'
4
5
  import type { ProgressEvent, ProgressOptions } from 'progress-events'
5
6
 
@@ -20,6 +21,11 @@ export interface AddOptions extends AbortOptions, ProgressOptions<AddPinEvents |
20
21
  */
21
22
  depth?: number
22
23
 
24
+ /**
25
+ * Walker factory used to traverse the DAG. Default: `depthFirstWalker()`.
26
+ */
27
+ walker?: GraphWalkerFactory
28
+
23
29
  /**
24
30
  * Optional user-defined metadata to store with the pin
25
31
  */
@@ -27,7 +33,10 @@ export interface AddOptions extends AbortOptions, ProgressOptions<AddPinEvents |
27
33
  }
28
34
 
29
35
  export interface RmOptions extends AbortOptions {
30
-
36
+ /**
37
+ * Walker factory used to traverse the DAG. Default: `depthFirstWalker()`.
38
+ */
39
+ walker?: GraphWalkerFactory
31
40
  }
32
41
 
33
42
  export interface LsOptions extends AbortOptions {
package/src/routing.ts CHANGED
@@ -1,4 +1,5 @@
1
- import type { AbortOptions, PeerId, PeerInfo, TraceOptions } from '@libp2p/interface'
1
+ import type { Multiaddr } from '@multiformats/multiaddr'
2
+ import type { AbortOptions } from 'abort-error'
2
3
  import type { CID } from 'multiformats/cid'
3
4
  import type { ProgressEvent, ProgressOptions } from 'progress-events'
4
5
 
@@ -8,7 +9,7 @@ import type { ProgressEvent, ProgressOptions } from 'progress-events'
8
9
  * local cache that may be used in preference over network calls, for example
9
10
  * when a record has a TTL.
10
11
  */
11
- export interface RoutingOptions<Event extends ProgressEvent = any> extends AbortOptions, ProgressOptions<Event>, TraceOptions {
12
+ export interface RoutingOptions<Event extends ProgressEvent = any> extends AbortOptions, ProgressOptions<Event> {
12
13
  /**
13
14
  * Pass `false` to not use the network
14
15
  *
@@ -29,12 +30,42 @@ export interface RoutingOptions<Event extends ProgressEvent = any> extends Abort
29
30
  * @default true
30
31
  */
31
32
  validate?: boolean
33
+
34
+ /**
35
+ * Where tracing is used, this value carries tracing context
36
+ */
37
+ trace?: any
38
+ }
39
+
40
+ /**
41
+ * A Peer is another node on the network
42
+ */
43
+ export interface Peer {
44
+ /**
45
+ * The identifier of the remote peer
46
+ */
47
+ id: CID
48
+
49
+ /**
50
+ * The multiaddrs a peer is listening on
51
+ */
52
+ multiaddrs: Multiaddr[]
32
53
  }
33
54
 
34
55
  /**
35
56
  * A provider can supply the content for a CID
36
57
  */
37
- export interface Provider extends PeerInfo {
58
+ export interface Provider {
59
+ /**
60
+ * The identifier of the remote peer, a CID
61
+ */
62
+ id: CID
63
+
64
+ /**
65
+ * The multiaddrs a peer is listening on
66
+ */
67
+ multiaddrs: Multiaddr[]
68
+
38
69
  /**
39
70
  * If present these are the methods that the peer can supply the content via.
40
71
  *
@@ -69,7 +100,7 @@ export interface RoutingFindProvidersEndEvent {
69
100
  export interface RoutingFindProvidersHttpGatewayProvider {
70
101
  routing: 'http-gateway-router'
71
102
  cid: CID
72
- provider: PeerInfo & {
103
+ provider: Peer & {
73
104
  protocols: ['transport-ipfs-gateway-http']
74
105
  }
75
106
  }
@@ -77,7 +108,7 @@ export interface RoutingFindProvidersHttpGatewayProvider {
77
108
  export interface RoutingFindProvidersDelegatedHttpRoutingProvider {
78
109
  routing: 'delegated-http-router'
79
110
  cid: CID
80
- provider: PeerInfo & {
111
+ provider: Peer & {
81
112
  routing: 'delegated-http-routing'
82
113
  protocols: string[]
83
114
  }
@@ -86,7 +117,7 @@ export interface RoutingFindProvidersDelegatedHttpRoutingProvider {
86
117
  export interface RoutingFindProvidersLibp2pProvider {
87
118
  routing: 'libp2p-router'
88
119
  cid: CID
89
- provider: PeerInfo
120
+ provider: Peer
90
121
  }
91
122
 
92
123
  export type RoutingFindProvidersProviderEvent = RoutingFindProvidersHttpGatewayProvider | RoutingFindProvidersDelegatedHttpRoutingProvider | RoutingFindProvidersLibp2pProvider
@@ -157,12 +188,12 @@ export type RoutingGetProgressEvents =
157
188
 
158
189
  export interface RoutingFindPeerStartEvent {
159
190
  routing: string
160
- peerId: PeerId
191
+ peerId: CID
161
192
  }
162
193
 
163
194
  export interface RoutingFindPeerEndEvent {
164
195
  routing: string
165
- peerId: PeerId
196
+ peerId: CID
166
197
  }
167
198
 
168
199
  export type RoutingFindPeerProgressEvents =
@@ -183,7 +214,7 @@ export type RoutingGetClosestPeersProgressEvents =
183
214
  ProgressEvent<'helia:routing:get-closest-peers:start', RoutingGetClosestPeersStartEvent> |
184
215
  ProgressEvent<'helia:routing:get-closest-peers:end', RoutingGetClosestPeersEndEvent>
185
216
 
186
- export interface Routing {
217
+ export interface Router {
187
218
  /**
188
219
  * The name of this routing implementation
189
220
  */
@@ -197,10 +228,12 @@ export interface Routing {
197
228
  *
198
229
  * ```js
199
230
  * // ...
200
- * await contentRouting.provide(cid)
231
+ * await contentRouting.provide(cid, {
232
+ * signal: AbortSignal.timeout(5_000)
233
+ * })
201
234
  * ```
202
235
  */
203
- provide(cid: CID, options?: RoutingOptions<RoutingProvideProgressEvents>): Promise<void>
236
+ provide?(cid: CID, options?: RoutingOptions<RoutingProvideProgressEvents>): Promise<void>
204
237
 
205
238
  /**
206
239
  * Helia will periodically re-provide every previously provided CID. Use this
@@ -210,10 +243,12 @@ export interface Routing {
210
243
  *
211
244
  * ```js
212
245
  * // ...
213
- * await contentRouting.cancelReprovide(cid)
246
+ * await contentRouting.cancelReprovide(cid, {
247
+ * signal: AbortSignal.timeout(5_000)
248
+ * })
214
249
  * ```
215
250
  */
216
- cancelReprovide(key: CID, options?: AbortOptions): Promise<void>
251
+ cancelReprovide?(key: CID, options?: AbortOptions): Promise<void>
217
252
 
218
253
  /**
219
254
  * Find the providers of the passed CID.
@@ -222,12 +257,14 @@ export interface Routing {
222
257
  *
223
258
  * ```js
224
259
  * // Iterate over the providers found for the given cid
225
- * for await (const provider of contentRouting.findProviders(cid)) {
260
+ * for await (const provider of contentRouting.findProviders(cid, {
261
+ * signal: AbortSignal.timeout(5_000)
262
+ * })) {
226
263
  * console.log(provider.id, provider.multiaddrs)
227
264
  * }
228
265
  * ```
229
266
  */
230
- findProviders(cid: CID, options?: RoutingOptions<RoutingFindProvidersProgressEvents>): AsyncIterable<Provider>
267
+ findProviders?(cid: CID, options?: RoutingOptions<RoutingFindProvidersProgressEvents>): AsyncIterable<Provider>
231
268
 
232
269
  /**
233
270
  * Puts a value corresponding to the passed key in a way that can later be
@@ -237,13 +274,15 @@ export interface Routing {
237
274
  *
238
275
  * ```js
239
276
  * // ...
240
- * const key = '/key'
277
+ * const key = uint8ArrayFromString('/key')
241
278
  * const value = uint8ArrayFromString('oh hello there')
242
279
  *
243
- * await contentRouting.put(key, value)
280
+ * await contentRouting.put(key, value, {
281
+ * signal: AbortSignal.timeout(5_000)
282
+ * })
244
283
  * ```
245
284
  */
246
- put(key: Uint8Array, value: Uint8Array, options?: RoutingOptions<RoutingPutProgressEvents>): Promise<void>
285
+ put?(key: Uint8Array, value: Uint8Array, options?: RoutingOptions<RoutingPutProgressEvents>): Promise<void>
247
286
 
248
287
  /**
249
288
  * Retrieves a value from the network corresponding to the passed key.
@@ -253,11 +292,13 @@ export interface Routing {
253
292
  * ```js
254
293
  * // ...
255
294
  *
256
- * const key = '/key'
257
- * const value = await contentRouting.get(key)
295
+ * const key = uint8ArrayFromString('/key')
296
+ * const value = await contentRouting.get(key, {
297
+ * signal: AbortSignal.timeout(5_000)
298
+ * })
258
299
  * ```
259
300
  */
260
- get(key: Uint8Array, options?: RoutingOptions<RoutingGetProgressEvents>): Promise<Uint8Array>
301
+ get?(key: Uint8Array, options?: RoutingOptions<RoutingGetProgressEvents>): Promise<Uint8Array>
261
302
 
262
303
  /**
263
304
  * Searches the network for peer info corresponding to the passed peer id.
@@ -266,10 +307,12 @@ export interface Routing {
266
307
  *
267
308
  * ```js
268
309
  * // ...
269
- * const peer = await peerRouting.findPeer(peerId, options)
310
+ * const peer = await peerRouting.findPeer(peerId, {
311
+ * signal: AbortSignal.timeout(5_000)
312
+ * })
270
313
  * ```
271
314
  */
272
- findPeer(peerId: PeerId, options?: RoutingOptions<RoutingFindPeerProgressEvents>): Promise<PeerInfo>
315
+ findPeer?(peer: CID, options?: RoutingOptions<RoutingFindPeerProgressEvents>): Promise<Peer>
273
316
 
274
317
  /**
275
318
  * Search the network for peers that are closer to the passed key. Peer
@@ -279,10 +322,14 @@ export interface Routing {
279
322
  *
280
323
  * ```js
281
324
  * // Iterate over the closest peers found for the given key
282
- * for await (const peer of peerRouting.getClosestPeers(key)) {
325
+ * for await (const peer of peerRouting.getClosestPeers(key, {
326
+ * signal: AbortSignal.timeout(5_000)
327
+ * })) {
283
328
  * console.log(peer.id, peer.multiaddrs)
284
329
  * }
285
330
  * ```
286
331
  */
287
- getClosestPeers(key: Uint8Array, options?: RoutingOptions<RoutingGetClosestPeersProgressEvents>): AsyncIterable<PeerInfo>
332
+ getClosestPeers?(key: Uint8Array, options?: RoutingOptions<RoutingGetClosestPeersProgressEvents>): AsyncIterable<Peer>
288
333
  }
334
+
335
+ export type Routing = Required<Omit<Router, 'name'>>