@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,79 @@
1
+ export const CONFLICT_ERROR_MSG = "Conflict";
2
+ export const EIP712_DOMAIN_NAME = "Obol";
3
+ export const EIP712_DOMAIN_VERSION = "1";
4
+ export const CreatorConfigHashSigningTypes = {
5
+ CreatorConfigHash: [{ name: "creator_config_hash", type: "string" }],
6
+ };
7
+ const EIP712Domain = [
8
+ { name: 'name', type: 'string' },
9
+ { name: 'version', type: 'string' },
10
+ { name: 'chainId', type: 'uint256' },
11
+ ];
12
+ export const Domain = (chainId) => {
13
+ return {
14
+ name: EIP712_DOMAIN_NAME,
15
+ version: EIP712_DOMAIN_VERSION,
16
+ chainId,
17
+ };
18
+ };
19
+ export const CreatorTypedMessage = Object.assign({ EIP712Domain }, CreatorConfigHashSigningTypes);
20
+ //A conflict once updateDefinition is merged
21
+ export const EnrSigningTypes = {
22
+ ENR: [{ name: "enr", type: "string" }],
23
+ };
24
+ export const OperatorConfigHashSigningTypes = {
25
+ OperatorConfigHash: [{ name: "operator_config_hash", type: "string" }],
26
+ };
27
+ export const OperatorTypedMessage = Object.assign({ EIP712Domain }, OperatorConfigHashSigningTypes);
28
+ export const ENRTypedMessage = Object.assign({ EIP712Domain }, EnrSigningTypes);
29
+ export const signCreatorConfigHashPayload = (payload, chainId) => {
30
+ return {
31
+ types: CreatorTypedMessage,
32
+ primaryType: 'CreatorConfigHash',
33
+ domain: {
34
+ name: EIP712_DOMAIN_NAME,
35
+ version: EIP712_DOMAIN_VERSION,
36
+ chainId,
37
+ },
38
+ message: payload,
39
+ };
40
+ };
41
+ export const signOperatorConfigHashPayload = (payload, chainId) => {
42
+ return {
43
+ types: OperatorTypedMessage,
44
+ primaryType: 'OperatorConfigHash',
45
+ domain: {
46
+ name: EIP712_DOMAIN_NAME,
47
+ version: EIP712_DOMAIN_VERSION,
48
+ chainId,
49
+ },
50
+ message: payload,
51
+ };
52
+ };
53
+ export const signEnrPayload = (payload, chainId) => {
54
+ return {
55
+ types: ENRTypedMessage,
56
+ primaryType: 'ENR',
57
+ domain: {
58
+ name: EIP712_DOMAIN_NAME,
59
+ version: EIP712_DOMAIN_VERSION,
60
+ chainId,
61
+ },
62
+ message: payload,
63
+ };
64
+ };
65
+ export const dkg_algorithm = "default";
66
+ export const config_version = "v1.7.0";
67
+ export const SDK_VERSION = "1.0.7";
68
+ export const DOMAIN_APPLICATION_BUILDER = '00000001';
69
+ export const DOMAIN_DEPOSIT = '03000000';
70
+ export const GENESIS_VALIDATOR_ROOT = '0000000000000000000000000000000000000000000000000000000000000000';
71
+ // Flow used to create defintion
72
+ export var DefinitionFlow;
73
+ (function (DefinitionFlow) {
74
+ DefinitionFlow["Group"] = "LP-Group";
75
+ DefinitionFlow["Solo"] = "LP-Solo";
76
+ DefinitionFlow["Charon"] = "Charon-Command";
77
+ })(DefinitionFlow || (DefinitionFlow = {}));
78
+ export const DEFAULT_BASE_URL = "https://api.obol.tech";
79
+ export const DEFAULT_CHAIN_ID = 1;
@@ -0,0 +1,7 @@
1
+ export class ConflictError extends Error {
2
+ constructor() {
3
+ super(`This Cluster has been already posted.`);
4
+ this.name = 'ConflictError';
5
+ Object.setPrototypeOf(this, ConflictError.prototype);
6
+ }
7
+ }
@@ -0,0 +1,165 @@
1
+ import { ContainerType, ByteVectorType, UintNumberType, ListCompositeType, ByteListType, fromHexString, } from '@chainsafe/ssz';
2
+ import { strToUint8Array } from './utils.js';
3
+ //cluster-definition
4
+ /**
5
+ * @param cluster The cluster configuration or the cluster definition
6
+ * @param configOnly a boolean to indicate config hash or definition hash
7
+ * @returns The config hash or the definition hash in of the corresponding cluster
8
+ */
9
+ export const clusterConfigOrDefinitionHash = (cluster, configOnly) => {
10
+ const definitionType = clusterDefinitionContainerType(configOnly);
11
+ const val = hashClusterDefinition(cluster, configOnly);
12
+ return ('0x' + Buffer.from(definitionType.hashTreeRoot(val).buffer).toString('hex'));
13
+ };
14
+ export const hashClusterDefinition = (cluster, configOnly) => {
15
+ const definitionType = clusterDefinitionContainerType(configOnly);
16
+ const val = definitionType.defaultValue();
17
+ //order should be same as charon https://github.com/ObolNetwork/charon/blob/d00b31e6465a260a43ce40f15c47fb5a5b009042/cluster/ssz.go#L285
18
+ val.uuid = strToUint8Array(cluster.uuid);
19
+ val.name = strToUint8Array(cluster.name);
20
+ val.version = strToUint8Array(cluster.version);
21
+ val.timestamp = strToUint8Array(cluster.timestamp);
22
+ val.num_validators = cluster.num_validators;
23
+ val.threshold = cluster.threshold;
24
+ val.dkg_algorithm = strToUint8Array(cluster.dkg_algorithm);
25
+ val.fork_version = fromHexString(cluster.fork_version);
26
+ val.operators = cluster.operators.map((operator) => {
27
+ return configOnly
28
+ ? { address: fromHexString(operator.address) }
29
+ : {
30
+ address: fromHexString(operator.address),
31
+ enr: strToUint8Array(operator.enr),
32
+ config_signature: fromHexString(operator.config_signature),
33
+ enr_signature: fromHexString(operator.enr_signature),
34
+ };
35
+ });
36
+ val.creator = configOnly
37
+ ? { address: fromHexString(cluster.creator.address) }
38
+ : {
39
+ address: fromHexString(cluster.creator.address),
40
+ config_signature: fromHexString(cluster.creator.config_signature),
41
+ };
42
+ val.validators = cluster.validators.map((validator) => {
43
+ return {
44
+ fee_recipient_address: fromHexString(validator.fee_recipient_address),
45
+ withdrawal_address: fromHexString(validator.withdrawal_address),
46
+ };
47
+ });
48
+ if (!configOnly) {
49
+ val.config_hash = fromHexString(cluster.config_hash);
50
+ }
51
+ return val;
52
+ };
53
+ const operatorAddressWrapperType = new ContainerType({
54
+ address: new ByteVectorType(20),
55
+ });
56
+ const creatorAddressWrapperType = new ContainerType({
57
+ address: new ByteVectorType(20),
58
+ });
59
+ export const operatorContainerType = new ContainerType({
60
+ address: new ByteVectorType(20),
61
+ enr: new ByteListType(1024), // This needs to be dynamic, since ENRs do not have a fixed length.
62
+ config_signature: new ByteVectorType(65),
63
+ enr_signature: new ByteVectorType(65),
64
+ });
65
+ export const creatorContainerType = new ContainerType({
66
+ address: new ByteVectorType(20),
67
+ config_signature: new ByteVectorType(65),
68
+ });
69
+ export const validatorsContainerType = new ContainerType({
70
+ fee_recipient_address: new ByteVectorType(20),
71
+ withdrawal_address: new ByteVectorType(20),
72
+ });
73
+ const newCreatorContainerType = (configOnly) => {
74
+ return configOnly ? creatorAddressWrapperType : creatorContainerType;
75
+ };
76
+ const newOperatorContainerType = (configOnly) => {
77
+ return configOnly ? operatorAddressWrapperType : operatorContainerType;
78
+ };
79
+ /**
80
+ * @param configOnly a boolean to indicate config hash or definition hash
81
+ * @returns SSZ Containerized type of cluster definition
82
+ */
83
+ export const clusterDefinitionContainerType = (configOnly) => {
84
+ let returnedContainerType = {
85
+ uuid: new ByteListType(64),
86
+ name: new ByteListType(256),
87
+ version: new ByteListType(16),
88
+ timestamp: new ByteListType(32),
89
+ num_validators: new UintNumberType(8),
90
+ threshold: new UintNumberType(8),
91
+ dkg_algorithm: new ByteListType(32),
92
+ fork_version: new ByteVectorType(4),
93
+ operators: new ListCompositeType(newOperatorContainerType(configOnly), 256),
94
+ creator: newCreatorContainerType(configOnly),
95
+ validators: new ListCompositeType(validatorsContainerType, 65536),
96
+ };
97
+ if (!configOnly) {
98
+ returnedContainerType = Object.assign(Object.assign({}, returnedContainerType), { config_hash: new ByteVectorType(32) });
99
+ }
100
+ return new ContainerType(returnedContainerType);
101
+ };
102
+ //cluster-lock
103
+ /**
104
+ * @param cluster The published cluster lock
105
+ * @returns The lock hash in of the corresponding cluster
106
+ */
107
+ export const clusterLockHash = (cluster) => {
108
+ const lockType = clusterLockContainerType();
109
+ const val = lockType.defaultValue();
110
+ //Check if we can replace with definition_hash
111
+ val.cluster_definition = hashClusterDefinition(cluster.cluster_definition, false);
112
+ val.distributed_validators = cluster.distributed_validators.map(dVaidator => {
113
+ return {
114
+ distributed_public_key: fromHexString(dVaidator.distributed_public_key),
115
+ public_shares: dVaidator.public_shares.map(publicShare => fromHexString(publicShare)),
116
+ deposit_data: {
117
+ pubkey: fromHexString(dVaidator.deposit_data.pubkey),
118
+ withdrawal_credentials: fromHexString(dVaidator.deposit_data.withdrawal_credentials),
119
+ amount: parseInt(dVaidator.deposit_data.amount),
120
+ signature: fromHexString(dVaidator.deposit_data.signature),
121
+ },
122
+ builder_registration: {
123
+ message: {
124
+ fee_recipient: fromHexString(dVaidator.builder_registration.message.fee_recipient),
125
+ gas_limit: dVaidator.builder_registration.message.gas_limit,
126
+ timestamp: dVaidator.builder_registration.message.timestamp,
127
+ pubkey: fromHexString(dVaidator.builder_registration.message.pubkey),
128
+ },
129
+ signature: fromHexString(dVaidator.builder_registration.signature),
130
+ },
131
+ };
132
+ });
133
+ return '0x' + Buffer.from(lockType.hashTreeRoot(val).buffer).toString('hex');
134
+ };
135
+ const depositDataContainer = new ContainerType({
136
+ pubkey: new ByteVectorType(48),
137
+ withdrawal_credentials: new ByteVectorType(32),
138
+ amount: new UintNumberType(8),
139
+ signature: new ByteVectorType(96),
140
+ });
141
+ const builderRegistrationMessageContainer = new ContainerType({
142
+ fee_recipient: new ByteVectorType(20),
143
+ gas_limit: new UintNumberType(8),
144
+ timestamp: new UintNumberType(8),
145
+ pubkey: new ByteVectorType(48),
146
+ });
147
+ const builderRegistrationContainer = new ContainerType({
148
+ message: builderRegistrationMessageContainer,
149
+ signature: new ByteVectorType(96),
150
+ });
151
+ const dvContainerType = new ContainerType({
152
+ distributed_public_key: new ByteVectorType(48),
153
+ public_shares: new ListCompositeType(new ByteVectorType(48), 256),
154
+ deposit_data: depositDataContainer,
155
+ builder_registration: builderRegistrationContainer,
156
+ });
157
+ /**
158
+ * @returns SSZ Containerized type of cluster lock
159
+ */
160
+ const clusterLockContainerType = () => {
161
+ return new ContainerType({
162
+ cluster_definition: clusterDefinitionContainerType(false),
163
+ distributed_validators: new ListCompositeType(dvContainerType, 65536),
164
+ });
165
+ };
@@ -0,0 +1,140 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { v4 as uuidv4 } from "uuid";
11
+ import { Base } from './base.js';
12
+ import { CONFLICT_ERROR_MSG, CreatorConfigHashSigningTypes, Domain, dkg_algorithm, config_version, OperatorConfigHashSigningTypes, EnrSigningTypes } from './constants.js';
13
+ import { ConflictError } from './errors.js';
14
+ import { clusterConfigOrDefinitionHash } from './hash.js';
15
+ import { validatePayload } from './ajv.js';
16
+ import { definitionSchema, operatorPayloadSchema } from './schema.js';
17
+ export * from "./types.js";
18
+ export * from "./services.js";
19
+ /**
20
+ * Obol sdk Client can be used for creating, managing and activating distributed validators.
21
+ */
22
+ export class Client extends Base {
23
+ /**
24
+ * @param config - Client configurations
25
+ * @param config.baseUrl - obol-api url
26
+ * @param config.chainId - Blockchain network ID
27
+ * @param signer - ethersJS Signer
28
+ * @returns Obol-SDK Client instance
29
+ *
30
+ * An example of how to instantiate obol-sdk Client:
31
+ * [obolClient](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts#L29)
32
+ */
33
+ constructor(config, signer) {
34
+ super(config);
35
+ this.signer = signer;
36
+ }
37
+ /**
38
+ * Creates a cluster definition which contains cluster configuration.
39
+ * @param {ClusterPayload} newCluster - The new unique cluster.
40
+ * @returns {Promise<string>} config_hash.
41
+ * @throws On duplicate entries, missing or wrong cluster keys.
42
+ *
43
+ * An example of how to use createClusterDefinition:
44
+ * [createObolCluster](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts)
45
+ */
46
+ createClusterDefinition(newCluster) {
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ if (!this.signer)
49
+ throw "Signer is required in createClusterDefinition";
50
+ validatePayload(newCluster, definitionSchema);
51
+ const clusterConfig = Object.assign(Object.assign({}, newCluster), { fork_version: this.fork_version, dkg_algorithm: dkg_algorithm, version: config_version, uuid: uuidv4(), timestamp: new Date().toISOString(), threshold: Math.ceil((2 * newCluster.operators.length) / 3), num_validators: newCluster.validators.length });
52
+ try {
53
+ const address = yield this.signer.getAddress();
54
+ clusterConfig.creator = { address };
55
+ clusterConfig.config_hash = clusterConfigOrDefinitionHash(clusterConfig, true);
56
+ const creatorConfigSignature = yield this.signer.signTypedData(Domain(this.chainId), CreatorConfigHashSigningTypes, { creator_config_hash: clusterConfig.config_hash });
57
+ const clusterDefinition = yield this.request(`/dv`, {
58
+ method: 'POST',
59
+ body: JSON.stringify(clusterConfig),
60
+ headers: {
61
+ Authorization: `Bearer ${creatorConfigSignature}`,
62
+ "fork-version": this.fork_version,
63
+ }
64
+ });
65
+ return clusterDefinition === null || clusterDefinition === void 0 ? void 0 : clusterDefinition.config_hash;
66
+ }
67
+ catch (err) {
68
+ if ((err === null || err === void 0 ? void 0 : err.message) == CONFLICT_ERROR_MSG)
69
+ throw new ConflictError();
70
+ throw err;
71
+ }
72
+ });
73
+ }
74
+ /**
75
+ * Approves joining a cluster with specific configuration.
76
+ * @param {OperatorPayload} operatorPayload - The operator data including signatures.
77
+ * @param {string} configHash - The config hash of the cluster which the operator confirms joining to.
78
+ * @returns {Promise<ClusterDefintion>} The cluster definition.
79
+ * @throws On unauthorized, duplicate entries, missing keys, not found cluster or invalid data.
80
+ *
81
+ * An example of how to use acceptClusterDefinition:
82
+ * [acceptClusterDefinition](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts)
83
+ */
84
+ acceptClusterDefinition(operatorPayload, configHash) {
85
+ return __awaiter(this, void 0, void 0, function* () {
86
+ if (!this.signer)
87
+ throw "Signer is required in acceptClusterDefinition";
88
+ validatePayload(operatorPayload, operatorPayloadSchema);
89
+ try {
90
+ const address = yield this.signer.getAddress();
91
+ const operatorConfigSignature = yield this.signer.signTypedData(Domain(this.chainId), OperatorConfigHashSigningTypes, { operator_config_hash: configHash });
92
+ const operatorENRSignature = yield this.signer.signTypedData(Domain(this.chainId), EnrSigningTypes, { enr: operatorPayload.enr });
93
+ const operatorData = Object.assign(Object.assign({}, operatorPayload), { address, enr_signature: operatorENRSignature, fork_version: this.fork_version });
94
+ const clusterDefinition = yield this.request(`/dv/${configHash}`, {
95
+ method: 'PUT',
96
+ body: JSON.stringify(operatorData),
97
+ headers: {
98
+ Authorization: `Bearer ${operatorConfigSignature}`,
99
+ }
100
+ });
101
+ return clusterDefinition;
102
+ }
103
+ catch (err) {
104
+ throw err;
105
+ }
106
+ });
107
+ }
108
+ /**
109
+ * @param configHash - The configuration hash returned in createClusterDefinition
110
+ * @returns {Promise<ClusterDefintion>} The cluster definition for config hash
111
+ * @throws On not found config hash.
112
+ *
113
+ * An example of how to use getClusterDefinition:
114
+ * [getObolClusterDefinition](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts)
115
+ */
116
+ getClusterDefinition(configHash) {
117
+ return __awaiter(this, void 0, void 0, function* () {
118
+ const clusterDefinition = yield this.request(`/dv/${configHash}`, {
119
+ method: 'GET',
120
+ });
121
+ return clusterDefinition;
122
+ });
123
+ }
124
+ /**
125
+ * @param configHash - The configuration hash in cluster-definition
126
+ * @returns {Promise<ClusterLock>} The matched cluster details (lock) from DB
127
+ * @throws On not found cluster definition or lock.
128
+ *
129
+ * An example of how to use getClusterLock:
130
+ * [getObolClusterLock](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts)
131
+ */
132
+ getClusterLock(configHash) {
133
+ return __awaiter(this, void 0, void 0, function* () {
134
+ const lock = yield this.request(`/lock/configHash/${configHash}`, {
135
+ method: 'GET',
136
+ });
137
+ return lock;
138
+ });
139
+ }
140
+ }
@@ -0,0 +1,69 @@
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
+ export const definitionSchema = {
17
+ type: "object",
18
+ properties: {
19
+ name: {
20
+ type: "string"
21
+ },
22
+ operators: {
23
+ type: "array",
24
+ minItems: 4,
25
+ uniqueItems: true,
26
+ items: {
27
+ type: "object",
28
+ properties: {
29
+ address: {
30
+ type: "string",
31
+ minLength: 42,
32
+ maxLength: 42
33
+ }
34
+ },
35
+ required: [
36
+ "address"
37
+ ]
38
+ }
39
+ },
40
+ validators: {
41
+ type: "array",
42
+ minItems: 1,
43
+ items: {
44
+ type: "object",
45
+ properties: {
46
+ fee_recipient_address: {
47
+ type: "string",
48
+ minLength: 42,
49
+ maxLength: 42
50
+ },
51
+ withdrawal_address: {
52
+ type: "string",
53
+ minLength: 42,
54
+ maxLength: 42
55
+ }
56
+ },
57
+ required: [
58
+ "fee_recipient_address",
59
+ "withdrawal_address"
60
+ ]
61
+ }
62
+ }
63
+ },
64
+ required: [
65
+ "name",
66
+ "operators",
67
+ "validators"
68
+ ]
69
+ };
@@ -0,0 +1,28 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { isValidClusterLock } from "./verify.js";
11
+ /**
12
+ * Verifies Cluster Lock's validity.
13
+ * @param lock - cluster lock
14
+ * @returns {Promise<{ result: boolean }> } boolean result to indicate if lock is valid
15
+ * @throws on missing keys or values.
16
+ *
17
+ * An example of how to use validateClusterLock:
18
+ * [validateClusterLock](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts)
19
+ */
20
+ export const validateClusterLock = (lock) => __awaiter(void 0, void 0, void 0, function* () {
21
+ try {
22
+ const isLockValid = yield isValidClusterLock(lock);
23
+ return isLockValid;
24
+ }
25
+ catch (err) {
26
+ throw err;
27
+ }
28
+ });
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Permitted ChainID's
3
+ */
4
+ export var FORK_MAPPING;
5
+ (function (FORK_MAPPING) {
6
+ /** Mainnet. */
7
+ FORK_MAPPING[FORK_MAPPING["0x00000000"] = 1] = "0x00000000";
8
+ /** Goerli/Prater. */
9
+ FORK_MAPPING[FORK_MAPPING["0x00001020"] = 5] = "0x00001020";
10
+ /** Gnosis Chain. */
11
+ FORK_MAPPING[FORK_MAPPING["0x00000064"] = 100] = "0x00000064";
12
+ /** Holesky. */
13
+ FORK_MAPPING[FORK_MAPPING["0x01017000"] = 17000] = "0x01017000";
14
+ })(FORK_MAPPING || (FORK_MAPPING = {}));
15
+ ;
@@ -0,0 +1,6 @@
1
+ export const hexWithout0x = (hex) => {
2
+ return hex.slice(2, hex.length);
3
+ };
4
+ export const strToUint8Array = (str) => {
5
+ return new TextEncoder().encode(str);
6
+ };