ExtKey

class ExtKey(var depth: Int = 0, var fingerprint: ByteArray = ByteArray(4), var child: Long = 0, var chaincode: ByteArray = ByteArray(32), var key: ByteArray = ByteArray(32)) : BCHserializable

A BIP32 hierarchical-deterministic extended key.

Mirrors the C++ CExtKey / CExtPubKey structures in libnexa (nexa/src/key.h, nexa/src/pubkey.h): it holds a key together with the metadata (depth, parent fingerprint, child number, and chaincode) needed to derive child keys. A single class represents both the private (CExtKey) and public (CExtPubKey) variants, distinguished by the length of key: 32 bytes is a private key, 33 bytes is a compressed public key. Both variants share the identical 74 byte serialized framing.

Encode/Decode convert to and from the standard 74 byte BIP32 representation (matching CExtKey::Encode / CExtKey::Decode and CExtPubKey::Encode / CExtPubKey::Decode), and the BCHserializable implementation wraps that representation with a compact-size length prefix exactly as the C++ Serialize / Unserialize do.

Constructors

Link copied to clipboard
constructor(depth: Int = 0, fingerprint: ByteArray = ByteArray(4), child: Long = 0, chaincode: ByteArray = ByteArray(32), key: ByteArray = ByteArray(32))
constructor(stream: BCHserialized)

Deserialize an extended key from the passed stream.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

chaincode: the 32 byte BIP32 chain code.

Link copied to clipboard
var child: Long

nChild: this key's index within its parent. A 32 bit unsigned value, held in a Long to stay unsigned.

Link copied to clipboard
var depth: Int

nDepth: how many derivations from the master key (0 == master). An unsigned byte (0..255).

Link copied to clipboard

vchFingerprint: the first 4 bytes of the hash160 of the parent's public key.

Link copied to clipboard

key: either a 32 byte secp256k1 private key (CExtKey) or a 33 byte compressed public key (CExtPubKey).

Functions

Link copied to clipboard
open override fun BCHdeserialize(stream: BCHserialized): BCHserialized
Link copied to clipboard
open override fun BCHserialize(format: SerializationType = SerializationType.UNKNOWN): BCHserialized
Link copied to clipboard
fun Decode(code: ByteArray)

Decode the 74 byte BIP32 representation into this object (mirrors CExtKey::Decode / CExtPubKey::Decode). The trailing 33 bytes are interpreted as a private key when the prefix byte (code41) is zero, otherwise as a 33 byte compressed public key.

Link copied to clipboard

Encode this extended key into its 74 byte BIP32 representation (mirrors CExtKey::Encode / CExtPubKey::Encode). Note that nChild is stored big-endian, as in the C++ implementation.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard

True if this holds a private key (CExtKey), false if it holds a public key (CExtPubKey).

Link copied to clipboard
fun neuter(): ExtKey

Return the extended public key (xpub) form of this key. If this is already public it is copied; if it is private the corresponding secp256k1 compressed public key is computed (mirrors CExtKey::Neuter).

Link copied to clipboard
Link copied to clipboard
open fun toByteArray(format: SerializationType = SerializationType.UNKNOWN): ByteArray