mooncred — credential formats for MoonBit: JSON Web Tokens, JWS, JWK and the JOSE algorithm set, built on mooncrypt's algorithms and moonbase's encodings.
// The key is whatever signs. Here, HMAC over SHA-256.
let key = @jwt.mac(fn() {
@hmac.Hmac::new(secret[:], fn() { @sha2.Hasher::new() })
})
let token = @jwt.sign(claims, HS256, key)
// The algorithm is the caller's, not the token's.
let got = @jwt.verify(token[:], HS256, key, now=now_seconds,
issuer=Some("moonbitstack"), audience=Some("moonapi"))| Package | What | Specification |
|---|---|---|
| jwt | JWS compact serialisation, all thirteen JOSE algorithms | RFC 7515, 7518, 7519, 8037 |
| jwk | JSON Web Key and key sets: reading, writing, choosing | RFC 7517, RFC 7518 §6 |
match key.material() {
Okp(x~, ..) => @ed25519.PublicKey::new(x[:])
_ => …
}moon add moonbitstack/mooncredInstall
Download zipmooncred — credential formats for MoonBit: JSON Web Tokens, JWS, JWK and the JOSE algorithm set, built on mooncrypt's algorithms and moonbase's encodings.