@aztec/foundation 0.0.1-commit.64b6bbb → 0.0.1-commit.69c59a8b3

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 (187) hide show
  1. package/dest/branded-types/buffer32_hash.d.ts +24 -0
  2. package/dest/branded-types/buffer32_hash.d.ts.map +1 -0
  3. package/dest/branded-types/buffer32_hash.js +19 -0
  4. package/dest/branded-types/checkpoint_number.d.ts +4 -1
  5. package/dest/branded-types/checkpoint_number.d.ts.map +1 -1
  6. package/dest/branded-types/checkpoint_number.js +3 -0
  7. package/dest/branded-types/index.d.ts +2 -1
  8. package/dest/branded-types/index.d.ts.map +1 -1
  9. package/dest/branded-types/index.js +1 -0
  10. package/dest/branded-types/slot.d.ts +4 -1
  11. package/dest/branded-types/slot.d.ts.map +1 -1
  12. package/dest/branded-types/slot.js +3 -0
  13. package/dest/buffer/buffer16.d.ts +3 -1
  14. package/dest/buffer/buffer16.d.ts.map +1 -1
  15. package/dest/buffer/buffer32.d.ts +28 -61
  16. package/dest/buffer/buffer32.d.ts.map +1 -1
  17. package/dest/buffer/buffer32.js +26 -60
  18. package/dest/buffer/index.d.ts +2 -1
  19. package/dest/buffer/index.d.ts.map +1 -1
  20. package/dest/buffer/index.js +1 -0
  21. package/dest/buffer/utils.d.ts +3 -0
  22. package/dest/buffer/utils.d.ts.map +1 -0
  23. package/dest/buffer/utils.js +7 -0
  24. package/dest/collection/array.d.ts +3 -1
  25. package/dest/collection/array.d.ts.map +1 -1
  26. package/dest/collection/array.js +15 -0
  27. package/dest/collection/index.d.ts +2 -1
  28. package/dest/collection/index.d.ts.map +1 -1
  29. package/dest/collection/index.js +1 -0
  30. package/dest/collection/lru_set.d.ts +35 -0
  31. package/dest/collection/lru_set.d.ts.map +1 -0
  32. package/dest/collection/lru_set.js +95 -0
  33. package/dest/config/env_var.d.ts +2 -2
  34. package/dest/config/env_var.d.ts.map +1 -1
  35. package/dest/config/index.d.ts +48 -30
  36. package/dest/config/index.d.ts.map +1 -1
  37. package/dest/config/index.js +35 -29
  38. package/dest/config/network_config.d.ts +19 -1
  39. package/dest/config/network_config.d.ts.map +1 -1
  40. package/dest/config/network_config.js +4 -1
  41. package/dest/config/network_name.d.ts +2 -2
  42. package/dest/config/network_name.d.ts.map +1 -1
  43. package/dest/config/network_name.js +2 -0
  44. package/dest/crypto/aes128/index.d.ts +2 -1
  45. package/dest/crypto/aes128/index.d.ts.map +1 -1
  46. package/dest/crypto/aes128/index.js +11 -2
  47. package/dest/crypto/bls/bn254_keystore.d.ts +1 -10
  48. package/dest/crypto/bls/bn254_keystore.d.ts.map +1 -1
  49. package/dest/crypto/bls/bn254_keystore.js +0 -17
  50. package/dest/crypto/poseidon/index.d.ts +1 -1
  51. package/dest/crypto/poseidon/index.d.ts.map +1 -1
  52. package/dest/crypto/poseidon/index.js +40 -33
  53. package/dest/crypto/secp256k1-signer/utils.d.ts +12 -1
  54. package/dest/crypto/secp256k1-signer/utils.d.ts.map +1 -1
  55. package/dest/crypto/secp256k1-signer/utils.js +26 -0
  56. package/dest/curves/bls12/field.d.ts +1 -1
  57. package/dest/curves/bls12/field.d.ts.map +1 -1
  58. package/dest/curves/bls12/field.js +0 -5
  59. package/dest/curves/bn254/field.d.ts +18 -16
  60. package/dest/curves/bn254/field.d.ts.map +1 -1
  61. package/dest/curves/bn254/field.js +23 -15
  62. package/dest/curves/grumpkin/point.d.ts +4 -4
  63. package/dest/curves/grumpkin/point.d.ts.map +1 -1
  64. package/dest/curves/grumpkin/point.js +7 -4
  65. package/dest/eth-address/index.d.ts +1 -1
  66. package/dest/eth-address/index.d.ts.map +1 -1
  67. package/dest/eth-address/index.js +0 -3
  68. package/dest/eth-signature/eth_signature.d.ts +2 -1
  69. package/dest/eth-signature/eth_signature.d.ts.map +1 -1
  70. package/dest/eth-signature/eth_signature.js +7 -2
  71. package/dest/fifo/fifo_frame_reader.d.ts +41 -0
  72. package/dest/fifo/fifo_frame_reader.d.ts.map +1 -0
  73. package/dest/fifo/fifo_frame_reader.js +74 -0
  74. package/dest/fifo/index.d.ts +2 -0
  75. package/dest/fifo/index.d.ts.map +1 -0
  76. package/dest/fifo/index.js +1 -0
  77. package/dest/jest/setup.js +24 -0
  78. package/dest/json-rpc/client/fetch.d.ts +1 -1
  79. package/dest/json-rpc/client/fetch.d.ts.map +1 -1
  80. package/dest/json-rpc/client/fetch.js +4 -3
  81. package/dest/json-rpc/client/safe_json_rpc_client.d.ts +2 -1
  82. package/dest/json-rpc/client/safe_json_rpc_client.d.ts.map +1 -1
  83. package/dest/json-rpc/client/safe_json_rpc_client.js +1 -1
  84. package/dest/json-rpc/client/undici.d.ts +1 -1
  85. package/dest/json-rpc/client/undici.d.ts.map +1 -1
  86. package/dest/json-rpc/client/undici.js +5 -3
  87. package/dest/json-rpc/server/api_key_auth.d.ts +19 -0
  88. package/dest/json-rpc/server/api_key_auth.d.ts.map +1 -0
  89. package/dest/json-rpc/server/api_key_auth.js +57 -0
  90. package/dest/json-rpc/server/index.d.ts +2 -1
  91. package/dest/json-rpc/server/index.d.ts.map +1 -1
  92. package/dest/json-rpc/server/index.js +1 -0
  93. package/dest/log/bigint-utils.d.ts +5 -0
  94. package/dest/log/bigint-utils.d.ts.map +1 -0
  95. package/dest/log/bigint-utils.js +21 -0
  96. package/dest/log/gcloud-logger-config.d.ts +1 -1
  97. package/dest/log/gcloud-logger-config.d.ts.map +1 -1
  98. package/dest/log/gcloud-logger-config.js +3 -0
  99. package/dest/log/pino-logger.d.ts +1 -1
  100. package/dest/log/pino-logger.d.ts.map +1 -1
  101. package/dest/log/pino-logger.js +21 -2
  102. package/dest/queue/batch_queue.d.ts +1 -1
  103. package/dest/queue/batch_queue.d.ts.map +1 -1
  104. package/dest/queue/batch_queue.js +1 -0
  105. package/dest/retry/index.d.ts +12 -1
  106. package/dest/retry/index.d.ts.map +1 -1
  107. package/dest/retry/index.js +21 -0
  108. package/dest/schemas/api.d.ts +2 -2
  109. package/dest/schemas/api.d.ts.map +1 -1
  110. package/dest/serialize/buffer_reader.d.ts +8 -1
  111. package/dest/serialize/buffer_reader.d.ts.map +1 -1
  112. package/dest/serialize/buffer_reader.js +13 -0
  113. package/dest/serialize/serialize.d.ts +19 -1
  114. package/dest/serialize/serialize.d.ts.map +1 -1
  115. package/dest/serialize/serialize.js +31 -0
  116. package/dest/sleep/index.d.ts +2 -1
  117. package/dest/sleep/index.d.ts.map +1 -1
  118. package/dest/sleep/index.js +10 -1
  119. package/dest/string/index.js +1 -1
  120. package/dest/timer/date.d.ts +3 -1
  121. package/dest/timer/date.d.ts.map +1 -1
  122. package/dest/timer/date.js +4 -0
  123. package/dest/transport/dispatch/create_dispatch_proxy.d.ts +11 -2
  124. package/dest/transport/dispatch/create_dispatch_proxy.d.ts.map +1 -1
  125. package/dest/transport/index.d.ts +1 -2
  126. package/dest/transport/index.d.ts.map +1 -1
  127. package/dest/transport/index.js +0 -1
  128. package/dest/transport/transport_client.js +2 -2
  129. package/dest/trees/indexed_merkle_tree_calculator.d.ts +1 -1
  130. package/dest/trees/indexed_merkle_tree_calculator.d.ts.map +1 -1
  131. package/dest/trees/indexed_merkle_tree_calculator.js +5 -1
  132. package/package.json +3 -2
  133. package/src/branded-types/buffer32_hash.ts +42 -0
  134. package/src/branded-types/checkpoint_number.ts +5 -0
  135. package/src/branded-types/index.ts +1 -0
  136. package/src/branded-types/slot.ts +5 -0
  137. package/src/buffer/buffer16.ts +3 -0
  138. package/src/buffer/buffer32.ts +36 -65
  139. package/src/buffer/index.ts +1 -0
  140. package/src/buffer/utils.ts +8 -0
  141. package/src/collection/array.ts +14 -0
  142. package/src/collection/index.ts +1 -0
  143. package/src/collection/lru_set.ts +115 -0
  144. package/src/config/env_var.ts +43 -12
  145. package/src/config/index.ts +110 -83
  146. package/src/config/network_config.ts +3 -0
  147. package/src/config/network_name.ts +4 -1
  148. package/src/crypto/aes128/index.ts +11 -2
  149. package/src/crypto/bls/bn254_keystore.ts +0 -23
  150. package/src/crypto/poseidon/index.ts +42 -34
  151. package/src/crypto/secp256k1-signer/utils.ts +32 -0
  152. package/src/curves/bls12/field.ts +0 -7
  153. package/src/curves/bn254/field.ts +31 -33
  154. package/src/curves/grumpkin/point.ts +6 -3
  155. package/src/eth-address/index.ts +0 -4
  156. package/src/eth-signature/eth_signature.ts +7 -1
  157. package/src/fifo/fifo_frame_reader.ts +98 -0
  158. package/src/fifo/index.ts +1 -0
  159. package/src/jest/setup.mjs +27 -0
  160. package/src/json-rpc/client/fetch.ts +4 -3
  161. package/src/json-rpc/client/safe_json_rpc_client.ts +2 -0
  162. package/src/json-rpc/client/undici.ts +5 -3
  163. package/src/json-rpc/server/api_key_auth.ts +63 -0
  164. package/src/json-rpc/server/index.ts +1 -0
  165. package/src/log/bigint-utils.ts +25 -0
  166. package/src/log/gcloud-logger-config.ts +5 -0
  167. package/src/log/pino-logger.ts +23 -2
  168. package/src/queue/batch_queue.ts +1 -0
  169. package/src/retry/index.ts +30 -0
  170. package/src/schemas/api.ts +4 -1
  171. package/src/serialize/buffer_reader.ts +15 -0
  172. package/src/serialize/serialize.ts +32 -0
  173. package/src/sleep/index.ts +10 -1
  174. package/src/string/index.ts +1 -1
  175. package/src/timer/date.ts +6 -0
  176. package/src/transport/dispatch/create_dispatch_proxy.ts +11 -1
  177. package/src/transport/index.ts +0 -1
  178. package/src/transport/transport_client.ts +2 -2
  179. package/src/trees/indexed_merkle_tree_calculator.ts +5 -1
  180. package/dest/crypto/serialize.d.ts +0 -51
  181. package/dest/crypto/serialize.d.ts.map +0 -1
  182. package/dest/crypto/serialize.js +0 -68
  183. package/dest/transport/dispatch/create_dispatch_fn.d.ts +0 -25
  184. package/dest/transport/dispatch/create_dispatch_fn.d.ts.map +0 -1
  185. package/dest/transport/dispatch/create_dispatch_fn.js +0 -17
  186. package/src/crypto/serialize.ts +0 -85
  187. package/src/transport/dispatch/create_dispatch_fn.ts +0 -35
