@aztec/foundation 0.22.0 → 0.24.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.
- package/dest/abi/buffer.js +2 -2
- package/dest/fields/fields.d.ts +1 -0
- package/dest/fields/fields.d.ts.map +1 -1
- package/dest/fields/fields.js +6 -3
- package/package.json +2 -2
- package/src/abi/abi.ts +337 -0
- package/src/abi/buffer.ts +36 -0
- package/src/abi/decoder.ts +176 -0
- package/src/abi/encoder.ts +143 -0
- package/src/abi/index.ts +6 -0
- package/src/abi/selector.ts +243 -0
- package/src/abi/utils.ts +50 -0
- package/src/array/array.ts +86 -0
- package/src/array/index.ts +1 -0
- package/src/async-map/index.ts +18 -0
- package/src/aztec-address/index.ts +36 -0
- package/src/bigint-buffer/index.ts +87 -0
- package/src/collection/array.ts +64 -0
- package/src/collection/index.ts +1 -0
- package/src/committable/committable.ts +46 -0
- package/src/committable/index.ts +1 -0
- package/src/crypto/index.ts +16 -0
- package/src/crypto/keccak/index.ts +33 -0
- package/src/crypto/pedersen/index.ts +1 -0
- package/src/crypto/pedersen/pedersen.elliptic.ts +584 -0
- package/src/crypto/pedersen/pedersen.noble.ts +573 -0
- package/src/crypto/pedersen/pedersen.wasm.ts +42 -0
- package/src/crypto/random/index.ts +42 -0
- package/src/crypto/sha256/index.ts +3 -0
- package/src/errors/index.ts +6 -0
- package/src/eth-address/index.ts +234 -0
- package/src/fields/coordinate.ts +104 -0
- package/src/fields/fields.ts +328 -0
- package/src/fields/index.ts +3 -0
- package/src/fields/point.ts +145 -0
- package/src/fifo/bounded_serial_queue.ts +100 -0
- package/src/fifo/index.ts +4 -0
- package/src/fifo/memory_fifo.ts +118 -0
- package/src/fifo/semaphore.ts +33 -0
- package/src/fifo/serial_queue.ts +81 -0
- package/src/index.ts +29 -0
- package/src/json-rpc/README.md +55 -0
- package/src/json-rpc/class_converter.ts +213 -0
- package/src/json-rpc/client/index.ts +1 -0
- package/src/json-rpc/client/json_rpc_client.ts +147 -0
- package/src/json-rpc/convert.ts +163 -0
- package/src/json-rpc/fixtures/class_a.ts +15 -0
- package/src/json-rpc/fixtures/class_b.ts +15 -0
- package/src/json-rpc/fixtures/test_state.ts +59 -0
- package/src/json-rpc/index.ts +8 -0
- package/src/json-rpc/js_utils.ts +20 -0
- package/src/json-rpc/server/index.ts +2 -0
- package/src/json-rpc/server/json_proxy.ts +60 -0
- package/src/json-rpc/server/json_rpc_server.ts +269 -0
- package/src/log/console.ts +39 -0
- package/src/log/debug.ts +83 -0
- package/src/log/index.ts +5 -0
- package/src/log/log_fn.ts +5 -0
- package/src/log/log_history.ts +44 -0
- package/src/log/logger.ts +137 -0
- package/src/mutex/index.ts +83 -0
- package/src/mutex/mutex_database.ts +12 -0
- package/src/noir/index.ts +1 -0
- package/src/noir/noir_package_config.ts +54 -0
- package/src/retry/index.ts +99 -0
- package/src/running-promise/index.ts +60 -0
- package/src/serialize/buffer_reader.ts +286 -0
- package/src/serialize/field_reader.ts +143 -0
- package/src/serialize/free_funcs.ts +147 -0
- package/src/serialize/index.ts +5 -0
- package/src/serialize/serialize.ts +303 -0
- package/src/serialize/types.ts +40 -0
- package/src/sleep/index.ts +71 -0
- package/src/testing/index.ts +1 -0
- package/src/testing/test_data.ts +36 -0
- package/src/timer/elapsed.ts +23 -0
- package/src/timer/index.ts +3 -0
- package/src/timer/timeout.ts +64 -0
- package/src/timer/timer.ts +48 -0
- package/src/transport/browser/index.ts +4 -0
- package/src/transport/browser/message_port_socket.ts +48 -0
- package/src/transport/browser/shared_worker_connector.ts +21 -0
- package/src/transport/browser/shared_worker_listener.ts +53 -0
- package/src/transport/browser/worker_connector.ts +30 -0
- package/src/transport/browser/worker_listener.ts +54 -0
- package/src/transport/dispatch/create_dispatch_fn.ts +35 -0
- package/src/transport/dispatch/create_dispatch_proxy.ts +141 -0
- package/src/transport/dispatch/messages.ts +58 -0
- package/src/transport/index.ts +11 -0
- package/src/transport/interface/connector.ts +9 -0
- package/src/transport/interface/listener.ts +16 -0
- package/src/transport/interface/socket.ts +15 -0
- package/src/transport/interface/transferable.ts +125 -0
- package/src/transport/node/index.ts +2 -0
- package/src/transport/node/node_connector.ts +30 -0
- package/src/transport/node/node_connector_socket.ts +52 -0
- package/src/transport/node/node_listener.ts +34 -0
- package/src/transport/node/node_listener_socket.ts +48 -0
- package/src/transport/transport_client.ts +131 -0
- package/src/transport/transport_server.ts +108 -0
- package/src/trees/index.ts +54 -0
- package/src/types/index.ts +8 -0
- package/src/url/index.ts +73 -0
- package/src/wasm/README.md +6 -0
- package/src/wasm/empty_wasi_sdk.ts +166 -0
- package/src/wasm/fixtures/gcd.wasm +0 -0
- package/src/wasm/fixtures/gcd.wat +27 -0
- package/src/wasm/index.ts +1 -0
- package/src/wasm/wasm_module.ts +260 -0
- package/src/worker/browser/index.ts +2 -0
- package/src/worker/browser/start_web_module.ts +23 -0
- package/src/worker/browser/web_data_store.ts +38 -0
- package/src/worker/browser/web_worker.ts +24 -0
- package/src/worker/data_store.ts +19 -0
- package/src/worker/index.ts +2 -0
- package/src/worker/node/index.ts +2 -0
- package/src/worker/node/node_data_store.ts +27 -0
- package/src/worker/node/node_worker.ts +22 -0
- package/src/worker/node/start_node_module.ts +29 -0
- package/src/worker/wasm_worker.ts +7 -0
- package/src/worker/worker_pool.ts +73 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Tuple } from '../serialize/types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Pads an array to the target length by appending an element to its end. Throws if target length exceeds the input array length. Does not modify the input array.
|
|
5
|
+
* @param arr - Array with elements to pad.
|
|
6
|
+
* @param elem - Element to use for padding.
|
|
7
|
+
* @param length - Target length.
|
|
8
|
+
* @returns A new padded array.
|
|
9
|
+
*/
|
|
10
|
+
export function padArrayEnd<T, N extends number>(arr: T[], elem: T, length: N): Tuple<T, N> {
|
|
11
|
+
if (arr.length > length) {
|
|
12
|
+
throw new Error(`Array size exceeds target length`);
|
|
13
|
+
}
|
|
14
|
+
// Since typescript cannot always deduce that something is a tuple, we cast
|
|
15
|
+
return [...arr, ...Array(length - arr.length).fill(elem)] as Tuple<T, N>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Pads an array to the target length by prepending elements at the beginning. Throws if target length exceeds the input array length. Does not modify the input array.
|
|
20
|
+
* @param arr - Array with elements to pad.
|
|
21
|
+
* @param elem - Element to use for padding.
|
|
22
|
+
* @param length - Target length.
|
|
23
|
+
* @returns A new padded array.
|
|
24
|
+
*/
|
|
25
|
+
export function padArrayStart<T, N extends number>(arr: T[], elem: T, length: N): Tuple<T, N> {
|
|
26
|
+
if (arr.length > length) {
|
|
27
|
+
throw new Error(`Array size exceeds target length`);
|
|
28
|
+
}
|
|
29
|
+
// Since typescript cannot always deduce that something is a tuple, we cast
|
|
30
|
+
return [...Array(length - arr.length).fill(elem), ...arr] as Tuple<T, N>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Returns if an array is composed of empty items.
|
|
35
|
+
* @param arr - Array to check.
|
|
36
|
+
* @returns True if every item in the array isEmpty.
|
|
37
|
+
*/
|
|
38
|
+
export function isArrayEmpty<T>(arr: T[], isEmpty: (item: T) => boolean): boolean {
|
|
39
|
+
for (const item of arr) {
|
|
40
|
+
if (!isEmpty(item)) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Returns the number of non-empty items in an array.
|
|
49
|
+
* @param arr - Array to check.
|
|
50
|
+
* @returns Number of non-empty items in an array.
|
|
51
|
+
*/
|
|
52
|
+
export function arrayNonEmptyLength<T>(arr: T[], isEmpty: (item: T) => boolean): number {
|
|
53
|
+
return arr.reduce((sum, item) => (isEmpty(item) ? sum : sum + 1), 0);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Executes the given function n times and returns the results in an array.
|
|
58
|
+
* @param n - How many times to repeat.
|
|
59
|
+
* @param fn - Mapper from index to value.
|
|
60
|
+
* @returns The array with the result from all executions.
|
|
61
|
+
*/
|
|
62
|
+
export function times<T>(n: number, fn: (i: number) => T): T[] {
|
|
63
|
+
return [...Array(n).keys()].map(i => fn(i));
|
|
64
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './array.js';
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A class that allows for a value to be committed or rolled back.
|
|
3
|
+
*/
|
|
4
|
+
export class Committable<T> {
|
|
5
|
+
private currentValue: T;
|
|
6
|
+
private nextValue: T | undefined = undefined;
|
|
7
|
+
|
|
8
|
+
constructor(initialValue: T) {
|
|
9
|
+
this.currentValue = initialValue;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Commits the uncommitted value.
|
|
14
|
+
*/
|
|
15
|
+
public commit() {
|
|
16
|
+
if (this.nextValue === undefined) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
this.currentValue = this.nextValue;
|
|
20
|
+
this.nextValue = undefined;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Rolls back the uncommitted value.
|
|
25
|
+
*/
|
|
26
|
+
public rollback() {
|
|
27
|
+
this.nextValue === undefined;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Gets the current value.
|
|
32
|
+
* @param includeUncommitted - Whether to include the uncommitted value.
|
|
33
|
+
* @returns The current value if includeUncommitted is false, otherwise the uncommitted value.
|
|
34
|
+
*/
|
|
35
|
+
public get(includeUncommitted: boolean = false): T {
|
|
36
|
+
return includeUncommitted && this.nextValue ? this.nextValue : this.currentValue;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Sets the next value to be committed to.
|
|
41
|
+
* @param value - The new value to be set.
|
|
42
|
+
*/
|
|
43
|
+
public set(value: T) {
|
|
44
|
+
this.nextValue = value;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './committable.js';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BarretenbergSync } from '@aztec/bb.js';
|
|
2
|
+
|
|
3
|
+
export * from './keccak/index.js';
|
|
4
|
+
export * from './random/index.js';
|
|
5
|
+
export * from './sha256/index.js';
|
|
6
|
+
export * from './pedersen/index.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Init the bb singleton. This constructs (if not already) the barretenberg sync api within bb.js itself.
|
|
10
|
+
* It takes about 100-200ms to initialize. It may not seem like much, but when in conjunction with many other things
|
|
11
|
+
* initializing, developers may want to pick precisely when to incur this cost.
|
|
12
|
+
* If in a test environment, we'll just do it on module load.
|
|
13
|
+
*/
|
|
14
|
+
export async function init() {
|
|
15
|
+
await BarretenbergSync.initSingleton();
|
|
16
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Keccak } from 'sha3';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Computes the Keccak-256 hash of the given input buffer.
|
|
5
|
+
*
|
|
6
|
+
* @param input - The input buffer to be hashed.
|
|
7
|
+
* @returns The computed Keccak-256 hash as a Buffer.
|
|
8
|
+
*/
|
|
9
|
+
export function keccak(input: Buffer) {
|
|
10
|
+
const hash = new Keccak(256);
|
|
11
|
+
return hash.update(input).digest();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Computes the keccak-256 hash of a given input string and returns the result as a hexadecimal string.
|
|
16
|
+
*/
|
|
17
|
+
export function keccak256String(input: string) {
|
|
18
|
+
const hash = new Keccak(256);
|
|
19
|
+
hash.reset();
|
|
20
|
+
hash.update(input);
|
|
21
|
+
return hash.digest('hex');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Computes the Keccak-224 hash of the given input buffer.
|
|
26
|
+
*
|
|
27
|
+
* @param input - The input buffer to be hashed.
|
|
28
|
+
* @returns The computed Keccak-224 hash as a Buffer.
|
|
29
|
+
*/
|
|
30
|
+
export function keccak224(input: Buffer) {
|
|
31
|
+
const hash = new Keccak(224);
|
|
32
|
+
return hash.update(input).digest();
|
|
33
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './pedersen.wasm.js';
|