@libp2p/peer-record 1.0.5 → 1.0.8

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"peer-record.d.ts","sourceRoot":"","sources":["../../../src/peer-record/peer-record.ts"],"names":[],"mappings":"AAKA,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,0EAIjB,CAAA;QAEM,MAAM,MAAM,QAAS,WAAW,KAAG,UAEzC,CAAA;QAEM,MAAM,MAAM,QAAS,UAAU,KAAG,WAExC,CAAA;KACF;IAEM,MAAM,KAAK,yEAMjB,CAAA;IAEM,MAAM,MAAM,QAAS,UAAU,KAAG,UAExC,CAAA;IAEM,MAAM,MAAM,QAAS,UAAU,KAAG,UAExC,CAAA;CACF"}
@@ -1,365 +1,34 @@
1
- /*eslint-disable*/
2
- import $protobuf from "protobufjs/minimal.js";
3
-
4
- // Common aliases
5
- const $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util;
6
-
7
- // Exported root namespace
8
- const $root = $protobuf.roots["libp2p-peer-record"] || ($protobuf.roots["libp2p-peer-record"] = {});
9
-
10
- export const PeerRecord = $root.PeerRecord = (() => {
11
-
12
- /**
13
- * Properties of a PeerRecord.
14
- * @exports IPeerRecord
15
- * @interface IPeerRecord
16
- * @property {Uint8Array|null} [peerId] PeerRecord peerId
17
- * @property {number|null} [seq] PeerRecord seq
18
- * @property {Array.<PeerRecord.IAddressInfo>|null} [addresses] PeerRecord addresses
19
- */
20
-
21
- /**
22
- * Constructs a new PeerRecord.
23
- * @exports PeerRecord
24
- * @classdesc Represents a PeerRecord.
25
- * @implements IPeerRecord
26
- * @constructor
27
- * @param {IPeerRecord=} [p] Properties to set
28
- */
29
- function PeerRecord(p) {
30
- this.addresses = [];
31
- if (p)
32
- for (var ks = Object.keys(p), i = 0; i < ks.length; ++i)
33
- if (p[ks[i]] != null)
34
- this[ks[i]] = p[ks[i]];
35
- }
36
-
37
- /**
38
- * PeerRecord peerId.
39
- * @member {Uint8Array} peerId
40
- * @memberof PeerRecord
41
- * @instance
42
- */
43
- PeerRecord.prototype.peerId = $util.newBuffer([]);
44
-
45
- /**
46
- * PeerRecord seq.
47
- * @member {number} seq
48
- * @memberof PeerRecord
49
- * @instance
50
- */
51
- PeerRecord.prototype.seq = $util.Long ? $util.Long.fromBits(0,0,true) : 0;
52
-
53
- /**
54
- * PeerRecord addresses.
55
- * @member {Array.<PeerRecord.IAddressInfo>} addresses
56
- * @memberof PeerRecord
57
- * @instance
58
- */
59
- PeerRecord.prototype.addresses = $util.emptyArray;
60
-
61
- /**
62
- * Encodes the specified PeerRecord message. Does not implicitly {@link PeerRecord.verify|verify} messages.
63
- * @function encode
64
- * @memberof PeerRecord
65
- * @static
66
- * @param {IPeerRecord} m PeerRecord message or plain object to encode
67
- * @param {$protobuf.Writer} [w] Writer to encode to
68
- * @returns {$protobuf.Writer} Writer
69
- */
70
- PeerRecord.encode = function encode(m, w) {
71
- if (!w)
72
- w = $Writer.create();
73
- if (m.peerId != null && Object.hasOwnProperty.call(m, "peerId"))
74
- w.uint32(10).bytes(m.peerId);
75
- if (m.seq != null && Object.hasOwnProperty.call(m, "seq"))
76
- w.uint32(16).uint64(m.seq);
77
- if (m.addresses != null && m.addresses.length) {
78
- for (var i = 0; i < m.addresses.length; ++i)
79
- $root.PeerRecord.AddressInfo.encode(m.addresses[i], w.uint32(26).fork()).ldelim();
80
- }
81
- return w;
82
- };
83
-
84
- /**
85
- * Decodes a PeerRecord message from the specified reader or buffer.
86
- * @function decode
87
- * @memberof PeerRecord
88
- * @static
89
- * @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from
90
- * @param {number} [l] Message length if known beforehand
91
- * @returns {PeerRecord} PeerRecord
92
- * @throws {Error} If the payload is not a reader or valid buffer
93
- * @throws {$protobuf.util.ProtocolError} If required fields are missing
94
- */
95
- PeerRecord.decode = function decode(r, l) {
96
- if (!(r instanceof $Reader))
97
- r = $Reader.create(r);
98
- var c = l === undefined ? r.len : r.pos + l, m = new $root.PeerRecord();
99
- while (r.pos < c) {
100
- var t = r.uint32();
101
- switch (t >>> 3) {
102
- case 1:
103
- m.peerId = r.bytes();
104
- break;
105
- case 2:
106
- m.seq = r.uint64();
107
- break;
108
- case 3:
109
- if (!(m.addresses && m.addresses.length))
110
- m.addresses = [];
111
- m.addresses.push($root.PeerRecord.AddressInfo.decode(r, r.uint32()));
112
- break;
113
- default:
114
- r.skipType(t & 7);
115
- break;
116
- }
117
- }
118
- return m;
119
- };
120
-
121
- /**
122
- * Creates a PeerRecord message from a plain object. Also converts values to their respective internal types.
123
- * @function fromObject
124
- * @memberof PeerRecord
125
- * @static
126
- * @param {Object.<string,*>} d Plain object
127
- * @returns {PeerRecord} PeerRecord
128
- */
129
- PeerRecord.fromObject = function fromObject(d) {
130
- if (d instanceof $root.PeerRecord)
131
- return d;
132
- var m = new $root.PeerRecord();
133
- if (d.peerId != null) {
134
- if (typeof d.peerId === "string")
135
- $util.base64.decode(d.peerId, m.peerId = $util.newBuffer($util.base64.length(d.peerId)), 0);
136
- else if (d.peerId.length)
137
- m.peerId = d.peerId;
138
- }
139
- if (d.seq != null) {
140
- if ($util.Long)
141
- (m.seq = $util.Long.fromValue(d.seq)).unsigned = true;
142
- else if (typeof d.seq === "string")
143
- m.seq = parseInt(d.seq, 10);
144
- else if (typeof d.seq === "number")
145
- m.seq = d.seq;
146
- else if (typeof d.seq === "object")
147
- m.seq = new $util.LongBits(d.seq.low >>> 0, d.seq.high >>> 0).toNumber(true);
148
- }
149
- if (d.addresses) {
150
- if (!Array.isArray(d.addresses))
151
- throw TypeError(".PeerRecord.addresses: array expected");
152
- m.addresses = [];
153
- for (var i = 0; i < d.addresses.length; ++i) {
154
- if (typeof d.addresses[i] !== "object")
155
- throw TypeError(".PeerRecord.addresses: object expected");
156
- m.addresses[i] = $root.PeerRecord.AddressInfo.fromObject(d.addresses[i]);
157
- }
158
- }
159
- return m;
160
- };
161
-
162
- /**
163
- * Creates a plain object from a PeerRecord message. Also converts values to other types if specified.
164
- * @function toObject
165
- * @memberof PeerRecord
166
- * @static
167
- * @param {PeerRecord} m PeerRecord
168
- * @param {$protobuf.IConversionOptions} [o] Conversion options
169
- * @returns {Object.<string,*>} Plain object
170
- */
171
- PeerRecord.toObject = function toObject(m, o) {
172
- if (!o)
173
- o = {};
174
- var d = {};
175
- if (o.arrays || o.defaults) {
176
- d.addresses = [];
177
- }
178
- if (o.defaults) {
179
- if (o.bytes === String)
180
- d.peerId = "";
181
- else {
182
- d.peerId = [];
183
- if (o.bytes !== Array)
184
- d.peerId = $util.newBuffer(d.peerId);
185
- }
186
- if ($util.Long) {
187
- var n = new $util.Long(0, 0, true);
188
- d.seq = o.longs === String ? n.toString() : o.longs === Number ? n.toNumber() : n;
189
- } else
190
- d.seq = o.longs === String ? "0" : 0;
191
- }
192
- if (m.peerId != null && m.hasOwnProperty("peerId")) {
193
- d.peerId = o.bytes === String ? $util.base64.encode(m.peerId, 0, m.peerId.length) : o.bytes === Array ? Array.prototype.slice.call(m.peerId) : m.peerId;
194
- }
195
- if (m.seq != null && m.hasOwnProperty("seq")) {
196
- if (typeof m.seq === "number")
197
- d.seq = o.longs === String ? String(m.seq) : m.seq;
198
- else
199
- d.seq = o.longs === String ? $util.Long.prototype.toString.call(m.seq) : o.longs === Number ? new $util.LongBits(m.seq.low >>> 0, m.seq.high >>> 0).toNumber(true) : m.seq;
200
- }
201
- if (m.addresses && m.addresses.length) {
202
- d.addresses = [];
203
- for (var j = 0; j < m.addresses.length; ++j) {
204
- d.addresses[j] = $root.PeerRecord.AddressInfo.toObject(m.addresses[j], o);
205
- }
206
- }
207
- return d;
208
- };
209
-
210
- /**
211
- * Converts this PeerRecord to JSON.
212
- * @function toJSON
213
- * @memberof PeerRecord
214
- * @instance
215
- * @returns {Object.<string,*>} JSON object
216
- */
217
- PeerRecord.prototype.toJSON = function toJSON() {
218
- return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
219
- };
220
-
221
- PeerRecord.AddressInfo = (function() {
222
-
223
- /**
224
- * Properties of an AddressInfo.
225
- * @memberof PeerRecord
226
- * @interface IAddressInfo
227
- * @property {Uint8Array|null} [multiaddr] AddressInfo multiaddr
228
- */
229
-
230
- /**
231
- * Constructs a new AddressInfo.
232
- * @memberof PeerRecord
233
- * @classdesc Represents an AddressInfo.
234
- * @implements IAddressInfo
235
- * @constructor
236
- * @param {PeerRecord.IAddressInfo=} [p] Properties to set
237
- */
238
- function AddressInfo(p) {
239
- if (p)
240
- for (var ks = Object.keys(p), i = 0; i < ks.length; ++i)
241
- if (p[ks[i]] != null)
242
- this[ks[i]] = p[ks[i]];
243
- }
244
-
245
- /**
246
- * AddressInfo multiaddr.
247
- * @member {Uint8Array} multiaddr
248
- * @memberof PeerRecord.AddressInfo
249
- * @instance
250
- */
251
- AddressInfo.prototype.multiaddr = $util.newBuffer([]);
252
-
253
- /**
254
- * Encodes the specified AddressInfo message. Does not implicitly {@link PeerRecord.AddressInfo.verify|verify} messages.
255
- * @function encode
256
- * @memberof PeerRecord.AddressInfo
257
- * @static
258
- * @param {PeerRecord.IAddressInfo} m AddressInfo message or plain object to encode
259
- * @param {$protobuf.Writer} [w] Writer to encode to
260
- * @returns {$protobuf.Writer} Writer
261
- */
262
- AddressInfo.encode = function encode(m, w) {
263
- if (!w)
264
- w = $Writer.create();
265
- if (m.multiaddr != null && Object.hasOwnProperty.call(m, "multiaddr"))
266
- w.uint32(10).bytes(m.multiaddr);
267
- return w;
1
+ /* eslint-disable import/export */
2
+ /* eslint-disable @typescript-eslint/no-namespace */
3
+ import { encodeMessage, decodeMessage, message, bytes, uint64 } from 'protons-runtime';
4
+ export var PeerRecord;
5
+ (function (PeerRecord) {
6
+ let AddressInfo;
7
+ (function (AddressInfo) {
8
+ AddressInfo.codec = () => {
9
+ return message({
10
+ 1: { name: 'multiaddr', codec: bytes }
11
+ });
268
12
  };
269
-
270
- /**
271
- * Decodes an AddressInfo message from the specified reader or buffer.
272
- * @function decode
273
- * @memberof PeerRecord.AddressInfo
274
- * @static
275
- * @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from
276
- * @param {number} [l] Message length if known beforehand
277
- * @returns {PeerRecord.AddressInfo} AddressInfo
278
- * @throws {Error} If the payload is not a reader or valid buffer
279
- * @throws {$protobuf.util.ProtocolError} If required fields are missing
280
- */
281
- AddressInfo.decode = function decode(r, l) {
282
- if (!(r instanceof $Reader))
283
- r = $Reader.create(r);
284
- var c = l === undefined ? r.len : r.pos + l, m = new $root.PeerRecord.AddressInfo();
285
- while (r.pos < c) {
286
- var t = r.uint32();
287
- switch (t >>> 3) {
288
- case 1:
289
- m.multiaddr = r.bytes();
290
- break;
291
- default:
292
- r.skipType(t & 7);
293
- break;
294
- }
295
- }
296
- return m;
13
+ AddressInfo.encode = (obj) => {
14
+ return encodeMessage(obj, AddressInfo.codec());
297
15
  };
298
-
299
- /**
300
- * Creates an AddressInfo message from a plain object. Also converts values to their respective internal types.
301
- * @function fromObject
302
- * @memberof PeerRecord.AddressInfo
303
- * @static
304
- * @param {Object.<string,*>} d Plain object
305
- * @returns {PeerRecord.AddressInfo} AddressInfo
306
- */
307
- AddressInfo.fromObject = function fromObject(d) {
308
- if (d instanceof $root.PeerRecord.AddressInfo)
309
- return d;
310
- var m = new $root.PeerRecord.AddressInfo();
311
- if (d.multiaddr != null) {
312
- if (typeof d.multiaddr === "string")
313
- $util.base64.decode(d.multiaddr, m.multiaddr = $util.newBuffer($util.base64.length(d.multiaddr)), 0);
314
- else if (d.multiaddr.length)
315
- m.multiaddr = d.multiaddr;
316
- }
317
- return m;
16
+ AddressInfo.decode = (buf) => {
17
+ return decodeMessage(buf, AddressInfo.codec());
318
18
  };
319
-
320
- /**
321
- * Creates a plain object from an AddressInfo message. Also converts values to other types if specified.
322
- * @function toObject
323
- * @memberof PeerRecord.AddressInfo
324
- * @static
325
- * @param {PeerRecord.AddressInfo} m AddressInfo
326
- * @param {$protobuf.IConversionOptions} [o] Conversion options
327
- * @returns {Object.<string,*>} Plain object
328
- */
329
- AddressInfo.toObject = function toObject(m, o) {
330
- if (!o)
331
- o = {};
332
- var d = {};
333
- if (o.defaults) {
334
- if (o.bytes === String)
335
- d.multiaddr = "";
336
- else {
337
- d.multiaddr = [];
338
- if (o.bytes !== Array)
339
- d.multiaddr = $util.newBuffer(d.multiaddr);
340
- }
341
- }
342
- if (m.multiaddr != null && m.hasOwnProperty("multiaddr")) {
343
- d.multiaddr = o.bytes === String ? $util.base64.encode(m.multiaddr, 0, m.multiaddr.length) : o.bytes === Array ? Array.prototype.slice.call(m.multiaddr) : m.multiaddr;
344
- }
345
- return d;
346
- };
347
-
348
- /**
349
- * Converts this AddressInfo to JSON.
350
- * @function toJSON
351
- * @memberof PeerRecord.AddressInfo
352
- * @instance
353
- * @returns {Object.<string,*>} JSON object
354
- */
355
- AddressInfo.prototype.toJSON = function toJSON() {
356
- return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
357
- };
358
-
359
- return AddressInfo;
360
- })();
361
-
362
- return PeerRecord;
363
- })();
364
-
365
- export { $root as default };
19
+ })(AddressInfo = PeerRecord.AddressInfo || (PeerRecord.AddressInfo = {}));
20
+ 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
+ });
26
+ };
27
+ PeerRecord.encode = (obj) => {
28
+ return encodeMessage(obj, PeerRecord.codec());
29
+ };
30
+ PeerRecord.decode = (buf) => {
31
+ return decodeMessage(buf, PeerRecord.codec());
32
+ };
33
+ })(PeerRecord || (PeerRecord = {}));
34
+ //# sourceMappingURL=peer-record.js.map
@@ -0,0 +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;AAQtF,MAAM,KAAW,UAAU,CAoC1B;AApCD,WAAiB,UAAU;IAKzB,IAAiB,WAAW,CAc3B;IAdD,WAAiB,WAAW;QACb,iBAAK,GAAG,GAAG,EAAE;YACxB,OAAO,OAAO,CAAc;gBAC1B,CAAC,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE;aACvC,CAAC,CAAA;QACJ,CAAC,CAAA;QAEY,kBAAM,GAAG,CAAC,GAAgB,EAAc,EAAE;YACrD,OAAO,aAAa,CAAC,GAAG,EAAE,WAAW,CAAC,KAAK,EAAE,CAAC,CAAA;QAChD,CAAC,CAAA;QAEY,kBAAM,GAAG,CAAC,GAAe,EAAe,EAAE;YACrD,OAAO,aAAa,CAAC,GAAG,EAAE,WAAW,CAAC,KAAK,EAAE,CAAC,CAAA;QAChD,CAAC,CAAA;IACH,CAAC,EAdgB,WAAW,GAAX,sBAAW,KAAX,sBAAW,QAc3B;IAEY,gBAAK,GAAG,GAAG,EAAE;QACxB,OAAO,OAAO,CAAa;YACzB,CAAC,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE;YACnC,CAAC,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE;YACjC,CAAC,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,UAAU,CAAC,WAAW,CAAC,KAAK,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE;SAC/E,CAAC,CAAA;IACJ,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,GAAe,EAAc,EAAE;QACpD,OAAO,aAAa,CAAC,GAAG,EAAE,UAAU,CAAC,KAAK,EAAE,CAAC,CAAA;IAC/C,CAAC,CAAA;AACH,CAAC,EApCgB,UAAU,KAAV,UAAU,QAoC1B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/peer-record",
3
- "version": "1.0.5",
3
+ "version": "1.0.8",
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-interfaces/tree/master/packages/libp2p-peer-record#readme",
@@ -125,30 +125,25 @@
125
125
  ]
