@libp2p/plaintext 2.0.29 → 3.0.0-049bfa0fa
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 +19 -21
- package/dist/src/index.js.map +1 -1
- package/package.json +11 -12
- package/src/index.ts +21 -24
- 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,32 +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 log =
|
|
53
|
-
const pb = pbStream(
|
|
51
|
+
async _encrypt(connection, options) {
|
|
52
|
+
const log = connection.log?.newScope('plaintext') ?? this.log;
|
|
53
|
+
const pb = pbStream(connection).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
|
-
|
|
66
|
-
pb.read(options)
|
|
67
|
-
]);
|
|
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);
|
|
68
66
|
let peerId;
|
|
69
67
|
try {
|
|
70
68
|
if (response.pubkey == null) {
|
|
@@ -91,7 +89,7 @@ class Plaintext {
|
|
|
91
89
|
}
|
|
92
90
|
log('plaintext key exchange completed successfully with peer %p', peerId);
|
|
93
91
|
return {
|
|
94
|
-
|
|
92
|
+
connection: pb.unwrap().unwrap(),
|
|
95
93
|
remotePeer: peerId
|
|
96
94
|
};
|
|
97
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,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,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AE,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": "
|
|
3
|
+
"version": "3.0.0-049bfa0fa",
|
|
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,21 +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
|
-
"protons-runtime": "^5.
|
|
48
|
+
"@libp2p/crypto": "5.1.9-049bfa0fa",
|
|
49
|
+
"@libp2p/interface": "3.0.0-049bfa0fa",
|
|
50
|
+
"@libp2p/peer-id": "6.0.0-049bfa0fa",
|
|
51
|
+
"@libp2p/utils": "7.0.0-049bfa0fa",
|
|
52
|
+
"protons-runtime": "^5.6.0",
|
|
53
53
|
"uint8arraylist": "^2.4.8",
|
|
54
54
|
"uint8arrays": "^5.1.0"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@libp2p/crypto": "
|
|
58
|
-
"@libp2p/logger": "
|
|
59
|
-
"aegir": "^47.0.
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"sinon": "^20.0.0"
|
|
57
|
+
"@libp2p/crypto": "5.1.9-049bfa0fa",
|
|
58
|
+
"@libp2p/logger": "6.0.0-049bfa0fa",
|
|
59
|
+
"aegir": "^47.0.22",
|
|
60
|
+
"protons": "^7.7.0",
|
|
61
|
+
"sinon": "^21.0.0"
|
|
63
62
|
},
|
|
64
63
|
"sideEffects": false
|
|
65
64
|
}
|
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 '@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,
|
|
30
|
+
import type { ComponentLogger, Logger, ConnectionEncrypter, SecuredConnection, PrivateKey, SecureConnectionOptions, MessageStream } from '@libp2p/interface'
|
|
31
31
|
|
|
32
32
|
const PROTOCOL = '/plaintext/2.0.0'
|
|
33
33
|
|
|
@@ -52,39 +52,36 @@ class Plaintext implements ConnectionEncrypter {
|
|
|
52
52
|
'@libp2p/connection-encryption'
|
|
53
53
|
]
|
|
54
54
|
|
|
55
|
-
async secureInbound
|
|
56
|
-
return this._encrypt(
|
|
55
|
+
async secureInbound (connection: MessageStream, options?: SecureConnectionOptions): Promise<SecuredConnection> {
|
|
56
|
+
return this._encrypt(connection, options)
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
async secureOutbound
|
|
60
|
-
return this._encrypt(
|
|
59
|
+
async secureOutbound (connection: MessageStream, options?: SecureConnectionOptions): Promise<SecuredConnection> {
|
|
60
|
+
return this._encrypt(connection, 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 (connection: MessageStream, options?: SecureConnectionOptions): Promise<SecuredConnection> {
|
|
67
|
+
const log = connection.log?.newScope('plaintext') ?? this.log
|
|
68
|
+
const pb = pbStream(connection).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
|
-
|
|
85
|
-
// Get the Exchange message
|
|
86
|
-
pb.read(options)
|
|
87
|
-
])
|
|
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)
|
|
88
85
|
|
|
89
86
|
let peerId
|
|
90
87
|
try {
|
|
@@ -118,7 +115,7 @@ class Plaintext implements ConnectionEncrypter {
|
|
|
118
115
|
log('plaintext key exchange completed successfully with peer %p', peerId)
|
|
119
116
|
|
|
120
117
|
return {
|
|
121
|
-
|
|
118
|
+
connection: pb.unwrap().unwrap(),
|
|
122
119
|
remotePeer: peerId
|
|
123
120
|
}
|
|
124
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
|
-
}
|