@noble/curves 0.5.1 → 0.6.0
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 +49 -8
- package/lib/_shortw_utils.d.ts +11 -26
- package/lib/abstract/bls.d.ts +51 -35
- package/lib/abstract/bls.js +77 -139
- package/lib/abstract/{group.d.ts → curve.d.ts} +31 -1
- package/lib/abstract/{group.js → curve.js} +39 -2
- package/lib/abstract/edwards.d.ts +30 -81
- package/lib/abstract/edwards.js +225 -420
- package/lib/abstract/hash-to-curve.d.ts +25 -6
- package/lib/abstract/hash-to-curve.js +40 -12
- package/lib/abstract/modular.d.ts +20 -7
- package/lib/abstract/modular.js +80 -51
- package/lib/abstract/montgomery.js +3 -4
- package/lib/abstract/poseidon.d.ts +29 -0
- package/lib/abstract/poseidon.js +115 -0
- package/lib/abstract/utils.d.ts +5 -34
- package/lib/abstract/utils.js +23 -63
- package/lib/abstract/weierstrass.d.ts +56 -79
- package/lib/abstract/weierstrass.js +509 -641
- package/lib/bls12-381.d.ts +1 -0
- package/lib/bls12-381.js +75 -65
- package/lib/bn.js +1 -1
- package/lib/ed25519.d.ts +7 -5
- package/lib/ed25519.js +87 -84
- package/lib/ed448.d.ts +3 -0
- package/lib/ed448.js +88 -84
- package/lib/esm/abstract/bls.js +77 -139
- package/lib/esm/abstract/{group.js → curve.js} +37 -1
- package/lib/esm/abstract/edwards.js +223 -418
- package/lib/esm/abstract/hash-to-curve.js +38 -11
- package/lib/esm/abstract/modular.js +77 -50
- package/lib/esm/abstract/montgomery.js +4 -7
- package/lib/esm/abstract/poseidon.js +109 -0
- package/lib/esm/abstract/utils.js +21 -59
- package/lib/esm/abstract/weierstrass.js +508 -640
- package/lib/esm/bls12-381.js +86 -76
- package/lib/esm/bn.js +1 -1
- package/lib/esm/ed25519.js +85 -83
- package/lib/esm/ed448.js +86 -83
- package/lib/esm/jubjub.js +6 -5
- package/lib/esm/p256.js +11 -9
- package/lib/esm/p384.js +11 -9
- package/lib/esm/p521.js +13 -12
- package/lib/esm/secp256k1.js +118 -157
- package/lib/esm/stark.js +104 -39
- package/lib/jubjub.d.ts +3 -2
- package/lib/jubjub.js +6 -5
- package/lib/p192.d.ts +22 -52
- package/lib/p224.d.ts +22 -52
- package/lib/p256.d.ts +25 -52
- package/lib/p256.js +13 -10
- package/lib/p384.d.ts +25 -52
- package/lib/p384.js +13 -10
- package/lib/p521.d.ts +25 -52
- package/lib/p521.js +15 -13
- package/lib/secp256k1.d.ts +26 -42
- package/lib/secp256k1.js +118 -157
- package/lib/stark.d.ts +36 -21
- package/lib/stark.js +107 -39
- package/package.json +14 -9
package/lib/p521.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PrivKey } from './abstract/utils.js';
|
|
2
|
+
import * as htf from './abstract/hash-to-curve.js';
|
|
2
3
|
export declare const P521: Readonly<{
|
|
3
4
|
create: (hash: import("./abstract/utils.js").CHash) => import("./abstract/weierstrass.js").CurveFn;
|
|
4
5
|
CURVE: Readonly<{
|
|
@@ -24,41 +25,26 @@ export declare const P521: Readonly<{
|
|
|
24
25
|
k2: bigint;
|
|
25
26
|
};
|
|
26
27
|
} | undefined;
|
|
27
|
-
readonly isTorsionFree?: ((c: import("./abstract/weierstrass.js").
|
|
28
|
-
readonly clearCofactor?: ((c: import("./abstract/weierstrass.js").
|
|
29
|
-
readonly htfDefaults?: import("./abstract/hash-to-curve.js").htfOpts | undefined;
|
|
30
|
-
readonly mapToCurve?: ((scalar: bigint[]) => {
|
|
31
|
-
x: bigint;
|
|
32
|
-
y: bigint;
|
|
33
|
-
}) | undefined;
|
|
28
|
+
readonly isTorsionFree?: ((c: import("./abstract/weierstrass.js").ProjConstructor<bigint>, point: import("./abstract/weierstrass.js").ProjPointType<bigint>) => boolean) | undefined;
|
|
29
|
+
readonly clearCofactor?: ((c: import("./abstract/weierstrass.js").ProjConstructor<bigint>, point: import("./abstract/weierstrass.js").ProjPointType<bigint>) => import("./abstract/weierstrass.js").ProjPointType<bigint>) | undefined;
|
|
34
30
|
lowS: boolean;
|
|
35
31
|
readonly hash: import("./abstract/utils.js").CHash;
|
|
36
32
|
readonly hmac: (key: Uint8Array, ...messages: Uint8Array[]) => Uint8Array;
|
|
37
33
|
readonly randomBytes: (bytesLength?: number | undefined) => Uint8Array;
|
|
38
|
-
readonly
|
|
34
|
+
readonly bits2int?: ((bytes: Uint8Array) => bigint) | undefined;
|
|
35
|
+
readonly bits2int_modN?: ((bytes: Uint8Array) => bigint) | undefined;
|
|
39
36
|
}>;
|
|
40
37
|
getPublicKey: (privateKey: PrivKey, isCompressed?: boolean | undefined) => Uint8Array;
|
|
41
|
-
getSharedSecret: (privateA: PrivKey, publicB: import("./abstract/
|
|
42
|
-
sign: (msgHash: import("./abstract/utils.js").Hex, privKey: PrivKey, opts?:
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
} | undefined) => boolean;
|
|
49
|
-
Point: import("./abstract/weierstrass.js").PointConstructor<bigint>;
|
|
50
|
-
ProjectivePoint: import("./abstract/weierstrass.js").ProjectiveConstructor<bigint>;
|
|
38
|
+
getSharedSecret: (privateA: PrivKey, publicB: import("./abstract/utils.js").Hex, isCompressed?: boolean | undefined) => Uint8Array;
|
|
39
|
+
sign: (msgHash: import("./abstract/utils.js").Hex, privKey: PrivKey, opts?: import("./abstract/weierstrass.js").SignOpts | undefined) => import("./abstract/weierstrass.js").SignatureType;
|
|
40
|
+
verify: (signature: import("./abstract/utils.js").Hex | {
|
|
41
|
+
r: bigint;
|
|
42
|
+
s: bigint;
|
|
43
|
+
}, msgHash: import("./abstract/utils.js").Hex, publicKey: import("./abstract/utils.js").Hex, opts?: import("./abstract/weierstrass.js").VerOpts | undefined) => boolean;
|
|
44
|
+
ProjectivePoint: import("./abstract/weierstrass.js").ProjConstructor<bigint>;
|
|
51
45
|
Signature: import("./abstract/weierstrass.js").SignatureConstructor;
|
|
52
46
|
utils: {
|
|
53
|
-
mod: (a: bigint, b?: bigint | undefined) => bigint;
|
|
54
|
-
invert: (number: bigint, modulo?: bigint | undefined) => bigint;
|
|
55
|
-
_bigintToBytes: (num: bigint) => Uint8Array;
|
|
56
|
-
_bigintToString: (num: bigint) => string;
|
|
57
47
|
_normalizePrivateKey: (key: PrivKey) => bigint;
|
|
58
|
-
_normalizePublicKey: (publicKey: import("./abstract/weierstrass.js").PubKey) => import("./abstract/weierstrass.js").PointType<bigint>;
|
|
59
|
-
_isWithinCurveOrder: (num: bigint) => boolean;
|
|
60
|
-
_isValidFieldElement: (num: bigint) => boolean;
|
|
61
|
-
_weierstrassEquation: (x: bigint) => bigint;
|
|
62
48
|
isValidPrivateKey(privateKey: PrivKey): boolean;
|
|
63
49
|
hashToPrivateKey: (hash: import("./abstract/utils.js").Hex) => Uint8Array;
|
|
64
50
|
randomPrivateKey: () => Uint8Array;
|
|
@@ -89,43 +75,30 @@ export declare const secp521r1: Readonly<{
|
|
|
89
75
|
k2: bigint;
|
|
90
76
|
};
|
|
91
77
|
} | undefined;
|
|
92
|
-
readonly isTorsionFree?: ((c: import("./abstract/weierstrass.js").
|
|
93
|
-
readonly clearCofactor?: ((c: import("./abstract/weierstrass.js").
|
|
94
|
-
readonly htfDefaults?: import("./abstract/hash-to-curve.js").htfOpts | undefined;
|
|
95
|
-
readonly mapToCurve?: ((scalar: bigint[]) => {
|
|
96
|
-
x: bigint;
|
|
97
|
-
y: bigint;
|
|
98
|
-
}) | undefined;
|
|
78
|
+
readonly isTorsionFree?: ((c: import("./abstract/weierstrass.js").ProjConstructor<bigint>, point: import("./abstract/weierstrass.js").ProjPointType<bigint>) => boolean) | undefined;
|
|
79
|
+
readonly clearCofactor?: ((c: import("./abstract/weierstrass.js").ProjConstructor<bigint>, point: import("./abstract/weierstrass.js").ProjPointType<bigint>) => import("./abstract/weierstrass.js").ProjPointType<bigint>) | undefined;
|
|
99
80
|
lowS: boolean;
|
|
100
81
|
readonly hash: import("./abstract/utils.js").CHash;
|
|
101
82
|
readonly hmac: (key: Uint8Array, ...messages: Uint8Array[]) => Uint8Array;
|
|
102
83
|
readonly randomBytes: (bytesLength?: number | undefined) => Uint8Array;
|
|
103
|
-
readonly
|
|
84
|
+
readonly bits2int?: ((bytes: Uint8Array) => bigint) | undefined;
|
|
85
|
+
readonly bits2int_modN?: ((bytes: Uint8Array) => bigint) | undefined;
|
|
104
86
|
}>;
|
|
105
87
|
getPublicKey: (privateKey: PrivKey, isCompressed?: boolean | undefined) => Uint8Array;
|
|
106
|
-
getSharedSecret: (privateA: PrivKey, publicB: import("./abstract/
|
|
107
|
-
sign: (msgHash: import("./abstract/utils.js").Hex, privKey: PrivKey, opts?:
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
} | undefined) => boolean;
|
|
114
|
-
Point: import("./abstract/weierstrass.js").PointConstructor<bigint>;
|
|
115
|
-
ProjectivePoint: import("./abstract/weierstrass.js").ProjectiveConstructor<bigint>;
|
|
88
|
+
getSharedSecret: (privateA: PrivKey, publicB: import("./abstract/utils.js").Hex, isCompressed?: boolean | undefined) => Uint8Array;
|
|
89
|
+
sign: (msgHash: import("./abstract/utils.js").Hex, privKey: PrivKey, opts?: import("./abstract/weierstrass.js").SignOpts | undefined) => import("./abstract/weierstrass.js").SignatureType;
|
|
90
|
+
verify: (signature: import("./abstract/utils.js").Hex | {
|
|
91
|
+
r: bigint;
|
|
92
|
+
s: bigint;
|
|
93
|
+
}, msgHash: import("./abstract/utils.js").Hex, publicKey: import("./abstract/utils.js").Hex, opts?: import("./abstract/weierstrass.js").VerOpts | undefined) => boolean;
|
|
94
|
+
ProjectivePoint: import("./abstract/weierstrass.js").ProjConstructor<bigint>;
|
|
116
95
|
Signature: import("./abstract/weierstrass.js").SignatureConstructor;
|
|
117
96
|
utils: {
|
|
118
|
-
mod: (a: bigint, b?: bigint | undefined) => bigint;
|
|
119
|
-
invert: (number: bigint, modulo?: bigint | undefined) => bigint;
|
|
120
|
-
_bigintToBytes: (num: bigint) => Uint8Array;
|
|
121
|
-
_bigintToString: (num: bigint) => string;
|
|
122
97
|
_normalizePrivateKey: (key: PrivKey) => bigint;
|
|
123
|
-
_normalizePublicKey: (publicKey: import("./abstract/weierstrass.js").PubKey) => import("./abstract/weierstrass.js").PointType<bigint>;
|
|
124
|
-
_isWithinCurveOrder: (num: bigint) => boolean;
|
|
125
|
-
_isValidFieldElement: (num: bigint) => boolean;
|
|
126
|
-
_weierstrassEquation: (x: bigint) => bigint;
|
|
127
98
|
isValidPrivateKey(privateKey: PrivKey): boolean;
|
|
128
99
|
hashToPrivateKey: (hash: import("./abstract/utils.js").Hex) => Uint8Array;
|
|
129
100
|
randomPrivateKey: () => Uint8Array;
|
|
130
101
|
};
|
|
131
102
|
}>;
|
|
103
|
+
declare const hashToCurve: (msg: import("./abstract/utils.js").Hex, options?: htf.htfBasicOpts | undefined) => htf.H2CPoint<bigint>, encodeToCurve: (msg: import("./abstract/utils.js").Hex, options?: htf.htfBasicOpts | undefined) => htf.H2CPoint<bigint>;
|
|
104
|
+
export { hashToCurve, encodeToCurve };
|
package/lib/p521.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.secp521r1 = exports.P521 = void 0;
|
|
3
|
+
exports.encodeToCurve = exports.hashToCurve = exports.secp521r1 = exports.P521 = void 0;
|
|
4
4
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
5
5
|
const _shortw_utils_js_1 = require("./_shortw_utils.js");
|
|
6
6
|
const sha512_1 = require("@noble/hashes/sha512");
|
|
7
7
|
const utils_js_1 = require("./abstract/utils.js");
|
|
8
8
|
const modular_js_1 = require("./abstract/modular.js");
|
|
9
9
|
const weierstrass_js_1 = require("./abstract/weierstrass.js");
|
|
10
|
+
const htf = require("./abstract/hash-to-curve.js");
|
|
10
11
|
// NIST secp521r1 aka P521
|
|
11
12
|
// Note that it's 521, which differs from 512 of its hash function.
|
|
12
13
|
// https://www.secg.org/sec2-v2.pdf, https://neuromancer.sk/std/nist/P-521
|
|
@@ -35,8 +36,7 @@ exports.P521 = (0, _shortw_utils_js_1.createCurve)({
|
|
|
35
36
|
Gy: BigInt('0x011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650'),
|
|
36
37
|
h: BigInt(1),
|
|
37
38
|
lowS: false,
|
|
38
|
-
// P521 keys could be 130, 131, 132 bytes
|
|
39
|
-
// We ensure all keys are 132 bytes.
|
|
39
|
+
// P521 keys could be 130, 131, 132 bytes. We normalize to 132 bytes.
|
|
40
40
|
// Does not replace validation; invalid keys would still be rejected.
|
|
41
41
|
normalizePrivateKey(key) {
|
|
42
42
|
if (typeof key === 'bigint')
|
|
@@ -46,16 +46,18 @@ exports.P521 = (0, _shortw_utils_js_1.createCurve)({
|
|
|
46
46
|
if (typeof key !== 'string' || !([130, 131, 132].includes(key.length))) {
|
|
47
47
|
throw new Error('Invalid key');
|
|
48
48
|
}
|
|
49
|
-
return key.padStart(66 * 2, '0');
|
|
50
|
-
},
|
|
51
|
-
mapToCurve: (scalars) => mapSWU(scalars[0]),
|
|
52
|
-
htfDefaults: {
|
|
53
|
-
DST: 'P521_XMD:SHA-512_SSWU_RO_',
|
|
54
|
-
p: Fp.ORDER,
|
|
55
|
-
m: 1,
|
|
56
|
-
k: 256,
|
|
57
|
-
expand: 'xmd',
|
|
58
|
-
hash: sha512_1.sha512,
|
|
49
|
+
return key.padStart(66 * 2, '0'); // ensure it's always 132 bytes
|
|
59
50
|
},
|
|
60
51
|
}, sha512_1.sha512);
|
|
61
52
|
exports.secp521r1 = exports.P521;
|
|
53
|
+
const { hashToCurve, encodeToCurve } = htf.hashToCurve(exports.secp521r1.ProjectivePoint, (scalars) => mapSWU(scalars[0]), {
|
|
54
|
+
DST: 'P521_XMD:SHA-512_SSWU_RO_',
|
|
55
|
+
encodeDST: 'P521_XMD:SHA-512_SSWU_NU_',
|
|
56
|
+
p: Fp.ORDER,
|
|
57
|
+
m: 1,
|
|
58
|
+
k: 256,
|
|
59
|
+
expand: 'xmd',
|
|
60
|
+
hash: sha512_1.sha512,
|
|
61
|
+
});
|
|
62
|
+
exports.hashToCurve = hashToCurve;
|
|
63
|
+
exports.encodeToCurve = encodeToCurve;
|
package/lib/secp256k1.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { PointType } from './abstract/weierstrass.js';
|
|
2
|
-
import { Hex, PrivKey } from './abstract/utils.js';
|
|
1
|
+
import { ProjPointType as PointType } from './abstract/weierstrass.js';
|
|
2
|
+
import { Hex, bytesToNumberBE as bytesToNum, PrivKey } from './abstract/utils.js';
|
|
3
|
+
import * as htf from './abstract/hash-to-curve.js';
|
|
3
4
|
export declare const secp256k1: Readonly<{
|
|
4
5
|
create: (hash: import("./abstract/utils.js").CHash) => import("./abstract/weierstrass.js").CurveFn;
|
|
5
6
|
CURVE: Readonly<{
|
|
@@ -25,56 +26,34 @@ export declare const secp256k1: Readonly<{
|
|
|
25
26
|
k2: bigint;
|
|
26
27
|
};
|
|
27
28
|
} | undefined;
|
|
28
|
-
readonly isTorsionFree?: ((c: import("./abstract/weierstrass.js").
|
|
29
|
-
readonly clearCofactor?: ((c: import("./abstract/weierstrass.js").
|
|
30
|
-
readonly htfDefaults?: import("./abstract/hash-to-curve.js").htfOpts | undefined;
|
|
31
|
-
readonly mapToCurve?: ((scalar: bigint[]) => {
|
|
32
|
-
x: bigint;
|
|
33
|
-
y: bigint;
|
|
34
|
-
}) | undefined;
|
|
29
|
+
readonly isTorsionFree?: ((c: import("./abstract/weierstrass.js").ProjConstructor<bigint>, point: PointType<bigint>) => boolean) | undefined;
|
|
30
|
+
readonly clearCofactor?: ((c: import("./abstract/weierstrass.js").ProjConstructor<bigint>, point: PointType<bigint>) => PointType<bigint>) | undefined;
|
|
35
31
|
lowS: boolean;
|
|
36
32
|
readonly hash: import("./abstract/utils.js").CHash;
|
|
37
33
|
readonly hmac: (key: Uint8Array, ...messages: Uint8Array[]) => Uint8Array;
|
|
38
34
|
readonly randomBytes: (bytesLength?: number | undefined) => Uint8Array;
|
|
39
|
-
readonly
|
|
35
|
+
readonly bits2int?: ((bytes: Uint8Array) => bigint) | undefined;
|
|
36
|
+
readonly bits2int_modN?: ((bytes: Uint8Array) => bigint) | undefined;
|
|
40
37
|
}>;
|
|
41
38
|
getPublicKey: (privateKey: PrivKey, isCompressed?: boolean | undefined) => Uint8Array;
|
|
42
|
-
getSharedSecret: (privateA: PrivKey, publicB:
|
|
43
|
-
sign: (msgHash: Hex, privKey: PrivKey, opts?:
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
} | undefined) => boolean;
|
|
50
|
-
Point: import("./abstract/weierstrass.js").PointConstructor<bigint>;
|
|
51
|
-
ProjectivePoint: import("./abstract/weierstrass.js").ProjectiveConstructor<bigint>;
|
|
39
|
+
getSharedSecret: (privateA: PrivKey, publicB: Hex, isCompressed?: boolean | undefined) => Uint8Array;
|
|
40
|
+
sign: (msgHash: Hex, privKey: PrivKey, opts?: import("./abstract/weierstrass.js").SignOpts | undefined) => import("./abstract/weierstrass.js").SignatureType;
|
|
41
|
+
verify: (signature: Hex | {
|
|
42
|
+
r: bigint;
|
|
43
|
+
s: bigint;
|
|
44
|
+
}, msgHash: Hex, publicKey: Hex, opts?: import("./abstract/weierstrass.js").VerOpts | undefined) => boolean;
|
|
45
|
+
ProjectivePoint: import("./abstract/weierstrass.js").ProjConstructor<bigint>;
|
|
52
46
|
Signature: import("./abstract/weierstrass.js").SignatureConstructor;
|
|
53
47
|
utils: {
|
|
54
|
-
mod: (a: bigint, b?: bigint | undefined) => bigint;
|
|
55
|
-
invert: (number: bigint, modulo?: bigint | undefined) => bigint;
|
|
56
|
-
_bigintToBytes: (num: bigint) => Uint8Array;
|
|
57
|
-
_bigintToString: (num: bigint) => string;
|
|
58
48
|
_normalizePrivateKey: (key: PrivKey) => bigint;
|
|
59
|
-
_normalizePublicKey: (publicKey: import("./abstract/weierstrass.js").PubKey) => PointType<bigint>;
|
|
60
|
-
_isWithinCurveOrder: (num: bigint) => boolean;
|
|
61
|
-
_isValidFieldElement: (num: bigint) => boolean;
|
|
62
|
-
_weierstrassEquation: (x: bigint) => bigint;
|
|
63
49
|
isValidPrivateKey(privateKey: PrivKey): boolean;
|
|
64
50
|
hashToPrivateKey: (hash: Hex) => Uint8Array;
|
|
65
51
|
randomPrivateKey: () => Uint8Array;
|
|
66
52
|
};
|
|
67
53
|
}>;
|
|
68
|
-
|
|
69
|
-
declare
|
|
70
|
-
|
|
71
|
-
readonly s: bigint;
|
|
72
|
-
constructor(r: bigint, s: bigint);
|
|
73
|
-
static fromHex(hex: Hex): SchnorrSignature;
|
|
74
|
-
assertValidity(): void;
|
|
75
|
-
toHex(): string;
|
|
76
|
-
toRawBytes(): Uint8Array;
|
|
77
|
-
}
|
|
54
|
+
declare function taggedHash(tag: string, ...messages: Uint8Array[]): Uint8Array;
|
|
55
|
+
declare function lift_x(x: bigint): PointType<bigint>;
|
|
56
|
+
declare function schnorrGetPublicKey(privateKey: PrivKey): Uint8Array;
|
|
78
57
|
/**
|
|
79
58
|
* Synchronously creates Schnorr signature. Improved security: verifies itself before
|
|
80
59
|
* producing an output.
|
|
@@ -82,15 +61,20 @@ declare class SchnorrSignature {
|
|
|
82
61
|
* @param privateKey private key
|
|
83
62
|
* @param auxRand random bytes that would be added to k. Bad RNG won't break it.
|
|
84
63
|
*/
|
|
85
|
-
declare function schnorrSign(message: Hex, privateKey:
|
|
64
|
+
declare function schnorrSign(message: Hex, privateKey: Hex, auxRand?: Hex): Uint8Array;
|
|
86
65
|
/**
|
|
87
66
|
* Verifies Schnorr signature synchronously.
|
|
88
67
|
*/
|
|
89
68
|
declare function schnorrVerify(signature: Hex, message: Hex, publicKey: Hex): boolean;
|
|
90
69
|
export declare const schnorr: {
|
|
91
|
-
|
|
92
|
-
getPublicKey: (privateKey: PrivKey) => Uint8Array;
|
|
70
|
+
getPublicKey: typeof schnorrGetPublicKey;
|
|
93
71
|
sign: typeof schnorrSign;
|
|
94
72
|
verify: typeof schnorrVerify;
|
|
73
|
+
utils: {
|
|
74
|
+
lift_x: typeof lift_x;
|
|
75
|
+
int: typeof bytesToNum;
|
|
76
|
+
taggedHash: typeof taggedHash;
|
|
77
|
+
};
|
|
95
78
|
};
|
|
96
|
-
|
|
79
|
+
declare const hashToCurve: (msg: Hex, options?: htf.htfBasicOpts | undefined) => htf.H2CPoint<bigint>, encodeToCurve: (msg: Hex, options?: htf.htfBasicOpts | undefined) => htf.H2CPoint<bigint>;
|
|
80
|
+
export { hashToCurve, encodeToCurve };
|
package/lib/secp256k1.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.encodeToCurve = exports.hashToCurve = exports.schnorr = exports.secp256k1 = void 0;
|
|
4
4
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
5
5
|
const sha256_1 = require("@noble/hashes/sha256");
|
|
6
6
|
const modular_js_1 = require("./abstract/modular.js");
|
|
@@ -8,12 +8,10 @@ const _shortw_utils_js_1 = require("./_shortw_utils.js");
|
|
|
8
8
|
const weierstrass_js_1 = require("./abstract/weierstrass.js");
|
|
9
9
|
const utils_js_1 = require("./abstract/utils.js");
|
|
10
10
|
const utils_1 = require("@noble/hashes/utils");
|
|
11
|
-
const
|
|
11
|
+
const htf = require("./abstract/hash-to-curve.js");
|
|
12
12
|
/**
|
|
13
|
-
* secp256k1 belongs to Koblitz curves: it has
|
|
14
|
-
*
|
|
15
|
-
* Endomorphism improves efficiency:
|
|
16
|
-
* Uses 2x less RAM, speeds up precomputation by 2x and ECDH / sign key recovery by 20%.
|
|
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%.
|
|
17
15
|
* Should always be used for Projective's double-and-add multiplication.
|
|
18
16
|
* For affines cached multiplication, it trades off 1/2 init time & 1/3 ram for 20% perf hit.
|
|
19
17
|
* https://gist.github.com/paulmillr/eb670806793e84df628a7c434a873066
|
|
@@ -24,10 +22,7 @@ const _1n = BigInt(1);
|
|
|
24
22
|
const _2n = BigInt(2);
|
|
25
23
|
const divNearest = (a, b) => (a + b / _2n) / b;
|
|
26
24
|
/**
|
|
27
|
-
*
|
|
28
|
-
* To calculate √y, we need to exponentiate it to a very big number:
|
|
29
|
-
* `y² = x³ + ax + b; y = y² ^ (p+1)/4`
|
|
30
|
-
* We are unwrapping the loop and multiplying it bit-by-bit.
|
|
25
|
+
* √n = n^((p+1)/4) for fields p = 3 mod 4. We unwrap the loop and multiply bit-by-bit.
|
|
31
26
|
* (P+1n/4n).toString(2) would produce bits [223x 1, 0, 22x 1, 4x 0, 11, 00]
|
|
32
27
|
*/
|
|
33
28
|
function sqrtMod(y) {
|
|
@@ -50,45 +45,11 @@ function sqrtMod(y) {
|
|
|
50
45
|
const t1 = ((0, modular_js_1.pow2)(b223, _23n, P) * b22) % P;
|
|
51
46
|
const t2 = ((0, modular_js_1.pow2)(t1, _6n, P) * b2) % P;
|
|
52
47
|
const root = (0, modular_js_1.pow2)(t2, _2n, P);
|
|
53
|
-
if (!Fp.
|
|
48
|
+
if (!Fp.eql(Fp.sqr(root), y))
|
|
54
49
|
throw new Error('Cannot find square root');
|
|
55
50
|
return root;
|
|
56
51
|
}
|
|
57
52
|
const Fp = (0, modular_js_1.Fp)(secp256k1P, undefined, undefined, { sqrt: sqrtMod });
|
|
58
|
-
const isoMap = (0, hash_to_curve_js_1.isogenyMap)(Fp, [
|
|
59
|
-
// xNum
|
|
60
|
-
[
|
|
61
|
-
'0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa8c7',
|
|
62
|
-
'0x7d3d4c80bc321d5b9f315cea7fd44c5d595d2fc0bf63b92dfff1044f17c6581',
|
|
63
|
-
'0x534c328d23f234e6e2a413deca25caece4506144037c40314ecbd0b53d9dd262',
|
|
64
|
-
'0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa88c',
|
|
65
|
-
],
|
|
66
|
-
// xDen
|
|
67
|
-
[
|
|
68
|
-
'0xd35771193d94918a9ca34ccbb7b640dd86cd409542f8487d9fe6b745781eb49b',
|
|
69
|
-
'0xedadc6f64383dc1df7c4b2d51b54225406d36b641f5e41bbc52a56612a8c6d14',
|
|
70
|
-
'0x0000000000000000000000000000000000000000000000000000000000000001', // LAST 1
|
|
71
|
-
],
|
|
72
|
-
// yNum
|
|
73
|
-
[
|
|
74
|
-
'0x4bda12f684bda12f684bda12f684bda12f684bda12f684bda12f684b8e38e23c',
|
|
75
|
-
'0xc75e0c32d5cb7c0fa9d0a54b12a0a6d5647ab046d686da6fdffc90fc201d71a3',
|
|
76
|
-
'0x29a6194691f91a73715209ef6512e576722830a201be2018a765e85a9ecee931',
|
|
77
|
-
'0x2f684bda12f684bda12f684bda12f684bda12f684bda12f684bda12f38e38d84',
|
|
78
|
-
],
|
|
79
|
-
// yDen
|
|
80
|
-
[
|
|
81
|
-
'0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffff93b',
|
|
82
|
-
'0x7a06534bb8bdb49fd5e9e6632722c2989467c1bfc8e8d978dfb425d2685c2573',
|
|
83
|
-
'0x6484aa716545ca2cf3a70c3fa8fe337e0a3d21162f0d6299a7bf8192bfd2a76f',
|
|
84
|
-
'0x0000000000000000000000000000000000000000000000000000000000000001', // LAST 1
|
|
85
|
-
],
|
|
86
|
-
].map((i) => i.map((j) => BigInt(j))));
|
|
87
|
-
const mapSWU = (0, weierstrass_js_1.mapToCurveSimpleSWU)(Fp, {
|
|
88
|
-
A: BigInt('0x3f8731abdd661adca08a5558f0f5d272e953d363cb6f0e5d405447c01a444533'),
|
|
89
|
-
B: BigInt('1771'),
|
|
90
|
-
Z: Fp.create(BigInt('-11')),
|
|
91
|
-
});
|
|
92
53
|
exports.secp256k1 = (0, _shortw_utils_js_1.createCurve)({
|
|
93
54
|
// Params: a, b
|
|
94
55
|
// Seem to be rigid https://bitcointalk.org/index.php?topic=289795.msg3183975#msg3183975
|
|
@@ -114,7 +75,7 @@ exports.secp256k1 = (0, _shortw_utils_js_1.createCurve)({
|
|
|
114
75
|
const b1 = -_1n * BigInt('0xe4437ed6010e88286f547fa90abfe4c3');
|
|
115
76
|
const a2 = BigInt('0x114ca50f7a8e2f3f657c1108d9d44cfd8');
|
|
116
77
|
const b2 = a1;
|
|
117
|
-
const POW_2_128 = BigInt('0x100000000000000000000000000000000');
|
|
78
|
+
const POW_2_128 = BigInt('0x100000000000000000000000000000000'); // (2n**128n).toString(16)
|
|
118
79
|
const c1 = divNearest(b2 * k, n);
|
|
119
80
|
const c2 = divNearest(-b1 * k, n);
|
|
120
81
|
let k1 = (0, modular_js_1.mod)(k - c1 * a1 - c2 * a2, n);
|
|
@@ -131,53 +92,13 @@ exports.secp256k1 = (0, _shortw_utils_js_1.createCurve)({
|
|
|
131
92
|
return { k1neg, k1, k2neg, k2 };
|
|
132
93
|
},
|
|
133
94
|
},
|
|
134
|
-
mapToCurve: (scalars) => {
|
|
135
|
-
const { x, y } = mapSWU(Fp.create(scalars[0]));
|
|
136
|
-
return isoMap(x, y);
|
|
137
|
-
},
|
|
138
|
-
htfDefaults: {
|
|
139
|
-
DST: 'secp256k1_XMD:SHA-256_SSWU_RO_',
|
|
140
|
-
p: Fp.ORDER,
|
|
141
|
-
m: 1,
|
|
142
|
-
k: 128,
|
|
143
|
-
expand: 'xmd',
|
|
144
|
-
hash: sha256_1.sha256,
|
|
145
|
-
},
|
|
146
95
|
}, sha256_1.sha256);
|
|
147
|
-
// Schnorr
|
|
96
|
+
// Schnorr signatures are superior to ECDSA from above.
|
|
97
|
+
// Below is Schnorr-specific code as per BIP0340.
|
|
98
|
+
// https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki
|
|
148
99
|
const _0n = BigInt(0);
|
|
149
|
-
const
|
|
150
|
-
const
|
|
151
|
-
const normalizePrivateKey = exports.secp256k1.utils._normalizePrivateKey;
|
|
152
|
-
// TODO: export?
|
|
153
|
-
function normalizePublicKey(publicKey) {
|
|
154
|
-
if (publicKey instanceof exports.secp256k1.Point) {
|
|
155
|
-
publicKey.assertValidity();
|
|
156
|
-
return publicKey;
|
|
157
|
-
}
|
|
158
|
-
else {
|
|
159
|
-
const bytes = (0, utils_js_1.ensureBytes)(publicKey);
|
|
160
|
-
// Schnorr is 32 bytes
|
|
161
|
-
if (bytes.length === 32) {
|
|
162
|
-
const x = (0, utils_js_1.bytesToNumberBE)(bytes);
|
|
163
|
-
if (!isValidFieldElement(x))
|
|
164
|
-
throw new Error('Point is not on curve');
|
|
165
|
-
const y2 = exports.secp256k1.utils._weierstrassEquation(x); // y² = x³ + ax + b
|
|
166
|
-
let y = sqrtMod(y2); // y = y² ^ (p+1)/4
|
|
167
|
-
const isYOdd = (y & _1n) === _1n;
|
|
168
|
-
// Schnorr
|
|
169
|
-
if (isYOdd)
|
|
170
|
-
y = exports.secp256k1.CURVE.Fp.negate(y);
|
|
171
|
-
const point = new exports.secp256k1.Point(x, y);
|
|
172
|
-
point.assertValidity();
|
|
173
|
-
return point;
|
|
174
|
-
}
|
|
175
|
-
// Do we need that in schnorr at all?
|
|
176
|
-
return exports.secp256k1.Point.fromHex(publicKey);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
const isWithinCurveOrder = exports.secp256k1.utils._isWithinCurveOrder;
|
|
180
|
-
const isValidFieldElement = exports.secp256k1.utils._isValidFieldElement;
|
|
100
|
+
const fe = (x) => typeof x === 'bigint' && _0n < x && x < secp256k1P;
|
|
101
|
+
const ge = (x) => typeof x === 'bigint' && _0n < x && x < secp256k1N;
|
|
181
102
|
const TAGS = {
|
|
182
103
|
challenge: 'BIP0340/challenge',
|
|
183
104
|
aux: 'BIP0340/aux',
|
|
@@ -194,45 +115,38 @@ function taggedHash(tag, ...messages) {
|
|
|
194
115
|
}
|
|
195
116
|
return (0, sha256_1.sha256)((0, utils_js_1.concatBytes)(tagP, ...messages));
|
|
196
117
|
}
|
|
197
|
-
exports.taggedHash = taggedHash;
|
|
198
118
|
const toRawX = (point) => point.toRawBytes(true).slice(1);
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
// Do we need this at all for Schnorr?
|
|
205
|
-
class SchnorrSignature {
|
|
206
|
-
constructor(r, s) {
|
|
207
|
-
this.r = r;
|
|
208
|
-
this.s = s;
|
|
209
|
-
this.assertValidity();
|
|
210
|
-
}
|
|
211
|
-
static fromHex(hex) {
|
|
212
|
-
const bytes = (0, utils_js_1.ensureBytes)(hex);
|
|
213
|
-
if (bytes.length !== 64)
|
|
214
|
-
throw new TypeError(`SchnorrSignature.fromHex: expected 64 bytes, not ${bytes.length}`);
|
|
215
|
-
const r = (0, utils_js_1.bytesToNumberBE)(bytes.subarray(0, 32));
|
|
216
|
-
const s = (0, utils_js_1.bytesToNumberBE)(bytes.subarray(32, 64));
|
|
217
|
-
return new SchnorrSignature(r, s);
|
|
218
|
-
}
|
|
219
|
-
assertValidity() {
|
|
220
|
-
const { r, s } = this;
|
|
221
|
-
if (!isValidFieldElement(r) || !isWithinCurveOrder(s))
|
|
222
|
-
throw new Error('Invalid signature');
|
|
223
|
-
}
|
|
224
|
-
toHex() {
|
|
225
|
-
return numTo32bStr(this.r) + numTo32bStr(this.s);
|
|
226
|
-
}
|
|
227
|
-
toRawBytes() {
|
|
228
|
-
return (0, utils_js_1.hexToBytes)(this.toHex());
|
|
229
|
-
}
|
|
230
|
-
}
|
|
119
|
+
const numTo32b = (n) => (0, utils_js_1.numberToBytesBE)(n, 32);
|
|
120
|
+
const modN = (x) => (0, modular_js_1.mod)(x, secp256k1N);
|
|
121
|
+
const _Point = exports.secp256k1.ProjectivePoint;
|
|
122
|
+
const Gmul = (priv) => _Point.fromPrivateKey(priv);
|
|
123
|
+
const GmulAdd = (Q, a, b) => _Point.BASE.multiplyAndAddUnsafe(Q, a, b);
|
|
231
124
|
function schnorrGetScalar(priv) {
|
|
232
|
-
|
|
233
|
-
|
|
125
|
+
// Let d' = int(sk)
|
|
126
|
+
// Fail if d' = 0 or d' ≥ n
|
|
127
|
+
// Let P = d'⋅G
|
|
128
|
+
// Let d = d' if has_even_y(P), otherwise let d = n - d' .
|
|
129
|
+
const point = Gmul(priv);
|
|
130
|
+
const scalar = point.hasEvenY() ? priv : modN(-priv);
|
|
234
131
|
return { point, scalar, x: toRawX(point) };
|
|
235
132
|
}
|
|
133
|
+
function lift_x(x) {
|
|
134
|
+
if (!fe(x))
|
|
135
|
+
throw new Error('bad x: need 0 < x < p'); // Fail if x ≥ p.
|
|
136
|
+
const c = (0, modular_js_1.mod)(x * x * x + BigInt(7), secp256k1P); // Let c = x³ + 7 mod p.
|
|
137
|
+
let y = sqrtMod(c); // Let y = c^(p+1)/4 mod p.
|
|
138
|
+
if (y % 2n !== 0n)
|
|
139
|
+
y = (0, modular_js_1.mod)(-y, secp256k1P); // Return the unique point P such that x(P) = x and
|
|
140
|
+
const p = new _Point(x, y, _1n); // y(P) = y if y mod 2 = 0 or y(P) = p-y otherwise.
|
|
141
|
+
p.assertValidity();
|
|
142
|
+
return p;
|
|
143
|
+
}
|
|
144
|
+
function challenge(...args) {
|
|
145
|
+
return modN((0, utils_js_1.bytesToNumberBE)(taggedHash(TAGS.challenge, ...args)));
|
|
146
|
+
}
|
|
147
|
+
function schnorrGetPublicKey(privateKey) {
|
|
148
|
+
return toRawX(Gmul(privateKey)); // Let d' = int(sk). Fail if d' = 0 or d' ≥ n. Return bytes(d'⋅G)
|
|
149
|
+
}
|
|
236
150
|
/**
|
|
237
151
|
* Synchronously creates Schnorr signature. Improved security: verifies itself before
|
|
238
152
|
* producing an output.
|
|
@@ -242,23 +156,23 @@ function schnorrGetScalar(priv) {
|
|
|
242
156
|
*/
|
|
243
157
|
function schnorrSign(message, privateKey, auxRand = (0, utils_1.randomBytes)(32)) {
|
|
244
158
|
if (message == null)
|
|
245
|
-
throw new
|
|
159
|
+
throw new Error(`sign: Expected valid message, not "${message}"`);
|
|
246
160
|
const m = (0, utils_js_1.ensureBytes)(message);
|
|
247
161
|
// checks for isWithinCurveOrder
|
|
248
|
-
const { x: px, scalar: d } = schnorrGetScalar(
|
|
249
|
-
const
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
const
|
|
253
|
-
const
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
const
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
162
|
+
const { x: px, scalar: d } = schnorrGetScalar((0, utils_js_1.bytesToNumberBE)((0, utils_js_1.ensureBytes)(privateKey, 32)));
|
|
163
|
+
const a = (0, utils_js_1.ensureBytes)(auxRand, 32); // Auxiliary random data a: a 32-byte array
|
|
164
|
+
// TODO: replace with proper xor?
|
|
165
|
+
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)
|
|
166
|
+
const rand = taggedHash(TAGS.nonce, t, px, m); // Let rand = hash/nonce(t || bytes(P) || m)
|
|
167
|
+
const k_ = modN((0, utils_js_1.bytesToNumberBE)(rand)); // Let k' = int(rand) mod n
|
|
168
|
+
if (k_ === _0n)
|
|
169
|
+
throw new Error('sign failed: k is zero'); // Fail if k' = 0.
|
|
170
|
+
const { point: R, x: rx, scalar: k } = schnorrGetScalar(k_); // Let R = k'⋅G.
|
|
171
|
+
const e = challenge(rx, px, m); // Let e = int(hash/challenge(bytes(R) || bytes(P) || m)) mod n.
|
|
172
|
+
const sig = new Uint8Array(64); // Let sig = bytes(R) || bytes((k + ed) mod n).
|
|
173
|
+
sig.set(numTo32b(R.px), 0);
|
|
174
|
+
sig.set(numTo32b(modN(k + e * d)), 32);
|
|
175
|
+
// If Verify(bytes(P), m, sig) (see below) returns failure, abort
|
|
262
176
|
if (!schnorrVerify(sig, m, px))
|
|
263
177
|
throw new Error('sign: Invalid signature produced');
|
|
264
178
|
return sig;
|
|
@@ -268,30 +182,77 @@ function schnorrSign(message, privateKey, auxRand = (0, utils_1.randomBytes)(32)
|
|
|
268
182
|
*/
|
|
269
183
|
function schnorrVerify(signature, message, publicKey) {
|
|
270
184
|
try {
|
|
271
|
-
const
|
|
272
|
-
const sig =
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
const
|
|
277
|
-
|
|
278
|
-
const e = schnorrChallengeFinalize(taggedHash(TAGS.challenge, numTo32b(r), toRawX(P), m));
|
|
279
|
-
// Finalize
|
|
280
|
-
// R = s⋅G - e⋅P
|
|
281
|
-
// -eP == (n-e)P
|
|
282
|
-
const R = exports.secp256k1.Point.BASE.multiplyAndAddUnsafe(P, normalizePrivateKey(s), (0, modular_js_1.mod)(-e, exports.secp256k1.CURVE.n));
|
|
283
|
-
if (!R || !R.hasEvenY() || R.x !== r)
|
|
185
|
+
const P = lift_x((0, utils_js_1.bytesToNumberBE)((0, utils_js_1.ensureBytes)(publicKey, 32))); // P = lift_x(int(pk)); fail if that fails
|
|
186
|
+
const sig = (0, utils_js_1.ensureBytes)(signature, 64);
|
|
187
|
+
const r = (0, utils_js_1.bytesToNumberBE)(sig.subarray(0, 32)); // Let r = int(sig[0:32]); fail if r ≥ p.
|
|
188
|
+
if (!fe(r))
|
|
189
|
+
return false;
|
|
190
|
+
const s = (0, utils_js_1.bytesToNumberBE)(sig.subarray(32, 64)); // Let s = int(sig[32:64]); fail if s ≥ n.
|
|
191
|
+
if (!ge(s))
|
|
284
192
|
return false;
|
|
285
|
-
|
|
193
|
+
const m = (0, utils_js_1.ensureBytes)(message);
|
|
194
|
+
const e = challenge(numTo32b(r), toRawX(P), m); // int(challenge(bytes(r)||bytes(P)||m)) mod n
|
|
195
|
+
const R = GmulAdd(P, s, modN(-e)); // R = s⋅G - e⋅P
|
|
196
|
+
if (!R || !R.hasEvenY() || R.toAffine().x !== r)
|
|
197
|
+
return false; // -eP == (n-e)P
|
|
198
|
+
return true; // Fail if is_infinite(R) / not has_even_y(R) / x(R) ≠ r.
|
|
286
199
|
}
|
|
287
200
|
catch (error) {
|
|
288
201
|
return false;
|
|
289
202
|
}
|
|
290
203
|
}
|
|
291
204
|
exports.schnorr = {
|
|
292
|
-
Signature: SchnorrSignature,
|
|
293
205
|
// Schnorr's pubkey is just `x` of Point (BIP340)
|
|
294
|
-
getPublicKey:
|
|
206
|
+
getPublicKey: schnorrGetPublicKey,
|
|
295
207
|
sign: schnorrSign,
|
|
296
208
|
verify: schnorrVerify,
|
|
209
|
+
utils: { lift_x, int: utils_js_1.bytesToNumberBE, taggedHash },
|
|
297
210
|
};
|
|
211
|
+
const isoMap = htf.isogenyMap(Fp, [
|
|
212
|
+
// xNum
|
|
213
|
+
[
|
|
214
|
+
'0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa8c7',
|
|
215
|
+
'0x7d3d4c80bc321d5b9f315cea7fd44c5d595d2fc0bf63b92dfff1044f17c6581',
|
|
216
|
+
'0x534c328d23f234e6e2a413deca25caece4506144037c40314ecbd0b53d9dd262',
|
|
217
|
+
'0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa88c',
|
|
218
|
+
],
|
|
219
|
+
// xDen
|
|
220
|
+
[
|
|
221
|
+
'0xd35771193d94918a9ca34ccbb7b640dd86cd409542f8487d9fe6b745781eb49b',
|
|
222
|
+
'0xedadc6f64383dc1df7c4b2d51b54225406d36b641f5e41bbc52a56612a8c6d14',
|
|
223
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001', // LAST 1
|
|
224
|
+
],
|
|
225
|
+
// yNum
|
|
226
|
+
[
|
|
227
|
+
'0x4bda12f684bda12f684bda12f684bda12f684bda12f684bda12f684b8e38e23c',
|
|
228
|
+
'0xc75e0c32d5cb7c0fa9d0a54b12a0a6d5647ab046d686da6fdffc90fc201d71a3',
|
|
229
|
+
'0x29a6194691f91a73715209ef6512e576722830a201be2018a765e85a9ecee931',
|
|
230
|
+
'0x2f684bda12f684bda12f684bda12f684bda12f684bda12f684bda12f38e38d84',
|
|
231
|
+
],
|
|
232
|
+
// yDen
|
|
233
|
+
[
|
|
234
|
+
'0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffff93b',
|
|
235
|
+
'0x7a06534bb8bdb49fd5e9e6632722c2989467c1bfc8e8d978dfb425d2685c2573',
|
|
236
|
+
'0x6484aa716545ca2cf3a70c3fa8fe337e0a3d21162f0d6299a7bf8192bfd2a76f',
|
|
237
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001', // LAST 1
|
|
238
|
+
],
|
|
239
|
+
].map((i) => i.map((j) => BigInt(j))));
|
|
240
|
+
const mapSWU = (0, weierstrass_js_1.mapToCurveSimpleSWU)(Fp, {
|
|
241
|
+
A: BigInt('0x3f8731abdd661adca08a5558f0f5d272e953d363cb6f0e5d405447c01a444533'),
|
|
242
|
+
B: BigInt('1771'),
|
|
243
|
+
Z: Fp.create(BigInt('-11')),
|
|
244
|
+
});
|
|
245
|
+
const { hashToCurve, encodeToCurve } = htf.hashToCurve(exports.secp256k1.ProjectivePoint, (scalars) => {
|
|
246
|
+
const { x, y } = mapSWU(Fp.create(scalars[0]));
|
|
247
|
+
return isoMap(x, y);
|
|
248
|
+
}, {
|
|
249
|
+
DST: 'secp256k1_XMD:SHA-256_SSWU_RO_',
|
|
250
|
+
encodeDST: 'secp256k1_XMD:SHA-256_SSWU_NU_',
|
|
251
|
+
p: Fp.ORDER,
|
|
252
|
+
m: 1,
|
|
253
|
+
k: 128,
|
|
254
|
+
expand: 'xmd',
|
|
255
|
+
hash: sha256_1.sha256,
|
|
256
|
+
});
|
|
257
|
+
exports.hashToCurve = hashToCurve;
|
|
258
|
+
exports.encodeToCurve = encodeToCurve;
|