starknet 10.2.0 → 10.3.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.
@@ -5919,8 +5919,11 @@ ${indent}}` : "}";
5919
5919
  var isLen = (name) => /_len$/.test(name);
5920
5920
  var isTypeFelt = (type) => type === "felt" || type === "core::felt252";
5921
5921
  var isTypeArray = (type) => /\*/.test(type) || type.startsWith("core::array::Array::") || type.startsWith("core::array::Span::");
5922
- var isTypeTuple = (type) => /^\(.*\)$/i.test(type);
5923
- var isTypeNamedTuple = (type) => /\(.*\)/i.test(type) && type.includes(":");
5922
+ var isTypeTuple = (type) => type.startsWith("(") && type.endsWith(")");
5923
+ var isTypeNamedTuple = (type) => {
5924
+ const start = type.indexOf("(");
5925
+ return start !== -1 && type.indexOf(")", start + 1) !== -1 && type.includes(":");
5926
+ };
5924
5927
  var isTypeStruct = (type, structs) => type in structs;
5925
5928
  var isTypeEnum = (type, enums) => type in enums;
5926
5929
  var isTypeOption = (type) => type.startsWith("core::option::Option::");
@@ -5936,7 +5939,7 @@ ${indent}}` : "}";
5936
5939
  var isTypeSecp256k1Point = (type) => type === Literal.Secp256k1Point;
5937
5940
  var isCairo1Type = (type) => type.includes("::");
5938
5941
  var getArrayType = (type) => {
5939
- return isCairo1Type(type) ? type.substring(type.indexOf("<") + 1, type.lastIndexOf(">")) : type.replace("*", "");
5942
+ return isCairo1Type(type) ? type.substring(type.indexOf("<") + 1, type.lastIndexOf(">")) : type.replaceAll("*", "");
5940
5943
  };
5941
5944
  function isCairo1Abi(abi) {
5942
5945
  const { cairo } = getAbiContractVersion(abi);
@@ -7737,6 +7740,18 @@ ${indent}}` : "}";
7737
7740
  * Cairo fixed array type.
7738
7741
  */
7739
7742
  arrayType;
7743
+ static parseFixedArrayType(type) {
7744
+ if (!type.startsWith("[") || !type.endsWith("]")) {
7745
+ return void 0;
7746
+ }
7747
+ const separator = type.lastIndexOf("; ");
7748
+ const itemType = type.slice(1, separator);
7749
+ const size = type.slice(separator + 2, -1);
7750
+ if (separator <= 1 || size.length === 0 || ![...size].every((char) => char >= "0" && char <= "9")) {
7751
+ return void 0;
7752
+ }
7753
+ return { itemType, size };
7754
+ }
7740
7755
  /**
7741
7756
  * Create an instance representing a Cairo fixed Array.
7742
7757
  * @param {any[]} content JS array representing a Cairo fixed array.
@@ -7780,10 +7795,10 @@ ${indent}}` : "}";
7780
7795
  * ```
7781
7796
  */
7782
7797
  static getFixedArraySize(type) {
7783
- const matchArray = type.match(/(?<=; )\d+(?=\])/);
7784
- if (matchArray === null)
7798
+ const fixedArrayType = _CairoFixedArray.parseFixedArrayType(type);
7799
+ if (!fixedArrayType)
7785
7800
  throw new Error(`ABI type ${type} do not includes a valid number after ';' character.`);
7786
- return Number(matchArray[0]);
7801
+ return Number(fixedArrayType.size);
7787
7802
  }
7788
7803
  /**
7789
7804
  * Retrieves the Cairo fixed array size from the CairoFixedArray instance.
@@ -7809,10 +7824,9 @@ ${indent}}` : "}";
7809
7824
  * ```
7810
7825
  */
7811
7826
  static getFixedArrayType = (type) => {
7812
- const matchArray = type.match(/(?<=\[).+(?=;)/);
7813
- if (matchArray === null)
7814
- throw new Error(`ABI type ${type} do not includes a valid type of data.`);
7815
- return matchArray[0];
7827
+ const fixedArrayType = _CairoFixedArray.parseFixedArrayType(type);
7828
+ if (!fixedArrayType) throw new Error(`ABI type ${type} do not includes a valid type of data.`);
7829
+ return fixedArrayType.itemType;
7816
7830
  };
7817
7831
  /**
7818
7832
  * Retrieve the Cairo content type of the Cairo fixed array.
@@ -7870,7 +7884,7 @@ ${indent}}` : "}";
7870
7884
  * // result = true
7871
7885
  */
