starknet 10.0.4 → 10.2.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
@@ -70,7 +70,7 @@ var api_exports = {};
70
70
  __export(api_exports, {
71
71
  JRPC: () => jsonrpc_exports,
72
72
  PAYMASTER_API: () => PAYMASTER_API,
73
- RPCSPEC0101: () => RPCSPEC0101,
73
+ RPCSPEC0103: () => RPCSPEC0103,
74
74
  RPCSPEC09: () => RPCSPEC09
75
75
  });
76
76
 
@@ -79,13 +79,13 @@ var jsonrpc_exports = {};
79
79
 
80
80
  // src/types/api/index.ts
81
81
  import * as RPCSPEC09 from "@starknet-io/starknet-types-09";
82
- import * as RPCSPEC0101 from "@starknet-io/starknet-types-0101";
83
- import { PAYMASTER_API } from "@starknet-io/starknet-types-0101";
82
+ import * as RPCSPEC0103 from "@starknet-io/starknet-types-0103";
83
+ import { PAYMASTER_API } from "@starknet-io/starknet-types-0103";
84
84
 
85
85
  // src/types/api/rpc.ts
86
86
  var rpc_exports = {};
87
- __reExport(rpc_exports, starknet_types_0101_star);
88
- import * as starknet_types_0101_star from "@starknet-io/starknet-types-0101";
87
+ __reExport(rpc_exports, starknet_types_0103_star);
88
+ import * as starknet_types_0103_star from "@starknet-io/starknet-types-0103";
89
89
 
90
90
  // src/types/api/index.ts
91
91
  __reExport(api_exports, rpc_exports);
@@ -94,19 +94,19 @@ __reExport(api_exports, rpc_exports);
94
94
  var { ETransactionVersion } = RPCSPEC09;
95
95
  var { ETransactionVersion2 } = RPCSPEC09;
96
96
  var { ETransactionVersion3 } = RPCSPEC09;
97
- var { EDataAvailabilityMode } = RPCSPEC0101;
98
- var { EDAMode } = RPCSPEC0101;
97
+ var { EDataAvailabilityMode } = RPCSPEC0103;
98
+ var { EDAMode } = RPCSPEC0103;
99
99
  function isRPC08Plus_ResourceBounds(entry) {
100
100
  return "l1_data_gas" in entry;
101
101
  }
102
102
  function isRPC08Plus_ResourceBoundsBN(entry) {
103
103
  return "l1_data_gas" in entry;
104
104
  }
105
- var { ETxnResponseFlag } = RPCSPEC0101;
106
- var { ETraceFlag } = RPCSPEC0101;
107
- var { ESubscriptionTag } = RPCSPEC0101;
108
- var { ETransactionStatus } = RPCSPEC0101;
109
- var { ETransactionExecutionStatus } = RPCSPEC0101;
105
+ var { ETxnResponseFlag } = RPCSPEC0103;
106
+ var { ETraceFlag } = RPCSPEC0103;
107
+ var { ESubscriptionTag } = RPCSPEC0103;
108
+ var { ETransactionStatus } = RPCSPEC0103;
109
+ var { ETransactionExecutionStatus } = RPCSPEC0103;
110
110
  var { ETransactionType: TransactionType } = RPCSPEC09;
111
111
  var { EBlockStatus: BlockStatus } = RPCSPEC09;
112
112
  var { ETransactionFinalityStatus: TransactionFinalityStatus } = RPCSPEC09;
@@ -321,9 +321,11 @@ var _SupportedRpcVersion = {
321
321
  "0.9.0": "0.9.0",
322
322
  "0.10.0": "0.10.0",
323
323
  "0.10.2": "0.10.2",
324
+ "0.10.3": "0.10.3",
324
325
  v0_9_0: "0.9.0",
325
326
  v0_10_0: "0.10.0",
326
- v0_10_2: "0.10.2"
327
+ v0_10_2: "0.10.2",
328
+ v0_10_3: "0.10.3"
327
329
  };
328
330
  var DEFAULT_GLOBAL_CONFIG = {
329
331
  rpcVersion: "0.10.0",
@@ -1849,6 +1851,24 @@ var CairoBytes31 = class _CairoBytes31 {
1849
1851
  }
1850
1852
  };
