@obolnetwork/obol-sdk 1.0.9 → 1.0.12

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 (66) hide show
  1. package/README.md +2 -1
  2. package/dist/cjs/src/ajv.js +17 -0
  3. package/dist/cjs/src/base.js +39 -0
  4. package/dist/cjs/src/constants.js +86 -0
  5. package/dist/cjs/src/errors.js +11 -0
  6. package/dist/cjs/src/hash.js +172 -0
  7. package/dist/cjs/src/index.js +158 -0
  8. package/dist/cjs/src/schema.js +72 -0
  9. package/dist/cjs/src/services.js +32 -0
  10. package/dist/cjs/src/types.js +18 -0
  11. package/dist/cjs/src/utils.js +11 -0
  12. package/dist/cjs/src/verify.js +326 -0
  13. package/dist/cjs/test/fixtures.js +101 -0
  14. package/dist/cjs/test/methods.test.js +128 -0
  15. package/dist/esm/src/ajv.js +10 -0
  16. package/dist/esm/src/base.js +35 -0
  17. package/dist/esm/src/constants.js +79 -0
  18. package/dist/esm/src/errors.js +7 -0
  19. package/dist/esm/src/hash.js +165 -0
  20. package/dist/esm/src/index.js +140 -0
  21. package/dist/esm/src/schema.js +69 -0
  22. package/dist/esm/src/services.js +28 -0
  23. package/dist/esm/src/types.js +15 -0
  24. package/dist/esm/src/utils.js +6 -0
  25. package/dist/esm/src/verify.js +295 -0
  26. package/dist/esm/test/fixtures.js +98 -0
  27. package/dist/esm/test/methods.test.js +126 -0
  28. package/dist/{ajv.d.ts → types/src/ajv.d.ts} +2 -3
  29. package/dist/{base.d.ts → types/src/base.d.ts} +13 -14
  30. package/dist/types/src/constants.d.ts +79 -0
  31. package/dist/{errors.d.ts → types/src/errors.d.ts} +4 -5
  32. package/dist/{hash.d.ts → types/src/hash.d.ts} +56 -64
  33. package/dist/{index.d.ts → types/src/index.d.ts} +64 -60
  34. package/dist/{schema.d.ts → types/src/schema.d.ts} +57 -58
  35. package/dist/types/src/services.d.ts +11 -0
  36. package/dist/{types.d.ts → types/src/types.d.ts} +153 -154
  37. package/dist/types/src/utils.d.ts +2 -0
  38. package/dist/types/src/verify.d.ts +4 -0
  39. package/dist/{fixtures.d.ts → types/test/fixtures.d.ts} +61 -62
  40. package/dist/types/test/methods.test.d.ts +1 -0
  41. package/package.json +55 -20
  42. package/src/ajv.ts +11 -0
  43. package/src/base.ts +44 -0
  44. package/src/constants.ts +118 -0
  45. package/src/errors.ts +11 -0
  46. package/src/hash.ts +250 -0
  47. package/src/index.ts +160 -0
  48. package/src/schema.ts +70 -0
  49. package/src/services.ts +20 -0
  50. package/src/types.ts +211 -0
  51. package/src/utils.ts +7 -0
  52. package/src/verify.ts +479 -0
  53. package/dist/ajv.d.ts.map +0 -1
  54. package/dist/base.d.ts.map +0 -1
  55. package/dist/cluster.test.d.ts +0 -2
  56. package/dist/cluster.test.d.ts.map +0 -1
  57. package/dist/constants.d.ts +0 -30
  58. package/dist/constants.d.ts.map +0 -1
  59. package/dist/errors.d.ts.map +0 -1
  60. package/dist/fixtures.d.ts.map +0 -1
  61. package/dist/hash.d.ts.map +0 -1
  62. package/dist/index.d.ts.map +0 -1
  63. package/dist/index.es.js +0 -15582
  64. package/dist/index.js +0 -15586
  65. package/dist/schema.d.ts.map +0 -1
  66. package/dist/types.d.ts.map +0 -1
