mirror of
https://github.com/fluencelabs/js-libp2p-noise
synced 2025-07-31 18:12:19 +00:00
Update setting remote id
This commit is contained in:
@@ -300,4 +300,35 @@ describe("Noise", () => {
|
||||
assert(false, e.message);
|
||||
}
|
||||
});
|
||||
|
||||
it("should working without remote peer provided in incoming connection", async() => {
|
||||
try {
|
||||
const staticKeysInitiator = generateKeypair();
|
||||
const noiseInit = new Noise(staticKeysInitiator.privateKey);
|
||||
const staticKeysResponder = generateKeypair();
|
||||
const noiseResp = new Noise(staticKeysResponder.privateKey);
|
||||
|
||||
// Prepare key cache for noise pipes
|
||||
KeyCache.store(localPeer, staticKeysInitiator.publicKey);
|
||||
KeyCache.store(remotePeer, staticKeysResponder.publicKey);
|
||||
|
||||
const [inboundConnection, outboundConnection] = DuplexPair();
|
||||
const [outbound, inbound] = await Promise.all([
|
||||
noiseInit.secureOutbound(localPeer, outboundConnection, remotePeer),
|
||||
noiseResp.secureInbound(remotePeer, inboundConnection),
|
||||
]);
|
||||
const wrappedInbound = Wrap(inbound.conn);
|
||||
const wrappedOutbound = Wrap(outbound.conn);
|
||||
|
||||
wrappedOutbound.writeLP(Buffer.from("test v2"));
|
||||
const response = await wrappedInbound.readLP();
|
||||
expect(response.toString()).equal("test v2");
|
||||
|
||||
assert(inbound.remotePeer.marshalPubKey().equals(localPeer.marshalPubKey()));
|
||||
assert(outbound.remotePeer.marshalPubKey().equals(remotePeer.marshalPubKey()));
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
assert(false, e.message);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user