Skip to content

Commit 04c4ff1

Browse files
committed
refactor(spec): build config.signature's two arms on the shared strictObject helper
The arms' unknown-key prescriptions move from hand-written error maps into strictObject guidance, so the alias-integrity audit registers them. Claude-Session: https://claude.ai/code/session_01WGufzggC8errMtPRYBUmoY Co-authored-by: Claude <noreply@anthropic.com>
1 parent e940477 commit 04c4ff1

1 file changed

Lines changed: 28 additions & 18 deletions

File tree

‎packages/spec/src/automation/api-trigger-signature.zod.ts‎

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import { z } from 'zod';
4+
import { strictObject } from '../shared/strict-object';
45
import { resolveFlowTriggerKind } from './flow-trigger-kind';
56
import { API_TRIGGER_SECRET_REF_KEY, apiTriggerSecretRefOf } from './api-trigger-secret-ref.zod';
67

@@ -71,6 +72,15 @@ const DIGEST_PREFIX = /^[\x21-\x2B\x2D-\x7E]+$/;
7172
/** The name of one `NAME=value` element of a signature header. */
7273
const ELEMENT_NAME = /^[A-Za-z0-9_-]+$/;
7374

75+
const BORN_CLOSED =
76+
'Declared closed from its first day: a key a verifier does not read is refused, never dropped, because an ' +
77+
'ignored setting on an auth boundary reads as a check that is not made.';
78+
79+
const NO_TIMESTAMP_ON_BODY =
80+
'A body-only scheme (`signs: \'body\'`) signs no time, so it has no timestamp to bound a replay with and no ' +
81+
'element list to read: `timestampElement` and `digestElement` belong to `signs: \'timestamp.body\'`. Declare ' +
82+
'`signs: \'timestamp.body\'` when the sender signs `<t>.<raw body>`, or remove them.';
83+
7484
const header = z
7585
.string({
7686
error: () =>
@@ -129,7 +139,14 @@ const element = (key: 'timestampElement' | 'digestElement', what: string) =>
129139
* Exported as its own def so the published surface records its keys (a union's
130140
* arms are otherwise invisible to the authorable-surface ledger).
131141
*/
132-
export const ApiTriggerBodySignatureSchema = z.strictObject(
142+
export const ApiTriggerBodySignatureSchema = strictObject(
143+
{
144+
surface: '`config.signature` (`signs: \'body\'`)',
145+
history: BORN_CLOSED,
146+
guidanceSets: [
147+
{ name: 'TIMESTAMPED_SIGNATURE_ELEMENT_KEYS', keys: ['timestampElement', 'digestElement'], prescription: NO_TIMESTAMP_ON_BODY },
148+
],
149+
},
133150
{
134151
signs: z.literal('body').describe('The sender signs the raw body alone. No replay window applies.'),
135152
header,
@@ -147,15 +164,6 @@ export const ApiTriggerBodySignatureSchema = z.strictObject(
147164
'sender), checked and removed before decoding. Absent: the whole value is the digest.',
148165
),
149166
},
150-
{
151-
error: (issue) =>
152-
issue.code === 'unrecognized_keys' &&
153-
(issue.keys.includes('timestampElement') || issue.keys.includes('digestElement'))
154-
? 'A body-only scheme (`signs: \'body\'`) signs no time, so it has no timestamp to bound a replay with and no ' +
155-
'element list to read: `timestampElement` and `digestElement` belong to `signs: \'timestamp.body\'`. ' +
156-
'Declare `signs: \'timestamp.body\'` when the sender signs `<t>.<raw body>`, or remove them.'
157-
: undefined,
158-
},
159167
).describe(
160168
'A sender that signs the raw body alone (DocuSign Connect, a GitHub-style `sha256=` sender): the header value, ' +
161169
'after `prefix`, is the one digest. No replay window applies.',
@@ -169,7 +177,16 @@ export const ApiTriggerBodySignatureSchema = z.strictObject(
169177
* `x-objectstack-signature` check applies. Exported as its own def for the
170178
* same reason as {@link ApiTriggerBodySignatureSchema}.
171179
*/
172-
export const ApiTriggerTimestampedSignatureSchema = z.strictObject(
180+
export const ApiTriggerTimestampedSignatureSchema = strictObject(
181+
{
182+
surface: '`config.signature` (`signs: \'timestamp.body\'`)',
183+
history: BORN_CLOSED,
184+
guidance: {
185+
prefix:
186+
'A `timestamp.body` scheme locates its digest by `digestElement` (`v1` for `t=…,v1=…`), not by a `prefix`. ' +
187+
'Remove `prefix`.',
188+
},
189+
},
173190
{
174191
signs: z
175192
.literal('timestamp.body')
@@ -186,13 +203,6 @@ export const ApiTriggerTimestampedSignatureSchema = z.strictObject(
186203
'rolls its key; the post verifies when one of them matches.',
187204
),
188205
},
189-
{
190-
error: (issue) =>
191-
issue.code === 'unrecognized_keys' && issue.keys.includes('prefix')
192-
? 'A `timestamp.body` scheme locates its digest by `digestElement` (`v1` for `t=…,v1=…`), not by a `prefix`. ' +
193-
'Remove `prefix`.'
194-
: undefined,
195-
},
196206
).describe(
197207
'A sender that signs `<t>.<raw body>` and writes `t` beside the digest as `NAME=value` elements of one header ' +
198208
'(Stripe-style `t=…,v1=…`). The same replay window as `x-objectstack-signature` applies.',

0 commit comments

Comments
 (0)