decodeAptosPrivateKey static method

(AptosKeyAlgorithm, List<int>) decodeAptosPrivateKey(
  1. String privateKey
)

decode aptos AIP-80 private key style to private key.

Implementation

static (AptosKeyAlgorithm, List<int>) decodeAptosPrivateKey(
    String privateKey) {
  int index = privateKey.lastIndexOf("-");
  if (index == -1) {
    throw DartAptosPluginException("Invalid aptos AIP-80 private key style.");
  }
  index += 1;

  try {
    final algorithm =
        AptosKeyAlgorithm.fromAip80(privateKey.substring(0, index));
    final keyBytes = BytesUtils.fromHexString(privateKey.substring(index));
    return (algorithm, keyBytes);
  } catch (e) {
    throw DartAptosPluginException("Invalid aptos AIP-80 private key style.",
        details: {"error": e.toString()});
  }
}