@obolnetwork/obol-sdk 2.11.4 → 2.11.5-rc.1

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 (144) hide show
  1. package/README.md +33 -0
  2. package/dist/browser/src/index.js +18280 -0
  3. package/dist/browser/src/index.js.map +1 -0
  4. package/dist/cjs/src/index.js +17470 -382
  5. package/dist/cjs/src/index.js.map +1 -0
  6. package/dist/esm/src/index.js +17437 -361
  7. package/dist/esm/src/index.js.map +1 -0
  8. package/dist/types/src/constants.d.ts +1 -2
  9. package/dist/types/src/eoa/eoaHelpers.d.ts +1 -1
  10. package/dist/types/src/exits/verificationHelpers.d.ts +0 -2
  11. package/dist/types/src/incentives/incentiveHelpers.d.ts +1 -1
  12. package/dist/types/src/splits/splitHelpers.d.ts +3 -3
  13. package/dist/types/src/utils.d.ts +2 -2
  14. package/dist/types/src/verification/common.d.ts +0 -2
  15. package/dist/types/src/verification/signature-validator.d.ts +4 -4
  16. package/dist/types/src/verification/v1.10.0.d.ts +1 -1
  17. package/dist/types/src/verification/v1.6.0.d.ts +1 -1
  18. package/dist/types/src/verification/v1.7.0.d.ts +1 -1
  19. package/dist/types/src/verification/v1.8.0.d.ts +1 -1
  20. package/dist/types/test/client/methods.spec.d.ts +17 -0
  21. package/dist/types/tsconfig.types.tsbuildinfo +1 -0
  22. package/dist/types/tsup.config.d.ts +2 -0
  23. package/package.json +96 -58
  24. package/dist/cjs/package.json +0 -139
  25. package/dist/cjs/src/abi/BatchDeposit.js +0 -120
  26. package/dist/cjs/src/abi/MerkleDistributorWithDeadline.js +0 -73
  27. package/dist/cjs/src/abi/Multicall3.js +0 -253
  28. package/dist/cjs/src/abi/OVM.js +0 -627
  29. package/dist/cjs/src/abi/OWR.js +0 -304
  30. package/dist/cjs/src/abi/SplitMain.js +0 -929
  31. package/dist/cjs/src/abi/splitV2FactoryAbi.js +0 -420
  32. package/dist/cjs/src/ajv.js +0 -136
  33. package/dist/cjs/src/base.js +0 -42
  34. package/dist/cjs/src/bytecodes.js +0 -19
  35. package/dist/cjs/src/constants.js +0 -272
  36. package/dist/cjs/src/eoa/eoa.js +0 -132
  37. package/dist/cjs/src/eoa/eoaHelpers.js +0 -82
  38. package/dist/cjs/src/errors.js +0 -11
  39. package/dist/cjs/src/exits/ethUtils.js +0 -57
  40. package/dist/cjs/src/exits/exit.js +0 -502
  41. package/dist/cjs/src/exits/verificationHelpers.js +0 -86
  42. package/dist/cjs/src/incentives/incentiveHelpers.js +0 -39
  43. package/dist/cjs/src/incentives/incentives.js +0 -119
  44. package/dist/cjs/src/schema.js +0 -352
  45. package/dist/cjs/src/services.js +0 -33
  46. package/dist/cjs/src/splits/splitHelpers.js +0 -571
  47. package/dist/cjs/src/splits/splits.js +0 -366
  48. package/dist/cjs/src/types.js +0 -29
  49. package/dist/cjs/src/utils.js +0 -77
  50. package/dist/cjs/src/verification/common.js +0 -355
  51. package/dist/cjs/src/verification/signature-validator.js +0 -73
  52. package/dist/cjs/src/verification/sszTypes.js +0 -69
  53. package/dist/cjs/src/verification/termsAndConditions.js +0 -40
  54. package/dist/cjs/src/verification/v1.10.0.js +0 -146
  55. package/dist/cjs/src/verification/v1.6.0.js +0 -149
  56. package/dist/cjs/src/verification/v1.7.0.js +0 -173
  57. package/dist/cjs/src/verification/v1.8.0.js +0 -196
  58. package/dist/cjs/test/client/ajv.spec.js +0 -320
  59. package/dist/cjs/test/client/methods.spec.js +0 -418
  60. package/dist/cjs/test/eoa/eoa.spec.js +0 -176
  61. package/dist/cjs/test/exit/ethUtils.spec.js +0 -83
  62. package/dist/cjs/test/exit/exit.spec.js +0 -399
  63. package/dist/cjs/test/exit/verificationHelpers.spec.js +0 -68
  64. package/dist/cjs/test/fixtures.js +0 -896
  65. package/dist/cjs/test/incentives/incentives.spec.js +0 -202
  66. package/dist/cjs/test/splits/splits.spec.js +0 -402
  67. package/dist/esm/package.json +0 -139
  68. package/dist/esm/src/abi/BatchDeposit.js +0 -117
  69. package/dist/esm/src/abi/MerkleDistributorWithDeadline.js +0 -70
  70. package/dist/esm/src/abi/Multicall3.js +0 -250
  71. package/dist/esm/src/abi/OVM.js +0 -624
  72. package/dist/esm/src/abi/OWR.js +0 -301
  73. package/dist/esm/src/abi/SplitMain.js +0 -926
  74. package/dist/esm/src/abi/splitV2FactoryAbi.js +0 -417
  75. package/dist/esm/src/ajv.js +0 -129
  76. package/dist/esm/src/base.js +0 -38
  77. package/dist/esm/src/bytecodes.js +0 -16
  78. package/dist/esm/src/constants.js +0 -238
  79. package/dist/esm/src/eoa/eoa.js +0 -128
  80. package/dist/esm/src/eoa/eoaHelpers.js +0 -77
  81. package/dist/esm/src/errors.js +0 -7
  82. package/dist/esm/src/exits/ethUtils.js +0 -52
  83. package/dist/esm/src/exits/exit.js +0 -475
  84. package/dist/esm/src/exits/verificationHelpers.js +0 -81
  85. package/dist/esm/src/incentives/incentiveHelpers.js +0 -34
  86. package/dist/esm/src/incentives/incentives.js +0 -115
  87. package/dist/esm/src/schema.js +0 -349
  88. package/dist/esm/src/services.js +0 -29
  89. package/dist/esm/src/splits/splitHelpers.js +0 -554
  90. package/dist/esm/src/splits/splits.js +0 -362
  91. package/dist/esm/src/types.js +0 -26
  92. package/dist/esm/src/utils.js +0 -68
  93. package/dist/esm/src/verification/common.js +0 -319
  94. package/dist/esm/src/verification/signature-validator.js +0 -64
  95. package/dist/esm/src/verification/sszTypes.js +0 -64
  96. package/dist/esm/src/verification/termsAndConditions.js +0 -33
  97. package/dist/esm/src/verification/v1.10.0.js +0 -140
  98. package/dist/esm/src/verification/v1.6.0.js +0 -142
  99. package/dist/esm/src/verification/v1.7.0.js +0 -166
  100. package/dist/esm/src/verification/v1.8.0.js +0 -189
  101. package/dist/esm/test/client/ajv.spec.js +0 -318
  102. package/dist/esm/test/client/methods.spec.js +0 -393
  103. package/dist/esm/test/eoa/eoa.spec.js +0 -174
  104. package/dist/esm/test/exit/ethUtils.spec.js +0 -81
  105. package/dist/esm/test/exit/exit.spec.js +0 -374
  106. package/dist/esm/test/exit/verificationHelpers.spec.js +0 -66
  107. package/dist/esm/test/fixtures.js +0 -893
  108. package/dist/esm/test/incentives/incentives.spec.js +0 -177
  109. package/dist/esm/test/splits/splits.spec.js +0 -400
  110. package/dist/types/src/verification/termsAndConditions.d.ts +0 -1
  111. package/src/abi/BatchDeposit.ts +0 -117
  112. package/src/abi/MerkleDistributorWithDeadline.ts +0 -70
  113. package/src/abi/Multicall3.ts +0 -250
  114. package/src/abi/OVM.ts +0 -624
  115. package/src/abi/OWR.ts +0 -302
  116. package/src/abi/SplitMain.ts +0 -927
  117. package/src/abi/splitV2FactoryAbi.ts +0 -417
  118. package/src/ajv.ts +0 -191
  119. package/src/base.ts +0 -54
  120. package/src/bytecodes.ts +0 -32
  121. package/src/constants.ts +0 -309
  122. package/src/eoa/eoa.ts +0 -153
  123. package/src/eoa/eoaHelpers.ts +0 -112
  124. package/src/errors.ts +0 -8
  125. package/src/exits/ethUtils.ts +0 -49
  126. package/src/exits/exit.ts +0 -661
  127. package/src/exits/verificationHelpers.ts +0 -110
  128. package/src/incentives/incentiveHelpers.ts +0 -55
  129. package/src/incentives/incentives.ts +0 -153
  130. package/src/index.ts +0 -614
  131. package/src/schema.ts +0 -376
  132. package/src/services.ts +0 -24
  133. package/src/splits/splitHelpers.ts +0 -1032
  134. package/src/splits/splits.ts +0 -504
  135. package/src/types.ts +0 -687
  136. package/src/utils.ts +0 -88
  137. package/src/verification/common.ts +0 -532
  138. package/src/verification/signature-validator.ts +0 -103
  139. package/src/verification/sszTypes.ts +0 -88
  140. package/src/verification/termsAndConditions.ts +0 -32
  141. package/src/verification/v1.10.0.ts +0 -245
  142. package/src/verification/v1.6.0.ts +0 -256
  143. package/src/verification/v1.7.0.ts +0 -309
  144. package/src/verification/v1.8.0.ts +0 -340
