@aztec/foundation 0.56.0 → 0.58.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/abi.d.ts +13 -0
- package/dest/abi/abi.d.ts.map +1 -1
- package/dest/abi/abi.js +1 -1
- package/dest/abi/encoder.d.ts.map +1 -1
- package/dest/abi/encoder.js +6 -1
- package/dest/collection/array.d.ts +4 -0
- package/dest/collection/array.d.ts.map +1 -1
- package/dest/collection/array.js +15 -1
- package/dest/config/env_var.d.ts +1 -1
- package/dest/config/env_var.d.ts.map +1 -1
- package/dest/config/index.d.ts +6 -0
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +12 -1
- package/dest/crypto/keccak/index.d.ts +2 -1
- package/dest/crypto/keccak/index.d.ts.map +1 -1
- package/dest/crypto/keccak/index.js +5 -1
- package/dest/decorators/index.d.ts +2 -0
- package/dest/decorators/index.d.ts.map +1 -0
- package/dest/decorators/index.js +2 -0
- package/dest/decorators/memoize.d.ts +2 -0
- package/dest/decorators/memoize.d.ts.map +1 -0
- package/dest/decorators/memoize.js +12 -0
- package/dest/error/index.d.ts +3 -0
- package/dest/error/index.d.ts.map +1 -1
- package/dest/error/index.js +13 -1
- package/dest/eth-signature/eth_signature.d.ts +3 -0
- package/dest/eth-signature/eth_signature.d.ts.map +1 -1
- package/dest/eth-signature/eth_signature.js +16 -3
- package/dest/fields/fields.js +2 -2
- package/dest/fields/point.js +2 -2
- package/dest/json-rpc/client/json_rpc_client.d.ts.map +1 -1
- package/dest/json-rpc/client/json_rpc_client.js +4 -3
- package/dest/json-rpc/convert.js +2 -2
- package/dest/log/logger.d.ts +9 -1
- package/dest/log/logger.d.ts.map +1 -1
- package/dest/log/logger.js +20 -12
- package/dest/promise/running-promise.d.ts +6 -0
- package/dest/promise/running-promise.d.ts.map +1 -1
- package/dest/promise/running-promise.js +29 -2
- package/dest/queue/base_memory_queue.d.ts +5 -0
- package/dest/queue/base_memory_queue.d.ts.map +1 -1
- package/dest/queue/base_memory_queue.js +8 -1
- package/dest/testing/test_data.js +2 -2
- package/dest/types/index.d.ts +2 -0
- package/dest/types/index.d.ts.map +1 -1
- package/dest/types/index.js +5 -2
- package/package.json +6 -2
- package/src/abi/abi.ts +14 -0
- package/src/abi/encoder.ts +6 -0
- package/src/collection/array.ts +15 -0
- package/src/config/env_var.ts +116 -107
- package/src/config/index.ts +12 -0
- package/src/crypto/keccak/index.ts +6 -1
- package/src/decorators/index.ts +1 -0
- package/src/decorators/memoize.ts +11 -0
- package/src/error/index.ts +9 -3
- package/src/eth-signature/eth_signature.ts +21 -2
- package/src/fields/fields.ts +1 -1
- package/src/fields/point.ts +1 -1
- package/src/json-rpc/client/json_rpc_client.ts +3 -2
- package/src/json-rpc/convert.ts +1 -1
- package/src/log/logger.ts +26 -12
- package/src/promise/running-promise.ts +32 -1
- package/src/queue/base_memory_queue.ts +8 -0
- package/src/testing/test_data.ts +1 -1
- package/src/types/index.ts +5 -0
package/src/collection/array.ts
CHANGED
|
@@ -100,3 +100,18 @@ export function unique<T>(arr: T[]): T[] {
|
|
|
100
100
|
export function compactArray<T>(arr: (T | undefined)[]): T[] {
|
|
101
101
|
return arr.filter((x: T | undefined): x is T => x !== undefined);
|
|
102
102
|
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Returns whether two arrays are equal. The arrays are equal if they have the same length and all elements are equal.
|
|
106
|
+
*/
|
|
107
|
+
export function areArraysEqual<T>(a: T[], b: T[], eq: (a: T, b: T) => boolean = (a: T, b: T) => a === b): boolean {
|
|
108
|
+
if (a.length !== b.length) {
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
for (let i = 0; i < a.length; i++) {
|
|
112
|
+
if (!eq(a[i], b[i])) {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return true;
|
|
117
|
+
}
|
package/src/config/env_var.ts
CHANGED
|
@@ -1,132 +1,141 @@
|
|
|
1
1
|
export type EnvVar =
|
|
2
|
-
| '
|
|
2
|
+
| 'ACVM_BINARY_PATH'
|
|
3
|
+
| 'ACVM_WORKING_DIRECTORY'
|
|
4
|
+
| 'API_KEY'
|
|
5
|
+
| 'API_PREFIX'
|
|
6
|
+
| 'ARCHIVER_MAX_LOGS'
|
|
7
|
+
| 'ARCHIVER_POLLING_INTERVAL_MS'
|
|
8
|
+
| 'ARCHIVER_URL'
|
|
9
|
+
| 'ARCHIVER_VIEM_POLLING_INTERVAL_MS'
|
|
3
10
|
| 'ASSUME_PROVEN_THROUGH_BLOCK_NUMBER'
|
|
4
|
-
| '
|
|
11
|
+
| 'AZTEC_NODE_URL'
|
|
12
|
+
| 'AZTEC_PORT'
|
|
13
|
+
| 'BB_BINARY_PATH'
|
|
14
|
+
| 'BB_SKIP_CLEANUP'
|
|
15
|
+
| 'BB_WORKING_DIRECTORY'
|
|
16
|
+
| 'BOOTSTRAP_NODES'
|
|
17
|
+
| 'BOT_DA_GAS_LIMIT'
|
|
18
|
+
| 'BOT_FEE_PAYMENT_METHOD'
|
|
19
|
+
| 'BOT_FLUSH_SETUP_TRANSACTIONS'
|
|
20
|
+
| 'BOT_FOLLOW_CHAIN'
|
|
21
|
+
| 'BOT_L2_GAS_LIMIT'
|
|
22
|
+
| 'BOT_MAX_PENDING_TXS'
|
|
23
|
+
| 'BOT_NO_START'
|
|
24
|
+
| 'BOT_NO_WAIT_FOR_TRANSFERS'
|
|
25
|
+
| 'BOT_PRIVATE_KEY'
|
|
26
|
+
| 'BOT_PRIVATE_TRANSFERS_PER_TX'
|
|
27
|
+
| 'BOT_PUBLIC_TRANSFERS_PER_TX'
|
|
28
|
+
| 'BOT_PXE_URL'
|
|
29
|
+
| 'BOT_RECIPIENT_ENCRYPTION_SECRET'
|
|
30
|
+
| 'BOT_SKIP_PUBLIC_SIMULATION'
|
|
31
|
+
| 'BOT_TOKEN_CONTRACT'
|
|
32
|
+
| 'BOT_TOKEN_SALT'
|
|
33
|
+
| 'BOT_TX_INTERVAL_SECONDS'
|
|
34
|
+
| 'BOT_TX_MINED_WAIT_SECONDS'
|
|
35
|
+
| 'COINBASE'
|
|
36
|
+
| 'DATA_DIRECTORY'
|
|
37
|
+
| 'DEBUG'
|
|
38
|
+
| 'DEPLOY_AZTEC_CONTRACTS_SALT'
|
|
39
|
+
| 'DEPLOY_AZTEC_CONTRACTS'
|
|
5
40
|
| 'ENABLE_GAS'
|
|
6
|
-
| '
|
|
41
|
+
| 'ENFORCE_FEES'
|
|
7
42
|
| 'ETHEREUM_HOST'
|
|
8
|
-
| 'L1_CHAIN_ID'
|
|
9
|
-
| 'MNEMONIC'
|
|
10
|
-
| 'ROLLUP_CONTRACT_ADDRESS'
|
|
11
|
-
| 'REGISTRY_CONTRACT_ADDRESS'
|
|
12
|
-
| 'INBOX_CONTRACT_ADDRESS'
|
|
13
|
-
| 'OUTBOX_CONTRACT_ADDRESS'
|
|
14
43
|
| 'FEE_JUICE_CONTRACT_ADDRESS'
|
|
15
44
|
| 'FEE_JUICE_PORTAL_CONTRACT_ADDRESS'
|
|
16
|
-
| '
|
|
17
|
-
| '
|
|
18
|
-
| '
|
|
45
|
+
| 'FEE_RECIPIENT'
|
|
46
|
+
| 'INBOX_CONTRACT_ADDRESS'
|
|
47
|
+
| 'L1_CHAIN_ID'
|
|
19
48
|
| 'L1_PRIVATE_KEY'
|
|
20
49
|
| 'L2_QUEUE_SIZE'
|
|
21
|
-
| '
|
|
22
|
-
| '
|
|
50
|
+
| 'LOG_JSON'
|
|
51
|
+
| 'LOG_LEVEL'
|
|
52
|
+
| 'MNEMONIC'
|
|
53
|
+
| 'NETWORK_NAME'
|
|
54
|
+
| 'NETWORK'
|
|
55
|
+
| 'OTEL_EXPORTER_OTLP_METRICS_ENDPOINT'
|
|
56
|
+
| 'OTEL_EXPORTER_OTLP_TRACES_ENDPOINT'
|
|
57
|
+
| 'OTEL_SERVICE_NAME'
|
|
58
|
+
| 'OUTBOX_CONTRACT_ADDRESS'
|
|
23
59
|
| 'P2P_BLOCK_CHECK_INTERVAL_MS'
|
|
24
|
-
| '
|
|
25
|
-
| 'P2P_L2_QUEUE_SIZE'
|
|
26
|
-
| 'TCP_LISTEN_ADDR'
|
|
27
|
-
| 'UDP_LISTEN_ADDR'
|
|
28
|
-
| 'P2P_TCP_ANNOUNCE_ADDR'
|
|
29
|
-
| 'P2P_UDP_ANNOUNCE_ADDR'
|
|
30
|
-
| 'PEER_ID_PRIVATE_KEY'
|
|
31
|
-
| 'BOOTSTRAP_NODES'
|
|
32
|
-
| 'P2P_TX_PROTOCOL'
|
|
33
|
-
| 'P2P_MIN_PEERS'
|
|
34
|
-
| 'P2P_MAX_PEERS'
|
|
35
|
-
| 'DATA_DIRECTORY'
|
|
36
|
-
| 'TX_GOSSIP_VERSION'
|
|
37
|
-
| 'P2P_QUERY_FOR_IP'
|
|
38
|
-
| 'P2P_TX_POOL_KEEP_PROVEN_FOR'
|
|
39
|
-
| 'P2P_GOSSIPSUB_INTERVAL_MS'
|
|
60
|
+
| 'P2P_ENABLED'
|
|
40
61
|
| 'P2P_GOSSIPSUB_D'
|
|
41
|
-
| 'P2P_GOSSIPSUB_DLO'
|
|
42
62
|
| 'P2P_GOSSIPSUB_DHI'
|
|
43
|
-
| '
|
|
63
|
+
| 'P2P_GOSSIPSUB_DLO'
|
|
64
|
+
| 'P2P_GOSSIPSUB_INTERVAL_MS'
|
|
44
65
|
| 'P2P_GOSSIPSUB_MCACHE_GOSSIP'
|
|
45
|
-
| '
|
|
46
|
-
| 'P2P_REQRESP_OVERALL_REQUEST_TIMEOUT_MS'
|
|
47
|
-
| 'P2P_REQRESP_INDIVIDUAL_REQUEST_TIMEOUT_MS'
|
|
48
|
-
| 'P2P_GOSSIPSUB_TX_TOPIC_WEIGHT'
|
|
49
|
-
| 'P2P_GOSSIPSUB_TX_INVALID_MESSAGE_DELIVERIES_WEIGHT'
|
|
66
|
+
| 'P2P_GOSSIPSUB_MCACHE_LENGTH'
|
|
50
67
|
| 'P2P_GOSSIPSUB_TX_INVALID_MESSAGE_DELIVERIES_DECAY'
|
|
68
|
+
| 'P2P_GOSSIPSUB_TX_INVALID_MESSAGE_DELIVERIES_WEIGHT'
|
|
69
|
+
| 'P2P_GOSSIPSUB_TX_TOPIC_WEIGHT'
|
|
70
|
+
| 'P2P_L2_QUEUE_SIZE'
|
|
71
|
+
| 'P2P_MAX_PEERS'
|
|
72
|
+
| 'P2P_MIN_PEERS'
|
|
73
|
+
| 'P2P_PEER_CHECK_INTERVAL_MS'
|
|
51
74
|
| 'P2P_PEER_PENALTY_VALUES'
|
|
52
|
-
| '
|
|
53
|
-
| '
|
|
54
|
-
| '
|
|
55
|
-
| '
|
|
56
|
-
| '
|
|
57
|
-
| '
|
|
58
|
-
| '
|
|
59
|
-
| '
|
|
60
|
-
| '
|
|
61
|
-
| '
|
|
62
|
-
| '
|
|
63
|
-
| '
|
|
64
|
-
| '
|
|
65
|
-
| '
|
|
66
|
-
| 'SEQ_MIN_SECONDS_BETWEEN_BLOCKS'
|
|
67
|
-
| 'SEQ_MAX_SECONDS_BETWEEN_BLOCKS'
|
|
68
|
-
| 'COINBASE'
|
|
69
|
-
| 'FEE_RECIPIENT'
|
|
70
|
-
| 'ACVM_WORKING_DIRECTORY'
|
|
71
|
-
| 'ACVM_BINARY_PATH'
|
|
72
|
-
| 'SEQ_ALLOWED_SETUP_FN'
|
|
73
|
-
| 'SEQ_ALLOWED_TEARDOWN_FN'
|
|
74
|
-
| 'SEQ_MAX_BLOCK_SIZE_IN_BYTES'
|
|
75
|
-
| 'ENFORCE_FEES'
|
|
76
|
-
| 'SEQ_PUBLISHER_PRIVATE_KEY'
|
|
77
|
-
| 'SEQ_REQUIRED_CONFIRMATIONS'
|
|
78
|
-
| 'SEQ_PUBLISH_RETRY_INTERVAL_MS'
|
|
79
|
-
| 'VERSION'
|
|
80
|
-
| 'SEQ_DISABLED'
|
|
81
|
-
| 'PROVER_DISABLED'
|
|
82
|
-
| 'PROVER_REAL_PROOFS'
|
|
75
|
+
| 'P2P_QUERY_FOR_IP'
|
|
76
|
+
| 'P2P_REQRESP_INDIVIDUAL_REQUEST_TIMEOUT_MS'
|
|
77
|
+
| 'P2P_REQRESP_OVERALL_REQUEST_TIMEOUT_MS'
|
|
78
|
+
| 'P2P_SEVERE_PEER_PENALTY_BLOCK_LENGTH'
|
|
79
|
+
| 'P2P_TCP_LISTEN_ADDR'
|
|
80
|
+
| 'P2P_TCP_ANNOUNCE_ADDR'
|
|
81
|
+
| 'P2P_TX_POOL_KEEP_PROVEN_FOR'
|
|
82
|
+
| 'P2P_TX_PROTOCOL'
|
|
83
|
+
| 'P2P_UDP_ANNOUNCE_ADDR'
|
|
84
|
+
| 'P2P_UDP_LISTEN_ADDR'
|
|
85
|
+
| 'PEER_ID_PRIVATE_KEY'
|
|
86
|
+
| 'PROOF_VERIFIER_L1_START_BLOCK'
|
|
87
|
+
| 'PROOF_VERIFIER_POLL_INTERVAL_MS'
|
|
88
|
+
| 'PROVER_AGENT_CONCURRENCY'
|
|
83
89
|
| 'PROVER_AGENT_ENABLED'
|
|
84
90
|
| 'PROVER_AGENT_POLL_INTERVAL_MS'
|
|
85
|
-
| '
|
|
86
|
-
| '
|
|
87
|
-
| 'PROVER_JOB_POLL_INTERVAL_MS'
|
|
91
|
+
| 'PROVER_COORDINATION_NODE_URL'
|
|
92
|
+
| 'PROVER_DISABLED'
|
|
88
93
|
| 'PROVER_ID'
|
|
89
|
-
| '
|
|
90
|
-
| '
|
|
94
|
+
| 'PROVER_JOB_POLL_INTERVAL_MS'
|
|
95
|
+
| 'PROVER_JOB_TIMEOUT_MS'
|
|
96
|
+
| 'PROVER_JOB_SOURCE_URL'
|
|
97
|
+
| 'PROVER_NODE_POLLING_INTERVAL_MS'
|
|
98
|
+
| 'PROVER_NODE_MAX_PENDING_JOBS'
|
|
91
99
|
| 'PROVER_PUBLISH_RETRY_INTERVAL_MS'
|
|
92
100
|
| 'PROVER_PUBLISHER_PRIVATE_KEY'
|
|
101
|
+
| 'PROVER_REAL_PROOFS'
|
|
93
102
|
| 'PROVER_REQUIRED_CONFIRMATIONS'
|
|
94
103
|
| 'PROVER_TEST_DELAY_MS'
|
|
95
|
-
| 'TX_PROVIDER_NODE_URL'
|
|
96
|
-
| 'TXE_PORT'
|
|
97
|
-
| 'LOG_JSON'
|
|
98
|
-
| 'BOT_PXE_URL'
|
|
99
|
-
| 'BOT_PRIVATE_KEY'
|
|
100
|
-
| 'BOT_RECIPIENT_ENCRYPTION_SECRET'
|
|
101
|
-
| 'BOT_TOKEN_SALT'
|
|
102
|
-
| 'BOT_TX_INTERVAL_SECONDS'
|
|
103
|
-
| 'BOT_PRIVATE_TRANSFERS_PER_TX'
|
|
104
|
-
| 'BOT_PUBLIC_TRANSFERS_PER_TX'
|
|
105
|
-
| 'BOT_FEE_PAYMENT_METHOD'
|
|
106
|
-
| 'BOT_NO_START'
|
|
107
|
-
| 'BOT_TX_MINED_WAIT_SECONDS'
|
|
108
|
-
| 'BOT_NO_WAIT_FOR_TRANSFERS'
|
|
109
|
-
| 'BOT_MAX_PENDING_TXS'
|
|
110
|
-
| 'BOT_SKIP_PUBLIC_SIMULATION'
|
|
111
|
-
| 'BOT_L2_GAS_LIMIT'
|
|
112
|
-
| 'BOT_DA_GAS_LIMIT'
|
|
113
104
|
| 'PXE_BLOCK_POLLING_INTERVAL_MS'
|
|
114
|
-
| 'PXE_L2_STARTING_BLOCK'
|
|
115
105
|
| 'PXE_DATA_DIRECTORY'
|
|
116
|
-
| '
|
|
117
|
-
| 'BB_WORKING_DIRECTORY'
|
|
118
|
-
| 'BB_SKIP_CLEANUP'
|
|
106
|
+
| 'PXE_L2_STARTING_BLOCK'
|
|
119
107
|
| 'PXE_PROVER_ENABLED'
|
|
120
|
-
| '
|
|
121
|
-
| '
|
|
122
|
-
| '
|
|
123
|
-
| '
|
|
124
|
-
| '
|
|
125
|
-
| '
|
|
108
|
+
| 'QUOTE_PROVIDER_BASIS_POINT_FEE'
|
|
109
|
+
| 'QUOTE_PROVIDER_BOND_AMOUNT'
|
|
110
|
+
| 'QUOTE_PROVIDER_URL'
|
|
111
|
+
| 'PROVER_TARGET_ESCROW_AMOUNT'
|
|
112
|
+
| 'PROVER_MINIMUM_ESCROW_AMOUNT'
|
|
113
|
+
| 'REGISTRY_CONTRACT_ADDRESS'
|
|
114
|
+
| 'ROLLUP_CONTRACT_ADDRESS'
|
|
115
|
+
| 'SEQ_ALLOWED_SETUP_FN'
|
|
116
|
+
| 'SEQ_ALLOWED_TEARDOWN_FN'
|
|
117
|
+
| 'SEQ_MAX_BLOCK_SIZE_IN_BYTES'
|
|
118
|
+
| 'SEQ_MAX_SECONDS_BETWEEN_BLOCKS'
|
|
119
|
+
| 'SEQ_MAX_TX_PER_BLOCK'
|
|
120
|
+
| 'SEQ_MIN_SECONDS_BETWEEN_BLOCKS'
|
|
121
|
+
| 'SEQ_MIN_TX_PER_BLOCK'
|
|
122
|
+
| 'SEQ_PUBLISH_RETRY_INTERVAL_MS'
|
|
123
|
+
| 'SEQ_PUBLISHER_PRIVATE_KEY'
|
|
124
|
+
| 'SEQ_REQUIRED_CONFIRMATIONS'
|
|
125
|
+
| 'SEQ_TX_POLLING_INTERVAL_MS'
|
|
126
|
+
| 'TELEMETRY'
|
|
127
|
+
| 'TEST_ACCOUNTS'
|
|
128
|
+
| 'TX_GOSSIP_VERSION'
|
|
129
|
+
| 'TXE_PORT'
|
|
126
130
|
| 'VALIDATOR_ATTESTATIONS_POOLING_INTERVAL_MS'
|
|
127
|
-
| '
|
|
128
|
-
| '
|
|
129
|
-
| '
|
|
130
|
-
| '
|
|
131
|
-
| '
|
|
132
|
-
| '
|
|
131
|
+
| 'VALIDATOR_ATTESTATIONS_WAIT_TIMEOUT_MS'
|
|
132
|
+
| 'VALIDATOR_DISABLED'
|
|
133
|
+
| 'VALIDATOR_PRIVATE_KEY'
|
|
134
|
+
| 'VERSION'
|
|
135
|
+
| 'WS_BLOCK_CHECK_INTERVAL_MS'
|
|
136
|
+
| 'WS_PROVEN_BLOCKS_ONLY'
|
|
137
|
+
| 'WS_BLOCK_REQUEST_BATCH_SIZE'
|
|
138
|
+
| 'VERIFIER_VIEM_POLLING_INTERVAL_MS'
|
|
139
|
+
| 'L1_READER_VIEM_POLLING_INTERVAL_MS'
|
|
140
|
+
| 'PROVER_VIEM_POLLING_INTERVAL_MS'
|
|
141
|
+
| 'SEQ_VIEM_POLLING_INTERVAL_MS';
|
package/src/config/index.ts
CHANGED
|
@@ -67,6 +67,18 @@ export function numberConfigHelper(defaultVal: number): Pick<ConfigMapping, 'par
|
|
|
67
67
|
};
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
+
/**
|
|
71
|
+
* Generates parseEnv and default values for a numerical config value.
|
|
72
|
+
* @param defaultVal - The default numerical value to use if the environment variable is not set or is invalid
|
|
73
|
+
* @returns Object with parseEnv and default values for a numerical config value
|
|
74
|
+
*/
|
|
75
|
+
export function bigintConfigHelper(defaultVal?: bigint): Pick<ConfigMapping, 'parseEnv' | 'defaultValue'> {
|
|
76
|
+
return {
|
|
77
|
+
parseEnv: (val: string) => BigInt(val),
|
|
78
|
+
defaultValue: defaultVal,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
70
82
|
/**
|
|
71
83
|
* Generates parseEnv for an optional numerical config value.
|
|
72
84
|
*/
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import { Keccak } from 'sha3';
|
|
2
2
|
|
|
3
|
+
import { Buffer32 } from '../../buffer/buffer32.js';
|
|
4
|
+
|
|
3
5
|
/**
|
|
4
6
|
* Computes the Keccak-256 hash of the given input buffer.
|
|
5
7
|
*
|
|
6
8
|
* @param input - The input buffer to be hashed.
|
|
7
9
|
* @returns The computed Keccak-256 hash as a Buffer.
|
|
8
10
|
*/
|
|
9
|
-
export function keccak256(input: Buffer) {
|
|
11
|
+
export function keccak256(input: Buffer | Buffer32) {
|
|
12
|
+
if (input instanceof Buffer32) {
|
|
13
|
+
input = input.buffer;
|
|
14
|
+
}
|
|
10
15
|
const hash = new Keccak(256);
|
|
11
16
|
return hash.update(input).digest();
|
|
12
17
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './memoize.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function memoize<This extends object, Result>(fn: () => Result, context: ClassMethodDecoratorContext) {
|
|
2
|
+
return function (this: This) {
|
|
3
|
+
const key = `__${String(context.name)}_value`;
|
|
4
|
+
const thisWithKey = this as { [key: string]: Result };
|
|
5
|
+
if (!(key in this)) {
|
|
6
|
+
const result = fn.call(this);
|
|
7
|
+
thisWithKey[key] = result;
|
|
8
|
+
}
|
|
9
|
+
return thisWithKey[key];
|
|
10
|
+
};
|
|
11
|
+
}
|
package/src/error/index.ts
CHANGED
|
@@ -3,14 +3,20 @@
|
|
|
3
3
|
* This custom error class extends the built-in Error class in JavaScript and
|
|
4
4
|
* can be used to handle cases where a process or task is terminated before completion.
|
|
5
5
|
*/
|
|
6
|
-
export class InterruptError extends Error {
|
|
6
|
+
export class InterruptError extends Error {
|
|
7
|
+
public override readonly name = 'InterruptError';
|
|
8
|
+
}
|
|
7
9
|
|
|
8
10
|
/**
|
|
9
11
|
* An error thrown when an action times out.
|
|
10
12
|
*/
|
|
11
|
-
export class TimeoutError extends Error {
|
|
13
|
+
export class TimeoutError extends Error {
|
|
14
|
+
public override readonly name = 'TimeoutError';
|
|
15
|
+
}
|
|
12
16
|
|
|
13
17
|
/**
|
|
14
18
|
* Represents an error thrown when an operation is aborted.
|
|
15
19
|
*/
|
|
16
|
-
export class AbortError extends Error {
|
|
20
|
+
export class AbortError extends Error {
|
|
21
|
+
public override readonly name = 'AbortError';
|
|
22
|
+
}
|
|
@@ -19,6 +19,9 @@ export type ViemSignature = {
|
|
|
19
19
|
* Contains a signature split into it's primary components (r,s,v)
|
|
20
20
|
*/
|
|
21
21
|
export class Signature {
|
|
22
|
+
// Cached values
|
|
23
|
+
private size: number | undefined;
|
|
24
|
+
|
|
22
25
|
constructor(
|
|
23
26
|
/** The r value of the signature */
|
|
24
27
|
public readonly r: Buffer32,
|
|
@@ -53,13 +56,17 @@ export class Signature {
|
|
|
53
56
|
|
|
54
57
|
const r = reader.readObject(Buffer32);
|
|
55
58
|
const s = reader.readObject(Buffer32);
|
|
56
|
-
const v =
|
|
59
|
+
const v = parseInt(sig.slice(2 + 64 * 2), 16);
|
|
57
60
|
|
|
58
61
|
const isEmpty = r.isZero() && s.isZero();
|
|
59
62
|
|
|
60
63
|
return new Signature(r, s, v, isEmpty);
|
|
61
64
|
}
|
|
62
65
|
|
|
66
|
+
static random(): Signature {
|
|
67
|
+
return new Signature(Buffer32.random(), Buffer32.random(), Math.floor(Math.random() * 2), false);
|
|
68
|
+
}
|
|
69
|
+
|
|
63
70
|
static empty(): Signature {
|
|
64
71
|
return new Signature(Buffer32.ZERO, Buffer32.ZERO, 0, true);
|
|
65
72
|
}
|
|
@@ -69,7 +76,19 @@ export class Signature {
|
|
|
69
76
|
}
|
|
70
77
|
|
|
71
78
|
toBuffer(): Buffer {
|
|
72
|
-
|
|
79
|
+
const buffer = serializeToBuffer([this.r, this.s, this.v]);
|
|
80
|
+
this.size = buffer.length;
|
|
81
|
+
return buffer;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
getSize(): number {
|
|
85
|
+
// We cache size to avoid recalculating it
|
|
86
|
+
if (this.size) {
|
|
87
|
+
return this.size;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
this.size = this.toBuffer().length;
|
|
91
|
+
return this.size;
|
|
73
92
|
}
|
|
74
93
|
|
|
75
94
|
to0xString(): `0x${string}` {
|
package/src/fields/fields.ts
CHANGED
|
@@ -47,7 +47,7 @@ abstract class BaseField {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
protected constructor(value: number | bigint | boolean | BaseField | Buffer) {
|
|
50
|
-
if (value
|
|
50
|
+
if (Buffer.isBuffer(value)) {
|
|
51
51
|
if (value.length > BaseField.SIZE_IN_BYTES) {
|
|
52
52
|
throw new Error(`Value length ${value.length} exceeds ${BaseField.SIZE_IN_BYTES}`);
|
|
53
53
|
}
|
package/src/fields/point.ts
CHANGED
|
@@ -258,7 +258,7 @@ export class Point {
|
|
|
258
258
|
* Check this is consistent with how bb is encoding the point at infinity
|
|
259
259
|
*/
|
|
260
260
|
public get inf() {
|
|
261
|
-
return this.
|
|
261
|
+
return this.isInfinite;
|
|
262
262
|
}
|
|
263
263
|
|
|
264
264
|
isOnGrumpkin() {
|
|
@@ -56,10 +56,11 @@ export async function defaultFetch(
|
|
|
56
56
|
throw new Error(`Failed to parse body as JSON: ${resp.text()}`);
|
|
57
57
|
}
|
|
58
58
|
if (!resp.ok) {
|
|
59
|
+
const errorMessage = `(JSON-RPC PROPAGATED) (host ${host}) (method ${rpcMethod}) (code ${resp.status}) ${responseJson.error.message}`;
|
|
59
60
|
if (noRetry || (resp.status >= 400 && resp.status < 500)) {
|
|
60
|
-
throw new NoRetryError(
|
|
61
|
+
throw new NoRetryError(errorMessage);
|
|
61
62
|
} else {
|
|
62
|
-
throw new Error(
|
|
63
|
+
throw new Error(errorMessage);
|
|
63
64
|
}
|
|
64
65
|
}
|
|
65
66
|
|
package/src/json-rpc/convert.ts
CHANGED
package/src/log/logger.ts
CHANGED
|
@@ -4,15 +4,20 @@ import { inspect } from 'util';
|
|
|
4
4
|
import { type LogData, type LogFn } from './log_fn.js';
|
|
5
5
|
|
|
6
6
|
const LogLevels = ['silent', 'error', 'warn', 'info', 'verbose', 'debug'] as const;
|
|
7
|
-
const DefaultLogLevel = process.env.NODE_ENV === 'test' ? ('silent' as const) : ('info' as const);
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* A valid log severity level.
|
|
11
10
|
*/
|
|
12
11
|
export type LogLevel = (typeof LogLevels)[number];
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
function getLogLevel() {
|
|
14
|
+
const envLogLevel = process.env.LOG_LEVEL?.toLowerCase() as LogLevel;
|
|
15
|
+
const defaultNonTestLogLevel = process.env.DEBUG === undefined ? ('info' as const) : ('debug' as const);
|
|
16
|
+
const defaultLogLevel = process.env.NODE_ENV === 'test' ? ('silent' as const) : defaultNonTestLogLevel;
|
|
17
|
+
return LogLevels.includes(envLogLevel) ? envLogLevel : defaultLogLevel;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export let currentLevel = getLogLevel();
|
|
16
21
|
|
|
17
22
|
const namespaces = process.env.DEBUG ?? 'aztec:*';
|
|
18
23
|
debug.enable(namespaces);
|
|
@@ -36,22 +41,31 @@ export type DebugLogger = Logger;
|
|
|
36
41
|
* If DEBUG="[module]" env is set, will enable debug logging if the module matches.
|
|
37
42
|
* Uses npm debug for debug level and console.error for other levels.
|
|
38
43
|
* @param name - Name of the module.
|
|
44
|
+
* @param fixedLogData - Additional data to include in the log message.
|
|
45
|
+
* @usage createDebugLogger('aztec:validator', {validatorAddress: '0x1234...'});
|
|
46
|
+
* // will always add the validator address to the log labels
|
|
39
47
|
* @returns A debug logger.
|
|
40
48
|
*/
|
|
41
|
-
|
|
49
|
+
|
|
50
|
+
export function createDebugLogger(name: string, fixedLogData?: LogData): DebugLogger {
|
|
42
51
|
const debugLogger = debug(name);
|
|
43
52
|
|
|
53
|
+
const attatchFixedLogData = (data?: LogData) => ({ ...fixedLogData, ...data });
|
|
54
|
+
|
|
44
55
|
const logger = {
|
|
45
56
|
silent: () => {},
|
|
46
|
-
error: (msg: string, err?: unknown, data?: LogData) =>
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
57
|
+
error: (msg: string, err?: unknown, data?: LogData) =>
|
|
58
|
+
logWithDebug(debugLogger, 'error', fmtErr(msg, err), attatchFixedLogData(data)),
|
|
59
|
+
warn: (msg: string, data?: LogData) => logWithDebug(debugLogger, 'warn', msg, attatchFixedLogData(data)),
|
|
60
|
+
info: (msg: string, data?: LogData) => logWithDebug(debugLogger, 'info', msg, attatchFixedLogData(data)),
|
|
61
|
+
verbose: (msg: string, data?: LogData) => logWithDebug(debugLogger, 'verbose', msg, attatchFixedLogData(data)),
|
|
62
|
+
debug: (msg: string, data?: LogData) => logWithDebug(debugLogger, 'debug', msg, attatchFixedLogData(data)),
|
|
51
63
|
};
|
|
52
|
-
return Object.assign(
|
|
64
|
+
return Object.assign(
|
|
65
|
+
(msg: string, data?: LogData) => logWithDebug(debugLogger, 'debug', msg, attatchFixedLogData(data)),
|
|
66
|
+
logger,
|
|
67
|
+
);
|
|
53
68
|
}
|
|
54
|
-
|
|
55
69
|
/** A callback to capture all logs. */
|
|
56
70
|
export type LogHandler = (level: LogLevel, namespace: string, msg: string, data?: LogData) => void;
|
|
57
71
|
|
|
@@ -101,7 +115,7 @@ function fmtErr(msg: string, err?: Error | unknown): string {
|
|
|
101
115
|
* Formats structured log data as a string for console output.
|
|
102
116
|
* @param data - Optional log data.
|
|
103
117
|
*/
|
|
104
|
-
function fmtLogData(data?: LogData): string {
|
|
118
|
+
export function fmtLogData(data?: LogData): string {
|
|
105
119
|
return Object.entries(data ?? {})
|
|
106
120
|
.map(([key, value]) => `${key}=${typeof value === 'object' && 'toString' in value ? value.toString() : value}`)
|
|
107
121
|
.join(' ');
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { InterruptibleSleep } from '../sleep/index.js';
|
|
2
|
+
import { type PromiseWithResolvers, promiseWithResolvers } from './utils.js';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* RunningPromise is a utility class that helps manage the execution of an asynchronous function
|
|
@@ -9,6 +10,7 @@ export class RunningPromise {
|
|
|
9
10
|
private running = false;
|
|
10
11
|
private runningPromise = Promise.resolve();
|
|
11
12
|
private interruptibleSleep = new InterruptibleSleep();
|
|
13
|
+
private requested: PromiseWithResolvers<void> | undefined = undefined;
|
|
12
14
|
|
|
13
15
|
constructor(private fn: () => void | Promise<void>, private pollingIntervalMS = 10000) {}
|
|
14
16
|
|
|
@@ -20,8 +22,19 @@ export class RunningPromise {
|
|
|
20
22
|
|
|
21
23
|
const poll = async () => {
|
|
22
24
|
while (this.running) {
|
|
25
|
+
const hasRequested = this.requested !== undefined;
|
|
23
26
|
await this.fn();
|
|
24
|
-
|
|
27
|
+
|
|
28
|
+
// If an immediate run had been requested *before* the function started running, resolve the request.
|
|
29
|
+
if (hasRequested) {
|
|
30
|
+
this.requested!.resolve();
|
|
31
|
+
this.requested = undefined;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// If no immediate run was requested, sleep for the polling interval.
|
|
35
|
+
if (this.requested === undefined) {
|
|
36
|
+
await this.interruptibleSleep.sleep(this.pollingIntervalMS);
|
|
37
|
+
}
|
|
25
38
|
}
|
|
26
39
|
};
|
|
27
40
|
this.runningPromise = poll();
|
|
@@ -45,6 +58,24 @@ export class RunningPromise {
|
|
|
45
58
|
return this.running;
|
|
46
59
|
}
|
|
47
60
|
|
|
61
|
+
/**
|
|
62
|
+
* Triggers an immediate run of the function, bypassing the polling interval.
|
|
63
|
+
* If the function is currently running, it will be allowed to continue and then called again immediately.
|
|
64
|
+
*/
|
|
65
|
+
public async trigger() {
|
|
66
|
+
if (!this.running) {
|
|
67
|
+
return this.fn();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
let requested = this.requested;
|
|
71
|
+
if (!requested) {
|
|
72
|
+
requested = promiseWithResolvers<void>();
|
|
73
|
+
this.requested = requested;
|
|
74
|
+
this.interruptibleSleep.interrupt();
|
|
75
|
+
}
|
|
76
|
+
await requested!.promise;
|
|
77
|
+
}
|
|
78
|
+
|
|
48
79
|
/**
|
|
49
80
|
* Updates the polling interval. The new interval will take effect after the next poll.
|
|
50
81
|
* @param pollingIntervalMS The polling interval in milliseconds.
|
|
@@ -24,6 +24,14 @@ export abstract class BaseMemoryQueue<T> {
|
|
|
24
24
|
return this.items.length;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Returns next item within the queue, or undefined if the queue is empty. Does not block.
|
|
29
|
+
* @returns The next item in the queue.
|
|
30
|
+
*/
|
|
31
|
+
public getImmediate(): T | undefined {
|
|
32
|
+
return this.items.get();
|
|
33
|
+
}
|
|
34
|
+
|
|
27
35
|
/**
|
|
28
36
|
* Returns next item within the queue, or blocks until an item has been put into the queue.
|
|
29
37
|
*
|
package/src/testing/test_data.ts
CHANGED
|
@@ -8,7 +8,7 @@ const testData: { [key: string]: unknown[] } = {};
|
|
|
8
8
|
|
|
9
9
|
/** Returns whether test data generation is enabled */
|
|
10
10
|
export function isGenerateTestDataEnabled() {
|
|
11
|
-
return process.env.AZTEC_GENERATE_TEST_DATA
|
|
11
|
+
return ['1', 'true'].includes(process.env.AZTEC_GENERATE_TEST_DATA ?? '') && typeof expect !== 'undefined';
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
/** Pushes test data with the given name, only if test data generation is enabled. */
|
package/src/types/index.ts
CHANGED
|
@@ -15,3 +15,8 @@ export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
|
15
15
|
|
|
16
16
|
/** Removes readonly modifiers for a type. */
|
|
17
17
|
export type Writeable<T> = { -readonly [P in keyof T]: T[P] };
|
|
18
|
+
|
|
19
|
+
/** Removes readonly modifiers for an object. */
|
|
20
|
+
export function unfreeze<T>(obj: T): Writeable<T> {
|
|
21
|
+
return obj as Writeable<T>;
|
|
22
|
+
}
|