@typeberry/jam 0.1.0-3c30204 → 0.1.0-b2d0b72

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.
@@ -25323,29 +25323,17 @@ function isBrowser() {
25323
25323
  * We avoid using `node:assert` to keep compatibility with a browser environment.
25324
25324
  * Note the checks should not have any side effects, since we might decide
25325
25325
  * to remove all of them in a post-processing step.
25326
- */
25327
- function debug_check(condition, message) {
25328
- if (!condition) {
25329
- throw new Error(`Assertion failure: ${message ?? ""}`);
25330
- }
25331
- }
25332
- function cast(_a, condition) {
25333
- return condition;
25334
- }
25335
- /**
25336
- * Yet another function to perform runtime assertions.
25337
- * This function returns a new type to mark in the code that this value was checked and you don't have to do it again.
25338
25326
  *
25339
- * In the post-processing step all usages of this functions should be replaced with simple casting. An example:
25340
- * const x = checkAndType<number, CheckedNumber>(y);
25341
- * should be replaced with:
25342
- * const x = y as CheckedNumber;
25327
+ * NOTE the function is intended to be used as tagged template string for the performance
25328
+ * reasons.
25343
25329
  */
25344
- function ensure(a, condition, message) {
25345
- if (cast(a, condition)) {
25346
- return a;
25330
+ function debug_check(strings, condition, ...data) {
25331
+ if (!condition) {
25332
+ // add an empty value so that `data.length === strings.length`
25333
+ data.unshift("");
25334
+ const message = strings.map((v, index) => `${v}${data[index] ?? ""}`);
25335
+ throw new Error(`Assertion failure:${message.join("")}`);
25347
25336
  }
25348
- throw new Error(`Assertion failure: ${message ?? ""}`);
25349
25337
  }
25350
25338
  /**
25351
25339
  * The function can be used to make sure that a particular type is `never`
@@ -25515,7 +25503,7 @@ function result_resultToString(res) {
25515
25503
  const result_Result = {
25516
25504
  /** Create new [`Result`] with `Ok` status. */
25517
25505
  ok: (ok) => {
25518
- debug_check(ok !== undefined, "`Ok` type cannot be undefined.");
25506
+ debug_check `${ok !== undefined} 'ok' type cannot be undefined.`;
25519
25507
  return {
25520
25508
  isOk: true,
25521
25509
  isError: false,
@@ -25524,7 +25512,7 @@ const result_Result = {
25524
25512
  },
25525
25513
  /** Create new [`Result`] with `Error` status. */
25526
25514
  error: (error, details = "") => {
25527
- debug_check(error !== undefined, "`Error` type cannot be undefined.");
25515
+ debug_check `${error !== undefined} 'Error' type cannot be undefined.`;
25528
25516
  return {
25529
25517
  isOk: false,
25530
25518
  isError: true,
@@ -25808,7 +25796,10 @@ class bitvec_BitVec {
25808
25796
  constructor(data, bitLength) {
25809
25797
  this.data = data;
25810
25798
  this.bitLength = bitLength;
25811
- debug_check(data.length * 8 >= bitLength, `Not enough bytes in the data array. Need ${data.length * 8} has ${bitLength}.`);
25799
+ debug_check `
25800
+ ${data.length * 8 >= bitLength}
25801
+ Not enough bytes in the data array. Need ${data.length * 8} has ${bitLength}.
25802
+ `;
25812
25803
  this.byteLength = Math.ceil(bitLength / 8);
25813
25804
  }
25814
25805
  /** Return a raw in-memory representation of this [`BitVec`]. */
@@ -25817,7 +25808,10 @@ class bitvec_BitVec {
25817
25808
  }
25818
25809
  /** Perform OR operation on all bits in place. */
25819
25810
  sumWith(other) {
25820
- debug_check(other.bitLength === this.bitLength, `Invalid bit length for sumWith: ${other.bitLength} vs ${this.bitLength}`);
25811
+ debug_check `
25812
+ ${other.bitLength === this.bitLength}
25813
+ Invalid bit length for sumWith: ${other.bitLength} vs ${this.bitLength}
25814
+ `;
25821
25815
  const otherRaw = other.raw;
25822
25816
  for (let i = 0; i < this.byteLength; i++) {
25823
25817
  this.data[i] |= otherRaw[i];
@@ -25827,7 +25821,7 @@ class bitvec_BitVec {
25827
25821
  * Set the bit at index `idx` to value `val`.
25828
25822
  */
25829
25823
  setBit(idx, val) {
25830
- debug_check(idx < this.bitLength, `Index out of bounds. Need ${idx} has ${this.bitLength}.`);
25824
+ debug_check `${idx >= 0 && idx < this.bitLength} Index out of bounds. Need ${idx} has ${this.bitLength}.`;
25831
25825
  const byteIndex = Math.floor(idx / 8);
25832
25826
  const bitIndexInByte = idx % 8;
25833
25827
  const mask = 1 << bitIndexInByte;
@@ -25842,7 +25836,7 @@ class bitvec_BitVec {
25842
25836
  * Return `true` if the bit at index `idx` is set.
25843
25837
  */
25844
25838
  isSet(idx) {
25845
- debug_check(idx < this.bitLength, `Index out of bounds. Need ${idx} has ${this.bitLength}.`);
25839
+ debug_check `${idx >= 0 && idx < this.bitLength} Index out of bounds. Need ${idx} has ${this.bitLength}.`;
25846
25840
  const byteIndex = Math.floor(idx / 8);
25847
25841
  const bitIndexInByte = idx % 8;
25848
25842
  const mask = 1 << bitIndexInByte;
@@ -26009,7 +26003,7 @@ class bytes_BytesBlob {
26009
26003
  }
26010
26004
  /** Create a new [`BytesBlob`] from an array of bytes. */
26011
26005
  static blobFromNumbers(v) {
26012
- debug_check(v.find((x) => (x & 0xff) !== x) === undefined, "BytesBlob.blobFromNumbers used with non-byte number array.");
26006
+ debug_check `${v.find((x) => (x & 0xff) !== x) === undefined} BytesBlob.blobFromNumbers used with non-byte number array.`;
26013
26007
  const arr = new Uint8Array(v);
26014
26008
  return new bytes_BytesBlob(arr);
26015
26009
  }
@@ -26053,7 +26047,7 @@ class bytes_Bytes extends bytes_BytesBlob {
26053
26047
  length;
26054
26048
  constructor(raw, len) {
26055
26049
  super(raw);
26056
- debug_check(raw.byteLength === len, `Given buffer has incorrect size ${raw.byteLength} vs expected ${len}`);
26050
+ debug_check `${raw.byteLength === len} Given buffer has incorrect size ${raw.byteLength} vs expected ${len}`;
26057
26051
  this.length = len;
26058
26052
  }
26059
26053
  /** Create new [`Bytes<X>`] given a backing buffer and it's length. */
@@ -26062,7 +26056,7 @@ class bytes_Bytes extends bytes_BytesBlob {
26062
26056
  }
26063
26057
  /** Create new [`Bytes<X>`] given an array of bytes and it's length. */
26064
26058
  static fromNumbers(v, len) {
26065
- debug_check(v.find((x) => (x & 0xff) !== x) === undefined, "Bytes.fromNumbers used with non-byte number array.");
26059
+ debug_check `${v.find((x) => (x & 0xff) !== x) === undefined} Bytes.fromNumbers used with non-byte number array.`;
26066
26060
  const x = new Uint8Array(v);
26067
26061
  return new bytes_Bytes(x, len);
26068
26062
  }
@@ -26073,7 +26067,7 @@ class bytes_Bytes extends bytes_BytesBlob {
26073
26067
  // TODO [ToDr] `fill` should have the argments swapped to align with the rest.
26074
26068
  /** Create a [`Bytes<X>`] with all bytes filled with given input number. */
26075
26069
  static fill(len, input) {
26076
- debug_check((input & 0xff) === input, "Input has to be a byte.");
26070
+ debug_check `${(input & 0xff) === input} Input has to be a byte.`;
26077
26071
  const bytes = bytes_Bytes.zero(len);
26078
26072
  bytes.raw.fill(input, 0, len);
26079
26073
  return bytes;
@@ -26096,7 +26090,7 @@ class bytes_Bytes extends bytes_BytesBlob {
26096
26090
  }
26097
26091
  /** Compare the sequence to another one. */
26098
26092
  isEqualTo(other) {
26099
- debug_check(this.length === other.length, "Comparing incorrectly typed bytes!");
26093
+ debug_check `${this.length === other.length} Comparing incorrectly typed bytes!`;
26100
26094
  return u8ArraySameLengthEqual(this.raw, other.raw);
26101
26095
  }
26102
26096
  /** Converts current type into some opaque extension. */
@@ -26105,7 +26099,7 @@ class bytes_Bytes extends bytes_BytesBlob {
26105
26099
  }
26106
26100
  }
26107
26101
  function byteFromString(s) {
26108
- debug_check(s.length === 2, "Two-character string expected");
26102
+ debug_check `${s.length === 2} Two-character string expected`;
26109
26103
  const a = numberFromCharCode(s.charCodeAt(0));
26110
26104
  const b = numberFromCharCode(s.charCodeAt(1));
26111
26105
  return (a << 4) | b;
@@ -26159,42 +26153,53 @@ const bytesBlobComparator = (a, b) => a.compare(b);
26159
26153
 
26160
26154
  ;// CONCATENATED MODULE: ./packages/core/numbers/index.ts
26161
26155
 
26162
- const asWithBytesRepresentation = (v) => v;
26156
+ const asTypedNumber = (v) => v;
26163
26157
  const MAX_VALUE_U8 = 0xff;
26164
26158
  const MAX_VALUE_U16 = 0xffff;
26165
26159
  const MAX_VALUE_U32 = 0xffff_ffff;
26166
26160
  const MAX_VALUE_U64 = 0xffffffffffffffffn;
26167
26161
  /** Attempt to cast an input number into U8. */
26168
- const tryAsU8 = (v) => ensure(v, isU8(v), `input must have one-byte representation, got ${v}`);
26162
+ const tryAsU8 = (v) => {
26163
+ debug_check `${isU8(v)} input must have one-byte representation, got ${v}`;
26164
+ return asTypedNumber(v);
26165
+ };
26169
26166
  /** Check if given number is a valid U8 number. */
26170
26167
  const isU8 = (v) => (v & MAX_VALUE_U8) === v;
26171
26168
  /** Attempt to cast an input number into U16. */
26172
- const numbers_tryAsU16 = (v) => ensure(v, isU16(v), `input must have two-byte representation, got ${v}`);
26169
+ const numbers_tryAsU16 = (v) => {
26170
+ debug_check `${isU16(v)} input must have two-byte representation, got ${v}`;
26171
+ return asTypedNumber(v);
26172
+ };
26173
26173
  /** Check if given number is a valid U16 number. */
26174
26174
  const isU16 = (v) => (v & MAX_VALUE_U16) === v;
26175
26175
  /** Attempt to cast an input number into U32. */
26176
- const numbers_tryAsU32 = (v) => ensure(v, isU32(v), `input must have four-byte representation, got ${v}`);
26176
+ const numbers_tryAsU32 = (v) => {
26177
+ debug_check `${isU32(v)} input must have four-byte representation, got ${v}`;
26178
+ return asTypedNumber(v);
26179
+ };
26177
26180
  /** Check if given number is a valid U32 number. */
26178
26181
  const isU32 = (v) => (v & MAX_VALUE_U32) >>> 0 === v;
26179
26182
  /** Attempt to cast an input number into U64. */
26180
26183
  const tryAsU64 = (x) => {
26181
26184
  const v = BigInt(x);
26182
- return ensure(v, isU64(v), `input must have eight-byte representation, got ${x}`);
26185
+ debug_check `${isU64(v)} input must have eight-byte representation, got ${x}`;
26186
+ return asTypedNumber(v);
26183
26187
  };
26184
26188
  /** Check if given number is a valid U64 number. */
26185
26189
  const isU64 = (v) => (v & MAX_VALUE_U64) === v;
26186
26190
  /** Collate two U32 parts into one U64. */
26187
26191
  const u64FromParts = ({ lower, upper }) => {
26188
26192
  const val = (BigInt(upper) << 32n) + BigInt(lower);
26189
- return asWithBytesRepresentation(val);
26193
+ return asTypedNumber(val);
26190
26194
  };
26191
26195
  /** Split U64 into lower & upper parts. */
26192
26196
  const u64IntoParts = (v) => {
26193
- const lower = v & (2n ** 32n - 1n);
26194
- const upper = v >> 32n;
26197
+ // Number(...) safe: both parts are <= 0xffffffff
26198
+ const lower = Number(v & (2n ** 32n - 1n));
26199
+ const upper = Number(v >> 32n);
26195
26200
  return {
26196
- lower: asWithBytesRepresentation(Number(lower)),
26197
- upper: asWithBytesRepresentation(Number(upper)),
26201
+ lower: asTypedNumber(lower),
26202
+ upper: asTypedNumber(upper),
26198
26203
  };
26199
26204
  };
26200
26205
  /**
@@ -26234,8 +26239,8 @@ function numbers_u32AsLeBytes(value) {
26234
26239
  * Interpret 4-byte `Uint8Array` as U32 written as little endian.
26235
26240
  */
26236
26241
  function leBytesAsU32(uint8Array) {
26237
- check(uint8Array.length === 4, "Input must be a Uint8Array of length 4");
26238
- return asWithBytesRepresentation(uint8Array[0] | (uint8Array[1] << 8) | (uint8Array[2] << 16) | (uint8Array[3] << 24));
26242
+ check `${uint8Array.length === 4} Input must be a Uint8Array of length 4`;
26243
+ return asTypedNumber(uint8Array[0] | (uint8Array[1] << 8) | (uint8Array[2] << 16) | (uint8Array[3] << 24));
26239
26244
  }
26240
26245
  /** Get the smallest value between U64 a and values given as input parameters. */
26241
26246
  const minU64 = (a, ...values) => values.reduce((min, value) => (value > min ? min : value), a);
@@ -26526,7 +26531,7 @@ class decoder_Decoder {
26526
26531
  this.skip(newOffset - this.offset);
26527
26532
  }
26528
26533
  else {
26529
- debug_check(newOffset >= 0, "The offset has to be positive");
26534
+ debug_check `${newOffset >= 0} The offset has to be positive`;
26530
26535
  this.offset = newOffset;
26531
26536
  }
26532
26537
  }
@@ -26554,7 +26559,7 @@ class decoder_Decoder {
26554
26559
  return num;
26555
26560
  }
26556
26561
  ensureHasBytes(bytes) {
26557
- debug_check(bytes >= 0, "Negative number of bytes given.");
26562
+ debug_check `${bytes >= 0} Negative number of bytes given.`;
26558
26563
  if (this.offset + bytes > this.source.length) {
26559
26564
  throw new Error(`Attempting to decode more data than there is left. Need ${bytes}, left: ${this.source.length - this.offset}.`);
26560
26565
  }
@@ -26562,7 +26567,7 @@ class decoder_Decoder {
26562
26567
  }
26563
26568
  const MASKS = [0xff, 0xfe, 0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x80];
26564
26569
  function decodeVariableLengthExtraBytes(firstByte) {
26565
- debug_check(firstByte >= 0 && firstByte < 256, `Incorrect byte value: ${firstByte}`);
26570
+ debug_check `${firstByte >= 0 && firstByte < 256} Incorrect byte value: ${firstByte}`;
26566
26571
  for (let i = 0; i < MASKS.length; i++) {
26567
26572
  if (firstByte >= MASKS[i]) {
26568
26573
  return 8 - i;
@@ -26717,7 +26722,7 @@ class descriptor_Descriptor {
26717
26722
 
26718
26723
 
26719
26724
  function tryAsExactBytes(a) {
26720
- check(a.isExact, "The value is not exact size estimation!");
26725
+ check `${a.isExact} The value is not exact size estimation!`;
26721
26726
  return a.bytes;
26722
26727
  }
26723
26728
  function addSizeHints(a, b) {
@@ -26824,8 +26829,8 @@ class encoder_Encoder {
26824
26829
  // we still allow positive numbers from `[maxNum / 2, maxNum)`.
26825
26830
  // So it does not matter if the argument is a negative value,
26826
26831
  // OR if someone just gave us two-complement already.
26827
- debug_check(num < maxNum, "Only for numbers up to 2**64 - 1");
26828
- debug_check(-num <= maxNum / 2n, "Only for numbers down to -2**63");
26832
+ debug_check `${num < maxNum} Only for numbers up to 2**64 - 1`;
26833
+ debug_check `${-num <= maxNum / 2n} Only for numbers down to -2**63`;
26829
26834
  this.ensureBigEnough(8);
26830
26835
  this.dataView.setBigInt64(this.offset, num, true);
26831
26836
  this.offset += 8;
@@ -26889,8 +26894,8 @@ class encoder_Encoder {
26889
26894
  // we still allow positive numbers from `[maxNum / 2, maxNum)`.
26890
26895
  // So it does not matter if the argument is a negative value,
26891
26896
  // OR if someone just gave us two-complement already.
26892
- debug_check(num < maxNum, `Only for numbers up to 2**${BITS * bytesToEncode} - 1`);
26893
- debug_check(-num <= maxNum / 2, `Only for numbers down to -2**${BITS * bytesToEncode - 1}`);
26897
+ debug_check `${num < maxNum} Only for numbers up to 2**${BITS * bytesToEncode} - 1`;
26898
+ debug_check `${-num <= maxNum / 2} Only for numbers down to -2**${BITS * bytesToEncode - 1}`;
26894
26899
  this.ensureBigEnough(bytesToEncode);
26895
26900
  }
26896
26901
  /**
@@ -26901,8 +26906,8 @@ class encoder_Encoder {
26901
26906
  * https://graypaper.fluffylabs.dev/#/579bd12/365202365202
26902
26907
  */
26903
26908
  varU32(num) {
26904
- debug_check(num >= 0, "Only for natural numbers.");
26905
- debug_check(num < 2 ** 32, "Only for numbers up to 2**32");
26909
+ debug_check `${num >= 0} Only for natural numbers.`;
26910
+ debug_check `${num < 2 ** 32} Only for numbers up to 2**32`;
26906
26911
  this.varU64(BigInt(num));
26907
26912
  }
26908
26913
  /**
@@ -27053,7 +27058,7 @@ class encoder_Encoder {
27053
27058
  * https://graypaper.fluffylabs.dev/#/579bd12/374400374400
27054
27059
  */
27055
27060
  sequenceVarLen(encode, elements) {
27056
- debug_check(elements.length <= 2 ** 32, "Wow, that's a nice long sequence you've got here.");
27061
+ debug_check `${elements.length <= 2 ** 32} Wow, that's a nice long sequence you've got here.`;
27057
27062
  this.varU32(numbers_tryAsU32(elements.length));
27058
27063
  this.sequenceFixLen(encode, elements);
27059
27064
  }
@@ -27074,7 +27079,7 @@ class encoder_Encoder {
27074
27079
  * anyway, so if we really should throw we will.
27075
27080
  */
27076
27081
  ensureBigEnough(length, options = { silent: false }) {
27077
- debug_check(length >= 0, "Negative length given");
27082
+ debug_check `${length >= 0} Negative length given`;
27078
27083
  const newLength = this.offset + length;
27079
27084
  if (newLength > MAX_LENGTH) {
27080
27085
  if (options.silent) {
@@ -27210,10 +27215,12 @@ class ObjectView {
27210
27215
  decodeUpTo(field) {
27211
27216
  const index = this.descriptorsKeys.indexOf(field);
27212
27217
  const lastField = this.descriptorsKeys[this.lastDecodedFieldIdx];
27213
- debug_check(this.lastDecodedFieldIdx < index, `Unjustified call to 'decodeUpTo' -
27218
+ debug_check `
27219
+ ${this.lastDecodedFieldIdx < index}
27220
+ Unjustified call to 'decodeUpTo' -
27214
27221
  the index ($Blobindex}, ${String(field)})
27215
27222
  is already decoded (${this.lastDecodedFieldIdx}, ${String(lastField)}).
27216
- `);
27223
+ `;
27217
27224
  let lastItem = this.cache.get(lastField);
27218
27225
  const skipper = new Skipper(this.decoder);
27219
27226
  // now skip all of the fields and further populate the cache.
@@ -27229,8 +27236,10 @@ class ObjectView {
27229
27236
  this.cache.set(field, lastItem);
27230
27237
  this.lastDecodedFieldIdx = i;
27231
27238
  }
27232
- const last = ensure(lastItem, lastItem !== undefined, "Last item must be set, since the loop turns at least once.");
27233
- return last;
27239
+ if (lastItem === undefined) {
27240
+ throw new Error("Last item must be set, since the loop turns at least once.");
27241
+ }
27242
+ return lastItem;
27234
27243
  }
27235
27244
  }
27236
27245
  /**
@@ -27263,8 +27272,10 @@ class SequenceView {
27263
27272
  *[Symbol.iterator]() {
27264
27273
  for (let i = 0; i < this.length; i++) {
27265
27274
  const val = this.get(i);
27266
- const v = ensure(val, val !== undefined, "We are within 0..this.length so all items are defined.");
27267
- yield v;
27275
+ if (val === undefined) {
27276
+ throw new Error("We are within 0..this.length so all items are defined.");
27277
+ }
27278
+ yield val;
27268
27279
  }
27269
27280
  }
27270
27281
  /** Create an array of all views mapped to some particular value. */
@@ -27307,7 +27318,10 @@ class SequenceView {
27307
27318
  return bytes_BytesBlob.blobFrom(this.decoder.source.subarray(this.initialDecoderOffset, this.decoder.bytesRead()));
27308
27319
  }
27309
27320
  decodeUpTo(index) {
27310
- debug_check(this.lastDecodedIdx < index, `Unjustified call to 'decodeUpTo' - the index (${index}) is already decoded (${this.lastDecodedIdx}).`);
27321
+ debug_check `
27322
+ ${this.lastDecodedIdx < index}
27323
+ Unjustified call to 'decodeUpTo' - the index (${index}) is already decoded (${this.lastDecodedIdx}).
27324
+ `;
27311
27325
  let lastItem = this.cache.get(this.lastDecodedIdx);
27312
27326
  const skipper = new Skipper(this.decoder);
27313
27327
  // now skip all of the fields and further populate the cache.
@@ -27322,8 +27336,10 @@ class SequenceView {
27322
27336
  this.cache.set(i, lastItem);
27323
27337
  this.lastDecodedIdx = i;
27324
27338
  }
27325
- const last = ensure(lastItem, lastItem !== undefined, "Last item must be set, since the loop turns at least once.");
27326
- return last;
27339
+ if (lastItem === undefined) {
27340
+ throw new Error("Last item must be set, since the loop turns at least once.");
27341
+ }
27342
+ return lastItem;
27327
27343
  }
27328
27344
  }
27329
27345
 
@@ -27356,7 +27372,10 @@ const TYPICAL_DICTIONARY_LENGTH = 32;
27356
27372
  */
27357
27373
  function readonlyArray(desc) {
27358
27374
  return desc.convert((x) => {
27359
- debug_check(Array.isArray(x), `Non-arrays are not supported as 'readonly': got ${typeof x}, ${x}`);
27375
+ debug_check `
27376
+ ${Array.isArray(x)}
27377
+ Non-arrays are not supported as 'readonly': got ${typeof x}, ${x}
27378
+ `;
27360
27379
  // NOTE [ToDr] This assumption is incorrect in general, but it's documented
27361
27380
  // in the general note. We avoid `.slice()` the array for performance reasons.
27362
27381
  return x;
@@ -28311,10 +28330,17 @@ async function initAll() {
28311
28330
  await init.ed25519();
28312
28331
  await init.reedSolomon();
28313
28332
  }
28333
+ function initOnce(doInit) {
28334
+ let ready = null;
28335
+ return async () => {
28336
+ if (ready === null) ready = doInit();
28337
+ return await ready;
28338
+ };
28339
+ }
28314
28340
  const init = {
28315
- bandersnatch: async () => await bandersnatch_default({ module_or_path: await bandersnatch_bg_default() }),
28316
- ed25519: async () => await ed25519_wasm_default({ module_or_path: await ed25519_wasm_bg_default() }),
28317
- reedSolomon: async () => await reed_solomon_wasm_default({ module_or_path: await reed_solomon_wasm_bg_default() })
28341
+ bandersnatch: initOnce(async () => await bandersnatch_default({ module_or_path: await bandersnatch_bg_default() })),
28342
+ ed25519: initOnce(async () => await ed25519_wasm_default({ module_or_path: await ed25519_wasm_bg_default() })),
28343
+ reedSolomon: initOnce(async () => await reed_solomon_wasm_default({ module_or_path: await reed_solomon_wasm_bg_default() }))
28318
28344
  };
28319
28345
 
28320
28346
  //#endregion
@@ -28336,7 +28362,7 @@ const BLS_KEY_BYTES = 144;
28336
28362
  /** Derive a Bandersnatch public key from a seed. */
28337
28363
  function bandersnatch_publicKey(seed) {
28338
28364
  const key = bandersnatch.derive_public_key(seed);
28339
- check(key[0] === 0, "Invalid Bandersnatch public key derived from seed");
28365
+ check `${key[0] === 0} Invalid Bandersnatch public key derived from seed`;
28340
28366
  return Bytes.fromBlob(key.subarray(1), BANDERSNATCH_KEY_BYTES).asOpaque();
28341
28367
  }
28342
28368
 
@@ -28824,7 +28850,7 @@ async function ed25519_verify(input) {
28824
28850
  data.set(signature.raw, offset);
28825
28851
  offset += ED25519_SIGNATURE_BYTES;
28826
28852
  const messageLength = message.length;
28827
- debug_check(messageLength < 256, `Message needs to be shorter than 256 bytes. Got: ${messageLength}`);
28853
+ debug_check `${messageLength < 256} Message needs to be shorter than 256 bytes. Got: ${messageLength}`;
28828
28854
  data[offset] = messageLength;
28829
28855
  offset += 1;
28830
28856
  data.set(message.raw, offset);
@@ -28908,7 +28934,7 @@ class PageAllocator {
28908
28934
  // TODO [ToDr] Benchmark the performance!
28909
28935
  constructor(hashesPerPage) {
28910
28936
  this.hashesPerPage = hashesPerPage;
28911
- check(hashesPerPage > 0 && hashesPerPage >>> 0 === hashesPerPage, "Expected a non-zero integer.");
28937
+ check `${hashesPerPage > 0 && hashesPerPage >>> 0 === hashesPerPage} Expected a non-zero integer.`;
28912
28938
  this.resetPage();
28913
28939
  }
28914
28940
  resetPage() {
@@ -29205,8 +29231,8 @@ class MultiMap {
29205
29231
  * if needed.
29206
29232
  */
29207
29233
  constructor(keysLength, keyMappers) {
29208
- check(keysLength > 0, "Keys cannot be empty.");
29209
- check(keyMappers === undefined || keyMappers.length === keysLength, "Incorrect number of key mappers given!");
29234
+ check `${keysLength > 0} Keys cannot be empty.`;
29235
+ check `${keyMappers === undefined || keyMappers.length === keysLength} Incorrect number of key mappers given!`;
29210
29236
  this.data = new Map();
29211
29237
  this.keyMappers = keyMappers === undefined ? Array(keysLength).fill(null) : keyMappers;
29212
29238
  }
@@ -29307,7 +29333,7 @@ class FixedSizeArray extends Array {
29307
29333
  this.fixedLength = this.length;
29308
29334
  }
29309
29335
  static new(data, len) {
29310
- debug_check(data.length === len, `Expected an array of size: ${len}, got: ${data.length}`);
29336
+ debug_check `${data.length === len} Expected an array of size: ${len}, got: ${data.length}`;
29311
29337
  const arr = new FixedSizeArray(len);
29312
29338
  for (let i = 0; i < len; i++) {
29313
29339
  arr[i] = data[i];
@@ -29441,7 +29467,7 @@ class SortedArray {
29441
29467
  }
29442
29468
  /** Create a new SortedSet from two sorted collections. */
29443
29469
  static fromTwoSortedCollections(first, second) {
29444
- debug_check(first.comparator === second.comparator, "Cannot merge arrays if they do not use the same comparator");
29470
+ debug_check `${first.comparator === second.comparator} Cannot merge arrays if they do not use the same comparator`;
29445
29471
  const comparator = first.comparator;
29446
29472
  const arr1 = first.array;
29447
29473
  const arr1Length = arr1.length;
@@ -29561,7 +29587,7 @@ class sorted_set_SortedSet extends SortedArray {
29561
29587
  }
29562
29588
  /** Create a new SortedSet from two sorted collections. */
29563
29589
  static fromTwoSortedCollections(first, second) {
29564
- debug_check(first.comparator === second.comparator, "Cannot merge arrays if they do not use the same comparator");
29590
+ debug_check `${first.comparator === second.comparator} Cannot merge arrays if they do not use the same comparator`;
29565
29591
  const comparator = first.comparator;
29566
29592
  if (first.length === 0) {
29567
29593
  return sorted_set_SortedSet.fromSortedArray(comparator, second.array);
@@ -30582,7 +30608,10 @@ const tryAsCoreIndex = (v) => opaque_asOpaqueType(numbers_tryAsU16(v));
30582
30608
  /** Attempt to convert a number into `Epoch`. */
30583
30609
  const tryAsEpoch = (v) => asOpaqueType(tryAsU32(v));
30584
30610
  function tryAsPerValidator(array, spec) {
30585
- debug_check(array.length === spec.validatorsCount, `Invalid per-validator array length. Expected ${spec.validatorsCount}, got: ${array.length}`);
30611
+ debug_check `
30612
+ ${array.length === spec.validatorsCount}
30613
+ Invalid per-validator array length. Expected ${spec.validatorsCount}, got: ${array.length}
30614
+ `;
30586
30615
  return sized_array_asKnownSize(array);
30587
30616
  }
30588
30617
  const codecPerValidator = (val) => codecWithContext((context) => {
@@ -30591,7 +30620,10 @@ const codecPerValidator = (val) => codecWithContext((context) => {
30591
30620
  });
30592
30621
  });
30593
30622
  function tryAsPerEpochBlock(array, spec) {
30594
- debug_check(array.length === spec.epochLength, `Invalid per-epoch-block array length. Expected ${spec.epochLength}, got: ${array.length}`);
30623
+ debug_check `
30624
+ ${array.length === spec.epochLength}
30625
+ Invalid per-epoch-block array length. Expected ${spec.epochLength}, got: ${array.length}
30626
+ `;
30595
30627
  return sized_array_asKnownSize(array);
30596
30628
  }
30597
30629
  const codecPerEpochBlock = (val) => codecWithContext((context) => {
@@ -30862,9 +30894,14 @@ class WorkItem extends WithDebug {
30862
30894
 
30863
30895
 
30864
30896
 
30897
+
30865
30898
  /** Verify the value is within the `WorkItemsCount` bounds. */
30866
30899
  function tryAsWorkItemsCount(len) {
30867
- return ensure(len, len >= MIN_NUMBER_OF_WORK_ITEMS && len <= work_package_MAX_NUMBER_OF_WORK_ITEMS, `WorkItemsCount: Expected '${MIN_NUMBER_OF_WORK_ITEMS} <= count <= ${work_package_MAX_NUMBER_OF_WORK_ITEMS}' got ${len}`);
30900
+ debug_check `
30901
+ ${len >= MIN_NUMBER_OF_WORK_ITEMS && len <= work_package_MAX_NUMBER_OF_WORK_ITEMS}
30902
+ WorkItemsCount: Expected '${MIN_NUMBER_OF_WORK_ITEMS} <= count <= ${work_package_MAX_NUMBER_OF_WORK_ITEMS}' got ${len}
30903
+ `;
30904
+ return tryAsU8(len);
30868
30905
  }
30869
30906
  /** Minimal number of work items in the work package or results in work report. */
30870
30907
  const MIN_NUMBER_OF_WORK_ITEMS = 1;
@@ -32837,7 +32874,10 @@ class AvailabilityAssignment extends WithDebug {
32837
32874
 
32838
32875
  /** Check if given array has correct length before casting to the opaque type. */
32839
32876
  function tryAsPerCore(array, spec) {
32840
- debug_check(array.length === spec.coresCount, `Invalid per-core array length. Expected ${spec.coresCount}, got: ${array.length}`);
32877
+ debug_check `
32878
+ ${array.length === spec.coresCount}
32879
+ Invalid per-core array length. Expected ${spec.coresCount}, got: ${array.length}
32880
+ `;
32841
32881
  return opaque_asOpaqueType(array);
32842
32882
  }
32843
32883
  const codecPerCore = (val) => codecWithContext((context) => {
@@ -34088,7 +34128,7 @@ class InMemoryState extends WithDebug {
34088
34128
  }
34089
34129
  removeServices(servicesRemoved) {
34090
34130
  for (const serviceId of servicesRemoved ?? []) {
34091
- debug_check(this.services.has(serviceId), `Attempting to remove non-existing service: ${serviceId}`);
34131
+ debug_check `${this.services.has(serviceId)} Attempting to remove non-existing service: ${serviceId}`;
34092
34132
  this.services.delete(serviceId);
34093
34133
  }
34094
34134
  }
@@ -34105,7 +34145,10 @@ class InMemoryState extends WithDebug {
34105
34145
  }
34106
34146
  else if (kind === state_update_UpdateStorageKind.Remove) {
34107
34147
  const { key } = action;
34108
- debug_check(service.data.storage.has(key.toString()), `Attempting to remove non-existing storage item at ${serviceId}: ${action.key}`);
34148
+ debug_check `
34149
+ ${service.data.storage.has(key.toString())}
34150
+ Attempting to remove non-existing storage item at ${serviceId}: ${action.key}
34151
+ `;
34109
34152
  service.data.storage.delete(key.toString());
34110
34153
  }
34111
34154
  else {
@@ -34788,12 +34831,12 @@ class nodes_TrieNode {
34788
34831
  }
34789
34832
  /** View this node as a branch node */
34790
34833
  asBranchNode() {
34791
- debug_check(this.getNodeType() === nodes_NodeType.Branch);
34834
+ debug_check `${this.getNodeType() === nodes_NodeType.Branch} not a branch!`;
34792
34835
  return new BranchNode(this);
34793
34836
  }
34794
34837
  /** View this node as a leaf node */
34795
34838
  asLeafNode() {
34796
- debug_check(this.getNodeType() !== nodes_NodeType.Branch);
34839
+ debug_check `${this.getNodeType() !== nodes_NodeType.Branch} not a leaf!`;
34797
34840
  return new LeafNode(this);
34798
34841
  }
34799
34842
  toString() {
@@ -35281,7 +35324,7 @@ function createSubtreeForBothLeaves(traversedPath, nodes, leafToReplace, leaf) {
35281
35324
  * Return a single bit from `key` located at `bitIndex`.
35282
35325
  */
35283
35326
  function getBit(key, bitIndex) {
35284
- debug_check(bitIndex < TRUNCATED_KEY_BITS);
35327
+ debug_check `${bitIndex < TRUNCATED_KEY_BITS} invalid bit index passed ${bitIndex}`;
35285
35328
  const byte = bitIndex >>> 3;
35286
35329
  const bit = bitIndex - (byte << 3);
35287
35330
  const mask = 0b10_00_00_00 >>> bit;
@@ -36288,7 +36331,7 @@ class TypedPort {
36288
36331
  * Send a response given the worker that has previously requested something.
36289
36332
  */
36290
36333
  respond(localState, request, data, transferList) {
36291
- debug_check(request.kind === "request");
36334
+ debug_check `${request.kind === "request"}`;
36292
36335
  this.postMessage({
36293
36336
  kind: "response",
36294
36337
  id: request.id,
@@ -36319,10 +36362,11 @@ class TypedPort {
36319
36362
  throw new Error(`Invalid message: ${JSON.stringify(msg)}.`);
36320
36363
  }
36321
36364
  switch (msg.kind) {
36322
- case "response":
36323
- debug_check(this.responseListeners.eventNames().indexOf(reqEvent(msg.id)) !== -1);
36365
+ case "response": {
36366
+ debug_check `${this.responseListeners.eventNames().indexOf(reqEvent(msg.id)) !== -1}`;
36324
36367
  this.responseListeners.emit(reqEvent(msg.id), null, msg.data, msg.name, msg.localState, msg);
36325
36368
  break;
36369
+ }
36326
36370
  case "signal":
36327
36371
  this.listeners.emit("signal", msg.name, msg.data, msg.localState, msg);
36328
36372
  break;
@@ -36537,9 +36581,9 @@ class MessageChannelStateMachine {
36537
36581
  const promise = new Promise((resolve, reject) => {
36538
36582
  parentPort.once("message", (value) => {
36539
36583
  try {
36540
- debug_check(value.kind === "request", "The initial message should be a request with channel.");
36541
- debug_check(value.name === CHANNEL_MESSAGE);
36542
- debug_check(value.data instanceof external_node_worker_threads_namespaceObject.MessagePort);
36584
+ debug_check `${value.kind === "request"} The initial message should be a request with channel.`;
36585
+ debug_check `${value.name === CHANNEL_MESSAGE}`;
36586
+ debug_check `${value.data instanceof external_node_worker_threads_namespaceObject.MessagePort}`;
36543
36587
  const port = new TypedPort(value.data);
36544
36588
  port.respond(machine.currentState().stateName, value, Ok);
36545
36589
  resolve(port);
@@ -36619,7 +36663,7 @@ class StateMachine {
36619
36663
  /** Get state object by name. */
36620
36664
  getState(name) {
36621
36665
  const state = this.allStates.get(name);
36622
- debug_check(state !== undefined, `Unable to retrieve state object for ${name}.`);
36666
+ debug_check `${state !== undefined} Unable to retrieve state object for ${name}.`;
36623
36667
  return state;
36624
36668
  }
36625
36669
  /** Get the currently active state object. */