encodeMultiEd25519Key static method

List<int> encodeMultiEd25519Key(
  1. List<Ed25519PublicKey> publicKeys,
  2. int threshold
)

encode Multi ED25519 public keys to MultiEd25519 address

Implementation

static List<int> encodeMultiEd25519Key(
    List<Ed25519PublicKey> publicKeys, int threshold) {
  try {
    final keys = publicKeys.toSet();
    if (keys.length != publicKeys.length) {
      throw AddressConverterException("Duplicate public key detected.");
    }
    if (publicKeys.length < AptosAddrConst.minPublicKeys ||
        publicKeys.length > AptosAddrConst.maximumPublicKeys) {
      throw AddressConverterException(
          "The number of public keys provided is invalid. It must be between ${AptosAddrConst.minPublicKeys} and ${AptosAddrConst.maximumPublicKeys}.");
    }
    if (threshold < AptosAddrConst.minthreshold ||
        threshold > publicKeys.length) {
      throw AddressConverterException(
          "Invalid threshold. The threshold must be between ${AptosAddrConst.minthreshold} and the number of provided public keys (${publicKeys.length}).");
    }
    final keyBytes = [
      ...publicKeys.map((e) => e.compressed.sublist(1)).expand((e) => e),
      threshold
    ];
    return hashKeyBytes(
        bytes: keyBytes, scheme: AptosAddrConst.multiEd25519AddressFlag);
  } on AddressConverterException {
    rethrow;
  } catch (e) {
    throw AddressConverterException(
        "Invalid aptos MultiEd25519 address bytes.",
        details: {"error": e.toString()});
  }
}