The Qi HD wallet is a BIP44-compliant hierarchical deterministic wallet used for managing a set of addresses in the Qi ledger. This is wallet implementation is the primary way to interact with the Qi UTXO ledger on the Quai network.

The Qi HD wallet supports:

  • Adding accounts to the wallet heierchy
  • Generating addresses for a specific account in any Zone
  • Signing and sending transactions for any address in the wallet
  • Serializing the wallet to JSON and deserializing it back to a wallet instance.

Example

import { QiHDWallet, Zone } from 'quais';

const wallet = new QiHDWallet();
const cyrpus1Address = await wallet.getNextAddress(0, Zone.Cyrpus1); // get the first address in the Cyrpus1 zone
await wallet.sendTransaction({ txInputs: [...], txOutputs: [...] }); // send a transaction
const serializedWallet = wallet.serialize(); // serialize current (account/address) state of the wallet
.
.
.
const deserializedWallet = QiHDWallet.deserialize(serializedWallet); // create a new wallet instance from the serialized data

Extends

  • AbstractHDWallet

Accessors

xPub

get xPub(): string

Returns the extended public key of the root node of the HD wallet.

Returns

string

The extended public key.

Source

wallet/hdwallet.ts:93

Methods

_scan()

private _scan(zone, account?): Promise<void>

Internal method to scan the specified zone for addresses with unspent outputs. This method handles the actual scanning logic, generating new addresses until the gap limit is reached for both gap and change addresses.

Parameters

ParameterTypeDefault valueDescription
zoneZoneundefinedThe zone in which to scan for addresses.
account?number0The index of the account to scan. Default is 0

Returns

Promise<void>

A promise that resolves when the scan is complete.

Throws

If the provider is not set.

Source

wallet/qi-hdwallet.ts:384


addAddress()

addAddress(
   account, 
   addressIndex, 
   isChange?): NeuteredAddressInfo

Adds an address to the wallet.

Parameters

ParameterTypeDefault valueDescription
accountnumberundefinedThe account number.
addressIndexnumberundefinedThe address index.
isChange?booleanfalseWhether the address is a change address. Default is false

Returns

NeuteredAddressInfo

The added address info.

Inherited from

AbstractHDWallet.addAddress

Source

wallet/hdwallet.ts:150


connect()

connect(provider): void

Connects the wallet to a provider.

Parameters

ParameterTypeDescription
providerProviderThe provider.

Returns

void

Inherited from

AbstractHDWallet.connect

Source

wallet/hdwallet.ts:380


getAddressInfo()

getAddressInfo(address): null | NeuteredAddressInfo

Gets the address info for a given address.

Parameters

ParameterTypeDescription
addressstringThe address.

Returns

null | NeuteredAddressInfo

The address info or null if not found.

Inherited from

AbstractHDWallet.getAddressInfo

Source

wallet/hdwallet.ts:238


getAddressesForAccount()

getAddressesForAccount(account): NeuteredAddressInfo[]

Gets the addresses for a given account.

Parameters

ParameterTypeDescription
accountnumberThe account number.

Returns

NeuteredAddressInfo[]

The addresses for the account.

Inherited from

AbstractHDWallet.getAddressesForAccount

Source

wallet/hdwallet.ts:264


getAddressesForZone()

getAddressesForZone(zone): NeuteredAddressInfo[]

Gets the addresses for a given zone.

Parameters

ParameterTypeDescription
zoneZoneThe zone.

Returns

NeuteredAddressInfo[]

The addresses for the zone.

Inherited from

AbstractHDWallet.getAddressesForZone

Source

wallet/hdwallet.ts:275


getChangeAddressesForZone()

getChangeAddressesForZone(zone): NeuteredAddressInfo[]

Gets the change addresses for the specified zone.

Parameters

ParameterTypeDescription
zoneZoneThe zone.

Returns

NeuteredAddressInfo[]

The change addresses for the zone.

Source

wallet/qi-hdwallet.ts:461


getGapAddressesForZone()

getGapAddressesForZone(zone): NeuteredAddressInfo[]

Gets the gap addresses for the specified zone.

Parameters

ParameterTypeDescription
zoneZoneThe zone.

Returns

NeuteredAddressInfo[]

The gap addresses for the zone.

Source

wallet/qi-hdwallet.ts:473


getGapChangeAddressesForZone()

