@noble/curves 0.4.0 → 0.5.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.
Files changed (72) hide show
  1. package/README.md +203 -162
  2. package/lib/_shortw_utils.d.ts +75 -0
  3. package/lib/_shortw_utils.js +20 -0
  4. package/lib/{bls.d.ts → abstract/bls.d.ts} +2 -1
  5. package/lib/{bls.js → abstract/bls.js} +28 -27
  6. package/lib/{edwards.d.ts → abstract/edwards.d.ts} +17 -0
  7. package/lib/{edwards.js → abstract/edwards.js} +45 -4
  8. package/lib/{group.d.ts → abstract/group.d.ts} +2 -1
  9. package/lib/{group.js → abstract/group.js} +4 -3
  10. package/lib/{hashToCurve.d.ts → abstract/hash-to-curve.d.ts} +6 -0
  11. package/lib/{hashToCurve.js → abstract/hash-to-curve.js} +15 -2
  12. package/lib/{modular.d.ts → abstract/modular.d.ts} +10 -4
  13. package/lib/{modular.js → abstract/modular.js} +110 -19
  14. package/lib/{montgomery.d.ts → abstract/montgomery.d.ts} +2 -1
  15. package/lib/{montgomery.js → abstract/montgomery.js} +17 -8
  16. package/lib/{utils.d.ts → abstract/utils.d.ts} +1 -1
  17. package/lib/{utils.js → abstract/utils.js} +1 -1
  18. package/lib/{weierstrass.d.ts → abstract/weierstrass.d.ts} +28 -16
  19. package/lib/{weierstrass.js → abstract/weierstrass.js} +261 -127
  20. package/lib/bls12-381.d.ts +66 -0
  21. package/lib/bls12-381.js +1132 -0
  22. package/lib/bn.d.ts +7 -0
  23. package/lib/bn.js +24 -0
  24. package/lib/ed25519.d.ts +48 -0
  25. package/lib/ed25519.js +322 -0
  26. package/lib/ed448.d.ts +3 -0
  27. package/lib/ed448.js +128 -0
  28. package/lib/esm/_shortw_utils.js +15 -0
  29. package/lib/esm/{bls.js → abstract/bls.js} +25 -24
  30. package/lib/esm/{edwards.js → abstract/edwards.js} +45 -4
  31. package/lib/esm/{group.js → abstract/group.js} +4 -3
  32. package/lib/esm/{hashToCurve.js → abstract/hash-to-curve.js} +13 -1
  33. package/lib/esm/{modular.js → abstract/modular.js} +108 -18
  34. package/lib/esm/{montgomery.js → abstract/montgomery.js} +17 -8
  35. package/lib/esm/{utils.js → abstract/utils.js} +1 -1
  36. package/lib/esm/{weierstrass.js → abstract/weierstrass.js} +255 -123
  37. package/lib/esm/bls12-381.js +1129 -0
  38. package/lib/esm/bn.js +21 -0
  39. package/lib/esm/ed25519.js +318 -0
  40. package/lib/esm/ed448.js +125 -0
  41. package/lib/esm/index.js +2 -0
  42. package/lib/esm/jubjub.js +52 -0
  43. package/lib/esm/p192.js +21 -0
  44. package/lib/esm/p224.js +21 -0
  45. package/lib/esm/p256.js +39 -0
  46. package/lib/esm/p384.js +44 -0
  47. package/lib/esm/p521.js +58 -0
  48. package/lib/esm/pasta.js +29 -0
  49. package/lib/esm/secp256k1.js +290 -0
  50. package/lib/esm/stark.js +222 -0
  51. package/lib/index.d.ts +0 -0
  52. package/lib/index.js +2 -0
  53. package/lib/jubjub.d.ts +7 -0
  54. package/lib/jubjub.js +57 -0
  55. package/lib/p192.d.ts +130 -0
  56. package/lib/p192.js +24 -0
  57. package/lib/p224.d.ts +130 -0
  58. package/lib/p224.js +24 -0
  59. package/lib/p256.d.ts +130 -0
  60. package/lib/p256.js +42 -0
  61. package/lib/p384.d.ts +130 -0
  62. package/lib/p384.js +47 -0
  63. package/lib/p521.d.ts +131 -0
  64. package/lib/p521.js +61 -0
  65. package/lib/pasta.d.ts +4 -0
  66. package/lib/pasta.js +32 -0
  67. package/lib/secp256k1.d.ts +96 -0
  68. package/lib/secp256k1.js +294 -0
  69. package/lib/stark.d.ts +72 -0
  70. package/lib/stark.js +243 -0
  71. package/package.json +146 -50
  72. package/index.js +0 -1