@@ -1,502 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
- Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.Exit = void 0;
36
- const discv5_1 = require("@chainsafe/discv5");
37
- const elliptic = __importStar(require("elliptic"));
38
- const bls_1 = require("@chainsafe/bls");
39
- const ssz_1 = require("@chainsafe/ssz");
40
- const ethUtils_1 = require("./ethUtils");
41
- const verificationHelpers_1 = require("./verificationHelpers");
42
- // Constants from obol-api/src/verification/exit.ts (assuming these might be needed or were in the original context)
43
- const DOMAIN_VOLUNTARY_EXIT = '0x04000000';
44
- // SSZ Type Definitions (adapted from obol-api/src/verification/exit.ts)
45
- const SSZExitMessageType = new ssz_1.ContainerType({
46
- epoch: new ssz_1.UintNumberType(8),
47
- validator_index: new ssz_1.UintNumberType(8),
48
- });
49
- const SSZPartialExitsPayloadType = new ssz_1.ContainerType({
50
- partial_exits: new ssz_1.ListCompositeType(new ssz_1.ContainerType({
51
- public_key: new ssz_1.ByteVectorType(48),
52
- signed_exit_message: new ssz_1.ContainerType({
53
- message: new ssz_1.ContainerType({
54
- epoch: new ssz_1.UintNumberType(8),
55
- validator_index: new ssz_1.UintNumberType(8),
56
- }),
57
- signature: new ssz_1.ByteVectorType(96),
58
- }),
59
- }), 65536),
60
- share_idx: new ssz_1.UintNumberType(8),
61
- });
62
- /**
63
- * Exit validation and verification class for Obol distributed validators.
64
- *
65
- * This class provides functionality to validate and verify voluntary exit signatures
66
- * for distributed validators in an Obol cluster. It handles both partial exit signatures
67
- * from individual operators and payload signatures that authorize exit operations.
68
- *
69
- * The class supports:
70
- * - Verification of BLS signatures for partial exit messages
71
- * - Verification of ECDSA signatures for exit payload authorization
72
- * - Validation of exit blobs against cluster configuration
73
- * - Duplicate detection and epoch validation
74
- *
75
- * @example
76
- * ```typescript
77
- * const exit = new Exit(1, provider); // Mainnet with provider
78
- *
79
- * // Verify a partial exit signature
80
- * const isValid = await exit.verifyPartialExitSignature(
81
- * publicShareKey,
82
- * signedExitMessage,
83
- * forkVersion,
84
- * genesisValidatorsRoot
85
- * );
86
- *
87
- * // Validate exit blobs for a cluster
88
- * const validBlobs = await exit.validateExitBlobs(
89
- * clusterConfig,
90
- * exitsPayload,
91
- * beaconNodeApiUrl,
92
- * existingBlobData
93
- * );
94
- * ```
95
- */
96
- class Exit {
97
- /**
98
- * Creates a new Exit instance for validator exit operations.
99
- *
100
- * @param chainId - The Ethereum chain ID (e.g., 1 for mainnet, 5 for goerli)
101
- * @param provider - Optional Ethereum provider for blockchain interactions
102
- *
103
- * @example
104
- * ```typescript
105
- * // For mainnet with a provider
106
- * const exit = new Exit(1, provider);
107
- *
108
- * // For goerli testnet without provider
109
- * const exit = new Exit(5, null);
110
- * ```
111
- */
112
- constructor(chainId, provider) {
113
- this.chainId = chainId;
114
- this.provider = provider;
115
- }
116
- /**
117
- * Safely parse a string integer to number, using BigInt to avoid precision loss
118
- * for large values beyond JavaScript's safe integer limit (2^53 - 1).
119
- * Throws an error if the value exceeds the safe range for a 64-bit unsigned integer.
120
- */
121
- static safeParseInt(value) {
122
- const bigIntValue = BigInt(value);
123
- // Check if value is within the range of a 64-bit unsigned integer
124
- const MAX_UINT64 = BigInt('0xFFFFFFFFFFFFFFFF');
125
- if (bigIntValue < 0 || bigIntValue > MAX_UINT64) {
126
- throw new Error(`Value ${value} is outside the valid range for a 64-bit unsigned integer`);
127
- }
128
- // Convert to number - SSZ library should handle values even if they exceed JS safe integer limits
129
- return Number(bigIntValue);
130
- }
131
- static computePartialExitMessageRoot(msg) {
132
- const sszValue = SSZExitMessageType.defaultValue();
133
- sszValue.epoch = Exit.safeParseInt(msg.epoch);
134
- sszValue.validator_index = Exit.safeParseInt(msg.validator_index);
135
- return Buffer.from(SSZExitMessageType.hashTreeRoot(sszValue).buffer);
136
- }
137
- static computeExitPayloadRoot(exits) {
138
- // Remove sorting since SSZ list ordering guarantees order
139
- // This eliminates the O(n log n) sort and improves performance
140
- const sszValue = SSZPartialExitsPayloadType.defaultValue();
141
- sszValue.partial_exits = exits.partial_exits.map(pe => ({
142
- public_key: (0, ssz_1.fromHexString)(pe.public_key),
143
- signed_exit_message: {
144
- message: {
145
- epoch: Exit.safeParseInt(pe.signed_exit_message.message.epoch),
146
- validator_index: Exit.safeParseInt(pe.signed_exit_message.message.validator_index),
147
- },
148
- signature: (0, ssz_1.fromHexString)(pe.signed_exit_message.signature),
149
- },
150
- }));
151
- sszValue.share_idx = exits.share_idx;
152
- return Buffer.from(SSZPartialExitsPayloadType.hashTreeRoot(sszValue).buffer).toString('hex');
153
- }
154
- /**
155
- * Verifies a partial exit signature from a distributed validator operator.
156
- *
157
- * This method validates that a partial exit signature was correctly signed by the
158
- * operator's share of the distributed validator's private key. It performs BLS
159
- * signature verification using the appropriate fork version and genesis validators root.
160
- *
161
- * @param publicShareKey - The operator's public share key (BLS public key, hex string with or without 0x prefix)
162
- * @param signedExitMessage - The signed exit message containing the exit details and signature
163
- * @param forkVersion - The Ethereum fork version (e.g., "0x00000000" for mainnet)
164
- * @param genesisValidatorsRootString - The genesis validators root for the network (hex string)
165
- *
166
- * @returns Promise resolving to true if the signature is valid, false otherwise
167
- *
168
- * @throws {Error} When unable to determine the Capella fork version for the given network
169
- * @throws {Error} When BLS library initialization or verification fails
170
- *
171
- * @example
172
- * ```typescript
173
- * const isValid = await exit.verifyPartialExitSignature(
174
- * "0x1234...abcd", // operator's public share key
175
- * {
176
- * message: { epoch: "12345", validator_index: "67890" },
177
- * signature: "0xabcd...1234"
178
- * },
179
- * "0x00000000", // mainnet fork version
180
- * "0x4b363db94e286120d76eb905340fdd4e54bfe9f06bf33ff6cf5ad27f511bfe95"
181
- * );
182
- * ```
183
- */
184
- verifyPartialExitSignature(publicShareKey, signedExitMessage, forkVersion, genesisValidatorsRootString) {
185
- return __awaiter(this, void 0, void 0, function* () {
186
- yield (0, bls_1.init)('herumi');
187
- const capellaForkVersionString = yield (0, ethUtils_1.getCapellaFork)(forkVersion);
188
- if (!capellaForkVersionString) {
189
- throw new Error(`Could not determine Capella fork version for base fork: ${forkVersion}`);
190
- }
191
- const partialExitMessageBuffer = Exit.computePartialExitMessageRoot(signedExitMessage.message);
192
- const exitDomain = (0, verificationHelpers_1.computeDomain)((0, ssz_1.fromHexString)(DOMAIN_VOLUNTARY_EXIT), capellaForkVersionString, (0, ssz_1.fromHexString)(genesisValidatorsRootString));
193
- const messageSigningRoot = (0, verificationHelpers_1.signingRoot)(exitDomain, partialExitMessageBuffer);
194
- return (0, bls_1.verify)((0, ssz_1.fromHexString)(publicShareKey), messageSigningRoot, (0, ssz_1.fromHexString)(signedExitMessage.signature));
195
- });
196
- }
197
- /**
198
- * Verifies the exit payload signature using the operator's ENR.
199
- *
200
- * This method validates that an exit payload was signed by the correct operator
201
- * using ECDSA signature verification. The signature is verified against the
202
- * operator's public key extracted from their ENR (Ethereum Node Record).
203
- *
204
- * @param enrString - The operator's ENR string containing their identity and public key
205
- * @param exitsPayload - The exit validation payload containing partial exits and operator signature
206
- *
207
- * @returns Promise resolving to true if the payload signature is valid, false otherwise
208
- *
209
- * @throws {Error} When the ENR string is invalid or cannot be decoded
210
- * @throws {Error} When the signature format is invalid (must be 130 hex characters)
211
- * @throws {Error} When signature verification encounters an error
212
- *
213
- * @example
214
- * ```typescript
215
- * const isValid = await exit.verifyExitPayloadSignature(
216
- * "enr:-LK4QFo_n0dUm4PKejSOXf8JkSWq5EINV0XhG1zY00d...", // operator ENR
217
- * {
218
- * partial_exits: [exitBlob1, exitBlob2],
219
- * share_idx: 1,
220
- * signature: "0x1234...abcd" // ECDSA signature (130 hex chars)
221
- * }
222
- * );
223
- * ```
224
- */
225
- verifyExitPayloadSignature(enrString, exitsPayload) {
226
- var _a, _b;
227
- return __awaiter(this, void 0, void 0, function* () {
228
- const partialExitsDtoHashRoot = Exit.computeExitPayloadRoot(exitsPayload);
229
- const ec = new elliptic.ec('secp256k1');
230
- let pubKeyHex;
231
- try {
232
- pubKeyHex = discv5_1.ENR.decodeTxt(enrString).publicKey.toString('hex');
233
- }
234
- catch (e) {
235
- throw new Error(`Invalid ENR string: ${enrString}. Error: ${(_a = e.message) !== null && _a !== void 0 ? _a : String(e)}`);
236
- }
237
- const sigHex = exitsPayload.signature.startsWith('0x')
238
- ? exitsPayload.signature.substring(2)
239
- : exitsPayload.signature;
240
- if (sigHex.length !== 130) {
241
- throw new Error(`Invalid signature length. Expected 130 hex chars (r + s), got ${sigHex.length}`);
242
- }
243
- const r = sigHex.slice(0, 64);
244
- const s = sigHex.slice(64, 128);
245
- const enrSignature = { r, s };
246
- try {
247
- return ec
248
- .keyFromPublic(pubKeyHex, 'hex')
249
- .verify(partialExitsDtoHashRoot, enrSignature);
250
- }
251
- catch (e) {
252
- throw new Error(`Signature verification failed: ${(_b = e.message) !== null && _b !== void 0 ? _b : String(e)}`);
253
- }
254
- });
255
- }
256
- validateOperatorAndPayload(clusterConfig, exitsPayload) {
257
- return __awaiter(this, void 0, void 0, function* () {
258
- const operatorIndex = exitsPayload.share_idx - 1;
259
- if (operatorIndex < 0 ||
260
- operatorIndex >= clusterConfig.definition.operators.length) {
261
- throw new Error(`Invalid share_idx ${exitsPayload.share_idx} for ${clusterConfig.definition.operators.length} operators.`);
262
- }
263
- const operatorEnr = clusterConfig.definition.operators[operatorIndex].enr;
264
- const isPayloadSignatureValid = yield this.verifyExitPayloadSignature(operatorEnr, exitsPayload);
265
- if (!isPayloadSignatureValid) {
266
- throw new Error('Incorrect payload signature for partial exits.');
267
- }
268
- return operatorEnr;
269
- });
270
- }
271
- getNetworkParameters(forkVersion, beaconNodeApiUrl) {
272
- return __awaiter(this, void 0, void 0, function* () {
273
- const genesisValidatorsRootString = yield (0, ethUtils_1.getGenesisValidatorsRoot)(beaconNodeApiUrl);
274
- if (!genesisValidatorsRootString) {
275
- throw new Error('Could not retrieve genesis validators root.');
276
- }
277
- const capellaForkVersionString = yield (0, ethUtils_1.getCapellaFork)(forkVersion);
278
- if (!capellaForkVersionString) {
279
- throw new Error(`Unsupported network: Could not determine Capella fork for ${forkVersion}`);
280
- }
281
- return {
282
- genesisValidatorsRoot: genesisValidatorsRootString,
283
- capellaForkVersion: capellaForkVersionString,
284
- };
285
- });
286
- }
287
- findValidatorInCluster(clusterConfig, publicKey, operatorIndex) {
288
- const validatorInCluster = clusterConfig.distributed_validators.find(dv => (dv.distributed_public_key.startsWith('0x')
289
- ? dv.distributed_public_key
290
- : '0x' + dv.distributed_public_key).toLowerCase() ===
291
- (publicKey.startsWith('0x')
292
- ? publicKey
293
- : '0x' + publicKey).toLowerCase());
294
- if (!validatorInCluster) {
295
- throw new Error(`Public key ${publicKey} not found in the cluster's distributed validators.`);
296
- }
297
- const publicShareForOperator = validatorInCluster.public_shares[operatorIndex];
298
- if (!publicShareForOperator) {
299
- throw new Error(`Public share for operator index ${operatorIndex} not found for validator ${publicKey}`);
300
- }
301
- return {
302
- validator: validatorInCluster,
303
- publicShare: publicShareForOperator,
304
- };
305
- }
306
- validateExistingBlobData(exitBlob, existingBlob, operatorIndex) {
307
- var _a, _b, _c;
308
- return __awaiter(this, void 0, void 0, function* () {
309
- if (!existingBlob) {
310
- return false;
311
- }
312
- // Check if existing blob data is for this public key
313
- const normalizeKey = (key) => (key.startsWith('0x') ? key : '0x' + key).toLowerCase();
314
- if (normalizeKey(existingBlob.public_key) !==
315
- normalizeKey(exitBlob.public_key)) {
316
- return false; // Existing blob data is for a different validator
317
- }
318
- if (existingBlob.validator_index !==
319
- exitBlob.signed_exit_message.message.validator_index) {
320
- throw new Error(`Validator index mismatch for already processed exit for public key ${exitBlob.public_key}. Expected ${existingBlob.validator_index}, got ${exitBlob.signed_exit_message.message.validator_index}.`);
321
- }
322
- const currentEpoch = Exit.safeParseInt(exitBlob.signed_exit_message.message.epoch);
323
- const existingEpoch = Exit.safeParseInt(existingBlob.epoch);
324
- if (currentEpoch < existingEpoch) {
325
- throw new Error(`New exit epoch ${currentEpoch} is not greater than existing exit epoch ${existingEpoch} for validator ${exitBlob.public_key}.`);
326
- }
327
- else if (currentEpoch === existingEpoch) {
328
- const operatorShareIndexString = String(operatorIndex);
329
- if (((_c = (_b = (_a = existingBlob.shares_exit_data) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b[operatorShareIndexString]) === null || _c === void 0 ? void 0 : _c.partial_exit_signature) &&
330
- existingBlob.shares_exit_data[0][operatorShareIndexString]
331
- .partial_exit_signature !== exitBlob.signed_exit_message.signature) {
332
- throw new Error(`Signature mismatch for validator ${exitBlob.public_key}, operator index ${operatorIndex} at epoch ${currentEpoch}. Received different signature than existing.`);
333
- }
334
- return true; // Already processed
335
- }
336
- return false;
337
- });
338
- }
339
- processExitBlob(exitBlob, clusterConfig, operatorIndex, genesisValidatorsRoot, existingBlobData) {
340
- return __awaiter(this, void 0, void 0, function* () {
341
- const { publicShare } = this.findValidatorInCluster(clusterConfig, exitBlob.public_key, operatorIndex);
342
- const alreadyProcessed = yield this.validateExistingBlobData(exitBlob, existingBlobData, operatorIndex);
343
- if (alreadyProcessed) {
344
- return null;
345
- }
346
- const isPartialSignatureValid = yield this.verifyPartialExitSignature(publicShare, exitBlob.signed_exit_message, clusterConfig.definition.fork_version, genesisValidatorsRoot);
347
- if (!isPartialSignatureValid) {
348
- throw new Error(`Invalid partial exit signature for validator ${exitBlob.public_key} by operator index ${operatorIndex}.`);
349
- }
350
- return exitBlob;
351
- });
352
- }
353
- /**
354
- * Validates exit blobs against cluster configuration and existing data.
355
- *
356
- * This method performs comprehensive validation of exit blobs including:
357
- * - Operator authorization and payload signature verification
358
- * - Network parameter validation (genesis root, fork version)
359
- * - Public key validation against cluster configuration
360
- * - Partial signature verification for each exit blob
361
- * - Duplicate detection and epoch progression validation
362
- * - Signature consistency checks for existing exits
363
- *
364
- * @param clusterConfig - The cluster configuration containing operators and distributed validators
365
- * @param exitsPayload - The exit validation payload with partial exits and operator info
366
- * @param beaconNodeApiUrl - The beacon node API URL for network parameter retrieval
367
- * @param existingBlobData - Existing exit blob data for duplicate detection, or null if none exists
368
- *
369
- * @returns Promise resolving to an array of validated, non-duplicate exit blobs
370
- *
371
- * @throws {Error} When share_idx is invalid or out of bounds for the cluster operators
372
- * @throws {Error} When payload signature verification fails
373
- * @throws {Error} When network parameters cannot be retrieved or are invalid
374
- * @throws {Error} When a public key is not found in the cluster's distributed validators
375
- * @throws {Error} When a partial exit signature is invalid
376
- * @throws {Error} When exit epoch validation fails (new epoch not greater than existing)
377
- * @throws {Error} When validator index mismatches with existing data
378
- * @throws {Error} When signature mismatches for the same epoch and operator
379
- *
380
- * @example
381
- * ```typescript
382
- * const validExitBlobs = await exit.validateExitBlobs(
383
- * {
384
- * definition: {
385
- * operators: [{ enr: "enr:-LK4Q..." }],
386
- * fork_version: "0x00000000",
387
- * threshold: 1
388
- * },
389
- * distributed_validators: [{
390
- * distributed_public_key: "0x1234...abcd",
391
- * public_shares: ["0x5678...efgh"]
392
- * }]
393
- * },
394
- * {
395
- * partial_exits: [exitBlob],
396
- * share_idx: 1,
397
- * signature: "0x1234...abcd"
398
- * },
399
- * "http://localhost:5052",
400
- * existingBlobData // or null for new exits
401
- * );
402
- * ```
403
- */
404
- validateExitBlobs(clusterConfig, exitsPayload, beaconNodeApiUrl, existingBlobData) {
405
- return __awaiter(this, void 0, void 0, function* () {
406
- yield this.validateOperatorAndPayload(clusterConfig, exitsPayload);
407
- const { genesisValidatorsRoot } = yield this.getNetworkParameters(clusterConfig.definition.fork_version, beaconNodeApiUrl);
408
- const operatorIndex = exitsPayload.share_idx - 1;
409
- const validNonDuplicateBlobs = [];
410
- for (const currentExitBlob of exitsPayload.partial_exits) {
411
- const processedBlob = yield this.processExitBlob(currentExitBlob, clusterConfig, operatorIndex, genesisValidatorsRoot, existingBlobData);
412
- if (processedBlob) {
413
- validNonDuplicateBlobs.push(processedBlob);
414
- }
415
- }
416
- return validNonDuplicateBlobs;
417
- });
418
- }
419
- /**
420
- * Recombines exit blobs into a single exit blob.
421
- *
422
- * This method aggregates partial exit signatures from multiple operators into a single exit blob.
423
- * It ensures that the signatures are properly ordered and aggregated according to the operator indices.
424
- *
425
- * @param exitBlob - The existing exit blob data containing partial exit signatures
426
- *
427
- * @returns Promise resolving to a single exit blob with aggregated signatures
428
- *
429
- * @throws {Error} When no valid signatures are found for aggregation
430
- * @throws {Error} When signature length is invalid
431
- * @throws {Error} When signature parsing fails
432
- *
433
- * @example
434
- * ```typescript
435
- * const aggregatedExitBlob = await exit.recombineExitBlobs(existingBlobData);
436
- * ```
437
- */
438
- recombineExitBlobs(exitBlob) {
439
- return __awaiter(this, void 0, void 0, function* () {
440
- yield (0, bls_1.init)('herumi');
441
- // Map to store signatures by their share index (matching Go's map[int]tbls.Signature)
442
- const signaturesByIndex = new Map();
443
- // Extract signatures from shares_exit_data (equivalent to er.Signatures in Go)
444
- if (!exitBlob.shares_exit_data || exitBlob.shares_exit_data.length === 0) {
445
- throw new Error('No shares exit data available for aggregation');
446
- }
447
- const signaturesMap = exitBlob.shares_exit_data[0] || {};
448
- for (const [sigIdxStr, sigData] of Object.entries(signaturesMap)) {
449
- const sigStr = sigData.partial_exit_signature;
450
- if (!sigStr || sigStr.length === 0) {
451
- // ignore, the associated share index didn't push a partial signature yet
452
- continue;
453
- }
454
- if (sigStr.length < 2) {
455
- throw new Error(`Signature string has invalid size: ${sigStr.length}`);
456
- }
457
- // Remove 0x prefix and ensure it's 96 bytes (192 hex chars)
458
- const cleanSigStr = sigStr.startsWith('0x')
459
- ? sigStr.substring(2)
460
- : sigStr;
461
- if (cleanSigStr.length !== 192) {
462
- throw new Error(`Invalid signature length. Expected 192 hex chars (96 bytes), got ${cleanSigStr.length}`);
463
- }
464
- try {
465
- const sigBytes = (0, ssz_1.fromHexString)(cleanSigStr);
466
- // Convert string index to number and add 1 (matching Go's sigIdx+1)
467
- const sigIdx = parseInt(sigIdxStr, 10);
468
- signaturesByIndex.set(sigIdx + 1, sigBytes);
469
- }
470
- catch (err) {
471
- throw new Error(`Invalid partial signature: ${String(err)}`);
472
- }
473
- }
474
- if (signaturesByIndex.size === 0) {
475
- throw new Error('No valid signatures found for aggregation');
476
- }
477
- // Sort by index and extract signatures in correct order
478
- const sortedIndices = Array.from(signaturesByIndex.keys()).sort((a, b) => a - b);
479
- const rawSignatures = sortedIndices.map(idx => {
480
- const signature = signaturesByIndex.get(idx);
481
- if (signature === undefined) {
482
- throw new Error(`Missing signature for index ${idx}`);
483
- }
484
- return signature;
485
- });
486
- // Aggregate signatures (equivalent to tbls.ThresholdAggregate in Go)
487
- // Note: @chainsafe/bls doesn't have explicit threshold aggregation, but ordering should be preserved
488
- const fullSig = (0, bls_1.aggregateSignatures)(rawSignatures);
489
- return {
490
- public_key: exitBlob.public_key,
491
- signed_exit_message: {
492
- message: {
493
- epoch: exitBlob.epoch,
494
- validator_index: exitBlob.validator_index,
495
- },
496
- signature: '0x' + Buffer.from(fullSig).toString('hex'),
497
- },
498
- };
499
- });
500
- }
501
- }
502
- exports.Exit = Exit;
@@ -1,86 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.signingRoot = exports.computeDomain = exports.GENESIS_VALIDATOR_ROOT_HEX_STRING = void 0;
4
- const ssz_1 = require("@chainsafe/ssz");
5
- // From obol-api/src/verification/common.ts
6
- exports.GENESIS_VALIDATOR_ROOT_HEX_STRING = '0x0000000000000000000000000000000000000000000000000000000000000000'; // Added 0x prefix
7
- const ForkDataType = new ssz_1.ContainerType({
8
- currentVersion: new ssz_1.ByteVectorType(4),
9
- genesisValidatorsRoot: new ssz_1.ByteVectorType(32),
10
- });
11
- const SigningRootType = new ssz_1.ContainerType({
12
- objectRoot: new ssz_1.ByteVectorType(32),
13
- domain: new ssz_1.ByteVectorType(32),
14
- });
15
- /**
16
- * https://github.com/ethereum/consensus-specs/blob/dev/specs/phase0/beacon-chain.md#compute_fork_data_root
17
- * @param currentVersion - Uint8Array of the current fork version.
18
- * @param genesisValidatorsRoot - Uint8Array of the genesis validators root.
19
- * @returns Uint8Array - The 32-byte fork data root.
20
- */
21
- function computeForkDataRoot(currentVersion, genesisValidatorsRoot) {
22
- const forkDataVal = ForkDataType.defaultValue();
23
- forkDataVal.currentVersion = currentVersion;
24
- forkDataVal.genesisValidatorsRoot = genesisValidatorsRoot;
25
- return Buffer.from(ForkDataType.hashTreeRoot(forkDataVal).buffer);
26
- }
27
- /**
28
- * Computes the domain for a given domain type, fork version, and genesis state.
29
- * https://github.com/ethereum/consensus-specs/blob/dev/specs/phase0/beacon-chain.md#compute_domain
30
- * @param domainType - Uint8Array representing the domain type (e.g., DOMAIN_VOLUNTARY_EXIT).
31
- * @param forkVersionString - Hex string of the fork version (e.g., Capella fork version).
32
- * @param genesisValidatorsRootOverride - Optional Uint8Array to override the default genesis validators root.
33
- * @returns Uint8Array - The 32-byte domain.
34
- */
35
- function computeDomain(domainType, // Should be 4 bytes
36
- forkVersionString, // Hex string, e.g., '0x03000000'
37
- genesisValidatorsRootOverride) {
38
- const forkVersionBytes = (0, ssz_1.fromHexString)(forkVersionString.substring(2, forkVersionString.length));
39
- if (forkVersionBytes.length !== 4) {
40
- throw new Error('Fork version must be 4 bytes');
41
- }
42
- if (domainType.length !== 4) {
43
- throw new Error('Domain type must be 4 bytes');
44
- }
45
- const actualGenesisValidatorsRoot = genesisValidatorsRootOverride !== null && genesisValidatorsRootOverride !== void 0 ? genesisValidatorsRootOverride : (0, ssz_1.fromHexString)(exports.GENESIS_VALIDATOR_ROOT_HEX_STRING.substring(2));
46
- if (actualGenesisValidatorsRoot.length !== 32) {
47
- throw new Error('genesisValidatorsRoot must be 32 bytes');
48
- }
49
- const forkDataRoot = computeForkDataRoot(forkVersionBytes, actualGenesisValidatorsRoot);
50
- const domain = new Uint8Array(32);
51
- domain.set(domainType);
52
- domain.set(forkDataRoot.subarray(0, 28), 4); // Set the remaining 28 bytes from forkDataRoot
53
- return domain;
54
- }
55
- exports.computeDomain = computeDomain;
56
- /**
57
- * Computes the signing root for an SSZ object and a domain.
58
- * https://github.com/ethereum/consensus-specs/blob/dev/specs/phase0/beacon-chain.md#compute_signing_root
59
- * @param sszObjectRoot - Uint8Array of the hash tree root of the SSZ object.
60
- * @param domain - Uint8Array of the domain.
61
- * @returns Uint8Array - The 32-byte signing root.
62
- */
63
- function computeSigningRoot(sszObjectRoot, // Should be 32 bytes
64
- domain) {
65
- if (sszObjectRoot.length !== 32) {
66
- throw new Error('SSZ object root must be 32 bytes');
67
- }
68
- if (domain.length !== 32) {
69
- throw new Error('Domain must be 32 bytes');
70
- }
71
- const val = SigningRootType.defaultValue();
72
- val.objectRoot = sszObjectRoot;
73
- val.domain = domain;
74
- return Buffer.from(SigningRootType.hashTreeRoot(val).buffer);
75
- }
76
- /**
77
- * Convenience wrapper for computeSigningRoot.
78
- * @param domain - Uint8Array of the domain.
79
- * @param messageBuffer - Buffer of the message (SSZ object root).
80
- * @returns Uint8Array - The signing root.
81
- */
82
- function signingRoot(domain, messageBuffer) {
83
- const sszObjectRootU8 = Uint8Array.from(messageBuffer);
84
- return computeSigningRoot(sszObjectRootU8, domain);
85
- }
86
- exports.signingRoot = signingRoot;
@@ -1,39 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.isClaimedFromMerkleDistributor = exports.claimIncentivesFromMerkleDistributor = void 0;
13
- const ethers_1 = require("ethers");
14
- const MerkleDistributorWithDeadline_1 = require("../abi/MerkleDistributorWithDeadline");
15
- const claimIncentivesFromMerkleDistributor = (incentivesData) => __awaiter(void 0, void 0, void 0, function* () {
16
- try {
17
- const contract = new ethers_1.Contract(incentivesData.contractAddress, MerkleDistributorWithDeadline_1.MerkleDistributorABI.abi, incentivesData.signer);
18
- const tx = yield contract.claim(BigInt(incentivesData.index), incentivesData.operatorAddress, BigInt(incentivesData.amount), incentivesData.merkleProof);
19
- const receipt = yield tx.wait();
20
- return { txHash: receipt.hash };
21
- }
22
- catch (error) {
23
- console.log('Error claiming incentives:', error);
24
- throw new Error(`Failed to claim incentives: ${error.message}`);
25
- }
26
- });
27
- exports.claimIncentivesFromMerkleDistributor = claimIncentivesFromMerkleDistributor;
28
- const isClaimedFromMerkleDistributor = (contractAddress, index, provider) => __awaiter(void 0, void 0, void 0, function* () {
29
- try {
30
- const contract = new ethers_1.Contract(contractAddress, MerkleDistributorWithDeadline_1.MerkleDistributorABI.abi, provider);
31
- const claimed = yield contract.isClaimed(BigInt(index));
32
- return claimed;
33
- }
34
- catch (error) {
35
- console.log('Error checking claim status:', error);
36
- throw new Error(`Failed to check claim status: ${error.message}`);
37
- }
38
- });
39
- exports.isClaimedFromMerkleDistributor = isClaimedFromMerkleDistributor;