Commit b66856d
authored
feat(pre-registration): expose hashJson + canonicalize for arbitrary content signing (#32)
The canonicalize+sha256 logic that signManifest is built on is general enough
that consumers signing arbitrary structured content (artifact bundles,
production packets, dataset versions, etc.) end up reimplementing it from
scratch. Two cases I checked while making this change:
- physim/apps/server/src/lib/manifest.ts re-implements canonicalize+sha256
for production-packet attestation, with an inline comment noting that
agent-eval's signer is shaped for HypothesisManifest only.
- phony/products/builder/api/src/eval/champion-sign.ts re-implements the
same canonicalize+sha256 (sync variant) before wrapping in Ed25519.
Both pieces of duplication go away if the generic primitive is exposed.
This change:
- Lifts the previously-private `canonicalize(v: unknown)` to an exported
function. Recursive key-sort, primitives pass through, arrays preserve
order. Behavior unchanged from the inlined version.
- Adds `hashJson<T>(obj: T): Promise<string>` — sha256 hex (full 64 chars)
over the canonicalized JSON encoding. The same primitive signManifest is
built on, refactored to call through.
- Naming: I went with `hashJson` rather than `hashContent` because
prompt-registry already exports `hashContent(s: string)` for the
truncated 12-char prompt-id helper. Different semantics (string in,
short id out) — the two coexist, named for what each actually does.
Backward compat: signManifest / verifyManifest output bit-for-bit identical
hashes (verified by a new test that compares hashJson(base) directly against
signManifest(base).contentHash). All 827 existing tests still pass.
Tests added:
- canonicalize sorts keys recursively + preserves array order + passes primitives
- hashJson is stable across key insertion order
- hashJson(base) === signManifest(base).contentHash (composition guarantee)
- hashJson and prompt-registry's hashContent are independent (different return shape)1 parent f5c1a88 commit b66856d
3 files changed
Lines changed: 92 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
497 | 497 | | |
498 | 498 | | |
499 | 499 | | |
500 | | - | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
501 | 507 | | |
502 | 508 | | |
503 | 509 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
75 | 124 | | |
76 | 125 | | |
77 | 126 | | |
| |||
83 | 132 | | |
84 | 133 | | |
85 | 134 | | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
| 135 | + | |
92 | 136 | | |
93 | 137 | | |
94 | 138 | | |
| |||
133 | 177 | | |
134 | 178 | | |
135 | 179 | | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
| 16 | + | |
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
| |||
172 | 174 | | |
173 | 175 | | |
174 | 176 | | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
175 | 210 | | |
0 commit comments