@@ -0,0 +1,118 @@
1
+ import { TypedMessage } from "@metamask/eth-sig-util";
2
+
3
+ export const CONFLICT_ERROR_MSG = "Conflict"
4
+
5
+ export const EIP712_DOMAIN_NAME = "Obol";
6
+ export const EIP712_DOMAIN_VERSION = "1";
7
+ export const CreatorConfigHashSigningTypes = {
8
+ CreatorConfigHash: [{ name: "creator_config_hash", type: "string" }],
9
+ };
10
+
11
+ const EIP712Domain = [
12
+ { name: 'name', type: 'string' },
13
+ { name: 'version', type: 'string' },
14
+ { name: 'chainId', type: 'uint256' },
15
+ ]
16
+
17
+ export const Domain = (chainId: number) => {
18
+ return {
19
+ name: EIP712_DOMAIN_NAME,
20
+ version: EIP712_DOMAIN_VERSION,
21
+ chainId,
22
+ }
23
+ }
24
+
25
+ export const CreatorTypedMessage = {
26
+ EIP712Domain,
27
+ ...CreatorConfigHashSigningTypes
28
+ };
29
+
30
+ //A conflict once updateDefinition is merged
31
+ export const EnrSigningTypes = {
32
+ ENR: [{ name: "enr", type: "string" }],
33
+ };
34
+
35
+ export const OperatorConfigHashSigningTypes = {
36
+ OperatorConfigHash: [{ name: "operator_config_hash", type: "string" }],
37
+ };
38
+
39
+ export const OperatorTypedMessage = {
40
+ EIP712Domain,
41
+ ...OperatorConfigHashSigningTypes
42
+ };
43
+
44
+ export const ENRTypedMessage = {
45
+ EIP712Domain,
46
+ ...EnrSigningTypes
47
+ };
48
+
49
+ export const signCreatorConfigHashPayload = (
50
+ payload: { creator_config_hash: string },
51
+ chainId: number,
52
+ ): TypedMessage<typeof CreatorTypedMessage> => {
53
+ return {
54
+ types: CreatorTypedMessage,
55
+ primaryType: 'CreatorConfigHash',
56
+ domain: {
57
+ name: EIP712_DOMAIN_NAME,
58
+ version: EIP712_DOMAIN_VERSION,
59
+ chainId,
60
+ },
61
+ message: payload,
62
+ };
63
+ }
64
+
65
+ export const signOperatorConfigHashPayload = (
66
+ payload: { operator_config_hash: string },
67
+ chainId: number,
68
+ ): TypedMessage<typeof OperatorTypedMessage> => {
69
+ return {
70
+ types: OperatorTypedMessage,
71
+ primaryType: 'OperatorConfigHash',
72
+ domain: {
73
+ name: EIP712_DOMAIN_NAME,
74
+ version: EIP712_DOMAIN_VERSION,
75
+ chainId,
76
+ },
77
+ message: payload,
78
+ };
79
+ }
80
+
81
+ export const signEnrPayload = (
82
+ payload: { enr: string },
83
+ chainId: number,
84
+ ): TypedMessage<typeof ENRTypedMessage> => {
85
+ return {
86
+ types: ENRTypedMessage,
87
+ primaryType: 'ENR',
88
+ domain: {
89
+ name: EIP712_DOMAIN_NAME,
90
+ version: EIP712_DOMAIN_VERSION,
91
+ chainId,
92
+ },
93
+ message: payload,
94
+ };
95
+ }
96
+
97
+
98
+ export const dkg_algorithm = "default";
99
+
100
+ export const config_version = "v1.7.0";
101
+
102
+ export const SDK_VERSION = "1.0.7";
103
+
104
+ export const DOMAIN_APPLICATION_BUILDER = '00000001';
105
+ export const DOMAIN_DEPOSIT = '03000000';
106
+ export const GENESIS_VALIDATOR_ROOT =
107
+ '0000000000000000000000000000000000000000000000000000000000000000';
108
+
109
+ // Flow used to create defintion
110
+ export enum DefinitionFlow {
111
+ Group = 'LP-Group',
112
+ Solo = 'LP-Solo',
113
+ Charon = 'Charon-Command',
114
+
115
+ }
116
+
117
+ export const DEFAULT_BASE_URL = "https://api.obol.tech";
118
+ export const DEFAULT_CHAIN_ID = 1;
package/src/errors.ts ADDED
@@ -0,0 +1,11 @@
1
+ export class ConflictError extends Error {
2
+ name = 'ConflictError'
3
+
4
+ constructor() {
5
+ super(
6
+ `This Cluster has been already posted.`,
7
+ )
8
+ Object.setPrototypeOf(this, ConflictError.prototype)
9
+ }
10
+ }
11
+
package/src/hash.ts ADDED
@@ -0,0 +1,250 @@
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
+ };
package/src/index.ts ADDED
@@ -0,0 +1,160 @@
1
+ import { Signer } from "ethers";
2
+ import { v4 as uuidv4 } from "uuid";
3
+ import { Base } from './base.js';
4
+ import { CONFLICT_ERROR_MSG, CreatorConfigHashSigningTypes, Domain, dkg_algorithm, config_version, OperatorConfigHashSigningTypes, EnrSigningTypes } from './constants.js';
5
+ import { ConflictError } from './errors.js';
6
+ import { ClusterDefintion, ClusterLock, ClusterPayload, OperatorPayload } from './types.js';
7
+ import { clusterConfigOrDefinitionHash } from './hash.js';
8
+ import { validatePayload } from './ajv.js';
9
+ import { definitionSchema, operatorPayloadSchema } from './schema.js';
10
+ export * from "./types.js";
11
+ export * from "./services.js";
12
+
13
+
14
+ /**
15
+ * Obol sdk Client can be used for creating, managing and activating distributed validators.
16
+ */
17
+ export class Client extends Base {
18
+ private signer: Signer | undefined;
19
+
20
+ /**
21
+ * @param config - Client configurations
22
+ * @param config.baseUrl - obol-api url
23
+ * @param config.chainId - Blockchain network ID
24
+ * @param signer - ethersJS Signer
25
+ * @returns Obol-SDK Client instance
26
+ *
27
+ * An example of how to instantiate obol-sdk Client:
28
+ * [obolClient](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts#L29)
29
+ */
30
+ constructor(config: { baseUrl?: string | undefined; chainId?: number | undefined }, signer?: Signer) {
31
+
32
+ super(config)
33
+ this.signer = signer
34
+ }
35
+
36
+ /**
37
+ * Creates a cluster definition which contains cluster configuration.
38
+ * @param {ClusterPayload} newCluster - The new unique cluster.
39
+ * @returns {Promise<string>} config_hash.
40
+ * @throws On duplicate entries, missing or wrong cluster keys.
41
+ *
42
+ * An example of how to use createClusterDefinition:
43
+ * [createObolCluster](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts)
44
+ */
45
+ async createClusterDefinition(newCluster: ClusterPayload): Promise<string> {
46
+ if (!this.signer) throw "Signer is required in createClusterDefinition"
47
+
48
+ validatePayload(newCluster, definitionSchema);
49
+
50
+ const clusterConfig: Partial<ClusterDefintion> = {
51
+ ...newCluster,
52
+ fork_version: this.fork_version,
53
+ dkg_algorithm: dkg_algorithm,
54
+ version: config_version,
55
+ uuid: uuidv4(),
56
+ timestamp: new Date().toISOString(),
57
+ threshold: Math.ceil((2 * newCluster.operators.length) / 3),
58
+ num_validators: newCluster.validators.length
59
+ }
60
+
61
+ try {
62
+ const address = await this.signer.getAddress();
63
+
64
+ clusterConfig.creator = { address };
65
+ clusterConfig.config_hash = clusterConfigOrDefinitionHash(clusterConfig as ClusterDefintion, true);
66
+
67
+ const creatorConfigSignature = await this.signer.signTypedData(Domain(this.chainId), CreatorConfigHashSigningTypes, { creator_config_hash: clusterConfig.config_hash });
68
+
69
+ const clusterDefinition: ClusterDefintion = await this.request(`/dv`, {
70
+ method: 'POST',
71
+ body: JSON.stringify(clusterConfig),
72
+ headers: {
73
+ Authorization: `Bearer ${creatorConfigSignature}`,
74
+ "fork-version": this.fork_version,
75
+ }
76
+
77
+ });
78
+ return clusterDefinition?.config_hash;
79
+ } catch (err: any) {
80
+ if (err?.message == CONFLICT_ERROR_MSG)
81
+ throw new ConflictError();
82
+ throw err;
83
+ }
84
+ }
85
+
86
+ /**
87
+ * Approves joining a cluster with specific configuration.
88
+ * @param {OperatorPayload} operatorPayload - The operator data including signatures.
89
+ * @param {string} configHash - The config hash of the cluster which the operator confirms joining to.
90
+ * @returns {Promise<ClusterDefintion>} The cluster definition.
91
+ * @throws On unauthorized, duplicate entries, missing keys, not found cluster or invalid data.
92
+ *
93
+ * An example of how to use acceptClusterDefinition:
94
+ * [acceptClusterDefinition](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts)
95
+ */
96
+ async acceptClusterDefinition(operatorPayload: OperatorPayload, configHash: string): Promise<ClusterDefintion> {
97
+ if (!this.signer) throw "Signer is required in acceptClusterDefinition"
98
+
99
+ validatePayload(operatorPayload, operatorPayloadSchema);
100
+
101
+ try {
102
+ const address = await this.signer.getAddress();
103
+
104
+ const operatorConfigSignature = await this.signer.signTypedData(Domain(this.chainId), OperatorConfigHashSigningTypes, { operator_config_hash: configHash });
105
+ const operatorENRSignature = await this.signer.signTypedData(Domain(this.chainId), EnrSigningTypes, { enr: operatorPayload.enr });
106
+
107
+ const operatorData: OperatorPayload = {
108
+ ...operatorPayload,
109
+ address,
110
+ enr_signature: operatorENRSignature,
111
+ fork_version: this.fork_version
112
+ }
113
+ const clusterDefinition: ClusterDefintion = await this.request(`/dv/${configHash}`, {
114
+ method: 'PUT',
115
+ body: JSON.stringify(operatorData),
116
+ headers: {
117
+ Authorization: `Bearer ${operatorConfigSignature}`,
118
+ }
119
+
120
+ });
121
+ return clusterDefinition;
122
+ } catch (err: any) {
123
+ throw err;
124
+ }
125
+ }
126
+
127
+
128
+ /**
129
+ * @param configHash - The configuration hash returned in createClusterDefinition
130
+ * @returns {Promise<ClusterDefintion>} The cluster definition for config hash
131
+ * @throws On not found config hash.
132
+ *
133
+ * An example of how to use getClusterDefinition:
134
+ * [getObolClusterDefinition](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts)
135
+ */
136
+ async getClusterDefinition(configHash: string): Promise<ClusterDefintion> {
137
+ const clusterDefinition: ClusterDefintion = await this.request(`/dv/${configHash}`, {
138
+ method: 'GET',
139
+ })
140
+
141
+ return clusterDefinition
142
+ }
143
+
144
+ /**
145
+ * @param configHash - The configuration hash in cluster-definition
146
+ * @returns {Promise<ClusterLock>} The matched cluster details (lock) from DB
147
+ * @throws On not found cluster definition or lock.
148
+ *
149
+ * An example of how to use getClusterLock:
150
+ * [getObolClusterLock](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts)
151
+ */
152
+ async getClusterLock(configHash: string): Promise<ClusterLock> {
153
+
154
+ const lock: ClusterLock = await this.request(`/lock/configHash/${configHash}`, {
155
+ method: 'GET',
156
+ })
157
+ return lock
158
+ }
159
+ }
160
+
package/src/schema.ts ADDED
@@ -0,0 +1,70 @@
1
+ export const operatorPayloadSchema = {
2
+ type: "object",
3
+ properties: {
4
+ version: {
5
+ type: "string"
6
+ },
7
+ enr: {
8
+ type: "string"
9
+ },
10
+ },
11
+ required: [
12
+ "version",
13
+ "enr",
14
+ ]
15
+ }
16
+
17
+ export const definitionSchema = {
18
+ type: "object",
19
+ properties: {
20
+ name: {
21
+ type: "string"
22
+ },
23
+ operators: {
24
+ type: "array",
25
+ minItems: 4,
26
+ uniqueItems: true,
27
+ items: {
28
+ type: "object",
29
+ properties: {
30
+ address: {
31
+ type: "string",
32
+ minLength: 42,
33
+ maxLength: 42
34
+ }
35
+ },
36
+ required: [
37
+ "address"
38
+ ]
39
+ }
40
+ },
41
+ validators: {
42
+ type: "array",
43
+ minItems: 1,
44
+ items: {
45
+ type: "object",
46
+ properties: {
47
+ fee_recipient_address: {
48
+ type: "string",
49
+ minLength: 42,
50
+ maxLength: 42
51
+ },
52
+ withdrawal_address: {
53
+ type: "string",
54
+ minLength: 42,
55
+ maxLength: 42
56
+ }
57
+ },
58
+ required: [
59
+ "fee_recipient_address",
60
+ "withdrawal_address"
61
+ ]
62
+ }
63
+ }
64
+ },
65
+ required: [
66
+ "name",
67
+ "operators",
68
+ "validators"
69
+ ]
70
+ }
@@ -0,0 +1,20 @@
1
+ import { ClusterLock } from "./types.js";
2
+ import { isValidClusterLock } from "./verify.js";
3
+
4
+ /**
5
+ * Verifies Cluster Lock's validity.
6
+ * @param lock - cluster lock
7
+ * @returns {Promise<{ result: boolean }> } boolean result to indicate if lock is valid
8
+ * @throws on missing keys or values.
9
+ *
10
+ * An example of how to use validateClusterLock:
11
+ * [validateClusterLock](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts)
12
+ */
13
+ export const validateClusterLock = async (lock: ClusterLock): Promise<boolean> => {
14
+ try {
15
+ const isLockValid = await isValidClusterLock(lock);
16
+ return isLockValid
17
+ } catch (err: any) {
18
+ throw err;
19
+ }
20
+ }