starknet 8.5.5 → 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,
@@ -1174,7 +1175,8 @@ var starknet = (() => {
1174
1175
  defaultTipType: "recommendedTip",
1175
1176
  fetch: void 0,
1176
1177
  websocket: void 0,
1177
- buffer: void 0
1178
+ buffer: void 0,
1179
+ blake: void 0
1178
1180
  };
1179
1181
  var RPC_DEFAULT_NODES = {
1180
1182
  SN_MAIN: [`https://starknet-mainnet.public.blastapi.io/rpc/`],
@@ -2512,6 +2514,7 @@ ${indent}}` : "}";
2512
2514
  var rotr = (word, shift) => word << 32 - shift | word >>> shift;
2513
2515
  var isLE = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68)();
2514
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);
2515
2518
  function byteSwap32(arr) {
2516
2519
  for (let i = 0; i < arr.length; i++) {
2517
2520
  arr[i] = byteSwap(arr[i]);
@@ -2542,6 +2545,14 @@ ${indent}}` : "}";
2542
2545
  hashC.create = () => hashCons();
2543
2546
  return hashC;
2544
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
+ }
2545
2556
  function wrapXOFConstructorWithOpts(hashCons) {
2546
2557
  const hashC = (msg, opts) => hashCons(opts).update(toBytes(msg)).digest();
2547
2558
  const tmp = hashCons({});
@@ -8912,12 +8923,16 @@ ${indent}}` : "}";
8912
8923
  // src/utils/hash/index.ts
8913
8924
  var hash_exports = {};
8914
8925
  __export(hash_exports, {
8926
+ COMPILED_CLASS_VERSION: () => COMPILED_CLASS_VERSION,
8927
+ blake2sHashMany: () => blake2sHashMany,
8915
8928
  calculateContractAddressFromHash: () => calculateContractAddressFromHash,
8916
8929
  calculateDeclareTransactionHash: () => calculateDeclareTransactionHash3,
8917
8930
  calculateDeployAccountTransactionHash: () => calculateDeployAccountTransactionHash3,
8918
8931
  calculateInvokeTransactionHash: () => calculateInvokeTransactionHash2,
8919
8932
  calculateL2MessageTxHash: () => calculateL2MessageTxHash,
8920
8933
  computeCompiledClassHash: () => computeCompiledClassHash,
8934
+ computeCompiledClassHashBlake: () => computeCompiledClassHashBlake,
8935
+ computeCompiledClassHashPoseidon: () => computeCompiledClassHashPoseidon,
8921
8936
  computeContractClassHash: () => computeContractClassHash,
8922
8937
  computeHashOnElements: () => computeHashOnElements3,
8923
8938
  computeHintedClassHash: () => computeHintedClassHash,
@@ -8927,13 +8942,17 @@ ${indent}}` : "}";
8927
8942
  computePoseidonHash: () => computePoseidonHash,
8928
8943
  computePoseidonHashOnElements: () => computePoseidonHashOnElements,
8929
8944
  computeSierraContractClassHash: () => computeSierraContractClassHash,
8945
+ encodeBuiltins: () => encodeBuiltins,
8946
+ flattenEntryPointData: () => flattenEntryPointData,
8930
8947
  formatSpaces: () => formatSpaces,
8931
8948
  getL1MessageHash: () => getL1MessageHash,
8932
8949
  getL2MessageHash: () => getL2MessageHash,
8933
8950
  getSelector: () => getSelector,
8934
8951
  getSelectorFromName: () => getSelectorFromName,
8935
8952
  hashByteCodeSegments: () => hashByteCodeSegments,
8953
+ hashByteCodeSegmentsBlake: () => hashByteCodeSegmentsBlake,
8936
8954
  keccakBn: () => keccakBn,
8955
+ nullSkipReplacer: () => nullSkipReplacer,
8937
8956
  poseidon: () => poseidon_exports,
8938
8957
  solidityUint256PackedKeccak256: () => solidityUint256PackedKeccak256,
8939
8958
  starknetKeccak: () => starknetKeccak
@@ -9194,20 +9213,51 @@ ${indent}}` : "}";
9194
9213
  throw new Error("Invalid Tx version for hash calculation");
9195
9214
  }
9196
9215
 
9197
- // 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
9198
9254
  function computePedersenHash(a, b) {
9199
9255
  return esm_exports4.pedersen(BigInt(a), BigInt(b));
9200
9256
  }
9201
- function computePoseidonHash(a, b) {
9202
- return toHex(esm_exports4.poseidonHash(BigInt(a), BigInt(b)));
9203
- }
9204
9257
  function computeHashOnElements3(data) {
9205
9258
  return [...data, data.length].reduce((x, y) => esm_exports4.pedersen(BigInt(x), BigInt(y)), 0).toString();
9206
9259
  }
9207
9260
  var computePedersenHashOnElements = computeHashOnElements3;
9208
- function computePoseidonHashOnElements(data) {
9209
- return toHex(poseidonHashMany(data.map((x) => BigInt(x))));
9210
- }
9211
9261
  function calculateContractAddressFromHash(salt, classHash, constructorCalldata, deployerAddress) {
9212
9262
  const compiledCalldata = CallData.compile(constructorCalldata);
9213
9263
  const constructorCalldataHash = computeHashOnElements3(compiledCalldata);
@@ -9221,30 +9271,6 @@ ${indent}}` : "}";
9221
9271
  ]);
