encodeKey method
Overrides the base class method to encode a public key as a P2SH (Pay-to-Script-Hash) address.
This method encodes a public key as a P2SH address using Bech32 encoding. It expects an optional map of keyword arguments with 'hrp' specifying the Human-Readable Part (HRP) and 'net_ver' for the network version bytes of the address. It validates the arguments, processes the public key as a Secp256k1 key, generates a script signature, and encodes it as a P2SH address using Bech32.
Parameters:
- pubKey: The public key to be encoded as a P2SH address.
- kwargs: Optional keyword arguments with 'hrp' for HRP and 'net_ver' for network version.
Returns: A String representing the Bech32-encoded P2SH address derived from the provided public key.
Implementation
@override
String encodeKey(List<int> pubKey, [Map<String, dynamic> kwargs = const {}]) {
/// Validate HRP and network version arguments.
AddrKeyValidator.validateAddressArgs<String>(kwargs, "hrp");
AddrKeyValidator.validateAddressArgs<List<int>>(kwargs, "net_ver");
final String hrp = kwargs['hrp'];
final List<int> netVerBytes = kwargs['net_ver'];
/// Validate and process the public key as a Secp256k1 key.
final IPublicKey pubKeyObj =
AddrKeyValidator.validateAndGetSecp256k1Key(pubKey);
/// Encode the P2SH address using Bech32 encoding.
return BchBech32Encoder.encode(
hrp, netVerBytes, _P2SHAddrUtils.addScriptSig(pubKeyObj));
}