7872
7886
  static isTypeFixedArray(type) {
7873
- return /^\[.*;\s.*\]$/.test(type) && /(?<=\[).+(?=;)/.test(type) && /(?<=; )\d+(?=\])/.test(type);
7887
+ return _CairoFixedArray.parseFixedArrayType(type) !== void 0;
7874
7888
  }
7875
7889
  };
7876
7890
 
@@ -8538,7 +8552,7 @@ ${indent}}` : "}";
8538
8552
  parsedDataArr.push(
8539
8553
  parseResponseValue(
8540
8554
  responseIterator,
8541
- { name, type: output.type.replace("*", "") },
8555
+ { name, type: output.type.replaceAll("*", "") },
8542
8556
  parser,
8543
8557
  structs,
8544
8558
  enums
@@ -11580,6 +11594,12 @@ ${indent}}` : "}";
11580
11594
  });
11581
11595
  return this.waitMode ? this.waitForTransaction((await promise).transaction_hash) : promise;
11582
11596
  }
11597
+ async invokeSignedTx(transaction) {
11598
+ const promise = this.fetchEndpoint("starknet_addInvokeTransaction", {
11599
+ invoke_transaction: transaction
11600
+ });
11601
+ return this.waitMode ? this.waitForTransaction((await promise).transaction_hash) : promise;
11602
+ }
11583
11603
  async declare(declareTransaction, details) {
11584
11604
  const transaction = await this.buildTransaction(
11585
11605
  {
@@ -12273,6 +12293,12 @@ ${indent}}` : "}";
12273
12293
  });
12274
12294
  return this.waitMode ? this.waitForTransaction((await promise).transaction_hash) : promise;
12275
12295
  }
12296
+ async invokeSignedTx(transaction) {
12297
+ const promise = this.fetchEndpoint("starknet_addInvokeTransaction", {
12298
+ invoke_transaction: transaction
12299
+ });
12300
+ return this.waitMode ? this.waitForTransaction((await promise).transaction_hash) : promise;
12301
+ }
12276
12302
  async declare(declareTransaction, details) {
12277
12303
  const transaction = await this.buildTransaction(
12278
12304
  {
@@ -14217,7 +14243,19 @@ ${indent}}` : "}";
14217
14243
  });
14218
14244
  }
14219
14245
  function isStarkDomain(domain) {
14220
- return /^(?:[a-z0-9-]{1,48}(?:[a-z0-9-]{1,48}[a-z0-9-])?\.)*[a-z0-9-]{1,48}\.stark$/.test(domain);
14246
+ const starkSuffix = ".stark";
14247
+ if (!domain.endsWith(starkSuffix)) {
14248
+ return false;
14249
+ }
14250
+ const name = domain.slice(0, -starkSuffix.length);
14251
+ if (name.length === 0) {
14252
+ return false;
14253
+ }
14254
+ return name.split(".").every((label) => {
14255
+ return label.length > 0 && label.length <= 48 && [...label].every((char) => {
14256
+ return char >= "a" && char <= "z" || char >= "0" && char <= "9" || char === "-";
14257
+ });
14258
+ });
14221
14259
  }
14222
14260
 
14223
14261
  // src/plugins/starknet-id/index.ts
@@ -14963,6 +15001,34 @@ ${indent}}` : "}";
14963
15001
  async invokeFunction(functionInvocation, details) {
14964
15002
  return this.channel.invoke(functionInvocation, details);
14965
15003
  }
15004
+ /**
15005
+ * Submit a pre-signed INVOKE_TXN_V3 transaction to the network.
15006
+ *
15007
+ * Broadcasts a transaction previously built and signed by `Account.getSignedTransaction()`.
15008
+ * Fees are already included in the signed transaction and will not be re-estimated.
15009
+ *
15010
+ * @param transaction - A fully signed `RPC.INVOKE_TXN_V3` object, as returned by `Account.getSignedTransaction()`
15011
+ *
15012
+ * @returns The transaction hash if `waitMode` is disabled (default), or the transaction receipt if `waitMode` is enabled.
15013
+ *
15014
+ * @remarks
15015
+ * - The transaction must be signed before calling this method ; use `Account.getSignedTransaction()` to produce it.
15016
+ * - Resubmitting the same signed transaction (same nonce) will be rejected by the network.
15017
+ * - If `waitMode` is enabled on the provider, this method waits for the transaction to be included in a block before returning.
15018
+ *
15019
+ * @example
15020
+ * ```typescript
15021
+ * const signedTx = await account.getSignedTransaction([
15022
+ * { contractAddress: erc20Address, entrypoint: 'transfer', calldata: [recipient, amount, 0] }
15023
+ * ]);
15024
+ * // inspect or store signedTx, then submit when ready:
15025
+ * const { transaction_hash } = await provider.invokeSignedTx(signedTx);
15026
+ * await provider.waitForTransaction(transaction_hash);
15027
+ * ```
15028
+ */
15029
+ async invokeSignedTx(transaction) {
15030
+ return this.channel.invokeSignedTx(transaction);
15031
+ }
14966
15032
  async declareContract(transaction, details) {
14967
15033
  return this.channel.declare(transaction, details);
14968
15034
  }
@@ -16841,7 +16907,12 @@ ${indent}}` : "}";
16841
16907
  returnInitialReads
