@noble/curves 2.0.0-beta.1 → 2.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +442 -273
- package/abstract/bls.d.ts +17 -17
- package/abstract/bls.d.ts.map +1 -1
- package/abstract/bls.js.map +1 -1
- package/abstract/curve.d.ts +14 -9
- package/abstract/curve.d.ts.map +1 -1
- package/abstract/curve.js +9 -3
- package/abstract/curve.js.map +1 -1
- package/abstract/edwards.d.ts +7 -9
- package/abstract/edwards.d.ts.map +1 -1
- package/abstract/edwards.js +12 -16
- package/abstract/edwards.js.map +1 -1
- package/abstract/hash-to-curve.d.ts +32 -31
- package/abstract/hash-to-curve.d.ts.map +1 -1
- package/abstract/hash-to-curve.js +15 -14
- package/abstract/hash-to-curve.js.map +1 -1
- package/abstract/modular.d.ts.map +1 -1
- package/abstract/modular.js +7 -5
- package/abstract/modular.js.map +1 -1
- package/abstract/montgomery.d.ts +3 -3
- package/abstract/montgomery.d.ts.map +1 -1
- package/abstract/montgomery.js +9 -13
- package/abstract/montgomery.js.map +1 -1
- package/abstract/oprf.d.ts +4 -4
- package/abstract/oprf.d.ts.map +1 -1
- package/abstract/oprf.js +2 -2
- package/abstract/oprf.js.map +1 -1
- package/abstract/poseidon.d.ts.map +1 -1
- package/abstract/poseidon.js +8 -9
- package/abstract/poseidon.js.map +1 -1
- package/abstract/weierstrass.d.ts +66 -20
- package/abstract/weierstrass.d.ts.map +1 -1
- package/abstract/weierstrass.js +72 -68
- package/abstract/weierstrass.js.map +1 -1
- package/bls12-381.d.ts +3 -9
- package/bls12-381.d.ts.map +1 -1
- package/bls12-381.js +3 -14
- package/bls12-381.js.map +1 -1
- package/bn254.d.ts +3 -3
- package/bn254.d.ts.map +1 -1
- package/bn254.js.map +1 -1
- package/ed25519.d.ts +22 -18
- package/ed25519.d.ts.map +1 -1
- package/ed25519.js +59 -31
- package/ed25519.js.map +1 -1
- package/ed448.d.ts +17 -8
- package/ed448.d.ts.map +1 -1
- package/ed448.js +69 -52
- package/ed448.js.map +1 -1
- package/index.d.ts +1 -0
- package/index.js +20 -4
- package/index.js.map +1 -1
- package/misc.js +2 -2
- package/misc.js.map +1 -1
- package/nist.d.ts +20 -2
- package/nist.d.ts.map +1 -1
- package/nist.js +30 -10
- package/nist.js.map +1 -1
- package/package.json +14 -13
- package/secp256k1.d.ts +10 -7
- package/secp256k1.d.ts.map +1 -1
- package/secp256k1.js +15 -16
- package/secp256k1.js.map +1 -1
- package/src/abstract/bls.ts +22 -22
- package/src/abstract/curve.ts +19 -5
- package/src/abstract/edwards.ts +20 -23
- package/src/abstract/hash-to-curve.ts +50 -51
- package/src/abstract/modular.ts +7 -5
- package/src/abstract/montgomery.ts +12 -18
- package/src/abstract/oprf.ts +5 -5
- package/src/abstract/poseidon.ts +6 -8
- package/src/abstract/weierstrass.ts +139 -89
- package/src/bls12-381.ts +4 -15
- package/src/bn254.ts +6 -6
- package/src/ed25519.ts +65 -40
- package/src/ed448.ts +87 -69
- package/src/index.ts +19 -3
- package/src/misc.ts +2 -2
- package/src/nist.ts +31 -15
- package/src/secp256k1.ts +16 -18
- package/src/utils.ts +33 -83
- package/src/webcrypto.ts +148 -107
- package/utils.d.ts +4 -20
- package/utils.d.ts.map +1 -1
- package/utils.js +30 -73
- package/utils.js.map +1 -1
- package/webcrypto.d.ts +73 -21
- package/webcrypto.d.ts.map +1 -1
- package/webcrypto.js +101 -76
- package/webcrypto.js.map +1 -1
- package/_shortw_utils.d.ts +0 -19
- package/_shortw_utils.d.ts.map +0 -1
- package/_shortw_utils.js +0 -20
- package/_shortw_utils.js.map +0 -1
- package/abstract/utils.d.ts +0 -5
- package/abstract/utils.d.ts.map +0 -1
- package/abstract/utils.js +0 -23
- package/abstract/utils.js.map +0 -1
- package/jubjub.d.ts +0 -12
- package/jubjub.d.ts.map +0 -1
- package/jubjub.js +0 -15
- package/jubjub.js.map +0 -1
- package/p256.d.ts +0 -16
- package/p256.d.ts.map +0 -1
- package/p256.js +0 -13
- package/p256.js.map +0 -1
- package/p384.d.ts +0 -16
- package/p384.d.ts.map +0 -1
- package/p384.js +0 -13
- package/p384.js.map +0 -1
- package/p521.d.ts +0 -16
- package/p521.d.ts.map +0 -1
- package/p521.js +0 -13
- package/p521.js.map +0 -1
- package/pasta.d.ts +0 -10
- package/pasta.d.ts.map +0 -1
- package/pasta.js +0 -13
- package/pasta.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@noble/curves",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.2",
|
|
4
4
|
"description": "Audited & minimal JS implementation of elliptic curve cryptography",
|
|
5
5
|
"files": [
|
|
6
6
|
"*.js",
|
|
@@ -11,16 +11,17 @@
|
|
|
11
11
|
"src"
|
|
12
12
|
],
|
|
13
13
|
"scripts": {
|
|
14
|
-
"bench": "npm run bench:install; cd test/benchmark; node secp256k1.
|
|
14
|
+
"bench": "npm run bench:install; cd test/benchmark; node secp256k1.ts; node curves.ts; node utils.ts; node bls.ts",
|
|
15
15
|
"bench:install": "cd test/benchmark; npm install; npm install ../.. --install-links",
|
|
16
16
|
"build": "tsc",
|
|
17
17
|
"build:release": "npx --no @paulmillr/jsbt esbuild test/build",
|
|
18
18
|
"build:clean": "rm {.,esm,abstract,esm/abstract}/*.{js,d.ts,d.ts.map,js.map} 2> /dev/null",
|
|
19
|
-
"lint": "prettier --check 'src/**/*.{js,ts}' 'test/*.js'",
|
|
20
|
-
"format": "prettier --write 'src/**/*.{js,ts}' 'test/*.js'",
|
|
21
|
-
"test": "node --disable-warning=ExperimentalWarning test/index.
|
|
22
|
-
"test:bun": "bun test/index.
|
|
23
|
-
"test:deno": "deno --allow-env --allow-read test/index.
|
|
19
|
+
"lint": "prettier --check 'src/**/*.{js,ts}' 'test/*.{js,ts}'",
|
|
20
|
+
"format": "prettier --write 'src/**/*.{js,ts}' 'test/*.{js,ts}'",
|
|
21
|
+
"test": "node --experimental-strip-types --disable-warning=ExperimentalWarning test/index.ts",
|
|
22
|
+
"test:bun": "bun test/index.ts",
|
|
23
|
+
"test:deno": "deno --allow-env --allow-read test/index.ts",
|
|
24
|
+
"test:node20": "cd test; npx tsc; node compiled/test/index.js",
|
|
24
25
|
"test:coverage": "npm install --no-save c8@10.1.2 && npx c8 npm test"
|
|
25
26
|
},
|
|
26
27
|
"author": "Paul Miller (https://paulmillr.com)",
|
|
@@ -31,16 +32,16 @@
|
|
|
31
32
|
},
|
|
32
33
|
"license": "MIT",
|
|
33
34
|
"dependencies": {
|
|
34
|
-
"@noble/hashes": "2.0.0-beta.
|
|
35
|
+
"@noble/hashes": "2.0.0-beta.4"
|
|
35
36
|
},
|
|
36
37
|
"devDependencies": {
|
|
37
|
-
"@paulmillr/jsbt": "0.4.
|
|
38
|
-
"@types/node": "
|
|
39
|
-
"fast-check": "4.
|
|
38
|
+
"@paulmillr/jsbt": "0.4.1",
|
|
39
|
+
"@types/node": "24.2.1",
|
|
40
|
+
"fast-check": "4.2.0",
|
|
40
41
|
"micro-bmark": "0.4.2",
|
|
41
42
|
"micro-should": "0.5.3",
|
|
42
|
-
"prettier": "3.
|
|
43
|
-
"typescript": "5.
|
|
43
|
+
"prettier": "3.6.2",
|
|
44
|
+
"typescript": "5.9.2"
|
|
44
45
|
},
|
|
45
46
|
"sideEffects": false,
|
|
46
47
|
"type": "module",
|
package/secp256k1.d.ts
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type CurveLengths } from './abstract/curve.ts';
|
|
2
2
|
import { type H2CHasher } from './abstract/hash-to-curve.ts';
|
|
3
3
|
import { type ECDSA, type WeierstrassPoint as PointType, type WeierstrassPointCons } from './abstract/weierstrass.ts';
|
|
4
4
|
/**
|
|
5
|
-
* secp256k1 curve
|
|
5
|
+
* secp256k1 curve: ECDSA and ECDH methods.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
7
|
+
* Uses sha256 to hash messages. To use a different hash,
|
|
8
|
+
* pass `{ prehash: false }` to sign / verify.
|
|
8
9
|
*
|
|
9
10
|
* @example
|
|
10
11
|
* ```js
|
|
11
|
-
* import { secp256k1 } from '@noble/curves/secp256k1';
|
|
12
|
+
* import { secp256k1 } from '@noble/curves/secp256k1.js';
|
|
12
13
|
* const { secretKey, publicKey } = secp256k1.keygen();
|
|
13
|
-
* const
|
|
14
|
+
* // const publicKey = secp256k1.getPublicKey(secretKey);
|
|
15
|
+
* const msg = new TextEncoder().encode('hello noble');
|
|
14
16
|
* const sig = secp256k1.sign(msg, secretKey);
|
|
15
|
-
* const isValid = secp256k1.verify(sig, msg, publicKey)
|
|
17
|
+
* const isValid = secp256k1.verify(sig, msg, publicKey);
|
|
18
|
+
* // const sigKeccak = secp256k1.sign(keccak256(msg), secretKey, { prehash: false });
|
|
16
19
|
* ```
|
|
17
20
|
*/
|
|
18
21
|
export declare const secp256k1: ECDSA;
|
|
@@ -58,7 +61,7 @@ export type SecpSchnorr = {
|
|
|
58
61
|
* https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki
|
|
59
62
|
* @example
|
|
60
63
|
* ```js
|
|
61
|
-
* import { schnorr } from '@noble/curves/secp256k1';
|
|
64
|
+
* import { schnorr } from '@noble/curves/secp256k1.js';
|
|
62
65
|
* const { secretKey, publicKey } = schnorr.keygen();
|
|
63
66
|
* // const publicKey = schnorr.getPublicKey(secretKey);
|
|
64
67
|
* const msg = new TextEncoder().encode('hello');
|
package/secp256k1.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"secp256k1.d.ts","sourceRoot":"","sources":["src/secp256k1.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"secp256k1.d.ts","sourceRoot":"","sources":["src/secp256k1.ts"],"names":[],"mappings":"AAUA,OAAO,EAAgB,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACtE,OA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AC;QACvD,MAAM,EAAE,OAAO,MAAM,CAAC;QACtB,UAAU,EAAE,OAAO,UAAU,CAAC;KAC/B,CAAC;IACF,OAAO,EAAE,YAAY,CAAC;CACvB,CAAC;AACF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,OAAO,EAAE,WA0BlB,CAAC;AA0CL,wEAAwE;AACxE,eAAO,MAAM,gBAAgB,EAAE,SAAS,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAgB/D,CAAC"}
|
package/secp256k1.js
CHANGED
|
@@ -8,10 +8,11 @@
|
|
|
8
8
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
9
9
|
import { sha256 } from '@noble/hashes/sha2.js';
|
|
10
10
|
import { randomBytes } from '@noble/hashes/utils.js';
|
|
11
|
+
import { createKeygen } from "./abstract/curve.js";
|
|
11
12
|
import { createHasher, isogenyMap } from "./abstract/hash-to-curve.js";
|
|
12
13
|
import { Field, mapHashToField, pow2 } from "./abstract/modular.js";
|
|
13
14
|
import { ecdsa, mapToCurveSimpleSWU, weierstrass, } from "./abstract/weierstrass.js";
|
|
14
|
-
import { abytes, asciiToBytes, bytesToNumberBE, concatBytes
|
|
15
|
+
import { abytes, asciiToBytes, bytesToNumberBE, concatBytes } from "./utils.js";
|
|
15
16
|
// Seems like generator was produced from some seed:
|
|
16
17
|
// `Pointk1.BASE.multiply(Pointk1.Fn.inv(2n, N)).toAffine().x`
|
|
17
18
|
// // gives short x 0x3b78ce563f89a0ed9414f5aa28ad0d96d6795f9c63n
|
|
@@ -32,7 +33,6 @@ const secp256k1_ENDO = {
|
|
|
32
33
|
],
|
|
33
34
|
};
|
|
34
35
|
const _0n = /* @__PURE__ */ BigInt(0);
|
|
35
|
-
const _1n = /* @__PURE__ */ BigInt(1);
|
|
36
36
|
const _2n = /* @__PURE__ */ BigInt(2);
|
|
37
37
|
/**
|
|
38
38
|
* √n = n^((p+1)/4) for fields p = 3 mod 4. We unwrap the loop and multiply bit-by-bit.
|
|
@@ -68,17 +68,20 @@ const Pointk1 = /* @__PURE__ */ weierstrass(secp256k1_CURVE, {
|
|
|
68
68
|
endo: secp256k1_ENDO,
|
|
69
69
|
});
|
|
70
70
|
/**
|
|
71
|
-
* secp256k1 curve
|
|
71
|
+
* secp256k1 curve: ECDSA and ECDH methods.
|
|
72
72
|
*
|
|
73
|
-
*
|
|
73
|
+
* Uses sha256 to hash messages. To use a different hash,
|
|
74
|
+
* pass `{ prehash: false }` to sign / verify.
|
|
74
75
|
*
|
|
75
76
|
* @example
|
|
76
77
|
* ```js
|
|
77
|
-
* import { secp256k1 } from '@noble/curves/secp256k1';
|
|
78
|
+
* import { secp256k1 } from '@noble/curves/secp256k1.js';
|
|
78
79
|
* const { secretKey, publicKey } = secp256k1.keygen();
|
|
79
|
-
* const
|
|
80
|
+
* // const publicKey = secp256k1.getPublicKey(secretKey);
|
|
81
|
+
* const msg = new TextEncoder().encode('hello noble');
|
|
80
82
|
* const sig = secp256k1.sign(msg, secretKey);
|
|
81
|
-
* const isValid = secp256k1.verify(sig, msg, publicKey)
|
|
83
|
+
* const isValid = secp256k1.verify(sig, msg, publicKey);
|
|
84
|
+
* // const sigKeccak = secp256k1.sign(keccak256(msg), secretKey, { prehash: false });
|
|
82
85
|
* ```
|
|
83
86
|
*/
|
|
84
87
|
export const secp256k1 = /* @__PURE__ */ ecdsa(Pointk1, sha256);
|
|
@@ -165,17 +168,17 @@ function schnorrSign(message, secretKey, auxRand = randomBytes(32)) {
|
|
|
165
168
|
* Will swallow errors & return false except for initial type validation of arguments.
|
|
166
169
|
*/
|
|
167
170
|
function schnorrVerify(signature, message, publicKey) {
|
|
168
|
-
const { Fn, BASE } = Pointk1;
|
|
171
|
+
const { Fp, Fn, BASE } = Pointk1;
|
|
169
172
|
const sig = abytes(signature, 64, 'signature');
|
|
170
173
|
const m = abytes(message, undefined, 'message');
|
|
171
174
|
const pub = abytes(publicKey, 32, 'publicKey');
|
|
172
175
|
try {
|
|
173
176
|
const P = lift_x(num(pub)); // P = lift_x(int(pk)); fail if that fails
|
|
174
177
|
const r = num(sig.subarray(0, 32)); // Let r = int(sig[0:32]); fail if r ≥ p.
|
|
175
|
-
if (!
|
|
178
|
+
if (!Fp.isValidNot0(r))
|
|
176
179
|
return false;
|
|
177
180
|
const s = num(sig.subarray(32, 64)); // Let s = int(sig[32:64]); fail if s ≥ n.
|
|
178
|
-
if (!
|
|
181
|
+
if (!Fn.isValidNot0(s))
|
|
179
182
|
return false;
|
|
180
183
|
const e = challenge(Fn.toBytes(r), pointToBytes(P), m); // int(challenge(bytes(r)||bytes(P)||m))%n
|
|
181
184
|
// R = s⋅G - e⋅P, where -eP == (n-e)P
|
|
@@ -195,7 +198,7 @@ function schnorrVerify(signature, message, publicKey) {
|
|
|
195
198
|
* https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki
|
|
196
199
|
* @example
|
|
197
200
|
* ```js
|
|
198
|
-
* import { schnorr } from '@noble/curves/secp256k1';
|
|
201
|
+
* import { schnorr } from '@noble/curves/secp256k1.js';
|
|
199
202
|
* const { secretKey, publicKey } = schnorr.keygen();
|
|
200
203
|
* // const publicKey = schnorr.getPublicKey(secretKey);
|
|
201
204
|
* const msg = new TextEncoder().encode('hello');
|
|
@@ -209,12 +212,8 @@ export const schnorr = /* @__PURE__ */ (() => {
|
|
|
209
212
|
const randomSecretKey = (seed = randomBytes(seedLength)) => {
|
|
210
213
|
return mapHashToField(seed, secp256k1_CURVE.n);
|
|
211
214
|
};
|
|
212
|
-
function keygen(seed) {
|
|
213
|
-
const secretKey = randomSecretKey(seed);
|
|
214
|
-
return { secretKey, publicKey: schnorrGetPublicKey(secretKey) };
|
|
215
|
-
}
|
|
216
215
|
return {
|
|
217
|
-
keygen,
|
|
216
|
+
keygen: createKeygen(randomSecretKey, schnorrGetPublicKey),
|
|
218
217
|
getPublicKey: schnorrGetPublicKey,
|
|
219
218
|
sign: schnorrSign,
|
|
220
219
|
verify: schnorrVerify,
|
package/secp256k1.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"secp256k1.js","sourceRoot":"","sources":["src/secp256k1.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,sEAAsE;AACtE,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"secp256k1.js","sourceRoot":"","sources":["src/secp256k1.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,sEAAsE;AACtE,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAqB,MAAM,qBAAqB,CAAC;AACtE,OAAO,EAAE,YAAY,EAAkB,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACvF,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,EAEL,KAAK,EAEL,mBAAmB,EAEnB,WAAW,GAGZ,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEhF,oDAAoD;AACpD,8DAA8D;AAC9D,iEAAiE;AACjE,MAAM,eAAe,GAA4B;IAC/C,CAAC,EAAE,MAAM,CAAC,oEAAoE,CAAC;IAC/E,CAAC,EAAE,MAAM,CAAC,oEAAoE,CAAC;IAC/E,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;IACZ,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;IACZ,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;IACZ,EAAE,EAAE,MAAM,CAAC,oEAAoE,CAAC;IAChF,EAAE,EAAE,MAAM,CAAC,oEAAoE,CAAC;CACjF,CAAC;AAEF,MAAM,cAAc,GAAqB;IACvC,IAAI,EA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,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACjD,OAAO,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AACtB,CAAC,EACD;IACE,GAAG,EAAE,gCAAgC;IACrC,SAAS,EAAE,gCAAgC;IAC3C,CAAC,EAAE,IAAI,CAAC,KAAK;IACb,CAAC,EAAE,CAAC;IACJ,CAAC,EAAE,GAAG;IACN,MAAM,EAAE,KAAK;IACb,IAAI,EAAE,MAAM;CACb,CACF,CAAC,EAAE,CAAC"}
|
package/src/abstract/bls.ts
CHANGED
|
@@ -19,9 +19,9 @@ import { abytes, memoized, notImplemented, randomBytes } from '../utils.ts';
|
|
|
19
19
|
import { normalizeZ, type CurveLengths } from './curve.ts';
|
|
20
20
|
import {
|
|
21
21
|
createHasher,
|
|
22
|
+
type H2CDSTOpts,
|
|
22
23
|
type H2CHasher,
|
|
23
24
|
type H2CHashOpts,
|
|
24
|
-
type H2CMethod,
|
|
25
25
|
type H2COpts,
|
|
26
26
|
type MapToCurve,
|
|
27
27
|
} from './hash-to-curve.ts';
|
|
@@ -34,16 +34,16 @@ type Fp = bigint; // Can be different field?
|
|
|
34
34
|
// prettier-ignore
|
|
35
35
|
const _0n = BigInt(0), _1n = BigInt(1), _2n = BigInt(2), _3n = BigInt(3);
|
|
36
36
|
|
|
37
|
-
export type
|
|
37
|
+
export type BlsTwistType = 'multiplicative' | 'divisive';
|
|
38
38
|
|
|
39
|
-
export type
|
|
39
|
+
export type BlsShortSignatureCoder<Fp> = {
|
|
40
40
|
fromBytes(bytes: Uint8Array): WeierstrassPoint<Fp>;
|
|
41
41
|
fromHex(hex: string): WeierstrassPoint<Fp>;
|
|
42
42
|
toBytes(point: WeierstrassPoint<Fp>): Uint8Array;
|
|
43
43
|
toHex(point: WeierstrassPoint<Fp>): string;
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
-
export type
|
|
46
|
+
export type BlsLongSignatureCoder<Fp> = {
|
|
47
47
|
fromBytes(bytes: Uint8Array): WeierstrassPoint<Fp>;
|
|
48
48
|
fromHex(hex: string): WeierstrassPoint<Fp>;
|
|
49
49
|
toBytes(point: WeierstrassPoint<Fp>): Uint8Array;
|
|
@@ -58,20 +58,20 @@ export type BlsFields = {
|
|
|
58
58
|
Fp12: Fp12Bls;
|
|
59
59
|
};
|
|
60
60
|
|
|
61
|
-
export type
|
|
61
|
+
export type BlsPostPrecomputePointAddFn = (
|
|
62
62
|
Rx: Fp2,
|
|
63
63
|
Ry: Fp2,
|
|
64
64
|
Rz: Fp2,
|
|
65
65
|
Qx: Fp2,
|
|
66
66
|
Qy: Fp2
|
|
67
67
|
) => { Rx: Fp2; Ry: Fp2; Rz: Fp2 };
|
|
68
|
-
export type
|
|
68
|
+
export type BlsPostPrecomputeFn = (
|
|
69
69
|
Rx: Fp2,
|
|
70
70
|
Ry: Fp2,
|
|
71
71
|
Rz: Fp2,
|
|
72
72
|
Qx: Fp2,
|
|
73
73
|
Qy: Fp2,
|
|
74
|
-
pointAdd:
|
|
74
|
+
pointAdd: BlsPostPrecomputePointAddFn
|
|
75
75
|
) => void;
|
|
76
76
|
export type BlsPairing = {
|
|
77
77
|
lengths: CurveLengths;
|
|
@@ -92,9 +92,9 @@ export type BlsPairingParams = {
|
|
|
92
92
|
// Can be different from `X` (seed) param.
|
|
93
93
|
ateLoopSize: bigint;
|
|
94
94
|
xNegative: boolean;
|
|
95
|
-
twistType:
|
|
95
|
+
twistType: BlsTwistType; // BLS12-381: Multiplicative, BN254: Divisive
|
|
96
96
|
randomBytes?: (len?: number) => Uint8Array;
|
|
97
|
-
postPrecompute?:
|
|
97
|
+
postPrecompute?: BlsPostPrecomputeFn; // Ugly hack to untwist point in BN254 after miller loop
|
|
98
98
|
};
|
|
99
99
|
export type BlsHasherParams = {
|
|
100
100
|
mapToG1?: MapToCurve<Fp>;
|
|
@@ -111,7 +111,7 @@ type Precompute = PrecomputeSingle[];
|
|
|
111
111
|
* - G1 is a subgroup of (x, y) E(Fq) over y² = x³ + 4.
|
|
112
112
|
* - G2 is a subgroup of ((x₁, x₂+i), (y₁, y₂+i)) E(Fq²) over y² = x³ + 4(1 + i) where i is √-1
|
|
113
113
|
*/
|
|
114
|
-
export interface
|
|
114
|
+
export interface BlsCurvePair {
|
|
115
115
|
lengths: CurveLengths;
|
|
116
116
|
millerLoopBatch: BlsPairing['millerLoopBatch'];
|
|
117
117
|
pairing: BlsPairing['pairing'];
|
|
@@ -131,22 +131,22 @@ export interface BLSCurvePair {
|
|
|
131
131
|
};
|
|
132
132
|
params: {
|
|
133
133
|
ateLoopSize: bigint;
|
|
134
|
-
twistType:
|
|
134
|
+
twistType: BlsTwistType;
|
|
135
135
|
};
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
-
export interface BlsCurvePairWithHashers extends
|
|
138
|
+
export interface BlsCurvePairWithHashers extends BlsCurvePair {
|
|
139
139
|
G1: H2CHasher<WeierstrassPointCons<Fp>>;
|
|
140
140
|
G2: H2CHasher<WeierstrassPointCons<Fp2>>;
|
|
141
141
|
}
|
|
142
142
|
|
|
143
143
|
export interface BlsCurvePairWithSignatures extends BlsCurvePairWithHashers {
|
|
144
|
-
longSignatures:
|
|
145
|
-
shortSignatures:
|
|
144
|
+
longSignatures: BlsSigs<bigint, Fp2>;
|
|
145
|
+
shortSignatures: BlsSigs<Fp2, bigint>;
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
type BLSInput = Uint8Array;
|
|
149
|
-
export interface
|
|
149
|
+
export interface BlsSigs<P, S> {
|
|
150
150
|
lengths: CurveLengths;
|
|
151
151
|
keygen(seed?: Uint8Array): {
|
|
152
152
|
secretKey: Uint8Array;
|
|
@@ -166,7 +166,7 @@ export interface BLSSigs<P, S> {
|
|
|
166
166
|
aggregatePublicKeys(publicKeys: (WeierstrassPoint<P> | BLSInput)[]): WeierstrassPoint<P>;
|
|
167
167
|
aggregateSignatures(signatures: (WeierstrassPoint<S> | BLSInput)[]): WeierstrassPoint<S>;
|
|
168
168
|
hash(message: Uint8Array, DST?: string | Uint8Array, hashOpts?: H2CHashOpts): WeierstrassPoint<S>;
|
|
169
|
-
Signature:
|
|
169
|
+
Signature: BlsLongSignatureCoder<S>;
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
// Not used with BLS12-381 (no sequential `11` in X). Useful for other curves.
|
|
@@ -346,9 +346,9 @@ function createBlsSig<P, S>(
|
|
|
346
346
|
PubPoint: WeierstrassPointCons<P>,
|
|
347
347
|
SigPoint: WeierstrassPointCons<S>,
|
|
348
348
|
isSigG1: boolean,
|
|
349
|
-
hashToSigCurve:
|
|
350
|
-
SignatureCoder?:
|
|
351
|
-
):
|
|
349
|
+
hashToSigCurve: (msg: Uint8Array, options?: H2CDSTOpts) => WeierstrassPoint<S>,
|
|
350
|
+
SignatureCoder?: BlsLongSignatureCoder<S>
|
|
351
|
+
): BlsSigs<P, S> {
|
|
352
352
|
const { Fr, Fp12, pairingBatch, randomSecretKey, lengths } = blsPairing;
|
|
353
353
|
if (!SignatureCoder) {
|
|
354
354
|
SignatureCoder = {
|
|
@@ -493,8 +493,8 @@ function createBlsSig<P, S>(
|
|
|
493
493
|
}
|
|
494
494
|
|
|
495
495
|
type BlsSignatureCoders = Partial<{
|
|
496
|
-
LongSignature:
|
|
497
|
-
ShortSignature:
|
|
496
|
+
LongSignature: BlsLongSignatureCoder<Fp2>;
|
|
497
|
+
ShortSignature: BlsShortSignatureCoder<Fp>;
|
|
498
498
|
}>;
|
|
499
499
|
|
|
500
500
|
// NOTE: separate function instead of function override, so we don't depend on hasher in bn254.
|
|
@@ -503,7 +503,7 @@ export function blsBasic(
|
|
|
503
503
|
G1_Point: WeierstrassPointCons<Fp>,
|
|
504
504
|
G2_Point: WeierstrassPointCons<Fp2>,
|
|
505
505
|
params: BlsPairingParams
|
|
506
|
-
):
|
|
506
|
+
): BlsCurvePair {
|
|
507
507
|
// Fields are specific for curve, so for now we'll need to pass them with opts
|
|
508
508
|
const { Fp, Fr, Fp2, Fp6, Fp12 } = fields;
|
|
509
509
|
// Point on G1 curve: (x, y)
|
package/src/abstract/curve.ts
CHANGED
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
6
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
7
|
-
import { bitLen, bitMask } from '../utils.ts';
|
|
7
|
+
import { bitLen, bitMask, type Signer } from '../utils.ts';
|
|
8
8
|
import { Field, FpInvertBatch, validateField, type IField } from './modular.ts';
|
|
9
9
|
|
|
10
|
-
const _0n = BigInt(0);
|
|
11
|
-
const _1n = BigInt(1);
|
|
10
|
+
const _0n = /* @__PURE__ */ BigInt(0);
|
|
11
|
+
const _1n = /* @__PURE__ */ BigInt(1);
|
|
12
12
|
|
|
13
13
|
export type AffinePoint<T> = {
|
|
14
14
|
x: T;
|
|
@@ -153,7 +153,7 @@ function validateW(W: number, bits: number) {
|
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
/** Internal wNAF opts for specific W and scalarBits */
|
|
156
|
-
|
|
156
|
+
type WOpts = {
|
|
157
157
|
windows: number;
|
|
158
158
|
windowSize: number;
|
|
159
159
|
mask: bigint;
|
|
@@ -592,7 +592,7 @@ function createField<T>(order: bigint, field?: IField<T>, isLE?: boolean): IFiel
|
|
|
592
592
|
export type FpFn<T> = { Fp: IField<T>; Fn: IField<bigint> };
|
|
593
593
|
|
|
594
594
|
/** Validates CURVE opts and creates fields */
|
|
595
|
-
export function
|
|
595
|
+
export function createCurveFields<T>(
|
|
596
596
|
type: 'weierstrass' | 'edwards',
|
|
597
597
|
CURVE: ValidCurveParams<T>,
|
|
598
598
|
curveOpts: Partial<FpFn<T>> = {},
|
|
@@ -617,3 +617,17 @@ export function _createCurveFields<T>(
|
|
|
617
617
|
CURVE = Object.freeze(Object.assign({}, CURVE));
|
|
618
618
|
return { CURVE, Fp, Fn };
|
|
619
619
|
}
|
|
620
|
+
|
|
621
|
+
type KeygenFn = (
|
|
622
|
+
seed?: Uint8Array,
|
|
623
|
+
isCompressed?: boolean
|
|
624
|
+
) => { secretKey: Uint8Array; publicKey: Uint8Array };
|
|
625
|
+
export function createKeygen(
|
|
626
|
+
randomSecretKey: Function,
|
|
627
|
+
getPublicKey: Signer['getPublicKey']
|
|
628
|
+
): KeygenFn {
|
|
629
|
+
return function keygen(seed?: Uint8Array) {
|
|
630
|
+
const secretKey = randomSecretKey(seed);
|
|
631
|
+
return { secretKey, publicKey: getPublicKey(secretKey) };
|
|
632
|
+
};
|
|
633
|
+
}
|
package/src/abstract/edwards.ts
CHANGED
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
*/
|
|
7
7
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
8
8
|
import {
|
|
9
|
-
_validateObject,
|
|
10
9
|
abool,
|
|
11
10
|
abytes,
|
|
12
11
|
aInRange,
|
|
@@ -18,12 +17,14 @@ import {
|
|
|
18
17
|
isBytes,
|
|
19
18
|
memoized,
|
|
20
19
|
notImplemented,
|
|
20
|
+
validateObject,
|
|
21
21
|
randomBytes as wcRandomBytes,
|
|
22
22
|
type FHash,
|
|
23
23
|
type Signer,
|
|
24
24
|
} from '../utils.ts';
|
|
25
25
|
import {
|
|
26
|
-
|
|
26
|
+
createCurveFields,
|
|
27
|
+
createKeygen,
|
|
27
28
|
normalizeZ,
|
|
28
29
|
wNAF,
|
|
29
30
|
type AffinePoint,
|
|
@@ -37,8 +38,6 @@ import { type IField } from './modular.ts';
|
|
|
37
38
|
// prettier-ignore
|
|
38
39
|
const _0n = BigInt(0), _1n = BigInt(1), _2n = BigInt(2), _8n = BigInt(8);
|
|
39
40
|
|
|
40
|
-
export type UVRatio = (u: bigint, v: bigint) => { isValid: boolean; value: bigint };
|
|
41
|
-
|
|
42
41
|
/** Instance of Extended Point with coordinates in X, Y, Z, T. */
|
|
43
42
|
export interface EdwardsPoint extends CurvePoint<bigint, EdwardsPoint> {
|
|
44
43
|
/** extended X coordinate. Different from affine x. */
|
|
@@ -146,9 +145,10 @@ export interface EdDSA {
|
|
|
146
145
|
*
|
|
147
146
|
* @example
|
|
148
147
|
* ```js
|
|
149
|
-
* const
|
|
148
|
+
* const someonesPub_ed = ed25519.getPublicKey(ed25519.utils.randomSecretKey());
|
|
149
|
+
* const someonesPub = ed25519.utils.toMontgomery(someonesPub);
|
|
150
150
|
* const aPriv = x25519.utils.randomSecretKey();
|
|
151
|
-
* x25519.getSharedSecret(aPriv,
|
|
151
|
+
* const shared = x25519.getSharedSecret(aPriv, someonesPub)
|
|
152
152
|
* ```
|
|
153
153
|
*/
|
|
154
154
|
toMontgomery: (publicKey: Uint8Array) => Uint8Array;
|
|
@@ -157,11 +157,12 @@ export interface EdDSA {
|
|
|
157
157
|
* @example
|
|
158
158
|
* ```js
|
|
159
159
|
* const someonesPub = x25519.getPublicKey(x25519.utils.randomSecretKey());
|
|
160
|
-
* const
|
|
161
|
-
*
|
|
160
|
+
* const aPriv_ed = ed25519.utils.randomSecretKey();
|
|
161
|
+
* const aPriv = ed25519.utils.toMontgomerySecret(aPriv_ed);
|
|
162
|
+
* const shared = x25519.getSharedSecret(aPriv, someonesPub)
|
|
162
163
|
* ```
|
|
163
164
|
*/
|
|
164
|
-
|
|
165
|
+
toMontgomerySecret: (secretKey: Uint8Array) => Uint8Array;
|
|
165
166
|
getExtendedPublicKey: (key: Uint8Array) => {
|
|
166
167
|
head: Uint8Array;
|
|
167
168
|
prefix: Uint8Array;
|
|
@@ -182,11 +183,11 @@ function isEdValidXY(Fp: IField<bigint>, CURVE: EdwardsOpts, x: bigint, y: bigin
|
|
|
182
183
|
}
|
|
183
184
|
|
|
184
185
|
export function edwards(params: EdwardsOpts, extraOpts: EdwardsExtraOpts = {}): EdwardsPointCons {
|
|
185
|
-
const validated =
|
|
186
|
+
const validated = createCurveFields('edwards', params, extraOpts, extraOpts.FpFnLE);
|
|
186
187
|
const { Fp, Fn } = validated;
|
|
187
188
|
let CURVE = validated.CURVE as EdwardsOpts;
|
|
188
189
|
const { h: cofactor } = CURVE;
|
|
189
|
-
|
|
190
|
+
validateObject(extraOpts, {}, { uvRatio: 'function' });
|
|
190
191
|
|
|
191
192
|
// Important:
|
|
192
193
|
// There are some places where Fp.BYTES is used instead of nByteLength.
|
|
@@ -221,8 +222,8 @@ export function edwards(params: EdwardsOpts, extraOpts: EdwardsExtraOpts = {}):
|
|
|
221
222
|
return n;
|
|
222
223
|
}
|
|
223
224
|
|
|
224
|
-
function
|
|
225
|
-
if (!(other instanceof Point)) throw new Error('
|
|
225
|
+
function aedpoint(other: unknown) {
|
|
226
|
+
if (!(other instanceof Point)) throw new Error('EdwardsPoint expected');
|
|
226
227
|
}
|
|
227
228
|
// Converts Extended point to default (x, y) coordinates.
|
|
228
229
|
// Can accept precomputed Z^-1 - for example, from invertBatch.
|
|
@@ -353,7 +354,7 @@ export function edwards(params: EdwardsOpts, extraOpts: EdwardsExtraOpts = {}):
|
|
|
353
354
|
|
|
354
355
|
// Compare one point to another.
|
|
355
356
|
equals(other: Point): boolean {
|
|
356
|
-
|
|
357
|
+
aedpoint(other);
|
|
357
358
|
const { X: X1, Y: Y1, Z: Z1 } = this;
|
|
358
359
|
const { X: X2, Y: Y2, Z: Z2 } = other;
|
|
359
360
|
const X1Z2 = modP(X1 * Z2);
|
|
@@ -398,7 +399,7 @@ export function edwards(params: EdwardsOpts, extraOpts: EdwardsExtraOpts = {}):
|
|
|
398
399
|
// https://hyperelliptic.org/EFD/g1p/auto-twisted-extended.html#addition-add-2008-hwcd
|
|
399
400
|
// Cost: 9M + 1*a + 1*d + 7add.
|
|
400
401
|
add(other: Point) {
|
|
401
|
-
|
|
402
|
+
aedpoint(other);
|
|
402
403
|
const { a, d } = CURVE;
|
|
403
404
|
const { X: X1, Y: Y1, Z: Z1, T: T1 } = this;
|
|
404
405
|
const { X: X2, Y: Y2, Z: Z2, T: T2 } = other;
|
|
@@ -599,7 +600,7 @@ export abstract class PrimeEdwardsPoint<T extends PrimeEdwardsPoint<T>>
|
|
|
599
600
|
*/
|
|
600
601
|
export function eddsa(Point: EdwardsPointCons, cHash: FHash, eddsaOpts: EdDSAOpts = {}): EdDSA {
|
|
601
602
|
if (typeof cHash !== 'function') throw new Error('"hash" function param is required');
|
|
602
|
-
|
|
603
|
+
validateObject(
|
|
603
604
|
eddsaOpts,
|
|
604
605
|
{},
|
|
605
606
|
{
|
|
@@ -661,7 +662,7 @@ export function eddsa(Point: EdwardsPointCons, cHash: FHash, eddsaOpts: EdDSAOpt
|
|
|
661
662
|
return modN_LE(cHash(domain(msg, abytes(context, undefined, 'context'), !!prehash)));
|
|
662
663
|
}
|
|
663
664
|
|
|
664
|
-
/** Signs message with
|
|
665
|
+
/** Signs message with secret key. RFC8032 5.1.6 */
|
|
665
666
|
function sign(
|
|
666
667
|
msg: Uint8Array,
|
|
667
668
|
secretKey: Uint8Array,
|
|
@@ -733,10 +734,6 @@ export function eddsa(Point: EdwardsPointCons, cHash: FHash, eddsaOpts: EdDSAOpt
|
|
|
733
734
|
function randomSecretKey(seed = randomBytes(lengths.seed)): Uint8Array {
|
|
734
735
|
return abytes(seed, lengths.seed, 'seed');
|
|
735
736
|
}
|
|
736
|
-
function keygen(seed?: Uint8Array) {
|
|
737
|
-
const secretKey = utils.randomSecretKey(seed);
|
|
738
|
-
return { secretKey, publicKey: getPublicKey(secretKey) };
|
|
739
|
-
}
|
|
740
737
|
|
|
741
738
|
function isValidSecretKey(key: Uint8Array): boolean {
|
|
742
739
|
return isBytes(key) && key.length === Fn.BYTES;
|
|
@@ -772,7 +769,7 @@ export function eddsa(Point: EdwardsPointCons, cHash: FHash, eddsaOpts: EdDSAOpt
|
|
|
772
769
|
const u = is25519 ? Fp.div(_1n + y, _1n - y) : Fp.div(y - _1n, y + _1n);
|
|
773
770
|
return Fp.toBytes(u);
|
|
774
771
|
},
|
|
775
|
-
|
|
772
|
+
toMontgomerySecret(secretKey: Uint8Array): Uint8Array {
|
|
776
773
|
const size = lengths.secretKey;
|
|
777
774
|
abytes(secretKey, size);
|
|
778
775
|
const hashed = cHash(secretKey.subarray(0, size));
|
|
@@ -781,7 +778,7 @@ export function eddsa(Point: EdwardsPointCons, cHash: FHash, eddsaOpts: EdDSAOpt
|
|
|
781
778
|
};
|
|
782
779
|
|
|
783
780
|
return Object.freeze({
|
|
784
|
-
keygen,
|
|
781
|
+
keygen: createKeygen(randomSecretKey, getPublicKey),
|
|
785
782
|
getPublicKey,
|
|
786
783
|
sign,
|
|
787
784
|
verify,
|