@aztec/foundation 0.55.1 → 0.57.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 (103) hide show
  1. package/dest/abi/abi.d.ts +13 -0
  2. package/dest/abi/abi.d.ts.map +1 -1
  3. package/dest/abi/abi.js +1 -1
  4. package/dest/abi/decoder.d.ts +6 -6
  5. package/dest/abi/decoder.d.ts.map +1 -1
  6. package/dest/abi/decoder.js +23 -24
  7. package/dest/buffer/buffer32.d.ts +9 -0
  8. package/dest/buffer/buffer32.d.ts.map +1 -1
  9. package/dest/buffer/buffer32.js +18 -1
  10. package/dest/collection/array.d.ts +4 -0
  11. package/dest/collection/array.d.ts.map +1 -1
  12. package/dest/collection/array.js +15 -1
  13. package/dest/config/env_var.d.ts +1 -1
  14. package/dest/config/env_var.d.ts.map +1 -1
  15. package/dest/config/index.d.ts +6 -0
  16. package/dest/config/index.d.ts.map +1 -1
  17. package/dest/config/index.js +12 -1
  18. package/dest/crypto/index.d.ts +1 -0
  19. package/dest/crypto/index.d.ts.map +1 -1
  20. package/dest/crypto/index.js +2 -1
  21. package/dest/crypto/keccak/index.d.ts +2 -1
  22. package/dest/crypto/keccak/index.d.ts.map +1 -1
  23. package/dest/crypto/keccak/index.js +5 -1
  24. package/dest/crypto/secp256k1-signer/index.d.ts +3 -0
  25. package/dest/crypto/secp256k1-signer/index.d.ts.map +1 -0
  26. package/dest/crypto/secp256k1-signer/index.js +3 -0
  27. package/dest/crypto/secp256k1-signer/secp256k1_signer.d.ts +24 -0
  28. package/dest/crypto/secp256k1-signer/secp256k1_signer.d.ts.map +1 -0
  29. package/dest/crypto/secp256k1-signer/secp256k1_signer.js +31 -0
  30. package/dest/crypto/secp256k1-signer/utils.d.ts +39 -0
  31. package/dest/crypto/secp256k1-signer/utils.d.ts.map +1 -0
  32. package/dest/crypto/secp256k1-signer/utils.js +89 -0
  33. package/dest/crypto/sha256/index.d.ts +15 -3
  34. package/dest/crypto/sha256/index.d.ts.map +1 -1
  35. package/dest/crypto/sha256/index.js +110 -5
  36. package/dest/decorators/index.d.ts +2 -0
  37. package/dest/decorators/index.d.ts.map +1 -0
  38. package/dest/decorators/index.js +2 -0
  39. package/dest/decorators/memoize.d.ts +2 -0
  40. package/dest/decorators/memoize.d.ts.map +1 -0
  41. package/dest/decorators/memoize.js +12 -0
  42. package/dest/eth-signature/eth_signature.d.ts +55 -0
  43. package/dest/eth-signature/eth_signature.d.ts.map +1 -0
  44. package/dest/eth-signature/eth_signature.js +72 -0
  45. package/dest/eth-signature/index.d.ts +2 -0
  46. package/dest/eth-signature/index.d.ts.map +1 -0
  47. package/dest/eth-signature/index.js +2 -0
  48. package/dest/fields/point.d.ts.map +1 -1
  49. package/dest/fields/point.js +3 -2
  50. package/dest/index.d.ts +1 -0
  51. package/dest/index.d.ts.map +1 -1
  52. package/dest/index.js +2 -1
  53. package/dest/serialize/buffer_reader.d.ts +9 -0
  54. package/dest/serialize/buffer_reader.d.ts.map +1 -1
  55. package/dest/serialize/buffer_reader.js +18 -1
  56. package/dest/serialize/serialize.js +2 -2
  57. package/dest/serialize/types.d.ts +1 -1
  58. package/dest/serialize/types.d.ts.map +1 -1
  59. package/dest/serialize/types.js +1 -1
  60. package/dest/testing/index.d.ts +1 -0
  61. package/dest/testing/index.d.ts.map +1 -1
  62. package/dest/testing/index.js +2 -1
  63. package/dest/testing/port_allocator.d.ts +10 -0
  64. package/dest/testing/port_allocator.d.ts.map +1 -0
  65. package/dest/testing/port_allocator.js +32 -0
  66. package/dest/testing/test_data.js +2 -2
  67. package/dest/trees/index.d.ts +1 -0
  68. package/dest/trees/index.d.ts.map +1 -1
  69. package/dest/trees/index.js +2 -2
  70. package/dest/trees/unbalanced_merkle_root.d.ts +12 -0
  71. package/dest/trees/unbalanced_merkle_root.d.ts.map +1 -0
  72. package/dest/trees/unbalanced_merkle_root.js +52 -0
  73. package/dest/types/index.d.ts +2 -0
  74. package/dest/types/index.d.ts.map +1 -1
  75. package/dest/types/index.js +5 -2
  76. package/package.json +9 -3
  77. package/src/abi/abi.ts +14 -0
  78. package/src/abi/decoder.ts +24 -25
  79. package/src/buffer/buffer32.ts +18 -0
  80. package/src/collection/array.ts +15 -0
  81. package/src/config/env_var.ts +116 -107
  82. package/src/config/index.ts +12 -0
  83. package/src/crypto/index.ts +1 -0
  84. package/src/crypto/keccak/index.ts +6 -1
  85. package/src/crypto/secp256k1-signer/index.ts +2 -0
  86. package/src/crypto/secp256k1-signer/secp256k1_signer.ts +38 -0
  87. package/src/crypto/secp256k1-signer/utils.ts +99 -0
  88. package/src/crypto/sha256/index.ts +137 -4
  89. package/src/decorators/index.ts +1 -0
  90. package/src/decorators/memoize.ts +11 -0
  91. package/src/eth-signature/eth_signature.ts +94 -0
  92. package/src/eth-signature/index.ts +1 -0
  93. package/src/fields/point.ts +2 -1
  94. package/src/index.ts +1 -0
  95. package/src/serialize/buffer_reader.ts +20 -0
  96. package/src/serialize/serialize.ts +1 -1
  97. package/src/serialize/types.ts +1 -1
  98. package/src/testing/index.ts +1 -0
  99. package/src/testing/port_allocator.ts +31 -0
  100. package/src/testing/test_data.ts +1 -1
  101. package/src/trees/index.ts +2 -0
  102. package/src/trees/unbalanced_merkle_root.ts +52 -0
  103. package/src/types/index.ts +5 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/foundation",
