@typeberry/jam 0.1.3-135961b → 0.1.3-462ca77

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.
@@ -22316,6 +22316,20 @@ const result_Result = {
22316
22316
  },
22317
22317
  };
22318
22318
 
22319
+ ;// CONCATENATED MODULE: ./packages/core/utils/safe-alloc-uint8array.ts
22320
+ // about 2GB, the maximum ArrayBuffer length on Chrome confirmed by several sources:
22321
+ // - https://issues.chromium.org/issues/40055619
22322
+ // - https://stackoverflow.com/a/72124984
22323
+ // - https://onnxruntime.ai/docs/tutorials/web/large-models.html#maximum-size-of-arraybuffer
22324
+ const MAX_LENGTH = 2145386496;
22325
+ function safe_alloc_uint8array_safeAllocUint8Array(length) {
22326
+ if (length > MAX_LENGTH) {
22327
+ // biome-ignore lint/suspicious/noConsole: can't have a dependency on logger here
22328
+ console.warn(`Trying to allocate ${length} bytes, which is greater than the maximum of ${MAX_LENGTH}.`);
22329
+ }
22330
+ return new Uint8Array(Math.min(MAX_LENGTH, length));
22331
+ }
22332
+
22319
22333
  ;// CONCATENATED MODULE: external "node:assert"
22320
22334
  const external_node_assert_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:assert");
22321
22335
  ;// CONCATENATED MODULE: ./packages/core/utils/test.ts
