starknet 10.1.0 → 10.3.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.
@@ -6261,6 +6261,22 @@ ${indent}}` : "}";
6261
6261
  }
6262
6262
  };
6263
6263
 
6264
+ // src/utils/ec.ts
6265
+ var ec_exports = {};
6266
+ __export(ec_exports, {
6267
+ starkCurve: () => esm_exports4,
6268
+ weierstrass: () => weierstrass_exports
6269
+ });
6270
+
6271
+ // src/utils/hash/pedersenCore.ts
6272
+ function computePedersenHash(a, b) {
6273
+ return esm_exports4.pedersen(BigInt(a), BigInt(b));
6274
+ }
6275
+ function computeHashOnElements2(data) {
6276
+ return [...data, data.length].reduce((x, y) => esm_exports4.pedersen(BigInt(x), BigInt(y)), 0).toString();
6277
+ }
6278
+ var computePedersenHashOnElements = computeHashOnElements2;
6279
+
6264
6280
  // src/utils/errors/rpc.ts
6265
6281
  var errorCodes = {
6266
6282
  FAILED_TO_RECEIVE_TXN: 1,
@@ -6555,6 +6571,31 @@ ${indent}}` : "}";
6555
6571
  const allBytes = concatenateArrayBuffer(this.toElements());
6556
6572
  return buffer_default.from(allBytes);
6557
6573
  }
