@noble/curves 0.8.0 → 0.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/README.md +12 -17
  2. package/_shortw_utils.js +13 -8
  3. package/_shortw_utils.js.map +1 -1
  4. package/abstract/bls.js +16 -12
  5. package/abstract/bls.js.map +1 -1
  6. package/abstract/curve.js +12 -7
  7. package/abstract/curve.js.map +1 -1
  8. package/abstract/edwards.js +20 -16
  9. package/abstract/edwards.js.map +1 -1
  10. package/abstract/hash-to-curve.js +26 -18
  11. package/abstract/hash-to-curve.js.map +1 -1
  12. package/abstract/modular.js +44 -24
  13. package/abstract/modular.js.map +1 -1
  14. package/abstract/montgomery.js +15 -11
  15. package/abstract/montgomery.js.map +1 -1
  16. package/abstract/poseidon.js +12 -6
  17. package/abstract/poseidon.js.map +1 -1
  18. package/abstract/utils.js +41 -19
  19. package/abstract/utils.js.map +1 -1
  20. package/abstract/weierstrass.js +28 -21
  21. package/abstract/weierstrass.js.map +1 -1
  22. package/bls12-381.js +66 -63
  23. package/bls12-381.js.map +1 -1
  24. package/bn.js +10 -7
  25. package/bn.js.map +1 -1
  26. package/ed25519.js +78 -72
  27. package/ed25519.js.map +1 -1
  28. package/ed448.js +41 -37
  29. package/ed448.js.map +1 -1
  30. package/esm/_shortw_utils.js +17 -0
  31. package/esm/_shortw_utils.js.map +1 -0
  32. package/esm/abstract/bls.js +226 -0
  33. package/esm/abstract/bls.js.map +1 -0
  34. package/esm/abstract/curve.js +152 -0
  35. package/esm/abstract/curve.js.map +1 -0
  36. package/esm/abstract/edwards.js +409 -0
  37. package/esm/abstract/edwards.js.map +1 -0
  38. package/esm/abstract/hash-to-curve.js +166 -0
  39. package/esm/abstract/hash-to-curve.js.map +1 -0
  40. package/esm/abstract/modular.js +346 -0
  41. package/esm/abstract/modular.js.map +1 -0
  42. package/esm/abstract/montgomery.js +157 -0
  43. package/esm/abstract/montgomery.js.map +1 -0
  44. package/esm/abstract/poseidon.js +110 -0
  45. package/esm/abstract/poseidon.js.map +1 -0
  46. package/esm/abstract/utils.js +222 -0
  47. package/esm/abstract/utils.js.map +1 -0
  48. package/esm/abstract/weierstrass.js +1011 -0
  49. package/esm/abstract/weierstrass.js.map +1 -0
  50. package/esm/bls12-381.js +1173 -0
  51. package/esm/bls12-381.js.map +1 -0
  52. package/esm/bn.js +22 -0
  53. package/esm/bn.js.map +1 -0
  54. package/esm/ed25519.js +397 -0
  55. package/esm/ed25519.js.map +1 -0
  56. package/esm/ed448.js +213 -0
  57. package/esm/ed448.js.map +1 -0
  58. package/esm/index.js +3 -0
  59. package/esm/index.js.map +1 -0
  60. package/esm/jubjub.js +54 -0
  61. package/esm/jubjub.js.map +1 -0
  62. package/esm/p256.js +42 -0
  63. package/esm/p256.js.map +1 -0
  64. package/esm/p384.js +47 -0
  65. package/esm/p384.js.map +1 -0
  66. package/esm/p521.js +48 -0
  67. package/esm/p521.js.map +1 -0
  68. package/esm/package.json +7 -0
  69. package/esm/pasta.js +30 -0
  70. package/esm/pasta.js.map +1 -0
  71. package/esm/secp256k1.js +252 -0
  72. package/esm/secp256k1.js.map +1 -0
  73. package/jubjub.js +22 -17
  74. package/jubjub.js.map +1 -1
  75. package/p256.js +17 -13
  76. package/p256.js.map +1 -1
  77. package/p384.js +17 -13
  78. package/p384.js.map +1 -1
  79. package/p521.js +17 -13
  80. package/p521.js.map +1 -1
  81. package/package.json +27 -9
  82. package/pasta.js +19 -16
  83. package/pasta.js.map +1 -1
  84. package/secp256k1.js +57 -53
  85. package/secp256k1.js.map +1 -1
  86. package/src/stark.ts +0 -341
  87. package/stark.d.ts +0 -81
  88. package/stark.d.ts.map +0 -1
  89. package/stark.js +0 -277
  90. package/stark.js.map +0 -1
