@noble/curves 1.8.1 → 1.9.0
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 +305 -433
- package/_shortw_utils.d.ts +2 -2
- package/_shortw_utils.js +2 -2
- package/abstract/bls.d.ts +5 -5
- package/abstract/bls.d.ts.map +1 -1
- package/abstract/bls.js +15 -16
- package/abstract/bls.js.map +1 -1
- package/abstract/curve.d.ts +11 -3
- package/abstract/curve.d.ts.map +1 -1
- package/abstract/curve.js +81 -78
- package/abstract/curve.js.map +1 -1
- package/abstract/edwards.d.ts +2 -2
- package/abstract/edwards.d.ts.map +1 -1
- package/abstract/edwards.js +58 -71
- package/abstract/edwards.js.map +1 -1
- package/abstract/hash-to-curve.d.ts +15 -9
- package/abstract/hash-to-curve.d.ts.map +1 -1
- package/abstract/hash-to-curve.js +49 -39
- package/abstract/hash-to-curve.js.map +1 -1
- package/abstract/modular.d.ts +11 -8
- package/abstract/modular.d.ts.map +1 -1
- package/abstract/modular.js +79 -67
- package/abstract/modular.js.map +1 -1
- package/abstract/montgomery.d.ts.map +1 -1
- package/abstract/montgomery.js +13 -12
- package/abstract/montgomery.js.map +1 -1
- package/abstract/poseidon.d.ts +40 -3
- package/abstract/poseidon.d.ts.map +1 -1
- package/abstract/poseidon.js +186 -7
- package/abstract/poseidon.js.map +1 -1
- package/abstract/tower.d.ts +2 -2
- package/abstract/tower.d.ts.map +1 -1
- package/abstract/tower.js +16 -17
- package/abstract/tower.js.map +1 -1
- package/abstract/utils.d.ts +5 -2
- package/abstract/utils.d.ts.map +1 -1
- package/abstract/utils.js +27 -14
- package/abstract/utils.js.map +1 -1
- package/abstract/weierstrass.d.ts +21 -9
- package/abstract/weierstrass.d.ts.map +1 -1
- package/abstract/weierstrass.js +103 -86
- package/abstract/weierstrass.js.map +1 -1
- package/bls12-381.d.ts +1 -1
- package/bls12-381.js +41 -41
- package/bls12-381.js.map +1 -1
- package/bn254.d.ts +3 -2
- package/bn254.d.ts.map +1 -1
- package/bn254.js +39 -29
- package/bn254.js.map +1 -1
- package/ed25519.d.ts +9 -6
- package/ed25519.d.ts.map +1 -1
- package/ed25519.js +70 -71
- package/ed25519.js.map +1 -1
- package/ed448.d.ts +7 -6
- package/ed448.d.ts.map +1 -1
- package/ed448.js +54 -56
- package/ed448.js.map +1 -1
- package/esm/_shortw_utils.d.ts +2 -2
- package/esm/_shortw_utils.js +1 -1
- package/esm/abstract/bls.d.ts +5 -5
- package/esm/abstract/bls.d.ts.map +1 -1
- package/esm/abstract/bls.js +6 -7
- package/esm/abstract/bls.js.map +1 -1
- package/esm/abstract/curve.d.ts +11 -3
- package/esm/abstract/curve.d.ts.map +1 -1
- package/esm/abstract/curve.js +77 -74
- package/esm/abstract/curve.js.map +1 -1
- package/esm/abstract/edwards.d.ts +2 -2
- package/esm/abstract/edwards.d.ts.map +1 -1
- package/esm/abstract/edwards.js +39 -52
- package/esm/abstract/edwards.js.map +1 -1
- package/esm/abstract/hash-to-curve.d.ts +15 -9
- package/esm/abstract/hash-to-curve.d.ts.map +1 -1
- package/esm/abstract/hash-to-curve.js +33 -23
- package/esm/abstract/hash-to-curve.js.map +1 -1
- package/esm/abstract/modular.d.ts +11 -8
- package/esm/abstract/modular.d.ts.map +1 -1
- package/esm/abstract/modular.js +71 -59
- package/esm/abstract/modular.js.map +1 -1
- package/esm/abstract/montgomery.d.ts.map +1 -1
- package/esm/abstract/montgomery.js +4 -3
- package/esm/abstract/montgomery.js.map +1 -1
- package/esm/abstract/poseidon.d.ts +40 -3
- package/esm/abstract/poseidon.d.ts.map +1 -1
- package/esm/abstract/poseidon.js +180 -5
- package/esm/abstract/poseidon.js.map +1 -1
- package/esm/abstract/tower.d.ts +2 -2
- package/esm/abstract/tower.d.ts.map +1 -1
- package/esm/abstract/tower.js +8 -9
- package/esm/abstract/tower.js.map +1 -1
- package/esm/abstract/utils.d.ts +5 -2
- package/esm/abstract/utils.d.ts.map +1 -1
- package/esm/abstract/utils.js +26 -13
- package/esm/abstract/utils.js.map +1 -1
- package/esm/abstract/weierstrass.d.ts +21 -9
- package/esm/abstract/weierstrass.d.ts.map +1 -1
- package/esm/abstract/weierstrass.js +76 -59
- package/esm/abstract/weierstrass.js.map +1 -1
- package/esm/bls12-381.d.ts +1 -1
- package/esm/bls12-381.js +9 -9
- package/esm/bls12-381.js.map +1 -1
- package/esm/bn254.d.ts +3 -2
- package/esm/bn254.d.ts.map +1 -1
- package/esm/bn254.js +17 -7
- package/esm/bn254.js.map +1 -1
- package/esm/ed25519.d.ts +9 -6
- package/esm/ed25519.d.ts.map +1 -1
- package/esm/ed25519.js +25 -26
- package/esm/ed25519.js.map +1 -1
- package/esm/ed448.d.ts +7 -6
- package/esm/ed448.d.ts.map +1 -1
- package/esm/ed448.js +17 -19
- package/esm/ed448.js.map +1 -1
- package/esm/jubjub.d.ts +7 -4
- package/esm/jubjub.d.ts.map +1 -1
- package/esm/jubjub.js +7 -60
- package/esm/jubjub.js.map +1 -1
- package/esm/misc.d.ts +21 -0
- package/esm/misc.d.ts.map +1 -0
- package/esm/misc.js +107 -0
- package/esm/misc.js.map +1 -0
- package/esm/nist.d.ts +29 -0
- package/esm/nist.d.ts.map +1 -0
- package/esm/nist.js +120 -0
- package/esm/nist.js.map +1 -0
- package/esm/p256.d.ts +9 -8
- package/esm/p256.d.ts.map +1 -1
- package/esm/p256.js +6 -43
- package/esm/p256.js.map +1 -1
- package/esm/p384.d.ts +10 -8
- package/esm/p384.d.ts.map +1 -1
- package/esm/p384.js +7 -47
- package/esm/p384.js.map +1 -1
- package/esm/p521.d.ts +6 -6
- package/esm/p521.d.ts.map +1 -1
- package/esm/p521.js +6 -55
- package/esm/p521.js.map +1 -1
- package/esm/pasta.d.ts +5 -7
- package/esm/pasta.d.ts.map +1 -1
- package/esm/pasta.js +5 -33
- package/esm/pasta.js.map +1 -1
- package/esm/secp256k1.d.ts +15 -10
- package/esm/secp256k1.d.ts.map +1 -1
- package/esm/secp256k1.js +21 -18
- package/esm/secp256k1.js.map +1 -1
- package/jubjub.d.ts +7 -4
- package/jubjub.d.ts.map +1 -1
- package/jubjub.js +8 -63
- package/jubjub.js.map +1 -1
- package/misc.d.ts +21 -0
- package/misc.d.ts.map +1 -0
- package/misc.js +112 -0
- package/misc.js.map +1 -0
- package/nist.d.ts +29 -0
- package/nist.d.ts.map +1 -0
- package/nist.js +123 -0
- package/nist.js.map +1 -0
- package/p256.d.ts +9 -8
- package/p256.d.ts.map +1 -1
- package/p256.js +5 -48
- package/p256.js.map +1 -1
- package/p384.d.ts +10 -8
- package/p384.d.ts.map +1 -1
- package/p384.js +6 -52
- package/p384.js.map +1 -1
- package/p521.d.ts +6 -6
- package/p521.d.ts.map +1 -1
- package/p521.js +5 -60
- package/p521.js.map +1 -1
- package/package.json +116 -12
- package/pasta.d.ts +5 -7
- package/pasta.d.ts.map +1 -1
- package/pasta.js +6 -34
- package/pasta.js.map +1 -1
- package/secp256k1.d.ts +15 -10
- package/secp256k1.d.ts.map +1 -1
- package/secp256k1.js +60 -57
- package/secp256k1.js.map +1 -1
- package/src/_shortw_utils.ts +2 -2
- package/src/abstract/bls.ts +10 -10
- package/src/abstract/curve.ts +89 -80
- package/src/abstract/edwards.ts +56 -63
- package/src/abstract/hash-to-curve.ts +49 -39
- package/src/abstract/modular.ts +68 -59
- package/src/abstract/montgomery.ts +4 -3
- package/src/abstract/poseidon.ts +208 -13
- package/src/abstract/tower.ts +9 -10
- package/src/abstract/utils.ts +28 -15
- package/src/abstract/weierstrass.ts +105 -87
- package/src/bls12-381.ts +10 -10
- package/src/bn254.ts +18 -8
- package/src/ed25519.ts +31 -28
- package/src/ed448.ts +24 -21
- package/src/jubjub.ts +8 -63
- package/src/misc.ts +123 -0
- package/src/nist.ts +154 -0
- package/src/p256.ts +6 -49
- package/src/p384.ts +8 -53
- package/src/p521.ts +6 -70
- package/src/pasta.ts +5 -39
- package/src/secp256k1.ts +25 -20
package/src/p256.ts
CHANGED
|
@@ -1,54 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* NIST secp256r1 aka p256.
|
|
3
|
-
* https://www.secg.org/sec2-v2.pdf, https://neuromancer.sk/std/nist/P-256
|
|
4
3
|
* @module
|
|
5
4
|
*/
|
|
6
5
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const Fp256 = Field(BigInt('0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff'));
|
|
14
|
-
const CURVE_A = Fp256.create(BigInt('-3'));
|
|
15
|
-
const CURVE_B = BigInt('0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b');
|
|
16
|
-
|
|
17
|
-
/** secp256r1 curve, ECDSA and ECDH methods. */
|
|
18
|
-
// prettier-ignore
|
|
19
|
-
export const p256: CurveFnWithCreate = createCurve({
|
|
20
|
-
a: CURVE_A, // Equation params: a, b
|
|
21
|
-
b: CURVE_B,
|
|
22
|
-
Fp: Fp256, // Field: 2n**224n * (2n**32n-1n) + 2n**192n + 2n**96n-1n
|
|
23
|
-
// Curve order, total count of valid points in the field
|
|
24
|
-
n: BigInt('0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551'),
|
|
25
|
-
// Base (generator) point (x, y)
|
|
26
|
-
Gx: BigInt('0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296'),
|
|
27
|
-
Gy: BigInt('0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5'),
|
|
28
|
-
h: BigInt(1),
|
|
29
|
-
lowS: false,
|
|
30
|
-
} as const, sha256);
|
|
31
|
-
/** Alias to p256. */
|
|
32
|
-
export const secp256r1: CurveFnWithCreate = p256;
|
|
33
|
-
|
|
34
|
-
const mapSWU = /* @__PURE__ */ (() =>
|
|
35
|
-
mapToCurveSimpleSWU(Fp256, {
|
|
36
|
-
A: CURVE_A,
|
|
37
|
-
B: CURVE_B,
|
|
38
|
-
Z: Fp256.create(BigInt('-10')),
|
|
39
|
-
}))();
|
|
40
|
-
|
|
41
|
-
const htf = /* @__PURE__ */ (() =>
|
|
42
|
-
createHasher(secp256r1.ProjectivePoint, (scalars: bigint[]) => mapSWU(scalars[0]), {
|
|
43
|
-
DST: 'P256_XMD:SHA-256_SSWU_RO_',
|
|
44
|
-
encodeDST: 'P256_XMD:SHA-256_SSWU_NU_',
|
|
45
|
-
p: Fp256.ORDER,
|
|
46
|
-
m: 1,
|
|
47
|
-
k: 128,
|
|
48
|
-
expand: 'xmd',
|
|
49
|
-
hash: sha256,
|
|
50
|
-
}))();
|
|
51
|
-
/** secp256r1 hash-to-curve from [RFC 9380](https://www.rfc-editor.org/rfc/rfc9380). */
|
|
52
|
-
export const hashToCurve: HTFMethod<bigint> = /* @__PURE__ */ (() => htf.hashToCurve)();
|
|
53
|
-
/** secp256r1 encode-to-curve from [RFC 9380](https://www.rfc-editor.org/rfc/rfc9380). */
|
|
54
|
-
export const encodeToCurve: HTFMethod<bigint> = /* @__PURE__ */ (() => htf.encodeToCurve)();
|
|
6
|
+
import { type HTFMethod } from './abstract/hash-to-curve.ts';
|
|
7
|
+
import { p256_hasher, p256 as p256n } from './nist.ts';
|
|
8
|
+
export const p256: typeof p256n = p256n;
|
|
9
|
+
export const secp256r1: typeof p256n = p256n;
|
|
10
|
+
export const hashToCurve: HTFMethod<bigint> = /* @__PURE__ */ (() => p256_hasher.hashToCurve)();
|
|
11
|
+
export const encodeToCurve: HTFMethod<bigint> = /* @__PURE__ */ (() => p256_hasher.encodeToCurve)();
|
package/src/p384.ts
CHANGED
|
@@ -1,58 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* NIST secp384r1 aka p384.
|
|
3
|
-
* https://www.secg.org/sec2-v2.pdf, https://neuromancer.sk/std/nist/P-384
|
|
4
3
|
* @module
|
|
5
4
|
*/
|
|
6
5
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const P = BigInt('0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff');
|
|
16
|
-
const Fp384 = Field(P);
|
|
17
|
-
const CURVE_A = Fp384.create(BigInt('-3'));
|
|
18
|
-
// prettier-ignore
|
|
19
|
-
const CURVE_B = BigInt('0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef');
|
|
20
|
-
|
|
21
|
-
/** secp384r1 curve, ECDSA and ECDH methods. */
|
|
22
|
-
// prettier-ignore
|
|
23
|
-
export const p384: CurveFnWithCreate = createCurve({
|
|
24
|
-
a: CURVE_A, // Equation params: a, b
|
|
25
|
-
b: CURVE_B,
|
|
26
|
-
Fp: Fp384, // Field: 2n**384n - 2n**128n - 2n**96n + 2n**32n - 1n
|
|
27
|
-
// Curve order, total count of valid points in the field.
|
|
28
|
-
n: BigInt('0xffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973'),
|
|
29
|
-
// Base (generator) point (x, y)
|
|
30
|
-
Gx: BigInt('0xaa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7'),
|
|
31
|
-
Gy: BigInt('0x3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f'),
|
|
32
|
-
h: BigInt(1),
|
|
33
|
-
lowS: false,
|
|
34
|
-
} as const, sha384);
|
|
35
|
-
/** Alias to p384. */
|
|
36
|
-
export const secp384r1: CurveFnWithCreate = p384;
|
|
37
|
-
|
|
38
|
-
const mapSWU = /* @__PURE__ */ (() =>
|
|
39
|
-
mapToCurveSimpleSWU(Fp384, {
|
|
40
|
-
A: CURVE_A,
|
|
41
|
-
B: CURVE_B,
|
|
42
|
-
Z: Fp384.create(BigInt('-12')),
|
|
43
|
-
}))();
|
|
44
|
-
|
|
45
|
-
const htf = /* @__PURE__ */ (() =>
|
|
46
|
-
createHasher(secp384r1.ProjectivePoint, (scalars: bigint[]) => mapSWU(scalars[0]), {
|
|
47
|
-
DST: 'P384_XMD:SHA-384_SSWU_RO_',
|
|
48
|
-
encodeDST: 'P384_XMD:SHA-384_SSWU_NU_',
|
|
49
|
-
p: Fp384.ORDER,
|
|
50
|
-
m: 1,
|
|
51
|
-
k: 192,
|
|
52
|
-
expand: 'xmd',
|
|
53
|
-
hash: sha384,
|
|
54
|
-
}))();
|
|
55
|
-
/** secp384r1 hash-to-curve from [RFC 9380](https://www.rfc-editor.org/rfc/rfc9380). */
|
|
56
|
-
export const hashToCurve: HTFMethod<bigint> = /* @__PURE__ */ (() => htf.hashToCurve)();
|
|
57
|
-
/** secp384r1 encode-to-curve from [RFC 9380](https://www.rfc-editor.org/rfc/rfc9380). */
|
|
58
|
-
export const encodeToCurve: HTFMethod<bigint> = /* @__PURE__ */ (() => htf.encodeToCurve)();
|
|
6
|
+
import { type HTFMethod } from './abstract/hash-to-curve.ts';
|
|
7
|
+
import { p384_hasher, p384 as p384n } from './nist.ts';
|
|
8
|
+
export const p384: typeof p384n = p384n;
|
|
9
|
+
export const secp384r1: typeof p384n = p384n;
|
|
10
|
+
export const hashToCurve: HTFMethod<bigint> = /* @__PURE__ */ (() => p384_hasher.hashToCurve)();
|
|
11
|
+
export const encodeToCurve: HTFMethod<bigint> = /* @__PURE__ */ (() => p384_hasher.encodeToCurve)();
|
|
12
|
+
|
|
13
|
+
/** @deprecated Use `import { p384_hasher } from "@noble/curves/nist"` module. */
|
package/src/p521.ts
CHANGED
|
@@ -1,75 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* NIST secp521r1 aka p521.
|
|
3
|
-
* Note that it's 521, which differs from 512 of its hash function.
|
|
4
|
-
* https://www.secg.org/sec2-v2.pdf, https://neuromancer.sk/std/nist/P-521
|
|
5
3
|
* @module
|
|
6
4
|
*/
|
|
7
5
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
// Field over which we'll do calculations.
|
|
15
|
-
// prettier-ignore
|
|
16
|
-
const P = BigInt('0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff');
|
|
17
|
-
const Fp521 = Field(P);
|
|
18
|
-
|
|
19
|
-
const CURVE = {
|
|
20
|
-
a: Fp521.create(BigInt('-3')),
|
|
21
|
-
b: BigInt(
|
|
22
|
-
'0x0051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00'
|
|
23
|
-
),
|
|
24
|
-
Fp: Fp521,
|
|
25
|
-
n: BigInt(
|
|
26
|
-
'0x01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409'
|
|
27
|
-
),
|
|
28
|
-
Gx: BigInt(
|
|
29
|
-
'0x00c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66'
|
|
30
|
-
),
|
|
31
|
-
Gy: BigInt(
|
|
32
|
-
'0x011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650'
|
|
33
|
-
),
|
|
34
|
-
h: BigInt(1),
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* NIST secp521r1 aka p521.
|
|
39
|
-
*/
|
|
40
|
-
// prettier-ignore
|
|
41
|
-
export const p521: CurveFnWithCreate = createCurve({
|
|
42
|
-
a: CURVE.a, // Equation params: a, b
|
|
43
|
-
b: CURVE.b,
|
|
44
|
-
Fp: Fp521, // Field: 2n**521n - 1n
|
|
45
|
-
// Curve order, total count of valid points in the field
|
|
46
|
-
n: CURVE.n,
|
|
47
|
-
Gx: CURVE.Gx, // Base point (x, y) aka generator point
|
|
48
|
-
Gy: CURVE.Gy,
|
|
49
|
-
h: CURVE.h,
|
|
50
|
-
lowS: false,
|
|
51
|
-
allowedPrivateKeyLengths: [130, 131, 132] // P521 keys are variable-length. Normalize to 132b
|
|
52
|
-
} as const, sha512);
|
|
53
|
-
export const secp521r1: CurveFnWithCreate = p521;
|
|
54
|
-
|
|
55
|
-
const mapSWU = /* @__PURE__ */ (() =>
|
|
56
|
-
mapToCurveSimpleSWU(Fp521, {
|
|
57
|
-
A: CURVE.a,
|
|
58
|
-
B: CURVE.b,
|
|
59
|
-
Z: Fp521.create(BigInt('-4')),
|
|
60
|
-
}))();
|
|
61
|
-
|
|
62
|
-
const htf = /* @__PURE__ */ (() =>
|
|
63
|
-
createHasher(secp521r1.ProjectivePoint, (scalars: bigint[]) => mapSWU(scalars[0]), {
|
|
64
|
-
DST: 'P521_XMD:SHA-512_SSWU_RO_',
|
|
65
|
-
encodeDST: 'P521_XMD:SHA-512_SSWU_NU_',
|
|
66
|
-
p: Fp521.ORDER,
|
|
67
|
-
m: 1,
|
|
68
|
-
k: 256,
|
|
69
|
-
expand: 'xmd',
|
|
70
|
-
hash: sha512,
|
|
71
|
-
}))();
|
|
72
|
-
/** secp521r1 hash-to-curve from [RFC 9380](https://www.rfc-editor.org/rfc/rfc9380). */
|
|
73
|
-
export const hashToCurve: HTFMethod<bigint> = /* @__PURE__ */ (() => htf.hashToCurve)();
|
|
74
|
-
/** secp521r1 encode-to-curve from [RFC 9380](https://www.rfc-editor.org/rfc/rfc9380). */
|
|
75
|
-
export const encodeToCurve: HTFMethod<bigint> = /* @__PURE__ */ (() => htf.encodeToCurve)();
|
|
6
|
+
import { type HTFMethod } from './abstract/hash-to-curve.ts';
|
|
7
|
+
import { p521_hasher, p521 as p521n } from './nist.ts';
|
|
8
|
+
export const p521: typeof p521n = p521n;
|
|
9
|
+
export const secp521r1: typeof p521n = p521n;
|
|
10
|
+
export const hashToCurve: HTFMethod<bigint> = /* @__PURE__ */ (() => p521_hasher.hashToCurve)();
|
|
11
|
+
export const encodeToCurve: HTFMethod<bigint> = /* @__PURE__ */ (() => p521_hasher.encodeToCurve)();
|
package/src/pasta.ts
CHANGED
|
@@ -1,39 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { sha256 } from '@noble/hashes/sha256';
|
|
7
|
-
import { getHash } from './_shortw_utils.js';
|
|
8
|
-
import { Field, mod } from './abstract/modular.js';
|
|
9
|
-
import { type CurveFn, weierstrass } from './abstract/weierstrass.js';
|
|
10
|
-
|
|
11
|
-
export const p: bigint = BigInt(
|
|
12
|
-
'0x40000000000000000000000000000000224698fc094cf91b992d30ed00000001'
|
|
13
|
-
);
|
|
14
|
-
export const q: bigint = BigInt(
|
|
15
|
-
'0x40000000000000000000000000000000224698fc0994a8dd8c46eb2100000001'
|
|
16
|
-
);
|
|
17
|
-
|
|
18
|
-
/** https://neuromancer.sk/std/other/Pallas */
|
|
19
|
-
export const pallas: CurveFn = weierstrass({
|
|
20
|
-
a: BigInt(0),
|
|
21
|
-
b: BigInt(5),
|
|
22
|
-
Fp: Field(p),
|
|
23
|
-
n: q,
|
|
24
|
-
Gx: mod(BigInt(-1), p),
|
|
25
|
-
Gy: BigInt(2),
|
|
26
|
-
h: BigInt(1),
|
|
27
|
-
...getHash(sha256),
|
|
28
|
-
});
|
|
29
|
-
/** https://neuromancer.sk/std/other/Vesta */
|
|
30
|
-
export const vesta: CurveFn = weierstrass({
|
|
31
|
-
a: BigInt(0),
|
|
32
|
-
b: BigInt(5),
|
|
33
|
-
Fp: Field(q),
|
|
34
|
-
n: p,
|
|
35
|
-
Gx: mod(BigInt(-1), q),
|
|
36
|
-
Gy: BigInt(2),
|
|
37
|
-
h: BigInt(1),
|
|
38
|
-
...getHash(sha256),
|
|
39
|
-
});
|
|
1
|
+
import { pallas as pn, vesta as vn } from './misc.ts';
|
|
2
|
+
/** @deprecated */
|
|
3
|
+
export const pallas: typeof pn = pn;
|
|
4
|
+
/** @deprecated */
|
|
5
|
+
export const vesta: typeof vn = vn;
|
package/src/secp256k1.ts
CHANGED
|
@@ -11,12 +11,12 @@
|
|
|
11
11
|
* @module
|
|
12
12
|
*/
|
|
13
13
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
14
|
-
import { sha256 } from '@noble/hashes/
|
|
14
|
+
import { sha256 } from '@noble/hashes/sha2';
|
|
15
15
|
import { randomBytes } from '@noble/hashes/utils';
|
|
16
|
-
import { createCurve, type CurveFnWithCreate } from './_shortw_utils.
|
|
17
|
-
import { createHasher, type HTFMethod, isogenyMap } from './abstract/hash-to-curve.
|
|
18
|
-
import { Field, mod, pow2 } from './abstract/modular.
|
|
19
|
-
import type { Hex, PrivKey } from './abstract/utils.
|
|
16
|
+
import { createCurve, type CurveFnWithCreate } from './_shortw_utils.ts';
|
|
17
|
+
import { createHasher, type Hasher, type HTFMethod, isogenyMap } from './abstract/hash-to-curve.ts';
|
|
18
|
+
import { Field, mod, pow2 } from './abstract/modular.ts';
|
|
19
|
+
import type { Hex, PrivKey } from './abstract/utils.ts';
|
|
20
20
|
import {
|
|
21
21
|
aInRange,
|
|
22
22
|
bytesToNumberBE,
|
|
@@ -24,8 +24,8 @@ import {
|
|
|
24
24
|
ensureBytes,
|
|
25
25
|
inRange,
|
|
26
26
|
numberToBytesBE,
|
|
27
|
-
} from './abstract/utils.
|
|
28
|
-
import { mapToCurveSimpleSWU, type ProjPointType as PointType } from './abstract/weierstrass.
|
|
27
|
+
} from './abstract/utils.ts';
|
|
28
|
+
import { mapToCurveSimpleSWU, type ProjPointType as PointType } from './abstract/weierstrass.ts';
|
|
29
29
|
|
|
30
30
|
const secp256k1P = BigInt('0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f');
|
|
31
31
|
const secp256k1N = BigInt('0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141');
|
|
@@ -64,27 +64,29 @@ function sqrtMod(y: bigint): bigint {
|
|
|
64
64
|
const Fpk1 = Field(secp256k1P, undefined, undefined, { sqrt: sqrtMod });
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
|
-
* secp256k1
|
|
67
|
+
* secp256k1 curve, ECDSA and ECDH methods.
|
|
68
|
+
*
|
|
69
|
+
* Field: `2n**256n - 2n**32n - 2n**9n - 2n**8n - 2n**7n - 2n**6n - 2n**4n - 1n`
|
|
68
70
|
*
|
|
69
71
|
* @example
|
|
72
|
+
* ```js
|
|
70
73
|
* import { secp256k1 } from '@noble/curves/secp256k1';
|
|
71
|
-
*
|
|
72
74
|
* const priv = secp256k1.utils.randomPrivateKey();
|
|
73
75
|
* const pub = secp256k1.getPublicKey(priv);
|
|
74
76
|
* const msg = new Uint8Array(32).fill(1); // message hash (not message) in ecdsa
|
|
75
77
|
* const sig = secp256k1.sign(msg, priv); // `{prehash: true}` option is available
|
|
76
78
|
* const isValid = secp256k1.verify(sig, msg, pub) === true;
|
|
79
|
+
* ```
|
|
77
80
|
*/
|
|
78
81
|
export const secp256k1: CurveFnWithCreate = createCurve(
|
|
79
82
|
{
|
|
80
|
-
a: BigInt(0),
|
|
83
|
+
a: BigInt(0),
|
|
81
84
|
b: BigInt(7),
|
|
82
|
-
Fp: Fpk1,
|
|
83
|
-
n: secp256k1N,
|
|
84
|
-
// Base point (x, y) aka generator point
|
|
85
|
+
Fp: Fpk1,
|
|
86
|
+
n: secp256k1N,
|
|
85
87
|
Gx: BigInt('55066263022277343669578718895168534326250603453777594175500187360389116729240'),
|
|
86
88
|
Gy: BigInt('32670510020758816978083085130507043184471273380659243275938904335757337482424'),
|
|
87
|
-
h: BigInt(1),
|
|
89
|
+
h: BigInt(1),
|
|
88
90
|
lowS: true, // Allow only low-S signatures by default in sign() and verify()
|
|
89
91
|
endo: {
|
|
90
92
|
// Endomorphism, see above
|
|
@@ -242,12 +244,14 @@ export type SecpSchnorr = {
|
|
|
242
244
|
* Schnorr signatures over secp256k1.
|
|
243
245
|
* https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki
|
|
244
246
|
* @example
|
|
247
|
+
* ```js
|
|
245
248
|
* import { schnorr } from '@noble/curves/secp256k1';
|
|
246
249
|
* const priv = schnorr.utils.randomPrivateKey();
|
|
247
250
|
* const pub = schnorr.getPublicKey(priv);
|
|
248
251
|
* const msg = new TextEncoder().encode('hello');
|
|
249
252
|
* const sig = schnorr.sign(msg, priv);
|
|
250
253
|
* const isValid = schnorr.verify(sig, msg, pub);
|
|
254
|
+
* ```
|
|
251
255
|
*/
|
|
252
256
|
export const schnorr: SecpSchnorr = /* @__PURE__ */ (() => ({
|
|
253
257
|
getPublicKey: schnorrGetPublicKey,
|
|
@@ -303,7 +307,8 @@ const mapSWU = /* @__PURE__ */ (() =>
|
|
|
303
307
|
B: BigInt('1771'),
|
|
304
308
|
Z: Fpk1.create(BigInt('-11')),
|
|
305
309
|
}))();
|
|
306
|
-
|
|
310
|
+
/** Hashing / encoding to secp256k1 points / field. RFC 9380 methods. */
|
|
311
|
+
export const secp256k1_hasher: Hasher<bigint> = /* @__PURE__ */ (() =>
|
|
307
312
|
createHasher(
|
|
308
313
|
secp256k1.ProjectivePoint,
|
|
309
314
|
(scalars: bigint[]) => {
|
|
@@ -318,11 +323,11 @@ const htf = /* @__PURE__ */ (() =>
|
|
|
318
323
|
k: 128,
|
|
319
324
|
expand: 'xmd',
|
|
320
325
|
hash: sha256,
|
|
321
|
-
}
|
|
326
|
+
} as const
|
|
322
327
|
))();
|
|
323
328
|
|
|
324
|
-
|
|
325
|
-
|
|
329
|
+
export const hashToCurve: HTFMethod<bigint> = /* @__PURE__ */ (() =>
|
|
330
|
+
secp256k1_hasher.hashToCurve)();
|
|
326
331
|
|
|
327
|
-
|
|
328
|
-
|
|
332
|
+
export const encodeToCurve: HTFMethod<bigint> = /* @__PURE__ */ (() =>
|
|
333
|
+
secp256k1_hasher.encodeToCurve)();
|