Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: export transiently referenced types #2717

Merged
merged 2 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/crypto/src/keys/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/**
* @packageDocumentation
*
* **Supported Key Types**
*
* The {@link generateKeyPair}, {@link marshalPublicKey}, and {@link marshalPrivateKey} functions accept a string `type` argument.
* ## Supported Key Types
*
* Currently the `'RSA'`, `'ed25519'`, and `secp256k1` types are supported, although ed25519 and secp256k1 keys support only signing and verification of messages.
*
Expand All @@ -19,6 +17,8 @@ import type { PrivateKey, PublicKey, KeyType, RSAPrivateKey, Secp256k1PrivateKey
import type { MultihashDigest } from 'multiformats'

export { generateEphemeralKeyPair } from './ecdh/index.js'
export type { Curve } from './ecdh/index.js'
export type { ECDHKey, EnhancedKey, EnhancedKeyPair, ECDHKeyPair } from './interface.js'
export { keyStretcher } from './key-stretcher.js'

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface MockNetworkComponents {
logger: ComponentLogger
}

class MockNetwork {
export class MockNetwork {
private components: MockNetworkComponents[] = []

addNode (components: MockNetworkComponents): void {
Expand Down
4 changes: 3 additions & 1 deletion packages/interface-compliance-tests/src/mocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ export { mockUpgrader } from './upgrader.js'
export { mockDuplex } from './duplex.js'
export { mockMetrics } from './metrics.js'
export type { MockUpgraderInit } from './upgrader.js'
export type { MockNetworkComponents } from './connection-manager.js'
export type { MockNetworkComponents, MockConnectionManagerComponents, MockNetwork } from './connection-manager.js'
export type { MockConnectionOptions, StreamInit, StreamPairInit } from './connection.js'
export type { MockMultiaddrConnPairOptions } from './multiaddr-connection.js'
2 changes: 1 addition & 1 deletion packages/interface-compliance-tests/src/mocks/muxer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,6 @@ class MockMuxerFactory implements StreamMuxerFactory {
}
}

export function mockMuxer (): MockMuxerFactory {
export function mockMuxer (): StreamMuxerFactory {
return new MockMuxerFactory()
}
1 change: 0 additions & 1 deletion packages/interface-compliance-tests/typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"./src/matchers.ts",
"./src/mocks/index.ts",
"./src/peer-discovery/index.ts",
"./src/peers.ts",
"./src/pubsub/index.ts",
"./src/stream-muxer/index.ts",
"./src/transport/index.ts"
Expand Down
8 changes: 6 additions & 2 deletions packages/interface-internal/src/connection-manager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ import type { ProgressOptions } from 'progress-events'
export interface OpenConnectionOptions extends AbortOptions, ProgressOptions<OpenConnectionProgressEvents> {
/**
* Connection requests with a higher priority will be executed before those
* with a lower priority. (default: 50)
* with a lower priority.
*
* @default 50
*/
priority?: number

