@libp2p/pubsub 6.0.3 → 6.0.5
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/dist/index.min.js +9 -9
- package/dist/src/index.d.ts +2 -6
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +16 -12
- package/dist/src/index.js.map +1 -1
- package/dist/src/peer-streams.d.ts.map +1 -1
- package/dist/src/peer-streams.js +3 -3
- package/dist/src/peer-streams.js.map +1 -1
- package/dist/src/sign.d.ts.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.map +1 -1
- package/package.json +6 -8
- package/src/index.ts +35 -31
- package/src/peer-streams.ts +9 -9
- package/src/sign.ts +2 -2
- package/src/utils.ts +4 -4
package/src/peer-streams.ts
CHANGED
|
@@ -58,14 +58,14 @@ export class PeerStreams extends EventEmitter<PeerStreamEvents> {
|
|
|
58
58
|
/**
|
|
59
59
|
* Do we have a connection to read from?
|
|
60
60
|
*/
|
|
61
|
-
get isReadable () {
|
|
61
|
+
get isReadable (): boolean {
|
|
62
62
|
return Boolean(this.inboundStream)
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
/**
|
|
66
66
|
* Do we have a connection to write on?
|
|
67
67
|
*/
|
|
68
|
-
get isWritable () {
|
|
68
|
+
get isWritable (): boolean {
|
|
69
69
|
return Boolean(this.outboundStream)
|
|
70
70
|
}
|
|
71
71
|
|
|
@@ -73,7 +73,7 @@ export class PeerStreams extends EventEmitter<PeerStreamEvents> {
|
|
|
73
73
|
* Send a message to this peer.
|
|
74
74
|
* Throws if there is no `stream` to write to available.
|
|
75
75
|
*/
|
|
76
|
-
write (data: Uint8Array | Uint8ArrayList) {
|
|
76
|
+
write (data: Uint8Array | Uint8ArrayList): void {
|
|
77
77
|
if (this.outboundStream == null) {
|
|
78
78
|
const id = this.id.toString()
|
|
79
79
|
throw new Error('No writable connection to ' + id)
|
|
@@ -85,7 +85,7 @@ export class PeerStreams extends EventEmitter<PeerStreamEvents> {
|
|
|
85
85
|
/**
|
|
86
86
|
* Attach a raw inbound stream and setup a read stream
|
|
87
87
|
*/
|
|
88
|
-
attachInboundStream (stream: Stream) {
|
|
88
|
+
attachInboundStream (stream: Stream): AsyncIterable<Uint8ArrayList> {
|
|
89
89
|
// Create and attach a new inbound stream
|
|
90
90
|
// The inbound stream is:
|
|
91
91
|
// - abortable, set to only return on abort, rather than throw
|
|
@@ -94,7 +94,7 @@ export class PeerStreams extends EventEmitter<PeerStreamEvents> {
|
|
|
94
94
|
this.inboundStream = abortableSource(
|
|
95
95
|
pipe(
|
|
96
96
|
this._rawInboundStream,
|
|
97
|
-
lp.decode()
|
|
97
|
+
(source) => lp.decode(source)
|
|
98
98
|
),
|
|
99
99
|
this._inboundAbortController.signal,
|
|
100
100
|
{ returnOnAbort: true }
|
|
@@ -107,12 +107,12 @@ export class PeerStreams extends EventEmitter<PeerStreamEvents> {
|
|
|
107
107
|
/**
|
|
108
108
|
* Attach a raw outbound stream and setup a write stream
|
|
109
109
|
*/
|
|
110
|
-
async attachOutboundStream (stream: Stream) {
|
|
110
|
+
async attachOutboundStream (stream: Stream): Promise<Pushable<Uint8ArrayList>> {
|
|
111
111
|
// If an outbound stream already exists, gently close it
|
|
112
112
|
const _prevStream = this.outboundStream
|
|
113
113
|
if (this.outboundStream != null) {
|
|
114
114
|
// End the stream without emitting a close event
|
|
115
|
-
|
|
115
|
+
this.outboundStream.end()
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
this._rawOutboundStream = stream
|
|
@@ -134,7 +134,7 @@ export class PeerStreams extends EventEmitter<PeerStreamEvents> {
|
|
|
134
134
|
|
|
135
135
|
pipe(
|
|
136
136
|
this.outboundStream,
|
|
137
|
-
lp.encode(),
|
|
137
|
+
(source) => lp.encode(source),
|
|
138
138
|
this._rawOutboundStream
|
|
139
139
|
).catch((err: Error) => {
|
|
140
140
|
log.error(err)
|
|
@@ -151,7 +151,7 @@ export class PeerStreams extends EventEmitter<PeerStreamEvents> {
|
|
|
151
151
|
/**
|
|
152
152
|
* Closes the open connection to peer
|
|
153
153
|
*/
|
|
154
|
-
close () {
|
|
154
|
+
close (): void {
|
|
155
155
|
if (this.closed) {
|
|
156
156
|
return
|
|
157
157
|
}
|
package/src/sign.ts
CHANGED
|
@@ -45,7 +45,7 @@ export async function signMessage (peerId: PeerId, message: { from: PeerId, topi
|
|
|
45
45
|
/**
|
|
46
46
|
* Verifies the signature of the given message
|
|
47
47
|
*/
|
|
48
|
-
export async function verifySignature (message: SignedMessage, encode: (rpc: PubSubRPCMessage) => Uint8Array) {
|
|
48
|
+
export async function verifySignature (message: SignedMessage, encode: (rpc: PubSubRPCMessage) => Uint8Array): Promise<boolean> {
|
|
49
49
|
if (message.type !== 'signed') {
|
|
50
50
|
throw new Error('Message type must be "signed" to be verified')
|
|
51
51
|
}
|
|
@@ -80,7 +80,7 @@ export async function verifySignature (message: SignedMessage, encode: (rpc: Pub
|
|
|
80
80
|
* Returns the PublicKey associated with the given message.
|
|
81
81
|
* If no valid PublicKey can be retrieved an error will be returned.
|
|
82
82
|
*/
|
|
83
|
-
export async function messagePublicKey (message: SignedMessage) {
|
|
83
|
+
export async function messagePublicKey (message: SignedMessage): Promise<Uint8Array> {
|
|
84
84
|
if (message.type !== 'signed') {
|
|
85
85
|
throw new Error('Message type must be "signed" to have a public key')
|
|
86
86
|
}
|
package/src/utils.ts
CHANGED
|
@@ -17,7 +17,7 @@ export function randomSeqno (): bigint {
|
|
|
17
17
|
/**
|
|
18
18
|
* Generate a message id, based on the `key` and `seqno`
|
|
19
19
|
*/
|
|
20
|
-
export const msgId = (key: Uint8Array, seqno: bigint) => {
|
|
20
|
+
export const msgId = (key: Uint8Array, seqno: bigint): Uint8Array => {
|
|
21
21
|
const seqnoBytes = uint8ArrayFromString(seqno.toString(16).padStart(16, '0'), 'base16')
|
|
22
22
|
|
|
23
23
|
const msgId = new Uint8Array(key.length + seqnoBytes.length)
|
|
@@ -30,7 +30,7 @@ export const msgId = (key: Uint8Array, seqno: bigint) => {
|
|
|
30
30
|
/**
|
|
31
31
|
* Generate a message id, based on message `data`
|
|
32
32
|
*/
|
|
33
|
-
export const noSignMsgId = (data: Uint8Array) => {
|
|
33
|
+
export const noSignMsgId = (data: Uint8Array): Uint8Array | Promise<Uint8Array> => {
|
|
34
34
|
return sha256.encode(data)
|
|
35
35
|
}
|
|
36
36
|
|
|
@@ -38,7 +38,7 @@ export const noSignMsgId = (data: Uint8Array) => {
|
|
|
38
38
|
* Check if any member of the first set is also a member
|
|
39
39
|
* of the second set
|
|
40
40
|
*/
|
|
41
|
-
export const anyMatch = (a: Set<number> | number[], b: Set<number> | number[]) => {
|
|
41
|
+
export const anyMatch = (a: Set<number> | number[], b: Set<number> | number[]): boolean => {
|
|
42
42
|
let bHas
|
|
43
43
|
if (Array.isArray(b)) {
|
|
44
44
|
bHas = (val: number) => b.includes(val)
|
|
@@ -58,7 +58,7 @@ export const anyMatch = (a: Set<number> | number[], b: Set<number> | number[]) =
|
|
|
58
58
|
/**
|
|
59
59
|
* Make everything an array
|
|
60
60
|
*/
|
|
61
|
-
export const ensureArray = function <T> (maybeArray: T | T[]) {
|
|
61
|
+
export const ensureArray = function <T> (maybeArray: T | T[]): T[] {
|
|
62
62
|
if (!Array.isArray(maybeArray)) {
|
|
63
63
|
return [maybeArray]
|
|
64
64
|
}
|