@libp2p/interface-compliance-tests 7.0.33 → 7.0.34-2d4c93ed6

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/connection-encryption/index.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,KAAK,EAAE,mBAAmB,EAAU,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAEhF,MAAM,WAAW,4BAA4B;IAC3C,UAAU,EAAE,UAAU,CAAA;CACvB;yBAEe,QAAQ,SAAS,CAAC,mBAAmB,EAAE,4BAA4B,CAAC,KAAG,IAAI;AAA3F,wBA2GC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/connection-encryption/index.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,KAAK,EAAE,mBAAmB,EAAU,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAEhF,MAAM,WAAW,4BAA4B;IAC3C,UAAU,EAAE,UAAU,CAAA;CACvB;yBAEe,QAAQ,SAAS,CAAC,mBAAmB,EAAE,4BAA4B,CAAC,KAAG,IAAI;AAA3F,wBA0MC"}
@@ -1,5 +1,5 @@
1
1
  import { generateKeyPair } from '@libp2p/crypto/keys';
2
- import { peerIdFromPrivateKey } from '@libp2p/peer-id';
2
+ import { peerIdFromPrivateKey, peerIdFromString } from '@libp2p/peer-id';
3
3
  import { multiaddrConnectionPair, echo } from '@libp2p/utils';
4
4
  import { expect } from 'aegir/chai';
5
5
  import all from 'it-all';
@@ -88,6 +88,78 @@ export default (common) => {
88
88
  expect(err).to.have.property('name', 'UnexpectedPeerError');
89
89
  });
90
90
  });
91
+ describe('remote peer id parsed from a string', () => {
92
+ let rsaKey;
93
+ let rsaPeer;
94
+ let cryptoRsa;
95
+ before(async () => {
96
+ rsaKey = await generateKeyPair('RSA', 512);
97
+ rsaPeer = peerIdFromPrivateKey(rsaKey);
98
+ cryptoRsa = await common.setup({
99
+ privateKey: rsaKey
100
+ });
101
+ });
102
+ async function secure(opts) {
103
+ const [remoteConn, localConn] = multiaddrConnectionPair();
104
+ try {
105
+ const [inboundResult, outboundResult] = await Promise.all([
106
+ opts.responder.secureInbound(localConn, {
107
+ remotePeer: opts.expectedByResponder
108
+ }),
109
+ opts.initiator.secureOutbound(remoteConn, {
110
+ remotePeer: opts.expectedByInitiator
111
+ })
112
+ ]);
113
+ return { inbound: inboundResult.remotePeer, outbound: outboundResult.remotePeer };
114
+ }
115
+ finally {
116
+ localConn.abort(new Error('test finished'));
117
+ remoteConn.abort(new Error('test finished'));
118
+ }
119
+ }
120
+ function parse(peerId) {
121
+ return peerIdFromString(peerId.toString());
122
+ }
123
+ it('should match an RSA peer id on outbound connections', async () => {
124
+ const expected = parse(rsaPeer);
125
+ expect(expected.publicKey).to.be.undefined();
126
+ const { outbound } = await secure({ initiator: crypto, responder: cryptoRsa, expectedByInitiator: expected });
127
+ expect(outbound.equals(rsaPeer)).to.be.true();
128
+ expect(outbound.publicKey?.equals(rsaKey.publicKey)).to.be.true();
129
+ });
130
+ it('should not match an RSA peer id against a different key on outbound connections', async () => {
131
+ const expected = parse(rsaPeer);
132
+ expect(expected.publicKey).to.be.undefined();
133
+ await expect(secure({ initiator: crypto, responder: cryptoRemote, expectedByInitiator: expected })).to.eventually.be.rejected
134
+ .with.property('name', 'UnexpectedPeerError');
135
+ });
136
+ it('should match an RSA peer id on inbound connections', async () => {
137
+ const expected = parse(rsaPeer);
138
+ expect(expected.publicKey).to.be.undefined();
139
+ const { inbound } = await secure({ initiator: cryptoRsa, responder: cryptoRemote, expectedByResponder: expected });
140
+ expect(inbound.equals(rsaPeer)).to.be.true();
141
+ expect(inbound.publicKey?.equals(rsaKey.publicKey)).to.be.true();
142
+ });
143
+ it('should return the key of an RSA peer on inbound connections without an expected peer', async () => {
144
+ const { inbound } = await secure({ initiator: cryptoRsa, responder: cryptoRemote });
145
+ expect(inbound.equals(rsaPeer)).to.be.true();
146
+ expect(inbound.publicKey?.equals(rsaKey.publicKey)).to.be.true();
147
+ });
148
+ it('should not match an RSA peer id against a different key on inbound connections', async () => {
149
+ const expected = parse(rsaPeer);
150
+ expect(expected.publicKey).to.be.undefined();
151
+ await expect(secure({ initiator: crypto, responder: cryptoRemote, expectedByResponder: expected })).to.eventually.be.rejected
152
+ .with.property('name', 'UnexpectedPeerError');
153
+ });
154
+ it('should match an Ed25519 peer id', async () => {
155
+ const { outbound } = await secure({ initiator: crypto, responder: cryptoRemote, expectedByInitiator: parse(remotePeer) });
156
+ expect(outbound.equals(remotePeer)).to.be.true();
157
+ });
158
+ it('should not match a different Ed25519 peer id', async () => {
159
+ await expect(secure({ initiator: crypto, responder: cryptoRemote, expectedByInitiator: parse(mitmPeer) })).to.eventually.be.rejected
160
+ .with.property('name', 'UnexpectedPeerError');
161
+ });
162
+ });
91
163
  });
