@typeberry/lib 0.4.0-fcdfbb1 → 0.4.1-0a3acb2

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.
Files changed (4) hide show
  1. package/index.cjs +670 -285
  2. package/index.d.ts +1466 -1407
  3. package/index.js +645 -259
  4. package/package.json +1 -1
package/index.js CHANGED
@@ -16,7 +16,11 @@ var TestSuite;
16
16
  })(TestSuite || (TestSuite = {}));
17
17
  const ALL_VERSIONS_IN_ORDER = [GpVersion.V0_6_7, GpVersion.V0_7_0, GpVersion.V0_7_1, GpVersion.V0_7_2];
18
18
  const DEFAULT_SUITE = TestSuite.W3F_DAVXY;
19
- const DEFAULT_VERSION = GpVersion.V0_7_2;
19
+ /**
20
+ * Current version is set to track the jam-conformance testing.
21
+ * Since we are currently at 0.7.1 not 0.7.2, we set our default version accordingly.
22
+ */
23
+ const DEFAULT_VERSION = GpVersion.V0_7_1;
20
24
  const env$1 = typeof process === "undefined" ? {} : process.env;
21
25
  let CURRENT_VERSION = parseCurrentVersion(env$1.GP_VERSION) ?? DEFAULT_VERSION;
22
26
  let CURRENT_SUITE = parseCurrentSuite(env$1.TEST_SUITE) ?? DEFAULT_SUITE;
