starknet 5.8.0 → 5.9.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 +7 -0
- package/dist/index.d.ts +38 -15
- package/dist/index.global.js +4465 -4470
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +243 -248
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +243 -248
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -43,9 +43,12 @@ var RPC;
|
|
|
43
43
|
})(TransactionType2 = RPC2.TransactionType || (RPC2.TransactionType = {}));
|
|
44
44
|
})(RPC || (RPC = {}));
|
|
45
45
|
|
|
46
|
-
// src/utils/
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
// src/utils/assert.ts
|
|
47
|
+
function assert(condition, message) {
|
|
48
|
+
if (!condition) {
|
|
49
|
+
throw new Error(message || "Assertion failure");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
49
52
|
|
|
50
53
|
// src/utils/hash.ts
|
|
51
54
|
var hash_exports = {};
|
|
@@ -2271,15 +2274,6 @@ __export(num_exports, {
|
|
|
2271
2274
|
toHexString: () => toHexString
|
|
2272
2275
|
});
|
|
2273
2276
|
import { hexToBytes as hexToBytesNoble } from "@noble/curves/abstract/utils";
|
|
2274
|
-
|
|
2275
|
-
// src/utils/assert.ts
|
|
2276
|
-
function assert(condition, message) {
|
|
2277
|
-
if (!condition) {
|
|
2278
|
-
throw new Error(message || "Assertion failure");
|
|
2279
|
-
}
|
|
2280
|
-
}
|
|
2281
|
-
|
|
2282
|
-
// src/utils/num.ts
|
|
2283
2277
|
function isHex(hex) {
|
|
2284
2278
|
return /^0x[0-9a-f]*$/i.test(hex);
|
|
2285
2279
|
}
|
|
@@ -2743,185 +2737,6 @@ function computeContractClassHash(contract) {
|
|
|
2743
2737
|
return computeLegacyContractClassHash(compiledContract);
|
|
2744
2738
|
}
|
|
2745
2739
|
|
|
2746
|
-
// src/utils/contract.ts
|
|
2747
|
-
function isSierra(contract) {
|
|
2748
|
-
const compiledContract = typeof contract === "string" ? parse2(contract) : contract;
|
|
2749
|
-
return "sierra_program" in compiledContract;
|
|
2750
|
-
}
|
|
2751
|
-
function extractContractHashes(payload) {
|
|
2752
|
-
const response = { ...payload };
|
|
2753
|
-
if (isSierra(payload.contract)) {
|
|
2754
|
-
if (!payload.compiledClassHash && payload.casm) {
|
|
2755
|
-
response.compiledClassHash = computeCompiledClassHash(payload.casm);
|
|
2756
|
-
}
|
|
2757
|
-
if (!response.compiledClassHash)
|
|
2758
|
-
throw new Error(
|
|
2759
|
-
"Extract compiledClassHash failed, provide (CairoAssembly).casm file or compiledClassHash"
|
|
2760
|
-
);
|
|
2761
|
-
}
|
|
2762
|
-
response.classHash = payload.classHash ?? computeContractClassHash(payload.contract);
|
|
2763
|
-
if (!response.classHash)
|
|
2764
|
-
throw new Error("Extract classHash failed, provide (CompiledContract).json file or classHash");
|
|
2765
|
-
return response;
|
|
2766
|
-
}
|
|
2767
|
-
|
|
2768
|
-
// src/utils/stark.ts
|
|
2769
|
-
var stark_exports = {};
|
|
2770
|
-
__export(stark_exports, {
|
|
2771
|
-
compressProgram: () => compressProgram,
|
|
2772
|
-
estimatedFeeToMaxFee: () => estimatedFeeToMaxFee,
|
|
2773
|
-
formatSignature: () => formatSignature,
|
|
2774
|
-
makeAddress: () => makeAddress,
|
|
2775
|
-
randomAddress: () => randomAddress,
|
|
2776
|
-
signatureToDecimalArray: () => signatureToDecimalArray,
|
|
2777
|
-
signatureToHexArray: () => signatureToHexArray
|
|
2778
|
-
});
|
|
2779
|
-
import { getStarkKey, utils } from "micro-starknet";
|
|
2780
|
-
import { gzip } from "pako";
|
|
2781
|
-
function compressProgram(jsonProgram) {
|
|
2782
|
-
const stringified = typeof jsonProgram === "string" ? jsonProgram : stringify2(jsonProgram);
|
|
2783
|
-
const compressedProgram = gzip(stringified);
|
|
2784
|
-
return btoaUniversal(compressedProgram);
|
|
2785
|
-
}
|
|
2786
|
-
function randomAddress() {
|
|
2787
|
-
const randomKeyPair = utils.randomPrivateKey();
|
|
2788
|
-
return getStarkKey(randomKeyPair);
|
|
2789
|
-
}
|
|
2790
|
-
function makeAddress(input) {
|
|
2791
|
-
return addHexPrefix(input).toLowerCase();
|
|
2792
|
-
}
|
|
2793
|
-
function formatSignature(sig) {
|
|
2794
|
-
if (!sig)
|
|
2795
|
-
throw Error("formatSignature: provided signature is undefined");
|
|
2796
|
-
if (Array.isArray(sig)) {
|
|
2797
|
-
return sig.map((it) => toHex(it));
|
|
2798
|
-
}
|
|
2799
|
-
try {
|
|
2800
|
-
const { r, s } = sig;
|
|
2801
|
-
return [toHex(r), toHex(s)];
|
|
2802
|
-
} catch (e) {
|
|
2803
|
-
throw new Error("Signature need to be weierstrass.SignatureType or an array for custom");
|
|
2804
|
-
}
|
|
2805
|
-
}
|
|
2806
|
-
function signatureToDecimalArray(sig) {
|
|
2807
|
-
return bigNumberishArrayToDecimalStringArray(formatSignature(sig));
|
|
2808
|
-
}
|
|
2809
|
-
function signatureToHexArray(sig) {
|
|
2810
|
-
return bigNumberishArrayToHexadecimalStringArray(formatSignature(sig));
|
|
2811
|
-
}
|
|
2812
|
-
function estimatedFeeToMaxFee(estimatedFee, overhead = 0.5) {
|
|
2813
|
-
const overHeadPercent = Math.round((1 + overhead) * 100);
|
|
2814
|
-
return toBigInt(estimatedFee) * toBigInt(overHeadPercent) / 100n;
|
|
2815
|
-
}
|
|
2816
|
-
|
|
2817
|
-
// src/utils/provider.ts
|
|
2818
|
-
function wait(delay) {
|
|
2819
|
-
return new Promise((res) => {
|
|
2820
|
-
setTimeout(res, delay);
|
|
2821
|
-
});
|
|
2822
|
-
}
|
|
2823
|
-
function parseCalldata(calldata = []) {
|
|
2824
|
-
return calldata.map((data) => {
|
|
2825
|
-
if (typeof data === "string" && isHex(data)) {
|
|
2826
|
-
return data;
|
|
2827
|
-
}
|
|
2828
|
-
return toHex(data);
|
|
2829
|
-
});
|
|
2830
|
-
}
|
|
2831
|
-
function createSierraContractClass(contract) {
|
|
2832
|
-
const result = { ...contract };
|
|
2833
|
-
delete result.sierra_program_debug_info;
|
|
2834
|
-
result.abi = formatSpaces(stringify2(contract.abi));
|
|
2835
|
-
result.sierra_program = formatSpaces(stringify2(contract.sierra_program));
|
|
2836
|
-
result.sierra_program = compressProgram(result.sierra_program);
|
|
2837
|
-
return result;
|
|
2838
|
-
}
|
|
2839
|
-
function parseContract(contract) {
|
|
2840
|
-
const parsedContract = typeof contract === "string" ? parse2(contract) : contract;
|
|
2841
|
-
if (!isSierra(contract)) {
|
|
2842
|
-
return {
|
|
2843
|
-
...parsedContract,
|
|
2844
|
-
..."program" in parsedContract && { program: compressProgram(parsedContract.program) }
|
|
2845
|
-
};
|
|
2846
|
-
}
|
|
2847
|
-
return createSierraContractClass(parsedContract);
|
|
2848
|
-
}
|
|
2849
|
-
|
|
2850
|
-
// src/utils/responseParser/rpc.ts
|
|
2851
|
-
var RPCResponseParser = class {
|
|
2852
|
-
parseGetBlockResponse(res) {
|
|
2853
|
-
return {
|
|
2854
|
-
timestamp: res.timestamp,
|
|
2855
|
-
block_hash: res.block_hash,
|
|
2856
|
-
block_number: res.block_number,
|
|
2857
|
-
new_root: res.new_root,
|
|
2858
|
-
parent_hash: res.parent_hash,
|
|
2859
|
-
status: res.status,
|
|
2860
|
-
transactions: res.transactions
|
|
2861
|
-
};
|
|
2862
|
-
}
|
|
2863
|
-
parseGetTransactionResponse(res) {
|
|
2864
|
-
return {
|
|
2865
|
-
calldata: res.calldata || [],
|
|
2866
|
-
contract_address: res.contract_address,
|
|
2867
|
-
sender_address: res.contract_address,
|
|
2868
|
-
max_fee: res.max_fee,
|
|
2869
|
-
nonce: res.nonce,
|
|
2870
|
-
signature: res.signature || [],
|
|
2871
|
-
transaction_hash: res.transaction_hash,
|
|
2872
|
-
version: res.version
|
|
2873
|
-
};
|
|
2874
|
-
}
|
|
2875
|
-
parseFeeEstimateResponse(res) {
|
|
2876
|
-
return {
|
|
2877
|
-
overall_fee: toBigInt(res.overall_fee),
|
|
2878
|
-
gas_consumed: toBigInt(res.gas_consumed),
|
|
2879
|
-
gas_price: toBigInt(res.gas_price)
|
|
2880
|
-
};
|
|
2881
|
-
}
|
|
2882
|
-
parseCallContractResponse(res) {
|
|
2883
|
-
return {
|
|
2884
|
-
result: res
|
|
2885
|
-
};
|
|
2886
|
-
}
|
|
2887
|
-
};
|
|
2888
|
-
|
|
2889
|
-
// src/provider/errors.ts
|
|
2890
|
-
function fixStack(target, fn = target.constructor) {
|
|
2891
|
-
const { captureStackTrace } = Error;
|
|
2892
|
-
captureStackTrace && captureStackTrace(target, fn);
|
|
2893
|
-
}
|
|
2894
|
-
function fixProto(target, prototype) {
|
|
2895
|
-
const { setPrototypeOf } = Object;
|
|
2896
|
-
setPrototypeOf ? setPrototypeOf(target, prototype) : target.__proto__ = prototype;
|
|
2897
|
-
}
|
|
2898
|
-
var CustomError = class extends Error {
|
|
2899
|
-
constructor(message) {
|
|
2900
|
-
super(message);
|
|
2901
|
-
Object.defineProperty(this, "name", {
|
|
2902
|
-
value: new.target.name,
|
|
2903
|
-
enumerable: false,
|
|
2904
|
-
configurable: true
|
|
2905
|
-
});
|
|
2906
|
-
fixProto(this, new.target.prototype);
|
|
2907
|
-
fixStack(this);
|
|
2908
|
-
}
|
|
2909
|
-
};
|
|
2910
|
-
var LibraryError = class extends CustomError {
|
|
2911
|
-
};
|
|
2912
|
-
var GatewayError = class extends LibraryError {
|
|
2913
|
-
constructor(message, errorCode) {
|
|
2914
|
-
super(message);
|
|
2915
|
-
this.errorCode = errorCode;
|
|
2916
|
-
}
|
|
2917
|
-
};
|
|
2918
|
-
var HttpError = class extends LibraryError {
|
|
2919
|
-
constructor(message, errorCode) {
|
|
2920
|
-
super(message);
|
|
2921
|
-
this.errorCode = errorCode;
|
|
2922
|
-
}
|
|
2923
|
-
};
|
|
2924
|
-
|
|
2925
2740
|
// src/utils/calldata/formatter.ts
|
|
2926
2741
|
var guard = {
|
|
2927
2742
|
isBN: (data, type, key) => {
|
|
@@ -3039,6 +2854,15 @@ function extractTupleMemberTypes(type) {
|
|
|
3039
2854
|
}
|
|
3040
2855
|
|
|
3041
2856
|
// src/utils/calldata/requestParser.ts
|
|
2857
|
+
function parseBaseTypes(type, val) {
|
|
2858
|
+
switch (true) {
|
|
2859
|
+
case isTypeUint256(type):
|
|
2860
|
+
const el_uint256 = uint256(val);
|
|
2861
|
+
return [felt(el_uint256.low), felt(el_uint256.high)];
|
|
2862
|
+
default:
|
|
2863
|
+
return felt(val);
|
|
2864
|
+
}
|
|
2865
|
+
}
|
|
3042
2866
|
function parseTuple(element, typeStr) {
|
|
3043
2867
|
const memberTypes = extractTupleMemberTypes(typeStr);
|
|
3044
2868
|
const elements = Object.values(element);
|
|
@@ -3063,10 +2887,6 @@ function parseCalldataValue(element, type, structs) {
|
|
|
3063
2887
|
if (Array.isArray(element)) {
|
|
3064
2888
|
throw Error(`Array inside array (nD) are not supported by cairo. Element: ${element} ${type}`);
|
|
3065
2889
|
}
|
|
3066
|
-
if (isTypeUint256(type)) {
|
|
3067
|
-
const el_uint256 = uint256(element);
|
|
3068
|
-
return [felt(el_uint256.low), felt(el_uint256.high)];
|
|
3069
|
-
}
|
|
3070
2890
|
if (structs[type] && structs[type].members.length) {
|
|
3071
2891
|
const { members } = structs[type];
|
|
3072
2892
|
const subElement = element;
|
|
@@ -3084,7 +2904,7 @@ function parseCalldataValue(element, type, structs) {
|
|
|
3084
2904
|
if (typeof element === "object") {
|
|
3085
2905
|
throw Error(`Parameter ${element} do not align with abi parameter ${type}`);
|
|
3086
2906
|
}
|
|
3087
|
-
return
|
|
2907
|
+
return parseBaseTypes(type, element);
|
|
3088
2908
|
}
|
|
3089
2909
|
function parseCalldataField(argsIterator, input, structs) {
|
|
3090
2910
|
const { name, type } = input;
|
|
@@ -3101,25 +2921,36 @@ function parseCalldataField(argsIterator, input, structs) {
|
|
|
3101
2921
|
result.push(felt(value.length));
|
|
3102
2922
|
const arrayType = getArrayType(input.type);
|
|
3103
2923
|
return value.reduce((acc, el) => {
|
|
3104
|
-
if (
|
|
3105
|
-
acc.push(felt(el));
|
|
3106
|
-
} else if (isTypeBool(arrayType) && typeof el === "boolean") {
|
|
3107
|
-
acc.push(el.toString());
|
|
3108
|
-
} else {
|
|
2924
|
+
if (isTypeStruct(arrayType, structs) || isTypeTuple(arrayType) || isTypeArray(arrayType)) {
|
|
3109
2925
|
acc.push(...parseCalldataValue(el, arrayType, structs));
|
|
2926
|
+
} else {
|
|
2927
|
+
return acc.concat(parseBaseTypes(arrayType, el));
|
|
3110
2928
|
}
|
|
3111
2929
|
return acc;
|
|
3112
2930
|
}, result);
|
|
3113
|
-
case (isTypeStruct(type, structs) || isTypeTuple(type)
|
|
2931
|
+
case (isTypeStruct(type, structs) || isTypeTuple(type)):
|
|
3114
2932
|
return parseCalldataValue(value, type, structs);
|
|
3115
|
-
case isTypeBool(type):
|
|
3116
|
-
return `${+value}`;
|
|
3117
2933
|
default:
|
|
3118
|
-
return
|
|
2934
|
+
return parseBaseTypes(type, value);
|
|
3119
2935
|
}
|
|
3120
2936
|
}
|
|
3121
2937
|
|
|
3122
2938
|
// src/utils/calldata/responseParser.ts
|
|
2939
|
+
function parseBaseTypes2(type, it) {
|
|
2940
|
+
let temp;
|
|
2941
|
+
switch (true) {
|
|
2942
|
+
case isTypeBool(type):
|
|
2943
|
+
temp = it.next().value;
|
|
2944
|
+
return Boolean(BigInt(temp));
|
|
2945
|
+
case isTypeUint256(type):
|
|
2946
|
+
const low = it.next().value;
|
|
2947
|
+
const high = it.next().value;
|
|
2948
|
+
return uint256ToBN({ low, high });
|
|
2949
|
+
default:
|
|
2950
|
+
temp = it.next().value;
|
|
2951
|
+
return BigInt(temp);
|
|
2952
|
+
}
|
|
2953
|
+
}
|
|
3123
2954
|
function parseResponseStruct(responseIterator, type, structs) {
|
|
3124
2955
|
if (type in structs && structs[type]) {
|
|
3125
2956
|
return structs[type].members.reduce((acc, el) => {
|
|
@@ -3136,8 +2967,7 @@ function parseResponseStruct(responseIterator, type, structs) {
|
|
|
3136
2967
|
return acc;
|
|
3137
2968
|
}, {});
|
|
3138
2969
|
}
|
|
3139
|
-
|
|
3140
|
-
return BigInt(temp);
|
|
2970
|
+
return parseBaseTypes2(type, responseIterator);
|
|
3141
2971
|
}
|
|
3142
2972
|
function responseParser(responseIterator, output, structs, parsedResult) {
|
|
3143
2973
|
const { name, type } = output;
|
|
@@ -3146,21 +2976,13 @@ function responseParser(responseIterator, output, structs, parsedResult) {
|
|
|
3146
2976
|
case isLen(name):
|
|
3147
2977
|
temp = responseIterator.next().value;
|
|
3148
2978
|
return BigInt(temp);
|
|
3149
|
-
case isTypeBool(type):
|
|
3150
|
-
temp = responseIterator.next().value;
|
|
3151
|
-
return Boolean(BigInt(temp));
|
|
3152
|
-
case isTypeUint256(type):
|
|
3153
|
-
const low = responseIterator.next().value;
|
|
3154
|
-
const high = responseIterator.next().value;
|
|
3155
|
-
return uint256ToBN({ low, high });
|
|
3156
2979
|
case isTypeArray(type):
|
|
3157
2980
|
const parsedDataArr = [];
|
|
3158
2981
|
if (isCairo1Type(type)) {
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
while (
|
|
3162
|
-
parsedDataArr.push(
|
|
3163
|
-
it = responseIterator.next();
|
|
2982
|
+
const arrayType = getArrayType(type);
|
|
2983
|
+
const len = BigInt(responseIterator.next().value);
|
|
2984
|
+
while (parsedDataArr.length < len) {
|
|
2985
|
+
parsedDataArr.push(parseResponseStruct(responseIterator, arrayType, structs));
|
|
3164
2986
|
}
|
|
3165
2987
|
return parsedDataArr;
|
|
3166
2988
|
}
|
|
@@ -3176,8 +2998,7 @@ function responseParser(responseIterator, output, structs, parsedResult) {
|
|
|
3176
2998
|
case (type in structs || isTypeTuple(type)):
|
|
3177
2999
|
return parseResponseStruct(responseIterator, type, structs);
|
|
3178
3000
|
default:
|
|
3179
|
-
|
|
3180
|
-
return BigInt(temp);
|
|
3001
|
+
return parseBaseTypes2(type, responseIterator);
|
|
3181
3002
|
}
|
|
3182
3003
|
}
|
|
3183
3004
|
|
|
@@ -3375,6 +3196,8 @@ var CallData = class {
|
|
|
3375
3196
|
let value = v;
|
|
3376
3197
|
if (isLongText(value))
|
|
3377
3198
|
value = splitLongString(value);
|
|
3199
|
+
if (k === "entrypoint")
|
|
3200
|
+
value = getSelectorFromName(value);
|
|
3378
3201
|
const kk = Array.isArray(oe) && k === "0" ? "$$len" : k;
|
|
3379
3202
|
if (isBigInt(value))
|
|
3380
3203
|
return [[`${prefix}${kk}`, felt(value)]];
|
|
@@ -3428,6 +3251,188 @@ var CallData = class {
|
|
|
3428
3251
|
{}
|
|
3429
3252
|
);
|
|
3430
3253
|
}
|
|
3254
|
+
static toCalldata(rawCalldata = []) {
|
|
3255
|
+
return CallData.compile(rawCalldata);
|
|
3256
|
+
}
|
|
3257
|
+
static toHex(rawCalldata = []) {
|
|
3258
|
+
const calldata = CallData.compile(rawCalldata);
|
|
3259
|
+
return calldata.map((it) => toHex(it));
|
|
3260
|
+
}
|
|
3261
|
+
};
|
|
3262
|
+
|
|
3263
|
+
// src/utils/fetchPonyfill.ts
|
|
3264
|
+
import isomorphicFetch from "isomorphic-fetch";
|
|
3265
|
+
var fetchPonyfill_default = typeof window !== "undefined" && window.fetch || typeof global !== "undefined" && global.fetch || isomorphicFetch;
|
|
3266
|
+
|
|
3267
|
+
// src/utils/contract.ts
|
|
3268
|
+
function isSierra(contract) {
|
|
3269
|
+
const compiledContract = typeof contract === "string" ? parse2(contract) : contract;
|
|
3270
|
+
return "sierra_program" in compiledContract;
|
|
3271
|
+
}
|
|
3272
|
+
function extractContractHashes(payload) {
|
|
3273
|
+
const response = { ...payload };
|
|
3274
|
+
if (isSierra(payload.contract)) {
|
|
3275
|
+
if (!payload.compiledClassHash && payload.casm) {
|
|
3276
|
+
response.compiledClassHash = computeCompiledClassHash(payload.casm);
|
|
3277
|
+
}
|
|
3278
|
+
if (!response.compiledClassHash)
|
|
3279
|
+
throw new Error(
|
|
3280
|
+
"Extract compiledClassHash failed, provide (CairoAssembly).casm file or compiledClassHash"
|
|
3281
|
+
);
|
|
3282
|
+
}
|
|
3283
|
+
response.classHash = payload.classHash ?? computeContractClassHash(payload.contract);
|
|
3284
|
+
if (!response.classHash)
|
|
3285
|
+
throw new Error("Extract classHash failed, provide (CompiledContract).json file or classHash");
|
|
3286
|
+
return response;
|
|
3287
|
+
}
|
|
3288
|
+
|
|
3289
|
+
// src/utils/stark.ts
|
|
3290
|
+
var stark_exports = {};
|
|
3291
|
+
__export(stark_exports, {
|
|
3292
|
+
compressProgram: () => compressProgram,
|
|
3293
|
+
estimatedFeeToMaxFee: () => estimatedFeeToMaxFee,
|
|
3294
|
+
formatSignature: () => formatSignature,
|
|
3295
|
+
makeAddress: () => makeAddress,
|
|
3296
|
+
randomAddress: () => randomAddress,
|
|
3297
|
+
signatureToDecimalArray: () => signatureToDecimalArray,
|
|
3298
|
+
signatureToHexArray: () => signatureToHexArray
|
|
3299
|
+
});
|
|
3300
|
+
import { getStarkKey, utils } from "micro-starknet";
|
|
3301
|
+
import { gzip } from "pako";
|
|
3302
|
+
function compressProgram(jsonProgram) {
|
|
3303
|
+
const stringified = typeof jsonProgram === "string" ? jsonProgram : stringify2(jsonProgram);
|
|
3304
|
+
const compressedProgram = gzip(stringified);
|
|
3305
|
+
return btoaUniversal(compressedProgram);
|
|
3306
|
+
}
|
|
3307
|
+
function randomAddress() {
|
|
3308
|
+
const randomKeyPair = utils.randomPrivateKey();
|
|
3309
|
+
return getStarkKey(randomKeyPair);
|
|
3310
|
+
}
|
|
3311
|
+
function makeAddress(input) {
|
|
3312
|
+
return addHexPrefix(input).toLowerCase();
|
|
3313
|
+
}
|
|
3314
|
+
function formatSignature(sig) {
|
|
3315
|
+
if (!sig)
|
|
3316
|
+
throw Error("formatSignature: provided signature is undefined");
|
|
3317
|
+
if (Array.isArray(sig)) {
|
|
3318
|
+
return sig.map((it) => toHex(it));
|
|
3319
|
+
}
|
|
3320
|
+
try {
|
|
3321
|
+
const { r, s } = sig;
|
|
3322
|
+
return [toHex(r), toHex(s)];
|
|
3323
|
+
} catch (e) {
|
|
3324
|
+
throw new Error("Signature need to be weierstrass.SignatureType or an array for custom");
|
|
3325
|
+
}
|
|
3326
|
+
}
|
|
3327
|
+
function signatureToDecimalArray(sig) {
|
|
3328
|
+
return bigNumberishArrayToDecimalStringArray(formatSignature(sig));
|
|
3329
|
+
}
|
|
3330
|
+
function signatureToHexArray(sig) {
|
|
3331
|
+
return bigNumberishArrayToHexadecimalStringArray(formatSignature(sig));
|
|
3332
|
+
}
|
|
3333
|
+
function estimatedFeeToMaxFee(estimatedFee, overhead = 0.5) {
|
|
3334
|
+
const overHeadPercent = Math.round((1 + overhead) * 100);
|
|
3335
|
+
return toBigInt(estimatedFee) * toBigInt(overHeadPercent) / 100n;
|
|
3336
|
+
}
|
|
3337
|
+
|
|
3338
|
+
// src/utils/provider.ts
|
|
3339
|
+
function wait(delay) {
|
|
3340
|
+
return new Promise((res) => {
|
|
3341
|
+
setTimeout(res, delay);
|
|
3342
|
+
});
|
|
3343
|
+
}
|
|
3344
|
+
function createSierraContractClass(contract) {
|
|
3345
|
+
const result = { ...contract };
|
|
3346
|
+
delete result.sierra_program_debug_info;
|
|
3347
|
+
result.abi = formatSpaces(stringify2(contract.abi));
|
|
3348
|
+
result.sierra_program = formatSpaces(stringify2(contract.sierra_program));
|
|
3349
|
+
result.sierra_program = compressProgram(result.sierra_program);
|
|
3350
|
+
return result;
|
|
3351
|
+
}
|
|
3352
|
+
function parseContract(contract) {
|
|
3353
|
+
const parsedContract = typeof contract === "string" ? parse2(contract) : contract;
|
|
3354
|
+
if (!isSierra(contract)) {
|
|
3355
|
+
return {
|
|
3356
|
+
...parsedContract,
|
|
3357
|
+
..."program" in parsedContract && { program: compressProgram(parsedContract.program) }
|
|
3358
|
+
};
|
|
3359
|
+
}
|
|
3360
|
+
return createSierraContractClass(parsedContract);
|
|
3361
|
+
}
|
|
3362
|
+
|
|
3363
|
+
// src/utils/responseParser/rpc.ts
|
|
3364
|
+
var RPCResponseParser = class {
|
|
3365
|
+
parseGetBlockResponse(res) {
|
|
3366
|
+
return {
|
|
3367
|
+
timestamp: res.timestamp,
|
|
3368
|
+
block_hash: res.block_hash,
|
|
3369
|
+
block_number: res.block_number,
|
|
3370
|
+
new_root: res.new_root,
|
|
3371
|
+
parent_hash: res.parent_hash,
|
|
3372
|
+
status: res.status,
|
|
3373
|
+
transactions: res.transactions
|
|
3374
|
+
};
|
|
3375
|
+
}
|
|
3376
|
+
parseGetTransactionResponse(res) {
|
|
3377
|
+
return {
|
|
3378
|
+
calldata: res.calldata || [],
|
|
3379
|
+
contract_address: res.contract_address,
|
|
3380
|
+
sender_address: res.contract_address,
|
|
3381
|
+
max_fee: res.max_fee,
|
|
3382
|
+
nonce: res.nonce,
|
|
3383
|
+
signature: res.signature || [],
|
|
3384
|
+
transaction_hash: res.transaction_hash,
|
|
3385
|
+
version: res.version
|
|
3386
|
+
};
|
|
3387
|
+
}
|
|
3388
|
+
parseFeeEstimateResponse(res) {
|
|
3389
|
+
return {
|
|
3390
|
+
overall_fee: toBigInt(res.overall_fee),
|
|
3391
|
+
gas_consumed: toBigInt(res.gas_consumed),
|
|
3392
|
+
gas_price: toBigInt(res.gas_price)
|
|
3393
|
+
};
|
|
3394
|
+
}
|
|
3395
|
+
parseCallContractResponse(res) {
|
|
3396
|
+
return {
|
|
3397
|
+
result: res
|
|
3398
|
+
};
|
|
3399
|
+
}
|
|
3400
|
+
};
|
|
3401
|
+
|
|
3402
|
+
// src/provider/errors.ts
|
|
3403
|
+
function fixStack(target, fn = target.constructor) {
|
|
3404
|
+
const { captureStackTrace } = Error;
|
|
3405
|
+
captureStackTrace && captureStackTrace(target, fn);
|
|
3406
|
+
}
|
|
3407
|
+
function fixProto(target, prototype) {
|
|
3408
|
+
const { setPrototypeOf } = Object;
|
|
3409
|
+
setPrototypeOf ? setPrototypeOf(target, prototype) : target.__proto__ = prototype;
|
|
3410
|
+
}
|
|
3411
|
+
var CustomError = class extends Error {
|
|
3412
|
+
constructor(message) {
|
|
3413
|
+
super(message);
|
|
3414
|
+
Object.defineProperty(this, "name", {
|
|
3415
|
+
value: new.target.name,
|
|
3416
|
+
enumerable: false,
|
|
3417
|
+
configurable: true
|
|
3418
|
+
});
|
|
3419
|
+
fixProto(this, new.target.prototype);
|
|
3420
|
+
fixStack(this);
|
|
3421
|
+
}
|
|
3422
|
+
};
|
|
3423
|
+
var LibraryError = class extends CustomError {
|
|
3424
|
+
};
|
|
3425
|
+
var GatewayError = class extends LibraryError {
|
|
3426
|
+
constructor(message, errorCode) {
|
|
3427
|
+
super(message);
|
|
3428
|
+
this.errorCode = errorCode;
|
|
3429
|
+
}
|
|
3430
|
+
};
|
|
3431
|
+
var HttpError = class extends LibraryError {
|
|
3432
|
+
constructor(message, errorCode) {
|
|
3433
|
+
super(message);
|
|
3434
|
+
this.errorCode = errorCode;
|
|
3435
|
+
}
|
|
3431
3436
|
};
|
|
3432
3437
|
|
|
3433
3438
|
// src/utils/starknetId.ts
|
|
@@ -3760,7 +3765,7 @@ var RpcProvider = class {
|
|
|
3760
3765
|
request: {
|
|
3761
3766
|
type: RPC.TransactionType.INVOKE,
|
|
3762
3767
|
sender_address: invocation.contractAddress,
|
|
3763
|
-
calldata:
|
|
3768
|
+
calldata: CallData.toHex(invocation.calldata),
|
|
3764
3769
|
signature: signatureToHexArray(invocation.signature),
|
|
3765
3770
|
version: toHex((invocationDetails == null ? void 0 : invocationDetails.version) || 0),
|
|
3766
3771
|
nonce: toHex(invocationDetails.nonce),
|
|
@@ -3848,7 +3853,7 @@ var RpcProvider = class {
|
|
|
3848
3853
|
return this.fetchEndpoint("starknet_addInvokeTransaction", {
|
|
3849
3854
|
invoke_transaction: {
|
|
3850
3855
|
sender_address: functionInvocation.contractAddress,
|
|
3851
|
-
calldata:
|
|
3856
|
+
calldata: CallData.toHex(functionInvocation.calldata),
|
|
3852
3857
|
type: RPC.TransactionType.INVOKE,
|
|
3853
3858
|
max_fee: toHex(details.maxFee || 0),
|
|
3854
3859
|
version: "0x1",
|
|
@@ -3863,7 +3868,7 @@ var RpcProvider = class {
|
|
|
3863
3868
|
request: {
|
|
3864
3869
|
contract_address: call.contractAddress,
|
|
3865
3870
|
entry_point_selector: getSelectorFromName(call.entrypoint),
|
|
3866
|
-
calldata:
|
|
3871
|
+
calldata: CallData.toHex(call.calldata)
|
|
3867
3872
|
},
|
|
3868
3873
|
block_id
|
|
3869
3874
|
});
|
|
@@ -4333,7 +4338,7 @@ var SequencerProvider = class {
|
|
|
4333
4338
|
return this.fetchEndpoint("add_transaction", void 0, {
|
|
4334
4339
|
type: "INVOKE_FUNCTION" /* INVOKE */,
|
|
4335
4340
|
sender_address: functionInvocation.contractAddress,
|
|
4336
|
-
calldata:
|
|
4341
|
+
calldata: CallData.compile(functionInvocation.calldata ?? []),
|
|
4337
4342
|
signature: signatureToDecimalArray(functionInvocation.signature),
|
|
4338
4343
|
nonce: toHex(details.nonce),
|
|
4339
4344
|
max_fee: toHex(details.maxFee || 0),
|
|
@@ -4344,7 +4349,7 @@ var SequencerProvider = class {
|
|
|
4344
4349
|
return this.fetchEndpoint("add_transaction", void 0, {
|
|
4345
4350
|
type: "DEPLOY_ACCOUNT" /* DEPLOY_ACCOUNT */,
|
|
4346
4351
|
contract_address_salt: addressSalt ?? randomAddress(),
|
|
4347
|
-
constructor_calldata:
|
|
4352
|
+
constructor_calldata: CallData.compile(constructorCalldata ?? []),
|
|
4348
4353
|
class_hash: toHex(classHash),
|
|
4349
4354
|
max_fee: toHex(details.maxFee || 0),
|
|
4350
4355
|
version: toHex(details.version || 0),
|
|
@@ -4428,7 +4433,7 @@ var SequencerProvider = class {
|
|
|
4428
4433
|
{
|
|
4429
4434
|
type: "DEPLOY_ACCOUNT" /* DEPLOY_ACCOUNT */,
|
|
4430
4435
|
class_hash: toHex(classHash),
|
|
4431
|
-
constructor_calldata:
|
|
4436
|
+
constructor_calldata: CallData.compile(constructorCalldata || []),
|
|
4432
4437
|
contract_address_salt: toHex(addressSalt || 0),
|
|
4433
4438
|
signature: signatureToDecimalArray(signature),
|
|
4434
4439
|
version: toHex((details == null ? void 0 : details.version) || 0),
|
|
@@ -4455,9 +4460,7 @@ var SequencerProvider = class {
|
|
|
4455
4460
|
res = {
|
|
4456
4461
|
type: invocation.type,
|
|
4457
4462
|
class_hash: toHex(toBigInt(invocation.classHash)),
|
|
4458
|
-
constructor_calldata:
|
|
4459
|
-
invocation.constructorCalldata || []
|
|
4460
|
-
),
|
|
4463
|
+
constructor_calldata: CallData.compile(invocation.constructorCalldata || []),
|
|
4461
4464
|
contract_address_salt: toHex(toBigInt(invocation.addressSalt || 0))
|
|
4462
4465
|
};
|
|
4463
4466
|
}
|
|
@@ -4952,19 +4955,13 @@ var transformCallsToMulticallArrays = (calls) => {
|
|
|
4952
4955
|
});
|
|
4953
4956
|
return {
|
|
4954
4957
|
callArray,
|
|
4955
|
-
calldata:
|
|
4958
|
+
calldata: CallData.compile({ calldata })
|
|
4956
4959
|
};
|
|
4957
4960
|
};
|
|
4958
4961
|
var fromCallsToExecuteCalldata = (calls) => {
|
|
4959
4962
|
const { callArray, calldata } = transformCallsToMulticallArrays(calls);
|
|
4960
|
-
|
|
4961
|
-
|
|
4962
|
-
...callArray.map(
|
|
4963
|
-
({ to, selector, data_offset, data_len }) => [to, selector, data_offset, data_len]
|
|
4964
|
-
).flat(),
|
|
4965
|
-
calldata.length.toString(),
|
|
4966
|
-
...calldata
|
|
4967
|
-
];
|
|
4963
|
+
const compiledCalls = CallData.compile({ callArray });
|
|
4964
|
+
return [...compiledCalls, ...calldata];
|
|
4968
4965
|
};
|
|
4969
4966
|
var fromCallsToExecuteCalldataWithNonce = (calls, nonce) => {
|
|
4970
4967
|
return [...fromCallsToExecuteCalldata(calls), toBigInt(nonce).toString()];
|
|
@@ -4973,20 +4970,16 @@ var transformCallsToMulticallArrays_cairo1 = (calls) => {
|
|
|
4973
4970
|
const callArray = calls.map((call) => ({
|
|
4974
4971
|
to: toBigInt(call.contractAddress).toString(10),
|
|
4975
4972
|
selector: toBigInt(getSelectorFromName(call.entrypoint)).toString(10),
|
|
4976
|
-
calldata:
|
|
4973
|
+
calldata: CallData.compile(call.calldata || [])
|
|
4977
4974
|
}));
|
|
4978
4975
|
return callArray;
|
|
4979
4976
|
};
|
|
4980
4977
|
var fromCallsToExecuteCalldata_cairo1 = (calls) => {
|
|
4981
|
-
|
|
4982
|
-
return [
|
|
4983
|
-
callArray.length.toString(),
|
|
4984
|
-
...callArray.map(({ to, selector, calldata }) => [to, selector, calldata.length.toString(), ...calldata]).flat()
|
|
4985
|
-
];
|
|
4978
|
+
return CallData.compile({ calls });
|
|
4986
4979
|
};
|
|
4987
4980
|
var getExecuteCalldata = (calls, cairoVersion = "0") => {
|
|
4988
4981
|
if (cairoVersion === "1") {
|
|
4989
|
-
return
|
|
4982
|
+
return CallData.compile({ calls });
|
|
4990
4983
|
}
|
|
4991
4984
|
return fromCallsToExecuteCalldata(calls);
|
|
4992
4985
|
};
|
|
@@ -5592,7 +5585,8 @@ var Account = class extends Provider {
|
|
|
5592
5585
|
const version = toBigInt(transactionVersion);
|
|
5593
5586
|
const nonce = ZERO;
|
|
5594
5587
|
const chainId = await this.getChainId();
|
|
5595
|
-
const
|
|
5588
|
+
const compiledCalldata = CallData.compile(constructorCalldata);
|
|
5589
|
+
const contractAddress = providedContractAddress ?? calculateContractAddressFromHash(addressSalt, classHash, compiledCalldata, 0);
|
|
5596
5590
|
const maxFee = transactionsDetail.maxFee ?? await this.getSuggestedMaxFee(
|
|
5597
5591
|
{
|
|
5598
5592
|
type: "DEPLOY_ACCOUNT" /* DEPLOY_ACCOUNT */,
|
|
@@ -5690,7 +5684,8 @@ var Account = class extends Provider {
|
|
|
5690
5684
|
constructorCalldata = [],
|
|
5691
5685
|
contractAddress: providedContractAddress
|
|
5692
5686
|
}, { nonce, chainId, version, maxFee }) {
|
|
5693
|
-
const
|
|
5687
|
+
const compiledCalldata = CallData.compile(constructorCalldata);
|
|
5688
|
+
const contractAddress = providedContractAddress ?? calculateContractAddressFromHash(addressSalt, classHash, compiledCalldata, 0);
|
|
5694
5689
|
const signature = await this.signer.signDeployAccountTransaction({
|
|
5695
5690
|
classHash,
|
|
5696
5691
|
contractAddress,
|