Skip to content

Commit

Permalink
support v1.8.0 (#31)
Browse files Browse the repository at this point in the history
* support v1.8.0

* remove not needed function

* add tests for v1.8.0

* test to validate  v1.7.0 lock

* add tests for deposit_amounts

* deposit amounts validation

* clean the code

* fix lint errors

* use v1.7.0 for creation

* add v1.6.0 data

* fix lint errors

* format cleaning
  • Loading branch information
HananINouman authored Mar 18, 2024
1 parent 0f1252f commit 9905321
Show file tree
Hide file tree
Showing 20 changed files with 1,916 additions and 1,104 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@obolnetwork/obol-sdk",
"version": "1.0.12",
"version": "1.0.13",
"description": "A package for creating Distributed Validators using the Obol API.",
"bugs": {
"url": "https://github.com/obolnetwork/obol-sdk/issues"
Expand Down Expand Up @@ -51,6 +51,7 @@
"ethers": "^6.4.0",
"nock": "^13.5.3",
"release-it": "^17.1.1",
"semver": "^7.6.0",
"typescript-eslint": "^7.1.0",
"uuid": "^9.0.0"
},
Expand Down
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,5 @@ export enum DefinitionFlow {

export const DEFAULT_BASE_URL = 'https://api.obol.tech'
export const DEFAULT_CHAIN_ID = 1

export const ETHER_TO_GWEI = 10 ** 9
256 changes: 0 additions & 256 deletions src/hash.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
type ClusterPayload,
type OperatorPayload,
} from './types.js'
import { clusterConfigOrDefinitionHash } from './hash.js'
import { clusterConfigOrDefinitionHash } from './verification/common.js'
import { validatePayload } from './ajv.js'
import { definitionSchema, operatorPayloadSchema } from './schema.js'
export * from './types.js'
Expand Down
2 changes: 1 addition & 1 deletion src/services.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type ClusterLock } from './types.js'
import { isValidClusterLock } from './verify.js'
import { isValidClusterLock } from './verification/common.js'

/**
* Verifies Cluster Lock's validity.
Expand Down
19 changes: 14 additions & 5 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,11 @@ export interface ClusterPayload {
/** The cluster nodes operators addresses. */
operators: ClusterOperator[]

/** The clusters validators information. */
/** The cluster validators information. */
validators: ClusterValidator[]

/** The cluster partial deposits in gwei or 32000000000. */
deposit_amounts?: string[]
}

/**
Expand Down Expand Up @@ -110,6 +113,9 @@ export interface ClusterDefintion extends ClusterPayload {
/** The number of distributed validators in the cluster. */
num_validators: number

/** The cluster partial deposits in gwei or 32000000000. */
deposit_amounts?: string[]

/** The hash of the cluster definition. */
definition_hash?: string
}
Expand Down Expand Up @@ -172,11 +178,14 @@ export interface DistributedValidator {
/** The public key of the node distributed validator share. */
public_shares: string[]

/** The required deposit data for activating the DV. */
deposit_data: Partial<DepositData>
/** The deposit data for activating the DV. */
deposit_data?: Partial<DepositData>

/** The deposit data with partial amounts or full amount for activating the DV. */
partial_deposit_data?: Array<Partial<DepositData>>

/** pre-generated signed validator builder registration to be sent to builder network. */
builder_registration: BuilderRegistration
builder_registration?: BuilderRegistration
}

/**
Expand All @@ -196,5 +205,5 @@ export interface ClusterLock {
lock_hash: string

/** Node Signature for the lock hash by the node secp256k1 key. */
node_signatures: string[]
node_signatures?: string[]
}
49 changes: 49 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,56 @@
import { DefinitionFlow } from './constants'
import { type ClusterDefintion } from './types'

export const hexWithout0x = (hex: string): string => {
return hex.slice(2, hex.length)
}

export const strToUint8Array = (str: string): Uint8Array => {
return new TextEncoder().encode(str)
}

export const definitionFlow = (
clusterDefinition: ClusterDefintion,
): DefinitionFlow | null => {
if (
clusterDefinition.creator.address &&
clusterDefinition.creator.config_signature &&
clusterDefinition.operators.every((operator) => {
return (
operator.address &&
operator.config_signature &&
operator.enr &&
operator.enr_signature
)
})
) {
return DefinitionFlow.Group
} else if (
clusterDefinition.creator.address &&
clusterDefinition.creator.config_signature &&
clusterDefinition.operators.every((operator) => {
return (
!operator.address &&
!operator.config_signature &&
operator.enr &&
!operator.enr_signature
)
})
) {
return DefinitionFlow.Solo
} else if (
!clusterDefinition.creator.address &&
!clusterDefinition.creator.config_signature &&
clusterDefinition.operators.every((operator) => {
return (
!operator.address &&
!operator.config_signature &&
operator.enr &&
!operator.enr_signature
)
})
) {
return DefinitionFlow.Charon
}
return null
}
Loading

0 comments on commit 9905321

Please sign in to comment.