|
| 1 | +--- |
| 2 | +title: Api Trigger Signature — Automation Protocol |
| 3 | +navTitle: Api Trigger Signature |
| 4 | +description: "An inbound api hook's verifier for a THIRD-PARTY sender, declared. Reference for ApiTriggerBodySignature and 2 more: every property with its type and default." |
| 5 | +--- |
| 6 | + |
| 7 | +{/* ⚠️ AUTO-GENERATED — DO NOT EDIT. Run build-docs.ts to regenerate. Hand-written docs live in the module folders under content/docs/. */} |
| 8 | + |
| 9 | +An inbound `api` hook's verifier for a THIRD-PARTY sender, declared. |
| 10 | + |
| 11 | +An `api` flow's start node arms an inbound hook (ADR-0041 Tier 1, whose |
| 12 | +acceptance criteria name "HMAC signature verification (GitHub/Stripe style) |
| 13 | +and a constant-time compare"). By default the hook admits a post only by |
| 14 | +ObjectStack's own `x-objectstack-signature`: the timestamped HMAC-SHA256 of |
| 15 | +`<t>.<raw body>` under the hook's secret. A vendor that signs its callbacks |
| 16 | +its own way could not be admitted at all, whatever key it held: DocuSign |
| 17 | +Connect's `X-DocuSign-Signature-1` (base64 HMAC-SHA256 of the raw body), a |
| 18 | +Stripe-style `t=…,v1=…` header (hex HMAC-SHA256 of `<t>.<raw body>`), a |
| 19 | +GitHub-style `sha256=<hex>`. `config.signature` declares how such a sender |
| 20 | +signs: which header carries the digest, which HMAC, which encoding, and what |
| 21 | +is signed. |
| 22 | + |
| 23 | +**The key is `config.secretRef`.** The same reference an ObjectStack-signed |
| 24 | +hook names, resolved the same way at every post: one key per hook, by name |
| 25 | +only. A vendor key is ⛔ never inline: a verifier beside a literal |
| 26 | +`config.secret` is refused, and so is one with no `secretRef` at all. |
| 27 | + |
| 28 | +**One verifier per hook.** A declared `signature` REPLACES the |
| 29 | +`x-objectstack-signature` check for its hook. The hook then verifies the |
| 30 | +declared scheme and nothing else: it does not stack with the platform's own |
| 31 | +check, and it is not optional (a post without the declared header is refused |
| 32 | +like a post with a bad one). A start node with no `signature` is verified |
| 33 | +exactly as it was before this key. `apiTriggerVerifierOf` is the one |
| 34 | +reader that decides which verifier a hook has, and it decides on the key's |
| 35 | +PRESENCE: a `signature` that is present and unusable is never read as |
| 36 | +absent, so it can never fall back to the platform's check. |
| 37 | + |
| 38 | +What the implementer owes (the constant-time compare, the replay window for |
| 39 | +a scheme that signs a timestamp and the absence of one for a scheme that |
| 40 | +does not, the one `401 INVALID_SIGNATURE` for every failure) is stated in |
| 41 | +`contracts/trigger-api-service.ts`, beside the platform's own verifier, |
| 42 | +because the member that verifies is declared there. |
| 43 | + |
| 44 | +Refusals, each anchored on the start node's `config.signature`: |
| 45 | + |
| 46 | + - a shape the schema refuses (`ApiTriggerSignatureSchema`): an |
| 47 | + unknown algorithm or encoding, a `signs` that is neither form, a |
| 48 | + `timestamp.body` scheme that names no timestamp source, a body-only |
| 49 | + scheme that names one, an undeclared key; |
| 50 | + - a `timestamp.body` scheme whose timestamp and digest are the same |
| 51 | + element of the header; |
| 52 | + - a verifier with no key reference (`config.secretRef` absent); |
| 53 | + - a verifier beside a literal `config.secret`: an inline key, and a second |
| 54 | + source for the one key the hook has; |
| 55 | + - a verifier on a flow that binds no inbound `api` trigger: nothing would |
| 56 | + ever read it. |
| 57 | + |
| 58 | +This is the vocabulary ADR-0138 D7 left to a follow-up (F1: an HMAC, a |
| 59 | +timestamp, a replay window), placed on the signed inbound-hook channel |
| 60 | +rather than on `ApiEndpointSchema`. |
| 61 | + |
| 62 | +<Callout type="info"> |
| 63 | +**Source:** `packages/spec/src/automation/api-trigger-signature.zod.ts` |
| 64 | +</Callout> |
| 65 | + |
| 66 | +## TypeScript Usage |
| 67 | + |
| 68 | +```typescript |
| 69 | +import { ApiTriggerBodySignatureSchema, ApiTriggerSignatureSchema, ApiTriggerTimestampedSignatureSchema } from '@objectstack/spec/automation'; |
| 70 | +import type { ApiTriggerBodySignature, ApiTriggerSignature, ApiTriggerTimestampedSignature } from '@objectstack/spec/automation'; |
| 71 | + |
| 72 | +// Validate data |
| 73 | +const result = ApiTriggerBodySignatureSchema.parse(data); |
| 74 | +``` |
| 75 | + |
| 76 | +--- |
| 77 | + |
| 78 | +## ApiTriggerBodySignature |
| 79 | + |
| 80 | +A sender that signs the raw body alone (DocuSign Connect, a GitHub-style `sha256=` sender): the header value, after `prefix`, is the one digest. No replay window applies. |
| 81 | + |
| 82 | +### Properties |
| 83 | + |
| 84 | +| Property | Type | Required | Description | |
| 85 | +| :--- | :--- | :--- | :--- | |
| 86 | +| **signs** | `'body'` | ✅ | The sender signs the raw body alone. No replay window applies. | |
| 87 | +| **header** | `string` | ✅ | The HTTP header the sender puts its signature in (`X-DocuSign-Signature-1`, `Stripe-Signature`), matched without regard to case. The hook reads this header and never `x-objectstack-signature`. | |
| 88 | +| **algorithm** | `Enum<'hmac-sha256'>` | ✅ | The MAC the sender computes under the key `config.secretRef` names. `hmac-sha256` is the only one. | |
| 89 | +| **encoding** | `Enum<'hex' \| 'base64'>` | ✅ | How the sender writes the digest in the header: `hex` or `base64` (the RFC 4648 standard alphabet). The digest is decoded and compared as the 32 bytes of the HMAC. | |
| 90 | +| **prefix** | `string` | optional | Literal text the sender writes before the digest in the header value (`sha256=` for a GitHub-style sender), checked and removed before decoding. Absent: the whole value is the digest. | |
| 91 | + |
| 92 | + |
| 93 | +--- |
| 94 | + |
| 95 | +## ApiTriggerSignature |
| 96 | + |
| 97 | +How a third-party sender signs its posts to this inbound hook, verified under the key `config.secretRef` names. Declared, it REPLACES the `x-objectstack-signature` check for this hook: the one verifier, never optional. A trigger that does not implement it refuses every post 401, never admits one unverified. |
| 98 | + |
| 99 | +### Union Options |
| 100 | + |
| 101 | +This schema accepts one of the following structures: |
| 102 | + |
| 103 | +#### Option 1 |
| 104 | + |
| 105 | +A sender that signs the raw body alone (DocuSign Connect, a GitHub-style `sha256=` sender): the header value, after `prefix`, is the one digest. No replay window applies. |
| 106 | + |
| 107 | +### Properties |
| 108 | + |
| 109 | +| Property | Type | Required | Description | |
| 110 | +| :--- | :--- | :--- | :--- | |
| 111 | +| **signs** | `'body'` | ✅ | The sender signs the raw body alone. No replay window applies. | |
| 112 | +| **header** | `string` | ✅ | The HTTP header the sender puts its signature in (`X-DocuSign-Signature-1`, `Stripe-Signature`), matched without regard to case. The hook reads this header and never `x-objectstack-signature`. | |
| 113 | +| **algorithm** | `Enum<'hmac-sha256'>` | ✅ | The MAC the sender computes under the key `config.secretRef` names. `hmac-sha256` is the only one. | |
| 114 | +| **encoding** | `Enum<'hex' \| 'base64'>` | ✅ | How the sender writes the digest in the header: `hex` or `base64` (the RFC 4648 standard alphabet). The digest is decoded and compared as the 32 bytes of the HMAC. | |
| 115 | +| **prefix** | `string` | optional | Literal text the sender writes before the digest in the header value (`sha256=` for a GitHub-style sender), checked and removed before decoding. Absent: the whole value is the digest. | |
| 116 | + |
| 117 | +--- |
| 118 | + |
| 119 | +#### Option 2 |
| 120 | + |
| 121 | +A sender that signs `<t>.<raw body>` and writes `t` beside the digest as `NAME=value` elements of one header (Stripe-style `t=…,v1=…`). The same replay window as `x-objectstack-signature` applies. |
| 122 | + |
| 123 | +### Properties |
| 124 | + |
| 125 | +| Property | Type | Required | Description | |
| 126 | +| :--- | :--- | :--- | :--- | |
| 127 | +| **signs** | `'timestamp.body'` | ✅ | The sender signs `<t>.<raw body>`, `t` read from `timestampElement`. The replay window applies. | |
| 128 | +| **header** | `string` | ✅ | The HTTP header the sender puts its signature in (`X-DocuSign-Signature-1`, `Stripe-Signature`), matched without regard to case. The hook reads this header and never `x-objectstack-signature`. | |
| 129 | +| **algorithm** | `Enum<'hmac-sha256'>` | ✅ | The MAC the sender computes under the key `config.secretRef` names. `hmac-sha256` is the only one. | |
| 130 | +| **encoding** | `Enum<'hex' \| 'base64'>` | ✅ | How the sender writes the digest in the header: `hex` or `base64` (the RFC 4648 standard alphabet). The digest is decoded and compared as the 32 bytes of the HMAC. | |
| 131 | +| **timestampElement** | `string` | ✅ | Where the timestamp comes from: the NAME of the header element `NAME=<unix seconds>` (`t`). Its value, exactly as received, is the `<t>` of the signed `<t>.<raw body>`. | |
| 132 | +| **digestElement** | `string` | ✅ | The NAME of the header element that carries the digest (`v1`). A sender may send it more than once while it rolls its key; the post verifies when one of them matches. | |
| 133 | + |
| 134 | +--- |
| 135 | + |
| 136 | + |
| 137 | +--- |
| 138 | + |
| 139 | +## ApiTriggerTimestampedSignature |
| 140 | + |
| 141 | +A sender that signs `<t>.<raw body>` and writes `t` beside the digest as `NAME=value` elements of one header (Stripe-style `t=…,v1=…`). The same replay window as `x-objectstack-signature` applies. |
| 142 | + |
| 143 | +### Properties |
| 144 | + |
| 145 | +| Property | Type | Required | Description | |
| 146 | +| :--- | :--- | :--- | :--- | |
| 147 | +| **signs** | `'timestamp.body'` | ✅ | The sender signs `<t>.<raw body>`, `t` read from `timestampElement`. The replay window applies. | |
| 148 | +| **header** | `string` | ✅ | The HTTP header the sender puts its signature in (`X-DocuSign-Signature-1`, `Stripe-Signature`), matched without regard to case. The hook reads this header and never `x-objectstack-signature`. | |
| 149 | +| **algorithm** | `Enum<'hmac-sha256'>` | ✅ | The MAC the sender computes under the key `config.secretRef` names. `hmac-sha256` is the only one. | |
| 150 | +| **encoding** | `Enum<'hex' \| 'base64'>` | ✅ | How the sender writes the digest in the header: `hex` or `base64` (the RFC 4648 standard alphabet). The digest is decoded and compared as the 32 bytes of the HMAC. | |
| 151 | +| **timestampElement** | `string` | ✅ | Where the timestamp comes from: the NAME of the header element `NAME=<unix seconds>` (`t`). Its value, exactly as received, is the `<t>` of the signed `<t>.<raw body>`. | |
| 152 | +| **digestElement** | `string` | ✅ | The NAME of the header element that carries the digest (`v1`). A sender may send it more than once while it rolls its key; the post verifies when one of them matches. | |
| 153 | + |
| 154 | + |
| 155 | +--- |
| 156 | + |
0 commit comments