@noble/curves 1.9.5 → 2.0.0-beta.1
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 -421
- package/abstract/bls.d.ts +49 -111
- 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 +7 -48
- package/abstract/curve.d.ts.map +1 -1
- package/abstract/curve.js +22 -47
- package/abstract/curve.js.map +1 -1
- package/abstract/edwards.d.ts +17 -68
- package/abstract/edwards.d.ts.map +1 -1
- package/abstract/edwards.js +98 -175
- 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 +11 -24
- package/abstract/hash-to-curve.d.ts.map +1 -1
- package/abstract/hash-to-curve.js +30 -35
- 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 +166 -167
- package/abstract/modular.js.map +1 -1
- package/abstract/montgomery.d.ts +4 -9
- package/abstract/montgomery.d.ts.map +1 -1
- package/abstract/montgomery.js +17 -20
- 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.js +20 -24
- package/abstract/poseidon.js.map +1 -1
- package/abstract/tower.d.ts +9 -7
- package/abstract/tower.d.ts.map +1 -1
- package/abstract/tower.js +600 -364
- package/abstract/tower.js.map +1 -1
- package/abstract/weierstrass.d.ts +12 -145
- package/abstract/weierstrass.d.ts.map +1 -1
- package/abstract/weierstrass.js +153 -377
- package/abstract/weierstrass.js.map +1 -1
- package/bls12-381.d.ts +2 -2
- package/bls12-381.d.ts.map +1 -1
- package/bls12-381.js +174 -216
- package/bls12-381.js.map +1 -1
- package/bn254.d.ts +58 -10
- package/bn254.d.ts.map +1 -1
- package/bn254.js +70 -130
- package/bn254.js.map +1 -1
- package/ed25519.d.ts +12 -31
- package/ed25519.d.ts.map +1 -1
- package/ed25519.js +104 -146
- package/ed25519.js.map +1 -1
- package/ed448.d.ts +14 -33
- package/ed448.d.ts.map +1 -1
- package/ed448.js +105 -132
- package/ed448.js.map +1 -1
- package/index.js +1 -1
- package/misc.d.ts +10 -14
- package/misc.d.ts.map +1 -1
- package/misc.js +51 -60
- package/misc.js.map +1 -1
- package/nist.d.ts +11 -14
- package/nist.d.ts.map +1 -1
- package/nist.js +46 -55
- package/nist.js.map +1 -1
- package/package.json +9 -224
- package/secp256k1.d.ts +7 -23
- package/secp256k1.d.ts.map +1 -1
- package/secp256k1.js +72 -83
- package/secp256k1.js.map +1 -1
- package/src/abstract/bls.ts +197 -344
- package/src/abstract/curve.ts +10 -83
- package/src/abstract/edwards.ts +96 -223
- package/src/abstract/hash-to-curve.ts +32 -45
- package/src/abstract/modular.ts +144 -130
- package/src/abstract/montgomery.ts +21 -22
- package/src/abstract/oprf.ts +600 -0
- package/src/abstract/tower.ts +627 -382
- package/src/abstract/weierstrass.ts +101 -482
- package/src/bls12-381.ts +148 -176
- package/src/bn254.ts +67 -122
- package/src/ed25519.ts +65 -118
- package/src/ed448.ts +63 -113
- package/src/index.ts +1 -1
- package/src/misc.ts +66 -49
- package/src/nist.ts +48 -57
- package/src/secp256k1.ts +56 -88
- package/src/utils.ts +41 -61
- package/src/webcrypto.ts +362 -0
- package/utils.d.ts +28 -19
- package/utils.d.ts.map +1 -1
- package/utils.js +45 -121
- package/utils.js.map +1 -1
- package/webcrypto.d.ts +47 -0
- package/webcrypto.d.ts.map +1 -0
- package/webcrypto.js +231 -0
- package/webcrypto.js.map +1 -0
- 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 -237
- package/esm/abstract/edwards.d.ts.map +0 -1
- package/esm/abstract/edwards.js +0 -632
- 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 -93
- package/esm/abstract/tower.d.ts.map +0 -1
- package/esm/abstract/tower.js +0 -502
- package/esm/abstract/tower.js.map +0 -1
- package/esm/abstract/utils.d.ts +0 -5
- package/esm/abstract/utils.d.ts.map +0 -1
- package/esm/abstract/utils.js +0 -7
- package/esm/abstract/utils.js.map +0 -1
- package/esm/abstract/weierstrass.d.ts +0 -412
- package/esm/abstract/weierstrass.d.ts.map +0 -1
- package/esm/abstract/weierstrass.js +0 -1428
- 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 -738
- 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 -246
- 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 -101
- package/esm/ed448.d.ts.map +0 -1
- package/esm/ed448.js +0 -448
- 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 -292
- 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/src/_shortw_utils.ts +0 -21
- package/src/abstract/utils.ts +0 -7
- 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/ed25519.ts
CHANGED
|
@@ -7,14 +7,17 @@
|
|
|
7
7
|
*/
|
|
8
8
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
9
9
|
import { sha512 } from '@noble/hashes/sha2.js';
|
|
10
|
-
import { abytes, concatBytes,
|
|
11
|
-
import {
|
|
10
|
+
import { abytes, concatBytes, hexToBytes } from '@noble/hashes/utils.js';
|
|
11
|
+
import { type AffinePoint } from './abstract/curve.ts';
|
|
12
12
|
import {
|
|
13
|
+
eddsa,
|
|
14
|
+
edwards,
|
|
13
15
|
PrimeEdwardsPoint,
|
|
14
|
-
|
|
15
|
-
type
|
|
16
|
+
type EdDSA,
|
|
17
|
+
type EdDSAOpts,
|
|
16
18
|
type EdwardsOpts,
|
|
17
19
|
type EdwardsPoint,
|
|
20
|
+
type EdwardsPointCons,
|
|
18
21
|
} from './abstract/edwards.ts';
|
|
19
22
|
import {
|
|
20
23
|
_DST_scalar,
|
|
@@ -22,11 +25,9 @@ import {
|
|
|
22
25
|
expand_message_xmd,
|
|
23
26
|
type H2CHasher,
|
|
24
27
|
type H2CHasherBase,
|
|
25
|
-
type H2CMethod,
|
|
26
28
|
type htfBasicOpts,
|
|
27
29
|
} from './abstract/hash-to-curve.ts';
|
|
28
30
|
import {
|
|
29
|
-
Field,
|
|
30
31
|
FpInvertBatch,
|
|
31
32
|
FpSqrtEven,
|
|
32
33
|
isNegativeLE,
|
|
@@ -34,24 +35,23 @@ import {
|
|
|
34
35
|
pow2,
|
|
35
36
|
type IField,
|
|
36
37
|
} from './abstract/modular.ts';
|
|
37
|
-
import { montgomery, type MontgomeryECDH
|
|
38
|
-
import {
|
|
38
|
+
import { montgomery, type MontgomeryECDH } from './abstract/montgomery.ts';
|
|
39
|
+
import { createORPF, type OPRF } from './abstract/oprf.ts';
|
|
40
|
+
import { asciiToBytes, bytesToNumberLE, equalBytes } from './utils.ts';
|
|
39
41
|
|
|
40
42
|
// prettier-ignore
|
|
41
|
-
const _0n = BigInt(0), _1n = BigInt(1), _2n = BigInt(2), _3n = BigInt(3);
|
|
43
|
+
const _0n = /* @__PURE__ */ BigInt(0), _1n = BigInt(1), _2n = BigInt(2), _3n = BigInt(3);
|
|
42
44
|
// prettier-ignore
|
|
43
45
|
const _5n = BigInt(5), _8n = BigInt(8);
|
|
44
46
|
|
|
45
|
-
// 2n**255n-19n
|
|
47
|
+
// P = 2n**255n - 19n
|
|
46
48
|
const ed25519_CURVE_p = BigInt(
|
|
47
49
|
'0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed'
|
|
48
50
|
);
|
|
49
|
-
|
|
50
|
-
// P = 2n**255n - 19n
|
|
51
51
|
// N = 2n**252n + 27742317777372353535851937790883648493n
|
|
52
52
|
// a = Fp.create(BigInt(-1))
|
|
53
53
|
// d = -121665/121666 a.k.a. Fp.neg(121665 * Fp.inv(121666))
|
|
54
|
-
const ed25519_CURVE: EdwardsOpts = {
|
|
54
|
+
const ed25519_CURVE: EdwardsOpts = /* @__PURE__ */ (() => ({
|
|
55
55
|
p: ed25519_CURVE_p,
|
|
56
56
|
n: BigInt('0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed'),
|
|
57
57
|
h: _8n,
|
|
@@ -59,7 +59,7 @@ const ed25519_CURVE: EdwardsOpts = {
|
|
|
59
59
|
d: BigInt('0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3'),
|
|
60
60
|
Gx: BigInt('0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a'),
|
|
61
61
|
Gy: BigInt('0x6666666666666666666666666666666666666666666666666666666666666658'),
|
|
62
|
-
};
|
|
62
|
+
}))();
|
|
63
63
|
|
|
64
64
|
function ed25519_pow_2_252_3(x: bigint) {
|
|
65
65
|
// prettier-ignore
|
|
@@ -117,19 +117,24 @@ function uvRatio(u: bigint, v: bigint): { isValid: boolean; value: bigint } {
|
|
|
117
117
|
return { isValid: useRoot1 || useRoot2, value: x };
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
const
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
120
|
+
const ed25519_Point = /* @__PURE__ */ edwards(ed25519_CURVE, { uvRatio });
|
|
121
|
+
const Fp = /* @__PURE__ */ (() => ed25519_Point.Fp)();
|
|
122
|
+
const Fn = /* @__PURE__ */ (() => ed25519_Point.Fn)();
|
|
123
|
+
|
|
124
|
+
const ed25519_eddsa_opts = { adjustScalarBytes };
|
|
125
|
+
function ed25519_domain(data: Uint8Array, ctx: Uint8Array, phflag: boolean) {
|
|
126
|
+
if (ctx.length > 255) throw new Error('Context is too big');
|
|
127
|
+
return concatBytes(
|
|
128
|
+
asciiToBytes('SigEd25519 no Ed25519 collisions'),
|
|
129
|
+
new Uint8Array([phflag ? 1 : 0, ctx.length]),
|
|
130
|
+
ctx,
|
|
131
|
+
data
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function _ed(opts: EdDSAOpts) {
|
|
136
|
+
return eddsa(ed25519_Point, sha512, Object.assign({}, ed25519_eddsa_opts, opts));
|
|
137
|
+
}
|
|
133
138
|
|
|
134
139
|
/**
|
|
135
140
|
* ed25519 curve with EdDSA signatures.
|
|
@@ -141,33 +146,11 @@ const ed25519Defaults = /* @__PURE__ */ (() => ({
|
|
|
141
146
|
* ed25519.verify(sig, msg, pub); // Default mode: follows ZIP215
|
|
142
147
|
* ed25519.verify(sig, msg, pub, { zip215: false }); // RFC8032 / FIPS 186-5
|
|
143
148
|
*/
|
|
144
|
-
export const ed25519:
|
|
145
|
-
|
|
146
|
-
function ed25519_domain(data: Uint8Array, ctx: Uint8Array, phflag: boolean) {
|
|
147
|
-
if (ctx.length > 255) throw new Error('Context is too big');
|
|
148
|
-
return concatBytes(
|
|
149
|
-
utf8ToBytes('SigEd25519 no Ed25519 collisions'),
|
|
150
|
-
new Uint8Array([phflag ? 1 : 0, ctx.length]),
|
|
151
|
-
ctx,
|
|
152
|
-
data
|
|
153
|
-
);
|
|
154
|
-
}
|
|
155
|
-
|
|
149
|
+
export const ed25519: EdDSA = /* @__PURE__ */ _ed({});
|
|
156
150
|
/** Context of ed25519. Uses context for domain separation. */
|
|
157
|
-
export const ed25519ctx:
|
|
158
|
-
twistedEdwards({
|
|
159
|
-
...ed25519Defaults,
|
|
160
|
-
domain: ed25519_domain,
|
|
161
|
-
}))();
|
|
162
|
-
|
|
151
|
+
export const ed25519ctx: EdDSA = /* @__PURE__ */ _ed({ domain: ed25519_domain });
|
|
163
152
|
/** Prehashed version of ed25519. Accepts already-hashed messages in sign() and verify(). */
|
|
164
|
-
export const ed25519ph:
|
|
165
|
-
twistedEdwards(
|
|
166
|
-
Object.assign({}, ed25519Defaults, {
|
|
167
|
-
domain: ed25519_domain,
|
|
168
|
-
prehash: sha512,
|
|
169
|
-
})
|
|
170
|
-
))();
|
|
153
|
+
export const ed25519ph: EdDSA = /* @__PURE__ */ _ed({ domain: ed25519_domain, prehash: sha512 });
|
|
171
154
|
|
|
172
155
|
/**
|
|
173
156
|
* ECDH using curve25519 aka x25519.
|
|
@@ -179,8 +162,8 @@ export const ed25519ph: CurveFn = /* @__PURE__ */ (() =>
|
|
|
179
162
|
* x25519.getPublicKey(priv) === x25519.scalarMultBase(priv);
|
|
180
163
|
* x25519.getPublicKey(x25519.utils.randomSecretKey());
|
|
181
164
|
*/
|
|
182
|
-
export const x25519:
|
|
183
|
-
const P =
|
|
165
|
+
export const x25519: MontgomeryECDH = /* @__PURE__ */ (() => {
|
|
166
|
+
const P = ed25519_CURVE_p;
|
|
184
167
|
return montgomery({
|
|
185
168
|
P,
|
|
186
169
|
type: 'x25519',
|
|
@@ -196,14 +179,13 @@ export const x25519: XCurveFn = /* @__PURE__ */ (() => {
|
|
|
196
179
|
// Hash To Curve Elligator2 Map (NOTE: different from ristretto255 elligator)
|
|
197
180
|
// NOTE: very important part is usage of FpSqrtEven for ELL2_C1_EDWARDS, since
|
|
198
181
|
// SageMath returns different root first and everything falls apart
|
|
199
|
-
|
|
200
|
-
const ELL2_C1 = /* @__PURE__ */ (() => (Fp.ORDER + _3n) / _8n)(); // 1. c1 = (q + 3) / 8 # Integer arithmetic
|
|
182
|
+
const ELL2_C1 = /* @__PURE__ */ (() => (ed25519_CURVE_p + _3n) / _8n)(); // 1. c1 = (q + 3) / 8 # Integer arithmetic
|
|
201
183
|
const ELL2_C2 = /* @__PURE__ */ (() => Fp.pow(_2n, ELL2_C1))(); // 2. c2 = 2^c1
|
|
202
184
|
const ELL2_C3 = /* @__PURE__ */ (() => Fp.sqrt(Fp.neg(Fp.ONE)))(); // 3. c3 = sqrt(-1)
|
|
203
185
|
|
|
204
186
|
// prettier-ignore
|
|
205
187
|
function map_to_curve_elligator2_curve25519(u: bigint) {
|
|
206
|
-
const ELL2_C4 = (
|
|
188
|
+
const ELL2_C4 = (ed25519_CURVE_p - _5n) / _8n; // 4. c4 = (q - 5) / 8 # Integer arithmetic
|
|
207
189
|
const ELL2_J = BigInt(486662);
|
|
208
190
|
|
|
209
191
|
let tv1 = Fp.sqr(u); // 1. tv1 = u^2
|
|
@@ -267,14 +249,14 @@ function map_to_curve_elligator2_edwards25519(u: bigint) {
|
|
|
267
249
|
}
|
|
268
250
|
|
|
269
251
|
/** Hashing to ed25519 points / field. RFC 9380 methods. */
|
|
270
|
-
export const ed25519_hasher: H2CHasher<
|
|
252
|
+
export const ed25519_hasher: H2CHasher<EdwardsPointCons> = /* @__PURE__ */ (() =>
|
|
271
253
|
createHasher(
|
|
272
|
-
|
|
254
|
+
ed25519_Point,
|
|
273
255
|
(scalars: bigint[]) => map_to_curve_elligator2_edwards25519(scalars[0]),
|
|
274
256
|
{
|
|
275
257
|
DST: 'edwards25519_XMD:SHA-512_ELL2_RO_',
|
|
276
258
|
encodeDST: 'edwards25519_XMD:SHA-512_ELL2_NU_',
|
|
277
|
-
p:
|
|
259
|
+
p: ed25519_CURVE_p,
|
|
278
260
|
m: 1,
|
|
279
261
|
k: 128,
|
|
280
262
|
expand: 'xmd',
|
|
@@ -306,8 +288,7 @@ const invertSqrt = (number: bigint) => uvRatio(_1n, number);
|
|
|
306
288
|
const MAX_255B = /* @__PURE__ */ BigInt(
|
|
307
289
|
'0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
|
|
308
290
|
);
|
|
309
|
-
const bytes255ToNumberLE = (bytes: Uint8Array) =>
|
|
310
|
-
ed25519.Point.Fp.create(bytesToNumberLE(bytes) & MAX_255B);
|
|
291
|
+
const bytes255ToNumberLE = (bytes: Uint8Array) => Fp.create(bytesToNumberLE(bytes) & MAX_255B);
|
|
311
292
|
|
|
312
293
|
type ExtendedPoint = EdwardsPoint;
|
|
313
294
|
|
|
@@ -318,7 +299,7 @@ type ExtendedPoint = EdwardsPoint;
|
|
|
318
299
|
*/
|
|
319
300
|
function calcElligatorRistrettoMap(r0: bigint): ExtendedPoint {
|
|
320
301
|
const { d } = ed25519_CURVE;
|
|
321
|
-
const P =
|
|
302
|
+
const P = ed25519_CURVE_p;
|
|
322
303
|
const mod = (n: bigint) => Fp.create(n);
|
|
323
304
|
const r = mod(SQRT_M1 * r0 * r0); // 1
|
|
324
305
|
const Ns = mod((r + _1n) * ONE_MINUS_D_SQ); // 2
|
|
@@ -335,7 +316,7 @@ function calcElligatorRistrettoMap(r0: bigint): ExtendedPoint {
|
|
|
335
316
|
const W1 = mod(Nt * SQRT_AD_MINUS_ONE); // 11
|
|
336
317
|
const W2 = mod(_1n - s2); // 12
|
|
337
318
|
const W3 = mod(_1n + s2); // 13
|
|
338
|
-
return new
|
|
319
|
+
return new ed25519_Point(mod(W0 * W3), mod(W2 * W1), mod(W1 * W3), mod(W0 * W2));
|
|
339
320
|
}
|
|
340
321
|
|
|
341
322
|
function ristretto255_map(bytes: Uint8Array): _RistrettoPoint {
|
|
@@ -361,10 +342,10 @@ class _RistrettoPoint extends PrimeEdwardsPoint<_RistrettoPoint> {
|
|
|
361
342
|
// because typescript strips comments, which makes bundlers disable tree-shaking.
|
|
362
343
|
// prettier-ignore
|
|
363
344
|
static BASE: _RistrettoPoint =
|
|
364
|
-
/* @__PURE__ */ (() => new _RistrettoPoint(
|
|
345
|
+
/* @__PURE__ */ (() => new _RistrettoPoint(ed25519_Point.BASE))();
|
|
365
346
|
// prettier-ignore
|
|
366
347
|
static ZERO: _RistrettoPoint =
|
|
367
|
-
/* @__PURE__ */ (() => new _RistrettoPoint(
|
|
348
|
+
/* @__PURE__ */ (() => new _RistrettoPoint(ed25519_Point.ZERO))();
|
|
368
349
|
// prettier-ignore
|
|
369
350
|
static Fp: IField<bigint> =
|
|
370
351
|
/* @__PURE__ */ (() => Fp)();
|
|
@@ -377,7 +358,7 @@ class _RistrettoPoint extends PrimeEdwardsPoint<_RistrettoPoint> {
|
|
|
377
358
|
}
|
|
378
359
|
|
|
379
360
|
static fromAffine(ap: AffinePoint<bigint>): _RistrettoPoint {
|
|
380
|
-
return new _RistrettoPoint(
|
|
361
|
+
return new _RistrettoPoint(ed25519_Point.fromAffine(ap));
|
|
381
362
|
}
|
|
382
363
|
|
|
383
364
|
protected assertSame(other: _RistrettoPoint): void {
|
|
@@ -388,11 +369,6 @@ class _RistrettoPoint extends PrimeEdwardsPoint<_RistrettoPoint> {
|
|
|
388
369
|
return new _RistrettoPoint(ep);
|
|
389
370
|
}
|
|
390
371
|
|
|
391
|
-
/** @deprecated use `import { ristretto255_hasher } from '@noble/curves/ed25519.js';` */
|
|
392
|
-
static hashToCurve(hex: Hex): _RistrettoPoint {
|
|
393
|
-
return ristretto255_map(ensureBytes('ristrettoHash', hex, 64));
|
|
394
|
-
}
|
|
395
|
-
|
|
396
372
|
static fromBytes(bytes: Uint8Array): _RistrettoPoint {
|
|
397
373
|
abytes(bytes, 32);
|
|
398
374
|
const { a, d } = ed25519_CURVE;
|
|
@@ -401,7 +377,7 @@ class _RistrettoPoint extends PrimeEdwardsPoint<_RistrettoPoint> {
|
|
|
401
377
|
const s = bytes255ToNumberLE(bytes);
|
|
402
378
|
// 1. Check that s_bytes is the canonical encoding of a field element, or else abort.
|
|
403
379
|
// 3. Check that s is non-negative, or else abort
|
|
404
|
-
if (!equalBytes(
|
|
380
|
+
if (!equalBytes(Fp.toBytes(s), bytes) || isNegativeLE(s, P))
|
|
405
381
|
throw new Error('invalid ristretto255 encoding 1');
|
|
406
382
|
const s2 = mod(s * s);
|
|
407
383
|
const u1 = mod(_1n + a * s2); // 4 (a is -1)
|
|
@@ -418,7 +394,7 @@ class _RistrettoPoint extends PrimeEdwardsPoint<_RistrettoPoint> {
|
|
|
418
394
|
const t = mod(x * y); // 12
|
|
419
395
|
if (!isValid || isNegativeLE(t, P) || y === _0n)
|
|
420
396
|
throw new Error('invalid ristretto255 encoding 2');
|
|
421
|
-
return new _RistrettoPoint(new
|
|
397
|
+
return new _RistrettoPoint(new ed25519_Point(x, y, _1n, t));
|
|
422
398
|
}
|
|
423
399
|
|
|
424
400
|
/**
|
|
@@ -426,12 +402,8 @@ class _RistrettoPoint extends PrimeEdwardsPoint<_RistrettoPoint> {
|
|
|
426
402
|
* Described in [RFC9496](https://www.rfc-editor.org/rfc/rfc9496#name-decode).
|
|
427
403
|
* @param hex Ristretto-encoded 32 bytes. Not every 32-byte string is valid ristretto encoding
|
|
428
404
|
*/
|
|
429
|
-
static fromHex(hex:
|
|
430
|
-
return _RistrettoPoint.fromBytes(
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
static msm(points: _RistrettoPoint[], scalars: bigint[]): _RistrettoPoint {
|
|
434
|
-
return pippenger(_RistrettoPoint, ed25519.Point.Fn, points, scalars);
|
|
405
|
+
static fromHex(hex: string): _RistrettoPoint {
|
|
406
|
+
return _RistrettoPoint.fromBytes(hexToBytes(hex));
|
|
435
407
|
}
|
|
436
408
|
|
|
437
409
|
/**
|
|
@@ -463,7 +435,7 @@ class _RistrettoPoint extends PrimeEdwardsPoint<_RistrettoPoint> {
|
|
|
463
435
|
if (isNegativeLE(X * zInv, P)) Y = mod(-Y); // 9
|
|
464
436
|
let s = mod((Z - Y) * D); // 10 (check footer's note, no sqrt(-a))
|
|
465
437
|
if (isNegativeLE(s, P)) s = mod(-s);
|
|
466
|
-
return
|
|
438
|
+
return Fp.toBytes(s); // 11
|
|
467
439
|
}
|
|
468
440
|
|
|
469
441
|
/**
|
|
@@ -491,24 +463,26 @@ export const ristretto255: {
|
|
|
491
463
|
} = { Point: _RistrettoPoint };
|
|
492
464
|
|
|
493
465
|
/** Hashing to ristretto255 points / field. RFC 9380 methods. */
|
|
494
|
-
export const ristretto255_hasher: H2CHasherBase<
|
|
466
|
+
export const ristretto255_hasher: H2CHasherBase<_RistrettoPoint> = {
|
|
495
467
|
hashToCurve(msg: Uint8Array, options?: htfBasicOpts): _RistrettoPoint {
|
|
496
468
|
const DST = options?.DST || 'ristretto255_XMD:SHA-512_R255MAP_RO_';
|
|
497
|
-
|
|
469
|
+
const xmd = expand_message_xmd(msg, DST, 64, sha512);
|
|
470
|
+
return ristretto255_map(xmd);
|
|
498
471
|
},
|
|
499
472
|
hashToScalar(msg: Uint8Array, options: htfBasicOpts = { DST: _DST_scalar }) {
|
|
500
473
|
const xmd = expand_message_xmd(msg, options.DST, 64, sha512);
|
|
501
|
-
return
|
|
474
|
+
return Fn.create(bytesToNumberLE(xmd));
|
|
502
475
|
},
|
|
503
476
|
};
|
|
504
477
|
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
478
|
+
export const ristretto255_oprf: OPRF = /* @__PURE__ */ (() =>
|
|
479
|
+
createORPF({
|
|
480
|
+
name: 'ristretto255-SHA512',
|
|
481
|
+
Point: _RistrettoPoint,
|
|
482
|
+
hash: sha512,
|
|
483
|
+
hashToGroup: ristretto255_hasher.hashToCurve,
|
|
484
|
+
hashToScalar: ristretto255_hasher.hashToScalar,
|
|
485
|
+
}))();
|
|
512
486
|
|
|
513
487
|
/**
|
|
514
488
|
* Weird / bogus points, useful for debugging.
|
|
@@ -526,30 +500,3 @@ export const ED25519_TORSION_SUBGROUP: string[] = [
|
|
|
526
500
|
'0000000000000000000000000000000000000000000000000000000000000000',
|
|
527
501
|
'c7176a703d4dd84fba3c0b760d10670f2a2053fa2c39ccc64ec7fd7792ac03fa',
|
|
528
502
|
];
|
|
529
|
-
|
|
530
|
-
/** @deprecated use `ed25519.utils.toMontgomery` */
|
|
531
|
-
export function edwardsToMontgomeryPub(edwardsPub: Hex): Uint8Array {
|
|
532
|
-
return ed25519.utils.toMontgomery(ensureBytes('pub', edwardsPub));
|
|
533
|
-
}
|
|
534
|
-
/** @deprecated use `ed25519.utils.toMontgomery` */
|
|
535
|
-
export const edwardsToMontgomery: typeof edwardsToMontgomeryPub = edwardsToMontgomeryPub;
|
|
536
|
-
|
|
537
|
-
/** @deprecated use `ed25519.utils.toMontgomeryPriv` */
|
|
538
|
-
export function edwardsToMontgomeryPriv(edwardsPriv: Uint8Array): Uint8Array {
|
|
539
|
-
return ed25519.utils.toMontgomeryPriv(ensureBytes('pub', edwardsPriv));
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
/** @deprecated use `ristretto255.Point` */
|
|
543
|
-
export const RistrettoPoint: typeof _RistrettoPoint = _RistrettoPoint;
|
|
544
|
-
/** @deprecated use `import { ed25519_hasher } from '@noble/curves/ed25519.js';` */
|
|
545
|
-
export const hashToCurve: H2CMethod<bigint> = /* @__PURE__ */ (() => ed25519_hasher.hashToCurve)();
|
|
546
|
-
/** @deprecated use `import { ed25519_hasher } from '@noble/curves/ed25519.js';` */
|
|
547
|
-
export const encodeToCurve: H2CMethod<bigint> = /* @__PURE__ */ (() =>
|
|
548
|
-
ed25519_hasher.encodeToCurve)();
|
|
549
|
-
type RistHasher = (msg: Uint8Array, options: htfBasicOpts) => _RistrettoPoint;
|
|
550
|
-
/** @deprecated use `import { ristretto255_hasher } from '@noble/curves/ed25519.js';` */
|
|
551
|
-
export const hashToRistretto255: RistHasher = /* @__PURE__ */ (() =>
|
|
552
|
-
ristretto255_hasher.hashToCurve as RistHasher)();
|
|
553
|
-
/** @deprecated use `import { ristretto255_hasher } from '@noble/curves/ed25519.js';` */
|
|
554
|
-
export const hash_to_ristretto255: RistHasher = /* @__PURE__ */ (() =>
|
|
555
|
-
ristretto255_hasher.hashToCurve as RistHasher)();
|