@noble/curves 1.8.1 → 1.8.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 +278 -418
- 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 +14 -15
- package/abstract/bls.js.map +1 -1
- package/abstract/curve.d.ts +10 -2
- 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 +55 -69
- package/abstract/edwards.js.map +1 -1
- package/abstract/hash-to-curve.d.ts +5 -4
- package/abstract/hash-to-curve.d.ts.map +1 -1
- package/abstract/hash-to-curve.js +20 -18
- package/abstract/hash-to-curve.js.map +1 -1
- package/abstract/modular.d.ts.map +1 -1
- package/abstract/modular.js +9 -9
- package/abstract/montgomery.js +12 -12
- package/abstract/poseidon.d.ts +1 -1
- package/abstract/poseidon.js +3 -3
- package/abstract/tower.d.ts +2 -2
- package/abstract/tower.js +13 -13
- package/abstract/utils.d.ts +4 -2
- package/abstract/utils.d.ts.map +1 -1
- package/abstract/utils.js +25 -14
- package/abstract/utils.js.map +1 -1
- package/abstract/weierstrass.d.ts +17 -4
- package/abstract/weierstrass.d.ts.map +1 -1
- package/abstract/weierstrass.js +97 -80
- 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 +2 -2
- package/bn254.js +29 -29
- package/bn254.js.map +1 -1
- package/ed25519.d.ts +8 -6
- package/ed25519.d.ts.map +1 -1
- package/ed25519.js +65 -66
- package/ed25519.js.map +1 -1
- package/ed448.d.ts +6 -6
- package/ed448.d.ts.map +1 -1
- package/ed448.js +50 -52
- 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 +5 -6
- package/esm/abstract/bls.js.map +1 -1
- package/esm/abstract/curve.d.ts +10 -2
- 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 +36 -50
- package/esm/abstract/edwards.js.map +1 -1
- package/esm/abstract/hash-to-curve.d.ts +5 -4
- package/esm/abstract/hash-to-curve.d.ts.map +1 -1
- package/esm/abstract/hash-to-curve.js +4 -2
- package/esm/abstract/hash-to-curve.js.map +1 -1
- package/esm/abstract/modular.d.ts.map +1 -1
- package/esm/abstract/modular.js +1 -1
- package/esm/abstract/montgomery.js +2 -2
- package/esm/abstract/poseidon.d.ts +1 -1
- package/esm/abstract/poseidon.js +1 -1
- package/esm/abstract/tower.d.ts +2 -2
- package/esm/abstract/tower.js +5 -5
- package/esm/abstract/utils.d.ts +4 -2
- package/esm/abstract/utils.d.ts.map +1 -1
- package/esm/abstract/utils.js +24 -13
- package/esm/abstract/utils.js.map +1 -1
- package/esm/abstract/weierstrass.d.ts +17 -4
- package/esm/abstract/weierstrass.d.ts.map +1 -1
- package/esm/abstract/weierstrass.js +70 -53
- 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 +2 -2
- package/esm/bn254.js +7 -7
- package/esm/bn254.js.map +1 -1
- package/esm/ed25519.d.ts +8 -6
- package/esm/ed25519.d.ts.map +1 -1
- package/esm/ed25519.js +20 -21
- package/esm/ed25519.js.map +1 -1
- package/esm/ed448.d.ts +6 -6
- package/esm/ed448.d.ts.map +1 -1
- package/esm/ed448.js +13 -15
- package/esm/ed448.js.map +1 -1
- package/esm/jubjub.d.ts +1 -4
- package/esm/jubjub.d.ts.map +1 -1
- package/esm/jubjub.js +1 -60
- package/esm/jubjub.js.map +1 -1
- package/esm/misc.d.ts +15 -0
- package/esm/misc.d.ts.map +1 -0
- package/esm/misc.js +101 -0
- package/esm/misc.js.map +1 -0
- package/esm/p256.d.ts +8 -5
- package/esm/p256.d.ts.map +1 -1
- package/esm/p256.js +13 -12
- package/esm/p256.js.map +1 -1
- package/esm/p384.d.ts +8 -5
- package/esm/p384.d.ts.map +1 -1
- package/esm/p384.js +14 -15
- package/esm/p384.js.map +1 -1
- package/esm/p521.d.ts +6 -5
- package/esm/p521.d.ts.map +1 -1
- package/esm/p521.js +19 -28
- package/esm/p521.js.map +1 -1
- package/esm/pasta.d.ts +1 -7
- package/esm/pasta.d.ts.map +1 -1
- package/esm/pasta.js +1 -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 +18 -14
- package/esm/secp256k1.js.map +1 -1
- package/jubjub.d.ts +1 -4
- package/jubjub.d.ts.map +1 -1
- package/jubjub.js +5 -63
- package/jubjub.js.map +1 -1
- package/misc.d.ts +15 -0
- package/misc.d.ts.map +1 -0
- package/misc.js +106 -0
- package/misc.js.map +1 -0
- package/p256.d.ts +8 -5
- package/p256.d.ts.map +1 -1
- package/p256.js +19 -18
- package/p256.js.map +1 -1
- package/p384.d.ts +8 -5
- package/p384.d.ts.map +1 -1
- package/p384.js +19 -20
- package/p384.js.map +1 -1
- package/p521.d.ts +6 -5
- package/p521.d.ts.map +1 -1
- package/p521.js +23 -32
- package/p521.js.map +1 -1
- package/package.json +14 -10
- package/pasta.d.ts +1 -7
- package/pasta.d.ts.map +1 -1
- package/pasta.js +4 -34
- package/pasta.js.map +1 -1
- package/secp256k1.d.ts +15 -10
- package/secp256k1.d.ts.map +1 -1
- package/secp256k1.js +57 -53
- package/secp256k1.js.map +1 -1
- package/src/_shortw_utils.ts +2 -2
- package/src/abstract/bls.ts +9 -9
- package/src/abstract/curve.ts +88 -79
- package/src/abstract/edwards.ts +47 -54
- package/src/abstract/hash-to-curve.ts +7 -5
- package/src/abstract/modular.ts +1 -1
- package/src/abstract/montgomery.ts +2 -2
- package/src/abstract/poseidon.ts +1 -1
- package/src/abstract/tower.ts +6 -6
- package/src/abstract/utils.ts +26 -15
- package/src/abstract/weierstrass.ts +89 -75
- package/src/bls12-381.ts +10 -10
- package/src/bn254.ts +8 -8
- package/src/ed25519.ts +24 -22
- package/src/ed448.ts +18 -17
- package/src/jubjub.ts +5 -63
- package/src/misc.ts +117 -0
- package/src/p256.ts +13 -12
- package/src/p384.ts +18 -15
- package/src/p521.ts +27 -32
- package/src/pasta.ts +1 -39
- package/src/secp256k1.ts +19 -15
package/src/ed448.ts
CHANGED
|
@@ -9,17 +9,17 @@
|
|
|
9
9
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
10
10
|
import { shake256 } from '@noble/hashes/sha3';
|
|
11
11
|
import { concatBytes, randomBytes, utf8ToBytes, wrapConstructor } from '@noble/hashes/utils';
|
|
12
|
-
import type { AffinePoint, Group } from './abstract/curve.
|
|
13
|
-
import { pippenger } from './abstract/curve.
|
|
14
|
-
import { type CurveFn, type ExtPointType, twistedEdwards } from './abstract/edwards.
|
|
12
|
+
import type { AffinePoint, Group } from './abstract/curve.ts';
|
|
13
|
+
import { pippenger } from './abstract/curve.ts';
|
|
14
|
+
import { type CurveFn, type ExtPointType, twistedEdwards } from './abstract/edwards.ts';
|
|
15
15
|
import {
|
|
16
16
|
createHasher,
|
|
17
17
|
expand_message_xof,
|
|
18
18
|
type htfBasicOpts,
|
|
19
19
|
type HTFMethod,
|
|
20
|
-
} from './abstract/hash-to-curve.
|
|
21
|
-
import { Field, isNegativeLE, mod, pow2 } from './abstract/modular.
|
|
22
|
-
import { montgomery, type CurveFn as XCurveFn } from './abstract/montgomery.
|
|
20
|
+
} from './abstract/hash-to-curve.ts';
|
|
21
|
+
import { Field, isNegativeLE, mod, pow2 } from './abstract/modular.ts';
|
|
22
|
+
import { montgomery, type CurveFn as XCurveFn } from './abstract/montgomery.ts';
|
|
23
23
|
import {
|
|
24
24
|
bytesToHex,
|
|
25
25
|
bytesToNumberLE,
|
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
equalBytes,
|
|
28
28
|
type Hex,
|
|
29
29
|
numberToBytesLE,
|
|
30
|
-
} from './abstract/utils.
|
|
30
|
+
} from './abstract/utils.ts';
|
|
31
31
|
|
|
32
32
|
const shake256_114 = wrapConstructor(() => shake256.create({ dkLen: 114 }));
|
|
33
33
|
const shake256_64 = wrapConstructor(() => shake256.create({ dkLen: 64 }));
|
|
@@ -98,22 +98,20 @@ const Fp = Field(ed448P, 456, true);
|
|
|
98
98
|
const ED448_DEF = {
|
|
99
99
|
// Param: a
|
|
100
100
|
a: BigInt(1),
|
|
101
|
-
// -39081.
|
|
101
|
+
// -39081 a.k.a. Fp.neg(39081)
|
|
102
102
|
d: BigInt(
|
|
103
103
|
'726838724295606890549323807888004534353641360687318060281490199180612328166730772686396383698676545930088884461843637361053498018326358'
|
|
104
104
|
),
|
|
105
|
-
// Finite field
|
|
105
|
+
// Finite field 2n**448n - 2n**224n - 1n
|
|
106
106
|
Fp,
|
|
107
|
-
// Subgroup order
|
|
107
|
+
// Subgroup order
|
|
108
108
|
// 2n**446n - 13818066809895115352007386748515426880336692474882178609894547503885n
|
|
109
109
|
n: BigInt(
|
|
110
110
|
'181709681073901722637330951972001133588410340171829515070372549795146003961539585716195755291692375963310293709091662304773755859649779'
|
|
111
111
|
),
|
|
112
112
|
// RFC 7748 has 56-byte keys, RFC 8032 has 57-byte keys
|
|
113
113
|
nBitLength: 456,
|
|
114
|
-
// Cofactor
|
|
115
114
|
h: BigInt(4),
|
|
116
|
-
// Base point (x, y) aka generator point
|
|
117
115
|
Gx: BigInt(
|
|
118
116
|
'224580040295924300187604334099896036246789641632564134246125461686950415467406032909029192869357953282578032075146446173674602635247710'
|
|
119
117
|
),
|
|
@@ -286,7 +284,7 @@ const htf = /* @__PURE__ */ (() =>
|
|
|
286
284
|
export const hashToCurve: HTFMethod<bigint> = /* @__PURE__ */ (() => htf.hashToCurve)();
|
|
287
285
|
export const encodeToCurve: HTFMethod<bigint> = /* @__PURE__ */ (() => htf.encodeToCurve)();
|
|
288
286
|
|
|
289
|
-
function
|
|
287
|
+
function adecafp(other: unknown) {
|
|
290
288
|
if (!(other instanceof DcfPoint)) throw new Error('DecafPoint expected');
|
|
291
289
|
}
|
|
292
290
|
|
|
@@ -354,9 +352,12 @@ function calcElligatorDecafMap(r0: bigint): ExtendedPoint {
|
|
|
354
352
|
class DcfPoint implements Group<DcfPoint> {
|
|
355
353
|
static BASE: DcfPoint;
|
|
356
354
|
static ZERO: DcfPoint;
|
|
355
|
+
private readonly ep: ExtendedPoint;
|
|
357
356
|
// Private property to discourage combining ExtendedPoint + DecafPoint
|
|
358
357
|
// Always use Decaf encoding/decoding instead.
|
|
359
|
-
constructor(
|
|
358
|
+
constructor(ep: ExtendedPoint) {
|
|
359
|
+
this.ep = ep;
|
|
360
|
+
}
|
|
360
361
|
|
|
361
362
|
static fromAffine(ap: AffinePoint<bigint>): DcfPoint {
|
|
362
363
|
return new DcfPoint(ed448.ExtendedPoint.fromAffine(ap));
|
|
@@ -453,7 +454,7 @@ class DcfPoint implements Group<DcfPoint> {
|
|
|
453
454
|
// Compare one point to another.
|
|
454
455
|
// https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-ristretto255-decaf448-07#name-equals-2
|
|
455
456
|
equals(other: DcfPoint): boolean {
|
|
456
|
-
|
|
457
|
+
adecafp(other);
|
|
457
458
|
const { ex: X1, ey: Y1 } = this.ep;
|
|
458
459
|
const { ex: X2, ey: Y2 } = other.ep;
|
|
459
460
|
const mod = ed448.CURVE.Fp.create;
|
|
@@ -462,12 +463,12 @@ class DcfPoint implements Group<DcfPoint> {
|
|
|
462
463
|
}
|
|
463
464
|
|
|
464
465
|
add(other: DcfPoint): DcfPoint {
|
|
465
|
-
|
|
466
|
+
adecafp(other);
|
|
466
467
|
return new DcfPoint(this.ep.add(other.ep));
|
|
467
468
|
}
|
|
468
469
|
|
|
469
470
|
subtract(other: DcfPoint): DcfPoint {
|
|
470
|
-
|
|
471
|
+
adecafp(other);
|
|
471
472
|
return new DcfPoint(this.ep.subtract(other.ep));
|
|
472
473
|
}
|
|
473
474
|
|
package/src/jubjub.ts
CHANGED
|
@@ -1,63 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*/
|
|
7
|
-
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
8
|
-
import { blake2s } from '@noble/hashes/blake2s';
|
|
9
|
-
import { sha512 } from '@noble/hashes/sha512';
|
|
10
|
-
import { concatBytes, randomBytes, utf8ToBytes } from '@noble/hashes/utils';
|
|
11
|
-
import { type CurveFn, type ExtPointType, twistedEdwards } from './abstract/edwards.js';
|
|
12
|
-
import { Field } from './abstract/modular.js';
|
|
13
|
-
|
|
14
|
-
export const jubjub: CurveFn = /* @__PURE__ */ twistedEdwards({
|
|
15
|
-
// Params: a, d
|
|
16
|
-
a: BigInt('0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000000'),
|
|
17
|
-
d: BigInt('0x2a9318e74bfa2b48f5fd9207e6bd7fd4292d7f6d37579d2601065fd6d6343eb1'),
|
|
18
|
-
// Finite field 𝔽p over which we'll do calculations
|
|
19
|
-
// Same value as bls12-381 Fr (not Fp)
|
|
20
|
-
Fp: Field(BigInt('0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001')),
|
|
21
|
-
// Subgroup order: how many points curve has
|
|
22
|
-
n: BigInt('0xe7db4ea6533afa906673b0101343b00a6682093ccc81082d0970e5ed6f72cb7'),
|
|
23
|
-
// Cofactor
|
|
24
|
-
h: BigInt(8),
|
|
25
|
-
// Base point (x, y) aka generator point
|
|
26
|
-
Gx: BigInt('0x11dafe5d23e1218086a365b99fbf3d3be72f6afd7d1f72623e6b071492d1122b'),
|
|
27
|
-
Gy: BigInt('0x1d523cf1ddab1a1793132e78c866c0c33e26ba5cc220fed7cc3f870e59d292aa'),
|
|
28
|
-
hash: sha512,
|
|
29
|
-
randomBytes,
|
|
30
|
-
} as const);
|
|
31
|
-
|
|
32
|
-
const GH_FIRST_BLOCK = utf8ToBytes(
|
|
33
|
-
'096b36a5804bfacef1691e173c366a47ff5ba84a44f26ddd7e8d9f79d5b42df0'
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
// Returns point at JubJub curve which is prime order and not zero
|
|
37
|
-
export function groupHash(tag: Uint8Array, personalization: Uint8Array): ExtPointType {
|
|
38
|
-
const h = blake2s.create({ personalization, dkLen: 32 });
|
|
39
|
-
h.update(GH_FIRST_BLOCK);
|
|
40
|
-
h.update(tag);
|
|
41
|
-
// NOTE: returns ExtendedPoint, in case it will be multiplied later
|
|
42
|
-
let p = jubjub.ExtendedPoint.fromHex(h.digest());
|
|
43
|
-
// NOTE: cannot replace with isSmallOrder, returns Point*8
|
|
44
|
-
p = p.multiply(jubjub.CURVE.h);
|
|
45
|
-
if (p.equals(jubjub.ExtendedPoint.ZERO)) throw new Error('Point has small order');
|
|
46
|
-
return p;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// No secret data is leaked here at all.
|
|
50
|
-
// It operates over public data:
|
|
51
|
-
// const G_SPEND = jubjub.findGroupHash(new Uint8Array(), utf8ToBytes('Item_G_'));
|
|
52
|
-
export function findGroupHash(m: Uint8Array, personalization: Uint8Array): ExtPointType {
|
|
53
|
-
const tag = concatBytes(m, new Uint8Array([0]));
|
|
54
|
-
const hashes = [];
|
|
55
|
-
for (let i = 0; i < 256; i++) {
|
|
56
|
-
tag[tag.length - 1] = i;
|
|
57
|
-
try {
|
|
58
|
-
hashes.push(groupHash(tag, personalization));
|
|
59
|
-
} catch (e) {}
|
|
60
|
-
}
|
|
61
|
-
if (!hashes.length) throw new Error('findGroupHash tag overflow');
|
|
62
|
-
return hashes[0];
|
|
63
|
-
}
|
|
1
|
+
export {
|
|
2
|
+
jubjub_findGroupHash as findGroupHash,
|
|
3
|
+
jubjub_groupHash as groupHash,
|
|
4
|
+
jubjub,
|
|
5
|
+
} from './misc.ts';
|
package/src/misc.ts
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Miscellaneous, rarely used curves.
|
|
3
|
+
* jubjub, babyjubjub, pallas, vesta.
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
7
|
+
import { blake256 } from '@noble/hashes/blake1';
|
|
8
|
+
import { blake2s } from '@noble/hashes/blake2s';
|
|
9
|
+
import { sha256, sha512 } from '@noble/hashes/sha2';
|
|
10
|
+
import { concatBytes, randomBytes, utf8ToBytes } from '@noble/hashes/utils';
|
|
11
|
+
import { getHash } from './_shortw_utils.ts';
|
|
12
|
+
import { type CurveFn, type ExtPointType, twistedEdwards } from './abstract/edwards.ts';
|
|
13
|
+
import { Field, mod } from './abstract/modular.ts';
|
|
14
|
+
import { type CurveFn as WCurveFn, weierstrass } from './abstract/weierstrass.ts';
|
|
15
|
+
|
|
16
|
+
// Jubjub curves have 𝔽p over scalar fields of other curves. They are friendly to ZK proofs.
|
|
17
|
+
// jubjub Fp = bls n. babyjubjub Fp = bn254 n.
|
|
18
|
+
// verify manually, check bls12-381.ts and bn254.ts.
|
|
19
|
+
// https://neuromancer.sk/std/other/JubJub
|
|
20
|
+
|
|
21
|
+
const bls12_381_Fr = Field(
|
|
22
|
+
BigInt('0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001')
|
|
23
|
+
);
|
|
24
|
+
const bn254_Fr = Field(
|
|
25
|
+
BigInt('21888242871839275222246405745257275088548364400416034343698204186575808495617')
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
/** Curve over scalar field of bls12-381. jubjub Fp = bls n */
|
|
29
|
+
export const jubjub: CurveFn = /* @__PURE__ */ twistedEdwards({
|
|
30
|
+
a: BigInt('0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000000'),
|
|
31
|
+
d: BigInt('0x2a9318e74bfa2b48f5fd9207e6bd7fd4292d7f6d37579d2601065fd6d6343eb1'),
|
|
32
|
+
Fp: bls12_381_Fr,
|
|
33
|
+
n: BigInt('0xe7db4ea6533afa906673b0101343b00a6682093ccc81082d0970e5ed6f72cb7'),
|
|
34
|
+
h: BigInt(8),
|
|
35
|
+
Gx: BigInt('0x11dafe5d23e1218086a365b99fbf3d3be72f6afd7d1f72623e6b071492d1122b'),
|
|
36
|
+
Gy: BigInt('0x1d523cf1ddab1a1793132e78c866c0c33e26ba5cc220fed7cc3f870e59d292aa'),
|
|
37
|
+
hash: sha512,
|
|
38
|
+
randomBytes,
|
|
39
|
+
} as const);
|
|
40
|
+
|
|
41
|
+
/** Curve over scalar field of bn254. babyjubjub Fp = bn254 n */
|
|
42
|
+
export const babyjubjub: CurveFn = /* @__PURE__ */ twistedEdwards({
|
|
43
|
+
a: BigInt(168700),
|
|
44
|
+
d: BigInt(168696),
|
|
45
|
+
Fp: bn254_Fr,
|
|
46
|
+
n: BigInt('21888242871839275222246405745257275088614511777268538073601725287587578984328'),
|
|
47
|
+
h: BigInt(8),
|
|
48
|
+
Gx: BigInt('995203441582195749578291179787384436505546430278305826713579947235728471134'),
|
|
49
|
+
Gy: BigInt('5472060717959818805561601436314318772137091100104008585924551046643952123905'),
|
|
50
|
+
hash: blake256,
|
|
51
|
+
randomBytes,
|
|
52
|
+
} as const);
|
|
53
|
+
|
|
54
|
+
const jubjub_gh_first_block = utf8ToBytes(
|
|
55
|
+
'096b36a5804bfacef1691e173c366a47ff5ba84a44f26ddd7e8d9f79d5b42df0'
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
// Returns point at JubJub curve which is prime order and not zero
|
|
59
|
+
export function jubjub_groupHash(tag: Uint8Array, personalization: Uint8Array): ExtPointType {
|
|
60
|
+
const h = blake2s.create({ personalization, dkLen: 32 });
|
|
61
|
+
h.update(jubjub_gh_first_block);
|
|
62
|
+
h.update(tag);
|
|
63
|
+
// NOTE: returns ExtendedPoint, in case it will be multiplied later
|
|
64
|
+
let p = jubjub.ExtendedPoint.fromHex(h.digest());
|
|
65
|
+
// NOTE: cannot replace with isSmallOrder, returns Point*8
|
|
66
|
+
p = p.multiply(jubjub.CURVE.h);
|
|
67
|
+
if (p.equals(jubjub.ExtendedPoint.ZERO)) throw new Error('Point has small order');
|
|
68
|
+
return p;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// No secret data is leaked here at all.
|
|
72
|
+
// It operates over public data:
|
|
73
|
+
// const G_SPEND = jubjub.findGroupHash(new Uint8Array(), utf8ToBytes('Item_G_'));
|
|
74
|
+
export function jubjub_findGroupHash(m: Uint8Array, personalization: Uint8Array): ExtPointType {
|
|
75
|
+
const tag = concatBytes(m, new Uint8Array([0]));
|
|
76
|
+
const hashes = [];
|
|
77
|
+
for (let i = 0; i < 256; i++) {
|
|
78
|
+
tag[tag.length - 1] = i;
|
|
79
|
+
try {
|
|
80
|
+
hashes.push(jubjub_groupHash(tag, personalization));
|
|
81
|
+
} catch (e) {}
|
|
82
|
+
}
|
|
83
|
+
if (!hashes.length) throw new Error('findGroupHash tag overflow');
|
|
84
|
+
return hashes[0];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Pasta curves. See [Spec](https://o1-labs.github.io/proof-systems/specs/pasta.html).
|
|
88
|
+
|
|
89
|
+
export const pasta_p: bigint = BigInt(
|
|
90
|
+
'0x40000000000000000000000000000000224698fc094cf91b992d30ed00000001'
|
|
91
|
+
);
|
|
92
|
+
export const pasta_q: bigint = BigInt(
|
|
93
|
+
'0x40000000000000000000000000000000224698fc0994a8dd8c46eb2100000001'
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
/** https://neuromancer.sk/std/other/Pallas */
|
|
97
|
+
export const pallas: WCurveFn = weierstrass({
|
|
98
|
+
a: BigInt(0),
|
|
99
|
+
b: BigInt(5),
|
|
100
|
+
Fp: Field(pasta_p),
|
|
101
|
+
n: pasta_q,
|
|
102
|
+
Gx: mod(BigInt(-1), pasta_p),
|
|
103
|
+
Gy: BigInt(2),
|
|
104
|
+
h: BigInt(1),
|
|
105
|
+
...getHash(sha256),
|
|
106
|
+
});
|
|
107
|
+
/** https://neuromancer.sk/std/other/Vesta */
|
|
108
|
+
export const vesta: WCurveFn = weierstrass({
|
|
109
|
+
a: BigInt(0),
|
|
110
|
+
b: BigInt(5),
|
|
111
|
+
Fp: Field(pasta_q),
|
|
112
|
+
n: pasta_p,
|
|
113
|
+
Gx: mod(BigInt(-1), pasta_q),
|
|
114
|
+
Gy: BigInt(2),
|
|
115
|
+
h: BigInt(1),
|
|
116
|
+
...getHash(sha256),
|
|
117
|
+
});
|
package/src/p256.ts
CHANGED
|
@@ -4,25 +4,26 @@
|
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
6
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
7
|
-
import { sha256 } from '@noble/hashes/
|
|
8
|
-
import { createCurve, type CurveFnWithCreate } from './_shortw_utils.
|
|
9
|
-
import { createHasher, type HTFMethod } from './abstract/hash-to-curve.
|
|
10
|
-
import { Field } from './abstract/modular.
|
|
11
|
-
import { mapToCurveSimpleSWU } from './abstract/weierstrass.
|
|
7
|
+
import { sha256 } from '@noble/hashes/sha2';
|
|
8
|
+
import { createCurve, type CurveFnWithCreate } from './_shortw_utils.ts';
|
|
9
|
+
import { createHasher, type HTFMethod } from './abstract/hash-to-curve.ts';
|
|
10
|
+
import { Field } from './abstract/modular.ts';
|
|
11
|
+
import { mapToCurveSimpleSWU } from './abstract/weierstrass.ts';
|
|
12
12
|
|
|
13
13
|
const Fp256 = Field(BigInt('0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff'));
|
|
14
14
|
const CURVE_A = Fp256.create(BigInt('-3'));
|
|
15
15
|
const CURVE_B = BigInt('0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b');
|
|
16
16
|
|
|
17
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* secp256r1 curve, ECDSA and ECDH methods.
|
|
19
|
+
* Field: `2n**224n * (2n**32n-1n) + 2n**192n + 2n**96n-1n`
|
|
20
|
+
*/
|
|
18
21
|
// prettier-ignore
|
|
19
22
|
export const p256: CurveFnWithCreate = createCurve({
|
|
20
|
-
a: CURVE_A,
|
|
23
|
+
a: CURVE_A,
|
|
21
24
|
b: CURVE_B,
|
|
22
|
-
Fp: Fp256,
|
|
23
|
-
// Curve order, total count of valid points in the field
|
|
25
|
+
Fp: Fp256,
|
|
24
26
|
n: BigInt('0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551'),
|
|
25
|
-
// Base (generator) point (x, y)
|
|
26
27
|
Gx: BigInt('0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296'),
|
|
27
28
|
Gy: BigInt('0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5'),
|
|
28
29
|
h: BigInt(1),
|
|
@@ -48,7 +49,7 @@ const htf = /* @__PURE__ */ (() =>
|
|
|
48
49
|
expand: 'xmd',
|
|
49
50
|
hash: sha256,
|
|
50
51
|
}))();
|
|
51
|
-
/** secp256r1 hash-to-curve from
|
|
52
|
+
/** secp256r1 hash-to-curve from RFC 9380. */
|
|
52
53
|
export const hashToCurve: HTFMethod<bigint> = /* @__PURE__ */ (() => htf.hashToCurve)();
|
|
53
|
-
/** secp256r1 encode-to-curve from
|
|
54
|
+
/** secp256r1 encode-to-curve from RFC 9380. */
|
|
54
55
|
export const encodeToCurve: HTFMethod<bigint> = /* @__PURE__ */ (() => htf.encodeToCurve)();
|
package/src/p384.ts
CHANGED
|
@@ -4,29 +4,32 @@
|
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
6
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
7
|
-
import { sha384 } from '@noble/hashes/
|
|
8
|
-
import { createCurve, type CurveFnWithCreate } from './_shortw_utils.
|
|
9
|
-
import { createHasher, type HTFMethod } from './abstract/hash-to-curve.
|
|
10
|
-
import { Field } from './abstract/modular.
|
|
11
|
-
import { mapToCurveSimpleSWU } from './abstract/weierstrass.
|
|
7
|
+
import { sha384 } from '@noble/hashes/sha2';
|
|
8
|
+
import { createCurve, type CurveFnWithCreate } from './_shortw_utils.ts';
|
|
9
|
+
import { createHasher, type HTFMethod } from './abstract/hash-to-curve.ts';
|
|
10
|
+
import { Field } from './abstract/modular.ts';
|
|
11
|
+
import { mapToCurveSimpleSWU } from './abstract/weierstrass.ts';
|
|
12
12
|
|
|
13
13
|
// Field over which we'll do calculations.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
const Fp384 = Field(
|
|
15
|
+
BigInt(
|
|
16
|
+
'0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff'
|
|
17
|
+
)
|
|
18
|
+
);
|
|
17
19
|
const CURVE_A = Fp384.create(BigInt('-3'));
|
|
18
20
|
// prettier-ignore
|
|
19
21
|
const CURVE_B = BigInt('0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef');
|
|
20
22
|
|
|
21
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* secp384r1 curve, ECDSA and ECDH methods.
|
|
25
|
+
* Field: `2n**384n - 2n**128n - 2n**96n + 2n**32n - 1n`.
|
|
26
|
+
* */
|
|
22
27
|
// prettier-ignore
|
|
23
28
|
export const p384: CurveFnWithCreate = createCurve({
|
|
24
|
-
a: CURVE_A,
|
|
29
|
+
a: CURVE_A,
|
|
25
30
|
b: CURVE_B,
|
|
26
|
-
Fp: Fp384,
|
|
27
|
-
// Curve order, total count of valid points in the field.
|
|
31
|
+
Fp: Fp384,
|
|
28
32
|
n: BigInt('0xffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973'),
|
|
29
|
-
// Base (generator) point (x, y)
|
|
30
33
|
Gx: BigInt('0xaa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7'),
|
|
31
34
|
Gy: BigInt('0x3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f'),
|
|
32
35
|
h: BigInt(1),
|
|
@@ -52,7 +55,7 @@ const htf = /* @__PURE__ */ (() =>
|
|
|
52
55
|
expand: 'xmd',
|
|
53
56
|
hash: sha384,
|
|
54
57
|
}))();
|
|
55
|
-
/** secp384r1 hash-to-curve from
|
|
58
|
+
/** secp384r1 hash-to-curve from RFC 9380. */
|
|
56
59
|
export const hashToCurve: HTFMethod<bigint> = /* @__PURE__ */ (() => htf.hashToCurve)();
|
|
57
|
-
/** secp384r1 encode-to-curve from
|
|
60
|
+
/** secp384r1 encode-to-curve from RFC 9380. */
|
|
58
61
|
export const encodeToCurve: HTFMethod<bigint> = /* @__PURE__ */ (() => htf.encodeToCurve)();
|
package/src/p521.ts
CHANGED
|
@@ -5,22 +5,32 @@
|
|
|
5
5
|
* @module
|
|
6
6
|
*/
|
|
7
7
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
8
|
-
import { sha512 } from '@noble/hashes/
|
|
9
|
-
import { createCurve, type CurveFnWithCreate } from './_shortw_utils.
|
|
10
|
-
import { createHasher, type HTFMethod } from './abstract/hash-to-curve.
|
|
11
|
-
import { Field } from './abstract/modular.
|
|
12
|
-
import { mapToCurveSimpleSWU } from './abstract/weierstrass.
|
|
8
|
+
import { sha512 } from '@noble/hashes/sha2';
|
|
9
|
+
import { createCurve, type CurveFnWithCreate } from './_shortw_utils.ts';
|
|
10
|
+
import { createHasher, type HTFMethod } from './abstract/hash-to-curve.ts';
|
|
11
|
+
import { Field } from './abstract/modular.ts';
|
|
12
|
+
import { mapToCurveSimpleSWU } from './abstract/weierstrass.ts';
|
|
13
13
|
|
|
14
14
|
// Field over which we'll do calculations.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
const Fp521 = Field(
|
|
16
|
+
BigInt(
|
|
17
|
+
'0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
|
|
18
|
+
)
|
|
19
|
+
);
|
|
18
20
|
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
const CURVE_A = Fp521.create(BigInt('-3'));
|
|
22
|
+
const CURVE_B = BigInt(
|
|
23
|
+
'0x0051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00'
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* NIST secp521r1 aka p521 curve, ECDSA and ECDH methods.
|
|
28
|
+
* Field: `2n**521n - 1n`.
|
|
29
|
+
*/
|
|
30
|
+
// prettier-ignore
|
|
31
|
+
export const p521: CurveFnWithCreate = createCurve({
|
|
32
|
+
a: CURVE_A,
|
|
33
|
+
b: CURVE_B,
|
|
24
34
|
Fp: Fp521,
|
|
25
35
|
n: BigInt(
|
|
26
36
|
'0x01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409'
|
|
@@ -32,21 +42,6 @@ const CURVE = {
|
|
|
32
42
|
'0x011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650'
|
|
33
43
|
),
|
|
34
44
|
h: BigInt(1),
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* NIST secp521r1 aka p521.
|
|
39
|
-
*/
|
|
40
|
-
// prettier-ignore
|
|
41
|
-
export const p521: CurveFnWithCreate = createCurve({
|
|
42
|
-
a: CURVE.a, // Equation params: a, b
|
|
43
|
-
b: CURVE.b,
|
|
44
|
-
Fp: Fp521, // Field: 2n**521n - 1n
|
|
45
|
-
// Curve order, total count of valid points in the field
|
|
46
|
-
n: CURVE.n,
|
|
47
|
-
Gx: CURVE.Gx, // Base point (x, y) aka generator point
|
|
48
|
-
Gy: CURVE.Gy,
|
|
49
|
-
h: CURVE.h,
|
|
50
45
|
lowS: false,
|
|
51
46
|
allowedPrivateKeyLengths: [130, 131, 132] // P521 keys are variable-length. Normalize to 132b
|
|
52
47
|
} as const, sha512);
|
|
@@ -54,8 +49,8 @@ export const secp521r1: CurveFnWithCreate = p521;
|
|
|
54
49
|
|
|
55
50
|
const mapSWU = /* @__PURE__ */ (() =>
|
|
56
51
|
mapToCurveSimpleSWU(Fp521, {
|
|
57
|
-
A:
|
|
58
|
-
B:
|
|
52
|
+
A: CURVE_A,
|
|
53
|
+
B: CURVE_B,
|
|
59
54
|
Z: Fp521.create(BigInt('-4')),
|
|
60
55
|
}))();
|
|
61
56
|
|
|
@@ -69,7 +64,7 @@ const htf = /* @__PURE__ */ (() =>
|
|
|
69
64
|
expand: 'xmd',
|
|
70
65
|
hash: sha512,
|
|
71
66
|
}))();
|
|
72
|
-
/** secp521r1 hash-to-curve from
|
|
67
|
+
/** secp521r1 hash-to-curve from RFC 9380. */
|
|
73
68
|
export const hashToCurve: HTFMethod<bigint> = /* @__PURE__ */ (() => htf.hashToCurve)();
|
|
74
|
-
/** secp521r1 encode-to-curve from
|
|
69
|
+
/** secp521r1 encode-to-curve from RFC 9380. */
|
|
75
70
|
export const encodeToCurve: HTFMethod<bigint> = /* @__PURE__ */ (() => htf.encodeToCurve)();
|
package/src/pasta.ts
CHANGED
|
@@ -1,39 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Pasta curves. See [Spec](https://o1-labs.github.io/proof-systems/specs/pasta.html).
|
|
3
|
-
* @module
|
|
4
|
-
*/
|
|
5
|
-
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
6
|
-
import { sha256 } from '@noble/hashes/sha256';
|
|
7
|
-
import { getHash } from './_shortw_utils.js';
|
|
8
|
-
import { Field, mod } from './abstract/modular.js';
|
|
9
|
-
import { type CurveFn, weierstrass } from './abstract/weierstrass.js';
|
|
10
|
-
|
|
11
|
-
export const p: bigint = BigInt(
|
|
12
|
-
'0x40000000000000000000000000000000224698fc094cf91b992d30ed00000001'
|
|
13
|
-
);
|
|
14
|
-
export const q: bigint = BigInt(
|
|
15
|
-
'0x40000000000000000000000000000000224698fc0994a8dd8c46eb2100000001'
|
|
16
|
-
);
|
|
17
|
-
|
|
18
|
-
/** https://neuromancer.sk/std/other/Pallas */
|
|
19
|
-
export const pallas: CurveFn = weierstrass({
|
|
20
|
-
a: BigInt(0),
|
|
21
|
-
b: BigInt(5),
|
|
22
|
-
Fp: Field(p),
|
|
23
|
-
n: q,
|
|
24
|
-
Gx: mod(BigInt(-1), p),
|
|
25
|
-
Gy: BigInt(2),
|
|
26
|
-
h: BigInt(1),
|
|
27
|
-
...getHash(sha256),
|
|
28
|
-
});
|
|
29
|
-
/** https://neuromancer.sk/std/other/Vesta */
|
|
30
|
-
export const vesta: CurveFn = weierstrass({
|
|
31
|
-
a: BigInt(0),
|
|
32
|
-
b: BigInt(5),
|
|
33
|
-
Fp: Field(q),
|
|
34
|
-
n: p,
|
|
35
|
-
Gx: mod(BigInt(-1), q),
|
|
36
|
-
Gy: BigInt(2),
|
|
37
|
-
h: BigInt(1),
|
|
38
|
-
...getHash(sha256),
|
|
39
|
-
});
|
|
1
|
+
export { pallas, vesta } from './misc.ts';
|
package/src/secp256k1.ts
CHANGED
|
@@ -11,12 +11,12 @@
|
|
|
11
11
|
* @module
|
|
12
12
|
*/
|
|
13
13
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
14
|
-
import { sha256 } from '@noble/hashes/
|
|
14
|
+
import { sha256 } from '@noble/hashes/sha2';
|
|
15
15
|
import { randomBytes } from '@noble/hashes/utils';
|
|
16
|
-
import { createCurve, type CurveFnWithCreate } from './_shortw_utils.
|
|
17
|
-
import { createHasher, type HTFMethod, isogenyMap } from './abstract/hash-to-curve.
|
|
18
|
-
import { Field, mod, pow2 } from './abstract/modular.
|
|
19
|
-
import type { Hex, PrivKey } from './abstract/utils.
|
|
16
|
+
import { createCurve, type CurveFnWithCreate } from './_shortw_utils.ts';
|
|
17
|
+
import { createHasher, type HTFMethod, isogenyMap } from './abstract/hash-to-curve.ts';
|
|
18
|
+
import { Field, mod, pow2 } from './abstract/modular.ts';
|
|
19
|
+
import type { Hex, PrivKey } from './abstract/utils.ts';
|
|
20
20
|
import {
|
|
21
21
|
aInRange,
|
|
22
22
|
bytesToNumberBE,
|
|
@@ -24,8 +24,8 @@ import {
|
|
|
24
24
|
ensureBytes,
|
|
25
25
|
inRange,
|
|
26
26
|
numberToBytesBE,
|
|
27
|
-
} from './abstract/utils.
|
|
28
|
-
import { mapToCurveSimpleSWU, type ProjPointType as PointType } from './abstract/weierstrass.
|
|
27
|
+
} from './abstract/utils.ts';
|
|
28
|
+
import { mapToCurveSimpleSWU, type ProjPointType as PointType } from './abstract/weierstrass.ts';
|
|
29
29
|
|
|
30
30
|
const secp256k1P = BigInt('0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f');
|
|
31
31
|
const secp256k1N = BigInt('0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141');
|
|
@@ -64,24 +64,26 @@ function sqrtMod(y: bigint): bigint {
|
|
|
64
64
|
const Fpk1 = Field(secp256k1P, undefined, undefined, { sqrt: sqrtMod });
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
|
-
* secp256k1
|
|
67
|
+
* secp256k1 curve, ECDSA and ECDH methods.
|
|
68
|
+
*
|
|
69
|
+
* Field: `2n**256n - 2n**32n - 2n**9n - 2n**8n - 2n**7n - 2n**6n - 2n**4n - 1n`
|
|
68
70
|
*
|
|
69
71
|
* @example
|
|
72
|
+
* ```js
|
|
70
73
|
* import { secp256k1 } from '@noble/curves/secp256k1';
|
|
71
|
-
*
|
|
72
74
|
* const priv = secp256k1.utils.randomPrivateKey();
|
|
73
75
|
* const pub = secp256k1.getPublicKey(priv);
|
|
74
76
|
* const msg = new Uint8Array(32).fill(1); // message hash (not message) in ecdsa
|
|
75
77
|
* const sig = secp256k1.sign(msg, priv); // `{prehash: true}` option is available
|
|
76
78
|
* const isValid = secp256k1.verify(sig, msg, pub) === true;
|
|
79
|
+
* ```
|
|
77
80
|
*/
|
|
78
81
|
export const secp256k1: CurveFnWithCreate = createCurve(
|
|
79
82
|
{
|
|
80
|
-
a: BigInt(0),
|
|
83
|
+
a: BigInt(0),
|
|
81
84
|
b: BigInt(7),
|
|
82
|
-
Fp: Fpk1,
|
|
83
|
-
n: secp256k1N,
|
|
84
|
-
// Base point (x, y) aka generator point
|
|
85
|
+
Fp: Fpk1,
|
|
86
|
+
n: secp256k1N,
|
|
85
87
|
Gx: BigInt('55066263022277343669578718895168534326250603453777594175500187360389116729240'),
|
|
86
88
|
Gy: BigInt('32670510020758816978083085130507043184471273380659243275938904335757337482424'),
|
|
87
89
|
h: BigInt(1), // Cofactor
|
|
@@ -242,12 +244,14 @@ export type SecpSchnorr = {
|
|
|
242
244
|
* Schnorr signatures over secp256k1.
|
|
243
245
|
* https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki
|
|
244
246
|
* @example
|
|
247
|
+
* ```js
|
|
245
248
|
* import { schnorr } from '@noble/curves/secp256k1';
|
|
246
249
|
* const priv = schnorr.utils.randomPrivateKey();
|
|
247
250
|
* const pub = schnorr.getPublicKey(priv);
|
|
248
251
|
* const msg = new TextEncoder().encode('hello');
|
|
249
252
|
* const sig = schnorr.sign(msg, priv);
|
|
250
253
|
* const isValid = schnorr.verify(sig, msg, pub);
|
|
254
|
+
* ```
|
|
251
255
|
*/
|
|
252
256
|
export const schnorr: SecpSchnorr = /* @__PURE__ */ (() => ({
|
|
253
257
|
getPublicKey: schnorrGetPublicKey,
|
|
@@ -321,8 +325,8 @@ const htf = /* @__PURE__ */ (() =>
|
|
|
321
325
|
}
|
|
322
326
|
))();
|
|
323
327
|
|
|
324
|
-
/** secp256k1 hash-to-curve from
|
|
328
|
+
/** secp256k1 hash-to-curve from RFC 9380. */
|
|
325
329
|
export const hashToCurve: HTFMethod<bigint> = /* @__PURE__ */ (() => htf.hashToCurve)();
|
|
326
330
|
|
|
327
|
-
/** secp256k1 encode-to-curve from
|
|
331
|
+
/** secp256k1 encode-to-curve from RFC 9380. */
|
|
328
332
|
export const encodeToCurve: HTFMethod<bigint> = /* @__PURE__ */ (() => htf.encodeToCurve)();
|