starknet 10.7.0 → 10.7.2

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
@@ -5326,13 +5326,16 @@ function toAnyPatchVersion(version) {
5326
5326
  }
5327
5327
  return `${parts[0]}.${parts[1]}.*`;
5328
5328
  }
5329
+ function toReleaseVersion(version) {
5330
+ return version.split(/[-+]/)[0];
5331
+ }
5329
5332
  function toApiVersion(version) {
5330
5333
  const [major, minor] = version.replace(/^v/, "").split(".");
5331
5334
  return `v${major}_${minor}`;
5332
5335
  }
5333
5336
  function compareVersions(a, b) {
5334
- const aParts = a.split(".").map(Number);
5335
- const bParts = b.split(".").map(Number);
5337
+ const aParts = toReleaseVersion(a).split(".").map(Number);
5338
+ const bParts = toReleaseVersion(b).split(".").map(Number);
5336
5339
  const maxLen = Math.max(aParts.length, bParts.length);
5337
5340
  for (let i = 0; i < maxLen; i += 1) {
5338
5341
  const aNum = aParts[i] || 0;
@@ -6090,7 +6093,7 @@ var RpcChannel = class {
6090
6093
  this.chainId = chainId;
6091
6094
  this.headers = { ...channelDefaults.options.headers, ...headers };
6092
6095
  this.retries = retries ?? channelDefaults.options.retries;
6093
- this.specVersion = specVersion;
6096
+ this.specVersion = specVersion ? toReleaseVersion(specVersion) : void 0;
6094
6097
  this.transactionRetryIntervalFallback = transactionRetryIntervalFallback ?? channelDefaults.options.transactionRetryIntervalFallback;
6095
6098
  this.waitMode = waitMode ?? false;
6096
6099
  this.requestId = 0;
@@ -6178,18 +6181,19 @@ var RpcChannel = class {
6178
6181
  */
6179
6182
  async setUpSpecVersion() {
6180
6183
  if (!this.specVersion) {
6181
- const unknownSpecVersion = await this.fetchEndpoint("starknet_specVersion");
6182
- if (!isVersion(this.channelSpecVersion, unknownSpecVersion)) {
6184
+ const nodeSpecVersion = await this.fetchEndpoint("starknet_specVersion");
6185
+ const specVersion = toReleaseVersion(nodeSpecVersion);
6186
+ if (!isVersion(this.channelSpecVersion, specVersion)) {
6183
6187
  logger.error(SYSTEM_MESSAGES.channelVersionMismatch, {
6184
6188
  channelId: this.id,
6185
6189
  channelSpecVersion: this.channelSpecVersion,
6186
- nodeSpecVersion: this.specVersion
6190
+ nodeSpecVersion
6187
6191
  });
6188
6192
  }
6189
- if (!isSupportedSpecVersion(unknownSpecVersion)) {
6193
+ if (!isSupportedSpecVersion(specVersion)) {
6190
6194
  throw new LibraryError(`${SYSTEM_MESSAGES.unsupportedSpecVersion}, channelId: ${this.id}`);
6191
6195
  }
6192
- this.specVersion = unknownSpecVersion;
6196
+ this.specVersion = specVersion;
6193
6197
  }
6194
6198
  return this.specVersion;
6195
6199
  }
@@ -6651,7 +6655,7 @@ var RpcChannel2 = class {
6651
6655
  this.chainId = chainId;
6652
6656
  this.headers = { ...channelDefaults.options.headers, ...headers };
6653
6657
  this.retries = retries ?? channelDefaults.options.retries;
6654
- this.specVersion = specVersion;
6658
+ this.specVersion = specVersion ? toReleaseVersion(specVersion) : void 0;
6655
6659
  this.transactionRetryIntervalFallback = transactionRetryIntervalFallback ?? channelDefaults.options.transactionRetryIntervalFallback;
6656
6660
  this.waitMode = waitMode ?? false;
6657
6661
  this.requestId = 0;
@@ -6739,18 +6743,19 @@ var RpcChannel2 = class {
6739
6743
  */
6740
6744
  async setUpSpecVersion() {
6741
6745
  if (!this.specVersion) {
6742
- const unknownSpecVersion = await this.fetchEndpoint("starknet_specVersion");
6743
- if (!isVersion("0.10", unknownSpecVersion)) {
6746
+ const nodeSpecVersion = await this.fetchEndpoint("starknet_specVersion");
6747
+ const specVersion = toReleaseVersion(nodeSpecVersion);
6748
+ if (!isVersion("0.10", specVersion)) {
6744
6749
  logger.error(SYSTEM_MESSAGES.channelVersionMismatch, {
6745
6750
  channelId: this.id,
6746
6751
  channelSpecVersion: this.channelSpecVersion,
6747
- nodeSpecVersion: this.specVersion
6752
+ nodeSpecVersion
6748
6753
  });
6749
6754
  }
6750
- if (!isSupportedSpecVersion(unknownSpecVersion)) {
6755
+ if (!isSupportedSpecVersion(specVersion)) {
6751
6756
  throw new LibraryError(`${SYSTEM_MESSAGES.unsupportedSpecVersion}, channelId: ${this.id}`);
6752
6757
  }
6753
- this.specVersion = unknownSpecVersion;
6758
+ this.specVersion = specVersion;
6754
6759
  }
6755
6760
  return this.specVersion;
6756
6761
  }
@@ -9704,16 +9709,17 @@ var RpcProvider = class {
9704
9709
  static async create(optionsOrProvider) {
9705
9710
  const channel = new rpc_0_9_0_exports.RpcChannel({ ...optionsOrProvider });
9706
9711
  const spec = await channel.getSpecVersion();
9707
- if (!isSupportedSpecVersion(spec)) {
9712
+ const specVersion = toReleaseVersion(spec);
9713
+ if (!isSupportedSpecVersion(specVersion)) {
9708
9714
  logger.warn(`Using incompatible node spec version ${spec}`);
9709
9715
  }
9710
- if (isVersion("0.9", spec)) {
9716
+ if (isVersion("0.9", specVersion)) {
9711
9717
  return new this({
9712
9718
  ...optionsOrProvider,
9713
9719
  specVersion: _SupportedRpcVersion.v0_9_0
9714
9720
  });
9715
9721
  }
9716
- if (isVersion("0.10", spec)) {
9722
+ if (isVersion("0.10", specVersion)) {
9717
9723
  return new this({
9718
9724
  ...optionsOrProvider,
9719
9725
  specVersion: _SupportedRpcVersion.v0_10_3
@@ -11326,9 +11332,12 @@ var getDefaultPaymasterNodeUrl = (networkName, mute = false) => {
11326
11332
  var assertGasFeeFromUnsafeCalls = (unsafeCalls, fees) => {
11327
11333
  const unsafeCall = toOutsideCallV2(unsafeCalls[unsafeCalls.length - 1]);
11328
11334
  const unsafeGasTokenCalldata = CallData.toCalldata(unsafeCall.Calldata);
11329
- const unsafeGasTokenValue = unsafeGasTokenCalldata[1];
11335
+ const unsafeGasTokenValue = uint256ToBN({
11336
+ low: unsafeGasTokenCalldata[1],
11337
+ high: unsafeGasTokenCalldata[2]
11338
+ });
11330
11339
  assert(
11331
- BigInt(unsafeGasTokenValue) === BigInt(fees),
11340
+ unsafeGasTokenValue === BigInt(fees),
11332
11341
  "Gas token value is not equal to the provided gas fees"
11333
11342
  );
11334
11343
  };
@@ -11338,12 +11347,21 @@ var assertGasTokenFromUnsafeCalls = (unsafeCalls, gasToken) => {
11338
11347
  BigInt(unsafeCall.To) === BigInt(gasToken),
11339
11348
  "Gas token address is not equal to the provided gas token"
11340
11349
  );
11350
+ assert(
11351
+ unsafeCall.Selector === getSelectorFromName("transfer"),
11352
+ "Gas token call selector is not a transfer"
11353
+ );
11354
+ assert(
11355
+ CallData.toCalldata(unsafeCall.Calldata).length === 3,
11356
+ "Gas token transfer calldata does not match the expected recipient/amount shape"
11357
+ );
11341
11358
  };
11342
- function assertCallsAreStrictlyEqual(originalCalls, unsafeCalls) {
11359
+ function assertCallsAreStrictlyEqual(originalCalls, unsafeCalls, isSponsored = false) {
11343
11360
  const baseError = "Provided calls are not strictly equal to the returned calls";
11361
+ const expectedExtraCalls = isSponsored ? 0 : 1;
11344
11362
  assert(
11345
- unsafeCalls.length - 1 === originalCalls.length,
11346
- `${baseError}: Expected ${originalCalls.length + 1} calls, got ${unsafeCalls.length}`
11363
+ unsafeCalls.length - expectedExtraCalls === originalCalls.length,
11364
+ `${baseError}: Expected ${originalCalls.length + expectedExtraCalls} calls, got ${unsafeCalls.length}`
11347
11365
  );
11348
11366
  for (let callIndex = 0; callIndex < originalCalls.length; callIndex += 1) {
11349
11367
  const originalCall = originalCalls[callIndex];
@@ -11377,21 +11395,42 @@ function assertCallsAreStrictlyEqual(originalCalls, unsafeCalls) {
11377
11395
  }
11378
11396
  }
11379
11397
  }
11380
- var assertPaymasterTransactionSafety = (preparedTransaction, calls, paymasterDetails, maxFeeInGasToken) => {
11381
- if (paymasterDetails.feeMode.mode !== "sponsored") {
11382
- if (preparedTransaction.type === "invoke" || preparedTransaction.type === "deploy_and_invoke") {
11383
- const unsafeCalls = "calls" in preparedTransaction.typed_data.message ? preparedTransaction.typed_data.message.calls : preparedTransaction.typed_data.message.Calls;
11384
- assertCallsAreStrictlyEqual(calls, unsafeCalls);
11398
+ var domainFieldToFelt = (value) => {
11399
+ try {
11400
+ return toBigInt(value);
11401
+ } catch {
11402
+ return toBigInt(encodeShortString(String(value)));
11403
+ }
11404
+ };
11405
+ var assertChainIdFromTypedData = (typedData, chainId) => {
11406
+ assert(
11407
+ typedData.domain.chainId !== void 0 && domainFieldToFelt(typedData.domain.chainId) === BigInt(chainId),
11408
+ "Paymaster typed data domain chainId does not match the account's provider chain"
11409
+ );
11410
+ };
11411
+ var assertPaymasterTransactionSafety = (preparedTransaction, calls, paymasterDetails, chainId, maxFeeInGasToken) => {
11412
+ if (preparedTransaction.type === "invoke" || preparedTransaction.type === "deploy_and_invoke") {
11413
+ assertChainIdFromTypedData(preparedTransaction.typed_data, chainId);
11414
+ const { message } = preparedTransaction.typed_data;
11415
+ const hasV1Calls = "calls" in message;
11416
+ const hasV2Calls = "Calls" in message;
11417
+ assert(
11418
+ hasV1Calls !== hasV2Calls,
11419
+ 'Paymaster typed data must declare exactly one of "calls" (SNIP-9 V1) or "Calls" (SNIP-9 V2)'
11420
+ );
11421
+ const unsafeCalls = hasV1Calls ? message.calls : message.Calls;
11422
+ assertCallsAreStrictlyEqual(calls, unsafeCalls, paymasterDetails.feeMode.mode === "sponsored");
11423
+ if (paymasterDetails.feeMode.mode !== "sponsored") {
11385
11424
  assertGasTokenFromUnsafeCalls(unsafeCalls, paymasterDetails.feeMode.gasToken);
11425
+ assertGasFeeFromUnsafeCalls(
11426
+ unsafeCalls,
11427
+ preparedTransaction.fee.suggested_max_fee_in_gas_token
11428
+ );
11386
11429
  if (maxFeeInGasToken) {
11387
11430
  assert(
11388
11431
  preparedTransaction.fee.suggested_max_fee_in_gas_token <= maxFeeInGasToken,
11389
11432
  "Gas token price is too high"
11390
11433
  );
11391
- assertGasFeeFromUnsafeCalls(
11392
- unsafeCalls,
11393
- preparedTransaction.fee.suggested_max_fee_in_gas_token
11394
- );
11395
11434
  }
11396
11435
  }
11397
11436
  }
@@ -12516,6 +12555,7 @@ var Account = class {
12516
12555
  preparedTransaction,
12517
12556
  calls,
12518
12557
  paymasterDetails,
12558
+ await this.provider.getChainId(),
12519
12559
  maxFeeInGasToken
12520
12560
  );
12521
12561
  const transaction = await this.preparePaymasterTransaction(preparedTransaction);
@@ -13963,6 +14003,7 @@ export {
13963
14003
  starknetId as starknetIdPlugin,
13964
14004
  toAnyPatchVersion,
13965
14005
  toApiVersion,
14006
+ toReleaseVersion,
13966
14007
  transaction_exports as transaction,
13967
14008
  typedData_exports as typedData,
13968
14009
  uint256_exports as uint256,