@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,319 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { fromHexString } from '@chainsafe/ssz';
11
- import elliptic from 'elliptic';
12
- import { init } from '@chainsafe/bls';
13
- import { FORK_MAPPING, } from '../types.js';
14
- import * as semver from 'semver';
15
- import { clusterDefinitionContainerTypeV1X6, hashClusterDefinitionV1X6, hashClusterLockV1X6, verifyDVV1X6, } from './v1.6.0.js';
16
- import { clusterDefinitionContainerTypeV1X7, hashClusterDefinitionV1X7, hashClusterLockV1X7, verifyDVV1X7, } from './v1.7.0.js';
17
- import { DOMAIN_APPLICATION_BUILDER, DOMAIN_DEPOSIT, DefinitionFlow, GENESIS_VALIDATOR_ROOT, signCreatorConfigHashPayload, signEnrPayload, signOperatorConfigHashPayload, } from '../constants.js';
18
- import { builderRegistrationMessageType, depositMessageType, forkDataType, signingRootType, } from './sszTypes.js';
19
- import { definitionFlow, hexWithout0x } from '../utils.js';
20
- import { ENR } from '@chainsafe/discv5';
21
- import { clusterDefinitionContainerTypeV1X8, hashClusterDefinitionV1X8, hashClusterLockV1X8, verifyDVV1X8, } from './v1.8.0.js';
22
- import { validateAddressSignature } from './signature-validator.js';
23
- import { clusterDefinitionContainerTypeV1X10, hashClusterDefinitionV1X10, hashClusterLockV1X10, verifyDVV1X10, } from './v1.10.0.js';
24
- // cluster-definition hash
25
- /**
26
- * @param cluster The cluster configuration or the cluster definition
27
- * @param configOnly a boolean to indicate config hash or definition hash
28
- * @returns The config hash or the definition hash in of the corresponding cluster
29
- */
30
- export const clusterConfigOrDefinitionHash = (cluster, configOnly) => {
31
- let definitionType, val;
32
- if (semver.eq(cluster.version, 'v1.6.0')) {
33
- definitionType = clusterDefinitionContainerTypeV1X6(configOnly);
34
- val = hashClusterDefinitionV1X6(cluster, configOnly);
35
- return ('0x' +
36
- Buffer.from(definitionType.hashTreeRoot(val).buffer).toString('hex'));
37
- }
38
- if (semver.eq(cluster.version, 'v1.7.0')) {
39
- definitionType = clusterDefinitionContainerTypeV1X7(configOnly);
40
- val = hashClusterDefinitionV1X7(cluster, configOnly);
41
- return ('0x' +
42
- Buffer.from(definitionType.hashTreeRoot(val).buffer).toString('hex'));
43
- }
44
- if (semver.eq(cluster.version, 'v1.8.0')) {
45
- definitionType = clusterDefinitionContainerTypeV1X8(configOnly);
46
- val = hashClusterDefinitionV1X8(cluster, configOnly);
47
- return ('0x' +
48
- Buffer.from(definitionType.hashTreeRoot(val).buffer).toString('hex'));
49
- }
50
- if (semver.eq(cluster.version, 'v1.10.0')) {
51
- definitionType = clusterDefinitionContainerTypeV1X10(configOnly);
52
- val = hashClusterDefinitionV1X10(cluster, configOnly);
53
- const x = '0x' +
54
- Buffer.from(definitionType.hashTreeRoot(val).buffer).toString('hex');
55
- return x;
56
- }
57
- throw new Error('unsupported version');
58
- };
59
- // cluster-lock hash
60
- /**
61
- * Returns the SSZ cluster lock hash of the given cluster lock object
62
- * @param cluster The cluster lock whose lock hash needs to be calculated
63
- * @returns The cluster lock hash in of the corresponding cluster lock
64
- */
65
- export const clusterLockHash = (clusterLock) => {
66
- if (semver.eq(clusterLock.cluster_definition.version, 'v1.6.0')) {
67
- return hashClusterLockV1X6(clusterLock);
68
- }
69
- if (semver.eq(clusterLock.cluster_definition.version, 'v1.7.0')) {
70
- return hashClusterLockV1X7(clusterLock);
71
- }
72
- if (semver.eq(clusterLock.cluster_definition.version, 'v1.8.0')) {
73
- if (clusterLock.cluster_definition.deposit_amounts === null &&
74
- clusterLock.distributed_validators.some(distributedValidator => {
75
- var _a;
76
- return ((_a = distributedValidator.partial_deposit_data) === null || _a === void 0 ? void 0 : _a.length) !== 1 ||
77
- distributedValidator.partial_deposit_data[0].amount !== '32000000000';
78
- })) {
79
- throw new Error('mismatch between deposit_amounts and partial_deposit_data fields');
80
- }
81
- return hashClusterLockV1X8(clusterLock);
82
- }
83
- if (semver.eq(clusterLock.cluster_definition.version, 'v1.10.0')) {
84
- // if (
85
- // clusterLock.cluster_definition.deposit_amounts === null &&
86
- // clusterLock.distributed_validators.some(
87
- // distributedValidator =>
88
- // distributedValidator.partial_deposit_data?.length !== 1 ||
89
- // distributedValidator.partial_deposit_data[0].amount !== '32000000000',
90
- // )
91
- // ) {
92
- // throw new Error(
93
- // 'mismatch between deposit_amounts and partial_deposit_data fields',
94
- // );
95
- // }
96
- return hashClusterLockV1X10(clusterLock);
97
- }
98
- // other versions
99
- throw new Error('unsupported version');
100
- };
101
- // Lock verification
102
- // cluster-definition signatures verification
103
- const validatePOSTConfigHashSigner = (address, signature, configHash, chainId, safeRpcUrl) => __awaiter(void 0, void 0, void 0, function* () {
104
- try {
105
- const data = signCreatorConfigHashPayload({ creator_config_hash: configHash }, chainId);
106
- return yield validateAddressSignature({
107
- address,
108
- token: signature,
109
- data,
110
- chainId,
111
- safeRpcUrl,
112
- });
113
- }
114
- catch (err) {
115
- throw err;
116
- }
117
- });
118
- const validatePUTConfigHashSigner = (address, signature, configHash, chainId, safeRpcUrl) => __awaiter(void 0, void 0, void 0, function* () {
119
- try {
120
- const data = signOperatorConfigHashPayload({ operator_config_hash: configHash }, chainId);
121
- return yield validateAddressSignature({
122
- address,
123
- token: signature,
124
- data,
125
- chainId,
126
- safeRpcUrl,
127
- });
128
- }
129
- catch (err) {
130
- throw err;
131
- }
132
- });
133
- const validateEnrSigner = (address, signature, payload, chainId, safeRpcUrl) => __awaiter(void 0, void 0, void 0, function* () {
134
- try {
135
- const data = signEnrPayload({ enr: payload }, chainId);
136
- return yield validateAddressSignature({
137
- address,
138
- token: signature,
139
- data,
140
- chainId,
141
- safeRpcUrl,
142
- });
143
- }
144
- catch (err) {
145
- throw err;
146
- }
147
- });
148
- const verifyDefinitionSignatures = (clusterDefinition, definitionType, safeRpcUrl) => __awaiter(void 0, void 0, void 0, function* () {
149
- if (definitionType === DefinitionFlow.Charon) {
150
- return true;
151
- }
152
- else {
153
- const isPOSTConfigHashSignerValid = yield validatePOSTConfigHashSigner(clusterDefinition.creator.address, clusterDefinition.creator.config_signature, clusterDefinition.config_hash, FORK_MAPPING[clusterDefinition.fork_version], safeRpcUrl);
154
- if (!isPOSTConfigHashSignerValid) {
155
- return false;
156
- }
157
- if (definitionType === DefinitionFlow.Solo) {
158
- return true;
159
- }
160
- for (const operator of clusterDefinition.operators) {
161
- const isPUTConfigHashSignerValid = yield validatePUTConfigHashSigner(operator.address, operator.config_signature, clusterDefinition.config_hash, FORK_MAPPING[clusterDefinition.fork_version], safeRpcUrl);
162
- const isENRSignerValid = yield validateEnrSigner(operator.address, operator.enr_signature, operator.enr, FORK_MAPPING[clusterDefinition.fork_version], safeRpcUrl);
163
- if (!isPUTConfigHashSignerValid || !isENRSignerValid) {
164
- return false;
165
- }
166
- }
167
- return true;
168
- }
169
- });
170
- // cluster-lock data verification
171
- const computeSigningRoot = (sszObjectRoot, domain) => {
172
- const signingRootDefaultValue = signingRootType.defaultValue();
173
- signingRootDefaultValue.objectRoot = sszObjectRoot;
174
- signingRootDefaultValue.domain = domain;
175
- return Buffer.from(signingRootType.hashTreeRoot(signingRootDefaultValue).buffer);
176
- };
177
- const computeDepositMsgRoot = (msg) => {
178
- const depositMsgVal = depositMessageType.defaultValue();
179
- depositMsgVal.pubkey = fromHexString(msg.pubkey);
180
- depositMsgVal.withdrawal_credentials = fromHexString(msg.withdrawal_credentials);
181
- depositMsgVal.amount = parseInt(msg.amount);
182
- return Buffer.from(depositMessageType.hashTreeRoot(depositMsgVal).buffer);
183
- };
184
- const computeForkDataRoot = (currentVersion, genesisValidatorsRoot) => {
185
- const forkDataVal = forkDataType.defaultValue();
186
- forkDataVal.currentVersion = currentVersion;
187
- forkDataVal.genesisValidatorsRoot = genesisValidatorsRoot;
188
- return Buffer.from(forkDataType.hashTreeRoot(forkDataVal).buffer);
189
- };
190
- const computebuilderRegistrationMsgRoot = (msg) => {
191
- const builderRegistrationMsgVal = builderRegistrationMessageType.defaultValue();
192
- builderRegistrationMsgVal.fee_recipient = fromHexString(msg.fee_recipient);
193
- builderRegistrationMsgVal.gas_limit = msg.gas_limit;
194
- builderRegistrationMsgVal.timestamp = msg.timestamp;
195
- builderRegistrationMsgVal.pubkey = fromHexString(msg.pubkey);
196
- return Buffer.from(builderRegistrationMessageType.hashTreeRoot(builderRegistrationMsgVal)
197
- .buffer);
198
- };
199
- const computeDomain = (domainType, lockForkVersion, genesisValidatorsRoot = fromHexString(GENESIS_VALIDATOR_ROOT)) => {
200
- const forkVersion = fromHexString(lockForkVersion.substring(2, lockForkVersion.length));
201
- const forkDataRoot = computeForkDataRoot(forkVersion, genesisValidatorsRoot);
202
- const domain = new Uint8Array(32);
203
- domain.set(domainType);
204
- domain.set(forkDataRoot.subarray(0, 28), 4);
205
- return domain;
206
- };
207
- /**
208
- * Verify deposit data withdrawal credintials and signature
209
- * @param {string} forkVersion - fork version in definition file.
210
- * @param {DistributedValidatorDto} validator - distributed validator.
211
- * @param {string} withdrawalAddress - withdrawal address in definition file.
212
- * @returns {boolean} - return if deposit data is valid.
213
- */
214
- export const verifyDepositData = (distributedPublicKey, depositData, withdrawalAddress, forkVersion, compounding) => {
215
- const depositDomain = computeDomain(fromHexString(DOMAIN_DEPOSIT), forkVersion);
216
- const withdrawalPrefix = compounding ? '0x02' : '0x01';
217
- const expectedWithdrawalCredentials = withdrawalPrefix +
218
- '0'.repeat(22) +
219
- withdrawalAddress.toLowerCase().slice(2);
220
- if (expectedWithdrawalCredentials !== depositData.withdrawal_credentials) {
221
- return { isValidDepositData: false, depositDataMsg: new Uint8Array(0) };
222
- }
223
- if (distributedPublicKey !== depositData.pubkey) {
224
- return { isValidDepositData: false, depositDataMsg: new Uint8Array(0) };
225
- }
226
- const depositMessageBuffer = computeDepositMsgRoot(depositData);
227
- const depositDataMessage = signingRoot(depositDomain, depositMessageBuffer);
228
- return { isValidDepositData: true, depositDataMsg: depositDataMessage };
229
- };
230
- export const verifyBuilderRegistration = (validator, feeRecipientAddress, forkVersion) => {
231
- var _a;
232
- const builderDomain = computeDomain(fromHexString(DOMAIN_APPLICATION_BUILDER), forkVersion);
233
- if (validator.distributed_public_key !==
234
- ((_a = validator.builder_registration) === null || _a === void 0 ? void 0 : _a.message.pubkey)) {
235
- return {
236
- isValidBuilderRegistration: false,
237
- builderRegistrationMsg: new Uint8Array(0),
238
- };
239
- }
240
- if (feeRecipientAddress.toLowerCase() !==
241
- validator.builder_registration.message.fee_recipient.toLowerCase()) {
242
- return {
243
- isValidBuilderRegistration: false,
244
- builderRegistrationMsg: new Uint8Array(0),
245
- };
246
- }
247
- const builderRegistrationMessageBuffer = computebuilderRegistrationMsgRoot(validator.builder_registration.message);
248
- const builderRegistrationMessage = signingRoot(builderDomain, builderRegistrationMessageBuffer);
249
- return {
250
- isValidBuilderRegistration: true,
251
- builderRegistrationMsg: builderRegistrationMessage,
252
- };
253
- };
254
- export const verifyNodeSignatures = (clusterLock) => {
255
- const ec = new elliptic.ec('secp256k1');
256
- const nodeSignatures = clusterLock.node_signatures;
257
- const lockHashWithout0x = hexWithout0x(clusterLock.lock_hash);
258
- // node(ENR) signatures
259
- for (let i = 0; i < nodeSignatures.length; i++) {
260
- const pubkey = ENR.decodeTxt(clusterLock.cluster_definition.operators[i].enr).publicKey.toString('hex');
261
- const ENRsignature = {
262
- r: nodeSignatures[i].slice(2, 66),
263
- s: nodeSignatures[i].slice(66, 130),
264
- };
265
- const nodeSignatureVerification = ec
266
- .keyFromPublic(pubkey, 'hex')
267
- .verify(lockHashWithout0x, ENRsignature);
268
- if (!nodeSignatureVerification) {
269
- return false;
270
- }
271
- }
272
- return true;
273
- };
274
- export const signingRoot = (domain, messageBuffer) => {
275
- return computeSigningRoot(messageBuffer, domain);
276
- };
277
- const verifyLockData = (clusterLock) => __awaiter(void 0, void 0, void 0, function* () {
278
- yield init('herumi');
279
- if (semver.eq(clusterLock.cluster_definition.version, 'v1.6.0')) {
280
- return verifyDVV1X6(clusterLock);
281
- }
282
- if (semver.eq(clusterLock.cluster_definition.version, 'v1.7.0')) {
283
- return verifyDVV1X7(clusterLock);
284
- }
285
- if (semver.eq(clusterLock.cluster_definition.version, 'v1.8.0')) {
286
- return verifyDVV1X8(clusterLock);
287
- }
288
- if (semver.eq(clusterLock.cluster_definition.version, 'v1.10.0')) {
289
- return verifyDVV1X10(clusterLock);
290
- }
291
- return false;
292
- });
293
- export const isValidClusterLock = (clusterLock, safeRpcUrl) => __awaiter(void 0, void 0, void 0, function* () {
294
- try {
295
- const definitionType = definitionFlow(clusterLock.cluster_definition);
296
- if (definitionType == null) {
297
- return false;
298
- }
299
- const isValidDefinitionData = yield verifyDefinitionSignatures(clusterLock.cluster_definition, definitionType, safeRpcUrl);
300
- if (!isValidDefinitionData) {
301
- return false;
302
- }
303
- if (clusterConfigOrDefinitionHash(clusterLock.cluster_definition, false) !==
304
- clusterLock.cluster_definition.definition_hash) {
305
- return false;
306
- }
307
- if (clusterLockHash(clusterLock) !== clusterLock.lock_hash) {
308
- return false;
309
- }
310
- const isValidLockData = yield verifyLockData(clusterLock);
311
- if (!isValidLockData) {
312
- return false;
313
- }
314
- return true;
315
- }
316
- catch (err) {
317
- return false;
318
- }
319
- });
@@ -1,64 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- /* eslint-disable @typescript-eslint/restrict-template-expressions */
11
- import { ethers } from 'ethers';
12
- import { SignTypedDataVersion, TypedDataUtils, } from '@metamask/eth-sig-util';
13
- import Safe from '@safe-global/protocol-kit';
14
- import { PROVIDER_MAP } from '../constants';
15
- import { hashTypedData } from '@safe-global/protocol-kit/dist/src/utils';
16
- import { isContractAvailable, getProvider } from '../utils';
17
- export const validateAddressSignature = ({ address, token, data, chainId, safeRpcUrl, }) => __awaiter(void 0, void 0, void 0, function* () {
18
- try {
19
- const provider = getProvider(chainId, safeRpcUrl);
20
- if (provider) {
21
- const contractAddress = yield isContractAvailable(address, provider);
22
- if (contractAddress) {
23
- return yield validateSmartContractSignature({
24
- token,
25
- data: data,
26
- address,
27
- chainId,
28
- safeRpcUrl,
29
- });
30
- }
31
- }
32
- return validateEOASignature({ token, data, address });
33
- }
34
- catch (error) {
35
- return validateEOASignature({ token, data, address });
36
- }
37
- });
38
- export const validateEOASignature = ({ token, data, address, }) => {
39
- try {
40
- const sig = ethers.Signature.from(token);
41
- const digest = TypedDataUtils.eip712Hash(data, SignTypedDataVersion.V4);
42
- return (ethers.recoverAddress(digest, sig).toLowerCase() ===
43
- address.toLocaleLowerCase());
44
- }
45
- catch (err) {
46
- console.error(`validate EOA Signature error: ${err}`);
47
- throw err;
48
- }
49
- };
50
- export const validateSmartContractSignature = ({ token, data, address, chainId, safeRpcUrl, }) => __awaiter(void 0, void 0, void 0, function* () {
51
- try {
52
- const safeProvider = safeRpcUrl !== null && safeRpcUrl !== void 0 ? safeRpcUrl : PROVIDER_MAP[chainId];
53
- const protocolKit = yield Safe.init({
54
- provider: safeProvider,
55
- safeAddress: address,
56
- });
57
- const messageHash = hashTypedData(data);
58
- const isValidSignature = yield protocolKit.isValidSignature(messageHash, token);
59
- return isValidSignature;
60
- }
61
- catch (err) {
62
- throw new Error(`Error validating smart contract signature: ${err.message}`);
63
- }
64
- });
@@ -1,64 +0,0 @@
1
- import { ByteListType, ByteVectorType, ContainerType, UintNumberType, } from '@chainsafe/ssz';
2
- export const operatorAddressWrapperType = new ContainerType({
3
- address: new ByteVectorType(20),
4
- });
5
- export const creatorAddressWrapperType = new ContainerType({
6
- address: new ByteVectorType(20),
7
- });
8
- export const operatorContainerType = new ContainerType({
9
- address: new ByteVectorType(20),
10
- enr: new ByteListType(1024), // This needs to be dynamic, since ENRs do not have a fixed length.
11
- config_signature: new ByteVectorType(65),
12
- enr_signature: new ByteVectorType(65),
13
- });
14
- export const creatorContainerType = new ContainerType({
15
- address: new ByteVectorType(20),
16
- config_signature: new ByteVectorType(65),
17
- });
18
- export const validatorsContainerType = new ContainerType({
19
- fee_recipient_address: new ByteVectorType(20),
20
- withdrawal_address: new ByteVectorType(20),
21
- });
22
- export const newCreatorContainerType = (configOnly) => {
23
- return configOnly ? creatorAddressWrapperType : creatorContainerType;
24
- };
25
- export const newOperatorContainerType = (configOnly) => {
26
- return configOnly ? operatorAddressWrapperType : operatorContainerType;
27
- };
28
- // Lock
29
- export const depositDataContainer = new ContainerType({
30
- pubkey: new ByteVectorType(48),
31
- withdrawal_credentials: new ByteVectorType(32),
32
- amount: new UintNumberType(8),
33
- signature: new ByteVectorType(96),
34
- });
35
- export const builderRegistrationMessageContainer = new ContainerType({
36
- fee_recipient: new ByteVectorType(20),
37
- gas_limit: new UintNumberType(8),
38
- timestamp: new UintNumberType(8),
39
- pubkey: new ByteVectorType(48),
40
- });
41
- export const builderRegistrationContainer = new ContainerType({
42
- message: builderRegistrationMessageContainer,
43
- signature: new ByteVectorType(96),
44
- });
45
- export const builderRegistrationMessageType = new ContainerType({
46
- fee_recipient: new ByteVectorType(20),
47
- gas_limit: new UintNumberType(8),
48
- timestamp: new UintNumberType(8),
49
- pubkey: new ByteVectorType(48),
50
- });
51
- // For domain computation that is used in deposit data and builder registration verification for dv
52
- export const forkDataType = new ContainerType({
53
- currentVersion: new ByteVectorType(4),
54
- genesisValidatorsRoot: new ByteVectorType(32),
55
- });
56
- export const depositMessageType = new ContainerType({
57
- pubkey: new ByteVectorType(48),
58
- withdrawal_credentials: new ByteVectorType(32),
59
- amount: new UintNumberType(8),
60
- });
61
- export const signingRootType = new ContainerType({
62
- objectRoot: new ByteVectorType(32),
63
- domain: new ByteVectorType(32),
64
- });
@@ -1,33 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import pdf from 'pdf-parse';
11
- import { ByteListType, ContainerType } from '@chainsafe/ssz';
12
- import { TERMS_AND_CONDITIONS_URL } from '../constants';
13
- import { strToUint8Array } from '../utils';
14
- export const hashTermsAndConditions = () => __awaiter(void 0, void 0, void 0, function* () {
15
- try {
16
- // read the pdf
17
- const response = yield fetch(TERMS_AND_CONDITIONS_URL);
18
- const pdfBuffarrayBuffer = yield response.arrayBuffer();
19
- const pdfBuffer = Buffer.from(pdfBuffarrayBuffer);
20
- const data = yield pdf(pdfBuffer);
21
- // ssz hash
22
- const termsType = new ContainerType({
23
- terms_and_conditions_hash: new ByteListType(Number.MAX_SAFE_INTEGER),
24
- });
25
- const termsHasVal = termsType.defaultValue();
26
- termsHasVal.terms_and_conditions_hash = strToUint8Array(data === null || data === void 0 ? void 0 : data.text.replace(/[^a-zA-Z0-9]/g, ''));
27
- return ('0x' +
28
- Buffer.from(termsType.hashTreeRoot(termsHasVal).buffer).toString('hex'));
29
- }
30
- catch (err) {
31
- return null;
32
- }
33
- });
@@ -1,140 +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, BooleanType, } from '@chainsafe/ssz';
5
- import { verifyDVV1X8 } from './v1.8.0';
6
- /**
7
- * Returns the containerized cluster definition
8
- * @param cluster ClusterDefinition to calculate the type from
9
- * @returns SSZ Containerized type of cluster input
10
- */
11
- export const clusterDefinitionContainerTypeV1X10 = (configOnly) => {
12
- let returnedContainerType = {
13
- uuid: new ByteListType(64),
14
- name: new ByteListType(256),
15
- version: new ByteListType(16),
16
- timestamp: new ByteListType(32),
17
- num_validators: new UintNumberType(8),
18
- threshold: new UintNumberType(8),
19
- dkg_algorithm: new ByteListType(32),
20
- fork_version: new ByteVectorType(4),
21
- operators: new ListCompositeType(newOperatorContainerType(configOnly), 256),
22
- creator: newCreatorContainerType(configOnly),
23
- validators: new ListCompositeType(validatorsContainerType, 65536),
24
- deposit_amounts: new ListBasicType(new UintNumberType(8), 256),
25
- consensus_protocol: new ByteListType(256),
26
- target_gas_limit: new UintNumberType(8),
27
- compounding: new BooleanType(),
28
- };
29
- if (!configOnly) {
30
- returnedContainerType = Object.assign(Object.assign({}, returnedContainerType), { config_hash: new ByteVectorType(32) });
31
- }
32
- return new ContainerType(returnedContainerType);
33
- };
34
- export const hashClusterDefinitionV1X10 = (cluster, configOnly) => {
35
- const definitionType = clusterDefinitionContainerTypeV1X10(configOnly);
36
- const val = definitionType.defaultValue();
37
- // order should be same as charon https://github.com/ObolNetwork/charon/blob/main/cluster/ssz.go#L276
38
- val.uuid = strToUint8Array(cluster.uuid);
39
- val.name = strToUint8Array(cluster.name);
40
- val.version = strToUint8Array(cluster.version);
41
- val.timestamp = strToUint8Array(cluster.timestamp);
42
- val.num_validators = cluster.num_validators;
43
- val.threshold = cluster.threshold;
44
- val.dkg_algorithm = strToUint8Array(cluster.dkg_algorithm);
45
- val.fork_version = fromHexString(cluster.fork_version);
46
- val.operators = cluster.operators.map(operator => {
47
- return configOnly
48
- ? { address: fromHexString(operator.address) }
49
- : {
50
- address: fromHexString(operator.address),
51
- enr: strToUint8Array(operator.enr),
52
- config_signature: fromHexString(operator.config_signature),
53
- enr_signature: fromHexString(operator.enr_signature),
54
- };
55
- });
56
- val.creator = configOnly
57
- ? { address: fromHexString(cluster.creator.address) }
58
- : {
59
- address: fromHexString(cluster.creator.address),
60
- config_signature: fromHexString(cluster.creator.config_signature),
61
- };
62
- val.validators = cluster.validators.map(validator => {
63
- return {
64
- fee_recipient_address: fromHexString(validator.fee_recipient_address),
65
- withdrawal_address: fromHexString(validator.withdrawal_address),
66
- };
67
- });
68
- if (cluster.deposit_amounts) {
69
- val.deposit_amounts = cluster.deposit_amounts.map((amount) => {
70
- return parseInt(amount);
71
- });
72
- }
73
- if (cluster.consensus_protocol) {
74
- val.consensus_protocol = strToUint8Array(cluster.consensus_protocol);
75
- }
76
- if (cluster.target_gas_limit) {
77
- val.target_gas_limit = cluster.target_gas_limit;
78
- }
79
- if (cluster.compounding) {
80
- val.compounding = cluster.compounding;
81
- }
82
- if (!configOnly) {
83
- val.config_hash = fromHexString(cluster.config_hash);
84
- }
85
- return val;
86
- };
87
- // cluster lock
88
- const dvContainerTypeV1X10 = new ContainerType({
89
- distributed_public_key: new ByteVectorType(48),
90
- public_shares: new ListCompositeType(new ByteVectorType(48), 256),
91
- partial_deposit_data: new ListCompositeType(depositDataContainer, 256),
92
- builder_registration: builderRegistrationContainer,
93
- });
94
- /**
95
- * @returns SSZ Containerized type of cluster lock
96
- */
97
- const clusterLockContainerTypeV1X10 = () => {
98
- return new ContainerType({
99
- cluster_definition: clusterDefinitionContainerTypeV1X10(false),
100
- distributed_validators: new ListCompositeType(dvContainerTypeV1X10, 65536),
101
- });
102
- };
103
- /**
104
- * @param cluster The published cluster lock
105
- * @returns The lock hash in of the corresponding cluster
106
- */
107
- export const hashClusterLockV1X10 = (cluster) => {
108
- const lockType = clusterLockContainerTypeV1X10();
109
- const val = lockType.defaultValue();
110
- // Check if we can replace with definition_hash
111
- val.cluster_definition = hashClusterDefinitionV1X10(cluster.cluster_definition, false);
112
- val.distributed_validators = cluster.distributed_validators.map(dValidator => {
113
- var _a, _b, _c, _d, _e;
114
- return {
115
- distributed_public_key: fromHexString(dValidator.distributed_public_key),
116
- public_shares: dValidator.public_shares.map(publicShare => fromHexString(publicShare)),
117
- // should be fixed
118
- partial_deposit_data: dValidator.partial_deposit_data.map(depositData => {
119
- return {
120
- pubkey: fromHexString(depositData.pubkey),
121
- withdrawal_credentials: fromHexString(depositData.withdrawal_credentials),
122
- amount: parseInt(depositData.amount),
123
- signature: fromHexString(depositData.signature),
124
- };
125
- }),
126
- builder_registration: {
127
- message: {
128
- fee_recipient: fromHexString((_a = dValidator.builder_registration) === null || _a === void 0 ? void 0 : _a.message.fee_recipient),
129
- gas_limit: (_b = dValidator.builder_registration) === null || _b === void 0 ? void 0 : _b.message.gas_limit,
130
- timestamp: (_c = dValidator.builder_registration) === null || _c === void 0 ? void 0 : _c.message.timestamp,
131
- pubkey: fromHexString((_d = dValidator.builder_registration) === null || _d === void 0 ? void 0 : _d.message.pubkey),
132
- },
133
- signature: fromHexString((_e = dValidator.builder_registration) === null || _e === void 0 ? void 0 : _e.signature),
134
- },
135
- };
136
- });
137
- return '0x' + Buffer.from(lockType.hashTreeRoot(val).buffer).toString('hex');
138
- };
139
- // DV verification
140
- export const verifyDVV1X10 = verifyDVV1X8;