@noble/curves 0.9.0 → 1.0.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 +197 -99
- package/abstract/bls.d.ts +43 -31
- package/abstract/bls.d.ts.map +1 -1
- package/abstract/bls.js +37 -28
- package/abstract/bls.js.map +1 -1
- package/abstract/edwards.d.ts +6 -2
- package/abstract/edwards.d.ts.map +1 -1
- package/abstract/edwards.js +37 -26
- package/abstract/edwards.js.map +1 -1
- package/abstract/hash-to-curve.d.ts +1 -1
- package/abstract/hash-to-curve.d.ts.map +1 -1
- package/abstract/hash-to-curve.js +3 -2
- package/abstract/hash-to-curve.js.map +1 -1
- package/abstract/modular.js +1 -1
- package/abstract/modular.js.map +1 -1
- package/abstract/utils.d.ts.map +1 -1
- package/abstract/utils.js +2 -2
- package/abstract/utils.js.map +1 -1
- package/abstract/weierstrass.d.ts +23 -0
- package/abstract/weierstrass.d.ts.map +1 -1
- package/abstract/weierstrass.js +44 -31
- package/abstract/weierstrass.js.map +1 -1
- package/bls12-381.d.ts.map +1 -1
- package/bls12-381.js +161 -162
- package/bls12-381.js.map +1 -1
- package/{bn.d.ts → bn254.d.ts} +1 -1
- package/bn254.d.ts.map +1 -0
- package/{bn.js → bn254.js} +1 -1
- package/bn254.js.map +1 -0
- package/ed25519.d.ts +9 -0
- package/ed25519.d.ts.map +1 -1
- package/ed25519.js +23 -9
- package/ed25519.js.map +1 -1
- package/ed448.d.ts +9 -0
- package/ed448.d.ts.map +1 -1
- package/ed448.js +19 -18
- package/ed448.js.map +1 -1
- package/esm/abstract/bls.js +37 -28
- package/esm/abstract/bls.js.map +1 -1
- package/esm/abstract/edwards.js +37 -26
- package/esm/abstract/edwards.js.map +1 -1
- package/esm/abstract/hash-to-curve.js +3 -2
- package/esm/abstract/hash-to-curve.js.map +1 -1
- package/esm/abstract/modular.js +1 -1
- package/esm/abstract/modular.js.map +1 -1
- package/esm/abstract/utils.js +2 -2
- package/esm/abstract/utils.js.map +1 -1
- package/esm/abstract/weierstrass.js +36 -23
- package/esm/abstract/weierstrass.js.map +1 -1
- package/esm/bls12-381.js +162 -163
- package/esm/bls12-381.js.map +1 -1
- package/esm/{bn.js → bn254.js} +1 -1
- package/esm/bn254.js.map +1 -0
- package/esm/ed25519.js +21 -8
- package/esm/ed25519.js.map +1 -1
- package/esm/ed448.js +17 -17
- package/esm/ed448.js.map +1 -1
- package/esm/p256.js +5 -6
- package/esm/p256.js.map +1 -1
- package/esm/p384.js +10 -12
- package/esm/p384.js.map +1 -1
- package/esm/p521.js +22 -18
- package/esm/p521.js.map +1 -1
- package/esm/secp256k1.js +1 -1
- package/esm/secp256k1.js.map +1 -1
- package/p256.d.ts +1 -1
- package/p256.d.ts.map +1 -1
- package/p256.js +6 -7
- package/p256.js.map +1 -1
- package/p384.d.ts +1 -1
- package/p384.d.ts.map +1 -1
- package/p384.js +11 -13
- package/p384.js.map +1 -1
- package/p521.d.ts +1 -1
- package/p521.d.ts.map +1 -1
- package/p521.js +23 -19
- package/p521.js.map +1 -1
- package/package.json +5 -8
- package/secp256k1.js +1 -1
- package/secp256k1.js.map +1 -1
- package/src/abstract/bls.ts +83 -61
- package/src/abstract/edwards.ts +49 -24
- package/src/abstract/hash-to-curve.ts +4 -3
- package/src/abstract/modular.ts +1 -1
- package/src/abstract/utils.ts +2 -2
- package/src/abstract/weierstrass.ts +36 -23
- package/src/bls12-381.ts +252 -171
- package/src/ed25519.ts +23 -9
- package/src/ed448.ts +18 -17
- package/src/p256.ts +15 -19
- package/src/p384.ts +17 -21
- package/src/p521.ts +34 -22
- package/src/secp256k1.ts +1 -1
- package/bn.d.ts.map +0 -1
- package/bn.js.map +0 -1
- package/esm/bn.js.map +0 -1
- /package/src/{bn.ts → bn254.ts} +0 -0
package/src/ed25519.ts
CHANGED
|
@@ -95,15 +95,15 @@ export const ED25519_TORSION_SUBGROUP = [
|
|
|
95
95
|
|
|
96
96
|
const Fp = Field(ED25519_P, undefined, true);
|
|
97
97
|
|
|
98
|
-
const
|
|
98
|
+
const ed25519Defaults = {
|
|
99
99
|
// Param: a
|
|
100
|
-
a: BigInt(-1),
|
|
101
|
-
//
|
|
100
|
+
a: BigInt(-1), // Fp.create(-1) is proper; our way still works and is faster
|
|
101
|
+
// d is equal to -121665/121666 over finite field.
|
|
102
102
|
// Negative number is P - number, and division is invert(number, P)
|
|
103
103
|
d: BigInt('37095705934669439343138083508754565189542113879843219016388785533085940283555'),
|
|
104
104
|
// Finite field 𝔽p over which we'll do calculations; 2n ** 255n - 19n
|
|
105
105
|
Fp,
|
|
106
|
-
// Subgroup order: how many points
|
|
106
|
+
// Subgroup order: how many points curve has
|
|
107
107
|
// 2n ** 252n + 27742317777372353535851937790883648493n;
|
|
108
108
|
n: BigInt('7237005577332262213973186563042994240857116359379907606001950938285454250989'),
|
|
109
109
|
// Cofactor
|
|
@@ -120,7 +120,7 @@ const ED25519_DEF = {
|
|
|
120
120
|
uvRatio,
|
|
121
121
|
} as const;
|
|
122
122
|
|
|
123
|
-
export const ed25519 = twistedEdwards(
|
|
123
|
+
export const ed25519 = twistedEdwards(ed25519Defaults);
|
|
124
124
|
function ed25519_domain(data: Uint8Array, ctx: Uint8Array, phflag: boolean) {
|
|
125
125
|
if (ctx.length > 255) throw new Error('Context is too big');
|
|
126
126
|
return concatBytes(
|
|
@@ -130,11 +130,11 @@ function ed25519_domain(data: Uint8Array, ctx: Uint8Array, phflag: boolean) {
|
|
|
130
130
|
data
|
|
131
131
|
);
|
|
132
132
|
}
|
|
133
|
-
export const ed25519ctx = twistedEdwards({ ...
|
|
133
|
+
export const ed25519ctx = twistedEdwards({ ...ed25519Defaults, domain: ed25519_domain });
|
|
134
134
|
export const ed25519ph = twistedEdwards({
|
|
135
|
-
...
|
|
135
|
+
...ed25519Defaults,
|
|
136
136
|
domain: ed25519_domain,
|
|
137
|
-
|
|
137
|
+
prehash: sha512,
|
|
138
138
|
});
|
|
139
139
|
|
|
140
140
|
export const x25519 = montgomery({
|
|
@@ -153,6 +153,20 @@ export const x25519 = montgomery({
|
|
|
153
153
|
randomBytes,
|
|
154
154
|
});
|
|
155
155
|
|
|
156
|
+
/**
|
|
157
|
+
* Converts ed25519 public key to x25519 public key. Uses formula:
|
|
158
|
+
* * `(u, v) = ((1+y)/(1-y), sqrt(-486664)*u/x)`
|
|
159
|
+
* * `(x, y) = (sqrt(-486664)*u/v, (u-1)/(u+1))`
|
|
160
|
+
* @example
|
|
161
|
+
* const aPub = ed25519.getPublicKey(utils.randomPrivateKey());
|
|
162
|
+
* x25519.getSharedSecret(edwardsToMontgomery(aPub), edwardsToMontgomery(someonesPub))
|
|
163
|
+
*/
|
|
164
|
+
export function edwardsToMontgomery(edwardsPub: Hex): Uint8Array {
|
|
165
|
+
const { y } = ed25519.ExtendedPoint.fromHex(edwardsPub);
|
|
166
|
+
const _1n = BigInt(1);
|
|
167
|
+
return Fp.toBytes(Fp.create((y - _1n) * Fp.inv(y + _1n)));
|
|
168
|
+
}
|
|
169
|
+
|
|
156
170
|
// Hash To Curve Elligator2 Map (NOTE: different from ristretto255 elligator)
|
|
157
171
|
// NOTE: very important part is usage of FpSqrtEven for ELL2_C1_EDWARDS, since
|
|
158
172
|
// SageMath returns different root first and everything falls apart
|
|
@@ -204,7 +218,7 @@ function map_to_curve_elligator2_curve25519(u: bigint) {
|
|
|
204
218
|
let y = Fp.cmov(y2, y1, e3); // 36. y = CMOV(y2, y1, e3) # If e3, y = y1, else y = y2
|
|
205
219
|
let e4 = Fp.isOdd(y); // 37. e4 = sgn0(y) == 1 # Fix sign of y
|
|
206
220
|
y = Fp.cmov(y, Fp.neg(y), e3 !== e4); // 38. y = CMOV(y, -y, e3 XOR e4)
|
|
207
|
-
return { xMn: xn, xMd: xd, yMn: y, yMd:
|
|
221
|
+
return { xMn: xn, xMd: xd, yMn: y, yMd: _1n }; // 39. return (xn, xd, y, 1)
|
|
208
222
|
}
|
|
209
223
|
|
|
210
224
|
const ELL2_C1_EDWARDS = FpSqrtEven(Fp, Fp.neg(BigInt(486664))); // sgn0(c1) MUST equal 0
|
package/src/ed448.ts
CHANGED
|
@@ -54,6 +54,7 @@ function adjustScalarBytes(bytes: Uint8Array): Uint8Array {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
const Fp = Field(ed448P, 456, true);
|
|
57
|
+
const _4n = BigInt(4);
|
|
57
58
|
|
|
58
59
|
const ED448_DEF = {
|
|
59
60
|
// Param: a
|
|
@@ -119,7 +120,7 @@ const ED448_DEF = {
|
|
|
119
120
|
|
|
120
121
|
export const ed448 = twistedEdwards(ED448_DEF);
|
|
121
122
|
// NOTE: there is no ed448ctx, since ed448 supports ctx by default
|
|
122
|
-
export const ed448ph = twistedEdwards({ ...ED448_DEF,
|
|
123
|
+
export const ed448ph = twistedEdwards({ ...ED448_DEF, prehash: shake256_64 });
|
|
123
124
|
|
|
124
125
|
export const x448 = montgomery({
|
|
125
126
|
a: BigInt(156326),
|
|
@@ -135,22 +136,22 @@ export const x448 = montgomery({
|
|
|
135
136
|
},
|
|
136
137
|
adjustScalarBytes,
|
|
137
138
|
randomBytes,
|
|
138
|
-
// The 4-isogeny maps between the Montgomery curve and this Edwards
|
|
139
|
-
// curve are:
|
|
140
|
-
// (u, v) = (y^2/x^2, (2 - x^2 - y^2)*y/x^3)
|
|
141
|
-
// (x, y) = (4*v*(u^2 - 1)/(u^4 - 2*u^2 + 4*v^2 + 1),
|
|
142
|
-
// -(u^5 - 2*u^3 - 4*u*v^2 + u)/
|
|
143
|
-
// (u^5 - 2*u^2*v^2 - 2*u^3 - 2*v^2 + u))
|
|
144
|
-
// xyToU: (p: PointType) => {
|
|
145
|
-
// const P = ed448P;
|
|
146
|
-
// const { x, y } = p;
|
|
147
|
-
// if (x === _0n) throw new Error(`Point with x=0 doesn't have mapping`);
|
|
148
|
-
// const invX = invert(x * x, P); // x^2
|
|
149
|
-
// const u = mod(y * y * invX, P); // (y^2/x^2)
|
|
150
|
-
// return numberToBytesLE(u, 56);
|
|
151
|
-
// },
|
|
152
139
|
});
|
|
153
140
|
|
|
141
|
+
/**
|
|
142
|
+
* Converts edwards448 public key to x448 public key. Uses formula:
|
|
143
|
+
* * `(u, v) = ((y-1)/(y+1), sqrt(156324)*u/x)`
|
|
144
|
+
* * `(x, y) = (sqrt(156324)*u/v, (1+u)/(1-u))`
|
|
145
|
+
* @example
|
|
146
|
+
* const aPub = ed448.getPublicKey(utils.randomPrivateKey());
|
|
147
|
+
* x448.getSharedSecret(edwardsToMontgomery(aPub), edwardsToMontgomery(someonesPub))
|
|
148
|
+
*/
|
|
149
|
+
export function edwardsToMontgomery(edwardsPub: string | Uint8Array): Uint8Array {
|
|
150
|
+
const { y } = ed448.ExtendedPoint.fromHex(edwardsPub);
|
|
151
|
+
const _1n = BigInt(1);
|
|
152
|
+
return Fp.toBytes(Fp.create((y - _1n) * Fp.inv(y + _1n)));
|
|
153
|
+
}
|
|
154
|
+
|
|
154
155
|
// Hash To Curve Elligator2 Map
|
|
155
156
|
const ELL2_C1 = (Fp.ORDER - BigInt(3)) / BigInt(4); // 1. c1 = (q - 3) / 4 # Integer arithmetic
|
|
156
157
|
const ELL2_J = BigInt(156326);
|
|
@@ -195,10 +196,10 @@ function map_to_curve_elligator2_edwards448(u: bigint) {
|
|
|
195
196
|
xEn = Fp.mul(xEn, xd2); // 9. xEn = xEn * xd2
|
|
196
197
|
xEn = Fp.mul(xEn, yd); // 10. xEn = xEn * yd
|
|
197
198
|
xEn = Fp.mul(xEn, yn); // 11. xEn = xEn * yn
|
|
198
|
-
xEn = Fp.mul(xEn,
|
|
199
|
+
xEn = Fp.mul(xEn, _4n); // 12. xEn = xEn * 4
|
|
199
200
|
tv2 = Fp.mul(tv2, xn2); // 13. tv2 = tv2 * xn2
|
|
200
201
|
tv2 = Fp.mul(tv2, yd2); // 14. tv2 = tv2 * yd2
|
|
201
|
-
let tv3 = Fp.mul(yn2,
|
|
202
|
+
let tv3 = Fp.mul(yn2, _4n); // 15. tv3 = 4 * yn2
|
|
202
203
|
let tv1 = Fp.add(tv3, yd2); // 16. tv1 = tv3 + yd2
|
|
203
204
|
tv1 = Fp.mul(tv1, xd4); // 17. tv1 = tv1 * xd4
|
|
204
205
|
let xEd = Fp.add(tv1, tv2); // 18. xEd = tv1 + tv2
|
package/src/p256.ts
CHANGED
|
@@ -5,10 +5,9 @@ import { Field } from './abstract/modular.js';
|
|
|
5
5
|
import { mapToCurveSimpleSWU } from './abstract/weierstrass.js';
|
|
6
6
|
import * as htf from './abstract/hash-to-curve.js';
|
|
7
7
|
|
|
8
|
-
// NIST secp256r1 aka
|
|
8
|
+
// NIST secp256r1 aka p256
|
|
9
9
|
// https://www.secg.org/sec2-v2.pdf, https://neuromancer.sk/std/nist/P-256
|
|
10
10
|
|
|
11
|
-
// Field over which we'll do calculations; 2n**224n * (2n**32n-1n) + 2n**192n + 2n**96n-1n
|
|
12
11
|
const Fp = Field(BigInt('0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff'));
|
|
13
12
|
const CURVE_A = Fp.create(BigInt('-3'));
|
|
14
13
|
const CURVE_B = BigInt('0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b');
|
|
@@ -19,23 +18,20 @@ const mapSWU = mapToCurveSimpleSWU(Fp, {
|
|
|
19
18
|
Z: Fp.create(BigInt('-10')),
|
|
20
19
|
});
|
|
21
20
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
sha256
|
|
37
|
-
);
|
|
38
|
-
export const secp256r1 = P256;
|
|
21
|
+
// prettier-ignore
|
|
22
|
+
export const p256 = createCurve({
|
|
23
|
+
a: CURVE_A, // Equation params: a, b
|
|
24
|
+
b: CURVE_B,
|
|
25
|
+
Fp, // Field: 2n**224n * (2n**32n-1n) + 2n**192n + 2n**96n-1n
|
|
26
|
+
// Curve order, total count of valid points in the field
|
|
27
|
+
n: BigInt('0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551'),
|
|
28
|
+
// Base (generator) point (x, y)
|
|
29
|
+
Gx: BigInt('0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296'),
|
|
30
|
+
Gy: BigInt('0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5'),
|
|
31
|
+
h: BigInt(1),
|
|
32
|
+
lowS: false,
|
|
33
|
+
} as const, sha256);
|
|
34
|
+
export const secp256r1 = p256;
|
|
39
35
|
|
|
40
36
|
const { hashToCurve, encodeToCurve } = htf.createHasher(
|
|
41
37
|
secp256r1.ProjectivePoint,
|
package/src/p384.ts
CHANGED
|
@@ -5,10 +5,10 @@ import { Field } from './abstract/modular.js';
|
|
|
5
5
|
import { mapToCurveSimpleSWU } from './abstract/weierstrass.js';
|
|
6
6
|
import * as htf from './abstract/hash-to-curve.js';
|
|
7
7
|
|
|
8
|
-
// NIST secp384r1 aka
|
|
8
|
+
// NIST secp384r1 aka p384
|
|
9
9
|
// https://www.secg.org/sec2-v2.pdf, https://neuromancer.sk/std/nist/P-384
|
|
10
10
|
|
|
11
|
-
// Field over which we'll do calculations.
|
|
11
|
+
// Field over which we'll do calculations.
|
|
12
12
|
// prettier-ignore
|
|
13
13
|
const P = BigInt('0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff');
|
|
14
14
|
const Fp = Field(P);
|
|
@@ -16,31 +16,27 @@ const CURVE_A = Fp.create(BigInt('-3'));
|
|
|
16
16
|
// prettier-ignore
|
|
17
17
|
const CURVE_B = BigInt('0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef');
|
|
18
18
|
|
|
19
|
+
// prettier-ignore
|
|
20
|
+
export const p384 = createCurve({
|
|
21
|
+
a: CURVE_A, // Equation params: a, b
|
|
22
|
+
b: CURVE_B,
|
|
23
|
+
Fp, // Field: 2n**384n - 2n**128n - 2n**96n + 2n**32n - 1n
|
|
24
|
+
// Curve order, total count of valid points in the field.
|
|
25
|
+
n: BigInt('0xffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973'),
|
|
26
|
+
// Base (generator) point (x, y)
|
|
27
|
+
Gx: BigInt('0xaa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7'),
|
|
28
|
+
Gy: BigInt('0x3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f'),
|
|
29
|
+
h: BigInt(1),
|
|
30
|
+
lowS: false,
|
|
31
|
+
} as const, sha384);
|
|
32
|
+
export const secp384r1 = p384;
|
|
33
|
+
|
|
19
34
|
const mapSWU = mapToCurveSimpleSWU(Fp, {
|
|
20
35
|
A: CURVE_A,
|
|
21
36
|
B: CURVE_B,
|
|
22
37
|
Z: Fp.create(BigInt('-12')),
|
|
23
38
|
});
|
|
24
39
|
|
|
25
|
-
// prettier-ignore
|
|
26
|
-
export const P384 = createCurve({
|
|
27
|
-
// Params: a, b
|
|
28
|
-
a: CURVE_A,
|
|
29
|
-
b: CURVE_B,
|
|
30
|
-
// Field over which we'll do calculations. 2n**384n - 2n**128n - 2n**96n + 2n**32n - 1n
|
|
31
|
-
Fp,
|
|
32
|
-
// Curve order, total count of valid points in the field.
|
|
33
|
-
n: BigInt('0xffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973'),
|
|
34
|
-
// Base point (x, y) aka generator point
|
|
35
|
-
Gx: BigInt('0xaa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7'),
|
|
36
|
-
Gy: BigInt('0x3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f'),
|
|
37
|
-
h: BigInt(1),
|
|
38
|
-
lowS: false,
|
|
39
|
-
} as const,
|
|
40
|
-
sha384
|
|
41
|
-
);
|
|
42
|
-
export const secp384r1 = P384;
|
|
43
|
-
|
|
44
40
|
const { hashToCurve, encodeToCurve } = htf.createHasher(
|
|
45
41
|
secp384r1.ProjectivePoint,
|
|
46
42
|
(scalars: bigint[]) => mapSWU(scalars[0]),
|
package/src/p521.ts
CHANGED
|
@@ -5,41 +5,53 @@ import { Field } from './abstract/modular.js';
|
|
|
5
5
|
import { mapToCurveSimpleSWU } from './abstract/weierstrass.js';
|
|
6
6
|
import * as htf from './abstract/hash-to-curve.js';
|
|
7
7
|
|
|
8
|
-
// NIST secp521r1 aka
|
|
8
|
+
// NIST secp521r1 aka p521
|
|
9
9
|
// Note that it's 521, which differs from 512 of its hash function.
|
|
10
10
|
// https://www.secg.org/sec2-v2.pdf, https://neuromancer.sk/std/nist/P-521
|
|
11
11
|
|
|
12
|
-
// Field over which we'll do calculations
|
|
12
|
+
// Field over which we'll do calculations.
|
|
13
13
|
// prettier-ignore
|
|
14
14
|
const P = BigInt('0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff');
|
|
15
15
|
const Fp = Field(P);
|
|
16
16
|
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
const CURVE = {
|
|
18
|
+
a: Fp.create(BigInt('-3')),
|
|
19
|
+
b: BigInt(
|
|
20
|
+
'0x0051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00'
|
|
21
|
+
),
|
|
22
|
+
Fp,
|
|
23
|
+
n: BigInt(
|
|
24
|
+
'0x01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409'
|
|
25
|
+
),
|
|
26
|
+
Gx: BigInt(
|
|
27
|
+
'0x00c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66'
|
|
28
|
+
),
|
|
29
|
+
Gy: BigInt(
|
|
30
|
+
'0x011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650'
|
|
31
|
+
),
|
|
32
|
+
h: BigInt(1),
|
|
33
|
+
};
|
|
26
34
|
|
|
27
35
|
// prettier-ignore
|
|
28
|
-
export const
|
|
29
|
-
//
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
Fp,
|
|
36
|
+
export const p521 = createCurve({
|
|
37
|
+
a: CURVE.a, // Equation params: a, b
|
|
38
|
+
b: CURVE.b,
|
|
39
|
+
Fp, // Field: 2n**521n - 1n
|
|
33
40
|
// Curve order, total count of valid points in the field
|
|
34
|
-
n:
|
|
35
|
-
// Base point (x, y) aka generator point
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
h: BigInt(1),
|
|
41
|
+
n: CURVE.n,
|
|
42
|
+
Gx: CURVE.Gx, // Base point (x, y) aka generator point
|
|
43
|
+
Gy: CURVE.Gy,
|
|
44
|
+
h: CURVE.h,
|
|
39
45
|
lowS: false,
|
|
40
46
|
allowedPrivateKeyLengths: [130, 131, 132] // P521 keys are variable-length. Normalize to 132b
|
|
41
47
|
} as const, sha512);
|
|
42
|
-
export const secp521r1 =
|
|
48
|
+
export const secp521r1 = p521;
|
|
49
|
+
|
|
50
|
+
const mapSWU = mapToCurveSimpleSWU(Fp, {
|
|
51
|
+
A: CURVE.a,
|
|
52
|
+
B: CURVE.b,
|
|
53
|
+
Z: Fp.create(BigInt('-4')),
|
|
54
|
+
});
|
|
43
55
|
|
|
44
56
|
const { hashToCurve, encodeToCurve } = htf.createHasher(
|
|
45
57
|
secp521r1.ProjectivePoint,
|
package/src/secp256k1.ts
CHANGED
|
@@ -131,7 +131,7 @@ function lift_x(x: bigint): PointType<bigint> {
|
|
|
131
131
|
const xx = modP(x * x);
|
|
132
132
|
const c = modP(xx * x + BigInt(7)); // Let c = x³ + 7 mod p.
|
|
133
133
|
let y = sqrtMod(c); // Let y = c^(p+1)/4 mod p.
|
|
134
|
-
if (y %
|
|
134
|
+
if (y % _2n !== _0n) y = modP(-y); // Return the unique point P such that x(P) = x and
|
|
135
135
|
const p = new Point(x, y, _1n); // y(P) = y if y mod 2 = 0 or y(P) = p-y otherwise.
|
|
136
136
|
p.assertValidity();
|
|
137
137
|
return p;
|
package/bn.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bn.d.ts","sourceRoot":"","sources":["src/bn.ts"],"names":[],"mappings":"AAKA;;;;;GAKG;AACH,eAAO,MAAM,KAAK,6CAShB,CAAC"}
|
package/bn.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bn.js","sourceRoot":"","sources":["src/bn.ts"],"names":[],"mappings":";;;AAAA,sEAAsE;AACtE,iDAA8C;AAC9C,8DAAwD;AACxD,yDAA6C;AAC7C,sDAA8C;AAC9C;;;;;GAKG;AACU,QAAA,KAAK,GAAG,IAAA,4BAAW,EAAC;IAC/B,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;IACZ,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;IACZ,EAAE,EAAE,IAAA,kBAAK,EAAC,MAAM,CAAC,oEAAoE,CAAC,CAAC;IACvF,CAAC,EAAE,MAAM,CAAC,oEAAoE,CAAC;IAC/E,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC;IACb,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC;IACb,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;IACZ,GAAG,IAAA,0BAAO,EAAC,eAAM,CAAC;CACnB,CAAC,CAAC"}
|
package/esm/bn.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bn.js","sourceRoot":"","sources":["../src/bn.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,WAAW,CAAC;IAC/B,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;IACZ,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;IACZ,EAAE,EAAE,KAAK,CAAC,MAAM,CAAC,oEAAoE,CAAC,CAAC;IACvF,CAAC,EAAE,MAAM,CAAC,oEAAoE,CAAC;IAC/E,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC;IACb,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC;IACb,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;IACZ,GAAG,OAAO,CAAC,MAAM,CAAC;CACnB,CAAC,CAAC"}
|
/package/src/{bn.ts → bn254.ts}
RENAMED
|
File without changes
|