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

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 (140) hide show
  1. package/dist/cjs/src/index.js +17457 -382
  2. package/dist/cjs/src/index.js.map +1 -0
  3. package/dist/esm/src/index.js +17424 -361
  4. package/dist/esm/src/index.js.map +1 -0
  5. package/dist/types/src/constants.d.ts +1 -2
  6. package/dist/types/src/eoa/eoaHelpers.d.ts +1 -1
  7. package/dist/types/src/exits/verificationHelpers.d.ts +0 -2
  8. package/dist/types/src/incentives/incentiveHelpers.d.ts +1 -1
  9. package/dist/types/src/splits/splitHelpers.d.ts +3 -3
  10. package/dist/types/src/utils.d.ts +2 -2
  11. package/dist/types/src/verification/common.d.ts +0 -2
  12. package/dist/types/src/verification/signature-validator.d.ts +4 -4
  13. package/dist/types/src/verification/v1.10.0.d.ts +1 -1
  14. package/dist/types/src/verification/v1.6.0.d.ts +1 -1
  15. package/dist/types/src/verification/v1.7.0.d.ts +1 -1
  16. package/dist/types/src/verification/v1.8.0.d.ts +1 -1
  17. package/dist/types/test/client/methods.spec.d.ts +17 -0
  18. package/dist/types/tsconfig.types.tsbuildinfo +1 -0
  19. package/dist/types/tsup.config.d.ts +2 -0
  20. package/package.json +79 -54
  21. package/dist/cjs/package.json +0 -139
  22. package/dist/cjs/src/abi/BatchDeposit.js +0 -120
  23. package/dist/cjs/src/abi/MerkleDistributorWithDeadline.js +0 -73
  24. package/dist/cjs/src/abi/Multicall3.js +0 -253
  25. package/dist/cjs/src/abi/OVM.js +0 -627
  26. package/dist/cjs/src/abi/OWR.js +0 -304
  27. package/dist/cjs/src/abi/SplitMain.js +0 -929
  28. package/dist/cjs/src/abi/splitV2FactoryAbi.js +0 -420
  29. package/dist/cjs/src/ajv.js +0 -136
  30. package/dist/cjs/src/base.js +0 -42
  31. package/dist/cjs/src/bytecodes.js +0 -19
  32. package/dist/cjs/src/constants.js +0 -272
  33. package/dist/cjs/src/eoa/eoa.js +0 -132
  34. package/dist/cjs/src/eoa/eoaHelpers.js +0 -82
  35. package/dist/cjs/src/errors.js +0 -11
  36. package/dist/cjs/src/exits/ethUtils.js +0 -57
  37. package/dist/cjs/src/exits/exit.js +0 -502
  38. package/dist/cjs/src/exits/verificationHelpers.js +0 -86
  39. package/dist/cjs/src/incentives/incentiveHelpers.js +0 -39
  40. package/dist/cjs/src/incentives/incentives.js +0 -119
  41. package/dist/cjs/src/schema.js +0 -352
  42. package/dist/cjs/src/services.js +0 -33
  43. package/dist/cjs/src/splits/splitHelpers.js +0 -571
  44. package/dist/cjs/src/splits/splits.js +0 -366
  45. package/dist/cjs/src/types.js +0 -29
  46. package/dist/cjs/src/utils.js +0 -77
  47. package/dist/cjs/src/verification/common.js +0 -355
  48. package/dist/cjs/src/verification/signature-validator.js +0 -73
  49. package/dist/cjs/src/verification/sszTypes.js +0 -69
  50. package/dist/cjs/src/verification/termsAndConditions.js +0 -40
  51. package/dist/cjs/src/verification/v1.10.0.js +0 -146
  52. package/dist/cjs/src/verification/v1.6.0.js +0 -149
  53. package/dist/cjs/src/verification/v1.7.0.js +0 -173
  54. package/dist/cjs/src/verification/v1.8.0.js +0 -196
  55. package/dist/cjs/test/client/ajv.spec.js +0 -320
  56. package/dist/cjs/test/client/methods.spec.js +0 -418
  57. package/dist/cjs/test/eoa/eoa.spec.js +0 -176
  58. package/dist/cjs/test/exit/ethUtils.spec.js +0 -83
  59. package/dist/cjs/test/exit/exit.spec.js +0 -399
  60. package/dist/cjs/test/exit/verificationHelpers.spec.js +0 -68
  61. package/dist/cjs/test/fixtures.js +0 -896
  62. package/dist/cjs/test/incentives/incentives.spec.js +0 -202
  63. package/dist/cjs/test/splits/splits.spec.js +0 -402
  64. package/dist/esm/package.json +0 -139
  65. package/dist/esm/src/abi/BatchDeposit.js +0 -117
  66. package/dist/esm/src/abi/MerkleDistributorWithDeadline.js +0 -70
  67. package/dist/esm/src/abi/Multicall3.js +0 -250
  68. package/dist/esm/src/abi/OVM.js +0 -624
  69. package/dist/esm/src/abi/OWR.js +0 -301
  70. package/dist/esm/src/abi/SplitMain.js +0 -926
  71. package/dist/esm/src/abi/splitV2FactoryAbi.js +0 -417
  72. package/dist/esm/src/ajv.js +0 -129
  73. package/dist/esm/src/base.js +0 -38
  74. package/dist/esm/src/bytecodes.js +0 -16
  75. package/dist/esm/src/constants.js +0 -238
  76. package/dist/esm/src/eoa/eoa.js +0 -128
  77. package/dist/esm/src/eoa/eoaHelpers.js +0 -77
  78. package/dist/esm/src/errors.js +0 -7
  79. package/dist/esm/src/exits/ethUtils.js +0 -52
  80. package/dist/esm/src/exits/exit.js +0 -475
  81. package/dist/esm/src/exits/verificationHelpers.js +0 -81
  82. package/dist/esm/src/incentives/incentiveHelpers.js +0 -34
  83. package/dist/esm/src/incentives/incentives.js +0 -115
  84. package/dist/esm/src/schema.js +0 -349
  85. package/dist/esm/src/services.js +0 -29
  86. package/dist/esm/src/splits/splitHelpers.js +0 -554
  87. package/dist/esm/src/splits/splits.js +0 -362
  88. package/dist/esm/src/types.js +0 -26
  89. package/dist/esm/src/utils.js +0 -68
  90. package/dist/esm/src/verification/common.js +0 -319
  91. package/dist/esm/src/verification/signature-validator.js +0 -64
  92. package/dist/esm/src/verification/sszTypes.js +0 -64
  93. package/dist/esm/src/verification/termsAndConditions.js +0 -33
  94. package/dist/esm/src/verification/v1.10.0.js +0 -140
  95. package/dist/esm/src/verification/v1.6.0.js +0 -142
  96. package/dist/esm/src/verification/v1.7.0.js +0 -166
  97. package/dist/esm/src/verification/v1.8.0.js +0 -189
  98. package/dist/esm/test/client/ajv.spec.js +0 -318
  99. package/dist/esm/test/client/methods.spec.js +0 -393
  100. package/dist/esm/test/eoa/eoa.spec.js +0 -174
  101. package/dist/esm/test/exit/ethUtils.spec.js +0 -81
  102. package/dist/esm/test/exit/exit.spec.js +0 -374
  103. package/dist/esm/test/exit/verificationHelpers.spec.js +0 -66
  104. package/dist/esm/test/fixtures.js +0 -893
  105. package/dist/esm/test/incentives/incentives.spec.js +0 -177
  106. package/dist/esm/test/splits/splits.spec.js +0 -400
  107. package/src/abi/BatchDeposit.ts +0 -117
  108. package/src/abi/MerkleDistributorWithDeadline.ts +0 -70
  109. package/src/abi/Multicall3.ts +0 -250
  110. package/src/abi/OVM.ts +0 -624
  111. package/src/abi/OWR.ts +0 -302
  112. package/src/abi/SplitMain.ts +0 -927
  113. package/src/abi/splitV2FactoryAbi.ts +0 -417
  114. package/src/ajv.ts +0 -191
  115. package/src/base.ts +0 -54
  116. package/src/bytecodes.ts +0 -32
  117. package/src/constants.ts +0 -309
  118. package/src/eoa/eoa.ts +0 -153
  119. package/src/eoa/eoaHelpers.ts +0 -112
  120. package/src/errors.ts +0 -8
  121. package/src/exits/ethUtils.ts +0 -49
  122. package/src/exits/exit.ts +0 -661
  123. package/src/exits/verificationHelpers.ts +0 -110
  124. package/src/incentives/incentiveHelpers.ts +0 -55
  125. package/src/incentives/incentives.ts +0 -153
  126. package/src/index.ts +0 -614
  127. package/src/schema.ts +0 -376
  128. package/src/services.ts +0 -24
  129. package/src/splits/splitHelpers.ts +0 -1032
  130. package/src/splits/splits.ts +0 -504
  131. package/src/types.ts +0 -687
  132. package/src/utils.ts +0 -88
  133. package/src/verification/common.ts +0 -532
  134. package/src/verification/signature-validator.ts +0 -103
  135. package/src/verification/sszTypes.ts +0 -88
  136. package/src/verification/termsAndConditions.ts +0 -32
  137. package/src/verification/v1.10.0.ts +0 -245
  138. package/src/verification/v1.6.0.ts +0 -256
  139. package/src/verification/v1.7.0.ts +0 -309
  140. package/src/verification/v1.8.0.ts +0 -340
