encodeSuiSecretKey static method

String encodeSuiSecretKey(
  1. List<int> secretKey, {
  2. EllipticCurveTypes? type,
  3. SuiKeyAlgorithm? keyScheme,
})

Encodes the Sui private key to a Bech32 string.

The encoded format includes the suiprivkey HRP, the key scheme flag, and the secret key bytes.

Implementation

static String encodeSuiSecretKey(
  List<int> secretKey, {
  EllipticCurveTypes? type,
  SuiKeyAlgorithm? keyScheme,
}) {
  if (keyScheme == null && type == null) {
    throw DartSuiPluginException(
      "Key scheme or Elliptic curve type required for generate sui Bech32 secret key.",
    );
  }
  keyScheme ??= SuiKeyAlgorithm.fromEllipticCurveType(type!);
  final key = IPrivateKey.fromBytes(secretKey, keyScheme.curveType);
  return Bech32Encoder.encode(SuiKeypairConst.suiPrivateKeyPrefix, [
    keyScheme.flag,
    ...key.raw,
  ]);
}