@noble/curves 0.6.4 → 0.7.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 +486 -298
- package/{lib/_shortw_utils.d.ts → _shortw_utils.d.ts} +1 -1
- package/_shortw_utils.d.ts.map +1 -0
- package/{lib/_shortw_utils.js → _shortw_utils.js} +2 -0
- package/_shortw_utils.js.map +1 -0
- package/{lib/abstract → abstract}/bls.d.ts +4 -9
- package/abstract/bls.d.ts.map +1 -0
- package/{lib/abstract → abstract}/bls.js +13 -26
- package/abstract/bls.js.map +1 -0
- package/{lib/abstract → abstract}/curve.d.ts +1 -0
- package/abstract/curve.d.ts.map +1 -0
- package/{lib/abstract → abstract}/curve.js +1 -0
- package/abstract/curve.js.map +1 -0
- package/{lib/abstract → abstract}/edwards.d.ts +1 -0
- package/abstract/edwards.d.ts.map +1 -0
- package/{lib/abstract → abstract}/edwards.js +9 -15
- package/abstract/edwards.js.map +1 -0
- package/{lib/abstract → abstract}/hash-to-curve.d.ts +5 -5
- package/abstract/hash-to-curve.d.ts.map +1 -0
- package/{lib/abstract → abstract}/hash-to-curve.js +41 -38
- package/abstract/hash-to-curve.js.map +1 -0
- package/{lib/abstract → abstract}/modular.d.ts +1 -0
- package/abstract/modular.d.ts.map +1 -0
- package/{lib/abstract → abstract}/modular.js +2 -1
- package/abstract/modular.js.map +1 -0
- package/{lib/abstract → abstract}/montgomery.d.ts +4 -3
- package/abstract/montgomery.d.ts.map +1 -0
- package/{lib/abstract → abstract}/montgomery.js +12 -9
- package/abstract/montgomery.js.map +1 -0
- package/{lib/abstract → abstract}/poseidon.d.ts +1 -0
- package/abstract/poseidon.d.ts.map +1 -0
- package/{lib/abstract → abstract}/poseidon.js +1 -0
- package/abstract/poseidon.js.map +1 -0
- package/{lib/abstract → abstract}/utils.d.ts +12 -1
- package/abstract/utils.d.ts.map +1 -0
- package/{lib/abstract → abstract}/utils.js +96 -10
- package/abstract/utils.js.map +1 -0
- package/{lib/abstract → abstract}/weierstrass.d.ts +6 -6
- package/abstract/weierstrass.d.ts.map +1 -0
- package/{lib/abstract → abstract}/weierstrass.js +74 -115
- package/abstract/weierstrass.js.map +1 -0
- package/{lib/bls12-381.d.ts → bls12-381.d.ts} +1 -0
- package/bls12-381.d.ts.map +1 -0
- package/{lib/bls12-381.js → bls12-381.js} +41 -7
- package/bls12-381.js.map +1 -0
- package/{lib/bn.d.ts → bn.d.ts} +1 -0
- package/bn.d.ts.map +1 -0
- package/{lib/bn.js → bn.js} +1 -0
- package/bn.js.map +1 -0
- package/{lib/ed25519.d.ts → ed25519.d.ts} +2 -1
- package/ed25519.d.ts.map +1 -0
- package/{lib/ed25519.js → ed25519.js} +6 -5
- package/ed25519.js.map +1 -0
- package/{lib/ed448.d.ts → ed448.d.ts} +2 -1
- package/ed448.d.ts.map +1 -0
- package/{lib/ed448.js → ed448.js} +4 -3
- package/ed448.js.map +1 -0
- package/{lib/esm → esm}/_shortw_utils.js +2 -0
- package/esm/_shortw_utils.js.map +1 -0
- package/{lib/esm → esm}/abstract/bls.js +14 -27
- package/esm/abstract/bls.js.map +1 -0
- package/{lib/esm → esm}/abstract/curve.js +1 -0
- package/esm/abstract/curve.js.map +1 -0
- package/{lib/esm → esm}/abstract/edwards.js +9 -15
- package/esm/abstract/edwards.js.map +1 -0
- package/{lib/esm → esm}/abstract/hash-to-curve.js +40 -36
- package/esm/abstract/hash-to-curve.js.map +1 -0
- package/{lib/esm → esm}/abstract/modular.js +2 -1
- package/esm/abstract/modular.js.map +1 -0
- package/{lib/esm → esm}/abstract/montgomery.js +12 -9
- package/esm/abstract/montgomery.js.map +1 -0
- package/{lib/esm → esm}/abstract/poseidon.js +1 -0
- package/esm/abstract/poseidon.js.map +1 -0
- package/{lib/esm → esm}/abstract/utils.js +93 -9
- package/esm/abstract/utils.js.map +1 -0
- package/{lib/esm → esm}/abstract/weierstrass.js +74 -115
- package/esm/abstract/weierstrass.js.map +1 -0
- package/{lib/esm → esm}/bls12-381.js +41 -7
- package/esm/bls12-381.js.map +1 -0
- package/{lib/esm → esm}/bn.js +1 -0
- package/esm/bn.js.map +1 -0
- package/{lib/esm → esm}/ed25519.js +7 -6
- package/esm/ed25519.js.map +1 -0
- package/{lib/esm → esm}/ed448.js +4 -3
- package/esm/ed448.js.map +1 -0
- package/{lib → esm}/index.js +1 -0
- package/esm/index.js.map +1 -0
- package/{lib/esm → esm}/jubjub.js +1 -0
- package/esm/jubjub.js.map +1 -0
- package/{lib/esm → esm}/p192.js +1 -0
- package/esm/p192.js.map +1 -0
- package/{lib/esm → esm}/p224.js +1 -0
- package/esm/p224.js.map +1 -0
- package/{lib/esm → esm}/p256.js +2 -1
- package/esm/p256.js.map +1 -0
- package/{lib/esm → esm}/p384.js +2 -1
- package/esm/p384.js.map +1 -0
- package/{lib/esm → esm}/p521.js +2 -1
- package/esm/p521.js.map +1 -0
- package/{lib/esm → esm}/package.json +0 -0
- package/{lib/esm → esm}/pasta.js +1 -0
- package/esm/pasta.js.map +1 -0
- package/{lib/esm → esm}/secp256k1.js +51 -50
- package/esm/secp256k1.js.map +1 -0
- package/{lib/esm → esm}/stark.js +5 -4
- package/esm/stark.js.map +1 -0
- package/index.d.ts +1 -0
- package/index.d.ts.map +1 -0
- package/index.js +3 -0
- package/index.js.map +1 -0
- package/{lib/jubjub.d.ts → jubjub.d.ts} +1 -0
- package/jubjub.d.ts.map +1 -0
- package/{lib/jubjub.js → jubjub.js} +1 -0
- package/jubjub.js.map +1 -0
- package/{lib/p192.d.ts → p192.d.ts} +1 -2
- package/p192.d.ts.map +1 -0
- package/{lib/p192.js → p192.js} +1 -0
- package/p192.js.map +1 -0
- package/{lib/p224.d.ts → p224.d.ts} +1 -2
- package/p224.d.ts.map +1 -0
- package/{lib/p224.js → p224.js} +1 -0
- package/p224.js.map +1 -0
- package/{lib/p256.d.ts → p256.d.ts} +2 -3
- package/p256.d.ts.map +1 -0
- package/{lib/p256.js → p256.js} +2 -1
- package/p256.js.map +1 -0
- package/{lib/p384.d.ts → p384.d.ts} +2 -3
- package/p384.d.ts.map +1 -0
- package/{lib/p384.js → p384.js} +2 -1
- package/p384.js.map +1 -0
- package/{lib/p521.d.ts → p521.d.ts} +2 -3
- package/p521.d.ts.map +1 -0
- package/{lib/p521.js → p521.js} +2 -1
- package/p521.js.map +1 -0
- package/package.json +84 -79
- package/{lib/pasta.d.ts → pasta.d.ts} +1 -0
- package/pasta.d.ts.map +1 -0
- package/{lib/pasta.js → pasta.js} +1 -0
- package/pasta.js.map +1 -0
- package/{lib/secp256k1.d.ts → secp256k1.d.ts} +20 -6
- package/secp256k1.d.ts.map +1 -0
- package/{lib/secp256k1.js → secp256k1.js} +48 -47
- package/secp256k1.js.map +1 -0
- package/src/_shortw_utils.ts +20 -0
- package/src/abstract/bls.ts +376 -0
- package/src/abstract/curve.ts +199 -0
- package/src/abstract/edwards.ts +479 -0
- package/src/abstract/hash-to-curve.ts +220 -0
- package/src/abstract/modular.ts +417 -0
- package/src/abstract/montgomery.ts +186 -0
- package/src/abstract/poseidon.ts +119 -0
- package/src/abstract/utils.ts +246 -0
- package/src/abstract/weierstrass.ts +1177 -0
- package/src/bls12-381.ts +1274 -0
- package/src/bn.ts +21 -0
- package/src/ed25519.ts +428 -0
- package/src/ed448.ts +241 -0
- package/{lib/esm/index.js → src/index.ts} +0 -1
- package/src/jubjub.ts +58 -0
- package/src/p192.ts +25 -0
- package/src/p224.ts +25 -0
- package/src/p256.ts +53 -0
- package/src/p384.ts +57 -0
- package/src/p521.ts +57 -0
- package/src/pasta.ts +31 -0
- package/src/secp256k1.ts +270 -0
- package/src/stark.ts +356 -0
- package/{lib/stark.d.ts → stark.d.ts} +1 -1
- package/stark.d.ts.map +1 -0
- package/{lib/stark.js → stark.js} +5 -4
- package/stark.js.map +1 -0
- package/lib/index.d.ts +0 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { mod } from './abstract/modular.js';
|
|
2
2
|
import { ProjPointType as PointType } from './abstract/weierstrass.js';
|
|
3
|
-
import { Hex,
|
|
3
|
+
import type { Hex, PrivKey } from './abstract/utils.js';
|
|
4
|
+
import { bytesToNumberBE } from './abstract/utils.js';
|
|
4
5
|
import * as htf from './abstract/hash-to-curve.js';
|
|
5
6
|
export declare const secp256k1: Readonly<{
|
|
6
7
|
create: (hash: import("./abstract/utils.js").CHash) => import("./abstract/weierstrass.js").CurveFn;
|
|
@@ -48,7 +49,6 @@ export declare const secp256k1: Readonly<{
|
|
|
48
49
|
utils: {
|
|
49
50
|
normPrivateKeyToScalar: (key: PrivKey) => bigint;
|
|
50
51
|
isValidPrivateKey(privateKey: PrivKey): boolean;
|
|
51
|
-
hashToPrivateKey: (hash: Hex) => Uint8Array;
|
|
52
52
|
randomPrivateKey: () => Uint8Array;
|
|
53
53
|
precompute: (windowSize?: number | undefined, point?: PointType<bigint> | undefined) => PointType<bigint>;
|
|
54
54
|
};
|
|
@@ -59,11 +59,23 @@ declare function schnorrGetExtPubKey(priv: PrivKey): {
|
|
|
59
59
|
scalar: bigint;
|
|
60
60
|
bytes: Uint8Array;
|
|
61
61
|
};
|
|
62
|
+
/**
|
|
63
|
+
* lift_x from BIP340. Convert 32-byte x coordinate to elliptic curve point.
|
|
64
|
+
* @returns valid point checked for being on-curve
|
|
65
|
+
*/
|
|
62
66
|
declare function lift_x(x: bigint): PointType<bigint>;
|
|
67
|
+
/**
|
|
68
|
+
* Schnorr public key is just `x` coordinate of Point as per BIP340.
|
|
69
|
+
*/
|
|
63
70
|
declare function schnorrGetPublicKey(privateKey: Hex): Uint8Array;
|
|
71
|
+
/**
|
|
72
|
+
* Creates Schnorr signature as per BIP340. Verifies itself before returning anything.
|
|
73
|
+
* auxRand is optional and is not the sole source of k generation: bad CSPRNG won't be dangerous.
|
|
74
|
+
*/
|
|
64
75
|
declare function schnorrSign(message: Hex, privateKey: PrivKey, auxRand?: Hex): Uint8Array;
|
|
65
76
|
/**
|
|
66
|
-
* Verifies Schnorr signature
|
|
77
|
+
* Verifies Schnorr signature.
|
|
78
|
+
* Will swallow errors & return false except for initial type validation of arguments.
|
|
67
79
|
*/
|
|
68
80
|
declare function schnorrVerify(signature: Hex, message: Hex, publicKey: Hex): boolean;
|
|
69
81
|
export declare const schnorr: {
|
|
@@ -71,14 +83,16 @@ export declare const schnorr: {
|
|
|
71
83
|
sign: typeof schnorrSign;
|
|
72
84
|
verify: typeof schnorrVerify;
|
|
73
85
|
utils: {
|
|
86
|
+
randomPrivateKey: () => Uint8Array;
|
|
74
87
|
getExtendedPublicKey: typeof schnorrGetExtPubKey;
|
|
75
88
|
lift_x: typeof lift_x;
|
|
76
89
|
pointToBytes: (point: PointType<bigint>) => Uint8Array;
|
|
77
90
|
numberToBytesBE: (n: bigint, len: number) => Uint8Array;
|
|
78
|
-
bytesToNumberBE: typeof
|
|
91
|
+
bytesToNumberBE: typeof bytesToNumberBE;
|
|
79
92
|
taggedHash: typeof taggedHash;
|
|
80
93
|
mod: typeof mod;
|
|
81
94
|
};
|
|
82
95
|
};
|
|
83
|
-
declare const hashToCurve: (msg:
|
|
84
|
-
export {
|
|
96
|
+
export declare const hashToCurve: (msg: Uint8Array, options?: htf.htfBasicOpts | undefined) => htf.H2CPoint<bigint>, encodeToCurve: (msg: Uint8Array, options?: htf.htfBasicOpts | undefined) => htf.H2CPoint<bigint>;
|
|
97
|
+
export {};
|
|
98
|
+
//# sourceMappingURL=secp256k1.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secp256k1.d.ts","sourceRoot":"","sources":["src/secp256k1.ts"],"names":[],"mappings":"AAGA,OAAO,EAAe,GAAG,EAAQ,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAAE,aAAa,IAAI,SAAS,EAAuB,MAAM,2BAA2B,CAAC;AAC5F,OAAO,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,eAAe,EAA6C,MAAM,qBAAqB,CAAC;AACjG,OAAO,KAAK,GAAG,MAAM,6BAA6B,CAAC;AAwCnD,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2CrB,CAAC;AASF,iBAAS,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,QAAQ,EAAE,UAAU,EAAE,GAAG,UAAU,CAQtE;AAWD,iBAAS,mBAAmB,CAAC,IAAI,EAAE,OAAO;;;;EAKzC;AACD;;;GAGG;AACH,iBAAS,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,CAS5C;AAQD;;GAEG;AACH,iBAAS,mBAAmB,CAAC,UAAU,EAAE,GAAG,GAAG,UAAU,CAExD;AAED;;;GAGG;AACH,iBAAS,WAAW,CAClB,OAAO,EAAE,GAAG,EACZ,UAAU,EAAE,OAAO,EACnB,OAAO,GAAE,GAAqB,GAC7B,UAAU,CAgBZ;AAED;;;GAGG;AACH,iBAAS,aAAa,CAAC,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,GAAG,OAAO,CAiB5E;AAED,eAAO,MAAM,OAAO;;;;;;;;8BA3FS,UAAU,MAAM,CAAC;;;;;;CAyG7C,CAAC;AAuCF,eAAO,MAAQ,WAAW,qFAAE,aAAa,mFAexC,CAAC"}
|
|
@@ -1,21 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var _a;
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
4
|
exports.encodeToCurve = exports.hashToCurve = exports.schnorr = exports.secp256k1 = void 0;
|
|
4
5
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
5
6
|
const sha256_1 = require("@noble/hashes/sha256");
|
|
7
|
+
const utils_1 = require("@noble/hashes/utils");
|
|
6
8
|
const modular_js_1 = require("./abstract/modular.js");
|
|
7
|
-
const _shortw_utils_js_1 = require("./_shortw_utils.js");
|
|
8
9
|
const weierstrass_js_1 = require("./abstract/weierstrass.js");
|
|
9
10
|
const utils_js_1 = require("./abstract/utils.js");
|
|
10
|
-
const utils_1 = require("@noble/hashes/utils");
|
|
11
11
|
const htf = require("./abstract/hash-to-curve.js");
|
|
12
|
-
|
|
13
|
-
* secp256k1 belongs to Koblitz curves: it has efficiently computable endomorphism.
|
|
14
|
-
* Endomorphism uses 2x less RAM, speeds up precomputation by 2x and ECDH / key recovery by 20%.
|
|
15
|
-
* Should always be used for Projective's double-and-add multiplication.
|
|
16
|
-
* For affines cached multiplication, it trades off 1/2 init time & 1/3 ram for 20% perf hit.
|
|
17
|
-
* https://gist.github.com/paulmillr/eb670806793e84df628a7c434a873066
|
|
18
|
-
*/
|
|
12
|
+
const _shortw_utils_js_1 = require("./_shortw_utils.js");
|
|
19
13
|
const secp256k1P = BigInt('0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f');
|
|
20
14
|
const secp256k1N = BigInt('0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141');
|
|
21
15
|
const _1n = BigInt(1);
|
|
@@ -51,23 +45,22 @@ function sqrtMod(y) {
|
|
|
51
45
|
}
|
|
52
46
|
const Fp = (0, modular_js_1.Fp)(secp256k1P, undefined, undefined, { sqrt: sqrtMod });
|
|
53
47
|
exports.secp256k1 = (0, _shortw_utils_js_1.createCurve)({
|
|
54
|
-
// Params: a, b
|
|
55
|
-
// Seem to be rigid https://bitcointalk.org/index.php?topic=289795.msg3183975#msg3183975
|
|
56
48
|
a: BigInt(0),
|
|
57
49
|
b: BigInt(7),
|
|
58
|
-
// Field over which we'll do calculations;
|
|
59
|
-
// 2n**256n - 2n**32n - 2n**9n - 2n**8n - 2n**7n - 2n**6n - 2n**4n - 1n
|
|
60
50
|
Fp,
|
|
61
|
-
// Curve order, total count of valid points in the field
|
|
62
51
|
n: secp256k1N,
|
|
63
52
|
// Base point (x, y) aka generator point
|
|
64
53
|
Gx: BigInt('55066263022277343669578718895168534326250603453777594175500187360389116729240'),
|
|
65
54
|
Gy: BigInt('32670510020758816978083085130507043184471273380659243275938904335757337482424'),
|
|
66
55
|
h: BigInt(1),
|
|
67
|
-
// Alllow only low-S signatures by default in sign() and verify()
|
|
68
56
|
lowS: true,
|
|
57
|
+
/**
|
|
58
|
+
* secp256k1 belongs to Koblitz curves: it has efficiently computable endomorphism.
|
|
59
|
+
* Endomorphism uses 2x less RAM, speeds up precomputation by 2x and ECDH / key recovery by 20%.
|
|
60
|
+
* For precomputed wNAF it trades off 1/2 init time & 1/3 ram for 20% perf hit.
|
|
61
|
+
* Explanation: https://gist.github.com/paulmillr/eb670806793e84df628a7c434a873066
|
|
62
|
+
*/
|
|
69
63
|
endo: {
|
|
70
|
-
// Params taken from https://gist.github.com/paulmillr/eb670806793e84df628a7c434a873066
|
|
71
64
|
beta: BigInt('0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee'),
|
|
72
65
|
splitScalar: (k) => {
|
|
73
66
|
const n = secp256k1N;
|
|
@@ -93,17 +86,11 @@ exports.secp256k1 = (0, _shortw_utils_js_1.createCurve)({
|
|
|
93
86
|
},
|
|
94
87
|
},
|
|
95
88
|
}, sha256_1.sha256);
|
|
96
|
-
// Schnorr signatures are superior to ECDSA from above.
|
|
97
|
-
// Below is Schnorr-specific code as per BIP0340.
|
|
89
|
+
// Schnorr signatures are superior to ECDSA from above. Below is Schnorr-specific BIP0340 code.
|
|
98
90
|
// https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki
|
|
99
91
|
const _0n = BigInt(0);
|
|
100
92
|
const fe = (x) => typeof x === 'bigint' && _0n < x && x < secp256k1P;
|
|
101
93
|
const ge = (x) => typeof x === 'bigint' && _0n < x && x < secp256k1N;
|
|
102
|
-
const TAGS = {
|
|
103
|
-
challenge: 'BIP0340/challenge',
|
|
104
|
-
aux: 'BIP0340/aux',
|
|
105
|
-
nonce: 'BIP0340/nonce',
|
|
106
|
-
};
|
|
107
94
|
/** An object mapping tags to their tagged hash prefix of [SHA256(tag) | SHA256(tag)] */
|
|
108
95
|
const TAGGED_HASH_PREFIXES = {};
|
|
109
96
|
function taggedHash(tag, ...messages) {
|
|
@@ -115,46 +102,58 @@ function taggedHash(tag, ...messages) {
|
|
|
115
102
|
}
|
|
116
103
|
return (0, sha256_1.sha256)((0, utils_js_1.concatBytes)(tagP, ...messages));
|
|
117
104
|
}
|
|
105
|
+
// ECDSA compact points are 33-byte. Schnorr is 32: we strip first byte 0x02 or 0x03
|
|
118
106
|
const pointToBytes = (point) => point.toRawBytes(true).slice(1);
|
|
119
107
|
const numTo32b = (n) => (0, utils_js_1.numberToBytesBE)(n, 32);
|
|
108
|
+
const modP = (x) => (0, modular_js_1.mod)(x, secp256k1P);
|
|
120
109
|
const modN = (x) => (0, modular_js_1.mod)(x, secp256k1N);
|
|
121
110
|
const Point = exports.secp256k1.ProjectivePoint;
|
|
122
111
|
const GmulAdd = (Q, a, b) => Point.BASE.multiplyAndAddUnsafe(Q, a, b);
|
|
123
|
-
|
|
112
|
+
// Calculate point, scalar and bytes
|
|
124
113
|
function schnorrGetExtPubKey(priv) {
|
|
125
|
-
|
|
114
|
+
const d = exports.secp256k1.utils.normPrivateKeyToScalar(priv); // same method executed in fromPrivateKey
|
|
126
115
|
const point = Point.fromPrivateKey(d); // P = d'⋅G; 0 < d' < n check is done inside
|
|
127
116
|
const scalar = point.hasEvenY() ? d : modN(-d); // d = d' if has_even_y(P), otherwise d = n-d'
|
|
128
117
|
return { point, scalar, bytes: pointToBytes(point) };
|
|
129
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* lift_x from BIP340. Convert 32-byte x coordinate to elliptic curve point.
|
|
121
|
+
* @returns valid point checked for being on-curve
|
|
122
|
+
*/
|
|
130
123
|
function lift_x(x) {
|
|
131
124
|
if (!fe(x))
|
|
132
125
|
throw new Error('bad x: need 0 < x < p'); // Fail if x ≥ p.
|
|
133
|
-
const
|
|
126
|
+
const xx = modP(x * x);
|
|
127
|
+
const c = modP(xx * x + BigInt(7)); // Let c = x³ + 7 mod p.
|
|
134
128
|
let y = sqrtMod(c); // Let y = c^(p+1)/4 mod p.
|
|
135
129
|
if (y % 2n !== 0n)
|
|
136
|
-
y = (
|
|
130
|
+
y = modP(-y); // Return the unique point P such that x(P) = x and
|
|
137
131
|
const p = new Point(x, y, _1n); // y(P) = y if y mod 2 = 0 or y(P) = p-y otherwise.
|
|
138
132
|
p.assertValidity();
|
|
139
133
|
return p;
|
|
140
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* Create tagged hash, convert it to bigint, reduce modulo-n.
|
|
137
|
+
*/
|
|
141
138
|
function challenge(...args) {
|
|
142
|
-
return modN((0, utils_js_1.bytesToNumberBE)(taggedHash(
|
|
139
|
+
return modN((0, utils_js_1.bytesToNumberBE)(taggedHash('BIP0340/challenge', ...args)));
|
|
143
140
|
}
|
|
144
|
-
|
|
141
|
+
/**
|
|
142
|
+
* Schnorr public key is just `x` coordinate of Point as per BIP340.
|
|
143
|
+
*/
|
|
145
144
|
function schnorrGetPublicKey(privateKey) {
|
|
146
145
|
return schnorrGetExtPubKey(privateKey).bytes; // d'=int(sk). Fail if d'=0 or d'≥n. Ret bytes(d'⋅G)
|
|
147
146
|
}
|
|
148
|
-
|
|
149
|
-
|
|
147
|
+
/**
|
|
148
|
+
* Creates Schnorr signature as per BIP340. Verifies itself before returning anything.
|
|
149
|
+
* auxRand is optional and is not the sole source of k generation: bad CSPRNG won't be dangerous.
|
|
150
|
+
*/
|
|
150
151
|
function schnorrSign(message, privateKey, auxRand = (0, utils_1.randomBytes)(32)) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
const
|
|
154
|
-
const
|
|
155
|
-
const
|
|
156
|
-
const t = numTo32b(d ^ (0, utils_js_1.bytesToNumberBE)(taggedHash(TAGS.aux, a))); // Let t be the byte-wise xor of bytes(d) and hash/aux(a)
|
|
157
|
-
const rand = taggedHash(TAGS.nonce, t, px, m); // Let rand = hash/nonce(t || bytes(P) || m)
|
|
152
|
+
const m = (0, utils_js_1.ensureBytes)('message', message);
|
|
153
|
+
const { bytes: px, scalar: d } = schnorrGetExtPubKey(privateKey); // checks for isWithinCurveOrder
|
|
154
|
+
const a = (0, utils_js_1.ensureBytes)('auxRand', auxRand, 32); // Auxiliary random data a: a 32-byte array
|
|
155
|
+
const t = numTo32b(d ^ (0, utils_js_1.bytesToNumberBE)(taggedHash('BIP0340/aux', a))); // Let t be the byte-wise xor of bytes(d) and hash/aux(a)
|
|
156
|
+
const rand = taggedHash('BIP0340/nonce', t, px, m); // Let rand = hash/nonce(t || bytes(P) || m)
|
|
158
157
|
const k_ = modN((0, utils_js_1.bytesToNumberBE)(rand)); // Let k' = int(rand) mod n
|
|
159
158
|
if (k_ === _0n)
|
|
160
159
|
throw new Error('sign failed: k is zero'); // Fail if k' = 0.
|
|
@@ -169,20 +168,22 @@ function schnorrSign(message, privateKey, auxRand = (0, utils_1.randomBytes)(32)
|
|
|
169
168
|
return sig;
|
|
170
169
|
}
|
|
171
170
|
/**
|
|
172
|
-
* Verifies Schnorr signature
|
|
171
|
+
* Verifies Schnorr signature.
|
|
172
|
+
* Will swallow errors & return false except for initial type validation of arguments.
|
|
173
173
|
*/
|
|
174
174
|
function schnorrVerify(signature, message, publicKey) {
|
|
175
|
+
const sig = (0, utils_js_1.ensureBytes)('signature', signature, 64);
|
|
176
|
+
const m = (0, utils_js_1.ensureBytes)('message', message);
|
|
177
|
+
const pub = (0, utils_js_1.ensureBytes)('publicKey', publicKey, 32);
|
|
175
178
|
try {
|
|
176
|
-
const P = lift_x(
|
|
177
|
-
const sig = (0, utils_js_1.ensureBytes)(signature, 64);
|
|
179
|
+
const P = lift_x((0, utils_js_1.bytesToNumberBE)(pub)); // P = lift_x(int(pk)); fail if that fails
|
|
178
180
|
const r = (0, utils_js_1.bytesToNumberBE)(sig.subarray(0, 32)); // Let r = int(sig[0:32]); fail if r ≥ p.
|
|
179
181
|
if (!fe(r))
|
|
180
182
|
return false;
|
|
181
183
|
const s = (0, utils_js_1.bytesToNumberBE)(sig.subarray(32, 64)); // Let s = int(sig[32:64]); fail if s ≥ n.
|
|
182
184
|
if (!ge(s))
|
|
183
185
|
return false;
|
|
184
|
-
const
|
|
185
|
-
const e = challenge(numTo32b(r), pointToBytes(P), m); // int(challenge(bytes(r)||bytes(P)||m)) mod n
|
|
186
|
+
const e = challenge(numTo32b(r), pointToBytes(P), m); // int(challenge(bytes(r)||bytes(P)||m))%n
|
|
186
187
|
const R = GmulAdd(P, s, modN(-e)); // R = s⋅G - e⋅P
|
|
187
188
|
if (!R || !R.hasEvenY() || R.toAffine().x !== r)
|
|
188
189
|
return false; // -eP == (n-e)P
|
|
@@ -197,6 +198,7 @@ exports.schnorr = {
|
|
|
197
198
|
sign: schnorrSign,
|
|
198
199
|
verify: schnorrVerify,
|
|
199
200
|
utils: {
|
|
201
|
+
randomPrivateKey: exports.secp256k1.utils.randomPrivateKey,
|
|
200
202
|
getExtendedPublicKey: schnorrGetExtPubKey,
|
|
201
203
|
lift_x,
|
|
202
204
|
pointToBytes,
|
|
@@ -240,7 +242,7 @@ const mapSWU = (0, weierstrass_js_1.mapToCurveSimpleSWU)(Fp, {
|
|
|
240
242
|
B: BigInt('1771'),
|
|
241
243
|
Z: Fp.create(BigInt('-11')),
|
|
242
244
|
});
|
|
243
|
-
|
|
245
|
+
_a = htf.createHasher(exports.secp256k1.ProjectivePoint, (scalars) => {
|
|
244
246
|
const { x, y } = mapSWU(Fp.create(scalars[0]));
|
|
245
247
|
return isoMap(x, y);
|
|
246
248
|
}, {
|
|
@@ -251,6 +253,5 @@ const { hashToCurve, encodeToCurve } = htf.hashToCurve(exports.secp256k1.Project
|
|
|
251
253
|
k: 128,
|
|
252
254
|
expand: 'xmd',
|
|
253
255
|
hash: sha256_1.sha256,
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
exports.encodeToCurve = encodeToCurve;
|
|
256
|
+
}), exports.hashToCurve = _a.hashToCurve, exports.encodeToCurve = _a.encod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E;QACpE,oEAAoE;QACpE,oEAAoE;KACrE;IACD,OAAO;IACP;QACE,oEAAoE;QACpE,oEAAoE;QACpE,oEAAoE;QACpE,oEAAoE,EAAE,SAAS;KAChF;CACF,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAA6B,CAClE,CAAC;AACF,MAAM,MAAM,GAAG,IAAA,oCAAmB,EAAC,EAAE,EAAE;IACrC,CAAC,EAAE,MAAM,CAAC,oEAAoE,CAAC;IAC/E,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC;IACjB,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;CAC5B,CAAC,CAAC;AACU,KAAiC,GAAG,CAAC,YAAY,CAC5D,iBAAS,CAAC,eAAe,EACzB,CAAC,OAAiB,EAAE,EAAE;IACpB,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/C,OAAO,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AACtB,CAAC,EACD;IACE,GAAG,EAAE,gCAAgC;IACrC,SAAS,EAAE,gCAAgC;IAC3C,CAAC,EAAE,EAAE,CAAC,KAAK;IACX,CAAC,EAAE,CAAC;IACJ,CAAC,EAAE,GAAG;IACN,MAAM,EAAE,KAAK;IACb,IAAI,EAAE,eAAM;CACb,CACF,EAfc,mBAAW,mBAAE,qBAAa,oBAevC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
2
|
+
import { hmac } from '@noble/hashes/hmac';
|
|
3
|
+
import { concatBytes, randomBytes } from '@noble/hashes/utils';
|
|
4
|
+
import { weierstrass, CurveType } from './abstract/weierstrass.js';
|
|
5
|
+
import { CHash } from './abstract/utils.js';
|
|
6
|
+
|
|
7
|
+
// connects noble-curves to noble-hashes
|
|
8
|
+
export function getHash(hash: CHash) {
|
|
9
|
+
return {
|
|
10
|
+
hash,
|
|
11
|
+
hmac: (key: Uint8Array, ...msgs: Uint8Array[]) => hmac(hash, key, concatBytes(...msgs)),
|
|
12
|
+
randomBytes,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
// Same API as @noble/hashes, with ability to create curve with custom hash
|
|
16
|
+
type CurveDef = Readonly<Omit<CurveType, 'hash' | 'hmac' | 'randomBytes'>>;
|
|
17
|
+
export function createCurve(curveDef: CurveDef, defHash: CHash) {
|
|
18
|
+
const create = (hash: CHash) => weierstrass({ ...curveDef, ...getHash(hash) });
|
|
19
|
+
return Object.freeze({ ...create(defHash), create });
|
|
20
|
+
}
|