@oxy.so/contracts 4.16.0 → 4.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/dist/cjs/.tsbuildinfo +1 -1
  2. package/dist/cjs/accountEmail.js +12 -34
  3. package/dist/cjs/accountGraph.js +22 -320
  4. package/dist/cjs/agentKeys.js +11 -13
  5. package/dist/cjs/client/accountEmail.js +48 -0
  6. package/dist/cjs/client/accountGraph.js +323 -0
  7. package/dist/cjs/client/agentKeys.js +77 -0
  8. package/dist/cjs/client/check.js +466 -0
  9. package/dist/cjs/client/deviceBoot.js +22 -0
  10. package/dist/cjs/client/deviceDirectory.js +51 -0
  11. package/dist/cjs/client/deviceSession.js +63 -0
  12. package/dist/cjs/client/externalIdentity.js +19 -0
  13. package/dist/cjs/client/identity.js +45 -0
  14. package/dist/cjs/client/identityLink.js +55 -0
  15. package/dist/cjs/client/identityProof.js +109 -0
  16. package/dist/cjs/client/index.js +190 -0
  17. package/dist/cjs/client/organizations.js +114 -0
  18. package/dist/cjs/client/products.js +153 -0
  19. package/dist/cjs/client/recommendations.js +33 -0
  20. package/dist/cjs/client/reputation.js +41 -0
  21. package/dist/cjs/client/safety.js +15 -0
  22. package/dist/cjs/client/sessionStatus.js +23 -0
  23. package/dist/cjs/client/signIn.js +157 -0
  24. package/dist/cjs/client/userResponse.js +15 -0
  25. package/dist/cjs/client/username.js +173 -0
  26. package/dist/cjs/deviceSession.js +3 -16
  27. package/dist/cjs/identityLink.js +13 -34
  28. package/dist/cjs/identityProof.js +18 -106
  29. package/dist/cjs/organizations.js +21 -41
  30. package/dist/cjs/reputation.js +3 -34
  31. package/dist/cjs/signIn.js +33 -111
  32. package/dist/cjs/username.js +23 -158
  33. package/dist/esm/.tsbuildinfo +1 -1
  34. package/dist/esm/accountEmail.js +4 -32
  35. package/dist/esm/accountGraph.js +4 -309
  36. package/dist/esm/agentKeys.js +4 -10
  37. package/dist/esm/client/accountEmail.js +45 -0
  38. package/dist/esm/client/accountGraph.js +314 -0
  39. package/dist/esm/client/agentKeys.js +74 -0
  40. package/dist/esm/client/check.js +428 -0
  41. package/dist/esm/client/deviceBoot.js +19 -0
  42. package/dist/esm/client/deviceDirectory.js +48 -0
  43. package/dist/esm/client/deviceSession.js +60 -0
  44. package/dist/esm/client/externalIdentity.js +16 -0
  45. package/dist/esm/client/identity.js +42 -0
  46. package/dist/esm/client/identityLink.js +50 -0
  47. package/dist/esm/client/identityProof.js +104 -0
  48. package/dist/esm/client/index.js +37 -0
  49. package/dist/esm/client/organizations.js +111 -0
  50. package/dist/esm/client/products.js +150 -0
  51. package/dist/esm/client/recommendations.js +30 -0
  52. package/dist/esm/client/reputation.js +37 -0
  53. package/dist/esm/client/safety.js +12 -0
  54. package/dist/esm/client/sessionStatus.js +20 -0
  55. package/dist/esm/client/signIn.js +151 -0
  56. package/dist/esm/client/userResponse.js +12 -0
  57. package/dist/esm/client/username.js +167 -0
  58. package/dist/esm/deviceSession.js +1 -15
  59. package/dist/esm/identityLink.js +4 -27
  60. package/dist/esm/identityProof.js +4 -99
  61. package/dist/esm/organizations.js +4 -31
  62. package/dist/esm/reputation.js +1 -32
  63. package/dist/esm/signIn.js +4 -96
  64. package/dist/esm/username.js +4 -148
  65. package/dist/types/.tsbuildinfo +1 -1
  66. package/dist/types/accountEmail.d.ts +2 -34
  67. package/dist/types/accountGraph.d.ts +12 -208
  68. package/dist/types/agency.d.ts +24 -24
  69. package/dist/types/agentKeys.d.ts +8 -6
  70. package/dist/types/client/accountEmail.d.ts +44 -0
  71. package/dist/types/client/accountGraph.d.ts +203 -0
  72. package/dist/types/client/agentKeys.d.ts +113 -0
  73. package/dist/types/client/check.d.ts +184 -0
  74. package/dist/types/client/deviceBoot.d.ts +6 -0
  75. package/dist/types/client/deviceDirectory.d.ts +134 -0
  76. package/dist/types/client/deviceSession.d.ts +91 -0
  77. package/dist/types/client/externalIdentity.d.ts +14 -0
  78. package/dist/types/client/identity.d.ts +8 -0
  79. package/dist/types/client/identityLink.d.ts +21 -0
  80. package/dist/types/client/identityProof.d.ts +73 -0
  81. package/dist/types/client/index.d.ts +37 -0
  82. package/dist/types/client/organizations.d.ts +167 -0
  83. package/dist/types/client/products.d.ts +145 -0
  84. package/dist/types/client/recommendations.d.ts +27 -0
  85. package/dist/types/client/reputation.d.ts +28 -0
  86. package/dist/types/client/safety.d.ts +13 -0
  87. package/dist/types/client/sessionStatus.d.ts +19 -0
  88. package/dist/types/client/signIn.d.ts +107 -0
  89. package/dist/types/client/userResponse.d.ts +7 -0
  90. package/dist/types/client/username.d.ts +126 -0
  91. package/dist/types/deviceDirectory.d.ts +28 -28
  92. package/dist/types/deviceSession.d.ts +1 -12
  93. package/dist/types/externalIdentity.d.ts +11 -11
  94. package/dist/types/identityLink.d.ts +3 -11
  95. package/dist/types/identityProof.d.ts +2 -65
  96. package/dist/types/inference/decisions.d.ts +10 -10
  97. package/dist/types/inference/embeddings.d.ts +16 -16
  98. package/dist/types/inference/errors.d.ts +8 -8
  99. package/dist/types/inference/inbox.d.ts +8 -8
  100. package/dist/types/inference/privateAutoExecution.d.ts +6 -6
  101. package/dist/types/inference/realtime.d.ts +30 -30
  102. package/dist/types/inference/request.d.ts +28 -28
  103. package/dist/types/inference/streamEvents.d.ts +16 -16
  104. package/dist/types/inference/usage.d.ts +4 -4
  105. package/dist/types/oauth.d.ts +2 -2
  106. package/dist/types/organizations.d.ts +8 -10
  107. package/dist/types/products/billing.d.ts +3 -0
  108. package/dist/types/reputation.d.ts +1 -11
  109. package/dist/types/sessionStatus.d.ts +2 -2
  110. package/dist/types/signIn.d.ts +6 -89
  111. package/dist/types/userResponse.d.ts +20 -20
  112. package/dist/types/username.d.ts +1 -96
  113. package/package.json +20 -1