3
- "version": "0.55.1",
3
+ "version": "0.57.0",
4
4
  "packageManager": "yarn@3.4.1",
5
5
  "type": "module",
6
6
  "main": "./dest/index.js",
@@ -15,8 +15,10 @@
15
15
  "./collection": "./dest/collection/index.js",
16
16
  "./config": "./dest/config/index.js",
17
17
  "./crypto": "./dest/crypto/index.js",
18
+ "./decorators": "./dest/decorators/index.js",
18
19
  "./error": "./dest/error/index.js",
19
20
  "./eth-address": "./dest/eth-address/index.js",
21
+ "./eth-signature": "./dest/eth-signature/index.js",
20
22
  "./queue": "./dest/queue/index.js",
21
23
  "./fs": "./dest/fs/index.js",
22
24
  "./buffer": "./dest/buffer/index.js",
@@ -67,6 +69,9 @@
67
69
  "parser": {
68
70
  "syntax": "typescript",
69
71
  "decorators": true
72
+ },
73
+ "transform": {
74
+ "decoratorVersion": "2022-03"
70
75
  }
71
76
  }
72
77
  }
@@ -90,7 +95,7 @@
90
95
  ]
91
96
  },
92
97
  "dependencies": {
93
- "@aztec/bb.js": "0.55.1",
98
+ "@aztec/bb.js": "0.57.0",
94
99
  "@koa/cors": "^5.0.0",
95
100
  "@noble/curves": "^1.2.0",
96
101
  "bn.js": "^5.2.1",
@@ -144,7 +149,8 @@
144
149
  "prettier": "^2.7.1",
145
150
  "supertest": "^6.3.3",
146
151
  "ts-node": "^10.9.1",
147
- "typescript": "^5.0.4"
152
+ "typescript": "^5.0.4",
153
+ "viem": "^2.7.15"
148
154
  },
