UNPKG

@koralabs/cardano-wallets

Version:

Library for connecting cardano wallets in the browser using CIP-30

171 lines (170 loc) 5.17 kB
import { EnabledWallet, Wallet } from '../interfaces/Wallet'; import { Utxo } from '../interfaces/Utxo'; import { Paginate } from '../interfaces/Paginate'; export declare class CardanoWallets { static _enabledWallet: EnabledWallet; static wallet: Wallet; static localStorageKey: string; static supportedWalletNames: string[]; /** * * Used to set the wallet in local storage * * @param walletKey string */ private static _setWallet; /** * * Uses CIP-30 'enable' function to enable the wallet * * @param wallet Wallet to enable * @returns */ private static _enableWallet; /** * * Validation method used to check if the wallet is supported * * @param walletKey string */ private static validateSupportedWallet; /** * * Validation method used to check the window.cardano object * * @param walletKey string */ private static validateWallet; /** * * Used to enable the wallet and set the wallet in local storage * * @param walletKey string e.g. 'nami', 'eternal', etc * @returns an enabled wallet */ static connect(walletKey: string): Promise<Wallet>; /** * * Gets the wallet from local storage if available. If not, method will return null * * @returns an enabled wallet or null */ static getWallet(): Promise<Wallet | null>; static disableWallet: () => Promise<void>; /** * * CIP-30 method to check if wallet is enabled * https://cips.cardano.org/cips/cip30/#cardanowalletnameisenabledpromisebool * * @returns CIP-30 Wallet */ static isWalletEnabled: () => Promise<boolean>; /** * * CIP-30 method to get the balance of the wallet * https://cips.cardano.org/cips/cip30/#apigetbalancepromisecborvalue * * @returns balanceHex */ static getBalance: () => Promise<string>; /** * * CIP-30 method to get the network id of the wallet * https://cips.cardano.org/cips/cip30/#apigetnetworkidpromisenumber * * @returns 0 or 1 (0 = testnet, 1 = mainnet) */ static getNetworkId: () => Promise<string>; /** * * CIP-30 method to get the UTXOs of the wallet * https://cips.cardano.org/cips/cip30/#apigetutxosamountcborvalueundefinedpaginatepaginateundefinedpromisetransactionunspentoutputnull * * @returns an array of hex encoded utxos */ static getUtxos: (amount?: string, paginate?: Paginate) => Promise<string[]>; /** * * CIP-30 method to get wallet collateral * https://cips.cardano.org/cips/cip30/#apigetcollateralparamsamountcborcoinpromisetransactionunspentoutputnull * * @returns list of Utxos */ static getCollateral: () => Promise<string[]>; /** * * CIP-30 method to get unused addresses * https://cips.cardano.org/cips/cip30/#apigetunusedaddressespromiseaddress * * @returns list of unused addresses */ static getUnusedAddresses: () => Promise<string[]>; /** * * CIP-30 method to get a change address * https://cips.cardano.org/cips/cip30/#apigetchangeaddresspromiseaddress * * @returns change address */ static getChangeAddress: () => Promise<string>; /** * * CIP-30 method to get a reward address * https://cips.cardano.org/cips/cip30/#apigetrewardaddressespromiseaddress * * @returns a reward address */ static getRewardAddresses: () => Promise<string[]>; /** * * CIP-30 method to get a sign a transaction * https://cips.cardano.org/cips/cip30/#apisigntxtxcbortransactionpartialsignboolfalsepromisecbortransaction_witness_set * * @param tx hex encoded transaction * @param partialSign boolean * @returns */ static signTx: (tx: string, partialSign?: boolean) => Promise<unknown>; /** * * CIP-30 method to submit a transaction * https://cips.cardano.org/cips/cip30/#apisubmittxtxcbortransactionpromisehash32 * * @param tx hex encoded transaction * @returns transaction id */ static submitTx: (tx: string) => Promise<string>; /** * * Uses the CIP-30 getNetworkId to check if wallet is in mainnet or testnet * * @returns boolean */ static isMainnet: () => Promise<boolean>; /** * * Used to verify that a wallet has the minimum necessary funds * * @param minimumBalance number */ static verifyBalance: (minimumBalance: number) => Promise<void>; /** * * Used to verify a wallet is actively staked * * @param { rewardAddress: string } * @returns void if staked, throws NotDelegated error if not * */ static verifyStaking({ rewardAddress }: { rewardAddress: string; }): Promise<void>; /** * * Uses the serialization library to convert hex encoded utxos to human readable values * * @param rawUtxos Raw utxos from getUtxos() * @returns Utxo[] */ static buildUtxos(rawUtxos: string[]): Promise<Utxo[]>; }