deriveChildKey method

HDPrivateKey deriveChildKey(
  1. String path
)

Derives a child private key along the specified path

E.g.

var derived = privateKey.deriveChildKey("m/0'/1/2'");

Implementation

HDPrivateKey deriveChildKey(String path) {
    List<ChildNumber> children =  HDUtils.parsePath(path);


    //some imperative madness to ensure children have their parents' fingerprint
    var fingerprint = _calculateFingerprint();
    var parentChainCode = this.chainCode;
    var lastChild;
    var pubkey = this.publicKey;
    var privkey = this.keyBuffer;
    var nd = 1;
    for (ChildNumber elem in children){
        lastChild = _deriveChildPrivateKey(nd, Uint8List.fromList(privkey), elem, fingerprint, parentChainCode, pubkey.getEncoded(true));
        fingerprint = lastChild._calculateFingerprint();
        parentChainCode = lastChild.chainCode;
        pubkey = lastChild.publicKey;
        privkey = lastChild.keyBuffer;
        nd++;
    }

    return lastChild;

}