@koralabs/cardano-wallets
Version:
Library for connecting cardano wallets in the browser using CIP-30
197 lines (196 loc) • 6.09 kB
TypeScript
import { EnabledWallet, Wallet } from '../interfaces/Wallet';
import { Utxo } from '../interfaces/Utxo';
import { Paginate } from '../interfaces/Paginate';
import { BuildTransactionInput } from '../interfaces/BuildTransactionInput';
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;
/**
*
* Helper function to add supported wallets.
* If none are added, all wallets are supported
*
* @param wallets string[], e.g. ['nami', 'eternal'] (window.cardano[key])
*
*/
static addSupportedWallets(wallets: string[]): void;
static setAdditionalWalletData(data: Record<string, string>): void;
/**
*
* 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
*/
static validateWallet(walletKey: string): void;
/**
*
* 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>;
static getWalletDetailsFromStorage(): any;
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<number>;
/**
*
* 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<any>;
/**
*
* 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>;
/**
*
* Fetches the wallet balance and converts it to ADA
*
* @returns number
*/
static getAdaBalance(): Promise<number>;
/**
*
* 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>;
/**
*
* Gets bech32 addresses from UTxOs
*
* @returns string[]
*/
static getUtxoBech32Addresses(): Promise<string[]>;
/**
*
* 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[]>;
static buildTransaction({ paymentDetails, feeDetails }: BuildTransactionInput): Promise<{
txHash: string;
tx: string;
}>;
static signTransaction(tx: string): Promise<string>;
static submitSignedTransaction(signedTxHex: string): Promise<string>;
static signAndSubmitTransaction(tx: string): Promise<string>;
}