@noble/curves 1.9.0 → 1.9.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 +78 -34
- package/_shortw_utils.d.ts +7 -5
- package/_shortw_utils.d.ts.map +1 -1
- package/_shortw_utils.js +2 -8
- package/_shortw_utils.js.map +1 -1
- package/abstract/bls.d.ts +60 -24
- package/abstract/bls.d.ts.map +1 -1
- package/abstract/bls.js +158 -109
- package/abstract/bls.js.map +1 -1
- package/abstract/curve.d.ts +44 -9
- package/abstract/curve.d.ts.map +1 -1
- package/abstract/curve.js +99 -11
- package/abstract/curve.js.map +1 -1
- package/abstract/edwards.d.ts +112 -25
- package/abstract/edwards.d.ts.map +1 -1
- package/abstract/edwards.js +141 -92
- package/abstract/edwards.js.map +1 -1
- package/abstract/fft.d.ts +122 -0
- package/abstract/fft.d.ts.map +1 -0
- package/abstract/fft.js +438 -0
- package/abstract/fft.js.map +1 -0
- package/abstract/hash-to-curve.d.ts +25 -11
- package/abstract/hash-to-curve.d.ts.map +1 -1
- package/abstract/hash-to-curve.js +17 -14
- package/abstract/hash-to-curve.js.map +1 -1
- package/abstract/modular.d.ts +28 -17
- package/abstract/modular.d.ts.map +1 -1
- package/abstract/modular.js +156 -139
- package/abstract/modular.js.map +1 -1
- package/abstract/montgomery.d.ts +3 -8
- package/abstract/montgomery.d.ts.map +1 -1
- package/abstract/montgomery.js +73 -93
- package/abstract/montgomery.js.map +1 -1
- package/abstract/poseidon.d.ts +5 -13
- package/abstract/poseidon.d.ts.map +1 -1
- package/abstract/poseidon.js +12 -7
- package/abstract/poseidon.js.map +1 -1
- package/abstract/tower.d.ts +20 -46
- package/abstract/tower.d.ts.map +1 -1
- package/abstract/tower.js +10 -4
- package/abstract/tower.js.map +1 -1
- package/abstract/utils.d.ts +1 -115
- package/abstract/utils.d.ts.map +1 -1
- package/abstract/utils.js +17 -371
- package/abstract/utils.js.map +1 -1
- package/abstract/weierstrass.d.ts +152 -73
- package/abstract/weierstrass.d.ts.map +1 -1
- package/abstract/weierstrass.js +487 -404
- package/abstract/weierstrass.js.map +1 -1
- package/bls12-381.d.ts +2 -0
- package/bls12-381.d.ts.map +1 -1
- package/bls12-381.js +504 -480
- package/bls12-381.js.map +1 -1
- package/bn254.d.ts +2 -0
- package/bn254.d.ts.map +1 -1
- package/bn254.js +44 -32
- package/bn254.js.map +1 -1
- package/ed25519.d.ts +25 -9
- package/ed25519.d.ts.map +1 -1
- package/ed25519.js +89 -65
- package/ed25519.js.map +1 -1
- package/ed448.d.ts +29 -10
- package/ed448.d.ts.map +1 -1
- package/ed448.js +116 -81
- package/ed448.js.map +1 -1
- package/esm/_shortw_utils.d.ts +7 -5
- package/esm/_shortw_utils.d.ts.map +1 -1
- package/esm/_shortw_utils.js +2 -8
- package/esm/_shortw_utils.js.map +1 -1
- package/esm/abstract/bls.d.ts +60 -24
- package/esm/abstract/bls.d.ts.map +1 -1
- package/esm/abstract/bls.js +158 -109
- package/esm/abstract/bls.js.map +1 -1
- package/esm/abstract/curve.d.ts +44 -9
- package/esm/abstract/curve.d.ts.map +1 -1
- package/esm/abstract/curve.js +96 -12
- package/esm/abstract/curve.js.map +1 -1
- package/esm/abstract/edwards.d.ts +112 -25
- package/esm/abstract/edwards.d.ts.map +1 -1
- package/esm/abstract/edwards.js +141 -94
- package/esm/abstract/edwards.js.map +1 -1
- package/esm/abstract/fft.d.ts +122 -0
- package/esm/abstract/fft.d.ts.map +1 -0
- package/esm/abstract/fft.js +425 -0
- package/esm/abstract/fft.js.map +1 -0
- package/esm/abstract/hash-to-curve.d.ts +25 -11
- package/esm/abstract/hash-to-curve.d.ts.map +1 -1
- package/esm/abstract/hash-to-curve.js +17 -14
- package/esm/abstract/hash-to-curve.js.map +1 -1
- package/esm/abstract/modular.d.ts +28 -17
- package/esm/abstract/modular.d.ts.map +1 -1
- package/esm/abstract/modular.js +155 -138
- package/esm/abstract/modular.js.map +1 -1
- package/esm/abstract/montgomery.d.ts +3 -8
- package/esm/abstract/montgomery.d.ts.map +1 -1
- package/esm/abstract/montgomery.js +74 -94
- package/esm/abstract/montgomery.js.map +1 -1
- package/esm/abstract/poseidon.d.ts +5 -13
- package/esm/abstract/poseidon.d.ts.map +1 -1
- package/esm/abstract/poseidon.js +12 -7
- package/esm/abstract/poseidon.js.map +1 -1
- package/esm/abstract/tower.d.ts +20 -46
- package/esm/abstract/tower.d.ts.map +1 -1
- package/esm/abstract/tower.js +10 -4
- package/esm/abstract/tower.js.map +1 -1
- package/esm/abstract/utils.d.ts +1 -115
- package/esm/abstract/utils.d.ts.map +1 -1
- package/esm/abstract/utils.js +3 -344
- package/esm/abstract/utils.js.map +1 -1
- package/esm/abstract/weierstrass.d.ts +152 -73
- package/esm/abstract/weierstrass.d.ts.map +1 -1
- package/esm/abstract/weierstrass.js +485 -406
- package/esm/abstract/weierstrass.js.map +1 -1
- package/esm/bls12-381.d.ts +2 -0
- package/esm/bls12-381.d.ts.map +1 -1
- package/esm/bls12-381.js +503 -479
- package/esm/bls12-381.js.map +1 -1
- package/esm/bn254.d.ts +2 -0
- package/esm/bn254.d.ts.map +1 -1
- package/esm/bn254.js +41 -29
- package/esm/bn254.js.map +1 -1
- package/esm/ed25519.d.ts +25 -9
- package/esm/ed25519.d.ts.map +1 -1
- package/esm/ed25519.js +84 -60
- package/esm/ed25519.js.map +1 -1
- package/esm/ed448.d.ts +29 -10
- package/esm/ed448.d.ts.map +1 -1
- package/esm/ed448.js +113 -78
- package/esm/ed448.js.map +1 -1
- package/esm/jubjub.d.ts +4 -0
- package/esm/jubjub.d.ts.map +1 -1
- package/esm/jubjub.js +4 -0
- package/esm/jubjub.js.map +1 -1
- package/esm/misc.d.ts.map +1 -1
- package/esm/misc.js +31 -26
- package/esm/misc.js.map +1 -1
- package/esm/nist.d.ts +8 -16
- package/esm/nist.d.ts.map +1 -1
- package/esm/nist.js +87 -97
- package/esm/nist.js.map +1 -1
- package/esm/p256.d.ts +3 -3
- package/esm/p384.d.ts +3 -3
- package/esm/p521.d.ts +3 -3
- package/esm/pasta.d.ts +4 -0
- package/esm/pasta.d.ts.map +1 -1
- package/esm/pasta.js +4 -0
- package/esm/pasta.js.map +1 -1
- package/esm/secp256k1.d.ts +6 -6
- package/esm/secp256k1.d.ts.map +1 -1
- package/esm/secp256k1.js +44 -41
- package/esm/secp256k1.js.map +1 -1
- package/esm/utils.d.ts +96 -0
- package/esm/utils.d.ts.map +1 -0
- package/esm/utils.js +279 -0
- package/esm/utils.js.map +1 -0
- package/jubjub.d.ts +4 -0
- package/jubjub.d.ts.map +1 -1
- package/jubjub.js +4 -0
- package/jubjub.js.map +1 -1
- package/misc.d.ts.map +1 -1
- package/misc.js +35 -30
- package/misc.js.map +1 -1
- package/nist.d.ts +8 -16
- package/nist.d.ts.map +1 -1
- package/nist.js +87 -97
- package/nist.js.map +1 -1
- package/p256.d.ts +3 -3
- package/p384.d.ts +3 -3
- package/p521.d.ts +3 -3
- package/package.json +26 -8
- package/pasta.d.ts +4 -0
- package/pasta.d.ts.map +1 -1
- package/pasta.js +4 -0
- package/pasta.js.map +1 -1
- package/secp256k1.d.ts +6 -6
- package/secp256k1.d.ts.map +1 -1
- package/secp256k1.js +47 -44
- package/secp256k1.js.map +1 -1
- package/src/_shortw_utils.ts +5 -15
- package/src/abstract/bls.ts +260 -145
- package/src/abstract/curve.ts +125 -18
- package/src/abstract/edwards.ts +282 -127
- package/src/abstract/fft.ts +519 -0
- package/src/abstract/hash-to-curve.ts +51 -27
- package/src/abstract/modular.ts +156 -143
- package/src/abstract/montgomery.ts +81 -111
- package/src/abstract/poseidon.ts +22 -18
- package/src/abstract/tower.ts +37 -68
- package/src/abstract/utils.ts +3 -378
- package/src/abstract/weierstrass.ts +752 -461
- package/src/bls12-381.ts +542 -507
- package/src/bn254.ts +47 -35
- package/src/ed25519.ts +104 -76
- package/src/ed448.ts +156 -105
- package/src/jubjub.ts +4 -0
- package/src/misc.ts +39 -34
- package/src/nist.ts +138 -126
- package/src/p256.ts +3 -3
- package/src/p384.ts +3 -3
- package/src/p521.ts +3 -3
- package/src/pasta.ts +5 -1
- package/src/secp256k1.ts +59 -47
- package/src/utils.ts +328 -0
- package/utils.d.ts +96 -0
- package/utils.d.ts.map +1 -0
- package/utils.js +313 -0
- package/utils.js.map +1 -0
package/nist.js
CHANGED
|
@@ -7,117 +7,107 @@ exports.p521_hasher = exports.secp521r1 = exports.p521 = exports.p384_hasher = e
|
|
|
7
7
|
* @module
|
|
8
8
|
*/
|
|
9
9
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
10
|
-
const
|
|
10
|
+
const sha2_js_1 = require("@noble/hashes/sha2.js");
|
|
11
11
|
const _shortw_utils_ts_1 = require("./_shortw_utils.js");
|
|
12
12
|
const hash_to_curve_ts_1 = require("./abstract/hash-to-curve.js");
|
|
13
13
|
const modular_ts_1 = require("./abstract/modular.js");
|
|
14
14
|
const weierstrass_ts_1 = require("./abstract/weierstrass.js");
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
* secp256r1 curve, ECDSA and ECDH methods.
|
|
20
|
-
* Field: `2n**224n * (2n**32n-1n) + 2n**192n + 2n**96n-1n`
|
|
21
|
-
*/
|
|
22
|
-
// prettier-ignore
|
|
23
|
-
exports.p256 = (0, _shortw_utils_ts_1.createCurve)({
|
|
24
|
-
a: p256_a,
|
|
25
|
-
b: p256_b,
|
|
26
|
-
Fp: Fp256,
|
|
15
|
+
// p = 2n**224n * (2n**32n-1n) + 2n**192n + 2n**96n - 1n
|
|
16
|
+
// a = Fp256.create(BigInt('-3'));
|
|
17
|
+
const p256_CURVE = {
|
|
18
|
+
p: BigInt('0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff'),
|
|
27
19
|
n: BigInt('0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551'),
|
|
20
|
+
h: BigInt(1),
|
|
21
|
+
a: BigInt('0xffffffff00000001000000000000000000000000fffffffffffffffffffffffc'),
|
|
22
|
+
b: BigInt('0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b'),
|
|
28
23
|
Gx: BigInt('0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296'),
|
|
29
24
|
Gy: BigInt('0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5'),
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
exports.secp256r1 = exports.p256;
|
|
35
|
-
const p256_mapSWU = /* @__PURE__ */ (() => (0, weierstrass_ts_1.mapToCurveSimpleSWU)(Fp256, {
|
|
36
|
-
A: p256_a,
|
|
37
|
-
B: p256_b,
|
|
38
|
-
Z: Fp256.create(BigInt('-10')),
|
|
39
|
-
}))();
|
|
40
|
-
/** Hashing / encoding to p256 points / field. RFC 9380 methods. */
|
|
41
|
-
exports.p256_hasher = (() => (0, hash_to_curve_ts_1.createHasher)(exports.secp256r1.ProjectivePoint, (scalars) => p256_mapSWU(scalars[0]), {
|
|
42
|
-
DST: 'P256_XMD:SHA-256_SSWU_RO_',
|
|
43
|
-
encodeDST: 'P256_XMD:SHA-256_SSWU_NU_',
|
|
44
|
-
p: Fp256.ORDER,
|
|
45
|
-
m: 1,
|
|
46
|
-
k: 128,
|
|
47
|
-
expand: 'xmd',
|
|
48
|
-
hash: sha2_1.sha256,
|
|
49
|
-
}))();
|
|
50
|
-
// Field over which we'll do calculations.
|
|
51
|
-
const Fp384 = (0, modular_ts_1.Field)(BigInt('0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff'));
|
|
52
|
-
const p384_a = Fp384.create(BigInt('-3'));
|
|
53
|
-
// prettier-ignore
|
|
54
|
-
const p384_b = BigInt('0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef');
|
|
55
|
-
/**
|
|
56
|
-
* secp384r1 curve, ECDSA and ECDH methods.
|
|
57
|
-
* Field: `2n**384n - 2n**128n - 2n**96n + 2n**32n - 1n`.
|
|
58
|
-
* */
|
|
59
|
-
// prettier-ignore
|
|
60
|
-
exports.p384 = (0, _shortw_utils_ts_1.createCurve)({
|
|
61
|
-
a: p384_a,
|
|
62
|
-
b: p384_b,
|
|
63
|
-
Fp: Fp384,
|
|
25
|
+
};
|
|
26
|
+
// p = 2n**384n - 2n**128n - 2n**96n + 2n**32n - 1n
|
|
27
|
+
const p384_CURVE = {
|
|
28
|
+
p: BigInt('0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff'),
|
|
64
29
|
n: BigInt('0xffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973'),
|
|
30
|
+
h: BigInt(1),
|
|
31
|
+
a: BigInt('0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000fffffffc'),
|
|
32
|
+
b: BigInt('0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef'),
|
|
65
33
|
Gx: BigInt('0xaa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7'),
|
|
66
34
|
Gy: BigInt('0x3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f'),
|
|
35
|
+
};
|
|
36
|
+
// p = 2n**521n - 1n
|
|
37
|
+
const p521_CURVE = {
|
|
38
|
+
p: BigInt('0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'),
|
|
39
|
+
n: BigInt('0x01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409'),
|
|
67
40
|
h: BigInt(1),
|
|
68
|
-
|
|
69
|
-
|
|
41
|
+
a: BigInt('0x1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc'),
|
|
42
|
+
b: BigInt('0x0051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00'),
|
|
43
|
+
Gx: BigInt('0x00c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66'),
|
|
44
|
+
Gy: BigInt('0x011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650'),
|
|
45
|
+
};
|
|
46
|
+
const Fp256 = (0, modular_ts_1.Field)(p256_CURVE.p);
|
|
47
|
+
const Fp384 = (0, modular_ts_1.Field)(p384_CURVE.p);
|
|
48
|
+
const Fp521 = (0, modular_ts_1.Field)(p521_CURVE.p);
|
|
49
|
+
function createSWU(field, opts) {
|
|
50
|
+
const map = (0, weierstrass_ts_1.mapToCurveSimpleSWU)(field, opts);
|
|
51
|
+
return (scalars) => map(scalars[0]);
|
|
52
|
+
}
|
|
53
|
+
/** NIST P256 (aka secp256r1, prime256v1) curve, ECDSA and ECDH methods. */
|
|
54
|
+
exports.p256 = (0, _shortw_utils_ts_1.createCurve)({ ...p256_CURVE, Fp: Fp256, lowS: false }, sha2_js_1.sha256);
|
|
55
|
+
/** Alias to p256. */
|
|
56
|
+
exports.secp256r1 = exports.p256;
|
|
57
|
+
/** Hashing / encoding to p256 points / field. RFC 9380 methods. */
|
|
58
|
+
exports.p256_hasher = (() => {
|
|
59
|
+
return (0, hash_to_curve_ts_1.createHasher)(exports.p256.Point, createSWU(Fp256, {
|
|
60
|
+
A: p256_CURVE.a,
|
|
61
|
+
B: p256_CURVE.b,
|
|
62
|
+
Z: Fp256.create(BigInt('-10')),
|
|
63
|
+
}), {
|
|
64
|
+
DST: 'P256_XMD:SHA-256_SSWU_RO_',
|
|
65
|
+
encodeDST: 'P256_XMD:SHA-256_SSWU_NU_',
|
|
66
|
+
p: p256_CURVE.p,
|
|
67
|
+
m: 1,
|
|
68
|
+
k: 128,
|
|
69
|
+
expand: 'xmd',
|
|
70
|
+
hash: sha2_js_1.sha256,
|
|
71
|
+
});
|
|
72
|
+
})();
|
|
73
|
+
/** NIST P384 (aka secp384r1) curve, ECDSA and ECDH methods. */
|
|
74
|
+
exports.p384 = (0, _shortw_utils_ts_1.createCurve)({ ...p384_CURVE, Fp: Fp384, lowS: false }, sha2_js_1.sha384);
|
|
70
75
|
/** Alias to p384. */
|
|
71
76
|
exports.secp384r1 = exports.p384;
|
|
72
|
-
const p384_mapSWU = /* @__PURE__ */ (() => (0, weierstrass_ts_1.mapToCurveSimpleSWU)(Fp384, {
|
|
73
|
-
A: p384_a,
|
|
74
|
-
B: p384_b,
|
|
75
|
-
Z: Fp384.create(BigInt('-12')),
|
|
76
|
-
}))();
|
|
77
77
|
/** Hashing / encoding to p384 points / field. RFC 9380 methods. */
|
|
78
|
-
exports.p384_hasher = (() =>
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
exports.p521 = (0, _shortw_utils_ts_1.createCurve)({
|
|
97
|
-
a: p521_a,
|
|
98
|
-
b: p521_b,
|
|
99
|
-
Fp: Fp521,
|
|
100
|
-
n: BigInt('0x01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409'),
|
|
101
|
-
Gx: BigInt('0x00c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66'),
|
|
102
|
-
Gy: BigInt('0x011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650'),
|
|
103
|
-
h: BigInt(1),
|
|
104
|
-
lowS: false,
|
|
105
|
-
allowedPrivateKeyLengths: [130, 131, 132] // P521 keys are variable-length. Normalize to 132b
|
|
106
|
-
}, sha2_1.sha512);
|
|
78
|
+
exports.p384_hasher = (() => {
|
|
79
|
+
return (0, hash_to_curve_ts_1.createHasher)(exports.p384.Point, createSWU(Fp384, {
|
|
80
|
+
A: p384_CURVE.a,
|
|
81
|
+
B: p384_CURVE.b,
|
|
82
|
+
Z: Fp384.create(BigInt('-12')),
|
|
83
|
+
}), {
|
|
84
|
+
DST: 'P384_XMD:SHA-384_SSWU_RO_',
|
|
85
|
+
encodeDST: 'P384_XMD:SHA-384_SSWU_NU_',
|
|
86
|
+
p: p384_CURVE.p,
|
|
87
|
+
m: 1,
|
|
88
|
+
k: 192,
|
|
89
|
+
expand: 'xmd',
|
|
90
|
+
hash: sha2_js_1.sha384,
|
|
91
|
+
});
|
|
92
|
+
})();
|
|
93
|
+
/** NIST P521 (aka secp521r1) curve, ECDSA and ECDH methods. */
|
|
94
|
+
exports.p521 = (0, _shortw_utils_ts_1.createCurve)({ ...p521_CURVE, Fp: Fp521, lowS: false, allowedPrivateKeyLengths: [130, 131, 132] }, sha2_js_1.sha512);
|
|
95
|
+
/** Alias to p521. */
|
|
107
96
|
exports.secp521r1 = exports.p521;
|
|
108
|
-
const p521_mapSWU = /* @__PURE__ */ (() => (0, weierstrass_ts_1.mapToCurveSimpleSWU)(Fp521, {
|
|
109
|
-
A: p521_a,
|
|
110
|
-
B: p521_b,
|
|
111
|
-
Z: Fp521.create(BigInt('-4')),
|
|
112
|
-
}))();
|
|
113
97
|
/** Hashing / encoding to p521 points / field. RFC 9380 methods. */
|
|
114
|
-
exports.p521_hasher = (() =>
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
98
|
+
exports.p521_hasher = (() => {
|
|
99
|
+
return (0, hash_to_curve_ts_1.createHasher)(exports.p521.Point, createSWU(Fp521, {
|
|
100
|
+
A: p521_CURVE.a,
|
|
101
|
+
B: p521_CURVE.b,
|
|
102
|
+
Z: Fp521.create(BigInt('-4')),
|
|
103
|
+
}), {
|
|
104
|
+
DST: 'P521_XMD:SHA-512_SSWU_RO_',
|
|
105
|
+
encodeDST: 'P521_XMD:SHA-512_SSWU_NU_',
|
|
106
|
+
p: p521_CURVE.p,
|
|
107
|
+
m: 1,
|
|
108
|
+
k: 256,
|
|
109
|
+
expand: 'xmd',
|
|
110
|
+
hash: sha2_js_1.sha512,
|
|
111
|
+
});
|
|
112
|
+
})();
|
|
123
113
|
//# sourceMappingURL=nist.js.map
|
package/nist.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nist.js","sourceRoot":"","sources":["src/nist.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACH,sEAAsE;AACtE,
|
|
1
|
+
{"version":3,"file":"nist.js","sourceRoot":"","sources":["src/nist.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACH,sEAAsE;AACtE,mDAA+D;AAC/D,yDAAyE;AACzE,kEAA2E;AAC3E,sDAA2D;AAC3D,8DAAsF;AAEtF,wDAAwD;AACxD,kCAAkC;AAClC,MAAM,UAAU,GAA4B;IAC1C,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,oEAAoE,CAAC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
import { type H2CMethod } from './abstract/hash-to-curve.ts';
|
|
7
7
|
import { p256 as p256n } from './nist.ts';
|
|
8
8
|
export declare const p256: typeof p256n;
|
|
9
9
|
export declare const secp256r1: typeof p256n;
|
|
10
|
-
export declare const hashToCurve:
|
|
11
|
-
export declare const encodeToCurve:
|
|
10
|
+
export declare const hashToCurve: H2CMethod<bigint>;
|
|
11
|
+
export declare const encodeToCurve: H2CMethod<bigint>;
|
|
12
12
|
//# sourceMappingURL=p256.d.ts.map
|
package/p384.d.ts
CHANGED
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
* @module
|
|
4
4
|
*/
|
|
5
5
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
6
|
-
import { type
|
|
6
|
+
import { type H2CMethod } from './abstract/hash-to-curve.ts';
|
|
7
7
|
import { p384 as p384n } from './nist.ts';
|
|
8
8
|
export declare const p384: typeof p384n;
|
|
9
9
|
export declare const secp384r1: typeof p384n;
|
|
10
|
-
export declare const hashToCurve:
|
|
11
|
-
export declare const encodeToCurve:
|
|
10
|
+
export declare const hashToCurve: H2CMethod<bigint>;
|
|
11
|
+
export declare const encodeToCurve: H2CMethod<bigint>;
|
|
12
12
|
/** @deprecated Use `import { p384_hasher } from "@noble/curves/nist"` module. */
|
|
13
13
|
//# sourceMappingURL=p384.d.ts.map
|
package/p521.d.ts
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
* @module
|
|
4
4
|
*/
|
|
5
5
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
6
|
-
import { type
|
|
6
|
+
import { type H2CMethod } from './abstract/hash-to-curve.ts';
|
|
7
7
|
import { p521 as p521n } from './nist.ts';
|
|
8
8
|
export declare const p521: typeof p521n;
|
|
9
9
|
export declare const secp521r1: typeof p521n;
|
|
10
|
-
export declare const hashToCurve:
|
|
11
|
-
export declare const encodeToCurve:
|
|
10
|
+
export declare const hashToCurve: H2CMethod<bigint>;
|
|
11
|
+
export declare const encodeToCurve: H2CMethod<bigint>;
|
|
12
12
|
//# sourceMappingURL=p521.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@noble/curves",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.2",
|
|
4
4
|
"description": "Audited & minimal JS implementation of elliptic curve cryptography",
|
|
5
5
|
"files": [
|
|
6
6
|
"*.js",
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
"abstract"
|
|
13
13
|
],
|
|
14
14
|
"scripts": {
|
|
15
|
-
"bench": "npm run bench:install; cd benchmark; node secp256k1.js; node curves.js; node utils.js; node bls.js",
|
|
16
|
-
"bench:install": "cd benchmark; npm install; npm install
|
|
15
|
+
"bench": "npm run bench:install; cd test/benchmark; node secp256k1.js; node curves.js; node utils.js; node bls.js",
|
|
16
|
+
"bench:install": "cd test/benchmark; npm install; npm install ../.. --install-links",
|
|
17
17
|
"build": "tsc && tsc -p tsconfig.cjs.json",
|
|
18
18
|
"build:release": "npx jsbt esbuild test/build",
|
|
19
19
|
"build:clean": "rm {.,esm,abstract,esm/abstract}/*.{js,d.ts,d.ts.map,js.map} 2> /dev/null",
|
|
@@ -35,10 +35,11 @@
|
|
|
35
35
|
"@noble/hashes": "1.8.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@paulmillr/jsbt": "0.
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"micro-
|
|
38
|
+
"@paulmillr/jsbt": "0.4.0",
|
|
39
|
+
"@types/node": "22.15.21",
|
|
40
|
+
"fast-check": "4.1.1",
|
|
41
|
+
"micro-bmark": "0.4.2",
|
|
42
|
+
"micro-should": "0.5.3",
|
|
42
43
|
"prettier": "3.5.3",
|
|
43
44
|
"typescript": "5.8.3"
|
|
44
45
|
},
|
|
@@ -89,6 +90,10 @@
|
|
|
89
90
|
"import": "./esm/abstract/weierstrass.js",
|
|
90
91
|
"require": "./abstract/weierstrass.js"
|
|
91
92
|
},
|
|
93
|
+
"./abstract/fft": {
|
|
94
|
+
"import": "./esm/abstract/fft.js",
|
|
95
|
+
"require": "./abstract/fft.js"
|
|
96
|
+
},
|
|
92
97
|
"./_shortw_utils": {
|
|
93
98
|
"import": "./esm/_shortw_utils.js",
|
|
94
99
|
"require": "./_shortw_utils.js"
|
|
@@ -145,6 +150,10 @@
|
|
|
145
150
|
"import": "./esm/secp256k1.js",
|
|
146
151
|
"require": "./secp256k1.js"
|
|
147
152
|
},
|
|
153
|
+
"./utils": {
|
|
154
|
+
"import": "./esm/utils.js",
|
|
155
|
+
"require": "./utils.js"
|
|
156
|
+
},
|
|
148
157
|
"./abstract/bls.js": {
|
|
149
158
|
"import": "./esm/abstract/bls.js",
|
|
150
159
|
"require": "./abstract/bls.js"
|
|
@@ -185,6 +194,10 @@
|
|
|
185
194
|
"import": "./esm/abstract/weierstrass.js",
|
|
186
195
|
"require": "./abstract/weierstrass.js"
|
|
187
196
|
},
|
|
197
|
+
"./abstract/fft.js": {
|
|
198
|
+
"import": "./esm/abstract/fft.js",
|
|
199
|
+
"require": "./abstract/fft.js"
|
|
200
|
+
},
|
|
188
201
|
"./_shortw_utils.js": {
|
|
189
202
|
"import": "./esm/_shortw_utils.js",
|
|
190
203
|
"require": "./_shortw_utils.js"
|
|
@@ -197,6 +210,10 @@
|
|
|
197
210
|
"import": "./esm/bn254.js",
|
|
198
211
|
"require": "./bn254.js"
|
|
199
212
|
},
|
|
213
|
+
"./utils.js": {
|
|
214
|
+
"import": "./esm/utils.js",
|
|
215
|
+
"require": "./utils.js"
|
|
216
|
+
},
|
|
200
217
|
"./ed448.js": {
|
|
201
218
|
"import": "./esm/ed448.js",
|
|
202
219
|
"require": "./ed448.js"
|
|
@@ -269,7 +286,8 @@
|
|
|
269
286
|
"weierstrass",
|
|
270
287
|
"montgomery",
|
|
271
288
|
"edwards",
|
|
272
|
-
"schnorr"
|
|
289
|
+
"schnorr",
|
|
290
|
+
"fft"
|
|
273
291
|
],
|
|
274
292
|
"funding": "https://paulmillr.com/funding/"
|
|
275
293
|
}
|
package/pasta.d.ts
CHANGED
package/pasta.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pasta.d.ts","sourceRoot":"","sources":["src/pasta.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,EAAE,EAAE,KAAK,IAAI,EAAE,EAAE,MAAM,WAAW,CAAC;AACtD,kBAAkB;AAClB,eAAO,MAAM,MAAM,EAAE,OAAO,EAAO,CAAC;AACpC,kBAAkB;AAClB,eAAO,MAAM,KAAK,EAAE,OAAO,EAAO,CAAC"}
|
|
1
|
+
{"version":3,"file":"pasta.d.ts","sourceRoot":"","sources":["src/pasta.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,MAAM,IAAI,EAAE,EAAE,KAAK,IAAI,EAAE,EAAE,MAAM,WAAW,CAAC;AACtD,kBAAkB;AAClB,eAAO,MAAM,MAAM,EAAE,OAAO,EAAO,CAAC;AACpC,kBAAkB;AAClB,eAAO,MAAM,KAAK,EAAE,OAAO,EAAO,CAAC"}
|
package/pasta.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.vesta = exports.pallas = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @deprecated
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
4
8
|
const misc_ts_1 = require("./misc.js");
|
|
5
9
|
/** @deprecated */
|
|
6
10
|
exports.pallas = misc_ts_1.pallas;
|
package/pasta.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pasta.js","sourceRoot":"","sources":["src/pasta.ts"],"names":[],"mappings":";;;AAAA,uCAAsD;AACtD,kBAAkB;AACL,QAAA,MAAM,GAAc,gBAAE,CAAC;AACpC,kBAAkB;AACL,QAAA,KAAK,GAAc,eAAE,CAAC"}
|
|
1
|
+
{"version":3,"file":"pasta.js","sourceRoot":"","sources":["src/pasta.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,uCAAsD;AACtD,kBAAkB;AACL,QAAA,MAAM,GAAc,gBAAE,CAAC;AACpC,kBAAkB;AACL,QAAA,KAAK,GAAc,eAAE,CAAC"}
|
package/secp256k1.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { type CurveFnWithCreate } from './_shortw_utils.ts';
|
|
2
|
-
import { type
|
|
2
|
+
import { type H2CHasher, type H2CMethod } from './abstract/hash-to-curve.ts';
|
|
3
3
|
import { mod } from './abstract/modular.ts';
|
|
4
|
-
import type { Hex, PrivKey } from './abstract/utils.ts';
|
|
5
|
-
import { bytesToNumberBE, numberToBytesBE } from './abstract/utils.ts';
|
|
6
4
|
import { type ProjPointType as PointType } from './abstract/weierstrass.ts';
|
|
5
|
+
import type { Hex, PrivKey } from './utils.ts';
|
|
6
|
+
import { bytesToNumberBE, numberToBytesBE } from './utils.ts';
|
|
7
7
|
/**
|
|
8
8
|
* secp256k1 curve, ECDSA and ECDH methods.
|
|
9
9
|
*
|
|
@@ -69,8 +69,8 @@ export type SecpSchnorr = {
|
|
|
69
69
|
*/
|
|
70
70
|
export declare const schnorr: SecpSchnorr;
|
|
71
71
|
/** Hashing / encoding to secp256k1 points / field. RFC 9380 methods. */
|
|
72
|
-
export declare const secp256k1_hasher:
|
|
73
|
-
export declare const hashToCurve:
|
|
74
|
-
export declare const encodeToCurve:
|
|
72
|
+
export declare const secp256k1_hasher: H2CHasher<bigint>;
|
|
73
|
+
export declare const hashToCurve: H2CMethod<bigint>;
|
|
74
|
+
export declare const encodeToCurve: H2CMethod<bigint>;
|
|
75
75
|
export {};
|
|
76
76
|
//# sourceMappingURL=secp256k1.d.ts.map
|
package/secp256k1.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"secp256k1.d.ts","sourceRoot":"","sources":["src/secp256k1.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"secp256k1.d.ts","sourceRoot":"","sources":["src/secp256k1.ts"],"names":[],"mappings":"AAUA,OAAO,EAAe,KAAK,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,SAAS,EAEf,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAS,GAAG,EAAQ,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAGL,KAAK,aAAa,IAAI,SAAS,EAEhC,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAEL,eAAe,EAIf,eAAe,EAChB,MAAM,YAAY,CAAC;AAiDpB;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,SAAS,EAAE,iBAgCvB,CAAC;AAMF,iBAAS,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,QAAQ,EAAE,UAAU,EAAE,GAAG,UAAU,CAQtE;AAiBD;;;GAGG;AACH,iBAAS,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,CAS5C;AASD;;GAEG;AACH,iBAAS,mBAAmB,CAAC,UAAU,EAAE,GAAG,GAAG,UAAU,CAExD;AAED;;;GAGG;AACH,iBAAS,WAAW,CAClB,OAAO,EAAE,GAAG,EACZ,UAAU,EAAE,OAAO,EACnB,OAAO,GAAE,GAAqB,GAC7B,UAAU,CAgBZ;AAED;;;GAGG;AACH,iBAAS,aAAa,CAAC,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,GAAG,OAAO,CAoB5E;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,YAAY,EAAE,OAAO,mBAAmB,CAAC;IACzC,IAAI,EAAE,OAAO,WAAW,CAAC;IACzB,MAAM,EAAE,OAAO,aAAa,CAAC;IAC7B,KAAK,EAAE;QACL,gBAAgB,EAAE,MAAM,UAAU,CAAC;QACnC,MAAM,EAAE,OAAO,MAAM,CAAC;QACtB,YAAY,EAAE,CAAC,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,KAAK,UAAU,CAAC;QACvD,eAAe,EAAE,OAAO,eAAe,CAAC;QACxC,eAAe,EAAE,OAAO,eAAe,CAAC;QACxC,UAAU,EAAE,OAAO,UAAU,CAAC;QAC9B,GAAG,EAAE,OAAO,GAAG,CAAC;KACjB,CAAC;CACH,CAAC;AACF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,OAAO,EAAE,WAajB,CAAC;AAyCN,wEAAwE;AACxE,eAAO,MAAM,gBAAgB,EAAE,SAAS,CAAC,MAAM,CAgBzC,CAAC;AAEP,eAAO,MAAM,WAAW,EAAE,SAAS,CAAC,MAAM,CACT,CAAC;AAElC,eAAO,MAAM,aAAa,EAAE,SAAS,CAAC,MAAM,CACT,CAAC"}
|
package/secp256k1.js
CHANGED
|
@@ -2,27 +2,33 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.encodeToCurve = exports.hashToCurve = exports.secp256k1_hasher = exports.schnorr = exports.secp256k1 = void 0;
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* SECG secp256k1. See [pdf](https://www.secg.org/sec2-v2.pdf).
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* secp256k1 belongs to Koblitz curves: it has efficiently computable endomorphism.
|
|
11
|
-
* Endomorphism uses 2x less RAM, speeds up precomputation by 2x and ECDH / key recovery by 20%.
|
|
12
|
-
* For precomputed wNAF it trades off 1/2 init time & 1/3 ram for 20% perf hit.
|
|
13
|
-
* [See explanation](https://gist.github.com/paulmillr/eb670806793e84df628a7c434a873066).
|
|
7
|
+
* Belongs to Koblitz curves: it has efficiently-computable GLV endomorphism ψ,
|
|
8
|
+
* check out {@link EndomorphismOpts}. Seems to be rigid (not backdoored).
|
|
14
9
|
* @module
|
|
15
10
|
*/
|
|
16
11
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
17
|
-
const
|
|
18
|
-
const
|
|
12
|
+
const sha2_js_1 = require("@noble/hashes/sha2.js");
|
|
13
|
+
const utils_js_1 = require("@noble/hashes/utils.js");
|
|
19
14
|
const _shortw_utils_ts_1 = require("./_shortw_utils.js");
|
|
20
15
|
const hash_to_curve_ts_1 = require("./abstract/hash-to-curve.js");
|
|
21
16
|
const modular_ts_1 = require("./abstract/modular.js");
|
|
22
|
-
const utils_ts_1 = require("./abstract/utils.js");
|
|
23
17
|
const weierstrass_ts_1 = require("./abstract/weierstrass.js");
|
|
24
|
-
const
|
|
25
|
-
|
|
18
|
+
const utils_ts_1 = require("./utils.js");
|
|
19
|
+
// Seems like generator was produced from some seed:
|
|
20
|
+
// `Point.BASE.multiply(Point.Fn.inv(2n, N)).toAffine().x`
|
|
21
|
+
// // gives short x 0x3b78ce563f89a0ed9414f5aa28ad0d96d6795f9c63n
|
|
22
|
+
const secp256k1_CURVE = {
|
|
23
|
+
p: BigInt('0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f'),
|
|
24
|
+
n: BigInt('0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141'),
|
|
25
|
+
h: BigInt(1),
|
|
26
|
+
a: BigInt(0),
|
|
27
|
+
b: BigInt(7),
|
|
28
|
+
Gx: BigInt('0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798'),
|
|
29
|
+
Gy: BigInt('0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8'),
|
|
30
|
+
};
|
|
31
|
+
const _0n = BigInt(0);
|
|
26
32
|
const _1n = BigInt(1);
|
|
27
33
|
const _2n = BigInt(2);
|
|
28
34
|
const divNearest = (a, b) => (a + b / _2n) / b;
|
|
@@ -31,7 +37,7 @@ const divNearest = (a, b) => (a + b / _2n) / b;
|
|
|
31
37
|
* (P+1n/4n).toString(2) would produce bits [223x 1, 0, 22x 1, 4x 0, 11, 00]
|
|
32
38
|
*/
|
|
33
39
|
function sqrtMod(y) {
|
|
34
|
-
const P =
|
|
40
|
+
const P = secp256k1_CURVE.p;
|
|
35
41
|
// prettier-ignore
|
|
36
42
|
const _3n = BigInt(3), _6n = BigInt(6), _11n = BigInt(11), _22n = BigInt(22);
|
|
37
43
|
// prettier-ignore
|
|
@@ -54,7 +60,7 @@ function sqrtMod(y) {
|
|
|
54
60
|
throw new Error('Cannot find square root');
|
|
55
61
|
return root;
|
|
56
62
|
}
|
|
57
|
-
const Fpk1 = (0, modular_ts_1.Field)(
|
|
63
|
+
const Fpk1 = (0, modular_ts_1.Field)(secp256k1_CURVE.p, undefined, undefined, { sqrt: sqrtMod });
|
|
58
64
|
/**
|
|
59
65
|
* secp256k1 curve, ECDSA and ECDH methods.
|
|
60
66
|
*
|
|
@@ -71,19 +77,14 @@ const Fpk1 = (0, modular_ts_1.Field)(secp256k1P, undefined, undefined, { sqrt: s
|
|
|
71
77
|
* ```
|
|
72
78
|
*/
|
|
73
79
|
exports.secp256k1 = (0, _shortw_utils_ts_1.createCurve)({
|
|
74
|
-
|
|
75
|
-
b: BigInt(7),
|
|
80
|
+
...secp256k1_CURVE,
|
|
76
81
|
Fp: Fpk1,
|
|
77
|
-
n: secp256k1N,
|
|
78
|
-
Gx: BigInt('55066263022277343669578718895168534326250603453777594175500187360389116729240'),
|
|
79
|
-
Gy: BigInt('32670510020758816978083085130507043184471273380659243275938904335757337482424'),
|
|
80
|
-
h: BigInt(1),
|
|
81
82
|
lowS: true, // Allow only low-S signatures by default in sign() and verify()
|
|
82
83
|
endo: {
|
|
83
84
|
// Endomorphism, see above
|
|
84
85
|
beta: BigInt('0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee'),
|
|
85
86
|
splitScalar: (k) => {
|
|
86
|
-
const n =
|
|
87
|
+
const n = secp256k1_CURVE.n;
|
|
87
88
|
const a1 = BigInt('0x3086d221a7d46bcde86c90e49284eb15');
|
|
88
89
|
const b1 = -_1n * BigInt('0xe4437ed6010e88286f547fa90abfe4c3');
|
|
89
90
|
const a2 = BigInt('0x114ca50f7a8e2f3f657c1108d9d44cfd8');
|
|
@@ -105,33 +106,32 @@ exports.secp256k1 = (0, _shortw_utils_ts_1.createCurve)({
|
|
|
105
106
|
return { k1neg, k1, k2neg, k2 };
|
|
106
107
|
},
|
|
107
108
|
},
|
|
108
|
-
},
|
|
109
|
+
}, sha2_js_1.sha256);
|
|
109
110
|
// Schnorr signatures are superior to ECDSA from above. Below is Schnorr-specific BIP0340 code.
|
|
110
111
|
// https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki
|
|
111
|
-
const _0n = BigInt(0);
|
|
112
112
|
/** An object mapping tags to their tagged hash prefix of [SHA256(tag) | SHA256(tag)] */
|
|
113
113
|
const TAGGED_HASH_PREFIXES = {};
|
|
114
114
|
function taggedHash(tag, ...messages) {
|
|
115
115
|
let tagP = TAGGED_HASH_PREFIXES[tag];
|
|
116
116
|
if (tagP === undefined) {
|
|
117
|
-
const tagH = (0,
|
|
117
|
+
const tagH = (0, sha2_js_1.sha256)(Uint8Array.from(tag, (c) => c.charCodeAt(0)));
|
|
118
118
|
tagP = (0, utils_ts_1.concatBytes)(tagH, tagH);
|
|
119
119
|
TAGGED_HASH_PREFIXES[tag] = tagP;
|
|
120
120
|
}
|
|
121
|
-
return (0,
|
|
121
|
+
return (0, sha2_js_1.sha256)((0, utils_ts_1.concatBytes)(tagP, ...messages));
|
|
122
122
|
}
|
|
123
123
|
// ECDSA compact points are 33-byte. Schnorr is 32: we strip first byte 0x02 or 0x03
|
|
124
|
-
const pointToBytes = (point) => point.
|
|
124
|
+
const pointToBytes = (point) => point.toBytes(true).slice(1);
|
|
125
125
|
const numTo32b = (n) => (0, utils_ts_1.numberToBytesBE)(n, 32);
|
|
126
|
-
const modP = (x) => (0, modular_ts_1.mod)(x,
|
|
127
|
-
const modN = (x) => (0, modular_ts_1.mod)(x,
|
|
128
|
-
const Point = exports.secp256k1.
|
|
129
|
-
const
|
|
126
|
+
const modP = (x) => (0, modular_ts_1.mod)(x, secp256k1_CURVE.p);
|
|
127
|
+
const modN = (x) => (0, modular_ts_1.mod)(x, secp256k1_CURVE.n);
|
|
128
|
+
const Point = /* @__PURE__ */ (() => exports.secp256k1.Point)();
|
|
129
|
+
const hasEven = (y) => y % _2n === _0n;
|
|
130
130
|
// Calculate point, scalar and bytes
|
|
131
131
|
function schnorrGetExtPubKey(priv) {
|
|
132
132
|
let d_ = exports.secp256k1.utils.normPrivateKeyToScalar(priv); // same method executed in fromPrivateKey
|
|
133
133
|
let p = Point.fromPrivateKey(d_); // P = d'⋅G; 0 < d' < n check is done inside
|
|
134
|
-
const scalar = p.
|
|
134
|
+
const scalar = hasEven(p.y) ? d_ : modN(-d_);
|
|
135
135
|
return { scalar: scalar, bytes: pointToBytes(p) };
|
|
136
136
|
}
|
|
137
137
|
/**
|
|
@@ -139,13 +139,13 @@ function schnorrGetExtPubKey(priv) {
|
|
|
139
139
|
* @returns valid point checked for being on-curve
|
|
140
140
|
*/
|
|
141
141
|
function lift_x(x) {
|
|
142
|
-
(0, utils_ts_1.aInRange)('x', x, _1n,
|
|
142
|
+
(0, utils_ts_1.aInRange)('x', x, _1n, secp256k1_CURVE.p); // Fail if x ≥ p.
|
|
143
143
|
const xx = modP(x * x);
|
|
144
144
|
const c = modP(xx * x + BigInt(7)); // Let c = x³ + 7 mod p.
|
|
145
145
|
let y = sqrtMod(c); // Let y = c^(p+1)/4 mod p.
|
|
146
|
-
if (y
|
|
146
|
+
if (!hasEven(y))
|
|
147
147
|
y = modP(-y); // Return the unique point P such that x(P) = x and
|
|
148
|
-
const p =
|
|
148
|
+
const p = Point.fromAffine({ x, y }); // y(P) = y if y mod 2 = 0 or y(P) = p-y otherwise.
|
|
149
149
|
p.assertValidity();
|
|
150
150
|
return p;
|
|
151
151
|
}
|
|
@@ -166,7 +166,7 @@ function schnorrGetPublicKey(privateKey) {
|
|
|
166
166
|
* Creates Schnorr signature as per BIP340. Verifies itself before returning anything.
|
|
167
167
|
* auxRand is optional and is not the sole source of k generation: bad CSPRNG won't be dangerous.
|
|
168
168
|
*/
|
|
169
|
-
function schnorrSign(message, privateKey, auxRand = (0,
|
|
169
|
+
function schnorrSign(message, privateKey, auxRand = (0, utils_js_1.randomBytes)(32)) {
|
|
170
170
|
const m = (0, utils_ts_1.ensureBytes)('message', message);
|
|
171
171
|
const { bytes: px, scalar: d } = schnorrGetExtPubKey(privateKey); // checks for isWithinCurveOrder
|
|
172
172
|
const a = (0, utils_ts_1.ensureBytes)('auxRand', auxRand, 32); // Auxiliary random data a: a 32-byte array
|
|
@@ -196,16 +196,19 @@ function schnorrVerify(signature, message, publicKey) {
|
|
|
196
196
|
try {
|
|
197
197
|
const P = lift_x(num(pub)); // P = lift_x(int(pk)); fail if that fails
|
|
198
198
|
const r = num(sig.subarray(0, 32)); // Let r = int(sig[0:32]); fail if r ≥ p.
|
|
199
|
-
if (!(0, utils_ts_1.inRange)(r, _1n,
|
|
199
|
+
if (!(0, utils_ts_1.inRange)(r, _1n, secp256k1_CURVE.p))
|
|
200
200
|
return false;
|
|
201
201
|
const s = num(sig.subarray(32, 64)); // Let s = int(sig[32:64]); fail if s ≥ n.
|
|
202
|
-
if (!(0, utils_ts_1.inRange)(s, _1n,
|
|
202
|
+
if (!(0, utils_ts_1.inRange)(s, _1n, secp256k1_CURVE.n))
|
|
203
203
|
return false;
|
|
204
204
|
const e = challenge(numTo32b(r), pointToBytes(P), m); // int(challenge(bytes(r)||bytes(P)||m))%n
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
205
|
+
// R = s⋅G - e⋅P, where -eP == (n-e)P
|
|
206
|
+
const R = Point.BASE.multiplyUnsafe(s).add(P.multiplyUnsafe(modN(-e)));
|
|
207
|
+
const { x, y } = R.toAffine();
|
|
208
|
+
// Fail if is_infinite(R) / not has_even_y(R) / x(R) ≠ r.
|
|
209
|
+
if (R.is0() || !hasEven(y) || x !== r)
|
|
210
|
+
return false;
|
|
211
|
+
return true;
|
|
209
212
|
}
|
|
210
213
|
catch (error) {
|
|
211
214
|
return false;
|
|
@@ -273,7 +276,7 @@ const mapSWU = /* @__PURE__ */ (() => (0, weierstrass_ts_1.mapToCurveSimpleSWU)(
|
|
|
273
276
|
Z: Fpk1.create(BigInt('-11')),
|
|
274
277
|
}))();
|
|
275
278
|
/** Hashing / encoding to secp256k1 points / field. RFC 9380 methods. */
|
|
276
|
-
exports.secp256k1_hasher = (() => (0, hash_to_curve_ts_1.createHasher)(exports.secp256k1.
|
|
279
|
+
exports.secp256k1_hasher = (() => (0, hash_to_curve_ts_1.createHasher)(exports.secp256k1.Point, (scalars) => {
|
|
277
280
|
const { x, y } = mapSWU(Fpk1.create(scalars[0]));
|
|
278
281
|
return isoMap(x, y);
|
|
279
282
|
}, {
|
|
@@ -283,7 +286,7 @@ exports.secp256k1_hasher = (() => (0, hash_to_curve_ts_1.createHasher)(exports.s
|
|
|
283
286
|
m: 1,
|
|
284
287
|
k: 128,
|
|
285
288
|
expand: 'xmd',
|
|
286
|
-
hash:
|
|
289
|
+
hash: sha2_js_1.sha256,
|
|
287
290
|
}))();
|
|
288
291
|
exports.hashToCurve = (() => exports.secp256k1_hasher.hashToCurve)();
|
|
289
292
|
exports.encodeToCurve = (() => exports.secp256k1_hasher.encodeToCurve)();
|