package/lib/stark.d.ts ADDED
@@ -0,0 +1,72 @@
1
+ import { ProjectivePointType } from './abstract/weierstrass.js';
2
+ import * as cutils from './abstract/utils.js';
3
+ declare type ProjectivePoint = ProjectivePointType<bigint>;
4
+ export declare const starkCurve: import("./abstract/weierstrass.js").CurveFn;
5
+ declare function getPublicKey0x(privKey: Hex, isCompressed?: boolean): Uint8Array;
6
+ declare function getSharedSecret0x(privKeyA: Hex, pubKeyB: Hex): Uint8Array;
7
+ declare function sign0x(msgHash: Hex, privKey: Hex, opts: any): import("./abstract/weierstrass.js").SignatureType;
8
+ declare function verify0x(signature: Hex, msgHash: Hex, pubKey: Hex): boolean;
9
+ declare const CURVE: Readonly<{
10
+ readonly nBitLength: number;
11
+ readonly nByteLength: number;
12
+ readonly Fp: import("./abstract/modular.js").Field<bigint>;
13
+ readonly n: bigint;
14
+ readonly h: bigint;
15
+ readonly hEff?: bigint | undefined;
16
+ readonly Gx: bigint;
17
+ readonly Gy: bigint;
18
+ readonly wrapPrivateKey?: boolean | undefined;
19
+ readonly allowInfinityPoint?: boolean | undefined;
20
+ readonly a: bigint;
21
+ readonly b: bigint;
22
+ readonly normalizePrivateKey?: ((key: cutils.PrivKey) => cutils.PrivKey) | undefined;
23
+ readonly endo?: {
24
+ beta: bigint;
25
+ splitScalar: (k: bigint) => {
26
+ k1neg: boolean;
27
+ k1: bigint;
28
+ k2neg: boolean;
29
+ k2: bigint;
30
+ };
31
+ } | undefined;
32
+ readonly isTorsionFree?: ((c: import("./abstract/weierstrass.js").ProjectiveConstructor<bigint>, point: ProjectivePointType<bigint>) => boolean) | undefined;
33
+ readonly clearCofactor?: ((c: import("./abstract/weierstrass.js").ProjectiveConstructor<bigint>, point: ProjectivePointType<bigint>) => ProjectivePointType<bigint>) | undefined;
34
+ readonly htfDefaults?: import("./abstract/hash-to-curve.js").htfOpts | undefined;
35
+ readonly mapToCurve?: ((scalar: bigint[]) => {
36
+ x: bigint;
37
+ y: bigint;
38
+ }) | undefined;
39
+ lowS: boolean;
40
+ readonly hash: cutils.CHash;
41
+ readonly hmac: (key: Uint8Array, ...messages: Uint8Array[]) => Uint8Array;
42
+ readonly randomBytes: (bytesLength?: number | undefined) => Uint8Array;
43
+ readonly truncateHash?: ((hash: Uint8Array, truncateOnly?: boolean | undefined) => bigint) | undefined;
44
+ }>, Point: import("./abstract/weierstrass.js").PointConstructor<bigint>, ProjectivePoint: import("./abstract/weierstrass.js").ProjectiveConstructor<bigint>, Signature: import("./abstract/weierstrass.js").SignatureConstructor;
45
+ export declare const utils: {
46
+ mod: (a: bigint, b?: bigint | undefined) => bigint;
47
+ invert: (number: bigint, modulo?: bigint | undefined) => bigint;
48
+ _bigintToBytes: (num: bigint) => Uint8Array;
49
+ _bigintToString: (num: bigint) => string;
50
+ _normalizePrivateKey: (key: cutils.PrivKey) => bigint;
51
+ _normalizePublicKey: (publicKey: import("./abstract/weierstrass.js").PubKey) => import("./abstract/weierstrass.js").PointType<bigint>;
52
+ _isWithinCurveOrder: (num: bigint) => boolean;
53
+ _isValidFieldElement: (num: bigint) => boolean;
54
+ _weierstrassEquation: (x: bigint) => bigint;
55
+ isValidPrivateKey(privateKey: cutils.PrivKey): boolean;
56
+ hashToPrivateKey: (hash: cutils.Hex) => Uint8Array;
57
+ randomPrivateKey: () => Uint8Array;
58
+ };
59
+ export { CURVE, Point, Signature, ProjectivePoint, getPublicKey0x as getPublicKey, getSharedSecret0x as getSharedSecret, sign0x as sign, verify0x as verify, };
60
+ export declare const bytesToHexEth: (uint8a: Uint8Array) => string;
61
+ export declare const strip0x: (hex: string) => string;
62
+ export declare const numberToHexEth: (num: bigint | number) => string;
63
+ declare type Hex = Uint8Array | string;
64
+ export declare function grindKey(seed: Hex): string;
65
+ export declare function getStarkKey(privateKey: Hex): string;
66
+ export declare function ethSigToPrivate(signature: string): string;
67
+ export declare function getAccountPath(layer: string, application: string, ethereumAddress: string, index: number): string;
68
+ declare type PedersenArg = Hex | bigint | number;
69
+ export declare function pedersen(x: PedersenArg, y: PedersenArg): string;
70
+ export declare function hashChain(data: PedersenArg[], fn?: typeof pedersen): PedersenArg;
71
+ export declare const computeHashOnElements: (data: PedersenArg[], fn?: typeof pedersen) => PedersenArg;
72
+ export declare const keccak: (data: Uint8Array) => bigint;
package/lib/stark.js ADDED
@@ -0,0 +1,243 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.keccak = exports.computeHashOnElements = exports.hashChain = exports.pedersen = exports.getAccountPath = exports.ethSigToPrivate = exports.getStarkKey = exports.grindKey = exports.numberToHexEth = exports.strip0x = exports.bytesToHexEth = exports.verify = exports.sign = exports.getSharedSecret = exports.getPublicKey = exports.ProjectivePoint = exports.Signature = exports.Point = exports.CURVE = exports.utils = exports.starkCurve = void 0;
4
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
5
+ const sha3_1 = require("@noble/hashes/sha3");
6
+ const sha256_1 = require("@noble/hashes/sha256");
7
+ const weierstrass_js_1 = require("./abstract/weierstrass.js");
8
+ const cutils = require("./abstract/utils.js");
9
+ const modular_js_1 = require("./abstract/modular.js");
10
+ const _shortw_utils_js_1 = require("./_shortw_utils.js");
11
+ // Stark-friendly elliptic curve
12
+ // https://docs.starkware.co/starkex/stark-curve.html
13
+ const CURVE_N = BigInt('3618502788666131213697322783095070105526743751716087489154079457884512865583');
14
+ const nBitLength = 252;
15
+ exports.starkCurve = (0, weierstrass_js_1.weierstrass)({
16
+ // Params: a, b
17
+ a: BigInt(1),
18
+ b: BigInt('3141592653589793238462643383279502884197169399375105820974944592307816406665'),
19
+ // Field over which we'll do calculations; 2n**251n + 17n * 2n**192n + 1n
20
+ // There is no efficient sqrt for field (P%4==1)
21
+ Fp: (0, modular_js_1.Fp)(BigInt('0x800000000000011000000000000000000000000000000000000000000000001')),
22
+ // Curve order, total count of valid points in the field.
23
+ n: CURVE_N,
24
+ nBitLength: nBitLength,
25
+ // Base point (x, y) aka generator point
26
+ Gx: BigInt('874739451078007766457464989774322083649278607533249481151382481072868806602'),
27
+ Gy: BigInt('152666792071518830868575557812948353041420400780739481342941381225525861407'),
28
+ h: BigInt(1),
29
+ // Default options
30
+ lowS: false,
31
+ ...(0, _shortw_utils_js_1.getHash)(sha256_1.sha256),
32
+ truncateHash: (hash, truncateOnly = false) => {
33
+ // TODO: cleanup, ugly code
34
+ // Fix truncation
35
+ if (!truncateOnly) {
36
+ let hashS = bytesToNumber0x(hash).toString(16);
37
+ if (hashS.length === 63) {
38
+ hashS += '0';
39
+ hash = hexToBytes0x(hashS);
40
+ }
41
+ }
42
+ // Truncate zero bytes on left (compat with elliptic)
43
+ while (hash[0] === 0)
44
+ hash = hash.subarray(1);
45
+ const byteLength = hash.length;
46
+ const delta = byteLength * 8 - nBitLength; // size of curve.n (252 bits)
47
+ let h = hash.length ? bytesToNumber0x(hash) : 0n;
48
+ if (delta > 0)
49
+ h = h >> BigInt(delta);
50
+ if (!truncateOnly && h >= CURVE_N)
51
+ h -= CURVE_N;
52
+ return h;
53
+ },
54
+ });
55
+ // Custom Starknet type conversion functions that can handle 0x and unpadded hex
56
+ function hexToBytes0x(hex) {
57
+ if (typeof hex !== 'string') {
58
+ throw new TypeError('hexToBytes: expected string, got ' + typeof hex);
59
+ }
60
+ hex = (0, exports.strip0x)(hex);
61
+ if (hex.length & 1)
62
+ hex = '0' + hex; // padding
63
+ if (hex.length % 2)
64
+ throw new Error('hexToBytes: received invalid unpadded hex ' + hex.length);
65
+ const array = new Uint8Array(hex.length / 2);
66
+ for (let i = 0; i < array.length; i++) {
67
+ const j = i * 2;
68
+ const hexByte = hex.slice(j, j + 2);
69
+ const byte = Number.parseInt(hexByte, 16);
70
+ if (Number.isNaN(byte) || byte < 0)
71
+ throw new Error('Invalid byte sequence');
72
+ array[i] = byte;
73
+ }
74
+ return array;
75
+ }
76
+ function hexToNumber0x(hex) {
77
+ if (typeof hex !== 'string') {
78
+ throw new TypeError('hexToNumber: expected string, got ' + typeof hex);
79
+ }
80
+ // Big Endian
81
+ // TODO: strip vs no strip?
82
+ return BigInt(`0x${(0, exports.strip0x)(hex)}`);
83
+ }
84
+ function bytesToNumber0x(bytes) {
85
+ return hexToNumber0x(cutils.bytesToHex(bytes));
86
+ }
87
+ function ensureBytes0x(hex) {
88
+ // Uint8Array.from() instead of hash.slice() because node.js Buffer
89
+ // is instance of Uint8Array, and its slice() creates **mutable** copy
90
+ return hex instanceof Uint8Array ? Uint8Array.from(hex) : hexToBytes0x(hex);
91
+ }
92
+ function normalizePrivateKey(privKey) {
93
+ return cutils.bytesToHex(ensureBytes0x(privKey)).padStart(32 * 2, '0');
94
+ }
95
+ function getPublicKey0x(privKey, isCompressed) {
96
+ return exports.starkCurve.getPublicKey(normalizePrivateKey(privKey), isCompressed);
97
+ }
98
+ exports.getPublicKey = getPublicKey0x;
99
+ function getSharedSecret0x(privKeyA, pubKeyB) {
100
+ return exports.starkCurve.getSharedSecret(normalizePrivateKey(privKeyA), pubKeyB);
101
+ }
102
+ exports.getSharedSecret = getSharedSecret0x;
103
+ function sign0x(msgHash, privKey, opts) {
104
+ if (typeof privKey === 'string')
105
+ privKey = (0, exports.strip0x)(privKey).padStart(64, '0');
106
+ return exports.starkCurve.sign(ensureBytes0x(msgHash), normalizePrivateKey(privKey), opts);
107
+ }
108
+ exports.sign = sign0x;
109
+ function verify0x(signature, msgHash, pubKey) {
110
+ const sig = signature instanceof Signature ? signature : ensureBytes0x(signature);
111
+ return exports.starkCurve.verify(sig, ensureBytes0x(msgHash), ensureBytes0x(pubKey));
112
+ }
113
+ exports.verify = verify0x;
114
+ const { CURVE, Point, ProjectivePoint, Signature } = exports.starkCurve;
115
+ exports.CURVE = CURVE;
116
+ exports.Point = Point;
117
+ exports.ProjectivePoint = ProjectivePoint;
118
+ exports.Signature = Signature;
119
+ exports.utils = exports.starkCurve.utils;
120
+ const stripLeadingZeros = (s) => s.replace(/^0+/gm, '');
121
+ const bytesToHexEth = (uint8a) => `0x${stripLeadingZeros(cutils.bytesToHex(uint8a))}`;
122
+ exports.bytesToHexEth = bytesToHexEth;
123
+ const strip0x = (hex) => hex.replace(/^0x/i, '');
124
+ exports.strip0x = strip0x;
125
+ const numberToHexEth = (num) => `0x${num.toString(16)}`;
126
+ exports.numberToHexEth = numberToHexEth;
127
+ // 1. seed generation
128
+ function hashKeyWithIndex(key, index) {
129
+ let indexHex = cutils.numberToHexUnpadded(index);
130
+ if (indexHex.length & 1)
131
+ indexHex = '0' + indexHex;
132
+ return bytesToNumber0x((0, sha256_1.sha256)(cutils.concatBytes(key, hexToBytes0x(indexHex))));
133
+ }
134
+ function grindKey(seed) {
135
+ const _seed = ensureBytes0x(seed);
136
+ const sha256mask = 2n ** 256n;
137
+ const limit = sha256mask - exports.starkCurve.utils.mod(sha256mask, exports.starkCurve.CURVE.n);
138
+ for (let i = 0;; i++) {
139
+ const key = hashKeyWithIndex(_seed, i);
140
+ // key should be in [0, limit)
141
+ if (key < limit)
142
+ return exports.starkCurve.utils.mod(key, exports.starkCurve.CURVE.n).toString(16);
143
+ }
144
+ }
145
+ exports.grindKey = grindKey;
146
+ function getStarkKey(privateKey) {
147
+ return (0, exports.bytesToHexEth)(getPublicKey0x(privateKey, true).slice(1));
148
+ }
149
+ exports.getStarkKey = getStarkKey;
150
+ function ethSigToPrivate(signature) {
151
+ signature = (0, exports.strip0x)(signature.replace(/^0x/, ''));
152
+ if (signature.length !== 130)
153
+ throw new Error('Wrong ethereum signature');
154
+ return grindKey(signature.substring(0, 64));
155
+ }
156
+ exports.ethSigToPrivate = ethSigToPrivate;
157
+ const MASK_31 = 2n ** 31n - 1n;
158
+ const int31 = (n) => Number(n & MASK_31);
159
+ function getAccountPath(layer, application, ethereumAddress, index) {
160
+ const layerNum = int31(bytesToNumber0x((0, sha256_1.sha256)(layer)));
161
+ const applicationNum = int31(bytesToNumber0x((0, sha256_1.sha256)(application)));
162
+ const eth = hexToNumber0x(ethereumAddress);
163
+ return `m/2645'/${layerNum}'/${applicationNum}'/${int31(eth)}'/${int31(eth >> 31n)}'/${index}`;
164
+ }
165
+ exports.getAccountPath = getAccountPath;
166
+ // https://docs.starkware.co/starkex/pedersen-hash-function.html
167
+ const PEDERSEN_POINTS_AFFINE = [
168
+ new Point(2089986280348253421170679821480865132823066470938446095505822317253594081284n, 1713931329540660377023406109199410414810705867260802078187082345529207694986n),
169
+ new Point(996781205833008774514500082376783249102396023663454813447423147977397232763n, 1668503676786377725805489344771023921079126552019160156920634619255970485781n),
170
+ new Point(2251563274489750535117886426533222435294046428347329203627021249169616184184n, 1798716007562728905295480679789526322175868328062420237419143593021674992973n),
171
+ new Point(2138414695194151160943305727036575959195309218611738193261179310511854807447n, 113410276730064486255102093846540133784865286929052426931474106396135072156n),
172
+ new Point(2379962749567351885752724891227938183011949129833673362440656643086021394946n, 776496453633298175483985398648758586525933812536653089401905292063708816422n),
173
+ ];
174
+ // for (const p of PEDERSEN_POINTS) p._setWindowSize(8);
175
+ const PEDERSEN_POINTS = PEDERSEN_POINTS_AFFINE.map(ProjectivePoint.fromAffine);
176
+ function pedersenPrecompute(p1, p2) {
177
+ const out = [];
178
+ let p = p1;
179
+ for (let i = 0; i < 248; i++) {
180
+ out.push(p);
181
+ p = p.double();
182
+ }
183
+ p = p2;
184
+ for (let i = 0; i < 4; i++) {
185
+ out.push(p);
186
+ p = p.double();
187
+ }
188
+ return out;
189
+ }
190
+ const PEDERSEN_POINTS1 = pedersenPrecompute(PEDERSEN_POINTS[1], PEDERSEN_POINTS[2]);
191
+ const PEDERSEN_POINTS2 = pedersenPrecompute(PEDERSEN_POINTS[3], PEDERSEN_POINTS[4]);
192
+ function pedersenArg(arg) {
193
+ let value;
194
+ if (typeof arg === 'bigint')
195
+ value = arg;
196
+ else if (typeof arg === 'number') {
197
+ if (!Number.isSafeInteger(arg))
198
+ throw new Error(`Invalid pedersenArg: ${arg}`);
199
+ value = BigInt(arg);
200
+ }
201
+ else
202
+ value = bytesToNumber0x(ensureBytes0x(arg));
203
+ // [0..Fp)
204
+ if (!(0n <= value && value < exports.starkCurve.CURVE.Fp.ORDER))
205
+ throw new Error(`PedersenArg should be 0 <= value < CURVE.P: ${value}`);
206
+ return value;
207
+ }
208
+ function pedersenSingle(point, value, constants) {
209
+ let x = pedersenArg(value);
210
+ for (let j = 0; j < 252; j++) {
211
+ const pt = constants[j];
212
+ if (pt.x === point.x)
213
+ throw new Error('Same point');
214
+ if ((x & 1n) !== 0n)
215
+ point = point.add(pt);
216
+ x >>= 1n;
217
+ }
218
+ return point;
219
+ }
220
+ // shift_point + x_low * P_0 + x_high * P1 + y_low * P2 + y_high * P3
221
+ function pedersen(x, y) {
222
+ let point = PEDERSEN_POINTS[0];
223
+ point = pedersenSingle(point, x, PEDERSEN_POINTS1);
224
+ point = pedersenSingle(point, y, PEDERSEN_POINTS2);
225
+ return (0, exports.bytesToHexEth)(point.toAffine().toRawBytes(true).slice(1));
226
+ }
227
+ exports.pedersen = pedersen;
228
+ function hashChain(data, fn = pedersen) {
229
+ if (!Array.isArray(data) || data.length < 1)
230
+ throw new Error('data should be array of at least 1 element');
231
+ if (data.length === 1)
232
+ return (0, exports.numberToHexEth)(pedersenArg(data[0]));
233
+ return Array.from(data)
234
+ .reverse()
235
+ .reduce((acc, i) => fn(i, acc));
236
+ }
237
+ exports.hashChain = hashChain;
238
+ // Same as hashChain, but computes hash even for single element and order is not revesed
239
+ const computeHashOnElements = (data, fn = pedersen) => [0, ...data, data.length].reduce((x, y) => fn(x, y));
240
+ exports.computeHashOnElements = computeHashOnElements;
241
+ const MASK_250 = 2n ** 250n - 1n;
242
+ const keccak = (data) => bytesToNumber0x((0, sha3_1.keccak_256)(data)) & MASK_250;
243
+ exports.keccak = keccak;
package/package.json CHANGED
@@ -1,19 +1,17 @@
1
1
  {
2
2
  "name": "@noble/curves",
3
- "version": "0.4.0",
4
- "description": "Minimal, zero-dependency JS implementation of elliptic curve cryptography",
3
+ "version": "0.5.0",
4
+ "description": "Minimal, auditable JS implementation of elliptic curve cryptography",
5
5
  "files": [
6
- "index.js",
7
- "lib",
8
- "lib/esm"
6
+ "lib"
9
7
  ],
10
8
  "scripts": {
11
- "bench": "node curve-definitions/benchmark/index.js",
9
+ "bench": "node benchmark/index.js",
12
10
  "build": "tsc && tsc -p tsconfig.esm.json",
13
11
  "build:release": "rollup -c rollup.config.js",
14
- "lint": "prettier --check 'src/**/*.{js,ts}' 'curve-definitions/src/**/*.{js,ts}'",
15
- "format": "prettier --write 'src/**/*.{js,ts}' 'curve-definitions/src/**/*.{js,ts}'",
16
- "test": "cd curve-definitions; node test/index.test.js"
12
+ "lint": "prettier --check 'src/**/*.{js,ts}' 'test/*.js'",
13
+ "format": "prettier --write 'src/**/*.{js,ts}' 'test/*.js'",
14
+ "test": "node test/index.test.js"
17
15
  },
18
16
  "author": "Paul Miller (https://paulmillr.com)",
19
17
  "homepage": "https://paulmillr.com/noble/",
@@ -22,8 +20,16 @@
22
20
  "url": "https://github.com/paulmillr/noble-curves.git"
23
21
  },
