diff --git a/vendor/@hyperswarm/secret-stream/index.d.ts b/vendor/@hyperswarm/secret-stream/index.d.ts index a6a853b..283542c 100644 --- a/vendor/@hyperswarm/secret-stream/index.d.ts +++ b/vendor/@hyperswarm/secret-stream/index.d.ts @@ -1,33 +1,35 @@ import { Duplex as NodeDuplex } from 'stream' import { Duplex, DuplexEvents } from 'streamx' -interface KeyPair { - publicKey: Buffer - secretKey: Buffer -} - -interface Opts { - autostart?: boolean - // TODO: Use https://github.com/chm-diederichs/noise-handshake/blob/main/noise.js for specific patterns - pattern?: string - remotePublicKey?: Buffer - keyPair?: KeyPair - handshake?: { - tx: Buffer - rx: Buffer - hash: Buffer +declare namespace NoiseSecretStream { + interface KeyPair { publicKey: Buffer - remotePublicKey: Buffer + secretKey: Buffer } -} -type NoiseStreamEvents = { - connect: () => void - handshake: () => void + interface Opts { + autostart?: boolean + // TODO: Use https://github.com/chm-diederichs/noise-handshake/blob/main/noise.js for specific patterns + pattern?: string + remotePublicKey?: Buffer + keyPair?: KeyPair + handshake?: { + tx: Buffer + rx: Buffer + hash: Buffer + publicKey: Buffer + remotePublicKey: Buffer + } + } + + type NoiseStreamEvents = { + connect: () => void + handshake: () => void + } } declare class NoiseSecretStream< - RawStream extends NodeDuplex | Duplex = Duplex + RawStream extends NodeDuplex | Duplex = NodeDuplex | Duplex > extends Duplex< any, any, @@ -35,7 +37,7 @@ declare class NoiseSecretStream< any, true, true, - DuplexEvents & NoiseStreamEvents + DuplexEvents & NoiseSecretStream.NoiseStreamEvents > { readonly isInitiator: boolean readonly noiseStream: this @@ -46,11 +48,15 @@ declare class NoiseSecretStream< opened: Promise userData: any - constructor(isInitiator: boolean, rawStream?: RawStream, opts?: Opts) + constructor( + isInitiator: boolean, + rawStream?: RawStream, + opts?: NoiseSecretStream.Opts + ) - static keyPair(seed?: Buffer): KeyPair + static keyPair(seed?: Buffer): NoiseSecretStream.KeyPair - start(rawStream?: NodeDuplex, opts?: Opts): void + start(rawStream?: NodeDuplex, opts?: NoiseSecretStream.Opts): void setTimeout(ms?: number): void setKeepAlive(ms?: number): void } diff --git a/vendor/hypercore/index.d.ts b/vendor/hypercore/index.d.ts index befe012..c31a81a 100644 --- a/vendor/hypercore/index.d.ts +++ b/vendor/hypercore/index.d.ts @@ -4,6 +4,7 @@ import { type Duplex, type Readable } from 'streamx' import { type Duplex as NodeDuplex } from 'stream' import type Protomux from 'protomux' import type NoiseStream from '@hyperswarm/secret-stream' +import RandomAccessFile from '../random-access-file/index.js' interface RemoteBitfield { get(index: number): boolean @@ -49,11 +50,6 @@ interface HypercorePeer { onrange(options: PeerOnRangeOptions): void } -interface DownloadingRange { - destroy(): void - done(): Promise -} - type HypercoreStorageName = 'oplog' | 'tree' | 'bitfield' | 'data' interface HypercoreInfo { @@ -120,11 +116,22 @@ declare namespace Hypercore { type HypercoreStorage = | string | ((name: HypercoreStorageName) => RandomAccessStorage) -} + interface DownloadingRange { + destroy(): void + done(): Promise + } + + type ReplicationStream< + TStream extends Duplex | NodeDuplex = Duplex | NodeDuplex + > = TStream & { + noiseStream: ProtocolStream + } +} -type ProtocolStream = Omit & { userData: Protomux } -type ReplicationStream = Duplex & { noiseStream: ProtocolStream } +type ProtocolStream = Omit & { + userData: Protomux +} type CreateProtocolStreamOpts = { stream?: Duplex | NodeDuplex @@ -132,6 +139,15 @@ type CreateProtocolStreamOpts = { ondiscoverykey?: (id: Buffer) => Promise } +interface DefaultStorageOptions { + unlocked: boolean + lock: boolean + poolSize: number + pool: RandomAccessFile.RAFOptions['pool'] + rmdir: boolean + writable: boolean +} + declare class Hypercore< TValueEncoding extends Hypercore.ValueEncoding = 'binary', TKey extends Buffer | string | undefined = undefined @@ -148,8 +164,30 @@ declare class Hypercore< readonly contiguousLength: number readonly fork: number readonly padding: number - static createProtocolStream(stream: boolean | Duplex | NodeDuplex | NoiseStream | ProtocolStream | ReplicationStream | Protomux, opts: CreateProtocolStreamOpts): ReplicationStream - + static createProtocolStream( + stream: boolean, + opts?: CreateProtocolStreamOpts + ): Hypercore.ReplicationStream + static createProtocolStream( + stream: + | Duplex + | NodeDuplex + | NoiseStream + | ProtocolStream + | Hypercore.ReplicationStream + | Protomux, + opts?: CreateProtocolStreamOpts + ): Hypercore.ReplicationStream + static defaultStorage( + storage: TStorage + ): (name: string) => InstanceType + static defaultStorage< + TStorageFn extends (name: string) => RandomAccessStorage + >(storage: TStorageFn): TStorageFn + static defaultStorage( + storage: string, + opts: DefaultStorageOptions + ): (name: string) => RandomAccessFile constructor(storage: Hypercore.HypercoreStorage) constructor( storage: Hypercore.HypercoreStorage, @@ -220,7 +258,7 @@ declare class Hypercore< end?: number blocks?: number[] linear?: boolean - }): DownloadingRange + }): Hypercore.DownloadingRange session(options?: Hypercore.HypercoreOptions): Hypercore close(): Promise ready(): Promise @@ -234,8 +272,11 @@ declare class Hypercore< replicate( isInitiatorOrReplicationStream: boolean | Duplex | NodeDuplex, opts?: { keepAlive?: boolean } - ): ReplicationStream - replicate(protomux: Protomux, opts?: { keepAlive?: boolean }): Protomux + ): Hypercore.ReplicationStream + replicate( + protomux: Protomux, + opts?: { keepAlive?: boolean } + ): Protomux findingPeers(): () => void }