verifyJWS function

dynamic verifyJWS(
  1. String token,
  2. String publicKey
)

Verifies the provided JWS token using the public key and returns the payload if the verification is successful.

The token parameter represents the JWS token to be verified. The publicKey parameter represents the public key used for verification. The function returns the payload of the JWS token if the verification is successful, otherwise it returns null.

Implementation

dynamic verifyJWS(String token, String publicKey) {
  try {
    final jwt = JWT.verify(
      token,
      EdDSAPublicKey(hex.decode(publicKey)),
      checkHeaderType: false,
    );

    return jwt.payload;
  } on JWTExpiredException {
    print("jwt expired");
  } on JWTException catch (ex) {
    print(ex.message);
  }
}