starknet 8.5.4 → 8.6.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.
@@ -118,6 +118,7 @@ var starknet = (() => {
118
118
  addAddressPadding: () => addAddressPadding,
119
119
  byteArray: () => byteArray_exports,
120
120
  cairo: () => cairo_exports,
121
+ compareVersions: () => compareVersions,
121
122
  config: () => config,
122
123
  constants: () => constants_exports,
123
124
  contractClassResponseToLegacyCompiledContract: () => contractClassResponseToLegacyCompiledContract,
@@ -989,7 +990,7 @@ var starknet = (() => {
989
990
  return buffer.reduce((r, x) => r + x.toString(16).padStart(2, "0"), "");
990
991
  }
991
992
  function removeHexPrefix(hex) {
992
- return hex.replace(/^0x/i, "");
993
+ return hex.startsWith("0x") || hex.startsWith("0X") ? hex.slice(2) : hex;
993
994
  }
994
995
  function addHexPrefix(hex) {
995
996
  return `0x${removeHexPrefix(hex)}`;
@@ -1031,11 +1032,10 @@ var starknet = (() => {
1031
1032
  return result;
1032
1033
  }
1033
1034
  function hexStringToUint8Array(hex) {
1034
- const cleanHex2 = hex.startsWith("0x") ? hex.slice(2) : hex;
1035
- if (cleanHex2.length > 0 && !/^[0-9a-fA-F]+$/.test(cleanHex2)) {
1036
- throw new Error(`Invalid hex string: "${hex}" contains non-hexadecimal characters`);
1035
+ if (!isHexString(addHexPrefix(hex))) {
1036
+ throw new Error(`Invalid hex string: "${hex}"`);
1037
1037
  }
1038
- const paddedHex = cleanHex2.length % 2 !== 0 ? `0${cleanHex2}` : cleanHex2;
1038
+ const paddedHex = removeHexPrefix(sanitizeHex(hex));
1039
1039
  const bytes = new Uint8Array(paddedHex.length / 2);
1040
1040
  for (let i = 0; i < paddedHex.length; i += 2) {
1041
1041
  bytes[i / 2] = parseInt(paddedHex.substring(i, i + 2), 16);
@@ -1175,7 +1175,8 @@ var starknet = (() => {
1175
1175
  defaultTipType: "recommendedTip",
1176
1176
  fetch: void 0,
1177
1177
  websocket: void 0,
1178
- buffer: void 0
1178
+ buffer: void 0,
1179
+ blake: void 0
1179
1180
  };
1180
1181
  var RPC_DEFAULT_NODES = {
1181
1182
  SN_MAIN: [`https://starknet-mainnet.public.blastapi.io/rpc/`],
@@ -2513,6 +2514,7 @@ ${indent}}` : "}";
2513
2514
  var rotr = (word, shift) => word << 32 - shift | word >>> shift;
2514
2515
  var isLE = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68)();
2515
2516
  var byteSwap = (word) => word << 24 & 4278190080 | word << 8 & 16711680 | word >>> 8 & 65280 | word >>> 24 & 255;
2517
+ var byteSwapIfBE = isLE ? (n) => n : (n) => byteSwap(n);
2516
2518
  function byteSwap32(arr) {
2517
2519
  for (let i = 0; i < arr.length; i++) {
2518
2520
  arr[i] = byteSwap(arr[i]);
@@ -2543,6 +2545,14 @@ ${indent}}` : "}";
2543
2545
  hashC.create = () => hashCons();
2544
2546
  return hashC;
2545
2547
  }
2548
+ function wrapConstructorWithOpts(hashCons) {
2549
+ const hashC = (msg, opts) => hashCons(opts).update(toBytes(msg)).digest();
2550
+ const tmp = hashCons({});
2551
+ hashC.outputLen = tmp.outputLen;
2552
+ hashC.blockLen = tmp.blockLen;
2553
+ hashC.create = (opts) => hashCons(opts);
2554
+ return hashC;
2555
+ }
2546
2556
  function wrapXOFConstructorWithOpts(hashCons) {
2547
2557
  const hashC = (msg, opts) => hashCons(opts).update(toBytes(msg)).digest();
2548
2558
  const tmp = hashCons({});
@@ -2845,6 +2855,9 @@ ${indent}}` : "}";
2845
2855
  return addHexPrefix(toBigInt(value).toString(16));
2846
2856
  }
2847
2857
  var toHexString = toHex;
2858
+ function cleanHex(hex) {
2859
+ return toHex(hex);
2860
+ }
2848
2861
  function toStorageKey(number) {
2849
2862
  return addHexPrefix(toBigInt(number).toString(16).padStart(64, "0"));
2850
2863
  }
@@ -2856,9 +2869,6 @@ ${indent}}` : "}";
2856
2869
  function hexToDecimalString(hex) {
2857
2870
  return BigInt(addHexPrefix(hex)).toString(10);
2858
2871
  }
2859
- function cleanHex(hex) {
2860
- return hex.toLowerCase().replace(/^(0x)0+/, "$1");
2861
- }
2862
2872
  function assertInRange(input, lowerBound, upperBound, inputName = "") {
2863
2873
  const messageSuffix = inputName === "" ? "invalid length" : `invalid ${inputName} length`;
2864
2874
  const inputBigInt = BigInt(input);
@@ -8913,12 +8923,16 @@ ${indent}}` : "}";
8913
8923
  // src/utils/hash/index.ts
8914
8924
  var hash_exports = {};
8915
8925
  __export(hash_exports, {
8926
+ COMPILED_CLASS_VERSION: () => COMPILED_CLASS_VERSION,
8927
+ blake2sHashMany: () => blake2sHashMany,
8916
8928
  calculateContractAddressFromHash: () => calculateContractAddressFromHash,
8917
8929
  calculateDeclareTransactionHash: () => calculateDeclareTransactionHash3,
8918
8930
  calculateDeployAccountTransactionHash: () => calculateDeployAccountTransactionHash3,
8919
8931
  calculateInvokeTransactionHash: () => calculateInvokeTransactionHash2,
8920
8932
  calculateL2MessageTxHash: () => calculateL2MessageTxHash,
8921
8933
  computeCompiledClassHash: () => computeCompiledClassHash,
8934
+ computeCompiledClassHashBlake: () => computeCompiledClassHashBlake,
8935
+ computeCompiledClassHashPoseidon: () => computeCompiledClassHashPoseidon,
8922
8936
  computeContractClassHash: () => computeContractClassHash,
8923
8937
  computeHashOnElements: () => computeHashOnElements3,
8924
8938
  computeHintedClassHash: () => computeHintedClassHash,
@@ -8928,13 +8942,17 @@ ${indent}}` : "}";
8928
8942
  computePoseidonHash: () => computePoseidonHash,
8929
8943
  computePoseidonHashOnElements: () => computePoseidonHashOnElements,
8930
8944
  computeSierraContractClassHash: () => computeSierraContractClassHash,
8945
+ encodeBuiltins: () => encodeBuiltins,
8946
+ flattenEntryPointData: () => flattenEntryPointData,
8931
8947
  formatSpaces: () => formatSpaces,
8932
8948
  getL1MessageHash: () => getL1MessageHash,
8933
8949
  getL2MessageHash: () => getL2MessageHash,
8934
8950
  getSelector: () => getSelector,
8935
8951
  getSelectorFromName: () => getSelectorFromName,
8936
8952
  hashByteCodeSegments: () => hashByteCodeSegments,
8953
+ hashByteCodeSegmentsBlake: () => hashByteCodeSegmentsBlake,
8937
8954
  keccakBn: () => keccakBn,
8955
+ nullSkipReplacer: () => nullSkipReplacer,
8938
8956
  poseidon: () => poseidon_exports,
8939
8957
  solidityUint256PackedKeccak256: () => solidityUint256PackedKeccak256,
8940
8958
  starknetKeccak: () => starknetKeccak
@@ -9195,20 +9213,51 @@ ${indent}}` : "}";
9195
9213
  throw new Error("Invalid Tx version for hash calculation");
9196
9214
  }
9197
9215
 
9198
- // src/utils/hash/classHash.ts
9216
+ // src/utils/hash/classHash/util.ts
9217
+ var COMPILED_CLASS_VERSION = "COMPILED_CLASS_V1";
9218
+ function formatSpaces(json) {
9219
+ let insideQuotes = false;
9220
+ const newString = [];
9221
+ for (const char of json) {
9222
+ if (char === '"' && (newString.length > 0 && newString.slice(-1)[0] === "\\") === false) {
9223
+ insideQuotes = !insideQuotes;
9224
+ }
9225
+ if (insideQuotes) {
9226
+ newString.push(char);
9227
+ } else {
9228
+ newString.push(char === ":" ? ": " : char === "," ? ", " : char);
9229
+ }
9230
+ }
9231
+ return newString.join("");
9232
+ }
9233
+ function nullSkipReplacer(key, value) {
9234
+ if (key === "attributes" || key === "accessible_scopes") {
9235
+ return Array.isArray(value) && value.length === 0 ? void 0 : value;
9236
+ }
9237
+ if (key === "debug_info") {
9238
+ return null;
9239
+ }
9240
+ return value === null ? void 0 : value;
9241
+ }
9242
+ function encodeBuiltins(builtins) {
9243
+ return builtins.map((it) => BigInt(encodeShortString(it)));
9244
+ }
9245
+ function flattenEntryPointData(data, encodedBuiltinsArray) {
9246
+ return data.flatMap((it, index) => [
9247
+ BigInt(it.selector),
9248
+ BigInt(it.offset),
9249
+ ...encodedBuiltinsArray[index]
9250
+ ]);
9251
+ }
9252
+
9253
+ // src/utils/hash/classHash/pedersen.ts
9199
9254
  function computePedersenHash(a, b) {
9200
9255
  return esm_exports4.pedersen(BigInt(a), BigInt(b));
9201
9256
  }
9202
- function computePoseidonHash(a, b) {
9203
- return toHex(esm_exports4.poseidonHash(BigInt(a), BigInt(b)));
9204
- }
9205
9257
  function computeHashOnElements3(data) {
9206
9258
  return [...data, data.length].reduce((x, y) => esm_exports4.pedersen(BigInt(x), BigInt(y)), 0).toString();
9207
9259
  }
9208
9260
  var computePedersenHashOnElements = computeHashOnElements3;
9209
- function computePoseidonHashOnElements(data) {
9210
- return toHex(poseidonHashMany(data.map((x) => BigInt(x))));
9211
- }
9212
9261
  function calculateContractAddressFromHash(salt, classHash, constructorCalldata, deployerAddress) {
9213
9262
  const compiledCalldata = CallData.compile(constructorCalldata);
9214
9263
  const constructorCalldataHash = computeHashOnElements3(compiledCalldata);
@@ -9222,30 +9271,6 @@ ${indent}}` : "}";
9222
9271
  ]);
9223
9272
  return toHex(BigInt(hash) % ADDR_BOUND);
9224
9273
  }
9225
- function nullSkipReplacer(key, value) {
9226
- if (key === "attributes" || key === "accessible_scopes") {
9227
- return Array.isArray(value) && value.length === 0 ? void 0 : value;
9228
- }
9229
- if (key === "debug_info") {
9230
- return null;
9231
- }
9232
- return value === null ? void 0 : value;
9233
- }
9234
- function formatSpaces(json) {
9235
- let insideQuotes = false;
9236
- const newString = [];
9237
- for (const char of json) {
9238
- if (char === '"' && (newString.length > 0 && newString.slice(-1)[0] === "\\") === false) {
9239
- insideQuotes = !insideQuotes;
9240
- }
9241
- if (insideQuotes) {
9242
- newString.push(char);
9243
- } else {
9244
- newString.push(char === ":" ? ": " : char === "," ? ", " : char);
9245
- }
9246
- }
9247
- return newString.join("");
9248
- }
9249
9274
  function computeHintedClassHash(compiledContract) {
9250
9275
  const { abi, program } = compiledContract;
9251
9276
  const contractClass = { abi, program };
@@ -9279,12 +9304,16 @@ ${indent}}` : "}";
9279
9304
  dataHash
9280
9305
  ]);
9281
9306
  }
9307
+
9308
+ // src/utils/hash/classHash/poseidon.ts
9309
+ function computePoseidonHash(a, b) {
9310
+ return toHex(esm_exports4.poseidonHash(BigInt(a), BigInt(b)));
9311
+ }
9312
+ function computePoseidonHashOnElements(data) {
9313
+ return toHex(poseidonHashMany(data.map((x) => BigInt(x))));
9314
+ }
9282
9315
  function hashBuiltins(builtins) {
9283
- return poseidonHashMany(
9284
- builtins.flatMap((it) => {
9285
- return BigInt(encodeShortString(it));
9286
- })
9287
- );
9316
+ return poseidonHashMany(encodeBuiltins(builtins));
9288
9317
  }
9289
9318
  function hashEntryPoint(data) {
9290
9319
  const base = data.flatMap((it) => {
@@ -9302,8 +9331,7 @@ ${indent}}` : "}";
9302
9331
  });
9303
9332
  return 1n + poseidonHashMany(hashLeaves);
9304
9333
  }
9305
- function computeCompiledClassHash(casm) {
9306
- const COMPILED_CLASS_VERSION = "COMPILED_CLASS_V1";
9334
+ function computeCompiledClassHashPoseidon(casm) {
9307
9335
  const compiledClassVersion = BigInt(encodeShortString(COMPILED_CLASS_VERSION));
9308
9336
  const externalEntryPointsHash = hashEntryPoint(casm.entry_points_by_type.EXTERNAL);
9309
9337
  const l1Handlers = hashEntryPoint(casm.entry_points_by_type.L1_HANDLER);
@@ -9348,6 +9376,561 @@ ${indent}}` : "}";
9348
9376
  ])
9349
9377
  );
9350
9378
  }
9379
+
9380
+ // node_modules/@noble/hashes/esm/_blake.js
9381
+ var SIGMA = /* @__PURE__ */ new Uint8Array([
9382
+ 0,
9383
+ 1,
9384
+ 2,
9385
+ 3,
9386
+ 4,
9387
+ 5,
9388
+ 6,
9389
+ 7,
9390
+ 8,
9391
+ 9,
9392
+ 10,
9393
+ 11,
9394
+ 12,
9395
+ 13,
9396
+ 14,
9397
+ 15,
9398
+ 14,
9399
+ 10,
9400
+ 4,
9401
+ 8,
9402
+ 9,
9403
+ 15,
9404
+ 13,
9405
+ 6,
9406
+ 1,
9407
+ 12,
9408
+ 0,
9409
+ 2,
9410
+ 11,
9411
+ 7,
9412
+ 5,
9413
+ 3,
9414
+ 11,
9415
+ 8,
9416
+ 12,
9417
+ 0,
9418
+ 5,
9419
+ 2,
9420
+ 15,
9421
+ 13,
9422
+ 10,
9423
+ 14,
9424
+ 3,
9425
+ 6,
9426
+ 7,
9427
+ 1,
9428
+ 9,
9429
+ 4,
9430
+ 7,
9431
+ 9,
9432
+ 3,
9433
+ 1,
9434
+ 13,
9435
+ 12,
9436
+ 11,
9437
+ 14,
9438
+ 2,
9439
+ 6,
9440
+ 5,
9441
+ 10,
9442
+ 4,
9443
+ 0,
9444
+ 15,
9445
+ 8,
9446
+ 9,
9447
+ 0,
9448
+ 5,
9449
+ 7,
9450
+ 2,
9451
+ 4,
9452
+ 10,
9453
+ 15,
9454
+ 14,
9455
+ 1,
9456
+ 11,
9457
+ 12,
9458
+ 6,
9459
+ 8,
9460
+ 3,
9461
+ 13,
9462
+ 2,
9463
+ 12,
9464
+ 6,
9465
+ 10,
9466
+ 0,
9467
+ 11,
9468
+ 8,
9469
+ 3,
9470
+ 4,
9471
+ 13,
9472
+ 7,
9473
+ 5,
9474
+ 15,
9475
+ 14,
9476
+ 1,
9477
+ 9,
9478
+ 12,
9479
+ 5,
9480
+ 1,
9481
+ 15,
9482
+ 14,
9483
+ 13,
9484
+ 4,
9485
+ 10,
9486
+ 0,
9487
+ 7,
9488
+ 6,
9489
+ 3,
9490
+ 9,
9491
+ 2,
9492
+ 8,
9493
+ 11,
9494
+ 13,
9495
+ 11,
9496
+ 7,
9497
+ 14,
9498
+ 12,
9499
+ 1,
9500
+ 3,
9501
+ 9,
9502
+ 5,
9503
+ 0,
9504
+ 15,
9505
+ 4,
9506
+ 8,
9507
+ 6,
9508
+ 2,
9509
+ 10,
9510
+ 6,
9511
+ 15,
9512
+ 14,
9513
+ 9,
9514
+ 11,
9515
+ 3,
9516
+ 0,
9517
+ 8,
9518
+ 12,
9519
+ 2,
9520
+ 13,
9521
+ 7,
9522
+ 1,
9523
+ 4,
9524
+ 10,
9525
+ 5,
9526
+ 10,
9527
+ 2,
9528
+ 8,
9529
+ 4,
9530
+ 7,
9531
+ 6,
9532
+ 1,
9533
+ 5,
9534
+ 15,
9535
+ 11,
9536
+ 9,
9537
+ 14,
9538
+ 3,
9539
+ 12,
9540
+ 13,
9541
+ 0,
9542
+ 0,
9543
+ 1,
9544
+ 2,
9545
+ 3,
9546
+ 4,
9547
+ 5,
9548
+ 6,
9549
+ 7,
9550
+ 8,
9551
+ 9,
9552
+ 10,
9553
+ 11,
9554
+ 12,
9555
+ 13,
9556
+ 14,
9557
+ 15,
9558
+ 14,
9559
+ 10,
9560
+ 4,
9561
+ 8,
9562
+ 9,
9563
+ 15,
9564
+ 13,
9565
+ 6,
9566
+ 1,
9567
+ 12,
9568
+ 0,
9569
+ 2,
9570
+ 11,
9571
+ 7,
9572
+ 5,
9573
+ 3
9574
+ ]);
9575
+ var BLAKE = class extends Hash {
9576
+ constructor(blockLen, outputLen, opts = {}, keyLen, saltLen, persLen) {
9577
+ super();
9578
+ this.blockLen = blockLen;
9579
+ this.outputLen = outputLen;
9580
+ this.length = 0;
9581
+ this.pos = 0;
9582
+ this.finished = false;
9583
+ this.destroyed = false;
9584
+ anumber2(blockLen);
9585
+ anumber2(outputLen);
9586
+ anumber2(keyLen);
9587
+ if (outputLen < 0 || outputLen > keyLen)
9588
+ throw new Error("outputLen bigger than keyLen");
9589
+ if (opts.key !== void 0 && (opts.key.length < 1 || opts.key.length > keyLen))
9590
+ throw new Error("key length must be undefined or 1.." + keyLen);
9591
+ if (opts.salt !== void 0 && opts.salt.length !== saltLen)
9592
+ throw new Error("salt must be undefined or " + saltLen);
9593
+ if (opts.personalization !== void 0 && opts.personalization.length !== persLen)
9594
+ throw new Error("personalization must be undefined or " + persLen);
9595
+ this.buffer = new Uint8Array(blockLen);
9596
+ this.buffer32 = u32(this.buffer);
9597
+ }
9598
+ update(data) {
9599
+ aexists(this);
9600
+ const { blockLen, buffer, buffer32 } = this;
9601
+ data = toBytes(data);
9602
+ const len = data.length;
9603
+ const offset = data.byteOffset;
9604
+ const buf = data.buffer;
9605
+ for (let pos = 0; pos < len; ) {
9606
+ if (this.pos === blockLen) {
9607
+ if (!isLE)
9608
+ byteSwap32(buffer32);
9609
+ this.compress(buffer32, 0, false);
9610
+ if (!isLE)
9611
+ byteSwap32(buffer32);
9612
+ this.pos = 0;
9613
+ }
9614
+ const take = Math.min(blockLen - this.pos, len - pos);
9615
+ const dataOffset = offset + pos;
9616
+ if (take === blockLen && !(dataOffset % 4) && pos + take < len) {
9617
+ const data32 = new Uint32Array(buf, dataOffset, Math.floor((len - pos) / 4));
9618
+ if (!isLE)
9619
+ byteSwap32(data32);
9620
+ for (let pos32 = 0; pos + blockLen < len; pos32 += buffer32.length, pos += blockLen) {
9621
+ this.length += blockLen;
9622
+ this.compress(data32, pos32, false);
9623
+ }
9624
+ if (!isLE)
9625
+ byteSwap32(data32);
9626
+ continue;
9627
+ }
9628
+ buffer.set(data.subarray(pos, pos + take), this.pos);
9629
+ this.pos += take;
9630
+ this.length += take;
9631
+ pos += take;
9632
+ }
9633
+ return this;
9634
+ }
9635
+ digestInto(out) {
9636
+ aexists(this);
9637
+ aoutput(out, this);
9638
+ const { pos, buffer32 } = this;
9639
+ this.finished = true;
9640
+ this.buffer.subarray(pos).fill(0);
9641
+ if (!isLE)
9642
+ byteSwap32(buffer32);
9643
+ this.compress(buffer32, 0, true);
9644
+ if (!isLE)
9645
+ byteSwap32(buffer32);
9646
+ const out32 = u32(out);
9647
+ this.get().forEach((v, i) => out32[i] = byteSwapIfBE(v));
9648
+ }
9649
+ digest() {
9650
+ const { buffer, outputLen } = this;
9651
+ this.digestInto(buffer);
9652
+ const res = buffer.slice(0, outputLen);
9653
+ this.destroy();
9654
+ return res;
9655
+ }
9656
+ _cloneInto(to) {
9657
+ const { buffer, length, finished, destroyed, outputLen, pos } = this;
9658
+ to || (to = new this.constructor({ dkLen: outputLen }));
9659
+ to.set(...this.get());
9660
+ to.length = length;
9661
+ to.finished = finished;
9662
+ to.destroyed = destroyed;
9663
+ to.outputLen = outputLen;
9664
+ to.buffer.set(buffer);
9665
+ to.pos = pos;
9666
+ return to;
9667
+ }
9668
+ };
9669
+
9670
+ // node_modules/@noble/hashes/esm/blake2s.js
9671
+ var B2S_IV = /* @__PURE__ */ new Uint32Array([
9672
+ 1779033703,
9673
+ 3144134277,
9674
+ 1013904242,
9675
+ 2773480762,
9676
+ 1359893119,
9677
+ 2600822924,
9678
+ 528734635,
9679
+ 1541459225
9680
+ ]);
9681
+ function G1s(a, b, c, d, x) {
9682
+ a = a + b + x | 0;
9683
+ d = rotr(d ^ a, 16);
9684
+ c = c + d | 0;
9685
+ b = rotr(b ^ c, 12);
9686
+ return { a, b, c, d };
9687
+ }
9688
+ function G2s(a, b, c, d, x) {
9689
+ a = a + b + x | 0;
9690
+ d = rotr(d ^ a, 8);
9691
+ c = c + d | 0;
9692
+ b = rotr(b ^ c, 7);
9693
+ return { a, b, c, d };
9694
+ }
9695
+ function compress(s, offset, msg, rounds, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15) {
9696
+ let j = 0;
9697
+ for (let i = 0; i < rounds; i++) {
9698
+ ({ a: v0, b: v4, c: v8, d: v12 } = G1s(v0, v4, v8, v12, msg[offset + s[j++]]));
9699
+ ({ a: v0, b: v4, c: v8, d: v12 } = G2s(v0, v4, v8, v12, msg[offset + s[j++]]));
9700
+ ({ a: v1, b: v5, c: v9, d: v13 } = G1s(v1, v5, v9, v13, msg[offset + s[j++]]));
9701
+ ({ a: v1, b: v5, c: v9, d: v13 } = G2s(v1, v5, v9, v13, msg[offset + s[j++]]));
9702
+ ({ a: v2, b: v6, c: v10, d: v14 } = G1s(v2, v6, v10, v14, msg[offset + s[j++]]));
9703
+ ({ a: v2, b: v6, c: v10, d: v14 } = G2s(v2, v6, v10, v14, msg[offset + s[j++]]));
9704
+ ({ a: v3, b: v7, c: v11, d: v15 } = G1s(v3, v7, v11, v15, msg[offset + s[j++]]));
9705
+ ({ a: v3, b: v7, c: v11, d: v15 } = G2s(v3, v7, v11, v15, msg[offset + s[j++]]));
9706
+ ({ a: v0, b: v5, c: v10, d: v15 } = G1s(v0, v5, v10, v15, msg[offset + s[j++]]));
9707
+ ({ a: v0, b: v5, c: v10, d: v15 } = G2s(v0, v5, v10, v15, msg[offset + s[j++]]));
9708
+ ({ a: v1, b: v6, c: v11, d: v12 } = G1s(v1, v6, v11, v12, msg[offset + s[j++]]));
9709
+ ({ a: v1, b: v6, c: v11, d: v12 } = G2s(v1, v6, v11, v12, msg[offset + s[j++]]));
9710
+ ({ a: v2, b: v7, c: v8, d: v13 } = G1s(v2, v7, v8, v13, msg[offset + s[j++]]));
9711
+ ({ a: v2, b: v7, c: v8, d: v13 } = G2s(v2, v7, v8, v13, msg[offset + s[j++]]));
9712
+ ({ a: v3, b: v4, c: v9, d: v14 } = G1s(v3, v4, v9, v14, msg[offset + s[j++]]));
9713
+ ({ a: v3, b: v4, c: v9, d: v14 } = G2s(v3, v4, v9, v14, msg[offset + s[j++]]));
9714
+ }
9715
+ return { v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15 };
9716
+ }
9717
+ var BLAKE2s = class extends BLAKE {
9718
+ constructor(opts = {}) {
9719
+ super(64, opts.dkLen === void 0 ? 32 : opts.dkLen, opts, 32, 8, 8);
9720
+ this.v0 = B2S_IV[0] | 0;
9721
+ this.v1 = B2S_IV[1] | 0;
9722
+ this.v2 = B2S_IV[2] | 0;
9723
+ this.v3 = B2S_IV[3] | 0;
9724
+ this.v4 = B2S_IV[4] | 0;
9725
+ this.v5 = B2S_IV[5] | 0;
9726
+ this.v6 = B2S_IV[6] | 0;
9727
+ this.v7 = B2S_IV[7] | 0;
9728
+ const keyLength = opts.key ? opts.key.length : 0;
9729
+ this.v0 ^= this.outputLen | keyLength << 8 | 1 << 16 | 1 << 24;
9730
+ if (opts.salt) {
9731
+ const salt = u32(toBytes(opts.salt));
9732
+ this.v4 ^= byteSwapIfBE(salt[0]);
9733
+ this.v5 ^= byteSwapIfBE(salt[1]);
9734
+ }
9735
+ if (opts.personalization) {
9736
+ const pers = u32(toBytes(opts.personalization));
9737
+ this.v6 ^= byteSwapIfBE(pers[0]);
9738
+ this.v7 ^= byteSwapIfBE(pers[1]);
9739
+ }
9740
+ if (opts.key) {
9741
+ const tmp = new Uint8Array(this.blockLen);
9742
+ tmp.set(toBytes(opts.key));
9743
+ this.update(tmp);
9744
+ }
9745
+ }
9746
+ get() {
9747
+ const { v0, v1, v2, v3, v4, v5, v6, v7 } = this;
9748
+ return [v0, v1, v2, v3, v4, v5, v6, v7];
9749
+ }
9750
+ // prettier-ignore
9751
+ set(v0, v1, v2, v3, v4, v5, v6, v7) {
9752
+ this.v0 = v0 | 0;
9753
+ this.v1 = v1 | 0;
9754
+ this.v2 = v2 | 0;
9755
+ this.v3 = v3 | 0;
9756
+ this.v4 = v4 | 0;
9757
+ this.v5 = v5 | 0;
9758
+ this.v6 = v6 | 0;
9759
+ this.v7 = v7 | 0;
9760
+ }
9761
+ compress(msg, offset, isLast) {
9762
+ const { h, l } = fromBig(BigInt(this.length));
9763
+ const { v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15 } = compress(SIGMA, offset, msg, 10, this.v0, this.v1, this.v2, this.v3, this.v4, this.v5, this.v6, this.v7, B2S_IV[0], B2S_IV[1], B2S_IV[2], B2S_IV[3], l ^ B2S_IV[4], h ^ B2S_IV[5], isLast ? ~B2S_IV[6] : B2S_IV[6], B2S_IV[7]);
9764
+ this.v0 ^= v0 ^ v8;
9765
+ this.v1 ^= v1 ^ v9;
9766
+ this.v2 ^= v2 ^ v10;
9767
+ this.v3 ^= v3 ^ v11;
9768
+ this.v4 ^= v4 ^ v12;
9769
+ this.v5 ^= v5 ^ v13;
9770
+ this.v6 ^= v6 ^ v14;
9771
+ this.v7 ^= v7 ^ v15;
9772
+ }
9773
+ destroy() {
9774
+ this.destroyed = true;
9775
+ this.buffer32.fill(0);
9776
+ this.set(0, 0, 0, 0, 0, 0, 0, 0);
9777
+ }
9778
+ };
9779
+ var blake2s = /* @__PURE__ */ wrapConstructorWithOpts((opts) => new BLAKE2s(opts));
9780
+
9781
+ // src/utils/connect/blake.ts
9782
+ function blakeHash(uint8Array) {
9783
+ return config.get("blake")?.(uint8Array) || blake2s(uint8Array, { dkLen: 32 });
9784
+ }
9785
+
9786
+ // src/utils/hash/classHash/blake.ts
9787
+ function blake2sHashMany(data) {
9788
+ const SMALL_THRESHOLD = 0x8000000000000000n;
9789
+ const BIG_MARKER = 2147483648;
9790
+ const u32Words = [];
9791
+ const buf = new ArrayBuffer(32);
9792
+ const feltView = new DataView(buf);
9793
+ for (const felt2 of data) {
9794
+ const u64_0 = felt2 & 0xffffffffffffffffn;
9795
+ const u64_1 = (felt2 & 0xffffffffffffffff0000000000000000n) >> 64n;
9796
+ const u64_2 = (felt2 & 0xffffffffffffffff00000000000000000000000000000000n) >> 128n;
9797
+ const u64_3 = (felt2 & 0xffffffffffffffff000000000000000000000000000000000000000000000000n) >> 192n;
9798
+ feltView.setBigUint64(0, u64_3, false);
9799
+ feltView.setBigUint64(8, u64_2, false);
9800
+ feltView.setBigUint64(16, u64_1, false);
9801
+ feltView.setBigUint64(24, u64_0, false);
9802
+ if (felt2 < SMALL_THRESHOLD) {
9803
+ const hi0 = feltView.getUint32(24, false);
9804
+ const lo0 = feltView.getUint32(28, false);
9805
+ u32Words.push(hi0, lo0);
9806
+ } else {
9807
+ const word0 = feltView.getUint32(0, false) | BIG_MARKER;
9808
+ const word1 = feltView.getUint32(4, false);
9809
+ const word2 = feltView.getUint32(8, false);
9810
+ const word3 = feltView.getUint32(12, false);
9811
+ const word4 = feltView.getUint32(16, false);
9812
+ const word5 = feltView.getUint32(20, false);
9813
+ const word6 = feltView.getUint32(24, false);
9814
+ const word7 = feltView.getUint32(28, false);
9815
+ u32Words.push(word0, word1, word2, word3, word4, word5, word6, word7);
9816
+ }
9817
+ }
9818
+ const bytes = new ArrayBuffer(u32Words.length * 4);
9819
+ const bytesView = new DataView(bytes);
9820
+ for (let i = 0; i < u32Words.length; i++) {
9821
+ bytesView.setUint32(i * 4, u32Words[i], true);
9822
+ }
9823
+ const hash = blakeHash(new Uint8Array(bytes));
9824
+ let hashBigInt = 0n;
9825
+ for (let i = 0; i < 32; i++) {
9826
+ hashBigInt |= BigInt(hash[i]) << BigInt(i * 8);
9827
+ }
9828
+ return hashBigInt % PRIME;
9829
+ }
9830
+ function hashBuiltinsBlake(builtins) {
9831
+ return blake2sHashMany(encodeBuiltins(builtins));
9832
+ }
9833
+ function hashEntryPointBlake(data) {
9834
+ const base = data.flatMap((it) => {
9835
+ return [BigInt(it.selector), BigInt(it.offset), hashBuiltinsBlake(it.builtins)];
9836
+ });
9837
+ return blake2sHashMany(base);
9838
+ }
9839
+ function bytecodeHashNodeBlake(iter, node) {
9840
+ if (typeof node === "number") {
9841
+ const data = [];
9842
+ for (let i = 0; i < node; i++) {
9843
+ const next = iter.next();
9844
+ if (next.done) throw new Error("Bytecode length mismatch");
9845
+ data.push(next.value);
9846
+ }
9847
+ return [node, blake2sHashMany(data)];
9848
+ }
9849
+ const innerNodes = node.map((child) => bytecodeHashNodeBlake(iter, child));
9850
+ const flatData = innerNodes.flatMap(([len, hash2]) => [BigInt(len), hash2]);
9851
+ const hash = blake2sHashMany(flatData) + 1n;
9852
+ const totalLen = innerNodes.reduce((sum, [len]) => sum + len, 0);
9853
+ return [totalLen, hash];
9854
+ }
9855
+ function hashByteCodeSegmentsBlake(casm) {
9856
+ const byteCode = casm.bytecode.map((n) => BigInt(n));
9857
+ const bytecodeSegmentLengths = casm.bytecode_segment_lengths;
9858
+ if (!bytecodeSegmentLengths) {
9859
+ return blake2sHashMany(byteCode);
9860
+ }
9861
+ const iter = byteCode[Symbol.iterator]();
9862
+ const [len, hash] = bytecodeHashNodeBlake(iter, bytecodeSegmentLengths);
9863
+ if (len !== byteCode.length) {
9864
+ throw new Error(`Bytecode length mismatch: expected ${byteCode.length}, got ${len}`);
9865
+ }
9866
+ return hash;
9867
+ }
9868
+ function computeCompiledClassHashBlake(casm) {
9869
+ const compiledClassVersion = BigInt(encodeShortString(COMPILED_CLASS_VERSION));
9870
+ const externalEntryPointsHash = hashEntryPointBlake(casm.entry_points_by_type.EXTERNAL);
9871
+ const l1Handlers = hashEntryPointBlake(casm.entry_points_by_type.L1_HANDLER);
9872
+ const constructor = hashEntryPointBlake(casm.entry_points_by_type.CONSTRUCTOR);
9873
+ const bytecode = hashByteCodeSegmentsBlake(casm);
9874
+ return toHex(
9875
+ blake2sHashMany([
9876
+ compiledClassVersion,
9877
+ externalEntryPointsHash,
9878
+ l1Handlers,
9879
+ constructor,
9880
+ bytecode
9881
+ ])
9882
+ );
9883
+ }
9884
+
9885
+ // src/utils/resolve.ts
9886
+ function isV3Tx(details) {
9887
+ const version = details.version ? toHex(details.version) : ETransactionVersion5.V3;
9888
+ return version === ETransactionVersion5.V3 || version === ETransactionVersion5.F3;
9889
+ }
9890
+ function isVersion(expected, provided) {
9891
+ const expectedParts = expected.split(".");
9892
+ const providedParts = provided.split(".");
9893
+ return expectedParts.every((part, index) => part === "*" || part === providedParts[index]);
9894
+ }
9895
+ function isSupportedSpecVersion(version, options = { allowAnyPatchVersion: false }) {
9896
+ return Object.values(_SupportedRpcVersion).some(
9897
+ (v) => isVersion(options.allowAnyPatchVersion ? toAnyPatchVersion(v) : v, version)
9898
+ );
9899
+ }
9900
+ function toAnyPatchVersion(version) {
9901
+ const parts = version.split(".");
9902
+ if (parts.length < 3) {
9903
+ return version;
9904
+ }
9905
+ return `${parts[0]}.${parts[1]}.*`;
9906
+ }
9907
+ function toApiVersion(version) {
9908
+ const [major, minor] = version.replace(/^v/, "").split(".");
9909
+ return `v${major}_${minor}`;
9910
+ }
9911
+ function compareVersions(a, b) {
9912
+ const aParts = a.split(".").map(Number);
9913
+ const bParts = b.split(".").map(Number);
9914
+ const maxLen = Math.max(aParts.length, bParts.length);
9915
+ for (let i = 0; i < maxLen; i += 1) {
9916
+ const aNum = aParts[i] || 0;
9917
+ const bNum = bParts[i] || 0;
9918
+ if (aNum > bNum) return 1;
9919
+ if (aNum < bNum) return -1;
9920
+ }
9921
+ return 0;
9922
+ }
9923
+ function isPendingBlock(response) {
9924
+ return response.status === "PENDING";
9925
+ }
9926
+ function isPendingTransaction(response) {
9927
+ return !("block_hash" in response);
9928
+ }
9929
+ function isPendingStateUpdate(response) {
9930
+ return !("block_hash" in response);
9931
+ }
9932
+
9933
+ // src/utils/hash/classHash/index.ts
9351
9934
  function computeContractClassHash(contract) {
9352
9935
  const compiledContract = isString(contract) ? parse2(contract) : contract;
9353
9936
  if ("sierra_program" in compiledContract) {
@@ -9355,6 +9938,12 @@ ${indent}}` : "}";
9355
9938
  }
9356
9939
  return computeLegacyContractClassHash(compiledContract);
9357
9940
  }
