@aztec/validator-client 0.0.0-test.1 → 0.0.1-commit.023c3e5
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/README.md +282 -0
- package/dest/block_proposal_handler.d.ts +63 -0
- package/dest/block_proposal_handler.d.ts.map +1 -0
- package/dest/block_proposal_handler.js +546 -0
- package/dest/checkpoint_builder.d.ts +66 -0
- package/dest/checkpoint_builder.d.ts.map +1 -0
- package/dest/checkpoint_builder.js +173 -0
- package/dest/config.d.ts +3 -14
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +41 -8
- package/dest/duties/validation_service.d.ts +50 -13
- package/dest/duties/validation_service.d.ts.map +1 -1
- package/dest/duties/validation_service.js +123 -17
- package/dest/factory.d.ts +28 -6
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +13 -6
- package/dest/index.d.ts +6 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +5 -1
- package/dest/key_store/ha_key_store.d.ts +99 -0
- package/dest/key_store/ha_key_store.d.ts.map +1 -0
- package/dest/key_store/ha_key_store.js +208 -0
- package/dest/key_store/index.d.ts +4 -1
- package/dest/key_store/index.d.ts.map +1 -1
- package/dest/key_store/index.js +3 -0
- package/dest/key_store/interface.d.ts +85 -6
- 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 +46 -11
- package/dest/key_store/local_key_store.d.ts.map +1 -1
- package/dest/key_store/local_key_store.js +68 -17
- package/dest/key_store/node_keystore_adapter.d.ts +151 -0
- package/dest/key_store/node_keystore_adapter.d.ts.map +1 -0
- package/dest/key_store/node_keystore_adapter.js +330 -0
- package/dest/key_store/web3signer_key_store.d.ts +66 -0
- package/dest/key_store/web3signer_key_store.d.ts.map +1 -0
- package/dest/key_store/web3signer_key_store.js +156 -0
- package/dest/metrics.d.ts +13 -5
- package/dest/metrics.d.ts.map +1 -1
- package/dest/metrics.js +63 -22
- package/dest/tx_validator/index.d.ts +3 -0
- package/dest/tx_validator/index.d.ts.map +1 -0
- package/dest/tx_validator/index.js +2 -0
- package/dest/tx_validator/nullifier_cache.d.ts +14 -0
- package/dest/tx_validator/nullifier_cache.d.ts.map +1 -0
- package/dest/tx_validator/nullifier_cache.js +24 -0
- package/dest/tx_validator/tx_validator_factory.d.ts +19 -0
- package/dest/tx_validator/tx_validator_factory.d.ts.map +1 -0
- package/dest/tx_validator/tx_validator_factory.js +54 -0
- package/dest/validator.d.ts +73 -58
- package/dest/validator.d.ts.map +1 -1
- package/dest/validator.js +559 -166
- package/package.json +37 -21
- package/src/block_proposal_handler.ts +555 -0
- package/src/checkpoint_builder.ts +314 -0
- package/src/config.ts +52 -22
- package/src/duties/validation_service.ts +193 -19
- package/src/factory.ts +65 -11
- package/src/index.ts +5 -1
- package/src/key_store/ha_key_store.ts +269 -0
- package/src/key_store/index.ts +3 -0
- package/src/key_store/interface.ts +100 -5
- package/src/key_store/local_key_store.ts +77 -18
- package/src/key_store/node_keystore_adapter.ts +398 -0
- package/src/key_store/web3signer_key_store.ts +205 -0
- package/src/metrics.ts +86 -23
- package/src/tx_validator/index.ts +2 -0
- package/src/tx_validator/nullifier_cache.ts +30 -0
- package/src/tx_validator/tx_validator_factory.ts +154 -0
- package/src/validator.ts +757 -221
- 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
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* High Availability Key Store
|
|
3
|
+
*
|
|
4
|
+
* A ValidatorKeyStore wrapper that adds slashing protection for HA validator setups.
|
|
5
|
+
* When multiple validator nodes are running, only one node will sign for a given duty.
|
|
6
|
+
*/
|
|
7
|
+
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
8
|
+
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
9
|
+
import type { Signature } from '@aztec/foundation/eth-signature';
|
|
10
|
+
import type { EthRemoteSignerConfig } from '@aztec/node-keystore';
|
|
11
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
12
|
+
import { type SigningContext } from '@aztec/validator-ha-signer/types';
|
|
13
|
+
import type { ValidatorHASigner } from '@aztec/validator-ha-signer/validator-ha-signer';
|
|
14
|
+
import { type TypedDataDefinition } from 'viem';
|
|
15
|
+
import type { ExtendedValidatorKeyStore } from './interface.js';
|
|
16
|
+
/**
|
|
17
|
+
* High Availability Key Store
|
|
18
|
+
*
|
|
19
|
+
* Wraps a base ExtendedValidatorKeyStore and ValidatorHASigner to provide
|
|
20
|
+
* HA-protected signing operations (when context is provided).
|
|
21
|
+
*
|
|
22
|
+
* The extended interface methods (getAttesterAddresses, getCoinbaseAddress, etc.)
|
|
23
|
+
* are pure pass-through since they don't require HA coordination.
|
|
24
|
+
*
|
|
25
|
+
* Usage:
|
|
26
|
+
* ```typescript
|
|
27
|
+
* const baseKeyStore = NodeKeystoreAdapter.fromPrivateKeys(privateKeys);
|
|
28
|
+
* const haSigner = new ValidatorHASigner(db, config);
|
|
29
|
+
* const haKeyStore = new HAKeyStore(baseKeyStore, haSigner);
|
|
30
|
+
*
|
|
31
|
+
* // Without context - signs directly (no HA protection)
|
|
32
|
+
* const sig = await haKeyStore.signMessageWithAddress(addr, msg);
|
|
33
|
+
*
|
|
34
|
+
* // With context - HA protected, throws DutyAlreadySignedError if already signed
|
|
35
|
+
* const result = await haKeyStore.signMessageWithAddress(addr, msg, {
|
|
36
|
+
* slot: 100n,
|
|
37
|
+
* blockNumber: 50n,
|
|
38
|
+
* dutyType: DutyType.BLOCK_PROPOSAL,
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare class HAKeyStore implements ExtendedValidatorKeyStore {
|
|
43
|
+
private readonly baseKeyStore;
|
|
44
|
+
private readonly haSigner;
|
|
45
|
+
private readonly log;
|
|
46
|
+
constructor(baseKeyStore: ExtendedValidatorKeyStore, haSigner: ValidatorHASigner);
|
|
47
|
+
/**
|
|
48
|
+
* Sign typed data with all addresses.
|
|
49
|
+
* Coordinates across nodes to prevent double-signing for most duty types.
|
|
50
|
+
* AUTH_REQUEST and TXS duties bypass HA protection since signing multiple times is safe.
|
|
51
|
+
* Returns only signatures that were successfully claimed by this node.
|
|
52
|
+
*/
|
|
53
|
+
signTypedData(typedData: TypedDataDefinition, context: SigningContext): Promise<Signature[]>;
|
|
54
|
+
/**
|
|
55
|
+
* Sign a message with all addresses.
|
|
56
|
+
* Coordinates across nodes to prevent double-signing for most duty types.
|
|
57
|
+
* AUTH_REQUEST and TXS duties bypass HA protection since signing multiple times is safe.
|
|
58
|
+
* Returns only signatures that were successfully claimed by this node.
|
|
59
|
+
*/
|
|
60
|
+
signMessage(message: Buffer32, context: SigningContext): Promise<Signature[]>;
|
|
61
|
+
/**
|
|
62
|
+
* Sign typed data with a specific address.
|
|
63
|
+
* Coordinates across nodes to prevent double-signing for most duty types.
|
|
64
|
+
* AUTH_REQUEST and TXS duties bypass HA protection since signing multiple times is safe.
|
|
65
|
+
* @throws DutyAlreadySignedError if the duty was already signed by another node
|
|
66
|
+
* @throws SlashingProtectionError if attempting to sign different data for the same slot
|
|
67
|
+
*/
|
|
68
|
+
signTypedDataWithAddress(address: EthAddress, typedData: TypedDataDefinition, context: SigningContext): Promise<Signature>;
|
|
69
|
+
/**
|
|
70
|
+
* Sign a message with a specific address.
|
|
71
|
+
* Coordinates across nodes to prevent double-signing for most duty types.
|
|
72
|
+
* AUTH_REQUEST and TXS duties bypass HA protection since signing multiple times is safe.
|
|
73
|
+
* @throws DutyAlreadySignedError if the duty was already signed by another node
|
|
74
|
+
* @throws SlashingProtectionError if attempting to sign different data for the same slot
|
|
75
|
+
*/
|
|
76
|
+
signMessageWithAddress(address: EthAddress, message: Buffer32, context: SigningContext): Promise<Signature>;
|
|
77
|
+
getAddress(index: number): EthAddress;
|
|
78
|
+
getAddresses(): EthAddress[];
|
|
79
|
+
getAttesterAddresses(): EthAddress[];
|
|
80
|
+
getCoinbaseAddress(attesterAddress: EthAddress): EthAddress;
|
|
81
|
+
getPublisherAddresses(attesterAddress: EthAddress): EthAddress[];
|
|
82
|
+
getFeeRecipient(attesterAddress: EthAddress): AztecAddress;
|
|
83
|
+
getRemoteSignerConfig(attesterAddress: EthAddress): EthRemoteSignerConfig | undefined;
|
|
84
|
+
/**
|
|
85
|
+
* Process signing errors from the HA signer.
|
|
86
|
+
* Logs expected HA errors (already signed) at appropriate levels.
|
|
87
|
+
* Re-throws unexpected errors.
|
|
88
|
+
*/
|
|
89
|
+
private processSigningError;
|
|
90
|
+
/**
|
|
91
|
+
* Start the high-availability key store
|
|
92
|
+
*/
|
|
93
|
+
start(): Promise<void>;
|
|
94
|
+
/**
|
|
95
|
+
* Stop the high-availability key store
|
|
96
|
+
*/
|
|
97
|
+
stop(): Promise<void>;
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaGFfa2V5X3N0b3JlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMva2V5X3N0b3JlL2hhX2tleV9zdG9yZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7Ozs7R0FLRztBQUNILE9BQU8sRUFBRSxRQUFRLEVBQUUsTUFBTSwwQkFBMEIsQ0FBQztBQUNwRCxPQUFPLEtBQUssRUFBRSxVQUFVLEVBQUUsTUFBTSwrQkFBK0IsQ0FBQztBQUNoRSxPQUFPLEtBQUssRUFBRSxTQUFTLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUVqRSxPQUFPLEtBQUssRUFBRSxxQkFBcUIsRUFBRSxNQUFNLHNCQUFzQixDQUFDO0FBQ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AAI,UAAU,EAAE,CAEnC;IAED,kBAAkB,CAAC,eAAe,EAAE,UAAU,GAAG,UAAU,CAE1D;IAED,qBAAqB,CAAC,eAAe,EAAE,UAAU,GAAG,UAAU,EAAE,CAE/D;IAED,eAAe,CAAC,eAAe,EAAE,UAAU,GAAG,YAAY,CAEzD;IAED,qBAAqB,CAAC,eAAe,EAAE,UAAU,GAAG,qBAAqB,GAAG,SAAS,CAEpF;IAED;;;;OAIG;IACH,OAAO,CAAC,mBAAmB;IAwB3B;;OAEG;IACI,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAE5B;IAED;;OAEG;IACU,IAAI,kBAEhB;CACF"}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* High Availability Key Store
|
|
3
|
+
*
|
|
4
|
+
* A ValidatorKeyStore wrapper that adds slashing protection for HA validator setups.
|
|
5
|
+
* When multiple validator nodes are running, only one node will sign for a given duty.
|
|
6
|
+
*/ import { Buffer32 } from '@aztec/foundation/buffer';
|
|
7
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
8
|
+
import { DutyAlreadySignedError, SlashingProtectionError } from '@aztec/validator-ha-signer/errors';
|
|
9
|
+
import { isHAProtectedContext } from '@aztec/validator-ha-signer/types';
|
|
10
|
+
import { hashTypedData } from 'viem';
|
|
11
|
+
/**
|
|
12
|
+
* High Availability Key Store
|
|
13
|
+
*
|
|
14
|
+
* Wraps a base ExtendedValidatorKeyStore and ValidatorHASigner to provide
|
|
15
|
+
* HA-protected signing operations (when context is provided).
|
|
16
|
+
*
|
|
17
|
+
* The extended interface methods (getAttesterAddresses, getCoinbaseAddress, etc.)
|
|
18
|
+
* are pure pass-through since they don't require HA coordination.
|
|
19
|
+
*
|
|
20
|
+
* Usage:
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const baseKeyStore = NodeKeystoreAdapter.fromPrivateKeys(privateKeys);
|
|
23
|
+
* const haSigner = new ValidatorHASigner(db, config);
|
|
24
|
+
* const haKeyStore = new HAKeyStore(baseKeyStore, haSigner);
|
|
25
|
+
*
|
|
26
|
+
* // Without context - signs directly (no HA protection)
|
|
27
|
+
* const sig = await haKeyStore.signMessageWithAddress(addr, msg);
|
|
28
|
+
*
|
|
29
|
+
* // With context - HA protected, throws DutyAlreadySignedError if already signed
|
|
30
|
+
* const result = await haKeyStore.signMessageWithAddress(addr, msg, {
|
|
31
|
+
* slot: 100n,
|
|
32
|
+
* blockNumber: 50n,
|
|
33
|
+
* dutyType: DutyType.BLOCK_PROPOSAL,
|
|
34
|
+
* });
|
|
35
|
+
* ```
|
|
36
|
+
*/ export class HAKeyStore {
|
|
37
|
+
baseKeyStore;
|
|
38
|
+
haSigner;
|
|
39
|
+
log;
|
|
40
|
+
constructor(baseKeyStore, haSigner){
|
|
41
|
+
this.baseKeyStore = baseKeyStore;
|
|
42
|
+
this.haSigner = haSigner;
|
|
43
|
+
this.log = createLogger('ha-key-store');
|
|
44
|
+
this.log.info('HAKeyStore initialized', {
|
|
45
|
+
nodeId: haSigner.nodeId
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Sign typed data with all addresses.
|
|
50
|
+
* Coordinates across nodes to prevent double-signing for most duty types.
|
|
51
|
+
* AUTH_REQUEST and TXS duties bypass HA protection since signing multiple times is safe.
|
|
52
|
+
* Returns only signatures that were successfully claimed by this node.
|
|
53
|
+
*/ async signTypedData(typedData, context) {
|
|
54
|
+
// no need for HA protection on auth request and txs signatures
|
|
55
|
+
if (!isHAProtectedContext(context)) {
|
|
56
|
+
return this.baseKeyStore.signTypedData(typedData, context);
|
|
57
|
+
}
|
|
58
|
+
// Sign each address with HA protection
|
|
59
|
+
const addresses = this.getAddresses();
|
|
60
|
+
const results = await Promise.allSettled(addresses.map((addr)=>this.signTypedDataWithAddress(addr, typedData, context)));
|
|
61
|
+
// Filter out failures (already signed by other nodes or other errors)
|
|
62
|
+
return results.filter((result)=>{
|
|
63
|
+
if (result.status === 'fulfilled') {
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
// Log expected HA errors (already signed) at debug level
|
|
67
|
+
if (result.reason instanceof DutyAlreadySignedError) {
|
|
68
|
+
this.log.debug(`Duty already signed by another node`, {
|
|
69
|
+
dutyType: context.dutyType,
|
|
70
|
+
slot: context.slot,
|
|
71
|
+
signedByNode: result.reason.signedByNode
|
|
72
|
+
});
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
// Re-throw unexpected errors
|
|
76
|
+
throw result.reason;
|
|
77
|
+
}).map((result)=>result.value);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Sign a message with all addresses.
|
|
81
|
+
* Coordinates across nodes to prevent double-signing for most duty types.
|
|
82
|
+
* AUTH_REQUEST and TXS duties bypass HA protection since signing multiple times is safe.
|
|
83
|
+
* Returns only signatures that were successfully claimed by this node.
|
|
84
|
+
*/ async signMessage(message, context) {
|
|
85
|
+
// no need for HA protection on auth request and txs signatures
|
|
86
|
+
if (!isHAProtectedContext(context)) {
|
|
87
|
+
return this.baseKeyStore.signMessage(message, context);
|
|
88
|
+
}
|
|
89
|
+
// Sign each address with HA protection
|
|
90
|
+
const addresses = this.getAddresses();
|
|
91
|
+
const results = await Promise.allSettled(addresses.map((addr)=>this.signMessageWithAddress(addr, message, context)));
|
|
92
|
+
// Filter out failures (already signed by other nodes or other errors)
|
|
93
|
+
return results.filter((result)=>{
|
|
94
|
+
if (result.status === 'fulfilled') {
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
// Log expected HA errors (already signed) at debug level
|
|
98
|
+
if (result.reason instanceof DutyAlreadySignedError) {
|
|
99
|
+
this.log.debug(`Duty already signed by another node`, {
|
|
100
|
+
dutyType: context.dutyType,
|
|
101
|
+
slot: context.slot,
|
|
102
|
+
signedByNode: result.reason.signedByNode
|
|
103
|
+
});
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
// Re-throw unexpected errors
|
|
107
|
+
throw result.reason;
|
|
108
|
+
}).map((result)=>result.value);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Sign typed data with a specific address.
|
|
112
|
+
* Coordinates across nodes to prevent double-signing for most duty types.
|
|
113
|
+
* AUTH_REQUEST and TXS duties bypass HA protection since signing multiple times is safe.
|
|
114
|
+
* @throws DutyAlreadySignedError if the duty was already signed by another node
|
|
115
|
+
* @throws SlashingProtectionError if attempting to sign different data for the same slot
|
|
116
|
+
*/ async signTypedDataWithAddress(address, typedData, context) {
|
|
117
|
+
// AUTH_REQUEST and TXS bypass HA protection - multiple signatures are safe
|
|
118
|
+
if (!isHAProtectedContext(context)) {
|
|
119
|
+
return this.baseKeyStore.signTypedDataWithAddress(address, typedData, context);
|
|
120
|
+
}
|
|
121
|
+
// Compute signing root from typed data for HA tracking
|
|
122
|
+
const digest = hashTypedData(typedData);
|
|
123
|
+
const messageHash = Buffer32.fromString(digest);
|
|
124
|
+
try {
|
|
125
|
+
return await this.haSigner.signWithProtection(address, messageHash, context, ()=>this.baseKeyStore.signTypedDataWithAddress(address, typedData, context));
|
|
126
|
+
} catch (error) {
|
|
127
|
+
this.processSigningError(error, context);
|
|
128
|
+
throw error;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Sign a message with a specific address.
|
|
133
|
+
* Coordinates across nodes to prevent double-signing for most duty types.
|
|
134
|
+
* AUTH_REQUEST and TXS duties bypass HA protection since signing multiple times is safe.
|
|
135
|
+
* @throws DutyAlreadySignedError if the duty was already signed by another node
|
|
136
|
+
* @throws SlashingProtectionError if attempting to sign different data for the same slot
|
|
137
|
+
*/ async signMessageWithAddress(address, message, context) {
|
|
138
|
+
// no need for HA protection on auth request and txs signatures
|
|
139
|
+
if (!isHAProtectedContext(context)) {
|
|
140
|
+
return this.baseKeyStore.signMessageWithAddress(address, message, context);
|
|
141
|
+
}
|
|
142
|
+
try {
|
|
143
|
+
return await this.haSigner.signWithProtection(address, message, context, (messageHash)=>this.baseKeyStore.signMessageWithAddress(address, messageHash, context));
|
|
144
|
+
} catch (error) {
|
|
145
|
+
this.processSigningError(error, context);
|
|
146
|
+
throw error;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
150
|
+
// pass-through methods (no HA logic needed)
|
|
151
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
152
|
+
getAddress(index) {
|
|
153
|
+
return this.baseKeyStore.getAddress(index);
|
|
154
|
+
}
|
|
155
|
+
getAddresses() {
|
|
156
|
+
return this.baseKeyStore.getAddresses();
|
|
157
|
+
}
|
|
158
|
+
getAttesterAddresses() {
|
|
159
|
+
return this.baseKeyStore.getAttesterAddresses();
|
|
160
|
+
}
|
|
161
|
+
getCoinbaseAddress(attesterAddress) {
|
|
162
|
+
return this.baseKeyStore.getCoinbaseAddress(attesterAddress);
|
|
163
|
+
}
|
|
164
|
+
getPublisherAddresses(attesterAddress) {
|
|
165
|
+
return this.baseKeyStore.getPublisherAddresses(attesterAddress);
|
|
166
|
+
}
|
|
167
|
+
getFeeRecipient(attesterAddress) {
|
|
168
|
+
return this.baseKeyStore.getFeeRecipient(attesterAddress);
|
|
169
|
+
}
|
|
170
|
+
getRemoteSignerConfig(attesterAddress) {
|
|
171
|
+
return this.baseKeyStore.getRemoteSignerConfig(attesterAddress);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Process signing errors from the HA signer.
|
|
175
|
+
* Logs expected HA errors (already signed) at appropriate levels.
|
|
176
|
+
* Re-throws unexpected errors.
|
|
177
|
+
*/ processSigningError(error, context) {
|
|
178
|
+
if (error instanceof DutyAlreadySignedError) {
|
|
179
|
+
this.log.debug(`Duty already signed by another node with the same payload`, {
|
|
180
|
+
dutyType: context.dutyType,
|
|
181
|
+
slot: context.slot,
|
|
182
|
+
signedByNode: error.signedByNode
|
|
183
|
+
});
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
if (error instanceof SlashingProtectionError) {
|
|
187
|
+
this.log.warn(`Duty already signed by another node with different payload`, {
|
|
188
|
+
dutyType: context.dutyType,
|
|
189
|
+
slot: context.slot,
|
|
190
|
+
existingMessageHash: error.existingMessageHash,
|
|
191
|
+
attemptedMessageHash: error.attemptedMessageHash
|
|
192
|
+
});
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
// Re-throw errors
|
|
196
|
+
throw error;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Start the high-availability key store
|
|
200
|
+
*/ start() {
|
|
201
|
+
return Promise.resolve(this.haSigner.start());
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Stop the high-availability key store
|
|
205
|
+
*/ async stop() {
|
|
206
|
+
await this.haSigner.stop();
|
|
207
|
+
}
|
|
208
|
+
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
export * from './interface.js';
|
|
2
2
|
export * from './local_key_store.js';
|
|
3
|
-
|
|
3
|
+
export * from './node_keystore_adapter.js';
|
|
4
|
+
export * from './web3signer_key_store.js';
|
|
5
|
+
export * from './ha_key_store.js';
|
|
6
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9rZXlfc3RvcmUvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsY0FBYyxnQkFBZ0IsQ0FBQztBQUMvQixjQUFjLHNCQUFzQixDQUFDO0FBQ3JDLGNBQWMsNEJBQTRCLENBQUM7QUFDM0MsY0FBYywyQkFBMkIsQ0FBQztBQUMxQyxjQUFjLG1CQUFtQixDQUFDIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/key_store/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/key_store/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mBAAmB,CAAC"}
|
package/dest/key_store/index.js
CHANGED
|
@@ -1,25 +1,104 @@
|
|
|
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
|
+
import type { SigningContext } from '@aztec/validator-ha-signer/types';
|
|
7
|
+
import type { TypedDataDefinition } from 'viem';
|
|
4
8
|
/** Key Store
|
|
5
9
|
*
|
|
6
10
|
* A keystore interface that can be replaced with a local keystore / remote signer service
|
|
7
11
|
*/
|
|
8
12
|
export interface ValidatorKeyStore {
|
|
9
13
|
/**
|
|
10
|
-
* Get the address of
|
|
14
|
+
* Get the address of a signer by index
|
|
11
15
|
*
|
|
16
|
+
* @param index - The index of the signer
|
|
12
17
|
* @returns the address
|
|
13
18
|
*/
|
|
14
|
-
getAddress(): EthAddress;
|
|
15
|
-
|
|
19
|
+
getAddress(index: number): EthAddress;
|
|
20
|
+
/**
|
|
21
|
+
* Get all addresses
|
|
22
|
+
*
|
|
23
|
+
* @returns all addresses
|
|
24
|
+
*/
|
|
25
|
+
getAddresses(): EthAddress[];
|
|
26
|
+
/**
|
|
27
|
+
* Sign typed data with all keystore private keys
|
|
28
|
+
* @param typedData - The complete EIP-712 typed data structure
|
|
29
|
+
* @param context - Signing context for HA slashing protection
|
|
30
|
+
* @returns signatures (when context provided with HA, only successfully claimed signatures are returned)
|
|
31
|
+
*/
|
|
32
|
+
signTypedData(typedData: TypedDataDefinition, context: SigningContext): Promise<Signature[]>;
|
|
33
|
+
/**
|
|
34
|
+
* Sign typed data with a specific address's private key
|
|
35
|
+
* @param address - The address of the signer to use
|
|
36
|
+
* @param typedData - The complete EIP-712 typed data structure
|
|
37
|
+
* @param context - Signing context for HA slashing protection
|
|
38
|
+
* @returns signature
|
|
39
|
+
*/
|
|
40
|
+
signTypedDataWithAddress(address: EthAddress, typedData: TypedDataDefinition, context: SigningContext): Promise<Signature>;
|
|
16
41
|
/**
|
|
17
42
|
* Flavor of sign message that followed EIP-712 eth signed message prefix
|
|
18
43
|
* Note: this is only required when we are using ecdsa signatures over secp256k1
|
|
19
44
|
*
|
|
20
45
|
* @param message - The message to sign.
|
|
21
|
-
* @
|
|
46
|
+
* @param context - Signing context for HA slashing protection
|
|
47
|
+
* @returns The signatures (when context provided with HA, only successfully claimed signatures are returned).
|
|
48
|
+
*/
|
|
49
|
+
signMessage(message: Buffer32, context: SigningContext): Promise<Signature[]>;
|
|
50
|
+
/**
|
|
51
|
+
* Sign a message with a specific address's private key
|
|
52
|
+
* @param address - The address of the signer to use
|
|
53
|
+
* @param message - The message to sign
|
|
54
|
+
* @param context - Signing context for HA slashing protection
|
|
55
|
+
* @returns signature
|
|
56
|
+
*/
|
|
57
|
+
signMessageWithAddress(address: EthAddress, message: Buffer32, context: SigningContext): Promise<Signature>;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Extended ValidatorKeyStore interface that supports the new keystore configuration model
|
|
61
|
+
* with role-based address management (attester, coinbase, publisher, fee recipient)
|
|
62
|
+
*/
|
|
63
|
+
export interface ExtendedValidatorKeyStore extends ValidatorKeyStore {
|
|
64
|
+
/**
|
|
65
|
+
* Get all attester addresses (maps to existing getAddresses())
|
|
66
|
+
* @returns all attester addresses
|
|
67
|
+
*/
|
|
68
|
+
getAttesterAddresses(): EthAddress[];
|
|
69
|
+
/**
|
|
70
|
+
* Get the coinbase address for a specific attester
|
|
71
|
+
* Falls back to the attester address if not set
|
|
72
|
+
* @param attesterAddress - The attester address to find the coinbase for
|
|
73
|
+
* @returns the coinbase address
|
|
74
|
+
*/
|
|
75
|
+
getCoinbaseAddress(attesterAddress: EthAddress): EthAddress;
|
|
76
|
+
/**
|
|
77
|
+
* Get all publisher addresses for a specific attester (EOAs used for sending block proposal L1 txs)
|
|
78
|
+
* Falls back to the attester addresses if not set
|
|
79
|
+
* @param attesterAddress - The attester address to find the publishers for
|
|
80
|
+
* @returns all publisher addresses for this validator
|
|
81
|
+
*/
|
|
82
|
+
getPublisherAddresses(attesterAddress: EthAddress): EthAddress[];
|
|
83
|
+
/**
|
|
84
|
+
* Get the fee recipient address for a specific attester
|
|
85
|
+
* @param attesterAddress - The attester address to find the fee recipient for
|
|
86
|
+
* @returns the fee recipient address
|
|
87
|
+
*/
|
|
88
|
+
getFeeRecipient(attesterAddress: EthAddress): AztecAddress;
|
|
89
|
+
/**
|
|
90
|
+
* Get the remote signer configuration for a specific attester if available
|
|
91
|
+
* @param attesterAddress - The attester address to find the remote signer config for
|
|
92
|
+
* @returns the remote signer configuration or undefined
|
|
93
|
+
*/
|
|
94
|
+
getRemoteSignerConfig(attesterAddress: EthAddress): EthRemoteSignerConfig | undefined;
|
|
95
|
+
/**
|
|
96
|
+
* Start the key store
|
|
97
|
+
*/
|
|
98
|
+
start(): Promise<void>;
|
|
99
|
+
/**
|
|
100
|
+
* Stop the key store
|
|
22
101
|
*/
|
|
23
|
-
|
|
102
|
+
stop(): Promise<void>;
|
|
24
103
|
}
|
|
25
|
-
//# sourceMappingURL=
|
|
104
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW50ZXJmYWNlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMva2V5X3N0b3JlL2ludGVyZmFjZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxRQUFR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BAAoB,IAAI,UAAU,EAAE,CAAC;IAErC;;;;;OAKG;IACH,kBAAkB,CAAC,eAAe,EAAE,UAAU,GAAG,UAAU,CAAC;IAE5D;;;;;OAKG;IACH,qBAAqB,CAAC,eAAe,EAAE,UAAU,GAAG,UAAU,EAAE,CAAC;IAEjE;;;;OAIG;IACH,eAAe,CAAC,eAAe,EAAE,UAAU,GAAG,YAAY,CAAC;IAE3D;;;;OAIG;IACH,qBAAqB,CAAC,eAAe,EAAE,UAAU,GAAG,qBAAqB,GAAG,SAAS,CAAC;IAEtF;;OAEG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvB;;OAEG;IACH,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACvB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
1
|
+
/**
|
|
2
|
+
* Extended ValidatorKeyStore interface that supports the new keystore configuration model
|
|
3
|
+
* with role-based address management (attester, coinbase, publisher, fee recipient)
|
|
4
4
|
*/ export { };
|
|
@@ -1,28 +1,63 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { 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 { SigningContext } from '@aztec/validator-ha-signer/types';
|
|
5
|
+
import { type TypedDataDefinition } from 'viem';
|
|
4
6
|
import type { ValidatorKeyStore } from './interface.js';
|
|
5
7
|
/**
|
|
6
8
|
* Local Key Store
|
|
7
9
|
*
|
|
8
|
-
* An implementation of the Key store using
|
|
10
|
+
* An implementation of the Key store using in memory private keys.
|
|
9
11
|
*/
|
|
10
12
|
export declare class LocalKeyStore implements ValidatorKeyStore {
|
|
11
|
-
private
|
|
12
|
-
|
|
13
|
+
private signers;
|
|
14
|
+
private signersByAddress;
|
|
15
|
+
constructor(privateKeys: Buffer32[]);
|
|
13
16
|
/**
|
|
14
|
-
* Get the address of
|
|
17
|
+
* Get the address of a signer by index
|
|
15
18
|
*
|
|
19
|
+
* @param index - The index of the signer
|
|
16
20
|
* @returns the address
|
|
17
21
|
*/
|
|
18
|
-
getAddress(): EthAddress;
|
|
22
|
+
getAddress(index: number): EthAddress;
|
|
19
23
|
/**
|
|
20
|
-
*
|
|
24
|
+
* Get the addresses of all signers
|
|
21
25
|
*
|
|
22
|
-
* @
|
|
26
|
+
* @returns the addresses
|
|
27
|
+
*/
|
|
28
|
+
getAddresses(): EthAddress[];
|
|
29
|
+
/**
|
|
30
|
+
* Sign a message with all keystore private keys
|
|
31
|
+
* @param typedData - The complete EIP-712 typed data structure (domain, types, primaryType, message)
|
|
32
|
+
* @param _context - Signing context (ignored by LocalKeyStore, used for HA protection)
|
|
23
33
|
* @return signature
|
|
24
34
|
*/
|
|
25
|
-
|
|
26
|
-
|
|
35
|
+
signTypedData(typedData: TypedDataDefinition, _context: SigningContext): Promise<Signature[]>;
|
|
36
|
+
/**
|
|
37
|
+
* Sign a message with a specific address's private key
|
|
38
|
+
* @param address - The address of the signer to use
|
|
39
|
+
* @param typedData - The complete EIP-712 typed data structure (domain, types, primaryType, message)
|
|
40
|
+
* @param _context - Signing context (ignored by LocalKeyStore, used for HA protection)
|
|
41
|
+
* @returns signature for the specified address
|
|
42
|
+
* @throws Error if the address is not found in the keystore
|
|
43
|
+
*/
|
|
44
|
+
signTypedDataWithAddress(address: EthAddress, typedData: TypedDataDefinition, _context: SigningContext): Promise<Signature>;
|
|
45
|
+
/**
|
|
46
|
+
* Sign a message using eth_sign with all keystore private keys
|
|
47
|
+
*
|
|
48
|
+
* @param message - The message to sign
|
|
49
|
+
* @param _context - Signing context (ignored by LocalKeyStore, used for HA protection)
|
|
50
|
+
* @return signatures
|
|
51
|
+
*/
|
|
52
|
+
signMessage(message: Buffer32, _context: SigningContext): Promise<Signature[]>;
|
|
53
|
+
/**
|
|
54
|
+
* Sign a message using eth_sign with a specific address's private key
|
|
55
|
+
* @param address - The address of the signer to use
|
|
56
|
+
* @param message - The message to sign
|
|
57
|
+
* @param _context - Signing context (ignored by LocalKeyStore, used for HA protection)
|
|
58
|
+
* @returns signature for the specified address
|
|
59
|
+
* @throws Error if the address is not found in the keystore
|
|
60
|
+
*/
|
|
61
|
+
signMessageWithAddress(address: EthAddress, message: Buffer32, _context: SigningContext): Promise<Signature>;
|
|
27
62
|
}
|
|
28
|
-
//# sourceMappingURL=
|
|
63
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibG9jYWxfa2V5X3N0b3JlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMva2V5X3N0b3JlL2xvY2FsX2tleV9zdG9yZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsUUFBUSxFQUFFLE1BQU0sMEJBQTBCLENBQUM7QUFFcEQsT0FBTyxLQUFLLEVBQUUsVUFBVSxFQUFFLE1BQU0sK0JBQStCLENBQUM7QUFDaEUsT0FBTyxLQUFLLEVBQUUsU0FBUyxFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFDakUsT0FBTyxLQUFLLEVBQUUsY0FBYyxFQUFFLE1BQU0sa0NBQWtDLENBQUM7QUFFdkUsT0FBTyxFQUFFLEtBQUssbUJBQW1CLEVBQWlCLE1BQU0sTUFBTSxDQUFDO0FBRS9ELE9BQU8sS0FBSyxFQUFFLGlCQUFpQixFQUFFLE1BQU0sZ0JBQWdCLENBQUM7QUFFeEQ7Ozs7R0FJRztBQUNILHFCQUFhLGFBQWMsWUFBVyxpQkFBaUI7SUFDckQsT0FBTyxDQUFDLE9BQU8sQ0FBb0I7SUFDbkMsT0FBTyxDQUFDLGdCQUFnQixDQUFzQztJQUU5RCxZQUFZLFdBQVcsRUFBRSxRQUFRLEVBQUUsRUFHbEM7SUFFRDs7Ozs7T0FLRztJQUNJLFVBQVUsQ0FBQyxLQUFLLEVBQUUsTUFBTSxHQUFHLFVBQVUsQ0FLM0M7SUFFRDs7OztPQUlHO0lBQ0ksWUFBWSxJQUFJLFVBQVUsRUFBRSxDQUVsQztJQUVEOzs7OztPQUtHO0lBQ0ksYUFBYSxDQUFDLFNBQVMsRUFBRSxtQkFBbUIsRUFBRSxRQUFRLEVBQUUsY0FBYyxHQUFHLE9BQU8sQ0FBQyxTQUFTLEVBQUUsQ0FBQyxDQUduRztJQUVEOzs7Ozs7O09BT0c7SUFDSSx3QkFBd0IsQ0FDN0IsT0FBTyxFQUFFLFVBQVUsRUFDbkIsU0FBUyxFQUFFLG1CQUFtQixFQUM5QixRQUFRLEVBQUUsY0FBYyxHQUN2QixPQUFPLENBQUMsU0FBUyxDQUFDLENBT3BCO0lBRUQ7Ozs7OztPQU1HO0lBQ0ksV0FBVyxDQUFDLE9BQU8sRUFBRSxRQUFRLEVBQUUsUUFBUSxFQUFFLGNBQWMsR0FBRyxPQUFPLENBQUMsU0FBUyxFQUFFLENBQUMsQ0FFcEY7SUFFRDs7Ozs7OztPQU9HO0lBQ0ksc0JBQXNCLENBQUMsT0FBTyxFQUFFLFVBQVUsRUFBRSxPQUFPLEVBQUUsUUFBUSxFQUFFLFFBQVEsRUFBRSxjQUFjLEdBQUcsT0FBTyxDQUFDLFNBQVMsQ0FBQyxDQU1sSDtDQUNGIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local_key_store.d.ts","sourceRoot":"","sources":["../../src/key_store/local_key_store.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"local_key_store.d.ts","sourceRoot":"","sources":["../../src/key_store/local_key_store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAEvE,OAAO,EAAE,KAAK,mBAAmB,EAAiB,MAAM,MAAM,CAAC;AAE/D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAExD;;;;GAIG;AACH,qBAAa,aAAc,YAAW,iBAAiB;IACrD,OAAO,CAAC,OAAO,CAAoB;IACnC,OAAO,CAAC,gBAAgB,CAAsC;IAE9D,YAAY,WAAW,EAAE,QAAQ,EAAE,EAGlC;IAED;;;;;OAKG;IACI,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAK3C;IAED;;;;OAIG;IACI,YAAY,IAAI,UAAU,EAAE,CAElC;IAED;;;;;OAKG;IACI,aAAa,CAAC,SAAS,EAAE,mBAAmB,EAAE,QAAQ,EAAE,cAAc,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,CAGnG;IAED;;;;;;;OAOG;IACI,wBAAwB,CAC7B,OAAO,EAAE,UAAU,EACnB,SAAS,EAAE,mBAAmB,EAC9B,QAAQ,EAAE,cAAc,GACvB,OAAO,CAAC,SAAS,CAAC,CAOpB;IAED;;;;;;OAMG;IACI,WAAW,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,cAAc,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,CAEpF;IAED;;;;;;;OAOG;IACI,sBAAsB,CAAC,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,cAAc,GAAG,OAAO,CAAC,SAAS,CAAC,CAMlH;CACF"}
|
|
@@ -1,32 +1,83 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
2
|
+
import { Secp256k1Signer } from '@aztec/foundation/crypto/secp256k1-signer';
|
|
3
|
+
import { hashTypedData } from 'viem';
|
|
2
4
|
/**
|
|
3
5
|
* Local Key Store
|
|
4
6
|
*
|
|
5
|
-
* An implementation of the Key store using
|
|
7
|
+
* An implementation of the Key store using in memory private keys.
|
|
6
8
|
*/ export class LocalKeyStore {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
signers;
|
|
10
|
+
signersByAddress;
|
|
11
|
+
constructor(privateKeys){
|
|
12
|
+
this.signers = privateKeys.map((privateKey)=>new Secp256k1Signer(privateKey));
|
|
13
|
+
this.signersByAddress = new Map(this.signers.map((signer)=>[
|
|
14
|
+
signer.address.toString(),
|
|
15
|
+
signer
|
|
16
|
+
]));
|
|
10
17
|
}
|
|
11
18
|
/**
|
|
12
|
-
* Get the address of
|
|
19
|
+
* Get the address of a signer by index
|
|
13
20
|
*
|
|
21
|
+
* @param index - The index of the signer
|
|
14
22
|
* @returns the address
|
|
15
|
-
*/ getAddress() {
|
|
16
|
-
|
|
23
|
+
*/ getAddress(index) {
|
|
24
|
+
if (index >= this.signers.length) {
|
|
25
|
+
throw new Error(`Index ${index} is out of bounds.`);
|
|
26
|
+
}
|
|
27
|
+
return this.signers[index].address;
|
|
17
28
|
}
|
|
18
29
|
/**
|
|
19
|
-
*
|
|
30
|
+
* Get the addresses of all signers
|
|
20
31
|
*
|
|
21
|
-
* @
|
|
32
|
+
* @returns the addresses
|
|
33
|
+
*/ getAddresses() {
|
|
34
|
+
return this.signers.map((signer)=>signer.address);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Sign a message with all keystore private keys
|
|
38
|
+
* @param typedData - The complete EIP-712 typed data structure (domain, types, primaryType, message)
|
|
39
|
+
* @param _context - Signing context (ignored by LocalKeyStore, used for HA protection)
|
|
22
40
|
* @return signature
|
|
23
|
-
*/
|
|
24
|
-
const
|
|
25
|
-
return Promise.
|
|
41
|
+
*/ signTypedData(typedData, _context) {
|
|
42
|
+
const digest = hashTypedData(typedData);
|
|
43
|
+
return Promise.all(this.signers.map((signer)=>signer.sign(Buffer32.fromString(digest))));
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Sign a message with a specific address's private key
|
|
47
|
+
* @param address - The address of the signer to use
|
|
48
|
+
* @param typedData - The complete EIP-712 typed data structure (domain, types, primaryType, message)
|
|
49
|
+
* @param _context - Signing context (ignored by LocalKeyStore, used for HA protection)
|
|
50
|
+
* @returns signature for the specified address
|
|
51
|
+
* @throws Error if the address is not found in the keystore
|
|
52
|
+
*/ signTypedDataWithAddress(address, typedData, _context) {
|
|
53
|
+
const signer = this.signersByAddress.get(address.toString());
|
|
54
|
+
if (!signer) {
|
|
55
|
+
throw new Error(`No signer found for address ${address.toString()}`);
|
|
56
|
+
}
|
|
57
|
+
const digest = hashTypedData(typedData);
|
|
58
|
+
return Promise.resolve(signer.sign(Buffer32.fromString(digest)));
|
|
26
59
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
60
|
+
/**
|
|
61
|
+
* Sign a message using eth_sign with all keystore private keys
|
|
62
|
+
*
|
|
63
|
+
* @param message - The message to sign
|
|
64
|
+
* @param _context - Signing context (ignored by LocalKeyStore, used for HA protection)
|
|
65
|
+
* @return signatures
|
|
66
|
+
*/ signMessage(message, _context) {
|
|
67
|
+
return Promise.all(this.signers.map((signer)=>signer.signMessage(message)));
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Sign a message using eth_sign with a specific address's private key
|
|
71
|
+
* @param address - The address of the signer to use
|
|
72
|
+
* @param message - The message to sign
|
|
73
|
+
* @param _context - Signing context (ignored by LocalKeyStore, used for HA protection)
|
|
74
|
+
* @returns signature for the specified address
|
|
75
|
+
* @throws Error if the address is not found in the keystore
|
|
76
|
+
*/ signMessageWithAddress(address, message, _context) {
|
|
77
|
+
const signer = this.signersByAddress.get(address.toString());
|
|
78
|
+
if (!signer) {
|
|
79
|
+
throw new Error(`No signer found for address ${address.toString()}`);
|
|
80
|
+
}
|
|
81
|
+
return Promise.resolve(signer.signMessage(message));
|
|
31
82
|
}
|
|
32
83
|
}
|