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.mjs CHANGED
@@ -169,7 +169,7 @@ __export(types_exports, {
169
169
  BlockStatus: () => BlockStatus,
170
170
  BlockTag: () => BlockTag,
171
171
  EntryPointType: () => EntryPointType,
172
- Litteral: () => Litteral,
172
+ Literal: () => Literal,
173
173
  RPC: () => rpc_exports,
174
174
  SIMULATION_FLAG: () => SIMULATION_FLAG,
175
175
  Sequencer: () => sequencer_exports,
@@ -177,6 +177,7 @@ __export(types_exports, {
177
177
  TransactionFinalityStatus: () => TransactionFinalityStatus,
178
178
  TransactionStatus: () => TransactionStatus,
179
179
  TransactionType: () => TransactionType,
180
+ TypedDataRevision: () => TypedDataRevision,
180
181
  Uint: () => Uint,
181
182
  ValidateType: () => ValidateType
182
183
  });
@@ -204,11 +205,11 @@ var Uint = /* @__PURE__ */ ((Uint2) => {
204
205
  Uint2["u256"] = "core::integer::u256";
205
206
  return Uint2;
206
207
  })(Uint || {});
207
- var Litteral = /* @__PURE__ */ ((Litteral2) => {
208
- Litteral2["ClassHash"] = "core::starknet::class_hash::ClassHash";
209
- Litteral2["ContractAddress"] = "core::starknet::contract_address::ContractAddress";
210
- return Litteral2;
211
- })(Litteral || {});
208
+ var Literal = /* @__PURE__ */ ((Literal2) => {
209
+ Literal2["ClassHash"] = "core::starknet::class_hash::ClassHash";
210
+ Literal2["ContractAddress"] = "core::starknet::contract_address::ContractAddress";
211
+ return Literal2;
212
+ })(Literal || {});
212
213
 
213
214
  // src/types/lib/contract/index.ts
214
215
  var EntryPointType = /* @__PURE__ */ ((EntryPointType2) => {
@@ -261,6 +262,13 @@ var BlockTag = /* @__PURE__ */ ((BlockTag2) => {
261
262
  return BlockTag2;
262
263
  })(BlockTag || {});
263
264
 
265
+ // src/types/typedData.ts
266
+ var TypedDataRevision = /* @__PURE__ */ ((TypedDataRevision2) => {
267
+ TypedDataRevision2["Active"] = "1";
268
+ TypedDataRevision2["Legacy"] = "0";
269
+ return TypedDataRevision2;
270
+ })(TypedDataRevision || {});
271
+
264
272
  // src/types/api/rpc.ts
265
273
  var rpc_exports = {};
266
274
  __export(rpc_exports, {
@@ -528,7 +536,7 @@ __export(cairo_exports, {
528
536
  isTypeEnum: () => isTypeEnum,
529
537
  isTypeEthAddress: () => isTypeEthAddress,
530
538
  isTypeFelt: () => isTypeFelt,
531
- isTypeLitteral: () => isTypeLitteral,
539
+ isTypeLiteral: () => isTypeLiteral,
532
540
  isTypeNamedTuple: () => isTypeNamedTuple,
533
541
  isTypeOption: () => isTypeOption,
534
542
  isTypeResult: () => isTypeResult,
@@ -578,7 +586,7 @@ var isTypeEnum = (type, enums) => type in enums;
578
586
  var isTypeOption = (type) => type.startsWith("core::option::Option::");
579
587
  var isTypeResult = (type) => type.startsWith("core::result::Result::");
580
588
  var isTypeUint = (type) => Object.values(Uint).includes(type);
581
- var isTypeLitteral = (type) => Object.values(Litteral).includes(type);
589
+ var isTypeLiteral = (type) => Object.values(Literal).includes(type);
582
590
  var isTypeUint256 = (type) => type === "core::integer::u256";
583
591
  var isTypeBool = (type) => type === "core::bool";
584
592
  var isTypeContractAddress = (type) => type === "core::starknet::contract_address::ContractAddress";
@@ -651,13 +659,21 @@ function felt(it) {
651
659
 
652
660
  // src/utils/calldata/enum/CairoCustomEnum.ts
653
661
  var CairoCustomEnum = class {
662
+ /**
663
+ * direct readonly access to variants of the Cairo Custom Enum.
664
+ * @returns a value of type any
665
+ * @example
666
+ * ```typescript
667
+ * const successValue = myCairoEnum.variant.Success;
668
+ */
669
+ variant;
654
670
  /**
655
671
  * @param enumContent an object with the variants as keys and the content as value. Only one content shall be defined.
656
672
  */
657
673
  constructor(enumContent) {
658
674
  const variantsList = Object.values(enumContent);
659
675
  if (variantsList.length === 0) {
660
- throw new Error("This Enum must have a least 1 variant");
676
+ throw new Error("This Enum must have at least 1 variant");
661
677
  }
662
678
  const nbActiveVariants = variantsList.filter(
663
679
  (content) => typeof content !== "undefined"
@@ -700,6 +716,8 @@ var CairoOptionVariant = /* @__PURE__ */ ((CairoOptionVariant2) => {
700
716
  return CairoOptionVariant2;
701
717
  })(CairoOptionVariant || {});
702
718
  var CairoOption = class {
719
+ Some;
720
+ None;
703
721
  constructor(variant, someContent) {
704
722
  if (!(variant in CairoOptionVariant)) {
705
723
  throw new Error("Wrong variant : should be CairoOptionVariant.Some or .None.");
@@ -751,6 +769,8 @@ var CairoResultVariant = /* @__PURE__ */ ((CairoResultVariant2) => {
751
769
  return CairoResultVariant2;
752
770
  })(CairoResultVariant || {});
753
771
  var CairoResult = class {
772
+ Ok;
773
+ Err;
754
774
  constructor(variant, resultContent) {
755
775
  if (!(variant in CairoResultVariant)) {
756
776
  throw new Error("Wrong variant : should be CairoResultVariant.Ok or .Err.");
@@ -849,6 +869,7 @@ function formatter(data, type, sameType) {
849
869
 
850
870
  // src/utils/calldata/parser/parser-0-1.1.0.ts
851
871
  var AbiParser1 = class {
872
+ abi;
852
873
  constructor(abi) {
853
874
  this.abi = abi;
854
875
  }
@@ -880,6 +901,7 @@ var AbiParser1 = class {
880
901
 
881
902
  // src/utils/calldata/parser/parser-2.0.0.ts
882
903
  var AbiParser2 = class {
904
+ abi;
883
905
  constructor(abi) {
884
906
  this.abi = abi;
885
907
  }
@@ -1625,7 +1647,7 @@ var validateArray = (parameter, input, structs, enums) => {
1625
1647
  case isTypeEnum(baseType, enums):
1626
1648
  parameter.forEach((it) => validateEnum(it, { name: input.name, type: baseType }));
1627
1649
  break;
1628
- case (isTypeUint(baseType) || isTypeLitteral(baseType)):
1650
+ case (isTypeUint(baseType) || isTypeLiteral(baseType)):
1629
1651
  parameter.forEach((param) => validateUint(param, input));
1630
1652
  break;
1631
1653
  case isTypeBool(baseType):
@@ -1646,7 +1668,7 @@ function validateFields(abiMethod, args, structs, enums) {
1646
1668
  case isTypeFelt(input.type):
1647
1669
  validateFelt(parameter, input);
1648
1670
  break;
1649
- case (isTypeUint(input.type) || isTypeLitteral(input.type)):
1671
+ case (isTypeUint(input.type) || isTypeLiteral(input.type)):
1650
1672
  validateUint(parameter, input);
1651
1673
  break;
1652
1674
  case isTypeBool(input.type):
@@ -1675,6 +1697,10 @@ function validateFields(abiMethod, args, structs, enums) {
1675
1697
 
1676
1698
  // src/utils/calldata/index.ts
1677
1699
  var CallData = class {
1700
+ abi;
1701
+ parser;
1702
+ structs;
1703
+ enums;
1678
1704
  constructor(abi) {
1679
1705
  this.structs = CallData.getAbiStruct(abi);
1680
1706
  this.enums = CallData.getAbiEnum(abi);
@@ -1919,6 +1945,10 @@ __export(hash_exports, {
1919
1945
  computeContractClassHash: () => computeContractClassHash,
1920
1946
  computeHashOnElements: () => computeHashOnElements,
1921
1947
  computeLegacyContractClassHash: () => computeLegacyContractClassHash,
1948
+ computePedersenHash: () => computePedersenHash,
1949
+ computePedersenHashOnElements: () => computePedersenHashOnElements,
1950
+ computePoseidonHash: () => computePoseidonHash,
1951
+ computePoseidonHashOnElements: () => computePoseidonHashOnElements,
1922
1952
  computeSierraContractClassHash: () => computeSierraContractClassHash,
1923
1953
  default: () => computeHintedClassHash,
1924
1954
  feeTransactionVersion: () => feeTransactionVersion,
@@ -1973,8 +2003,18 @@ var feeTransactionVersion_2 = BN_FEE_TRANSACTION_VERSION_2;
1973
2003
  function getVersionsByType(versionType) {
1974
2004
  return versionType === "fee" ? { v1: feeTransactionVersion, v2: feeTransactionVersion_2 } : { v1: transactionVersion, v2: transactionVersion_2 };
1975
2005
  }
2006
+ function computePedersenHash(a, b) {
2007
+ return starkCurve.pedersen(BigInt(a), BigInt(b));
2008
+ }
2009
+ function computePoseidonHash(a, b) {
2010
+ return toHex(starkCurve.poseidonHash(BigInt(a), BigInt(b)));
2011
+ }
1976
2012
  function computeHashOnElements(data) {
1977
- return [...data, data.length].reduce((x, y) => starkCurve.pedersen(toBigInt(x), toBigInt(y)), 0).toString();
2013
+ return [...data, data.length].reduce((x, y) => starkCurve.pedersen(BigInt(x), BigInt(y)), 0).toString();
2014
+ }
2015
+ var computePedersenHashOnElements = computeHashOnElements;
2016
+ function computePoseidonHashOnElements(data) {
2017
+ return toHex(poseidonHashMany(data.map((x) => BigInt(x))));
1978
2018
  }
1979
2019
  function calculateTransactionHashCommon(txHashPrefix, version, contractAddress, entryPointSelector, calldata, maxFee, chainId, additionalData = []) {
1980
2020
  const calldataHash = computeHashOnElements(calldata);
@@ -2367,6 +2407,7 @@ function fixProto(target, prototype) {
2367
2407
  setPrototypeOf ? setPrototypeOf(target, prototype) : target.__proto__ = prototype;
2368
2408
  }
2369
2409
  var CustomError = class extends Error {
2410
+ name;
2370
2411
  constructor(message) {
2371
2412
  super(message);
2372
2413
  Object.defineProperty(this, "name", {
@@ -2543,14 +2584,9 @@ async function getAddressFromStarkName(provider, name, StarknetIdContract2) {
2543
2584
  // src/provider/utils.ts
2544
2585
  var validBlockTags = Object.values(BlockTag);
2545
2586
  var Block = class {
2546
- constructor(_identifier) {
2547
- this.hash = null;
2548
- this.number = null;
2549
- this.tag = null;
2550
- this.valueOf = () => this.number;
2551
- this.toString = () => this.hash;
2552
- this.setIdentifier(_identifier);
2553
- }
2587
+ hash = null;
2588
+ number = null;
2589
+ tag = null;
2554
2590
  setIdentifier(__identifier) {
2555
2591
  if (typeof __identifier === "string" && isHex(__identifier)) {
2556
2592
  this.hash = __identifier;
@@ -2564,6 +2600,9 @@ var Block = class {
2564
2600
  this.tag = "pending" /* pending */;
2565
2601
  }
2566
2602
  }
2603
+ constructor(_identifier) {
2604
+ this.setIdentifier(_identifier);
2605
+ }
2567
2606
  // TODO: fix any
2568
2607
  get queryIdentifier() {
2569
2608
  if (this.number !== null) {
@@ -2587,6 +2626,8 @@ var Block = class {
2587
2626
  set identifier(_identifier) {
2588
2627
  this.setIdentifier(_identifier);
2589
2628
  }
2629
+ valueOf = () => this.number;
2630
+ toString = () => this.hash;
2590
2631
  get sequencerIdentifier() {
2591
2632
  return this.hash !== null ? { blockHash: this.hash } : { blockNumber: this.number ?? this.tag };
2592
2633
  }
@@ -2606,36 +2647,13 @@ var defaultOptions = {
2606
2647
  retries: 200
2607
2648
  };
2608
2649
  var RpcProvider = class {
2650
+ nodeUrl;
2651
+ headers;
2652
+ responseParser = new RPCResponseParser();
2653
+ retries;
2654
+ blockIdentifier;
2655
+ chainId;
2609
2656
  constructor(optionsOrProvider) {
2610
- this.responseParser = new RPCResponseParser();
2611
- /**
2612
- * @deprecated renamed to getBlockLatestAccepted(); (will be removed in next minor version)
2613
- */
2614
- this.getBlockHashAndNumber = this.getBlockLatestAccepted;
2615
- /**
2616
- * @deprecated renamed to getBlockStateUpdate();
2617
- */
2618
- this.getStateUpdate = this.getBlockStateUpdate;
2619
- /**
2620
- * Returns the execution traces of all transactions included in the given block
2621
- * @deprecated renamed to getBlockTransactionsTraces()
2622
- */
2623
- this.traceBlockTransactions = this.getBlockTransactionsTraces;
2624
- /**
2625
- * Get the number of transactions in a block given a block id
2626
- * @deprecated renamed to getBlockTransactionCount()
2627
- * @returns Number of transactions
2628
- */
2629
- this.getTransactionCount = this.getBlockTransactionCount;
2630
- /**
2631
- * @deprecated renamed to getTransactionTrace();
2632
- * For a given executed transaction, return the trace of its execution, including internal calls
2633
- */
2634
- this.traceTransaction = this.getTransactionTrace;
2635
- /**
2636
- * @deprecated renamed to simulateTransaction();
2637
- */
2638
- this.getSimulateTransaction = this.simulateTransaction;
2639
2657
  const { nodeUrl, retries, headers, blockIdentifier, chainId, rpcVersion } = optionsOrProvider || {};
2640
2658
  if (Object.values(NetworkName).includes(nodeUrl)) {
2641
2659
  this.nodeUrl = getDefaultNodeUrl(
@@ -2693,7 +2711,7 @@ var RpcProvider = class {
2693
2711
  }
2694
2712
  }
2695
2713
  async getChainId() {
2696
- this.chainId ?? (this.chainId = await this.fetchEndpoint("starknet_chainId"));
2714
+ this.chainId ??= await this.fetchEndpoint("starknet_chainId");
2697
2715
  return this.chainId;
2698
2716
  }
2699
2717
  /**
@@ -2718,6 +2736,10 @@ var RpcProvider = class {
2718
2736
  this.responseParser.parseGetBlockResponse
2719
2737
  );
2720
2738
  }
2739
+ /**
2740
+ * @deprecated renamed to getBlockLatestAccepted(); (will be removed in next minor version)
2741
+ */
2742
+ getBlockHashAndNumber = this.getBlockLatestAccepted;
2721
2743
  /**
2722
2744
  * Get the most recent accepted block hash and number
2723
2745
  */
@@ -2744,14 +2766,29 @@ var RpcProvider = class {
2744
2766
  const block_id = new Block(blockIdentifier).identifier;
2745
2767
  return this.fetchEndpoint("starknet_getStateUpdate", { block_id });
2746
2768
  }
2769
+ /**
2770
+ * @deprecated renamed to getBlockStateUpdate();
2771
+ */
2772
+ getStateUpdate = this.getBlockStateUpdate;
2747
2773
  async getBlockTransactionsTraces(blockIdentifier = this.blockIdentifier) {
2748
2774
  const block_id = new Block(blockIdentifier).identifier;
2749
2775
  return this.fetchEndpoint("starknet_traceBlockTransactions", { block_id });
2750
2776
  }
2777
+ /**
2778
+ * Returns the execution traces of all transactions included in the given block
2779
+ * @deprecated renamed to getBlockTransactionsTraces()
2780
+ */
2781
+ traceBlockTransactions = this.getBlockTransactionsTraces;
2751
2782
  async getBlockTransactionCount(blockIdentifier = this.blockIdentifier) {
2752
2783
  const block_id = new Block(blockIdentifier).identifier;
2753
2784
  return this.fetchEndpoint("starknet_getBlockTransactionCount", { block_id });
2754
2785
  }
2786
+ /**
2787
+ * Get the number of transactions in a block given a block id
2788
+ * @deprecated renamed to getBlockTransactionCount()
2789
+ * @returns Number of transactions
2790
+ */
2791
+ getTransactionCount = this.getBlockTransactionCount;
2755
2792
  /**
2756
2793
  * Return transactions from pending block
2757
2794
  * @deprecated Instead use getBlock(BlockTag.pending); (will be removed in next minor version)
@@ -2784,6 +2821,11 @@ var RpcProvider = class {
2784
2821
  const transaction_hash = toHex(txHash);
2785
2822
  return this.fetchEndpoint("starknet_traceTransaction", { transaction_hash });
2786
2823
  }
2824
+ /**
2825
+ * @deprecated renamed to getTransactionTrace();
2826
+ * For a given executed transaction, return the trace of its execution, including internal calls
2827
+ */
2828
+ traceTransaction = this.getTransactionTrace;
2787
2829
  /**
2788
2830
  * NEW: Get the status of a transaction
2789
2831
  */
@@ -2791,6 +2833,10 @@ var RpcProvider = class {
2791
2833
  const transaction_hash = toHex(transactionHash);
2792
2834
  return this.fetchEndpoint("starknet_getTransactionStatus", { transaction_hash });
2793
2835
  }
2836
+ /**
2837
+ * @deprecated renamed to simulateTransaction();
2838
+ */
2839
+ getSimulateTransaction = this.simulateTransaction;
2794
2840
  /**
2795
2841
  * @param invocations AccountInvocations
2796
2842
  * @param simulateTransactionOptions blockIdentifier and flags to skip validation and fee charge<br/>
@@ -3345,8 +3391,14 @@ var defaultOptions2 = {
3345
3391
  blockIdentifier: "pending" /* pending */
3346
3392
  };
3347
3393
  var SequencerProvider = class {
3394
+ baseUrl;
3395
+ feederGatewayUrl;
3396
+ gatewayUrl;
3397
+ headers;
3398
+ blockIdentifier;
3399
+ chainId;
3400
+ responseParser = new SequencerAPIResponseParser();
3348
3401
  constructor(optionsOrProvider = defaultOptions2) {
3349
- this.responseParser = new SequencerAPIResponseParser();
3350
3402
  if ("network" in optionsOrProvider) {
3351
3403
  this.baseUrl = SequencerProvider.getNetworkFromName(optionsOrProvider.network);
3352
3404
  this.feederGatewayUrl = buildUrl(this.baseUrl, "feeder_gateway");
@@ -3535,7 +3587,7 @@ var SequencerProvider = class {
3535
3587
  } else if (classHash) {
3536
3588
  contractClass = await this.getClassByHash(classHash, blockIdentifier);
3537
3589
  } else {
3538
- throw Error("getContractVersion require contractAddress or classHash");
3590
+ throw Error("getContractVersion requires contractAddress or classHash");
3539
3591
  }
3540
3592
  if (isSierra(contractClass)) {
3541
3593
  if (compiler) {
@@ -3824,6 +3876,7 @@ ${res.tx_failure_reason.error_message}`;
3824
3876
 
3825
3877
  // src/provider/default.ts
3826
3878
  var Provider = class {
3879
+ provider;
3827
3880
  constructor(providerOrOptions) {
3828
3881
  if (providerOrOptions instanceof Provider) {
3829
3882
  this.provider = providerOrOptions.provider;
@@ -3991,6 +4044,8 @@ var getExecuteCalldata = (calls, cairoVersion = "0") => {
3991
4044
  // src/utils/typedData.ts
3992
4045
  var typedData_exports = {};
3993
4046
  __export(typedData_exports, {
4047
+ TypedDataRevision: () => TypedDataRevision,
4048
+ byteArrayFromString: () => byteArrayFromString,
3994
4049
  encodeData: () => encodeData,
3995
4050
  encodeType: () => encodeType,
3996
4051
  encodeValue: () => encodeValue,
@@ -4009,8 +4064,12 @@ __export(merkle_exports, {
4009
4064
  proofMerklePath: () => proofMerklePath
4010
4065
  });
4011
4066
  var MerkleTree = class {
4012
- constructor(leafHashes) {
4013
- this.branches = [];
4067
+ leaves;
4068
+ branches = [];
4069
+ root;
4070
+ hashMethod;
4071
+ constructor(leafHashes, hashMethod = computePedersenHash) {
4072
+ this.hashMethod = hashMethod;
4014
4073
  this.leaves = leafHashes;
4015
4074
  this.root = this.build(leafHashes);
4016
4075
  }
@@ -4029,20 +4088,20 @@ var MerkleTree = class {
4029
4088
  const newLeaves = [];
4030
4089
  for (let i = 0; i < leaves.length; i += 2) {
4031
4090
  if (i + 1 === leaves.length) {
4032
- newLeaves.push(MerkleTree.hash(leaves[i], "0x0"));
4091
+ newLeaves.push(MerkleTree.hash(leaves[i], "0x0", this.hashMethod));
4033
4092
  } else {
4034
- newLeaves.push(MerkleTree.hash(leaves[i], leaves[i + 1]));
4093
+ newLeaves.push(MerkleTree.hash(leaves[i], leaves[i + 1], this.hashMethod));
4035
4094
  }
4036
4095
  }
4037
4096
  return this.build(newLeaves);
4038
4097
  }
4039
4098
  /**
4040
- * Create pedersen hash from a and b
4099
+ * Create hash from ordered a and b, Pedersen hash default
4041
4100
  * @returns format: hex-string
4042
4101
  */
4043
- static hash(a, b) {
4044
- const [aSorted, bSorted] = [toBigInt(a), toBigInt(b)].sort((x, y) => x >= y ? 1 : -1);
4045
- return starkCurve.pedersen(aSorted, bSorted);
4102
+ static hash(a, b, hashMethod = computePedersenHash) {
4103
+ const [aSorted, bSorted] = [BigInt(a), BigInt(b)].sort((x, y) => x >= y ? 1 : -1);
4104
+ return hashMethod(aSorted, bSorted);
4046
4105
  }
4047
4106
  /**
4048
4107
  * Return path to leaf
@@ -4065,21 +4124,64 @@ var MerkleTree = class {
4065
4124
  const currentBranchLevelIndex = this.leaves.length === branch.length ? -1 : this.branches.findIndex((b) => b.length === branch.length);
4066
4125
  const nextBranch = this.branches[currentBranchLevelIndex + 1] ?? [this.root];
4067
4126
  return this.getProof(
4068
- MerkleTree.hash(isLeft ? leaf : neededBranch, isLeft ? neededBranch : leaf),
4127
+ MerkleTree.hash(isLeft ? leaf : neededBranch, isLeft ? neededBranch : leaf, this.hashMethod),
4069
4128
  nextBranch,
4070
4129
  newHashPath
4071
4130
  );
4072
4131
  }
4073
4132
  };
4074
- function proofMerklePath(root, leaf, path) {
4133
+ function proofMerklePath(root, leaf, path, hashMethod = computePedersenHash) {
4075
4134
  if (path.length === 0) {
4076
4135
  return root === leaf;
4077
4136
  }
4078
4137
  const [next, ...rest] = path;
4079
- return proofMerklePath(root, MerkleTree.hash(leaf, next), rest);
4138
+ return proofMerklePath(root, MerkleTree.hash(leaf, next, hashMethod), rest, hashMethod);
4080
4139
  }
4081
4140
 
4082
4141
  // src/utils/typedData.ts
4142
+ var presetTypes = {
4143
+ u256: JSON.parse('[{ "name": "low", "type": "u128" }, { "name": "high", "type": "u128" }]'),
4144
+ TokenAmount: JSON.parse(
4145
+ '[{ "name": "token_address", "type": "ContractAddress" }, { "name": "amount", "type": "u256" }]'
4146
+ ),
4147
+ NftId: JSON.parse(
4148
+ '[{ "name": "collection_address", "type": "ContractAddress" }, { "name": "token_id", "type": "u256" }]'
4149
+ )
4150
+ };
4151
+ var revisionConfiguration = {
4152
+ ["1" /* Active */]: {
4153
+ domain: "StarknetDomain",
4154
+ hashMethod: computePoseidonHashOnElements,
4155
+ hashMerkleMethod: computePoseidonHash,
4156
+ escapeTypeString: (s) => `"${s}"`,
4157
+ presetTypes
4158
+ },
4159
+ ["0" /* Legacy */]: {
4160
+ domain: "StarkNetDomain",
4161
+ hashMethod: computePedersenHashOnElements,
4162
+ hashMerkleMethod: computePedersenHash,
4163
+ escapeTypeString: (s) => s,
4164
+ presetTypes: {}
4165
+ }
4166
+ };
4167
+ function byteArrayFromString(targetString) {
4168
+ const shortStrings = splitLongString(targetString);
4169
+ const remainder = shortStrings[shortStrings.length - 1];
4170
+ const shortStringsEncoded = shortStrings.map(encodeShortString);
4171
+ const [pendingWord, pendingWordLength] = remainder === void 0 || remainder.length === 31 ? ["0x00", 0] : [shortStringsEncoded.pop(), remainder.length];
4172
+ return {
4173
+ data: shortStringsEncoded.length === 0 ? ["0x00"] : shortStringsEncoded,
4174
+ pending_word: pendingWord,
4175
+ pending_word_len: pendingWordLength
4176
+ };
4177
+ }
4178
+ function identifyRevision({ types, domain }) {
4179
+ if (revisionConfiguration["1" /* Active */].domain in types && domain.revision === "1" /* Active */)
4180
+ return "1" /* Active */;
4181
+ if (revisionConfiguration["0" /* Legacy */].domain in types && (domain.revision ?? "0" /* Legacy */) === "0" /* Legacy */)
4182
+ return "0" /* Legacy */;
4183
+ return void 0;
4184
+ }
4083
4185
  function getHex(value) {
4084
4186
  try {
4085
4187
  return toHex(value);
@@ -4090,25 +4192,29 @@ function getHex(value) {
4090
4192
  throw new Error(`Invalid BigNumberish: ${value}`);
4091
4193
  }
4092
4194
  }
4093
- var validateTypedData = (data) => {
4195
+ function validateTypedData(data) {
4094
4196
  const typedData = data;
4095
- const valid = Boolean(typedData.types && typedData.primaryType && typedData.message);
4096
- return valid;
4097
- };
4197
+ return Boolean(
4198
+ typedData.message && typedData.primaryType && typedData.types && identifyRevision(typedData)
4199
+ );
4200
+ }
4098
4201
  function prepareSelector(selector) {
4099
4202
  return isHex(selector) ? selector : getSelectorFromName(selector);
4100
4203
  }
4101
4204
  function isMerkleTreeType(type) {
4102
4205
  return type.type === "merkletree";
4103
4206
  }
4104
- var getDependencies = (types, type, dependencies = []) => {
4207
+ function getDependencies(types, type, dependencies = [], contains = "", revision = "0" /* Legacy */) {
4105
4208
  if (type[type.length - 1] === "*") {
4106
4209
  type = type.slice(0, -1);
4210
+ } else if (revision === "1" /* Active */) {
4211
+ if (type === "enum") {
4212
+ type = contains;
4213
+ } else if (type.match(/^\(.*\)$/)) {
4214
+ type = type.slice(1, -1);
4215
+ }
4107
4216
  }
4108
- if (dependencies.includes(type)) {
4109
- return dependencies;
4110
- }
4111
- if (!types[type]) {
4217
+ if (dependencies.includes(type) || !types[type]) {
4112
4218
  return dependencies;
4113
4219
  }
4114
4220
  return [
@@ -4116,14 +4222,14 @@ var getDependencies = (types, type, dependencies = []) => {
4116
4222
  ...types[type].reduce(
4117
4223
  (previous, t) => [
4118
4224
  ...previous,
4119
- ...getDependencies(types, t.type, previous).filter(
4225
+ ...getDependencies(types, t.type, previous, t.contains, revision).filter(
4120
4226
  (dependency) => !previous.includes(dependency)
4121
4227
  )
4122
4228
  ],
4123
4229
  []
4124
4230
  )
4125
4231
  ];
4126
- };
4232
+ }
4127
4233
  function getMerkleTreeType(types, ctx) {
4128
4234
  if (ctx.parent && ctx.key) {
4129
4235
  const parentType = types[ctx.parent];
@@ -4139,80 +4245,148 @@ function getMerkleTreeType(types, ctx) {
4139
4245
  }
4140
4246
  return "raw";
4141
4247
  }
4142
- var encodeType = (types, type) => {
4143
- const [primary, ...dependencies] = getDependencies(types, type);
4248
+ function encodeType(types, type, revision = "0" /* Legacy */) {
4249
+ const [primary, ...dependencies] = getDependencies(types, type, void 0, void 0, revision);
4144
4250
  const newTypes = !primary ? [] : [primary, ...dependencies.sort()];
4251
+ const esc = revisionConfiguration[revision].escapeTypeString;
4145
4252
  return newTypes.map((dependency) => {
4146
- return `${dependency}(${types[dependency].map((t) => `${t.name}:${t.type}`)})`;
4253
+ const dependencyElements = types[dependency].map((t) => {
4254
+ const targetType = t.type === "enum" && revision === "1" /* Active */ ? t.contains : t.type;
4255
+ const typeString = targetType.match(/^\(.*\)$/) ? `(${targetType.slice(1, -1).split(",").map((e) => e ? esc(e) : e).join(",")})` : esc(targetType);
4256
+ return `${esc(t.name)}:${typeString}`;
4257
+ });
4258
+ return `${esc(dependency)}(${dependencyElements})`;
4147
4259
  }).join("");
4148
- };
4149
- var getTypeHash = (types, type) => {
4150
- return getSelectorFromName(encodeType(types, type));
4151
- };
4152
- var encodeValue = (types, type, data, ctx = {}) => {
4260
+ }
4261
+ function getTypeHash(types, type, revision = "0" /* Legacy */) {
4262
+ return getSelectorFromName(encodeType(types, type, revision));
4263
+ }
4264
+ function encodeValue(types, type, data, ctx = {}, revision = "0" /* Legacy */) {
4153
4265
  if (types[type]) {
4154
- return [type, getStructHash(types, type, data)];
4266
+ return [type, getStructHash(types, type, data, revision)];
4155
4267
  }
4156
- if (Object.keys(types).map((x) => `${x}*`).includes(type)) {
4157
- const structHashes = data.map((struct) => {
4158
- return getStructHash(types, type.slice(0, -1), struct);
4159
- });
4160
- return [type, computeHashOnElements(structHashes)];
4161
- }
4162
- if (type === "merkletree") {
4163
- const merkleTreeType = getMerkleTreeType(types, ctx);
4164
- const structHashes = data.map((struct) => {
4165
- return encodeValue(types, merkleTreeType, struct)[1];
4166
- });
4167
- const { root } = new MerkleTree(structHashes);
4168
- return ["felt", root];
4169
- }
4170
- if (type === "felt*") {
4171
- return ["felt*", computeHashOnElements(data)];
4268
+ if (revisionConfiguration[revision].presetTypes[type]) {
4269
+ return [
4270
+ type,
4271
+ getStructHash(
4272
+ revisionConfiguration[revision].presetTypes,
4273
+ type,
4274
+ data,
4275
+ revision
4276
+ )
4277
+ ];
4172
4278
  }
4173
- if (type === "selector") {
4174
- return ["felt", prepareSelector(data)];
4279
+ if (type.endsWith("*")) {
4280
+ const hashes = data.map(
4281
+ (entry) => encodeValue(types, type.slice(0, -1), entry, void 0, revision)[1]
4282
+ );
4283
+ return [type, revisionConfiguration[revision].hashMethod(hashes)];
4284
+ }
4285
+ switch (type) {
4286
+ case "enum": {
4287
+ if (revision === "1" /* Active */) {
4288
+ const [variantKey, variantData] = Object.entries(data)[0];
4289
+ const parentType = types[ctx.parent][0];
4290
+ const enumType = types[parentType.contains];
4291
+ const variantType = enumType.find((t) => t.name === variantKey);
4292
+ const variantIndex = enumType.indexOf(variantType);
4293
+ const encodedSubtypes = variantType.type.slice(1, -1).split(",").map((subtype, index) => {
4294
+ if (!subtype)
4295
+ return subtype;
4296
+ const subtypeData = variantData[index];
4297
+ return encodeValue(types, subtype, subtypeData, void 0, revision)[1];
4298
+ });
4299
+ return [
4300
+ type,
4301
+ revisionConfiguration[revision].hashMethod([variantIndex, ...encodedSubtypes])
4302
+ ];
4303
+ }
4304
+ return [type, getHex(data)];
4305
+ }
4306
+ case "merkletree": {
4307
+ const merkleTreeType = getMerkleTreeType(types, ctx);
4308
+ const structHashes = data.map((struct) => {
4309
+ return encodeValue(types, merkleTreeType, struct, void 0, revision)[1];
4310
+ });
4311
+ const { root } = new MerkleTree(
4312
+ structHashes,
4313
+ revisionConfiguration[revision].hashMerkleMethod
4314
+ );
4315
+ return ["felt", root];
4316
+ }
4317
+ case "selector": {
4318
+ return ["felt", prepareSelector(data)];
4319
+ }
4320
+ case "string": {
4321
+ if (revision === "1" /* Active */) {
4322
+ const byteArray = byteArrayFromString(data);
4323
+ const elements = [
4324
+ byteArray.data.length,
4325
+ ...byteArray.data,
4326
+ byteArray.pending_word,
4327
+ byteArray.pending_word_len
4328
+ ];
4329
+ return [type, revisionConfiguration[revision].hashMethod(elements)];
4330
+ }
4331
+ return [type, getHex(data)];
4332
+ }
4333
+ case "felt":
4334
+ case "bool":
4335
+ case "u128":
4336
+ case "i128":
4337
+ case "ContractAddress":
4338
+ case "ClassHash":
4339
+ case "timestamp":
4340
+ case "shortstring":
4341
+ return [type, getHex(data)];
4342
+ default: {
4343
+ if (revision === "1" /* Active */) {
4344
+ throw new Error(`Unsupported type: ${type}`);
4345
+ }
4346
+ return [type, getHex(data)];
4347
+ }
4175
4348
  }
4176
- return [type, getHex(data)];
4177
- };
4178
- var encodeData = (types, type, data) => {
4179
- const [returnTypes, values] = types[type].reduce(
4349
+ }
4350
+ function encodeData(types, type, data, revision = "0" /* Legacy */) {
4351
+ const targetType = types[type] ?? revisionConfiguration[revision].presetTypes[type];
4352
+ const [returnTypes, values] = targetType.reduce(
4180
4353
  ([ts, vs], field) => {
4181
- if (data[field.name] === void 0 || data[field.name] === null) {
4354
+ if (data[field.name] === void 0 || data[field.name] === null && field.type !== "enum") {
4182
4355
  throw new Error(`Cannot encode data: missing data for '${field.name}'`);
4183
4356
  }
4184
4357
  const value = data[field.name];
4185
- const [t, encodedValue] = encodeValue(types, field.type, value, {
4186
- parent: type,
4187
- key: field.name
4188
- });
4358
+ const ctx = { parent: type, key: field.name };
4359
+ const [t, encodedValue] = encodeValue(types, field.type, value, ctx, revision);
4189
4360
  return [
4190
4361
  [...ts, t],
4191
4362
  [...vs, encodedValue]
4192
4363
  ];
4193
4364
  },
4194
- [["felt"], [getTypeHash(types, type)]]
4365
+ [["felt"], [getTypeHash(types, type, revision)]]
4195
4366
  );
4196
4367
  return [returnTypes, values];
4197
- };
4198
- var getStructHash = (types, type, data) => {
4199
- return computeHashOnElements(encodeData(types, type, data)[1]);
4200
- };
4201
- var getMessageHash = (typedData, account) => {
4368
+ }
4369
+ function getStructHash(types, type, data, revision = "0" /* Legacy */) {
4370
+ return revisionConfiguration[revision].hashMethod(encodeData(types, type, data, revision)[1]);
4371
+ }
4372
+ function getMessageHash(typedData, account) {
4202
4373
  if (!validateTypedData(typedData)) {
4203
4374
  throw new Error("Typed data does not match JSON schema");
4204
4375
  }
4376
+ const revision = identifyRevision(typedData);
4377
+ const { domain, hashMethod } = revisionConfiguration[revision];
4205
4378
  const message = [
4206
4379
  encodeShortString("StarkNet Message"),
4207
- getStructHash(typedData.types, "StarkNetDomain", typedData.domain),
4380
+ getStructHash(typedData.types, domain, typedData.domain, revision),
4208
4381
  account,
4209
- getStructHash(typedData.types, typedData.primaryType, typedData.message)
4382
+ getStructHash(typedData.types, typedData.primaryType, typedData.message, revision)
4210
4383
  ];
4211
- return computeHashOnElements(message);
4212
- };
4384
+ return hashMethod(message);
4385
+ }
4213
4386
 
4214
4387
  // src/signer/default.ts
4215
4388
  var Signer = class {
4389
+ pk;
4216
4390
  constructor(pk = starkCurve.utils.randomPrivateKey()) {
4217
4391
  this.pk = pk instanceof Uint8Array ? buf2hex(pk) : toHex(pk);
4218
4392
  }
@@ -4307,9 +4481,11 @@ function parseUDCEvent(txReceipt) {
4307
4481
 
4308
4482
  // src/account/default.ts
4309
4483
  var Account = class extends Provider {
4484
+ signer;
4485
+ address;
4486
+ cairoVersion;
4310
4487
  constructor(providerOrOptions, address, pkOrSigner, cairoVersion) {
4311
4488
  super(providerOrOptions);
4312
- this.deploySelf = this.deployAccount;
4313
4489
  this.address = address.toLowerCase();
4314
4490
  this.signer = typeof pkOrSigner === "string" || pkOrSigner instanceof Uint8Array ? new Signer(pkOrSigner) : pkOrSigner;
4315
4491
  if (cairoVersion) {
@@ -4582,6 +4758,7 @@ var Account = class extends Provider {
4582
4758
  );
4583
4759
  return { declare: { ...declare }, deploy };
4584
4760
  }
4761
+ deploySelf = this.deployAccount;
4585
4762
  async deployAccount({
4586
4763
  classHash,
4587
4764
  constructorCalldata = [],
@@ -4945,6 +5122,17 @@ function getCalldata(args, callback) {
4945
5122
  return callback();
4946
5123
  }
4947
5124
  var Contract = class {
5125
+ abi;
5126
+ address;
5127
+ providerOrAccount;
5128
+ deployTransactionHash;
5129
+ structs;
5130
+ events;
5131
+ functions;
5132
+ callStatic;
5133
+ populateTransaction;
5134
+ estimateFee;
5135
+ callData;
4948
5136
  /**
4949
5137
  * Contract class to handle contract methods
4950
5138
  *
@@ -5118,7 +5306,7 @@ var Contract = class {
5118
5306
  async getVersion() {
5119
5307
  return this.providerOrAccount.getContractVersion(this.address);
5120
5308
  }
5121
- typed(tAbi) {
5309
+ typedv1(tAbi) {
5122
5310
  return this;
5123
5311
  }
5124
5312
  typedv2(tAbi) {
@@ -5128,10 +5316,21 @@ var Contract = class {
5128
5316
 
5129
5317
  // src/contract/interface.ts
5130
5318
  var ContractInterface = class {
5319
+ functions;
5320
+ callStatic;
5321
+ populateTransaction;
5322
+ estimateFee;
5131
5323
  };
5132
5324
 
5133
5325
  // src/contract/contractFactory.ts
5134
5326
  var ContractFactory = class {
5327
+ compiledContract;
5328
+ account;
5329
+ abi;
5330
+ classHash;
5331
+ casm;
5332
+ compiledClassHash;
5333
+ CallData;
5135
5334
  /**
5136
5335
  * @param params CFParams
5137
5336
  * - compiledContract: CompiledContract;
@@ -5199,7 +5398,7 @@ var ContractFactory = class {
5199
5398
  attach(address) {
5200
5399
  return new Contract(this.abi, address, this.account);
5201
5400
  }
5202
- // 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
5401
+ // 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
5203
5402
  };
5204
5403
 
5205
5404
  // src/utils/address.ts
@@ -5254,7 +5453,7 @@ export {
5254
5453
  GatewayError,
5255
5454
  HttpError,
5256
5455
  LibraryError,
5257
- Litteral,
5456
+ Literal,
5258
5457
  Provider,
5259
5458
  ProviderInterface,
5260
5459
  rpc_exports as RPC,
@@ -5268,6 +5467,7 @@ export {
5268
5467
  TransactionFinalityStatus,
5269
5468
  TransactionStatus,
5270
5469
  TransactionType,
5470
+ TypedDataRevision,
5271
5471
  Uint,
5272
5472
  ValidateType,
5273
5473
  addAddressPadding,