HdWallet class

This class implements a hierarchical deterministic wallet that generates cryptographic keys and addresses given a root signing key. It also supports the creation/restoration of the root signing key from a set of nmemonic BIP-39 words. Cardano Shelley addresses are supported by default, but the code is general enough to support any wallet based on the BIP32-ED25519 standard.

This code builds on following standards:

https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki - HD wallets https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki - mnemonic words https://github.com/bitcoin/bips/blob/master/bip-0043.mediawiki - Bitcoin purpose https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki - multi-acct wallets https://cips.cardano.org/cips/cip3/ - key generation https://cips.cardano.org/cips/cip5/ - Bech32 prefixes https://cips.cardano.org/cips/cip11/ - staking key https://cips.cardano.org/cips/cip16/ - key serialisation https://cips.cardano.org/cips/cip19/ - address structure https://cips.cardano.org/cips/cip1852/ - 1852 purpose field https://cips.cardano.org/cips/cip1855/ - forging keys https://github.com/LedgerHQ/orakolo/blob/master/papers/Ed25519_BIP%20Final.pdf

BIP-44 path: m / purpose' / coin_type' / account_ix' / change_chain / address_ix

Cardano adoption: m / 1852' / 1851' / account' / role / index

BIP-44 Wallets Key Hierarchy - Cardano derivation: +--------------------------------------------------------------------------------+ | BIP-39 Encoded Seed with CRC a.k.a Mnemonic Words | | | | squirrel material silly twice direct ... razor become junk kingdom flee | | | +--------------------------------------------------------------------------------+ | | v +--------------------------+ +-----------------------+ | Wallet Private Key |--->| Wallet Public Key | +--------------------------+ +-----------------------+ | | purpose (e.g. 1852') | v +--------------------------+ | Purpose Private Key | +--------------------------+ | | coin type (e.g. 1815' for ADA) v +--------------------------+ | Coin Type Private Key | +--------------------------+ | | account ix (e.g. 0') v +--------------------------+ +-----------------------+ | Account Private Key |--->| Account Public Key | +--------------------------+ +-----------------------+ | | | role (e.g. 0=external/payments, | | 1=internal/change, 2=staking) | v v +--------------------------+ +-----------------------+ | Change Private Key |--->| Change Public Key | +--------------------------+ +-----------------------+ | | | index (e.g. 0) | v v +--------------------------+ +-----------------------+ | Address Private Key |--->| Address Public Key | +--------------------------+ +-----------------------+

Constructors

HdWallet({required Bip32SigningKey rootSigningKey})
root constructor taking a root signing key
HdWallet.fromHexEntropy(String hexEntropy)
factory
HdWallet.fromMnemonic(String mnemonic)
factory
HdWallet.fromSeed(Uint8List seed)
Create HdWallet from seed
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
logger → Logger
final
rootSigningKey → Bip32SigningKey
final
rootVerifyKey → Bip32VerifyKey
return the root signing key
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

accountKeys({int account = defaultAccountIndex}) Bip32KeyPair
return account keypair.
buildAddressKitCache({Set<ShelleyAddress> usedSet = const {}, int account = defaultAccountIndex, int role = paymentRole, int index = defaultAddressIndex, NetworkId networkId = NetworkId.testnet, int beyondUsedOffset = maxOverrun}) List<ShelleyAddressKit>
Build a cache of spend or change addresses their keys. When used addresses are encounted, cache size is increased to maintain beyondUsedOffset.
derive({required Bip32KeyPair keys, required int index}) Bip32KeyPair
The magic of parent-to-child key-pair derivation happens here. If a parent signing key is provided, a child signing key is generated. If a parent verify key is provided and the index is NOT hardened, then a child verify key is also included. If hardened and no signingKey is provied, it returns an empty pair (i.e. error condition).
deriveAddressKeys({int purpose = defaultPurpose, int coinType = defaultCoinType, int account = defaultAccountIndex, int role = paymentRole, int index = defaultAddressIndex}) Bip32KeyPair
run down the 5 level hierarchical chain to derive a new address key pair.
deriveUnusedBaseAddressKit({int account = defaultAccountIndex, int role = paymentRole, int index = defaultAddressIndex, NetworkId networkId = NetworkId.testnet, UnusedAddressFunction unusedCallback = alwaysUnused}) ShelleyAddressKit
iterate key chain until an unused address is found, then return keys and address.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
stakingKeyPair({int account = defaultAccountIndex, int index = defaultAddressIndex, NetworkId networkId = NetworkId.testnet}) Bip32KeyPair
toBaseAddress({required Bip32PublicKey spend, required Bip32PublicKey stake, NetworkId networkId = NetworkId.testnet}) ShelleyAddress
construct a Shelley base address give a public spend key, public stake key and networkId
toRewardAddress({required Bip32PublicKey spend, NetworkId networkId = NetworkId.testnet}) ShelleyAddress
construct a Shelley staking address give a public spend key and networkId
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Constants

maxOverrun → const int