@obolnetwork/obol-sdk 2.11.3 → 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 (143) 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/abi/OVM.d.ts +103 -0
  6. package/dist/types/src/bytecodes.d.ts +3 -2
  7. package/dist/types/src/constants.d.ts +1 -2
  8. package/dist/types/src/eoa/eoaHelpers.d.ts +1 -1
  9. package/dist/types/src/exits/verificationHelpers.d.ts +0 -2
  10. package/dist/types/src/incentives/incentiveHelpers.d.ts +1 -1
  11. package/dist/types/src/splits/splitHelpers.d.ts +3 -3
  12. package/dist/types/src/utils.d.ts +2 -2
  13. package/dist/types/src/verification/common.d.ts +0 -2
  14. package/dist/types/src/verification/signature-validator.d.ts +4 -4
  15. package/dist/types/src/verification/v1.10.0.d.ts +1 -1
  16. package/dist/types/src/verification/v1.6.0.d.ts +1 -1
  17. package/dist/types/src/verification/v1.7.0.d.ts +1 -1
  18. package/dist/types/src/verification/v1.8.0.d.ts +1 -1
  19. package/dist/types/test/client/methods.spec.d.ts +17 -0
  20. package/dist/types/tsconfig.types.tsbuildinfo +1 -0
  21. package/dist/types/tsup.config.d.ts +2 -0
  22. package/package.json +79 -54
  23. package/dist/cjs/package.json +0 -139
  24. package/dist/cjs/src/abi/BatchDeposit.js +0 -120
  25. package/dist/cjs/src/abi/MerkleDistributorWithDeadline.js +0 -73
  26. package/dist/cjs/src/abi/Multicall3.js +0 -253
  27. package/dist/cjs/src/abi/OVMFactory.js +0 -620
  28. package/dist/cjs/src/abi/OWR.js +0 -304
  29. package/dist/cjs/src/abi/SplitMain.js +0 -929
  30. package/dist/cjs/src/abi/splitV2FactoryAbi.js +0 -420
  31. package/dist/cjs/src/ajv.js +0 -136
  32. package/dist/cjs/src/base.js +0 -42
  33. package/dist/cjs/src/bytecodes.js +0 -18
  34. package/dist/cjs/src/constants.js +0 -268
  35. package/dist/cjs/src/eoa/eoa.js +0 -132
  36. package/dist/cjs/src/eoa/eoaHelpers.js +0 -82
  37. package/dist/cjs/src/errors.js +0 -11
  38. package/dist/cjs/src/exits/ethUtils.js +0 -57
  39. package/dist/cjs/src/exits/exit.js +0 -502
  40. package/dist/cjs/src/exits/verificationHelpers.js +0 -86
  41. package/dist/cjs/src/incentives/incentiveHelpers.js +0 -39
  42. package/dist/cjs/src/incentives/incentives.js +0 -119
  43. package/dist/cjs/src/schema.js +0 -352
  44. package/dist/cjs/src/services.js +0 -33
  45. package/dist/cjs/src/splits/splitHelpers.js +0 -571
  46. package/dist/cjs/src/splits/splits.js +0 -366
  47. package/dist/cjs/src/types.js +0 -29
  48. package/dist/cjs/src/utils.js +0 -77
  49. package/dist/cjs/src/verification/common.js +0 -355
  50. package/dist/cjs/src/verification/signature-validator.js +0 -73
  51. package/dist/cjs/src/verification/sszTypes.js +0 -69
  52. package/dist/cjs/src/verification/termsAndConditions.js +0 -40
  53. package/dist/cjs/src/verification/v1.10.0.js +0 -146
  54. package/dist/cjs/src/verification/v1.6.0.js +0 -149
  55. package/dist/cjs/src/verification/v1.7.0.js +0 -173
  56. package/dist/cjs/src/verification/v1.8.0.js +0 -196
  57. package/dist/cjs/test/client/ajv.spec.js +0 -320
  58. package/dist/cjs/test/client/methods.spec.js +0 -418
  59. package/dist/cjs/test/eoa/eoa.spec.js +0 -176
  60. package/dist/cjs/test/exit/ethUtils.spec.js +0 -83
  61. package/dist/cjs/test/exit/exit.spec.js +0 -399
  62. package/dist/cjs/test/exit/verificationHelpers.spec.js +0 -68
  63. package/dist/cjs/test/fixtures.js +0 -896
  64. package/dist/cjs/test/incentives/incentives.spec.js +0 -202
  65. package/dist/cjs/test/splits/splits.spec.js +0 -402
  66. package/dist/esm/package.json +0 -139
  67. package/dist/esm/src/abi/BatchDeposit.js +0 -117
  68. package/dist/esm/src/abi/MerkleDistributorWithDeadline.js +0 -70
  69. package/dist/esm/src/abi/Multicall3.js +0 -250
  70. package/dist/esm/src/abi/OVMFactory.js +0 -617
  71. package/dist/esm/src/abi/OWR.js +0 -301
  72. package/dist/esm/src/abi/SplitMain.js +0 -926
  73. package/dist/esm/src/abi/splitV2FactoryAbi.js +0 -417
  74. package/dist/esm/src/ajv.js +0 -129
  75. package/dist/esm/src/base.js +0 -38
  76. package/dist/esm/src/bytecodes.js +0 -15
  77. package/dist/esm/src/constants.js +0 -234
  78. package/dist/esm/src/eoa/eoa.js +0 -128
  79. package/dist/esm/src/eoa/eoaHelpers.js +0 -77
  80. package/dist/esm/src/errors.js +0 -7
  81. package/dist/esm/src/exits/ethUtils.js +0 -52
  82. package/dist/esm/src/exits/exit.js +0 -475
  83. package/dist/esm/src/exits/verificationHelpers.js +0 -81
  84. package/dist/esm/src/incentives/incentiveHelpers.js +0 -34
  85. package/dist/esm/src/incentives/incentives.js +0 -115
  86. package/dist/esm/src/schema.js +0 -349
  87. package/dist/esm/src/services.js +0 -29
  88. package/dist/esm/src/splits/splitHelpers.js +0 -554
  89. package/dist/esm/src/splits/splits.js +0 -362
  90. package/dist/esm/src/types.js +0 -26
  91. package/dist/esm/src/utils.js +0 -68
  92. package/dist/esm/src/verification/common.js +0 -319
  93. package/dist/esm/src/verification/signature-validator.js +0 -64
  94. package/dist/esm/src/verification/sszTypes.js +0 -64
  95. package/dist/esm/src/verification/termsAndConditions.js +0 -33
  96. package/dist/esm/src/verification/v1.10.0.js +0 -140
  97. package/dist/esm/src/verification/v1.6.0.js +0 -142
  98. package/dist/esm/src/verification/v1.7.0.js +0 -166
  99. package/dist/esm/src/verification/v1.8.0.js +0 -189
  100. package/dist/esm/test/client/ajv.spec.js +0 -318
  101. package/dist/esm/test/client/methods.spec.js +0 -393
  102. package/dist/esm/test/eoa/eoa.spec.js +0 -174
  103. package/dist/esm/test/exit/ethUtils.spec.js +0 -81
  104. package/dist/esm/test/exit/exit.spec.js +0 -374
  105. package/dist/esm/test/exit/verificationHelpers.spec.js +0 -66
  106. package/dist/esm/test/fixtures.js +0 -893
  107. package/dist/esm/test/incentives/incentives.spec.js +0 -177
  108. package/dist/esm/test/splits/splits.spec.js +0 -400
  109. package/dist/types/src/abi/OVMFactory.d.ts +0 -662
  110. package/src/abi/BatchDeposit.ts +0 -117
  111. package/src/abi/MerkleDistributorWithDeadline.ts +0 -70
  112. package/src/abi/Multicall3.ts +0 -250
  113. package/src/abi/OVMFactory.ts +0 -617
  114. package/src/abi/OWR.ts +0 -302
  115. package/src/abi/SplitMain.ts +0 -927
  116. package/src/abi/splitV2FactoryAbi.ts +0 -417
  117. package/src/ajv.ts +0 -191
  118. package/src/base.ts +0 -54
  119. package/src/bytecodes.ts +0 -31
  120. package/src/constants.ts +0 -304
  121. package/src/eoa/eoa.ts +0 -153
  122. package/src/eoa/eoaHelpers.ts +0 -112
  123. package/src/errors.ts +0 -8
  124. package/src/exits/ethUtils.ts +0 -49
  125. package/src/exits/exit.ts +0 -661
  126. package/src/exits/verificationHelpers.ts +0 -110
  127. package/src/incentives/incentiveHelpers.ts +0 -55
  128. package/src/incentives/incentives.ts +0 -153
  129. package/src/index.ts +0 -614
  130. package/src/schema.ts +0 -376
  131. package/src/services.ts +0 -24
  132. package/src/splits/splitHelpers.ts +0 -1032
  133. package/src/splits/splits.ts +0 -504
  134. package/src/types.ts +0 -687
  135. package/src/utils.ts +0 -88
  136. package/src/verification/common.ts +0 -532
  137. package/src/verification/signature-validator.ts +0 -103
  138. package/src/verification/sszTypes.ts +0 -88
  139. package/src/verification/termsAndConditions.ts +0 -32
  140. package/src/verification/v1.10.0.ts +0 -245
  141. package/src/verification/v1.6.0.ts +0 -256
  142. package/src/verification/v1.7.0.ts +0 -309
  143. package/src/verification/v1.8.0.ts +0 -340
