@obolnetwork/obol-sdk 1.0.11 → 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.
Files changed (70) hide show
  1. package/LICENCE +21 -0
  2. package/README.md +33 -3
  3. package/dist/cjs/package.json +128 -0
  4. package/dist/cjs/src/ajv.js +2 -1
  5. package/dist/cjs/src/base.js +2 -2
  6. package/dist/cjs/src/constants.js +38 -13
  7. package/dist/cjs/src/errors.js +1 -1
  8. package/dist/cjs/src/index.js +24 -21
  9. package/dist/cjs/src/schema.js +24 -36
  10. package/dist/cjs/src/services.js +2 -2
  11. package/dist/cjs/src/types.js +0 -1
  12. package/dist/cjs/src/utils.js +36 -1
  13. package/dist/cjs/src/{verify.js → verification/common.js} +128 -155
  14. package/dist/cjs/src/verification/sszTypes.js +69 -0
  15. package/dist/cjs/src/verification/v1.6.0.js +149 -0
  16. package/dist/cjs/src/verification/v1.7.0.js +173 -0
  17. package/dist/cjs/src/verification/v1.8.0.js +183 -0
  18. package/dist/cjs/test/fixtures.js +281 -63
  19. package/dist/cjs/test/methods.test.js +58 -35
  20. package/dist/esm/package.json +128 -0
  21. package/dist/esm/src/ajv.js +2 -1
  22. package/dist/esm/src/base.js +2 -2
  23. package/dist/esm/src/constants.js +14 -12
  24. package/dist/esm/src/errors.js +1 -1
  25. package/dist/esm/src/index.js +27 -24
  26. package/dist/esm/src/schema.js +24 -36
  27. package/dist/esm/src/services.js +1 -1
  28. package/dist/esm/src/types.js +0 -1
  29. package/dist/esm/src/utils.js +34 -0
  30. package/dist/esm/src/{verify.js → verification/common.js} +114 -146
  31. package/dist/esm/src/verification/sszTypes.js +64 -0
  32. package/dist/esm/src/verification/v1.6.0.js +142 -0
  33. package/dist/esm/src/verification/v1.7.0.js +166 -0
  34. package/dist/esm/src/verification/v1.8.0.js +176 -0
  35. package/dist/esm/test/fixtures.js +280 -62
  36. package/dist/esm/test/methods.test.js +59 -36
  37. package/dist/types/src/ajv.d.ts +1 -1
  38. package/dist/types/src/base.d.ts +3 -3
  39. package/dist/types/src/constants.d.ts +8 -10
  40. package/dist/types/src/index.d.ts +16 -16
  41. package/dist/types/src/services.d.ts +1 -1
  42. package/dist/types/src/types.d.ts +33 -27
  43. package/dist/types/src/utils.d.ts +3 -0
  44. package/dist/types/src/verification/common.d.ts +32 -0
  45. package/dist/types/src/verification/sszTypes.d.ts +63 -0
  46. package/dist/types/src/verification/v1.6.0.d.ts +34 -0
  47. package/dist/types/src/verification/v1.7.0.d.ts +34 -0
  48. package/dist/types/src/verification/v1.8.0.d.ts +35 -0
  49. package/dist/types/test/fixtures.d.ts +104 -2
  50. package/package.json +42 -7
  51. package/src/ajv.ts +15 -10
  52. package/src/base.ts +25 -21
  53. package/src/constants.ts +80 -78
  54. package/src/errors.ts +6 -9
  55. package/src/index.ts +118 -81
  56. package/src/schema.ts +24 -36
  57. package/src/services.ts +15 -13
  58. package/src/types.ts +72 -74
  59. package/src/utils.ts +53 -4
  60. package/src/verification/common.ts +420 -0
  61. package/src/verification/sszTypes.ts +79 -0
  62. package/src/verification/v1.6.0.ts +226 -0
  63. package/src/verification/v1.7.0.ts +274 -0
  64. package/src/verification/v1.8.0.ts +281 -0
  65. package/dist/cjs/src/hash.js +0 -172
  66. package/dist/esm/src/hash.js +0 -165
  67. package/dist/types/src/hash.d.ts +0 -56
  68. package/dist/types/src/verify.d.ts +0 -4
  69. package/src/hash.ts +0 -250
  70. package/src/verify.ts +0 -479
