@aztec/foundation 0.66.0 → 0.67.0

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 (89) hide show
  1. package/dest/abi/abi.d.ts.map +1 -1
  2. package/dest/abi/abi.js +25 -10
  3. package/dest/abi/encoder.js +3 -3
  4. package/dest/abi/event_selector.js +2 -2
  5. package/dest/abi/function_selector.js +2 -2
  6. package/dest/collection/array.d.ts +2 -0
  7. package/dest/collection/array.d.ts.map +1 -1
  8. package/dest/collection/array.js +10 -1
  9. package/dest/collection/object.d.ts +6 -0
  10. package/dest/collection/object.d.ts.map +1 -1
  11. package/dest/collection/object.js +15 -1
  12. package/dest/config/env_var.d.ts +1 -1
  13. package/dest/config/env_var.d.ts.map +1 -1
  14. package/dest/crypto/random/randomness_singleton.js +3 -3
  15. package/dest/fields/fields.d.ts +20 -2
  16. package/dest/fields/fields.d.ts.map +1 -1
  17. package/dest/fields/fields.js +37 -3
  18. package/dest/fs/run_in_dir.js +2 -2
  19. package/dest/iterable/index.d.ts +1 -0
  20. package/dest/iterable/index.d.ts.map +1 -1
  21. package/dest/iterable/index.js +2 -1
  22. package/dest/iterable/toArray.d.ts +2 -0
  23. package/dest/iterable/toArray.d.ts.map +1 -0
  24. package/dest/iterable/toArray.js +8 -0
  25. package/dest/json-rpc/client/fetch.d.ts +2 -2
  26. package/dest/json-rpc/client/fetch.d.ts.map +1 -1
  27. package/dest/json-rpc/client/fetch.js +3 -3
  28. package/dest/json-rpc/client/safe_json_rpc_client.d.ts.map +1 -1
  29. package/dest/json-rpc/client/safe_json_rpc_client.js +7 -12
  30. package/dest/json-rpc/server/safe_json_rpc_server.d.ts +3 -2
  31. package/dest/json-rpc/server/safe_json_rpc_server.d.ts.map +1 -1
  32. package/dest/json-rpc/server/safe_json_rpc_server.js +5 -5
  33. package/dest/log/log-filters.d.ts.map +1 -1
  34. package/dest/log/log-filters.js +8 -2
  35. package/dest/log/log_fn.d.ts +1 -1
  36. package/dest/log/pino-logger.d.ts +18 -7
  37. package/dest/log/pino-logger.d.ts.map +1 -1
  38. package/dest/log/pino-logger.js +32 -18
  39. package/dest/queue/base_memory_queue.d.ts.map +1 -1
  40. package/dest/queue/base_memory_queue.js +3 -3
  41. package/dest/queue/bounded_serial_queue.d.ts.map +1 -1
  42. package/dest/queue/bounded_serial_queue.js +3 -3
  43. package/dest/queue/fifo_memory_queue.d.ts +2 -2
  44. package/dest/queue/fifo_memory_queue.d.ts.map +1 -1
  45. package/dest/queue/fifo_memory_queue.js +1 -1
  46. package/dest/retry/index.d.ts.map +1 -1
  47. package/dest/retry/index.js +3 -3
  48. package/dest/schemas/utils.d.ts +3 -1
  49. package/dest/schemas/utils.d.ts.map +1 -1
  50. package/dest/schemas/utils.js +8 -3
  51. package/dest/testing/test_data.d.ts +11 -0
  52. package/dest/testing/test_data.d.ts.map +1 -1
  53. package/dest/testing/test_data.js +24 -1
  54. package/dest/transport/dispatch/create_dispatch_fn.d.ts.map +1 -1
  55. package/dest/transport/dispatch/create_dispatch_fn.js +3 -3
  56. package/dest/transport/transport_client.js +3 -3
  57. package/dest/wasm/wasm_module.d.ts.map +1 -1
  58. package/dest/wasm/wasm_module.js +2 -2
  59. package/dest/worker/worker_pool.js +3 -3
  60. package/package.json +9 -3
  61. package/src/abi/abi.ts +30 -11
  62. package/src/abi/encoder.ts +2 -2
  63. package/src/abi/event_selector.ts +1 -1
  64. package/src/abi/function_selector.ts +1 -1
  65. package/src/collection/array.ts +10 -0
  66. package/src/collection/object.ts +22 -0
  67. package/src/config/env_var.ts +9 -2
  68. package/src/crypto/random/randomness_singleton.ts +2 -2
  69. package/src/fields/fields.ts +40 -2
  70. package/src/fs/run_in_dir.ts +1 -1
  71. package/src/iterable/index.ts +1 -0
  72. package/src/iterable/toArray.ts +7 -0
  73. package/src/jest/setup.mjs +9 -0
  74. package/src/json-rpc/client/fetch.ts +3 -3
  75. package/src/json-rpc/client/safe_json_rpc_client.ts +7 -15
  76. package/src/json-rpc/server/safe_json_rpc_server.ts +5 -5
  77. package/src/log/log-filters.ts +7 -1
  78. package/src/log/log_fn.ts +1 -1
  79. package/src/log/pino-logger.ts +48 -41
  80. package/src/queue/base_memory_queue.ts +2 -2
  81. package/src/queue/bounded_serial_queue.ts +2 -2
  82. package/src/queue/fifo_memory_queue.ts +2 -2
  83. package/src/retry/index.ts +2 -2
  84. package/src/schemas/utils.ts +10 -2
  85. package/src/testing/test_data.ts +25 -0
  86. package/src/transport/dispatch/create_dispatch_fn.ts +2 -2
  87. package/src/transport/transport_client.ts +2 -2
  88. package/src/wasm/wasm_module.ts +1 -1
  89. package/src/worker/worker_pool.ts +2 -2
