mirror of
https://github.com/fluencelabs/js-libp2p-noise
synced 2025-04-25 18:32:22 +00:00
Complete test
This commit is contained in:
parent
051f0765f9
commit
3b5a401a1c
@ -127,13 +127,14 @@ export class XXHandshake {
|
|||||||
cs.n = nonce;
|
cs.n = nonce;
|
||||||
}
|
}
|
||||||
|
|
||||||
private encryptWithAd(cs: CipherState, ad: bytes, plaintext: bytes) : bytes {
|
public encryptWithAd(cs: CipherState, ad: bytes, plaintext: bytes) : bytes {
|
||||||
const e = this.encrypt(cs.k, cs.n, ad, plaintext);
|
const e = this.encrypt(cs.k, cs.n, ad, plaintext);
|
||||||
this.setNonce(cs, this.incrementNonce(cs.n));
|
this.setNonce(cs, this.incrementNonce(cs.n));
|
||||||
|
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
private decryptWithAd(cs: CipherState, ad: bytes, ciphertext: bytes) : bytes {
|
public decryptWithAd(cs: CipherState, ad: bytes, ciphertext: bytes) : bytes {
|
||||||
const plaintext = this.decrypt(cs.k, cs.n, ad, ciphertext);
|
const plaintext = this.decrypt(cs.k, cs.n, ad, ciphertext);
|
||||||
this.setNonce(cs, this.incrementNonce(cs.n));
|
this.setNonce(cs, this.incrementNonce(cs.n));
|
||||||
|
|
||||||
|
@ -36,8 +36,7 @@ describe("Index", () => {
|
|||||||
return await crypto.keys.generateKeyPair('ed25519');
|
return await crypto.keys.generateKeyPair('ed25519');
|
||||||
}
|
}
|
||||||
|
|
||||||
async function doHandshake() {
|
async function doHandshake(xx) {
|
||||||
const xx = new XXHandshake();
|
|
||||||
const kpInit = await xx.generateKeypair();
|
const kpInit = await xx.generateKeypair();
|
||||||
const kpResp = await xx.generateKeypair();
|
const kpResp = await xx.generateKeypair();
|
||||||
const payloadString = Buffer.from("noise-libp2p-static-key:");
|
const payloadString = Buffer.from("noise-libp2p-static-key:");
|
||||||
@ -99,14 +98,19 @@ describe("Index", () => {
|
|||||||
|
|
||||||
// initiator send message
|
// initiator send message
|
||||||
const messageBuffer3 = await xx.sendMessage(nsInit, Buffer.alloc(0));
|
const messageBuffer3 = await xx.sendMessage(nsInit, Buffer.alloc(0));
|
||||||
|
|
||||||
// responder receive message
|
// responder receive message
|
||||||
const plaintext3 = await xx.recvMessage(nsResp, messageBuffer3);
|
const plaintext3 = await xx.recvMessage(nsResp, messageBuffer3);
|
||||||
console.log("Stage 2 responder payload: ", plaintext3);
|
console.log("Stage 2 responder payload: ", plaintext3);
|
||||||
|
|
||||||
|
assert(nsInit.cs1.k.equals(nsResp.cs1.k));
|
||||||
|
assert(nsInit.cs2.k.equals(nsResp.cs2.k));
|
||||||
|
|
||||||
return { nsInit, nsResp };
|
return { nsInit, nsResp };
|
||||||
}
|
}
|
||||||
|
|
||||||
it("Test handshake", async () => {
|
it("Test handshake", async () => {
|
||||||
await doHandshake();
|
const xx = new XXHandshake();
|
||||||
})
|
await doHandshake(xx);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user