UNPKG

@hashgraph/solo

Version:

An opinionated CLI tool to deploy and manage private Hedera Networks.

211 lines (210 loc) 11.6 kB
import { AccountId, type AccountInfo, Client, type Key, Long, PrivateKey } from '@hiero-ledger/sdk'; import { type SoloLogger } from './logging/solo-logger.js'; import { type K8Factory } from '../integration/kube/k8-factory.js'; import { type AccountIdWithKeyPairObject, type Optional } from '../types/index.js'; import { type NodeAlias, type NodeAliases } from '../types/aliases.js'; import { type NamespaceName } from '../types/namespace/namespace-name.js'; import { type ClusterReferences, type DeploymentName } from './../types/index.js'; import { type NodeServiceMapping } from '../types/mappings/node-service-mapping.js'; import { LocalConfigRuntimeState } from '../business/runtime-state/config/local/local-config-runtime-state.js'; import { type RemoteConfigRuntimeStateApi } from '../business/runtime-state/api/remote-config-runtime-state-api.js'; export declare class AccountManager { private readonly logger?; private readonly k8Factory?; private readonly remoteConfig?; private readonly localConfig?; private _portForwards; private _forcePortForward; _nodeClient: Optional<Client>; constructor(logger?: SoloLogger, k8Factory?: K8Factory, remoteConfig?: RemoteConfigRuntimeStateApi, localConfig?: LocalConfigRuntimeState); /** * Gets the account keys from the Kubernetes secret from which it is stored * @param accountId - the account ID for which we want its keys * @param namespace - the namespace storing the secret */ getAccountKeysFromSecret(accountId: string, namespace: NamespaceName): Promise<AccountIdWithKeyPairObject>; /** * Gets the treasury account private key from Kubernetes secret if it exists, else * returns the Genesis private key, then will return an AccountInfo object with the * accountId, ed25519PrivateKey, publicKey * @param namespace - the namespace that the secret is in * @param deploymentName */ getTreasuryAccountKeys(namespace: NamespaceName, deploymentName: DeploymentName): Promise<AccountIdWithKeyPairObject>; /** * batch up the accounts into sets to be processed * @param [accountRange] * @returns an array of arrays of numbers representing the accounts to update */ batchAccounts(accountRange?: number[][]): number[][]; /** stops and closes the port forwards and the _nodeClient */ close(): Promise<void>; /** * loads and initializes the Node Client * @param namespace - the namespace of the network * @param clusterReferences - the cluster references * @param [deployment] - k8 deployment name * @param [forcePortForward] - whether to force the port forward */ loadNodeClient(namespace: NamespaceName, clusterReferences: ClusterReferences, deployment: DeploymentName, forcePortForward?: boolean): Promise<Client>; /** * loads and initializes the Node Client, throws a SoloError if anything fails * @param namespace - the namespace of the network * @param clusterReferences - the cluster references * @param skipNodeAlias - the node alias to skip * @param deployment - the deployment name * @param [forcePortForward] - whether to force the port forward */ refreshNodeClient(namespace: NamespaceName, clusterReferences: ClusterReferences, skipNodeAlias: NodeAlias, deployment: DeploymentName, forcePortForward?: boolean): Promise<Client>; /** * if the load balancer IP is not set, then we should use the local host port forward * @param networkNodeServices * @returns whether to use the local host port forward */ private shouldUseLocalHostPortForward; /** * Returns a node client that can be used to make calls against * @param namespace - the namespace for which the node client resides * @param networkNodeServicesMap - a map of the service objects that proxy the nodes * @param operatorId - the account id of the operator of the transactions * @param operatorKey - the private key of the operator of the transactions * @param skipNodeAlias - the node alias to skip * @returns a node client that can be used to call transactions */ _getNodeClient(namespace: NamespaceName, networkNodeServicesMap: NodeServiceMapping, operatorId: string, operatorKey: string, skipNodeAlias: string): Promise<Client>; private configureNodeAccess; /** * pings the network node to ensure that the connection is working * @param object - the object containing the network node endpoint and account id * @param accountId - the account id to ping * @throws {@link SoloError} if the ping fails */ private testNodeClientConnection; /** * Gets a Map of the Hedera node services and the attributes needed, throws a SoloError if anything fails * @param namespace - the namespace of the solo network deployment * @param clusterReferences - the cluster references to use for the services * @param deployment - the deployment to use * @returns a map of the network node services */ getNodeServiceMap(namespace: NamespaceName, clusterReferences: ClusterReferences, deployment: DeploymentName): Promise<NodeServiceMapping>; /** * updates a set of special accounts keys with a newly generated key and stores them in a Kubernetes secret * @param namespace the namespace of the nodes network * @param currentSet - the accounts to update * @param updateSecrets - whether to delete the secret prior to creating a new secret * @param resultTracker - an object to keep track of the results from the accounts that are being updated * @param deploymentName - the deployment name * @returns the updated resultTracker object */ updateSpecialAccountsKeys(namespace: NamespaceName, currentSet: number[], updateSecrets: boolean, resultTracker: { skippedCount: number; rejectedCount: number; fulfilledCount: number; }, deploymentName: DeploymentName): Promise<{ skippedCount: number; rejectedCount: number; fulfilledCount: number; }>; /** * update the account keys for a given account and store its new key in a Kubernetes secret * @param namespace - the namespace of the nodes network * @param accountId - the account that will get its keys updated * @param genesisKey - the genesis key to compare against * @param updateSecrets - whether to delete the secret before creating a new secret * @returns the result of the call */ updateAccountKeys(namespace: NamespaceName, accountId: AccountId, genesisKey: PrivateKey, updateSecrets: boolean): Promise<{ value: string; status: string; } | { reason: string; value: string; status: string; }>; /** * creates or replaces the Kubernetes secret for the account key * @param privateKey - the private key to store in the secret * @param accountId - the account id for which to create the secret * @param updateSecrets - whether to replace the secret if it exists * @param namespace - the namespace in which to create the secret */ createOrReplaceAccountKeySecret(privateKey: PrivateKey, accountId: AccountId, updateSecrets: boolean, namespace: NamespaceName): Promise<void>; /** * gets the account info from Hedera network * @param accountId - the account * @returns the private key of the account */ accountInfoQuery(accountId: AccountId | string): Promise<AccountInfo>; /** * gets the account private and public key from the Kubernetes secret from which it is stored * @param accountId - the account * @returns the private key of the account */ getAccountKeys(accountId: AccountId | string): Promise<Key[]>; /** * send an account key update transaction to the network of nodes * @param accountId - the account that will get its keys updated * @param newPrivateKey - the new private key * @param oldPrivateKey - the genesis key that is the current key * @returns whether the update was successful */ sendAccountKeyUpdate(accountId: AccountId | string, newPrivateKey: PrivateKey | string, oldPrivateKey: PrivateKey | string): Promise<boolean>; /** * creates a new Hedera account * @param namespace - the namespace to store the Kubernetes key secret into * @param privateKey - the private key of type PrivateKey * @param amount - the amount of HBAR to add to the account * @param [setAlias] - whether to set the alias of the account to the public key, requires the ed25519PrivateKey supplied to be ECDSA * @param context * @returns a custom object with the account information in it */ createNewAccount(namespace: NamespaceName, privateKey: PrivateKey, amount: number, setAlias: boolean, context: string): Promise<{ accountId: string; privateKey: string; publicKey: string; balance: number; accountAlias?: string; }>; /** * transfer the specified amount of HBAR from one account to another * @param fromAccountId - the account to pull the HBAR from * @param toAccountId - the account to put the HBAR * @param hbarAmount - the amount of HBAR * @returns if the transaction was successfully posted */ transferAmount(fromAccountId: AccountId | string, toAccountId: AccountId | string, hbarAmount: number): Promise<boolean>; /** * Fetch and prepare address book as a base64 string */ prepareAddressBookBase64(namespace: NamespaceName, clusterReferences: ClusterReferences, deployment: DeploymentName, operatorId: string, operatorKey: string, forcePortForward: boolean): Promise<string>; getFileContents(namespace: NamespaceName, fileNumber: number, clusterReferences: ClusterReferences, deployment?: DeploymentName, forcePortForward?: boolean): Promise<string>; /** * Build and prepare address book as a base64 string by reading gossip signing keys from the * local keys directory and node topology from RemoteConfig. * This method does not require Kubernetes services or secrets to exist yet, making it suitable * for use during simultaneous consensus node + mirror node deployment. * @param keysDirectory - path to the directory containing gossip key PEM files (e.g. ~/.solo/cache/keys) * @param deployment - deployment name, used to derive per-node account IDs */ buildAddressBookBase64(keysDirectory: string, deployment: DeploymentName): Promise<string>; /** * Pings the network node with a grpc call to ensure it is working, throws a SoloError if the ping fails * @param obj - the network node object where the key is the network endpoint and the value is the account id * @param accountId - the account id to ping * @throws {@link SoloError} if the ping fails */ private sdkPingNetworkNode; getAccountIdByNumber(deployment: DeploymentName, number: number | Long): AccountId; getOperatorAccountId(deployment: DeploymentName): AccountId; getFreezeAccountId(deployment: DeploymentName): AccountId; getTreasuryAccountId(deployment: DeploymentName): AccountId; getStartAccountId(deployment: DeploymentName): AccountId; /** * Create a map of node aliases to account IDs * @param nodeAliases * @param deploymentName * @returns the map of node IDs to account IDs */ getNodeAccountMap(nodeAliases: NodeAliases, deploymentName: DeploymentName): Map<NodeAlias, string>; }