@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.
@@ -1 +1 @@
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"}
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 '@libp2p/utils';
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(connection, options) {
43
- return this._encrypt(connection, options);
42
+ async secureInbound(conn, options) {
43
+ return this._encrypt(conn, options);
44
44
  }
45
- async secureOutbound(connection, options) {
46
- return this._encrypt(connection, options);
45
+ async secureOutbound(conn, options) {
46
+ return this._encrypt(conn, options);
47
47
  }
48
48
  /**
49
49
  * Encrypt connection
50
50
  */
51
- async _encrypt(connection, options) {
52
- const log = connection.log?.newScope('plaintext') ?? this.log;
53
- const pb = pbStream(connection).pb(Exchange);
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
- // 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);
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
- connection: pb.unwrap().unwrap(),
94
+ conn: pb.unwrap().unwrap(),
93
95
  remotePeer: peerId
94
96
  };
95
97
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OA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AC,4DAA4D,EAAE,MAAM,CAAC,CAAA;QAEzE,OAAO;YACL,IAAI,EAAE,EAAE,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE;YAC1B,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.29-6059227cb",
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-6059227cb",
49
- "@libp2p/interface": "2.11.0-6059227cb",
50
- "@libp2p/peer-id": "5.1.9-6059227cb",
51
- "@libp2p/utils": "6.7.2-6059227cb",
52
- "protons-runtime": "^5.6.0",
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-6059227cb",
58
- "@libp2p/logger": "5.2.0-6059227cb",
59
- "aegir": "^47.0.22",
60
- "protons": "^7.7.0",
61
- "sinon": "^21.0.0"
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 '@libp2p/utils'
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, MessageStream } from '@libp2p/interface'
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 (connection: MessageStream, options?: SecureConnectionOptions): Promise<SecuredConnection> {
56
- return this._encrypt(connection, options)
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 (connection: MessageStream, options?: SecureConnectionOptions): Promise<SecuredConnection> {
60
- return this._encrypt(connection, options)
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 (connection: MessageStream, options?: SecureConnectionOptions): Promise<SecuredConnection> {
67
- const log = connection.log?.newScope('plaintext') ?? this.log
68
- const pb = pbStream(connection).pb(Exchange)
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
- // 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)
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
- connection: pb.unwrap().unwrap(),
121
+ conn: pb.unwrap().unwrap(),
119
122
  remotePeer: peerId
120
123
  }
121
124
  }