SuiAccount.fromPrivateKey constructor

SuiAccount.fromPrivateKey(
  1. String privateKey,
  2. SignatureScheme scheme
)

Implementation

factory SuiAccount.fromPrivateKey(String privateKey, SignatureScheme scheme) {
  final privateKeyHex = Hex.trimHex(Hex.prefixHex(privateKey));
  if (privateKeyHex.length != 64 && privateKeyHex.length != 128) {
    throw ArgumentError("Invalid private key length ${privateKeyHex.length}");
  }
  SuiAccount account;
  switch (scheme) {
    case SignatureScheme.Secp256k1:
      account = SuiAccount(
          Secp256k1Keypair.fromSecretKey(Hex.decode(privateKeyHex)));
      break;
    case SignatureScheme.Secp256r1:
      account = SuiAccount(
          Secp256r1Keypair.fromSecretKey(Hex.decode(privateKeyHex)));
      break;
    case SignatureScheme.Ed25519:
      account =
          SuiAccount(Ed25519Keypair.fromSecretKey(Hex.decode(privateKeyHex)));
      break;
    default:
      throw ArgumentError('Undefined SignatureScheme $scheme');
  }
  return account;
}