Skip to main content

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:

  1. An application with the key:read and monitorable:write scopes.
  2. 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.

ProfileSignature sizeWhen to use
ecdsa-p25664 bytesBroad hardware and library support
composite-mldsa65-ecdsa-p2563373 bytesPost-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:

RequestKey fieldsSignature fields
UpdatepkSigningKeyHashsignature
LookupsNonesignature
Create incidentpkSigningKeyHashreconstruction.signatureIncidentKey, events[].signaturePayload
Add eventpkSigningKeyHashsignaturePayload
Update incidentpkSigningKeyHashsignaturePayload

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:

  1. Select a signing profile to generate a signing key. The private key stays in this browser tab.
  2. Register a monitorable with the key. The envelope carries pkSigningKey and signature.
  3. 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.

No encryption key yet
Key no key ID · no signing 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

Request to encrypt
{}

Signature Errors​

StatusMessageCause
401Signature requiredThe monitorable has a signing key and the request has no signature
401pkSigningKeyHash does not match the stored signing keypkSigningKeyHash is missing or isn't the hash of the stored key
401Invalid signatureThe signature doesn't verify against the commitment
400Failed to decrypt encryptedPayloadThe 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 HPKE info for a signed monitorable starts with lp(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​

API Reference​