starknet 5.26.1 → 5.28.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.js CHANGED
@@ -48,7 +48,7 @@ __export(src_exports, {
48
48
  GatewayError: () => GatewayError,
49
49
  HttpError: () => HttpError,
50
50
  LibraryError: () => LibraryError,
51
- Litteral: () => Litteral,
51
+ Literal: () => Literal,
52
52
  Provider: () => Provider,
53
53
  ProviderInterface: () => ProviderInterface,
54
54
  RPC: () => rpc_exports,
@@ -62,6 +62,7 @@ __export(src_exports, {
62
62
  TransactionFinalityStatus: () => TransactionFinalityStatus,
63
63
  TransactionStatus: () => TransactionStatus,
64
64
  TransactionType: () => TransactionType,
65
+ TypedDataRevision: () => TypedDataRevision,
65
66
  Uint: () => Uint,
66
67
  ValidateType: () => ValidateType,
67
68
  addAddressPadding: () => addAddressPadding,
@@ -267,7 +268,7 @@ __export(types_exports, {
267
268
  BlockStatus: () => BlockStatus,
268
269
  BlockTag: () => BlockTag,
269
270
  EntryPointType: () => EntryPointType,
270
- Litteral: () => Litteral,
271
+ Literal: () => Literal,
271
272
  RPC: () => rpc_exports,
272
273
  SIMULATION_FLAG: () => SIMULATION_FLAG,
273
274
  Sequencer: () => sequencer_exports,
@@ -275,6 +276,7 @@ __export(types_exports, {
275
276
  TransactionFinalityStatus: () => TransactionFinalityStatus,
276
277
  TransactionStatus: () => TransactionStatus,
277
278
  TransactionType: () => TransactionType,
279
+ TypedDataRevision: () => TypedDataRevision,
278
280
  Uint: () => Uint,
279
281
  ValidateType: () => ValidateType
280
282
  });
@@ -302,11 +304,11 @@ var Uint = /* @__PURE__ */ ((Uint2) => {
302
304
  Uint2["u256"] = "core::integer::u256";
303
305
  return Uint2;
304
306
  })(Uint || {});
305
- var Litteral = /* @__PURE__ */ ((Litteral2) => {
306
- Litteral2["ClassHash"] = "core::starknet::class_hash::ClassHash";
307
- Litteral2["ContractAddress"] = "core::starknet::contract_address::ContractAddress";
308
- return Litteral2;
309
- })(Litteral || {});
307
+ var Literal = /* @__PURE__ */ ((Literal2) => {
308
+ Literal2["ClassHash"] = "core::starknet::class_hash::ClassHash";
309
+ Literal2["ContractAddress"] = "core::starknet::contract_address::ContractAddress";
310
+ return Literal2;
311
+ })(Literal || {});
310
312
 
311
313
  // src/types/lib/contract/index.ts
312
314
  var EntryPointType = /* @__PURE__ */ ((EntryPointType2) => {
@@ -359,6 +361,13 @@ var BlockTag = /* @__PURE__ */ ((BlockTag2) => {
359
361
  return BlockTag2;
360
362
  })(BlockTag || {});
361
363
 
364
+ // src/types/typedData.ts
365
+ var TypedDataRevision = /* @__PURE__ */ ((TypedDataRevision2) => {
366
+ TypedDataRevision2["Active"] = "1";
367
+ TypedDataRevision2["Legacy"] = "0";
368
+ return TypedDataRevision2;
369
+ })(TypedDataRevision || {});
370
+
362
371
  // src/types/api/rpc.ts
363
372
  var rpc_exports = {};
364
373
  __export(rpc_exports, {
@@ -626,7 +635,7 @@ __export(cairo_exports, {
626
635
  isTypeEnum: () => isTypeEnum,
627
636
  isTypeEthAddress: () => isTypeEthAddress,
628
637
  isTypeFelt: () => isTypeFelt,
629
- isTypeLitteral: () => isTypeLitteral,
638
+ isTypeLiteral: () => isTypeLiteral,
630
639
  isTypeNamedTuple: () => isTypeNamedTuple,
631
640
  isTypeOption: () => isTypeOption,
632
641
  isTypeResult: () => isTypeResult,
@@ -676,7 +685,7 @@ var isTypeEnum = (type, enums) => type in enums;
676
685
  var isTypeOption = (type) => type.startsWith("core::option::Option::");
677
686
  var isTypeResult = (type) => type.startsWith("core::result::Result::");
678
687
  var isTypeUint = (type) => Object.values(Uint).includes(type);
679
- var isTypeLitteral = (type) => Object.values(Litteral).includes(type);
688
+ var isTypeLiteral = (type) => Object.values(Literal).includes(type);
680
689
  var isTypeUint256 = (type) => type === "core::integer::u256";
681
690
  var isTypeBool = (type) => type === "core::bool";
682
691
  var isTypeContractAddress = (type) => type === "core::starknet::contract_address::ContractAddress";
@@ -749,13 +758,21 @@ function felt(it) {
749
758
 
750
759
  // src/utils/calldata/enum/CairoCustomEnum.ts
751
760
  var CairoCustomEnum = class {
761
+ /**
762
+ * direct readonly access to variants of the Cairo Custom Enum.
763
+ * @returns a value of type any
764
+ * @example
765
+ * ```typescript
766
+ * const successValue = myCairoEnum.variant.Success;
767
+ */
768
+ variant;
752
769
  /**
753
770
  * @param enumContent an object with the variants as keys and the content as value. Only one content shall be defined.
754
771
  */
755
772
  constructor(enumContent) {
756
773
  const variantsList = Object.values(enumContent);
757
774
  if (variantsList.length === 0) {
758
- throw new Error("This Enum must have a least 1 variant");
775
+ throw new Error("This Enum must have at least 1 variant");
759
776
  }
760
777
  const nbActiveVariants = variantsList.filter(
761
778
  (content) => typeof content !== "undefined"
@@ -798,6 +815,8 @@ var CairoOptionVariant = /* @__PURE__ */ ((CairoOptionVariant2) => {
798
815
  return CairoOptionVariant2;
799
816
  })(CairoOptionVariant || {});
800
817
  var CairoOption = class {
818
+ Some;
819
+ None;
801
820
  constructor(variant, someContent) {
802
821
  if (!(variant in CairoOptionVariant)) {
803
822
  throw new Error("Wrong variant : should be CairoOptionVariant.Some or .None.");
@@ -849,6 +868,8 @@ var CairoResultVariant = /* @__PURE__ */ ((CairoResultVariant2) => {
849
868
  return CairoResultVariant2;
850
869
  })(CairoResultVariant || {});
851
870
  var CairoResult = class {
871
+ Ok;
872
+ Err;
852
873
  constructor(variant, resultContent) {
853
874
  if (!(variant in CairoResultVariant)) {
854
875
  throw new Error("Wrong variant : should be CairoResultVariant.Ok or .Err.");
@@ -947,6 +968,7 @@ function formatter(data, type, sameType) {
947
968
 
948
969
  // src/utils/calldata/parser/parser-0-1.1.0.ts
949
970
  var AbiParser1 = class {
971
+ abi;
950
972
  constructor(abi) {
951
973
  this.abi = abi;
952
974
  }
@@ -978,6 +1000,7 @@ var AbiParser1 = class {
978
1000
 
979
1001
  // src/utils/calldata/parser/parser-2.0.0.ts
980
1002
  var AbiParser2 = class {
1003
+ abi;
981
1004
  constructor(abi) {
982
1005
  this.abi = abi;
983
1006
  }
@@ -1723,7 +1746,7 @@ var validateArray = (parameter, input, structs, enums) => {
1723
1746
  case isTypeEnum(baseType, enums):
1724
1747
  parameter.forEach((it) => validateEnum(it, { name: input.name, type: baseType }));
1725
1748
  break;
1726
- case (isTypeUint(baseType) || isTypeLitteral(baseType)):
1749
+ case (isTypeUint(baseType) || isTypeLiteral(baseType)):
1727
1750
  parameter.forEach((param) => validateUint(param, input));
1728
1751
  break;
1729
1752
  case isTypeBool(baseType):
@@ -1744,7 +1767,7 @@ function validateFields(abiMethod, args, structs, enums) {
1744
1767
  case isTypeFelt(input.type):
1745
1768
  validateFelt(parameter, input);
1746
1769
  break;
1747
- case (isTypeUint(input.type) || isTypeLitteral(input.type)):
1770
+ case (isTypeUint(input.type) || isTypeLiteral(input.type)):
1748
1771
  validateUint(parameter, input);
1749
1772
  break;
1750
1773
  case isTypeBool(input.type):
@@ -1773,6 +1796,10 @@ function validateFields(abiMethod, args, structs, enums) {
1773
1796
 
1774
1797
  // src/utils/calldata/index.ts
1775
1798
  var CallData = class {
1799
+ abi;
1800
+ parser;
1801
+ structs;
1802
+ enums;
1776
1803
  constructor(abi) {
1777
1804
  this.structs = CallData.getAbiStruct(abi);
1778
1805
  this.enums = CallData.getAbiEnum(abi);
@@ -2017,6 +2044,10 @@ __export(hash_exports, {
2017
2044
  computeContractClassHash: () => computeContractClassHash,
2018
2045
  computeHashOnElements: () => computeHashOnElements,
2019
2046
  computeLegacyContractClassHash: () => computeLegacyContractClassHash,
2047
+ computePedersenHash: () => computePedersenHash,
2048
+ computePedersenHashOnElements: () => computePedersenHashOnElements,
2049
+ computePoseidonHash: () => computePoseidonHash,
2050
+ computePoseidonHashOnElements: () => computePoseidonHashOnElements,
2020
2051
  computeSierraContractClassHash: () => computeSierraContractClassHash,
2021
2052
  default: () => computeHintedClassHash,
2022
2053
  feeTransactionVersion: () => feeTransactionVersion,
@@ -2071,8 +2102,18 @@ var feeTransactionVersion_2 = BN_FEE_TRANSACTION_VERSION_2;
2071
2102
  function getVersionsByType(versionType) {
2072
2103
  return versionType === "fee" ? { v1: feeTransactionVersion, v2: feeTransactionVersion_2 } : { v1: transactionVersion, v2: transactionVersion_2 };
2073
2104
  }
2105
+ function computePedersenHash(a, b) {
2106
+ return starkCurve.pedersen(BigInt(a), BigInt(b));
2107
+ }
2108
+ function computePoseidonHash(a, b) {
2109
+ return toHex(starkCurve.poseidonHash(BigInt(a), BigInt(b)));
2110
+ }
2074
2111
  function computeHashOnElements(data) {
2075
- return [...data, data.length].reduce((x, y) => starkCurve.pedersen(toBigInt(x), toBigInt(y)), 0).toString();
2112
+ return [...data, data.length].reduce((x, y) => starkCurve.pedersen(BigInt(x), BigInt(y)), 0).toString();
2113
+ }
2114
+ var computePedersenHashOnElements = computeHashOnElements;
2115
+ function computePoseidonHashOnElements(data) {
2116
+ return toHex((0, import_starknet2.poseidonHashMany)(data.map((x) => BigInt(x))));
2076
2117
  }
2077
2118
  function calculateTransactionHashCommon(txHashPrefix, version, contractAddress, entryPointSelector, calldata, maxFee, chainId, additionalData = []) {
2078
2119
  const calldataHash = computeHashOnElements(calldata);
@@ -2465,6 +2506,7 @@ function fixProto(target, prototype) {
2465
2506
  setPrototypeOf ? setPrototypeOf(target, prototype) : target.__proto__ = prototype;
2466
2507
  }
2467
2508
  var CustomError = class extends Error {
2509
+ name;
2468
2510
  constructor(message) {
2469
2511
  super(message);
2470
2512
  Object.defineProperty(this, "name", {
@@ -2641,14 +2683,9 @@ async function getAddressFromStarkName(provider, name, StarknetIdContract2) {
2641
2683
  // src/provider/utils.ts
2642
2684
  var validBlockTags = Object.values(BlockTag);
2643
2685
  var Block = class {
2644
- constructor(_identifier) {
2645
- this.hash = null;
2646
- this.number = null;
2647
- this.tag = null;
2648
- this.valueOf = () => this.number;
2649
- this.toString = () => this.hash;
2650
- this.setIdentifier(_identifier);
2651
- }
2686
+ hash = null;
2687
+ number = null;
2688
+ tag = null;
2652
2689
  setIdentifier(__identifier) {
2653
2690
  if (typeof __identifier === "string" && isHex(__identifier)) {
2654
2691
  this.hash = __identifier;
@@ -2662,6 +2699,9 @@ var Block = class {
2662
2699
  this.tag = "pending" /* pending */;
2663
2700
  }
2664
2701
  }
2702
+ constructor(_identifier) {
2703
+ this.setIdentifier(_identifier);
2704
+ }
2665
2705
  // TODO: fix any
2666
2706
  get queryIdentifier() {
2667
2707
  if (this.number !== null) {
@@ -2685,6 +2725,8 @@ var Block = class {
2685
2725
  set identifier(_identifier) {
2686
2726
  this.setIdentifier(_identifier);
2687
2727
  }
2728
+ valueOf = () => this.number;
2729
+ toString = () => this.hash;
2688
2730
  get sequencerIdentifier() {
2689
2731
  return this.hash !== null ? { blockHash: this.hash } : { blockNumber: this.number ?? this.tag };
2690
2732
  }
@@ -2704,36 +2746,13 @@ var defaultOptions = {
2704
2746
  retries: 200
2705
2747
  };
2706
2748
  var RpcProvider = class {
2749
+ nodeUrl;
2750
+ headers;
2751
+ responseParser = new RPCResponseParser();
2752
+ retries;
2753
+ blockIdentifier;
2754
+ chainId;
2707
2755
  constructor(optionsOrProvider) {
2708
- this.responseParser = new RPCResponseParser();
2709
- /**
2710
- * @deprecated renamed to getBlockLatestAccepted(); (will be removed in next minor version)
2711
- */
2712
- this.getBlockHashAndNumber = this.getBlockLatestAccepted;
2713
- /**
2714
- * @deprecated renamed to getBlockStateUpdate();
2715
- */
2716
- this.getStateUpdate = this.getBlockStateUpdate;
2717
- /**
2718
- * Returns the execution traces of all transactions included in the given block
2719
- * @deprecated renamed to getBlockTransactionsTraces()
2720
- */
2721
- this.traceBlockTransactions = this.getBlockTransactionsTraces;
2722
- /**
2723
- * Get the number of transactions in a block given a block id
2724
- * @deprecated renamed to getBlockTransactionCount()
2725
- * @returns Number of transactions
2726
- */
2727
- this.getTransactionCount = this.getBlockTransactionCount;
2728
- /**
2729
- * @deprecated renamed to getTransactionTrace();
2730
- * For a given executed transaction, return the trace of its execution, including internal calls
2731
- */
2732
- this.traceTransaction = this.getTransactionTrace;
2733
- /**
2734
- * @deprecated renamed to simulateTransaction();
2735
- */
2736
- this.getSimulateTransaction = this.simulateTransaction;
2737
2756
  const { nodeUrl, retries, headers, blockIdentifier, chainId, rpcVersion } = optionsOrProvider || {};
2738
2757
  if (Object.values(NetworkName).includes(nodeUrl)) {
2739
2758
  this.nodeUrl = getDefaultNodeUrl(
@@ -2791,7 +2810,7 @@ var RpcProvider = class {
2791
2810
  }
2792
2811
  }
2793
2812
  async getChainId() {
2794
- this.chainId ?? (this.chainId = await this.fetchEndpoint("starknet_chainId"));
2813
+ this.chainId ??= await this.fetchEndpoint("starknet_chainId");
2795
2814
  return this.chainId;
2796
2815
  }
2797
2816
  /**
@@ -2816,6 +2835,10 @@ var RpcProvider = class {
2816
2835
  this.responseParser.parseGetBlockResponse
2817
2836
  );
2818
2837
  }
2838
+ /**
2839
+ * @deprecated renamed to getBlockLatestAccepted(); (will be removed in next minor version)
2840
+ */
2841
+ getBlockHashAndNumber = this.getBlockLatestAccepted;
2819
2842
  /**
2820
2843
  * Get the most recent accepted block hash and number
2821
2844
  */
@@ -2842,14 +2865,29 @@ var RpcProvider = class {
2842
2865
  const block_id = new Block(blockIdentifier).identifier;
2843
2866
  return this.fetchEndpoint("starknet_getStateUpdate", { block_id });
2844
2867
  }
2868
+ /**
2869
+ * @deprecated renamed to getBlockStateUpdate();
2870
+ */
2871
+ getStateUpdate = this.getBlockStateUpdate;
2845
2872
  async getBlockTransactionsTraces(blockIdentifier = this.blockIdentifier) {
2846
2873
  const block_id = new Block(blockIdentifier).identifier;
2847
2874
  return this.fetchEndpoint("starknet_traceBlockTransactions", { block_id });
2848
2875
  }
2876
+ /**
2877
+ * Returns the execution traces of all transactions included in the given block
2878
+ * @deprecated renamed to getBlockTransactionsTraces()
2879
+ */
2880
+ traceBlockTransactions = this.getBlockTransactionsTraces;
2849
2881
  async getBlockTransactionCount(blockIdentifier = this.blockIdentifier) {
2850
2882
  const block_id = new Block(blockIdentifier).identifier;
2851
2883
  return this.fetchEndpoint("starknet_getBlockTransactionCount", { block_id });
2852
2884
  }
2885
+ /**
2886
+ * Get the number of transactions in a block given a block id
2887
+ * @deprecated renamed to getBlockTransactionCount()
2888
+ * @returns Number of transactions
2889
+ */
2890
+ getTransactionCount = this.getBlockTransactionCount;
2853
2891
  /**
2854
2892
  * Return transactions from pending block
2855
2893
  * @deprecated Instead use getBlock(BlockTag.pending); (will be removed in next minor version)
@@ -2882,6 +2920,11 @@ var RpcProvider = class {
2882
2920
  const transaction_hash = toHex(txHash);
2883
2921
  return this.fetchEndpoint("starknet_traceTransaction", { transaction_hash });
2884
2922
  }
2923
+ /**
2924
+ * @deprecated renamed to getTransactionTrace();
2925
+ * For a given executed transaction, return the trace of its execution, including internal calls
2926
+ */
2927
+ traceTransaction = this.getTransactionTrace;
2885
2928
  /**
2886
2929
  * NEW: Get the status of a transaction
2887
2930
  */
@@ -2889,6 +2932,10 @@ var RpcProvider = class {
2889
2932
  const transaction_hash = toHex(transactionHash);
2890
2933
  return this.fetchEndpoint("starknet_getTransactionStatus", { transaction_hash });
2891
2934
  }
2935
+ /**
2936
+ * @deprecated renamed to simulateTransaction();
2937
+ */
2938
+ getSimulateTransaction = this.simulateTransaction;
2892
2939
  /**
2893
2940
  * @param invocations AccountInvocations
2894
2941
  * @param simulateTransactionOptions blockIdentifier and flags to skip validation and fee charge<br/>
@@ -3443,8 +3490,14 @@ var defaultOptions2 = {
3443
3490
  blockIdentifier: "pending" /* pending */
3444
3491
  };
3445
3492
  var SequencerProvider = class {
3493
+ baseUrl;
3494
+ feederGatewayUrl;
3495
+ gatewayUrl;
3496
+ headers;
3497
+ blockIdentifier;
3498
+ chainId;
3499
+ responseParser = new SequencerAPIResponseParser();
3446
3500
  constructor(optionsOrProvider = defaultOptions2) {
3447
- this.responseParser = new SequencerAPIResponseParser();
3448
3501
  if ("network" in optionsOrProvider) {
3449
3502
  this.baseUrl = SequencerProvider.getNetworkFromName(optionsOrProvider.network);
3450
3503
  this.feederGatewayUrl = buildUrl(this.baseUrl, "feeder_gateway");
@@ -3633,7 +3686,7 @@ var SequencerProvider = class {
3633
3686
  } else if (classHash) {
3634
3687
  contractClass = await this.getClassByHash(classHash, blockIdentifier);
3635
3688
  } else {
3636
- throw Error("getContractVersion require contractAddress or classHash");
3689
+ throw Error("getContractVersion requires contractAddress or classHash");
3637
3690
  }
3638
3691
  if (isSierra(contractClass)) {
3639
3692
  if (compiler) {
@@ -3922,6 +3975,7 @@ ${res.tx_failure_reason.error_message}`;
3922
3975
 
3923
3976
  // src/provider/default.ts
3924
3977
  var Provider = class {
3978
+ provider;
3925
3979
  constructor(providerOrOptions) {
3926
3980
  if (providerOrOptions instanceof Provider) {
3927
3981
  this.provider = providerOrOptions.provider;
@@ -4089,6 +4143,8 @@ var getExecuteCalldata = (calls, cairoVersion = "0") => {
4089
4143
  // src/utils/typedData.ts
4090
4144
  var typedData_exports = {};
4091
4145
  __export(typedData_exports, {
4146
+ TypedDataRevision: () => TypedDataRevision,
4147
+ byteArrayFromString: () => byteArrayFromString,
4092
4148
  encodeData: () => encodeData,
4093
4149
  encodeType: () => encodeType,
4094
4150
  encodeValue: () => encodeValue,
@@ -4107,8 +4163,12 @@ __export(merkle_exports, {
4107
4163
  proofMerklePath: () => proofMerklePath
4108
4164
  });
4109
4165
  var MerkleTree = class {
4110
- constructor(leafHashes) {
4111
- this.branches = [];
4166
+ leaves;
4167
+ branches = [];
4168
+ root;
4169
+ hashMethod;
4170
+ constructor(leafHashes, hashMethod = computePedersenHash) {
4171
+ this.hashMethod = hashMethod;
4112
4172
  this.leaves = leafHashes;
4113
4173
  this.root = this.build(leafHashes);
4114
4174
  }
@@ -4127,20 +4187,20 @@ var MerkleTree = class {
4127
4187
  const newLeaves = [];
4128
4188
  for (let i = 0; i < leaves.length; i += 2) {
4129
4189
  if (i + 1 === leaves.length) {
4130
- newLeaves.push(MerkleTree.hash(leaves[i], "0x0"));
4190
+ newLeaves.push(MerkleTree.hash(leaves[i], "0x0", this.hashMethod));
4131
4191
  } else {
4132
- newLeaves.push(MerkleTree.hash(leaves[i], leaves[i + 1]));
4192
+ newLeaves.push(MerkleTree.hash(leaves[i], leaves[i + 1], this.hashMethod));
4133
4193
  }
4134
4194
  }
4135
4195
  return this.build(newLeaves);
4136
4196
  }
4137
4197
  /**
4138
- * Create pedersen hash from a and b
4198
+ * Create hash from ordered a and b, Pedersen hash default
4139
4199
  * @returns format: hex-string
4140
4200
  */
4141
- static hash(a, b) {
4142
- const [aSorted, bSorted] = [toBigInt(a), toBigInt(b)].sort((x, y) => x >= y ? 1 : -1);
4143
- return starkCurve.pedersen(aSorted, bSorted);
4201
+ static hash(a, b, hashMethod = computePedersenHash) {
4202
+ const [aSorted, bSorted] = [BigInt(a), BigInt(b)].sort((x, y) => x >= y ? 1 : -1);
4203
+ return hashMethod(aSorted, bSorted);
4144
4204
  }
4145
4205
  /**
4146
4206
  * Return path to leaf
@@ -4163,21 +4223,64 @@ var MerkleTree = class {
4163
4223
  const currentBranchLevelIndex = this.leaves.length === branch.length ? -1 : this.branches.findIndex((b) => b.length === branch.length);
4164
4224
  const nextBranch = this.branches[currentBranchLevelIndex + 1] ?? [this.root];
4165
4225
  return this.getProof(
4166
- MerkleTree.hash(isLeft ? leaf : neededBranch, isLeft ? neededBranch : leaf),
4226
+ MerkleTree.hash(isLeft ? leaf : neededBranch, isLeft ? neededBranch : leaf, this.hashMethod),
4167
4227
  nextBranch,
4168
4228
  newHashPath
4169
4229
  );
4170
4230
  }
4171
4231
  };
4172
- function proofMerklePath(root, leaf, path) {
4232
+ function proofMerklePath(root, leaf, path, hashMethod = computePedersenHash) {
4173
4233
  if (path.length === 0) {
4174
4234
  return root === leaf;
4175
4235
  }
4176
4236
  const [next, ...rest] = path;
4177
- return proofMerklePath(root, MerkleTree.hash(leaf, next), rest);
4237
+ return proofMerklePath(root, MerkleTree.hash(leaf, next, hashMethod), rest, hashMethod);
4178
4238
  }
4179
4239
 
4180
4240
  // src/utils/typedData.ts
4241
+ var presetTypes = {
4242
+ u256: JSON.parse('[{ "name": "low", "type": "u128" }, { "name": "high", "type": "u128" }]'),
4243
+ TokenAmount: JSON.parse(
4244
+ '[{ "name": "token_address", "type": "ContractAddress" }, { "name": "amount", "type": "u256" }]'
4245
+ ),
4246
+ NftId: JSON.parse(
4247
+ '[{ "name": "collection_address", "type": "ContractAddress" }, { "name": "token_id", "type": "u256" }]'
4248
+ )
4249
+ };
4250
+ var revisionConfiguration = {
4251
+ ["1" /* Active */]: {
4252
+ domain: "StarknetDomain",
4253
+ hashMethod: computePoseidonHashOnElements,
4254
+ hashMerkleMethod: computePoseidonHash,
4255
+ escapeTypeString: (s) => `"${s}"`,
4256
+ presetTypes
4257
+ },
4258
+ ["0" /* Legacy */]: {
4259
+ domain: "StarkNetDomain",
4260
+ hashMethod: computePedersenHashOnElements,
4261
+ hashMerkleMethod: computePedersenHash,
4262
+ escapeTypeString: (s) => s,
4263
+ presetTypes: {}
4264
+ }
4265
+ };
4266
+ function byteArrayFromString(targetString) {
4267
+ const shortStrings = splitLongString(targetString);
4268
+ const remainder = shortStrings[shortStrings.length - 1];
4269
+ const shortStringsEncoded = shortStrings.map(encodeShortString);
4270
+ const [pendingWord, pendingWordLength] = remainder === void 0 || remainder.length === 31 ? ["0x00", 0] : [shortStringsEncoded.pop(), remainder.length];
4271
+ return {
4272
+ data: shortStringsEncoded.length === 0 ? ["0x00"] : shortStringsEncoded,
4273
+ pending_word: pendingWord,
4274
+ pending_word_len: pendingWordLength
4275
+ };
4276
+ }
4277
+ function identifyRevision({ types, domain }) {
4278
+ if (revisionConfiguration["1" /* Active */].domain in types && domain.revision === "1" /* Active */)
4279
+ return "1" /* Active */;
4280
+ if (revisionConfiguration["0" /* Legacy */].domain in types && (domain.revision ?? "0" /* Legacy */) === "0" /* Legacy */)
4281
+ return "0" /* Legacy */;
4282
+ return void 0;
4283
+ }
4181
4284
  function getHex(value) {
4182
4285
  try {
4183
4286
  return toHex(value);
@@ -4188,25 +4291,29 @@ function getHex(value) {
4188
4291
  throw new Error(`Invalid BigNumberish: ${value}`);
4189
4292
  }
4190
4293
  }
4191
- var validateTypedData = (data) => {
4294
+ function validateTypedData(data) {
4192
4295
  const typedData = data;
4193
- const valid = Boolean(typedData.types && typedData.primaryType && typedData.message);
4194
- return valid;
4195
- };
4296
+ return Boolean(
4297
+ typedData.message && typedData.primaryType && typedData.types && identifyRevision(typedData)
4298
+ );
4299
+ }
4196
4300
  function prepareSelector(selector) {
4197
4301
  return isHex(selector) ? selector : getSelectorFromName(selector);
4198
4302
  }
4199
4303
  function isMerkleTreeType(type) {
4200
4304
  return type.type === "merkletree";
4201
4305
  }
4202
- var getDependencies = (types, type, dependencies = []) => {
4306
+ function getDependencies(types, type, dependencies = [], contains = "", revision = "0" /* Legacy */) {
4203
4307
  if (type[type.length - 1] === "*") {
4204
4308
  type = type.slice(0, -1);
4309
+ } else if (revision === "1" /* Active */) {
4310
+ if (type === "enum") {
4311
+ type = contains;
4312
+ } else if (type.match(/^\(.*\)$/)) {
4313
+ type = type.slice(1, -1);
4314
+ }
4205
4315
  }
4206
- if (dependencies.includes(type)) {
4207
- return dependencies;
4208
- }
4209
- if (!types[type]) {
4316
+ if (dependencies.includes(type) || !types[type]) {
4210
4317
  return dependencies;
4211
4318
  }
4212
4319
  return [
@@ -4214,14 +4321,14 @@ var getDependencies = (types, type, dependencies = []) => {
4214
4321
  ...types[type].reduce(
4215
4322
  (previous, t) => [
4216
4323
  ...previous,
4217
- ...getDependencies(types, t.type, previous).filter(
4324
+ ...getDependencies(types, t.type, previous, t.contains, revision).filter(
4218
4325
  (dependency) => !previous.includes(dependency)
4219
4326
  )
4220
4327
  ],
4221
4328
  []
4222
4329
  )
4223
4330
  ];
4224
- };
4331
+ }
4225
4332
  function getMerkleTreeType(types, ctx) {
4226
4333
  if (ctx.parent && ctx.key) {
4227
4334
  const parentType = types[ctx.parent];
@@ -4237,80 +4344,148 @@ function getMerkleTreeType(types, ctx) {
4237
4344
  }
4238
4345
  return "raw";
4239
4346
  }
4240
- var encodeType = (types, type) => {
4241
- const [primary, ...dependencies] = getDependencies(types, type);
4347
+ function encodeType(types, type, revision = "0" /* Legacy */) {
4348
+ const [primary, ...dependencies] = getDependencies(types, type, void 0, void 0, revision);
4242
4349
  const newTypes = !primary ? [] : [primary, ...dependencies.sort()];
4350
+ const esc = revisionConfiguration[revision].escapeTypeString;
4243
4351
  return newTypes.map((dependency) => {
4244
- return `${dependency}(${types[dependency].map((t) => `${t.name}:${t.type}`)})`;
4352
+ const dependencyElements = types[dependency].map((t) => {
4353
+ const targetType = t.type === "enum" && revision === "1" /* Active */ ? t.contains : t.type;
4354
+ const typeString = targetType.match(/^\(.*\)$/) ? `(${targetType.slice(1, -1).split(",").map((e) => e ? esc(e) : e).join(",")})` : esc(targetType);
4355
+ return `${esc(t.name)}:${typeString}`;
4356
+ });
4357
+ return `${esc(dependency)}(${dependencyElements})`;
4245
4358
  }).join("");
4246
- };
4247
- var getTypeHash = (types, type) => {
4248
- return getSelectorFromName(encodeType(types, type));
4249
- };
4250
- var encodeValue = (types, type, data, ctx = {}) => {
4359
+ }
4360
+ function getTypeHash(types, type, revision = "0" /* Legacy */) {
4361
+ return getSelectorFromName(encodeType(types, type, revision));
4362
+ }
4363
+ function encodeValue(types, type, data, ctx = {}, revision = "0" /* Legacy */) {
4251
4364
  if (types[type]) {
4252
- return [type, getStructHash(types, type, data)];
4365
+ return [type, getStructHash(types, type, data, revision)];
4253
4366
  }
4254
- if (Object.keys(types).map((x) => `${x}*`).includes(type)) {
4255
- const structHashes = data.map((struct) => {
4256
- return getStructHash(types, type.slice(0, -1), struct);
4257
- });
4258
- return [type, computeHashOnElements(structHashes)];
4259
- }
4260
- if (type === "merkletree") {
4261
- const merkleTreeType = getMerkleTreeType(types, ctx);
4262
- const structHashes = data.map((struct) => {
4263
- return encodeValue(types, merkleTreeType, struct)[1];
4264
- });
4265
- const { root } = new MerkleTree(structHashes);
4266
- return ["felt", root];
4267
- }
4268
- if (type === "felt*") {
4269
- return ["felt*", computeHashOnElements(data)];
4367
+ if (revisionConfiguration[revision].presetTypes[type]) {
4368
+ return [
4369
+ type,
4370
+ getStructHash(
4371
+ revisionConfiguration[revision].presetTypes,
4372
+ type,
4373
+ data,
4374
+ revision
4375
+ )
4376
+ ];
4270
4377
  }
4271
- if (type === "selector") {
4272
- return ["felt", prepareSelector(data)];
4378
+ if (type.endsWith("*")) {
4379
+ const hashes = data.map(
4380
+ (entry) => encodeValue(types, type.slice(0, -1), entry, void 0, revision)[1]
4381
+ );
4382
+ return [type, revisionConfiguration[revision].hashMethod(hashes)];
4383
+ }
4384
+ switch (type) {
4385
+ case "enum": {
4386
+ if (revision === "1" /* Active */) {
4387
+ const [variantKey, variantData] = Object.entries(data)[0];
4388
+ const parentType = types[ctx.parent][0];
4389
+ const enumType = types[parentType.contains];
4390
+ const variantType = enumType.find((t) => t.name === variantKey);
4391
+ const variantIndex = enumType.indexOf(variantType);
4392
+ const encodedSubtypes = variantType.type.slice(1, -1).split(",").map((subtype, index) => {
4393
+ if (!subtype)
4394
+ return subtype;
4395
+ const subtypeData = variantData[index];
4396
+ return encodeValue(types, subtype, subtypeData, void 0, revision)[1];
4397
+ });
4398
+ return [
4399
+ type,
4400
+ revisionConfiguration[revision].hashMethod([variantIndex, ...encodedSubtypes])
4401
+ ];
4402
+ }
4403
+ return [type, getHex(data)];
4404
+ }
4405
+ case "merkletree": {
4406
+ const merkleTreeType = getMerkleTreeType(types, ctx);
4407
+ const structHashes = data.map((struct) => {
4408
+ return encodeValue(types, merkleTreeType, struct, void 0, revision)[1];
4409
+ });
4410
+ const { root } = new MerkleTree(
4411
+ structHashes,
4412
+ revisionConfiguration[revision].hashMerkleMethod
4413
+ );
4414
+ return ["felt", root];
4415
+ }
4416
+ case "selector": {
4417
+ return ["felt", prepareSelector(data)];
4418
+ }
4419
+ case "string": {
4420
+ if (revision === "1" /* Active */) {
4421
+ const byteArray = byteArrayFromString(data);
4422
+ const elements = [
4423
+ byteArray.data.length,
4424
+ ...byteArray.data,
4425
+ byteArray.pending_word,
4426
+ byteArray.pending_word_len
4427
+ ];
4428
+ return [type, revisionConfiguration[revision].hashMethod(elements)];
4429
+ }
4430
+ return [type, getHex(data)];
4431
+ }
4432
+ case "felt":
4433
+ case "bool":
4434
+ case "u128":
4435
+ case "i128":
4436
+ case "ContractAddress":
4437
+ case "ClassHash":
4438
+ case "timestamp":
4439
+ case "shortstring":
4440
+ return [type, getHex(data)];
4441
+ default: {
4442
+ if (revision === "1" /* Active */) {
4443
+ throw new Error(`Unsupported type: ${type}`);
4444
+ }
4445
+ return [type, getHex(data)];
4446
+ }
4273
4447
  }
4274
- return [type, getHex(data)];
4275
- };
4276
- var encodeData = (types, type, data) => {
4277
- const [returnTypes, values] = types[type].reduce(
4448
+ }
4449
+ function encodeData(types, type, data, revision = "0" /* Legacy */) {
4450
+ const targetType = types[type] ?? revisionConfiguration[revision].presetTypes[type];
4451
+ const [returnTypes, values] = targetType.reduce(
4278
4452
  ([ts, vs], field) => {
4279
- if (data[field.name] === void 0 || data[field.name] === null) {
4453
+ if (data[field.name] === void 0 || data[field.name] === null && field.type !== "enum") {
4280
4454
  throw new Error(`Cannot encode data: missing data for '${field.name}'`);
4281
4455
  }
4282
4456
  const value = data[field.name];
4283
- const [t, encodedValue] = encodeValue(types, field.type, value, {
4284
- parent: type,
4285
- key: field.name
4286
- });
4457
+ const ctx = { parent: type, key: field.name };
4458
+ const [t, encodedValue] = encodeValue(types, field.type, value, ctx, revision);
4287
4459
  return [
4288
4460
  [...ts, t],
4289
4461
  [...vs, encodedValue]
4290
4462
  ];
4291
4463
  },
4292
- [["felt"], [getTypeHash(types, type)]]
4464
+ [["felt"], [getTypeHash(types, type, revision)]]
4293
4465
  );
4294
4466
  return [returnTypes, values];
4295
- };
4296
- var getStructHash = (types, type, data) => {
4297
- return computeHashOnElements(encodeData(types, type, data)[1]);
4298
- };
4299
- var getMessageHash = (typedData, account) => {
4467
+ }
4468
+ function getStructHash(types, type, data, revision = "0" /* Legacy */) {
4469
+ return revisionConfiguration[revision].hashMethod(encodeData(types, type, data, revision)[1]);
4470
+ }
4471
+ function getMessageHash(typedData, account) {
4300
4472
  if (!validateTypedData(typedData)) {
4301
4473
  throw new Error("Typed data does not match JSON schema");
4302
4474
  }
4475
+ const revision = identifyRevision(typedData);
4476
+ const { domain, hashMethod } = revisionConfiguration[revision];
4303
4477
  const message = [
4304
4478
  encodeShortString("StarkNet Message"),
4305
- getStructHash(typedData.types, "StarkNetDomain", typedData.domain),
4479
+ getStructHash(typedData.types, domain, typedData.domain, revision),
4306
4480
  account,
4307
- getStructHash(typedData.types, typedData.primaryType, typedData.message)
4481
+ getStructHash(typedData.types, typedData.primaryType, typedData.message, revision)
4308
4482
  ];
4309
- return computeHashOnElements(message);
4310
- };
4483
+ return hashMethod(message);
4484
+ }
4311
4485
 
4312
4486
  // src/signer/default.ts
4313
4487
  var Signer = class {
4488
+ pk;
4314
4489
  constructor(pk = starkCurve.utils.randomPrivateKey()) {
4315
4490
  this.pk = pk instanceof Uint8Array ? buf2hex(pk) : toHex(pk);
4316
4491
  }
@@ -4405,9 +4580,11 @@ function parseUDCEvent(txReceipt) {
4405
4580
 
4406
4581
  // src/account/default.ts
4407
4582
  var Account = class extends Provider {
4583
+ signer;
4584
+ address;
4585
+ cairoVersion;
4408
4586
  constructor(providerOrOptions, address, pkOrSigner, cairoVersion) {
4409
4587
  super(providerOrOptions);
4410
- this.deploySelf = this.deployAccount;
4411
4588
  this.address = address.toLowerCase();
4412
4589
  this.signer = typeof pkOrSigner === "string" || pkOrSigner instanceof Uint8Array ? new Signer(pkOrSigner) : pkOrSigner;
4413
4590
  if (cairoVersion) {
@@ -4680,6 +4857,7 @@ var Account = class extends Provider {
4680
4857
  );
4681
4858
  return { declare: { ...declare }, deploy };
4682
4859
  }
4860
+ deploySelf = this.deployAccount;
4683
4861
  async deployAccount({
4684
4862
  classHash,
4685
4863
  constructorCalldata = [],
@@ -5043,6 +5221,17 @@ function getCalldata(args, callback) {
5043
5221
  return callback();
5044
5222
  }
5045
5223
  var Contract = class {
5224
+ abi;
5225
+ address;
5226
+ providerOrAccount;
5227
+ deployTransactionHash;
5228
+ structs;
5229
+ events;
5230
+ functions;
5231
+ callStatic;
5232
+ populateTransaction;
5233
+ estimateFee;
5234
+ callData;
5046
5235
  /**
5047
5236
  * Contract class to handle contract methods
5048
5237
  *
@@ -5216,7 +5405,7 @@ var Contract = class {
5216
5405
  async getVersion() {
5217
5406
  return this.providerOrAccount.getContractVersion(this.address);
5218
5407
  }
5219
- typed(tAbi) {
5408
+ typedv1(tAbi) {
5220
5409
  return this;
5221
5410
  }
5222
5411
  typedv2(tAbi) {
@@ -5226,10 +5415,21 @@ var Contract = class {
5226
5415
 
5227
5416
  // src/contract/interface.ts
5228
5417
  var ContractInterface = class {
5418
+ functions;
5419
+ callStatic;
5420
+ populateTransaction;
5421
+ estimateFee;
5229
5422
  };
5230
5423
 
5231
5424
  // src/contract/contractFactory.ts
5232
5425
  var ContractFactory = class {
5426
+ compiledContract;
5427
+ account;
5428
+ abi;
5429
+ classHash;
5430
+ casm;
5431
+ compiledClassHash;
5432
+ CallData;
5233
5433
  /**
5234
5434
  * @param params CFParams
5235
5435
  * - compiledContract: CompiledContract;
@@ -5297,7 +5497,7 @@ var ContractFactory = class {
5297
5497
  attach(address) {
5298
5498
  return new Contract(this.abi, address, this.account);
5299
5499
  }
5300
- // ethers.js' getDeployTransaction cant be supported as it requires the account or signer to return a signed transaction which is not possible with the current implementation
5500
+ // ethers.js' getDeployTransaction can't be supported as it requires the account or signer to return a signed transaction which is not possible with the current implementation
5301
5501
  };
5302
5502
 
5303
5503
  // src/utils/address.ts
@@ -5353,7 +5553,7 @@ var number = num_exports;
5353
5553
  GatewayError,
5354
5554
  HttpError,
5355
5555
  LibraryError,
5356
- Litteral,
5556
+ Literal,
5357
5557
  Provider,
5358
5558
  ProviderInterface,
5359
5559
  RPC,
@@ -5367,6 +5567,7 @@ var number = num_exports;
5367
5567
  TransactionFinalityStatus,
5368
5568
  TransactionStatus,
5369
5569
  TransactionType,
5570
+ TypedDataRevision,
5370
5571
  Uint,
5371
5572
  ValidateType,
5372
5573
  addAddressPadding,