@@ -269,6 +269,22 @@ export function serializeBigInt(n: bigint, width = 32) {
269
269
  return toBufferBE(n, width);
270
270
  }
271
271
 
272
+ /**
273
+ * Serialize a signed BigInt value into a Buffer of specified width using two's complement.
274
+ * @param n - The signed BigInt value to be serialized.
275
+ * @param width - The width (in bytes) of the output Buffer, optional with default value 32.
276
+ * @returns A Buffer containing the serialized signed BigInt value in big-endian format.
277
+ */
278
+ export function serializeSignedBigInt(n: bigint, width = 32) {
279
+ const widthBits = BigInt(width * 8);
280
+ const max = 1n << (widthBits - 1n);
281
+ if (n < -max || n >= max) {
282
+ throw new Error(`Signed BigInt ${n.toString()} does not fit into ${width} bytes`);
283
+ }
284
+ const unsigned = n < 0n ? (1n << widthBits) + n : n;
285
+ return toBufferBE(unsigned, width);
286
+ }
287
+
272
288
  /**
273
289
  * Deserialize a big integer from a buffer, given an offset and width.
274
290
  * Reads the specified number of bytes from the buffer starting at the offset, converts it to a big integer, and returns the deserialized result along with the number of bytes read (advanced).
@@ -282,6 +298,22 @@ export function deserializeBigInt(buf: Buffer, offset = 0, width = 32) {
282
298
  return { elem: toBigIntBE(buf.subarray(offset, offset + width)), adv: width };
283
299
  }
284
300
 
301
+ /**
302
+ * Deserialize a signed BigInt from a buffer (two's complement).
303
+ * @param buf - The buffer containing the signed big integer to be deserialized.
304
+ * @param offset - The position in the buffer where the integer starts. Defaults to 0.
305
+ * @param width - The number of bytes to read from the buffer for the integer. Defaults to 32.
306
+ * @returns An object containing the deserialized signed bigint value ('elem') and bytes advanced ('adv').
307
+ */
308
+ export function deserializeSignedBigInt(buf: Buffer, offset = 0, width = 32) {
309
+ const { elem, adv } = deserializeBigInt(buf, offset, width);
310
+ const widthBits = BigInt(width * 8);
311
+ const signBit = 1n << (widthBits - 1n);
312
+ const fullRange = 1n << widthBits;
313
+ const signed = elem >= signBit ? elem - fullRange : elem;
314
+ return { elem: signed, adv };
315
+ }
316
+
285
317
  /**
286
318
  * Serializes a Date object into a Buffer containing its timestamp as a big integer value.
287
319
  * The resulting Buffer has a fixed width of 8 bytes, representing a 64-bit big-endian integer.
@@ -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
 
@@ -58,7 +58,7 @@ export function urlJoin(...args: string[]): string {
58
58
  end--;
59
59
  }
60
60
 
61
- if (start < end) {
61
+ if (start <= end) {
62
62
  processed.push(arg.slice(start, end + 1));
63
63
  }
64
64
  }
package/src/timer/date.ts CHANGED
@@ -32,6 +32,12 @@ export class TestDateProvider extends DateProvider {
32
32
  this.logger.warn(`Time set to ${new Date(timeMs).toISOString()}`, { offset: this.offset, timeMs });
33
33
  }
34
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
+
35
41
  /** Advances the time by the given number of seconds. */
