mirror of
https://github.com/fluencelabs/js-libp2p-noise
synced 2025-06-10 21:21:38 +00:00
Address PR comments
This commit is contained in:
13
package.json
13
package.json
@ -17,7 +17,6 @@
|
||||
"@babel/cli": "^7.6.4",
|
||||
"@babel/core": "^7.6.4",
|
||||
"@babel/plugin-proposal-object-rest-spread": "^7.6.2",
|
||||
"@babel/plugin-transform-runtime": "^7.6.2",
|
||||
"@babel/preset-env": "^7.6.3",
|
||||
"@babel/preset-typescript": "^7.6.0",
|
||||
"@babel/register": "^7.6.2",
|
||||
@ -29,16 +28,23 @@
|
||||
"bn.js-typings": "^1.0.1",
|
||||
"chai": "^4.2.0",
|
||||
"eslint": "^6.6.0",
|
||||
"libp2p-crypto": "^0.17.1",
|
||||
"mocha": "^6.2.2",
|
||||
"typescript": "^3.6.4"
|
||||
},
|
||||
"babel": {
|
||||
"presets": [
|
||||
"@babel/preset-env",
|
||||
[
|
||||
"@babel/preset-env",
|
||||
{
|
||||
"targets": {
|
||||
"node": "12"
|
||||
}
|
||||
}
|
||||
],
|
||||
"@babel/preset-typescript"
|
||||
],
|
||||
"plugins": [
|
||||
"@babel/plugin-transform-runtime",
|
||||
"@babel/plugin-proposal-object-rest-spread"
|
||||
]
|
||||
},
|
||||
@ -46,7 +52,6 @@
|
||||
"bcrypto": "^4.2.3",
|
||||
"bn.js": "^5.0.0",
|
||||
"buffer": "^5.4.3",
|
||||
"libp2p-crypto": "^0.17.1",
|
||||
"protobufjs": "~6.8.8"
|
||||
}
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ export class XXHandshake {
|
||||
return result;
|
||||
}
|
||||
|
||||
private convertNonce(n: uint32) : bytes {
|
||||
private nonceToBytes(n: uint32) : bytes {
|
||||
const nonce = Buffer.alloc(12);
|
||||
nonce.writeUInt32LE(n, 4);
|
||||
|
||||
@ -88,7 +88,7 @@ export class XXHandshake {
|
||||
}
|
||||
|
||||
private encrypt(k: bytes32, n: uint32, ad: bytes, plaintext: bytes) : bytes {
|
||||
const nonce = this.convertNonce(n);
|
||||
const nonce = this.nonceToBytes(n);
|
||||
const ctx = new AEAD();
|
||||
ctx.init(k, nonce);
|
||||
ctx.aad(ad);
|
||||
@ -98,7 +98,7 @@ export class XXHandshake {
|
||||
}
|
||||
|
||||
private decrypt(k: bytes32, n: uint32, ad: bytes, ciphertext: bytes) : bytes {
|
||||
const nonce = this.convertNonce(n);
|
||||
const nonce = this.nonceToBytes(n);
|
||||
const ctx = new AEAD();
|
||||
|
||||
ctx.init(k, nonce);
|
||||
@ -123,7 +123,7 @@ export class XXHandshake {
|
||||
return !this.isEmptyKey(cs.k);
|
||||
}
|
||||
|
||||
private setNonce(cs: CipherState, nonce: uint32) {
|
||||
private setNonce(cs: CipherState, nonce: uint32) : void {
|
||||
cs.n = nonce;
|
||||
}
|
||||
|
||||
|
11
test/utils.ts
Normal file
11
test/utils.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import protobuf from "protobufjs";
|
||||
import * as crypto from 'libp2p-crypto';
|
||||
|
||||
export async function loadPayloadProto () {
|
||||
const payloadProtoBuf = await protobuf.load("protos/payload.proto");
|
||||
return payloadProtoBuf.lookupType("pb.NoiseHandshakePayload");
|
||||
}
|
||||
|
||||
export async function generateEd25519Keys() {
|
||||
return await crypto.keys.generateKeyPair('ed25519');
|
||||
}
|
@ -1,10 +1,9 @@
|
||||
import { expect, assert } from "chai";
|
||||
import { Buffer } from 'buffer';
|
||||
import * as crypto from 'libp2p-crypto';
|
||||
import protobuf from 'protobufjs';
|
||||
import { ed25519 } from 'bcrypto';
|
||||
|
||||
import { XXHandshake, KeyPair } from "../src/xx";
|
||||
import { loadPayloadProto, generateEd25519Keys } from "./utils";
|
||||
|
||||
describe("Index", () => {
|
||||
const prologue = Buffer.from("/noise", "utf-8");
|
||||
@ -32,10 +31,6 @@ describe("Index", () => {
|
||||
expect(k3.toString('hex')).to.equal('ff67bf9727e31b06efc203907e6786667d2c7a74ac412b4d31a80ba3fd766f68');
|
||||
})
|
||||
|
||||
async function generateEd25519Keys() {
|
||||
return await crypto.keys.generateKeyPair('ed25519');
|
||||
}
|
||||
|
||||
async function doHandshake(xx) {
|
||||
const kpInit = await xx.generateKeypair();
|
||||
const kpResp = await xx.generateKeypair();
|
||||
@ -57,8 +52,7 @@ describe("Index", () => {
|
||||
/* STAGE 0 */
|
||||
|
||||
// initiator creates payload
|
||||
const payloadProtoBuf = await protobuf.load("payload.proto");
|
||||
const NoiseHandshakePayload = payloadProtoBuf.lookupType("pb.NoiseHandshakePayload");
|
||||
const NoiseHandshakePayload = await loadPayloadProto();
|
||||
const payloadInit = NoiseHandshakePayload.create({
|
||||
libp2pKey: libp2pInitKeys.bytes,
|
||||
noiseStaticKeySignature: initSignedPayload,
|
||||
@ -113,4 +107,5 @@ describe("Index", () => {
|
||||
const xx = new XXHandshake();
|
||||
await doHandshake(xx);
|
||||
});
|
||||
|
||||
});
|
||||
|
14
yarn.lock
14
yarn.lock
@ -538,16 +538,6 @@
|
||||
dependencies:
|
||||
"@babel/helper-plugin-utils" "^7.0.0"
|
||||
|
||||
"@babel/plugin-transform-runtime@^7.6.2":
|
||||
version "7.6.2"
|
||||
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-runtime/-/plugin-transform-runtime-7.6.2.tgz#2669f67c1fae0ae8d8bf696e4263ad52cb98b6f8"
|
||||
integrity sha512-cqULw/QB4yl73cS5Y0TZlQSjDvNkzDbu0FurTZyHlJpWE5T3PCMdnyV+xXoH1opr1ldyHODe3QAX3OMAii5NxA==
|
||||
dependencies:
|
||||
"@babel/helper-module-imports" "^7.0.0"
|
||||
"@babel/helper-plugin-utils" "^7.0.0"
|
||||
resolve "^1.8.1"
|
||||
semver "^5.5.1"
|
||||
|
||||
"@babel/plugin-transform-shorthand-properties@^7.2.0":
|
||||
version "7.2.0"
|
||||
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-shorthand-properties/-/plugin-transform-shorthand-properties-7.2.0.tgz#6333aee2f8d6ee7e28615457298934a3b46198f0"
|
||||
@ -3226,7 +3216,7 @@ resolve-url@^0.2.1:
|
||||
resolved "https://registry.yarnpkg.com/resolve-url/-/resolve-url-0.2.1.tgz#2c637fe77c893afd2a663fe21aa9080068e2052a"
|
||||
integrity sha1-LGN/53yJOv0qZj/iGqkIAGjiBSo=
|
||||
|
||||
resolve@^1.3.2, resolve@^1.8.1:
|
||||
resolve@^1.3.2:
|
||||
version "1.12.0"
|
||||
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.12.0.tgz#3fc644a35c84a48554609ff26ec52b66fa577df6"
|
||||
integrity sha512-B/dOmuoAik5bKcD6s6nXDCjzUKnaDvdkRyAk6rsmsKLipWj4797iothd7jmmUhWTfinVMU+wc56rYKsit2Qy4w==
|
||||
@ -3338,7 +3328,7 @@ secp256k1@^3.6.2:
|
||||
nan "^2.14.0"
|
||||
safe-buffer "^5.1.2"
|
||||
|
||||
semver@^5.3.0, semver@^5.4.1, semver@^5.5.0, semver@^5.5.1, semver@^5.6.0, semver@^5.7.0:
|
||||
semver@^5.3.0, semver@^5.4.1, semver@^5.5.0, semver@^5.6.0, semver@^5.7.0:
|
||||
version "5.7.1"
|
||||
resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7"
|
||||
integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==
|
||||
|
Reference in New Issue
Block a user