9941
+ function computeCompiledClassHash(casm, specVersion) {
9942
+ if (specVersion && compareVersions(specVersion, "0.10.0") >= 0) {
9943
+ return computeCompiledClassHashBlake(casm);
9944
+ }
9945
+ return computeCompiledClassHashPoseidon(casm);
9946
+ }
9358
9947
 
9359
9948
  // src/utils/stark/index.ts
9360
9949
  var stark_exports = {};
@@ -13735,11 +14324,11 @@ ${indent}}` : "}";
13735
14324
  const compiledContract = isString(contract) ? parse2(contract) : contract;
13736
14325
  return "sierra_program" in compiledContract;
13737
14326
  }
13738
- function extractContractHashes(payload) {
14327
+ function extractContractHashes(payload, specVersion) {
13739
14328
  const response = { ...payload };
13740
14329
  if (isSierra(payload.contract)) {
13741
14330
  if (!payload.compiledClassHash && payload.casm) {
13742
- response.compiledClassHash = computeCompiledClassHash(payload.casm);
14331
+ response.compiledClassHash = computeCompiledClassHash(payload.casm, specVersion);
13743
14332
  }
13744
14333
  if (!response.compiledClassHash)
13745
14334
  throw new Error(
@@ -14129,44 +14718,6 @@ ${indent}}` : "}";
14129
14718
  validBlockTags: () => validBlockTags,