36
42
  public advanceTime(seconds: number) {
37
43
  this.offset += seconds * 1000;
@@ -2,7 +2,17 @@ import { EventEmitter } from 'events';
2
2
 
3
3
  import { type TransferDescriptor, isTransferDescriptor } from '../interface/transferable.js';
4
4
  import type { TransportClient } from '../transport_client.js';
5
- import type { DispatchMsg } from './create_dispatch_fn.js';
5
+
6
+ /**
7
+ * Represents a message object for dispatching function calls.
8
+ * Contains the function name ('fn') and an array of arguments ('args') required to call the target method.
9
+ */
10
+ export interface DispatchMsg {
11
+ /** Name of the target method to be called. */
12
+ fn: string;
13
+ /** An array of arguments to be passed to the target method. */
14
+ args: any[];
15
+ }
6
16
 
7
17
  /**
8
18
  * FilterOutAttributes type filters out all non-method properties of an object, leaving only the attributes
@@ -1,4 +1,3 @@
1
- export * from './dispatch/create_dispatch_fn.js';
2
1
  export * from './dispatch/create_dispatch_proxy.js';
3
2
  export * from './dispatch/messages.js';
4
3
  export * from './interface/connector.js';
@@ -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,25 +0,0 @@
1
- /**
2
- * Represents a message object for dispatching function calls.
3
- * Contains the function name ('fn') and an array of arguments ('args') required to call the target method.
4
- */
5
- export interface DispatchMsg {
6
- /**
7
- * Name of the target method to be called.
8
- */
9
- fn: string;
10
- /**
11
- * An array of arguments to be passed to the target method.
12
- */
13
- args: any[];
14
- }
15
- /**
16
- * Creates a dispatch function that calls the target's specified method with provided arguments.
17
- * The created dispatch function takes a DispatchMsg object as input, which contains the name of
18
- * the method to be called ('fn') and an array of arguments to be passed to the method ('args').
19
- *
20
- * @param targetFn - A function that returns the target object containing the methods to be dispatched.
21
- * @param log - Optional logging function for debugging purposes.
22
- * @returns A dispatch function that accepts a DispatchMsg object and calls the target's method with provided arguments.
23
- */
24
- export declare function createDispatchFn(targetFn: () => any, log?: import("../../log/pino-logger.js").Logger): ({ fn, args }: DispatchMsg) => Promise<any>;
25
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY3JlYXRlX2Rpc3BhdGNoX2ZuLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvdHJhbnNwb3J0L2Rpc3BhdGNoL2NyZWF0ZV9kaXNwYXRjaF9mbi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFJQTs7O0dBR0c7QUFDSCxNQUFNLFdBQVcsV0FBVztJQUMxQjs7T0FFRztJQUNILEVBQUUsRUFBRSxNQUFNLENBQUM7SUFDWDs7T0FFRztJQUNILElBQUksRUFBRSxHQUFHLEVBQUUsQ0FBQztDQUNiO0FBRUQ7Ozs7Ozs7O0dBUUc7QUFDSCx3QkFBZ0IsZ0JBQWdCLENBQUMsUUFBUSxFQUFFLE1BQU0sR0FBRyxFQUFFLEdBQUcsNENBQXNDLCtDQU05RiJ9
@@ -1 +0,0 @@
1
- {"version":3,"file":"create_dispatch_fn.d.ts","sourceRoot":"","sources":["../../../src/transport/dispatch/create_dispatch_fn.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IACX;;OAEG;IACH,IAAI,EAAE,GAAG,EAAE,CAAC;CACb;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,EAAE,GAAG,4CAAsC,+CAM9F"}
@@ -1,17 +0,0 @@
1
- import { format } from 'util';
2
- import { createLogger } from '../../log/index.js';
3
- /**
4
- * Creates a dispatch function that calls the target's specified method with provided arguments.
5
- * The created dispatch function takes a DispatchMsg object as input, which contains the name of
6
- * the method to be called ('fn') and an array of arguments to be passed to the method ('args').
7
- *
8
- * @param targetFn - A function that returns the target object containing the methods to be dispatched.
9
- * @param log - Optional logging function for debugging purposes.
10
- * @returns A dispatch function that accepts a DispatchMsg object and calls the target's method with provided arguments.
11
- */ export function createDispatchFn(targetFn, log = createLogger('foundation:dispatch')) {
12
- return async ({ fn, args })=>{
13
- const target = targetFn();
14
- log.debug(format(`dispatching to ${target}: ${fn}`, args));
15
- return await target[fn](...args);
16
- };
17
- }
@@ -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
- }
@@ -1,35 +0,0 @@
1
- import { format } from 'util';
2
-
3
- import { createLogger } from '../../log/index.js';
4
-
5
- /**
6
- * Represents a message object for dispatching function calls.
7
- * Contains the function name ('fn') and an array of arguments ('args') required to call the target method.
8
- */
9
- export interface DispatchMsg {
10
- /**
11
- * Name of the target method to be called.
12
- */
13
- fn: string;
14
- /**
15
- * An array of arguments to be passed to the target method.
16
- */
17
- args: any[];
18
- }
19
-
20
- /**
21
- * Creates a dispatch function that calls the target's specified method with provided arguments.
22
- * The created dispatch function takes a DispatchMsg object as input, which contains the name of
23
- * the method to be called ('fn') and an array of arguments to be passed to the method ('args').
24
- *
25
- * @param targetFn - A function that returns the target object containing the methods to be dispatched.
26
- * @param log - Optional logging function for debugging purposes.
27
- * @returns A dispatch function that accepts a DispatchMsg object and calls the target's method with provided arguments.
28
- */
29
- export function createDispatchFn(targetFn: () => any, log = createLogger('foundation:dispatch')) {
30
- return async ({ fn, args }: DispatchMsg) => {
31
- const target = targetFn();
32
- log.debug(format(`dispatching to ${target}: ${fn}`, args));
33
- return await target[fn](...args);
34
- };
35
- }