Ed25519PublicKey.fromBytes constructor

Ed25519PublicKey.fromBytes(
  1. List<int> keyBytes
)

Factory method for creating an Ed25519PublicKey from a byte array. It checks the length and prefix of the provided keyBytes to ensure validity. If the keyBytes include a public key prefix, it removes it before creating the instance.

Implementation

factory Ed25519PublicKey.fromBytes(List<int> keyBytes) {
  if (keyBytes.length ==
      Ed25519KeysConst.pubKeyByteLen + Ed25519KeysConst.pubKeyPrefix.length) {
    final prefix = keyBytes.sublist(0, Ed25519KeysConst.pubKeyPrefix.length);
    if (BytesUtils.bytesEqual(prefix, Ed25519KeysConst.pubKeyPrefix) ||
        BytesUtils.bytesEqual(prefix, Ed25519KeysConst.xrpPubKeyPrefix)) {
      keyBytes = keyBytes.sublist(1);
    }
  }
  return Ed25519PublicKey._(
      EDDSAPublicKey(Curves.generatorED25519, keyBytes));
}