#!/usr/bin/env ruby

# Public domain, no copyright. Use at your own risk.

# gem install jwt-eddsa
require "jwt/eddsa"

# EdDSA Token generated by LibJWT
# Key generated by OpenSSL (keys/eddsa_key_ed25519-pub.pem)
# The pub key was converted to 32-bytes with some openssl and CLI magic

token = "eyJhbGciOiJFRERTQSIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE0NzU5ODA1NDUsImlzc" +
        "yI6ImZpbGVzLm1hY2xhcmEtbGxjLmNvbSIsInJlZiI6IlhYWFgtWVlZWS1aWlpaLUF" +
        "BQUEtQ0NDQyIsInN1YiI6InVzZXIwIn0.19ip2DFFjaZ_UFVCo0OtdwuzSmOYModle" +
        "JVeFcAjb_4hrAAf0pZSf8O78pivbXLJenEIsaZ9REFOauBeDxbTBw"

pub_key = "\x1d\x48\xfe\xd7\x89\x0d\xe8\xde\x22\xe6\xa3\x55\x91\xf1\x21\xc0" +
          "\xa8\x82\x7f\xeb\x52\xae\xf4\x47\xb2\xd4\x1d\xb5\x5f\x1a\xe5\x03"

verify_key = Ed25519::VerifyKey.new(pub_key)

payload, header = JWT.decode(token, verify_key, true, algorithm: "EdDSA")
puts payload
puts header
