atproto/browser/dpop
Browser-native DPoP (RFC 9449) key generation and proof signing, backed
by WebCrypto (crypto.subtle). atproto/oauth/dpop.gleam’s gose/
kryptos-backed implementation compiles for the javascript target but
cannot run in a real browser tab: kryptos’s JS FFI is node:crypto-only,
with no WebCrypto anywhere in it. This module is not a drop-in for
dpop.gleam (different key type — a real, non-extractable WebCrypto
CryptoKeyPair, not a gose.Key — and every operation is async, since
WebCrypto itself is) — it’s for a from-scratch browser OAuth client. It
produces byte-identical DPoP proof JWTs otherwise: same claims, same
ES256-over-P-256 signing.
Types
An opaque WebCrypto keypair handle (a native CryptoKeyPair). Never
constructed or inspected from Gleam directly — every operation on it
goes through this module’s FFI, so the private key material never
crosses into Gleam-visible values.
pub type DpopKey
Values
pub fn bare_public_jwk(
key: DpopKey,
) -> promise.Promise(Result(json.Json, String))
The public key as a bare JWK (kty/crv/x/y), for embedding in a DPoP proof
header — mirrors atproto/oauth/dpop.bare_public_jwk.
pub fn generate_key() -> promise.Promise(DpopKey)
pub fn proof(
key: DpopKey,
method method: String,
url url: String,
nonce nonce: option.Option(String),
ath ath: option.Option(String),
) -> promise.Promise(Result(String, String))
Sign one DPoP proof JWT for a request. Claims match
atproto/oauth/dpop.proof exactly (jti/htm/htu/iat, optional nonce/ath).