From 8fbc57278f1740ae5d4d75a8d0f7c6f193f8d697 Mon Sep 17 00:00:00 2001 From: junderw Date: Fri, 21 Jul 2023 16:14:32 -0700 Subject: [PATCH] Add ASM.JS package creation to CI --- .github/workflows/ci.yaml | 42 +++++++++++++++++++--- .github/workflows/gh-pages.yaml | 10 +++--- .gitignore | 1 + Dockerfile | 2 +- Makefile | 59 +++++++++++++++++++++++++++++-- README.md | 9 +++++ benches/index.js | 7 +++- benches/noble_secp256k1.js | 16 --------- benches/package-lock.json | 62 +++++++++++++++++++++++++++------ benches/package.json | 2 +- package.json | 4 +-- tests/ecdsa.js | 10 +++--- tests/index.js | 17 ++++++--- tests/points.js | 20 +++++------ tests/privates.js | 8 ++--- tests/schnorr.js | 12 +++---- 16 files changed, 208 insertions(+), 73 deletions(-) delete mode 100644 benches/noble_secp256k1.js diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 01eb0d6..a14e4ae 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -61,21 +61,26 @@ jobs: - uses: actions/cache@v2 id: binaryen-cache with: - path: binaryen-version_100 - key: binaryen-version_100 + path: binaryen-version_114 + key: binaryen-version_114 - name: Install wasm-opt (binaryen) if: steps.binaryen-cache.outputs.cache-hit != 'true' run: | - wget https://github.com/WebAssembly/binaryen/releases/download/version_100/binaryen-version_100-x86_64-linux.tar.gz - tar zxvf binaryen-version_100-x86_64-linux.tar.gz binaryen-version_100/bin/wasm-opt + wget https://github.com/WebAssembly/binaryen/releases/download/version_114/binaryen-version_114-x86_64-linux.tar.gz + tar zxvf binaryen-version_114-x86_64-linux.tar.gz binaryen-version_114/bin/wasm-opt binaryen-version_114/bin/wasm2js - name: Build wasm - run: export PATH=$PATH:./binaryen-version_100/bin/ && make build-wasm + run: export PATH=$PATH:./binaryen-version_114/bin/ && make build-wasm - name: Build JS run: make build-js + - name: Build ASM.JS + run: | + export PATH=$PATH:./binaryen-version_114/bin/ && make build-asmjs + sed -i 's/DELETE ME TO RUN//g' tests/index.js + - name: Run Node.js tests and coverage run: | make test-node-raw-ci @@ -131,6 +136,24 @@ jobs: name: package path: tiny-secp256k1-* + - uses: actions/cache@v2 + id: binaryen-cache + with: + path: binaryen-version_114 + key: binaryen-version_114 + + - name: Create ASM.js package + run: | + export PATH=$PATH:./binaryen-version_114/bin/ && make build-asmjs + cd tiny-secp256k1-asmjs + npm pack + + - name: Upload ASM.js package + uses: actions/upload-artifact@v2 + with: + name: package-asmjs + path: tiny-secp256k1-asmjs/bitcoin-js-tiny-secp256k1-asmjs-* + benchmark: name: Benchmark needs: [test] @@ -159,6 +182,15 @@ jobs: name: wasm path: lib + - uses: actions/cache@v2 + id: binaryen-cache + with: + path: binaryen-version_114 + key: binaryen-version_114 + + - name: Build ASM.JS + run: export PATH=$PATH:./binaryen-version_114/bin/ && make build-asmjs + - name: Install benchmark dependencies run: cd benches && npm ci diff --git a/.github/workflows/gh-pages.yaml b/.github/workflows/gh-pages.yaml index 1a04dc2..2154e86 100644 --- a/.github/workflows/gh-pages.yaml +++ b/.github/workflows/gh-pages.yaml @@ -29,17 +29,17 @@ jobs: - uses: actions/cache@v2 id: binaryen-cache with: - path: binaryen-version_100 - key: binaryen-version_100 + path: binaryen-version_114 + key: binaryen-version_114 - name: Install wasm-opt (binaryen) if: steps.binaryen-cache.outputs.cache-hit != 'true' run: | - wget https://github.com/WebAssembly/binaryen/releases/download/version_100/binaryen-version_100-x86_64-linux.tar.gz - tar zxvf binaryen-version_100-x86_64-linux.tar.gz binaryen-version_100/bin/wasm-opt + wget https://github.com/WebAssembly/binaryen/releases/download/version_114/binaryen-version_114-x86_64-linux.tar.gz + tar zxvf binaryen-version_114-x86_64-linux.tar.gz binaryen-version_114/bin/wasm-opt binaryen-version_114/bin/wasm2js - name: Build wasm - run: export PATH=$PATH:./binaryen-version_100/bin/ && make build-wasm + run: export PATH=$PATH:./binaryen-version_114/bin/ && make build-wasm - name: Build JS run: make build-js diff --git a/.gitignore b/.gitignore index 3ce6831..c4a4bb3 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ /target /tests/browser /types +/tiny-secp256k1-asmjs diff --git a/Dockerfile b/Dockerfile index 6447986..23ee7d0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -39,7 +39,7 @@ RUN curl -sSf https://apt.llvm.org/llvm.sh | bash -s -- 12 && \ ln -s $(which clang-12) /usr/bin/clang # Install wasm-opt from binaryen -RUN git clone --depth 1 --branch version_100 https://github.com/WebAssembly/binaryen.git /binaryen && \ +RUN git clone --depth 1 --branch version_114 https://github.com/WebAssembly/binaryen.git /binaryen && \ cd /binaryen && \ cmake . && \ make -j$(nproc) && \ diff --git a/Makefile b/Makefile index b538f5f..bf46e4f 100644 --- a/Makefile +++ b/Makefile @@ -22,6 +22,59 @@ build-wasm: mkdir -p lib && cp -f target/wasm32-unknown-unknown/release/secp256k1_wasm.wasm lib/secp256k1.wasm wasm-opt -O4 --strip-debug --strip-producers --output lib/secp256k1.wasm lib/secp256k1.wasm +.PHONY: build-asmjs +build-asmjs: asmjs-build asmjs-fixes + +.PHONY: build-asmjs-dev +build-asmjs-dev: asmjs-build-dev asmjs-fixes + +.PHONY: asmjs-build +asmjs-build: + mkdir -p tiny-secp256k1-asmjs/lib + cp -R lib/ tiny-secp256k1-asmjs/ + wasm2js -O4 --disable-gc -n tiny-secp256k1-asmjs/lib/secp256k1.wasm --output tiny-secp256k1-asmjs/lib/secp256k1.asm.js + +.PHONY: asmjs-build-dev +asmjs-build-dev: + mkdir -p tiny-secp256k1-asmjs/lib + cp -R lib/ tiny-secp256k1-asmjs/ + wasm2js tiny-secp256k1-asmjs/lib/secp256k1.wasm --output tiny-secp256k1-asmjs/lib/secp256k1.asm.js + +.PHONY: asmjs-fixes +asmjs-fixes: + ### Remove the copied wasm file and replace all imports + rm tiny-secp256k1-asmjs/lib/secp256k1.wasm + for FILE in $$(grep -lR secp256k1.wasm ./tiny-secp256k1-asmjs/lib); do \ + sed -i 's/\.wasm/.asm.js/g' "$$FILE"; \ + done + + ### Copy over package.json, README, LICENSE + cp package.json tiny-secp256k1-asmjs/ + cp LICENSE tiny-secp256k1-asmjs/ + cp README.md tiny-secp256k1-asmjs/ + sed -i 's/"tiny-secp256k1"/"@bitcoin-js\/tiny-secp256k1-asmjs"/g' tiny-secp256k1-asmjs/package.json + grep -v wasm_loader tiny-secp256k1-asmjs/package.json > tiny-secp256k1-asmjs/package.json.new + mv tiny-secp256k1-asmjs/package.json.new tiny-secp256k1-asmjs/package.json + + ### 4 places where we want to replace the name tiny-secp256k1 in the README + sed -i 's/\(# \|install \|add \|v\/\|package\/\)tiny-secp256k1/\1@bitcoin-js\/tiny-secp256k1-asmjs/g' tiny-secp256k1-asmjs/README.md + + ### Copy the asm JS to cjs folder (needs modification) + cp tiny-secp256k1-asmjs/lib/secp256k1.asm.js tiny-secp256k1-asmjs/lib/cjs/secp256k1.asm.js + sed -i -e 's/import \* as \(.*\) from .\.\/\(.*\)\.js.;/const \1 = require('"'"'.\/\2.cjs'"'"');/g' tiny-secp256k1-asmjs/lib/cjs/secp256k1.asm.js + sed -i -e 's/export var /module.exports./g' tiny-secp256k1-asmjs/lib/cjs/secp256k1.asm.js + mv tiny-secp256k1-asmjs/lib/cjs/secp256k1.asm.js tiny-secp256k1-asmjs/lib/cjs/secp256k1.asm.cjs + + ### Modify imports for cjs only + for FILE in $$(grep -lR secp256k1.asm.js ./tiny-secp256k1-asmjs/lib/cjs); do \ + sed -i 's/\.asm.js/.asm.cjs/g' "$$FILE"; \ + done + + ### The NodeJS loader is not needed with ASM JS + mv tiny-secp256k1-asmjs/lib/cjs/wasm_loader.browser.cjs tiny-secp256k1-asmjs/lib/cjs/wasm_loader.cjs + mv tiny-secp256k1-asmjs/lib/wasm_loader.browser.js tiny-secp256k1-asmjs/lib/wasm_loader.js + rm tiny-secp256k1-asmjs/lib/wasm_loader.browser.d.ts + .PHONY: build-wasm-debug build-wasm-debug: RUSTFLAGS="-C link-args=-zstack-size=655360" cargo build --target wasm32-unknown-unknown @@ -48,6 +101,8 @@ clean-built: examples/react-app/dist/*.txt \ examples/react-app/dist/*.wasm \ lib \ + tiny-secp256k1-asmjs \ + *.tgz \ tests/browser eslint_files = benches/*.{js,json} examples/**/*.{js,json} src_ts/*.ts tests/*.js *.json *.cjs @@ -79,7 +134,7 @@ test-browser-build-raw: npx webpack build -c tests/browser.webpack.js .PHONY: test-browser-build -test-browser-build: build-js build-wasm-debug test-browser-build-raw +test-browser-build: build-js build-wasm-debug build-asmjs test-browser-build-raw test_browser_raw = node tests/browser-run.js | npx tap-summary @@ -105,7 +160,7 @@ test-node-raw-ci: $(test_node_raw) --no-ansi --no-progress .PHONY: test-node -test-node: build-js build-wasm-debug test-node-raw +test-node: build-js build-wasm-debug build-asmjs test-node-raw .PHONY: test-node-coverage-raw test-node-coverage-raw: diff --git a/README.md b/README.md index 16e8489..e47e6c7 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,15 @@ Previous version of `tiny-secp256k1` implement [C++ addon](https://nodejs.org/ap Current version use Rust crate (which use C library) compiled to [WebAssembly](https://developer.mozilla.org/en-US/docs/WebAssembly). With Wasm same code executed in any environment. Wasm is faster than `elliptic` but slower than node bindings ([results in PR](https://github.com/bitcoinjs/tiny-secp256k1/pull/53#issuecomment-801844450) or you can run own benchmark in `benches` directory). +Tools like webpack, environments like React Native, and a large part of the JavaScript/TypeScript ecosystem has support for WASM based libraries. However, it usually involves special config settings which might be difficult to figure out. We have examples in the examples folder that uses webpack to create a demo website. + +However, there are also **alternative implementations** of the interface of this library. + +## Alternatives + +1. [`@bitcoinjs-lib/tiny-secp256k1-asmjs`](https://www.npmjs.com/package/@bitcoin-js/tiny-secp256k1-asmjs) - This library uses wasm2js to convert this library into pure JS. It is about 10x ~ 20x slower than WASM and 3x ~ 10x slower than our old v1 JS implementation. +2. [`@bitcoinerlab/secp256k1`](https://www.npmjs.com/package/@bitcoinerlab/secp256k1) - This library uses noble/secp256k1, and therefore it uses JS native `BigInt`. If you can support `BigInt` it is much faster than ASM.JS, however, this is not maintained by this library's maintainers, so there's no guarantee that they will keep up with any interface changes in the future. Please check before using. It is about 1.5x ~ 5x slower than WASM. + ## Building For building locally you need C/C++ toolchain, Rust version >=1.50.0 and `wasm-opt` from [binaryen](https://github.com/WebAssembly/binaryen). diff --git a/benches/index.js b/benches/index.js index bd586af..4c6e8eb 100644 --- a/benches/index.js +++ b/benches/index.js @@ -1,8 +1,9 @@ import tiny_secp256k1_prev_js from "tiny-secp256k1/js.js"; import tiny_secp256k1_prev_native from "tiny-secp256k1/native.js"; import * as tiny_secp256k1 from "../lib/index.js"; +import * as tiny_secp256k1_asmjs from "../tiny-secp256k1-asmjs/lib/index.js"; import * as cryptocoinjs_secp256k1 from "./cryptocoinjs_secp256k1.js"; -import noble_secp256k1 from "./noble_secp256k1.js"; +import noble_secp256k1 from "@bitcoinerlab/secp256k1"; import { fecdsa, fpoints, @@ -27,6 +28,10 @@ const modules = [ name: "tiny-secp256k1 (WASM)", secp256k1: tiny_secp256k1, }, + { + name: "tiny-secp256k1 (ASM.JS)", + secp256k1: tiny_secp256k1_asmjs, + }, { name: "tiny-secp256k1@1.1.6 (C++ addon, NAN/V8)", secp256k1: tiny_secp256k1_prev_native, diff --git a/benches/noble_secp256k1.js b/benches/noble_secp256k1.js deleted file mode 100644 index 5b2ffd1..0000000 --- a/benches/noble_secp256k1.js +++ /dev/null @@ -1,16 +0,0 @@ -import * as secp256k1 from "noble-secp256k1"; - -export default { - // isPoint - // isPointCompressed - // isPrivate - // pointAdd - // pointAddScalar - // pointCompress - pointFromScalar: secp256k1.getPublicKey, - // pointMultiply - // privateAdd - // privateSub - sign: secp256k1.sign, - // verify: (h, Q, signature) => secp256k1.verify(signature, h, Q), -}; diff --git a/benches/package-lock.json b/benches/package-lock.json index 6c7ff29..ffce72a 100644 --- a/benches/package-lock.json +++ b/benches/package-lock.json @@ -9,11 +9,42 @@ "version": "0.0.0", "license": "MIT", "dependencies": { - "noble-secp256k1": "=1.1.2", + "@bitcoinerlab/secp256k1": "=1.0.5", "secp256k1": "=4.0.2", "tiny-secp256k1": "=1.1.6" } }, + "node_modules/@bitcoinerlab/secp256k1": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/@bitcoinerlab/secp256k1/-/secp256k1-1.0.5.tgz", + "integrity": "sha512-8gT+ukTCFN2rTxn4hD9Jq3k+UJwcprgYjfK/SQUSLgznXoIgsBnlPuARMkyyuEjycQK9VvnPiejKdszVTflh+w==", + "dependencies": { + "@noble/hashes": "^1.1.5", + "@noble/secp256k1": "^1.7.1" + } + }, + "node_modules/@noble/hashes": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.1.tgz", + "integrity": "sha512-EbqwksQwz9xDRGfDST86whPBgM65E0OH/pCgqW0GBVzO22bNE+NuIbeTb714+IfSjU3aRk47EUvXIb5bTsenKA==", + "engines": { + "node": ">= 16" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/@noble/secp256k1": { + "version": "1.7.1", + "resolved": "https://registry.npmjs.org/@noble/secp256k1/-/secp256k1-1.7.1.tgz", + "integrity": "sha512-hOUk6AyBFmqVrv7k5WAw/LpszxVbj9gGN4JRkIX52fdFAj1UA61KXmZDvqVEm+pOyec3+fIeZB02LYa/pWOArw==", + "funding": [ + { + "type": "individual", + "url": "https://paulmillr.com/funding/" + } + ] + }, "node_modules/bindings": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz", @@ -147,11 +178,6 @@ "resolved": "https://registry.npmjs.org/nan/-/nan-2.15.0.tgz", "integrity": "sha512-8ZtvEnA2c5aYCZYd1cvgdnU6cqwixRoYg70xPLWUws5ORTa/lnw+u4amixRS/Ac5U5mQVgp9pnlSUnbNWFaWZQ==" }, - "node_modules/noble-secp256k1": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/noble-secp256k1/-/noble-secp256k1-1.1.2.tgz", - "integrity": "sha512-+fW9Vt7ev0aT+esL8tVsH79GiDB0b8Nzk9cgwPKXoG1rKJjaA7Phg2VzxV541qdu/V1bG/y8xA0nJBu1QvBmTg==" - }, "node_modules/node-addon-api": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-2.0.2.tgz", @@ -265,6 +291,25 @@ } }, "dependencies": { + "@bitcoinerlab/secp256k1": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/@bitcoinerlab/secp256k1/-/secp256k1-1.0.5.tgz", + "integrity": "sha512-8gT+ukTCFN2rTxn4hD9Jq3k+UJwcprgYjfK/SQUSLgznXoIgsBnlPuARMkyyuEjycQK9VvnPiejKdszVTflh+w==", + "requires": { + "@noble/hashes": "^1.1.5", + "@noble/secp256k1": "^1.7.1" + } + }, + "@noble/hashes": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.1.tgz", + "integrity": "sha512-EbqwksQwz9xDRGfDST86whPBgM65E0OH/pCgqW0GBVzO22bNE+NuIbeTb714+IfSjU3aRk47EUvXIb5bTsenKA==" + }, + "@noble/secp256k1": { + "version": "1.7.1", + "resolved": "https://registry.npmjs.org/@noble/secp256k1/-/secp256k1-1.7.1.tgz", + "integrity": "sha512-hOUk6AyBFmqVrv7k5WAw/LpszxVbj9gGN4JRkIX52fdFAj1UA61KXmZDvqVEm+pOyec3+fIeZB02LYa/pWOArw==" + }, "bindings": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz", @@ -395,11 +440,6 @@ "resolved": "https://registry.npmjs.org/nan/-/nan-2.15.0.tgz", "integrity": "sha512-8ZtvEnA2c5aYCZYd1cvgdnU6cqwixRoYg70xPLWUws5ORTa/lnw+u4amixRS/Ac5U5mQVgp9pnlSUnbNWFaWZQ==" }, - "noble-secp256k1": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/noble-secp256k1/-/noble-secp256k1-1.1.2.tgz", - "integrity": "sha512-+fW9Vt7ev0aT+esL8tVsH79GiDB0b8Nzk9cgwPKXoG1rKJjaA7Phg2VzxV541qdu/V1bG/y8xA0nJBu1QvBmTg==" - }, "node-addon-api": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-2.0.2.tgz", diff --git a/benches/package.json b/benches/package.json index 0c4c9fd..5e08738 100644 --- a/benches/package.json +++ b/benches/package.json @@ -9,7 +9,7 @@ "start": "node --experimental-json-modules index.js" }, "dependencies": { - "noble-secp256k1": "=1.1.2", + "@bitcoinerlab/secp256k1": "=1.0.5", "secp256k1": "=4.0.2", "tiny-secp256k1": "=1.1.6" } diff --git a/package.json b/package.json index 235f815..e99ea6f 100644 --- a/package.json +++ b/package.json @@ -25,8 +25,8 @@ } }, "browser": { - "./lib/rand.js": "./lib/rand.browser.js", - "./lib/wasm_loader.js": "./lib/wasm_loader.browser.js" + "./lib/wasm_loader.js": "./lib/wasm_loader.browser.js", + "./lib/rand.js": "./lib/rand.browser.js" }, "types": "./lib/index.d.ts", "files": [ diff --git a/tests/ecdsa.js b/tests/ecdsa.js index d5ce1bb..5b5201b 100644 --- a/tests/ecdsa.js +++ b/tests/ecdsa.js @@ -29,8 +29,8 @@ function corrupt(x) { return x; } -export default function (secp256k1) { - test("sign", (t) => { +export default function (secp256k1, type) { + test(`sign (${type})`, (t) => { for (const f of fecdsa.valid) { const d = fromHex(f.d); const m = fromHex(f.m); @@ -108,7 +108,7 @@ export default function (secp256k1) { t.end(); }); - test("signRecoverable", (t) => { + test(`signRecoverable (${type})`, (t) => { for (const f of fecdsa.valid) { const d = fromHex(f.d); const m = fromHex(f.m); @@ -224,7 +224,7 @@ export default function (secp256k1) { t.end(); }); - test("verify", (t) => { + test(`verify (${type})`, (t) => { for (const f of fecdsa.valid) { const d = fromHex(f.d); const Q = secp256k1.pointFromScalar(d, true); @@ -287,7 +287,7 @@ export default function (secp256k1) { t.end(); }); - test("recover", (t) => { + test(`recover (${type})`, (t) => { for (const f of fecdsa.valid) { const d = fromHex(f.d); const Q = secp256k1.pointFromScalar(d, true); diff --git a/tests/index.js b/tests/index.js index 7ba9034..7e09dfe 100644 --- a/tests/index.js +++ b/tests/index.js @@ -1,5 +1,6 @@ import test from "tape"; import * as secp256k1 from "../lib/index.js"; +import * as secp256k1Asm from "../tiny-secp256k1-asmjs/lib/index.js"; import test_ecdsa from "./ecdsa.js"; import test_points from "./points.js"; @@ -13,7 +14,15 @@ test.onFinish(() => { } }); -test_schnorr(secp256k1); -test_ecdsa(secp256k1); -test_points(secp256k1); -test_privates(secp256k1); +test_schnorr(secp256k1, "WASM"); +test_ecdsa(secp256k1, "WASM"); +test_points(secp256k1, "WASM"); +test_privates(secp256k1, "WASM"); + +// eslint-disable-next-line no-constant-condition +if ("DELETE ME TO RUN" === "") { + test_schnorr(secp256k1Asm, "ASM.JS"); + test_ecdsa(secp256k1Asm, "ASM.JS"); + test_points(secp256k1Asm, "ASM.JS"); + test_privates(secp256k1Asm, "ASM.JS"); +} diff --git a/tests/points.js b/tests/points.js index 71bed40..c369700 100644 --- a/tests/points.js +++ b/tests/points.js @@ -2,8 +2,8 @@ import test from "tape"; import { fromHex } from "./util.js"; import fpoints from "./fixtures/points.json" assert { type: "json" }; -export default function (secp256k1) { - test("isPoint", (t) => { +export default function (secp256k1, type) { + test(`isPoint (${type})`, (t) => { for (const f of fpoints.valid.isPoint) { const p = fromHex(f.P); t.equal( @@ -16,7 +16,7 @@ export default function (secp256k1) { t.end(); }); - test("isPointCompressed", (t) => { + test(`isPointCompressed (${type})`, (t) => { for (const f of fpoints.valid.isPoint) { if (!f.expected) continue; const p = fromHex(f.P); @@ -31,7 +31,7 @@ export default function (secp256k1) { t.end(); }); - test("isXOnlyPoint", (t) => { + test(`isXOnlyPoint (${type})`, (t) => { for (const f of fpoints.valid.isPoint) { if (!f.expected) continue; const p = fromHex(f.P); @@ -47,7 +47,7 @@ export default function (secp256k1) { t.end(); }); - test("pointAdd", (t) => { + test(`pointAdd (${type})`, (t) => { for (const f of fpoints.valid.pointAdd) { const p = fromHex(f.P); const q = fromHex(f.Q); @@ -83,7 +83,7 @@ export default function (secp256k1) { t.end(); }); - test("pointAddScalar", (t) => { + test(`pointAddScalar (${type})`, (t) => { for (const f of fpoints.valid.pointAddScalar) { const p = fromHex(f.P); const d = fromHex(f.d); @@ -119,7 +119,7 @@ export default function (secp256k1) { t.end(); }); - test("pointCompress", (t) => { + test(`pointCompress (${type})`, (t) => { for (const f of fpoints.valid.pointCompress) { const p = fromHex(f.P); const expected = fromHex(f.expected); @@ -144,7 +144,7 @@ export default function (secp256k1) { t.end(); }); - test("pointFromScalar", (t) => { + test(`pointFromScalar (${type})`, (t) => { for (const f of fpoints.valid.pointFromScalar) { const d = fromHex(f.d); const expected = fromHex(f.expected); @@ -178,7 +178,7 @@ export default function (secp256k1) { t.end(); }); - test("pointMultiply", (t) => { + test(`pointMultiply (${type})`, (t) => { for (const f of fpoints.valid.pointMultiply) { const p = fromHex(f.P); const d = fromHex(f.d); @@ -214,7 +214,7 @@ export default function (secp256k1) { t.end(); }); - test("pointNegate", (t) => { + test(`pointNegate (${type})`, (t) => { for (const f of fpoints.valid.pointNegate) { const d = fromHex(f.d); const expected = fromHex(f.expected); diff --git a/tests/privates.js b/tests/privates.js index 9adf237..40f1738 100644 --- a/tests/privates.js +++ b/tests/privates.js @@ -2,8 +2,8 @@ import test from "tape"; import { fromHex } from "./util.js"; import fprivates from "./fixtures/privates.json" assert { type: "json" }; -export default function (secp256k1) { - test("isPrivate", (t) => { +export default function (secp256k1, type) { + test(`isPrivate (${type})`, (t) => { for (const f of fprivates.valid.isPrivate) { const d = fromHex(f.d); @@ -17,7 +17,7 @@ export default function (secp256k1) { t.end(); }); - test("privateAdd", (t) => { + test(`privateAdd (${type})`, (t) => { for (const f of fprivates.valid.privateAdd) { const d = fromHex(f.d); const tweak = fromHex(f.tweak); @@ -46,7 +46,7 @@ export default function (secp256k1) { t.end(); }); - test("privateSub", (t) => { + test(`privateSub (${type})`, (t) => { for (const f of fprivates.valid.privateSub) { const d = fromHex(f.d); const tweak = fromHex(f.tweak); diff --git a/tests/schnorr.js b/tests/schnorr.js index 948dbc6..f7af5eb 100644 --- a/tests/schnorr.js +++ b/tests/schnorr.js @@ -22,12 +22,12 @@ export function parseTweakAddVector(f) { }; } -export default function (secp256k1) { +export default function (secp256k1, type) { const rand = () => Math.floor(Math.random() * 254) + 1; // [1..254]; const randPubKey = () => secp256k1.xOnlyPointFromScalar(new Uint8Array(32).fill(rand())); - test("sign schnorr", (t) => { + test(`sign schnorr (${type})`, (t) => { for (const fHex of fschnorr.bip340testvectors) { if (fHex.d) { const f = parseBip340Vector(fHex); @@ -42,7 +42,7 @@ export default function (secp256k1) { t.end(); }); - test("verify schnorr", (t) => { + test(`verify schnorr (${type})`, (t) => { for (const fHex of fschnorr.bip340testvectors) { const f = parseBip340Vector(fHex); if (f.exception) { @@ -62,7 +62,7 @@ export default function (secp256k1) { t.end(); }); - test("scalar to xOnlyPubkey", (t) => { + test(`scalar to xOnlyPubkey (${type})`, (t) => { for (const fHex of fschnorr.bip340testvectors) { if (fHex.d) { const f = parseBip340Vector(fHex); @@ -77,7 +77,7 @@ export default function (secp256k1) { t.end(); }); - test("pubkey to xOnlyPubkey", (t) => { + test(`pubkey to xOnlyPubkey (${type})`, (t) => { for (const fHex of fschnorr.bip340testvectors) { if (fHex.d) { const f = parseBip340Vector(fHex); @@ -99,7 +99,7 @@ export default function (secp256k1) { t.end(); }); - test("xonly pubkey tweak add schnorr", (t) => { + test(`xonly pubkey tweak add schnorr (${type})`, (t) => { for (const fHex of fschnorr.tweakaddvectors) { const f = parseTweakAddVector(fHex); const res = secp256k1.xOnlyPointAddTweak(f.pubkey, f.tweak);