import { AddSignature, SigHashType } from './sig'; import { BitcoinNetwork, IBitcoinProvider, Urgency } from './provider.interface'; import { IBaseWallet } from '../baseWallet'; import { Network, networks, payments } from 'bitcoinjs-lib'; /** * @interface IBitcoinWallet */ export interface IBitcoinWallet extends IBaseWallet { /** * @returns {Promise} Balance held by the wallet in satoshis. */ getBalance(): Promise; /** * @returns {Promise} Public key of the wallet */ getPublicKey(): Promise; /** * @returns {Promise} Network of the wallet provided during initialization */ getNetwork(): Promise; /** * @returns {Promise} Provider of the wallet that gives read only access to the mempool */ getProvider(): Promise; /** * Fee for a transaction according to the urgency * * @param {number} amount - in satoshis * @param {Urgency} urgency - urgency of the fee * @returns {Promise} Fee suggested by the provider */ suggestFee(amount: number, urgency: Urgency): Promise; signSchnorr(buf: Buffer): Promise; /** * Sends bitcoins to a recipient * * @param {string} toAddress - Address of the recipient * @param {number} amt - in satoshis * @param {number} [fee] * @returns {Promise} Tx id of the sent transaction */ send(toAddress: string, amt: number, fee?: number): Promise; /** * Spends bitcoin from a script to a given address. * * @param {Buffer} script - The locking script * @param {Buffer[]} witness - The witnesses * @param {string} [toAddress] - The address of the recipient. If not provided then the wallet address is used as the recipient. * @param {number} [nSequence] - The sequence number * @returns {Promise} Transaction ID */ spend(script: Buffer, scriptAddress: string, { toAddress, fee, nSequence, unlockScript, // only for p2sh witness, }: { toAddress?: string; fee?: number; nSequence?: number; witness?: (Buffer | AddSignature)[]; unlockScript?: (payments.StackElement | AddSignature)[]; }): Promise; /** * @returns {BitcoinWalletConfig} */ walletConfig(): BitcoinWalletConfig; addSignatureSegwitV0(type?: SigHashType): AddSignature; addSignatureP2sh(type?: SigHashType): AddSignature; addSignatureSegwitV1(type?: SigHashType): AddSignature; } /** * @typedef {Object} BitcoinWalletConfig * * @property {Network} network - The network of the wallet * @property {string} path - The derivation path */ export type BitcoinWalletConfig = { network: BitcoinNetwork; path: string; addressType?: string; }; export { Network, networks };