From 17d82c7fe38239d3ba0451202895837885f80e1c Mon Sep 17 00:00:00 2001 From: junderw Date: Thu, 29 Jun 2023 00:02:03 -0700 Subject: [PATCH 1/2] Bump secp256k1-sys --- .eslintrc.cjs | 10 +++ .github/workflows/ci.yaml | 2 +- .github/workflows/gh-pages.yaml | 2 +- Cargo.lock | 16 ++-- Cargo.toml | 14 ++-- benches/fixtures.js | 8 +- package-lock.json | 135 +++++++++++++++++++++++++++++--- package.json | 2 + rust-toolchain | 2 +- src/lib.rs | 102 ++++++++++-------------- tests/ecdsa.js | 2 +- tests/fixtures/ecdsa.json | 24 ++++-- tests/points.js | 2 +- tests/privates.js | 2 +- tests/schnorr.js | 2 +- 15 files changed, 223 insertions(+), 102 deletions(-) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index aeacbe1..26cb3f6 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -20,5 +20,15 @@ module.exports = { "@typescript-eslint/explicit-module-boundary-types": ["error"], }, }, + { + files: ["tests/*.js", "benches/fixtures.js"], + parser: "@babel/eslint-parser", + parserOptions: { + requireConfigFile: false, + babelOptions: { + plugins: ["@babel/plugin-syntax-import-assertions"], + }, + }, + }, ], }; diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index d6527c4..01eb0d6 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -7,7 +7,7 @@ on: pull_request: env: - NODE_VERSION: 14.0.0 + NODE_VERSION: 18.16.1 jobs: lint: diff --git a/.github/workflows/gh-pages.yaml b/.github/workflows/gh-pages.yaml index 37e9b61..1a04dc2 100644 --- a/.github/workflows/gh-pages.yaml +++ b/.github/workflows/gh-pages.yaml @@ -6,7 +6,7 @@ on: - master env: - NODE_VERSION: 14.0.0 + NODE_VERSION: 18.16.1 jobs: publish-react-app: diff --git a/Cargo.lock b/Cargo.lock index b642037..a465944 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,25 +1,25 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "cc" version = "1.0.71" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79c2681d6594606957bbb8631c4b90a7fcaaa72cdb714743a437b156d6a7eedd" [[package]] name = "secp256k1-sys" -version = "0.4.1" -source = "git+https://github.com/rust-bitcoin/rust-secp256k1?rev=455ee57ba4051bb2cfea5f5f675378170fb42c7f#455ee57ba4051bb2cfea5f5f675378170fb42c7f" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70a129b9e9efbfb223753b9163c4ab3b13cff7fd9c7f010fbac25ab4099fa07e" dependencies = [ - "cc 1.0.71 (registry+https://github.com/rust-lang/crates.io-index)", + "cc", ] [[package]] name = "secp256k1-wasm" version = "0.0.0" dependencies = [ - "secp256k1-sys 0.4.1 (git+https://github.com/rust-bitcoin/rust-secp256k1?rev=455ee57ba4051bb2cfea5f5f675378170fb42c7f)", + "secp256k1-sys", ] - -[metadata] -"checksum cc 1.0.71 (registry+https://github.com/rust-lang/crates.io-index)" = "79c2681d6594606957bbb8631c4b90a7fcaaa72cdb714743a437b156d6a7eedd" -"checksum secp256k1-sys 0.4.1 (git+https://github.com/rust-bitcoin/rust-secp256k1?rev=455ee57ba4051bb2cfea5f5f675378170fb42c7f)" = "" diff --git a/Cargo.toml b/Cargo.toml index b2ff6fd..7b8d691 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,19 +2,21 @@ name = "secp256k1-wasm" version = "0.0.0" authors = ["Kirill Fomichev "] -edition = "2018" +edition = "2021" description = "A Rust library for building tiny-secp256k1 WASM." -rust-version = "1.50" license = "MIT" publish = false [lib] crate-type = ["cdylib"] -[dependencies] -# `[patch.crates-io]` is not working :( -# This commit is where secp256k1-sys version changed to 0.4.1 -secp256k1-sys = { version = "0.4.1", default-features = false, features=["recovery"], git = "https://github.com/rust-bitcoin/rust-secp256k1", rev = "455ee57ba4051bb2cfea5f5f675378170fb42c7f" } +[dependencies.secp256k1-sys] +version = "=0.8.1" +default-features = false +features=[ + "recovery", + "lowmemory" +] [profile.release] lto = true diff --git a/benches/fixtures.js b/benches/fixtures.js index b944a45..d20c85c 100644 --- a/benches/fixtures.js +++ b/benches/fixtures.js @@ -1,9 +1,9 @@ import * as crypto from "crypto"; import * as tiny_secp256k1 from "../lib/index.js"; -import _fecdsa from "../tests/fixtures/ecdsa.json"; -import _fpoints from "../tests/fixtures/points.json"; -import _fprivates from "../tests/fixtures/privates.json"; -import _fschnorr from "../tests/fixtures/schnorr.json"; +import _fecdsa from "../tests/fixtures/ecdsa.json" assert { type: "json" }; +import _fpoints from "../tests/fixtures/points.json" assert { type: "json" }; +import _fprivates from "../tests/fixtures/privates.json" assert { type: "json" }; +import _fschnorr from "../tests/fixtures/schnorr.json" assert { type: "json" }; import { parseBip340Vector } from "../tests/schnorr.js"; const randPubKey = () => diff --git a/package-lock.json b/package-lock.json index baf62b5..f225784 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,8 @@ "uint8array-tools": "0.0.7" }, "devDependencies": { + "@babel/eslint-parser": "^7.22.5", + "@babel/plugin-syntax-import-assertions": "^7.22.5", "@types/node": "^14.14.35", "@typescript-eslint/eslint-plugin": "^4.18.0", "@typescript-eslint/parser": "^4.18.0", @@ -105,6 +107,33 @@ "semver": "bin/semver.js" } }, + "node_modules/@babel/eslint-parser": { + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/eslint-parser/-/eslint-parser-7.22.5.tgz", + "integrity": "sha512-C69RWYNYtrgIRE5CmTd77ZiLDXqgBipahJc/jHP3sLcAGj6AJzxNIuKNpVnICqbyK7X3pFUfEvL++rvtbQpZkQ==", + "dev": true, + "dependencies": { + "@nicolo-ribaudo/eslint-scope-5-internals": "5.1.1-v1", + "eslint-visitor-keys": "^2.1.0", + "semver": "^6.3.0" + }, + "engines": { + "node": "^10.13.0 || ^12.13.0 || >=14.0.0" + }, + "peerDependencies": { + "@babel/core": ">=7.11.0", + "eslint": "^7.5.0 || ^8.0.0" + } + }, + "node_modules/@babel/eslint-parser/node_modules/semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "dev": true, + "bin": { + "semver": "bin/semver.js" + } + }, "node_modules/@babel/generator": { "version": "7.15.8", "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.15.8.tgz", @@ -239,6 +268,15 @@ "node": ">=6.9.0" } }, + "node_modules/@babel/helper-plugin-utils": { + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.22.5.tgz", + "integrity": "sha512-uLls06UVKgFG9QD4OeFYLEGteMIAa5kpTPcFL28yuCIIzsf6ZyKZMllKVOCZFhiZ5ptnwX4mtKdWCBE/uT4amg==", + "dev": true, + "engines": { + "node": ">=6.9.0" + } + }, "node_modules/@babel/helper-replace-supers": { "version": "7.15.4", "resolved": "https://registry.npmjs.org/@babel/helper-replace-supers/-/helper-replace-supers-7.15.4.tgz", @@ -407,6 +445,21 @@ "node": ">=6.0.0" } }, + "node_modules/@babel/plugin-syntax-import-assertions": { + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-import-assertions/-/plugin-syntax-import-assertions-7.22.5.tgz", + "integrity": "sha512-rdV97N7KqsRzeNGoWUOK6yUsWarLjE5Su/Snk9IYPU9CwkWHs4t+rTGOvffTR8XGkJMTAdLfO0xVnXm8wugIJg==", + "dev": true, + "dependencies": { + "@babel/helper-plugin-utils": "^7.22.5" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, "node_modules/@babel/template": { "version": "7.15.4", "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.15.4.tgz", @@ -668,6 +721,15 @@ "@jridgewell/sourcemap-codec": "^1.4.10" } }, + "node_modules/@nicolo-ribaudo/eslint-scope-5-internals": { + "version": "5.1.1-v1", + "resolved": "https://registry.npmjs.org/@nicolo-ribaudo/eslint-scope-5-internals/-/eslint-scope-5-internals-5.1.1-v1.tgz", + "integrity": "sha512-54/JRvkLIzzDWshCWfuhadfrfZVPiElY8Fcgmg1HroEly/EDSszzhBAsarCux+D/kOslTRquNzuyGSmUSTTHGg==", + "dev": true, + "dependencies": { + "eslint-scope": "5.1.1" + } + }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -1559,14 +1621,24 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001265", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001265.tgz", - "integrity": "sha512-YzBnspggWV5hep1m9Z6sZVLOt7vrju8xWooFAgN6BA5qvy98qPAPb7vNUzypFaoh2pb3vlfzbDO8tB57UPGbtw==", + "version": "1.0.30001509", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001509.tgz", + "integrity": "sha512-2uDDk+TRiTX5hMcUYT/7CSyzMZxjfGu0vAUjS2g0LSD8UoXOv0LtpH4LxGMemsiPq6LCVIUjNwVM0erkOkGCDA==", "dev": true, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/browserslist" - } + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/browserslist" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/caniuse-lite" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ] }, "node_modules/chalk": { "version": "4.1.2", @@ -6800,6 +6872,25 @@ } } }, + "@babel/eslint-parser": { + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/eslint-parser/-/eslint-parser-7.22.5.tgz", + "integrity": "sha512-C69RWYNYtrgIRE5CmTd77ZiLDXqgBipahJc/jHP3sLcAGj6AJzxNIuKNpVnICqbyK7X3pFUfEvL++rvtbQpZkQ==", + "dev": true, + "requires": { + "@nicolo-ribaudo/eslint-scope-5-internals": "5.1.1-v1", + "eslint-visitor-keys": "^2.1.0", + "semver": "^6.3.0" + }, + "dependencies": { + "semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "dev": true + } + } + }, "@babel/generator": { "version": "7.15.8", "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.15.8.tgz", @@ -6903,6 +6994,12 @@ "@babel/types": "^7.15.4" } }, + "@babel/helper-plugin-utils": { + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.22.5.tgz", + "integrity": "sha512-uLls06UVKgFG9QD4OeFYLEGteMIAa5kpTPcFL28yuCIIzsf6ZyKZMllKVOCZFhiZ5ptnwX4mtKdWCBE/uT4amg==", + "dev": true + }, "@babel/helper-replace-supers": { "version": "7.15.4", "resolved": "https://registry.npmjs.org/@babel/helper-replace-supers/-/helper-replace-supers-7.15.4.tgz", @@ -7031,6 +7128,15 @@ "integrity": "sha512-BRYa3wcQnjS/nqI8Ac94pYYpJfojHVvVXJ97+IDCImX4Jc8W8Xv1+47enbruk+q1etOpsQNwnfFcNGw+gtPGxA==", "dev": true }, + "@babel/plugin-syntax-import-assertions": { + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-import-assertions/-/plugin-syntax-import-assertions-7.22.5.tgz", + "integrity": "sha512-rdV97N7KqsRzeNGoWUOK6yUsWarLjE5Su/Snk9IYPU9CwkWHs4t+rTGOvffTR8XGkJMTAdLfO0xVnXm8wugIJg==", + "dev": true, + "requires": { + "@babel/helper-plugin-utils": "^7.22.5" + } + }, "@babel/template": { "version": "7.15.4", "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.15.4.tgz", @@ -7246,6 +7352,15 @@ "@jridgewell/sourcemap-codec": "^1.4.10" } }, + "@nicolo-ribaudo/eslint-scope-5-internals": { + "version": "5.1.1-v1", + "resolved": "https://registry.npmjs.org/@nicolo-ribaudo/eslint-scope-5-internals/-/eslint-scope-5-internals-5.1.1-v1.tgz", + "integrity": "sha512-54/JRvkLIzzDWshCWfuhadfrfZVPiElY8Fcgmg1HroEly/EDSszzhBAsarCux+D/kOslTRquNzuyGSmUSTTHGg==", + "dev": true, + "requires": { + "eslint-scope": "5.1.1" + } + }, "@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -7912,9 +8027,9 @@ "dev": true }, "caniuse-lite": { - "version": "1.0.30001265", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001265.tgz", - "integrity": "sha512-YzBnspggWV5hep1m9Z6sZVLOt7vrju8xWooFAgN6BA5qvy98qPAPb7vNUzypFaoh2pb3vlfzbDO8tB57UPGbtw==", + "version": "1.0.30001509", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001509.tgz", + "integrity": "sha512-2uDDk+TRiTX5hMcUYT/7CSyzMZxjfGu0vAUjS2g0LSD8UoXOv0LtpH4LxGMemsiPq6LCVIUjNwVM0erkOkGCDA==", "dev": true }, "chalk": { diff --git a/package.json b/package.json index 028e5b5..1e53c85 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,8 @@ "uint8array-tools": "0.0.7" }, "devDependencies": { + "@babel/eslint-parser": "^7.22.5", + "@babel/plugin-syntax-import-assertions": "^7.22.5", "@types/node": "^14.14.35", "@typescript-eslint/eslint-plugin": "^4.18.0", "@typescript-eslint/parser": "^4.18.0", diff --git a/rust-toolchain b/rust-toolchain index f269cd1..9006c0b 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -1.58.0 \ No newline at end of file +1.70.0 \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 5eb9ab6..63382f9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,6 +11,8 @@ fn panic(_info: &core::panic::PanicInfo) -> ! { core::arch::wasm32::unreachable() } +use core::ptr::NonNull; + use secp256k1_sys::{ secp256k1_context_no_precomp, secp256k1_context_preallocated_create, secp256k1_context_preallocated_size, secp256k1_context_randomize, secp256k1_ec_pubkey_combine, @@ -19,8 +21,8 @@ use secp256k1_sys::{ secp256k1_ec_seckey_tweak_add, secp256k1_ecdsa_sign, secp256k1_ecdsa_signature_normalize, secp256k1_ecdsa_signature_parse_compact, secp256k1_ecdsa_signature_serialize_compact, secp256k1_ecdsa_verify, secp256k1_keypair_create, secp256k1_keypair_xonly_pub, - secp256k1_nonce_function_bip340, secp256k1_nonce_function_rfc6979, secp256k1_schnorrsig_sign, - secp256k1_schnorrsig_verify, secp256k1_xonly_pubkey_from_pubkey, secp256k1_xonly_pubkey_parse, + secp256k1_nonce_function_rfc6979, secp256k1_schnorrsig_sign, secp256k1_schnorrsig_verify, + secp256k1_xonly_pubkey_from_pubkey, secp256k1_xonly_pubkey_parse, secp256k1_xonly_pubkey_serialize, secp256k1_xonly_pubkey_tweak_add, secp256k1_xonly_pubkey_tweak_add_check, types::c_void, Context, KeyPair, PublicKey, Signature, XOnlyPublicKey, SECP256K1_SER_COMPRESSED, SECP256K1_SER_UNCOMPRESSED, SECP256K1_START_SIGN, @@ -48,7 +50,7 @@ extern "C" { type InvalidInputResult = Result; #[allow(clippy::large_stack_arrays)] -static CONTEXT_BUFFER: [u8; 1_114_320] = [0; 1_114_320]; +static CONTEXT_BUFFER: [u8; 192] = [0; 192]; static mut CONTEXT_SEED: [u8; 32] = [0; 32]; const PRIVATE_KEY_SIZE: usize = 32; @@ -122,7 +124,7 @@ fn get_context() -> *const Context { secp256k1_context_preallocated_size(SECP256K1_START_SIGN | SECP256K1_START_VERIFY); assert_eq!(size, CONTEXT_BUFFER.len()); let ctx = secp256k1_context_preallocated_create( - CONTEXT_BUFFER.as_ptr() as *mut c_void, + NonNull::new(CONTEXT_BUFFER.as_ptr() as *mut c_void).expect("Not null"), SECP256K1_START_SIGN | SECP256K1_START_VERIFY, ); initialize_context_seed(); @@ -130,7 +132,7 @@ fn get_context() -> *const Context { CONTEXT_SEED[0] = 1; CONTEXT_SEED[1..].fill(0); assert_eq!(retcode, 1); - CONTEXT = ctx; + CONTEXT = ctx.as_ptr(); } CONTEXT } @@ -193,7 +195,7 @@ unsafe fn pubkey_serialize(pk: &PublicKey, output: *mut u8, mut outputlen: usize secp256k1_context_no_precomp, output, &mut outputlen, - pk.as_ptr().cast::(), + pk, flags, ), 1 @@ -202,11 +204,7 @@ unsafe fn pubkey_serialize(pk: &PublicKey, output: *mut u8, mut outputlen: usize unsafe fn x_only_pubkey_serialize(pk: &XOnlyPublicKey, output: *mut u8) { assert_eq!( - secp256k1_xonly_pubkey_serialize( - secp256k1_context_no_precomp, - output, - pk.as_ptr().cast::(), - ), + secp256k1_xonly_pubkey_serialize(secp256k1_context_no_precomp, output, pk), 1 ); } @@ -239,7 +237,7 @@ pub extern "C" fn point_add(inputlen: usize, inputlen2: usize, outputlen: usize) let pk1 = jstry!(pubkey_parse(PUBLIC_KEY_INPUT.as_ptr(), inputlen), 0); let pk2 = jstry!(pubkey_parse(PUBLIC_KEY_INPUT2.as_ptr(), inputlen2), 0); let mut pk = PublicKey::new(); - let ptrs = [pk1.as_ptr(), pk2.as_ptr()]; + let ptrs = [&pk1, &pk2]; if secp256k1_ec_pubkey_combine( secp256k1_context_no_precomp, &mut pk, @@ -260,12 +258,7 @@ pub extern "C" fn point_add(inputlen: usize, inputlen2: usize, outputlen: usize) pub extern "C" fn point_add_scalar(inputlen: usize, outputlen: usize) -> i32 { unsafe { let mut pk = jstry!(pubkey_parse(PUBLIC_KEY_INPUT.as_ptr(), inputlen), 0); - if secp256k1_ec_pubkey_tweak_add( - get_context(), - pk.as_mut_ptr().cast::(), - TWEAK_INPUT.as_ptr(), - ) == 1 - { + if secp256k1_ec_pubkey_tweak_add(get_context(), &mut pk, TWEAK_INPUT.as_ptr()) == 1 { pubkey_serialize(&pk, PUBLIC_KEY_INPUT.as_mut_ptr(), outputlen); 1 } else { @@ -383,16 +376,13 @@ pub extern "C" fn point_multiply(inputlen: usize, outputlen: usize) -> i32 { #[export_name = "privateAdd"] pub extern "C" fn private_add() -> i32 { unsafe { - if secp256k1_ec_seckey_tweak_add( - secp256k1_context_no_precomp, - PRIVATE_INPUT.as_mut_ptr(), - TWEAK_INPUT.as_ptr(), - ) == 1 - { - 1 - } else { - 0 - } + i32::from( + secp256k1_ec_seckey_tweak_add( + secp256k1_context_no_precomp, + PRIVATE_INPUT.as_mut_ptr(), + TWEAK_INPUT.as_ptr(), + ) == 1, + ) } } @@ -405,16 +395,13 @@ pub extern "C" fn private_sub() -> i32 { secp256k1_ec_seckey_negate(secp256k1_context_no_precomp, TWEAK_INPUT.as_mut_ptr()), 1 ); - if secp256k1_ec_seckey_tweak_add( - secp256k1_context_no_precomp, - PRIVATE_INPUT.as_mut_ptr(), - TWEAK_INPUT.as_ptr(), - ) == 1 - { - 1 - } else { - 0 - } + i32::from( + secp256k1_ec_seckey_tweak_add( + secp256k1_context_no_precomp, + PRIVATE_INPUT.as_mut_ptr(), + TWEAK_INPUT.as_ptr(), + ) == 1, + ) } } @@ -439,8 +426,7 @@ pub extern "C" fn sign(extra_data: i32) { core::ptr::null() } else { EXTRA_DATA_INPUT.as_ptr() - } - .cast::(); + }; assert_eq!( secp256k1_ecdsa_sign( @@ -449,7 +435,7 @@ pub extern "C" fn sign(extra_data: i32) { HASH_INPUT.as_ptr(), PRIVATE_INPUT.as_ptr(), secp256k1_nonce_function_rfc6979, - noncedata + noncedata.cast() ), 1 ); @@ -475,8 +461,7 @@ pub extern "C" fn sign_recoverable(extra_data: i32) -> i32 { core::ptr::null() } else { EXTRA_DATA_INPUT.as_ptr() - } - .cast::(); + }; assert_eq!( secp256k1_ecdsa_sign_recoverable( @@ -485,7 +470,7 @@ pub extern "C" fn sign_recoverable(extra_data: i32) -> i32 { HASH_INPUT.as_ptr(), PRIVATE_INPUT.as_ptr(), secp256k1_nonce_function_rfc6979, - noncedata + noncedata.cast() ), 1 ); @@ -525,8 +510,7 @@ pub extern "C" fn sign_schnorr(extra_data: i32) { SIGNATURE_INPUT.as_mut_ptr(), HASH_INPUT.as_ptr(), &keypair, - secp256k1_nonce_function_bip340, - noncedata + noncedata.cast() ), 1 ); @@ -557,11 +541,7 @@ pub extern "C" fn verify(inputlen: usize, strict: i32) -> i32 { ); } - if secp256k1_ecdsa_verify(get_context(), &signature, HASH_INPUT.as_ptr(), &pk) == 1 { - 1 - } else { - 0 - } + i32::from(secp256k1_ecdsa_verify(get_context(), &signature, HASH_INPUT.as_ptr(), &pk) == 1) } } @@ -595,16 +575,14 @@ pub extern "C" fn recover(outputlen: usize, recid: i32) -> i32 { pub extern "C" fn verify_schnorr() -> i32 { unsafe { let pk = jstry!(x_only_pubkey_parse(X_ONLY_PUBLIC_KEY_INPUT.as_ptr()), 0); - if secp256k1_schnorrsig_verify( - get_context(), - SIGNATURE_INPUT.as_ptr(), - HASH_INPUT.as_ptr(), - &pk, - ) == 1 - { - 1 - } else { - 0 - } + i32::from( + secp256k1_schnorrsig_verify( + get_context(), + SIGNATURE_INPUT.as_ptr(), + HASH_INPUT.as_ptr(), + 32, + &pk, + ) == 1, + ) } } diff --git a/tests/ecdsa.js b/tests/ecdsa.js index 802f9c8..d5ce1bb 100644 --- a/tests/ecdsa.js +++ b/tests/ecdsa.js @@ -1,6 +1,6 @@ import test from "tape"; import { fromHex, toHex } from "./util.js"; -import fecdsa from "./fixtures/ecdsa.json"; +import fecdsa from "./fixtures/ecdsa.json" assert { type: "json" }; const buf1 = fromHex( "0000000000000000000000000000000000000000000000000000000000000000" diff --git a/tests/fixtures/ecdsa.json b/tests/fixtures/ecdsa.json index de558d7..dddc346 100644 --- a/tests/fixtures/ecdsa.json +++ b/tests/fixtures/ecdsa.json @@ -106,11 +106,18 @@ "recoveryId": 1 }, { - "description": "Strange hash", + "description": "Strange hash (MAX)", "d": "0000000000000000000000000000000000000000000000000000000000000001", "m": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", - "signature": "3f8fe493cf305a7f02b2d2c060ba66a8f7bd13a7a64d5200c0655ad069bd85b51cf94236c3857e33a1023a5216cbc81b1dc3adcc1c71f4212df1997ffdfb140a", - "recoveryId": 1 + "signature": "7cb38cc5712e9e11a767615f6080dbc111c9cdd613eb98999fd92a86bafd45407923ca1f4d03471d2866f776ef8a6d3cac099b427331aeb245aa9dafeddcf115", + "recoveryId": 0 + }, + { + "description": "Strange hash (MAX % N) (Should be same as MAX)", + "d": "0000000000000000000000000000000000000000000000000000000000000001", + "m": "000000000000000000000000000000014551231950b75fc4402da1732fc9bebe", + "signature": "7cb38cc5712e9e11a767615f6080dbc111c9cdd613eb98999fd92a86bafd45407923ca1f4d03471d2866f776ef8a6d3cac099b427331aeb245aa9dafeddcf115", + "recoveryId": 0 }, { "description": "Stange hash", @@ -120,10 +127,17 @@ "recoveryId": 0 }, { - "description": "Strange hash", + "description": "Strange hash (MAX)", "d": "fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140", "m": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", - "signature": "2d0b04a7560652f419e2542ea7d27f2c4afb0e111bb409cfe9f34b7ff7d3315850118e90fcfe28abd0635a2e90f00db72bdbfcedbf56dad4049de85798031b38", + "signature": "a7f83b5963eaf5332c633327cc967be8f4166d3f1e0b77f9761d8f4e42211e9a58aae31be1eb1e496923bbe8ca5e843cfb89f4d986d61d4edfd7d6fc3c9cf62c", + "recoveryId": 0 + }, + { + "description": "Strange hash (MAX % N) (Should be same as MAX)", + "d": "fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140", + "m": "000000000000000000000000000000014551231950b75fc4402da1732fc9bebe", + "signature": "a7f83b5963eaf5332c633327cc967be8f4166d3f1e0b77f9761d8f4e42211e9a58aae31be1eb1e496923bbe8ca5e843cfb89f4d986d61d4edfd7d6fc3c9cf62c", "recoveryId": 0 }, { diff --git a/tests/points.js b/tests/points.js index ea7b8af..71bed40 100644 --- a/tests/points.js +++ b/tests/points.js @@ -1,6 +1,6 @@ import test from "tape"; import { fromHex } from "./util.js"; -import fpoints from "./fixtures/points.json"; +import fpoints from "./fixtures/points.json" assert { type: "json" }; export default function (secp256k1) { test("isPoint", (t) => { diff --git a/tests/privates.js b/tests/privates.js index 83d858f..9adf237 100644 --- a/tests/privates.js +++ b/tests/privates.js @@ -1,6 +1,6 @@ import test from "tape"; import { fromHex } from "./util.js"; -import fprivates from "./fixtures/privates.json"; +import fprivates from "./fixtures/privates.json" assert { type: "json" }; export default function (secp256k1) { test("isPrivate", (t) => { diff --git a/tests/schnorr.js b/tests/schnorr.js index 1da8340..948dbc6 100644 --- a/tests/schnorr.js +++ b/tests/schnorr.js @@ -1,6 +1,6 @@ import test from "tape"; import { fromHex, toHex } from "./util.js"; -import fschnorr from "./fixtures/schnorr.json"; +import fschnorr from "./fixtures/schnorr.json" assert { type: "json" }; export function parseBip340Vector(f) { return { From 05675e66c1482a86572891da38a7a6cf2190da2c Mon Sep 17 00:00:00 2001 From: junderw Date: Thu, 29 Jun 2023 01:24:00 -0700 Subject: [PATCH 2/2] 2.2.3 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index f225784..391a2c5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "tiny-secp256k1", - "version": "2.2.2", + "version": "2.2.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "tiny-secp256k1", - "version": "2.2.2", + "version": "2.2.3", "license": "MIT", "dependencies": { "uint8array-tools": "0.0.7" diff --git a/package.json b/package.json index 1e53c85..235f815 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tiny-secp256k1", - "version": "2.2.2", + "version": "2.2.3", "description": "A tiny secp256k1 JS", "homepage": "https://github.com/bitcoinjs/tiny-secp256k1#readme", "bugs": {