Class: AccountManager
The AccountManager class.
Table of contents
Methods
- backup
- bech32ToHex
- changeStrongholdPassword
- clearStrongholdPassword
- createAccount
- destroy
- emitTestEvent
- generateMnemonic
- getAccount
- getAccountIndexes
- getAccounts
- generateAddress
- getNodeInfo
- getLedgerNanoStatus
- hexToBech32
- isStrongholdPasswordAvailable
- listen
- clearListeners
- recoverAccounts
- removeLatestAccount
- restoreBackup
- setClientOptions
- setStrongholdPassword
- setStrongholdPasswordClearInterval
- startBackgroundSync
- stopBackgroundSync
- storeMnemonic
- verifyMnemonic
- updateNodeAuth
Methods
backup
▸ backup(destination
, password
): Promise
<void
>
Backup the data to a Stronghold snapshot.
Parameters
Name | Type |
---|---|
destination | string |
password | string |
Returns
Promise
<void
>
bech32ToHex
▸ bech32ToHex(bech32Address
): Promise
<string
>
Transform a bech32 encoded address to a hex encoded address
Parameters
Name | Type |
---|---|
bech32Address | string |
Returns
Promise
<string
>
changeStrongholdPassword
▸ changeStrongholdPassword(currentPassword
, newPassword
): Promise
<void
>
Change the Stronghold password.
Parameters
Name | Type |
---|---|
currentPassword | string |
newPassword | string |
Returns
Promise
<void
>
clearStrongholdPassword
▸ clearStrongholdPassword(): Promise
<void
>
Clear the Stronghold password from memory.
Returns
Promise
<void
>
createAccount
▸ createAccount(payload
): Promise
<Account
>
Create a new account.
Parameters
Name | Type |
---|---|
payload | CreateAccountPayload |
Returns
Promise
<Account
>
destroy
▸ destroy(): Promise
<void
>
Destroy the AccountManager and drop its database connection.
Returns
Promise
<void
>
emitTestEvent
▸ emitTestEvent(event
): Promise
<void
>
Emit a provided event for testing of the event system.
Parameters
Name | Type |
---|---|
event | WalletEvent |
Returns
Promise
<void
>
generateMnemonic
▸ generateMnemonic(): Promise
<string
>
Generate a random BIP39 mnemonic.
Returns
Promise
<string
>
getAccount
▸ getAccount(accountId
): Promise
<Account
>
Get an account by its alias or index.
Parameters
Name | Type |
---|---|
accountId | AccountId |
Returns
Promise
<Account
>
getAccountIndexes
▸ getAccountIndexes(): Promise
<number
[]>
Get all account indexes.
Returns
Promise
<number
[]>
getAccounts
▸ getAccounts(): Promise
<Account
[]>
Get all accounts.
Returns
Promise
<Account
[]>
generateAddress
▸ generateAddress(accountIndex
, internal
, addressIndex
, options?
, bech32Hrp?
): Promise
<string
>
Generate an address without storing it.
Parameters
Name | Type |
---|---|
accountIndex | number |
internal | boolean |
addressIndex | number |
options? | GenerateAddressOptions |
bech32Hrp? | string |
Returns
Promise
<string
>
getNodeInfo
▸ getNodeInfo(url?
, auth?
): Promise
<NodeInfoWrapper
>
Get the node info.
Parameters
Name | Type |
---|---|
url? | string |
auth? | Auth |
Returns
Promise
<NodeInfoWrapper
>
getLedgerNanoStatus
▸ getLedgerNanoStatus(): Promise
<LedgerNanoStatus
>
Get the status for a Ledger Nano.
Returns
Promise
<LedgerNanoStatus
>
hexToBech32
▸ hexToBech32(hex
, bech32Hrp?
): Promise
<string
>
Transform hex encoded address to bech32 encoded address. If no bech32Hrp is provided, the AccountManager will attempt to retrieve it from the NodeInfo. If this does not succeed, it will default to the Shimmer testnet bech32Hrp.
Parameters
Name | Type |
---|---|
hex | string |
bech32Hrp? | string |
Returns
Promise
<string
>
isStrongholdPasswordAvailable
▸ isStrongholdPasswordAvailable(): Promise
<boolean
>
Check if the Stronghold password has been set.
Returns
Promise
<boolean
>
listen
▸ listen(eventTypes
, callback
): void
Listen to wallet events with a callback. An empty array will listen to all possible events.
Parameters
Name | Type |
---|---|
eventTypes | EventType [] |
callback | (error : Error , result : string ) => void |
Returns
void
clearListeners
▸ clearListeners(eventTypes
): Promise
<void
>
Clear the callbacks for provided events. An empty array will clear all listeners.
Parameters
Name | Type |
---|---|
eventTypes | EventType [] |
Returns
Promise
<void
>
recoverAccounts
▸ recoverAccounts(accountStartIndex
, accountGapLimit
, addressGapLimit
, syncOptions
): Promise
<Account
[]>
Find accounts with unspent outputs.
Parameters
Name | Type |
---|---|
accountStartIndex | number |
accountGapLimit | number |
addressGapLimit | number |
syncOptions | AccountSyncOptions |
Returns
Promise
<Account
[]>
removeLatestAccount
▸ removeLatestAccount(): Promise
<void
>
Delete the latest account.
Returns
Promise
<void
>
restoreBackup
▸ restoreBackup(source
, password
): Promise
<void
>
Restore a backup from a Stronghold file Replaces client_options, coin_type, secret_manager and accounts. Returns an error if accounts were already created If Stronghold is used as secret_manager, the existing Stronghold file will be overwritten. If a mnemonic was stored, it will be gone.
Parameters
Name | Type |
---|---|
source | string |
password | string |
Returns
Promise
<void
>
setClientOptions
▸ setClientOptions(clientOptions
): Promise
<void
>
Set ClientOptions.
Parameters
Name | Type |
---|---|
clientOptions | ClientOptions |
Returns
Promise
<void
>
setStrongholdPassword
▸ setStrongholdPassword(password
): Promise
<void
>
Set the Stronghold password.
Parameters
Name | Type |
---|---|
password | string |
Returns
Promise
<void
>
setStrongholdPasswordClearInterval
▸ setStrongholdPasswordClearInterval(intervalInMilliseconds?
): Promise
<void
>
Set the interval after which the Stronghold password gets cleared from memory.
Parameters
Name | Type |
---|---|
intervalInMilliseconds? | number |
Returns
Promise
<void
>
startBackgroundSync
▸ startBackgroundSync(options?
, intervalInMilliseconds?
): Promise
<void
>
Start the background syncing process for all accounts.
Parameters
Name | Type |
---|---|
options? | AccountSyncOptions |
intervalInMilliseconds? | number |
Returns
Promise
<void
>
stopBackgroundSync
▸ stopBackgroundSync(): Promise
<void
>
Stop the background syncing process for all accounts.
Returns
Promise
<void
>
storeMnemonic
▸ storeMnemonic(mnemonic
): Promise
<void
>
Store a mnemonic in the Stronghold snapshot.
Parameters
Name | Type |
---|---|
mnemonic | string |
Returns
Promise
<void
>
verifyMnemonic
▸ verifyMnemonic(mnemonic
): Promise
<void
>
Verify if a mnemonic is a valid BIP39 mnemonic.
Parameters
Name | Type |
---|---|
mnemonic | string |
Returns
Promise
<void
>
updateNodeAuth
▸ updateNodeAuth(url
, auth?
): Promise
<void
>
Update the authentication for the provided node.
Parameters
Name | Type |
---|---|
url | string |
auth? | Auth |
Returns
Promise
<void
>