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.js
CHANGED
|
@@ -2595,6 +2595,9 @@ var getArrayType = (type) => {
|
|
|
2595
2595
|
function isCairo1Abi(abi) {
|
|
2596
2596
|
const firstFunction = abi.find((entry) => entry.type === "function");
|
|
2597
2597
|
if (!firstFunction) {
|
|
2598
|
+
if (abi.find((it) => it.type === "interface")) {
|
|
2599
|
+
return true;
|
|
2600
|
+
}
|
|
2598
2601
|
throw new Error(`Error in ABI. No function in ABI.`);
|
|
2599
2602
|
}
|
|
2600
2603
|
if (firstFunction.inputs.length) {
|
|
@@ -2696,6 +2699,92 @@ function formatter(data, type, sameType) {
|
|
|
2696
2699
|
}, {});
|
|
2697
2700
|
}
|
|
2698
2701
|
|
|
2702
|
+
// src/utils/calldata/parser/parser-0-1.1.0.ts
|
|
2703
|
+
var AbiParser1 = class {
|
|
2704
|
+
constructor(abi) {
|
|
2705
|
+
this.abi = abi;
|
|
2706
|
+
}
|
|
2707
|
+
/**
|
|
2708
|
+
* abi method inputs length without '_len' inputs
|
|
2709
|
+
* cairo 0 reducer
|
|
2710
|
+
* @param abiMethod FunctionAbi
|
|
2711
|
+
* @returns number
|
|
2712
|
+
*/
|
|
2713
|
+
methodInputsLength(abiMethod) {
|
|
2714
|
+
return abiMethod.inputs.reduce((acc, input) => !isLen(input.name) ? acc + 1 : acc, 0);
|
|
2715
|
+
}
|
|
2716
|
+
/**
|
|
2717
|
+
* get method definition from abi
|
|
2718
|
+
* @param name string
|
|
2719
|
+
* @returns FunctionAbi | undefined
|
|
2720
|
+
*/
|
|
2721
|
+
getMethod(name) {
|
|
2722
|
+
return this.abi.find((it) => it.name === name);
|
|
2723
|
+
}
|
|
2724
|
+
/**
|
|
2725
|
+
* Get Abi in legacy format
|
|
2726
|
+
* @returns Abi
|
|
2727
|
+
*/
|
|
2728
|
+
getLegacyFormat() {
|
|
2729
|
+
return this.abi;
|
|
2730
|
+
}
|
|
2731
|
+
};
|
|
2732
|
+
|
|
2733
|
+
// src/utils/calldata/parser/parser-2.0.0.ts
|
|
2734
|
+
var AbiParser2 = class {
|
|
2735
|
+
constructor(abi) {
|
|
2736
|
+
this.abi = abi;
|
|
2737
|
+
}
|
|
2738
|
+
/**
|
|
2739
|
+
* abi method inputs length
|
|
2740
|
+
* @param abiMethod FunctionAbi
|
|
2741
|
+
* @returns number
|
|
2742
|
+
*/
|
|
2743
|
+
methodInputsLength(abiMethod) {
|
|
2744
|
+
return abiMethod.inputs.length;
|
|
2745
|
+
}
|
|
2746
|
+
/**
|
|
2747
|
+
* get method definition from abi
|
|
2748
|
+
* @param name string
|
|
2749
|
+
* @returns FunctionAbi | undefined
|
|
2750
|
+
*/
|
|
2751
|
+
getMethod(name) {
|
|
2752
|
+
const intf = this.abi.find((it) => it.type === "interface");
|
|
2753
|
+
return intf.items.find((it) => it.name === name);
|
|
2754
|
+
}
|
|
2755
|
+
/**
|
|
2756
|
+
* Get Abi in legacy format
|
|
2757
|
+
* @returns Abi
|
|
2758
|
+
*/
|
|
2759
|
+
getLegacyFormat() {
|
|
2760
|
+
return this.abi.flatMap((e) => {
|
|
2761
|
+
if (e.type === "interface") {
|
|
2762
|
+
return e.items;
|
|
2763
|
+
}
|
|
2764
|
+
return e;
|
|
2765
|
+
});
|
|
2766
|
+
}
|
|
2767
|
+
};
|
|
2768
|
+
|
|
2769
|
+
// src/utils/calldata/parser/index.ts
|
|
2770
|
+
function createAbiParser(abi) {
|
|
2771
|
+
const version = getAbiVersion(abi);
|
|
2772
|
+
if (version === 0 || version === 1) {
|
|
2773
|
+
return new AbiParser1(abi);
|
|
2774
|
+
}
|
|
2775
|
+
if (version === 2) {
|
|
2776
|
+
return new AbiParser2(abi);
|
|
2777
|
+
}
|
|
2778
|
+
throw Error(`Unsupported ABI version ${version}`);
|
|
2779
|
+
}
|
|
2780
|
+
function getAbiVersion(abi) {
|
|
2781
|
+
if (abi.find((it) => it.type === "interface"))
|
|
2782
|
+
return 2;
|
|
2783
|
+
if (isCairo1Abi(abi))
|
|
2784
|
+
return 1;
|
|
2785
|
+
return 0;
|
|
2786
|
+
}
|
|
2787
|
+
|
|
2699
2788
|
// src/utils/calldata/tuple.ts
|
|
2700
2789
|
function parseNamedTuple(namedTuple) {
|
|
2701
2790
|
const name = namedTuple.substring(0, namedTuple.indexOf(":"));
|
|
@@ -2924,6 +3013,14 @@ function parseTuple(element, typeStr) {
|
|
|
2924
3013
|
};
|
|
2925
3014
|
});
|
|
2926
3015
|
}
|
|
3016
|
+
function parseUint256(element) {
|
|
3017
|
+
if (typeof element === "object") {
|
|
3018
|
+
const { low, high } = element;
|
|
3019
|
+
return [felt(low), felt(high)];
|
|
3020
|
+
}
|
|
3021
|
+
const el_uint256 = uint256(element);
|
|
3022
|
+
return [felt(el_uint256.low), felt(el_uint256.high)];
|
|
3023
|
+
}
|
|
2927
3024
|
function parseCalldataValue(element, type, structs) {
|
|
2928
3025
|
if (element === void 0) {
|
|
2929
3026
|
throw Error(`Missing parameter for type ${type}`);
|
|
@@ -2937,6 +3034,9 @@ function parseCalldataValue(element, type, structs) {
|
|
|
2937
3034
|
}, result);
|
|
2938
3035
|
}
|
|
2939
3036
|
if (structs[type] && structs[type].members.length) {
|
|
3037
|
+
if (isTypeUint256(type)) {
|
|
3038
|
+
return parseUint256(element);
|
|
3039
|
+
}
|
|
2940
3040
|
const { members } = structs[type];
|
|
2941
3041
|
const subElement = element;
|
|
2942
3042
|
return members.reduce((acc, it) => {
|
|
@@ -2951,12 +3051,7 @@ function parseCalldataValue(element, type, structs) {
|
|
|
2951
3051
|
}, []);
|
|
2952
3052
|
}
|
|
2953
3053
|
if (isTypeUint256(type)) {
|
|
2954
|
-
|
|
2955
|
-
const { low, high } = element;
|
|
2956
|
-
return [felt(low), felt(high)];
|
|
2957
|
-
}
|
|
2958
|
-
const el_uint256 = uint256(element);
|
|
2959
|
-
return [felt(el_uint256.low), felt(el_uint256.high)];
|
|
3054
|
+
return parseUint256(element);
|
|
2960
3055
|
}
|
|
2961
3056
|
if (typeof element === "object") {
|
|
2962
3057
|
throw Error(`Parameter ${element} do not align with abi parameter ${type}`);
|
|
@@ -2999,6 +3094,11 @@ function parseBaseTypes2(type, it) {
|
|
|
2999
3094
|
}
|
|
3000
3095
|
}
|
|
3001
3096
|
function parseResponseValue(responseIterator, element, structs) {
|
|
3097
|
+
if (isTypeUint256(element.type)) {
|
|
3098
|
+
const low = responseIterator.next().value;
|
|
3099
|
+
const high = responseIterator.next().value;
|
|
3100
|
+
return uint256ToBN({ low, high });
|
|
3101
|
+
}
|
|
3002
3102
|
if (element.type in structs && structs[element.type]) {
|
|
3003
3103
|
return structs[element.type].members.reduce((acc, el) => {
|
|
3004
3104
|
acc[el.name] = parseResponseValue(responseIterator, el, structs);
|
|
@@ -3125,6 +3225,10 @@ var validateBool = (parameter, input) => {
|
|
|
3125
3225
|
);
|
|
3126
3226
|
};
|
|
3127
3227
|
var validateStruct = (parameter, input, structs) => {
|
|
3228
|
+
if (input.type === "core::integer::u256" /* u256 */) {
|
|
3229
|
+
validateUint(parameter, input);
|
|
3230
|
+
return;
|
|
3231
|
+
}
|
|
3128
3232
|
assert(
|
|
3129
3233
|
typeof parameter === "object" && !Array.isArray(parameter),
|
|
3130
3234
|
`Validate: arg ${input.name} is cairo type struct (${input.type}), and should be defined as js object (not array)`
|
|
@@ -3214,8 +3318,9 @@ function validateFields(abiMethod, args, structs) {
|
|
|
3214
3318
|
// src/utils/calldata/index.ts
|
|
3215
3319
|
var CallData = class {
|
|
3216
3320
|
constructor(abi) {
|
|
3217
|
-
this.abi = abi;
|
|
3218
3321
|
this.structs = CallData.getAbiStruct(abi);
|
|
3322
|
+
this.parser = createAbiParser(abi);
|
|
3323
|
+
this.abi = this.parser.getLegacyFormat();
|
|
3219
3324
|
}
|
|
3220
3325
|
/**
|
|
3221
3326
|
* Validate arguments passed to the method as corresponding to the ones in the abi
|
|
@@ -3237,9 +3342,9 @@ var CallData = class {
|
|
|
3237
3342
|
);
|
|
3238
3343
|
}
|
|
3239
3344
|
const abiMethod = this.abi.find(
|
|
3240
|
-
(abi) => type === "DEPLOY" /* DEPLOY */ ? abi.name === method && abi.type ===
|
|
3345
|
+
(abi) => type === "DEPLOY" /* DEPLOY */ ? abi.name === method && abi.type === "constructor" : abi.name === method && abi.type === "function"
|
|
3241
3346
|
);
|
|
3242
|
-
const inputsLength =
|
|
3347
|
+
const inputsLength = this.parser.methodInputsLength(abiMethod);
|
|
3243
3348
|
if (args.length !== inputsLength) {
|
|
3244
3349
|
throw Error(
|
|
3245
3350
|
`Invalid number of arguments, expected ${inputsLength} arguments, but got ${args.length}`
|
|
@@ -3346,14 +3451,6 @@ var CallData = class {
|
|
|
3346
3451
|
const parsed = this.parse(method, response);
|
|
3347
3452
|
return formatter(parsed, format);
|
|
3348
3453
|
}
|
|
3349
|
-
/**
|
|
3350
|
-
* Helper to calculate inputs from abi
|
|
3351
|
-
* @param inputs AbiEntry
|
|
3352
|
-
* @returns number
|
|
3353
|
-
*/
|
|
3354
|
-
static abiInputsLength(inputs) {
|
|
3355
|
-
return inputs.reduce((acc, input) => !isLen(input.name) ? acc + 1 : acc, 0);
|
|
3356
|
-
}
|
|
3357
3454
|
/**
|
|
3358
3455
|
* Helper to extract structs from abi
|
|
3359
3456
|
* @param abi Abi
|
|
@@ -3471,12 +3568,12 @@ function calculateTransactionHashCommon(txHashPrefix, version, contractAddress,
|
|
|
3471
3568
|
];
|
|
3472
3569
|
return computeHashOnElements(dataToHash);
|
|
3473
3570
|
}
|
|
3474
|
-
function calculateDeployTransactionHash(contractAddress, constructorCalldata, version, chainId) {
|
|
3571
|
+
function calculateDeployTransactionHash(contractAddress, constructorCalldata, version, chainId, constructorName = "constructor") {
|
|
3475
3572
|
return calculateTransactionHashCommon(
|
|
3476
3573
|
"0x6465706c6f79" /* DEPLOY */,
|
|
3477
3574
|
version,
|
|
3478
3575
|
contractAddress,
|
|
3479
|
-
getSelectorFromName(
|
|
3576
|
+
getSelectorFromName(constructorName),
|
|
3480
3577
|
constructorCalldata,
|
|
3481
3578
|
0,
|
|
3482
3579
|
chainId
|
|
@@ -6182,7 +6279,8 @@ var Contract = class {
|
|
|
6182
6279
|
this.providerOrAccount = providerOrAccount;
|
|
6183
6280
|
this.callData = new CallData(abi);
|
|
6184
6281
|
this.structs = CallData.getAbiStruct(abi);
|
|
6185
|
-
|
|
6282
|
+
const parser = createAbiParser(abi);
|
|
6283
|
+
this.abi = parser.getLegacyFormat();
|
|
6186
6284
|
const options = { enumerable: true, value: {}, writable: false };
|
|
6187
6285
|
Object.defineProperties(this, {
|
|
6188
6286
|
functions: { enumerable: true, value: {}, writable: false },
|