XrpVerifier.fromKeyBytes constructor

XrpVerifier.fromKeyBytes(
  1. List<int> keyBytes,
  2. EllipticCurveTypes algorithm
)

Factory method to create an XrpVerifier instance from key bytes and curve type.

keyBytes The bytes representing the public key. algorithm The elliptic curve type of the public key.

Implementation

factory XrpVerifier.fromKeyBytes(
  List<int> keyBytes,
  EllipticCurveTypes algorithm,
) {
  switch (algorithm) {
    case EllipticCurveTypes.ed25519:
      final pub = Ed25519PublicKey.fromBytes(keyBytes);
      final verifyingKey = EDDSAPublicKey(
        CryptoSignerConst.generatorED25519,
        pub.compressed.sublist(1),
      );
      return XrpVerifier._(verifyingKey, null);
    case EllipticCurveTypes.secp256k1:
      final point = ProjectiveECCPoint.fromBytes(
        curve: CryptoSignerConst.generatorSecp256k1.curve,
        data: keyBytes,
        order: null,
      );
      final verifyingKey = ECDSAPublicKey(
        CryptoSignerConst.generatorSecp256k1,
        point,
      );
      return XrpVerifier._(null, ECDSAVerifyKey(verifyingKey));
    default:
      throw ArgumentException.invalidOperationArguments(
        "XrpVerifier",
        name: "algorithm",
        reason: "Unsupported key algorithm.",
      );
  }
}