@@ -22559,6 +22573,7 @@ function isResult(x) {
22559
22573
 
22560
22574
 
22561
22575
 
22576
+
22562
22577
  ;// CONCATENATED MODULE: ./packages/core/bytes/bitvec.ts
22563
22578
 
22564
22579
  /**
@@ -22580,7 +22595,7 @@ class bitvec_BitVec {
22580
22595
  * Create new [`BitVec`] with all values set to `false`.
22581
22596
  */
22582
22597
  static empty(bitLength) {
22583
- const data = new Uint8Array(Math.ceil(bitLength / 8));
22598
+ const data = safe_alloc_uint8array_safeAllocUint8Array(Math.ceil(bitLength / 8));
22584
22599
  return new bitvec_BitVec(data, bitLength);
22585
22600
  }
22586
22601
  byteLength;
@@ -22780,7 +22795,7 @@ class bytes_BytesBlob {
22780
22795
  static blobFromParts(v, ...rest) {
22781
22796
  const vArr = v instanceof Uint8Array ? [v] : v;
22782
22797
  const totalLength = vArr.reduce((a, v) => a + v.length, 0) + rest.reduce((a, v) => a + v.length, 0);
22783
- const buffer = new Uint8Array(totalLength);
22798
+ const buffer = safe_alloc_uint8array_safeAllocUint8Array(totalLength);
22784
22799
  let offset = 0;
22785
22800
  for (const r of vArr) {
22786
22801
  buffer.set(r, offset);
@@ -22853,7 +22868,7 @@ class bytes_Bytes extends bytes_BytesBlob {
22853
22868
  }
22854
22869
  /** Create an empty [`Bytes<X>`] of given length. */
22855
22870
  static zero(len) {
22856
- return new bytes_Bytes(new Uint8Array(len), len);
22871
+ return new bytes_Bytes(safe_alloc_uint8array_safeAllocUint8Array(len), len);
22857
22872
  }
22858
22873
  // TODO [ToDr] `fill` should have the argments swapped to align with the rest.
22859
22874
  /** Create a [`Bytes<X>`] with all bytes filled with given input number. */
@@ -23523,7 +23538,7 @@ function addSizeHints(a, b) {
23523
23538
  };
23524
23539
  }
23525
23540
  const DEFAULT_START_LENGTH = 512; // 512B
23526
- const MAX_LENGTH = 10 * 1024 * 1024; // 10MB
23541
+ const encoder_MAX_LENGTH = 10 * 1024 * 1024; // 10MB
23527
23542
  /**
23528
23543
  * JAM encoder.
23529
23544
  */
@@ -23539,7 +23554,7 @@ class encoder_Encoder {
23539
23554
  return new encoder_Encoder(options.destination);
23540
23555
  }
23541
23556
  const startLength = options?.expectedLength ?? DEFAULT_START_LENGTH;
23542
- const buffer = new ArrayBuffer(Math.min(MAX_LENGTH, startLength), { maxByteLength: MAX_LENGTH });
23557
+ const buffer = new ArrayBuffer(Math.min(encoder_MAX_LENGTH, startLength), { maxByteLength: encoder_MAX_LENGTH });
23543
23558
  const destination = new Uint8Array(buffer);
23544
23559
  return new encoder_Encoder(destination, buffer);
23545
23560
  }
@@ -23872,11 +23887,11 @@ class encoder_Encoder {
23872
23887
  ensureBigEnough(length, options = { silent: false }) {
23873
23888
  debug_check `${length >= 0} Negative length given`;
23874
23889
  const newLength = this.offset + length;
23875
- if (newLength > MAX_LENGTH) {
23890
+ if (newLength > encoder_MAX_LENGTH) {
23876
23891
  if (options.silent) {
23877
23892
  return;
23878
23893
  }
23879
- throw new Error(`The encoded size would reach the maximum of ${MAX_LENGTH}.`);
23894
+ throw new Error(`The encoded size would reach the maximum of ${encoder_MAX_LENGTH}.`);
23880
23895
  }
23881
23896
  if (newLength > this.destination.length) {
23882
23897
  // we can try to resize the underlying buffer
@@ -23884,7 +23899,7 @@ class encoder_Encoder {
23884
23899
  // make sure we at least double the size of the buffer every time.
23885
23900
  const minExtend = Math.max(newLength, this.buffer.byteLength << 1);
23886
23901
  // but we must never exceed the max length.
23887
- this.buffer.resize(Math.min(MAX_LENGTH, minExtend));
23902
+ this.buffer.resize(Math.min(encoder_MAX_LENGTH, minExtend));
23888
23903
  }
23889
23904
  // and then check again
23890
23905
  if (newLength > this.destination.length) {
@@ -25644,7 +25659,7 @@ async function ed25519_verify(input) {
25644
25659
  return Promise.resolve([]);
25645
25660
  }
25646
25661
  const dataLength = input.reduce((acc, { message, key, signature }) => acc + key.length + signature.length + message.length + 1, 0);
25647
- const data = new Uint8Array(dataLength);
25662
+ const data = safe_alloc_uint8array_safeAllocUint8Array(dataLength);
25648
25663
  let offset = 0;
25649
25664
  for (const { key, message, signature } of input) {
25650
25665
  data.set(key.raw, offset);
@@ -25731,7 +25746,7 @@ class allocator_SimpleAllocator {
25731
25746
  /** An allocator that works by allocating larger (continuous) pages of memory. */
25732
25747
  class PageAllocator {
25733
25748
  hashesPerPage;
25734
- page = new Uint8Array(0);
25749
+ page = safeAllocUint8Array(0);
25735
25750
  currentHash = 0;
25736
25751
  // TODO [ToDr] Benchmark the performance!
25737
25752
  constructor(hashesPerPage) {
@@ -25742,7 +25757,7 @@ class PageAllocator {
25742
25757
  resetPage() {
25743
25758
  const pageSizeBytes = this.hashesPerPage * HASH_SIZE;
25744
25759
  this.currentHash = 0;
25745
- this.page = new Uint8Array(pageSizeBytes);
25760
+ this.page = safeAllocUint8Array(pageSizeBytes);
25746
25761
  }
25747
25762
  emptyHash() {
25748
25763
  const startIdx = this.currentHash * HASH_SIZE;
@@ -31570,7 +31585,7 @@ class SerializedService {
31570
31585
  getStorage(rawKey) {
31571
31586
  if (Compatibility.isLessThan(GpVersion.V0_6_7)) {
31572
31587
  const SERVICE_ID_BYTES = 4;
31573
- const serviceIdAndKey = new Uint8Array(SERVICE_ID_BYTES + rawKey.length);
31588
+ const serviceIdAndKey = safeAllocUint8Array(SERVICE_ID_BYTES + rawKey.length);
31574
31589
  serviceIdAndKey.set(u32AsLeBytes(this.serviceId));
31575
31590
  serviceIdAndKey.set(rawKey.raw, SERVICE_ID_BYTES);
31576
31591
  const key = asOpaqueType(BytesBlob.blobFrom(blake2b.hashBytes(serviceIdAndKey).raw));
@@ -31661,7 +31676,7 @@ class nodes_TrieNode {
31661
31676
  raw;
31662
31677
  constructor(
31663
31678
  /** Exactly 512 bits / 64 bytes */
31664
- raw = new Uint8Array(nodes_TRIE_NODE_BYTES)) {
31679
+ raw = safe_alloc_uint8array_safeAllocUint8Array(nodes_TRIE_NODE_BYTES)) {
31665
31680
  this.raw = raw;
31666
31681
  }
31667
31682
  /** Returns the type of the node */