126
126
  },
127
127
  "scripts": {
128
+ "clean": "aegir clean",
128
129
  "lint": "aegir lint",
129
- "dep-check": "aegir dep-check dist/src/**/*.js dist/test/**/*.js",
130
- "build": "tsc && npm run build:copy-proto-files",
131
- "generate": "npm run generate:envelope && npm run generate:envelope-types && npm run generate:peer-record && npm run generate:peer-record-types",
132
- "generate:envelope": "pbjs -t static-module -w es6 -r libp2p-peer-record-envelope --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/envelope/envelope.js ./src/envelope/envelope.proto",
133
- "generate:envelope-types": "pbts -o src/envelope/envelope.d.ts src/envelope/envelope.js",
134
- "generate:peer-record": "pbjs -t static-module -w es6 -r libp2p-peer-record --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/peer-record/peer-record.js ./src/peer-record/peer-record.proto",
135
- "generate:peer-record-types": "pbts -o src/peer-record/peer-record.d.ts src/peer-record/peer-record.js",
136
- "build:copy-proto-files": "cp src/envelope/envelope.js dist/src/envelope && cp src/envelope/*.d.ts dist/src/envelope && cp src/peer-record/peer-record.js dist/src/peer-record && cp src/peer-record/*.d.ts dist/src/peer-record",
137
- "pretest": "npm run build",
138
- "test": "aegir test -f ./dist/test/*.js -f ./dist/test/**/*.js",
139
- "test:chrome": "npm run test -- -t browser",
140
- "test:chrome-webworker": "npm run test -- -t webworker",
141
- "test:firefox": "npm run test -- -t browser -- --browser firefox",
142
- "test:firefox-webworker": "npm run test -- -t webworker -- --browser firefox",
143
- "test:node": "npm run test -- -t node --cov",
144
- "test:electron-main": "npm run test -- -t electron-main"
130
+ "dep-check": "aegir dep-check",
131
+ "build": "aegir build",
132
+ "test": "aegir test",
133
+ "test:chrome": "aegir test -t browser --cov",
134
+ "test:chrome-webworker": "aegir test -t webworker",
135
+ "test:firefox": "aegir test -t browser -- --browser firefox",
136
+ "test:firefox-webworker": "aegir test -t webworker -- --browser firefox",
137
+ "test:node": "aegir test -t node --cov",
138
+ "test:electron-main": "aegir test -t electron-main",
139
+ "release": "aegir release"
145
140
  },
