mirror of
https://github.com/fluencelabs/js-libp2p-noise
synced 2025-06-18 00:41:41 +00:00
Merge remote-tracking branch 'remotes/origin/master' into feature/xx-fallback
# Conflicts: # src/handshake-xx.ts # src/noise.ts # src/utils.ts # test/noise.test.ts # test/xx-handshake.test.ts
This commit is contained in:
@ -9,7 +9,7 @@ import {XXHandshake} from "../src/handshake-xx";
|
||||
import {
|
||||
createHandshakePayload,
|
||||
generateKeypair,
|
||||
getHandshakePayload,
|
||||
getHandshakePayload, getPayload,
|
||||
signPayload
|
||||
} from "../src/utils";
|
||||
import {decode0, decode1, encode1} from "../src/encoder";
|
||||
@ -26,10 +26,8 @@ describe("Noise", () => {
|
||||
|
||||
it("should communicate through encrypted streams", async() => {
|
||||
try {
|
||||
const { privateKey: libp2pInitPrivKey } = getKeyPairFromPeerId(localPeer);
|
||||
const { privateKey: libp2pRespPrivKey } = getKeyPairFromPeerId(remotePeer);
|
||||
const noiseInit = new Noise(libp2pInitPrivKey);
|
||||
const noiseResp = new Noise(libp2pRespPrivKey);
|
||||
const noiseInit = new Noise();
|
||||
const noiseResp = new Noise();
|
||||
|
||||
const [inboundConnection, outboundConnection] = DuplexPair();
|
||||
const [outbound, inbound] = await Promise.all([
|
||||
@ -48,8 +46,7 @@ describe("Noise", () => {
|
||||
});
|
||||
|
||||
it("should test that secureOutbound is spec compliant", async() => {
|
||||
const { privateKey: libp2pInitPrivKey } = getKeyPairFromPeerId(localPeer);
|
||||
const noiseInit = new Noise(libp2pInitPrivKey);
|
||||
const noiseInit = new Noise();
|
||||
const [inboundConnection, outboundConnection] = DuplexPair();
|
||||
|
||||
const [outbound, { wrapped, handshake }] = await Promise.all([
|
||||
@ -59,9 +56,10 @@ describe("Noise", () => {
|
||||
const prologue = Buffer.from('/noise');
|
||||
const staticKeys = generateKeypair();
|
||||
const xx = new XX();
|
||||
const { privateKey: libp2pPrivKey, publicKey: libp2pPubKey } = getKeyPairFromPeerId(remotePeer);
|
||||
|
||||
const handshake = new XXHandshake(false, libp2pPrivKey, libp2pPubKey, prologue, staticKeys, wrapped, localPeer, xx);
|
||||
const payload = await getPayload(remotePeer, staticKeys.publicKey);
|
||||
const handshake = new Handshake(false, payload, prologue, staticKeys, wrapped, localPeer, xx);
|
||||
|
||||
let receivedMessageBuffer = decode0((await wrapped.readLP()).slice());
|
||||
// The first handshake message contains the initiator's ephemeral public key
|
||||
@ -69,7 +67,8 @@ describe("Noise", () => {
|
||||
xx.recvMessage(handshake.session, receivedMessageBuffer);
|
||||
|
||||
// Stage 1
|
||||
const signedPayload = signPayload(libp2pPrivKey, getHandshakePayload(staticKeys.publicKey));
|
||||
const { privateKey: libp2pPrivKey, publicKey: libp2pPubKey } = getKeyPairFromPeerId(remotePeer);
|
||||
const signedPayload = await signPayload(remotePeer, getHandshakePayload(staticKeys.publicKey));
|
||||
const handshakePayload = await createHandshakePayload(libp2pPubKey, libp2pPrivKey, signedPayload);
|
||||
|
||||
const messageBuffer = xx.sendMessage(handshake.session, handshakePayload);
|
||||
@ -101,10 +100,8 @@ describe("Noise", () => {
|
||||
|
||||
it("should test large payloads", async() => {
|
||||
try {
|
||||
const { privateKey: libp2pInitPrivKey } = getKeyPairFromPeerId(localPeer);
|
||||
const { privateKey: libp2pRespPrivKey } = getKeyPairFromPeerId(remotePeer);
|
||||
const noiseInit = new Noise(libp2pInitPrivKey);
|
||||
const noiseResp = new Noise(libp2pRespPrivKey);
|
||||
const noiseInit = new Noise();
|
||||
const noiseResp = new Noise();
|
||||
|
||||
const [inboundConnection, outboundConnection] = DuplexPair();
|
||||
const [outbound, inbound] = await Promise.all([
|
||||
|
Reference in New Issue
Block a user