@aztec/foundation 0.16.4 → 0.16.5

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 (121) hide show
  1. package/dest/abi/function_selector.js +2 -2
  2. package/dest/aztec-address/index.js +2 -2
  3. package/dest/json-rpc/server/index.d.ts +1 -1
  4. package/dest/json-rpc/server/index.d.ts.map +1 -1
  5. package/dest/json-rpc/server/index.js +2 -2
  6. package/dest/json-rpc/server/json_rpc_server.d.ts +7 -0
  7. package/dest/json-rpc/server/json_rpc_server.d.ts.map +1 -1
  8. package/dest/json-rpc/server/json_rpc_server.js +13 -1
  9. package/package.json +2 -2
  10. package/src/abi/abi.ts +0 -310
  11. package/src/abi/abi_coder.ts +0 -25
  12. package/src/abi/decoder.ts +0 -161
  13. package/src/abi/encoder.ts +0 -120
  14. package/src/abi/function_selector.ts +0 -135
  15. package/src/abi/index.ts +0 -6
  16. package/src/abi/utils.ts +0 -28
  17. package/src/async-map/index.ts +0 -18
  18. package/src/aztec-address/index.ts +0 -30
  19. package/src/bigint-buffer/index.ts +0 -74
  20. package/src/collection/array.ts +0 -54
  21. package/src/collection/index.ts +0 -1
  22. package/src/committable/committable.ts +0 -46
  23. package/src/committable/index.ts +0 -1
  24. package/src/crypto/index.ts +0 -16
  25. package/src/crypto/keccak/index.ts +0 -33
  26. package/src/crypto/pedersen/index.ts +0 -1
  27. package/src/crypto/pedersen/pedersen.elliptic.ts +0 -584
  28. package/src/crypto/pedersen/pedersen.noble.ts +0 -573
  29. package/src/crypto/pedersen/pedersen.wasm.ts +0 -42
  30. package/src/crypto/random/index.ts +0 -42
  31. package/src/crypto/sha256/index.ts +0 -3
  32. package/src/errors/index.ts +0 -6
  33. package/src/eth-address/index.ts +0 -244
  34. package/src/fields/coordinate.ts +0 -104
  35. package/src/fields/fields.ts +0 -261
  36. package/src/fields/index.ts +0 -3
  37. package/src/fields/point.ts +0 -140
  38. package/src/fifo/bounded_serial_queue.ts +0 -100
  39. package/src/fifo/index.ts +0 -4
  40. package/src/fifo/memory_fifo.ts +0 -114
  41. package/src/fifo/semaphore.ts +0 -33
  42. package/src/fifo/serial_queue.ts +0 -78
  43. package/src/index.ts +0 -29
  44. package/src/json-rpc/README.md +0 -55
  45. package/src/json-rpc/class_converter.ts +0 -209
  46. package/src/json-rpc/client/index.ts +0 -1
  47. package/src/json-rpc/client/json_rpc_client.ts +0 -136
  48. package/src/json-rpc/convert.ts +0 -163
  49. package/src/json-rpc/fixtures/class_a.ts +0 -15
  50. package/src/json-rpc/fixtures/class_b.ts +0 -15
  51. package/src/json-rpc/fixtures/test_state.ts +0 -59
  52. package/src/json-rpc/index.ts +0 -8
  53. package/src/json-rpc/js_utils.ts +0 -20
  54. package/src/json-rpc/server/index.ts +0 -2
  55. package/src/json-rpc/server/json_proxy.ts +0 -43
  56. package/src/json-rpc/server/json_rpc_server.ts +0 -190
  57. package/src/log/console.ts +0 -39
  58. package/src/log/debug.ts +0 -83
  59. package/src/log/index.ts +0 -5
  60. package/src/log/log_fn.ts +0 -5
  61. package/src/log/log_history.ts +0 -44
  62. package/src/log/logger.ts +0 -137
  63. package/src/mutex/index.ts +0 -83
  64. package/src/mutex/mutex_database.ts +0 -12
  65. package/src/noir/index.ts +0 -1
  66. package/src/noir/noir_package_config.ts +0 -54
  67. package/src/retry/index.ts +0 -99
  68. package/src/running-promise/index.ts +0 -60
  69. package/src/serialize/buffer_reader.ts +0 -250
  70. package/src/serialize/free_funcs.ts +0 -279
  71. package/src/serialize/index.ts +0 -3
  72. package/src/serialize/types.ts +0 -40
  73. package/src/sleep/index.ts +0 -71
  74. package/src/testing/index.ts +0 -1
  75. package/src/testing/test_data.ts +0 -36
  76. package/src/timer/elapsed.ts +0 -23
  77. package/src/timer/index.ts +0 -3
  78. package/src/timer/timeout.ts +0 -64
  79. package/src/timer/timer.ts +0 -48
  80. package/src/transport/browser/index.ts +0 -4
  81. package/src/transport/browser/message_port_socket.ts +0 -48
  82. package/src/transport/browser/shared_worker_connector.ts +0 -21
  83. package/src/transport/browser/shared_worker_listener.ts +0 -53
  84. package/src/transport/browser/worker_connector.ts +0 -30
  85. package/src/transport/browser/worker_listener.ts +0 -54
  86. package/src/transport/dispatch/create_dispatch_fn.ts +0 -35
  87. package/src/transport/dispatch/create_dispatch_proxy.ts +0 -141
  88. package/src/transport/dispatch/messages.ts +0 -58
  89. package/src/transport/index.ts +0 -11
  90. package/src/transport/interface/connector.ts +0 -9
  91. package/src/transport/interface/listener.ts +0 -16
  92. package/src/transport/interface/socket.ts +0 -15
  93. package/src/transport/interface/transferable.ts +0 -125
  94. package/src/transport/node/index.ts +0 -2
  95. package/src/transport/node/node_connector.ts +0 -30
  96. package/src/transport/node/node_connector_socket.ts +0 -52
  97. package/src/transport/node/node_listener.ts +0 -34
  98. package/src/transport/node/node_listener_socket.ts +0 -48
  99. package/src/transport/transport_client.ts +0 -131
  100. package/src/transport/transport_server.ts +0 -108
  101. package/src/trees/index.ts +0 -48
  102. package/src/types/index.ts +0 -7
  103. package/src/url/index.ts +0 -73
  104. package/src/wasm/README.md +0 -6
  105. package/src/wasm/empty_wasi_sdk.ts +0 -166
  106. package/src/wasm/fixtures/gcd.wasm +0 -0
  107. package/src/wasm/fixtures/gcd.wat +0 -27
  108. package/src/wasm/index.ts +0 -1
  109. package/src/wasm/wasm_module.ts +0 -260
  110. package/src/worker/browser/index.ts +0 -2
  111. package/src/worker/browser/start_web_module.ts +0 -23
  112. package/src/worker/browser/web_data_store.ts +0 -38
  113. package/src/worker/browser/web_worker.ts +0 -24
  114. package/src/worker/data_store.ts +0 -19
  115. package/src/worker/index.ts +0 -2
  116. package/src/worker/node/index.ts +0 -2
  117. package/src/worker/node/node_data_store.ts +0 -27
  118. package/src/worker/node/node_worker.ts +0 -22
  119. package/src/worker/node/start_node_module.ts +0 -29
  120. package/src/worker/wasm_worker.ts +0 -7
  121. package/src/worker/worker_pool.ts +0 -73
