@noble/curves 1.8.0 → 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 +282 -419
- package/_shortw_utils.d.ts +2 -2
- package/_shortw_utils.d.ts.map +1 -1
- package/_shortw_utils.js +2 -2
- package/_shortw_utils.js.map +1 -1
- 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.d.ts.map +1 -1
- package/abstract/poseidon.js +3 -3
- package/abstract/poseidon.js.map +1 -1
- 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 +19 -6
- 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.d.ts.map +1 -1
- package/bls12-381.js +48 -49
- package/bls12-381.js.map +1 -1
- package/bn254.d.ts +2 -2
- package/bn254.d.ts.map +1 -1
- package/bn254.js +29 -30
- 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.d.ts.map +1 -1
- package/esm/_shortw_utils.js +1 -1
- package/esm/_shortw_utils.js.map +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.d.ts.map +1 -1
- package/esm/abstract/poseidon.js +1 -1
- package/esm/abstract/poseidon.js.map +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 +19 -6
- package/esm/abstract/weierstrass.d.ts.map +1 -1
- package/esm/abstract/weierstrass.js +77 -60
- package/esm/abstract/weierstrass.js.map +1 -1
- package/esm/bls12-381.d.ts +1 -1
- package/esm/bls12-381.d.ts.map +1 -1
- package/esm/bls12-381.js +16 -17
- package/esm/bls12-381.js.map +1 -1
- package/esm/bn254.d.ts +2 -2
- package/esm/bn254.d.ts.map +1 -1
- package/esm/bn254.js +7 -8
- 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/index.js +13 -1
- package/esm/index.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/index.js +13 -1
- package/index.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 +21 -16
- 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 +14 -12
- package/src/abstract/curve.ts +88 -79
- package/src/abstract/edwards.ts +52 -59
- 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 +99 -77
- package/src/bls12-381.ts +30 -28
- package/src/bn254.ts +11 -13
- package/src/ed25519.ts +27 -26
- package/src/ed448.ts +21 -20
- package/src/index.ts +13 -1
- 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 +20 -16
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 { 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,21 +11,21 @@
|
|
|
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, CurveFnWithCreate } from './_shortw_utils.
|
|
17
|
-
import { createHasher, 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
|
-
inRange,
|
|
22
21
|
aInRange,
|
|
23
22
|
bytesToNumberBE,
|
|
24
23
|
concatBytes,
|
|
25
24
|
ensureBytes,
|
|
25
|
+
inRange,
|
|
26
26
|
numberToBytesBE,
|
|
27
|
-
} from './abstract/utils.
|
|
28
|
-
import { ProjPointType as PointType
|
|
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)();
|