getGapChangeAddressesForZone(zone): NeuteredAddressInfo[]

Gets the gap change addresses for the specified zone.

Parameters

ParameterTypeDescription
zoneZoneThe zone.

Returns

NeuteredAddressInfo[]

The gap change addresses for the zone.

Source

wallet/qi-hdwallet.ts:485


getNextAddress()

getNextAddress(account, zone): Promise<NeuteredAddressInfo>

Promise that resolves to the next address for the specified account and zone.

Parameters

ParameterTypeDescription
accountnumberThe index of the account for which to retrieve the next address.
zoneZoneThe zone in which to retrieve the next address.

Returns

Promise<NeuteredAddressInfo>

The next neutered address information.

Inherited from

AbstractHDWallet.getNextAddress

Source

wallet/hdwallet.ts:195


getNextAddressSync()

getNextAddressSync(account, zone): NeuteredAddressInfo

Synchronously retrieves the next address for the specified account and zone.

Parameters

ParameterTypeDescription
accountnumberThe index of the account for which to retrieve the next address.
zoneZoneThe zone in which to retrieve the next address.

Returns

NeuteredAddressInfo

The next neutered address information.

Inherited from

AbstractHDWallet.getNextAddressSync

Source

wallet/hdwallet.ts:206


getNextChangeAddress()

getNextChangeAddress(account, zone): Promise<NeuteredAddressInfo>

Promise that resolves to the next change address for the specified account and zone.

Parameters

ParameterTypeDescription
accountnumberThe index of the account for which to retrieve the next change address.
zoneZoneThe zone in which to retrieve the next change address.

Returns

Promise<NeuteredAddressInfo>

The next change neutered address information.

Source

wallet/qi-hdwallet.ts:139


getNextChangeAddressSync()

getNextChangeAddressSync(account, zone): NeuteredAddressInfo

Synchronously retrieves the next change address for the specified account and zone.

Parameters

ParameterTypeDescription
accountnumberThe index of the account for which to retrieve the next change address.
zoneZoneThe zone in which to retrieve the next change address.

Returns

NeuteredAddressInfo

The next change neutered address information.

Source

wallet/qi-hdwallet.ts:150


getOutpoints()

getOutpoints(zone): OutpointInfo[]

Gets the outpoints for the specified zone.

Parameters

ParameterTypeDescription
zoneZoneThe zone.

Returns

OutpointInfo[]

The outpoints for the zone.

Source

wallet/qi-hdwallet.ts:170


getPrivateKey()

getPrivateKey(address): string

Returns the private key for a given address. This method should be used with caution as it exposes the private key to the user.

Parameters

ParameterTypeDescription
addressstringThe address associated with the desired private key.

Returns

string

The private key.

Inherited from

AbstractHDWallet.getPrivateKey

Source

wallet/hdwallet.ts:253


importOutpoints()

importOutpoints(outpoints): void

Imports an array of outpoints.

Parameters

ParameterTypeDescription
outpointsOutpointInfo[]The outpoints to import.

Returns

void

Source

wallet/qi-hdwallet.ts:159


scan()

scan(zone, account?): Promise<void>

Scans the specified zone for addresses with unspent outputs. Starting at index 0, it will generate new addresses until the gap limit is reached for both gap and change addresses.

Parameters

ParameterTypeDefault valueDescription
zoneZoneundefinedThe zone in which to scan for addresses.
account?number0The index of the account to scan. Default is 0

Returns

Promise<void>

A promise that resolves when the scan is complete.

Throws

If the zone is invalid.

Source

wallet/qi-hdwallet.ts:332


scanAddress()

private scanAddress(
   zone, 
   account, 
   isChange, 
addressesCount): Promise<number>

Scans for the next address in the specified zone and account, checking for associated outpoints, and updates the address count and gap addresses accordingly.

Parameters

ParameterTypeDescription
zoneZoneThe zone in which the address is being scanned.
accountnumberThe index of the account for which the address is being scanned.
isChangebooleanA flag indicating whether the address is a change address.
addressesCountnumberThe current count of addresses scanned.

Returns

Promise<number>

A promise that resolves to the updated address count.

Throws

If an error occurs during the address scanning or outpoints retrieval process.

Source

wallet/qi-hdwallet.ts:413


sendTransaction()

sendTransaction(tx): Promise<TransactionResponse>