@@ -1,120 +0,0 @@
1
- import { ABIType, FunctionAbi, isAddressStruct } from '@aztec/foundation/abi';
2
-
3
- import { Fr } from '../fields/index.js';
4
-
5
- /**
6
- * Encodes arguments for a function call.
7
- * Missing support for integer and string.
8
- */
9
- class ArgumentEncoder {
10
- private flattened: Fr[] = [];
11
-
12
- constructor(private abi: FunctionAbi, private args: any[]) {}
13
-
14
- static typeSize(abiType: ABIType): number {
15
- switch (abiType.kind) {
16
- case 'field':
17
- case 'boolean':
18
- case 'integer':
19
- return 1;
20
- case 'string':
21
- return abiType.length;
22
- case 'array':
23
- return abiType.length * ArgumentEncoder.typeSize(abiType.type);
24
- case 'struct':
25
- return abiType.fields.reduce((acc, field) => acc + ArgumentEncoder.typeSize(field.type), 0);
26
- default: {
27
- const exhaustiveCheck: never = abiType;
28
- throw new Error(`Unhandled abi type: ${exhaustiveCheck}`);
29
- }
30
- }
31
- }
32
-
33
- /**
34
- * Encodes a single argument from the given type to field.
35
- * @param abiType - The abi type of the argument.
36
- * @param arg - The value to encode.
37
- * @param name - Name.
38
- */
39
- private encodeArgument(abiType: ABIType, arg: any, name?: string) {
40
- if (arg === undefined || arg == null) {
41
- throw new Error(`Undefined argument ${name ?? 'unnamed'} of type ${abiType.kind}`);
42
- }
43
- switch (abiType.kind) {
44
- case 'field':
45
- if (typeof arg === 'number') {
46
- this.flattened.push(new Fr(BigInt(arg)));
47
- } else if (typeof arg === 'bigint') {
48
- this.flattened.push(new Fr(arg));
49
- } else if (typeof arg === 'boolean') {
50
- this.flattened.push(new Fr(arg ? 1n : 0n));
51
- } else if (typeof arg === 'object') {
52
- if (Buffer.isBuffer(arg)) {
53
- this.flattened.push(Fr.fromBuffer(arg));
54
- } else if (typeof arg.toField === 'function') {
55
- this.flattened.push(arg.toField());
56
- } else {
57
- throw new Error(`Argument for ${name} cannot be serialized to a field`);
58
- }
59
- } else {
60
- throw new Error(`Invalid argument "${arg}" of type ${abiType.kind}`);
61
- }
62
- break;
63
- case 'boolean':
64
- this.flattened.push(new Fr(arg ? 1n : 0n));
65
- break;
66
- case 'array':
67
- for (let i = 0; i < abiType.length; i += 1) {
68
- this.encodeArgument(abiType.type, arg[i], `${name}[${i}]`);
69
- }
70
- break;
71
- case 'struct':
72
- // If the abi expects a struct like { address: Field } and the supplied arg does not have
73
- // an address field in it, we try to encode it as if it were a field directly.
74
- if (isAddressStruct(abiType) && typeof arg.address === 'undefined') {
75
- this.encodeArgument({ kind: 'field' }, arg, `${name}.address`);
76
- break;
77
- }
78
- for (const field of abiType.fields) {
79
- this.encodeArgument(field.type, arg[field.name], `${name}.${field.name}`);
80
- }
81
- break;
82
- case 'integer':
83
- this.flattened.push(new Fr(arg));
84
- break;
85
- default:
86
- throw new Error(`Unsupported type: ${abiType.kind}`);
87
- }
88
- }
89
-
90
- /**
91
- * Encodes all the arguments for the given function ABI.
92
- * @returns The encoded arguments.
93
- */
94
- public encode() {
95
- for (let i = 0; i < this.abi.parameters.length; i += 1) {
96
- const parameterAbi = this.abi.parameters[i];
97
- this.encodeArgument(parameterAbi.type, this.args[i], parameterAbi.name);
98
- }
99
- return this.flattened;
100
- }
101
- }
102
-
103
- /**
104
- * Encodes all the arguments for a function call.
105
- * @param abi - The function ABI entry.
106
- * @param args - The arguments to encode.
107
- * @returns The encoded arguments.
108
- */
109
- export function encodeArguments(abi: FunctionAbi, args: any[]) {
110
- return new ArgumentEncoder(abi, args).encode();
111
- }
112
-
113
- /**
114
- * Returns the size of the arguments for a function ABI.
115
- * @param abi - The function ABI entry.
116
- * @returns The size of the arguments.
117
- */
118
- export function countArgumentsSize(abi: FunctionAbi) {
119
- return abi.parameters.reduce((acc, parameter) => acc + ArgumentEncoder.typeSize(parameter.type), 0);
120
- }
@@ -1,135 +0,0 @@
1
- import { ABIParameter, decodeFunctionSignature } from '@aztec/foundation/abi';
2
- import { toBigIntBE, toBufferBE } from '@aztec/foundation/bigint-buffer';
3
- import { keccak } from '@aztec/foundation/crypto';
4
- import { Fr } from '@aztec/foundation/fields';
5
- import { BufferReader } from '@aztec/foundation/serialize';
6
-
7
- /**
8
- * A function selector is the first 4 bytes of the hash of a function signature.
9
- */
10
- export class FunctionSelector {
11
- /**
12
- * The size of the function selector in bytes.
13
- */
14
- public static SIZE = 4;
15
-
16
- constructor(/** number representing the function selector */ public value: number) {
17
- if (value > 2 ** (FunctionSelector.SIZE * 8) - 1) {
18
- throw new Error(`Function selector must fit in ${FunctionSelector.SIZE} bytes.`);
19
- }
20
- }
21
-
22
- /**
23
- * Checks if the function selector is empty (all bytes are 0).
24
- * @returns True if the function selector is empty (all bytes are 0).
25
- */
26
- public isEmpty(): boolean {
27
- return this.value === 0;
28
- }
29
-
30
- /**
31
- * Serialize as a buffer.
32
- * @param bufferSize - The buffer size.
33
- * @returns The buffer.
34
- */
35
- toBuffer(bufferSize = FunctionSelector.SIZE): Buffer {
36
- return toBufferBE(BigInt(this.value), bufferSize);
37
- }
38
-
39
- /**
40
- * Serialize as a hex string.
41
- * @returns The string.
42
- */
43
- toString(): string {
44
- return this.toBuffer().toString('hex');
45
- }
46
-
47
- /**
48
- * Checks if this function selector is equal to another.
49
- * @param other - The other function selector.
50
- * @returns True if the function selectors are equal.
51
- */
52
- equals(other: FunctionSelector): boolean {
53
- return this.value === other.value;
54
- }
55
-
56
- /**
57
- * Deserializes from a buffer or reader, corresponding to a write in cpp.
58
- * @param buffer - Buffer or BufferReader to read from.
59
- * @returns The FunctionSelector.
60
- */
61
- static fromBuffer(buffer: Buffer | BufferReader): FunctionSelector {
62
- const reader = BufferReader.asReader(buffer);
63
- const value = Number(toBigIntBE(reader.readBytes(FunctionSelector.SIZE)));
64
- return new FunctionSelector(value);
65
- }
66
-
67
- /**
68
- * Returns a new field with the same contents as this EthAddress.
69
- *
70
- * @returns An Fr instance.
71
- */
72
- public toField() {
73
- return new Fr(BigInt(this.value));
74
- }
75
-
76
- /**
77
- * Converts a field to function selector.
78
- * @param fr - The field to convert.
79
- * @returns The function selector.
80
- */
81
- static fromField(fr: Fr): FunctionSelector {
82
- return new FunctionSelector(Number(fr.toBigInt()));
83
- }
84
-
85
- /**
86
- * Creates a function selector from a signature.
87
- * @param signature - Signature of the function to generate the selector for (e.g. "transfer(field,field)").
88
- * @returns Function selector.
89
- */
90
- static fromSignature(signature: string): FunctionSelector {
91
- // throw if signature contains whitespace
92
- if (/\s/.test(signature)) {
93
- throw new Error('Function Signature cannot contain whitespace');
94
- }
95
- return FunctionSelector.fromBuffer(keccak(Buffer.from(signature)).subarray(0, FunctionSelector.SIZE));
96
- }
97
-
98
- /**
99
- * Creates a function selector for a given function name and parameters.
100
- * @param name - The name of the function.
101
- * @param parameters - An array of ABIParameter objects, each containing the type information of a function parameter.
102
- * @returns A Buffer containing the 4-byte function selector.
103
- */
104
- static fromNameAndParameters(name: string, parameters: ABIParameter[]) {
105
- const signature = decodeFunctionSignature(name, parameters);
106
- const selector = FunctionSelector.fromSignature(signature);
107
- // If using the debug logger here it kill the typing in the `server_world_state_synchronizer` and jest tests.
108
- // console.log(`Function selector for ${signature} is ${selector}`);
109
- return selector;
110
- }
111
-
112
- /**
113
- * Create an AztecAddress instance from a hex-encoded string.
114
- * The input 'address' should be prefixed with '0x' or not, and have exactly 64 hex characters.
115
- * Throws an error if the input length is invalid or address value is out of range.
116
- *
117
- * @param selector - The hex-encoded string representing the Aztec address.
118
- * @returns An AztecAddress instance.
119
- */
120
- static fromString(selector: string) {
121
- const buf = Buffer.from(selector.replace(/^0x/i, ''), 'hex');
122
- if (buf.length !== FunctionSelector.SIZE) {
123
- throw new Error(`Invalid length ${buf.length}.`);
124
- }
125
- return FunctionSelector.fromBuffer(buf);
126
- }
127
-
128
- /**
129
- * Creates an empty function selector.
130
- * @returns An empty function selector.
131
- */
132
- static empty(): FunctionSelector {
133
- return new FunctionSelector(0);
134
- }
135
- }
package/src/abi/index.ts DELETED
@@ -1,6 +0,0 @@
1
- export * from './abi.js';
2
- export * from './abi_coder.js';
3
- export * from './encoder.js';
4
- export * from './decoder.js';
5
- export * from './function_selector.js';
6
- export * from './utils.js';
package/src/abi/utils.ts DELETED
@@ -1,28 +0,0 @@
1
- import { ABIType } from './abi.js';
2
-
3
- /**
4
- * Returns whether the ABI type is an Aztec or Ethereum Address defined in Aztec.nr.
5
- * @param abiType - Type to check.
6
- * @returns Boolean.
7
- */
8
- export function isAddressStruct(abiType: ABIType) {
9
- return isEthereumAddressStruct(abiType) || isAztecAddressStruct(abiType);
10
- }
11
-
12
- /**
13
- * Returns whether the ABI type is an Ethereum Address defined in Aztec.nr.
14
- * @param abiType - Type to check.
15
- * @returns Boolean.
16
- */
17
- export function isEthereumAddressStruct(abiType: ABIType) {
18
- return abiType.kind === 'struct' && abiType.path.endsWith('::types::address::EthereumAddress');
19
- }
20
-
21
- /**
22
- * Returns whether the ABI type is an Aztec Address defined in Aztec.nr.
23
- * @param abiType - Type to check.
24
- * @returns Boolean.
25
- */
26
- export function isAztecAddressStruct(abiType: ABIType) {
27
- return abiType.kind === 'struct' && abiType.path.endsWith('::types::address::AztecAddress');
28
- }
@@ -1,18 +0,0 @@
1
- /**
2
- * Maps an array of elements by applying an asynchronous function to each element in sequence,
3
- * and returns a new array with the results. The function receives each element of the array
4
- * and its index as arguments, and should return a Promise that resolves to the desired value.
5
- *
6
- * @typeParam T - The original array element type.
7
- * @typeParam U - The resulting array element type.
8
- * @param arr - The array to map.
9
- * @param fn - The async function to apply on each element of the array.
10
- * @returns A Promise that resolves to a new array containing the mapped values.
11
- */
12
- export async function asyncMap<T, U>(arr: T[], fn: (e: T, i: number) => Promise<U>): Promise<U[]> {
13
- const results: U[] = [];
14
- for (let i = 0; i < arr.length; ++i) {
15
- results.push(await fn(arr[i], i));
16
- }
17
- return results;
18
- }
@@ -1,30 +0,0 @@
1
- import { Fr } from '../fields/index.js';
2
-
3
- /**
4
- * AztecAddress represents a 32-byte address in the Aztec Protocol.
5
- * It provides methods to create, manipulate, and compare addresses.
6
- * The maximum value of an address is determined by the field modulus and all instances of AztecAddress.
7
- * It should have a value less than or equal to this max value.
8
- * This class also provides helper functions to convert addresses from strings, buffers, and other formats.
9
- */
10
- export class AztecAddress extends Fr {
11
- constructor(buffer: Buffer) {
12
- if (buffer.length !== 32) {
13
- throw new Error(`Invalid length ${buffer.length}.`);
14
- }
15
- super(buffer);
16
- }
17
-
18
- static fromField(fr: Fr) {
19
- return new AztecAddress(fr.toBuffer());
20
- }
21
-
22
- static fromBigInt(value: bigint) {
23
- return AztecAddress.fromField(new Fr(value));
24
- }
25
-
26
- static fromString(buf: string) {
27
- const buffer = Buffer.from(buf.replace(/^0x/i, ''), 'hex');
28
- return new AztecAddress(buffer);
29
- }
30
- }
@@ -1,74 +0,0 @@
1
- /**
2
- * Convert a little-endian buffer into a BigInt.
3
- * @param buf - The little-endian buffer to convert.
4
- * @returns A BigInt with the little-endian representation of buf.
5
- */
6
- export function toBigIntLE(buf: Buffer): bigint {
7
- const reversed = Buffer.from(buf);
8
- reversed.reverse();
9
- const hex = reversed.toString('hex');
10
- if (hex.length === 0) {
11
- return BigInt(0);
12
- }
13
- return BigInt(`0x${hex}`);
14
- }
15
-
16
- /**
17
- * Convert a big-endian buffer into a BigInt.
18
- * @param buf - The big-endian buffer to convert.
19
- * @returns A BigInt with the big-endian representation of buf.
20
- */
21
- export function toBigIntBE(buf: Buffer): bigint {
22
- const hex = buf.toString('hex');
23
- if (hex.length === 0) {
24
- return BigInt(0);
25
- }
26
- return BigInt(`0x${hex}`);
27
- }
28
-
29
- /**
30
- * Convert a BigInt to a little-endian buffer.
31
- * @param num - The BigInt to convert.
32
- * @param width - The number of bytes that the resulting buffer should be.
33
- * @returns A little-endian buffer representation of num.
34
- */
35
- export function toBufferLE(num: bigint, width: number): Buffer {
36
- if (num < BigInt(0)) {
37
- throw new Error(`Cannot convert negative bigint ${num.toString()} to buffer with toBufferLE.`);
38
- }
39
- const hex = num.toString(16);
40
- const buffer = Buffer.from(hex.padStart(width * 2, '0').slice(0, width * 2), 'hex');
41
- buffer.reverse();
42
- return buffer;
43
- }
44
-
45
- /**
46
- * Convert a BigInt to a big-endian buffer.
47
- * @param num - The BigInt to convert.
48
- * @param width - The number of bytes that the resulting buffer should be.
49
- * @returns A big-endian buffer representation of num.
50
- */
51
- export function toBufferBE(num: bigint, width: number): Buffer {
52
- if (num < BigInt(0)) {
53
- throw new Error(`Cannot convert negative bigint ${num.toString()} to buffer with toBufferBE.`);
54
- }
55
- const hex = num.toString(16);
56
- const buffer = Buffer.from(hex.padStart(width * 2, '0').slice(0, width * 2), 'hex');
57
- if (buffer.length > width) {
58
- throw new Error(`Number ${num.toString(16)} does not fit in ${width}`);
59
- }
60
- return buffer;
61
- }
62
-
63
- /**
64
- * Converts a BigInt to its hex representation.
65
- * @param num - The BigInt to convert.
66
- * @param padTo32 - Whether to pad the resulting string to 32 bytes.
67
- * @returns An even-length 0x-prefixed string.
68
- */
69
- export function toHex(num: bigint, padTo32 = false): `0x${string}` {
70
- const str = num.toString(16);
71
- const targetLen = str.length % 2 === 0 ? str.length : str.length + 1;
72
- const paddedStr = str.padStart(padTo32 ? 64 : targetLen, '0');
73
- return `0x${paddedStr}`;
74
- }
@@ -1,54 +0,0 @@
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
- }
@@ -1 +0,0 @@
1
- export * from './array.js';
@@ -1,46 +0,0 @@
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
- }
@@ -1 +0,0 @@
1
- export * from './committable.js';
@@ -1,16 +0,0 @@
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
- }
@@ -1,33 +0,0 @@
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
- }
@@ -1 +0,0 @@
1
- export * from './pedersen.wasm.js';