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.js CHANGED
@@ -192,6 +192,7 @@ __export(index_exports, {
192
192
  starknetIdPlugin: () => starknetId,
193
193
  toAnyPatchVersion: () => toAnyPatchVersion,
194
194
  toApiVersion: () => toApiVersion,
195
+ toReleaseVersion: () => toReleaseVersion,
195
196
  transaction: () => transaction_exports,
196
197
  typedData: () => typedData_exports,
197
198
  uint256: () => uint256_exports,
@@ -5510,13 +5511,16 @@ function toAnyPatchVersion(version) {
5510
5511
  }
5511
5512
  return `${parts[0]}.${parts[1]}.*`;
5512
5513
  }
5514
+ function toReleaseVersion(version) {
5515
+ return version.split(/[-+]/)[0];
5516
+ }
5513
5517
  function toApiVersion(version) {
5514
5518
  const [major, minor] = version.replace(/^v/, "").split(".");
5515
5519
  return `v${major}_${minor}`;
5516
5520
  }
5517
5521
  function compareVersions(a, b) {
5518
- const aParts = a.split(".").map(Number);
5519
- const bParts = b.split(".").map(Number);
5522
+ const aParts = toReleaseVersion(a).split(".").map(Number);
5523
+ const bParts = toReleaseVersion(b).split(".").map(Number);
5520
5524
  const maxLen = Math.max(aParts.length, bParts.length);
5521
5525
  for (let i = 0; i < maxLen; i += 1) {
5522
5526
  const aNum = aParts[i] || 0;
@@ -6274,7 +6278,7 @@ var RpcChannel = class {
6274
6278
  this.chainId = chainId;
6275
6279
  this.headers = { ...channelDefaults.options.headers, ...headers };
6276
6280
  this.retries = retries ?? channelDefaults.options.retries;
6277
- this.specVersion = specVersion;
6281
+ this.specVersion = specVersion ? toReleaseVersion(specVersion) : void 0;
6278
6282
  this.transactionRetryIntervalFallback = transactionRetryIntervalFallback ?? channelDefaults.options.transactionRetryIntervalFallback;
6279
6283
  this.waitMode = waitMode ?? false;
6280
6284
  this.requestId = 0;
@@ -6362,18 +6366,19 @@ var RpcChannel = class {
6362
6366
  */
6363
6367
  async setUpSpecVersion() {
6364
6368
  if (!this.specVersion) {
6365
- const unknownSpecVersion = await this.fetchEndpoint("starknet_specVersion");
6366
- if (!isVersion(this.channelSpecVersion, unknownSpecVersion)) {
6369
+ const nodeSpecVersion = await this.fetchEndpoint("starknet_specVersion");
6370
+ const specVersion = toReleaseVersion(nodeSpecVersion);
6371
+ if (!isVersion(this.channelSpecVersion, specVersion)) {
6367
6372
  logger.error(SYSTEM_MESSAGES.channelVersionMismatch, {
6368
6373
  channelId: this.id,
6369
6374
  channelSpecVersion: this.channelSpecVersion,
6370
- nodeSpecVersion: this.specVersion
6375
+ nodeSpecVersion
6371
6376
  });
6372
6377
  }
6373
- if (!isSupportedSpecVersion(unknownSpecVersion)) {
6378
+ if (!isSupportedSpecVersion(specVersion)) {
6374
6379
  throw new LibraryError(`${SYSTEM_MESSAGES.unsupportedSpecVersion}, channelId: ${this.id}`);
6375
6380
  }
6376
- this.specVersion = unknownSpecVersion;
6381
+ this.specVersion = specVersion;
6377
6382
  }
6378
6383
  return this.specVersion;
6379
6384
  }
@@ -6835,7 +6840,7 @@ var RpcChannel2 = class {
6835
6840
  this.chainId = chainId;
6836
6841
  this.headers = { ...channelDefaults.options.headers, ...headers };
6837
6842
  this.retries = retries ?? channelDefaults.options.retries;
6838
- this.specVersion = specVersion;
6843
+ this.specVersion = specVersion ? toReleaseVersion(specVersion) : void 0;
6839
6844
  this.transactionRetryIntervalFallback = transactionRetryIntervalFallback ?? channelDefaults.options.transactionRetryIntervalFallback;
6840
6845
  this.waitMode = waitMode ?? false;
6841
6846
  this.requestId = 0;
@@ -6923,18 +6928,19 @@ var RpcChannel2 = class {
6923
6928
  */
6924
6929
  async setUpSpecVersion() {
6925
6930
  if (!this.specVersion) {
6926
- const unknownSpecVersion = await this.fetchEndpoint("starknet_specVersion");
6927
- if (!isVersion("0.10", unknownSpecVersion)) {
6931
+ const nodeSpecVersion = await this.fetchEndpoint("starknet_specVersion");
6932
+ const specVersion = toReleaseVersion(nodeSpecVersion);
6933
+ if (!isVersion("0.10", specVersion)) {
6928
6934
  logger.error(SYSTEM_MESSAGES.channelVersionMismatch, {
6929
6935
  channelId: this.id,
6930
6936
  channelSpecVersion: this.channelSpecVersion,
6931
- nodeSpecVersion: this.specVersion
6937
+ nodeSpecVersion
6932
6938
  });
6933
6939
  }
6934
- if (!isSupportedSpecVersion(unknownSpecVersion)) {
6940
+ if (!isSupportedSpecVersion(specVersion)) {
6935
6941
  throw new LibraryError(`${SYSTEM_MESSAGES.unsupportedSpecVersion}, channelId: ${this.id}`);
6936
6942
  }
6937
- this.specVersion = unknownSpecVersion;
6943
+ this.specVersion = specVersion;
6938
6944
  }
6939
6945
  return this.specVersion;
6940
6946
  }
@@ -9888,16 +9894,17 @@ var RpcProvider = class {
9888
9894
  static async create(optionsOrProvider) {
9889
9895
  const channel = new rpc_0_9_0_exports.RpcChannel({ ...optionsOrProvider });
9890
9896
  const spec = await channel.getSpecVersion();
9891
- if (!isSupportedSpecVersion(spec)) {
9897
+ const specVersion = toReleaseVersion(spec);
9898
+ if (!isSupportedSpecVersion(specVersion)) {
9892
9899
  logger.warn(`Using incompatible node spec version ${spec}`);
9893
9900
  }
9894
- if (isVersion("0.9", spec)) {
9901
+ if (isVersion("0.9", specVersion)) {
9895
9902
  return new this({
9896
9903
  ...optionsOrProvider,
9897
9904
  specVersion: _SupportedRpcVersion.v0_9_0
9898
9905
  });
9899
9906
  }
9900
- if (isVersion("0.10", spec)) {
9907
+ if (isVersion("0.10", specVersion)) {
9901
9908
  return new this({
9902
9909
  ...optionsOrProvider,
9903
9910
  specVersion: _SupportedRpcVersion.v0_10_3
@@ -11510,9 +11517,12 @@ var getDefaultPaymasterNodeUrl = (networkName, mute = false) => {
11510
11517
  var assertGasFeeFromUnsafeCalls = (unsafeCalls, fees) => {
11511
11518
  const unsafeCall = toOutsideCallV2(unsafeCalls[unsafeCalls.length - 1]);
11512
11519
  const unsafeGasTokenCalldata = CallData.toCalldata(unsafeCall.Calldata);
11513
- const unsafeGasTokenValue = unsafeGasTokenCalldata[1];
11520
+ const unsafeGasTokenValue = uint256ToBN({
11521
+ low: unsafeGasTokenCalldata[1],
11522
+ high: unsafeGasTokenCalldata[2]
11523
+ });
11514
11524
  assert(
11515
- BigInt(unsafeGasTokenValue) === BigInt(fees),
11525
+ unsafeGasTokenValue === BigInt(fees),
11516
11526
  "Gas token value is not equal to the provided gas fees"
11517
11527
  );
11518
11528
  };
@@ -11522,12 +11532,21 @@ var assertGasTokenFromUnsafeCalls = (unsafeCalls, gasToken) => {
11522
11532
  BigInt(unsafeCall.To) === BigInt(gasToken),
11523
11533
  "Gas token address is not equal to the provided gas token"
11524
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
+ );
11525
11543
  };
11526
- function assertCallsAreStrictlyEqual(originalCalls, unsafeCalls) {
11544
+ function assertCallsAreStrictlyEqual(originalCalls, unsafeCalls, isSponsored = false) {
11527
11545
  const baseError = "Provided calls are not strictly equal to the returned calls";
11546
+ const expectedExtraCalls = isSponsored ? 0 : 1;
11528
11547
  assert(
11529
- unsafeCalls.length - 1 === originalCalls.length,
11530
- `${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}`
11531
11550
  );
11532
11551
  for (let callIndex = 0; callIndex < originalCalls.length; callIndex += 1) {
11533
11552
  const originalCall = originalCalls[callIndex];
@@ -11561,21 +11580,42 @@ function assertCallsAreStrictlyEqual(originalCalls, unsafeCalls) {
11561
11580
  }
11562
11581
  }
11563
11582
  }
11564
- var assertPaymasterTransactionSafety = (preparedTransaction, calls, paymasterDetails, maxFeeInGasToken) => {
11565
- if (paymasterDetails.feeMode.mode !== "sponsored") {
11566
- if (preparedTransaction.type === "invoke" || preparedTransaction.type === "deploy_and_invoke") {
11567
- const unsafeCalls = "calls" in preparedTransaction.typed_data.message ? preparedTransaction.typed_data.message.calls : preparedTransaction.typed_data.message.Calls;
11568
- 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") {
11569
11609
  assertGasTokenFromUnsafeCalls(unsafeCalls, paymasterDetails.feeMode.gasToken);
11610
+ assertGasFeeFromUnsafeCalls(
11611
+ unsafeCalls,
11612
+ preparedTransaction.fee.suggested_max_fee_in_gas_token
11613
+ );
11570
11614
  if (maxFeeInGasToken) {
11571
11615
  assert(
11572
11616
  preparedTransaction.fee.suggested_max_fee_in_gas_token <= maxFeeInGasToken,
11573
11617
  "Gas token price is too high"
11574
11618
  );
11575
- assertGasFeeFromUnsafeCalls(
11576
- unsafeCalls,
11577
- preparedTransaction.fee.suggested_max_fee_in_gas_token
11578
- );
11579
11619
  }
11580
11620
  }
11581
11621
  }
@@ -12700,6 +12740,7 @@ var Account = class {
12700
12740
  preparedTransaction,
12701
12741
  calls,
12702
12742
  paymasterDetails,
12743
+ await this.provider.getChainId(),
12703
12744
  maxFeeInGasToken
12704
12745
  );
12705
12746
  const transaction = await this.preparePaymasterTransaction(preparedTransaction);
@@ -14147,6 +14188,7 @@ function units(amount, simbol = "fri") {
14147
14188
  starknetIdPlugin,
14148
14189
  toAnyPatchVersion,
14149
14190
  toApiVersion,
14191
+ toReleaseVersion,
14150
14192
  transaction,
14151
14193
  typedData,
14152
14194
  uint256,