@noble/curves 0.4.0 → 0.5.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 +254 -162
- package/lib/_shortw_utils.d.ts +75 -0
- package/lib/_shortw_utils.js +20 -0
- package/lib/{bls.d.ts → abstract/bls.d.ts} +2 -1
- package/lib/{bls.js → abstract/bls.js} +28 -27
- package/lib/{edwards.d.ts → abstract/edwards.d.ts} +17 -0
- package/lib/{edwards.js → abstract/edwards.js} +45 -4
- package/lib/{group.d.ts → abstract/group.d.ts} +2 -1
- package/lib/{group.js → abstract/group.js} +4 -3
- package/lib/abstract/hash-to-curve.d.ts +28 -0
- package/lib/{hashToCurve.js → abstract/hash-to-curve.js} +46 -11
- package/lib/{modular.d.ts → abstract/modular.d.ts} +13 -16
- package/lib/abstract/modular.js +337 -0
- package/lib/{montgomery.d.ts → abstract/montgomery.d.ts} +2 -1
- package/lib/{montgomery.js → abstract/montgomery.js} +17 -8
- package/lib/{utils.d.ts → abstract/utils.d.ts} +4 -2
- package/lib/{utils.js → abstract/utils.js} +1 -1
- package/lib/{weierstrass.d.ts → abstract/weierstrass.d.ts} +28 -16
- package/lib/{weierstrass.js → abstract/weierstrass.js} +261 -127
- package/lib/bls12-381.d.ts +66 -0
- package/lib/bls12-381.js +1132 -0
- package/lib/bn.d.ts +7 -0
- package/lib/bn.js +24 -0
- package/lib/ed25519.d.ts +48 -0
- package/lib/ed25519.js +385 -0
- package/lib/ed448.d.ts +3 -0
- package/lib/ed448.js +211 -0
- package/lib/esm/_shortw_utils.js +15 -0
- package/lib/esm/{bls.js → abstract/bls.js} +25 -24
- package/lib/esm/{edwards.js → abstract/edwards.js} +45 -4
- package/lib/esm/{group.js → abstract/group.js} +4 -3
- package/lib/esm/{hashToCurve.js → abstract/hash-to-curve.js} +43 -10
- package/lib/esm/abstract/modular.js +319 -0
- package/lib/esm/{montgomery.js → abstract/montgomery.js} +17 -8
- package/lib/esm/{utils.js → abstract/utils.js} +1 -1
- package/lib/esm/{weierstrass.js → abstract/weierstrass.js} +255 -123
- package/lib/esm/bls12-381.js +1129 -0
- package/lib/esm/bn.js +21 -0
- package/lib/esm/ed25519.js +381 -0
- package/lib/esm/ed448.js +208 -0
- package/lib/esm/index.js +2 -0
- package/lib/esm/jubjub.js +52 -0
- package/lib/esm/p192.js +21 -0
- package/lib/esm/p224.js +21 -0
- package/lib/esm/p256.js +39 -0
- package/lib/esm/p384.js +44 -0
- package/lib/esm/p521.js +58 -0
- package/lib/esm/pasta.js +29 -0
- package/lib/esm/secp256k1.js +293 -0
- package/lib/esm/stark.js +224 -0
- package/lib/index.d.ts +0 -0
- package/lib/index.js +2 -0
- package/lib/jubjub.d.ts +7 -0
- package/lib/jubjub.js +57 -0
- package/lib/p192.d.ts +130 -0
- package/lib/p192.js +24 -0
- package/lib/p224.d.ts +130 -0
- package/lib/p224.js +24 -0
- package/lib/p256.d.ts +130 -0
- package/lib/p256.js +42 -0
- package/lib/p384.d.ts +130 -0
- package/lib/p384.js +47 -0
- package/lib/p521.d.ts +131 -0
- package/lib/p521.js +61 -0
- package/lib/pasta.d.ts +4 -0
- package/lib/pasta.js +32 -0
- package/lib/secp256k1.d.ts +96 -0
- package/lib/secp256k1.js +297 -0
- package/lib/stark.d.ts +72 -0
- package/lib/stark.js +245 -0
- package/package.json +146 -50
- package/index.js +0 -1
- package/lib/esm/modular.js +0 -252
- package/lib/hashToCurve.d.ts +0 -13
- package/lib/modular.js +0 -267
package/lib/esm/stark.js
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
2
|
+
import { keccak_256 } from '@noble/hashes/sha3';
|
|
3
|
+
import { sha256 } from '@noble/hashes/sha256';
|
|
4
|
+
import { weierstrass } from './abstract/weierstrass.js';
|
|
5
|
+
import * as cutils from './abstract/utils.js';
|
|
6
|
+
import { Fp } from './abstract/modular.js';
|
|
7
|
+
import { getHash } from './_shortw_utils.js';
|
|
8
|
+
// Stark-friendly elliptic curve
|
|
9
|
+
// https://docs.starkware.co/starkex/stark-curve.html
|
|
10
|
+
const CURVE_N = BigInt('3618502788666131213697322783095070105526743751716087489154079457884512865583');
|
|
11
|
+
const nBitLength = 252;
|
|
12
|
+
export const starkCurve = weierstrass({
|
|
13
|
+
// Params: a, b
|
|
14
|
+
a: BigInt(1),
|
|
15
|
+
b: BigInt('3141592653589793238462643383279502884197169399375105820974944592307816406665'),
|
|
16
|
+
// Field over which we'll do calculations; 2n**251n + 17n * 2n**192n + 1n
|
|
17
|
+
// There is no efficient sqrt for field (P%4==1)
|
|
18
|
+
Fp: Fp(BigInt('0x800000000000011000000000000000000000000000000000000000000000001')),
|
|
19
|
+
// Curve order, total count of valid points in the field.
|
|
20
|
+
n: CURVE_N,
|
|
21
|
+
nBitLength: nBitLength,
|
|
22
|
+
// Base point (x, y) aka generator point
|
|
23
|
+
Gx: BigInt('874739451078007766457464989774322083649278607533249481151382481072868806602'),
|
|
24
|
+
Gy: BigInt('152666792071518830868575557812948353041420400780739481342941381225525861407'),
|
|
25
|
+
h: BigInt(1),
|
|
26
|
+
// Default options
|
|
27
|
+
lowS: false,
|
|
28
|
+
...getHash(sha256),
|
|
29
|
+
truncateHash: (hash, truncateOnly = false) => {
|
|
30
|
+
// TODO: cleanup, ugly code
|
|
31
|
+
// Fix truncation
|
|
32
|
+
if (!truncateOnly) {
|
|
33
|
+
let hashS = bytesToNumber0x(hash).toString(16);
|
|
34
|
+
if (hashS.length === 63) {
|
|
35
|
+
hashS += '0';
|
|
36
|
+
hash = hexToBytes0x(hashS);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
// Truncate zero bytes on left (compat with elliptic)
|
|
40
|
+
while (hash[0] === 0)
|
|
41
|
+
hash = hash.subarray(1);
|
|
42
|
+
const byteLength = hash.length;
|
|
43
|
+
const delta = byteLength * 8 - nBitLength; // size of curve.n (252 bits)
|
|
44
|
+
let h = hash.length ? bytesToNumber0x(hash) : 0n;
|
|
45
|
+
if (delta > 0)
|
|
46
|
+
h = h >> BigInt(delta);
|
|
47
|
+
if (!truncateOnly && h >= CURVE_N)
|
|
48
|
+
h -= CURVE_N;
|
|
49
|
+
return h;
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
// Custom Starknet type conversion functions that can handle 0x and unpadded hex
|
|
53
|
+
function hexToBytes0x(hex) {
|
|
54
|
+
if (typeof hex !== 'string') {
|
|
55
|
+
throw new TypeError('hexToBytes: expected string, got ' + typeof hex);
|
|
56
|
+
}
|
|
57
|
+
hex = strip0x(hex);
|
|
58
|
+
if (hex.length & 1)
|
|
59
|
+
hex = '0' + hex; // padding
|
|
60
|
+
if (hex.length % 2)
|
|
61
|
+
throw new Error('hexToBytes: received invalid unpadded hex ' + hex.length);
|
|
62
|
+
const array = new Uint8Array(hex.length / 2);
|
|
63
|
+
for (let i = 0; i < array.length; i++) {
|
|
64
|
+
const j = i * 2;
|
|
65
|
+
const hexByte = hex.slice(j, j + 2);
|
|
66
|
+
const byte = Number.parseInt(hexByte, 16);
|
|
67
|
+
if (Number.isNaN(byte) || byte < 0)
|
|
68
|
+
throw new Error('Invalid byte sequence');
|
|
69
|
+
array[i] = byte;
|
|
70
|
+
}
|
|
71
|
+
return array;
|
|
72
|
+
}
|
|
73
|
+
function hexToNumber0x(hex) {
|
|
74
|
+
if (typeof hex !== 'string') {
|
|
75
|
+
throw new TypeError('hexToNumber: expected string, got ' + typeof hex);
|
|
76
|
+
}
|
|
77
|
+
// Big Endian
|
|
78
|
+
// TODO: strip vs no strip?
|
|
79
|
+
return BigInt(`0x${strip0x(hex)}`);
|
|
80
|
+
}
|
|
81
|
+
function bytesToNumber0x(bytes) {
|
|
82
|
+
return hexToNumber0x(cutils.bytesToHex(bytes));
|
|
83
|
+
}
|
|
84
|
+
function ensureBytes0x(hex) {
|
|
85
|
+
// Uint8Array.from() instead of hash.slice() because node.js Buffer
|
|
86
|
+
// is instance of Uint8Array, and its slice() creates **mutable** copy
|
|
87
|
+
return hex instanceof Uint8Array ? Uint8Array.from(hex) : hexToBytes0x(hex);
|
|
88
|
+
}
|
|
89
|
+
function normalizePrivateKey(privKey) {
|
|
90
|
+
return cutils.bytesToHex(ensureBytes0x(privKey)).padStart(32 * 2, '0');
|
|
91
|
+
}
|
|
92
|
+
function getPublicKey0x(privKey, isCompressed) {
|
|
93
|
+
return starkCurve.getPublicKey(normalizePrivateKey(privKey), isCompressed);
|
|
94
|
+
}
|
|
95
|
+
function getSharedSecret0x(privKeyA, pubKeyB) {
|
|
96
|
+
return starkCurve.getSharedSecret(normalizePrivateKey(privKeyA), pubKeyB);
|
|
97
|
+
}
|
|
98
|
+
function sign0x(msgHash, privKey, opts) {
|
|
99
|
+
if (typeof privKey === 'string')
|
|
100
|
+
privKey = strip0x(privKey).padStart(64, '0');
|
|
101
|
+
return starkCurve.sign(ensureBytes0x(msgHash), normalizePrivateKey(privKey), opts);
|
|
102
|
+
}
|
|
103
|
+
function verify0x(signature, msgHash, pubKey) {
|
|
104
|
+
const sig = signature instanceof Signature ? signature : ensureBytes0x(signature);
|
|
105
|
+
return starkCurve.verify(sig, ensureBytes0x(msgHash), ensureBytes0x(pubKey));
|
|
106
|
+
}
|
|
107
|
+
const { CURVE, Point, ProjectivePoint, Signature } = starkCurve;
|
|
108
|
+
export const utils = starkCurve.utils;
|
|
109
|
+
export { CURVE, Point, Signature, ProjectivePoint, getPublicKey0x as getPublicKey, getSharedSecret0x as getSharedSecret, sign0x as sign, verify0x as verify, };
|
|
110
|
+
const stripLeadingZeros = (s) => s.replace(/^0+/gm, '');
|
|
111
|
+
export const bytesToHexEth = (uint8a) => `0x${stripLeadingZeros(cutils.bytesToHex(uint8a))}`;
|
|
112
|
+
export const strip0x = (hex) => hex.replace(/^0x/i, '');
|
|
113
|
+
export const numberToHexEth = (num) => `0x${num.toString(16)}`;
|
|
114
|
+
// 1. seed generation
|
|
115
|
+
function hashKeyWithIndex(key, index) {
|
|
116
|
+
let indexHex = cutils.numberToHexUnpadded(index);
|
|
117
|
+
if (indexHex.length & 1)
|
|
118
|
+
indexHex = '0' + indexHex;
|
|
119
|
+
return bytesToNumber0x(sha256(cutils.concatBytes(key, hexToBytes0x(indexHex))));
|
|
120
|
+
}
|
|
121
|
+
export function grindKey(seed) {
|
|
122
|
+
const _seed = ensureBytes0x(seed);
|
|
123
|
+
const sha256mask = 2n ** 256n;
|
|
124
|
+
const limit = sha256mask - starkCurve.utils.mod(sha256mask, starkCurve.CURVE.n);
|
|
125
|
+
for (let i = 0;; i++) {
|
|
126
|
+
const key = hashKeyWithIndex(_seed, i);
|
|
127
|
+
// key should be in [0, limit)
|
|
128
|
+
if (key < limit)
|
|
129
|
+
return starkCurve.utils.mod(key, starkCurve.CURVE.n).toString(16);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
export function getStarkKey(privateKey) {
|
|
133
|
+
return bytesToHexEth(getPublicKey0x(privateKey, true).slice(1));
|
|
134
|
+
}
|
|
135
|
+
export function ethSigToPrivate(signature) {
|
|
136
|
+
signature = strip0x(signature.replace(/^0x/, ''));
|
|
137
|
+
if (signature.length !== 130)
|
|
138
|
+
throw new Error('Wrong ethereum signature');
|
|
139
|
+
return grindKey(signature.substring(0, 64));
|
|
140
|
+
}
|
|
141
|
+
const MASK_31 = 2n ** 31n - 1n;
|
|
142
|
+
const int31 = (n) => Number(n & MASK_31);
|
|
143
|
+
export function getAccountPath(layer, application, ethereumAddress, index) {
|
|
144
|
+
const layerNum = int31(bytesToNumber0x(sha256(layer)));
|
|
145
|
+
const applicationNum = int31(bytesToNumber0x(sha256(application)));
|
|
146
|
+
const eth = hexToNumber0x(ethereumAddress);
|
|
147
|
+
return `m/2645'/${layerNum}'/${applicationNum}'/${int31(eth)}'/${int31(eth >> 31n)}'/${index}`;
|
|
148
|
+
}
|
|
149
|
+
// https://docs.starkware.co/starkex/pedersen-hash-function.html
|
|
150
|
+
const PEDERSEN_POINTS_AFFINE = [
|
|
151
|
+
new Point(2089986280348253421170679821480865132823066470938446095505822317253594081284n, 1713931329540660377023406109199410414810705867260802078187082345529207694986n),
|
|
152
|
+
new Point(996781205833008774514500082376783249102396023663454813447423147977397232763n, 1668503676786377725805489344771023921079126552019160156920634619255970485781n),
|
|
153
|
+
new Point(2251563274489750535117886426533222435294046428347329203627021249169616184184n, 1798716007562728905295480679789526322175868328062420237419143593021674992973n),
|
|
154
|
+
new Point(2138414695194151160943305727036575959195309218611738193261179310511854807447n, 113410276730064486255102093846540133784865286929052426931474106396135072156n),
|
|
155
|
+
new Point(2379962749567351885752724891227938183011949129833673362440656643086021394946n, 776496453633298175483985398648758586525933812536653089401905292063708816422n),
|
|
156
|
+
];
|
|
157
|
+
// for (const p of PEDERSEN_POINTS) p._setWindowSize(8);
|
|
158
|
+
const PEDERSEN_POINTS = PEDERSEN_POINTS_AFFINE.map(ProjectivePoint.fromAffine);
|
|
159
|
+
function pedersenPrecompute(p1, p2) {
|
|
160
|
+
const out = [];
|
|
161
|
+
let p = p1;
|
|
162
|
+
for (let i = 0; i < 248; i++) {
|
|
163
|
+
out.push(p);
|
|
164
|
+
p = p.double();
|
|
165
|
+
}
|
|
166
|
+
// NOTE: we cannot use wNAF here, because last 4 bits will require full 248 bits multiplication
|
|
167
|
+
// We can add support for this to wNAF, but it will complicate wNAF.
|
|
168
|
+
p = p2;
|
|
169
|
+
for (let i = 0; i < 4; i++) {
|
|
170
|
+
out.push(p);
|
|
171
|
+
p = p.double();
|
|
172
|
+
}
|
|
173
|
+
return out;
|
|
174
|
+
}
|
|
175
|
+
const PEDERSEN_POINTS1 = pedersenPrecompute(PEDERSEN_POINTS[1], PEDERSEN_POINTS[2]);
|
|
176
|
+
const PEDERSEN_POINTS2 = pedersenPrecompute(PEDERSEN_POINTS[3], PEDERSEN_POINTS[4]);
|
|
177
|
+
function pedersenArg(arg) {
|
|
178
|
+
let value;
|
|
179
|
+
if (typeof arg === 'bigint')
|
|
180
|
+
value = arg;
|
|
181
|
+
else if (typeof arg === 'number') {
|
|
182
|
+
if (!Number.isSafeInteger(arg))
|
|
183
|
+
throw new Error(`Invalid pedersenArg: ${arg}`);
|
|
184
|
+
value = BigInt(arg);
|
|
185
|
+
}
|
|
186
|
+
else
|
|
187
|
+
value = bytesToNumber0x(ensureBytes0x(arg));
|
|
188
|
+
// [0..Fp)
|
|
189
|
+
if (!(0n <= value && value < starkCurve.CURVE.Fp.ORDER))
|
|
190
|
+
throw new Error(`PedersenArg should be 0 <= value < CURVE.P: ${value}`);
|
|
191
|
+
return value;
|
|
192
|
+
}
|
|
193
|
+
function pedersenSingle(point, value, constants) {
|
|
194
|
+
let x = pedersenArg(value);
|
|
195
|
+
for (let j = 0; j < 252; j++) {
|
|
196
|
+
const pt = constants[j];
|
|
197
|
+
if (pt.x === point.x)
|
|
198
|
+
throw new Error('Same point');
|
|
199
|
+
if ((x & 1n) !== 0n)
|
|
200
|
+
point = point.add(pt);
|
|
201
|
+
x >>= 1n;
|
|
202
|
+
}
|
|
203
|
+
return point;
|
|
204
|
+
}
|
|
205
|
+
// shift_point + x_low * P_0 + x_high * P1 + y_low * P2 + y_high * P3
|
|
206
|
+
export function pedersen(x, y) {
|
|
207
|
+
let point = PEDERSEN_POINTS[0];
|
|
208
|
+
point = pedersenSingle(point, x, PEDERSEN_POINTS1);
|
|
209
|
+
point = pedersenSingle(point, y, PEDERSEN_POINTS2);
|
|
210
|
+
return bytesToHexEth(point.toAffine().toRawBytes(true).slice(1));
|
|
211
|
+
}
|
|
212
|
+
export function hashChain(data, fn = pedersen) {
|
|
213
|
+
if (!Array.isArray(data) || data.length < 1)
|
|
214
|
+
throw new Error('data should be array of at least 1 element');
|
|
215
|
+
if (data.length === 1)
|
|
216
|
+
return numberToHexEth(pedersenArg(data[0]));
|
|
217
|
+
return Array.from(data)
|
|
218
|
+
.reverse()
|
|
219
|
+
.reduce((acc, i) => fn(i, acc));
|
|
220
|
+
}
|
|
221
|
+
// Same as hashChain, but computes hash even for single element and order is not revesed
|
|
222
|
+
export const computeHashOnElements = (data, fn = pedersen) => [0, ...data, data.length].reduce((x, y) => fn(x, y));
|
|
223
|
+
const MASK_250 = 2n ** 250n - 1n;
|
|
224
|
+
export const keccak = (data) => bytesToNumber0x(keccak_256(data)) & MASK_250;
|
package/lib/index.d.ts
ADDED
|
File without changes
|
package/lib/index.js
ADDED
package/lib/jubjub.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* jubjub Twisted Edwards curve.
|
|
3
|
+
* https://neuromancer.sk/std/other/JubJub
|
|
4
|
+
*/
|
|
5
|
+
export declare const jubjub: import("./abstract/edwards.js").CurveFn;
|
|
6
|
+
export declare function groupHash(tag: Uint8Array, personalization: Uint8Array): import("./abstract/edwards.js").ExtendedPointType;
|
|
7
|
+
export declare function findGroupHash(m: Uint8Array, personalization: Uint8Array): import("./abstract/edwards.js").ExtendedPointType;
|
package/lib/jubjub.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findGroupHash = exports.groupHash = exports.jubjub = void 0;
|
|
4
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
5
|
+
const sha256_1 = require("@noble/hashes/sha256");
|
|
6
|
+
const utils_1 = require("@noble/hashes/utils");
|
|
7
|
+
const edwards_js_1 = require("./abstract/edwards.js");
|
|
8
|
+
const blake2s_1 = require("@noble/hashes/blake2s");
|
|
9
|
+
const modular_js_1 = require("./abstract/modular.js");
|
|
10
|
+
/**
|
|
11
|
+
* jubjub Twisted Edwards curve.
|
|
12
|
+
* https://neuromancer.sk/std/other/JubJub
|
|
13
|
+
*/
|
|
14
|
+
exports.jubjub = (0, edwards_js_1.twistedEdwards)({
|
|
15
|
+
// Params: a, d
|
|
16
|
+
a: BigInt('0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000000'),
|
|
17
|
+
d: BigInt('0x2a9318e74bfa2b48f5fd9207e6bd7fd4292d7f6d37579d2601065fd6d6343eb1'),
|
|
18
|
+
// Finite field 𝔽p over which we'll do calculations
|
|
19
|
+
Fp: (0, modular_js_1.Fp)(BigInt('0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001')),
|
|
20
|
+
// Subgroup order: how many points ed25519 has
|
|
21
|
+
// 2n ** 252n + 27742317777372353535851937790883648493n;
|
|
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: sha256_1.sha256,
|
|
29
|
+
randomBytes: utils_1.randomBytes,
|
|
30
|
+
});
|
|
31
|
+
const GH_FIRST_BLOCK = (0, utils_1.utf8ToBytes)('096b36a5804bfacef1691e173c366a47ff5ba84a44f26ddd7e8d9f79d5b42df0');
|
|
32
|
+
// Returns point at JubJub curve which is prime order and not zero
|
|
33
|
+
function groupHash(tag, personalization) {
|
|
34
|
+
const h = blake2s_1.blake2s.create({ personalization, dkLen: 32 });
|
|
35
|
+
h.update(GH_FIRST_BLOCK);
|
|
36
|
+
h.update(tag);
|
|
37
|
+
// NOTE: returns ExtendedPoint, in case it will be multiplied later
|
|
38
|
+
let p = exports.jubjub.ExtendedPoint.fromAffine(exports.jubjub.Point.fromHex(h.digest()));
|
|
39
|
+
// NOTE: cannot replace with isSmallOrder, returns Point*8
|
|
40
|
+
p = p.multiply(exports.jubjub.CURVE.h);
|
|
41
|
+
if (p.equals(exports.jubjub.ExtendedPoint.ZERO))
|
|
42
|
+
throw new Error('Point has small order');
|
|
43
|
+
return p;
|
|
44
|
+
}
|
|
45
|
+
exports.groupHash = groupHash;
|
|
46
|
+
function findGroupHash(m, personalization) {
|
|
47
|
+
const tag = (0, utils_1.concatBytes)(m, new Uint8Array([0]));
|
|
48
|
+
for (let i = 0; i < 256; i++) {
|
|
49
|
+
tag[tag.length - 1] = i;
|
|
50
|
+
try {
|
|
51
|
+
return groupHash(tag, personalization);
|
|
52
|
+
}
|
|
53
|
+
catch (e) { }
|
|
54
|
+
}
|
|
55
|
+
throw new Error('findGroupHash tag overflow');
|
|
56
|
+
}
|
|
57
|
+
exports.findGroupHash = findGroupHash;
|
package/lib/p192.d.ts
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
export declare const P192: Readonly<{
|
|
2
|
+
create: (hash: import("./abstract/utils.js").CHash) => import("./abstract/weierstrass.js").CurveFn;
|
|
3
|
+
CURVE: Readonly<{
|
|
4
|
+
readonly nBitLength: number;
|
|
5
|
+
readonly nByteLength: number;
|
|
6
|
+
readonly Fp: import("./abstract/modular.js").Field<bigint>;
|
|
7
|
+
readonly n: bigint;
|
|
8
|
+
readonly h: bigint;
|
|
9
|
+
readonly hEff?: bigint | undefined;
|
|
10
|
+
readonly Gx: bigint;
|
|
11
|
+
readonly Gy: bigint;
|
|
12
|
+
readonly wrapPrivateKey?: boolean | undefined;
|
|
13
|
+
readonly allowInfinityPoint?: boolean | undefined;
|
|
14
|
+
readonly a: bigint;
|
|
15
|
+
readonly b: bigint;
|
|
16
|
+
readonly normalizePrivateKey?: ((key: import("./abstract/utils.js").PrivKey) => import("./abstract/utils.js").PrivKey) | undefined;
|
|
17
|
+
readonly endo?: {
|
|
18
|
+
beta: bigint;
|
|
19
|
+
splitScalar: (k: bigint) => {
|
|
20
|
+
k1neg: boolean;
|
|
21
|
+
k1: bigint;
|
|
22
|
+
k2neg: boolean;
|
|
23
|
+
k2: bigint;
|
|
24
|
+
};
|
|
25
|
+
} | undefined;
|
|
26
|
+
readonly isTorsionFree?: ((c: import("./abstract/weierstrass.js").ProjectiveConstructor<bigint>, point: import("./abstract/weierstrass.js").ProjectivePointType<bigint>) => boolean) | undefined;
|
|
27
|
+
readonly clearCofactor?: ((c: import("./abstract/weierstrass.js").ProjectiveConstructor<bigint>, point: import("./abstract/weierstrass.js").ProjectivePointType<bigint>) => import("./abstract/weierstrass.js").ProjectivePointType<bigint>) | undefined;
|
|
28
|
+
readonly htfDefaults?: import("./abstract/hash-to-curve.js").htfOpts | undefined;
|
|
29
|
+
readonly mapToCurve?: ((scalar: bigint[]) => {
|
|
30
|
+
x: bigint;
|
|
31
|
+
y: bigint;
|
|
32
|
+
}) | undefined;
|
|
33
|
+
lowS: boolean;
|
|
34
|
+
readonly hash: import("./abstract/utils.js").CHash;
|
|
35
|
+
readonly hmac: (key: Uint8Array, ...messages: Uint8Array[]) => Uint8Array;
|
|
36
|
+
readonly randomBytes: (bytesLength?: number | undefined) => Uint8Array;
|
|
37
|
+
readonly truncateHash?: ((hash: Uint8Array, truncateOnly?: boolean | undefined) => bigint) | undefined;
|
|
38
|
+
}>;
|
|
39
|
+
getPublicKey: (privateKey: import("./abstract/utils.js").PrivKey, isCompressed?: boolean | undefined) => Uint8Array;
|
|
40
|
+
getSharedSecret: (privateA: import("./abstract/utils.js").PrivKey, publicB: import("./abstract/weierstrass.js").PubKey, isCompressed?: boolean | undefined) => Uint8Array;
|
|
41
|
+
sign: (msgHash: import("./abstract/utils.js").Hex, privKey: import("./abstract/utils.js").PrivKey, opts?: {
|
|
42
|
+
lowS?: boolean | undefined;
|
|
43
|
+
extraEntropy?: (true | import("./abstract/utils.js").Hex) | undefined;
|
|
44
|
+
} | undefined) => import("./abstract/weierstrass.js").SignatureType;
|
|
45
|
+
verify: (signature: import("./abstract/utils.js").Hex | import("./abstract/weierstrass.js").SignatureType, msgHash: import("./abstract/utils.js").Hex, publicKey: import("./abstract/weierstrass.js").PubKey, opts?: {
|
|
46
|
+
lowS?: boolean | undefined;
|
|
47
|
+
} | undefined) => boolean;
|
|
48
|
+
Point: import("./abstract/weierstrass.js").PointConstructor<bigint>;
|
|
49
|
+
ProjectivePoint: import("./abstract/weierstrass.js").ProjectiveConstructor<bigint>;
|
|
50
|
+
Signature: import("./abstract/weierstrass.js").SignatureConstructor;
|
|
51
|
+
utils: {
|
|
52
|
+
mod: (a: bigint, b?: bigint | undefined) => bigint;
|
|
53
|
+
invert: (number: bigint, modulo?: bigint | undefined) => bigint;
|
|
54
|
+
_bigintToBytes: (num: bigint) => Uint8Array;
|
|
55
|
+
_bigintToString: (num: bigint) => string;
|
|
56
|
+
_normalizePrivateKey: (key: import("./abstract/utils.js").PrivKey) => bigint;
|
|
57
|
+
_normalizePublicKey: (publicKey: import("./abstract/weierstrass.js").PubKey) => import("./abstract/weierstrass.js").PointType<bigint>;
|
|
58
|
+
_isWithinCurveOrder: (num: bigint) => boolean;
|
|
59
|
+
_isValidFieldElement: (num: bigint) => boolean;
|
|
60
|
+
_weierstrassEquation: (x: bigint) => bigint;
|
|
61
|
+
isValidPrivateKey(privateKey: import("./abstract/utils.js").PrivKey): boolean;
|
|
62
|
+
hashToPrivateKey: (hash: import("./abstract/utils.js").Hex) => Uint8Array;
|
|
63
|
+
randomPrivateKey: () => Uint8Array;
|
|
64
|
+
};
|
|
65
|
+
}>;
|
|
66
|
+
export declare const secp192r1: Readonly<{
|
|
67
|
+
create: (hash: import("./abstract/utils.js").CHash) => import("./abstract/weierstrass.js").CurveFn;
|
|
68
|
+
CURVE: Readonly<{
|
|
69
|
+
readonly nBitLength: number;
|
|
70
|
+
readonly nByteLength: number;
|
|
71
|
+
readonly Fp: import("./abstract/modular.js").Field<bigint>;
|
|
72
|
+
readonly n: bigint;
|
|
73
|
+
readonly h: bigint;
|
|
74
|
+
readonly hEff?: bigint | undefined;
|
|
75
|
+
readonly Gx: bigint;
|
|
76
|
+
readonly Gy: bigint;
|
|
77
|
+
readonly wrapPrivateKey?: boolean | undefined;
|
|
78
|
+
readonly allowInfinityPoint?: boolean | undefined;
|
|
79
|
+
readonly a: bigint;
|
|
80
|
+
readonly b: bigint;
|
|
81
|
+
readonly normalizePrivateKey?: ((key: import("./abstract/utils.js").PrivKey) => import("./abstract/utils.js").PrivKey) | undefined;
|
|
82
|
+
readonly endo?: {
|
|
83
|
+
beta: bigint;
|
|
84
|
+
splitScalar: (k: bigint) => {
|
|
85
|
+
k1neg: boolean;
|
|
86
|
+
k1: bigint;
|
|
87
|
+
k2neg: boolean;
|
|
88
|
+
k2: bigint;
|
|
89
|
+
};
|
|
90
|
+
} | undefined;
|
|
91
|
+
readonly isTorsionFree?: ((c: import("./abstract/weierstrass.js").ProjectiveConstructor<bigint>, point: import("./abstract/weierstrass.js").ProjectivePointType<bigint>) => boolean) | undefined;
|
|
92
|
+
readonly clearCofactor?: ((c: import("./abstract/weierstrass.js").ProjectiveConstructor<bigint>, point: import("./abstract/weierstrass.js").ProjectivePointType<bigint>) => import("./abstract/weierstrass.js").ProjectivePointType<bigint>) | undefined;
|
|
93
|
+
readonly htfDefaults?: import("./abstract/hash-to-curve.js").htfOpts | undefined;
|
|
94
|
+
readonly mapToCurve?: ((scalar: bigint[]) => {
|
|
95
|
+
x: bigint;
|
|
96
|
+
y: bigint;
|
|
97
|
+
}) | undefined;
|
|
98
|
+
lowS: boolean;
|
|
99
|
+
readonly hash: import("./abstract/utils.js").CHash;
|
|
100
|
+
readonly hmac: (key: Uint8Array, ...messages: Uint8Array[]) => Uint8Array;
|
|
101
|
+
readonly randomBytes: (bytesLength?: number | undefined) => Uint8Array;
|
|
102
|
+
readonly truncateHash?: ((hash: Uint8Array, truncateOnly?: boolean | undefined) => bigint) | undefined;
|
|
103
|
+
}>;
|
|
104
|
+
getPublicKey: (privateKey: import("./abstract/utils.js").PrivKey, isCompressed?: boolean | undefined) => Uint8Array;
|
|
105
|
+
getSharedSecret: (privateA: import("./abstract/utils.js").PrivKey, publicB: import("./abstract/weierstrass.js").PubKey, isCompressed?: boolean | undefined) => Uint8Array;
|
|
106
|
+
sign: (msgHash: import("./abstract/utils.js").Hex, privKey: import("./abstract/utils.js").PrivKey, opts?: {
|
|
107
|
+
lowS?: boolean | undefined;
|
|
108
|
+
extraEntropy?: (true | import("./abstract/utils.js").Hex) | undefined;
|
|
109
|
+
} | undefined) => import("./abstract/weierstrass.js").SignatureType;
|
|
110
|
+
verify: (signature: import("./abstract/utils.js").Hex | import("./abstract/weierstrass.js").SignatureType, msgHash: import("./abstract/utils.js").Hex, publicKey: import("./abstract/weierstrass.js").PubKey, opts?: {
|
|
111
|
+
lowS?: boolean | undefined;
|
|
112
|
+
} | undefined) => boolean;
|
|
113
|
+
Point: import("./abstract/weierstrass.js").PointConstructor<bigint>;
|
|
114
|
+
ProjectivePoint: import("./abstract/weierstrass.js").ProjectiveConstructor<bigint>;
|
|
115
|
+
Signature: import("./abstract/weierstrass.js").SignatureConstructor;
|
|
116
|
+
utils: {
|
|
117
|
+
mod: (a: bigint, b?: bigint | undefined) => bigint;
|
|
118
|
+
invert: (number: bigint, modulo?: bigint | undefined) => bigint;
|
|
119
|
+
_bigintToBytes: (num: bigint) => Uint8Array;
|
|
120
|
+
_bigintToString: (num: bigint) => string;
|
|
121
|
+
_normalizePrivateKey: (key: import("./abstract/utils.js").PrivKey) => bigint;
|
|
122
|
+
_normalizePublicKey: (publicKey: import("./abstract/weierstrass.js").PubKey) => import("./abstract/weierstrass.js").PointType<bigint>;
|
|
123
|
+
_isWithinCurveOrder: (num: bigint) => boolean;
|
|
124
|
+
_isValidFieldElement: (num: bigint) => boolean;
|
|
125
|
+
_weierstrassEquation: (x: bigint) => bigint;
|
|
126
|
+
isValidPrivateKey(privateKey: import("./abstract/utils.js").PrivKey): boolean;
|
|
127
|
+
hashToPrivateKey: (hash: import("./abstract/utils.js").Hex) => Uint8Array;
|
|
128
|
+
randomPrivateKey: () => Uint8Array;
|
|
129
|
+
};
|
|
130
|
+
}>;
|
package/lib/p192.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.secp192r1 = exports.P192 = void 0;
|
|
4
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
5
|
+
const _shortw_utils_js_1 = require("./_shortw_utils.js");
|
|
6
|
+
const sha256_1 = require("@noble/hashes/sha256");
|
|
7
|
+
const modular_js_1 = require("./abstract/modular.js");
|
|
8
|
+
// NIST secp192r1 aka P192
|
|
9
|
+
// https://www.secg.org/sec2-v2.pdf, https://neuromancer.sk/std/secg/secp192r1
|
|
10
|
+
exports.P192 = (0, _shortw_utils_js_1.createCurve)({
|
|
11
|
+
// Params: a, b
|
|
12
|
+
a: BigInt('0xfffffffffffffffffffffffffffffffefffffffffffffffc'),
|
|
13
|
+
b: BigInt('0x64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1'),
|
|
14
|
+
// Field over which we'll do calculations; 2n ** 192n - 2n ** 64n - 1n
|
|
15
|
+
Fp: (0, modular_js_1.Fp)(BigInt('0xfffffffffffffffffffffffffffffffeffffffffffffffff')),
|
|
16
|
+
// Curve order, total count of valid points in the field.
|
|
17
|
+
n: BigInt('0xffffffffffffffffffffffff99def836146bc9b1b4d22831'),
|
|
18
|
+
// Base point (x, y) aka generator point
|
|
19
|
+
Gx: BigInt('0x188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012'),
|
|
20
|
+
Gy: BigInt('0x07192b95ffc8da78631011ed6b24cdd573f977a11e794811'),
|
|
21
|
+
h: BigInt(1),
|
|
22
|
+
lowS: false,
|
|
23
|
+
}, sha256_1.sha256);
|
|
24
|
+
exports.secp192r1 = exports.P192;
|
package/lib/p224.d.ts
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
export declare const P224: Readonly<{
|
|
2
|
+
create: (hash: import("./abstract/utils.js").CHash) => import("./abstract/weierstrass.js").CurveFn;
|
|
3
|
+
CURVE: Readonly<{
|
|
4
|
+
readonly nBitLength: number;
|
|
5
|
+
readonly nByteLength: number;
|
|
6
|
+
readonly Fp: import("./abstract/modular.js").Field<bigint>;
|
|
7
|
+
readonly n: bigint;
|
|
8
|
+
readonly h: bigint;
|
|
9
|
+
readonly hEff?: bigint | undefined;
|
|
10
|
+
readonly Gx: bigint;
|
|
11
|
+
readonly Gy: bigint;
|
|
12
|
+
readonly wrapPrivateKey?: boolean | undefined;
|
|
13
|
+
readonly allowInfinityPoint?: boolean | undefined;
|
|
14
|
+
readonly a: bigint;
|
|
15
|
+
readonly b: bigint;
|
|
16
|
+
readonly normalizePrivateKey?: ((key: import("./abstract/utils.js").PrivKey) => import("./abstract/utils.js").PrivKey) | undefined;
|
|
17
|
+
readonly endo?: {
|
|
18
|
+
beta: bigint;
|
|
19
|
+
splitScalar: (k: bigint) => {
|
|
20
|
+
k1neg: boolean;
|
|
21
|
+
k1: bigint;
|
|
22
|
+
k2neg: boolean;
|
|
23
|
+
k2: bigint;
|
|
24
|
+
};
|
|
25
|
+
} | undefined;
|
|
26
|
+
readonly isTorsionFree?: ((c: import("./abstract/weierstrass.js").ProjectiveConstructor<bigint>, point: import("./abstract/weierstrass.js").ProjectivePointType<bigint>) => boolean) | undefined;
|
|
27
|
+
readonly clearCofactor?: ((c: import("./abstract/weierstrass.js").ProjectiveConstructor<bigint>, point: import("./abstract/weierstrass.js").ProjectivePointType<bigint>) => import("./abstract/weierstrass.js").ProjectivePointType<bigint>) | undefined;
|
|
28
|
+
readonly htfDefaults?: import("./abstract/hash-to-curve.js").htfOpts | undefined;
|
|
29
|
+
readonly mapToCurve?: ((scalar: bigint[]) => {
|
|
30
|
+
x: bigint;
|
|
31
|
+
y: bigint;
|
|
32
|
+
}) | undefined;
|
|
33
|
+
lowS: boolean;
|
|
34
|
+
readonly hash: import("./abstract/utils.js").CHash;
|
|
35
|
+
readonly hmac: (key: Uint8Array, ...messages: Uint8Array[]) => Uint8Array;
|
|
36
|
+
readonly randomBytes: (bytesLength?: number | undefined) => Uint8Array;
|
|
37
|
+
readonly truncateHash?: ((hash: Uint8Array, truncateOnly?: boolean | undefined) => bigint) | undefined;
|
|
38
|
+
}>;
|
|
39
|
+
getPublicKey: (privateKey: import("./abstract/utils.js").PrivKey, isCompressed?: boolean | undefined) => Uint8Array;
|
|
40
|
+
getSharedSecret: (privateA: import("./abstract/utils.js").PrivKey, publicB: import("./abstract/weierstrass.js").PubKey, isCompressed?: boolean | undefined) => Uint8Array;
|
|
41
|
+
sign: (msgHash: import("./abstract/utils.js").Hex, privKey: import("./abstract/utils.js").PrivKey, opts?: {
|
|
42
|
+
lowS?: boolean | undefined;
|
|
43
|
+
extraEntropy?: (true | import("./abstract/utils.js").Hex) | undefined;
|
|
44
|
+
} | undefined) => import("./abstract/weierstrass.js").SignatureType;
|
|
45
|
+
verify: (signature: import("./abstract/utils.js").Hex | import("./abstract/weierstrass.js").SignatureType, msgHash: import("./abstract/utils.js").Hex, publicKey: import("./abstract/weierstrass.js").PubKey, opts?: {
|
|
46
|
+
lowS?: boolean | undefined;
|
|
47
|
+
} | undefined) => boolean;
|
|
48
|
+
Point: import("./abstract/weierstrass.js").PointConstructor<bigint>;
|
|
49
|
+
ProjectivePoint: import("./abstract/weierstrass.js").ProjectiveConstructor<bigint>;
|
|
50
|
+
Signature: import("./abstract/weierstrass.js").SignatureConstructor;
|
|
51
|
+
utils: {
|
|
52
|
+
mod: (a: bigint, b?: bigint | undefined) => bigint;
|
|
53
|
+
invert: (number: bigint, modulo?: bigint | undefined) => bigint;
|
|
54
|
+
_bigintToBytes: (num: bigint) => Uint8Array;
|
|
55
|
+
_bigintToString: (num: bigint) => string;
|
|
56
|
+
_normalizePrivateKey: (key: import("./abstract/utils.js").PrivKey) => bigint;
|
|
57
|
+
_normalizePublicKey: (publicKey: import("./abstract/weierstrass.js").PubKey) => import("./abstract/weierstrass.js").PointType<bigint>;
|
|
58
|
+
_isWithinCurveOrder: (num: bigint) => boolean;
|
|
59
|
+
_isValidFieldElement: (num: bigint) => boolean;
|
|
60
|
+
_weierstrassEquation: (x: bigint) => bigint;
|
|
61
|
+
isValidPrivateKey(privateKey: import("./abstract/utils.js").PrivKey): boolean;
|
|
62
|
+
hashToPrivateKey: (hash: import("./abstract/utils.js").Hex) => Uint8Array;
|
|
63
|
+
randomPrivateKey: () => Uint8Array;
|
|
64
|
+
};
|
|
65
|
+
}>;
|
|
66
|
+
export declare const secp224r1: Readonly<{
|
|
67
|
+
create: (hash: import("./abstract/utils.js").CHash) => import("./abstract/weierstrass.js").CurveFn;
|
|
68
|
+
CURVE: Readonly<{
|
|
69
|
+
readonly nBitLength: number;
|
|
70
|
+
readonly nByteLength: number;
|
|
71
|
+
readonly Fp: import("./abstract/modular.js").Field<bigint>;
|
|
72
|
+
readonly n: bigint;
|
|
73
|
+
readonly h: bigint;
|
|
74
|
+
readonly hEff?: bigint | undefined;
|
|
75
|
+
readonly Gx: bigint;
|
|
76
|
+
readonly Gy: bigint;
|
|
77
|
+
readonly wrapPrivateKey?: boolean | undefined;
|
|
78
|
+
readonly allowInfinityPoint?: boolean | undefined;
|
|
79
|
+
readonly a: bigint;
|
|
80
|
+
readonly b: bigint;
|
|
81
|
+
readonly normalizePrivateKey?: ((key: import("./abstract/utils.js").PrivKey) => import("./abstract/utils.js").PrivKey) | undefined;
|
|
82
|
+
readonly endo?: {
|
|
83
|
+
beta: bigint;
|
|
84
|
+
splitScalar: (k: bigint) => {
|
|
85
|
+
k1neg: boolean;
|
|
86
|
+
k1: bigint;
|
|
87
|
+
k2neg: boolean;
|
|
88
|
+
k2: bigint;
|
|
89
|
+
};
|
|
90
|
+
} | undefined;
|
|
91
|
+
readonly isTorsionFree?: ((c: import("./abstract/weierstrass.js").ProjectiveConstructor<bigint>, point: import("./abstract/weierstrass.js").ProjectivePointType<bigint>) => boolean) | undefined;
|
|
92
|
+
readonly clearCofactor?: ((c: import("./abstract/weierstrass.js").ProjectiveConstructor<bigint>, point: import("./abstract/weierstrass.js").ProjectivePointType<bigint>) => import("./abstract/weierstrass.js").ProjectivePointType<bigint>) | undefined;
|
|
93
|
+
readonly htfDefaults?: import("./abstract/hash-to-curve.js").htfOpts | undefined;
|
|
94
|
+
readonly mapToCurve?: ((scalar: bigint[]) => {
|
|
95
|
+
x: bigint;
|
|
96
|
+
y: bigint;
|
|
97
|
+
}) | undefined;
|
|
98
|
+
lowS: boolean;
|
|
99
|
+
readonly hash: import("./abstract/utils.js").CHash;
|
|
100
|
+
readonly hmac: (key: Uint8Array, ...messages: Uint8Array[]) => Uint8Array;
|
|
101
|
+
readonly randomBytes: (bytesLength?: number | undefined) => Uint8Array;
|
|
102
|
+
readonly truncateHash?: ((hash: Uint8Array, truncateOnly?: boolean | undefined) => bigint) | undefined;
|
|
103
|
+
}>;
|
|
104
|
+
getPublicKey: (privateKey: import("./abstract/utils.js").PrivKey, isCompressed?: boolean | undefined) => Uint8Array;
|
|
105
|
+
getSharedSecret: (privateA: import("./abstract/utils.js").PrivKey, publicB: import("./abstract/weierstrass.js").PubKey, isCompressed?: boolean | undefined) => Uint8Array;
|
|
106
|
+
sign: (msgHash: import("./abstract/utils.js").Hex, privKey: import("./abstract/utils.js").PrivKey, opts?: {
|
|
107
|
+
lowS?: boolean | undefined;
|
|
108
|
+
extraEntropy?: (true | import("./abstract/utils.js").Hex) | undefined;
|
|
109
|
+
} | undefined) => import("./abstract/weierstrass.js").SignatureType;
|
|
110
|
+
verify: (signature: import("./abstract/utils.js").Hex | import("./abstract/weierstrass.js").SignatureType, msgHash: import("./abstract/utils.js").Hex, publicKey: import("./abstract/weierstrass.js").PubKey, opts?: {
|
|
111
|
+
lowS?: boolean | undefined;
|
|
112
|
+
} | undefined) => boolean;
|
|
113
|
+
Point: import("./abstract/weierstrass.js").PointConstructor<bigint>;
|
|
114
|
+
ProjectivePoint: import("./abstract/weierstrass.js").ProjectiveConstructor<bigint>;
|
|
115
|
+
Signature: import("./abstract/weierstrass.js").SignatureConstructor;
|
|
116
|
+
utils: {
|
|
117
|
+
mod: (a: bigint, b?: bigint | undefined) => bigint;
|
|
118
|
+
invert: (number: bigint, modulo?: bigint | undefined) => bigint;
|
|
119
|
+
_bigintToBytes: (num: bigint) => Uint8Array;
|
|
120
|
+
_bigintToString: (num: bigint) => string;
|
|
121
|
+
_normalizePrivateKey: (key: import("./abstract/utils.js").PrivKey) => bigint;
|
|
122
|
+
_normalizePublicKey: (publicKey: import("./abstract/weierstrass.js").PubKey) => import("./abstract/weierstrass.js").PointType<bigint>;
|
|
123
|
+
_isWithinCurveOrder: (num: bigint) => boolean;
|
|
124
|
+
_isValidFieldElement: (num: bigint) => boolean;
|
|
125
|
+
_weierstrassEquation: (x: bigint) => bigint;
|
|
126
|
+
isValidPrivateKey(privateKey: import("./abstract/utils.js").PrivKey): boolean;
|
|
127
|
+
hashToPrivateKey: (hash: import("./abstract/utils.js").Hex) => Uint8Array;
|
|
128
|
+
randomPrivateKey: () => Uint8Array;
|
|
129
|
+
};
|
|
130
|
+
}>;
|
package/lib/p224.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.secp224r1 = exports.P224 = void 0;
|
|
4
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
5
|
+
const _shortw_utils_js_1 = require("./_shortw_utils.js");
|
|
6
|
+
const sha256_1 = require("@noble/hashes/sha256");
|
|
7
|
+
const modular_js_1 = require("./abstract/modular.js");
|
|
8
|
+
// NIST secp224r1 aka P224
|
|
9
|
+
// https://www.secg.org/sec2-v2.pdf, https://neuromancer.sk/std/nist/P-224
|
|
10
|
+
exports.P224 = (0, _shortw_utils_js_1.createCurve)({
|
|
11
|
+
// Params: a, b
|
|
12
|
+
a: BigInt('0xfffffffffffffffffffffffffffffffefffffffffffffffffffffffe'),
|
|
13
|
+
b: BigInt('0xb4050a850c04b3abf54132565044b0b7d7bfd8ba270b39432355ffb4'),
|
|
14
|
+
// Field over which we'll do calculations; 2n**224n - 2n**96n + 1n
|
|
15
|
+
Fp: (0, modular_js_1.Fp)(BigInt('0xffffffffffffffffffffffffffffffff000000000000000000000001')),
|
|
16
|
+
// Curve order, total count of valid points in the field
|
|
17
|
+
n: BigInt('0xffffffffffffffffffffffffffff16a2e0b8f03e13dd29455c5c2a3d'),
|
|
18
|
+
// Base point (x, y) aka generator point
|
|
19
|
+
Gx: BigInt('0xb70e0cbd6bb4bf7f321390b94a03c1d356c21122343280d6115c1d21'),
|
|
20
|
+
Gy: BigInt('0xbd376388b5f723fb4c22dfe6cd4375a05a07476444d5819985007e34'),
|
|
21
|
+
h: BigInt(1),
|
|
22
|
+
lowS: false,
|
|
23
|
+
}, sha256_1.sha224);
|
|
24
|
+
exports.secp224r1 = exports.P224;
|