@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,88 +0,0 @@
1
- import {
2
- ByteListType,
3
- ByteVectorType,
4
- ContainerType,
5
- UintNumberType,
6
- } from '@chainsafe/ssz';
7
- import { type UintNumberByteLen } from '@chainsafe/ssz/lib/type/uint';
8
-
9
- export const operatorAddressWrapperType = new ContainerType({
10
- address: new ByteVectorType(20),
11
- });
12
-
13
- export const creatorAddressWrapperType = new ContainerType({
14
- address: new ByteVectorType(20),
15
- });
16
-
17
- export const operatorContainerType = new ContainerType({
18
- address: new ByteVectorType(20),
19
- enr: new ByteListType(1024), // This needs to be dynamic, since ENRs do not have a fixed length.
20
- config_signature: new ByteVectorType(65),
21
- enr_signature: new ByteVectorType(65),
22
- });
23
-
24
- export const creatorContainerType = new ContainerType({
25
- address: new ByteVectorType(20),
26
- config_signature: new ByteVectorType(65),
27
- });
28
-
29
- export const validatorsContainerType = new ContainerType({
30
- fee_recipient_address: new ByteVectorType(20),
31
- withdrawal_address: new ByteVectorType(20),
32
- });
33
-
34
- export const newCreatorContainerType = (
35
- configOnly: boolean,
36
- ): ContainerType<any> => {
37
- return configOnly ? creatorAddressWrapperType : creatorContainerType;
38
- };
39
-
40
- export const newOperatorContainerType = (
41
- configOnly: boolean,
42
- ): ContainerType<any> => {
43
- return configOnly ? operatorAddressWrapperType : operatorContainerType;
44
- };
45
-
46
- // Lock
47
- export const depositDataContainer = new ContainerType({
48
- pubkey: new ByteVectorType(48),
49
- withdrawal_credentials: new ByteVectorType(32),
50
- amount: new UintNumberType(8 as UintNumberByteLen),
51
- signature: new ByteVectorType(96),
52
- });
53
-
54
- export const builderRegistrationMessageContainer = new ContainerType({
55
- fee_recipient: new ByteVectorType(20),
56
- gas_limit: new UintNumberType(8 as UintNumberByteLen),
57
- timestamp: new UintNumberType(8 as UintNumberByteLen),
58
- pubkey: new ByteVectorType(48),
59
- });
60
-
61
- export const builderRegistrationContainer = new ContainerType({
62
- message: builderRegistrationMessageContainer,
63
- signature: new ByteVectorType(96),
64
- });
65
-
66
- export const builderRegistrationMessageType = new ContainerType({
67
- fee_recipient: new ByteVectorType(20),
68
- gas_limit: new UintNumberType(8 as UintNumberByteLen),
69
- timestamp: new UintNumberType(8 as UintNumberByteLen),
70
- pubkey: new ByteVectorType(48),
71
- });
72
-
73
- // For domain computation that is used in deposit data and builder registration verification for dv
74
- export const forkDataType = new ContainerType({
75
- currentVersion: new ByteVectorType(4),
76
- genesisValidatorsRoot: new ByteVectorType(32),
77
- });
78
-
79
- export const depositMessageType = new ContainerType({
80
- pubkey: new ByteVectorType(48),
81
- withdrawal_credentials: new ByteVectorType(32),
82
- amount: new UintNumberType(8),
83
- });
84
-
85
- export const signingRootType = new ContainerType({
86
- objectRoot: new ByteVectorType(32),
87
- domain: new ByteVectorType(32),
88
- });
@@ -1,32 +0,0 @@
1
- import pdf from 'pdf-parse';
2
- import { ByteListType, ContainerType } from '@chainsafe/ssz';
3
- import { TERMS_AND_CONDITIONS_URL } from '../constants';
4
- import { strToUint8Array } from '../utils';
5
-
6
- export const hashTermsAndConditions = async (): Promise<string | null> => {
7
- try {
8
- // read the pdf
9
- const response = await fetch(TERMS_AND_CONDITIONS_URL);
10
- const pdfBuffarrayBuffer = await response.arrayBuffer();
11
- const pdfBuffer = Buffer.from(pdfBuffarrayBuffer);
12
- const data = await pdf(pdfBuffer);
13
-
14
- // ssz hash
15
- const termsType = new ContainerType({
16
- terms_and_conditions_hash: new ByteListType(Number.MAX_SAFE_INTEGER),
17
- });
18
-
19
- const termsHasVal = termsType.defaultValue();
20
-
21
- termsHasVal.terms_and_conditions_hash = strToUint8Array(
22
- data?.text.replace(/[^a-zA-Z0-9]/g, ''),
23
- );
24
-
25
- return (
26
- '0x' +
27
- Buffer.from(termsType.hashTreeRoot(termsHasVal).buffer).toString('hex')
28
- );
29
- } catch (err) {
30
- return null;
31
- }
32
- };
@@ -1,245 +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
- BooleanType,
25
- } from '@chainsafe/ssz';
26
- import { type ValueOfFields } from '@chainsafe/ssz/lib/view/container';
27
- import {
28
- type ClusterDefinition,
29
- type ClusterLock,
30
- type DepositData,
31
- } from '../types';
32
- import { verifyDVV1X8 } from './v1.8.0';
33
-
34
- // cluster definition
35
- type DefinitionFieldsV1X10 = {
36
- uuid: ByteListType;
37
- name: ByteListType;
38
- version: ByteListType;
39
- timestamp: ByteListType;
40
- num_validators: UintNumberType;
41
- threshold: UintNumberType;
42
- dkg_algorithm: ByteListType;
43
- fork_version: ByteVectorType;
44
- operators: ListCompositeType<
45
- typeof operatorContainerType | typeof operatorAddressWrapperType
46
- >;
47
- creator: typeof creatorContainerType | typeof creatorAddressWrapperType;
48
- validators: ListCompositeType<typeof validatorsContainerType>;
49
- deposit_amounts: ListBasicType<UintNumberType>;
50
- consensus_protocol: ByteListType;
51
- target_gas_limit: UintNumberType;
52
- compounding: BooleanType;
53
- config_hash?: ByteVectorType;
54
- };
55
-
56
- type DefinitionContainerTypeV1X10 = ContainerType<DefinitionFieldsV1X10>;
57
-
58
- /**
59
- * Returns the containerized cluster definition
60
- * @param cluster ClusterDefinition to calculate the type from
61
- * @returns SSZ Containerized type of cluster input
62
- */
63
- export const clusterDefinitionContainerTypeV1X10 = (
64
- configOnly: boolean,
65
- ): DefinitionContainerTypeV1X10 => {
66
- let returnedContainerType: any = {
67
- uuid: new ByteListType(64),
68
- name: new ByteListType(256),
69
- version: new ByteListType(16),
70
- timestamp: new ByteListType(32),
71
- num_validators: new UintNumberType(8 as UintNumberByteLen),
72
- threshold: new UintNumberType(8 as UintNumberByteLen),
73
- dkg_algorithm: new ByteListType(32),
74
- fork_version: new ByteVectorType(4),
75
- operators: new ListCompositeType(newOperatorContainerType(configOnly), 256),
76
- creator: newCreatorContainerType(configOnly),
77
- validators: new ListCompositeType(validatorsContainerType, 65536),
78
- deposit_amounts: new ListBasicType(
79
- new UintNumberType(8 as UintNumberByteLen),
80
- 256,
81
- ),
82
- consensus_protocol: new ByteListType(256),
83
- target_gas_limit: new UintNumberType(8 as UintNumberByteLen),
84
- compounding: new BooleanType(),
85
- };
86
-
87
- if (!configOnly) {
88
- returnedContainerType = {
89
- ...returnedContainerType,
90
- config_hash: new ByteVectorType(32),
91
- };
92
- }
93
-
94
- return new ContainerType(returnedContainerType);
95
- };
96
-
97
- export const hashClusterDefinitionV1X10 = (
98
- cluster: ClusterDefinition,
99
- configOnly: boolean,
100
- ): ValueOfFields<DefinitionFieldsV1X10> => {
101
- const definitionType = clusterDefinitionContainerTypeV1X10(configOnly);
102
-
103
- const val = definitionType.defaultValue();
104
-
105
- // order should be same as charon https://github.com/ObolNetwork/charon/blob/main/cluster/ssz.go#L276
106
- val.uuid = strToUint8Array(cluster.uuid);
107
- val.name = strToUint8Array(cluster.name);
108
- val.version = strToUint8Array(cluster.version);
109
- val.timestamp = strToUint8Array(cluster.timestamp);
110
- val.num_validators = cluster.num_validators;
111
- val.threshold = cluster.threshold;
112
- val.dkg_algorithm = strToUint8Array(cluster.dkg_algorithm);
113
- val.fork_version = fromHexString(cluster.fork_version);
114
- val.operators = cluster.operators.map(operator => {
115
- return configOnly
116
- ? { address: fromHexString(operator.address) }
117
- : {
118
- address: fromHexString(operator.address),
119
- enr: strToUint8Array(operator.enr as string),
120
- config_signature: fromHexString(operator.config_signature as string),
121
- enr_signature: fromHexString(operator.enr_signature as string),
122
- };
123
- });
124
- val.creator = configOnly
125
- ? { address: fromHexString(cluster.creator.address) }
126
- : {
127
- address: fromHexString(cluster.creator.address),
128
- config_signature: fromHexString(
129
- cluster.creator.config_signature as string,
130
- ),
131
- };
132
- val.validators = cluster.validators.map(validator => {
133
- return {
134
- fee_recipient_address: fromHexString(validator.fee_recipient_address),
135
- withdrawal_address: fromHexString(validator.withdrawal_address),
136
- };
137
- });
138
- if (cluster.deposit_amounts) {
139
- val.deposit_amounts = cluster.deposit_amounts.map((amount: string) => {
140
- return parseInt(amount);
141
- });
142
- }
143
- if (cluster.consensus_protocol) {
144
- val.consensus_protocol = strToUint8Array(cluster.consensus_protocol);
145
- }
146
- if (cluster.target_gas_limit) {
147
- val.target_gas_limit = cluster.target_gas_limit;
148
- }
149
-
150
- if (cluster.compounding) {
151
- val.compounding = cluster.compounding;
152
- }
153
-
154
- if (!configOnly) {
155
- val.config_hash = fromHexString(cluster.config_hash);
156
- }
157
- return val;
158
- };
159
-
160
- // cluster lock
161
-
162
- const dvContainerTypeV1X10 = new ContainerType({
163
- distributed_public_key: new ByteVectorType(48),
164
- public_shares: new ListCompositeType(new ByteVectorType(48), 256),
165
- partial_deposit_data: new ListCompositeType(depositDataContainer, 256),
166
- builder_registration: builderRegistrationContainer,
167
- });
168
-
169
- type LockContainerTypeV1X10 = ContainerType<{
170
- cluster_definition: DefinitionContainerTypeV1X10;
171
- distributed_validators: ListCompositeType<typeof dvContainerTypeV1X10>;
172
- }>;
173
-
174
- /**
175
- * @returns SSZ Containerized type of cluster lock
176
- */
177
- const clusterLockContainerTypeV1X10 = (): LockContainerTypeV1X10 => {
178
- return new ContainerType({
179
- cluster_definition: clusterDefinitionContainerTypeV1X10(false),
180
- distributed_validators: new ListCompositeType(dvContainerTypeV1X10, 65536),
181
- });
182
- };
183
-
184
- /**
185
- * @param cluster The published cluster lock
186
- * @returns The lock hash in of the corresponding cluster
187
- */
188
- export const hashClusterLockV1X10 = (cluster: ClusterLock): string => {
189
- const lockType = clusterLockContainerTypeV1X10();
190
-
191
- const val = lockType.defaultValue();
192
-
193
- // Check if we can replace with definition_hash
194
- val.cluster_definition = hashClusterDefinitionV1X10(
195
- cluster.cluster_definition,
196
- false,
197
- );
198
- val.distributed_validators = cluster.distributed_validators.map(
199
- dValidator => {
200
- return {
201
- distributed_public_key: fromHexString(
202
- dValidator.distributed_public_key,
203
- ),
204
- public_shares: dValidator.public_shares.map(publicShare =>
205
- fromHexString(publicShare),
206
- ),
207
- // should be fixed
208
- partial_deposit_data: (
209
- dValidator.partial_deposit_data as DepositData[]
210
- ).map(depositData => {
211
- return {
212
- pubkey: fromHexString(depositData.pubkey),
213
- withdrawal_credentials: fromHexString(
214
- depositData.withdrawal_credentials,
215
- ),
216
- amount: parseInt(depositData.amount),
217
- signature: fromHexString(depositData.signature),
218
- };
219
- }),
220
- builder_registration: {
221
- message: {
222
- fee_recipient: fromHexString(
223
- dValidator.builder_registration?.message.fee_recipient as string,
224
- ),
225
- gas_limit: dValidator.builder_registration?.message
226
- .gas_limit as number,
227
- timestamp: dValidator.builder_registration?.message
228
- .timestamp as number,
229
- pubkey: fromHexString(
230
- dValidator.builder_registration?.message.pubkey as string,
231
- ),
232
- },
233
- signature: fromHexString(
234
- dValidator.builder_registration?.signature as string,
235
- ),
236
- },
237
- };
238
- },
239
- );
240
-
241
- return '0x' + Buffer.from(lockType.hashTreeRoot(val).buffer).toString('hex');
242
- };
243
-
244
- // DV verification
245
- export const verifyDVV1X10 = verifyDVV1X8;
@@ -1,256 +0,0 @@
1
- import {
2
- type UintNumberByteLen,
3
- UintNumberType,
4
- } from '@chainsafe/ssz/lib/type/uint';
5
- import { strToUint8Array } from '../utils';
6
- import {
7
- type creatorAddressWrapperType,
8
- type creatorContainerType,
9
- newCreatorContainerType,
10
- newOperatorContainerType,
11
- type operatorAddressWrapperType,
12
- type operatorContainerType,
13
- validatorsContainerType,
14
- } from './sszTypes';
15
- import {
16
- ByteListType,
17
- ByteVectorType,
18
- ContainerType,
19
- ListCompositeType,
20
- fromHexString,
21
- } from '@chainsafe/ssz';
22
- import { type ValueOfFields } from '@chainsafe/ssz/lib/view/container';
23
- import {
24
- type ClusterDefinition,
25
- type ClusterLock,
26
- type DepositData,
27
- } from '../types';
28
- import { verifyDepositData } from './common';
29
- import {
30
- aggregateSignatures,
31
- verifyAggregate,
32
- verifyMultiple,
33
- } from '@chainsafe/bls';
34
-
35
- // cluster definition
36
- type DefinitionFieldsV1X6 = {
37
- uuid: ByteListType;
38
- name: ByteListType;
39
- version: ByteListType;
40
- timestamp: ByteListType;
41
- num_validators: UintNumberType;
42
- threshold: UintNumberType;
43
- dkg_algorithm: ByteListType;
44
- fork_version: ByteVectorType;
45
- operators: ListCompositeType<
46
- typeof operatorContainerType | typeof operatorAddressWrapperType
47
- >;
48
- creator: typeof creatorContainerType | typeof creatorAddressWrapperType;
49
- validators: ListCompositeType<typeof validatorsContainerType>;
50
- config_hash?: ByteVectorType;
51
- };
52
-
53
- type DefinitionContainerTypeV1X6 = ContainerType<DefinitionFieldsV1X6>;
54
-
55
- /**
56
- * Returns the containerized cluster definition
57
- * @param cluster ClusterDefinition to calculate the type from
58
- * @returns SSZ Containerized type of cluster input
59
- */
60
- export const clusterDefinitionContainerTypeV1X6 = (
61
- configOnly: boolean,
62
- ): DefinitionContainerTypeV1X6 => {
63
- let returnedContainerType: any = {
64
- uuid: new ByteListType(64),
65
- name: new ByteListType(256),
66
- version: new ByteListType(16),
67
- timestamp: new ByteListType(32),
68
- num_validators: new UintNumberType(8 as UintNumberByteLen),
69
- threshold: new UintNumberType(8 as UintNumberByteLen),
70
- dkg_algorithm: new ByteListType(32),
71
- fork_version: new ByteVectorType(4),
72
- operators: new ListCompositeType(newOperatorContainerType(configOnly), 256),
73
- creator: newCreatorContainerType(configOnly),
74
- validators: new ListCompositeType(validatorsContainerType, 65536),
75
- };
76
-
77
- if (!configOnly) {
78
- returnedContainerType = {
79
- ...returnedContainerType,
80
- config_hash: new ByteVectorType(32),
81
- };
82
- }
83
-
84
- return new ContainerType(returnedContainerType);
85
- };
86
-
87
- export const hashClusterDefinitionV1X6 = (
88
- cluster: ClusterDefinition,
89
- configOnly: boolean,
90
- ): ValueOfFields<DefinitionFieldsV1X6> => {
91
- const definitionType = clusterDefinitionContainerTypeV1X6(configOnly);
92
-
93
- const val = definitionType.defaultValue();
94
-
95
- // order should be same as charon https://github.com/ObolNetwork/charon/blob/main/cluster/ssz.go#L276
96
- val.uuid = strToUint8Array(cluster.uuid);
97
- val.name = strToUint8Array(cluster.name);
98
- val.version = strToUint8Array(cluster.version);
99
- val.timestamp = strToUint8Array(cluster.timestamp);
100
- val.num_validators = cluster.num_validators;
101
- val.threshold = cluster.threshold;
102
- val.dkg_algorithm = strToUint8Array(cluster.dkg_algorithm);
103
- val.fork_version = fromHexString(cluster.fork_version);
104
- val.operators = cluster.operators.map(operator => {
105
- return configOnly
106
- ? { address: fromHexString(operator.address) }
107
- : {
108
- address: fromHexString(operator.address),
109
- enr: strToUint8Array(operator.enr as string),
110
- config_signature: fromHexString(operator.config_signature as string),
111
- enr_signature: fromHexString(operator.enr_signature as string),
112
- };
113
- });
114
- val.creator = configOnly
115
- ? { address: fromHexString(cluster.creator.address) }
116
- : {
117
- address: fromHexString(cluster.creator.address),
118
- config_signature: fromHexString(
119
- cluster.creator.config_signature as string,
120
- ),
121
- };
122
- val.validators = cluster.validators.map(validator => {
123
- return {
124
- fee_recipient_address: fromHexString(validator.fee_recipient_address),
125
- withdrawal_address: fromHexString(validator.withdrawal_address),
126
- };
127
- });
128
-
129
- if (!configOnly) {
130
- val.config_hash = fromHexString(cluster.config_hash);
131
- }
132
- return val;
133
- };
134
-
135
- // cluster lock
136
-
137
- const dvContainerTypeV1X6 = new ContainerType({
138
- distributed_public_key: new ByteVectorType(48),
139
- public_shares: new ListCompositeType(new ByteVectorType(48), 256),
140
- pubkey: new ByteVectorType(48),
141
- withdrawal_credentials: new ByteVectorType(32),
142
- amount: new UintNumberType(8 as UintNumberByteLen),
143
- signature: new ByteVectorType(96),
144
- });
145
-
146
- type LockContainerTypeV1X6 = ContainerType<{
147
- cluster_definition: DefinitionContainerTypeV1X6;
148
- distributed_validators: ListCompositeType<typeof dvContainerTypeV1X6>;
149
- }>;
150
-
151
- /**
152
- * @returns SSZ Containerized type of cluster lock
153
- */
154
- const clusterLockContainerTypeV1X6 = (): LockContainerTypeV1X6 => {
155
- return new ContainerType({
156
- cluster_definition: clusterDefinitionContainerTypeV1X6(false),
157
- distributed_validators: new ListCompositeType(dvContainerTypeV1X6, 65536),
158
- });
159
- };
160
-
161
- /**
162
- * @param cluster The published cluster lock
163
- * @returns The lock hash in of the corresponding cluster
164
- */
165
- export const hashClusterLockV1X6 = (cluster: ClusterLock): string => {
166
- const lockType = clusterLockContainerTypeV1X6();
167
-
168
- const val = lockType.defaultValue();
169
-
170
- // Check if we can replace with definition_hash
171
- val.cluster_definition = hashClusterDefinitionV1X6(
172
- cluster.cluster_definition,
173
- false,
174
- );
175
- val.distributed_validators = cluster.distributed_validators.map(
176
- dValidator => {
177
- return {
178
- distributed_public_key: fromHexString(
179
- dValidator.distributed_public_key,
180
- ),
181
- public_shares: dValidator.public_shares.map(publicShare =>
182
- fromHexString(publicShare),
183
- ),
184
- pubkey: fromHexString(dValidator.deposit_data?.pubkey as string),
185
- withdrawal_credentials: fromHexString(
186
- dValidator.deposit_data?.withdrawal_credentials as string,
187
- ),
188
- amount: parseInt(dValidator.deposit_data?.amount as string),
189
- signature: fromHexString(dValidator.deposit_data?.signature as string),
190
- };
191
- },
192
- );
193
-
194
- return '0x' + Buffer.from(lockType.hashTreeRoot(val).buffer).toString('hex');
195
- };
196
-
197
- // DV verification
198
- export const verifyDVV1X6 = (clusterLock: ClusterLock): boolean => {
199
- const validators = clusterLock.distributed_validators;
200
- const pubShares = [];
201
- const pubKeys = [];
202
- const builderRegistrationAndDepositDataMessages = [];
203
- const blsSignatures = [];
204
-
205
- for (let i = 0; i < validators.length; i++) {
206
- const validator = validators[i];
207
- const validatorPublicShares = validator.public_shares;
208
- const distributedPublicKey = validator.distributed_public_key;
209
-
210
- // Needed in signature_aggregate verification
211
- for (const element of validatorPublicShares) {
212
- pubShares.push(fromHexString(element));
213
- }
214
-
215
- const { isValidDepositData, depositDataMsg } = verifyDepositData(
216
- distributedPublicKey,
217
- validator.deposit_data as Partial<DepositData>,
218
- clusterLock.cluster_definition.validators[i].withdrawal_address,
219
- clusterLock.cluster_definition.fork_version,
220
- );
221
-
222
- if (!isValidDepositData) {
223
- return false;
224
- }
225
-
226
- pubKeys.push(fromHexString(validator.distributed_public_key));
227
- builderRegistrationAndDepositDataMessages.push(depositDataMsg);
228
- blsSignatures.push(
229
- fromHexString(validator.deposit_data?.signature as string),
230
- );
231
- }
232
-
233
- const aggregateBLSSignature = aggregateSignatures(blsSignatures);
234
-
235
- if (
236
- !verifyMultiple(
237
- pubKeys,
238
- builderRegistrationAndDepositDataMessages,
239
- aggregateBLSSignature,
240
- )
241
- ) {
242
- return false;
243
- }
244
-
245
- if (
246
- !verifyAggregate(
247
- pubShares,
248
- fromHexString(clusterLock.lock_hash),
249
- fromHexString(clusterLock.signature_aggregate),
250
- )
251
- ) {
252
- return false;
253
- }
254
-
255
- return true;
256
- };