@obolnetwork/obol-sdk 1.0.12 → 1.0.13
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/LICENCE +21 -0
- package/README.md +33 -3
- package/dist/cjs/package.json +128 -0
- package/dist/cjs/src/ajv.js +2 -1
- package/dist/cjs/src/base.js +2 -2
- package/dist/cjs/src/constants.js +38 -13
- package/dist/cjs/src/errors.js +1 -1
- package/dist/cjs/src/index.js +24 -21
- package/dist/cjs/src/schema.js +24 -36
- package/dist/cjs/src/services.js +2 -2
- package/dist/cjs/src/types.js +0 -1
- package/dist/cjs/src/utils.js +36 -1
- package/dist/cjs/src/{verify.js → verification/common.js} +128 -155
- package/dist/cjs/src/verification/sszTypes.js +69 -0
- package/dist/cjs/src/verification/v1.6.0.js +149 -0
- package/dist/cjs/src/verification/v1.7.0.js +173 -0
- package/dist/cjs/src/verification/v1.8.0.js +183 -0
- package/dist/cjs/test/fixtures.js +281 -63
- package/dist/cjs/test/methods.test.js +58 -35
- package/dist/esm/package.json +128 -0
- package/dist/esm/src/ajv.js +2 -1
- package/dist/esm/src/base.js +2 -2
- package/dist/esm/src/constants.js +14 -12
- package/dist/esm/src/errors.js +1 -1
- package/dist/esm/src/index.js +27 -24
- package/dist/esm/src/schema.js +24 -36
- package/dist/esm/src/services.js +1 -1
- package/dist/esm/src/types.js +0 -1
- package/dist/esm/src/utils.js +34 -0
- package/dist/esm/src/{verify.js → verification/common.js} +114 -146
- package/dist/esm/src/verification/sszTypes.js +64 -0
- package/dist/esm/src/verification/v1.6.0.js +142 -0
- package/dist/esm/src/verification/v1.7.0.js +166 -0
- package/dist/esm/src/verification/v1.8.0.js +176 -0
- package/dist/esm/test/fixtures.js +280 -62
- package/dist/esm/test/methods.test.js +59 -36
- package/dist/types/src/ajv.d.ts +1 -1
- package/dist/types/src/base.d.ts +3 -3
- package/dist/types/src/constants.d.ts +8 -10
- package/dist/types/src/index.d.ts +16 -16
- package/dist/types/src/services.d.ts +1 -1
- package/dist/types/src/types.d.ts +33 -27
- package/dist/types/src/utils.d.ts +3 -0
- package/dist/types/src/verification/common.d.ts +32 -0
- package/dist/types/src/verification/sszTypes.d.ts +63 -0
- package/dist/types/src/verification/v1.6.0.d.ts +34 -0
- package/dist/types/src/verification/v1.7.0.d.ts +34 -0
- package/dist/types/src/verification/v1.8.0.d.ts +35 -0
- package/dist/types/test/fixtures.d.ts +104 -2
- package/package.json +42 -8
- package/src/ajv.ts +15 -10
- package/src/base.ts +25 -21
- package/src/constants.ts +80 -78
- package/src/errors.ts +6 -9
- package/src/index.ts +118 -81
- package/src/schema.ts +24 -36
- package/src/services.ts +15 -13
- package/src/types.ts +72 -74
- package/src/utils.ts +53 -4
- package/src/verification/common.ts +420 -0
- package/src/verification/sszTypes.ts +79 -0
- package/src/verification/v1.6.0.ts +226 -0
- package/src/verification/v1.7.0.ts +274 -0
- package/src/verification/v1.8.0.ts +281 -0
- package/dist/cjs/src/hash.js +0 -172
- package/dist/esm/src/hash.js +0 -165
- package/dist/types/src/hash.d.ts +0 -56
- package/dist/types/src/verify.d.ts +0 -4
- package/src/hash.ts +0 -250
- package/src/verify.ts +0 -479
package/src/hash.ts
DELETED
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ContainerType,
|
|
3
|
-
ByteVectorType,
|
|
4
|
-
UintNumberType,
|
|
5
|
-
ListCompositeType,
|
|
6
|
-
ByteListType,
|
|
7
|
-
fromHexString,
|
|
8
|
-
} from '@chainsafe/ssz';
|
|
9
|
-
import { UintNumberByteLen } from '@chainsafe/ssz/lib/type/uint.js';
|
|
10
|
-
import { ValueOfFields } from '@chainsafe/ssz/lib/view/container.js';
|
|
11
|
-
import { ClusterDefintion, ClusterLock } from './types.js';
|
|
12
|
-
import { strToUint8Array } from './utils.js';
|
|
13
|
-
|
|
14
|
-
//cluster-definition
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @param cluster The cluster configuration or the cluster definition
|
|
18
|
-
* @param configOnly a boolean to indicate config hash or definition hash
|
|
19
|
-
* @returns The config hash or the definition hash in of the corresponding cluster
|
|
20
|
-
*/
|
|
21
|
-
export const clusterConfigOrDefinitionHash = (
|
|
22
|
-
cluster: ClusterDefintion,
|
|
23
|
-
configOnly: boolean,
|
|
24
|
-
): string => {
|
|
25
|
-
|
|
26
|
-
const definitionType = clusterDefinitionContainerType(configOnly);
|
|
27
|
-
const val = hashClusterDefinition(cluster, configOnly);
|
|
28
|
-
return (
|
|
29
|
-
'0x' + Buffer.from(definitionType.hashTreeRoot(val).buffer).toString('hex')
|
|
30
|
-
);
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export const hashClusterDefinition = (
|
|
34
|
-
cluster: ClusterDefintion,
|
|
35
|
-
configOnly: boolean,
|
|
36
|
-
): ValueOfFields<DefinitionFields> => {
|
|
37
|
-
const definitionType = clusterDefinitionContainerType(configOnly);
|
|
38
|
-
|
|
39
|
-
const val = definitionType.defaultValue();
|
|
40
|
-
|
|
41
|
-
//order should be same as charon https://github.com/ObolNetwork/charon/blob/d00b31e6465a260a43ce40f15c47fb5a5b009042/cluster/ssz.go#L285
|
|
42
|
-
val.uuid = strToUint8Array(cluster.uuid);
|
|
43
|
-
val.name = strToUint8Array(cluster.name);
|
|
44
|
-
val.version = strToUint8Array(cluster.version);
|
|
45
|
-
val.timestamp = strToUint8Array(cluster.timestamp);
|
|
46
|
-
val.num_validators = cluster.num_validators;
|
|
47
|
-
val.threshold = cluster.threshold;
|
|
48
|
-
val.dkg_algorithm = strToUint8Array(cluster.dkg_algorithm);
|
|
49
|
-
val.fork_version = fromHexString(cluster.fork_version);
|
|
50
|
-
val.operators = cluster.operators.map((operator) => {
|
|
51
|
-
return configOnly
|
|
52
|
-
? { address: fromHexString(operator.address) }
|
|
53
|
-
: {
|
|
54
|
-
address: fromHexString(operator.address),
|
|
55
|
-
enr: strToUint8Array(operator.enr as string),
|
|
56
|
-
config_signature: fromHexString(operator.config_signature as string),
|
|
57
|
-
enr_signature: fromHexString(operator.enr_signature as string),
|
|
58
|
-
};
|
|
59
|
-
});
|
|
60
|
-
val.creator = configOnly
|
|
61
|
-
? { address: fromHexString(cluster.creator.address) }
|
|
62
|
-
: {
|
|
63
|
-
address: fromHexString(cluster.creator.address),
|
|
64
|
-
config_signature: fromHexString(cluster.creator.config_signature as string),
|
|
65
|
-
};
|
|
66
|
-
val.validators = cluster.validators.map((validator: { fee_recipient_address: string; withdrawal_address: string; }) => {
|
|
67
|
-
return {
|
|
68
|
-
fee_recipient_address: fromHexString(validator.fee_recipient_address),
|
|
69
|
-
withdrawal_address: fromHexString(validator.withdrawal_address),
|
|
70
|
-
};
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
if (!configOnly) {
|
|
74
|
-
val.config_hash = fromHexString(cluster.config_hash);
|
|
75
|
-
}
|
|
76
|
-
return val;
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
const operatorAddressWrapperType = new ContainerType({
|
|
80
|
-
address: new ByteVectorType(20),
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
const creatorAddressWrapperType = new ContainerType({
|
|
84
|
-
address: new ByteVectorType(20),
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
export const operatorContainerType = new ContainerType({
|
|
88
|
-
address: new ByteVectorType(20),
|
|
89
|
-
enr: new ByteListType(1024), // This needs to be dynamic, since ENRs do not have a fixed length.
|
|
90
|
-
config_signature: new ByteVectorType(65),
|
|
91
|
-
enr_signature: new ByteVectorType(65),
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
export const creatorContainerType = new ContainerType({
|
|
95
|
-
address: new ByteVectorType(20),
|
|
96
|
-
config_signature: new ByteVectorType(65),
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
export const validatorsContainerType = new ContainerType({
|
|
100
|
-
fee_recipient_address: new ByteVectorType(20),
|
|
101
|
-
withdrawal_address: new ByteVectorType(20),
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
const newCreatorContainerType = (configOnly: boolean) => {
|
|
105
|
-
return configOnly ? creatorAddressWrapperType : creatorContainerType;
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
const newOperatorContainerType = (configOnly: boolean) => {
|
|
109
|
-
return configOnly ? operatorAddressWrapperType : operatorContainerType;
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
type DefinitionFields = {
|
|
113
|
-
uuid: ByteListType;
|
|
114
|
-
name: ByteListType;
|
|
115
|
-
version: ByteListType;
|
|
116
|
-
timestamp: ByteListType;
|
|
117
|
-
num_validators: UintNumberType;
|
|
118
|
-
threshold: UintNumberType;
|
|
119
|
-
dkg_algorithm: ByteListType;
|
|
120
|
-
fork_version: ByteVectorType;
|
|
121
|
-
operators: ListCompositeType<
|
|
122
|
-
typeof operatorContainerType | typeof operatorAddressWrapperType
|
|
123
|
-
>;
|
|
124
|
-
creator: typeof creatorContainerType | typeof creatorAddressWrapperType;
|
|
125
|
-
validators: ListCompositeType<typeof validatorsContainerType>;
|
|
126
|
-
config_hash?: ByteVectorType;
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
export type DefinitionContainerType =
|
|
130
|
-
ContainerType<DefinitionFields>;
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* @param configOnly a boolean to indicate config hash or definition hash
|
|
134
|
-
* @returns SSZ Containerized type of cluster definition
|
|
135
|
-
*/
|
|
136
|
-
export const clusterDefinitionContainerType = (
|
|
137
|
-
configOnly: boolean,
|
|
138
|
-
): DefinitionContainerType => {
|
|
139
|
-
let returnedContainerType: DefinitionFields = {
|
|
140
|
-
uuid: new ByteListType(64),
|
|
141
|
-
name: new ByteListType(256),
|
|
142
|
-
version: new ByteListType(16),
|
|
143
|
-
timestamp: new ByteListType(32),
|
|
144
|
-
num_validators: new UintNumberType(8 as UintNumberByteLen),
|
|
145
|
-
threshold: new UintNumberType(8 as UintNumberByteLen),
|
|
146
|
-
dkg_algorithm: new ByteListType(32),
|
|
147
|
-
fork_version: new ByteVectorType(4),
|
|
148
|
-
operators: new ListCompositeType(newOperatorContainerType(configOnly), 256),
|
|
149
|
-
creator: newCreatorContainerType(configOnly),
|
|
150
|
-
validators: new ListCompositeType(validatorsContainerType, 65536),
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
if (!configOnly) {
|
|
154
|
-
returnedContainerType = {
|
|
155
|
-
...returnedContainerType,
|
|
156
|
-
config_hash: new ByteVectorType(32),
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
return new ContainerType(returnedContainerType);
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
//cluster-lock
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* @param cluster The published cluster lock
|
|
167
|
-
* @returns The lock hash in of the corresponding cluster
|
|
168
|
-
*/
|
|
169
|
-
export const clusterLockHash = (cluster: ClusterLock): string => {
|
|
170
|
-
const lockType = clusterLockContainerType();
|
|
171
|
-
|
|
172
|
-
const val = lockType.defaultValue();
|
|
173
|
-
|
|
174
|
-
//Check if we can replace with definition_hash
|
|
175
|
-
val.cluster_definition = hashClusterDefinition(
|
|
176
|
-
cluster.cluster_definition,
|
|
177
|
-
false,
|
|
178
|
-
);
|
|
179
|
-
val.distributed_validators = cluster.distributed_validators.map(dVaidator => {
|
|
180
|
-
return {
|
|
181
|
-
distributed_public_key: fromHexString(dVaidator.distributed_public_key),
|
|
182
|
-
public_shares: dVaidator.public_shares.map(publicShare =>
|
|
183
|
-
fromHexString(publicShare),
|
|
184
|
-
),
|
|
185
|
-
deposit_data: {
|
|
186
|
-
pubkey: fromHexString(dVaidator.deposit_data.pubkey as string),
|
|
187
|
-
withdrawal_credentials: fromHexString(
|
|
188
|
-
dVaidator.deposit_data.withdrawal_credentials as string
|
|
189
|
-
),
|
|
190
|
-
amount: parseInt(dVaidator.deposit_data.amount as string),
|
|
191
|
-
signature: fromHexString(dVaidator.deposit_data.signature as string),
|
|
192
|
-
},
|
|
193
|
-
builder_registration: {
|
|
194
|
-
message: {
|
|
195
|
-
fee_recipient: fromHexString(
|
|
196
|
-
dVaidator.builder_registration.message.fee_recipient,
|
|
197
|
-
),
|
|
198
|
-
gas_limit: dVaidator.builder_registration.message.gas_limit,
|
|
199
|
-
timestamp: dVaidator.builder_registration.message.timestamp,
|
|
200
|
-
pubkey: fromHexString(dVaidator.builder_registration.message.pubkey),
|
|
201
|
-
},
|
|
202
|
-
signature: fromHexString(dVaidator.builder_registration.signature),
|
|
203
|
-
},
|
|
204
|
-
};
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
return '0x' + Buffer.from(lockType.hashTreeRoot(val).buffer).toString('hex');
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
const depositDataContainer = new ContainerType({
|
|
211
|
-
pubkey: new ByteVectorType(48),
|
|
212
|
-
withdrawal_credentials: new ByteVectorType(32),
|
|
213
|
-
amount: new UintNumberType(8 as UintNumberByteLen),
|
|
214
|
-
signature: new ByteVectorType(96),
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
const builderRegistrationMessageContainer = new ContainerType({
|
|
219
|
-
fee_recipient: new ByteVectorType(20),
|
|
220
|
-
gas_limit: new UintNumberType(8 as UintNumberByteLen),
|
|
221
|
-
timestamp: new UintNumberType(8 as UintNumberByteLen),
|
|
222
|
-
pubkey: new ByteVectorType(48),
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
const builderRegistrationContainer = new ContainerType({
|
|
226
|
-
message: builderRegistrationMessageContainer,
|
|
227
|
-
signature: new ByteVectorType(96),
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
const dvContainerType = new ContainerType({
|
|
231
|
-
distributed_public_key: new ByteVectorType(48),
|
|
232
|
-
public_shares: new ListCompositeType(new ByteVectorType(48), 256),
|
|
233
|
-
deposit_data: depositDataContainer,
|
|
234
|
-
builder_registration: builderRegistrationContainer,
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
type LockContainerType = ContainerType<{
|
|
238
|
-
cluster_definition: DefinitionContainerType;
|
|
239
|
-
distributed_validators: ListCompositeType<typeof dvContainerType>;
|
|
240
|
-
}>;
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* @returns SSZ Containerized type of cluster lock
|
|
244
|
-
*/
|
|
245
|
-
const clusterLockContainerType = (): LockContainerType => {
|
|
246
|
-
return new ContainerType({
|
|
247
|
-
cluster_definition: clusterDefinitionContainerType(false),
|
|
248
|
-
distributed_validators: new ListCompositeType(dvContainerType, 65536),
|
|
249
|
-
});
|
|
250
|
-
};
|