@libp2p/peer-record 5.0.3 → 5.0.4-ab0e3980
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/README.md +3 -3
- package/dist/index.min.js +14 -14
- package/dist/src/envelope/index.d.ts +1 -1
- package/dist/src/envelope/index.d.ts.map +1 -1
- package/dist/src/envelope/index.js +57 -54
- package/dist/src/envelope/index.js.map +1 -1
- package/dist/src/peer-record/index.d.ts +1 -1
- package/dist/src/peer-record/index.d.ts.map +1 -1
- package/dist/src/peer-record/index.js +21 -17
- package/dist/src/peer-record/index.js.map +1 -1
- package/package.json +20 -108
- package/src/envelope/index.ts +6 -6
- package/src/peer-record/index.ts +5 -5
- package/dist/typedoc-urls.json +0 -6
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { Uint8ArrayList } from 'uint8arraylist';
|
|
1
2
|
import type { PeerId } from '@libp2p/interface-peer-id';
|
|
2
3
|
import type { Record, Envelope } from '@libp2p/interface-record';
|
|
3
|
-
import { Uint8ArrayList } from 'uint8arraylist';
|
|
4
4
|
export interface RecordEnvelopeInit {
|
|
5
5
|
peerId: PeerId;
|
|
6
6
|
payloadType: 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":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAK/C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AAEhE,MAAM,WAAW,kBAAkB;IACjC,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,KAAG,QAAQ,cAAc,CAAC,CAU7F;IAED;;;OAGG;IACH,MAAM,CAAC,IAAI,WAAkB,MAAM,UAAU,MAAM,KAAG,QAAQ,cAAc,CAAC,CAkB5E;IAED;;;OAGG;IACH,MAAM,CAAC,cAAc,SAAgB,UAAU,GAAG,cAAc,UAAU,MAAM,KAAG,QAAQ,cAAc,CAAC,CASzG;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,kBAAkB;IASrC;;OAEG;IACH,OAAO,IAAK,UAAU;IAiBtB;;OAEG;IACH,MAAM,CAAE,KAAK,EAAE,QAAQ,GAAG,OAAO;IAIjC;;OAEG;IACG,QAAQ,CAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAWlD"}
|
|
@@ -1,14 +1,64 @@
|
|
|
1
|
-
|
|
1
|
+
import { unmarshalPrivateKey, unmarshalPublicKey } from '@libp2p/crypto/keys';
|
|
2
2
|
import { CodeError } from '@libp2p/interfaces/errors';
|
|
3
|
-
import {
|
|
3
|
+
import { peerIdFromKeys } from '@libp2p/peer-id';
|
|
4
|
+
import { unsigned } from 'uint8-varint';
|
|
5
|
+
import { Uint8ArrayList } from 'uint8arraylist';
|
|
4
6
|
import { equals as uint8ArrayEquals } from 'uint8arrays/equals';
|
|
5
|
-
import {
|
|
7
|
+
import { fromString as uint8arraysFromString } from 'uint8arrays/from-string';
|
|
6
8
|
import { codes } from '../errors.js';
|
|
7
9
|
import { Envelope as Protobuf } from './envelope.js';
|
|
8
|
-
import { peerIdFromKeys } from '@libp2p/peer-id';
|
|
9
|
-
import { Uint8ArrayList } from 'uint8arraylist';
|
|
10
|
-
import { unsigned } from 'uint8-varint';
|
|
11
10
|
export class RecordEnvelope {
|
|
11
|
+
/**
|
|
12
|
+
* Unmarshal a serialized Envelope protobuf message
|
|
13
|
+
*/
|
|
14
|
+
static createFromProtobuf = async (data) => {
|
|
15
|
+
const envelopeData = Protobuf.decode(data);
|
|
16
|
+
const peerId = await peerIdFromKeys(envelopeData.publicKey);
|
|
17
|
+
return new RecordEnvelope({
|
|
18
|
+
peerId,
|
|
19
|
+
payloadType: envelopeData.payloadType,
|
|
20
|
+
payload: envelopeData.payload,
|
|
21
|
+
signature: envelopeData.signature
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Seal marshals the given Record, places the marshaled bytes inside an Envelope
|
|
26
|
+
* and signs it with the given peerId's private key
|
|
27
|
+
*/
|
|
28
|
+
static seal = async (record, peerId) => {
|
|
29
|
+
if (peerId.privateKey == null) {
|
|
30
|
+
throw new Error('Missing private key');
|
|
31
|
+
}
|
|
32
|
+
const domain = record.domain;
|
|
33
|
+
const payloadType = record.codec;
|
|
34
|
+
const payload = record.marshal();
|
|
35
|
+
const signData = formatSignaturePayload(domain, payloadType, payload);
|
|
36
|
+
const key = await unmarshalPrivateKey(peerId.privateKey);
|
|
37
|
+
const signature = await key.sign(signData.subarray());
|
|
38
|
+
return new RecordEnvelope({
|
|
39
|
+
peerId,
|
|
40
|
+
payloadType,
|
|
41
|
+
payload,
|
|
42
|
+
signature
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Open and certify a given marshalled envelope.
|
|
47
|
+
* Data is unmarshalled and the signature validated for the given domain.
|
|
48
|
+
*/
|
|
49
|
+
static openAndCertify = async (data, domain) => {
|
|
50
|
+
const envelope = await RecordEnvelope.createFromProtobuf(data);
|
|
51
|
+
const valid = await envelope.validate(domain);
|
|
52
|
+
if (!valid) {
|
|
53
|
+
throw new CodeError('envelope signature is not valid for the given domain', codes.ERR_SIGNATURE_NOT_VALID);
|
|
54
|
+
}
|
|
55
|
+
return envelope;
|
|
56
|
+
};
|
|
57
|
+
peerId;
|
|
58
|
+
payloadType;
|
|
59
|
+
payload;
|
|
60
|
+
signature;
|
|
61
|
+
marshaled;
|
|
12
62
|
/**
|
|
13
63
|
* The Envelope is responsible for keeping an arbitrary signed record
|
|
14
64
|
* by a libp2p peer.
|
|
@@ -52,56 +102,9 @@ export class RecordEnvelope {
|
|
|
52
102
|
throw new Error('Missing public key');
|
|
53
103
|
}
|
|
54
104
|
const key = unmarshalPublicKey(this.peerId.publicKey);
|
|
55
|
-
return
|
|
105
|
+
return key.verify(signData.subarray(), this.signature);
|
|
56
106
|
}
|
|
57
107
|
}
|
|
58
|
-
_a = RecordEnvelope;
|
|
59
|
-
/**
|
|
60
|
-
* Unmarshal a serialized Envelope protobuf message
|
|
61
|
-
*/
|
|
62
|
-
RecordEnvelope.createFromProtobuf = async (data) => {
|
|
63
|
-
const envelopeData = Protobuf.decode(data);
|
|
64
|
-
const peerId = await peerIdFromKeys(envelopeData.publicKey);
|
|
65
|
-
return new RecordEnvelope({
|
|
66
|
-
peerId,
|
|
67
|
-
payloadType: envelopeData.payloadType,
|
|
68
|
-
payload: envelopeData.payload,
|
|
69
|
-
signature: envelopeData.signature
|
|
70
|
-
});
|
|
71
|
-
};
|
|
72
|
-
/**
|
|
73
|
-
* Seal marshals the given Record, places the marshaled bytes inside an Envelope
|
|
74
|
-
* and signs it with the given peerId's private key
|
|
75
|
-
*/
|
|
76
|
-
RecordEnvelope.seal = async (record, peerId) => {
|
|
77
|
-
if (peerId.privateKey == null) {
|
|
78
|
-
throw new Error('Missing private key');
|
|
79
|
-
}
|
|
80
|
-
const domain = record.domain;
|
|
81
|
-
const payloadType = record.codec;
|
|
82
|
-
const payload = record.marshal();
|
|
83
|
-
const signData = formatSignaturePayload(domain, payloadType, payload);
|
|
84
|
-
const key = await unmarshalPrivateKey(peerId.privateKey);
|
|
85
|
-
const signature = await key.sign(signData.subarray());
|
|
86
|
-
return new RecordEnvelope({
|
|
87
|
-
peerId,
|
|
88
|
-
payloadType,
|
|
89
|
-
payload,
|
|
90
|
-
signature
|
|
91
|
-
});
|
|
92
|
-
};
|
|
93
|
-
/**
|
|
94
|
-
* Open and certify a given marshalled envelope.
|
|
95
|
-
* Data is unmarshalled and the signature validated for the given domain.
|
|
96
|
-
*/
|
|
97
|
-
RecordEnvelope.openAndCertify = async (data, domain) => {
|
|
98
|
-
const envelope = await RecordEnvelope.createFromProtobuf(data);
|
|
99
|
-
const valid = await envelope.validate(domain);
|
|
100
|
-
if (!valid) {
|
|
101
|
-
throw new CodeError('envelope signature is not valid for the given domain', codes.ERR_SIGNATURE_NOT_VALID);
|
|
102
|
-
}
|
|
103
|
-
return envelope;
|
|
104
|
-
};
|
|
105
108
|
/**
|
|
106
109
|
* Helper function that prepares a Uint8Array to sign or verify a signature
|
|
107
110
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/envelope/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/envelope/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAC7E,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,EAAE,MAAM,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAC/D,OAAO,EAAE,UAAU,IAAI,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;AAC7E,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;A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CAAC,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Multiaddr } from '@multiformats/multiaddr';
|
|
2
1
|
import type { PeerId } from '@libp2p/interface-peer-id';
|
|
2
|
+
import type { Multiaddr } from '@multiformats/multiaddr';
|
|
3
3
|
import type { Uint8ArrayList } from 'uint8arraylist';
|
|
4
4
|
export interface PeerRecordInit {
|
|
5
5
|
peerId: PeerId;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/peer-record/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/peer-record/index.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACxD,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,IAAK,UAAU;IActB;;OAEG;IACH,MAAM,CAAE,KAAK,EAAE,OAAO,GAAG,OAAO;CAsBjC"}
|
|
@@ -1,16 +1,32 @@
|
|
|
1
|
-
import { multiaddr } from '@multiformats/multiaddr';
|
|
2
|
-
import { arrayEquals } from '@libp2p/utils/array-equals';
|
|
3
1
|
import { peerIdFromBytes } from '@libp2p/peer-id';
|
|
4
|
-
import {
|
|
2
|
+
import { arrayEquals } from '@libp2p/utils/array-equals';
|
|
3
|
+
import { multiaddr } from '@multiformats/multiaddr';
|
|
5
4
|
import { ENVELOPE_DOMAIN_PEER_RECORD, ENVELOPE_PAYLOAD_TYPE_PEER_RECORD } from './consts.js';
|
|
5
|
+
import { PeerRecord as Protobuf } from './peer-record.js';
|
|
6
6
|
/**
|
|
7
7
|
* The PeerRecord is used for distributing peer routing records across the network.
|
|
8
8
|
* It contains the peer's reachable listen addresses.
|
|
9
9
|
*/
|
|
10
10
|
export class PeerRecord {
|
|
11
|
+
/**
|
|
12
|
+
* Unmarshal Peer Record Protobuf
|
|
13
|
+
*/
|
|
14
|
+
static createFromProtobuf = (buf) => {
|
|
15
|
+
const peerRecord = Protobuf.decode(buf);
|
|
16
|
+
const peerId = peerIdFromBytes(peerRecord.peerId);
|
|
17
|
+
const multiaddrs = (peerRecord.addresses ?? []).map((a) => multiaddr(a.multiaddr));
|
|
18
|
+
const seqNumber = peerRecord.seq;
|
|
19
|
+
return new PeerRecord({ peerId, multiaddrs, seqNumber });
|
|
20
|
+
};
|
|
21
|
+
static DOMAIN = ENVELOPE_DOMAIN_PEER_RECORD;
|
|
22
|
+
static CODEC = ENVELOPE_PAYLOAD_TYPE_PEER_RECORD;
|
|
23
|
+
peerId;
|
|
24
|
+
multiaddrs;
|
|
25
|
+
seqNumber;
|
|
26
|
+
domain = PeerRecord.DOMAIN;
|
|
27
|
+
codec = PeerRecord.CODEC;
|
|
28
|
+
marshaled;
|
|
11
29
|
constructor(init) {
|
|
12
|
-
this.domain = PeerRecord.DOMAIN;
|
|
13
|
-
this.codec = PeerRecord.CODEC;
|
|
14
30
|
const { peerId, multiaddrs, seqNumber } = init;
|
|
15
31
|
this.peerId = peerId;
|
|
16
32
|
this.multiaddrs = multiaddrs ?? [];
|
|
@@ -53,16 +69,4 @@ export class PeerRecord {
|
|
|
53
69
|
return true;
|
|
54
70
|
}
|
|
55
71
|
}
|
|
56
|
-
/**
|
|
57
|
-
* Unmarshal Peer Record Protobuf
|
|
58
|
-
*/
|
|
59
|
-
PeerRecord.createFromProtobuf = (buf) => {
|
|
60
|
-
const peerRecord = Protobuf.decode(buf);
|
|
61
|
-
const peerId = peerIdFromBytes(peerRecord.peerId);
|
|
62
|
-
const multiaddrs = (peerRecord.addresses ?? []).map((a) => multiaddr(a.multiaddr));
|
|
63
|
-
const seqNumber = peerRecord.seq;
|
|
64
|
-
return new PeerRecord({ peerId, multiaddrs, seqNumber });
|
|
65
|
-
};
|
|
66
|
-
PeerRecord.DOMAIN = ENVELOPE_DOMAIN_PEER_RECORD;
|
|
67
|
-
PeerRecord.CODEC = ENVELOPE_PAYLOAD_TYPE_PEER_RECORD;
|
|
68
72
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/peer-record/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/peer-record/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,EACL,2BAA2B,EAC3B,iCAAiC,EAClC,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,UAAU,IAAI,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAmBzD;;;GAGG;AACH,MAAM,OAAO,UAAU;IACrB;;OAEG;IACH,MAAM,CAAC,kBAAkB,GAAG,CAAC,GAAgC,EAAc,E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AAC;gBAC3B,SAAS,EAAE,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;oBACrC,SAAS,EAAE,CAAC,CAAC,KAAK;iBACnB,CAAC,CAAC;aACJ,CAAC,CAAA;SACH;QAED,OAAO,IAAI,CAAC,SAAS,CAAA;IACvB,CAAC;IAED;;OAEG;IACH,MAAM,CAAE,KAAc;QACpB,IAAI,CAAC,CAAC,KAAK,YAAY,UAAU,CAAC,EAAE;YAClC,OAAO,KAAK,CAAA;SACb;QAED,kBAAkB;QAClB,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE;YACrC,OAAO,KAAK,CAAA;SACb;QAED,qBAAqB;QACrB,IAAI,IAAI,CAAC,SAAS,KAAK,KAAK,CAAC,SAAS,EAAE;YACtC,OAAO,KAAK,CAAA;SACb;QAED,sBAAsB;QACtB,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,EAAE;YACnD,OAAO,KAAK,CAAA;SACb;QAED,OAAO,IAAI,CAAA;IACb,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,23 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/peer-record",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.4-ab0e3980",
|
|
4
4
|
"description": "Used to transfer signed peer data across the network",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
|
-
"homepage": "https://github.com/libp2p/js-libp2p
|
|
6
|
+
"homepage": "https://github.com/libp2p/js-libp2p/tree/master/packages/peer-record#readme",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "git+https://github.com/libp2p/js-libp2p
|
|
9
|
+
"url": "git+https://github.com/libp2p/js-libp2p.git"
|
|
10
10
|
},
|
|
11
11
|
"bugs": {
|
|
12
|
-
"url": "https://github.com/libp2p/js-libp2p
|
|
12
|
+
"url": "https://github.com/libp2p/js-libp2p/issues"
|
|
13
13
|
},
|
|
14
14
|
"keywords": [
|
|
15
15
|
"IPFS"
|
|
16
16
|
],
|
|
17
|
-
"engines": {
|
|
18
|
-
"node": ">=16.0.0",
|
|
19
|
-
"npm": ">=7.0.0"
|
|
20
|
-
},
|
|
21
17
|
"type": "module",
|
|
22
18
|
"types": "./dist/src/index.d.ts",
|
|
23
19
|
"files": [
|
|
@@ -44,91 +40,6 @@
|
|
|
44
40
|
"src/peer-record/peer-record.js"
|
|
45
41
|
]
|
|
46
42
|
},
|
|
47
|
-
"release": {
|
|
48
|
-
"branches": [
|
|
49
|
-
"master"
|
|
50
|
-
],
|
|
51
|
-
"plugins": [
|
|
52
|
-
[
|
|
53
|
-
"@semantic-release/commit-analyzer",
|
|
54
|
-
{
|
|
55
|
-
"preset": "conventionalcommits",
|
|
56
|
-
"releaseRules": [
|
|
57
|
-
{
|
|
58
|
-
"breaking": true,
|
|
59
|
-
"release": "major"
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
"revert": true,
|
|
63
|
-
"release": "patch"
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
"type": "feat",
|
|
67
|
-
"release": "minor"
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
"type": "fix",
|
|
71
|
-
"release": "patch"
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
"type": "docs",
|
|
75
|
-
"release": "patch"
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
"type": "test",
|
|
79
|
-
"release": "patch"
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
"type": "deps",
|
|
83
|
-
"release": "patch"
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
"scope": "no-release",
|
|
87
|
-
"release": false
|
|
88
|
-
}
|
|
89
|
-
]
|
|
90
|
-
}
|
|
91
|
-
],
|
|
92
|
-
[
|
|
93
|
-
"@semantic-release/release-notes-generator",
|
|
94
|
-
{
|
|
95
|
-
"preset": "conventionalcommits",
|
|
96
|
-
"presetConfig": {
|
|
97
|
-
"types": [
|
|
98
|
-
{
|
|
99
|
-
"type": "feat",
|
|
100
|
-
"section": "Features"
|
|
101
|
-
},
|
|
102
|
-
{
|
|
103
|
-
"type": "fix",
|
|
104
|
-
"section": "Bug Fixes"
|
|
105
|
-
},
|
|
106
|
-
{
|
|
107
|
-
"type": "chore",
|
|
108
|
-
"section": "Trivial Changes"
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
"type": "docs",
|
|
112
|
-
"section": "Documentation"
|
|
113
|
-
},
|
|
114
|
-
{
|
|
115
|
-
"type": "deps",
|
|
116
|
-
"section": "Dependencies"
|
|
117
|
-
},
|
|
118
|
-
{
|
|
119
|
-
"type": "test",
|
|
120
|
-
"section": "Tests"
|
|
121
|
-
}
|
|
122
|
-
]
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
],
|
|
126
|
-
"@semantic-release/changelog",
|
|
127
|
-
"@semantic-release/npm",
|
|
128
|
-
"@semantic-release/github",
|
|
129
|
-
"@semantic-release/git"
|
|
130
|
-
]
|
|
131
|
-
},
|
|
132
43
|
"scripts": {
|
|
133
44
|
"clean": "aegir clean",
|
|
134
45
|
"lint": "aegir lint",
|
|
@@ -141,28 +52,29 @@
|
|
|
141
52
|
"test:firefox": "aegir test -t browser -- --browser firefox",
|
|
142
53
|
"test:firefox-webworker": "aegir test -t webworker -- --browser firefox",
|
|
143
54
|
"test:node": "aegir test -t node --cov",
|
|
144
|
-
"test:electron-main": "aegir test -t electron-main"
|
|
145
|
-
"release": "aegir release",
|
|
146
|
-
"docs": "aegir docs"
|
|
55
|
+
"test:electron-main": "aegir test -t electron-main"
|
|
147
56
|
},
|
|
148
57
|
"dependencies": {
|
|
149
|
-
"@libp2p/crypto": "
|
|
150
|
-
"@libp2p/interface-peer-id": "
|
|
151
|
-
"@libp2p/interface-record": "
|
|
152
|
-
"@libp2p/interfaces": "
|
|
153
|
-
"@libp2p/peer-id": "
|
|
154
|
-
"@libp2p/utils": "
|
|
155
|
-
"@multiformats/multiaddr": "^12.
|
|
58
|
+
"@libp2p/crypto": "1.0.17-ab0e3980",
|
|
59
|
+
"@libp2p/interface-peer-id": "2.0.2-ab0e3980",
|
|
60
|
+
"@libp2p/interface-record": "2.0.7-ab0e3980",
|
|
61
|
+
"@libp2p/interfaces": "3.3.2-ab0e3980",
|
|
62
|
+
"@libp2p/peer-id": "2.0.3-ab0e3980",
|
|
63
|
+
"@libp2p/utils": "3.0.12-ab0e3980",
|
|
64
|
+
"@multiformats/multiaddr": "^12.1.3",
|
|
156
65
|
"protons-runtime": "^5.0.0",
|
|
157
66
|
"uint8-varint": "^1.0.2",
|
|
158
|
-
"uint8arraylist": "^2.
|
|
159
|
-
"uint8arrays": "^4.0.
|
|
67
|
+
"uint8arraylist": "^2.4.3",
|
|
68
|
+
"uint8arrays": "^4.0.3"
|
|
160
69
|
},
|
|
161
70
|
"devDependencies": {
|
|
162
|
-
"@libp2p/interface-record-compliance-tests": "
|
|
163
|
-
"@libp2p/peer-id-factory": "
|
|
71
|
+
"@libp2p/interface-record-compliance-tests": "2.0.5-ab0e3980",
|
|
72
|
+
"@libp2p/peer-id-factory": "2.0.3-ab0e3980",
|
|
164
73
|
"@types/varint": "^6.0.0",
|
|
165
|
-
"aegir": "^
|
|
74
|
+
"aegir": "^39.0.10",
|
|
166
75
|
"protons": "^7.0.2"
|
|
76
|
+
},
|
|
77
|
+
"typedoc": {
|
|
78
|
+
"entryPoint": "./src/index.ts"
|
|
167
79
|
}
|
|
168
80
|
}
|
package/src/envelope/index.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
+
import { unmarshalPrivateKey, unmarshalPublicKey } from '@libp2p/crypto/keys'
|
|
1
2
|
import { CodeError } from '@libp2p/interfaces/errors'
|
|
2
|
-
import {
|
|
3
|
+
import { peerIdFromKeys } from '@libp2p/peer-id'
|
|
4
|
+
import { unsigned } from 'uint8-varint'
|
|
5
|
+
import { Uint8ArrayList } from 'uint8arraylist'
|
|
3
6
|
import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
|
|
4
|
-
import {
|
|
7
|
+
import { fromString as uint8arraysFromString } from 'uint8arrays/from-string'
|
|
5
8
|
import { codes } from '../errors.js'
|
|
6
9
|
import { Envelope as Protobuf } from './envelope.js'
|
|
7
|
-
import { peerIdFromKeys } from '@libp2p/peer-id'
|
|
8
10
|
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
9
11
|
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 RecordEnvelopeInit {
|
|
14
14
|
peerId: PeerId
|
|
@@ -130,7 +130,7 @@ export class RecordEnvelope implements Envelope {
|
|
|
130
130
|
|
|
131
131
|
const key = unmarshalPublicKey(this.peerId.publicKey)
|
|
132
132
|
|
|
133
|
-
return
|
|
133
|
+
return key.verify(signData.subarray(), this.signature)
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
136
|
|
package/src/peer-record/index.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
2
|
-
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
3
|
-
import { multiaddr } from '@multiformats/multiaddr'
|
|
4
|
-
import { arrayEquals } from '@libp2p/utils/array-equals'
|
|
5
1
|
import { peerIdFromBytes } from '@libp2p/peer-id'
|
|
6
|
-
import {
|
|
2
|
+
import { arrayEquals } from '@libp2p/utils/array-equals'
|
|
3
|
+
import { multiaddr } from '@multiformats/multiaddr'
|
|
7
4
|
import {
|
|
8
5
|
ENVELOPE_DOMAIN_PEER_RECORD,
|
|
9
6
|
ENVELOPE_PAYLOAD_TYPE_PEER_RECORD
|
|
10
7
|
} from './consts.js'
|
|
8
|
+
import { PeerRecord as Protobuf } from './peer-record.js'
|
|
9
|
+
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
10
|
+
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
11
11
|
import type { Uint8ArrayList } from 'uint8arraylist'
|
|
12
12
|
|
|
13
13
|
export interface PeerRecordInit {
|
package/dist/typedoc-urls.json
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"PeerRecord": "https://libp2p.github.io/js-libp2p-peer-record/classes/PeerRecord.html",
|
|
3
|
-
"RecordEnvelope": "https://libp2p.github.io/js-libp2p-peer-record/classes/RecordEnvelope.html",
|
|
4
|
-
"PeerRecordInit": "https://libp2p.github.io/js-libp2p-peer-record/interfaces/PeerRecordInit.html",
|
|
5
|
-
"RecordEnvelopeInit": "https://libp2p.github.io/js-libp2p-peer-record/interfaces/RecordEnvelopeInit.html"
|
|
6
|
-
}
|