signMessage
import { signMessage } from "jsr:@ende/http/unstable-message-signatures";function ยท experimental
async function signMessage<T extends Request | Response>(options: SignOptions<T>): Promise<T>Sign an HTTP message per RFC 9421.
Returns a new Request/Response with Signature and Signature-Input
headers appended. The original message is not mutated.
options: SignOptions<T>Signing options.
Returns
A new message with signature headers appended.
Example: Usage
import { signMessage } from "@ende/http/unstable-message-signatures";
import { assert } from "@ende/assert";
const key = await crypto.subtle.generateKey("Ed25519", true, ["sign", "verify"]) as CryptoKeyPair;
const request = new Request("https://example.com/", { method: "POST" });
const signed = await signMessage({
message: request,
params: {
components: ["@method", "@authority"],
keyId: "test-key",
created: Math.floor(Date.now() / 1000),
},
key: key.privateKey,
});
assert(signed.headers.has("Signature"));
assert(signed.headers.has("Signature-Input"));