@aztec/foundation 0.0.1-commit.9d2bcf6d → 0.0.1-commit.9ef841308

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 (130) hide show
  1. package/dest/array/sorted_array.d.ts +6 -1
  2. package/dest/array/sorted_array.d.ts.map +1 -1
  3. package/dest/array/sorted_array.js +18 -15
  4. package/dest/branded-types/slot.d.ts +4 -1
  5. package/dest/branded-types/slot.d.ts.map +1 -1
  6. package/dest/branded-types/slot.js +3 -0
  7. package/dest/buffer/index.d.ts +2 -1
  8. package/dest/buffer/index.d.ts.map +1 -1
  9. package/dest/buffer/index.js +1 -0
  10. package/dest/buffer/utils.d.ts +3 -0
  11. package/dest/buffer/utils.d.ts.map +1 -0
  12. package/dest/buffer/utils.js +7 -0
  13. package/dest/collection/array.d.ts +3 -1
  14. package/dest/collection/array.d.ts.map +1 -1
  15. package/dest/collection/array.js +15 -0
  16. package/dest/collection/index.d.ts +2 -1
  17. package/dest/collection/index.d.ts.map +1 -1
  18. package/dest/collection/index.js +1 -0
  19. package/dest/collection/lru_set.d.ts +35 -0
  20. package/dest/collection/lru_set.d.ts.map +1 -0
  21. package/dest/collection/lru_set.js +95 -0
  22. package/dest/config/env_var.d.ts +2 -2
  23. package/dest/config/env_var.d.ts.map +1 -1
  24. package/dest/config/index.d.ts +1 -1
  25. package/dest/config/index.d.ts.map +1 -1
  26. package/dest/config/index.js +15 -0
  27. package/dest/config/network_config.d.ts +19 -1
  28. package/dest/config/network_config.d.ts.map +1 -1
  29. package/dest/config/network_config.js +4 -1
  30. package/dest/config/network_name.d.ts +2 -2
  31. package/dest/config/network_name.d.ts.map +1 -1
  32. package/dest/config/network_name.js +2 -0
  33. package/dest/crypto/poseidon/index.d.ts +1 -1
  34. package/dest/crypto/poseidon/index.d.ts.map +1 -1
  35. package/dest/crypto/poseidon/index.js +40 -33
  36. package/dest/crypto/secp256k1-signer/utils.d.ts +12 -1
  37. package/dest/crypto/secp256k1-signer/utils.d.ts.map +1 -1
  38. package/dest/crypto/secp256k1-signer/utils.js +26 -0
  39. package/dest/curves/bn254/field.d.ts +2 -1
  40. package/dest/curves/bn254/field.d.ts.map +1 -1
  41. package/dest/curves/bn254/field.js +5 -2
  42. package/dest/eth-signature/eth_signature.d.ts +2 -1
  43. package/dest/eth-signature/eth_signature.d.ts.map +1 -1
  44. package/dest/eth-signature/eth_signature.js +7 -2
  45. package/dest/fifo/fifo_frame_reader.d.ts +41 -0
  46. package/dest/fifo/fifo_frame_reader.d.ts.map +1 -0
  47. package/dest/fifo/fifo_frame_reader.js +74 -0
  48. package/dest/fifo/index.d.ts +2 -0
  49. package/dest/fifo/index.d.ts.map +1 -0
  50. package/dest/fifo/index.js +1 -0
  51. package/dest/jest/setup.js +24 -0
  52. package/dest/json-rpc/client/safe_json_rpc_client.d.ts +2 -1
  53. package/dest/json-rpc/client/safe_json_rpc_client.d.ts.map +1 -1
  54. package/dest/json-rpc/client/safe_json_rpc_client.js +1 -1
  55. package/dest/json-rpc/server/api_key_auth.d.ts +19 -0
  56. package/dest/json-rpc/server/api_key_auth.d.ts.map +1 -0
  57. package/dest/json-rpc/server/api_key_auth.js +57 -0
  58. package/dest/json-rpc/server/index.d.ts +2 -1
  59. package/dest/json-rpc/server/index.d.ts.map +1 -1
  60. package/dest/json-rpc/server/index.js +1 -0
  61. package/dest/log/bigint-utils.d.ts +5 -0
  62. package/dest/log/bigint-utils.d.ts.map +1 -0
  63. package/dest/log/bigint-utils.js +21 -0
  64. package/dest/log/gcloud-logger-config.d.ts +1 -1
  65. package/dest/log/gcloud-logger-config.d.ts.map +1 -1
  66. package/dest/log/gcloud-logger-config.js +3 -0
  67. package/dest/log/log-filters.d.ts +17 -4
  68. package/dest/log/log-filters.d.ts.map +1 -1
  69. package/dest/log/log-filters.js +26 -12
  70. package/dest/log/pino-logger.d.ts +1 -1
  71. package/dest/log/pino-logger.d.ts.map +1 -1
  72. package/dest/log/pino-logger.js +6 -2
  73. package/dest/queue/base_memory_queue.d.ts +2 -2
  74. package/dest/queue/base_memory_queue.d.ts.map +1 -1
  75. package/dest/schemas/api.d.ts +2 -2
  76. package/dest/schemas/api.d.ts.map +1 -1
  77. package/dest/serialize/buffer_reader.d.ts +8 -1
  78. package/dest/serialize/buffer_reader.d.ts.map +1 -1
  79. package/dest/serialize/buffer_reader.js +13 -0
  80. package/dest/serialize/serialize.d.ts +19 -1
  81. package/dest/serialize/serialize.d.ts.map +1 -1
  82. package/dest/serialize/serialize.js +31 -0
  83. package/dest/sleep/index.d.ts +2 -1
  84. package/dest/sleep/index.d.ts.map +1 -1
  85. package/dest/sleep/index.js +10 -1
  86. package/dest/timer/date.d.ts +25 -1
  87. package/dest/timer/date.d.ts.map +1 -1
  88. package/dest/timer/date.js +33 -0
  89. package/dest/transport/transport_client.js +2 -2
  90. package/dest/trees/indexed_merkle_tree_calculator.d.ts +1 -1
  91. package/dest/trees/indexed_merkle_tree_calculator.d.ts.map +1 -1
  92. package/dest/trees/indexed_merkle_tree_calculator.js +5 -1
  93. package/package.json +23 -2
  94. package/src/array/sorted_array.ts +22 -17
  95. package/src/branded-types/slot.ts +5 -0
  96. package/src/buffer/index.ts +1 -0
  97. package/src/buffer/utils.ts +8 -0
  98. package/src/collection/array.ts +14 -0
  99. package/src/collection/index.ts +1 -0
  100. package/src/collection/lru_set.ts +115 -0
  101. package/src/config/env_var.ts +47 -9
  102. package/src/config/index.ts +15 -0
  103. package/src/config/network_config.ts +3 -0
  104. package/src/config/network_name.ts +4 -1
  105. package/src/crypto/poseidon/index.ts +42 -34
  106. package/src/crypto/secp256k1-signer/utils.ts +32 -0
  107. package/src/curves/bn254/field.ts +6 -2
  108. package/src/eth-signature/eth_signature.ts +7 -1
  109. package/src/fifo/fifo_frame_reader.ts +98 -0
  110. package/src/fifo/index.ts +1 -0
  111. package/src/jest/setup.mjs +27 -0
  112. package/src/json-rpc/client/safe_json_rpc_client.ts +2 -0
  113. package/src/json-rpc/server/api_key_auth.ts +63 -0
  114. package/src/json-rpc/server/index.ts +1 -0
  115. package/src/log/bigint-utils.ts +25 -0
  116. package/src/log/gcloud-logger-config.ts +5 -0
  117. package/src/log/log-filters.ts +29 -11
  118. package/src/log/pino-logger.ts +6 -2
  119. package/src/queue/base_memory_queue.ts +1 -1
  120. package/src/schemas/api.ts +4 -1
  121. package/src/serialize/buffer_reader.ts +15 -0
  122. package/src/serialize/serialize.ts +32 -0
  123. package/src/sleep/index.ts +10 -1
  124. package/src/timer/date.ts +48 -0
  125. package/src/transport/transport_client.ts +2 -2
  126. package/src/trees/indexed_merkle_tree_calculator.ts +5 -1
  127. package/dest/crypto/serialize.d.ts +0 -51
  128. package/dest/crypto/serialize.d.ts.map +0 -1
  129. package/dest/crypto/serialize.js +0 -68
  130. package/src/crypto/serialize.ts +0 -85