9222
9272
  return toHex(BigInt(hash) % ADDR_BOUND);
9223
9273
  }
9224
- function nullSkipReplacer(key, value) {
9225
- if (key === "attributes" || key === "accessible_scopes") {
9226
- return Array.isArray(value) && value.length === 0 ? void 0 : value;
9227
- }
9228
- if (key === "debug_info") {
9229
- return null;
9230
- }
9231
- return value === null ? void 0 : value;
9232
- }
9233
- function formatSpaces(json) {
9234
- let insideQuotes = false;
9235
- const newString = [];
9236
- for (const char of json) {
9237
- if (char === '"' && (newString.length > 0 && newString.slice(-1)[0] === "\\") === false) {
9238
- insideQuotes = !insideQuotes;
9239
- }
9240
- if (insideQuotes) {
9241
- newString.push(char);
9242
- } else {
9243
- newString.push(char === ":" ? ": " : char === "," ? ", " : char);
9244
- }
9245
- }
9246
- return newString.join("");
9247
- }
9248
9274
  function computeHintedClassHash(compiledContract) {
9249
9275
  const { abi, program } = compiledContract;
9250
9276
  const contractClass = { abi, program };
@@ -9278,12 +9304,16 @@ ${indent}}` : "}";
9278
9304
  dataHash
9279
9305
  ]);
9280
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
+ }
9281
9315
  function hashBuiltins(builtins) {
9282
- return poseidonHashMany(
9283
- builtins.flatMap((it) => {
9284
- return BigInt(encodeShortString(it));
9285
- })
9286
- );
9316
+ return poseidonHashMany(encodeBuiltins(builtins));
9287
9317
  }
9288
9318
  function hashEntryPoint(data) {
9289
9319
  const base = data.flatMap((it) => {
@@ -9301,8 +9331,7 @@ ${indent}}` : "}";
9301
9331
  });
9302
9332
  return 1n + poseidonHashMany(hashLeaves);
9303
9333
  }
9304
- function computeCompiledClassHash(casm) {
9305
- const COMPILED_CLASS_VERSION = "COMPILED_CLASS_V1";
9334
+ function computeCompiledClassHashPoseidon(casm) {
9306
9335
  const compiledClassVersion = BigInt(encodeShortString(COMPILED_CLASS_VERSION));
9307
9336
  const externalEntryPointsHash = hashEntryPoint(casm.entry_points_by_type.EXTERNAL);
9308
9337
  const l1Handlers = hashEntryPoint(casm.entry_points_by_type.L1_HANDLER);
@@ -9347,6 +9376,561 @@ ${indent}}` : "}";
9347
9376
  ])
9348
9377
  );
9349
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
9350
9934
  function computeContractClassHash(contract) {
9351
9935
  const compiledContract = isString(contract) ? parse2(contract) : contract;
9352
9936
  if ("sierra_program" in compiledContract) {
@@ -9354,6 +9938,12 @@ ${indent}}` : "}";
9354
9938
  }
9355
9939
  return computeLegacyContractClassHash(compiledContract);
9356
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
+ }
9357
9947
 
9358
9948
  // src/utils/stark/index.ts
9359
9949
  var stark_exports = {};
@@ -13734,11 +14324,11 @@ ${indent}}` : "}";
13734
14324
  const compiledContract = isString(contract) ? parse2(contract) : contract;
13735
14325
  return "sierra_program" in compiledContract;
13736
14326
  }
13737
- function extractContractHashes(payload) {
14327
+ function extractContractHashes(payload, specVersion) {
13738
14328
  const response = { ...payload };
13739
14329
  if (isSierra(payload.contract)) {
13740
14330
  if (!payload.compiledClassHash && payload.casm) {
13741
- response.compiledClassHash = computeCompiledClassHash(payload.casm);
14331
+ response.compiledClassHash = computeCompiledClassHash(payload.casm, specVersion);
13742
14332
  }
13743
14333
  if (!response.compiledClassHash)
13744
14334
  throw new Error(
@@ -14128,44 +14718,6 @@ ${indent}}` : "}";
14128
14718
  validBlockTags: () => validBlockTags,
14129
14719
  wait: () => wait
14130
14720
  });
