forPath method
Derives a key based on a path.
A path is a slash delimited string starting with 'm' for private key and 'M' for a public key. Hardened keys are indexed with a tick. Example: "m/100/1'". This is the first Hardened private extended key on depth 2.
Implementation
ExtendedKey forPath(String path) {
_validatePath(path);
var wantsPrivate = path[0] == _privateKeyPrefix;
var children = _parseChildren(path);
if (children.isEmpty) {
if (wantsPrivate) {
return root!;
}
return root!.publicKey();
}
dynamic derivationFunction = wantsPrivate
? deriveExtendedPrivateChildKey
: deriveExtendedPublicChildKey;
return children.fold(root!, (ExtendedKey previousKey, int childNumber) {
return derivationFunction(previousKey, childNumber);
});
}