mirror of
https://github.com/fluencelabs/js-libp2p-noise
synced 2025-04-25 16:02:28 +00:00
Write test and resolve babel and ts compilation
This commit is contained in:
parent
c542b53a4b
commit
0132590829
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "js-libp2p-noise",
|
"name": "js-libp2p-noise",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"main": "index.js",
|
"main": "index",
|
||||||
"repository": "git@github.com:NodeFactoryIo/js-libp2p-noise.git",
|
"repository": "git@github.com:NodeFactoryIo/js-libp2p-noise.git",
|
||||||
"author": "NodeFactory <info@nodefactory.io>",
|
"author": "NodeFactory <info@nodefactory.io>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
@ -16,9 +16,11 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/cli": "^7.6.4",
|
"@babel/cli": "^7.6.4",
|
||||||
"@babel/core": "^7.6.4",
|
"@babel/core": "^7.6.4",
|
||||||
|
"@babel/plugin-transform-runtime": "^7.6.2",
|
||||||
"@babel/preset-env": "^7.6.3",
|
"@babel/preset-env": "^7.6.3",
|
||||||
"@babel/preset-typescript": "^7.6.0",
|
"@babel/preset-typescript": "^7.6.0",
|
||||||
"@babel/register": "^7.6.2",
|
"@babel/register": "^7.6.2",
|
||||||
|
"@babel/runtime": "^7.6.3",
|
||||||
"@types/chai": "^4.2.4",
|
"@types/chai": "^4.2.4",
|
||||||
"@types/mocha": "^5.2.7",
|
"@types/mocha": "^5.2.7",
|
||||||
"@typescript-eslint/eslint-plugin": "^2.6.0",
|
"@typescript-eslint/eslint-plugin": "^2.6.0",
|
||||||
@ -34,7 +36,9 @@
|
|||||||
"@babel/preset-env",
|
"@babel/preset-env",
|
||||||
"@babel/preset-typescript"
|
"@babel/preset-typescript"
|
||||||
],
|
],
|
||||||
"plugins": []
|
"plugins": [
|
||||||
|
"@babel/plugin-transform-runtime"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bcrypto": "^4.2.3",
|
"bcrypto": "^4.2.3",
|
||||||
|
12
src/xx.ts
12
src/xx.ts
@ -1,9 +1,9 @@
|
|||||||
import {bytes32, bytes16, uint32, uint64, bytes} from './types/basic'
|
import {bytes32, bytes16, uint32, uint64, bytes} from './types/basic'
|
||||||
import { Buffer } from 'buffer';
|
import { Buffer } from 'buffer';
|
||||||
import * as crypto from 'libp2p-crypto';
|
import * as crypto from 'libp2p-crypto';
|
||||||
import AEAD from 'bcrypto/aead-browser';
|
import AEAD from 'bcrypto';
|
||||||
|
|
||||||
interface KeyPair {
|
export interface KeyPair {
|
||||||
publicKey: bytes32,
|
publicKey: bytes32,
|
||||||
privateKey: bytes32,
|
privateKey: bytes32,
|
||||||
}
|
}
|
||||||
@ -51,6 +51,7 @@ export class XXHandshake {
|
|||||||
const ss = await this.initializeSymmetric(name);
|
const ss = await this.initializeSymmetric(name);
|
||||||
await this.mixHash(ss, prologue);
|
await this.mixHash(ss, prologue);
|
||||||
|
|
||||||
|
// @ts-ignore-next-line
|
||||||
return {ss, s, e, rs, re, psk};
|
return {ss, s, e, rs, re, psk};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,6 +62,7 @@ export class XXHandshake {
|
|||||||
const ss = await this.initializeSymmetric(name);
|
const ss = await this.initializeSymmetric(name);
|
||||||
await this.mixHash(ss, prologue);
|
await this.mixHash(ss, prologue);
|
||||||
|
|
||||||
|
// @ts-ignore-next-line
|
||||||
return {ss, s, e, rs, re, psk};
|
return {ss, s, e, rs, re, psk};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,8 +153,10 @@ export class XXHandshake {
|
|||||||
return await crypto.hmac.create('sha256', Buffer.from([...a, ...b]))
|
return await crypto.hmac.create('sha256', Buffer.from([...a, ...b]))
|
||||||
}
|
}
|
||||||
|
|
||||||
public async initSession(initiator: boolean, prologue: bytes32[], s: KeyPair, rs: bytes32) : Promise<NoiseSession> {
|
public async initSession(initiator: boolean, prologue: bytes32, s: KeyPair, rs: bytes32) : Promise<NoiseSession> {
|
||||||
let session: NoiseSession;
|
// TODO: Create noisesession object/class
|
||||||
|
// @ts-ignore-next-line
|
||||||
|
let session: NoiseSession = {};
|
||||||
const psk = this.createEmptyKey();
|
const psk = this.createEmptyKey();
|
||||||
|
|
||||||
if (initiator) {
|
if (initiator) {
|
||||||
|
24
test/xx.test.ts
Normal file
24
test/xx.test.ts
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import { expect } from "chai";
|
||||||
|
import { Buffer } from 'buffer';
|
||||||
|
import * as crypto from 'libp2p-crypto';
|
||||||
|
|
||||||
|
import { XXHandshake, KeyPair } from "../src/xx";
|
||||||
|
|
||||||
|
// TODO: Move this to some protocol related file
|
||||||
|
async function generateKeypair() : Promise<KeyPair> {
|
||||||
|
return await crypto.keys.generateKeyPair('ed25519');
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("Index", () => {
|
||||||
|
const prologue = Buffer.from("/noise", "utf-8");
|
||||||
|
|
||||||
|
it("Test creating new XX session", async () => {
|
||||||
|
const kpInitiator: KeyPair = await generateKeypair();
|
||||||
|
const kpResponder: KeyPair = await generateKeypair();
|
||||||
|
|
||||||
|
const xx = new XXHandshake();
|
||||||
|
|
||||||
|
const session = await xx.initSession(true, prologue, kpInitiator, kpResponder.publicKey);
|
||||||
|
console.log(session)
|
||||||
|
})
|
||||||
|
});
|
@ -4,13 +4,15 @@
|
|||||||
"module": "commonjs",
|
"module": "commonjs",
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
|
"noImplicitAny": false,
|
||||||
"typeRoots": [
|
"typeRoots": [
|
||||||
"./node_modules/@types"
|
"./node_modules/@types"
|
||||||
],
|
|
||||||
"include": [
|
|
||||||
"./node_modules/bn.js-typings/index.d.ts"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"include": [
|
||||||
|
"**/src/**/*.ts",
|
||||||
|
"./node_modules/bn.js-typings/index.d.ts"
|
||||||
|
],
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"node_modules"
|
"node_modules"
|
||||||
]
|
]
|
||||||
|
26
yarn.lock
26
yarn.lock
@ -538,6 +538,16 @@
|
|||||||
dependencies:
|
dependencies:
|
||||||
"@babel/helper-plugin-utils" "^7.0.0"
|
"@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":
|
"@babel/plugin-transform-shorthand-properties@^7.2.0":
|
||||||
version "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"
|
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-shorthand-properties/-/plugin-transform-shorthand-properties-7.2.0.tgz#6333aee2f8d6ee7e28615457298934a3b46198f0"
|
||||||
@ -668,6 +678,13 @@
|
|||||||
pirates "^4.0.0"
|
pirates "^4.0.0"
|
||||||
source-map-support "^0.5.9"
|
source-map-support "^0.5.9"
|
||||||
|
|
||||||
|
"@babel/runtime@^7.6.3":
|
||||||
|
version "7.6.3"
|
||||||
|
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.6.3.tgz#935122c74c73d2240cafd32ddb5fc2a6cd35cf1f"
|
||||||
|
integrity sha512-kq6anf9JGjW8Nt5rYfEuGRaEAaH1mkv3Bbu6rYvLOpPh/RusSJXuKPEAoZ7L7gybZkchE8+NV5g9vKF4AGAtsA==
|
||||||
|
dependencies:
|
||||||
|
regenerator-runtime "^0.13.2"
|
||||||
|
|
||||||
"@babel/template@^7.1.0", "@babel/template@^7.4.4", "@babel/template@^7.6.0":
|
"@babel/template@^7.1.0", "@babel/template@^7.4.4", "@babel/template@^7.6.0":
|
||||||
version "7.6.0"
|
version "7.6.0"
|
||||||
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.6.0.tgz#7f0159c7f5012230dad64cca42ec9bdb5c9536e6"
|
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.6.0.tgz#7f0159c7f5012230dad64cca42ec9bdb5c9536e6"
|
||||||
@ -3038,6 +3055,11 @@ regenerate@^1.4.0:
|
|||||||
resolved "https://registry.yarnpkg.com/regenerate/-/regenerate-1.4.0.tgz#4a856ec4b56e4077c557589cae85e7a4c8869a11"
|
resolved "https://registry.yarnpkg.com/regenerate/-/regenerate-1.4.0.tgz#4a856ec4b56e4077c557589cae85e7a4c8869a11"
|
||||||
integrity sha512-1G6jJVDWrt0rK99kBjvEtziZNCICAuvIPkSiUFIQxVP06RCVpq3dmDo2oi6ABpYaDYaTRr67BEhL8r1wgEZZKg==
|
integrity sha512-1G6jJVDWrt0rK99kBjvEtziZNCICAuvIPkSiUFIQxVP06RCVpq3dmDo2oi6ABpYaDYaTRr67BEhL8r1wgEZZKg==
|
||||||
|
|
||||||
|
regenerator-runtime@^0.13.2:
|
||||||
|
version "0.13.3"
|
||||||
|
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.3.tgz#7cf6a77d8f5c6f60eb73c5fc1955b2ceb01e6bf5"
|
||||||
|
integrity sha512-naKIZz2GQ8JWh///G7L3X6LaQUAMp2lvb1rvwwsURe/VXwD6VMfr+/1NuNw3ag8v2kY1aQ/go5SNn79O9JU7yw==
|
||||||
|
|
||||||
regenerator-transform@^0.14.0:
|
regenerator-transform@^0.14.0:
|
||||||
version "0.14.1"
|
version "0.14.1"
|
||||||
resolved "https://registry.yarnpkg.com/regenerator-transform/-/regenerator-transform-0.14.1.tgz#3b2fce4e1ab7732c08f665dfdb314749c7ddd2fb"
|
resolved "https://registry.yarnpkg.com/regenerator-transform/-/regenerator-transform-0.14.1.tgz#3b2fce4e1ab7732c08f665dfdb314749c7ddd2fb"
|
||||||
@ -3117,7 +3139,7 @@ resolve-url@^0.2.1:
|
|||||||
resolved "https://registry.yarnpkg.com/resolve-url/-/resolve-url-0.2.1.tgz#2c637fe77c893afd2a663fe21aa9080068e2052a"
|
resolved "https://registry.yarnpkg.com/resolve-url/-/resolve-url-0.2.1.tgz#2c637fe77c893afd2a663fe21aa9080068e2052a"
|
||||||
integrity sha1-LGN/53yJOv0qZj/iGqkIAGjiBSo=
|
integrity sha1-LGN/53yJOv0qZj/iGqkIAGjiBSo=
|
||||||
|
|
||||||
resolve@^1.3.2:
|
resolve@^1.3.2, resolve@^1.8.1:
|
||||||
version "1.12.0"
|
version "1.12.0"
|
||||||
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.12.0.tgz#3fc644a35c84a48554609ff26ec52b66fa577df6"
|
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.12.0.tgz#3fc644a35c84a48554609ff26ec52b66fa577df6"
|
||||||
integrity sha512-B/dOmuoAik5bKcD6s6nXDCjzUKnaDvdkRyAk6rsmsKLipWj4797iothd7jmmUhWTfinVMU+wc56rYKsit2Qy4w==
|
integrity sha512-B/dOmuoAik5bKcD6s6nXDCjzUKnaDvdkRyAk6rsmsKLipWj4797iothd7jmmUhWTfinVMU+wc56rYKsit2Qy4w==
|
||||||
@ -3229,7 +3251,7 @@ secp256k1@^3.6.2:
|
|||||||
nan "^2.14.0"
|
nan "^2.14.0"
|
||||||
safe-buffer "^5.1.2"
|
safe-buffer "^5.1.2"
|
||||||
|
|
||||||
semver@^5.3.0, semver@^5.4.1, semver@^5.5.0, semver@^5.6.0, semver@^5.7.0:
|
semver@^5.3.0, semver@^5.4.1, semver@^5.5.0, semver@^5.5.1, semver@^5.6.0, semver@^5.7.0:
|
||||||
version "5.7.1"
|
version "5.7.1"
|
||||||
resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7"
|
resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7"
|
||||||
integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==
|
integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==
|
||||||
|
Loading…
x
Reference in New Issue
Block a user