beignet / Wallet
- _customGetAddress
- _customGetScriptHash
- _data
- _disableMessagesOnCreate
- _getData
- _mnemonic
- _network
- _passphrase
- _pendingRefreshPromises
- _root
- _seed
- _setData
- addressType
- addressTypesToMonitor
- disableMessages
- electrum
- electrumOptions
- feeEstimates
- gapLimitOptions
- id
- isRefreshing
- isSwitchingNetworks
- name
- rbf
- savingOperations
- selectedFeeId
- sendMessage
- transaction
- _getAddress
- _handleRefreshError
- _resolveAllPendingRefreshPromises
- addAddresses
- addBoostedTransaction
- addGhostTransaction
- addTxInput
- addTxTag
- addUnconfirmedTransactions
- blockHeightToConfirmations
- checkElectrumConnection
- checkUnconfirmedTransactions
- clearAddresses
- clearTransactions
- clearUtxos
- confirmationsToBlockHeight
- connectToElectrum
- deleteOnChainTransactionById
- formatTransactions
- generateAddresses
- generateNewReceiveAddress
- getAddress
- getAddressBalance
- getAddressByPath
- getAddressFromScriptHash
- getAddressHistory
- getAddressIndexInfo
- getAddressInfoFromScriptHash
- getAddressesBalance
- getAddressesFromPrivateKey
- getBalance
- getBip32Interface
- getBitcoinNetwork
- getBoostableTransactions
- getBoostedTransactionParents
- getBoostedTransactions
- getChangeAddress
- getFeeEstimates
- getFeeInfo
- getGapLimit
- getHighestStoredAddressIndex
- getInputData
- getNextAvailableAddress
- getPrivateKey
- getPrivateKeyInfo
- getRbfData
- getReceiveAddress
- getScriptHash
- getScriptHashBalance
- getTransactionDetails
- getUnconfirmedTransactions
- getUtxos
- getWalletData
- getWalletDataKey
- isValid
- listUtxos
- processUnconfirmedTransactions
- refreshWallet
- removeDuplicateAddresses
- removeTxInput
- removeTxTag
- rescanAddresses
- resetAddressIndexes
- resetSendTransaction
- saveWalletData
- send
- sendMany
- sendMax
- setWalletData
- setZeroIndexAddresses
- setupFeeForOnChainTransaction
- setupTransaction
- storageIdCheck
- sweepPrivateKey
- switchNetwork
- updateAddressIndex
- updateAddressIndexes
- updateAddressType
- updateAndSaveWalletData
- updateFeeEstimates
- updateGapLimit
- updateGhostTransactions
- updateHeader
- updateTransactionHeights
- updateTransactions
- updateWalletBalance
- validateAddress
- create
• Private new Wallet(«destructured»)
| Name | Type |
|---|---|
«destructured» |
IWallet |
• Private Optional _customGetAddress: (data: ICustomGetAddress) => Promise<Result<IGetAddressResponse>>
▸ (data): Promise<Result<IGetAddressResponse>>
| Name | Type |
|---|---|
data |
ICustomGetAddress |
Promise<Result<IGetAddressResponse>>
• Private Optional _customGetScriptHash: (data: ICustomGetScriptHash) => Promise<string>
▸ (data): Promise<string>
| Name | Type |
|---|---|
data |
ICustomGetScriptHash |
Promise<string>
• Private _data: IWalletData
• Private _disableMessagesOnCreate: boolean
• Private _getData: TGetData
• Private Readonly _mnemonic: string
• Private _network: EAvailableNetworks
• Private Readonly _passphrase: string
• Private _pendingRefreshPromises: (result: Result<IWalletData>) => void[] = []
• Private Readonly _root: BIP32Interface
• Private Readonly _seed: Buffer
• Private Optional _setData: TSetData
• addressType: EAddressType
• addressTypesToMonitor: EAddressType[]
• disableMessages: boolean
• electrum: Electrum
• Optional electrumOptions: Object
| Name | Type |
|---|---|
batchDelay? |
number |
batchLimit? |
number |
net? |
Server |
servers? |
TServer | TServer[] |
tls? |
TLSSocket |
• feeEstimates: IOnchainFees
• gapLimitOptions: TGapLimitOptions
• Readonly id: string
• isRefreshing: boolean
• isSwitchingNetworks: boolean
• Readonly name: string
• rbf: boolean
• Private savingOperations: Record<string, Promise<string>> = {}
Saves the wallet data object to storage if able.
Async
Param
Param
• selectedFeeId: EFeeId
• sendMessage: TOnMessage
• transaction: Transaction
• get balance(): number
number
• get data(): IWalletData
• get network(): EAvailableNetworks
• get transactions(): IFormattedTransactions
• get unconfirmedTransactions(): IFormattedTransactions
• get utxos(): IUtxo[]
IUtxo[]
▸ Private _getAddress(path, addressType): Promise<Result<IGetAddressResponse>>
Returns the address for the specified path and address type.
| Name | Type |
|---|---|
path |
string |
addressType |
EAddressType |
Promise<Result<IGetAddressResponse>>
▸ Private _handleRefreshError(errorMessage): Result<IWalletData>
| Name | Type |
|---|---|
errorMessage |
string |
▸ Private _resolveAllPendingRefreshPromises(result): void
| Name | Type |
|---|---|
result |
Result<IWalletData> |
void
▸ Private addAddresses(«destructured»?): Promise<Result<IGenerateAddressesResponse>>
This method will generate addresses as specified and return an object of filtered addresses to ensure no duplicates are returned.
| Name | Type |
|---|---|
«destructured» |
IGenerateAddresses |
Promise<Result<IGenerateAddressesResponse>>
Async
▸ addBoostedTransaction(«destructured»): Promise<Result<IBoostedTransaction>>
Adds a boosted transaction id to the boostedTransactions object.
| Name | Type |
|---|---|
«destructured» |
Object |
› fee |
number |
› newTxId |
string |
› oldTxId |
string |
› type? |
EBoostType |
Promise<Result<IBoostedTransaction>>
▸ addGhostTransaction(txid): Promise<void>
Sets "exists" to false for a given on-chain transaction id.
| Name | Type |
|---|---|
txid |
Object |
txid.txid |
string |
Promise<void>
▸ addTxInput(input): Result<IUtxo[]>
Adds a specified input to the current transaction.
| Name | Type |
|---|---|
input |
Object |
input.input |
IUtxo |
▸ addTxTag(tag): Result<string>
Adds a specified tag to the current transaction.
| Name | Type |
|---|---|
tag |
Object |
tag.tag |
string |
Result<string>
▸ Private addUnconfirmedTransactions(transactions): Promise<Result<string>>
Parses and adds unconfirmed transactions to the store.
| Name | Type |
|---|---|
transactions |
Object |
transactions.transactions |
IFormattedTransactions |
Promise<Result<string>>
Async
▸ blockHeightToConfirmations(«destructured»): number
Returns the number of confirmations for a given block height.
| Name | Type |
|---|---|
«destructured» |
Object |
› blockHeight? |
number |
› currentHeight? |
number |
number
▸ checkElectrumConnection(): Promise<Result<string>>
Ensures the connection to Electrum is still available. Will attempt to reconnect if not initially available.
Promise<Result<string>>
▸ Private checkUnconfirmedTransactions(reorgDetected?): Promise<Result<string>>
Checks existing unconfirmed transactions that have been received and removes any that have >= 6 confirmations. If the tx is reorg'd or bumped from the mempool and no longer exists, the transaction will be removed from the store and updated in the activity list.
| Name | Type | Default value |
|---|---|---|
reorgDetected |
boolean |
false |
Promise<Result<string>>
Async
▸ Private clearAddresses(): Promise<string>
Clears the addresses and changeAddresses object for a given wallet and network.
Promise<string>
Async
▸ Private clearTransactions(): Promise<string>
Clears the transactions object for a given wallet and network from storage.
Promise<string>
▸ clearUtxos(): Promise<string>
Clears the UTXO array and balance from storage.
Promise<string>
Async
▸ confirmationsToBlockHeight(«destructured»): number
Returns the block height for a given number of confirmations from storage.
| Name | Type |
|---|---|
«destructured» |
Object |
› confirmations |
number |
› currentHeight? |
number |
number
▸ connectToElectrum(servers?): Promise<Result<string>>
Attempts to connect to the specified Electrum server(s).
| Name | Type |
|---|---|
servers? |
TServer | TServer[] |
Promise<Result<string>>
▸ deleteOnChainTransactionById(txid): Promise<void>
Deletes a given on-chain transaction by id.
| Name | Type |
|---|---|
txid |
Object |
txid.txid |
string |
Promise<void>
▸ formatTransactions(transactions): Promise<Result<IFormattedTransactions>>
Formats the provided transaction.
| Name | Type |
|---|---|
transactions |
Object |
transactions.transactions |
ITransaction<IUtxo>[] |
Promise<Result<IFormattedTransactions>>
Async
▸ generateAddresses(«destructured»): Promise<Result<IGenerateAddressesResponse>>
Generates a series of addresses based on the specified params.
| Name | Type |
|---|---|
«destructured» |
IGenerateAddresses |
Promise<Result<IGenerateAddressesResponse>>
Async
▸ generateNewReceiveAddress(«destructured»?): Promise<Result<IAddress>>
Generate a new receive address for the provided addresstype up to the set gap limit.
| Name | Type |
|---|---|
«destructured» |
Object |
› addressType? |
EAddressType |
› keyDerivationPath? |
IKeyDerivationPath |
› overrideGapLimit? |
boolean |
Async
▸ getAddress(«destructured»?): Promise<string>
Returns a single Bitcoin address based on the provided address type, index and whether it is a change address.
| Name | Type |
|---|---|
«destructured» |
IGetAddress |
Promise<string>
▸ getAddressBalance(address): Promise<Result<IGetAddressBalanceRes>>
Returns the address balance for the specified address.
| Name | Type |
|---|---|
address |
string |
Promise<Result<IGetAddressBalanceRes>>
▸ getAddressByPath(«destructured»): Promise<Result<IGetAddressResponse>>
Get address for a given keyPair, network and type.
| Name | Type |
|---|---|
«destructured» |
IGetAddressByPath |
Promise<Result<IGetAddressResponse>>
▸ getAddressFromScriptHash(scriptHash): undefined | IAddress
Returns the address from a provided script hash in storage.
| Name | Type |
|---|---|
scriptHash |
string |
undefined | IAddress
▸ getAddressHistory(address): Promise<Result<TTxResult[]>>
Returns an array of tx_hashes and their height for a given address.
| Name | Type |
|---|---|
address |
string |
▸ getAddressIndexInfo(): TAddressIndexInfo
Returns current address index information.
▸ getAddressInfoFromScriptHash(scriptHash): Result<{ address: IAddress ; addressType: EAddressType }>
| Name | Type |
|---|---|
scriptHash |
string |
Result<{ address: IAddress ; addressType: EAddressType }>
▸ getAddressesBalance(addresses?): Promise<Result<number>>
Returns combined balance of provided addresses.
| Name | Type | Default value |
|---|---|---|
addresses |
string[] |
[] |
Promise<Result<number>>
Async
▸ getAddressesFromPrivateKey(privateKey, _addressTypes?): Result<IGetAddressesFromPrivateKey>
Get addresses from a given private key.
| Name | Type |
|---|---|
privateKey |
string |
_addressTypes? |
EAddressType[] |
Result<IGetAddressesFromPrivateKey>
▸ getBalance(): number
Returns the known balance from storage.
number
▸ getBip32Interface(): Promise<Result<BIP32Interface>>
Creates a BIP32Interface from the selected wallet's mnemonic and passphrase
Promise<Result<BIP32Interface>>
▸ Private getBitcoinNetwork(network?): Network
Returns the Network object of the currently selected network (bitcoin or testnet).
| Name | Type |
|---|---|
network? |
TAvailableNetworks |
Network
▸ getBoostableTransactions(): Object
Returns an array of transactions that can be boosted with cpfp and rbf.
Object
| Name | Type |
|---|---|
cpfp |
IFormattedTransaction[] |
rbf |
IFormattedTransaction[] |
▸ getBoostedTransactionParents(«destructured»): string[]
Returns an array of parents for a boosted transaction id.
| Name | Type |
|---|---|
«destructured» |
Object |
› boostedTransactions? |
IBoostedTransactions |
› txid |
string |
string[]
▸ getBoostedTransactions(): IBoostedTransactions
Returns boosted transactions object.
▸ getChangeAddress(addressType?): Promise<Result<IAddress>>
Retrieves the next available change address data.
| Name | Type |
|---|---|
addressType? |
EAddressType |
Async
▸ getFeeEstimates(network?): Promise<IOnchainFees>
Returns the current fee estimates for the provided network.
| Name | Type |
|---|---|
network |
EAvailableNetworks |
Promise<IOnchainFees>
Async
▸ getFeeInfo(«destructured»?): Result<TGetTotalFeeObj>
Returns a fee object for the current transaction.
| Name | Type |
|---|---|
«destructured» |
Object |
› fundingLightning? |
boolean |
› message? |
string |
› satsPerByte? |
number |
› transaction? |
Partial<ISendTransaction> |
▸ Private getGapLimit(addressType?): Result<{ addressDelta: number ; changeAddressDelta: number }>
Returns the difference between the current address index and the last used address index.
| Name | Type |
|---|---|
addressType? |
Object |
addressType.addressType? |
EAddressType |
Result<{ addressDelta: number ; changeAddressDelta: number }>
▸ getHighestStoredAddressIndex(addressType): Result<{ addressIndex: IAddress ; changeAddressIndex: IAddress }>
Returns the highest address and change address index stored in the app for the specified wallet and network. Retrives the highest stored address index for the provided address type.
| Name | Type |
|---|---|
addressType |
Object |
addressType.addressType |
EAddressType |
Result<{ addressIndex: IAddress ; changeAddressIndex: IAddress }>
▸ getInputData(inputs): Promise<Result<InputData>>
Returns formatted input data from the inputs array.
| Name | Type |
|---|---|
inputs |
Object |
inputs.inputs |
{ tx_hash: string ; vout: number }[] |
Async
▸ getNextAvailableAddress(addressType?): Promise<Result<IGetNextAvailableAddressResponse>>
Returns the next available address for the given addresstype.
| Name | Type |
|---|---|
addressType? |
EAddressType |
Promise<Result<IGetNextAvailableAddressResponse>>
▸ getPrivateKey(path): string
Returns private key for the provided path.
| Name | Type |
|---|---|
path |
string |
string
▸ getPrivateKeyInfo(privateKey): Promise<Result<IPrivateKeyInfo>>
Returns the balance, utxos, and keyPair info for a given private key.
| Name | Type |
|---|---|
privateKey |
string |
Promise<Result<IPrivateKeyInfo>>
Async
▸ getRbfData(txHash): Promise<Result<IRbfData>>
Using a tx_hash this method will return the necessary data to create a replace-by-fee transaction for any 0-conf, RBF-enabled tx.
| Name | Type |
|---|---|
txHash |
Object |
txHash.txHash |
ITxHash |
▸ getReceiveAddress(addressType?): Promise<Result<string>>
Returns the next available receive address.
| Name | Type |
|---|---|
addressType? |
Object |
addressType.addressType? |
EAddressType |
Promise<Result<string>>
▸ getScriptHash(«destructured»): Promise<string>
Get scriptHash for a given address
| Name | Type |
|---|---|
«destructured» |
Object |
› address |
string |
› network |
EAvailableNetworks |
Promise<string>
▸ getScriptHashBalance(scriptHash): Promise<Result<IGetAddressBalanceRes>>
Returns the balance for the specified scriptHash.
| Name | Type |
|---|---|
scriptHash |
string |
Promise<Result<IGetAddressBalanceRes>>
▸ getTransactionDetails(tx_hash): Promise<Result<TTxDetails>>
Returns the transaction details for a given tx_hash.
| Name | Type |
|---|---|
tx_hash |
string |
Promise<Result<TTxDetails>>
▸ getUnconfirmedTransactions(): IFormattedTransactions
Returns the current wallet's unconfirmed transactions from storage.
▸ getUtxos(«destructured»?): Promise<Result<IGetUtxosResponse>>
Retrieves and sets UTXO's for the current wallet from Electrum.
| Name | Type |
|---|---|
«destructured» |
Object |
› addressIndex? |
number |
› addressTypesToCheck? |
EAddressType[] |
› changeAddressIndex? |
number |
› scanningStrategy? |
EScanningStrategy |
Promise<Result<IGetUtxosResponse>>
▸ getWalletData(): Promise<Result<IWalletData>>
Gets the wallet data object from storage if able. Otherwise, it falls back to the default wallet data object.
Promise<Result<IWalletData>>
▸ getWalletDataKey(key): string
Returns the key used for storing wallet data in the key/value pair.
| Name | Type |
|---|---|
key |
keyof IWalletData |
string
▸ isValid(mnemonic): boolean
Ensures the provided mnemonic matches the one stored in the wallet and is valid.
| Name | Type |
|---|---|
mnemonic |
any |
boolean
▸ listUtxos(): IUtxo[]
Returns the current wallet's UTXO's from storage.
IUtxo[]
▸ Private processUnconfirmedTransactions(): Promise<Result<TProcessUnconfirmedTransactions>>
This method processes all transactions with less than 6 confirmations and returns the following:
- Transactions that still have less than 6 confirmations and can be considered unconfirmed. (unconfirmedTxs)
- Transactions that have fewer confirmations than before due to a reorg. (outdatedTxs)
- Transactions that have been removed from the mempool. (ghostTxs)
Promise<Result<TProcessUnconfirmedTransactions>>
Async
▸ refreshWallet(scanAllAddresses?): Promise<Result<IWalletData>>
Refreshes/Syncs the wallet data.
| Name | Type |
|---|---|
scanAllAddresses? |
Object |
scanAllAddresses.scanAllAddresses |
undefined | boolean |
Promise<Result<IWalletData>>
▸ Private removeDuplicateAddresses(«destructured»): Promise<Result<IGenerateAddressesResponse>>
This method will compare a set of specified addresses to the currently stored addresses and remove any duplicates.
| Name | Type |
|---|---|
«destructured» |
Object |
› addresses? |
IAddresses |
› changeAddresses? |
IAddresses |
Promise<Result<IGenerateAddressesResponse>>
Async
▸ removeTxInput(input): Result<IUtxo[]>
Removes the specified input from the current transaction.
| Name | Type |
|---|---|
input |
Object |
input.input |
IUtxo |
▸ removeTxTag(tag): Result<string>
Removes a specified tag from the current transaction.
| Name | Type |
|---|---|
tag |
Object |
tag.tag |
string |
Result<string>
▸ rescanAddresses(«destructured»?): Promise<Result<IWalletData>>
This method will clear the utxo array for each address type and reset the address indexes back to the original/default app values. Once cleared & reset the app will rescan the wallet's addresses from index zero at the standard gap limit or higher (if previously set higher by the user).
| Name | Type |
|---|---|
«destructured» |
Object |
› shouldClearAddresses? |
boolean |
› shouldClearTransactions? |
boolean |
Promise<Result<IWalletData>>
Async
▸ Private resetAddressIndexes(): Promise<void>
Resets address indexes back to the app's default/original state.
Promise<void>
▸ resetSendTransaction(): Promise<Result<string>>
This completely resets the send transaction state.
Promise<Result<string>>
▸ saveWalletData<K>(key, data): Promise<string>
| Name | Type |
|---|---|
K |
extends keyof IWalletData |
| Name | Type |
|---|---|
key |
keyof IWalletData |
data |
IWalletData[K] |
Promise<string>
▸ send(«destructured»): Promise<Result<string>>
Sets up and creates a transaction to a single output/recipient.
| Name | Type |
|---|---|
«destructured» |
Object |
› address |
string |
› amount |
number |
› broadcast? |
boolean |
› message? |
string |
› rbf? |
boolean |
› satsPerByte? |
number |
› shuffleOutputs? |
boolean |
Promise<Result<string>>
Async
▸ sendMany(«destructured»): Promise<Result<string>>
Sets up and creates a transaction to multiple outputs.
| Name | Type |
|---|---|
«destructured» |
Object |
› broadcast? |
boolean |
› rbf? |
boolean |
› satsPerByte? |
number |
› shuffleOutputs? |
boolean |
› txs |
ISendTx[] |
Promise<Result<string>>
▸ sendMax(«destructured»?): Promise<Result<string>>
Sends the maximum amount of sats to a given address at the specified satsPerByte.
| Name | Type |
|---|---|
«destructured» |
Object |
› address? |
string |
› broadcast? |
boolean |
› rbf? |
boolean |
› satsPerByte? |
number |
Promise<Result<string>>
▸ Private setWalletData(): Promise<Result<boolean>>
Sets the wallet data object.
Promise<Result<boolean>>
▸ Private setZeroIndexAddresses(): Promise<Result<string>>
Will ensure that both address and change address indexes are set at index 0. Will also generate and store address and changeAddress at index 0.
Promise<Result<string>>
Async
▸ setupFeeForOnChainTransaction(«destructured»?): Result<string>
Updates the fee rate for the current transaction to the preferred value if none set.
| Name | Type |
|---|---|
«destructured» |
Object |
› satsPerByte? |
number |
› selectedFeeId? |
EFeeId |
Result<string>
▸ setupTransaction(params?): Promise<TSetupTransactionResponse>
Sets up the transaction object with existing inputs and change address information @async.
| Name | Type |
|---|---|
params |
ISetupTransaction |
Promise<TSetupTransactionResponse>
▸ Private storageIdCheck(id): Promise<Result<string>>
Ensure we are not overwriting wallet data of a different wallet by checking that the wallet id's match.
| Name | Type |
|---|---|
id |
string |
Promise<Result<string>>
Async
▸ sweepPrivateKey(«destructured»): Promise<Result<ISweepPrivateKeyRes>>
Sweeps a private key to a given address.
| Name | Type |
|---|---|
«destructured» |
ISweepPrivateKey |
Promise<Result<ISweepPrivateKeyRes>>
Async
▸ switchNetwork(network, servers?): Promise<Result<Wallet>>
| Name | Type |
|---|---|
network |
EAvailableNetworks |
servers? |
TServer | TServer[] |
▸ Private updateAddressIndex(addressType, isChangeAddress, index?): Promise<void>
Updates the address index for a given address type.
| Name | Type | Default value |
|---|---|---|
addressType |
EAddressType |
undefined |
isChangeAddress |
boolean |
undefined |
index? |
number |
0 |
Promise<void>
Async
▸ Private updateAddressIndexes(): Promise<Result<string>>
This method updates the next available (zero-balance) address & changeAddress index.
Promise<Result<string>>
Async
▸ updateAddressType(addressType): Promise<void>
Updates the address type for the current wallet.
| Name | Type |
|---|---|
addressType |
EAddressType |
Promise<void>
▸ Private updateAndSaveWalletData(key, data, addressType?): Promise<void>
| Name | Type |
|---|---|
key |
keyof IWalletData |
data |
IWalletData |
addressType? |
EAddressType |
Promise<void>
▸ updateFeeEstimates(forceUpdate?): Promise<Result<IOnchainFees>>
Updates the fee estimates for the current network.
| Name | Type | Default value | Description |
|---|---|---|---|
forceUpdate? |
boolean |
false |
Ignores the timestamp if set true and forces the update |
Promise<Result<IOnchainFees>>
Async
▸ updateGapLimit(gapLimitOptions): Result<TGapLimitOptions>
Allows the user to update the gap limit options.
| Name | Type |
|---|---|
gapLimitOptions |
TGapLimitOptions |
▸ Private updateGhostTransactions(txIds): Promise<Result<string>>
Removes transactions from the store and activity list.
| Name | Type |
|---|---|
txIds |
Object |
txIds.txIds |
string[] |
Promise<Result<string>>
Async
▸ updateHeader(headerData): Promise<void>
Updates & Saves header information to storage.
| Name | Type |
|---|---|
headerData |
IHeader |
Promise<void>
▸ Private updateTransactionHeights(txs): Promise<string>
Updates the confirmation state of activity item transactions that were reorg'd out.
| Name | Type |
|---|---|
txs |
IUtxo[] |
Promise<string>
Async
▸ updateTransactions(«destructured»?): Promise<Result<undefined | string>>
Retrieves, formats & stores the transaction history for the selected wallet/network.
| Name | Type |
|---|---|
«destructured» |
Object |
› replaceStoredTransactions? |
boolean |
› scanAllAddresses? |
boolean |
Promise<Result<undefined | string>>
▸ updateWalletBalance(balance): Result<string>
Used to temporarily update the balance until the Electrum server catches up after sending a transaction.
| Name | Type |
|---|---|
balance |
Object |
balance.balance |
number |
Result<string>
▸ validateAddress(address): boolean
Attempts to validate a given address.
| Name | Type |
|---|---|
address |
string |
boolean
▸ Static create(params): Promise<Result<Wallet>>
| Name | Type |
|---|---|
params |
IWallet |