10 releases

0.3.1 Jul 15, 2024
0.2.1 Mar 20, 2024
0.1.6 Dec 20, 2022
0.1.5 Aug 15, 2022
0.1.1 Nov 23, 2021

#169 in Cryptography

Download history 459/week @ 2024-08-12 289/week @ 2024-08-19 554/week @ 2024-08-26 293/week @ 2024-09-02 625/week @ 2024-09-09 606/week @ 2024-09-16 601/week @ 2024-09-23 428/week @ 2024-09-30 699/week @ 2024-10-07 1473/week @ 2024-10-14 987/week @ 2024-10-21 780/week @ 2024-10-28 845/week @ 2024-11-04 949/week @ 2024-11-11 1362/week @ 2024-11-18 1189/week @ 2024-11-25

4,345 downloads per month

MIT/Apache

46KB
920 lines

truelayer-signing

Rust crate to produce & verify TrueLayer API requests signatures.

Crates.io Docs.rs

// `Tl-Signature` value to send with the request.
let tl_signature = truelayer_signing::sign_with_pem(kid, private_key)
    .method(Method::Post)
    .path("/payouts")
    .header("Idempotency-Key", idempotency_key)
    .body(body)
    .build_signer()
    .sign()?;

See full example.

Prerequisites

  • OpenSSL (see here for instructions).

Verifying webhooks

The verify_with_jwks function may be used to verify webhook Tl-Signature header signatures.

// `jku` field is included in webhook signatures
let jku = truelayer_signing::extract_jws_header(webhook_signature)?.jku?;

// check `jku` is an allowed TrueLayer url & fetch jwks JSON (not provided by this lib)
ensure_jku_allowed(jku)?;
let jwks = fetch_jwks(jku);

// jwks may be used directly to verify a signature
truelayer_signing::verify_with_jwks(jwks)
    .method(Method::Post)
    .path(path)
    .headers(all_webhook_headers)
    .body(body)
    .build_verifier()
    .verify(webhook_signature)?;

See webhook server example.

Dependencies

~3.5–5MB
~100K SLoC