149
155
  "files": [
150
156
  "dest",
package/src/abi/abi.ts CHANGED
@@ -309,6 +309,20 @@ export type ContractNote = {
309
309
  * Type of the note (e.g., 'TransparentNote')
310
310
  */
311
311
  typ: string;
312
+ /**
313
+ * Fields of the note.
314
+ */
315
+ fields: NoteField[];
316
+ };
317
+
318
+ /** Type representing a field of a note (e.g. `amount` in `TokenNote`). */
319
+ export type NoteField = {
320
+ /** Name of the field (e.g. `amount`). */
321
+ name: string;
322
+ /** Index where the note field starts in the serialized note array. */
323
+ index: number;
324
+ /** Whether the field can be unset when creating the note (in the partial notes flow). */
325
+ nullable: boolean;
312
326
  };
313
327
 
314
328
  /**
@@ -6,21 +6,21 @@ import { isAztecAddressStruct } from './utils.js';
6
6
  /**
7
7
  * The type of our decoded ABI.
8
8
  */
9
- export type DecodedReturn = bigint | boolean | AztecAddress | DecodedReturn[] | { [key: string]: DecodedReturn };
9
+ export type AbiDecoded = bigint | boolean | AztecAddress | AbiDecoded[] | { [key: string]: AbiDecoded };
10
10
 
11
11
  /**
12
- * Decodes return values from a function call.
13
- * Missing support for integer and string.
12
+ * Decodes values using a provided ABI.
13
+ * Missing support for signed integer.
14
14
  */
15
- class ReturnValuesDecoder {
16
- constructor(private returnTypes: AbiType[], private flattened: Fr[]) {}
15
+ class AbiDecoder {
16
+ constructor(private types: AbiType[], private flattened: Fr[]) {}
17
17
 
18
18
  /**
19
19
  * Decodes a single return value from field to the given type.
20
20
  * @param abiType - The type of the return value.
21
21
  * @returns The decoded return value.
22
22
  */
23
- private decodeReturn(abiType: AbiType): DecodedReturn {
23
+ private decodeNext(abiType: AbiType): AbiDecoded {
24
24
  switch (abiType.kind) {
25
25
  case 'field':
26
26
  return this.getNextField().toBigInt();
@@ -34,18 +34,18 @@ class ReturnValuesDecoder {
34
34
  case 'array': {
35
35
  const array = [];
36
36
  for (let i = 0; i < abiType.length; i += 1) {
37
- array.push(this.decodeReturn(abiType.type));
37
+ array.push(this.decodeNext(abiType.type));
38
38
  }
39
39
  return array;
40
40
  }
41
41
  case 'struct': {
42
- const struct: { [key: string]: DecodedReturn } = {};
42
+ const struct: { [key: string]: AbiDecoded } = {};
43
43
  if (isAztecAddressStruct(abiType)) {
44
44
  return new AztecAddress(this.getNextField().toBuffer());
45
45
  }
46
46
 
47
47
  for (const field of abiType.fields) {
48
- struct[field.name] = this.decodeReturn(field.type);
48
+ struct[field.name] = this.decodeNext(field.type);
49
49
  }
50
50
  return struct;
51
51
  }
@@ -59,7 +59,7 @@ class ReturnValuesDecoder {
59
59
  case 'tuple': {
60
60
  const array = [];
61
61
  for (const tupleAbiType of abiType.fields) {
62
- array.push(this.decodeReturn(tupleAbiType));
62
+ array.push(this.decodeNext(tupleAbiType));
63
63
  }
64
64
  return array;
65
65
  }
@@ -69,8 +69,8 @@ class ReturnValuesDecoder {
69
69
  }
70
70
 
71
71
  /**
72
- * Gets the next field in the flattened return values.
73
- * @returns The next field in the flattened return values.
72
+ * Gets the next field in the flattened buffer.
73
+ * @returns The next field in the flattened buffer.
74
74
  */
75
75
  private getNextField(): Fr {
76
76
  const field = this.flattened.shift();
@@ -81,30 +81,29 @@ class ReturnValuesDecoder {
81
81
  }
82
82
 
83
83
  /**
84
- * Decodes all the return values for the given function ABI.
85
- * Aztec.nr support only single return value
86
- * The return value can however be simple types, structs or arrays
84
+ * Decodes all the values for the given ABI.
85
+ * The decided value can be simple types, structs or arrays
87
86
  * @returns The decoded return values.
88
87
  */
89
- public decode(): DecodedReturn {
90
- if (this.returnTypes.length > 1) {
91
- throw new Error('Multiple return values not supported');
88
+ public decode(): AbiDecoded {
89
+ if (this.types.length > 1) {
90
+ throw new Error('Multiple types not supported');
92
91
  }
93
- if (this.returnTypes.length === 0) {
92
+ if (this.types.length === 0) {
94
93
  return [];
95
94
  }
96
- return this.decodeReturn(this.returnTypes[0]);
95
+ return this.decodeNext(this.types[0]);
97
96
  }
98
97
  }
99
98
 
100
99
  /**
101
- * Decodes return values from a function call.
102
- * @param abi - The ABI entry of the function.
103
- * @param returnValues - The decoded return values.
100
+ * Decodes values in a flattened Field array using a provided ABI.
101
+ * @param abi - The ABI to use as reference.
102
+ * @param buffer - The flattened Field array to decode.
104
103
  * @returns
105
104
  */
106
- export function decodeReturnValues(returnTypes: AbiType[], returnValues: Fr[]) {
107
- return new ReturnValuesDecoder(returnTypes, returnValues.slice()).decode();
105
+ export function decodeFromAbi(typ: AbiType[], buffer: Fr[]) {
106
+ return new AbiDecoder(typ, buffer.slice()).decode();
108
107
  }
109
108
 
110
109
  /**
@@ -112,7 +112,25 @@ export class Buffer32 {
112
112
  * @param str - The TX hash in string format.
113
113
  * @returns A new Buffer32 object.
114
114
  */
115
+ public static fromStringUnchecked(str: string): Buffer32 {
116
+ return new Buffer32(Buffer.from(str, 'hex'));
117
+ }
118
+
119
+ /**
120
+ * Converts a string into a Buffer32 object.
121
+ * NOTE: this method includes checks for the 0x prefix and the length of the string.
122
+ * if you dont need this checks, use fromStringUnchecked instead.
123
+ *
124
+ * @param str - The TX hash in string format.
125
+ * @returns A new Buffer32 object.
126
+ */
115
127
  public static fromString(str: string): Buffer32 {
128
+ if (str.startsWith('0x')) {
129
+ str = str.slice(2);
130
+ }
131
+ if (str.length !== 64) {
132
+ throw new Error(`Expected string to be 64 characters long, but was ${str.length}`);
133
+ }
116
134
  return new Buffer32(Buffer.from(str, 'hex'));
117
135
  }
118
136
 
@@ -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
+ }
@@ -1,132 +1,141 @@
1
1
  export type EnvVar =
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'
10
+ | 'ASSUME_PROVEN_THROUGH_BLOCK_NUMBER'
11
+ | 'AZTEC_NODE_URL'
2
12
  | 'AZTEC_PORT'
3
- | 'ASSUME_PROVEN_UNTIL_BLOCK_NUMBER'
4
- | 'TEST_ACCOUNTS'
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
- | 'API_PREFIX'
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
- | 'ARCHIVER_URL'
17
- | 'DEPLOY_AZTEC_CONTRACTS'
18
- | 'DEPLOY_AZTEC_CONTRACTS_SALT'
45
+ | 'FEE_RECIPIENT'
46
+ | 'INBOX_CONTRACT_ADDRESS'
47
+ | 'L1_CHAIN_ID'
19
48
  | 'L1_PRIVATE_KEY'
20
49
  | 'L2_QUEUE_SIZE'
21
- | 'WS_BLOCK_CHECK_INTERVAL_MS'
22
- | 'P2P_ENABLED'
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
- | 'P2P_PEER_CHECK_INTERVAL_MS'
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
- | 'P2P_GOSSIPSUB_MCACHE_LENGTH'
63
+ | 'P2P_GOSSIPSUB_DLO'
64
+ | 'P2P_GOSSIPSUB_INTERVAL_MS'
44
65
  | 'P2P_GOSSIPSUB_MCACHE_GOSSIP'
45
- | 'P2P_SEVERE_PEER_PENALTY_BLOCK_LENGTH'
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
- | 'TELEMETRY'
53
- | 'OTEL_SERVICE_NAME'
54
- | 'OTEL_EXPORTER_OTLP_METRICS_ENDPOINT'
55
- | 'OTEL_EXPORTER_OTLP_TRACES_ENDPOINT'
56
- | 'NETWORK_NAME'
57
- | 'NETWORK'
58
- | 'API_KEY'
59
- | 'AZTEC_NODE_URL'
60
- | 'ARCHIVER_POLLING_INTERVAL_MS'
61
- | 'ARCHIVER_VIEM_POLLING_INTERVAL_MS'
62
- | 'ARCHIVER_MAX_LOGS'
63
- | 'SEQ_TX_POLLING_INTERVAL_MS'
64
- | 'SEQ_MAX_TX_PER_BLOCK'
65
- | 'SEQ_MIN_TX_PER_BLOCK'
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_ANNOUNCE_ADDR'
80
+ | 'P2P_TX_POOL_KEEP_PROVEN_FOR'
81
+ | 'P2P_TX_PROTOCOL'
82
+ | 'P2P_UDP_ANNOUNCE_ADDR'
83
+ | 'PEER_ID_PRIVATE_KEY'
84
+ | 'PROOF_VERIFIER_L1_START_BLOCK'
85
+ | 'PROOF_VERIFIER_POLL_INTERVAL_MS'
86
+ | 'PROVER_AGENT_CONCURRENCY'
83
87
  | 'PROVER_AGENT_ENABLED'
84
88
  | 'PROVER_AGENT_POLL_INTERVAL_MS'
85
- | 'PROVER_AGENT_CONCURRENCY'
86
- | 'PROVER_JOB_TIMEOUT_MS'
87
- | 'PROVER_JOB_POLL_INTERVAL_MS'
89
+ | 'PROVER_COORDINATION_NODE_URL'
90
+ | 'PROVER_DISABLED'
88
91
  | 'PROVER_ID'
89
- | 'WS_L2_BLOCK_QUEUE_SIZE'
90
- | 'WS_PROVEN_BLOCKS_ONLY'
92
+ | 'PROVER_JOB_POLL_INTERVAL_MS'
93
+ | 'PROVER_JOB_TIMEOUT_MS'
94
+ | 'PROVER_NODE_POLLING_INTERVAL_MS'
95
+ | 'PROVER_NODE_MAX_PENDING_JOBS'
91
96
  | 'PROVER_PUBLISH_RETRY_INTERVAL_MS'
92
97
  | 'PROVER_PUBLISHER_PRIVATE_KEY'
98
+ | 'PROVER_REAL_PROOFS'
93
99
  | 'PROVER_REQUIRED_CONFIRMATIONS'
94
100
  | '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
101
  | 'PXE_BLOCK_POLLING_INTERVAL_MS'
114
- | 'PXE_L2_STARTING_BLOCK'
115
102
  | 'PXE_DATA_DIRECTORY'
116
- | 'BB_BINARY_PATH'
117
- | 'BB_WORKING_DIRECTORY'
118
- | 'BB_SKIP_CLEANUP'
103
+ | 'PXE_L2_STARTING_BLOCK'
119
104
  | 'PXE_PROVER_ENABLED'
120
- | 'BOT_FOLLOW_CHAIN'
121
- | 'BOT_FLUSH_SETUP_TRANSACTIONS'
122
- | 'BOT_TOKEN_CONTRACT'
123
- | 'VALIDATOR_PRIVATE_KEY'
124
- | 'VALIDATOR_DISABLED'
125
- | 'VALIDATOR_ATTESTATIONS_WAIT_TIMEOUT_MS'
105
+ | 'QUOTE_PROVIDER_BASIS_POINT_FEE'
106
+ | 'QUOTE_PROVIDER_BOND_AMOUNT'
107
+ | 'QUOTE_PROVIDER_URL'
108
+ | 'PROVER_TARGET_STAKE_AMOUNT'
109
+ | 'PROVER_MINIMUM_STAKE_AMOUNT'
110
+ | 'REGISTRY_CONTRACT_ADDRESS'
111
+ | 'ROLLUP_CONTRACT_ADDRESS'
112
+ | 'SEQ_ALLOWED_SETUP_FN'
113
+ | 'SEQ_ALLOWED_TEARDOWN_FN'
114
+ | 'SEQ_DISABLED'
115
+ | 'SEQ_MAX_BLOCK_SIZE_IN_BYTES'
116
+ | 'SEQ_MAX_SECONDS_BETWEEN_BLOCKS'
117
+ | 'SEQ_MAX_TX_PER_BLOCK'
118
+ | 'SEQ_MIN_SECONDS_BETWEEN_BLOCKS'
119
+ | 'SEQ_MIN_TX_PER_BLOCK'
120
+ | 'SEQ_PUBLISH_RETRY_INTERVAL_MS'
121
+ | 'SEQ_PUBLISHER_PRIVATE_KEY'
122
+ | 'SEQ_REQUIRED_CONFIRMATIONS'
123
+ | 'SEQ_TX_POLLING_INTERVAL_MS'
124
+ | 'TCP_LISTEN_ADDR'
125
+ | 'TELEMETRY'
126
+ | 'TEST_ACCOUNTS'
127
+ | 'TX_GOSSIP_VERSION'
128
+ | 'TXE_PORT'
129
+ | 'UDP_LISTEN_ADDR'
126
130
  | 'VALIDATOR_ATTESTATIONS_POOLING_INTERVAL_MS'
127
- | 'PROVER_NODE_DISABLE_AUTOMATIC_PROVING'
128
- | 'PROVER_NODE_MAX_PENDING_JOBS'
129
- | 'PROOF_VERIFIER_POLL_INTERVAL_MS'
130
- | 'PROOF_VERIFIER_L1_START_BLOCK'
131
- | 'LOG_LEVEL'
132
- | 'DEBUG';
131
+ | 'VALIDATOR_ATTESTATIONS_WAIT_TIMEOUT_MS'
132
+ | 'VALIDATOR_DISABLED'
133
+ | 'VALIDATOR_PRIVATE_KEY'
134
+ | 'VERSION'
135
+ | 'WS_BLOCK_CHECK_INTERVAL_MS'
136
+ | 'WS_L2_BLOCK_QUEUE_SIZE'
137
+ | 'WS_PROVEN_BLOCKS_ONLY'
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';
@@ -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
  */
@@ -6,6 +6,7 @@ export * from './sha256/index.js';
6
6
  export * from './sha512/index.js';
7
7
  export * from './pedersen/index.js';
8
8
  export * from './poseidon/index.js';
9
+ export * from './secp256k1-signer/index.js';
9
10
 
10
11
  /**
11
12
  * Init the bb singleton. This constructs (if not already) the barretenberg sync api within bb.js itself.
@@ -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,2 @@
1
+ export * from './secp256k1_signer.js';
2
+ export * from './utils.js';
@@ -0,0 +1,38 @@
1
+ import { Buffer32 } from '@aztec/foundation/buffer';
2
+ import { type EthAddress } from '@aztec/foundation/eth-address';
3
+ import { type Signature } from '@aztec/foundation/eth-signature';
4
+
5
+ import { addressFromPrivateKey, makeEthSignDigest, signMessage } from './utils.js';
6
+
7
+ /**
8
+ * Secp256k1Signer
9
+ *
10
+ * A class for signing messages using a secp256k1 private key.
11
+ * - This is a slim drop in replacement for an Ethereum signer, so it can be used in the same way.
12
+ * - See `utils.ts` for functions that enable recovering addresses and public keys from signatures.
13
+ */
14
+ export class Secp256k1Signer {
15
+ public readonly address: EthAddress;
16
+
17
+ constructor(private privateKey: Buffer32) {
18
+ this.address = addressFromPrivateKey(privateKey.buffer);
19
+ }
20
+
21
+ sign(message: Buffer32): Signature {
22
+ return signMessage(message, this.privateKey.buffer);
23
+ }
24
+
25
+ /**
26
+ * Sign a message using the same method as eth_sign
27
+ * @param message - The message to sign.
28
+ * @returns The signature.
29
+ */
30
+ signMessage(message: Buffer32): Signature {
31
+ const digest = makeEthSignDigest(message);
32
+ return this.sign(digest);
33
+ }
34
+
35
+ static random(): Secp256k1Signer {
36
+ return new Secp256k1Signer(Buffer32.random());
37
+ }
38
+ }
@@ -0,0 +1,99 @@
1
+ import { secp256k1 } from '@noble/curves/secp256k1';
2
+
3
+ import { Buffer32 } from '../../buffer/buffer32.js';
4
+ import { EthAddress } from '../../eth-address/index.js';
5
+ import { Signature } from '../../eth-signature/eth_signature.js';
6
+ import { keccak256 } from '../keccak/index.js';
7
+
8
+ const ETH_SIGN_PREFIX = '\x19Ethereum Signed Message:\n32';
9
+
10
+ // We just hash the message to make it easier to work with in the smart contract.
11
+ export function makeEthSignDigest(message: Buffer32): Buffer32 {
12
+ const prefix = Buffer.from(ETH_SIGN_PREFIX);
13
+ return Buffer32.fromBuffer(keccak256(Buffer.concat([prefix, message.buffer])));
14
+ }
15
+
16
+ /**
17
+ * Converts a public key to an address.
18
+ * @param publicKey - The public key to convert.
19
+ * @returns The address.
20
+ */
21
+ function publicKeyToAddress(publicKey: Buffer): EthAddress {
22
+ const hash = keccak256(publicKey.subarray(1));
23
+ return new EthAddress(hash.subarray(12));
24
+ }
25
+
26
+ /**
27
+ * Converts a private key to a public key.
28
+ * @param privateKey - The private key to convert.
29
+ * @returns The public key.
30
+ */
31
+ export function publicKeyFromPrivateKey(privateKey: Buffer): Buffer {
32
+ return Buffer.from(secp256k1.getPublicKey(privateKey, false));
33
+ }
34
+
35
+ /**
36
+ * Converts a private key to an address.
37
+ * @param privateKey - The private key to convert.
38
+ * @returns The address.
39
+ */
40
+ export function addressFromPrivateKey(privateKey: Buffer): EthAddress {
41
+ const publicKey = publicKeyFromPrivateKey(privateKey);
42
+ return publicKeyToAddress(publicKey);
43
+ }
44
+
45
+ /**
46
+ * Recovers an address from a hash and a signature.
47
+ * @param hash - The hash to recover the address from.
48
+ * @param signature - The signature to recover the address from.
49
+ * @returns The address.
50
+ */
51
+ export function recoverAddress(hash: Buffer32, signature: Signature): EthAddress {
52
+ const publicKey = recoverPublicKey(hash, signature);
53
+ return publicKeyToAddress(publicKey);
54
+ }
55
+
56
+ /**
57
+ * @attribution - viem
58
+ * Converts a yParityOrV value to a recovery bit.
59
+ * @param yParityOrV - The yParityOrV value to convert.
60
+ * @returns The recovery bit.
61
+ */
62
+ function toRecoveryBit(yParityOrV: number) {
63
+ if (yParityOrV === 0 || yParityOrV === 1) {
64
+ return yParityOrV;
65
+ }
66
+ if (yParityOrV === 27) {
67
+ return 0;
68
+ }
69
+ if (yParityOrV === 28) {
70
+ return 1;
71
+ }
72
+ throw new Error('Invalid yParityOrV value');
73
+ }
74
+
75
+ /**
76
+ * Signs a message using ecdsa over the secp256k1 curve.
77
+ * @param message - The message to sign.
78
+ * @param privateKey - The private key to sign the message with.
79
+ * @returns The signature.
80
+ */
81
+ export function signMessage(message: Buffer32, privateKey: Buffer) {
82
+ const { r, s, recovery } = secp256k1.sign(message.buffer, privateKey);
83
+ return new Signature(Buffer32.fromBigInt(r), Buffer32.fromBigInt(s), recovery ? 28 : 27);
84
+ }
85
+
86
+ /**
87
+ * Recovers a public key from a hash and a signature.
88
+ * @param hash - The hash to recover the public key from.
89
+ * @param signature - The signature to recover the public key from.
90
+ * @returns The public key.
91
+ */
92
+ export function recoverPublicKey(hash: Buffer32, signature: Signature): Buffer {
93
+ const { r, s, v } = signature;
94
+ const recoveryBit = toRecoveryBit(v);
95
+ const sig = new secp256k1.Signature(r.toBigInt(), s.toBigInt()).addRecoveryBit(recoveryBit);
96
+
97
+ const publicKey = sig.recoverPublicKey(hash.buffer).toHex(false);
98
+ return Buffer.from(publicKey, 'hex');
99
+ }