14130
14719
  wait: () => wait
14131
14720
  });
14132
-
14133
- // src/utils/resolve.ts
14134
- function isV3Tx(details) {
14135
- const version = details.version ? toHex(details.version) : ETransactionVersion5.V3;
14136
- return version === ETransactionVersion5.V3 || version === ETransactionVersion5.F3;
14137
- }
14138
- function isVersion(expected, provided) {
14139
- const expectedParts = expected.split(".");
14140
- const providedParts = provided.split(".");
14141
- return expectedParts.every((part, index) => part === "*" || part === providedParts[index]);
14142
- }
14143
- function isSupportedSpecVersion(version, options = { allowAnyPatchVersion: false }) {
14144
- return Object.values(_SupportedRpcVersion).some(
14145
- (v) => isVersion(options.allowAnyPatchVersion ? toAnyPatchVersion(v) : v, version)
14146
- );
14147
- }
14148
- function toAnyPatchVersion(version) {
14149
- const parts = version.split(".");
14150
- if (parts.length < 3) {
14151
- return version;
14152
- }
14153
- return `${parts[0]}.${parts[1]}.*`;
14154
- }
14155
- function toApiVersion(version) {
14156
- const [major, minor] = version.replace(/^v/, "").split(".");
14157
- return `v${major}_${minor}`;
14158
- }
14159
- function isPendingBlock(response) {
14160
- return response.status === "PENDING";
14161
- }
14162
- function isPendingTransaction(response) {
14163
- return !("block_hash" in response);
14164
- }
14165
- function isPendingStateUpdate(response) {
14166
- return !("block_hash" in response);
14167
- }
14168
-
14169
- // src/utils/provider.ts
14170
14721
  function wait(delay) {
14171
14722
  return new Promise((res) => {
14172
14723
  setTimeout(res, delay);
@@ -17340,7 +17891,10 @@ ${indent}}` : "}";
17340
17891
  async isClassDeclared(contractClassIdentifier, blockIdentifier) {
17341
17892
  let classHash;
17342
17893
  if (!contractClassIdentifier.classHash && "contract" in contractClassIdentifier) {
17343
- const hashes = extractContractHashes(contractClassIdentifier);
17894
+ const hashes = extractContractHashes(
17895
+ contractClassIdentifier,
17896
+ await this.channel.setUpSpecVersion()
17897
+ );
17344
17898
  classHash = hashes.classHash;
17345
17899
  } else if (contractClassIdentifier.classHash) {
17346
17900
  classHash = contractClassIdentifier.classHash;
@@ -19828,7 +20382,7 @@ ${indent}}` : "}";
19828
20382
  throw new Error("Deployer emitted event is empty");
19829
20383
  }
19830
20384
  const event = txReceipt.events.find(
19831
- (it) => cleanHex(it.from_address) === cleanHex(toHex(this.address))
20385
+ (it) => toHex(it.from_address) === toHex(this.address)
19832
20386
  ) || {
19833
20387
  data: []
19834
20388
  };
@@ -19928,7 +20482,10 @@ ${indent}}` : "}";
19928
20482
  "Declare fee estimation is not supported for Cairo0 contracts"
19929
20483
  );
19930
20484
  const invocations = [
19931
- { type: ETransactionType2.DECLARE, payload: extractContractHashes(payload) }
20485
+ {
20486
+ type: ETransactionType2.DECLARE,
20487
+ payload: extractContractHashes(payload, await this.channel.setUpSpecVersion())
20488
+ }
19932
20489
  ];
19933
20490
  const estimateBulk = await this.estimateFeeBulk(invocations, details);
19934
20491
  return estimateBulk[0];
@@ -20091,7 +20648,10 @@ ${indent}}` : "}";
20091
20648
  * @param transactionsDetail (optional)
