@libp2p/peer-record 8.0.30 → 8.0.31
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/index.min.js +1 -1
- package/dist/index.min.js.map +4 -4
- package/dist/src/envelope/index.d.ts +5 -4
- package/dist/src/envelope/index.d.ts.map +1 -1
- package/dist/src/envelope/index.js +8 -8
- package/dist/src/envelope/index.js.map +1 -1
- package/package.json +8 -8
- package/src/envelope/index.ts +9 -8
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Uint8ArrayList } from 'uint8arraylist';
|
|
2
2
|
import type { Record, Envelope, PrivateKey, PublicKey } from '@libp2p/interface';
|
|
3
|
+
import type { AbortOptions } from '@multiformats/multiaddr';
|
|
3
4
|
export interface RecordEnvelopeInit {
|
|
4
5
|
publicKey: PublicKey;
|
|
5
6
|
payloadType: Uint8Array;
|
|
@@ -10,17 +11,17 @@ export declare class RecordEnvelope implements Envelope {
|
|
|
10
11
|
/**
|
|
11
12
|
* Unmarshal a serialized Envelope protobuf message
|
|
12
13
|
*/
|
|
13
|
-
static createFromProtobuf: (data: Uint8Array | Uint8ArrayList) =>
|
|
14
|
+
static createFromProtobuf: (data: Uint8Array | Uint8ArrayList) => 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
|
|
17
18
|
*/
|
|
18
|
-
static seal: (record: Record, privateKey: PrivateKey) => Promise<RecordEnvelope>;
|
|
19
|
+
static seal: (record: Record, privateKey: PrivateKey, options?: AbortOptions) => Promise<RecordEnvelope>;
|
|
19
20
|
/**
|
|
20
21
|
* Open and certify a given marshaled envelope.
|
|
21
22
|
* Data is unmarshaled and the signature validated for the given domain.
|
|
22
23
|
*/
|
|
23
|
-
static openAndCertify: (data: Uint8Array | Uint8ArrayList, domain: string) => Promise<RecordEnvelope>;
|
|
24
|
+
static openAndCertify: (data: Uint8Array | Uint8ArrayList, domain: string, options?: AbortOptions) => Promise<RecordEnvelope>;
|
|
24
25
|
publicKey: PublicKey;
|
|
25
26
|
payloadType: Uint8Array;
|
|
26
27
|
payload: Uint8Array;
|
|
@@ -42,6 +43,6 @@ export declare class RecordEnvelope implements Envelope {
|
|
|
42
43
|
/**
|
|
43
44
|
* Validate envelope data signature for the given domain
|
|
44
45
|
*/
|
|
45
|
-
validate(domain: string): Promise<boolean>;
|
|
46
|
+
validate(domain: string, options?: AbortOptions): Promise<boolean>;
|
|
46
47
|
}
|
|
47
48
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/envelope/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAK/C,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/envelope/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAK/C,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAChF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAE3D,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,SAAS,CAAA;IACpB,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,GAAI,MAAM,UAAU,GAAG,cAAc,KAAG,cAAc,CAU9E;IAED;;;OAGG;IACH,MAAM,CAAC,IAAI,GAAU,QAAQ,MAAM,EAAE,YAAY,UAAU,EAAE,UAAU,YAAY,KAAG,OAAO,CAAC,cAAc,CAAC,CAiB5G;IAED;;;OAGG;IACH,MAAM,CAAC,cAAc,GAAU,MAAM,UAAU,GAAG,cAAc,EAAE,QAAQ,MAAM,EAAE,UAAU,YAAY,KAAG,OAAO,CAAC,cAAc,CAAC,CASjI;IAEM,SAAS,EAAE,SAAS,CAAA;IACpB,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;IAatB;;OAEG;IACH,MAAM,CAAE,KAAK,CAAC,EAAE,QAAQ,GAAG,OAAO;IAQlC;;OAEG;IACG,QAAQ,CAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC;CAK1E"}
|
|
@@ -9,7 +9,7 @@ export class RecordEnvelope {
|
|
|
9
9
|
/**
|
|
10
10
|
* Unmarshal a serialized Envelope protobuf message
|
|
11
11
|
*/
|
|
12
|
-
static createFromProtobuf =
|
|
12
|
+
static createFromProtobuf = (data) => {
|
|
13
13
|
const envelopeData = Protobuf.decode(data);
|
|
14
14
|
const publicKey = publicKeyFromProtobuf(envelopeData.publicKey);
|
|
15
15
|
return new RecordEnvelope({
|
|
@@ -23,7 +23,7 @@ export class RecordEnvelope {
|
|
|
23
23
|
* Seal marshals the given Record, places the marshaled bytes inside an Envelope
|
|
24
24
|
* and signs it with the given peerId's private key
|
|
25
25
|
*/
|
|
26
|
-
static seal = async (record, privateKey) => {
|
|
26
|
+
static seal = async (record, privateKey, options) => {
|
|
27
27
|
if (privateKey == null) {
|
|
28
28
|
throw new Error('Missing private key');
|
|
29
29
|
}
|
|
@@ -31,7 +31,7 @@ export class RecordEnvelope {
|
|
|
31
31
|
const payloadType = record.codec;
|
|
32
32
|
const payload = record.marshal();
|
|
33
33
|
const signData = formatSignaturePayload(domain, payloadType, payload);
|
|
34
|
-
const signature = await privateKey.sign(signData.subarray());
|
|
34
|
+
const signature = await privateKey.sign(signData.subarray(), options);
|
|
35
35
|
return new RecordEnvelope({
|
|
36
36
|
publicKey: privateKey.publicKey,
|
|
37
37
|
payloadType,
|
|
@@ -43,9 +43,9 @@ export class RecordEnvelope {
|
|
|
43
43
|
* Open and certify a given marshaled envelope.
|
|
44
44
|
* Data is unmarshaled and the signature validated for the given domain.
|
|
45
45
|
*/
|
|
46
|
-
static openAndCertify = async (data, domain) => {
|
|
47
|
-
const envelope =
|
|
48
|
-
const valid = await envelope.validate(domain);
|
|
46
|
+
static openAndCertify = async (data, domain, options) => {
|
|
47
|
+
const envelope = RecordEnvelope.createFromProtobuf(data);
|
|
48
|
+
const valid = await envelope.validate(domain, options);
|
|
49
49
|
if (!valid) {
|
|
50
50
|
throw new InvalidSignatureError('Envelope signature is not valid for the given domain');
|
|
51
51
|
}
|
|
@@ -93,9 +93,9 @@ export class RecordEnvelope {
|
|
|
93
93
|
/**
|
|
94
94
|
* Validate envelope data signature for the given domain
|
|
95
95
|
*/
|
|
96
|
-
async validate(domain) {
|
|
96
|
+
async validate(domain, options) {
|
|
97
97
|
const signData = formatSignaturePayload(domain, this.payloadType, this.payload);
|
|
98
|
-
return this.publicKey.verify(signData.subarray(), this.signature);
|
|
98
|
+
return this.publicKey.verify(signData.subarray(), this.signature, options);
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
101
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/envelope/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AAChF,OAAO,KAAK,MAAM,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAA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AAkD;IAClD,wCAAwC;IACxC,6CAA6C;IAC7C,mCAAmC;IAEnC,MAAM,gBAAgB,GAAG,qBAAqB,CAAC,MAAM,CAAC,CAAA;IACtD,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAA;IAC/D,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAA;IAC3D,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IAEnD,OAAO,IAAI,cAAc,CACvB,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,WAAW,EACX,aAAa,EACb,OAAO,CACR,CAAA;AACH,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/peer-record",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.31",
|
|
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/tree/main/packages/peer-record#readme",
|
|
@@ -48,20 +48,20 @@
|
|
|
48
48
|
"test:electron-main": "aegir test -t electron-main"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@libp2p/crypto": "^5.1.
|
|
52
|
-
"@libp2p/interface": "^2.10.
|
|
53
|
-
"@libp2p/peer-id": "^5.1.
|
|
54
|
-
"@libp2p/utils": "^6.6.
|
|
51
|
+
"@libp2p/crypto": "^5.1.5",
|
|
52
|
+
"@libp2p/interface": "^2.10.3",
|
|
53
|
+
"@libp2p/peer-id": "^5.1.6",
|
|
54
|
+
"@libp2p/utils": "^6.6.6",
|
|
55
55
|
"@multiformats/multiaddr": "^12.4.0",
|
|
56
|
-
"multiformats": "^13.3.
|
|
56
|
+
"multiformats": "^13.3.6",
|
|
57
57
|
"protons-runtime": "^5.5.0",
|
|
58
58
|
"uint8-varint": "^2.0.4",
|
|
59
59
|
"uint8arraylist": "^2.4.8",
|
|
60
60
|
"uint8arrays": "^5.1.0"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
|
-
"aegir": "^47.0.
|
|
64
|
-
"protons": "^7.6.
|
|
63
|
+
"aegir": "^47.0.14",
|
|
64
|
+
"protons": "^7.6.1"
|
|
65
65
|
},
|
|
66
66
|
"sideEffects": false
|
|
67
67
|
}
|
package/src/envelope/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { fromString as uint8arraysFromString } from 'uint8arrays/from-string'
|
|
|
6
6
|
import { Envelope as Protobuf } from './envelope.js'
|
|
7
7
|
import { InvalidSignatureError } from './errors.js'
|
|
8
8
|
import type { Record, Envelope, PrivateKey, PublicKey } from '@libp2p/interface'
|
|
9
|
+
import type { AbortOptions } from '@multiformats/multiaddr'
|
|
9
10
|
|
|
10
11
|
export interface RecordEnvelopeInit {
|
|
11
12
|
publicKey: PublicKey
|
|
@@ -18,7 +19,7 @@ export class RecordEnvelope implements Envelope {
|
|
|
18
19
|
/**
|
|
19
20
|
* Unmarshal a serialized Envelope protobuf message
|
|
20
21
|
*/
|
|
21
|
-
static createFromProtobuf =
|
|
22
|
+
static createFromProtobuf = (data: Uint8Array | Uint8ArrayList): RecordEnvelope => {
|
|
22
23
|
const envelopeData = Protobuf.decode(data)
|
|
23
24
|
const publicKey = publicKeyFromProtobuf(envelopeData.publicKey)
|
|
24
25
|
|
|
@@ -34,7 +35,7 @@ export class RecordEnvelope implements Envelope {
|
|
|
34
35
|
* Seal marshals the given Record, places the marshaled bytes inside an Envelope
|
|
35
36
|
* and signs it with the given peerId's private key
|
|
36
37
|
*/
|
|
37
|
-
static seal = async (record: Record, privateKey: PrivateKey): Promise<RecordEnvelope> => {
|
|
38
|
+
static seal = async (record: Record, privateKey: PrivateKey, options?: AbortOptions): Promise<RecordEnvelope> => {
|
|
38
39
|
if (privateKey == null) {
|
|
39
40
|
throw new Error('Missing private key')
|
|
40
41
|
}
|
|
@@ -43,7 +44,7 @@ export class RecordEnvelope implements Envelope {
|
|
|
43
44
|
const payloadType = record.codec
|
|
44
45
|
const payload = record.marshal()
|
|
45
46
|
const signData = formatSignaturePayload(domain, payloadType, payload)
|
|
46
|
-
const signature = await privateKey.sign(signData.subarray())
|
|
47
|
+
const signature = await privateKey.sign(signData.subarray(), options)
|
|
47
48
|
|
|
48
49
|
return new RecordEnvelope({
|
|
49
50
|
publicKey: privateKey.publicKey,
|
|
@@ -57,9 +58,9 @@ export class RecordEnvelope implements Envelope {
|
|
|
57
58
|
* Open and certify a given marshaled envelope.
|
|
58
59
|
* Data is unmarshaled and the signature validated for the given domain.
|
|
59
60
|
*/
|
|
60
|
-
static openAndCertify = async (data: Uint8Array | Uint8ArrayList, domain: string): Promise<RecordEnvelope> => {
|
|
61
|
-
const envelope =
|
|
62
|
-
const valid = await envelope.validate(domain)
|
|
61
|
+
static openAndCertify = async (data: Uint8Array | Uint8ArrayList, domain: string, options?: AbortOptions): Promise<RecordEnvelope> => {
|
|
62
|
+
const envelope = RecordEnvelope.createFromProtobuf(data)
|
|
63
|
+
const valid = await envelope.validate(domain, options)
|
|
63
64
|
|
|
64
65
|
if (!valid) {
|
|
65
66
|
throw new InvalidSignatureError('Envelope signature is not valid for the given domain')
|
|
@@ -117,10 +118,10 @@ export class RecordEnvelope implements Envelope {
|
|
|
117
118
|
/**
|
|
118
119
|
* Validate envelope data signature for the given domain
|
|
119
120
|
*/
|
|
120
|
-
async validate (domain: string): Promise<boolean> {
|
|
121
|
+
async validate (domain: string, options?: AbortOptions): Promise<boolean> {
|
|
121
122
|
const signData = formatSignaturePayload(domain, this.payloadType, this.payload)
|
|
122
123
|
|
|
123
|
-
return this.publicKey.verify(signData.subarray(), this.signature)
|
|
124
|
+
return this.publicKey.verify(signData.subarray(), this.signature, options)
|
|
124
125
|
}
|
|
125
126
|
}
|
|
126
127
|
|