@noble/curves 1.9.7 → 2.0.0-beta.2
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 +520 -505
- package/abstract/bls.d.ts +58 -120
- package/abstract/bls.d.ts.map +1 -1
- package/abstract/bls.js +108 -152
- package/abstract/bls.js.map +1 -1
- package/abstract/curve.d.ts +18 -54
- package/abstract/curve.d.ts.map +1 -1
- package/abstract/curve.js +30 -49
- package/abstract/curve.js.map +1 -1
- package/abstract/edwards.d.ts +18 -77
- package/abstract/edwards.d.ts.map +1 -1
- package/abstract/edwards.js +68 -144
- package/abstract/edwards.js.map +1 -1
- package/abstract/fft.js +14 -27
- package/abstract/fft.js.map +1 -1
- package/abstract/hash-to-curve.d.ts +35 -47
- package/abstract/hash-to-curve.d.ts.map +1 -1
- package/abstract/hash-to-curve.js +42 -46
- package/abstract/hash-to-curve.js.map +1 -1
- package/abstract/modular.d.ts +5 -17
- package/abstract/modular.d.ts.map +1 -1
- package/abstract/modular.js +170 -169
- package/abstract/modular.js.map +1 -1
- package/abstract/montgomery.d.ts +7 -12
- package/abstract/montgomery.d.ts.map +1 -1
- package/abstract/montgomery.js +22 -29
- package/abstract/montgomery.js.map +1 -1
- package/abstract/oprf.d.ts +282 -0
- package/abstract/oprf.d.ts.map +1 -0
- package/abstract/oprf.js +297 -0
- package/abstract/oprf.js.map +1 -0
- package/abstract/poseidon.d.ts.map +1 -1
- package/abstract/poseidon.js +26 -31
- package/abstract/poseidon.js.map +1 -1
- package/abstract/tower.d.ts.map +1 -1
- package/abstract/tower.js +43 -19
- package/abstract/tower.js.map +1 -1
- package/abstract/weierstrass.d.ts +77 -168
- package/abstract/weierstrass.d.ts.map +1 -1
- package/abstract/weierstrass.js +184 -389
- package/abstract/weierstrass.js.map +1 -1
- package/bls12-381.d.ts +5 -11
- package/bls12-381.d.ts.map +1 -1
- package/bls12-381.js +161 -181
- package/bls12-381.js.map +1 -1
- package/bn254.d.ts +59 -11
- package/bn254.d.ts.map +1 -1
- package/bn254.js +69 -97
- package/bn254.js.map +1 -1
- package/ed25519.d.ts +33 -48
- package/ed25519.d.ts.map +1 -1
- package/ed25519.js +147 -161
- package/ed25519.js.map +1 -1
- package/ed448.d.ts +27 -36
- package/ed448.d.ts.map +1 -1
- package/ed448.js +143 -164
- package/ed448.js.map +1 -1
- package/index.d.ts +1 -0
- package/index.js +20 -4
- package/index.js.map +1 -1
- package/misc.d.ts +10 -14
- package/misc.d.ts.map +1 -1
- package/misc.js +53 -62
- package/misc.js.map +1 -1
- package/nist.d.ts +31 -16
- package/nist.d.ts.map +1 -1
- package/nist.js +75 -64
- package/nist.js.map +1 -1
- package/package.json +20 -234
- package/secp256k1.d.ts +17 -30
- package/secp256k1.d.ts.map +1 -1
- package/secp256k1.js +59 -73
- package/secp256k1.js.map +1 -1
- package/src/abstract/bls.ts +207 -354
- package/src/abstract/curve.ts +25 -84
- package/src/abstract/edwards.ts +68 -193
- package/src/abstract/hash-to-curve.ts +71 -85
- package/src/abstract/modular.ts +150 -134
- package/src/abstract/montgomery.ts +28 -35
- package/src/abstract/oprf.ts +600 -0
- package/src/abstract/poseidon.ts +6 -8
- package/src/abstract/tower.ts +0 -3
- package/src/abstract/weierstrass.ts +203 -525
- package/src/bls12-381.ts +133 -139
- package/src/bn254.ts +69 -93
- package/src/ed25519.ts +106 -133
- package/src/ed448.ts +111 -138
- package/src/index.ts +19 -3
- package/src/misc.ts +68 -51
- package/src/nist.ts +77 -70
- package/src/secp256k1.ts +46 -81
- package/src/utils.ts +67 -137
- package/src/webcrypto.ts +403 -0
- package/utils.d.ts +31 -38
- package/utils.d.ts.map +1 -1
- package/utils.js +66 -185
- package/utils.js.map +1 -1
- package/webcrypto.d.ts +99 -0
- package/webcrypto.d.ts.map +1 -0
- package/webcrypto.js +256 -0
- package/webcrypto.js.map +1 -0
- package/_shortw_utils.d.ts +0 -19
- package/_shortw_utils.d.ts.map +0 -1
- package/_shortw_utils.js +0 -20
- package/_shortw_utils.js.map +0 -1
- package/abstract/utils.d.ts +0 -78
- package/abstract/utils.d.ts.map +0 -1
- package/abstract/utils.js +0 -73
- package/abstract/utils.js.map +0 -1
- package/esm/_shortw_utils.d.ts +0 -19
- package/esm/_shortw_utils.d.ts.map +0 -1
- package/esm/_shortw_utils.js +0 -16
- package/esm/_shortw_utils.js.map +0 -1
- package/esm/abstract/bls.d.ts +0 -190
- package/esm/abstract/bls.d.ts.map +0 -1
- package/esm/abstract/bls.js +0 -408
- package/esm/abstract/bls.js.map +0 -1
- package/esm/abstract/curve.d.ts +0 -231
- package/esm/abstract/curve.d.ts.map +0 -1
- package/esm/abstract/curve.js +0 -465
- package/esm/abstract/curve.js.map +0 -1
- package/esm/abstract/edwards.d.ts +0 -243
- package/esm/abstract/edwards.d.ts.map +0 -1
- package/esm/abstract/edwards.js +0 -627
- package/esm/abstract/edwards.js.map +0 -1
- package/esm/abstract/fft.d.ts +0 -122
- package/esm/abstract/fft.d.ts.map +0 -1
- package/esm/abstract/fft.js +0 -425
- package/esm/abstract/fft.js.map +0 -1
- package/esm/abstract/hash-to-curve.d.ts +0 -102
- package/esm/abstract/hash-to-curve.d.ts.map +0 -1
- package/esm/abstract/hash-to-curve.js +0 -203
- package/esm/abstract/hash-to-curve.js.map +0 -1
- package/esm/abstract/modular.d.ts +0 -171
- package/esm/abstract/modular.d.ts.map +0 -1
- package/esm/abstract/modular.js +0 -530
- package/esm/abstract/modular.js.map +0 -1
- package/esm/abstract/montgomery.d.ts +0 -30
- package/esm/abstract/montgomery.d.ts.map +0 -1
- package/esm/abstract/montgomery.js +0 -157
- package/esm/abstract/montgomery.js.map +0 -1
- package/esm/abstract/poseidon.d.ts +0 -68
- package/esm/abstract/poseidon.d.ts.map +0 -1
- package/esm/abstract/poseidon.js +0 -296
- package/esm/abstract/poseidon.js.map +0 -1
- package/esm/abstract/tower.d.ts +0 -95
- package/esm/abstract/tower.d.ts.map +0 -1
- package/esm/abstract/tower.js +0 -714
- package/esm/abstract/tower.js.map +0 -1
- package/esm/abstract/utils.d.ts +0 -78
- package/esm/abstract/utils.d.ts.map +0 -1
- package/esm/abstract/utils.js +0 -70
- package/esm/abstract/utils.js.map +0 -1
- package/esm/abstract/weierstrass.d.ts +0 -416
- package/esm/abstract/weierstrass.d.ts.map +0 -1
- package/esm/abstract/weierstrass.js +0 -1413
- package/esm/abstract/weierstrass.js.map +0 -1
- package/esm/bls12-381.d.ts +0 -16
- package/esm/bls12-381.d.ts.map +0 -1
- package/esm/bls12-381.js +0 -705
- package/esm/bls12-381.js.map +0 -1
- package/esm/bn254.d.ts +0 -18
- package/esm/bn254.d.ts.map +0 -1
- package/esm/bn254.js +0 -214
- package/esm/bn254.js.map +0 -1
- package/esm/ed25519.d.ts +0 -106
- package/esm/ed25519.d.ts.map +0 -1
- package/esm/ed25519.js +0 -467
- package/esm/ed25519.js.map +0 -1
- package/esm/ed448.d.ts +0 -100
- package/esm/ed448.d.ts.map +0 -1
- package/esm/ed448.js +0 -459
- package/esm/ed448.js.map +0 -1
- package/esm/index.d.ts +0 -2
- package/esm/index.d.ts.map +0 -1
- package/esm/index.js +0 -17
- package/esm/index.js.map +0 -1
- package/esm/jubjub.d.ts +0 -12
- package/esm/jubjub.d.ts.map +0 -1
- package/esm/jubjub.js +0 -12
- package/esm/jubjub.js.map +0 -1
- package/esm/misc.d.ts +0 -19
- package/esm/misc.d.ts.map +0 -1
- package/esm/misc.js +0 -109
- package/esm/misc.js.map +0 -1
- package/esm/nist.d.ts +0 -21
- package/esm/nist.d.ts.map +0 -1
- package/esm/nist.js +0 -132
- package/esm/nist.js.map +0 -1
- package/esm/p256.d.ts +0 -16
- package/esm/p256.d.ts.map +0 -1
- package/esm/p256.js +0 -16
- package/esm/p256.js.map +0 -1
- package/esm/p384.d.ts +0 -16
- package/esm/p384.d.ts.map +0 -1
- package/esm/p384.js +0 -16
- package/esm/p384.js.map +0 -1
- package/esm/p521.d.ts +0 -16
- package/esm/p521.d.ts.map +0 -1
- package/esm/p521.js +0 -16
- package/esm/p521.js.map +0 -1
- package/esm/package.json +0 -4
- package/esm/pasta.d.ts +0 -10
- package/esm/pasta.d.ts.map +0 -1
- package/esm/pasta.js +0 -10
- package/esm/pasta.js.map +0 -1
- package/esm/secp256k1.d.ts +0 -89
- package/esm/secp256k1.d.ts.map +0 -1
- package/esm/secp256k1.js +0 -294
- package/esm/secp256k1.js.map +0 -1
- package/esm/utils.d.ts +0 -110
- package/esm/utils.d.ts.map +0 -1
- package/esm/utils.js +0 -322
- package/esm/utils.js.map +0 -1
- package/jubjub.d.ts +0 -12
- package/jubjub.d.ts.map +0 -1
- package/jubjub.js +0 -15
- package/jubjub.js.map +0 -1
- package/p256.d.ts +0 -16
- package/p256.d.ts.map +0 -1
- package/p256.js +0 -13
- package/p256.js.map +0 -1
- package/p384.d.ts +0 -16
- package/p384.d.ts.map +0 -1
- package/p384.js +0 -13
- package/p384.js.map +0 -1
- package/p521.d.ts +0 -16
- package/p521.d.ts.map +0 -1
- package/p521.js +0 -13
- package/p521.js.map +0 -1
- package/pasta.d.ts +0 -10
- package/pasta.d.ts.map +0 -1
- package/pasta.js +0 -13
- package/pasta.js.map +0 -1
- package/src/_shortw_utils.ts +0 -21
- package/src/abstract/utils.ts +0 -80
- package/src/jubjub.ts +0 -12
- package/src/p256.ts +0 -15
- package/src/p384.ts +0 -15
- package/src/p521.ts +0 -15
- package/src/package.json +0 -3
- package/src/pasta.ts +0 -9
package/src/ed448.ts
CHANGED
|
@@ -8,14 +8,14 @@
|
|
|
8
8
|
*/
|
|
9
9
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
10
10
|
import { shake256 } from '@noble/hashes/sha3.js';
|
|
11
|
-
import {
|
|
11
|
+
import { concatBytes, hexToBytes, createHasher as wrapConstructor } from '@noble/hashes/utils.js';
|
|
12
12
|
import type { AffinePoint } from './abstract/curve.ts';
|
|
13
|
-
import { pippenger } from './abstract/curve.ts';
|
|
14
13
|
import {
|
|
14
|
+
eddsa,
|
|
15
15
|
edwards,
|
|
16
16
|
PrimeEdwardsPoint,
|
|
17
|
-
|
|
18
|
-
type
|
|
17
|
+
type EdDSA,
|
|
18
|
+
type EdDSAOpts,
|
|
19
19
|
type EdwardsOpts,
|
|
20
20
|
type EdwardsPoint,
|
|
21
21
|
type EdwardsPointCons,
|
|
@@ -24,14 +24,14 @@ import {
|
|
|
24
24
|
_DST_scalar,
|
|
25
25
|
createHasher,
|
|
26
26
|
expand_message_xof,
|
|
27
|
+
type H2CDSTOpts,
|
|
27
28
|
type H2CHasher,
|
|
28
29
|
type H2CHasherBase,
|
|
29
|
-
type H2CMethod,
|
|
30
|
-
type htfBasicOpts,
|
|
31
30
|
} from './abstract/hash-to-curve.ts';
|
|
32
31
|
import { Field, FpInvertBatch, isNegativeLE, mod, pow2, type IField } from './abstract/modular.ts';
|
|
33
|
-
import { montgomery, type MontgomeryECDH
|
|
34
|
-
import {
|
|
32
|
+
import { montgomery, type MontgomeryECDH } from './abstract/montgomery.ts';
|
|
33
|
+
import { createORPF, type OPRF } from './abstract/oprf.ts';
|
|
34
|
+
import { abytes, asciiToBytes, bytesToNumberLE, equalBytes } from './utils.ts';
|
|
35
35
|
|
|
36
36
|
// edwards448 curve
|
|
37
37
|
// a = 1n
|
|
@@ -39,10 +39,11 @@ import { asciiToBytes, bytesToNumberLE, ensureBytes, equalBytes, type Hex } from
|
|
|
39
39
|
// Finite field 2n**448n - 2n**224n - 1n
|
|
40
40
|
// Subgroup order
|
|
41
41
|
// 2n**446n - 13818066809895115352007386748515426880336692474882178609894547503885n
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
const ed448_CURVE_p = BigInt(
|
|
43
|
+
'0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
|
|
44
|
+
);
|
|
45
|
+
const ed448_CURVE: EdwardsOpts = /* @__PURE__ */ (() => ({
|
|
46
|
+
p: ed448_CURVE_p,
|
|
46
47
|
n: BigInt(
|
|
47
48
|
'0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffff7cca23e9c44edb49aed63690216cc2728dc58f552378c292ab5844f3'
|
|
48
49
|
),
|
|
@@ -57,28 +58,29 @@ const ed448_CURVE: EdwardsOpts = {
|
|
|
57
58
|
Gy: BigInt(
|
|
58
59
|
'0x693f46716eb6bc248876203756c9c7624bea73736ca3984087789c1e05a0c2d73ad3ff1ce67c39c4fdbd132c4ed7c8ad9808795bf230fa14'
|
|
59
60
|
),
|
|
60
|
-
};
|
|
61
|
+
}))();
|
|
61
62
|
|
|
62
63
|
// E448 NIST curve is identical to edwards448, except for:
|
|
63
64
|
// d = 39082/39081
|
|
64
65
|
// Gx = 3/2
|
|
65
|
-
const E448_CURVE: EdwardsOpts =
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
66
|
+
const E448_CURVE: EdwardsOpts = /* @__PURE__ */ (() =>
|
|
67
|
+
Object.assign({}, ed448_CURVE, {
|
|
68
|
+
d: BigInt(
|
|
69
|
+
'0xd78b4bdc7f0daf19f24f38c29373a2ccad46157242a50f37809b1da3412a12e79ccc9c81264cfe9ad080997058fb61c4243cc32dbaa156b9'
|
|
70
|
+
),
|
|
71
|
+
Gx: BigInt(
|
|
72
|
+
'0x79a70b2b70400553ae7c9df416c792c61128751ac92969240c25a07d728bdc93e21f7787ed6972249de732f38496cd11698713093e9c04fc'
|
|
73
|
+
),
|
|
74
|
+
Gy: BigInt(
|
|
75
|
+
'0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffff80000000000000000000000000000000000000000000000000000001'
|
|
76
|
+
),
|
|
77
|
+
}))();
|
|
76
78
|
|
|
77
79
|
const shake256_114 = /* @__PURE__ */ wrapConstructor(() => shake256.create({ dkLen: 114 }));
|
|
78
80
|
const shake256_64 = /* @__PURE__ */ wrapConstructor(() => shake256.create({ dkLen: 64 }));
|
|
79
81
|
|
|
80
82
|
// prettier-ignore
|
|
81
|
-
const _1n = BigInt(1), _2n = BigInt(2), _3n = BigInt(3), _4n = BigInt(4), _11n = BigInt(11);
|
|
83
|
+
const _1n = BigInt(1), _2n = BigInt(2), _3n = BigInt(3), _4n = /* @__PURE__ */ BigInt(4), _11n = BigInt(11);
|
|
82
84
|
// prettier-ignore
|
|
83
85
|
const _22n = BigInt(22), _44n = BigInt(44), _88n = BigInt(88), _223n = BigInt(223);
|
|
84
86
|
|
|
@@ -86,7 +88,7 @@ const _22n = BigInt(22), _44n = BigInt(44), _88n = BigInt(88), _223n = BigInt(22
|
|
|
86
88
|
// Used for efficient square root calculation.
|
|
87
89
|
// ((P-3)/4).toString(2) would produce bits [223x 1, 0, 222x 1]
|
|
88
90
|
function ed448_pow_Pminus3div4(x: bigint): bigint {
|
|
89
|
-
const P =
|
|
91
|
+
const P = ed448_CURVE_p;
|
|
90
92
|
const b2 = (x * x * x) % P;
|
|
91
93
|
const b3 = (b2 * b2 * x) % P;
|
|
92
94
|
const b6 = (pow2(b3, _3n, P) * b3) % P;
|
|
@@ -115,7 +117,7 @@ function adjustScalarBytes(bytes: Uint8Array): Uint8Array {
|
|
|
115
117
|
// Constant-time ratio of u to v. Allows to combine inversion and square root u/√v.
|
|
116
118
|
// Uses algo from RFC8032 5.1.3.
|
|
117
119
|
function uvRatio(u: bigint, v: bigint): { isValid: boolean; value: bigint } {
|
|
118
|
-
const P =
|
|
120
|
+
const P = ed448_CURVE_p;
|
|
119
121
|
// https://www.rfc-editor.org/rfc/rfc8032#section-5.2.3
|
|
120
122
|
// To compute the square root of (u/v), the first step is to compute the
|
|
121
123
|
// candidate root x = (u/v)^((p+1)/4). This can be done using the
|
|
@@ -138,10 +140,10 @@ function uvRatio(u: bigint, v: bigint): { isValid: boolean; value: bigint } {
|
|
|
138
140
|
// The value fits in 448 bits, but we use 456-bit (57-byte) elements because of bitflags.
|
|
139
141
|
// - ed25519 fits in 255 bits, allowing using last 1 byte for specifying bit flag of point negation.
|
|
140
142
|
// - ed448 fits in 448 bits. We can't use last 1 byte: we can only use a bit 224 in the middle.
|
|
141
|
-
const Fp = /* @__PURE__ */ (() => Field(
|
|
143
|
+
const Fp = /* @__PURE__ */ (() => Field(ed448_CURVE_p, { BITS: 456, isLE: true }))();
|
|
142
144
|
const Fn = /* @__PURE__ */ (() => Field(ed448_CURVE.n, { BITS: 456, isLE: true }))();
|
|
143
145
|
// decaf448 uses 448-bit (56-byte) keys
|
|
144
|
-
const Fp448 = /* @__PURE__ */ (() => Field(
|
|
146
|
+
const Fp448 = /* @__PURE__ */ (() => Field(ed448_CURVE_p, { BITS: 448, isLE: true }))();
|
|
145
147
|
const Fn448 = /* @__PURE__ */ (() => Field(ed448_CURVE.n, { BITS: 448, isLE: true }))();
|
|
146
148
|
|
|
147
149
|
// SHAKE256(dom4(phflag,context)||x, 114)
|
|
@@ -154,53 +156,48 @@ function dom4(data: Uint8Array, ctx: Uint8Array, phflag: boolean) {
|
|
|
154
156
|
data
|
|
155
157
|
);
|
|
156
158
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
Fp,
|
|
163
|
-
Fn,
|
|
164
|
-
nBitLength: Fn.BITS,
|
|
165
|
-
hash: shake256_114,
|
|
166
|
-
adjustScalarBytes,
|
|
167
|
-
domain: dom4,
|
|
168
|
-
uvRatio,
|
|
169
|
-
}))();
|
|
159
|
+
const ed448_Point = /* @__PURE__ */ edwards(ed448_CURVE, { Fp, Fn, uvRatio });
|
|
160
|
+
|
|
161
|
+
function ed4(opts: EdDSAOpts) {
|
|
162
|
+
return eddsa(ed448_Point, shake256_114, Object.assign({ adjustScalarBytes, domain: dom4 }, opts));
|
|
163
|
+
}
|
|
170
164
|
|
|
171
165
|
/**
|
|
172
166
|
* ed448 EdDSA curve and methods.
|
|
173
167
|
* @example
|
|
174
|
-
*
|
|
168
|
+
* ```js
|
|
169
|
+
* import { ed448 } from '@noble/curves/ed448.js';
|
|
175
170
|
* const { secretKey, publicKey } = ed448.keygen();
|
|
176
|
-
* const
|
|
171
|
+
* // const publicKey = ed448.getPublicKey(secretKey);
|
|
172
|
+
* const msg = new TextEncoder().encode('hello noble');
|
|
177
173
|
* const sig = ed448.sign(msg, secretKey);
|
|
178
174
|
* const isValid = ed448.verify(sig, msg, publicKey);
|
|
175
|
+
* ```
|
|
179
176
|
*/
|
|
180
|
-
export const ed448:
|
|
177
|
+
export const ed448: EdDSA = /* @__PURE__ */ ed4({});
|
|
181
178
|
|
|
182
179
|
// There is no ed448ctx, since ed448 supports ctx by default
|
|
183
|
-
/** Prehashed version of ed448.
|
|
184
|
-
export const ed448ph:
|
|
185
|
-
twistedEdwards({
|
|
186
|
-
...ED448_DEF,
|
|
187
|
-
prehash: shake256_64,
|
|
188
|
-
}))();
|
|
189
|
-
|
|
180
|
+
/** Prehashed version of ed448. See {@link ed448} */
|
|
181
|
+
export const ed448ph: EdDSA = /* @__PURE__ */ ed4({ prehash: shake256_64 });
|
|
190
182
|
/**
|
|
191
|
-
* E448
|
|
192
|
-
* E448 != edwards448 used in ed448.
|
|
183
|
+
* E448 (NIST) != edwards448 used in ed448.
|
|
193
184
|
* E448 is birationally equivalent to edwards448.
|
|
194
185
|
*/
|
|
195
|
-
export const E448: EdwardsPointCons = edwards(E448_CURVE);
|
|
186
|
+
export const E448: EdwardsPointCons = /* @__PURE__ */ edwards(E448_CURVE);
|
|
196
187
|
|
|
197
188
|
/**
|
|
198
189
|
* ECDH using curve448 aka x448.
|
|
199
|
-
*
|
|
200
|
-
*
|
|
190
|
+
*
|
|
191
|
+
* @example
|
|
192
|
+
* ```js
|
|
193
|
+
* import { x448 } from '@noble/curves/ed448.js';
|
|
194
|
+
* const alice = x448.keygen();
|
|
195
|
+
* const bob = x448.keygen();
|
|
196
|
+
* const shared = x448.getSharedSecret(alice.secretKey, bob.publicKey);
|
|
197
|
+
* ```
|
|
201
198
|
*/
|
|
202
|
-
export const x448:
|
|
203
|
-
const P =
|
|
199
|
+
export const x448: MontgomeryECDH = /* @__PURE__ */ (() => {
|
|
200
|
+
const P = ed448_CURVE_p;
|
|
204
201
|
return montgomery({
|
|
205
202
|
P,
|
|
206
203
|
type: 'x448',
|
|
@@ -214,7 +211,7 @@ export const x448: XCurveFn = /* @__PURE__ */ (() => {
|
|
|
214
211
|
})();
|
|
215
212
|
|
|
216
213
|
// Hash To Curve Elligator2 Map
|
|
217
|
-
const ELL2_C1 = /* @__PURE__ */ (() => (
|
|
214
|
+
const ELL2_C1 = /* @__PURE__ */ (() => (ed448_CURVE_p - BigInt(3)) / BigInt(4))(); // 1. c1 = (q - 3) / 4 # Integer arithmetic
|
|
218
215
|
const ELL2_J = /* @__PURE__ */ BigInt(156326);
|
|
219
216
|
|
|
220
217
|
function map_to_curve_elligator2_curve448(u: bigint) {
|
|
@@ -291,11 +288,11 @@ function map_to_curve_elligator2_edwards448(u: bigint) {
|
|
|
291
288
|
}
|
|
292
289
|
|
|
293
290
|
/** Hashing / encoding to ed448 points / field. RFC 9380 methods. */
|
|
294
|
-
export const ed448_hasher: H2CHasher<
|
|
295
|
-
createHasher(
|
|
291
|
+
export const ed448_hasher: H2CHasher<EdwardsPointCons> = /* @__PURE__ */ (() =>
|
|
292
|
+
createHasher(ed448_Point, (scalars: bigint[]) => map_to_curve_elligator2_edwards448(scalars[0]), {
|
|
296
293
|
DST: 'edwards448_XOF:SHAKE256_ELL2_RO_',
|
|
297
294
|
encodeDST: 'edwards448_XOF:SHAKE256_ELL2_NU_',
|
|
298
|
-
p:
|
|
295
|
+
p: ed448_CURVE_p,
|
|
299
296
|
m: 1,
|
|
300
297
|
k: 224,
|
|
301
298
|
expand: 'xof',
|
|
@@ -323,9 +320,8 @@ const invertSqrt = (number: bigint) => uvRatio(_1n, number);
|
|
|
323
320
|
* and [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-element-derivation-2).
|
|
324
321
|
*/
|
|
325
322
|
function calcElligatorDecafMap(r0: bigint): EdwardsPoint {
|
|
326
|
-
const { d } = ed448_CURVE;
|
|
327
|
-
const
|
|
328
|
-
const mod = (n: bigint) => Fp.create(n);
|
|
323
|
+
const { d, p: P } = ed448_CURVE;
|
|
324
|
+
const mod = (n: bigint) => Fp448.create(n);
|
|
329
325
|
|
|
330
326
|
const r = mod(-(r0 * r0)); // 1
|
|
331
327
|
const u0 = mod(d * (r - _1n)); // 2
|
|
@@ -348,20 +344,7 @@ function calcElligatorDecafMap(r0: bigint): EdwardsPoint {
|
|
|
348
344
|
const W1 = mod(s2 + _1n); // 9
|
|
349
345
|
const W2 = mod(s2 - _1n); // 10
|
|
350
346
|
const W3 = mod(v_prime * s * (r - _1n) * ONE_MINUS_TWO_D + sgn); // 11
|
|
351
|
-
return new
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
function decaf448_map(bytes: Uint8Array): _DecafPoint {
|
|
355
|
-
abytes(bytes, 112);
|
|
356
|
-
const skipValidation = true;
|
|
357
|
-
// Note: Similar to the field element decoding described in
|
|
358
|
-
// [RFC7748], and unlike the field element decoding described in
|
|
359
|
-
// Section 5.3.1, non-canonical values are accepted.
|
|
360
|
-
const r1 = Fp448.create(Fp448.fromBytes(bytes.subarray(0, 56), skipValidation));
|
|
361
|
-
const R1 = calcElligatorDecafMap(r1);
|
|
362
|
-
const r2 = Fp448.create(Fp448.fromBytes(bytes.subarray(56, 112), skipValidation));
|
|
363
|
-
const R2 = calcElligatorDecafMap(r2);
|
|
364
|
-
return new _DecafPoint(R1.add(R2));
|
|
347
|
+
return new ed448_Point(mod(W0 * W3), mod(W2 * W1), mod(W1 * W3), mod(W0 * W2));
|
|
365
348
|
}
|
|
366
349
|
|
|
367
350
|
/**
|
|
@@ -375,10 +358,10 @@ class _DecafPoint extends PrimeEdwardsPoint<_DecafPoint> {
|
|
|
375
358
|
// The following gymnastics is done because typescript strips comments otherwise
|
|
376
359
|
// prettier-ignore
|
|
377
360
|
static BASE: _DecafPoint =
|
|
378
|
-
/* @__PURE__ */ (() => new _DecafPoint(
|
|
361
|
+
/* @__PURE__ */ (() => new _DecafPoint(ed448_Point.BASE).multiplyUnsafe(_2n))();
|
|
379
362
|
// prettier-ignore
|
|
380
363
|
static ZERO: _DecafPoint =
|
|
381
|
-
/* @__PURE__ */ (() => new _DecafPoint(
|
|
364
|
+
/* @__PURE__ */ (() => new _DecafPoint(ed448_Point.ZERO))();
|
|
382
365
|
// prettier-ignore
|
|
383
366
|
static Fp: IField<bigint> =
|
|
384
367
|
/* @__PURE__ */ (() => Fp448)();
|
|
@@ -391,7 +374,7 @@ class _DecafPoint extends PrimeEdwardsPoint<_DecafPoint> {
|
|
|
391
374
|
}
|
|
392
375
|
|
|
393
376
|
static fromAffine(ap: AffinePoint<bigint>): _DecafPoint {
|
|
394
|
-
return new _DecafPoint(
|
|
377
|
+
return new _DecafPoint(ed448_Point.fromAffine(ap));
|
|
395
378
|
}
|
|
396
379
|
|
|
397
380
|
protected assertSame(other: _DecafPoint): void {
|
|
@@ -402,21 +385,14 @@ class _DecafPoint extends PrimeEdwardsPoint<_DecafPoint> {
|
|
|
402
385
|
return new _DecafPoint(ep);
|
|
403
386
|
}
|
|
404
387
|
|
|
405
|
-
/** @deprecated use `import { decaf448_hasher } from '@noble/curves/ed448.js';` */
|
|
406
|
-
static hashToCurve(hex: Hex): _DecafPoint {
|
|
407
|
-
return decaf448_map(ensureBytes('decafHash', hex, 112));
|
|
408
|
-
}
|
|
409
|
-
|
|
410
388
|
static fromBytes(bytes: Uint8Array): _DecafPoint {
|
|
411
389
|
abytes(bytes, 56);
|
|
412
|
-
const { d } = ed448_CURVE;
|
|
413
|
-
const P = Fp.ORDER;
|
|
390
|
+
const { d, p: P } = ed448_CURVE;
|
|
414
391
|
const mod = (n: bigint) => Fp448.create(n);
|
|
415
392
|
const s = Fp448.fromBytes(bytes);
|
|
416
393
|
|
|
417
394
|
// 1. Check that s_bytes is the canonical encoding of a field element, or else abort.
|
|
418
395
|
// 2. Check that s is non-negative, or else abort
|
|
419
|
-
|
|
420
396
|
if (!equalBytes(Fn448.toBytes(s), bytes) || isNegativeLE(s, P))
|
|
421
397
|
throw new Error('invalid decaf448 encoding 1');
|
|
422
398
|
|
|
@@ -435,7 +411,7 @@ class _DecafPoint extends PrimeEdwardsPoint<_DecafPoint> {
|
|
|
435
411
|
const t = mod(x * y); // 8
|
|
436
412
|
|
|
437
413
|
if (!isValid) throw new Error('invalid decaf448 encoding 2');
|
|
438
|
-
return new _DecafPoint(new
|
|
414
|
+
return new _DecafPoint(new ed448_Point(x, y, _1n, t));
|
|
439
415
|
}
|
|
440
416
|
|
|
441
417
|
/**
|
|
@@ -443,13 +419,8 @@ class _DecafPoint extends PrimeEdwardsPoint<_DecafPoint> {
|
|
|
443
419
|
* Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-decode-2).
|
|
444
420
|
* @param hex Decaf-encoded 56 bytes. Not every 56-byte string is valid decaf encoding
|
|
445
421
|
*/
|
|
446
|
-
static fromHex(hex:
|
|
447
|
-
return _DecafPoint.fromBytes(
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
/** @deprecated use `import { pippenger } from '@noble/curves/abstract/curve.js';` */
|
|
451
|
-
static msm(points: _DecafPoint[], scalars: bigint[]): _DecafPoint {
|
|
452
|
-
return pippenger(_DecafPoint, Fn, points, scalars);
|
|
422
|
+
static fromHex(hex: string): _DecafPoint {
|
|
423
|
+
return _DecafPoint.fromBytes(hexToBytes(hex));
|
|
453
424
|
}
|
|
454
425
|
|
|
455
426
|
/**
|
|
@@ -458,8 +429,8 @@ class _DecafPoint extends PrimeEdwardsPoint<_DecafPoint> {
|
|
|
458
429
|
*/
|
|
459
430
|
toBytes(): Uint8Array {
|
|
460
431
|
const { X, Z, T } = this.ep;
|
|
461
|
-
const P =
|
|
462
|
-
const mod = (n: bigint) =>
|
|
432
|
+
const P = ed448_CURVE.p;
|
|
433
|
+
const mod = (n: bigint) => Fp448.create(n);
|
|
463
434
|
const u1 = mod(mod(X + T) * mod(X - T)); // 1
|
|
464
435
|
const x2 = mod(X * X);
|
|
465
436
|
const { value: invsqrt } = invertSqrt(mod(u1 * ONE_MINUS_D * x2)); // 2
|
|
@@ -480,7 +451,7 @@ class _DecafPoint extends PrimeEdwardsPoint<_DecafPoint> {
|
|
|
480
451
|
const { X: X1, Y: Y1 } = this.ep;
|
|
481
452
|
const { X: X2, Y: Y2 } = other.ep;
|
|
482
453
|
// (x1 * y2 == y1 * x2)
|
|
483
|
-
return
|
|
454
|
+
return Fp448.create(X1 * Y2) === Fp448.create(Y1 * X2);
|
|
484
455
|
}
|
|
485
456
|
|
|
486
457
|
is0(): boolean {
|
|
@@ -493,28 +464,52 @@ export const decaf448: {
|
|
|
493
464
|
} = { Point: _DecafPoint };
|
|
494
465
|
|
|
495
466
|
/** Hashing to decaf448 points / field. RFC 9380 methods. */
|
|
496
|
-
export const decaf448_hasher: H2CHasherBase<
|
|
497
|
-
|
|
467
|
+
export const decaf448_hasher: H2CHasherBase<typeof _DecafPoint> = {
|
|
468
|
+
Point: _DecafPoint,
|
|
469
|
+
hashToCurve(msg: Uint8Array, options?: H2CDSTOpts): _DecafPoint {
|
|
498
470
|
const DST = options?.DST || 'decaf448_XOF:SHAKE256_D448MAP_RO_';
|
|
499
|
-
return
|
|
471
|
+
return decaf448_hasher.deriveToCurve!(expand_message_xof(msg, DST, 112, 224, shake256));
|
|
500
472
|
},
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
473
|
+
/**
|
|
474
|
+
* Warning: has big modulo bias of 2^-64.
|
|
475
|
+
* RFC is invalid. RFC says "use 64-byte xof", while for 2^-112 bias
|
|
476
|
+
* it must use 84-byte xof (56+56/2), not 64.
|
|
477
|
+
*/
|
|
478
|
+
hashToScalar(msg: Uint8Array, options: H2CDSTOpts = { DST: _DST_scalar }): bigint {
|
|
505
479
|
// Can't use `Fn448.fromBytes()`. 64-byte input => 56-byte field element
|
|
506
480
|
const xof = expand_message_xof(msg, options.DST, 64, 256, shake256);
|
|
507
481
|
return Fn448.create(bytesToNumberLE(xof));
|
|
508
482
|
},
|
|
483
|
+
/**
|
|
484
|
+
* HashToCurve-like construction based on RFC 9496 (Element Derivation).
|
|
485
|
+
* Converts 112 uniform random bytes into a curve point.
|
|
486
|
+
*
|
|
487
|
+
* WARNING: This represents an older hash-to-curve construction, preceding the finalization of RFC 9380.
|
|
488
|
+
* It was later reused as a component in the newer `hash_to_ristretto255` function defined in RFC 9380.
|
|
489
|
+
*/
|
|
490
|
+
deriveToCurve(bytes: Uint8Array): _DecafPoint {
|
|
491
|
+
abytes(bytes, 112);
|
|
492
|
+
const skipValidation = true;
|
|
493
|
+
// Note: Similar to the field element decoding described in
|
|
494
|
+
// [RFC7748], and unlike the field element decoding described in
|
|
495
|
+
// Section 5.3.1, non-canonical values are accepted.
|
|
496
|
+
const r1 = Fp448.create(Fp448.fromBytes(bytes.subarray(0, 56), skipValidation));
|
|
497
|
+
const R1 = calcElligatorDecafMap(r1);
|
|
498
|
+
const r2 = Fp448.create(Fp448.fromBytes(bytes.subarray(56, 112), skipValidation));
|
|
499
|
+
const R2 = calcElligatorDecafMap(r2);
|
|
500
|
+
return new _DecafPoint(R1.add(R2));
|
|
501
|
+
},
|
|
509
502
|
};
|
|
510
503
|
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
504
|
+
/** decaf448 OPRF, defined in RFC 9497. */
|
|
505
|
+
export const decaf448_oprf: OPRF = /* @__PURE__ */ (() =>
|
|
506
|
+
createORPF({
|
|
507
|
+
name: 'decaf448-SHAKE256',
|
|
508
|
+
Point: _DecafPoint,
|
|
509
|
+
hash: (msg: Uint8Array) => shake256(msg, { dkLen: 64 }),
|
|
510
|
+
hashToGroup: decaf448_hasher.hashToCurve,
|
|
511
|
+
hashToScalar: decaf448_hasher.hashToScalar,
|
|
512
|
+
}))();
|
|
518
513
|
|
|
519
514
|
/**
|
|
520
515
|
* Weird / bogus points, useful for debugging.
|
|
@@ -528,25 +523,3 @@ export const ED448_TORSION_SUBGROUP: string[] = [
|
|
|
528
523
|
'000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
|
|
529
524
|
'000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080',
|
|
530
525
|
];
|
|
531
|
-
|
|
532
|
-
type DcfHasher = (msg: Uint8Array, options: htfBasicOpts) => _DecafPoint;
|
|
533
|
-
|
|
534
|
-
/** @deprecated use `decaf448.Point` */
|
|
535
|
-
export const DecafPoint: typeof _DecafPoint = _DecafPoint;
|
|
536
|
-
/** @deprecated use `import { ed448_hasher } from '@noble/curves/ed448.js';` */
|
|
537
|
-
export const hashToCurve: H2CMethod<bigint> = /* @__PURE__ */ (() => ed448_hasher.hashToCurve)();
|
|
538
|
-
/** @deprecated use `import { ed448_hasher } from '@noble/curves/ed448.js';` */
|
|
539
|
-
export const encodeToCurve: H2CMethod<bigint> = /* @__PURE__ */ (() =>
|
|
540
|
-
ed448_hasher.encodeToCurve)();
|
|
541
|
-
/** @deprecated use `import { decaf448_hasher } from '@noble/curves/ed448.js';` */
|
|
542
|
-
export const hashToDecaf448: DcfHasher = /* @__PURE__ */ (() =>
|
|
543
|
-
decaf448_hasher.hashToCurve as DcfHasher)();
|
|
544
|
-
/** @deprecated use `import { decaf448_hasher } from '@noble/curves/ed448.js';` */
|
|
545
|
-
export const hash_to_decaf448: DcfHasher = /* @__PURE__ */ (() =>
|
|
546
|
-
decaf448_hasher.hashToCurve as DcfHasher)();
|
|
547
|
-
/** @deprecated use `ed448.utils.toMontgomery` */
|
|
548
|
-
export function edwardsToMontgomeryPub(edwardsPub: string | Uint8Array): Uint8Array {
|
|
549
|
-
return ed448.utils.toMontgomery(ensureBytes('pub', edwardsPub));
|
|
550
|
-
}
|
|
551
|
-
/** @deprecated use `ed448.utils.toMontgomery` */
|
|
552
|
-
export const edwardsToMontgomery: typeof edwardsToMontgomeryPub = edwardsToMontgomeryPub;
|
package/src/index.ts
CHANGED
|
@@ -4,12 +4,28 @@
|
|
|
4
4
|
* @example
|
|
5
5
|
```js
|
|
6
6
|
import { secp256k1, schnorr } from '@noble/curves/secp256k1.js';
|
|
7
|
-
import { ed25519, ed25519ph, ed25519ctx, x25519,
|
|
8
|
-
import { ed448, ed448ph,
|
|
7
|
+
import { ed25519, ed25519ph, ed25519ctx, x25519, ristretto255 } from '@noble/curves/ed25519.js';
|
|
8
|
+
import { ed448, ed448ph, x448, decaf448 } from '@noble/curves/ed448.js';
|
|
9
9
|
import { p256, p384, p521 } from '@noble/curves/nist.js';
|
|
10
10
|
import { bls12_381 } from '@noble/curves/bls12-381.js';
|
|
11
11
|
import { bn254 } from '@noble/curves/bn254.js';
|
|
12
|
-
import {
|
|
12
|
+
import { jubjub, babyjubjub, brainpoolP256r1, brainpoolP384r1, brainpoolP512r1 } from '@noble/curves/misc.js';
|
|
13
|
+
import * as webcrypto from '@noble/curves/webcrypto.js';
|
|
14
|
+
|
|
15
|
+
// hash-to-curve
|
|
16
|
+
import { secp256k1_hasher } from '@noble/curves/secp256k1.js';
|
|
17
|
+
import { p256_hasher, p384_hasher, p521_hasher } from '@noble/curves/nist.js';
|
|
18
|
+
import { ristretto255_hasher } from '@noble/curves/ed25519.js';
|
|
19
|
+
import { decaf448_hasher } from '@noble/curves/ed448.js';
|
|
20
|
+
|
|
21
|
+
// OPRFs
|
|
22
|
+
import { p256_oprf, p384_oprf, p521_oprf } from '@noble/curves/nist.js';
|
|
23
|
+
import { ristretto255_oprf } from '@noble/curves/ed25519.js';
|
|
24
|
+
import { decaf448_oprf } from '@noble/curves/ed448.js';
|
|
25
|
+
|
|
26
|
+
// utils
|
|
27
|
+
import { bytesToHex, hexToBytes, concatBytes } from '@noble/curves/abstract/utils.js';
|
|
28
|
+
import { Field } from '@noble/curves/abstract/modular.js';
|
|
13
29
|
```
|
|
14
30
|
*/
|
|
15
31
|
throw new Error('root module cannot be imported: import submodules instead. Check out README');
|
package/src/misc.ts
CHANGED
|
@@ -6,18 +6,19 @@
|
|
|
6
6
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
7
7
|
import { blake256 } from '@noble/hashes/blake1.js';
|
|
8
8
|
import { blake2s } from '@noble/hashes/blake2.js';
|
|
9
|
-
import { sha256, sha512 } from '@noble/hashes/sha2.js';
|
|
10
|
-
import { concatBytes
|
|
9
|
+
import { sha256, sha384, sha512 } from '@noble/hashes/sha2.js';
|
|
10
|
+
import { concatBytes } from '@noble/hashes/utils.js';
|
|
11
11
|
import {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
eddsa,
|
|
13
|
+
edwards,
|
|
14
|
+
type EdDSA,
|
|
14
15
|
type EdwardsOpts,
|
|
15
16
|
type EdwardsPoint,
|
|
16
17
|
} from './abstract/edwards.ts';
|
|
17
|
-
import {
|
|
18
|
-
import { weierstrass, type CurveFn as WCurveFn } from './abstract/weierstrass.ts';
|
|
18
|
+
import { ecdsa, weierstrass, type ECDSA, type WeierstrassOpts } from './abstract/weierstrass.ts';
|
|
19
19
|
import { bls12_381_Fr } from './bls12-381.ts';
|
|
20
20
|
import { bn254_Fr } from './bn254.ts';
|
|
21
|
+
import { asciiToBytes } from './utils.ts';
|
|
21
22
|
|
|
22
23
|
// Jubjub curves have 𝔽p over scalar fields of other curves. They are friendly to ZK proofs.
|
|
23
24
|
// jubjub Fp = bls n. babyjubjub Fp = bn254 n.
|
|
@@ -32,11 +33,7 @@ const jubjub_CURVE: EdwardsOpts = {
|
|
|
32
33
|
Gy: BigInt('0x1d523cf1ddab1a1793132e78c866c0c33e26ba5cc220fed7cc3f870e59d292aa'),
|
|
33
34
|
};
|
|
34
35
|
/** Curve over scalar field of bls12-381. jubjub Fp = bls n */
|
|
35
|
-
export const jubjub:
|
|
36
|
-
...jubjub_CURVE,
|
|
37
|
-
Fp: bls12_381_Fr,
|
|
38
|
-
hash: sha512,
|
|
39
|
-
});
|
|
36
|
+
export const jubjub: EdDSA = /* @__PURE__ */ eddsa(edwards(jubjub_CURVE), sha512);
|
|
40
37
|
|
|
41
38
|
const babyjubjub_CURVE: EdwardsOpts = {
|
|
42
39
|
p: bn254_Fr.ORDER,
|
|
@@ -48,13 +45,9 @@ const babyjubjub_CURVE: EdwardsOpts = {
|
|
|
48
45
|
Gy: BigInt('0xc19139cb84c680a6e14116da06056174a0cfa121e6e5c2450f87d64fc000001'),
|
|
49
46
|
};
|
|
50
47
|
/** Curve over scalar field of bn254. babyjubjub Fp = bn254 n */
|
|
51
|
-
export const babyjubjub:
|
|
52
|
-
...babyjubjub_CURVE,
|
|
53
|
-
Fp: bn254_Fr,
|
|
54
|
-
hash: blake256,
|
|
55
|
-
});
|
|
48
|
+
export const babyjubjub: EdDSA = /* @__PURE__ */ eddsa(edwards(babyjubjub_CURVE), blake256);
|
|
56
49
|
|
|
57
|
-
const jubjub_gh_first_block =
|
|
50
|
+
const jubjub_gh_first_block = asciiToBytes(
|
|
58
51
|
'096b36a5804bfacef1691e173c366a47ff5ba84a44f26ddd7e8d9f79d5b42df0'
|
|
59
52
|
);
|
|
60
53
|
|
|
@@ -63,7 +56,7 @@ export function jubjub_groupHash(tag: Uint8Array, personalization: Uint8Array):
|
|
|
63
56
|
const h = blake2s.create({ personalization, dkLen: 32 });
|
|
64
57
|
h.update(jubjub_gh_first_block);
|
|
65
58
|
h.update(tag);
|
|
66
|
-
// NOTE: returns
|
|
59
|
+
// NOTE: returns EdwardsPoint, in case it will be multiplied later
|
|
67
60
|
let p = jubjub.Point.fromBytes(h.digest());
|
|
68
61
|
// NOTE: cannot replace with isSmallOrder, returns Point*8
|
|
69
62
|
p = p.multiply(jubjub_CURVE.h);
|
|
@@ -73,7 +66,7 @@ export function jubjub_groupHash(tag: Uint8Array, personalization: Uint8Array):
|
|
|
73
66
|
|
|
74
67
|
// No secret data is leaked here at all.
|
|
75
68
|
// It operates over public data:
|
|
76
|
-
// const G_SPEND = jubjub.findGroupHash(Uint8Array.of(),
|
|
69
|
+
// const G_SPEND = jubjub.findGroupHash(Uint8Array.of(), asciiToBytes('Item_G_'));
|
|
77
70
|
export function jubjub_findGroupHash(m: Uint8Array, personalization: Uint8Array): EdwardsPoint {
|
|
78
71
|
const tag = concatBytes(m, Uint8Array.of(0));
|
|
79
72
|
const hashes = [];
|
|
@@ -87,38 +80,62 @@ export function jubjub_findGroupHash(m: Uint8Array, personalization: Uint8Array)
|
|
|
87
80
|
return hashes[0];
|
|
88
81
|
}
|
|
89
82
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
'
|
|
94
|
-
)
|
|
95
|
-
|
|
96
|
-
'
|
|
97
|
-
)
|
|
83
|
+
const brainpoolP256r1_CURVE: WeierstrassOpts<bigint> = {
|
|
84
|
+
p: BigInt('0xa9fb57dba1eea9bc3e660a909d838d726e3bf623d52620282013481d1f6e5377'),
|
|
85
|
+
a: BigInt('0x7d5a0975fc2c3057eef67530417affe7fb8055c126dc5c6ce94a4b44f330b5d9'),
|
|
86
|
+
b: BigInt('0x26dc5c6ce94a4b44f330b5d9bbd77cbf958416295cf7e1ce6bccdc18ff8c07b6'),
|
|
87
|
+
n: BigInt('0xa9fb57dba1eea9bc3e660a909d838d718c397aa3b561a6f7901e0e82974856a7'),
|
|
88
|
+
Gx: BigInt('0x8bd2aeb9cb7e57cb2c4b482ffc81b7afb9de27e1e3bd23c23a4453bd9ace3262'),
|
|
89
|
+
Gy: BigInt('0x547ef835c3dac4fd97f8461a14611dc9c27745132ded8e545c1d54c72f046997'),
|
|
90
|
+
h: BigInt(1),
|
|
91
|
+
};
|
|
92
|
+
/** Brainpool P256r1 with sha256, from RFC 5639. */
|
|
93
|
+
export const brainpoolP256r1: ECDSA = ecdsa(weierstrass(brainpoolP256r1_CURVE), sha256);
|
|
98
94
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
a: BigInt(
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
95
|
+
const brainpoolP384r1_CURVE: WeierstrassOpts<bigint> = {
|
|
96
|
+
p: BigInt(
|
|
97
|
+
'0x8cb91e82a3386d280f5d6f7e50e641df152f7109ed5456b412b1da197fb71123acd3a729901d1a71874700133107ec53'
|
|
98
|
+
),
|
|
99
|
+
a: BigInt(
|
|
100
|
+
'0x7bc382c63d8c150c3c72080ace05afa0c2bea28e4fb22787139165efba91f90f8aa5814a503ad4eb04a8c7dd22ce2826'
|
|
101
|
+
),
|
|
102
|
+
b: BigInt(
|
|
103
|
+
'0x04a8c7dd22ce28268b39b55416f0447c2fb77de107dcd2a62e880ea53eeb62d57cb4390295dbc9943ab78696fa504c11'
|
|
104
|
+
),
|
|
105
|
+
n: BigInt(
|
|
106
|
+
'0x8cb91e82a3386d280f5d6f7e50e641df152f7109ed5456b31f166e6cac0425a7cf3ab6af6b7fc3103b883202e9046565'
|
|
107
|
+
),
|
|
108
|
+
Gx: BigInt(
|
|
109
|
+
'0x1d1c64f068cf45ffa2a63a81b7c13f6b8847a3e77ef14fe3db7fcafe0cbd10e8e826e03436d646aaef87b2e247d4af1e'
|
|
110
|
+
),
|
|
111
|
+
Gy: BigInt(
|
|
112
|
+
'0x8abe1d7520f9c2a45cb1eb8e95cfd55262b70b29feec5864e19c054ff99129280e4646217791811142820341263c5315'
|
|
113
|
+
),
|
|
109
114
|
h: BigInt(1),
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
115
|
+
};
|
|
116
|
+
/** Brainpool P384r1 with sha384, from RFC 5639. */
|
|
117
|
+
export const brainpoolP384r1: ECDSA = ecdsa(weierstrass(brainpoolP384r1_CURVE), sha384);
|
|
118
|
+
|
|
119
|
+
const brainpoolP512r1_CURVE: WeierstrassOpts<bigint> = {
|
|
120
|
+
p: BigInt(
|
|
121
|
+
'0xaadd9db8dbe9c48b3fd4e6ae33c9fc07cb308db3b3c9d20ed6639cca703308717d4d9b009bc66842aecda12ae6a380e62881ff2f2d82c68528aa6056583a48f3'
|
|
122
|
+
),
|
|
123
|
+
a: BigInt(
|
|
124
|
+
'0x7830a3318b603b89e2327145ac234cc594cbdd8d3df91610a83441caea9863bc2ded5d5aa8253aa10a2ef1c98b9ac8b57f1117a72bf2c7b9e7c1ac4d77fc94ca'
|
|
125
|
+
),
|
|
126
|
+
b: BigInt(
|
|
127
|
+
'0x3df91610a83441caea9863bc2ded5d5aa8253aa10a2ef1c98b9ac8b57f1117a72bf2c7b9e7c1ac4d77fc94cadc083e67984050b75ebae5dd2809bd638016f723'
|
|
128
|
+
),
|
|
129
|
+
n: BigInt(
|
|
130
|
+
'0xaadd9db8dbe9c48b3fd4e6ae33c9fc07cb308db3b3c9d20ed6639cca70330870553e5c414ca92619418661197fac10471db1d381085ddaddb58796829ca90069'
|
|
131
|
+
),
|
|
132
|
+
Gx: BigInt(
|
|
133
|
+
'0x81aee4bdd82ed9645a21322e9c4c6a9385ed9f70b5d916c1b43b62eef4d0098eff3b1f78e2d0d48d50d1687b93b97d5f7c6d5047406a5e688b352209bcb9f822'
|
|
134
|
+
),
|
|
135
|
+
Gy: BigInt(
|
|
136
|
+
'0x7dde385d566332ecc0eabfa9cf7822fdf209f70024a57b1aa000c55b881f8111b2dcde494a5f485e5bca4bd88a2763aed1ca2b2fa8f0540678cd1e0f3ad80892'
|
|
137
|
+
),
|
|
122
138
|
h: BigInt(1),
|
|
123
|
-
|
|
124
|
-
|
|
139
|
+
};
|
|
140
|
+
/** Brainpool P521r1 with sha512, from RFC 5639. */
|
|
141
|
+
export const brainpoolP512r1: ECDSA = ecdsa(weierstrass(brainpoolP512r1_CURVE), sha512);
|