@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/bn254.js
CHANGED
|
@@ -16,6 +16,15 @@ There are huge compatibility issues in the ecosystem:
|
|
|
16
16
|
https://github.com/scipr-lab/libff/blob/a44f482e18b8ac04d034c193bd9d7df7817ad73f/libff/algebra/curves/bn128/bn128_init.cpp#L166-L169
|
|
17
17
|
3. halo2curves bn256 is also incompatible and returns different outputs
|
|
18
18
|
|
|
19
|
+
We don't implement Point methods toHex / toRawBytes.
|
|
20
|
+
To work around this limitation, has to initialize points on their own from BigInts.
|
|
21
|
+
Reason it's not implemented is because [there is no standard](https://github.com/privacy-scaling-explorations/halo2curves/issues/109).
|
|
22
|
+
Points of divergence:
|
|
23
|
+
|
|
24
|
+
- Endianness: LE vs BE (byte-swapped)
|
|
25
|
+
- Flags as first hex bits (similar to BLS) vs no-flags
|
|
26
|
+
- Imaginary part last in G2 vs first (c0, c1 vs c1, c0)
|
|
27
|
+
|
|
19
28
|
The goal of our implementation is to support "Ethereum" variant of the curve,
|
|
20
29
|
because it at least has specs:
|
|
21
30
|
|
|
@@ -48,28 +57,28 @@ Ate loop size: 6x+2
|
|
|
48
57
|
* @module
|
|
49
58
|
*/
|
|
50
59
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
51
|
-
const
|
|
60
|
+
const sha2_1 = require("@noble/hashes/sha2");
|
|
52
61
|
const utils_1 = require("@noble/hashes/utils");
|
|
53
|
-
const
|
|
54
|
-
const
|
|
55
|
-
const
|
|
56
|
-
const
|
|
57
|
-
const
|
|
58
|
-
const
|
|
62
|
+
const _shortw_utils_ts_1 = require("./_shortw_utils.js");
|
|
63
|
+
const bls_ts_1 = require("./abstract/bls.js");
|
|
64
|
+
const modular_ts_1 = require("./abstract/modular.js");
|
|
65
|
+
const tower_ts_1 = require("./abstract/tower.js");
|
|
66
|
+
const utils_ts_1 = require("./abstract/utils.js");
|
|
67
|
+
const weierstrass_ts_1 = require("./abstract/weierstrass.js");
|
|
59
68
|
// prettier-ignore
|
|
60
69
|
const _1n = BigInt(1), _2n = BigInt(2), _3n = BigInt(3);
|
|
61
70
|
const _6n = BigInt(6);
|
|
62
71
|
const BN_X = BigInt('4965661367192848881');
|
|
63
|
-
const BN_X_LEN = (0,
|
|
72
|
+
const BN_X_LEN = (0, utils_ts_1.bitLen)(BN_X);
|
|
64
73
|
const SIX_X_SQUARED = _6n * BN_X ** _2n;
|
|
65
74
|
// Finite field over r. It's for convenience and is not used in the code below.
|
|
66
|
-
const Fr = (0,
|
|
75
|
+
const Fr = (0, modular_ts_1.Field)(BigInt('21888242871839275222246405745257275088548364400416034343698204186575808495617'));
|
|
67
76
|
// Fp2.div(Fp2.mul(Fp2.ONE, _3n), Fp2.NONRESIDUE)
|
|
68
77
|
const Fp2B = {
|
|
69
78
|
c0: BigInt('19485874751759354771024239261021720505790618469301721065564631296452457478373'),
|
|
70
79
|
c1: BigInt('266929791119991161246907387137283842545076965332900288569378510910307636690'),
|
|
71
80
|
};
|
|
72
|
-
const { Fp, Fp2, Fp6, Fp4Square, Fp12 } = (0,
|
|
81
|
+
const { Fp, Fp2, Fp6, Fp4Square, Fp12 } = (0, tower_ts_1.tower12)({
|
|
73
82
|
ORDER: BigInt('21888242871839275222246405745257275088696311157297823662689037894645226208583'),
|
|
74
83
|
FP2_NONRESIDUE: [BigInt(9), _1n],
|
|
75
84
|
Fp2mulByB: (num) => Fp2.mul(num, Fp2B),
|
|
@@ -99,7 +108,7 @@ const { Fp, Fp2, Fp6, Fp4Square, Fp12 } = (0, tower_js_1.tower12)({
|
|
|
99
108
|
let z = Fp12.ONE;
|
|
100
109
|
for (let i = BN_X_LEN - 1; i >= 0; i--) {
|
|
101
110
|
z = Fp12._cyclotomicSquare(z);
|
|
102
|
-
if ((0,
|
|
111
|
+
if ((0, utils_ts_1.bitGet)(n, i))
|
|
103
112
|
z = Fp12.mul(z, num);
|
|
104
113
|
}
|
|
105
114
|
return z;
|
|
@@ -120,7 +129,7 @@ const { Fp, Fp2, Fp6, Fp4Square, Fp12 } = (0, tower_js_1.tower12)({
|
|
|
120
129
|
},
|
|
121
130
|
});
|
|
122
131
|
// END OF CURVE FIELDS
|
|
123
|
-
const { G2psi, psi } = (0,
|
|
132
|
+
const { G2psi, psi } = (0, tower_ts_1.psiFrobenius)(Fp, Fp2, Fp2.NONRESIDUE);
|
|
124
133
|
/*
|
|
125
134
|
No hashToCurve for now (and signatures):
|
|
126
135
|
|
|
@@ -136,7 +145,7 @@ const htfDefaults = Object.freeze({
|
|
|
136
145
|
m: 2,
|
|
137
146
|
k: 128,
|
|
138
147
|
expand: 'xmd',
|
|
139
|
-
hash:
|
|
148
|
+
hash: sha2_1.sha256,
|
|
140
149
|
});
|
|
141
150
|
const _postPrecompute = (Rx, Ry, Rz, Qx, Qy, pointAdd) => {
|
|
142
151
|
const q = psi(Qx, Qy);
|
|
@@ -149,7 +158,7 @@ exports._postPrecompute = _postPrecompute;
|
|
|
149
158
|
* bn254 (a.k.a. alt_bn128) pairing-friendly curve.
|
|
150
159
|
* Contains G1 / G2 operations and pairings.
|
|
151
160
|
*/
|
|
152
|
-
exports.bn254 = (0,
|
|
161
|
+
exports.bn254 = (0, bls_ts_1.bls)({
|
|
153
162
|
// Fields
|
|
154
163
|
fields: { Fp, Fp2, Fp6, Fp12, Fr },
|
|
155
164
|
G1: {
|
|
@@ -162,13 +171,13 @@ exports.bn254 = (0, bls_js_1.bls)({
|
|
|
162
171
|
htfDefaults: { ...htfDefaults, m: 1, DST: 'BN254G2_XMD:SHA-256_SVDW_RO_' },
|
|
163
172
|
wrapPrivateKey: true,
|
|
164
173
|
allowInfinityPoint: true,
|
|
165
|
-
mapToCurve:
|
|
166
|
-
fromBytes:
|
|
167
|
-
toBytes:
|
|
174
|
+
mapToCurve: utils_ts_1.notImplemented,
|
|
175
|
+
fromBytes: utils_ts_1.notImplemented,
|
|
176
|
+
toBytes: utils_ts_1.notImplemented,
|
|
168
177
|
ShortSignature: {
|
|
169
|
-
fromHex:
|
|
170
|
-
toRawBytes:
|
|
171
|
-
toHex:
|
|
178
|
+
fromHex: utils_ts_1.notImplemented,
|
|
179
|
+
toRawBytes: utils_ts_1.notImplemented,
|
|
180
|
+
toHex: utils_ts_1.notImplemented,
|
|
172
181
|
},
|
|
173
182
|
},
|
|
174
183
|
G2: {
|
|
@@ -190,13 +199,13 @@ exports.bn254 = (0, bls_js_1.bls)({
|
|
|
190
199
|
wrapPrivateKey: true,
|
|
191
200
|
allowInfinityPoint: true,
|
|
192
201
|
isTorsionFree: (c, P) => P.multiplyUnsafe(SIX_X_SQUARED).equals(G2psi(c, P)), // [p]P = [6X^2]P
|
|
193
|
-
mapToCurve:
|
|
194
|
-
fromBytes:
|
|
195
|
-
toBytes:
|
|
202
|
+
mapToCurve: utils_ts_1.notImplemented,
|
|
203
|
+
fromBytes: utils_ts_1.notImplemented,
|
|
204
|
+
toBytes: utils_ts_1.notImplemented,
|
|
196
205
|
Signature: {
|
|
197
|
-
fromHex:
|
|
198
|
-
toRawBytes:
|
|
199
|
-
toHex:
|
|
206
|
+
fromHex: utils_ts_1.notImplemented,
|
|
207
|
+
toRawBytes: utils_ts_1.notImplemented,
|
|
208
|
+
toHex: utils_ts_1.notImplemented,
|
|
200
209
|
},
|
|
201
210
|
},
|
|
202
211
|
params: {
|
|
@@ -206,7 +215,7 @@ exports.bn254 = (0, bls_js_1.bls)({
|
|
|
206
215
|
twistType: 'divisive',
|
|
207
216
|
},
|
|
208
217
|
htfDefaults,
|
|
209
|
-
hash:
|
|
218
|
+
hash: sha2_1.sha256,
|
|
210
219
|
randomBytes: utils_1.randomBytes,
|
|
211
220
|
postPrecompute: exports._postPrecompute,
|
|
212
221
|
});
|
|
@@ -214,8 +223,9 @@ exports.bn254 = (0, bls_js_1.bls)({
|
|
|
214
223
|
* bn254 weierstrass curve with ECDSA.
|
|
215
224
|
* This is very rare and probably not used anywhere.
|
|
216
225
|
* Instead, you should use G1 / G2, defined above.
|
|
226
|
+
* @deprecated
|
|
217
227
|
*/
|
|
218
|
-
exports.bn254_weierstrass = (0,
|
|
228
|
+
exports.bn254_weierstrass = (0, weierstrass_ts_1.weierstrass)({
|
|
219
229
|
a: BigInt(0),
|
|
220
230
|
b: BigInt(3),
|
|
221
231
|
Fp,
|
|
@@ -223,6 +233,6 @@ exports.bn254_weierstrass = (0, weierstrass_js_1.weierstrass)({
|
|
|
223
233
|
Gx: BigInt(1),
|
|
224
234
|
Gy: BigInt(2),
|
|
225
235
|
h: BigInt(1),
|
|
226
|
-
...(0,
|
|
236
|
+
...(0, _shortw_utils_ts_1.getHash)(sha2_1.sha256),
|
|
227
237
|
});
|
|
228
238
|
//# sourceMappingURL=bn254.js.map
|
package/bn254.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bn254.js","sourceRoot":"","sources":["src/bn254.ts"],"names":[],"mappings":";;;AAAA
|
|
1
|
+
{"version":3,"file":"bn254.js","sourceRoot":"","sources":["src/bn254.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,sEAAsE;AACtE,6CAA4C;AAC5C,+CAAkD;AAClD,yDAA6C;AAC7C,8CAK2B;AAC3B,sDAA8C;AAE9C,kDAA4D;AAC5D,kDAAqE;AACrE,8DAAsE;AACtE,kBAAkB;AAClB,MAAM,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;AACxD,MAAM,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;AAEtB,MAAM,IAAI,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC;AAC3C,MAAM,QAAQ,GAAG,IAAA,iBAAM,EAAC,IAAI,CAAC,CAAC;AAC9B,MAAM,aAAa,GAAG,GAAG,GAAG,IAAI,IAAI,GAAG,CAAC;AAExC,+EAA+E;AAC/E,MAAM,EAAE,GAAG,IAAA,kBAAK,EACd,MAAM,CAAC,+EAA+E,CAAC,CACx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IAC1F,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,aAAM,CAAC;CACnB,CAAC,CAAC"}
|
package/ed25519.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { type AffinePoint, type Group } from './abstract/curve.
|
|
2
|
-
import { type CurveFn, type ExtPointType } from './abstract/edwards.
|
|
3
|
-
import { type htfBasicOpts, type HTFMethod } from './abstract/hash-to-curve.
|
|
4
|
-
import { type CurveFn as XCurveFn } from './abstract/montgomery.
|
|
5
|
-
import { type Hex } from './abstract/utils.
|
|
1
|
+
import { type AffinePoint, type Group } from './abstract/curve.ts';
|
|
2
|
+
import { type CurveFn, type ExtPointType } from './abstract/edwards.ts';
|
|
3
|
+
import { type Hasher, type htfBasicOpts, type HTFMethod } from './abstract/hash-to-curve.ts';
|
|
4
|
+
import { type CurveFn as XCurveFn } from './abstract/montgomery.ts';
|
|
5
|
+
import { type Hex } from './abstract/utils.ts';
|
|
6
|
+
/** Weird / bogus points, useful for debugging. */
|
|
6
7
|
export declare const ED25519_TORSION_SUBGROUP: string[];
|
|
7
8
|
/**
|
|
8
9
|
* ed25519 curve with EdDSA signatures.
|
|
@@ -48,6 +49,7 @@ export declare const edwardsToMontgomery: typeof edwardsToMontgomeryPub;
|
|
|
48
49
|
* x25519.getSharedSecret(edwardsToMontgomeryPriv(aPriv), someonesPub)
|
|
49
50
|
*/
|
|
50
51
|
export declare function edwardsToMontgomeryPriv(edwardsPriv: Uint8Array): Uint8Array;
|
|
52
|
+
export declare const ed25519_hasher: Hasher<bigint>;
|
|
51
53
|
export declare const hashToCurve: HTFMethod<bigint>;
|
|
52
54
|
export declare const encodeToCurve: HTFMethod<bigint>;
|
|
53
55
|
type ExtendedPoint = ExtPointType;
|
|
@@ -59,9 +61,9 @@ type ExtendedPoint = ExtPointType;
|
|
|
59
61
|
* https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-ristretto255-decaf448
|
|
60
62
|
*/
|
|
61
63
|
declare class RistPoint implements Group<RistPoint> {
|
|
62
|
-
private readonly ep;
|
|
63
64
|
static BASE: RistPoint;
|
|
64
65
|
static ZERO: RistPoint;
|
|
66
|
+
private readonly ep;
|
|
65
67
|
constructor(ep: ExtendedPoint);
|
|
66
68
|
static fromAffine(ap: AffinePoint<bigint>): RistPoint;
|
|
67
69
|
/**
|
|
@@ -96,6 +98,7 @@ declare class RistPoint implements Group<RistPoint> {
|
|
|
96
98
|
}
|
|
97
99
|
export declare const RistrettoPoint: typeof RistPoint;
|
|
98
100
|
export declare const hashToRistretto255: (msg: Uint8Array, options: htfBasicOpts) => RistPoint;
|
|
101
|
+
/** @deprecated */
|
|
99
102
|
export declare const hash_to_ristretto255: (msg: Uint8Array, options: htfBasicOpts) => RistPoint;
|
|
100
103
|
export {};
|
|
101
104
|
//# sourceMappingURL=ed25519.d.ts.map
|
package/ed25519.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ed25519.d.ts","sourceRoot":"","sources":["src/ed25519.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,KAAK,EAAa,MAAM,qBAAqB,CAAC;AAC9E,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,YAAY,EAAkB,MAAM,uBAAuB,CAAC;AACxF,OAAO,EAGL,KAAK,YAAY,EACjB,KAAK,SAAS,EACf,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAc,KAAK,OAAO,IAAI,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAChF,OAAO,EAKL,KAAK,GAAG,EAET,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"ed25519.d.ts","sourceRoot":"","sources":["src/ed25519.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,KAAK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gB;gBAGvB,EAAE,EAAE,aAAa;IAI7B,MAAM,CAAC,UAAU,CAAC,EAAE,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,SAAS;IAIrD;;;;;;OAMG;IACH,MAAM,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,GAAG,SAAS;IASvC;;;;OAIG;IACH,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,GAAG,SAAS;IA2BnC,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,SAAS;IAK7D;;;OAGG;IACH,UAAU,IAAI,UAAU;IA4BxB,KAAK,IAAI,MAAM;IAIf,QAAQ,IAAI,MAAM;IAKlB,MAAM,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO;IAWjC,GAAG,CAAC,KAAK,EAAE,SAAS,GAAG,SAAS;IAKhC,QAAQ,CAAC,KAAK,EAAE,SAAS,GAAG,SAAS;IAKrC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS;IAInC,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS;IAIzC,MAAM,IAAI,SAAS;IAInB,MAAM,IAAI,SAAS;CAGpB;AACD,eAAO,MAAM,cAAc,EAAE,OAAO,SAIhC,CAAC;AAGL,eAAO,MAAM,kBAAkB,GAAI,KAAK,UAAU,EAAE,SAAS,YAAY,KAAG,SAM3E,CAAC;AACF,kBAAkB;AAClB,eAAO,MAAM,oBAAoB,EAAE,CAAC,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY,KAAK,SAC3D,CAAC"}
|
package/ed25519.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.hash_to_ristretto255 = exports.hashToRistretto255 = exports.RistrettoPoint = exports.encodeToCurve = exports.hashToCurve = exports.edwardsToMontgomery = exports.x25519 = exports.ed25519ph = exports.ed25519ctx = exports.ed25519 = exports.ED25519_TORSION_SUBGROUP = void 0;
|
|
3
|
+
exports.hash_to_ristretto255 = exports.hashToRistretto255 = exports.RistrettoPoint = exports.encodeToCurve = exports.hashToCurve = exports.ed25519_hasher = exports.edwardsToMontgomery = exports.x25519 = exports.ed25519ph = exports.ed25519ctx = exports.ed25519 = exports.ED25519_TORSION_SUBGROUP = void 0;
|
|
4
4
|
exports.edwardsToMontgomeryPub = edwardsToMontgomeryPub;
|
|
5
5
|
exports.edwardsToMontgomeryPriv = edwardsToMontgomeryPriv;
|
|
6
6
|
/**
|
|
@@ -11,16 +11,18 @@ exports.edwardsToMontgomeryPriv = edwardsToMontgomeryPriv;
|
|
|
11
11
|
* @module
|
|
12
12
|
*/
|
|
13
13
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
14
|
-
const
|
|
14
|
+
const sha2_1 = require("@noble/hashes/sha2");
|
|
15
15
|
const utils_1 = require("@noble/hashes/utils");
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
16
|
+
const curve_ts_1 = require("./abstract/curve.js");
|
|
17
|
+
const edwards_ts_1 = require("./abstract/edwards.js");
|
|
18
|
+
const hash_to_curve_ts_1 = require("./abstract/hash-to-curve.js");
|
|
19
|
+
const modular_ts_1 = require("./abstract/modular.js");
|
|
20
|
+
const montgomery_ts_1 = require("./abstract/montgomery.js");
|
|
21
|
+
const utils_ts_1 = require("./abstract/utils.js");
|
|
22
|
+
// 2n**255n - 19n
|
|
22
23
|
const ED25519_P = BigInt('57896044618658097711785492504343953926634992332820282019728792003956564819949');
|
|
23
24
|
// √(-1) aka √(a) aka 2^((p-1)/4)
|
|
25
|
+
// Fp.sqrt(Fp.neg(1))
|
|
24
26
|
const ED25519_SQRT_M1 = /* @__PURE__ */ BigInt('19681161376707505956807079304988542015446066515923890162744021073123829784752');
|
|
25
27
|
// prettier-ignore
|
|
26
28
|
const _0n = BigInt(0), _1n = BigInt(1), _2n = BigInt(2), _3n = BigInt(3);
|
|
@@ -32,16 +34,16 @@ function ed25519_pow_2_252_3(x) {
|
|
|
32
34
|
const P = ED25519_P;
|
|
33
35
|
const x2 = (x * x) % P;
|
|
34
36
|
const b2 = (x2 * x) % P; // x^3, 11
|
|
35
|
-
const b4 = ((0,
|
|
36
|
-
const b5 = ((0,
|
|
37
|
-
const b10 = ((0,
|
|
38
|
-
const b20 = ((0,
|
|
39
|
-
const b40 = ((0,
|
|
40
|
-
const b80 = ((0,
|
|
41
|
-
const b160 = ((0,
|
|
42
|
-
const b240 = ((0,
|
|
43
|
-
const b250 = ((0,
|
|
44
|
-
const pow_p_5_8 = ((0,
|
|
37
|
+
const b4 = ((0, modular_ts_1.pow2)(b2, _2n, P) * b2) % P; // x^15, 1111
|
|
38
|
+
const b5 = ((0, modular_ts_1.pow2)(b4, _1n, P) * x) % P; // x^31
|
|
39
|
+
const b10 = ((0, modular_ts_1.pow2)(b5, _5n, P) * b5) % P;
|
|
40
|
+
const b20 = ((0, modular_ts_1.pow2)(b10, _10n, P) * b10) % P;
|
|
41
|
+
const b40 = ((0, modular_ts_1.pow2)(b20, _20n, P) * b20) % P;
|
|
42
|
+
const b80 = ((0, modular_ts_1.pow2)(b40, _40n, P) * b40) % P;
|
|
43
|
+
const b160 = ((0, modular_ts_1.pow2)(b80, _80n, P) * b80) % P;
|
|
44
|
+
const b240 = ((0, modular_ts_1.pow2)(b160, _80n, P) * b80) % P;
|
|
45
|
+
const b250 = ((0, modular_ts_1.pow2)(b240, _10n, P) * b10) % P;
|
|
46
|
+
const pow_p_5_8 = ((0, modular_ts_1.pow2)(b250, _2n, P) * x) % P;
|
|
45
47
|
// ^ To pow to (p+3)/8, multiply it by x.
|
|
46
48
|
return { pow_p_5_8, b2 };
|
|
47
49
|
}
|
|
@@ -58,26 +60,26 @@ function adjustScalarBytes(bytes) {
|
|
|
58
60
|
// sqrt(u/v)
|
|
59
61
|
function uvRatio(u, v) {
|
|
60
62
|
const P = ED25519_P;
|
|
61
|
-
const v3 = (0,
|
|
62
|
-
const v7 = (0,
|
|
63
|
+
const v3 = (0, modular_ts_1.mod)(v * v * v, P); // v³
|
|
64
|
+
const v7 = (0, modular_ts_1.mod)(v3 * v3 * v, P); // v⁷
|
|
63
65
|
// (p+3)/8 and (p-5)/8
|
|
64
66
|
const pow = ed25519_pow_2_252_3(u * v7).pow_p_5_8;
|
|
65
|
-
let x = (0,
|
|
66
|
-
const vx2 = (0,
|
|
67
|
+
let x = (0, modular_ts_1.mod)(u * v3 * pow, P); // (uv³)(uv⁷)^(p-5)/8
|
|
68
|
+
const vx2 = (0, modular_ts_1.mod)(v * x * x, P); // vx²
|
|
67
69
|
const root1 = x; // First root candidate
|
|
68
|
-
const root2 = (0,
|
|
70
|
+
const root2 = (0, modular_ts_1.mod)(x * ED25519_SQRT_M1, P); // Second root candidate
|
|
69
71
|
const useRoot1 = vx2 === u; // If vx² = u (mod p), x is a square root
|
|
70
|
-
const useRoot2 = vx2 === (0,
|
|
71
|
-
const noRoot = vx2 === (0,
|
|
72
|
+
const useRoot2 = vx2 === (0, modular_ts_1.mod)(-u, P); // If vx² = -u, set x <-- x * 2^((p-1)/4)
|
|
73
|
+
const noRoot = vx2 === (0, modular_ts_1.mod)(-u * ED25519_SQRT_M1, P); // There is no valid root, vx² = -u√(-1)
|
|
72
74
|
if (useRoot1)
|
|
73
75
|
x = root1;
|
|
74
76
|
if (useRoot2 || noRoot)
|
|
75
77
|
x = root2; // We return root2 anyway, for const-time
|
|
76
|
-
if ((0,
|
|
77
|
-
x = (0,
|
|
78
|
+
if ((0, modular_ts_1.isNegativeLE)(x, P))
|
|
79
|
+
x = (0, modular_ts_1.mod)(-x, P);
|
|
78
80
|
return { isValid: useRoot1 || useRoot2, value: x };
|
|
79
81
|
}
|
|
80
|
-
|
|
82
|
+
/** Weird / bogus points, useful for debugging. */
|
|
81
83
|
exports.ED25519_TORSION_SUBGROUP = [
|
|
82
84
|
'0100000000000000000000000000000000000000000000000000000000000000',
|
|
83
85
|
'c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac037a',
|
|
@@ -88,24 +90,20 @@ exports.ED25519_TORSION_SUBGROUP = [
|
|
|
88
90
|
'0000000000000000000000000000000000000000000000000000000000000000',
|
|
89
91
|
'c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac03fa',
|
|
90
92
|
];
|
|
91
|
-
const Fp = /* @__PURE__ */ (() => (0,
|
|
93
|
+
const Fp = /* @__PURE__ */ (() => (0, modular_ts_1.Field)(ED25519_P, undefined, true))();
|
|
92
94
|
const ed25519Defaults = /* @__PURE__ */ (() => ({
|
|
93
|
-
//
|
|
94
|
-
a:
|
|
95
|
-
// d is
|
|
96
|
-
// Negative number is P - number, and division is invert(number, P)
|
|
95
|
+
// Removing Fp.create() will still work, and is 10% faster on sign
|
|
96
|
+
a: Fp.create(BigInt(-1)),
|
|
97
|
+
// d is -121665/121666 a.k.a. Fp.neg(121665 * Fp.inv(121666))
|
|
97
98
|
d: BigInt('37095705934669439343138083508754565189542113879843219016388785533085940283555'),
|
|
98
|
-
// Finite field
|
|
99
|
+
// Finite field 2n**255n - 19n
|
|
99
100
|
Fp,
|
|
100
|
-
// Subgroup order
|
|
101
|
-
// 2n**252n + 27742317777372353535851937790883648493n;
|
|
101
|
+
// Subgroup order 2n**252n + 27742317777372353535851937790883648493n;
|
|
102
102
|
n: BigInt('7237005577332262213973186563042994240857116359379907606001950938285454250989'),
|
|
103
|
-
// Cofactor
|
|
104
103
|
h: _8n,
|
|
105
|
-
// Base point (x, y) aka generator point
|
|
106
104
|
Gx: BigInt('15112221349535400772501151409588531511454012693041857206046113283949847762202'),
|
|
107
105
|
Gy: BigInt('46316835694926478169428394003475163141307993866256225615783033603165251855960'),
|
|
108
|
-
hash:
|
|
106
|
+
hash: sha2_1.sha512,
|
|
109
107
|
randomBytes: utils_1.randomBytes,
|
|
110
108
|
adjustScalarBytes,
|
|
111
109
|
// dom2
|
|
@@ -124,19 +122,19 @@ const ed25519Defaults = /* @__PURE__ */ (() => ({
|
|
|
124
122
|
* ed25519.verify(sig, msg, pub); // Default mode: follows ZIP215
|
|
125
123
|
* ed25519.verify(sig, msg, pub, { zip215: false }); // RFC8032 / FIPS 186-5
|
|
126
124
|
*/
|
|
127
|
-
exports.ed25519 = (() => (0,
|
|
125
|
+
exports.ed25519 = (() => (0, edwards_ts_1.twistedEdwards)(ed25519Defaults))();
|
|
128
126
|
function ed25519_domain(data, ctx, phflag) {
|
|
129
127
|
if (ctx.length > 255)
|
|
130
128
|
throw new Error('Context is too big');
|
|
131
129
|
return (0, utils_1.concatBytes)((0, utils_1.utf8ToBytes)('SigEd25519 no Ed25519 collisions'), new Uint8Array([phflag ? 1 : 0, ctx.length]), ctx, data);
|
|
132
130
|
}
|
|
133
|
-
exports.ed25519ctx = (() => (0,
|
|
131
|
+
exports.ed25519ctx = (() => (0, edwards_ts_1.twistedEdwards)({
|
|
134
132
|
...ed25519Defaults,
|
|
135
133
|
domain: ed25519_domain,
|
|
136
134
|
}))();
|
|
137
|
-
exports.ed25519ph = (() => (0,
|
|
135
|
+
exports.ed25519ph = (() => (0, edwards_ts_1.twistedEdwards)(Object.assign({}, ed25519Defaults, {
|
|
138
136
|
domain: ed25519_domain,
|
|
139
|
-
prehash:
|
|
137
|
+
prehash: sha2_1.sha512,
|
|
140
138
|
})))();
|
|
141
139
|
/**
|
|
142
140
|
* ECDH using curve25519 aka x25519.
|
|
@@ -148,7 +146,7 @@ exports.ed25519ph = (() => (0, edwards_js_1.twistedEdwards)(Object.assign({}, ed
|
|
|
148
146
|
* x25519.getPublicKey(priv) === x25519.scalarMultBase(priv);
|
|
149
147
|
* x25519.getPublicKey(x25519.utils.randomPrivateKey());
|
|
150
148
|
*/
|
|
151
|
-
exports.x25519 = (() => (0,
|
|
149
|
+
exports.x25519 = (() => (0, montgomery_ts_1.montgomery)({
|
|
152
150
|
P: ED25519_P,
|
|
153
151
|
a: BigInt(486662),
|
|
154
152
|
montgomeryBits: 255, // n is 253 bits
|
|
@@ -158,7 +156,7 @@ exports.x25519 = (() => (0, montgomery_js_1.montgomery)({
|
|
|
158
156
|
const P = ED25519_P;
|
|
159
157
|
// x^(p-2) aka x^(2^255-21)
|
|
160
158
|
const { pow_p_5_8, b2 } = ed25519_pow_2_252_3(x);
|
|
161
|
-
return (0,
|
|
159
|
+
return (0, modular_ts_1.mod)((0, modular_ts_1.pow2)(pow_p_5_8, _3n, P) * b2, P);
|
|
162
160
|
},
|
|
163
161
|
adjustScalarBytes,
|
|
164
162
|
randomBytes: utils_1.randomBytes,
|
|
@@ -239,7 +237,7 @@ function map_to_curve_elligator2_curve25519(u) {
|
|
|
239
237
|
y = Fp.cmov(y, Fp.neg(y), e3 !== e4); // 38. y = CMOV(y, -y, e3 XOR e4)
|
|
240
238
|
return { xMn: xn, xMd: xd, yMn: y, yMd: _1n }; // 39. return (xn, xd, y, 1)
|
|
241
239
|
}
|
|
242
|
-
const ELL2_C1_EDWARDS = /* @__PURE__ */ (() => (0,
|
|
240
|
+
const ELL2_C1_EDWARDS = /* @__PURE__ */ (() => (0, modular_ts_1.FpSqrtEven)(Fp, Fp.neg(BigInt(486664))))(); // sgn0(c1) MUST equal 0
|
|
243
241
|
function map_to_curve_elligator2_edwards25519(u) {
|
|
244
242
|
const { xMn, xMd, yMn, yMd } = map_to_curve_elligator2_curve25519(u); // 1. (xMn, xMd, yMn, yMd) =
|
|
245
243
|
// map_to_curve_elligator2_curve25519(u)
|
|
@@ -254,21 +252,21 @@ function map_to_curve_elligator2_edwards25519(u) {
|
|
|
254
252
|
xd = Fp.cmov(xd, Fp.ONE, e); // 10. xd = CMOV(xd, 1, e)
|
|
255
253
|
yn = Fp.cmov(yn, Fp.ONE, e); // 11. yn = CMOV(yn, 1, e)
|
|
256
254
|
yd = Fp.cmov(yd, Fp.ONE, e); // 12. yd = CMOV(yd, 1, e)
|
|
257
|
-
const
|
|
258
|
-
return { x: Fp.mul(xn,
|
|
255
|
+
const [xd_inv, yd_inv] = (0, modular_ts_1.FpInvertBatch)(Fp, [xd, yd], true); // batch division
|
|
256
|
+
return { x: Fp.mul(xn, xd_inv), y: Fp.mul(yn, yd_inv) }; // 13. return (xn, xd, yn, yd)
|
|
259
257
|
}
|
|
260
|
-
|
|
258
|
+
exports.ed25519_hasher = (() => (0, hash_to_curve_ts_1.createHasher)(exports.ed25519.ExtendedPoint, (scalars) => map_to_curve_elligator2_edwards25519(scalars[0]), {
|
|
261
259
|
DST: 'edwards25519_XMD:SHA-512_ELL2_RO_',
|
|
262
260
|
encodeDST: 'edwards25519_XMD:SHA-512_ELL2_NU_',
|
|
263
261
|
p: Fp.ORDER,
|
|
264
262
|
m: 1,
|
|
265
263
|
k: 128,
|
|
266
264
|
expand: 'xmd',
|
|
267
|
-
hash:
|
|
265
|
+
hash: sha2_1.sha512,
|
|
268
266
|
}))();
|
|
269
|
-
exports.hashToCurve = (() =>
|
|
270
|
-
exports.encodeToCurve = (() =>
|
|
271
|
-
function
|
|
267
|
+
exports.hashToCurve = (() => exports.ed25519_hasher.hashToCurve)();
|
|
268
|
+
exports.encodeToCurve = (() => exports.ed25519_hasher.encodeToCurve)();
|
|
269
|
+
function aristp(other) {
|
|
272
270
|
if (!(other instanceof RistPoint))
|
|
273
271
|
throw new Error('RistrettoPoint expected');
|
|
274
272
|
}
|
|
@@ -285,7 +283,7 @@ const D_MINUS_ONE_SQ = /* @__PURE__ */ BigInt('404408343463085368581010424693231
|
|
|
285
283
|
// Calculates 1/√(number)
|
|
286
284
|
const invertSqrt = (number) => uvRatio(_1n, number);
|
|
287
285
|
const MAX_255B = /* @__PURE__ */ BigInt('0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff');
|
|
288
|
-
const bytes255ToNumberLE = (bytes) => exports.ed25519.CURVE.Fp.create((0,
|
|
286
|
+
const bytes255ToNumberLE = (bytes) => exports.ed25519.CURVE.Fp.create((0, utils_ts_1.bytesToNumberLE)(bytes) & MAX_255B);
|
|
289
287
|
// Computes Elligator map for Ristretto
|
|
290
288
|
// https://ristretto.group/formulas/elligator.html
|
|
291
289
|
function calcElligatorRistrettoMap(r0) {
|
|
@@ -298,7 +296,7 @@ function calcElligatorRistrettoMap(r0) {
|
|
|
298
296
|
const D = mod((c - d * r) * mod(r + d)); // 4
|
|
299
297
|
let { isValid: Ns_D_is_sq, value: s } = uvRatio(Ns, D); // 5
|
|
300
298
|
let s_ = mod(s * r0); // 6
|
|
301
|
-
if (!(0,
|
|
299
|
+
if (!(0, modular_ts_1.isNegativeLE)(s_, P))
|
|
302
300
|
s_ = mod(-s_);
|
|
303
301
|
if (!Ns_D_is_sq)
|
|
304
302
|
s = s_; // 7
|
|
@@ -336,7 +334,7 @@ class RistPoint {
|
|
|
336
334
|
* @param hex 64-byte output of a hash function
|
|
337
335
|
*/
|
|
338
336
|
static hashToCurve(hex) {
|
|
339
|
-
hex = (0,
|
|
337
|
+
hex = (0, utils_ts_1.ensureBytes)('ristrettoHash', hex, 64);
|
|
340
338
|
const r1 = bytes255ToNumberLE(hex.slice(0, 32));
|
|
341
339
|
const R1 = calcElligatorRistrettoMap(r1);
|
|
342
340
|
const r2 = bytes255ToNumberLE(hex.slice(32, 64));
|
|
@@ -349,7 +347,7 @@ class RistPoint {
|
|
|
349
347
|
* @param hex Ristretto-encoded 32 bytes. Not every 32-byte string is valid ristretto encoding
|
|
350
348
|
*/
|
|
351
349
|
static fromHex(hex) {
|
|
352
|
-
hex = (0,
|
|
350
|
+
hex = (0, utils_ts_1.ensureBytes)('ristrettoHex', hex, 32);
|
|
353
351
|
const { a, d } = exports.ed25519.CURVE;
|
|
354
352
|
const P = exports.ed25519.CURVE.Fp.ORDER;
|
|
355
353
|
const mod = exports.ed25519.CURVE.Fp.create;
|
|
@@ -357,7 +355,7 @@ class RistPoint {
|
|
|
357
355
|
const s = bytes255ToNumberLE(hex);
|
|
358
356
|
// 1. Check that s_bytes is the canonical encoding of a field element, or else abort.
|
|
359
357
|
// 3. Check that s is non-negative, or else abort
|
|
360
|
-
if (!(0,
|
|
358
|
+
if (!(0, utils_ts_1.equalBytes)((0, utils_ts_1.numberToBytesLE)(s, 32), hex) || (0, modular_ts_1.isNegativeLE)(s, P))
|
|
361
359
|
throw new Error(emsg);
|
|
362
360
|
const s2 = mod(s * s);
|
|
363
361
|
const u1 = mod(_1n + a * s2); // 4 (a is -1)
|
|
@@ -369,17 +367,17 @@ class RistPoint {
|
|
|
369
367
|
const Dx = mod(I * u2); // 8
|
|
370
368
|
const Dy = mod(I * Dx * v); // 9
|
|
371
369
|
let x = mod((s + s) * Dx); // 10
|
|
372
|
-
if ((0,
|
|
370
|
+
if ((0, modular_ts_1.isNegativeLE)(x, P))
|
|
373
371
|
x = mod(-x); // 10
|
|
374
372
|
const y = mod(u1 * Dy); // 11
|
|
375
373
|
const t = mod(x * y); // 12
|
|
376
|
-
if (!isValid || (0,
|
|
374
|
+
if (!isValid || (0, modular_ts_1.isNegativeLE)(t, P) || y === _0n)
|
|
377
375
|
throw new Error(emsg);
|
|
378
376
|
return new RistPoint(new exports.ed25519.ExtendedPoint(x, y, _1n, t));
|
|
379
377
|
}
|
|
380
378
|
static msm(points, scalars) {
|
|
381
|
-
const Fn = (0,
|
|
382
|
-
return (0,
|
|
379
|
+
const Fn = (0, modular_ts_1.Field)(exports.ed25519.CURVE.n, exports.ed25519.CURVE.nBitLength);
|
|
380
|
+
return (0, curve_ts_1.pippenger)(RistPoint, Fn, points, scalars);
|
|
383
381
|
}
|
|
384
382
|
/**
|
|
385
383
|
* Encodes ristretto point to Uint8Array.
|
|
@@ -398,7 +396,7 @@ class RistPoint {
|
|
|
398
396
|
const D2 = mod(invsqrt * u2); // 5
|
|
399
397
|
const zInv = mod(D1 * D2 * t); // 6
|
|
400
398
|
let D; // 7
|
|
401
|
-
if ((0,
|
|
399
|
+
if ((0, modular_ts_1.isNegativeLE)(t * zInv, P)) {
|
|
402
400
|
let _x = mod(y * SQRT_M1);
|
|
403
401
|
let _y = mod(x * SQRT_M1);
|
|
404
402
|
x = _x;
|
|
@@ -408,22 +406,22 @@ class RistPoint {
|
|
|
408
406
|
else {
|
|
409
407
|
D = D2; // 8
|
|
410
408
|
}
|
|
411
|
-
if ((0,
|
|
409
|
+
if ((0, modular_ts_1.isNegativeLE)(x * zInv, P))
|
|
412
410
|
y = mod(-y); // 9
|
|
413
411
|
let s = mod((z - y) * D); // 10 (check footer's note, no sqrt(-a))
|
|
414
|
-
if ((0,
|
|
412
|
+
if ((0, modular_ts_1.isNegativeLE)(s, P))
|
|
415
413
|
s = mod(-s);
|
|
416
|
-
return (0,
|
|
414
|
+
return (0, utils_ts_1.numberToBytesLE)(s, 32); // 11
|
|
417
415
|
}
|
|
418
416
|
toHex() {
|
|
419
|
-
return (0,
|
|
417
|
+
return (0, utils_ts_1.bytesToHex)(this.toRawBytes());
|
|
420
418
|
}
|
|
421
419
|
toString() {
|
|
422
420
|
return this.toHex();
|
|
423
421
|
}
|
|
424
422
|
// Compare one point to another.
|
|
425
423
|
equals(other) {
|
|
426
|
-
|
|
424
|
+
aristp(other);
|
|
427
425
|
const { ex: X1, ey: Y1 } = this.ep;
|
|
428
426
|
const { ex: X2, ey: Y2 } = other.ep;
|
|
429
427
|
const mod = exports.ed25519.CURVE.Fp.create;
|
|
@@ -433,11 +431,11 @@ class RistPoint {
|
|
|
433
431
|
return one || two;
|
|
434
432
|
}
|
|
435
433
|
add(other) {
|
|
436
|
-
|
|
434
|
+
aristp(other);
|
|
437
435
|
return new RistPoint(this.ep.add(other.ep));
|
|
438
436
|
}
|
|
439
437
|
subtract(other) {
|
|
440
|
-
|
|
438
|
+
aristp(other);
|
|
441
439
|
return new RistPoint(this.ep.subtract(other.ep));
|
|
442
440
|
}
|
|
443
441
|
multiply(scalar) {
|
|
@@ -464,10 +462,11 @@ exports.RistrettoPoint = (() => {
|
|
|
464
462
|
const hashToRistretto255 = (msg, options) => {
|
|
465
463
|
const d = options.DST;
|
|
466
464
|
const DST = typeof d === 'string' ? (0, utils_1.utf8ToBytes)(d) : d;
|
|
467
|
-
const uniform_bytes = (0,
|
|
465
|
+
const uniform_bytes = (0, hash_to_curve_ts_1.expand_message_xmd)(msg, DST, 64, sha2_1.sha512);
|
|
468
466
|
const P = RistPoint.hashToCurve(uniform_bytes);
|
|
469
467
|
return P;
|
|
470
468
|
};
|
|
471
469
|
exports.hashToRistretto255 = hashToRistretto255;
|
|
470
|
+
/** @deprecated */
|
|
472
471
|
exports.hash_to_ristretto255 = exports.hashToRistretto255; // legacy
|
|
473
472
|
//# sourceMappingURL=ed25519.js.map
|