UNPKG

@ravenrebels/ravencoin-jswallet

Version:
413 lines (411 loc) 11.7 kB
import RavencoinKey, { Network } from "@ravenrebels/ravencoin-key"; export interface ISettings { assets?: Array<string>; baseCurrency: "RVN"; mode: "RAVENCOIN_AND_ASSETS" | "ASSETS" | "SOME_ASSETS"; subTagline?: string; tagline: string; headline: string; } export interface ISend { amount: number; assetName?: string; toAddress: string; forcedUTXOs?: IForcedUTXO[]; forcedChangeAddressAssets?: string; forcedChangeAddressBaseCurrency?: string; } export type ChainType = Network | (string & {}); export interface IAddressDelta { address: string; assetName: string; blockindex: number; height: number; index: number; satoshis: number; txid: string; prevtxid?: string; } export interface ISendManyOptions { assetName?: string; outputs: { [key: string]: number; }; } export interface ISendManyTransactionOptions { assetName?: string; outputs: { [key: string]: number; }; wallet: Wallet; forcedUTXOs?: IForcedUTXO[]; forcedChangeAddressAssets?: string; forcedChangeAddressBaseCurrency?: string; } export interface ITransactionOptions { amount: number; assetName: string; toAddress: string; wallet: Wallet; forcedUTXOs?: IForcedUTXO[]; forcedChangeAddressAssets?: string; forcedChangeAddressBaseCurrency?: string; } export interface SweepResult { errorDescription?: string; fromAddress?: string; inputs?: Array<IInput>; outputs?: any; rawTransaction?: string; toAddresses?: string[]; transactionId?: string; UTXOs?: Array<IUTXO>; } export type TPrivateKey = { [key: string]: string; }; export interface ISendResult { transactionId: string | null; debug: { amount: number; assetName: string; error?: any; fee: number; inputs: Array<IVout_when_creating_transactions>; outputs: any; privateKeys?: TPrivateKey; rawUnsignedTransaction?: string; rvnAmount: number; rvnChangeAmount: number; signedTransaction?: string; UTXOs: IUTXO[]; walletMempool: any; }; } export interface Asset { name: string; amount: number; } export interface IHistory { inputs: Array<IHistoryTransaction>; outputs: Array<IHistoryTransaction>; } export interface IHistoryTransaction { blockhash: string; time: number; vout: IVout[]; vin: Vin[]; txid: string; } export interface ITransaction { c_asset?: string; c_amount_satoshis?: number; asset?: Asset; amount?: number; blockhash?: string; blocktime?: number; hex?: string; locktime: number; vin: Vin[]; hash: string; size: number; vsize: number; time?: number; txid: string; vout: IVout[]; version?: number; } export interface ISendInternalProps { amount: number; assetName: string; baseCurrency: string; changeAddress: string; changeAddressAssets?: string; fromAddressObjects: Array<IAddressMetaData>; network: ChainType; readOnly?: boolean; rpc: RPCType; toAddress: string; } export interface Vin { c_index?: number; address?: string; scriptSig: ScriptSig; sequence: number; txid: string; value: number; valueSat: number; vout: number; } export interface ScriptSig { asm: string; hex: string; } export interface IVout_when_creating_transactions { txid: string; vout: number; address: string; } export interface IVout { c_index?: number; value: number; n: number; scriptPubKey: ScriptPubKey; valueSat: number; } export interface ScriptPubKey { asm: string; hex: string; reqSigs: number; type: string; addresses: string[]; asset?: Asset; } export type IBalance = BalanceRoot[] | null; export interface BalanceRoot { assetName: string; balance: number; received: number; } export interface IValidateAddressResponse { isvalid: boolean; address: string; scriptPubKey: string; ismine: boolean; iswatchonly: boolean; isscript: boolean; } export interface IUTXO { address: string; assetName: string; height?: number; outputIndex: number; script: string; satoshis: number; txid: string; value: number; forced?: boolean; } export interface IAssetMetaData { assetName: string; } export type IAddressMetaData = ReturnType<typeof RavencoinKey.getAddressByPath>; export interface IUser { lastKnownUsedPosition?: number; id: string; mnemonic: string; displayName?: string; profileImageURL?: string; } export interface IConfig { raven_username: string; raven_password: string; raven_url: string; network: string; } export interface IInput { txid: string; vout: number; address?: string; } export type RPCType = (arg1: string, arg2: any[]) => any; export interface ITransactionOptions { amount: number; assetName: string; toAddress: string; wallet: Wallet; } export interface IOptions { mnemonic: string; minAmountOfAddresses?: number; network?: ChainType; rpc_username?: string; rpc_password?: string; rpc_url?: string; offlineMode?: boolean; } export interface IMempoolEntry { address: string; assetName: string; txid: string; index: number; satoshis: number; timestamp: number; prevtxid: string; prevout: number; } export interface IForcedUTXO { utxo: IUTXO; privateKey: string; address: string; } /** * SendManyTransaction Class * * This class is responsible for calculating the necessary steps to broadcast a Ravencoin transaction: * 1) Identify available UTXOs that are not already spent in the mempool. * 2) Determine the required number of UTXOs for creating this transaction. * 3) Define the transaction's inputs and outputs. * 4) Sign the transaction. * * Note: this class does not do the actual broadcasting; it is up to the user. * * How does it work? * 1) Create an instance: * const transaction = new SendManyTransaction({ * assetName, * outputs: options.outputs, * wallet: this, * }); * * 2) Load data from the network: * transaction.loadData(); */ export class SendManyTransaction { _allUTXOs: IUTXO[]; feerate: number; constructor(options: ISendManyTransactionOptions); /** * * @returns forced UTXOs for this transaction, that means "no matter want, spend this UTXO" */ getForcedUTXOs(): IForcedUTXO[]; getWalletMempool(): IMempoolEntry[]; getSizeInKB(): number; loadData(): Promise<void>; getAmount(): number; getUTXOs(): IUTXO[]; validate(): void; predictUTXOs(): IUTXO[]; getBaseCurrencyAmount(): number; getBaseCurrencyChange(): number; getAssetChange(): number; isAssetTransfer(): boolean; getOutputs(): Promise<Record<string, any>>; _getChangeAddressAssets(): Promise<string>; getInputs(): { address: string; txid: string; vout: number; }[]; getPrivateKeys(): Record<string, string>; getFee(): number; getFeeRate(): Promise<number>; } export class Transaction { constructor(options: ITransactionOptions); getWalletMempool(): IMempoolEntry[]; getSizeInKB(): number; loadData(): Promise<void>; getUTXOs(): IUTXO[]; predictUTXOs(): IUTXO[]; getBaseCurrencyAmount(): number; getBaseCurrencyChange(): number; getAssetChange(): number; isAssetTransfer(): boolean; getOutputs(): Promise<Record<string, any>>; getInputs(): { address: string; txid: string; vout: number; }[]; getPrivateKeys(): Record<string, string>; getFee(): number; getFeeRate(): Promise<number>; } declare function getBaseCurrencyByNetwork(network: ChainType): string; export class Wallet { rpc: (method: string, params: any[]) => Promise<any>; _mnemonic: string; network: ChainType; addressObjects: Array<IAddressMetaData>; receiveAddress: string; changeAddress: string; addressPosition: number; baseCurrency: string; offlineMode: boolean; setBaseCurrency(currency: string): void; getBaseCurrency(): string; /** * Sweeping a private key means to send all the funds the address holds to your your wallet. * The private key you sweep does not become a part of your wallet. * * NOTE: the address you sweep needs to cointain enough RVN to pay for the transaction * * @param WIF the private key of the address that you want move funds from * @returns either a string, that is the transaction id or null if there were no funds to send */ sweep(WIF: string, onlineMode: boolean): Promise<SweepResult>; getAddressObjects(): IAddressMetaData[]; getAddresses(): Array<string>; init(options: IOptions): Promise<void>; hasHistory(addresses: Array<string>): Promise<boolean>; _getFirstUnusedAddress(external: boolean): Promise<string>; getHistory(): Promise<IAddressDelta[]>; getMempool(): Promise<IMempoolEntry[]>; getReceiveAddress(): Promise<string>; getChangeAddress(): Promise<string>; /** * * @param assetName if present, only return UTXOs for that asset, otherwise for all assets * @returns UTXOs for assets */ getAssetUTXOs(assetName?: string): Promise<IUTXO[]>; getUTXOs(): Promise<any>; getPrivateKeyByAddress(address: string): string; sendRawTransaction(raw: string): Promise<string>; send(options: ISend): Promise<ISendResult>; sendMany({ outputs, assetName }: ISendManyOptions): Promise<ISendResult>; /** * Does all the heavy lifting regarding creating a SendManyTransaction * but it does not broadcast the actual transaction. * Perhaps the user wants to accept the transaction fee? * @param options * @returns An transaction that has not been broadcasted */ createTransaction(options: ISend): Promise<ISendResult>; /** * Does all the heavy lifting regarding creating a transaction * but it does not broadcast the actual transaction. * Perhaps the user wants to accept the transaction fee? * @param options * @returns An transaction that has not been broadcasted */ createSendManyTransaction(options: { assetName?: string; outputs: { [key: string]: number; }; }): Promise<ISendResult>; /** * This method checks if an UTXO is being spent in the mempool. * rpc getaddressutxos will list available UTXOs on the chain. * BUT an UTXO can be being spent by a transaction in mempool. * * @param utxo * @returns boolean true if utxo is being spent in mempool, false if not */ isSpentInMempool(utxo: IUTXO): Promise<boolean>; getAssets(): Promise<{ value: number; assetName: string; balance: number; received: number; }[]>; getBalance(): Promise<number>; convertMempoolEntryToUTXO(mempoolEntry: IMempoolEntry): Promise<IUTXO>; /** * Get list of spendable UTXOs in mempool. * Note: a UTXO in mempool can already be "being spent" * @param mempool (optional) * @returns list of UTXOs in mempool ready to spend */ getUTXOsInMempool(mempool?: IMempoolEntry[]): Promise<IUTXO[]>; } declare const _default: { createInstance: typeof createInstance; getBaseCurrencyByNetwork: typeof getBaseCurrencyByNetwork; }; export default _default; export function createInstance(options: IOptions): Promise<Wallet>; //# sourceMappingURL=types.d.ts.map