@libp2p/peer-record 3.0.0 → 4.0.2
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/src/envelope/envelope.d.ts +2 -1
- package/dist/src/envelope/envelope.d.ts.map +1 -1
- package/dist/src/envelope/envelope.js +82 -7
- package/dist/src/envelope/envelope.js.map +1 -1
- package/dist/src/envelope/index.d.ts +3 -2
- package/dist/src/envelope/index.d.ts.map +1 -1
- package/dist/src/envelope/index.js +14 -21
- package/dist/src/envelope/index.js.map +1 -1
- package/dist/src/peer-record/index.d.ts +2 -1
- package/dist/src/peer-record/index.d.ts.map +1 -1
- package/dist/src/peer-record/index.js.map +1 -1
- package/dist/src/peer-record/peer-record.d.ts +3 -2
- package/dist/src/peer-record/peer-record.d.ts.map +1 -1
- package/dist/src/peer-record/peer-record.js +106 -9
- package/dist/src/peer-record/peer-record.js.map +1 -1
- package/package.json +16 -10
- package/src/envelope/envelope.ts +95 -8
- package/src/envelope/index.ts +23 -25
- package/src/peer-record/index.ts +2 -1
- package/src/peer-record/peer-record.ts +126 -11
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Uint8ArrayList } from 'uint8arraylist';
|
|
1
2
|
import type { Codec } from 'protons-runtime';
|
|
2
3
|
export interface Envelope {
|
|
3
4
|
publicKey: Uint8Array;
|
|
@@ -8,6 +9,6 @@ export interface Envelope {
|
|
|
8
9
|
export declare namespace Envelope {
|
|
9
10
|
const codec: () => Codec<Envelope>;
|
|
10
11
|
const encode: (obj: Envelope) => Uint8Array;
|
|
11
|
-
const decode: (buf: Uint8Array) => Envelope;
|
|
12
|
+
const decode: (buf: Uint8Array | Uint8ArrayList) => Envelope;
|
|
12
13
|
}
|
|
13
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;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;
|
|
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
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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,
|
|
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,MAAM,iBAAiB,CAAA;AAWvE,MAAM,KAAW,QAAQ,CAuGxB;AAvGD,WAAiB,QAAQ;IACvB,IAAI,MAAuB,CAAA;IAEd,cAAK,GAAG,GAAoB,EAAE;QACzC,IAAI,MAAM,IAAI,IAAI,EAAE;YAClB,MAAM,GAAG,OAAO,CA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IAAI,IAAI,EAAE;oBACvB,MAAM,IAAI,KAAK,CAAC,8EAA8E,CAAC,CAAA;iBAChG;gBAED,IAAI,GAAG,CAAC,SAAS,IAAI,IAAI,EAAE;oBACzB,MAAM,IAAI,KAAK,CAAC,gFAAgF,CAAC,CAAA;iBAClG;gBAED,OAAO,GAAG,CAAA;YACZ,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"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { PeerId } from '@libp2p/interface-peer-id';
|
|
2
2
|
import type { Record, Envelope } from '@libp2p/interface-record';
|
|
3
|
+
import { Uint8ArrayList } from 'uint8arraylist';
|
|
3
4
|
export interface EnvelopeInit {
|
|
4
5
|
peerId: PeerId;
|
|
5
6
|
payloadType: Uint8Array;
|
|
@@ -10,7 +11,7 @@ export declare class RecordEnvelope implements Envelope {
|
|
|
10
11
|
/**
|
|
11
12
|
* Unmarshal a serialized Envelope protobuf message
|
|
12
13
|
*/
|
|
13
|
-
static createFromProtobuf: (data: Uint8Array) => Promise<RecordEnvelope>;
|
|
14
|
+
static createFromProtobuf: (data: Uint8Array | Uint8ArrayList) => Promise<RecordEnvelope>;
|
|
14
15
|
/**
|
|
15
16
|
* Seal marshals the given Record, places the marshaled bytes inside an Envelope
|
|
16
17
|
* and signs it with the given peerId's private key
|
|
@@ -20,7 +21,7 @@ export declare class RecordEnvelope implements Envelope {
|
|
|
20
21
|
* Open and certify a given marshalled envelope.
|
|
21
22
|
* Data is unmarshalled and the signature validated for the given domain.
|
|
22
23
|
*/
|
|
23
|
-
static openAndCertify: (data: Uint8Array, domain: string) => Promise<RecordEnvelope>;
|
|
24
|
+
static openAndCertify: (data: Uint8Array | Uint8ArrayList, domain: string) => Promise<RecordEnvelope>;
|
|
24
25
|
peerId: PeerId;
|
|
25
26
|
payloadType: Uint8Array;
|
|
26
27
|
payload: Uint8Array;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/envelope/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/envelope/index.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAG/C,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAA;IACd,WAAW,EAAE,UAAU,CAAA;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,13 +1,13 @@
|
|
|
1
1
|
var _a;
|
|
2
2
|
import errCode from 'err-code';
|
|
3
|
-
import { concat as uint8arraysConcat } from 'uint8arrays/concat';
|
|
4
3
|
import { fromString as uint8arraysFromString } from 'uint8arrays/from-string';
|
|
4
|
+
import { equals as uint8ArrayEquals } from 'uint8arrays/equals';
|
|
5
5
|
import { unmarshalPrivateKey, unmarshalPublicKey } from '@libp2p/crypto/keys';
|
|
6
|
-
import varint from 'varint';
|
|
7
|
-
import { equals as uint8arraysEquals } from 'uint8arrays/equals';
|
|
8
6
|
import { codes } from '../errors.js';
|
|
9
7
|
import { Envelope as Protobuf } from './envelope.js';
|
|
10
8
|
import { peerIdFromKeys } from '@libp2p/peer-id';
|
|
9
|
+
import { Uint8ArrayList } from 'uint8arraylist';
|
|
10
|
+
import { unsigned } from 'uint8-varint';
|
|
11
11
|
export class RecordEnvelope {
|
|
12
12
|
/**
|
|
13
13
|
* The Envelope is responsible for keeping an arbitrary signed record
|
|
@@ -31,7 +31,7 @@ export class RecordEnvelope {
|
|
|
31
31
|
this.marshaled = Protobuf.encode({
|
|
32
32
|
publicKey: this.peerId.publicKey,
|
|
33
33
|
payloadType: this.payloadType,
|
|
34
|
-
payload: this.payload,
|
|
34
|
+
payload: this.payload.subarray(),
|
|
35
35
|
signature: this.signature
|
|
36
36
|
});
|
|
37
37
|
}
|
|
@@ -41,7 +41,7 @@ export class RecordEnvelope {
|
|
|
41
41
|
* Verifies if the other Envelope is identical to this one
|
|
42
42
|
*/
|
|
43
43
|
equals(other) {
|
|
44
|
-
return
|
|
44
|
+
return uint8ArrayEquals(this.marshal(), other.marshal());
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
47
47
|
* Validate envelope data signature for the given domain
|
|
@@ -52,7 +52,7 @@ export class RecordEnvelope {
|
|
|
52
52
|
throw new Error('Missing public key');
|
|
53
53
|
}
|
|
54
54
|
const key = unmarshalPublicKey(this.peerId.publicKey);
|
|
55
|
-
return await key.verify(signData, this.signature);
|
|
55
|
+
return await key.verify(signData.subarray(), this.signature);
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
_a = RecordEnvelope;
|
|
@@ -74,15 +74,15 @@ RecordEnvelope.createFromProtobuf = async (data) => {
|
|
|
74
74
|
* and signs it with the given peerId's private key
|
|
75
75
|
*/
|
|
76
76
|
RecordEnvelope.seal = async (record, peerId) => {
|
|
77
|
+
if (peerId.privateKey == null) {
|
|
78
|
+
throw new Error('Missing private key');
|
|
79
|
+
}
|
|
77
80
|
const domain = record.domain;
|
|
78
81
|
const payloadType = record.codec;
|
|
79
82
|
const payload = record.marshal();
|
|
80
83
|
const signData = formatSignaturePayload(domain, payloadType, payload);
|
|
81
|
-
if (peerId.privateKey == null) {
|
|
82
|
-
throw new Error('Missing private key');
|
|
83
|
-
}
|
|
84
84
|
const key = await unmarshalPrivateKey(peerId.privateKey);
|
|
85
|
-
const signature = await key.sign(signData);
|
|
85
|
+
const signature = await key.sign(signData.subarray());
|
|
86
86
|
return new RecordEnvelope({
|
|
87
87
|
peerId,
|
|
88
88
|
payloadType,
|
|
@@ -114,16 +114,9 @@ const formatSignaturePayload = (domain, payloadType, payload) => {
|
|
|
114
114
|
// - The length of the payload field in bytes
|
|
115
115
|
// - The value of the payload field
|
|
116
116
|
const domainUint8Array = uint8arraysFromString(domain);
|
|
117
|
-
const domainLength =
|
|
118
|
-
const payloadTypeLength =
|
|
119
|
-
const payloadLength =
|
|
120
|
-
return
|
|
121
|
-
new Uint8Array(domainLength),
|
|
122
|
-
domainUint8Array,
|
|
123
|
-
new Uint8Array(payloadTypeLength),
|
|
124
|
-
payloadType,
|
|
125
|
-
new Uint8Array(payloadLength),
|
|
126
|
-
payload
|
|
127
|
-
]);
|
|
117
|
+
const domainLength = unsigned.encode(domainUint8Array.byteLength);
|
|
118
|
+
const payloadTypeLength = unsigned.encode(payloadType.length);
|
|
119
|
+
const payloadLength = unsigned.encode(payload.length);
|
|
120
|
+
return new Uint8ArrayList(domainLength, domainUint8Array, payloadTypeLength, payloadType, payloadLength, payload);
|
|
128
121
|
};
|
|
129
122
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/envelope/index.ts"],"names":[],"mappings":";AAAA,OAAO,OAAO,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/envelope/index.ts"],"names":[],"mappings":";AAAA,OAAO,OAAO,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,UAAU,IAAI,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;AAC7E,OAAO,EAAE,MAAM,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAC/D,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAC7E,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AACpC,OAAO,EAAE,QAAQ,IAAI,QAAQ,EAAE,MAAM,eAAe,CAAA;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAGhD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AASvC,MAAM,OAAO,cAAc;IA6DzB;;;OAGG;IACH,YAAa,IAAkB;QAC7B,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,IAAI,CAAA;QAExD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;QAC9B,IAAI,CAAC,OAAO,GA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CAAC,MAAM,CAAC,CAAA;IAE7C,IAAI,CAAC,KAAK,EAAE;QACV,MAAM,OAAO,CAAC,IAAI,KAAK,CAAC,sDAAsD,CAAC,EAAE,KAAK,CAAC,uBAAuB,CAAC,CAAA;KAChH;IAED,OAAO,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"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Multiaddr } from '@multiformats/multiaddr';
|
|
2
2
|
import type { PeerId } from '@libp2p/interface-peer-id';
|
|
3
|
+
import type { Uint8ArrayList } from 'uint8arraylist';
|
|
3
4
|
export interface PeerRecordInit {
|
|
4
5
|
peerId: PeerId;
|
|
5
6
|
/**
|
|
@@ -19,7 +20,7 @@ export declare class PeerRecord {
|
|
|
19
20
|
/**
|
|
20
21
|
* Unmarshal Peer Record Protobuf
|
|
21
22
|
*/
|
|
22
|
-
static createFromProtobuf: (buf: Uint8Array) => PeerRecord;
|
|
23
|
+
static createFromProtobuf: (buf: Uint8Array | Uint8ArrayList) => PeerRecord;
|
|
23
24
|
static DOMAIN: string;
|
|
24
25
|
static CODEC: Uint8Array;
|
|
25
26
|
peerId: PeerId;
|
|
@@ -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;
|
|
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,CAAA;CACnB;AAED;;;GAGG;AACH,qBAAa,UAAU;IACrB;;OAEG;IACH,MAAM,CAAC,kBAAkB,QAAS,UAAU,GAAG,cAAc,KAAG,UAAU,CAOzE;IAED,MAAM,CAAC,MAAM,SAA8B;IAC3C,MAAM,CAAC,KAAK,aAAoC;IAEzC,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,SAAS,EAAE,CAAA;IACvB,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,SAAoB;IAC1B,KAAK,aAAmB;IAC/B,OAAO,CAAC,SAAS,CAAC,CAAY;gBAEjB,IAAI,EAAE,cAAc;IAQjC;;OAEG;IACH,OAAO;IAcP;;OAEG;IACH,MAAM,CAAE,KAAK,EAAE,OAAO;CAsBvB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/peer-record/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAEnD,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,EAAE,UAAU,IAAI,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AACzD,OAAO,EACL,2BAA2B,EAC3B,iCAAiC,EAClC,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/peer-record/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAEnD,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,EAAE,UAAU,IAAI,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AACzD,OAAO,EACL,2BAA2B,EAC3B,iCAAiC,EAClC,MAAM,aAAa,CAAA;AAiBpB;;;GAGG;AACH,MAAM,OAAO,UAAU;IAuBrB,YAAa,IAAoB;QAJ1B,WAAM,GAAG,UAAU,CAAC,MAAM,CAAA;QAC1B,UAAK,GAAG,UAAU,CAAC,KAAK,CAAA;QAI7B,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,IAAI,CAAA;QAE9C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,UAAU,GAAG,UAAU,IAAI,EAAE,CAAA;QAClC,IAAI,CAAC,SAAS,GAAG,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;IAClD,CAAC;IAED;;OAEG;IACH,OAAO;QACL,IAAI,IAAI,CAAC,SAAS,IAAI,IAAI,EAAE;YAC1B,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC,M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AG,UAAU,CAAC,GAAG,CAAA;IAEhC,OAAO,IAAI,UAAU,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC,CAAA;AAC1D,CAAC,CAAA;AAEM,iBAAM,GAAG,2BAA2B,CAAA;AACpC,gBAAK,GAAG,iCAAiC,CAAA"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Uint8ArrayList } from 'uint8arraylist';
|
|
1
2
|
import type { Codec } from 'protons-runtime';
|
|
2
3
|
export interface PeerRecord {
|
|
3
4
|
peerId: Uint8Array;
|
|
@@ -11,10 +12,10 @@ export declare namespace PeerRecord {
|
|
|
11
12
|
namespace AddressInfo {
|
|
12
13
|
const codec: () => Codec<AddressInfo>;
|
|
13
14
|
const encode: (obj: AddressInfo) => Uint8Array;
|
|
14
|
-
const decode: (buf: Uint8Array) => AddressInfo;
|
|
15
|
+
const decode: (buf: Uint8Array | Uint8ArrayList) => AddressInfo;
|
|
15
16
|
}
|
|
16
17
|
const codec: () => Codec<PeerRecord>;
|
|
17
18
|
const encode: (obj: PeerRecord) => Uint8Array;
|
|
18
|
-
const decode: (buf: Uint8Array) => PeerRecord;
|
|
19
|
+
const decode: (buf: Uint8Array | Uint8ArrayList) => PeerRecord;
|
|
19
20
|
}
|
|
20
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;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;
|
|
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
|
|
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
|
-
|
|
10
|
-
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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,
|
|
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,MAAM,iBAAiB,CAAA;AAUvE,MAAM,KAAW,UAAU,CAsJ1B;AAtJD,WAAiB,UAAU;IAKzB,IAAiB,WAAW,CA0D3B;IA1DD,WAAiB,WAAW;QAC1B,IAAI,MAA0B,CAAA;QAEjB,iBAAK,GAAG,GAAuB,EAAE;YAC5C,IAAI,MAAM,IAAI,IAAI,EAAE;gBAClB,MAAM,GAAG,OAAO,CAAc,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,GAAG,EAAE,EAAE,EAAE;oBACvD,IAAI,IAAI,CAAC,eAAe,KAAK,KAAK,EAAE;wBAClC,MAAM,CAAC,IAAI,EAAE,CAAA;qBACd;oBAED,IAAI,GAAG,CAAC,SAAS,IAAI,IAAI,EAAE;wBACzB,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;wB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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": "
|
|
3
|
+
"version": "4.0.2",
|
|
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",
|
|
@@ -71,15 +71,15 @@
|
|
|
71
71
|
"release": "patch"
|
|
72
72
|
},
|
|
73
73
|
{
|
|
74
|
-
"type": "
|
|
74
|
+
"type": "docs",
|
|
75
75
|
"release": "patch"
|
|
76
76
|
},
|
|
77
77
|
{
|
|
78
|
-
"type": "
|
|
78
|
+
"type": "test",
|
|
79
79
|
"release": "patch"
|
|
80
80
|
},
|
|
81
81
|
{
|
|
82
|
-
"type": "
|
|
82
|
+
"type": "deps",
|
|
83
83
|
"release": "patch"
|
|
84
84
|
},
|
|
85
85
|
{
|
|
@@ -109,7 +109,11 @@
|
|
|
109
109
|
},
|
|
110
110
|
{
|
|
111
111
|
"type": "docs",
|
|
112
|
-
"section": "
|
|
112
|
+
"section": "Documentation"
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
"type": "deps",
|
|
116
|
+
"section": "Dependencies"
|
|
113
117
|
},
|
|
114
118
|
{
|
|
115
119
|
"type": "test",
|
|
@@ -143,29 +147,31 @@
|
|
|
143
147
|
"dependencies": {
|
|
144
148
|
"@libp2p/crypto": "^1.0.0",
|
|
145
149
|
"@libp2p/interface-peer-id": "^1.0.2",
|
|
146
|
-
"@libp2p/interface-record": "^
|
|
150
|
+
"@libp2p/interface-record": "^2.0.1",
|
|
147
151
|
"@libp2p/logger": "^2.0.0",
|
|
148
152
|
"@libp2p/peer-id": "^1.1.13",
|
|
149
153
|
"@libp2p/utils": "^3.0.0",
|
|
150
154
|
"@multiformats/multiaddr": "^10.1.5",
|
|
151
155
|
"err-code": "^3.0.1",
|
|
152
|
-
"interface-datastore": "^
|
|
156
|
+
"interface-datastore": "^7.0.0",
|
|
153
157
|
"it-all": "^1.0.6",
|
|
154
158
|
"it-filter": "^1.0.3",
|
|
155
159
|
"it-foreach": "^0.1.1",
|
|
156
160
|
"it-map": "^1.0.6",
|
|
157
161
|
"it-pipe": "^2.0.3",
|
|
158
162
|
"multiformats": "^9.6.3",
|
|
159
|
-
"protons-runtime": "^1.0
|
|
163
|
+
"protons-runtime": "^3.1.0",
|
|
164
|
+
"uint8-varint": "^1.0.2",
|
|
165
|
+
"uint8arraylist": "^2.1.0",
|
|
160
166
|
"uint8arrays": "^3.0.0",
|
|
161
167
|
"varint": "^6.0.0"
|
|
162
168
|
},
|
|
163
169
|
"devDependencies": {
|
|
164
|
-
"@libp2p/interface-record-compliance-tests": "^
|
|
170
|
+
"@libp2p/interface-record-compliance-tests": "^2.0.0",
|
|
165
171
|
"@libp2p/peer-id-factory": "^1.0.0",
|
|
166
172
|
"@types/varint": "^6.0.0",
|
|
167
173
|
"aegir": "^37.3.0",
|
|
168
|
-
"protons": "^
|
|
174
|
+
"protons": "^5.1.0",
|
|
169
175
|
"sinon": "^14.0.0"
|
|
170
176
|
}
|
|
171
177
|
}
|
package/src/envelope/envelope.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/* eslint-disable import/export */
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-namespace */
|
|
3
3
|
|
|
4
|
-
import { encodeMessage, decodeMessage, message
|
|
4
|
+
import { encodeMessage, decodeMessage, message } from 'protons-runtime'
|
|
5
|
+
import type { Uint8ArrayList } from 'uint8arraylist'
|
|
5
6
|
import type { Codec } from 'protons-runtime'
|
|
6
7
|
|
|
7
8
|
export interface Envelope {
|
|
@@ -12,20 +13,106 @@ export interface Envelope {
|
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
export namespace Envelope {
|
|
16
|
+
let _codec: Codec<Envelope>
|
|
17
|
+
|
|
15
18
|
export const codec = (): Codec<Envelope> => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
|
22
109
|
}
|
|
23
110
|
|
|
24
111
|
export const encode = (obj: Envelope): Uint8Array => {
|
|
25
112
|
return encodeMessage(obj, Envelope.codec())
|
|
26
113
|
}
|
|
27
114
|
|
|
28
|
-
export const decode = (buf: Uint8Array): Envelope => {
|
|
115
|
+
export const decode = (buf: Uint8Array | Uint8ArrayList): Envelope => {
|
|
29
116
|
return decodeMessage(buf, Envelope.codec())
|
|
30
117
|
}
|
|
31
118
|
}
|
package/src/envelope/index.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import errCode from 'err-code'
|
|
2
|
-
import { concat as uint8arraysConcat } from 'uint8arrays/concat'
|
|
3
2
|
import { fromString as uint8arraysFromString } from 'uint8arrays/from-string'
|
|
3
|
+
import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
|
|
4
4
|
import { unmarshalPrivateKey, unmarshalPublicKey } from '@libp2p/crypto/keys'
|
|
5
|
-
import varint from 'varint'
|
|
6
|
-
import { equals as uint8arraysEquals } from 'uint8arrays/equals'
|
|
7
5
|
import { codes } from '../errors.js'
|
|
8
6
|
import { Envelope as Protobuf } from './envelope.js'
|
|
9
7
|
import { peerIdFromKeys } from '@libp2p/peer-id'
|
|
10
8
|
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
11
9
|
import type { Record, Envelope } from '@libp2p/interface-record'
|
|
10
|
+
import { Uint8ArrayList } from 'uint8arraylist'
|
|
11
|
+
import { unsigned } from 'uint8-varint'
|
|
12
12
|
|
|
13
13
|
export interface EnvelopeInit {
|
|
14
14
|
peerId: PeerId
|
|
@@ -21,7 +21,7 @@ export class RecordEnvelope implements Envelope {
|
|
|
21
21
|
/**
|
|
22
22
|
* Unmarshal a serialized Envelope protobuf message
|
|
23
23
|
*/
|
|
24
|
-
static createFromProtobuf = async (data: Uint8Array) => {
|
|
24
|
+
static createFromProtobuf = async (data: Uint8Array | Uint8ArrayList) => {
|
|
25
25
|
const envelopeData = Protobuf.decode(data)
|
|
26
26
|
const peerId = await peerIdFromKeys(envelopeData.publicKey)
|
|
27
27
|
|
|
@@ -38,18 +38,16 @@ export class RecordEnvelope implements Envelope {
|
|
|
38
38
|
* and signs it with the given peerId's private key
|
|
39
39
|
*/
|
|
40
40
|
static seal = async (record: Record, peerId: PeerId) => {
|
|
41
|
-
const domain = record.domain
|
|
42
|
-
const payloadType = record.codec
|
|
43
|
-
const payload = record.marshal()
|
|
44
|
-
|
|
45
|
-
const signData = formatSignaturePayload(domain, payloadType, payload)
|
|
46
|
-
|
|
47
41
|
if (peerId.privateKey == null) {
|
|
48
42
|
throw new Error('Missing private key')
|
|
49
43
|
}
|
|
50
44
|
|
|
45
|
+
const domain = record.domain
|
|
46
|
+
const payloadType = record.codec
|
|
47
|
+
const payload = record.marshal()
|
|
48
|
+
const signData = formatSignaturePayload(domain, payloadType, payload)
|
|
51
49
|
const key = await unmarshalPrivateKey(peerId.privateKey)
|
|
52
|
-
const signature = await key.sign(signData)
|
|
50
|
+
const signature = await key.sign(signData.subarray())
|
|
53
51
|
|
|
54
52
|
return new RecordEnvelope({
|
|
55
53
|
peerId,
|
|
@@ -63,7 +61,7 @@ export class RecordEnvelope implements Envelope {
|
|
|
63
61
|
* Open and certify a given marshalled envelope.
|
|
64
62
|
* Data is unmarshalled and the signature validated for the given domain.
|
|
65
63
|
*/
|
|
66
|
-
static openAndCertify = async (data: Uint8Array, domain: string) => {
|
|
64
|
+
static openAndCertify = async (data: Uint8Array | Uint8ArrayList, domain: string) => {
|
|
67
65
|
const envelope = await RecordEnvelope.createFromProtobuf(data)
|
|
68
66
|
const valid = await envelope.validate(domain)
|
|
69
67
|
|
|
@@ -96,7 +94,7 @@ export class RecordEnvelope implements Envelope {
|
|
|
96
94
|
/**
|
|
97
95
|
* Marshal the envelope content
|
|
98
96
|
*/
|
|
99
|
-
marshal () {
|
|
97
|
+
marshal (): Uint8Array {
|
|
100
98
|
if (this.peerId.publicKey == null) {
|
|
101
99
|
throw new Error('Missing public key')
|
|
102
100
|
}
|
|
@@ -105,7 +103,7 @@ export class RecordEnvelope implements Envelope {
|
|
|
105
103
|
this.marshaled = Protobuf.encode({
|
|
106
104
|
publicKey: this.peerId.publicKey,
|
|
107
105
|
payloadType: this.payloadType,
|
|
108
|
-
payload: this.payload,
|
|
106
|
+
payload: this.payload.subarray(),
|
|
109
107
|
signature: this.signature
|
|
110
108
|
})
|
|
111
109
|
}
|
|
@@ -117,7 +115,7 @@ export class RecordEnvelope implements Envelope {
|
|
|
117
115
|
* Verifies if the other Envelope is identical to this one
|
|
118
116
|
*/
|
|
119
117
|
equals (other: Envelope) {
|
|
120
|
-
return
|
|
118
|
+
return uint8ArrayEquals(this.marshal(), other.marshal())
|
|
121
119
|
}
|
|
122
120
|
|
|
123
121
|
/**
|
|
@@ -132,14 +130,14 @@ export class RecordEnvelope implements Envelope {
|
|
|
132
130
|
|
|
133
131
|
const key = unmarshalPublicKey(this.peerId.publicKey)
|
|
134
132
|
|
|
135
|
-
return await key.verify(signData, this.signature)
|
|
133
|
+
return await key.verify(signData.subarray(), this.signature)
|
|
136
134
|
}
|
|
137
135
|
}
|
|
138
136
|
|
|
139
137
|
/**
|
|
140
138
|
* Helper function that prepares a Uint8Array to sign or verify a signature
|
|
141
139
|
*/
|
|
142
|
-
const formatSignaturePayload = (domain: string, payloadType: Uint8Array, payload: Uint8Array) => {
|
|
140
|
+
const formatSignaturePayload = (domain: string, payloadType: Uint8Array, payload: Uint8Array | Uint8ArrayList): Uint8ArrayList => {
|
|
143
141
|
// When signing, a peer will prepare a Uint8Array by concatenating the following:
|
|
144
142
|
// - The length of the domain separation string string in bytes
|
|
145
143
|
// - The domain separation string, encoded as UTF-8
|
|
@@ -149,16 +147,16 @@ const formatSignaturePayload = (domain: string, payloadType: Uint8Array, payload
|
|
|
149
147
|
// - The value of the payload field
|
|
150
148
|
|
|
151
149
|
const domainUint8Array = uint8arraysFromString(domain)
|
|
152
|
-
const domainLength =
|
|
153
|
-
const payloadTypeLength =
|
|
154
|
-
const payloadLength =
|
|
150
|
+
const domainLength = unsigned.encode(domainUint8Array.byteLength)
|
|
151
|
+
const payloadTypeLength = unsigned.encode(payloadType.length)
|
|
152
|
+
const payloadLength = unsigned.encode(payload.length)
|
|
155
153
|
|
|
156
|
-
return
|
|
157
|
-
|
|
154
|
+
return new Uint8ArrayList(
|
|
155
|
+
domainLength,
|
|
158
156
|
domainUint8Array,
|
|
159
|
-
|
|
157
|
+
payloadTypeLength,
|
|
160
158
|
payloadType,
|
|
161
|
-
|
|
159
|
+
payloadLength,
|
|
162
160
|
payload
|
|
163
|
-
|
|
161
|
+
)
|
|
164
162
|
}
|
package/src/peer-record/index.ts
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
ENVELOPE_DOMAIN_PEER_RECORD,
|
|
8
8
|
ENVELOPE_PAYLOAD_TYPE_PEER_RECORD
|
|
9
9
|
} from './consts.js'
|
|
10
|
+
import type { Uint8ArrayList } from 'uint8arraylist'
|
|
10
11
|
|
|
11
12
|
export interface PeerRecordInit {
|
|
12
13
|
peerId: PeerId
|
|
@@ -30,7 +31,7 @@ export class PeerRecord {
|
|
|
30
31
|
/**
|
|
31
32
|
* Unmarshal Peer Record Protobuf
|
|
32
33
|
*/
|
|
33
|
-
static createFromProtobuf = (buf: Uint8Array): PeerRecord => {
|
|
34
|
+
static createFromProtobuf = (buf: Uint8Array | Uint8ArrayList): PeerRecord => {
|
|
34
35
|
const peerRecord = Protobuf.decode(buf)
|
|
35
36
|
const peerId = peerIdFromBytes(peerRecord.peerId)
|
|
36
37
|
const multiaddrs = (peerRecord.addresses ?? []).map((a) => new Multiaddr(a.multiaddr))
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/* eslint-disable import/export */
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-namespace */
|
|
3
3
|
|
|
4
|
-
import { encodeMessage, decodeMessage, message
|
|
4
|
+
import { encodeMessage, decodeMessage, message } from 'protons-runtime'
|
|
5
|
+
import type { Uint8ArrayList } from 'uint8arraylist'
|
|
5
6
|
import type { Codec } from 'protons-runtime'
|
|
6
7
|
|
|
7
8
|
export interface PeerRecord {
|
|
@@ -16,34 +17,148 @@ export namespace PeerRecord {
|
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
export namespace AddressInfo {
|
|
20
|
+
let _codec: Codec<AddressInfo>
|
|
21
|
+
|
|
19
22
|
export const codec = (): Codec<AddressInfo> => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
|
23
68
|
}
|
|
24
69
|
|
|
25
70
|
export const encode = (obj: AddressInfo): Uint8Array => {
|
|
26
71
|
return encodeMessage(obj, AddressInfo.codec())
|
|
27
72
|
}
|
|
28
73
|
|
|
29
|
-
export const decode = (buf: Uint8Array): AddressInfo => {
|
|
74
|
+
export const decode = (buf: Uint8Array | Uint8ArrayList): AddressInfo => {
|
|
30
75
|
return decodeMessage(buf, AddressInfo.codec())
|
|
31
76
|
}
|
|
32
77
|
}
|
|
33
78
|
|
|
79
|
+
let _codec: Codec<PeerRecord>
|
|
80
|
+
|
|
34
81
|
export const codec = (): Codec<PeerRecord> => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
|
40
155
|
}
|
|
41
156
|
|
|
42
157
|
export const encode = (obj: PeerRecord): Uint8Array => {
|
|
43
158
|
return encodeMessage(obj, PeerRecord.codec())
|
|
44
159
|
}
|
|
45
160
|
|
|
46
|
-
export const decode = (buf: Uint8Array): PeerRecord => {
|
|
161
|
+
export const decode = (buf: Uint8Array | Uint8ArrayList): PeerRecord => {
|
|
47
162
|
return decodeMessage(buf, PeerRecord.codec())
|
|
48
163
|
}
|
|
49
164
|
}
|