diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e6dcb7f..113cdbf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, macos-latest, windows-latest] - node-version: ["16", "18", "20"] + node-version: [lts/*, lts/-1, lts/-2] steps: - name: Checkout project diff --git a/package-lock.json b/package-lock.json index b6b78bd..5880f3d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,13 +11,12 @@ "dependencies": { "wasmbuilder": "0.0.16", "wasmcurves": "0.2.2", - "web-worker": "1.2.0" + "web-worker": "1.5.0" }, "devDependencies": { "@rollup/plugin-commonjs": "^25.0.4", "@rollup/plugin-node-resolve": "^15.2.1", "@rollup/plugin-replace": "^5.0.3", - "blake2b": "^2.1.3", "chai": "^5.1.1", "eslint": "^9.12.0", "mocha": "^10.7.3", @@ -128,18 +127,32 @@ } }, "node_modules/@eslint/plugin-kit": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/@eslint/plugin-kit/-/plugin-kit-0.2.0.tgz", - "integrity": "sha512-vH9PiIMMwvhCx31Af3HiGzsVNULDbyVkHXwlemn/B0TFj/00ho3y55efXrUZTfQipxoHC5u4xq6zblww1zm1Ig==", + "version": "0.2.8", + "resolved": "https://registry.npmjs.org/@eslint/plugin-kit/-/plugin-kit-0.2.8.tgz", + "integrity": "sha512-ZAoA40rNMPwSm+AeHpCq8STiNAwzWLJuP8Xv4CHIc9wv/PSuExjMrmjfYNj682vW0OOiZ1HKxzvjQr9XZIisQA==", "dev": true, "license": "Apache-2.0", "dependencies": { + "@eslint/core": "^0.13.0", "levn": "^0.4.1" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" } }, + "node_modules/@eslint/plugin-kit/node_modules/@eslint/core": { + "version": "0.13.0", + "resolved": "https://registry.npmjs.org/@eslint/core/-/core-0.13.0.tgz", + "integrity": "sha512-yfkgDw1KR66rkT5A8ci4irzDysN7FRpq3ttJolR88OqQikAWqwA8j5VZyas+vjyBNFIJ7MfybJ9plMILI2UrCw==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@types/json-schema": "^7.0.15" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + } + }, "node_modules/@humanfs/core": { "version": "0.19.0", "resolved": "https://registry.npmjs.org/@humanfs/core/-/core-0.19.0.tgz", @@ -413,12 +426,6 @@ "node": ">=12" } }, - "node_modules/b4a": { - "version": "1.6.4", - "resolved": "https://registry.npmjs.org/b4a/-/b4a-1.6.4.tgz", - "integrity": "sha512-fpWrvyVHEKyeEvbKZTVOeZF3VSKKWtJxFIxX/jaVPf+cLbGUSitjb49pHLqPV2BUNNZ0LcoeEGfE/YCpyDYHIw==", - "dev": true - }, "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -434,26 +441,6 @@ "node": ">=8" } }, - "node_modules/blake2b": { - "version": "2.1.4", - "resolved": "https://registry.npmjs.org/blake2b/-/blake2b-2.1.4.tgz", - "integrity": "sha512-AyBuuJNI64gIvwx13qiICz6H6hpmjvYS5DGkG6jbXMOT8Z3WUJ3V1X0FlhIoT1b/5JtHE3ki+xjtMvu1nn+t9A==", - "dev": true, - "dependencies": { - "blake2b-wasm": "^2.4.0", - "nanoassert": "^2.0.0" - } - }, - "node_modules/blake2b-wasm": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/blake2b-wasm/-/blake2b-wasm-2.4.0.tgz", - "integrity": "sha512-S1kwmW2ZhZFFFOghcx73+ZajEfKBqhP82JMssxtLVMxlaPea1p9uoLiUZ5WYyHn0KddwbLc+0vh4wR0KBNoT5w==", - "dev": true, - "dependencies": { - "b4a": "^1.0.1", - "nanoassert": "^2.0.0" - } - }, "node_modules/brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", @@ -641,10 +628,11 @@ "dev": true }, "node_modules/cross-spawn": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", - "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", + "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", "dev": true, + "license": "MIT", "dependencies": { "path-key": "^3.1.0", "shebang-command": "^2.0.0", @@ -1533,12 +1521,6 @@ "dev": true, "license": "MIT" }, - "node_modules/nanoassert": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/nanoassert/-/nanoassert-2.0.0.tgz", - "integrity": "sha512-7vO7n28+aYO4J+8w96AzhmU8G+Y/xpPDJz/se19ICsqj/momRbb9mh9ZUtkoJ5X3nTnPdhEJyc0qnM6yAsHBaA==", - "dev": true - }, "node_modules/natural-compare": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", @@ -1932,9 +1914,10 @@ } }, "node_modules/web-worker": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/web-worker/-/web-worker-1.2.0.tgz", - "integrity": "sha512-PgF341avzqyx60neE9DD+XS26MMNMoUQRz9NOZwW32nPQrF6p77f1htcnjBSEV8BGMKZ16choqUG4hyI0Hx7mA==" + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/web-worker/-/web-worker-1.5.0.tgz", + "integrity": "sha512-RiMReJrTAiA+mBjGONMnjVDP2u3p9R1vkcGz6gDIrOMT3oGuYwX2WRMYI9ipkphSuE5XKEhydbhNEJh4NY9mlw==", + "license": "Apache-2.0" }, "node_modules/which": { "version": "2.0.2", diff --git a/package.json b/package.json index 1fee00b..a3ad475 100644 --- a/package.json +++ b/package.json @@ -41,13 +41,12 @@ "dependencies": { "wasmbuilder": "0.0.16", "wasmcurves": "0.2.2", - "web-worker": "1.2.0" + "web-worker": "1.5.0" }, "devDependencies": { "@rollup/plugin-commonjs": "^25.0.4", "@rollup/plugin-node-resolve": "^15.2.1", "@rollup/plugin-replace": "^5.0.3", - "blake2b": "^2.1.3", "chai": "^5.1.1", "eslint": "^9.12.0", "mocha": "^10.7.3", diff --git a/test.js b/test.js deleted file mode 100644 index 9554235..0000000 --- a/test.js +++ /dev/null @@ -1,137 +0,0 @@ - -const bn128 = require("./index").bn128; -const utils = require("./index").utils; - -const Fq = bn128.F1; - -const blake2b = require("blake2b"); - -const ChaCha = require("./src/chacha"); - -const pubKey = { - tau_g1_s: [ - Fq.e("0x1403cf4fed293e66a8cd522be9f938524111f6f08762371bff53ee387a39cf13"), - Fq.e("0x2accbda355c222301a1bd802db7454d86a4ec2ee89ae895ca21f147d6b705740"), - Fq.e("1") - ], - tau_g1_sx: [ - Fq.e("0x12996cf89d854246f1ab002e446436b77a64349117ec1fb2aa57a304890e81ef"), - Fq.e("0x0c17fd067df52c480a1db3c6890821f975932d89d0d53c6c60777cc56f1dd712"), - Fq.e("1") - ], - alpha_g1_s:[ - Fq.e("0x12a64bbe8af7fcb19052e25e188c1fcdac454928142f8e89f58e03249e18b223"), - Fq.e("0x22be31a388d0ec551530e1b1581b671b4340e88990de805a7bfed8bdb9c1accd"), - Fq.e("1") - ], - alpha_g1_sx: [ - Fq.e("0x262ff8dd594374c6ed5e892ba31315f6e47c500784a12ea8d2c573730888a392"), - Fq.e("0x0b3a94f2b61178f2974e039cfd671e7405ec43eb2c09dc8f43a34f450917a62f"), - Fq.e("1") - ], - beta_g1_s: [ - Fq.e("0x0d9b3088b69daf6746c6bba4f9b359234abbfd3306bce14b198e7a5556c777e6"), - Fq.e("0x066d1acac914883df6a9dc57dc2037a481ba4b8646efe13e2584b9258bd52d0c"), - Fq.e("1") - ], - beta_g1_sx: [ - Fq.e("0x248232878c359dbe632c387dc0d955520e8d3363f1cd9621ec9fd4a05460c754"), - Fq.e("0x12074f06ef232a472cb36c328e760c4acfb4bedad4ca3ee09971578a0fe185ab"), - Fq.e("1") - ], - tau_g2_spx: [ - [ - Fq.e("0x0fe02fcc3aee51c1f3a37f3f152ebe5476ae659468f2ee81cdeb19d0dad366c5"), - Fq.e("0x01aeb4db892bcb273aada80f5eab10e2e50ae59a5c274b0d7303f5c5a52ee88b"), - ],[ - Fq.e("0x2d00022d840d493fb93c68a63b29e2692c0cd3caf354fe60eae1ebacefc2c948"), - Fq.e("0x204065ff10344153a08cfe4ae543c47fba883ef8a54530fa6a52c87e5c28ef2b"), - ],[ - Fq.e("1"), - Fq.e("0") - ] - ], - alpha_g2_spx: [ - [ - Fq.e("0x2e649d01a58a7795762df8f0634c273ebce6950a9a2ba3d4459458620d3164a0"), - Fq.e("0x1b58044d3e205a918124fea3983583199b4f99fd0abb39ede2c684b0810bdc1e"), - ],[ - Fq.e("0x021d41558cea5fa32c9f3de5834cb2ee45ce4cdf471353395d019dfe0c9c2509"), - Fq.e("0x1c04148bac3f17b219c2655cd63ad2596ea63293103487be488a1d5a9054ddbf"), - ],[ - Fq.e("1"), - Fq.e("0") - ] - ], - beta_g2_spx: [ - [ - Fq.e("0x029251aed5163109667300035ce200b7195fc6e261581ba38776d87d7f0b1a7d"), - Fq.e("0x09d6847f1b945ccdc00418a807f4b0af67ec5c0030c4f203581eff9d4af4347f"), - ],[ - Fq.e("0x04b62ecdc94bf94fcefdf93f06ca4f63026a47a0d4138941b8ee45b9f7177e5c"), - Fq.e("0x1f0a6bff3945f207f407ff1c813b66a28b495f55a3788c3e200c74817e86f7ce"), - ],[ - Fq.e("1"), - Fq.e("0") - ] - ] -}; - - -const challange = Buffer.from( - "bc0bde7980381fa642b2097591dd83f1"+ - "ed15b003e15c35520af32c95eb519149"+ - "2a6f3175215635cfc10e6098e2c612d0"+ - "ca84f1a9f90b5333560c8af59b9209f4", "hex"); - -function getG2sp(persinalization, challange, g1s, g1sx) { - - const h = blake2b(64); - h.update(Buffer.from([persinalization])); - h.update(challange); - h.update( utils.beInt2Buff(g1s[0],32)); - h.update( utils.beInt2Buff(g1s[1],32)); - h.update( utils.beInt2Buff(g1sx[0],32)); - h.update( utils.beInt2Buff(g1sx[1],32)); - const hash = Buffer.from(h.digest()); - - const seed = []; - for (let i=0; i<8; i++) { - seed[i] = hash.readUInt32BE(i*4); - } - - const rng = new ChaCha(seed); - - const g2_sp = bn128.G2.fromRng(rng); - - return g2_sp; - -} - -const tau_g2_sp = getG2sp(0, challange, pubKey.tau_g1_s, pubKey.tau_g1_sx); -if (bn128.F12.eq( - bn128.pairing(pubKey.tau_g1_sx,tau_g2_sp), - bn128.pairing(pubKey.tau_g1_s, pubKey.tau_g2_spx))) { - console.log("Key tau matches!!"); -} else { - console.log("ERROR Key tau does not match!!"); -} - -const alpha_g2_sp = getG2sp(1, challange, pubKey.alpha_g1_s, pubKey.alpha_g1_sx); -if (bn128.F12.eq( - bn128.pairing(pubKey.alpha_g1_sx, alpha_g2_sp), - bn128.pairing(pubKey.alpha_g1_s , pubKey.alpha_g2_spx))) { - console.log("Key alfa matches!!"); -} else { - console.log("ERROR Alfa tau does not match!!"); -} - -const beta_g2_sp = getG2sp(2, challange, pubKey.beta_g1_s, pubKey.beta_g1_sx); -if (bn128.F12.eq( - bn128.pairing(pubKey.beta_g1_sx, beta_g2_sp), - bn128.pairing(pubKey.beta_g1_s , pubKey.beta_g2_spx))) { - console.log("Key beta matches!!"); -} else { - console.log("ERROR Beta tau does not match!!"); -} -