92
164
  };
93
165
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/connection-encryption/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AACtD,OAAO,EAAE,uBAAuB,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACnC,OAAO,GAAG,MAAM,QAAQ,CAAA;AACxB,OAAO,QAAQ,MAAM,cAAc,CAAA;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAChC,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAQ5E,eAAe,CAAC,MAAoE,EAAQ,EAAE;IAC5F,QAAQ,CAA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C,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,mBAAmB,EAAE,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,QAAQ;qBACjI,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAA;YACjD,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/interface-compliance-tests",
3
- "version": "7.0.33",
3
+ "version": "7.0.34-2d4c93ed6",
4
4
  "description": "Compliance tests for JS libp2p interfaces",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/interface-compliance-tests#readme",
@@ -86,15 +86,15 @@
86
86
  "test:electron-main": "aegir test -t electron-main"
87
87
  },
88
88
  "dependencies": {
89
- "@libp2p/crypto": "^5.1.24",
90
- "@libp2p/echo": "^3.1.15",
91
- "@libp2p/interface": "^3.3.1",
92
- "@libp2p/interface-internal": "^3.1.14",
93
- "@libp2p/logger": "^6.2.14",
94
- "@libp2p/memory": "^2.0.29",
95
- "@libp2p/peer-id": "^6.0.16",
96
- "@libp2p/plaintext": "^3.0.29",
97
- "@libp2p/utils": "^7.4.2",
89
+ "@libp2p/crypto": "5.1.25-2d4c93ed6",
90
+ "@libp2p/echo": "3.1.16-2d4c93ed6",
91
+ "@libp2p/interface": "3.4.0-2d4c93ed6",
92
+ "@libp2p/interface-internal": "3.2.0-2d4c93ed6",
93
+ "@libp2p/logger": "6.2.15-2d4c93ed6",
94
+ "@libp2p/memory": "2.0.30-2d4c93ed6",
95
+ "@libp2p/peer-id": "6.0.17-2d4c93ed6",
96
+ "@libp2p/plaintext": "3.0.30-2d4c93ed6",
97
+ "@libp2p/utils": "7.4.3-2d4c93ed6",
98
98
  "@multiformats/multiaddr": "^13.0.3",
99
99
  "@multiformats/multiaddr-matcher": "^3.0.2",
100
100
  "aegir": "^48.1.1",
@@ -104,9 +104,9 @@
104
104
  "it-map": "^3.1.4",
105
105
  "it-pushable": "^3.2.3",
106
106
  "it-to-buffer": "^5.0.0",
107
- "libp2p": "^3.3.12",
107
+ "libp2p": "3.4.0-2d4c93ed6",
108
108
  "p-defer": "^4.0.1",
109
- "p-event": "^7.0.0",
109
+ "p-event": "^8.0.1",
110
110
  "p-retry": "^8.0.0",
111
111
  "p-wait-for": "^6.0.0",
112
112
  "protons-runtime": "^7.0.0",
@@ -1,5 +1,5 @@
1
1
  import { generateKeyPair } from '@libp2p/crypto/keys'
2
- import { peerIdFromPrivateKey } from '@libp2p/peer-id'
2
+ import { peerIdFromPrivateKey, peerIdFromString } from '@libp2p/peer-id'
3
3
  import { multiaddrConnectionPair, echo } from '@libp2p/utils'
4
4
  import { expect } from 'aegir/chai'
5
5
  import all from 'it-all'
@@ -119,5 +119,100 @@ export default (common: TestSetup<ConnectionEncrypter, ConnectionEncrypterSetupA
119
119
  expect(err).to.have.property('name', 'UnexpectedPeerError')
120
120
  })
