@libp2p/plaintext 2.0.28 → 2.0.29-8484de8a2
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 +22 -23
- package/dist/src/index.js.map +1 -1
- package/package.json +11 -13
- package/src/index.ts +24 -28
- package/dist/typedoc-urls.json +0 -6
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,EAAU,mBAAmB,EAAqB,UAAU,EAA0C,MAAM,mBAAmB,CAAA;AAI5J,MAAM,WAAW,mBAAmB;IAClC,UAAU,EAAE,UAAU,CAAA;IACtB,MAAM,EAAE,eAAe,CAAA;CACxB;AAuFD,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 '@libp2p/utils';
|
|
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,31 +39,30 @@ class Plaintext {
|
|
|
39
39
|
[serviceCapabilities] = [
|
|
40
40
|
'@libp2p/connection-encryption'
|
|
41
41
|
];
|
|
42
|
-
async secureInbound(
|
|
43
|
-
return this._encrypt(
|
|
42
|
+
async secureInbound(connection, options) {
|
|
43
|
+
return this._encrypt(connection, options);
|
|
44
44
|
}
|
|
45
|
-
async secureOutbound(
|
|
46
|
-
return this._encrypt(
|
|
45
|
+
async secureOutbound(connection, options) {
|
|
46
|
+
return this._encrypt(connection, options);
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
49
49
|
* Encrypt connection
|
|
50
50
|
*/
|
|
51
|
-
async _encrypt(
|
|
52
|
-
const
|
|
53
|
-
|
|
51
|
+
async _encrypt(connection, options) {
|
|
52
|
+
const log = connection.log?.newScope('plaintext') ?? this.log;
|
|
53
|
+
const pb = pbStream(connection).pb(Exchange);
|
|
54
|
+
log('write pubkey exchange to peer %p', options?.remotePeer);
|
|
54
55
|
const publicKey = this.privateKey.publicKey;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
pb.read(options)
|
|
66
|
-
]);
|
|
56
|
+
// Encode the public key and write it to the remote peer
|
|
57
|
+
await pb.write({
|
|
58
|
+
id: publicKey.toMultihash().bytes,
|
|
59
|
+
pubkey: {
|
|
60
|
+
Type: KeyType[publicKey.type],
|
|
61
|
+
Data: publicKey.raw
|
|
62
|
+
}
|
|
63
|
+
}, options);
|
|
64
|
+
// Get the Exchange message
|
|
65
|
+
const response = await pb.read(options);
|
|
67
66
|
let peerId;
|
|
68
67
|
try {
|
|
69
68
|
if (response.pubkey == null) {
|
|
@@ -82,15 +81,15 @@ class Plaintext {
|
|
|
82
81
|
}
|
|
83
82
|
}
|
|
84
83
|
catch (err) {
|
|
85
|
-
|
|
84
|
+
log.error(err);
|
|
86
85
|
throw new InvalidCryptoExchangeError('Invalid public key - ' + err.message);
|
|
87
86
|
}
|
|
88
87
|
if (options?.remotePeer != null && !peerId.equals(options?.remotePeer)) {
|
|
89
88
|
throw new UnexpectedPeerError();
|
|
90
89
|
}
|
|
91
|
-
|
|
90
|
+
log('plaintext key exchange completed successfully with peer %p', peerId);
|
|
92
91
|
return {
|
|
93
|
-
|
|
92
|
+
connection: pb.unwrap().unwrap(),
|
|
94
93
|
remotePeer: peerId
|
|
95
94
|
};
|
|
96
95
|
}
|
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,eAAe,CAAA;AACxC,OAAO,EAAE,MAAM,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAC/D,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAGjD,MAAM,QAAQ,G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,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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/plaintext",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.29-8484de8a2",
|
|
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,22 +45,20 @@
|
|
|
45
45
|
"doc-check": "aegir doc-check"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@libp2p/crypto": "
|
|
49
|
-
"@libp2p/interface": "
|
|
50
|
-
"@libp2p/peer-id": "
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"protons-runtime": "^5.5.0",
|
|
48
|
+
"@libp2p/crypto": "5.1.8-8484de8a2",
|
|
49
|
+
"@libp2p/interface": "2.11.0-8484de8a2",
|
|
50
|
+
"@libp2p/peer-id": "5.1.9-8484de8a2",
|
|
51
|
+
"@libp2p/utils": "6.7.2-8484de8a2",
|
|
52
|
+
"protons-runtime": "^5.6.0",
|
|
54
53
|
"uint8arraylist": "^2.4.8",
|
|
55
54
|
"uint8arrays": "^5.1.0"
|
|
56
55
|
},
|
|
57
56
|
"devDependencies": {
|
|
58
|
-
"@libp2p/crypto": "
|
|
59
|
-
"@libp2p/logger": "
|
|
60
|
-
"aegir": "^47.0.
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"sinon": "^20.0.0"
|
|
57
|
+
"@libp2p/crypto": "5.1.8-8484de8a2",
|
|
58
|
+
"@libp2p/logger": "5.2.0-8484de8a2",
|
|
59
|
+
"aegir": "^47.0.21",
|
|
60
|
+
"protons": "^7.7.0",
|
|
61
|
+
"sinon": "^21.0.0"
|
|
64
62
|
},
|
|
65
63
|
"sideEffects": false
|
|
66
64
|
}
|
package/src/index.ts
CHANGED
|
@@ -24,12 +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 '@libp2p/utils'
|
|
28
28
|
import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
|
|
29
29
|
import { Exchange, KeyType } from './pb/proto.js'
|
|
30
|
-
import type { ComponentLogger, Logger,
|
|
31
|
-
import type { Duplex } from 'it-stream-types'
|
|
32
|
-
import type { Uint8ArrayList } from 'uint8arraylist'
|
|
30
|
+
import type { ComponentLogger, Logger, ConnectionEncrypter, SecuredConnection, PrivateKey, SecureConnectionOptions, MessageStream } from '@libp2p/interface'
|
|
33
31
|
|
|
34
32
|
const PROTOCOL = '/plaintext/2.0.0'
|
|
35
33
|
|
|
@@ -54,38 +52,36 @@ class Plaintext implements ConnectionEncrypter {
|
|
|
54
52
|
'@libp2p/connection-encryption'
|
|
55
53
|
]
|
|
56
54
|
|
|
57
|
-
async secureInbound
|
|
58
|
-
return this._encrypt(
|
|
55
|
+
async secureInbound (connection: MessageStream, options?: SecureConnectionOptions): Promise<SecuredConnection> {
|
|
56
|
+
return this._encrypt(connection, options)
|
|
59
57
|
}
|
|
60
58
|
|
|
61
|
-
async secureOutbound
|
|
62
|
-
return this._encrypt(
|
|
59
|
+
async secureOutbound (connection: MessageStream, options?: SecureConnectionOptions): Promise<SecuredConnection> {
|
|
60
|
+
return this._encrypt(connection, options)
|
|
63
61
|
}
|
|
64
62
|
|
|
65
63
|
/**
|
|
66
64
|
* Encrypt connection
|
|
67
65
|
*/
|
|
68
|
-
async _encrypt
|
|
69
|
-
const
|
|
66
|
+
async _encrypt (connection: MessageStream, options?: SecureConnectionOptions): Promise<SecuredConnection> {
|
|
67
|
+
const log = connection.log?.newScope('plaintext') ?? this.log
|
|
68
|
+
const pb = pbStream(connection).pb(Exchange)
|
|
70
69
|
|
|
71
|
-
|
|
70
|
+
log('write pubkey exchange to peer %p', options?.remotePeer)
|
|
72
71
|
|
|
73
72
|
const publicKey = this.privateKey.publicKey
|
|
74
73
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
// Get the Exchange message
|
|
87
|
-
pb.read(options)
|
|
88
|
-
])
|
|
74
|
+
// Encode the public key and write it to the remote peer
|
|
75
|
+
await pb.write({
|
|
76
|
+
id: publicKey.toMultihash().bytes,
|
|
77
|
+
pubkey: {
|
|
78
|
+
Type: KeyType[publicKey.type],
|
|
79
|
+
Data: publicKey.raw
|
|
80
|
+
}
|
|
81
|
+
}, options)
|
|
82
|
+
|
|
83
|
+
// Get the Exchange message
|
|
84
|
+
const response = await pb.read(options)
|
|
89
85
|
|
|
90
86
|
let peerId
|
|
91
87
|
try {
|
|
@@ -108,7 +104,7 @@ class Plaintext implements ConnectionEncrypter {
|
|
|
108
104
|
throw new InvalidCryptoExchangeError('Public key did not match id')
|
|
109
105
|
}
|
|
110
106
|
} catch (err: any) {
|
|
111
|
-
|
|
107
|
+
log.error(err)
|
|
112
108
|
throw new InvalidCryptoExchangeError('Invalid public key - ' + err.message)
|
|
113
109
|
}
|
|
114
110
|
|
|
@@ -116,10 +112,10 @@ class Plaintext implements ConnectionEncrypter {
|
|
|
116
112
|
throw new UnexpectedPeerError()
|
|
117
113
|
}
|
|
118
114
|
|
|
119
|
-
|
|
115
|
+
log('plaintext key exchange completed successfully with peer %p', peerId)
|
|
120
116
|
|
|
121
117
|
return {
|
|
122
|
-
|
|
118
|
+
connection: pb.unwrap().unwrap(),
|
|
123
119
|
remotePeer: peerId
|
|
124
120
|
}
|
|
125
121
|
}
|
package/dist/typedoc-urls.json
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"PlaintextComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_plaintext.PlaintextComponents.html",
|
|
3
|
-
".:PlaintextComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_plaintext.PlaintextComponents.html",
|
|
4
|
-
"plaintext": "https://libp2p.github.io/js-libp2p/functions/_libp2p_plaintext.plaintext.html",
|
|
5
|
-
".:plaintext": "https://libp2p.github.io/js-libp2p/functions/_libp2p_plaintext.plaintext.html"
|
|
6
|
-
}
|