146
141
  "dependencies": {
147
- "@libp2p/crypto": "^0.22.7",
148
- "@libp2p/interfaces": "^1.3.6",
149
- "@libp2p/logger": "^1.0.3",
150
- "@libp2p/peer-id": "^1.0.4",
151
- "@libp2p/utils": "^1.0.5",
142
+ "@libp2p/crypto": "^0.22.8",
143
+ "@libp2p/interfaces": "^1.3.0",
144
+ "@libp2p/logger": "^1.1.0",
145
+ "@libp2p/peer-id": "^1.1.0",
146
+ "@libp2p/utils": "^1.0.9",
152
147
  "@multiformats/multiaddr": "^10.1.5",
153
148
  "err-code": "^3.0.1",
154
149
  "interface-datastore": "^6.1.0",
@@ -158,15 +153,16 @@
158
153
  "it-map": "^1.0.6",
159
154
  "it-pipe": "^2.0.3",
160
155
  "multiformats": "^9.6.3",
161
- "protobufjs": "^6.10.2",
156
+ "protons-runtime": "^1.0.2",
162
157
  "uint8arrays": "^3.0.0",
163
158
  "varint": "^6.0.0"
164
159
  },
165
160
  "devDependencies": {
166
- "@libp2p/interface-compliance-tests": "^1.1.2",
167
- "@libp2p/peer-id-factory": "^1.0.5",
161
+ "@libp2p/interface-compliance-tests": "^1.1.0",
162
+ "@libp2p/peer-id-factory": "^1.0.0",
168
163
  "@types/varint": "^6.0.0",
169
- "aegir": "^36.1.3",
164
+ "aegir": "^37.0.7",
165
+ "protons": "^3.0.2",
170
166
  "sinon": "^13.0.1"
171
167
  }