@@ -0,0 +1,314 @@
1
+ /**
2
+ * Account kinds and categories, without Zod. Schemas: `../accountGraph.ts`.
3
+ *
4
+ * Part of `@oxy.so/contracts/client`: never import `zod` here (see `./check.ts`).
5
+ */
6
+ /**
7
+ * The union is spelled out above and the array proves coverage BOTH ways
8
+ * (`satisfies` here, the `Gap` alias below) — the same shape this package's
9
+ * `ACCOUNT_CATEGORY_IDS` / `TRUST_TIERS` pairs use, and the one
10
+ * `db/schema/users.ts` mirrors to keep the `users_kind_check` CHECK honest.
11
+ *
12
+ * Deriving the union from the array instead would cost nothing here and be paid
13
+ * by consumers: `kind` travels into `@oxy.so/services` on every device-directory
14
+ * context (`deviceContextSchema.kind` → `DeviceContext` → the switcher rows),
15
+ * and an indexed-access type is materially more expensive to check there than a
16
+ * literal union.
17
+ */
18
+ export const ACCOUNT_KINDS = [
19
+ 'personal',
20
+ 'organization',
21
+ 'project',
22
+ 'bot',
23
+ 'channel',
24
+ ];
25
+ export const CHILD_ACCOUNT_KINDS = [
26
+ 'organization',
27
+ 'project',
28
+ 'bot',
29
+ 'channel',
30
+ ];
31
+ /**
32
+ * Whether an account of this kind may be the SUBJECT OF A DELEGATION — an
33
+ * application acting as it on some person's authority. `POST /internal/accounts/
34
+ * :id/service-switch` and the OAuth delegated subject both gate on this.
35
+ *
36
+ * It is NOT the question an account switcher asks. See
37
+ * {@link isOperatorSwitchTargetKind}, and the note below on why the difference
38
+ * is `bot`.
39
+ *
40
+ * Two kinds are refused, for opposite reasons:
41
+ *
42
+ * - `personal` is a human login, so assuming it would be impersonation.
43
+ * - `channel` is a CONTENT identity, not an operating one. A channel exists so
44
+ * that posts can be authored BY it; it is never a seat anybody occupies. Its
45
+ * operators act on it through their own membership, and an application
46
+ * publishes to it with its own credential. Refusing act-as is what makes
47
+ * "no login, ever" structural rather than incidental: no session can be
48
+ * minted whose subject is a channel, so no bearer exists that could add an
49
+ * auth method to one (every auth-method write resolves its target from the
50
+ * authenticated subject, never from a parameter).
51
+ *
52
+ * Consumers must gate on this predicate rather than testing `kind === 'personal'`,
53
+ * which silently admits every kind added after it was written.
54
+ *
55
+ * Being act-as-eligible is NOT being without an identity of one's own. A bot is
56
+ * act-as-eligible AND its own actor (`accountKindActorNature` → `'agent'` in
57
+ * `accountSubject.ts`): an application acting as it on a person's authority
58
+ * records that person as the actor, and the bot acting with nobody operating it
59
+ * records the bot. Neither ever records the bot's owner in the bot's place.
60
+ */
61
+ export function isDelegatedActAsEligibleKind(kind) {
62
+ return kind === 'organization' || kind === 'project' || kind === 'bot';
63
+ }
64
+ /**
65
+ * Whether a PERSON may switch into an account of this kind — become it, in an
66
+ * account switcher, for the rest of their session.
67
+ *
68
+ * ## Why this is not the same question as {@link isDelegatedActAsEligibleKind}
69
+ *
70
+ * The two differ on exactly one kind, `bot`, and that difference is the whole
71
+ * reason both exist.
72
+ *
73
+ * **A bot is not something you become. It is somebody of its own.** It is an
74
+ * agent's identity, with its own resources, roles, plan and balance, and it is
75
+ * the actor of what it does unoperated. A person may still act AS it on their
76
+ * own authority — that is delegation, recorded with the person as actor, and it
77
+ * is what {@link isDelegatedActAsEligibleKind} admits it for. What a person
78
+ * never does is occupy its seat. This is a refusal of a SEAT, not a capability
79
+ * restriction: nothing a bot may do depends on this predicate.
80
+ *
81
+ * Handing a person the bot's seat instead inverts that. It puts a human inside
82
+ * the identity that exists to act without one, and it does so on the human's own
83
+ * device, next to their personal login — which is precisely what happened: a
84
+ * `bot` account held a live session on a person's device, offered to them by a
85
+ * switcher that had asked the delegation question by mistake.
86
+ *
87
+ * `channel` is refused here as well, for the reason set out above, and
88
+ * `personal` because assuming somebody else's login is impersonation.
89
+ *
90
+ * ## This is the narrower predicate, deliberately
91
+ *
92
+ * Everything a person may become, a service may also act as; the reverse does
93
+ * not hold. A caller that is unsure which question it is asking wants THIS one:
94
+ * being wrong here withholds an affordance, while being wrong the other way
95
+ * hands out a seat.
96
+ */
97
+ export function isOperatorSwitchTargetKind(kind) {
98
+ return kind === 'organization' || kind === 'project';
99
+ }
100
+ /**
101
+ * Narrow an unknown value to an {@link AccountKind}.
102
+ *
103
+ * The user-DTO serializers read from structurally-permissive `unknown` sources
104
+ * (a Drizzle row, a raw document, an already-formatted object), so each one
105
+ * would otherwise hand-roll this check and they would drift on what counts.
106
+ */
107
+ export function isAccountKind(value) {
108
+ return typeof value === 'string' && ACCOUNT_KINDS.includes(value);
109
+ }
110
+ // ===========================================================================
111
+ // Account categories
112
+ //
113
+ // Four rules govern this taxonomy. Each one is here because the obvious
114
+ // alternative fails silently rather than loudly.
115
+ //
116
+ // 1. AN ID IS AN OPAQUE, IMMUTABLE SLUG — the LABEL is not stored anywhere.
117
+ // Every value below is an identifier that no rename may ever change. The
118
+ // human-readable label lives in each client's own translation catalogue,
119
+ // keyed by the id. Re-labelling `agency` from "Real estate agency" to
120
+ // "Agency" is therefore a one-line locale edit that touches no row; moving
121
+ // the label into the column or the DTO would make the same edit a data
122
+ // migration, and would pin every reader to the language of whoever chose it.
123
+ //
124
+ // 2. THE PRIMARY CATEGORY IS THE FIRST ELEMENT of an ordered list. Not a
125
+ // separate flag, and not a second field: a flag admits two primaries and
126
+ // admits none, and ordering makes both unrepresentable. The cost is that
127
+ // ORDER IS DATA — anything that re-serializes, sorts or de-duplicates this
128
+ // list can change which category is primary without erroring, so no layer
129
+ // between the column and the client may reorder it.
130
+ //
131
+ // 3. THE VOCABULARY IS APPEND-ONLY. `ACCOUNT_CATEGORY_IDS` may gain ids and may
132
+ // never lose one, because rows already carry the ids it holds. Withdrawing a
133
+ // category means listing it in {@link RETIRED_ACCOUNT_CATEGORY_IDS}, which
134
+ // removes it from the picker while leaving it readable and re-writable. The
135
+ // database enforces the same asymmetry: its CHECK is re-evaluated on EVERY
136
+ // update to a row, so narrowing the allowed set makes an unrelated write —
137
+ // saving a bio — fail on any account that had picked the withdrawn value.
138
+ // Measured on a real Postgres, `NOT VALID` included; it does not help.
139
+ //
140
+ // 4. THE SET IS CLOSED. An id nobody can validate is an id no client can render:
141
+ // the label comes from a translation key derived from the id, so an invented
142
+ // value paints as a blank or a raw slug in every app at once. Closing it also
143
+ // costs nothing that rule 3 does not already charge — adding a category needs
144
+ // a migration to widen the CHECK whether or not the enum exists, so an open
145
+ // list would buy back no work, only the validation.
146
+ // ===========================================================================
147
+ /**
148
+ * Every account category, by stable id.
149
+ *
150
+ * Grouped by comment for readability only; the storage, the wire and the picker
151
+ * all treat this as one flat list. `other` is the escape hatch for an account
152
+ * that fits nothing here.
153
+ *
154
+ * TO ADD ONE: append an id (lowercase ASCII, `snake_case`) here, publish
155
+ * `@oxy.so/contracts`, then ship a migration that widens
156
+ * `users_account_categories_check` — never edit an existing migration — and add
157
+ * an `accounts.accountCategory.<id>` label to each client's locales.
158
+ *
159
+ * TO WITHDRAW ONE: leave the id here and add it to
160
+ * {@link RETIRED_ACCOUNT_CATEGORY_IDS}. See rule 3 above.
161
+ */
162
+ export const ACCOUNT_CATEGORY_IDS = [
163
+ // ---- media & public information -----------------------------------------
164
+ 'news',
165
+ 'politics',
166
+ // ---- business & economy --------------------------------------------------
167
+ 'business',
168
+ 'startup',
169
+ 'finance',
170
+ 'crypto',
171
+ 'marketplace',
172
+ 'retail',
173
+ // The four ids the single-valued `organizationCategory` field used to hold,
174
+ // carried forward VERBATIM. Their labels may be rewritten freely; their ids
175
+ // may not, because live rows hold them.
176
+ 'real_estate',
177
+ 'agency',
178
+ 'landlord',
179
+ 'cooperative',
180
+ 'architecture',
181
+ // ---- technology ----------------------------------------------------------
182
+ 'technology',
183
+ 'software',
184
+ 'ai',
185
+ 'security',
186
+ 'automation',
187
+ // ---- knowledge -----------------------------------------------------------
188
+ 'science',
189
+ 'education',
190
+ 'books',
191
+ // ---- health --------------------------------------------------------------
192
+ 'health',
193
+ 'fitness',
194
+ // ---- sport & play --------------------------------------------------------
195
+ 'sports',
196
+ 'gaming',
197
+ // ---- culture & entertainment ---------------------------------------------
198
+ //
199
+ // There is deliberately NO generic `entertainment` here, and re-adding one is
200
+ // a regression rather than a gap. It is the only id this list ever carried
201
+ // that was dominated by its own specifics — `film`, `music`, `gaming` and
202
+ // `comedy` all exist — and a generic drawer sitting beside its four
203
+ // concretions collects the lazy pick, which degrades the data for all four at
204
+ // once: the accounts that would have said `film` say `entertainment` instead,
205
+ // and `film` stops meaning what it meant.
206
+ //
207
+ // The other overlaps in this vocabulary are NOT the same case and must not be
208
+ // merged on this reasoning: `sports`/`fitness`, `art`/`photography`,
209
+ // `business`/`startup`, `finance`/`crypto`, `home_garden`/`diy` and
210
+ // `technology`/`software`/`security` are genuinely different audiences, and
211
+ // with a cap of four the granularity is cheap.
212
+ 'music',
213
+ 'film',
214
+ 'podcast',
215
+ 'art',
216
+ 'photography',
217
+ 'comedy',
218
+ // ---- everyday life -------------------------------------------------------
219
+ 'food',
220
+ 'travel',
221
+ 'fashion',
222
+ 'home_garden',
223
+ 'diy',
224
+ 'automotive',
225
+ 'animals',
226
+ 'family',
227
+ // ---- society -------------------------------------------------------------
228
+ 'nonprofit',
229
+ 'government',
230
+ 'community',
231
+ 'activism',
232
+ 'environment',
233
+ 'religion',
234
+ // ---- fallback ------------------------------------------------------------
235
+ 'other',
236
+ ];
237
+ /**
238
+ * Ids withdrawn from the picker. Empty today.
239
+ *
240
+ * A withdrawn id keeps working everywhere it is already stored: it validates,
241
+ * it survives a round-trip save, it still renders from its label key, and it
242
+ * stays PRIMARY if it was primary. Nothing rewrites a stored list — a read-time
243
+ * or migration-time demotion would silently replace a choice its owner made,
244
+ * which is precisely what stable ids exist to prevent. The owner drops it on
245
+ * their next edit; until then it is honoured.
246
+ *
247
+ * What withdrawal changes is only this: the id leaves
248
+ * {@link SELECTABLE_ACCOUNT_CATEGORY_IDS}, so no picker offers it, and
249
+ * {@link newlyAddedRetiredCategories} refuses to let a write ADD it to an
250
+ * account that did not already have it.
251
+ */
252
+ export const RETIRED_ACCOUNT_CATEGORY_IDS = [];
253
+ /** Whether a category may still be OFFERED. A stored one is readable either way. */
254
+ export function isSelectableAccountCategoryId(id) {
255
+ return !RETIRED_ACCOUNT_CATEGORY_IDS.includes(id);
256
+ }
257
+ /** The ids a picker may offer, in declaration order. */
258
+ export const SELECTABLE_ACCOUNT_CATEGORY_IDS = ACCOUNT_CATEGORY_IDS.filter(isSelectableAccountCategoryId);
259
+ /**
260
+ * Which of `next` are withdrawn ids the account did not already carry — i.e.
261
+ * the ones a write must be refused for.
262
+ *
263
+ * `retired` is a parameter rather than a module read so the rule can be
264
+ * exercised against a non-empty set while the production one is empty; a test
265
+ * over `RETIRED_ACCOUNT_CATEGORY_IDS` alone would pass vacuously today and stay
266
+ * passing if the rule were deleted.
267
+ */
268
+ export function newlyAddedRetiredCategories(next, previous, retired) {
269
+ return next.filter((id) => retired.includes(id) && !previous.includes(id));
270
+ }
271
+ /**
272
+ * How many categories one account may carry.
273
+ *
274
+ * Four, not "as many as you like". Three reasons, in the order they bind:
275
+ *
276
+ * - The primary has to MEAN something. At ten categories the first element
277
+ * reads as a sort artifact rather than a choice, and rule 2 above is the
278
+ * entire mechanism by which a primary exists.
279
+ * - The profile RENDERS them as a row of chips; four labels of this length is
280
+ * what fits a phone-width profile header before the row wraps or truncates.
281
+ * - Four is enough to place a genuinely compound account without a tag cloud:
282
+ * a housing cooperative that is also a non-profit serving a local community
283
+ * spends `cooperative`, `nonprofit`, `community`, `real_estate` — and is the
284
+ * most compound real example in the ecosystem.
285
+ *
286
+ * One constant, read by the wire schema, the database CHECK and the picker, so
287
+ * changing it is one edit plus a migration.
288
+ */
289
+ export const MAX_ACCOUNT_CATEGORIES = 4;
290
+ /**
291
+ * Kinds that may carry categories: every kind EXCEPT `personal`.
292
+ *
293
+ * A person has interests, not a sector — and their interests are not a
294
+ * classification anybody else gets to read off their profile. Spelled out
295
+ * positively, like {@link isDelegatedActAsEligibleKind} and for the same reason: a `kind
296
+ * !== 'personal'` test silently admits every kind invented after it was
297
+ * written, whereas this list forces whoever adds one to decide.
298
+ */
299
+ export const ACCOUNT_CATEGORY_KINDS = [
300
+ 'organization',
301
+ 'project',
302
+ 'bot',
303
+ 'channel',
304
+ ];
305
+ /**
306
+ * Whether an account of this kind may carry categories.
307
+ *
308
+ * The API refuses the write and the `users_account_categories_kind_check`
309
+ * constraint makes it unrepresentable; both derive from
310
+ * {@link ACCOUNT_CATEGORY_KINDS}, so they cannot disagree.
311
+ */
312
+ export function kindAcceptsAccountCategories(kind) {
313
+ return ACCOUNT_CATEGORY_KINDS.includes(kind ?? '');
314
+ }
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Agent-key constants and checks, without Zod. Schemas: `../agentKeys.ts`.
3
+ *
4
+ * Part of `@oxy.so/contracts/client`: never import `zod` here (see `./check.ts`).
5
+ */
6
+ import { array, boolean, datetime, discriminatedUnion, exact, int, literal, maxLength, minLength, nullable, number, oneOf, optional, pattern, positive, strictObject, string, trim, } from './check.js';
7
+ import { reauthProofCheck } from './signIn.js';
8
+ export const AGENT_PROOF_AUDIENCE = 'oxy-api/agent';
9
+ export const AGENT_PROOF_TTL_MS = 60000;
10
+ export const AGENT_PROOF_ACTIONS = [
11
+ 'agent_signin',
12
+ 'agent_enroll',
13
+ 'agent_rotate',
14
+ 'agent_recover',
15
+ 'agent_governance',
16
+ ];
17
+ export const ACCOUNT_AUTH_METHODS = ['identity', 'agent_key'];
18
+ /* -------------------------------------------------------------------------- */
19
+ /* Checks */
20
+ /* -------------------------------------------------------------------------- */
21
+ const hex64 = string(pattern(/^[0-9a-f]{64}$/));
22
+ const hexSignature = string(pattern(/^[0-9a-f]+$/i), maxLength(160));
23
+ const timestamp = number(int, positive);
24
+ const publicKey = string(trim, minLength(1), maxLength(130));
25
+ const label = string(trim, minLength(1), maxLength(120));
26
+ export const agentProofClaimsCheck = exact()(strictObject({
27
+ version: literal(1),
28
+ audience: literal(AGENT_PROOF_AUDIENCE),
29
+ action: oneOf(AGENT_PROOF_ACTIONS),
30
+ accountId: string(minLength(1)),
31
+ actorId: string(minLength(1)),
32
+ authMethodId: nullable(string()),
33
+ publicKey: string(minLength(1)),
34
+ payloadDigest: hex64,
35
+ challenge: hex64,
36
+ expiresAt: number(int, positive),
37
+ }));
38
+ export const agentChallengeRequestCheck = exact()(strictObject({ publicKey }));
39
+ export const agentVerifyRequestCheck = exact()(strictObject({ challenge: hex64, signature: hexSignature, timestamp, publicKey }));
40
+ export const agentKeyOperationCheck = exact()(discriminatedUnion('operation', {
41
+ enroll: strictObject({ operation: literal('enroll'), publicKey, label }),
42
+ recover: strictObject({ operation: literal('recover'), publicKey, label }),
43
+ rotate: strictObject({
44
+ operation: literal('rotate'),
45
+ publicKey,
46
+ label,
47
+ retireCurrent: optional(boolean),
48
+ }),
49
+ revoke: strictObject({ operation: literal('revoke'), methodId: string(minLength(1)) }),
50
+ }));
51
+ export const executeAgentKeyOperationCheck = exact()(strictObject({
52
+ operation: agentKeyOperationCheck,
53
+ proof: strictObject({
54
+ challenge: hex64,
55
+ timestamp,
56
+ keySignature: optional(hexSignature),
57
+ governorSignature: optional(hexSignature),
58
+ reauth: optional(reauthProofCheck),
59
+ }),
60
+ }));
61
+ export const agentKeyOperationChallengeCheck = exact()(strictObject({ claims: agentProofClaimsCheck, governorPublicKey: nullable(string()) }));
62
+ export const agentKeyOperationResultCheck = exact()(strictObject({ methodId: nullable(string()), revokedMethodIds: array(string()) }));
63
+ export const agentKeyListResponseCheck = exact()(strictObject({
64
+ keys: array(strictObject({
65
+ id: string(),
66
+ publicKey: string(),
67
+ label: string(),
68
+ enrolledByUserId: nullable(string()),
69
+ enrollmentMethod: oneOf(['governor', 'rotation', 'recovery']),
70
+ linkedAt: string(datetime),
71
+ lastUsedAt: nullable(string(datetime)),
72
+ revokedAt: nullable(string(datetime)),
73
+ })),
74
+ }));