20092
20649
  */
20093
20650
  async declareIfNot(payload, transactionsDetail = {}) {
20094
- const declareContractPayload = extractContractHashes(payload);
20651
+ const declareContractPayload = extractContractHashes(
20652
+ payload,
20653
+ await this.channel.setUpSpecVersion()
20654
+ );
20095
20655
  try {
20096
20656
  await this.getClassByHash(declareContractPayload.classHash);
20097
20657
  } catch (error) {
@@ -20104,7 +20664,10 @@ ${indent}}` : "}";
20104
20664
  }
20105
20665
  async declare(payload, details = {}) {
20106
20666
  assert(isSierra(payload.contract), SYSTEM_MESSAGES.declareNonSierra);
20107
- const declareContractPayload = extractContractHashes(payload);
20667
+ const declareContractPayload = extractContractHashes(
20668
+ payload,
20669
+ await this.channel.setUpSpecVersion()
20670
+ );
20108
20671
  const detailsWithTip = await this.resolveDetailsWithTip(details);
20109
20672
  const { resourceBounds: providedResourceBounds } = details;
20110
20673
  let resourceBounds = providedResourceBounds;
@@ -20411,7 +20974,10 @@ ${indent}}` : "}";
20411
20974
  };
20412
20975
  }
20413
20976
  async buildDeclarePayload(payload, details) {
20414
- const { classHash, contract, compiledClassHash } = extractContractHashes(payload);
20977
+ const { classHash, contract, compiledClassHash } = extractContractHashes(
20978
+ payload,
20979
+ await this.channel.setUpSpecVersion()
20980
+ );
20415
20981
  const compressedCompiledContract = parseContract(contract);
20416
20982
  assert(
20417
20983
  !isUndefined(compiledClassHash) && (details.version === ETransactionVersion33.F3 || details.version === ETransactionVersion33.V3),
@@ -20757,8 +21323,11 @@ ${indent}}` : "}";
20757
21323
  };
20758
21324
  return addInvokeTransaction(this.walletProvider, params);
20759
21325
  }
20760
- declare(payload) {
20761
- const declareContractPayload = extractContractHashes(payload);
21326
+ async declare(payload) {
21327
+ const declareContractPayload = extractContractHashes(
21328
+ payload,
21329
+ await this.channel.setUpSpecVersion()
21330
+ );
20762
21331
  const pContract = payload.contract;
20763
21332
  const cairo1Contract = {
20764
21333
  ...pContract,
@@ -21175,7 +21744,7 @@ ${indent}}` : "}";
21175
21744
  transaction_hash: txR.transaction_hash,
21176
21745
  ...event
21177
21746
  };
21178
- }).filter((event) => cleanHex(event.from_address) === cleanHex(this.address), []) || [];
21747
+ }).filter((event) => toHex(event.from_address) === toHex(this.address), []) || [];
21179
21748
  parsed = parseEvents(
21180
21749
  emittedEvents,
21181
21750
  this.events,