@@ -1,11 +1,11 @@
1
1
  import { TimeoutError } from '../error/index.js';
2
- import { createDebugLogger } from '../log/index.js';
2
+ import { createLogger } from '../log/index.js';
3
3
 
4
4
  export abstract class BaseMemoryQueue<T> {
5
5
  private waiting: ((item: T | null) => void)[] = [];
6
6
  private flushing = false;
7
7
 
8
- constructor(private log = createDebugLogger('aztec:foundation:memory_fifo')) {}
8
+ constructor(private log = createLogger('foundation:memory_fifo')) {}
9
9
 
10
10
  protected abstract get items(): {
11
11
  length: number;
@@ -1,4 +1,4 @@
1
- import { createDebugLogger } from '../log/index.js';
1
+ import { createLogger } from '../log/index.js';
2
2
  import { Semaphore } from './semaphore.js';
3
3
  import { SerialQueue } from './serial_queue.js';
4
4
 
@@ -10,7 +10,7 @@ export class BoundedSerialQueue {
10
10
  private readonly queue = new SerialQueue();
11
11
  private semaphore: Semaphore;
12
12
 
13
- constructor(maxQueueSize: number, private log = createDebugLogger('aztec:foundation:bounded_serial_queue')) {
13
+ constructor(maxQueueSize: number, private log = createLogger('foundation:bounded_serial_queue')) {
14
14
  this.semaphore = new Semaphore(maxQueueSize);
15
15
  }
16
16
 
@@ -1,4 +1,4 @@
1
- import { type DebugLogger } from '../log/index.js';
1
+ import { type Logger } from '../log/index.js';
2
2
  import { BaseMemoryQueue } from './base_memory_queue.js';
3
3
 
4
4
  /**
@@ -9,7 +9,7 @@ import { BaseMemoryQueue } from './base_memory_queue.js';
9
9
  export class FifoMemoryQueue<T> extends BaseMemoryQueue<T> {
10
10
  private container = new FifoQueue<T>();
11
11
 
12
- constructor(log?: DebugLogger) {
12
+ constructor(log?: Logger) {
13
13
  super(log);
14
14
  }
15
15
 
@@ -1,4 +1,4 @@
1
- import { createDebugLogger } from '../log/index.js';
1
+ import { createLogger } from '../log/index.js';
2
2
  import { sleep } from '../sleep/index.js';
3
3
  import { Timer } from '../timer/index.js';
4
4
 
@@ -48,7 +48,7 @@ export async function retry<Result>(
48
48
  fn: () => Promise<Result>,
49
49
  name = 'Operation',
50
50
  backoff = backoffGenerator(),
51
- log = createDebugLogger('aztec:foundation:retry'),
51
+ log = createLogger('foundation:retry'),
52
52
  failSilently = false,
53
53
  ) {
54
54
  while (true) {
@@ -3,13 +3,16 @@ import {
3
3
  type ParseInput,
4
4
  type ParseReturnType,
5
5
  ZodFirstPartyTypeKind,
6
+ type ZodObject,
6
7
  ZodOptional,
7
8
  ZodParsedType,
9
+ type ZodRawShape,
8
10
  type ZodType,
9
11
  type ZodTypeAny,
10
12
  z,
11
13
  } from 'zod';
12
14
 
15
+ import { pick } from '../collection/object.js';
13
16
  import { isHex, withoutHexPrefix } from '../string/index.js';
14
17
  import { type ZodFor } from './types.js';
15
18
 
@@ -72,10 +75,10 @@ export function hexSchemaFor<TClass extends { fromString(str: string): any } | {
72
75
  string
73
76
  > {
74
77
  const stringSchema = refinement ? z.string().refine(refinement, `Not a valid instance`) : z.string();
75
- const hexSchema = stringSchema.refine(isHex, 'Not a valid hex string').transform(withoutHexPrefix);
78
+ const hexSchema = stringSchema.refine(isHex, 'Not a valid hex string');
76
79
  return 'fromString' in klazz
77
80
  ? hexSchema.transform(klazz.fromString.bind(klazz))
78
- : hexSchema.transform(str => Buffer.from(str, 'hex')).transform(klazz.fromBuffer.bind(klazz));
81
+ : hexSchema.transform(str => Buffer.from(withoutHexPrefix(str), 'hex')).transform(klazz.fromBuffer.bind(klazz));
79
82
  }
80
83
 
81
84
  /**
@@ -102,3 +105,8 @@ export function mapSchema<TKey, TValue>(key: ZodFor<TKey>, value: ZodFor<TValue>
102
105
  export function setSchema<T>(value: ZodFor<T>): ZodFor<Set<T>> {
103
106
  return z.array(value).transform(entries => new Set(entries));
104
107
  }
108
+
109
+ /** Given an already parsed and validated object, extracts the keys defined in the given schema. Does not validate again. */
110
+ export function pickFromSchema<T extends object, S extends ZodObject<ZodRawShape>>(obj: T, schema: S) {
111
+ return pick(obj, ...Object.keys(schema.shape));
112
+ }
@@ -5,12 +5,21 @@ import { createConsoleLogger } from '../log/console.js';
5
5
  import { fileURLToPath } from '../url/index.js';
6
6
 
7
7
  const testData: { [key: string]: unknown[] } = {};
8
+ let generateProtocolCircuitTestData = false;
8
9
 
9
10
  /** Returns whether test data generation is enabled */
10
11
  export function isGenerateTestDataEnabled() {
11
12
  return ['1', 'true'].includes(process.env.AZTEC_GENERATE_TEST_DATA ?? '') && typeof expect !== 'undefined';
12
13
  }
13
14
 
15
+ /**
16
+ * This is separate so Prover.tomls don't get edited everytime any test is run,
17
+ * Only full.test updates prover tomls, then switches this off.
18
+ */
19
+ export function switchGenerateProtocolCircuitTestData() {
20
+ generateProtocolCircuitTestData = !generateProtocolCircuitTestData;
21
+ }
22
+
14
23
  /** Pushes test data with the given name, only if test data generation is enabled. */
15
24
  export function pushTestData<T>(itemName: string, data: T) {
16
25
  if (!isGenerateTestDataEnabled()) {
@@ -76,6 +85,22 @@ export function updateInlineTestData(targetFileFromRepoRoot: string, itemName: s
76
85
  logger(`Updated test data in ${targetFile} for ${itemName} to ${value}`);
77
86
  }
78
87
 
88
+ /**
89
+ * Updates the sample Prover.toml files in noir-projects/noir-protocol-circuits/crates/.
90
+ * @remarks Requires AZTEC_GENERATE_TEST_DATA=1 & generateProtocolCircuitTestData=true to be set
91
+ * To re-gen, run 'AZTEC_GENERATE_TEST_DATA=1 FAKE_PROOFS=1 yarn workspace @aztec/end-to-end test full.test'
92
+ */
93
+ export function updateProtocolCircuitSampleInputs(circuitName: string, value: string) {
94
+ if (!isGenerateTestDataEnabled() || !generateProtocolCircuitTestData) {
95
+ return;
96
+ }
97
+ const logger = createConsoleLogger('aztec:testing:test_data');
98
+ const targetFileFromRepoRoot = `noir-projects/noir-protocol-circuits/crates/${circuitName}/Prover.toml`;
99
+ const targetFile = getPathToFile(targetFileFromRepoRoot);
100
+ writeFileSync(targetFile, value);
101
+ logger(`Updated test data in ${targetFile} for ${circuitName}`);
102
+ }
103
+
79
104
  function getPathToFile(targetFileFromRepoRoot: string) {
80
105
  const repoRoot = resolve(dirname(fileURLToPath(import.meta.url)), '../../../../');
81
106
  if (!existsSync(join(repoRoot, 'CODEOWNERS'))) {
@@ -1,6 +1,6 @@
1
1
  import { format } from 'util';
2
2
 
3
- import { createDebugLogger } from '../../log/index.js';
3
+ import { createLogger } from '../../log/index.js';
4
4
 
5
5
  /**
6
6
  * Represents a message object for dispatching function calls.
@@ -26,7 +26,7 @@ export interface DispatchMsg {
26
26
  * @param log - Optional logging function for debugging purposes.
27
27
  * @returns A dispatch function that accepts a DispatchMsg object and calls the target's method with provided arguments.
28
28
  */
29
- export function createDispatchFn(targetFn: () => any, log = createDebugLogger('aztec:foundation:dispatch')) {
29
+ export function createDispatchFn(targetFn: () => any, log = createLogger('foundation:dispatch')) {
30
30
  return async ({ fn, args }: DispatchMsg) => {
31
31
  const target = targetFn();
32
32
  log.debug(format(`dispatching to ${target}: ${fn}`, args));
@@ -1,12 +1,12 @@
1
1
  import EventEmitter from 'events';
2
2
  import { format } from 'util';
3
3
 
4
- import { createDebugLogger } from '../log/index.js';
4
+ import { createLogger } from '../log/index.js';
5
5
  import { type EventMessage, type ResponseMessage, isEventMessage } from './dispatch/messages.js';
6
6
  import { type Connector } from './interface/connector.js';
7
7
  import { type Socket } from './interface/socket.js';
8
8
 
9
- const log = createDebugLogger('aztec:transport_client');
9
+ const log = createLogger('foundation:transport_client');
10
10
 
11
11
  /**
12
12
  * Represents a pending request in the TransportClient.
@@ -59,7 +59,7 @@ export class WasmModule implements IWasmModule {
59
59
  constructor(
60
60
  private module: WebAssembly.Module | Buffer,
61
61
  private importFn: (module: WasmModule) => any,
62
- loggerName = 'aztec:wasm',
62
+ loggerName = 'wasm',
63
63
  ) {
64
64
  this.debug = createDebugOnlyLogger(loggerName);
65
65
  this.mutexQ.put(true);
@@ -1,7 +1,7 @@
1
- import { createDebugLogger } from '../log/index.js';
1
+ import { createLogger } from '../log/index.js';
2
2
  import { type WasmWorker } from './wasm_worker.js';
3
3
 
4
- const log = createDebugLogger('bb:worker_pool');
4
+ const log = createLogger('foundation:worker_pool');
5
5
 
6
6
  /**
7
7
  * Type of a worker factory.