@libp2p/plaintext 3.0.30-f0e64b9b8 → 3.0.31-aa5ba42d0
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 +3 -3
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +8 -10
- package/dist/src/index.js.map +1 -1
- package/dist/src/pb/proto.d.ts +9 -40
- package/dist/src/pb/proto.d.ts.map +1 -1
- package/dist/src/pb/proto.js +22 -114
- package/dist/src/pb/proto.js.map +1 -1
- package/package.json +9 -8
- package/src/index.ts +9 -10
- package/src/pb/proto.proto +2 -13
- package/src/pb/proto.ts +33 -156
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AASH,OAAO,KAAK,EAAE,eAAe,EAAU,mBAAmB,EAAqB,UAAU,EAA0C,MAAM,mBAAmB,CAAA;AAI5J,MAAM,WAAW,mBAAmB;IAClC,UAAU,EAAE,UAAU,CAAA;IACtB,MAAM,EAAE,eAAe,CAAA;CACxB;AAqFD,wBAAgB,SAAS,IAAK,CAAC,UAAU,EAAE,mBAAmB,KAAK,mBAAmB,CAErF"}
|
package/dist/src/index.js
CHANGED
|
@@ -20,12 +20,13 @@
|
|
|
20
20
|
* })
|
|
21
21
|
* ```
|
|
22
22
|
*/
|
|
23
|
-
import {
|
|
23
|
+
import { publicKeyFromProtobuf, publicKeyToProtobuf } from '@libp2p/crypto/keys';
|
|
24
24
|
import { UnexpectedPeerError, InvalidCryptoExchangeError, serviceCapabilities, ProtocolError } from '@libp2p/interface';
|
|
25
25
|
import { peerIdFromPublicKey } from '@libp2p/peer-id';
|
|
26
26
|
import { pbStream } from '@libp2p/utils';
|
|
27
27
|
import { equals as uint8ArrayEquals } from 'uint8arrays/equals';
|
|
28
|
-
import {
|
|
28
|
+
import { withArrayBuffer } from 'uint8arrays/with-array-buffer';
|
|
29
|
+
import { Exchange } from "./pb/proto.js";
|
|
29
30
|
const PROTOCOL = '/plaintext/2.0.0';
|
|
30
31
|
class Plaintext {
|
|
31
32
|
protocol = PROTOCOL;
|
|
@@ -56,10 +57,7 @@ class Plaintext {
|
|
|
56
57
|
// Encode the public key and write it to the remote peer
|
|
57
58
|
await pb.write({
|
|
58
59
|
id: publicKey.toMultihash().bytes,
|
|
59
|
-
pubkey:
|
|
60
|
-
Type: KeyType[publicKey.type],
|
|
61
|
-
Data: publicKey.raw
|
|
62
|
-
}
|
|
60
|
+
pubkey: withArrayBuffer(publicKeyToProtobuf(publicKey))
|
|
63
61
|
}, options);
|
|
64
62
|
// Get the Exchange message
|
|
65
63
|
const response = await pb.read(options);
|
|
@@ -68,17 +66,17 @@ class Plaintext {
|
|
|
68
66
|
if (response.pubkey == null) {
|
|
69
67
|
throw new ProtocolError('Public key missing');
|
|
70
68
|
}
|
|
71
|
-
if (response.pubkey.
|
|
69
|
+
if (response.pubkey.byteLength === 0) {
|
|
72
70
|
throw new ProtocolError('Public key data too short');
|
|
73
71
|
}
|
|
74
72
|
if (response.id == null) {
|
|
75
73
|
throw new ProtocolError('Remote id missing');
|
|
76
74
|
}
|
|
77
|
-
const pubKey =
|
|
78
|
-
|
|
79
|
-
if (!uint8ArrayEquals(peerId.toMultihash().bytes, response.id)) {
|
|
75
|
+
const pubKey = publicKeyFromProtobuf(response.pubkey);
|
|
76
|
+
if (!uint8ArrayEquals(pubKey.toMultihash().bytes, response.id)) {
|
|
80
77
|
throw new InvalidCryptoExchangeError('Public key did not match id');
|
|
81
78
|
}
|
|
79
|
+
peerId = peerIdFromPublicKey(pubKey);
|
|
82
80
|
}
|
|
83
81
|
catch (err) {
|
|
84
82
|
log.error('invalid public key - %e', err);
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AAChF,OAAO,EAAE,mBAAmB,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACvH,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,MAAM,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAGxC,MAAM,QAAQ,GAAG,kBAAkB,CAAA;AAOnC,MAAM,SAAS;IACN,QAAQ,GAAW,QAAQ,CAAA;IACjB,UAAU,CAAY;IACtB,GAAG,CAAQ;IAE5B,YAAa,UAA+B;QAC1C,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC,UAAU,CAAA;QACvC,IAAI,CAAC,GAAG,GAAG,UAAU,CAAC,MAAM,CAAC,YAAY,CAAC,kBAAkB,CAAC,CAAA;IAC/D,CAAC;IAEQ,CAAC,MAAM,CAAC,WAAW,CAAC,GAAG,mBAAmB,CAAA;IAE1C,CAAC,mBAAmB,CAAC,GAAa;QACzC,+BAA+B;KAChC,CAAA;IAED,KAAK,CAAC,aAAa,CAAE,UAAyB,EAAE,OAAiC;QAC/E,OAAO,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AAa,CAAC,mBAAmB,CAAC,CAAA;YAC9C,CAAC;YAED,MAAM,MAAM,GAAG,qBAAqB,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;YAErD,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;gBAC/D,MAAM,IAAI,0BAA0B,CAAC,6BAA6B,CAAC,CAAA;YACrE,CAAC;YAED,MAAM,GAAG,mBAAmB,CAAC,MAAM,CAAC,CAAA;QACtC,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,GAAG,CAAC,KAAK,CAAC,yBAAyB,EAAE,GAAG,CAAC,CAAA;YACzC,MAAM,IAAI,0BAA0B,CAAC,wBAAwB,GAAG,CAAC,OAAO,EAAE,CAAC,CAAA;QAC7E,CAAC;QAED,IAAI,OAAO,EAAE,UAAU,IAAI,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,EAAE,CAAC;YACvE,MAAM,IAAI,mBAAmB,EAAE,CAAA;QACjC,CAAC;QAED,GAAG,CAAC,4DAA4D,EAAE,MAAM,CAAC,CAAA;QAEzE,OAAO;YACL,UAAU,EAAE,EAAE,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE;YAChC,UAAU,EAAE,MAAM;SACnB,CAAA;IACH,CAAC;CACF;AAED,MAAM,UAAU,SAAS;IACvB,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,IAAI,SAAS,CAAC,UAAU,CAAC,CAAA;AAClD,CAAC"}
|
package/dist/src/pb/proto.d.ts
CHANGED
|
@@ -1,52 +1,21 @@
|
|
|
1
1
|
import type { Codec, DecodeOptions } from 'protons-runtime';
|
|
2
2
|
import type { Uint8ArrayList } from 'uint8arraylist';
|
|
3
3
|
export interface Exchange {
|
|
4
|
-
id?: Uint8Array
|
|
5
|
-
pubkey?:
|
|
4
|
+
id?: Uint8Array<ArrayBuffer>;
|
|
5
|
+
pubkey?: Uint8Array<ArrayBuffer>;
|
|
6
6
|
}
|
|
7
7
|
export declare namespace Exchange {
|
|
8
8
|
const codec: () => Codec<Exchange>;
|
|
9
9
|
interface ExchangeIdFieldEvent {
|
|
10
|
-
field: '
|
|
11
|
-
value: Uint8Array
|
|
10
|
+
field: '.id';
|
|
11
|
+
value: Uint8Array<ArrayBuffer>;
|
|
12
12
|
}
|
|
13
|
-
interface
|
|
14
|
-
field: '
|
|
15
|
-
value:
|
|
13
|
+
interface ExchangePubkeyFieldEvent {
|
|
14
|
+
field: '.pubkey';
|
|
15
|
+
value: Uint8Array<ArrayBuffer>;
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
field: '$.pubkey.Data';
|
|
19
|
-
value: Uint8Array;
|
|
20
|
-
}
|
|
21
|
-
function encode(obj: Partial<Exchange>): Uint8Array;
|
|
17
|
+
function encode(obj: Partial<Exchange>): Uint8Array<ArrayBuffer>;
|
|
22
18
|
function decode(buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<Exchange>): Exchange;
|
|
23
|
-
function stream(buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<Exchange>): Generator<ExchangeIdFieldEvent |
|
|
24
|
-
}
|
|
25
|
-
export declare enum KeyType {
|
|
26
|
-
RSA = "RSA",
|
|
27
|
-
Ed25519 = "Ed25519",
|
|
28
|
-
secp256k1 = "secp256k1",
|
|
29
|
-
ECDSA = "ECDSA"
|
|
30
|
-
}
|
|
31
|
-
export declare namespace KeyType {
|
|
32
|
-
const codec: () => Codec<KeyType>;
|
|
33
|
-
}
|
|
34
|
-
export interface PublicKey {
|
|
35
|
-
Type?: KeyType;
|
|
36
|
-
Data: Uint8Array;
|
|
37
|
-
}
|
|
38
|
-
export declare namespace PublicKey {
|
|
39
|
-
const codec: () => Codec<PublicKey>;
|
|
40
|
-
interface PublicKeyTypeFieldEvent {
|
|
41
|
-
field: '$.Type';
|
|
42
|
-
value: KeyType;
|
|
43
|
-
}
|
|
44
|
-
interface PublicKeyDataFieldEvent {
|
|
45
|
-
field: '$.Data';
|
|
46
|
-
value: Uint8Array;
|
|
47
|
-
}
|
|
48
|
-
function encode(obj: Partial<PublicKey>): Uint8Array;
|
|
49
|
-
function decode(buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<PublicKey>): PublicKey;
|
|
50
|
-
function stream(buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<PublicKey>): Generator<PublicKeyTypeFieldEvent | PublicKeyDataFieldEvent>;
|
|
19
|
+
function stream(buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<Exchange>): Generator<ExchangeIdFieldEvent | ExchangePubkeyFieldEvent>;
|
|
51
20
|
}
|
|
52
21
|
//# sourceMappingURL=proto.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proto.d.ts","sourceRoot":"","sources":["../../../src/pb/proto.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"proto.d.ts","sourceRoot":"","sources":["../../../src/pb/proto.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD,MAAM,WAAW,QAAQ;IACvB,EAAE,CAAC,EAAE,UAAU,CAAC,WAAW,CAAC,CAAA;IAC5B,MAAM,CAAC,EAAE,UAAU,CAAC,WAAW,CAAC,CAAA;CACjC;AAED,yBAAiB,QAAQ,CAAC;IAGjB,MAAM,KAAK,QAAO,KAAK,CAAC,QAAQ,CA4FtC,CAAA;IAED,UAAiB,oBAAoB;QACnC,KAAK,EAAE,KAAK,CAAA;QACZ,KAAK,EAAE,UAAU,CAAC,WAAW,CAAC,CAAA;KAC/B;IAED,UAAiB,wBAAwB;QACvC,KAAK,EAAE,SAAS,CAAA;QAChB,KAAK,EAAE,UAAU,CAAC,WAAW,CAAC,CAAA;KAC/B;IAED,SAAgB,MAAM,CAAE,GAAG,EAAE,OAAO,CAAC,QAAQ,CAAC,GAAG,UAAU,CAAC,WAAW,CAAC,CAEvE;IAED,SAAgB,MAAM,CAAE,GAAG,EAAE,UAAU,GAAG,cAAc,EAAE,IAAI,CAAC,EAAE,aAAa,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAElG;IAED,SAAgB,MAAM,CAAE,GAAG,EAAE,UAAU,GAAG,cAAc,EAAE,IAAI,CAAC,EAAE,aAAa,CAAC,QAAQ,CAAC,GAAG,SAAS,CAAC,oBAAoB,GAAG,wBAAwB,CAAC,CAEpJ;CACF"}
|
package/dist/src/pb/proto.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { decodeMessage, encodeMessage,
|
|
2
|
-
import { alloc as uint8ArrayAlloc } from 'uint8arrays/alloc';
|
|
1
|
+
import { decodeMessage, encodeMessage, message, streamMessage } from 'protons-runtime';
|
|
3
2
|
export var Exchange;
|
|
4
3
|
(function (Exchange) {
|
|
5
4
|
let _codec;
|
|
@@ -15,7 +14,7 @@ export var Exchange;
|
|
|
15
14
|
}
|
|
16
15
|
if (obj.pubkey != null) {
|
|
17
16
|
w.uint32(18);
|
|
18
|
-
|
|
17
|
+
w.bytes(obj.pubkey);
|
|
19
18
|
}
|
|
20
19
|
if (opts.lengthDelimited !== false) {
|
|
21
20
|
w.ldelim();
|
|
@@ -31,9 +30,7 @@ export var Exchange;
|
|
|
31
30
|
break;
|
|
32
31
|
}
|
|
33
32
|
case 2: {
|
|
34
|
-
obj.pubkey =
|
|
35
|
-
limits: opts.limits?.pubkey
|
|
36
|
-
});
|
|
33
|
+
obj.pubkey = reader.bytes();
|
|
37
34
|
break;
|
|
38
35
|
}
|
|
39
36
|
default: {
|
|
@@ -45,20 +42,28 @@ export var Exchange;
|
|
|
45
42
|
return obj;
|
|
46
43
|
}, function* (reader, length, prefix, opts = {}) {
|
|
47
44
|
const end = length == null ? reader.len : reader.pos + length;
|
|
45
|
+
if (prefix !== '.') {
|
|
46
|
+
yield {
|
|
47
|
+
field: prefix.endsWith('.') ? prefix.substring(0, prefix.length - 1) : prefix,
|
|
48
|
+
type: 'start',
|
|
49
|
+
message: 'Exchange'
|
|
50
|
+
};
|
|
51
|
+
}
|
|
48
52
|
while (reader.pos < end) {
|
|
49
53
|
const tag = reader.uint32();
|
|
50
54
|
switch (tag >>> 3) {
|
|
51
55
|
case 1: {
|
|
52
56
|
yield {
|
|
53
|
-
field: `${prefix}
|
|
57
|
+
field: `${prefix}id`,
|
|
54
58
|
value: reader.bytes()
|
|
55
59
|
};
|
|
56
60
|
break;
|
|
57
61
|
}
|
|
58
62
|
case 2: {
|
|
59
|
-
yield
|
|
60
|
-
|
|
61
|
-
|
|
63
|
+
yield {
|
|
64
|
+
field: `${prefix}pubkey`,
|
|
65
|
+
value: reader.bytes()
|
|
66
|
+
};
|
|
62
67
|
break;
|
|
63
68
|
}
|
|
64
69
|
default: {
|
|
@@ -67,6 +72,13 @@ export var Exchange;
|
|
|
67
72
|
}
|
|
68
73
|
}
|
|
69
74
|
}
|
|
75
|
+
if (prefix !== '.') {
|
|
76
|
+
yield {
|
|
77
|
+
field: prefix.endsWith('.') ? prefix.substring(0, prefix.length - 1) : prefix,
|
|
78
|
+
type: 'end',
|
|
79
|
+
message: 'Exchange'
|
|
80
|
+
};
|
|
81
|
+
}
|
|
70
82
|
});
|
|
71
83
|
}
|
|
72
84
|
return _codec;
|
|
@@ -84,108 +96,4 @@ export var Exchange;
|
|
|
84
96
|
}
|
|
85
97
|
Exchange.stream = stream;
|
|
86
98
|
})(Exchange || (Exchange = {}));
|
|
87
|
-
export var KeyType;
|
|
88
|
-
(function (KeyType) {
|
|
89
|
-
KeyType["RSA"] = "RSA";
|
|
90
|
-
KeyType["Ed25519"] = "Ed25519";
|
|
91
|
-
KeyType["secp256k1"] = "secp256k1";
|
|
92
|
-
KeyType["ECDSA"] = "ECDSA";
|
|
93
|
-
})(KeyType || (KeyType = {}));
|
|
94
|
-
var __KeyTypeValues;
|
|
95
|
-
(function (__KeyTypeValues) {
|
|
96
|
-
__KeyTypeValues[__KeyTypeValues["RSA"] = 0] = "RSA";
|
|
97
|
-
__KeyTypeValues[__KeyTypeValues["Ed25519"] = 1] = "Ed25519";
|
|
98
|
-
__KeyTypeValues[__KeyTypeValues["secp256k1"] = 2] = "secp256k1";
|
|
99
|
-
__KeyTypeValues[__KeyTypeValues["ECDSA"] = 3] = "ECDSA";
|
|
100
|
-
})(__KeyTypeValues || (__KeyTypeValues = {}));
|
|
101
|
-
(function (KeyType) {
|
|
102
|
-
KeyType.codec = () => {
|
|
103
|
-
return enumeration(__KeyTypeValues);
|
|
104
|
-
};
|
|
105
|
-
})(KeyType || (KeyType = {}));
|
|
106
|
-
export var PublicKey;
|
|
107
|
-
(function (PublicKey) {
|
|
108
|
-
let _codec;
|
|
109
|
-
PublicKey.codec = () => {
|
|
110
|
-
if (_codec == null) {
|
|
111
|
-
_codec = message((obj, w, opts = {}) => {
|
|
112
|
-
if (opts.lengthDelimited !== false) {
|
|
113
|
-
w.fork();
|
|
114
|
-
}
|
|
115
|
-
if (obj.Type != null) {
|
|
116
|
-
w.uint32(8);
|
|
117
|
-
KeyType.codec().encode(obj.Type, w);
|
|
118
|
-
}
|
|
119
|
-
if ((obj.Data != null && obj.Data.byteLength > 0)) {
|
|
120
|
-
w.uint32(18);
|
|
121
|
-
w.bytes(obj.Data);
|
|
122
|
-
}
|
|
123
|
-
if (opts.lengthDelimited !== false) {
|
|
124
|
-
w.ldelim();
|
|
125
|
-
}
|
|
126
|
-
}, (reader, length, opts = {}) => {
|
|
127
|
-
const obj = {
|
|
128
|
-
Data: uint8ArrayAlloc(0)
|
|
129
|
-
};
|
|
130
|
-
const end = length == null ? reader.len : reader.pos + length;
|
|
131
|
-
while (reader.pos < end) {
|
|
132
|
-
const tag = reader.uint32();
|
|
133
|
-
switch (tag >>> 3) {
|
|
134
|
-
case 1: {
|
|
135
|
-
obj.Type = KeyType.codec().decode(reader);
|
|
136
|
-
break;
|
|
137
|
-
}
|
|
138
|
-
case 2: {
|
|
139
|
-
obj.Data = reader.bytes();
|
|
140
|
-
break;
|
|
141
|
-
}
|
|
142
|
-
default: {
|
|
143
|
-
reader.skipType(tag & 7);
|
|
144
|
-
break;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
return obj;
|
|
149
|
-
}, function* (reader, length, prefix, opts = {}) {
|
|
150
|
-
const end = length == null ? reader.len : reader.pos + length;
|
|
151
|
-
while (reader.pos < end) {
|
|
152
|
-
const tag = reader.uint32();
|
|
153
|
-
switch (tag >>> 3) {
|
|
154
|
-
case 1: {
|
|
155
|
-
yield {
|
|
156
|
-
field: `${prefix}.Type`,
|
|
157
|
-
value: KeyType.codec().decode(reader)
|
|
158
|
-
};
|
|
159
|
-
break;
|
|
160
|
-
}
|
|
161
|
-
case 2: {
|
|
162
|
-
yield {
|
|
163
|
-
field: `${prefix}.Data`,
|
|
164
|
-
value: reader.bytes()
|
|
165
|
-
};
|
|
166
|
-
break;
|
|
167
|
-
}
|
|
168
|
-
default: {
|
|
169
|
-
reader.skipType(tag & 7);
|
|
170
|
-
break;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
return _codec;
|
|
177
|
-
};
|
|
178
|
-
function encode(obj) {
|
|
179
|
-
return encodeMessage(obj, PublicKey.codec());
|
|
180
|
-
}
|
|
181
|
-
PublicKey.encode = encode;
|
|
182
|
-
function decode(buf, opts) {
|
|
183
|
-
return decodeMessage(buf, PublicKey.codec(), opts);
|
|
184
|
-
}
|
|
185
|
-
PublicKey.decode = decode;
|
|
186
|
-
function stream(buf, opts) {
|
|
187
|
-
return streamMessage(buf, PublicKey.codec(), opts);
|
|
188
|
-
}
|
|
189
|
-
PublicKey.stream = stream;
|
|
190
|
-
})(PublicKey || (PublicKey = {}));
|
|
191
99
|
//# sourceMappingURL=proto.js.map
|
package/dist/src/pb/proto.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proto.js","sourceRoot":"","sources":["../../../src/pb/proto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"proto.js","sourceRoot":"","sources":["../../../src/pb/proto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAStF,MAAM,KAAW,QAAQ,CAsHxB;AAtHD,WAAiB,QAAQ;IACvB,IAAI,MAAuB,CAAA;IAEd,cAAK,GAAG,GAAoB,EAAE;QACzC,IAAI,MAAM,IAAI,IAAI,EAAE,CAAC;YACnB,MAAM,GAAG,OAAO,CAAW,CAAC,GAAG,EAAE,CAAC,EAAE,IAAI,GAAG,EAAE,EAAE,EAAE;gBAC/C,IAAI,IAAI,CAAC,eAAe,KAAK,KAAK,EAAE,CAAC;oBACnC,CAAC,CAAC,IAAI,EAAE,CAAA;gBACV,CAAC;gBAED,IAAI,GAAG,CAAC,EAAE,IAAI,IAAI,EAAE,CAAC;oBACnB,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;oBACZ,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;gBACjB,CAAC;gBAED,IAAI,GAAG,CAAC,MAAM,IAAI,IAAI,EAAE,CAAC;oBACvB,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;oBACZ,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;gBACrB,CAAC;gBAED,IAAI,IAAI,CAAC,eAAe,KAAK,KAAK,EAAE,CAAC;oBACnC,CAAC,CAAC,MAAM,EAAE,CAAA;gBACZ,CAAC;YACH,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,GAAG,EAAE,EAAE,EAAE;gBAC/B,MAAM,GAAG,G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CAAC,GAAG,EAAE,QAAQ,CAAC,KAAK,EAAE,EAAE,IAAI,CAAC,CAAA;IACnD,CAAC;IAFe,eAAM,SAErB,CAAA;IAED,SAAgB,MAAM,CAAE,GAAgC,EAAE,IAA8B;QACtF,OAAO,aAAa,CAAC,GAAG,EAAE,QAAQ,CAAC,KAAK,EAAE,EAAE,IAAI,CAAC,CAAA;IACnD,CAAC;IAFe,eAAM,SAErB,CAAA;AACH,CAAC,EAtHgB,QAAQ,KAAR,QAAQ,QAsHxB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/plaintext",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.31-aa5ba42d0",
|
|
4
4
|
"description": "An insecure connection encrypter",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/connection-encrypter-plaintext#readme",
|
|
@@ -46,20 +46,21 @@
|
|
|
46
46
|
"doc-check": "aegir doc-check"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@libp2p/crypto": "5.
|
|
50
|
-
"@libp2p/interface": "3.4.0-
|
|
51
|
-
"@libp2p/peer-id": "6.0.
|
|
52
|
-
"@libp2p/utils": "7.4.
|
|
49
|
+
"@libp2p/crypto": "5.2.0-aa5ba42d0",
|
|
50
|
+
"@libp2p/interface": "3.4.0-aa5ba42d0",
|
|
51
|
+
"@libp2p/peer-id": "6.0.18-aa5ba42d0",
|
|
52
|
+
"@libp2p/utils": "7.4.4-aa5ba42d0",
|
|
53
53
|
"protons-runtime": "^7.0.0",
|
|
54
54
|
"uint8arraylist": "^3.0.2",
|
|
55
55
|
"uint8arrays": "^6.1.1"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@libp2p/crypto": "5.
|
|
59
|
-
"@libp2p/logger": "6.2.
|
|
58
|
+
"@libp2p/crypto": "5.2.0-aa5ba42d0",
|
|
59
|
+
"@libp2p/logger": "6.2.16-aa5ba42d0",
|
|
60
60
|
"aegir": "^48.1.1",
|
|
61
61
|
"protons": "^9.0.1",
|
|
62
|
-
"sinon": "^22.0.0"
|
|
62
|
+
"sinon": "^22.0.0",
|
|
63
|
+
"uint8-varint": "^3.0.0"
|
|
63
64
|
},
|
|
64
65
|
"sideEffects": false
|
|
65
66
|
}
|
package/src/index.ts
CHANGED
|
@@ -21,12 +21,13 @@
|
|
|
21
21
|
* ```
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
-
import {
|
|
24
|
+
import { publicKeyFromProtobuf, publicKeyToProtobuf } from '@libp2p/crypto/keys'
|
|
25
25
|
import { UnexpectedPeerError, InvalidCryptoExchangeError, serviceCapabilities, ProtocolError } from '@libp2p/interface'
|
|
26
26
|
import { peerIdFromPublicKey } from '@libp2p/peer-id'
|
|
27
27
|
import { pbStream } from '@libp2p/utils'
|
|
28
28
|
import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
|
|
29
|
-
import {
|
|
29
|
+
import { withArrayBuffer } from 'uint8arrays/with-array-buffer'
|
|
30
|
+
import { Exchange } from './pb/proto.ts'
|
|
30
31
|
import type { ComponentLogger, Logger, ConnectionEncrypter, SecuredConnection, PrivateKey, SecureConnectionOptions, MessageStream } from '@libp2p/interface'
|
|
31
32
|
|
|
32
33
|
const PROTOCOL = '/plaintext/2.0.0'
|
|
@@ -74,10 +75,7 @@ class Plaintext implements ConnectionEncrypter {
|
|
|
74
75
|
// Encode the public key and write it to the remote peer
|
|
75
76
|
await pb.write({
|
|
76
77
|
id: publicKey.toMultihash().bytes,
|
|
77
|
-
pubkey:
|
|
78
|
-
Type: KeyType[publicKey.type],
|
|
79
|
-
Data: publicKey.raw
|
|
80
|
-
}
|
|
78
|
+
pubkey: withArrayBuffer(publicKeyToProtobuf(publicKey))
|
|
81
79
|
}, options)
|
|
82
80
|
|
|
83
81
|
// Get the Exchange message
|
|
@@ -89,7 +87,7 @@ class Plaintext implements ConnectionEncrypter {
|
|
|
89
87
|
throw new ProtocolError('Public key missing')
|
|
90
88
|
}
|
|
91
89
|
|
|
92
|
-
if (response.pubkey.
|
|
90
|
+
if (response.pubkey.byteLength === 0) {
|
|
93
91
|
throw new ProtocolError('Public key data too short')
|
|
94
92
|
}
|
|
95
93
|
|
|
@@ -97,12 +95,13 @@ class Plaintext implements ConnectionEncrypter {
|
|
|
97
95
|
throw new ProtocolError('Remote id missing')
|
|
98
96
|
}
|
|
99
97
|
|
|
100
|
-
const pubKey =
|
|
101
|
-
peerId = peerIdFromPublicKey(pubKey)
|
|
98
|
+
const pubKey = publicKeyFromProtobuf(response.pubkey)
|
|
102
99
|
|
|
103
|
-
if (!uint8ArrayEquals(
|
|
100
|
+
if (!uint8ArrayEquals(pubKey.toMultihash().bytes, response.id)) {
|
|
104
101
|
throw new InvalidCryptoExchangeError('Public key did not match id')
|
|
105
102
|
}
|
|
103
|
+
|
|
104
|
+
peerId = peerIdFromPublicKey(pubKey)
|
|
106
105
|
} catch (err: any) {
|
|
107
106
|
log.error('invalid public key - %e', err)
|
|
108
107
|
throw new InvalidCryptoExchangeError(`Invalid public key - ${err.message}`)
|
package/src/pb/proto.proto
CHANGED
|
@@ -2,17 +2,6 @@ syntax = "proto3";
|
|
|
2
2
|
|
|
3
3
|
message Exchange {
|
|
4
4
|
optional bytes id = 1;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
enum KeyType {
|
|
9
|
-
RSA = 0;
|
|
10
|
-
Ed25519 = 1;
|
|
11
|
-
secp256k1 = 2;
|
|
12
|
-
ECDSA = 3;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
message PublicKey {
|
|
16
|
-
optional KeyType Type = 1;
|
|
17
|
-
bytes Data = 2;
|
|
5
|
+
// a protobuf encoded libp2p PublicKey
|
|
6
|
+
optional bytes pubkey = 2;
|
|
18
7
|
}
|