@libp2p/interfaces
Advanced tools
Comparing version 1.3.6 to 1.3.7
@@ -5,2 +5,3 @@ import type { PeerId } from '../peer-id/index.js'; | ||
import type { EventEmitter, Startable } from '../index.js'; | ||
import type { Stream } from '../connection/index.js'; | ||
/** | ||
@@ -14,3 +15,3 @@ * On the producing side: | ||
*/ | ||
export declare type StrictSign = 'StrictSign'; | ||
export declare const StrictSign = "StrictSign"; | ||
/** | ||
@@ -26,8 +27,7 @@ * On the producing side: | ||
*/ | ||
export declare type StrictNoSign = 'StrictNoSign'; | ||
export declare const StrictNoSign = "StrictNoSign"; | ||
export interface Message { | ||
from?: Uint8Array; | ||
receivedFrom: string; | ||
from: PeerId; | ||
topicIDs: string[]; | ||
seqno?: Uint8Array; | ||
seqno?: BigInt; | ||
data: Uint8Array; | ||
@@ -37,16 +37,38 @@ signature?: Uint8Array; | ||
} | ||
export interface PeerStreams { | ||
export interface RPCMessage { | ||
from: Uint8Array; | ||
data: Uint8Array; | ||
topicIDs: string[]; | ||
seqno?: Uint8Array; | ||
signature?: Uint8Array; | ||
key?: Uint8Array; | ||
} | ||
export interface RPCSubscription { | ||
subscribe: boolean; | ||
topicID: string; | ||
} | ||
export interface RPC { | ||
subscriptions: RPCSubscription[]; | ||
msgs: RPCMessage[]; | ||
} | ||
export interface PeerStreams extends EventEmitter<PeerStreamEvents> { | ||
id: PeerId; | ||
protocol: string; | ||
outboundStream: Pushable<Uint8Array> | undefined; | ||
inboundStream: AsyncIterable<Uint8Array> | undefined; | ||
outboundStream?: Pushable<Uint8Array>; | ||
inboundStream?: AsyncIterable<Uint8Array>; | ||
isWritable: boolean; | ||
close: () => void; | ||
write: (buf: Uint8Array) => void; | ||
attachInboundStream: (stream: Stream) => AsyncIterable<Uint8Array>; | ||
attachOutboundStream: (stream: Stream) => Promise<Pushable<Uint8Array>>; | ||
} | ||
export interface PubsubOptions { | ||
export interface PubSubOptions { | ||
registrar: Registrar; | ||
peerId: PeerId; | ||
debugName?: string; | ||
multicodecs: string[]; | ||
libp2p: any; | ||
multicodecs?: string[]; | ||
/** | ||
* defines how signatures should be handled | ||
*/ | ||
globalSignaturePolicy?: StrictSign | StrictNoSign; | ||
globalSignaturePolicy?: typeof StrictSign | typeof StrictNoSign; | ||
/** | ||
@@ -73,19 +95,17 @@ * if can relay messages not subscribed | ||
} | ||
export interface PubsubEvents { | ||
export interface PubSubEvents { | ||
'pubsub:subscription-change': CustomEvent<SubscriptionChangeData>; | ||
} | ||
export interface PubSub<EventMap extends PubsubEvents> extends EventEmitter<EventMap>, Startable { | ||
peerId: PeerId; | ||
started: boolean; | ||
peers: Map<string, PeerStreams>; | ||
subscriptions: Set<string>; | ||
topics: Map<string, Set<string>>; | ||
globalSignaturePolicy: StrictSign | StrictNoSign; | ||
registrar: Registrar; | ||
export interface PubSub<EventMap extends PubSubEvents> extends EventEmitter<EventMap>, Startable { | ||
globalSignaturePolicy: typeof StrictSign | typeof StrictNoSign; | ||
multicodecs: string[]; | ||
getPeers: () => PeerId[]; | ||
getTopics: () => string[]; | ||
subscribe: (topic: string) => void; | ||
getSubscribers: (topic: string) => string[]; | ||
getSubscribers: (topic: string) => PeerId[]; | ||
unsubscribe: (topic: string) => void; | ||
publish: (topic: string, data: Uint8Array) => Promise<void>; | ||
validate: (message: Message) => Promise<void>; | ||
processRpc: (from: PeerId, peerStreams: PeerStreams, rpc: RPC) => Promise<boolean>; | ||
emitMessage: (message: Message) => void; | ||
} | ||
@@ -92,0 +112,0 @@ export interface PeerStreamEvents { |
@@ -1,2 +0,21 @@ | ||
export {}; | ||
/** | ||
* On the producing side: | ||
* * Build messages with the signature, key (from may be enough for certain inlineable public key types), from and seqno fields. | ||
* | ||
* On the consuming side: | ||
* * Enforce the fields to be present, reject otherwise. | ||
* * Propagate only if the fields are valid and signature can be verified, reject otherwise. | ||
*/ | ||
export const StrictSign = 'StrictSign'; | ||
/** | ||
* On the producing side: | ||
* * Build messages without the signature, key, from and seqno fields. | ||
* * The corresponding protobuf key-value pairs are absent from the marshalled message, not just empty. | ||
* | ||
* On the consuming side: | ||
* * Enforce the fields to be absent, reject otherwise. | ||
* * Propagate only if the fields are absent, reject otherwise. | ||
* * A message_id function will not be able to use the above fields, and should instead rely on the data field. A commonplace strategy is to calculate a hash. | ||
*/ | ||
export const StrictNoSign = 'StrictNoSign'; | ||
//# sourceMappingURL=index.js.map |
@@ -20,5 +20,6 @@ import type { EventEmitter } from '../index.js'; | ||
export interface Registrar { | ||
getProtocols: () => string[]; | ||
handle: (protocol: string | string[], handler: StreamHandler) => Promise<string>; | ||
unhandle: (id: string) => Promise<void>; | ||
getHandlers: (protocol: string) => StreamHandler[]; | ||
getHandler: (protocol: string) => StreamHandler; | ||
register: (protocols: string | string[], topology: Topology) => string; | ||
@@ -25,0 +26,0 @@ unregister: (id: string) => void; |
{ | ||
"name": "@libp2p/interfaces", | ||
"version": "1.3.6", | ||
"version": "1.3.7", | ||
"description": "Interfaces for JS Libp2p", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0 OR MIT", |
@@ -5,2 +5,3 @@ import type { PeerId } from '../peer-id/index.js' | ||
import type { EventEmitter, Startable } from '../index.js' | ||
import type { Stream } from '../connection/index.js' | ||
@@ -15,3 +16,3 @@ /** | ||
*/ | ||
export type StrictSign = 'StrictSign' | ||
export const StrictSign = 'StrictSign' | ||
@@ -28,9 +29,8 @@ /** | ||
*/ | ||
export type StrictNoSign = 'StrictNoSign' | ||
export const StrictNoSign = 'StrictNoSign' | ||
export interface Message { | ||
from?: Uint8Array | ||
receivedFrom: string | ||
from: PeerId | ||
topicIDs: string[] | ||
seqno?: Uint8Array | ||
seqno?: BigInt | ||
data: Uint8Array | ||
@@ -41,13 +41,39 @@ signature?: Uint8Array | ||
export interface PeerStreams { | ||
export interface RPCMessage { | ||
from: Uint8Array | ||
data: Uint8Array | ||
topicIDs: string[] | ||
seqno?: Uint8Array | ||
signature?: Uint8Array | ||
key?: Uint8Array | ||
} | ||
export interface RPCSubscription { | ||
subscribe: boolean | ||
topicID: string | ||
} | ||
export interface RPC { | ||
subscriptions: RPCSubscription[] | ||
msgs: RPCMessage[] | ||
} | ||
export interface PeerStreams extends EventEmitter<PeerStreamEvents> { | ||
id: PeerId | ||
protocol: string | ||
outboundStream: Pushable<Uint8Array> | undefined | ||
inboundStream: AsyncIterable<Uint8Array> | undefined | ||
outboundStream?: Pushable<Uint8Array> | ||
inboundStream?: AsyncIterable<Uint8Array> | ||
isWritable: boolean | ||
close: () => void | ||
write: (buf: Uint8Array) => void | ||
attachInboundStream: (stream: Stream) => AsyncIterable<Uint8Array> | ||
attachOutboundStream: (stream: Stream) => Promise<Pushable<Uint8Array>> | ||
} | ||
export interface PubsubOptions { | ||
export interface PubSubOptions { | ||
registrar: Registrar | ||
peerId: PeerId | ||
debugName?: string | ||
multicodecs: string[] | ||
libp2p: any | ||
multicodecs?: string[] | ||
@@ -57,3 +83,3 @@ /** | ||
*/ | ||
globalSignaturePolicy?: StrictSign | StrictNoSign | ||
globalSignaturePolicy?: typeof StrictSign | typeof StrictNoSign | ||
@@ -86,21 +112,20 @@ /** | ||
export interface PubsubEvents { | ||
export interface PubSubEvents { | ||
'pubsub:subscription-change': CustomEvent<SubscriptionChangeData> | ||
} | ||
export interface PubSub<EventMap extends PubsubEvents> extends EventEmitter<EventMap>, Startable { | ||
peerId: PeerId | ||
started: boolean | ||
peers: Map<string, PeerStreams> | ||
subscriptions: Set<string> | ||
topics: Map<string, Set<string>> | ||
globalSignaturePolicy: StrictSign | StrictNoSign | ||
registrar: Registrar | ||
export interface PubSub<EventMap extends PubSubEvents> extends EventEmitter<EventMap>, Startable { | ||
globalSignaturePolicy: typeof StrictSign | typeof StrictNoSign | ||
multicodecs: string[] | ||
getPeers: () => PeerId[] | ||
getTopics: () => string[] | ||
subscribe: (topic: string) => void | ||
getSubscribers: (topic: string) => string[] | ||
getSubscribers: (topic: string) => PeerId[] | ||
unsubscribe: (topic: string) => void | ||
publish: (topic: string, data: Uint8Array) => Promise<void> | ||
validate: (message: Message) => Promise<void> | ||
processRpc: (from: PeerId, peerStreams: PeerStreams, rpc: RPC) => Promise<boolean> | ||
emitMessage: (message: Message) => void | ||
} | ||
@@ -107,0 +132,0 @@ |
@@ -25,5 +25,6 @@ import type { EventEmitter } from '../index.js' | ||
export interface Registrar { | ||
getProtocols: () => string[] | ||
handle: (protocol: string | string[], handler: StreamHandler) => Promise<string> | ||
unhandle: (id: string) => Promise<void> | ||
getHandlers: (protocol: string) => StreamHandler[] | ||
getHandler: (protocol: string) => StreamHandler | ||
@@ -30,0 +31,0 @@ register: (protocols: string | string[], topology: Topology) => string |
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
1314130
2272