starknet 5.1.1 → 5.3.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/dist/index.js CHANGED
@@ -28,9 +28,11 @@ var src_exports = {};
28
28
  __export(src_exports, {
29
29
  Account: () => Account,
30
30
  AccountInterface: () => AccountInterface,
31
+ CallData: () => CallData,
31
32
  Contract: () => Contract,
32
33
  ContractFactory: () => ContractFactory,
33
34
  ContractInterface: () => ContractInterface,
35
+ EntryPointType: () => EntryPointType,
34
36
  GatewayError: () => GatewayError,
35
37
  HttpError: () => HttpError,
36
38
  LibraryError: () => LibraryError,
@@ -66,7 +68,15 @@ __export(src_exports, {
66
68
  });
67
69
  module.exports = __toCommonJS(src_exports);
68
70
 
69
- // src/types/lib.ts
71
+ // src/types/lib/contract/index.ts
72
+ var EntryPointType = /* @__PURE__ */ ((EntryPointType2) => {
73
+ EntryPointType2["EXTERNAL"] = "EXTERNAL";
74
+ EntryPointType2["L1_HANDLER"] = "L1_HANDLER";
75
+ EntryPointType2["CONSTRUCTOR"] = "CONSTRUCTOR";
76
+ return EntryPointType2;
77
+ })(EntryPointType || {});
78
+
79
+ // src/types/lib/index.ts
70
80
  var TransactionStatus = /* @__PURE__ */ ((TransactionStatus2) => {
71
81
  TransactionStatus2["NOT_RECEIVED"] = "NOT_RECEIVED";
72
82
  TransactionStatus2["RECEIVED"] = "RECEIVED";
@@ -110,19 +120,23 @@ __export(hash_exports, {
110
120
  calculateDeployTransactionHash: () => calculateDeployTransactionHash,
111
121
  calculateTransactionHash: () => calculateTransactionHash,
112
122
  calculateTransactionHashCommon: () => calculateTransactionHashCommon,
123
+ computeCompiledClassHash: () => computeCompiledClassHash,
113
124
  computeContractClassHash: () => computeContractClassHash,
114
125
  computeHashOnElements: () => computeHashOnElements,
126
+ computeLegacyContractClassHash: () => computeLegacyContractClassHash,
127
+ computeSierraContractClassHash: () => computeSierraContractClassHash,
115
128
  default: () => computeHintedClassHash,
116
129
  feeTransactionVersion: () => feeTransactionVersion,
130
+ formatSpaces: () => formatSpaces,
117
131
  getSelector: () => getSelector,
118
132
  getSelectorFromName: () => getSelectorFromName,
119
133
  keccakBn: () => keccakBn,
120
134
  poseidon: () => poseidon,
121
135
  starknetKeccak: () => starknetKeccak,
122
- transactionVersion: () => transactionVersion
136
+ transactionVersion: () => transactionVersion,
137
+ transactionVersion_2: () => transactionVersion_2
123
138
  });
124
- var import_keccak = require("ethereum-cryptography/keccak.js");
125
- var import_utils = require("ethereum-cryptography/utils.js");
139
+ var import_micro_starknet = require("micro-starknet");
126
140
 
127
141
  // src/constants.ts
128
142
  var constants_exports = {};
@@ -2289,6 +2303,7 @@ __export(num_exports, {
2289
2303
  getDecimalString: () => getDecimalString,
2290
2304
  getHexString: () => getHexString,
2291
2305
  getHexStringArray: () => getHexStringArray,
2306
+ hexToBytes: () => hexToBytes,
2292
2307
  hexToDecimalString: () => hexToDecimalString,
2293
2308
  isBigInt: () => isBigInt,
2294
2309
  isHex: () => isHex,
@@ -2298,6 +2313,7 @@ __export(num_exports, {
2298
2313
  toHex: () => toHex,
2299
2314
  toHexString: () => toHexString
2300
2315
  });
2316
+ var import_utils = require("@noble/curves/abstract/utils");
2301
2317
 
2302
2318
  // src/utils/assert.ts
2303
2319
  function assert(condition, message) {
@@ -2363,6 +2379,15 @@ function getHexStringArray(value) {
2363
2379
  return value.map((el) => getHexString(el));
2364
2380
  }
2365
2381
  var toCairoBool = (value) => (+value).toString();
2382
+ function hexToBytes(value) {
2383
+ if (!isHex(value))
2384
+ throw new Error(`${value} need to be a hex-string`);
2385
+ let adaptedValue = removeHexPrefix(value);
2386
+ if (adaptedValue.length % 2 !== 0) {
2387
+ adaptedValue = `0${adaptedValue}`;
2388
+ }
2389
+ return (0, import_utils.hexToBytes)(adaptedValue);
2390
+ }
2366
2391
 
2367
2392
  // src/utils/shortString.ts
2368
2393
  var shortString_exports = {};
@@ -2477,7 +2502,7 @@ __export(ec_exports, {
2477
2502
  starkCurve: () => starkCurve,
2478
2503
  weierstrass: () => weierstrass
2479
2504
  });
2480
- var starkCurve = __toESM(require("@noble/curves/stark"));
2505
+ var starkCurve = __toESM(require("micro-starknet"));
2481
2506
  var weierstrass = __toESM(require("@noble/curves/abstract/weierstrass"));
2482
2507
 
2483
2508
  // src/utils/json.ts
@@ -2505,14 +2530,15 @@ var json_default = { parse, stringify };
2505
2530
  // src/utils/hash.ts
2506
2531
  var poseidon = __toESM(require("@noble/curves/abstract/poseidon"));
2507
2532
  var transactionVersion = 1n;
2533
+ var transactionVersion_2 = 2n;
2508
2534
  var feeTransactionVersion = 2n ** 128n + transactionVersion;
2509
2535
  function keccakBn(value) {
2510
2536
  const hexWithoutPrefix = removeHexPrefix(toHex(BigInt(value)));
2511
2537
  const evenHex = hexWithoutPrefix.length % 2 === 0 ? hexWithoutPrefix : `0${hexWithoutPrefix}`;
2512
- return addHexPrefix(buf2hex((0, import_keccak.keccak256)((0, import_utils.hexToBytes)(evenHex))));
2538
+ return addHexPrefix((0, import_micro_starknet.keccak)(hexToBytes(addHexPrefix(evenHex))).toString(16));
2513
2539
  }
2514
2540
  function keccakHex(value) {
2515
- return addHexPrefix(buf2hex((0, import_keccak.keccak256)(utf8ToArray(value))));
2541
+ return addHexPrefix((0, import_micro_starknet.keccak)(utf8ToArray(value)).toString(16));
2516
2542
  }
2517
2543
  function starknetKeccak(value) {
2518
2544
  const hash = BigInt(keccakHex(value));
@@ -2558,7 +2584,7 @@ function calculateDeployTransactionHash(contractAddress, constructorCalldata, ve
2558
2584
  chainId
2559
2585
  );
2560
2586
  }
2561
- function calculateDeclareTransactionHash(classHash, senderAddress, version, maxFee, chainId, nonce) {
2587
+ function calculateDeclareTransactionHash(classHash, senderAddress, version, maxFee, chainId, nonce, compiledClassHash) {
2562
2588
  return calculateTransactionHashCommon(
2563
2589
  "0x6465636c617265" /* DECLARE */,
2564
2590
  version,
@@ -2567,7 +2593,7 @@ function calculateDeclareTransactionHash(classHash, senderAddress, version, maxF
2567
2593
  [classHash],
2568
2594
  maxFee,
2569
2595
  chainId,
2570
- [nonce]
2596
+ [nonce, ...compiledClassHash ? [compiledClassHash] : []]
2571
2597
  );
2572
2598
  }
2573
2599
  function calculateDeployAccountTransactionHash(contractAddress, classHash, constructorCalldata, salt, version, maxFee, chainId, nonce) {
@@ -2615,32 +2641,28 @@ function nullSkipReplacer(key, value) {
2615
2641
  }
2616
2642
  return value === null ? void 0 : value;
2617
2643
  }
2644
+ function formatSpaces(json2) {
2645
+ let insideQuotes = false;
2646
+ let newString = "";
2647
+ for (const char of json2) {
2648
+ if (char === '"' && newString.endsWith("\\") === false) {
2649
+ insideQuotes = !insideQuotes;
2650
+ }
2651
+ if (insideQuotes) {
2652
+ newString += char;
2653
+ } else {
2654
+ newString += char === ":" ? ": " : char === "," ? ", " : char;
2655
+ }
2656
+ }
2657
+ return newString;
2658
+ }
2618
2659
  function computeHintedClassHash(compiledContract) {
2619
2660
  const { abi, program } = compiledContract;
2620
2661
  const contractClass = { abi, program };
2621
- const serialisedJson = stringify(contractClass, nullSkipReplacer).split("").reduce(
2622
- ([insideQuotes, newString], char) => {
2623
- if (char === '"' && newString[newString.length - 1] !== "\\") {
2624
- insideQuotes = !insideQuotes;
2625
- }
2626
- if (insideQuotes) {
2627
- newString += char;
2628
- return [insideQuotes, newString];
2629
- }
2630
- if (char === ":" && !insideQuotes) {
2631
- newString += ": ";
2632
- } else if (char === "," && !insideQuotes) {
2633
- newString += ", ";
2634
- } else {
2635
- newString += char;
2636
- }
2637
- return [insideQuotes, newString];
2638
- },
2639
- [false, ""]
2640
- )[1];
2641
- return addHexPrefix(starkCurve.keccak(utf8ToArray(serialisedJson)).toString(16));
2662
+ const serializedJson = formatSpaces(stringify(contractClass, nullSkipReplacer));
2663
+ return addHexPrefix(starkCurve.keccak(utf8ToArray(serializedJson)).toString(16));
2642
2664
  }
2643
- function computeContractClassHash(contract) {
2665
+ function computeLegacyContractClassHash(contract) {
2644
2666
  const compiledContract = typeof contract === "string" ? parse(contract) : contract;
2645
2667
  const apiVersion = toHex(API_VERSION);
2646
2668
  const externalEntryPointsHash = computeHashOnElements(
@@ -2667,6 +2689,95 @@ function computeContractClassHash(contract) {
2667
2689
  dataHash
2668
2690
  ]);
2669
2691
  }
2692
+ function hashBuiltins(builtins) {
2693
+ return (0, import_micro_starknet.poseidonHashMany)(
2694
+ builtins.flatMap((it) => {
2695
+ return BigInt(encodeShortString(it));
2696
+ })
2697
+ );
2698
+ }
2699
+ function hashEntryPoint(data) {
2700
+ const base = data.flatMap((it) => {
2701
+ return [BigInt(it.selector), BigInt(it.offset), hashBuiltins(it.builtins)];
2702
+ });
2703
+ return (0, import_micro_starknet.poseidonHashMany)(base);
2704
+ }
2705
+ function computeCompiledClassHash(casm) {
2706
+ const COMPILED_CLASS_VERSION = "COMPILED_CLASS_V1";
2707
+ const compiledClassVersion = BigInt(encodeShortString(COMPILED_CLASS_VERSION));
2708
+ const externalEntryPointsHash = hashEntryPoint(casm.entry_points_by_type.EXTERNAL);
2709
+ const l1Handlers = hashEntryPoint(casm.entry_points_by_type.L1_HANDLER);
2710
+ const constructor = hashEntryPoint(casm.entry_points_by_type.CONSTRUCTOR);
2711
+ const bytecode = (0, import_micro_starknet.poseidonHashMany)(casm.bytecode.map((it) => BigInt(it)));
2712
+ return toHex(
2713
+ (0, import_micro_starknet.poseidonHashMany)([
2714
+ compiledClassVersion,
2715
+ externalEntryPointsHash,
2716
+ l1Handlers,
2717
+ constructor,
2718
+ bytecode
2719
+ ])
2720
+ );
2721
+ }
2722
+ function hashEntryPointSierra(data) {
2723
+ const base = data.flatMap((it) => {
2724
+ return [BigInt(it.selector), BigInt(it.function_idx)];
2725
+ });
2726
+ return (0, import_micro_starknet.poseidonHashMany)(base);
2727
+ }
2728
+ function hashAbi(sierra) {
2729
+ const indentString = formatSpaces(stringify(sierra.abi, null));
2730
+ return BigInt(addHexPrefix(starkCurve.keccak(utf8ToArray(indentString)).toString(16)));
2731
+ }
2732
+ function computeSierraContractClassHash(sierra) {
2733
+ const CONTRACT_CLASS_VERSION = "CONTRACT_CLASS_V0.1.0";
2734
+ const compiledClassVersion = BigInt(encodeShortString(CONTRACT_CLASS_VERSION));
2735
+ const externalEntryPointsHash = hashEntryPointSierra(sierra.entry_points_by_type.EXTERNAL);
2736
+ const l1Handlers = hashEntryPointSierra(sierra.entry_points_by_type.L1_HANDLER);
2737
+ const constructor = hashEntryPointSierra(sierra.entry_points_by_type.CONSTRUCTOR);
2738
+ const abiHash = hashAbi(sierra);
2739
+ const sierraProgram = (0, import_micro_starknet.poseidonHashMany)(sierra.sierra_program.map((it) => BigInt(it)));
2740
+ return toHex(
2741
+ (0, import_micro_starknet.poseidonHashMany)([
2742
+ compiledClassVersion,
2743
+ externalEntryPointsHash,
2744
+ l1Handlers,
2745
+ constructor,
2746
+ abiHash,
2747
+ sierraProgram
2748
+ ])
2749
+ );
2750
+ }
2751
+ function computeContractClassHash(contract) {
2752
+ const compiledContract = typeof contract === "string" ? parse(contract) : contract;
2753
+ if ("sierra_program" in compiledContract) {
2754
+ return computeSierraContractClassHash(compiledContract);
2755
+ }
2756
+ return computeLegacyContractClassHash(compiledContract);
2757
+ }
2758
+
2759
+ // src/utils/contract.ts
2760
+ var import_json_bigint2 = require("json-bigint");
2761
+ function isSierra(contract) {
2762
+ const compiledContract = typeof contract === "string" ? (0, import_json_bigint2.parse)(contract) : contract;
2763
+ return "sierra_program" in compiledContract;
2764
+ }
2765
+ function extractContractHashes(payload) {
2766
+ const response = { ...payload };
2767
+ if (isSierra(payload.contract)) {
2768
+ if (!payload.compiledClassHash && payload.casm) {
2769
+ response.compiledClassHash = computeCompiledClassHash(payload.casm);
2770
+ }
2771
+ if (!response.compiledClassHash)
2772
+ throw new Error(
2773
+ "Extract compiledClassHash failed, provide (CairoAssembly).casm file or compiledClassHash"
2774
+ );
2775
+ }
2776
+ response.classHash = payload.classHash ?? computeContractClassHash(payload.contract);
2777
+ if (!response.classHash)
2778
+ throw new Error("Extract classHash failed, provide (CompiledContract).json file or classHash");
2779
+ return response;
2780
+ }
2670
2781
 
2671
2782
  // src/utils/stark.ts
2672
2783
  var stark_exports = {};
@@ -2681,7 +2792,7 @@ __export(stark_exports, {
2681
2792
  signatureToDecimalArray: () => signatureToDecimalArray,
2682
2793
  signatureToHexArray: () => signatureToHexArray
2683
2794
  });
2684
- var import_stark = require("@noble/curves/stark");
2795
+ var import_micro_starknet2 = require("micro-starknet");
2685
2796
  var import_pako = require("pako");
2686
2797
  function compressProgram(jsonProgram) {
2687
2798
  const stringified = typeof jsonProgram === "string" ? jsonProgram : stringify(jsonProgram);
@@ -2689,8 +2800,8 @@ function compressProgram(jsonProgram) {
2689
2800
  return btoaUniversal(compressedProgram);
2690
2801
  }
2691
2802
  function randomAddress() {
2692
- const randomKeyPair = import_stark.utils.randomPrivateKey();
2693
- return (0, import_stark.getStarkKey)(randomKeyPair);
2803
+ const randomKeyPair = import_micro_starknet2.utils.randomPrivateKey();
2804
+ return (0, import_micro_starknet2.getStarkKey)(randomKeyPair);
2694
2805
  }
2695
2806
  function makeAddress(input) {
2696
2807
  return addHexPrefix(input).toLowerCase();
@@ -2715,7 +2826,7 @@ function parseSignature(sig) {
2715
2826
  if (!sig)
2716
2827
  return void 0;
2717
2828
  const [r, s] = sig;
2718
- return new import_stark.Signature(toBigInt(r), toBigInt(s));
2829
+ return new import_micro_starknet2.Signature(toBigInt(r), toBigInt(s));
2719
2830
  }
2720
2831
  function compileCalldata(args) {
2721
2832
  const compiledData = Object.values(args).flatMap((value) => {
@@ -2751,12 +2862,23 @@ function parseCalldata(calldata = []) {
2751
2862
  return toHex(data);
2752
2863
  });
2753
2864
  }
2865
+ function createSierraContractClass(contract) {
2866
+ const result = { ...contract };
2867
+ delete result.sierra_program_debug_info;
2868
+ result.abi = formatSpaces(stringify(contract.abi));
2869
+ result.sierra_program = formatSpaces(stringify(contract.sierra_program));
2870
+ result.sierra_program = compressProgram(result.sierra_program);
2871
+ return result;
2872
+ }
2754
2873
  function parseContract(contract) {
2755
2874
  const parsedContract = typeof contract === "string" ? parse(contract) : contract;
2756
- return {
2757
- ...parsedContract,
2758
- program: compressProgram(parsedContract.program)
2759
- };
2875
+ if (!isSierra(contract)) {
2876
+ return {
2877
+ ...parsedContract,
2878
+ ..."program" in parsedContract && { program: compressProgram(parsedContract.program) }
2879
+ };
2880
+ }
2881
+ return createSierraContractClass(parsedContract);
2760
2882
  }
2761
2883
 
2762
2884
  // src/utils/responseParser/rpc.ts
@@ -2776,6 +2898,7 @@ var RPCResponseParser = class {
2776
2898
  return {
2777
2899
  calldata: res.calldata || [],
2778
2900
  contract_address: res.contract_address,
2901
+ sender_address: res.contract_address,
2779
2902
  max_fee: res.max_fee,
2780
2903
  nonce: res.nonce,
2781
2904
  signature: res.signature || [],
@@ -3145,22 +3268,25 @@ var RpcProvider = class {
3145
3268
  }
3146
3269
  async getDeclareEstimateFee({ senderAddress, contractDefinition, signature }, details, blockIdentifier = this.blockIdentifier) {
3147
3270
  const block_id = new Block(blockIdentifier).identifier;
3148
- return this.fetchEndpoint("starknet_estimateFee", {
3149
- request: {
3150
- type: RPC.TransactionType.DECLARE,
3151
- contract_class: {
3152
- program: contractDefinition.program,
3153
- entry_points_by_type: contractDefinition.entry_points_by_type,
3154
- abi: contractDefinition.abi
3271
+ if ("program" in contractDefinition) {
3272
+ return this.fetchEndpoint("starknet_estimateFee", {
3273
+ request: {
3274
+ type: RPC.TransactionType.DECLARE,
3275
+ contract_class: {
3276
+ program: contractDefinition.program,
3277
+ entry_points_by_type: contractDefinition.entry_points_by_type,
3278
+ abi: contractDefinition.abi
3279
+ },
3280
+ sender_address: senderAddress,
3281
+ signature: signatureToHexArray(signature),
3282
+ version: toHex((details == null ? void 0 : details.version) || 0),
3283
+ nonce: toHex(details.nonce),
3284
+ max_fee: toHex((details == null ? void 0 : details.maxFee) || 0)
3155
3285
  },
3156
- sender_address: senderAddress,
3157
- signature: signatureToHexArray(signature),
3158
- version: toHex((details == null ? void 0 : details.version) || 0),
3159
- nonce: toHex(details.nonce),
3160
- max_fee: toHex((details == null ? void 0 : details.maxFee) || 0)
3161
- },
3162
- block_id
3163
- }).then(this.responseParser.parseFeeEstimateResponse);
3286
+ block_id
3287
+ }).then(this.responseParser.parseFeeEstimateResponse);
3288
+ }
3289
+ throw new Error("RPC do not support Sierra Contracts yet");
3164
3290
  }
3165
3291
  async getDeployAccountEstimateFee({ classHash, constructorCalldata, addressSalt, signature }, details, blockIdentifier = this.blockIdentifier) {
3166
3292
  const block_id = new Block(blockIdentifier).identifier;
@@ -3182,21 +3308,24 @@ var RpcProvider = class {
3182
3308
  throw new Error("RPC does not implement getInvokeEstimateFeeBulk function");
3183
3309
  }
3184
3310
  async declareContract({ contractDefinition, signature, senderAddress }, details) {
3185
- return this.fetchEndpoint("starknet_addDeclareTransaction", {
3186
- declare_transaction: {
3187
- contract_class: {
3188
- program: contractDefinition.program,
3189
- entry_points_by_type: contractDefinition.entry_points_by_type,
3190
- abi: contractDefinition.abi
3191
- },
3192
- type: RPC.TransactionType.DECLARE,
3193
- version: toHex(details.version || 0),
3194
- max_fee: toHex(details.maxFee || 0),
3195
- signature: signatureToHexArray(signature),
3196
- sender_address: senderAddress,
3197
- nonce: toHex(details.nonce)
3198
- }
3199
- });
3311
+ if ("program" in contractDefinition) {
3312
+ return this.fetchEndpoint("starknet_addDeclareTransaction", {
3313
+ declare_transaction: {
3314
+ contract_class: {
3315
+ program: contractDefinition.program,
3316
+ entry_points_by_type: contractDefinition.entry_points_by_type,
3317
+ abi: contractDefinition.abi
3318
+ },
3319
+ type: RPC.TransactionType.DECLARE,
3320
+ version: "0x1",
3321
+ max_fee: toHex(details.maxFee || 0),
3322
+ signature: signatureToHexArray(signature),
3323
+ sender_address: senderAddress,
3324
+ nonce: toHex(details.nonce)
3325
+ }
3326
+ });
3327
+ }
3328
+ throw new Error("RPC do not support Sierra Contracts yet");
3200
3329
  }
3201
3330
  async deployAccountContract({ classHash, constructorCalldata, addressSalt, signature }, details) {
3202
3331
  return this.fetchEndpoint("starknet_addDeployAccountTransaction", {
@@ -3219,7 +3348,7 @@ var RpcProvider = class {
3219
3348
  calldata: parseCalldata(functionInvocation.calldata),
3220
3349
  type: RPC.TransactionType.INVOKE,
3221
3350
  max_fee: toHex(details.maxFee || 0),
3222
- version: toHex(details.version || 1),
3351
+ version: "0x1",
3223
3352
  signature: signatureToHexArray(functionInvocation.signature),
3224
3353
  nonce: toHex(details.nonce)
3225
3354
  }
@@ -3328,7 +3457,6 @@ var SequencerAPIResponseParser = class extends ResponseParser {
3328
3457
  return {
3329
3458
  ...res,
3330
3459
  calldata: "calldata" in res.transaction ? res.transaction.calldata : [],
3331
- contract_address: "contract_address" in res.transaction ? res.transaction.contract_address : void 0,
3332
3460
  contract_class: "contract_class" in res.transaction ? res.transaction.contract_class : void 0,
3333
3461
  entry_point_selector: "entry_point_selector" in res.transaction ? res.transaction.entry_point_selector : void 0,
3334
3462
  max_fee: "max_fee" in res.transaction ? res.transaction.max_fee : void 0,
@@ -3446,24 +3574,18 @@ var SequencerAPIResponseParser = class extends ResponseParser {
3446
3574
  };
3447
3575
  }
3448
3576
  parseGetStateUpdateResponse(res) {
3449
- const nonces = [].concat(res.state_diff.nonces).map(({ contract_address, nonce }) => {
3450
- return {
3451
- contract_address,
3452
- nonce
3453
- };
3454
- });
3455
- const storage_diffs = [].concat(res.state_diff.storage_diffs).map(({ address, storage_entries }) => {
3456
- return {
3457
- address,
3458
- storage_entries
3459
- };
3460
- });
3577
+ const nonces = Object.entries(res.state_diff.nonces).map(([contract_address, nonce]) => ({
3578
+ contract_address,
3579
+ nonce
3580
+ }));
3581
+ const storage_diffs = Object.entries(res.state_diff.storage_diffs).map(
3582
+ ([address, storage_entries]) => ({ address, storage_entries })
3583
+ );
3461
3584
  return {
3462
3585
  ...res,
3463
3586
  state_diff: {
3587
+ ...res.state_diff,
3464
3588
  storage_diffs,
3465
- declared_contract_hashes: res.state_diff.declared_contract_hashes,
3466
- deployed_contracts: res.state_diff.deployed_contracts,
3467
3589
  nonces
3468
3590
  }
3469
3591
  };
@@ -3637,7 +3759,6 @@ var SequencerProvider = class {
3637
3759
  "call_contract",
3638
3760
  { blockIdentifier },
3639
3761
  {
3640
- signature: [],
3641
3762
  contract_address: contractAddress,
3642
3763
  entry_point_selector: getSelectorFromName(entryPointSelector),
3643
3764
  calldata
@@ -3682,18 +3803,23 @@ var SequencerProvider = class {
3682
3803
  async getClassHashAt(contractAddress, blockIdentifier = this.blockIdentifier) {
3683
3804
  return this.fetchEndpoint("get_class_hash_at", { blockIdentifier, contractAddress });
3684
3805
  }
3685
- async getClassByHash(classHash) {
3686
- return this.fetchEndpoint("get_class_by_hash", { classHash }).then(parseContract);
3806
+ async getClassByHash(classHash, blockIdentifier = this.blockIdentifier) {
3807
+ return this.fetchEndpoint("get_class_by_hash", { classHash, blockIdentifier }).then(
3808
+ parseContract
3809
+ );
3810
+ }
3811
+ async getCompiledClassByClassHash(classHash, blockIdentifier = this.blockIdentifier) {
3812
+ return this.fetchEndpoint("get_compiled_class_by_class_hash", { classHash, blockIdentifier });
3687
3813
  }
3688
3814
  async invokeFunction(functionInvocation, details) {
3689
3815
  return this.fetchEndpoint("add_transaction", void 0, {
3690
3816
  type: "INVOKE_FUNCTION" /* INVOKE */,
3691
- contract_address: functionInvocation.contractAddress,
3817
+ sender_address: functionInvocation.contractAddress,
3692
3818
  calldata: bigNumberishArrayToDecimalStringArray(functionInvocation.calldata ?? []),
3693
3819
  signature: signatureToDecimalArray(functionInvocation.signature),
3694
3820
  nonce: toHex(details.nonce),
3695
3821
  max_fee: toHex(details.maxFee || 0),
3696
- version: toHex(details.version || 1)
3822
+ version: "0x1"
3697
3823
  }).then(this.responseParser.parseInvokeFunctionResponse);
3698
3824
  }
3699
3825
  async deployAccountContract({ classHash, constructorCalldata, addressSalt, signature }, details) {
@@ -3708,27 +3834,39 @@ var SequencerProvider = class {
3708
3834
  signature: signatureToDecimalArray(signature)
3709
3835
  }).then(this.responseParser.parseDeployContractResponse);
3710
3836
  }
3711
- async declareContract({ senderAddress, contractDefinition, signature }, details) {
3837
+ async declareContract({ senderAddress, contractDefinition, signature, compiledClassHash }, details) {
3838
+ if (!isSierra(contractDefinition)) {
3839
+ return this.fetchEndpoint("add_transaction", void 0, {
3840
+ type: "DECLARE" /* DECLARE */,
3841
+ contract_class: contractDefinition,
3842
+ nonce: toHex(details.nonce),
3843
+ signature: signatureToDecimalArray(signature),
3844
+ sender_address: senderAddress,
3845
+ max_fee: toHex(details.maxFee || 0),
3846
+ version: "0x1"
3847
+ }).then(this.responseParser.parseDeclareContractResponse);
3848
+ }
3712
3849
  return this.fetchEndpoint("add_transaction", void 0, {
3713
3850
  type: "DECLARE" /* DECLARE */,
3851
+ sender_address: senderAddress,
3852
+ compiled_class_hash: compiledClassHash,
3714
3853
  contract_class: contractDefinition,
3715
3854
  nonce: toHex(details.nonce),
3716
3855
  signature: signatureToDecimalArray(signature),
3717
- sender_address: senderAddress,
3718
3856
  max_fee: toHex(details.maxFee || 0),
3719
- version: toHex(details.version || 1)
3857
+ version: "0x2"
3720
3858
  }).then(this.responseParser.parseDeclareContractResponse);
3721
3859
  }
3722
- async getEstimateFee(invocation, invocationDetails, blockIdentifier = this.blockIdentifier) {
3723
- return this.getInvokeEstimateFee(invocation, invocationDetails, blockIdentifier);
3860
+ async getEstimateFee(invocation, invocationDetails, blockIdentifier = this.blockIdentifier, skipValidate = false) {
3861
+ return this.getInvokeEstimateFee(invocation, invocationDetails, blockIdentifier, skipValidate);
3724
3862
  }
3725
- async getInvokeEstimateFee(invocation, invocationDetails, blockIdentifier = this.blockIdentifier) {
3863
+ async getInvokeEstimateFee(invocation, invocationDetails, blockIdentifier = this.blockIdentifier, skipValidate = false) {
3726
3864
  return this.fetchEndpoint(
3727
3865
  "estimate_fee",
3728
- { blockIdentifier },
3866
+ { blockIdentifier, skipValidate },
3729
3867
  {
3730
3868
  type: "INVOKE_FUNCTION" /* INVOKE */,
3731
- contract_address: invocation.contractAddress,
3869
+ sender_address: invocation.contractAddress,
3732
3870
  calldata: invocation.calldata ?? [],
3733
3871
  signature: signatureToDecimalArray(invocation.signature),
3734
3872
  version: toHex((invocationDetails == null ? void 0 : invocationDetails.version) || 1),
@@ -3736,24 +3874,39 @@ var SequencerProvider = class {
3736
3874
  }
3737
3875
  ).then(this.responseParser.parseFeeEstimateResponse);
3738
3876
  }
3739
- async getDeclareEstimateFee({ senderAddress, contractDefinition, signature }, details, blockIdentifier = this.blockIdentifier) {
3877
+ async getDeclareEstimateFee({ senderAddress, contractDefinition, signature, compiledClassHash }, details, blockIdentifier = this.blockIdentifier, skipValidate = false) {
3878
+ if (!isSierra(contractDefinition)) {
3879
+ return this.fetchEndpoint(
3880
+ "estimate_fee",
3881
+ { blockIdentifier, skipValidate },
3882
+ {
3883
+ type: "DECLARE" /* DECLARE */,
3884
+ sender_address: senderAddress,
3885
+ contract_class: contractDefinition,
3886
+ signature: signatureToDecimalArray(signature),
3887
+ version: toHex((details == null ? void 0 : details.version) || toBigInt(feeTransactionVersion)),
3888
+ nonce: toHex(details.nonce)
3889
+ }
3890
+ ).then(this.responseParser.parseFeeEstimateResponse);
3891
+ }
3740
3892
  return this.fetchEndpoint(
3741
3893
  "estimate_fee",
3742
- { blockIdentifier },
3894
+ { blockIdentifier, skipValidate },
3743
3895
  {
3744
3896
  type: "DECLARE" /* DECLARE */,
3745
3897
  sender_address: senderAddress,
3898
+ compiled_class_hash: compiledClassHash,
3746
3899
  contract_class: contractDefinition,
3900
+ nonce: toHex(details.nonce),
3747
3901
  signature: signatureToDecimalArray(signature),
3748
- version: toHex((details == null ? void 0 : details.version) || 1),
3749
- nonce: toHex(details.nonce)
3902
+ version: "0x2"
3750
3903
  }
3751
3904
  ).then(this.responseParser.parseFeeEstimateResponse);
3752
3905
  }
3753
- async getDeployAccountEstimateFee({ classHash, addressSalt, constructorCalldata, signature }, details, blockIdentifier = this.blockIdentifier) {
3906
+ async getDeployAccountEstimateFee({ classHash, addressSalt, constructorCalldata, signature }, details, blockIdentifier = this.blockIdentifier, skipValidate = false) {
3754
3907
  return this.fetchEndpoint(
3755
3908
  "estimate_fee",
3756
- { blockIdentifier },
3909
+ { blockIdentifier, skipValidate },
3757
3910
  {
3758
3911
  type: "DEPLOY_ACCOUNT" /* DEPLOY_ACCOUNT */,
3759
3912
  class_hash: toHex(classHash),
@@ -3771,7 +3924,7 @@ var SequencerProvider = class {
3771
3924
  if (invocation.type === "INVOKE_FUNCTION") {
3772
3925
  res = {
3773
3926
  type: invocation.type,
3774
- contract_address: invocation.contractAddress,
3927
+ sender_address: invocation.contractAddress,
3775
3928
  calldata: invocation.calldata ?? []
3776
3929
  };
3777
3930
  } else if (invocation.type === "DECLARE") {
@@ -3850,13 +4003,13 @@ ${res.tx_failure_reason.error_message}` : res.tx_status;
3850
4003
  };
3851
4004
  return this.fetchEndpoint("estimate_message_fee", { blockIdentifier }, validCallL1Handler);
3852
4005
  }
3853
- async getSimulateTransaction(invocation, invocationDetails, blockIdentifier = this.blockIdentifier) {
4006
+ async getSimulateTransaction(invocation, invocationDetails, blockIdentifier = this.blockIdentifier, skipValidate = false) {
3854
4007
  return this.fetchEndpoint(
3855
4008
  "simulate_transaction",
3856
- { blockIdentifier },
4009
+ { blockIdentifier, skipValidate },
3857
4010
  {
3858
4011
  type: "INVOKE_FUNCTION",
3859
- contract_address: invocation.contractAddress,
4012
+ sender_address: invocation.contractAddress,
3860
4013
  calldata: invocation.calldata ?? [],
3861
4014
  signature: signatureToDecimalArray(invocation.signature),
3862
4015
  version: toHex((invocationDetails == null ? void 0 : invocationDetails.version) || 1),
@@ -3916,11 +4069,12 @@ var Provider = class {
3916
4069
  async getEstimateFee(invocationWithTxType, invocationDetails, blockIdentifier) {
3917
4070
  return this.provider.getEstimateFee(invocationWithTxType, invocationDetails, blockIdentifier);
3918
4071
  }
3919
- async getInvokeEstimateFee(invocationWithTxType, invocationDetails, blockIdentifier) {
4072
+ async getInvokeEstimateFee(invocationWithTxType, invocationDetails, blockIdentifier, skipValidate) {
3920
4073
  return this.provider.getInvokeEstimateFee(
3921
4074
  invocationWithTxType,
3922
4075
  invocationDetails,
3923
- blockIdentifier
4076
+ blockIdentifier,
4077
+ skipValidate
3924
4078
  );
3925
4079
  }
3926
4080
  async getEstimateFeeBulk(invocations, blockIdentifier) {
@@ -3950,11 +4104,16 @@ var Provider = class {
3950
4104
  async declareContract(transaction, details) {
3951
4105
  return this.provider.declareContract(transaction, details);
3952
4106
  }
3953
- async getDeclareEstimateFee(transaction, details, blockIdentifier) {
3954
- return this.provider.getDeclareEstimateFee(transaction, details, blockIdentifier);
4107
+ async getDeclareEstimateFee(transaction, details, blockIdentifier, skipValidate) {
4108
+ return this.provider.getDeclareEstimateFee(transaction, details, blockIdentifier, skipValidate);
3955
4109
  }
3956
- getDeployAccountEstimateFee(transaction, details, blockIdentifier) {
3957
- return this.provider.getDeployAccountEstimateFee(transaction, details, blockIdentifier);
4110
+ getDeployAccountEstimateFee(transaction, details, blockIdentifier, skipValidate) {
4111
+ return this.provider.getDeployAccountEstimateFee(
4112
+ transaction,
4113
+ details,
4114
+ blockIdentifier,
4115
+ skipValidate
4116
+ );
3958
4117
  }
3959
4118
  async getCode(contractAddress, blockIdentifier) {
3960
4119
  return this.provider.getCode(contractAddress, blockIdentifier);
@@ -3962,8 +4121,13 @@ var Provider = class {
3962
4121
  async waitForTransaction(txHash, options) {
3963
4122
  return this.provider.waitForTransaction(txHash, options);
3964
4123
  }
3965
- async getSimulateTransaction(invocation, invocationDetails, blockIdentifier) {
3966
- return this.provider.getSimulateTransaction(invocation, invocationDetails, blockIdentifier);
4124
+ async getSimulateTransaction(invocation, invocationDetails, blockIdentifier, skipValidate) {
4125
+ return this.provider.getSimulateTransaction(
4126
+ invocation,
4127
+ invocationDetails,
4128
+ blockIdentifier,
4129
+ skipValidate
4130
+ );
3967
4131
  }
3968
4132
  async getStateUpdate(blockIdentifier) {
3969
4133
  return this.provider.getStateUpdate(blockIdentifier);
@@ -4941,14 +5105,23 @@ var Signer = class {
4941
5105
  );
4942
5106
  return starkCurve.sign(msgHash, this.pk);
4943
5107
  }
4944
- async signDeclareTransaction({ classHash, senderAddress, chainId, maxFee, version, nonce }) {
5108
+ async signDeclareTransaction({
5109
+ classHash,
5110
+ senderAddress,
5111
+ chainId,
5112
+ maxFee,
5113
+ version,
5114
+ nonce,
5115
+ compiledClassHash
5116
+ }) {
4945
5117
  const msgHash = calculateDeclareTransactionHash(
4946
5118
  classHash,
4947
5119
  senderAddress,
4948
5120
  version,
4949
5121
  maxFee,
4950
5122
  chainId,
4951
- nonce
5123
+ nonce,
5124
+ compiledClassHash
4952
5125
  );
4953
5126
  return starkCurve.sign(msgHash, this.pk);
4954
5127
  }
@@ -4990,7 +5163,7 @@ var Account = class extends Provider {
4990
5163
  async estimateFee(calls, estimateFeeDetails) {
4991
5164
  return this.estimateInvokeFee(calls, estimateFeeDetails);
4992
5165
  }
4993
- async estimateInvokeFee(calls, { nonce: providedNonce, blockIdentifier } = {}) {
5166
+ async estimateInvokeFee(calls, { nonce: providedNonce, blockIdentifier, skipValidate } = {}) {
4994
5167
  const transactions = Array.isArray(calls) ? calls : [calls];
4995
5168
  const nonce = toBigInt(providedNonce ?? await this.getNonce());
4996
5169
  const version = toBigInt(feeTransactionVersion);
@@ -5006,7 +5179,8 @@ var Account = class extends Provider {
5006
5179
  const response = await super.getInvokeEstimateFee(
5007
5180
  { ...invocation },
5008
5181
  { version, nonce },
5009
- blockIdentifier
5182
+ blockIdentifier,
5183
+ skipValidate
5010
5184
  );
5011
5185
  const suggestedMaxFee = estimatedFeeToMaxFee(response.overall_fee);
5012
5186
  return {
@@ -5014,18 +5188,19 @@ var Account = class extends Provider {
5014
5188
  suggestedMaxFee
5015
5189
  };
5016
5190
  }
5017
- async estimateDeclareFee({ contract, classHash: providedClassHash }, { blockIdentifier, nonce: providedNonce } = {}) {
5191
+ async estimateDeclareFee({ contract, classHash: providedClassHash, casm, compiledClassHash }, { blockIdentifier, nonce: providedNonce, skipValidate } = {}) {
5018
5192
  const nonce = toBigInt(providedNonce ?? await this.getNonce());
5019
- const version = toBigInt(feeTransactionVersion);
5193
+ const version = !isSierra(contract) ? toBigInt(feeTransactionVersion) : transactionVersion_2;
5020
5194
  const chainId = await this.getChainId();
5021
- const payload = await this.buildDeclarePayload(
5022
- { classHash: providedClassHash, contract },
5195
+ const declareContractTransaction = await this.buildDeclarePayload(
5196
+ { classHash: providedClassHash, contract, casm, compiledClassHash },
5023
5197
  { nonce, chainId, version, walletAddress: this.address, maxFee: ZERO }
5024
5198
  );
5025
5199
  const response = await super.getDeclareEstimateFee(
5026
- { ...payload },
5200
+ declareContractTransaction,
5027
5201
  { version, nonce },
5028
- blockIdentifier
5202
+ blockIdentifier,
5203
+ skipValidate
5029
5204
  );
5030
5205
  const suggestedMaxFee = estimatedFeeToMaxFee(response.overall_fee);
5031
5206
  return {
@@ -5038,7 +5213,7 @@ var Account = class extends Provider {
5038
5213
  addressSalt = 0,
5039
5214
  constructorCalldata = [],
5040
5215
  contractAddress: providedContractAddress
5041
- }, { blockIdentifier } = {}) {
5216
+ }, { blockIdentifier, skipValidate } = {}) {
5042
5217
  const version = toBigInt(feeTransactionVersion);
5043
5218
  const nonce = ZERO;
5044
5219
  const chainId = await this.getChainId();
@@ -5049,7 +5224,8 @@ var Account = class extends Provider {
5049
5224
  const response = await super.getDeployAccountEstimateFee(
5050
5225
  { ...payload },
5051
5226
  { version, nonce },
5052
- blockIdentifier
5227
+ blockIdentifier,
5228
+ skipValidate
5053
5229
  );
5054
5230
  const suggestedMaxFee = estimatedFeeToMaxFee(response.overall_fee);
5055
5231
  return {
@@ -5165,32 +5341,24 @@ var Account = class extends Provider {
5165
5341
  }
5166
5342
  );
5167
5343
  }
5168
- async declare({ contract, classHash: providedClassHash }, transactionsDetail = {}) {
5169
- const nonce = toBigInt(transactionsDetail.nonce ?? await this.getNonce());
5170
- const classHash = providedClassHash ?? computeContractClassHash(contract);
5171
- const maxFee = transactionsDetail.maxFee ?? await this.getSuggestedMaxFee(
5172
- { type: "DECLARE" /* DECLARE */, payload: { classHash, contract } },
5344
+ async declare(payload, transactionsDetail = {}) {
5345
+ const declareContractPayload = extractContractHashes(payload);
5346
+ const details = {};
5347
+ details.nonce = toBigInt(transactionsDetail.nonce ?? await this.getNonce());
5348
+ details.maxFee = transactionsDetail.maxFee ?? await this.getSuggestedMaxFee(
5349
+ {
5350
+ type: "DECLARE" /* DECLARE */,
5351
+ payload: declareContractPayload
5352
+ },
5173
5353
  transactionsDetail
5174
5354
  );
5175
- const version = toBigInt(transactionVersion);
5176
- const chainId = await this.getChainId();
5177
- const signature = await this.signer.signDeclareTransaction({
5178
- classHash,
5179
- senderAddress: this.address,
5180
- chainId,
5181
- maxFee,
5182
- version,
5183
- nonce
5355
+ details.version = !isSierra(payload.contract) ? transactionVersion : transactionVersion_2;
5356
+ details.chainId = await this.getChainId();
5357
+ const declareContractTransaction = await this.buildDeclarePayload(declareContractPayload, {
5358
+ ...details,
5359
+ walletAddress: this.address
5184
5360
  });
5185
- const contractDefinition = parseContract(contract);
5186
- return this.declareContract(
5187
- { contractDefinition, senderAddress: this.address, signature },
5188
- {
5189
- nonce,
5190
- maxFee,
5191
- version
5192
- }
5193
- );
5361
+ return this.declareContract(declareContractTransaction, details);
5194
5362
  }
5195
5363
  async deploy(payload, details) {
5196
5364
  const params = [].concat(payload).map((it) => {
@@ -5331,11 +5499,12 @@ var Account = class extends Provider {
5331
5499
  }
5332
5500
  return feeEstimate.suggestedMaxFee.toString();
5333
5501
  }
5334
- async buildDeclarePayload({ classHash: providedClassHash, contract }, { nonce, chainId, version, walletAddress, maxFee }) {
5502
+ async buildDeclarePayload(payload, { nonce, chainId, version, walletAddress, maxFee }) {
5503
+ const { classHash, contract, compiledClassHash } = extractContractHashes(payload);
5335
5504
  const contractDefinition = parseContract(contract);
5336
- const classHash = providedClassHash ?? computeContractClassHash(contract);
5337
5505
  const signature = await this.signer.signDeclareTransaction({
5338
5506
  classHash,
5507
+ compiledClassHash,
5339
5508
  senderAddress: walletAddress,
5340
5509
  chainId,
5341
5510
  maxFee,
@@ -5345,7 +5514,8 @@ var Account = class extends Provider {
5345
5514
  return {
5346
5515
  senderAddress: walletAddress,
5347
5516
  signature,
5348
- contractDefinition
5517
+ contractDefinition,
5518
+ compiledClassHash
5349
5519
  };
5350
5520
  }
5351
5521
  async buildAccountDeployPayload({
@@ -5395,7 +5565,7 @@ var Account = class extends Provider {
5395
5565
  });
5396
5566
  return calls;
5397
5567
  }
5398
- async simulateTransaction(calls, { nonce: providedNonce, blockIdentifier } = {}) {
5568
+ async simulateTransaction(calls, { nonce: providedNonce, blockIdentifier, skipValidate } = {}) {
5399
5569
  const transactions = Array.isArray(calls) ? calls : [calls];
5400
5570
  const nonce = toBigInt(providedNonce ?? await this.getNonce());
5401
5571
  const version = toBigInt(feeTransactionVersion);
@@ -5411,7 +5581,8 @@ var Account = class extends Provider {
5411
5581
  const response = await super.getSimulateTransaction(
5412
5582
  invocation,
5413
5583
  { version, nonce },
5414
- blockIdentifier
5584
+ blockIdentifier,
5585
+ skipValidate
5415
5586
  );
5416
5587
  const suggestedMaxFee = estimatedFeeToMaxFee(response.fee_estimation.overall_fee);
5417
5588
  return {
@@ -5432,7 +5603,7 @@ var AccountInterface = class extends ProviderInterface {
5432
5603
  };
5433
5604
 
5434
5605
  // src/utils/address.ts
5435
- var import_bytes = require("@ethersproject/bytes");
5606
+ var import_utils5 = require("@noble/curves/abstract/utils");
5436
5607
  function addAddressPadding(address) {
5437
5608
  return addHexPrefix(removeHexPrefix(toHex(address)).padStart(64, "0"));
5438
5609
  }
@@ -5446,7 +5617,8 @@ function validateAndParseAddress(address) {
5446
5617
  }
5447
5618
  function getChecksumAddress(address) {
5448
5619
  const chars = removeHexPrefix(validateAndParseAddress(address)).toLowerCase().split("");
5449
- const hashed = (0, import_bytes.arrayify)(keccakBn(address), { hexPad: "left" });
5620
+ const hex = removeHexPrefix(keccakBn(address));
5621
+ const hashed = (0, import_utils5.hexToBytes)(hex.padStart(64, "0"));
5450
5622
  for (let i = 0; i < chars.length; i += 2) {
5451
5623
  if (hashed[i >> 1] >> 4 >= 8) {
5452
5624
  chars[i] = chars[i].toUpperCase();
@@ -5467,9 +5639,11 @@ var number = num_exports;
5467
5639
  0 && (module.exports = {
5468
5640
  Account,
5469
5641
  AccountInterface,
5642
+ CallData,
5470
5643
  Contract,
5471
5644
  ContractFactory,
5472
5645
  ContractInterface,
5646
+ EntryPointType,
5473
5647
  GatewayError,
5474
5648
  HttpError,
5475
5649
  LibraryError,