@libp2p/pubsub 7.0.1 → 7.0.3-42c1c097
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/index.min.js +13 -13
- package/dist/src/index.d.ts +6 -6
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +48 -9
- package/dist/src/index.js.map +1 -1
- package/dist/src/peer-streams.d.ts +5 -5
- package/dist/src/peer-streams.d.ts.map +1 -1
- package/dist/src/peer-streams.js +26 -3
- package/dist/src/peer-streams.js.map +1 -1
- package/dist/src/sign.d.ts +2 -2
- package/dist/src/sign.d.ts.map +1 -1
- package/dist/src/sign.js +3 -3
- package/dist/src/sign.js.map +1 -1
- package/dist/src/utils.d.ts +1 -1
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +3 -3
- package/dist/src/utils.js.map +1 -1
- package/package.json +25 -115
- package/src/index.ts +12 -12
- package/src/peer-streams.ts +7 -7
- package/src/sign.ts +5 -5
- package/src/utils.ts +4 -4
- package/dist/typedoc-urls.json +0 -16
package/src/index.ts
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
+
import { CodeError } from '@libp2p/interface/errors'
|
2
|
+
import { EventEmitter, CustomEvent } from '@libp2p/interface/events'
|
3
|
+
import { type PubSub, type Message, type StrictNoSign, type StrictSign, type PubSubInit, type PubSubEvents, type PeerStreams, type PubSubRPCMessage, type PubSubRPC, type PubSubRPCSubscription, type SubscriptionChangeData, type PublishResult, type TopicValidatorFn, TopicValidatorResult } from '@libp2p/interface/pubsub'
|
1
4
|
import { logger } from '@libp2p/logger'
|
2
|
-
import {
|
3
|
-
import {
|
5
|
+
import { PeerMap, PeerSet } from '@libp2p/peer-collections'
|
6
|
+
import { createTopology } from '@libp2p/topology'
|
4
7
|
import { pipe } from 'it-pipe'
|
5
8
|
import Queue from 'p-queue'
|
6
|
-
import { createTopology } from '@libp2p/topology'
|
7
9
|
import { codes } from './errors.js'
|
8
10
|
import { PeerStreams as PeerStreamsImpl } from './peer-streams.js'
|
9
|
-
import { toMessage, ensureArray, noSignMsgId, msgId, toRpcMessage, randomSeqno } from './utils.js'
|
10
11
|
import {
|
11
12
|
signMessage,
|
12
13
|
verifySignature
|
13
14
|
} from './sign.js'
|
14
|
-
import
|
15
|
-
import type {
|
16
|
-
import type {
|
17
|
-
import {
|
18
|
-
import { PeerMap, PeerSet } from '@libp2p/peer-collections'
|
15
|
+
import { toMessage, ensureArray, noSignMsgId, msgId, toRpcMessage, randomSeqno } from './utils.js'
|
16
|
+
import type { Connection } from '@libp2p/interface/connection'
|
17
|
+
import type { PeerId } from '@libp2p/interface/peer-id'
|
18
|
+
import type { IncomingStreamData, Registrar } from '@libp2p/interface-internal/registrar'
|
19
19
|
import type { Uint8ArrayList } from 'uint8arraylist'
|
20
20
|
|
21
21
|
const log = logger('libp2p:pubsub')
|
@@ -132,7 +132,7 @@ export abstract class PubSubBaseProtocol<Events extends Record<string, any> = Pu
|
|
132
132
|
onConnect: this._onPeerConnected,
|
133
133
|
onDisconnect: this._onPeerDisconnected
|
134
134
|
})
|
135
|
-
this._registrarTopologyIds = await Promise.all(this.multicodecs.map(async multicodec =>
|
135
|
+
this._registrarTopologyIds = await Promise.all(this.multicodecs.map(async multicodec => registrar.register(multicodec, topology)))
|
136
136
|
|
137
137
|
log('started')
|
138
138
|
this.started = true
|
@@ -589,9 +589,9 @@ export abstract class PubSubBaseProtocol<Events extends Record<string, any> = Pu
|
|
589
589
|
const signaturePolicy = this.globalSignaturePolicy
|
590
590
|
switch (signaturePolicy) {
|
591
591
|
case 'StrictSign':
|
592
|
-
return
|
592
|
+
return signMessage(this.components.peerId, message, this.encodeMessage.bind(this))
|
593
593
|
case 'StrictNoSign':
|
594
|
-
return
|
594
|
+
return Promise.resolve({
|
595
595
|
type: 'unsigned',
|
596
596
|
...message
|
597
597
|
})
|
package/src/peer-streams.ts
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
+
import { EventEmitter, CustomEvent } from '@libp2p/interface/events'
|
1
2
|
import { logger } from '@libp2p/logger'
|
2
|
-
import {
|
3
|
+
import { abortableSource } from 'abortable-iterator'
|
3
4
|
import * as lp from 'it-length-prefixed'
|
4
|
-
import { pushable } from 'it-pushable'
|
5
5
|
import { pipe } from 'it-pipe'
|
6
|
-
import {
|
7
|
-
import type { PeerId } from '@libp2p/interface-peer-id'
|
8
|
-
import type { Stream } from '@libp2p/interface-connection'
|
9
|
-
import type { Pushable } from 'it-pushable'
|
10
|
-
import type { PeerStreamEvents } from '@libp2p/interface-pubsub'
|
6
|
+
import { pushable } from 'it-pushable'
|
11
7
|
import { Uint8ArrayList } from 'uint8arraylist'
|
8
|
+
import type { Stream } from '@libp2p/interface/connection'
|
9
|
+
import type { PeerId } from '@libp2p/interface/peer-id'
|
10
|
+
import type { PeerStreamEvents } from '@libp2p/interface/pubsub'
|
11
|
+
import type { Pushable } from 'it-pushable'
|
12
12
|
|
13
13
|
const log = logger('libp2p-pubsub:peer-streams')
|
14
14
|
|
package/src/sign.ts
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
+
import { keys } from '@libp2p/crypto'
|
2
|
+
import { peerIdFromKeys } from '@libp2p/peer-id'
|
1
3
|
import { concat as uint8ArrayConcat } from 'uint8arrays/concat'
|
2
4
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
3
5
|
import { toRpcMessage } from './utils.js'
|
4
|
-
import type { PeerId } from '@libp2p/interface
|
5
|
-
import {
|
6
|
-
import type { PubSubRPCMessage, SignedMessage } from '@libp2p/interface-pubsub'
|
7
|
-
import { peerIdFromKeys } from '@libp2p/peer-id'
|
6
|
+
import type { PeerId } from '@libp2p/interface/peer-id'
|
7
|
+
import type { PubSubRPCMessage, SignedMessage } from '@libp2p/interface/pubsub'
|
8
8
|
|
9
9
|
export const SignPrefix = uint8ArrayFromString('libp2p-pubsub:')
|
10
10
|
|
@@ -73,7 +73,7 @@ export async function verifySignature (message: SignedMessage, encode: (rpc: Pub
|
|
73
73
|
const pubKey = keys.unmarshalPublicKey(pubKeyBytes)
|
74
74
|
|
75
75
|
// verify the base message
|
76
|
-
return
|
76
|
+
return pubKey.verify(bytes, message.signature)
|
77
77
|
}
|
78
78
|
|
79
79
|
/**
|
package/src/utils.ts
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
import { randomBytes } from '@libp2p/crypto'
|
2
|
+
import { CodeError } from '@libp2p/interface/errors'
|
3
|
+
import { peerIdFromBytes, peerIdFromKeys } from '@libp2p/peer-id'
|
4
|
+
import { sha256 } from 'multiformats/hashes/sha2'
|
2
5
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
3
6
|
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
|
4
|
-
import { sha256 } from 'multiformats/hashes/sha2'
|
5
|
-
import type { Message, PubSubRPCMessage } from '@libp2p/interface-pubsub'
|
6
|
-
import { peerIdFromBytes, peerIdFromKeys } from '@libp2p/peer-id'
|
7
7
|
import { codes } from './errors.js'
|
8
|
-
import {
|
8
|
+
import type { Message, PubSubRPCMessage } from '@libp2p/interface/pubsub'
|
9
9
|
|
10
10
|
/**
|
11
11
|
* Generate a random sequence number
|
package/dist/typedoc-urls.json
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"codes": "https://libp2p.github.io/js-libp2p-pubsub/variables/errors.codes.html",
|
3
|
-
"PubSubBaseProtocol": "https://libp2p.github.io/js-libp2p-pubsub/classes/index.PubSubBaseProtocol.html",
|
4
|
-
"PubSubComponents": "https://libp2p.github.io/js-libp2p-pubsub/interfaces/index.PubSubComponents.html",
|
5
|
-
"PeerStreams": "https://libp2p.github.io/js-libp2p-pubsub/classes/peer_streams.PeerStreams.html",
|
6
|
-
"PeerStreamsInit": "https://libp2p.github.io/js-libp2p-pubsub/interfaces/peer_streams.PeerStreamsInit.html",
|
7
|
-
"anyMatch": "https://libp2p.github.io/js-libp2p-pubsub/functions/utils.anyMatch.html",
|
8
|
-
"bigIntFromBytes": "https://libp2p.github.io/js-libp2p-pubsub/functions/utils.bigIntFromBytes.html",
|
9
|
-
"bigIntToBytes": "https://libp2p.github.io/js-libp2p-pubsub/functions/utils.bigIntToBytes.html",
|
10
|
-
"ensureArray": "https://libp2p.github.io/js-libp2p-pubsub/functions/utils.ensureArray.html",
|
11
|
-
"msgId": "https://libp2p.github.io/js-libp2p-pubsub/functions/utils.msgId.html",
|
12
|
-
"noSignMsgId": "https://libp2p.github.io/js-libp2p-pubsub/functions/utils.noSignMsgId.html",
|
13
|
-
"randomSeqno": "https://libp2p.github.io/js-libp2p-pubsub/functions/utils.randomSeqno.html",
|
14
|
-
"toMessage": "https://libp2p.github.io/js-libp2p-pubsub/functions/utils.toMessage.html",
|
15
|
-
"toRpcMessage": "https://libp2p.github.io/js-libp2p-pubsub/functions/utils.toRpcMessage.html"
|
16
|
-
}
|