AdaPrivateKey.fromBytes constructor

AdaPrivateKey.fromBytes(
  1. List<int> privateKeyBytes
)

Constructs an AdaPrivateKey from the given privateKeyBytes.

Throws a MessageException if the length of privateKeyBytes is invalid.

Implementation

factory AdaPrivateKey.fromBytes(List<int> privateKeyBytes) {
  if (privateKeyBytes.length != Ed25519KeysConst.privKeyByteLen &&
      privateKeyBytes.length != Ed25519KholawKeysConst.privKeyByteLen) {
    throw MessageException("Invalid private key bytes.", details: {
      "length": privateKeyBytes.length,
      "Excepted":
          "${Ed25519KeysConst.privKeyByteLen} or ${Ed25519KholawKeysConst.privKeyByteLen}"
    });
  }
  IPrivateKey key;
  if (privateKeyBytes.length == Ed25519KholawKeysConst.privKeyByteLen) {
    key = Ed25519KholawPrivateKey.fromBytes(privateKeyBytes);
  } else {
    key = Ed25519PrivateKey.fromBytes(privateKeyBytes);
  }
  return AdaPrivateKey._(key);
}