Bip32Base.fromExtendedKey constructor
Bip32Base.fromExtendedKey(
- String exKeyStr, [
- Bip32KeyNetVersions? keyNetVer
Creates a BIP-32 key from an extended key string.
The exKeyStr
parameter represents the extended key string, and the
optional keyNetVer
specifies the key network version.
Implementation
Bip32Base.fromExtendedKey(String exKeyStr, [Bip32KeyNetVersions? keyNetVer]) {
keyNetVer ??= defaultKeyNetVersion;
final deserKey =
Bip32KeyDeserializer.deserializeKey(exKeyStr, keyNetVer: keyNetVer);
final keyBytes = deserKey.keyBytes;
final Bip32KeyData keyData = deserKey.keyData;
final isPublic = deserKey.isPublic;
if (keyData.depth.depth == 0) {
if (!keyData.parentFingerPrint.isMasterKey()) {
throw Bip32KeyError(
'Invalid extended master key (wrong fingerprint: ${keyData.parentFingerPrint.toHex()})');
}
if (keyData.index.index != 0) {
throw Bip32KeyError(
'Invalid extended master key (wrong child index: ${keyData.index.toInt()})');
}
}
_privKey = _initializePrivateKey(isPublic ? null : keyBytes,
isPublic ? keyBytes : null, keyData, keyNetVer, curveType);
_pubKey = _initializePublicKey(isPublic ? null : keyBytes,
isPublic ? keyBytes : null, keyData, keyNetVer, curveType);
}