@@ -22,6 +22,7 @@ import { InterruptError } from '../error/index.js';
22
22
  */
23
23
  export class InterruptibleSleep {
24
24
  private interrupts: Array<(shouldThrow: boolean) => void> = [];
25
+ private timeoutIds: NodeJS.Timeout[] = [];
25
26
 
26
27
  /**
27
28
  * Sleep for a specified amount of time in milliseconds.
@@ -38,9 +39,15 @@ export class InterruptibleSleep {
38
39
  this.interrupts.push(resolve);
39
40
  });
40
41
 
41
- const timeoutPromise = new Promise<boolean>(resolve => setTimeout(() => resolve(false), ms));
42
+ let timeoutId: NodeJS.Timeout;
43
+ const timeoutPromise = new Promise<boolean>(resolve => {
44
+ timeoutId = setTimeout(() => resolve(false), ms);
45
+ this.timeoutIds.push(timeoutId);
46
+ });
42
47
  const shouldThrow = await Promise.race([interruptPromise, timeoutPromise]);
43
48
 
49
+ clearTimeout(timeoutId!);
50
+ this.timeoutIds = this.timeoutIds.filter(id => id !== timeoutId);
44
51
  this.interrupts = this.interrupts.filter(res => res !== interruptResolve);
45
52
 
46
53
  if (shouldThrow) {
@@ -58,6 +65,8 @@ export class InterruptibleSleep {
58
65
  public interrupt(sleepShouldThrow = false): void {
59
66
  this.interrupts.forEach(resolve => resolve(sleepShouldThrow));
60
67
  this.interrupts = [];
68
+ this.timeoutIds.forEach(id => clearTimeout(id));
69
+ this.timeoutIds = [];
61
70
  }
62
71
  }
63
72
 
package/src/timer/date.ts CHANGED
@@ -31,4 +31,52 @@ export class TestDateProvider extends DateProvider {
31
31
  this.offset = timeMs - Date.now();
32
32
  this.logger.warn(`Time set to ${new Date(timeMs).toISOString()}`, { offset: this.offset, timeMs });
33
33
  }
34
+
35
+ /** Resets the time back to real time (offset = 0). */
36
+ public reset() {
37
+ this.offset = 0;
38
+ this.logger.warn('Time reset to real time');
39
+ }
40
+
41
+ /** Advances the time by the given number of seconds. */
42
+ public advanceTime(seconds: number) {
43
+ this.offset += seconds * 1000;
44
+ }
45
+ }
46
+
47
+ /**
48
+ * A date provider for tests that only advances time via explicit advanceTime() calls.
49
+ * Unlike TestDateProvider, this does NOT track real time progression - time is completely
50
+ * frozen until explicitly advanced. This eliminates flakiness from tests taking
51
+ * varying amounts of real time to execute.
52
+ */
53
+ export class ManualDateProvider extends DateProvider {
54
+ private currentTimeMs: number;
55
+
56
+ /**
57
+ * @param initialTimeMs - Initial time in milliseconds. Defaults to a round timestamp for easy visualization.
58
+ */
59
+ constructor(initialTimeMs: number = Date.UTC(2025, 0, 1, 0, 0, 0)) {
60
+ super();
61
+ this.currentTimeMs = initialTimeMs;
62
+ }
63
+
64
+ public override now(): number {
65
+ return this.currentTimeMs;
66
+ }
67
+
68
+ /** Sets the current time to the given timestamp in milliseconds. */
69
+ public setTime(timeMs: number) {
70
+ this.currentTimeMs = timeMs;
71
+ }
72
+
73
+ /** Advances the time by the given number of seconds. */
74
+ public advanceTime(seconds: number) {
75
+ this.currentTimeMs += seconds * 1000;
76
+ }
77
+
78
+ /** Advances the time by the given number of milliseconds. */
79
+ public advanceTimeMs(ms: number) {
80
+ this.currentTimeMs += ms;
81
+ }
34
82
  }
