mirror of
https://github.com/fluencelabs/js-libp2p-noise
synced 2025-06-12 16:01:37 +00:00
Write handshake test
This commit is contained in:
@ -1,11 +1,39 @@
|
||||
import { expect } from "chai";
|
||||
import DuplexPair from 'it-pair/duplex';
|
||||
import Duplex from 'it-pair/duplex';
|
||||
import {Buffer} from "buffer";
|
||||
import Wrap from "it-pb-rpc";
|
||||
|
||||
import { Noise } from "../src";
|
||||
import {generateEd25519Keys} from "./utils";
|
||||
import {Handshake} from "../src/handshake";
|
||||
import {generateKeypair} from "../src/utils";
|
||||
|
||||
describe("Handshake", () => {
|
||||
it("should propose, exchange and finish handshake", async() => {
|
||||
const duplex = Duplex();
|
||||
const connectionFrom = Wrap(duplex[0]);
|
||||
const connectionTo = Wrap(duplex[1]);
|
||||
|
||||
const prologue = Buffer.from('/noise');
|
||||
const staticKeysInitiator = generateKeypair();
|
||||
const staticKeysResponder = generateKeypair();
|
||||
|
||||
const handshakeInitator = new Handshake('XX', staticKeysResponder.publicKey, prologue, staticKeysInitiator, connectionFrom);
|
||||
const handshakeResponder = new Handshake('XX', staticKeysInitiator.publicKey, prologue, staticKeysResponder, connectionTo);
|
||||
|
||||
console.log("Going to start with the handshake process...")
|
||||
|
||||
const sessionInitator = await handshakeInitator.propose(true);
|
||||
const sessionResponder = await handshakeResponder.propose(false);
|
||||
|
||||
console.log("Propose finished")
|
||||
|
||||
await handshakeInitator.exchange(true, sessionInitator);
|
||||
await handshakeResponder.exchange(false, sessionResponder);
|
||||
|
||||
console.log("exchange finished")
|
||||
|
||||
await handshakeInitator.finish(true, sessionInitator);
|
||||
await handshakeResponder.finish(false, sessionResponder);
|
||||
|
||||
console.log("finish finished")
|
||||
})
|
||||
});
|
||||
|
Reference in New Issue
Block a user