@obolnetwork/obol-sdk 2.2.2 → 2.2.4
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/package.json +1 -1
- package/dist/cjs/src/index.js +1 -0
- package/dist/cjs/src/verification/common.js +31 -5
- package/dist/cjs/src/verification/v1.10.0.js +146 -0
- package/dist/cjs/src/verification/v1.8.0.js +1 -1
- package/dist/cjs/test/fixtures.js +265 -1
- package/dist/cjs/test/methods.test.js +5 -0
- package/dist/esm/package.json +1 -1
- package/dist/esm/src/index.js +1 -0
- package/dist/esm/src/verification/common.js +31 -5
- package/dist/esm/src/verification/v1.10.0.js +140 -0
- package/dist/esm/src/verification/v1.8.0.js +1 -1
- package/dist/esm/test/fixtures.js +264 -0
- package/dist/esm/test/methods.test.js +6 -1
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/types.d.ts +6 -0
- package/dist/types/src/verification/common.d.ts +1 -1
- package/dist/types/src/verification/v1.10.0.d.ts +38 -0
- package/dist/types/test/fixtures.d.ts +108 -0
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/types.ts +9 -0
- package/src/verification/common.ts +43 -7
- package/src/verification/v1.10.0.ts +245 -0
- package/src/verification/v1.8.0.ts +1 -0
|
@@ -47,6 +47,12 @@ import {
|
|
|
47
47
|
verifyDVV1X8,
|
|
48
48
|
} from './v1.8.0.js';
|
|
49
49
|
import { validateAddressSignature } from './signature-validator.js';
|
|
50
|
+
import {
|
|
51
|
+
clusterDefinitionContainerTypeV1X10,
|
|
52
|
+
hashClusterDefinitionV1X10,
|
|
53
|
+
hashClusterLockV1X10,
|
|
54
|
+
verifyDVV1X10,
|
|
55
|
+
} from './v1.10.0.js';
|
|
50
56
|
|
|
51
57
|
// cluster-definition hash
|
|
52
58
|
|
|
@@ -88,6 +94,15 @@ export const clusterConfigOrDefinitionHash = (
|
|
|
88
94
|
);
|
|
89
95
|
}
|
|
90
96
|
|
|
97
|
+
if (semver.eq(cluster.version, 'v1.10.0')) {
|
|
98
|
+
definitionType = clusterDefinitionContainerTypeV1X10(configOnly);
|
|
99
|
+
val = hashClusterDefinitionV1X10(cluster, configOnly);
|
|
100
|
+
const x =
|
|
101
|
+
'0x' +
|
|
102
|
+
Buffer.from(definitionType.hashTreeRoot(val).buffer).toString('hex');
|
|
103
|
+
return x;
|
|
104
|
+
}
|
|
105
|
+
|
|
91
106
|
throw new Error('unsupported version');
|
|
92
107
|
};
|
|
93
108
|
|
|
@@ -123,6 +138,22 @@ export const clusterLockHash = (clusterLock: ClusterLock): string => {
|
|
|
123
138
|
return hashClusterLockV1X8(clusterLock);
|
|
124
139
|
}
|
|
125
140
|
|
|
141
|
+
if (semver.eq(clusterLock.cluster_definition.version, 'v1.10.0')) {
|
|
142
|
+
// if (
|
|
143
|
+
// clusterLock.cluster_definition.deposit_amounts === null &&
|
|
144
|
+
// clusterLock.distributed_validators.some(
|
|
145
|
+
// distributedValidator =>
|
|
146
|
+
// distributedValidator.partial_deposit_data?.length !== 1 ||
|
|
147
|
+
// distributedValidator.partial_deposit_data[0].amount !== '32000000000',
|
|
148
|
+
// )
|
|
149
|
+
// ) {
|
|
150
|
+
// throw new Error(
|
|
151
|
+
// 'mismatch between deposit_amounts and partial_deposit_data fields',
|
|
152
|
+
// );
|
|
153
|
+
// }
|
|
154
|
+
return hashClusterLockV1X10(clusterLock);
|
|
155
|
+
}
|
|
156
|
+
|
|
126
157
|
// other versions
|
|
127
158
|
throw new Error('unsupported version');
|
|
128
159
|
};
|
|
@@ -323,18 +354,19 @@ export const verifyDepositData = (
|
|
|
323
354
|
depositData: Partial<DepositData>,
|
|
324
355
|
withdrawalAddress: string,
|
|
325
356
|
forkVersion: string,
|
|
357
|
+
compounding?: boolean,
|
|
326
358
|
): { isValidDepositData: boolean; depositDataMsg: Uint8Array } => {
|
|
327
359
|
const depositDomain = computeDomain(
|
|
328
360
|
fromHexString(DOMAIN_DEPOSIT),
|
|
329
361
|
forkVersion,
|
|
330
362
|
);
|
|
331
|
-
const
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
) {
|
|
363
|
+
const withdrawalPrefix = compounding ? '0x02' : '0x01';
|
|
364
|
+
const expectedWithdrawalCredentials =
|
|
365
|
+
withdrawalPrefix +
|
|
366
|
+
'0'.repeat(22) +
|
|
367
|
+
withdrawalAddress.toLowerCase().slice(2);
|
|
368
|
+
|
|
369
|
+
if (expectedWithdrawalCredentials !== depositData.withdrawal_credentials) {
|
|
338
370
|
return { isValidDepositData: false, depositDataMsg: new Uint8Array(0) };
|
|
339
371
|
}
|
|
340
372
|
|
|
@@ -444,6 +476,10 @@ const verifyLockData = async (clusterLock: ClusterLock): Promise<boolean> => {
|
|
|
444
476
|
if (semver.eq(clusterLock.cluster_definition.version, 'v1.8.0')) {
|
|
445
477
|
return verifyDVV1X8(clusterLock);
|
|
446
478
|
}
|
|
479
|
+
|
|
480
|
+
if (semver.eq(clusterLock.cluster_definition.version, 'v1.10.0')) {
|
|
481
|
+
return verifyDVV1X10(clusterLock);
|
|
482
|
+
}
|
|
447
483
|
return false;
|
|
448
484
|
};
|
|
449
485
|
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type UintNumberByteLen,
|
|
3
|
+
UintNumberType,
|
|
4
|
+
} from '@chainsafe/ssz/lib/type/uint';
|
|
5
|
+
import { strToUint8Array } from '../utils';
|
|
6
|
+
import {
|
|
7
|
+
builderRegistrationContainer,
|
|
8
|
+
type creatorAddressWrapperType,
|
|
9
|
+
type creatorContainerType,
|
|
10
|
+
depositDataContainer,
|
|
11
|
+
newCreatorContainerType,
|
|
12
|
+
newOperatorContainerType,
|
|
13
|
+
type operatorAddressWrapperType,
|
|
14
|
+
type operatorContainerType,
|
|
15
|
+
validatorsContainerType,
|
|
16
|
+
} from './sszTypes';
|
|
17
|
+
import {
|
|
18
|
+
ByteListType,
|
|
19
|
+
ByteVectorType,
|
|
20
|
+
ContainerType,
|
|
21
|
+
ListBasicType,
|
|
22
|
+
ListCompositeType,
|
|
23
|
+
fromHexString,
|
|
24
|
+
BooleanType,
|
|
25
|
+
} from '@chainsafe/ssz';
|
|
26
|
+
import { type ValueOfFields } from '@chainsafe/ssz/lib/view/container';
|
|
27
|
+
import {
|
|
28
|
+
type ClusterDefinition,
|
|
29
|
+
type ClusterLock,
|
|
30
|
+
type DepositData,
|
|
31
|
+
} from '../types';
|
|
32
|
+
import { verifyDVV1X8 } from './v1.8.0';
|
|
33
|
+
|
|
34
|
+
// cluster definition
|
|
35
|
+
type DefinitionFieldsV1X10 = {
|
|
36
|
+
uuid: ByteListType;
|
|
37
|
+
name: ByteListType;
|
|
38
|
+
version: ByteListType;
|
|
39
|
+
timestamp: ByteListType;
|
|
40
|
+
num_validators: UintNumberType;
|
|
41
|
+
threshold: UintNumberType;
|
|
42
|
+
dkg_algorithm: ByteListType;
|
|
43
|
+
fork_version: ByteVectorType;
|
|
44
|
+
operators: ListCompositeType<
|
|
45
|
+
typeof operatorContainerType | typeof operatorAddressWrapperType
|
|
46
|
+
>;
|
|
47
|
+
creator: typeof creatorContainerType | typeof creatorAddressWrapperType;
|
|
48
|
+
validators: ListCompositeType<typeof validatorsContainerType>;
|
|
49
|
+
deposit_amounts: ListBasicType<UintNumberType>;
|
|
50
|
+
consensus_protocol: ByteListType;
|
|
51
|
+
target_gas_limit: UintNumberType;
|
|
52
|
+
compounding: BooleanType;
|
|
53
|
+
config_hash?: ByteVectorType;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
type DefinitionContainerTypeV1X10 = ContainerType<DefinitionFieldsV1X10>;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Returns the containerized cluster definition
|
|
60
|
+
* @param cluster ClusterDefinition to calculate the type from
|
|
61
|
+
* @returns SSZ Containerized type of cluster input
|
|
62
|
+
*/
|
|
63
|
+
export const clusterDefinitionContainerTypeV1X10 = (
|
|
64
|
+
configOnly: boolean,
|
|
65
|
+
): DefinitionContainerTypeV1X10 => {
|
|
66
|
+
let returnedContainerType: any = {
|
|
67
|
+
uuid: new ByteListType(64),
|
|
68
|
+
name: new ByteListType(256),
|
|
69
|
+
version: new ByteListType(16),
|
|
70
|
+
timestamp: new ByteListType(32),
|
|
71
|
+
num_validators: new UintNumberType(8 as UintNumberByteLen),
|
|
72
|
+
threshold: new UintNumberType(8 as UintNumberByteLen),
|
|
73
|
+
dkg_algorithm: new ByteListType(32),
|
|
74
|
+
fork_version: new ByteVectorType(4),
|
|
75
|
+
operators: new ListCompositeType(newOperatorContainerType(configOnly), 256),
|
|
76
|
+
creator: newCreatorContainerType(configOnly),
|
|
77
|
+
validators: new ListCompositeType(validatorsContainerType, 65536),
|
|
78
|
+
deposit_amounts: new ListBasicType(
|
|
79
|
+
new UintNumberType(8 as UintNumberByteLen),
|
|
80
|
+
256,
|
|
81
|
+
),
|
|
82
|
+
consensus_protocol: new ByteListType(256),
|
|
83
|
+
target_gas_limit: new UintNumberType(8 as UintNumberByteLen),
|
|
84
|
+
compounding: new BooleanType(),
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
if (!configOnly) {
|
|
88
|
+
returnedContainerType = {
|
|
89
|
+
...returnedContainerType,
|
|
90
|
+
config_hash: new ByteVectorType(32),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return new ContainerType(returnedContainerType);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export const hashClusterDefinitionV1X10 = (
|
|
98
|
+
cluster: ClusterDefinition,
|
|
99
|
+
configOnly: boolean,
|
|
100
|
+
): ValueOfFields<DefinitionFieldsV1X10> => {
|
|
101
|
+
const definitionType = clusterDefinitionContainerTypeV1X10(configOnly);
|
|
102
|
+
|
|
103
|
+
const val = definitionType.defaultValue();
|
|
104
|
+
|
|
105
|
+
// order should be same as charon https://github.com/ObolNetwork/charon/blob/main/cluster/ssz.go#L276
|
|
106
|
+
val.uuid = strToUint8Array(cluster.uuid);
|
|
107
|
+
val.name = strToUint8Array(cluster.name);
|
|
108
|
+
val.version = strToUint8Array(cluster.version);
|
|
109
|
+
val.timestamp = strToUint8Array(cluster.timestamp);
|
|
110
|
+
val.num_validators = cluster.num_validators;
|
|
111
|
+
val.threshold = cluster.threshold;
|
|
112
|
+
val.dkg_algorithm = strToUint8Array(cluster.dkg_algorithm);
|
|
113
|
+
val.fork_version = fromHexString(cluster.fork_version);
|
|
114
|
+
val.operators = cluster.operators.map(operator => {
|
|
115
|
+
return configOnly
|
|
116
|
+
? { address: fromHexString(operator.address) }
|
|
117
|
+
: {
|
|
118
|
+
address: fromHexString(operator.address),
|
|
119
|
+
enr: strToUint8Array(operator.enr as string),
|
|
120
|
+
config_signature: fromHexString(operator.config_signature as string),
|
|
121
|
+
enr_signature: fromHexString(operator.enr_signature as string),
|
|
122
|
+
};
|
|
123
|
+
});
|
|
124
|
+
val.creator = configOnly
|
|
125
|
+
? { address: fromHexString(cluster.creator.address) }
|
|
126
|
+
: {
|
|
127
|
+
address: fromHexString(cluster.creator.address),
|
|
128
|
+
config_signature: fromHexString(
|
|
129
|
+
cluster.creator.config_signature as string,
|
|
130
|
+
),
|
|
131
|
+
};
|
|
132
|
+
val.validators = cluster.validators.map(validator => {
|
|
133
|
+
return {
|
|
134
|
+
fee_recipient_address: fromHexString(validator.fee_recipient_address),
|
|
135
|
+
withdrawal_address: fromHexString(validator.withdrawal_address),
|
|
136
|
+
};
|
|
137
|
+
});
|
|
138
|
+
if (cluster.deposit_amounts) {
|
|
139
|
+
val.deposit_amounts = cluster.deposit_amounts.map((amount: string) => {
|
|
140
|
+
return parseInt(amount);
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
if (cluster.consensus_protocol) {
|
|
144
|
+
val.consensus_protocol = strToUint8Array(cluster.consensus_protocol);
|
|
145
|
+
}
|
|
146
|
+
if (cluster.target_gas_limit) {
|
|
147
|
+
val.target_gas_limit = cluster.target_gas_limit;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (cluster.compounding) {
|
|
151
|
+
val.compounding = cluster.compounding;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (!configOnly) {
|
|
155
|
+
val.config_hash = fromHexString(cluster.config_hash);
|
|
156
|
+
}
|
|
157
|
+
return val;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
// cluster lock
|
|
161
|
+
|
|
162
|
+
const dvContainerTypeV1X10 = new ContainerType({
|
|
163
|
+
distributed_public_key: new ByteVectorType(48),
|
|
164
|
+
public_shares: new ListCompositeType(new ByteVectorType(48), 256),
|
|
165
|
+
partial_deposit_data: new ListCompositeType(depositDataContainer, 256),
|
|
166
|
+
builder_registration: builderRegistrationContainer,
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
type LockContainerTypeV1X10 = ContainerType<{
|
|
170
|
+
cluster_definition: DefinitionContainerTypeV1X10;
|
|
171
|
+
distributed_validators: ListCompositeType<typeof dvContainerTypeV1X10>;
|
|
172
|
+
}>;
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* @returns SSZ Containerized type of cluster lock
|
|
176
|
+
*/
|
|
177
|
+
const clusterLockContainerTypeV1X10 = (): LockContainerTypeV1X10 => {
|
|
178
|
+
return new ContainerType({
|
|
179
|
+
cluster_definition: clusterDefinitionContainerTypeV1X10(false),
|
|
180
|
+
distributed_validators: new ListCompositeType(dvContainerTypeV1X10, 65536),
|
|
181
|
+
});
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* @param cluster The published cluster lock
|
|
186
|
+
* @returns The lock hash in of the corresponding cluster
|
|
187
|
+
*/
|
|
188
|
+
export const hashClusterLockV1X10 = (cluster: ClusterLock): string => {
|
|
189
|
+
const lockType = clusterLockContainerTypeV1X10();
|
|
190
|
+
|
|
191
|
+
const val = lockType.defaultValue();
|
|
192
|
+
|
|
193
|
+
// Check if we can replace with definition_hash
|
|
194
|
+
val.cluster_definition = hashClusterDefinitionV1X10(
|
|
195
|
+
cluster.cluster_definition,
|
|
196
|
+
false,
|
|
197
|
+
);
|
|
198
|
+
val.distributed_validators = cluster.distributed_validators.map(
|
|
199
|
+
dValidator => {
|
|
200
|
+
return {
|
|
201
|
+
distributed_public_key: fromHexString(
|
|
202
|
+
dValidator.distributed_public_key,
|
|
203
|
+
),
|
|
204
|
+
public_shares: dValidator.public_shares.map(publicShare =>
|
|
205
|
+
fromHexString(publicShare),
|
|
206
|
+
),
|
|
207
|
+
// should be fixed
|
|
208
|
+
partial_deposit_data: (
|
|
209
|
+
dValidator.partial_deposit_data as DepositData[]
|
|
210
|
+
).map(depositData => {
|
|
211
|
+
return {
|
|
212
|
+
pubkey: fromHexString(depositData.pubkey),
|
|
213
|
+
withdrawal_credentials: fromHexString(
|
|
214
|
+
depositData.withdrawal_credentials,
|
|
215
|
+
),
|
|
216
|
+
amount: parseInt(depositData.amount),
|
|
217
|
+
signature: fromHexString(depositData.signature),
|
|
218
|
+
};
|
|
219
|
+
}),
|
|
220
|
+
builder_registration: {
|
|
221
|
+
message: {
|
|
222
|
+
fee_recipient: fromHexString(
|
|
223
|
+
dValidator.builder_registration?.message.fee_recipient as string,
|
|
224
|
+
),
|
|
225
|
+
gas_limit: dValidator.builder_registration?.message
|
|
226
|
+
.gas_limit as number,
|
|
227
|
+
timestamp: dValidator.builder_registration?.message
|
|
228
|
+
.timestamp as number,
|
|
229
|
+
pubkey: fromHexString(
|
|
230
|
+
dValidator.builder_registration?.message.pubkey as string,
|
|
231
|
+
),
|
|
232
|
+
},
|
|
233
|
+
signature: fromHexString(
|
|
234
|
+
dValidator.builder_registration?.signature as string,
|
|
235
|
+
),
|
|
236
|
+
},
|
|
237
|
+
};
|
|
238
|
+
},
|
|
239
|
+
);
|
|
240
|
+
|
|
241
|
+
return '0x' + Buffer.from(lockType.hashTreeRoot(val).buffer).toString('hex');
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
// DV verification
|
|
245
|
+
export const verifyDVV1X10 = verifyDVV1X8;
|
|
@@ -259,6 +259,7 @@ export const verifyDVV1X8 = (clusterLock: ClusterLock): boolean => {
|
|
|
259
259
|
depositData as Partial<DepositData>,
|
|
260
260
|
clusterLock.cluster_definition.validators[i].withdrawal_address,
|
|
261
261
|
clusterLock.cluster_definition.fork_version,
|
|
262
|
+
clusterLock.cluster_definition.compounding,
|
|
262
263
|
);
|
|
263
264
|
|
|
264
265
|
if (!isValidDepositData) {
|