hashToPoint static method

Uint8List hashToPoint(
  1. Uint8List data
)

Keccak-256, decompress as Ed25519, retry on failure, then * 8 for subgroup.

Implementation

static Uint8List hashToPoint(Uint8List data) {
  final ed = VaultKeeper.vault.ed25519;
  var hash = VaultKeeper.vault.digest.keccak256(data);
  while (true) {
    try {
      final tryBytes = Uint8List.fromList(hash);
      tryBytes[31] &= 0x7f;
      // validatePoint will throw on invalid
      final point = ed.validatePoint(tryBytes);
      final cleared = ed.scalarMult(_cofactor8, point);
      // Check non-identity (not all zeros except byte 0 which would be 0x01)
      if (cleared[0] != 0x01 || cleared.skip(1).any((b) => b != 0)) {
        return cleared;
      }
    } catch (_) {} // decompression failed, retry
    hash = VaultKeeper.vault.digest.keccak256(hash);
  }
}