@aztec/validator-client 0.0.0-test.1 → 0.0.1-commit.b655e406
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/block_proposal_handler.d.ts +52 -0
- package/dest/block_proposal_handler.d.ts.map +1 -0
- package/dest/block_proposal_handler.js +286 -0
- package/dest/config.d.ts +2 -13
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +31 -7
- package/dest/duties/validation_service.d.ts +16 -8
- package/dest/duties/validation_service.d.ts.map +1 -1
- package/dest/duties/validation_service.js +35 -11
- package/dest/factory.d.ts +21 -4
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +13 -6
- package/dest/index.d.ts +3 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +3 -1
- package/dest/key_store/index.d.ts +2 -0
- package/dest/key_store/index.d.ts.map +1 -1
- package/dest/key_store/index.js +2 -0
- package/dest/key_store/interface.d.ts +54 -5
- package/dest/key_store/interface.d.ts.map +1 -1
- package/dest/key_store/interface.js +3 -3
- package/dest/key_store/local_key_store.d.ts +40 -10
- package/dest/key_store/local_key_store.d.ts.map +1 -1
- package/dest/key_store/local_key_store.js +63 -16
- package/dest/key_store/node_keystore_adapter.d.ts +138 -0
- package/dest/key_store/node_keystore_adapter.d.ts.map +1 -0
- package/dest/key_store/node_keystore_adapter.js +316 -0
- package/dest/key_store/web3signer_key_store.d.ts +67 -0
- package/dest/key_store/web3signer_key_store.d.ts.map +1 -0
- package/dest/key_store/web3signer_key_store.js +152 -0
- package/dest/metrics.d.ts +11 -4
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +52 -15
- package/dest/validator.d.ts +48 -61
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +262 -165
- package/package.json +25 -19
- package/src/block_proposal_handler.ts +343 -0
- package/src/config.ts +42 -22
- package/src/duties/validation_service.ts +69 -14
- package/src/factory.ts +56 -11
- package/src/index.ts +3 -1
- package/src/key_store/index.ts +2 -0
- package/src/key_store/interface.ts +61 -5
- package/src/key_store/local_key_store.ts +67 -17
- package/src/key_store/node_keystore_adapter.ts +375 -0
- package/src/key_store/web3signer_key_store.ts +192 -0
- package/src/metrics.ts +68 -17
- package/src/validator.ts +381 -233
- package/dest/errors/index.d.ts +0 -2
- package/dest/errors/index.d.ts.map +0 -1
- package/dest/errors/index.js +0 -1
- package/dest/errors/validator.error.d.ts +0 -29
- package/dest/errors/validator.error.d.ts.map +0 -1
- package/dest/errors/validator.error.js +0 -45
- package/src/errors/index.ts +0 -1
- package/src/errors/validator.error.ts +0 -55
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { Buffer32 } from '@aztec/foundation/buffer';
|
|
2
2
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
3
|
import type { Signature } from '@aztec/foundation/eth-signature';
|
|
4
|
+
import type { EthRemoteSignerConfig } from '@aztec/node-keystore';
|
|
5
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
6
|
+
|
|
7
|
+
import type { TypedDataDefinition } from 'viem';
|
|
4
8
|
|
|
5
9
|
/** Key Store
|
|
6
10
|
*
|
|
@@ -8,19 +12,71 @@ import type { Signature } from '@aztec/foundation/eth-signature';
|
|
|
8
12
|
*/
|
|
9
13
|
export interface ValidatorKeyStore {
|
|
10
14
|
/**
|
|
11
|
-
* Get the address of
|
|
15
|
+
* Get the address of a signer by index
|
|
12
16
|
*
|
|
17
|
+
* @param index - The index of the signer
|
|
13
18
|
* @returns the address
|
|
14
19
|
*/
|
|
15
|
-
getAddress(): EthAddress;
|
|
20
|
+
getAddress(index: number): EthAddress;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Get all addresses
|
|
24
|
+
*
|
|
25
|
+
* @returns all addresses
|
|
26
|
+
*/
|
|
27
|
+
getAddresses(): EthAddress[];
|
|
16
28
|
|
|
17
|
-
|
|
29
|
+
signTypedData(typedData: TypedDataDefinition): Promise<Signature[]>;
|
|
30
|
+
signTypedDataWithAddress(address: EthAddress, typedData: TypedDataDefinition): Promise<Signature>;
|
|
18
31
|
/**
|
|
19
32
|
* Flavor of sign message that followed EIP-712 eth signed message prefix
|
|
20
33
|
* Note: this is only required when we are using ecdsa signatures over secp256k1
|
|
21
34
|
*
|
|
22
35
|
* @param message - The message to sign.
|
|
23
|
-
* @returns The
|
|
36
|
+
* @returns The signatures.
|
|
37
|
+
*/
|
|
38
|
+
signMessage(message: Buffer32): Promise<Signature[]>;
|
|
39
|
+
signMessageWithAddress(address: EthAddress, message: Buffer32): Promise<Signature>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Extended ValidatorKeyStore interface that supports the new keystore configuration model
|
|
44
|
+
* with role-based address management (attester, coinbase, publisher, fee recipient)
|
|
45
|
+
*/
|
|
46
|
+
export interface ExtendedValidatorKeyStore extends ValidatorKeyStore {
|
|
47
|
+
/**
|
|
48
|
+
* Get all attester addresses (maps to existing getAddresses())
|
|
49
|
+
* @returns all attester addresses
|
|
50
|
+
*/
|
|
51
|
+
getAttesterAddresses(): EthAddress[];
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Get the coinbase address for a specific attester
|
|
55
|
+
* Falls back to the attester address if not set
|
|
56
|
+
* @param attesterAddress - The attester address to find the coinbase for
|
|
57
|
+
* @returns the coinbase address
|
|
58
|
+
*/
|
|
59
|
+
getCoinbaseAddress(attesterAddress: EthAddress): EthAddress;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Get all publisher addresses for a specific attester (EOAs used for sending block proposal L1 txs)
|
|
63
|
+
* Falls back to the attester addresses if not set
|
|
64
|
+
* @param attesterAddress - The attester address to find the publishers for
|
|
65
|
+
* @returns all publisher addresses for this validator
|
|
66
|
+
*/
|
|
67
|
+
getPublisherAddresses(attesterAddress: EthAddress): EthAddress[];
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Get the fee recipient address for a specific attester
|
|
71
|
+
* @param attesterAddress - The attester address to find the fee recipient for
|
|
72
|
+
* @returns the fee recipient address
|
|
73
|
+
*/
|
|
74
|
+
getFeeRecipient(attesterAddress: EthAddress): AztecAddress;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Get the remote signer configuration for a specific attester if available
|
|
78
|
+
* @param attesterAddress - The attester address to find the remote signer config for
|
|
79
|
+
* @returns the remote signer configuration or undefined
|
|
24
80
|
*/
|
|
25
|
-
|
|
81
|
+
getRemoteSignerConfig(attesterAddress: EthAddress): EthRemoteSignerConfig | undefined;
|
|
26
82
|
}
|
|
@@ -1,46 +1,96 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
2
2
|
import { Secp256k1Signer } from '@aztec/foundation/crypto';
|
|
3
3
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
4
4
|
import type { Signature } from '@aztec/foundation/eth-signature';
|
|
5
5
|
|
|
6
|
+
import { type TypedDataDefinition, hashTypedData } from 'viem';
|
|
7
|
+
|
|
6
8
|
import type { ValidatorKeyStore } from './interface.js';
|
|
7
9
|
|
|
8
10
|
/**
|
|
9
11
|
* Local Key Store
|
|
10
12
|
*
|
|
11
|
-
* An implementation of the Key store using
|
|
13
|
+
* An implementation of the Key store using in memory private keys.
|
|
12
14
|
*/
|
|
13
15
|
export class LocalKeyStore implements ValidatorKeyStore {
|
|
14
|
-
private
|
|
16
|
+
private signers: Secp256k1Signer[];
|
|
17
|
+
private signersByAddress: Map<`0x${string}`, Secp256k1Signer>;
|
|
15
18
|
|
|
16
|
-
constructor(
|
|
17
|
-
this.
|
|
19
|
+
constructor(privateKeys: Buffer32[]) {
|
|
20
|
+
this.signers = privateKeys.map(privateKey => new Secp256k1Signer(privateKey));
|
|
21
|
+
this.signersByAddress = new Map(this.signers.map(signer => [signer.address.toString(), signer]));
|
|
18
22
|
}
|
|
19
23
|
|
|
20
24
|
/**
|
|
21
|
-
* Get the address of
|
|
25
|
+
* Get the address of a signer by index
|
|
22
26
|
*
|
|
27
|
+
* @param index - The index of the signer
|
|
23
28
|
* @returns the address
|
|
24
29
|
*/
|
|
25
|
-
public getAddress(): EthAddress {
|
|
26
|
-
|
|
30
|
+
public getAddress(index: number): EthAddress {
|
|
31
|
+
if (index >= this.signers.length) {
|
|
32
|
+
throw new Error(`Index ${index} is out of bounds.`);
|
|
33
|
+
}
|
|
34
|
+
return this.signers[index].address;
|
|
27
35
|
}
|
|
28
36
|
|
|
29
37
|
/**
|
|
30
|
-
*
|
|
38
|
+
* Get the addresses of all signers
|
|
31
39
|
*
|
|
32
|
-
* @
|
|
40
|
+
* @returns the addresses
|
|
41
|
+
*/
|
|
42
|
+
public getAddresses(): EthAddress[] {
|
|
43
|
+
return this.signers.map(signer => signer.address);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Sign a message with all keystore private keys
|
|
48
|
+
* @param typedData - The complete EIP-712 typed data structure (domain, types, primaryType, message)
|
|
33
49
|
* @return signature
|
|
34
50
|
*/
|
|
35
|
-
public
|
|
36
|
-
const
|
|
51
|
+
public signTypedData(typedData: TypedDataDefinition): Promise<Signature[]> {
|
|
52
|
+
const digest = hashTypedData(typedData);
|
|
53
|
+
return Promise.all(this.signers.map(signer => signer.sign(Buffer32.fromString(digest))));
|
|
54
|
+
}
|
|
37
55
|
|
|
38
|
-
|
|
56
|
+
/**
|
|
57
|
+
* Sign a message with a specific address's private key
|
|
58
|
+
* @param address - The address of the signer to use
|
|
59
|
+
* @param typedData - The complete EIP-712 typed data structure (domain, types, primaryType, message)
|
|
60
|
+
* @returns signature for the specified address
|
|
61
|
+
* @throws Error if the address is not found in the keystore
|
|
62
|
+
*/
|
|
63
|
+
public signTypedDataWithAddress(address: EthAddress, typedData: TypedDataDefinition): Promise<Signature> {
|
|
64
|
+
const signer = this.signersByAddress.get(address.toString());
|
|
65
|
+
if (!signer) {
|
|
66
|
+
throw new Error(`No signer found for address ${address.toString()}`);
|
|
67
|
+
}
|
|
68
|
+
const digest = hashTypedData(typedData);
|
|
69
|
+
return Promise.resolve(signer.sign(Buffer32.fromString(digest)));
|
|
39
70
|
}
|
|
40
71
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
72
|
+
/**
|
|
73
|
+
* Sign a message using eth_sign with all keystore private keys
|
|
74
|
+
*
|
|
75
|
+
* @param message - The message to sign
|
|
76
|
+
* @return signatures
|
|
77
|
+
*/
|
|
78
|
+
public signMessage(message: Buffer32): Promise<Signature[]> {
|
|
79
|
+
return Promise.all(this.signers.map(signer => signer.signMessage(message)));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Sign a message using eth_sign with a specific address's private key
|
|
84
|
+
* @param address - The address of the signer to use
|
|
85
|
+
* @param message - The message to sign
|
|
86
|
+
* @returns signature for the specified address
|
|
87
|
+
* @throws Error if the address is not found in the keystore
|
|
88
|
+
*/
|
|
89
|
+
public signMessageWithAddress(address: EthAddress, message: Buffer32): Promise<Signature> {
|
|
90
|
+
const signer = this.signersByAddress.get(address.toString());
|
|
91
|
+
if (!signer) {
|
|
92
|
+
throw new Error(`No signer found for address ${address.toString()}`);
|
|
93
|
+
}
|
|
94
|
+
return Promise.resolve(signer.signMessage(message));
|
|
45
95
|
}
|
|
46
96
|
}
|
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
import type { EthSigner } from '@aztec/ethereum';
|
|
2
|
+
import type { Buffer32 } from '@aztec/foundation/buffer';
|
|
3
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
4
|
+
import type { Signature } from '@aztec/foundation/eth-signature';
|
|
5
|
+
import { KeystoreManager, loadKeystoreFile } from '@aztec/node-keystore';
|
|
6
|
+
import type { EthRemoteSignerConfig } from '@aztec/node-keystore';
|
|
7
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
8
|
+
import { InvalidValidatorPrivateKeyError } from '@aztec/stdlib/validators';
|
|
9
|
+
|
|
10
|
+
import type { TypedDataDefinition } from 'viem';
|
|
11
|
+
import { privateKeyToAccount } from 'viem/accounts';
|
|
12
|
+
|
|
13
|
+
import type { ExtendedValidatorKeyStore } from './interface.js';
|
|
14
|
+
|
|
15
|
+
type AddressHex = string;
|
|
16
|
+
type ValidatorIndex = number;
|
|
17
|
+
|
|
18
|
+
interface ValidatorCache {
|
|
19
|
+
attesters: EthSigner[];
|
|
20
|
+
publishers: EthSigner[];
|
|
21
|
+
all: EthSigner[];
|
|
22
|
+
byAddress: Map<AddressHex, EthSigner>; // all signers, any role
|
|
23
|
+
attesterSet: Set<AddressHex>; // attester addresses only
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export class NodeKeystoreAdapter implements ExtendedValidatorKeyStore {
|
|
27
|
+
private readonly keystoreManager: KeystoreManager;
|
|
28
|
+
|
|
29
|
+
// Per-validator cache (lazy)
|
|
30
|
+
private readonly validators = new Map<ValidatorIndex, ValidatorCache>();
|
|
31
|
+
|
|
32
|
+
private readonly addressIndex = new Map<AddressHex, { signer: EthSigner; validatorIndex: ValidatorIndex }>();
|
|
33
|
+
|
|
34
|
+
private constructor(keystoreManager: KeystoreManager) {
|
|
35
|
+
this.keystoreManager = keystoreManager;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Create an adapter from a keystore JSON file on disk.
|
|
40
|
+
* @param keystoreFilePath Absolute or relative path to a keystore JSON file
|
|
41
|
+
* @returns A configured NodeKeystoreAdapter instance
|
|
42
|
+
* @throws Error when the file fails schema validation or cannot be read
|
|
43
|
+
*/
|
|
44
|
+
static fromKeystoreFile(keystoreFilePath: string): NodeKeystoreAdapter {
|
|
45
|
+
const keystoreConfig = loadKeystoreFile(keystoreFilePath);
|
|
46
|
+
return NodeKeystoreAdapter.fromKeystoreConfig(keystoreConfig);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Create an adapter from an in-memory keystore-like object.
|
|
51
|
+
* Validates resolved duplicate attester addresses across validators and sources.
|
|
52
|
+
* @param keystoreConfig Parsed config object (typically result of loadKeystoreFile)
|
|
53
|
+
* @returns A configured NodeKeystoreAdapter instance
|
|
54
|
+
* @throws Error when resolved duplicate attester addresses are detected
|
|
55
|
+
*/
|
|
56
|
+
static fromKeystoreConfig(keystoreConfig: unknown): NodeKeystoreAdapter {
|
|
57
|
+
const keystoreManager = new KeystoreManager(keystoreConfig as any);
|
|
58
|
+
// Validate resolved attester addresses (covers JSON V3 and mnemonic duplicates across validators)
|
|
59
|
+
keystoreManager.validateResolvedUniqueAttesterAddresses();
|
|
60
|
+
return new NodeKeystoreAdapter(keystoreManager);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Build an adapter directly from a list of validator private keys.
|
|
65
|
+
* Each key becomes a separate validator using the same key for attester and publisher,
|
|
66
|
+
* coinbase defaults to the derived EOA address, and feeRecipient is a 32-byte padded address.
|
|
67
|
+
* Note: Fee recipient is a temporary placeholder, replace with actual fee recipient when implemented.
|
|
68
|
+
*/
|
|
69
|
+
static fromPrivateKeys(privateKeys: string[]): NodeKeystoreAdapter {
|
|
70
|
+
// Minimal validation: 0x + 64 hex
|
|
71
|
+
const isPk = (s: string) => /^0x[0-9a-fA-F]{64}$/.test(s);
|
|
72
|
+
for (const pk of privateKeys) {
|
|
73
|
+
if (!isPk(pk)) {
|
|
74
|
+
throw new InvalidValidatorPrivateKeyError();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const validators = privateKeys.map(pk => {
|
|
79
|
+
const account = privateKeyToAccount(pk as `0x${string}`);
|
|
80
|
+
const ethAddress = account.address as `0x${string}`;
|
|
81
|
+
// TODO: Temporary fee recipient, replace with actual fee recipient when implemented
|
|
82
|
+
const feeRecipient = `0x${ethAddress.slice(2).padStart(64, '0')}` as `0x${string}`;
|
|
83
|
+
return {
|
|
84
|
+
attester: pk as `0x${string}`,
|
|
85
|
+
publisher: pk as `0x${string}`,
|
|
86
|
+
coinbase: ethAddress,
|
|
87
|
+
feeRecipient,
|
|
88
|
+
};
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
const cfg = { schemaVersion: 1, validators } as const;
|
|
92
|
+
return NodeKeystoreAdapter.fromKeystoreConfig(cfg);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Build an adapter for a Web3Signer setup by providing the signer URL and the EOA addresses.
|
|
97
|
+
* Each address becomes a separate validator; attester and publisher point to the same remote signer entry.
|
|
98
|
+
* Note: Fee recipient is a temporary placeholder, replace with actual fee recipient when implemented.
|
|
99
|
+
*/
|
|
100
|
+
static fromWeb3Signer(web3SignerUrl: string, addresses: EthAddress[]): NodeKeystoreAdapter {
|
|
101
|
+
const validators = addresses.map(address => {
|
|
102
|
+
const ethAddress = address.toString() as `0x${string}`;
|
|
103
|
+
// TODO: Temporary fee recipient, replace with actual fee recipient when implemented
|
|
104
|
+
const feeRecipient = `0x${ethAddress.slice(2).padStart(64, '0')}` as `0x${string}`;
|
|
105
|
+
return {
|
|
106
|
+
attester: { address: ethAddress, remoteSignerUrl: web3SignerUrl },
|
|
107
|
+
publisher: { address: ethAddress, remoteSignerUrl: web3SignerUrl },
|
|
108
|
+
coinbase: ethAddress,
|
|
109
|
+
feeRecipient,
|
|
110
|
+
};
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
const cfg = { schemaVersion: 1, validators } as const;
|
|
114
|
+
return NodeKeystoreAdapter.fromKeystoreConfig(cfg);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
static fromKeyStoreManager(manager: KeystoreManager): NodeKeystoreAdapter {
|
|
118
|
+
return new NodeKeystoreAdapter(manager);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Normalize address keys to lowercase hex strings for map/set usage.
|
|
123
|
+
*/
|
|
124
|
+
private static key(addr: EthAddress | AddressHex): AddressHex {
|
|
125
|
+
return typeof addr === 'string' ? addr.toLowerCase() : addr.toString().toLowerCase();
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Ensure per-validator signer cache exists; build it by creating
|
|
130
|
+
* attester/publisher signers and populating indices when missing.
|
|
131
|
+
* @param validatorIndex Index of the validator in the keystore
|
|
132
|
+
* @returns The cached validator entry
|
|
133
|
+
*/
|
|
134
|
+
private ensureValidator(validatorIndex: number): ValidatorCache {
|
|
135
|
+
const cached = this.validators.get(validatorIndex);
|
|
136
|
+
if (cached) {
|
|
137
|
+
return cached;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const attesters = this.keystoreManager.createAttesterSigners(validatorIndex);
|
|
141
|
+
const publishers = this.keystoreManager.createPublisherSigners(validatorIndex);
|
|
142
|
+
|
|
143
|
+
// Build 'all' + indices
|
|
144
|
+
const byAddress = new Map<AddressHex, EthSigner>();
|
|
145
|
+
const attesterSet = new Set<AddressHex>();
|
|
146
|
+
|
|
147
|
+
for (const s of attesters) {
|
|
148
|
+
const k = NodeKeystoreAdapter.key(s.address);
|
|
149
|
+
byAddress.set(k, s);
|
|
150
|
+
attesterSet.add(k);
|
|
151
|
+
}
|
|
152
|
+
for (const s of publishers) {
|
|
153
|
+
const k = NodeKeystoreAdapter.key(s.address);
|
|
154
|
+
if (!byAddress.has(k)) {
|
|
155
|
+
byAddress.set(k, s);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const all = Array.from(byAddress.values());
|
|
160
|
+
|
|
161
|
+
// Populate global index
|
|
162
|
+
for (const [k, signer] of byAddress.entries()) {
|
|
163
|
+
this.addressIndex.set(k, { signer, validatorIndex });
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const built: ValidatorCache = { attesters, publishers, all, byAddress, attesterSet };
|
|
167
|
+
this.validators.set(validatorIndex, built);
|
|
168
|
+
return built;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Iterate all validator indices in the keystore manager.
|
|
173
|
+
*/
|
|
174
|
+
private *validatorIndices(): Iterable<number> {
|
|
175
|
+
const n = this.keystoreManager.getValidatorCount();
|
|
176
|
+
for (let i = 0; i < n; i++) {
|
|
177
|
+
yield i;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Find the validator index that contains the given attester address.
|
|
183
|
+
* @param attesterAddress Address to locate
|
|
184
|
+
* @returns Validator index
|
|
185
|
+
* @throws Error when no validator contains the attester
|
|
186
|
+
*/
|
|
187
|
+
private findValidatorIndexForAttester(attesterAddress: EthAddress): number {
|
|
188
|
+
const key = NodeKeystoreAdapter.key(attesterAddress);
|
|
189
|
+
|
|
190
|
+
// Fast path: if we’ve already cached any validator that includes this as attester
|
|
191
|
+
for (const i of this.validatorIndices()) {
|
|
192
|
+
const v = this.ensureValidator(i);
|
|
193
|
+
if (v.attesterSet.has(key)) {
|
|
194
|
+
return i;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
throw new Error(`Attester address ${attesterAddress.toString()} not found in any validator configuration`);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Get attester address by flat index across all validators' attester sets.
|
|
203
|
+
* @param index Zero-based flat index across all attesters
|
|
204
|
+
* @returns EthAddress for the indexed attester
|
|
205
|
+
* @throws Error when index is out of bounds
|
|
206
|
+
*/
|
|
207
|
+
getAddress(index: number): EthAddress {
|
|
208
|
+
const all = this.getAddresses();
|
|
209
|
+
if (index < 0 || index >= all.length) {
|
|
210
|
+
throw new Error(`Index ${index} is out of bounds (0..${all.length - 1}).`);
|
|
211
|
+
}
|
|
212
|
+
return all[index];
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Get all attester addresses across validators (legacy-compatible view).
|
|
217
|
+
*/
|
|
218
|
+
getAddresses(): EthAddress[] {
|
|
219
|
+
const out: EthAddress[] = [];
|
|
220
|
+
for (const i of this.validatorIndices()) {
|
|
221
|
+
const v = this.ensureValidator(i);
|
|
222
|
+
// attester addresses only for backward compatibility
|
|
223
|
+
for (const s of v.attesters) {
|
|
224
|
+
out.push(s.address);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return out;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Sign typed data with all attester signers across validators.
|
|
232
|
+
* @param typedData EIP-712 typed data
|
|
233
|
+
* @returns Array of signatures in validator order, flattened
|
|
234
|
+
*/
|
|
235
|
+
async signTypedData(typedData: TypedDataDefinition): Promise<Signature[]> {
|
|
236
|
+
const jobs: Promise<Signature>[] = [];
|
|
237
|
+
for (const i of this.validatorIndices()) {
|
|
238
|
+
const v = this.ensureValidator(i);
|
|
239
|
+
for (const s of v.attesters) {
|
|
240
|
+
jobs.push(this.keystoreManager.signTypedData(s, typedData));
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return await Promise.all(jobs);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Sign a message with all attester signers across validators.
|
|
248
|
+
* @param message 32-byte message (already hashed/padded as needed)
|
|
249
|
+
* @returns Array of signatures in validator order, flattened
|
|
250
|
+
*/
|
|
251
|
+
async signMessage(message: Buffer32): Promise<Signature[]> {
|
|
252
|
+
const jobs: Promise<Signature>[] = [];
|
|
253
|
+
for (const i of this.validatorIndices()) {
|
|
254
|
+
const v = this.ensureValidator(i);
|
|
255
|
+
for (const s of v.attesters) {
|
|
256
|
+
jobs.push(this.keystoreManager.signMessage(s, message));
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return await Promise.all(jobs);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Sign typed data with a signer identified by address (any role).
|
|
264
|
+
* Hydrates caches on-demand when the address is first seen.
|
|
265
|
+
* @param address Address to sign with
|
|
266
|
+
* @param typedData EIP-712 typed data
|
|
267
|
+
* @returns Signature from the signer matching the address
|
|
268
|
+
* @throws Error when no signer exists for the address
|
|
269
|
+
*/
|
|
270
|
+
async signTypedDataWithAddress(address: EthAddress, typedData: TypedDataDefinition): Promise<Signature> {
|
|
271
|
+
const entry = this.addressIndex.get(NodeKeystoreAdapter.key(address));
|
|
272
|
+
if (entry) {
|
|
273
|
+
return await this.keystoreManager.signTypedData(entry.signer, typedData);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// If not in global index yet, lazily hydrate all validators once and retry
|
|
277
|
+
for (const i of this.validatorIndices()) {
|
|
278
|
+
this.ensureValidator(i);
|
|
279
|
+
}
|
|
280
|
+
const second = this.addressIndex.get(NodeKeystoreAdapter.key(address));
|
|
281
|
+
if (second) {
|
|
282
|
+
return await this.keystoreManager.signTypedData(second.signer, typedData);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
throw new Error(`No signer found for address ${address.toString()}`);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Sign a message with a signer identified by address (any role).
|
|
290
|
+
* Hydrates caches on-demand when the address is first seen.
|
|
291
|
+
* @param address Address to sign with
|
|
292
|
+
* @param message 32-byte message
|
|
293
|
+
* @returns Signature from the signer matching the address
|
|
294
|
+
* @throws Error when no signer exists for the address
|
|
295
|
+
*/
|
|
296
|
+
async signMessageWithAddress(address: EthAddress, message: Buffer32): Promise<Signature> {
|
|
297
|
+
const entry = this.addressIndex.get(NodeKeystoreAdapter.key(address));
|
|
298
|
+
if (entry) {
|
|
299
|
+
return await this.keystoreManager.signMessage(entry.signer, message);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
for (const i of this.validatorIndices()) {
|
|
303
|
+
this.ensureValidator(i);
|
|
304
|
+
}
|
|
305
|
+
const second = this.addressIndex.get(NodeKeystoreAdapter.key(address));
|
|
306
|
+
if (second) {
|
|
307
|
+
return await this.keystoreManager.signMessage(second.signer, message);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
throw new Error(`No signer found for address ${address.toString()}`);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Get all attester addresses across validators (alias of getAddresses).
|
|
315
|
+
*/
|
|
316
|
+
getAttesterAddresses(): EthAddress[] {
|
|
317
|
+
return this.getAddresses();
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Get the effective coinbase address for the validator that contains the given attester.
|
|
322
|
+
* @param attesterAddress Address of an attester belonging to the validator
|
|
323
|
+
* @returns Coinbase EthAddress
|
|
324
|
+
*/
|
|
325
|
+
getCoinbaseAddress(attesterAddress: EthAddress): EthAddress {
|
|
326
|
+
const validatorIndex = this.findValidatorIndexForAttester(attesterAddress);
|
|
327
|
+
return this.keystoreManager.getCoinbaseAddress(validatorIndex, attesterAddress);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Get the publisher addresses for the validator that contains the given attester.
|
|
332
|
+
* @param attesterAddress Address of an attester belonging to the validator
|
|
333
|
+
* @returns Array of publisher addresses
|
|
334
|
+
*/
|
|
335
|
+
getPublisherAddresses(attesterAddress: EthAddress): EthAddress[] {
|
|
336
|
+
const validatorIndex = this.findValidatorIndexForAttester(attesterAddress);
|
|
337
|
+
const v = this.ensureValidator(validatorIndex);
|
|
338
|
+
return v.publishers.map(s => s.address);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
getAttestorForPublisher(publisherAddress: EthAddress): EthAddress {
|
|
342
|
+
const attestorAddresses = this.getAttesterAddresses();
|
|
343
|
+
for (const attestor of attestorAddresses) {
|
|
344
|
+
const publishers = this.getPublisherAddresses(attestor);
|
|
345
|
+
const found = publishers.some(publisher => publisher.equals(publisherAddress));
|
|
346
|
+
if (found) {
|
|
347
|
+
return attestor;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
// Could not find an attestor for this publisher
|
|
351
|
+
throw new Error(`Failed to find attestor for publisher ${publisherAddress.toString()}`);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Get the fee recipient for the validator that contains the given attester.
|
|
356
|
+
* @param attesterAddress Address of an attester belonging to the validator
|
|
357
|
+
* @returns Fee recipient as AztecAddress
|
|
358
|
+
*/
|
|
359
|
+
getFeeRecipient(attesterAddress: EthAddress): AztecAddress {
|
|
360
|
+
const validatorIndex = this.findValidatorIndexForAttester(attesterAddress);
|
|
361
|
+
return this.keystoreManager.getFeeRecipient(validatorIndex);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Get the effective remote signer configuration for the attester.
|
|
366
|
+
* Precedence: account-level override > validator-level override > file-level default.
|
|
367
|
+
* Returns undefined for local signers (private key / JSON-V3 / mnemonic).
|
|
368
|
+
* @param attesterAddress Address of an attester belonging to the validator
|
|
369
|
+
* @returns Effective remote signer configuration or undefined
|
|
370
|
+
*/
|
|
371
|
+
getRemoteSignerConfig(attesterAddress: EthAddress): EthRemoteSignerConfig | undefined {
|
|
372
|
+
const validatorIndex = this.findValidatorIndexForAttester(attesterAddress);
|
|
373
|
+
return this.keystoreManager.getEffectiveRemoteSignerConfig(validatorIndex, attesterAddress);
|
|
374
|
+
}
|
|
375
|
+
}
|