new CustodialWallet()
- Description:
Implements a fully-featured custodial HD wallet supporting BIP32/39/44/49/84/86 standards with legacy, wrapped SegWit, native SegWit, and Taproot address support.
- Source:
Examples
// Create a new wallet
const { wallet, mnemonic } = CustodialWallet.createNew('main');
console.log('Backup phrase:', mnemonic);
// Get different address types
const legacy = wallet.getReceivingAddress(0, 0, 'legacy'); // 1...
const wrapped = wallet.getReceivingAddress(0, 0, 'wrapped-segwit'); // 3...
const native = wallet.getReceivingAddress(0, 0, 'segwit'); // bc1q...
const taproot = wallet.getReceivingAddress(0, 0, 'taproot'); // bc1p...
Members
created :number
- Source:
Type:
- number
derivedAddresses :Map.<string, Object>
- Source:
Type:
- Map.<string, Object>
masterKeys :Object
- Source:
Type:
- Object
mnemonic :string|null
- Source:
Type:
- string | null
network :string
- Source:
Type:
- string
version :string
- Source:
Type:
- string
Methods
canSign() → {boolean}
- Description:
Check if wallet has private key access
- Source:
Returns:
True if wallet can sign
- Type
- boolean
clearCache() → {void}
- Description:
Clear the derived addresses cache
- Source:
Returns:
- Type
- void
createTransaction() → {TransactionBuilder}
- Description:
Create a new transaction builder
- Source:
Returns:
Transaction builder instance
- Type
- TransactionBuilder
deriveAddress(accountopt, changeopt, indexopt, typeopt) → {Object|string|string|string|null|Buffer|null|string|string|string|Buffer|Buffer|null}
- Description:
Derive a Bitcoin address at the specified path
- Source:
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
account |
number |
<optional> |
0
|
Account index (hardened) |
change |
number |
<optional> |
0
|
Change index (0=external, 1=internal) |
index |
number |
<optional> |
0
|
Address index |
type |
string |
<optional> |
'segwit'
|
Address type ('legacy', 'wrapped-segwit', 'segwit', 'taproot') |
Returns:
-
Derived address details
- Type
- Object
-
returns.address - Bitcoin address
- Type
- string
-
returns.publicKey - Compressed public key hex
- Type
- string
-
returns.privateKey - WIF-encoded private key
- Type
- string | null
-
returns.privateKeyBuffer - Raw private key buffer
- Type
- Buffer | null
-
returns.path - Full derivation path
- Type
- string
-
returns.type - Address type
- Type
- string
-
returns.network - Network type
- Type
- string
-
returns.scriptPubKey - Output script
- Type
- Buffer
-
returns.redeemScript - Redeem script (for P2SH types)
- Type
- Buffer | null
destroy() → {void}
- Description:
Securely clear all sensitive data
- Source:
Returns:
- Type
- void
exportWIF(accountopt, changeopt, indexopt, typeopt) → {string|null}
- Description:
Export private key as WIF
- Source:
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
account |
number |
<optional> |
0
|
Account index |
change |
number |
<optional> |
0
|
Change index |
index |
number |
<optional> |
0
|
Address index |
type |
string |
<optional> |
'segwit'
|
Address type |
Returns:
WIF-encoded private key
- Type
- string | null
getAddresses(accountopt, typeopt, countopt) → {Array.<Object>}
- Description:
Get all addresses of a specific type for an account
- Source:
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
account |
number |
<optional> |
0
|
Account index |
type |
string |
<optional> |
'segwit'
|
Address type |
count |
number |
<optional> |
20
|
Number of addresses to generate |
Returns:
Array of address details
- Type
- Array.<Object>
getChangeAddress(accountopt, indexopt, typeopt) → {Object}
- Description:
Get a change (internal) address
- Source:
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
account |
number |
<optional> |
0
|
Account index |
index |
number |
<optional> |
0
|
Address index |
type |
string |
<optional> |
'segwit'
|
Address type |
Returns:
Address details
- Type
- Object
getExtendedPrivateKey() → {string}
- Description:
Get the master extended private key (xprv/tprv)
- Source:
Returns:
Extended private key
- Type
- string
getExtendedPublicKey() → {string}
- Description:
Get the master extended public key (xpub/tpub)
- Source:
Returns:
Extended public key
- Type
- string
getMnemonic() → {string|null}
- Description:
Get the wallet's mnemonic phrase
- Source:
Returns:
Mnemonic phrase or null if not available
- Type
- string | null
getNetwork() → {string}
- Description:
Get the wallet's network type
- Source:
Returns:
Network type ('main' or 'test')
- Type
- string
getReceivingAddress(accountopt, indexopt, typeopt) → {Object}
- Description:
Get a receiving (external) address
- Source:
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
account |
number |
<optional> |
0
|
Account index |
index |
number |
<optional> |
0
|
Address index |
type |
string |
<optional> |
'segwit'
|
Address type |
Returns:
Address details
- Type
- Object
signMessage(message, accountopt, indexopt, typeopt) → {Object}
- Description:
Sign a message using Bitcoin message signing
- Source:
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
message |
string | Buffer | Message to sign |
||
account |
number |
<optional> |
0
|
Account index |
index |
number |
<optional> |
0
|
Address index |
type |
string |
<optional> |
'segwit'
|
Address type for signing |
Throws:
-
If no private key available
- Type
- CustodialWalletError
Returns:
Signature result
- Type
- Object
(async) signMessageBIP322(message, accountopt, indexopt, typeopt) → {Promise.<Buffer>}
- Description:
Sign a message using BIP322 (for SegWit/Taproot addresses)
- Source:
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
message |
string | Buffer | Message to sign |
||
account |
number |
<optional> |
0
|
Account index |
index |
number |
<optional> |
0
|
Address index |
type |
string |
<optional> |
'segwit'
|
Address type |
Returns:
BIP322 signature
- Type
- Promise.<Buffer>
(async) signTransaction(builder, inputInfo) → {Promise.<TransactionBuilder>}
- Description:
Sign a transaction with wallet keys
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
builder |
TransactionBuilder | Transaction builder with inputs added |
inputInfo |
Array.<Object> | Array of {account, change, index, type} for each input |
Returns:
Signed transaction builder
- Type
- Promise.<TransactionBuilder>
toJSON() → {Object}
- Description:
Serialize wallet to JSON (excludes sensitive data)
- Source:
Returns:
JSON-serializable wallet data
- Type
- Object
verifyMessage(message, signature, publicKey) → {boolean}
- Description:
Verify a signed message
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
message |
string | Buffer | Original message |
signature |
Object | Signature to verify |
publicKey |
string | Buffer | Public key to verify against |
Returns:
True if signature is valid
- Type
- boolean
(static) createNew(networkopt, strengthopt) → {Object}
- Description:
Create a new wallet with a fresh mnemonic
- Source:
Example
const { wallet, mnemonic } = CustodialWallet.createNew('main');
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
network |
string |
<optional> |
'main'
|
Network type ('main' or 'test') |
strength |
number |
<optional> |
256
|
Mnemonic strength (128, 160, 192, 224, 256) |
Throws:
-
If wallet creation fails
- Type
- CustodialWalletError
Returns:
New wallet and backup mnemonic
- Type
- Object
(static) fromExtendedKey(network, extendedKey) → {CustodialWallet}
- Description:
Create a wallet from an extended key (xprv/xpub/tprv/tpub)
- Source:
Example
const wallet = CustodialWallet.fromExtendedKey('main', 'xprv...');
Parameters:
| Name | Type | Description |
|---|---|---|
network |
string | Network type ('main' or 'test') |
extendedKey |
string | BIP32 extended key |
Throws:
-
If extended key format is invalid
- Type
- CustodialWalletError
Returns:
Wallet instance
- Type
- CustodialWallet
(static) fromMnemonic(network, mnemonic, passphraseopt) → {CustodialWallet}
- Description:
Restore a wallet from a BIP39 mnemonic phrase
- Source:
Example
const wallet = CustodialWallet.fromMnemonic('main', 'abandon abandon abandon...');
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
network |
string | Network type ('main' or 'test') |
||
mnemonic |
string | BIP39 mnemonic phrase (12-24 words) |
||
passphrase |
string |
<optional> |
''
|
Optional BIP39 passphrase |
Throws:
-
If mnemonic is invalid
- Type
- CustodialWalletError
Returns:
Restored wallet instance
- Type
- CustodialWallet
(static) fromSeed(network, seed) → {CustodialWallet}
- Description:
Create a wallet from a raw seed
- Source:
Example
const wallet = CustodialWallet.fromSeed('main', seedHex);
Parameters:
| Name | Type | Description |
|---|---|---|
network |
string | Network type ('main' or 'test') |
seed |
string | Buffer | 64-byte seed as hex string or Buffer |
Throws:
-
If seed is invalid
- Type
- CustodialWalletError
Returns:
Wallet instance
- Type
- CustodialWallet
(static) fromWIF(wif) → {CustodialWallet}
- Description:
Create a wallet from a WIF private key
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
wif |
string | WIF-encoded private key |
Throws:
-
If WIF is invalid
- Type
- CustodialWalletError
Returns:
Wallet instance (single-key, no derivation)
- Type
- CustodialWallet