16842
16908
  });
16843
16909
  }
16844
- async execute(transactions, transactionsDetail = {}) {
16910
+ /**
16911
+ * Shared preparation logic for execute() and buildExecute().
16912
+ * Runs hooks, estimates fees, and builds accountInvocations.
16913
+ * @private
16914
+ */
16915
+ async prepareInvoke(transactions, transactionsDetail = {}) {
16845
16916
  const hookResult = this.accountPluginManager.runAccountHook("beforeExecute", {
16846
16917
  calls: transactions,
16847
16918
  details: transactionsDetail
@@ -16866,7 +16937,15 @@ ${indent}}` : "}";
16866
16937
  skipValidate: false
16867
16938
  }
16868
16939
  );
16869
- const invocation = accountInvocations[0];
16940
+ return {
16941
+ invocation: accountInvocations[0],
16942
+ hookedTransactions,
16943
+ hookedDetails,
16944
+ detailsWithTip
16945
+ };
16946
+ }
16947
+ async execute(transactions, transactionsDetail = {}) {
16948
+ const { invocation, hookedTransactions, hookedDetails, detailsWithTip } = await this.prepareInvoke(transactions, transactionsDetail);
16870
16949
  const result = await this.provider.invokeFunction(
16871
16950
  {
16872
16951
  contractAddress: invocation.contractAddress,
@@ -16888,6 +16967,51 @@ ${indent}}` : "}";
16888
16967
  });
16889
16968
  return result;
16890
16969
  }
16970
+ /**
16971
+ * Build a signed INVOKE_TXN_V3 transaction without submitting it to the network.
16972
+ *
16973
+ * Produces a fully signed transaction object that can be inspected, stored,
16974
+ * or submitted later via `provider.channel.sendTransaction()`.
16975
+ * Main usage is to send a virtual transaction to a proof server.
16976
+ * Fees are estimated automatically if not provided.
16977
+ *
16978
+ * @param transactions - Single call or array of calls to include in the transaction
16979
+ * @param transactionsDetail - Transaction execution options
16980
+ * @returns A fully signed `RPC.INVOKE_TXN_V3` object, ready to broadcast
16981
+ *
16982
+ * @remarks
16983
+ * - Unlike `execute()`, this method does **not** submit the transaction ; the account nonce is unchanged after the call.
16984
+ * - The `afterExecute` plugin hook is intentionally **not** triggered.
16985
+ * - The returned object can be broadcast with `provider.channel.sendTransaction()`.
16986
+ *
16987
+ * @example
16988
+ * ```typescript
16989
+ * const signedTx = await account.getSignedTransaction(
16990
+ * { contractAddress: erc20Address, entrypoint: 'transfer', calldata: [recipient, amount, 0] }
16991
+ * );
16992
+ * ```
16993
+ */
16994
+ async getSignedTransaction(transactions, transactionsDetail = {}) {
16995
+ const { invocation, hookedDetails, detailsWithTip } = await this.prepareInvoke(
16996
+ transactions,
16997
+ transactionsDetail
16998
+ );
16999
+ return this.provider.channel.buildTransaction(
17000
+ {
17001
+ type: ETransactionType2.INVOKE,
17002
+ contractAddress: invocation.contractAddress,
17003
+ calldata: invocation.calldata,
17004
+ signature: invocation.signature,
17005
+ ...hookedDetails.proofFacts && { proofFacts: hookedDetails.proofFacts },
17006
+ ...hookedDetails.proof && { proof: hookedDetails.proof },
17007
+ ...v3Details(detailsWithTip),
17008
+ resourceBounds: invocation.resourceBounds,
17009
+ nonce: invocation.nonce,
17010
+ version: invocation.version
17011
+ },
17012
+ "transaction"
17013
+ );
17014
+ }
16891
17015
  /**
16892
17016
  * First check if contract is already declared, if not declare it
16893
17017
  * If contract already declared returned transaction_hash is ''.