starknet 10.7.1 → 10.7.3

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
@@ -11517,9 +11517,12 @@ var getDefaultPaymasterNodeUrl = (networkName, mute = false) => {
11517
11517
  var assertGasFeeFromUnsafeCalls = (unsafeCalls, fees) => {
11518
11518
  const unsafeCall = toOutsideCallV2(unsafeCalls[unsafeCalls.length - 1]);
11519
11519
  const unsafeGasTokenCalldata = CallData.toCalldata(unsafeCall.Calldata);
11520
- const unsafeGasTokenValue = unsafeGasTokenCalldata[1];
11520
+ const unsafeGasTokenValue = uint256ToBN({
11521
+ low: unsafeGasTokenCalldata[1],
11522
+ high: unsafeGasTokenCalldata[2]
11523
+ });
11521
11524
  assert(
11522
- BigInt(unsafeGasTokenValue) === BigInt(fees),
11525
+ unsafeGasTokenValue === BigInt(fees),
11523
11526
  "Gas token value is not equal to the provided gas fees"
11524
11527
  );
11525
11528
  };
@@ -11529,12 +11532,21 @@ var assertGasTokenFromUnsafeCalls = (unsafeCalls, gasToken) => {
11529
11532
  BigInt(unsafeCall.To) === BigInt(gasToken),
11530
11533
  "Gas token address is not equal to the provided gas token"
11531
11534
  );
11535
+ assert(
11536
+ unsafeCall.Selector === getSelectorFromName("transfer"),
11537
+ "Gas token call selector is not a transfer"
11538
+ );
11539
+ assert(
11540
+ CallData.toCalldata(unsafeCall.Calldata).length === 3,
11541
+ "Gas token transfer calldata does not match the expected recipient/amount shape"
11542
+ );
11532
11543
  };
11533
- function assertCallsAreStrictlyEqual(originalCalls, unsafeCalls) {
11544
+ function assertCallsAreStrictlyEqual(originalCalls, unsafeCalls, isSponsored = false) {
11534
11545
  const baseError = "Provided calls are not strictly equal to the returned calls";
11546
+ const expectedExtraCalls = isSponsored ? 0 : 1;
11535
11547
  assert(
11536
- unsafeCalls.length - 1 === originalCalls.length,
11537
- `${baseError}: Expected ${originalCalls.length + 1} calls, got ${unsafeCalls.length}`
11548
+ unsafeCalls.length - expectedExtraCalls === originalCalls.length,
11549
+ `${baseError}: Expected ${originalCalls.length + expectedExtraCalls} calls, got ${unsafeCalls.length}`
11538
11550
  );
11539
11551
  for (let callIndex = 0; callIndex < originalCalls.length; callIndex += 1) {
11540
11552
  const originalCall = originalCalls[callIndex];
@@ -11568,21 +11580,42 @@ function assertCallsAreStrictlyEqual(originalCalls, unsafeCalls) {
11568
11580
  }
11569
11581
  }
11570
11582
  }
11571
- var assertPaymasterTransactionSafety = (preparedTransaction, calls, paymasterDetails, maxFeeInGasToken) => {
11572
- if (paymasterDetails.feeMode.mode !== "sponsored") {
11573
- if (preparedTransaction.type === "invoke" || preparedTransaction.type === "deploy_and_invoke") {
11574
- const unsafeCalls = "calls" in preparedTransaction.typed_data.message ? preparedTransaction.typed_data.message.calls : preparedTransaction.typed_data.message.Calls;
11575
- assertCallsAreStrictlyEqual(calls, unsafeCalls);
11583
+ var domainFieldToFelt = (value) => {
11584
+ try {
11585
+ return toBigInt(value);
11586
+ } catch {
11587
+ return toBigInt(encodeShortString(String(value)));
11588
+ }
11589
+ };
11590
+ var assertChainIdFromTypedData = (typedData, chainId) => {
11591
+ assert(
11592
+ typedData.domain.chainId !== void 0 && domainFieldToFelt(typedData.domain.chainId) === BigInt(chainId),
11593
+ "Paymaster typed data domain chainId does not match the account's provider chain"
11594
+ );
11595
+ };
11596
+ var assertPaymasterTransactionSafety = (preparedTransaction, calls, paymasterDetails, chainId, maxFeeInGasToken) => {
11597
+ if (preparedTransaction.type === "invoke" || preparedTransaction.type === "deploy_and_invoke") {
11598
+ assertChainIdFromTypedData(preparedTransaction.typed_data, chainId);
11599
+ const { message } = preparedTransaction.typed_data;
11600
+ const hasV1Calls = "calls" in message;
11601
+ const hasV2Calls = "Calls" in message;
11602
+ assert(
11603
+ hasV1Calls !== hasV2Calls,
11604
+ 'Paymaster typed data must declare exactly one of "calls" (SNIP-9 V1) or "Calls" (SNIP-9 V2)'
11605
+ );
11606
+ const unsafeCalls = hasV1Calls ? message.calls : message.Calls;
11607
+ assertCallsAreStrictlyEqual(calls, unsafeCalls, paymasterDetails.feeMode.mode === "sponsored");
11608
+ if (paymasterDetails.feeMode.mode !== "sponsored") {
11576
11609
  assertGasTokenFromUnsafeCalls(unsafeCalls, paymasterDetails.feeMode.gasToken);
11610
+ assertGasFeeFromUnsafeCalls(
11611
+ unsafeCalls,
11612
+ preparedTransaction.fee.suggested_max_fee_in_gas_token
11613
+ );
11577
11614
  if (maxFeeInGasToken) {
11578
11615
  assert(
11579
11616
  preparedTransaction.fee.suggested_max_fee_in_gas_token <= maxFeeInGasToken,
11580
11617
  "Gas token price is too high"
11581
11618
  );
11582
- assertGasFeeFromUnsafeCalls(
11583
- unsafeCalls,
11584
- preparedTransaction.fee.suggested_max_fee_in_gas_token
11585
- );
11586
11619
  }
11587
11620
  }
11588
11621
  }
@@ -11836,9 +11869,10 @@ var Deployer = class {
11836
11869
  const compiledConstructorCallData = getCompiledCalldata(constructorCalldata, () => {
11837
11870
  if (abi) {
11838
11871
  const calldataClass = new CallData(abi);
11839
- const rawArgs = Object.values(constructorCalldata);
11840
- calldataClass.validate(ValidateType.DEPLOY, "constructor", rawArgs);
11841
- return calldataClass.compile("constructor", rawArgs);
11872
+ if (Array.isArray(constructorCalldata)) {
11873
+ calldataClass.validate(ValidateType.DEPLOY, "constructor", constructorCalldata);
11874
+ }
11875
+ return calldataClass.compile("constructor", constructorCalldata);
11842
11876
  }
11843
11877
  return CallData.compile(constructorCalldata);
11844
11878
  });
@@ -12707,6 +12741,7 @@ var Account = class {
12707
12741
  preparedTransaction,
12708
12742
  calls,
12709
12743
  paymasterDetails,
12744
+ await this.provider.getChainId(),
12710
12745
  maxFeeInGasToken
12711
12746
  );
12712
12747
  const transaction = await this.preparePaymasterTransaction(preparedTransaction);