Class Bip32
A BIP-32 hierarchical deterministic key on secp256k1: Bitcoin, every EVM chain and most
others derive their accounts this way from one Mnemonic seed.
A node holds a private key, or only the public key once neuter() has dropped it; a
public node still derives every non-hardened child, which is how a watch-only server
hands out deposit addresses without holding a secret. toXprv() and toXpub() write the
standard serialization and parse(String) reads it back.
Private key material lives in arrays this object owns; call destroy() to wipe them.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longThe offset that marks a hardened index.static final intThe testnet private version bytes, which print astprv.static final intThe testnet public version bytes, which print astpub.static final intThe mainnet private version bytes, which print asxprv.static final intThe mainnet public version bytes, which print asxpub. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]A copy of the 32-byte chain code.child(long index) The child atindex; addHARDENEDfor a hardened one, which needs the private key.longThe index this node was derived with, includingHARDENED.intdepth()The distance from the master node.derive(DerivationPath path) Derives along a path relative to this node.Derives along a path relative to this node, such asm/84'/0'/0'/0/7.voiddestroy()Wipes the private key and chain code.intThe first four bytes ofHASH160(publicKey), as a big-endian int.booleanTells whether this node holds its private key.static Bip32master(byte[] seed) The master node of a seed (16 to 64 bytes, normallyMnemonic.toSeed(String, String)).neuter()This node without its private key.intThe first four bytes of the parent's key identifier, as a big-endian int; 0 for the master node.static Bip32Reads an extended key in its Base58Check form (xprv...,xpub...,tprv...or any other version bytes);versiontells which.byte[]A copy of the 32-byte private key.byte[]A copy of the 33-byte compressed public key.serialize(int versionBytes, boolean includePrivate) The serialization under any version bytes (SLIP-132zpub, testnettpub, ...).toXprv()The mainnetxprvserialization.toXpub()The mainnetxpubserialization.intversion()The version bytes this node wasparse(String)d with, or 0 for a derived node.
-
Field Details
-
HARDENED
public static final long HARDENEDThe offset that marks a hardened index.- See Also:
-
XPRV
public static final int XPRVThe mainnet private version bytes, which print asxprv.- See Also:
-
XPUB
public static final int XPUBThe mainnet public version bytes, which print asxpub.- See Also:
-
TPRV
public static final int TPRVThe testnet private version bytes, which print astprv.- See Also:
-
TPUB
public static final int TPUBThe testnet public version bytes, which print astpub.- See Also:
-
-
Method Details
-
master
The master node of a seed (16 to 64 bytes, normally
Mnemonic.toSeed(String, String)).Throws
IllegalArgumentException: for a seed out of range, or one whose master key is invalid (probability below 2^-127)
-
parse
-
version
public int version()The version bytes this node wasparse(String)d with, or 0 for a derived node. -
child
-
derive
-
derive
Derives along a path relative to this node. -
neuter
This node without its private key. -
hasPrivateKey
public boolean hasPrivateKey()Tells whether this node holds its private key. -
privateKey
public byte[] privateKey()A copy of the 32-byte private key. Wipe it after use.
Throws
IllegalStateException: on a public-only node
-
publicKey
public byte[] publicKey()A copy of the 33-byte compressed public key. -
chainCode
public byte[] chainCode()A copy of the 32-byte chain code. -
depth
public int depth()The distance from the master node. -
childNumber
public long childNumber()The index this node was derived with, includingHARDENED. -
parentFingerprint
public int parentFingerprint()The first four bytes of the parent's key identifier, as a big-endian int; 0 for the master node. -
fingerprint
public int fingerprint()The first four bytes ofHASH160(publicKey), as a big-endian int. -
toXprv
The mainnetxprvserialization. -
toXpub
The mainnetxpubserialization. -
serialize
The serialization under any version bytes (SLIP-132
zpub, testnettpub, ...).Parameters
-
versionBytes: the four version bytes as a big-endian int -
includePrivate:truefor the private form, which needs the private key
-
-
destroy
public void destroy()Wipes the private key and chain code. The node is unusable afterwards.
-