172
168
  }
@@ -0,0 +1,30 @@
1
+ /* eslint-disable import/export */
2
+ /* eslint-disable @typescript-eslint/no-namespace */
3
+
4
+ import { encodeMessage, decodeMessage, message, bytes } from 'protons-runtime'
5
+
6
+ export interface Envelope {
7
+ publicKey: Uint8Array
8
+ payloadType: Uint8Array
9
+ payload: Uint8Array
10
+ signature: Uint8Array
11
+ }
12
+
13
+ export namespace Envelope {
14
+ export const codec = () => {
15
+ return message<Envelope>({
16
+ 1: { name: 'publicKey', codec: bytes },
17
+ 2: { name: 'payloadType', codec: bytes },
18
+ 3: { name: 'payload', codec: bytes },
19
+ 5: { name: 'signature', codec: bytes }
20
+ })
21
+ }
22
+
23
+ export const encode = (obj: Envelope): Uint8Array => {
24
+ return encodeMessage(obj, Envelope.codec())
25
+ }
26
+
27
+ export const decode = (buf: Uint8Array): Envelope => {
28
+ return decodeMessage(buf, Envelope.codec())
29
+ }
30
+ }
@@ -10,7 +10,7 @@ import { peerIdFromKeys } from '@libp2p/peer-id'
10
10
  import type { PeerId } from '@libp2p/interfaces/peer-id'