@@ -1,142 +0,0 @@
1
- import { UintNumberType, } from '@chainsafe/ssz/lib/type/uint';
2
- import { strToUint8Array } from '../utils';
3
- import { newCreatorContainerType, newOperatorContainerType, validatorsContainerType, } from './sszTypes';
4
- import { ByteListType, ByteVectorType, ContainerType, ListCompositeType, fromHexString, } from '@chainsafe/ssz';
5
- import { verifyDepositData } from './common';
6
- import { aggregateSignatures, verifyAggregate, verifyMultiple, } from '@chainsafe/bls';
7
- /**
8
- * Returns the containerized cluster definition
9
- * @param cluster ClusterDefinition to calculate the type from
10
- * @returns SSZ Containerized type of cluster input
11
- */
12
- export const clusterDefinitionContainerTypeV1X6 = (configOnly) => {
13
- let returnedContainerType = {
14
- uuid: new ByteListType(64),
15
- name: new ByteListType(256),
16
- version: new ByteListType(16),
17
- timestamp: new ByteListType(32),
18
- num_validators: new UintNumberType(8),
19
- threshold: new UintNumberType(8),
20
- dkg_algorithm: new ByteListType(32),
21
- fork_version: new ByteVectorType(4),
22
- operators: new ListCompositeType(newOperatorContainerType(configOnly), 256),
23
- creator: newCreatorContainerType(configOnly),
24
- validators: new ListCompositeType(validatorsContainerType, 65536),
25
- };
26
- if (!configOnly) {
27
- returnedContainerType = Object.assign(Object.assign({}, returnedContainerType), { config_hash: new ByteVectorType(32) });
28
- }
29
- return new ContainerType(returnedContainerType);
30
- };
31
- export const hashClusterDefinitionV1X6 = (cluster, configOnly) => {
32
- const definitionType = clusterDefinitionContainerTypeV1X6(configOnly);
33
- const val = definitionType.defaultValue();
34
- // order should be same as charon https://github.com/ObolNetwork/charon/blob/main/cluster/ssz.go#L276
35
- val.uuid = strToUint8Array(cluster.uuid);
36
- val.name = strToUint8Array(cluster.name);
37
- val.version = strToUint8Array(cluster.version);
38
- val.timestamp = strToUint8Array(cluster.timestamp);
39
- val.num_validators = cluster.num_validators;
40
- val.threshold = cluster.threshold;
41
- val.dkg_algorithm = strToUint8Array(cluster.dkg_algorithm);
42
- val.fork_version = fromHexString(cluster.fork_version);
43
- val.operators = cluster.operators.map(operator => {
44
- return configOnly
45
- ? { address: fromHexString(operator.address) }
46
- : {
47
- address: fromHexString(operator.address),
48
- enr: strToUint8Array(operator.enr),
49
- config_signature: fromHexString(operator.config_signature),
50
- enr_signature: fromHexString(operator.enr_signature),
51
- };
52
- });
53
- val.creator = configOnly
54
- ? { address: fromHexString(cluster.creator.address) }
55
- : {
56
- address: fromHexString(cluster.creator.address),
57
- config_signature: fromHexString(cluster.creator.config_signature),
58
- };
59
- val.validators = cluster.validators.map(validator => {
60
- return {
61
- fee_recipient_address: fromHexString(validator.fee_recipient_address),
62
- withdrawal_address: fromHexString(validator.withdrawal_address),
63
- };
64
- });
65
- if (!configOnly) {
66
- val.config_hash = fromHexString(cluster.config_hash);
67
- }
68
- return val;
69
- };
70
- // cluster lock
71
- const dvContainerTypeV1X6 = new ContainerType({
72
- distributed_public_key: new ByteVectorType(48),
73
- public_shares: new ListCompositeType(new ByteVectorType(48), 256),
74
- pubkey: new ByteVectorType(48),
75
- withdrawal_credentials: new ByteVectorType(32),
76
- amount: new UintNumberType(8),
77
- signature: new ByteVectorType(96),
78
- });
79
- /**
80
- * @returns SSZ Containerized type of cluster lock
81
- */
82
- const clusterLockContainerTypeV1X6 = () => {
83
- return new ContainerType({
84
- cluster_definition: clusterDefinitionContainerTypeV1X6(false),
85
- distributed_validators: new ListCompositeType(dvContainerTypeV1X6, 65536),
86
- });
87
- };
88
- /**
89
- * @param cluster The published cluster lock
90
- * @returns The lock hash in of the corresponding cluster
91
- */
92
- export const hashClusterLockV1X6 = (cluster) => {
93
- const lockType = clusterLockContainerTypeV1X6();
94
- const val = lockType.defaultValue();
95
- // Check if we can replace with definition_hash
96
- val.cluster_definition = hashClusterDefinitionV1X6(cluster.cluster_definition, false);
97
- val.distributed_validators = cluster.distributed_validators.map(dValidator => {
98
- var _a, _b, _c, _d;
99
- return {
100
- distributed_public_key: fromHexString(dValidator.distributed_public_key),
101
- public_shares: dValidator.public_shares.map(publicShare => fromHexString(publicShare)),
102
- pubkey: fromHexString((_a = dValidator.deposit_data) === null || _a === void 0 ? void 0 : _a.pubkey),
103
- withdrawal_credentials: fromHexString((_b = dValidator.deposit_data) === null || _b === void 0 ? void 0 : _b.withdrawal_credentials),
104
- amount: parseInt((_c = dValidator.deposit_data) === null || _c === void 0 ? void 0 : _c.amount),
105
- signature: fromHexString((_d = dValidator.deposit_data) === null || _d === void 0 ? void 0 : _d.signature),
106
- };
107
- });
108
- return '0x' + Buffer.from(lockType.hashTreeRoot(val).buffer).toString('hex');
109
- };
110
- // DV verification
111
- export const verifyDVV1X6 = (clusterLock) => {
112
- var _a;
113
- const validators = clusterLock.distributed_validators;
114
- const pubShares = [];
115
- const pubKeys = [];
116
- const builderRegistrationAndDepositDataMessages = [];
117
- const blsSignatures = [];
118
- for (let i = 0; i < validators.length; i++) {
119
- const validator = validators[i];
120
- const validatorPublicShares = validator.public_shares;
121
- const distributedPublicKey = validator.distributed_public_key;
122
- // Needed in signature_aggregate verification
123
- for (const element of validatorPublicShares) {
124
- pubShares.push(fromHexString(element));
125
- }
126
- const { isValidDepositData, depositDataMsg } = verifyDepositData(distributedPublicKey, validator.deposit_data, clusterLock.cluster_definition.validators[i].withdrawal_address, clusterLock.cluster_definition.fork_version);
127
- if (!isValidDepositData) {
128
- return false;
129
- }
130
- pubKeys.push(fromHexString(validator.distributed_public_key));
131
- builderRegistrationAndDepositDataMessages.push(depositDataMsg);
132
- blsSignatures.push(fromHexString((_a = validator.deposit_data) === null || _a === void 0 ? void 0 : _a.signature));
133
- }
134
- const aggregateBLSSignature = aggregateSignatures(blsSignatures);
135
- if (!verifyMultiple(pubKeys, builderRegistrationAndDepositDataMessages, aggregateBLSSignature)) {
136
- return false;
137
- }
138
- if (!verifyAggregate(pubShares, fromHexString(clusterLock.lock_hash), fromHexString(clusterLock.signature_aggregate))) {
139
- return false;
140
- }
141
- return true;
142
- };
@@ -1,166 +0,0 @@
1
- import { UintNumberType, } from '@chainsafe/ssz/lib/type/uint';
2
- import { strToUint8Array } from '../utils';
3
- import { builderRegistrationContainer, depositDataContainer, newCreatorContainerType, newOperatorContainerType, validatorsContainerType, } from './sszTypes';
4
- import { ByteListType, ByteVectorType, ContainerType, ListCompositeType, fromHexString, } from '@chainsafe/ssz';
5
- import { verifyBuilderRegistration, verifyDepositData, verifyNodeSignatures, } from './common';
6
- import { aggregateSignatures, verifyAggregate, verifyMultiple, } from '@chainsafe/bls';
7
- /**
8
- * Returns the containerized cluster definition
9
- * @param cluster ClusterDefinition to calculate the type from
10
- * @returns SSZ Containerized type of cluster input
11
- */
12
- export const clusterDefinitionContainerTypeV1X7 = (configOnly) => {
13
- let returnedContainerType = {
14
- uuid: new ByteListType(64),
15
- name: new ByteListType(256),
16
- version: new ByteListType(16),
17
- timestamp: new ByteListType(32),
18
- num_validators: new UintNumberType(8),
19
- threshold: new UintNumberType(8),
20
- dkg_algorithm: new ByteListType(32),
21
- fork_version: new ByteVectorType(4),
22
- operators: new ListCompositeType(newOperatorContainerType(configOnly), 256),
23
- creator: newCreatorContainerType(configOnly),
24
- validators: new ListCompositeType(validatorsContainerType, 65536),
25
- };
26
- if (!configOnly) {
27
- returnedContainerType = Object.assign(Object.assign({}, returnedContainerType), { config_hash: new ByteVectorType(32) });
28
- }
29
- return new ContainerType(returnedContainerType);
30
- };
31
- export const hashClusterDefinitionV1X7 = (cluster, configOnly) => {
32
- const definitionType = clusterDefinitionContainerTypeV1X7(configOnly);
33
- const val = definitionType.defaultValue();
34
- // order should be same as charon https://github.com/ObolNetwork/charon/blob/main/cluster/ssz.go#L276
35
- val.uuid = strToUint8Array(cluster.uuid);
36
- val.name = strToUint8Array(cluster.name);
37
- val.version = strToUint8Array(cluster.version);
38
- val.timestamp = strToUint8Array(cluster.timestamp);
39
- val.num_validators = cluster.num_validators;
40
- val.threshold = cluster.threshold;
41
- val.dkg_algorithm = strToUint8Array(cluster.dkg_algorithm);
42
- val.fork_version = fromHexString(cluster.fork_version);
43
- val.operators = cluster.operators.map(operator => {
44
- return configOnly
45
- ? { address: fromHexString(operator.address) }
46
- : {
47
- address: fromHexString(operator.address),
48
- enr: strToUint8Array(operator.enr),
49
- config_signature: fromHexString(operator.config_signature),
50
- enr_signature: fromHexString(operator.enr_signature),
51
- };
52
- });
53
- val.creator = configOnly
54
- ? { address: fromHexString(cluster.creator.address) }
55
- : {
56
- address: fromHexString(cluster.creator.address),
57
- config_signature: fromHexString(cluster.creator.config_signature),
58
- };
59
- val.validators = cluster.validators.map(validator => {
60
- return {
61
- fee_recipient_address: fromHexString(validator.fee_recipient_address),
62
- withdrawal_address: fromHexString(validator.withdrawal_address),
63
- };
64
- });
65
- if (!configOnly) {
66
- val.config_hash = fromHexString(cluster.config_hash);
67
- }
68
- return val;
69
- };
70
- // cluster lock
71
- const dvContainerTypeV1X7 = new ContainerType({
72
- distributed_public_key: new ByteVectorType(48),
73
- public_shares: new ListCompositeType(new ByteVectorType(48), 256),
74
- deposit_data: depositDataContainer,
75
- builder_registration: builderRegistrationContainer,
76
- });
77
- /**
78
- * @returns SSZ Containerized type of cluster lock
79
- */
80
- const clusterLockContainerTypeV1X7 = () => {
81
- return new ContainerType({
82
- cluster_definition: clusterDefinitionContainerTypeV1X7(false),
83
- distributed_validators: new ListCompositeType(dvContainerTypeV1X7, 65536),
84
- });
85
- };
86
- /**
87
- * @param cluster The published cluster lock
88
- * @returns The lock hash in of the corresponding cluster
89
- */
90
- export const hashClusterLockV1X7 = (cluster) => {
91
- const lockType = clusterLockContainerTypeV1X7();
92
- const val = lockType.defaultValue();
93
- // Check if we can replace with definition_hash
94
- val.cluster_definition = hashClusterDefinitionV1X7(cluster.cluster_definition, false);
95
- val.distributed_validators = cluster.distributed_validators.map(dValidator => {
96
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
97
- return {
98
- distributed_public_key: fromHexString(dValidator.distributed_public_key),
99
- public_shares: dValidator.public_shares.map(publicShare => fromHexString(publicShare)),
100
- deposit_data: {
101
- pubkey: fromHexString((_a = dValidator.deposit_data) === null || _a === void 0 ? void 0 : _a.pubkey),
102
- withdrawal_credentials: fromHexString((_b = dValidator.deposit_data) === null || _b === void 0 ? void 0 : _b.withdrawal_credentials),
103
- amount: parseInt((_c = dValidator.deposit_data) === null || _c === void 0 ? void 0 : _c.amount),
104
- signature: fromHexString((_d = dValidator.deposit_data) === null || _d === void 0 ? void 0 : _d.signature),
105
- },
106
- builder_registration: {
107
- message: {
108
- fee_recipient: fromHexString((_e = dValidator.builder_registration) === null || _e === void 0 ? void 0 : _e.message.fee_recipient),
109
- gas_limit: (_f = dValidator.builder_registration) === null || _f === void 0 ? void 0 : _f.message.gas_limit,
110
- timestamp: (_g = dValidator.builder_registration) === null || _g === void 0 ? void 0 : _g.message.timestamp,
111
- pubkey: fromHexString((_h = dValidator.builder_registration) === null || _h === void 0 ? void 0 : _h.message.pubkey),
112
- },
113
- signature: fromHexString((_j = dValidator.builder_registration) === null || _j === void 0 ? void 0 : _j.signature),
114
- },
115
- };
116
- });
117
- return '0x' + Buffer.from(lockType.hashTreeRoot(val).buffer).toString('hex');
118
- };
119
- // DV verification
120
- export const verifyDVV1X7 = (clusterLock) => {
121
- var _a, _b;
122
- const validators = clusterLock.distributed_validators;
123
- const pubShares = [];
124
- const pubKeys = [];
125
- const builderRegistrationAndDepositDataMessages = [];
126
- const blsSignatures = [];
127
- for (let i = 0; i < validators.length; i++) {
128
- const validator = validators[i];
129
- const validatorPublicShares = validator.public_shares;
130
- const distributedPublicKey = validator.distributed_public_key;
131
- // Needed in signature_aggregate verification
132
- for (const element of validatorPublicShares) {
133
- pubShares.push(fromHexString(element));
134
- }
135
- // Deposit Data Verification
136
- const { isValidDepositData, depositDataMsg } = verifyDepositData(distributedPublicKey, validator.deposit_data, clusterLock.cluster_definition.validators[i].withdrawal_address, clusterLock.cluster_definition.fork_version);
137
- if (!isValidDepositData) {
138
- return false;
139
- }
140
- pubKeys.push(fromHexString(distributedPublicKey));
141
- builderRegistrationAndDepositDataMessages.push(depositDataMsg);
142
- blsSignatures.push(fromHexString((_a = validator.deposit_data) === null || _a === void 0 ? void 0 : _a.signature));
143
- // Builder Registration Verification
144
- const { isValidBuilderRegistration, builderRegistrationMsg } = verifyBuilderRegistration(validator, clusterLock.cluster_definition.validators[i].fee_recipient_address, clusterLock.cluster_definition.fork_version);
145
- if (!isValidBuilderRegistration) {
146
- return false;
147
- }
148
- pubKeys.push(fromHexString(distributedPublicKey));
149
- builderRegistrationAndDepositDataMessages.push(builderRegistrationMsg);
150
- blsSignatures.push(fromHexString((_b = validator.builder_registration) === null || _b === void 0 ? void 0 : _b.signature));
151
- }
152
- // BLS signatures verification
153
- const aggregateBLSSignature = aggregateSignatures(blsSignatures);
154
- if (!verifyMultiple(pubKeys, builderRegistrationAndDepositDataMessages, aggregateBLSSignature)) {
155
- return false;
156
- }
157
- // Node Signatures verification
158
- if (!verifyNodeSignatures(clusterLock)) {
159
- return false;
160
- }
161
- // signature_aggregate verification
162
- if (!verifyAggregate(pubShares, fromHexString(clusterLock.lock_hash), fromHexString(clusterLock.signature_aggregate))) {
163
- return false;
164
- }
165
- return true;
166
- };
@@ -1,189 +0,0 @@
1
- import { UintNumberType, } from '@chainsafe/ssz/lib/type/uint';
2
- import { strToUint8Array } from '../utils';
3
- import { builderRegistrationContainer, depositDataContainer, newCreatorContainerType, newOperatorContainerType, validatorsContainerType, } from './sszTypes';
4
- import { ByteListType, ByteVectorType, ContainerType, ListBasicType, ListCompositeType, fromHexString, } from '@chainsafe/ssz';
5
- import { verifyBuilderRegistration, verifyDepositData, verifyNodeSignatures, } from './common';
6
- import { aggregateSignatures, verifyAggregate, verifyMultiple, } from '@chainsafe/bls';
7
- /**
8
- * Returns the containerized cluster definition
9
- * @param cluster ClusterDefinition to calculate the type from
10
- * @returns SSZ Containerized type of cluster input
11
- */
12
- export const clusterDefinitionContainerTypeV1X8 = (configOnly) => {
13
- let returnedContainerType = {
14
- uuid: new ByteListType(64),
15
- name: new ByteListType(256),
16
- version: new ByteListType(16),
17
- timestamp: new ByteListType(32),
18
- num_validators: new UintNumberType(8),
19
- threshold: new UintNumberType(8),
20
- dkg_algorithm: new ByteListType(32),
21
- fork_version: new ByteVectorType(4),
22
- operators: new ListCompositeType(newOperatorContainerType(configOnly), 256),
23
- creator: newCreatorContainerType(configOnly),
24
- validators: new ListCompositeType(validatorsContainerType, 65536),
25
- deposit_amounts: new ListBasicType(new UintNumberType(8), 256),
26
- };
27
- if (!configOnly) {
28
- returnedContainerType = Object.assign(Object.assign({}, returnedContainerType), { config_hash: new ByteVectorType(32) });
29
- }
30
- return new ContainerType(returnedContainerType);
31
- };
32
- export const hashClusterDefinitionV1X8 = (cluster, configOnly) => {
33
- const definitionType = clusterDefinitionContainerTypeV1X8(configOnly);
34
- const val = definitionType.defaultValue();
35
- // order should be same as charon https://github.com/ObolNetwork/charon/blob/main/cluster/ssz.go#L276
36
- val.uuid = strToUint8Array(cluster.uuid);
37
- val.name = strToUint8Array(cluster.name);
38
- val.version = strToUint8Array(cluster.version);
39
- val.timestamp = strToUint8Array(cluster.timestamp);
40
- val.num_validators = cluster.num_validators;
41
- val.threshold = cluster.threshold;
42
- val.dkg_algorithm = strToUint8Array(cluster.dkg_algorithm);
43
- val.fork_version = fromHexString(cluster.fork_version);
44
- val.operators = cluster.operators.map(operator => {
45
- return configOnly
46
- ? { address: fromHexString(operator.address) }
47
- : {
48
- address: fromHexString(operator.address),
49
- enr: strToUint8Array(operator.enr),
50
- config_signature: fromHexString(operator.config_signature),
51
- enr_signature: fromHexString(operator.enr_signature),
52
- };
53
- });
54
- val.creator = configOnly
55
- ? { address: fromHexString(cluster.creator.address) }
56
- : {
57
- address: fromHexString(cluster.creator.address),
58
- config_signature: fromHexString(cluster.creator.config_signature),
59
- };
60
- val.validators = cluster.validators.map(validator => {
61
- return {
62
- fee_recipient_address: fromHexString(validator.fee_recipient_address),
63
- withdrawal_address: fromHexString(validator.withdrawal_address),
64
- };
65
- });
66
- if (cluster.deposit_amounts) {
67
- val.deposit_amounts = cluster.deposit_amounts.map((amount) => {
68
- return parseInt(amount);
69
- });
70
- }
71
- if (!configOnly) {
72
- val.config_hash = fromHexString(cluster.config_hash);
73
- }
74
- return val;
75
- };
76
- // cluster lock
77
- const dvContainerTypeV1X8 = new ContainerType({
78
- distributed_public_key: new ByteVectorType(48),
79
- public_shares: new ListCompositeType(new ByteVectorType(48), 256),
80
- partial_deposit_data: new ListCompositeType(depositDataContainer, 256),
81
- builder_registration: builderRegistrationContainer,
82
- });
83
- /**
84
- * @returns SSZ Containerized type of cluster lock
85
- */
86
- const clusterLockContainerTypeV1X8 = () => {
87
- return new ContainerType({
88
- cluster_definition: clusterDefinitionContainerTypeV1X8(false),
89
- distributed_validators: new ListCompositeType(dvContainerTypeV1X8, 65536),
90
- });
91
- };
92
- /**
93
- * @param cluster The published cluster lock
94
- * @returns The lock hash in of the corresponding cluster
95
- */
96
- export const hashClusterLockV1X8 = (cluster) => {
97
- const lockType = clusterLockContainerTypeV1X8();
98
- const val = lockType.defaultValue();
99
- // Check if we can replace with definition_hash
100
- val.cluster_definition = hashClusterDefinitionV1X8(cluster.cluster_definition, false);
101
- val.distributed_validators = cluster.distributed_validators.map(dValidator => {
102
- var _a, _b, _c, _d, _e;
103
- return {
104
- distributed_public_key: fromHexString(dValidator.distributed_public_key),
105
- public_shares: dValidator.public_shares.map(publicShare => fromHexString(publicShare)),
106
- // should be fixed
107
- partial_deposit_data: dValidator.partial_deposit_data.map(depositData => {
108
- return {
109
- pubkey: fromHexString(depositData.pubkey),
110
- withdrawal_credentials: fromHexString(depositData.withdrawal_credentials),
111
- amount: parseInt(depositData.amount),
112
- signature: fromHexString(depositData.signature),
113
- };
114
- }),
115
- builder_registration: {
116
- message: {
117
- fee_recipient: fromHexString((_a = dValidator.builder_registration) === null || _a === void 0 ? void 0 : _a.message.fee_recipient),
118
- gas_limit: (_b = dValidator.builder_registration) === null || _b === void 0 ? void 0 : _b.message.gas_limit,
119
- timestamp: (_c = dValidator.builder_registration) === null || _c === void 0 ? void 0 : _c.message.timestamp,
120
- pubkey: fromHexString((_d = dValidator.builder_registration) === null || _d === void 0 ? void 0 : _d.message.pubkey),
121
- },
122
- signature: fromHexString((_e = dValidator.builder_registration) === null || _e === void 0 ? void 0 : _e.signature),
123
- },
124
- };
125
- });
126
- return '0x' + Buffer.from(lockType.hashTreeRoot(val).buffer).toString('hex');
127
- };
128
- // DV verification
129
- export const verifyDVV1X8 = (clusterLock) => {
130
- var _a;
131
- const validators = clusterLock.distributed_validators;
132
- const pubShares = [];
133
- const pubKeys = [];
134
- const builderRegistrationAndDepositDataMessages = [];
135
- const blsSignatures = [];
136
- for (let i = 0; i < validators.length; i++) {
137
- const validator = validators[i];
138
- const validatorPublicShares = validator.public_shares;
139
- const distributedPublicKey = validator.distributed_public_key;
140
- // Needed in signature_aggregate verification
141
- for (const element of validatorPublicShares) {
142
- pubShares.push(fromHexString(element));
143
- }
144
- // Check deposit amounts match exactly if they are defined
145
- const depositAmounts = clusterLock.cluster_definition.deposit_amounts;
146
- if (!!depositAmounts && depositAmounts !== null) {
147
- const partialDepositAmounts = validator.partial_deposit_data.map(d => d.amount);
148
- // Check that partialDepositAmounts includes all unique elements of depositAmounts
149
- const uniqueDepositAmounts = [...new Set(depositAmounts.map(Number))];
150
- const partialAmountsSet = new Set(partialDepositAmounts.map(Number));
151
- if (!uniqueDepositAmounts.every(amount => partialAmountsSet.has(amount))) {
152
- return false;
153
- }
154
- }
155
- // Deposit Data Verification
156
- for (const element of validator.partial_deposit_data) {
157
- const depositData = element;
158
- const { isValidDepositData, depositDataMsg } = verifyDepositData(distributedPublicKey, depositData, clusterLock.cluster_definition.validators[i].withdrawal_address, clusterLock.cluster_definition.fork_version, clusterLock.cluster_definition.compounding);
159
- if (!isValidDepositData) {
160
- return false;
161
- }
162
- pubKeys.push(fromHexString(distributedPublicKey));
163
- builderRegistrationAndDepositDataMessages.push(depositDataMsg);
164
- blsSignatures.push(fromHexString(depositData === null || depositData === void 0 ? void 0 : depositData.signature));
165
- }
166
- // Builder Registration Verification
167
- const { isValidBuilderRegistration, builderRegistrationMsg } = verifyBuilderRegistration(validator, clusterLock.cluster_definition.validators[i].fee_recipient_address, clusterLock.cluster_definition.fork_version);
168
- if (!isValidBuilderRegistration) {
169
- return false;
170
- }
171
- pubKeys.push(fromHexString(distributedPublicKey));
172
- builderRegistrationAndDepositDataMessages.push(builderRegistrationMsg);
173
- blsSignatures.push(fromHexString((_a = validator.builder_registration) === null || _a === void 0 ? void 0 : _a.signature));
174
- }
175
- // BLS signatures verification
176
- const aggregateBLSSignature = aggregateSignatures(blsSignatures);
177
- if (!verifyMultiple(pubKeys, builderRegistrationAndDepositDataMessages, aggregateBLSSignature)) {
178
- return false;
179
- }
180
- // Node Signatures verification
181
- if (!verifyNodeSignatures(clusterLock)) {
182
- return false;
183
- }
184
- // signature_aggregate verification
185
- if (!verifyAggregate(pubShares, fromHexString(clusterLock.lock_hash), fromHexString(clusterLock.signature_aggregate))) {
186
- return false;
187
- }
188
- return true;
189
- };