From 242ee620c5e0104300859740fe79b6afe5f590ea Mon Sep 17 00:00:00 2001 From: Paul Miller Date: Wed, 28 Dec 2022 06:32:27 +0000 Subject: [PATCH] Merge packages into one --- .github/workflows/nodejs.yml | 3 +- README.md | 57 +++--- .../benchmark => benchmark}/index.js | 0 .../benchmark => benchmark}/package.json | 0 curve-definitions/LICENSE | 21 --- curve-definitions/README.md | 13 -- curve-definitions/package.json | 58 ------ curve-definitions/test/hashToCurve.test.js | 109 ------------ curve-definitions/test/package.json | 7 - curve-definitions/tsconfig.esm.json | 25 --- curve-definitions/tsconfig.json | 25 --- package.json | 168 ++++++++++++++---- .../src => src}/_shortw_utils.ts | 5 +- src/{ => abstract}/bls.ts | 2 +- src/{ => abstract}/edwards.ts | 2 +- src/{ => abstract}/group.ts | 0 .../hash-to-curve.ts} | 0 src/{ => abstract}/modular.ts | 0 src/{ => abstract}/montgomery.ts | 0 src/{ => abstract}/utils.ts | 0 src/{ => abstract}/weierstrass.ts | 2 +- {curve-definitions/src => src}/bls12-381.ts | 39 ++-- {curve-definitions/src => src}/bn.ts | 6 +- {curve-definitions/src => src}/ed25519.ts | 10 +- {curve-definitions/src => src}/ed448.ts | 8 +- {curve-definitions/src => src}/index.ts | 0 {curve-definitions/src => src}/jubjub.ts | 6 +- {curve-definitions/src => src}/p192.ts | 4 +- {curve-definitions/src => src}/p224.ts | 4 +- {curve-definitions/src => src}/p256.ts | 6 +- {curve-definitions/src => src}/p384.ts | 6 +- {curve-definitions/src => src}/p521.ts | 8 +- {curve-definitions/src => src}/pasta.ts | 6 +- {curve-definitions/src => src}/secp256k1.ts | 10 +- {curve-definitions/src => src}/stark.ts | 10 +- .../test => test}/basic.test.js | 27 ++- .../test => test}/bls12-381.test.js | 4 +- .../bls12-381/bls12-381-g2-test-vectors.txt | 0 .../bls12-381-scalar-test-vectors.txt | 0 .../bls12-381/go_pairing_vectors/go.mod | 0 .../bls12-381/go_pairing_vectors/go.sum | 0 .../bls12-381/go_pairing_vectors/pairing.json | 0 .../bls12-381/go_pairing_vectors/t.go | 0 .../bls12-381/zkcrypto/convert.js | 0 .../bls12-381/zkcrypto/converted.json | 0 .../g1_compressed_valid_test_vectors.dat | Bin .../g1_uncompressed_valid_test_vectors.dat | Bin .../g2_compressed_valid_test_vectors.dat | Bin .../g2_uncompressed_valid_test_vectors.dat | Bin .../test => test}/ed25519.test.js | 4 +- .../test => test}/ed25519/vectors.txt | 0 .../test => test}/ed25519/zip215.json | 0 .../test => test}/ed448.test.js | 4 +- .../test => test}/fixtures/rfc6979.json | 0 test/hash-to-curve.test.js | 107 +++++++++++ .../BLS12381G1_XMD:SHA-256_SSWU_NU_.json | 0 .../BLS12381G1_XMD:SHA-256_SSWU_RO_.json | 0 .../BLS12381G2_XMD:SHA-256_SSWU_NU_.json | 0 .../BLS12381G2_XMD:SHA-256_SSWU_RO_.json | 0 .../P256_XMD:SHA-256_SSWU_NU_.json | 0 .../P256_XMD:SHA-256_SSWU_RO_.json | 0 .../P384_XMD:SHA-384_SSWU_NU_.json | 0 .../P384_XMD:SHA-384_SSWU_RO_.json | 0 .../P521_XMD:SHA-512_SSWU_NU_.json | 0 .../P521_XMD:SHA-512_SSWU_RO_.json | 0 .../curve25519_XMD:SHA-512_ELL2_NU_.json | 0 .../curve25519_XMD:SHA-512_ELL2_RO_.json | 0 .../curve448_XOF:SHAKE256_ELL2_NU_.json | 0 .../curve448_XOF:SHAKE256_ELL2_RO_.json | 0 .../edwards25519_XMD:SHA-512_ELL2_NU_.json | 0 .../edwards25519_XMD:SHA-512_ELL2_RO_.json | 0 .../edwards448_XOF:SHAKE256_ELL2_NU_.json | 0 .../edwards448_XOF:SHAKE256_ELL2_RO_.json | 0 .../expand_message_xmd_SHA256_256.json | 0 .../expand_message_xmd_SHA256_38.json | 0 .../expand_message_xmd_SHA512_38.json | 0 .../expand_message_xof_SHAKE128_256.json | 0 .../expand_message_xof_SHAKE128_36.json | 0 .../expand_message_xof_SHAKE256_36.json | 0 .../secp256k1_XMD:SHA-256_SSWU_NU_.json | 0 .../secp256k1_XMD:SHA-256_SSWU_RO_.json | 0 .../test => test}/index.test.js | 2 +- .../test => test}/jubjub.test.js | 2 +- {curve-definitions/test => test}/nist.test.js | 14 +- .../lib/esm => test}/package.json | 0 .../test => test}/secp256k1.test.js | 2 +- .../test => test}/stark/basic.test.js | 2 +- .../test => test}/stark/benchmark/index.js | 2 +- .../stark/benchmark/package.json | 0 .../test => test}/stark/fixtures/issue2.json | 0 .../stark/fixtures/keys_precomputed.json | 0 .../rfc6979_signature_test_vector.json | 0 .../test => test}/stark/index.test.js | 0 .../test => test}/stark/property.test.js | 2 +- .../test => test}/stark/stark.test.js | 2 +- .../test => test}/vectors/ecdh.json | 0 .../test => test}/vectors/ecdsa.json | 0 .../test => test}/vectors/points.json | 0 .../test => test}/vectors/points.txt | 0 .../test => test}/vectors/privates-2.txt | 0 .../test => test}/vectors/privates.json | 0 .../test => test}/vectors/rfc6979.json | 0 .../test => test}/vectors/schnorr.csv | 0 .../test => test}/vectors/wychenproof.json | 0 .../ecdh_secp224r1_ecpoint_test.json | 0 .../wycheproof/ecdh_secp224r1_test.json | 0 .../wycheproof/ecdh_secp256k1_test.json | 0 .../ecdh_secp256r1_ecpoint_test.json | 0 .../wycheproof/ecdh_secp256r1_test.json | 0 .../ecdh_secp384r1_ecpoint_test.json | 0 .../wycheproof/ecdh_secp384r1_test.json | 0 .../ecdh_secp521r1_ecpoint_test.json | 0 .../wycheproof/ecdh_secp521r1_test.json | 0 .../test => test}/wycheproof/ecdh_test.json | 0 .../ecdsa_secp224r1_sha224_test.json | 0 .../ecdsa_secp224r1_sha256_test.json | 0 .../ecdsa_secp224r1_sha3_224_test.json | 0 .../ecdsa_secp224r1_sha3_256_test.json | 0 .../ecdsa_secp224r1_sha3_512_test.json | 0 .../ecdsa_secp224r1_sha512_test.json | 0 .../ecdsa_secp256k1_sha256_test.json | 0 .../ecdsa_secp256k1_sha3_256_test.json | 0 .../ecdsa_secp256k1_sha3_512_test.json | 0 .../ecdsa_secp256k1_sha512_test.json | 0 .../ecdsa_secp256r1_sha256_test.json | 0 .../ecdsa_secp256r1_sha3_256_test.json | 0 .../ecdsa_secp256r1_sha3_512_test.json | 0 .../ecdsa_secp256r1_sha512_test.json | 0 .../ecdsa_secp384r1_sha384_test.json | 0 .../ecdsa_secp384r1_sha3_384_test.json | 0 .../ecdsa_secp384r1_sha3_512_test.json | 0 .../ecdsa_secp384r1_sha512_test.json | 0 .../ecdsa_secp521r1_sha3_512_test.json | 0 .../ecdsa_secp521r1_sha512_test.json | 0 .../test => test}/wycheproof/ecdsa_test.json | 0 .../test => test}/wycheproof/ed448_test.json | 0 .../test => test}/wycheproof/eddsa_test.json | 0 .../test => test}/wycheproof/x25519_test.json | 0 .../test => test}/wycheproof/x448_test.json | 0 139 files changed, 369 insertions(+), 425 deletions(-) rename {curve-definitions/benchmark => benchmark}/index.js (100%) rename {curve-definitions/benchmark => benchmark}/package.json (100%) delete mode 100644 curve-definitions/LICENSE delete mode 100644 curve-definitions/README.md delete mode 100644 curve-definitions/package.json delete mode 100644 curve-definitions/test/hashToCurve.test.js delete mode 100644 curve-definitions/test/package.json delete mode 100644 curve-definitions/tsconfig.esm.json delete mode 100644 curve-definitions/tsconfig.json rename {curve-definitions/src => src}/_shortw_utils.ts (78%) rename src/{ => abstract}/bls.ts (99%) rename src/{ => abstract}/edwards.ts (99%) rename src/{ => abstract}/group.ts (100%) rename src/{hashToCurve.ts => abstract/hash-to-curve.ts} (100%) rename src/{ => abstract}/modular.ts (100%) rename src/{ => abstract}/montgomery.ts (100%) rename src/{ => abstract}/utils.ts (100%) rename src/{ => abstract}/weierstrass.ts (99%) rename {curve-definitions/src => src}/bls12-381.ts (98%) rename {curve-definitions/src => src}/bn.ts (78%) rename {curve-definitions/src => src}/ed25519.ts (97%) rename {curve-definitions/src => src}/ed448.ts (96%) rename {curve-definitions/src => src}/index.ts (100%) rename {curve-definitions/src => src}/jubjub.ts (92%) rename {curve-definitions/src => src}/p192.ts (89%) rename {curve-definitions/src => src}/p224.ts (89%) rename {curve-definitions/src => src}/p256.ts (88%) rename {curve-definitions/src => src}/p384.ts (90%) rename {curve-definitions/src => src}/p521.ts (90%) rename {curve-definitions/src => src}/pasta.ts (80%) rename {curve-definitions/src => src}/secp256k1.ts (97%) rename {curve-definitions/src => src}/stark.ts (96%) rename {curve-definitions/test => test}/basic.test.js (94%) rename {curve-definitions/test => test}/bls12-381.test.js (99%) rename {curve-definitions/test => test}/bls12-381/bls12-381-g2-test-vectors.txt (100%) rename {curve-definitions/test => test}/bls12-381/bls12-381-scalar-test-vectors.txt (100%) rename {curve-definitions/test => test}/bls12-381/go_pairing_vectors/go.mod (100%) rename {curve-definitions/test => test}/bls12-381/go_pairing_vectors/go.sum (100%) rename {curve-definitions/test => test}/bls12-381/go_pairing_vectors/pairing.json (100%) rename {curve-definitions/test => test}/bls12-381/go_pairing_vectors/t.go (100%) rename {curve-definitions/test => test}/bls12-381/zkcrypto/convert.js (100%) rename {curve-definitions/test => test}/bls12-381/zkcrypto/converted.json (100%) rename {curve-definitions/test => test}/bls12-381/zkcrypto/g1_compressed_valid_test_vectors.dat (100%) rename {curve-definitions/test => test}/bls12-381/zkcrypto/g1_uncompressed_valid_test_vectors.dat (100%) rename {curve-definitions/test => test}/bls12-381/zkcrypto/g2_compressed_valid_test_vectors.dat (100%) rename {curve-definitions/test => test}/bls12-381/zkcrypto/g2_uncompressed_valid_test_vectors.dat (100%) rename {curve-definitions/test => test}/ed25519.test.js (99%) rename {curve-definitions/test => test}/ed25519/vectors.txt (100%) rename {curve-definitions/test => test}/ed25519/zip215.json (100%) rename {curve-definitions/test => test}/ed448.test.js (99%) rename {curve-definitions/test => test}/fixtures/rfc6979.json (100%) create mode 100644 test/hash-to-curve.test.js rename {curve-definitions/test/hashToCurve => test/hash-to-curve}/BLS12381G1_XMD:SHA-256_SSWU_NU_.json (100%) rename {curve-definitions/test/hashToCurve => test/hash-to-curve}/BLS12381G1_XMD:SHA-256_SSWU_RO_.json (100%) rename {curve-definitions/test/hashToCurve => test/hash-to-curve}/BLS12381G2_XMD:SHA-256_SSWU_NU_.json (100%) rename {curve-definitions/test/hashToCurve => test/hash-to-curve}/BLS12381G2_XMD:SHA-256_SSWU_RO_.json (100%) rename {curve-definitions/test/hashToCurve => test/hash-to-curve}/P256_XMD:SHA-256_SSWU_NU_.json (100%) rename {curve-definitions/test/hashToCurve => test/hash-to-curve}/P256_XMD:SHA-256_SSWU_RO_.json (100%) rename {curve-definitions/test/hashToCurve => test/hash-to-curve}/P384_XMD:SHA-384_SSWU_NU_.json (100%) rename {curve-definitions/test/hashToCurve => test/hash-to-curve}/P384_XMD:SHA-384_SSWU_RO_.json (100%) rename {curve-definitions/test/hashToCurve => test/hash-to-curve}/P521_XMD:SHA-512_SSWU_NU_.json (100%) rename {curve-definitions/test/hashToCurve => test/hash-to-curve}/P521_XMD:SHA-512_SSWU_RO_.json (100%) rename {curve-definitions/test/hashToCurve => test/hash-to-curve}/curve25519_XMD:SHA-512_ELL2_NU_.json (100%) rename {curve-definitions/test/hashToCurve => test/hash-to-curve}/curve25519_XMD:SHA-512_ELL2_RO_.json (100%) rename {curve-definitions/test/hashToCurve => test/hash-to-curve}/curve448_XOF:SHAKE256_ELL2_NU_.json (100%) rename {curve-definitions/test/hashToCurve => test/hash-to-curve}/curve448_XOF:SHAKE256_ELL2_RO_.json (100%) rename {curve-definitions/test/hashToCurve => test/hash-to-curve}/edwards25519_XMD:SHA-512_ELL2_NU_.json (100%) rename {curve-definitions/test/hashToCurve => test/hash-to-curve}/edwards25519_XMD:SHA-512_ELL2_RO_.json (100%) rename {curve-definitions/test/hashToCurve => test/hash-to-curve}/edwards448_XOF:SHAKE256_ELL2_NU_.json (100%) rename {curve-definitions/test/hashToCurve => test/hash-to-curve}/edwards448_XOF:SHAKE256_ELL2_RO_.json (100%) rename {curve-definitions/test/hashToCurve => test/hash-to-curve}/expand_message_xmd_SHA256_256.json (100%) rename {curve-definitions/test/hashToCurve => test/hash-to-curve}/expand_message_xmd_SHA256_38.json (100%) rename {curve-definitions/test/hashToCurve => test/hash-to-curve}/expand_message_xmd_SHA512_38.json (100%) rename {curve-definitions/test/hashToCurve => test/hash-to-curve}/expand_message_xof_SHAKE128_256.json (100%) rename {curve-definitions/test/hashToCurve => test/hash-to-curve}/expand_message_xof_SHAKE128_36.json (100%) rename {curve-definitions/test/hashToCurve => test/hash-to-curve}/expand_message_xof_SHAKE256_36.json (100%) rename {curve-definitions/test/hashToCurve => test/hash-to-curve}/secp256k1_XMD:SHA-256_SSWU_NU_.json (100%) rename {curve-definitions/test/hashToCurve => test/hash-to-curve}/secp256k1_XMD:SHA-256_SSWU_RO_.json (100%) rename {curve-definitions/test => test}/index.test.js (90%) rename {curve-definitions/test => test}/jubjub.test.js (97%) rename {curve-definitions/test => test}/nist.test.js (97%) rename {curve-definitions/lib/esm => test}/package.json (100%) rename {curve-definitions/test => test}/secp256k1.test.js (99%) rename {curve-definitions/test => test}/stark/basic.test.js (99%) rename {curve-definitions/test => test}/stark/benchmark/index.js (96%) rename {curve-definitions/test => test}/stark/benchmark/package.json (100%) rename {curve-definitions/test => test}/stark/fixtures/issue2.json (100%) rename {curve-definitions/test => test}/stark/fixtures/keys_precomputed.json (100%) rename {curve-definitions/test => test}/stark/fixtures/rfc6979_signature_test_vector.json (100%) rename {curve-definitions/test => test}/stark/index.test.js (100%) rename {curve-definitions/test => test}/stark/property.test.js (96%) rename {curve-definitions/test => test}/stark/stark.test.js (99%) rename {curve-definitions/test => test}/vectors/ecdh.json (100%) rename {curve-definitions/test => test}/vectors/ecdsa.json (100%) rename {curve-definitions/test => test}/vectors/points.json (100%) rename {curve-definitions/test => test}/vectors/points.txt (100%) rename {curve-definitions/test => test}/vectors/privates-2.txt (100%) rename {curve-definitions/test => test}/vectors/privates.json (100%) rename {curve-definitions/test => test}/vectors/rfc6979.json (100%) rename {curve-definitions/test => test}/vectors/schnorr.csv (100%) rename {curve-definitions/test => test}/vectors/wychenproof.json (100%) rename {curve-definitions/test => test}/wycheproof/ecdh_secp224r1_ecpoint_test.json (100%) rename {curve-definitions/test => test}/wycheproof/ecdh_secp224r1_test.json (100%) rename {curve-definitions/test => test}/wycheproof/ecdh_secp256k1_test.json (100%) rename {curve-definitions/test => test}/wycheproof/ecdh_secp256r1_ecpoint_test.json (100%) rename {curve-definitions/test => test}/wycheproof/ecdh_secp256r1_test.json (100%) rename {curve-definitions/test => test}/wycheproof/ecdh_secp384r1_ecpoint_test.json (100%) rename {curve-definitions/test => test}/wycheproof/ecdh_secp384r1_test.json (100%) rename {curve-definitions/test => test}/wycheproof/ecdh_secp521r1_ecpoint_test.json (100%) rename {curve-definitions/test => test}/wycheproof/ecdh_secp521r1_test.json (100%) rename {curve-definitions/test => test}/wycheproof/ecdh_test.json (100%) rename {curve-definitions/test => test}/wycheproof/ecdsa_secp224r1_sha224_test.json (100%) rename {curve-definitions/test => test}/wycheproof/ecdsa_secp224r1_sha256_test.json (100%) rename {curve-definitions/test => test}/wycheproof/ecdsa_secp224r1_sha3_224_test.json (100%) rename {curve-definitions/test => test}/wycheproof/ecdsa_secp224r1_sha3_256_test.json (100%) rename {curve-definitions/test => test}/wycheproof/ecdsa_secp224r1_sha3_512_test.json (100%) rename {curve-definitions/test => test}/wycheproof/ecdsa_secp224r1_sha512_test.json (100%) rename {curve-definitions/test => test}/wycheproof/ecdsa_secp256k1_sha256_test.json (100%) rename {curve-definitions/test => test}/wycheproof/ecdsa_secp256k1_sha3_256_test.json (100%) rename {curve-definitions/test => test}/wycheproof/ecdsa_secp256k1_sha3_512_test.json (100%) rename {curve-definitions/test => test}/wycheproof/ecdsa_secp256k1_sha512_test.json (100%) rename {curve-definitions/test => test}/wycheproof/ecdsa_secp256r1_sha256_test.json (100%) rename {curve-definitions/test => test}/wycheproof/ecdsa_secp256r1_sha3_256_test.json (100%) rename {curve-definitions/test => test}/wycheproof/ecdsa_secp256r1_sha3_512_test.json (100%) rename {curve-definitions/test => test}/wycheproof/ecdsa_secp256r1_sha512_test.json (100%) rename {curve-definitions/test => test}/wycheproof/ecdsa_secp384r1_sha384_test.json (100%) rename {curve-definitions/test => test}/wycheproof/ecdsa_secp384r1_sha3_384_test.json (100%) rename {curve-definitions/test => test}/wycheproof/ecdsa_secp384r1_sha3_512_test.json (100%) rename {curve-definitions/test => test}/wycheproof/ecdsa_secp384r1_sha512_test.json (100%) rename {curve-definitions/test => test}/wycheproof/ecdsa_secp521r1_sha3_512_test.json (100%) rename {curve-definitions/test => test}/wycheproof/ecdsa_secp521r1_sha512_test.json (100%) rename {curve-definitions/test => test}/wycheproof/ecdsa_test.json (100%) rename {curve-definitions/test => test}/wycheproof/ed448_test.json (100%) rename {curve-definitions/test => test}/wycheproof/eddsa_test.json (100%) rename {curve-definitions/test => test}/wycheproof/x25519_test.json (100%) rename {curve-definitions/test => test}/wycheproof/x448_test.json (100%) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 2e9f2f5..6929ba2 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -13,6 +13,5 @@ jobs: node-version: 18 - run: npm install - run: npm run build --if-present - - run: cd curve-definitions; npm install; npm run build --if-present - - run: npm test - run: npm run lint --if-present + - run: npm test diff --git a/README.md b/README.md index 2eeae50..3052d51 100644 --- a/README.md +++ b/README.md @@ -1,36 +1,36 @@ # noble-curves -Minimal, zero-dependency JS implementation of elliptic curve cryptography. +Minimal, auditable JS implementation of elliptic curve cryptography. - Short Weierstrass, Edwards, Montgomery curves -- ECDSA, EdDSA, Schnorr, BLS signature schemes -- ECDH key agreement -- [hash to curve](https://datatracker.ietf.org/doc/draft-irtf-cfrg-hash-to-curve/) algorithms for encoding or hashing an arbitrary string to a point on an elliptic curve +- ECDSA, EdDSA, Schnorr, BLS signature schemes, ECDH key agreement +- [hash to curve](https://datatracker.ietf.org/doc/draft-irtf-cfrg-hash-to-curve/) + for encoding or hashing an arbitrary string to a point on an elliptic curve - Auditable, [fast](#speed) -- 🔻 Helps JS bundlers with lack of entry point, ensures small size of your app +- 🔻 Tree-shaking-friendly: there is no entry point, which ensures small size of your app - 🔍 Unique tests ensure correctness. Wycheproof vectors included -No curve definitions are provided out-of-box. Use separate package `micro-curve-definitions`: +There are two parts of the package: -- It provides: +1. `abstract/` directory specifies zero-dependency EC algorithms +2. root directory utilizes one dependency `@noble/hashes` and provides ready-to-use: - NIST curves secp192r1/P192, secp224r1/P224, secp256r1/P256, secp384r1/P384, secp521r1/P521 - SECG curve secp256k1 - - bls12-381, bn254 pairing-friendly curves + - pairing-friendly curves bls12-381, bn254 - ed25519/curve25519/x25519/ristretto, edwards448/curve448/x448 RFC7748 / RFC8032 / ZIP215 stuff -- It allows to keep the main library minimal, zero-dependency. - m-c-d depends on a hashing library `@noble/hashes` -- Packages may be merged later, once a stable version is ready -The goal for the near future is to update previous packages +Curves incorporate work from previous noble packages ([secp256k1](https://github.com/paulmillr/noble-secp256k1), [ed25519](https://github.com/paulmillr/noble-ed25519), -[bls12-381](https://github.com/paulmillr/noble-bls12-381)) with lean UMD builds based on noble-curves. This would improve compatibility & allow having one codebase for everything. +[bls12-381](https://github.com/paulmillr/noble-bls12-381)), +which had security audits and were developed from 2019 to 2022. +The goal is to replace them with lean UMD builds based on single-codebase noble-curves. ### This library belongs to _noble_ crypto > **noble-crypto** — high-security, easily auditable set of contained cryptographic libraries and tools. -- No dependencies, small files +- Minimal dependencies, small files - Easily auditable TypeScript/JS code - Supported in all major browsers and stable node.js versions - All releases are signed with PGP keys @@ -50,8 +50,23 @@ Use NPM in node.js / browser, or include single file from The library does not have an entry point. It allows you to select specific primitives and drop everything else. If you only want to use secp256k1, just use the library with rollup or other bundlers. This is done to make your bundles tiny. ```ts -import { Fp } from '@noble/curves/modular'; -import { weierstrass } from '@noble/curves/weierstrass'; +import { secp256k1 } from '@noble/curves/secp256k1'; + +const key = secp256k1.utils.randomPrivateKey(); +const pub = secp256k1.getPublicKey(key); +const msg = new Uint8Array(32).fill(1); +const sig = secp256k1.sign(msg, key); +secp256k1.verify(sig, msg, pub) === true; +sig.recoverPublicKey(msg) === pub; +const someonesPub = secp256k1.getPublicKey(secp256k1.utils.randomPrivateKey()); +const shared = secp256k1.getSharedSecret(key, someonesPub); +``` + +To define a custom curve with the same functionality: + +```ts +import { Fp } from '@noble/curves/abstract/modular'; +import { weierstrass } from '@noble/curves/abstract/weierstrass'; import { sha256 } from '@noble/hashes/sha256'; import { hmac } from '@noble/hashes/hmac'; import { concatBytes, randomBytes } from '@noble/hashes/utils'; @@ -65,16 +80,8 @@ const secp256k1 = weierstrass({ Gy: 32670510020758816978083085130507043184471273380659243275938904335757337482424n, hash: sha256, hmac: (k: Uint8Array, ...msgs: Uint8Array[]) => hmac(sha256, key, concatBytes(...msgs)), + randomBytes }); - -const key = secp256k1.utils.randomPrivateKey(); -const pub = secp256k1.getPublicKey(key); -const msg = randomBytes(32); -const sig = secp256k1.sign(msg, key); -secp256k1.verify(sig, msg, pub) === true; -sig.recoverPublicKey(msg) === pub; -const someonesPub = secp256k1.getPublicKey(secp256k1.utils.randomPrivateKey()); -const shared = secp256k1.getSharedSecret(key, someonesPub); ``` ## API diff --git a/curve-definitions/benchmark/index.js b/benchmark/index.js similarity index 100% rename from curve-definitions/benchmark/index.js rename to benchmark/index.js diff --git a/curve-definitions/benchmark/package.json b/benchmark/package.json similarity index 100% rename from curve-definitions/benchmark/package.json rename to benchmark/package.json diff --git a/curve-definitions/LICENSE b/curve-definitions/LICENSE deleted file mode 100644 index 9297a04..0000000 --- a/curve-definitions/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2022 Paul Miller (https://paulmillr.com) - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the “Software”), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. \ No newline at end of file diff --git a/curve-definitions/README.md b/curve-definitions/README.md deleted file mode 100644 index aa0a476..0000000 --- a/curve-definitions/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# micro-curve-definitions - -Elliptic curves implementations. `@noble/curves` is zero-dependency library for internal arithmetics. - -## Usage - -```sh -npm install micro-curve-definitions -``` - -## License - -MIT (c) Paul Miller [(https://paulmillr.com)](https://paulmillr.com), see LICENSE file. diff --git a/curve-definitions/package.json b/curve-definitions/package.json deleted file mode 100644 index 1bdc8b7..0000000 --- a/curve-definitions/package.json +++ /dev/null @@ -1,58 +0,0 @@ -{ - "name": "micro-curve-definitions", - "version": "0.4.0", - "description": "Curve definitions for @noble/curves", - "files": [ - "lib" - ], - "main": "lib/index.js", - "module": "lib/index.js", - "types": "lib/index.d.ts", - "dependencies": { - "@noble/curves": "file:..", - "@noble/hashes": "1.1.5" - }, - "devDependencies": { - "@scure/base": "~1.1.0", - "@scure/bip32": "^1.1.1", - "@scure/bip39": "^1.1.0", - "@types/node": "18.11.3", - "fast-check": "3.0.0", - "micro-should": "0.2.0", - "prettier": "2.6.2", - "typescript": "4.7.3" - }, - "author": "Paul Miller (https://paulmillr.com)", - "license": "MIT", - "homepage": "https://github.com/paulmillr/noble-curves", - "repository": { - "type": "git", - "url": "git+https://github.com/paulmillr/noble-curves.git" - }, - "scripts": { - "build": "tsc && tsc -p tsconfig.esm.json", - "lint": "prettier --check src", - "test": "node test/index.test.js" - }, - "keywords": [ - "secp192r1", - "secp224r1", - "secp256r1", - "secp384r1", - "secp521r1", - "NIST P192", - "NIST P224", - "NIST P256", - "NIST P384", - "NIST P521", - "NIST curves", - "EC", - "elliptic curves" - ], - "funding": [ - { - "type": "individual", - "url": "https://paulmillr.com/funding/" - } - ] -} diff --git a/curve-definitions/test/hashToCurve.test.js b/curve-definitions/test/hashToCurve.test.js deleted file mode 100644 index c387efa..0000000 --- a/curve-definitions/test/hashToCurve.test.js +++ /dev/null @@ -1,109 +0,0 @@ -import { deepStrictEqual } from 'assert'; -import { should } from 'micro-should'; -import { bytesToHex } from '@noble/hashes/utils'; -// Generic tests for all curves in package -import { sha256 } from '@noble/hashes/sha256'; -import { sha512 } from '@noble/hashes/sha512'; -import { secp256r1 } from '../lib/p256.js'; -import { secp384r1 } from '../lib/p384.js'; -import { secp521r1 } from '../lib/p521.js'; -import { secp256k1 } from '../lib/secp256k1.js'; -import { bls12_381 } from '../lib/bls12-381.js'; -import { ed25519 } from '../lib/ed25519.js'; -import { ed448 } from '../lib/ed448.js'; -import { stringToBytes, expand_message_xmd } from '@noble/curves/hashToCurve'; - -import { default as xmd_sha256_38 } from './hashToCurve/expand_message_xmd_SHA256_38.json' assert { type: 'json' }; -import { default as xmd_sha256_256 } from './hashToCurve/expand_message_xmd_SHA256_256.json' assert { type: 'json' }; -import { default as xmd_sha512_38 } from './hashToCurve/expand_message_xmd_SHA512_38.json' assert { type: 'json' }; -// P256 -import { default as p256_ro } from './hashToCurve/P256_XMD:SHA-256_SSWU_RO_.json' assert { type: 'json' }; -import { default as p256_nu } from './hashToCurve/P256_XMD:SHA-256_SSWU_NU_.json' assert { type: 'json' }; -// P384 -import { default as p384_ro } from './hashToCurve/P384_XMD:SHA-384_SSWU_RO_.json' assert { type: 'json' }; -import { default as p384_nu } from './hashToCurve/P384_XMD:SHA-384_SSWU_NU_.json' assert { type: 'json' }; -// P521 -import { default as p521_ro } from './hashToCurve/P521_XMD:SHA-512_SSWU_RO_.json' assert { type: 'json' }; -import { default as p521_nu } from './hashToCurve/P521_XMD:SHA-512_SSWU_NU_.json' assert { type: 'json' }; -// secp256k1 -import { default as secp256k1_ro } from './hashToCurve/secp256k1_XMD:SHA-256_SSWU_RO_.json' assert { type: 'json' }; -import { default as secp256k1_nu } from './hashToCurve/secp256k1_XMD:SHA-256_SSWU_NU_.json' assert { type: 'json' }; -// bls-G1 -import { default as g1_ro } from './hashToCurve/BLS12381G1_XMD:SHA-256_SSWU_RO_.json' assert { type: 'json' }; -import { default as g1_nu } from './hashToCurve/BLS12381G1_XMD:SHA-256_SSWU_NU_.json' assert { type: 'json' }; -// bls-G2 -import { default as g2_ro } from './hashToCurve/BLS12381G2_XMD:SHA-256_SSWU_RO_.json' assert { type: 'json' }; -import { default as g2_nu } from './hashToCurve/BLS12381G2_XMD:SHA-256_SSWU_NU_.json' assert { type: 'json' }; -// ed25519 -import { default as ed25519_ro } from './hashToCurve/edwards25519_XMD:SHA-512_ELL2_RO_.json' assert { type: 'json' }; -import { default as ed25519_nu } from './hashToCurve/edwards25519_XMD:SHA-512_ELL2_NU_.json' assert { type: 'json' }; -// ed448 -import { default as ed448_ro } from './hashToCurve/edwards448_XOF:SHAKE256_ELL2_RO_.json' assert { type: 'json' }; -import { default as ed448_nu } from './hashToCurve/edwards448_XOF:SHAKE256_ELL2_NU_.json' assert { type: 'json' }; - -function testExpandXMD(hash, vectors) { - for (let i = 0; i < vectors.tests.length; i++) { - const t = vectors.tests[i]; - should(`expand_message_xmd/${vectors.hash}/${vectors.DST.length}/${i}`, () => { - const p = expand_message_xmd( - stringToBytes(t.msg), - stringToBytes(vectors.DST), - t.len_in_bytes, - hash - ); - deepStrictEqual(bytesToHex(p), t.uniform_bytes); - }); - } -} - -testExpandXMD(sha256, xmd_sha256_38); -testExpandXMD(sha256, xmd_sha256_256); -testExpandXMD(sha512, xmd_sha512_38); - -function stringToFp(s) { - // bls-G2 support - if (s.includes(',')) { - const [c0, c1] = s.split(',').map(BigInt); - return { c0, c1 }; - } - return BigInt(s); -} - -function testCurve(curve, ro, nu) { - for (let i = 0; i < ro.vectors.length; i++) { - const t = ro.vectors[i]; - should(`${ro.curve}/${ro.ciphersuite}(${i})`, () => { - const p = curve.Point.hashToCurve(stringToBytes(t.msg), { - DST: ro.dst, - }); - deepStrictEqual(p.x, stringToFp(t.P.x), 'Px'); - deepStrictEqual(p.y, stringToFp(t.P.y), 'Py'); - }); - } - for (let i = 0; i < nu.vectors.length; i++) { - const t = nu.vectors[i]; - should(`${nu.curve}/${nu.ciphersuite}(${i})`, () => { - const p = curve.Point.encodeToCurve(stringToBytes(t.msg), { - DST: nu.dst, - }); - deepStrictEqual(p.x, stringToFp(t.P.x), 'Px'); - deepStrictEqual(p.y, stringToFp(t.P.y), 'Py'); - }); - } -} - -testCurve(secp256r1, p256_ro, p256_nu); -testCurve(secp384r1, p384_ro, p384_nu); -testCurve(secp521r1, p521_ro, p521_nu); -// TODO: remove same tests from bls12 -testCurve(bls12_381.G1, g1_ro, g1_nu); -testCurve(bls12_381.G2, g2_ro, g2_nu); -testCurve(secp256k1, secp256k1_ro, secp256k1_nu); -//testCurve(ed25519, ed25519_ro, ed25519_nu); -//testCurve(ed448, ed448_ro, ed448_nu); - -// ESM is broken. -import url from 'url'; -if (import.meta.url === url.pathToFileURL(process.argv[1]).href) { - should.run(); -} diff --git a/curve-definitions/test/package.json b/curve-definitions/test/package.json deleted file mode 100644 index 1517420..0000000 --- a/curve-definitions/test/package.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "type": "module", - "browser": { - "crypto": false, - "./crypto": "./esm/cryptoBrowser.js" - } -} diff --git a/curve-definitions/tsconfig.esm.json b/curve-definitions/tsconfig.esm.json deleted file mode 100644 index c71b25e..0000000 --- a/curve-definitions/tsconfig.esm.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "compilerOptions": { - "strict": true, - "declaration": true, - "declarationMap": true, - "target": "es2020", - "lib": [ - "es2020", - "dom" - ], - "module": "es6", - "moduleResolution": "node16", - "outDir": "lib/esm", - "noImplicitAny": true, - "preserveConstEnums": true, - "baseUrl": ".", - }, - "include": [ - "src", - ], - "exclude": [ - "node_modules", - "lib" - ] -} \ No newline at end of file diff --git a/curve-definitions/tsconfig.json b/curve-definitions/tsconfig.json deleted file mode 100644 index 9beeb18..0000000 --- a/curve-definitions/tsconfig.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "compilerOptions": { - "strict": true, - "declaration": true, - "declarationMap": true, - "target": "es2020", - "lib": [ - "es2020", - "dom" - ], - "module": "commonjs", - "moduleResolution": "node16", - "outDir": "lib", - "noImplicitAny": true, - "preserveConstEnums": true, - "baseUrl": ".", - }, - "include": [ - "src", - ], - "exclude": [ - "node_modules", - "lib" - ] -} \ No newline at end of file diff --git a/package.json b/package.json index bbfdfdb..aa25ff1 100644 --- a/package.json +++ b/package.json @@ -1,19 +1,19 @@ { "name": "@noble/curves", "version": "0.4.0", - "description": "Minimal, zero-dependency JS implementation of elliptic curve cryptography", + "description": "Minimal, auditable JS implementation of elliptic curve cryptography", "files": [ "index.js", "lib", "lib/esm" ], "scripts": { - "bench": "node curve-definitions/benchmark/index.js", + "bench": "node benchmark/index.js", "build": "tsc && tsc -p tsconfig.esm.json", "build:release": "rollup -c rollup.config.js", - "lint": "prettier --check 'src/**/*.{js,ts}' 'curve-definitions/src/**/*.{js,ts}'", - "format": "prettier --write 'src/**/*.{js,ts}' 'curve-definitions/src/**/*.{js,ts}'", - "test": "cd curve-definitions; node test/index.test.js" + "lint": "prettier --check 'src/**/*.{js,ts}' 'test/*.js'", + "format": "prettier --write 'src/**/*.{js,ts}' 'test/*.js'", + "test": "node test/index.test.js" }, "author": "Paul Miller (https://paulmillr.com)", "homepage": "https://paulmillr.com/noble/", @@ -22,8 +22,16 @@ "url": "https://github.com/paulmillr/noble-curves.git" }, "license": "MIT", + "dependencies": { + "@noble/hashes": "~1.1.5" + }, "devDependencies": { "@rollup/plugin-node-resolve": "13.3.0", + "@scure/base": "~1.1.1", + "@scure/bip32": "~1.1.1", + "@scure/bip39": "~1.1.0", + "@types/node": "18.11.3", + "fast-check": "3.0.0", "micro-bmark": "0.2.0", "micro-should": "0.2.0", "prettier": "2.6.2", @@ -32,55 +40,137 @@ }, "main": "index.js", "exports": { - "./edwards": { - "types": "./lib/edwards.d.ts", - "import": "./lib/esm/edwards.js", - "default": "./lib/edwards.js" + "./abstract/edwards": { + "types": "./lib/abstract/edwards.d.ts", + "import": "./lib/esm/abstract/edwards.js", + "default": "./lib/abstract/edwards.js" }, - "./modular": { - "types": "./lib/modular.d.ts", - "import": "./lib/esm/modular.js", - "default": "./lib/modular.js" + "./abstract/modular": { + "types": "./lib/abstract/modular.d.ts", + "import": "./lib/esm/abstract/modular.js", + "default": "./lib/abstract/modular.js" }, - "./montgomery": { - "types": "./lib/montgomery.d.ts", - "import": "./lib/esm/montgomery.js", - "default": "./lib/montgomery.js" + "./abstract/montgomery": { + "types": "./lib/abstract/montgomery.d.ts", + "import": "./lib/esm/abstract/montgomery.js", + "default": "./lib/abstract/montgomery.js" }, - "./weierstrass": { - "types": "./lib/weierstrass.d.ts", - "import": "./lib/esm/weierstrass.js", - "default": "./lib/weierstrass.js" + "./abstract/weierstrass": { + "types": "./lib/abstract/weierstrass.d.ts", + "import": "./lib/esm/abstract/weierstrass.js", + "default": "./lib/abstract/weierstrass.js" }, - "./bls": { - "types": "./lib/bls.d.ts", - "import": "./lib/esm/bls.js", - "default": "./lib/bls.js" + "./abstract/bls": { + "types": "./lib/abstract/bls.d.ts", + "import": "./lib/esm/abstract/bls.js", + "default": "./lib/abstract/bls.js" }, - "./hashToCurve": { - "types": "./lib/hashToCurve.d.ts", - "import": "./lib/esm/hashToCurve.js", - "default": "./lib/hashToCurve.js" + "./abstract/hash-to-curve": { + "types": "./lib/abstract/hash-to-curve.d.ts", + "import": "./lib/esm/abstract/hash-to-curve.js", + "default": "./lib/abstract/hash-to-curve.js" }, - "./group": { - "types": "./lib/group.d.ts", - "import": "./lib/esm/group.js", - "default": "./lib/group.js" + "./abstract/group": { + "types": "./lib/abstract/group.d.ts", + "import": "./lib/esm/abstract/group.js", + "default": "./lib/abstract/group.js" }, - "./utils": { - "types": "./lib/utils.d.ts", - "import": "./lib/esm/utils.js", - "default": "./lib/utils.js" + "./abstract/utils": { + "types": "./lib/abstract/utils.d.ts", + "import": "./lib/esm/abstract/utils.js", + "default": "./lib/abstract/utils.js" + }, + "./_shortw_utils": { + "types": "./lib/_shortw_utils.d.ts", + "import": "./lib/esm/_shortw_utils.js", + "default": "./lib/_shortw_utils.js" + }, + "./bls12-381": { + "types": "./lib/bls12-381.d.ts", + "import": "./lib/esm/bls12-381.js", + "default": "./lib/bls12-381.js" + }, + "./bn": { + "types": "./lib/bn.d.ts", + "import": "./lib/esm/bn.js", + "default": "./lib/bn.js" + }, + "./ed25519": { + "types": "./lib/ed25519.d.ts", + "import": "./lib/esm/ed25519.js", + "default": "./lib/ed25519.js" + }, + "./ed448": { + "types": "./lib/ed448.d.ts", + "import": "./lib/esm/ed448.js", + "default": "./lib/ed448.js" + }, + "./index": { + "types": "./lib/index.d.ts", + "import": "./lib/esm/index.js", + "default": "./lib/index.js" + }, + "./jubjub": { + "types": "./lib/jubjub.d.ts", + "import": "./lib/esm/jubjub.js", + "default": "./lib/jubjub.js" + }, + "./p192": { + "types": "./lib/p192.d.ts", + "import": "./lib/esm/p192.js", + "default": "./lib/p192.js" + }, + "./p224": { + "types": "./lib/p224.d.ts", + "import": "./lib/esm/p224.js", + "default": "./lib/p224.js" + }, + "./p256": { + "types": "./lib/p256.d.ts", + "import": "./lib/esm/p256.js", + "default": "./lib/p256.js" + }, + "./p384": { + "types": "./lib/p384.d.ts", + "import": "./lib/esm/p384.js", + "default": "./lib/p384.js" + }, + "./p521": { + "types": "./lib/p521.d.ts", + "import": "./lib/esm/p521.js", + "default": "./lib/p521.js" + }, + "./pasta": { + "types": "./lib/pasta.d.ts", + "import": "./lib/esm/pasta.js", + "default": "./lib/pasta.js" + }, + "./secp256k1": { + "types": "./lib/secp256k1.d.ts", + "import": "./lib/esm/secp256k1.js", + "default": "./lib/secp256k1.js" + }, + "./stark": { + "types": "./lib/stark.d.ts", + "import": "./lib/esm/stark.js", + "default": "./lib/stark.js" } }, "keywords": [ "elliptic", "curve", "cryptography", - "hyperelliptic", + "weierstrass", + "montgomery", + "edwards", "p256", "p384", "p521", + "secp256r1", + "secp256k1", + "bls12-381", + "bn254", + "bls", "nist", "ecc", "ecdsa", @@ -93,4 +183,4 @@ "url": "https://paulmillr.com/funding/" } ] -} \ No newline at end of file +} diff --git a/curve-definitions/src/_shortw_utils.ts b/src/_shortw_utils.ts similarity index 78% rename from curve-definitions/src/_shortw_utils.ts rename to src/_shortw_utils.ts index 1084572..ebda4a9 100644 --- a/curve-definitions/src/_shortw_utils.ts +++ b/src/_shortw_utils.ts @@ -1,7 +1,8 @@ +/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */ import { hmac } from '@noble/hashes/hmac'; import { concatBytes, randomBytes } from '@noble/hashes/utils'; -import { weierstrass, CurveType } from '@noble/curves/weierstrass'; -import { CHash } from '@noble/curves/utils'; +import { weierstrass, CurveType } from './abstract/weierstrass.js'; +import { CHash } from './abstract/utils.js'; export function getHash(hash: CHash) { return { diff --git a/src/bls.ts b/src/abstract/bls.ts similarity index 99% rename from src/bls.ts rename to src/abstract/bls.ts index 4defb2c..13107ac 100644 --- a/src/bls.ts +++ b/src/abstract/bls.ts @@ -7,7 +7,7 @@ import { ensureBytes, numberToBytesBE, bytesToNumberBE, bitLen, bitGet } from '. import * as utils from './utils.js'; // Types import { hexToBytes, bytesToHex, Hex, PrivKey } from './utils.js'; -import { htfOpts, stringToBytes, hash_to_field, expand_message_xmd } from './hashToCurve.js'; +import { htfOpts, stringToBytes, hash_to_field, expand_message_xmd } from './hash-to-curve.js'; import { CurvePointsType, PointType, CurvePointsRes, weierstrassPoints } from './weierstrass.js'; type Fp = bigint; // Can be different field? diff --git a/src/edwards.ts b/src/abstract/edwards.ts similarity index 99% rename from src/edwards.ts rename to src/abstract/edwards.ts index 765355f..c8d16f3 100644 --- a/src/edwards.ts +++ b/src/abstract/edwards.ts @@ -23,7 +23,7 @@ import { PrivKey, } from './utils.js'; // TODO: import * as u from './utils.js'? import { Group, GroupConstructor, wNAF } from './group.js'; -import { hash_to_field, htfOpts, validateHTFOpts } from './hashToCurve.js'; +import { hash_to_field, htfOpts, validateHTFOpts } from './hash-to-curve.js'; // Be friendly to bad ECMAScript parsers by not using bigint literals like 123n const _0n = BigInt(0); diff --git a/src/group.ts b/src/abstract/group.ts similarity index 100% rename from src/group.ts rename to src/abstract/group.ts diff --git a/src/hashToCurve.ts b/src/abstract/hash-to-curve.ts similarity index 100% rename from src/hashToCurve.ts rename to src/abstract/hash-to-curve.ts diff --git a/src/modular.ts b/src/abstract/modular.ts similarity index 100% rename from src/modular.ts rename to src/abstract/modular.ts diff --git a/src/montgomery.ts b/src/abstract/montgomery.ts similarity index 100% rename from src/montgomery.ts rename to src/abstract/montgomery.ts diff --git a/src/utils.ts b/src/abstract/utils.ts similarity index 100% rename from src/utils.ts rename to src/abstract/utils.ts diff --git a/src/weierstrass.ts b/src/abstract/weierstrass.ts similarity index 99% rename from src/weierstrass.ts rename to src/abstract/weierstrass.ts index 466527f..3247b31 100644 --- a/src/weierstrass.ts +++ b/src/abstract/weierstrass.ts @@ -23,7 +23,7 @@ import { PrivKey, } from './utils.js'; import * as utils from './utils.js'; -import { hash_to_field, htfOpts, validateHTFOpts } from './hashToCurve.js'; +import { hash_to_field, htfOpts, validateHTFOpts } from './hash-to-curve.js'; import { Group, GroupConstructor, wNAF } from './group.js'; type HmacFnSync = (key: Uint8Array, ...messages: Uint8Array[]) => Uint8Array; diff --git a/curve-definitions/src/bls12-381.ts b/src/bls12-381.ts similarity index 98% rename from curve-definitions/src/bls12-381.ts rename to src/bls12-381.ts index 9f2daa8..68699ab 100644 --- a/curve-definitions/src/bls12-381.ts +++ b/src/bls12-381.ts @@ -1,7 +1,8 @@ +/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */ import { sha256 } from '@noble/hashes/sha256'; import { randomBytes } from '@noble/hashes/utils'; -import { bls, CurveFn } from '@noble/curves/bls'; -import * as mod from '@noble/curves/modular'; +import { bls, CurveFn } from './abstract/bls.js'; +import * as mod from './abstract/modular.js'; import { concatBytes, ensureBytes, @@ -12,15 +13,15 @@ import { bitGet, Hex, bitMask, -} from '@noble/curves/utils'; +} from './abstract/utils.js'; // Types import { PointType, ProjectivePointType, ProjectiveConstructor, mapToCurveSimpleSWU, -} from '@noble/curves/weierstrass'; -import { isogenyMap } from '@noble/curves/hashToCurve'; +} from './abstract/weierstrass.js'; +import { isogenyMap } from './abstract/hash-to-curve.js'; // Differences from bls12-381: // - PointG1 -> G1.Point @@ -202,14 +203,14 @@ const FP2_FROBENIUS_COEFFICIENTS = [ // For Fp2 roots of unity. const rv1 = 0x6af0e0437ff400b6831e36d6bd17ffe48395dabc2d3435e77f76e17009241c5ee67992f72ec05f4c81084fbede3cc09n; -const ev1 = - 0x699be3b8c6870965e5bf892ad5d2cc7b0e85a117402dfd83b7f4a947e02d978498255a2aaec0ac627b5afbdf1bf1c90n; -const ev2 = - 0x8157cd83046453f5dd0972b6e3949e4288020b5b8a9cc99ca07e27089a2ce2436d965026adad3ef7baba37f2183e9b5n; -const ev3 = - 0xab1c2ffdd6c253ca155231eb3e71ba044fd562f6f72bc5bad5ec46a0b7a3b0247cf08ce6c6317f40edbc653a72dee17n; -const ev4 = - 0xaa404866706722864480885d68ad0ccac1967c7544b447873cc37e0181271e006df72162a3d3e0287bf597fbf7f8fc1n; +// const ev1 = +// 0x699be3b8c6870965e5bf892ad5d2cc7b0e85a117402dfd83b7f4a947e02d978498255a2aaec0ac627b5afbdf1bf1c90n; +// const ev2 = +// 0x8157cd83046453f5dd0972b6e3949e4288020b5b8a9cc99ca07e27089a2ce2436d965026adad3ef7baba37f2183e9b5n; +// const ev3 = +// 0xab1c2ffdd6c253ca155231eb3e71ba044fd562f6f72bc5bad5ec46a0b7a3b0247cf08ce6c6317f40edbc653a72dee17n; +// const ev4 = +// 0xaa404866706722864480885d68ad0ccac1967c7544b447873cc37e0181271e006df72162a3d3e0287bf597fbf7f8fc1n; // Eighth roots of unity, used for computing square roots in Fp2. // To verify or re-calculate: @@ -225,12 +226,12 @@ const FP2_ROOTS_OF_UNITY = [ [-rv1, -rv1], ].map((pair) => Fp2.fromBigTuple(pair)); // eta values, used for computing sqrt(g(X1(t))) -const FP2_ETAs = [ - [ev1, ev2], - [-ev2, ev1], - [ev3, ev4], - [-ev4, ev3], -].map((pair) => Fp2.fromBigTuple(pair)); +// const FP2_ETAs = [ +// [ev1, ev2], +// [-ev2, ev1], +// [ev3, ev4], +// [-ev4, ev3], +// ].map((pair) => Fp2.fromBigTuple(pair)); // Finite extension field over irreducible polynominal. // Fp2(v) / (v³ - ξ) where ξ = u + 1 diff --git a/curve-definitions/src/bn.ts b/src/bn.ts similarity index 78% rename from curve-definitions/src/bn.ts rename to src/bn.ts index d8eda2a..935e52c 100644 --- a/curve-definitions/src/bn.ts +++ b/src/bn.ts @@ -1,8 +1,8 @@ -/*! @noble/curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */ -import { weierstrass } from '@noble/curves/weierstrass'; +/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */ +import { weierstrass } from './abstract/weierstrass.js'; import { sha256 } from '@noble/hashes/sha256'; import { getHash } from './_shortw_utils.js'; -import { Fp } from '@noble/curves/modular'; +import { Fp } from './abstract/modular.js'; /** * bn254 pairing-friendly curve. * Previously known as alt_bn_128, when it had 128-bit security. diff --git a/curve-definitions/src/ed25519.ts b/src/ed25519.ts similarity index 97% rename from curve-definitions/src/ed25519.ts rename to src/ed25519.ts index 69b9c45..cfc51d7 100644 --- a/curve-definitions/src/ed25519.ts +++ b/src/ed25519.ts @@ -1,9 +1,9 @@ -/*! @noble/curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */ +/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */ import { sha512 } from '@noble/hashes/sha512'; import { concatBytes, randomBytes, utf8ToBytes } from '@noble/hashes/utils'; -import { twistedEdwards, ExtendedPointType } from '@noble/curves/edwards'; -import { montgomery } from '@noble/curves/montgomery'; -import { mod, pow2, isNegativeLE, Fp as Field } from '@noble/curves/modular'; +import { twistedEdwards, ExtendedPointType } from './abstract/edwards.js'; +import { montgomery } from './abstract/montgomery.js'; +import { mod, pow2, isNegativeLE, Fp as Field } from './abstract/modular.js'; import { ensureBytes, equalBytes, @@ -11,7 +11,7 @@ import { bytesToNumberLE, numberToBytesLE, Hex, -} from '@noble/curves/utils'; +} from './abstract/utils.js'; /** * ed25519 Twisted Edwards curve with following addons: diff --git a/curve-definitions/src/ed448.ts b/src/ed448.ts similarity index 96% rename from curve-definitions/src/ed448.ts rename to src/ed448.ts index 76dd4cb..4ccb07d 100644 --- a/curve-definitions/src/ed448.ts +++ b/src/ed448.ts @@ -1,9 +1,9 @@ -/*! @noble/curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */ +/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */ import { shake256 } from '@noble/hashes/sha3'; import { concatBytes, randomBytes, utf8ToBytes, wrapConstructor } from '@noble/hashes/utils'; -import { twistedEdwards } from '@noble/curves/edwards'; -import { mod, pow2, Fp } from '@noble/curves/modular'; -import { montgomery } from '@noble/curves/montgomery'; +import { twistedEdwards } from './abstract/edwards.js'; +import { mod, pow2, Fp } from './abstract/modular.js'; +import { montgomery } from './abstract/montgomery.js'; /** * Edwards448 (not Ed448-Goldilocks) curve with following addons: diff --git a/curve-definitions/src/index.ts b/src/index.ts similarity index 100% rename from curve-definitions/src/index.ts rename to src/index.ts diff --git a/curve-definitions/src/jubjub.ts b/src/jubjub.ts similarity index 92% rename from curve-definitions/src/jubjub.ts rename to src/jubjub.ts index e6e48e3..f98dac6 100644 --- a/curve-definitions/src/jubjub.ts +++ b/src/jubjub.ts @@ -1,9 +1,9 @@ -/*! @noble/curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */ +/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */ import { sha256 } from '@noble/hashes/sha256'; import { concatBytes, randomBytes, utf8ToBytes } from '@noble/hashes/utils'; -import { twistedEdwards } from '@noble/curves/edwards'; +import { twistedEdwards } from './abstract/edwards.js'; import { blake2s } from '@noble/hashes/blake2s'; -import { Fp } from '@noble/curves/modular'; +import { Fp } from './abstract/modular.js'; /** * jubjub Twisted Edwards curve. diff --git a/curve-definitions/src/p192.ts b/src/p192.ts similarity index 89% rename from curve-definitions/src/p192.ts rename to src/p192.ts index 68238e8..11c41b7 100644 --- a/curve-definitions/src/p192.ts +++ b/src/p192.ts @@ -1,7 +1,7 @@ -/*! @noble/curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */ +/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */ import { createCurve } from './_shortw_utils.js'; import { sha256 } from '@noble/hashes/sha256'; -import { Fp } from '@noble/curves/modular'; +import { Fp } from './abstract/modular.js'; // NIST secp192r1 aka P192 // https://www.secg.org/sec2-v2.pdf, https://neuromancer.sk/std/secg/secp192r1 diff --git a/curve-definitions/src/p224.ts b/src/p224.ts similarity index 89% rename from curve-definitions/src/p224.ts rename to src/p224.ts index 4eebcc1..be4a34c 100644 --- a/curve-definitions/src/p224.ts +++ b/src/p224.ts @@ -1,7 +1,7 @@ -/*! @noble/curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */ +/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */ import { createCurve } from './_shortw_utils.js'; import { sha224 } from '@noble/hashes/sha256'; -import { Fp } from '@noble/curves/modular'; +import { Fp } from './abstract/modular.js'; // NIST secp224r1 aka P224 // https://www.secg.org/sec2-v2.pdf, https://neuromancer.sk/std/nist/P-224 diff --git a/curve-definitions/src/p256.ts b/src/p256.ts similarity index 88% rename from curve-definitions/src/p256.ts rename to src/p256.ts index ace546a..688d7f1 100644 --- a/curve-definitions/src/p256.ts +++ b/src/p256.ts @@ -1,8 +1,8 @@ -/*! @noble/curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */ +/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */ import { createCurve } from './_shortw_utils.js'; import { sha256 } from '@noble/hashes/sha256'; -import { Fp as Field } from '@noble/curves/modular'; -import { mapToCurveSimpleSWU } from '@noble/curves/weierstrass'; +import { Fp as Field } from './abstract/modular.js'; +import { mapToCurveSimpleSWU } from './abstract/weierstrass.js'; // NIST secp256r1 aka P256 // https://www.secg.org/sec2-v2.pdf, https://neuromancer.sk/std/nist/P-256 diff --git a/curve-definitions/src/p384.ts b/src/p384.ts similarity index 90% rename from curve-definitions/src/p384.ts rename to src/p384.ts index 0abdc12..41f940e 100644 --- a/curve-definitions/src/p384.ts +++ b/src/p384.ts @@ -1,8 +1,8 @@ -/*! @noble/curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */ +/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */ import { createCurve } from './_shortw_utils.js'; import { sha384 } from '@noble/hashes/sha512'; -import { Fp as Field } from '@noble/curves/modular'; -import { mapToCurveSimpleSWU } from '@noble/curves/weierstrass'; +import { Fp as Field } from './abstract/modular.js'; +import { mapToCurveSimpleSWU } from './abstract/weierstrass.js'; // NIST secp384r1 aka P384 // https://www.secg.org/sec2-v2.pdf, https://neuromancer.sk/std/nist/P-384 diff --git a/curve-definitions/src/p521.ts b/src/p521.ts similarity index 90% rename from curve-definitions/src/p521.ts rename to src/p521.ts index 1bf89d7..5111f48 100644 --- a/curve-definitions/src/p521.ts +++ b/src/p521.ts @@ -1,9 +1,9 @@ -/*! @noble/curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */ +/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */ import { createCurve } from './_shortw_utils.js'; import { sha512 } from '@noble/hashes/sha512'; -import { bytesToHex, PrivKey } from '@noble/curves/utils'; -import { Fp as Field } from '@noble/curves/modular'; -import { mapToCurveSimpleSWU } from '@noble/curves/weierstrass'; +import { bytesToHex, PrivKey } from './abstract/utils.js'; +import { Fp as Field } from './abstract/modular.js'; +import { mapToCurveSimpleSWU } from './abstract/weierstrass.js'; // NIST secp521r1 aka P521 // Note that it's 521, which differs from 512 of its hash function. diff --git a/curve-definitions/src/pasta.ts b/src/pasta.ts similarity index 80% rename from curve-definitions/src/pasta.ts rename to src/pasta.ts index 4b02eab..1f7c8e1 100644 --- a/curve-definitions/src/pasta.ts +++ b/src/pasta.ts @@ -1,8 +1,8 @@ -/*! @noble/curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */ +/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */ import { sha256 } from '@noble/hashes/sha256'; -import { weierstrass } from '@noble/curves/weierstrass'; +import { weierstrass } from './abstract/weierstrass.js'; import { getHash } from './_shortw_utils.js'; -import * as mod from '@noble/curves/modular'; +import * as mod from './abstract/modular.js'; export const p = BigInt('0x40000000000000000000000000000000224698fc094cf91b992d30ed00000001'); export const q = BigInt('0x40000000000000000000000000000000224698fc0994a8dd8c46eb2100000001'); diff --git a/curve-definitions/src/secp256k1.ts b/src/secp256k1.ts similarity index 97% rename from curve-definitions/src/secp256k1.ts rename to src/secp256k1.ts index 28f0d9a..66bfa6f 100644 --- a/curve-definitions/src/secp256k1.ts +++ b/src/secp256k1.ts @@ -1,8 +1,8 @@ -/*! @noble/curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */ +/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */ import { sha256 } from '@noble/hashes/sha256'; -import { Fp as Field, mod, pow2 } from '@noble/curves/modular'; +import { Fp as Field, mod, pow2 } from './abstract/modular.js'; import { createCurve } from './_shortw_utils.js'; -import { PointType, mapToCurveSimpleSWU } from '@noble/curves/weierstrass'; +import { PointType, mapToCurveSimpleSWU } from './abstract/weierstrass.js'; import { ensureBytes, concatBytes, @@ -10,9 +10,9 @@ import { hexToBytes, bytesToNumberBE, PrivKey, -} from '@noble/curves/utils'; +} from './abstract/utils.js'; import { randomBytes } from '@noble/hashes/utils'; -import { isogenyMap } from '@noble/curves/hashToCurve'; +import { isogenyMap } from './abstract/hash-to-curve.js'; /** * secp256k1 belongs to Koblitz curves: it has diff --git a/curve-definitions/src/stark.ts b/src/stark.ts similarity index 96% rename from curve-definitions/src/stark.ts rename to src/stark.ts index cc86a74..5d81c67 100644 --- a/curve-definitions/src/stark.ts +++ b/src/stark.ts @@ -1,11 +1,9 @@ -/*! @noble/curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */ +/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */ import { keccak_256 } from '@noble/hashes/sha3'; import { sha256 } from '@noble/hashes/sha256'; -import { hmac } from '@noble/hashes/hmac'; -import { concatBytes, randomBytes } from '@noble/hashes/utils'; -import { weierstrass, ProjectivePointType } from '@noble/curves/weierstrass'; -import * as cutils from '@noble/curves/utils'; -import { Fp } from '@noble/curves/modular'; +import { weierstrass, ProjectivePointType } from './abstract/weierstrass.js'; +import * as cutils from './abstract/utils.js'; +import { Fp } from './abstract/modular.js'; import { getHash } from './_shortw_utils.js'; type ProjectivePoint = ProjectivePointType; diff --git a/curve-definitions/test/basic.test.js b/test/basic.test.js similarity index 94% rename from curve-definitions/test/basic.test.js rename to test/basic.test.js index 6ff38c7..a6a5961 100644 --- a/curve-definitions/test/basic.test.js +++ b/test/basic.test.js @@ -1,21 +1,20 @@ import { deepStrictEqual, throws } from 'assert'; import { should } from 'micro-should'; import * as fc from 'fast-check'; -import * as mod from '@noble/curves/modular'; -import { randomBytes } from '@noble/hashes/utils'; +import * as mod from '../lib/esm/abstract/modular.js'; // Generic tests for all curves in package -import { secp192r1 } from '../lib/p192.js'; -import { secp224r1 } from '../lib/p224.js'; -import { secp256r1 } from '../lib/p256.js'; -import { secp384r1 } from '../lib/p384.js'; -import { secp521r1 } from '../lib/p521.js'; -import { secp256k1 } from '../lib/secp256k1.js'; -import { ed25519, ed25519ctx, ed25519ph } from '../lib/ed25519.js'; -import { ed448, ed448ph } from '../lib/ed448.js'; -import { starkCurve } from '../lib/stark.js'; -import { pallas, vesta } from '../lib/pasta.js'; -import { bn254 } from '../lib/bn.js'; -import { jubjub } from '../lib/jubjub.js'; +import { secp192r1 } from '../lib/esm/p192.js'; +import { secp224r1 } from '../lib/esm/p224.js'; +import { secp256r1 } from '../lib/esm/p256.js'; +import { secp384r1 } from '../lib/esm/p384.js'; +import { secp521r1 } from '../lib/esm/p521.js'; +import { secp256k1 } from '../lib/esm/secp256k1.js'; +import { ed25519, ed25519ctx, ed25519ph } from '../lib/esm/ed25519.js'; +import { ed448, ed448ph } from '../lib/esm/ed448.js'; +import { starkCurve } from '../lib/esm/stark.js'; +import { pallas, vesta } from '../lib/esm/pasta.js'; +import { bn254 } from '../lib/esm/bn.js'; +import { jubjub } from '../lib/esm/jubjub.js'; // prettier-ignore const CURVES = { diff --git a/curve-definitions/test/bls12-381.test.js b/test/bls12-381.test.js similarity index 99% rename from curve-definitions/test/bls12-381.test.js rename to test/bls12-381.test.js index 4fcee43..884df4a 100644 --- a/curve-definitions/test/bls12-381.test.js +++ b/test/bls12-381.test.js @@ -1,4 +1,4 @@ -import { bls12_381 } from '../lib/bls12-381.js'; +import { bls12_381 } from '../lib/esm/bls12-381.js'; import { should } from 'micro-should'; import { deepStrictEqual, notDeepStrictEqual, throws } from 'assert'; import { sha512 } from '@noble/hashes/sha512'; @@ -6,7 +6,7 @@ import * as fc from 'fast-check'; import { readFileSync } from 'fs'; import zkVectors from './bls12-381/zkcrypto/converted.json' assert { type: 'json' }; import pairingVectors from './bls12-381/go_pairing_vectors/pairing.json' assert { type: 'json' }; -import { wNAF } from '@noble/curves/group'; +import { wNAF } from '../lib/esm/abstract/group.js'; const bls = bls12_381; const { Fp2 } = bls; diff --git a/curve-definitions/test/bls12-381/bls12-381-g2-test-vectors.txt b/test/bls12-381/bls12-381-g2-test-vectors.txt similarity index 100% rename from curve-definitions/test/bls12-381/bls12-381-g2-test-vectors.txt rename to test/bls12-381/bls12-381-g2-test-vectors.txt diff --git a/curve-definitions/test/bls12-381/bls12-381-scalar-test-vectors.txt b/test/bls12-381/bls12-381-scalar-test-vectors.txt similarity index 100% rename from curve-definitions/test/bls12-381/bls12-381-scalar-test-vectors.txt rename to test/bls12-381/bls12-381-scalar-test-vectors.txt diff --git a/curve-definitions/test/bls12-381/go_pairing_vectors/go.mod b/test/bls12-381/go_pairing_vectors/go.mod similarity index 100% rename from curve-definitions/test/bls12-381/go_pairing_vectors/go.mod rename to test/bls12-381/go_pairing_vectors/go.mod diff --git a/curve-definitions/test/bls12-381/go_pairing_vectors/go.sum b/test/bls12-381/go_pairing_vectors/go.sum similarity index 100% rename from curve-definitions/test/bls12-381/go_pairing_vectors/go.sum rename to test/bls12-381/go_pairing_vectors/go.sum diff --git a/curve-definitions/test/bls12-381/go_pairing_vectors/pairing.json b/test/bls12-381/go_pairing_vectors/pairing.json similarity index 100% rename from curve-definitions/test/bls12-381/go_pairing_vectors/pairing.json rename to test/bls12-381/go_pairing_vectors/pairing.json diff --git a/curve-definitions/test/bls12-381/go_pairing_vectors/t.go b/test/bls12-381/go_pairing_vectors/t.go similarity index 100% rename from curve-definitions/test/bls12-381/go_pairing_vectors/t.go rename to test/bls12-381/go_pairing_vectors/t.go diff --git a/curve-definitions/test/bls12-381/zkcrypto/convert.js b/test/bls12-381/zkcrypto/convert.js similarity index 100% rename from curve-definitions/test/bls12-381/zkcrypto/convert.js rename to test/bls12-381/zkcrypto/convert.js diff --git a/curve-definitions/test/bls12-381/zkcrypto/converted.json b/test/bls12-381/zkcrypto/converted.json similarity index 100% rename from curve-definitions/test/bls12-381/zkcrypto/converted.json rename to test/bls12-381/zkcrypto/converted.json diff --git a/curve-definitions/test/bls12-381/zkcrypto/g1_compressed_valid_test_vectors.dat b/test/bls12-381/zkcrypto/g1_compressed_valid_test_vectors.dat similarity index 100% rename from curve-definitions/test/bls12-381/zkcrypto/g1_compressed_valid_test_vectors.dat rename to test/bls12-381/zkcrypto/g1_compressed_valid_test_vectors.dat diff --git a/curve-definitions/test/bls12-381/zkcrypto/g1_uncompressed_valid_test_vectors.dat b/test/bls12-381/zkcrypto/g1_uncompressed_valid_test_vectors.dat similarity index 100% rename from curve-definitions/test/bls12-381/zkcrypto/g1_uncompressed_valid_test_vectors.dat rename to test/bls12-381/zkcrypto/g1_uncompressed_valid_test_vectors.dat diff --git a/curve-definitions/test/bls12-381/zkcrypto/g2_compressed_valid_test_vectors.dat b/test/bls12-381/zkcrypto/g2_compressed_valid_test_vectors.dat similarity index 100% rename from curve-definitions/test/bls12-381/zkcrypto/g2_compressed_valid_test_vectors.dat rename to test/bls12-381/zkcrypto/g2_compressed_valid_test_vectors.dat diff --git a/curve-definitions/test/bls12-381/zkcrypto/g2_uncompressed_valid_test_vectors.dat b/test/bls12-381/zkcrypto/g2_uncompressed_valid_test_vectors.dat similarity index 100% rename from curve-definitions/test/bls12-381/zkcrypto/g2_uncompressed_valid_test_vectors.dat rename to test/bls12-381/zkcrypto/g2_uncompressed_valid_test_vectors.dat diff --git a/curve-definitions/test/ed25519.test.js b/test/ed25519.test.js similarity index 99% rename from curve-definitions/test/ed25519.test.js rename to test/ed25519.test.js index 6508d2d..915f808 100644 --- a/curve-definitions/test/ed25519.test.js +++ b/test/ed25519.test.js @@ -1,11 +1,11 @@ import { deepStrictEqual, throws } from 'assert'; import { should } from 'micro-should'; import * as fc from 'fast-check'; -import { ed25519, ed25519ctx, ed25519ph, x25519, RistrettoPoint } from '../lib/ed25519.js'; +import { ed25519, ed25519ctx, ed25519ph, x25519, RistrettoPoint } from '../lib/esm/ed25519.js'; import { readFileSync } from 'fs'; import { default as zip215 } from './ed25519/zip215.json' assert { type: 'json' }; import { hexToBytes, bytesToHex, randomBytes } from '@noble/hashes/utils'; -import { numberToBytesLE } from '@noble/curves/utils'; +import { numberToBytesLE } from '../lib/esm/abstract/utils.js'; import { sha512 } from '@noble/hashes/sha512'; import { default as ed25519vectors } from './wycheproof/eddsa_test.json' assert { type: 'json' }; import { default as x25519vectors } from './wycheproof/x25519_test.json' assert { type: 'json' }; diff --git a/curve-definitions/test/ed25519/vectors.txt b/test/ed25519/vectors.txt similarity index 100% rename from curve-definitions/test/ed25519/vectors.txt rename to test/ed25519/vectors.txt diff --git a/curve-definitions/test/ed25519/zip215.json b/test/ed25519/zip215.json similarity index 100% rename from curve-definitions/test/ed25519/zip215.json rename to test/ed25519/zip215.json diff --git a/curve-definitions/test/ed448.test.js b/test/ed448.test.js similarity index 99% rename from curve-definitions/test/ed448.test.js rename to test/ed448.test.js index b7938d3..c19c823 100644 --- a/curve-definitions/test/ed448.test.js +++ b/test/ed448.test.js @@ -1,9 +1,9 @@ import { deepStrictEqual, throws } from 'assert'; import { should } from 'micro-should'; import * as fc from 'fast-check'; -import { ed448, ed448ph, x448 } from '../lib/ed448.js'; +import { ed448, ed448ph, x448 } from '../lib/esm/ed448.js'; import { hexToBytes, bytesToHex, randomBytes } from '@noble/hashes/utils'; -import { numberToBytesLE } from '@noble/curves/utils'; +import { numberToBytesLE } from '../lib/esm/abstract/utils.js'; import { default as ed448vectors } from './wycheproof/ed448_test.json' assert { type: 'json' }; import { default as x448vectors } from './wycheproof/x448_test.json' assert { type: 'json' }; diff --git a/curve-definitions/test/fixtures/rfc6979.json b/test/fixtures/rfc6979.json similarity index 100% rename from curve-definitions/test/fixtures/rfc6979.json rename to test/fixtures/rfc6979.json diff --git a/test/hash-to-curve.test.js b/test/hash-to-curve.test.js new file mode 100644 index 0000000..446a4a4 --- /dev/null +++ b/test/hash-to-curve.test.js @@ -0,0 +1,107 @@ +import { deepStrictEqual } from 'assert'; +import { should } from 'micro-should'; +import { bytesToHex } from '@noble/hashes/utils'; +// Generic tests for all curves in package +import { sha256 } from '@noble/hashes/sha256'; +import { sha512 } from '@noble/hashes/sha512'; +import { secp256r1 } from '../lib/esm/p256.js'; +import { secp384r1 } from '../lib/esm/p384.js'; +import { secp521r1 } from '../lib/esm/p521.js'; +import { secp256k1 } from '../lib/esm/secp256k1.js'; +import { bls12_381 } from '../lib/esm/bls12-381.js'; +import { stringToBytes, expand_message_xmd } from '../lib/esm/abstract/hash-to-curve.js'; + +import { default as xmd_sha256_38 } from './hash-to-curve/expand_message_xmd_SHA256_38.json' assert { type: 'json' }; +import { default as xmd_sha256_256 } from './hash-to-curve/expand_message_xmd_SHA256_256.json' assert { type: 'json' }; +import { default as xmd_sha512_38 } from './hash-to-curve/expand_message_xmd_SHA512_38.json' assert { type: 'json' }; +// P256 +import { default as p256_ro } from './hash-to-curve/P256_XMD:SHA-256_SSWU_RO_.json' assert { type: 'json' }; +import { default as p256_nu } from './hash-to-curve/P256_XMD:SHA-256_SSWU_NU_.json' assert { type: 'json' }; +// P384 +import { default as p384_ro } from './hash-to-curve/P384_XMD:SHA-384_SSWU_RO_.json' assert { type: 'json' }; +import { default as p384_nu } from './hash-to-curve/P384_XMD:SHA-384_SSWU_NU_.json' assert { type: 'json' }; +// P521 +import { default as p521_ro } from './hash-to-curve/P521_XMD:SHA-512_SSWU_RO_.json' assert { type: 'json' }; +import { default as p521_nu } from './hash-to-curve/P521_XMD:SHA-512_SSWU_NU_.json' assert { type: 'json' }; +// secp256k1 +import { default as secp256k1_ro } from './hash-to-curve/secp256k1_XMD:SHA-256_SSWU_RO_.json' assert { type: 'json' }; +import { default as secp256k1_nu } from './hash-to-curve/secp256k1_XMD:SHA-256_SSWU_NU_.json' assert { type: 'json' }; +// bls-G1 +import { default as g1_ro } from './hash-to-curve/BLS12381G1_XMD:SHA-256_SSWU_RO_.json' assert { type: 'json' }; +import { default as g1_nu } from './hash-to-curve/BLS12381G1_XMD:SHA-256_SSWU_NU_.json' assert { type: 'json' }; +// bls-G2 +import { default as g2_ro } from './hash-to-curve/BLS12381G2_XMD:SHA-256_SSWU_RO_.json' assert { type: 'json' }; +import { default as g2_nu } from './hash-to-curve/BLS12381G2_XMD:SHA-256_SSWU_NU_.json' assert { type: 'json' }; +// ed25519 +import { default as ed25519_ro } from './hash-to-curve/edwards25519_XMD:SHA-512_ELL2_RO_.json' assert { type: 'json' }; +import { default as ed25519_nu } from './hash-to-curve/edwards25519_XMD:SHA-512_ELL2_NU_.json' assert { type: 'json' }; +// ed448 +import { default as ed448_ro } from './hash-to-curve/edwards448_XOF:SHAKE256_ELL2_RO_.json' assert { type: 'json' }; +import { default as ed448_nu } from './hash-to-curve/edwards448_XOF:SHAKE256_ELL2_NU_.json' assert { type: 'json' }; + +function testExpandXMD(hash, vectors) { + for (let i = 0; i < vectors.tests.length; i++) { + const t = vectors.tests[i]; + should(`expand_message_xmd/${vectors.hash}/${vectors.DST.length}/${i}`, () => { + const p = expand_message_xmd( + stringToBytes(t.msg), + stringToBytes(vectors.DST), + t.len_in_bytes, + hash + ); + deepStrictEqual(bytesToHex(p), t.uniform_bytes); + }); + } +} + +testExpandXMD(sha256, xmd_sha256_38); +testExpandXMD(sha256, xmd_sha256_256); +testExpandXMD(sha512, xmd_sha512_38); + +function stringToFp(s) { + // bls-G2 support + if (s.includes(',')) { + const [c0, c1] = s.split(',').map(BigInt); + return { c0, c1 }; + } + return BigInt(s); +} + +function testCurve(curve, ro, nu) { + for (let i = 0; i < ro.vectors.length; i++) { + const t = ro.vectors[i]; + should(`${ro.curve}/${ro.ciphersuite}(${i})`, () => { + const p = curve.Point.hashToCurve(stringToBytes(t.msg), { + DST: ro.dst, + }); + deepStrictEqual(p.x, stringToFp(t.P.x), 'Px'); + deepStrictEqual(p.y, stringToFp(t.P.y), 'Py'); + }); + } + for (let i = 0; i < nu.vectors.length; i++) { + const t = nu.vectors[i]; + should(`${nu.curve}/${nu.ciphersuite}(${i})`, () => { + const p = curve.Point.encodeToCurve(stringToBytes(t.msg), { + DST: nu.dst, + }); + deepStrictEqual(p.x, stringToFp(t.P.x), 'Px'); + deepStrictEqual(p.y, stringToFp(t.P.y), 'Py'); + }); + } +} + +testCurve(secp256r1, p256_ro, p256_nu); +testCurve(secp384r1, p384_ro, p384_nu); +testCurve(secp521r1, p521_ro, p521_nu); +// TODO: remove same tests from bls12 +testCurve(bls12_381.G1, g1_ro, g1_nu); +testCurve(bls12_381.G2, g2_ro, g2_nu); +testCurve(secp256k1, secp256k1_ro, secp256k1_nu); +//testCurve(ed25519, ed25519_ro, ed25519_nu); +//testCurve(ed448, ed448_ro, ed448_nu); + +// ESM is broken. +import url from 'url'; +if (import.meta.url === url.pathToFileURL(process.argv[1]).href) { + should.run(); +} diff --git a/curve-definitions/test/hashToCurve/BLS12381G1_XMD:SHA-256_SSWU_NU_.json b/test/hash-to-curve/BLS12381G1_XMD:SHA-256_SSWU_NU_.json similarity index 100% rename from curve-definitions/test/hashToCurve/BLS12381G1_XMD:SHA-256_SSWU_NU_.json rename to test/hash-to-curve/BLS12381G1_XMD:SHA-256_SSWU_NU_.json diff --git a/curve-definitions/test/hashToCurve/BLS12381G1_XMD:SHA-256_SSWU_RO_.json b/test/hash-to-curve/BLS12381G1_XMD:SHA-256_SSWU_RO_.json similarity index 100% rename from curve-definitions/test/hashToCurve/BLS12381G1_XMD:SHA-256_SSWU_RO_.json rename to test/hash-to-curve/BLS12381G1_XMD:SHA-256_SSWU_RO_.json diff --git a/curve-definitions/test/hashToCurve/BLS12381G2_XMD:SHA-256_SSWU_NU_.json b/test/hash-to-curve/BLS12381G2_XMD:SHA-256_SSWU_NU_.json similarity index 100% rename from curve-definitions/test/hashToCurve/BLS12381G2_XMD:SHA-256_SSWU_NU_.json rename to test/hash-to-curve/BLS12381G2_XMD:SHA-256_SSWU_NU_.json diff --git a/curve-definitions/test/hashToCurve/BLS12381G2_XMD:SHA-256_SSWU_RO_.json b/test/hash-to-curve/BLS12381G2_XMD:SHA-256_SSWU_RO_.json similarity index 100% rename from curve-definitions/test/hashToCurve/BLS12381G2_XMD:SHA-256_SSWU_RO_.json rename to test/hash-to-curve/BLS12381G2_XMD:SHA-256_SSWU_RO_.json diff --git a/curve-definitions/test/hashToCurve/P256_XMD:SHA-256_SSWU_NU_.json b/test/hash-to-curve/P256_XMD:SHA-256_SSWU_NU_.json similarity index 100% rename from curve-definitions/test/hashToCurve/P256_XMD:SHA-256_SSWU_NU_.json rename to test/hash-to-curve/P256_XMD:SHA-256_SSWU_NU_.json diff --git a/curve-definitions/test/hashToCurve/P256_XMD:SHA-256_SSWU_RO_.json b/test/hash-to-curve/P256_XMD:SHA-256_SSWU_RO_.json similarity index 100% rename from curve-definitions/test/hashToCurve/P256_XMD:SHA-256_SSWU_RO_.json rename to test/hash-to-curve/P256_XMD:SHA-256_SSWU_RO_.json diff --git a/curve-definitions/test/hashToCurve/P384_XMD:SHA-384_SSWU_NU_.json b/test/hash-to-curve/P384_XMD:SHA-384_SSWU_NU_.json similarity index 100% rename from curve-definitions/test/hashToCurve/P384_XMD:SHA-384_SSWU_NU_.json rename to test/hash-to-curve/P384_XMD:SHA-384_SSWU_NU_.json diff --git a/curve-definitions/test/hashToCurve/P384_XMD:SHA-384_SSWU_RO_.json b/test/hash-to-curve/P384_XMD:SHA-384_SSWU_RO_.json similarity index 100% rename from curve-definitions/test/hashToCurve/P384_XMD:SHA-384_SSWU_RO_.json rename to test/hash-to-curve/P384_XMD:SHA-384_SSWU_RO_.json diff --git a/curve-definitions/test/hashToCurve/P521_XMD:SHA-512_SSWU_NU_.json b/test/hash-to-curve/P521_XMD:SHA-512_SSWU_NU_.json similarity index 100% rename from curve-definitions/test/hashToCurve/P521_XMD:SHA-512_SSWU_NU_.json rename to test/hash-to-curve/P521_XMD:SHA-512_SSWU_NU_.json diff --git a/curve-definitions/test/hashToCurve/P521_XMD:SHA-512_SSWU_RO_.json b/test/hash-to-curve/P521_XMD:SHA-512_SSWU_RO_.json similarity index 100% rename from curve-definitions/test/hashToCurve/P521_XMD:SHA-512_SSWU_RO_.json rename to test/hash-to-curve/P521_XMD:SHA-512_SSWU_RO_.json diff --git a/curve-definitions/test/hashToCurve/curve25519_XMD:SHA-512_ELL2_NU_.json b/test/hash-to-curve/curve25519_XMD:SHA-512_ELL2_NU_.json similarity index 100% rename from curve-definitions/test/hashToCurve/curve25519_XMD:SHA-512_ELL2_NU_.json rename to test/hash-to-curve/curve25519_XMD:SHA-512_ELL2_NU_.json diff --git a/curve-definitions/test/hashToCurve/curve25519_XMD:SHA-512_ELL2_RO_.json b/test/hash-to-curve/curve25519_XMD:SHA-512_ELL2_RO_.json similarity index 100% rename from curve-definitions/test/hashToCurve/curve25519_XMD:SHA-512_ELL2_RO_.json rename to test/hash-to-curve/curve25519_XMD:SHA-512_ELL2_RO_.json diff --git a/curve-definitions/test/hashToCurve/curve448_XOF:SHAKE256_ELL2_NU_.json b/test/hash-to-curve/curve448_XOF:SHAKE256_ELL2_NU_.json similarity index 100% rename from curve-definitions/test/hashToCurve/curve448_XOF:SHAKE256_ELL2_NU_.json rename to test/hash-to-curve/curve448_XOF:SHAKE256_ELL2_NU_.json diff --git a/curve-definitions/test/hashToCurve/curve448_XOF:SHAKE256_ELL2_RO_.json b/test/hash-to-curve/curve448_XOF:SHAKE256_ELL2_RO_.json similarity index 100% rename from curve-definitions/test/hashToCurve/curve448_XOF:SHAKE256_ELL2_RO_.json rename to test/hash-to-curve/curve448_XOF:SHAKE256_ELL2_RO_.json diff --git a/curve-definitions/test/hashToCurve/edwards25519_XMD:SHA-512_ELL2_NU_.json b/test/hash-to-curve/edwards25519_XMD:SHA-512_ELL2_NU_.json similarity index 100% rename from curve-definitions/test/hashToCurve/edwards25519_XMD:SHA-512_ELL2_NU_.json rename to test/hash-to-curve/edwards25519_XMD:SHA-512_ELL2_NU_.json diff --git a/curve-definitions/test/hashToCurve/edwards25519_XMD:SHA-512_ELL2_RO_.json b/test/hash-to-curve/edwards25519_XMD:SHA-512_ELL2_RO_.json similarity index 100% rename from curve-definitions/test/hashToCurve/edwards25519_XMD:SHA-512_ELL2_RO_.json rename to test/hash-to-curve/edwards25519_XMD:SHA-512_ELL2_RO_.json diff --git a/curve-definitions/test/hashToCurve/edwards448_XOF:SHAKE256_ELL2_NU_.json b/test/hash-to-curve/edwards448_XOF:SHAKE256_ELL2_NU_.json similarity index 100% rename from curve-definitions/test/hashToCurve/edwards448_XOF:SHAKE256_ELL2_NU_.json rename to test/hash-to-curve/edwards448_XOF:SHAKE256_ELL2_NU_.json diff --git a/curve-definitions/test/hashToCurve/edwards448_XOF:SHAKE256_ELL2_RO_.json b/test/hash-to-curve/edwards448_XOF:SHAKE256_ELL2_RO_.json similarity index 100% rename from curve-definitions/test/hashToCurve/edwards448_XOF:SHAKE256_ELL2_RO_.json rename to test/hash-to-curve/edwards448_XOF:SHAKE256_ELL2_RO_.json diff --git a/curve-definitions/test/hashToCurve/expand_message_xmd_SHA256_256.json b/test/hash-to-curve/expand_message_xmd_SHA256_256.json similarity index 100% rename from curve-definitions/test/hashToCurve/expand_message_xmd_SHA256_256.json rename to test/hash-to-curve/expand_message_xmd_SHA256_256.json diff --git a/curve-definitions/test/hashToCurve/expand_message_xmd_SHA256_38.json b/test/hash-to-curve/expand_message_xmd_SHA256_38.json similarity index 100% rename from curve-definitions/test/hashToCurve/expand_message_xmd_SHA256_38.json rename to test/hash-to-curve/expand_message_xmd_SHA256_38.json diff --git a/curve-definitions/test/hashToCurve/expand_message_xmd_SHA512_38.json b/test/hash-to-curve/expand_message_xmd_SHA512_38.json similarity index 100% rename from curve-definitions/test/hashToCurve/expand_message_xmd_SHA512_38.json rename to test/hash-to-curve/expand_message_xmd_SHA512_38.json diff --git a/curve-definitions/test/hashToCurve/expand_message_xof_SHAKE128_256.json b/test/hash-to-curve/expand_message_xof_SHAKE128_256.json similarity index 100% rename from curve-definitions/test/hashToCurve/expand_message_xof_SHAKE128_256.json rename to test/hash-to-curve/expand_message_xof_SHAKE128_256.json diff --git a/curve-definitions/test/hashToCurve/expand_message_xof_SHAKE128_36.json b/test/hash-to-curve/expand_message_xof_SHAKE128_36.json similarity index 100% rename from curve-definitions/test/hashToCurve/expand_message_xof_SHAKE128_36.json rename to test/hash-to-curve/expand_message_xof_SHAKE128_36.json diff --git a/curve-definitions/test/hashToCurve/expand_message_xof_SHAKE256_36.json b/test/hash-to-curve/expand_message_xof_SHAKE256_36.json similarity index 100% rename from curve-definitions/test/hashToCurve/expand_message_xof_SHAKE256_36.json rename to test/hash-to-curve/expand_message_xof_SHAKE256_36.json diff --git a/curve-definitions/test/hashToCurve/secp256k1_XMD:SHA-256_SSWU_NU_.json b/test/hash-to-curve/secp256k1_XMD:SHA-256_SSWU_NU_.json similarity index 100% rename from curve-definitions/test/hashToCurve/secp256k1_XMD:SHA-256_SSWU_NU_.json rename to test/hash-to-curve/secp256k1_XMD:SHA-256_SSWU_NU_.json diff --git a/curve-definitions/test/hashToCurve/secp256k1_XMD:SHA-256_SSWU_RO_.json b/test/hash-to-curve/secp256k1_XMD:SHA-256_SSWU_RO_.json similarity index 100% rename from curve-definitions/test/hashToCurve/secp256k1_XMD:SHA-256_SSWU_RO_.json rename to test/hash-to-curve/secp256k1_XMD:SHA-256_SSWU_RO_.json diff --git a/curve-definitions/test/index.test.js b/test/index.test.js similarity index 90% rename from curve-definitions/test/index.test.js rename to test/index.test.js index dd65799..aa4be0b 100644 --- a/curve-definitions/test/index.test.js +++ b/test/index.test.js @@ -9,6 +9,6 @@ import './secp256k1.test.js'; import './stark/stark.test.js'; import './jubjub.test.js'; import './bls12-381.test.js'; -import './hashToCurve.test.js'; +import './hash-to-curve.test.js'; should.run(); diff --git a/curve-definitions/test/jubjub.test.js b/test/jubjub.test.js similarity index 97% rename from curve-definitions/test/jubjub.test.js rename to test/jubjub.test.js index 2b12fcb..dd42027 100644 --- a/curve-definitions/test/jubjub.test.js +++ b/test/jubjub.test.js @@ -1,4 +1,4 @@ -import { jubjub, findGroupHash } from '../lib/jubjub.js'; +import { jubjub, findGroupHash } from '../lib/esm/jubjub.js'; import { should } from 'micro-should'; import { deepStrictEqual, throws } from 'assert'; import { hexToBytes, bytesToHex } from '@noble/hashes/utils'; diff --git a/curve-definitions/test/nist.test.js b/test/nist.test.js similarity index 97% rename from curve-definitions/test/nist.test.js rename to test/nist.test.js index 88dc2ed..d56325a 100644 --- a/curve-definitions/test/nist.test.js +++ b/test/nist.test.js @@ -1,12 +1,12 @@ import { deepStrictEqual, throws } from 'assert'; import { should } from 'micro-should'; -import { secp192r1, P192 } from '../lib/p192.js'; -import { secp224r1, P224 } from '../lib/p224.js'; -import { secp256r1, P256 } from '../lib/p256.js'; -import { secp384r1, P384 } from '../lib/p384.js'; -import { secp521r1, P521 } from '../lib/p521.js'; -import { secp256k1 } from '../lib/secp256k1.js'; -import { hexToBytes, bytesToHex } from '@noble/curves/utils'; +import { secp192r1, P192 } from '../lib/esm/p192.js'; +import { secp224r1, P224 } from '../lib/esm/p224.js'; +import { secp256r1, P256 } from '../lib/esm/p256.js'; +import { secp384r1, P384 } from '../lib/esm/p384.js'; +import { secp521r1, P521 } from '../lib/esm/p521.js'; +import { secp256k1 } from '../lib/esm/secp256k1.js'; +import { hexToBytes, bytesToHex } from '../lib/esm/abstract/utils.js'; import { default as ecdsa } from './wycheproof/ecdsa_test.json' assert { type: 'json' }; import { default as ecdh } from './wycheproof/ecdh_test.json' assert { type: 'json' }; import { default as rfc6979 } from './fixtures/rfc6979.json' assert { type: 'json' }; diff --git a/curve-definitions/lib/esm/package.json b/test/package.json similarity index 100% rename from curve-definitions/lib/esm/package.json rename to test/package.json diff --git a/curve-definitions/test/secp256k1.test.js b/test/secp256k1.test.js similarity index 99% rename from curve-definitions/test/secp256k1.test.js rename to test/secp256k1.test.js index 65152eb..0767c59 100644 --- a/curve-definitions/test/secp256k1.test.js +++ b/test/secp256k1.test.js @@ -1,5 +1,5 @@ import * as fc from 'fast-check'; -import { secp256k1, schnorr } from '../lib/secp256k1.js'; +import { secp256k1, schnorr } from '../lib/esm/secp256k1.js'; import { readFileSync } from 'fs'; import { default as ecdsa } from './vectors/ecdsa.json' assert { type: 'json' }; import { default as ecdh } from './vectors/ecdh.json' assert { type: 'json' }; diff --git a/curve-definitions/test/stark/basic.test.js b/test/stark/basic.test.js similarity index 99% rename from curve-definitions/test/stark/basic.test.js rename to test/stark/basic.test.js index 3b6e43d..e60cd89 100644 --- a/curve-definitions/test/stark/basic.test.js +++ b/test/stark/basic.test.js @@ -1,6 +1,6 @@ import { deepStrictEqual, throws } from 'assert'; import { should } from 'micro-should'; -import * as starknet from '../../lib/stark.js'; +import * as starknet from '../../lib/esm/stark.js'; import { default as issue2 } from './fixtures/issue2.json' assert { type: 'json' }; should('Basic elliptic sanity check', () => { diff --git a/curve-definitions/test/stark/benchmark/index.js b/test/stark/benchmark/index.js similarity index 96% rename from curve-definitions/test/stark/benchmark/index.js rename to test/stark/benchmark/index.js index ba54240..4f3d3ca 100644 --- a/curve-definitions/test/stark/benchmark/index.js +++ b/test/stark/benchmark/index.js @@ -1,4 +1,4 @@ -import * as microStark from '../../../lib/stark.js'; +import * as microStark from '../../../lib/esm/stark.js'; import * as starkwareCrypto from '@starkware-industries/starkware-crypto-utils'; import * as bench from 'micro-bmark'; const { run, mark } = bench; // or bench.mark diff --git a/curve-definitions/test/stark/benchmark/package.json b/test/stark/benchmark/package.json similarity index 100% rename from curve-definitions/test/stark/benchmark/package.json rename to test/stark/benchmark/package.json diff --git a/curve-definitions/test/stark/fixtures/issue2.json b/test/stark/fixtures/issue2.json similarity index 100% rename from curve-definitions/test/stark/fixtures/issue2.json rename to test/stark/fixtures/issue2.json diff --git a/curve-definitions/test/stark/fixtures/keys_precomputed.json b/test/stark/fixtures/keys_precomputed.json similarity index 100% rename from curve-definitions/test/stark/fixtures/keys_precomputed.json rename to test/stark/fixtures/keys_precomputed.json diff --git a/curve-definitions/test/stark/fixtures/rfc6979_signature_test_vector.json b/test/stark/fixtures/rfc6979_signature_test_vector.json similarity index 100% rename from curve-definitions/test/stark/fixtures/rfc6979_signature_test_vector.json rename to test/stark/fixtures/rfc6979_signature_test_vector.json diff --git a/curve-definitions/test/stark/index.test.js b/test/stark/index.test.js similarity index 100% rename from curve-definitions/test/stark/index.test.js rename to test/stark/index.test.js diff --git a/curve-definitions/test/stark/property.test.js b/test/stark/property.test.js similarity index 96% rename from curve-definitions/test/stark/property.test.js rename to test/stark/property.test.js index 3ee19ca..97e16ad 100644 --- a/curve-definitions/test/stark/property.test.js +++ b/test/stark/property.test.js @@ -1,6 +1,6 @@ import { deepStrictEqual, throws } from 'assert'; import { should } from 'micro-should'; -import * as starknet from '../../lib/stark.js'; +import * as starknet from '../../lib/esm/stark.js'; import * as fc from 'fast-check'; const FC_BIGINT = fc.bigInt(1n + 1n, starknet.CURVE.n - 1n); diff --git a/curve-definitions/test/stark/stark.test.js b/test/stark/stark.test.js similarity index 99% rename from curve-definitions/test/stark/stark.test.js rename to test/stark/stark.test.js index 681eba6..31a5be5 100644 --- a/curve-definitions/test/stark/stark.test.js +++ b/test/stark/stark.test.js @@ -3,7 +3,7 @@ import { should } from 'micro-should'; import { hex, utf8 } from '@scure/base'; import * as bip32 from '@scure/bip32'; import * as bip39 from '@scure/bip39'; -import * as starknet from '../../lib/stark.js'; +import * as starknet from '../../lib/esm/stark.js'; import { default as sigVec } from './fixtures/rfc6979_signature_test_vector.json' assert { type: 'json' }; import { default as precomputedKeys } from './fixtures/keys_precomputed.json' assert { type: 'json' }; diff --git a/curve-definitions/test/vectors/ecdh.json b/test/vectors/ecdh.json similarity index 100% rename from curve-definitions/test/vectors/ecdh.json rename to test/vectors/ecdh.json diff --git a/curve-definitions/test/vectors/ecdsa.json b/test/vectors/ecdsa.json similarity index 100% rename from curve-definitions/test/vectors/ecdsa.json rename to test/vectors/ecdsa.json diff --git a/curve-definitions/test/vectors/points.json b/test/vectors/points.json similarity index 100% rename from curve-definitions/test/vectors/points.json rename to test/vectors/points.json diff --git a/curve-definitions/test/vectors/points.txt b/test/vectors/points.txt similarity index 100% rename from curve-definitions/test/vectors/points.txt rename to test/vectors/points.txt diff --git a/curve-definitions/test/vectors/privates-2.txt b/test/vectors/privates-2.txt similarity index 100% rename from curve-definitions/test/vectors/privates-2.txt rename to test/vectors/privates-2.txt diff --git a/curve-definitions/test/vectors/privates.json b/test/vectors/privates.json similarity index 100% rename from curve-definitions/test/vectors/privates.json rename to test/vectors/privates.json diff --git a/curve-definitions/test/vectors/rfc6979.json b/test/vectors/rfc6979.json similarity index 100% rename from curve-definitions/test/vectors/rfc6979.json rename to test/vectors/rfc6979.json diff --git a/curve-definitions/test/vectors/schnorr.csv b/test/vectors/schnorr.csv similarity index 100% rename from curve-definitions/test/vectors/schnorr.csv rename to test/vectors/schnorr.csv diff --git a/curve-definitions/test/vectors/wychenproof.json b/test/vectors/wychenproof.json similarity index 100% rename from curve-definitions/test/vectors/wychenproof.json rename to test/vectors/wychenproof.json diff --git a/curve-definitions/test/wycheproof/ecdh_secp224r1_ecpoint_test.json b/test/wycheproof/ecdh_secp224r1_ecpoint_test.json similarity index 100% rename from curve-definitions/test/wycheproof/ecdh_secp224r1_ecpoint_test.json rename to test/wycheproof/ecdh_secp224r1_ecpoint_test.json diff --git a/curve-definitions/test/wycheproof/ecdh_secp224r1_test.json b/test/wycheproof/ecdh_secp224r1_test.json similarity index 100% rename from curve-definitions/test/wycheproof/ecdh_secp224r1_test.json rename to test/wycheproof/ecdh_secp224r1_test.json diff --git a/curve-definitions/test/wycheproof/ecdh_secp256k1_test.json b/test/wycheproof/ecdh_secp256k1_test.json similarity index 100% rename from curve-definitions/test/wycheproof/ecdh_secp256k1_test.json rename to test/wycheproof/ecdh_secp256k1_test.json diff --git a/curve-definitions/test/wycheproof/ecdh_secp256r1_ecpoint_test.json b/test/wycheproof/ecdh_secp256r1_ecpoint_test.json similarity index 100% rename from curve-definitions/test/wycheproof/ecdh_secp256r1_ecpoint_test.json rename to test/wycheproof/ecdh_secp256r1_ecpoint_test.json diff --git a/curve-definitions/test/wycheproof/ecdh_secp256r1_test.json b/test/wycheproof/ecdh_secp256r1_test.json similarity index 100% rename from curve-definitions/test/wycheproof/ecdh_secp256r1_test.json rename to test/wycheproof/ecdh_secp256r1_test.json diff --git a/curve-definitions/test/wycheproof/ecdh_secp384r1_ecpoint_test.json b/test/wycheproof/ecdh_secp384r1_ecpoint_test.json similarity index 100% rename from curve-definitions/test/wycheproof/ecdh_secp384r1_ecpoint_test.json rename to test/wycheproof/ecdh_secp384r1_ecpoint_test.json diff --git a/curve-definitions/test/wycheproof/ecdh_secp384r1_test.json b/test/wycheproof/ecdh_secp384r1_test.json similarity index 100% rename from curve-definitions/test/wycheproof/ecdh_secp384r1_test.json rename to test/wycheproof/ecdh_secp384r1_test.json diff --git a/curve-definitions/test/wycheproof/ecdh_secp521r1_ecpoint_test.json b/test/wycheproof/ecdh_secp521r1_ecpoint_test.json similarity index 100% rename from curve-definitions/test/wycheproof/ecdh_secp521r1_ecpoint_test.json rename to test/wycheproof/ecdh_secp521r1_ecpoint_test.json diff --git a/curve-definitions/test/wycheproof/ecdh_secp521r1_test.json b/test/wycheproof/ecdh_secp521r1_test.json similarity index 100% rename from curve-definitions/test/wycheproof/ecdh_secp521r1_test.json rename to test/wycheproof/ecdh_secp521r1_test.json diff --git a/curve-definitions/test/wycheproof/ecdh_test.json b/test/wycheproof/ecdh_test.json similarity index 100% rename from curve-definitions/test/wycheproof/ecdh_test.json rename to test/wycheproof/ecdh_test.json diff --git a/curve-definitions/test/wycheproof/ecdsa_secp224r1_sha224_test.json b/test/wycheproof/ecdsa_secp224r1_sha224_test.json similarity index 100% rename from curve-definitions/test/wycheproof/ecdsa_secp224r1_sha224_test.json rename to test/wycheproof/ecdsa_secp224r1_sha224_test.json diff --git a/curve-definitions/test/wycheproof/ecdsa_secp224r1_sha256_test.json b/test/wycheproof/ecdsa_secp224r1_sha256_test.json similarity index 100% rename from curve-definitions/test/wycheproof/ecdsa_secp224r1_sha256_test.json rename to test/wycheproof/ecdsa_secp224r1_sha256_test.json diff --git a/curve-definitions/test/wycheproof/ecdsa_secp224r1_sha3_224_test.json b/test/wycheproof/ecdsa_secp224r1_sha3_224_test.json similarity index 100% rename from curve-definitions/test/wycheproof/ecdsa_secp224r1_sha3_224_test.json rename to test/wycheproof/ecdsa_secp224r1_sha3_224_test.json diff --git a/curve-definitions/test/wycheproof/ecdsa_secp224r1_sha3_256_test.json b/test/wycheproof/ecdsa_secp224r1_sha3_256_test.json similarity index 100% rename from curve-definitions/test/wycheproof/ecdsa_secp224r1_sha3_256_test.json rename to test/wycheproof/ecdsa_secp224r1_sha3_256_test.json diff --git a/curve-definitions/test/wycheproof/ecdsa_secp224r1_sha3_512_test.json b/test/wycheproof/ecdsa_secp224r1_sha3_512_test.json similarity index 100% rename from curve-definitions/test/wycheproof/ecdsa_secp224r1_sha3_512_test.json rename to test/wycheproof/ecdsa_secp224r1_sha3_512_test.json diff --git a/curve-definitions/test/wycheproof/ecdsa_secp224r1_sha512_test.json b/test/wycheproof/ecdsa_secp224r1_sha512_test.json similarity index 100% rename from curve-definitions/test/wycheproof/ecdsa_secp224r1_sha512_test.json rename to test/wycheproof/ecdsa_secp224r1_sha512_test.json diff --git a/curve-definitions/test/wycheproof/ecdsa_secp256k1_sha256_test.json b/test/wycheproof/ecdsa_secp256k1_sha256_test.json similarity index 100% rename from curve-definitions/test/wycheproof/ecdsa_secp256k1_sha256_test.json rename to test/wycheproof/ecdsa_secp256k1_sha256_test.json diff --git a/curve-definitions/test/wycheproof/ecdsa_secp256k1_sha3_256_test.json b/test/wycheproof/ecdsa_secp256k1_sha3_256_test.json similarity index 100% rename from curve-definitions/test/wycheproof/ecdsa_secp256k1_sha3_256_test.json rename to test/wycheproof/ecdsa_secp256k1_sha3_256_test.json diff --git a/curve-definitions/test/wycheproof/ecdsa_secp256k1_sha3_512_test.json b/test/wycheproof/ecdsa_secp256k1_sha3_512_test.json similarity index 100% rename from curve-definitions/test/wycheproof/ecdsa_secp256k1_sha3_512_test.json rename to test/wycheproof/ecdsa_secp256k1_sha3_512_test.json diff --git a/curve-definitions/test/wycheproof/ecdsa_secp256k1_sha512_test.json b/test/wycheproof/ecdsa_secp256k1_sha512_test.json similarity index 100% rename from curve-definitions/test/wycheproof/ecdsa_secp256k1_sha512_test.json rename to test/wycheproof/ecdsa_secp256k1_sha512_test.json diff --git a/curve-definitions/test/wycheproof/ecdsa_secp256r1_sha256_test.json b/test/wycheproof/ecdsa_secp256r1_sha256_test.json similarity index 100% rename from curve-definitions/test/wycheproof/ecdsa_secp256r1_sha256_test.json rename to test/wycheproof/ecdsa_secp256r1_sha256_test.json diff --git a/curve-definitions/test/wycheproof/ecdsa_secp256r1_sha3_256_test.json b/test/wycheproof/ecdsa_secp256r1_sha3_256_test.json similarity index 100% rename from curve-definitions/test/wycheproof/ecdsa_secp256r1_sha3_256_test.json rename to test/wycheproof/ecdsa_secp256r1_sha3_256_test.json diff --git a/curve-definitions/test/wycheproof/ecdsa_secp256r1_sha3_512_test.json b/test/wycheproof/ecdsa_secp256r1_sha3_512_test.json similarity index 100% rename from curve-definitions/test/wycheproof/ecdsa_secp256r1_sha3_512_test.json rename to test/wycheproof/ecdsa_secp256r1_sha3_512_test.json diff --git a/curve-definitions/test/wycheproof/ecdsa_secp256r1_sha512_test.json b/test/wycheproof/ecdsa_secp256r1_sha512_test.json similarity index 100% rename from curve-definitions/test/wycheproof/ecdsa_secp256r1_sha512_test.json rename to test/wycheproof/ecdsa_secp256r1_sha512_test.json diff --git a/curve-definitions/test/wycheproof/ecdsa_secp384r1_sha384_test.json b/test/wycheproof/ecdsa_secp384r1_sha384_test.json similarity index 100% rename from curve-definitions/test/wycheproof/ecdsa_secp384r1_sha384_test.json rename to test/wycheproof/ecdsa_secp384r1_sha384_test.json diff --git a/curve-definitions/test/wycheproof/ecdsa_secp384r1_sha3_384_test.json b/test/wycheproof/ecdsa_secp384r1_sha3_384_test.json similarity index 100% rename from curve-definitions/test/wycheproof/ecdsa_secp384r1_sha3_384_test.json rename to test/wycheproof/ecdsa_secp384r1_sha3_384_test.json diff --git a/curve-definitions/test/wycheproof/ecdsa_secp384r1_sha3_512_test.json b/test/wycheproof/ecdsa_secp384r1_sha3_512_test.json similarity index 100% rename from curve-definitions/test/wycheproof/ecdsa_secp384r1_sha3_512_test.json rename to test/wycheproof/ecdsa_secp384r1_sha3_512_test.json diff --git a/curve-definitions/test/wycheproof/ecdsa_secp384r1_sha512_test.json b/test/wycheproof/ecdsa_secp384r1_sha512_test.json similarity index 100% rename from curve-definitions/test/wycheproof/ecdsa_secp384r1_sha512_test.json rename to test/wycheproof/ecdsa_secp384r1_sha512_test.json diff --git a/curve-definitions/test/wycheproof/ecdsa_secp521r1_sha3_512_test.json b/test/wycheproof/ecdsa_secp521r1_sha3_512_test.json similarity index 100% rename from curve-definitions/test/wycheproof/ecdsa_secp521r1_sha3_512_test.json rename to test/wycheproof/ecdsa_secp521r1_sha3_512_test.json diff --git a/curve-definitions/test/wycheproof/ecdsa_secp521r1_sha512_test.json b/test/wycheproof/ecdsa_secp521r1_sha512_test.json similarity index 100% rename from curve-definitions/test/wycheproof/ecdsa_secp521r1_sha512_test.json rename to test/wycheproof/ecdsa_secp521r1_sha512_test.json diff --git a/curve-definitions/test/wycheproof/ecdsa_test.json b/test/wycheproof/ecdsa_test.json similarity index 100% rename from curve-definitions/test/wycheproof/ecdsa_test.json rename to test/wycheproof/ecdsa_test.json diff --git a/curve-definitions/test/wycheproof/ed448_test.json b/test/wycheproof/ed448_test.json similarity index 100% rename from curve-definitions/test/wycheproof/ed448_test.json rename to test/wycheproof/ed448_test.json diff --git a/curve-definitions/test/wycheproof/eddsa_test.json b/test/wycheproof/eddsa_test.json similarity index 100% rename from curve-definitions/test/wycheproof/eddsa_test.json rename to test/wycheproof/eddsa_test.json diff --git a/curve-definitions/test/wycheproof/x25519_test.json b/test/wycheproof/x25519_test.json similarity index 100% rename from curve-definitions/test/wycheproof/x25519_test.json rename to test/wycheproof/x25519_test.json diff --git a/curve-definitions/test/wycheproof/x448_test.json b/test/wycheproof/x448_test.json similarity index 100% rename from curve-definitions/test/wycheproof/x448_test.json rename to test/wycheproof/x448_test.json