starknet 5.13.2 → 5.14.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/dist/index.js CHANGED
@@ -55,19 +55,25 @@ __export(src_exports, {
55
55
  buildUrl: () => buildUrl,
56
56
  cairo: () => cairo_exports,
57
57
  constants: () => constants_exports,
58
+ contractClassResponseToLegacyCompiledContract: () => contractClassResponseToLegacyCompiledContract,
58
59
  defaultProvider: () => defaultProvider,
59
60
  ec: () => ec_exports,
60
61
  encode: () => encode_exports,
62
+ extractContractHashes: () => extractContractHashes,
61
63
  fixProto: () => fixProto,
62
64
  fixStack: () => fixStack,
63
65
  getCalldata: () => getCalldata,
64
66
  getChecksumAddress: () => getChecksumAddress,
65
67
  hash: () => hash_exports,
68
+ isSierra: () => isSierra,
66
69
  isUrl: () => isUrl,
67
70
  json: () => json_exports,
68
71
  merkle: () => merkle_exports,
69
72
  num: () => num_exports,
70
73
  number: () => number,
74
+ parseUDCEvent: () => parseUDCEvent,
75
+ provider: () => provider_exports,
76
+ selector: () => selector_exports,
71
77
  shortString: () => shortString_exports,
72
78
  splitArgsAndOptions: () => splitArgsAndOptions,
73
79
  stark: () => stark_exports,
@@ -2400,6 +2406,13 @@ function hexToBytes(value) {
2400
2406
  }
2401
2407
 
2402
2408
  // src/utils/selector.ts
2409
+ var selector_exports = {};
2410
+ __export(selector_exports, {
2411
+ getSelector: () => getSelector,
2412
+ getSelectorFromName: () => getSelectorFromName,
2413
+ keccakBn: () => keccakBn,
2414
+ starknetKeccak: () => starknetKeccak
2415
+ });
2403
2416
  var import_micro_starknet = require("micro-starknet");
2404
2417
  function keccakBn(value) {
2405
2418
  const hexWithoutPrefix = removeHexPrefix(toHex(BigInt(value)));
@@ -2483,6 +2496,7 @@ __export(cairo_exports, {
2483
2496
  Uint: () => Uint,
2484
2497
  felt: () => felt,
2485
2498
  getArrayType: () => getArrayType,
2499
+ isCairo1Abi: () => isCairo1Abi,
2486
2500
  isCairo1Type: () => isCairo1Type,
2487
2501
  isLen: () => isLen,
2488
2502
  isTypeArray: () => isTypeArray,
@@ -2552,6 +2566,19 @@ var getArrayType = (type) => {
2552
2566
  }
2553
2567
  return type.replace("*", "");
2554
2568
  };
2569
+ function isCairo1Abi(abi) {
2570
+ const firstFunction = abi.find((entry) => entry.type === "function");
2571
+ if (!firstFunction) {
2572
+ throw new Error(`Error in ABI. No function in ABI.`);
2573
+ }
2574
+ if (firstFunction.inputs.length) {
2575
+ return isCairo1Type(firstFunction.inputs[0].type);
2576
+ }
2577
+ if (firstFunction.outputs.length) {
2578
+ return isCairo1Type(firstFunction.outputs[0].type);
2579
+ }
2580
+ throw new Error(`Error in ABI. No input/output in function ${firstFunction.name}`);
2581
+ }
2555
2582
  var uint256 = (it) => {
2556
2583
  const bn = BigInt(it);
2557
2584
  if (!isUint256(bn))
@@ -3602,34 +3629,6 @@ function computeContractClassHash(contract) {
3602
3629
  return computeLegacyContractClassHash(compiledContract);
3603
3630
  }
3604
3631
 
3605
- // src/utils/contract.ts
3606
- function isSierra(contract) {
3607
- const compiledContract = typeof contract === "string" ? parse2(contract) : contract;
3608
- return "sierra_program" in compiledContract;
3609
- }
3610
- function extractContractHashes(payload) {
3611
- const response = { ...payload };
3612
- if (isSierra(payload.contract)) {
3613
- if (!payload.compiledClassHash && payload.casm) {
3614
- response.compiledClassHash = computeCompiledClassHash(payload.casm);
3615
- }
3616
- if (!response.compiledClassHash)
3617
- throw new Error(
3618
- "Extract compiledClassHash failed, provide (CairoAssembly).casm file or compiledClassHash"
3619
- );
3620
- }
3621
- response.classHash = payload.classHash ?? computeContractClassHash(payload.contract);
3622
- if (!response.classHash)
3623
- throw new Error("Extract classHash failed, provide (CompiledContract).json file or classHash");
3624
- return response;
3625
- }
3626
-
3627
- // src/utils/fetchPonyfill.ts
3628
- var import_isomorphic_fetch = __toESM(require("isomorphic-fetch"));
3629
- var fetchPonyfill_default = typeof window !== "undefined" && window.fetch || // use buildin fetch in browser if available
3630
- typeof global !== "undefined" && global.fetch || // use buildin fetch in node, react-native and service worker if available
3631
- import_isomorphic_fetch.default;
3632
-
3633
3632
  // src/utils/stark.ts
3634
3633
  var stark_exports = {};
3635
3634
  __export(stark_exports, {
@@ -3686,7 +3685,48 @@ function estimatedFeeToMaxFee(estimatedFee, overhead = 0.5) {
3686
3685
  return toBigInt(estimatedFee) * toBigInt(overHeadPercent) / 100n;
3687
3686
  }
3688
3687
 
3688
+ // src/utils/contract.ts
3689
+ function isSierra(contract) {
3690
+ const compiledContract = typeof contract === "string" ? parse2(contract) : contract;
3691
+ return "sierra_program" in compiledContract;
3692
+ }
3693
+ function extractContractHashes(payload) {
3694
+ const response = { ...payload };
3695
+ if (isSierra(payload.contract)) {
3696
+ if (!payload.compiledClassHash && payload.casm) {
3697
+ response.compiledClassHash = computeCompiledClassHash(payload.casm);
3698
+ }
3699
+ if (!response.compiledClassHash)
3700
+ throw new Error(
3701
+ "Extract compiledClassHash failed, provide (CairoAssembly).casm file or compiledClassHash"
3702
+ );
3703
+ }
3704
+ response.classHash = payload.classHash ?? computeContractClassHash(payload.contract);
3705
+ if (!response.classHash)
3706
+ throw new Error("Extract classHash failed, provide (CompiledContract).json file or classHash");
3707
+ return response;
3708
+ }
3709
+ function contractClassResponseToLegacyCompiledContract(ccr) {
3710
+ if (isSierra(ccr)) {
3711
+ throw Error("ContractClassResponse need to be LegacyContractClass (cairo0 response class)");
3712
+ }
3713
+ const contract = ccr;
3714
+ return { ...contract, program: decompressProgram(contract.program) };
3715
+ }
3716
+
3717
+ // src/utils/fetchPonyfill.ts
3718
+ var import_isomorphic_fetch = __toESM(require("isomorphic-fetch"));
3719
+ var fetchPonyfill_default = typeof window !== "undefined" && window.fetch || // use buildin fetch in browser if available
3720
+ typeof global !== "undefined" && global.fetch || // use buildin fetch in node, react-native and service worker if available
3721
+ import_isomorphic_fetch.default;
3722
+
3689
3723
  // src/utils/provider.ts
3724
+ var provider_exports = {};
3725
+ __export(provider_exports, {
3726
+ createSierraContractClass: () => createSierraContractClass,
3727
+ parseContract: () => parseContract,
3728
+ wait: () => wait
3729
+ });
3690
3730
  function wait(delay) {
3691
3731
  return new Promise((res) => {
3692
3732
  setTimeout(res, delay);
@@ -3705,7 +3745,6 @@ function parseContract(contract) {
3705
3745
  if (!isSierra(contract)) {
3706
3746
  return {
3707
3747
  ...parsedContract,
3708
- // TODO: Why do we gzip program object?
3709
3748
  ..."program" in parsedContract && { program: compressProgram(parsedContract.program) }
3710
3749
  };
3711
3750
  }
@@ -4197,14 +4236,13 @@ var RpcProvider = class {
4197
4236
  }
4198
4237
  async declareContract({ contract, signature, senderAddress, compiledClassHash }, details) {
4199
4238
  if (!isSierra(contract)) {
4200
- const legacyContract = contract;
4201
4239
  return this.fetchEndpoint("starknet_addDeclareTransaction", {
4202
4240
  declare_transaction: {
4203
4241
  type: RPC.TransactionType.DECLARE,
4204
4242
  contract_class: {
4205
- program: legacyContract.program,
4206
- entry_points_by_type: legacyContract.entry_points_by_type,
4207
- abi: legacyContract.abi
4243
+ program: contract.program,
4244
+ entry_points_by_type: contract.entry_points_by_type,
4245
+ abi: contract.abi
4208
4246
  },
4209
4247
  version: toHex(transactionVersion),
4210
4248
  max_fee: toHex(details.maxFee || 0),
@@ -4214,15 +4252,14 @@ var RpcProvider = class {
4214
4252
  }
4215
4253
  });
4216
4254
  }
4217
- const sierraContract = contract;
4218
4255
  return this.fetchEndpoint("starknet_addDeclareTransaction", {
4219
4256
  declare_transaction: {
4220
4257
  type: RPC.TransactionType.DECLARE,
4221
4258
  contract_class: {
4222
- sierra_program: decompressProgram(sierraContract.sierra_program),
4223
- contract_class_version: sierraContract.contract_class_version,
4224
- entry_points_by_type: sierraContract.entry_points_by_type,
4225
- abi: sierraContract.abi
4259
+ sierra_program: decompressProgram(contract.sierra_program),
4260
+ contract_class_version: contract.contract_class_version,
4261
+ entry_points_by_type: contract.entry_points_by_type,
4262
+ abi: contract.abi
4226
4263
  },
4227
4264
  compiled_class_hash: compiledClassHash || "",
4228
4265
  version: toHex(transactionVersion_2),
@@ -6263,6 +6300,9 @@ var Contract = class {
6263
6300
  calldata
6264
6301
  };
6265
6302
  }
6303
+ isCairo1() {
6304
+ return cairo_exports.isCairo1Abi(this.abi);
6305
+ }
6266
6306
  };
6267
6307
 
6268
6308
  // src/contract/interface.ts
@@ -6393,19 +6433,25 @@ var number = num_exports;
6393
6433
  buildUrl,
6394
6434
  cairo,
6395
6435
  constants,
6436
+ contractClassResponseToLegacyCompiledContract,
6396
6437
  defaultProvider,
6397
6438
  ec,
6398
6439
  encode,
6440
+ extractContractHashes,
6399
6441
  fixProto,
6400
6442
  fixStack,
6401
6443
  getCalldata,
6402
6444
  getChecksumAddress,
6403
6445
  hash,
6446
+ isSierra,
6404
6447
  isUrl,
6405
6448
  json,
6406
6449
  merkle,
6407
6450
  num,
6408
6451
  number,
6452
+ parseUDCEvent,
6453
+ provider,
6454
+ selector,
6409
6455
  shortString,
6410
6456
  splitArgsAndOptions,
6411
6457
  stark,