starknet 6.6.6 → 6.7.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.
package/dist/index.mjs CHANGED
@@ -528,11 +528,9 @@ var BlockTag = /* @__PURE__ */ ((BlockTag2) => {
528
528
  })(BlockTag || {});
529
529
 
530
530
  // src/types/typedData.ts
531
- var TypedDataRevision = /* @__PURE__ */ ((TypedDataRevision2) => {
532
- TypedDataRevision2["Active"] = "1";
533
- TypedDataRevision2["Legacy"] = "0";
534
- return TypedDataRevision2;
535
- })(TypedDataRevision || {});
531
+ import {
532
+ TypedDataRevision
533
+ } from "starknet-types";
536
534
 
537
535
  // src/utils/assert.ts
538
536
  function assert(condition, message) {
@@ -3175,6 +3173,23 @@ function contractClassResponseToLegacyCompiledContract(ccr) {
3175
3173
  return { ...contract, program: decompressProgram(contract.program) };
3176
3174
  }
3177
3175
 
3176
+ // src/utils/eth.ts
3177
+ var eth_exports = {};
3178
+ __export(eth_exports, {
3179
+ ethRandomPrivateKey: () => ethRandomPrivateKey,
3180
+ validateAndParseEthAddress: () => validateAndParseEthAddress
3181
+ });
3182
+ import { secp256k1 } from "@noble/curves/secp256k1";
3183
+ function ethRandomPrivateKey() {
3184
+ return sanitizeHex(buf2hex(secp256k1.utils.randomPrivateKey()));
3185
+ }
3186
+ function validateAndParseEthAddress(address) {
3187
+ assertInRange(address, ZERO, 2n ** 160n - 1n, "Ethereum Address ");
3188
+ const result = addHexPrefix(removeHexPrefix(toHex(address)).padStart(40, "0"));
3189
+ assert(result.match(/^(0x)?[0-9a-f]{40}$/), "Invalid Ethereum Address Format");
3190
+ return result;
3191
+ }
3192
+
3178
3193
  // src/utils/fetchPonyfill.ts
3179
3194
  import makeFetchCookie from "fetch-cookie";
3180
3195
  import isomorphicFetch from "isomorphic-fetch";
@@ -3853,7 +3868,7 @@ var RpcChannel = class {
3853
3868
  estimateMessageFee(message, blockIdentifier = this.blockIdentifier) {
3854
3869
  const { from_address, to_address, entry_point_selector, payload } = message;
3855
3870
  const formattedMessage = {
3856
- from_address: toHex(from_address),
3871
+ from_address: validateAndParseEthAddress(from_address),
3857
3872
  to_address: toHex(to_address),
3858
3873
  entry_point_selector: getSelector(entry_point_selector),
3859
3874
  payload: getHexStringArray(payload)
@@ -3965,11 +3980,11 @@ var RpcChannel2 = class {
3965
3980
  requestId;
3966
3981
  blockIdentifier;
3967
3982
  chainId;
3968
- speckVersion;
3983
+ specVersion;
3969
3984
  waitMode;
3970
3985
  // behave like web2 rpc and return when tx is processed
3971
3986
  constructor(optionsOrProvider) {
3972
- const { nodeUrl, retries, headers, blockIdentifier, chainId, waitMode } = optionsOrProvider || {};
3987
+ const { nodeUrl, retries, headers, blockIdentifier, chainId, specVersion, waitMode } = optionsOrProvider || {};
3973
3988
  if (Object.values(NetworkName).includes(nodeUrl)) {
3974
3989
  this.nodeUrl = getDefaultNodeUrl(nodeUrl, optionsOrProvider?.default);
3975
3990
  } else if (nodeUrl) {
@@ -3981,6 +3996,7 @@ var RpcChannel2 = class {
3981
3996
  this.headers = { ...defaultOptions2.headers, ...headers };
3982
3997
  this.blockIdentifier = blockIdentifier || defaultOptions2.blockIdentifier;
3983
3998
  this.chainId = chainId;
3999
+ this.specVersion = specVersion;
3984
4000
  this.waitMode = waitMode || false;
3985
4001
  this.requestId = 0;
3986
4002
  }
@@ -4032,8 +4048,8 @@ var RpcChannel2 = class {
4032
4048
  return this.chainId;
4033
4049
  }
4034
4050
  async getSpecVersion() {
4035
- this.speckVersion ??= await this.fetchEndpoint("starknet_specVersion");
4036
- return this.speckVersion;
4051
+ this.specVersion ??= await this.fetchEndpoint("starknet_specVersion");
4052
+ return this.specVersion;
4037
4053
  }
4038
4054
  getNonceForAddress(contractAddress, blockIdentifier = this.blockIdentifier) {
4039
4055
  const contract_address = toHex(contractAddress);
@@ -4390,7 +4406,7 @@ var RpcChannel2 = class {
4390
4406
  estimateMessageFee(message, blockIdentifier = this.blockIdentifier) {
4391
4407
  const { from_address, to_address, entry_point_selector, payload } = message;
4392
4408
  const formattedMessage = {
4393
- from_address: toHex(from_address),
4409
+ from_address: validateAndParseEthAddress(from_address),
4394
4410
  to_address: toHex(to_address),
4395
4411
  entry_point_selector: getSelector(entry_point_selector),
4396
4412
  payload: getHexStringArray(payload)
@@ -4524,7 +4540,9 @@ var RPCResponseParser = class {
4524
4540
  gas_price: toBigInt(val.gas_price),
4525
4541
  unit: val.unit,
4526
4542
  suggestedMaxFee: this.estimatedFeeToMaxFee(val.overall_fee),
4527
- resourceBounds: this.estimateFeeToBounds(val)
4543
+ resourceBounds: this.estimateFeeToBounds(val),
4544
+ data_gas_consumed: val.data_gas_consumed ? toBigInt(val.data_gas_consumed) : 0n,
4545
+ data_gas_price: val.data_gas_price ? toBigInt(val.data_gas_price) : 0n
4528
4546
  };
4529
4547
  }
4530
4548
  parseFeeEstimateBulkResponse(res) {
@@ -4534,7 +4552,9 @@ var RPCResponseParser = class {
4534
4552
  gas_price: toBigInt(val.gas_price),
4535
4553
  unit: val.unit,
4536
4554
  suggestedMaxFee: this.estimatedFeeToMaxFee(val.overall_fee),
4537
- resourceBounds: this.estimateFeeToBounds(val)
4555
+ resourceBounds: this.estimateFeeToBounds(val),
4556
+ data_gas_consumed: val.data_gas_consumed ? toBigInt(val.data_gas_consumed) : 0n,
4557
+ data_gas_price: val.data_gas_price ? toBigInt(val.data_gas_price) : 0n
4538
4558
  }));
4539
4559
  }
4540
4560
  parseSimulateTransactionResponse(res) {
@@ -5404,14 +5424,14 @@ var presetTypes = {
5404
5424
  )
5405
5425
  };
5406
5426
  var revisionConfiguration = {
5407
- ["1" /* Active */]: {
5427
+ [TypedDataRevision.Active]: {
5408
5428
  domain: "StarknetDomain",
5409
5429
  hashMethod: computePoseidonHashOnElements,
5410
5430
  hashMerkleMethod: computePoseidonHash,
5411
5431
  escapeTypeString: (s) => `"${s}"`,
5412
5432
  presetTypes
5413
5433
  },
5414
- ["0" /* Legacy */]: {
5434
+ [TypedDataRevision.Legacy]: {
5415
5435
  domain: "StarkNetDomain",
5416
5436
  hashMethod: computePedersenHashOnElements,
5417
5437
  hashMerkleMethod: computePedersenHash,
@@ -5424,10 +5444,10 @@ function assertRange(data, type, { min, max }) {
5424
5444
  assert(value >= min && value <= max, `${value} (${type}) is out of bounds [${min}, ${max}]`);
5425
5445
  }
5426
5446
  function identifyRevision({ types, domain }) {
5427
- if (revisionConfiguration["1" /* Active */].domain in types && domain.revision === "1" /* Active */)
5428
- return "1" /* Active */;
5429
- if (revisionConfiguration["0" /* Legacy */].domain in types && (domain.revision ?? "0" /* Legacy */) === "0" /* Legacy */)
5430
- return "0" /* Legacy */;
5447
+ if (revisionConfiguration[TypedDataRevision.Active].domain in types && domain.revision === TypedDataRevision.Active)
5448
+ return TypedDataRevision.Active;
5449
+ if (revisionConfiguration[TypedDataRevision.Legacy].domain in types && (domain.revision ?? TypedDataRevision.Legacy) === TypedDataRevision.Legacy)
5450
+ return TypedDataRevision.Legacy;
5431
5451
  return void 0;
5432
5452
  }
5433
5453
  function getHex(value) {
@@ -5452,10 +5472,10 @@ function prepareSelector(selector) {
5452
5472
  function isMerkleTreeType(type) {
5453
5473
  return type.type === "merkletree";
5454
5474
  }
5455
- function getDependencies(types, type, dependencies = [], contains = "", revision = "0" /* Legacy */) {
5475
+ function getDependencies(types, type, dependencies = [], contains = "", revision = TypedDataRevision.Legacy) {
5456
5476
  if (type[type.length - 1] === "*") {
5457
5477
  type = type.slice(0, -1);
5458
- } else if (revision === "1" /* Active */) {
5478
+ } else if (revision === TypedDataRevision.Active) {
5459
5479
  if (type === "enum") {
5460
5480
  type = contains;
5461
5481
  } else if (type.match(/^\(.*\)$/)) {
@@ -5493,8 +5513,8 @@ function getMerkleTreeType(types, ctx) {
5493
5513
  }
5494
5514
  return "raw";
5495
5515
  }
5496
- function encodeType(types, type, revision = "0" /* Legacy */) {
5497
- const allTypes = revision === "1" /* Active */ ? { ...types, ...revisionConfiguration[revision].presetTypes } : types;
5516
+ function encodeType(types, type, revision = TypedDataRevision.Legacy) {
5517
+ const allTypes = revision === TypedDataRevision.Active ? { ...types, ...revisionConfiguration[revision].presetTypes } : types;
5498
5518
  const [primary, ...dependencies] = getDependencies(
5499
5519
  allTypes,
5500
5520
  type,
@@ -5506,17 +5526,17 @@ function encodeType(types, type, revision = "0" /* Legacy */) {
5506
5526
  const esc = revisionConfiguration[revision].escapeTypeString;
5507
5527
  return newTypes.map((dependency) => {
5508
5528
  const dependencyElements = allTypes[dependency].map((t) => {
5509
- const targetType = t.type === "enum" && revision === "1" /* Active */ ? t.contains : t.type;
5529
+ const targetType = t.type === "enum" && revision === TypedDataRevision.Active ? t.contains : t.type;
5510
5530
  const typeString = targetType.match(/^\(.*\)$/) ? `(${targetType.slice(1, -1).split(",").map((e) => e ? esc(e) : e).join(",")})` : esc(targetType);
5511
5531
  return `${esc(t.name)}:${typeString}`;
5512
5532
  });
5513
5533
  return `${esc(dependency)}(${dependencyElements})`;
5514
5534
  }).join("");
5515
5535
  }
5516
- function getTypeHash(types, type, revision = "0" /* Legacy */) {
5536
+ function getTypeHash(types, type, revision = TypedDataRevision.Legacy) {
5517
5537
  return getSelectorFromName(encodeType(types, type, revision));
5518
5538
  }
5519
- function encodeValue(types, type, data, ctx = {}, revision = "0" /* Legacy */) {
5539
+ function encodeValue(types, type, data, ctx = {}, revision = TypedDataRevision.Legacy) {
5520
5540
  if (types[type]) {
5521
5541
  return [type, getStructHash(types, type, data, revision)];
5522
5542
  }
@@ -5539,7 +5559,7 @@ function encodeValue(types, type, data, ctx = {}, revision = "0" /* Legacy */) {
5539
5559
  }
5540
5560
  switch (type) {
5541
5561
  case "enum": {
5542
- if (revision === "1" /* Active */) {
5562
+ if (revision === TypedDataRevision.Active) {
5543
5563
  const [variantKey, variantData] = Object.entries(data)[0];
5544
5564
  const parentType = types[ctx.parent][0];
5545
5565
  const enumType = types[parentType.contains];
@@ -5573,7 +5593,7 @@ function encodeValue(types, type, data, ctx = {}, revision = "0" /* Legacy */) {
5573
5593
  return ["felt", prepareSelector(data)];
5574
5594
  }
5575
5595
  case "string": {
5576
- if (revision === "1" /* Active */) {
5596
+ if (revision === TypedDataRevision.Active) {
5577
5597
  const byteArray = byteArrayFromString(data);
5578
5598
  const elements = [
5579
5599
  byteArray.data.length,
@@ -5586,7 +5606,7 @@ function encodeValue(types, type, data, ctx = {}, revision = "0" /* Legacy */) {
5586
5606
  return [type, getHex(data)];
5587
5607
  }
5588
5608
  case "i128": {
5589
- if (revision === "1" /* Active */) {
5609
+ if (revision === TypedDataRevision.Active) {
5590
5610
  const value = BigInt(data);
5591
5611
  assertRange(value, type, RANGE_I128);
5592
5612
  return [type, getHex(value < 0n ? PRIME + value : value)];
@@ -5595,40 +5615,40 @@ function encodeValue(types, type, data, ctx = {}, revision = "0" /* Legacy */) {
5595
5615
  }
5596
5616
  case "timestamp":
5597
5617
  case "u128": {
5598
- if (revision === "1" /* Active */) {
5618
+ if (revision === TypedDataRevision.Active) {
5599
5619
  assertRange(data, type, RANGE_U128);
5600
5620
  }
5601
5621
  return [type, getHex(data)];
5602
5622
  }
5603
5623
  case "felt":
5604
5624
  case "shortstring": {
5605
- if (revision === "1" /* Active */) {
5625
+ if (revision === TypedDataRevision.Active) {
5606
5626
  assertRange(getHex(data), type, RANGE_FELT);
5607
5627
  }
5608
5628
  return [type, getHex(data)];
5609
5629
  }
5610
5630
  case "ClassHash":
5611
5631
  case "ContractAddress": {
5612
- if (revision === "1" /* Active */) {
5632
+ if (revision === TypedDataRevision.Active) {
5613
5633
  assertRange(data, type, RANGE_FELT);
5614
5634
  }
5615
5635
  return [type, getHex(data)];
5616
5636
  }
5617
5637
  case "bool": {
5618
- if (revision === "1" /* Active */) {
5638
+ if (revision === TypedDataRevision.Active) {
5619
5639
  assert(typeof data === "boolean", `Type mismatch for ${type} ${data}`);
5620
5640
  }
5621
5641
  return [type, getHex(data)];
5622
5642
  }
5623
5643
  default: {
5624
- if (revision === "1" /* Active */) {
5644
+ if (revision === TypedDataRevision.Active) {
5625
5645
  throw new Error(`Unsupported type: ${type}`);
5626
5646
  }
5627
5647
  return [type, getHex(data)];
5628
5648
  }
5629
5649
  }
5630
5650
  }
5631
- function encodeData(types, type, data, revision = "0" /* Legacy */) {
5651
+ function encodeData(types, type, data, revision = TypedDataRevision.Legacy) {
5632
5652
  const targetType = types[type] ?? revisionConfiguration[revision].presetTypes[type];
5633
5653
  const [returnTypes, values] = targetType.reduce(
5634
5654
  ([ts, vs], field) => {
@@ -5647,7 +5667,7 @@ function encodeData(types, type, data, revision = "0" /* Legacy */) {
5647
5667
  );
5648
5668
  return [returnTypes, values];
5649
5669
  }
5650
- function getStructHash(types, type, data, revision = "0" /* Legacy */) {
5670
+ function getStructHash(types, type, data, revision = TypedDataRevision.Legacy) {
5651
5671
  return revisionConfiguration[revision].hashMethod(encodeData(types, type, data, revision)[1]);
5652
5672
  }
5653
5673
  function getMessageHash(typedData, account) {
@@ -5759,16 +5779,6 @@ var Signer = class {
5759
5779
  // src/signer/ethSigner.ts
5760
5780
  import { secp256k1 as secp256k12 } from "@noble/curves/secp256k1";
5761
5781
 
5762
- // src/utils/eth.ts
5763
- var eth_exports = {};
5764
- __export(eth_exports, {
5765
- ethRandomPrivateKey: () => ethRandomPrivateKey
5766
- });
5767
- import { secp256k1 } from "@noble/curves/secp256k1";
5768
- function ethRandomPrivateKey() {
5769
- return sanitizeHex(buf2hex(secp256k1.utils.randomPrivateKey()));
5770
- }
5771
-
5772
5782
  // src/utils/uint256.ts
5773
5783
  var uint256_exports = {};
5774
5784
  __export(uint256_exports, {
@@ -6131,8 +6141,9 @@ var Account = class extends RpcProvider2 {
6131
6141
  skipExecute
6132
6142
  });
6133
6143
  }
6134
- async execute(calls, abis = void 0, details = {}) {
6135
- const transactions = Array.isArray(calls) ? calls : [calls];
6144
+ async execute(transactions, arg2, transactionsDetail = {}) {
6145
+ const details = arg2 === void 0 || Array.isArray(arg2) ? transactionsDetail : arg2;
6146
+ const calls = Array.isArray(transactions) ? transactions : [transactions];
6136
6147
  const nonce = toBigInt(details.nonce ?? await this.getNonce());
6137
6148
  const version = toTransactionVersion(
6138
6149
  this.getPreferredVersion("0x1" /* V1 */, "0x3" /* V3 */),
@@ -6141,7 +6152,7 @@ var Account = class extends RpcProvider2 {
6141
6152
  );
6142
6153
  const estimate = await this.getUniversalSuggestedFee(
6143
6154
  version,
6144
- { type: "INVOKE_FUNCTION" /* INVOKE */, payload: calls },
6155
+ { type: "INVOKE_FUNCTION" /* INVOKE */, payload: transactions },
6145
6156
  {
6146
6157
  ...details,
6147
6158
  version
@@ -6158,8 +6169,8 @@ var Account = class extends RpcProvider2 {
6158
6169
  chainId,
6159
6170
  cairoVersion: await this.getCairoVersion()
6160
6171
  };
6161
- const signature = await this.signer.signTransaction(transactions, signerDetails, abis);
6162
- const calldata = getExecuteCalldata(transactions, await this.getCairoVersion());
6172
+ const signature = await this.signer.signTransaction(calls, signerDetails);
6173
+ const calldata = getExecuteCalldata(calls, await this.getCairoVersion());
6163
6174
  return this.invokeFunction(
6164
6175
  { contractAddress: this.address, calldata, signature },
6165
6176
  {
@@ -6371,7 +6382,9 @@ var Account = class extends RpcProvider2 {
6371
6382
  overall_fee: ZERO,
6372
6383
  unit: "FRI",
6373
6384
  suggestedMaxFee: ZERO,
6374
- resourceBounds: estimateFeeToBounds(ZERO)
6385
+ resourceBounds: estimateFeeToBounds(ZERO),
6386
+ data_gas_consumed: 0n,
6387
+ data_gas_price: 0n
6375
6388
  };
6376
6389
  break;
6377
6390
  }
@@ -6540,6 +6553,23 @@ var AccountInterface = class extends ProviderInterface {
6540
6553
  };
6541
6554
 
6542
6555
  // src/wallet/connect.ts
6556
+ var connect_exports = {};
6557
+ __export(connect_exports, {
6558
+ addDeclareTransaction: () => addDeclareTransaction,
6559
+ addDeployAccountTransaction: () => addDeployAccountTransaction,
6560
+ addInvokeTransaction: () => addInvokeTransaction,
6561
+ addStarknetChain: () => addStarknetChain,
6562
+ deploymentData: () => deploymentData,
6563
+ getPermissions: () => getPermissions,
6564
+ onAccountChange: () => onAccountChange,
6565
+ onNetworkChanged: () => onNetworkChanged,
6566
+ requestAccounts: () => requestAccounts,
6567
+ requestChainId: () => requestChainId,
6568
+ signMessage: () => signMessage,
6569
+ supportedSpecs: () => supportedSpecs,
6570
+ switchStarknetChain: () => switchStarknetChain,
6571
+ watchAsset: () => watchAsset
6572
+ });
6543
6573
  function requestAccounts(swo, silentMode = false) {
6544
6574
  return swo.request({
6545
6575
  type: "wallet_requestAccounts",
@@ -7225,17 +7255,12 @@ export {
7225
7255
  ValidateType,
7226
7256
  WalletAccount,
7227
7257
  addAddressPadding,
7228
- addDeclareTransaction,
7229
- addDeployAccountTransaction,
7230
- addInvokeTransaction,
7231
- addStarknetChain,
7232
7258
  buildUrl,
7233
7259
  byteArray_exports as byteArray,
7234
7260
  cairo_exports as cairo,
7235
7261
  constants_exports as constants,
7236
7262
  contractClassResponseToLegacyCompiledContract,
7237
7263
  defaultProvider,
7238
- deploymentData,
7239
7264
  ec_exports as ec,
7240
7265
  encode_exports as encode,
7241
7266
  eth_exports as eth,
@@ -7245,7 +7270,6 @@ export {
7245
7270
  fixStack,
7246
7271
  getCalldata,
7247
7272
  getChecksumAddress,
7248
- getPermissions,
7249
7273
  hash_exports as hash,
7250
7274
  isSierra,
7251
7275
  isUrl,
@@ -7253,20 +7277,13 @@ export {
7253
7277
  merkle_exports as merkle,
7254
7278
  num_exports as num,
7255
7279
  number,
7256
- onAccountChange,
7257
- onNetworkChanged,
7258
7280
  parseUDCEvent,
7259
7281
  provider_exports as provider,
7260
- requestAccounts,
7261
- requestChainId,
7262
7282
  selector_exports as selector,
7263
7283
  shortString_exports as shortString,
7264
- signMessage,
7265
7284
  splitArgsAndOptions,
7266
7285
  stark_exports as stark,
7267
7286
  starknetId_exports as starknetId,
7268
- supportedSpecs,
7269
- switchStarknetChain,
7270
7287
  transaction_exports as transaction,
7271
7288
  typedData_exports as typedData,
7272
7289
  types_exports as types,
@@ -7275,6 +7292,6 @@ export {
7275
7292
  v3_exports as v3hash,
7276
7293
  validateAndParseAddress,
7277
7294
  validateChecksumAddress,
7278
- watchAsset
7295
+ connect_exports as wallet
7279
7296
  };
7280
7297
  //# sourceMappingURL=index.mjs.map