@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/README.md
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-

|
|
2
2
|
|
|
3
3
|
<h1 align="center">Obol SDK</h1>
|
|
4
4
|
|
|
5
|
-
This repo contains the Obol Software Development Kit, for creating Distributed Validators with the help of the [Obol API](https://docs.obol.
|
|
5
|
+
This repo contains the Obol Software Development Kit, for creating Distributed Validators with the help of the [Obol API](https://docs.obol.org/api).
|
|
6
6
|
|
|
7
7
|
## Getting Started
|
|
8
8
|
|
|
9
|
-
Checkout our [docs](https://docs.obol.
|
|
9
|
+
Checkout our [docs](https://docs.obol.org/docs/advanced/quickstart-sdk), [examples](https://github.com/ObolNetwork/obol-sdk-examples/), and SDK [reference](https://obolnetwork.github.io/obol-sdk). Further guides and walkthroughs coming soon.
|
|
10
|
+
|
|
11
|
+
## Terms and Conditions
|
|
12
|
+
To use obol-sdk and in order to be able to create a cluster definition or accept an invite to join a cluster, you must accept the [latest Obol terms and conditions](https://obol.org/terms.pdf) by calling acceptObolLatestTermsAndConditions.
|
|
10
13
|
|
|
11
14
|
## Contributing
|
|
12
15
|
|
package/dist/cjs/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@obolnetwork/obol-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.17",
|
|
4
4
|
"description": "A package for creating Distributed Validators using the Obol API.",
|
|
5
5
|
"bugs": {
|
|
6
6
|
"url": "https://github.com/obolnetwork/obol-sdk/issues"
|
|
7
7
|
},
|
|
8
|
-
"homepage": "https://docs.obol.
|
|
8
|
+
"homepage": "https://docs.obol.org/",
|
|
9
9
|
"keywords": [
|
|
10
10
|
"Obol",
|
|
11
11
|
"Distributed Validators",
|
|
@@ -20,13 +20,15 @@
|
|
|
20
20
|
"npm:publish": "npm publish --tag latest",
|
|
21
21
|
"release": "release-it",
|
|
22
22
|
"release:dry": "release-it --dry-run --no-npm",
|
|
23
|
-
"lint": "eslint \"{src,
|
|
24
|
-
"lint-ci": "eslint \"{src,
|
|
23
|
+
"lint": "eslint \"{src,test}/**/*.{js,ts}\" --fix",
|
|
24
|
+
"lint-ci": "eslint \"{src,test}/**/*.{js,ts}\"",
|
|
25
|
+
"prettier-ci": "prettier --check \"{src,test}/**/*.{js,ts}\"",
|
|
26
|
+
"prettier": "prettier --write \"{src,test}/**/*.{js,ts}\""
|
|
25
27
|
},
|
|
26
28
|
"main": "./dist/cjs/src/index.js",
|
|
27
29
|
"module": "./dist/esm/src/index.js",
|
|
28
30
|
"typings": "./dist/types/src/index.d.ts",
|
|
29
|
-
"author": "Obol Labs (https://obol.
|
|
31
|
+
"author": "Obol Labs (https://obol.org)",
|
|
30
32
|
"repository": {
|
|
31
33
|
"type": "git",
|
|
32
34
|
"url": "git+https://github.com/obolnetwork/obol-sdk.git"
|
|
@@ -65,15 +67,18 @@
|
|
|
65
67
|
"@types/semver": "^7.5.8",
|
|
66
68
|
"@types/uuid": "^9.0.1",
|
|
67
69
|
"eslint": "^8.57.0",
|
|
70
|
+
"husky": "^9.0.11",
|
|
68
71
|
"jest": "^28.1.3",
|
|
72
|
+
"lint-staged": "^15.2.2",
|
|
69
73
|
"msw": "^2.2.1",
|
|
70
74
|
"npm-run-all": "^4.1.5",
|
|
75
|
+
"prettier": "^3.2.5",
|
|
71
76
|
"release-it": "^17.2.1",
|
|
72
77
|
"ts-jest": "^28.0.8",
|
|
73
78
|
"tsup": "^6.7.0",
|
|
74
79
|
"typedoc": "^0.25.7",
|
|
75
80
|
"typedoc-plugin-markdown": "^4.0.0-next.50",
|
|
76
|
-
"typescript": "
|
|
81
|
+
"typescript": "~5.3.3"
|
|
77
82
|
},
|
|
78
83
|
"engines": {
|
|
79
84
|
"node": ">= 16"
|
package/dist/cjs/src/ajv.js
CHANGED
|
@@ -5,9 +5,36 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.validatePayload = void 0;
|
|
7
7
|
const ajv_1 = __importDefault(require("ajv"));
|
|
8
|
+
const ethers_1 = require("ethers");
|
|
9
|
+
function validDepositAmounts(data, deposits) {
|
|
10
|
+
let sum = 0;
|
|
11
|
+
// from ether togwei is same as from gwei to wei
|
|
12
|
+
const maxDeposit = Number((0, ethers_1.parseUnits)('32', 'gwei'));
|
|
13
|
+
const minDeposit = Number((0, ethers_1.parseUnits)('1', 'gwei'));
|
|
14
|
+
for (const element of deposits) {
|
|
15
|
+
const amountInGWei = Number(element);
|
|
16
|
+
if (!Number.isInteger(amountInGWei) ||
|
|
17
|
+
amountInGWei > maxDeposit ||
|
|
18
|
+
amountInGWei < minDeposit) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
sum += amountInGWei;
|
|
22
|
+
}
|
|
23
|
+
if (sum / minDeposit !== 32) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
8
30
|
function validatePayload(data, schema) {
|
|
9
31
|
var _a;
|
|
10
32
|
const ajv = new ajv_1.default();
|
|
33
|
+
ajv.addKeyword({
|
|
34
|
+
keyword: 'validDepositAmounts',
|
|
35
|
+
validate: validDepositAmounts,
|
|
36
|
+
errors: true,
|
|
37
|
+
});
|
|
11
38
|
const validate = ajv.compile(schema);
|
|
12
39
|
const isValid = validate(data);
|
|
13
40
|
if (!isValid) {
|
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.TERMS_AND_CONDITIONS_URL = exports.TERMS_AND_CONDITIONS_VERSION = exports.ETHER_TO_GWEI = exports.DEFAULT_CHAIN_ID = exports.DEFAULT_BASE_URL = exports.DefinitionFlow = exports.GENESIS_VALIDATOR_ROOT = exports.DOMAIN_DEPOSIT = exports.DOMAIN_APPLICATION_BUILDER = exports.SDK_VERSION = exports.CONFIG_VERSION = exports.DKG_ALGORITHM = exports.signEnrPayload = exports.signOperatorConfigHashPayload = exports.signCreatorConfigHashPayload = exports.ENRTypedMessage = exports.OperatorTypedMessage = exports.OperatorConfigHashSigningTypes = exports.EnrSigningTypes = exports.CreatorTypedMessage = exports.Domain = exports.TermsAndConditionsSigningTypes = exports.CreatorConfigHashSigningTypes = exports.EIP712_DOMAIN_VERSION = exports.EIP712_DOMAIN_NAME = exports.CONFLICT_ERROR_MSG = void 0;
|
|
26
|
+
exports.TERMS_AND_CONDITIONS_HASH = exports.TERMS_AND_CONDITIONS_URL = exports.TERMS_AND_CONDITIONS_VERSION = exports.ETHER_TO_GWEI = exports.DEFAULT_CHAIN_ID = exports.DEFAULT_BASE_VERSION = exports.DEFAULT_BASE_URL = exports.DefinitionFlow = exports.GENESIS_VALIDATOR_ROOT = exports.DOMAIN_DEPOSIT = exports.DOMAIN_APPLICATION_BUILDER = exports.SDK_VERSION = exports.CONFIG_VERSION = exports.DKG_ALGORITHM = exports.signEnrPayload = exports.signOperatorConfigHashPayload = exports.signCreatorConfigHashPayload = exports.ENRTypedMessage = exports.OperatorTypedMessage = exports.OperatorConfigHashSigningTypes = exports.EnrSigningTypes = exports.CreatorTypedMessage = exports.Domain = exports.TermsAndConditionsSigningTypes = exports.CreatorConfigHashSigningTypes = exports.EIP712_DOMAIN_VERSION = exports.EIP712_DOMAIN_NAME = exports.CONFLICT_ERROR_MSG = void 0;
|
|
27
27
|
const pjson = __importStar(require("../package.json"));
|
|
28
28
|
exports.CONFLICT_ERROR_MSG = 'Conflict';
|
|
29
29
|
exports.EIP712_DOMAIN_NAME = 'Obol';
|
|
@@ -35,7 +35,7 @@ exports.TermsAndConditionsSigningTypes = {
|
|
|
35
35
|
TermsAndConditions: [
|
|
36
36
|
{ name: 'terms_and_conditions_hash', type: 'string' },
|
|
37
37
|
{ name: 'version', type: 'uint256' },
|
|
38
|
-
]
|
|
38
|
+
],
|
|
39
39
|
};
|
|
40
40
|
const EIP712Domain = [
|
|
41
41
|
{ name: 'name', type: 'string' },
|
|
@@ -103,7 +103,7 @@ const signEnrPayload = (payload, chainId) => {
|
|
|
103
103
|
};
|
|
104
104
|
exports.signEnrPayload = signEnrPayload;
|
|
105
105
|
exports.DKG_ALGORITHM = 'default';
|
|
106
|
-
exports.CONFIG_VERSION = 'v1.
|
|
106
|
+
exports.CONFIG_VERSION = 'v1.8.0';
|
|
107
107
|
exports.SDK_VERSION = pjson.version;
|
|
108
108
|
exports.DOMAIN_APPLICATION_BUILDER = '00000001';
|
|
109
109
|
exports.DOMAIN_DEPOSIT = '03000000';
|
|
@@ -116,7 +116,11 @@ var DefinitionFlow;
|
|
|
116
116
|
DefinitionFlow["Charon"] = "Charon-Command";
|
|
117
117
|
})(DefinitionFlow || (exports.DefinitionFlow = DefinitionFlow = {}));
|
|
118
118
|
exports.DEFAULT_BASE_URL = 'https://api.obol.tech';
|
|
119
|
+
exports.DEFAULT_BASE_VERSION = 'v1';
|
|
119
120
|
exports.DEFAULT_CHAIN_ID = 17000;
|
|
120
121
|
exports.ETHER_TO_GWEI = 10 ** 9;
|
|
121
122
|
exports.TERMS_AND_CONDITIONS_VERSION = 1;
|
|
122
|
-
exports.TERMS_AND_CONDITIONS_URL =
|
|
123
|
+
exports.TERMS_AND_CONDITIONS_URL = exports.TERMS_AND_CONDITIONS_VERSION === 1
|
|
124
|
+
? 'https://obol.org/terms.pdf'
|
|
125
|
+
: `https://obol.org/${exports.TERMS_AND_CONDITIONS_VERSION}/terms.pdf`;
|
|
126
|
+
exports.TERMS_AND_CONDITIONS_HASH = '0xd33721644e8f3afab1495a74abe3523cec12d48b8da6cb760972492ca3f1a273';
|
package/dist/cjs/src/index.js
CHANGED
|
@@ -31,7 +31,6 @@ const errors_js_1 = require("./errors.js");
|
|
|
31
31
|
const common_js_1 = require("./verification/common.js");
|
|
32
32
|
const ajv_js_1 = require("./ajv.js");
|
|
33
33
|
const schema_js_1 = require("./schema.js");
|
|
34
|
-
const termsAndConditions_js_1 = require("./verification/termsAndConditions.js");
|
|
35
34
|
__exportStar(require("./types.js"), exports);
|
|
36
35
|
__exportStar(require("./services.js"), exports);
|
|
37
36
|
/**
|
|
@@ -53,29 +52,31 @@ class Client extends base_js_1.Base {
|
|
|
53
52
|
this.signer = signer;
|
|
54
53
|
}
|
|
55
54
|
/**
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
55
|
+
* Accepts Obol terms and conditions to be able to create or update data.
|
|
56
|
+
* @returns {Promise<string>} terms and conditions acceptance success message.
|
|
57
|
+
* @throws On unverified signature or wrong hash.
|
|
58
|
+
*
|
|
59
|
+
* An example of how to use acceptObolLatestTermsAndConditions:
|
|
60
|
+
* [acceptObolLatestTermsAndConditions](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts#L44)
|
|
61
|
+
*/
|
|
61
62
|
acceptObolLatestTermsAndConditions() {
|
|
62
63
|
return __awaiter(this, void 0, void 0, function* () {
|
|
63
64
|
if (!this.signer) {
|
|
64
65
|
throw new Error('Signer is required in acceptObolTermsAndConditions');
|
|
65
66
|
}
|
|
66
67
|
try {
|
|
67
|
-
const termsAndConditionsHash =
|
|
68
|
+
const termsAndConditionsHash = constants_js_1.TERMS_AND_CONDITIONS_HASH;
|
|
68
69
|
const address = yield this.signer.getAddress();
|
|
69
70
|
const termsAndConditionsPayload = {
|
|
70
71
|
address,
|
|
71
72
|
version: constants_js_1.TERMS_AND_CONDITIONS_VERSION,
|
|
72
|
-
terms_and_conditions_hash: termsAndConditionsHash
|
|
73
|
+
terms_and_conditions_hash: termsAndConditionsHash,
|
|
73
74
|
};
|
|
74
75
|
const termsAndConditionsSignature = yield this.signer.signTypedData((0, constants_js_1.Domain)(), constants_js_1.TermsAndConditionsSigningTypes, {
|
|
75
76
|
terms_and_conditions_hash: termsAndConditionsHash,
|
|
76
77
|
version: constants_js_1.TERMS_AND_CONDITIONS_VERSION,
|
|
77
78
|
});
|
|
78
|
-
const termsAndConditionsResponse = yield this.request(
|
|
79
|
+
const termsAndConditionsResponse = yield this.request(`/${constants_js_1.DEFAULT_BASE_VERSION}/termsAndConditions`, {
|
|
79
80
|
method: 'POST',
|
|
80
81
|
body: JSON.stringify(termsAndConditionsPayload),
|
|
81
82
|
headers: {
|
|
@@ -99,7 +100,7 @@ class Client extends base_js_1.Base {
|
|
|
99
100
|
* @throws On duplicate entries, missing or wrong cluster keys.
|
|
100
101
|
*
|
|
101
102
|
* An example of how to use createClusterDefinition:
|
|
102
|
-
* [createObolCluster](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts)
|
|
103
|
+
* [createObolCluster](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts#L59)
|
|
103
104
|
*/
|
|
104
105
|
createClusterDefinition(newCluster) {
|
|
105
106
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -107,13 +108,15 @@ class Client extends base_js_1.Base {
|
|
|
107
108
|
throw new Error('Signer is required in createClusterDefinition');
|
|
108
109
|
}
|
|
109
110
|
(0, ajv_js_1.validatePayload)(newCluster, schema_js_1.definitionSchema);
|
|
110
|
-
const clusterConfig = Object.assign(Object.assign({}, newCluster), { fork_version: this.fork_version, dkg_algorithm: constants_js_1.DKG_ALGORITHM, version: constants_js_1.CONFIG_VERSION, uuid: (0, uuid_1.v4)(), timestamp: new Date().toISOString(), threshold: Math.ceil((2 * newCluster.operators.length) / 3), num_validators: newCluster.validators.length
|
|
111
|
+
const clusterConfig = Object.assign(Object.assign({}, newCluster), { fork_version: this.fork_version, dkg_algorithm: constants_js_1.DKG_ALGORITHM, version: constants_js_1.CONFIG_VERSION, uuid: (0, uuid_1.v4)(), timestamp: new Date().toISOString(), threshold: Math.ceil((2 * newCluster.operators.length) / 3), num_validators: newCluster.validators.length, deposit_amounts: newCluster.deposit_amounts
|
|
112
|
+
? newCluster.deposit_amounts
|
|
113
|
+
: ['32000000000'] });
|
|
111
114
|
try {
|
|
112
115
|
const address = yield this.signer.getAddress();
|
|
113
116
|
clusterConfig.creator = { address };
|
|
114
117
|
clusterConfig.config_hash = (0, common_js_1.clusterConfigOrDefinitionHash)(clusterConfig, true);
|
|
115
118
|
const creatorConfigSignature = yield this.signer.signTypedData((0, constants_js_1.Domain)(this.chainId), constants_js_1.CreatorConfigHashSigningTypes, { creator_config_hash: clusterConfig.config_hash });
|
|
116
|
-
const clusterDefinition = yield this.request(
|
|
119
|
+
const clusterDefinition = yield this.request(`/${constants_js_1.DEFAULT_BASE_VERSION}/definition`, {
|
|
117
120
|
method: 'POST',
|
|
118
121
|
body: JSON.stringify(clusterConfig),
|
|
119
122
|
headers: {
|
|
@@ -139,7 +142,7 @@ class Client extends base_js_1.Base {
|
|
|
139
142
|
* @throws On unauthorized, duplicate entries, missing keys, not found cluster or invalid data.
|
|
140
143
|
*
|
|
141
144
|
* An example of how to use acceptClusterDefinition:
|
|
142
|
-
* [acceptClusterDefinition](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts)
|
|
145
|
+
* [acceptClusterDefinition](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts#L106)
|
|
143
146
|
*/
|
|
144
147
|
acceptClusterDefinition(operatorPayload, configHash) {
|
|
145
148
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -152,7 +155,7 @@ class Client extends base_js_1.Base {
|
|
|
152
155
|
const operatorConfigSignature = yield this.signer.signTypedData((0, constants_js_1.Domain)(this.chainId), constants_js_1.OperatorConfigHashSigningTypes, { operator_config_hash: configHash });
|
|
153
156
|
const operatorENRSignature = yield this.signer.signTypedData((0, constants_js_1.Domain)(this.chainId), constants_js_1.EnrSigningTypes, { enr: operatorPayload.enr });
|
|
154
157
|
const operatorData = Object.assign(Object.assign({}, operatorPayload), { address, enr_signature: operatorENRSignature, fork_version: this.fork_version });
|
|
155
|
-
const clusterDefinition = yield this.request(
|
|
158
|
+
const clusterDefinition = yield this.request(`/${constants_js_1.DEFAULT_BASE_VERSION}/definition/${configHash}`, {
|
|
156
159
|
method: 'PUT',
|
|
157
160
|
body: JSON.stringify(operatorData),
|
|
158
161
|
headers: {
|
|
@@ -172,11 +175,11 @@ class Client extends base_js_1.Base {
|
|
|
172
175
|
* @throws On not found config hash.
|
|
173
176
|
*
|
|
174
177
|
* An example of how to use getClusterDefinition:
|
|
175
|
-
* [getObolClusterDefinition](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts)
|
|
178
|
+
* [getObolClusterDefinition](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts#L74)
|
|
176
179
|
*/
|
|
177
180
|
getClusterDefinition(configHash) {
|
|
178
181
|
return __awaiter(this, void 0, void 0, function* () {
|
|
179
|
-
const clusterDefinition = yield this.request(
|
|
182
|
+
const clusterDefinition = yield this.request(`/${constants_js_1.DEFAULT_BASE_VERSION}/definition/${configHash}`, {
|
|
180
183
|
method: 'GET',
|
|
181
184
|
});
|
|
182
185
|
return clusterDefinition;
|
|
@@ -188,11 +191,11 @@ class Client extends base_js_1.Base {
|
|
|
188
191
|
* @throws On not found cluster definition or lock.
|
|
189
192
|
*
|
|
190
193
|
* An example of how to use getClusterLock:
|
|
191
|
-
* [getObolClusterLock](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts)
|
|
194
|
+
* [getObolClusterLock](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts#L89)
|
|
192
195
|
*/
|
|
193
196
|
getClusterLock(configHash) {
|
|
194
197
|
return __awaiter(this, void 0, void 0, function* () {
|
|
195
|
-
const lock = yield this.request(
|
|
198
|
+
const lock = yield this.request(`/${constants_js_1.DEFAULT_BASE_VERSION}/lock/configHash/${configHash}`, {
|
|
196
199
|
method: 'GET',
|
|
197
200
|
});
|
|
198
201
|
return lock;
|
package/dist/cjs/src/schema.js
CHANGED
|
@@ -55,6 +55,14 @@ exports.definitionSchema = {
|
|
|
55
55
|
required: ['fee_recipient_address', 'withdrawal_address'],
|
|
56
56
|
},
|
|
57
57
|
},
|
|
58
|
+
deposit_amounts: {
|
|
59
|
+
type: 'array',
|
|
60
|
+
items: {
|
|
61
|
+
type: 'string',
|
|
62
|
+
pattern: '^[0-9]+$',
|
|
63
|
+
},
|
|
64
|
+
validDepositAmounts: true,
|
|
65
|
+
},
|
|
58
66
|
},
|
|
59
67
|
required: ['name', 'operators', 'validators'],
|
|
60
68
|
};
|
package/dist/cjs/src/services.js
CHANGED
|
@@ -18,7 +18,7 @@ const common_js_1 = require("./verification/common.js");
|
|
|
18
18
|
* @throws on missing keys or values.
|
|
19
19
|
*
|
|
20
20
|
* An example of how to use validateClusterLock:
|
|
21
|
-
* [validateClusterLock](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts)
|
|
21
|
+
* [validateClusterLock](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts#L127)
|
|
22
22
|
*/
|
|
23
23
|
const validateClusterLock = (lock) => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
24
|
try {
|
package/dist/cjs/src/utils.js
CHANGED
|
@@ -13,7 +13,7 @@ exports.strToUint8Array = strToUint8Array;
|
|
|
13
13
|
const definitionFlow = (clusterDefinition) => {
|
|
14
14
|
if (clusterDefinition.creator.address &&
|
|
15
15
|
clusterDefinition.creator.config_signature &&
|
|
16
|
-
clusterDefinition.operators.every(
|
|
16
|
+
clusterDefinition.operators.every(operator => {
|
|
17
17
|
return (operator.address &&
|
|
18
18
|
operator.config_signature &&
|
|
19
19
|
operator.enr &&
|
|
@@ -23,7 +23,7 @@ const definitionFlow = (clusterDefinition) => {
|
|
|
23
23
|
}
|
|
24
24
|
else if (clusterDefinition.creator.address &&
|
|
25
25
|
clusterDefinition.creator.config_signature &&
|
|
26
|
-
clusterDefinition.operators.every(
|
|
26
|
+
clusterDefinition.operators.every(operator => {
|
|
27
27
|
return (!operator.address &&
|
|
28
28
|
!operator.config_signature &&
|
|
29
29
|
operator.enr &&
|
|
@@ -33,7 +33,7 @@ const definitionFlow = (clusterDefinition) => {
|
|
|
33
33
|
}
|
|
34
34
|
else if (!clusterDefinition.creator.address &&
|
|
35
35
|
!clusterDefinition.creator.config_signature &&
|
|
36
|
-
clusterDefinition.operators.every(
|
|
36
|
+
clusterDefinition.operators.every(operator => {
|
|
37
37
|
return (!operator.address &&
|
|
38
38
|
!operator.config_signature &&
|
|
39
39
|
operator.enr &&
|
|
@@ -61,17 +61,20 @@ const clusterConfigOrDefinitionHash = (cluster, configOnly) => {
|
|
|
61
61
|
if (semver.eq(cluster.version, 'v1.6.0')) {
|
|
62
62
|
definitionType = (0, v1_6_0_js_1.clusterDefinitionContainerTypeV1X6)(configOnly);
|
|
63
63
|
val = (0, v1_6_0_js_1.hashClusterDefinitionV1X6)(cluster, configOnly);
|
|
64
|
-
return ('0x' +
|
|
64
|
+
return ('0x' +
|
|
65
|
+
Buffer.from(definitionType.hashTreeRoot(val).buffer).toString('hex'));
|
|
65
66
|
}
|
|
66
67
|
if (semver.eq(cluster.version, 'v1.7.0')) {
|
|
67
68
|
definitionType = (0, v1_7_0_js_1.clusterDefinitionContainerTypeV1X7)(configOnly);
|
|
68
69
|
val = (0, v1_7_0_js_1.hashClusterDefinitionV1X7)(cluster, configOnly);
|
|
69
|
-
return ('0x' +
|
|
70
|
+
return ('0x' +
|
|
71
|
+
Buffer.from(definitionType.hashTreeRoot(val).buffer).toString('hex'));
|
|
70
72
|
}
|
|
71
73
|
if (semver.eq(cluster.version, 'v1.8.0')) {
|
|
72
74
|
definitionType = (0, v1_8_0_js_1.clusterDefinitionContainerTypeV1X8)(configOnly);
|
|
73
75
|
val = (0, v1_8_0_js_1.hashClusterDefinitionV1X8)(cluster, configOnly);
|
|
74
|
-
return ('0x' +
|
|
76
|
+
return ('0x' +
|
|
77
|
+
Buffer.from(definitionType.hashTreeRoot(val).buffer).toString('hex'));
|
|
75
78
|
}
|
|
76
79
|
throw new Error('unsupported version');
|
|
77
80
|
};
|
|
@@ -143,7 +146,7 @@ const verifyDefinitionSignatures = (clusterDefinition, definitionType) => {
|
|
|
143
146
|
if (definitionType === constants_js_1.DefinitionFlow.Solo) {
|
|
144
147
|
return true;
|
|
145
148
|
}
|
|
146
|
-
return clusterDefinition.operators.every(
|
|
149
|
+
return clusterDefinition.operators.every(operator => {
|
|
147
150
|
const configSigner = getPUTConfigHashSigner(operator.config_signature, clusterDefinition.config_hash, types_js_1.FORK_MAPPING[clusterDefinition.fork_version]);
|
|
148
151
|
const enrSigner = getEnrSigner(operator.enr_signature, operator.enr, types_js_1.FORK_MAPPING[clusterDefinition.fork_version]);
|
|
149
152
|
if (configSigner !== operator.address.toLowerCase() ||
|
|
@@ -220,15 +223,24 @@ const verifyBuilderRegistration = (validator, feeRecipientAddress, forkVersion)
|
|
|
220
223
|
const builderDomain = computeDomain((0, ssz_1.fromHexString)(constants_js_1.DOMAIN_APPLICATION_BUILDER), forkVersion);
|
|
221
224
|
if (validator.distributed_public_key !==
|
|
222
225
|
((_a = validator.builder_registration) === null || _a === void 0 ? void 0 : _a.message.pubkey)) {
|
|
223
|
-
return {
|
|
226
|
+
return {
|
|
227
|
+
isValidBuilderRegistration: false,
|
|
228
|
+
builderRegistrationMsg: new Uint8Array(0),
|
|
229
|
+
};
|
|
224
230
|
}
|
|
225
231
|
if (feeRecipientAddress.toLowerCase() !==
|
|
226
232
|
validator.builder_registration.message.fee_recipient.toLowerCase()) {
|
|
227
|
-
return {
|
|
233
|
+
return {
|
|
234
|
+
isValidBuilderRegistration: false,
|
|
235
|
+
builderRegistrationMsg: new Uint8Array(0),
|
|
236
|
+
};
|
|
228
237
|
}
|
|
229
238
|
const builderRegistrationMessageBuffer = computebuilderRegistrationMsgRoot(validator.builder_registration.message);
|
|
230
239
|
const builderRegistrationMessage = (0, exports.signingRoot)(builderDomain, builderRegistrationMessageBuffer);
|
|
231
|
-
return {
|
|
240
|
+
return {
|
|
241
|
+
isValidBuilderRegistration: true,
|
|
242
|
+
builderRegistrationMsg: builderRegistrationMessage,
|
|
243
|
+
};
|
|
232
244
|
};
|
|
233
245
|
exports.verifyBuilderRegistration = verifyBuilderRegistration;
|
|
234
246
|
const verifyNodeSignatures = (clusterLock) => {
|
|
@@ -29,7 +29,7 @@ const hashTermsAndConditions = () => __awaiter(void 0, void 0, void 0, function*
|
|
|
29
29
|
terms_and_conditions_hash: new ssz_1.ByteListType(Number.MAX_SAFE_INTEGER),
|
|
30
30
|
});
|
|
31
31
|
const termsHasVal = termsType.defaultValue();
|
|
32
|
-
termsHasVal.terms_and_conditions_hash = (0, utils_1.strToUint8Array)(data === null || data === void 0 ? void 0 : data.text);
|
|
32
|
+
termsHasVal.terms_and_conditions_hash = (0, utils_1.strToUint8Array)(data === null || data === void 0 ? void 0 : data.text.replace(/[^a-zA-Z0-9]/g, ''));
|
|
33
33
|
return ('0x' +
|
|
34
34
|
Buffer.from(termsType.hashTreeRoot(termsHasVal).buffer).toString('hex'));
|
|
35
35
|
}
|
|
@@ -60,7 +60,7 @@ const hashClusterDefinitionV1X6 = (cluster, configOnly) => {
|
|
|
60
60
|
address: (0, ssz_1.fromHexString)(cluster.creator.address),
|
|
61
61
|
config_signature: (0, ssz_1.fromHexString)(cluster.creator.config_signature),
|
|
62
62
|
};
|
|
63
|
-
val.validators = cluster.validators.map(
|
|
63
|
+
val.validators = cluster.validators.map(validator => {
|
|
64
64
|
return {
|
|
65
65
|
fee_recipient_address: (0, ssz_1.fromHexString)(validator.fee_recipient_address),
|
|
66
66
|
withdrawal_address: (0, ssz_1.fromHexString)(validator.withdrawal_address),
|
|
@@ -60,7 +60,7 @@ const hashClusterDefinitionV1X7 = (cluster, configOnly) => {
|
|
|
60
60
|
address: (0, ssz_1.fromHexString)(cluster.creator.address),
|
|
61
61
|
config_signature: (0, ssz_1.fromHexString)(cluster.creator.config_signature),
|
|
62
62
|
};
|
|
63
|
-
val.validators = cluster.validators.map(
|
|
63
|
+
val.validators = cluster.validators.map(validator => {
|
|
64
64
|
return {
|
|
65
65
|
fee_recipient_address: (0, ssz_1.fromHexString)(validator.fee_recipient_address),
|
|
66
66
|
withdrawal_address: (0, ssz_1.fromHexString)(validator.withdrawal_address),
|
|
@@ -97,11 +97,11 @@ const hashClusterLockV1X7 = (cluster) => {
|
|
|
97
97
|
const val = lockType.defaultValue();
|
|
98
98
|
// Check if we can replace with definition_hash
|
|
99
99
|
val.cluster_definition = (0, exports.hashClusterDefinitionV1X7)(cluster.cluster_definition, false);
|
|
100
|
-
val.distributed_validators = cluster.distributed_validators.map(
|
|
100
|
+
val.distributed_validators = cluster.distributed_validators.map(dValidator => {
|
|
101
101
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
102
102
|
return {
|
|
103
103
|
distributed_public_key: (0, ssz_1.fromHexString)(dValidator.distributed_public_key),
|
|
104
|
-
public_shares: dValidator.public_shares.map(
|
|
104
|
+
public_shares: dValidator.public_shares.map(publicShare => (0, ssz_1.fromHexString)(publicShare)),
|
|
105
105
|
deposit_data: {
|
|
106
106
|
pubkey: (0, ssz_1.fromHexString)((_a = dValidator.deposit_data) === null || _a === void 0 ? void 0 : _a.pubkey),
|
|
107
107
|
withdrawal_credentials: (0, ssz_1.fromHexString)((_b = dValidator.deposit_data) === null || _b === void 0 ? void 0 : _b.withdrawal_credentials),
|
|
@@ -61,7 +61,7 @@ const hashClusterDefinitionV1X8 = (cluster, configOnly) => {
|
|
|
61
61
|
address: (0, ssz_1.fromHexString)(cluster.creator.address),
|
|
62
62
|
config_signature: (0, ssz_1.fromHexString)(cluster.creator.config_signature),
|
|
63
63
|
};
|
|
64
|
-
val.validators = cluster.validators.map(
|
|
64
|
+
val.validators = cluster.validators.map(validator => {
|
|
65
65
|
return {
|
|
66
66
|
fee_recipient_address: (0, ssz_1.fromHexString)(validator.fee_recipient_address),
|
|
67
67
|
withdrawal_address: (0, ssz_1.fromHexString)(validator.withdrawal_address),
|
|
@@ -146,8 +146,8 @@ const verifyDVV1X8 = (clusterLock) => {
|
|
|
146
146
|
pubShares.push((0, ssz_1.fromHexString)(element));
|
|
147
147
|
}
|
|
148
148
|
// Deposit Data Verification
|
|
149
|
-
for (
|
|
150
|
-
const depositData =
|
|
149
|
+
for (const element of validator.partial_deposit_data) {
|
|
150
|
+
const depositData = element;
|
|
151
151
|
const { isValidDepositData, depositDataMsg } = (0, common_1.verifyDepositData)(distributedPublicKey, depositData, clusterLock.cluster_definition.validators[i].withdrawal_address, clusterLock.cluster_definition.fork_version);
|
|
152
152
|
if (!isValidDepositData) {
|
|
153
153
|
return false;
|