deriveArchethicKeypair function

KeyPair deriveArchethicKeypair(
  1. dynamic seed,
  2. String derivationPath,
  3. int index, {
  4. String curve = 'ed25519',
})

Implementation

KeyPair deriveArchethicKeypair(dynamic seed, String derivationPath, int index,
    {String curve = 'ed25519'}) {
  // Hash the derivation path
  final Digest sha256 = Digest('SHA-256');
  final Uint8List hashedPath = sha256.process(Uint8List.fromList(
      replaceDerivationPathIndex(derivationPath, index).codeUnits));

  final crypto_lib.Hmac hmac = crypto_lib.Hmac(crypto_lib.sha512, seed);
  final crypto_lib.Digest digest = hmac.convert(hashedPath);
  final Uint8List extendedSeed =
      Uint8List.fromList(digest.bytes.sublist(0, 32));

  return crypto.generateDeterministicKeyPair(
      extendedSeed, curve, keychainOriginId);
}