Class: Account

Account

new Account(options)

Represents a BIP44 Account belonging to a Wallet. Note that this object does not enforce locks. Any method that does a write is internal API only and will lead to race conditions if used elsewhere.

Parameters:
Name Type Description
options Object
Properties
Name Type Attributes Description
db WalletDB
accountKey HDPublicKey
witness Boolean <nullable>

Whether to use witness programs.

accountIndex Number

The BIP44 account index.

receiveDepth Number <nullable>

The index of the next receiving address.

changeDepth Number <nullable>

The index of the next change address.

type String <nullable>

Type of wallet (pubkeyhash, multisig) (default=pubkeyhash).

m Number <nullable>

m value for multisig.

n Number <nullable>

n value for multisig.

id String <nullable>

Wallet ID

name String <nullable>

Account name

Source:

Methods

(static) fromJSON(json) → {Account}

Instantiate a Account from a jsonified account object.

Parameters:
Name Type Description
json Object

The jsonified account object.

Source:
Returns:
Type
Account

(static) fromRaw(data) → {Account}

Instantiate a account from serialized data.

Parameters:
Name Type Description
data Buffer
Source:
Returns:
Type
Account

(static) isAccount(obj) → {Boolean}

Test an object to see if it is a Account.

Parameters:
Name Type Description
obj Object
Source:
Returns:
Type
Boolean

(static) parseJSON(json, passphrasenullable) → {Object|Object}

Handle a deserialized JSON account object.

Parameters:
Name Type Attributes Description
json Object
passphrase String <nullable>
Source:
Throws:

Error on bad decrypt

Returns:
  • A "naked" account (a plain javascript object which is suitable for passing to the Account constructor).

    Type
    Object
  • Type
    Object

(static) parseRaw(data) → {Object}

Parse a serialized account. Return a "naked" account object, suitable for passing into the account constructor.

Parameters:
Name Type Description
data Buffer
Source:
Returns:
Type
Object

addKey(key, callback)

Add a public account key to the account (multisig). Saves the key in the wallet database.

Parameters:
Name Type Description
key HDPublicKey
callback function
Source:

close(callback)

Close the account, unregister with the database.

Parameters:
Name Type Description
callback function
Source:

createAddress(change, callback)

Create a new address (increments depth).

Parameters:
Name Type Description
change Boolean
callback function

Returns [Error, KeyRing].

Source:

createChange() → {KeyRing}

Create a new change address (increments receiveDepth).

Source:
Returns:
Type
KeyRing

createReceive() → {KeyRing}

Create a new receiving address (increments receiveDepth).

Source:
Returns:
Type
KeyRing

deriveAddress(change, index) → {KeyRing}

Derive an address at index. Do not increment depth.

Parameters:
Name Type Description
change Boolean

Whether the address on the change branch.

index Number
Source:
Returns:
Type
KeyRing

deriveChange(index) → {KeyRing}

Derive a change address at index. Do not increment depth.

Parameters:
Name Type Description
index Number
Source:
Returns:
Type
KeyRing

deriveReceive(index) → {KeyRing}

Derive a receiving address at index. Do not increment depth.

Parameters:
Name Type Description
index Number
Source:
Returns:
Type
KeyRing

init(callback)

Attempt to intialize the account (generating the first addresses along with the lookahead addresses). Called automatically from the walletdb and open().

Parameters:
Name Type Description
callback function
Source:

inspect() → {Object}

Convert the account to a more inspection-friendly object.

Source:
Returns:
Type
Object

open(callback)

Open the account, register with the database.

Parameters:
Name Type Description
callback function
Source:

pushKey(key)

Add a public account key to the account (multisig). Does not update the database.

Parameters:
Name Type Description
key HDPublicKey

Account (bip44) key (can be in base58 form).

Source:
Throws:

Error on non-hdkey/non-accountkey.

removeKey(key, callback)

Remove a public account key from the account (multisig). Remove the key from the wallet database.

Parameters:
Name Type Description
key HDPublicKey
callback function
Source:

save(callback)

Save the account to the database. Necessary when address depth and keys change.

Parameters:
Name Type Description
callback function
Source:

saveAddress(address, callback)

Save addresses to path map.

Parameters:
Name Type Description
address Array.<KeyRing>
callback function
Source:

scan(getByAddress, callback)

Scan for addresses.

Parameters:
Name Type Description
getByAddress function

Must be a callback which accepts a callback and returns transactions by address.

callback function

Return [Error, Number] (total number of addresses allocated).

Source:

setDepth(depth, callback)

Set change and receiving depth (depth is the index of the next address). Allocate all addresses up to depth. Note that this also allocates new lookahead addresses.

Parameters:
Name Type Description
depth Number
callback function

Returns [Error, KeyRing, KeyRing].

Source:

spliceKey(key)

Remove a public account key to the account (multisig). Does not update the database.

Parameters:
Name Type Description
key HDPublicKey

Account (bip44) key (can be in base58 form).

Source:
Throws:

Error on non-hdkey/non-accountkey.

toJSON() → {Object}

Convert the account to an object suitable for serialization. Will automatically encrypt the master key based on the passphrase option.

Source:
Returns:
Type
Object

toRaw() → {Buffer}

Serialize the account.

Source:
Returns:
Type
Buffer