@aztec/node-keystore 2.0.0-nightly.20250816
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/index.d.ts +6 -0
- package/dest/index.d.ts.map +1 -0
- package/dest/index.js +5 -0
- package/dest/keystore_manager.d.ts +123 -0
- package/dest/keystore_manager.d.ts.map +1 -0
- package/dest/keystore_manager.js +511 -0
- package/dest/loader.d.ts +62 -0
- package/dest/loader.d.ts.map +1 -0
- package/dest/loader.js +255 -0
- package/dest/schemas.d.ts +965 -0
- package/dest/schemas.d.ts.map +1 -0
- package/dest/schemas.js +83 -0
- package/dest/signer.d.ts +85 -0
- package/dest/signer.d.ts.map +1 -0
- package/dest/signer.js +148 -0
- package/dest/types.d.ts +98 -0
- package/dest/types.d.ts.map +1 -0
- package/dest/types.js +7 -0
- package/package.json +89 -0
- package/src/index.ts +5 -0
- package/src/keystore_manager.ts +646 -0
- package/src/loader.ts +301 -0
- package/src/schemas.ts +91 -0
- package/src/signer.ts +227 -0
- package/src/types.ts +112 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../src/schemas.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAuExB,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAWvB,CAAC;AAEL,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC"}
|
package/dest/schemas.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod schemas for keystore validation using Aztec's validation functions
|
|
3
|
+
*/ import { EthAddress } from '@aztec/foundation/eth-address';
|
|
4
|
+
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
// Use Aztec's validation functions but return string types to match our TypeScript interfaces
|
|
7
|
+
const ethAddressSchema = z.string().refine(EthAddress.isAddress, 'Invalid Ethereum address');
|
|
8
|
+
const ethPrivateKeySchema = z.string().regex(/^0x[0-9a-fA-F]{64}$/, 'Invalid private key (must be 32 bytes with 0x prefix)');
|
|
9
|
+
const aztecAddressSchema = z.string().refine(AztecAddress.isAddress, 'Invalid Aztec address');
|
|
10
|
+
const urlSchema = z.string().url('Invalid URL');
|
|
11
|
+
// Remote signer config schema
|
|
12
|
+
const remoteSignerConfigSchema = z.union([
|
|
13
|
+
urlSchema,
|
|
14
|
+
z.object({
|
|
15
|
+
remoteSignerUrl: urlSchema,
|
|
16
|
+
certPath: z.string().optional(),
|
|
17
|
+
certPass: z.string().optional()
|
|
18
|
+
})
|
|
19
|
+
]);
|
|
20
|
+
// Remote signer account schema
|
|
21
|
+
const remoteSignerAccountSchema = z.union([
|
|
22
|
+
ethAddressSchema,
|
|
23
|
+
z.object({
|
|
24
|
+
address: ethAddressSchema,
|
|
25
|
+
remoteSignerUrl: urlSchema.optional(),
|
|
26
|
+
certPath: z.string().optional(),
|
|
27
|
+
certPass: z.string().optional()
|
|
28
|
+
})
|
|
29
|
+
]);
|
|
30
|
+
// JSON V3 keystore schema
|
|
31
|
+
const jsonKeyFileV3Schema = z.object({
|
|
32
|
+
path: z.string(),
|
|
33
|
+
password: z.string().optional()
|
|
34
|
+
});
|
|
35
|
+
// Mnemonic config schema
|
|
36
|
+
const mnemonicConfigSchema = z.object({
|
|
37
|
+
mnemonic: z.string().min(1, 'Mnemonic cannot be empty'),
|
|
38
|
+
addressIndex: z.number().int().min(0).optional(),
|
|
39
|
+
accountIndex: z.number().int().min(0).optional(),
|
|
40
|
+
addressCount: z.number().int().min(1).optional(),
|
|
41
|
+
accountCount: z.number().int().min(1).optional()
|
|
42
|
+
});
|
|
43
|
+
// EthAccount schema
|
|
44
|
+
const ethAccountSchema = z.union([
|
|
45
|
+
ethPrivateKeySchema,
|
|
46
|
+
remoteSignerAccountSchema,
|
|
47
|
+
jsonKeyFileV3Schema
|
|
48
|
+
]);
|
|
49
|
+
// EthAccounts schema
|
|
50
|
+
const ethAccountsSchema = z.union([
|
|
51
|
+
ethAccountSchema,
|
|
52
|
+
z.array(ethAccountSchema),
|
|
53
|
+
mnemonicConfigSchema
|
|
54
|
+
]);
|
|
55
|
+
// Prover keystore schema
|
|
56
|
+
const proverKeyStoreSchema = z.union([
|
|
57
|
+
ethAccountSchema,
|
|
58
|
+
z.object({
|
|
59
|
+
id: ethAddressSchema,
|
|
60
|
+
publisher: z.array(ethAccountsSchema)
|
|
61
|
+
})
|
|
62
|
+
]);
|
|
63
|
+
// Validator keystore schema
|
|
64
|
+
const validatorKeyStoreSchema = z.object({
|
|
65
|
+
attester: ethAccountsSchema,
|
|
66
|
+
coinbase: ethAddressSchema.optional(),
|
|
67
|
+
publisher: ethAccountsSchema.optional(),
|
|
68
|
+
feeRecipient: aztecAddressSchema,
|
|
69
|
+
remoteSigner: remoteSignerConfigSchema.optional()
|
|
70
|
+
});
|
|
71
|
+
// Main keystore schema
|
|
72
|
+
export const keystoreSchema = z.object({
|
|
73
|
+
schemaVersion: z.literal(1),
|
|
74
|
+
validators: z.array(validatorKeyStoreSchema).optional(),
|
|
75
|
+
slasher: ethAccountsSchema.optional(),
|
|
76
|
+
remoteSigner: remoteSignerConfigSchema.optional(),
|
|
77
|
+
prover: proverKeyStoreSchema.optional()
|
|
78
|
+
}).refine((data)=>data.validators || data.prover, {
|
|
79
|
+
message: 'Keystore must have at least validators or prover configuration',
|
|
80
|
+
path: [
|
|
81
|
+
'root'
|
|
82
|
+
]
|
|
83
|
+
});
|
package/dest/signer.d.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Signer Interface and Implementations
|
|
3
|
+
*
|
|
4
|
+
* Common interface for different signing backends (local, remote, encrypted)
|
|
5
|
+
*/
|
|
6
|
+
import { Buffer32 } from '@aztec/foundation/buffer';
|
|
7
|
+
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
8
|
+
import { Signature } from '@aztec/foundation/eth-signature';
|
|
9
|
+
import type { TypedDataDefinition } from 'viem';
|
|
10
|
+
import type { EthRemoteSignerConfig } from './types.js';
|
|
11
|
+
/**
|
|
12
|
+
* Error thrown for remote signer HTTP or JSON-RPC failures
|
|
13
|
+
*/
|
|
14
|
+
export declare class SignerError extends Error {
|
|
15
|
+
method: 'eth_sign' | 'eth_signTypedData_v4';
|
|
16
|
+
url: string;
|
|
17
|
+
statusCode?: number | undefined;
|
|
18
|
+
errorCode?: number | undefined;
|
|
19
|
+
constructor(message: string, method: 'eth_sign' | 'eth_signTypedData_v4', url: string, statusCode?: number | undefined, errorCode?: number | undefined);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Common interface for all signer implementations
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* Abstraction for signing operations used by the node keystore.
|
|
26
|
+
*/
|
|
27
|
+
export interface Signer {
|
|
28
|
+
/** The Ethereum address for this signer */
|
|
29
|
+
readonly address: EthAddress;
|
|
30
|
+
/** Sign a message using eth_sign (with Ethereum message prefix) */
|
|
31
|
+
signMessage(message: Buffer32): Promise<Signature>;
|
|
32
|
+
/** Sign typed data using EIP-712 */
|
|
33
|
+
signTypedData(typedData: TypedDataDefinition): Promise<Signature>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Local signer using in-memory private key
|
|
37
|
+
*/
|
|
38
|
+
/**
|
|
39
|
+
* Local signer that holds an in-memory Secp256k1 private key.
|
|
40
|
+
*/
|
|
41
|
+
export declare class LocalSigner implements Signer {
|
|
42
|
+
private readonly signer;
|
|
43
|
+
constructor(privateKey: Buffer32);
|
|
44
|
+
get address(): EthAddress;
|
|
45
|
+
signMessage(message: Buffer32): Promise<Signature>;
|
|
46
|
+
signTypedData(typedData: TypedDataDefinition): Promise<Signature>;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Remote signer using Web3Signer HTTP API
|
|
50
|
+
*/
|
|
51
|
+
/**
|
|
52
|
+
* Remote signer that proxies signing operations to a Web3Signer-compatible HTTP endpoint.
|
|
53
|
+
*/
|
|
54
|
+
export declare class RemoteSigner implements Signer {
|
|
55
|
+
readonly address: EthAddress;
|
|
56
|
+
private readonly config;
|
|
57
|
+
constructor(address: EthAddress, config: EthRemoteSignerConfig);
|
|
58
|
+
/**
|
|
59
|
+
* Sign a message using eth_sign via remote JSON-RPC.
|
|
60
|
+
*/
|
|
61
|
+
signMessage(message: Buffer32): Promise<Signature>;
|
|
62
|
+
/**
|
|
63
|
+
* Sign typed data using eth_signTypedData_v4 via remote JSON-RPC.
|
|
64
|
+
*/
|
|
65
|
+
signTypedData(typedData: TypedDataDefinition): Promise<Signature>;
|
|
66
|
+
/**
|
|
67
|
+
* Make a JSON-RPC sign request using eth_sign
|
|
68
|
+
*/
|
|
69
|
+
/**
|
|
70
|
+
* Make a JSON-RPC eth_sign request.
|
|
71
|
+
*/
|
|
72
|
+
private makeJsonRpcSignRequest;
|
|
73
|
+
/**
|
|
74
|
+
* Make a JSON-RPC sign typed data request using eth_signTypedData_v4
|
|
75
|
+
*/
|
|
76
|
+
/**
|
|
77
|
+
* Make a JSON-RPC eth_signTypedData_v4 request.
|
|
78
|
+
*/
|
|
79
|
+
private makeJsonRpcSignTypedDataRequest;
|
|
80
|
+
/**
|
|
81
|
+
* Resolve the effective remote signer URL from config.
|
|
82
|
+
*/
|
|
83
|
+
private getSignerUrl;
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=signer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signer.d.ts","sourceRoot":"","sources":["../src/signer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAE5D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,MAAM,CAAC;AAGhD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY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mBAAmB,GAAG,OAAO,CAAC,SAAS,CAAC;IAIvE;;OAEG;IACH;;OAEG;YACW,sBAAsB;IAoDpC;;OAEG;IACH;;OAEG;YACW,+BAA+B;IAoD7C;;OAEG;IACH,OAAO,CAAC,YAAY;CAMrB"}
|
package/dest/signer.js
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Signer Interface and Implementations
|
|
3
|
+
*
|
|
4
|
+
* Common interface for different signing backends (local, remote, encrypted)
|
|
5
|
+
*/ import { Buffer32 } from '@aztec/foundation/buffer';
|
|
6
|
+
import { Secp256k1Signer } from '@aztec/foundation/crypto';
|
|
7
|
+
import { Signature } from '@aztec/foundation/eth-signature';
|
|
8
|
+
import { hashTypedData } from 'viem';
|
|
9
|
+
/**
|
|
10
|
+
* Error thrown for remote signer HTTP or JSON-RPC failures
|
|
11
|
+
*/ export class SignerError extends Error {
|
|
12
|
+
method;
|
|
13
|
+
url;
|
|
14
|
+
statusCode;
|
|
15
|
+
errorCode;
|
|
16
|
+
constructor(message, method, url, statusCode, errorCode){
|
|
17
|
+
super(message), this.method = method, this.url = url, this.statusCode = statusCode, this.errorCode = errorCode;
|
|
18
|
+
this.name = 'SignerError';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Local signer using in-memory private key
|
|
23
|
+
*/ /**
|
|
24
|
+
* Local signer that holds an in-memory Secp256k1 private key.
|
|
25
|
+
*/ export class LocalSigner {
|
|
26
|
+
signer;
|
|
27
|
+
constructor(privateKey){
|
|
28
|
+
this.signer = new Secp256k1Signer(privateKey);
|
|
29
|
+
}
|
|
30
|
+
get address() {
|
|
31
|
+
return this.signer.address;
|
|
32
|
+
}
|
|
33
|
+
signMessage(message) {
|
|
34
|
+
return Promise.resolve(this.signer.signMessage(message));
|
|
35
|
+
}
|
|
36
|
+
signTypedData(typedData) {
|
|
37
|
+
const digest = hashTypedData(typedData);
|
|
38
|
+
return Promise.resolve(this.signer.sign(Buffer32.fromString(digest)));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Remote signer using Web3Signer HTTP API
|
|
43
|
+
*/ /**
|
|
44
|
+
* Remote signer that proxies signing operations to a Web3Signer-compatible HTTP endpoint.
|
|
45
|
+
*/ export class RemoteSigner {
|
|
46
|
+
address;
|
|
47
|
+
config;
|
|
48
|
+
constructor(address, config){
|
|
49
|
+
this.address = address;
|
|
50
|
+
this.config = config;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Sign a message using eth_sign via remote JSON-RPC.
|
|
54
|
+
*/ async signMessage(message) {
|
|
55
|
+
return await this.makeJsonRpcSignRequest(message);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Sign typed data using eth_signTypedData_v4 via remote JSON-RPC.
|
|
59
|
+
*/ async signTypedData(typedData) {
|
|
60
|
+
return await this.makeJsonRpcSignTypedDataRequest(typedData);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Make a JSON-RPC sign request using eth_sign
|
|
64
|
+
*/ /**
|
|
65
|
+
* Make a JSON-RPC eth_sign request.
|
|
66
|
+
*/ async makeJsonRpcSignRequest(data) {
|
|
67
|
+
const url = this.getSignerUrl();
|
|
68
|
+
const body = {
|
|
69
|
+
jsonrpc: '2.0',
|
|
70
|
+
method: 'eth_sign',
|
|
71
|
+
params: [
|
|
72
|
+
this.address.toString(),
|
|
73
|
+
data.toString()
|
|
74
|
+
],
|
|
75
|
+
id: 1
|
|
76
|
+
};
|
|
77
|
+
const response = await fetch(url, {
|
|
78
|
+
method: 'POST',
|
|
79
|
+
headers: {
|
|
80
|
+
'Content-Type': 'application/json'
|
|
81
|
+
},
|
|
82
|
+
body: JSON.stringify(body)
|
|
83
|
+
});
|
|
84
|
+
if (!response.ok) {
|
|
85
|
+
const errorText = await response.text();
|
|
86
|
+
throw new SignerError(`Web3Signer request failed for eth_sign at ${url}: ${response.status} ${response.statusText} - ${errorText}`, 'eth_sign', url, response.status);
|
|
87
|
+
}
|
|
88
|
+
const result = await response.json();
|
|
89
|
+
if (result.error) {
|
|
90
|
+
throw new SignerError(`Web3Signer JSON-RPC error for eth_sign at ${url}: ${result.error.code} - ${result.error.message}`, 'eth_sign', url, undefined, result.error.code);
|
|
91
|
+
}
|
|
92
|
+
if (!result.result) {
|
|
93
|
+
throw new Error('Invalid response from Web3Signer: no result found');
|
|
94
|
+
}
|
|
95
|
+
let signatureHex = result.result;
|
|
96
|
+
if (!signatureHex.startsWith('0x')) {
|
|
97
|
+
signatureHex = '0x' + signatureHex;
|
|
98
|
+
}
|
|
99
|
+
return Signature.fromString(signatureHex);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Make a JSON-RPC sign typed data request using eth_signTypedData_v4
|
|
103
|
+
*/ /**
|
|
104
|
+
* Make a JSON-RPC eth_signTypedData_v4 request.
|
|
105
|
+
*/ async makeJsonRpcSignTypedDataRequest(typedData) {
|
|
106
|
+
const url = this.getSignerUrl();
|
|
107
|
+
const body = {
|
|
108
|
+
jsonrpc: '2.0',
|
|
109
|
+
method: 'eth_signTypedData_v4',
|
|
110
|
+
params: [
|
|
111
|
+
this.address.toString(),
|
|
112
|
+
typedData
|
|
113
|
+
],
|
|
114
|
+
id: 1
|
|
115
|
+
};
|
|
116
|
+
const response = await fetch(url, {
|
|
117
|
+
method: 'POST',
|
|
118
|
+
headers: {
|
|
119
|
+
'Content-Type': 'application/json'
|
|
120
|
+
},
|
|
121
|
+
body: JSON.stringify(body)
|
|
122
|
+
});
|
|
123
|
+
if (!response.ok) {
|
|
124
|
+
const errorText = await response.text();
|
|
125
|
+
throw new SignerError(`Web3Signer request failed for eth_signTypedData_v4 at ${url}: ${response.status} ${response.statusText} - ${errorText}`, 'eth_signTypedData_v4', url, response.status);
|
|
126
|
+
}
|
|
127
|
+
const result = await response.json();
|
|
128
|
+
if (result.error) {
|
|
129
|
+
throw new SignerError(`Web3Signer JSON-RPC error for eth_signTypedData_v4 at ${url}: ${result.error.code} - ${result.error.message}`, 'eth_signTypedData_v4', url, undefined, result.error.code);
|
|
130
|
+
}
|
|
131
|
+
if (!result.result) {
|
|
132
|
+
throw new Error('Invalid response from Web3Signer: no result found');
|
|
133
|
+
}
|
|
134
|
+
let signatureHex = result.result;
|
|
135
|
+
if (!signatureHex.startsWith('0x')) {
|
|
136
|
+
signatureHex = '0x' + signatureHex;
|
|
137
|
+
}
|
|
138
|
+
return Signature.fromString(signatureHex);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Resolve the effective remote signer URL from config.
|
|
142
|
+
*/ getSignerUrl() {
|
|
143
|
+
if (typeof this.config === 'string') {
|
|
144
|
+
return this.config;
|
|
145
|
+
}
|
|
146
|
+
return this.config.remoteSignerUrl;
|
|
147
|
+
}
|
|
148
|
+
}
|
package/dest/types.d.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keys and Addresses Configuration Types
|
|
3
|
+
*
|
|
4
|
+
* TypeScript definitions based on the specification for validator keystore files.
|
|
5
|
+
* These types define the JSON structure for configuring validators, provers, and
|
|
6
|
+
* their associated keys and addresses.
|
|
7
|
+
*/
|
|
8
|
+
/** Parameterized hex string type for specific byte lengths */
|
|
9
|
+
export type Hex<TByteLength extends number> = `0x${string}` & {
|
|
10
|
+
readonly _length: TByteLength;
|
|
11
|
+
};
|
|
12
|
+
/** 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 EthJsonKeyFileV3Config = {
|
|
14
|
+
path: string;
|
|
15
|
+
password?: string;
|
|
16
|
+
};
|
|
17
|
+
/** A private key is a 32-byte 0x-prefixed hex */
|
|
18
|
+
export type EthPrivateKey = Hex<32>;
|
|
19
|
+
/** An address is a 20-byte 0x-prefixed hex */
|
|
20
|
+
export type EthAddressHex = Hex<20>;
|
|
21
|
+
/** An Aztec address is a 32-byte 0x-prefixed hex */
|
|
22
|
+
export type AztecAddressHex = Hex<32>;
|
|
23
|
+
/** URL type for remote signers */
|
|
24
|
+
export type Url = string;
|
|
25
|
+
/**
|
|
26
|
+
* A remote signer is configured as an URL to connect to, and optionally a client certificate to use for auth
|
|
27
|
+
*/
|
|
28
|
+
export type EthRemoteSignerConfig = Url | {
|
|
29
|
+
remoteSignerUrl: Url;
|
|
30
|
+
certPath?: string;
|
|
31
|
+
certPass?: string;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* A remote signer account config is equal to the remote signer config, but requires an address to be specified.
|
|
35
|
+
* If only the address is set, then the default remote signer config from the parent config is used.
|
|
36
|
+
*/
|
|
37
|
+
export type EthRemoteSignerAccount = EthAddressHex | {
|
|
38
|
+
address: EthAddressHex;
|
|
39
|
+
remoteSignerUrl?: Url;
|
|
40
|
+
certPath?: string;
|
|
41
|
+
certPass?: string;
|
|
42
|
+
};
|
|
43
|
+
/** An L1 account is a private key, a remote signer configuration, or a standard json key store file */
|
|
44
|
+
export type EthAccount = EthPrivateKey | EthRemoteSignerAccount | EthJsonKeyFileV3Config;
|
|
45
|
+
/** A mnemonic can be used to define a set of accounts */
|
|
46
|
+
export type EthMnemonicConfig = {
|
|
47
|
+
mnemonic: string;
|
|
48
|
+
addressIndex?: number;
|
|
49
|
+
accountIndex?: number;
|
|
50
|
+
addressCount?: number;
|
|
51
|
+
accountCount?: number;
|
|
52
|
+
};
|
|
53
|
+
/** One or more L1 accounts */
|
|
54
|
+
export type EthAccounts = EthAccount | EthAccount[] | EthMnemonicConfig;
|
|
55
|
+
export type ProverKeyStore = {
|
|
56
|
+
/** Address that identifies the prover. This address will receive the rewards. */
|
|
57
|
+
id: EthAddressHex;
|
|
58
|
+
/** One or more EOAs used for sending proof L1 txs. */
|
|
59
|
+
publisher: EthAccounts[];
|
|
60
|
+
} | EthAccount;
|
|
61
|
+
export type ValidatorKeyStore = {
|
|
62
|
+
/**
|
|
63
|
+
* One or more validator attester keys to handle in this configuration block.
|
|
64
|
+
* An attester address may only appear once across all configuration blocks across all keystore files.
|
|
65
|
+
*/
|
|
66
|
+
attester: EthAccounts;
|
|
67
|
+
/**
|
|
68
|
+
* Coinbase address to use when proposing an L2 block as any of the validators in this configuration block.
|
|
69
|
+
* Falls back to the attester address if not set.
|
|
70
|
+
*/
|
|
71
|
+
coinbase?: EthAddressHex;
|
|
72
|
+
/**
|
|
73
|
+
* One or more EOAs used for sending block proposal L1 txs for all validators in this configuration block.
|
|
74
|
+
* Falls back to the attester account if not set.
|
|
75
|
+
*/
|
|
76
|
+
publisher?: EthAccounts;
|
|
77
|
+
/**
|
|
78
|
+
* Fee recipient address to use when proposing an L2 block as any of the validators in this configuration block.
|
|
79
|
+
*/
|
|
80
|
+
feeRecipient: AztecAddressHex;
|
|
81
|
+
/**
|
|
82
|
+
* Default remote signer for all accounts in this block.
|
|
83
|
+
*/
|
|
84
|
+
remoteSigner?: EthRemoteSignerConfig;
|
|
85
|
+
};
|
|
86
|
+
export type KeyStore = {
|
|
87
|
+
/** Schema version of this keystore file (initially 1). */
|
|
88
|
+
schemaVersion: number;
|
|
89
|
+
/** Validator configurations. */
|
|
90
|
+
validators?: ValidatorKeyStore[];
|
|
91
|
+
/** One or more accounts used for creating slash payloads on L1. Does not create slash payloads if not set. */
|
|
92
|
+
slasher?: EthAccounts;
|
|
93
|
+
/** Default config for the remote signer for all accounts in this file. */
|
|
94
|
+
remoteSigner?: EthRemoteSignerConfig;
|
|
95
|
+
/** Prover configuration. Only one prover configuration is allowed. */
|
|
96
|
+
prover?: ProverKeyStore;
|
|
97
|
+
};
|
|
98
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,8DAA8D;AAC9D,MAAM,MAAM,GAAG,CAAC,WAAW,SAAS,MAAM,IAAI,KAAK,MAAM,EAAE,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,WA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AExE,MAAM,MAAM,cAAc,GACtB;IACE,iFAAiF;IACjF,EAAE,EAAE,aAAa,CAAC;IAClB,sDAAsD;IACtD,SAAS,EAAE,WAAW,EAAE,CAAC;CAC1B,GACD,UAAU,CAAC;AAEf,MAAM,MAAM,iBAAiB,GAAG;IAC9B;;;OAGG;IACH,QAAQ,EAAE,WAAW,CAAC;IACtB;;;OAGG;IACH,QAAQ,CAAC,EAAE,aAAa,CAAC;IACzB;;;OAGG;IACH,SAAS,CAAC,EAAE,WAAW,CAAC;IACxB;;OAEG;IACH,YAAY,EAAE,eAAe,CAAC;IAC9B;;OAEG;IACH,YAAY,CAAC,EAAE,qBAAqB,CAAC;CACtC,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG;IACrB,0DAA0D;IAC1D,aAAa,EAAE,MAAM,CAAC;IACtB,gCAAgC;IAChC,UAAU,CAAC,EAAE,iBAAiB,EAAE,CAAC;IACjC,8GAA8G;IAC9G,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,0EAA0E;IAC1E,YAAY,CAAC,EAAE,qBAAqB,CAAC;IACrC,sEAAsE;IACtE,MAAM,CAAC,EAAE,cAAc,CAAC;CACzB,CAAC"}
|
package/dest/types.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keys and Addresses Configuration Types
|
|
3
|
+
*
|
|
4
|
+
* TypeScript definitions based on the specification for validator keystore files.
|
|
5
|
+
* These types define the JSON structure for configuring validators, provers, and
|
|
6
|
+
* their associated keys and addresses.
|
|
7
|
+
*/ /** Parameterized hex string type for specific byte lengths */ export { };
|
package/package.json
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aztec/node-keystore",
|
|
3
|
+
"version": "2.0.0-nightly.20250816",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": "./dest/index.js",
|
|
7
|
+
"./types": "./dest/types.js",
|
|
8
|
+
"./validation": "./dest/validation.js",
|
|
9
|
+
"./loader": "./dest/loader.js"
|
|
10
|
+
},
|
|
11
|
+
"typedocOptions": {
|
|
12
|
+
"entryPoints": [
|
|
13
|
+
"./src/index.ts"
|
|
14
|
+
],
|
|
15
|
+
"name": "Node Keystore",
|
|
16
|
+
"tsconfig": "./tsconfig.json"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "yarn clean && tsc -b",
|
|
20
|
+
"build:dev": "tsc -b --watch",
|
|
21
|
+
"clean": "rm -rf ./dest .tsbuildinfo",
|
|
22
|
+
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
|
|
23
|
+
},
|
|
24
|
+
"inherits": [
|
|
25
|
+
"../package.common.json"
|
|
26
|
+
],
|
|
27
|
+
"jest": {
|
|
28
|
+
"moduleNameMapper": {
|
|
29
|
+
"^(\\.{1,2}/.*)\\.[cm]?js$": "$1"
|
|
30
|
+
},
|
|
31
|
+
"testRegex": "./src/.*\\.test\\.(js|mjs|ts)$",
|
|
32
|
+
"rootDir": "./src",
|
|
33
|
+
"transform": {
|
|
34
|
+
"^.+\\.tsx?$": [
|
|
35
|
+
"@swc/jest",
|
|
36
|
+
{
|
|
37
|
+
"jsc": {
|
|
38
|
+
"parser": {
|
|
39
|
+
"syntax": "typescript",
|
|
40
|
+
"decorators": true
|
|
41
|
+
},
|
|
42
|
+
"transform": {
|
|
43
|
+
"decoratorVersion": "2022-03"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
},
|
|
49
|
+
"extensionsToTreatAsEsm": [
|
|
50
|
+
".ts"
|
|
51
|
+
],
|
|
52
|
+
"reporters": [
|
|
53
|
+
"default"
|
|
54
|
+
],
|
|
55
|
+
"testTimeout": 120000,
|
|
56
|
+
"setupFiles": [
|
|
57
|
+
"../../foundation/src/jest/setup.mjs"
|
|
58
|
+
],
|
|
59
|
+
"testEnvironment": "../../foundation/src/jest/env.mjs",
|
|
60
|
+
"setupFilesAfterEnv": [
|
|
61
|
+
"../../foundation/src/jest/setupAfterEnv.mjs"
|
|
62
|
+
]
|
|
63
|
+
},
|
|
64
|
+
"dependencies": {
|
|
65
|
+
"@aztec/foundation": "2.0.0-nightly.20250816",
|
|
66
|
+
"@aztec/stdlib": "2.0.0-nightly.20250816",
|
|
67
|
+
"@ethersproject/wallet": "^5.7.0",
|
|
68
|
+
"tslib": "^2.4.0",
|
|
69
|
+
"viem": "2.23.7",
|
|
70
|
+
"zod": "^3.23.8"
|
|
71
|
+
},
|
|
72
|
+
"devDependencies": {
|
|
73
|
+
"@jest/globals": "^30.0.0",
|
|
74
|
+
"@types/jest": "^30.0.0",
|
|
75
|
+
"@types/node": "^22.15.17",
|
|
76
|
+
"jest": "^30.0.0",
|
|
77
|
+
"ts-node": "^10.9.1",
|
|
78
|
+
"typescript": "^5.3.3"
|
|
79
|
+
},
|
|
80
|
+
"files": [
|
|
81
|
+
"dest",
|
|
82
|
+
"src",
|
|
83
|
+
"!*.test.*"
|
|
84
|
+
],
|
|
85
|
+
"types": "./dest/index.d.ts",
|
|
86
|
+
"engines": {
|
|
87
|
+
"node": ">=20.10"
|
|
88
|
+
}
|
|
89
|
+
}
|