starknet 5.8.0 → 5.9.1
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 +15 -0
- package/dist/index.d.ts +40 -17
- package/dist/index.global.js +6820 -5610
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +252 -251
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +252 -251
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -114,9 +114,12 @@ var RPC;
|
|
|
114
114
|
})(TransactionType2 = RPC2.TransactionType || (RPC2.TransactionType = {}));
|
|
115
115
|
})(RPC || (RPC = {}));
|
|
116
116
|
|
|
117
|
-
// src/utils/
|
|
118
|
-
|
|
119
|
-
|
|
117
|
+
// src/utils/assert.ts
|
|
118
|
+
function assert(condition, message) {
|
|
119
|
+
if (!condition) {
|
|
120
|
+
throw new Error(message || "Assertion failure");
|
|
121
|
+
}
|
|
122
|
+
}
|
|
120
123
|
|
|
121
124
|
// src/utils/hash.ts
|
|
122
125
|
var hash_exports = {};
|
|
@@ -2342,15 +2345,6 @@ __export(num_exports, {
|
|
|
2342
2345
|
toHexString: () => toHexString
|
|
2343
2346
|
});
|
|
2344
2347
|
var import_utils = require("@noble/curves/abstract/utils");
|
|
2345
|
-
|
|
2346
|
-
// src/utils/assert.ts
|
|
2347
|
-
function assert(condition, message) {
|
|
2348
|
-
if (!condition) {
|
|
2349
|
-
throw new Error(message || "Assertion failure");
|
|
2350
|
-
}
|
|
2351
|
-
}
|
|
2352
|
-
|
|
2353
|
-
// src/utils/num.ts
|
|
2354
2348
|
function isHex(hex) {
|
|
2355
2349
|
return /^0x[0-9a-f]*$/i.test(hex);
|
|
2356
2350
|
}
|
|
@@ -2814,185 +2808,6 @@ function computeContractClassHash(contract) {
|
|
|
2814
2808
|
return computeLegacyContractClassHash(compiledContract);
|
|
2815
2809
|
}
|
|
2816
2810
|
|
|
2817
|
-
// src/utils/contract.ts
|
|
2818
|
-
function isSierra(contract) {
|
|
2819
|
-
const compiledContract = typeof contract === "string" ? parse2(contract) : contract;
|
|
2820
|
-
return "sierra_program" in compiledContract;
|
|
2821
|
-
}
|
|
2822
|
-
function extractContractHashes(payload) {
|
|
2823
|
-
const response = { ...payload };
|
|
2824
|
-
if (isSierra(payload.contract)) {
|
|
2825
|
-
if (!payload.compiledClassHash && payload.casm) {
|
|
2826
|
-
response.compiledClassHash = computeCompiledClassHash(payload.casm);
|
|
2827
|
-
}
|
|
2828
|
-
if (!response.compiledClassHash)
|
|
2829
|
-
throw new Error(
|
|
2830
|
-
"Extract compiledClassHash failed, provide (CairoAssembly).casm file or compiledClassHash"
|
|
2831
|
-
);
|
|
2832
|
-
}
|
|
2833
|
-
response.classHash = payload.classHash ?? computeContractClassHash(payload.contract);
|
|
2834
|
-
if (!response.classHash)
|
|
2835
|
-
throw new Error("Extract classHash failed, provide (CompiledContract).json file or classHash");
|
|
2836
|
-
return response;
|
|
2837
|
-
}
|
|
2838
|
-
|
|
2839
|
-
// src/utils/stark.ts
|
|
2840
|
-
var stark_exports = {};
|
|
2841
|
-
__export(stark_exports, {
|
|
2842
|
-
compressProgram: () => compressProgram,
|
|
2843
|
-
estimatedFeeToMaxFee: () => estimatedFeeToMaxFee,
|
|
2844
|
-
formatSignature: () => formatSignature,
|
|
2845
|
-
makeAddress: () => makeAddress,
|
|
2846
|
-
randomAddress: () => randomAddress,
|
|
2847
|
-
signatureToDecimalArray: () => signatureToDecimalArray,
|
|
2848
|
-
signatureToHexArray: () => signatureToHexArray
|
|
2849
|
-
});
|
|
2850
|
-
var import_micro_starknet2 = require("micro-starknet");
|
|
2851
|
-
var import_pako = require("pako");
|
|
2852
|
-
function compressProgram(jsonProgram) {
|
|
2853
|
-
const stringified = typeof jsonProgram === "string" ? jsonProgram : stringify2(jsonProgram);
|
|
2854
|
-
const compressedProgram = (0, import_pako.gzip)(stringified);
|
|
2855
|
-
return btoaUniversal(compressedProgram);
|
|
2856
|
-
}
|
|
2857
|
-
function randomAddress() {
|
|
2858
|
-
const randomKeyPair = import_micro_starknet2.utils.randomPrivateKey();
|
|
2859
|
-
return (0, import_micro_starknet2.getStarkKey)(randomKeyPair);
|
|
2860
|
-
}
|
|
2861
|
-
function makeAddress(input) {
|
|
2862
|
-
return addHexPrefix(input).toLowerCase();
|
|
2863
|
-
}
|
|
2864
|
-
function formatSignature(sig) {
|
|
2865
|
-
if (!sig)
|
|
2866
|
-
throw Error("formatSignature: provided signature is undefined");
|
|
2867
|
-
if (Array.isArray(sig)) {
|
|
2868
|
-
return sig.map((it) => toHex(it));
|
|
2869
|
-
}
|
|
2870
|
-
try {
|
|
2871
|
-
const { r, s } = sig;
|
|
2872
|
-
return [toHex(r), toHex(s)];
|
|
2873
|
-
} catch (e) {
|
|
2874
|
-
throw new Error("Signature need to be weierstrass.SignatureType or an array for custom");
|
|
2875
|
-
}
|
|
2876
|
-
}
|
|
2877
|
-
function signatureToDecimalArray(sig) {
|
|
2878
|
-
return bigNumberishArrayToDecimalStringArray(formatSignature(sig));
|
|
2879
|
-
}
|
|
2880
|
-
function signatureToHexArray(sig) {
|
|
2881
|
-
return bigNumberishArrayToHexadecimalStringArray(formatSignature(sig));
|
|
2882
|
-
}
|
|
2883
|
-
function estimatedFeeToMaxFee(estimatedFee, overhead = 0.5) {
|
|
2884
|
-
const overHeadPercent = Math.round((1 + overhead) * 100);
|
|
2885
|
-
return toBigInt(estimatedFee) * toBigInt(overHeadPercent) / 100n;
|
|
2886
|
-
}
|
|
2887
|
-
|
|
2888
|
-
// src/utils/provider.ts
|
|
2889
|
-
function wait(delay) {
|
|
2890
|
-
return new Promise((res) => {
|
|
2891
|
-
setTimeout(res, delay);
|
|
2892
|
-
});
|
|
2893
|
-
}
|
|
2894
|
-
function parseCalldata(calldata = []) {
|
|
2895
|
-
return calldata.map((data) => {
|
|
2896
|
-
if (typeof data === "string" && isHex(data)) {
|
|
2897
|
-
return data;
|
|
2898
|
-
}
|
|
2899
|
-
return toHex(data);
|
|
2900
|
-
});
|
|
2901
|
-
}
|
|
2902
|
-
function createSierraContractClass(contract) {
|
|
2903
|
-
const result = { ...contract };
|
|
2904
|
-
delete result.sierra_program_debug_info;
|
|
2905
|
-
result.abi = formatSpaces(stringify2(contract.abi));
|
|
2906
|
-
result.sierra_program = formatSpaces(stringify2(contract.sierra_program));
|
|
2907
|
-
result.sierra_program = compressProgram(result.sierra_program);
|
|
2908
|
-
return result;
|
|
2909
|
-
}
|
|
2910
|
-
function parseContract(contract) {
|
|
2911
|
-
const parsedContract = typeof contract === "string" ? parse2(contract) : contract;
|
|
2912
|
-
if (!isSierra(contract)) {
|
|
2913
|
-
return {
|
|
2914
|
-
...parsedContract,
|
|
2915
|
-
..."program" in parsedContract && { program: compressProgram(parsedContract.program) }
|
|
2916
|
-
};
|
|
2917
|
-
}
|
|
2918
|
-
return createSierraContractClass(parsedContract);
|
|
2919
|
-
}
|
|
2920
|
-
|
|
2921
|
-
// src/utils/responseParser/rpc.ts
|
|
2922
|
-
var RPCResponseParser = class {
|
|
2923
|
-
parseGetBlockResponse(res) {
|
|
2924
|
-
return {
|
|
2925
|
-
timestamp: res.timestamp,
|
|
2926
|
-
block_hash: res.block_hash,
|
|
2927
|
-
block_number: res.block_number,
|
|
2928
|
-
new_root: res.new_root,
|
|
2929
|
-
parent_hash: res.parent_hash,
|
|
2930
|
-
status: res.status,
|
|
2931
|
-
transactions: res.transactions
|
|
2932
|
-
};
|
|
2933
|
-
}
|
|
2934
|
-
parseGetTransactionResponse(res) {
|
|
2935
|
-
return {
|
|
2936
|
-
calldata: res.calldata || [],
|
|
2937
|
-
contract_address: res.contract_address,
|
|
2938
|
-
sender_address: res.contract_address,
|
|
2939
|
-
max_fee: res.max_fee,
|
|
2940
|
-
nonce: res.nonce,
|
|
2941
|
-
signature: res.signature || [],
|
|
2942
|
-
transaction_hash: res.transaction_hash,
|
|
2943
|
-
version: res.version
|
|
2944
|
-
};
|
|
2945
|
-
}
|
|
2946
|
-
parseFeeEstimateResponse(res) {
|
|
2947
|
-
return {
|
|
2948
|
-
overall_fee: toBigInt(res.overall_fee),
|
|
2949
|
-
gas_consumed: toBigInt(res.gas_consumed),
|
|
2950
|
-
gas_price: toBigInt(res.gas_price)
|
|
2951
|
-
};
|
|
2952
|
-
}
|
|
2953
|
-
parseCallContractResponse(res) {
|
|
2954
|
-
return {
|
|
2955
|
-
result: res
|
|
2956
|
-
};
|
|
2957
|
-
}
|
|
2958
|
-
};
|
|
2959
|
-
|
|
2960
|
-
// src/provider/errors.ts
|
|
2961
|
-
function fixStack(target, fn = target.constructor) {
|
|
2962
|
-
const { captureStackTrace } = Error;
|
|
2963
|
-
captureStackTrace && captureStackTrace(target, fn);
|
|
2964
|
-
}
|
|
2965
|
-
function fixProto(target, prototype) {
|
|
2966
|
-
const { setPrototypeOf } = Object;
|
|
2967
|
-
setPrototypeOf ? setPrototypeOf(target, prototype) : target.__proto__ = prototype;
|
|
2968
|
-
}
|
|
2969
|
-
var CustomError = class extends Error {
|
|
2970
|
-
constructor(message) {
|
|
2971
|
-
super(message);
|
|
2972
|
-
Object.defineProperty(this, "name", {
|
|
2973
|
-
value: new.target.name,
|
|
2974
|
-
enumerable: false,
|
|
2975
|
-
configurable: true
|
|
2976
|
-
});
|
|
2977
|
-
fixProto(this, new.target.prototype);
|
|
2978
|
-
fixStack(this);
|
|
2979
|
-
}
|
|
2980
|
-
};
|
|
2981
|
-
var LibraryError = class extends CustomError {
|
|
2982
|
-
};
|
|
2983
|
-
var GatewayError = class extends LibraryError {
|
|
2984
|
-
constructor(message, errorCode) {
|
|
2985
|
-
super(message);
|
|
2986
|
-
this.errorCode = errorCode;
|
|
2987
|
-
}
|
|
2988
|
-
};
|
|
2989
|
-
var HttpError = class extends LibraryError {
|
|
2990
|
-
constructor(message, errorCode) {
|
|
2991
|
-
super(message);
|
|
2992
|
-
this.errorCode = errorCode;
|
|
2993
|
-
}
|
|
2994
|
-
};
|
|
2995
|
-
|
|
2996
2811
|
// src/utils/calldata/formatter.ts
|
|
2997
2812
|
var guard = {
|
|
2998
2813
|
isBN: (data, type, key) => {
|
|
@@ -3110,6 +2925,15 @@ function extractTupleMemberTypes(type) {
|
|
|
3110
2925
|
}
|
|
3111
2926
|
|
|
3112
2927
|
// src/utils/calldata/requestParser.ts
|
|
2928
|
+
function parseBaseTypes(type, val) {
|
|
2929
|
+
switch (true) {
|
|
2930
|
+
case isTypeUint256(type):
|
|
2931
|
+
const el_uint256 = uint256(val);
|
|
2932
|
+
return [felt(el_uint256.low), felt(el_uint256.high)];
|
|
2933
|
+
default:
|
|
2934
|
+
return felt(val);
|
|
2935
|
+
}
|
|
2936
|
+
}
|
|
3113
2937
|
function parseTuple(element, typeStr) {
|
|
3114
2938
|
const memberTypes = extractTupleMemberTypes(typeStr);
|
|
3115
2939
|
const elements = Object.values(element);
|
|
@@ -3134,10 +2958,6 @@ function parseCalldataValue(element, type, structs) {
|
|
|
3134
2958
|
if (Array.isArray(element)) {
|
|
3135
2959
|
throw Error(`Array inside array (nD) are not supported by cairo. Element: ${element} ${type}`);
|
|
3136
2960
|
}
|
|
3137
|
-
if (isTypeUint256(type)) {
|
|
3138
|
-
const el_uint256 = uint256(element);
|
|
3139
|
-
return [felt(el_uint256.low), felt(el_uint256.high)];
|
|
3140
|
-
}
|
|
3141
2961
|
if (structs[type] && structs[type].members.length) {
|
|
3142
2962
|
const { members } = structs[type];
|
|
3143
2963
|
const subElement = element;
|
|
@@ -3155,7 +2975,7 @@ function parseCalldataValue(element, type, structs) {
|
|
|
3155
2975
|
if (typeof element === "object") {
|
|
3156
2976
|
throw Error(`Parameter ${element} do not align with abi parameter ${type}`);
|
|
3157
2977
|
}
|
|
3158
|
-
return
|
|
2978
|
+
return parseBaseTypes(type, element);
|
|
3159
2979
|
}
|
|
3160
2980
|
function parseCalldataField(argsIterator, input, structs) {
|
|
3161
2981
|
const { name, type } = input;
|
|
@@ -3172,25 +2992,42 @@ function parseCalldataField(argsIterator, input, structs) {
|
|
|
3172
2992
|
result.push(felt(value.length));
|
|
3173
2993
|
const arrayType = getArrayType(input.type);
|
|
3174
2994
|
return value.reduce((acc, el) => {
|
|
3175
|
-
if (
|
|
3176
|
-
acc.push(felt(el));
|
|
3177
|
-
} else if (isTypeBool(arrayType) && typeof el === "boolean") {
|
|
3178
|
-
acc.push(el.toString());
|
|
3179
|
-
} else {
|
|
2995
|
+
if (isTypeStruct(arrayType, structs) || isTypeTuple(arrayType) || isTypeArray(arrayType)) {
|
|
3180
2996
|
acc.push(...parseCalldataValue(el, arrayType, structs));
|
|
2997
|
+
} else {
|
|
2998
|
+
return acc.concat(parseBaseTypes(arrayType, el));
|
|
3181
2999
|
}
|
|
3182
3000
|
return acc;
|
|
3183
3001
|
}, result);
|
|
3184
|
-
case (isTypeStruct(type, structs) || isTypeTuple(type)
|
|
3002
|
+
case (isTypeStruct(type, structs) || isTypeTuple(type)):
|
|
3185
3003
|
return parseCalldataValue(value, type, structs);
|
|
3186
|
-
case
|
|
3187
|
-
|
|
3004
|
+
case isTypeUint256(type):
|
|
3005
|
+
if (typeof value === "object") {
|
|
3006
|
+
return [felt(value.low), felt(value.high)];
|
|
3007
|
+
}
|
|
3008
|
+
const el_uint256 = uint256(value);
|
|
3009
|
+
return [felt(el_uint256.low), felt(el_uint256.high)];
|
|
3188
3010
|
default:
|
|
3189
|
-
return
|
|
3011
|
+
return parseBaseTypes(type, value);
|
|
3190
3012
|
}
|
|
3191
3013
|
}
|
|
3192
3014
|
|
|
3193
3015
|
// src/utils/calldata/responseParser.ts
|
|
3016
|
+
function parseBaseTypes2(type, it) {
|
|
3017
|
+
let temp;
|
|
3018
|
+
switch (true) {
|
|
3019
|
+
case isTypeBool(type):
|
|
3020
|
+
temp = it.next().value;
|
|
3021
|
+
return Boolean(BigInt(temp));
|
|
3022
|
+
case isTypeUint256(type):
|
|
3023
|
+
const low = it.next().value;
|
|
3024
|
+
const high = it.next().value;
|
|
3025
|
+
return uint256ToBN({ low, high });
|
|
3026
|
+
default:
|
|
3027
|
+
temp = it.next().value;
|
|
3028
|
+
return BigInt(temp);
|
|
3029
|
+
}
|
|
3030
|
+
}
|
|
3194
3031
|
function parseResponseStruct(responseIterator, type, structs) {
|
|
3195
3032
|
if (type in structs && structs[type]) {
|
|
3196
3033
|
return structs[type].members.reduce((acc, el) => {
|
|
@@ -3207,8 +3044,7 @@ function parseResponseStruct(responseIterator, type, structs) {
|
|
|
3207
3044
|
return acc;
|
|
3208
3045
|
}, {});
|
|
3209
3046
|
}
|
|
3210
|
-
|
|
3211
|
-
return BigInt(temp);
|
|
3047
|
+
return parseBaseTypes2(type, responseIterator);
|
|
3212
3048
|
}
|
|
3213
3049
|
function responseParser(responseIterator, output, structs, parsedResult) {
|
|
3214
3050
|
const { name, type } = output;
|
|
@@ -3217,21 +3053,13 @@ function responseParser(responseIterator, output, structs, parsedResult) {
|
|
|
3217
3053
|
case isLen(name):
|
|
3218
3054
|
temp = responseIterator.next().value;
|
|
3219
3055
|
return BigInt(temp);
|
|
3220
|
-
case isTypeBool(type):
|
|
3221
|
-
temp = responseIterator.next().value;
|
|
3222
|
-
return Boolean(BigInt(temp));
|
|
3223
|
-
case isTypeUint256(type):
|
|
3224
|
-
const low = responseIterator.next().value;
|
|
3225
|
-
const high = responseIterator.next().value;
|
|
3226
|
-
return uint256ToBN({ low, high });
|
|
3227
3056
|
case isTypeArray(type):
|
|
3228
3057
|
const parsedDataArr = [];
|
|
3229
3058
|
if (isCairo1Type(type)) {
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
while (
|
|
3233
|
-
parsedDataArr.push(
|
|
3234
|
-
it = responseIterator.next();
|
|
3059
|
+
const arrayType = getArrayType(type);
|
|
3060
|
+
const len = BigInt(responseIterator.next().value);
|
|
3061
|
+
while (parsedDataArr.length < len) {
|
|
3062
|
+
parsedDataArr.push(parseResponseStruct(responseIterator, arrayType, structs));
|
|
3235
3063
|
}
|
|
3236
3064
|
return parsedDataArr;
|
|
3237
3065
|
}
|
|
@@ -3247,8 +3075,7 @@ function responseParser(responseIterator, output, structs, parsedResult) {
|
|
|
3247
3075
|
case (type in structs || isTypeTuple(type)):
|
|
3248
3076
|
return parseResponseStruct(responseIterator, type, structs);
|
|
3249
3077
|
default:
|
|
3250
|
-
|
|
3251
|
-
return BigInt(temp);
|
|
3078
|
+
return parseBaseTypes2(type, responseIterator);
|
|
3252
3079
|
}
|
|
3253
3080
|
}
|
|
3254
3081
|
|
|
@@ -3267,10 +3094,10 @@ var validateUint = (parameter, input) => {
|
|
|
3267
3094
|
);
|
|
3268
3095
|
}
|
|
3269
3096
|
assert(
|
|
3270
|
-
typeof parameter === "string" || typeof parameter === "number" || typeof parameter === "bigint",
|
|
3271
|
-
`Validate: arg ${input.name} of cairo type ${input.type} should be type (String, Number or BigInt)`
|
|
3097
|
+
typeof parameter === "string" || typeof parameter === "number" || typeof parameter === "bigint" || typeof parameter === "object" && "low" in parameter && "high" in parameter,
|
|
3098
|
+
`Validate: arg ${input.name} of cairo ZORG type ${input.type} should be type (String, Number or BigInt)`
|
|
3272
3099
|
);
|
|
3273
|
-
const param = toBigInt(parameter);
|
|
3100
|
+
const param = typeof parameter === "object" ? uint256ToBN(parameter) : toBigInt(parameter);
|
|
3274
3101
|
switch (input.type) {
|
|
3275
3102
|
case "core::integer::u8" /* u8 */:
|
|
3276
3103
|
assert(
|
|
@@ -3446,6 +3273,8 @@ var CallData = class {
|
|
|
3446
3273
|
let value = v;
|
|
3447
3274
|
if (isLongText(value))
|
|
3448
3275
|
value = splitLongString(value);
|
|
3276
|
+
if (k === "entrypoint")
|
|
3277
|
+
value = getSelectorFromName(value);
|
|
3449
3278
|
const kk = Array.isArray(oe) && k === "0" ? "$$len" : k;
|
|
3450
3279
|
if (isBigInt(value))
|
|
3451
3280
|
return [[`${prefix}${kk}`, felt(value)]];
|
|
@@ -3499,6 +3328,188 @@ var CallData = class {
|
|
|
3499
3328
|
{}
|
|
3500
3329
|
);
|
|
3501
3330
|
}
|
|
3331
|
+
static toCalldata(rawCalldata = []) {
|
|
3332
|
+
return CallData.compile(rawCalldata);
|
|
3333
|
+
}
|
|
3334
|
+
static toHex(rawCalldata = []) {
|
|
3335
|
+
const calldata = CallData.compile(rawCalldata);
|
|
3336
|
+
return calldata.map((it) => toHex(it));
|
|
3337
|
+
}
|
|
3338
|
+
};
|
|
3339
|
+
|
|
3340
|
+
// src/utils/fetchPonyfill.ts
|
|
3341
|
+
var import_isomorphic_fetch = __toESM(require("isomorphic-fetch"));
|
|
3342
|
+
var fetchPonyfill_default = typeof window !== "undefined" && window.fetch || typeof global !== "undefined" && global.fetch || import_isomorphic_fetch.default;
|
|
3343
|
+
|
|
3344
|
+
// src/utils/contract.ts
|
|
3345
|
+
function isSierra(contract) {
|
|
3346
|
+
const compiledContract = typeof contract === "string" ? parse2(contract) : contract;
|
|
3347
|
+
return "sierra_program" in compiledContract;
|
|
3348
|
+
}
|
|
3349
|
+
function extractContractHashes(payload) {
|
|
3350
|
+
const response = { ...payload };
|
|
3351
|
+
if (isSierra(payload.contract)) {
|
|
3352
|
+
if (!payload.compiledClassHash && payload.casm) {
|
|
3353
|
+
response.compiledClassHash = computeCompiledClassHash(payload.casm);
|
|
3354
|
+
}
|
|
3355
|
+
if (!response.compiledClassHash)
|
|
3356
|
+
throw new Error(
|
|
3357
|
+
"Extract compiledClassHash failed, provide (CairoAssembly).casm file or compiledClassHash"
|
|
3358
|
+
);
|
|
3359
|
+
}
|
|
3360
|
+
response.classHash = payload.classHash ?? computeContractClassHash(payload.contract);
|
|
3361
|
+
if (!response.classHash)
|
|
3362
|
+
throw new Error("Extract classHash failed, provide (CompiledContract).json file or classHash");
|
|
3363
|
+
return response;
|
|
3364
|
+
}
|
|
3365
|
+
|
|
3366
|
+
// src/utils/stark.ts
|
|
3367
|
+
var stark_exports = {};
|
|
3368
|
+
__export(stark_exports, {
|
|
3369
|
+
compressProgram: () => compressProgram,
|
|
3370
|
+
estimatedFeeToMaxFee: () => estimatedFeeToMaxFee,
|
|
3371
|
+
formatSignature: () => formatSignature,
|
|
3372
|
+
makeAddress: () => makeAddress,
|
|
3373
|
+
randomAddress: () => randomAddress,
|
|
3374
|
+
signatureToDecimalArray: () => signatureToDecimalArray,
|
|
3375
|
+
signatureToHexArray: () => signatureToHexArray
|
|
3376
|
+
});
|
|
3377
|
+
var import_micro_starknet2 = require("micro-starknet");
|
|
3378
|
+
var import_pako = require("pako");
|
|
3379
|
+
function compressProgram(jsonProgram) {
|
|
3380
|
+
const stringified = typeof jsonProgram === "string" ? jsonProgram : stringify2(jsonProgram);
|
|
3381
|
+
const compressedProgram = (0, import_pako.gzip)(stringified);
|
|
3382
|
+
return btoaUniversal(compressedProgram);
|
|
3383
|
+
}
|
|
3384
|
+
function randomAddress() {
|
|
3385
|
+
const randomKeyPair = import_micro_starknet2.utils.randomPrivateKey();
|
|
3386
|
+
return (0, import_micro_starknet2.getStarkKey)(randomKeyPair);
|
|
3387
|
+
}
|
|
3388
|
+
function makeAddress(input) {
|
|
3389
|
+
return addHexPrefix(input).toLowerCase();
|
|
3390
|
+
}
|
|
3391
|
+
function formatSignature(sig) {
|
|
3392
|
+
if (!sig)
|
|
3393
|
+
throw Error("formatSignature: provided signature is undefined");
|
|
3394
|
+
if (Array.isArray(sig)) {
|
|
3395
|
+
return sig.map((it) => toHex(it));
|
|
3396
|
+
}
|
|
3397
|
+
try {
|
|
3398
|
+
const { r, s } = sig;
|
|
3399
|
+
return [toHex(r), toHex(s)];
|
|
3400
|
+
} catch (e) {
|
|
3401
|
+
throw new Error("Signature need to be weierstrass.SignatureType or an array for custom");
|
|
3402
|
+
}
|
|
3403
|
+
}
|
|
3404
|
+
function signatureToDecimalArray(sig) {
|
|
3405
|
+
return bigNumberishArrayToDecimalStringArray(formatSignature(sig));
|
|
3406
|
+
}
|
|
3407
|
+
function signatureToHexArray(sig) {
|
|
3408
|
+
return bigNumberishArrayToHexadecimalStringArray(formatSignature(sig));
|
|
3409
|
+
}
|
|
3410
|
+
function estimatedFeeToMaxFee(estimatedFee, overhead = 0.5) {
|
|
3411
|
+
const overHeadPercent = Math.round((1 + overhead) * 100);
|
|
3412
|
+
return toBigInt(estimatedFee) * toBigInt(overHeadPercent) / 100n;
|
|
3413
|
+
}
|
|
3414
|
+
|
|
3415
|
+
// src/utils/provider.ts
|
|
3416
|
+
function wait(delay) {
|
|
3417
|
+
return new Promise((res) => {
|
|
3418
|
+
setTimeout(res, delay);
|
|
3419
|
+
});
|
|
3420
|
+
}
|
|
3421
|
+
function createSierraContractClass(contract) {
|
|
3422
|
+
const result = { ...contract };
|
|
3423
|
+
delete result.sierra_program_debug_info;
|
|
3424
|
+
result.abi = formatSpaces(stringify2(contract.abi));
|
|
3425
|
+
result.sierra_program = formatSpaces(stringify2(contract.sierra_program));
|
|
3426
|
+
result.sierra_program = compressProgram(result.sierra_program);
|
|
3427
|
+
return result;
|
|
3428
|
+
}
|
|
3429
|
+
function parseContract(contract) {
|
|
3430
|
+
const parsedContract = typeof contract === "string" ? parse2(contract) : contract;
|
|
3431
|
+
if (!isSierra(contract)) {
|
|
3432
|
+
return {
|
|
3433
|
+
...parsedContract,
|
|
3434
|
+
..."program" in parsedContract && { program: compressProgram(parsedContract.program) }
|
|
3435
|
+
};
|
|
3436
|
+
}
|
|
3437
|
+
return createSierraContractClass(parsedContract);
|
|
3438
|
+
}
|
|
3439
|
+
|
|
3440
|
+
// src/utils/responseParser/rpc.ts
|
|
3441
|
+
var RPCResponseParser = class {
|
|
3442
|
+
parseGetBlockResponse(res) {
|
|
3443
|
+
return {
|
|
3444
|
+
timestamp: res.timestamp,
|
|
3445
|
+
block_hash: res.block_hash,
|
|
3446
|
+
block_number: res.block_number,
|
|
3447
|
+
new_root: res.new_root,
|
|
3448
|
+
parent_hash: res.parent_hash,
|
|
3449
|
+
status: res.status,
|
|
3450
|
+
transactions: res.transactions
|
|
3451
|
+
};
|
|
3452
|
+
}
|
|
3453
|
+
parseGetTransactionResponse(res) {
|
|
3454
|
+
return {
|
|
3455
|
+
calldata: res.calldata || [],
|
|
3456
|
+
contract_address: res.contract_address,
|
|
3457
|
+
sender_address: res.contract_address,
|
|
3458
|
+
max_fee: res.max_fee,
|
|
3459
|
+
nonce: res.nonce,
|
|
3460
|
+
signature: res.signature || [],
|
|
3461
|
+
transaction_hash: res.transaction_hash,
|
|
3462
|
+
version: res.version
|
|
3463
|
+
};
|
|
3464
|
+
}
|
|
3465
|
+
parseFeeEstimateResponse(res) {
|
|
3466
|
+
return {
|
|
3467
|
+
overall_fee: toBigInt(res.overall_fee),
|
|
3468
|
+
gas_consumed: toBigInt(res.gas_consumed),
|
|
3469
|
+
gas_price: toBigInt(res.gas_price)
|
|
3470
|
+
};
|
|
3471
|
+
}
|
|
3472
|
+
parseCallContractResponse(res) {
|
|
3473
|
+
return {
|
|
3474
|
+
result: res
|
|
3475
|
+
};
|
|
3476
|
+
}
|
|
3477
|
+
};
|
|
3478
|
+
|
|
3479
|
+
// src/provider/errors.ts
|
|
3480
|
+
function fixStack(target, fn = target.constructor) {
|
|
3481
|
+
const { captureStackTrace } = Error;
|
|
3482
|
+
captureStackTrace && captureStackTrace(target, fn);
|
|
3483
|
+
}
|
|
3484
|
+
function fixProto(target, prototype) {
|
|
3485
|
+
const { setPrototypeOf } = Object;
|
|
3486
|
+
setPrototypeOf ? setPrototypeOf(target, prototype) : target.__proto__ = prototype;
|
|
3487
|
+
}
|
|
3488
|
+
var CustomError = class extends Error {
|
|
3489
|
+
constructor(message) {
|
|
3490
|
+
super(message);
|
|
3491
|
+
Object.defineProperty(this, "name", {
|
|
3492
|
+
value: new.target.name,
|
|
3493
|
+
enumerable: false,
|
|
3494
|
+
configurable: true
|
|
3495
|
+
});
|
|
3496
|
+
fixProto(this, new.target.prototype);
|
|
3497
|
+
fixStack(this);
|
|
3498
|
+
}
|
|
3499
|
+
};
|
|
3500
|
+
var LibraryError = class extends CustomError {
|
|
3501
|
+
};
|
|
3502
|
+
var GatewayError = class extends LibraryError {
|
|
3503
|
+
constructor(message, errorCode) {
|
|
3504
|
+
super(message);
|
|
3505
|
+
this.errorCode = errorCode;
|
|
3506
|
+
}
|
|
3507
|
+
};
|
|
3508
|
+
var HttpError = class extends LibraryError {
|
|
3509
|
+
constructor(message, errorCode) {
|
|
3510
|
+
super(message);
|
|
3511
|
+
this.errorCode = errorCode;
|
|
3512
|
+
}
|
|
3502
3513
|
};
|
|
3503
3514
|
|
|
3504
3515
|
// src/utils/starknetId.ts
|
|
@@ -3831,7 +3842,7 @@ var RpcProvider = class {
|
|
|
3831
3842
|
request: {
|
|
3832
3843
|
type: RPC.TransactionType.INVOKE,
|
|
3833
3844
|
sender_address: invocation.contractAddress,
|
|
3834
|
-
calldata:
|
|
3845
|
+
calldata: CallData.toHex(invocation.calldata),
|
|
3835
3846
|
signature: signatureToHexArray(invocation.signature),
|
|
3836
3847
|
version: toHex((invocationDetails == null ? void 0 : invocationDetails.version) || 0),
|
|
3837
3848
|
nonce: toHex(invocationDetails.nonce),
|
|
@@ -3919,7 +3930,7 @@ var RpcProvider = class {
|
|
|
3919
3930
|
return this.fetchEndpoint("starknet_addInvokeTransaction", {
|
|
3920
3931
|
invoke_transaction: {
|
|
3921
3932
|
sender_address: functionInvocation.contractAddress,
|
|
3922
|
-
calldata:
|
|
3933
|
+
calldata: CallData.toHex(functionInvocation.calldata),
|
|
3923
3934
|
type: RPC.TransactionType.INVOKE,
|
|
3924
3935
|
max_fee: toHex(details.maxFee || 0),
|
|
3925
3936
|
version: "0x1",
|
|
@@ -3934,7 +3945,7 @@ var RpcProvider = class {
|
|
|
3934
3945
|
request: {
|
|
3935
3946
|
contract_address: call.contractAddress,
|
|
3936
3947
|
entry_point_selector: getSelectorFromName(call.entrypoint),
|
|
3937
|
-
calldata:
|
|
3948
|
+
calldata: CallData.toHex(call.calldata)
|
|
3938
3949
|
},
|
|
3939
3950
|
block_id
|
|
3940
3951
|
});
|
|
@@ -4404,7 +4415,7 @@ var SequencerProvider = class {
|
|
|
4404
4415
|
return this.fetchEndpoint("add_transaction", void 0, {
|
|
4405
4416
|
type: "INVOKE_FUNCTION" /* INVOKE */,
|
|
4406
4417
|
sender_address: functionInvocation.contractAddress,
|
|
4407
|
-
calldata:
|
|
4418
|
+
calldata: CallData.compile(functionInvocation.calldata ?? []),
|
|
4408
4419
|
signature: signatureToDecimalArray(functionInvocation.signature),
|
|
4409
4420
|
nonce: toHex(details.nonce),
|
|
4410
4421
|
max_fee: toHex(details.maxFee || 0),
|
|
@@ -4415,7 +4426,7 @@ var SequencerProvider = class {
|
|
|
4415
4426
|
return this.fetchEndpoint("add_transaction", void 0, {
|
|
4416
4427
|
type: "DEPLOY_ACCOUNT" /* DEPLOY_ACCOUNT */,
|
|
4417
4428
|
contract_address_salt: addressSalt ?? randomAddress(),
|
|
4418
|
-
constructor_calldata:
|
|
4429
|
+
constructor_calldata: CallData.compile(constructorCalldata ?? []),
|
|
4419
4430
|
class_hash: toHex(classHash),
|
|
4420
4431
|
max_fee: toHex(details.maxFee || 0),
|
|
4421
4432
|
version: toHex(details.version || 0),
|
|
@@ -4499,7 +4510,7 @@ var SequencerProvider = class {
|
|
|
4499
4510
|
{
|
|
4500
4511
|
type: "DEPLOY_ACCOUNT" /* DEPLOY_ACCOUNT */,
|
|
4501
4512
|
class_hash: toHex(classHash),
|
|
4502
|
-
constructor_calldata:
|
|
4513
|
+
constructor_calldata: CallData.compile(constructorCalldata || []),
|
|
4503
4514
|
contract_address_salt: toHex(addressSalt || 0),
|
|
4504
4515
|
signature: signatureToDecimalArray(signature),
|
|
4505
4516
|
version: toHex((details == null ? void 0 : details.version) || 0),
|
|
@@ -4526,9 +4537,7 @@ var SequencerProvider = class {
|
|
|
4526
4537
|
res = {
|
|
4527
4538
|
type: invocation.type,
|
|
4528
4539
|
class_hash: toHex(toBigInt(invocation.classHash)),
|
|
4529
|
-
constructor_calldata:
|
|
4530
|
-
invocation.constructorCalldata || []
|
|
4531
|
-
),
|
|
4540
|
+
constructor_calldata: CallData.compile(invocation.constructorCalldata || []),
|
|
4532
4541
|
contract_address_salt: toHex(toBigInt(invocation.addressSalt || 0))
|
|
4533
4542
|
};
|
|
4534
4543
|
}
|
|
@@ -5023,19 +5032,13 @@ var transformCallsToMulticallArrays = (calls) => {
|
|
|
5023
5032
|
});
|
|
5024
5033
|
return {
|
|
5025
5034
|
callArray,
|
|
5026
|
-
calldata:
|
|
5035
|
+
calldata: CallData.compile({ calldata })
|
|
5027
5036
|
};
|
|
5028
5037
|
};
|
|
5029
5038
|
var fromCallsToExecuteCalldata = (calls) => {
|
|
5030
5039
|
const { callArray, calldata } = transformCallsToMulticallArrays(calls);
|
|
5031
|
-
|
|
5032
|
-
|
|
5033
|
-
...callArray.map(
|
|
5034
|
-
({ to, selector, data_offset, data_len }) => [to, selector, data_offset, data_len]
|
|
5035
|
-
).flat(),
|
|
5036
|
-
calldata.length.toString(),
|
|
5037
|
-
...calldata
|
|
5038
|
-
];
|
|
5040
|
+
const compiledCalls = CallData.compile({ callArray });
|
|
5041
|
+
return [...compiledCalls, ...calldata];
|
|
5039
5042
|
};
|
|
5040
5043
|
var fromCallsToExecuteCalldataWithNonce = (calls, nonce) => {
|
|
5041
5044
|
return [...fromCallsToExecuteCalldata(calls), toBigInt(nonce).toString()];
|
|
@@ -5044,20 +5047,16 @@ var transformCallsToMulticallArrays_cairo1 = (calls) => {
|
|
|
5044
5047
|
const callArray = calls.map((call) => ({
|
|
5045
5048
|
to: toBigInt(call.contractAddress).toString(10),
|
|
5046
5049
|
selector: toBigInt(getSelectorFromName(call.entrypoint)).toString(10),
|
|
5047
|
-
calldata:
|
|
5050
|
+
calldata: CallData.compile(call.calldata || [])
|
|
5048
5051
|
}));
|
|
5049
5052
|
return callArray;
|
|
5050
5053
|
};
|
|
5051
5054
|
var fromCallsToExecuteCalldata_cairo1 = (calls) => {
|
|
5052
|
-
|
|
5053
|
-
return [
|
|
5054
|
-
callArray.length.toString(),
|
|
5055
|
-
...callArray.map(({ to, selector, calldata }) => [to, selector, calldata.length.toString(), ...calldata]).flat()
|
|
5056
|
-
];
|
|
5055
|
+
return CallData.compile({ calls });
|
|
5057
5056
|
};
|
|
5058
5057
|
var getExecuteCalldata = (calls, cairoVersion = "0") => {
|
|
5059
5058
|
if (cairoVersion === "1") {
|
|
5060
|
-
return
|
|
5059
|
+
return CallData.compile({ calls });
|
|
5061
5060
|
}
|
|
5062
5061
|
return fromCallsToExecuteCalldata(calls);
|
|
5063
5062
|
};
|
|
@@ -5663,7 +5662,8 @@ var Account = class extends Provider {
|
|
|
5663
5662
|
const version = toBigInt(transactionVersion);
|
|
5664
5663
|
const nonce = ZERO;
|
|
5665
5664
|
const chainId = await this.getChainId();
|
|
5666
|
-
const
|
|
5665
|
+
const compiledCalldata = CallData.compile(constructorCalldata);
|
|
5666
|
+
const contractAddress = providedContractAddress ?? calculateContractAddressFromHash(addressSalt, classHash, compiledCalldata, 0);
|
|
5667
5667
|
const maxFee = transactionsDetail.maxFee ?? await this.getSuggestedMaxFee(
|
|
5668
5668
|
{
|
|
5669
5669
|
type: "DEPLOY_ACCOUNT" /* DEPLOY_ACCOUNT */,
|
|
@@ -5761,7 +5761,8 @@ var Account = class extends Provider {
|
|
|
5761
5761
|
constructorCalldata = [],
|
|
5762
5762
|
contractAddress: providedContractAddress
|
|
5763
5763
|
}, { nonce, chainId, version, maxFee }) {
|
|
5764
|
-
const
|
|
5764
|
+
const compiledCalldata = CallData.compile(constructorCalldata);
|
|
5765
|
+
const contractAddress = providedContractAddress ?? calculateContractAddressFromHash(addressSalt, classHash, compiledCalldata, 0);
|
|
5765
5766
|
const signature = await this.signer.signDeployAccountTransaction({
|
|
5766
5767
|
classHash,
|
|
5767
5768
|
contractAddress,
|