@@ -91,7 +91,7 @@ export class TransportClient<Payload> extends EventEmitter {
91
91
  }
92
92
  const msgId = this.msgId++;
93
93
  const msg = { msgId, payload };
94
- log.debug(format(`->`, msg));
94
+ log.trace(format(`->`, msg));
95
95
  return new Promise<any>((resolve, reject) => {
96
96
  this.pendingRequests.push({ resolve, reject, msgId });
97
97
  this.socket!.send(msg, transfer).catch(reject);
@@ -111,7 +111,7 @@ export class TransportClient<Payload> extends EventEmitter {
111
111
  this.close();
112
112
  return;
113
113
  }
114
- log.debug(format(`<-`, msg));
114
+ log.trace(format(`<-`, msg));
115
115
  if (isEventMessage(msg)) {
116
116
  this.emit('event_msg', msg.payload);
117
117
  return;
@@ -40,7 +40,11 @@ export class IndexedMerkleTreeCalculator<T extends IndexedTreeLeafPreimage, N ex
40
40
  }
41
41
  const sorted = values
42
42
  .map((v, i) => ({ value: v, index: i }))
43
- .sort((a, b) => Number(toBigIntBE(b.value) - toBigIntBE(a.value)));
43
+ .sort((a, b): -1 | 0 | 1 => {
44
+ const aBigInt = toBigIntBE(a.value);
45
+ const bBigInt = toBigIntBE(b.value);
46
+ return aBigInt < bBigInt ? 1 : aBigInt > bBigInt ? -1 : 0;
47
+ });
44
48
  const indexedLeaves = sorted.map((item, i) => ({
45
49
  leaf: this.factory.fromBuffer(
46
50
  Buffer.concat([
@@ -1,51 +0,0 @@
1
- import { Buffer } from 'buffer';
2
- /**
3
- * For serializing an array of fixed length buffers.
4
- * TODO move to foundation pkg.
5
- * @param arr - Array of bufffers.
6
- * @returns The serialized buffers.
7
- */
8
- export declare function serializeBufferArrayToVector(arr: Buffer[]): Buffer<ArrayBuffer>;
9
- /**
10
- * Helper function for deserializeArrayFromVector.
11
- */
12
- type DeserializeFn<T> = (buf: Buffer, offset: number) => {
13
- /**
14
- * The deserialized type.
15
- */
16
- elem: T;
17
- /**
18
- * How many bytes to advance by.
19
- */
20
- adv: number;
21
- };
22
- /**
23
- * For deserializing numbers to 32-bit little-endian form.
24
- * TODO move to foundation pkg.
25
- * @param n - The number.
26
- * @returns The endian-corrected number.
27
- */
28
- export declare function deserializeArrayFromVector<T>(deserialize: DeserializeFn<T>, vector: Buffer, offset?: number): {
29
- elem: T[];
30
- adv: number;
31
- };
32
- /**
33
- * For serializing numbers to 32 bit little-endian form.
34
- * TODO move to foundation pkg.
35
- * @param n - The number.
36
- * @returns The endian-corrected number.
37
- */
38
- export declare function numToUInt32LE(n: number, bufferSize?: number): Buffer<ArrayBuffer>;
39
- /**
40
- * Deserialize the 256-bit number at address `offset`.
41
- * @param buf - The buffer.
42
- * @param offset - The address.
43
- * @returns The derserialized 256-bit field.
44
- */
45
- export declare function deserializeField(buf: Buffer, offset?: number): {
46
- elem: Buffer<ArrayBuffer>;
47
- adv: number;
48
- };
49
- export declare function concatenateUint8Arrays(arrayOfUint8Arrays: Uint8Array[]): Uint8Array<ArrayBuffer>;
50
- export {};
51
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2VyaWFsaXplLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvY3J5cHRvL3NlcmlhbGl6ZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFFQSxPQUFPLEVBQUUsTUFBTSxFQUFFLE1BQU0sUUFBUSxDQUFDO0FBRWhDOzs7OztHQUtHO0FBQ0gsd0JBQWdCLDRCQUE0QixDQUFDLEdBQUcsRUFBRSxNQUFNLEVBQUUsdUJBSXpEO0FBRUQ7O0dBRUc7QUFDSCxLQUFLLGFBQWEsQ0FBQyxDQUFDLElBQUksQ0FDdEIsR0FBRyxFQUFFLE1BQU0sRUFDWCxNQUFNLEVBQUUsTUFBTSxLQUNYO0lBQ0g7O09BRUc7SUFDSCxJQUFJLEVBQUUsQ0FBQyxDQUFDO0lBQ1I7O09BRUc7SUFDSCxHQUFHLEVBQUUsTUFBTSxDQUFDO0NBQ2IsQ0FBQztBQUVGOzs7OztHQUtHO0FBQ0gsd0JBQWdCLDBCQUEwQixDQUFDLENBQUMsRUFBRSxXQUFXLEVBQUUsYUFBYSxDQUFDLENBQUMsQ0FBQyxFQUFFLE1BQU0sRUFBRSxNQUFNLEVBQUUsTUFBTSxTQUFJOzs7RUFXdEc7QUFFRDs7Ozs7R0FLRztBQUNILHdCQUFnQixhQUFhLENBQUMsQ0FBQyxFQUFFLE1BQU0sRUFBRSxVQUFVLFNBQUksdUJBSXREO0FBRUQ7Ozs7O0dBS0c7QUFDSCx3QkFBZ0IsZ0JBQWdCLENBQUMsR0FBRyxFQUFFLE1BQU0sRUFBRSxNQUFNLFNBQUk7OztFQUd2RDtBQUVELHdCQUFnQixzQkFBc0IsQ0FBQyxrQkFBa0IsRUFBRSxVQUFVLEVBQUUsMkJBU3RFIn0=
@@ -1 +0,0 @@
1
- {"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../../src/crypto/serialize.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAAC,GAAG,EAAE,MAAM,EAAE,uBAIzD;AAED;;GAEG;AACH,KAAK,aAAa,CAAC,CAAC,IAAI,CACtB,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,KACX;IACH;;OAEG;IACH,IAAI,EAAE,CAAC,CAAC;IACR;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,CAAC,EAAE,WAAW,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,SAAI;;;EAWtG;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,SAAI,uBAItD;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,SAAI;;;EAGvD;AAED,wBAAgB,sBAAsB,CAAC,kBAAkB,EAAE,UAAU,EAAE,2BAStE"}
@@ -1,68 +0,0 @@
1
- // TODO find a new home for this as we move to external bb.js
2
- // See https://github.com/AztecProtocol/aztec-packages/issues/782
3
- import { Buffer } from 'buffer';
4
- /**
5
- * For serializing an array of fixed length buffers.
6
- * TODO move to foundation pkg.
7
- * @param arr - Array of bufffers.
8
- * @returns The serialized buffers.
9
- */ export function serializeBufferArrayToVector(arr) {
10
- const lengthBuf = Buffer.alloc(4);
11
- lengthBuf.writeUInt32BE(arr.length, 0);
12
- return Buffer.concat([
13
- lengthBuf,
14
- ...arr
15
- ]);
16
- }
17
- /**
18
- * For deserializing numbers to 32-bit little-endian form.
19
- * TODO move to foundation pkg.
20
- * @param n - The number.
21
- * @returns The endian-corrected number.
22
- */ export function deserializeArrayFromVector(deserialize, vector, offset = 0) {
23
- let pos = offset;
24
- const size = vector.readUInt32BE(pos);
25
- pos += 4;
26
- const arr = new Array(size);
27
- for(let i = 0; i < size; ++i){
28
- const { elem, adv } = deserialize(vector, pos);
29
- pos += adv;
30
- arr[i] = elem;
31
- }
32
- return {
33
- elem: arr,
34
- adv: pos - offset
35
- };
36
- }
37
- /**
38
- * For serializing numbers to 32 bit little-endian form.
39
- * TODO move to foundation pkg.
40
- * @param n - The number.
41
- * @returns The endian-corrected number.
42
- */ export function numToUInt32LE(n, bufferSize = 4) {
43
- const buf = Buffer.alloc(bufferSize);
44
- buf.writeUInt32LE(n, bufferSize - 4);
45
- return buf;
46
- }
47
- /**
48
- * Deserialize the 256-bit number at address `offset`.
49
- * @param buf - The buffer.
50
- * @param offset - The address.
51
- * @returns The derserialized 256-bit field.
52
- */ export function deserializeField(buf, offset = 0) {
53
- const adv = 32;
54
- return {
55
- elem: buf.slice(offset, offset + adv),
56
- adv
57
- };
58
- }
59
- export function concatenateUint8Arrays(arrayOfUint8Arrays) {
60
- const totalLength = arrayOfUint8Arrays.reduce((prev, curr)=>prev + curr.length, 0);
61
- const result = new Uint8Array(totalLength);
62
- let length = 0;
63
- for (const array of arrayOfUint8Arrays){
64
- result.set(array, length);
65
- length += array.length;
66
- }
67
- return result;
68
- }
@@ -1,85 +0,0 @@
1
- // TODO find a new home for this as we move to external bb.js
2
- // See https://github.com/AztecProtocol/aztec-packages/issues/782
3
- import { Buffer } from 'buffer';
4
-
5
- /**
6
- * For serializing an array of fixed length buffers.
7
- * TODO move to foundation pkg.
8
- * @param arr - Array of bufffers.
9
- * @returns The serialized buffers.
10
- */
11
- export function serializeBufferArrayToVector(arr: Buffer[]) {
12
- const lengthBuf = Buffer.alloc(4);
13
- lengthBuf.writeUInt32BE(arr.length, 0);
14
- return Buffer.concat([lengthBuf, ...arr]);
15
- }
16
-
17
- /**
18
- * Helper function for deserializeArrayFromVector.
19
- */
20
- type DeserializeFn<T> = (
21
- buf: Buffer,
22
- offset: number,
23
- ) => {
24
- /**
25
- * The deserialized type.
26
- */
27
- elem: T;
28
- /**
29
- * How many bytes to advance by.
30
- */
31
- adv: number;
32
- };
33
-
34
- /**
35
- * For deserializing numbers to 32-bit little-endian form.
36
- * TODO move to foundation pkg.
37
- * @param n - The number.
38
- * @returns The endian-corrected number.
39
- */
40
- export function deserializeArrayFromVector<T>(deserialize: DeserializeFn<T>, vector: Buffer, offset = 0) {
41
- let pos = offset;
42
- const size = vector.readUInt32BE(pos);
43
- pos += 4;
44
- const arr = new Array<T>(size);
45
- for (let i = 0; i < size; ++i) {
46
- const { elem, adv } = deserialize(vector, pos);
47
- pos += adv;
48
- arr[i] = elem;
49
- }
50
- return { elem: arr, adv: pos - offset };
51
- }
52
-
53
- /**
54
- * For serializing numbers to 32 bit little-endian form.
55
- * TODO move to foundation pkg.
56
- * @param n - The number.
57
- * @returns The endian-corrected number.
58
- */
59
- export function numToUInt32LE(n: number, bufferSize = 4) {
60
- const buf = Buffer.alloc(bufferSize);
61
- buf.writeUInt32LE(n, bufferSize - 4);
62
- return buf;
63
- }
64
-
65
- /**
66
- * Deserialize the 256-bit number at address `offset`.
67
- * @param buf - The buffer.
68
- * @param offset - The address.
69
- * @returns The derserialized 256-bit field.
70
- */
71
- export function deserializeField(buf: Buffer, offset = 0) {
72
- const adv = 32;
73
- return { elem: buf.slice(offset, offset + adv), adv };
74
- }
75
-
76
- export function concatenateUint8Arrays(arrayOfUint8Arrays: Uint8Array[]) {
77
- const totalLength = arrayOfUint8Arrays.reduce((prev, curr) => prev + curr.length, 0);
78
- const result = new Uint8Array(totalLength);
79
- let length = 0;
80
- for (const array of arrayOfUint8Arrays) {
81
- result.set(array, length);
82
- length += array.length;
83
- }
84
- return result;
85
- }