encodeKey method

  1. @override
String encodeKey(
  1. List<int> pubKey, {
  2. String? hrp,
})
override

Overrides the base class method to encode a public key as a P2TR (Pay-to-Taproot) address.

Implementation

@override
String encodeKey(List<int> pubKey, {String? hrp}) {
  hrp = AddrKeyValidator.getAddrArg<String>(hrp, "hrp");

  /// Validate and process the public key as a Secp256k1 key.
  final pubKeyObj = AddrKeyValidator.validateAndGetSecp256k1Key(pubKey);

  /// Tweak the public key to create a P2TR address.
  final tweakedPubKey = BigintUtils.toBytes(
    P2TRUtils.tweakPublicKey(pubKeyObj.point as ProjectiveECCPoint).x,
    length: Curves.curveSecp256k1.baselen,
  );

  /// Encode the tweaked public key as a P2TR address using Bech32.
  return SegwitBech32Encoder.encode(hrp, P2TRConst.witnessVer, tweakedPubKey);
}