starknet 5.10.2 → 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 +6 -0
- package/dist/index.d.ts +324 -370
- package/dist/index.global.js +684 -56
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +343 -30
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +339 -30
- 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) {
|
|
@@ -5887,8 +6127,8 @@ var starknet = (() => {
|
|
|
5887
6127
|
if (isTypeTuple(element.type)) {
|
|
5888
6128
|
const memberTypes = extractTupleMemberTypes(element.type);
|
|
5889
6129
|
return memberTypes.reduce((acc, it, idx) => {
|
|
5890
|
-
const name =
|
|
5891
|
-
const type =
|
|
6130
|
+
const name = it?.name ? it.name : idx;
|
|
6131
|
+
const type = it?.type ? it.type : it;
|
|
5892
6132
|
const el = { name, type };
|
|
5893
6133
|
acc[name] = parseResponseValue(responseIterator, el, structs);
|
|
5894
6134
|
return acc;
|
|
@@ -6096,6 +6336,12 @@ var starknet = (() => {
|
|
|
6096
6336
|
this.abi = abi;
|
|
6097
6337
|
this.structs = CallData.getAbiStruct(abi);
|
|
6098
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
|
+
*/
|
|
6099
6345
|
validate(type, method, args = []) {
|
|
6100
6346
|
if (type !== "DEPLOY") {
|
|
6101
6347
|
const invocableFunctionNames = this.abi.filter((abi) => {
|
|
@@ -6120,14 +6366,41 @@ var starknet = (() => {
|
|
|
6120
6366
|
}
|
|
6121
6367
|
validateFields(abiMethod, args, this.structs);
|
|
6122
6368
|
}
|
|
6123
|
-
|
|
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
|
+
}
|
|
6124
6393
|
const argsIterator = args[Symbol.iterator]();
|
|
6125
|
-
|
|
6126
|
-
return inputs.reduce(
|
|
6394
|
+
return abiMethod.inputs.reduce(
|
|
6127
6395
|
(acc, input) => isLen(input.name) ? acc : acc.concat(parseCalldataField(argsIterator, input, this.structs)),
|
|
6128
6396
|
[]
|
|
6129
6397
|
);
|
|
6130
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
|
+
*/
|
|
6131
6404
|
static compile(rawArgs) {
|
|
6132
6405
|
const createTree = (obj) => {
|
|
6133
6406
|
const getEntries = (o, prefix = "") => {
|
|
@@ -6162,6 +6435,12 @@ var starknet = (() => {
|
|
|
6162
6435
|
});
|
|
6163
6436
|
return callTreeArray;
|
|
6164
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
|
+
*/
|
|
6165
6444
|
parse(method, response) {
|
|
6166
6445
|
const { outputs } = this.abi.find((abi) => abi.name === method);
|
|
6167
6446
|
const responseIterator = response.flat()[Symbol.iterator]();
|
|
@@ -6175,13 +6454,30 @@ var starknet = (() => {
|
|
|
6175
6454
|
}, {});
|
|
6176
6455
|
return Object.keys(parsed).length === 1 && 0 in parsed ? parsed[0] : parsed;
|
|
6177
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
|
+
*/
|
|
6178
6464
|
format(method, response, format) {
|
|
6179
6465
|
const parsed = this.parse(method, response);
|
|
6180
6466
|
return formatter(parsed, format);
|
|
6181
6467
|
}
|
|
6468
|
+
/**
|
|
6469
|
+
* Helper to calculate inputs from abi
|
|
6470
|
+
* @param inputs AbiEntry
|
|
6471
|
+
* @returns number
|
|
6472
|
+
*/
|
|
6182
6473
|
static abiInputsLength(inputs) {
|
|
6183
6474
|
return inputs.reduce((acc, input) => !isLen(input.name) ? acc + 1 : acc, 0);
|
|
6184
6475
|
}
|
|
6476
|
+
/**
|
|
6477
|
+
* Helper to extract structs from abi
|
|
6478
|
+
* @param abi Abi
|
|
6479
|
+
* @returns AbiStructs - structs from abi
|
|
6480
|
+
*/
|
|
6185
6481
|
static getAbiStruct(abi) {
|
|
6186
6482
|
return abi.filter((abiEntry) => abiEntry.type === "struct").reduce(
|
|
6187
6483
|
(acc, abiEntry) => ({
|
|
@@ -6191,9 +6487,19 @@ var starknet = (() => {
|
|
|
6191
6487
|
{}
|
|
6192
6488
|
);
|
|
6193
6489
|
}
|
|
6490
|
+
/**
|
|
6491
|
+
* Helper: Compile HexCalldata | RawCalldata | RawArgs
|
|
6492
|
+
* @param rawCalldata HexCalldata | RawCalldata | RawArgs
|
|
6493
|
+
* @returns Calldata
|
|
6494
|
+
*/
|
|
6194
6495
|
static toCalldata(rawCalldata = []) {
|
|
6195
6496
|
return CallData.compile(rawCalldata);
|
|
6196
6497
|
}
|
|
6498
|
+
/**
|
|
6499
|
+
* Helper: Convert raw to HexCalldata
|
|
6500
|
+
* @param raw HexCalldata | RawCalldata | RawArgs
|
|
6501
|
+
* @returns HexCalldata
|
|
6502
|
+
*/
|
|
6197
6503
|
static toHex(raw = []) {
|
|
6198
6504
|
const calldata = CallData.compile(raw);
|
|
6199
6505
|
return calldata.map((it) => toHex(it));
|
|
@@ -6202,7 +6508,9 @@ var starknet = (() => {
|
|
|
6202
6508
|
|
|
6203
6509
|
// src/utils/fetchPonyfill.ts
|
|
6204
6510
|
var import_isomorphic_fetch = __toESM(require_fetch_npm_browserify());
|
|
6205
|
-
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;
|
|
6206
6514
|
|
|
6207
6515
|
// src/utils/hash.ts
|
|
6208
6516
|
var hash_exports = {};
|
|
@@ -6358,6 +6666,7 @@ var starknet = (() => {
|
|
|
6358
6666
|
};
|
|
6359
6667
|
return {
|
|
6360
6668
|
constTimeNegate,
|
|
6669
|
+
// non-const time multiplication ladder
|
|
6361
6670
|
unsafeLadder(elm, n) {
|
|
6362
6671
|
let p = c.ZERO;
|
|
6363
6672
|
let d = elm;
|
|
@@ -6369,6 +6678,16 @@ var starknet = (() => {
|
|
|
6369
6678
|
}
|
|
6370
6679
|
return p;
|
|
6371
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
|
+
*/
|
|
6372
6691
|
precomputeWindow(elm, W) {
|
|
6373
6692
|
const { windows, windowSize } = opts(W);
|
|
6374
6693
|
const points = [];
|
|
@@ -6385,6 +6704,13 @@ var starknet = (() => {
|
|
|
6385
6704
|
}
|
|
6386
6705
|
return points;
|
|
6387
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
|
+
*/
|
|
6388
6714
|
wNAF(W, precomputes, n) {
|
|
6389
6715
|
const { windows, windowSize } = opts(W);
|
|
6390
6716
|
let p = c.ZERO;
|
|
@@ -6467,6 +6793,7 @@ var starknet = (() => {
|
|
|
6467
6793
|
}
|
|
6468
6794
|
var { bytesToNumberBE: b2n2, hexToBytes: h2b2 } = utils_exports;
|
|
6469
6795
|
var DER2 = {
|
|
6796
|
+
// asn.1 DER encoding utils
|
|
6470
6797
|
Err: class DERErr2 extends Error {
|
|
6471
6798
|
constructor(m = "") {
|
|
6472
6799
|
super(m);
|
|
@@ -6570,6 +6897,8 @@ var starknet = (() => {
|
|
|
6570
6897
|
if (pz == null || !Fp.isValid(pz))
|
|
6571
6898
|
throw new Error("z required");
|
|
6572
6899
|
}
|
|
6900
|
+
// Does not validate if the point is on-curve.
|
|
6901
|
+
// Use fromHex instead, or call assertValidity() later.
|
|
6573
6902
|
static fromAffine(p) {
|
|
6574
6903
|
const { x, y } = p || {};
|
|
6575
6904
|
if (!p || !Fp.isValid(x) || !Fp.isValid(y))
|
|
@@ -6587,22 +6916,35 @@ var starknet = (() => {
|
|
|
6587
6916
|
get y() {
|
|
6588
6917
|
return this.toAffine().y;
|
|
6589
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
|
+
*/
|
|
6590
6925
|
static normalizeZ(points) {
|
|
6591
6926
|
const toInv = Fp.invertBatch(points.map((p) => p.pz));
|
|
6592
6927
|
return points.map((p, i) => p.toAffine(toInv[i])).map(Point.fromAffine);
|
|
6593
6928
|
}
|
|
6929
|
+
/**
|
|
6930
|
+
* Converts hash string or Uint8Array to Point.
|
|
6931
|
+
* @param hex short/long ECDSA hex
|
|
6932
|
+
*/
|
|
6594
6933
|
static fromHex(hex) {
|
|
6595
6934
|
const P = Point.fromAffine(CURVE2.fromBytes(ensureBytes("pointHex", hex)));
|
|
6596
6935
|
P.assertValidity();
|
|
6597
6936
|
return P;
|
|
6598
6937
|
}
|
|
6938
|
+
// Multiplies generator point by privateKey.
|
|
6599
6939
|
static fromPrivateKey(privateKey) {
|
|
6600
6940
|
return Point.BASE.multiply(normPrivateKeyToScalar(privateKey));
|
|
6601
6941
|
}
|
|
6942
|
+
// "Private method", don't use it directly
|
|
6602
6943
|
_setWindowSize(windowSize) {
|
|
6603
6944
|
this._WINDOW_SIZE = windowSize;
|
|
6604
6945
|
pointPrecomputes.delete(this);
|
|
6605
6946
|
}
|
|
6947
|
+
// A point on curve is valid if it conforms to equation.
|
|
6606
6948
|
assertValidity() {
|
|
6607
6949
|
if (this.is0()) {
|
|
6608
6950
|
if (CURVE2.allowInfinityPoint)
|
|
@@ -6625,6 +6967,9 @@ var starknet = (() => {
|
|
|
6625
6967
|
return !Fp.isOdd(y);
|
|
6626
6968
|
throw new Error("Field doesn't support isOdd");
|
|
6627
6969
|
}
|
|
6970
|
+
/**
|
|
6971
|
+
* Compare one point to another.
|
|
6972
|
+
*/
|
|
6628
6973
|
equals(other) {
|
|
6629
6974
|
assertPrjPoint(other);
|
|
6630
6975
|
const { px: X1, py: Y1, pz: Z1 } = this;
|
|
@@ -6633,9 +6978,16 @@ var starknet = (() => {
|
|
|
6633
6978
|
const U2 = Fp.eql(Fp.mul(Y1, Z2), Fp.mul(Y2, Z1));
|
|
6634
6979
|
return U1 && U2;
|
|
6635
6980
|
}
|
|
6981
|
+
/**
|
|
6982
|
+
* Flips point to one corresponding to (x, -y) in Affine coordinates.
|
|
6983
|
+
*/
|
|
6636
6984
|
negate() {
|
|
6637
6985
|
return new Point(this.px, Fp.neg(this.py), this.pz);
|
|
6638
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.
|
|
6639
6991
|
double() {
|
|
6640
6992
|
const { a, b } = CURVE2;
|
|
6641
6993
|
const b3 = Fp.mul(b, 3n);
|
|
@@ -6674,6 +7026,10 @@ var starknet = (() => {
|
|
|
6674
7026
|
Z3 = Fp.add(Z3, Z3);
|
|
6675
7027
|
return new Point(X3, Y3, Z3);
|
|
6676
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.
|
|
6677
7033
|
add(other) {
|
|
6678
7034
|
assertPrjPoint(other);
|
|
6679
7035
|
const { px: X1, py: Y1, pz: Z1 } = this;
|
|
@@ -6735,6 +7091,11 @@ var starknet = (() => {
|
|
|
6735
7091
|
return comp.map((p, i) => p.toAffine(toInv[i])).map(Point.fromAffine);
|
|
6736
7092
|
});
|
|
6737
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
|
+
*/
|
|
6738
7099
|
multiplyUnsafe(n) {
|
|
6739
7100
|
const I = Point.ZERO;
|
|
6740
7101
|
if (n === _0n9)
|
|
@@ -6765,6 +7126,15 @@ var starknet = (() => {
|
|
|
6765
7126
|
k2p = new Point(Fp.mul(k2p.px, endo.beta), k2p.py, k2p.pz);
|
|
6766
7127
|
return k1p.add(k2p);
|
|
6767
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
|
+
*/
|
|
6768
7138
|
multiply(scalar) {
|
|
6769
7139
|
assertGE(scalar);
|
|
6770
7140
|
let n = scalar;
|
|
@@ -6786,12 +7156,21 @@ var starknet = (() => {
|
|
|
6786
7156
|
}
|
|
6787
7157
|
return Point.normalizeZ([point, fake])[0];
|
|
6788
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
|
+
*/
|
|
6789
7165
|
multiplyAndAddUnsafe(Q, a, b) {
|
|
6790
7166
|
const G = Point.BASE;
|
|
6791
7167
|
const mul = (P, a2) => a2 === _0n9 || a2 === _1n9 || !P.equals(G) ? P.multiplyUnsafe(a2) : P.multiply(a2);
|
|
6792
7168
|
const sum = mul(this, a).add(mul(Q, b));
|
|
6793
7169
|
return sum.is0() ? void 0 : sum;
|
|
6794
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)
|
|
6795
7174
|
toAffine(iz) {
|
|
6796
7175
|
const { px: x, py: y, pz: z } = this;
|
|
6797
7176
|
const is0 = this.is0();
|
|
@@ -6921,11 +7300,14 @@ var starknet = (() => {
|
|
|
6921
7300
|
this.recovery = recovery;
|
|
6922
7301
|
this.assertValidity();
|
|
6923
7302
|
}
|
|
7303
|
+
// pair (bytes of r, bytes of s)
|
|
6924
7304
|
static fromCompact(hex) {
|
|
6925
7305
|
const l = CURVE2.nByteLength;
|
|
6926
7306
|
hex = ensureBytes("compactSignature", hex, l * 2);
|
|
6927
7307
|
return new Signature3(slcNum(hex, 0, l), slcNum(hex, l, 2 * l));
|
|
6928
7308
|
}
|
|
7309
|
+
// DER encoded ECDSA signature
|
|
7310
|
+
// https://bitcoin.stackexchange.com/questions/57644/what-are-the-parts-of-a-bitcoin-transaction-input-script
|
|
6929
7311
|
static fromDER(hex) {
|
|
6930
7312
|
const { r, s } = DER2.toSig(ensureBytes("DER", hex));
|
|
6931
7313
|
return new Signature3(r, s);
|
|
@@ -6958,18 +7340,21 @@ var starknet = (() => {
|
|
|
6958
7340
|
Q.assertValidity();
|
|
6959
7341
|
return Q;
|
|
6960
7342
|
}
|
|
7343
|
+
// Signatures should be low-s, to prevent malleability.
|
|
6961
7344
|
hasHighS() {
|
|
6962
7345
|
return isBiggerThanHalfOrder(this.s);
|
|
6963
7346
|
}
|
|
6964
7347
|
normalizeS() {
|
|
6965
7348
|
return this.hasHighS() ? new Signature3(this.r, modN(-this.s), this.recovery) : this;
|
|
6966
7349
|
}
|
|
7350
|
+
// DER-encoded
|
|
6967
7351
|
toDERRawBytes() {
|
|
6968
7352
|
return hexToBytes(this.toDERHex());
|
|
6969
7353
|
}
|
|
6970
7354
|
toDERHex() {
|
|
6971
7355
|
return DER2.hexFromSig({ r: this.r, s: this.s });
|
|
6972
7356
|
}
|
|
7357
|
+
// padded bytes of r, then padded bytes of s
|
|
6973
7358
|
toCompactRawBytes() {
|
|
6974
7359
|
return hexToBytes(this.toCompactHex());
|
|
6975
7360
|
}
|
|
@@ -6987,11 +7372,23 @@ var starknet = (() => {
|
|
|
6987
7372
|
}
|
|
6988
7373
|
},
|
|
6989
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
|
+
*/
|
|
6990
7379
|
randomPrivateKey: () => {
|
|
6991
7380
|
const rand = CURVE2.randomBytes(Fp.BYTES + 8);
|
|
6992
7381
|
const num = hashToPrivateScalar2(rand, CURVE_ORDER2);
|
|
6993
7382
|
return numberToBytesBE(num, CURVE2.nByteLength);
|
|
6994
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
|
+
*/
|
|
6995
7392
|
precompute(windowSize = 8, point = Point.BASE) {
|
|
6996
7393
|
point._setWindowSize(windowSize);
|
|
6997
7394
|
point.multiply(BigInt(3));
|
|
@@ -7087,7 +7484,6 @@ var starknet = (() => {
|
|
|
7087
7484
|
}
|
|
7088
7485
|
Point.BASE._setWindowSize(8);
|
|
7089
7486
|
function verify2(signature, msgHash, publicKey, opts = defaultVerOpts) {
|
|
7090
|
-
var _a;
|
|
7091
7487
|
const sg = signature;
|
|
7092
7488
|
msgHash = ensureBytes("msgHash", msgHash);
|
|
7093
7489
|
publicKey = ensureBytes("publicKey", publicKey);
|
|
@@ -7126,7 +7522,7 @@ var starknet = (() => {
|
|
|
7126
7522
|
const is = invN(s);
|
|
7127
7523
|
const u1 = modN(h * is);
|
|
7128
7524
|
const u2 = modN(r * is);
|
|
7129
|
-
const R =
|
|
7525
|
+
const R = Point.BASE.multiplyAndAddUnsafe(P, u1, u2)?.toAffine();
|
|
7130
7526
|
if (!R)
|
|
7131
7527
|
return false;
|
|
7132
7528
|
const v = modN(R.x);
|
|
@@ -7385,11 +7781,17 @@ var starknet = (() => {
|
|
|
7385
7781
|
}
|
|
7386
7782
|
throw new Error("Cannot safely convert to number: " + "the value '".concat(this.value, "' would ").concat(unsafeReason, " and become ").concat(parseFloat(this.value)));
|
|
7387
7783
|
}
|
|
7784
|
+
/**
|
|
7785
|
+
* Get the value of the LosslessNumber as string.
|
|
7786
|
+
*/
|
|
7388
7787
|
}, {
|
|
7389
7788
|
key: "toString",
|
|
7390
7789
|
value: function toString2() {
|
|
7391
7790
|
return this.value;
|
|
7392
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.
|
|
7393
7795
|
}]);
|
|
7394
7796
|
return LosslessNumber2;
|
|
7395
7797
|
}();
|
|
@@ -7760,6 +8162,7 @@ var starknet = (() => {
|
|
|
7760
8162
|
n: "\n",
|
|
7761
8163
|
r: "\r",
|
|
7762
8164
|
t: " "
|
|
8165
|
+
// note that \u is handled separately in parseString()
|
|
7763
8166
|
};
|
|
7764
8167
|
var codeBackslash = 92;
|
|
7765
8168
|
var codeOpeningBrace = 123;
|
|
@@ -8281,9 +8684,18 @@ var starknet = (() => {
|
|
|
8281
8684
|
var REP_3_6 = 16;
|
|
8282
8685
|
var REPZ_3_10 = 17;
|
|
8283
8686
|
var REPZ_11_138 = 18;
|
|
8284
|
-
var extra_lbits =
|
|
8285
|
-
|
|
8286
|
-
|
|
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
|
+
);
|
|
8287
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]);
|
|
8288
8700
|
var DIST_CODE_LEN = 512;
|
|
8289
8701
|
var static_ltree = new Array((L_CODES$1 + 2) * 2);
|
|
@@ -8333,7 +8745,12 @@ var starknet = (() => {
|
|
|
8333
8745
|
}
|
|
8334
8746
|
};
|
|
8335
8747
|
var send_code = (s, c, tree) => {
|
|
8336
|
-
send_bits(
|
|
8748
|
+
send_bits(
|
|
8749
|
+
s,
|
|
8750
|
+
tree[c * 2],
|
|
8751
|
+
tree[c * 2 + 1]
|
|
8752
|
+
/*.Len*/
|
|
8753
|
+
);
|
|
8337
8754
|
};
|
|
8338
8755
|
var bi_reverse = (code, len) => {
|
|
8339
8756
|
let res = 0;
|
|
@@ -8614,19 +9031,44 @@ var starknet = (() => {
|
|
|
8614
9031
|
}
|
|
8615
9032
|
node = elems;
|
|
8616
9033
|
do {
|
|
8617
|
-
n = s.heap[
|
|
8618
|
-
|
|
8619
|
-
|
|
8620
|
-
|
|
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
|
+
];
|
|
8621
9052
|
s.heap[--s.heap_max] = n;
|
|
8622
9053
|
s.heap[--s.heap_max] = m;
|
|
8623
9054
|
tree[node * 2] = tree[n * 2] + tree[m * 2];
|
|
8624
9055
|
s.depth[node] = (s.depth[n] >= s.depth[m] ? s.depth[n] : s.depth[m]) + 1;
|
|
8625
9056
|
tree[n * 2 + 1] = tree[m * 2 + 1] = node;
|
|
8626
|
-
s.heap[
|
|
8627
|
-
|
|
9057
|
+
s.heap[
|
|
9058
|
+
1
|
|
9059
|
+
/*SMALLEST*/
|
|
9060
|
+
] = node++;
|
|
9061
|
+
pqdownheap(
|
|
9062
|
+
s,
|
|
9063
|
+
tree,
|
|
9064
|
+
1
|
|
9065
|
+
/*SMALLEST*/
|
|
9066
|
+
);
|
|
8628
9067
|
} while (s.heap_len >= 2);
|
|
8629
|
-
s.heap[--s.heap_max] = s.heap[
|
|
9068
|
+
s.heap[--s.heap_max] = s.heap[
|
|
9069
|
+
1
|
|
9070
|
+
/*SMALLEST*/
|
|
9071
|
+
];
|
|
8630
9072
|
gen_bitlen(s, desc);
|
|
8631
9073
|
gen_codes(tree, max_code, s.bl_count);
|
|
8632
9074
|
};
|
|
@@ -8891,16 +9333,26 @@ var starknet = (() => {
|
|
|
8891
9333
|
var crc32_1 = crc32;
|
|
8892
9334
|
var messages = {
|
|
8893
9335
|
2: "need dictionary",
|
|
9336
|
+
/* Z_NEED_DICT 2 */
|
|
8894
9337
|
1: "stream end",
|
|
9338
|
+
/* Z_STREAM_END 1 */
|
|
8895
9339
|
0: "",
|
|
9340
|
+
/* Z_OK 0 */
|
|
8896
9341
|
"-1": "file error",
|
|
9342
|
+
/* Z_ERRNO (-1) */
|
|
8897
9343
|
"-2": "stream error",
|
|
9344
|
+
/* Z_STREAM_ERROR (-2) */
|
|
8898
9345
|
"-3": "data error",
|
|
9346
|
+
/* Z_DATA_ERROR (-3) */
|
|
8899
9347
|
"-4": "insufficient memory",
|
|
9348
|
+
/* Z_MEM_ERROR (-4) */
|
|
8900
9349
|
"-5": "buffer error",
|
|
9350
|
+
/* Z_BUF_ERROR (-5) */
|
|
8901
9351
|
"-6": "incompatible version"
|
|
9352
|
+
/* Z_VERSION_ERROR (-6) */
|
|
8902
9353
|
};
|
|
8903
9354
|
var constants$2 = {
|
|
9355
|
+
/* Allowed flush values; see deflate() and inflate() below for details */
|
|
8904
9356
|
Z_NO_FLUSH: 0,
|
|
8905
9357
|
Z_PARTIAL_FLUSH: 1,
|
|
8906
9358
|
Z_SYNC_FLUSH: 2,
|
|
@@ -8908,6 +9360,9 @@ var starknet = (() => {
|
|
|
8908
9360
|
Z_FINISH: 4,
|
|
8909
9361
|
Z_BLOCK: 5,
|
|
8910
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
|
+
*/
|
|
8911
9366
|
Z_OK: 0,
|
|
8912
9367
|
Z_STREAM_END: 1,
|
|
8913
9368
|
Z_NEED_DICT: 2,
|
|
@@ -8916,6 +9371,8 @@ var starknet = (() => {
|
|
|
8916
9371
|
Z_DATA_ERROR: -3,
|
|
8917
9372
|
Z_MEM_ERROR: -4,
|
|
8918
9373
|
Z_BUF_ERROR: -5,
|
|
9374
|
+
//Z_VERSION_ERROR: -6,
|
|
9375
|
+
/* compression levels */
|
|
8919
9376
|
Z_NO_COMPRESSION: 0,
|
|
8920
9377
|
Z_BEST_SPEED: 1,
|
|
8921
9378
|
Z_BEST_COMPRESSION: 9,
|
|
@@ -8925,10 +9382,14 @@ var starknet = (() => {
|
|
|
8925
9382
|
Z_RLE: 3,
|
|
8926
9383
|
Z_FIXED: 4,
|
|
8927
9384
|
Z_DEFAULT_STRATEGY: 0,
|
|
9385
|
+
/* Possible values of the data_type field (though see inflate()) */
|
|
8928
9386
|
Z_BINARY: 0,
|
|
8929
9387
|
Z_TEXT: 1,
|
|
9388
|
+
//Z_ASCII: 1, // = Z_TEXT (deprecated)
|
|
8930
9389
|
Z_UNKNOWN: 2,
|
|
9390
|
+
/* The deflate compression method */
|
|
8931
9391
|
Z_DEFLATED: 8
|
|
9392
|
+
//Z_NULL: null // Use -1 or null inline, depending on var type
|
|
8932
9393
|
};
|
|
8933
9394
|
var { _tr_init, _tr_stored_block, _tr_flush_block, _tr_tally, _tr_align } = trees;
|
|
8934
9395
|
var {
|
|
@@ -9523,16 +9984,27 @@ var starknet = (() => {
|
|
|
9523
9984
|
this.func = func;
|
|
9524
9985
|
}
|
|
9525
9986
|
var configuration_table = [
|
|
9987
|
+
/* good lazy nice chain */
|
|
9526
9988
|
new Config(0, 0, 0, 0, deflate_stored),
|
|
9989
|
+
/* 0 store only */
|
|
9527
9990
|
new Config(4, 4, 8, 4, deflate_fast),
|
|
9991
|
+
/* 1 max speed, no lazy matches */
|
|
9528
9992
|
new Config(4, 5, 16, 8, deflate_fast),
|
|
9993
|
+
/* 2 */
|
|
9529
9994
|
new Config(4, 6, 32, 32, deflate_fast),
|
|
9995
|
+
/* 3 */
|
|
9530
9996
|
new Config(4, 4, 16, 16, deflate_slow),
|
|
9997
|
+
/* 4 lazy matches */
|
|
9531
9998
|
new Config(8, 16, 32, 32, deflate_slow),
|
|
9999
|
+
/* 5 */
|
|
9532
10000
|
new Config(8, 16, 128, 128, deflate_slow),
|
|
10001
|
+
/* 6 */
|
|
9533
10002
|
new Config(8, 32, 128, 256, deflate_slow),
|
|
10003
|
+
/* 7 */
|
|
9534
10004
|
new Config(32, 128, 258, 1024, deflate_slow),
|
|
10005
|
+
/* 8 */
|
|
9535
10006
|
new Config(32, 258, 258, 4096, deflate_slow)
|
|
10007
|
+
/* 9 max compression */
|
|
9536
10008
|
];
|
|
9537
10009
|
var lm_init = (s) => {
|
|
9538
10010
|
s.window_size = 2 * s.w_size;
|
|
@@ -9619,7 +10091,9 @@ var starknet = (() => {
|
|
|
9619
10091
|
return 1;
|
|
9620
10092
|
}
|
|
9621
10093
|
const s = strm.state;
|
|
9622
|
-
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) {
|
|
9623
10097
|
return 1;
|
|
9624
10098
|
}
|
|
9625
10099
|
return 0;
|
|
@@ -9636,7 +10110,11 @@ var starknet = (() => {
|
|
|
9636
10110
|
if (s.wrap < 0) {
|
|
9637
10111
|
s.wrap = -s.wrap;
|
|
9638
10112
|
}
|
|
9639
|
-
s.status =
|
|
10113
|
+
s.status = //#ifdef GZIP
|
|
10114
|
+
s.wrap === 2 ? GZIP_STATE : (
|
|
10115
|
+
//#endif
|
|
10116
|
+
s.wrap ? INIT_STATE : BUSY_STATE
|
|
10117
|
+
);
|
|
9640
10118
|
strm.adler = s.wrap === 2 ? 0 : 1;
|
|
9641
10119
|
s.last_flush = -2;
|
|
9642
10120
|
_tr_init(s);
|
|
@@ -10621,6 +11099,7 @@ var starknet = (() => {
|
|
|
10621
11099
|
var LENS$1 = 1;
|
|
10622
11100
|
var DISTS$1 = 2;
|
|
10623
11101
|
var lbase = new Uint16Array([
|
|
11102
|
+
/* Length codes 257..285 base */
|
|
10624
11103
|
3,
|
|
10625
11104
|
4,
|
|
10626
11105
|
5,
|
|
@@ -10654,6 +11133,7 @@ var starknet = (() => {
|
|
|
10654
11133
|
0
|
|
10655
11134
|
]);
|
|
10656
11135
|
var lext = new Uint8Array([
|
|
11136
|
+
/* Length codes 257..285 extra */
|
|
10657
11137
|
16,
|
|
10658
11138
|
16,
|
|
10659
11139
|
16,
|
|
@@ -10687,6 +11167,7 @@ var starknet = (() => {
|
|
|
10687
11167
|
78
|
|
10688
11168
|
]);
|
|
10689
11169
|
var dbase = new Uint16Array([
|
|
11170
|
+
/* Distance codes 0..29 base */
|
|
10690
11171
|
1,
|
|
10691
11172
|
2,
|
|
10692
11173
|
3,
|
|
@@ -10721,6 +11202,7 @@ var starknet = (() => {
|
|
|
10721
11202
|
0
|
|
10722
11203
|
]);
|
|
10723
11204
|
var dext = new Uint8Array([
|
|
11205
|
+
/* Distance codes 0..29 extra */
|
|
10724
11206
|
16,
|
|
10725
11207
|
16,
|
|
10726
11208
|
16,
|
|
@@ -11184,7 +11666,10 @@ var starknet = (() => {
|
|
|
11184
11666
|
const hbuf = new Uint8Array(4);
|
|
11185
11667
|
let opts;
|
|
11186
11668
|
let n;
|
|
11187
|
-
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
|
+
);
|
|
11188
11673
|
if (inflateStateCheck(strm) || !strm.output || !strm.input && strm.avail_in !== 0) {
|
|
11189
11674
|
return Z_STREAM_ERROR$1;
|
|
11190
11675
|
}
|
|
@@ -11235,7 +11720,8 @@ var starknet = (() => {
|
|
|
11235
11720
|
if (state.head) {
|
|
11236
11721
|
state.head.done = false;
|
|
11237
11722
|
}
|
|
11238
|
-
if (!(state.wrap & 1) ||
|
|
11723
|
+
if (!(state.wrap & 1) || /* check if zlib header allowed */
|
|
11724
|
+
(((hold & 255) << 8) + (hold >> 8)) % 31) {
|
|
11239
11725
|
strm.msg = "incorrect header check";
|
|
11240
11726
|
state.mode = BAD;
|
|
11241
11727
|
break;
|
|
@@ -11377,8 +11863,11 @@ var starknet = (() => {
|
|
|
11377
11863
|
state.head.extra.set(
|
|
11378
11864
|
input.subarray(
|
|
11379
11865
|
next,
|
|
11866
|
+
// extra field is limited to 65536 bytes
|
|
11867
|
+
// - no need for additional size check
|
|
11380
11868
|
next + copy
|
|
11381
11869
|
),
|
|
11870
|
+
/*len + copy > state.head.extra_max - len ? state.head.extra_max : copy,*/
|
|
11382
11871
|
len
|
|
11383
11872
|
);
|
|
11384
11873
|
}
|
|
@@ -11993,7 +12482,8 @@ var starknet = (() => {
|
|
|
11993
12482
|
strm.total_out += _out;
|
|
11994
12483
|
state.total += _out;
|
|
11995
12484
|
if (state.wrap & 4 && _out) {
|
|
11996
|
-
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);
|
|
11997
12487
|
}
|
|
11998
12488
|
_out = left;
|
|
11999
12489
|
if (state.wrap & 4 && (state.flags ? hold : zswap32(hold)) !== state.check) {
|
|
@@ -12053,7 +12543,8 @@ var starknet = (() => {
|
|
|
12053
12543
|
strm.total_out += _out;
|
|
12054
12544
|
state.total += _out;
|
|
12055
12545
|
if (state.wrap & 4 && _out) {
|
|
12056
|
-
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);
|
|
12057
12548
|
}
|
|
12058
12549
|
strm.data_type = state.bits + (state.last ? 64 : 0) + (state.mode === TYPE ? 128 : 0) + (state.mode === LEN_ || state.mode === COPY_ ? 256 : 0);
|
|
12059
12550
|
if ((_in === 0 && _out === 0 || flush === Z_FINISH$1) && ret === Z_OK$1) {
|
|
@@ -12382,6 +12873,7 @@ var starknet = (() => {
|
|
|
12382
12873
|
if (!isSierra(contract)) {
|
|
12383
12874
|
return {
|
|
12384
12875
|
...parsedContract,
|
|
12876
|
+
// TODO: Why do we gzip program object?
|
|
12385
12877
|
..."program" in parsedContract && { program: compressProgram(parsedContract.program) }
|
|
12386
12878
|
};
|
|
12387
12879
|
}
|
|
@@ -12634,6 +13126,7 @@ var starknet = (() => {
|
|
|
12634
13126
|
this.tag = "pending";
|
|
12635
13127
|
}
|
|
12636
13128
|
}
|
|
13129
|
+
// TODO: fix any
|
|
12637
13130
|
get queryIdentifier() {
|
|
12638
13131
|
if (this.number !== null) {
|
|
12639
13132
|
return `blockNumber=${this.number}`;
|
|
@@ -12643,6 +13136,7 @@ var starknet = (() => {
|
|
|
12643
13136
|
}
|
|
12644
13137
|
return `blockNumber=${this.tag}`;
|
|
12645
13138
|
}
|
|
13139
|
+
// TODO: fix any
|
|
12646
13140
|
get identifier() {
|
|
12647
13141
|
if (this.number !== null) {
|
|
12648
13142
|
return { block_number: this.number };
|
|
@@ -12690,17 +13184,17 @@ var starknet = (() => {
|
|
|
12690
13184
|
}
|
|
12691
13185
|
}
|
|
12692
13186
|
async fetchEndpoint(method, params) {
|
|
12693
|
-
var _a;
|
|
12694
13187
|
try {
|
|
12695
13188
|
const rawResult = await this.fetch(method, params);
|
|
12696
13189
|
const { error, result } = await rawResult.json();
|
|
12697
13190
|
this.errorHandler(error);
|
|
12698
13191
|
return result;
|
|
12699
13192
|
} catch (error) {
|
|
12700
|
-
this.errorHandler(
|
|
13193
|
+
this.errorHandler(error?.response?.data);
|
|
12701
13194
|
throw error;
|
|
12702
13195
|
}
|
|
12703
13196
|
}
|
|
13197
|
+
// Methods from Interface
|
|
12704
13198
|
async getChainId() {
|
|
12705
13199
|
this.chainId ?? (this.chainId = await this.fetchEndpoint("starknet_chainId"));
|
|
12706
13200
|
return this.chainId;
|
|
@@ -12754,6 +13248,7 @@ var starknet = (() => {
|
|
|
12754
13248
|
block_id
|
|
12755
13249
|
});
|
|
12756
13250
|
}
|
|
13251
|
+
// Methods from Interface
|
|
12757
13252
|
async getTransaction(txHash) {
|
|
12758
13253
|
return this.getTransactionByHash(txHash).then(this.responseParser.parseGetTransactionResponse);
|
|
12759
13254
|
}
|
|
@@ -12795,9 +13290,9 @@ var starknet = (() => {
|
|
|
12795
13290
|
sender_address: invocation.contractAddress,
|
|
12796
13291
|
calldata: CallData.toHex(invocation.calldata),
|
|
12797
13292
|
signature: signatureToHexArray(invocation.signature),
|
|
12798
|
-
version: toHex(
|
|
13293
|
+
version: toHex(invocationDetails?.version || 0),
|
|
12799
13294
|
nonce: toHex(invocationDetails.nonce),
|
|
12800
|
-
max_fee: toHex(
|
|
13295
|
+
max_fee: toHex(invocationDetails?.maxFee || 0)
|
|
12801
13296
|
},
|
|
12802
13297
|
block_id
|
|
12803
13298
|
}).then(this.responseParser.parseFeeEstimateResponse);
|
|
@@ -12812,12 +13307,13 @@ var starknet = (() => {
|
|
|
12812
13307
|
program: contractDefinition.program,
|
|
12813
13308
|
entry_points_by_type: contractDefinition.entry_points_by_type,
|
|
12814
13309
|
abi: contractDefinition.abi
|
|
13310
|
+
// rpc 2.0
|
|
12815
13311
|
},
|
|
12816
13312
|
sender_address: senderAddress,
|
|
12817
13313
|
signature: signatureToHexArray(signature),
|
|
12818
|
-
version: toHex(
|
|
13314
|
+
version: toHex(details?.version || 0),
|
|
12819
13315
|
nonce: toHex(details.nonce),
|
|
12820
|
-
max_fee: toHex(
|
|
13316
|
+
max_fee: toHex(details?.maxFee || 0)
|
|
12821
13317
|
},
|
|
12822
13318
|
block_id
|
|
12823
13319
|
}).then(this.responseParser.parseFeeEstimateResponse);
|
|
@@ -12833,9 +13329,9 @@ var starknet = (() => {
|
|
|
12833
13329
|
class_hash: toHex(classHash),
|
|
12834
13330
|
contract_address_salt: toHex(addressSalt || 0),
|
|
12835
13331
|
signature: signatureToHexArray(signature),
|
|
12836
|
-
version: toHex(
|
|
13332
|
+
version: toHex(details?.version || 0),
|
|
12837
13333
|
nonce: toHex(details.nonce),
|
|
12838
|
-
max_fee: toHex(
|
|
13334
|
+
max_fee: toHex(details?.maxFee || 0)
|
|
12839
13335
|
},
|
|
12840
13336
|
block_id
|
|
12841
13337
|
}).then(this.responseParser.parseFeeEstimateResponse);
|
|
@@ -12843,6 +13339,7 @@ var starknet = (() => {
|
|
|
12843
13339
|
async getEstimateFeeBulk(_invocations, _blockIdentifier = this.blockIdentifier) {
|
|
12844
13340
|
throw new Error("RPC does not implement getInvokeEstimateFeeBulk function");
|
|
12845
13341
|
}
|
|
13342
|
+
// TODO: Revisit after Pathfinder release with JSON-RPC v0.2.1 RPC Spec
|
|
12846
13343
|
async declareContract({ contractDefinition, signature, senderAddress }, details) {
|
|
12847
13344
|
if ("program" in contractDefinition) {
|
|
12848
13345
|
return this.fetchEndpoint("starknet_addDeclareTransaction", {
|
|
@@ -12851,6 +13348,7 @@ var starknet = (() => {
|
|
|
12851
13348
|
program: contractDefinition.program,
|
|
12852
13349
|
entry_points_by_type: contractDefinition.entry_points_by_type,
|
|
12853
13350
|
abi: contractDefinition.abi
|
|
13351
|
+
// rpc 2.0
|
|
12854
13352
|
},
|
|
12855
13353
|
type: RPC.TransactionType.DECLARE,
|
|
12856
13354
|
version: "0x1",
|
|
@@ -12890,6 +13388,7 @@ var starknet = (() => {
|
|
|
12890
13388
|
}
|
|
12891
13389
|
});
|
|
12892
13390
|
}
|
|
13391
|
+
// Methods from Interface
|
|
12893
13392
|
async callContract(call, blockIdentifier = this.blockIdentifier) {
|
|
12894
13393
|
const block_id = new Block(blockIdentifier).identifier;
|
|
12895
13394
|
const result = await this.fetchEndpoint("starknet_call", {
|
|
@@ -12913,8 +13412,8 @@ var starknet = (() => {
|
|
|
12913
13412
|
let { retries } = this;
|
|
12914
13413
|
let onchain = false;
|
|
12915
13414
|
let txReceipt = {};
|
|
12916
|
-
const retryInterval =
|
|
12917
|
-
const successStates =
|
|
13415
|
+
const retryInterval = options?.retryInterval ?? 8e3;
|
|
13416
|
+
const successStates = options?.successStates ?? [
|
|
12918
13417
|
"ACCEPTED_ON_L1" /* ACCEPTED_ON_L1 */,
|
|
12919
13418
|
"ACCEPTED_ON_L2" /* ACCEPTED_ON_L2 */,
|
|
12920
13419
|
"PENDING" /* PENDING */
|
|
@@ -12948,16 +13447,41 @@ var starknet = (() => {
|
|
|
12948
13447
|
await wait(retryInterval);
|
|
12949
13448
|
return txReceipt;
|
|
12950
13449
|
}
|
|
13450
|
+
/**
|
|
13451
|
+
* Gets the transaction count from a block.
|
|
13452
|
+
*
|
|
13453
|
+
*
|
|
13454
|
+
* @param blockIdentifier
|
|
13455
|
+
* @returns Number of transactions
|
|
13456
|
+
*/
|
|
12951
13457
|
async getTransactionCount(blockIdentifier = this.blockIdentifier) {
|
|
12952
13458
|
const block_id = new Block(blockIdentifier).identifier;
|
|
12953
13459
|
return this.fetchEndpoint("starknet_getBlockTransactionCount", { block_id });
|
|
12954
13460
|
}
|
|
13461
|
+
/**
|
|
13462
|
+
* Gets the latest block number
|
|
13463
|
+
*
|
|
13464
|
+
*
|
|
13465
|
+
* @returns Number of the latest block
|
|
13466
|
+
*/
|
|
12955
13467
|
async getBlockNumber() {
|
|
12956
13468
|
return this.fetchEndpoint("starknet_blockNumber");
|
|
12957
13469
|
}
|
|
13470
|
+
/**
|
|
13471
|
+
* Gets syncing status of the node
|
|
13472
|
+
*
|
|
13473
|
+
*
|
|
13474
|
+
* @returns Object with the stats data
|
|
13475
|
+
*/
|
|
12958
13476
|
async getSyncingStats() {
|
|
12959
13477
|
return this.fetchEndpoint("starknet_syncing");
|
|
12960
13478
|
}
|
|
13479
|
+
/**
|
|
13480
|
+
* Gets all the events filtered
|
|
13481
|
+
*
|
|
13482
|
+
*
|
|
13483
|
+
* @returns events and the pagination of the events
|
|
13484
|
+
*/
|
|
12961
13485
|
async getEvents(eventFilter) {
|
|
12962
13486
|
return this.fetchEndpoint("starknet_getEvents", { filter: eventFilter });
|
|
12963
13487
|
}
|
|
@@ -13008,6 +13532,7 @@ var starknet = (() => {
|
|
|
13008
13532
|
transaction_hash: res.transaction_hash,
|
|
13009
13533
|
status: res.status,
|
|
13010
13534
|
messages_sent: res.l2_to_l1_messages,
|
|
13535
|
+
// TODO: parse
|
|
13011
13536
|
events: res.events,
|
|
13012
13537
|
..."block_hash" in res && { block_hash: res.block_hash },
|
|
13013
13538
|
..."block_number" in res && { block_number: res.block_number },
|
|
@@ -13015,6 +13540,7 @@ var starknet = (() => {
|
|
|
13015
13540
|
..."transaction_index" in res && { transaction_index: res.transaction_index },
|
|
13016
13541
|
..."execution_resources" in res && { execution_resources: res.execution_resources },
|
|
13017
13542
|
..."l1_to_l2_consumed_message" in res && {
|
|
13543
|
+
// eslint-disable-next-line @typescript-eslint/dot-notation
|
|
13018
13544
|
l1_to_l2_consumed_message: res["l1_to_l2_consumed_message"]
|
|
13019
13545
|
},
|
|
13020
13546
|
..."transaction_failure_reason" in res && {
|
|
@@ -13126,6 +13652,7 @@ var starknet = (() => {
|
|
|
13126
13652
|
}
|
|
13127
13653
|
};
|
|
13128
13654
|
}
|
|
13655
|
+
// TODO: Define response as new type as it diff from ContractClass
|
|
13129
13656
|
parseSierraContractClassResponse(res) {
|
|
13130
13657
|
return {
|
|
13131
13658
|
...res,
|
|
@@ -13187,9 +13714,9 @@ var starknet = (() => {
|
|
|
13187
13714
|
);
|
|
13188
13715
|
this.gatewayUrl = buildUrl(this.baseUrl, "gateway", optionsOrProvider.gatewayUrl);
|
|
13189
13716
|
}
|
|
13190
|
-
this.chainId =
|
|
13717
|
+
this.chainId = optionsOrProvider?.chainId ?? SequencerProvider.getChainIdFromBaseUrl(this.baseUrl);
|
|
13191
13718
|
this.headers = optionsOrProvider.headers;
|
|
13192
|
-
this.blockIdentifier =
|
|
13719
|
+
this.blockIdentifier = optionsOrProvider?.blockIdentifier || defaultOptions2.blockIdentifier;
|
|
13193
13720
|
}
|
|
13194
13721
|
static getNetworkFromName(name) {
|
|
13195
13722
|
switch (name) {
|
|
@@ -13255,6 +13782,7 @@ var starknet = (() => {
|
|
|
13255
13782
|
}
|
|
13256
13783
|
return this.headers;
|
|
13257
13784
|
}
|
|
13785
|
+
// typesafe fetch
|
|
13258
13786
|
async fetchEndpoint(endpoint, ...[query, request]) {
|
|
13259
13787
|
const baseUrl = this.getFetchUrl(endpoint);
|
|
13260
13788
|
const method = this.getFetchMethod(endpoint);
|
|
@@ -13267,9 +13795,9 @@ var starknet = (() => {
|
|
|
13267
13795
|
}
|
|
13268
13796
|
async fetch(endpoint, options) {
|
|
13269
13797
|
const url = buildUrl(this.baseUrl, "", endpoint);
|
|
13270
|
-
const method =
|
|
13798
|
+
const method = options?.method ?? "GET";
|
|
13271
13799
|
const headers = this.getHeaders(method);
|
|
13272
|
-
const body = stringify2(options
|
|
13800
|
+
const body = stringify2(options?.body);
|
|
13273
13801
|
try {
|
|
13274
13802
|
const response = await fetchPonyfill_default(url, {
|
|
13275
13803
|
method,
|
|
@@ -13286,7 +13814,7 @@ var starknet = (() => {
|
|
|
13286
13814
|
}
|
|
13287
13815
|
throw new GatewayError(responseBody.message, responseBody.code);
|
|
13288
13816
|
}
|
|
13289
|
-
const parseChoice =
|
|
13817
|
+
const parseChoice = options?.parseAlwaysAsBigInt ? parseAlwaysAsBig : parse2;
|
|
13290
13818
|
return parseChoice(textResponse);
|
|
13291
13819
|
} catch (error) {
|
|
13292
13820
|
if (error instanceof Error && !(error instanceof LibraryError))
|
|
@@ -13302,6 +13830,9 @@ var starknet = (() => {
|
|
|
13302
13830
|
"call_contract",
|
|
13303
13831
|
{ blockIdentifier },
|
|
13304
13832
|
{
|
|
13833
|
+
// TODO - determine best choice once both are fully supported in devnet
|
|
13834
|
+
// signature: [],
|
|
13835
|
+
// sender_address: contractAddress,
|
|
13305
13836
|
contract_address: contractAddress,
|
|
13306
13837
|
entry_point_selector: getSelectorFromName(entryPointSelector),
|
|
13307
13838
|
calldata: CallData.compile(calldata)
|
|
@@ -13420,7 +13951,7 @@ var starknet = (() => {
|
|
|
13420
13951
|
sender_address: invocation.contractAddress,
|
|
13421
13952
|
calldata: CallData.compile(invocation.calldata ?? []),
|
|
13422
13953
|
signature: signatureToDecimalArray(invocation.signature),
|
|
13423
|
-
version: toHex(
|
|
13954
|
+
version: toHex(invocationDetails?.version || 1),
|
|
13424
13955
|
nonce: toHex(invocationDetails.nonce)
|
|
13425
13956
|
}
|
|
13426
13957
|
).then(this.responseParser.parseFeeEstimateResponse);
|
|
@@ -13435,7 +13966,7 @@ var starknet = (() => {
|
|
|
13435
13966
|
sender_address: senderAddress,
|
|
13436
13967
|
contract_class: contractDefinition,
|
|
13437
13968
|
signature: signatureToDecimalArray(signature),
|
|
13438
|
-
version: toHex(
|
|
13969
|
+
version: toHex(details?.version || toBigInt(feeTransactionVersion)),
|
|
13439
13970
|
nonce: toHex(details.nonce)
|
|
13440
13971
|
}
|
|
13441
13972
|
).then(this.responseParser.parseFeeEstimateResponse);
|
|
@@ -13464,7 +13995,7 @@ var starknet = (() => {
|
|
|
13464
13995
|
constructor_calldata: CallData.compile(constructorCalldata || []),
|
|
13465
13996
|
contract_address_salt: toHex(addressSalt || 0),
|
|
13466
13997
|
signature: signatureToDecimalArray(signature),
|
|
13467
|
-
version: toHex(
|
|
13998
|
+
version: toHex(details?.version || 0),
|
|
13468
13999
|
nonce: toHex(details.nonce)
|
|
13469
14000
|
}
|
|
13470
14001
|
).then(this.responseParser.parseFeeEstimateResponse);
|
|
@@ -13495,7 +14026,7 @@ var starknet = (() => {
|
|
|
13495
14026
|
return {
|
|
13496
14027
|
...res,
|
|
13497
14028
|
signature: bigNumberishArrayToDecimalStringArray(formatSignature(invocation.signature)),
|
|
13498
|
-
version: toHex(toBigInt(
|
|
14029
|
+
version: toHex(toBigInt(invocation?.version || 1)),
|
|
13499
14030
|
nonce: toHex(toBigInt(invocation.nonce))
|
|
13500
14031
|
};
|
|
13501
14032
|
});
|
|
@@ -13510,8 +14041,8 @@ var starknet = (() => {
|
|
|
13510
14041
|
const errorStates = ["REJECTED" /* REJECTED */, "NOT_RECEIVED" /* NOT_RECEIVED */];
|
|
13511
14042
|
let onchain = false;
|
|
13512
14043
|
let res;
|
|
13513
|
-
const retryInterval =
|
|
13514
|
-
const successStates =
|
|
14044
|
+
const retryInterval = options?.retryInterval ?? 8e3;
|
|
14045
|
+
const successStates = options?.successStates ?? [
|
|
13515
14046
|
"ACCEPTED_ON_L1" /* ACCEPTED_ON_L1 */,
|
|
13516
14047
|
"ACCEPTED_ON_L2" /* ACCEPTED_ON_L2 */,
|
|
13517
14048
|
"PENDING" /* PENDING */
|
|
@@ -13532,13 +14063,33 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
13532
14063
|
const txReceipt = await this.getTransactionReceipt(txHash);
|
|
13533
14064
|
return txReceipt;
|
|
13534
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
|
+
*/
|
|
13535
14074
|
async getTransactionStatus(txHash) {
|
|
13536
14075
|
const txHashHex = toHex(txHash);
|
|
13537
14076
|
return this.fetchEndpoint("get_transaction_status", { transactionHash: txHashHex });
|
|
13538
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
|
+
*/
|
|
13539
14084
|
async getContractAddresses() {
|
|
13540
14085
|
return this.fetchEndpoint("get_contract_addresses");
|
|
13541
14086
|
}
|
|
14087
|
+
/**
|
|
14088
|
+
* Gets the transaction trace from a tx id.
|
|
14089
|
+
*
|
|
14090
|
+
* @param txHash
|
|
14091
|
+
* @returns the transaction trace
|
|
14092
|
+
*/
|
|
13542
14093
|
async getTransactionTrace(txHash) {
|
|
13543
14094
|
const txHashHex = toHex(txHash);
|
|
13544
14095
|
return this.fetchEndpoint("get_transaction_trace", { transactionHash: txHashHex });
|
|
@@ -13561,9 +14112,9 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
13561
14112
|
sender_address: invocation.contractAddress,
|
|
13562
14113
|
calldata: CallData.compile(invocation.calldata ?? []),
|
|
13563
14114
|
signature: signatureToDecimalArray(invocation.signature),
|
|
13564
|
-
version: toHex(
|
|
14115
|
+
version: toHex(invocationDetails?.version || 1),
|
|
13565
14116
|
nonce: toHex(invocationDetails.nonce),
|
|
13566
|
-
max_fee: toHex(
|
|
14117
|
+
max_fee: toHex(invocationDetails?.maxFee || 0)
|
|
13567
14118
|
}
|
|
13568
14119
|
).then(this.responseParser.parseFeeSimulateTransactionResponse);
|
|
13569
14120
|
}
|
|
@@ -13573,6 +14124,7 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
13573
14124
|
this.responseParser.parseGetStateUpdateResponse
|
|
13574
14125
|
);
|
|
13575
14126
|
}
|
|
14127
|
+
// consider adding an optional trace retrieval parameter to the getBlock method
|
|
13576
14128
|
async getBlockTraces(blockIdentifier = this.blockIdentifier) {
|
|
13577
14129
|
const args = new Block(blockIdentifier).sequencerIdentifier;
|
|
13578
14130
|
return this.fetchEndpoint("get_block_traces", { ...args });
|
|
@@ -13757,6 +14309,13 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
13757
14309
|
return callback();
|
|
13758
14310
|
}
|
|
13759
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
|
+
*/
|
|
13760
14319
|
constructor(abi, address, providerOrAccount = defaultProvider) {
|
|
13761
14320
|
this.address = address && address.toLowerCase();
|
|
13762
14321
|
this.providerOrAccount = providerOrAccount;
|
|
@@ -13919,6 +14478,13 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
13919
14478
|
this.classHash = classHash;
|
|
13920
14479
|
this.CallData = new CallData(abi);
|
|
13921
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
|
+
*/
|
|
13922
14488
|
async deploy(...args) {
|
|
13923
14489
|
const { args: param, options = { parseRequest: true } } = splitArgsAndOptions(args);
|
|
13924
14490
|
const constructorCalldata = getCalldata(param, () => {
|
|
@@ -13945,13 +14511,26 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
13945
14511
|
contractInstance.deployTransactionHash = transaction_hash;
|
|
13946
14512
|
return contractInstance;
|
|
13947
14513
|
}
|
|
14514
|
+
/**
|
|
14515
|
+
* Attaches to new Account
|
|
14516
|
+
*
|
|
14517
|
+
* @param account - new Provider or Account to attach to
|
|
14518
|
+
* @returns ContractFactory
|
|
14519
|
+
*/
|
|
13948
14520
|
connect(account) {
|
|
13949
14521
|
this.account = account;
|
|
13950
14522
|
return this;
|
|
13951
14523
|
}
|
|
14524
|
+
/**
|
|
14525
|
+
* Attaches current abi and account to the new address
|
|
14526
|
+
*
|
|
14527
|
+
* @param address - Contract address
|
|
14528
|
+
* @returns Contract
|
|
14529
|
+
*/
|
|
13952
14530
|
attach(address) {
|
|
13953
14531
|
return new Contract(this.abi, address, this.account);
|
|
13954
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
|
|
13955
14534
|
};
|
|
13956
14535
|
|
|
13957
14536
|
// src/signer/interface.ts
|
|
@@ -14530,6 +15109,14 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
14530
15109
|
}
|
|
14531
15110
|
);
|
|
14532
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
|
+
*/
|
|
14533
15120
|
async declareIfNot(payload, transactionsDetail = {}) {
|
|
14534
15121
|
const declareContractPayload = extractContractHashes(payload);
|
|
14535
15122
|
try {
|
|
@@ -14710,6 +15297,9 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
14710
15297
|
}
|
|
14711
15298
|
return feeEstimate.suggestedMaxFee;
|
|
14712
15299
|
}
|
|
15300
|
+
/**
|
|
15301
|
+
* will be renamed to buildDeclareContractTransaction
|
|
15302
|
+
*/
|
|
14713
15303
|
async buildDeclarePayload(payload, { nonce, chainId, version, walletAddress, maxFee }) {
|
|
14714
15304
|
const { classHash, contract, compiledClassHash } = extractContractHashes(payload);
|
|
14715
15305
|
const contractDefinition = parseContract(contract);
|
|
@@ -14849,7 +15439,45 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
|
|
|
14849
15439
|
var number2 = num_exports;
|
|
14850
15440
|
return __toCommonJS(src_exports);
|
|
14851
15441
|
})();
|
|
14852
|
-
/*!
|
|
14853
|
-
|
|
14854
|
-
|
|
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
|
+
*/
|
|
14855
15483
|
//# sourceMappingURL=index.global.js.map
|