11
11
  import type { Record, Envelope } from '@libp2p/interfaces/record'
12
12
 
13
- export interface EnvelopeOptions {
13
+ export interface EnvelopeInit {
14
14
  peerId: PeerId
15
15
  payloadType: Uint8Array
16
16
  payload: Uint8Array
@@ -84,8 +84,8 @@ export class RecordEnvelope implements Envelope {
84
84
  * The Envelope is responsible for keeping an arbitrary signed record
85
85
  * by a libp2p peer.
86
86
  */
87
- constructor (options: EnvelopeOptions) {
88
- const { peerId, payloadType, payload, signature } = options
87
+ constructor (init: EnvelopeInit) {
88
+ const { peerId, payloadType, payload, signature } = init
89
89
 
90
90
  this.peerId = peerId
91
91
  this.payloadType = payloadType
@@ -97,13 +97,17 @@ export class RecordEnvelope implements Envelope {
97
97
  * Marshal the envelope content
98
98
  */
99
99
  marshal () {
100
+ if (this.peerId.publicKey == null) {
101
+ throw new Error('Missing public key')
102
+ }
103
+
100
104
  if (this.marshaled == null) {
101
105
  this.marshaled = Protobuf.encode({
102
106
  publicKey: this.peerId.publicKey,
103
107
  payloadType: this.payloadType,
104
108
  payload: this.payload,
105
109
  signature: this.signature
106
- }).finish()
110
+ })
107
111
  }
108
112
 
109
113
  return this.marshaled
@@ -8,7 +8,7 @@ import {
8
8
  ENVELOPE_PAYLOAD_TYPE_PEER_RECORD
9
9
  } from './consts.js'
10
10
 
11
- export interface PeerRecordOptions {
11
+ export interface PeerRecordInit {
12
12
  peerId: PeerId
13
13
 
14
14
  /**
@@ -19,7 +19,7 @@ export interface PeerRecordOptions {
19
19
  /**
20
20
  * Monotonically-increasing sequence counter that's used to order PeerRecords in time.
21
21
  */
22
- seqNumber?: number
22
+ seqNumber?: bigint
23
23
  }
24
24
 
25
25
  /**
@@ -34,7 +34,7 @@ export class PeerRecord {
34
34
  const peerRecord = Protobuf.decode(buf)
35
35
  const peerId = peerIdFromBytes(peerRecord.peerId)
36
36
  const multiaddrs = (peerRecord.addresses ?? []).map((a) => new Multiaddr(a.multiaddr))
37
- const seqNumber = Number(peerRecord.seq)
37
+ const seqNumber = peerRecord.seq
38
38
 
39
39
  return new PeerRecord({ peerId, multiaddrs, seqNumber })
40
40
  }
@@ -44,17 +44,17 @@ export class PeerRecord {
44
44
 
45
45
  public peerId: PeerId
46
46
  public multiaddrs: Multiaddr[]
47
- public seqNumber: number
47
+ public seqNumber: bigint
48
48
  public domain = PeerRecord.DOMAIN
49
49
  public codec = PeerRecord.CODEC
50
50
  private marshaled?: Uint8Array
51
51
 
52
- constructor (options: PeerRecordOptions) {
53
- const { peerId, multiaddrs, seqNumber } = options
52
+ constructor (init: PeerRecordInit) {
53
+ const { peerId, multiaddrs, seqNumber } = init
54
54
 
55
55
  this.peerId = peerId
56
56
  this.multiaddrs = multiaddrs ?? []
57
- this.seqNumber = seqNumber ?? Date.now()
57
+ this.seqNumber = seqNumber ?? BigInt(Date.now())
58
58
  }
59
59
 
60
60
  /**
@@ -64,11 +64,11 @@ export class PeerRecord {
64
64
  if (this.marshaled == null) {
65
65
  this.marshaled = Protobuf.encode({
66
66
  peerId: this.peerId.toBytes(),
67
- seq: this.seqNumber,
67
+ seq: BigInt(this.seqNumber),
68
68
  addresses: this.multiaddrs.map((m) => ({
69
69
  multiaddr: m.bytes
70
70
  }))
71
- }).finish()
71
+ })
72
72
  }
73
73
 
74
74
  return this.marshaled
@@ -0,0 +1,48 @@
1
+ /* eslint-disable import/export */
2
+ /* eslint-disable @typescript-eslint/no-namespace */
3
+
4
+ import { encodeMessage, decodeMessage, message, bytes, uint64 } from 'protons-runtime'
5
+
6
+ export interface PeerRecord {
7
+ peerId: Uint8Array
8
+ seq: bigint
9
+ addresses: PeerRecord.AddressInfo[]
10
+ }
11
+
12
+ export namespace PeerRecord {
13
+ export interface AddressInfo {
14
+ multiaddr: Uint8Array
15
+ }
16
+
17
+ export namespace AddressInfo {
18
+ export const codec = () => {
19
+ return message<AddressInfo>({
20
+ 1: { name: 'multiaddr', codec: bytes }
21
+ })
22
+ }
23
+
24
+ export const encode = (obj: AddressInfo): Uint8Array => {
25
+ return encodeMessage(obj, AddressInfo.codec())
26
+ }
27
+
28
+ export const decode = (buf: Uint8Array): AddressInfo => {
29
+ return decodeMessage(buf, AddressInfo.codec())
30
+ }
31
+ }
32
+
33
+ export const codec = () => {
34
+ return message<PeerRecord>({
35
+ 1: { name: 'peerId', codec: bytes },
36
+ 2: { name: 'seq', codec: uint64 },
37
+ 3: { name: 'addresses', codec: PeerRecord.AddressInfo.codec(), repeats: true }
38
+ })
39
+ }
40
+
41
+ export const encode = (obj: PeerRecord): Uint8Array => {
42
+ return encodeMessage(obj, PeerRecord.codec())
43
+ }
44
+
45
+ export const decode = (buf: Uint8Array): PeerRecord => {
46
+ return decodeMessage(buf, PeerRecord.codec())
47
+ }
48
+ }