@aztec/foundation 0.47.1 → 0.49.2

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 (86) hide show
  1. package/dest/abi/abi.d.ts +7 -1
  2. package/dest/abi/abi.d.ts.map +1 -1
  3. package/dest/abi/abi.js +1 -1
  4. package/dest/config/env_var.d.ts +2 -0
  5. package/dest/config/env_var.d.ts.map +1 -0
  6. package/dest/config/env_var.js +2 -0
  7. package/dest/config/index.d.ts +53 -0
  8. package/dest/config/index.d.ts.map +1 -0
  9. package/dest/config/index.js +99 -0
  10. package/dest/crypto/pedersen/pedersen.wasm.d.ts +1 -1
  11. package/dest/crypto/pedersen/pedersen.wasm.d.ts.map +1 -1
  12. package/dest/crypto/pedersen/pedersen.wasm.js +3 -3
  13. package/dest/crypto/poseidon/index.d.ts +7 -0
  14. package/dest/crypto/poseidon/index.d.ts.map +1 -1
  15. package/dest/crypto/poseidon/index.js +14 -1
  16. package/dest/fields/fields.js +2 -2
  17. package/dest/fields/point.d.ts +0 -6
  18. package/dest/fields/point.d.ts.map +1 -1
  19. package/dest/fields/point.js +1 -13
  20. package/dest/fs/run_in_dir.d.ts +1 -1
  21. package/dest/fs/run_in_dir.d.ts.map +1 -1
  22. package/dest/fs/run_in_dir.js +8 -4
  23. package/dest/hash/index.d.ts +83 -0
  24. package/dest/hash/index.d.ts.map +1 -0
  25. package/dest/hash/index.js +110 -0
  26. package/dest/index.d.ts +3 -1
  27. package/dest/index.d.ts.map +1 -1
  28. package/dest/index.js +4 -2
  29. package/dest/noir/noir_package_config.d.ts +4 -4
  30. package/dest/promise/running-promise.d.ts +5 -0
  31. package/dest/promise/running-promise.d.ts.map +1 -1
  32. package/dest/promise/running-promise.js +8 -1
  33. package/dest/{fifo/memory_fifo.d.ts → queue/base_memory_queue.d.ts} +8 -8
  34. package/dest/queue/base_memory_queue.d.ts.map +1 -0
  35. package/dest/{fifo/memory_fifo.js → queue/base_memory_queue.js} +5 -11
  36. package/dest/queue/bounded_serial_queue.d.ts.map +1 -0
  37. package/dest/{fifo → queue}/bounded_serial_queue.js +1 -1
  38. package/dest/queue/fifo_memory_queue.d.ts +21 -0
  39. package/dest/queue/fifo_memory_queue.d.ts.map +1 -0
  40. package/dest/queue/fifo_memory_queue.js +33 -0
  41. package/dest/queue/index.d.ts +6 -0
  42. package/dest/queue/index.d.ts.map +1 -0
  43. package/dest/queue/index.js +6 -0
  44. package/dest/queue/priority_memory_queue.d.ts +13 -0
  45. package/dest/queue/priority_memory_queue.d.ts.map +1 -0
  46. package/dest/queue/priority_memory_queue.js +17 -0
  47. package/dest/queue/priority_queue.d.ts +14 -0
  48. package/dest/queue/priority_queue.d.ts.map +1 -0
  49. package/dest/queue/priority_queue.js +29 -0
  50. package/dest/queue/semaphore.d.ts.map +1 -0
  51. package/dest/{fifo → queue}/semaphore.js +3 -3
  52. package/dest/queue/serial_queue.d.ts.map +1 -0
  53. package/dest/{fifo → queue}/serial_queue.js +3 -3
  54. package/dest/wasm/wasm_module.d.ts.map +1 -1
  55. package/dest/wasm/wasm_module.js +3 -3
  56. package/package.json +5 -3
  57. package/src/abi/abi.ts +9 -1
  58. package/src/config/env_var.ts +98 -0
  59. package/src/config/index.ts +132 -0
  60. package/src/crypto/pedersen/pedersen.wasm.ts +5 -2
  61. package/src/crypto/poseidon/index.ts +20 -0
  62. package/src/fields/fields.ts +1 -1
  63. package/src/fields/point.ts +0 -13
  64. package/src/fs/run_in_dir.ts +6 -3
  65. package/src/hash/index.ts +123 -0
  66. package/src/index.ts +3 -1
  67. package/src/promise/running-promise.ts +8 -0
  68. package/src/{fifo/memory_fifo.ts → queue/base_memory_queue.ts} +11 -10
  69. package/src/queue/fifo_memory_queue.ts +39 -0
  70. package/src/{fifo → queue}/index.ts +2 -1
  71. package/src/queue/priority_memory_queue.ts +20 -0
  72. package/src/queue/priority_queue.ts +34 -0
  73. package/src/{fifo → queue}/semaphore.ts +2 -2
  74. package/src/{fifo → queue}/serial_queue.ts +2 -2
  75. package/src/wasm/wasm_module.ts +2 -2
  76. package/dest/fifo/bounded_serial_queue.d.ts.map +0 -1
  77. package/dest/fifo/index.d.ts +0 -5
  78. package/dest/fifo/index.d.ts.map +0 -1
  79. package/dest/fifo/index.js +0 -5
  80. package/dest/fifo/memory_fifo.d.ts.map +0 -1
  81. package/dest/fifo/semaphore.d.ts.map +0 -1
  82. package/dest/fifo/serial_queue.d.ts.map +0 -1
  83. /package/dest/{fifo → queue}/bounded_serial_queue.d.ts +0 -0
  84. /package/dest/{fifo → queue}/semaphore.d.ts +0 -0
  85. /package/dest/{fifo → queue}/serial_queue.d.ts +0 -0
  86. /package/src/{fifo → queue}/bounded_serial_queue.ts +0 -0
