starknet 5.15.1 → 5.16.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 +8 -0
- package/dist/index.d.ts +22 -7
- package/dist/index.global.js +118 -20
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +118 -20
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +118 -20
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2508,6 +2508,9 @@ var getArrayType = (type) => {
|
|
|
2508
2508
|
function isCairo1Abi(abi) {
|
|
2509
2509
|
const firstFunction = abi.find((entry) => entry.type === "function");
|
|
2510
2510
|
if (!firstFunction) {
|
|
2511
|
+
if (abi.find((it) => it.type === "interface")) {
|
|
2512
|
+
return true;
|
|
2513
|
+
}
|
|
2511
2514
|
throw new Error(`Error in ABI. No function in ABI.`);
|
|
2512
2515
|
}
|
|
2513
2516
|
if (firstFunction.inputs.length) {
|
|
@@ -2609,6 +2612,92 @@ function formatter(data, type, sameType) {
|
|
|
2609
2612
|
}, {});
|
|
2610
2613
|
}
|
|
2611
2614
|
|
|
2615
|
+
// src/utils/calldata/parser/parser-0-1.1.0.ts
|
|
2616
|
+
var AbiParser1 = class {
|
|
2617
|
+
constructor(abi) {
|
|
2618
|
+
this.abi = abi;
|
|
2619
|
+
}
|
|
2620
|
+
/**
|
|
2621
|
+
* abi method inputs length without '_len' inputs
|
|
2622
|
+
* cairo 0 reducer
|
|
2623
|
+
* @param abiMethod FunctionAbi
|
|
2624
|
+
* @returns number
|
|
2625
|
+
*/
|
|
2626
|
+
methodInputsLength(abiMethod) {
|
|
2627
|
+
return abiMethod.inputs.reduce((acc, input) => !isLen(input.name) ? acc + 1 : acc, 0);
|
|
2628
|
+
}
|
|
2629
|
+
/**
|
|
2630
|
+
* get method definition from abi
|
|
2631
|
+
* @param name string
|
|
2632
|
+
* @returns FunctionAbi | undefined
|
|
2633
|
+
*/
|
|
2634
|
+
getMethod(name) {
|
|
2635
|
+
return this.abi.find((it) => it.name === name);
|
|
2636
|
+
}
|
|
2637
|
+
/**
|
|
2638
|
+
* Get Abi in legacy format
|
|
2639
|
+
* @returns Abi
|
|
2640
|
+
*/
|
|
2641
|
+
getLegacyFormat() {
|
|
2642
|
+
return this.abi;
|
|
2643
|
+
}
|
|
2644
|
+
};
|
|
2645
|
+
|
|
2646
|
+
// src/utils/calldata/parser/parser-2.0.0.ts
|
|
2647
|
+
var AbiParser2 = class {
|
|
2648
|
+
constructor(abi) {
|
|
2649
|
+
this.abi = abi;
|
|
2650
|
+
}
|
|
2651
|
+
/**
|
|
2652
|
+
* abi method inputs length
|
|
2653
|
+
* @param abiMethod FunctionAbi
|
|
2654
|
+
* @returns number
|
|
2655
|
+
*/
|
|
2656
|
+
methodInputsLength(abiMethod) {
|
|
2657
|
+
return abiMethod.inputs.length;
|
|
2658
|
+
}
|
|
2659
|
+
/**
|
|
2660
|
+
* get method definition from abi
|
|
2661
|
+
* @param name string
|
|
2662
|
+
* @returns FunctionAbi | undefined
|
|
2663
|
+
*/
|
|
2664
|
+
getMethod(name) {
|
|
2665
|
+
const intf = this.abi.find((it) => it.type === "interface");
|
|
2666
|
+
return intf.items.find((it) => it.name === name);
|
|
2667
|
+
}
|
|
2668
|
+
/**
|
|
2669
|
+
* Get Abi in legacy format
|
|
2670
|
+
* @returns Abi
|
|
2671
|
+
*/
|
|
2672
|
+
getLegacyFormat() {
|
|
2673
|
+
return this.abi.flatMap((e) => {
|
|
2674
|
+
if (e.type === "interface") {
|
|
2675
|
+
return e.items;
|
|
2676
|
+
}
|
|
2677
|
+
return e;
|
|
2678
|
+
});
|
|
2679
|
+
}
|
|
2680
|
+
};
|
|
2681
|
+
|
|
2682
|
+
// src/utils/calldata/parser/index.ts
|
|
2683
|
+
function createAbiParser(abi) {
|
|
2684
|
+
const version = getAbiVersion(abi);
|
|
2685
|
+
if (version === 0 || version === 1) {
|
|
2686
|
+
return new AbiParser1(abi);
|
|
2687
|
+
}
|
|
2688
|
+
if (version === 2) {
|
|
2689
|
+
return new AbiParser2(abi);
|
|
2690
|
+
}
|
|
2691
|
+
throw Error(`Unsupported ABI version ${version}`);
|
|
2692
|
+
}
|
|
2693
|
+
function getAbiVersion(abi) {
|
|
2694
|
+
if (abi.find((it) => it.type === "interface"))
|
|
2695
|
+
return 2;
|
|
2696
|
+
if (isCairo1Abi(abi))
|
|
2697
|
+
return 1;
|
|
2698
|
+
return 0;
|
|
2699
|
+
}
|
|
2700
|
+
|
|
2612
2701
|
// src/utils/calldata/tuple.ts
|
|
2613
2702
|
function parseNamedTuple(namedTuple) {
|
|
2614
2703
|
const name = namedTuple.substring(0, namedTuple.indexOf(":"));
|
|
@@ -2837,6 +2926,14 @@ function parseTuple(element, typeStr) {
|
|
|
2837
2926
|
};
|
|
2838
2927
|
});
|
|
2839
2928
|
}
|
|
2929
|
+
function parseUint256(element) {
|
|
2930
|
+
if (typeof element === "object") {
|
|
2931
|
+
const { low, high } = element;
|
|
2932
|
+
return [felt(low), felt(high)];
|
|
2933
|
+
}
|
|
2934
|
+
const el_uint256 = uint256(element);
|
|
2935
|
+
return [felt(el_uint256.low), felt(el_uint256.high)];
|
|
2936
|
+
}
|
|
2840
2937
|
function parseCalldataValue(element, type, structs) {
|
|
2841
2938
|
if (element === void 0) {
|
|
2842
2939
|
throw Error(`Missing parameter for type ${type}`);
|
|
@@ -2850,6 +2947,9 @@ function parseCalldataValue(element, type, structs) {
|
|
|
2850
2947
|
}, result);
|
|
2851
2948
|
}
|
|
2852
2949
|
if (structs[type] && structs[type].members.length) {
|
|
2950
|
+
if (isTypeUint256(type)) {
|
|
2951
|
+
return parseUint256(element);
|
|
2952
|
+
}
|
|
2853
2953
|
const { members } = structs[type];
|
|
2854
2954
|
const subElement = element;
|
|
2855
2955
|
return members.reduce((acc, it) => {
|
|
@@ -2864,12 +2964,7 @@ function parseCalldataValue(element, type, structs) {
|
|
|
2864
2964
|
}, []);
|
|
2865
2965
|
}
|
|
2866
2966
|
if (isTypeUint256(type)) {
|
|
2867
|
-
|
|
2868
|
-
const { low, high } = element;
|
|
2869
|
-
return [felt(low), felt(high)];
|
|
2870
|
-
}
|
|
2871
|
-
const el_uint256 = uint256(element);
|
|
2872
|
-
return [felt(el_uint256.low), felt(el_uint256.high)];
|
|
2967
|
+
return parseUint256(element);
|
|
2873
2968
|
}
|
|
2874
2969
|
if (typeof element === "object") {
|
|
2875
2970
|
throw Error(`Parameter ${element} do not align with abi parameter ${type}`);
|
|
@@ -2912,6 +3007,11 @@ function parseBaseTypes2(type, it) {
|
|
|
2912
3007
|
}
|
|
2913
3008
|
}
|
|
2914
3009
|
function parseResponseValue(responseIterator, element, structs) {
|
|
3010
|
+
if (isTypeUint256(element.type)) {
|
|
3011
|
+
const low = responseIterator.next().value;
|
|
3012
|
+
const high = responseIterator.next().value;
|
|
3013
|
+
return uint256ToBN({ low, high });
|
|
3014
|
+
}
|
|
2915
3015
|
if (element.type in structs && structs[element.type]) {
|
|
2916
3016
|
return structs[element.type].members.reduce((acc, el) => {
|
|
2917
3017
|
acc[el.name] = parseResponseValue(responseIterator, el, structs);
|
|
@@ -3038,6 +3138,10 @@ var validateBool = (parameter, input) => {
|
|
|
3038
3138
|
);
|
|
3039
3139
|
};
|
|
3040
3140
|
var validateStruct = (parameter, input, structs) => {
|
|
3141
|
+
if (input.type === "core::integer::u256" /* u256 */) {
|
|
3142
|
+
validateUint(parameter, input);
|
|
3143
|
+
return;
|
|
3144
|
+
}
|
|
3041
3145
|
assert(
|
|
3042
3146
|
typeof parameter === "object" && !Array.isArray(parameter),
|
|
3043
3147
|
`Validate: arg ${input.name} is cairo type struct (${input.type}), and should be defined as js object (not array)`
|
|
@@ -3127,8 +3231,9 @@ function validateFields(abiMethod, args, structs) {
|
|
|
3127
3231
|
// src/utils/calldata/index.ts
|
|
3128
3232
|
var CallData = class {
|
|
3129
3233
|
constructor(abi) {
|
|
3130
|
-
this.abi = abi;
|
|
3131
3234
|
this.structs = CallData.getAbiStruct(abi);
|
|
3235
|
+
this.parser = createAbiParser(abi);
|
|
3236
|
+
this.abi = this.parser.getLegacyFormat();
|
|
3132
3237
|
}
|
|
3133
3238
|
/**
|
|
3134
3239
|
* Validate arguments passed to the method as corresponding to the ones in the abi
|
|
@@ -3150,9 +3255,9 @@ var CallData = class {
|
|
|
3150
3255
|
);
|
|
3151
3256
|
}
|
|
3152
3257
|
const abiMethod = this.abi.find(
|
|
3153
|
-
(abi) => type === "DEPLOY" /* DEPLOY */ ? abi.name === method && abi.type ===
|
|
3258
|
+
(abi) => type === "DEPLOY" /* DEPLOY */ ? abi.name === method && abi.type === "constructor" : abi.name === method && abi.type === "function"
|
|
3154
3259
|
);
|
|
3155
|
-
const inputsLength =
|
|
3260
|
+
const inputsLength = this.parser.methodInputsLength(abiMethod);
|
|
3156
3261
|
if (args.length !== inputsLength) {
|
|
3157
3262
|
throw Error(
|
|
3158
3263
|
`Invalid number of arguments, expected ${inputsLength} arguments, but got ${args.length}`
|
|
@@ -3259,14 +3364,6 @@ var CallData = class {
|
|
|
3259
3364
|
const parsed = this.parse(method, response);
|
|
3260
3365
|
return formatter(parsed, format);
|
|
3261
3366
|
}
|
|
3262
|
-
/**
|
|
3263
|
-
* Helper to calculate inputs from abi
|
|
3264
|
-
* @param inputs AbiEntry
|
|
3265
|
-
* @returns number
|
|
3266
|
-
*/
|
|
3267
|
-
static abiInputsLength(inputs) {
|
|
3268
|
-
return inputs.reduce((acc, input) => !isLen(input.name) ? acc + 1 : acc, 0);
|
|
3269
|
-
}
|
|
3270
3367
|
/**
|
|
3271
3368
|
* Helper to extract structs from abi
|
|
3272
3369
|
* @param abi Abi
|
|
@@ -3384,12 +3481,12 @@ function calculateTransactionHashCommon(txHashPrefix, version, contractAddress,
|
|
|
3384
3481
|
];
|
|
3385
3482
|
return computeHashOnElements(dataToHash);
|
|
3386
3483
|
}
|
|
3387
|
-
function calculateDeployTransactionHash(contractAddress, constructorCalldata, version, chainId) {
|
|
3484
|
+
function calculateDeployTransactionHash(contractAddress, constructorCalldata, version, chainId, constructorName = "constructor") {
|
|
3388
3485
|
return calculateTransactionHashCommon(
|
|
3389
3486
|
"0x6465706c6f79" /* DEPLOY */,
|
|
3390
3487
|
version,
|
|
3391
3488
|
contractAddress,
|
|
3392
|
-
getSelectorFromName(
|
|
3489
|
+
getSelectorFromName(constructorName),
|
|
3393
3490
|
constructorCalldata,
|
|
3394
3491
|
0,
|
|
3395
3492
|
chainId
|
|
@@ -6095,7 +6192,8 @@ var Contract = class {
|
|
|
6095
6192
|
this.providerOrAccount = providerOrAccount;
|
|
6096
6193
|
this.callData = new CallData(abi);
|
|
6097
6194
|
this.structs = CallData.getAbiStruct(abi);
|
|
6098
|
-
|
|
6195
|
+
const parser = createAbiParser(abi);
|
|
6196
|
+
this.abi = parser.getLegacyFormat();
|
|
6099
6197
|
const options = { enumerable: true, value: {}, writable: false };
|
|
6100
6198
|
Object.defineProperties(this, {
|
|
6101
6199
|
functions: { enumerable: true, value: {}, writable: false },
|