1851
1853
 
1854
+ // src/utils/ec.ts
1855
+ var ec_exports = {};
1856
+ __export(ec_exports, {
1857
+ starkCurve: () => starkCurve,
1858
+ weierstrass: () => weierstrass
1859
+ });
1860
+ import * as starkCurve from "@scure/starknet";
1861
+ import * as weierstrass from "@noble/curves/abstract/weierstrass";
1862
+
1863
+ // src/utils/hash/pedersenCore.ts
1864
+ function computePedersenHash(a, b) {
1865
+ return starkCurve.pedersen(BigInt(a), BigInt(b));
1866
+ }
1867
+ function computeHashOnElements(data) {
1868
+ return [...data, data.length].reduce((x, y) => starkCurve.pedersen(BigInt(x), BigInt(y)), 0).toString();
1869
+ }
1870
+ var computePedersenHashOnElements = computeHashOnElements;
1871
+
1852
1872
  // src/utils/errors/rpc.ts
1853
1873
  var errorCodes = {
1854
1874
  FAILED_TO_RECEIVE_TXN: 1,
@@ -2143,6 +2163,31 @@ var CairoByteArray = class _CairoByteArray {
2143
2163
  const allBytes = concatenateArrayBuffer(this.toElements());
2144
2164
  return buffer_default.from(allBytes);
2145
2165
  }
2166
+ /**
2167
+ * Compute the Pedersen hash of this ByteArray, following OpenZeppelin's `hash_byte_array` algorithm.
2168
+ *
2169
+ * Serializes the ByteArray to its felt252 components (data array length, each data chunk,
2170
+ * pending_word, pending_word_len), then chains Pedersen hash over all elements starting
2171
+ * from 0, and finalizes with the total element count.
2172
+ *
2173
+ * @returns {string} hex-string felt252 Pedersen hash of the ByteArray
2174
+ * @example
2175
+ * ```typescript
2176
+ * const ba = new CairoByteArray('Hello');
2177
+ * const result = ba.hash();
2178
+ * // result = 0x15d19ad651ffaf8e90a13938db2081fa3ff01de0712e00cbe69891bace66c51
2179
+ * ```
2180
+ */
2181
+ hash() {
2182
+ this.assertInitialized();
2183
+ const serialized = [
2184
+ addHexPrefix(this.data.length.toString(16)),
2185
+ ...this.data.flatMap((bytes31) => bytes31.toApiRequest()),
2186
+ ...this.pending_word.toApiRequest(),
2187
+ ...this.pending_word_len.toApiRequest()
2188
+ ];
2189
+ return computeHashOnElements(serialized);
2190
+ }
2146
2191
  /**
2147
2192
  * returns an array of all the data chunks and the pending word
2148
2193
  * when concatenated, represents the original bytes sequence
@@ -4703,7 +4748,7 @@ __export(hash_exports, {
4703
4748
  computeCompiledClassHashBlake: () => computeCompiledClassHashBlake,
4704
4749
  computeCompiledClassHashPoseidon: () => computeCompiledClassHashPoseidon,
4705
4750
  computeContractClassHash: () => computeContractClassHash,
4706
- computeHashOnElements: () => computeHashOnElements2,
4751
+ computeHashOnElements: () => computeHashOnElements,
4707
4752
  computeHintedClassHash: () => computeHintedClassHash,
4708
4753
  computeLegacyContractClassHash: () => computeLegacyContractClassHash,
4709
4754
  computePedersenHash: () => computePedersenHash,
@@ -4843,24 +4888,13 @@ __export(v2_exports, {
4843
4888
  calculateL2MessageTxHash: () => calculateL2MessageTxHash,
4844
4889
  calculateTransactionHash: () => calculateTransactionHash,
4845
4890
  calculateTransactionHashCommon: () => calculateTransactionHashCommon2,
4846
- computeHashOnElements: () => computeHashOnElements
4891
+ computeHashOnElements: () => computeHashOnElements2
4847
4892
  });
4848
-
4849
- // src/utils/ec.ts
4850
- var ec_exports = {};
4851
- __export(ec_exports, {
4852
- starkCurve: () => starkCurve,
4853
- weierstrass: () => weierstrass
4854
- });
4855
- import * as starkCurve from "@scure/starknet";
4856
- import * as weierstrass from "@noble/curves/abstract/weierstrass";
4857
-
4858
- // src/utils/hash/transactionHash/v2.ts
4859
- function computeHashOnElements(data) {
4893
+ function computeHashOnElements2(data) {
4860
4894
  return [...data, data.length].reduce((x, y) => starkCurve.pedersen(toBigInt(x), toBigInt(y)), 0).toString();
4861
4895
  }
4862
4896
  function calculateTransactionHashCommon2(txHashPrefix, version, contractAddress, entryPointSelector, calldata, maxFee, chainId, additionalData = []) {
4863
- const calldataHash = computeHashOnElements(calldata);
4897
+ const calldataHash = computeHashOnElements2(calldata);
4864
4898
  const dataToHash = [
4865
4899
  txHashPrefix,
4866
4900
  version,
@@ -4871,7 +4905,7 @@ function calculateTransactionHashCommon2(txHashPrefix, version, contractAddress,
4871
4905
  chainId,
4872
4906
  ...additionalData
4873
4907
  ];
4874
- return computeHashOnElements(dataToHash);
4908
+ return computeHashOnElements2(dataToHash);
4875
4909
  }
4876
4910
  function calculateDeclareTransactionHash2(classHash, senderAddress, version, maxFee, chainId, nonce, compiledClassHash) {
4877
4911
  return calculateTransactionHashCommon2(
@@ -5030,18 +5064,11 @@ function flattenEntryPointData(data, encodedBuiltinsArray) {
5030
5064
  }
5031
5065
 
5032
5066
  // src/utils/hash/classHash/pedersen.ts
5033
- function computePedersenHash(a, b) {
5034
- return starkCurve.pedersen(BigInt(a), BigInt(b));
5035
- }
5036
- function computeHashOnElements2(data) {
5037
- return [...data, data.length].reduce((x, y) => starkCurve.pedersen(BigInt(x), BigInt(y)), 0).toString();
5038
- }
5039
- var computePedersenHashOnElements = computeHashOnElements2;
5040
5067
  function calculateContractAddressFromHash(salt, classHash, constructorCalldata, deployerAddress) {
5041
5068
  const compiledCalldata = CallData.compile(constructorCalldata);
5042
- const constructorCalldataHash = computeHashOnElements2(compiledCalldata);
5069
+ const constructorCalldataHash = computeHashOnElements(compiledCalldata);
5043
5070
  const CONTRACT_ADDRESS_PREFIX = felt("0x535441524b4e45545f434f4e54524143545f41444452455353");
5044
- const hash = computeHashOnElements2([
5071
+ const hash = computeHashOnElements([
5045
5072
  CONTRACT_ADDRESS_PREFIX,
5046
5073
  deployerAddress,
5047
5074
  salt,
@@ -5059,21 +5086,21 @@ function computeHintedClassHash(compiledContract) {
5059
5086
  function computeLegacyContractClassHash(contract) {
5060
5087
  const compiledContract = isString(contract) ? parse2(contract) : contract;
5061
5088
  const apiVersion = toHex(API_VERSION);
5062
- const externalEntryPointsHash = computeHashOnElements2(
5089
+ const externalEntryPointsHash = computeHashOnElements(
5063
5090
  compiledContract.entry_points_by_type.EXTERNAL.flatMap((e) => [e.selector, e.offset])
5064
5091
  );
5065
- const l1HandlerEntryPointsHash = computeHashOnElements2(
5092
+ const l1HandlerEntryPointsHash = computeHashOnElements(
5066
5093
  compiledContract.entry_points_by_type.L1_HANDLER.flatMap((e) => [e.selector, e.offset])
5067
5094
  );
5068
- const constructorEntryPointHash = computeHashOnElements2(
5095
+ const constructorEntryPointHash = computeHashOnElements(
5069
5096
  compiledContract.entry_points_by_type.CONSTRUCTOR.flatMap((e) => [e.selector, e.offset])
5070
5097
  );
5071
- const builtinsHash = computeHashOnElements2(
5098
+ const builtinsHash = computeHashOnElements(
5072
5099
  compiledContract.program.builtins.map((s) => encodeShortString(s))
5073
5100
  );
5074
5101
  const hintedClassHash = computeHintedClassHash(compiledContract);
5075
- const dataHash = computeHashOnElements2(compiledContract.program.data);
5076
- return computeHashOnElements2([
5102
+ const dataHash = computeHashOnElements(compiledContract.program.data);
5103
+ return computeHashOnElements([
5077
5104
  apiVersion,
5078
5105
  externalEntryPointsHash,
5079
5106
  l1HandlerEntryPointsHash,
@@ -6549,6 +6576,7 @@ var rpc_0_10_2_exports = {};
6549
6576
  __export(rpc_0_10_2_exports, {
6550
6577
  RpcChannel: () => RpcChannel2
6551
6578
  });
6579
+ import * as RPC from "@starknet-io/starknet-types-0101";
6552
6580
  var RpcChannel2 = class {
6553
6581
  id = "RPC0.10.2";
6554
6582
  /**
@@ -6768,7 +6796,7 @@ var RpcChannel2 = class {
6768
6796
  */
6769
6797
  getBlockWithTxs(blockIdentifier = this.blockIdentifier, options) {
6770
6798
  const block_id = new Block(blockIdentifier).identifier;
6771
- const response_flags = options?.includeProofFacts ? [RPCSPEC0101.ETxnResponseFlag.INCLUDE_PROOF_FACTS] : void 0;
6799
+ const response_flags = options?.includeProofFacts ? [RPC.ETxnResponseFlag.INCLUDE_PROOF_FACTS] : void 0;
6772
6800
  return this.fetchEndpoint("starknet_getBlockWithTxs", {
6773
6801
  block_id,
6774
6802
  ...response_flags && { response_flags }
@@ -6782,7 +6810,7 @@ var RpcChannel2 = class {
6782
6810
  */
6783
6811
  getBlockWithReceipts(blockIdentifier = this.blockIdentifier, options) {
6784
6812
  const block_id = new Block(blockIdentifier).identifier;
6785
- const response_flags = options?.includeProofFacts ? [RPCSPEC0101.ETxnResponseFlag.INCLUDE_PROOF_FACTS] : void 0;
6813
+ const response_flags = options?.includeProofFacts ? [RPC.ETxnResponseFlag.INCLUDE_PROOF_FACTS] : void 0;
6786
6814
  return this.fetchEndpoint("starknet_getBlockWithReceipts", {
6787
6815
  block_id,
6788
6816
  ...response_flags && { response_flags }
@@ -6805,7 +6833,7 @@ var RpcChannel2 = class {
6805
6833
  */
6806
6834
  getBlockTransactionsTraces(blockIdentifier = this.blockIdentifier, options) {
6807
6835
  const block_id = new Block(blockIdentifier).identifier;
6808
- const trace_flags = options?.returnInitialReads ? [RPCSPEC0101.ETraceFlag.RETURN_INITIAL_READS] : void 0;
6836
+ const trace_flags = options?.returnInitialReads ? [RPC.ETraceFlag.RETURN_INITIAL_READS] : void 0;
6809
6837
  return this.fetchEndpoint("starknet_traceBlockTransactions", {
6810
6838
  block_id,
6811
6839
  ...trace_flags && { trace_flags }
@@ -6823,7 +6851,7 @@ var RpcChannel2 = class {
6823
6851
  */
6824
6852
  getTransactionByHash(txHash, options) {
6825
6853
  const transaction_hash = toHex(txHash);
6826
- const response_flags = options?.includeProofFacts ? [RPCSPEC0101.ETxnResponseFlag.INCLUDE_PROOF_FACTS] : void 0;
6854
+ const response_flags = options?.includeProofFacts ? [RPC.ETxnResponseFlag.INCLUDE_PROOF_FACTS] : void 0;
6827
6855
  return this.fetchEndpoint("starknet_getTransactionByHash", {
6828
6856
  transaction_hash,
6829
6857
  ...response_flags && { response_flags }
@@ -6838,7 +6866,7 @@ var RpcChannel2 = class {
6838
6866
  */
6839
6867
  getTransactionByBlockIdAndIndex(blockIdentifier, index, options) {
6840
6868
  const block_id = new Block(blockIdentifier).identifier;
6841
- const response_flags = options?.includeProofFacts ? [RPCSPEC0101.ETxnResponseFlag.INCLUDE_PROOF_FACTS] : void 0;
6869
+ const response_flags = options?.includeProofFacts ? [RPC.ETxnResponseFlag.INCLUDE_PROOF_FACTS] : void 0;
6842
6870
  return this.fetchEndpoint("starknet_getTransactionByBlockIdAndIndex", {
6843
6871
  block_id,
6844
6872
  index,
@@ -6879,9 +6907,9 @@ var RpcChannel2 = class {
6879
6907
  } = simulateTransactionOptions;
6880
6908
  const block_id = new Block(blockIdentifier).identifier;
6881
6909
  const simulationFlags = [];
6882
- if (skipValidate) simulationFlags.push(RPCSPEC0101.ESimulationFlag.SKIP_VALIDATE);
6883
- if (skipFeeCharge) simulationFlags.push(RPCSPEC0101.ESimulationFlag.SKIP_FEE_CHARGE);
6884
- const trace_flags = returnInitialReads ? [RPCSPEC0101.ETraceFlag.RETURN_INITIAL_READS] : void 0;
6910
+ if (skipValidate) simulationFlags.push(RPC.ESimulationFlag.SKIP_VALIDATE);
6911
+ if (skipFeeCharge) simulationFlags.push(RPC.ESimulationFlag.SKIP_FEE_CHARGE);
6912
+ const trace_flags = returnInitialReads ? [RPC.ETraceFlag.RETURN_INITIAL_READS] : void 0;
6885
6913
  return this.fetchEndpoint("starknet_simulateTransactions", {
6886
6914
  block_id,
6887
6915
  transactions: await Promise.all(invocations.map((it) => this.buildTransaction(it))),
@@ -6899,13 +6927,13 @@ var RpcChannel2 = class {
6899
6927
  const errorStates = options?.errorStates ?? [];
6900
6928
  const successStates = options?.successStates ?? [
6901
6929
  // RPC.ETransactionExecutionStatus.SUCCEEDED, // UDC on SUCCEEDED + pre_confirmed had no proper events to parse UDC
6902
- RPCSPEC0101.ETransactionFinalityStatus.ACCEPTED_ON_L2,
6903
- RPCSPEC0101.ETransactionFinalityStatus.ACCEPTED_ON_L1
6930
+ RPC.ETransactionFinalityStatus.ACCEPTED_ON_L2,
6931
+ RPC.ETransactionFinalityStatus.ACCEPTED_ON_L1
6904
6932
  ];
6905
6933
  const errorMessages = {
6906
- [RPCSPEC0101.ETransactionStatus.RECEIVED]: SYSTEM_MESSAGES.txEvictedFromMempool,
6907
- [RPCSPEC0101.ETransactionStatus.PRE_CONFIRMED]: SYSTEM_MESSAGES.consensusFailed,
6908
- [RPCSPEC0101.ETransactionStatus.CANDIDATE]: SYSTEM_MESSAGES.txFailsBlockBuildingValidation
6934
+ [RPC.ETransactionStatus.RECEIVED]: SYSTEM_MESSAGES.txEvictedFromMempool,
6935
+ [RPC.ETransactionStatus.PRE_CONFIRMED]: SYSTEM_MESSAGES.consensusFailed,
6936
+ [RPC.ETransactionStatus.CANDIDATE]: SYSTEM_MESSAGES.txFailsBlockBuildingValidation
6909
6937
  };
6910
6938
  const txLife = [];
6911
6939
  let txStatus;
@@ -7002,7 +7030,7 @@ var RpcChannel2 = class {
7002
7030
  const { blockIdentifier = this.blockIdentifier, skipValidate = methodDefaults.skipValidate } = options;
7003
7031
  const block_id = new Block(blockIdentifier).identifier;
7004
7032
  const flags = {
7005
- simulation_flags: skipValidate ? [RPCSPEC0101.ESimulationFlag.SKIP_VALIDATE] : []
7033
+ simulation_flags: skipValidate ? [RPC.ESimulationFlag.SKIP_VALIDATE] : []
7006
7034
  };
7007
7035
  return this.fetchEndpoint("starknet_estimateFee", {
7008
7036
  request: await Promise.all(invocations.map((it) => this.buildTransaction(it, "fee"))),
@@ -7116,7 +7144,7 @@ var RpcChannel2 = class {
7116
7144
  };
7117
7145
  if (invocation.type === api_exports.ETransactionType.INVOKE) {
7118
7146
  const btx = {
7119
- type: RPCSPEC0101.ETransactionType.INVOKE,
7147
+ type: RPC.ETransactionType.INVOKE,
7120
7148
  sender_address: invocation.contractAddress,
7121
7149
  calldata: CallData.toHex(invocation.calldata),
7122
7150
  ...details,
@@ -7158,6 +7186,16 @@ var RpcChannel2 = class {
7158
7186
  }
7159
7187
  };
7160
7188
 
7189
+ // src/channel/rpc_0_10_3.ts
7190
+ var rpc_0_10_3_exports = {};
7191
+ __export(rpc_0_10_3_exports, {
7192
+ RpcChannel: () => RpcChannel3
7193
+ });
7194
+ var RpcChannel3 = class extends RpcChannel2 {
7195
+ id = "RPC0.10.3";
7196
+ channelSpecVersion = _SupportedRpcVersion.v0_10_3;
7197
+ };
7198
+
7161
7199
  // src/utils/eventEmitter.ts
7162
7200
  var EventEmitter = class {
7163
7201
  listeners = {};
@@ -9429,12 +9467,12 @@ var RpcProvider = class {
9429
9467
  if (isVersion("0.9", options.specVersion)) {
9430
9468
  this.channel = new rpc_0_9_0_exports.RpcChannel({ ...options, waitMode: false });
9431
9469
  } else if (isVersion("0.10", options.specVersion)) {
9432
- this.channel = new rpc_0_10_2_exports.RpcChannel({ ...options, waitMode: false });
9470
+ this.channel = new rpc_0_10_3_exports.RpcChannel({ ...options, waitMode: false });
9433
9471
  } else throw new Error(`unsupported channel for spec version: ${options.specVersion}`);
9434
9472
  } else if (isVersion("0.9", config.get("rpcVersion"))) {
9435
9473
  this.channel = new rpc_0_9_0_exports.RpcChannel({ ...options, waitMode: false });
9436
9474
  } else if (isVersion("0.10", config.get("rpcVersion"))) {
9437
- this.channel = new rpc_0_10_2_exports.RpcChannel({ ...options, waitMode: false });
9475
+ this.channel = new rpc_0_10_3_exports.RpcChannel({ ...options, waitMode: false });
9438
9476
  } else throw new Error("unable to define spec version for channel");
9439
9477
  this.responseParser = new RPCResponseParser(options?.resourceBoundsOverhead);
9440
9478
  const plugins = options?.plugins === false ? [] : options?.plugins ?? defaultPlugins;
@@ -9463,7 +9501,7 @@ var RpcProvider = class {
9463
9501
  if (isVersion("0.10", spec)) {
9464
9502
  return new this({
9465
9503
  ...optionsOrProvider,
9466
- specVersion: _SupportedRpcVersion.v0_10_2
9504
+ specVersion: _SupportedRpcVersion.v0_10_3
9467
9505
  });
9468
9506
  }
9469
9507
  throw new LibraryError(
@@ -13244,12 +13282,13 @@ export {
13244
13282
  RpcProvider as Provider,
13245
13283
  ProviderInterface,
13246
13284
  api_exports as RPC,
13247
- rpc_0_10_2_exports as RPC0101,
13285
+ rpc_0_10_2_exports as RPC0102,
13286
+ rpc_0_10_3_exports as RPC0103,
13248
13287
  rpc_0_9_0_exports as RPC09,
13249
13288
  RPCResponseParser,
13250
13289
  ReceiptTx,
13251
13290
  ResponseParser,
13252
- RpcChannel2 as RpcChannel,
13291
+ RpcChannel3 as RpcChannel,
13253
13292
  RpcError,
13254
13293
  RpcProvider,
13255
13294
  Signer,