@obolnetwork/obol-sdk 1.0.15 → 1.0.17
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 +6 -3
- package/dist/cjs/package.json +11 -6
- package/dist/cjs/src/ajv.js +27 -0
- package/dist/cjs/src/constants.js +8 -4
- package/dist/cjs/src/index.js +21 -18
- package/dist/cjs/src/schema.js +8 -0
- package/dist/cjs/src/services.js +1 -1
- package/dist/cjs/src/utils.js +3 -3
- package/dist/cjs/src/verification/common.js +19 -7
- package/dist/cjs/src/verification/termsAndConditions.js +1 -1
- package/dist/cjs/src/verification/v1.6.0.js +1 -1
- package/dist/cjs/src/verification/v1.7.0.js +3 -3
- package/dist/cjs/src/verification/v1.8.0.js +3 -3
- package/dist/cjs/test/fixtures.js +71 -82
- package/dist/cjs/test/methods.test.js +54 -27
- package/dist/esm/package.json +11 -6
- package/dist/esm/src/ajv.js +27 -0
- package/dist/esm/src/base.js +1 -1
- package/dist/esm/src/constants.js +7 -3
- package/dist/esm/src/index.js +22 -19
- package/dist/esm/src/schema.js +8 -0
- package/dist/esm/src/services.js +1 -1
- package/dist/esm/src/utils.js +3 -3
- package/dist/esm/src/verification/common.js +27 -15
- package/dist/esm/src/verification/sszTypes.js +1 -1
- package/dist/esm/src/verification/termsAndConditions.js +1 -1
- package/dist/esm/src/verification/v1.6.0.js +5 -5
- package/dist/esm/src/verification/v1.7.0.js +8 -8
- package/dist/esm/src/verification/v1.8.0.js +8 -8
- package/dist/esm/test/fixtures.js +71 -82
- package/dist/esm/test/methods.test.js +55 -28
- package/dist/types/src/constants.d.ts +3 -1
- package/dist/types/src/index.d.ts +11 -9
- package/dist/types/src/schema.d.ts +8 -0
- package/dist/types/src/services.d.ts +1 -1
- package/dist/types/src/types.d.ts +18 -18
- package/package.json +12 -7
- package/src/ajv.ts +38 -7
- package/src/base.ts +22 -18
- package/src/constants.ts +42 -36
- package/src/errors.ts +4 -4
- package/src/index.ts +96 -84
- package/src/schema.ts +10 -2
- package/src/services.ts +7 -7
- package/src/types.ts +65 -65
- package/src/utils.ts +17 -17
- package/src/verification/common.ts +374 -333
- package/src/verification/sszTypes.ts +60 -51
- package/src/verification/termsAndConditions.ts +16 -14
- package/src/verification/v1.6.0.ts +214 -184
- package/src/verification/v1.7.0.ts +268 -233
- package/src/verification/v1.8.0.ts +266 -225
package/src/constants.ts
CHANGED
|
@@ -1,61 +1,61 @@
|
|
|
1
|
-
import { type TypedMessage } from '@metamask/eth-sig-util'
|
|
2
|
-
import { type TypedDataDomain } from 'ethers'
|
|
3
|
-
import * as pjson from '../package.json'
|
|
1
|
+
import { type TypedMessage } from '@metamask/eth-sig-util';
|
|
2
|
+
import { type TypedDataDomain } from 'ethers';
|
|
3
|
+
import * as pjson from '../package.json';
|
|
4
4
|
|
|
5
|
-
export const CONFLICT_ERROR_MSG = 'Conflict'
|
|
5
|
+
export const CONFLICT_ERROR_MSG = 'Conflict';
|
|
6
6
|
|
|
7
|
-
export const EIP712_DOMAIN_NAME = 'Obol'
|
|
8
|
-
export const EIP712_DOMAIN_VERSION = '1'
|
|
7
|
+
export const EIP712_DOMAIN_NAME = 'Obol';
|
|
8
|
+
export const EIP712_DOMAIN_VERSION = '1';
|
|
9
9
|
export const CreatorConfigHashSigningTypes = {
|
|
10
10
|
CreatorConfigHash: [{ name: 'creator_config_hash', type: 'string' }],
|
|
11
|
-
}
|
|
11
|
+
};
|
|
12
12
|
export const TermsAndConditionsSigningTypes = {
|
|
13
13
|
TermsAndConditions: [
|
|
14
14
|
{ name: 'terms_and_conditions_hash', type: 'string' },
|
|
15
15
|
{ name: 'version', type: 'uint256' },
|
|
16
|
-
]
|
|
17
|
-
}
|
|
16
|
+
],
|
|
17
|
+
};
|
|
18
18
|
|
|
19
19
|
const EIP712Domain = [
|
|
20
20
|
{ name: 'name', type: 'string' },
|
|
21
21
|
{ name: 'version', type: 'string' },
|
|
22
22
|
{ name: 'chainId', type: 'uint256' },
|
|
23
|
-
]
|
|
23
|
+
];
|
|
24
24
|
|
|
25
25
|
export const Domain = (chainId?: number): TypedDataDomain => {
|
|
26
26
|
const typeDataDomain: any = {
|
|
27
27
|
name: EIP712_DOMAIN_NAME,
|
|
28
28
|
version: EIP712_DOMAIN_VERSION,
|
|
29
|
-
}
|
|
29
|
+
};
|
|
30
30
|
if (chainId) {
|
|
31
|
-
typeDataDomain.chainId = chainId
|
|
31
|
+
typeDataDomain.chainId = chainId;
|
|
32
32
|
}
|
|
33
|
-
return typeDataDomain
|
|
34
|
-
}
|
|
33
|
+
return typeDataDomain;
|
|
34
|
+
};
|
|
35
35
|
|
|
36
36
|
export const CreatorTypedMessage = {
|
|
37
37
|
EIP712Domain,
|
|
38
38
|
...CreatorConfigHashSigningTypes,
|
|
39
|
-
}
|
|
39
|
+
};
|
|
40
40
|
|
|
41
41
|
// A conflict once updateDefinition is merged
|
|
42
42
|
export const EnrSigningTypes = {
|
|
43
43
|
ENR: [{ name: 'enr', type: 'string' }],
|
|
44
|
-
}
|
|
44
|
+
};
|
|
45
45
|
|
|
46
46
|
export const OperatorConfigHashSigningTypes = {
|
|
47
47
|
OperatorConfigHash: [{ name: 'operator_config_hash', type: 'string' }],
|
|
48
|
-
}
|
|
48
|
+
};
|
|
49
49
|
|
|
50
50
|
export const OperatorTypedMessage = {
|
|
51
51
|
EIP712Domain,
|
|
52
52
|
...OperatorConfigHashSigningTypes,
|
|
53
|
-
}
|
|
53
|
+
};
|
|
54
54
|
|
|
55
55
|
export const ENRTypedMessage = {
|
|
56
56
|
EIP712Domain,
|
|
57
57
|
...EnrSigningTypes,
|
|
58
|
-
}
|
|
58
|
+
};
|
|
59
59
|
|
|
60
60
|
export const signCreatorConfigHashPayload = (
|
|
61
61
|
payload: { creator_config_hash: string },
|
|
@@ -70,8 +70,8 @@ export const signCreatorConfigHashPayload = (
|
|
|
70
70
|
chainId,
|
|
71
71
|
},
|
|
72
72
|
message: payload,
|
|
73
|
-
}
|
|
74
|
-
}
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
75
|
|
|
76
76
|
export const signOperatorConfigHashPayload = (
|
|
77
77
|
payload: { operator_config_hash: string },
|
|
@@ -86,8 +86,8 @@ export const signOperatorConfigHashPayload = (
|
|
|
86
86
|
chainId,
|
|
87
87
|
},
|
|
88
88
|
message: payload,
|
|
89
|
-
}
|
|
90
|
-
}
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
91
|
|
|
92
92
|
export const signEnrPayload = (
|
|
93
93
|
payload: { enr: string },
|
|
@@ -102,19 +102,19 @@ export const signEnrPayload = (
|
|
|
102
102
|
chainId,
|
|
103
103
|
},
|
|
104
104
|
message: payload,
|
|
105
|
-
}
|
|
106
|
-
}
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
107
|
|
|
108
|
-
export const DKG_ALGORITHM = 'default'
|
|
108
|
+
export const DKG_ALGORITHM = 'default';
|
|
109
109
|
|
|
110
|
-
export const CONFIG_VERSION = 'v1.
|
|
110
|
+
export const CONFIG_VERSION = 'v1.8.0';
|
|
111
111
|
|
|
112
|
-
export const SDK_VERSION = pjson.version
|
|
112
|
+
export const SDK_VERSION = pjson.version;
|
|
113
113
|
|
|
114
|
-
export const DOMAIN_APPLICATION_BUILDER = '00000001'
|
|
115
|
-
export const DOMAIN_DEPOSIT = '03000000'
|
|
114
|
+
export const DOMAIN_APPLICATION_BUILDER = '00000001';
|
|
115
|
+
export const DOMAIN_DEPOSIT = '03000000';
|
|
116
116
|
export const GENESIS_VALIDATOR_ROOT =
|
|
117
|
-
'0000000000000000000000000000000000000000000000000000000000000000'
|
|
117
|
+
'0000000000000000000000000000000000000000000000000000000000000000';
|
|
118
118
|
|
|
119
119
|
// Flow used to create definition
|
|
120
120
|
export enum DefinitionFlow {
|
|
@@ -123,10 +123,16 @@ export enum DefinitionFlow {
|
|
|
123
123
|
Charon = 'Charon-Command',
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
-
export const DEFAULT_BASE_URL = 'https://api.obol.tech'
|
|
127
|
-
export const
|
|
126
|
+
export const DEFAULT_BASE_URL = 'https://api.obol.tech';
|
|
127
|
+
export const DEFAULT_BASE_VERSION = 'v1';
|
|
128
|
+
export const DEFAULT_CHAIN_ID = 17000;
|
|
128
129
|
|
|
129
|
-
export const ETHER_TO_GWEI = 10 ** 9
|
|
130
|
+
export const ETHER_TO_GWEI = 10 ** 9;
|
|
130
131
|
|
|
131
|
-
export const TERMS_AND_CONDITIONS_VERSION = 1
|
|
132
|
-
export const TERMS_AND_CONDITIONS_URL =
|
|
132
|
+
export const TERMS_AND_CONDITIONS_VERSION = 1;
|
|
133
|
+
export const TERMS_AND_CONDITIONS_URL =
|
|
134
|
+
TERMS_AND_CONDITIONS_VERSION === 1
|
|
135
|
+
? 'https://obol.org/terms.pdf'
|
|
136
|
+
: `https://obol.org/${TERMS_AND_CONDITIONS_VERSION as number}/terms.pdf`;
|
|
137
|
+
export const TERMS_AND_CONDITIONS_HASH =
|
|
138
|
+
'0xd33721644e8f3afab1495a74abe3523cec12d48b8da6cb760972492ca3f1a273';
|
package/src/errors.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export class ConflictError extends Error {
|
|
2
|
-
name = 'ConflictError'
|
|
2
|
+
name = 'ConflictError';
|
|
3
3
|
|
|
4
|
-
constructor
|
|
5
|
-
super('This Cluster has been already posted.')
|
|
6
|
-
Object.setPrototypeOf(this, ConflictError.prototype)
|
|
4
|
+
constructor() {
|
|
5
|
+
super('This Cluster has been already posted.');
|
|
6
|
+
Object.setPrototypeOf(this, ConflictError.prototype);
|
|
7
7
|
}
|
|
8
8
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { type Signer } from 'ethers'
|
|
2
|
-
import { v4 as uuidv4 } from 'uuid'
|
|
3
|
-
import { Base } from './base.js'
|
|
1
|
+
import { type Signer } from 'ethers';
|
|
2
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
3
|
+
import { Base } from './base.js';
|
|
4
4
|
import {
|
|
5
5
|
CONFLICT_ERROR_MSG,
|
|
6
6
|
CreatorConfigHashSigningTypes,
|
|
@@ -11,26 +11,27 @@ import {
|
|
|
11
11
|
EnrSigningTypes,
|
|
12
12
|
TERMS_AND_CONDITIONS_VERSION,
|
|
13
13
|
TermsAndConditionsSigningTypes,
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
DEFAULT_BASE_VERSION,
|
|
15
|
+
TERMS_AND_CONDITIONS_HASH,
|
|
16
|
+
} from './constants.js';
|
|
17
|
+
import { ConflictError } from './errors.js';
|
|
16
18
|
import {
|
|
17
19
|
type ClusterDefinition,
|
|
18
20
|
type ClusterLock,
|
|
19
21
|
type ClusterPayload,
|
|
20
22
|
type OperatorPayload,
|
|
21
|
-
} from './types.js'
|
|
22
|
-
import { clusterConfigOrDefinitionHash } from './verification/common.js'
|
|
23
|
-
import { validatePayload } from './ajv.js'
|
|
24
|
-
import { definitionSchema, operatorPayloadSchema } from './schema.js'
|
|
25
|
-
|
|
26
|
-
export * from './
|
|
27
|
-
export * from './services.js'
|
|
23
|
+
} from './types.js';
|
|
24
|
+
import { clusterConfigOrDefinitionHash } from './verification/common.js';
|
|
25
|
+
import { validatePayload } from './ajv.js';
|
|
26
|
+
import { definitionSchema, operatorPayloadSchema } from './schema.js';
|
|
27
|
+
export * from './types.js';
|
|
28
|
+
export * from './services.js';
|
|
28
29
|
|
|
29
30
|
/**
|
|
30
31
|
* Obol sdk Client can be used for creating, managing and activating distributed validators.
|
|
31
32
|
*/
|
|
32
33
|
export class Client extends Base {
|
|
33
|
-
private readonly signer: Signer | undefined
|
|
34
|
+
private readonly signer: Signer | undefined;
|
|
34
35
|
|
|
35
36
|
/**
|
|
36
37
|
* @param config - Client configurations
|
|
@@ -42,31 +43,32 @@ export class Client extends Base {
|
|
|
42
43
|
* An example of how to instantiate obol-sdk Client:
|
|
43
44
|
* [obolClient](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts#L29)
|
|
44
45
|
*/
|
|
45
|
-
constructor
|
|
46
|
-
config
|
|
47
|
-
signer
|
|
48
|
-
) {
|
|
49
|
-
super(config)
|
|
50
|
-
this.signer = signer
|
|
46
|
+
constructor(config: { baseUrl?: string; chainId?: number }, signer?: Signer) {
|
|
47
|
+
super(config);
|
|
48
|
+
this.signer = signer;
|
|
51
49
|
}
|
|
52
50
|
|
|
53
51
|
/**
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
52
|
+
* Accepts Obol terms and conditions to be able to create or update data.
|
|
53
|
+
* @returns {Promise<string>} terms and conditions acceptance success message.
|
|
54
|
+
* @throws On unverified signature or wrong hash.
|
|
55
|
+
*
|
|
56
|
+
* An example of how to use acceptObolLatestTermsAndConditions:
|
|
57
|
+
* [acceptObolLatestTermsAndConditions](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts#L44)
|
|
58
|
+
*/
|
|
59
|
+
async acceptObolLatestTermsAndConditions(): Promise<string> {
|
|
60
|
+
if (!this.signer) {
|
|
61
|
+
throw new Error('Signer is required in acceptObolTermsAndConditions');
|
|
62
|
+
}
|
|
61
63
|
|
|
62
64
|
try {
|
|
63
|
-
const termsAndConditionsHash =
|
|
64
|
-
const address = await this.signer.getAddress()
|
|
65
|
+
const termsAndConditionsHash = TERMS_AND_CONDITIONS_HASH;
|
|
66
|
+
const address = await this.signer.getAddress();
|
|
65
67
|
const termsAndConditionsPayload = {
|
|
66
68
|
address,
|
|
67
69
|
version: TERMS_AND_CONDITIONS_VERSION,
|
|
68
|
-
terms_and_conditions_hash: termsAndConditionsHash
|
|
69
|
-
}
|
|
70
|
+
terms_and_conditions_hash: termsAndConditionsHash,
|
|
71
|
+
};
|
|
70
72
|
|
|
71
73
|
const termsAndConditionsSignature = await this.signer.signTypedData(
|
|
72
74
|
Domain(),
|
|
@@ -75,21 +77,22 @@ export class Client extends Base {
|
|
|
75
77
|
terms_and_conditions_hash: termsAndConditionsHash,
|
|
76
78
|
version: TERMS_AND_CONDITIONS_VERSION,
|
|
77
79
|
},
|
|
78
|
-
)
|
|
80
|
+
);
|
|
79
81
|
|
|
80
|
-
const termsAndConditionsResponse: { message: string
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
82
|
+
const termsAndConditionsResponse: { message: string; success: boolean } =
|
|
83
|
+
await this.request(`/${DEFAULT_BASE_VERSION}/termsAndConditions`, {
|
|
84
|
+
method: 'POST',
|
|
85
|
+
body: JSON.stringify(termsAndConditionsPayload),
|
|
86
|
+
headers: {
|
|
87
|
+
Authorization: `Bearer ${termsAndConditionsSignature}`,
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
return termsAndConditionsResponse?.message;
|
|
88
91
|
} catch (err: any) {
|
|
89
92
|
if (err?.message === CONFLICT_ERROR_MSG) {
|
|
90
|
-
throw new ConflictError()
|
|
93
|
+
throw new ConflictError();
|
|
91
94
|
}
|
|
92
|
-
throw err
|
|
95
|
+
throw err;
|
|
93
96
|
}
|
|
94
97
|
}
|
|
95
98
|
|
|
@@ -100,12 +103,14 @@ export class Client extends Base {
|
|
|
100
103
|
* @throws On duplicate entries, missing or wrong cluster keys.
|
|
101
104
|
*
|
|
102
105
|
* An example of how to use createClusterDefinition:
|
|
103
|
-
* [createObolCluster](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts)
|
|
106
|
+
* [createObolCluster](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts#L59)
|
|
104
107
|
*/
|
|
105
|
-
async createClusterDefinition
|
|
106
|
-
if (!this.signer) {
|
|
108
|
+
async createClusterDefinition(newCluster: ClusterPayload): Promise<string> {
|
|
109
|
+
if (!this.signer) {
|
|
110
|
+
throw new Error('Signer is required in createClusterDefinition');
|
|
111
|
+
}
|
|
107
112
|
|
|
108
|
-
validatePayload(newCluster, definitionSchema)
|
|
113
|
+
validatePayload(newCluster, definitionSchema);
|
|
109
114
|
|
|
110
115
|
const clusterConfig: Partial<ClusterDefinition> = {
|
|
111
116
|
...newCluster,
|
|
@@ -116,37 +121,42 @@ export class Client extends Base {
|
|
|
116
121
|
timestamp: new Date().toISOString(),
|
|
117
122
|
threshold: Math.ceil((2 * newCluster.operators.length) / 3),
|
|
118
123
|
num_validators: newCluster.validators.length,
|
|
119
|
-
|
|
120
|
-
|
|
124
|
+
deposit_amounts: newCluster.deposit_amounts
|
|
125
|
+
? newCluster.deposit_amounts
|
|
126
|
+
: ['32000000000'],
|
|
127
|
+
};
|
|
121
128
|
try {
|
|
122
|
-
const address = await this.signer.getAddress()
|
|
129
|
+
const address = await this.signer.getAddress();
|
|
123
130
|
|
|
124
|
-
clusterConfig.creator = { address }
|
|
131
|
+
clusterConfig.creator = { address };
|
|
125
132
|
clusterConfig.config_hash = clusterConfigOrDefinitionHash(
|
|
126
133
|
clusterConfig as ClusterDefinition,
|
|
127
134
|
true,
|
|
128
|
-
)
|
|
135
|
+
);
|
|
129
136
|
|
|
130
137
|
const creatorConfigSignature = await this.signer.signTypedData(
|
|
131
138
|
Domain(this.chainId),
|
|
132
139
|
CreatorConfigHashSigningTypes,
|
|
133
140
|
{ creator_config_hash: clusterConfig.config_hash },
|
|
134
|
-
)
|
|
135
|
-
|
|
136
|
-
const clusterDefinition: ClusterDefinition = await this.request(
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
const clusterDefinition: ClusterDefinition = await this.request(
|
|
144
|
+
`/${DEFAULT_BASE_VERSION}/definition`,
|
|
145
|
+
{
|
|
146
|
+
method: 'POST',
|
|
147
|
+
body: JSON.stringify(clusterConfig),
|
|
148
|
+
headers: {
|
|
149
|
+
Authorization: `Bearer ${creatorConfigSignature}`,
|
|
150
|
+
'fork-version': this.fork_version,
|
|
151
|
+
},
|
|
142
152
|
},
|
|
143
|
-
|
|
144
|
-
return clusterDefinition?.config_hash
|
|
153
|
+
);
|
|
154
|
+
return clusterDefinition?.config_hash;
|
|
145
155
|
} catch (err: any) {
|
|
146
156
|
if (err?.message === CONFLICT_ERROR_MSG) {
|
|
147
|
-
throw new ConflictError()
|
|
157
|
+
throw new ConflictError();
|
|
148
158
|
}
|
|
149
|
-
throw err
|
|
159
|
+
throw err;
|
|
150
160
|
}
|
|
151
161
|
}
|
|
152
162
|
|
|
@@ -158,38 +168,40 @@ export class Client extends Base {
|
|
|
158
168
|
* @throws On unauthorized, duplicate entries, missing keys, not found cluster or invalid data.
|
|
159
169
|
*
|
|
160
170
|
* An example of how to use acceptClusterDefinition:
|
|
161
|
-
* [acceptClusterDefinition](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts)
|
|
171
|
+
* [acceptClusterDefinition](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts#L106)
|
|
162
172
|
*/
|
|
163
|
-
async acceptClusterDefinition
|
|
173
|
+
async acceptClusterDefinition(
|
|
164
174
|
operatorPayload: OperatorPayload,
|
|
165
175
|
configHash: string,
|
|
166
176
|
): Promise<ClusterDefinition> {
|
|
167
|
-
if (!this.signer) {
|
|
177
|
+
if (!this.signer) {
|
|
178
|
+
throw new Error('Signer is required in acceptClusterDefinition');
|
|
179
|
+
}
|
|
168
180
|
|
|
169
|
-
validatePayload(operatorPayload, operatorPayloadSchema)
|
|
181
|
+
validatePayload(operatorPayload, operatorPayloadSchema);
|
|
170
182
|
|
|
171
183
|
try {
|
|
172
|
-
const address = await this.signer.getAddress()
|
|
184
|
+
const address = await this.signer.getAddress();
|
|
173
185
|
|
|
174
186
|
const operatorConfigSignature = await this.signer.signTypedData(
|
|
175
187
|
Domain(this.chainId),
|
|
176
188
|
OperatorConfigHashSigningTypes,
|
|
177
189
|
{ operator_config_hash: configHash },
|
|
178
|
-
)
|
|
190
|
+
);
|
|
179
191
|
const operatorENRSignature = await this.signer.signTypedData(
|
|
180
192
|
Domain(this.chainId),
|
|
181
193
|
EnrSigningTypes,
|
|
182
194
|
{ enr: operatorPayload.enr },
|
|
183
|
-
)
|
|
195
|
+
);
|
|
184
196
|
|
|
185
197
|
const operatorData: OperatorPayload = {
|
|
186
198
|
...operatorPayload,
|
|
187
199
|
address,
|
|
188
200
|
enr_signature: operatorENRSignature,
|
|
189
201
|
fork_version: this.fork_version,
|
|
190
|
-
}
|
|
202
|
+
};
|
|
191
203
|
const clusterDefinition: ClusterDefinition = await this.request(
|
|
192
|
-
|
|
204
|
+
`/${DEFAULT_BASE_VERSION}/definition/${configHash}`,
|
|
193
205
|
{
|
|
194
206
|
method: 'PUT',
|
|
195
207
|
body: JSON.stringify(operatorData),
|
|
@@ -197,10 +209,10 @@ export class Client extends Base {
|
|
|
197
209
|
Authorization: `Bearer ${operatorConfigSignature}`,
|
|
198
210
|
},
|
|
199
211
|
},
|
|
200
|
-
)
|
|
201
|
-
return clusterDefinition
|
|
212
|
+
);
|
|
213
|
+
return clusterDefinition;
|
|
202
214
|
} catch (err: any) {
|
|
203
|
-
throw err
|
|
215
|
+
throw err;
|
|
204
216
|
}
|
|
205
217
|
}
|
|
206
218
|
|
|
@@ -210,17 +222,17 @@ export class Client extends Base {
|
|
|
210
222
|
* @throws On not found config hash.
|
|
211
223
|
*
|
|
212
224
|
* An example of how to use getClusterDefinition:
|
|
213
|
-
* [getObolClusterDefinition](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts)
|
|
225
|
+
* [getObolClusterDefinition](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts#L74)
|
|
214
226
|
*/
|
|
215
|
-
async getClusterDefinition
|
|
227
|
+
async getClusterDefinition(configHash: string): Promise<ClusterDefinition> {
|
|
216
228
|
const clusterDefinition: ClusterDefinition = await this.request(
|
|
217
|
-
|
|
229
|
+
`/${DEFAULT_BASE_VERSION}/definition/${configHash}`,
|
|
218
230
|
{
|
|
219
231
|
method: 'GET',
|
|
220
232
|
},
|
|
221
|
-
)
|
|
233
|
+
);
|
|
222
234
|
|
|
223
|
-
return clusterDefinition
|
|
235
|
+
return clusterDefinition;
|
|
224
236
|
}
|
|
225
237
|
|
|
226
238
|
/**
|
|
@@ -229,15 +241,15 @@ export class Client extends Base {
|
|
|
229
241
|
* @throws On not found cluster definition or lock.
|
|
230
242
|
*
|
|
231
243
|
* An example of how to use getClusterLock:
|
|
232
|
-
* [getObolClusterLock](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts)
|
|
244
|
+
* [getObolClusterLock](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts#L89)
|
|
233
245
|
*/
|
|
234
|
-
async getClusterLock
|
|
246
|
+
async getClusterLock(configHash: string): Promise<ClusterLock> {
|
|
235
247
|
const lock: ClusterLock = await this.request(
|
|
236
|
-
|
|
248
|
+
`/${DEFAULT_BASE_VERSION}/lock/configHash/${configHash}`,
|
|
237
249
|
{
|
|
238
250
|
method: 'GET',
|
|
239
251
|
},
|
|
240
|
-
)
|
|
241
|
-
return lock
|
|
252
|
+
);
|
|
253
|
+
return lock;
|
|
242
254
|
}
|
|
243
255
|
}
|
package/src/schema.ts
CHANGED
|
@@ -9,7 +9,7 @@ export const operatorPayloadSchema = {
|
|
|
9
9
|
},
|
|
10
10
|
},
|
|
11
11
|
required: ['version', 'enr'],
|
|
12
|
-
}
|
|
12
|
+
};
|
|
13
13
|
|
|
14
14
|
export const definitionSchema = {
|
|
15
15
|
type: 'object',
|
|
@@ -53,6 +53,14 @@ export const definitionSchema = {
|
|
|
53
53
|
required: ['fee_recipient_address', 'withdrawal_address'],
|
|
54
54
|
},
|
|
55
55
|
},
|
|
56
|
+
deposit_amounts: {
|
|
57
|
+
type: 'array',
|
|
58
|
+
items: {
|
|
59
|
+
type: 'string',
|
|
60
|
+
pattern: '^[0-9]+$',
|
|
61
|
+
},
|
|
62
|
+
validDepositAmounts: true,
|
|
63
|
+
},
|
|
56
64
|
},
|
|
57
65
|
required: ['name', 'operators', 'validators'],
|
|
58
|
-
}
|
|
66
|
+
};
|
package/src/services.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type ClusterLock } from './types.js'
|
|
2
|
-
import { isValidClusterLock } from './verification/common.js'
|
|
1
|
+
import { type ClusterLock } from './types.js';
|
|
2
|
+
import { isValidClusterLock } from './verification/common.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Verifies Cluster Lock's validity.
|
|
@@ -8,15 +8,15 @@ import { isValidClusterLock } from './verification/common.js'
|
|
|
8
8
|
* @throws on missing keys or values.
|
|
9
9
|
*
|
|
10
10
|
* An example of how to use validateClusterLock:
|
|
11
|
-
* [validateClusterLock](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts)
|
|
11
|
+
* [validateClusterLock](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts#L127)
|
|
12
12
|
*/
|
|
13
13
|
export const validateClusterLock = async (
|
|
14
14
|
lock: ClusterLock,
|
|
15
15
|
): Promise<boolean> => {
|
|
16
16
|
try {
|
|
17
|
-
const isLockValid = await isValidClusterLock(lock)
|
|
18
|
-
return isLockValid
|
|
17
|
+
const isLockValid = await isValidClusterLock(lock);
|
|
18
|
+
return isLockValid;
|
|
19
19
|
} catch (err: any) {
|
|
20
|
-
throw err
|
|
20
|
+
throw err;
|
|
21
21
|
}
|
|
22
|
-
}
|
|
22
|
+
};
|