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.
@@ -665,7 +665,7 @@ var starknet = (() => {
665
665
  GatewayError: () => GatewayError,
666
666
  HttpError: () => HttpError,
667
667
  LibraryError: () => LibraryError,
668
- Litteral: () => Litteral,
668
+ Literal: () => Literal,
669
669
  Provider: () => Provider,
670
670
  ProviderInterface: () => ProviderInterface,
671
671
  RPC: () => rpc_exports,
@@ -679,6 +679,7 @@ var starknet = (() => {
679
679
  TransactionFinalityStatus: () => TransactionFinalityStatus,
680
680
  TransactionStatus: () => TransactionStatus,
681
681
  TransactionType: () => TransactionType,
682
+ TypedDataRevision: () => TypedDataRevision,
682
683
  Uint: () => Uint,
683
684
  ValidateType: () => ValidateType,
684
685
  addAddressPadding: () => addAddressPadding,
@@ -1057,7 +1058,7 @@ var starknet = (() => {
1057
1058
  BlockStatus: () => BlockStatus,
1058
1059
  BlockTag: () => BlockTag,
1059
1060
  EntryPointType: () => EntryPointType,
1060
- Litteral: () => Litteral,
1061
+ Literal: () => Literal,
1061
1062
  RPC: () => rpc_exports,
1062
1063
  SIMULATION_FLAG: () => SIMULATION_FLAG,
1063
1064
  Sequencer: () => sequencer_exports,
@@ -1065,6 +1066,7 @@ var starknet = (() => {
1065
1066
  TransactionFinalityStatus: () => TransactionFinalityStatus,
1066
1067
  TransactionStatus: () => TransactionStatus,
1067
1068
  TransactionType: () => TransactionType,
1069
+ TypedDataRevision: () => TypedDataRevision,
1068
1070
  Uint: () => Uint,
1069
1071
  ValidateType: () => ValidateType
1070
1072
  });
@@ -1092,11 +1094,11 @@ var starknet = (() => {
1092
1094
  Uint2["u256"] = "core::integer::u256";
1093
1095
  return Uint2;
1094
1096
  })(Uint || {});
1095
- var Litteral = /* @__PURE__ */ ((Litteral2) => {
1096
- Litteral2["ClassHash"] = "core::starknet::class_hash::ClassHash";
1097
- Litteral2["ContractAddress"] = "core::starknet::contract_address::ContractAddress";
1098
- return Litteral2;
1099
- })(Litteral || {});
1097
+ var Literal = /* @__PURE__ */ ((Literal2) => {
1098
+ Literal2["ClassHash"] = "core::starknet::class_hash::ClassHash";
1099
+ Literal2["ContractAddress"] = "core::starknet::contract_address::ContractAddress";
1100
+ return Literal2;
1101
+ })(Literal || {});
1100
1102
 
1101
1103
  // src/types/lib/contract/index.ts
1102
1104
  var EntryPointType = /* @__PURE__ */ ((EntryPointType2) => {
@@ -1149,6 +1151,13 @@ var starknet = (() => {
1149
1151
  return BlockTag2;
1150
1152
  })(BlockTag || {});
1151
1153
 
1154
+ // src/types/typedData.ts
1155
+ var TypedDataRevision = /* @__PURE__ */ ((TypedDataRevision2) => {
1156
+ TypedDataRevision2["Active"] = "1";
1157
+ TypedDataRevision2["Legacy"] = "0";
1158
+ return TypedDataRevision2;
1159
+ })(TypedDataRevision || {});
1160
+
1152
1161
  // src/types/api/rpc.ts
1153
1162
  var rpc_exports = {};
1154
1163
  __export(rpc_exports, {
@@ -3963,7 +3972,7 @@ var starknet = (() => {
3963
3972
  isTypeEnum: () => isTypeEnum,
3964
3973
  isTypeEthAddress: () => isTypeEthAddress,
3965
3974
  isTypeFelt: () => isTypeFelt,
3966
- isTypeLitteral: () => isTypeLitteral,
3975
+ isTypeLiteral: () => isTypeLiteral,
3967
3976
  isTypeNamedTuple: () => isTypeNamedTuple,
3968
3977
  isTypeOption: () => isTypeOption,
3969
3978
  isTypeResult: () => isTypeResult,
@@ -4013,7 +4022,7 @@ var starknet = (() => {
4013
4022
  var isTypeOption = (type) => type.startsWith("core::option::Option::");
4014
4023
  var isTypeResult = (type) => type.startsWith("core::result::Result::");
4015
4024
  var isTypeUint = (type) => Object.values(Uint).includes(type);
4016
- var isTypeLitteral = (type) => Object.values(Litteral).includes(type);
4025
+ var isTypeLiteral = (type) => Object.values(Literal).includes(type);
4017
4026
  var isTypeUint256 = (type) => type === "core::integer::u256";
4018
4027
  var isTypeBool = (type) => type === "core::bool";
4019
4028
  var isTypeContractAddress = (type) => type === "core::starknet::contract_address::ContractAddress";
@@ -4086,13 +4095,21 @@ var starknet = (() => {
4086
4095
 
4087
4096
  // src/utils/calldata/enum/CairoCustomEnum.ts
4088
4097
  var CairoCustomEnum = class {
4098
+ /**
4099
+ * direct readonly access to variants of the Cairo Custom Enum.
4100
+ * @returns a value of type any
4101
+ * @example
4102
+ * ```typescript
4103
+ * const successValue = myCairoEnum.variant.Success;
4104
+ */
4105
+ variant;
4089
4106
  /**
4090
4107
  * @param enumContent an object with the variants as keys and the content as value. Only one content shall be defined.
4091
4108
  */
4092
4109
  constructor(enumContent) {
4093
4110
  const variantsList = Object.values(enumContent);
4094
4111
  if (variantsList.length === 0) {
4095
- throw new Error("This Enum must have a least 1 variant");
4112
+ throw new Error("This Enum must have at least 1 variant");
4096
4113
  }
4097
4114
  const nbActiveVariants = variantsList.filter(
4098
4115
  (content) => typeof content !== "undefined"
@@ -4135,6 +4152,8 @@ var starknet = (() => {
4135
4152
  return CairoOptionVariant2;
4136
4153
  })(CairoOptionVariant || {});
4137
4154
  var CairoOption = class {
4155
+ Some;
4156
+ None;
4138
4157
  constructor(variant, someContent) {
4139
4158
  if (!(variant in CairoOptionVariant)) {
4140
4159
  throw new Error("Wrong variant : should be CairoOptionVariant.Some or .None.");
@@ -4186,6 +4205,8 @@ var starknet = (() => {
4186
4205
  return CairoResultVariant2;
4187
4206
  })(CairoResultVariant || {});
4188
4207
  var CairoResult = class {
4208
+ Ok;
4209
+ Err;
4189
4210
  constructor(variant, resultContent) {
4190
4211
  if (!(variant in CairoResultVariant)) {
4191
4212
  throw new Error("Wrong variant : should be CairoResultVariant.Ok or .Err.");
@@ -4284,6 +4305,7 @@ var starknet = (() => {
4284
4305
 
4285
4306
  // src/utils/calldata/parser/parser-0-1.1.0.ts
4286
4307
  var AbiParser1 = class {
4308
+ abi;
4287
4309
  constructor(abi) {
4288
4310
  this.abi = abi;
4289
4311
  }
@@ -4315,6 +4337,7 @@ var starknet = (() => {
4315
4337
 
4316
4338
  // src/utils/calldata/parser/parser-2.0.0.ts
4317
4339
  var AbiParser2 = class {
4340
+ abi;
4318
4341
  constructor(abi) {
4319
4342
  this.abi = abi;
4320
4343
  }
@@ -5060,7 +5083,7 @@ var starknet = (() => {
5060
5083
  case isTypeEnum(baseType, enums):
5061
5084
  parameter.forEach((it) => validateEnum(it, { name: input.name, type: baseType }));
5062
5085
  break;
5063
- case (isTypeUint(baseType) || isTypeLitteral(baseType)):
5086
+ case (isTypeUint(baseType) || isTypeLiteral(baseType)):
5064
5087
  parameter.forEach((param) => validateUint(param, input));
5065
5088
  break;
5066
5089
  case isTypeBool(baseType):
@@ -5081,7 +5104,7 @@ var starknet = (() => {
5081
5104
  case isTypeFelt(input.type):
5082
5105
  validateFelt(parameter, input);
5083
5106
  break;
5084
- case (isTypeUint(input.type) || isTypeLitteral(input.type)):
5107
+ case (isTypeUint(input.type) || isTypeLiteral(input.type)):
5085
5108
  validateUint(parameter, input);
5086
5109
  break;
5087
5110
  case isTypeBool(input.type):
@@ -5110,6 +5133,10 @@ var starknet = (() => {
5110
5133
 
5111
5134
  // src/utils/calldata/index.ts
5112
5135
  var CallData = class {
5136
+ abi;
5137
+ parser;
5138
+ structs;
5139
+ enums;
5113
5140
  constructor(abi) {
5114
5141
  this.structs = CallData.getAbiStruct(abi);
5115
5142
  this.enums = CallData.getAbiEnum(abi);
@@ -5354,6 +5381,10 @@ var starknet = (() => {
5354
5381
  computeContractClassHash: () => computeContractClassHash,
5355
5382
  computeHashOnElements: () => computeHashOnElements2,
5356
5383
  computeLegacyContractClassHash: () => computeLegacyContractClassHash,
5384
+ computePedersenHash: () => computePedersenHash,
5385
+ computePedersenHashOnElements: () => computePedersenHashOnElements,
5386
+ computePoseidonHash: () => computePoseidonHash,
5387
+ computePoseidonHashOnElements: () => computePoseidonHashOnElements,
5357
5388
  computeSierraContractClassHash: () => computeSierraContractClassHash,
5358
5389
  default: () => computeHintedClassHash,
5359
5390
  feeTransactionVersion: () => feeTransactionVersion,
@@ -6063,8 +6094,18 @@ var starknet = (() => {
6063
6094
  function getVersionsByType(versionType) {
6064
6095
  return versionType === "fee" ? { v1: feeTransactionVersion, v2: feeTransactionVersion_2 } : { v1: transactionVersion, v2: transactionVersion_2 };
6065
6096
  }
6097
+ function computePedersenHash(a, b) {
6098
+ return esm_exports.pedersen(BigInt(a), BigInt(b));
6099
+ }
6100
+ function computePoseidonHash(a, b) {
6101
+ return toHex(esm_exports.poseidonHash(BigInt(a), BigInt(b)));
6102
+ }
6066
6103
  function computeHashOnElements2(data) {
6067
- return [...data, data.length].reduce((x, y) => esm_exports.pedersen(toBigInt(x), toBigInt(y)), 0).toString();
6104
+ return [...data, data.length].reduce((x, y) => esm_exports.pedersen(BigInt(x), BigInt(y)), 0).toString();
6105
+ }
6106
+ var computePedersenHashOnElements = computeHashOnElements2;
6107
+ function computePoseidonHashOnElements(data) {
6108
+ return toHex(poseidonHashMany(data.map((x) => BigInt(x))));
6068
6109
  }
6069
6110
  function calculateTransactionHashCommon(txHashPrefix, version, contractAddress, entryPointSelector, calldata, maxFee, chainId, additionalData = []) {
6070
6111
  const calldataHash = computeHashOnElements2(calldata);
@@ -10620,6 +10661,7 @@ var starknet = (() => {
10620
10661
  setPrototypeOf ? setPrototypeOf(target, prototype) : target.__proto__ = prototype;
10621
10662
  }
10622
10663
  var CustomError = class extends Error {
10664
+ name;
10623
10665
  constructor(message) {
10624
10666
  super(message);
10625
10667
  Object.defineProperty(this, "name", {
@@ -10796,14 +10838,9 @@ var starknet = (() => {
10796
10838
  // src/provider/utils.ts
10797
10839
  var validBlockTags = Object.values(BlockTag);
10798
10840
  var Block = class {
10799
- constructor(_identifier) {
10800
- this.hash = null;
10801
- this.number = null;
10802
- this.tag = null;
10803
- this.valueOf = () => this.number;
10804
- this.toString = () => this.hash;
10805
- this.setIdentifier(_identifier);
10806
- }
10841
+ hash = null;
10842
+ number = null;
10843
+ tag = null;
10807
10844
  setIdentifier(__identifier) {
10808
10845
  if (typeof __identifier === "string" && isHex(__identifier)) {
10809
10846
  this.hash = __identifier;
@@ -10817,6 +10854,9 @@ var starknet = (() => {
10817
10854
  this.tag = "pending" /* pending */;
10818
10855
  }
10819
10856
  }
10857
+ constructor(_identifier) {
10858
+ this.setIdentifier(_identifier);
10859
+ }
10820
10860
  // TODO: fix any
10821
10861
  get queryIdentifier() {
10822
10862
  if (this.number !== null) {
@@ -10840,6 +10880,8 @@ var starknet = (() => {
10840
10880
  set identifier(_identifier) {
10841
10881
  this.setIdentifier(_identifier);
10842
10882
  }
10883
+ valueOf = () => this.number;
10884
+ toString = () => this.hash;
10843
10885
  get sequencerIdentifier() {
10844
10886
  return this.hash !== null ? { blockHash: this.hash } : { blockNumber: this.number ?? this.tag };
10845
10887
  }
@@ -10859,36 +10901,13 @@ var starknet = (() => {
10859
10901
  retries: 200
10860
10902
  };
10861
10903
  var RpcProvider = class {
10904
+ nodeUrl;
10905
+ headers;
10906
+ responseParser = new RPCResponseParser();
10907
+ retries;
10908
+ blockIdentifier;
10909
+ chainId;
10862
10910
  constructor(optionsOrProvider) {
10863
- this.responseParser = new RPCResponseParser();
10864
- /**
10865
- * @deprecated renamed to getBlockLatestAccepted(); (will be removed in next minor version)
10866
- */
10867
- this.getBlockHashAndNumber = this.getBlockLatestAccepted;
10868
- /**
10869
- * @deprecated renamed to getBlockStateUpdate();
10870
- */
10871
- this.getStateUpdate = this.getBlockStateUpdate;
10872
- /**
10873
- * Returns the execution traces of all transactions included in the given block
10874
- * @deprecated renamed to getBlockTransactionsTraces()
10875
- */
10876
- this.traceBlockTransactions = this.getBlockTransactionsTraces;
10877
- /**
10878
- * Get the number of transactions in a block given a block id
10879
- * @deprecated renamed to getBlockTransactionCount()
10880
- * @returns Number of transactions
10881
- */
10882
- this.getTransactionCount = this.getBlockTransactionCount;
10883
- /**
10884
- * @deprecated renamed to getTransactionTrace();
10885
- * For a given executed transaction, return the trace of its execution, including internal calls
10886
- */
10887
- this.traceTransaction = this.getTransactionTrace;
10888
- /**
10889
- * @deprecated renamed to simulateTransaction();
10890
- */
10891
- this.getSimulateTransaction = this.simulateTransaction;
10892
10911
  const { nodeUrl, retries, headers, blockIdentifier, chainId, rpcVersion } = optionsOrProvider || {};
10893
10912
  if (Object.values(NetworkName).includes(nodeUrl)) {
10894
10913
  this.nodeUrl = getDefaultNodeUrl(
@@ -10946,7 +10965,7 @@ var starknet = (() => {
10946
10965
  }
10947
10966
  }
10948
10967
  async getChainId() {
10949
- this.chainId ?? (this.chainId = await this.fetchEndpoint("starknet_chainId"));
10968
+ this.chainId ??= await this.fetchEndpoint("starknet_chainId");
10950
10969
  return this.chainId;
10951
10970
  }
10952
10971
  /**
@@ -10971,6 +10990,10 @@ var starknet = (() => {
10971
10990
  this.responseParser.parseGetBlockResponse
10972
10991
  );
10973
10992
  }
10993
+ /**
10994
+ * @deprecated renamed to getBlockLatestAccepted(); (will be removed in next minor version)
10995
+ */
10996
+ getBlockHashAndNumber = this.getBlockLatestAccepted;
10974
10997
  /**
10975
10998
  * Get the most recent accepted block hash and number
10976
10999
  */
@@ -10997,14 +11020,29 @@ var starknet = (() => {
10997
11020
  const block_id = new Block(blockIdentifier).identifier;
10998
11021
  return this.fetchEndpoint("starknet_getStateUpdate", { block_id });
10999
11022
  }
11023
+ /**
11024
+ * @deprecated renamed to getBlockStateUpdate();
11025
+ */
11026
+ getStateUpdate = this.getBlockStateUpdate;
11000
11027
  async getBlockTransactionsTraces(blockIdentifier = this.blockIdentifier) {
11001
11028
  const block_id = new Block(blockIdentifier).identifier;
11002
11029
  return this.fetchEndpoint("starknet_traceBlockTransactions", { block_id });
11003
11030
  }
11031
+ /**
11032
+ * Returns the execution traces of all transactions included in the given block
11033
+ * @deprecated renamed to getBlockTransactionsTraces()
11034
+ */
11035
+ traceBlockTransactions = this.getBlockTransactionsTraces;
11004
11036
  async getBlockTransactionCount(blockIdentifier = this.blockIdentifier) {
11005
11037
  const block_id = new Block(blockIdentifier).identifier;
11006
11038
  return this.fetchEndpoint("starknet_getBlockTransactionCount", { block_id });
11007
11039
  }
11040
+ /**
11041
+ * Get the number of transactions in a block given a block id
11042
+ * @deprecated renamed to getBlockTransactionCount()
11043
+ * @returns Number of transactions
11044
+ */
11045
+ getTransactionCount = this.getBlockTransactionCount;
11008
11046
  /**
11009
11047
  * Return transactions from pending block
11010
11048
  * @deprecated Instead use getBlock(BlockTag.pending); (will be removed in next minor version)
@@ -11037,6 +11075,11 @@ var starknet = (() => {
11037
11075
  const transaction_hash = toHex(txHash);
11038
11076
  return this.fetchEndpoint("starknet_traceTransaction", { transaction_hash });
11039
11077
  }
11078
+ /**
11079
+ * @deprecated renamed to getTransactionTrace();
11080
+ * For a given executed transaction, return the trace of its execution, including internal calls
11081
+ */
11082
+ traceTransaction = this.getTransactionTrace;
11040
11083
  /**
11041
11084
  * NEW: Get the status of a transaction
11042
11085
  */
@@ -11044,6 +11087,10 @@ var starknet = (() => {
11044
11087
  const transaction_hash = toHex(transactionHash);
11045
11088
  return this.fetchEndpoint("starknet_getTransactionStatus", { transaction_hash });
11046
11089
  }
11090
+ /**
11091
+ * @deprecated renamed to simulateTransaction();
11092
+ */
11093
+ getSimulateTransaction = this.simulateTransaction;
11047
11094
  /**
11048
11095
  * @param invocations AccountInvocations
11049
11096
  * @param simulateTransactionOptions blockIdentifier and flags to skip validation and fee charge<br/>
@@ -11598,8 +11645,14 @@ var starknet = (() => {
11598
11645
  blockIdentifier: "pending" /* pending */
11599
11646
  };
11600
11647
  var SequencerProvider = class {
11648
+ baseUrl;
11649
+ feederGatewayUrl;
11650
+ gatewayUrl;
11651
+ headers;
11652
+ blockIdentifier;
11653
+ chainId;
11654
+ responseParser = new SequencerAPIResponseParser();
11601
11655
  constructor(optionsOrProvider = defaultOptions2) {
11602
- this.responseParser = new SequencerAPIResponseParser();
11603
11656
  if ("network" in optionsOrProvider) {
11604
11657
  this.baseUrl = SequencerProvider.getNetworkFromName(optionsOrProvider.network);
11605
11658
  this.feederGatewayUrl = buildUrl(this.baseUrl, "feeder_gateway");
@@ -11788,7 +11841,7 @@ var starknet = (() => {
11788
11841
  } else if (classHash) {
11789
11842
  contractClass = await this.getClassByHash(classHash, blockIdentifier);
11790
11843
  } else {
11791
- throw Error("getContractVersion require contractAddress or classHash");
11844
+ throw Error("getContractVersion requires contractAddress or classHash");
11792
11845
  }
11793
11846
  if (isSierra(contractClass)) {
11794
11847
  if (compiler) {
@@ -12077,6 +12130,7 @@ ${res.tx_failure_reason.error_message}`;
12077
12130
 
12078
12131
  // src/provider/default.ts
12079
12132
  var Provider = class {
12133
+ provider;
12080
12134
  constructor(providerOrOptions) {
12081
12135
  if (providerOrOptions instanceof Provider) {
12082
12136
  this.provider = providerOrOptions.provider;
@@ -12244,6 +12298,8 @@ ${res.tx_failure_reason.error_message}`;
12244
12298
  // src/utils/typedData.ts
12245
12299
  var typedData_exports = {};
12246
12300
  __export(typedData_exports, {
12301
+ TypedDataRevision: () => TypedDataRevision,
12302
+ byteArrayFromString: () => byteArrayFromString,
12247
12303
  encodeData: () => encodeData,
12248
12304
  encodeType: () => encodeType,
12249
12305
  encodeValue: () => encodeValue,
@@ -12262,8 +12318,12 @@ ${res.tx_failure_reason.error_message}`;
12262
12318
  proofMerklePath: () => proofMerklePath
12263
12319
  });
12264
12320
  var MerkleTree = class {
12265
- constructor(leafHashes) {
12266
- this.branches = [];
12321
+ leaves;
12322
+ branches = [];
12323
+ root;
12324
+ hashMethod;
12325
+ constructor(leafHashes, hashMethod = computePedersenHash) {
12326
+ this.hashMethod = hashMethod;
12267
12327
  this.leaves = leafHashes;
12268
12328
  this.root = this.build(leafHashes);
12269
12329
  }
@@ -12282,20 +12342,20 @@ ${res.tx_failure_reason.error_message}`;
12282
12342
  const newLeaves = [];
12283
12343
  for (let i = 0; i < leaves.length; i += 2) {
12284
12344
  if (i + 1 === leaves.length) {
12285
- newLeaves.push(MerkleTree.hash(leaves[i], "0x0"));
12345
+ newLeaves.push(MerkleTree.hash(leaves[i], "0x0", this.hashMethod));
12286
12346
  } else {
12287
- newLeaves.push(MerkleTree.hash(leaves[i], leaves[i + 1]));
12347
+ newLeaves.push(MerkleTree.hash(leaves[i], leaves[i + 1], this.hashMethod));
12288
12348
  }
12289
12349
  }
12290
12350
  return this.build(newLeaves);
12291
12351
  }
12292
12352
  /**
12293
- * Create pedersen hash from a and b
12353
+ * Create hash from ordered a and b, Pedersen hash default
12294
12354
  * @returns format: hex-string
12295
12355
  */
12296
- static hash(a, b) {
12297
- const [aSorted, bSorted] = [toBigInt(a), toBigInt(b)].sort((x, y) => x >= y ? 1 : -1);
12298
- return esm_exports.pedersen(aSorted, bSorted);
12356
+ static hash(a, b, hashMethod = computePedersenHash) {
12357
+ const [aSorted, bSorted] = [BigInt(a), BigInt(b)].sort((x, y) => x >= y ? 1 : -1);
12358
+ return hashMethod(aSorted, bSorted);
12299
12359
  }
12300
12360
  /**
12301
12361
  * Return path to leaf
@@ -12318,21 +12378,64 @@ ${res.tx_failure_reason.error_message}`;
12318
12378
  const currentBranchLevelIndex = this.leaves.length === branch.length ? -1 : this.branches.findIndex((b) => b.length === branch.length);
12319
12379
  const nextBranch = this.branches[currentBranchLevelIndex + 1] ?? [this.root];
12320
12380
  return this.getProof(
12321
- MerkleTree.hash(isLeft ? leaf : neededBranch, isLeft ? neededBranch : leaf),
12381
+ MerkleTree.hash(isLeft ? leaf : neededBranch, isLeft ? neededBranch : leaf, this.hashMethod),
12322
12382
  nextBranch,
12323
12383
  newHashPath
12324
12384
  );
12325
12385
  }
12326
12386
  };
12327
- function proofMerklePath(root, leaf, path) {
12387
+ function proofMerklePath(root, leaf, path, hashMethod = computePedersenHash) {
12328
12388
  if (path.length === 0) {
12329
12389
  return root === leaf;
12330
12390
  }
12331
12391
  const [next, ...rest] = path;
12332
- return proofMerklePath(root, MerkleTree.hash(leaf, next), rest);
12392
+ return proofMerklePath(root, MerkleTree.hash(leaf, next, hashMethod), rest, hashMethod);
12333
12393
  }
12334
12394
 
12335
12395
  // src/utils/typedData.ts
12396
+ var presetTypes = {
12397
+ u256: JSON.parse('[{ "name": "low", "type": "u128" }, { "name": "high", "type": "u128" }]'),
12398
+ TokenAmount: JSON.parse(
12399
+ '[{ "name": "token_address", "type": "ContractAddress" }, { "name": "amount", "type": "u256" }]'
12400
+ ),
12401
+ NftId: JSON.parse(
12402
+ '[{ "name": "collection_address", "type": "ContractAddress" }, { "name": "token_id", "type": "u256" }]'
12403
+ )
12404
+ };
12405
+ var revisionConfiguration = {
12406
+ ["1" /* Active */]: {
12407
+ domain: "StarknetDomain",
12408
+ hashMethod: computePoseidonHashOnElements,
12409
+ hashMerkleMethod: computePoseidonHash,
12410
+ escapeTypeString: (s) => `"${s}"`,
12411
+ presetTypes
12412
+ },
12413
+ ["0" /* Legacy */]: {
12414
+ domain: "StarkNetDomain",
12415
+ hashMethod: computePedersenHashOnElements,
12416
+ hashMerkleMethod: computePedersenHash,
12417
+ escapeTypeString: (s) => s,
12418
+ presetTypes: {}
12419
+ }
12420
+ };
12421
+ function byteArrayFromString(targetString) {
12422
+ const shortStrings = splitLongString(targetString);
12423
+ const remainder = shortStrings[shortStrings.length - 1];
12424
+ const shortStringsEncoded = shortStrings.map(encodeShortString);
12425
+ const [pendingWord, pendingWordLength] = remainder === void 0 || remainder.length === 31 ? ["0x00", 0] : [shortStringsEncoded.pop(), remainder.length];
12426
+ return {
12427
+ data: shortStringsEncoded.length === 0 ? ["0x00"] : shortStringsEncoded,
12428
+ pending_word: pendingWord,
12429
+ pending_word_len: pendingWordLength
12430
+ };
12431
+ }
12432
+ function identifyRevision({ types, domain }) {
12433
+ if (revisionConfiguration["1" /* Active */].domain in types && domain.revision === "1" /* Active */)
12434
+ return "1" /* Active */;
12435
+ if (revisionConfiguration["0" /* Legacy */].domain in types && (domain.revision ?? "0" /* Legacy */) === "0" /* Legacy */)
12436
+ return "0" /* Legacy */;
12437
+ return void 0;
12438
+ }
12336
12439
  function getHex(value) {
12337
12440
  try {
12338
12441
  return toHex(value);
@@ -12343,25 +12446,29 @@ ${res.tx_failure_reason.error_message}`;
12343
12446
  throw new Error(`Invalid BigNumberish: ${value}`);
12344
12447
  }
12345
12448
  }
12346
- var validateTypedData = (data) => {
12449
+ function validateTypedData(data) {
12347
12450
  const typedData = data;
12348
- const valid = Boolean(typedData.types && typedData.primaryType && typedData.message);
12349
- return valid;
12350
- };
12451
+ return Boolean(
12452
+ typedData.message && typedData.primaryType && typedData.types && identifyRevision(typedData)
12453
+ );
12454
+ }
12351
12455
  function prepareSelector(selector) {
12352
12456
  return isHex(selector) ? selector : getSelectorFromName(selector);
12353
12457
  }
12354
12458
  function isMerkleTreeType(type) {
12355
12459
  return type.type === "merkletree";
12356
12460
  }
12357
- var getDependencies = (types, type, dependencies = []) => {
12461
+ function getDependencies(types, type, dependencies = [], contains = "", revision = "0" /* Legacy */) {
12358
12462
  if (type[type.length - 1] === "*") {
12359
12463
  type = type.slice(0, -1);
12464
+ } else if (revision === "1" /* Active */) {
12465
+ if (type === "enum") {
12466
+ type = contains;
12467
+ } else if (type.match(/^\(.*\)$/)) {
12468
+ type = type.slice(1, -1);
12469
+ }
12360
12470
  }
12361
- if (dependencies.includes(type)) {
12362
- return dependencies;
12363
- }
12364
- if (!types[type]) {
12471
+ if (dependencies.includes(type) || !types[type]) {
12365
12472
  return dependencies;
12366
12473
  }
12367
12474
  return [
@@ -12369,14 +12476,14 @@ ${res.tx_failure_reason.error_message}`;
12369
12476
  ...types[type].reduce(
12370
12477
  (previous, t) => [
12371
12478
  ...previous,
12372
- ...getDependencies(types, t.type, previous).filter(
12479
+ ...getDependencies(types, t.type, previous, t.contains, revision).filter(
12373
12480
  (dependency) => !previous.includes(dependency)
12374
12481
  )
12375
12482
  ],
12376
12483
  []
12377
12484
  )
12378
12485
  ];
12379
- };
12486
+ }
12380
12487
  function getMerkleTreeType(types, ctx) {
12381
12488
  if (ctx.parent && ctx.key) {
12382
12489
  const parentType = types[ctx.parent];
@@ -12392,80 +12499,148 @@ ${res.tx_failure_reason.error_message}`;
12392
12499
  }
12393
12500
  return "raw";
12394
12501
  }
12395
- var encodeType = (types, type) => {
12396
- const [primary, ...dependencies] = getDependencies(types, type);
12502
+ function encodeType(types, type, revision = "0" /* Legacy */) {
12503
+ const [primary, ...dependencies] = getDependencies(types, type, void 0, void 0, revision);
12397
12504
  const newTypes = !primary ? [] : [primary, ...dependencies.sort()];
12505
+ const esc = revisionConfiguration[revision].escapeTypeString;
12398
12506
  return newTypes.map((dependency) => {
12399
- return `${dependency}(${types[dependency].map((t) => `${t.name}:${t.type}`)})`;
12507
+ const dependencyElements = types[dependency].map((t) => {
12508
+ const targetType = t.type === "enum" && revision === "1" /* Active */ ? t.contains : t.type;
12509
+ const typeString = targetType.match(/^\(.*\)$/) ? `(${targetType.slice(1, -1).split(",").map((e) => e ? esc(e) : e).join(",")})` : esc(targetType);
12510
+ return `${esc(t.name)}:${typeString}`;
12511
+ });
12512
+ return `${esc(dependency)}(${dependencyElements})`;
12400
12513
  }).join("");
12401
- };
12402
- var getTypeHash = (types, type) => {
12403
- return getSelectorFromName(encodeType(types, type));
12404
- };
12405
- var encodeValue = (types, type, data, ctx = {}) => {
12514
+ }
12515
+ function getTypeHash(types, type, revision = "0" /* Legacy */) {
12516
+ return getSelectorFromName(encodeType(types, type, revision));
12517
+ }
12518
+ function encodeValue(types, type, data, ctx = {}, revision = "0" /* Legacy */) {
12406
12519
  if (types[type]) {
12407
- return [type, getStructHash(types, type, data)];
12408
- }
12409
- if (Object.keys(types).map((x) => `${x}*`).includes(type)) {
12410
- const structHashes = data.map((struct) => {
12411
- return getStructHash(types, type.slice(0, -1), struct);
12412
- });
12413
- return [type, computeHashOnElements2(structHashes)];
12414
- }
12415
- if (type === "merkletree") {
12416
- const merkleTreeType = getMerkleTreeType(types, ctx);
12417
- const structHashes = data.map((struct) => {
12418
- return encodeValue(types, merkleTreeType, struct)[1];
12419
- });
12420
- const { root } = new MerkleTree(structHashes);
12421
- return ["felt", root];
12422
- }
12423
- if (type === "felt*") {
12424
- return ["felt*", computeHashOnElements2(data)];
12520
+ return [type, getStructHash(types, type, data, revision)];
12425
12521
  }
12426
- if (type === "selector") {
12427
- return ["felt", prepareSelector(data)];
12522
+ if (revisionConfiguration[revision].presetTypes[type]) {
12523
+ return [
12524
+ type,
12525
+ getStructHash(
12526
+ revisionConfiguration[revision].presetTypes,
12527
+ type,
12528
+ data,
12529
+ revision
12530
+ )
12531
+ ];
12428
12532
  }
12429
- return [type, getHex(data)];
12430
- };
12431
- var encodeData = (types, type, data) => {
12432
- const [returnTypes, values] = types[type].reduce(
12533
+ if (type.endsWith("*")) {
12534
+ const hashes = data.map(
12535
+ (entry) => encodeValue(types, type.slice(0, -1), entry, void 0, revision)[1]
12536
+ );
12537
+ return [type, revisionConfiguration[revision].hashMethod(hashes)];
12538
+ }
12539
+ switch (type) {
12540
+ case "enum": {
12541
+ if (revision === "1" /* Active */) {
12542
+ const [variantKey, variantData] = Object.entries(data)[0];
12543
+ const parentType = types[ctx.parent][0];
12544
+ const enumType = types[parentType.contains];
12545
+ const variantType = enumType.find((t) => t.name === variantKey);
12546
+ const variantIndex = enumType.indexOf(variantType);
12547
+ const encodedSubtypes = variantType.type.slice(1, -1).split(",").map((subtype, index) => {
12548
+ if (!subtype)
12549
+ return subtype;
12550
+ const subtypeData = variantData[index];
12551
+ return encodeValue(types, subtype, subtypeData, void 0, revision)[1];
12552
+ });
12553
+ return [
12554
+ type,
12555
+ revisionConfiguration[revision].hashMethod([variantIndex, ...encodedSubtypes])
12556
+ ];
12557
+ }
12558
+ return [type, getHex(data)];
12559
+ }
12560
+ case "merkletree": {
12561
+ const merkleTreeType = getMerkleTreeType(types, ctx);
12562
+ const structHashes = data.map((struct) => {
12563
+ return encodeValue(types, merkleTreeType, struct, void 0, revision)[1];
12564
+ });
12565
+ const { root } = new MerkleTree(
12566
+ structHashes,
12567
+ revisionConfiguration[revision].hashMerkleMethod
12568
+ );
12569
+ return ["felt", root];
12570
+ }
12571
+ case "selector": {
12572
+ return ["felt", prepareSelector(data)];
12573
+ }
12574
+ case "string": {
12575
+ if (revision === "1" /* Active */) {
12576
+ const byteArray = byteArrayFromString(data);
12577
+ const elements = [
12578
+ byteArray.data.length,
12579
+ ...byteArray.data,
12580
+ byteArray.pending_word,
12581
+ byteArray.pending_word_len
12582
+ ];
12583
+ return [type, revisionConfiguration[revision].hashMethod(elements)];
12584
+ }
12585
+ return [type, getHex(data)];
12586
+ }
12587
+ case "felt":
12588
+ case "bool":
12589
+ case "u128":
12590
+ case "i128":
12591
+ case "ContractAddress":
12592
+ case "ClassHash":
12593
+ case "timestamp":
12594
+ case "shortstring":
12595
+ return [type, getHex(data)];
12596
+ default: {
12597
+ if (revision === "1" /* Active */) {
12598
+ throw new Error(`Unsupported type: ${type}`);
12599
+ }
12600
+ return [type, getHex(data)];
12601
+ }
12602
+ }
12603
+ }
12604
+ function encodeData(types, type, data, revision = "0" /* Legacy */) {
12605
+ const targetType = types[type] ?? revisionConfiguration[revision].presetTypes[type];
12606
+ const [returnTypes, values] = targetType.reduce(
12433
12607
  ([ts, vs], field) => {
12434
- if (data[field.name] === void 0 || data[field.name] === null) {
12608
+ if (data[field.name] === void 0 || data[field.name] === null && field.type !== "enum") {
12435
12609
  throw new Error(`Cannot encode data: missing data for '${field.name}'`);
12436
12610
  }
12437
12611
  const value = data[field.name];
12438
- const [t, encodedValue] = encodeValue(types, field.type, value, {
12439
- parent: type,
12440
- key: field.name
12441
- });
12612
+ const ctx = { parent: type, key: field.name };
12613
+ const [t, encodedValue] = encodeValue(types, field.type, value, ctx, revision);
12442
12614
  return [
12443
12615
  [...ts, t],
12444
12616
  [...vs, encodedValue]
12445
12617
  ];
12446
12618
  },
12447
- [["felt"], [getTypeHash(types, type)]]
12619
+ [["felt"], [getTypeHash(types, type, revision)]]
12448
12620
  );
12449
12621
  return [returnTypes, values];
12450
- };
12451
- var getStructHash = (types, type, data) => {
12452
- return computeHashOnElements2(encodeData(types, type, data)[1]);
12453
- };
12454
- var getMessageHash = (typedData, account) => {
12622
+ }
12623
+ function getStructHash(types, type, data, revision = "0" /* Legacy */) {
12624
+ return revisionConfiguration[revision].hashMethod(encodeData(types, type, data, revision)[1]);
12625
+ }
12626
+ function getMessageHash(typedData, account) {
12455
12627
  if (!validateTypedData(typedData)) {
12456
12628
  throw new Error("Typed data does not match JSON schema");
12457
12629
  }
12630
+ const revision = identifyRevision(typedData);
12631
+ const { domain, hashMethod } = revisionConfiguration[revision];
12458
12632
  const message = [
12459
12633
  encodeShortString("StarkNet Message"),
12460
- getStructHash(typedData.types, "StarkNetDomain", typedData.domain),
12634
+ getStructHash(typedData.types, domain, typedData.domain, revision),
12461
12635
  account,
12462
- getStructHash(typedData.types, typedData.primaryType, typedData.message)
12636
+ getStructHash(typedData.types, typedData.primaryType, typedData.message, revision)
12463
12637
  ];
12464
- return computeHashOnElements2(message);
12465
- };
12638
+ return hashMethod(message);
12639
+ }
12466
12640
 
12467
12641
  // src/signer/default.ts
12468
12642
  var Signer = class {
12643
+ pk;
12469
12644
  constructor(pk = esm_exports.utils.randomPrivateKey()) {
12470
12645
  this.pk = pk instanceof Uint8Array ? buf2hex(pk) : toHex(pk);
12471
12646
  }
@@ -12560,9 +12735,11 @@ ${res.tx_failure_reason.error_message}`;
12560
12735
 
12561
12736
  // src/account/default.ts
12562
12737
  var Account = class extends Provider {
12738
+ signer;
12739
+ address;
12740
+ cairoVersion;
12563
12741
  constructor(providerOrOptions, address, pkOrSigner, cairoVersion) {
12564
12742
  super(providerOrOptions);
12565
- this.deploySelf = this.deployAccount;
12566
12743
  this.address = address.toLowerCase();
12567
12744
  this.signer = typeof pkOrSigner === "string" || pkOrSigner instanceof Uint8Array ? new Signer(pkOrSigner) : pkOrSigner;
12568
12745
  if (cairoVersion) {
@@ -12835,6 +13012,7 @@ ${res.tx_failure_reason.error_message}`;
12835
13012
  );
12836
13013
  return { declare: { ...declare }, deploy };
12837
13014
  }
13015
+ deploySelf = this.deployAccount;
12838
13016
  async deployAccount({
12839
13017
  classHash,
12840
13018
  constructorCalldata = [],
@@ -13198,6 +13376,17 @@ ${res.tx_failure_reason.error_message}`;
13198
13376
  return callback();
13199
13377
  }
13200
13378
  var Contract = class {
13379
+ abi;
13380
+ address;
13381
+ providerOrAccount;
13382
+ deployTransactionHash;
13383
+ structs;
13384
+ events;
13385
+ functions;
13386
+ callStatic;
13387
+ populateTransaction;
13388
+ estimateFee;
13389
+ callData;
13201
13390
  /**
13202
13391
  * Contract class to handle contract methods
13203
13392
  *
@@ -13371,7 +13560,7 @@ ${res.tx_failure_reason.error_message}`;
13371
13560
  async getVersion() {
13372
13561
  return this.providerOrAccount.getContractVersion(this.address);
13373
13562
  }
13374
- typed(tAbi) {
13563
+ typedv1(tAbi) {
13375
13564
  return this;
13376
13565
  }
13377
13566
  typedv2(tAbi) {
@@ -13381,10 +13570,21 @@ ${res.tx_failure_reason.error_message}`;
13381
13570
 
13382
13571
  // src/contract/interface.ts
13383
13572
  var ContractInterface = class {
13573
+ functions;
13574
+ callStatic;
13575
+ populateTransaction;
13576
+ estimateFee;
13384
13577
  };
13385
13578
 
13386
13579
  // src/contract/contractFactory.ts
13387
13580
  var ContractFactory = class {
13581
+ compiledContract;
13582
+ account;
13583
+ abi;
13584
+ classHash;
13585
+ casm;
13586
+ compiledClassHash;
13587
+ CallData;
13388
13588
  /**
13389
13589
  * @param params CFParams
13390
13590
  * - compiledContract: CompiledContract;
@@ -13452,7 +13652,7 @@ ${res.tx_failure_reason.error_message}`;
13452
13652
  attach(address) {
13453
13653
  return new Contract(this.abi, address, this.account);
13454
13654
  }
13455
- // 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
13655
+ // 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
13456
13656
  };
13457
13657
 
13458
13658
  // src/utils/address.ts