package/src/stark.ts DELETED
@@ -1,341 +0,0 @@
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 { utf8ToBytes } from '@noble/hashes/utils';
5
- import { Fp, mod, Field, validateField } from './abstract/modular.js';
6
- import { poseidon } from './abstract/poseidon.js';
7
- import { weierstrass, ProjPointType, SignatureType } from './abstract/weierstrass.js';
8
- import * as u from './abstract/utils.js';
9
- import type { Hex } from './abstract/utils.js';
10
- import { getHash } from './_shortw_utils.js';
11
-
12
- // Stark-friendly elliptic curve
13
- // https://docs.starkware.co/starkex/stark-curve.html
14
-
15
- type ProjectivePoint = ProjPointType<bigint>;
16
- const CURVE_ORDER = BigInt(
17
- '3618502788666131213697322783095070105526743751716087489154079457884512865583'
18
- );
19
- const nBitLength = 252;
20
- function bits2int(bytes: Uint8Array): bigint {
21
- while (bytes[0] === 0) bytes = bytes.subarray(1); // strip leading 0s
22
- // Copy-pasted from weierstrass.ts
23
- const delta = bytes.length * 8 - nBitLength;
24
- const num = u.bytesToNumberBE(bytes);
25
- return delta > 0 ? num >> BigInt(delta) : num;
26
- }
27
- function hex0xToBytes(hex: string): Uint8Array {
28
- if (typeof hex === 'string') {
29
- hex = strip0x(hex); // allow 0x prefix
30
- if (hex.length & 1) hex = '0' + hex; // allow unpadded hex
31
- }
32
- return u.hexToBytes(hex);
33
- }
34
- const curve = weierstrass({
35
- a: BigInt(1), // Params: a, b
36
- b: BigInt('3141592653589793238462643383279502884197169399375105820974944592307816406665'),
37
- // Field over which we'll do calculations; 2n**251n + 17n * 2n**192n + 1n
38
- // There is no efficient sqrt for field (P%4==1)
39
- Fp: Fp(BigInt('0x800000000000011000000000000000000000000000000000000000000000001')),
40
- n: CURVE_ORDER, // Curve order, total count of valid points in the field.
41
- nBitLength, // len(bin(N).replace('0b',''))
42
- // Base point (x, y) aka generator point
43
- Gx: BigInt('874739451078007766457464989774322083649278607533249481151382481072868806602'),
44
- Gy: BigInt('152666792071518830868575557812948353041420400780739481342941381225525861407'),
45
- h: BigInt(1), // cofactor
46
- lowS: false, // Allow high-s signatures
47
- ...getHash(sha256),
48
- // Custom truncation routines for stark curve
49
- bits2int,
50
- bits2int_modN: (bytes: Uint8Array): bigint => {
51
- // 2102820b232636d200cb21f1d330f20d096cae09d1bf3edb1cc333ddee11318 =>
52
- // 2102820b232636d200cb21f1d330f20d096cae09d1bf3edb1cc333ddee113180
53
- const hex = u.bytesToNumberBE(bytes).toString(16); // toHex unpadded
54
- if (hex.length === 63) bytes = hex0xToBytes(hex + '0'); // append trailing 0
55
- return mod(bits2int(bytes), CURVE_ORDER);
56
- },
57
- });
58
- export const _starkCurve = curve;
59
-
60
- function ensureBytes(hex: Hex): Uint8Array {
61
- return u.ensureBytes('', typeof hex === 'string' ? hex0xToBytes(hex) : hex);
62
- }
63
-
64
- function normPrivKey(privKey: Hex): string {
65
- return u.bytesToHex(ensureBytes(privKey)).padStart(64, '0');
66
- }
67
- export function getPublicKey(privKey: Hex, isCompressed = false): Uint8Array {
68
- return curve.getPublicKey(normPrivKey(privKey), isCompressed);
69
- }
70
- export function getSharedSecret(privKeyA: Hex, pubKeyB: Hex): Uint8Array {
71
- return curve.getSharedSecret(normPrivKey(privKeyA), pubKeyB);
72
- }
73
- export function sign(msgHash: Hex, privKey: Hex, opts?: any): SignatureType {
74
- return curve.sign(ensureBytes(msgHash), normPrivKey(privKey), opts);
75
- }
76
- export function verify(signature: SignatureType | Hex, msgHash: Hex, pubKey: Hex) {
77
- const sig = signature instanceof Signature ? signature : ensureBytes(signature);
78
- return curve.verify(sig, ensureBytes(msgHash), ensureBytes(pubKey));
79
- }
80
-
81
- const { CURVE, ProjectivePoint, Signature, utils } = curve;
82
- export { CURVE, ProjectivePoint, Signature, utils };
83
-
84
- function extractX(bytes: Uint8Array): string {
85
- const hex = u.bytesToHex(bytes.subarray(1));
86
- const stripped = hex.replace(/^0+/gm, ''); // strip leading 0s
87
- return `0x${stripped}`;
88
- }
89
- function strip0x(hex: string) {
90
- return hex.replace(/^0x/i, '');
91
- }
92
- function numberTo0x16(num: bigint) {
93
- // can't use utils.numberToHexUnpadded: adds leading 0 for even byte length
94
- return `0x${num.toString(16)}`;
95
- }
96
-
97
- // seed generation
98
- export function grindKey(seed: Hex) {
99
- const _seed = ensureBytes(seed);
100
- const sha256mask = 2n ** 256n;
101
- const limit = sha256mask - mod(sha256mask, CURVE_ORDER);
102
- for (let i = 0; ; i++) {
103
- const key = sha256Num(u.concatBytes(_seed, u.numberToVarBytesBE(BigInt(i))));
104
- if (key < limit) return mod(key, CURVE_ORDER).toString(16); // key should be in [0, limit)
105
- if (i === 100000) throw new Error('grindKey is broken: tried 100k vals'); // prevent dos
106
- }
107
- }
108
-
109
- export function getStarkKey(privateKey: Hex): string {
110
- return extractX(getPublicKey(privateKey, true));
111
- }
112
-
113
- export function ethSigToPrivate(signature: string): string {
114
- signature = strip0x(signature);
115
- if (signature.length !== 130) throw new Error('Wrong ethereum signature');
116
- return grindKey(signature.substring(0, 64));
117
- }
118
-
119
- const MASK_31 = 2n ** 31n - 1n;
120
- const int31 = (n: bigint) => Number(n & MASK_31);
121
- export function getAccountPath(
122
- layer: string,
123
- application: string,
124
- ethereumAddress: string,
125
- index: number
126
- ): string {
127
- const layerNum = int31(sha256Num(layer));
128
- const applicationNum = int31(sha256Num(application));
129
- const eth = u.hexToNumber(strip0x(ethereumAddress));
130
- return `m/2645'/${layerNum}'/${applicationNum}'/${int31(eth)}'/${int31(eth >> 31n)}'/${index}`;
131
- }
132
-
133
- // https://docs.starkware.co/starkex/pedersen-hash-function.html
134
- const PEDERSEN_POINTS = [
135
- new ProjectivePoint(
136
- 2089986280348253421170679821480865132823066470938446095505822317253594081284n,
137
- 1713931329540660377023406109199410414810705867260802078187082345529207694986n,
138
- 1n
139
- ),
140
- new ProjectivePoint(
141
- 996781205833008774514500082376783249102396023663454813447423147977397232763n,
142
- 1668503676786377725805489344771023921079126552019160156920634619255970485781n,
143
- 1n
144
- ),
145
- new ProjectivePoint(
146
- 2251563274489750535117886426533222435294046428347329203627021249169616184184n,
147
- 1798716007562728905295480679789526322175868328062420237419143593021674992973n,
148
- 1n
149
- ),
150
- new ProjectivePoint(
151
- 2138414695194151160943305727036575959195309218611738193261179310511854807447n,
152
- 113410276730064486255102093846540133784865286929052426931474106396135072156n,
153
- 1n
154
- ),
155
- new ProjectivePoint(
156
- 2379962749567351885752724891227938183011949129833673362440656643086021394946n,
157
- 776496453633298175483985398648758586525933812536653089401905292063708816422n,
158
- 1n
159
- ),
160
- ];
161
-
162
- function pedersenPrecompute(p1: ProjectivePoint, p2: ProjectivePoint): ProjectivePoint[] {
163
- const out: ProjectivePoint[] = [];
164
- let p = p1;
165
- for (let i = 0; i < 248; i++) {
166
- out.push(p);
167
- p = p.double();
168
- }
169
- // NOTE: we cannot use wNAF here, because last 4 bits will require full 248 bits multiplication
170
- // We can add support for this to wNAF, but it will complicate wNAF.
171
- p = p2;
172
- for (let i = 0; i < 4; i++) {
173
- out.push(p);
174
- p = p.double();
175
- }
176
- return out;
177
- }
178
- const PEDERSEN_POINTS1 = pedersenPrecompute(PEDERSEN_POINTS[1], PEDERSEN_POINTS[2]);
179
- const PEDERSEN_POINTS2 = pedersenPrecompute(PEDERSEN_POINTS[3], PEDERSEN_POINTS[4]);
180
-
181
- type PedersenArg = Hex | bigint | number;
182
- function pedersenArg(arg: PedersenArg): bigint {
183
- let value: bigint;
184
- if (typeof arg === 'bigint') {
185
- value = arg;
186
- } else if (typeof arg === 'number') {
187
- if (!Number.isSafeInteger(arg)) throw new Error(`Invalid pedersenArg: ${arg}`);
188
- value = BigInt(arg);
189
- } else {
190
- value = u.bytesToNumberBE(ensureBytes(arg));
191
- }
192
- if (!(0n <= value && value < curve.CURVE.Fp.ORDER))
193
- throw new Error(`PedersenArg should be 0 <= value < CURVE.P: ${value}`); // [0..Fp)
194
- return value;
195
- }
196
-
197
- function pedersenSingle(point: ProjectivePoint, value: PedersenArg, constants: ProjectivePoint[]) {
198
- let x = pedersenArg(value);
199
- for (let j = 0; j < 252; j++) {
200
- const pt = constants[j];
201
- if (pt.equals(point)) throw new Error('Same point');
202
- if ((x & 1n) !== 0n) point = point.add(pt);
203
- x >>= 1n;
204
- }
205
- return point;
206
- }
207
-
208
- // shift_point + x_low * P_0 + x_high * P1 + y_low * P2 + y_high * P3
209
- export function pedersen(x: PedersenArg, y: PedersenArg): string {
210
- let point: ProjectivePoint = PEDERSEN_POINTS[0];
211
- point = pedersenSingle(point, x, PEDERSEN_POINTS1);
212
- point = pedersenSingle(point, y, PEDERSEN_POINTS2);
213
- return extractX(point.toRawBytes(true));
214
- }
215
-
216
- export function hashChain(data: PedersenArg[], fn = pedersen) {
217
- if (!Array.isArray(data) || data.length < 1)
218
- throw new Error('data should be array of at least 1 element');
219
- if (data.length === 1) return numberTo0x16(pedersenArg(data[0]));
220
- return Array.from(data)
221
- .reverse()
222
- .reduce((acc, i) => fn(i, acc));
223
- }
224
- // Same as hashChain, but computes hash even for single element and order is not revesed
225
- export const computeHashOnElements = (data: PedersenArg[], fn = pedersen) =>
226
- [0, ...data, data.length].reduce((x, y) => fn(x, y));
227
-
228
- const MASK_250 = u.bitMask(250);
229
- export const keccak = (data: Uint8Array): bigint => u.bytesToNumberBE(keccak_256(data)) & MASK_250;
230
- const sha256Num = (data: Uint8Array | string): bigint => u.bytesToNumberBE(sha256(data));
231
-
232
- // Poseidon hash
233
- export const Fp253 = Fp(
234
- BigInt('14474011154664525231415395255581126252639794253786371766033694892385558855681')
235
- ); // 2^253 + 2^199 + 1
236
- export const Fp251 = Fp(
237
- BigInt('3618502788666131213697322783095070105623107215331596699973092056135872020481')
238
- ); // 2^251 + 17 * 2^192 + 1
239
-
240
- function poseidonRoundConstant(Fp: Field<bigint>, name: string, idx: number) {
241
- const val = Fp.fromBytes(sha256(utf8ToBytes(`${name}${idx}`)));
242
- return Fp.create(val);
243
- }
244
-
245
- // NOTE: doesn't check eiginvalues and possible can create unsafe matrix. But any filtration here will break compatibility with starknet
246
- // Please use only if you really know what you doing.
247
- // https://eprint.iacr.org/2019/458.pdf Section 2.3 (Avoiding Insecure Matrices)
248
- export function _poseidonMDS(Fp: Field<bigint>, name: string, m: number, attempt = 0) {
249
- const x_values: bigint[] = [];
250
- const y_values: bigint[] = [];
251
- for (let i = 0; i < m; i++) {
252
- x_values.push(poseidonRoundConstant(Fp, `${name}x`, attempt * m + i));
253
- y_values.push(poseidonRoundConstant(Fp, `${name}y`, attempt * m + i));
254
- }
255
- if (new Set([...x_values, ...y_values]).size !== 2 * m)
256
- throw new Error('X and Y values are not distinct');
257
- return x_values.map((x) => y_values.map((y) => Fp.inv(Fp.sub(x, y))));
258
- }
259
-
260
- const MDS_SMALL = [
261
- [3, 1, 1],
262
- [1, -1, 1],
263
- [1, 1, -2],
264
- ].map((i) => i.map(BigInt));
265
-
266
- export type PoseidonOpts = {
267
- Fp: Field<bigint>;
268
- rate: number;
269
- capacity: number;
270
- roundsFull: number;
271
- roundsPartial: number;
272
- };
273
-
274
- export type PoseidonFn = ReturnType<typeof poseidon> & {
275
- m: number;
276
- rate: number;
277
- capacity: number;
278
- };
279
-
280
- export function poseidonBasic(opts: PoseidonOpts, mds: bigint[][]): PoseidonFn {
281
- validateField(opts.Fp);
282
- if (!Number.isSafeInteger(opts.rate) || !Number.isSafeInteger(opts.capacity))
283
- throw new Error(`Wrong poseidon opts: ${opts}`);
284
- const m = opts.rate + opts.capacity;
285
- const rounds = opts.roundsFull + opts.roundsPartial;
286
- const roundConstants = [];
287
- for (let i = 0; i < rounds; i++) {
288
- const row = [];
289
- for (let j = 0; j < m; j++) row.push(poseidonRoundConstant(opts.Fp, 'Hades', m * i + j));
290
- roundConstants.push(row);
291
- }
292
- const res: Partial<PoseidonFn> = poseidon({
293
- ...opts,
294
- t: m,
295
- sboxPower: 3,
296
- reversePartialPowIdx: true, // Why?!
297
- mds,
298
- roundConstants,
299
- });
300
- res.m = m;
301
- res.rate = opts.rate;
302
- res.capacity = opts.capacity;
303
- return res as PoseidonFn;
304
- }
305
-
306
- export function poseidonCreate(opts: PoseidonOpts, mdsAttempt = 0) {
307
- const m = opts.rate + opts.capacity;
308
- if (!Number.isSafeInteger(mdsAttempt)) throw new Error(`Wrong mdsAttempt=${mdsAttempt}`);
309
- return poseidonBasic(opts, _poseidonMDS(opts.Fp, 'HadesMDS', m, mdsAttempt));
310
- }
311
-
312
- export const poseidonSmall = poseidonBasic(
313
- { Fp: Fp251, rate: 2, capacity: 1, roundsFull: 8, roundsPartial: 83 },
314
- MDS_SMALL
315
- );
316
-
317
- export function poseidonHash(x: bigint, y: bigint, fn = poseidonSmall): bigint {
318
- return fn([x, y, 2n])[0];
319
- }
320
-
321
- export function poseidonHashFunc(x: Uint8Array, y: Uint8Array, fn = poseidonSmall): Uint8Array {
322
- return u.numberToVarBytesBE(poseidonHash(u.bytesToNumberBE(x), u.bytesToNumberBE(y), fn));
323
- }
324
-
325
- export function poseidonHashSingle(x: bigint, fn = poseidonSmall): bigint {
326
- return fn([x, 0n, 1n])[0];
327
- }
328
-
329
- export function poseidonHashMany(values: bigint[], fn = poseidonSmall): bigint {
330
- const { m, rate } = fn;
331
- if (!Array.isArray(values)) throw new Error('bigint array expected in values');
332
- const padded = Array.from(values); // copy
333
- padded.push(1n);
334
- while (padded.length % rate !== 0) padded.push(0n);
335
- let state: bigint[] = new Array(m).fill(0n);
336
- for (let i = 0; i < padded.length; i += rate) {
337
- for (let j = 0; j < rate; j++) state[j] += padded[i + j];
338
- state = fn(state);
339
- }
340
- return state[0];
341
- }
package/stark.d.ts DELETED
@@ -1,81 +0,0 @@
1
- import { Field } from './abstract/modular.js';
2
- import { poseidon } from './abstract/poseidon.js';
3
- import { ProjPointType, SignatureType } from './abstract/weierstrass.js';
4
- import * as u from './abstract/utils.js';
5
- import type { Hex } from './abstract/utils.js';
6
- declare type ProjectivePoint = ProjPointType<bigint>;
7
- export declare const _starkCurve: import("./abstract/weierstrass.js").CurveFn;
8
- export declare function getPublicKey(privKey: Hex, isCompressed?: boolean): Uint8Array;
9
- export declare function getSharedSecret(privKeyA: Hex, pubKeyB: Hex): Uint8Array;
10
- export declare function sign(msgHash: Hex, privKey: Hex, opts?: any): SignatureType;
11
- export declare function verify(signature: SignatureType | Hex, msgHash: Hex, pubKey: Hex): boolean;
12
- declare const CURVE: Readonly<{
13
- readonly nBitLength: number;
14
- readonly nByteLength: number;
15
- readonly Fp: Field<bigint>;
16
- readonly n: bigint;
17
- readonly h: bigint;
18
- readonly hEff?: bigint | undefined;
19
- readonly Gx: bigint;
20
- readonly Gy: bigint;
21
- readonly allowInfinityPoint?: boolean | undefined;
22
- readonly a: bigint;
23
- readonly b: bigint;
24
- readonly allowedPrivateKeyLengths?: readonly number[] | undefined;
25
- readonly wrapPrivateKey?: boolean | undefined;
26
- readonly endo?: {
27
- beta: bigint;
28
- splitScalar: (k: bigint) => {
29
- k1neg: boolean;
30
- k1: bigint;
31
- k2neg: boolean;
32
- k2: bigint;
33
- };
34
- } | undefined;
35
- readonly isTorsionFree?: ((c: import("./abstract/weierstrass.js").ProjConstructor<bigint>, point: ProjPointType<bigint>) => boolean) | undefined;
36
- readonly clearCofactor?: ((c: import("./abstract/weierstrass.js").ProjConstructor<bigint>, point: ProjPointType<bigint>) => ProjPointType<bigint>) | undefined;
37
- readonly hash: u.CHash;
38
- readonly hmac: (key: Uint8Array, ...messages: Uint8Array[]) => Uint8Array;
39
- readonly randomBytes: (bytesLength?: number | undefined) => Uint8Array;
40
- lowS: boolean;
41
- readonly bits2int?: ((bytes: Uint8Array) => bigint) | undefined;
42
- readonly bits2int_modN?: ((bytes: Uint8Array) => bigint) | undefined;
43
- }>, ProjectivePoint: import("./abstract/weierstrass.js").ProjConstructor<bigint>, Signature: import("./abstract/weierstrass.js").SignatureConstructor, utils: {
44
- normPrivateKeyToScalar: (key: u.PrivKey) => bigint;
45
- isValidPrivateKey(privateKey: u.PrivKey): boolean;
46
- randomPrivateKey: () => Uint8Array;
47
- precompute: (windowSize?: number | undefined, point?: ProjPointType<bigint> | undefined) => ProjPointType<bigint>;
48
- };
49
- export { CURVE, ProjectivePoint, Signature, utils };
50
- export declare function grindKey(seed: Hex): string;
51
- export declare function getStarkKey(privateKey: Hex): string;
52
- export declare function ethSigToPrivate(signature: string): string;
53
- export declare function getAccountPath(layer: string, application: string, ethereumAddress: string, index: number): string;
54
- declare type PedersenArg = Hex | bigint | number;
55
- export declare function pedersen(x: PedersenArg, y: PedersenArg): string;
56
- export declare function hashChain(data: PedersenArg[], fn?: typeof pedersen): PedersenArg;
57
- export declare const computeHashOnElements: (data: PedersenArg[], fn?: typeof pedersen) => PedersenArg;
58
- export declare const keccak: (data: Uint8Array) => bigint;
59
- export declare const Fp253: Readonly<Field<bigint> & Required<Pick<Field<bigint>, "isOdd">>>;
60
- export declare const Fp251: Readonly<Field<bigint> & Required<Pick<Field<bigint>, "isOdd">>>;
61
- export declare function _poseidonMDS(Fp: Field<bigint>, name: string, m: number, attempt?: number): bigint[][];
62
- export declare type PoseidonOpts = {
63
- Fp: Field<bigint>;
64
- rate: number;
65
- capacity: number;
66
- roundsFull: number;
67
- roundsPartial: number;
68
- };
69
- export declare type PoseidonFn = ReturnType<typeof poseidon> & {
70
- m: number;
71
- rate: number;
72
- capacity: number;
73
- };
74
- export declare function poseidonBasic(opts: PoseidonOpts, mds: bigint[][]): PoseidonFn;
75
- export declare function poseidonCreate(opts: PoseidonOpts, mdsAttempt?: number): PoseidonFn;
76
- export declare const poseidonSmall: PoseidonFn;
77
- export declare function poseidonHash(x: bigint, y: bigint, fn?: PoseidonFn): bigint;
78
- export declare function poseidonHashFunc(x: Uint8Array, y: Uint8Array, fn?: PoseidonFn): Uint8Array;
79
- export declare function poseidonHashSingle(x: bigint, fn?: PoseidonFn): bigint;
80
- export declare function poseidonHashMany(values: bigint[], fn?: PoseidonFn): bigint;
81
- //# sourceMappingURL=stark.d.ts.map
package/stark.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"stark.d.ts","sourceRoot":"","sources":["src/stark.ts"],"names":[],"mappings":"AAIA,OAAO,EAAW,KAAK,EAAiB,MAAM,uBAAuB,CAAC;AACtE,OAA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