btcAddress static method

String btcAddress(
  1. ECPublicKey pubkey
)

return a BTC Address

Implementation

static String btcAddress(ECPublicKey pubkey) {
  assert(pubkey.Q != null);
  Digest sha256 = Digest("SHA-256");
  Digest ripemd = RIPEMD160Digest();
  final pubBytes = pubkey.Q!.getEncoded(false);
  final shaHash = sha256.process(pubBytes);
  final ripHash = ripemd.process(shaHash);
  final networkHash = [0x00] + ripHash.toList();
  final check1 = sha256.process(Uint8List.fromList(networkHash));
  final check2 = sha256.process(check1);
  final finalCheck = check2.sublist(0, 4);
  final codeList = networkHash + finalCheck;
  Base58Encoder b58 = const Base58Encoder(
    '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz',
  );
  return b58.convert(codeList);
}