From 818fbfce0544f816286e8eedcf6f3729accd59c0 Mon Sep 17 00:00:00 2001 From: HananINouman Date: Tue, 2 Jul 2024 20:34:16 +0300 Subject: [PATCH] fix prettier stuff --- src/base.ts | 8 +- src/constants.ts | 29 ++++--- src/index.ts | 78 +++++++++-------- src/types.ts | 20 ++--- src/utils.ts | 4 +- src/verification/common.ts | 8 +- src/verification/termsAndConditions.ts | 30 ++++--- src/verification/v1.6.0.ts | 4 +- src/verification/v1.7.0.ts | 4 +- src/verification/v1.8.0.ts | 63 +++++++------- test/fixtures.ts | 115 ++++++++++++++----------- test/methods.test.ts | 29 ++++--- test/sdk-package-test/cluster.test.ts | 49 +++++------ test/sdk-package-test/utils.ts | 12 +-- 14 files changed, 244 insertions(+), 209 deletions(-) diff --git a/src/base.ts b/src/base.ts index bf0b07c..b203473 100644 --- a/src/base.ts +++ b/src/base.ts @@ -42,13 +42,13 @@ export abstract class Base { try { const response = await fetch(url, config); if (response.ok) { - return await response.json() + return await response.json(); } else { - const errorResponse = await response.json() - throw errorResponse + const errorResponse = await response.json(); + throw errorResponse; } } catch (e: any) { - throw e + throw e; } } } diff --git a/src/constants.ts b/src/constants.ts index f18bb47..1d561d4 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -8,13 +8,13 @@ export const EIP712_DOMAIN_NAME = 'Obol'; export const EIP712_DOMAIN_VERSION = '1'; export const CreatorConfigHashSigningTypes = { CreatorConfigHash: [{ name: 'creator_config_hash', type: 'string' }], -} +}; export const TermsAndConditionsSigningTypes = { TermsAndConditions: [ { name: 'terms_and_conditions_hash', type: 'string' }, { name: 'version', type: 'uint256' }, - ] -} + ], +}; const EIP712Domain = [ { name: 'name', type: 'string' }, @@ -26,12 +26,12 @@ export const Domain = (chainId?: number): TypedDataDomain => { const typeDataDomain: any = { name: EIP712_DOMAIN_NAME, version: EIP712_DOMAIN_VERSION, - } + }; if (chainId) { - typeDataDomain.chainId = chainId + typeDataDomain.chainId = chainId; } - return typeDataDomain -} + return typeDataDomain; +}; export const CreatorTypedMessage = { EIP712Domain, @@ -123,13 +123,16 @@ export enum DefinitionFlow { Charon = 'Charon-Command', } -export const DEFAULT_BASE_URL = 'https://api.obol.tech' -export const DEFAULT_BASE_VERSION = 'v1' -export const DEFAULT_CHAIN_ID = 17000 +export const DEFAULT_BASE_URL = 'https://api.obol.tech'; +export const DEFAULT_BASE_VERSION = 'v1'; +export const DEFAULT_CHAIN_ID = 17000; -export const ETHER_TO_GWEI = 10 ** 9 +export const ETHER_TO_GWEI = 10 ** 9; -export const TERMS_AND_CONDITIONS_VERSION = 1 -export const TERMS_AND_CONDITIONS_URL = (TERMS_AND_CONDITIONS_VERSION === 1) ? 'https://obol.org/terms.pdf' : `https://obol.org/${TERMS_AND_CONDITIONS_VERSION as number}/terms.pdf` +export const TERMS_AND_CONDITIONS_VERSION = 1; +export const TERMS_AND_CONDITIONS_URL = + TERMS_AND_CONDITIONS_VERSION === 1 + ? 'https://obol.org/terms.pdf' + : `https://obol.org/${TERMS_AND_CONDITIONS_VERSION as number}/terms.pdf`; export const TERMS_AND_CONDITIONS_HASH = '0xd33721644e8f3afab1495a74abe3523cec12d48b8da6cb760972492ca3f1a273'; diff --git a/src/index.ts b/src/index.ts index b669ad8..4fe4cb0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -13,19 +13,19 @@ import { TermsAndConditionsSigningTypes, DEFAULT_BASE_VERSION, TERMS_AND_CONDITIONS_HASH, -} from './constants.js' -import { ConflictError } from './errors.js' +} from './constants.js'; +import { ConflictError } from './errors.js'; import { type ClusterDefinition, type ClusterLock, type ClusterPayload, type OperatorPayload, -} from './types.js' -import { clusterConfigOrDefinitionHash } from './verification/common.js' -import { validatePayload } from './ajv.js' -import { definitionSchema, operatorPayloadSchema } from './schema.js' -export * from './types.js' -export * from './services.js' +} from './types.js'; +import { clusterConfigOrDefinitionHash } from './verification/common.js'; +import { validatePayload } from './ajv.js'; +import { definitionSchema, operatorPayloadSchema } from './schema.js'; +export * from './types.js'; +export * from './services.js'; /** * Obol sdk Client can be used for creating, managing and activating distributed validators. @@ -56,17 +56,19 @@ export class Client extends Base { * An example of how to use acceptObolLatestTermsAndConditions: * [acceptObolLatestTermsAndConditions](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts#L44) */ - async acceptObolLatestTermsAndConditions (): Promise { - if (!this.signer) { throw new Error('Signer is required in acceptObolTermsAndConditions') } + async acceptObolLatestTermsAndConditions(): Promise { + if (!this.signer) { + throw new Error('Signer is required in acceptObolTermsAndConditions'); + } try { - const termsAndConditionsHash = TERMS_AND_CONDITIONS_HASH - const address = await this.signer.getAddress() + const termsAndConditionsHash = TERMS_AND_CONDITIONS_HASH; + const address = await this.signer.getAddress(); const termsAndConditionsPayload = { address, version: TERMS_AND_CONDITIONS_VERSION, - terms_and_conditions_hash: termsAndConditionsHash - } + terms_and_conditions_hash: termsAndConditionsHash, + }; const termsAndConditionsSignature = await this.signer.signTypedData( Domain(), @@ -75,21 +77,22 @@ export class Client extends Base { terms_and_conditions_hash: termsAndConditionsHash, version: TERMS_AND_CONDITIONS_VERSION, }, - ) + ); - const termsAndConditionsResponse: { message: string, success: boolean } = await this.request(`/${DEFAULT_BASE_VERSION}/termsAndConditions`, { - method: 'POST', - body: JSON.stringify(termsAndConditionsPayload), - headers: { - Authorization: `Bearer ${termsAndConditionsSignature}`, - }, - }) - return termsAndConditionsResponse?.message + const termsAndConditionsResponse: { message: string; success: boolean } = + await this.request(`/${DEFAULT_BASE_VERSION}/termsAndConditions`, { + method: 'POST', + body: JSON.stringify(termsAndConditionsPayload), + headers: { + Authorization: `Bearer ${termsAndConditionsSignature}`, + }, + }); + return termsAndConditionsResponse?.message; } catch (err: any) { if (err?.message === CONFLICT_ERROR_MSG) { - throw new ConflictError() + throw new ConflictError(); } - throw err + throw err; } } @@ -137,14 +140,17 @@ export class Client extends Base { { creator_config_hash: clusterConfig.config_hash }, ); - const clusterDefinition: ClusterDefinition = await this.request(`/${DEFAULT_BASE_VERSION}/definition`, { - method: 'POST', - body: JSON.stringify(clusterConfig), - headers: { - Authorization: `Bearer ${creatorConfigSignature}`, - 'fork-version': this.fork_version, + const clusterDefinition: ClusterDefinition = await this.request( + `/${DEFAULT_BASE_VERSION}/definition`, + { + method: 'POST', + body: JSON.stringify(clusterConfig), + headers: { + Authorization: `Bearer ${creatorConfigSignature}`, + 'fork-version': this.fork_version, + }, }, - }); + ); return clusterDefinition?.config_hash; } catch (err: any) { if (err?.message === CONFLICT_ERROR_MSG) { @@ -168,7 +174,9 @@ export class Client extends Base { operatorPayload: OperatorPayload, configHash: string, ): Promise { - if (!this.signer) { throw new Error('Signer is required in acceptClusterDefinition') } + if (!this.signer) { + throw new Error('Signer is required in acceptClusterDefinition'); + } validatePayload(operatorPayload, operatorPayloadSchema); @@ -191,7 +199,7 @@ export class Client extends Base { address, enr_signature: operatorENRSignature, fork_version: this.fork_version, - } + }; const clusterDefinition: ClusterDefinition = await this.request( `/${DEFAULT_BASE_VERSION}/definition/${configHash}`, { @@ -216,7 +224,7 @@ export class Client extends Base { * An example of how to use getClusterDefinition: * [getObolClusterDefinition](https://github.com/ObolNetwork/obol-sdk-examples/blob/main/TS-Example/index.ts#L74) */ - async getClusterDefinition (configHash: string): Promise { + async getClusterDefinition(configHash: string): Promise { const clusterDefinition: ClusterDefinition = await this.request( `/${DEFAULT_BASE_VERSION}/definition/${configHash}`, { diff --git a/src/types.ts b/src/types.ts index a89bcb5..ef68d71 100644 --- a/src/types.ts +++ b/src/types.ts @@ -36,7 +36,7 @@ export type ClusterOperator = { /** The operator configuration signature. */ config_signature?: string; -} +}; /** * A partial view of `ClusterOperator` with `enr` and `version` as required properties. @@ -52,7 +52,7 @@ export type ClusterCreator = { address: string; /** The cluster configuration signature. */ config_signature?: string; -} +}; /** * Validator withdrawal configuration @@ -63,7 +63,7 @@ export type ClusterValidator = { /** The validator reward address. */ withdrawal_address: string; -} +}; /** * Cluster configuration @@ -80,7 +80,7 @@ export type ClusterPayload = { /** The cluster partial deposits in gwei or 32000000000. */ deposit_amounts?: string[]; -} +}; /** * Cluster definition data needed for dkg @@ -135,7 +135,7 @@ export type BuilderRegistrationMessage = { /** The public key of the DV. */ pubkey: string; -} +}; /** * Pre-generated Signed Validator Builder Registration @@ -146,7 +146,7 @@ export type BuilderRegistration = { /** BLS signature of the builder registration message. */ signature: string; -} +}; /** * Required deposit data for validator activation @@ -166,7 +166,7 @@ export type DepositData = { /** BLS signature of the deposit message. */ signature: string; -} +}; /** * Required deposit data for validator activation @@ -186,14 +186,14 @@ export type DistributedValidator = { /** pre-generated signed validator builder registration to be sent to builder network. */ builder_registration?: BuilderRegistration; -} +}; /** * Cluster Details after DKG is complete */ export type ClusterLock = { /** The cluster definition. */ - cluster_definition: ClusterDefinition + cluster_definition: ClusterDefinition; /** The cluster distributed validators. */ distributed_validators: DistributedValidator[]; @@ -206,4 +206,4 @@ export type ClusterLock = { /** Node Signature for the lock hash by the node secp256k1 key. */ node_signatures?: string[]; -} +}; diff --git a/src/utils.ts b/src/utils.ts index 8af4e43..736f822 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,5 +1,5 @@ -import { DefinitionFlow } from './constants' -import { type ClusterDefinition } from './types' +import { DefinitionFlow } from './constants'; +import { type ClusterDefinition } from './types'; export const hexWithout0x = (hex: string): string => { return hex.slice(2, hex.length); diff --git a/src/verification/common.ts b/src/verification/common.ts index ec5704f..16bc631 100644 --- a/src/verification/common.ts +++ b/src/verification/common.ts @@ -57,8 +57,8 @@ import { * @returns The config hash or the definition hash in of the corresponding cluster */ export const clusterConfigOrDefinitionHash = ( - cluster: ClusterDefinition, - configOnly: boolean, + cluster: ClusterDefinition, + configOnly: boolean, ): string => { let definitionType, val; @@ -176,8 +176,8 @@ const getEnrSigner = ( }; const verifyDefinitionSignatures = ( - clusterDefinition: ClusterDefinition, - definitionType: DefinitionFlow, + clusterDefinition: ClusterDefinition, + definitionType: DefinitionFlow, ): boolean => { if (definitionType === DefinitionFlow.Charon) { return true; diff --git a/src/verification/termsAndConditions.ts b/src/verification/termsAndConditions.ts index 6e60fe1..5e4cefd 100644 --- a/src/verification/termsAndConditions.ts +++ b/src/verification/termsAndConditions.ts @@ -1,30 +1,32 @@ -import pdf from 'pdf-parse' -import { ByteListType, ContainerType } from '@chainsafe/ssz' -import { TERMS_AND_CONDITIONS_URL } from '../constants' -import { strToUint8Array } from '../utils' +import pdf from 'pdf-parse'; +import { ByteListType, ContainerType } from '@chainsafe/ssz'; +import { TERMS_AND_CONDITIONS_URL } from '../constants'; +import { strToUint8Array } from '../utils'; export const hashTermsAndConditions = async (): Promise => { try { // read the pdf - const response = await fetch(TERMS_AND_CONDITIONS_URL) - const pdfBuffarrayBuffer = await response.arrayBuffer() - const pdfBuffer = Buffer.from(pdfBuffarrayBuffer) - const data = await pdf(pdfBuffer) + const response = await fetch(TERMS_AND_CONDITIONS_URL); + const pdfBuffarrayBuffer = await response.arrayBuffer(); + const pdfBuffer = Buffer.from(pdfBuffarrayBuffer); + const data = await pdf(pdfBuffer); // ssz hash const termsType = new ContainerType({ terms_and_conditions_hash: new ByteListType(Number.MAX_SAFE_INTEGER), - }) + }); - const termsHasVal = termsType.defaultValue() + const termsHasVal = termsType.defaultValue(); - termsHasVal.terms_and_conditions_hash = strToUint8Array(data?.text.replace(/[^a-zA-Z0-9]/g, '')) + termsHasVal.terms_and_conditions_hash = strToUint8Array( + data?.text.replace(/[^a-zA-Z0-9]/g, ''), + ); return ( '0x' + Buffer.from(termsType.hashTreeRoot(termsHasVal).buffer).toString('hex') - ) + ); } catch (err) { - return null + return null; } -} +}; diff --git a/src/verification/v1.6.0.ts b/src/verification/v1.6.0.ts index e75805e..9579d0d 100644 --- a/src/verification/v1.6.0.ts +++ b/src/verification/v1.6.0.ts @@ -85,8 +85,8 @@ export const clusterDefinitionContainerTypeV1X6 = ( }; export const hashClusterDefinitionV1X6 = ( - cluster: ClusterDefinition, - configOnly: boolean, + cluster: ClusterDefinition, + configOnly: boolean, ): ValueOfFields => { const definitionType = clusterDefinitionContainerTypeV1X6(configOnly); diff --git a/src/verification/v1.7.0.ts b/src/verification/v1.7.0.ts index 51ecb09..2e524f7 100644 --- a/src/verification/v1.7.0.ts +++ b/src/verification/v1.7.0.ts @@ -91,8 +91,8 @@ export const clusterDefinitionContainerTypeV1X7 = ( }; export const hashClusterDefinitionV1X7 = ( - cluster: ClusterDefinition, - configOnly: boolean, + cluster: ClusterDefinition, + configOnly: boolean, ): ValueOfFields => { const definitionType = clusterDefinitionContainerTypeV1X7(configOnly); diff --git a/src/verification/v1.8.0.ts b/src/verification/v1.8.0.ts index e6e1cb9..8fff5d4 100644 --- a/src/verification/v1.8.0.ts +++ b/src/verification/v1.8.0.ts @@ -117,20 +117,20 @@ export const hashClusterDefinitionV1X8 = ( return configOnly ? { address: fromHexString(operator.address) } : { - address: fromHexString(operator.address), - enr: strToUint8Array(operator.enr as string), - config_signature: fromHexString(operator.config_signature as string), - enr_signature: fromHexString(operator.enr_signature as string), - }; + address: fromHexString(operator.address), + enr: strToUint8Array(operator.enr as string), + config_signature: fromHexString(operator.config_signature as string), + enr_signature: fromHexString(operator.enr_signature as string), + }; }); val.creator = configOnly ? { address: fromHexString(cluster.creator.address) } : { - address: fromHexString(cluster.creator.address), - config_signature: fromHexString( - cluster.creator.config_signature as string, - ), - }; + address: fromHexString(cluster.creator.address), + config_signature: fromHexString( + cluster.creator.config_signature as string, + ), + }; val.validators = cluster.validators.map(validator => { return { fee_recipient_address: fromHexString(validator.fee_recipient_address), @@ -248,48 +248,45 @@ export const verifyDVV1X8 = (clusterLock: ClusterLock): boolean => { // Needed in signature_aggregate verification for (const element of validatorPublicShares) { - pubShares.push(fromHexString(element)) + pubShares.push(fromHexString(element)); } // Deposit Data Verification for (const element of validator.partial_deposit_data as DepositData[]) { - const depositData = element + const depositData = element; const { isValidDepositData, depositDataMsg } = verifyDepositData( distributedPublicKey, depositData as Partial, clusterLock.cluster_definition.validators[i].withdrawal_address, - clusterLock.cluster_definition.fork_version - ) + clusterLock.cluster_definition.fork_version, + ); - if ( - !isValidDepositData - ) { - return false + if (!isValidDepositData) { + return false; } - pubKeys.push(fromHexString(distributedPublicKey)) - builderRegistrationAndDepositDataMessages.push(depositDataMsg) - blsSignatures.push(fromHexString(depositData?.signature)) + pubKeys.push(fromHexString(distributedPublicKey)); + builderRegistrationAndDepositDataMessages.push(depositDataMsg); + blsSignatures.push(fromHexString(depositData?.signature)); } // Builder Registration Verification - const { isValidBuilderRegistration, builderRegistrationMsg } = verifyBuilderRegistration( - validator, - clusterLock.cluster_definition.validators[i].fee_recipient_address, - clusterLock.cluster_definition.fork_version - ) + const { isValidBuilderRegistration, builderRegistrationMsg } = + verifyBuilderRegistration( + validator, + clusterLock.cluster_definition.validators[i].fee_recipient_address, + clusterLock.cluster_definition.fork_version, + ); - if ( - !isValidBuilderRegistration - ) { - return false + if (!isValidBuilderRegistration) { + return false; } - pubKeys.push(fromHexString(distributedPublicKey)) - builderRegistrationAndDepositDataMessages.push(builderRegistrationMsg) + pubKeys.push(fromHexString(distributedPublicKey)); + builderRegistrationAndDepositDataMessages.push(builderRegistrationMsg); blsSignatures.push( fromHexString(validator.builder_registration?.signature as string), - ) + ); } // BLS signatures verification diff --git a/test/fixtures.ts b/test/fixtures.ts index cca8cc2..3ad338b 100644 --- a/test/fixtures.ts +++ b/test/fixtures.ts @@ -227,44 +227,49 @@ export const clusterConfigV1X8 = { withdrawal_address: '0xE0C5ceA4D3869F156717C66E188Ae81C80914a6e', }, ], - deposit_amounts: [ - '8000000000', - '16000000000', - '8000000000' - ], -} + deposit_amounts: ['8000000000', '16000000000', '8000000000'], +}; export const clusterLockV1X8 = { cluster_definition: { name: 'xxxx', creator: { address: '0x86B8145c98e5BD25BA722645b15eD65f024a87EC', - config_signature: '0xd30b182fadbc2c5b2bb3f3f6ed6ac2588f297ceb610ed5509bf3e5a25a9b30c70f8a09ef1d2c8e1dbe5ff441299fe66ec677734cc08beec87e94b7effcb089701b' + config_signature: + '0xd30b182fadbc2c5b2bb3f3f6ed6ac2588f297ceb610ed5509bf3e5a25a9b30c70f8a09ef1d2c8e1dbe5ff441299fe66ec677734cc08beec87e94b7effcb089701b', }, operators: [ { address: '0x86B8145c98e5BD25BA722645b15eD65f024a87EC', enr: 'enr:-HW4QLlrtMjFLGkFT1bwdGbvZQlH8hLi0M2g44JAxEYP3BZmYpcsy9Q56HPPD87fMucjvLv4-obEFacpsg0ehRilbHeAgmlkgnY0iXNlY3AyNTZrMaEDRaa5o2aSgqyFq_ERZcQTztrOij1mFtXX1bJuVI6ieak', - config_signature: '0x3df771ecfc9ae2d01da9249dc636a42893e48759c0fa5c51f5e5e14f3ea4513233d1e3bbdd0e11d4b67c8a907201fd08225a75a1e2d6f510a439d6b15f0c36341c', - enr_signature: '0x3fe2a124dabe3d517e4c274074b3529d36d9528ca6fa8a4e74ef356f86a07c1462fe72a5336421c2647be7babc4ce1835c2101133e0779cf81d4a8d8cb9fe5591c' + config_signature: + '0x3df771ecfc9ae2d01da9249dc636a42893e48759c0fa5c51f5e5e14f3ea4513233d1e3bbdd0e11d4b67c8a907201fd08225a75a1e2d6f510a439d6b15f0c36341c', + enr_signature: + '0x3fe2a124dabe3d517e4c274074b3529d36d9528ca6fa8a4e74ef356f86a07c1462fe72a5336421c2647be7babc4ce1835c2101133e0779cf81d4a8d8cb9fe5591c', }, { address: '0xC35CfCd67b9C27345a54EDEcC1033F2284148c81', enr: 'enr:-Iu4QNbiUUUwT18LynBbVPJhNxvzQsaSpUr40mQTWscnZaqKb6vAlvV8j-eDDR3E0wjMQumGRbGm2IAb5_k4bVWJiVGAgmlkgnY0gmlwhH8AAAGJc2VjcDI1NmsxoQPOiodUji0ohgJb5sNK1hgv8g6xO5_znZz3NkkBkyYyKIN0Y3CCDhqDdWRwgg4u', - config_signature: '0x12d19d6fc4c1a5d9e7be09f47c2f2357dd89f47aba8ae0185f5345e08bcc3adc324bdd51e68a12c3ca34c604d786cfde5f0798aa928dac496edb16c70e7086551b', - enr_signature: '0xa3d49832dfaf0ad87c5796f9bc151009343da70b91fd53bee3645baa63d001d3207662da8f67b3a20f2ee30c9cacb24a5719a78dc24e030c8ac93e7b3b46bf881b' + config_signature: + '0x12d19d6fc4c1a5d9e7be09f47c2f2357dd89f47aba8ae0185f5345e08bcc3adc324bdd51e68a12c3ca34c604d786cfde5f0798aa928dac496edb16c70e7086551b', + enr_signature: + '0xa3d49832dfaf0ad87c5796f9bc151009343da70b91fd53bee3645baa63d001d3207662da8f67b3a20f2ee30c9cacb24a5719a78dc24e030c8ac93e7b3b46bf881b', }, { address: '0x33807D6F1DCe44b9C599fFE03640762A6F08C496', enr: 'enr:-Iu4QJyserRukhG0Vgi2csu7GjpHYUGufNEbZ8Q7ZBrcZUb0KqpL5QzHonkh1xxHlxatTxrIcX_IS5J3SEWR_sa0ptGAgmlkgnY0gmlwhH8AAAGJc2VjcDI1NmsxoQMAUgEqczOjevyculnUIofhCj0DkgJudErM7qCYIvIkzIN0Y3CCDhqDdWRwgg4u', - config_signature: '0x665d287c46921aad0dde389291b982f24dbbeb4b7ce5ee7bbc4a7d1fb55134f7136889eb3ce70208a7f276b9d4aefb1fbc6159476934567e5bf11765b2c9649b1b', - enr_signature: '0xc32d5ea29569b01354d48ddaf56df1481a5ae618ffb47602ef40e0e77357de5f23a5258923be5fa06ecce20f5692847860c25c38b97a4e306c94decd99c0519a1b' + config_signature: + '0x665d287c46921aad0dde389291b982f24dbbeb4b7ce5ee7bbc4a7d1fb55134f7136889eb3ce70208a7f276b9d4aefb1fbc6159476934567e5bf11765b2c9649b1b', + enr_signature: + '0xc32d5ea29569b01354d48ddaf56df1481a5ae618ffb47602ef40e0e77357de5f23a5258923be5fa06ecce20f5692847860c25c38b97a4e306c94decd99c0519a1b', }, { address: '0xc6e76F72Ea672FAe05C357157CfC37720F0aF26f', enr: 'enr:-HW4QKJTwXC6Chw6zbnA3HFZi6Jo0DkIgjKy4eUBpsSOGnAeWE6ChEjEyk_6R6Qrm7jI-iqfs3_HYxiKde8vFgvHHrCAgmlkgnY0iXNlY3AyNTZrMaECfFKQH4spdZCHqrKVz1Q02xYla6J_RQECDNNYBRWdzv8', - config_signature: '0x610f7be9c7c38878cde1cb391de08eee2f86e62f31f450843b4e37164e738fc8769046e53ad1f018f54ddaf858ff372d22169702c60d68bda19c96fdd20150b61c', - enr_signature: '0xe2977c79f63b8fe6cb6551efec0cf69041c7f4aaa8ea338997a397450ee946023b03ccb70ad3cc97b1319e1eea9f7472a2ca161bc8b33acdcde689d84c7e771c1b' - } + config_signature: + '0x610f7be9c7c38878cde1cb391de08eee2f86e62f31f450843b4e37164e738fc8769046e53ad1f018f54ddaf858ff372d22169702c60d68bda19c96fdd20150b61c', + enr_signature: + '0xe2977c79f63b8fe6cb6551efec0cf69041c7f4aaa8ea338997a397450ee946023b03ccb70ad3cc97b1319e1eea9f7472a2ca161bc8b33acdcde689d84c7e771c1b', + }, ], uuid: 'bc2fec0c-0b8b-4415-bf48-1e96b07f50eb', version: 'v1.8.0', @@ -274,81 +279,95 @@ export const clusterLockV1X8 = { validators: [ { fee_recipient_address: '0x7aC193bF9a9C6e6DD6302969E8Ea6EdF6df490d8', - withdrawal_address: '0x9e0AC0078F10d28E875577bb3A4A9EDAB60c03EC' + withdrawal_address: '0x9e0AC0078F10d28E875577bb3A4A9EDAB60c03EC', }, { fee_recipient_address: '0x7aC193bF9a9C6e6DD6302969E8Ea6EdF6df490d8', - withdrawal_address: '0x9e0AC0078F10d28E875577bb3A4A9EDAB60c03EC' - } + withdrawal_address: '0x9e0AC0078F10d28E875577bb3A4A9EDAB60c03EC', + }, ], dkg_algorithm: 'default', fork_version: '0x01017000', - deposit_amounts: [ - '32000000000' - ], - config_hash: '0xb2601f51d277f699acb8ea3b9fb4fc68087c0f1f2c6ae83d00fdd853a6cddb31', - definition_hash: '0x2a9d52b1dd13fd91661d81e3786512ffdcc3689e2ec97105add153f543c642b4' + deposit_amounts: ['32000000000'], + config_hash: + '0xb2601f51d277f699acb8ea3b9fb4fc68087c0f1f2c6ae83d00fdd853a6cddb31', + definition_hash: + '0x2a9d52b1dd13fd91661d81e3786512ffdcc3689e2ec97105add153f543c642b4', }, distributed_validators: [ { - distributed_public_key: '0xa33ae80f967a669d8df3ae769acc114577fab185d53e10154b0b50cc0cf9b9f35e466a318f174e8cecdc12173d95cb27', + distributed_public_key: + '0xa33ae80f967a669d8df3ae769acc114577fab185d53e10154b0b50cc0cf9b9f35e466a318f174e8cecdc12173d95cb27', public_shares: [ '0x849db297f690a26e76d5930f99eac9e3f95d9232256d6e39124fe071745b43c8b5418c733b06683aa240a2a0e44b9b8f', '0xa1051bf5692153d5bc418946763bb5c82780a05e97bd5b258ea7abe6705047628edd8277366f6b5d0469abfee18988d9', '0x87d0342e5dc49a0a0c8f08ec011da3bd859a333bfc46ddd0a194485aa5aa954b7c18d05a2c1ae148d4dc45331101f496', - '0xa4fa0e971e1a5e38ebe89c6457bc9316b3dd0933660b17e1c717ac148f8340a5db20d867c7a24758c701f6b6bec4d552' + '0xa4fa0e971e1a5e38ebe89c6457bc9316b3dd0933660b17e1c717ac148f8340a5db20d867c7a24758c701f6b6bec4d552', ], builder_registration: { message: { fee_recipient: '0x7ac193bf9a9c6e6dd6302969e8ea6edf6df490d8', gas_limit: 30000000, timestamp: 1696000704, - pubkey: '0xa33ae80f967a669d8df3ae769acc114577fab185d53e10154b0b50cc0cf9b9f35e466a318f174e8cecdc12173d95cb27' + pubkey: + '0xa33ae80f967a669d8df3ae769acc114577fab185d53e10154b0b50cc0cf9b9f35e466a318f174e8cecdc12173d95cb27', }, - signature: '0xb39977fe7c45bab28cfd1bcf356a71b0557187a75e0dfa0facaf5eddba05988c0da85800a4b4528704df44f280913ebc125eb3f9c091d6dd220c92dfcc3c80bc7a9ed2f1b96bffaeaa1053cf117b02b48eb755139c5623b6e61dd92c27d15813' + signature: + '0xb39977fe7c45bab28cfd1bcf356a71b0557187a75e0dfa0facaf5eddba05988c0da85800a4b4528704df44f280913ebc125eb3f9c091d6dd220c92dfcc3c80bc7a9ed2f1b96bffaeaa1053cf117b02b48eb755139c5623b6e61dd92c27d15813', }, partial_deposit_data: [ { - pubkey: '0xa33ae80f967a669d8df3ae769acc114577fab185d53e10154b0b50cc0cf9b9f35e466a318f174e8cecdc12173d95cb27', - withdrawal_credentials: '0x0100000000000000000000009e0ac0078f10d28e875577bb3a4a9edab60c03ec', + pubkey: + '0xa33ae80f967a669d8df3ae769acc114577fab185d53e10154b0b50cc0cf9b9f35e466a318f174e8cecdc12173d95cb27', + withdrawal_credentials: + '0x0100000000000000000000009e0ac0078f10d28e875577bb3a4a9edab60c03ec', amount: '32000000000', - signature: '0x9861022ca71cf18aad49a201b023356b8c5ca090086614b681cb84a54327caeff53c0a71c5f55f49976114bb86de2ad6052d174d7948e6c8a924d9bfbbbc2181fad967d818454c6c4f7cffb7bb93dc2c4f4c87fc5598cb4582fa08eff0c7bc08' - } - ] + signature: + '0x9861022ca71cf18aad49a201b023356b8c5ca090086614b681cb84a54327caeff53c0a71c5f55f49976114bb86de2ad6052d174d7948e6c8a924d9bfbbbc2181fad967d818454c6c4f7cffb7bb93dc2c4f4c87fc5598cb4582fa08eff0c7bc08', + }, + ], }, { - distributed_public_key: '0xaa888bf805bec7da7ac18dea3afefbf5b8510cbf76367229dab830b3ecdd4533b9d50fb9fcb454df5cbe08e4b31e8479', + distributed_public_key: + '0xaa888bf805bec7da7ac18dea3afefbf5b8510cbf76367229dab830b3ecdd4533b9d50fb9fcb454df5cbe08e4b31e8479', public_shares: [ '0x8279ae646839d946a622d096296ffcccd289e8c49ea2308560bbb731c63d4b49ea46db817a955e47634edbded4919d82', '0xa8a12b5b645b015c55515b3220395e015fc051c58bf243e1b638770652c67f863852f9190e3e182aa86b99823b4cf28d', '0xb0c557f812060bb1c409e5324c7b54f35fee8f1180c714e60784f7df6a58e3ba3da6cc8b3cebc01975f9f41efcd777cb', - '0xa7a8576c3b21221f2a6adefc41b4c1f979ee0761e9a7ff50d30434d1a0c4e7fc505b308636801925e698286b802de421' + '0xa7a8576c3b21221f2a6adefc41b4c1f979ee0761e9a7ff50d30434d1a0c4e7fc505b308636801925e698286b802de421', ], builder_registration: { message: { fee_recipient: '0x7ac193bf9a9c6e6dd6302969e8ea6edf6df490d8', gas_limit: 30000000, timestamp: 1696000704, - pubkey: '0xaa888bf805bec7da7ac18dea3afefbf5b8510cbf76367229dab830b3ecdd4533b9d50fb9fcb454df5cbe08e4b31e8479' + pubkey: + '0xaa888bf805bec7da7ac18dea3afefbf5b8510cbf76367229dab830b3ecdd4533b9d50fb9fcb454df5cbe08e4b31e8479', }, - signature: '0x8dcb54028adb8f5601b6ab20ded381dabb6739b3e506df795a279043997908c7d38a68b8e8dda27516165f18e437a84603935bfefc1a83befbd1a90ac43fcc7fb0eed81122852a2ee71fef414aa8879198da239527036b0eaebcdc88d6eca3d1' + signature: + '0x8dcb54028adb8f5601b6ab20ded381dabb6739b3e506df795a279043997908c7d38a68b8e8dda27516165f18e437a84603935bfefc1a83befbd1a90ac43fcc7fb0eed81122852a2ee71fef414aa8879198da239527036b0eaebcdc88d6eca3d1', }, partial_deposit_data: [ { - pubkey: '0xaa888bf805bec7da7ac18dea3afefbf5b8510cbf76367229dab830b3ecdd4533b9d50fb9fcb454df5cbe08e4b31e8479', - withdrawal_credentials: '0x0100000000000000000000009e0ac0078f10d28e875577bb3a4a9edab60c03ec', + pubkey: + '0xaa888bf805bec7da7ac18dea3afefbf5b8510cbf76367229dab830b3ecdd4533b9d50fb9fcb454df5cbe08e4b31e8479', + withdrawal_credentials: + '0x0100000000000000000000009e0ac0078f10d28e875577bb3a4a9edab60c03ec', amount: '32000000000', - signature: '0x95ee68e5191d34e10f567ab0f565cd927211b29be9ab830d39bf74d0486aee7bff78d8fe12d455cb40ec707378eea1040a9d80806f82afa58295de9d4db2dccc48cfaf3c98e9020c6b5c8a9aacf5bbfc7e316871f505000304d9d39b7ad5c5d8' - } - ] - } + signature: + '0x95ee68e5191d34e10f567ab0f565cd927211b29be9ab830d39bf74d0486aee7bff78d8fe12d455cb40ec707378eea1040a9d80806f82afa58295de9d4db2dccc48cfaf3c98e9020c6b5c8a9aacf5bbfc7e316871f505000304d9d39b7ad5c5d8', + }, + ], + }, ], - signature_aggregate: '0x81ab6319191e3b9065f14231a71fe480b4a45e5e5db4a064faa19a31d04b9cb55fa88b8aa3c966b054b97ae7db2233ee060ae333c5ca3a55ed16b9a3de1894087901cb2d3a177de1cd40030c93301c23ca3edd28dfd1ad04e210b7e2c7625f89', - lock_hash: '0x186e7e61fb49373d9034d101f2f08429cb379bfcc2f7fa5e9598e8a14ae13ed7', + signature_aggregate: + '0x81ab6319191e3b9065f14231a71fe480b4a45e5e5db4a064faa19a31d04b9cb55fa88b8aa3c966b054b97ae7db2233ee060ae333c5ca3a55ed16b9a3de1894087901cb2d3a177de1cd40030c93301c23ca3edd28dfd1ad04e210b7e2c7625f89', + lock_hash: + '0x186e7e61fb49373d9034d101f2f08429cb379bfcc2f7fa5e9598e8a14ae13ed7', node_signatures: [ '0xd4b1b6f7b363015b9d1c1c4f199fffc3f9238b7326fdfc5059b175519b05c90a022a18bf2e3eae7d7b0e833384131c2e7be17cc78f6ca23644ae345904dc2d2601', '0xc186f930d8d281ab3999fb0ff62b5d96045a4e2330d9d8b300d5d1014f6b4bd925d9c2fedbb53047a49d4008f82600f46e1131b981222c5e423c12b1c9fd544900', '0xbc0831fa82b1a70e17eb4fe6f79249a8f5aab1d1f196dd07e32766eb27e72354757d7146b64fca4ad4efa554f7a5d4e7ef835aab6348e9afa37c9eeab069ff4e01', - '0x0135f307831fa58ff64f9af46e00b92e2375162646af88f6991ba6f98a8c262f2c41846af59da68eadb8ff9c94db42ee8005bd4236e5897635573db2911460aa00' - ] -} + '0x0135f307831fa58ff64f9af46e00b92e2375162646af88f6991ba6f98a8c262f2c41846af59da68eadb8ff9c94db42ee8005bd4236e5897635573db2911460aa00', + ], +}; diff --git a/test/methods.test.ts b/test/methods.test.ts index 273cadd..bc6dea9 100644 --- a/test/methods.test.ts +++ b/test/methods.test.ts @@ -12,7 +12,7 @@ import { Base } from '../src/base'; import { validatePayload } from '../src/ajv'; import { HttpResponse, http } from 'msw'; import { setupServer } from 'msw/node'; -import { hashTermsAndConditions } from '../src/verification/termsAndConditions' +import { hashTermsAndConditions } from '../src/verification/termsAndConditions'; /* eslint no-new: 0 */ describe('Cluster Client', () => { @@ -39,12 +39,14 @@ describe('Cluster Client', () => { test('createTermsAndConditions should return "successful authorization"', async () => { clientInstance['request'] = jest .fn() - .mockReturnValue(Promise.resolve({ message: 'successful authorization' })) + .mockReturnValue( + Promise.resolve({ message: 'successful authorization' }), + ); const isAuthorized = - await clientInstance.acceptObolLatestTermsAndConditions() - expect(isAuthorized).toEqual('successful authorization') - }) + await clientInstance.acceptObolLatestTermsAndConditions(); + expect(isAuthorized).toEqual('successful authorization'); + }); test('createClusterDefinition should return config_hash', async () => { clientInstance['request'] = jest @@ -247,12 +249,15 @@ describe('Cluster Client without a signer', () => { ])( "$version: 'should return true on verified cluster lock'", async ({ clusterLock }) => { - const isValidLock: boolean = await validateClusterLock(clusterLock) - expect(isValidLock).toEqual(true) - }) + const isValidLock: boolean = await validateClusterLock(clusterLock); + expect(isValidLock).toEqual(true); + }, + ); test('Finds the hash of the latest version of terms and conditions', async () => { - const termsAndConditionsHash = await hashTermsAndConditions() - expect(termsAndConditionsHash).toEqual('0xd33721644e8f3afab1495a74abe3523cec12d48b8da6cb760972492ca3f1a273') - }) -}) + const termsAndConditionsHash = await hashTermsAndConditions(); + expect(termsAndConditionsHash).toEqual( + '0xd33721644e8f3afab1495a74abe3523cec12d48b8da6cb760972492ca3f1a273', + ); + }); +}); diff --git a/test/sdk-package-test/cluster.test.ts b/test/sdk-package-test/cluster.test.ts index 798a758..3ef77cf 100755 --- a/test/sdk-package-test/cluster.test.ts +++ b/test/sdk-package-test/cluster.test.ts @@ -14,8 +14,8 @@ import { app, postClusterDef, signer, - secondClient -} from './utils' + secondClient, +} from './utils'; import { type ClusterDefinition, Client, @@ -30,25 +30,25 @@ jest.setTimeout(10000); /* eslint @typescript-eslint/no-misused-promises: 0 */ // --> OFF describe('Cluster Definition', () => { - let configHash: string - let clusterDefinition: ClusterDefinition - let secondConfigHash: string + let configHash: string; + let clusterDefinition: ClusterDefinition; + let secondConfigHash: string; const clientWithoutAsigner = new Client({ baseUrl: 'https://obol-api-nonprod-dev.dev.obol.tech', chainId: 17000, }); - const unauthorisedClient = secondClient + const unauthorisedClient = secondClient; it('should post latest terms and conditions acceptance signature', async () => { - const isAuthorised = await client.acceptObolLatestTermsAndConditions() - expect(isAuthorised).toEqual('successful authorization') - }) + const isAuthorised = await client.acceptObolLatestTermsAndConditions(); + expect(isAuthorised).toEqual('successful authorization'); + }); it('should post a cluster definition and return confighash for an authorised user', async () => { - configHash = await client.createClusterDefinition(clusterConfigV1X8) - expect(configHash).toHaveLength(66) - }) + configHash = await client.createClusterDefinition(clusterConfigV1X8); + expect(configHash).toHaveLength(66); + }); it('should throw on post a cluster without a signer', async () => { try { @@ -62,12 +62,12 @@ describe('Cluster Definition', () => { it('should throw on post a cluster if the user did not sign latest terms and conditions', async () => { try { - await unauthorisedClient.createClusterDefinition(clusterConfigV1X8) + await unauthorisedClient.createClusterDefinition(clusterConfigV1X8); } catch (err: any) { - expect(err.message).toEqual('Missing t&c signature') - expect(err.statusCode).toEqual(401) + expect(err.message).toEqual('Missing t&c signature'); + expect(err.statusCode).toEqual(401); } - }) + }); it('should fetch the cluster definition for the configHash', async () => { clusterDefinition = await client.getClusterDefinition(configHash); @@ -87,24 +87,25 @@ describe('Cluster Definition', () => { configHash, ); } catch (err: any) { - expect(err.message).toEqual('Data not found') + expect(err.message).toEqual('Data not found'); } }); it('should throw on accept a cluster if the user did not sign latest terms and conditions', async () => { try { - await unauthorisedClient.acceptClusterDefinition({ enr, version: clusterDefinition.version }, + await unauthorisedClient.acceptClusterDefinition( + { enr, version: clusterDefinition.version }, configHash, - ) + ); } catch (err: any) { - expect(err.message).toEqual('Missing t&c signature') - expect(err.statusCode).toEqual(401) + expect(err.message).toEqual('Missing t&c signature'); + expect(err.statusCode).toEqual(401); } - }) + }); it('should update the cluster which the operator belongs to for an authorised user', async () => { - const signerAddress = await signer.getAddress() - clusterConfigV1X8.operators.push({ address: signerAddress }) + const signerAddress = await signer.getAddress(); + clusterConfigV1X8.operators.push({ address: signerAddress }); secondConfigHash = await client.createClusterDefinition(clusterConfigV1X8); diff --git a/test/sdk-package-test/utils.ts b/test/sdk-package-test/utils.ts index c18c323..80ee982 100644 --- a/test/sdk-package-test/utils.ts +++ b/test/sdk-package-test/utils.ts @@ -18,20 +18,20 @@ export const signer = wallet.connect(null); export const client: Client = new Client( { baseUrl: 'https://obol-api-nonprod-dev.dev.obol.tech', chainId: 17000 }, signer as any, -) +); -const secondMnemonic = ethers.Wallet.createRandom().mnemonic?.phrase ?? '' +const secondMnemonic = ethers.Wallet.createRandom().mnemonic?.phrase ?? ''; -const secondprivateKey = ethers.Wallet.fromPhrase(secondMnemonic).privateKey +const secondprivateKey = ethers.Wallet.fromPhrase(secondMnemonic).privateKey; -const secondWallet = new ethers.Wallet(secondprivateKey) +const secondWallet = new ethers.Wallet(secondprivateKey); -export const secondSigner = secondWallet.connect(null) +export const secondSigner = secondWallet.connect(null); export const secondClient: Client = new Client( { baseUrl: 'https://obol-api-nonprod-dev.dev.obol.tech', chainId: 17000 }, secondSigner as any, -) +); export const app = client.baseUrl;