@obolnetwork/obol-sdk 1.0.16 → 1.0.17

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