14131
-
14132
- // src/utils/resolve.ts
14133
- function isV3Tx(details) {
14134
- const version = details.version ? toHex(details.version) : ETransactionVersion5.V3;
14135
- return version === ETransactionVersion5.V3 || version === ETransactionVersion5.F3;
14136
- }
14137
- function isVersion(expected, provided) {
14138
- const expectedParts = expected.split(".");
14139
- const providedParts = provided.split(".");
14140
- return expectedParts.every((part, index) => part === "*" || part === providedParts[index]);
14141
- }
14142
- function isSupportedSpecVersion(version, options = { allowAnyPatchVersion: false }) {
14143
- return Object.values(_SupportedRpcVersion).some(
14144
- (v) => isVersion(options.allowAnyPatchVersion ? toAnyPatchVersion(v) : v, version)
14145
- );
14146
- }
14147
- function toAnyPatchVersion(version) {
14148
- const parts = version.split(".");
14149
- if (parts.length < 3) {
14150
- return version;
14151
- }
14152
- return `${parts[0]}.${parts[1]}.*`;
14153
- }
14154
- function toApiVersion(version) {
14155
- const [major, minor] = version.replace(/^v/, "").split(".");
14156
- return `v${major}_${minor}`;
14157
- }
14158
- function isPendingBlock(response) {
14159
- return response.status === "PENDING";
14160
- }
14161
- function isPendingTransaction(response) {
14162
- return !("block_hash" in response);
14163
- }
14164
- function isPendingStateUpdate(response) {
14165
- return !("block_hash" in response);
14166
- }
14167
-
14168
- // src/utils/provider.ts
14169
14721
  function wait(delay) {
14170
14722
  return new Promise((res) => {
14171
14723
  setTimeout(res, delay);
@@ -17339,7 +17891,10 @@ ${indent}}` : "}";
17339
17891
  async isClassDeclared(contractClassIdentifier, blockIdentifier) {
17340
17892
  let classHash;
17341
17893
  if (!contractClassIdentifier.classHash && "contract" in contractClassIdentifier) {
17342
- const hashes = extractContractHashes(contractClassIdentifier);
17894
+ const hashes = extractContractHashes(
17895
+ contractClassIdentifier,
17896
+ await this.channel.setUpSpecVersion()
17897
+ );
17343
17898
  classHash = hashes.classHash;
17344
17899
  } else if (contractClassIdentifier.classHash) {
17345
17900
  classHash = contractClassIdentifier.classHash;
@@ -19927,7 +20482,10 @@ ${indent}}` : "}";
19927
20482
  "Declare fee estimation is not supported for Cairo0 contracts"
19928
20483
  );
19929
20484
  const invocations = [
19930
- { type: ETransactionType2.DECLARE, payload: extractContractHashes(payload) }
20485
+ {
20486
+ type: ETransactionType2.DECLARE,
20487
+ payload: extractContractHashes(payload, await this.channel.setUpSpecVersion())
20488
+ }
19931
20489
  ];
19932
20490
  const estimateBulk = await this.estimateFeeBulk(invocations, details);
19933
20491
  return estimateBulk[0];
@@ -20090,7 +20648,10 @@ ${indent}}` : "}";
20090
20648
  * @param transactionsDetail (optional)
20091
20649
  */
20092
20650
  async declareIfNot(payload, transactionsDetail = {}) {
20093
- const declareContractPayload = extractContractHashes(payload);
20651
+ const declareContractPayload = extractContractHashes(
20652
+ payload,
20653
+ await this.channel.setUpSpecVersion()
20654
+ );
20094
20655
  try {
20095
20656
  await this.getClassByHash(declareContractPayload.classHash);
20096
20657
  } catch (error) {
@@ -20103,7 +20664,10 @@ ${indent}}` : "}";
20103
20664
  }
20104
20665
  async declare(payload, details = {}) {
20105
20666
  assert(isSierra(payload.contract), SYSTEM_MESSAGES.declareNonSierra);
20106
- const declareContractPayload = extractContractHashes(payload);
20667
+ const declareContractPayload = extractContractHashes(
20668
+ payload,
20669
+ await this.channel.setUpSpecVersion()
20670
+ );
20107
20671
  const detailsWithTip = await this.resolveDetailsWithTip(details);
20108
20672
  const { resourceBounds: providedResourceBounds } = details;
20109
20673
  let resourceBounds = providedResourceBounds;
@@ -20410,7 +20974,10 @@ ${indent}}` : "}";
20410
20974
  };
20411
20975
  }
20412
20976
  async buildDeclarePayload(payload, details) {
20413
- const { classHash, contract, compiledClassHash } = extractContractHashes(payload);
20977
+ const { classHash, contract, compiledClassHash } = extractContractHashes(
20978
+ payload,
20979
+ await this.channel.setUpSpecVersion()
20980
+ );
20414
20981
  const compressedCompiledContract = parseContract(contract);
20415
20982
  assert(
20416
20983
  !isUndefined(compiledClassHash) && (details.version === ETransactionVersion33.F3 || details.version === ETransactionVersion33.V3),
@@ -20756,8 +21323,11 @@ ${indent}}` : "}";
20756
21323
  };
20757
21324
  return addInvokeTransaction(this.walletProvider, params);
20758
21325
  }
20759
- declare(payload) {
20760
- const declareContractPayload = extractContractHashes(payload);
21326
+ async declare(payload) {
21327
+ const declareContractPayload = extractContractHashes(
21328
+ payload,
21329
+ await this.channel.setUpSpecVersion()
21330
+ );
20761
21331
  const pContract = payload.contract;
20762
21332
  const cairo1Contract = {
20763
21333
  ...pContract,