formatPrivateKey static method

String formatPrivateKey(
  1. HexInput privateKey,
  2. PrivateKeyVariants type
)

Format a HexInput to an AIP-80 compliant string.

Read about AIP-80

privateKey is the hex string or bytes format of the private key. type is the private key type.

Implementation

static String formatPrivateKey(HexInput privateKey, PrivateKeyVariants type) {
  final aip80Prefix = aip80Prefixes[type]!;

  // Remove the prefix if it exists.
  var formattedPrivateKey = privateKey;
  if (formattedPrivateKey is String &&
      formattedPrivateKey.startsWith(aip80Prefix)) {
    formattedPrivateKey = formattedPrivateKey.split('-')[2];
  }

  return '$aip80Prefix${Hex.fromHexInput(formattedPrivateKey)}';
}