@noble/curves 1.1.0 → 1.2.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 +267 -164
- package/abstract/bls.d.ts.map +1 -1
- package/abstract/bls.js +2 -2
- package/abstract/bls.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 +14 -8
- package/abstract/hash-to-curve.js.map +1 -1
- package/abstract/modular.d.ts +51 -11
- package/abstract/modular.d.ts.map +1 -1
- package/abstract/modular.js +79 -21
- package/abstract/modular.js.map +1 -1
- package/abstract/poseidon.d.ts.map +1 -1
- package/abstract/poseidon.js +39 -41
- package/abstract/poseidon.js.map +1 -1
- package/abstract/utils.d.ts +1 -0
- package/abstract/utils.d.ts.map +1 -1
- package/abstract/utils.js +2 -1
- package/abstract/utils.js.map +1 -1
- package/abstract/weierstrass.d.ts +2 -1
- package/abstract/weierstrass.d.ts.map +1 -1
- package/abstract/weierstrass.js +13 -11
- package/abstract/weierstrass.js.map +1 -1
- package/bls12-381.d.ts.map +1 -1
- package/bls12-381.js +7 -8
- package/bls12-381.js.map +1 -1
- package/ed25519.d.ts +1 -0
- package/ed25519.d.ts.map +1 -1
- package/ed25519.js +9 -6
- package/ed25519.js.map +1 -1
- package/ed448.d.ts +51 -2
- package/ed448.d.ts.map +1 -1
- package/ed448.js +206 -28
- package/ed448.js.map +1 -1
- package/esm/abstract/bls.js +3 -3
- package/esm/abstract/bls.js.map +1 -1
- package/esm/abstract/hash-to-curve.js +14 -8
- package/esm/abstract/hash-to-curve.js.map +1 -1
- package/esm/abstract/modular.js +75 -20
- package/esm/abstract/modular.js.map +1 -1
- package/esm/abstract/poseidon.js +39 -41
- package/esm/abstract/poseidon.js.map +1 -1
- package/esm/abstract/utils.js +2 -1
- package/esm/abstract/utils.js.map +1 -1
- package/esm/abstract/weierstrass.js +13 -11
- package/esm/abstract/weierstrass.js.map +1 -1
- package/esm/bls12-381.js +7 -8
- package/esm/bls12-381.js.map +1 -1
- package/esm/ed25519.js +9 -6
- package/esm/ed25519.js.map +1 -1
- package/esm/ed448.js +208 -31
- package/esm/ed448.js.map +1 -1
- package/esm/jubjub.js +1 -1
- package/esm/jubjub.js.map +1 -1
- package/esm/package.json +1 -4
- package/jubjub.js.map +1 -1
- package/package.json +4 -3
- package/src/abstract/bls.ts +3 -3
- package/src/abstract/hash-to-curve.ts +14 -8
- package/src/abstract/modular.ts +81 -22
- package/src/abstract/poseidon.ts +39 -40
- package/src/abstract/utils.ts +4 -1
- package/src/abstract/weierstrass.ts +13 -11
- package/src/bls12-381.ts +7 -8
- package/src/ed25519.ts +9 -6
- package/src/ed448.ts +251 -33
- package/src/jubjub.ts +1 -1
package/src/ed448.ts
CHANGED
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
2
2
|
import { shake256 } from '@noble/hashes/sha3';
|
|
3
3
|
import { concatBytes, randomBytes, utf8ToBytes, wrapConstructor } from '@noble/hashes/utils';
|
|
4
|
-
import { twistedEdwards } from './abstract/edwards.js';
|
|
5
|
-
import { mod, pow2, Field } from './abstract/modular.js';
|
|
4
|
+
import { ExtPointType, twistedEdwards } from './abstract/edwards.js';
|
|
5
|
+
import { mod, pow2, Field, isNegativeLE } from './abstract/modular.js';
|
|
6
6
|
import { montgomery } from './abstract/montgomery.js';
|
|
7
|
-
import { createHasher } from './abstract/hash-to-curve.js';
|
|
7
|
+
import { createHasher, htfBasicOpts, expand_message_xof } from './abstract/hash-to-curve.js';
|
|
8
|
+
import {
|
|
9
|
+
bytesToHex,
|
|
10
|
+
bytesToNumberLE,
|
|
11
|
+
ensureBytes,
|
|
12
|
+
equalBytes,
|
|
13
|
+
Hex,
|
|
14
|
+
numberToBytesLE,
|
|
15
|
+
} from './abstract/utils.js';
|
|
16
|
+
import { AffinePoint } from './abstract/curve.js';
|
|
8
17
|
|
|
9
18
|
/**
|
|
10
19
|
* Edwards448 (not Ed448-Goldilocks) curve with following addons:
|
|
11
|
-
*
|
|
20
|
+
* - X448 ECDH
|
|
21
|
+
* - Decaf cofactor elimination
|
|
22
|
+
* - Elligator hash-to-group / point indistinguishability
|
|
12
23
|
* Conforms to RFC 8032 https://www.rfc-editor.org/rfc/rfc8032.html#section-5.2
|
|
13
24
|
*/
|
|
14
25
|
|
|
@@ -18,15 +29,16 @@ const ed448P = BigInt(
|
|
|
18
29
|
'726838724295606890549323807888004534353641360687318060281490199180612328166730772686396383698676545930088884461843637361053498018365439'
|
|
19
30
|
);
|
|
20
31
|
|
|
32
|
+
// prettier-ignore
|
|
33
|
+
const _1n = BigInt(1), _2n = BigInt(2), _3n = BigInt(3), _4n = BigInt(4), _11n = BigInt(11);
|
|
34
|
+
// prettier-ignore
|
|
35
|
+
const _22n = BigInt(22), _44n = BigInt(44), _88n = BigInt(88), _223n = BigInt(223);
|
|
36
|
+
|
|
21
37
|
// powPminus3div4 calculates z = x^k mod p, where k = (p-3)/4.
|
|
22
38
|
// Used for efficient square root calculation.
|
|
23
39
|
// ((P-3)/4).toString(2) would produce bits [223x 1, 0, 222x 1]
|
|
24
40
|
function ed448_pow_Pminus3div4(x: bigint): bigint {
|
|
25
41
|
const P = ed448P;
|
|
26
|
-
// prettier-ignore
|
|
27
|
-
const _1n = BigInt(1), _2n = BigInt(2), _3n = BigInt(3), _11n = BigInt(11);
|
|
28
|
-
// prettier-ignore
|
|
29
|
-
const _22n = BigInt(22), _44n = BigInt(44), _88n = BigInt(88), _223n = BigInt(223);
|
|
30
42
|
const b2 = (x * x * x) % P;
|
|
31
43
|
const b3 = (b2 * b2 * x) % P;
|
|
32
44
|
const b6 = (pow2(b3, _3n, P) * b3) % P;
|
|
@@ -53,8 +65,29 @@ function adjustScalarBytes(bytes: Uint8Array): Uint8Array {
|
|
|
53
65
|
return bytes;
|
|
54
66
|
}
|
|
55
67
|
|
|
68
|
+
// Constant-time ratio of u to v. Allows to combine inversion and square root u/√v.
|
|
69
|
+
// Uses algo from RFC8032 5.1.3.
|
|
70
|
+
function uvRatio(u: bigint, v: bigint): { isValid: boolean; value: bigint } {
|
|
71
|
+
const P = ed448P;
|
|
72
|
+
// https://www.rfc-editor.org/rfc/rfc8032#section-5.2.3
|
|
73
|
+
// To compute the square root of (u/v), the first step is to compute the
|
|
74
|
+
// candidate root x = (u/v)^((p+1)/4). This can be done using the
|
|
75
|
+
// following trick, to use a single modular powering for both the
|
|
76
|
+
// inversion of v and the square root:
|
|
77
|
+
// x = (u/v)^((p+1)/4) = u³v(u⁵v³)^((p-3)/4) (mod p)
|
|
78
|
+
const u2v = mod(u * u * v, P); // u²v
|
|
79
|
+
const u3v = mod(u2v * u, P); // u³v
|
|
80
|
+
const u5v3 = mod(u3v * u2v * v, P); // u⁵v³
|
|
81
|
+
const root = ed448_pow_Pminus3div4(u5v3);
|
|
82
|
+
const x = mod(u3v * root, P);
|
|
83
|
+
// Verify that root is exists
|
|
84
|
+
const x2 = mod(x * x, P); // x²
|
|
85
|
+
// If vx² = u, the recovered x-coordinate is x. Otherwise, no
|
|
86
|
+
// square root exists, and the decoding fails.
|
|
87
|
+
return { isValid: mod(x2 * v, P) === u, value: x };
|
|
88
|
+
}
|
|
89
|
+
|
|
56
90
|
const Fp = Field(ed448P, 456, true);
|
|
57
|
-
const _4n = BigInt(4);
|
|
58
91
|
|
|
59
92
|
const ED448_DEF = {
|
|
60
93
|
// Param: a
|
|
@@ -94,33 +127,12 @@ const ED448_DEF = {
|
|
|
94
127
|
data
|
|
95
128
|
);
|
|
96
129
|
},
|
|
97
|
-
|
|
98
|
-
// Constant-time ratio of u to v. Allows to combine inversion and square root u/√v.
|
|
99
|
-
// Uses algo from RFC8032 5.1.3.
|
|
100
|
-
uvRatio: (u: bigint, v: bigint): { isValid: boolean; value: bigint } => {
|
|
101
|
-
const P = ed448P;
|
|
102
|
-
// https://datatracker.ietf.org/doc/html/rfc8032#section-5.2.3
|
|
103
|
-
// To compute the square root of (u/v), the first step is to compute the
|
|
104
|
-
// candidate root x = (u/v)^((p+1)/4). This can be done using the
|
|
105
|
-
// following trick, to use a single modular powering for both the
|
|
106
|
-
// inversion of v and the square root:
|
|
107
|
-
// x = (u/v)^((p+1)/4) = u³v(u⁵v³)^((p-3)/4) (mod p)
|
|
108
|
-
const u2v = mod(u * u * v, P); // u²v
|
|
109
|
-
const u3v = mod(u2v * u, P); // u³v
|
|
110
|
-
const u5v3 = mod(u3v * u2v * v, P); // u⁵v³
|
|
111
|
-
const root = ed448_pow_Pminus3div4(u5v3);
|
|
112
|
-
const x = mod(u3v * root, P);
|
|
113
|
-
// Verify that root is exists
|
|
114
|
-
const x2 = mod(x * x, P); // x²
|
|
115
|
-
// If vx² = u, the recovered x-coordinate is x. Otherwise, no
|
|
116
|
-
// square root exists, and the decoding fails.
|
|
117
|
-
return { isValid: mod(x2 * v, P) === u, value: x };
|
|
118
|
-
},
|
|
130
|
+
uvRatio,
|
|
119
131
|
} as const;
|
|
120
132
|
|
|
121
|
-
export const ed448 = twistedEdwards(ED448_DEF);
|
|
133
|
+
export const ed448 = /* @__PURE__ */ twistedEdwards(ED448_DEF);
|
|
122
134
|
// NOTE: there is no ed448ctx, since ed448 supports ctx by default
|
|
123
|
-
export const ed448ph = twistedEdwards({ ...ED448_DEF, prehash: shake256_64 });
|
|
135
|
+
export const ed448ph = /* @__PURE__ */ twistedEdwards({ ...ED448_DEF, prehash: shake256_64 });
|
|
124
136
|
|
|
125
137
|
export const x448 = /* @__PURE__ */ (() =>
|
|
126
138
|
montgomery({
|
|
@@ -245,3 +257,209 @@ const htf = /* @__PURE__ */ (() =>
|
|
|
245
257
|
))();
|
|
246
258
|
export const hashToCurve = /* @__PURE__ */ (() => htf.hashToCurve)();
|
|
247
259
|
export const encodeToCurve = /* @__PURE__ */ (() => htf.encodeToCurve)();
|
|
260
|
+
|
|
261
|
+
function assertDcfPoint(other: unknown) {
|
|
262
|
+
if (!(other instanceof DcfPoint)) throw new Error('DecafPoint expected');
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// 1-d
|
|
266
|
+
const ONE_MINUS_D = BigInt('39082');
|
|
267
|
+
// 1-2d
|
|
268
|
+
const ONE_MINUS_TWO_D = BigInt('78163');
|
|
269
|
+
// √(-d)
|
|
270
|
+
const SQRT_MINUS_D = BigInt(
|
|
271
|
+
'98944233647732219769177004876929019128417576295529901074099889598043702116001257856802131563896515373927712232092845883226922417596214'
|
|
272
|
+
);
|
|
273
|
+
// 1 / √(-d)
|
|
274
|
+
const INVSQRT_MINUS_D = BigInt(
|
|
275
|
+
'315019913931389607337177038330951043522456072897266928557328499619017160722351061360252776265186336876723201881398623946864393857820716'
|
|
276
|
+
);
|
|
277
|
+
// Calculates 1/√(number)
|
|
278
|
+
const invertSqrt = (number: bigint) => uvRatio(_1n, number);
|
|
279
|
+
|
|
280
|
+
const MAX_448B = BigInt(
|
|
281
|
+
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
|
|
282
|
+
);
|
|
283
|
+
const bytes448ToNumberLE = (bytes: Uint8Array) =>
|
|
284
|
+
ed448.CURVE.Fp.create(bytesToNumberLE(bytes) & MAX_448B);
|
|
285
|
+
|
|
286
|
+
type ExtendedPoint = ExtPointType;
|
|
287
|
+
|
|
288
|
+
// Computes Elligator map for Decaf
|
|
289
|
+
// https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-ristretto255-decaf448-07#name-element-derivation-2
|
|
290
|
+
function calcElligatorDecafMap(r0: bigint): ExtendedPoint {
|
|
291
|
+
const { d } = ed448.CURVE;
|
|
292
|
+
const P = ed448.CURVE.Fp.ORDER;
|
|
293
|
+
const mod = ed448.CURVE.Fp.create;
|
|
294
|
+
|
|
295
|
+
const r = mod(-(r0 * r0)); // 1
|
|
296
|
+
const u0 = mod(d * (r - _1n)); // 2
|
|
297
|
+
const u1 = mod((u0 + _1n) * (u0 - r)); // 3
|
|
298
|
+
|
|
299
|
+
const { isValid: was_square, value: v } = uvRatio(ONE_MINUS_TWO_D, mod((r + _1n) * u1)); // 4
|
|
300
|
+
|
|
301
|
+
let v_prime = v; // 5
|
|
302
|
+
if (!was_square) v_prime = mod(r0 * v);
|
|
303
|
+
|
|
304
|
+
let sgn = _1n; // 6
|
|
305
|
+
if (!was_square) sgn = mod(-_1n);
|
|
306
|
+
|
|
307
|
+
const s = mod(v_prime * (r + _1n)); // 7
|
|
308
|
+
let s_abs = s;
|
|
309
|
+
if (isNegativeLE(s, P)) s_abs = mod(-s);
|
|
310
|
+
|
|
311
|
+
const s2 = s * s;
|
|
312
|
+
const W0 = mod(s_abs * _2n); // 8
|
|
313
|
+
const W1 = mod(s2 + _1n); // 9
|
|
314
|
+
const W2 = mod(s2 - _1n); // 10
|
|
315
|
+
const W3 = mod(v_prime * s * (r - _1n) * ONE_MINUS_TWO_D + sgn); // 11
|
|
316
|
+
return new ed448.ExtendedPoint(mod(W0 * W3), mod(W2 * W1), mod(W1 * W3), mod(W0 * W2));
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Each ed448/ExtendedPoint has 4 different equivalent points. This can be
|
|
321
|
+
* a source of bugs for protocols like ring signatures. Decaf was created to solve this.
|
|
322
|
+
* Decaf point operates in X:Y:Z:T extended coordinates like ExtendedPoint,
|
|
323
|
+
* but it should work in its own namespace: do not combine those two.
|
|
324
|
+
* https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-ristretto255-decaf448
|
|
325
|
+
*/
|
|
326
|
+
class DcfPoint {
|
|
327
|
+
static BASE: DcfPoint;
|
|
328
|
+
static ZERO: DcfPoint;
|
|
329
|
+
// Private property to discourage combining ExtendedPoint + DecafPoint
|
|
330
|
+
// Always use Decaf encoding/decoding instead.
|
|
331
|
+
constructor(private readonly ep: ExtendedPoint) {}
|
|
332
|
+
|
|
333
|
+
static fromAffine(ap: AffinePoint<bigint>) {
|
|
334
|
+
return new DcfPoint(ed448.ExtendedPoint.fromAffine(ap));
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Takes uniform output of 112-byte hash function like shake256 and converts it to `DecafPoint`.
|
|
339
|
+
* The hash-to-group operation applies Elligator twice and adds the results.
|
|
340
|
+
* **Note:** this is one-way map, there is no conversion from point to hash.
|
|
341
|
+
* https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-ristretto255-decaf448-07#name-element-derivation-2
|
|
342
|
+
* @param hex 112-byte output of a hash function
|
|
343
|
+
*/
|
|
344
|
+
static hashToCurve(hex: Hex): DcfPoint {
|
|
345
|
+
hex = ensureBytes('decafHash', hex, 112);
|
|
346
|
+
const r1 = bytes448ToNumberLE(hex.slice(0, 56));
|
|
347
|
+
const R1 = calcElligatorDecafMap(r1);
|
|
348
|
+
const r2 = bytes448ToNumberLE(hex.slice(56, 112));
|
|
349
|
+
const R2 = calcElligatorDecafMap(r2);
|
|
350
|
+
return new DcfPoint(R1.add(R2));
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Converts decaf-encoded string to decaf point.
|
|
355
|
+
* https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-ristretto255-decaf448-07#name-decode-2
|
|
356
|
+
* @param hex Decaf-encoded 56 bytes. Not every 56-byte string is valid decaf encoding
|
|
357
|
+
*/
|
|
358
|
+
static fromHex(hex: Hex): DcfPoint {
|
|
359
|
+
hex = ensureBytes('decafHex', hex, 56);
|
|
360
|
+
const { d } = ed448.CURVE;
|
|
361
|
+
const P = ed448.CURVE.Fp.ORDER;
|
|
362
|
+
const mod = ed448.CURVE.Fp.create;
|
|
363
|
+
const emsg = 'DecafPoint.fromHex: the hex is not valid encoding of DecafPoint';
|
|
364
|
+
const s = bytes448ToNumberLE(hex);
|
|
365
|
+
|
|
366
|
+
// 1. Check that s_bytes is the canonical encoding of a field element, or else abort.
|
|
367
|
+
// 2. Check that s is non-negative, or else abort
|
|
368
|
+
if (!equalBytes(numberToBytesLE(s, 56), hex) || isNegativeLE(s, P)) throw new Error(emsg);
|
|
369
|
+
|
|
370
|
+
const s2 = mod(s * s); // 1
|
|
371
|
+
const u1 = mod(_1n + s2); // 2
|
|
372
|
+
const u1sq = mod(u1 * u1);
|
|
373
|
+
const u2 = mod(u1sq - _4n * d * s2); // 3
|
|
374
|
+
|
|
375
|
+
const { isValid, value: invsqrt } = invertSqrt(mod(u2 * u1sq)); // 4
|
|
376
|
+
|
|
377
|
+
let u3 = mod((s + s) * invsqrt * u1 * SQRT_MINUS_D); // 5
|
|
378
|
+
if (isNegativeLE(u3, P)) u3 = mod(-u3);
|
|
379
|
+
|
|
380
|
+
const x = mod(u3 * invsqrt * u2 * INVSQRT_MINUS_D); // 6
|
|
381
|
+
const y = mod((_1n - s2) * invsqrt * u1); // 7
|
|
382
|
+
const t = mod(x * y); // 8
|
|
383
|
+
|
|
384
|
+
if (!isValid) throw new Error(emsg);
|
|
385
|
+
return new DcfPoint(new ed448.ExtendedPoint(x, y, _1n, t));
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* Encodes decaf point to Uint8Array.
|
|
390
|
+
* https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-ristretto255-decaf448-07#name-encode-2
|
|
391
|
+
*/
|
|
392
|
+
toRawBytes(): Uint8Array {
|
|
393
|
+
let { ex: x, ey: _y, ez: z, et: t } = this.ep;
|
|
394
|
+
const P = ed448.CURVE.Fp.ORDER;
|
|
395
|
+
const mod = ed448.CURVE.Fp.create;
|
|
396
|
+
|
|
397
|
+
const u1 = mod(mod(x + t) * mod(x - t)); // 1
|
|
398
|
+
const x2 = mod(x * x);
|
|
399
|
+
const { value: invsqrt } = invertSqrt(mod(u1 * ONE_MINUS_D * x2)); // 2
|
|
400
|
+
|
|
401
|
+
let ratio = mod(invsqrt * u1 * SQRT_MINUS_D); // 3
|
|
402
|
+
if (isNegativeLE(ratio, P)) ratio = mod(-ratio);
|
|
403
|
+
|
|
404
|
+
const u2 = mod(INVSQRT_MINUS_D * ratio * z - t); // 4
|
|
405
|
+
|
|
406
|
+
let s = mod(ONE_MINUS_D * invsqrt * x * u2); // 5
|
|
407
|
+
if (isNegativeLE(s, P)) s = mod(-s);
|
|
408
|
+
|
|
409
|
+
return numberToBytesLE(s, 56);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
toHex(): string {
|
|
413
|
+
return bytesToHex(this.toRawBytes());
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
toString(): string {
|
|
417
|
+
return this.toHex();
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// Compare one point to another.
|
|
421
|
+
// https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-ristretto255-decaf448-07#name-equals-2
|
|
422
|
+
equals(other: DcfPoint): boolean {
|
|
423
|
+
assertDcfPoint(other);
|
|
424
|
+
const { ex: X1, ey: Y1 } = this.ep;
|
|
425
|
+
const { ex: X2, ey: Y2 } = other.ep;
|
|
426
|
+
const mod = ed448.CURVE.Fp.create;
|
|
427
|
+
// (x1 * y2 == y1 * x2)
|
|
428
|
+
return mod(X1 * Y2) === mod(Y1 * X2);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
add(other: DcfPoint): DcfPoint {
|
|
432
|
+
assertDcfPoint(other);
|
|
433
|
+
return new DcfPoint(this.ep.add(other.ep));
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
subtract(other: DcfPoint): DcfPoint {
|
|
437
|
+
assertDcfPoint(other);
|
|
438
|
+
return new DcfPoint(this.ep.subtract(other.ep));
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
multiply(scalar: bigint): DcfPoint {
|
|
442
|
+
return new DcfPoint(this.ep.multiply(scalar));
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
multiplyUnsafe(scalar: bigint): DcfPoint {
|
|
446
|
+
return new DcfPoint(this.ep.multiplyUnsafe(scalar));
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
export const DecafPoint = /* @__PURE__ */ (() => {
|
|
450
|
+
// decaf448 base point is ed448 base x 2
|
|
451
|
+
// https://github.com/dalek-cryptography/curve25519-dalek/blob/59837c6ecff02b77b9d5ff84dbc239d0cf33ef90/vendor/ristretto.sage#L699
|
|
452
|
+
if (!DcfPoint.BASE) DcfPoint.BASE = new DcfPoint(ed448.ExtendedPoint.BASE).multiply(_2n);
|
|
453
|
+
if (!DcfPoint.ZERO) DcfPoint.ZERO = new DcfPoint(ed448.ExtendedPoint.ZERO);
|
|
454
|
+
return DcfPoint;
|
|
455
|
+
})();
|
|
456
|
+
|
|
457
|
+
// Hashing to decaf448. https://www.rfc-editor.org/rfc/rfc9380#appendix-C
|
|
458
|
+
export const hashToDecaf448 = (msg: Uint8Array, options: htfBasicOpts) => {
|
|
459
|
+
const d = options.DST;
|
|
460
|
+
const DST = typeof d === 'string' ? utf8ToBytes(d) : d;
|
|
461
|
+
const uniform_bytes = expand_message_xof(msg, DST, 112, 224, shake256);
|
|
462
|
+
const P = DcfPoint.hashToCurve(uniform_bytes);
|
|
463
|
+
return P;
|
|
464
|
+
};
|
|
465
|
+
export const hash_to_decaf448 = hashToDecaf448; // legacy
|
package/src/jubjub.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { Field } from './abstract/modular.js';
|
|
|
11
11
|
* jubjub does not use EdDSA, so `hash`/sha512 params are passed because interface expects them.
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
export const jubjub = twistedEdwards({
|
|
14
|
+
export const jubjub = /* @__PURE__ */ twistedEdwards({
|
|
15
15
|
// Params: a, d
|
|
16
16
|
a: BigInt('0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000000'),
|
|
17
17
|
d: BigInt('0x2a9318e74bfa2b48f5fd9207e6bd7fd4292d7f6d37579d2601065fd6d6343eb1'),
|