UNPKG

@cosmos-kit/terra-extension

Version:
42 lines 1.36 kB
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; import { OfflineSigner } from './signer'; import { fromBase64 } from '@cosmjs/encoding'; export class TerraClient { constructor(client) { _defineProperty(this, "client", void 0); this.client = client; } async disconnect() { this.client.disconnect(); } async getSimpleAccount(chainId) { const account = await this.getAccount(chainId); return { namespace: 'cosmos', chainId, address: account.address }; } async getAccount(chainId) { const account = await this.client.connect(); const infos = await this.client.info(); const networkInfo = infos[chainId]; if (!networkInfo) { return Promise.reject(`Unsupported chainId: ${chainId}. Please swap to ${chainId} network in Station Wallet.`); } const coinTypeByChainId = networkInfo.coinType; const accountPubkey = account.pubkey[coinTypeByChainId]; if (!accountPubkey) { return Promise.reject(`Can't find pubkey in Station Wallet.(Coin type: ${coinTypeByChainId})`); } return { address: account.address, algo: 'secp256k1', pubkey: fromBase64(accountPubkey) }; } async getOfflineSigner(chainId) { const accountInfo = await this.getAccount(chainId); return new OfflineSigner(this.client, accountInfo); } }