121
121
  })
122
+
123
+ describe('remote peer id parsed from a string', () => {
124
+ let rsaKey: PrivateKey
125
+ let rsaPeer: PeerId
126
+ let cryptoRsa: ConnectionEncrypter
127
+
128
+ before(async () => {
129
+ rsaKey = await generateKeyPair('RSA', 512)
130
+ rsaPeer = peerIdFromPrivateKey(rsaKey)
131
+ cryptoRsa = await common.setup({
132
+ privateKey: rsaKey
133
+ })
134
+ })
135
+
136
+ interface SecureOptions {
137
+ initiator: ConnectionEncrypter
138
+ responder: ConnectionEncrypter
139
+ expectedByInitiator?: PeerId
140
+ expectedByResponder?: PeerId
141
+ }
142
+
143
+ async function secure (opts: SecureOptions): Promise<{ inbound: PeerId, outbound: PeerId }> {
144
+ const [remoteConn, localConn] = multiaddrConnectionPair()
145
+
146
+ try {
147
+ const [inboundResult, outboundResult] = await Promise.all([
148
+ opts.responder.secureInbound(localConn, {
149
+ remotePeer: opts.expectedByResponder
150
+ }),
151
+ opts.initiator.secureOutbound(remoteConn, {
152
+ remotePeer: opts.expectedByInitiator
153
+ })
154
+ ])
155
+
156
+ return { inbound: inboundResult.remotePeer, outbound: outboundResult.remotePeer }
157
+ } finally {
158
+ localConn.abort(new Error('test finished'))
159
+ remoteConn.abort(new Error('test finished'))
160
+ }
161
+ }
162
+
163
+ function parse (peerId: PeerId): PeerId {
164
+ return peerIdFromString(peerId.toString())
165
+ }
166
+
167
+ it('should match an RSA peer id on outbound connections', async () => {
168
+ const expected = parse(rsaPeer)
169
+ expect(expected.publicKey).to.be.undefined()
170
+
171
+ const { outbound } = await secure({ initiator: crypto, responder: cryptoRsa, expectedByInitiator: expected })
172
+ expect(outbound.equals(rsaPeer)).to.be.true()
173
+ expect(outbound.publicKey?.equals(rsaKey.publicKey)).to.be.true()
174
+ })
175
+
176
+ it('should not match an RSA peer id against a different key on outbound connections', async () => {
177
+ const expected = parse(rsaPeer)
178
+ expect(expected.publicKey).to.be.undefined()
179
+
180
+ await expect(secure({ initiator: crypto, responder: cryptoRemote, expectedByInitiator: expected })).to.eventually.be.rejected
181
+ .with.property('name', 'UnexpectedPeerError')
182
+ })
183
+
184
+ it('should match an RSA peer id on inbound connections', async () => {
185
+ const expected = parse(rsaPeer)
186
+ expect(expected.publicKey).to.be.undefined()
187
+
188
+ const { inbound } = await secure({ initiator: cryptoRsa, responder: cryptoRemote, expectedByResponder: expected })
189
+ expect(inbound.equals(rsaPeer)).to.be.true()
190
+ expect(inbound.publicKey?.equals(rsaKey.publicKey)).to.be.true()
191
+ })
192
+
193
+ it('should return the key of an RSA peer on inbound connections without an expected peer', async () => {
194
+ const { inbound } = await secure({ initiator: cryptoRsa, responder: cryptoRemote })
195
+ expect(inbound.equals(rsaPeer)).to.be.true()
196
+ expect(inbound.publicKey?.equals(rsaKey.publicKey)).to.be.true()
197
+ })
198
+
199
+ it('should not match an RSA peer id against a different key on inbound connections', async () => {
200
+ const expected = parse(rsaPeer)
201
+ expect(expected.publicKey).to.be.undefined()
202
+
203
+ await expect(secure({ initiator: crypto, responder: cryptoRemote, expectedByResponder: expected })).to.eventually.be.rejected
204
+ .with.property('name', 'UnexpectedPeerError')
205
+ })
206
+
207
+ it('should match an Ed25519 peer id', async () => {
208
+ const { outbound } = await secure({ initiator: crypto, responder: cryptoRemote, expectedByInitiator: parse(remotePeer) })
209
+ expect(outbound.equals(remotePeer)).to.be.true()
210
+ })
211
+
212
+ it('should not match a different Ed25519 peer id', async () => {
213
+ await expect(secure({ initiator: crypto, responder: cryptoRemote, expectedByInitiator: parse(mitmPeer) })).to.eventually.be.rejected
214
+ .with.property('name', 'UnexpectedPeerError')
215
+ })
216
+ })
122
217
  })
