Class: Wallet

Manages a collection of accounts derived from the wallet root seed.

Note

Wallet creation should generally be handled through the createWallet or restoreWallet factory functions.

Properties

wallet.accounts

Array<Account>

Collection of managed Class: Account instances derived from the wallet root.

wallet.delegationContext

Object

Keys corresponding to the signing authority for this account. Only applicable after calling wallet.applyDelegatedAuthorizationAgency.

delegationContext.keys

Object

The root delegatee private and public keys for signing on behalf of delegator accounts

delegationContext.path

string

The path of the derived delegatee keys relative to the wallet root

wallet.rootSeed

string

Seed master seed corresponding to the root of the wallet

Methods

wallet.getAccountByAddress(address)

Gets a managed account corresponding to the passed address.

Returns:The target Account, or null if not found.
Arguments
Name Type Required Description
address String Yes Address of the target account
wallet.generatePlugAccount()

Initialize a managed Pl^g account derived from the wallet root.

Returns:An Account instance corresponding to the new managed account.

Examples

Initialize a managed account

1
2
// Initializes a Pl^g account corresponding to the next available path
const account = wallet.generatePlugAccount()
wallet.addPlugAccount(pathOrPrivateKey)

Initialize a managed Pl^g account using either the path or the private key passed in. Private keys must be passed in as Buffers.

Returns:An Account instance corresponding to the new managed account.

Examples

Initialize a managed account with the corresponding private key

1
2
3
4
5
6
// Initializes a Pl^g account with the corresponding private key
const plugPrivateKey = Buffer.from(
    'c4d2153885580a91ce9000b05c4cf53aeac80e98374d89c98d454a44be3a502c',
    'hex'
)
const account = wallet.addPlugAccount(plugPrivateKey)

Initialize a managed account with the corresponding path

1
2
// Initializes a Pl^g account with the corresponding path
const account = wallet.addPlugAccount('m/5')
wallet.generateEthAccount()

Initialize a managed Ethereum account derived from the wallet root. Note: Ethereum accounts will have an Ethereum asset automatically added

Returns:An Account instance corresponding to the new managed account.

Examples

Initialize a managed account

1
2
3
// Initializes a Ethereum account corresponding to the next available path
const account = wallet.generateEthAccount()
console.log(account.assets.ETH.name) //ETH
wallet.addEthAccount(pathOrPrivateKey)

Initialize a managed ETH account using either the path or the private key passed in. Private keys must be passed in as Buffers.

Returns:An Account instance corresponding to the new managed account.

Examples

Initialize a managed account with the corresponding private key

1
2
3
4
5
6
7
// Initializes an ETH account with the corresponding private key
const ethPrivateKey = Buffer.from(
    'c4d2153885580a91ce9000b05c4cf53aeac80e98374d89c98d454a44be3a502c',
    'hex'
)
const account = wallet.addEthAccount(ethPrivateKey)
console.log(account.assets.ETH.name) //ETH

Initialize a managed account with the corresponding path

1
2
3
// Initializes an ETH account with the corresponding path
const account = wallet.addEthAccount('m/5')
console.log(account.assets.ETH.name) //ETH
wallet.applyDelegatedAuthorizationAgency(agentPath?)

Make this wallet aware of a delegated authority that can be used to:

  • Discover existing registered accounts that are, or could potentially delegate authority to the provided agent
  • Allow registration of locally created accounts as siblings to the provided delegated agent
  • Send transactions on behalf of delegating accounts
Returns:Promise A promise indicating the completion of the process
Arguments
Name Type Required Description
agentPath String No The hierarchical location of the delegatee relative to the wallet root - defaults to m/140990'
wallet.export()

Exports the wallet structure for later restoration. Wallets can be restored using the restoreWallet factory function.

Returns:object Wallet structure for restoration

Examples

Export and restore a wallet

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
import { createWallet, restoreWallet } from 'cryptoasset-wallet'

const rootSeed = '86bd966a3bb5f6e9c28166c95f2bb7ca4e0f55d62399...'
const wallet = createWallet(rootSeed)
const myPlugAccount = wallet.generatePlugAccount()
myPlugAccount.addAsset('CENNZ')

const exportedWallet = wallet.export()

const restoredWallet = restoreWallet(rootSeed, exportedWallet)
console.log(restoredWallet.accounts[0].assets['CENNZ'].name) // "CENNZ"