@aztec/validator-ha-signer 0.0.1-commit.0208eb9

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.
Files changed (58) hide show
  1. package/README.md +187 -0
  2. package/dest/config.d.ts +101 -0
  3. package/dest/config.d.ts.map +1 -0
  4. package/dest/config.js +92 -0
  5. package/dest/db/index.d.ts +4 -0
  6. package/dest/db/index.d.ts.map +1 -0
  7. package/dest/db/index.js +3 -0
  8. package/dest/db/migrations/1_initial-schema.d.ts +9 -0
  9. package/dest/db/migrations/1_initial-schema.d.ts.map +1 -0
  10. package/dest/db/migrations/1_initial-schema.js +20 -0
  11. package/dest/db/postgres.d.ts +84 -0
  12. package/dest/db/postgres.d.ts.map +1 -0
  13. package/dest/db/postgres.js +210 -0
  14. package/dest/db/schema.d.ts +95 -0
  15. package/dest/db/schema.d.ts.map +1 -0
  16. package/dest/db/schema.js +229 -0
  17. package/dest/db/test_helper.d.ts +10 -0
  18. package/dest/db/test_helper.d.ts.map +1 -0
  19. package/dest/db/test_helper.js +14 -0
  20. package/dest/db/types.d.ts +166 -0
  21. package/dest/db/types.d.ts.map +1 -0
  22. package/dest/db/types.js +49 -0
  23. package/dest/errors.d.ts +34 -0
  24. package/dest/errors.d.ts.map +1 -0
  25. package/dest/errors.js +34 -0
  26. package/dest/factory.d.ts +42 -0
  27. package/dest/factory.d.ts.map +1 -0
  28. package/dest/factory.js +70 -0
  29. package/dest/migrations.d.ts +15 -0
  30. package/dest/migrations.d.ts.map +1 -0
  31. package/dest/migrations.js +53 -0
  32. package/dest/slashing_protection_service.d.ts +84 -0
  33. package/dest/slashing_protection_service.d.ts.map +1 -0
  34. package/dest/slashing_protection_service.js +225 -0
  35. package/dest/test/pglite_pool.d.ts +92 -0
  36. package/dest/test/pglite_pool.d.ts.map +1 -0
  37. package/dest/test/pglite_pool.js +210 -0
  38. package/dest/types.d.ts +152 -0
  39. package/dest/types.d.ts.map +1 -0
  40. package/dest/types.js +21 -0
  41. package/dest/validator_ha_signer.d.ts +71 -0
  42. package/dest/validator_ha_signer.d.ts.map +1 -0
  43. package/dest/validator_ha_signer.js +132 -0
  44. package/package.json +106 -0
  45. package/src/config.ts +149 -0
  46. package/src/db/index.ts +3 -0
  47. package/src/db/migrations/1_initial-schema.ts +26 -0
  48. package/src/db/postgres.ts +284 -0
  49. package/src/db/schema.ts +266 -0
  50. package/src/db/test_helper.ts +17 -0
  51. package/src/db/types.ts +206 -0
  52. package/src/errors.ts +47 -0
  53. package/src/factory.ts +82 -0
  54. package/src/migrations.ts +75 -0
  55. package/src/slashing_protection_service.ts +287 -0
  56. package/src/test/pglite_pool.ts +256 -0
  57. package/src/types.ts +226 -0
  58. package/src/validator_ha_signer.ts +162 -0
