CardanoSigner.fromKeyBytes constructor

CardanoSigner.fromKeyBytes(
  1. List<int> keyBytes
)

Factory method to create an SolanaSigner instance from key bytes.

Implementation

factory CardanoSigner.fromKeyBytes(List<int> keyBytes) {
  if (keyBytes.length != Ed25519KholawKeysConst.privKeyByteLen &&
      keyBytes.length != Ed25519KeysConst.privKeyByteLen) {
    throw MessageException("Invalid key bytes length.", details: {
      "length": keyBytes.length,
      "Excepted":
          "${Ed25519KholawKeysConst.privKeyByteLen} or ${Ed25519KeysConst.privKeyByteLen}"
    });
  }
  // Create an EDDSA private key from the key bytes using the ED25519 curve.
  final EDDSAPrivateKey signingKey;
  if (keyBytes.length == Ed25519KholawKeysConst.privKeyByteLen) {
    signingKey = EDDSAPrivateKey.fromKhalow(
        CardanoSignerConst.ed25519Generator, keyBytes);
  } else {
    signingKey = EDDSAPrivateKey(
        CardanoSignerConst.ed25519Generator, keyBytes, () => SHA512());
  }
  return CardanoSigner._(signingKey);
}