Skip to content

signature ¤

sign_request ¤

sign_request(
    request: Request,
    key: Ed25519PrivateKey,
    created: datetime,
)

Sign a request using HTTP Message Signatures.

The function adds three additional headers: Content-Digest, Signature-Input, and Signature. See the following spec for more details: https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-message-signatures

The signature covers the request method, the URL host and path, the Content-Type header, and the request body. At this time, an ED25519 signature is generated with a hard-coded key ID of "default".

Parameters:

Name Type Description Default
request Request

The request to sign.

required
key Ed25519PrivateKey

The Ed25519 private key to use to generate the signature.

required
created datetime

The times at which the signature is created.

required

verify_request ¤

verify_request(
    request: Request,
    key: Ed25519PublicKey,
    max_age: timedelta,
)

Verify a request containing an HTTP Message Signature.

The function checks three additional headers: Content-Digest, Signature-Input, and Signature. See the following spec for more details: https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-message-signatures

The function checks signatures that cover at least the request method, the URL host and path, the Content-Type header, and the request body (via the Content-Digest header). At this time, signatures must use a hard-coded key ID of "default".

Parameters:

Name Type Description Default
request Request

The request to verify.

required
key Ed25519PublicKey

The Ed25519 public key to use to verify the signature.

required
max_age timedelta

The maximum age of the signature.

required