Sign Requests
In this guide, we will give a monitorable a signing key and sign its encrypted requests.Why Sign Requests?
Encryption keeps a request private, but anyone with your access token can still send one. A monitorable signing key proves that each encrypted request came from the device that holds the key's private half.
Once a monitorable has a signing key:
- Every encrypted request is checked: Updates, lookups, and incident requests for the monitorable must be signed, or Hyperion returns 401
- Ciphertexts are bound to the key: The key's hash is part of each HPKE
info, so a request encrypted without it fails to decrypt - The private key never leaves the device: Hyperion stores only the public key and never returns it in responses
Signing is optional per monitorable. Without a signing key, signature fields are ignored. Plaintext requests are never signed.
Getting Started
Before signing requests, you need:
- An application with the
key:readandmonitorable:writescopes. - The helpers and encryption key from the Encrypt Monitorable Data guide.
How It Works
Each encrypted request defines a 32-byte commitment hash over its timestamp and ciphertext. Your device signs the commitment and sends the signature in the envelope. Hyperion rebuilds the commitment from the envelope and checks the signature with the monitorable's stored key.
The commitment and HPKE info for every request are listed on the Encrypted Requests concept page.
Step 1: Generate a Signing Key
Hyperion supports two signing profiles. Choose one per device.
| Profile | Signature size | When to use |
|---|---|---|
ecdsa-p256 | 64 bytes | Broad hardware and library support |
composite-mldsa65-ecdsa-p256 | 3373 bytes | Post-quantum protection combined with ECDSA P-256 |
Both examples return the same SigningKey shape, which the rest of this guide uses.
ECDSA P-256
import { webcrypto } from "node:crypto";
export interface SigningKey {
publicKeySpki: Uint8Array;
sign(message: Uint8Array): Promise<Uint8Array>;
}
export async function generateEcdsaSigningKey(): Promise<SigningKey> {
const { publicKey, privateKey } = await webcrypto.subtle.generateKey(
{ name: "ECDSA", namedCurve: "P-256" },
false,
["sign", "verify"],
);
return {
publicKeySpki: new Uint8Array(
await webcrypto.subtle.exportKey("spki", publicKey),
),
sign: async (message) =>
new Uint8Array(
await webcrypto.subtle.sign(
{ name: "ECDSA", hash: "SHA-256" },
privateKey,
message,
),
),
};
}
WebCrypto returns ECDSA signatures in the 64-byte r ‖ s form Hyperion expects. If your platform returns DER signatures, convert them first.
Composite ML-DSA-65 and ECDSA P-256
The composite profile uses the @noble/post-quantum package for ML-DSA-65.
import { createHash, webcrypto } from "node:crypto";
import { ml_dsa65 } from "@noble/post-quantum/ml-dsa.js";
const COMPOSITE_ALGORITHM = Uint8Array.from([
0x06, 0x08, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x83, 0xb7, 0x0f, 0x01,
]);
const P256_POINT_LENGTH = 65;
function der(tag: number, content: Uint8Array): Uint8Array {
const length = content.byteLength;
const lengthBytes =
length < 0x80
? [length]
: length < 0x100
? [0x81, length]
: [0x82, length >> 8, length & 0xff];
return concat(Uint8Array.from([tag, ...lengthBytes]), content);
}
export async function generateCompositeSigningKey(): Promise<SigningKey> {
const mlDsa = ml_dsa65.keygen(webcrypto.getRandomValues(new Uint8Array(32)));
const ecdsa = await webcrypto.subtle.generateKey(
{ name: "ECDSA", namedCurve: "P-256" },
false,
["sign", "verify"],
);
const ecdsaSpki = new Uint8Array(
await webcrypto.subtle.exportKey("spki", ecdsa.publicKey),
);
const ecdsaPoint = ecdsaSpki.subarray(ecdsaSpki.byteLength - P256_POINT_LENGTH);
return {
publicKeySpki: der(
0x30,
concat(
der(0x30, COMPOSITE_ALGORITHM),
der(0x03, concat(Uint8Array.of(0), mlDsa.publicKey, ecdsaPoint)),
),
),
async sign(message) {
const prehash = new Uint8Array(
createHash("sha512").update(message).digest(),
);
const ecdsaSignature = await webcrypto.subtle.sign(
{ name: "ECDSA", hash: "SHA-512" },
ecdsa.privateKey,
prehash,
);
return concat(
ml_dsa65.sign(prehash, mlDsa.secretKey),
new Uint8Array(ecdsaSignature),
);
},
};
}
Generate and keep the private key on the device, ideally in hardware-backed storage. Never send it to Hyperion or log it.
Step 2: Register with a Signing Key
Send the public key and a signature with the encrypted register request. Hyperion stores the key only if the signature, made with that key, verifies.
Add the key's hash to the HPKE info, then sign the commitment over requestTimestamp and the ciphertext:
const requestTimestamp = canonicalTimestamp();
const encryptedPayload = await sealHpke(
encryptionKey,
jsonBytes(createMonitorableRequest),
lp(sha256(signingKey.publicKeySpki)),
lp(requestTimestamp),
);
const commitment = sha256(
concat(lp(requestTimestamp), lp(sha256(encryptedPayload))),
);
const envelope = {
encryptionKeyId: encryptionKey.id,
requestTimestamp,
encryptedPayload: toBase64(encryptedPayload),
pkSigningKey: toBase64(signingKey.publicKeySpki),
signature: toBase64(await signingKey.sign(commitment)),
};
Send the envelope to POST /v1/monitorables as in Encrypt Monitorable Data. pkSigningKey and signature must be sent together.
You can also set the key with the pkSigningKey field of a plaintext create or update request.
Step 3: Sign Later Requests
Requests for a monitorable with a signing key identify the key by its hash and sign the request's commitment. For an encrypted update:
const pkSigningKeyHash = sha256(signingKey.publicKeySpki);
const requestTimestamp = canonicalTimestamp();
const encryptedPayload = await sealHpke(
encryptionKey,
jsonBytes(updateMonitorableRequest),
concat(lp(pkSigningKeyHash), lp(monitorableId)),
lp(monitorableId),
);
const commitment = sha256(
concat(
lp(monitorableId),
lp(requestTimestamp),
lp(sha256(encryptedPayload)),
),
);
const envelope = {
encryptionKeyId: encryptionKey.id,
requestTimestamp,
encryptedPayload: toBase64(encryptedPayload),
pkSigningKeyHash: toBase64(pkSigningKeyHash),
signature: toBase64(await signingKey.sign(commitment)),
};
Each request carries its signature in its own fields:
| Request | Key fields | Signature fields |
|---|---|---|
| Update | pkSigningKeyHash | signature |
| Lookups | None | signature |
| Create incident | pkSigningKeyHash | reconstruction.signatureIncidentKey, events[].signaturePayload |
| Add event | pkSigningKeyHash | signaturePayload |
| Update incident | pkSigningKeyHash | signaturePayload |
See Look Up Records and Encrypt Incidents for those requests.
Step 4: Replace or Remove the Key
To replace the key, send an encrypted update that carries the new key in pkSigningKey instead of pkSigningKeyHash. Use the new key's hash in the HPKE info, and sign the commitment with the new key:
const encryptedPayload = await sealHpke(
encryptionKey,
jsonBytes(updateMonitorableRequest),
concat(lp(sha256(newSigningKey.publicKeySpki)), lp(monitorableId)),
lp(monitorableId),
);
const envelope = {
encryptionKeyId: encryptionKey.id,
requestTimestamp,
encryptedPayload: toBase64(encryptedPayload),
pkSigningKey: toBase64(newSigningKey.publicKeySpki),
signature: toBase64(await newSigningKey.sign(commitment)),
};
commitment is built the same way as in Step 3. Once the update succeeds, sign every later request with the new key.
To remove the key, send "pkSigningKey": null inside the update request, signed with the current key as in Step 3. Later requests are then no longer signed.
Try It: Sign a Request
Use the builder below to sign requests in your browser:
- Select a signing profile to generate a signing key. The private key stays in this browser tab.
- Register a monitorable with the key. The envelope carries
pkSigningKeyandsignature. - Switch to Update a monitorable and enter the monitorable's ID. Choose Stored key to sign with the key you registered, or generate a new key and choose New key to replace it.
The lookup and incident builders on the other encryption guides sign with the same key until you reload the page.
Encrypted monitorable request builder
Fill in a register or update request and encrypt it to your encryption key.
Encryption key
Paste the id, algorithm, and publicKey from GET /v1/encryption-keys/current, or generate a demo key. Hyperion can't decrypt requests built with a demo key.
Monitorable signing key
Generated in this browser tab and kept only until you reload. Other builders on these pages sign with the same key.
Request
External identifier to represent this monitorable. Alternatively, send the optional query parameter externalId; a query value takes precedence over the body.
Personal identification code for the monitorable. Cannot be reused across contacts and the monitorable.
Optional base64-encoded SPKI DER monitorable signing public key. When stored, later encrypted requests for this monitorable must include a valid signature.
Type of premises being monitored
{}
Signature Errors
| Status | Message | Cause |
|---|---|---|
| 401 | Signature required | The monitorable has a signing key and the request has no signature |
| 401 | pkSigningKeyHash does not match the stored signing key | pkSigningKeyHash is missing or isn't the hash of the stored key |
| 401 | Invalid signature | The signature doesn't verify against the commitment |
| 400 | Failed to decrypt encryptedPayload | The HPKE info left out the key's hash, or used the wrong key |
Conclusion
You've given a monitorable a signing key and signed its encrypted requests. Hyperion now rejects any encrypted request for the monitorable that your device didn't sign.
Best Practices
- One key per device: Generate the signing key on the device that sends the requests
- Sign the commitment, not the JSON: The signed message is always the 32-byte commitment hash
- Include the key's hash in
info: Every HPKEinfofor a signed monitorable starts withlp(H(pkSigningKey)) - Rotate with proof: Replace a key with an update signed by the new key
- Prefer the composite profile: It keeps requests verifiable if ECDSA is broken
Learn More
Related Guides
- Encrypt Monitorable Data - Register and update monitorables with encrypted requests
- Look Up Records - Read records with encrypted lookups
- Encrypt Incidents - Create and update incidents with encrypted requests
Related Concepts
- Encrypted Requests - Every envelope, binding, and signed commitment
- Monitorables - Entities that can be monitored
API Reference
- Create Monitorable - Register a monitorable with a signing key
- Update Monitorable - Replace or remove a signing key