@obolnetwork/obol-sdk 2.11.4 → 2.11.5-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/src/index.js +17457 -382
- package/dist/cjs/src/index.js.map +1 -0
- package/dist/esm/src/index.js +17424 -361
- package/dist/esm/src/index.js.map +1 -0
- package/dist/types/src/constants.d.ts +1 -2
- package/dist/types/src/eoa/eoaHelpers.d.ts +1 -1
- package/dist/types/src/exits/verificationHelpers.d.ts +0 -2
- package/dist/types/src/incentives/incentiveHelpers.d.ts +1 -1
- package/dist/types/src/splits/splitHelpers.d.ts +3 -3
- package/dist/types/src/utils.d.ts +2 -2
- package/dist/types/src/verification/common.d.ts +0 -2
- package/dist/types/src/verification/signature-validator.d.ts +4 -4
- package/dist/types/src/verification/v1.10.0.d.ts +1 -1
- package/dist/types/src/verification/v1.6.0.d.ts +1 -1
- package/dist/types/src/verification/v1.7.0.d.ts +1 -1
- package/dist/types/src/verification/v1.8.0.d.ts +1 -1
- package/dist/types/test/client/methods.spec.d.ts +17 -0
- package/dist/types/tsconfig.types.tsbuildinfo +1 -0
- package/dist/types/tsup.config.d.ts +2 -0
- package/package.json +79 -54
- package/dist/cjs/package.json +0 -139
- package/dist/cjs/src/abi/BatchDeposit.js +0 -120
- package/dist/cjs/src/abi/MerkleDistributorWithDeadline.js +0 -73
- package/dist/cjs/src/abi/Multicall3.js +0 -253
- package/dist/cjs/src/abi/OVM.js +0 -627
- package/dist/cjs/src/abi/OWR.js +0 -304
- package/dist/cjs/src/abi/SplitMain.js +0 -929
- package/dist/cjs/src/abi/splitV2FactoryAbi.js +0 -420
- package/dist/cjs/src/ajv.js +0 -136
- package/dist/cjs/src/base.js +0 -42
- package/dist/cjs/src/bytecodes.js +0 -19
- package/dist/cjs/src/constants.js +0 -272
- package/dist/cjs/src/eoa/eoa.js +0 -132
- package/dist/cjs/src/eoa/eoaHelpers.js +0 -82
- package/dist/cjs/src/errors.js +0 -11
- package/dist/cjs/src/exits/ethUtils.js +0 -57
- package/dist/cjs/src/exits/exit.js +0 -502
- package/dist/cjs/src/exits/verificationHelpers.js +0 -86
- package/dist/cjs/src/incentives/incentiveHelpers.js +0 -39
- package/dist/cjs/src/incentives/incentives.js +0 -119
- package/dist/cjs/src/schema.js +0 -352
- package/dist/cjs/src/services.js +0 -33
- package/dist/cjs/src/splits/splitHelpers.js +0 -571
- package/dist/cjs/src/splits/splits.js +0 -366
- package/dist/cjs/src/types.js +0 -29
- package/dist/cjs/src/utils.js +0 -77
- package/dist/cjs/src/verification/common.js +0 -355
- package/dist/cjs/src/verification/signature-validator.js +0 -73
- package/dist/cjs/src/verification/sszTypes.js +0 -69
- package/dist/cjs/src/verification/termsAndConditions.js +0 -40
- package/dist/cjs/src/verification/v1.10.0.js +0 -146
- package/dist/cjs/src/verification/v1.6.0.js +0 -149
- package/dist/cjs/src/verification/v1.7.0.js +0 -173
- package/dist/cjs/src/verification/v1.8.0.js +0 -196
- package/dist/cjs/test/client/ajv.spec.js +0 -320
- package/dist/cjs/test/client/methods.spec.js +0 -418
- package/dist/cjs/test/eoa/eoa.spec.js +0 -176
- package/dist/cjs/test/exit/ethUtils.spec.js +0 -83
- package/dist/cjs/test/exit/exit.spec.js +0 -399
- package/dist/cjs/test/exit/verificationHelpers.spec.js +0 -68
- package/dist/cjs/test/fixtures.js +0 -896
- package/dist/cjs/test/incentives/incentives.spec.js +0 -202
- package/dist/cjs/test/splits/splits.spec.js +0 -402
- package/dist/esm/package.json +0 -139
- package/dist/esm/src/abi/BatchDeposit.js +0 -117
- package/dist/esm/src/abi/MerkleDistributorWithDeadline.js +0 -70
- package/dist/esm/src/abi/Multicall3.js +0 -250
- package/dist/esm/src/abi/OVM.js +0 -624
- package/dist/esm/src/abi/OWR.js +0 -301
- package/dist/esm/src/abi/SplitMain.js +0 -926
- package/dist/esm/src/abi/splitV2FactoryAbi.js +0 -417
- package/dist/esm/src/ajv.js +0 -129
- package/dist/esm/src/base.js +0 -38
- package/dist/esm/src/bytecodes.js +0 -16
- package/dist/esm/src/constants.js +0 -238
- package/dist/esm/src/eoa/eoa.js +0 -128
- package/dist/esm/src/eoa/eoaHelpers.js +0 -77
- package/dist/esm/src/errors.js +0 -7
- package/dist/esm/src/exits/ethUtils.js +0 -52
- package/dist/esm/src/exits/exit.js +0 -475
- package/dist/esm/src/exits/verificationHelpers.js +0 -81
- package/dist/esm/src/incentives/incentiveHelpers.js +0 -34
- package/dist/esm/src/incentives/incentives.js +0 -115
- package/dist/esm/src/schema.js +0 -349
- package/dist/esm/src/services.js +0 -29
- package/dist/esm/src/splits/splitHelpers.js +0 -554
- package/dist/esm/src/splits/splits.js +0 -362
- package/dist/esm/src/types.js +0 -26
- package/dist/esm/src/utils.js +0 -68
- package/dist/esm/src/verification/common.js +0 -319
- package/dist/esm/src/verification/signature-validator.js +0 -64
- package/dist/esm/src/verification/sszTypes.js +0 -64
- package/dist/esm/src/verification/termsAndConditions.js +0 -33
- package/dist/esm/src/verification/v1.10.0.js +0 -140
- package/dist/esm/src/verification/v1.6.0.js +0 -142
- package/dist/esm/src/verification/v1.7.0.js +0 -166
- package/dist/esm/src/verification/v1.8.0.js +0 -189
- package/dist/esm/test/client/ajv.spec.js +0 -318
- package/dist/esm/test/client/methods.spec.js +0 -393
- package/dist/esm/test/eoa/eoa.spec.js +0 -174
- package/dist/esm/test/exit/ethUtils.spec.js +0 -81
- package/dist/esm/test/exit/exit.spec.js +0 -374
- package/dist/esm/test/exit/verificationHelpers.spec.js +0 -66
- package/dist/esm/test/fixtures.js +0 -893
- package/dist/esm/test/incentives/incentives.spec.js +0 -177
- package/dist/esm/test/splits/splits.spec.js +0 -400
- package/src/abi/BatchDeposit.ts +0 -117
- package/src/abi/MerkleDistributorWithDeadline.ts +0 -70
- package/src/abi/Multicall3.ts +0 -250
- package/src/abi/OVM.ts +0 -624
- package/src/abi/OWR.ts +0 -302
- package/src/abi/SplitMain.ts +0 -927
- package/src/abi/splitV2FactoryAbi.ts +0 -417
- package/src/ajv.ts +0 -191
- package/src/base.ts +0 -54
- package/src/bytecodes.ts +0 -32
- package/src/constants.ts +0 -309
- package/src/eoa/eoa.ts +0 -153
- package/src/eoa/eoaHelpers.ts +0 -112
- package/src/errors.ts +0 -8
- package/src/exits/ethUtils.ts +0 -49
- package/src/exits/exit.ts +0 -661
- package/src/exits/verificationHelpers.ts +0 -110
- package/src/incentives/incentiveHelpers.ts +0 -55
- package/src/incentives/incentives.ts +0 -153
- package/src/index.ts +0 -614
- package/src/schema.ts +0 -376
- package/src/services.ts +0 -24
- package/src/splits/splitHelpers.ts +0 -1032
- package/src/splits/splits.ts +0 -504
- package/src/types.ts +0 -687
- package/src/utils.ts +0 -88
- package/src/verification/common.ts +0 -532
- package/src/verification/signature-validator.ts +0 -103
- package/src/verification/sszTypes.ts +0 -88
- package/src/verification/termsAndConditions.ts +0 -32
- package/src/verification/v1.10.0.ts +0 -245
- package/src/verification/v1.6.0.ts +0 -256
- package/src/verification/v1.7.0.ts +0 -309
- 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
|
-
};
|