@@ -0,0 +1,166 @@
1
+ import type { BlockNumber, CheckpointNumber, IndexWithinCheckpoint, SlotNumber } from '@aztec/foundation/branded-types';
2
+ import type { EthAddress } from '@aztec/foundation/eth-address';
3
+ import type { Signature } from '@aztec/foundation/eth-signature';
4
+ /**
5
+ * Row type from PostgreSQL query
6
+ */
7
+ export interface DutyRow {
8
+ rollup_address: string;
9
+ validator_address: string;
10
+ slot: string;
11
+ block_number: string;
12
+ block_index_within_checkpoint: number;
13
+ duty_type: DutyType;
14
+ status: DutyStatus;
15
+ message_hash: string;
16
+ signature: string | null;
17
+ node_id: string;
18
+ lock_token: string;
19
+ started_at: Date;
20
+ completed_at: Date | null;
21
+ error_message: string | null;
22
+ }
23
+ /**
24
+ * Row type from INSERT_OR_GET_DUTY query (includes is_new flag)
25
+ */
26
+ export interface InsertOrGetRow extends DutyRow {
27
+ is_new: boolean;
28
+ }
29
+ /**
30
+ * Type of validator duty being performed
31
+ */
32
+ export declare enum DutyType {
33
+ BLOCK_PROPOSAL = "BLOCK_PROPOSAL",
34
+ CHECKPOINT_PROPOSAL = "CHECKPOINT_PROPOSAL",
35
+ ATTESTATION = "ATTESTATION",
36
+ ATTESTATIONS_AND_SIGNERS = "ATTESTATIONS_AND_SIGNERS",
37
+ GOVERNANCE_VOTE = "GOVERNANCE_VOTE",
38
+ SLASHING_VOTE = "SLASHING_VOTE",
39
+ AUTH_REQUEST = "AUTH_REQUEST",
40
+ TXS = "TXS"
41
+ }
42
+ /**
43
+ * Status of a duty in the database
44
+ */
45
+ export declare enum DutyStatus {
46
+ SIGNING = "signing",
47
+ SIGNED = "signed"
48
+ }
49
+ /**
50
+ * Record of a validator duty in the database
51
+ */
52
+ export interface ValidatorDutyRecord {
53
+ /** Ethereum address of the rollup contract */
54
+ rollupAddress: EthAddress;
55
+ /** Ethereum address of the validator */
56
+ validatorAddress: EthAddress;
57
+ /** Slot number for this duty */
58
+ slot: SlotNumber;
59
+ /** Block number for this duty */
60
+ blockNumber: BlockNumber;
61
+ /** Block index within checkpoint (0, 1, 2... for block proposals, -1 for other duty types) */
62
+ blockIndexWithinCheckpoint: number;
63
+ /** Type of duty being performed */
64
+ dutyType: DutyType;
65
+ /** Current status of the duty */
66
+ status: DutyStatus;
67
+ /** The signing root (hash) for this duty */
68
+ messageHash: string;
69
+ /** The signature (populated after successful signing) */
70
+ signature?: string;
71
+ /** Unique identifier for the node that acquired the lock */
72
+ nodeId: string;
73
+ /** Secret token for verifying ownership of the duty lock */
74
+ lockToken: string;
75
+ /** When the duty signing was started */
76
+ startedAt: Date;
77
+ /** When the duty signing was completed (success or failure) */
78
+ completedAt?: Date;
79
+ /** Error message (currently unused) */
80
+ errorMessage?: string;
81
+ }
82
+ /**
83
+ * Duty identifier for block proposals.
84
+ * blockIndexWithinCheckpoint is REQUIRED and must be >= 0.
85
+ */
86
+ export interface BlockProposalDutyIdentifier {
87
+ rollupAddress: EthAddress;
88
+ validatorAddress: EthAddress;
89
+ slot: SlotNumber;
90
+ /** Block index within checkpoint (0, 1, 2...). Required for block proposals. */
91
+ blockIndexWithinCheckpoint: IndexWithinCheckpoint;
92
+ dutyType: DutyType.BLOCK_PROPOSAL;
93
+ }
94
+ /**
95
+ * Duty identifier for non-block-proposal duties.
96
+ * blockIndexWithinCheckpoint is not applicable (internally stored as -1).
97
+ */
98
+ export interface OtherDutyIdentifier {
99
+ rollupAddress: EthAddress;
100
+ validatorAddress: EthAddress;
101
+ slot: SlotNumber;
102
+ dutyType: DutyType.CHECKPOINT_PROPOSAL | DutyType.ATTESTATION | DutyType.ATTESTATIONS_AND_SIGNERS | DutyType.GOVERNANCE_VOTE | DutyType.SLASHING_VOTE | DutyType.AUTH_REQUEST | DutyType.TXS;
103
+ }
104
+ /**
105
+ * Minimal info needed to identify a unique duty.
106
+ * Uses discriminated union to enforce type safety:
107
+ * - BLOCK_PROPOSAL duties MUST have blockIndexWithinCheckpoint >= 0
108
+ * - Other duty types do NOT have blockIndexWithinCheckpoint (internally -1)
109
+ */
110
+ export type DutyIdentifier = BlockProposalDutyIdentifier | OtherDutyIdentifier;
111
+ /**
112
+ * Validates and normalizes the block index for a duty.
113
+ * - BLOCK_PROPOSAL: validates blockIndexWithinCheckpoint is provided and >= 0
114
+ * - Other duty types: always returns -1
115
+ *
116
+ * @throws Error if BLOCK_PROPOSAL is missing blockIndexWithinCheckpoint or has invalid value
117
+ */
118
+ export declare function normalizeBlockIndex(dutyType: DutyType, blockIndexWithinCheckpoint: number | undefined): number;
119
+ /**
120
+ * Gets the block index from a DutyIdentifier.
121
+ * - BLOCK_PROPOSAL: returns the blockIndexWithinCheckpoint
122
+ * - Other duty types: returns -1
123
+ */
124
+ export declare function getBlockIndexFromDutyIdentifier(duty: DutyIdentifier): number;
125
+ /**
126
+ * Additional parameters for checking and recording a new duty
127
+ */
128
+ interface CheckAndRecordExtra {
129
+ /** Block number for this duty */
130
+ blockNumber: BlockNumber | CheckpointNumber;
131
+ /** The signing root (hash) for this duty */
132
+ messageHash: string;
133
+ /** Identifier for the node that acquired the lock */
134
+ nodeId: string;
135
+ }
136
+ /**
137
+ * Parameters for checking and recording a new duty.
138
+ * Uses intersection with DutyIdentifier to preserve the discriminated union.
139
+ */
140
+ export type CheckAndRecordParams = DutyIdentifier & CheckAndRecordExtra;
141
+ /**
142
+ * Additional parameters for recording a successful signing
143
+ */
144
+ interface RecordSuccessExtra {
145
+ signature: Signature;
146
+ nodeId: string;
147
+ lockToken: string;
148
+ }
149
+ /**
150
+ * Parameters for recording a successful signing.
151
+ * Uses intersection with DutyIdentifier to preserve the discriminated union.
152
+ */
153
+ export type RecordSuccessParams = DutyIdentifier & RecordSuccessExtra;
154
+ /**
155
+ * Additional parameters for deleting a duty
156
+ */
157
+ interface DeleteDutyExtra {
158
+ lockToken: string;
159
+ }
160
+ /**
161
+ * Parameters for deleting a duty.
162
+ * Uses intersection with DutyIdentifier to preserve the discriminated union.
163
+ */
164
+ export type DeleteDutyParams = DutyIdentifier & DeleteDutyExtra;
165
+ export {};
166
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZXMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9kYi90eXBlcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxXQUFXLEVBQUUsZ0JBQWdCLEVBQUUscUJBQXFCLEVBQUUsVUFBVSxFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFDeEgsT0FBTyxLQUFLLEVBQUUsVUFBVSxFQUFFLE1BQU0sK0JBQStCLENBQUM7QUFDaEUsT0FBTyxLQUFLLEVBQUUsU0FBUyxFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFFakU7O0dBRUc7QUFDSCxNQUFNLFdBQVcsT0FBTztJQUN0QixjQUFjLEVBQUUsTUFBTSxDQUFDO0lBQ3ZCLGlCQUFpQixFQUFFLE1BQU0sQ0FBQztJQUMxQixJQUFJLEVBQUUsTUFBTSxDQUFDO0lBQ2IsWUFBWSxFQUFFLE1BQU0sQ0FBQztJQUNyQiw2QkFBNkIsRUFBRSxNQUFNLENBQUM7SUFDdEMsU0FBUyxFQUFFLFFBQVEsQ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QAAQ,CAAC,eAAe,GACxB,QAAQ,CAAC,aAAa,GACtB,QAAQ,CAAC,YAAY,GACrB,QAAQ,CAAC,GAAG,CAAC;CAClB;AAED;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GAAG,2BAA2B,GAAG,mBAAmB,CAAC;AAE/E;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,EAAE,0BAA0B,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAc9G;AAED;;;;GAIG;AACH,wBAAgB,+BAA+B,CAAC,IAAI,EAAE,cAAc,GAAG,MAAM,CAK5E;AAED;;GAEG;AACH,UAAU,mBAAmB;IAC3B,iCAAiC;IACjC,WAAW,EAAE,WAAW,GAAG,gBAAgB,CAAC;IAC5C,4CAA4C;IAC5C,WAAW,EAAE,MAAM,CAAC;IACpB,qDAAqD;IACrD,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,MAAM,MAAM,oBAAoB,GAAG,cAAc,GAAG,mBAAmB,CAAC;AAExE;;GAEG;AACH,UAAU,kBAAkB;IAC1B,SAAS,EAAE,SAAS,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,MAAM,MAAM,mBAAmB,GAAG,cAAc,GAAG,kBAAkB,CAAC;AAEtE;;GAEG;AACH,UAAU,eAAe;IACvB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG,cAAc,GAAG,eAAe,CAAC"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Type of validator duty being performed
3
+ */ export var DutyType = /*#__PURE__*/ function(DutyType) {
4
+ DutyType["BLOCK_PROPOSAL"] = "BLOCK_PROPOSAL";
5
+ DutyType["CHECKPOINT_PROPOSAL"] = "CHECKPOINT_PROPOSAL";
6
+ DutyType["ATTESTATION"] = "ATTESTATION";
7
+ DutyType["ATTESTATIONS_AND_SIGNERS"] = "ATTESTATIONS_AND_SIGNERS";
8
+ DutyType["GOVERNANCE_VOTE"] = "GOVERNANCE_VOTE";
9
+ DutyType["SLASHING_VOTE"] = "SLASHING_VOTE";
10
+ DutyType["AUTH_REQUEST"] = "AUTH_REQUEST";
11
+ DutyType["TXS"] = "TXS";
12
+ return DutyType;
13
+ }({});
14
+ /**
15
+ * Status of a duty in the database
16
+ */ export var DutyStatus = /*#__PURE__*/ function(DutyStatus) {
17
+ DutyStatus["SIGNING"] = "signing";
18
+ DutyStatus["SIGNED"] = "signed";
19
+ return DutyStatus;
20
+ }({});
21
+ /**
22
+ * Validates and normalizes the block index for a duty.
23
+ * - BLOCK_PROPOSAL: validates blockIndexWithinCheckpoint is provided and >= 0
24
+ * - Other duty types: always returns -1
25
+ *
26
+ * @throws Error if BLOCK_PROPOSAL is missing blockIndexWithinCheckpoint or has invalid value
27
+ */ export function normalizeBlockIndex(dutyType, blockIndexWithinCheckpoint) {
28
+ if (dutyType === "BLOCK_PROPOSAL") {
29
+ if (blockIndexWithinCheckpoint === undefined) {
30
+ throw new Error('BLOCK_PROPOSAL duties require blockIndexWithinCheckpoint to be specified');
31
+ }
32
+ if (blockIndexWithinCheckpoint < 0) {
33
+ throw new Error(`BLOCK_PROPOSAL duties require blockIndexWithinCheckpoint >= 0, got ${blockIndexWithinCheckpoint}`);
34
+ }
35
+ return blockIndexWithinCheckpoint;
36
+ }
37
+ // For all other duty types, always use -1
38
+ return -1;
39
+ }
40
+ /**
41
+ * Gets the block index from a DutyIdentifier.
42
+ * - BLOCK_PROPOSAL: returns the blockIndexWithinCheckpoint
43
+ * - Other duty types: returns -1
44
+ */ export function getBlockIndexFromDutyIdentifier(duty) {
45
+ if (duty.dutyType === "BLOCK_PROPOSAL") {
46
+ return duty.blockIndexWithinCheckpoint;
47
+ }
48
+ return -1;
49
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Custom errors for the validator HA signer
3
+ */
4
+ import type { SlotNumber } from '@aztec/foundation/branded-types';
5
+ import type { DutyType } from './db/types.js';
6
+ /**
7
+ * Thrown when a duty has already been signed (by any node).
8
+ * This is expected behavior in an HA setup - all nodes try to sign,
9
+ * the first one wins, and subsequent attempts get this error.
10
+ */
11
+ export declare class DutyAlreadySignedError extends Error {
12
+ readonly slot: SlotNumber;
13
+ readonly dutyType: DutyType;
14
+ readonly blockIndexWithinCheckpoint: number;
15
+ readonly signedByNode: string;
16
+ constructor(slot: SlotNumber, dutyType: DutyType, blockIndexWithinCheckpoint: number, signedByNode: string);
17
+ }
18
+ /**
19
+ * Thrown when attempting to sign data that conflicts with an already-signed duty.
20
+ * This means the same validator tried to sign DIFFERENT data for the same slot.
21
+ *
22
+ * This is expected in HA setups where nodes may build different blocks
23
+ * (e.g., different transaction ordering) - the protection prevents double-signing.
24
+ */
25
+ export declare class SlashingProtectionError extends Error {
26
+ readonly slot: SlotNumber;
27
+ readonly dutyType: DutyType;
28
+ readonly blockIndexWithinCheckpoint: number;
29
+ readonly existingMessageHash: string;
30
+ readonly attemptedMessageHash: string;
31
+ readonly signedByNode: string;
32
+ constructor(slot: SlotNumber, dutyType: DutyType, blockIndexWithinCheckpoint: number, existingMessageHash: string, attemptedMessageHash: string, signedByNode: string);
33
+ }
34
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXJyb3JzLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvZXJyb3JzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBQ0gsT0FBTyxLQUFLLEVBQUUsVUFBVSxFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFFbEUsT0FBTyxLQUFLLEVBQUUsUUFBUSxFQUFFLE1BQU0sZUFBZSxDQUFDO0FBRTlDOzs7O0dBSUc7QUFDSCxxQkFBYSxzQkFBdUIsU0FBUSxLQUFLO2FBRTdCLElBQUksRUFBRSxVQUFVO2FBQ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E,MAAM,EAIrC;CACF;AAED;;;;;;GAMG;AACH,qBAAa,uBAAwB,SAAQ,KAAK;aAE9B,IAAI,EAAE,UAAU;aAChB,QAAQ,EAAE,QAAQ;aAClB,0BAA0B,EAAE,MAAM;aAClC,mBAAmB,EAAE,MAAM;aAC3B,oBAAoB,EAAE,MAAM;aAC5B,YAAY,EAAE,MAAM;IANtC,YACkB,IAAI,EAAE,UAAU,EAChB,QAAQ,EAAE,QAAQ,EAClB,0BAA0B,EAAE,MAAM,EAClC,mBAAmB,EAAE,MAAM,EAC3B,oBAAoB,EAAE,MAAM,EAC5B,YAAY,EAAE,MAAM,EAOrC;CACF"}
package/dest/errors.js ADDED
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Custom errors for the validator HA signer
3
+ */ /**
4
+ * Thrown when a duty has already been signed (by any node).
5
+ * This is expected behavior in an HA setup - all nodes try to sign,
6
+ * the first one wins, and subsequent attempts get this error.
7
+ */ export class DutyAlreadySignedError extends Error {
8
+ slot;
9
+ dutyType;
10
+ blockIndexWithinCheckpoint;
11
+ signedByNode;
12
+ constructor(slot, dutyType, blockIndexWithinCheckpoint, signedByNode){
13
+ super(`Duty ${dutyType} for slot ${slot} already signed by node ${signedByNode}`), this.slot = slot, this.dutyType = dutyType, this.blockIndexWithinCheckpoint = blockIndexWithinCheckpoint, this.signedByNode = signedByNode;
14
+ this.name = 'DutyAlreadySignedError';
15
+ }
16
+ }
17
+ /**
18
+ * Thrown when attempting to sign data that conflicts with an already-signed duty.
19
+ * This means the same validator tried to sign DIFFERENT data for the same slot.
20
+ *
21
+ * This is expected in HA setups where nodes may build different blocks
22
+ * (e.g., different transaction ordering) - the protection prevents double-signing.
23
+ */ export class SlashingProtectionError extends Error {
24
+ slot;
25
+ dutyType;
26
+ blockIndexWithinCheckpoint;
27
+ existingMessageHash;
28
+ attemptedMessageHash;
29
+ signedByNode;
30
+ constructor(slot, dutyType, blockIndexWithinCheckpoint, existingMessageHash, attemptedMessageHash, signedByNode){
31
+ super(`Slashing protection: ${dutyType} for slot ${slot} was already signed with different data. ` + `Existing: ${existingMessageHash.slice(0, 10)}..., Attempted: ${attemptedMessageHash.slice(0, 10)}...`), this.slot = slot, this.dutyType = dutyType, this.blockIndexWithinCheckpoint = blockIndexWithinCheckpoint, this.existingMessageHash = existingMessageHash, this.attemptedMessageHash = attemptedMessageHash, this.signedByNode = signedByNode;
32
+ this.name = 'SlashingProtectionError';
33
+ }
34
+ }
@@ -0,0 +1,42 @@
1
+ import type { ValidatorHASignerConfig } from './config.js';
2
+ import type { CreateHASignerDeps, SlashingProtectionDatabase } from './types.js';
3
+ import { ValidatorHASigner } from './validator_ha_signer.js';
4
+ /**
5
+ * Create a validator HA signer with PostgreSQL backend
6
+ *
7
+ * After creating the signer, call `signer.start()` to begin background
8
+ * cleanup tasks. Call `signer.stop()` during graceful shutdown.
9
+ *
10
+ * Example with manual migrations (recommended for production):
11
+ * ```bash
12
+ * # Run migrations separately
13
+ * yarn migrate:up
14
+ * ```
15
+ *
16
+ * ```typescript
17
+ * const { signer, db } = await createHASigner({
18
+ * databaseUrl: process.env.DATABASE_URL,
19
+ * haSigningEnabled: true,
20
+ * nodeId: 'validator-node-1',
21
+ * pollingIntervalMs: 100,
22
+ * signingTimeoutMs: 3000,
23
+ * });
24
+ * signer.start(); // Start background cleanup
25
+ *
26
+ * // ... use signer ...
27
+ *
28
+ * await signer.stop(); // On shutdown
29
+ * ```
30
+ *
31
+ * Note: Migrations must be run separately using `aztec migrate-ha-db up` before
32
+ * creating the signer. The factory will verify the schema is initialized via `db.initialize()`.
33
+ *
34
+ * @param config - Configuration for the HA signer
35
+ * @param deps - Optional dependencies (e.g., for testing)
36
+ * @returns An object containing the signer and database instances
37
+ */
38
+ export declare function createHASigner(config: ValidatorHASignerConfig, deps?: CreateHASignerDeps): Promise<{
39
+ signer: ValidatorHASigner;
40
+ db: SlashingProtectionDatabase;
41
+ }>;
42
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjoz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@@
1
+ /**
2
+ * Factory functions for creating validator HA signers
3
+ */ import { Pool } from 'pg';
4
+ import { PostgresSlashingProtectionDatabase } from './db/postgres.js';
5
+ import { ValidatorHASigner } from './validator_ha_signer.js';
6
+ /**
7
+ * Create a validator HA signer with PostgreSQL backend
8
+ *
9
+ * After creating the signer, call `signer.start()` to begin background
10
+ * cleanup tasks. Call `signer.stop()` during graceful shutdown.
11
+ *
12
+ * Example with manual migrations (recommended for production):
13
+ * ```bash
14
+ * # Run migrations separately
15
+ * yarn migrate:up
16
+ * ```
17
+ *
18
+ * ```typescript
19
+ * const { signer, db } = await createHASigner({
20
+ * databaseUrl: process.env.DATABASE_URL,
21
+ * haSigningEnabled: true,
22
+ * nodeId: 'validator-node-1',
23
+ * pollingIntervalMs: 100,
24
+ * signingTimeoutMs: 3000,
25
+ * });
26
+ * signer.start(); // Start background cleanup
27
+ *
28
+ * // ... use signer ...
29
+ *
30
+ * await signer.stop(); // On shutdown
31
+ * ```
32
+ *
33
+ * Note: Migrations must be run separately using `aztec migrate-ha-db up` before
34
+ * creating the signer. The factory will verify the schema is initialized via `db.initialize()`.
35
+ *
36
+ * @param config - Configuration for the HA signer
37
+ * @param deps - Optional dependencies (e.g., for testing)
38
+ * @returns An object containing the signer and database instances
39
+ */ export async function createHASigner(config, deps) {
40
+ const { databaseUrl, poolMaxCount, poolMinCount, poolIdleTimeoutMs, poolConnectionTimeoutMs, ...signerConfig } = config;
41
+ if (!databaseUrl) {
42
+ throw new Error('databaseUrl is required for createHASigner');
43
+ }
44
+ // Create connection pool (or use provided pool)
45
+ let pool;
46
+ if (!deps?.pool) {
47
+ pool = new Pool({
48
+ connectionString: databaseUrl,
49
+ max: poolMaxCount ?? 10,
50
+ min: poolMinCount ?? 0,
51
+ idleTimeoutMillis: poolIdleTimeoutMs ?? 10_000,
52
+ connectionTimeoutMillis: poolConnectionTimeoutMs ?? 0
53
+ });
54
+ } else {
55
+ pool = deps.pool;
56
+ }
57
+ // Create database instance
58
+ const db = new PostgresSlashingProtectionDatabase(pool);
59
+ // Verify database schema is initialized and version matches
60
+ await db.initialize();
61
+ // Create signer
62
+ const signer = new ValidatorHASigner(db, {
63
+ ...signerConfig,
64
+ databaseUrl
65
+ });
66
+ return {
67
+ signer,
68
+ db
69
+ };
70
+ }
@@ -0,0 +1,15 @@
1
+ export interface RunMigrationsOptions {
2
+ /** Migration direction ('up' to apply, 'down' to rollback). Defaults to 'up'. */
3
+ direction?: 'up' | 'down';
4
+ /** Enable verbose output. Defaults to false. */
5
+ verbose?: boolean;
6
+ }
7
+ /**
8
+ * Run database migrations programmatically
9
+ *
10
+ * @param databaseUrl - PostgreSQL connection string
11
+ * @param options - Migration options (direction, verbose)
12
+ * @returns Array of applied migration names
13
+ */
14
+ export declare function runMigrations(databaseUrl: string, options?: RunMigrationsOptions): Promise<string[]>;
15
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWlncmF0aW9ucy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL21pZ3JhdGlvbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBYUEsTUFBTSxXQUFXLG9CQUFvQjtJQUNuQyxpRkFBaUY7SUFDakYsU0FBUyxDQUFDLEVBQUUsSUFBSSxHQUFHLE1BQU0sQ0FBQztJQUMxQixnREFBZ0Q7SUFDaEQsT0FBTyxDQUFDLEVBQUUsT0FBTyxDQUFDO0NBQ25CO0FBRUQ7Ozs7OztHQU1HO0FBQ0gsd0JBQXNCLGFBQWEsQ0FBQyxXQUFXLEVBQUUsTUFBTSxFQUFFLE9BQU8sR0FBRSxvQkFBeUIsR0FBRyxPQUFPLENBQUMsTUFBTSxFQUFFLENBQUMsQ0ErQzlHIn0=
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../src/migrations.ts"],"names":[],"mappings":"AAaA,MAAM,WAAW,oBAAoB;IACnC,iFAAiF;IACjF,SAAS,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC;IAC1B,gDAAgD;IAChD,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;GAMG;AACH,wBAAsB,aAAa,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,GAAE,oBAAyB,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CA+C9G"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Programmatic migration runner
3
+ */ import { createLogger } from '@aztec/foundation/log';
4
+ import { readdirSync } from 'fs';
5
+ import { runner } from 'node-pg-migrate';
6
+ import { dirname, join } from 'path';
7
+ import { fileURLToPath } from 'url';
8
+ const __filename = fileURLToPath(import.meta.url);
9
+ const __dirname = dirname(__filename);
10
+ /**
11
+ * Run database migrations programmatically
12
+ *
13
+ * @param databaseUrl - PostgreSQL connection string
14
+ * @param options - Migration options (direction, verbose)
15
+ * @returns Array of applied migration names
16
+ */ export async function runMigrations(databaseUrl, options = {}) {
17
+ const direction = options.direction ?? 'up';
18
+ const verbose = options.verbose ?? false;
19
+ const log = createLogger('validator-ha-signer:migrations');
20
+ const migrationsDir = join(__dirname, 'db', 'migrations');
21
+ try {
22
+ log.info(`Running migrations ${direction}...`);
23
+ // Filter out .d.ts and .d.ts.map files - node-pg-migrate only needs .js files
24
+ const migrationFiles = readdirSync(migrationsDir);
25
+ const jsMigrationFiles = migrationFiles.filter((file)=>file.endsWith('.js') && !file.endsWith('.d.ts') && !file.endsWith('.d.ts.map'));
26
+ if (jsMigrationFiles.length === 0) {
27
+ log.info('No migration files found');
28
+ return [];
29
+ }
30
+ const appliedMigrations = await runner({
31
+ databaseUrl,
32
+ dir: migrationsDir,
33
+ direction,
34
+ migrationsTable: 'pgmigrations',
35
+ count: direction === 'down' ? 1 : Infinity,
36
+ verbose,
37
+ log: (msg)=>verbose ? log.info(msg) : log.debug(msg),
38
+ // Ignore TypeScript declaration files - node-pg-migrate will try to import them otherwise
39
+ ignorePattern: '.*\\.d\\.(ts|js)$|.*\\.d\\.ts\\.map$'
40
+ });
41
+ if (appliedMigrations.length === 0) {
42
+ log.info('No migrations to apply - schema is up to date');
43
+ } else {
44
+ log.info(`Applied ${appliedMigrations.length} migration(s)`, {
45
+ migrations: appliedMigrations.map((m)=>m.name)
46
+ });
47
+ }
48
+ return appliedMigrations.map((m)=>m.name);
49
+ } catch (error) {
50
+ log.error('Migration failed', error);
51
+ throw error;
52
+ }
53
+ }
@@ -0,0 +1,84 @@
1
+ import { type CheckAndRecordParams, type DeleteDutyParams, type RecordSuccessParams } from './db/types.js';
2
+ import type { SlashingProtectionDatabase, ValidatorHASignerConfig } from './types.js';
3
+ /**
4
+ * Slashing Protection Service
5
+ *
6
+ * This service ensures that a validator only signs one block/attestation per slot,
7
+ * even when running multiple redundant nodes (HA setup).
8
+ *
9
+ * All nodes in the HA setup try to sign - the first one wins, others get
10
+ * DutyAlreadySignedError (normal) or SlashingProtectionError (if different data).
11
+ *
12
+ * Flow:
13
+ * 1. checkAndRecord() - Atomically try to acquire lock via tryInsertOrGetExisting
14
+ * 2. Caller performs the signing operation
15
+ * 3. recordSuccess() - Update to 'signed' status with signature
16
+ * OR deleteDuty() - Delete the record to allow retry
17
+ */
18
+ export declare class SlashingProtectionService {
19
+ private readonly db;
20
+ private readonly config;
21
+ private readonly log;
22
+ private readonly pollingIntervalMs;
23
+ private readonly signingTimeoutMs;
24
+ private readonly maxStuckDutiesAgeMs;
25
+ private cleanupRunningPromise;
26
+ private lastOldDutiesCleanupAtMs?;
27
+ constructor(db: SlashingProtectionDatabase, config: ValidatorHASignerConfig);
28
+ /**
29
+ * Check if a duty can be performed and acquire the lock if so.
30
+ *
31
+ * This method uses an atomic insert-or-get operation.
32
+ * It will:
33
+ * 1. Try to insert a new record with 'signing' status
34
+ * 2. If insert succeeds, we acquired the lock - return the lockToken
35
+ * 3. If a record exists, handle based on status:
36
+ * - SIGNED: Throw appropriate error (already signed or slashing protection)
37
+ * - SIGNING: Wait and poll until status changes, then handle result
38
+ *
39
+ * @returns The lockToken that must be used for recordSuccess/deleteDuty
40
+ * @throws DutyAlreadySignedError if the duty was already completed
41
+ * @throws SlashingProtectionError if attempting to sign different data for same slot/duty
42
+ */
43
+ checkAndRecord(params: CheckAndRecordParams): Promise<string>;
44
+ /**
45
+ * Record a successful signing operation.
46
+ * Updates the duty status to 'signed' and stores the signature.
47
+ * Only succeeds if the lockToken matches (caller must be the one who created the duty).
48
+ *
49
+ * @returns true if the update succeeded, false if token didn't match
50
+ */
51
+ recordSuccess(params: RecordSuccessParams): Promise<boolean>;
52
+ /**
53
+ * Delete a duty record after a failed signing operation.
54
+ * Removes the record to allow another node/attempt to retry.
55
+ * Only succeeds if the lockToken matches (caller must be the one who created the duty).
56
+ *
57
+ * @returns true if the delete succeeded, false if token didn't match
58
+ */
59
+ deleteDuty(params: DeleteDutyParams): Promise<boolean>;
60
+ /**
61
+ * Get the node ID for this service
62
+ */
63
+ get nodeId(): string;
64
+ /**
65
+ * Start running tasks.
66
+ * Cleanup runs immediately on start to recover from any previous crashes.
67
+ */
68
+ /**
69
+ * Start the background cleanup task.
70
+ * Also performs one-time cleanup of duties with outdated rollup addresses.
71
+ */
72
+ start(): Promise<void>;
73
+ /**
74
+ * Stop the background cleanup task.
75
+ */
76
+ stop(): Promise<void>;
77
+ /**
78
+ * Close the database connection.
79
+ * Should be called after stop() during graceful shutdown.
80
+ */
81
+ close(): Promise<void>;
82
+ private cleanup;
83
+ }
84
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2xhc2hpbmdfcHJvdGVjdGlvbl9zZXJ2aWNlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvc2xhc2hpbmdfcHJvdGVjdGlvbl9zZXJ2aWNlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQVVBLE9BQU8sRUFDTCxLQUFLLG9CQUFvQixFQUN6QixLQUFLLGdCQUFnQixFQ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