starknet 6.3.0 → 6.4.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
@@ -2449,6 +2449,7 @@ __export(hash_exports, {
2449
2449
  formatSpaces: () => formatSpaces,
2450
2450
  getSelector: () => getSelector,
2451
2451
  getSelectorFromName: () => getSelectorFromName,
2452
+ hashByteCodeSegments: () => hashByteCodeSegments,
2452
2453
  keccakBn: () => keccakBn,
2453
2454
  poseidon: () => poseidon,
2454
2455
  starknetKeccak: () => starknetKeccak
@@ -2835,13 +2836,23 @@ function hashEntryPoint(data) {
2835
2836
  });
2836
2837
  return (0, import_starknet3.poseidonHashMany)(base);
2837
2838
  }
2839
+ function hashByteCodeSegments(casm) {
2840
+ const byteCode = casm.bytecode.map((n) => BigInt(n));
2841
+ const bytecodeSegmentLengths = casm.bytecode_segment_lengths ?? [];
2842
+ let segmentStart = 0;
2843
+ const hashLeaves = bytecodeSegmentLengths.flatMap((len) => {
2844
+ const segment = byteCode.slice(segmentStart, segmentStart += len);
2845
+ return [BigInt(len), (0, import_starknet3.poseidonHashMany)(segment)];
2846
+ });
2847
+ return 1n + (0, import_starknet3.poseidonHashMany)(hashLeaves);
2848
+ }
2838
2849
  function computeCompiledClassHash(casm) {
2839
2850
  const COMPILED_CLASS_VERSION = "COMPILED_CLASS_V1";
2840
2851
  const compiledClassVersion = BigInt(encodeShortString(COMPILED_CLASS_VERSION));
2841
2852
  const externalEntryPointsHash = hashEntryPoint(casm.entry_points_by_type.EXTERNAL);
2842
2853
  const l1Handlers = hashEntryPoint(casm.entry_points_by_type.L1_HANDLER);
2843
2854
  const constructor = hashEntryPoint(casm.entry_points_by_type.CONSTRUCTOR);
2844
- const bytecode = (0, import_starknet3.poseidonHashMany)(casm.bytecode.map((it) => BigInt(it)));
2855
+ const bytecode = casm.bytecode_segment_lengths ? hashByteCodeSegments(casm) : (0, import_starknet3.poseidonHashMany)(casm.bytecode.map((it) => BigInt(it)));
2845
2856
  return toHex(
2846
2857
  (0, import_starknet3.poseidonHashMany)([
2847
2858
  compiledClassVersion,
@@ -5258,11 +5269,18 @@ function getMerkleTreeType(types, ctx) {
5258
5269
  return "raw";
5259
5270
  }
5260
5271
  function encodeType(types, type, revision = "0" /* Legacy */) {
5261
- const [primary, ...dependencies] = getDependencies(types, type, void 0, void 0, revision);
5272
+ const allTypes = revision === "1" /* Active */ ? { ...types, ...revisionConfiguration[revision].presetTypes } : types;
5273
+ const [primary, ...dependencies] = getDependencies(
5274
+ allTypes,
5275
+ type,
5276
+ void 0,
5277
+ void 0,
5278
+ revision
5279
+ );
5262
5280
  const newTypes = !primary ? [] : [primary, ...dependencies.sort()];
5263
5281
  const esc = revisionConfiguration[revision].escapeTypeString;
5264
5282
  return newTypes.map((dependency) => {
5265
- const dependencyElements = types[dependency].map((t) => {
5283
+ const dependencyElements = allTypes[dependency].map((t) => {
5266
5284
  const targetType = t.type === "enum" && revision === "1" /* Active */ ? t.contains : t.type;
5267
5285
  const typeString = targetType.match(/^\(.*\)$/) ? `(${targetType.slice(1, -1).split(",").map((e) => e ? esc(e) : e).join(",")})` : esc(targetType);
5268
5286
  return `${esc(t.name)}:${typeString}`;
@@ -5660,7 +5678,12 @@ var Account = class extends RpcProvider2 {
5660
5678
  return this.estimateInvokeFee(calls, estimateFeeDetails);
5661
5679
  }
5662
5680
  async estimateInvokeFee(calls, details = {}) {
5663
- const { nonce: providedNonce, blockIdentifier, version: providedVersion } = details;
5681
+ const {
5682
+ nonce: providedNonce,
5683
+ blockIdentifier,
5684
+ version: providedVersion,
5685
+ skipValidate = true
5686
+ } = details;
5664
5687
  const transactions = Array.isArray(calls) ? calls : [calls];
5665
5688
  const nonce = toBigInt(providedNonce ?? await this.getNonce());
5666
5689
  const version = toTransactionVersion(
@@ -5675,7 +5698,8 @@ var Account = class extends RpcProvider2 {
5675
5698
  maxFee: ZERO,
5676
5699
  version,
5677
5700
  chainId,
5678
- cairoVersion: await this.getCairoVersion()
5701
+ cairoVersion: await this.getCairoVersion(),
5702
+ skipValidate
5679
5703
  };
5680
5704
  const invocation = await this.buildInvocation(transactions, signerDetails);
5681
5705
  return super.getInvokeEstimateFee(
@@ -5686,7 +5710,12 @@ var Account = class extends RpcProvider2 {
5686
5710
  );
5687
5711
  }
5688
5712
  async estimateDeclareFee(payload, details = {}) {
5689
- const { blockIdentifier, nonce: providedNonce, version: providedVersion } = details;
5713
+ const {
5714
+ blockIdentifier,
5715
+ nonce: providedNonce,
5716
+ version: providedVersion,
5717
+ skipValidate = true
5718
+ } = details;
5690
5719
  const nonce = toBigInt(providedNonce ?? await this.getNonce());
5691
5720
  const version = toTransactionVersion(
5692
5721
  !isSierra(payload.contract) ? "0x100000000000000000000000000000001" /* F1 */ : this.getPreferredVersion("0x100000000000000000000000000000002" /* F2 */, "0x100000000000000000000000000000003" /* F3 */),
@@ -5700,8 +5729,9 @@ var Account = class extends RpcProvider2 {
5700
5729
  version,
5701
5730
  walletAddress: this.address,
5702
5731
  maxFee: ZERO,
5703
- cairoVersion: void 0
5732
+ cairoVersion: void 0,
5704
5733
  // unused parameter
5734
+ skipValidate
5705
5735
  });
5706
5736
  return super.getDeclareEstimateFee(
5707
5737
  declareContractTransaction,
@@ -5716,7 +5746,7 @@ var Account = class extends RpcProvider2 {
5716
5746
  constructorCalldata = [],
5717
5747
  contractAddress
5718
5748
  }, details = {}) {
5719
- const { blockIdentifier, version: providedVersion } = details;
5749
+ const { blockIdentifier, version: providedVersion, skipValidate = true } = details;
5720
5750
  const version = toTransactionVersion(
5721
5751
  this.getPreferredVersion("0x100000000000000000000000000000001" /* F1 */, "0x100000000000000000000000000000003" /* F3 */),
5722
5752
  toFeeVersion(providedVersion)
@@ -5733,8 +5763,9 @@ var Account = class extends RpcProvider2 {
5733
5763
  walletAddress: this.address,
5734
5764
  // unused parameter
5735
5765
  maxFee: ZERO,
5736
- cairoVersion: void 0
5766
+ cairoVersion: void 0,
5737
5767
  // unused parameter,
5768
+ skipValidate
5738
5769
  }
5739
5770
  );
5740
5771
  return super.getDeployAccountEstimateFee(
@@ -5770,7 +5801,7 @@ var Account = class extends RpcProvider2 {
5770
5801
  });
5771
5802
  }
5772
5803
  async simulateTransaction(invocations, details = {}) {
5773
- const { nonce, blockIdentifier, skipValidate, skipExecute, version } = details;
5804
+ const { nonce, blockIdentifier, skipValidate = true, skipExecute, version } = details;
5774
5805
  const accountInvocations = await this.accountInvocationsFactory(invocations, {
5775
5806
  ...v3Details(details),
5776
5807
  versions: [
@@ -5782,7 +5813,8 @@ var Account = class extends RpcProvider2 {
5782
5813
  )
5783
5814
  ],
5784
5815
  nonce,
5785
- blockIdentifier
5816
+ blockIdentifier,
5817
+ skipValidate
5786
5818
  });
5787
5819
  return super.getSimulateTransaction(accountInvocations, {
5788
5820
  blockIdentifier,
@@ -6068,7 +6100,7 @@ var Account = class extends RpcProvider2 {
6068
6100
  }
6069
6101
  async buildInvocation(call, details) {
6070
6102
  const calldata = getExecuteCalldata(call, await this.getCairoVersion());
6071
- const signature = await this.signer.signTransaction(call, details);
6103
+ const signature = !details.skipValidate ? await this.signer.signTransaction(call, details) : [];
6072
6104
  return {
6073
6105
  ...v3Details(details),
6074
6106
  contractAddress: this.address,
@@ -6082,14 +6114,14 @@ var Account = class extends RpcProvider2 {
6082
6114
  if (typeof compiledClassHash === "undefined" && (details.version === "0x100000000000000000000000000000003" /* F3 */ || details.version === "0x3" /* V3 */)) {
6083
6115
  throw Error("V3 Transaction work with Cairo1 Contracts and require compiledClassHash");
6084
6116
  }
6085
- const signature = await this.signer.signDeclareTransaction({
6117
+ const signature = !details.skipValidate ? await this.signer.signDeclareTransaction({
6086
6118
  ...details,
6087
6119
  ...v3Details(details),
6088
6120
  classHash,
6089
6121
  compiledClassHash,
6090
- // TODO: TS Nekuzi da v2 nemora imat a v3 mora i da je throvano ako nije definiran
6122
+ // TODO: TS, cast because optional for v2 and required for v3, thrown if not present
6091
6123
  senderAddress: details.walletAddress
6092
- });
6124
+ }) : [];
6093
6125
  return {
6094
6126
  senderAddress: details.walletAddress,
6095
6127
  signature,
@@ -6105,14 +6137,14 @@ var Account = class extends RpcProvider2 {
6105
6137
  }, details) {
6106
6138
  const compiledCalldata = CallData.compile(constructorCalldata);
6107
6139
  const contractAddress = providedContractAddress ?? calculateContractAddressFromHash(addressSalt, classHash, compiledCalldata, 0);
6108
- const signature = await this.signer.signDeployAccountTransaction({
6140
+ const signature = !details.skipValidate ? await this.signer.signDeployAccountTransaction({
6109
6141
  ...details,
6110
6142
  ...v3Details(details),
6111
6143
  classHash,
6112
6144
  contractAddress,
6113
6145
  addressSalt,
6114
6146
  constructorCalldata: compiledCalldata
6115
- });
6147
+ }) : [];
6116
6148
  return {
6117
6149
  ...v3Details(details),
6118
6150
  classHash,
@@ -6145,7 +6177,7 @@ var Account = class extends RpcProvider2 {
6145
6177
  return calls;
6146
6178
  }
6147
6179
  async accountInvocationsFactory(invocations, details) {
6148
- const { nonce, blockIdentifier } = details;
6180
+ const { nonce, blockIdentifier, skipValidate = true } = details;
6149
6181
  const safeNonce = await this.getNonceSafe(nonce);
6150
6182
  const chainId = await this.getChainId();
6151
6183
  const versions = details.versions.map((it) => toTransactionVersion(it));
@@ -6161,7 +6193,8 @@ var Account = class extends RpcProvider2 {
6161
6193
  maxFee: ZERO,
6162
6194
  chainId,
6163
6195
  cairoVersion,
6164
- version: ""
6196
+ version: "",
6197
+ skipValidate
6165
6198
  };
6166
6199
  const common = {
6167
6200
  type: transaction.type,