UNPKG

@tatumio/utxo-wallet-provider

Version:

UTXO provider with local wallet operations

182 lines (181 loc) 6.21 kB
import { Transaction } from 'bitcore-lib'; export type XpubWithMnemonic = { xpub: string; mnemonic: string; derivationPath: string; }; export type UtxoWallet = { address: string; privateKey: string; mnemonic: string; }; interface Bip32 { public: number; private: number; } export interface NetworkConfig { messagePrefix: string; bech32: string; bip32: Bip32; pubKeyHash: number; scriptHash: number; wif: number; } export interface BtcBasedTransaction extends Transaction { serialize(unchecked?: boolean): string; } export type UtxoTxPayload = TransactionFromAddress | TransactionFromUTXO; export type TransactionFromAddress = { /** * The array of blockchain addresses to send the assets from and their private keys. For each address, the last 100 transactions are scanned for any UTXO to be included in the transaction. */ fromAddress: Array<TransactionFromAddressSource>; /** * The array of blockchain addresses to send the assets to and the amounts that each address should receive. The difference between the UTXOs calculated in the <code>fromAddress</code> section and the total amount to receive calculated in the <code>to</code> section will be used as the gas fee. To explicitly specify the fee amount and the blockchain address where any extra funds remaining after covering the fee will be sent, set the <code>fee</code> and <code>changeAddress</code> parameters. */ to: Array<TransactionTarget>; /** * The fee to be paid for the transaction; if you are using this parameter, you have to also use the <code>changeAddress</code> parameter because these two parameters only work together. */ fee?: string; /** * The blockchain address to send any extra assets remaining after covering the fee to; if you are using this parameter, you have to also use the <code>fee</code> parameter because these two parameters only work together. */ changeAddress?: string; }; export type TransactionFromUTXO = { /** * The array of transaction hashes, indexes of its UTXOs, and the private keys of the associated blockchain addresses */ fromUTXO: Array<TransactionFromUTXOSource>; /** * The array of blockchain addresses to send the assets to and the amounts that each address should receive. The difference between the UTXOs calculated in the <code>fromUTXO</code> section and the total amount to receive calculated in the <code>to</code> section will be used as the gas fee. To explicitly specify the fee amount and the blockchain address where any extra funds remaining after covering the fee will be sent, set the <code>fee</code> and <code>changeAddress</code> parameters. */ to: Array<TransactionTarget>; /** * The fee to be paid for the transaction; if you are using this parameter, you have to also use the <code>changeAddress</code> parameter because these two parameters only work together. */ fee?: string; /** * The blockchain address to send any extra assets remaining after covering the fee; if you are using this parameter, you have to also use the <code>fee</code> parameter because these two parameters only work together. */ changeAddress?: string; }; export type TransactionFromAddressSource = { /** * The blockchain address to send the assets from */ address: string; /** * The private key of the address to send the assets from */ privateKey: string; }; export type TransactionTarget = { /** * The blockchain address to receive the assets */ address: string; /** * The amount to receive */ value: number; }; export type TransactionFromUTXOSource = { /** * The transaction hash of the UTXO to be spent */ txHash: string; /** * The index of the UTXO to be spent */ index: number; /** * The private key of the blockchain address that holds the UTXO to be spent */ privateKey: string; }; export type UTXO = { /** * The version of the transaction */ version?: number; /** * The height (number) of the block where the transaction is included in */ height?: number; /** * The amount of the UTXO (in satoshis) */ value?: number; /** * Data generated by the spender; is almost always used as variables to satisfy the conditions in the pubkey script */ script?: string; /** * The blockchain address of the UTXO owner */ address?: string; /** * If set to "true", the transaction is a coinbase transaction (a transaction created by a Bitcoin miner to collect their reward) */ coinbase?: boolean; /** * The hash of the transaction */ hash?: string; /** * The index of the transaction output checked for the UTXO */ index?: number; }; export interface DogeUTXO { confirmations: number; coinbase: boolean; bestblock: string; version: number; value: number; n: number; scriptPubKey: { asm: string; hex: string; regSigs: number; type: string; addresses: string[]; }; } export type FeeBtcBased = { /** * Transaction fee in BTC|LTC to be paid, if transaction should be included in next 1-2 blocks. */ fast: string; /** * Transaction fee in BTC|LTC to be paid, if transaction should be included in next 5-6 blocks. */ medium: string; /** * Transaction fee in BTC|LTC to be paid, if transaction should be included in next 7+ blocks. */ slow: string; }; export type UtxoResponse = Array<{ chain: ChainUtxoEnum; /** * Address of the UTXO */ address: string; /** * Hash of the transaction this UTXO is present in */ txHash: string; /** * Index of the UTXO in the transaction */ index: number; /** * Value of the UTXO, in BTC, LTC or DOGE. */ value: number; }>; export type ChainUtxoEnum = 'bitcoin' | 'bitcoin-testnet' | 'bitcoin-mainnet' | 'litecoin' | 'litecoin-mainnet' | 'litecoin-testnet' | 'doge' | 'doge-mainnet' | 'doge-testnet'; export {};