package/LICENCE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Obol Labs, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,10 +1,40 @@
1
1
  ![Obol Logo](https://obol.tech/obolnetwork.png)
2
2
 
3
-
4
3
  <h1 align="center">Obol SDK</h1>
5
4
 
6
- This repo contains the Obol Software Development Kit, for creating Distributed Validators with the help of the [Obol API](https://docs.obol.tech/api).
5
+ This repo contains the Obol Software Development Kit, for creating Distributed Validators with the help of the [Obol API](https://docs.obol.tech/api).
7
6
 
8
7
  ## Getting Started
9
8
 
10
- Checkout our [docs](https://docs.obol.tech/docs/advanced/quickstart-sdk), [examples](https://github.com/ObolNetwork/obol-sdk-examples/), and SDK [reference](https://obolnetwork.github.io/obol-packages). Further guides and walkthroughs coming soon.
9
+ Checkout our [docs](https://docs.obol.tech/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
+ ## Contributing
12
+
13
+ Please review the following guidelines:
14
+
15
+ - [How to Report Bugs](#how-to-report-bugs)
16
+ - [How to Propose Changes](#how-to-propose-changes)
17
+ - [Code Review Process](#code-review-process)
18
+
19
+ ### How to Report Bugs
20
+
21
+ If you encounter a bug or unexpected behavior, please follow these steps to report it:
22
+
23
+ 1. Go to the "Issues" tab of this repository.
24
+ 2. Click on the "Get started" button in the Bug report section.
25
+ 3. Provide a clear title and description of the issue following the format provided.
26
+
27
+ ### How to Propose Changes
28
+
29
+ If you'd like to propose improvements or new features, please follow these steps:
30
+
31
+ 1. Fork this repository.
32
+ 2. Create a new branch for your changes.
33
+ 3. Make your changes and commit them with clear messages.
34
+ 4. Open a pull request with a detailed description of the changes.
35
+
36
+ ### Code Review Process
37
+
38
+ All contributions are reviewed before they are merged into the main branch. Please address any feedback provided during the review process.
39
+
40
+ Thank you for contributing to Obol-SDK!
@@ -0,0 +1,128 @@
1
+ {
2
+ "name": "@obolnetwork/obol-sdk",
3
+ "version": "1.0.13",
4
+ "description": "A package for creating Distributed Validators using the Obol API.",
5
+ "bugs": {
6
+ "url": "https://github.com/obolnetwork/obol-sdk/issues"
7
+ },
8
+ "homepage": "https://docs.obol.tech/",
9
+ "keywords": [
10
+ "Obol",
11
+ "Distributed Validators",
12
+ "Ethereum"
13
+ ],
14
+ "scripts": {
15
+ "compile": "tsc -b ./tsconfig.cjs.json ./tsconfig.esm.json ./tsconfig.types.json",
16
+ "build:clean": "rm -rf ./dist",
17
+ "build": "npm-run-all build:clean compile",
18
+ "test": "jest ./test/methods.test.ts",
19
+ "generate-typedoc": "typedoc",
20
+ "npm:publish": "npm publish --tag latest",
21
+ "release": "release-it",
22
+ "release:dry": "release-it --dry-run --no-npm",
23
+ "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
24
+ "lint-ci": "eslint \"{src,apps,libs,test}/**/*.ts\""
25
+ },
26
+ "main": "./dist/cjs/src/index.js",
27
+ "module": "./dist/esm/src/index.js",
28
+ "typings": "./dist/types/src/index.d.ts",
29
+ "author": "Obol Labs (https://obol.tech)",
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "git+https://github.com/obolnetwork/obol-sdk.git"
33
+ },
34
+ "license": "ISC",
35
+ "publishConfig": {
36
+ "registry": "https://registry.npmjs.org/",
37
+ "access": "public"
38
+ },
39
+ "dependencies": {
40
+ "@chainsafe/bls": "6.0.3",
41
+ "@chainsafe/blst": "^0.2.9",
42
+ "@chainsafe/discv5": "^0.5.1",
43
+ "@chainsafe/ssz": "^0.14.0",
44
+ "@metamask/eth-sig-util": "^7.0.1",
45
+ "ajv": "^8.12.0",
46
+ "cross-fetch": "^3.1.5",
47
+ "elliptic": "^6.5.4",
48
+ "eslint-config-standard-with-typescript": "^43.0.1",
49
+ "eslint-plugin-import": "^2.29.1",
50
+ "eslint-plugin-n": "^16.6.2",
51
+ "eslint-plugin-promise": "^6.1.1",
52
+ "ethers": "^6.4.0",
53
+ "nock": "^13.5.3",
54
+ "release-it": "^17.1.1",
55
+ "semver": "^7.6.0",
56
+ "typescript-eslint": "^7.1.0",
57
+ "uuid": "^9.0.0"
58
+ },
59
+ "devDependencies": {
60
+ "@release-it/conventional-changelog": "^8.0.1",
61
+ "@types/elliptic": "^6.4.18",
62
+ "@types/jest": "^28.1.8",
63
+ "@types/node": "^20.2.5",
64
+ "@types/uuid": "^9.0.1",
65
+ "eslint": "^8.57.0",
66
+ "jest": "^28.1.3",
67
+ "msw": "^2.2.1",
68
+ "npm-run-all": "^4.1.5",
69
+ "ts-jest": "^28.0.8",
70
+ "tsup": "^6.7.0",
71
+ "typedoc": "^0.25.7",
72
+ "typedoc-plugin-markdown": "^4.0.0-next.50",
73
+ "typescript": "^5.3.3"
74
+ },
75
+ "engines": {
76
+ "node": ">= 16"
77
+ },
78
+ "files": [
79
+ "package.json",
80
+ "README.md",
81
+ "dist",
82
+ "src"
83
+ ],
84
+ "release-it": {
85
+ "git": {
86
+ "commitMessage": "chore(release): v${version}",
87
+ "push": true,
88
+ "commit": true,
89
+ "tag": true,
90
+ "requireCommits": false,
91
+ "requireCleanWorkingDir": false
92
+ },
93
+ "github": {
94
+ "release": true,
95
+ "draft": true
96
+ },
97
+ "npm": {
98
+ "publish": false,
99
+ "ignoreVersion": false
100
+ },
101
+ "plugins": {
102
+ "@release-it/conventional-changelog": {
103
+ "preset": "angular",
104
+ "infile": "CHANGELOG.md",
105
+ "header": "# Changelog"
106
+ }
107
+ }
108
+ },
109
+ "jest": {
110
+ "transform": {
111
+ "\\.[jt]sx?$": "ts-jest"
112
+ },
113
+ "globals": {
114
+ "ts-jest": {
115
+ "useESM": true
116
+ }
117
+ },
118
+ "moduleNameMapper": {
119
+ "^bn.js$": "<rootDir>/node_modules/bn.js",
120
+ "^asn1.js$": "<rootDir>/node_modules/asn1.js",
121
+ "^hash.js$": "<rootDir>/node_modules/hash.js",
122
+ "(.+)\\.js": "$1"
123
+ },
124
+ "extensionsToTreatAsEsm": [
125
+ ".ts"
126
+ ]
127
+ }
128
+ }
@@ -6,11 +6,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.validatePayload = void 0;
7
7
  const ajv_1 = __importDefault(require("ajv"));
8
8
  function validatePayload(data, schema) {
9
+ var _a;
9
10
  const ajv = new ajv_1.default();
10
11
  const validate = ajv.compile(schema);
11
12
  const isValid = validate(data);
12
13
  if (!isValid) {
13
- throw new Error(`Schema compilation errors', ${validate.errors && validate.errors[0].message}`);
14
+ throw new Error(`Schema compilation errors', ${(_a = validate.errors) === null || _a === void 0 ? void 0 : _a[0].message}`);
14
15
  }
15
16
  return isValid;
16
17
  }
@@ -14,7 +14,7 @@ exports.Base = void 0;
14
14
  const constants_js_1 = require("./constants.js");
15
15
  const types_js_1 = require("./types.js");
16
16
  class Base {
17
- constructor({ baseUrl = constants_js_1.DEFAULT_BASE_URL, chainId = constants_js_1.DEFAULT_CHAIN_ID }) {
17
+ constructor({ baseUrl = constants_js_1.DEFAULT_BASE_URL, chainId = constants_js_1.DEFAULT_CHAIN_ID, }) {
18
18
  this.baseUrl = baseUrl;
19
19
  this.chainId = chainId;
20
20
  this.fork_version = types_js_1.FORK_MAPPING[this.chainId];
@@ -26,7 +26,7 @@ class Base {
26
26
  try {
27
27
  const response = yield fetch(url, config);
28
28
  if (response.ok) {
29
- return (yield response.json());
29
+ return yield response.json();
30
30
  }
31
31
  throw new Error(response.statusText);
32
32
  }
@@ -1,11 +1,35 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
- 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.CreatorConfigHashSigningTypes = exports.EIP712_DOMAIN_VERSION = exports.EIP712_DOMAIN_NAME = exports.CONFLICT_ERROR_MSG = void 0;
4
- exports.CONFLICT_ERROR_MSG = "Conflict";
5
- exports.EIP712_DOMAIN_NAME = "Obol";
6
- exports.EIP712_DOMAIN_VERSION = "1";
26
+ 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.CreatorConfigHashSigningTypes = exports.EIP712_DOMAIN_VERSION = exports.EIP712_DOMAIN_NAME = exports.CONFLICT_ERROR_MSG = void 0;
27
+ const pjson = __importStar(require("../package.json"));
28
+ exports.CONFLICT_ERROR_MSG = 'Conflict';
29
+ exports.EIP712_DOMAIN_NAME = 'Obol';
30
+ exports.EIP712_DOMAIN_VERSION = '1';
7
31
  exports.CreatorConfigHashSigningTypes = {
8
- CreatorConfigHash: [{ name: "creator_config_hash", type: "string" }],
32
+ CreatorConfigHash: [{ name: 'creator_config_hash', type: 'string' }],
9
33
  };
10
34
  const EIP712Domain = [
11
35
  { name: 'name', type: 'string' },
@@ -21,12 +45,12 @@ const Domain = (chainId) => {
21
45
  };
22
46
  exports.Domain = Domain;
23
47
  exports.CreatorTypedMessage = Object.assign({ EIP712Domain }, exports.CreatorConfigHashSigningTypes);
24
- //A conflict once updateDefinition is merged
48
+ // A conflict once updateDefinition is merged
25
49
  exports.EnrSigningTypes = {
26
- ENR: [{ name: "enr", type: "string" }],
50
+ ENR: [{ name: 'enr', type: 'string' }],
27
51
  };
28
52
  exports.OperatorConfigHashSigningTypes = {
29
- OperatorConfigHash: [{ name: "operator_config_hash", type: "string" }],
53
+ OperatorConfigHash: [{ name: 'operator_config_hash', type: 'string' }],
30
54
  };
31
55
  exports.OperatorTypedMessage = Object.assign({ EIP712Domain }, exports.OperatorConfigHashSigningTypes);
32
56
  exports.ENRTypedMessage = Object.assign({ EIP712Domain }, exports.EnrSigningTypes);
@@ -69,9 +93,9 @@ const signEnrPayload = (payload, chainId) => {
69
93
  };
70
94
  };
71
95
  exports.signEnrPayload = signEnrPayload;
72
- exports.dkg_algorithm = "default";
73
- exports.config_version = "v1.7.0";
74
- exports.SDK_VERSION = "1.0.7";
96
+ exports.DKG_ALGORITHM = 'default';
97
+ exports.CONFIG_VERSION = 'v1.7.0';
98
+ exports.SDK_VERSION = pjson.version;
75
99
  exports.DOMAIN_APPLICATION_BUILDER = '00000001';
76
100
  exports.DOMAIN_DEPOSIT = '03000000';
77
101
  exports.GENESIS_VALIDATOR_ROOT = '0000000000000000000000000000000000000000000000000000000000000000';
@@ -82,5 +106,6 @@ var DefinitionFlow;
82
106
  DefinitionFlow["Solo"] = "LP-Solo";
83
107
  DefinitionFlow["Charon"] = "Charon-Command";
84
108
  })(DefinitionFlow || (exports.DefinitionFlow = DefinitionFlow = {}));
85
- exports.DEFAULT_BASE_URL = "https://api.obol.tech";
86
- exports.DEFAULT_CHAIN_ID = 1;
109
+ exports.DEFAULT_BASE_URL = 'https://api.obol.tech';
110
+ exports.DEFAULT_CHAIN_ID = 17000;
111
+ exports.ETHER_TO_GWEI = 10 ** 9;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ConflictError = void 0;
4
4
  class ConflictError extends Error {
5
5
  constructor() {
6
- super(`This Cluster has been already posted.`);
6
+ super('This Cluster has been already posted.');
7
7
  this.name = 'ConflictError';
8
8
  Object.setPrototypeOf(this, ConflictError.prototype);
9
9
  }
@@ -28,7 +28,7 @@ const uuid_1 = require("uuid");
28
28
  const base_js_1 = require("./base.js");
29
29
  const constants_js_1 = require("./constants.js");
30
30
  const errors_js_1 = require("./errors.js");
31
- const hash_js_1 = require("./hash.js");
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
34
  __exportStar(require("./types.js"), exports);
@@ -62,46 +62,49 @@ class Client extends base_js_1.Base {
62
62
  */
63
63
  createClusterDefinition(newCluster) {
64
64
  return __awaiter(this, void 0, void 0, function* () {
65
- if (!this.signer)
66
- throw "Signer is required in createClusterDefinition";
65
+ if (!this.signer) {
66
+ throw new Error('Signer is required in createClusterDefinition');
67
+ }
67
68
  (0, ajv_js_1.validatePayload)(newCluster, schema_js_1.definitionSchema);
68
- 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 });
69
+ 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 });
69
70
  try {
70
71
  const address = yield this.signer.getAddress();
71
72
  clusterConfig.creator = { address };
72
- clusterConfig.config_hash = (0, hash_js_1.clusterConfigOrDefinitionHash)(clusterConfig, true);
73
+ clusterConfig.config_hash = (0, common_js_1.clusterConfigOrDefinitionHash)(clusterConfig, true);
73
74
  const creatorConfigSignature = yield this.signer.signTypedData((0, constants_js_1.Domain)(this.chainId), constants_js_1.CreatorConfigHashSigningTypes, { creator_config_hash: clusterConfig.config_hash });
74
- const clusterDefinition = yield this.request(`/dv`, {
75
+ const clusterDefinition = yield this.request('/dv', {
75
76
  method: 'POST',
76
77
  body: JSON.stringify(clusterConfig),
77
78
  headers: {
78
79
  Authorization: `Bearer ${creatorConfigSignature}`,
79
- "fork-version": this.fork_version,
80
- }
80
+ 'fork-version': this.fork_version,
81
+ },
81
82
  });
82
83
  return clusterDefinition === null || clusterDefinition === void 0 ? void 0 : clusterDefinition.config_hash;
83
84
  }
84
85
  catch (err) {
85
- if ((err === null || err === void 0 ? void 0 : err.message) == constants_js_1.CONFLICT_ERROR_MSG)
86
+ if ((err === null || err === void 0 ? void 0 : err.message) === constants_js_1.CONFLICT_ERROR_MSG) {
86
87
  throw new errors_js_1.ConflictError();
88
+ }
87
89
  throw err;
88
90
  }
89
91
  });
90
92
  }
91
93
  /**
92
- * Approves joining a cluster with specific configuration.
93
- * @param {OperatorPayload} operatorPayload - The operator data including signatures.
94
- * @param {string} configHash - The config hash of the cluster which the operator confirms joining to.
95
- * @returns {Promise<ClusterDefintion>} The cluster definition.
96
- * @throws On unauthorized, duplicate entries, missing keys, not found cluster or invalid data.
97
- *
98
- * An example of how to use acceptClusterDefinition:
99
- * [acceptClusterDefinition](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts)
100
- */
94
+ * Approves joining a cluster with specific configuration.
95
+ * @param {OperatorPayload} operatorPayload - The operator data including signatures.
96
+ * @param {string} configHash - The config hash of the cluster which the operator confirms joining to.
97
+ * @returns {Promise<ClusterDefintion>} The cluster definition.
98
+ * @throws On unauthorized, duplicate entries, missing keys, not found cluster or invalid data.
99
+ *
100
+ * An example of how to use acceptClusterDefinition:
101
+ * [acceptClusterDefinition](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts)
102
+ */
101
103
  acceptClusterDefinition(operatorPayload, configHash) {
102
104
  return __awaiter(this, void 0, void 0, function* () {
103
- if (!this.signer)
104
- throw "Signer is required in acceptClusterDefinition";
105
+ if (!this.signer) {
106
+ throw new Error('Signer is required in acceptClusterDefinition');
107
+ }
105
108
  (0, ajv_js_1.validatePayload)(operatorPayload, schema_js_1.operatorPayloadSchema);
106
109
  try {
107
110
  const address = yield this.signer.getAddress();
@@ -113,7 +116,7 @@ class Client extends base_js_1.Base {
113
116
  body: JSON.stringify(operatorData),
114
117
  headers: {
115
118
  Authorization: `Bearer ${operatorConfigSignature}`,
116
- }
119
+ },
117
120
  });
118
121
  return clusterDefinition;
119
122
  }
@@ -2,71 +2,59 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.definitionSchema = exports.operatorPayloadSchema = void 0;
4
4
  exports.operatorPayloadSchema = {
5
- type: "object",
5
+ type: 'object',
6
6
  properties: {
7
7
  version: {
8
- type: "string"
8
+ type: 'string',
9
9
  },
10
10
  enr: {
11
- type: "string"
11
+ type: 'string',
12
12
  },
13
13
  },
14
- required: [
15
- "version",
16
- "enr",
17
- ]
14
+ required: ['version', 'enr'],
18
15
  };
19
16
  exports.definitionSchema = {
20
- type: "object",
17
+ type: 'object',
21
18
  properties: {
22
19
  name: {
23
- type: "string"
20
+ type: 'string',
24
21
  },
25
22
  operators: {
26
- type: "array",
23
+ type: 'array',
27
24
  minItems: 4,
28
25
  uniqueItems: true,
29
26
  items: {
30
- type: "object",
27
+ type: 'object',
31
28
  properties: {
32
29
  address: {
33
- type: "string",
30
+ type: 'string',
34
31
  minLength: 42,
35
- maxLength: 42
36
- }
32
+ maxLength: 42,
33
+ },
37
34
  },
38
- required: [
39
- "address"
40
- ]
41
- }
35
+ required: ['address'],
36
+ },
42
37
  },
43
38
  validators: {
44
- type: "array",
39
+ type: 'array',
45
40
  minItems: 1,
46
41
  items: {
47
- type: "object",
42
+ type: 'object',
48
43
  properties: {
49
44
  fee_recipient_address: {
50
- type: "string",
45
+ type: 'string',
51
46
  minLength: 42,
52
- maxLength: 42
47
+ maxLength: 42,
53
48
  },
54
49
  withdrawal_address: {
55
- type: "string",
50
+ type: 'string',
56
51
  minLength: 42,
57
- maxLength: 42
58
- }
52
+ maxLength: 42,
53
+ },
59
54
  },
60
- required: [
61
- "fee_recipient_address",
62
- "withdrawal_address"
63
- ]
64
- }
65
- }
55
+ required: ['fee_recipient_address', 'withdrawal_address'],
56
+ },
57
+ },
66
58
  },
67
- required: [
68
- "name",
69
- "operators",
70
- "validators"
71
- ]
59
+ required: ['name', 'operators', 'validators'],
72
60
  };
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.validateClusterLock = void 0;
13
- const verify_js_1 = require("./verify.js");
13
+ const common_js_1 = require("./verification/common.js");
14
14
  /**
15
15
  * Verifies Cluster Lock's validity.
16
16
  * @param lock - cluster lock
@@ -22,7 +22,7 @@ const verify_js_1 = require("./verify.js");
22
22
  */
23
23
  const validateClusterLock = (lock) => __awaiter(void 0, void 0, void 0, function* () {
24
24
  try {
25
- const isLockValid = yield (0, verify_js_1.isValidClusterLock)(lock);
25
+ const isLockValid = yield (0, common_js_1.isValidClusterLock)(lock);
26
26
  return isLockValid;
27
27
  }
28
28
  catch (err) {
@@ -15,4 +15,3 @@ var FORK_MAPPING;
15
15
  /** Holesky. */
16
16
  FORK_MAPPING[FORK_MAPPING["0x01017000"] = 17000] = "0x01017000";
17
17
  })(FORK_MAPPING || (exports.FORK_MAPPING = FORK_MAPPING = {}));
18
- ;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.strToUint8Array = exports.hexWithout0x = void 0;
3
+ exports.definitionFlow = exports.strToUint8Array = exports.hexWithout0x = void 0;
4
+ const constants_1 = require("./constants");
4
5
  const hexWithout0x = (hex) => {
5
6
  return hex.slice(2, hex.length);
6
7
  };
@@ -9,3 +10,37 @@ const strToUint8Array = (str) => {
9
10
  return new TextEncoder().encode(str);
10
11
  };
11
12
  exports.strToUint8Array = strToUint8Array;
13
+ const definitionFlow = (clusterDefinition) => {
14
+ if (clusterDefinition.creator.address &&
15
+ clusterDefinition.creator.config_signature &&
16
+ clusterDefinition.operators.every((operator) => {
17
+ return (operator.address &&
18
+ operator.config_signature &&
19
+ operator.enr &&
20
+ operator.enr_signature);
21
+ })) {
22
+ return constants_1.DefinitionFlow.Group;
23
+ }
24
+ else if (clusterDefinition.creator.address &&
25
+ clusterDefinition.creator.config_signature &&
26
+ clusterDefinition.operators.every((operator) => {
27
+ return (!operator.address &&
28
+ !operator.config_signature &&
29
+ operator.enr &&
30
+ !operator.enr_signature);
31
+ })) {
32
+ return constants_1.DefinitionFlow.Solo;
33
+ }
34
+ else if (!clusterDefinition.creator.address &&
35
+ !clusterDefinition.creator.config_signature &&
36
+ clusterDefinition.operators.every((operator) => {
37
+ return (!operator.address &&
38
+ !operator.config_signature &&
39
+ operator.enr &&
40
+ !operator.enr_signature);
41
+ })) {
42
+ return constants_1.DefinitionFlow.Charon;
43
+ }
44
+ return null;
45
+ };
46
+ exports.definitionFlow = definitionFlow;