@obolnetwork/obol-sdk 2.2.1 → 2.2.3
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/README.md +5 -0
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/src/index.js +1 -0
- package/dist/cjs/src/utils.js +1 -1
- package/dist/cjs/src/verification/common.js +32 -1
- package/dist/cjs/src/verification/v1.10.0.js +142 -0
- package/dist/cjs/test/fixtures.js +420 -1
- package/dist/cjs/test/methods.test.js +1 -0
- package/dist/esm/package.json +1 -1
- package/dist/esm/src/index.js +1 -0
- package/dist/esm/src/utils.js +1 -1
- package/dist/esm/src/verification/common.js +32 -1
- package/dist/esm/src/verification/v1.10.0.js +136 -0
- package/dist/esm/test/fixtures.js +419 -0
- package/dist/esm/test/methods.test.js +2 -1
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/types.d.ts +4 -0
- package/dist/types/src/verification/v1.10.0.d.ts +37 -0
- package/dist/types/test/fixtures.d.ts +53 -0
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/types.ts +6 -0
- package/src/utils.ts +1 -1
- package/src/verification/common.ts +41 -1
- package/src/verification/v1.10.0.ts +238 -0
|
@@ -263,3 +263,56 @@ export declare const clusterLockWithSafe: {
|
|
|
263
263
|
lock_hash: string;
|
|
264
264
|
node_signatures: string[];
|
|
265
265
|
};
|
|
266
|
+
export declare const clusterLockV1X10: {
|
|
267
|
+
cluster_definition: {
|
|
268
|
+
name: string;
|
|
269
|
+
creator: {
|
|
270
|
+
address: string;
|
|
271
|
+
config_signature: string;
|
|
272
|
+
};
|
|
273
|
+
operators: {
|
|
274
|
+
address: string;
|
|
275
|
+
enr: string;
|
|
276
|
+
config_signature: string;
|
|
277
|
+
enr_signature: string;
|
|
278
|
+
}[];
|
|
279
|
+
uuid: string;
|
|
280
|
+
version: string;
|
|
281
|
+
timestamp: string;
|
|
282
|
+
num_validators: number;
|
|
283
|
+
threshold: number;
|
|
284
|
+
validators: {
|
|
285
|
+
fee_recipient_address: string;
|
|
286
|
+
withdrawal_address: string;
|
|
287
|
+
}[];
|
|
288
|
+
dkg_algorithm: string;
|
|
289
|
+
fork_version: string;
|
|
290
|
+
deposit_amounts: null;
|
|
291
|
+
consensus_protocol: string;
|
|
292
|
+
target_gas_limit: number;
|
|
293
|
+
config_hash: string;
|
|
294
|
+
definition_hash: string;
|
|
295
|
+
};
|
|
296
|
+
distributed_validators: {
|
|
297
|
+
distributed_public_key: string;
|
|
298
|
+
public_shares: string[];
|
|
299
|
+
builder_registration: {
|
|
300
|
+
message: {
|
|
301
|
+
fee_recipient: string;
|
|
302
|
+
gas_limit: number;
|
|
303
|
+
timestamp: number;
|
|
304
|
+
pubkey: string;
|
|
305
|
+
};
|
|
306
|
+
signature: string;
|
|
307
|
+
};
|
|
308
|
+
partial_deposit_data: {
|
|
309
|
+
pubkey: string;
|
|
310
|
+
withdrawal_credentials: string;
|
|
311
|
+
amount: string;
|
|
312
|
+
signature: string;
|
|
313
|
+
}[];
|
|
314
|
+
}[];
|
|
315
|
+
signature_aggregate: string;
|
|
316
|
+
lock_hash: string;
|
|
317
|
+
node_signatures: string[];
|
|
318
|
+
};
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -50,6 +50,7 @@ import { isContractAvailable } from './utils.js';
|
|
|
50
50
|
export * from './types.js';
|
|
51
51
|
export * from './services.js';
|
|
52
52
|
export * from './verification/signature-validator.js';
|
|
53
|
+
export * from './verification/common.js';
|
|
53
54
|
|
|
54
55
|
/**
|
|
55
56
|
* Obol sdk Client can be used for creating, managing and activating distributed validators.
|
package/src/types.ts
CHANGED
|
@@ -138,6 +138,12 @@ export interface ClusterDefinition extends ClusterPayload {
|
|
|
138
138
|
|
|
139
139
|
/** The hash of the cluster definition. */
|
|
140
140
|
definition_hash?: string;
|
|
141
|
+
|
|
142
|
+
/** The consensus protocol e.g qbft. */
|
|
143
|
+
consensus_protocol?: string;
|
|
144
|
+
|
|
145
|
+
/** The target gas limit where default is 30M. */
|
|
146
|
+
target_gas_limit?: number;
|
|
141
147
|
}
|
|
142
148
|
|
|
143
149
|
/**
|
package/src/utils.ts
CHANGED
|
@@ -78,7 +78,7 @@ export const isContractAvailable = async (
|
|
|
78
78
|
|
|
79
79
|
export const getProvider = (chainId: number): ethers.Provider => {
|
|
80
80
|
const rpcUrl = PROVIDER_MAP[chainId];
|
|
81
|
-
if (!rpcUrl) {
|
|
81
|
+
if (!rpcUrl || rpcUrl === 'undefined') {
|
|
82
82
|
throw new Error(`No provider configured for ${FORK_NAMES[chainId]}`);
|
|
83
83
|
}
|
|
84
84
|
return new ethers.JsonRpcProvider(rpcUrl);
|
|
@@ -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
|
};
|
|
@@ -329,11 +360,16 @@ export const verifyDepositData = (
|
|
|
329
360
|
forkVersion,
|
|
330
361
|
);
|
|
331
362
|
const eth1AddressWithdrawalPrefix = '0x01';
|
|
363
|
+
const compoundingWithdrawalPrefix = '0x02';
|
|
332
364
|
if (
|
|
333
365
|
eth1AddressWithdrawalPrefix +
|
|
334
366
|
'0'.repeat(22) +
|
|
335
367
|
withdrawalAddress.toLowerCase().slice(2) !==
|
|
336
|
-
|
|
368
|
+
depositData.withdrawal_credentials &&
|
|
369
|
+
compoundingWithdrawalPrefix +
|
|
370
|
+
'0'.repeat(22) +
|
|
371
|
+
withdrawalAddress.toLowerCase().slice(2) !==
|
|
372
|
+
depositData.withdrawal_credentials
|
|
337
373
|
) {
|
|
338
374
|
return { isValidDepositData: false, depositDataMsg: new Uint8Array(0) };
|
|
339
375
|
}
|
|
@@ -444,6 +480,10 @@ const verifyLockData = async (clusterLock: ClusterLock): Promise<boolean> => {
|
|
|
444
480
|
if (semver.eq(clusterLock.cluster_definition.version, 'v1.8.0')) {
|
|
445
481
|
return verifyDVV1X8(clusterLock);
|
|
446
482
|
}
|
|
483
|
+
|
|
484
|
+
if (semver.eq(clusterLock.cluster_definition.version, 'v1.10.0')) {
|
|
485
|
+
return verifyDVV1X10(clusterLock);
|
|
486
|
+
}
|
|
447
487
|
return false;
|
|
448
488
|
};
|
|
449
489
|
|
|
@@ -0,0 +1,238 @@
|
|
|
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
|
+
} from '@chainsafe/ssz';
|
|
25
|
+
import { type ValueOfFields } from '@chainsafe/ssz/lib/view/container';
|
|
26
|
+
import {
|
|
27
|
+
type ClusterDefinition,
|
|
28
|
+
type ClusterLock,
|
|
29
|
+
type DepositData,
|
|
30
|
+
} from '../types';
|
|
31
|
+
import { verifyDVV1X8 } from './v1.8.0';
|
|
32
|
+
|
|
33
|
+
// cluster definition
|
|
34
|
+
type DefinitionFieldsV1X10 = {
|
|
35
|
+
uuid: ByteListType;
|
|
36
|
+
name: ByteListType;
|
|
37
|
+
version: ByteListType;
|
|
38
|
+
timestamp: ByteListType;
|
|
39
|
+
num_validators: UintNumberType;
|
|
40
|
+
threshold: UintNumberType;
|
|
41
|
+
dkg_algorithm: ByteListType;
|
|
42
|
+
fork_version: ByteVectorType;
|
|
43
|
+
operators: ListCompositeType<
|
|
44
|
+
typeof operatorContainerType | typeof operatorAddressWrapperType
|
|
45
|
+
>;
|
|
46
|
+
creator: typeof creatorContainerType | typeof creatorAddressWrapperType;
|
|
47
|
+
validators: ListCompositeType<typeof validatorsContainerType>;
|
|
48
|
+
deposit_amounts: ListBasicType<UintNumberType>;
|
|
49
|
+
consensus_protocol: ByteListType;
|
|
50
|
+
target_gas_limit: UintNumberType;
|
|
51
|
+
config_hash?: ByteVectorType;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
type DefinitionContainerTypeV1X10 = ContainerType<DefinitionFieldsV1X10>;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Returns the containerized cluster definition
|
|
58
|
+
* @param cluster ClusterDefinition to calculate the type from
|
|
59
|
+
* @returns SSZ Containerized type of cluster input
|
|
60
|
+
*/
|
|
61
|
+
export const clusterDefinitionContainerTypeV1X10 = (
|
|
62
|
+
configOnly: boolean,
|
|
63
|
+
): DefinitionContainerTypeV1X10 => {
|
|
64
|
+
let returnedContainerType: any = {
|
|
65
|
+
uuid: new ByteListType(64),
|
|
66
|
+
name: new ByteListType(256),
|
|
67
|
+
version: new ByteListType(16),
|
|
68
|
+
timestamp: new ByteListType(32),
|
|
69
|
+
num_validators: new UintNumberType(8 as UintNumberByteLen),
|
|
70
|
+
threshold: new UintNumberType(8 as UintNumberByteLen),
|
|
71
|
+
dkg_algorithm: new ByteListType(32),
|
|
72
|
+
fork_version: new ByteVectorType(4),
|
|
73
|
+
operators: new ListCompositeType(newOperatorContainerType(configOnly), 256),
|
|
74
|
+
creator: newCreatorContainerType(configOnly),
|
|
75
|
+
validators: new ListCompositeType(validatorsContainerType, 65536),
|
|
76
|
+
deposit_amounts: new ListBasicType(
|
|
77
|
+
new UintNumberType(8 as UintNumberByteLen),
|
|
78
|
+
256,
|
|
79
|
+
),
|
|
80
|
+
consensus_protocol: new ByteListType(256),
|
|
81
|
+
target_gas_limit: new UintNumberType(8 as UintNumberByteLen),
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
if (!configOnly) {
|
|
85
|
+
returnedContainerType = {
|
|
86
|
+
...returnedContainerType,
|
|
87
|
+
config_hash: new ByteVectorType(32),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return new ContainerType(returnedContainerType);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export const hashClusterDefinitionV1X10 = (
|
|
95
|
+
cluster: ClusterDefinition,
|
|
96
|
+
configOnly: boolean,
|
|
97
|
+
): ValueOfFields<DefinitionFieldsV1X10> => {
|
|
98
|
+
const definitionType = clusterDefinitionContainerTypeV1X10(configOnly);
|
|
99
|
+
|
|
100
|
+
const val = definitionType.defaultValue();
|
|
101
|
+
|
|
102
|
+
// order should be same as charon https://github.com/ObolNetwork/charon/blob/main/cluster/ssz.go#L276
|
|
103
|
+
val.uuid = strToUint8Array(cluster.uuid);
|
|
104
|
+
val.name = strToUint8Array(cluster.name);
|
|
105
|
+
val.version = strToUint8Array(cluster.version);
|
|
106
|
+
val.timestamp = strToUint8Array(cluster.timestamp);
|
|
107
|
+
val.num_validators = cluster.num_validators;
|
|
108
|
+
val.threshold = cluster.threshold;
|
|
109
|
+
val.dkg_algorithm = strToUint8Array(cluster.dkg_algorithm);
|
|
110
|
+
val.fork_version = fromHexString(cluster.fork_version);
|
|
111
|
+
val.operators = cluster.operators.map(operator => {
|
|
112
|
+
return configOnly
|
|
113
|
+
? { address: fromHexString(operator.address) }
|
|
114
|
+
: {
|
|
115
|
+
address: fromHexString(operator.address),
|
|
116
|
+
enr: strToUint8Array(operator.enr as string),
|
|
117
|
+
config_signature: fromHexString(operator.config_signature as string),
|
|
118
|
+
enr_signature: fromHexString(operator.enr_signature as string),
|
|
119
|
+
};
|
|
120
|
+
});
|
|
121
|
+
val.creator = configOnly
|
|
122
|
+
? { address: fromHexString(cluster.creator.address) }
|
|
123
|
+
: {
|
|
124
|
+
address: fromHexString(cluster.creator.address),
|
|
125
|
+
config_signature: fromHexString(
|
|
126
|
+
cluster.creator.config_signature as string,
|
|
127
|
+
),
|
|
128
|
+
};
|
|
129
|
+
val.validators = cluster.validators.map(validator => {
|
|
130
|
+
return {
|
|
131
|
+
fee_recipient_address: fromHexString(validator.fee_recipient_address),
|
|
132
|
+
withdrawal_address: fromHexString(validator.withdrawal_address),
|
|
133
|
+
};
|
|
134
|
+
});
|
|
135
|
+
if (cluster.deposit_amounts) {
|
|
136
|
+
val.deposit_amounts = cluster.deposit_amounts.map((amount: string) => {
|
|
137
|
+
return parseInt(amount);
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
if (cluster.consensus_protocol) {
|
|
141
|
+
val.consensus_protocol = strToUint8Array(cluster.consensus_protocol);
|
|
142
|
+
}
|
|
143
|
+
if (cluster.target_gas_limit) {
|
|
144
|
+
val.target_gas_limit = cluster.target_gas_limit;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (!configOnly) {
|
|
148
|
+
val.config_hash = fromHexString(cluster.config_hash);
|
|
149
|
+
}
|
|
150
|
+
return val;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
// cluster lock
|
|
154
|
+
|
|
155
|
+
const dvContainerTypeV1X10 = new ContainerType({
|
|
156
|
+
distributed_public_key: new ByteVectorType(48),
|
|
157
|
+
public_shares: new ListCompositeType(new ByteVectorType(48), 256),
|
|
158
|
+
partial_deposit_data: new ListCompositeType(depositDataContainer, 256),
|
|
159
|
+
builder_registration: builderRegistrationContainer,
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
type LockContainerTypeV1X10 = ContainerType<{
|
|
163
|
+
cluster_definition: DefinitionContainerTypeV1X10;
|
|
164
|
+
distributed_validators: ListCompositeType<typeof dvContainerTypeV1X10>;
|
|
165
|
+
}>;
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* @returns SSZ Containerized type of cluster lock
|
|
169
|
+
*/
|
|
170
|
+
const clusterLockContainerTypeV1X10 = (): LockContainerTypeV1X10 => {
|
|
171
|
+
return new ContainerType({
|
|
172
|
+
cluster_definition: clusterDefinitionContainerTypeV1X10(false),
|
|
173
|
+
distributed_validators: new ListCompositeType(dvContainerTypeV1X10, 65536),
|
|
174
|
+
});
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* @param cluster The published cluster lock
|
|
179
|
+
* @returns The lock hash in of the corresponding cluster
|
|
180
|
+
*/
|
|
181
|
+
export const hashClusterLockV1X10 = (cluster: ClusterLock): string => {
|
|
182
|
+
const lockType = clusterLockContainerTypeV1X10();
|
|
183
|
+
|
|
184
|
+
const val = lockType.defaultValue();
|
|
185
|
+
|
|
186
|
+
// Check if we can replace with definition_hash
|
|
187
|
+
val.cluster_definition = hashClusterDefinitionV1X10(
|
|
188
|
+
cluster.cluster_definition,
|
|
189
|
+
false,
|
|
190
|
+
);
|
|
191
|
+
val.distributed_validators = cluster.distributed_validators.map(
|
|
192
|
+
dValidator => {
|
|
193
|
+
return {
|
|
194
|
+
distributed_public_key: fromHexString(
|
|
195
|
+
dValidator.distributed_public_key,
|
|
196
|
+
),
|
|
197
|
+
public_shares: dValidator.public_shares.map(publicShare =>
|
|
198
|
+
fromHexString(publicShare),
|
|
199
|
+
),
|
|
200
|
+
// should be fixed
|
|
201
|
+
partial_deposit_data: (
|
|
202
|
+
dValidator.partial_deposit_data as DepositData[]
|
|
203
|
+
).map(depositData => {
|
|
204
|
+
return {
|
|
205
|
+
pubkey: fromHexString(depositData.pubkey),
|
|
206
|
+
withdrawal_credentials: fromHexString(
|
|
207
|
+
depositData.withdrawal_credentials,
|
|
208
|
+
),
|
|
209
|
+
amount: parseInt(depositData.amount),
|
|
210
|
+
signature: fromHexString(depositData.signature),
|
|
211
|
+
};
|
|
212
|
+
}),
|
|
213
|
+
builder_registration: {
|
|
214
|
+
message: {
|
|
215
|
+
fee_recipient: fromHexString(
|
|
216
|
+
dValidator.builder_registration?.message.fee_recipient as string,
|
|
217
|
+
),
|
|
218
|
+
gas_limit: dValidator.builder_registration?.message
|
|
219
|
+
.gas_limit as number,
|
|
220
|
+
timestamp: dValidator.builder_registration?.message
|
|
221
|
+
.timestamp as number,
|
|
222
|
+
pubkey: fromHexString(
|
|
223
|
+
dValidator.builder_registration?.message.pubkey as string,
|
|
224
|
+
),
|
|
225
|
+
},
|
|
226
|
+
signature: fromHexString(
|
|
227
|
+
dValidator.builder_registration?.signature as string,
|
|
228
|
+
),
|
|
229
|
+
},
|
|
230
|
+
};
|
|
231
|
+
},
|
|
232
|
+
);
|
|
233
|
+
|
|
234
|
+
return '0x' + Buffer.from(lockType.hashTreeRoot(val).buffer).toString('hex');
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
// DV verification
|
|
238
|
+
export const verifyDVV1X10 = verifyDVV1X8;
|