@aztec/node-keystore 3.0.0-canary.a9708bd → 3.0.0-devnet.2
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/keystore_manager.d.ts +15 -3
- package/dest/keystore_manager.d.ts.map +1 -1
- package/dest/keystore_manager.js +179 -121
- package/dest/loader.js +22 -3
- package/dest/schemas.d.ts +906 -713
- package/dest/schemas.d.ts.map +1 -1
- package/dest/schemas.js +45 -25
- package/dest/signer.d.ts +8 -0
- package/dest/signer.d.ts.map +1 -1
- package/dest/signer.js +51 -0
- package/dest/types.d.ts +32 -16
- package/dest/types.d.ts.map +1 -1
- package/dest/types.js +1 -1
- package/package.json +5 -5
- package/src/keystore_manager.ts +215 -143
- package/src/loader.ts +24 -4
- package/src/schemas.ts +47 -32
- package/src/signer.ts +76 -0
- package/src/types.ts +37 -23
package/src/schemas.ts
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Zod schemas for keystore validation using Aztec's validation functions
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { optional, schemas } from '@aztec/foundation/schemas';
|
|
5
5
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
6
6
|
|
|
7
7
|
import { z } from 'zod';
|
|
8
8
|
|
|
9
|
+
import type { BLSPrivateKey, EthPrivateKey } from './types.js';
|
|
10
|
+
|
|
9
11
|
// Use Aztec's validation functions but return string types to match our TypeScript interfaces
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
+
export const ethPrivateKeySchema = z
|
|
13
|
+
.string()
|
|
14
|
+
.regex(/^0x[0-9a-fA-F]{64}$/, 'Invalid private key (must be 32 bytes with 0x prefix)')
|
|
15
|
+
.transform(s => s as EthPrivateKey);
|
|
16
|
+
export const blsPrivateKeySchema = z
|
|
12
17
|
.string()
|
|
13
|
-
.regex(/^0x[0-9a-fA-F]{64}$/, 'Invalid private key (must be 32 bytes with 0x prefix)')
|
|
14
|
-
|
|
18
|
+
.regex(/^0x[0-9a-fA-F]{64}$/, 'Invalid BLS private key (must be 32 bytes with 0x prefix)')
|
|
19
|
+
.transform(s => s as BLSPrivateKey);
|
|
15
20
|
const urlSchema = z.string().url('Invalid URL');
|
|
16
21
|
|
|
17
22
|
// Remote signer config schema
|
|
@@ -19,26 +24,26 @@ const remoteSignerConfigSchema = z.union([
|
|
|
19
24
|
urlSchema,
|
|
20
25
|
z.object({
|
|
21
26
|
remoteSignerUrl: urlSchema,
|
|
22
|
-
certPath: z.string()
|
|
23
|
-
certPass: z.string()
|
|
27
|
+
certPath: optional(z.string()),
|
|
28
|
+
certPass: optional(z.string()),
|
|
24
29
|
}),
|
|
25
30
|
]);
|
|
26
31
|
|
|
27
32
|
// Remote signer account schema
|
|
28
33
|
const remoteSignerAccountSchema = z.union([
|
|
29
|
-
|
|
34
|
+
schemas.EthAddress,
|
|
30
35
|
z.object({
|
|
31
|
-
address:
|
|
32
|
-
remoteSignerUrl: urlSchema
|
|
33
|
-
certPath: z.string()
|
|
34
|
-
certPass: z.string()
|
|
36
|
+
address: schemas.EthAddress,
|
|
37
|
+
remoteSignerUrl: urlSchema,
|
|
38
|
+
certPath: optional(z.string()),
|
|
39
|
+
certPass: optional(z.string()),
|
|
35
40
|
}),
|
|
36
41
|
]);
|
|
37
42
|
|
|
38
43
|
// JSON V3 keystore schema
|
|
39
44
|
const jsonKeyFileV3Schema = z.object({
|
|
40
45
|
path: z.string(),
|
|
41
|
-
password: z.string()
|
|
46
|
+
password: optional(z.string()),
|
|
42
47
|
});
|
|
43
48
|
|
|
44
49
|
// Mnemonic config schema
|
|
@@ -51,46 +56,56 @@ const mnemonicConfigSchema = z.object({
|
|
|
51
56
|
});
|
|
52
57
|
|
|
53
58
|
// EthAccount schema
|
|
54
|
-
const ethAccountSchema = z.union([
|
|
55
|
-
ethPrivateKeySchema,
|
|
56
|
-
remoteSignerAccountSchema,
|
|
57
|
-
jsonKeyFileV3Schema,
|
|
58
|
-
mnemonicConfigSchema,
|
|
59
|
-
]);
|
|
59
|
+
const ethAccountSchema = z.union([ethPrivateKeySchema, remoteSignerAccountSchema, jsonKeyFileV3Schema]);
|
|
60
60
|
|
|
61
61
|
// EthAccounts schema
|
|
62
|
-
const ethAccountsSchema = z.union([ethAccountSchema, z.array(ethAccountSchema)]);
|
|
62
|
+
const ethAccountsSchema = z.union([ethAccountSchema, z.array(ethAccountSchema), mnemonicConfigSchema]);
|
|
63
|
+
|
|
64
|
+
// BLSAccount schema
|
|
65
|
+
const blsAccountSchema = z.union([blsPrivateKeySchema, jsonKeyFileV3Schema]);
|
|
66
|
+
|
|
67
|
+
// AttesterAccount schema: either EthAccount or { eth: EthAccount, bls?: BLSAccount }
|
|
68
|
+
const attesterAccountSchema = z.union([
|
|
69
|
+
ethAccountSchema,
|
|
70
|
+
z.object({
|
|
71
|
+
eth: ethAccountSchema,
|
|
72
|
+
bls: optional(blsAccountSchema),
|
|
73
|
+
}),
|
|
74
|
+
]);
|
|
75
|
+
|
|
76
|
+
// AttesterAccounts schema: AttesterAccount | AttesterAccount[] | MnemonicConfig
|
|
77
|
+
const attesterAccountsSchema = z.union([attesterAccountSchema, z.array(attesterAccountSchema), mnemonicConfigSchema]);
|
|
63
78
|
|
|
64
79
|
// Prover keystore schema
|
|
65
80
|
const proverKeyStoreSchema = z.union([
|
|
66
81
|
ethAccountSchema,
|
|
67
82
|
z.object({
|
|
68
|
-
id:
|
|
83
|
+
id: schemas.EthAddress,
|
|
69
84
|
publisher: ethAccountsSchema,
|
|
70
85
|
}),
|
|
71
86
|
]);
|
|
72
87
|
|
|
73
88
|
// Validator keystore schema
|
|
74
89
|
const validatorKeyStoreSchema = z.object({
|
|
75
|
-
attester:
|
|
76
|
-
coinbase:
|
|
77
|
-
publisher: ethAccountsSchema
|
|
78
|
-
feeRecipient:
|
|
79
|
-
remoteSigner: remoteSignerConfigSchema
|
|
90
|
+
attester: attesterAccountsSchema,
|
|
91
|
+
coinbase: optional(schemas.EthAddress),
|
|
92
|
+
publisher: optional(ethAccountsSchema),
|
|
93
|
+
feeRecipient: AztecAddress.schema,
|
|
94
|
+
remoteSigner: optional(remoteSignerConfigSchema),
|
|
95
|
+
fundingAccount: optional(ethAccountSchema),
|
|
80
96
|
});
|
|
81
97
|
|
|
82
98
|
// Main keystore schema
|
|
83
99
|
export const keystoreSchema = z
|
|
84
100
|
.object({
|
|
85
101
|
schemaVersion: z.literal(1),
|
|
86
|
-
validators: z.array(validatorKeyStoreSchema)
|
|
87
|
-
slasher: ethAccountsSchema
|
|
88
|
-
remoteSigner: remoteSignerConfigSchema
|
|
89
|
-
prover: proverKeyStoreSchema
|
|
102
|
+
validators: optional(z.array(validatorKeyStoreSchema)),
|
|
103
|
+
slasher: optional(ethAccountsSchema),
|
|
104
|
+
remoteSigner: optional(remoteSignerConfigSchema),
|
|
105
|
+
prover: optional(proverKeyStoreSchema),
|
|
106
|
+
fundingAccount: optional(ethAccountSchema),
|
|
90
107
|
})
|
|
91
108
|
.refine(data => data.validators || data.prover, {
|
|
92
109
|
message: 'Keystore must have at least validators or prover configuration',
|
|
93
110
|
path: ['root'],
|
|
94
111
|
});
|
|
95
|
-
|
|
96
|
-
export type KeyStoreSchema = z.infer<typeof keystoreSchema>;
|
package/src/signer.ts
CHANGED
|
@@ -104,6 +104,82 @@ export class RemoteSigner implements EthSigner {
|
|
|
104
104
|
private fetch: typeof globalThis.fetch = globalThis.fetch,
|
|
105
105
|
) {}
|
|
106
106
|
|
|
107
|
+
/**
|
|
108
|
+
* Validates that a web3signer is accessible and that the given addresses are available.
|
|
109
|
+
* @param remoteSignerUrl - The URL of the web3signer (can be string or EthRemoteSignerConfig)
|
|
110
|
+
* @param addresses - The addresses to check for availability
|
|
111
|
+
* @param fetch - Optional fetch implementation for testing
|
|
112
|
+
* @throws Error if the web3signer is not accessible or if any address is not available
|
|
113
|
+
*/
|
|
114
|
+
static async validateAccess(
|
|
115
|
+
remoteSignerUrl: EthRemoteSignerConfig,
|
|
116
|
+
addresses: string[],
|
|
117
|
+
fetch: typeof globalThis.fetch = globalThis.fetch,
|
|
118
|
+
): Promise<void> {
|
|
119
|
+
const url = typeof remoteSignerUrl === 'string' ? remoteSignerUrl : remoteSignerUrl.remoteSignerUrl;
|
|
120
|
+
|
|
121
|
+
try {
|
|
122
|
+
// Check if the web3signer is reachable by calling eth_accounts
|
|
123
|
+
const response = await fetch(url, {
|
|
124
|
+
method: 'POST',
|
|
125
|
+
headers: {
|
|
126
|
+
'Content-Type': 'application/json',
|
|
127
|
+
},
|
|
128
|
+
body: JSON.stringify({
|
|
129
|
+
jsonrpc: '2.0',
|
|
130
|
+
method: 'eth_accounts',
|
|
131
|
+
params: [],
|
|
132
|
+
id: 1,
|
|
133
|
+
}),
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
if (!response.ok) {
|
|
137
|
+
const errorText = await response.text();
|
|
138
|
+
throw new SignerError(
|
|
139
|
+
`Web3Signer validation failed: ${response.status} ${response.statusText} - ${errorText}`,
|
|
140
|
+
'eth_accounts',
|
|
141
|
+
url,
|
|
142
|
+
response.status,
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const result = await response.json();
|
|
147
|
+
|
|
148
|
+
if (result.error) {
|
|
149
|
+
throw new SignerError(
|
|
150
|
+
`Web3Signer JSON-RPC error during validation: ${result.error.code} - ${result.error.message}`,
|
|
151
|
+
'eth_accounts',
|
|
152
|
+
url,
|
|
153
|
+
200,
|
|
154
|
+
result.error.code,
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (!result.result || !Array.isArray(result.result)) {
|
|
159
|
+
throw new Error('Invalid response from Web3Signer: expected array of accounts');
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Normalize addresses to lowercase for comparison
|
|
163
|
+
const availableAccounts: string[] = result.result.map((addr: string) => addr.toLowerCase());
|
|
164
|
+
const requestedAddresses = addresses.map(addr => addr.toLowerCase());
|
|
165
|
+
|
|
166
|
+
// Check if all requested addresses are available
|
|
167
|
+
const missingAddresses = requestedAddresses.filter(addr => !availableAccounts.includes(addr));
|
|
168
|
+
|
|
169
|
+
if (missingAddresses.length > 0) {
|
|
170
|
+
throw new Error(`The following addresses are not available in the web3signer: ${missingAddresses.join(', ')}`);
|
|
171
|
+
}
|
|
172
|
+
} catch (error: any) {
|
|
173
|
+
if (error instanceof SignerError) {
|
|
174
|
+
throw error;
|
|
175
|
+
}
|
|
176
|
+
if (error.code === 'ECONNREFUSED' || error.cause?.code === 'ECONNREFUSED') {
|
|
177
|
+
throw new Error(`Unable to connect to web3signer at ${url}. Please ensure it is running and accessible.`);
|
|
178
|
+
}
|
|
179
|
+
throw error;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
107
183
|
/**
|
|
108
184
|
* Sign a message using eth_sign via remote JSON-RPC.
|
|
109
185
|
*/
|
package/src/types.ts
CHANGED
|
@@ -5,21 +5,20 @@
|
|
|
5
5
|
* These types define the JSON structure for configuring validators, provers, and
|
|
6
6
|
* their associated keys and addresses.
|
|
7
7
|
*/
|
|
8
|
+
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
9
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
8
10
|
|
|
9
11
|
/** Parameterized hex string type for specific byte lengths */
|
|
10
12
|
export type Hex<TByteLength extends number> = `0x${string}` & { readonly _length: TByteLength };
|
|
11
13
|
|
|
12
14
|
/** A json keystore config points to a local file with the encrypted private key, and may require a password for decrypting it */
|
|
13
|
-
export type
|
|
15
|
+
export type JsonKeyFileV3Config = { path: string; password?: string };
|
|
14
16
|
|
|
15
17
|
/** A private key is a 32-byte 0x-prefixed hex */
|
|
16
18
|
export type EthPrivateKey = Hex<32>;
|
|
17
19
|
|
|
18
|
-
/**
|
|
19
|
-
export type
|
|
20
|
-
|
|
21
|
-
/** An Aztec address is a 32-byte 0x-prefixed hex */
|
|
22
|
-
export type AztecAddressHex = Hex<32>;
|
|
20
|
+
/** A BLS private key is a 32-byte 0x-prefixed hex */
|
|
21
|
+
export type BLSPrivateKey = Hex<32>;
|
|
23
22
|
|
|
24
23
|
/** URL type for remote signers */
|
|
25
24
|
export type Url = string;
|
|
@@ -40,19 +39,19 @@ export type EthRemoteSignerConfig =
|
|
|
40
39
|
* If only the address is set, then the default remote signer config from the parent config is used.
|
|
41
40
|
*/
|
|
42
41
|
export type EthRemoteSignerAccount =
|
|
43
|
-
|
|
|
42
|
+
| EthAddress
|
|
44
43
|
| {
|
|
45
|
-
address:
|
|
46
|
-
remoteSignerUrl
|
|
44
|
+
address: EthAddress;
|
|
45
|
+
remoteSignerUrl: Url;
|
|
47
46
|
certPath?: string;
|
|
48
47
|
certPass?: string;
|
|
49
48
|
};
|
|
50
49
|
|
|
51
50
|
/** An L1 account is a private key, a remote signer configuration, or a standard json key store file */
|
|
52
|
-
export type EthAccount = EthPrivateKey | EthRemoteSignerAccount |
|
|
51
|
+
export type EthAccount = EthPrivateKey | EthRemoteSignerAccount | JsonKeyFileV3Config;
|
|
53
52
|
|
|
54
53
|
/** A mnemonic can be used to define a set of accounts */
|
|
55
|
-
export type
|
|
54
|
+
export type MnemonicConfig = {
|
|
56
55
|
mnemonic: string;
|
|
57
56
|
addressIndex?: number;
|
|
58
57
|
accountIndex?: number;
|
|
@@ -61,28 +60,37 @@ export type EthMnemonicConfig = {
|
|
|
61
60
|
};
|
|
62
61
|
|
|
63
62
|
/** One or more L1 accounts */
|
|
64
|
-
export type EthAccounts = EthAccount | EthAccount[] |
|
|
63
|
+
export type EthAccounts = EthAccount | EthAccount[] | MnemonicConfig;
|
|
65
64
|
|
|
66
|
-
export type
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
65
|
+
export type ProverKeyStoreWithId = {
|
|
66
|
+
/** Address that identifies the prover. This address will receive the rewards. */
|
|
67
|
+
id: EthAddress;
|
|
68
|
+
/** One or more EOAs used for sending proof L1 txs. */
|
|
69
|
+
publisher: EthAccounts;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export type ProverKeyStore = ProverKeyStoreWithId | EthAccount;
|
|
73
|
+
|
|
74
|
+
/** A BLS account is either a private key, or a standard json key store file */
|
|
75
|
+
export type BLSAccount = BLSPrivateKey | JsonKeyFileV3Config;
|
|
76
|
+
|
|
77
|
+
/** An AttesterAccount is a combined EthAccount and optional BLSAccount */
|
|
78
|
+
export type AttesterAccount = { eth: EthAccount; bls?: BLSAccount } | EthAccount;
|
|
79
|
+
|
|
80
|
+
/** One or more attester accounts combining ETH and BLS keys */
|
|
81
|
+
export type AttesterAccounts = AttesterAccount | AttesterAccount[] | MnemonicConfig;
|
|
74
82
|
|
|
75
83
|
export type ValidatorKeyStore = {
|
|
76
84
|
/**
|
|
77
85
|
* One or more validator attester keys to handle in this configuration block.
|
|
78
86
|
* An attester address may only appear once across all configuration blocks across all keystore files.
|
|
79
87
|
*/
|
|
80
|
-
attester:
|
|
88
|
+
attester: AttesterAccounts;
|
|
81
89
|
/**
|
|
82
90
|
* Coinbase address to use when proposing an L2 block as any of the validators in this configuration block.
|
|
83
91
|
* Falls back to the attester address if not set.
|
|
84
92
|
*/
|
|
85
|
-
coinbase?:
|
|
93
|
+
coinbase?: EthAddress;
|
|
86
94
|
/**
|
|
87
95
|
* One or more EOAs used for sending block proposal L1 txs for all validators in this configuration block.
|
|
88
96
|
* Falls back to the attester account if not set.
|
|
@@ -91,11 +99,15 @@ export type ValidatorKeyStore = {
|
|
|
91
99
|
/**
|
|
92
100
|
* Fee recipient address to use when proposing an L2 block as any of the validators in this configuration block.
|
|
93
101
|
*/
|
|
94
|
-
feeRecipient:
|
|
102
|
+
feeRecipient: AztecAddress;
|
|
95
103
|
/**
|
|
96
104
|
* Default remote signer for all accounts in this block.
|
|
97
105
|
*/
|
|
98
106
|
remoteSigner?: EthRemoteSignerConfig;
|
|
107
|
+
/**
|
|
108
|
+
* Used for automatically funding publisher accounts in this block.
|
|
109
|
+
*/
|
|
110
|
+
fundingAccount?: EthAccount;
|
|
99
111
|
};
|
|
100
112
|
|
|
101
113
|
export type KeyStore = {
|
|
@@ -109,4 +121,6 @@ export type KeyStore = {
|
|
|
109
121
|
remoteSigner?: EthRemoteSignerConfig;
|
|
110
122
|
/** Prover configuration. Only one prover configuration is allowed. */
|
|
111
123
|
prover?: ProverKeyStore;
|
|
124
|
+
/** Used for automatically funding publisher accounts if there is none defined in the corresponding ValidatorKeyStore*/
|
|
125
|
+
fundingAccount?: EthAccount;
|
|
112
126
|
};
|