@libp2p/peer-record 4.0.0 → 4.0.1

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.
@@ -1,5 +1,5 @@
1
- import type { Codec } from 'protons-runtime';
2
1
  import type { Uint8ArrayList } from 'uint8arraylist';
2
+ import type { Codec } from 'protons-runtime';
3
3
  export interface Envelope {
4
4
  publicKey: Uint8Array;
5
5
  payloadType: Uint8Array;
@@ -8,7 +8,7 @@ export interface Envelope {
8
8
  }
9
9
  export declare namespace Envelope {
10
10
  const codec: () => Codec<Envelope>;
11
- const encode: (obj: Envelope) => Uint8ArrayList;
11
+ const encode: (obj: Envelope) => Uint8Array;
12
12
  const decode: (buf: Uint8Array | Uint8ArrayList) => Envelope;
13
13
  }
14
14
  //# sourceMappingURL=envelope.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"envelope.d.ts","sourceRoot":"","sources":["../../../src/envelope/envelope.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD,MAAM,WAAW,QAAQ;IACvB,SAAS,EAAE,UAAU,CAAA;IACrB,WAAW,EAAE,UAAU,CAAA;IACvB,OAAO,EAAE,UAAU,CAAA;IACnB,SAAS,EAAE,UAAU,CAAA;CACtB;AAED,yBAAiB,QAAQ,CAAC;IACjB,MAAM,KAAK,QAAO,MAAM,QAAQ,CAOtC,CAAA;IAEM,MAAM,MAAM,QAAS,QAAQ,KAAG,cAEtC,CAAA;IAEM,MAAM,MAAM,QAAS,UAAU,GAAG,cAAc,KAAG,QAEzD,CAAA;CACF"}
1
+ {"version":3,"file":"envelope.d.ts","sourceRoot":"","sources":["../../../src/envelope/envelope.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAE5C,MAAM,WAAW,QAAQ;IACvB,SAAS,EAAE,UAAU,CAAA;IACrB,WAAW,EAAE,UAAU,CAAA;IACvB,OAAO,EAAE,UAAU,CAAA;IACnB,SAAS,EAAE,UAAU,CAAA;CACtB;AAED,yBAAiB,QAAQ,CAAC;IAGjB,MAAM,KAAK,QAAO,MAAM,QAAQ,CA2FtC,CAAA;IAEM,MAAM,MAAM,QAAS,QAAQ,KAAG,UAEtC,CAAA;IAEM,MAAM,MAAM,QAAS,UAAU,GAAG,cAAc,KAAG,QAEzD,CAAA;CACF"}
@@ -1,15 +1,90 @@
1
1
  /* eslint-disable import/export */
2
2
  /* eslint-disable @typescript-eslint/no-namespace */
3
- import { encodeMessage, decodeMessage, message, bytes } from 'protons-runtime';
3
+ import { encodeMessage, decodeMessage, message } from 'protons-runtime';
4
4
  export var Envelope;
5
5
  (function (Envelope) {
6
+ let _codec;
6
7
  Envelope.codec = () => {
7
- return message({
8
- 1: { name: 'publicKey', codec: bytes },
9
- 2: { name: 'payloadType', codec: bytes },
10
- 3: { name: 'payload', codec: bytes },
11
- 5: { name: 'signature', codec: bytes }
12
- });
8
+ if (_codec == null) {
9
+ _codec = message((obj, writer, opts = {}) => {
10
+ if (opts.lengthDelimited !== false) {
11
+ writer.fork();
12
+ }
13
+ if (obj.publicKey != null) {
14
+ writer.uint32(10);
15
+ writer.bytes(obj.publicKey);
16
+ }
17
+ else {
18
+ throw new Error('Protocol error: required field "publicKey" was not found in object');
19
+ }
20
+ if (obj.payloadType != null) {
21
+ writer.uint32(18);
22
+ writer.bytes(obj.payloadType);
23
+ }
24
+ else {
25
+ throw new Error('Protocol error: required field "payloadType" was not found in object');
26
+ }
27
+ if (obj.payload != null) {
28
+ writer.uint32(26);
29
+ writer.bytes(obj.payload);
30
+ }
31
+ else {
32
+ throw new Error('Protocol error: required field "payload" was not found in object');
33
+ }
34
+ if (obj.signature != null) {
35
+ writer.uint32(42);
36
+ writer.bytes(obj.signature);
37
+ }
38
+ else {
39
+ throw new Error('Protocol error: required field "signature" was not found in object');
40
+ }
41
+ if (opts.lengthDelimited !== false) {
42
+ writer.ldelim();
43
+ }
44
+ }, (reader, length) => {
45
+ const obj = {
46
+ publicKey: new Uint8Array(0),
47
+ payloadType: new Uint8Array(0),
48
+ payload: new Uint8Array(0),
49
+ signature: new Uint8Array(0)
50
+ };
51
+ const end = length == null ? reader.len : reader.pos + length;
52
+ while (reader.pos < end) {
53
+ const tag = reader.uint32();
54
+ switch (tag >>> 3) {
55
+ case 1:
56
+ obj.publicKey = reader.bytes();
57
+ break;
58
+ case 2:
59
+ obj.payloadType = reader.bytes();
60
+ break;
61
+ case 3:
62
+ obj.payload = reader.bytes();
63
+ break;
64
+ case 5:
65
+ obj.signature = reader.bytes();
66
+ break;
67
+ default:
68
+ reader.skipType(tag & 7);
69
+ break;
70
+ }
71
+ }
72
+ if (obj.publicKey == null) {
73
+ throw new Error('Protocol error: value for required field "publicKey" was not found in protobuf');
74
+ }
75
+ if (obj.payloadType == null) {
76
+ throw new Error('Protocol error: value for required field "payloadType" was not found in protobuf');
77
+ }
78
+ if (obj.payload == null) {
79
+ throw new Error('Protocol error: value for required field "payload" was not found in protobuf');
80
+ }
81
+ if (obj.signature == null) {
82
+ throw new Error('Protocol error: value for required field "signature" was not found in protobuf');
83
+ }
84
+ return obj;
85
+ });
86
+ }
87
+ return _codec;
13
88
  };
14
89
  Envelope.encode = (obj) => {
15
90
  return encodeMessage(obj, Envelope.codec());
@@ -1 +1 @@
1
- {"version":3,"file":"envelope.js","sourceRoot":"","sources":["../../../src/envelope/envelope.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,oDAAoD;AAEpD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAW9E,MAAM,KAAW,QAAQ,CAiBxB;AAjBD,WAAiB,QAAQ;IACV,cAAK,GAAG,GAAoB,EAAE;QACzC,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,CAAC,CAAC,CAAA;SACH;QAED,OAAO,MAAM,CAAA;IACf,CAAC,CAAA;IAEY,eAAM,GAAG,CAAC,GAAa,EAAc,EAAE;QAClD,OAAO,aAAa,CAAC,GAAG,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAA;IAC7C,CAAC,CAAA;IAEY,eAAM,GAAG,CAAC,GAAgC,EAAY,EAAE;QACnE,OAAO,aAAa,CAAC,GAAG,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAA;IAC7C,CAAC,CAAA;AACH,CAAC,EAvGgB,QAAQ,KAAR,QAAQ,QAuGxB"}
@@ -4,7 +4,7 @@ import { Uint8ArrayList } from 'uint8arraylist';
4
4
  export interface EnvelopeInit {
5
5
  peerId: PeerId;
6
6
  payloadType: Uint8Array;
7
- payload: Uint8Array | Uint8ArrayList;
7
+ payload: Uint8Array;
8
8
  signature: Uint8Array;
9
9
  }
10
10
  export declare class RecordEnvelope implements Envelope {
@@ -24,9 +24,9 @@ export declare class RecordEnvelope implements Envelope {
24
24
  static openAndCertify: (data: Uint8Array | Uint8ArrayList, domain: string) => Promise<RecordEnvelope>;
25
25
  peerId: PeerId;
26
26
  payloadType: Uint8Array;
27
- payload: Uint8Array | Uint8ArrayList;
27
+ payload: Uint8Array;
28
28
  signature: Uint8Array;
29
- marshaled?: Uint8ArrayList;
29
+ marshaled?: Uint8Array;
30
30
  /**
31
31
  * The Envelope is responsible for keeping an arbitrary signed record
32
32
  * by a libp2p peer.
@@ -35,7 +35,7 @@ export declare class RecordEnvelope implements Envelope {
35
35
  /**
36
36
  * Marshal the envelope content
37
37
  */
38
- marshal(): Uint8ArrayList;
38
+ marshal(): Uint8Array;
39
39
  /**
40
40
  * Verifies if the other Envelope is identical to this one
41
41
  */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/envelope/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CA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AA;IACvB,OAAO,EAAE,UAAU,CAAA;IACnB,SAAS,EAAE,UAAU,CAAA;CACtB;AAED,qBAAa,cAAe,YAAW,QAAQ;IAC7C;;OAEG;IACH,MAAM,CAAC,kBAAkB,SAAgB,UAAU,GAAG,cAAc,6BAUnE;IAED;;;OAGG;IACH,MAAM,CAAC,IAAI,WAAkB,MAAM,UAAU,MAAM,6BAkBlD;IAED;;;OAGG;IACH,MAAM,CAAC,cAAc,SAAgB,UAAU,GAAG,cAAc,UAAU,MAAM,6BAS/E;IAEM,MAAM,EAAE,MAAM,CAAA;IACd,WAAW,EAAE,UAAU,CAAA;IACvB,OAAO,EAAE,UAAU,CAAA;IACnB,SAAS,EAAE,UAAU,CAAA;IACrB,SAAS,CAAC,EAAE,UAAU,CAAA;IAE7B;;;OAGG;gBACU,IAAI,EAAE,YAAY;IAS/B;;OAEG;IACH,OAAO,IAAK,UAAU;IAiBtB;;OAEG;IACH,MAAM,CAAE,KAAK,EAAE,QAAQ;IAIvB;;OAEG;IACG,QAAQ,CAAE,MAAM,EAAE,MAAM;CAW/B"}
@@ -1,6 +1,7 @@
1
1
  var _a;
2
2
  import errCode from 'err-code';
3
3
  import { fromString as uint8arraysFromString } from 'uint8arrays/from-string';
4
+ import { equals as uint8ArrayEquals } from 'uint8arrays/equals';
4
5
  import { unmarshalPrivateKey, unmarshalPublicKey } from '@libp2p/crypto/keys';
5
6
  import { codes } from '../errors.js';
6
7
  import { Envelope as Protobuf } from './envelope.js';
@@ -40,7 +41,7 @@ export class RecordEnvelope {
40
41
  * Verifies if the other Envelope is identical to this one
41
42
  */
42
43
  equals(other) {
43
- return this.marshal().equals(other.marshal());
44
+ return uint8ArrayEquals(this.marshal(), other.marshal());
44
45
  }
45
46
  /**
46
47
  * Validate envelope data signature for the given domain
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/envelope/index.ts"],"names":[],"mappings":";AAAA,OAAO,OAAO,MAAM,UAAU,CAAA;AAC9B,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,QAAQ,CAAA;AACjB,CAAC,CAAA;AAgEH;;GAEG;AACH,MAAM,sBAAsB,GAAG,CAAC,MAAc,EAAE,WAAuB,EAAE,OAAoC,EAAkB,EAAE;IAC/H,iFAAiF;IACjF,+DAA+D;IAC/D,mDAAmD;IACnD,kDAAkD;IAClD,wCAAwC;IACxC,6CAA6C;IAC7C,mCAAmC;IAEnC,MAAM,gBAAgB,GAAG,qBAAqB,CAAC,MAAM,CAAC,CAAA;IACtD,MAAM,YAAY,GAAG,QAAQ,CAAC,MAAM,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAA;IACjE,MAAM,iBAAiB,GAAG,QAAQ,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAA;IAC7D,MAAM,aAAa,GAAG,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IAErD,OAAO,IAAI,cAAc,CACvB,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,WAAW,EACX,aAAa,EACb,OAAO,CACR,CAAA;AACH,CAAC,CAAA"}
@@ -33,7 +33,7 @@ export declare class PeerRecord {
33
33
  /**
34
34
  * Marshal a record to be used in an envelope
35
35
  */
36
- marshal(): Uint8ArrayList;
36
+ marshal(): Uint8Array;
37
37
  /**
38
38
  * Returns true if `this` record equals the `other`
39
39
  */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/peer-record/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AAQvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAA;IAEd;;OAEG;IACH,UAAU,CAAC,EAAE,SAAS,EAAE,CAAA;IAExB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,C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AAI,EAAE,cAAc;IAQjC;;OAEG;IACH,OAAO;IAcP;;OAEG;IACH,MAAM,CAAE,KAAK,EAAE,OAAO;CAsBvB"}
@@ -1,5 +1,5 @@
1
- import type { Codec } from 'protons-runtime';
2
1
  import type { Uint8ArrayList } from 'uint8arraylist';
2
+ import type { Codec } from 'protons-runtime';
3
3
  export interface PeerRecord {
4
4
  peerId: Uint8Array;
5
5
  seq: bigint;
@@ -11,11 +11,11 @@ export declare namespace PeerRecord {
11
11
  }
12
12
  namespace AddressInfo {
13
13
  const codec: () => Codec<AddressInfo>;
14
- const encode: (obj: AddressInfo) => Uint8ArrayList;
14
+ const encode: (obj: AddressInfo) => Uint8Array;
15
15
  const decode: (buf: Uint8Array | Uint8ArrayList) => AddressInfo;
16
16
  }
17
17
  const codec: () => Codec<PeerRecord>;
18
- const encode: (obj: PeerRecord) => Uint8ArrayList;
18
+ const encode: (obj: PeerRecord) => Uint8Array;
19
19
  const decode: (buf: Uint8Array | Uint8ArrayList) => PeerRecord;
20
20
  }
21
21
  //# sourceMappingURL=peer-record.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"peer-record.d.ts","sourceRoot":"","sources":["../../../src/peer-record/peer-record.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,UAAU,CAAA;IAClB,GAAG,EAAE,MAAM,CAAA;IACX,SAAS,EAAE,UAAU,CAAC,WAAW,EAAE,CAAA;CACpC;AAED,yBAAiB,UAAU,CAAC;IAC1B,UAAiB,WAAW;QAC1B,SAAS,EAAE,UAAU,CAAA;KACtB;IAED,UAAiB,WAAW,CAAC;QACpB,MAAM,KAAK,QAAO,MAAM,WAAW,CAIzC,CAAA;QAEM,MAAM,MAAM,QAAS,WAAW,KAAG,cAEzC,CAAA;QAEM,MAAM,MAAM,QAAS,UAAU,GAAG,cAAc,KAAG,WAEzD,CAAA;KACF;IAEM,MAAM,KAAK,QAAO,MAAM,UAAU,CAMxC,CAAA;IAEM,MAAM,MAAM,QAAS,UAAU,KAAG,cAExC,CAAA;IAEM,MAAM,MAAM,QAAS,UAAU,GAAG,cAAc,KAAG,UAEzD,CAAA;CACF"}
1
+ {"version":3,"file":"peer-record.d.ts","sourceRoot":"","sources":["../../../src/peer-record/peer-record.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAE5C,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,UAAU,CAAA;IAClB,GAAG,EAAE,MAAM,CAAA;IACX,SAAS,EAAE,UAAU,CAAC,WAAW,EAAE,CAAA;CACpC;AAED,yBAAiB,UAAU,CAAC;IAC1B,UAAiB,WAAW;QAC1B,SAAS,EAAE,UAAU,CAAA;KACtB;IAED,UAAiB,WAAW,CAAC;QAGpB,MAAM,KAAK,QAAO,MAAM,WAAW,CA8CzC,CAAA;QAEM,MAAM,MAAM,QAAS,WAAW,KAAG,UAEzC,CAAA;QAEM,MAAM,MAAM,QAAS,UAAU,GAAG,cAAc,KAAG,WAEzD,CAAA;KACF;IAIM,MAAM,KAAK,QAAO,MAAM,UAAU,CA0ExC,CAAA;IAEM,MAAM,MAAM,QAAS,UAAU,KAAG,UAExC,CAAA;IAEM,MAAM,MAAM,QAAS,UAAU,GAAG,cAAc,KAAG,UAEzD,CAAA;CACF"}
@@ -1,14 +1,50 @@
1
1
  /* eslint-disable import/export */
2
2
  /* eslint-disable @typescript-eslint/no-namespace */
3
- import { encodeMessage, decodeMessage, message, bytes, uint64 } from 'protons-runtime';
3
+ import { encodeMessage, decodeMessage, message } from 'protons-runtime';
4
4
  export var PeerRecord;
5
5
  (function (PeerRecord) {
6
6
  let AddressInfo;
7
7
  (function (AddressInfo) {
8
+ let _codec;
8
9
  AddressInfo.codec = () => {
9
- return message({
10
- 1: { name: 'multiaddr', codec: bytes }
11
- });
10
+ if (_codec == null) {
11
+ _codec = message((obj, writer, opts = {}) => {
12
+ if (opts.lengthDelimited !== false) {
13
+ writer.fork();
14
+ }
15
+ if (obj.multiaddr != null) {
16
+ writer.uint32(10);
17
+ writer.bytes(obj.multiaddr);
18
+ }
19
+ else {
20
+ throw new Error('Protocol error: required field "multiaddr" was not found in object');
21
+ }
22
+ if (opts.lengthDelimited !== false) {
23
+ writer.ldelim();
24
+ }
25
+ }, (reader, length) => {
26
+ const obj = {
27
+ multiaddr: new Uint8Array(0)
28
+ };
29
+ const end = length == null ? reader.len : reader.pos + length;
30
+ while (reader.pos < end) {
31
+ const tag = reader.uint32();
32
+ switch (tag >>> 3) {
33
+ case 1:
34
+ obj.multiaddr = reader.bytes();
35
+ break;
36
+ default:
37
+ reader.skipType(tag & 7);
38
+ break;
39
+ }
40
+ }
41
+ if (obj.multiaddr == null) {
42
+ throw new Error('Protocol error: value for required field "multiaddr" was not found in protobuf');
43
+ }
44
+ return obj;
45
+ });
46
+ }
47
+ return _codec;
12
48
  };
13
49
  AddressInfo.encode = (obj) => {
14
50
  return encodeMessage(obj, AddressInfo.codec());
@@ -17,12 +53,73 @@ export var PeerRecord;
17
53
  return decodeMessage(buf, AddressInfo.codec());
18
54
  };
19
55
  })(AddressInfo = PeerRecord.AddressInfo || (PeerRecord.AddressInfo = {}));
56
+ let _codec;
20
57
  PeerRecord.codec = () => {
21
- return message({
22
- 1: { name: 'peerId', codec: bytes },
23
- 2: { name: 'seq', codec: uint64 },
24
- 3: { name: 'addresses', codec: PeerRecord.AddressInfo.codec(), repeats: true }
25
- });
58
+ if (_codec == null) {
59
+ _codec = message((obj, writer, opts = {}) => {
60
+ if (opts.lengthDelimited !== false) {
61
+ writer.fork();
62
+ }
63
+ if (obj.peerId != null) {
64
+ writer.uint32(10);
65
+ writer.bytes(obj.peerId);
66
+ }
67
+ else {
68
+ throw new Error('Protocol error: required field "peerId" was not found in object');
69
+ }
70
+ if (obj.seq != null) {
71
+ writer.uint32(16);
72
+ writer.uint64(obj.seq);
73
+ }
74
+ else {
75
+ throw new Error('Protocol error: required field "seq" was not found in object');
76
+ }
77
+ if (obj.addresses != null) {
78
+ for (const value of obj.addresses) {
79
+ writer.uint32(26);
80
+ PeerRecord.AddressInfo.codec().encode(value, writer);
81
+ }
82
+ }
83
+ else {
84
+ throw new Error('Protocol error: required field "addresses" was not found in object');
85
+ }
86
+ if (opts.lengthDelimited !== false) {
87
+ writer.ldelim();
88
+ }
89
+ }, (reader, length) => {
90
+ const obj = {
91
+ peerId: new Uint8Array(0),
92
+ seq: 0n,
93
+ addresses: []
94
+ };
95
+ const end = length == null ? reader.len : reader.pos + length;
96
+ while (reader.pos < end) {
97
+ const tag = reader.uint32();
98
+ switch (tag >>> 3) {
99
+ case 1:
100
+ obj.peerId = reader.bytes();
101
+ break;
102
+ case 2:
103
+ obj.seq = reader.uint64();
104
+ break;
105
+ case 3:
106
+ obj.addresses.push(PeerRecord.AddressInfo.codec().decode(reader, reader.uint32()));
107
+ break;
108
+ default:
109
+ reader.skipType(tag & 7);
110
+ break;
111
+ }
112
+ }
113
+ if (obj.peerId == null) {
114
+ throw new Error('Protocol error: value for required field "peerId" was not found in protobuf');
115
+ }
116
+ if (obj.seq == null) {
117
+ throw new Error('Protocol error: value for required field "seq" was not found in protobuf');
118
+ }
119
+ return obj;
120
+ });
121
+ }
122
+ return _codec;
26
123
  };
27
124
  PeerRecord.encode = (obj) => {
28
125
  return encodeMessage(obj, PeerRecord.codec());
@@ -1 +1 @@
1
- {"version":3,"file":"peer-record.js","sourceRoot":"","sources":["../../../src/peer-record/peer-record.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,oDAAoD;AAEpD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAUtF,MAA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jB,KAAK,CAAC;4BACJ,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,EAAE,CAAA;4BAC3B,MAAK;wBACP,KAAK,CAAC;4BACJ,GAAG,CAAC,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,CAAA;4BACzB,MAAK;wBACP,KAAK,CAAC;4BACJ,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAA;4BAClF,MAAK;wBACP;4BACE,MAAM,CAAC,QAAQ,CAAC,GAAG,GAAG,CAAC,CAAC,CAAA;4BACxB,MAAK;qBACR;iBACF;gBAED,IAAI,GAAG,CAAC,MAAM,IAAI,IAAI,EAAE;oBACtB,MAAM,IAAI,KAAK,CAAC,6EAA6E,CAAC,CAAA;iBAC/F;gBAED,IAAI,GAAG,CAAC,GAAG,IAAI,IAAI,EAAE;oBACnB,MAAM,IAAI,KAAK,CAAC,0EAA0E,CAAC,CAAA;iBAC5F;gBAED,OAAO,GAAG,CAAA;YACZ,CAAC,CAAC,CAAA;SACH;QAED,OAAO,MAAM,CAAA;IACf,CAAC,CAAA;IAEY,iBAAM,GAAG,CAAC,GAAe,EAAc,EAAE;QACpD,OAAO,aAAa,CAAC,GAAG,EAAE,UAAU,CAAC,KAAK,EAAE,CAAC,CAAA;IAC/C,CAAC,CAAA;IAEY,iBAAM,GAAG,CAAC,GAAgC,EAAc,EAAE;QACrE,OAAO,aAAa,CAAC,GAAG,EAAE,UAAU,CAAC,KAAK,EAAE,CAAC,CAAA;IAC/C,CAAC,CAAA;AACH,CAAC,EAtJgB,UAAU,KAAV,UAAU,QAsJ1B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/peer-record",
3
- "version": "4.0.0",
3
+ "version": "4.0.1",
4
4
  "description": "Used to transfer signed peer data across the network",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/libp2p/js-libp2p-peer-record#readme",
@@ -147,7 +147,7 @@
147
147
  "dependencies": {
148
148
  "@libp2p/crypto": "^1.0.0",
149
149
  "@libp2p/interface-peer-id": "^1.0.2",
150
- "@libp2p/interface-record": "^2.0.0",
150
+ "@libp2p/interface-record": "^2.0.1",
151
151
  "@libp2p/logger": "^2.0.0",
152
152
  "@libp2p/peer-id": "^1.1.13",
153
153
  "@libp2p/utils": "^3.0.0",
@@ -160,7 +160,7 @@
160
160
  "it-map": "^1.0.6",
161
161
  "it-pipe": "^2.0.3",
162
162
  "multiformats": "^9.6.3",
163
- "protons-runtime": "^2.0.2",
163
+ "protons-runtime": "^3.1.0",
164
164
  "uint8-varint": "^1.0.2",
165
165
  "uint8arraylist": "^2.1.0",
166
166
  "uint8arrays": "^3.0.0",
@@ -171,7 +171,7 @@
171
171
  "@libp2p/peer-id-factory": "^1.0.0",
172
172
  "@types/varint": "^6.0.0",
173
173
  "aegir": "^37.3.0",
174
- "protons": "^4.0.1",
174
+ "protons": "^5.1.0",
175
175
  "sinon": "^14.0.0"
176
176
  }
177
177
  }
@@ -1,9 +1,9 @@
1
1
  /* eslint-disable import/export */
2
2
  /* eslint-disable @typescript-eslint/no-namespace */
3
3
 
4
- import { encodeMessage, decodeMessage, message, bytes } from 'protons-runtime'
5
- import type { Codec } from 'protons-runtime'
4
+ import { encodeMessage, decodeMessage, message } from 'protons-runtime'
6
5
  import type { Uint8ArrayList } from 'uint8arraylist'
6
+ import type { Codec } from 'protons-runtime'
7
7
 
8
8
  export interface Envelope {
9
9
  publicKey: Uint8Array
@@ -13,16 +13,102 @@ export interface Envelope {
13
13
  }
14
14
 
15
15
  export namespace Envelope {
16
+ let _codec: Codec<Envelope>
17
+
16
18
  export const codec = (): Codec<Envelope> => {
17
- return message<Envelope>({
18
- 1: { name: 'publicKey', codec: bytes },
19
- 2: { name: 'payloadType', codec: bytes },
20
- 3: { name: 'payload', codec: bytes },
21
- 5: { name: 'signature', codec: bytes }
22
- })
19
+ if (_codec == null) {
20
+ _codec = message<Envelope>((obj, writer, opts = {}) => {
21
+ if (opts.lengthDelimited !== false) {
22
+ writer.fork()
23
+ }
24
+
25
+ if (obj.publicKey != null) {
26
+ writer.uint32(10)
27
+ writer.bytes(obj.publicKey)
28
+ } else {
29
+ throw new Error('Protocol error: required field "publicKey" was not found in object')
30
+ }
31
+
32
+ if (obj.payloadType != null) {
33
+ writer.uint32(18)
34
+ writer.bytes(obj.payloadType)
35
+ } else {
36
+ throw new Error('Protocol error: required field "payloadType" was not found in object')
37
+ }
38
+
39
+ if (obj.payload != null) {
40
+ writer.uint32(26)
41
+ writer.bytes(obj.payload)
42
+ } else {
43
+ throw new Error('Protocol error: required field "payload" was not found in object')
44
+ }
45
+
46
+ if (obj.signature != null) {
47
+ writer.uint32(42)
48
+ writer.bytes(obj.signature)
49
+ } else {
50
+ throw new Error('Protocol error: required field "signature" was not found in object')
51
+ }
52
+
53
+ if (opts.lengthDelimited !== false) {
54
+ writer.ldelim()
55
+ }
56
+ }, (reader, length) => {
57
+ const obj: any = {
58
+ publicKey: new Uint8Array(0),
59
+ payloadType: new Uint8Array(0),
60
+ payload: new Uint8Array(0),
61
+ signature: new Uint8Array(0)
62
+ }
63
+
64
+ const end = length == null ? reader.len : reader.pos + length
65
+
66
+ while (reader.pos < end) {
67
+ const tag = reader.uint32()
68
+
69
+ switch (tag >>> 3) {
70
+ case 1:
71
+ obj.publicKey = reader.bytes()
72
+ break
73
+ case 2:
74
+ obj.payloadType = reader.bytes()
75
+ break
76
+ case 3:
77
+ obj.payload = reader.bytes()
78
+ break
79
+ case 5:
80
+ obj.signature = reader.bytes()
81
+ break
82
+ default:
83
+ reader.skipType(tag & 7)
84
+ break
85
+ }
86
+ }
87
+
88
+ if (obj.publicKey == null) {
89
+ throw new Error('Protocol error: value for required field "publicKey" was not found in protobuf')
90
+ }
91
+
92
+ if (obj.payloadType == null) {
93
+ throw new Error('Protocol error: value for required field "payloadType" was not found in protobuf')
94
+ }
95
+
96
+ if (obj.payload == null) {
97
+ throw new Error('Protocol error: value for required field "payload" was not found in protobuf')
98
+ }
99
+
100
+ if (obj.signature == null) {
101
+ throw new Error('Protocol error: value for required field "signature" was not found in protobuf')
102
+ }
103
+
104
+ return obj
105
+ })
106
+ }
107
+
108
+ return _codec
23
109
  }
24
110
 
25
- export const encode = (obj: Envelope): Uint8ArrayList => {
111
+ export const encode = (obj: Envelope): Uint8Array => {
26
112
  return encodeMessage(obj, Envelope.codec())
27
113
  }
28
114
 
@@ -1,5 +1,6 @@
1
1
  import errCode from 'err-code'
2
2
  import { fromString as uint8arraysFromString } from 'uint8arrays/from-string'
3
+ import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
3
4
  import { unmarshalPrivateKey, unmarshalPublicKey } from '@libp2p/crypto/keys'
4
5
  import { codes } from '../errors.js'
5
6
  import { Envelope as Protobuf } from './envelope.js'
@@ -12,7 +13,7 @@ import { unsigned } from 'uint8-varint'
12
13
  export interface EnvelopeInit {
13
14
  peerId: PeerId
14
15
  payloadType: Uint8Array
15
- payload: Uint8Array | Uint8ArrayList
16
+ payload: Uint8Array
16
17
  signature: Uint8Array
17
18
  }
18
19
 
@@ -73,9 +74,9 @@ export class RecordEnvelope implements Envelope {
73
74
 
74
75
  public peerId: PeerId
75
76
  public payloadType: Uint8Array
76
- public payload: Uint8Array | Uint8ArrayList
77
+ public payload: Uint8Array
77
78
  public signature: Uint8Array
78
- public marshaled?: Uint8ArrayList
79
+ public marshaled?: Uint8Array
79
80
 
80
81
  /**
81
82
  * The Envelope is responsible for keeping an arbitrary signed record
@@ -93,7 +94,7 @@ export class RecordEnvelope implements Envelope {
93
94
  /**
94
95
  * Marshal the envelope content
95
96
  */
96
- marshal (): Uint8ArrayList {
97
+ marshal (): Uint8Array {
97
98
  if (this.peerId.publicKey == null) {
98
99
  throw new Error('Missing public key')
99
100
  }
@@ -114,7 +115,7 @@ export class RecordEnvelope implements Envelope {
114
115
  * Verifies if the other Envelope is identical to this one
115
116
  */
116
117
  equals (other: Envelope) {
117
- return this.marshal().equals(other.marshal())
118
+ return uint8ArrayEquals(this.marshal(), other.marshal())
118
119
  }
119
120
 
120
121
  /**
@@ -48,7 +48,7 @@ export class PeerRecord {
48
48
  public seqNumber: bigint
49
49
  public domain = PeerRecord.DOMAIN
50
50
  public codec = PeerRecord.CODEC
51
- private marshaled?: Uint8ArrayList
51
+ private marshaled?: Uint8Array
52
52
 
53
53
  constructor (init: PeerRecordInit) {
54
54
  const { peerId, multiaddrs, seqNumber } = init
@@ -1,9 +1,9 @@
1
1
  /* eslint-disable import/export */
2
2
  /* eslint-disable @typescript-eslint/no-namespace */
3
3
 
4
- import { encodeMessage, decodeMessage, message, bytes, uint64 } from 'protons-runtime'
5
- import type { Codec } from 'protons-runtime'
4
+ import { encodeMessage, decodeMessage, message } from 'protons-runtime'
6
5
  import type { Uint8ArrayList } from 'uint8arraylist'
6
+ import type { Codec } from 'protons-runtime'
7
7
 
8
8
  export interface PeerRecord {
9
9
  peerId: Uint8Array
@@ -17,13 +17,57 @@ export namespace PeerRecord {
17
17
  }
18
18
 
19
19
  export namespace AddressInfo {
20
+ let _codec: Codec<AddressInfo>
21
+
20
22
  export const codec = (): Codec<AddressInfo> => {
21
- return message<AddressInfo>({
22
- 1: { name: 'multiaddr', codec: bytes }
23
- })
23
+ if (_codec == null) {
24
+ _codec = message<AddressInfo>((obj, writer, opts = {}) => {
25
+ if (opts.lengthDelimited !== false) {
26
+ writer.fork()
27
+ }
28
+
29
+ if (obj.multiaddr != null) {
30
+ writer.uint32(10)
31
+ writer.bytes(obj.multiaddr)
32
+ } else {
33
+ throw new Error('Protocol error: required field "multiaddr" was not found in object')
34
+ }
35
+
36
+ if (opts.lengthDelimited !== false) {
37
+ writer.ldelim()
38
+ }
39
+ }, (reader, length) => {
40
+ const obj: any = {
41
+ multiaddr: new Uint8Array(0)
42
+ }
43
+
44
+ const end = length == null ? reader.len : reader.pos + length
45
+
46
+ while (reader.pos < end) {
47
+ const tag = reader.uint32()
48
+
49
+ switch (tag >>> 3) {
50
+ case 1:
51
+ obj.multiaddr = reader.bytes()
52
+ break
53
+ default:
54
+ reader.skipType(tag & 7)
55
+ break
56
+ }
57
+ }
58
+
59
+ if (obj.multiaddr == null) {
60
+ throw new Error('Protocol error: value for required field "multiaddr" was not found in protobuf')
61
+ }
62
+
63
+ return obj
64
+ })
65
+ }
66
+
67
+ return _codec
24
68
  }
25
69
 
26
- export const encode = (obj: AddressInfo): Uint8ArrayList => {
70
+ export const encode = (obj: AddressInfo): Uint8Array => {
27
71
  return encodeMessage(obj, AddressInfo.codec())
28
72
  }
29
73
 
@@ -32,15 +76,85 @@ export namespace PeerRecord {
32
76
  }
33
77
  }
34
78
 
79
+ let _codec: Codec<PeerRecord>
80
+
35
81
  export const codec = (): Codec<PeerRecord> => {
36
- return message<PeerRecord>({
37
- 1: { name: 'peerId', codec: bytes },
38
- 2: { name: 'seq', codec: uint64 },
39
- 3: { name: 'addresses', codec: PeerRecord.AddressInfo.codec(), repeats: true }
40
- })
82
+ if (_codec == null) {
83
+ _codec = message<PeerRecord>((obj, writer, opts = {}) => {
84
+ if (opts.lengthDelimited !== false) {
85
+ writer.fork()
86
+ }
87
+
88
+ if (obj.peerId != null) {
89
+ writer.uint32(10)
90
+ writer.bytes(obj.peerId)
91
+ } else {
92
+ throw new Error('Protocol error: required field "peerId" was not found in object')
93
+ }
94
+
95
+ if (obj.seq != null) {
96
+ writer.uint32(16)
97
+ writer.uint64(obj.seq)
98
+ } else {
99
+ throw new Error('Protocol error: required field "seq" was not found in object')
100
+ }
101
+
102
+ if (obj.addresses != null) {
103
+ for (const value of obj.addresses) {
104
+ writer.uint32(26)
105
+ PeerRecord.AddressInfo.codec().encode(value, writer)
106
+ }
107
+ } else {
108
+ throw new Error('Protocol error: required field "addresses" was not found in object')
109
+ }
110
+
111
+ if (opts.lengthDelimited !== false) {
112
+ writer.ldelim()
113
+ }
114
+ }, (reader, length) => {
115
+ const obj: any = {
116
+ peerId: new Uint8Array(0),
117
+ seq: 0n,
118
+ addresses: []
119
+ }
120
+
121
+ const end = length == null ? reader.len : reader.pos + length
122
+
123
+ while (reader.pos < end) {
124
+ const tag = reader.uint32()
125
+
126
+ switch (tag >>> 3) {
127
+ case 1:
128
+ obj.peerId = reader.bytes()
129
+ break
130
+ case 2:
131
+ obj.seq = reader.uint64()
132
+ break
133
+ case 3:
134
+ obj.addresses.push(PeerRecord.AddressInfo.codec().decode(reader, reader.uint32()))
135
+ break
136
+ default:
137
+ reader.skipType(tag & 7)
138
+ break
139
+ }
140
+ }
141
+
142
+ if (obj.peerId == null) {
143
+ throw new Error('Protocol error: value for required field "peerId" was not found in protobuf')
144
+ }
145
+
146
+ if (obj.seq == null) {
147
+ throw new Error('Protocol error: value for required field "seq" was not found in protobuf')
148
+ }
149
+
150
+ return obj
151
+ })
152
+ }
153
+
154
+ return _codec
41
155
  }
42
156
 
43
- export const encode = (obj: PeerRecord): Uint8ArrayList => {
157
+ export const encode = (obj: PeerRecord): Uint8Array => {
44
158
  return encodeMessage(obj, PeerRecord.codec())
45
159
  }
46
160