/**
* When opening a connection to a remote peer, if a connection already exists
* it will be returned instead of creating a new connection. Pass true here
* to override that and dial a new connection anyway. (default: false)
* to override that and dial a new connection anyway.
*
* @default false
*/
force?: boolean
}
Expand Down
8 changes: 6 additions & 2 deletions packages/interface-internal/src/registrar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@ export interface StreamHandler {

export interface StreamHandlerOptions {
/**
* How many incoming streams can be open for this protocol at the same time on each connection (default: 32)
* How many incoming streams can be open for this protocol at the same time on each connection
*
* @default 32
*/
maxInboundStreams?: number

/**
* How many outgoing streams can be open for this protocol at the same time on each connection (default: 64)
* How many outgoing streams can be open for this protocol at the same time on each connection
*
* @default 64
*/
maxOutboundStreams?: number

Expand Down
2 changes: 1 addition & 1 deletion packages/interface/src/connection/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export interface Stream extends Duplex<AsyncGenerator<Uint8ArrayList>, Source<Ui
*
* This will cause a `RESET` message to be sent to the remote, *unless* the sink has already ended.
*
* The sink will return and the source will throw if an error is passed or return normally if not.
* The sink will return and the source will throw.
*/
abort(err: Error): void

Expand Down
4 changes: 3 additions & 1 deletion packages/interface/src/events.browser.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/** Noop for browser compatibility */
/**
* Noop for browser compatibility
*/
export function setMaxListeners (): void {}
4 changes: 3 additions & 1 deletion packages/interface/src/events.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { setMaxListeners as nodeSetMaxListeners } from 'events'

// create a setMaxListeners that doesn't break browser usage
/**
* Create a setMaxListeners that doesn't break browser usage
*/
export const setMaxListeners: typeof nodeSetMaxListeners = (n, ...eventTargets) => {
try {
nodeSetMaxListeners(n, ...eventTargets)
Expand Down
175 changes: 152 additions & 23 deletions packages/interface/src/keys/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ import type { Uint8ArrayList } from 'uint8arraylist'

export type KeyType = 'RSA' | 'Ed25519' | 'secp256k1'

interface PublicKeyBase<KeyType extends string, DigestCode extends number = number> {
export interface RSAPublicKey {
/**
* The type of this key
*/
readonly type: KeyType
readonly type: 'RSA'

/**
* The raw public key bytes (for Ed25519 and secp256k1 keys) or PKIX in ASN1
* DER format (for RSA keys)
* PKIX in ASN1 DER format
*/
readonly raw: Uint8Array

Expand All @@ -24,20 +23,101 @@ interface PublicKeyBase<KeyType extends string, DigestCode extends number = numb
/**
* Returns this public key as a Multihash digest.
*
* It contains either an identity hash containing the protobuf version of the
* public key (for Ed25519 and secp256k1 keys) or a sha256 hash of the
* protobuf version of the public key (RSA keys).
* It contains a sha256 hash of the protobuf version of the public key.
*/
toMultihash(): MultihashDigest<DigestCode>
toMultihash(): MultihashDigest<0x12>

/**
* Return this public key as a CID encoded with the `libp2p-key` codec
*
* The digest contains either an identity hash containing the protobuf version
* of the public key (for Ed25519 and secp256k1 keys) or a sha256 hash of the
* protobuf version of the public key (RSA keys).
* The digest contains a sha256 hash of the protobuf version of the public
* key.
*/
toCID(): CID<unknown, 0x72, DigestCode, 1>
toCID(): CID<unknown, 0x72, 0x12, 1>

/**
* Verify the passed data was signed by the private key corresponding to this
* public key
*/
verify(data: Uint8Array | Uint8ArrayList, sig: Uint8Array): boolean | Promise<boolean>

/**
* Returns this key as a multihash with base58btc encoding
*/
toString(): string
}

export interface Ed25519PublicKey {
/**
* The type of this key
*/
readonly type: 'Ed25519'

/**
* The raw public key bytes
*/
readonly raw: Uint8Array

/**
* Returns `true` if the passed object matches this key
*/
equals(key?: any): boolean

/**
* Returns this public key as an identity hash containing the protobuf wrapped
* public key
*/
toMultihash(): MultihashDigest<0x0>

/**
* Return this public key as a CID encoded with the `libp2p-key` codec
*
* The digest contains an identity hash containing the protobuf wrapped
* version of the public key.
*/
toCID(): CID<unknown, 0x72, 0x0, 1>

/**
* Verify the passed data was signed by the private key corresponding to this
* public key
*/
verify(data: Uint8Array | Uint8ArrayList, sig: Uint8Array): boolean | Promise<boolean>

/**
* Returns this key as a multihash with base58btc encoding
*/
toString(): string
}

export interface Secp256k1PublicKey {
/**
* The type of this key
*/
readonly type: 'secp256k1'

/**
* The raw public key bytes
*/
readonly raw: Uint8Array

/**
* Returns `true` if the passed object matches this key
*/
equals(key?: any): boolean

/**
* Returns this public key as an identity hash containing the protobuf wrapped
* public key
*/
toMultihash(): MultihashDigest<0x0>

/**
* Return this public key as a CID encoded with the `libp2p-key` codec
*
* The digest contains an identity hash containing the protobuf wrapped
* version of the public key.
*/
toCID(): CID<unknown, 0x72, 0x0, 1>

/**
* Verify the passed data was signed by the private key corresponding to this
Expand All @@ -51,9 +131,6 @@ interface PublicKeyBase<KeyType extends string, DigestCode extends number = numb
toString(): string
}

export interface RSAPublicKey extends PublicKeyBase<'RSA', 0x12> {}
export interface Ed25519PublicKey extends PublicKeyBase<'Ed25519', 0x0> {}
export interface Secp256k1PublicKey extends PublicKeyBase<'secp256k1', 0x0> {}
export type PublicKey = RSAPublicKey | Ed25519PublicKey | Secp256k1PublicKey

/**
Expand All @@ -76,20 +153,75 @@ export function isPublicKey (key?: any): key is PublicKey {
/**
* Generic private key interface
*/
interface PrivateKeyBase<KeyType extends string, PublicKeyType extends PublicKeyBase<KeyType>> {
export interface RSAPrivateKey {
/**
* The type of this key
*/
readonly type: 'RSA'

/**
* The public key that corresponds to this private key
*/
readonly publicKey: RSAPublicKey

/**
* PKIX in ASN1 DER format
*/
readonly raw: Uint8Array

/**
* Returns `true` if the passed object matches this key
*/
equals(key?: any): boolean

/**
* Sign the passed data with this private key and return the signature for
* later verification
*/
sign(data: Uint8Array | Uint8ArrayList): Uint8Array | Promise<Uint8Array>
}

export interface Ed25519PrivateKey {
/**
* The type of this key
*/
readonly type: 'Ed25519'

/**
* The public key that corresponds to this private key
*/
readonly publicKey: Ed25519PublicKey

/**
* The raw public key bytes
*/
readonly raw: Uint8Array

/**
* Returns `true` if the passed object matches this key
*/
equals(key?: any): boolean

/**
* Sign the passed data with this private key and return the signature for
* later verification
*/
sign(data: Uint8Array | Uint8ArrayList): Uint8Array | Promise<Uint8Array>
}

export interface Secp256k1PrivateKey {
/**
* The type of this key
*/
readonly type: KeyType
readonly type: 'secp256k1'

/**
* The public key that corresponds to this private key
*/
readonly publicKey: PublicKeyType
readonly publicKey: Secp256k1PublicKey

/**
* The raw public key bytes (for Ed25519 and secp256k1 keys) or PKIX in ASN1
* DER format (for RSA keys)
* The raw public key bytes
*/
readonly raw: Uint8Array

Expand All @@ -105,9 +237,6 @@ interface PrivateKeyBase<KeyType extends string, PublicKeyType extends PublicKey
sign(data: Uint8Array | Uint8ArrayList): Uint8Array | Promise<Uint8Array>
}

export interface RSAPrivateKey extends PrivateKeyBase<'RSA', RSAPublicKey> {}
export interface Ed25519PrivateKey extends PrivateKeyBase<'Ed25519', Ed25519PublicKey> {}
export interface Secp256k1PrivateKey extends PrivateKeyBase<'secp256k1', Secp256k1PublicKey> {}
export type PrivateKey = RSAPrivateKey | Ed25519PrivateKey | Secp256k1PrivateKey

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/interface/src/pubsub/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export interface PubSubInit {
maxOutboundStreams?: number
}

interface Subscription {
export interface Subscription {
topic: string
subscribe: boolean
}
Expand Down
8 changes: 6 additions & 2 deletions packages/interface/src/stream-handler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ export interface StreamHandler {

export interface StreamHandlerOptions {
/**
* How many incoming streams can be open for this protocol at the same time on each connection (default: 32)
* How many incoming streams can be open for this protocol at the same time on each connection
*
* @default 32
*/
maxInboundStreams?: number

/**
* How many outgoing streams can be open for this protocol at the same time on each connection (default: 64)
* How many outgoing streams can be open for this protocol at the same time on each connection
*
* @default 64
*/
maxOutboundStreams?: number

Expand Down
2 changes: 2 additions & 0 deletions packages/kad-dht/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ export type Selectors = Record<string, SelectFn>
*/
export type Validators = Record<string, ValidateFn>

export type { ProvidersInit }

export interface KadDHTInit {
/**
* How many peers to store in each kBucket. Once there are more than this
Expand Down
Loading
Loading