starknet 5.10.1 → 5.11.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/CHANGELOG.md +12 -0
- package/dist/index.d.ts +324 -370
- package/dist/index.global.js +693 -63
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +352 -37
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +348 -37
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.global.js
CHANGED
|
@@ -25,6 +25,10 @@ var starknet = (() => {
|
|
|
25
25
|
return to;
|
|
26
26
|
};
|
|
27
27
|
var __toESM = (mod3, isNodeMode, target) => (target = mod3 != null ? __create(__getProtoOf(mod3)) : {}, __copyProps(
|
|
28
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
29
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
30
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
31
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
32
|
isNodeMode || !mod3 || !mod3.__esModule ? __defProp(target, "default", { value: mod3, enumerable: true }) : target,
|
|
29
33
|
mod3
|
|
30
34
|
));
|
|
@@ -272,10 +276,10 @@ var starknet = (() => {
|
|
|
272
276
|
if (options.cache === "no-store" || options.cache === "no-cache") {
|
|
273
277
|
var reParamSearch = /([?&])_=[^&]*/;
|
|
274
278
|
if (reParamSearch.test(this.url)) {
|
|
275
|
-
this.url = this.url.replace(reParamSearch, "$1_=" + new Date().getTime());
|
|
279
|
+
this.url = this.url.replace(reParamSearch, "$1_=" + (/* @__PURE__ */ new Date()).getTime());
|
|
276
280
|
} else {
|
|
277
281
|
var reQueryString = /\?/;
|
|
278
|
-
this.url += (reQueryString.test(this.url) ? "&" : "?") + "_=" + new Date().getTime();
|
|
282
|
+
this.url += (reQueryString.test(this.url) ? "&" : "?") + "_=" + (/* @__PURE__ */ new Date()).getTime();
|
|
279
283
|
}
|
|
280
284
|
}
|
|
281
285
|
}
|
|
@@ -1238,6 +1242,7 @@ var starknet = (() => {
|
|
|
1238
1242
|
return result;
|
|
1239
1243
|
}
|
|
1240
1244
|
var Hash = class {
|
|
1245
|
+
// Safe version that clones internal state
|
|
1241
1246
|
clone() {
|
|
1242
1247
|
return this._cloneInto();
|
|
1243
1248
|
}
|
|
@@ -1329,6 +1334,7 @@ var starknet = (() => {
|
|
|
1329
1334
|
B.fill(0);
|
|
1330
1335
|
}
|
|
1331
1336
|
var Keccak = class extends Hash {
|
|
1337
|
+
// NOTE: we accept arguments in bytes instead of bits here.
|
|
1332
1338
|
constructor(blockLen, suffix, outputLen, enableXOF = false, rounds = 24) {
|
|
1333
1339
|
super();
|
|
1334
1340
|
this.blockLen = blockLen;
|
|
@@ -1640,6 +1646,7 @@ var starknet = (() => {
|
|
|
1640
1646
|
const { A, B, C, D, E, F, G, H } = this;
|
|
1641
1647
|
return [A, B, C, D, E, F, G, H];
|
|
1642
1648
|
}
|
|
1649
|
+
// prettier-ignore
|
|
1643
1650
|
set(A, B, C, D, E, F, G, H) {
|
|
1644
1651
|
this.A = A | 0;
|
|
1645
1652
|
this.B = B | 0;
|
|
@@ -2131,6 +2138,7 @@ var starknet = (() => {
|
|
|
2131
2138
|
mul: (lhs, rhs) => mod(lhs * rhs, ORDER),
|
|
2132
2139
|
pow: (num, power) => FpPow(f, num, power),
|
|
2133
2140
|
div: (lhs, rhs) => mod(lhs * invert(rhs, ORDER), ORDER),
|
|
2141
|
+
// Same as above, but doesn't normalize
|
|
2134
2142
|
sqrN: (num) => num * num,
|
|
2135
2143
|
addN: (lhs, rhs) => lhs + rhs,
|
|
2136
2144
|
subN: (lhs, rhs) => lhs - rhs,
|
|
@@ -2138,6 +2146,8 @@ var starknet = (() => {
|
|
|
2138
2146
|
inv: (num) => invert(num, ORDER),
|
|
2139
2147
|
sqrt: redef.sqrt || ((n) => sqrtP(f, n)),
|
|
2140
2148
|
invertBatch: (lst) => FpInvertBatch(f, lst),
|
|
2149
|
+
// TODO: do we really need constant cmov?
|
|
2150
|
+
// We don't have const-time bigints anyway, so probably will be not very useful
|
|
2141
2151
|
cmov: (a, b, c) => c ? b : a,
|
|
2142
2152
|
toBytes: (num) => isLE2 ? numberToBytesLE2(num, BYTES) : numberToBytesBE2(num, BYTES),
|
|
2143
2153
|
fromBytes: (bytes2) => {
|
|
@@ -2257,6 +2267,7 @@ var starknet = (() => {
|
|
|
2257
2267
|
};
|
|
2258
2268
|
return {
|
|
2259
2269
|
constTimeNegate,
|
|
2270
|
+
// non-const time multiplication ladder
|
|
2260
2271
|
unsafeLadder(elm, n) {
|
|
2261
2272
|
let p = c.ZERO;
|
|
2262
2273
|
let d = elm;
|
|
@@ -2268,6 +2279,16 @@ var starknet = (() => {
|
|
|
2268
2279
|
}
|
|
2269
2280
|
return p;
|
|
2270
2281
|
},
|
|
2282
|
+
/**
|
|
2283
|
+
* Creates a wNAF precomputation window. Used for caching.
|
|
2284
|
+
* Default window size is set by `utils.precompute()` and is equal to 8.
|
|
2285
|
+
* Number of precomputed points depends on the curve size:
|
|
2286
|
+
* 2^(𝑊−1) * (Math.ceil(𝑛 / 𝑊) + 1), where:
|
|
2287
|
+
* - 𝑊 is the window size
|
|
2288
|
+
* - 𝑛 is the bitlength of the curve order.
|
|
2289
|
+
* For a 256-bit curve and window size 8, the number of precomputed points is 128 * 33 = 4224.
|
|
2290
|
+
* @returns precomputed point tables flattened to a single array
|
|
2291
|
+
*/
|
|
2271
2292
|
precomputeWindow(elm, W) {
|
|
2272
2293
|
const { windows, windowSize } = opts(W);
|
|
2273
2294
|
const points = [];
|
|
@@ -2284,6 +2305,13 @@ var starknet = (() => {
|
|
|
2284
2305
|
}
|
|
2285
2306
|
return points;
|
|
2286
2307
|
},
|
|
2308
|
+
/**
|
|
2309
|
+
* Implements ec multiplication using precomputed tables and w-ary non-adjacent form.
|
|
2310
|
+
* @param W window size
|
|
2311
|
+
* @param precomputes precomputed tables
|
|
2312
|
+
* @param n scalar (we don't check here, but should be less than curve order)
|
|
2313
|
+
* @returns real and fake (for const-time) points
|
|
2314
|
+
*/
|
|
2287
2315
|
wNAF(W, precomputes, n) {
|
|
2288
2316
|
const { windows, windowSize } = opts(W);
|
|
2289
2317
|
let p = c.ZERO;
|
|
@@ -2370,6 +2398,7 @@ var starknet = (() => {
|
|
|
2370
2398
|
}
|
|
2371
2399
|
var { bytesToNumberBE: b2n, hexToBytes: h2b } = utils_exports2;
|
|
2372
2400
|
var DER = {
|
|
2401
|
+
// asn.1 DER encoding utils
|
|
2373
2402
|
Err: class DERErr extends Error {
|
|
2374
2403
|
constructor(m = "") {
|
|
2375
2404
|
super(m);
|
|
@@ -2490,6 +2519,8 @@ var starknet = (() => {
|
|
|
2490
2519
|
if (pz == null || !Fp.isValid(pz))
|
|
2491
2520
|
throw new Error("z required");
|
|
2492
2521
|
}
|
|
2522
|
+
// Does not validate if the point is on-curve.
|
|
2523
|
+
// Use fromHex instead, or call assertValidity() later.
|
|
2493
2524
|
static fromAffine(p) {
|
|
2494
2525
|
const { x, y } = p || {};
|
|
2495
2526
|
if (!p || !Fp.isValid(x) || !Fp.isValid(y))
|
|
@@ -2507,22 +2538,35 @@ var starknet = (() => {
|
|
|
2507
2538
|
get y() {
|
|
2508
2539
|
return this.toAffine().y;
|
|
2509
2540
|
}
|
|
2541
|
+
/**
|
|
2542
|
+
* Takes a bunch of Projective Points but executes only one
|
|
2543
|
+
* inversion on all of them. Inversion is very slow operation,
|
|
2544
|
+
* so this improves performance massively.
|
|
2545
|
+
* Optimization: converts a list of projective points to a list of identical points with Z=1.
|
|
2546
|
+
*/
|
|
2510
2547
|
static normalizeZ(points) {
|
|
2511
2548
|
const toInv = Fp.invertBatch(points.map((p) => p.pz));
|
|
2512
2549
|
return points.map((p, i) => p.toAffine(toInv[i])).map(Point.fromAffine);
|
|
2513
2550
|
}
|
|
2551
|
+
/**
|
|
2552
|
+
* Converts hash string or Uint8Array to Point.
|
|
2553
|
+
* @param hex short/long ECDSA hex
|
|
2554
|
+
*/
|
|
2514
2555
|
static fromHex(hex) {
|
|
2515
2556
|
const P = Point.fromAffine(fromBytes(ensureBytes2("pointHex", hex)));
|
|
2516
2557
|
P.assertValidity();
|
|
2517
2558
|
return P;
|
|
2518
2559
|
}
|
|
2560
|
+
// Multiplies generator point by privateKey.
|
|
2519
2561
|
static fromPrivateKey(privateKey) {
|
|
2520
2562
|
return Point.BASE.multiply(normPrivateKeyToScalar(privateKey));
|
|
2521
2563
|
}
|
|
2564
|
+
// "Private method", don't use it directly
|
|
2522
2565
|
_setWindowSize(windowSize) {
|
|
2523
2566
|
this._WINDOW_SIZE = windowSize;
|
|
2524
2567
|
pointPrecomputes.delete(this);
|
|
2525
2568
|
}
|
|
2569
|
+
// A point on curve is valid if it conforms to equation.
|
|
2526
2570
|
assertValidity() {
|
|
2527
2571
|
if (this.is0()) {
|
|
2528
2572
|
if (CURVE2.allowInfinityPoint)
|
|
@@ -2545,6 +2589,9 @@ var starknet = (() => {
|
|
|
2545
2589
|
return !Fp.isOdd(y);
|
|
2546
2590
|
throw new Error("Field doesn't support isOdd");
|
|
2547
2591
|
}
|
|
2592
|
+
/**
|
|
2593
|
+
* Compare one point to another.
|
|
2594
|
+
*/
|
|
2548
2595
|
equals(other) {
|
|
2549
2596
|
assertPrjPoint(other);
|
|
2550
2597
|
const { px: X1, py: Y1, pz: Z1 } = this;
|
|
@@ -2553,9 +2600,16 @@ var starknet = (() => {
|
|
|
2553
2600
|
const U2 = Fp.eql(Fp.mul(Y1, Z2), Fp.mul(Y2, Z1));
|
|
2554
2601
|
return U1 && U2;
|
|
2555
2602
|
}
|
|
2603
|
+
/**
|
|
2604
|
+
* Flips point to one corresponding to (x, -y) in Affine coordinates.
|
|
2605
|
+
*/
|
|
2556
2606
|
negate() {
|
|
2557
2607
|
return new Point(this.px, Fp.neg(this.py), this.pz);
|
|
2558
2608
|
}
|
|
2609
|
+
// Renes-Costello-Batina exception-free doubling formula.
|
|
2610
|
+
// There is 30% faster Jacobian formula, but it is not complete.
|
|
2611
|
+
// https://eprint.iacr.org/2015/1060, algorithm 3
|
|
2612
|
+
// Cost: 8M + 3S + 3*a + 2*b3 + 15add.
|
|
2559
2613
|
double() {
|
|
2560
2614
|
const { a, b } = CURVE2;
|
|
2561
2615
|
const b3 = Fp.mul(b, _3n2);
|
|
@@ -2594,6 +2648,10 @@ var starknet = (() => {
|
|
|
2594
2648
|
Z3 = Fp.add(Z3, Z3);
|
|
2595
2649
|
return new Point(X3, Y3, Z3);
|
|
2596
2650
|
}
|
|
2651
|
+
// Renes-Costello-Batina exception-free addition formula.
|
|
2652
|
+
// There is 30% faster Jacobian formula, but it is not complete.
|
|
2653
|
+
// https://eprint.iacr.org/2015/1060, algorithm 1
|
|
2654
|
+
// Cost: 12M + 0S + 3*a + 3*b3 + 23add.
|
|
2597
2655
|
add(other) {
|
|
2598
2656
|
assertPrjPoint(other);
|
|
2599
2657
|
const { px: X1, py: Y1, pz: Z1 } = this;
|
|
@@ -2655,6 +2713,11 @@ var starknet = (() => {
|
|
|
2655
2713
|
return comp.map((p, i) => p.toAffine(toInv[i])).map(Point.fromAffine);
|
|
2656
2714
|
});
|
|
2657
2715
|
}
|
|
2716
|
+
/**
|
|
2717
|
+
* Non-constant-time multiplication. Uses double-and-add algorithm.
|
|
2718
|
+
* It's faster, but should only be used when you don't care about
|
|
2719
|
+
* an exposed private key e.g. sig verification, which works over *public* keys.
|
|
2720
|
+
*/
|
|
2658
2721
|
multiplyUnsafe(n) {
|
|
2659
2722
|
const I = Point.ZERO;
|
|
2660
2723
|
if (n === _0n6)
|
|
@@ -2685,6 +2748,15 @@ var starknet = (() => {
|
|
|
2685
2748
|
k2p = new Point(Fp.mul(k2p.px, endo.beta), k2p.py, k2p.pz);
|
|
2686
2749
|
return k1p.add(k2p);
|
|
2687
2750
|
}
|
|
2751
|
+
/**
|
|
2752
|
+
* Constant time multiplication.
|
|
2753
|
+
* Uses wNAF method. Windowed method may be 10% faster,
|
|
2754
|
+
* but takes 2x longer to generate and consumes 2x memory.
|
|
2755
|
+
* Uses precomputes when available.
|
|
2756
|
+
* Uses endomorphism for Koblitz curves.
|
|
2757
|
+
* @param scalar by which the point would be multiplied
|
|
2758
|
+
* @returns New point
|
|
2759
|
+
*/
|
|
2688
2760
|
multiply(scalar) {
|
|
2689
2761
|
assertGE(scalar);
|
|
2690
2762
|
let n = scalar;
|
|
@@ -2706,12 +2778,21 @@ var starknet = (() => {
|
|
|
2706
2778
|
}
|
|
2707
2779
|
return Point.normalizeZ([point, fake])[0];
|
|
2708
2780
|
}
|
|
2781
|
+
/**
|
|
2782
|
+
* Efficiently calculate `aP + bQ`. Unsafe, can expose private key, if used incorrectly.
|
|
2783
|
+
* Not using Strauss-Shamir trick: precomputation tables are faster.
|
|
2784
|
+
* The trick could be useful if both P and Q are not G (not in our case).
|
|
2785
|
+
* @returns non-zero affine point
|
|
2786
|
+
*/
|
|
2709
2787
|
multiplyAndAddUnsafe(Q, a, b) {
|
|
2710
2788
|
const G = Point.BASE;
|
|
2711
2789
|
const mul = (P, a2) => a2 === _0n6 || a2 === _1n6 || !P.equals(G) ? P.multiplyUnsafe(a2) : P.multiply(a2);
|
|
2712
2790
|
const sum = mul(this, a).add(mul(Q, b));
|
|
2713
2791
|
return sum.is0() ? void 0 : sum;
|
|
2714
2792
|
}
|
|
2793
|
+
// Converts Projective point to affine (x, y) coordinates.
|
|
2794
|
+
// Can accept precomputed Z^-1 - for example, from invertBatch.
|
|
2795
|
+
// (x, y, z) ∋ (x=x/z, y=y/z)
|
|
2715
2796
|
toAffine(iz) {
|
|
2716
2797
|
const { px: x, py: y, pz: z } = this;
|
|
2717
2798
|
const is0 = this.is0();
|
|
@@ -2841,11 +2922,14 @@ var starknet = (() => {
|
|
|
2841
2922
|
this.recovery = recovery;
|
|
2842
2923
|
this.assertValidity();
|
|
2843
2924
|
}
|
|
2925
|
+
// pair (bytes of r, bytes of s)
|
|
2844
2926
|
static fromCompact(hex) {
|
|
2845
2927
|
const l = CURVE2.nByteLength;
|
|
2846
2928
|
hex = ensureBytes2("compactSignature", hex, l * 2);
|
|
2847
2929
|
return new Signature3(slcNum(hex, 0, l), slcNum(hex, l, 2 * l));
|
|
2848
2930
|
}
|
|
2931
|
+
// DER encoded ECDSA signature
|
|
2932
|
+
// https://bitcoin.stackexchange.com/questions/57644/what-are-the-parts-of-a-bitcoin-transaction-input-script
|
|
2849
2933
|
static fromDER(hex) {
|
|
2850
2934
|
const { r, s } = DER.toSig(ensureBytes2("DER", hex));
|
|
2851
2935
|
return new Signature3(r, s);
|
|
@@ -2878,18 +2962,21 @@ var starknet = (() => {
|
|
|
2878
2962
|
Q.assertValidity();
|
|
2879
2963
|
return Q;
|
|
2880
2964
|
}
|
|
2965
|
+
// Signatures should be low-s, to prevent malleability.
|
|
2881
2966
|
hasHighS() {
|
|
2882
2967
|
return isBiggerThanHalfOrder(this.s);
|
|
2883
2968
|
}
|
|
2884
2969
|
normalizeS() {
|
|
2885
2970
|
return this.hasHighS() ? new Signature3(this.r, modN(-this.s), this.recovery) : this;
|
|
2886
2971
|
}
|
|
2972
|
+
// DER-encoded
|
|
2887
2973
|
toDERRawBytes() {
|
|
2888
2974
|
return hexToBytes3(this.toDERHex());
|
|
2889
2975
|
}
|
|
2890
2976
|
toDERHex() {
|
|
2891
2977
|
return DER.hexFromSig({ r: this.r, s: this.s });
|
|
2892
2978
|
}
|
|
2979
|
+
// padded bytes of r, then padded bytes of s
|
|
2893
2980
|
toCompactRawBytes() {
|
|
2894
2981
|
return hexToBytes3(this.toCompactHex());
|
|
2895
2982
|
}
|
|
@@ -2907,11 +2994,23 @@ var starknet = (() => {
|
|
|
2907
2994
|
}
|
|
2908
2995
|
},
|
|
2909
2996
|
normPrivateKeyToScalar,
|
|
2997
|
+
/**
|
|
2998
|
+
* Produces cryptographically secure private key from random of size (nBitLength+64)
|
|
2999
|
+
* as per FIPS 186 B.4.1 with modulo bias being neglible.
|
|
3000
|
+
*/
|
|
2910
3001
|
randomPrivateKey: () => {
|
|
2911
3002
|
const rand = CURVE2.randomBytes(Fp.BYTES + 8);
|
|
2912
3003
|
const num = hashToPrivateScalar(rand, CURVE_ORDER2);
|
|
2913
3004
|
return numberToBytesBE2(num, CURVE2.nByteLength);
|
|
2914
3005
|
},
|
|
3006
|
+
/**
|
|
3007
|
+
* Creates precompute table for an arbitrary EC point. Makes point "cached".
|
|
3008
|
+
* Allows to massively speed-up `point.multiply(scalar)`.
|
|
3009
|
+
* @returns cached point
|
|
3010
|
+
* @example
|
|
3011
|
+
* const fast = utils.precompute(8, ProjectivePoint.fromHex(someonesPubKey));
|
|
3012
|
+
* fast.multiply(privKey); // much faster ECDH now
|
|
3013
|
+
*/
|
|
2915
3014
|
precompute(windowSize = 8, point = Point.BASE) {
|
|
2916
3015
|
point._setWindowSize(windowSize);
|
|
2917
3016
|
point.multiply(BigInt(3));
|
|
@@ -3007,7 +3106,6 @@ var starknet = (() => {
|
|
|
3007
3106
|
}
|
|
3008
3107
|
Point.BASE._setWindowSize(8);
|
|
3009
3108
|
function verify2(signature, msgHash, publicKey, opts = defaultVerOpts) {
|
|
3010
|
-
var _a;
|
|
3011
3109
|
const sg = signature;
|
|
3012
3110
|
msgHash = ensureBytes2("msgHash", msgHash);
|
|
3013
3111
|
publicKey = ensureBytes2("publicKey", publicKey);
|
|
@@ -3046,7 +3144,7 @@ var starknet = (() => {
|
|
|
3046
3144
|
const is = invN(s);
|
|
3047
3145
|
const u1 = modN(h * is);
|
|
3048
3146
|
const u2 = modN(r * is);
|
|
3049
|
-
const R =
|
|
3147
|
+
const R = Point.BASE.multiplyAndAddUnsafe(P, u1, u2)?.toAffine();
|
|
3050
3148
|
if (!R)
|
|
3051
3149
|
return false;
|
|
3052
3150
|
const v = modN(R.x);
|
|
@@ -5631,7 +5729,9 @@ var starknet = (() => {
|
|
|
5631
5729
|
if (!isUint256(bn))
|
|
5632
5730
|
throw new Error("Number is too large");
|
|
5633
5731
|
return {
|
|
5732
|
+
// eslint-disable-next-line no-bitwise
|
|
5634
5733
|
low: (bn & UINT_128_MAX).toString(10),
|
|
5734
|
+
// eslint-disable-next-line no-bitwise
|
|
5635
5735
|
high: (bn >> 128n).toString(10)
|
|
5636
5736
|
};
|
|
5637
5737
|
};
|
|
@@ -5767,7 +5867,11 @@ var starknet = (() => {
|
|
|
5767
5867
|
}
|
|
5768
5868
|
function extractCairo1Tuple(type) {
|
|
5769
5869
|
const cleanType = type.replace(/\s/g, "").slice(1, -1);
|
|
5770
|
-
|
|
5870
|
+
const { subTuple, result } = parseSubTuple(cleanType);
|
|
5871
|
+
const recomposed = result.split(",").map((it) => {
|
|
5872
|
+
return subTuple.length ? it.replace(" ", subTuple.shift()) : it;
|
|
5873
|
+
});
|
|
5874
|
+
return recomposed;
|
|
5771
5875
|
}
|
|
5772
5876
|
function extractTupleMemberTypes(type) {
|
|
5773
5877
|
if (isCairo1Type(type)) {
|
|
@@ -5776,6 +5880,142 @@ var starknet = (() => {
|
|
|
5776
5880
|
return extractCairo0Tuple(type);
|
|
5777
5881
|
}
|
|
5778
5882
|
|
|
5883
|
+
// src/utils/calldata/propertyOrder.ts
|
|
5884
|
+
function errorU256(key) {
|
|
5885
|
+
return Error(
|
|
5886
|
+
`Your object includes the property : ${key}, containing an Uint256 object without the 'low' and 'high' keys.`
|
|
5887
|
+
);
|
|
5888
|
+
}
|
|
5889
|
+
function orderPropsByAbi(unorderedObject, abiOfObject, structs) {
|
|
5890
|
+
const orderStruct = (unorderedObject2, abiObject) => {
|
|
5891
|
+
const orderedObject2 = abiObject.reduce((orderedObject, abiParam) => {
|
|
5892
|
+
const setProperty = (value) => Object.defineProperty(orderedObject, abiParam.name, {
|
|
5893
|
+
enumerable: true,
|
|
5894
|
+
value: value ?? unorderedObject2[abiParam.name]
|
|
5895
|
+
});
|
|
5896
|
+
if (unorderedObject2[abiParam.name] === "undefined") {
|
|
5897
|
+
if (isCairo1Type(abiParam.type) || !isLen(abiParam.name)) {
|
|
5898
|
+
throw Error(`Your object needs a property with key : ${abiParam.name} .`);
|
|
5899
|
+
}
|
|
5900
|
+
}
|
|
5901
|
+
switch (true) {
|
|
5902
|
+
case isTypeStruct(abiParam.type, structs):
|
|
5903
|
+
setProperty(
|
|
5904
|
+
orderStruct(
|
|
5905
|
+
unorderedObject2[abiParam.name],
|
|
5906
|
+
structs[abiParam.type].members
|
|
5907
|
+
)
|
|
5908
|
+
);
|
|
5909
|
+
break;
|
|
5910
|
+
case isTypeUint256(abiParam.type): {
|
|
5911
|
+
const u256 = unorderedObject2[abiParam.name];
|
|
5912
|
+
if (typeof u256 !== "object") {
|
|
5913
|
+
setProperty();
|
|
5914
|
+
break;
|
|
5915
|
+
}
|
|
5916
|
+
if (!("low" in u256 && "high" in u256)) {
|
|
5917
|
+
throw errorU256(abiParam.name);
|
|
5918
|
+
}
|
|
5919
|
+
setProperty({ low: u256.low, high: u256.high });
|
|
5920
|
+
break;
|
|
5921
|
+
}
|
|
5922
|
+
case isTypeTuple(abiParam.type):
|
|
5923
|
+
setProperty(orderTuple(unorderedObject2[abiParam.name], abiParam));
|
|
5924
|
+
break;
|
|
5925
|
+
case isTypeArray(abiParam.type):
|
|
5926
|
+
setProperty(orderArray(unorderedObject2[abiParam.name], abiParam));
|
|
5927
|
+
break;
|
|
5928
|
+
case (!isCairo1Type(abiParam.type) && isLen(abiParam.name)):
|
|
5929
|
+
break;
|
|
5930
|
+
default:
|
|
5931
|
+
setProperty();
|
|
5932
|
+
}
|
|
5933
|
+
return orderedObject;
|
|
5934
|
+
}, {});
|
|
5935
|
+
return orderedObject2;
|
|
5936
|
+
};
|
|
5937
|
+
function orderArray(myArray, abiParam) {
|
|
5938
|
+
const typeInArray = getArrayType(abiParam.type);
|
|
5939
|
+
if (typeof myArray === "string") {
|
|
5940
|
+
return myArray;
|
|
5941
|
+
}
|
|
5942
|
+
switch (true) {
|
|
5943
|
+
case typeInArray in structs:
|
|
5944
|
+
return myArray.map((myObj) => orderStruct(myObj, structs[typeInArray].members));
|
|
5945
|
+
case typeInArray === "core::integer::u256":
|
|
5946
|
+
return myArray.map((u256) => {
|
|
5947
|
+
if (typeof u256 !== "object") {
|
|
5948
|
+
return u256;
|
|
5949
|
+
}
|
|
5950
|
+
if (!("low" in u256 && "high" in u256)) {
|
|
5951
|
+
throw errorU256(abiParam.name);
|
|
5952
|
+
}
|
|
5953
|
+
return { low: u256.low, high: u256.high };
|
|
5954
|
+
});
|
|
5955
|
+
case isTypeTuple(typeInArray):
|
|
5956
|
+
return myArray.map((myElem) => orderTuple(myElem, { name: "0", type: typeInArray }));
|
|
5957
|
+
case isTypeArray(typeInArray):
|
|
5958
|
+
return myArray.map((myElem) => orderArray(myElem, { name: "0", type: typeInArray }));
|
|
5959
|
+
default:
|
|
5960
|
+
return myArray;
|
|
5961
|
+
}
|
|
5962
|
+
}
|
|
5963
|
+
function orderTuple(unorderedObject2, abiParam) {
|
|
5964
|
+
const typeList = extractTupleMemberTypes(abiParam.type);
|
|
5965
|
+
const orderedObject2 = typeList.reduce((orderedObject, abiTypeCairoX, index) => {
|
|
5966
|
+
const myObjKeys = Object.keys(unorderedObject2);
|
|
5967
|
+
const setProperty = (value) => Object.defineProperty(orderedObject, index.toString(), {
|
|
5968
|
+
enumerable: true,
|
|
5969
|
+
value: value ?? unorderedObject2[myObjKeys[index]]
|
|
5970
|
+
});
|
|
5971
|
+
const abiType = abiTypeCairoX?.type ? abiTypeCairoX.type : abiTypeCairoX;
|
|
5972
|
+
switch (true) {
|
|
5973
|
+
case isTypeStruct(abiType, structs):
|
|
5974
|
+
setProperty(
|
|
5975
|
+
orderStruct(
|
|
5976
|
+
unorderedObject2[myObjKeys[index]],
|
|
5977
|
+
structs[abiType].members
|
|
5978
|
+
)
|
|
5979
|
+
);
|
|
5980
|
+
break;
|
|
5981
|
+
case isTypeUint256(abiType): {
|
|
5982
|
+
const u256 = unorderedObject2[myObjKeys[index]];
|
|
5983
|
+
if (typeof u256 !== "object") {
|
|
5984
|
+
setProperty();
|
|
5985
|
+
break;
|
|
5986
|
+
}
|
|
5987
|
+
if (!("low" in u256 && "high" in u256)) {
|
|
5988
|
+
throw errorU256(abiParam.name);
|
|
5989
|
+
}
|
|
5990
|
+
setProperty({ low: u256.low, high: u256.high });
|
|
5991
|
+
break;
|
|
5992
|
+
}
|
|
5993
|
+
case isTypeTuple(abiType):
|
|
5994
|
+
setProperty(
|
|
5995
|
+
orderTuple(unorderedObject2[myObjKeys[index]], {
|
|
5996
|
+
name: "0",
|
|
5997
|
+
type: abiType
|
|
5998
|
+
})
|
|
5999
|
+
);
|
|
6000
|
+
break;
|
|
6001
|
+
case isTypeArray(abiType):
|
|
6002
|
+
setProperty(
|
|
6003
|
+
orderArray(unorderedObject2[myObjKeys[index]], {
|
|
6004
|
+
name: "0",
|
|
6005
|
+
type: abiType
|
|
6006
|
+
})
|
|
6007
|
+
);
|
|
6008
|
+
break;
|
|
6009
|
+
default:
|
|
6010
|
+
setProperty();
|
|
6011
|
+
}
|
|
6012
|
+
return orderedObject;
|
|
6013
|
+
}, {});
|
|
6014
|
+
return orderedObject2;
|
|
6015
|
+
}
|
|
6016
|
+
return orderStruct(unorderedObject, abiOfObject);
|
|
6017
|
+
}
|
|
6018
|
+
|
|
5779
6019
|
// src/utils/calldata/requestParser.ts
|
|
5780
6020
|
function parseBaseTypes(type, val) {
|
|
5781
6021
|
switch (true) {
|
|
@@ -5829,6 +6069,14 @@ var starknet = (() => {
|
|
|
5829
6069
|
return acc.concat(parsedData);
|
|
5830
6070
|
}, []);
|
|
5831
6071
|
}
|
|
6072
|
+
if (isTypeUint256(type)) {
|
|
6073
|
+
if (typeof element === "object") {
|
|
6074
|
+
const { low, high } = element;
|
|
6075
|
+
return [felt(low), felt(high)];
|
|
6076
|
+
}
|
|
6077
|
+
const el_uint256 = uint256(element);
|
|
6078
|
+
return [felt(el_uint256.low), felt(el_uint256.high)];
|
|
6079
|
+
}
|
|
5832
6080
|
if (typeof element === "object") {
|
|
5833
6081
|
throw Error(`Parameter ${element} do not align with abi parameter ${type}`);
|
|
5834
6082
|
}
|
|
@@ -5846,14 +6094,8 @@ var starknet = (() => {
|
|
|
5846
6094
|
value = splitLongString(value);
|
|
5847
6095
|
}
|
|
5848
6096
|
return parseCalldataValue(value, input.type, structs);
|
|
5849
|
-
case (isTypeStruct(type, structs) || isTypeTuple(type)):
|
|
6097
|
+
case (isTypeStruct(type, structs) || isTypeTuple(type) || isTypeUint256(type)):
|
|
5850
6098
|
return parseCalldataValue(value, type, structs);
|
|
5851
|
-
case isTypeUint256(type):
|
|
5852
|
-
if (typeof value === "object") {
|
|
5853
|
-
return [felt(value.low), felt(value.high)];
|
|
5854
|
-
}
|
|
5855
|
-
const el_uint256 = uint256(value);
|
|
5856
|
-
return [felt(el_uint256.low), felt(el_uint256.high)];
|
|
5857
6099
|
default:
|
|
5858
6100
|
return parseBaseTypes(type, value);
|
|
5859
6101
|
}
|
|
@@ -5885,8 +6127,8 @@ var starknet = (() => {
|
|
|
5885
6127
|
if (isTypeTuple(element.type)) {
|
|
5886
6128
|
const memberTypes = extractTupleMemberTypes(element.type);
|
|
5887
6129
|
return memberTypes.reduce((acc, it, idx) => {
|
|
5888
|
-
const name =
|
|
5889
|
-
const type =
|
|
6130
|
+
const name = it?.name ? it.name : idx;
|
|
6131
|
+
const type = it?.type ? it.type : it;
|
|
5890
6132
|
const el = { name, type };
|
|
5891
6133
|
acc[name] = parseResponseValue(responseIterator, el, structs);
|
|
5892
6134
|
return acc;
|
|
@@ -6094,6 +6336,12 @@ var starknet = (() => {
|
|
|
6094
6336
|
this.abi = abi;
|
|
6095
6337
|
this.structs = CallData.getAbiStruct(abi);
|
|
6096
6338
|
}
|
|
6339
|
+
/**
|
|
6340
|
+
* Validate arguments passed to the method as corresponding to the ones in the abi
|
|
6341
|
+
* @param type string - type of the method
|
|
6342
|
+
* @param method string - name of the method
|
|
6343
|
+
* @param args ArgsOrCalldata - arguments that are passed to the method
|
|
6344
|
+
*/
|
|
6097
6345
|
validate(type, method, args = []) {
|
|
6098
6346
|
if (type !== "DEPLOY") {
|
|
6099
6347
|
const invocableFunctionNames = this.abi.filter((abi) => {
|
|
@@ -6118,14 +6366,41 @@ var starknet = (() => {
|
|
|
6118
6366
|
}
|
|
6119
6367
|
validateFields(abiMethod, args, this.structs);
|
|
6120
6368
|
}
|
|
6121
|
-
|
|
6369
|
+
/**
|
|
6370
|
+
* Compile contract callData with abi
|
|
6371
|
+
* Parse the calldata by using input fields from the abi for that method
|
|
6372
|
+
* @param method string - method name
|
|
6373
|
+
* @param args RawArgs - arguments passed to the method. Can be an array of arguments (in the order of abi definition), or an object constructed in conformity with abi (in this case, the parameter can be in a wrong order).
|
|
6374
|
+
* @return Calldata - parsed arguments in format that contract is expecting
|
|
6375
|
+
* @example
|
|
6376
|
+
* ```typescript
|
|
6377
|
+
* const calldata = myCallData.compile("constructor",["0x34a",[1,3n]]);
|
|
6378
|
+
* ```
|
|
6379
|
+
* ```typescript
|
|
6380
|
+
* const calldata2 = myCallData.compile("constructor",{list:[1,3n],balance:"0x34"}); // wrong order is valid
|
|
6381
|
+
* ```
|
|
6382
|
+
*/
|
|
6383
|
+
compile(method, argsCalldata) {
|
|
6384
|
+
const abiMethod = this.abi.find((abi) => abi.name === method);
|
|
6385
|
+
let args;
|
|
6386
|
+
if (Array.isArray(argsCalldata)) {
|
|
6387
|
+
args = argsCalldata;
|
|
6388
|
+
} else {
|
|
6389
|
+
const orderedObject = orderPropsByAbi(argsCalldata, abiMethod.inputs, this.structs);
|
|
6390
|
+
args = Object.values(orderedObject);
|
|
6391
|
+
validateFields(abiMethod, args, this.structs);
|
|
6392
|
+
}
|
|
6122
6393
|
const argsIterator = args[Symbol.iterator]();
|
|
6123
|
-
|
|
6124
|
-
return inputs.reduce(
|
|
6394
|
+
return abiMethod.inputs.reduce(
|
|
6125
6395
|
(acc, input) => isLen(input.name) ? acc : acc.concat(parseCalldataField(argsIterator, input, this.structs)),
|
|
6126
6396
|
[]
|
|
6127
6397
|
);
|
|
6128
6398
|
}
|
|
6399
|
+
/**
|
|
6400
|
+
* Compile contract callData without abi
|
|
6401
|
+
* @param rawArgs RawArgs representing cairo method arguments or string array of compiled data
|
|
6402
|
+
* @returns Calldata
|
|
6403
|
+
*/
|
|
6129
6404
|
static compile(rawArgs) {
|
|
6130
6405
|
const createTree = (obj) => {
|
|
6131
6406
|
const getEntries = (o, prefix = "") => {
|
|
@@ -6160,6 +6435,12 @@ var starknet = (() => {
|
|
|
6160
6435
|
});
|
|
6161
6436
|
return callTreeArray;
|
|
6162
6437
|
}
|
|
6438
|
+
/**
|
|
6439
|
+
* Parse elements of the response array and structuring them into response object
|
|
6440
|
+
* @param method string - method name
|
|
6441
|
+
* @param response string[] - response from the method
|
|
6442
|
+
* @return Result - parsed response corresponding to the abi
|
|
6443
|
+
*/
|
|
6163
6444
|
parse(method, response) {
|
|
6164
6445
|
const { outputs } = this.abi.find((abi) => abi.name === method);
|
|
6165
6446
|
const responseIterator = response.flat()[Symbol.iterator]();
|
|
@@ -6173,13 +6454,30 @@ var starknet = (() => {
|
|
|
6173
6454
|
}, {});
|
|
6174
6455
|
return Object.keys(parsed).length === 1 && 0 in parsed ? parsed[0] : parsed;
|
|
6175
6456
|
}
|
|
6457
|
+
/**
|
|
6458
|
+
* Format cairo method response data to native js values based on provided format schema
|
|
6459
|
+
* @param method string - cairo method name
|
|
6460
|
+
* @param response string[] - cairo method response
|
|
6461
|
+
* @param format object - formatter object schema
|
|
6462
|
+
* @returns Result - parsed and formatted response object
|
|
6463
|
+
*/
|
|
6176
6464
|
format(method, response, format) {
|
|
6177
6465
|
const parsed = this.parse(method, response);
|
|
6178
6466
|
return formatter(parsed, format);
|
|
6179
6467
|
}
|
|
6468
|
+
/**
|
|
6469
|
+
* Helper to calculate inputs from abi
|
|
6470
|
+
* @param inputs AbiEntry
|
|
6471
|
+
* @returns number
|
|
6472
|
+
*/
|
|
6180
6473
|
static abiInputsLength(inputs) {
|
|
6181
6474
|
return inputs.reduce((acc, input) => !isLen(input.name) ? acc + 1 : acc, 0);
|
|
6182
6475
|
}
|
|
6476
|
+
/**
|
|
6477
|
+
* Helper to extract structs from abi
|
|
6478
|
+
* @param abi Abi
|
|
6479
|
+
* @returns AbiStructs - structs from abi
|
|
6480
|
+
*/
|
|
6183
6481
|
static getAbiStruct(abi) {
|
|
6184
6482
|
return abi.filter((abiEntry) => abiEntry.type === "struct").reduce(
|
|
6185
6483
|
(acc, abiEntry) => ({
|
|
@@ -6189,9 +6487,19 @@ var starknet = (() => {
|
|
|
6189
6487
|
{}
|
|
6190
6488
|
);
|
|
6191
6489
|
}
|
|
6490
|
+
/**
|
|
6491
|
+
* Helper: Compile HexCalldata | RawCalldata | RawArgs
|
|
6492
|
+
* @param rawCalldata HexCalldata | RawCalldata | RawArgs
|
|
6493
|
+
* @returns Calldata
|
|
6494
|
+
*/
|
|
6192
6495
|
static toCalldata(rawCalldata = []) {
|
|
6193
6496
|
return CallData.compile(rawCalldata);
|
|
6194
6497
|
}
|
|
6498
|
+
/**
|
|
6499
|
+
* Helper: Convert raw to HexCalldata
|
|
6500
|
+
* @param raw HexCalldata | RawCalldata | RawArgs
|
|
6501
|
+
* @returns HexCalldata
|
|
6502
|
+
*/
|
|
6195
6503
|
static toHex(raw = []) {
|
|
6196
6504
|
const calldata = CallData.compile(raw);
|
|
6197
6505
|
return calldata.map((it) => toHex(it));
|
|
@@ -6200,7 +6508,9 @@ var starknet = (() => {
|
|
|
6200
6508
|
|
|
6201
6509
|
// src/utils/fetchPonyfill.ts
|
|
6202
6510
|
var import_isomorphic_fetch = __toESM(require_fetch_npm_browserify());
|
|
6203
|
-
var fetchPonyfill_default = typeof window !== "undefined" && window.fetch ||
|
|
6511
|
+
var fetchPonyfill_default = typeof window !== "undefined" && window.fetch || // use buildin fetch in browser if available
|
|
6512
|
+
typeof global !== "undefined" && global.fetch || // use buildin fetch in node, react-native and service worker if available
|
|
6513
|
+
import_isomorphic_fetch.default;
|
|
6204
6514
|
|
|
6205
6515
|
// src/utils/hash.ts
|
|
6206
6516
|
var hash_exports = {};
|
|
@@ -6356,6 +6666,7 @@ var starknet = (() => {
|
|
|
6356
6666
|
};
|
|
6357
6667
|
return {
|
|
6358
6668
|
constTimeNegate,
|
|
6669
|
+
// non-const time multiplication ladder
|
|
6359
6670
|
unsafeLadder(elm, n) {
|
|
6360
6671
|
let p = c.ZERO;
|
|
6361
6672
|
let d = elm;
|
|
@@ -6367,6 +6678,16 @@ var starknet = (() => {
|
|
|
6367
6678
|
}
|
|
6368
6679
|
return p;
|
|
6369
6680
|
},
|
|
6681
|
+
/**
|
|
6682
|
+
* Creates a wNAF precomputation window. Used for caching.
|
|
6683
|
+
* Default window size is set by `utils.precompute()` and is equal to 8.
|
|
6684
|
+
* Number of precomputed points depends on the curve size:
|
|
6685
|
+
* 2^(𝑊−1) * (Math.ceil(𝑛 / 𝑊) + 1), where:
|
|
6686
|
+
* - 𝑊 is the window size
|
|
6687
|
+
* - 𝑛 is the bitlength of the curve order.
|
|
6688
|
+
* For a 256-bit curve and window size 8, the number of precomputed points is 128 * 33 = 4224.
|
|
6689
|
+
* @returns precomputed point tables flattened to a single array
|
|
6690
|
+
*/
|
|
6370
6691
|
precomputeWindow(elm, W) {
|
|
6371
6692
|
const { windows, windowSize } = opts(W);
|
|
6372
6693
|
const points = [];
|
|
@@ -6383,6 +6704,13 @@ var starknet = (() => {
|
|
|
6383
6704
|
}
|
|
6384
6705
|
return points;
|
|
6385
6706
|
},
|
|
6707
|
+
/**
|
|
6708
|
+
* Implements ec multiplication using precomputed tables and w-ary non-adjacent form.
|
|
6709
|
+
* @param W window size
|
|
6710
|
+
* @param precomputes precomputed tables
|
|
6711
|
+
* @param n scalar (we don't check here, but should be less than curve order)
|
|
6712
|
+
* @returns real and fake (for const-time) points
|
|
6713
|
+
*/
|
|
6386
6714
|
wNAF(W, precomputes, n) {
|
|
6387
6715
|
const { windows, windowSize } = opts(W);
|
|
6388
6716
|
let p = c.ZERO;
|
|
@@ -6465,6 +6793,7 @@ var starknet = (() => {
|
|
|
6465
6793
|
}
|
|
6466
6794
|
var { bytesToNumberBE: b2n2, hexToBytes: h2b2 } = utils_exports;
|
|
6467
6795
|
var DER2 = {
|
|
6796
|
+
// asn.1 DER encoding utils
|
|
6468
6797
|
Err: class DERErr2 extends Error {
|
|
6469
6798
|
constructor(m = "") {
|
|
6470
6799
|
super(m);
|
|
@@ -6568,6 +6897,8 @@ var starknet = (() => {
|
|
|
6568
6897
|
if (pz == null || !Fp.isValid(pz))
|
|
6569
6898
|
throw new Error("z required");
|
|
6570
6899
|
}
|
|
6900
|
+
// Does not validate if the point is on-curve.
|
|
6901
|
+
// Use fromHex instead, or call assertValidity() later.
|
|
6571
6902
|
static fromAffine(p) {
|
|
6572
6903
|
const { x, y } = p || {};
|
|
6573
6904
|
if (!p || !Fp.isValid(x) || !Fp.isValid(y))
|
|
@@ -6585,22 +6916,35 @@ var starknet = (() => {
|
|
|
6585
6916
|
get y() {
|
|
6586
6917
|
return this.toAffine().y;
|
|
6587
6918
|
}
|
|
6919
|
+
/**
|
|
6920
|
+
* Takes a bunch of Projective Points but executes only one
|
|
6921
|
+
* inversion on all of them. Inversion is very slow operation,
|
|
6922
|
+
* so this improves performance massively.
|
|
6923
|
+
* Optimization: converts a list of projective points to a list of identical points with Z=1.
|
|
6924
|
+
*/
|
|
6588
6925
|
static normalizeZ(points) {
|
|
6589
6926
|
const toInv = Fp.invertBatch(points.map((p) => p.pz));
|
|
6590
6927
|
return points.map((p, i) => p.toAffine(toInv[i])).map(Point.fromAffine);
|
|
6591
6928
|
}
|
|
6929
|
+
/**
|
|
6930
|
+
* Converts hash string or Uint8Array to Point.
|
|
6931
|
+
* @param hex short/long ECDSA hex
|
|
6932
|
+
*/
|
|
6592
6933
|
static fromHex(hex) {
|
|
6593
6934
|
const P = Point.fromAffine(CURVE2.fromBytes(ensureBytes("pointHex", hex)));
|
|
6594
6935
|
P.assertValidity();
|
|
6595
6936
|
return P;
|
|
6596
6937
|
}
|
|
6938
|
+
// Multiplies generator point by privateKey.
|
|
6597
6939
|
static fromPrivateKey(privateKey) {
|
|
6598
6940
|
return Point.BASE.multiply(normPrivateKeyToScalar(privateKey));
|
|
6599
6941
|
}
|
|
6942
|
+
// "Private method", don't use it directly
|
|
6600
6943
|
_setWindowSize(windowSize) {
|
|
6601
6944
|
this._WINDOW_SIZE = windowSize;
|
|
6602
6945
|
pointPrecomputes.delete(this);
|
|
6603
6946
|
}
|
|
6947
|
+
// A point on curve is valid if it conforms to equation.
|
|
6604
6948
|
assertValidity() {
|
|
6605
6949
|
if (this.is0()) {
|
|
6606
6950
|
if (CURVE2.allowInfinityPoint)
|
|
@@ -6623,6 +6967,9 @@ var starknet = (() => {
|
|
|
6623
6967
|
return !Fp.isOdd(y);
|
|
6624
6968
|
throw new Error("Field doesn't support isOdd");
|
|
6625
6969
|
}
|
|
6970
|
+
/**
|
|
6971
|
+
* Compare one point to another.
|
|
6972
|
+
*/
|
|
6626
6973
|
equals(other) {
|
|
6627
6974
|
assertPrjPoint(other);
|
|
6628
6975
|
const { px: X1, py: Y1, pz: Z1 } = this;
|
|
@@ -6631,9 +6978,16 @@ var starknet = (() => {
|
|
|
6631
6978
|
const U2 = Fp.eql(Fp.mul(Y1, Z2), Fp.mul(Y2, Z1));
|
|
6632
6979
|
return U1 && U2;
|
|
6633
6980
|
}
|
|
6981
|
+
/**
|
|
6982
|
+
* Flips point to one corresponding to (x, -y) in Affine coordinates.
|
|
6983
|
+
*/
|
|
6634
6984
|
negate() {
|
|
6635
6985
|
return new Point(this.px, Fp.neg(this.py), this.pz);
|
|
6636
6986
|
}
|
|
6987
|
+
// Renes-Costello-Batina exception-free doubling formula.
|
|
6988
|
+
// There is 30% faster Jacobian formula, but it is not complete.
|
|
6989
|
+
// https://eprint.iacr.org/2015/1060, algorithm 3
|
|
6990
|
+
// Cost: 8M + 3S + 3*a + 2*b3 + 15add.
|
|
6637
6991
|
double() {
|
|
6638
6992
|
const { a, b } = CURVE2;
|
|
6639
6993
|
const b3 = Fp.mul(b, 3n);
|
|
@@ -6672,6 +7026,10 @@ var starknet = (() => {
|
|
|
6672
7026
|
Z3 = Fp.add(Z3, Z3);
|
|
6673
7027
|
return new Point(X3, Y3, Z3);
|
|
6674
7028
|
}
|
|
7029
|
+
// Renes-Costello-Batina exception-free addition formula.
|
|
7030
|
+
// There is 30% faster Jacobian formula, but it is not complete.
|
|
7031
|
+
// https://eprint.iacr.org/2015/1060, algorithm 1
|
|
7032
|
+
// Cost: 12M + 0S + 3*a + 3*b3 + 23add.
|
|
6675
7033
|
add(other) {
|
|
6676
7034
|
assertPrjPoint(other);
|
|
6677
7035
|
const { px: X1, py: Y1, pz: Z1 } = this;
|
|
@@ -6733,6 +7091,11 @@ var starknet = (() => {
|
|
|
6733
7091
|
return comp.map((p, i) => p.toAffine(toInv[i])).map(Point.fromAffine);
|
|
6734
7092
|
});
|
|
6735
7093
|
}
|
|
7094
|
+
/**
|
|
7095
|
+
* Non-constant-time multiplication. Uses double-and-add algorithm.
|
|
7096
|
+
* It's faster, but should only be used when you don't care about
|
|
7097
|
+
* an exposed private key e.g. sig verification, which works over *public* keys.
|
|
7098
|
+
*/
|
|
6736
7099
|
multiplyUnsafe(n) {
|
|
6737
7100
|
const I = Point.ZERO;
|
|
6738
7101
|
if (n === _0n9)
|
|
@@ -6763,6 +7126,15 @@ var starknet = (() => {
|
|
|
6763
7126
|
k2p = new Point(Fp.mul(k2p.px, endo.beta), k2p.py, k2p.pz);
|
|
6764
7127
|
return k1p.add(k2p);
|
|
6765
7128
|
}
|
|
7129
|
+
/**
|
|
7130
|
+
* Constant time multiplication.
|
|
7131
|
+
* Uses wNAF method. Windowed method may be 10% faster,
|
|
7132
|
+
* but takes 2x longer to generate and consumes 2x memory.
|
|
7133
|
+
* Uses precomputes when available.
|
|
7134
|
+
* Uses endomorphism for Koblitz curves.
|
|
7135
|
+
* @param scalar by which the point would be multiplied
|
|
7136
|
+
* @returns New point
|
|
7137
|
+
*/
|
|
6766
7138
|
multiply(scalar) {
|
|
6767
7139
|
assertGE(scalar);
|
|
6768
7140
|
let n = scalar;
|
|
@@ -6784,12 +7156,21 @@ var starknet = (() => {
|
|
|
6784
7156
|
}
|
|
6785
7157
|
return Point.normalizeZ([point, fake])[0];
|
|
6786
7158
|
}
|
|
7159
|
+
/**
|
|
7160
|
+
* Efficiently calculate `aP + bQ`. Unsafe, can expose private key, if used incorrectly.
|
|
7161
|
+
* Not using Strauss-Shamir trick: precomputation tables are faster.
|
|
7162
|
+
* The trick could be useful if both P and Q are not G (not in our case).
|
|
7163
|
+
* @returns non-zero affine point
|
|
7164
|
+
*/
|
|
6787
7165
|
multiplyAndAddUnsafe(Q, a, b) {
|
|
6788
7166
|
const G = Point.BASE;
|
|
6789
7167
|
const mul = (P, a2) => a2 === _0n9 || a2 === _1n9 || !P.equals(G) ? P.multiplyUnsafe(a2) : P.multiply(a2);
|
|
6790
7168
|
const sum = mul(this, a).add(mul(Q, b));
|
|
6791
7169
|
return sum.is0() ? void 0 : sum;
|
|
6792
7170
|
}
|
|
7171
|
+
// Converts Projective point to affine (x, y) coordinates.
|
|
7172
|
+
// Can accept precomputed Z^-1 - for example, from invertBatch.
|
|
7173
|
+
// (x, y, z) ∋ (x=x/z, y=y/z)
|
|
6793
7174
|
toAffine(iz) {
|
|
6794
7175
|
const { px: x, py: y, pz: z } = this;
|
|
6795
7176
|
const is0 = this.is0();
|
|
@@ -6919,11 +7300,14 @@ var starknet = (() => {
|
|
|
6919
7300
|
this.recovery = recovery;
|
|
6920
7301
|
this.assertValidity();
|
|
6921
7302
|
}
|
|
7303
|
+
// pair (bytes of r, bytes of s)
|
|
6922
7304
|
static fromCompact(hex) {
|
|
6923
7305
|
const l = CURVE2.nByteLength;
|
|
6924
7306
|
hex = ensureBytes("compactSignature", hex, l * 2);
|
|
6925
7307
|
return new Signature3(slcNum(hex, 0, l), slcNum(hex, l, 2 * l));
|
|
6926
7308
|
}
|
|
7309
|
+
// DER encoded ECDSA signature
|
|
7310
|
+
// https://bitcoin.stackexchange.com/questions/57644/what-are-the-parts-of-a-bitcoin-transaction-input-script
|
|
6927
7311
|
static fromDER(hex) {
|
|
6928
7312
|
const { r, s } = DER2.toSig(ensureBytes("DER", hex));
|
|
6929
7313
|
return new Signature3(r, s);
|
|
@@ -6956,18 +7340,21 @@ var starknet = (() => {
|
|
|
6956
7340
|
Q.assertValidity();
|
|
6957
7341
|
return Q;
|
|
6958
7342
|
}
|
|
7343
|
+
// Signatures should be low-s, to prevent malleability.
|
|
6959
7344
|
hasHighS() {
|
|
6960
7345
|
return isBiggerThanHalfOrder(this.s);
|
|
6961
7346
|
}
|
|
6962
7347
|
normalizeS() {
|
|
6963
7348
|
return this.hasHighS() ? new Signature3(this.r, modN(-this.s), this.recovery) : this;
|
|
6964
7349
|
}
|
|
7350
|
+
// DER-encoded
|
|
6965
7351
|
toDERRawBytes() {
|
|
6966
7352
|
return hexToBytes(this.toDERHex());
|
|
6967
7353
|
}
|
|
6968
7354
|
toDERHex() {
|
|
6969
7355
|
return DER2.hexFromSig({ r: this.r, s: this.s });
|
|
6970
7356
|
}
|
|
7357
|
+
// padded bytes of r, then padded bytes of s
|
|
6971
7358
|
toCompactRawBytes() {
|
|
6972
7359
|
return hexToBytes(this.toCompactHex());
|
|
6973
7360
|
}
|
|
@@ -6985,11 +7372,23 @@ var starknet = (() => {
|
|
|
6985
7372
|
}
|
|
6986
7373
|
},
|
|
6987
7374
|
normPrivateKeyToScalar,
|
|
7375
|
+
/**
|
|
7376
|
+
* Produces cryptographically secure private key from random of size (nBitLength+64)
|
|
7377
|
+
* as per FIPS 186 B.4.1 with modulo bias being neglible.
|
|
7378
|
+
*/
|
|
6988
7379
|
randomPrivateKey: () => {
|
|
6989
7380
|
const rand = CURVE2.randomBytes(Fp.BYTES + 8);
|
|
6990
7381
|
const num = hashToPrivateScalar2(rand, CURVE_ORDER2);
|
|
6991
7382
|
return numberToBytesBE(num, CURVE2.nByteLength);
|
|
6992
7383
|
},
|
|
7384
|
+
/**
|
|
7385
|
+
* Creates precompute table for an arbitrary EC point. Makes point "cached".
|
|
7386
|
+
* Allows to massively speed-up `point.multiply(scalar)`.
|
|
7387
|
+
* @returns cached point
|
|
7388
|
+
* @example
|
|
7389
|
+
* const fast = utils.precompute(8, ProjectivePoint.fromHex(someonesPubKey));
|
|
7390
|
+
* fast.multiply(privKey); // much faster ECDH now
|
|
7391
|
+
*/
|
|
6993
7392
|
precompute(windowSize = 8, point = Point.BASE) {
|
|
6994
7393
|
point._setWindowSize(windowSize);
|
|
6995
7394
|
point.multiply(BigInt(3));
|
|
@@ -7085,7 +7484,6 @@ var starknet = (() => {
|
|
|
7085
7484
|
}
|
|
7086
7485
|
Point.BASE._setWindowSize(8);
|
|
7087
7486
|
function verify2(signature, msgHash, publicKey, opts = defaultVerOpts) {
|
|
7088
|
-
var _a;
|
|
7089
7487
|
const sg = signature;
|
|
7090
7488
|
msgHash = ensureBytes("msgHash", msgHash);
|
|
7091
7489
|
publicKey = ensureBytes("publicKey", publicKey);
|
|
@@ -7124,7 +7522,7 @@ var starknet = (() => {
|
|
|
7124
7522
|
const is = invN(s);
|
|
7125
7523
|
const u1 = modN(h * is);
|
|
7126
7524
|
const u2 = modN(r * is);
|
|
7127
|
-
const R =
|
|
7525
|
+
const R = Point.BASE.multiplyAndAddUnsafe(P, u1, u2)?.toAffine();
|
|
7128
7526
|
if (!R)
|
|
7129
7527
|
return false;
|
|
7130
7528
|
const v = modN(R.x);
|
|
@@ -7383,11 +7781,17 @@ var starknet = (() => {
|
|
|
7383
7781
|
}
|
|
7384
7782
|
throw new Error("Cannot safely convert to number: " + "the value '".concat(this.value, "' would ").concat(unsafeReason, " and become ").concat(parseFloat(this.value)));
|
|
7385
7783
|
}
|
|
7784
|
+
/**
|
|
7785
|
+
* Get the value of the LosslessNumber as string.
|
|
7786
|
+
*/
|
|
7386
7787
|
}, {
|
|
7387
7788
|
key: "toString",
|
|
7388
7789
|
value: function toString2() {
|
|
7389
7790
|
return this.value;
|
|
7390
7791
|
}
|
|
7792
|
+
// Note: we do NOT implement a .toJSON() method, and you should not implement
|
|
7793
|
+
// or use that, it cannot safely turn the numeric value in the string into
|
|
7794
|
+
// stringified JSON since it has to be parsed into a number first.
|
|
7391
7795
|
}]);
|
|
7392
7796
|
return LosslessNumber2;
|
|
7393
7797
|
}();
|
|
@@ -7758,6 +8162,7 @@ var starknet = (() => {
|
|
|
7758
8162
|
n: "\n",
|
|
7759
8163
|
r: "\r",
|
|
7760
8164
|
t: " "
|
|
8165
|
+
// note that \u is handled separately in parseString()
|
|
7761
8166
|
};
|
|
7762
8167
|
var codeBackslash = 92;
|
|
7763
8168
|
var codeOpeningBrace = 123;
|
|
@@ -8279,9 +8684,18 @@ var starknet = (() => {
|
|
|
8279
8684
|
var REP_3_6 = 16;
|
|
8280
8685
|
var REPZ_3_10 = 17;
|
|
8281
8686
|
var REPZ_11_138 = 18;
|
|
8282
|
-
var extra_lbits =
|
|
8283
|
-
|
|
8284
|
-
|
|
8687
|
+
var extra_lbits = (
|
|
8688
|
+
/* extra bits for each length code */
|
|
8689
|
+
new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0])
|
|
8690
|
+
);
|
|
8691
|
+
var extra_dbits = (
|
|
8692
|
+
/* extra bits for each distance code */
|
|
8693
|
+
new Uint8Array([0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13])
|
|
8694
|
+
);
|
|
8695
|
+
var extra_blbits = (
|
|
8696
|
+
/* extra bits for each bit length code */
|
|
8697
|
+
new Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7])
|
|
8698
|
+
);
|
|
8285
8699
|
var bl_order = new Uint8Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]);
|
|
8286
8700
|
var DIST_CODE_LEN = 512;
|
|
8287
8701
|
var static_ltree = new Array((L_CODES$1 + 2) * 2);
|
|
@@ -8331,7 +8745,12 @@ var starknet = (() => {
|
|
|
8331
8745
|
}
|
|
8332
8746
|
};
|
|
8333
8747
|
var send_code = (s, c, tree) => {
|
|
8334
|
-
send_bits(
|
|
8748
|
+
send_bits(
|
|
8749
|
+
s,
|
|
8750
|
+
tree[c * 2],
|
|
8751
|
+
tree[c * 2 + 1]
|
|
8752
|
+
/*.Len*/
|
|
8753
|
+
);
|
|
8335
8754
|
};
|
|
8336
8755
|
var bi_reverse = (code, len) => {
|
|
8337
8756
|
let res = 0;
|
|
@@ -8612,19 +9031,44 @@ var starknet = (() => {
|
|
|
8612
9031
|
}
|
|
8613
9032
|
node = elems;
|
|
8614
9033
|
do {
|
|
8615
|
-
n = s.heap[
|
|
8616
|
-
|
|
8617
|
-
|
|
8618
|
-
|
|
9034
|
+
n = s.heap[
|
|
9035
|
+
1
|
|
9036
|
+
/*SMALLEST*/
|
|
9037
|
+
];
|
|
9038
|
+
s.heap[
|
|
9039
|
+
1
|
|
9040
|
+
/*SMALLEST*/
|
|
9041
|
+
] = s.heap[s.heap_len--];
|
|
9042
|
+
pqdownheap(
|
|
9043
|
+
s,
|
|
9044
|
+
tree,
|
|
9045
|
+
1
|
|
9046
|
+
/*SMALLEST*/
|
|
9047
|
+
);
|
|
9048
|
+
m = s.heap[
|
|
9049
|
+
1
|
|
9050
|
+
/*SMALLEST*/
|
|
9051
|
+
];
|
|
8619
9052
|
s.heap[--s.heap_max] = n;
|
|
8620
9053
|
s.heap[--s.heap_max] = m;
|
|
8621
9054
|
tree[node * 2] = tree[n * 2] + tree[m * 2];
|
|
8622
9055
|
s.depth[node] = (s.depth[n] >= s.depth[m] ? s.depth[n] : s.depth[m]) + 1;
|
|
8623
9056
|
tree[n * 2 + 1] = tree[m * 2 + 1] = node;
|
|
8624
|
-
s.heap[
|
|
8625
|
-
|
|
9057
|
+
s.heap[
|
|
9058
|
+
1
|
|
9059
|
+
/*SMALLEST*/
|
|
9060
|
+
] = node++;
|
|
9061
|
+
pqdownheap(
|
|
9062
|
+
s,
|
|
9063
|
+
tree,
|
|
9064
|
+
1
|
|
9065
|
+
/*SMALLEST*/
|
|
9066
|
+
);
|
|
8626
9067
|
} while (s.heap_len >= 2);
|
|
8627
|
-
s.heap[--s.heap_max] = s.heap[
|
|
9068
|
+
s.heap[--s.heap_max] = s.heap[
|
|
9069
|
+
1
|
|
9070
|
+
/*SMALLEST*/
|
|
9071
|
+
];
|
|
8628
9072
|
gen_bitlen(s, desc);
|
|
8629
9073
|
gen_codes(tree, max_code, s.bl_count);
|
|
8630
9074
|
};
|
|
@@ -8889,16 +9333,26 @@ var starknet = (() => {
|
|
|
8889
9333
|
var crc32_1 = crc32;
|
|
8890
9334
|
var messages = {
|
|
8891
9335
|
2: "need dictionary",
|
|
9336
|
+
/* Z_NEED_DICT 2 */
|
|
8892
9337
|
1: "stream end",
|
|
9338
|
+
/* Z_STREAM_END 1 */
|
|
8893
9339
|
0: "",
|
|
9340
|
+
/* Z_OK 0 */
|
|
8894
9341
|
"-1": "file error",
|
|
9342
|
+
/* Z_ERRNO (-1) */
|
|
8895
9343
|
"-2": "stream error",
|
|
9344
|
+
/* Z_STREAM_ERROR (-2) */
|
|
8896
9345
|
"-3": "data error",
|
|
9346
|
+
/* Z_DATA_ERROR (-3) */
|
|
8897
9347
|
"-4": "insufficient memory",
|
|
9348
|
+
/* Z_MEM_ERROR (-4) */
|
|
8898
9349
|
"-5": "buffer error",
|
|
9350
|
+
/* Z_BUF_ERROR (-5) */
|
|
8899
9351
|
"-6": "incompatible version"
|
|
9352
|
+
/* Z_VERSION_ERROR (-6) */
|
|
8900
9353
|
};
|
|
8901
9354
|
var constants$2 = {
|
|
9355
|
+
/* Allowed flush values; see deflate() and inflate() below for details */
|
|
8902
9356
|
Z_NO_FLUSH: 0,
|
|
8903
9357
|
Z_PARTIAL_FLUSH: 1,
|
|
8904
9358
|
Z_SYNC_FLUSH: 2,
|
|
@@ -8906,6 +9360,9 @@ var starknet = (() => {
|
|
|
8906
9360
|
Z_FINISH: 4,
|
|
8907
9361
|
Z_BLOCK: 5,
|
|
8908
9362
|
Z_TREES: 6,
|
|
9363
|
+
/* Return codes for the compression/decompression functions. Negative values
|
|
9364
|
+
* are errors, positive values are used for special but normal events.
|
|
9365
|
+
*/
|
|
8909
9366
|
Z_OK: 0,
|
|
8910
9367
|
Z_STREAM_END: 1,
|
|
8911
9368
|
Z_NEED_DICT: 2,
|
|
@@ -8914,6 +9371,8 @@ var starknet = (() => {
|
|
|
8914
9371
|
Z_DATA_ERROR: -3,
|
|
8915
9372
|
Z_MEM_ERROR: -4,
|
|
8916
9373
|
Z_BUF_ERROR: -5,
|
|
9374
|
+
//Z_VERSION_ERROR: -6,
|
|
9375
|
+
/* compression levels */
|
|
8917
9376
|
Z_NO_COMPRESSION: 0,
|
|
8918
9377
|
Z_BEST_SPEED: 1,
|
|
8919
9378
|
Z_BEST_COMPRESSION: 9,
|
|
@@ -8923,10 +9382,14 @@ var starknet = (() => {
|
|
|
8923
9382
|
Z_RLE: 3,
|
|
8924
9383
|
Z_FIXED: 4,
|
|
8925
9384
|
Z_DEFAULT_STRATEGY: 0,
|
|
9385
|
+
/* Possible values of the data_type field (though see inflate()) */
|
|
8926
9386
|
Z_BINARY: 0,
|
|
8927
9387
|
Z_TEXT: 1,
|
|
9388
|
+
//Z_ASCII: 1, // = Z_TEXT (deprecated)
|
|
8928
9389
|
Z_UNKNOWN: 2,
|
|
9390
|
+
/* The deflate compression method */
|
|
8929
9391
|
Z_DEFLATED: 8
|
|
9392
|
+
//Z_NULL: null // Use -1 or null inline, depending on var type
|
|
8930
9393
|
};
|
|
8931
9394
|
var { _tr_init, _tr_stored_block, _tr_flush_block, _tr_tally, _tr_align } = trees;
|
|
8932
9395
|
var {
|
|
@@ -9521,16 +9984,27 @@ var starknet = (() => {
|
|
|
9521
9984
|
this.func = func;
|
|
9522
9985
|
}
|
|
9523
9986
|
var configuration_table = [
|
|
9987
|
+
/* good lazy nice chain */
|
|
9524
9988
|
new Config(0, 0, 0, 0, deflate_stored),
|
|
9989
|
+
/* 0 store only */
|
|
9525
9990
|
new Config(4, 4, 8, 4, deflate_fast),
|
|
9991
|
+
/* 1 max speed, no lazy matches */
|
|
9526
9992
|
new Config(4, 5, 16, 8, deflate_fast),
|
|
9993
|
+
/* 2 */
|
|
9527
9994
|
new Config(4, 6, 32, 32, deflate_fast),
|
|
9995
|
+
/* 3 */
|
|
9528
9996
|
new Config(4, 4, 16, 16, deflate_slow),
|
|
9997
|
+
/* 4 lazy matches */
|
|
9529
9998
|
new Config(8, 16, 32, 32, deflate_slow),
|
|
9999
|
+
/* 5 */
|
|
9530
10000
|
new Config(8, 16, 128, 128, deflate_slow),
|
|
10001
|
+
/* 6 */
|
|
9531
10002
|
new Config(8, 32, 128, 256, deflate_slow),
|
|
10003
|
+
/* 7 */
|
|
9532
10004
|
new Config(32, 128, 258, 1024, deflate_slow),
|
|
10005
|
+
/* 8 */
|
|
9533
10006
|
new Config(32, 258, 258, 4096, deflate_slow)
|
|
10007
|
+
/* 9 max compression */
|
|
9534
10008
|
];
|
|
9535
10009
|
var lm_init = (s) => {
|
|
9536
10010
|
s.window_size = 2 * s.w_size;
|
|
@@ -9617,7 +10091,9 @@ var starknet = (() => {
|
|
|
9617
10091
|
return 1;
|
|
9618
10092
|
}
|
|
9619
10093
|
const s = strm.state;
|
|
9620
|
-
if (!s || s.strm !== strm || s.status !== INIT_STATE &&
|
|
10094
|
+
if (!s || s.strm !== strm || s.status !== INIT_STATE && //#ifdef GZIP
|
|
10095
|
+
s.status !== GZIP_STATE && //#endif
|
|
10096
|
+
s.status !== EXTRA_STATE && s.status !== NAME_STATE && s.status !== COMMENT_STATE && s.status !== HCRC_STATE && s.status !== BUSY_STATE && s.status !== FINISH_STATE) {
|
|
9621
10097
|
return 1;
|
|
9622
10098
|
}
|
|
9623
10099
|
return 0;
|
|
@@ -9634,7 +10110,11 @@ var starknet = (() => {
|
|
|
9634
10110
|
if (s.wrap < 0) {
|
|
9635
10111
|
s.wrap = -s.wrap;
|
|
9636
10112
|
}
|
|
9637
|
-
s.status =
|
|
10113
|
+
s.status = //#ifdef GZIP
|
|
10114
|
+
s.wrap === 2 ? GZIP_STATE : (
|
|
10115
|
+
//#endif
|
|
10116
|
+
s.wrap ? INIT_STATE : BUSY_STATE
|
|
10117
|
+
);
|
|
9638
10118
|
strm.adler = s.wrap === 2 ? 0 : 1;
|
|
9639
10119
|
s.last_flush = -2;
|
|
9640
10120
|
_tr_init(s);
|
|
@@ -10619,6 +11099,7 @@ var starknet = (() => {
|
|
|
10619
11099
|
var LENS$1 = 1;
|
|
10620
11100
|
var DISTS$1 = 2;
|
|
10621
11101
|
var lbase = new Uint16Array([
|
|
11102
|
+
/* Length codes 257..285 base */
|
|
10622
11103
|
3,
|
|
10623
11104
|
4,
|
|
10624
11105
|
5,
|
|
@@ -10652,6 +11133,7 @@ var starknet = (() => {
|
|
|
10652
11133
|
0
|
|
10653
11134
|
]);
|
|
10654
11135
|
var lext = new Uint8Array([
|
|
11136
|
+
/* Length codes 257..285 extra */
|
|
10655
11137
|
16,
|
|
10656
11138
|
16,
|
|
10657
11139
|
16,
|
|
@@ -10685,6 +11167,7 @@ var starknet = (() => {
|
|
|
10685
11167
|
78
|
|
10686
11168
|
]);
|
|
10687
11169
|
var dbase = new Uint16Array([
|
|
11170
|
+
/* Distance codes 0..29 base */
|
|
10688
11171
|
1,
|
|
10689
11172
|
2,
|
|
10690
11173
|
3,
|
|
@@ -10719,6 +11202,7 @@ var starknet = (() => {
|
|
|
10719
11202
|
0
|
|
10720
11203
|
]);
|
|
10721
11204
|
var dext = new Uint8Array([
|
|
11205
|
+
/* Distance codes 0..29 extra */
|
|
10722
11206
|
16,
|
|
10723
11207
|
16,
|
|
10724
11208
|
16,
|
|
@@ -11182,7 +11666,10 @@ var starknet = (() => {
|
|
|
11182
11666
|
const hbuf = new Uint8Array(4);
|
|
11183
11667
|
let opts;
|
|
11184
11668
|
let n;
|
|
11185
|
-
const order =
|
|
11669
|
+
const order = (
|
|
11670
|
+
/* permutation of code lengths */
|
|
11671
|
+
new Uint8Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15])
|
|
11672
|
+
);
|
|
11186
11673
|
if (inflateStateCheck(strm) || !strm.output || !strm.input && strm.avail_in !== 0) {
|
|
11187
11674
|
return Z_STREAM_ERROR$1;
|
|
11188
11675
|
}
|
|
@@ -11233,7 +11720,8 @@ var starknet = (() => {
|
|
|
11233
11720
|
if (state.head) {
|
|
11234
11721
|
state.head.done = false;
|
|
11235
11722
|
}
|
|
11236
|
-
if (!(state.wrap & 1) ||
|
|
11723
|
+
if (!(state.wrap & 1) || /* check if zlib header allowed */
|
|
11724
|
+
(((hold & 255) << 8) + (hold >> 8)) % 31) {
|
|
11237
11725
|
strm.msg = "incorrect header check";
|
|
11238
11726
|
state.mode = BAD;
|
|
11239
11727
|
break;
|
|
@@ -11375,8 +11863,11 @@ var starknet = (() => {
|
|
|
11375
11863
|
state.head.extra.set(
|
|
11376
11864
|
input.subarray(
|
|
11377
11865
|
next,
|
|
11866
|
+
// extra field is limited to 65536 bytes
|
|
11867
|
+
// - no need for additional size check
|
|
11378
11868
|
next + copy
|
|
11379
11869
|
),
|
|
11870
|
+
/*len + copy > state.head.extra_max - len ? state.head.extra_max : copy,*/
|
|
11380
11871
|
len
|
|
11381
11872
|
);
|
|
11382
11873
|
}
|
|
@@ -11991,7 +12482,8 @@ var starknet = (() => {
|
|
|
11991
12482
|
strm.total_out += _out;
|
|
11992
12483
|
state.total += _out;
|
|
11993
12484
|
if (state.wrap & 4 && _out) {
|
|
11994
|
-
strm.adler = state.check =
|
|
12485
|
+
strm.adler = state.check = /*UPDATE_CHECK(state.check, put - _out, _out);*/
|
|
12486
|
+
state.flags ? crc32_1(state.check, output2, _out, put - _out) : adler32_1(state.check, output2, _out, put - _out);
|
|
11995
12487
|
}
|
|
11996
12488
|
_out = left;
|
|
11997
12489
|
if (state.wrap & 4 && (state.flags ? hold : zswap32(hold)) !== state.check) {
|
|
@@ -12051,7 +12543,8 @@ var starknet = (() => {
|
|
|
12051
12543
|
strm.total_out += _out;
|
|
12052
12544
|
state.total += _out;
|
|
12053
12545
|
if (state.wrap & 4 && _out) {
|
|
12054
|
-
strm.adler = state.check =
|
|
12546
|
+
strm.adler = state.check = /*UPDATE_CHECK(state.check, strm.next_out - _out, _out);*/
|
|
12547
|
+
state.flags ? crc32_1(state.check, output2, _out, strm.next_out - _out) : adler32_1(state.check, output2, _out, strm.next_out - _out);
|
|
12055
12548
|
}
|
|
12056
12549
|
strm.data_type = state.bits + (state.last ? 64 : 0) + (state.mode === TYPE ? 128 : 0) + (state.mode === LEN_ || state.mode === COPY_ ? 256 : 0);
|
|
12057
12550
|
if ((_in === 0 && _out === 0 || flush === Z_FINISH$1) && ret === Z_OK$1) {
|
|
@@ -12380,6 +12873,7 @@ var starknet = (() => {
|
|
|
12380
12873
|
if (!isSierra(contract)) {
|
|
12381
12874
|
return {
|
|
12382
12875
|
...parsedContract,
|
|
12876
|
+
// TODO: Why do we gzip program object?
|
|
12383
12877
|
..."program" in parsedContract && { program: compressProgram(parsedContract.program) }
|
|
12384
12878
|
};
|
|
12385
12879
|
}
|
|
@@ -12632,6 +13126,7 @@ var starknet = (() => {
|
|
|
12632
13126
|
this.tag = "pending";
|
|
12633
13127
|
}
|
|
12634
13128
|
}
|
|
13129
|
+
// TODO: fix any
|
|
12635
13130
|
get queryIdentifier() {
|
|
12636
13131
|
if (this.number !== null) {
|
|
12637
13132
|
return `blockNumber=${this.number}`;
|
|
@@ -12641,6 +13136,7 @@ var starknet = (() => {
|
|
|
12641
13136
|
}
|
|
12642
13137
|
return `blockNumber=${this.tag}`;
|
|
12643
13138
|
}
|
|
13139
|
+
// TODO: fix any
|
|
12644
13140
|
get identifier() {
|
|
12645
13141
|
if (this.number !== null) {
|
|
12646
13142
|
return { block_number: this.number };
|
|
@@ -12688,17 +13184,17 @@ var starknet = (() => {
|
|
|
12688
13184
|
}
|
|
12689
13185
|
}
|
|
12690
13186
|
async fetchEndpoint(method, params) {
|
|
12691
|
-
var _a;
|
|
12692
13187
|
try {
|
|
12693
13188
|
const rawResult = await this.fetch(method, params);
|
|
12694
13189
|
const { error, result } = await rawResult.json();
|
|
12695
13190
|
this.errorHandler(error);
|
|
12696
13191
|
return result;
|
|
12697
13192
|
} catch (error) {
|
|
12698
|
-
this.errorHandler(
|
|
13193
|
+
this.errorHandler(error?.response?.data);
|
|
12699
13194
|
throw error;
|
|
12700
13195
|
}
|
|
12701
13196
|
}
|
|
13197
|
+
// Methods from Interface
|
|
12702
13198
|
async getChainId() {
|
|
12703
13199
|
this.chainId ?? (this.chainId = await this.fetchEndpoint("starknet_chainId"));
|
|
12704
13200
|
return this.chainId;
|
|
@@ -12752,6 +13248,7 @@ var starknet = (() => {
|
|
|
12752
13248
|
block_id
|
|
12753
13249
|
});
|
|
12754
13250
|
}
|
|
13251
|
+
// Methods from Interface
|
|
12755
13252
|
async getTransaction(txHash) {
|
|
12756
13253
|
return this.getTransactionByHash(txHash).then(this.responseParser.parseGetTransactionResponse);
|
|
12757
13254
|
}
|
|
@@ -12793,9 +13290,9 @@ var starknet = (() => {
|
|
|
12793
13290
|
sender_address: invocation.contractAddress,
|
|
12794
13291
|
calldata: CallData.toHex(invocation.calldata),
|
|
12795
13292
|
signature: signatureToHexArray(invocation.signature),
|
|
12796
|
-
version: toHex(
|
|
13293
|
+
version: toHex(invocationDetails?.version || 0),
|
|
12797
13294
|
nonce: toHex(invocationDetails.nonce),
|
|
12798
|
-
max_fee: toHex(
|
|
13295
|
+
max_fee: toHex(invocationDetails?.maxFee || 0)
|
|
12799
13296
|
},
|
|
12800
13297
|
block_id
|
|
12801
13298
|
}).then(this.responseParser.parseFeeEstimateResponse);
|
|
@@ -12810,12 +13307,13 @@ var starknet = (() => {
|
|
|
12810
13307
|
program: contractDefinition.program,
|
|
12811
13308
|
entry_points_by_type: contractDefinition.entry_points_by_type,
|
|
12812
13309
|
abi: contractDefinition.abi
|
|
13310
|
+
// rpc 2.0
|
|
12813
13311
|
},
|
|
12814
13312
|
sender_address: senderAddress,
|
|
12815
13313
|
signature: signatureToHexArray(signature),
|
|
12816
|
-
version: toHex(
|
|
13314
|
+
version: toHex(details?.version || 0),
|
|
12817
13315
|
nonce: toHex(details.nonce),
|
|
12818
|
-
max_fee: toHex(
|
|
13316
|
+
max_fee: toHex(details?.maxFee || 0)
|
|
12819
13317
|
},
|
|
12820
13318
|
block_id
|
|
12821
13319
|
}).then(this.responseParser.parseFeeEstimateResponse);
|
|
@@ -12831,9 +13329,9 @@ var starknet = (() => {
|
|
|
12831
13329
|
class_hash: toHex(classHash),
|
|
12832
13330
|
contract_address_salt: toHex(addressSalt || 0),
|
|
12833
13331
|
signature: signatureToHexArray(signature),
|
|
12834
|
-
version: toHex(
|
|
13332
|
+
version: toHex(details?.version || 0),
|
|
12835
13333
|
nonce: toHex(details.nonce),
|
|
12836
|
-
max_fee: toHex(
|
|
13334
|
+
max_fee: toHex(details?.maxFee || 0)
|
|
12837
13335
|
},
|
|
12838
13336
|
block_id
|
|
12839
13337
|
}).then(this.responseParser.parseFeeEstimateResponse);
|
|
@@ -12841,6 +13339,7 @@ var starknet = (() => {
|
|
|
12841
13339
|
async getEstimateFeeBulk(_invocations, _blockIdentifier = this.blockIdentifier) {
|
|
12842
13340
|
throw new Error("RPC does not implement getInvokeEstimateFeeBulk function");
|
|
12843
13341
|
}
|
|
13342
|
+
// TODO: Revisit after Pathfinder release with JSON-RPC v0.2.1 RPC Spec
|
|
12844
13343
|
async declareContract({ contractDefinition, signature, senderAddress }, details) {
|
|
12845
13344
|
if ("program" in contractDefinition) {
|
|
12846
13345
|
return this.fetchEndpoint("starknet_addDeclareTransaction", {
|
|
@@ -12849,6 +13348,7 @@ var starknet = (() => {
|
|
|
12849
13348
|
program: contractDefinition.program,
|
|
12850
13349
|
entry_points_by_type: contractDefinition.entry_points_by_type,
|
|
12851
13350
|
abi: contractDefinition.abi
|
|
13351
|
+
// rpc 2.0
|
|
12852
13352
|
},
|
|
12853
13353
|
type: RPC.TransactionType.DECLARE,
|
|
12854
13354
|
version: "0x1",
|
|
@@ -12888,6 +13388,7 @@ var starknet = (() => {
|
|
|
12888
13388
|
}
|
|
12889
13389
|
});
|
|
12890
13390
|
}
|
|
13391
|
+
// Methods from Interface
|
|
12891
13392
|
async callContract(call, blockIdentifier = this.blockIdentifier) {
|
|
12892
13393
|
const block_id = new Block(blockIdentifier).identifier;
|
|
12893
13394
|
const result = await this.fetchEndpoint("starknet_call", {
|
|
@@ -12911,8 +13412,8 @@ var starknet = (() => {
|
|
|
12911
13412
|
let { retries } = this;
|
|
12912
13413
|
let onchain = false;
|
|
12913
13414
|
let txReceipt = {};
|
|
12914
|
-
const retryInterval =
|
|
12915
|
-
const successStates =
|
|
13415
|
+
const retryInterval = options?.retryInterval ?? 8e3;
|
|
13416
|
+
const successStates = options?.successStates ?? [
|
|
12916
13417
|
"ACCEPTED_ON_L1" /* ACCEPTED_ON_L1 */,
|
|
12917
13418
|
"ACCEPTED_ON_L2" /* ACCEPTED_ON_L2 */,
|
|
12918
13419
|
"PENDING" /* PENDING */
|
|
@@ -12946,16 +13447,41 @@ var starknet = (() => {
|
|
|
12946
13447
|
await wait(retryInterval);
|
|
12947
13448
|
return txReceipt;
|
|
12948
13449
|
}
|
|
13450
|
+
/**
|
|
13451
|
+
* Gets the transaction count from a block.
|
|
13452
|
+
*
|
|
13453
|
+
*
|
|
13454
|
+
* @param blockIdentifier
|
|
13455
|
+
* @returns Number of transactions
|
|
13456
|
+
*/
|
|
12949
13457
|
async getTransactionCount(blockIdentifier = this.blockIdentifier) {
|
|
12950
13458
|
const block_id = new Block(blockIdentifier).identifier;
|
|
12951
13459
|
return this.fetchEndpoint("starknet_getBlockTransactionCount", { block_id });
|
|
12952
13460
|
}
|
|
13461
|
+
/**
|
|
13462
|
+
* Gets the latest block number
|
|
13463
|
+
*
|
|
13464
|
+
*
|
|
13465
|
+
* @returns Number of the latest block
|
|
13466
|
+
*/
|
|
12953
13467
|
async getBlockNumber() {
|
|
12954
13468
|
return this.fetchEndpoint("starknet_blockNumber");
|
|
12955
13469
|
}
|
|
13470
|
+
/**
|
|
13471
|
+
* Gets syncing status of the node
|
|
13472
|
+
*
|
|
13473
|
+
*
|
|
13474
|
+
* @returns Object with the stats data
|
|
13475
|
+
*/
|
|
12956
13476
|
async getSyncingStats() {
|
|
12957
13477
|
return this.fetchEndpoint("starknet_syncing");
|
|
12958
13478
|
}
|
|
13479
|
+
/**
|
|
13480
|
+
* Gets all the events filtered
|
|
13481
|
+
*
|
|
13482
|
+
*
|
|
13483
|
+
* @returns events and the pagination of the events
|
|
13484
|
+
*/
|
|
12959
13485
|
async getEvents(eventFilter) {
|
|
12960
13486
|
return this.fetchEndpoint("starknet_getEvents", { filter: eventFilter });
|
|
12961
13487
|
}
|
|
@@ -13006,6 +13532,7 @@ var starknet = (() => {
|
|
|
13006
13532
|
transaction_hash: res.transaction_hash,
|
|
13007
13533
|
status: res.status,
|
|
13008
13534
|
messages_sent: res.l2_to_l1_messages,
|
|
13535
|
+
// TODO: parse
|
|
13009
13536
|
events: res.events,
|
|
13010
13537
|
..."block_hash" in res && { block_hash: res.block_hash },
|
|
13011
13538
|
..."block_number" in res && { block_number: res.block_number },
|
|
@@ -13013,6 +13540,7 @@ var starknet = (() => {
|
|
|
13013
13540
|
..."transaction_index" in res && { transaction_index: res.transaction_index },
|
|
13014
13541
|
..."execution_resources" in res && { execution_resources: res.execution_resources },
|
|
13015
13542
|
..."l1_to_l2_consumed_message" in res && {
|
|
13543
|
+
// eslint-disable-next-line @typescript-eslint/dot-notation
|
|
13016
13544
|
l1_to_l2_consumed_message: res["l1_to_l2_consumed_message"]
|
|
13017
13545
|
},
|
|
13018
13546
|
..."transaction_failure_reason" in res && {
|
|
@@ -13124,6 +13652,7 @@ var starknet = (() => {
|
|
|
13124
13652
|
}
|
|
13125
13653
|
};
|
|
13126
13654
|
}
|
|
13655
|
+
// TODO: Define response as new type as it diff from ContractClass
|
|
13127
13656
|
parseSierraContractClassResponse(res) {
|
|
13128
13657
|
return {
|
|
13129
13658
|
...res,
|
|
@@ -13185,9 +13714,9 @@ var starknet = (() => {
|
|
|
13185
13714
|
);
|
|
13186
13715
|
this.gatewayUrl = buildUrl(this.baseUrl, "gateway", optionsOrProvider.gatewayUrl);
|
|
13187
13716
|
}
|
|
13188
|
-
this.chainId =
|
|
13717
|
+
this.chainId = optionsOrProvider?.chainId ?? SequencerProvider.getChainIdFromBaseUrl(this.baseUrl);
|
|
13189
13718
|
this.headers = optionsOrProvider.headers;
|
|
13190
|
-
this.blockIdentifier =
|
|
13719
|
+
this.blockIdentifier = optionsOrProvider?.blockIdentifier || defaultOptions2.blockIdentifier;
|
|
13191
13720
|
}
|
|
13192
13721
|
static getNetworkFromName(name) {
|
|
13193
13722
|
switch (name) {
|
|
@@ -13253,6 +13782,7 @@ var starknet = (() => {
|
|
|
13253
13782
|
}
|
|
13254
13783
|
return this.headers;
|
|
13255
13784
|
}
|
|
13785
|
+
// typesafe fetch
|
|
13256
13786
|
async fetchEndpoint(endpoint, ...[query, request]) {
|
|
13257
13787
|
const baseUrl = this.getFetchUrl(endpoint);
|
|
13258
13788
|
const method = this.getFetchMethod(endpoint);
|
|
@@ -13265,9 +13795,9 @@ var starknet = (() => {
|
|
|
13265
13795
|
}
|
|
13266
13796
|
async fetch(endpoint, options) {
|
|
13267
13797
|
const url = buildUrl(this.baseUrl, "", endpoint);
|
|
13268
|
-
const method =
|
|
13798
|
+
const method = options?.method ?? "GET";
|
|
13269
13799
|
const headers = this.getHeaders(method);
|
|
13270
|
-
const body = stringify2(options
|
|
13800
|
+
const body = stringify2(options?.body);
|
|
13271
13801
|
try {
|
|
13272
13802
|
const response = await fetchPonyfill_default(url, {
|
|
13273
13803
|
method,
|
|
@@ -13284,7 +13814,7 @@ var starknet = (() => {
|
|
|
13284
13814
|
}
|
|
13285
13815
|
throw new GatewayError(responseBody.message, responseBody.code);
|
|
13286
13816
|
}
|
|
13287
|
-
const parseChoice =
|
|
13817
|
+
const parseChoice = options?.parseAlwaysAsBigInt ? parseAlwaysAsBig : parse2;
|
|
13288
13818
|
return parseChoice(textResponse);
|
|
13289
13819
|
} catch (error) {
|
|
13290
13820
|
if (error instanceof Error && !(error instanceof LibraryError))
|
|
@@ -13300,6 +13830,9 @@ var starknet = (() => {
|
|
|
13300
13830
|
"call_contract",
|
|
13301
13831
|
{ blockIdentifier },
|
|
13302
13832
|
{
|
|
13833
|
+
// TODO - determine best choice once both are fully supported in devnet
|
|
13834
|
+
// signature: [],
|
|
13835
|
+
// sender_address: contractAddress,
|
|
13303
13836
|
contract_address: contractAddress,
|
|
13304
13837
|
entry_point_selector: getSelectorFromName(entryPointSelector),
|
|
13305
13838
|
calldata: CallData.compile(calldata)
|
|
@@ -13418,7 +13951,7 @@ var starknet = (() => {
|
|
|
13418
13951
|
sender_address: invocation.contractAddress,
|
|
13419
13952
|
calldata: CallData.compile(invocation.calldata ?? []),
|
|
13420
13953
|
signature: signatureToDecimalArray(invocation.signature),
|
|
13421
|
-
version: toHex(
|
|
13954
|
+
version: toHex(invocationDetails?.version || 1),
|
|
13422
13955
|
nonce: toHex(invocationDetails.nonce)
|
|
13423
13956
|
}
|
|
13424
13957
|
).then(this.responseParser.parseFeeEstimateResponse);
|
|
@@ -13433,7 +13966,7 @@ var starknet = (() => {
|
|
|
13433
13966
|
sender_address: senderAddress,
|
|
13434
13967
|
contract_class: contractDefinition,
|
|
13435
13968
|
signature: signatureToDecimalArray(signature),
|
|
13436
|
-
version: toHex(
|
|
13969
|
+
version: toHex(details?.version || toBigInt(feeTransactionVersion)),
|
|
13437
13970
|
nonce: toHex(details.nonce)
|
|
13438
13971
|
}
|
|
13439
13972
|
).then(this.responseParser.parseFeeEstimateResponse);
|
|
@@ -13462,7 +13995,7 @@ var starknet = (() => {
|
|
|
13462
13995
|
constructor_calldata: CallData.compile(constructorCalldata || []),
|
|
13463
13996
|
contract_address_salt: toHex(addressSalt || 0),
|
|
13464
13997
|
signature: signatureToDecimalArray(signature),
|
|
13465
|
-
version: toHex(
|
|
13998
|
+
version: toHex(details?.version || 0),
|
|
13466
13999
|
nonce: toHex(details.nonce)
|
|
13467
14000
|
}
|
|
13468
14001
|
).then(this.responseParser.parseFeeEstimateResponse);
|
|
@@ -13493,7 +14026,7 @@ var starknet = (() => {
|
|
|
13493
14026
|
return {
|
|
13494
14027
|
...res,
|
|
13495
14028
|
signature: bigNumberishArrayToDecimalStringArray(formatSignature(invocation.signature)),
|
|
13496
|
-
version: toHex(toBigInt(
|
|
14029
|
+
version: toHex(toBigInt(invocation?.version || 1)),
|
|
13497
14030
|
nonce: toHex(toBigInt(invocation.nonce))
|
|
13498
14031
|
};
|
|
13499
14032
|
});
|
|
@@ -13508,8 +14041,8 @@ var starknet = (() => {
|
|
|
13508
14041
|
const errorStates = ["REJECTED" /* REJECTED */, "NOT_RECEIVED" /* NOT_RECEIVED */];
|
|
13509
14042
|
let onchain = false;
|
|
13510
14043
|
let res;
|
|
13511
|
-
const retryInterval =
|
|
13512
|
-
const successStates =
|
|
14044
|
+
const retryInterval = options?.retryInterval ?? 8e3;
|
|
14045
|
+
const successStates = options?.successStates ?? [
|
|
13513
14046
|
"ACCEPTED_ON_L1" /* ACCEPTED_ON_L1 */,
|
|
13514
14047
|
"ACCEPTED_ON_L2" /* ACCEPTED_ON_L2 */,
|
|
13515
14048
|
"PENDING" /* PENDING */
|
|
@@ -13530,13 +14063,33 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
13530
14063
|
const txReceipt = await this.getTransactionReceipt(txHash);
|
|
13531
14064
|
return txReceipt;
|
|
13532
14065
|
}
|
|
14066
|
+
/**
|
|
14067
|
+
* Gets the status of a transaction.
|
|
14068
|
+
*
|
|
14069
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L48-L52)
|
|
14070
|
+
*
|
|
14071
|
+
* @param txHash
|
|
14072
|
+
* @returns the transaction status object \{ block_number, tx_status: NOT_RECEIVED | RECEIVED | PENDING | REJECTED | ACCEPTED_ONCHAIN \}
|
|
14073
|
+
*/
|
|
13533
14074
|
async getTransactionStatus(txHash) {
|
|
13534
14075
|
const txHashHex = toHex(txHash);
|
|
13535
14076
|
return this.fetchEndpoint("get_transaction_status", { transactionHash: txHashHex });
|
|
13536
14077
|
}
|
|
14078
|
+
/**
|
|
14079
|
+
* Gets the smart contract address on the goerli testnet.
|
|
14080
|
+
*
|
|
14081
|
+
* [Reference](https://github.com/starkware-libs/cairo-lang/blob/f464ec4797361b6be8989e36e02ec690e74ef285/src/starkware/starknet/services/api/feeder_gateway/feeder_gateway_client.py#L13-L15)
|
|
14082
|
+
* @returns starknet smart contract addresses
|
|
14083
|
+
*/
|
|
13537
14084
|
async getContractAddresses() {
|
|
13538
14085
|
return this.fetchEndpoint("get_contract_addresses");
|
|
13539
14086
|
}
|
|
14087
|
+
/**
|
|
14088
|
+
* Gets the transaction trace from a tx id.
|
|
14089
|
+
*
|
|
14090
|
+
* @param txHash
|
|
14091
|
+
* @returns the transaction trace
|
|
14092
|
+
*/
|
|
13540
14093
|
async getTransactionTrace(txHash) {
|
|
13541
14094
|
const txHashHex = toHex(txHash);
|
|
13542
14095
|
return this.fetchEndpoint("get_transaction_trace", { transactionHash: txHashHex });
|
|
@@ -13559,9 +14112,9 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
13559
14112
|
sender_address: invocation.contractAddress,
|
|
13560
14113
|
calldata: CallData.compile(invocation.calldata ?? []),
|
|
13561
14114
|
signature: signatureToDecimalArray(invocation.signature),
|
|
13562
|
-
version: toHex(
|
|
14115
|
+
version: toHex(invocationDetails?.version || 1),
|
|
13563
14116
|
nonce: toHex(invocationDetails.nonce),
|
|
13564
|
-
max_fee: toHex(
|
|
14117
|
+
max_fee: toHex(invocationDetails?.maxFee || 0)
|
|
13565
14118
|
}
|
|
13566
14119
|
).then(this.responseParser.parseFeeSimulateTransactionResponse);
|
|
13567
14120
|
}
|
|
@@ -13571,6 +14124,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
13571
14124
|
this.responseParser.parseGetStateUpdateResponse
|
|
13572
14125
|
);
|
|
13573
14126
|
}
|
|
14127
|
+
// consider adding an optional trace retrieval parameter to the getBlock method
|
|
13574
14128
|
async getBlockTraces(blockIdentifier = this.blockIdentifier) {
|
|
13575
14129
|
const args = new Block(blockIdentifier).sequencerIdentifier;
|
|
13576
14130
|
return this.fetchEndpoint("get_block_traces", { ...args });
|
|
@@ -13755,6 +14309,13 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
13755
14309
|
return callback();
|
|
13756
14310
|
}
|
|
13757
14311
|
var Contract = class {
|
|
14312
|
+
/**
|
|
14313
|
+
* Contract class to handle contract methods
|
|
14314
|
+
*
|
|
14315
|
+
* @param abi - Abi of the contract object
|
|
14316
|
+
* @param address (optional) - address to connect to
|
|
14317
|
+
* @param providerOrAccount (optional) - Provider or Account to attach to
|
|
14318
|
+
*/
|
|
13758
14319
|
constructor(abi, address, providerOrAccount = defaultProvider) {
|
|
13759
14320
|
this.address = address && address.toLowerCase();
|
|
13760
14321
|
this.providerOrAccount = providerOrAccount;
|
|
@@ -13917,6 +14478,13 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
13917
14478
|
this.classHash = classHash;
|
|
13918
14479
|
this.CallData = new CallData(abi);
|
|
13919
14480
|
}
|
|
14481
|
+
/**
|
|
14482
|
+
* Deploys contract and returns new instance of the Contract
|
|
14483
|
+
*
|
|
14484
|
+
* @param args - Array of the constructor arguments for deployment
|
|
14485
|
+
* @param options (optional) Object - parseRequest, parseResponse, addressSalt
|
|
14486
|
+
* @returns deployed Contract
|
|
14487
|
+
*/
|
|
13920
14488
|
async deploy(...args) {
|
|
13921
14489
|
const { args: param, options = { parseRequest: true } } = splitArgsAndOptions(args);
|
|
13922
14490
|
const constructorCalldata = getCalldata(param, () => {
|
|
@@ -13943,13 +14511,26 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
13943
14511
|
contractInstance.deployTransactionHash = transaction_hash;
|
|
13944
14512
|
return contractInstance;
|
|
13945
14513
|
}
|
|
14514
|
+
/**
|
|
14515
|
+
* Attaches to new Account
|
|
14516
|
+
*
|
|
14517
|
+
* @param account - new Provider or Account to attach to
|
|
14518
|
+
* @returns ContractFactory
|
|
14519
|
+
*/
|
|
13946
14520
|
connect(account) {
|
|
13947
14521
|
this.account = account;
|
|
13948
14522
|
return this;
|
|
13949
14523
|
}
|
|
14524
|
+
/**
|
|
14525
|
+
* Attaches current abi and account to the new address
|
|
14526
|
+
*
|
|
14527
|
+
* @param address - Contract address
|
|
14528
|
+
* @returns Contract
|
|
14529
|
+
*/
|
|
13950
14530
|
attach(address) {
|
|
13951
14531
|
return new Contract(this.abi, address, this.account);
|
|
13952
14532
|
}
|
|
14533
|
+
// ethers.js' getDeployTransaction cant be supported as it requires the account or signer to return a signed transaction which is not possible with the current implementation
|
|
13953
14534
|
};
|
|
13954
14535
|
|
|
13955
14536
|
// src/signer/interface.ts
|
|
@@ -14528,6 +15109,14 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
14528
15109
|
}
|
|
14529
15110
|
);
|
|
14530
15111
|
}
|
|
15112
|
+
/**
|
|
15113
|
+
* First check if contract is already declared, if not declare it
|
|
15114
|
+
* If contract already declared returned transaction_hash is ''.
|
|
15115
|
+
* Method will pass even if contract is already declared
|
|
15116
|
+
* @param payload DeclareContractPayload
|
|
15117
|
+
* @param transactionsDetail (optional) InvocationsDetails = \{\}
|
|
15118
|
+
* @returns DeclareContractResponse
|
|
15119
|
+
*/
|
|
14531
15120
|
async declareIfNot(payload, transactionsDetail = {}) {
|
|
14532
15121
|
const declareContractPayload = extractContractHashes(payload);
|
|
14533
15122
|
try {
|
|
@@ -14708,6 +15297,9 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
14708
15297
|
}
|
|
14709
15298
|
return feeEstimate.suggestedMaxFee;
|
|
14710
15299
|
}
|
|
15300
|
+
/**
|
|
15301
|
+
* will be renamed to buildDeclareContractTransaction
|
|
15302
|
+
*/
|
|
14711
15303
|
async buildDeclarePayload(payload, { nonce, chainId, version, walletAddress, maxFee }) {
|
|
14712
15304
|
const { classHash, contract, compiledClassHash } = extractContractHashes(payload);
|
|
14713
15305
|
const contractDefinition = parseContract(contract);
|
|
@@ -14847,7 +15439,45 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
14847
15439
|
var number2 = num_exports;
|
|
14848
15440
|
return __toCommonJS(src_exports);
|
|
14849
15441
|
})();
|
|
14850
|
-
/*!
|
|
14851
|
-
|
|
14852
|
-
|
|
15442
|
+
/*! Bundled license information:
|
|
15443
|
+
|
|
15444
|
+
@noble/curves/esm/abstract/utils.js:
|
|
15445
|
+
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
15446
|
+
|
|
15447
|
+
@noble/hashes/esm/utils.js:
|
|
15448
|
+
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
15449
|
+
|
|
15450
|
+
@noble/curves/esm/abstract/utils.js:
|
|
15451
|
+
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
15452
|
+
|
|
15453
|
+
@noble/curves/esm/abstract/modular.js:
|
|
15454
|
+
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
15455
|
+
|
|
15456
|
+
@noble/curves/esm/abstract/poseidon.js:
|
|
15457
|
+
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
15458
|
+
|
|
15459
|
+
@noble/curves/esm/abstract/curve.js:
|
|
15460
|
+
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
15461
|
+
|
|
15462
|
+
@noble/curves/esm/abstract/weierstrass.js:
|
|
15463
|
+
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
15464
|
+
|
|
15465
|
+
@noble/curves/esm/_shortw_utils.js:
|
|
15466
|
+
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
15467
|
+
|
|
15468
|
+
@noble/curves/esm/abstract/modular.js:
|
|
15469
|
+
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
15470
|
+
|
|
15471
|
+
@noble/curves/esm/abstract/curve.js:
|
|
15472
|
+
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
15473
|
+
|
|
15474
|
+
@noble/curves/esm/abstract/weierstrass.js:
|
|
15475
|
+
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
15476
|
+
|
|
15477
|
+
@noble/curves/esm/abstract/poseidon.js:
|
|
15478
|
+
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
15479
|
+
|
|
15480
|
+
pako/dist/pako.esm.mjs:
|
|
15481
|
+
(*! pako 2.1.0 https://github.com/nodeca/pako @license (MIT AND Zlib) *)
|
|
15482
|
+
*/
|
|
14853
15483
|
//# sourceMappingURL=index.global.js.map
|