@noble/curves 1.5.0 → 1.7.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 +76 -25
- package/_shortw_utils.d.ts.map +1 -1
- package/abstract/bls.d.ts +7 -5
- package/abstract/bls.d.ts.map +1 -1
- package/abstract/bls.js +9 -9
- package/abstract/bls.js.map +1 -1
- package/abstract/curve.d.ts +37 -2
- package/abstract/curve.d.ts.map +1 -1
- package/abstract/curve.js +220 -22
- package/abstract/curve.js.map +1 -1
- package/abstract/edwards.d.ts +3 -0
- package/abstract/edwards.d.ts.map +1 -1
- package/abstract/edwards.js +25 -9
- package/abstract/edwards.js.map +1 -1
- package/abstract/hash-to-curve.d.ts.map +1 -1
- package/abstract/hash-to-curve.js +7 -6
- package/abstract/hash-to-curve.js.map +1 -1
- package/abstract/modular.d.ts.map +1 -1
- package/abstract/modular.js +32 -21
- package/abstract/modular.js.map +1 -1
- package/abstract/montgomery.d.ts.map +1 -1
- package/abstract/montgomery.js +5 -3
- package/abstract/montgomery.js.map +1 -1
- package/abstract/poseidon.d.ts.map +1 -1
- package/abstract/poseidon.js +22 -22
- package/abstract/poseidon.js.map +1 -1
- package/abstract/tower.d.ts +2 -0
- package/abstract/tower.d.ts.map +1 -1
- package/abstract/tower.js +7 -6
- package/abstract/tower.js.map +1 -1
- package/abstract/utils.d.ts.map +1 -1
- package/abstract/utils.js +21 -23
- package/abstract/utils.js.map +1 -1
- package/abstract/weierstrass.d.ts +19 -3
- package/abstract/weierstrass.d.ts.map +1 -1
- package/abstract/weierstrass.js +149 -71
- package/abstract/weierstrass.js.map +1 -1
- package/bls12-381.js +8 -8
- package/bn254.d.ts +2 -1
- package/bn254.d.ts.map +1 -1
- package/bn254.js +9 -7
- package/bn254.js.map +1 -1
- package/ed448.js +1 -1
- package/ed448.js.map +1 -1
- package/esm/_shortw_utils.d.ts.map +1 -1
- package/esm/abstract/bls.d.ts +7 -5
- package/esm/abstract/bls.d.ts.map +1 -1
- package/esm/abstract/bls.js +9 -9
- package/esm/abstract/bls.js.map +1 -1
- package/esm/abstract/curve.d.ts +37 -2
- package/esm/abstract/curve.d.ts.map +1 -1
- package/esm/abstract/curve.js +219 -23
- package/esm/abstract/curve.js.map +1 -1
- package/esm/abstract/edwards.d.ts +3 -0
- package/esm/abstract/edwards.d.ts.map +1 -1
- package/esm/abstract/edwards.js +27 -11
- package/esm/abstract/edwards.js.map +1 -1
- package/esm/abstract/hash-to-curve.d.ts.map +1 -1
- package/esm/abstract/hash-to-curve.js +7 -6
- package/esm/abstract/hash-to-curve.js.map +1 -1
- package/esm/abstract/modular.d.ts.map +1 -1
- package/esm/abstract/modular.js +32 -21
- package/esm/abstract/modular.js.map +1 -1
- package/esm/abstract/montgomery.d.ts.map +1 -1
- package/esm/abstract/montgomery.js +5 -3
- package/esm/abstract/montgomery.js.map +1 -1
- package/esm/abstract/poseidon.d.ts.map +1 -1
- package/esm/abstract/poseidon.js +22 -22
- package/esm/abstract/poseidon.js.map +1 -1
- package/esm/abstract/tower.d.ts +2 -0
- package/esm/abstract/tower.d.ts.map +1 -1
- package/esm/abstract/tower.js +7 -6
- package/esm/abstract/tower.js.map +1 -1
- package/esm/abstract/utils.d.ts.map +1 -1
- package/esm/abstract/utils.js +21 -23
- package/esm/abstract/utils.js.map +1 -1
- package/esm/abstract/weierstrass.d.ts +19 -3
- package/esm/abstract/weierstrass.d.ts.map +1 -1
- package/esm/abstract/weierstrass.js +150 -72
- package/esm/abstract/weierstrass.js.map +1 -1
- package/esm/bls12-381.js +8 -8
- package/esm/bn254.d.ts +2 -1
- package/esm/bn254.d.ts.map +1 -1
- package/esm/bn254.js +7 -6
- package/esm/bn254.js.map +1 -1
- package/esm/ed448.js +1 -1
- package/esm/ed448.js.map +1 -1
- package/esm/jubjub.d.ts.map +1 -1
- package/esm/jubjub.js +8 -2
- package/esm/jubjub.js.map +1 -1
- package/esm/p256.d.ts.map +1 -1
- package/esm/p256.js +6 -6
- package/esm/p256.js.map +1 -1
- package/esm/p384.d.ts.map +1 -1
- package/esm/p384.js +6 -6
- package/esm/p384.js.map +1 -1
- package/esm/p521.d.ts.map +1 -1
- package/esm/p521.js +7 -7
- package/esm/p521.js.map +1 -1
- package/esm/secp256k1.d.ts.map +1 -1
- package/esm/secp256k1.js +8 -8
- package/esm/secp256k1.js.map +1 -1
- package/jubjub.d.ts.map +1 -1
- package/jubjub.js +8 -2
- package/jubjub.js.map +1 -1
- package/p256.d.ts.map +1 -1
- package/p256.js +6 -6
- package/p256.js.map +1 -1
- package/p384.d.ts.map +1 -1
- package/p384.js +6 -6
- package/p384.js.map +1 -1
- package/p521.d.ts.map +1 -1
- package/p521.js +7 -7
- package/p521.js.map +1 -1
- package/package.json +28 -20
- package/secp256k1.d.ts.map +1 -1
- package/secp256k1.js +8 -8
- package/secp256k1.js.map +1 -1
- package/src/abstract/bls.ts +25 -13
- package/src/abstract/curve.ts +228 -23
- package/src/abstract/edwards.ts +40 -11
- package/src/abstract/hash-to-curve.ts +5 -6
- package/src/abstract/modular.ts +29 -19
- package/src/abstract/montgomery.ts +5 -3
- package/src/abstract/poseidon.ts +20 -24
- package/src/abstract/tower.ts +8 -6
- package/src/abstract/utils.ts +18 -24
- package/src/abstract/weierstrass.ts +144 -64
- package/src/bls12-381.ts +9 -9
- package/src/bn254.ts +16 -7
- package/src/ed448.ts +1 -1
- package/src/jubjub.ts +7 -2
- package/src/p256.ts +6 -6
- package/src/p384.ts +6 -6
- package/src/p521.ts +7 -7
- package/src/secp256k1.ts +8 -8
package/src/bls12-381.ts
CHANGED
|
@@ -56,7 +56,7 @@ bls12-381 is pairing-friendly Barreto-Lynn-Scott elliptic curve construction all
|
|
|
56
56
|
// prettier-ignore
|
|
57
57
|
const _0n = BigInt(0), _1n = BigInt(1), _2n = BigInt(2), _3n = BigInt(3), _4n = BigInt(4);
|
|
58
58
|
|
|
59
|
-
/*
|
|
59
|
+
/*
|
|
60
60
|
Embedding degree (k): 12
|
|
61
61
|
Seed (X): -15132376222941642752
|
|
62
62
|
Fr: (x⁴-x²+1)
|
|
@@ -509,7 +509,7 @@ export const bls12_381: CurveFn = bls({
|
|
|
509
509
|
}
|
|
510
510
|
const right = Fp.add(Fp.pow(x, _3n), Fp.create(bls12_381.params.G1b)); // y² = x³ + b
|
|
511
511
|
let y = Fp.sqrt(right);
|
|
512
|
-
if (!y) throw new Error('
|
|
512
|
+
if (!y) throw new Error('invalid compressed G1 point');
|
|
513
513
|
if ((y * _2n) / P !== BigInt(sort)) y = Fp.neg(y);
|
|
514
514
|
return { x: Fp.create(x), y: Fp.create(y) };
|
|
515
515
|
} else if (value.length === 96 && !compressed) {
|
|
@@ -522,7 +522,7 @@ export const bls12_381: CurveFn = bls({
|
|
|
522
522
|
}
|
|
523
523
|
return { x: Fp.create(x), y: Fp.create(y) };
|
|
524
524
|
} else {
|
|
525
|
-
throw new Error('
|
|
525
|
+
throw new Error('invalid point G1, expected 48/96 bytes');
|
|
526
526
|
}
|
|
527
527
|
},
|
|
528
528
|
toBytes: (c, point, isCompressed) => {
|
|
@@ -553,7 +553,7 @@ export const bls12_381: CurveFn = bls({
|
|
|
553
553
|
const x = Fp.create(compressedValue & Fp.MASK);
|
|
554
554
|
const right = Fp.add(Fp.pow(x, _3n), Fp.create(bls12_381.params.G1b)); // y² = x³ + b
|
|
555
555
|
let y = Fp.sqrt(right);
|
|
556
|
-
if (!y) throw new Error('
|
|
556
|
+
if (!y) throw new Error('invalid compressed G1 point');
|
|
557
557
|
const aflag = BigInt(sort);
|
|
558
558
|
if ((y * _2n) / P !== aflag) y = Fp.neg(y);
|
|
559
559
|
const point = bls12_381.G1.ProjectivePoint.fromAffine({ x, y });
|
|
@@ -644,7 +644,7 @@ export const bls12_381: CurveFn = bls({
|
|
|
644
644
|
(!compressed && infinity && sort) || // 01100000
|
|
645
645
|
(sort && infinity && compressed) // 11100000
|
|
646
646
|
) {
|
|
647
|
-
throw new Error('
|
|
647
|
+
throw new Error('invalid encoding flag: ' + (bytes[0] & 0b1110_0000));
|
|
648
648
|
}
|
|
649
649
|
const L = Fp.BYTES;
|
|
650
650
|
const slc = (b: Uint8Array, from: number, to?: number) => bytesToNumberBE(b.slice(from, to));
|
|
@@ -654,7 +654,7 @@ export const bls12_381: CurveFn = bls({
|
|
|
654
654
|
if (infinity) {
|
|
655
655
|
// check that all bytes are 0
|
|
656
656
|
if (value.reduce((p, c) => (p !== 0 ? c + 1 : c), 0) > 0) {
|
|
657
|
-
throw new Error('
|
|
657
|
+
throw new Error('invalid compressed G2 point');
|
|
658
658
|
}
|
|
659
659
|
return { x: Fp2.ZERO, y: Fp2.ZERO };
|
|
660
660
|
}
|
|
@@ -669,7 +669,7 @@ export const bls12_381: CurveFn = bls({
|
|
|
669
669
|
} else if (value.length === 192 && !compressed) {
|
|
670
670
|
if (infinity) {
|
|
671
671
|
if (value.reduce((p, c) => (p !== 0 ? c + 1 : c), 0) > 0) {
|
|
672
|
-
throw new Error('
|
|
672
|
+
throw new Error('invalid uncompressed G2 point');
|
|
673
673
|
}
|
|
674
674
|
return { x: Fp2.ZERO, y: Fp2.ZERO };
|
|
675
675
|
}
|
|
@@ -679,7 +679,7 @@ export const bls12_381: CurveFn = bls({
|
|
|
679
679
|
const y0 = slc(value, 3 * L, 4 * L);
|
|
680
680
|
return { x: Fp2.fromBigTuple([x0, x1]), y: Fp2.fromBigTuple([y0, y1]) };
|
|
681
681
|
} else {
|
|
682
|
-
throw new Error('
|
|
682
|
+
throw new Error('invalid point G2, expected 96/192 bytes');
|
|
683
683
|
}
|
|
684
684
|
},
|
|
685
685
|
toBytes: (c, point, isCompressed) => {
|
|
@@ -712,7 +712,7 @@ export const bls12_381: CurveFn = bls({
|
|
|
712
712
|
const P = Fp.ORDER;
|
|
713
713
|
const half = value.length / 2;
|
|
714
714
|
if (half !== 48 && half !== 96)
|
|
715
|
-
throw new Error('
|
|
715
|
+
throw new Error('invalid compressed signature length, must be 96 or 192');
|
|
716
716
|
const z1 = bytesToNumberBE(value.slice(0, half));
|
|
717
717
|
const z2 = bytesToNumberBE(value.slice(half));
|
|
718
718
|
// Indicates the infinity point
|
package/src/bn254.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { sha256 } from '@noble/hashes/sha256';
|
|
|
3
3
|
import { getHash } from './_shortw_utils.js';
|
|
4
4
|
import { weierstrass } from './abstract/weierstrass.js';
|
|
5
5
|
import { randomBytes } from '@noble/hashes/utils';
|
|
6
|
-
import { bls, CurveFn } from './abstract/bls.js';
|
|
6
|
+
import { bls, CurveFn, PostPrecomputeFn, PostPrecomputePointAddFn } from './abstract/bls.js';
|
|
7
7
|
import { Field } from './abstract/modular.js';
|
|
8
8
|
import { bitGet, bitLen, notImplemented } from './abstract/utils.js';
|
|
9
9
|
import { tower12, psiFrobenius } from './abstract/tower.js';
|
|
@@ -148,6 +148,20 @@ const htfDefaults = Object.freeze({
|
|
|
148
148
|
hash: sha256,
|
|
149
149
|
} as const);
|
|
150
150
|
|
|
151
|
+
export const _postPrecompute: PostPrecomputeFn = (
|
|
152
|
+
Rx: Fp2,
|
|
153
|
+
Ry: Fp2,
|
|
154
|
+
Rz: Fp2,
|
|
155
|
+
Qx: Fp2,
|
|
156
|
+
Qy: Fp2,
|
|
157
|
+
pointAdd: PostPrecomputePointAddFn
|
|
158
|
+
) => {
|
|
159
|
+
const q = psi(Qx, Qy);
|
|
160
|
+
({ Rx, Ry, Rz } = pointAdd(Rx, Ry, Rz, q[0], q[1]));
|
|
161
|
+
const q2 = psi(q[0], q[1]);
|
|
162
|
+
pointAdd(Rx, Ry, Rz, q2[0], Fp2.neg(q2[1]));
|
|
163
|
+
};
|
|
164
|
+
|
|
151
165
|
/**
|
|
152
166
|
* bn254 (a.k.a. alt_bn128) pairing-friendly curve.
|
|
153
167
|
* Contains G1 / G2 operations and pairings.
|
|
@@ -212,12 +226,7 @@ export const bn254: CurveFn = bls({
|
|
|
212
226
|
hash: sha256,
|
|
213
227
|
randomBytes,
|
|
214
228
|
|
|
215
|
-
postPrecompute:
|
|
216
|
-
const q = psi(Qx, Qy);
|
|
217
|
-
({ Rx, Ry, Rz } = pointAdd(Rx, Ry, Rz, q[0], q[1]));
|
|
218
|
-
const q2 = psi(q[0], q[1]);
|
|
219
|
-
pointAdd(Rx, Ry, Rz, q2[0], Fp2.neg(q2[1]));
|
|
220
|
-
},
|
|
229
|
+
postPrecompute: _postPrecompute,
|
|
221
230
|
});
|
|
222
231
|
|
|
223
232
|
/**
|
package/src/ed448.ts
CHANGED
|
@@ -120,7 +120,7 @@ const ED448_DEF = {
|
|
|
120
120
|
adjustScalarBytes,
|
|
121
121
|
// dom4
|
|
122
122
|
domain: (data: Uint8Array, ctx: Uint8Array, phflag: boolean) => {
|
|
123
|
-
if (ctx.length > 255) throw new Error(
|
|
123
|
+
if (ctx.length > 255) throw new Error('context must be smaller than 255, got: ' + ctx.length);
|
|
124
124
|
return concatBytes(
|
|
125
125
|
utf8ToBytes('SigEd448'),
|
|
126
126
|
new Uint8Array([phflag ? 1 : 0, ctx.length]),
|
package/src/jubjub.ts
CHANGED
|
@@ -46,13 +46,18 @@ export function groupHash(tag: Uint8Array, personalization: Uint8Array) {
|
|
|
46
46
|
return p;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
// No secret data is leaked here at all.
|
|
50
|
+
// It operates over public data:
|
|
51
|
+
// const G_SPEND = jubjub.findGroupHash(new Uint8Array(), utf8ToBytes('Item_G_'));
|
|
49
52
|
export function findGroupHash(m: Uint8Array, personalization: Uint8Array) {
|
|
50
53
|
const tag = concatBytes(m, new Uint8Array([0]));
|
|
54
|
+
const hashes = [];
|
|
51
55
|
for (let i = 0; i < 256; i++) {
|
|
52
56
|
tag[tag.length - 1] = i;
|
|
53
57
|
try {
|
|
54
|
-
|
|
58
|
+
hashes.push(groupHash(tag, personalization));
|
|
55
59
|
} catch (e) {}
|
|
56
60
|
}
|
|
57
|
-
throw new Error('findGroupHash tag overflow');
|
|
61
|
+
if (!hashes.length) throw new Error('findGroupHash tag overflow');
|
|
62
|
+
return hashes[0];
|
|
58
63
|
}
|
package/src/p256.ts
CHANGED
|
@@ -8,15 +8,15 @@ import { mapToCurveSimpleSWU } from './abstract/weierstrass.js';
|
|
|
8
8
|
// NIST secp256r1 aka p256
|
|
9
9
|
// https://www.secg.org/sec2-v2.pdf, https://neuromancer.sk/std/nist/P-256
|
|
10
10
|
|
|
11
|
-
const
|
|
12
|
-
const CURVE_A =
|
|
11
|
+
const Fp256 = Field(BigInt('0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff'));
|
|
12
|
+
const CURVE_A = Fp256.create(BigInt('-3'));
|
|
13
13
|
const CURVE_B = BigInt('0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b');
|
|
14
14
|
|
|
15
15
|
// prettier-ignore
|
|
16
16
|
export const p256 = createCurve({
|
|
17
17
|
a: CURVE_A, // Equation params: a, b
|
|
18
18
|
b: CURVE_B,
|
|
19
|
-
Fp, // Field: 2n**224n * (2n**32n-1n) + 2n**192n + 2n**96n-1n
|
|
19
|
+
Fp: Fp256, // Field: 2n**224n * (2n**32n-1n) + 2n**192n + 2n**96n-1n
|
|
20
20
|
// Curve order, total count of valid points in the field
|
|
21
21
|
n: BigInt('0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551'),
|
|
22
22
|
// Base (generator) point (x, y)
|
|
@@ -28,17 +28,17 @@ export const p256 = createCurve({
|
|
|
28
28
|
export const secp256r1 = p256;
|
|
29
29
|
|
|
30
30
|
const mapSWU = /* @__PURE__ */ (() =>
|
|
31
|
-
mapToCurveSimpleSWU(
|
|
31
|
+
mapToCurveSimpleSWU(Fp256, {
|
|
32
32
|
A: CURVE_A,
|
|
33
33
|
B: CURVE_B,
|
|
34
|
-
Z:
|
|
34
|
+
Z: Fp256.create(BigInt('-10')),
|
|
35
35
|
}))();
|
|
36
36
|
|
|
37
37
|
const htf = /* @__PURE__ */ (() =>
|
|
38
38
|
createHasher(secp256r1.ProjectivePoint, (scalars: bigint[]) => mapSWU(scalars[0]), {
|
|
39
39
|
DST: 'P256_XMD:SHA-256_SSWU_RO_',
|
|
40
40
|
encodeDST: 'P256_XMD:SHA-256_SSWU_NU_',
|
|
41
|
-
p:
|
|
41
|
+
p: Fp256.ORDER,
|
|
42
42
|
m: 1,
|
|
43
43
|
k: 128,
|
|
44
44
|
expand: 'xmd',
|
package/src/p384.ts
CHANGED
|
@@ -11,8 +11,8 @@ import { mapToCurveSimpleSWU } from './abstract/weierstrass.js';
|
|
|
11
11
|
// Field over which we'll do calculations.
|
|
12
12
|
// prettier-ignore
|
|
13
13
|
const P = BigInt('0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff');
|
|
14
|
-
const
|
|
15
|
-
const CURVE_A =
|
|
14
|
+
const Fp384 = Field(P);
|
|
15
|
+
const CURVE_A = Fp384.create(BigInt('-3'));
|
|
16
16
|
// prettier-ignore
|
|
17
17
|
const CURVE_B = BigInt('0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef');
|
|
18
18
|
|
|
@@ -20,7 +20,7 @@ const CURVE_B = BigInt('0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe814112031408
|
|
|
20
20
|
export const p384 = createCurve({
|
|
21
21
|
a: CURVE_A, // Equation params: a, b
|
|
22
22
|
b: CURVE_B,
|
|
23
|
-
Fp, // Field: 2n**384n - 2n**128n - 2n**96n + 2n**32n - 1n
|
|
23
|
+
Fp: Fp384, // Field: 2n**384n - 2n**128n - 2n**96n + 2n**32n - 1n
|
|
24
24
|
// Curve order, total count of valid points in the field.
|
|
25
25
|
n: BigInt('0xffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973'),
|
|
26
26
|
// Base (generator) point (x, y)
|
|
@@ -32,17 +32,17 @@ export const p384 = createCurve({
|
|
|
32
32
|
export const secp384r1 = p384;
|
|
33
33
|
|
|
34
34
|
const mapSWU = /* @__PURE__ */ (() =>
|
|
35
|
-
mapToCurveSimpleSWU(
|
|
35
|
+
mapToCurveSimpleSWU(Fp384, {
|
|
36
36
|
A: CURVE_A,
|
|
37
37
|
B: CURVE_B,
|
|
38
|
-
Z:
|
|
38
|
+
Z: Fp384.create(BigInt('-12')),
|
|
39
39
|
}))();
|
|
40
40
|
|
|
41
41
|
const htf = /* @__PURE__ */ (() =>
|
|
42
42
|
createHasher(secp384r1.ProjectivePoint, (scalars: bigint[]) => mapSWU(scalars[0]), {
|
|
43
43
|
DST: 'P384_XMD:SHA-384_SSWU_RO_',
|
|
44
44
|
encodeDST: 'P384_XMD:SHA-384_SSWU_NU_',
|
|
45
|
-
p:
|
|
45
|
+
p: Fp384.ORDER,
|
|
46
46
|
m: 1,
|
|
47
47
|
k: 192,
|
|
48
48
|
expand: 'xmd',
|
package/src/p521.ts
CHANGED
|
@@ -12,14 +12,14 @@ import { mapToCurveSimpleSWU } from './abstract/weierstrass.js';
|
|
|
12
12
|
// Field over which we'll do calculations.
|
|
13
13
|
// prettier-ignore
|
|
14
14
|
const P = BigInt('0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff');
|
|
15
|
-
const
|
|
15
|
+
const Fp521 = Field(P);
|
|
16
16
|
|
|
17
17
|
const CURVE = {
|
|
18
|
-
a:
|
|
18
|
+
a: Fp521.create(BigInt('-3')),
|
|
19
19
|
b: BigInt(
|
|
20
20
|
'0x0051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00'
|
|
21
21
|
),
|
|
22
|
-
Fp,
|
|
22
|
+
Fp: Fp521,
|
|
23
23
|
n: BigInt(
|
|
24
24
|
'0x01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409'
|
|
25
25
|
),
|
|
@@ -36,7 +36,7 @@ const CURVE = {
|
|
|
36
36
|
export const p521 = createCurve({
|
|
37
37
|
a: CURVE.a, // Equation params: a, b
|
|
38
38
|
b: CURVE.b,
|
|
39
|
-
Fp, // Field: 2n**521n - 1n
|
|
39
|
+
Fp: Fp521, // Field: 2n**521n - 1n
|
|
40
40
|
// Curve order, total count of valid points in the field
|
|
41
41
|
n: CURVE.n,
|
|
42
42
|
Gx: CURVE.Gx, // Base point (x, y) aka generator point
|
|
@@ -48,17 +48,17 @@ export const p521 = createCurve({
|
|
|
48
48
|
export const secp521r1 = p521;
|
|
49
49
|
|
|
50
50
|
const mapSWU = /* @__PURE__ */ (() =>
|
|
51
|
-
mapToCurveSimpleSWU(
|
|
51
|
+
mapToCurveSimpleSWU(Fp521, {
|
|
52
52
|
A: CURVE.a,
|
|
53
53
|
B: CURVE.b,
|
|
54
|
-
Z:
|
|
54
|
+
Z: Fp521.create(BigInt('-4')),
|
|
55
55
|
}))();
|
|
56
56
|
|
|
57
57
|
const htf = /* @__PURE__ */ (() =>
|
|
58
58
|
createHasher(secp521r1.ProjectivePoint, (scalars: bigint[]) => mapSWU(scalars[0]), {
|
|
59
59
|
DST: 'P521_XMD:SHA-512_SSWU_RO_',
|
|
60
60
|
encodeDST: 'P521_XMD:SHA-512_SSWU_NU_',
|
|
61
|
-
p:
|
|
61
|
+
p: Fp521.ORDER,
|
|
62
62
|
m: 1,
|
|
63
63
|
k: 256,
|
|
64
64
|
expand: 'xmd',
|
package/src/secp256k1.ts
CHANGED
|
@@ -45,11 +45,11 @@ function sqrtMod(y: bigint): bigint {
|
|
|
45
45
|
const t1 = (pow2(b223, _23n, P) * b22) % P;
|
|
46
46
|
const t2 = (pow2(t1, _6n, P) * b2) % P;
|
|
47
47
|
const root = pow2(t2, _2n, P);
|
|
48
|
-
if (!
|
|
48
|
+
if (!Fpk1.eql(Fpk1.sqr(root), y)) throw new Error('Cannot find square root');
|
|
49
49
|
return root;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
const
|
|
52
|
+
const Fpk1 = Field(secp256k1P, undefined, undefined, { sqrt: sqrtMod });
|
|
53
53
|
|
|
54
54
|
/**
|
|
55
55
|
* secp256k1 short weierstrass curve and ECDSA signatures over it.
|
|
@@ -58,7 +58,7 @@ export const secp256k1 = createCurve(
|
|
|
58
58
|
{
|
|
59
59
|
a: BigInt(0), // equation params: a, b
|
|
60
60
|
b: BigInt(7), // Seem to be rigid: bitcointalk.org/index.php?topic=289795.msg3183975#msg3183975
|
|
61
|
-
Fp, // Field's prime: 2n**256n - 2n**32n - 2n**9n - 2n**8n - 2n**7n - 2n**6n - 2n**4n - 1n
|
|
61
|
+
Fp: Fpk1, // Field's prime: 2n**256n - 2n**32n - 2n**9n - 2n**8n - 2n**7n - 2n**6n - 2n**4n - 1n
|
|
62
62
|
n: secp256k1N, // Curve order, total count of valid points in the field
|
|
63
63
|
// Base point (x, y) aka generator point
|
|
64
64
|
Gx: BigInt('55066263022277343669578718895168534326250603453777594175500187360389116729240'),
|
|
@@ -228,7 +228,7 @@ export const schnorr = /* @__PURE__ */ (() => ({
|
|
|
228
228
|
|
|
229
229
|
const isoMap = /* @__PURE__ */ (() =>
|
|
230
230
|
isogenyMap(
|
|
231
|
-
|
|
231
|
+
Fpk1,
|
|
232
232
|
[
|
|
233
233
|
// xNum
|
|
234
234
|
[
|
|
@@ -260,22 +260,22 @@ const isoMap = /* @__PURE__ */ (() =>
|
|
|
260
260
|
].map((i) => i.map((j) => BigInt(j))) as [bigint[], bigint[], bigint[], bigint[]]
|
|
261
261
|
))();
|
|
262
262
|
const mapSWU = /* @__PURE__ */ (() =>
|
|
263
|
-
mapToCurveSimpleSWU(
|
|
263
|
+
mapToCurveSimpleSWU(Fpk1, {
|
|
264
264
|
A: BigInt('0x3f8731abdd661adca08a5558f0f5d272e953d363cb6f0e5d405447c01a444533'),
|
|
265
265
|
B: BigInt('1771'),
|
|
266
|
-
Z:
|
|
266
|
+
Z: Fpk1.create(BigInt('-11')),
|
|
267
267
|
}))();
|
|
268
268
|
const htf = /* @__PURE__ */ (() =>
|
|
269
269
|
createHasher(
|
|
270
270
|
secp256k1.ProjectivePoint,
|
|
271
271
|
(scalars: bigint[]) => {
|
|
272
|
-
const { x, y } = mapSWU(
|
|
272
|
+
const { x, y } = mapSWU(Fpk1.create(scalars[0]));
|
|
273
273
|
return isoMap(x, y);
|
|
274
274
|
},
|
|
275
275
|
{
|
|
276
276
|
DST: 'secp256k1_XMD:SHA-256_SSWU_RO_',
|
|
277
277
|
encodeDST: 'secp256k1_XMD:SHA-256_SSWU_NU_',
|
|
278
|
-
p:
|
|
278
|
+
p: Fpk1.ORDER,
|
|
279
279
|
m: 1,
|
|
280
280
|
k: 128,
|
|
281
281
|
expand: 'xmd',
|