@aztec/foundation 0.0.1-commit.3100065 → 0.0.1-commit.330febf

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 (47) hide show
  1. package/dest/config/env_var.d.ts +2 -2
  2. package/dest/config/env_var.d.ts.map +1 -1
  3. package/dest/crypto/keys/index.d.ts +3 -2
  4. package/dest/crypto/keys/index.d.ts.map +1 -1
  5. package/dest/crypto/keys/index.js +30 -6
  6. package/dest/fifo/fifo_frame_reader.d.ts +2 -2
  7. package/dest/fifo/fifo_frame_reader.d.ts.map +1 -1
  8. package/dest/fifo/fifo_frame_reader.js +21 -4
  9. package/dest/json-rpc/client/safe_json_rpc_client.d.ts +1 -1
  10. package/dest/json-rpc/client/safe_json_rpc_client.d.ts.map +1 -1
  11. package/dest/json-rpc/client/safe_json_rpc_client.js +3 -2
  12. package/dest/json-rpc/server/safe_json_rpc_server.d.ts +1 -1
  13. package/dest/json-rpc/server/safe_json_rpc_server.d.ts.map +1 -1
  14. package/dest/json-rpc/server/safe_json_rpc_server.js +5 -1
  15. package/dest/log/aws-logger-config.d.ts +8 -0
  16. package/dest/log/aws-logger-config.d.ts.map +1 -0
  17. package/dest/log/aws-logger-config.js +55 -0
  18. package/dest/log/pino-logger.d.ts +1 -1
  19. package/dest/log/pino-logger.d.ts.map +1 -1
  20. package/dest/log/pino-logger.js +12 -6
  21. package/dest/serialize/buffer_reader.d.ts +1 -1
  22. package/dest/serialize/buffer_reader.d.ts.map +1 -1
  23. package/dest/serialize/buffer_reader.js +5 -0
  24. package/dest/serialize/serialize.d.ts +1 -32
  25. package/dest/serialize/serialize.d.ts.map +1 -1
  26. package/dest/serialize/serialize.js +0 -21
  27. package/dest/string/index.d.ts +3 -1
  28. package/dest/string/index.d.ts.map +1 -1
  29. package/dest/string/index.js +12 -0
  30. package/dest/testing/files/index.d.ts +1 -1
  31. package/dest/testing/files/index.js +2 -2
  32. package/dest/trees/sibling_path.d.ts +9 -11
  33. package/dest/trees/sibling_path.d.ts.map +1 -1
  34. package/dest/trees/sibling_path.js +13 -20
  35. package/package.json +2 -2
  36. package/src/config/env_var.ts +8 -0
  37. package/src/crypto/keys/index.ts +20 -4
  38. package/src/fifo/fifo_frame_reader.ts +17 -2
  39. package/src/json-rpc/client/safe_json_rpc_client.ts +3 -2
  40. package/src/json-rpc/server/safe_json_rpc_server.ts +5 -1
  41. package/src/log/aws-logger-config.ts +32 -0
  42. package/src/log/pino-logger.ts +14 -4
  43. package/src/serialize/buffer_reader.ts +5 -0
  44. package/src/serialize/serialize.ts +0 -50
  45. package/src/string/index.ts +14 -0
  46. package/src/testing/files/index.ts +2 -2
  47. package/src/trees/sibling_path.ts +13 -24
@@ -3,15 +3,18 @@ import { z } from 'zod';
3
3
  import { makeTuple } from '../array/array.js';
4
4
  import { Fr } from '../curves/bn254/index.js';
5
5
  import { schemas } from '../schemas/index.js';
6
- import {
7
- type Tuple,
8
- assertLength,
9
- deserializeArrayFromVector,
10
- serializeArrayOfBufferableToVector,
11
- } from '../serialize/index.js';
6
+ import { BufferReader, type Tuple, assertLength, serializeArrayOfBufferableToVector } from '../serialize/index.js';
12
7
  import { bufferToHex, hexToBuffer } from '../string/index.js';
13
8
  import type { Hasher } from './hasher.js';
14
9
 
10
+ /**
11
+ * Upper bound on the elements a serialized sibling path may declare. The deepest protocol tree is 42 levels,
12
+ * and the stacked path proving L2-to-L1 message inclusion spans four unbalanced trees, so this leaves room to
13
+ * spare while keeping a malformed length prefix from driving a large allocation. `stdlib` asserts that it stays
14
+ * above every protocol tree height, which this package cannot check itself without depending on `@aztec/constants`.
15
+ */
16
+ export const MAX_SIBLING_PATH_LENGTH = 128;
17
+
15
18
  /**
16
19
  * Contains functionality to compute and serialize/deserialize a sibling path.
17
20
  * E.g. Sibling path for a leaf at index 3 in a tree of depth 3 consists of:
@@ -118,26 +121,12 @@ export class SiblingPath<N extends number> {
118
121
  * @param buf - A buffer containing the buffer representation of SiblingPath.
119
122
  * @param offset - An offset to start deserializing from.
120
123
  * @returns A SiblingPath object.
124
+ * @throws If the length prefix exceeds MAX_SIBLING_PATH_LENGTH or the buffer holds fewer elements than it declares.
121
125
  */
122
126
  static fromBuffer<N extends number>(buf: Buffer, offset = 0): SiblingPath<N> {
123
- const { elem } = SiblingPath.deserialize<N>(buf, offset);
124
- return elem;
125
- }
126
-
127
- /**
128
- * Deserializes a SiblingPath object from a slice of a part of a buffer and returns the amount of bytes advanced.
129
- * @param buf - A buffer representation of the sibling path.
130
- * @param offset - An offset to start deserializing from.
131
- * @returns The deserialized sibling path and the number of bytes advanced.
132
- */
133
- static deserialize<N extends number>(buf: Buffer, offset = 0) {
134
- const deserializePath = (buf: Buffer, offset: number) => ({
135
- elem: buf.slice(offset, offset + 32),
136
- adv: 32,
137
- });
138
- const { elem, adv } = deserializeArrayFromVector(deserializePath, buf, offset);
139
- const size = elem.length;
140
- return { elem: new SiblingPath<N>(size as N, elem), adv };
127
+ const reader = new BufferReader(buf, offset);
128
+ const path = reader.readVector({ fromBuffer: r => r.readBytes(Fr.SIZE_IN_BYTES) }, MAX_SIBLING_PATH_LENGTH);
129
+ return new SiblingPath<N>(path.length as N, path);
141
130
  }
142
131
 
143
132
  /**