@aztec/node-keystore 2.0.0-rc.23 → 2.0.0-rc.25
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 +2 -1
- package/dest/keystore_manager.d.ts.map +1 -1
- package/dest/keystore_manager.js +60 -82
- package/dest/schemas.d.ts +563 -903
- package/dest/schemas.d.ts.map +1 -1
- package/dest/schemas.js +24 -26
- package/dest/types.d.ts +10 -11
- package/dest/types.d.ts.map +1 -1
- package/dest/types.js +1 -1
- package/package.json +4 -4
- package/src/keystore_manager.ts +73 -94
- package/src/loader.ts +1 -1
- package/src/schemas.ts +27 -33
- package/src/types.ts +14 -18
|
@@ -7,6 +7,7 @@ import type { EthSigner } from '@aztec/ethereum';
|
|
|
7
7
|
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
8
8
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
9
9
|
import type { Signature } from '@aztec/foundation/eth-signature';
|
|
10
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
10
11
|
import type { TypedDataDefinition } from 'viem';
|
|
11
12
|
import type { EthAccounts, EthRemoteSignerConfig, KeyStore, ProverKeyStore, ValidatorKeyStore as ValidatorKeystoreConfig } from './types.js';
|
|
12
13
|
/**
|
|
@@ -74,7 +75,7 @@ export declare class KeystoreManager {
|
|
|
74
75
|
/**
|
|
75
76
|
* Get fee recipient for validator
|
|
76
77
|
*/
|
|
77
|
-
getFeeRecipient(validatorIndex: number):
|
|
78
|
+
getFeeRecipient(validatorIndex: number): AztecAddress;
|
|
78
79
|
/**
|
|
79
80
|
* Get the raw slasher configuration as provided in the keystore file.
|
|
80
81
|
* @returns The slasher accounts configuration or undefined if not set
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keystore_manager.d.ts","sourceRoot":"","sources":["../src/keystore_manager.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,SAAS,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Ac3D,kCAAkC,IAAI,SAAS,EAAE;IAWjD;;OAEG;IACH,oBAAoB,IAAI,SAAS,EAAE;IAQnC;;OAEG;IACH,mBAAmB,IAAI;QAAE,EAAE,EAAE,UAAU,GAAG,SAAS,CAAC;QAAC,OAAO,EAAE,SAAS,EAAE,CAAA;KAAE,GAAG,SAAS;IAkCvF;;OAEG;IACH,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,uBAAuB;IAOpD;;OAEG;IACH,iBAAiB,IAAI,MAAM;IAI3B;;OAEG;IACH,kBAAkB,CAAC,cAAc,EAAE,MAAM,GAAG,UAAU;IAgBtD;;OAEG;IACH,eAAe,CAAC,cAAc,EAAE,MAAM,GAAG,YAAY;IAKrD;;;OAGG;IACH,kBAAkB,IAAI,WAAW,GAAG,SAAS;IAI7C;;;OAGG;IACH,eAAe,IAAI,cAAc,GAAG,SAAS;IAI7C;;;OAGG;IACH,uCAAuC,IAAI,IAAI;IAqB/C;;OAEG;IACH,OAAO,CAAC,4BAA4B;IA+BpC;;OAEG;IACH,OAAO,CAAC,0BAA0B;IA2ClC;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAkD9B;;OAEG;IACH,OAAO,CAAC,gCAAgC;IAwBxC;;OAEG;IACH,OAAO,CAAC,yBAAyB;IA8BjC;;OAEG;IACG,WAAW,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,SAAS,CAAC;IAI3E;;OAEG;IACG,aAAa,CAAC,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,mBAAmB,GAAG,OAAO,CAAC,SAAS,CAAC;IAI1F;;;OAGG;IACH,8BAA8B,CAC5B,cAAc,EAAE,MAAM,EACtB,eAAe,EAAE,UAAU,GAC1B,qBAAqB,GAAG,SAAS;CAkHrC"}
|
package/dest/keystore_manager.js
CHANGED
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Manages keystore configuration and delegates signing operations to appropriate signers.
|
|
5
5
|
*/ import { Buffer32 } from '@aztec/foundation/buffer';
|
|
6
|
-
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
7
6
|
import { Wallet } from '@ethersproject/wallet';
|
|
8
7
|
import { readFileSync, readdirSync, statSync } from 'fs';
|
|
9
8
|
import { extname, join } from 'path';
|
|
10
9
|
import { mnemonicToAccount } from 'viem/accounts';
|
|
10
|
+
import { ethPrivateKeySchema } from './schemas.js';
|
|
11
11
|
import { LocalSigner, RemoteSigner } from './signer.js';
|
|
12
12
|
/**
|
|
13
13
|
* Error thrown when keystore operations fail
|
|
@@ -61,22 +61,13 @@ import { LocalSigner, RemoteSigner } from './signer.js';
|
|
|
61
61
|
if (account.startsWith('0x') && account.length === 66) {
|
|
62
62
|
// Private key -> derive address locally without external deps
|
|
63
63
|
try {
|
|
64
|
-
const signer = new LocalSigner(Buffer32.fromString(account));
|
|
64
|
+
const signer = new LocalSigner(Buffer32.fromString(ethPrivateKeySchema.parse(account)));
|
|
65
65
|
results.push(signer.address);
|
|
66
66
|
} catch {
|
|
67
67
|
// Ignore invalid private key at construction time
|
|
68
68
|
}
|
|
69
69
|
return;
|
|
70
70
|
}
|
|
71
|
-
if (account.startsWith('0x') && account.length === 42) {
|
|
72
|
-
// Address string
|
|
73
|
-
try {
|
|
74
|
-
results.push(EthAddress.fromString(account));
|
|
75
|
-
} catch {
|
|
76
|
-
// Ignore invalid address format at construction time
|
|
77
|
-
}
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
71
|
// Any other string cannot be confidently resolved here
|
|
81
72
|
return;
|
|
82
73
|
}
|
|
@@ -88,16 +79,13 @@ import { LocalSigner, RemoteSigner } from './signer.js';
|
|
|
88
79
|
if ('mnemonic' in account) {
|
|
89
80
|
return;
|
|
90
81
|
}
|
|
91
|
-
// Remote signer account
|
|
82
|
+
// Remote signer account. If it contains 'address' then extract, otherwise it IS the address
|
|
92
83
|
const remoteSigner = account;
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
results.push(EthAddress.fromString(address));
|
|
97
|
-
} catch {
|
|
98
|
-
// Ignore invalid address format at construction time
|
|
99
|
-
}
|
|
84
|
+
if ('address' in remoteSigner) {
|
|
85
|
+
results.push(remoteSigner.address);
|
|
86
|
+
return;
|
|
100
87
|
}
|
|
88
|
+
results.push(remoteSigner);
|
|
101
89
|
};
|
|
102
90
|
if (Array.isArray(accounts)) {
|
|
103
91
|
for (const account of accounts){
|
|
@@ -147,7 +135,7 @@ import { LocalSigner, RemoteSigner } from './signer.js';
|
|
|
147
135
|
if (!this.keystore.prover) {
|
|
148
136
|
return undefined;
|
|
149
137
|
}
|
|
150
|
-
// Handle
|
|
138
|
+
// Handle prover being a private key, JSON key store or remote signer with nested address
|
|
151
139
|
if (typeof this.keystore.prover === 'string' || 'path' in this.keystore.prover || 'address' in this.keystore.prover) {
|
|
152
140
|
const signers = this.createSignersFromEthAccounts(this.keystore.prover, this.keystore.remoteSigner);
|
|
153
141
|
return {
|
|
@@ -155,10 +143,19 @@ import { LocalSigner, RemoteSigner } from './signer.js';
|
|
|
155
143
|
signers
|
|
156
144
|
};
|
|
157
145
|
}
|
|
158
|
-
|
|
159
|
-
|
|
146
|
+
// Handle prover as Id and specified publishers
|
|
147
|
+
if ('id' in this.keystore.prover) {
|
|
148
|
+
const id = this.keystore.prover.id;
|
|
149
|
+
const signers = this.createSignersFromEthAccounts(this.keystore.prover.publisher, this.keystore.remoteSigner);
|
|
150
|
+
return {
|
|
151
|
+
id,
|
|
152
|
+
signers
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
// Here, prover is just an EthAddress for a remote signer
|
|
156
|
+
const signers = this.createSignersFromEthAccounts(this.keystore.prover, this.keystore.remoteSigner);
|
|
160
157
|
return {
|
|
161
|
-
id,
|
|
158
|
+
id: undefined,
|
|
162
159
|
signers
|
|
163
160
|
};
|
|
164
161
|
}
|
|
@@ -180,7 +177,7 @@ import { LocalSigner, RemoteSigner } from './signer.js';
|
|
|
180
177
|
*/ getCoinbaseAddress(validatorIndex) {
|
|
181
178
|
const validator = this.getValidator(validatorIndex);
|
|
182
179
|
if (validator.coinbase) {
|
|
183
|
-
return
|
|
180
|
+
return validator.coinbase;
|
|
184
181
|
}
|
|
185
182
|
// Fall back to first attester address
|
|
186
183
|
const attesterSigners = this.createAttesterSigners(validatorIndex);
|
|
@@ -261,13 +258,9 @@ import { LocalSigner, RemoteSigner } from './signer.js';
|
|
|
261
258
|
if (typeof account === 'string') {
|
|
262
259
|
if (account.startsWith('0x') && account.length === 66) {
|
|
263
260
|
// Private key
|
|
264
|
-
return new LocalSigner(Buffer32.fromString(account));
|
|
261
|
+
return new LocalSigner(Buffer32.fromString(ethPrivateKeySchema.parse(account)));
|
|
265
262
|
} else {
|
|
266
|
-
|
|
267
|
-
if (!defaultRemoteSigner) {
|
|
268
|
-
throw new KeystoreError(`No remote signer configuration found for address ${account}`);
|
|
269
|
-
}
|
|
270
|
-
return new RemoteSigner(EthAddress.fromString(account), defaultRemoteSigner);
|
|
263
|
+
throw new Error(`Invalid private key`);
|
|
271
264
|
}
|
|
272
265
|
}
|
|
273
266
|
// JSON V3 keystore
|
|
@@ -277,23 +270,23 @@ import { LocalSigner, RemoteSigner } from './signer.js';
|
|
|
277
270
|
}
|
|
278
271
|
// Remote signer account
|
|
279
272
|
const remoteSigner = account;
|
|
280
|
-
if (
|
|
281
|
-
//
|
|
282
|
-
|
|
283
|
-
|
|
273
|
+
if ('address' in remoteSigner) {
|
|
274
|
+
// Remote signer with config
|
|
275
|
+
const config = remoteSigner.remoteSignerUrl ? {
|
|
276
|
+
remoteSignerUrl: remoteSigner.remoteSignerUrl,
|
|
277
|
+
certPath: remoteSigner.certPath,
|
|
278
|
+
certPass: remoteSigner.certPass
|
|
279
|
+
} : defaultRemoteSigner;
|
|
280
|
+
if (!config) {
|
|
281
|
+
throw new KeystoreError(`No remote signer configuration found for address ${remoteSigner.address}`);
|
|
284
282
|
}
|
|
285
|
-
return new RemoteSigner(
|
|
283
|
+
return new RemoteSigner(remoteSigner.address, config);
|
|
286
284
|
}
|
|
287
|
-
//
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
certPath: remoteSigner.certPath,
|
|
291
|
-
certPass: remoteSigner.certPass
|
|
292
|
-
} : defaultRemoteSigner;
|
|
293
|
-
if (!config) {
|
|
294
|
-
throw new KeystoreError(`No remote signer configuration found for address ${remoteSigner.address}`);
|
|
285
|
+
// Just an address - use default config
|
|
286
|
+
if (!defaultRemoteSigner) {
|
|
287
|
+
throw new KeystoreError(`No remote signer configuration found for address ${remoteSigner}`);
|
|
295
288
|
}
|
|
296
|
-
return new RemoteSigner(
|
|
289
|
+
return new RemoteSigner(remoteSigner, defaultRemoteSigner);
|
|
297
290
|
}
|
|
298
291
|
/**
|
|
299
292
|
* Create signer from JSON V3 keystore file or directory
|
|
@@ -410,20 +403,13 @@ import { LocalSigner, RemoteSigner } from './signer.js';
|
|
|
410
403
|
if (account.startsWith('0x') && account.length === 66) {
|
|
411
404
|
// This is a private key - derive the address
|
|
412
405
|
try {
|
|
413
|
-
const signer = new LocalSigner(Buffer32.fromString(account));
|
|
406
|
+
const signer = new LocalSigner(Buffer32.fromString(ethPrivateKeySchema.parse(account)));
|
|
414
407
|
return signer.address;
|
|
415
408
|
} catch {
|
|
416
|
-
return
|
|
417
|
-
}
|
|
418
|
-
} else if (account.startsWith('0x') && account.length === 42) {
|
|
419
|
-
// This is an address
|
|
420
|
-
try {
|
|
421
|
-
return EthAddress.fromString(account);
|
|
422
|
-
} catch {
|
|
423
|
-
return null;
|
|
409
|
+
return undefined;
|
|
424
410
|
}
|
|
425
411
|
}
|
|
426
|
-
return
|
|
412
|
+
return undefined;
|
|
427
413
|
}
|
|
428
414
|
// JSON V3 keystore
|
|
429
415
|
if ('path' in account) {
|
|
@@ -431,17 +417,15 @@ import { LocalSigner, RemoteSigner } from './signer.js';
|
|
|
431
417
|
const signers = this.createSignerFromJsonV3(account);
|
|
432
418
|
return signers.map((s)=>s.address);
|
|
433
419
|
} catch {
|
|
434
|
-
return
|
|
420
|
+
return undefined;
|
|
435
421
|
}
|
|
436
422
|
}
|
|
437
|
-
// Remote signer account
|
|
423
|
+
// Remote signer account, either it is an address or the address is nested
|
|
438
424
|
const remoteSigner = account;
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
return EthAddress.fromString(address);
|
|
442
|
-
} catch {
|
|
443
|
-
return null;
|
|
425
|
+
if ('address' in remoteSigner) {
|
|
426
|
+
return remoteSigner.address;
|
|
444
427
|
}
|
|
428
|
+
return remoteSigner;
|
|
445
429
|
};
|
|
446
430
|
// Helper to check if account matches and get its remote signer config
|
|
447
431
|
const checkAccount = (account)=>{
|
|
@@ -458,13 +442,7 @@ import { LocalSigner, RemoteSigner } from './signer.js';
|
|
|
458
442
|
}
|
|
459
443
|
// Found a match - determine the config to return
|
|
460
444
|
if (typeof account === 'string') {
|
|
461
|
-
|
|
462
|
-
// Private key - local signer, no remote config
|
|
463
|
-
return undefined;
|
|
464
|
-
} else {
|
|
465
|
-
// Address only - use defaults
|
|
466
|
-
return validator.remoteSigner || this.keystore.remoteSigner;
|
|
467
|
-
}
|
|
445
|
+
return undefined;
|
|
468
446
|
}
|
|
469
447
|
// JSON V3 - local signer, no remote config
|
|
470
448
|
if ('path' in account) {
|
|
@@ -472,21 +450,21 @@ import { LocalSigner, RemoteSigner } from './signer.js';
|
|
|
472
450
|
}
|
|
473
451
|
// Remote signer account with potential override
|
|
474
452
|
const remoteSigner = account;
|
|
475
|
-
if (
|
|
476
|
-
//
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
// No URL specified, use defaults
|
|
488
|
-
return validator.remoteSigner || this.keystore.remoteSigner;
|
|
453
|
+
if ('address' in remoteSigner) {
|
|
454
|
+
// Has inline config
|
|
455
|
+
if (remoteSigner.remoteSignerUrl) {
|
|
456
|
+
return {
|
|
457
|
+
remoteSignerUrl: remoteSigner.remoteSignerUrl,
|
|
458
|
+
certPath: remoteSigner.certPath,
|
|
459
|
+
certPass: remoteSigner.certPass
|
|
460
|
+
};
|
|
461
|
+
} else {
|
|
462
|
+
// No URL specified, use defaults
|
|
463
|
+
return validator.remoteSigner || this.keystore.remoteSigner;
|
|
464
|
+
}
|
|
489
465
|
}
|
|
466
|
+
// Just an address, use defaults
|
|
467
|
+
return validator.remoteSigner || this.keystore.remoteSigner;
|
|
490
468
|
};
|
|
491
469
|
// Check the attester configuration
|
|
492
470
|
const { attester } = validator;
|