24
22
  "license": "MIT",
23
+ "dependencies": {
24
+ "@noble/hashes": "1.1.5"
25
+ },
25
26
  "devDependencies": {
26
27
  "@rollup/plugin-node-resolve": "13.3.0",
28
+ "@scure/base": "~1.1.1",
29
+ "@scure/bip32": "~1.1.1",
30
+ "@scure/bip39": "~1.1.0",
31
+ "@types/node": "18.11.3",
32
+ "fast-check": "3.0.0",
27
33
  "micro-bmark": "0.2.0",
28
34
  "micro-should": "0.2.0",
29
35
  "prettier": "2.6.2",
@@ -32,55 +38,145 @@
32
38
  },
33
39
  "main": "index.js",
34
40
  "exports": {
35
- "./edwards": {
36
- "types": "./lib/edwards.d.ts",
37
- "import": "./lib/esm/edwards.js",
38
- "default": "./lib/edwards.js"
39
- },
40
- "./modular": {
41
- "types": "./lib/modular.d.ts",
42
- "import": "./lib/esm/modular.js",
43
- "default": "./lib/modular.js"
44
- },
45
- "./montgomery": {
46
- "types": "./lib/montgomery.d.ts",
47
- "import": "./lib/esm/montgomery.js",
48
- "default": "./lib/montgomery.js"
49
- },
50
- "./weierstrass": {
51
- "types": "./lib/weierstrass.d.ts",
52
- "import": "./lib/esm/weierstrass.js",
53
- "default": "./lib/weierstrass.js"
54
- },
55
- "./bls": {
56
- "types": "./lib/bls.d.ts",
57
- "import": "./lib/esm/bls.js",
58
- "default": "./lib/bls.js"
59
- },
60
- "./hashToCurve": {
61
- "types": "./lib/hashToCurve.d.ts",
62
- "import": "./lib/esm/hashToCurve.js",
63
- "default": "./lib/hashToCurve.js"
64
- },
65
- "./group": {
66
- "types": "./lib/group.d.ts",
67
- "import": "./lib/esm/group.js",
68
- "default": "./lib/group.js"
69
- },
70
- "./utils": {
71
- "types": "./lib/utils.d.ts",
72
- "import": "./lib/esm/utils.js",
73
- "default": "./lib/utils.js"
41
+ ".": {
42
+ "types": "./lib/index.d.ts",
43
+ "import": "./lib/esm/index.js",
44
+ "default": "./lib/index.js"
45
+ },
46
+ "./abstract/edwards": {
47
+ "types": "./lib/abstract/edwards.d.ts",
48
+ "import": "./lib/esm/abstract/edwards.js",
49
+ "default": "./lib/abstract/edwards.js"
50
+ },
51
+ "./abstract/modular": {
52
+ "types": "./lib/abstract/modular.d.ts",
53
+ "import": "./lib/esm/abstract/modular.js",
54
+ "default": "./lib/abstract/modular.js"
55
+ },
56
+ "./abstract/montgomery": {
57
+ "types": "./lib/abstract/montgomery.d.ts",
58
+ "import": "./lib/esm/abstract/montgomery.js",
59
+ "default": "./lib/abstract/montgomery.js"
60
+ },
61
+ "./abstract/weierstrass": {
62
+ "types": "./lib/abstract/weierstrass.d.ts",
63
+ "import": "./lib/esm/abstract/weierstrass.js",
64
+ "default": "./lib/abstract/weierstrass.js"
65
+ },
66
+ "./abstract/bls": {
67
+ "types": "./lib/abstract/bls.d.ts",
68
+ "import": "./lib/esm/abstract/bls.js",
69
+ "default": "./lib/abstract/bls.js"
70
+ },
71
+ "./abstract/hash-to-curve": {
72
+ "types": "./lib/abstract/hash-to-curve.d.ts",
73
+ "import": "./lib/esm/abstract/hash-to-curve.js",
74
+ "default": "./lib/abstract/hash-to-curve.js"
75
+ },
76
+ "./abstract/group": {
77
+ "types": "./lib/abstract/group.d.ts",
78
+ "import": "./lib/esm/abstract/group.js",
79
+ "default": "./lib/abstract/group.js"
80
+ },
81
+ "./abstract/utils": {
82
+ "types": "./lib/abstract/utils.d.ts",
83
+ "import": "./lib/esm/abstract/utils.js",
84
+ "default": "./lib/abstract/utils.js"
85
+ },
86
+ "./_shortw_utils": {
87
+ "types": "./lib/_shortw_utils.d.ts",
88
+ "import": "./lib/esm/_shortw_utils.js",
89
+ "default": "./lib/_shortw_utils.js"
90
+ },
91
+ "./bls12-381": {
92
+ "types": "./lib/bls12-381.d.ts",
93
+ "import": "./lib/esm/bls12-381.js",
94
+ "default": "./lib/bls12-381.js"
95
+ },
96
+ "./bn": {
97
+ "types": "./lib/bn.d.ts",
98
+ "import": "./lib/esm/bn.js",
99
+ "default": "./lib/bn.js"
100
+ },
101
+ "./ed25519": {
102
+ "types": "./lib/ed25519.d.ts",
103
+ "import": "./lib/esm/ed25519.js",
104
+ "default": "./lib/ed25519.js"
105
+ },
106
+ "./ed448": {
107
+ "types": "./lib/ed448.d.ts",
108
+ "import": "./lib/esm/ed448.js",
109
+ "default": "./lib/ed448.js"
110
+ },
111
+ "./index": {
112
+ "types": "./lib/index.d.ts",
113
+ "import": "./lib/esm/index.js",
114
+ "default": "./lib/index.js"
115
+ },
116
+ "./jubjub": {
117
+ "types": "./lib/jubjub.d.ts",
118
+ "import": "./lib/esm/jubjub.js",
119
+ "default": "./lib/jubjub.js"
120
+ },
121
+ "./p192": {
122
+ "types": "./lib/p192.d.ts",
123
+ "import": "./lib/esm/p192.js",
124
+ "default": "./lib/p192.js"
125
+ },
126
+ "./p224": {
127
+ "types": "./lib/p224.d.ts",
128
+ "import": "./lib/esm/p224.js",
129
+ "default": "./lib/p224.js"
130
+ },
131
+ "./p256": {
132
+ "types": "./lib/p256.d.ts",
133
+ "import": "./lib/esm/p256.js",
134
+ "default": "./lib/p256.js"
135
+ },
136
+ "./p384": {
137
+ "types": "./lib/p384.d.ts",
138
+ "import": "./lib/esm/p384.js",
139
+ "default": "./lib/p384.js"
140
+ },
141
+ "./p521": {
142
+ "types": "./lib/p521.d.ts",
143
+ "import": "./lib/esm/p521.js",
144
+ "default": "./lib/p521.js"
145
+ },
146
+ "./pasta": {
147
+ "types": "./lib/pasta.d.ts",
148
+ "import": "./lib/esm/pasta.js",
149
+ "default": "./lib/pasta.js"
150
+ },
151
+ "./secp256k1": {
152
+ "types": "./lib/secp256k1.d.ts",
153
+ "import": "./lib/esm/secp256k1.js",
154
+ "default": "./lib/secp256k1.js"
155
+ },
156
+ "./stark": {
157
+ "types": "./lib/stark.d.ts",
158
+ "import": "./lib/esm/stark.js",
159
+ "default": "./lib/stark.js"
74
160
  }
75
161
  },
76
162
  "keywords": [
77
163
  "elliptic",
78
164
  "curve",
79
165
  "cryptography",
80
- "hyperelliptic",
166
+ "weierstrass",
167
+ "montgomery",
168
+ "edwards",
81
169
  "p256",
82
170
  "p384",
83
171
  "p521",
172
+ "secp256r1",
173
+ "secp256k1",
174
+ "ed25519",
175
+ "ed448",
176
+ "bls12-381",
177
+ "bn254",
178
+ "pasta",
179
+ "bls",
84
180
  "nist",
85
181
  "ecc",
86
182
  "ecdsa",
@@ -93,4 +189,4 @@
93
189
  "url": "https://paulmillr.com/funding/"
94
190
  }
95
191
  ]
96
- }
192
+ }
package/index.js DELETED
@@ -1 +0,0 @@
1
- throw new Error('Incorrect usage. Import submodules instead');