6574
+ /**
6575
+ * Compute the Pedersen hash of this ByteArray, following OpenZeppelin's `hash_byte_array` algorithm.
6576
+ *
6577
+ * Serializes the ByteArray to its felt252 components (data array length, each data chunk,
6578
+ * pending_word, pending_word_len), then chains Pedersen hash over all elements starting
6579
+ * from 0, and finalizes with the total element count.
6580
+ *
6581
+ * @returns {string} hex-string felt252 Pedersen hash of the ByteArray
6582
+ * @example
6583
+ * ```typescript
6584
+ * const ba = new CairoByteArray('Hello');
6585
+ * const result = ba.hash();
6586
+ * // result = 0x15d19ad651ffaf8e90a13938db2081fa3ff01de0712e00cbe69891bace66c51
6587
+ * ```
6588
+ */
6589
+ hash() {
6590
+ this.assertInitialized();
6591
+ const serialized = [
6592
+ addHexPrefix(this.data.length.toString(16)),
6593
+ ...this.data.flatMap((bytes31) => bytes31.toApiRequest()),
6594
+ ...this.pending_word.toApiRequest(),
6595
+ ...this.pending_word_len.toApiRequest()
6596
+ ];
6597
+ return computeHashOnElements2(serialized);
6598
+ }
6558
6599
  /**
6559
6600
  * returns an array of all the data chunks and the pending word
6560
6601
  * when concatenated, represents the original bytes sequence
@@ -9115,7 +9156,7 @@ ${indent}}` : "}";
9115
9156
  computeCompiledClassHashBlake: () => computeCompiledClassHashBlake,
9116
9157
  computeCompiledClassHashPoseidon: () => computeCompiledClassHashPoseidon,
9117
9158
  computeContractClassHash: () => computeContractClassHash,
9118
- computeHashOnElements: () => computeHashOnElements3,
9159
+ computeHashOnElements: () => computeHashOnElements2,
9119
9160
  computeHintedClassHash: () => computeHintedClassHash,
9120
9161
  computeLegacyContractClassHash: () => computeLegacyContractClassHash,
9121
9162
  computePedersenHash: () => computePedersenHash,
@@ -9253,22 +9294,13 @@ ${indent}}` : "}";
9253
9294
  calculateL2MessageTxHash: () => calculateL2MessageTxHash,
9254
9295
  calculateTransactionHash: () => calculateTransactionHash,
9255
9296
  calculateTransactionHashCommon: () => calculateTransactionHashCommon2,
9256
- computeHashOnElements: () => computeHashOnElements2
9257
- });
9258
-
9259
- // src/utils/ec.ts
9260
- var ec_exports = {};
9261
- __export(ec_exports, {
9262
- starkCurve: () => esm_exports4,
9263
- weierstrass: () => weierstrass_exports
9297
+ computeHashOnElements: () => computeHashOnElements3
9264
9298
  });
9265
-
9266
- // src/utils/hash/transactionHash/v2.ts
9267
- function computeHashOnElements2(data) {
9299
+ function computeHashOnElements3(data) {
9268
9300
  return [...data, data.length].reduce((x, y) => esm_exports4.pedersen(toBigInt(x), toBigInt(y)), 0).toString();
9269
9301
  }
9270
9302
  function calculateTransactionHashCommon2(txHashPrefix, version, contractAddress, entryPointSelector, calldata, maxFee, chainId, additionalData = []) {
9271
- const calldataHash = computeHashOnElements2(calldata);
9303
+ const calldataHash = computeHashOnElements3(calldata);
9272
9304
  const dataToHash = [
9273
9305
  txHashPrefix,
9274
9306
  version,
@@ -9279,7 +9311,7 @@ ${indent}}` : "}";
9279
9311
  chainId,
9280
9312
  ...additionalData
9281
9313
  ];
9282
- return computeHashOnElements2(dataToHash);
9314
+ return computeHashOnElements3(dataToHash);
9283
9315
  }
9284
9316
  function calculateDeclareTransactionHash2(classHash, senderAddress, version, maxFee, chainId, nonce, compiledClassHash) {
9285
9317
  return calculateTransactionHashCommon2(
@@ -9438,18 +9470,11 @@ ${indent}}` : "}";
9438
9470
  }
9439
9471
 
9440
9472
  // src/utils/hash/classHash/pedersen.ts
9441
- function computePedersenHash(a, b) {
9442
- return esm_exports4.pedersen(BigInt(a), BigInt(b));
9443
- }
9444
- function computeHashOnElements3(data) {
9445
- return [...data, data.length].reduce((x, y) => esm_exports4.pedersen(BigInt(x), BigInt(y)), 0).toString();
9446
- }
9447
- var computePedersenHashOnElements = computeHashOnElements3;
9448
9473
  function calculateContractAddressFromHash(salt, classHash, constructorCalldata, deployerAddress) {
9449
9474
  const compiledCalldata = CallData.compile(constructorCalldata);
9450
- const constructorCalldataHash = computeHashOnElements3(compiledCalldata);
9475
+ const constructorCalldataHash = computeHashOnElements2(compiledCalldata);
9451
9476
  const CONTRACT_ADDRESS_PREFIX = felt("0x535441524b4e45545f434f4e54524143545f41444452455353");
9452
- const hash = computeHashOnElements3([
9477
+ const hash = computeHashOnElements2([
9453
9478
  CONTRACT_ADDRESS_PREFIX,
9454
9479
  deployerAddress,
9455
9480
  salt,
@@ -9467,21 +9492,21 @@ ${indent}}` : "}";
9467
9492
  function computeLegacyContractClassHash(contract) {
9468
9493
  const compiledContract = isString(contract) ? parse2(contract) : contract;
9469
9494
  const apiVersion = toHex(API_VERSION);
9470
- const externalEntryPointsHash = computeHashOnElements3(
9495
+ const externalEntryPointsHash = computeHashOnElements2(
9471
9496
  compiledContract.entry_points_by_type.EXTERNAL.flatMap((e) => [e.selector, e.offset])
9472
9497
  );
9473
- const l1HandlerEntryPointsHash = computeHashOnElements3(
9498
+ const l1HandlerEntryPointsHash = computeHashOnElements2(
9474
9499
  compiledContract.entry_points_by_type.L1_HANDLER.flatMap((e) => [e.selector, e.offset])
9475
9500
  );
9476
- const constructorEntryPointHash = computeHashOnElements3(
9501
+ const constructorEntryPointHash = computeHashOnElements2(
9477
9502
  compiledContract.entry_points_by_type.CONSTRUCTOR.flatMap((e) => [e.selector, e.offset])
9478
9503
  );
9479
- const builtinsHash = computeHashOnElements3(
9504
+ const builtinsHash = computeHashOnElements2(
9480
9505
  compiledContract.program.builtins.map((s) => encodeShortString(s))
9481
9506
  );
9482
9507
  const hintedClassHash = computeHintedClassHash(compiledContract);
9483
- const dataHash = computeHashOnElements3(compiledContract.program.data);
9484
- return computeHashOnElements3([
9508
+ const dataHash = computeHashOnElements2(compiledContract.program.data);
9509
+ return computeHashOnElements2([
9485
9510
  apiVersion,
9486
9511
  externalEntryPointsHash,
9487
9512
  l1HandlerEntryPointsHash,
@@ -11555,6 +11580,12 @@ ${indent}}` : "}";
11555
11580
  });
11556
11581
  return this.waitMode ? this.waitForTransaction((await promise).transaction_hash) : promise;
11557
11582
  }
11583
+ async invokeSignedTx(transaction) {
11584
+ const promise = this.fetchEndpoint("starknet_addInvokeTransaction", {
11585
+ invoke_transaction: transaction
11586
+ });
11587
+ return this.waitMode ? this.waitForTransaction((await promise).transaction_hash) : promise;
11588
+ }
11558
11589
  async declare(declareTransaction, details) {
11559
11590
  const transaction = await this.buildTransaction(
11560
11591
  {
@@ -12248,6 +12279,12 @@ ${indent}}` : "}";
12248
12279
  });
12249
12280
  return this.waitMode ? this.waitForTransaction((await promise).transaction_hash) : promise;
12250
12281
  }
12282
+ async invokeSignedTx(transaction) {
12283
+ const promise = this.fetchEndpoint("starknet_addInvokeTransaction", {
12284
+ invoke_transaction: transaction
12285
+ });
12286
+ return this.waitMode ? this.waitForTransaction((await promise).transaction_hash) : promise;
12287
+ }
12251
12288
  async declare(declareTransaction, details) {
12252
12289
  const transaction = await this.buildTransaction(
12253
12290
  {
@@ -14938,6 +14975,34 @@ ${indent}}` : "}";
14938
14975
  async invokeFunction(functionInvocation, details) {
14939
14976
  return this.channel.invoke(functionInvocation, details);
14940
14977
  }
14978
+ /**
14979
+ * Submit a pre-signed INVOKE_TXN_V3 transaction to the network.
14980
+ *
14981
+ * Broadcasts a transaction previously built and signed by `Account.getSignedTransaction()`.
14982
+ * Fees are already included in the signed transaction and will not be re-estimated.
14983
+ *
14984
+ * @param transaction - A fully signed `RPC.INVOKE_TXN_V3` object, as returned by `Account.getSignedTransaction()`
14985
+ *
14986
+ * @returns The transaction hash if `waitMode` is disabled (default), or the transaction receipt if `waitMode` is enabled.
14987
+ *
14988
+ * @remarks
14989
+ * - The transaction must be signed before calling this method ; use `Account.getSignedTransaction()` to produce it.
14990
+ * - Resubmitting the same signed transaction (same nonce) will be rejected by the network.
14991
+ * - If `waitMode` is enabled on the provider, this method waits for the transaction to be included in a block before returning.
14992
+ *
14993
+ * @example
14994
+ * ```typescript
14995
+ * const signedTx = await account.getSignedTransaction([
14996
+ * { contractAddress: erc20Address, entrypoint: 'transfer', calldata: [recipient, amount, 0] }
14997
+ * ]);
14998
+ * // inspect or store signedTx, then submit when ready:
14999
+ * const { transaction_hash } = await provider.invokeSignedTx(signedTx);
15000
+ * await provider.waitForTransaction(transaction_hash);
15001
+ * ```
15002
+ */
15003
+ async invokeSignedTx(transaction) {
15004
+ return this.channel.invokeSignedTx(transaction);
15005
+ }
14941
15006
  async declareContract(transaction, details) {
14942
15007
  return this.channel.declare(transaction, details);
14943
15008
  }