@@ -75,8 +79,8 @@ class Compatibility {
75
79
  /**
76
80
  * Allows selecting different values for different Gray Paper versions from one record.
77
81
  *
78
- * @param fallback The default value to return if no value is found for the current.
79
- * @param record A record mapping versions to values, checking if the version is greater or equal to the current version.
82
+ * fallback The default value to return if no value is found for the current.
83
+ * versions A record mapping versions to values, checking if the version is greater or equal to the current version.
80
84
  * @returns The value for the current version, or the default value.
81
85
  */
82
86
  static selectIfGreaterOrEqual({ fallback, versions, }) {
@@ -236,7 +240,7 @@ const workspacePathFix = env.NODE_ENV === "development"
236
240
  : () => (p) => p;
237
241
 
238
242
  /**
239
- * @fileoverview `Opaque<Type, Token>` constructs a unique type which is a subset of Type with a
243
+ * `Opaque<Type, Token>` constructs a unique type which is a subset of Type with a
240
244
  * specified unique token Token. It means that base type cannot be assigned to unique type by accident.
241
245
  * Good examples of opaque types include:
242
246
  * - JWTs or other tokens - these are special kinds of string used for authorization purposes.
@@ -579,7 +583,7 @@ function isResult(x) {
579
583
  * as an afterthought.
580
584
  */
581
585
 
582
- var index$v = /*#__PURE__*/Object.freeze({
586
+ var index$u = /*#__PURE__*/Object.freeze({
583
587
  __proto__: null,
584
588
  get CURRENT_SUITE () { return CURRENT_SUITE; },
585
589
  get CURRENT_VERSION () { return CURRENT_VERSION; },
@@ -736,7 +740,7 @@ class Ordering {
736
740
  }
737
741
  }
738
742
 
739
- var index$u = /*#__PURE__*/Object.freeze({
743
+ var index$t = /*#__PURE__*/Object.freeze({
740
744
  __proto__: null,
741
745
  Ordering: Ordering
742
746
  });
@@ -988,7 +992,7 @@ function u8ArraySameLengthEqual(self, other) {
988
992
  }
989
993
  const bytesBlobComparator = (a, b) => a.compare(b);
990
994
 
991
- var index$t = /*#__PURE__*/Object.freeze({
995
+ var index$s = /*#__PURE__*/Object.freeze({
992
996
  __proto__: null,
993
997
  BitVec: BitVec,
994
998
  Bytes: Bytes,
@@ -1090,7 +1094,7 @@ const minU64 = (a, ...values) => values.reduce((min, value) => (value > min ? mi
1090
1094
  /** Get the biggest value between U64 a and values given as input parameters. */
1091
1095
  const maxU64 = (a, ...values) => values.reduce((max, value) => (value < max ? max : value), a);
1092
1096
 
1093
- var index$s = /*#__PURE__*/Object.freeze({
1097
+ var index$r = /*#__PURE__*/Object.freeze({
1094
1098
  __proto__: null,
1095
1099
  isU16: isU16,
1096
1100
  isU32: isU32,
@@ -2529,7 +2533,7 @@ function sequenceViewFixLen(type, { fixedLength }) {
2529
2533
  }, skipper);
2530
2534
  }
2531
2535
 
2532
- var index$r = /*#__PURE__*/Object.freeze({
2536
+ var index$q = /*#__PURE__*/Object.freeze({
2533
2537
  __proto__: null,
2534
2538
  Decoder: Decoder,
2535
2539
  Descriptor: Descriptor,
@@ -3730,7 +3734,7 @@ var keyDerivation = /*#__PURE__*/Object.freeze({
3730
3734
  trivialSeed: trivialSeed
3731
3735
  });
3732
3736
 
3733
- var index$q = /*#__PURE__*/Object.freeze({
3737
+ var index$p = /*#__PURE__*/Object.freeze({
3734
3738
  __proto__: null,
3735
3739
  BANDERSNATCH_KEY_BYTES: BANDERSNATCH_KEY_BYTES,
3736
3740
  BANDERSNATCH_PROOF_BYTES: BANDERSNATCH_PROOF_BYTES,
@@ -4368,7 +4372,7 @@ var keccak = /*#__PURE__*/Object.freeze({
4368
4372
  // TODO [ToDr] (#213) this should most likely be moved to a separate
4369
4373
  // package to avoid pulling in unnecessary deps.
4370
4374
 
4371
- var index$p = /*#__PURE__*/Object.freeze({
4375
+ var index$o = /*#__PURE__*/Object.freeze({
4372
4376
  __proto__: null,
4373
4377
  Blake2b: Blake2b,
4374
4378
  HASH_SIZE: HASH_SIZE,
@@ -4420,8 +4424,434 @@ class ArrayView {
4420
4424
  }
4421
4425
  }
4422
4426
 
4423
- /** A map which uses hashes as keys. */
4424
- class HashDictionary {
4427
+ /** A map which uses byte blobs as keys */
4428
+ class BlobDictionary extends WithDebug {
4429
+ mapNodeThreshold;
4430
+ /**
4431
+ * The root node of the dictionary.
4432
+ *
4433
+ * This is the main internal data structure that organizes entries
4434
+ * in a tree-like fashion (array-based nodes up to `mapNodeThreshold`,
4435
+ * map-based nodes beyond it). All insertions, updates, and deletions
4436
+ * operate through this structure.
4437
+ */
4438
+ root = Node.withList();
4439
+ /**
4440
+ * Auxiliary map that stores references to the original keys and their values.
4441
+ *
4442
+ * - Overriding a value in the main structure does not replace the original key reference.
4443
+ * - Used for efficient iteration over `keys()`, `values()`, `entries()`, and computing `size`.
4444
+ */
4445
+ keyvals = new Map();
4446
+ /**
4447
+ * Protected constructor used internally by `BlobDictionary.new`
4448
+ * and `BlobDictionary.fromEntries`.
4449
+ *
4450
+ * This enforces controlled instantiation — users should create instances
4451
+ * through the provided static factory methods instead of calling the
4452
+ * constructor directly.
4453
+ *
4454
+ * @param mapNodeThreshold - The threshold that determines when the dictionary
4455
+ * switches from using an array-based (`ListChildren`) node to a map-based (`MapChildren`) node for storing entries.
4456
+ */
4457
+ constructor(mapNodeThreshold) {
4458
+ super();
4459
+ this.mapNodeThreshold = mapNodeThreshold;
4460
+ }
4461
+ /**
4462
+ * Returns the number of entries in the dictionary.
4463
+ *
4464
+ * The count is derived from the auxiliary `keyvals` map, which stores
4465
+ * all original key references and their associated values. This ensures
4466
+ * that the `size` reflects the actual number of entries, independent of
4467
+ * internal overrides in the main `root` structure.
4468
+ *
4469
+ * @returns The total number of entries in the dictionary.
4470
+ */
4471
+ get size() {
4472
+ return this.keyvals.size;
4473
+ }
4474
+ [TEST_COMPARE_USING]() {
4475
+ const vals = Array.from(this);
4476
+ vals.sort((a, b) => a[0].compare(b[0]).value);
4477
+ return vals;
4478
+ }
4479
+ /**
4480
+ * Creates an empty `BlobDictionary`.
4481
+ *
4482
+ * @param mapNodeThreshold - The threshold that determines when the dictionary
4483
+ * switches from using an array-based (`ListChildren`) node to a map-based (`MapChildren`) node for storing entries.
4484
+ * Defaults to `0`.
4485
+ *
4486
+ * @returns A new, empty `BlobDictionary` instance.
4487
+ */
4488
+ static new(mapNodeThreshold = 0) {
4489
+ return new BlobDictionary(mapNodeThreshold);
4490
+ }
4491
+ /**
4492
+ * Creates a new `BlobDictionary` initialized with the given entries.
4493
+ *
4494
+ * @param entries - An array of `[key, value]` pairs used to populate the dictionary.
4495
+ * @param mapNodeThreshold - The threshold that determines when the dictionary
4496
+ * switches from using an array-based (`ListChildren`) node to a map-based (`MapChildren`) node for storing entries.
4497
+ * Defaults to `0`.
4498
+ *
4499
+ * @returns A new `BlobDictionary` containing the provided entries.
4500
+ */
4501
+ static fromEntries(entries, mapNodeThreshold) {
4502
+ const dict = BlobDictionary.new(mapNodeThreshold);
4503
+ for (const [key, value] of entries) {
4504
+ dict.set(key, value);
4505
+ }
4506
+ return dict;
4507
+ }
4508
+ /**
4509
+ * Internal helper that inserts, updates or deletes an entry in the dictionary.
4510
+ *
4511
+ * Behaviour details:
4512
+ * - Passing `undefined` as `value` indicates a deletion. (E.g. `delete` uses `internalSet(key, undefined)`.)
4513
+ * - When an add (new entry) or a delete actually changes the structure, the method returns the affected leaf node.
4514
+ * - When the call only overrides an existing value (no structural add/delete), the method returns `null`.
4515
+ *
4516
+ * This method is intended for internal use by the dictionary implementation and allows `undefined` as a
4517
+ * sentinel value to signal removals.
4518
+ *
4519
+ * @param key - The key to insert, update or remove.
4520
+ * @param value - The value to associate with the key, or `undefined` to remove the key.
4521
+ * @returns The leaf node created or removed on add/delete, or `null` if the operation only overwrote an existing value.
4522
+ */
4523
+ internalSet(key, value) {
4524
+ let node = this.root;
4525
+ const keyChunkGenerator = key.chunks(CHUNK_SIZE);
4526
+ let depth = 0;
4527
+ for (;;) {
4528
+ const maybeKeyChunk = keyChunkGenerator.next().value;
4529
+ if (maybeKeyChunk === undefined) {
4530
+ if (value === undefined) {
4531
+ return node.remove(key);
4532
+ }
4533
+ return node.set(key, value);
4534
+ }
4535
+ const keyChunk = asOpaqueType(maybeKeyChunk);
4536
+ if (node.children instanceof ListChildren) {
4537
+ const subkey = BytesBlob.blobFrom(key.raw.subarray(CHUNK_SIZE * depth));
4538
+ const leaf = value !== undefined ? node.children.insert(subkey, { key, value }) : node.children.remove(subkey);
4539
+ if (subkey.length > CHUNK_SIZE && node.children.children.length > this.mapNodeThreshold) {
4540
+ node.convertListChildrenToMap();
4541
+ }
4542
+ return leaf;
4543
+ }
4544
+ depth += 1;
4545
+ const children = node.children;
4546
+ if (children instanceof ListChildren) {
4547
+ throw new Error("We handle list node earlier. If we fall through, we know it's for the `Map` case.");
4548
+ }
4549
+ if (children instanceof MapChildren) {
4550
+ const maybeNode = children.getChild(keyChunk);
4551
+ if (maybeNode !== undefined) {
4552
+ // simply go one level deeper
4553
+ node = maybeNode;
4554
+ }
4555
+ else {
4556
+ // we are trying to remove an item, but it does not exist
4557
+ if (value === undefined) {
4558
+ return null;
4559
+ }
4560
+ // no more child nodes, we insert a new one.
4561
+ const newNode = Node.withList();
4562
+ children.setChild(keyChunk, newNode);
4563
+ node = newNode;
4564
+ }
4565
+ continue;
4566
+ }
4567
+ assertNever(children);
4568
+ }
4569
+ }
4570
+ /**
4571
+ * Adds a new entry to the dictionary or updates the value of an existing key.
4572
+ *
4573
+ * If an entry with the given key already exists, its value is replaced
4574
+ * with the new one.
4575
+ *
4576
+ * @param key - The key to add or update in the dictionary.
4577
+ * @param value - The value to associate with the specified key.
4578
+ * @returns Nothing (`void`).
4579
+ */
4580
+ set(key, value) {
4581
+ const leaf = this.internalSet(key, value);
4582
+ if (leaf !== null) {
4583
+ this.keyvals.set(leaf.key, leaf);
4584
+ }
4585
+ }
4586
+ /**
4587
+ * Retrieves the value associated with the given key from the dictionary.
4588
+ *
4589
+ * If the key does not exist, this method returns `undefined`.
4590
+ *
4591
+ * @param key - The key whose associated value should be retrieved.
4592
+ * @returns The value associated with the specified key, or `undefined` if the key is not present.
4593
+ */
4594
+ get(key) {
4595
+ let node = this.root;
4596
+ const pathChunksGenerator = key.chunks(CHUNK_SIZE);
4597
+ let depth = 0;
4598
+ while (node !== undefined) {
4599
+ const maybePathChunk = pathChunksGenerator.next().value;
4600
+ if (node.children instanceof ListChildren) {
4601
+ const subkey = BytesBlob.blobFrom(key.raw.subarray(depth * CHUNK_SIZE));
4602
+ const child = node.children.find(subkey);
4603
+ if (child !== null) {
4604
+ return child.value;
4605
+ }
4606
+ }
4607
+ if (maybePathChunk === undefined) {
4608
+ return node.getLeaf()?.value;
4609
+ }
4610
+ if (node.children instanceof MapChildren) {
4611
+ const pathChunk = asOpaqueType(maybePathChunk);
4612
+ node = node.children.getChild(pathChunk);
4613
+ depth += 1;
4614
+ }
4615
+ }
4616
+ return undefined;
4617
+ }
4618
+ /**
4619
+ * Checks whether the dictionary contains an entry for the given key.
4620
+ *
4621
+ * ⚠️ **Note:** Avoid using `has(...)` together with `get(...)` in a pattern like this:
4622
+ *
4623
+ * ```ts
4624
+ * if (dict.has(key)) {
4625
+ * const value = dict.get(key);
4626
+ * ...
4627
+ * }
4628
+ * ```
4629
+ *
4630
+ * This approach performs two lookups for the same key.
4631
+ *
4632
+ * Instead, prefer the following pattern, which retrieves the value once:
4633
+ *
4634
+ * ```ts
4635
+ * const value = dict.get(key);
4636
+ * if (value !== undefined) {
4637
+ * ...
4638
+ * }
4639
+ * ```
4640
+ *
4641
+ * @param key - The key to check for.
4642
+ * @returns `true` if the dictionary contains an entry for the given key, otherwise `false`.
4643
+ */
4644
+ has(key) {
4645
+ return this.get(key) !== undefined;
4646
+ }
4647
+ /**
4648
+ * Removes an entry with the specified key from the dictionary.
4649
+ *
4650
+ * Internally, this calls {@link internalSet} with `undefined` to mark the entry as deleted.
4651
+ *
4652
+ * @param key - The key of the entry to remove.
4653
+ * @returns `true` if an entry was removed (i.e. the key existed), otherwise `false`.
4654
+ */
4655
+ delete(key) {
4656
+ const leaf = this.internalSet(key, undefined);
4657
+ if (leaf !== null) {
4658
+ this.keyvals.delete(leaf.key);
4659
+ return true;
4660
+ }
4661
+ return false;
4662
+ }
4663
+ /**
4664
+ * Returns an iterator over the keys in the dictionary.
4665
+ *
4666
+ * The iterator yields each key in insertion order.
4667
+ *
4668
+ * @returns An iterator over all keys in the dictionary.
4669
+ */
4670
+ keys() {
4671
+ return this.keyvals.keys();
4672
+ }
4673
+ /**
4674
+ * Returns an iterator over the values in the dictionary.
4675
+ *
4676
+ * The iterator yields each value in insertion order.
4677
+ *
4678
+ * @returns An iterator over all values in the dictionary.
4679
+ */
4680
+ *values() {
4681
+ for (const leaf of this.keyvals.values()) {
4682
+ yield leaf.value;
4683
+ }
4684
+ }
4685
+ /**
4686
+ * Returns an iterator over the `[key, value]` pairs in the dictionary.
4687
+ *
4688
+ * The iterator yields entries in insertion order.
4689
+ *
4690
+ * @returns An iterator over `[key, value]` tuples for each entry in the dictionary.
4691
+ */
4692
+ *entries() {
4693
+ for (const leaf of this.keyvals.values()) {
4694
+ yield [leaf.key, leaf.value];
4695
+ }
4696
+ }
4697
+ /**
4698
+ * Default iterator for the dictionary.
4699
+ *
4700
+ * Equivalent to calling {@link entries}.
4701
+ * Enables iteration with `for...of`:
4702
+ *
4703
+ * ```ts
4704
+ * for (const [key, value] of dict) {
4705
+ * ...
4706
+ * }
4707
+ * ```
4708
+ *
4709
+ * @returns An iterator over `[key, value]` pairs.
4710
+ */
4711
+ [Symbol.iterator]() {
4712
+ return this.entries();
4713
+ }
4714
+ /**
4715
+ * Creates a new sorted array of values, ordered by their corresponding keys.
4716
+ *
4717
+ * Iterates over all entries in the dictionary and sorts them according
4718
+ * to the provided comparator function applied to the keys.
4719
+ *
4720
+ * @param comparator - A comparator function that can compare two keys.
4721
+ *
4722
+ * @returns A new array containing all values from the dictionary,
4723
+ * sorted according to their keys.
4724
+ */
4725
+ toSortedArray(comparator) {
4726
+ const vals = Array.from(this);
4727
+ vals.sort((a, b) => comparator(a[0], b[0]).value);
4728
+ return vals.map((x) => x[1]);
4729
+ }
4730
+ }
4731
+ const CHUNK_SIZE = 6;
4732
+ /**
4733
+ * A function to transform a bytes chunk (up to 6 bytes into U48 number)
4734
+ *
4735
+ * Note that it uses 3 additional bits to store length(`value * 8 + len;`),
4736
+ * It is needed to distinguish shorter chunks that have 0s at the end, for example: [1, 2] and [1, 2, 0]
4737
+ * */
4738
+ function bytesAsU48(bytes) {
4739
+ const len = bytes.length;
4740
+ check `${len <= CHUNK_SIZE} Length has to be <= ${CHUNK_SIZE}, got: ${len}`;
4741
+ let value = bytes[3] | (bytes[2] << 8) | (bytes[1] << 16) | (bytes[0] << 24);
4742
+ for (let i = 4; i < bytes.length; i++) {
4743
+ value = value * 256 + bytes[i];
4744
+ }
4745
+ return value * 8 + len;
4746
+ }
4747
+ class Node {
4748
+ leaf;
4749
+ children;
4750
+ convertListChildrenToMap() {
4751
+ if (!(this.children instanceof ListChildren)) {
4752
+ return;
4753
+ }
4754
+ this.children = MapChildren.fromListNode(this.children);
4755
+ }
4756
+ static withList() {
4757
+ return new Node(undefined, ListChildren.new());
4758
+ }
4759
+ static withMap() {
4760
+ return new Node(undefined, MapChildren.new());
4761
+ }
4762
+ constructor(leaf, children) {
4763
+ this.leaf = leaf;
4764
+ this.children = children;
4765
+ }
4766
+ getLeaf() {
4767
+ return this.leaf;
4768
+ }
4769
+ remove(_key) {
4770
+ if (this.leaf === undefined) {
4771
+ return null;
4772
+ }
4773
+ const removedLeaf = this.leaf;
4774
+ this.leaf = undefined;
4775
+ return removedLeaf;
4776
+ }
4777
+ set(key, value) {
4778
+ if (this.leaf === undefined) {
4779
+ this.leaf = { key, value };
4780
+ return this.leaf;
4781
+ }
4782
+ this.leaf.value = value;
4783
+ return null;
4784
+ }
4785
+ }
4786
+ class ListChildren {
4787
+ children = [];
4788
+ constructor() { }
4789
+ find(key) {
4790
+ const result = this.children.find((item) => item[0].isEqualTo(key));
4791
+ if (result !== undefined) {
4792
+ return result[1];
4793
+ }
4794
+ return null;
4795
+ }
4796
+ remove(key) {
4797
+ const existingIndex = this.children.findIndex((item) => item[0].isEqualTo(key));
4798
+ if (existingIndex >= 0) {
4799
+ const ret = this.children.splice(existingIndex, 1);
4800
+ return ret[0][1];
4801
+ }
4802
+ return null;
4803
+ }
4804
+ insert(key, leaf) {
4805
+ const existingIndex = this.children.findIndex((item) => item[0].isEqualTo(key));
4806
+ if (existingIndex >= 0) {
4807
+ const existing = this.children[existingIndex];
4808
+ existing[1].value = leaf.value;
4809
+ return null;
4810
+ }
4811
+ this.children.push([key, leaf]);
4812
+ return leaf;
4813
+ }
4814
+ static new() {
4815
+ return new ListChildren();
4816
+ }
4817
+ }
4818
+ class MapChildren {
4819
+ children = new Map();
4820
+ constructor() { }
4821
+ static new() {
4822
+ return new MapChildren();
4823
+ }
4824
+ static fromListNode(node) {
4825
+ const mapNode = new MapChildren();
4826
+ for (const [key, leaf] of node.children) {
4827
+ const currentKeyChunk = asOpaqueType(BytesBlob.blobFrom(key.raw.subarray(0, CHUNK_SIZE)));
4828
+ const subKey = BytesBlob.blobFrom(key.raw.subarray(CHUNK_SIZE));
4829
+ let child = mapNode.getChild(currentKeyChunk);
4830
+ if (child === undefined) {
4831
+ child = Node.withList();
4832
+ mapNode.setChild(currentKeyChunk, child);
4833
+ }
4834
+ const children = child.children;
4835
+ children.insert(subKey, leaf);
4836
+ }
4837
+ return mapNode;
4838
+ }
4839
+ getChild(keyChunk) {
4840
+ const chunkAsNumber = bytesAsU48(keyChunk.raw);
4841
+ return this.children.get(chunkAsNumber);
4842
+ }
4843
+ setChild(keyChunk, node) {
4844
+ const chunkAsNumber = bytesAsU48(keyChunk.raw);
4845
+ this.children.set(chunkAsNumber, node);
4846
+ }
4847
+ }
4848
+
4849
+ /**
4850
+ * A map which uses hashes as keys.
4851
+ *
4852
+ * @deprecated
4853
+ * */
4854
+ class StringHashDictionary {
4425
4855
  // TODO [ToDr] [crit] We can't use `TrieHash` directly in the map,
4426
4856
  // because of the way it's being compared. Hence having `string` here.
4427
4857
  // This has to be benchmarked and re-written to a custom map most likely.
@@ -4486,6 +4916,16 @@ class HashDictionary {
4486
4916
  return this.map.delete(key.toString());
4487
4917
  }
4488
4918
  }
4919
+ /**
4920
+ * A value that indicates when `BlobDictionary` transforms Array nodes into Map nodes.
4921
+ * In practice, it doesn't matter much because, in real life, arrays in this structure usually have a length close to 1.
4922
+ */
4923
+ const BLOB_DICTIONARY_THRESHOLD$1 = 5;
4924
+ class HashDictionary extends BlobDictionary {
4925
+ constructor() {
4926
+ super(BLOB_DICTIONARY_THRESHOLD$1);
4927
+ }
4928
+ }
4489
4929
 
4490
4930
  /** A set specialized for storing hashes. */
4491
4931
  class HashSet {
@@ -4935,6 +5375,18 @@ class SortedSet extends SortedArray {
4935
5375
  }
4936
5376
  }
4937
5377
 
5378
+ function getTruncatedKey(key) {
5379
+ // Always return exactly TRUNCATED_HASH_SIZE bytes.
5380
+ if (key.length === TRUNCATED_HASH_SIZE) {
5381
+ return key;
5382
+ }
5383
+ return Bytes.fromBlob(key.raw.subarray(0, TRUNCATED_HASH_SIZE), TRUNCATED_HASH_SIZE);
5384
+ }
5385
+ /**
5386
+ * A value that indicates when `BlobDictionary` transforms Array nodes into Map nodes.
5387
+ * In practice, it doesn't matter much because, in real life, arrays in this structure usually have a length close to 1.
5388
+ */
5389
+ const BLOB_DICTIONARY_THRESHOLD = 5;
4938
5390
  /**
4939
5391
  * A collection of hash-based keys (likely `StateKey`s) which ignores
4940
5392
  * differences on the last byte.
@@ -4947,48 +5399,37 @@ class TruncatedHashDictionary {
4947
5399
  * Each key will be copied and have the last byte replace with a 0.
4948
5400
  */
4949
5401
  static fromEntries(entries) {
4950
- /** Copy key bytes of an entry and replace the last one with 0. */
4951
- const mapped = Array.from(entries).map(([key, value]) => {
4952
- const newKey = Bytes.zero(HASH_SIZE).asOpaque();
4953
- newKey.raw.set(key.raw.subarray(0, TRUNCATED_HASH_SIZE));
4954
- return [newKey, value];
4955
- });
4956
- return new TruncatedHashDictionary(HashDictionary.fromEntries(mapped));
5402
+ return new TruncatedHashDictionary(BlobDictionary.fromEntries(Array.from(entries).map(([key, value]) => [getTruncatedKey(key), value]), BLOB_DICTIONARY_THRESHOLD));
4957
5403
  }
4958
- /** A truncated key which we re-use to query the dictionary. */
4959
- truncatedKey = Bytes.zero(HASH_SIZE).asOpaque();
4960
5404
  constructor(dict) {
4961
5405
  this.dict = dict;
4962
5406
  }
4963
5407
  [TEST_COMPARE_USING]() {
4964
- return this.dict;
5408
+ return Array.from(this.dict);
4965
5409
  }
4966
5410
  /** Return number of items in the dictionary. */
4967
5411
  get size() {
4968
5412
  return this.dict.size;
4969
5413
  }
4970
5414
  /** Retrieve a value that matches the key on `TRUNCATED_HASH_SIZE`. */
4971
- get(fullKey) {
4972
- this.truncatedKey.raw.set(fullKey.raw.subarray(0, TRUNCATED_HASH_SIZE));
4973
- return this.dict.get(this.truncatedKey);
5415
+ get(key) {
5416
+ const truncatedKey = getTruncatedKey(key);
5417
+ return this.dict.get(truncatedKey);
4974
5418
  }
4975
5419
  /** Return true if the key is present in the dictionary */
4976
- has(fullKey) {
4977
- this.truncatedKey.raw.set(fullKey.raw.subarray(0, TRUNCATED_HASH_SIZE));
4978
- return this.dict.has(this.truncatedKey);
5420
+ has(key) {
5421
+ const truncatedKey = getTruncatedKey(key);
5422
+ return this.dict.has(truncatedKey);
4979
5423
  }
4980
5424
  /** Set or update a value that matches the key on `TRUNCATED_HASH_SIZE`. */
4981
- set(fullKey, value) {
4982
- // NOTE we can't use the the shared key here, since the collection will
4983
- // store the key for us, hence the copy.
4984
- const key = Bytes.zero(HASH_SIZE);
4985
- key.raw.set(fullKey.raw.subarray(0, TRUNCATED_HASH_SIZE));
4986
- this.dict.set(key.asOpaque(), value);
5425
+ set(key, value) {
5426
+ const truncatedKey = getTruncatedKey(key);
5427
+ this.dict.set(truncatedKey, value);
4987
5428
  }
4988
5429
  /** Remove a value that matches the key on `TRUNCATED_HASH_SIZE`. */
4989
- delete(fullKey) {
4990
- this.truncatedKey.raw.set(fullKey.raw.subarray(0, TRUNCATED_HASH_SIZE));
4991
- this.dict.delete(this.truncatedKey);
5430
+ delete(key) {
5431
+ const truncatedKey = getTruncatedKey(key);
5432
+ this.dict.delete(truncatedKey);
4992
5433
  }
4993
5434
  /** Iterator over values of the dictionary. */
4994
5435
  values() {
@@ -4996,26 +5437,28 @@ class TruncatedHashDictionary {
4996
5437
  }
4997
5438
  /** Iterator over entries of the dictionary (with truncated keys) */
4998
5439
  *entries() {
4999
- for (const [key, value] of this.dict.entries()) {
5000
- yield [Bytes.fromBlob(key.raw.subarray(0, TRUNCATED_HASH_SIZE), TRUNCATED_HASH_SIZE).asOpaque(), value];
5001
- }
5440
+ yield* this.dict.entries();
5002
5441
  }
5003
5442
  [Symbol.iterator]() {
5004
5443
  return this.entries();
5005
5444
  }
5006
5445
  }
5007
5446
 
5008
- var index$o = /*#__PURE__*/Object.freeze({
5447
+ var index$n = /*#__PURE__*/Object.freeze({
5009
5448
  __proto__: null,
5010
5449
  ArrayView: ArrayView,
5450
+ BlobDictionary: BlobDictionary,
5011
5451
  FixedSizeArray: FixedSizeArray,
5012
5452
  HashDictionary: HashDictionary,
5013
5453
  HashSet: HashSet,
5454
+ ListChildren: ListChildren,
5014
5455
  MultiMap: MultiMap,
5015
5456
  SortedArray: SortedArray,
5016
5457
  SortedSet: SortedSet,
5458
+ StringHashDictionary: StringHashDictionary,
5017
5459
  TruncatedHashDictionary: TruncatedHashDictionary,
5018
- asKnownSize: asKnownSize
5460
+ asKnownSize: asKnownSize,
5461
+ bytesAsU48: bytesAsU48
5019
5462
  });
5020
5463
 
5021
5464
  /**
@@ -5192,7 +5635,7 @@ var PvmBackend;
5192
5635
  PvmBackend[PvmBackend["Ananas"] = 1] = "Ananas";
5193
5636
  })(PvmBackend || (PvmBackend = {}));
5194
5637
 
5195
- var index$n = /*#__PURE__*/Object.freeze({
5638
+ var index$m = /*#__PURE__*/Object.freeze({
5196
5639
  __proto__: null,
5197
5640
  Bootnode: Bootnode,
5198
5641
  ChainSpec: ChainSpec,
@@ -6699,7 +7142,7 @@ function reencodeAsView(codec, object, chainSpec) {
6699
7142
  return Decoder.decodeObject(codec.View, encoded, chainSpec);
6700
7143
  }
6701
7144
 
6702
- var index$m = /*#__PURE__*/Object.freeze({
7145
+ var index$l = /*#__PURE__*/Object.freeze({
6703
7146
  __proto__: null,
6704
7147
  Block: Block,
6705
7148
  EpochMarker: EpochMarker,
@@ -6709,6 +7152,8 @@ var index$m = /*#__PURE__*/Object.freeze({
6709
7152
  SEGMENT_BYTES: SEGMENT_BYTES,
6710
7153
  TicketsMarker: TicketsMarker,
6711
7154
  ValidatorKeys: ValidatorKeys,
7155
+ W_E: W_E,
7156
+ W_S: W_S,
6712
7157
  assurances: assurances,
6713
7158
  codecPerEpochBlock: codecPerEpochBlock,
6714
7159
  codecPerValidator: codecPerValidator,
@@ -6969,7 +7414,7 @@ var json;
6969
7414
  json.object = object;
6970
7415
  })(json || (json = {}));
6971
7416
 
6972
- var index$l = /*#__PURE__*/Object.freeze({
7417
+ var index$k = /*#__PURE__*/Object.freeze({
6973
7418
  __proto__: null,
6974
7419
  get json () { return json; },
6975
7420
  parseFromJson: parseFromJson
@@ -7239,7 +7684,7 @@ const blockFromJson = (spec) => json.object({
7239
7684
  extrinsic: getExtrinsicFromJson(spec),
7240
7685
  }, ({ header, extrinsic }) => Block.create({ header, extrinsic }));
7241
7686
 
7242
- var index$k = /*#__PURE__*/Object.freeze({
7687
+ var index$j = /*#__PURE__*/Object.freeze({
7243
7688
  __proto__: null,
7244
7689
  blockFromJson: blockFromJson,
7245
7690
  disputesExtrinsicFromJson: disputesExtrinsicFromJson,
@@ -7733,7 +8178,7 @@ class Logger {
7733
8178
  }
7734
8179
  }
7735
8180
 
7736
- var index$j = /*#__PURE__*/Object.freeze({
8181
+ var index$i = /*#__PURE__*/Object.freeze({
7737
8182
  __proto__: null,
7738
8183
  get Level () { return Level; },
7739
8184
  Logger: Logger,
@@ -7948,7 +8393,7 @@ function isJsonObject(value) {
7948
8393
  return typeof value === "object" && value !== null && !Array.isArray(value);
7949
8394
  }
7950
8395
 
7951
- var index$i = /*#__PURE__*/Object.freeze({
8396
+ var index$h = /*#__PURE__*/Object.freeze({
7952
8397
  __proto__: null,
7953
8398
  DEFAULT_CONFIG: DEFAULT_CONFIG,
7954
8399
  DEV_CONFIG: DEV_CONFIG,
@@ -9157,11 +9602,32 @@ const ENTROPY_ENTRIES = 4;
9157
9602
 
9158
9603
  var UpdatePreimageKind;
9159
9604
  (function (UpdatePreimageKind) {
9160
- /** Insert new preimage and optionally update it's lookup history. */
9605
+ /**
9606
+ * Insert new preimage and optionally update it's lookup history.
9607
+ *
9608
+ * Used in: `provide`
9609
+ *
9610
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/383904383904?v=0.7.2
9611
+ */
9161
9612
  UpdatePreimageKind[UpdatePreimageKind["Provide"] = 0] = "Provide";
9162
- /** Remove a preimage and it's lookup history. */
9613
+ /**
9614
+ * Remove a preimage and it's lookup history.
9615
+ *
9616
+ * Used in: `forget` and `eject`
9617
+ *
9618
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/38c701380202?v=0.7.2
9619
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/379102379302?v=0.7.2
9620
+ */
9163
9621
  UpdatePreimageKind[UpdatePreimageKind["Remove"] = 1] = "Remove";
9164
- /** update or add lookup history for preimage hash/len to given value. */
9622
+ /**
9623
+ * Update or add lookup history for preimage hash/len to given value.
9624
+ *
9625
+ * Used in: `solicit` and `forget`
9626
+ *
9627
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/382802382802?v=0.7.2
9628
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/384002384b02?v=0.7.2
9629
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/38c60038ea00?v=0.7.2
9630
+ */
9165
9631
  UpdatePreimageKind[UpdatePreimageKind["UpdateOrAdd"] = 2] = "UpdateOrAdd";
9166
9632
  })(UpdatePreimageKind || (UpdatePreimageKind = {}));
9167
9633
  /**
@@ -9169,7 +9635,7 @@ var UpdatePreimageKind;
9169
9635
  *
9170
9636
  * Can be one of the following cases:
9171
9637
  * 1. Provide a new preimage blob and set the lookup history to available at `slot`.
9172
- * 2. Remove (expunge) a preimage and it's lookup history.
9638
+ * 2. Remove (forget) a preimage and it's lookup history.
9173
9639
  * 3. Update `LookupHistory` with given value.
9174
9640
  */
9175
9641
  class UpdatePreimage {
@@ -9742,7 +10208,7 @@ const serviceDataCodec = codec$1.dictionary(codec$1.u32.asOpaque(), serviceEntri
9742
10208
  sortKeys: (a, b) => a - b,
9743
10209
  });
9744
10210
 
9745
- var index$h = /*#__PURE__*/Object.freeze({
10211
+ var index$g = /*#__PURE__*/Object.freeze({
9746
10212
  __proto__: null,
9747
10213
  AUTHORIZATION_QUEUE_SIZE: AUTHORIZATION_QUEUE_SIZE,
9748
10214
  AccumulationOutput: AccumulationOutput,
@@ -10373,7 +10839,6 @@ class LeafNode {
10373
10839
  /**
10374
10840
  * Get the byte length of embedded value.
10375
10841
  *
10376
- * @remark
10377
10842
  * Note in case this node only contains hash this is going to be 0.
10378
10843
  */
10379
10844
  getValueLength() {
@@ -10384,7 +10849,6 @@ class LeafNode {
10384
10849
  /**
10385
10850
  * Returns the embedded value.
10386
10851
  *
10387
- * @remark
10388
10852
  * Note that this is going to be empty for a regular leaf node (i.e. containing a hash).
10389
10853
  */
10390
10854
  getValue() {
@@ -10394,7 +10858,6 @@ class LeafNode {
10394
10858
  /**
10395
10859
  * Returns contained value hash.
10396
10860
  *
10397
- * @remark
10398
10861
  * Note that for embedded value this is going to be full 0-padded 32 bytes.
10399
10862
  */
10400
10863
  getValueHash() {
@@ -10816,7 +11279,7 @@ const bitLookup = [
10816
11279
  [0b00000000, 8],
10817
11280
  ];
10818
11281
 
10819
- var index$g = /*#__PURE__*/Object.freeze({
11282
+ var index$f = /*#__PURE__*/Object.freeze({
10820
11283
  __proto__: null,
10821
11284
  BranchNode: BranchNode,
10822
11285
  InMemoryTrie: InMemoryTrie,
@@ -11183,7 +11646,7 @@ function loadState(spec, blake2b, entries) {
11183
11646
  * hashmap of `key -> value` entries.
11184
11647
  */
11185
11648
 
11186
- var index$f = /*#__PURE__*/Object.freeze({
11649
+ var index$e = /*#__PURE__*/Object.freeze({
11187
11650
  __proto__: null,
11188
11651
  SerializedService: SerializedService,
11189
11652
  SerializedState: SerializedState,
@@ -11432,7 +11895,7 @@ class InMemoryStates {
11432
11895
  async close() { }
11433
11896
  }
11434
11897
 
11435
- var index$e = /*#__PURE__*/Object.freeze({
11898
+ var index$d = /*#__PURE__*/Object.freeze({
11436
11899
  __proto__: null,
11437
11900
  InMemoryBlocks: InMemoryBlocks,
11438
11901
  InMemorySerializedStates: InMemorySerializedStates,
@@ -11796,7 +12259,7 @@ const initEc = async () => {
11796
12259
  await init.reedSolomon();
11797
12260
  };
11798
12261
 
11799
- var index$d = /*#__PURE__*/Object.freeze({
12262
+ var index$c = /*#__PURE__*/Object.freeze({
11800
12263
  __proto__: null,
11801
12264
  N_CHUNKS_REDUNDANCY: N_CHUNKS_REDUNDANCY,
11802
12265
  N_CHUNKS_REQUIRED: N_CHUNKS_REQUIRED,
@@ -12230,7 +12693,7 @@ class FuzzTarget {
12230
12693
  }
12231
12694
  }
12232
12695
 
12233
- var index$c = /*#__PURE__*/Object.freeze({
12696
+ var index$b = /*#__PURE__*/Object.freeze({
12234
12697
  __proto__: null,
12235
12698
  AncestryItem: AncestryItem,
12236
12699
  ErrorMessage: ErrorMessage,
@@ -12248,9 +12711,9 @@ var index$c = /*#__PURE__*/Object.freeze({
12248
12711
  stateRootCodec: stateRootCodec
12249
12712
  });
12250
12713
 
12251
- var index$b = /*#__PURE__*/Object.freeze({
12714
+ var index$a = /*#__PURE__*/Object.freeze({
12252
12715
  __proto__: null,
12253
- v1: index$c
12716
+ v1: index$b
12254
12717
  });
12255
12718
 
12256
12719
  /** Size of the transfer memo. */
@@ -12679,7 +13142,11 @@ class PartiallyUpdatedState {
12679
13142
  const service = this.state.getService(serviceId);
12680
13143
  return service?.getPreimage(hash) ?? null;
12681
13144
  }
12682
- /** Get status of a preimage of current service taking into account any updates. */
13145
+ /**
13146
+ * Get status of a preimage of current service taking into account any updates.
13147
+ *
13148
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/110201110201?v=0.7.2
13149
+ */
12683
13150
  getLookupHistory(currentTimeslot, serviceId, hash, length) {
12684
13151
  const updatedService = this.stateUpdate.services.updated.get(serviceId);
12685
13152
  /** Return lookup history item for newly created service */
@@ -12716,12 +13183,7 @@ class PartiallyUpdatedState {
12716
13183
  return new LookupHistoryItem(hash, updatedPreimage.length, tryAsLookupHistorySlots([currentTimeslot]));
12717
13184
  }
12718
13185
  case UpdatePreimageKind.Remove: {
12719
- const state = stateFallback();
12720
- // kinda impossible, since we know it's there because it's removed.
12721
- if (state === null) {
12722
- return null;
12723
- }
12724
- return new LookupHistoryItem(hash, state.length, tryAsLookupHistorySlots([...state.slots, currentTimeslot]));
13186
+ return null;
12725
13187
  }
12726
13188
  case UpdatePreimageKind.UpdateOrAdd: {
12727
13189
  return action.item;
@@ -13113,42 +13575,6 @@ class HostCallsManager {
13113
13575
  }
13114
13576
  }
13115
13577
 
13116
- /** Create a new gas counter instance depending on the gas value. */
13117
- function gasCounter(gas) {
13118
- return new GasCounterU64(tryAsU64(gas));
13119
- }
13120
- class GasCounterU64 {
13121
- gas;
13122
- initialGas;
13123
- constructor(gas) {
13124
- this.gas = gas;
13125
- this.initialGas = tryAsGas(gas);
13126
- }
13127
- set(g) {
13128
- this.gas = tryAsU64(g);
13129
- }
13130
- get() {
13131
- return tryAsGas(this.gas);
13132
- }
13133
- sub(g) {
13134
- const result = this.gas - tryAsU64(g);
13135
- if (result >= 0n) {
13136
- this.gas = tryAsU64(result);
13137
- return false;
13138
- }
13139
- this.gas = tryAsU64(0n);
13140
- return true;
13141
- }
13142
- used() {
13143
- const gasConsumed = tryAsU64(this.initialGas) - this.gas;
13144
- // In we have less than zero left we assume that all gas has been consumed.
13145
- if (gasConsumed < 0) {
13146
- return this.initialGas;
13147
- }
13148
- return tryAsGas(gasConsumed);
13149
- }
13150
- }
13151
-
13152
13578
  const tryAsMemoryIndex = (index) => {
13153
13579
  check `${index >= 0 && index <= MAX_MEMORY_INDEX} Incorrect memory index: ${index}!`;
13154
13580
  return asOpaqueType(index);
@@ -13871,7 +14297,7 @@ function getRegisters(argsLength) {
13871
14297
  return regs;
13872
14298
  }
13873
14299
 
13874
- var index$a = /*#__PURE__*/Object.freeze({
14300
+ var index$9 = /*#__PURE__*/Object.freeze({
13875
14301
  __proto__: null,
13876
14302
  MemorySegment: MemorySegment,
13877
14303
  SpiMemory: SpiMemory,
@@ -13930,7 +14356,7 @@ function extractCodeAndMetadata(blobWithMetadata) {
13930
14356
  return { metadata, code };
13931
14357
  }
13932
14358
 
13933
- var index$9 = /*#__PURE__*/Object.freeze({
14359
+ var index$8 = /*#__PURE__*/Object.freeze({
13934
14360
  __proto__: null,
13935
14361
  Program: Program,
13936
14362
  extractCodeAndMetadata: extractCodeAndMetadata
@@ -14894,6 +15320,42 @@ class BasicBlocks {
14894
15320
  }
14895
15321
  }
14896
15322
 
15323
+ /** Create a new gas counter instance depending on the gas value. */
15324
+ function gasCounter(gas) {
15325
+ return new GasCounterU64(tryAsU64(gas));
15326
+ }
15327
+ class GasCounterU64 {
15328
+ gas;
15329
+ initialGas;
15330
+ constructor(gas) {
15331
+ this.gas = gas;
15332
+ this.initialGas = tryAsGas(gas);
15333
+ }
15334
+ set(g) {
15335
+ this.gas = tryAsU64(g);
15336
+ }
15337
+ get() {
15338
+ return tryAsGas(this.gas);
15339
+ }
15340
+ sub(g) {
15341
+ const result = this.gas - tryAsU64(g);
15342
+ if (result >= 0n) {
15343
+ this.gas = tryAsU64(result);
15344
+ return false;
15345
+ }
15346
+ this.gas = tryAsU64(0n);
15347
+ return true;
15348
+ }
15349
+ used() {
15350
+ const gasConsumed = tryAsU64(this.initialGas) - this.gas;
15351
+ // In we have less than zero left we assume that all gas has been consumed.
15352
+ if (gasConsumed < 0) {
15353
+ return this.initialGas;
15354
+ }
15355
+ return tryAsGas(gasConsumed);
15356
+ }
15357
+ }
15358
+
14897
15359
  const instructionGasMap = (() => {
14898
15360
  const instructionGasMap = new Array(HIGHEST_INSTRUCTION_NUMBER + 1);
14899
15361
  for (let i = 0; i < HIGHEST_INSTRUCTION_NUMBER + 1; i++) {
@@ -16802,8 +17264,77 @@ class Interpreter {
16802
17264
  }
16803
17265
  }
16804
17266
 
16805
- var index$8 = /*#__PURE__*/Object.freeze({
17267
+ class DebuggerAdapter {
17268
+ pvm;
17269
+ constructor(useSbrkGas = false) {
17270
+ this.pvm = new Interpreter({ useSbrkGas });
17271
+ }
17272
+ resetGeneric(rawProgram, flatRegisters, initialGas) {
17273
+ this.pvm.resetGeneric(rawProgram, 0, tryAsGas(initialGas), new Registers(flatRegisters));
17274
+ }
17275
+ reset(rawProgram, pc, gas, maybeRegisters, maybeMemory) {
17276
+ this.pvm.resetGeneric(rawProgram, pc, tryAsGas(gas), maybeRegisters, maybeMemory);
17277
+ }
17278
+ getPageDump(pageNumber) {
17279
+ const page = this.pvm.getMemoryPage(pageNumber);
17280
+ if (page === null) {
17281
+ // page wasn't allocated so we return an empty page
17282
+ return safeAllocUint8Array(PAGE_SIZE$1);
17283
+ }
17284
+ if (page.length === PAGE_SIZE$1) {
17285
+ // page was allocated and has a proper size so we can simply return it
17286
+ return page;
17287
+ }
17288
+ // page was allocated but it is shorter than PAGE_SIZE so we have to extend it
17289
+ const fullPage = safeAllocUint8Array(PAGE_SIZE$1);
17290
+ fullPage.set(page);
17291
+ return fullPage;
17292
+ }
17293
+ setMemory(address, value) {
17294
+ this.pvm.memory.storeFrom(tryAsMemoryIndex(address), value);
17295
+ }
17296
+ getExitArg() {
17297
+ return this.pvm.getExitParam() ?? 0;
17298
+ }
17299
+ getStatus() {
17300
+ return this.pvm.getStatus();
17301
+ }
17302
+ nextStep() {
17303
+ return this.pvm.nextStep() === Status.OK;
17304
+ }
17305
+ nSteps(steps) {
17306
+ check `${steps >>> 0 > 0} Expected a positive integer got ${steps}`;
17307
+ for (let i = 0; i < steps; i++) {
17308
+ const isOk = this.nextStep();
17309
+ if (!isOk) {
17310
+ return false;
17311
+ }
17312
+ }
17313
+ return true;
17314
+ }
17315
+ getRegisters() {
17316
+ return this.pvm.registers.getAllU64();
17317
+ }
17318
+ setRegisters(registers) {
17319
+ this.pvm.registers.copyFrom(new Registers(registers));
17320
+ }
17321
+ getProgramCounter() {
17322
+ return this.pvm.getPC();
17323
+ }
17324
+ setNextProgramCounter(nextPc) {
17325
+ this.pvm.setNextPC(nextPc);
17326
+ }
17327
+ getGasLeft() {
17328
+ return BigInt(this.pvm.gas.get());
17329
+ }
17330
+ setGasLeft(gas) {
17331
+ this.pvm.gas.set(tryAsGas(gas));
17332
+ }
17333
+ }
17334
+
17335
+ var index$7 = /*#__PURE__*/Object.freeze({
16806
17336
  __proto__: null,
17337
+ DebuggerAdapter: DebuggerAdapter,
16807
17338
  Interpreter: Interpreter,
16808
17339
  Memory: Memory,
16809
17340
  MemoryBuilder: MemoryBuilder,
@@ -17393,7 +17924,7 @@ class InterpreterInstanceManager {
17393
17924
  }
17394
17925
  }
17395
17926
 
17396
- var index$7 = /*#__PURE__*/Object.freeze({
17927
+ var index$6 = /*#__PURE__*/Object.freeze({
17397
17928
  __proto__: null,
17398
17929
  HostCallMemory: HostCallMemory,
17399
17930
  HostCallRegisters: HostCallRegisters,
@@ -17486,7 +18017,7 @@ const codecServiceAccountInfoWithThresholdBalance = codec$1.object({
17486
18017
  parentService: codec$1.u32.convert((x) => x, tryAsServiceId),
17487
18018
  }, "ServiceAccountInfoWithThresholdBalance");
17488
18019
 
17489
- var index$6 = /*#__PURE__*/Object.freeze({
18020
+ var index$5 = /*#__PURE__*/Object.freeze({
17490
18021
  __proto__: null,
17491
18022
  AccumulationStateUpdate: AccumulationStateUpdate,
17492
18023
  CURRENT_SERVICE_ID: CURRENT_SERVICE_ID,
@@ -17641,154 +18172,9 @@ class Mountain {
17641
18172
  }
17642
18173
  }
17643
18174
 
17644
- var index$5 = /*#__PURE__*/Object.freeze({
17645
- __proto__: null,
17646
- MerkleMountainRange: MerkleMountainRange
17647
- });
17648
-
17649
- class DebuggerAdapter {
17650
- pvm;
17651
- constructor(useSbrkGas = false) {
17652
- this.pvm = new Interpreter({ useSbrkGas });
17653
- }
17654
- resetGeneric(rawProgram, flatRegisters, initialGas) {
17655
- this.pvm.resetGeneric(rawProgram, 0, tryAsGas(initialGas), new Registers(flatRegisters));
17656
- }
17657
- reset(rawProgram, pc, gas, maybeRegisters, maybeMemory) {
17658
- this.pvm.resetGeneric(rawProgram, pc, tryAsGas(gas), maybeRegisters, maybeMemory);
17659
- }
17660
- getPageDump(pageNumber) {
17661
- const page = this.pvm.getMemoryPage(pageNumber);
17662
- if (page === null) {
17663
- // page wasn't allocated so we return an empty page
17664
- return safeAllocUint8Array(PAGE_SIZE$1);
17665
- }
17666
- if (page.length === PAGE_SIZE$1) {
17667
- // page was allocated and has a proper size so we can simply return it
17668
- return page;
17669
- }
17670
- // page was allocated but it is shorter than PAGE_SIZE so we have to extend it
17671
- const fullPage = safeAllocUint8Array(PAGE_SIZE$1);
17672
- fullPage.set(page);
17673
- return fullPage;
17674
- }
17675
- setMemory(address, value) {
17676
- this.pvm.memory.storeFrom(tryAsMemoryIndex(address), value);
17677
- }
17678
- getExitArg() {
17679
- return this.pvm.getExitParam() ?? 0;
17680
- }
17681
- getStatus() {
17682
- return this.pvm.getStatus();
17683
- }
17684
- nextStep() {
17685
- return this.pvm.nextStep() === Status.OK;
17686
- }
17687
- nSteps(steps) {
17688
- check `${steps >>> 0 > 0} Expected a positive integer got ${steps}`;
17689
- for (let i = 0; i < steps; i++) {
17690
- const isOk = this.nextStep();
17691
- if (!isOk) {
17692
- return false;
17693
- }
17694
- }
17695
- return true;
17696
- }
17697
- getRegisters() {
17698
- return this.pvm.registers.getAllU64();
17699
- }
17700
- setRegisters(registers) {
17701
- this.pvm.registers.copyFrom(new Registers(registers));
17702
- }
17703
- getProgramCounter() {
17704
- return this.pvm.getPC();
17705
- }
17706
- setNextProgramCounter(nextPc) {
17707
- this.pvm.setNextPC(nextPc);
17708
- }
17709
- getGasLeft() {
17710
- return BigInt(this.pvm.gas.get());
17711
- }
17712
- setGasLeft(gas) {
17713
- this.pvm.gas.set(tryAsGas(gas));
17714
- }
17715
- }
17716
-
17717
18175
  var index$4 = /*#__PURE__*/Object.freeze({
17718
18176
  __proto__: null,
17719
- AccumulationStateUpdate: AccumulationStateUpdate,
17720
- ArgsDecoder: ArgsDecoder,
17721
- get ArgumentType () { return ArgumentType; },
17722
- BasicBlocks: BasicBlocks,
17723
- CURRENT_SERVICE_ID: CURRENT_SERVICE_ID,
17724
- get EjectError () { return EjectError; },
17725
- ExtendedWitdthImmediateDecoder: ExtendedWitdthImmediateDecoder,
17726
- get ForgetPreimageError () { return ForgetPreimageError; },
17727
- HostCallMemory: HostCallMemory,
17728
- HostCallRegisters: HostCallRegisters,
17729
- HostCallResult: HostCallResult,
17730
- ImmediateDecoder: ImmediateDecoder,
17731
- InsufficientFundsError: InsufficientFundsError,
17732
- MachineInstance: MachineInstance,
17733
- Mask: Mask,
17734
- get MemoryOperation () { return MemoryOperation; },
17735
- MemorySegment: MemorySegment,
17736
- NO_OF_REGISTERS: NO_OF_REGISTERS$1,
17737
- get NewServiceError () { return NewServiceError; },
17738
- NibblesDecoder: NibblesDecoder,
17739
- NoMachineError: NoMachineError,
17740
- OK: OK,
17741
- get PagesError () { return PagesError; },
17742
- PartiallyUpdatedState: PartiallyUpdatedState,
17743
- get PeekPokeError () { return PeekPokeError; },
17744
- PendingTransfer: PendingTransfer,
17745
- get PreimageStatusKind () { return PreimageStatusKind; },
17746
- Program: Program,
17747
- ProgramDecoder: ProgramDecoder,
17748
- get ProvidePreimageError () { return ProvidePreimageError; },
17749
- Pvm: DebuggerAdapter,
17750
- Registers: Registers,
17751
- get RequestPreimageError () { return RequestPreimageError; },
17752
- Result: Result$1,
17753
- SERVICE_ID_BYTES: SERVICE_ID_BYTES,
17754
- SegmentExportError: SegmentExportError,
17755
- SpiMemory: SpiMemory,
17756
- SpiProgram: SpiProgram,
17757
- TRANSFER_MEMO_BYTES: TRANSFER_MEMO_BYTES,
17758
- get TransferError () { return TransferError; },
17759
- UnprivilegedError: UnprivilegedError,
17760
- get UpdatePrivilegesError () { return UpdatePrivilegesError; },
17761
- WithDebug: WithDebug,
17762
- get ZeroVoidError () { return ZeroVoidError; },
17763
- asOpaqueType: asOpaqueType,
17764
- assertEmpty: assertEmpty,
17765
- assertNever: assertNever,
17766
- block: index$m,
17767
- bytes: index$t,
17768
- check: check,
17769
- clampU64ToU32: clampU64ToU32,
17770
- createResults: createResults,
17771
- decodeStandardProgram: decodeStandardProgram,
17772
- emptyRegistersBuffer: emptyRegistersBuffer,
17773
- extractCodeAndMetadata: extractCodeAndMetadata,
17774
- getServiceId: getServiceId,
17775
- getServiceIdOrCurrent: getServiceIdOrCurrent,
17776
- hash: index$p,
17777
- hostCallInfoAccount: codecServiceAccountInfoWithThresholdBalance,
17778
- inspect: inspect,
17779
- instructionArgumentTypeMap: instructionArgumentTypeMap,
17780
- interpreter: index$8,
17781
- isBrowser: isBrowser,
17782
- lazyInspect: lazyInspect,
17783
- measure: measure,
17784
- numbers: index$s,
17785
- resultToString: resultToString,
17786
- seeThrough: seeThrough,
17787
- slotsToPreimageStatus: slotsToPreimageStatus,
17788
- toMemoryOperation: toMemoryOperation,
17789
- tryAsMachineId: tryAsMachineId,
17790
- tryAsProgramCounter: tryAsProgramCounter,
17791
- writeServiceIdAsLeBytes: writeServiceIdAsLeBytes
18177
+ MerkleMountainRange: MerkleMountainRange
17792
18178
  });
17793
18179
 
17794
18180
  const ENTROPY_BYTES = 32;
@@ -18430,4 +18816,4 @@ var index = /*#__PURE__*/Object.freeze({
18430
18816
  TransitionHasher: TransitionHasher
18431
18817
  });
18432
18818
 
18433
- export { index$m as block, index$k as block_json, index$t as bytes, index$r as codec, index$o as collections, index$n as config, index$i as config_node, index$q as crypto, index$e as database, index$d as erasure_coding, index$b as fuzz_proto, index$p as hash, index$6 as jam_host_calls, index$l as json_parser, index$j as logger, index$5 as mmr, index$s as numbers, index$u as ordering, index$4 as pvm, index$7 as pvm_host_calls, index$8 as pvm_interpreter, index$9 as pvm_program, index$a as pvm_spi_decoder, index$3 as shuffling, index$h as state, index$2 as state_json, index$f as state_merkleization, index$1 as state_vectors, index as transition, index$g as trie, index$v as utils };
18819
+ export { index$l as block, index$j as block_json, index$s as bytes, index$q as codec, index$n as collections, index$m as config, index$h as config_node, index$p as crypto, index$d as database, index$c as erasure_coding, index$a as fuzz_proto, index$o as hash, index$5 as jam_host_calls, index$k as json_parser, index$i as logger, index$4 as mmr, index$r as numbers, index$t as ordering, index$7 as pvm, index$6 as pvm_host_calls, index$8 as pvm_program, index$9 as pvm_spi_decoder, index$3 as shuffling, index$g as state, index$2 as state_json, index$e as state_merkleization, index$1 as state_vectors, index as transition, index$f as trie, index$u as utils };