@@ -1,309 +0,0 @@
1
- import {
2
- type UintNumberByteLen,
3
- UintNumberType,
4
- } from '@chainsafe/ssz/lib/type/uint';
5
- import { strToUint8Array } from '../utils';
6
- import {
7
- builderRegistrationContainer,
8
- type creatorAddressWrapperType,
9
- type creatorContainerType,
10
- depositDataContainer,
11
- newCreatorContainerType,
12
- newOperatorContainerType,
13
- type operatorAddressWrapperType,
14
- type operatorContainerType,
15
- validatorsContainerType,
16
- } from './sszTypes';
17
- import {
18
- ByteListType,
19
- ByteVectorType,
20
- ContainerType,
21
- ListCompositeType,
22
- fromHexString,
23
- } from '@chainsafe/ssz';
24
- import { type ValueOfFields } from '@chainsafe/ssz/lib/view/container';
25
- import {
26
- type ClusterDefinition,
27
- type ClusterLock,
28
- type DepositData,
29
- } from '../types';
30
- import {
31
- verifyBuilderRegistration,
32
- verifyDepositData,
33
- verifyNodeSignatures,
34
- } from './common';
35
- import {
36
- aggregateSignatures,
37
- verifyAggregate,
38
- verifyMultiple,
39
- } from '@chainsafe/bls';
40
-
41
- // cluster definition
42
- type DefinitionFieldsV1X7 = {
43
- uuid: ByteListType;
44
- name: ByteListType;
45
- version: ByteListType;
46
- timestamp: ByteListType;
47
- num_validators: UintNumberType;
48
- threshold: UintNumberType;
49
- dkg_algorithm: ByteListType;
50
- fork_version: ByteVectorType;
51
- operators: ListCompositeType<
52
- typeof operatorContainerType | typeof operatorAddressWrapperType
53
- >;
54
- creator: typeof creatorContainerType | typeof creatorAddressWrapperType;
55
- validators: ListCompositeType<typeof validatorsContainerType>;
56
- config_hash?: ByteVectorType;
57
- };
58
-
59
- type DefinitionContainerTypeV1X7 = ContainerType<DefinitionFieldsV1X7>;
60
-
61
- /**
62
- * Returns the containerized cluster definition
63
- * @param cluster ClusterDefinition to calculate the type from
64
- * @returns SSZ Containerized type of cluster input
65
- */
66
- export const clusterDefinitionContainerTypeV1X7 = (
67
- configOnly: boolean,
68
- ): DefinitionContainerTypeV1X7 => {
69
- let returnedContainerType: any = {
70
- uuid: new ByteListType(64),
71
- name: new ByteListType(256),
72
- version: new ByteListType(16),
73
- timestamp: new ByteListType(32),
74
- num_validators: new UintNumberType(8 as UintNumberByteLen),
75
- threshold: new UintNumberType(8 as UintNumberByteLen),
76
- dkg_algorithm: new ByteListType(32),
77
- fork_version: new ByteVectorType(4),
78
- operators: new ListCompositeType(newOperatorContainerType(configOnly), 256),
79
- creator: newCreatorContainerType(configOnly),
80
- validators: new ListCompositeType(validatorsContainerType, 65536),
81
- };
82
-
83
- if (!configOnly) {
84
- returnedContainerType = {
85
- ...returnedContainerType,
86
- config_hash: new ByteVectorType(32),
87
- };
88
- }
89
-
90
- return new ContainerType(returnedContainerType);
91
- };
92
-
93
- export const hashClusterDefinitionV1X7 = (
94
- cluster: ClusterDefinition,
95
- configOnly: boolean,
96
- ): ValueOfFields<DefinitionFieldsV1X7> => {
97
- const definitionType = clusterDefinitionContainerTypeV1X7(configOnly);
98
-
99
- const val = definitionType.defaultValue();
100
-
101
- // order should be same as charon https://github.com/ObolNetwork/charon/blob/main/cluster/ssz.go#L276
102
- val.uuid = strToUint8Array(cluster.uuid);
103
- val.name = strToUint8Array(cluster.name);
104
- val.version = strToUint8Array(cluster.version);
105
- val.timestamp = strToUint8Array(cluster.timestamp);
106
- val.num_validators = cluster.num_validators;
107
- val.threshold = cluster.threshold;
108
- val.dkg_algorithm = strToUint8Array(cluster.dkg_algorithm);
109
- val.fork_version = fromHexString(cluster.fork_version);
110
- val.operators = cluster.operators.map(operator => {
111
- return configOnly
112
- ? { address: fromHexString(operator.address) }
113
- : {
114
- address: fromHexString(operator.address),
115
- enr: strToUint8Array(operator.enr as string),
116
- config_signature: fromHexString(operator.config_signature as string),
117
- enr_signature: fromHexString(operator.enr_signature as string),
118
- };
119
- });
120
- val.creator = configOnly
121
- ? { address: fromHexString(cluster.creator.address) }
122
- : {
123
- address: fromHexString(cluster.creator.address),
124
- config_signature: fromHexString(
125
- cluster.creator.config_signature as string,
126
- ),
127
- };
128
- val.validators = cluster.validators.map(validator => {
129
- return {
130
- fee_recipient_address: fromHexString(validator.fee_recipient_address),
131
- withdrawal_address: fromHexString(validator.withdrawal_address),
132
- };
133
- });
134
-
135
- if (!configOnly) {
136
- val.config_hash = fromHexString(cluster.config_hash);
137
- }
138
- return val;
139
- };
140
-
141
- // cluster lock
142
-
143
- const dvContainerTypeV1X7 = new ContainerType({
144
- distributed_public_key: new ByteVectorType(48),
145
- public_shares: new ListCompositeType(new ByteVectorType(48), 256),
146
- deposit_data: depositDataContainer,
147
- builder_registration: builderRegistrationContainer,
148
- });
149
-
150
- type LockContainerTypeV1X7 = ContainerType<{
151
- cluster_definition: DefinitionContainerTypeV1X7;
152
- distributed_validators: ListCompositeType<typeof dvContainerTypeV1X7>;
153
- }>;
154
-
155
- /**
156
- * @returns SSZ Containerized type of cluster lock
157
- */
158
- const clusterLockContainerTypeV1X7 = (): LockContainerTypeV1X7 => {
159
- return new ContainerType({
160
- cluster_definition: clusterDefinitionContainerTypeV1X7(false),
161
- distributed_validators: new ListCompositeType(dvContainerTypeV1X7, 65536),
162
- });
163
- };
164
-
165
- /**
166
- * @param cluster The published cluster lock
167
- * @returns The lock hash in of the corresponding cluster
168
- */
169
- export const hashClusterLockV1X7 = (cluster: ClusterLock): string => {
170
- const lockType = clusterLockContainerTypeV1X7();
171
-
172
- const val = lockType.defaultValue();
173
-
174
- // Check if we can replace with definition_hash
175
- val.cluster_definition = hashClusterDefinitionV1X7(
176
- cluster.cluster_definition,
177
- false,
178
- );
179
- val.distributed_validators = cluster.distributed_validators.map(
180
- dValidator => {
181
- return {
182
- distributed_public_key: fromHexString(
183
- dValidator.distributed_public_key,
184
- ),
185
- public_shares: dValidator.public_shares.map(publicShare =>
186
- fromHexString(publicShare),
187
- ),
188
- deposit_data: {
189
- pubkey: fromHexString(dValidator.deposit_data?.pubkey as string),
190
- withdrawal_credentials: fromHexString(
191
- dValidator.deposit_data?.withdrawal_credentials as string,
192
- ),
193
- amount: parseInt(dValidator.deposit_data?.amount as string),
194
- signature: fromHexString(
195
- dValidator.deposit_data?.signature as string,
196
- ),
197
- },
198
- builder_registration: {
199
- message: {
200
- fee_recipient: fromHexString(
201
- dValidator.builder_registration?.message.fee_recipient as string,
202
- ),
203
- gas_limit: dValidator.builder_registration?.message
204
- .gas_limit as number,
205
- timestamp: dValidator.builder_registration?.message
206
- .timestamp as number,
207
- pubkey: fromHexString(
208
- dValidator.builder_registration?.message.pubkey as string,
209
- ),
210
- },
211
- signature: fromHexString(
212
- dValidator.builder_registration?.signature as string,
213
- ),
214
- },
215
- };
216
- },
217
- );
218
-
219
- return '0x' + Buffer.from(lockType.hashTreeRoot(val).buffer).toString('hex');
220
- };
221
-
222
- // DV verification
223
- export const verifyDVV1X7 = (clusterLock: ClusterLock): boolean => {
224
- const validators = clusterLock.distributed_validators;
225
-
226
- const pubShares = [];
227
-
228
- const pubKeys = [];
229
- const builderRegistrationAndDepositDataMessages = [];
230
- const blsSignatures = [];
231
-
232
- for (let i = 0; i < validators.length; i++) {
233
- const validator = validators[i];
234
- const validatorPublicShares = validator.public_shares;
235
- const distributedPublicKey = validator.distributed_public_key;
236
-
237
- // Needed in signature_aggregate verification
238
- for (const element of validatorPublicShares) {
239
- pubShares.push(fromHexString(element));
240
- }
241
-
242
- // Deposit Data Verification
243
- const { isValidDepositData, depositDataMsg } = verifyDepositData(
244
- distributedPublicKey,
245
- validator.deposit_data as Partial<DepositData>,
246
- clusterLock.cluster_definition.validators[i].withdrawal_address,
247
- clusterLock.cluster_definition.fork_version,
248
- );
249
-
250
- if (!isValidDepositData) {
251
- return false;
252
- }
253
-
254
- pubKeys.push(fromHexString(distributedPublicKey));
255
- builderRegistrationAndDepositDataMessages.push(depositDataMsg);
256
- blsSignatures.push(
257
- fromHexString(validator.deposit_data?.signature as string),
258
- );
259
-
260
- // Builder Registration Verification
261
- const { isValidBuilderRegistration, builderRegistrationMsg } =
262
- verifyBuilderRegistration(
263
- validator,
264
- clusterLock.cluster_definition.validators[i].fee_recipient_address,
265
- clusterLock.cluster_definition.fork_version,
266
- );
267
-
268
- if (!isValidBuilderRegistration) {
269
- return false;
270
- }
271
-
272
- pubKeys.push(fromHexString(distributedPublicKey));
273
- builderRegistrationAndDepositDataMessages.push(builderRegistrationMsg);
274
- blsSignatures.push(
275
- fromHexString(validator.builder_registration?.signature as string),
276
- );
277
- }
278
-
279
- // BLS signatures verification
280
- const aggregateBLSSignature = aggregateSignatures(blsSignatures);
281
-
282
- if (
283
- !verifyMultiple(
284
- pubKeys,
285
- builderRegistrationAndDepositDataMessages,
286
- aggregateBLSSignature,
287
- )
288
- ) {
289
- return false;
290
- }
291
-
292
- // Node Signatures verification
293
- if (!verifyNodeSignatures(clusterLock)) {
294
- return false;
295
- }
296
-
297
- // signature_aggregate verification
298
- if (
299
- !verifyAggregate(
300
- pubShares,
301
- fromHexString(clusterLock.lock_hash),
302
- fromHexString(clusterLock.signature_aggregate),
303
- )
304
- ) {
305
- return false;
306
- }
307
-
308
- return true;
309
- };
@@ -1,340 +0,0 @@
1
- import {
2
- type UintNumberByteLen,
3
- UintNumberType,
4
- } from '@chainsafe/ssz/lib/type/uint';
5
- import { strToUint8Array } from '../utils';
6
- import {
7
- builderRegistrationContainer,
8
- type creatorAddressWrapperType,
9
- type creatorContainerType,
10
- depositDataContainer,
11
- newCreatorContainerType,
12
- newOperatorContainerType,
13
- type operatorAddressWrapperType,
14
- type operatorContainerType,
15
- validatorsContainerType,
16
- } from './sszTypes';
17
- import {
18
- ByteListType,
19
- ByteVectorType,
20
- ContainerType,
21
- ListBasicType,
22
- ListCompositeType,
23
- fromHexString,
24
- } from '@chainsafe/ssz';
25
- import { type ValueOfFields } from '@chainsafe/ssz/lib/view/container';
26
- import {
27
- type ClusterDefinition,
28
- type ClusterLock,
29
- type DepositData,
30
- } from '../types';
31
- import {
32
- verifyBuilderRegistration,
33
- verifyDepositData,
34
- verifyNodeSignatures,
35
- } from './common';
36
- import {
37
- aggregateSignatures,
38
- verifyAggregate,
39
- verifyMultiple,
40
- } from '@chainsafe/bls';
41
-
42
- // cluster definition
43
- type DefinitionFieldsV1X8 = {
44
- uuid: ByteListType;
45
- name: ByteListType;
46
- version: ByteListType;
47
- timestamp: ByteListType;
48
- num_validators: UintNumberType;
49
- threshold: UintNumberType;
50
- dkg_algorithm: ByteListType;
51
- fork_version: ByteVectorType;
52
- operators: ListCompositeType<
53
- typeof operatorContainerType | typeof operatorAddressWrapperType
54
- >;
55
- creator: typeof creatorContainerType | typeof creatorAddressWrapperType;
56
- validators: ListCompositeType<typeof validatorsContainerType>;
57
- deposit_amounts: ListBasicType<UintNumberType>;
58
- config_hash?: ByteVectorType;
59
- };
60
-
61
- type DefinitionContainerTypeV1X8 = ContainerType<DefinitionFieldsV1X8>;
62
-
63
- /**
64
- * Returns the containerized cluster definition
65
- * @param cluster ClusterDefinition to calculate the type from
66
- * @returns SSZ Containerized type of cluster input
67
- */
68
- export const clusterDefinitionContainerTypeV1X8 = (
69
- configOnly: boolean,
70
- ): DefinitionContainerTypeV1X8 => {
71
- let returnedContainerType: any = {
72
- uuid: new ByteListType(64),
73
- name: new ByteListType(256),
74
- version: new ByteListType(16),
75
- timestamp: new ByteListType(32),
76
- num_validators: new UintNumberType(8 as UintNumberByteLen),
77
- threshold: new UintNumberType(8 as UintNumberByteLen),
78
- dkg_algorithm: new ByteListType(32),
79
- fork_version: new ByteVectorType(4),
80
- operators: new ListCompositeType(newOperatorContainerType(configOnly), 256),
81
- creator: newCreatorContainerType(configOnly),
82
- validators: new ListCompositeType(validatorsContainerType, 65536),
83
- deposit_amounts: new ListBasicType(
84
- new UintNumberType(8 as UintNumberByteLen),
85
- 256,
86
- ),
87
- };
88
-
89
- if (!configOnly) {
90
- returnedContainerType = {
91
- ...returnedContainerType,
92
- config_hash: new ByteVectorType(32),
93
- };
94
- }
95
-
96
- return new ContainerType(returnedContainerType);
97
- };
98
-
99
- export const hashClusterDefinitionV1X8 = (
100
- cluster: ClusterDefinition,
101
- configOnly: boolean,
102
- ): ValueOfFields<DefinitionFieldsV1X8> => {
103
- const definitionType = clusterDefinitionContainerTypeV1X8(configOnly);
104
-
105
- const val = definitionType.defaultValue();
106
-
107
- // order should be same as charon https://github.com/ObolNetwork/charon/blob/main/cluster/ssz.go#L276
108
- val.uuid = strToUint8Array(cluster.uuid);
109
- val.name = strToUint8Array(cluster.name);
110
- val.version = strToUint8Array(cluster.version);
111
- val.timestamp = strToUint8Array(cluster.timestamp);
112
- val.num_validators = cluster.num_validators;
113
- val.threshold = cluster.threshold;
114
- val.dkg_algorithm = strToUint8Array(cluster.dkg_algorithm);
115
- val.fork_version = fromHexString(cluster.fork_version);
116
- val.operators = cluster.operators.map(operator => {
117
- return configOnly
118
- ? { address: fromHexString(operator.address) }
119
- : {
120
- address: fromHexString(operator.address),
121
- enr: strToUint8Array(operator.enr as string),
122
- config_signature: fromHexString(operator.config_signature as string),
123
- enr_signature: fromHexString(operator.enr_signature as string),
124
- };
125
- });
126
- val.creator = configOnly
127
- ? { address: fromHexString(cluster.creator.address) }
128
- : {
129
- address: fromHexString(cluster.creator.address),
130
- config_signature: fromHexString(
131
- cluster.creator.config_signature as string,
132
- ),
133
- };
134
- val.validators = cluster.validators.map(validator => {
135
- return {
136
- fee_recipient_address: fromHexString(validator.fee_recipient_address),
137
- withdrawal_address: fromHexString(validator.withdrawal_address),
138
- };
139
- });
140
- if (cluster.deposit_amounts) {
141
- val.deposit_amounts = cluster.deposit_amounts.map((amount: string) => {
142
- return parseInt(amount);
143
- });
144
- }
145
-
146
- if (!configOnly) {
147
- val.config_hash = fromHexString(cluster.config_hash);
148
- }
149
- return val;
150
- };
151
-
152
- // cluster lock
153
-
154
- const dvContainerTypeV1X8 = new ContainerType({
155
- distributed_public_key: new ByteVectorType(48),
156
- public_shares: new ListCompositeType(new ByteVectorType(48), 256),
157
- partial_deposit_data: new ListCompositeType(depositDataContainer, 256),
158
- builder_registration: builderRegistrationContainer,
159
- });
160
-
161
- type LockContainerTypeV1X8 = ContainerType<{
162
- cluster_definition: DefinitionContainerTypeV1X8;
163
- distributed_validators: ListCompositeType<typeof dvContainerTypeV1X8>;
164
- }>;
165
-
166
- /**
167
- * @returns SSZ Containerized type of cluster lock
168
- */
169
- const clusterLockContainerTypeV1X8 = (): LockContainerTypeV1X8 => {
170
- return new ContainerType({
171
- cluster_definition: clusterDefinitionContainerTypeV1X8(false),
172
- distributed_validators: new ListCompositeType(dvContainerTypeV1X8, 65536),
173
- });
174
- };
175
-
176
- /**
177
- * @param cluster The published cluster lock
178
- * @returns The lock hash in of the corresponding cluster
179
- */
180
- export const hashClusterLockV1X8 = (cluster: ClusterLock): string => {
181
- const lockType = clusterLockContainerTypeV1X8();
182
-
183
- const val = lockType.defaultValue();
184
-
185
- // Check if we can replace with definition_hash
186
- val.cluster_definition = hashClusterDefinitionV1X8(
187
- cluster.cluster_definition,
188
- false,
189
- );
190
- val.distributed_validators = cluster.distributed_validators.map(
191
- dValidator => {
192
- return {
193
- distributed_public_key: fromHexString(
194
- dValidator.distributed_public_key,
195
- ),
196
- public_shares: dValidator.public_shares.map(publicShare =>
197
- fromHexString(publicShare),
198
- ),
199
- // should be fixed
200
- partial_deposit_data: (
201
- dValidator.partial_deposit_data as DepositData[]
202
- ).map(depositData => {
203
- return {
204
- pubkey: fromHexString(depositData.pubkey),
205
- withdrawal_credentials: fromHexString(
206
- depositData.withdrawal_credentials,
207
- ),
208
- amount: parseInt(depositData.amount),
209
- signature: fromHexString(depositData.signature),
210
- };
211
- }),
212
- builder_registration: {
213
- message: {
214
- fee_recipient: fromHexString(
215
- dValidator.builder_registration?.message.fee_recipient as string,
216
- ),
217
- gas_limit: dValidator.builder_registration?.message
218
- .gas_limit as number,
219
- timestamp: dValidator.builder_registration?.message
220
- .timestamp as number,
221
- pubkey: fromHexString(
222
- dValidator.builder_registration?.message.pubkey as string,
223
- ),
224
- },
225
- signature: fromHexString(
226
- dValidator.builder_registration?.signature as string,
227
- ),
228
- },
229
- };
230
- },
231
- );
232
-
233
- return '0x' + Buffer.from(lockType.hashTreeRoot(val).buffer).toString('hex');
234
- };
235
-
236
- // DV verification
237
- export const verifyDVV1X8 = (clusterLock: ClusterLock): boolean => {
238
- const validators = clusterLock.distributed_validators;
239
- const pubShares = [];
240
- const pubKeys = [];
241
- const builderRegistrationAndDepositDataMessages = [];
242
- const blsSignatures = [];
243
-
244
- for (let i = 0; i < validators.length; i++) {
245
- const validator = validators[i];
246
- const validatorPublicShares = validator.public_shares;
247
- const distributedPublicKey = validator.distributed_public_key;
248
-
249
- // Needed in signature_aggregate verification
250
- for (const element of validatorPublicShares) {
251
- pubShares.push(fromHexString(element));
252
- }
253
-
254
- // Check deposit amounts match exactly if they are defined
255
- const depositAmounts = clusterLock.cluster_definition.deposit_amounts;
256
- if (!!depositAmounts && depositAmounts !== null) {
257
- const partialDepositAmounts = (
258
- validator.partial_deposit_data as DepositData[]
259
- ).map(d => d.amount);
260
-
261
- // Check that partialDepositAmounts includes all unique elements of depositAmounts
262
- const uniqueDepositAmounts = [...new Set(depositAmounts.map(Number))];
263
- const partialAmountsSet = new Set(partialDepositAmounts.map(Number));
264
-
265
- if (
266
- !uniqueDepositAmounts.every(amount => partialAmountsSet.has(amount))
267
- ) {
268
- return false;
269
- }
270
- }
271
- // Deposit Data Verification
272
- for (const element of validator.partial_deposit_data as DepositData[]) {
273
- const depositData = element;
274
- const { isValidDepositData, depositDataMsg } = verifyDepositData(
275
- distributedPublicKey,
276
- depositData as Partial<DepositData>,
277
- clusterLock.cluster_definition.validators[i].withdrawal_address,
278
- clusterLock.cluster_definition.fork_version,
279
- clusterLock.cluster_definition.compounding,
280
- );
281
-
282
- if (!isValidDepositData) {
283
- return false;
284
- }
285
-
286
- pubKeys.push(fromHexString(distributedPublicKey));
287
- builderRegistrationAndDepositDataMessages.push(depositDataMsg);
288
- blsSignatures.push(fromHexString(depositData?.signature));
289
- }
290
-
291
- // Builder Registration Verification
292
- const { isValidBuilderRegistration, builderRegistrationMsg } =
293
- verifyBuilderRegistration(
294
- validator,
295
- clusterLock.cluster_definition.validators[i].fee_recipient_address,
296
- clusterLock.cluster_definition.fork_version,
297
- );
298
-
299
- if (!isValidBuilderRegistration) {
300
- return false;
301
- }
302
-
303
- pubKeys.push(fromHexString(distributedPublicKey));
304
- builderRegistrationAndDepositDataMessages.push(builderRegistrationMsg);
305
- blsSignatures.push(
306
- fromHexString(validator.builder_registration?.signature as string),
307
- );
308
- }
309
-
310
- // BLS signatures verification
311
- const aggregateBLSSignature = aggregateSignatures(blsSignatures);
312
-
313
- if (
314
- !verifyMultiple(
315
- pubKeys,
316
- builderRegistrationAndDepositDataMessages,
317
- aggregateBLSSignature,
318
- )
319
- ) {
320
- return false;
321
- }
322
-
323
- // Node Signatures verification
324
- if (!verifyNodeSignatures(clusterLock)) {
325
- return false;
326
- }
327
-
328
- // signature_aggregate verification
329
- if (
330
- !verifyAggregate(
331
- pubShares,
332
- fromHexString(clusterLock.lock_hash),
333
- fromHexString(clusterLock.signature_aggregate),
334
- )
335
- ) {
336
- return false;
337
- }
338
-
339
- return true;
340
- };