@aztec/foundation 0.0.1-commit.858058eac → 0.0.1-commit.85d7d01
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/config/env_var.d.ts +2 -2
- package/dest/config/env_var.d.ts.map +1 -1
- package/dest/config/network_name.d.ts +2 -2
- package/dest/config/network_name.d.ts.map +1 -1
- package/dest/config/network_name.js +2 -0
- package/dest/crypto/poseidon/index.js +13 -13
- package/dest/curves/bn254/field.d.ts +2 -1
- package/dest/curves/bn254/field.d.ts.map +1 -1
- package/dest/curves/bn254/field.js +5 -2
- package/dest/json-rpc/client/safe_json_rpc_client.d.ts +2 -1
- package/dest/json-rpc/client/safe_json_rpc_client.d.ts.map +1 -1
- package/dest/json-rpc/client/safe_json_rpc_client.js +1 -1
- package/dest/json-rpc/server/api_key_auth.d.ts +19 -0
- package/dest/json-rpc/server/api_key_auth.d.ts.map +1 -0
- package/dest/json-rpc/server/api_key_auth.js +57 -0
- package/dest/json-rpc/server/index.d.ts +2 -1
- package/dest/json-rpc/server/index.d.ts.map +1 -1
- package/dest/json-rpc/server/index.js +1 -0
- package/dest/log/bigint-utils.d.ts +5 -0
- package/dest/log/bigint-utils.d.ts.map +1 -0
- package/dest/log/bigint-utils.js +18 -0
- package/dest/log/gcloud-logger-config.d.ts +1 -1
- package/dest/log/gcloud-logger-config.d.ts.map +1 -1
- package/dest/log/gcloud-logger-config.js +3 -0
- package/dest/log/pino-logger.d.ts +1 -1
- package/dest/log/pino-logger.d.ts.map +1 -1
- package/dest/log/pino-logger.js +4 -0
- package/dest/serialize/buffer_reader.d.ts +8 -1
- package/dest/serialize/buffer_reader.d.ts.map +1 -1
- package/dest/serialize/buffer_reader.js +13 -0
- package/dest/serialize/serialize.d.ts +19 -1
- package/dest/serialize/serialize.d.ts.map +1 -1
- package/dest/serialize/serialize.js +31 -0
- package/dest/timer/date.d.ts +3 -1
- package/dest/timer/date.d.ts.map +1 -1
- package/dest/timer/date.js +4 -0
- package/dest/transport/transport_client.js +2 -2
- package/package.json +2 -2
- package/src/config/env_var.ts +19 -2
- package/src/config/network_name.ts +4 -1
- package/src/crypto/poseidon/index.ts +13 -13
- package/src/curves/bn254/field.ts +6 -2
- package/src/json-rpc/client/safe_json_rpc_client.ts +2 -0
- package/src/json-rpc/server/api_key_auth.ts +63 -0
- package/src/json-rpc/server/index.ts +1 -0
- package/src/log/bigint-utils.ts +22 -0
- package/src/log/gcloud-logger-config.ts +5 -0
- package/src/log/pino-logger.ts +4 -0
- package/src/serialize/buffer_reader.ts +15 -0
- package/src/serialize/serialize.ts +32 -0
- package/src/timer/date.ts +6 -0
- package/src/transport/transport_client.ts +2 -2
|
@@ -115,6 +115,13 @@ export declare function toFriendlyJSON(obj: object): string;
|
|
|
115
115
|
* @returns A Buffer containing the serialized BigInt value in big-endian format.
|
|
116
116
|
*/
|
|
117
117
|
export declare function serializeBigInt(n: bigint, width?: number): Buffer<ArrayBufferLike>;
|
|
118
|
+
/**
|
|
119
|
+
* Serialize a signed BigInt value into a Buffer of specified width using two's complement.
|
|
120
|
+
* @param n - The signed BigInt value to be serialized.
|
|
121
|
+
* @param width - The width (in bytes) of the output Buffer, optional with default value 32.
|
|
122
|
+
* @returns A Buffer containing the serialized signed BigInt value in big-endian format.
|
|
123
|
+
*/
|
|
124
|
+
export declare function serializeSignedBigInt(n: bigint, width?: number): Buffer<ArrayBufferLike>;
|
|
118
125
|
/**
|
|
119
126
|
* Deserialize a big integer from a buffer, given an offset and width.
|
|
120
127
|
* Reads the specified number of bytes from the buffer starting at the offset, converts it to a big integer, and returns the deserialized result along with the number of bytes read (advanced).
|
|
@@ -128,6 +135,17 @@ export declare function deserializeBigInt(buf: Buffer, offset?: number, width?:
|
|
|
128
135
|
elem: bigint;
|
|
129
136
|
adv: number;
|
|
130
137
|
};
|
|
138
|
+
/**
|
|
139
|
+
* Deserialize a signed BigInt from a buffer (two's complement).
|
|
140
|
+
* @param buf - The buffer containing the signed big integer to be deserialized.
|
|
141
|
+
* @param offset - The position in the buffer where the integer starts. Defaults to 0.
|
|
142
|
+
* @param width - The number of bytes to read from the buffer for the integer. Defaults to 32.
|
|
143
|
+
* @returns An object containing the deserialized signed bigint value ('elem') and bytes advanced ('adv').
|
|
144
|
+
*/
|
|
145
|
+
export declare function deserializeSignedBigInt(buf: Buffer, offset?: number, width?: number): {
|
|
146
|
+
elem: bigint;
|
|
147
|
+
adv: number;
|
|
148
|
+
};
|
|
131
149
|
/**
|
|
132
150
|
* Serializes a Date object into a Buffer containing its timestamp as a big integer value.
|
|
133
151
|
* The resulting Buffer has a fixed width of 8 bytes, representing a 64-bit big-endian integer.
|
|
@@ -178,4 +196,4 @@ export declare function deserializeInt32(buf: Buffer, offset?: number): {
|
|
|
178
196
|
adv: number;
|
|
179
197
|
};
|
|
180
198
|
export {};
|
|
181
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
199
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2VyaWFsaXplLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvc2VyaWFsaXplL3NlcmlhbGl6ZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFDQSxPQUFPLEVBQUUsRUFBRSxFQUFFLE1BQU0sMEJBQTBCLENBQUM7QUFHOUM7Ozs7O0dBS0c7QUFDSCx3QkFBZ0Isa0NBQWtDLENBQUMsSUFBSSxFQUFFLFVBQVUsRUFBRSxFQUFFLFlBQVksU0FBSSxHQUFHLE1BQU0sQ0FhL0Y7QUFFRDs7R0FFRztBQUNILEtBQUssYUFBYSxDQUFDLENBQUMsSUFBSSxDQUN0QixHQUFHLEVBQUUsTUFBTSxFQUNYLE1BQU0sRUFBRSxNQUFNLEtBQ1g7SUFDSDs7T0FFRztJQUNILElBQUksRUFBRSxDQUFDLENBQUM7SUFDUjs7T0FFRztJQUNILEdBQUcsRUFBRSxNQUFNLENBQUM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C,CAAC,EAAE,MAAM,EAAE,KAAK,SAAK,2BAQ1D;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,SAAI,EAAE,KAAK,SAAK;;;EAEpE;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,SAAI,EAAE,KAAK,SAAK;;;EAO1E;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,2BAEvC;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,SAAI;;;EAGtD;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,SAAI;;;EAGxD;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,SAAI;;;EAGvD"}
|
|
@@ -176,6 +176,20 @@ import { numToUInt32BE } from './free_funcs.js';
|
|
|
176
176
|
*/ export function serializeBigInt(n, width = 32) {
|
|
177
177
|
return toBufferBE(n, width);
|
|
178
178
|
}
|
|
179
|
+
/**
|
|
180
|
+
* Serialize a signed BigInt value into a Buffer of specified width using two's complement.
|
|
181
|
+
* @param n - The signed BigInt value to be serialized.
|
|
182
|
+
* @param width - The width (in bytes) of the output Buffer, optional with default value 32.
|
|
183
|
+
* @returns A Buffer containing the serialized signed BigInt value in big-endian format.
|
|
184
|
+
*/ export function serializeSignedBigInt(n, width = 32) {
|
|
185
|
+
const widthBits = BigInt(width * 8);
|
|
186
|
+
const max = 1n << widthBits - 1n;
|
|
187
|
+
if (n < -max || n >= max) {
|
|
188
|
+
throw new Error(`Signed BigInt ${n.toString()} does not fit into ${width} bytes`);
|
|
189
|
+
}
|
|
190
|
+
const unsigned = n < 0n ? (1n << widthBits) + n : n;
|
|
191
|
+
return toBufferBE(unsigned, width);
|
|
192
|
+
}
|
|
179
193
|
/**
|
|
180
194
|
* Deserialize a big integer from a buffer, given an offset and width.
|
|
181
195
|
* Reads the specified number of bytes from the buffer starting at the offset, converts it to a big integer, and returns the deserialized result along with the number of bytes read (advanced).
|
|
@@ -190,6 +204,23 @@ import { numToUInt32BE } from './free_funcs.js';
|
|
|
190
204
|
adv: width
|
|
191
205
|
};
|
|
192
206
|
}
|
|
207
|
+
/**
|
|
208
|
+
* Deserialize a signed BigInt from a buffer (two's complement).
|
|
209
|
+
* @param buf - The buffer containing the signed big integer to be deserialized.
|
|
210
|
+
* @param offset - The position in the buffer where the integer starts. Defaults to 0.
|
|
211
|
+
* @param width - The number of bytes to read from the buffer for the integer. Defaults to 32.
|
|
212
|
+
* @returns An object containing the deserialized signed bigint value ('elem') and bytes advanced ('adv').
|
|
213
|
+
*/ export function deserializeSignedBigInt(buf, offset = 0, width = 32) {
|
|
214
|
+
const { elem, adv } = deserializeBigInt(buf, offset, width);
|
|
215
|
+
const widthBits = BigInt(width * 8);
|
|
216
|
+
const signBit = 1n << widthBits - 1n;
|
|
217
|
+
const fullRange = 1n << widthBits;
|
|
218
|
+
const signed = elem >= signBit ? elem - fullRange : elem;
|
|
219
|
+
return {
|
|
220
|
+
elem: signed,
|
|
221
|
+
adv
|
|
222
|
+
};
|
|
223
|
+
}
|
|
193
224
|
/**
|
|
194
225
|
* Serializes a Date object into a Buffer containing its timestamp as a big integer value.
|
|
195
226
|
* The resulting Buffer has a fixed width of 8 bytes, representing a 64-bit big-endian integer.
|
package/dest/timer/date.d.ts
CHANGED
|
@@ -11,6 +11,8 @@ export declare class TestDateProvider extends DateProvider {
|
|
|
11
11
|
constructor(logger?: import("../log/pino-logger.js").Logger);
|
|
12
12
|
now(): number;
|
|
13
13
|
setTime(timeMs: number): void;
|
|
14
|
+
/** Resets the time back to real time (offset = 0). */
|
|
15
|
+
reset(): void;
|
|
14
16
|
/** Advances the time by the given number of seconds. */
|
|
15
17
|
advanceTime(seconds: number): void;
|
|
16
18
|
}
|
|
@@ -34,4 +36,4 @@ export declare class ManualDateProvider extends DateProvider {
|
|
|
34
36
|
/** Advances the time by the given number of milliseconds. */
|
|
35
37
|
advanceTimeMs(ms: number): void;
|
|
36
38
|
}
|
|
37
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
39
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGF0ZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3RpbWVyL2RhdGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBRUEsZ0NBQWdDO0FBQ2hDLHFCQUFhLFlBQVk7SUFDaEIsR0FBRyxJQUFJLE1BQU0sQ0FFbkI7SUFFTSxZQUFZLElBQUksTUFBTSxDQUU1QjtJQUVNLFNBQVMsSUFBSSxJQUFJLENBRXZCO0NBQ0Y7QUFFRCwwREFBMEQ7QUFDMUQscUJBQWEsZ0JBQWlCLFNBQVEsWUFBWTtJQUdwQyxPQUFPLENBQUMsUUFBUSxDQUFDLE1BQU07SUFGbkMsT0FBTyxDQUFDLE1BQU0sQ0FBSztJQUVuQixZQUE2QixNQUFNLHlDQUFnRCxFQUVsRjtJQUVlLEdBQUcsSUFBSSxNQUFNLENBRTVCO0lBRU0sT0FBTyxDQUFDLE1BQU0sRUFBRSxNQUFNLFFBRzVCO0lBRUQsc0RBQXNEO0lBQy9DLEtBQUssU0FHWDtJQUVELHdEQUF3RDtJQUNqRCxXQUFXLENBQUMsT0FBTyxFQUFFLE1BQU0sUUFFakM7Q0FDRjtBQUVEOzs7OztHQUtHO0FBQ0gscUJBQWEsa0JBQW1CLFNBQVEsWUFBWTtJQUNsRCxPQUFPLENBQUMsYUFBYSxDQUFTO0lBRTlCOztPQUVHO0lBQ0gsWUFBWSxhQUFhLEdBQUUsTUFBc0MsRUFHaEU7SUFFZSxHQUFHLElBQUksTUFBTSxDQUU1QjtJQUVELG9FQUFvRTtJQUM3RCxPQUFPLENBQUMsTUFBTSxFQUFFLE1BQU0sUUFFNUI7SUFFRCx3REFBd0Q7SUFDakQsV0FBVyxDQUFDLE9BQU8sRUFBRSxNQUFNLFFBRWpDO0lBRUQsNkRBQTZEO0lBQ3RELGFBQWEsQ0FBQyxFQUFFLEVBQUUsTUFBTSxRQUU5QjtDQUNGIn0=
|
package/dest/timer/date.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../../src/timer/date.ts"],"names":[],"mappings":"AAEA,gCAAgC;AAChC,qBAAa,YAAY;IAChB,GAAG,IAAI,MAAM,CAEnB;IAEM,YAAY,IAAI,MAAM,CAE5B;IAEM,SAAS,IAAI,IAAI,CAEvB;CACF;AAED,0DAA0D;AAC1D,qBAAa,gBAAiB,SAAQ,YAAY;IAGpC,OAAO,CAAC,QAAQ,CAAC,MAAM;IAFnC,OAAO,CAAC,MAAM,CAAK;IAEnB,YAA6B,MAAM,yCAAgD,EAElF;IAEe,GAAG,IAAI,MAAM,CAE5B;IAEM,OAAO,CAAC,MAAM,EAAE,MAAM,QAG5B;IAED,wDAAwD;IACjD,WAAW,CAAC,OAAO,EAAE,MAAM,QAEjC;CACF;AAED;;;;;GAKG;AACH,qBAAa,kBAAmB,SAAQ,YAAY;IAClD,OAAO,CAAC,aAAa,CAAS;IAE9B;;OAEG;IACH,YAAY,aAAa,GAAE,MAAsC,EAGhE;IAEe,GAAG,IAAI,MAAM,CAE5B;IAED,oEAAoE;IAC7D,OAAO,CAAC,MAAM,EAAE,MAAM,QAE5B;IAED,wDAAwD;IACjD,WAAW,CAAC,OAAO,EAAE,MAAM,QAEjC;IAED,6DAA6D;IACtD,aAAa,CAAC,EAAE,EAAE,MAAM,QAE9B;CACF"}
|
|
1
|
+
{"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../../src/timer/date.ts"],"names":[],"mappings":"AAEA,gCAAgC;AAChC,qBAAa,YAAY;IAChB,GAAG,IAAI,MAAM,CAEnB;IAEM,YAAY,IAAI,MAAM,CAE5B;IAEM,SAAS,IAAI,IAAI,CAEvB;CACF;AAED,0DAA0D;AAC1D,qBAAa,gBAAiB,SAAQ,YAAY;IAGpC,OAAO,CAAC,QAAQ,CAAC,MAAM;IAFnC,OAAO,CAAC,MAAM,CAAK;IAEnB,YAA6B,MAAM,yCAAgD,EAElF;IAEe,GAAG,IAAI,MAAM,CAE5B;IAEM,OAAO,CAAC,MAAM,EAAE,MAAM,QAG5B;IAED,sDAAsD;IAC/C,KAAK,SAGX;IAED,wDAAwD;IACjD,WAAW,CAAC,OAAO,EAAE,MAAM,QAEjC;CACF;AAED;;;;;GAKG;AACH,qBAAa,kBAAmB,SAAQ,YAAY;IAClD,OAAO,CAAC,aAAa,CAAS;IAE9B;;OAEG;IACH,YAAY,aAAa,GAAE,MAAsC,EAGhE;IAEe,GAAG,IAAI,MAAM,CAE5B;IAED,oEAAoE;IAC7D,OAAO,CAAC,MAAM,EAAE,MAAM,QAE5B;IAED,wDAAwD;IACjD,WAAW,CAAC,OAAO,EAAE,MAAM,QAEjC;IAED,6DAA6D;IACtD,aAAa,CAAC,EAAE,EAAE,MAAM,QAE9B;CACF"}
|
package/dest/timer/date.js
CHANGED
|
@@ -26,6 +26,10 @@ import { createLogger } from '../log/pino-logger.js';
|
|
|
26
26
|
timeMs
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
|
+
/** Resets the time back to real time (offset = 0). */ reset() {
|
|
30
|
+
this.offset = 0;
|
|
31
|
+
this.logger.warn('Time reset to real time');
|
|
32
|
+
}
|
|
29
33
|
/** Advances the time by the given number of seconds. */ advanceTime(seconds) {
|
|
30
34
|
this.offset += seconds * 1000;
|
|
31
35
|
}
|
|
@@ -55,7 +55,7 @@ const log = createLogger('foundation:transport_client');
|
|
|
55
55
|
msgId,
|
|
56
56
|
payload
|
|
57
57
|
};
|
|
58
|
-
log.
|
|
58
|
+
log.trace(format(`->`, msg));
|
|
59
59
|
return new Promise((resolve, reject)=>{
|
|
60
60
|
this.pendingRequests.push({
|
|
61
61
|
resolve,
|
|
@@ -77,7 +77,7 @@ const log = createLogger('foundation:transport_client');
|
|
|
77
77
|
this.close();
|
|
78
78
|
return;
|
|
79
79
|
}
|
|
80
|
-
log.
|
|
80
|
+
log.trace(format(`<-`, msg));
|
|
81
81
|
if (isEventMessage(msg)) {
|
|
82
82
|
this.emit('event_msg', msg.payload);
|
|
83
83
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/foundation",
|
|
3
|
-
"version": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.85d7d01",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dest/index.js",
|
|
6
6
|
"types": "./dest/index.d.ts",
|
|
@@ -144,7 +144,7 @@
|
|
|
144
144
|
"testEnvironment": "../../foundation/src/jest/env.mjs"
|
|
145
145
|
},
|
|
146
146
|
"dependencies": {
|
|
147
|
-
"@aztec/bb.js": "0.0.1-commit.
|
|
147
|
+
"@aztec/bb.js": "0.0.1-commit.85d7d01",
|
|
148
148
|
"@koa/cors": "^5.0.0",
|
|
149
149
|
"@noble/curves": "=1.7.0",
|
|
150
150
|
"@noble/hashes": "^1.6.1",
|
package/src/config/env_var.ts
CHANGED
|
@@ -12,6 +12,9 @@ export type EnvVar =
|
|
|
12
12
|
| 'ARCHIVER_VIEM_POLLING_INTERVAL_MS'
|
|
13
13
|
| 'ARCHIVER_BATCH_SIZE'
|
|
14
14
|
| 'AZTEC_ADMIN_PORT'
|
|
15
|
+
| 'AZTEC_ADMIN_API_KEY_HASH'
|
|
16
|
+
| 'AZTEC_DISABLE_ADMIN_API_KEY'
|
|
17
|
+
| 'AZTEC_RESET_ADMIN_API_KEY'
|
|
15
18
|
| 'AZTEC_NODE_ADMIN_URL'
|
|
16
19
|
| 'AZTEC_NODE_URL'
|
|
17
20
|
| 'AZTEC_PORT'
|
|
@@ -47,7 +50,10 @@ export type EnvVar =
|
|
|
47
50
|
| 'BOT_TX_MINED_WAIT_SECONDS'
|
|
48
51
|
| 'BOT_MAX_CONSECUTIVE_ERRORS'
|
|
49
52
|
| 'BOT_STOP_WHEN_UNHEALTHY'
|
|
50
|
-
| '
|
|
53
|
+
| 'BOT_MODE'
|
|
54
|
+
| 'BOT_L2_TO_L1_MESSAGES_PER_TX'
|
|
55
|
+
| 'BOT_L1_TO_L2_SEED_COUNT'
|
|
56
|
+
| 'BOT_L1_TO_L2_SEED_INTERVAL'
|
|
51
57
|
| 'COINBASE'
|
|
52
58
|
| 'CRS_PATH'
|
|
53
59
|
| 'DATA_DIRECTORY'
|
|
@@ -64,6 +70,7 @@ export type EnvVar =
|
|
|
64
70
|
| 'PUBLIC_DATA_TREE_MAP_SIZE_KB'
|
|
65
71
|
| 'DEBUG'
|
|
66
72
|
| 'DEBUG_P2P_DISABLE_COLOCATION_PENALTY'
|
|
73
|
+
| 'ENABLE_PROVER_NODE'
|
|
67
74
|
| 'ETHEREUM_HOSTS'
|
|
68
75
|
| 'ETHEREUM_DEBUG_HOSTS'
|
|
69
76
|
| 'ETHEREUM_ALLOW_NO_DEBUG_HOSTS'
|
|
@@ -75,6 +82,7 @@ export type EnvVar =
|
|
|
75
82
|
| 'L1_CONSENSUS_HOST_URLS'
|
|
76
83
|
| 'L1_CONSENSUS_HOST_API_KEYS'
|
|
77
84
|
| 'L1_CONSENSUS_HOST_API_KEY_HEADERS'
|
|
85
|
+
| 'L1_TX_FAILED_STORE'
|
|
78
86
|
| 'LOG_JSON'
|
|
79
87
|
| 'LOG_MULTILINE'
|
|
80
88
|
| 'LOG_NO_COLOR_PER_ACTOR'
|
|
@@ -141,9 +149,9 @@ export type EnvVar =
|
|
|
141
149
|
| 'P2P_PREFERRED_PEERS'
|
|
142
150
|
| 'P2P_MAX_PENDING_TX_COUNT'
|
|
143
151
|
| 'P2P_SEEN_MSG_CACHE_SIZE'
|
|
144
|
-
| 'P2P_DROP_TX'
|
|
145
152
|
| 'P2P_DROP_TX_CHANCE'
|
|
146
153
|
| 'P2P_TX_POOL_DELETE_TXS_AFTER_REORG'
|
|
154
|
+
| 'P2P_MIN_TX_POOL_AGE_MS'
|
|
147
155
|
| 'DEBUG_P2P_INSTRUMENT_MESSAGES'
|
|
148
156
|
| 'PEER_ID_PRIVATE_KEY'
|
|
149
157
|
| 'PEER_ID_PRIVATE_KEY_PATH'
|
|
@@ -208,9 +216,11 @@ export type EnvVar =
|
|
|
208
216
|
| 'SEQ_L1_PUBLISHING_TIME_ALLOWANCE_IN_SLOT'
|
|
209
217
|
| 'SEQ_ATTESTATION_PROPAGATION_TIME'
|
|
210
218
|
| 'SEQ_BLOCK_DURATION_MS'
|
|
219
|
+
| 'SEQ_EXPECTED_BLOCK_PROPOSALS_PER_SLOT'
|
|
211
220
|
| 'SEQ_BUILD_CHECKPOINT_IF_EMPTY'
|
|
212
221
|
| 'SEQ_SECONDS_BEFORE_INVALIDATING_BLOCK_AS_COMMITTEE_MEMBER'
|
|
213
222
|
| 'SEQ_SECONDS_BEFORE_INVALIDATING_BLOCK_AS_NON_COMMITTEE_MEMBER'
|
|
223
|
+
| 'SEQ_SKIP_CHECKPOINT_PUBLISH_PERCENT'
|
|
214
224
|
| 'SLASH_MIN_PENALTY_PERCENTAGE'
|
|
215
225
|
| 'SLASH_MAX_PENALTY_PERCENTAGE'
|
|
216
226
|
| 'SLASH_VALIDATORS_ALWAYS'
|
|
@@ -251,6 +261,12 @@ export type EnvVar =
|
|
|
251
261
|
| 'TX_COLLECTION_FILE_STORE_URLS'
|
|
252
262
|
| 'TX_COLLECTION_FILE_STORE_SLOW_DELAY_MS'
|
|
253
263
|
| 'TX_COLLECTION_FILE_STORE_FAST_DELAY_MS'
|
|
264
|
+
| 'TX_COLLECTION_FILE_STORE_FAST_WORKER_COUNT'
|
|
265
|
+
| 'TX_COLLECTION_FILE_STORE_SLOW_WORKER_COUNT'
|
|
266
|
+
| 'TX_COLLECTION_FILE_STORE_FAST_BACKOFF_BASE_MS'
|
|
267
|
+
| 'TX_COLLECTION_FILE_STORE_SLOW_BACKOFF_BASE_MS'
|
|
268
|
+
| 'TX_COLLECTION_FILE_STORE_FAST_BACKOFF_MAX_MS'
|
|
269
|
+
| 'TX_COLLECTION_FILE_STORE_SLOW_BACKOFF_MAX_MS'
|
|
254
270
|
| 'TX_FILE_STORE_URL'
|
|
255
271
|
| 'TX_FILE_STORE_UPLOAD_CONCURRENCY'
|
|
256
272
|
| 'TX_FILE_STORE_MAX_QUEUE_SIZE'
|
|
@@ -269,6 +285,7 @@ export type EnvVar =
|
|
|
269
285
|
| 'WS_BLOCK_REQUEST_BATCH_SIZE'
|
|
270
286
|
| 'L1_READER_VIEM_POLLING_INTERVAL_MS'
|
|
271
287
|
| 'WS_DATA_DIRECTORY'
|
|
288
|
+
| 'WS_NUM_HISTORIC_CHECKPOINTS'
|
|
272
289
|
| 'WS_NUM_HISTORIC_BLOCKS'
|
|
273
290
|
| 'ETHEREUM_SLOT_DURATION'
|
|
274
291
|
| 'AZTEC_SLOT_DURATION'
|
|
@@ -5,7 +5,8 @@ export type NetworkNames =
|
|
|
5
5
|
| 'testnet'
|
|
6
6
|
| 'mainnet'
|
|
7
7
|
| 'next-net'
|
|
8
|
-
| 'devnet'
|
|
8
|
+
| 'devnet'
|
|
9
|
+
| `v${number}-devnet-${number}`;
|
|
9
10
|
|
|
10
11
|
export function getActiveNetworkName(name?: string): NetworkNames {
|
|
11
12
|
const network = name || process.env.NETWORK;
|
|
@@ -23,6 +24,8 @@ export function getActiveNetworkName(name?: string): NetworkNames {
|
|
|
23
24
|
return 'next-net';
|
|
24
25
|
} else if (network === 'devnet') {
|
|
25
26
|
return 'devnet';
|
|
27
|
+
} else if (/^v\d+-devnet-\d+$/.test(network)) {
|
|
28
|
+
return network as `v${number}-devnet-${number}`;
|
|
26
29
|
}
|
|
27
30
|
throw new Error(`Unknown network: ${network}`);
|
|
28
31
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Barretenberg } from '@aztec/bb.js';
|
|
2
2
|
|
|
3
3
|
import { Fr } from '../../curves/bn254/field.js';
|
|
4
4
|
import { type Fieldable, serializeToFields } from '../../serialize/serialize.js';
|
|
@@ -10,9 +10,9 @@ import { type Fieldable, serializeToFields } from '../../serialize/serialize.js'
|
|
|
10
10
|
*/
|
|
11
11
|
export async function poseidon2Hash(input: Fieldable[]): Promise<Fr> {
|
|
12
12
|
const inputFields = serializeToFields(input);
|
|
13
|
-
await
|
|
14
|
-
const api =
|
|
15
|
-
const response = api.poseidon2Hash({
|
|
13
|
+
await Barretenberg.initSingleton();
|
|
14
|
+
const api = Barretenberg.getSingleton();
|
|
15
|
+
const response = await api.poseidon2Hash({
|
|
16
16
|
inputs: inputFields.map(i => i.toBuffer()),
|
|
17
17
|
});
|
|
18
18
|
return Fr.fromBuffer(Buffer.from(response.hash));
|
|
@@ -27,9 +27,9 @@ export async function poseidon2Hash(input: Fieldable[]): Promise<Fr> {
|
|
|
27
27
|
export async function poseidon2HashWithSeparator(input: Fieldable[], separator: number): Promise<Fr> {
|
|
28
28
|
const inputFields = serializeToFields(input);
|
|
29
29
|
inputFields.unshift(new Fr(separator));
|
|
30
|
-
await
|
|
31
|
-
const api =
|
|
32
|
-
const response = api.poseidon2Hash({
|
|
30
|
+
await Barretenberg.initSingleton();
|
|
31
|
+
const api = Barretenberg.getSingleton();
|
|
32
|
+
const response = await api.poseidon2Hash({
|
|
33
33
|
inputs: inputFields.map(i => i.toBuffer()),
|
|
34
34
|
});
|
|
35
35
|
return Fr.fromBuffer(Buffer.from(response.hash));
|
|
@@ -44,9 +44,9 @@ export async function poseidon2Permutation(input: Fieldable[]): Promise<Fr[]> {
|
|
|
44
44
|
const inputFields = serializeToFields(input);
|
|
45
45
|
// We'd like this assertion but it's not possible to use it in the browser.
|
|
46
46
|
// assert(input.length === 4, 'Input state must be of size 4');
|
|
47
|
-
await
|
|
48
|
-
const api =
|
|
49
|
-
const response = api.poseidon2Permutation({
|
|
47
|
+
await Barretenberg.initSingleton();
|
|
48
|
+
const api = Barretenberg.getSingleton();
|
|
49
|
+
const response = await api.poseidon2Permutation({
|
|
50
50
|
inputs: inputFields.map(i => i.toBuffer()),
|
|
51
51
|
});
|
|
52
52
|
// We'd like this assertion but it's not possible to use it in the browser.
|
|
@@ -65,9 +65,9 @@ export async function poseidon2HashBytes(input: Buffer): Promise<Fr> {
|
|
|
65
65
|
inputFields.push(Fr.fromBuffer(fieldBytes));
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
await
|
|
69
|
-
const api =
|
|
70
|
-
const response = api.poseidon2Hash({
|
|
68
|
+
await Barretenberg.initSingleton();
|
|
69
|
+
const api = Barretenberg.getSingleton();
|
|
70
|
+
const response = await api.poseidon2Hash({
|
|
71
71
|
inputs: inputFields.map(i => i.toBuffer()),
|
|
72
72
|
});
|
|
73
73
|
|
|
@@ -118,14 +118,18 @@ abstract class BaseField {
|
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
cmp(rhs: BaseField): -1 | 0 | 1 {
|
|
121
|
-
|
|
122
|
-
return this.asBigInt === rhsBigInt ? 0 : this.asBigInt < rhsBigInt ? -1 : 1;
|
|
121
|
+
return BaseField.cmpAsBigInt(this.asBigInt, rhs.asBigInt);
|
|
123
122
|
}
|
|
124
123
|
|
|
125
124
|
static cmp(lhs: BaseField, rhs: BaseField): -1 | 0 | 1 {
|
|
126
125
|
return lhs.cmp(rhs);
|
|
127
126
|
}
|
|
128
127
|
|
|
128
|
+
// Actual bigint comparison. Arguments must have been validated previously.
|
|
129
|
+
static cmpAsBigInt(lhs: bigint, rhs: bigint): -1 | 0 | 1 {
|
|
130
|
+
return lhs === rhs ? 0 : lhs < rhs ? -1 : 1;
|
|
131
|
+
}
|
|
132
|
+
|
|
129
133
|
isZero(): boolean {
|
|
130
134
|
return this.asBigInt === 0n;
|
|
131
135
|
}
|
|
@@ -24,6 +24,7 @@ export type SafeJsonRpcClientOptions = {
|
|
|
24
24
|
batchWindowMS?: number;
|
|
25
25
|
maxBatchSize?: number;
|
|
26
26
|
maxRequestBodySize?: number;
|
|
27
|
+
extraHeaders?: Record<string, string>;
|
|
27
28
|
onResponse?: (res: {
|
|
28
29
|
response: any;
|
|
29
30
|
headers: { get: (header: string) => string | null | undefined };
|
|
@@ -129,6 +130,7 @@ export function createSafeJsonRpcClient<T extends object>(
|
|
|
129
130
|
const { response, headers } = await fetch(
|
|
130
131
|
host,
|
|
131
132
|
rpcCalls.map(({ request }) => request),
|
|
133
|
+
config.extraHeaders,
|
|
132
134
|
);
|
|
133
135
|
|
|
134
136
|
if (config.onResponse) {
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { timingSafeEqual } from 'crypto';
|
|
2
|
+
import type Koa from 'koa';
|
|
3
|
+
|
|
4
|
+
import { sha256 } from '../../crypto/sha256/index.js';
|
|
5
|
+
import { createLogger } from '../../log/index.js';
|
|
6
|
+
|
|
7
|
+
const log = createLogger('json-rpc:api-key-auth');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Computes the SHA-256 hash of a string and returns it as a Buffer.
|
|
11
|
+
* @param input - The input string to hash.
|
|
12
|
+
* @returns The SHA-256 hash as a Buffer.
|
|
13
|
+
*/
|
|
14
|
+
export function sha256Hash(input: string): Buffer {
|
|
15
|
+
return sha256(Buffer.from(input));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Creates a Koa middleware that enforces API key authentication on all requests
|
|
20
|
+
* except the health check endpoint (GET /status).
|
|
21
|
+
*
|
|
22
|
+
* The API key can be provided via the `x-api-key` header or the `Authorization: Bearer <key>` header.
|
|
23
|
+
* Comparison is done by hashing the provided key with SHA-256 and comparing against the stored hash.
|
|
24
|
+
*
|
|
25
|
+
* @param apiKeyHash - The SHA-256 hash of the expected API key as a Buffer.
|
|
26
|
+
* @returns A Koa middleware that rejects requests without a valid API key.
|
|
27
|
+
*/
|
|
28
|
+
export function getApiKeyAuthMiddleware(
|
|
29
|
+
apiKeyHash: Buffer,
|
|
30
|
+
): (ctx: Koa.Context, next: () => Promise<void>) => Promise<void> {
|
|
31
|
+
return async (ctx: Koa.Context, next: () => Promise<void>) => {
|
|
32
|
+
// Allow health check through without auth
|
|
33
|
+
if (ctx.path === '/status' && ctx.method === 'GET') {
|
|
34
|
+
return next();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const providedKey = ctx.get('x-api-key') || ctx.get('authorization')?.replace(/^Bearer\s+/i, '');
|
|
38
|
+
if (!providedKey) {
|
|
39
|
+
log.warn(`Rejected admin RPC request from ${ctx.ip}: missing API key`);
|
|
40
|
+
ctx.status = 401;
|
|
41
|
+
ctx.body = {
|
|
42
|
+
jsonrpc: '2.0',
|
|
43
|
+
id: null,
|
|
44
|
+
error: { code: -32000, message: 'Unauthorized: invalid or missing API key' },
|
|
45
|
+
};
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const providedHashBuf = sha256Hash(providedKey);
|
|
50
|
+
if (!timingSafeEqual(apiKeyHash, providedHashBuf)) {
|
|
51
|
+
log.warn(`Rejected admin RPC request from ${ctx.ip}: invalid API key`);
|
|
52
|
+
ctx.status = 401;
|
|
53
|
+
ctx.body = {
|
|
54
|
+
jsonrpc: '2.0',
|
|
55
|
+
id: null,
|
|
56
|
+
error: { code: -32000, message: 'Unauthorized: invalid or missing API key' },
|
|
57
|
+
};
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
await next();
|
|
62
|
+
};
|
|
63
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts bigint values to strings recursively in a log object to avoid serialization issues.
|
|
3
|
+
*/
|
|
4
|
+
export function convertBigintsToStrings(obj: unknown): unknown {
|
|
5
|
+
if (typeof obj === 'bigint') {
|
|
6
|
+
return String(obj);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
if (Array.isArray(obj)) {
|
|
10
|
+
return obj.map(item => convertBigintsToStrings(item));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (obj !== null && typeof obj === 'object') {
|
|
14
|
+
const result: Record<string, unknown> = {};
|
|
15
|
+
for (const key in obj) {
|
|
16
|
+
result[key] = convertBigintsToStrings((obj as Record<string, unknown>)[key]);
|
|
17
|
+
}
|
|
18
|
+
return result;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return obj;
|
|
22
|
+
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { pino } from 'pino';
|
|
2
2
|
|
|
3
|
+
import { convertBigintsToStrings } from './bigint-utils.js';
|
|
4
|
+
|
|
3
5
|
/* eslint-disable camelcase */
|
|
4
6
|
|
|
5
7
|
const GOOGLE_CLOUD_TRACE_ID = 'logging.googleapis.com/trace';
|
|
@@ -15,6 +17,9 @@ export const GoogleCloudLoggerConfig = {
|
|
|
15
17
|
messageKey: 'message',
|
|
16
18
|
formatters: {
|
|
17
19
|
log(object: Record<string, unknown>): Record<string, unknown> {
|
|
20
|
+
// Convert bigints to strings recursively to avoid serialization issues
|
|
21
|
+
object = convertBigintsToStrings(object) as Record<string, unknown>;
|
|
22
|
+
|
|
18
23
|
// Add trace context attributes following Cloud Logging structured log format described
|
|
19
24
|
// in https://cloud.google.com/logging/docs/structured-logging#special-payload-fields
|
|
20
25
|
const { trace_id, span_id, trace_flags, ...rest } = object;
|
package/src/log/pino-logger.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { inspect } from 'util';
|
|
|
7
7
|
import { compactArray } from '../collection/array.js';
|
|
8
8
|
import type { EnvVar } from '../config/index.js';
|
|
9
9
|
import { parseBooleanEnv } from '../config/parse-env.js';
|
|
10
|
+
import { convertBigintsToStrings } from './bigint-utils.js';
|
|
10
11
|
import { GoogleCloudLoggerConfig } from './gcloud-logger-config.js';
|
|
11
12
|
import { getLogLevelFromFilters, parseLogLevelEnvVar } from './log-filters.js';
|
|
12
13
|
import type { LogLevel } from './log-levels.js';
|
|
@@ -165,6 +166,9 @@ const pinoOpts: pino.LoggerOptions<keyof typeof customLevels> = {
|
|
|
165
166
|
...redactedPaths.map(p => `opts.${p}`),
|
|
166
167
|
],
|
|
167
168
|
},
|
|
169
|
+
formatters: {
|
|
170
|
+
log: obj => convertBigintsToStrings(obj) as Record<string, unknown>,
|
|
171
|
+
},
|
|
168
172
|
...(useGcloudLogging ? GoogleCloudLoggerConfig : {}),
|
|
169
173
|
};
|
|
170
174
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { toBigIntBE } from '../bigint-buffer/index.js';
|
|
1
2
|
import type { Tuple } from './types.js';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -130,6 +131,20 @@ export class BufferReader {
|
|
|
130
131
|
return result;
|
|
131
132
|
}
|
|
132
133
|
|
|
134
|
+
/**
|
|
135
|
+
* Reads a 256-bit signed integer (two's complement) from the buffer at the current index position.
|
|
136
|
+
* Updates the index position by 32 bytes after reading the number.
|
|
137
|
+
*
|
|
138
|
+
* @returns The read 256 bit signed value as a bigint.
|
|
139
|
+
*/
|
|
140
|
+
public readInt256(): bigint {
|
|
141
|
+
this.#rangeCheck(32);
|
|
142
|
+
const unsigned = toBigIntBE(this.buffer.subarray(this.index, this.index + 32));
|
|
143
|
+
this.index += 32;
|
|
144
|
+
const signBit = 1n << 255n;
|
|
145
|
+
return unsigned >= signBit ? unsigned - (1n << 256n) : unsigned;
|
|
146
|
+
}
|
|
147
|
+
|
|
133
148
|
/** Alias for readUInt256 */
|
|
134
149
|
public readBigInt(): bigint {
|
|
135
150
|
return this.readUInt256();
|
|
@@ -269,6 +269,22 @@ export function serializeBigInt(n: bigint, width = 32) {
|
|
|
269
269
|
return toBufferBE(n, width);
|
|
270
270
|
}
|
|
271
271
|
|
|
272
|
+
/**
|
|
273
|
+
* Serialize a signed BigInt value into a Buffer of specified width using two's complement.
|
|
274
|
+
* @param n - The signed BigInt value to be serialized.
|
|
275
|
+
* @param width - The width (in bytes) of the output Buffer, optional with default value 32.
|
|
276
|
+
* @returns A Buffer containing the serialized signed BigInt value in big-endian format.
|
|
277
|
+
*/
|
|
278
|
+
export function serializeSignedBigInt(n: bigint, width = 32) {
|
|
279
|
+
const widthBits = BigInt(width * 8);
|
|
280
|
+
const max = 1n << (widthBits - 1n);
|
|
281
|
+
if (n < -max || n >= max) {
|
|
282
|
+
throw new Error(`Signed BigInt ${n.toString()} does not fit into ${width} bytes`);
|
|
283
|
+
}
|
|
284
|
+
const unsigned = n < 0n ? (1n << widthBits) + n : n;
|
|
285
|
+
return toBufferBE(unsigned, width);
|
|
286
|
+
}
|
|
287
|
+
|
|
272
288
|
/**
|
|
273
289
|
* Deserialize a big integer from a buffer, given an offset and width.
|
|
274
290
|
* Reads the specified number of bytes from the buffer starting at the offset, converts it to a big integer, and returns the deserialized result along with the number of bytes read (advanced).
|
|
@@ -282,6 +298,22 @@ export function deserializeBigInt(buf: Buffer, offset = 0, width = 32) {
|
|
|
282
298
|
return { elem: toBigIntBE(buf.subarray(offset, offset + width)), adv: width };
|
|
283
299
|
}
|
|
284
300
|
|
|
301
|
+
/**
|
|
302
|
+
* Deserialize a signed BigInt from a buffer (two's complement).
|
|
303
|
+
* @param buf - The buffer containing the signed big integer to be deserialized.
|
|
304
|
+
* @param offset - The position in the buffer where the integer starts. Defaults to 0.
|
|
305
|
+
* @param width - The number of bytes to read from the buffer for the integer. Defaults to 32.
|
|
306
|
+
* @returns An object containing the deserialized signed bigint value ('elem') and bytes advanced ('adv').
|
|
307
|
+
*/
|
|
308
|
+
export function deserializeSignedBigInt(buf: Buffer, offset = 0, width = 32) {
|
|
309
|
+
const { elem, adv } = deserializeBigInt(buf, offset, width);
|
|
310
|
+
const widthBits = BigInt(width * 8);
|
|
311
|
+
const signBit = 1n << (widthBits - 1n);
|
|
312
|
+
const fullRange = 1n << widthBits;
|
|
313
|
+
const signed = elem >= signBit ? elem - fullRange : elem;
|
|
314
|
+
return { elem: signed, adv };
|
|
315
|
+
}
|
|
316
|
+
|
|
285
317
|
/**
|
|
286
318
|
* Serializes a Date object into a Buffer containing its timestamp as a big integer value.
|
|
287
319
|
* The resulting Buffer has a fixed width of 8 bytes, representing a 64-bit big-endian integer.
|
package/src/timer/date.ts
CHANGED
|
@@ -32,6 +32,12 @@ export class TestDateProvider extends DateProvider {
|
|
|
32
32
|
this.logger.warn(`Time set to ${new Date(timeMs).toISOString()}`, { offset: this.offset, timeMs });
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
/** Resets the time back to real time (offset = 0). */
|
|
36
|
+
public reset() {
|
|
37
|
+
this.offset = 0;
|
|
38
|
+
this.logger.warn('Time reset to real time');
|
|
39
|
+
}
|
|
40
|
+
|
|
35
41
|
/** Advances the time by the given number of seconds. */
|
|
36
42
|
public advanceTime(seconds: number) {
|
|
37
43
|
this.offset += seconds * 1000;
|
|
@@ -91,7 +91,7 @@ export class TransportClient<Payload> extends EventEmitter {
|
|
|
91
91
|
}
|
|
92
92
|
const msgId = this.msgId++;
|
|
93
93
|
const msg = { msgId, payload };
|
|
94
|
-
log.
|
|
94
|
+
log.trace(format(`->`, msg));
|
|
95
95
|
return new Promise<any>((resolve, reject) => {
|
|
96
96
|
this.pendingRequests.push({ resolve, reject, msgId });
|
|
97
97
|
this.socket!.send(msg, transfer).catch(reject);
|
|
@@ -111,7 +111,7 @@ export class TransportClient<Payload> extends EventEmitter {
|
|
|
111
111
|
this.close();
|
|
112
112
|
return;
|
|
113
113
|
}
|
|
114
|
-
log.
|
|
114
|
+
log.trace(format(`<-`, msg));
|
|
115
115
|
if (isEventMessage(msg)) {
|
|
116
116
|
this.emit('event_msg', msg.payload);
|
|
117
117
|
return;
|