@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,374 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { Exit } from '../../src/exits/exit';
11
- import * as ethUtils from '../../src/exits/ethUtils';
12
- import * as bls from '@chainsafe/bls';
13
- import { ENR } from '@chainsafe/discv5';
14
- import * as elliptic from 'elliptic';
15
- import { CAPELLA_FORK_MAPPING } from '../../src/constants';
16
- import { fromHexString } from '@chainsafe/ssz';
17
- import * as verificationHelpers from '../../src/exits/verificationHelpers';
18
- // --- Mocks ---
19
- jest.mock('../../src/exits/ethUtils');
20
- jest.mock('@chainsafe/bls', () => {
21
- const actual = jest.requireActual('@chainsafe/bls');
22
- return Object.assign(Object.assign({ __esModule: true }, actual), { init: jest.fn(), verify: jest.fn(), aggregateSignatures: jest.fn() });
23
- });
24
- // ENR and elliptic will be spied on, not fully mocked at module level for more flexibility
25
- const mockedEthUtils = ethUtils;
26
- const mockedBls = bls;
27
- // --- Test Data ---
28
- const MAINNET_BASE_FORK_VERSION = '0x00000000';
29
- const MAINNET_CAPELLA_FORK_VERSION = CAPELLA_FORK_MAPPING[MAINNET_BASE_FORK_VERSION];
30
- const MOCK_GENESIS_ROOT = '0x0000000000000000000000000000000000000000000000000000000000000001';
31
- const MOCK_BEACON_API_URL = 'http://localhost:5052';
32
- const mockOperatorEnr = 'enr:-LK4QFo_n0dUm4PKejSOXf8JkSWq5EINV0XhG1zY00d22QpYdyxSAyQNsGkYQyKR5Ohe2kEkmS0nS31tuqVfXDNf_vEAhGV0aAgQD___2iXChwcEChAgAAAAADg__________g2V0aMfLCGgohEAcNlBpLdCgAAAQAdIaENsZS0CAAAABAAAAAAAAAAAAAAAAAAAAACAAAAAAAAAAIAAAAAAAAAAIAAAAAAAAAYAAAAAAAAAAAAAAAAAAAIQA___________gmlkgnY0gmlwhH8AAAGJc2VjcDI1NmsxoQPKwrO7sVJzX4B2vW1bTqWCpGA93R2aZqa2ZCrqSrh8CYN1ZHCCIyg';
33
- const mockOperatorPublicKeyHex = '03ca0aceeec549cd7f8076bd6d5b4ea582a4603ddd1d9a66a6b6642aeaa4ae1f09';
34
- const mockExitMessage = {
35
- epoch: '1',
36
- validator_index: '10',
37
- };
38
- const mockSignedExitMessage = {
39
- message: mockExitMessage,
40
- signature: '0x' + 'ab'.repeat(96),
41
- };
42
- const mockExitBlob = {
43
- public_key: '0x' + 'cd'.repeat(48),
44
- signed_exit_message: mockSignedExitMessage,
45
- };
46
- const mockExitPayload = {
47
- partial_exits: [mockExitBlob],
48
- share_idx: 1,
49
- signature: '0x' + 'ef'.repeat(65),
50
- };
51
- // Make mockClusterConfig directly ExitClusterConfig for easier use in tests
52
- const mockClusterConfig = {
53
- definition: {
54
- operators: [{ enr: mockOperatorEnr }],
55
- fork_version: MAINNET_BASE_FORK_VERSION,
56
- threshold: 1,
57
- },
58
- distributed_validators: [
59
- {
60
- distributed_public_key: mockExitBlob.public_key,
61
- public_shares: ['0x' + 'aa'.repeat(48)],
62
- },
63
- ],
64
- };
65
- const mockExistingBlobData = {
66
- public_key: mockExitBlob.public_key,
67
- epoch: mockExitMessage.epoch,
68
- validator_index: mockExitMessage.validator_index,
69
- shares_exit_data: [],
70
- };
71
- describe('exit', () => {
72
- let enrDecodeTxtSpy;
73
- let ecVerifySpy;
74
- let keyFromPublicSpy;
75
- let exit;
76
- beforeEach(() => {
77
- jest.resetAllMocks();
78
- exit = new Exit(1, null);
79
- mockedBls.init.mockResolvedValue(undefined);
80
- mockedBls.verify.mockReturnValue(true);
81
- mockedEthUtils.getCapellaFork.mockResolvedValue(MAINNET_CAPELLA_FORK_VERSION);
82
- mockedEthUtils.getGenesisValidatorsRoot.mockResolvedValue(MOCK_GENESIS_ROOT);
83
- const mockDecodedENR = {
84
- publicKey: Buffer.from(mockOperatorPublicKeyHex, 'hex'),
85
- };
86
- enrDecodeTxtSpy = jest
87
- .spyOn(ENR, 'decodeTxt')
88
- .mockReturnValue(mockDecodedENR);
89
- ecVerifySpy = jest.fn().mockReturnValue(true);
90
- keyFromPublicSpy = jest.spyOn(elliptic.ec.prototype, 'keyFromPublic');
91
- keyFromPublicSpy.mockImplementation(function () {
92
- return { verify: ecVerifySpy };
93
- });
94
- });
95
- afterEach(() => {
96
- if (enrDecodeTxtSpy)
97
- enrDecodeTxtSpy.mockRestore();
98
- jest.restoreAllMocks();
99
- });
100
- describe('verifyPartialExitSignature', () => {
101
- const publicShareKey = mockClusterConfig.distributed_validators[0].public_shares[0];
102
- it('should return true for a valid signature', () => __awaiter(void 0, void 0, void 0, function* () {
103
- const isValid = yield exit.verifyPartialExitSignature(publicShareKey, mockSignedExitMessage, MAINNET_BASE_FORK_VERSION, MOCK_GENESIS_ROOT);
104
- expect(isValid).toBe(true);
105
- expect(mockedBls.init).toHaveBeenCalledWith('herumi');
106
- expect(mockedBls.verify).toHaveBeenCalled();
107
- expect(mockedEthUtils.getCapellaFork).toHaveBeenCalledWith(MAINNET_BASE_FORK_VERSION);
108
- }));
109
- it('should return false if BLS verification fails', () => __awaiter(void 0, void 0, void 0, function* () {
110
- mockedBls.verify.mockReturnValue(false);
111
- const isValid = yield exit.verifyPartialExitSignature(publicShareKey, mockSignedExitMessage, MAINNET_BASE_FORK_VERSION, MOCK_GENESIS_ROOT);
112
- expect(isValid).toBe(false);
113
- }));
114
- it('should throw if getCapellaFork returns null', () => __awaiter(void 0, void 0, void 0, function* () {
115
- mockedEthUtils.getCapellaFork.mockResolvedValue(null);
116
- yield expect(exit.verifyPartialExitSignature(publicShareKey, mockSignedExitMessage, MAINNET_BASE_FORK_VERSION, MOCK_GENESIS_ROOT)).rejects.toThrow('Could not determine Capella fork version');
117
- }));
118
- it('should call computeDomain and signingRoot with correct parameters', () => __awaiter(void 0, void 0, void 0, function* () {
119
- const computeDomainSpy = jest.spyOn(verificationHelpers, 'computeDomain');
120
- const signingRootSpy = jest.spyOn(verificationHelpers, 'signingRoot');
121
- yield exit.verifyPartialExitSignature(publicShareKey, mockSignedExitMessage, MAINNET_BASE_FORK_VERSION, MOCK_GENESIS_ROOT);
122
- expect(computeDomainSpy).toHaveBeenCalledWith(fromHexString('04000000'), MAINNET_CAPELLA_FORK_VERSION, fromHexString(MOCK_GENESIS_ROOT.substring(2)));
123
- expect(signingRootSpy).toHaveBeenCalled();
124
- computeDomainSpy.mockRestore();
125
- signingRootSpy.mockRestore();
126
- }));
127
- });
128
- describe('verifyExitPayloadSignature', () => {
129
- it('should return true for a valid ECDSA signature', () => __awaiter(void 0, void 0, void 0, function* () {
130
- const isValid = yield exit.verifyExitPayloadSignature(mockOperatorEnr, mockExitPayload);
131
- expect(isValid).toBe(true);
132
- expect(enrDecodeTxtSpy).toHaveBeenCalledWith(mockOperatorEnr);
133
- expect(ecVerifySpy).toHaveBeenCalled();
134
- }));
135
- it('should return false if ECDSA verification fails', () => __awaiter(void 0, void 0, void 0, function* () {
136
- ecVerifySpy.mockReturnValue(false);
137
- const isValid = yield exit.verifyExitPayloadSignature(mockOperatorEnr, mockExitPayload);
138
- expect(isValid).toBe(false);
139
- }));
140
- it('should throw if ENR is invalid', () => __awaiter(void 0, void 0, void 0, function* () {
141
- enrDecodeTxtSpy.mockImplementation(() => {
142
- throw new Error('Invalid ENR');
143
- });
144
- yield expect(exit.verifyExitPayloadSignature('invalid-enr', mockExitPayload)).rejects.toThrow('Invalid ENR string');
145
- }));
146
- it('should throw if signature hex is not 128 characters (excluding 0x)', () => __awaiter(void 0, void 0, void 0, function* () {
147
- const payloadWithInvalidSig = Object.assign(Object.assign({}, mockExitPayload), { signature: '0x123456' });
148
- yield expect(exit.verifyExitPayloadSignature(mockOperatorEnr, payloadWithInvalidSig)).rejects.toThrow('Invalid signature length');
149
- }));
150
- });
151
- describe('validateExitBlobs', () => {
152
- it('should successfully validate a new, valid exit blob', () => __awaiter(void 0, void 0, void 0, function* () {
153
- const result = yield exit.validateExitBlobs(mockClusterConfig, mockExitPayload, MOCK_BEACON_API_URL, null);
154
- expect(result).toEqual([mockExitBlob]);
155
- expect(ecVerifySpy).toHaveBeenCalled(); // Called by internal verifyExitPayloadSignature
156
- expect(mockedBls.verify).toHaveBeenCalled(); // Called by internal verifyPartialExitSignature
157
- }));
158
- it('should throw if operatorIndex (from share_idx) is out of bounds', () => __awaiter(void 0, void 0, void 0, function* () {
159
- const invalidPayload = Object.assign(Object.assign({}, mockExitPayload), { share_idx: 0 });
160
- yield expect(exit.validateExitBlobs(mockClusterConfig, invalidPayload, MOCK_BEACON_API_URL, mockExistingBlobData)).rejects.toThrow('Invalid share_idx');
161
- const invalidPayload2 = Object.assign(Object.assign({}, mockExitPayload), { share_idx: mockClusterConfig.definition.operators.length + 1 });
162
- yield expect(exit.validateExitBlobs(mockClusterConfig, invalidPayload2, MOCK_BEACON_API_URL, mockExistingBlobData)).rejects.toThrow('Invalid share_idx');
163
- }));
164
- it('should throw if payload signature is invalid', () => __awaiter(void 0, void 0, void 0, function* () {
165
- ecVerifySpy.mockReturnValue(false);
166
- yield expect(exit.validateExitBlobs(mockClusterConfig, mockExitPayload, MOCK_BEACON_API_URL, mockExistingBlobData)).rejects.toThrow('Incorrect payload signature');
167
- }));
168
- it('should throw if getGenesisValidatorsRoot returns null', () => __awaiter(void 0, void 0, void 0, function* () {
169
- mockedEthUtils.getGenesisValidatorsRoot.mockResolvedValue(null);
170
- yield expect(exit.validateExitBlobs(mockClusterConfig, mockExitPayload, MOCK_BEACON_API_URL, mockExistingBlobData)).rejects.toThrow('Could not retrieve genesis validators root');
171
- }));
172
- it('should throw if getCapellaFork returns null (unsupported network)', () => __awaiter(void 0, void 0, void 0, function* () {
173
- mockedEthUtils.getCapellaFork.mockResolvedValue(null);
174
- yield expect(exit.validateExitBlobs(mockClusterConfig, mockExitPayload, MOCK_BEACON_API_URL, mockExistingBlobData)).rejects.toThrow('Unsupported network: Could not determine Capella fork');
175
- }));
176
- it('should throw if a public key in an exit blob is not found in cluster config', () => __awaiter(void 0, void 0, void 0, function* () {
177
- const blobWithUnknownKey = Object.assign(Object.assign({}, mockExitBlob), { public_key: '0x' + 'deadbeef'.repeat(12) });
178
- const payloadWithUnknownKey = Object.assign(Object.assign({}, mockExitPayload), { partial_exits: [blobWithUnknownKey] });
179
- yield expect(exit.validateExitBlobs(mockClusterConfig, payloadWithUnknownKey, MOCK_BEACON_API_URL, null)).rejects.toThrow("Public key 0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef not found in the cluster's distributed validators.");
180
- }));
181
- it('should throw if a partial exit signature is invalid', () => __awaiter(void 0, void 0, void 0, function* () {
182
- mockedBls.verify.mockReturnValue(false);
183
- yield expect(exit.validateExitBlobs(mockClusterConfig, mockExitPayload, MOCK_BEACON_API_URL, null)).rejects.toThrow('Invalid partial exit signature for validator 0xcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd by operator index 0.');
184
- }));
185
- it('should return an empty array if an exit blob has already been processed (epoch match)', () => __awaiter(void 0, void 0, void 0, function* () {
186
- const result = yield exit.validateExitBlobs(mockClusterConfig, mockExitPayload, MOCK_BEACON_API_URL, mockExistingBlobData);
187
- expect(result).toEqual([]);
188
- }));
189
- it('should throw if an exit blob has been processed with a different validator index', () => __awaiter(void 0, void 0, void 0, function* () {
190
- const existingBlobWithDifferentIndex = {
191
- public_key: mockExitBlob.public_key,
192
- epoch: mockExitMessage.epoch,
193
- validator_index: (parseInt(mockExitMessage.validator_index, 10) + 1).toString(), // Different index
194
- shares_exit_data: [],
195
- };
196
- yield expect(exit.validateExitBlobs(mockClusterConfig, mockExitPayload, MOCK_BEACON_API_URL, existingBlobWithDifferentIndex)).rejects.toThrow('Validator index mismatch for already processed exit for public key 0xcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd. Expected 11, got 10.');
197
- }));
198
- it('should throw if an exit blob has been processed with a higher epoch', () => __awaiter(void 0, void 0, void 0, function* () {
199
- const existingBlobWithHigherEpoch = {
200
- public_key: mockExitBlob.public_key,
201
- epoch: (parseInt(mockExitMessage.epoch, 10) + 1).toString(), // Existing epoch is HIGHER (e.g. 2)
202
- validator_index: mockExitMessage.validator_index,
203
- shares_exit_data: [],
204
- };
205
- // currentExitBlob (from mockExitPayload) has mockExitMessage.epoch (e.g. '1')
206
- yield expect(exit.validateExitBlobs(mockClusterConfig, mockExitPayload, MOCK_BEACON_API_URL, existingBlobWithHigherEpoch)).rejects.toThrow('New exit epoch 1 is not greater than existing exit epoch 2 for validator 0xcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd.');
207
- }));
208
- it('should successfully validate if an exit blob has been processed with a lower epoch', () => __awaiter(void 0, void 0, void 0, function* () {
209
- const existingBlobWithLowerEpoch = {
210
- public_key: mockExitBlob.public_key,
211
- epoch: (parseInt(mockExitMessage.epoch, 10) - 1).toString(),
212
- validator_index: mockExitMessage.validator_index,
213
- shares_exit_data: [],
214
- };
215
- const result = yield exit.validateExitBlobs(mockClusterConfig, mockExitPayload, MOCK_BEACON_API_URL, existingBlobWithLowerEpoch);
216
- expect(result).toEqual([mockExitBlob]);
217
- }));
218
- it('should throw on signature mismatch for existing blob with same epoch', () => __awaiter(void 0, void 0, void 0, function* () {
219
- const operatorIndex = 0;
220
- const operatorShareIndexString = String(operatorIndex);
221
- const existingBlobWithDifferentSignature = {
222
- public_key: mockExitBlob.public_key,
223
- epoch: mockExitMessage.epoch,
224
- validator_index: mockExitMessage.validator_index,
225
- shares_exit_data: [
226
- {
227
- [operatorShareIndexString]: {
228
- partial_exit_signature: '0x' + 'different'.repeat(16),
229
- },
230
- },
231
- ],
232
- };
233
- yield expect(exit.validateExitBlobs(mockClusterConfig, mockExitPayload, MOCK_BEACON_API_URL, existingBlobWithDifferentSignature)).rejects.toThrow('Signature mismatch for validator 0xcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd, operator index 0 at epoch 1.');
234
- }));
235
- it('should handle multiple blobs, some new, some already processed', () => __awaiter(void 0, void 0, void 0, function* () {
236
- const anotherMockExitBlob = {
237
- public_key: '0x' + '11'.repeat(48),
238
- signed_exit_message: {
239
- message: { epoch: '2', validator_index: '20' },
240
- signature: '0x' + 'bb'.repeat(96),
241
- },
242
- };
243
- const payloadWithTwoBlobs = Object.assign(Object.assign({}, mockExitPayload), { partial_exits: [mockExitBlob, anotherMockExitBlob] });
244
- const clusterConfigWithTwoValidators = Object.assign(Object.assign({}, mockClusterConfig), { distributed_validators: [
245
- ...mockClusterConfig.distributed_validators,
246
- {
247
- distributed_public_key: anotherMockExitBlob.public_key,
248
- public_shares: ['0x' + 'cc'.repeat(48)],
249
- },
250
- ] });
251
- // Only the first blob has existing data, second is new
252
- const existingBlobDataForFirstOnly = {
253
- public_key: mockExitBlob.public_key,
254
- epoch: mockExitMessage.epoch,
255
- validator_index: mockExitMessage.validator_index,
256
- shares_exit_data: [],
257
- };
258
- const result = yield exit.validateExitBlobs(clusterConfigWithTwoValidators, payloadWithTwoBlobs, MOCK_BEACON_API_URL, existingBlobDataForFirstOnly);
259
- expect(result.length).toBe(1);
260
- expect(result[0]).toEqual(anotherMockExitBlob);
261
- }));
262
- it('should throw if getGenesisValidatorsRoot itself throws an error', () => __awaiter(void 0, void 0, void 0, function* () {
263
- mockedEthUtils.getGenesisValidatorsRoot.mockRejectedValue(new Error('Beacon node unavailable'));
264
- yield expect(exit.validateExitBlobs(mockClusterConfig, mockExitPayload, MOCK_BEACON_API_URL, mockExistingBlobData)).rejects.toThrow('Beacon node unavailable');
265
- }));
266
- // Additional test cases to match API service coverage
267
- it('should handle public key format differences (with and without 0x prefix)', () => __awaiter(void 0, void 0, void 0, function* () {
268
- const blobWithoutPrefix = Object.assign(Object.assign({}, mockExitBlob), { public_key: 'cd'.repeat(48) });
269
- const payloadWithoutPrefix = Object.assign(Object.assign({}, mockExitPayload), { partial_exits: [blobWithoutPrefix] });
270
- const clusterConfigWithoutPrefix = Object.assign(Object.assign({}, mockClusterConfig), { distributed_validators: [
271
- {
272
- distributed_public_key: '0x' + 'cd'.repeat(48), // With 0x prefix
273
- public_shares: ['0x' + 'aa'.repeat(48)],
274
- },
275
- ] });
276
- const result = yield exit.validateExitBlobs(clusterConfigWithoutPrefix, payloadWithoutPrefix, MOCK_BEACON_API_URL, null);
277
- expect(result).toEqual([blobWithoutPrefix]);
278
- }));
279
- it('should handle public key case differences', () => __awaiter(void 0, void 0, void 0, function* () {
280
- const blobWithUppercase = Object.assign(Object.assign({}, mockExitBlob), { public_key: '0x' + 'CD'.repeat(48) });
281
- const payloadWithUppercase = Object.assign(Object.assign({}, mockExitPayload), { partial_exits: [blobWithUppercase] });
282
- const clusterConfigWithLowercase = Object.assign(Object.assign({}, mockClusterConfig), { distributed_validators: [
283
- {
284
- distributed_public_key: '0x' + 'cd'.repeat(48), // Lowercase
285
- public_shares: ['0x' + 'aa'.repeat(48)],
286
- },
287
- ] });
288
- const result = yield exit.validateExitBlobs(clusterConfigWithLowercase, payloadWithUppercase, MOCK_BEACON_API_URL, null);
289
- expect(result).toEqual([blobWithUppercase]);
290
- }));
291
- it('should throw if public share for operator index is not found', () => __awaiter(void 0, void 0, void 0, function* () {
292
- const clusterConfigWithMissingShare = Object.assign(Object.assign({}, mockClusterConfig), { distributed_validators: [
293
- {
294
- distributed_public_key: mockExitBlob.public_key,
295
- public_shares: [], // Empty public shares array
296
- },
297
- ] });
298
- yield expect(exit.validateExitBlobs(clusterConfigWithMissingShare, mockExitPayload, MOCK_BEACON_API_URL, mockExistingBlobData)).rejects.toThrow('Public share for operator index 0 not found for validator 0xcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd');
299
- }));
300
- });
301
- describe('recombineExitBlobs', () => {
302
- it('should successfully recombine signatures into a single exit blob', () => __awaiter(void 0, void 0, void 0, function* () {
303
- const mockExistingBlob = {
304
- public_key: '0x' + '1234'.repeat(24),
305
- epoch: '100',
306
- validator_index: '200',
307
- shares_exit_data: [
308
- {
309
- 0: { partial_exit_signature: '0x' + 'a0'.repeat(96) },
310
- 2: { partial_exit_signature: '0x' + 'a2'.repeat(96) }, // Note non-sequential indices
311
- 1: { partial_exit_signature: '0x' + 'a1'.repeat(96) },
312
- },
313
- ],
314
- };
315
- const expectedAggregatedSig = '0x' + 'ff'.repeat(96);
316
- const expectedAggregatedSigBytes = fromHexString(expectedAggregatedSig);
317
- mockedBls.aggregateSignatures.mockReturnValue(expectedAggregatedSigBytes);
318
- const result = yield exit.recombineExitBlobs(mockExistingBlob);
319
- expect(mockedBls.init).toHaveBeenCalledWith('herumi');
320
- expect(mockedBls.aggregateSignatures).toHaveBeenCalledTimes(1);
321
- const calls = mockedBls.aggregateSignatures.mock.calls;
322
- const rawSignatures = calls[0][0];
323
- // Check if signatures were passed in sorted order of operator index
324
- expect(rawSignatures[0]).toEqual(fromHexString('a0'.repeat(96)));
325
- expect(rawSignatures[1]).toEqual(fromHexString('a1'.repeat(96)));
326
- expect(rawSignatures[2]).toEqual(fromHexString('a2'.repeat(96)));
327
- expect(result).toEqual({
328
- public_key: mockExistingBlob.public_key,
329
- signed_exit_message: {
330
- message: {
331
- epoch: mockExistingBlob.epoch,
332
- validator_index: mockExistingBlob.validator_index,
333
- },
334
- signature: expectedAggregatedSig,
335
- },
336
- });
337
- }));
338
- it('should throw if no valid signatures are found', () => __awaiter(void 0, void 0, void 0, function* () {
339
- const mockExistingBlob = {
340
- public_key: '0x' + '1234'.repeat(24),
341
- epoch: '100',
342
- validator_index: '200',
343
- shares_exit_data: [
344
- {
345
- 0: { partial_exit_signature: '' }, // empty sig
346
- },
347
- ],
348
- };
349
- yield expect(exit.recombineExitBlobs(mockExistingBlob)).rejects.toThrow('No valid signatures found for aggregation');
350
- }));
351
- it('should throw on invalid signature length', () => __awaiter(void 0, void 0, void 0, function* () {
352
- const mockExistingBlob = {
353
- public_key: '0x' + '1234'.repeat(24),
354
- epoch: '100',
355
- validator_index: '200',
356
- shares_exit_data: [
357
- {
358
- 0: { partial_exit_signature: '0x1234' },
359
- },
360
- ],
361
- };
362
- yield expect(exit.recombineExitBlobs(mockExistingBlob)).rejects.toThrow('Invalid signature length');
363
- }));
364
- it('should handle empty shares_exit_data', () => __awaiter(void 0, void 0, void 0, function* () {
365
- const mockExistingBlob = {
366
- public_key: '0x' + '1234'.repeat(24),
367
- epoch: '100',
368
- validator_index: '200',
369
- shares_exit_data: [],
370
- };
371
- yield expect(exit.recombineExitBlobs(mockExistingBlob)).rejects.toThrow('No shares exit data available for aggregation');
372
- }));
373
- });
374
- });
@@ -1,66 +0,0 @@
1
- import { computeDomain, signingRoot, GENESIS_VALIDATOR_ROOT_HEX_STRING, } from '../../src/exits/verificationHelpers';
2
- import { CAPELLA_FORK_MAPPING } from '../../src/constants'; // Assuming this contains fork versions
3
- import { fromHexString } from '@chainsafe/ssz';
4
- // Mock data similar to what's used in obol-api tests or common scenarios
5
- const DOMAIN_VOLUNTARY_EXIT_HEX = '0x04000000';
6
- const MAINNET_BASE_FORK_VERSION = '0x00000000';
7
- const MAINNET_CAPELLA_FORK_VERSION = CAPELLA_FORK_MAPPING[MAINNET_BASE_FORK_VERSION]; // '0x03000000'
8
- // Sample SSZ Object Root (32 bytes, replace with a realistic one if available from other tests)
9
- const MOCK_SSZ_OBJECT_ROOT_HEX = '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef';
10
- describe('verificationHelpers', () => {
11
- describe('computeDomain', () => {
12
- it('should compute a domain with default genesis root', () => {
13
- const domainType = fromHexString(DOMAIN_VOLUNTARY_EXIT_HEX.substring(2));
14
- const domain = computeDomain(domainType, MAINNET_CAPELLA_FORK_VERSION);
15
- expect(domain).toBeInstanceOf(Uint8Array);
16
- expect(domain.length).toBe(32);
17
- // Add more specific expectation if a known domain value exists for these inputs
18
- });
19
- it('should compute a domain with a custom genesis root', () => {
20
- const domainType = fromHexString(DOMAIN_VOLUNTARY_EXIT_HEX.substring(2));
21
- const customGenesisRoot = fromHexString(MOCK_SSZ_OBJECT_ROOT_HEX.substring(2)); // Using a mock root
22
- const domain = computeDomain(domainType, MAINNET_CAPELLA_FORK_VERSION, customGenesisRoot);
23
- expect(domain).toBeInstanceOf(Uint8Array);
24
- expect(domain.length).toBe(32);
25
- // Add more specific expectation if a known domain value exists
26
- });
27
- it('should use GENESIS_VALIDATOR_ROOT_HEX_STRING when override is undefined', () => {
28
- const domainType = fromHexString(DOMAIN_VOLUNTARY_EXIT_HEX.substring(2));
29
- const domain1 = computeDomain(domainType, MAINNET_CAPELLA_FORK_VERSION);
30
- const domain2 = computeDomain(domainType, MAINNET_CAPELLA_FORK_VERSION, fromHexString(GENESIS_VALIDATOR_ROOT_HEX_STRING.substring(2)));
31
- expect(domain1).toEqual(domain2);
32
- });
33
- it('should throw an error for invalid fork version hex string (e.g. too short)', () => {
34
- const domainType = fromHexString(DOMAIN_VOLUNTARY_EXIT_HEX.substring(2));
35
- // Example of an invalid (too short) fork version string
36
- const invalidForkVersion = '0x0300';
37
- expect(() => computeDomain(domainType, invalidForkVersion)).toThrow();
38
- });
39
- it('should throw an error for invalid domainType (e.g. not 4 bytes)', () => {
40
- const invalidDomainType = fromHexString('010203'); // 3 bytes
41
- expect(() => computeDomain(invalidDomainType, MAINNET_CAPELLA_FORK_VERSION)).toThrow();
42
- });
43
- });
44
- describe('signingRoot', () => {
45
- it('should compute a signing root', () => {
46
- const domainType = fromHexString(DOMAIN_VOLUNTARY_EXIT_HEX.substring(2));
47
- const domain = computeDomain(domainType, MAINNET_CAPELLA_FORK_VERSION);
48
- const messageBuffer = Buffer.from(MOCK_SSZ_OBJECT_ROOT_HEX.substring(2), 'hex');
49
- const root = signingRoot(domain, messageBuffer);
50
- expect(root).toBeInstanceOf(Uint8Array);
51
- expect(root.length).toBe(32);
52
- // Add more specific expectation if a known signing root value exists
53
- });
54
- it('should throw if domain is not 32 bytes', () => {
55
- const invalidDomain = new Uint8Array(31); // Not 32 bytes
56
- const messageBuffer = Buffer.from(MOCK_SSZ_OBJECT_ROOT_HEX.substring(2), 'hex');
57
- expect(() => signingRoot(invalidDomain, messageBuffer)).toThrow();
58
- });
59
- it('should throw if messageBuffer is not 32 bytes', () => {
60
- const domainType = fromHexString(DOMAIN_VOLUNTARY_EXIT_HEX.substring(2));
61
- const domain = computeDomain(domainType, MAINNET_CAPELLA_FORK_VERSION);
62
- const invalidMessageBuffer = Buffer.from('0102030405060708', 'hex'); // Not 32 bytes
63
- expect(() => signingRoot(domain, invalidMessageBuffer)).toThrow();
64
- });
65
- });
66
- });