@libp2p/plaintext 2.0.29-6059227cb → 2.0.29-87bc8d4fb
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/index.d.ts.map +1 -1
- package/dist/src/index.js +21 -19
- package/dist/src/index.js.map +1 -1
- package/package.json +12 -11
- package/src/index.ts +24 -21
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;AAQH,OAAO,KAAK,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAQH,OAAO,KAAK,EAAE,eAAe,EAA+B,mBAAmB,EAAqB,UAAU,EAA4C,MAAM,mBAAmB,CAAA;AAInL,MAAM,WAAW,mBAAmB;IAClC,UAAU,EAAE,UAAU,CAAA;IACtB,MAAM,EAAE,eAAe,CAAA;CACxB;AA0FD,wBAAgB,SAAS,IAAK,CAAC,UAAU,EAAE,mBAAmB,KAAK,mBAAmB,CAErF"}
|
package/dist/src/index.js
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
import { publicKeyFromRaw } from '@libp2p/crypto/keys';
|
|
24
24
|
import { UnexpectedPeerError, InvalidCryptoExchangeError, serviceCapabilities, ProtocolError } from '@libp2p/interface';
|
|
25
25
|
import { peerIdFromPublicKey } from '@libp2p/peer-id';
|
|
26
|
-
import { pbStream } from '
|
|
26
|
+
import { pbStream } from 'it-protobuf-stream';
|
|
27
27
|
import { equals as uint8ArrayEquals } from 'uint8arrays/equals';
|
|
28
28
|
import { Exchange, KeyType } from './pb/proto.js';
|
|
29
29
|
const PROTOCOL = '/plaintext/2.0.0';
|
|
@@ -39,30 +39,32 @@ class Plaintext {
|
|
|
39
39
|
[serviceCapabilities] = [
|
|
40
40
|
'@libp2p/connection-encryption'
|
|
41
41
|
];
|
|
42
|
-
async secureInbound(
|
|
43
|
-
return this._encrypt(
|
|
42
|
+
async secureInbound(conn, options) {
|
|
43
|
+
return this._encrypt(conn, options);
|
|
44
44
|
}
|
|
45
|
-
async secureOutbound(
|
|
46
|
-
return this._encrypt(
|
|
45
|
+
async secureOutbound(conn, options) {
|
|
46
|
+
return this._encrypt(conn, options);
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
49
49
|
* Encrypt connection
|
|
50
50
|
*/
|
|
51
|
-
async _encrypt(
|
|
52
|
-
const log =
|
|
53
|
-
const pb = pbStream(
|
|
51
|
+
async _encrypt(conn, options) {
|
|
52
|
+
const log = conn.log?.newScope('plaintext') ?? this.log;
|
|
53
|
+
const pb = pbStream(conn).pb(Exchange);
|
|
54
54
|
log('write pubkey exchange to peer %p', options?.remotePeer);
|
|
55
55
|
const publicKey = this.privateKey.publicKey;
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
56
|
+
const [, response] = await Promise.all([
|
|
57
|
+
// Encode the public key and write it to the remote peer
|
|
58
|
+
pb.write({
|
|
59
|
+
id: publicKey.toMultihash().bytes,
|
|
60
|
+
pubkey: {
|
|
61
|
+
Type: KeyType[publicKey.type],
|
|
62
|
+
Data: publicKey.raw
|
|
63
|
+
}
|
|
64
|
+
}, options),
|
|
65
|
+
// Get the Exchange message
|
|
66
|
+
pb.read(options)
|
|
67
|
+
]);
|
|
66
68
|
let peerId;
|
|
67
69
|
try {
|
|
68
70
|
if (response.pubkey == null) {
|
|
@@ -89,7 +91,7 @@ class Plaintext {
|
|
|
89
91
|
}
|
|
90
92
|
log('plaintext key exchange completed successfully with peer %p', peerId);
|
|
91
93
|
return {
|
|
92
|
-
|
|
94
|
+
conn: pb.unwrap().unwrap(),
|
|
93
95
|
remotePeer: peerId
|
|
94
96
|
};
|
|
95
97
|
}
|
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,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AACtD,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,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AACtD,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,oBAAoB,CAAA;AAC7C,OAAO,EAAE,MAAM,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAC/D,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAGjD,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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AS;IACvB,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,IAAI,SAAS,CAAC,UAAU,CAAC,CAAA;AAClD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/plaintext",
|
|
3
|
-
"version": "2.0.29-
|
|
3
|
+
"version": "2.0.29-87bc8d4fb",
|
|
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",
|
|
@@ -45,20 +45,21 @@
|
|
|
45
45
|
"doc-check": "aegir doc-check"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@libp2p/crypto": "5.1.8-
|
|
49
|
-
"@libp2p/interface": "2.11.0-
|
|
50
|
-
"@libp2p/peer-id": "5.1.9-
|
|
51
|
-
"
|
|
52
|
-
"protons-runtime": "^5.
|
|
48
|
+
"@libp2p/crypto": "5.1.8-87bc8d4fb",
|
|
49
|
+
"@libp2p/interface": "2.11.0-87bc8d4fb",
|
|
50
|
+
"@libp2p/peer-id": "5.1.9-87bc8d4fb",
|
|
51
|
+
"it-protobuf-stream": "^2.0.2",
|
|
52
|
+
"protons-runtime": "^5.5.0",
|
|
53
53
|
"uint8arraylist": "^2.4.8",
|
|
54
54
|
"uint8arrays": "^5.1.0"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@libp2p/crypto": "5.1.8-
|
|
58
|
-
"@libp2p/logger": "5.2.0-
|
|
59
|
-
"aegir": "^47.0.
|
|
60
|
-
"
|
|
61
|
-
"
|
|
57
|
+
"@libp2p/crypto": "5.1.8-87bc8d4fb",
|
|
58
|
+
"@libp2p/logger": "5.2.0-87bc8d4fb",
|
|
59
|
+
"aegir": "^47.0.14",
|
|
60
|
+
"it-pair": "^2.0.6",
|
|
61
|
+
"protons": "^7.6.1",
|
|
62
|
+
"sinon": "^20.0.0"
|
|
62
63
|
},
|
|
63
64
|
"sideEffects": false
|
|
64
65
|
}
|
package/src/index.ts
CHANGED
|
@@ -24,10 +24,10 @@
|
|
|
24
24
|
import { publicKeyFromRaw } from '@libp2p/crypto/keys'
|
|
25
25
|
import { UnexpectedPeerError, InvalidCryptoExchangeError, serviceCapabilities, ProtocolError } from '@libp2p/interface'
|
|
26
26
|
import { peerIdFromPublicKey } from '@libp2p/peer-id'
|
|
27
|
-
import { pbStream } from '
|
|
27
|
+
import { pbStream } from 'it-protobuf-stream'
|
|
28
28
|
import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
|
|
29
29
|
import { Exchange, KeyType } from './pb/proto.js'
|
|
30
|
-
import type { ComponentLogger, Logger, ConnectionEncrypter, SecuredConnection, PrivateKey, SecureConnectionOptions,
|
|
30
|
+
import type { ComponentLogger, Logger, MultiaddrConnection, ConnectionEncrypter, SecuredConnection, PrivateKey, SecureConnectionOptions, SecurableStream } from '@libp2p/interface'
|
|
31
31
|
|
|
32
32
|
const PROTOCOL = '/plaintext/2.0.0'
|
|
33
33
|
|
|
@@ -52,36 +52,39 @@ class Plaintext implements ConnectionEncrypter {
|
|
|
52
52
|
'@libp2p/connection-encryption'
|
|
53
53
|
]
|
|
54
54
|
|
|
55
|
-
async secureInbound (
|
|
56
|
-
return this._encrypt(
|
|
55
|
+
async secureInbound<Stream extends SecurableStream = MultiaddrConnection>(conn: Stream, options?: SecureConnectionOptions): Promise<SecuredConnection<Stream>> {
|
|
56
|
+
return this._encrypt(conn, options)
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
async secureOutbound (
|
|
60
|
-
return this._encrypt(
|
|
59
|
+
async secureOutbound<Stream extends SecurableStream = MultiaddrConnection>(conn: Stream, options?: SecureConnectionOptions): Promise<SecuredConnection<Stream>> {
|
|
60
|
+
return this._encrypt(conn, options)
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
/**
|
|
64
64
|
* Encrypt connection
|
|
65
65
|
*/
|
|
66
|
-
async _encrypt (
|
|
67
|
-
const log =
|
|
68
|
-
const pb = pbStream(
|
|
66
|
+
async _encrypt<Stream extends SecurableStream = MultiaddrConnection>(conn: Stream, options?: SecureConnectionOptions): Promise<SecuredConnection<Stream>> {
|
|
67
|
+
const log = conn.log?.newScope('plaintext') ?? this.log
|
|
68
|
+
const pb = pbStream(conn).pb(Exchange)
|
|
69
69
|
|
|
70
70
|
log('write pubkey exchange to peer %p', options?.remotePeer)
|
|
71
71
|
|
|
72
72
|
const publicKey = this.privateKey.publicKey
|
|
73
73
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
74
|
+
const [
|
|
75
|
+
, response
|
|
76
|
+
] = await Promise.all([
|
|
77
|
+
// Encode the public key and write it to the remote peer
|
|
78
|
+
pb.write({
|
|
79
|
+
id: publicKey.toMultihash().bytes,
|
|
80
|
+
pubkey: {
|
|
81
|
+
Type: KeyType[publicKey.type],
|
|
82
|
+
Data: publicKey.raw
|
|
83
|
+
}
|
|
84
|
+
}, options),
|
|
85
|
+
// Get the Exchange message
|
|
86
|
+
pb.read(options)
|
|
87
|
+
])
|
|
85
88
|
|
|
86
89
|
let peerId
|
|
87
90
|
try {
|
|
@@ -115,7 +118,7 @@ class Plaintext implements ConnectionEncrypter {
|
|
|
115
118
|
log('plaintext key exchange completed successfully with peer %p', peerId)
|
|
116
119
|
|
|
117
120
|
return {
|
|
118
|
-
|
|
121
|
+
conn: pb.unwrap().unwrap(),
|
|
119
122
|
remotePeer: peerId
|
|
120
123
|
}
|
|
121
124
|
}
|