123
218
  }
@@ -1,13 +0,0 @@
1
- {
2
- "ConnectionEncrypterSetupArgs": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface-compliance-tests.connection-encryption.ConnectionEncrypterSetupArgs.html",
3
- "./connection-encryption:ConnectionEncrypterSetupArgs": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface-compliance-tests.connection-encryption.ConnectionEncrypterSetupArgs.html",
4
- "default": "https://libp2p.github.io/js-libp2p/variables/_libp2p_interface-compliance-tests.connection-encryption.default.html",
5
- "./connection-encryption:default": "https://libp2p.github.io/js-libp2p/variables/_libp2p_interface-compliance-tests.connection-encryption.default.html",
6
- "TestSetup": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface-compliance-tests.index.TestSetup.html",
7
- ".:TestSetup": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface-compliance-tests.index.TestSetup.html",
8
- "./peer-discovery:default": "https://libp2p.github.io/js-libp2p/variables/_libp2p_interface-compliance-tests.peer-discovery.default.html",
9
- "./stream-muxer:default": "https://libp2p.github.io/js-libp2p/variables/_libp2p_interface-compliance-tests.stream-muxer.default.html",
10
- "TransportTestFixtures": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface-compliance-tests.transport.TransportTestFixtures.html",
11
- "./transport:TransportTestFixtures": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_interface-compliance-tests.transport.TransportTestFixtures.html",
12
- "./transport:default": "https://libp2p.github.io/js-libp2p/variables/_libp2p_interface-compliance-tests.transport.default.html"
13
- }