@imolko/ultra-event-signature
v0.4.2
Published
Formato v1 de firma de hechos CloudEvent (JSON canónico + DSSE PAE + Ed25519) y verificador puro sin dependencias.
Readme
ultra-event-signature
One primitive — sign a CloudEvent fact, verify it years later from a stored copy — shared by every service of the platform: the store-publisher worker, Sentinel, and the emitters (landlord, alchemix, cortex).
This package is a format and a crypto primitive, nothing else. It exists because the platform consumes facts emitted by services it does not control, and a fact must be able to prove who authored it after it has left its producer, been persisted, restored from a backup and replayed into a projection.
What this package is
| It is | It is not | |---|---| | the v1 fact-signature format (canonical JSON + DSSE PAE + Ed25519) | an event envelope, factory or shape registry | | one small, pure, dependency-free verifier | a key store, a secret manager or a policy distributor | | a trust-policy evaluator | a trust-policy owner: the key set and the scopes are configuration | | a published conformance suite in machine-readable vectors | a broker, a gateway or an admission service |
Custody never enters this package: private keys and key sets arrive as arguments. A library that can read a key from disk or from the environment is a library that will.
Public surface
| Export | Status |
|---|---|
| SIGNATURE_FORMAT_VERSION, DSSE_PREAMBLE, SIGNATURE_ALGORITHM, PAE_DIGEST_ALGORITHM | exported |
| signFact, verifyFact | spec 1, S2 |
| parseKeySet, parseTrustPolicy | spec 1, S3 |
| factPayloadType, toDsseEnvelope | spec 1, S4 |
| signFactKey, verifyFactKeyBundle, factKeyFingerprint | spec 2, S6 |
| ./vectors/* | published static JSON: conformance vectors |
The canonical JSON and the PAE are internal on purpose: a consumer that can call
them can get them half-right. The only published derivation is
factPayloadType, which returns the payloadType the format signs. The pure
entry point imports only node:crypto; the CLI lives in bin/ and is imported
by nothing in dist-node/index.js.
Conformance vectors
The package publishes its machine-readable vectors, so a consumer reads them from the installed package instead of vendoring a copy:
| Subpath | File |
|---|---|
| @imolko/ultra-event-signature/vectors/fact-signature.v1.json | the v1 fact vectors (04) |
| @imolko/ultra-event-signature/vectors/fact-key.v1.json | the fact-key bundle vector (07) |
They are static JSON under the ./vectors/* subpath, not module exports. Read
them from node_modules and pin the file's SHA-256 in the test that consumes
them; npm run conformance fails when either file changes:
// CommonJS: resolve by the published subpath, read the bytes, pin the digest.
const { createHash } = require("node:crypto");
const { readFileSync } = require("node:fs");
const path = require.resolve(
"@imolko/ultra-event-signature/vectors/fact-signature.v1.json",
);
const bytes = readFileSync(path);
const digest = createHash("sha256").update(bytes).digest("hex");
// fact-signature.v1.json
// a66b0b388bffcdd0ce49001d48a2f47a64cd1d79bbb13121e01a2eb93faa40f8
// fact-key.v1.json
// c316c8ea30c6a3e2baa800c035511e568a5844385bf40888cabf5dbdb337ddb7
const vectors = JSON.parse(bytes);// ESM: JSON modules need the import attribute under Node's exports map.
import vectors from "@imolko/ultra-event-signature/vectors/fact-signature.v1.json"
with { type: "json" };The vectors embed the publicly known test key from 04 §1. It MUST never be trusted by a production policy.
Fact-key bundle
An emitter publishes its public key as a fact-key bundle: a signed document
(fact-key.v1.json) and its detached 64-byte signature (fact-key.v1.sig). The
bundle proves the key is the one the emitter published and that the publisher
holds the private half (07 §1).
The CLI under bin/ produces and checks it; in this repository run it after
npm run build as node bin/fact-key.mjs, or as fact-key once the package is
installed.
generate — once per rotation, locally
node bin/fact-key.mjs generate --kid landlord-2026a --out .keysWrites .keys/landlord-2026a.private.pem (PKCS#8, mode 0600) and
.keys/landlord-2026a.public.json, then prints
{kid, publicKeyJwk, fingerprintSha256, privateKeyPath}. Keep .keys outside
the repository and the image. --force overwrites an existing pair.
build — document, signature and self-check
node bin/fact-key.mjs build \
--emitter landlord \
--kid landlord-2026a \
--source landlord.imolko.com/tenants \
--type com.nixailabs.landlord.v1.infra-provisioned \
--type com.nixailabs.landlord.v1.infra-updated \
--key-file .keys/landlord-2026a.private.pem \
--out-dir dist/fact-keyWrites dist/fact-key/fact-key.v1.json and fact-key.v1.sig, verifies the
result against {source, types} before writing, and prints
{kid, documentSha256, fingerprintSha256}. It exits 1 when the self-check is
not verified, so a pipeline cannot publish an unverified bundle.
Add --expect-document-sha256 or --expect-fingerprint-sha256 when the
reviewer already pinned them; a mismatch fails the same check.
verify — the reviewer's verdict
node bin/fact-key.mjs verify \
--document dist/fact-key/fact-key.v1.json \
--signature dist/fact-key/fact-key.v1.sig \
--source landlord.imolko.com/tenants \
--type com.nixailabs.landlord.v1.infra-provisioned \
--type com.nixailabs.landlord.v1.infra-updated \
--expect-document-sha256 <sha256-hex> \
--expect-fingerprint-sha256 <sha256-hex>Prints one JSON verdict: {kind: "verified", kid, documentSha256,
fingerprintSha256} or {kind: "rejected", reason, issues}. Exit codes are 0
for verified, 1 for rejected and 2 for a usage error.
Custody and pinning
The private key stays in the emitter's secret store or signing service: the CLI
receives its path, writes only into --out-dir, and never prints the private
key. generate creates key material once per rotation as a manual, protected
step; it is not the test seed from 04 §1,
which is public and must never reach production.
The consumer pins the digest of the OCI manifest that carries the bundle and
the bundle's fingerprintSha256 (07 §8),
confirming the fingerprint over a second channel. Verification is offline: a
consumer never fetches the bundle at fact-verification time. A verified bundle is
evidence for the reviewed key-set change; it grants the key no authority.
Interoperability helpers
Two helpers convert a fact into the shapes the rest of the ecosystem speaks, without turning the converter into a verdict:
factPayloadType(envelope)derivesapplication/vnd.nixailabs.fact.<type>.<dataVersion>+json, wheredataVersionis the last path segment ofdataschema. A missingtype/dataschema, an empty version or a version containing?/#isinvalid.toDsseEnvelope(signed)emits the DSSE statement of 05 §6:payloadis base64 standard of the canonical covered content andsigis base64 standard of the same 64 signature bytes. It does not verify the signature, consult the key set or evaluate the policy.
Both return a flat ParseResult ({ kind: 'parsed', value } or
{ kind: 'invalid', issues }) and never throw.
import { factPayloadType, toDsseEnvelope } from "@imolko/ultra-event-signature";
const payloadType = factPayloadType(signedEnvelope);
if (payloadType.kind === "parsed") {
console.log(payloadType.value);
// application/vnd.nixailabs.fact.com.example.v1.ping.1.0.0+json
}
const dsse = toDsseEnvelope(signedEnvelope);
if (dsse.kind === "parsed") {
console.log(dsse.value.signatures[0].keyid); // securityKeyId
console.log(dsse.value.payload); // base64(canonicalJson(covered))
}Because the payload and the signature are the ones the fact already carries,
stock DSSE tooling, cosign and a transparency log consume a fact without a
custom verifier.
Emitter kit
The flow an emitter needs before its first production fact is written down so it can be handed over without the surrounding conversation:
- Emitter checklist — the ten items of
05 §1, the integer-only rule
for
data, add-then-cut rotation and the custody warning. - Runnable signer — signs the
minimal-pingvector, verifies it against a test key set and policy, and prints the verdict, thesecurityKeyIdand the signature. Run it afternpm run buildwithnpm run example:sign.
The signer uses the test key from 04 §1. That key is publicly known: it exists to compare bytes and must never be used in a production key set, policy or image.
Delivery tools
- CLI under
bin/(spec 2):generate,buildandverify— the flow above. It reports the document digest and the key fingerprint and writes the two bundle files. - CI component (
templates/fact-key.yml, spec 3): a reusable GitLab job that builds and self-checks the bundle and, withpublish: true, pushes it as an OCI artifact and reports its manifest digest. Its self-test reproduces the published vector withpublish: falseand needs no registry credentials.
Both are delivery, not custody. They receive key material as arguments, never store it, and a valid bundle never grants the key any authority — the policy in 03 — trust policy decides what a key may sign.
CI component for fact-keys
templates/fact-key.yml is a GitLab CI component that runs the publish step of
07 §10 inside an emitter's
pipeline: it builds the bundle, re-runs the contract check a consumer will run,
optionally publishes the pair as an OCI artifact and reports the digests. It is
released with the package under the same tag (PJ-003), so the component and the
CLI that understands the format always travel together.
Include
include:
- component: $CI_SERVER_FQDN/imolko/ultra-stack/ultra-event-signature/fact-key@<tag>
inputs:
stage: deploy
library-package: "@imolko/ultra-event-signature@<tag>"
emitter: landlord
kid: landlord-2026a
source: landlord.imolko.com/tenants
types: com.nixailabs.landlord.v1.infra-provisioned,com.nixailabs.landlord.v1.infra-updated
# key-variable: FACT_KEY_PRIVATE_KEY
# registry-repository: "" # empty means $CI_REGISTRY_IMAGE
# publish: trueInputs
| Input | Required | Default | Meaning |
|---|---|---|---|
| stage | no | deploy | Stage that runs the job |
| library-package | yes | — | Exact npm spec or local tarball of the library |
| emitter | yes | — | Name the emitter publishes under |
| kid | yes | — | Key id, ^[A-Za-z0-9_.-]{1,128}$; at most 119 when publishing (OCI tag limit) |
| source | yes | — | Frozen source the key signs for |
| types | yes | — | Comma-separated types, no wildcards |
| key-variable | no | FACT_KEY_PRIVATE_KEY | Name of the CI variable holding the PEM (multiline, base64 or a File variable) |
| registry-repository | no | "" → $CI_REGISTRY_IMAGE | OCI repository to publish into |
| publish | no | true | Push the pair on a tag pipeline; false only leaves job artifacts |
| oras-version | no | 1.2.3 | oras release downloaded and verified against that release's checksums |
| expected-document-sha256 | no | "" | Pin the document digest; a mismatch fails the build |
| expected-signature-hex | no | "" | Pin the raw signature in hex; used by the self-test |
library-package is also the version input of the component: the YAML fixes no
version of its own. Use the exact spec of the same tag as the component
(fact-key@<tag> with @imolko/ultra-event-signature@<tag>), or a local tarball
in the self-test. The repository publishes with npm version in memory, and the
tag points at the integration commit where package.json still says 0.0.0, so
a default derived from the repository would not describe what was published.
scripts/component.test.mjs fails if the template pins a version or gives
library-package a default.
types is a comma-separated string because GitLab array inputs do not
interpolate reliably into script; the job splits it and passes one --type per
element.
The key variable
The job never receives the key as an input. key-variable names the CI variable
that holds the private key; the job copies it into a mktemp -d directory
outside the workspace, sets mode 0600 under umask 077, passes the file path
to the CLI and deletes the directory with a trap. The key is never printed,
never put on a command line and never lands in the artifacts; a missing or
empty variable stops the job with a message before the CLI runs.
GitLab requires a masked variable to be a single line with no spaces, so a multiline PEM cannot be masked directly. The component accepts three forms:
- a multiline PEM (handy for local runs and this repository's self-test);
- a base64-encoded PEM on one line — the form to use for a
maskedandprotectedvariable (base64 -w0 key.pem); - a GitLab File variable: the value is the path to the file that holds the PEM, which the job copies into its temporary directory.
The test key from 04 §1 is publicly
known and only belongs in the component's self-test. This repository does not
configure it as a GitLab variable: the job rebuilds it from testKey.pkcs8Hex in
the vector with
scripts/test-key-fixture.mjs and exports it
under the name key-variable points to. The self-test therefore travels with
the commit — no project setting to provision, nothing to leak, and it runs on a
fork. The component still reads it as a variable, which is the interface an
emitter uses; in an emitter's project that variable holds a real key and is
masked and protected. The job exits non-zero when fact-key build's
self-check is not verified, so an unverified bundle never reaches the registry.
Publication, rotation and pinning
With publish: true the job runs only on a tag pipeline, as 07
§10 describes, and pushes
fact-key.v1.json and fact-key.v1.sig with the media types of 07
§2 to
<registry-repository>:fact-key-<kid>, then reports the descriptor. oras is
downloaded from its official release and verified against the checksums that
release publishes, which protects the download, not the provenance of the
release: the version is pinned by oras-version and approved at review. A new key is
a new kid and therefore a new tag; add-then-cut rotation in
03 §6 still applies, and
a kid is never reused for a different key.
Every run leaves fact-key/fact-key.v1.json, fact-key.v1.sig and
digests.json as job artifacts. digests.json carries {kid, documentSha256,
fingerprintSha256, manifestDigest, package}; with publish: false,
manifestDigest is null.
The consumer pins the manifest digest — the manifestDigest the job reports,
or oras manifest fetch <repo>:fact-key-<kid> --descriptor — together with the
bundle's documentSha256 and fingerprintSha256, confirmed over a second
channel. Never pin the tag: a re-tag can move the name, not the digest already
reviewed. oras stamps a creation annotation on every push, so republishing the
same bundle under the same tag yields a different manifest digest; pin the digest
of the review that was actually approved. A consumer never fetches the bundle at
fact-verification time.
The component is consumed by tag from this repository. It is not published to
the GitLab CI/CD Catalog: that would require a release: job on a tag pipeline,
which this repository deliberately does not create.
generate is not a job
The component builds, verifies and publishes; it never creates key material. The
pair comes from fact-key generate run once per rotation, locally or on a
protected ref (07 §10), and the
private half is moved into the emitter's secret store by the operator. CI has no
step that generates or rotates keys (PJ-003).
The bundle this job publishes is delivery, not custody: it proves the key is the
one the emitter published and that the publisher holds the private half, and it
grants no authority beyond the consumer's policy.
Why a separate package
@imolko/ultra-ddd already has the two insertion points for event signing
(getEventSigned / isEventSignedWith) and implements a scheme the platform is
retiring. Putting the primitive inside it would force every consumer to take the
whole DDD toolkit and its release cadence, and would collide with the store
platform's deliberate decision not to depend on that envelope at runtime
(PJ-034). The dependency direction is therefore fixed:
emitters ──▶ @imolko/ultra-event-signature ◀── consumers
▲
@imolko/ultra-ddd delegates to itSpecifications
| Document | Contents |
|---|---|
| 00 — requirements | normative requirements, invariants, what "done" means |
| 01 — wire format | the v1 format: covered attributes, canonical JSON, PAE, signature, digest |
| 02 — API | public surface, purity, verdicts, errors, versioning |
| 03 — trust policy | key-set and policy shapes, evaluation order, rotation and revocation |
| 04 — conformance | the vectors, how to run them, how a non-TypeScript emitter conforms |
| 05 — integration | emitters, ultra-ddd delegation, Sentinel, consumers, HMAC retirement |
| 06 — delivery | slices, test-first plan, gates, definition of done |
| 07 — the fact-key bundle | how an emitter publishes its public key, and how a consumer verifies the publication |
Delivery surfaces: the fact-key CLI in bin/ (spec 2) and the GitLab CI
component in templates/fact-key.yml (spec 3).
Machine-readable vectors: vectors/fact-signature.v1.json
and vectors/fact-key.v1.json. They are published in
the tarball under the ./vectors/* subpath (04 §4).
Status
Waves A and B implemented. src/index.ts exports the format constants,
signFact, verifyFact, the key-set and trust-policy parsers, the
interoperability helpers and the fact-key API (signFactKey,
verifyFactKeyBundle, factKeyFingerprint). The fact-key CLI ships under
bin/ and the reusable CI component lives in templates/fact-key.yml; both are
released with the package (PJ-003). The wire format and its vectors are frozen,
and the package still has zero runtime dependencies — the only runtime import in
dist-node/index.js is node:crypto.
The decisions this package serves are recorded in the store platform's project
tier: PJ-049 (a fact is trusted by the key that signed it) and PJ-050
(Sentinel is the admission point and forwards the emitter's signature), in
imolko/nixai-stores/generator under docs/adr/. This repository keeps its own
project decisions in docs/adr/: PJ-001
(CommonJS build), PJ-002
(no domain layer), PJ-003
(fact-key, CLI and CI component as product), PJ-004
(flat results, zero runtime dependencies), PJ-005
(the tenancy rule) and PJ-006
(the key is resolved before the digest in verifyFact).
Engineering rules
- Zero runtime dependencies.
node:cryptoonly. Node 22.14+. - The library entry point is pure: no I/O, no environment, no filesystem, no network, no clock. The CLI is the only file-reading surface and lives outside the built entry point's import graph.
- Deterministic: the same envelope and key produce the same signature bytes (Ed25519 per RFC 8032), which is what makes the vectors assertable.
- Test-first. Every test carries
@name/@scenarioJSDoc. - Conventional Commits. Semver. Breaking the wire format is a major of this
package and a new
signatureFormatin the key set, never a silent change.