@@ -16816,7 +16881,12 @@ ${indent}}` : "}";
16816
16881
  returnInitialReads
16817
16882
  });
16818
16883
  }
16819
- async execute(transactions, transactionsDetail = {}) {
16884
+ /**
16885
+ * Shared preparation logic for execute() and buildExecute().
16886
+ * Runs hooks, estimates fees, and builds accountInvocations.
16887
+ * @private
16888
+ */
16889
+ async prepareInvoke(transactions, transactionsDetail = {}) {
16820
16890
  const hookResult = this.accountPluginManager.runAccountHook("beforeExecute", {
16821
16891
  calls: transactions,
16822
16892
  details: transactionsDetail
@@ -16841,7 +16911,15 @@ ${indent}}` : "}";
16841
16911
  skipValidate: false
16842
16912
  }
16843
16913
  );
16844
- const invocation = accountInvocations[0];
16914
+ return {
16915
+ invocation: accountInvocations[0],
16916
+ hookedTransactions,
16917
+ hookedDetails,
16918
+ detailsWithTip
16919
+ };
16920
+ }
16921
+ async execute(transactions, transactionsDetail = {}) {
16922
+ const { invocation, hookedTransactions, hookedDetails, detailsWithTip } = await this.prepareInvoke(transactions, transactionsDetail);
16845
16923
  const result = await this.provider.invokeFunction(
16846
16924
  {
16847
16925
  contractAddress: invocation.contractAddress,
@@ -16863,6 +16941,51 @@ ${indent}}` : "}";
16863
16941
  });
16864
16942
  return result;
16865
16943
  }
16944
+ /**
16945
+ * Build a signed INVOKE_TXN_V3 transaction without submitting it to the network.
16946
+ *
16947
+ * Produces a fully signed transaction object that can be inspected, stored,
16948
+ * or submitted later via `provider.channel.sendTransaction()`.
16949
+ * Main usage is to send a virtual transaction to a proof server.
16950
+ * Fees are estimated automatically if not provided.
16951
+ *
16952
+ * @param transactions - Single call or array of calls to include in the transaction
16953
+ * @param transactionsDetail - Transaction execution options
16954
+ * @returns A fully signed `RPC.INVOKE_TXN_V3` object, ready to broadcast
16955
+ *
16956
+ * @remarks
16957
+ * - Unlike `execute()`, this method does **not** submit the transaction ; the account nonce is unchanged after the call.
16958
+ * - The `afterExecute` plugin hook is intentionally **not** triggered.
16959
+ * - The returned object can be broadcast with `provider.channel.sendTransaction()`.
16960
+ *
16961
+ * @example
16962
+ * ```typescript
16963
+ * const signedTx = await account.getSignedTransaction(
16964
+ * { contractAddress: erc20Address, entrypoint: 'transfer', calldata: [recipient, amount, 0] }
16965
+ * );
16966
+ * ```
16967
+ */
16968
+ async getSignedTransaction(transactions, transactionsDetail = {}) {
16969
+ const { invocation, hookedDetails, detailsWithTip } = await this.prepareInvoke(
16970
+ transactions,
16971
+ transactionsDetail
16972
+ );
16973
+ return this.provider.channel.buildTransaction(
16974
+ {
16975
+ type: ETransactionType2.INVOKE,
16976
+ contractAddress: invocation.contractAddress,
16977
+ calldata: invocation.calldata,
16978
+ signature: invocation.signature,
16979
+ ...hookedDetails.proofFacts && { proofFacts: hookedDetails.proofFacts },
16980
+ ...hookedDetails.proof && { proof: hookedDetails.proof },
16981
+ ...v3Details(detailsWithTip),
16982
+ resourceBounds: invocation.resourceBounds,
16983
+ nonce: invocation.nonce,
16984
+ version: invocation.version
16985
+ },
16986
+ "transaction"
16987
+ );
16988
+ }
16866
16989
  /**
16867
16990
  * First check if contract is already declared, if not declare it
16868
16991
  * If contract already declared returned transaction_hash is ''.