@@ -1,18 +1,19 @@
1
1
  import { TimeoutError } from '../error/index.js';
2
2
  import { createDebugLogger } from '../log/index.js';
3
3
 
4
- /**
5
- * A simple fifo queue. It can grow unbounded. It can have multiple producers and consumers.
6
- * Putting an item onto the queue always succeeds, unless either end() or cancel() has been called in which case
7
- * the item being pushed is simply discarded.
8
- */
9
- export class MemoryFifo<T> {
4
+ export abstract class BaseMemoryQueue<T> {
10
5
  private waiting: ((item: T | null) => void)[] = [];
11
- private items: T[] = [];
12
6
  private flushing = false;
13
7
 
14
8
  constructor(private log = createDebugLogger('aztec:foundation:memory_fifo')) {}
15
9
 
10
+ protected abstract get items(): {
11
+ length: number;
12
+ get(): T | undefined;
13
+ put(item: T): void;
14
+ clear: () => void;
15
+ };
16
+
16
17
  /**
17
18
  * Returns the current number of items in the queue.
18
19
  * The length represents the size of the queue at the time of invocation and may change as new items are added or consumed.
@@ -36,7 +37,7 @@ export class MemoryFifo<T> {
36
37
  */
37
38
  public get(timeoutSec?: number): Promise<T | null> {
38
39
  if (this.items.length) {
39
- return Promise.resolve(this.items.shift()!);
40
+ return Promise.resolve(this.items.get()!);
40
41
  }
41
42
 
42
43
  if (this.items.length === 0 && this.flushing) {
@@ -78,7 +79,7 @@ export class MemoryFifo<T> {
78
79
  this.waiting.shift()!(item);
79
80
  return true;
80
81
  } else {
81
- this.items.push(item);
82
+ this.items.put(item);
82
83
  return true;
83
84
  }
84
85
  }
@@ -100,7 +101,7 @@ export class MemoryFifo<T> {
100
101
  */
101
102
  public cancel() {
102
103
  this.flushing = true;
103
- this.items = [];
104
+ this.items.clear();
104
105
  this.waiting.forEach(resolve => resolve(null));
105
106
  }
106
107
 
@@ -0,0 +1,39 @@
1
+ import { type DebugLogger } from '../log/logger.js';
2
+ import { BaseMemoryQueue } from './base_memory_queue.js';
3
+
4
+ /**
5
+ * A simple fifo queue. It can grow unbounded. It can have multiple producers and consumers.
6
+ * Putting an item onto the queue always succeeds, unless either end() or cancel() has been called in which case
7
+ * the item being pushed is simply discarded.
8
+ */
9
+ export class FifoMemoryQueue<T> extends BaseMemoryQueue<T> {
10
+ private container = new FifoQueue<T>();
11
+
12
+ constructor(log?: DebugLogger) {
13
+ super(log);
14
+ }
15
+
16
+ protected override get items() {
17
+ return this.container;
18
+ }
19
+ }
20
+
21
+ class FifoQueue<T> {
22
+ private items: T[] = [];
23
+
24
+ public put(item: T): void {
25
+ this.items.push(item);
26
+ }
27
+
28
+ public get(): T | undefined {
29
+ return this.items.shift();
30
+ }
31
+
32
+ public get length(): number {
33
+ return this.items.length;
34
+ }
35
+
36
+ public clear() {
37
+ this.items = [];
38
+ }
39
+ }
@@ -1,4 +1,5 @@
1
- export * from './memory_fifo.js';
1
+ export * from './fifo_memory_queue.js';
2
+ export * from './priority_memory_queue.js';
2
3
  export * from './serial_queue.js';
3
4
  export * from './bounded_serial_queue.js';
4
5
  export * from './semaphore.js';
@@ -0,0 +1,20 @@
1
+ import { BaseMemoryQueue } from './base_memory_queue.js';
2
+ import { PriorityQueue } from './priority_queue.js';
3
+
4
+ /**
5
+ * A priority queue. It can grow unbounded. It can have multiple producers and consumers.
6
+ * Putting an item onto the queue always succeeds, unless either end() or cancel() has been called in which case
7
+ * the item being pushed is simply discarded.
8
+ */
9
+ export class PriorityMemoryQueue<T> extends BaseMemoryQueue<T> {
10
+ private container: PriorityQueue<T>;
11
+
12
+ constructor(comparator: (a: T, b: T) => number) {
13
+ super();
14
+ this.container = new PriorityQueue(comparator);
15
+ }
16
+
17
+ protected override get items() {
18
+ return this.container;
19
+ }
20
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Priority queue implementation based on a custom comparator.
3
+ */
4
+ export class PriorityQueue<T> {
5
+ private items: T[];
6
+
7
+ constructor(private comparator: (a: T, b: T) => number) {
8
+ this.items = [];
9
+ }
10
+
11
+ public put(item: T): void {
12
+ let i = 0;
13
+ while (i < this.items.length && this.comparator(item, this.items[i]) >= 0) {
14
+ i++;
15
+ }
16
+ this.items.splice(i, 0, item);
17
+ }
18
+
19
+ public get(): T | undefined {
20
+ return this.items.shift();
21
+ }
22
+
23
+ public peek(): T | undefined {
24
+ return this.items[0];
25
+ }
26
+
27
+ public clear() {
28
+ this.items = [];
29
+ }
30
+
31
+ public get length(): number {
32
+ return this.items.length;
33
+ }
34
+ }
@@ -1,10 +1,10 @@
1
- import { MemoryFifo } from './memory_fifo.js';
1
+ import { FifoMemoryQueue } from './fifo_memory_queue.js';
2
2
 
3
3
  /**
4
4
  * Allows the acquiring of up to `size` tokens before calls to acquire block, waiting for a call to release().
5
5
  */
6
6
  export class Semaphore {
7
- private readonly queue = new MemoryFifo<boolean>();
7
+ private readonly queue = new FifoMemoryQueue<boolean>();
8
8
 
9
9
  constructor(size: number) {
10
10
  new Array(size).fill(true).map(() => this.queue.put(true));
@@ -1,10 +1,10 @@
1
- import { MemoryFifo } from './memory_fifo.js';
1
+ import { FifoMemoryQueue } from './fifo_memory_queue.js';
2
2
 
3
3
  /**
4
4
  * A more specialized fifo queue that enqueues functions to execute. Enqueued functions are executed in serial.
5
5
  */
6
6
  export class SerialQueue {
7
- private readonly queue = new MemoryFifo<() => Promise<void>>();
7
+ private readonly queue = new FifoMemoryQueue<() => Promise<void>>();
8
8
  private runningPromise!: Promise<void>;
9
9
 
10
10
  /**
@@ -1,8 +1,8 @@
1
1
  import { Buffer } from 'buffer';
2
2
 
3
3
  import { randomBytes } from '../crypto/index.js';
4
- import { MemoryFifo } from '../fifo/index.js';
5
4
  import { type LogFn, createDebugOnlyLogger } from '../log/index.js';
5
+ import { FifoMemoryQueue } from '../queue/index.js';
6
6
  import { getEmptyWasiSdk } from './empty_wasi_sdk.js';
7
7
 
8
8
  /**
@@ -47,7 +47,7 @@ export class WasmModule implements IWasmModule {
47
47
  private memory!: WebAssembly.Memory;
48
48
  private heap!: Uint8Array;
49
49
  private instance?: WebAssembly.Instance;
50
- private mutexQ = new MemoryFifo<boolean>();
50
+ private mutexQ = new FifoMemoryQueue<boolean>();
51
51
  private debug: LogFn;
52
52
 
53
53
  /**
@@ -1 +0,0 @@
1
- {"version":3,"file":"bounded_serial_queue.d.ts","sourceRoot":"","sources":["../../src/fifo/bounded_serial_queue.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,qBAAa,kBAAkB;IAIK,OAAO,CAAC,GAAG;IAH7C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAqB;IAC3C,OAAO,CAAC,SAAS,CAAY;gBAEjB,YAAY,EAAE,MAAM,EAAU,GAAG,oCAA6D;IAI1G;;;OAGG;IACI,KAAK;IAIZ;;;;;OAKG;IACI,MAAM;IAIb;;;;;OAKG;IACI,MAAM;IAIb;;;;;;;OAOG;IACI,GAAG;IAIV;;;;;OAKG;IACU,GAAG,CAAC,EAAE,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAexD;;;;OAIG;IACU,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAWtD;;OAEG;IACU,SAAS;CAGvB"}
@@ -1,5 +0,0 @@
1
- export * from './memory_fifo.js';
2
- export * from './serial_queue.js';
3
- export * from './bounded_serial_queue.js';
4
- export * from './semaphore.js';
5
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fifo/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gBAAgB,CAAC"}
@@ -1,5 +0,0 @@
1
- export * from './memory_fifo.js';
2
- export * from './serial_queue.js';
3
- export * from './bounded_serial_queue.js';
4
- export * from './semaphore.js';
5
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvZmlmby9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxjQUFjLGtCQUFrQixDQUFDO0FBQ2pDLGNBQWMsbUJBQW1CLENBQUM7QUFDbEMsY0FBYywyQkFBMkIsQ0FBQztBQUMxQyxjQUFjLGdCQUFnQixDQUFDIn0=
@@ -1 +0,0 @@
1
- {"version":3,"file":"memory_fifo.d.ts","sourceRoot":"","sources":["../../src/fifo/memory_fifo.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,qBAAa,UAAU,CAAC,CAAC;IAKX,OAAO,CAAC,GAAG;IAJvB,OAAO,CAAC,OAAO,CAAoC;IACnD,OAAO,CAAC,KAAK,CAAW;IACxB,OAAO,CAAC,QAAQ,CAAS;gBAEL,GAAG,oCAAoD;IAE3E;;;;;OAKG;IACI,MAAM;IAIb;;;;;;;;;;OAUG;IACI,GAAG,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;IA+BlD;;;;OAIG;IACI,GAAG,CAAC,IAAI,EAAE,CAAC,GAAG,OAAO;IAa5B;;;;OAIG;IACI,GAAG;IAKV;;;;OAIG;IACI,MAAM;IAMb;;;;;;;;OAQG;IACU,OAAO,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC;CAazD"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"semaphore.d.ts","sourceRoot":"","sources":["../../src/fifo/semaphore.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA6B;gBAEvC,IAAI,EAAE,MAAM;IAIxB;;;;;;OAMG;IACU,OAAO;IAIpB;;;;;OAKG;IACI,OAAO;CAGf"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"serial_queue.d.ts","sourceRoot":"","sources":["../../src/fifo/serial_queue.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAyC;IAC/D,OAAO,CAAC,cAAc,CAAiB;IAEvC;;;;;OAKG;IACI,KAAK;IAIZ;;;;;OAKG;IACI,MAAM;IAIb;;;;;;OAMG;IACI,MAAM;IAKb;;;;;OAKG;IACI,GAAG;IAKV;;;;;OAKG;IACI,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAgB/C;;OAEG;IACU,SAAS;CAGvB"}
File without changes
File without changes
File without changes
File without changes