@libp2p/pubsub 1.2.3 → 1.2.7

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.
@@ -11,7 +11,7 @@ export declare function signMessage(peerId: PeerId, message: Message): Promise<M
11
11
  export declare function verifySignature(message: Message): Promise<boolean>;
12
12
  /**
13
13
  * Returns the PublicKey associated with the given message.
14
- * If no, valid PublicKey can be retrieved an error will be returned.
14
+ * If no valid PublicKey can be retrieved an error will be returned.
15
15
  */
16
16
  export declare function messagePublicKey(message: Message): Promise<Uint8Array>;
17
17
  //# sourceMappingURL=sign.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sign.d.ts","sourceRoot":"","sources":["../../../src/message/sign.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAGxD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAA;AAExD,eAAO,MAAM,UAAU,YAAyC,CAAA;AAEhE;;GAEG;AACH,wBAAsB,WAAW,CAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,oBAyBlE;AAED;;GAEG;AACH,wBAAsB,eAAe,CAAE,OAAO,EAAE,OAAO,oBAyBtD;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,CAAE,OAAO,EAAE,OAAO,uBAyBvD"}
1
+ {"version":3,"file":"sign.d.ts","sourceRoot":"","sources":["../../../src/message/sign.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAExD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAA;AAGxD,eAAO,MAAM,UAAU,YAAyC,CAAA;AAEhE;;GAEG;AACH,wBAAsB,WAAW,CAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,oBAyBlE;AAED;;GAEG;AACH,wBAAsB,eAAe,CAAE,OAAO,EAAE,OAAO,oBAyBtD;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,CAAE,OAAO,EAAE,OAAO,uBAoBvD"}
@@ -1,10 +1,9 @@
1
- import * as PeerIdFactory from '@libp2p/peer-id-factory';
2
1
  import { RPC } from './rpc.js';
3
2
  import { concat as uint8ArrayConcat } from 'uint8arrays/concat';
4
3
  import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
5
- import { normalizeOutRpcMessage } from '../utils.js';
4
+ import { toRpcMessage } from '../utils.js';
6
5
  import { keys } from '@libp2p/crypto';
7
- import { PeerId as PeerIdImpl } from '@libp2p/peer-id';
6
+ import { peerIdFromKeys } from '@libp2p/peer-id';
8
7
  export const SignPrefix = uint8ArrayFromString('libp2p-pubsub:');
9
8
  /**
10
9
  * Signs the provided message with the given `peerId`
@@ -13,7 +12,7 @@ export async function signMessage(peerId, message) {
13
12
  // Get the message in bytes, and prepend with the pubsub prefix
14
13
  const bytes = uint8ArrayConcat([
15
14
  SignPrefix,
16
- RPC.Message.encode(normalizeOutRpcMessage(message)).finish()
15
+ RPC.Message.encode(toRpcMessage(message)).finish()
17
16
  ]);
18
17
  if (peerId.privateKey == null) {
19
18
  throw new Error('Cannot sign message, no private key present');
@@ -44,7 +43,7 @@ export async function verifySignature(message) {
44
43
  const bytes = uint8ArrayConcat([
45
44
  SignPrefix,
46
45
  RPC.Message.encode({
47
- ...message,
46
+ ...toRpcMessage(message),
48
47
  signature: undefined,
49
48
  key: undefined
50
49
  }).finish()
@@ -57,26 +56,21 @@ export async function verifySignature(message) {
57
56
  }
58
57
  /**
59
58
  * Returns the PublicKey associated with the given message.
60
- * If no, valid PublicKey can be retrieved an error will be returned.
59
+ * If no valid PublicKey can be retrieved an error will be returned.
61
60
  */
62
61
  export async function messagePublicKey(message) {
63
62
  // should be available in the from property of the message (peer id)
64
63
  if (message.from == null) {
65
64
  throw new Error('Could not get the public key from the originator id');
66
65
  }
67
- const from = PeerIdImpl.fromBytes(message.from);
68
66
  if (message.key != null) {
69
- const keyPeerId = await PeerIdFactory.createFromPubKey(keys.unmarshalPublicKey(message.key));
70
- // the key belongs to the sender, return the key
71
- if (!keyPeerId.equals(from)) {
72
- throw new Error('Public Key does not match the originator');
73
- }
67
+ const keyPeerId = await peerIdFromKeys(message.key);
74
68
  if (keyPeerId.publicKey != null) {
75
69
  return keyPeerId.publicKey;
76
70
  }
77
71
  }
78
- else if (from.publicKey != null) {
79
- return from.publicKey;
72
+ if (message.from.publicKey != null) {
73
+ return message.from.publicKey;
80
74
  }
81
75
  // We couldn't validate pubkey is from the originator, error
82
76
  throw new Error('Could not get the public key from the originator id');
@@ -1 +1 @@
1
- {"version":3,"file":"sign.js","sourceRoot":"","sources":["../../../src/message/sign.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,aAAa,MAAM,yBAAyB,CAAA;AACxD,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,MAAM,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAC/D,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAEpD,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAA;AACrC,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAGtD,MAAM,CAAC,MAAM,UAAU,GAAG,oBAAoB,CAAC,gBAAgB,CAAC,CAAA;AAEhE;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAE,MAAc,EAAE,OAAgB;IACjE,+DAA+D;IAC/D,MAAM,KAAK,GAAG,gBAAgB,CAAC;QAC7B,UAAU;QACV,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,sBAAsB,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,EAAE;KAC7D,CAAC,CAAA;IAEF,IAAI,MAAM,CAAC,UAAU,IAAI,IAAI,EAAE;QAC7B,MAAM,IA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S,EAAE,SAAS;YACpB,GAAG,EAAE,SAAS;SACf,CAAC,CAAC,MAAM,EAAE;KACZ,CAAC,CAAA;IAEF,qBAAqB;IACrB,MAAM,WAAW,GAAG,MAAM,gBAAgB,CAAC,OAAO,CAAC,CAAA;IACnD,MAAM,MAAM,GAAG,IAAI,CAAC,kBAAkB,CAAC,WAAW,CAAC,CAAA;IAEnD,0BAA0B;IAC1B,OAAO,MAAM,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC,CAAA;AACtD,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAE,OAAgB;IACtD,oEAAoE;IACpE,IAAI,OAAO,CAAC,IAAI,IAAI,IAAI,EAAE;QACxB,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAA;KACvE;IAED,IAAI,OAAO,CAAC,GAAG,IAAI,IAAI,EAAE;QACvB,MAAM,SAAS,GAAG,MAAM,cAAc,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;QAEnD,IAAI,SAAS,CAAC,SAAS,IAAI,IAAI,EAAE;YAC/B,OAAO,SAAS,CAAC,SAAS,CAAA;SAC3B;KACF;IAED,IAAI,OAAO,CAAC,IAAI,CAAC,SAAS,IAAI,IAAI,EAAE;QAClC,OAAO,OAAO,CAAC,IAAI,CAAC,SAAS,CAAA;KAC9B;IAED,4DAA4D;IAC5D,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAA;AACxE,CAAC"}
@@ -16,19 +16,19 @@ export declare class PeerStreams extends EventEmitter<PeerStreamEvents> {
16
16
  /**
17
17
  * Write stream - it's preferable to use the write method
18
18
  */
19
- outboundStream: Pushable<Uint8Array> | undefined;
19
+ outboundStream?: Pushable<Uint8Array>;
20
20
  /**
21
21
  * Read stream
22
22
  */
23
- inboundStream: AsyncIterable<Uint8Array> | undefined;
23
+ inboundStream?: AsyncIterable<Uint8Array>;
24
24
  /**
25
25
  * The raw outbound stream, as retrieved from conn.newStream
26
26
  */
27
- private _rawOutboundStream;
27
+ private _rawOutboundStream?;
28
28
  /**
29
29
  * The raw inbound stream, as retrieved from the callback from libp2p.handle
30
30
  */
31
- private _rawInboundStream;
31
+ private _rawInboundStream?;
32
32
  /**
33
33
  * An AbortController for controlled shutdown of the inbound stream
34
34
  */
@@ -55,7 +55,7 @@ export declare class PeerStreams extends EventEmitter<PeerStreamEvents> {
55
55
  /**
56
56
  * Attach a raw outbound stream and setup a write stream
57
57
  */
58
- attachOutboundStream(stream: Stream): Promise<void>;
58
+ attachOutboundStream(stream: Stream): Promise<Pushable<Uint8Array>>;
59
59
  /**
60
60
  * Closes the open connection to peer
61
61
  */
@@ -1 +1 @@
1
- {"version":3,"file":"peer-streams.d.ts","sourceRoot":"","sources":["../../src/peer-streams.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAe,MAAM,oBAAoB,CAAA;AAK9D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AACxD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAA;AAC3D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAA;AAIjE,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAA;IACV,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED;;GAEG;AACH,qBAAa,WAAY,SAAQ,YAAY,CAAC,gBAAgB,CAAC;IAC7D,SAAgB,EAAE,EAAE,MAAM,CAAA;IAC1B,SAAgB,QAAQ,EAAE,MAAM,CAAA;IAChC;;OAEG;IACI,cAAc,EAAE,QAAQ,CAAC,UAAU,CAAC,GAAG,SAAS,CAAA;IACvD;;OAEG;IACI,aAAa,EAAE,aAAa,CAAC,UAAU,CAAC,GAAG,SAAS,CAAA;IAC3D;;OAEG;IACH,OAAO,CAAC,kBAAkB,CAAoB;IAC9C;;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C,CAAQ;IAClC;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,uBAAuB,CAAiB;IACzD,OAAO,CAAC,MAAM,CAAS;gBAEV,IAAI,EAAE,OAAO;IAU1B;;OAEG;IACH,IAAI,UAAU,YAEb;IAED;;OAEG;IACH,IAAI,UAAU,YAEb;IAED;;;OAGG;IACH,KAAK,CAAE,IAAI,EAAE,UAAU;IASvB;;OAEG;IACH,mBAAmB,CAAE,MAAM,EAAE,MAAM;IAmBnC;;OAEG;IACG,oBAAoB,CAAE,MAAM,EAAE,MAAM;IAwC1C;;OAEG;IACH,KAAK;CAsBN"}
@@ -83,6 +83,7 @@ export class PeerStreams extends EventEmitter {
83
83
  if (_prevStream == null) {
84
84
  this.dispatchEvent(new CustomEvent('stream:outbound'));
85
85
  }
86
+ return this.outboundStream;
86
87
  }
87
88
  /**
88
89
  * Closes the open connection to peer
@@ -1 +1 @@
1
- {"version":3,"file":"peer-streams.js","sourceRoot":"","sources":["../../src/peer-streams.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAC9D,OAAO,KAAK,EAAE,MAAM,oBAAoB,CAAA;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAMpD,MAAM,GAAG,GAAG,MAAM,CAAC,4BAA4B,CAAC,CAAA;AAOhD;;GAEG;AACH,MAAM,OAAO,WAAY,SAAQ,YAA8B;IAyB7D,YAAa,IAAa;QACxB,KAAK,EAAE,CAAA;QAEP,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,CAAA;QACjB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAA;QAE7B,IAAI,CAAC,uBAAuB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AS,CAAA;QAClC,IAAI,CAAC,aAAa,GAAG,SAAS,CAAA;QAC9B,IAAI,CAAC,aAAa,CAAC,IAAI,WAAW,CAAC,OAAO,CAAC,CAAC,CAAA;IAC9C,CAAC;CACF"}
@@ -1,13 +1,13 @@
1
1
  import type * as RPC from './message/rpc.js';
2
- import type { Message } from '@libp2p/interfaces/pubsub';
2
+ import type { Message, RPCMessage } from '@libp2p/interfaces/pubsub';
3
3
  /**
4
4
  * Generate a random sequence number
5
5
  */
6
- export declare const randomSeqno: () => any;
6
+ export declare function randomSeqno(): BigInt;
7
7
  /**
8
- * Generate a message id, based on the `from` and `seqno`
8
+ * Generate a message id, based on the `key` and `seqno`
9
9
  */
10
- export declare const msgId: (from: Uint8Array | string, seqno: Uint8Array) => Uint8Array;
10
+ export declare const msgId: (key: Uint8Array, seqno: BigInt) => Uint8Array;
11
11
  /**
12
12
  * Generate a message id, based on message `data`
13
13
  */
@@ -21,9 +21,6 @@ export declare const anyMatch: (a: Set<number> | number[], b: Set<number> | numb
21
21
  * Make everything an array
22
22
  */
23
23
  export declare const ensureArray: <T>(maybeArray: T | T[]) => T[];
24
- /**
25
- * Ensures `message.from` is base58 encoded
26
- */
27
- export declare const normalizeInRpcMessage: (message: RPC.RPC.IMessage, peerId?: string | undefined) => any;
28
- export declare const normalizeOutRpcMessage: (message: Message) => Message;
24
+ export declare const toMessage: (message: RPC.RPC.IMessage) => Message;
25
+ export declare const toRpcMessage: (message: Message) => RPCMessage;
29
26
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,GAAG,MAAM,kBAAkB,CAAA;AAC5C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAA;AAExD;;GAEG;AACH,eAAO,MAAM,WAAW,WAEvB,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,KAAK,SAAU,UAAU,GAAG,MAAM,SAAS,UAAU,eAajE,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,WAAW,SAAU,UAAU,2DAAwB,CAAA;AAEpE;;;GAGG;AACH,eAAO,MAAM,QAAQ,MAAO,IAAI,MAAM,CAAC,GAAG,MAAM,EAAE,KAAK,IAAI,MAAM,CAAC,GAAG,MAAM,EAAE,YAe5E,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,WAAW,iCAMvB,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,qBAAqB,YAAa,OAAO,CAAC,QAAQ,qCAS9D,CAAA;AAED,eAAO,MAAM,sBAAsB,YAAa,OAAO,YAStD,CAAA"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,GAAG,MAAM,kBAAkB,CAAA;AAC5C,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AAKpE;;GAEG;AACH,wBAAgB,WAAW,IAAK,MAAM,CAErC;AAED;;GAEG;AACH,eAAO,MAAM,KAAK,QAAS,UAAU,SAAS,MAAM,eAQnD,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,WAAW,SAAU,UAAU,2DAE3C,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,QAAQ,MAAO,IAAI,MAAM,CAAC,GAAG,MAAM,EAAE,KAAK,IAAI,MAAM,CAAC,GAAG,MAAM,EAAE,YAe5E,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,WAAW,iCAMvB,CAAA;AAED,eAAO,MAAM,SAAS,YAAa,OAAO,CAAC,QAAQ,KAAG,OAarD,CAAA;AAED,eAAO,MAAM,YAAY,YAAa,OAAO,KAAG,UAS/C,CAAA"}
package/dist/src/utils.js CHANGED
@@ -1,33 +1,32 @@
1
1
  import { randomBytes } from 'iso-random-stream';
2
2
  import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
3
- import { PeerId } from '@libp2p/peer-id';
3
+ import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
4
4
  import { sha256 } from 'multiformats/hashes/sha2';
5
+ import { peerIdFromBytes } from '@libp2p/peer-id';
6
+ import { codes } from './errors.js';
7
+ import errcode from 'err-code';
5
8
  /**
6
9
  * Generate a random sequence number
7
10
  */
8
- export const randomSeqno = () => {
9
- return randomBytes(8);
10
- };
11
+ export function randomSeqno() {
12
+ return BigInt(`0x${uint8ArrayToString(randomBytes(8), 'base16')}`);
13
+ }
11
14
  /**
12
- * Generate a message id, based on the `from` and `seqno`
15
+ * Generate a message id, based on the `key` and `seqno`
13
16
  */
14
- export const msgId = (from, seqno) => {
15
- let fromBytes;
16
- if (from instanceof Uint8Array) {
17
- fromBytes = PeerId.fromBytes(from).multihash.digest;
18
- }
19
- else {
20
- fromBytes = PeerId.fromString(from).multihash.digest;
21
- }
22
- const msgId = new Uint8Array(fromBytes.length + seqno.length);
23
- msgId.set(fromBytes, 0);
24
- msgId.set(seqno, fromBytes.length);
17
+ export const msgId = (key, seqno) => {
18
+ const seqnoBytes = uint8ArrayFromString(seqno.toString(16).padStart(16, '0'), 'base16');
19
+ const msgId = new Uint8Array(key.length + seqnoBytes.length);
20
+ msgId.set(key, 0);
21
+ msgId.set(seqnoBytes, key.length);
25
22
  return msgId;
26
23
  };
27
24
  /**
28
25
  * Generate a message id, based on message `data`
29
26
  */
30
- export const noSignMsgId = (data) => sha256.encode(data);
27
+ export const noSignMsgId = (data) => {
28
+ return sha256.encode(data);
29
+ };
31
30
  /**
32
31
  * Check if any member of the first set is also a member
33
32
  * of the second set
@@ -56,25 +55,27 @@ export const ensureArray = function (maybeArray) {
56
55
  }
57
56
  return maybeArray;
58
57
  };
59
- /**
60
- * Ensures `message.from` is base58 encoded
61
- */
62
- export const normalizeInRpcMessage = (message, peerId) => {
63
- // @ts-expect-error receivedFrom not yet defined
64
- const m = Object.assign({}, message);
65
- if (peerId != null) {
66
- m.receivedFrom = peerId;
58
+ export const toMessage = (message) => {
59
+ if (message.from == null) {
60
+ throw errcode(new Error('RPC message was missing from'), codes.ERR_MISSING_FROM);
67
61
  }
68
- return m;
62
+ return {
63
+ from: peerIdFromBytes(message.from),
64
+ topic: message.topic ?? '',
65
+ seqno: message.seqno == null ? undefined : BigInt(`0x${uint8ArrayToString(message.seqno, 'base16')}`),
66
+ data: message.data ?? new Uint8Array(0),
67
+ signature: message.signature ?? undefined,
68
+ key: message.key ?? undefined
69
+ };
69
70
  };
70
- export const normalizeOutRpcMessage = (message) => {
71
- const m = Object.assign({}, message);
72
- if (typeof message.from === 'string') {
73
- m.from = uint8ArrayFromString(message.from, 'base58btc');
74
- }
75
- if (typeof message.data === 'string') {
76
- m.data = uint8ArrayFromString(message.data);
77
- }
78
- return m;
71
+ export const toRpcMessage = (message) => {
72
+ return {
73
+ from: message.from.multihash.bytes,
74
+ data: message.data,
75
+ seqno: message.seqno == null ? undefined : uint8ArrayFromString(message.seqno.toString(16).padStart(16, '0'), 'base16'),
76
+ topic: message.topic,
77
+ signature: message.signature,
78
+ key: message.key
79
+ };
79
80
  };
80
81
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAA;AAIjD;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,EAAE;IAC9B,OAAO,WAAW,CAAC,CAAC,CAAC,CAAA;AACvB,CAAC,CAAA;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,IAAyB,EAAE,KAAiB,EAAE,EAAE;IACpE,IAAI,SAAS,CAAA;IAEb,IA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AAI;QAClB,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,oBAAoB,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,QAAQ,CAAC;QACvH,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,GAAG,EAAE,OAAO,CAAC,GAAG;KACjB,CAAA;AACH,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/pubsub",
3
- "version": "1.2.3",
3
+ "version": "1.2.7",
4
4
  "description": "libp2p pubsub base class",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/libp2p/js-libp2p-interfaces/tree/master/packages/libp2p-pubsub#readme",
@@ -176,12 +176,9 @@
176
176
  "test:firefox-webworker": "npm run test -- -t webworker -- --browser firefox",
177
177
  "test:node": "npm run test -- -t node --cov",
178
178
  "test:electron-main": "npm run test -- -t electron-main",
179
- "build:proto": "npm run build:proto:rpc && npm run build:proto:topic-descriptor",
180
- "build:proto:rpc": "pbjs -t static-module -w es6 -r libp2p-pubsub-rpc --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/message/rpc.js ./src/message/rpc.proto",
181
- "build:proto:topic-descriptor": "pbjs -t static-module -w es6 -r libp2p-pubsub-topic-descriptor --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/message/topic-descriptor.js ./src/message/topic-descriptor.proto",
182
- "build:proto-types": "npm run build:proto-types:rpc && npm run build:proto-types:topic-descriptor",
183
- "build:proto-types:rpc": "pbts -o src/message/rpc.d.ts src/message/rpc.js",
184
- "build:proto-types:topic-descriptor": "pbts -o src/message/topic-descriptor.d.ts src/message/topic-descriptor.js",
179
+ "generate": "npm run generate:proto:rpc && npm run generate:proto-types:rpc",
180
+ "generate:proto:rpc": "pbjs -t static-module -w es6 -r libp2p-pubsub-rpc --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/message/rpc.js ./src/message/rpc.proto",
181
+ "generate:proto-types:rpc": "pbts -o src/message/rpc.d.ts src/message/rpc.js",
185
182
  "build:copy-proto-files": "cp src/message/*.js dist/src/message && cp src/message/*.d.ts dist/src/message"
186
183
  },
187
184
  "dependencies": {
@@ -189,19 +186,19 @@
189
186
  "@libp2p/interfaces": "^1.0.0",
190
187
  "@libp2p/logger": "^1.0.1",
191
188
  "@libp2p/peer-id": "^1.0.0",
192
- "@libp2p/peer-id-factory": "^1.0.0",
189
+ "@libp2p/peer-map": "^1.0.0",
193
190
  "@libp2p/topology": "^1.0.0",
194
191
  "@multiformats/multiaddr": "^10.1.1",
195
192
  "err-code": "^3.0.1",
196
193
  "iso-random-stream": "^2.0.0",
197
- "it-length-prefixed": "^6.0.1",
194
+ "it-length-prefixed": "^7.0.0",
198
195
  "it-pipe": "^2.0.2",
199
196
  "multiformats": "^9.4.10",
200
197
  "p-queue": "^7.1.0",
201
198
  "uint8arrays": "^3.0.0"
202
199
  },
203
200
  "devDependencies": {
204
- "@types/bl": "^5.0.2",
201
+ "@libp2p/peer-id-factory": "^1.0.0",
205
202
  "abortable-iterator": "^4.0.2",
206
203
  "aegir": "^36.1.3",
207
204
  "it-pair": "^2.0.2",
package/src/errors.ts CHANGED
@@ -19,10 +19,18 @@ export const codes = {
19
19
  * Message expected to have a `seqno`, but doesn't
20
20
  */
21
21
  ERR_MISSING_SEQNO: 'ERR_MISSING_SEQNO',
22
+ /**
23
+ * Message expected to have a `key`, but doesn't
24
+ */
25
+ ERR_MISSING_KEY: 'ERR_MISSING_KEY',
22
26
  /**
23
27
  * Message `signature` is invalid
24
28
  */
25
29
  ERR_INVALID_SIGNATURE: 'ERR_INVALID_SIGNATURE',
30
+ /**
31
+ * Message expected to have a `from`, but doesn't
32
+ */
33
+ ERR_MISSING_FROM: 'ERR_MISSING_FROM',
26
34
 
27
35
  // Strict no-signing codes
28
36