starknet 11.4.0 → 11.4.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
@@ -18821,6 +18821,47 @@ var assertPaymasterTransactionSafety = (preparedTransaction, calls, paymasterDet
18821
18821
  );
18822
18822
  }
18823
18823
  }
18824
+ const msg = message;
18825
+ const version = hasV1Calls ? OutsideExecutionVersion.V1 : OutsideExecutionVersion.V2;
18826
+ const [callerKey, nonceKey, afterKey, beforeKey] = hasV1Calls ? ["caller", "nonce", "execute_after", "execute_before"] : ["Caller", "Nonce", "Execute After", "Execute Before"];
18827
+ assert(
18828
+ [callerKey, nonceKey, afterKey, beforeKey].every((key) => msg[key] !== void 0),
18829
+ "Paymaster typed data does not match the expected outside execution"
18830
+ );
18831
+ const caller = msg[callerKey];
18832
+ const nonce = msg[nonceKey];
18833
+ const executeAfter = msg[afterKey];
18834
+ const executeBefore = msg[beforeKey];
18835
+ if (paymasterDetails.timeBounds) {
18836
+ const requestedAfter = toBigInt(paymasterDetails.timeBounds.executeAfter ?? 1);
18837
+ const requestedBefore = toBigInt(paymasterDetails.timeBounds.executeBefore);
18838
+ assert(
18839
+ toBigInt(executeAfter) >= requestedAfter && toBigInt(executeBefore) <= requestedBefore,
18840
+ "Paymaster typed data execution window is not within the requested time bounds"
18841
+ );
18842
+ }
18843
+ const expectedCalls = [...calls];
18844
+ if (paymasterDetails.feeMode.mode !== "sponsored") {
18845
+ const feeCall = toOutsideCallV2(unsafeCalls[unsafeCalls.length - 1]);
18846
+ const feeRecipient = CallData.toCalldata(feeCall.Calldata)[0];
18847
+ const feeAmount = bnToUint256(preparedTransaction.fee.suggested_max_fee_in_gas_token);
18848
+ expectedCalls.push({
18849
+ contractAddress: paymasterDetails.feeMode.gasToken,
18850
+ entrypoint: "transfer",
18851
+ calldata: [feeRecipient, feeAmount.low, feeAmount.high]
18852
+ });
18853
+ }
18854
+ const expectedTypedData = getTypedData(
18855
+ chainId,
18856
+ { caller, execute_after: executeAfter, execute_before: executeBefore },
18857
+ nonce,
18858
+ expectedCalls,
18859
+ version
18860
+ );
18861
+ assert(
18862
+ getMessageHash(expectedTypedData, 0) === getMessageHash(preparedTransaction.typed_data, 0),
18863
+ "Paymaster typed data does not match the expected outside execution"
18864
+ );
18824
18865
  }
18825
18866
  };
18826
18867
 
@@ -19984,7 +20025,24 @@ var Account = class {
19984
20025
  const preparedTransaction = await this.buildPaymasterTransaction(calls, paymasterDetails);
19985
20026
  return preparedTransaction.fee;
19986
20027
  }
19987
- async preparePaymasterTransaction(preparedTransaction) {
20028
+ /**
20029
+ * Signs a transaction prepared by the paymaster, after checking it is safe to sign. The safety
20030
+ * check needs the calls and the fee details the user actually requested, so a caller that uses
20031
+ * this low-level method directly must pass them, the same way `executePaymasterTransaction`
20032
+ * does.
20033
+ * @param preparedTransaction the transaction returned by the paymaster.
20034
+ * @param calls the calls the user requested.
20035
+ * @param paymasterDetails the fee mode and related paymaster details.
20036
+ * @param maxFeeInGasToken optional user-approved ceiling on the gas-token fee.
20037
+ */
20038
+ async preparePaymasterTransaction(preparedTransaction, calls, paymasterDetails, maxFeeInGasToken) {
20039
+ assertPaymasterTransactionSafety(
20040
+ preparedTransaction,
20041
+ calls,
20042
+ paymasterDetails,
20043
+ await this.provider.getChainId(),
20044
+ maxFeeInGasToken
20045
+ );
19988
20046
  let transaction;
19989
20047
  switch (preparedTransaction.type) {
19990
20048
  case "deploy_and_invoke": {
@@ -20026,14 +20084,12 @@ var Account = class {
20026
20084
  }
20027
20085
  async executePaymasterTransaction(calls, paymasterDetails, maxFeeInGasToken) {
20028
20086
  const preparedTransaction = await this.buildPaymasterTransaction(calls, paymasterDetails);
20029
- assertPaymasterTransactionSafety(
20087
+ const transaction = await this.preparePaymasterTransaction(
20030
20088
  preparedTransaction,
20031
20089
  calls,
20032
20090
  paymasterDetails,
20033
- await this.provider.getChainId(),
20034
20091
  maxFeeInGasToken
20035
20092
  );
20036
- const transaction = await this.preparePaymasterTransaction(preparedTransaction);
20037
20093
  return this.paymaster.executeTransaction(transaction, preparedTransaction.parameters).then((response) => ({ transaction_hash: response.transaction_hash }));
20038
20094
  }
20039
20095
  };