@libp2p/interface
Advanced tools
Comparing version 1.7.0-50b897139 to 1.7.0-5214dec4a
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PInterface = factory()}(typeof self !== 'undefined' ? self : this, function () { | ||
"use strict";var Libp2PInterface=(()=>{var n=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var L=Object.prototype.hasOwnProperty;var _=(e,t)=>{for(var o in t)n(e,o,{get:t[o],enumerable:!0})},g=(e,t,o,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of I(t))!L.call(e,r)&&r!==o&&n(e,r,{get:()=>t[r],enumerable:!(s=A(t,r))||s.enumerable});return e};var v=e=>g(n({},"__esModule",{value:!0}),e);var z={};_(z,{AbortError:()=>c,AggregateCodeError:()=>l,CodeError:()=>a,CustomEvent:()=>h,ERR_INVALID_MESSAGE:()=>X,ERR_INVALID_PARAMETERS:()=>G,ERR_NOT_FOUND:()=>j,ERR_TIMEOUT:()=>F,Ed25519:()=>w,FaultTolerance:()=>p,InvalidCryptoExchangeError:()=>x,InvalidCryptoTransmissionError:()=>m,KEEP_ALIVE:()=>U,RSA:()=>P,StrictNoSign:()=>k,StrictSign:()=>V,TopicValidatorResult:()=>i,TypedEventEmitter:()=>E,UnexpectedPeerError:()=>f,connectionSymbol:()=>S,contentRoutingSymbol:()=>T,isConnection:()=>N,isPeerId:()=>O,isStartable:()=>d,isTransport:()=>B,peerDiscoverySymbol:()=>M,peerIdSymbol:()=>R,peerRoutingSymbol:()=>C,secp256k1:()=>D,serviceCapabilities:()=>K,serviceDependencies:()=>q,setMaxListeners:()=>u,start:()=>Y,stop:()=>H,transportSymbol:()=>b});var S=Symbol.for("@libp2p/connection");function N(e){return e!=null&&!!e[S]}var T=Symbol.for("@libp2p/content-routing");var w="Ed25519",P="RSA",D="secp256k1";var M=Symbol.for("@libp2p/peer-discovery");var R=Symbol.for("@libp2p/peer-id");function O(e){return e!=null&&!!e[R]}var C=Symbol.for("@libp2p/peer-routing");var U="keep-alive";var V="StrictSign",k="StrictNoSign",i;(function(e){e.Accept="accept",e.Ignore="ignore",e.Reject="reject"})(i||(i={}));var b=Symbol.for("@libp2p/transport");function B(e){return e!=null&&!!e[b]}var p;(function(e){e[e.FATAL_ALL=0]="FATAL_ALL",e[e.NO_FATAL=1]="NO_FATAL"})(p||(p={}));var c=class e extends Error{code;type;constructor(t="The operation was aborted"){super(t),this.name="AbortError",this.code=e.code,this.type=e.type}static code="ABORT_ERR";static type="aborted"},a=class extends Error{code;props;constructor(t,o,s){super(t),this.code=o,this.name=s?.name??"CodeError",this.props=s??{}}},l=class extends AggregateError{code;props;constructor(t,o,s,r){super(t,o),this.code=s,this.name=r?.name??"AggregateCodeError",this.props=r??{}}},f=class e extends Error{code;constructor(t="Unexpected Peer"){super(t),this.name="UnexpectedPeerError",this.code=e.code}static code="ERR_UNEXPECTED_PEER"},x=class e extends Error{code;constructor(t="Invalid crypto exchange"){super(t),this.name="InvalidCryptoExchangeError",this.code=e.code}static code="ERR_INVALID_CRYPTO_EXCHANGE"},m=class e extends Error{code;constructor(t="Invalid crypto transmission"){super(t),this.name="InvalidCryptoTransmissionError",this.code=e.code}static code="ERR_INVALID_CRYPTO_TRANSMISSION"},F="ERR_TIMEOUT",G="ERR_INVALID_PARAMETERS",j="ERR_NOT_FOUND",X="ERR_INVALID_MESSAGE";var u=(e,...t)=>{try{[...t]}catch{}};var E=class extends EventTarget{#t=new Map;constructor(){super(),u(1/0,this)}listenerCount(t){let o=this.#t.get(t);return o==null?0:o.length}addEventListener(t,o,s){super.addEventListener(t,o,s);let r=this.#t.get(t);r==null&&(r=[],this.#t.set(t,r)),r.push({callback:o,once:(s!==!0&&s!==!1&&s?.once)??!1})}removeEventListener(t,o,s){super.removeEventListener(t.toString(),o??null,s);let r=this.#t.get(t);r!=null&&(r=r.filter(({callback:y})=>y!==o),this.#t.set(t,r))}dispatchEvent(t){let o=super.dispatchEvent(t),s=this.#t.get(t.type);return s==null||(s=s.filter(({once:r})=>!r),this.#t.set(t.type,s)),o}safeDispatchEvent(t,o={}){return this.dispatchEvent(new h(t,o))}},h=globalThis.CustomEvent;function d(e){return e!=null&&typeof e.start=="function"&&typeof e.stop=="function"}async function Y(...e){let t=[];for(let o of e)d(o)&&t.push(o);await Promise.all(t.map(async o=>{o.beforeStart!=null&&await o.beforeStart()})),await Promise.all(t.map(async o=>{await o.start()})),await Promise.all(t.map(async o=>{o.afterStart!=null&&await o.afterStart()}))}async function H(...e){let t=[];for(let o of e)d(o)&&t.push(o);await Promise.all(t.map(async o=>{o.beforeStop!=null&&await o.beforeStop()})),await Promise.all(t.map(async o=>{await o.stop()})),await Promise.all(t.map(async o=>{o.afterStop!=null&&await o.afterStop()}))}var K=Symbol.for("@libp2p/service-capabilities"),q=Symbol.for("@libp2p/service-dependencies");return v(z);})(); | ||
"use strict";var Libp2PInterface=(()=>{var n=Object.defineProperty;var J=Object.getOwnPropertyDescriptor;var Q=Object.getOwnPropertyNames;var V=Object.prototype.hasOwnProperty;var W=(t,r)=>{for(var e in r)n(t,e,{get:r[e],enumerable:!0})},X=(t,r,e,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of Q(r))!V.call(t,o)&&o!==e&&n(t,o,{get:()=>r[o],enumerable:!(s=J(r,o))||s.enumerable});return t};var Y=t=>X(n({},"__esModule",{value:!0}),t);var ur={};W(ur,{AbortError:()=>p,AggregateCodeError:()=>l,AlreadyStartedError:()=>N,CodeError:()=>i,ConnectionClosedError:()=>b,ConnectionClosingError:()=>E,ConnectionFailedError:()=>y,DialError:()=>k,FaultTolerance:()=>c,InvalidCIDError:()=>w,InvalidCryptoExchangeError:()=>x,InvalidMessageError:()=>T,InvalidMultiaddrError:()=>I,InvalidMultihashError:()=>A,InvalidParametersError:()=>m,InvalidPeerIdError:()=>L,InvalidPrivateKeyError:()=>f,InvalidPublicKeyError:()=>d,KEEP_ALIVE:()=>or,LimitedConnectionError:()=>U,ListenError:()=>_,NotFoundError:()=>g,NotStartedError:()=>M,ProtocolError:()=>C,StreamResetError:()=>S,StreamStateError:()=>v,StrictNoSign:()=>nr,StrictSign:()=>sr,TimeoutError:()=>D,TooManyInboundProtocolStreamsError:()=>B,TooManyOutboundProtocolStreamsError:()=>j,TopicValidatorResult:()=>a,TypedEventEmitter:()=>R,UnexpectedPeerError:()=>u,UnsupportedKeyTypeError:()=>F,UnsupportedOperationError:()=>h,UnsupportedProtocolError:()=>P,connectionSymbol:()=>q,contentRoutingSymbol:()=>$,isConnection:()=>Z,isPeerId:()=>tr,isStartable:()=>K,isTransport:()=>ar,peerDiscoverySymbol:()=>rr,peerIdSymbol:()=>z,peerRoutingSymbol:()=>er,serviceCapabilities:()=>ir,serviceDependencies:()=>lr,setMaxListeners:()=>O,start:()=>cr,stop:()=>pr,transportSymbol:()=>G});var q=Symbol.for("@libp2p/connection");function Z(t){return t!=null&&!!t[q]}var $=Symbol.for("@libp2p/content-routing");var rr=Symbol.for("@libp2p/peer-discovery");var z=Symbol.for("@libp2p/peer-id");function tr(t){return!!t?.[z]}var er=Symbol.for("@libp2p/peer-routing");var or="keep-alive";var sr="StrictSign",nr="StrictNoSign",a;(function(t){t.Accept="accept",t.Ignore="ignore",t.Reject="reject"})(a||(a={}));var G=Symbol.for("@libp2p/transport");function ar(t){return t!=null&&!!t[G]}var c;(function(t){t[t.FATAL_ALL=0]="FATAL_ALL",t[t.NO_FATAL=1]="NO_FATAL"})(c||(c={}));var p=class extends Error{constructor(r="The operation was aborted"){super(r),this.name="AbortError"}},i=class extends Error{code;props;constructor(r,e,s){super(r),this.code=e,this.name=s?.name??"CodeError",this.props=s??{}}},l=class extends AggregateError{code;props;constructor(r,e,s,o){super(r,e),this.code=s,this.name=o?.name??"AggregateCodeError",this.props=o??{}}},u=class extends Error{constructor(r="Unexpected Peer"){super(r),this.name="UnexpectedPeerError"}},x=class extends Error{constructor(r="Invalid crypto exchange"){super(r),this.name="InvalidCryptoExchangeError"}},m=class extends Error{constructor(r="Invalid parameters"){super(r),this.name="InvalidParametersError"}},d=class extends Error{constructor(r="Invalid public key"){super(r),this.name="InvalidPublicKeyError"}},f=class extends Error{constructor(r="Invalid private key"){super(r),this.name="InvalidPrivateKeyError"}},h=class extends Error{constructor(r="Unsupported operation"){super(r),this.name="UnsupportedOperationError"}},E=class extends Error{constructor(r="The connection is closing"){super(r),this.name="ConnectionClosingError"}},b=class extends Error{constructor(r="The connection is closed"){super(r),this.name="ConnectionClosedError"}},y=class extends Error{constructor(r="Connection failed"){super(r),this.name="ConnectionFailedError"}},S=class extends Error{constructor(r="The stream has been reset"){super(r),this.name="StreamResetError"}},v=class extends Error{constructor(r="The stream is in an invalid state"){super(r),this.name="StreamStateError"}},g=class extends Error{constructor(r="Not found"){super(r),this.name="NotFoundError"}},L=class extends Error{constructor(r="Invalid PeerID"){super(r),this.name="InvalidPeerIdError"}},I=class extends Error{constructor(r="Invalid multiaddr"){super(r),this.name="InvalidMultiaddrError"}},w=class extends Error{constructor(r="Invalid CID"){super(r),this.name="InvalidCIDError"}},A=class extends Error{constructor(r="Invalid Multihash"){super(r),this.name="InvalidMultihashError"}},P=class extends Error{constructor(r="Unsupported protocol error"){super(r),this.name="UnsupportedProtocolError"}},T=class extends Error{constructor(r="Invalid message"){super(r),this.name="InvalidMessageError"}},C=class extends Error{constructor(r="Protocol error"){super(r),this.name="ProtocolError"}},D=class extends Error{constructor(r="Timed out"){super(r),this.name="TimeoutError"}},M=class extends Error{constructor(r="Not started"){super(r),this.name="NotStartedError"}},N=class extends Error{constructor(r="Already started"){super(r),this.name="AlreadyStartedError"}},k=class extends Error{constructor(r="Dial error"){super(r),this.name="DialError"}},_=class extends Error{constructor(r="Listen error"){super(r),this.name="ListenError"}},U=class extends Error{constructor(r="Limited connection"){super(r),this.name="LimitedConnectionError"}},B=class extends Error{constructor(r="Too many inbound protocol streams"){super(r),this.name="TooManyInboundProtocolStreamsError"}},j=class extends Error{constructor(r="Too many outbound protocol streams"){super(r),this.name="TooManyOutboundProtocolStreamsError"}},F=class extends Error{constructor(r="Unsupported key type"){super(r),this.name="UnsupportedKeyTypeError"}};var O=(t,...r)=>{try{[...r]}catch{}};var R=class extends EventTarget{#r=new Map;constructor(){super(),O(1/0,this)}listenerCount(r){let e=this.#r.get(r);return e==null?0:e.length}addEventListener(r,e,s){super.addEventListener(r,e,s);let o=this.#r.get(r);o==null&&(o=[],this.#r.set(r,o)),o.push({callback:e,once:(s!==!0&&s!==!1&&s?.once)??!1})}removeEventListener(r,e,s){super.removeEventListener(r.toString(),e??null,s);let o=this.#r.get(r);o!=null&&(o=o.filter(({callback:H})=>H!==e),this.#r.set(r,o))}dispatchEvent(r){let e=super.dispatchEvent(r),s=this.#r.get(r.type);return s==null||(s=s.filter(({once:o})=>!o),this.#r.set(r.type,s)),e}safeDispatchEvent(r,e={}){return this.dispatchEvent(new CustomEvent(r,e))}};function K(t){return t!=null&&typeof t.start=="function"&&typeof t.stop=="function"}async function cr(...t){let r=[];for(let e of t)K(e)&&r.push(e);await Promise.all(r.map(async e=>{e.beforeStart!=null&&await e.beforeStart()})),await Promise.all(r.map(async e=>{await e.start()})),await Promise.all(r.map(async e=>{e.afterStart!=null&&await e.afterStart()}))}async function pr(...t){let r=[];for(let e of t)K(e)&&r.push(e);await Promise.all(r.map(async e=>{e.beforeStop!=null&&await e.beforeStop()})),await Promise.all(r.map(async e=>{await e.stop()})),await Promise.all(r.map(async e=>{e.afterStop!=null&&await e.afterStop()}))}var ir=Symbol.for("@libp2p/service-capabilities"),lr=Symbol.for("@libp2p/service-dependencies");return Y(ur);})(); | ||
return Libp2PInterface})); |
import type { MultiaddrConnection } from '../connection/index.js'; | ||
import type { AbortOptions } from '../index.js'; | ||
import type { PeerId } from '../peer-id/index.js'; | ||
@@ -6,2 +7,10 @@ import type { Duplex } from 'it-stream-types'; | ||
/** | ||
* If the remote PeerId is known and passed as an option, the securing operation | ||
* will throw if the remote peer cannot prove it has the private key that | ||
* corresponds to the public key the remote PeerId is derived from. | ||
*/ | ||
export interface SecureConnectionOptions extends AbortOptions { | ||
remotePeer?: PeerId; | ||
} | ||
/** | ||
* A libp2p connection encrypter module must be compliant to this interface | ||
@@ -17,3 +26,3 @@ * to ensure all exchanged data between two peers is encrypted. | ||
*/ | ||
secureOutbound<Stream extends Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>> = MultiaddrConnection>(localPeer: PeerId, connection: Stream, remotePeer?: PeerId): Promise<SecuredConnection<Stream, Extension>>; | ||
secureOutbound<Stream extends Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>> = MultiaddrConnection>(connection: Stream, options?: SecureConnectionOptions): Promise<SecuredConnection<Stream, Extension>>; | ||
/** | ||
@@ -24,3 +33,3 @@ * Decrypt incoming data. If the remote PeerId is known, | ||
*/ | ||
secureInbound<Stream extends Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>> = MultiaddrConnection>(localPeer: PeerId, connection: Stream, remotePeer?: PeerId): Promise<SecuredConnection<Stream, Extension>>; | ||
secureInbound<Stream extends Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>> = MultiaddrConnection>(connection: Stream, options?: SecureConnectionOptions): Promise<SecuredConnection<Stream, Extension>>; | ||
} | ||
@@ -27,0 +36,0 @@ export interface SecuredConnection<Stream = any, Extension = unknown> { |
@@ -160,8 +160,12 @@ import type { AbortOptions, Logger } from '../index.js'; | ||
/** | ||
* Opt-in to running over a transient connection - one that has time/data limits | ||
* placed on it. | ||
* Opt-in to running over a limited connection - one that has restrictions | ||
* on the amount of data that may be transferred or how long it may be open for. | ||
* | ||
* These limits are typically enforced by a relay server, if the protocol | ||
* will be transferring a lot of data or the stream will be open for a long time | ||
* consider upgrading to a direct connection before opening the stream. | ||
* | ||
* @default false | ||
*/ | ||
runOnTransientConnection?: boolean; | ||
runOnLimitedConnection?: boolean; | ||
/** | ||
@@ -196,2 +200,23 @@ * By default when negotiating a protocol the dialer writes then protocol name | ||
/** | ||
* Connection limits are present on connections that are only allowed to | ||
* transfer a certain amount of bytes or be open for a certain number | ||
* of seconds. | ||
* | ||
* These limits are applied by Circuit Relay v2 servers, for example and | ||
* the connection will normally be closed abruptly if the limits are | ||
* exceeded. | ||
*/ | ||
export interface ConnectionLimits { | ||
/** | ||
* If present this is the number of bytes remaining that may be | ||
* transferred over this connection | ||
*/ | ||
bytes?: bigint; | ||
/** | ||
* If present this is the number of seconds that this connection will | ||
* remain open for | ||
*/ | ||
seconds?: number; | ||
} | ||
/** | ||
* A Connection is a high-level representation of a connection | ||
@@ -244,8 +269,7 @@ * to a remote peer that may have been secured by encryption and | ||
/** | ||
* A transient connection is one that is not expected to be open for very long | ||
* or one that cannot transfer very much data, such as one being used as a | ||
* circuit relay connection. Protocols need to explicitly opt-in to being run | ||
* over transient connections. | ||
* If present, this connection has limits applied to it, perhaps by an | ||
* intermediate relay. Once the limits have been reached the connection will | ||
* be closed by the relay. | ||
*/ | ||
transient: boolean; | ||
limits?: ConnectionLimits; | ||
/** | ||
@@ -252,0 +276,0 @@ * The time in milliseconds it takes to make a round trip to the remote peer. |
@@ -7,8 +7,7 @@ /** | ||
export declare class AbortError extends Error { | ||
readonly code: string; | ||
readonly type: string; | ||
constructor(message?: string); | ||
static readonly code = "ABORT_ERR"; | ||
static readonly type = "aborted"; | ||
} | ||
/** | ||
* @deprecated | ||
*/ | ||
export declare class CodeError<T extends Record<string, any> = Record<string, never>> extends Error { | ||
@@ -19,2 +18,5 @@ readonly code: string; | ||
} | ||
/** | ||
* @deprecated | ||
*/ | ||
export declare class AggregateCodeError<T extends Record<string, any> = Record<string, never>> extends AggregateError { | ||
@@ -26,20 +28,91 @@ readonly code: string; | ||
export declare class UnexpectedPeerError extends Error { | ||
code: string; | ||
constructor(message?: string); | ||
static readonly code = "ERR_UNEXPECTED_PEER"; | ||
} | ||
export declare class InvalidCryptoExchangeError extends Error { | ||
code: string; | ||
constructor(message?: string); | ||
static readonly code = "ERR_INVALID_CRYPTO_EXCHANGE"; | ||
} | ||
export declare class InvalidCryptoTransmissionError extends Error { | ||
code: string; | ||
export declare class InvalidParametersError extends Error { | ||
constructor(message?: string); | ||
static readonly code = "ERR_INVALID_CRYPTO_TRANSMISSION"; | ||
} | ||
export declare const ERR_TIMEOUT = "ERR_TIMEOUT"; | ||
export declare const ERR_INVALID_PARAMETERS = "ERR_INVALID_PARAMETERS"; | ||
export declare const ERR_NOT_FOUND = "ERR_NOT_FOUND"; | ||
export declare const ERR_INVALID_MESSAGE = "ERR_INVALID_MESSAGE"; | ||
export declare class InvalidPublicKeyError extends Error { | ||
constructor(message?: string); | ||
} | ||
export declare class InvalidPrivateKeyError extends Error { | ||
constructor(message?: string); | ||
} | ||
export declare class UnsupportedOperationError extends Error { | ||
constructor(message?: string); | ||
} | ||
export declare class ConnectionClosingError extends Error { | ||
constructor(message?: string); | ||
} | ||
export declare class ConnectionClosedError extends Error { | ||
constructor(message?: string); | ||
} | ||
export declare class ConnectionFailedError extends Error { | ||
constructor(message?: string); | ||
} | ||
export declare class StreamResetError extends Error { | ||
constructor(message?: string); | ||
} | ||
export declare class StreamStateError extends Error { | ||
constructor(message?: string); | ||
} | ||
export declare class NotFoundError extends Error { | ||
constructor(message?: string); | ||
} | ||
export declare class InvalidPeerIdError extends Error { | ||
constructor(message?: string); | ||
} | ||
export declare class InvalidMultiaddrError extends Error { | ||
constructor(message?: string); | ||
} | ||
export declare class InvalidCIDError extends Error { | ||
constructor(message?: string); | ||
} | ||
export declare class InvalidMultihashError extends Error { | ||
constructor(message?: string); | ||
} | ||
export declare class UnsupportedProtocolError extends Error { | ||
constructor(message?: string); | ||
} | ||
/** | ||
* An invalid or malformed message was encountered during a protocol exchange | ||
*/ | ||
export declare class InvalidMessageError extends Error { | ||
constructor(message?: string); | ||
} | ||
export declare class ProtocolError extends Error { | ||
constructor(message?: string); | ||
} | ||
export declare class TimeoutError extends Error { | ||
constructor(message?: string); | ||
} | ||
export declare class NotStartedError extends Error { | ||
constructor(message?: string); | ||
} | ||
export declare class AlreadyStartedError extends Error { | ||
constructor(message?: string); | ||
} | ||
export declare class DialError extends Error { | ||
constructor(message?: string); | ||
} | ||
export declare class ListenError extends Error { | ||
constructor(message?: string); | ||
} | ||
export declare class LimitedConnectionError extends Error { | ||
constructor(message?: string); | ||
} | ||
export declare class TooManyInboundProtocolStreamsError extends Error { | ||
constructor(message?: string); | ||
} | ||
export declare class TooManyOutboundProtocolStreamsError extends Error { | ||
constructor(message?: string); | ||
} | ||
/** | ||
* Thrown when and attempt to operate on an unsupported key was made | ||
*/ | ||
export declare class UnsupportedKeyTypeError extends Error { | ||
constructor(message?: string); | ||
} | ||
//# sourceMappingURL=errors.d.ts.map |
@@ -7,13 +7,10 @@ /** | ||
export class AbortError extends Error { | ||
code; | ||
type; | ||
constructor(message = 'The operation was aborted') { | ||
super(message); | ||
this.name = 'AbortError'; | ||
this.code = AbortError.code; | ||
this.type = AbortError.type; | ||
} | ||
static code = 'ABORT_ERR'; | ||
static type = 'aborted'; | ||
} | ||
/** | ||
* @deprecated | ||
*/ | ||
export class CodeError extends Error { | ||
@@ -29,2 +26,5 @@ code; | ||
} | ||
/** | ||
* @deprecated | ||
*/ | ||
export class AggregateCodeError extends AggregateError { | ||
@@ -41,33 +41,175 @@ code; | ||
export class UnexpectedPeerError extends Error { | ||
code; | ||
constructor(message = 'Unexpected Peer') { | ||
super(message); | ||
this.name = 'UnexpectedPeerError'; | ||
this.code = UnexpectedPeerError.code; | ||
} | ||
static code = 'ERR_UNEXPECTED_PEER'; | ||
} | ||
export class InvalidCryptoExchangeError extends Error { | ||
code; | ||
constructor(message = 'Invalid crypto exchange') { | ||
super(message); | ||
this.name = 'InvalidCryptoExchangeError'; | ||
this.code = InvalidCryptoExchangeError.code; | ||
} | ||
static code = 'ERR_INVALID_CRYPTO_EXCHANGE'; | ||
} | ||
export class InvalidCryptoTransmissionError extends Error { | ||
code; | ||
constructor(message = 'Invalid crypto transmission') { | ||
export class InvalidParametersError extends Error { | ||
constructor(message = 'Invalid parameters') { | ||
super(message); | ||
this.name = 'InvalidCryptoTransmissionError'; | ||
this.code = InvalidCryptoTransmissionError.code; | ||
this.name = 'InvalidParametersError'; | ||
} | ||
static code = 'ERR_INVALID_CRYPTO_TRANSMISSION'; | ||
} | ||
// Error codes | ||
export const ERR_TIMEOUT = 'ERR_TIMEOUT'; | ||
export const ERR_INVALID_PARAMETERS = 'ERR_INVALID_PARAMETERS'; | ||
export const ERR_NOT_FOUND = 'ERR_NOT_FOUND'; | ||
export const ERR_INVALID_MESSAGE = 'ERR_INVALID_MESSAGE'; | ||
export class InvalidPublicKeyError extends Error { | ||
constructor(message = 'Invalid public key') { | ||
super(message); | ||
this.name = 'InvalidPublicKeyError'; | ||
} | ||
} | ||
export class InvalidPrivateKeyError extends Error { | ||
constructor(message = 'Invalid private key') { | ||
super(message); | ||
this.name = 'InvalidPrivateKeyError'; | ||
} | ||
} | ||
export class UnsupportedOperationError extends Error { | ||
constructor(message = 'Unsupported operation') { | ||
super(message); | ||
this.name = 'UnsupportedOperationError'; | ||
} | ||
} | ||
export class ConnectionClosingError extends Error { | ||
constructor(message = 'The connection is closing') { | ||
super(message); | ||
this.name = 'ConnectionClosingError'; | ||
} | ||
} | ||
export class ConnectionClosedError extends Error { | ||
constructor(message = 'The connection is closed') { | ||
super(message); | ||
this.name = 'ConnectionClosedError'; | ||
} | ||
} | ||
export class ConnectionFailedError extends Error { | ||
constructor(message = 'Connection failed') { | ||
super(message); | ||
this.name = 'ConnectionFailedError'; | ||
} | ||
} | ||
export class StreamResetError extends Error { | ||
constructor(message = 'The stream has been reset') { | ||
super(message); | ||
this.name = 'StreamResetError'; | ||
} | ||
} | ||
export class StreamStateError extends Error { | ||
constructor(message = 'The stream is in an invalid state') { | ||
super(message); | ||
this.name = 'StreamStateError'; | ||
} | ||
} | ||
export class NotFoundError extends Error { | ||
constructor(message = 'Not found') { | ||
super(message); | ||
this.name = 'NotFoundError'; | ||
} | ||
} | ||
export class InvalidPeerIdError extends Error { | ||
constructor(message = 'Invalid PeerID') { | ||
super(message); | ||
this.name = 'InvalidPeerIdError'; | ||
} | ||
} | ||
export class InvalidMultiaddrError extends Error { | ||
constructor(message = 'Invalid multiaddr') { | ||
super(message); | ||
this.name = 'InvalidMultiaddrError'; | ||
} | ||
} | ||
export class InvalidCIDError extends Error { | ||
constructor(message = 'Invalid CID') { | ||
super(message); | ||
this.name = 'InvalidCIDError'; | ||
} | ||
} | ||
export class InvalidMultihashError extends Error { | ||
constructor(message = 'Invalid Multihash') { | ||
super(message); | ||
this.name = 'InvalidMultihashError'; | ||
} | ||
} | ||
export class UnsupportedProtocolError extends Error { | ||
constructor(message = 'Unsupported protocol error') { | ||
super(message); | ||
this.name = 'UnsupportedProtocolError'; | ||
} | ||
} | ||
/** | ||
* An invalid or malformed message was encountered during a protocol exchange | ||
*/ | ||
export class InvalidMessageError extends Error { | ||
constructor(message = 'Invalid message') { | ||
super(message); | ||
this.name = 'InvalidMessageError'; | ||
} | ||
} | ||
export class ProtocolError extends Error { | ||
constructor(message = 'Protocol error') { | ||
super(message); | ||
this.name = 'ProtocolError'; | ||
} | ||
} | ||
export class TimeoutError extends Error { | ||
constructor(message = 'Timed out') { | ||
super(message); | ||
this.name = 'TimeoutError'; | ||
} | ||
} | ||
export class NotStartedError extends Error { | ||
constructor(message = 'Not started') { | ||
super(message); | ||
this.name = 'NotStartedError'; | ||
} | ||
} | ||
export class AlreadyStartedError extends Error { | ||
constructor(message = 'Already started') { | ||
super(message); | ||
this.name = 'AlreadyStartedError'; | ||
} | ||
} | ||
export class DialError extends Error { | ||
constructor(message = 'Dial error') { | ||
super(message); | ||
this.name = 'DialError'; | ||
} | ||
} | ||
export class ListenError extends Error { | ||
constructor(message = 'Listen error') { | ||
super(message); | ||
this.name = 'ListenError'; | ||
} | ||
} | ||
export class LimitedConnectionError extends Error { | ||
constructor(message = 'Limited connection') { | ||
super(message); | ||
this.name = 'LimitedConnectionError'; | ||
} | ||
} | ||
export class TooManyInboundProtocolStreamsError extends Error { | ||
constructor(message = 'Too many inbound protocol streams') { | ||
super(message); | ||
this.name = 'TooManyInboundProtocolStreamsError'; | ||
} | ||
} | ||
export class TooManyOutboundProtocolStreamsError extends Error { | ||
constructor(message = 'Too many outbound protocol streams') { | ||
super(message); | ||
this.name = 'TooManyOutboundProtocolStreamsError'; | ||
} | ||
} | ||
/** | ||
* Thrown when and attempt to operate on an unsupported key was made | ||
*/ | ||
export class UnsupportedKeyTypeError extends Error { | ||
constructor(message = 'Unsupported key type') { | ||
super(message); | ||
this.name = 'UnsupportedKeyTypeError'; | ||
} | ||
} | ||
//# sourceMappingURL=errors.js.map |
@@ -36,6 +36,2 @@ export interface EventCallback<EventType> { | ||
} | ||
export declare const CustomEvent: { | ||
new <T>(type: string, eventInitDict?: CustomEventInit<T> | undefined): CustomEvent<T>; | ||
prototype: CustomEvent<any>; | ||
}; | ||
//# sourceMappingURL=event-target.d.ts.map |
@@ -56,3 +56,2 @@ import { setMaxListeners } from './events.js'; | ||
} | ||
export const CustomEvent = globalThis.CustomEvent; | ||
//# sourceMappingURL=event-target.js.map |
@@ -19,4 +19,5 @@ /** | ||
import type { TypedEventTarget } from './event-target.js'; | ||
import type { Ed25519PublicKey, PublicKey, RSAPublicKey, Secp256k1PublicKey } from './keys/index.js'; | ||
import type { Metrics } from './metrics/index.js'; | ||
import type { PeerId } from './peer-id/index.js'; | ||
import type { Ed25519PeerId, PeerId, RSAPeerId, Secp256k1PeerId, URLPeerId } from './peer-id/index.js'; | ||
import type { PeerInfo } from './peer-info/index.js'; | ||
@@ -299,3 +300,3 @@ import type { PeerRouting } from './peer-routing/index.js'; | ||
*/ | ||
runOnTransientConnection?: boolean; | ||
runOnLimitedConnection?: boolean; | ||
} | ||
@@ -305,2 +306,6 @@ export type TransportManagerDialProgressEvents = ProgressEvent<'transport-manager:selected-transport', string>; | ||
export interface DialOptions extends AbortOptions, ProgressOptions { | ||
/** | ||
* If true, open a new connection to the remote even if one already exists | ||
*/ | ||
force?: boolean; | ||
} | ||
@@ -578,3 +583,7 @@ export interface DialProtocolOptions extends NewStreamOptions { | ||
*/ | ||
getPublicKey(peer: PeerId, options?: AbortOptions): Promise<Uint8Array>; | ||
getPublicKey(peer: Ed25519PeerId, options?: AbortOptions): Promise<Ed25519PublicKey>; | ||
getPublicKey(peer: Secp256k1PeerId, options?: AbortOptions): Promise<Secp256k1PublicKey>; | ||
getPublicKey(peer: RSAPeerId, options?: AbortOptions): Promise<RSAPublicKey>; | ||
getPublicKey(peer: URLPeerId, options?: AbortOptions): Promise<never>; | ||
getPublicKey(peer: PeerId, options?: AbortOptions): Promise<PublicKey>; | ||
/** | ||
@@ -581,0 +590,0 @@ * Given the current node configuration, returns a promise of `true` or |
@@ -0,36 +1,87 @@ | ||
import type { CID } from 'multiformats/cid'; | ||
import type { MultihashDigest } from 'multiformats/hashes/interface'; | ||
import type { Uint8ArrayList } from 'uint8arraylist'; | ||
export interface PublicKey<Type extends KeyType = 'Ed25519'> { | ||
readonly bytes: Uint8Array; | ||
export type KeyType = 'RSA' | 'Ed25519' | 'secp256k1'; | ||
interface PublicKeyBase<KeyType extends string, DigestCode extends number = number> { | ||
/** | ||
* The type of this key | ||
*/ | ||
readonly type: KeyType; | ||
/** | ||
* The raw public key bytes (for Ed25519 and secp256k1 keys) or PKIX in ASN1 | ||
* DER format (for RSA keys) | ||
*/ | ||
readonly raw: Uint8Array; | ||
/** | ||
* Returns `true` if the passed object matches this key | ||
*/ | ||
equals(key?: any): boolean; | ||
/** | ||
* 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). | ||
*/ | ||
toMultihash(): MultihashDigest<DigestCode>; | ||
/** | ||
* 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). | ||
*/ | ||
toCID(): CID<unknown, 0x72, DigestCode, 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>; | ||
marshal(): Uint8Array; | ||
equals(key: PublicKey<Type>): boolean; | ||
hash(): Uint8Array | Promise<Uint8Array>; | ||
/** | ||
* Returns this key as a multihash with base58btc encoding | ||
*/ | ||
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; | ||
/** | ||
* Generic private key interface | ||
*/ | ||
export interface PrivateKey<Type extends KeyType = 'Ed25519'> { | ||
readonly public: PublicKey<Type>; | ||
readonly bytes: Uint8Array; | ||
sign(data: Uint8Array | Uint8ArrayList): Uint8Array | Promise<Uint8Array>; | ||
marshal(): Uint8Array; | ||
equals(key: PrivateKey<Type>): boolean; | ||
hash(): Uint8Array | Promise<Uint8Array>; | ||
interface PrivateKeyBase<KeyType extends string, PublicKeyType extends PublicKeyBase<KeyType>> { | ||
/** | ||
* Gets the ID of the key. | ||
* | ||
* The key id is the base58 encoding of the SHA-256 multihash of its public key. | ||
* The public key is a protobuf encoding containing a type and the DER encoding | ||
* of the PKCS SubjectPublicKeyInfo. | ||
* The type of this key | ||
*/ | ||
id(): Promise<string>; | ||
readonly type: KeyType; | ||
/** | ||
* Exports the password protected key in the format specified. | ||
* The public key that corresponds to this private key | ||
*/ | ||
export(password: string, format?: 'pkcs-8' | string): Promise<string>; | ||
readonly publicKey: PublicKeyType; | ||
/** | ||
* The raw public key bytes (for Ed25519 and secp256k1 keys) or PKIX in ASN1 | ||
* DER format (for RSA keys) | ||
*/ | ||
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 declare const Ed25519 = "Ed25519"; | ||
export declare const RSA = "RSA"; | ||
export declare const secp256k1 = "secp256k1"; | ||
export type KeyType = typeof Ed25519 | typeof RSA | typeof secp256k1; | ||
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; | ||
export {}; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,4 +0,2 @@ | ||
export const Ed25519 = 'Ed25519'; | ||
export const RSA = 'RSA'; | ||
export const secp256k1 = 'secp256k1'; | ||
export {}; | ||
//# sourceMappingURL=index.js.map |
@@ -70,17 +70,17 @@ import type { MultiaddrConnection, Stream, Connection } from '../connection/index.js'; | ||
*/ | ||
export interface MetricGroup { | ||
export interface MetricGroup<T extends string = any> { | ||
/** | ||
* Update the stored metric group to the passed value | ||
*/ | ||
update(values: Record<string, number>): void; | ||
update(values: Partial<Record<T, number>>): void; | ||
/** | ||
* Increment the metric group keys by the passed number or | ||
* any non-numeric value to increment by 1 | ||
* `true` to increment by 1 | ||
*/ | ||
increment(values: Record<string, number | unknown>): void; | ||
increment(values: Partial<Record<T, number | true>>): void; | ||
/** | ||
* Decrement the metric group keys by the passed number or | ||
* any non-numeric value to decrement by 1 | ||
* `true` to decrement by 1 | ||
*/ | ||
decrement(values: Record<string, number | unknown>): void; | ||
decrement(values: Partial<Record<T, number | true>>): void; | ||
/** | ||
@@ -116,3 +116,3 @@ * Reset the passed key in this metric group to its default value | ||
*/ | ||
export interface CounterGroup { | ||
export interface CounterGroup<T extends string = any> { | ||
/** | ||
@@ -122,3 +122,3 @@ * Increment the metric group keys by the passed number or | ||
*/ | ||
increment(values: Record<string, number | unknown>): void; | ||
increment(values: Partial<Record<T, number | true>>): void; | ||
/** | ||
@@ -125,0 +125,0 @@ * Reset the passed key in this metric group to its default value |
@@ -1,32 +0,134 @@ | ||
import type { KeyType } from '../keys/index.js'; | ||
import type { Ed25519PublicKey, KeyType, RSAPublicKey, Secp256k1PublicKey } from '../keys/index.js'; | ||
import type { CID } from 'multiformats/cid'; | ||
import type { MultihashDigest } from 'multiformats/hashes/interface'; | ||
export type PeerIdType = KeyType | string; | ||
export interface RSAPeerId extends PeerId { | ||
/** | ||
* A PeerId generated from an RSA public key - it is a base58btc encoded sha-256 | ||
* hash of the public key. | ||
* | ||
* RSA public keys are too large to pass around freely, instead Ed25519 or | ||
* secp256k1 should be preferred as they can embed their public key in the | ||
* PeerId itself. | ||
* | ||
* @deprecated Ed25519 or secp256k1 keys are preferred to RSA | ||
*/ | ||
export interface RSAPeerId { | ||
readonly type: 'RSA'; | ||
readonly publicKey?: Uint8Array; | ||
/** | ||
* RSA public keys are too large to embed in the multihash commonly used to | ||
* refer to peers, so this will only be defined if the public key has | ||
* previously been found through a routing query or during normal protocol | ||
* operations | ||
*/ | ||
readonly publicKey?: RSAPublicKey; | ||
/** | ||
* Returns the multihash from `toMultihash()` as a base58btc encoded string | ||
*/ | ||
toString(): string; | ||
/** | ||
* Returns a multihash, the digest of which is the SHA2-256 hash of the public | ||
* key | ||
*/ | ||
toMultihash(): MultihashDigest<0x12>; | ||
/** | ||
* Returns a CID with the libp2p key code and the same multihash as | ||
* `toMultihash()` | ||
*/ | ||
toCID(): CID<Uint8Array, 0x72, 0x12, 1>; | ||
/** | ||
* Returns true if the passed argument is equivalent to this PeerId | ||
*/ | ||
equals(other?: any): boolean; | ||
} | ||
export interface Ed25519PeerId extends PeerId { | ||
export interface Ed25519PeerId { | ||
readonly type: 'Ed25519'; | ||
readonly publicKey: Uint8Array; | ||
/** | ||
* This will always be defined as the public key is embedded in the multihash | ||
* of this PeerId | ||
*/ | ||
readonly publicKey: Ed25519PublicKey; | ||
/** | ||
* Returns the multihash from `toMultihash()` as a base58btc encoded string | ||
*/ | ||
toString(): string; | ||
/** | ||
* Returns a multihash, the digest of which is the protobuf-encoded public key | ||
* encoded as an identity hash | ||
*/ | ||
toMultihash(): MultihashDigest<0x0>; | ||
/** | ||
* Returns a CID with the libp2p key code and the same multihash as | ||
* `toMultihash()` | ||
*/ | ||
toCID(): CID<Uint8Array, 0x72, 0x0, 1>; | ||
/** | ||
* Returns true if the passed argument is equivalent to this PeerId | ||
*/ | ||
equals(other?: any): boolean; | ||
} | ||
export interface Secp256k1PeerId extends PeerId { | ||
export interface Secp256k1PeerId { | ||
readonly type: 'secp256k1'; | ||
readonly publicKey: Uint8Array; | ||
/** | ||
* This will always be defined as the public key is embedded in the multihash | ||
* of this PeerId | ||
*/ | ||
readonly publicKey: Secp256k1PublicKey; | ||
/** | ||
* Returns the multihash from `toMultihash()` as a base58btc encoded string | ||
*/ | ||
toString(): string; | ||
/** | ||
* Returns a multihash, the digest of which is the protobuf-encoded public key | ||
* encoded as an identity hash | ||
*/ | ||
toMultihash(): MultihashDigest<0x0>; | ||
/** | ||
* Returns a CID with the libp2p key code and the same multihash as | ||
* `toMultihash()` | ||
*/ | ||
toCID(): CID<Uint8Array, 0x72, 0x0, 1>; | ||
/** | ||
* Returns true if the passed argument is equivalent to this PeerId | ||
*/ | ||
equals(other?: any): boolean; | ||
} | ||
export interface URLPeerId extends PeerId { | ||
export interface URLPeerId { | ||
readonly type: 'url'; | ||
} | ||
export interface PeerId { | ||
type: PeerIdType; | ||
multihash: MultihashDigest; | ||
privateKey?: Uint8Array; | ||
publicKey?: Uint8Array; | ||
/** | ||
* This will always be undefined as URL Peers do not have public keys | ||
*/ | ||
readonly publicKey: undefined; | ||
/** | ||
* Returns CID from `toCID()` encoded as a base36 string | ||
*/ | ||
toString(): string; | ||
toCID(): CID; | ||
toBytes(): Uint8Array; | ||
equals(other?: PeerId | Uint8Array | string): boolean; | ||
/** | ||
* Returns a multihash, the digest of which is the URL encoded as an identity | ||
* hash | ||
*/ | ||
toMultihash(): MultihashDigest<0x0>; | ||
/** | ||
* Returns a CID with the Transport IPFS Gateway HTTP code and the same | ||
* multihash as `toMultihash()` | ||
*/ | ||
toCID(): CID<Uint8Array, 0x0920, 0x0, 1>; | ||
/** | ||
* Returns true if the passed argument is equivalent to this PeerId | ||
*/ | ||
equals(other?: any): boolean; | ||
} | ||
/** | ||
* This is a union of all known PeerId types - use the `.type` field to | ||
* disambiguate them | ||
*/ | ||
export type PeerId = RSAPeerId | Ed25519PeerId | Secp256k1PeerId | URLPeerId; | ||
/** | ||
* All PeerId implementations must use this symbol as the name of a property | ||
* with a boolean `true` value | ||
*/ | ||
export declare const peerIdSymbol: unique symbol; | ||
export declare function isPeerId(other: any): other is PeerId; | ||
/** | ||
* Returns true if the passed argument is a PeerId implementation | ||
*/ | ||
export declare function isPeerId(other?: any): other is PeerId; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -0,5 +1,12 @@ | ||
/** | ||
* All PeerId implementations must use this symbol as the name of a property | ||
* with a boolean `true` value | ||
*/ | ||
export const peerIdSymbol = Symbol.for('@libp2p/peer-id'); | ||
/** | ||
* Returns true if the passed argument is a PeerId implementation | ||
*/ | ||
export function isPeerId(other) { | ||
return other != null && Boolean(other[peerIdSymbol]); | ||
return Boolean(other?.[peerIdSymbol]); | ||
} | ||
//# sourceMappingURL=index.js.map |
@@ -0,1 +1,2 @@ | ||
import type { PublicKey } from '../keys/index.js'; | ||
import type { PeerId } from '../peer-id/index.js'; | ||
@@ -80,5 +81,7 @@ import type { Multiaddr } from '@multiformats/multiaddr'; | ||
/** | ||
* If this Peer has an RSA key, it's public key can be set with this property | ||
* If this Peer has an RSA key, it's public key can be set with this property. | ||
* | ||
* The byte array should be the protobuf encoded form of the public key. | ||
*/ | ||
publicKey?: Uint8Array; | ||
publicKey?: PublicKey; | ||
/** | ||
@@ -85,0 +88,0 @@ * The last peer record envelope received |
import type { Stream } from '../connection/index.js'; | ||
import type { TypedEventTarget } from '../event-target.js'; | ||
import type { PublicKey } from '../keys/index.js'; | ||
import type { PeerId } from '../peer-id/index.js'; | ||
@@ -34,3 +35,3 @@ import type { Pushable } from 'it-pushable'; | ||
signature: Uint8Array; | ||
key: Uint8Array; | ||
key: PublicKey; | ||
} | ||
@@ -37,0 +38,0 @@ export interface UnsignedMessage { |
@@ -1,2 +0,2 @@ | ||
import type { PeerId } from '../peer-id/index.js'; | ||
import type { PublicKey } from '../keys/index.js'; | ||
import type { Uint8ArrayList } from 'uint8arraylist'; | ||
@@ -25,3 +25,3 @@ /** | ||
export interface Envelope { | ||
peerId: PeerId; | ||
publicKey: PublicKey; | ||
payloadType: Uint8Array | Uint8ArrayList; | ||
@@ -28,0 +28,0 @@ payload: Uint8Array; |
@@ -19,6 +19,6 @@ import type { Connection, Stream } from '../connection/index.js'; | ||
/** | ||
* Opt-in to running over a transient connection - one that has time/data limits | ||
* placed on it. | ||
* Opt-in to running over connections with limits on how much data can be | ||
* transferred or how long it can be open for. | ||
*/ | ||
runOnTransientConnection?: boolean; | ||
runOnLimitedConnection?: boolean; | ||
} | ||
@@ -25,0 +25,0 @@ export interface StreamHandlerRecord { |
@@ -27,8 +27,9 @@ import type { Connection } from '../connection/index.js'; | ||
/** | ||
* If true, invoke `onConnect` for this topology on transient (e.g. short-lived | ||
* and/or data-limited) connections | ||
* If true, invoke `onConnect` for this topology on limited connections, e.g. | ||
* ones with limits on how much data can be transferred or how long they can | ||
* be open for. | ||
* | ||
* @default false | ||
*/ | ||
notifyOnTransient?: boolean; | ||
notifyOnLimitedConnection?: boolean; | ||
/** | ||
@@ -35,0 +36,0 @@ * Invoked when a new connection is opened to a peer that supports the |
@@ -1,2 +0,2 @@ | ||
import type { Connection, MultiaddrConnection } from '../connection/index.js'; | ||
import type { Connection, ConnectionLimits, MultiaddrConnection } from '../connection/index.js'; | ||
import type { TypedEventTarget } from '../event-target.js'; | ||
@@ -88,11 +88,7 @@ import type { AbortOptions } from '../index.js'; | ||
} | ||
export interface UpgraderOptions<ConnectionUpgradeEvents extends ProgressEvent = ProgressEvent> extends ProgressOptions<ConnectionUpgradeEvents> { | ||
export interface UpgraderOptions<ConnectionUpgradeEvents extends ProgressEvent = ProgressEvent> extends ProgressOptions<ConnectionUpgradeEvents>, AbortOptions { | ||
skipEncryption?: boolean; | ||
skipProtection?: boolean; | ||
muxerFactory?: StreamMuxerFactory; | ||
/** | ||
* The passed MultiaddrConnection has limits place on duration and/or data | ||
* transfer amounts so is not expected to be open for very long. | ||
*/ | ||
transient?: boolean; | ||
limits?: ConnectionLimits; | ||
} | ||
@@ -99,0 +95,0 @@ export type InboundConnectionUpgradeEvents = ProgressEvent<'upgrader:encrypt-inbound-connection'> | ProgressEvent<'upgrader:multiplex-inbound-connection'>; |
{ | ||
"name": "@libp2p/interface", | ||
"version": "1.7.0-50b897139", | ||
"version": "1.7.0-5214dec4a", | ||
"description": "The interface implemented by a libp2p node", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0 OR MIT", |
import type { MultiaddrConnection } from '../connection/index.js' | ||
import type { AbortOptions } from '../index.js' | ||
import type { PeerId } from '../peer-id/index.js' | ||
@@ -7,2 +8,11 @@ import type { Duplex } from 'it-stream-types' | ||
/** | ||
* If the remote PeerId is known and passed as an option, the securing operation | ||
* will throw if the remote peer cannot prove it has the private key that | ||
* corresponds to the public key the remote PeerId is derived from. | ||
*/ | ||
export interface SecureConnectionOptions extends AbortOptions { | ||
remotePeer?: PeerId | ||
} | ||
/** | ||
* A libp2p connection encrypter module must be compliant to this interface | ||
@@ -19,3 +29,3 @@ * to ensure all exchanged data between two peers is encrypted. | ||
*/ | ||
secureOutbound <Stream extends Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>> = MultiaddrConnection> (localPeer: PeerId, connection: Stream, remotePeer?: PeerId): Promise<SecuredConnection<Stream, Extension>> | ||
secureOutbound <Stream extends Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>> = MultiaddrConnection> (connection: Stream, options?: SecureConnectionOptions): Promise<SecuredConnection<Stream, Extension>> | ||
@@ -27,3 +37,3 @@ /** | ||
*/ | ||
secureInbound <Stream extends Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>> = MultiaddrConnection> (localPeer: PeerId, connection: Stream, remotePeer?: PeerId): Promise<SecuredConnection<Stream, Extension>> | ||
secureInbound <Stream extends Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>> = MultiaddrConnection> (connection: Stream, options?: SecureConnectionOptions): Promise<SecuredConnection<Stream, Extension>> | ||
} | ||
@@ -30,0 +40,0 @@ |
@@ -188,8 +188,12 @@ import type { AbortOptions, Logger } from '../index.js' | ||
/** | ||
* Opt-in to running over a transient connection - one that has time/data limits | ||
* placed on it. | ||
* Opt-in to running over a limited connection - one that has restrictions | ||
* on the amount of data that may be transferred or how long it may be open for. | ||
* | ||
* These limits are typically enforced by a relay server, if the protocol | ||
* will be transferring a lot of data or the stream will be open for a long time | ||
* consider upgrading to a direct connection before opening the stream. | ||
* | ||
* @default false | ||
*/ | ||
runOnTransientConnection?: boolean | ||
runOnLimitedConnection?: boolean | ||
@@ -227,2 +231,25 @@ /** | ||
/** | ||
* Connection limits are present on connections that are only allowed to | ||
* transfer a certain amount of bytes or be open for a certain number | ||
* of seconds. | ||
* | ||
* These limits are applied by Circuit Relay v2 servers, for example and | ||
* the connection will normally be closed abruptly if the limits are | ||
* exceeded. | ||
*/ | ||
export interface ConnectionLimits { | ||
/** | ||
* If present this is the number of bytes remaining that may be | ||
* transferred over this connection | ||
*/ | ||
bytes?: bigint | ||
/** | ||
* If present this is the number of seconds that this connection will | ||
* remain open for | ||
*/ | ||
seconds?: number | ||
} | ||
/** | ||
* A Connection is a high-level representation of a connection | ||
@@ -285,8 +312,7 @@ * to a remote peer that may have been secured by encryption and | ||
/** | ||
* A transient connection is one that is not expected to be open for very long | ||
* or one that cannot transfer very much data, such as one being used as a | ||
* circuit relay connection. Protocols need to explicitly opt-in to being run | ||
* over transient connections. | ||
* If present, this connection has limits applied to it, perhaps by an | ||
* intermediate relay. Once the limits have been reached the connection will | ||
* be closed by the relay. | ||
*/ | ||
transient: boolean | ||
limits?: ConnectionLimits | ||
@@ -293,0 +319,0 @@ /** |
@@ -7,17 +7,11 @@ /** | ||
export class AbortError extends Error { | ||
public readonly code: string | ||
public readonly type: string | ||
constructor (message: string = 'The operation was aborted') { | ||
super(message) | ||
this.name = 'AbortError' | ||
this.code = AbortError.code | ||
this.type = AbortError.type | ||
} | ||
static readonly code = 'ABORT_ERR' | ||
static readonly type = 'aborted' | ||
} | ||
/** | ||
* @deprecated | ||
*/ | ||
export class CodeError<T extends Record<string, any> = Record<string, never>> extends Error { | ||
@@ -38,2 +32,5 @@ public readonly props: T | ||
/** | ||
* @deprecated | ||
*/ | ||
export class AggregateCodeError<T extends Record<string, any> = Record<string, never>> extends AggregateError { | ||
@@ -56,42 +53,201 @@ public readonly props: T | ||
export class UnexpectedPeerError extends Error { | ||
public code: string | ||
constructor (message = 'Unexpected Peer') { | ||
super(message) | ||
this.name = 'UnexpectedPeerError' | ||
this.code = UnexpectedPeerError.code | ||
} | ||
static readonly code = 'ERR_UNEXPECTED_PEER' | ||
} | ||
export class InvalidCryptoExchangeError extends Error { | ||
public code: string | ||
constructor (message = 'Invalid crypto exchange') { | ||
super(message) | ||
this.name = 'InvalidCryptoExchangeError' | ||
this.code = InvalidCryptoExchangeError.code | ||
} | ||
} | ||
static readonly code = 'ERR_INVALID_CRYPTO_EXCHANGE' | ||
export class InvalidParametersError extends Error { | ||
constructor (message = 'Invalid parameters') { | ||
super(message) | ||
this.name = 'InvalidParametersError' | ||
} | ||
} | ||
export class InvalidCryptoTransmissionError extends Error { | ||
public code: string | ||
export class InvalidPublicKeyError extends Error { | ||
constructor (message = 'Invalid public key') { | ||
super(message) | ||
this.name = 'InvalidPublicKeyError' | ||
} | ||
} | ||
constructor (message = 'Invalid crypto transmission') { | ||
export class InvalidPrivateKeyError extends Error { | ||
constructor (message = 'Invalid private key') { | ||
super(message) | ||
this.name = 'InvalidCryptoTransmissionError' | ||
this.code = InvalidCryptoTransmissionError.code | ||
this.name = 'InvalidPrivateKeyError' | ||
} | ||
} | ||
static readonly code = 'ERR_INVALID_CRYPTO_TRANSMISSION' | ||
export class UnsupportedOperationError extends Error { | ||
constructor (message = 'Unsupported operation') { | ||
super(message) | ||
this.name = 'UnsupportedOperationError' | ||
} | ||
} | ||
// Error codes | ||
export class ConnectionClosingError extends Error { | ||
constructor (message = 'The connection is closing') { | ||
super(message) | ||
this.name = 'ConnectionClosingError' | ||
} | ||
} | ||
export const ERR_TIMEOUT = 'ERR_TIMEOUT' | ||
export const ERR_INVALID_PARAMETERS = 'ERR_INVALID_PARAMETERS' | ||
export const ERR_NOT_FOUND = 'ERR_NOT_FOUND' | ||
export const ERR_INVALID_MESSAGE = 'ERR_INVALID_MESSAGE' | ||
export class ConnectionClosedError extends Error { | ||
constructor (message = 'The connection is closed') { | ||
super(message) | ||
this.name = 'ConnectionClosedError' | ||
} | ||
} | ||
export class ConnectionFailedError extends Error { | ||
constructor (message = 'Connection failed') { | ||
super(message) | ||
this.name = 'ConnectionFailedError' | ||
} | ||
} | ||
export class StreamResetError extends Error { | ||
constructor (message = 'The stream has been reset') { | ||
super(message) | ||
this.name = 'StreamResetError' | ||
} | ||
} | ||
export class StreamStateError extends Error { | ||
constructor (message = 'The stream is in an invalid state') { | ||
super(message) | ||
this.name = 'StreamStateError' | ||
} | ||
} | ||
export class NotFoundError extends Error { | ||
constructor (message = 'Not found') { | ||
super(message) | ||
this.name = 'NotFoundError' | ||
} | ||
} | ||
export class InvalidPeerIdError extends Error { | ||
constructor (message = 'Invalid PeerID') { | ||
super(message) | ||
this.name = 'InvalidPeerIdError' | ||
} | ||
} | ||
export class InvalidMultiaddrError extends Error { | ||
constructor (message = 'Invalid multiaddr') { | ||
super(message) | ||
this.name = 'InvalidMultiaddrError' | ||
} | ||
} | ||
export class InvalidCIDError extends Error { | ||
constructor (message = 'Invalid CID') { | ||
super(message) | ||
this.name = 'InvalidCIDError' | ||
} | ||
} | ||
export class InvalidMultihashError extends Error { | ||
constructor (message = 'Invalid Multihash') { | ||
super(message) | ||
this.name = 'InvalidMultihashError' | ||
} | ||
} | ||
export class UnsupportedProtocolError extends Error { | ||
constructor (message = 'Unsupported protocol error') { | ||
super(message) | ||
this.name = 'UnsupportedProtocolError' | ||
} | ||
} | ||
/** | ||
* An invalid or malformed message was encountered during a protocol exchange | ||
*/ | ||
export class InvalidMessageError extends Error { | ||
constructor (message = 'Invalid message') { | ||
super(message) | ||
this.name = 'InvalidMessageError' | ||
} | ||
} | ||
export class ProtocolError extends Error { | ||
constructor (message = 'Protocol error') { | ||
super(message) | ||
this.name = 'ProtocolError' | ||
} | ||
} | ||
export class TimeoutError extends Error { | ||
constructor (message = 'Timed out') { | ||
super(message) | ||
this.name = 'TimeoutError' | ||
} | ||
} | ||
export class NotStartedError extends Error { | ||
constructor (message = 'Not started') { | ||
super(message) | ||
this.name = 'NotStartedError' | ||
} | ||
} | ||
export class AlreadyStartedError extends Error { | ||
constructor (message = 'Already started') { | ||
super(message) | ||
this.name = 'AlreadyStartedError' | ||
} | ||
} | ||
export class DialError extends Error { | ||
constructor (message = 'Dial error') { | ||
super(message) | ||
this.name = 'DialError' | ||
} | ||
} | ||
export class ListenError extends Error { | ||
constructor (message = 'Listen error') { | ||
super(message) | ||
this.name = 'ListenError' | ||
} | ||
} | ||
export class LimitedConnectionError extends Error { | ||
constructor (message = 'Limited connection') { | ||
super(message) | ||
this.name = 'LimitedConnectionError' | ||
} | ||
} | ||
export class TooManyInboundProtocolStreamsError extends Error { | ||
constructor (message = 'Too many inbound protocol streams') { | ||
super(message) | ||
this.name = 'TooManyInboundProtocolStreamsError' | ||
} | ||
} | ||
export class TooManyOutboundProtocolStreamsError extends Error { | ||
constructor (message = 'Too many outbound protocol streams') { | ||
super(message) | ||
this.name = 'TooManyOutboundProtocolStreamsError' | ||
} | ||
} | ||
/** | ||
* Thrown when and attempt to operate on an unsupported key was made | ||
*/ | ||
export class UnsupportedKeyTypeError extends Error { | ||
constructor (message = 'Unsupported key type') { | ||
super(message) | ||
this.name = 'UnsupportedKeyTypeError' | ||
} | ||
} |
@@ -107,3 +107,1 @@ import { setMaxListeners } from './events.js' | ||
} | ||
export const CustomEvent = globalThis.CustomEvent |
@@ -20,4 +20,5 @@ /** | ||
import type { TypedEventTarget } from './event-target.js' | ||
import type { Ed25519PublicKey, PublicKey, RSAPublicKey, Secp256k1PublicKey } from './keys/index.js' | ||
import type { Metrics } from './metrics/index.js' | ||
import type { PeerId } from './peer-id/index.js' | ||
import type { Ed25519PeerId, PeerId, RSAPeerId, Secp256k1PeerId, URLPeerId } from './peer-id/index.js' | ||
import type { PeerInfo } from './peer-info/index.js' | ||
@@ -335,3 +336,3 @@ import type { PeerRouting } from './peer-routing/index.js' | ||
*/ | ||
runOnTransientConnection?: boolean | ||
runOnLimitedConnection?: boolean | ||
} | ||
@@ -352,3 +353,6 @@ | ||
export interface DialOptions extends AbortOptions, ProgressOptions { | ||
/** | ||
* If true, open a new connection to the remote even if one already exists | ||
*/ | ||
force?: boolean | ||
} | ||
@@ -648,3 +652,7 @@ | ||
*/ | ||
getPublicKey(peer: PeerId, options?: AbortOptions): Promise<Uint8Array> | ||
getPublicKey(peer: Ed25519PeerId, options?: AbortOptions): Promise<Ed25519PublicKey> | ||
getPublicKey(peer: Secp256k1PeerId, options?: AbortOptions): Promise<Secp256k1PublicKey> | ||
getPublicKey(peer: RSAPeerId, options?: AbortOptions): Promise<RSAPublicKey> | ||
getPublicKey(peer: URLPeerId, options?: AbortOptions): Promise<never> | ||
getPublicKey(peer: PeerId, options?: AbortOptions): Promise<PublicKey> | ||
@@ -651,0 +659,0 @@ /** |
@@ -0,39 +1,94 @@ | ||
import type { CID } from 'multiformats/cid' | ||
import type { MultihashDigest } from 'multiformats/hashes/interface' | ||
import type { Uint8ArrayList } from 'uint8arraylist' | ||
export interface PublicKey<Type extends KeyType = 'Ed25519'> { | ||
readonly bytes: Uint8Array | ||
export type KeyType = 'RSA' | 'Ed25519' | 'secp256k1' | ||
interface PublicKeyBase<KeyType extends string, DigestCode extends number = number> { | ||
/** | ||
* The type of this key | ||
*/ | ||
readonly type: KeyType | ||
/** | ||
* The raw public key bytes (for Ed25519 and secp256k1 keys) or PKIX in ASN1 | ||
* DER format (for RSA keys) | ||
*/ | ||
readonly raw: Uint8Array | ||
/** | ||
* Returns `true` if the passed object matches this key | ||
*/ | ||
equals(key?: any): boolean | ||
/** | ||
* 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). | ||
*/ | ||
toMultihash(): MultihashDigest<DigestCode> | ||
/** | ||
* 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). | ||
*/ | ||
toCID(): CID<unknown, 0x72, DigestCode, 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> | ||
marshal(): Uint8Array | ||
equals(key: PublicKey<Type>): boolean | ||
hash(): Uint8Array | Promise<Uint8Array> | ||
/** | ||
* Returns this key as a multihash with base58btc encoding | ||
*/ | ||
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 | ||
/** | ||
* Generic private key interface | ||
*/ | ||
export interface PrivateKey<Type extends KeyType = 'Ed25519'> { | ||
readonly public: PublicKey<Type> | ||
readonly bytes: Uint8Array | ||
sign(data: Uint8Array | Uint8ArrayList): Uint8Array | Promise<Uint8Array> | ||
marshal(): Uint8Array | ||
equals(key: PrivateKey<Type>): boolean | ||
hash(): Uint8Array | Promise<Uint8Array> | ||
interface PrivateKeyBase<KeyType extends string, PublicKeyType extends PublicKeyBase<KeyType>> { | ||
/** | ||
* Gets the ID of the key. | ||
* | ||
* The key id is the base58 encoding of the SHA-256 multihash of its public key. | ||
* The public key is a protobuf encoding containing a type and the DER encoding | ||
* of the PKCS SubjectPublicKeyInfo. | ||
* The type of this key | ||
*/ | ||
id(): Promise<string> | ||
readonly type: KeyType | ||
/** | ||
* Exports the password protected key in the format specified. | ||
* The public key that corresponds to this private key | ||
*/ | ||
export(password: string, format?: 'pkcs-8' | string): Promise<string> | ||
readonly publicKey: PublicKeyType | ||
/** | ||
* The raw public key bytes (for Ed25519 and secp256k1 keys) or PKIX in ASN1 | ||
* DER format (for RSA keys) | ||
*/ | ||
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 const Ed25519 = 'Ed25519' | ||
export const RSA = 'RSA' | ||
export const secp256k1 = 'secp256k1' | ||
export type KeyType = typeof Ed25519 | typeof RSA | typeof secp256k1 | ||
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 |
@@ -79,19 +79,19 @@ import type { MultiaddrConnection, Stream, Connection } from '../connection/index.js' | ||
*/ | ||
export interface MetricGroup { | ||
export interface MetricGroup<T extends string = any> { | ||
/** | ||
* Update the stored metric group to the passed value | ||
*/ | ||
update(values: Record<string, number>): void | ||
update(values: Partial<Record<T, number>>): void | ||
/** | ||
* Increment the metric group keys by the passed number or | ||
* any non-numeric value to increment by 1 | ||
* `true` to increment by 1 | ||
*/ | ||
increment(values: Record<string, number | unknown>): void | ||
increment(values: Partial<Record<T, number | true>>): void | ||
/** | ||
* Decrement the metric group keys by the passed number or | ||
* any non-numeric value to decrement by 1 | ||
* `true` to decrement by 1 | ||
*/ | ||
decrement(values: Record<string, number | unknown>): void | ||
decrement(values: Partial<Record<T, number | true>>): void | ||
@@ -132,3 +132,3 @@ /** | ||
*/ | ||
export interface CounterGroup { | ||
export interface CounterGroup<T extends string = any> { | ||
/** | ||
@@ -138,3 +138,3 @@ * Increment the metric group keys by the passed number or | ||
*/ | ||
increment(values: Record<string, number | unknown>): void | ||
increment(values: Partial<Record<T, number | true>>): void | ||
@@ -141,0 +141,0 @@ /** |
@@ -1,2 +0,2 @@ | ||
import type { KeyType } from '../keys/index.js' | ||
import type { Ed25519PublicKey, KeyType, RSAPublicKey, Secp256k1PublicKey } from '../keys/index.js' | ||
import type { CID } from 'multiformats/cid' | ||
@@ -7,37 +7,158 @@ import type { MultihashDigest } from 'multiformats/hashes/interface' | ||
export interface RSAPeerId extends PeerId { | ||
/** | ||
* A PeerId generated from an RSA public key - it is a base58btc encoded sha-256 | ||
* hash of the public key. | ||
* | ||
* RSA public keys are too large to pass around freely, instead Ed25519 or | ||
* secp256k1 should be preferred as they can embed their public key in the | ||
* PeerId itself. | ||
* | ||
* @deprecated Ed25519 or secp256k1 keys are preferred to RSA | ||
*/ | ||
export interface RSAPeerId { | ||
readonly type: 'RSA' | ||
readonly publicKey?: Uint8Array | ||
/** | ||
* RSA public keys are too large to embed in the multihash commonly used to | ||
* refer to peers, so this will only be defined if the public key has | ||
* previously been found through a routing query or during normal protocol | ||
* operations | ||
*/ | ||
readonly publicKey?: RSAPublicKey | ||
/** | ||
* Returns the multihash from `toMultihash()` as a base58btc encoded string | ||
*/ | ||
toString(): string | ||
/** | ||
* Returns a multihash, the digest of which is the SHA2-256 hash of the public | ||
* key | ||
*/ | ||
toMultihash(): MultihashDigest<0x12> | ||
/** | ||
* Returns a CID with the libp2p key code and the same multihash as | ||
* `toMultihash()` | ||
*/ | ||
toCID(): CID<Uint8Array, 0x72, 0x12, 1> | ||
/** | ||
* Returns true if the passed argument is equivalent to this PeerId | ||
*/ | ||
equals(other?: any): boolean | ||
} | ||
export interface Ed25519PeerId extends PeerId { | ||
export interface Ed25519PeerId { | ||
readonly type: 'Ed25519' | ||
readonly publicKey: Uint8Array | ||
/** | ||
* This will always be defined as the public key is embedded in the multihash | ||
* of this PeerId | ||
*/ | ||
readonly publicKey: Ed25519PublicKey | ||
/** | ||
* Returns the multihash from `toMultihash()` as a base58btc encoded string | ||
*/ | ||
toString(): string | ||
/** | ||
* Returns a multihash, the digest of which is the protobuf-encoded public key | ||
* encoded as an identity hash | ||
*/ | ||
toMultihash(): MultihashDigest<0x0> | ||
/** | ||
* Returns a CID with the libp2p key code and the same multihash as | ||
* `toMultihash()` | ||
*/ | ||
toCID(): CID<Uint8Array, 0x72, 0x0, 1> | ||
/** | ||
* Returns true if the passed argument is equivalent to this PeerId | ||
*/ | ||
equals(other?: any): boolean | ||
} | ||
export interface Secp256k1PeerId extends PeerId { | ||
export interface Secp256k1PeerId { | ||
readonly type: 'secp256k1' | ||
readonly publicKey: Uint8Array | ||
/** | ||
* This will always be defined as the public key is embedded in the multihash | ||
* of this PeerId | ||
*/ | ||
readonly publicKey: Secp256k1PublicKey | ||
/** | ||
* Returns the multihash from `toMultihash()` as a base58btc encoded string | ||
*/ | ||
toString(): string | ||
/** | ||
* Returns a multihash, the digest of which is the protobuf-encoded public key | ||
* encoded as an identity hash | ||
*/ | ||
toMultihash(): MultihashDigest<0x0> | ||
/** | ||
* Returns a CID with the libp2p key code and the same multihash as | ||
* `toMultihash()` | ||
*/ | ||
toCID(): CID<Uint8Array, 0x72, 0x0, 1> | ||
/** | ||
* Returns true if the passed argument is equivalent to this PeerId | ||
*/ | ||
equals(other?: any): boolean | ||
} | ||
export interface URLPeerId extends PeerId { | ||
export interface URLPeerId { | ||
readonly type: 'url' | ||
} | ||
export interface PeerId { | ||
type: PeerIdType | ||
multihash: MultihashDigest | ||
privateKey?: Uint8Array | ||
publicKey?: Uint8Array | ||
/** | ||
* This will always be undefined as URL Peers do not have public keys | ||
*/ | ||
readonly publicKey: undefined | ||
/** | ||
* Returns CID from `toCID()` encoded as a base36 string | ||
*/ | ||
toString(): string | ||
toCID(): CID | ||
toBytes(): Uint8Array | ||
equals(other?: PeerId | Uint8Array | string): boolean | ||
/** | ||
* Returns a multihash, the digest of which is the URL encoded as an identity | ||
* hash | ||
*/ | ||
toMultihash(): MultihashDigest<0x0> | ||
/** | ||
* Returns a CID with the Transport IPFS Gateway HTTP code and the same | ||
* multihash as `toMultihash()` | ||
*/ | ||
toCID(): CID<Uint8Array, 0x0920, 0x0, 1> | ||
/** | ||
* Returns true if the passed argument is equivalent to this PeerId | ||
*/ | ||
equals(other?: any): boolean | ||
} | ||
/** | ||
* This is a union of all known PeerId types - use the `.type` field to | ||
* disambiguate them | ||
*/ | ||
export type PeerId = RSAPeerId | Ed25519PeerId | Secp256k1PeerId | URLPeerId | ||
/** | ||
* All PeerId implementations must use this symbol as the name of a property | ||
* with a boolean `true` value | ||
*/ | ||
export const peerIdSymbol = Symbol.for('@libp2p/peer-id') | ||
export function isPeerId (other: any): other is PeerId { | ||
return other != null && Boolean(other[peerIdSymbol]) | ||
/** | ||
* Returns true if the passed argument is a PeerId implementation | ||
*/ | ||
export function isPeerId (other?: any): other is PeerId { | ||
return Boolean(other?.[peerIdSymbol]) | ||
} |
@@ -0,1 +1,2 @@ | ||
import type { PublicKey } from '../keys/index.js' | ||
import type { PeerId } from '../peer-id/index.js' | ||
@@ -94,5 +95,7 @@ import type { Multiaddr } from '@multiformats/multiaddr' | ||
/** | ||
* If this Peer has an RSA key, it's public key can be set with this property | ||
* If this Peer has an RSA key, it's public key can be set with this property. | ||
* | ||
* The byte array should be the protobuf encoded form of the public key. | ||
*/ | ||
publicKey?: Uint8Array | ||
publicKey?: PublicKey | ||
@@ -99,0 +102,0 @@ /** |
import type { Stream } from '../connection/index.js' | ||
import type { TypedEventTarget } from '../event-target.js' | ||
import type { PublicKey } from '../keys/index.js' | ||
import type { PeerId } from '../peer-id/index.js' | ||
@@ -38,3 +39,3 @@ import type { Pushable } from 'it-pushable' | ||
signature: Uint8Array | ||
key: Uint8Array | ||
key: PublicKey | ||
} | ||
@@ -41,0 +42,0 @@ |
@@ -1,2 +0,2 @@ | ||
import type { PeerId } from '../peer-id/index.js' | ||
import type { PublicKey } from '../keys/index.js' | ||
import type { Uint8ArrayList } from 'uint8arraylist' | ||
@@ -27,3 +27,3 @@ | ||
export interface Envelope { | ||
peerId: PeerId | ||
publicKey: PublicKey | ||
payloadType: Uint8Array | Uint8ArrayList | ||
@@ -30,0 +30,0 @@ payload: Uint8Array |
@@ -24,6 +24,6 @@ import type { Connection, Stream } from '../connection/index.js' | ||
/** | ||
* Opt-in to running over a transient connection - one that has time/data limits | ||
* placed on it. | ||
* Opt-in to running over connections with limits on how much data can be | ||
* transferred or how long it can be open for. | ||
*/ | ||
runOnTransientConnection?: boolean | ||
runOnLimitedConnection?: boolean | ||
} | ||
@@ -30,0 +30,0 @@ |
@@ -30,8 +30,9 @@ import type { Connection } from '../connection/index.js' | ||
/** | ||
* If true, invoke `onConnect` for this topology on transient (e.g. short-lived | ||
* and/or data-limited) connections | ||
* If true, invoke `onConnect` for this topology on limited connections, e.g. | ||
* ones with limits on how much data can be transferred or how long they can | ||
* be open for. | ||
* | ||
* @default false | ||
*/ | ||
notifyOnTransient?: boolean | ||
notifyOnLimitedConnection?: boolean | ||
@@ -38,0 +39,0 @@ /** |
@@ -1,2 +0,2 @@ | ||
import type { Connection, MultiaddrConnection } from '../connection/index.js' | ||
import type { Connection, ConnectionLimits, MultiaddrConnection } from '../connection/index.js' | ||
import type { TypedEventTarget } from '../event-target.js' | ||
@@ -103,12 +103,7 @@ import type { AbortOptions } from '../index.js' | ||
export interface UpgraderOptions<ConnectionUpgradeEvents extends ProgressEvent = ProgressEvent> extends ProgressOptions<ConnectionUpgradeEvents> { | ||
export interface UpgraderOptions<ConnectionUpgradeEvents extends ProgressEvent = ProgressEvent> extends ProgressOptions<ConnectionUpgradeEvents>, AbortOptions { | ||
skipEncryption?: boolean | ||
skipProtection?: boolean | ||
muxerFactory?: StreamMuxerFactory | ||
/** | ||
* The passed MultiaddrConnection has limits place on duration and/or data | ||
* transfer amounts so is not expected to be open for very long. | ||
*/ | ||
transient?: boolean | ||
limits?: ConnectionLimits | ||
} | ||
@@ -115,0 +110,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
266392
6468