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.mjs CHANGED
@@ -1509,8 +1509,11 @@ var CairoUint512 = class _CairoUint512 {
1509
1509
  var isLen = (name) => /_len$/.test(name);
1510
1510
  var isTypeFelt = (type) => type === "felt" || type === "core::felt252";
1511
1511
  var isTypeArray = (type) => /\*/.test(type) || type.startsWith("core::array::Array::") || type.startsWith("core::array::Span::");
1512
- var isTypeTuple = (type) => /^\(.*\)$/i.test(type);
1513
- var isTypeNamedTuple = (type) => /\(.*\)/i.test(type) && type.includes(":");
1512
+ var isTypeTuple = (type) => type.startsWith("(") && type.endsWith(")");
1513
+ var isTypeNamedTuple = (type) => {
1514
+ const start = type.indexOf("(");
1515
+ return start !== -1 && type.indexOf(")", start + 1) !== -1 && type.includes(":");
1516
+ };
1514
1517
  var isTypeStruct = (type, structs) => type in structs;
1515
1518
  var isTypeEnum = (type, enums) => type in enums;
1516
1519
  var isTypeOption = (type) => type.startsWith("core::option::Option::");
@@ -1526,7 +1529,7 @@ var isTypeU96 = (type) => type === "core::internal::bounded_int::BoundedInt::<0,
1526
1529
  var isTypeSecp256k1Point = (type) => type === Literal.Secp256k1Point;
1527
1530
  var isCairo1Type = (type) => type.includes("::");
1528
1531
  var getArrayType = (type) => {
1529
- return isCairo1Type(type) ? type.substring(type.indexOf("<") + 1, type.lastIndexOf(">")) : type.replace("*", "");
1532
+ return isCairo1Type(type) ? type.substring(type.indexOf("<") + 1, type.lastIndexOf(">")) : type.replaceAll("*", "");
1530
1533
  };
1531
1534
  function isCairo1Abi(abi) {
1532
1535
  const { cairo } = getAbiContractVersion(abi);
@@ -3329,6 +3332,18 @@ var CairoFixedArray = class _CairoFixedArray {
3329
3332
  * Cairo fixed array type.
3330
3333
  */
3331
3334
  arrayType;
3335
+ static parseFixedArrayType(type) {
3336
+ if (!type.startsWith("[") || !type.endsWith("]")) {
3337
+ return void 0;
3338
+ }
3339
+ const separator = type.lastIndexOf("; ");
3340
+ const itemType = type.slice(1, separator);
3341
+ const size = type.slice(separator + 2, -1);
3342
+ if (separator <= 1 || size.length === 0 || ![...size].every((char) => char >= "0" && char <= "9")) {
3343
+ return void 0;
3344
+ }
3345
+ return { itemType, size };
3346
+ }
3332
3347
  /**
3333
3348
  * Create an instance representing a Cairo fixed Array.
3334
3349
  * @param {any[]} content JS array representing a Cairo fixed array.
@@ -3372,10 +3387,10 @@ var CairoFixedArray = class _CairoFixedArray {
3372
3387
  * ```
3373
3388
  */
3374
3389
  static getFixedArraySize(type) {
3375
- const matchArray = type.match(/(?<=; )\d+(?=\])/);
3376
- if (matchArray === null)
3390
+ const fixedArrayType = _CairoFixedArray.parseFixedArrayType(type);
3391
+ if (!fixedArrayType)
3377
3392
  throw new Error(`ABI type ${type} do not includes a valid number after ';' character.`);
3378
- return Number(matchArray[0]);
3393
+ return Number(fixedArrayType.size);
3379
3394
  }
3380
3395
  /**
3381
3396
  * Retrieves the Cairo fixed array size from the CairoFixedArray instance.
@@ -3401,10 +3416,9 @@ var CairoFixedArray = class _CairoFixedArray {
3401
3416
  * ```
3402
3417
  */
3403
3418
  static getFixedArrayType = (type) => {
3404
- const matchArray = type.match(/(?<=\[).+(?=;)/);
3405
- if (matchArray === null)
3406
- throw new Error(`ABI type ${type} do not includes a valid type of data.`);
3407
- return matchArray[0];
3419
+ const fixedArrayType = _CairoFixedArray.parseFixedArrayType(type);
3420
+ if (!fixedArrayType) throw new Error(`ABI type ${type} do not includes a valid type of data.`);
3421
+ return fixedArrayType.itemType;
3408
3422
  };
3409
3423
  /**
3410
3424
  * Retrieve the Cairo content type of the Cairo fixed array.
@@ -3462,7 +3476,7 @@ var CairoFixedArray = class _CairoFixedArray {
3462
3476
  * // result = true
3463
3477
  */
3464
3478
  static isTypeFixedArray(type) {
3465
- return /^\[.*;\s.*\]$/.test(type) && /(?<=\[).+(?=;)/.test(type) && /(?<=; )\d+(?=\])/.test(type);
3479
+ return _CairoFixedArray.parseFixedArrayType(type) !== void 0;
3466
3480
  }
3467
3481
  };
3468
3482
 
@@ -4130,7 +4144,7 @@ function responseParser({
4130
4144
  parsedDataArr.push(
4131
4145
  parseResponseValue(
4132
4146
  responseIterator,
4133
- { name, type: output.type.replace("*", "") },
4147
+ { name, type: output.type.replaceAll("*", "") },
4134
4148
  parser,
4135
4149
  structs,
4136
4150
  enums
@@ -6443,6 +6457,12 @@ var RpcChannel = class {
6443
6457
  });
6444
6458
  return this.waitMode ? this.waitForTransaction((await promise).transaction_hash) : promise;
6445
6459
  }
6460
+ async invokeSignedTx(transaction) {
6461
+ const promise = this.fetchEndpoint("starknet_addInvokeTransaction", {
6462
+ invoke_transaction: transaction
6463
+ });
6464
+ return this.waitMode ? this.waitForTransaction((await promise).transaction_hash) : promise;
6465
+ }
6446
6466
  async declare(declareTransaction, details) {
6447
6467
  const transaction = await this.buildTransaction(
6448
6468
  {
@@ -7052,6 +7072,12 @@ var RpcChannel2 = class {
7052
7072
  });
7053
7073
  return this.waitMode ? this.waitForTransaction((await promise).transaction_hash) : promise;
7054
7074
  }
7075
+ async invokeSignedTx(transaction) {
7076
+ const promise = this.fetchEndpoint("starknet_addInvokeTransaction", {
7077
+ invoke_transaction: transaction
7078
+ });
7079
+ return this.waitMode ? this.waitForTransaction((await promise).transaction_hash) : promise;
7080
+ }
7055
7081
  async declare(declareTransaction, details) {
7056
7082
  const transaction = await this.buildTransaction(
7057
7083
  {
@@ -8996,7 +9022,19 @@ function dynamicCallData(hardcoded, reference = void 0, arrayReference = void 0)
8996
9022
  });
8997
9023
  }
8998
9024
  function isStarkDomain(domain) {
8999
- return /^(?:[a-z0-9-]{1,48}(?:[a-z0-9-]{1,48}[a-z0-9-])?\.)*[a-z0-9-]{1,48}\.stark$/.test(domain);
9025
+ const starkSuffix = ".stark";
9026
+ if (!domain.endsWith(starkSuffix)) {
9027
+ return false;
9028
+ }
9029
+ const name = domain.slice(0, -starkSuffix.length);
9030
+ if (name.length === 0) {
9031
+ return false;
9032
+ }
9033
+ return name.split(".").every((label) => {
9034
+ return label.length > 0 && label.length <= 48 && [...label].every((char) => {
9035
+ return char >= "a" && char <= "z" || char >= "0" && char <= "9" || char === "-";
9036
+ });
9037
+ });
9000
9038
  }
9001
9039
 
9002
9040
  // src/plugins/starknet-id/index.ts
@@ -9742,6 +9780,34 @@ var RpcProvider = class {
9742
9780
  async invokeFunction(functionInvocation, details) {
9743
9781
  return this.channel.invoke(functionInvocation, details);
9744
9782
  }
9783
+ /**
9784
+ * Submit a pre-signed INVOKE_TXN_V3 transaction to the network.
9785
+ *
9786
+ * Broadcasts a transaction previously built and signed by `Account.getSignedTransaction()`.
9787
+ * Fees are already included in the signed transaction and will not be re-estimated.
9788
+ *
9789
+ * @param transaction - A fully signed `RPC.INVOKE_TXN_V3` object, as returned by `Account.getSignedTransaction()`
9790
+ *
9791
+ * @returns The transaction hash if `waitMode` is disabled (default), or the transaction receipt if `waitMode` is enabled.
9792
+ *
9793
+ * @remarks
9794
+ * - The transaction must be signed before calling this method ; use `Account.getSignedTransaction()` to produce it.
9795
+ * - Resubmitting the same signed transaction (same nonce) will be rejected by the network.
9796
+ * - If `waitMode` is enabled on the provider, this method waits for the transaction to be included in a block before returning.
9797
+ *
9798
+ * @example
9799
+ * ```typescript
9800
+ * const signedTx = await account.getSignedTransaction([
9801
+ * { contractAddress: erc20Address, entrypoint: 'transfer', calldata: [recipient, amount, 0] }
9802
+ * ]);
9803
+ * // inspect or store signedTx, then submit when ready:
9804
+ * const { transaction_hash } = await provider.invokeSignedTx(signedTx);
9805
+ * await provider.waitForTransaction(transaction_hash);
9806
+ * ```
9807
+ */
9808
+ async invokeSignedTx(transaction) {
9809
+ return this.channel.invokeSignedTx(transaction);
9810
+ }
9745
9811
  async declareContract(transaction, details) {
9746
9812
  return this.channel.declare(transaction, details);
9747
9813
  }
@@ -11624,7 +11690,12 @@ var Account = class {
11624
11690
  returnInitialReads
11625
11691
  });
11626
11692
  }
11627
- async execute(transactions, transactionsDetail = {}) {
11693
+ /**
11694
+ * Shared preparation logic for execute() and buildExecute().
11695
+ * Runs hooks, estimates fees, and builds accountInvocations.
11696
+ * @private
11697
+ */
11698
+ async prepareInvoke(transactions, transactionsDetail = {}) {
11628
11699
  const hookResult = this.accountPluginManager.runAccountHook("beforeExecute", {
11629
11700
  calls: transactions,
11630
11701
  details: transactionsDetail
@@ -11649,7 +11720,15 @@ var Account = class {
11649
11720
  skipValidate: false
11650
11721
  }
11651
11722
  );
11652
- const invocation = accountInvocations[0];
11723
+ return {
11724
+ invocation: accountInvocations[0],
11725
+ hookedTransactions,
11726
+ hookedDetails,
11727
+ detailsWithTip
11728
+ };
11729
+ }
11730
+ async execute(transactions, transactionsDetail = {}) {
11731
+ const { invocation, hookedTransactions, hookedDetails, detailsWithTip } = await this.prepareInvoke(transactions, transactionsDetail);
11653
11732
  const result = await this.provider.invokeFunction(
11654
11733
  {
11655
11734
  contractAddress: invocation.contractAddress,
@@ -11671,6 +11750,51 @@ var Account = class {
11671
11750
  });
11672
11751
  return result;
11673
11752
  }
11753
+ /**
11754
+ * Build a signed INVOKE_TXN_V3 transaction without submitting it to the network.
11755
+ *
11756
+ * Produces a fully signed transaction object that can be inspected, stored,
11757
+ * or submitted later via `provider.channel.sendTransaction()`.
11758
+ * Main usage is to send a virtual transaction to a proof server.
11759
+ * Fees are estimated automatically if not provided.
11760
+ *
11761
+ * @param transactions - Single call or array of calls to include in the transaction
11762
+ * @param transactionsDetail - Transaction execution options
11763
+ * @returns A fully signed `RPC.INVOKE_TXN_V3` object, ready to broadcast
11764
+ *
11765
+ * @remarks
11766
+ * - Unlike `execute()`, this method does **not** submit the transaction ; the account nonce is unchanged after the call.
11767
+ * - The `afterExecute` plugin hook is intentionally **not** triggered.
11768
+ * - The returned object can be broadcast with `provider.channel.sendTransaction()`.
11769
+ *
11770
+ * @example
11771
+ * ```typescript
11772
+ * const signedTx = await account.getSignedTransaction(
11773
+ * { contractAddress: erc20Address, entrypoint: 'transfer', calldata: [recipient, amount, 0] }
11774
+ * );
11775
+ * ```
11776
+ */
11777
+ async getSignedTransaction(transactions, transactionsDetail = {}) {
11778
+ const { invocation, hookedDetails, detailsWithTip } = await this.prepareInvoke(
11779
+ transactions,
11780
+ transactionsDetail
11781
+ );
11782
+ return this.provider.channel.buildTransaction(
11783
+ {
11784
+ type: api_exports.ETransactionType.INVOKE,
11785
+ contractAddress: invocation.contractAddress,
11786
+ calldata: invocation.calldata,
11787
+ signature: invocation.signature,
11788
+ ...hookedDetails.proofFacts && { proofFacts: hookedDetails.proofFacts },
11789
+ ...hookedDetails.proof && { proof: hookedDetails.proof },
11790
+ ...v3Details(detailsWithTip),
11791
+ resourceBounds: invocation.resourceBounds,
11792
+ nonce: invocation.nonce,
11793
+ version: invocation.version
11794
+ },
11795
+ "transaction"
11796
+ );
11797
+ }
11674
11798
  /**
11675
11799
  * First check if contract is already declared, if not declare it
11676
11800
  * If contract already declared returned transaction_hash is ''.