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.
package/dist/index.js CHANGED
@@ -1690,8 +1690,11 @@ var CairoUint512 = class _CairoUint512 {
1690
1690
  var isLen = (name) => /_len$/.test(name);
1691
1691
  var isTypeFelt = (type) => type === "felt" || type === "core::felt252";
1692
1692
  var isTypeArray = (type) => /\*/.test(type) || type.startsWith("core::array::Array::") || type.startsWith("core::array::Span::");
1693
- var isTypeTuple = (type) => /^\(.*\)$/i.test(type);
1694
- var isTypeNamedTuple = (type) => /\(.*\)/i.test(type) && type.includes(":");
1693
+ var isTypeTuple = (type) => type.startsWith("(") && type.endsWith(")");
1694
+ var isTypeNamedTuple = (type) => {
1695
+ const start = type.indexOf("(");
1696
+ return start !== -1 && type.indexOf(")", start + 1) !== -1 && type.includes(":");
1697
+ };
1695
1698
  var isTypeStruct = (type, structs) => type in structs;
1696
1699
  var isTypeEnum = (type, enums) => type in enums;
1697
1700
  var isTypeOption = (type) => type.startsWith("core::option::Option::");
@@ -1707,7 +1710,7 @@ var isTypeU96 = (type) => type === "core::internal::bounded_int::BoundedInt::<0,
1707
1710
  var isTypeSecp256k1Point = (type) => type === Literal.Secp256k1Point;
1708
1711
  var isCairo1Type = (type) => type.includes("::");
1709
1712
  var getArrayType = (type) => {
1710
- return isCairo1Type(type) ? type.substring(type.indexOf("<") + 1, type.lastIndexOf(">")) : type.replace("*", "");
1713
+ return isCairo1Type(type) ? type.substring(type.indexOf("<") + 1, type.lastIndexOf(">")) : type.replaceAll("*", "");
1711
1714
  };
1712
1715
  function isCairo1Abi(abi) {
1713
1716
  const { cairo } = getAbiContractVersion(abi);
@@ -3510,6 +3513,18 @@ var CairoFixedArray = class _CairoFixedArray {
3510
3513
  * Cairo fixed array type.
3511
3514
  */
3512
3515
  arrayType;
3516
+ static parseFixedArrayType(type) {
3517
+ if (!type.startsWith("[") || !type.endsWith("]")) {
3518
+ return void 0;
3519
+ }
3520
+ const separator = type.lastIndexOf("; ");
3521
+ const itemType = type.slice(1, separator);
3522
+ const size = type.slice(separator + 2, -1);
3523
+ if (separator <= 1 || size.length === 0 || ![...size].every((char) => char >= "0" && char <= "9")) {
3524
+ return void 0;
3525
+ }
3526
+ return { itemType, size };
3527
+ }
3513
3528
  /**
3514
3529
  * Create an instance representing a Cairo fixed Array.
3515
3530
  * @param {any[]} content JS array representing a Cairo fixed array.
@@ -3553,10 +3568,10 @@ var CairoFixedArray = class _CairoFixedArray {
3553
3568
  * ```
3554
3569
  */
3555
3570
  static getFixedArraySize(type) {
3556
- const matchArray = type.match(/(?<=; )\d+(?=\])/);
3557
- if (matchArray === null)
3571
+ const fixedArrayType = _CairoFixedArray.parseFixedArrayType(type);
3572
+ if (!fixedArrayType)
3558
3573
  throw new Error(`ABI type ${type} do not includes a valid number after ';' character.`);
3559
- return Number(matchArray[0]);
3574
+ return Number(fixedArrayType.size);
3560
3575
  }
3561
3576
  /**
3562
3577
  * Retrieves the Cairo fixed array size from the CairoFixedArray instance.
@@ -3582,10 +3597,9 @@ var CairoFixedArray = class _CairoFixedArray {
3582
3597
  * ```
3583
3598
  */
3584
3599
  static getFixedArrayType = (type) => {
3585
- const matchArray = type.match(/(?<=\[).+(?=;)/);
3586
- if (matchArray === null)
3587
- throw new Error(`ABI type ${type} do not includes a valid type of data.`);
3588
- return matchArray[0];
3600
+ const fixedArrayType = _CairoFixedArray.parseFixedArrayType(type);
3601
+ if (!fixedArrayType) throw new Error(`ABI type ${type} do not includes a valid type of data.`);
3602
+ return fixedArrayType.itemType;
3589
3603
  };
3590
3604
  /**
3591
3605
  * Retrieve the Cairo content type of the Cairo fixed array.
@@ -3643,7 +3657,7 @@ var CairoFixedArray = class _CairoFixedArray {
3643
3657
  * // result = true
3644
3658
  */
3645
3659
  static isTypeFixedArray(type) {
3646
- return /^\[.*;\s.*\]$/.test(type) && /(?<=\[).+(?=;)/.test(type) && /(?<=; )\d+(?=\])/.test(type);
3660
+ return _CairoFixedArray.parseFixedArrayType(type) !== void 0;
3647
3661
  }
3648
3662
  };
3649
3663
 
@@ -4311,7 +4325,7 @@ function responseParser({
4311
4325
  parsedDataArr.push(
4312
4326
  parseResponseValue(
4313
4327
  responseIterator,
4314
- { name, type: output.type.replace("*", "") },
4328
+ { name, type: output.type.replaceAll("*", "") },
4315
4329
  parser,
4316
4330
  structs,
4317
4331
  enums
@@ -6624,6 +6638,12 @@ var RpcChannel = class {
6624
6638
  });
6625
6639
  return this.waitMode ? this.waitForTransaction((await promise).transaction_hash) : promise;
6626
6640
  }
6641
+ async invokeSignedTx(transaction) {
6642
+ const promise = this.fetchEndpoint("starknet_addInvokeTransaction", {
6643
+ invoke_transaction: transaction
6644
+ });
6645
+ return this.waitMode ? this.waitForTransaction((await promise).transaction_hash) : promise;
6646
+ }
6627
6647
  async declare(declareTransaction, details) {
6628
6648
  const transaction = await this.buildTransaction(
6629
6649
  {
@@ -7233,6 +7253,12 @@ var RpcChannel2 = class {
7233
7253
  });
7234
7254
  return this.waitMode ? this.waitForTransaction((await promise).transaction_hash) : promise;
7235
7255
  }
7256
+ async invokeSignedTx(transaction) {
7257
+ const promise = this.fetchEndpoint("starknet_addInvokeTransaction", {
7258
+ invoke_transaction: transaction
7259
+ });
7260
+ return this.waitMode ? this.waitForTransaction((await promise).transaction_hash) : promise;
7261
+ }
7236
7262
  async declare(declareTransaction, details) {
7237
7263
  const transaction = await this.buildTransaction(
7238
7264
  {
@@ -9177,7 +9203,19 @@ function dynamicCallData(hardcoded, reference = void 0, arrayReference = void 0)
9177
9203
  });
9178
9204
  }
9179
9205
  function isStarkDomain(domain) {
9180
- return /^(?:[a-z0-9-]{1,48}(?:[a-z0-9-]{1,48}[a-z0-9-])?\.)*[a-z0-9-]{1,48}\.stark$/.test(domain);
9206
+ const starkSuffix = ".stark";
9207
+ if (!domain.endsWith(starkSuffix)) {
9208
+ return false;
9209
+ }
9210
+ const name = domain.slice(0, -starkSuffix.length);
9211
+ if (name.length === 0) {
9212
+ return false;
9213
+ }
9214
+ return name.split(".").every((label) => {
9215
+ return label.length > 0 && label.length <= 48 && [...label].every((char) => {
9216
+ return char >= "a" && char <= "z" || char >= "0" && char <= "9" || char === "-";
9217
+ });
9218
+ });
9181
9219
  }
9182
9220
 
9183
9221
  // src/plugins/starknet-id/index.ts
@@ -9923,6 +9961,34 @@ var RpcProvider = class {
9923
9961
  async invokeFunction(functionInvocation, details) {
9924
9962
  return this.channel.invoke(functionInvocation, details);
9925
9963
  }
9964
+ /**
9965
+ * Submit a pre-signed INVOKE_TXN_V3 transaction to the network.
9966
+ *
9967
+ * Broadcasts a transaction previously built and signed by `Account.getSignedTransaction()`.
9968
+ * Fees are already included in the signed transaction and will not be re-estimated.
9969
+ *
9970
+ * @param transaction - A fully signed `RPC.INVOKE_TXN_V3` object, as returned by `Account.getSignedTransaction()`
9971
+ *
9972
+ * @returns The transaction hash if `waitMode` is disabled (default), or the transaction receipt if `waitMode` is enabled.
9973
+ *
9974
+ * @remarks
9975
+ * - The transaction must be signed before calling this method ; use `Account.getSignedTransaction()` to produce it.
9976
+ * - Resubmitting the same signed transaction (same nonce) will be rejected by the network.
9977
+ * - If `waitMode` is enabled on the provider, this method waits for the transaction to be included in a block before returning.
9978
+ *
9979
+ * @example
9980
+ * ```typescript
9981
+ * const signedTx = await account.getSignedTransaction([
9982
+ * { contractAddress: erc20Address, entrypoint: 'transfer', calldata: [recipient, amount, 0] }
9983
+ * ]);
9984
+ * // inspect or store signedTx, then submit when ready:
9985
+ * const { transaction_hash } = await provider.invokeSignedTx(signedTx);
9986
+ * await provider.waitForTransaction(transaction_hash);
9987
+ * ```
9988
+ */
9989
+ async invokeSignedTx(transaction) {
9990
+ return this.channel.invokeSignedTx(transaction);
9991
+ }
9926
9992
  async declareContract(transaction, details) {
9927
9993
  return this.channel.declare(transaction, details);
9928
9994
  }
@@ -11805,7 +11871,12 @@ var Account = class {
11805
11871
  returnInitialReads
11806
11872
  });
11807
11873
  }
11808
- async execute(transactions, transactionsDetail = {}) {
11874
+ /**
11875
+ * Shared preparation logic for execute() and buildExecute().
11876
+ * Runs hooks, estimates fees, and builds accountInvocations.
11877
+ * @private
11878
+ */
11879
+ async prepareInvoke(transactions, transactionsDetail = {}) {
11809
11880
  const hookResult = this.accountPluginManager.runAccountHook("beforeExecute", {
11810
11881
  calls: transactions,
11811
11882
  details: transactionsDetail
@@ -11830,7 +11901,15 @@ var Account = class {
11830
11901
  skipValidate: false
11831
11902
  }
11832
11903
  );
11833
- const invocation = accountInvocations[0];
11904
+ return {
11905
+ invocation: accountInvocations[0],
11906
+ hookedTransactions,
11907
+ hookedDetails,
11908
+ detailsWithTip
11909
+ };
11910
+ }
11911
+ async execute(transactions, transactionsDetail = {}) {
11912
+ const { invocation, hookedTransactions, hookedDetails, detailsWithTip } = await this.prepareInvoke(transactions, transactionsDetail);
11834
11913
  const result = await this.provider.invokeFunction(
11835
11914
  {
11836
11915
  contractAddress: invocation.contractAddress,
@@ -11852,6 +11931,51 @@ var Account = class {
11852
11931
  });
11853
11932
  return result;
11854
11933
  }
11934
+ /**
11935
+ * Build a signed INVOKE_TXN_V3 transaction without submitting it to the network.
11936
+ *
11937
+ * Produces a fully signed transaction object that can be inspected, stored,
11938
+ * or submitted later via `provider.channel.sendTransaction()`.
11939
+ * Main usage is to send a virtual transaction to a proof server.
11940
+ * Fees are estimated automatically if not provided.
11941
+ *
11942
+ * @param transactions - Single call or array of calls to include in the transaction
11943
+ * @param transactionsDetail - Transaction execution options
11944
+ * @returns A fully signed `RPC.INVOKE_TXN_V3` object, ready to broadcast
11945
+ *
11946
+ * @remarks
11947
+ * - Unlike `execute()`, this method does **not** submit the transaction ; the account nonce is unchanged after the call.
11948
+ * - The `afterExecute` plugin hook is intentionally **not** triggered.
11949
+ * - The returned object can be broadcast with `provider.channel.sendTransaction()`.
11950
+ *
11951
+ * @example
11952
+ * ```typescript
11953
+ * const signedTx = await account.getSignedTransaction(
11954
+ * { contractAddress: erc20Address, entrypoint: 'transfer', calldata: [recipient, amount, 0] }
11955
+ * );
11956
+ * ```
11957
+ */
11958
+ async getSignedTransaction(transactions, transactionsDetail = {}) {
11959
+ const { invocation, hookedDetails, detailsWithTip } = await this.prepareInvoke(
11960
+ transactions,
11961
+ transactionsDetail
11962
+ );
11963
+ return this.provider.channel.buildTransaction(
11964
+ {
11965
+ type: api_exports.ETransactionType.INVOKE,
11966
+ contractAddress: invocation.contractAddress,
11967
+ calldata: invocation.calldata,
11968
+ signature: invocation.signature,
11969
+ ...hookedDetails.proofFacts && { proofFacts: hookedDetails.proofFacts },
11970
+ ...hookedDetails.proof && { proof: hookedDetails.proof },
11971
+ ...v3Details(detailsWithTip),
11972
+ resourceBounds: invocation.resourceBounds,
11973
+ nonce: invocation.nonce,
11974
+ version: invocation.version
11975
+ },
11976
+ "transaction"
11977
+ );
11978
+ }
11855
11979
  /**
11856
11980
  * First check if contract is already declared, if not declare it
11857
11981
  * If contract already declared returned transaction_hash is ''.