derivePath method

Future<_KeyData> derivePath(
  1. String path,
  2. Uint8List seedBytes, {
  3. int offset = _HARDENED_OFFSET,
})

Implementation

Future<_KeyData> derivePath(
  String path,
  Uint8List seedBytes, {
  int offset = _HARDENED_OFFSET,
}) async {
  if (!_pathRegex.hasMatch(path)) {
    throw ArgumentError(
        'Invalid derivation path. Expected BIP32 path format');
  }

  final master = getMasterKeyFromSeed(seedBytes);
  final segments = path.split('/').sublist(1);

  return segments.fold<Future<_KeyData>>(master,
      (prevKeyData, indexStr) async {
    final index = int.parse(indexStr.substring(0, indexStr.length - 1));
    final prev = await prevKeyData;
    final priv = await _getCKDPriv(prev, index + offset);

    return priv;
  });
}