Sends a Qi transaction.

Parameters

ParameterTypeDescription
txQiTransactionRequestThe transaction to send.

Returns

Promise<TransactionResponse>

The transaction response.

Overrides

AbstractHDWallet.sendTransaction

Throws

If the provider is not set or if the transaction has no inputs.

Source

wallet/qi-hdwallet.ts:208


serialize()

serialize(): SerializedQiHDWallet

Serializes the HD wallet state into a format suitable for storage or transmission.

Returns

SerializedQiHDWallet

An object representing the serialized state of the HD wallet, including outpoints, change addresses, gap addresses, and other inherited properties.

Overrides

AbstractHDWallet.serialize

Source

wallet/qi-hdwallet.ts:513


signMessage()

signMessage(address, message): Promise<string>

Signs a message using the private key associated with the given address.

Parameters

ParameterTypeDescription
addressstringThe address for which the message is to be signed.
messagestring | Uint8ArrayThe message to be signed, either as a string or Uint8Array.

Returns

Promise<string>

A promise that resolves to the signature of the message in hexadecimal string format.

Overrides

AbstractHDWallet.signMessage

Throws

If the address does not correspond to a valid HD node or if signing fails.

Source

wallet/qi-hdwallet.ts:499


signTransaction()

signTransaction(tx): Promise<string>

Signs a Qi transaction and returns the serialized transaction.

Parameters

ParameterTypeDescription
txQiTransactionRequestThe transaction to sign.

Returns

Promise<string>

The serialized transaction.

Overrides

AbstractHDWallet.signTransaction

Throws

If the UTXO transaction is invalid.

Source

wallet/qi-hdwallet.ts:182


sync()

sync(zone, account?): Promise<void>

Scans the specified zone for addresses with unspent outputs. Starting at the last address index, it will generate new addresses until the gap limit is reached for both gap and change addresses. If no account is specified, it will scan all accounts known to the wallet.

Parameters

ParameterTypeDescription
zoneZoneThe zone in which to sync addresses.
account?numberThe index of the account to sync. If not specified, all accounts will be scanned.

Returns

Promise<void>

A promise that resolves when the sync is complete.

Throws

If the zone is invalid.

Source

wallet/qi-hdwallet.ts:354


createRandom()

static createRandom<T>(
   this, 
   password?, 
   wordlist?): T

Creates a random HD wallet.

Type parameters

Type parameter
T extends AbstractHDWallet<T>

Parameters

ParameterTypeDescription
thisObjectThe constructor of the HD wallet.
password?stringThe password.
wordlist?WordlistThe wordlist.

Returns

T

The created instance.

Inherited from

AbstractHDWallet.createRandom

Source

wallet/hdwallet.ts:319


deserialize()

static deserialize(serialized): Promise<QiHDWallet>

Deserializes a serialized QiHDWallet object and reconstructs the wallet instance.

Parameters

ParameterTypeDescription
serializedSerializedQiHDWalletThe serialized object representing the state of a QiHDWallet.

Returns

Promise<QiHDWallet>

A promise that resolves to a reconstructed QiHDWallet instance.

Overrides

AbstractHDWallet.deserialize

Throws

If the serialized data is invalid or if any addresses in the gap addresses or gap change addresses do not exist in the wallet.

Source

wallet/qi-hdwallet.ts:532


fromMnemonic()

static fromMnemonic<T>(this, mnemonic): T

Creates an HD wallet from a mnemonic.

Type parameters

Type parameter
T extends AbstractHDWallet<T>

Parameters

ParameterTypeDescription
thisObjectThe constructor of the HD wallet.
mnemonicMnemonicThe mnemonic.

Returns

T

The created instance.

Inherited from

AbstractHDWallet.fromMnemonic

Source

wallet/hdwallet.ts:304


fromPhrase()

static fromPhrase<T>(
   this, 
   phrase, 
   password?, 
   wordlist?): T

Creates an HD wallet from a phrase.

Type parameters

Type parameter
T extends AbstractHDWallet<T>

Parameters

ParameterTypeDescription
thisObjectThe constructor of the HD wallet.
phrasestringThe phrase.
password?stringThe password.
wordlist?WordlistThe wordlist.

Returns

T

The created instance.

Inherited from

AbstractHDWallet.fromPhrase

Source

wallet/hdwallet.ts:343