@oxy.so/contracts 1.0.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 (147) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +16 -0
  3. package/dist/cjs/.tsbuildinfo +1 -0
  4. package/dist/cjs/accountGraph.js +489 -0
  5. package/dist/cjs/agency.js +439 -0
  6. package/dist/cjs/browserHub.js +215 -0
  7. package/dist/cjs/civic.js +163 -0
  8. package/dist/cjs/commonsSignIn.js +59 -0
  9. package/dist/cjs/deviceBoot.js +50 -0
  10. package/dist/cjs/deviceDirectory.js +189 -0
  11. package/dist/cjs/devicePairing.js +138 -0
  12. package/dist/cjs/deviceSession.js +164 -0
  13. package/dist/cjs/emailAgentContext.js +32 -0
  14. package/dist/cjs/followGraph.js +28 -0
  15. package/dist/cjs/identity.js +258 -0
  16. package/dist/cjs/inboxPush.js +24 -0
  17. package/dist/cjs/index.js +618 -0
  18. package/dist/cjs/inference/accountBilling.js +334 -0
  19. package/dist/cjs/inference/aliaModelRelease.js +262 -0
  20. package/dist/cjs/inference/attribution.js +106 -0
  21. package/dist/cjs/inference/catalogue.js +487 -0
  22. package/dist/cjs/inference/entitlement.js +217 -0
  23. package/dist/cjs/inference/errors.js +309 -0
  24. package/dist/cjs/inference/identifiers.js +224 -0
  25. package/dist/cjs/inference/inbox.js +105 -0
  26. package/dist/cjs/inference/modelDocumentation.js +433 -0
  27. package/dist/cjs/inference/money.js +188 -0
  28. package/dist/cjs/inference/priceVersion.js +110 -0
  29. package/dist/cjs/inference/providerConnection.js +455 -0
  30. package/dist/cjs/inference/request.js +477 -0
  31. package/dist/cjs/inference/routingPolicy.js +318 -0
  32. package/dist/cjs/inference/streamEvents.js +258 -0
  33. package/dist/cjs/inference/usage.js +329 -0
  34. package/dist/cjs/inference/version.js +105 -0
  35. package/dist/cjs/keyRecovery.js +91 -0
  36. package/dist/cjs/keyRotation.js +75 -0
  37. package/dist/cjs/links.js +68 -0
  38. package/dist/cjs/moderationReputation.js +298 -0
  39. package/dist/cjs/oauth.js +66 -0
  40. package/dist/cjs/oxyRecordTypes.js +71 -0
  41. package/dist/cjs/protocol.js +53 -0
  42. package/dist/cjs/recommendations.js +168 -0
  43. package/dist/cjs/reputation.js +297 -0
  44. package/dist/cjs/sessionStatus.js +121 -0
  45. package/dist/cjs/transparency.js +89 -0
  46. package/dist/cjs/updates.js +252 -0
  47. package/dist/cjs/userInvalidation.js +89 -0
  48. package/dist/cjs/userResponse.js +245 -0
  49. package/dist/cjs/username.js +290 -0
  50. package/dist/cjs/webauthn.js +71 -0
  51. package/dist/esm/.tsbuildinfo +1 -0
  52. package/dist/esm/accountGraph.js +480 -0
  53. package/dist/esm/agency.js +436 -0
  54. package/dist/esm/browserHub.js +212 -0
  55. package/dist/esm/civic.js +160 -0
  56. package/dist/esm/commonsSignIn.js +56 -0
  57. package/dist/esm/deviceBoot.js +47 -0
  58. package/dist/esm/deviceDirectory.js +186 -0
  59. package/dist/esm/devicePairing.js +135 -0
  60. package/dist/esm/deviceSession.js +161 -0
  61. package/dist/esm/emailAgentContext.js +29 -0
  62. package/dist/esm/followGraph.js +27 -0
  63. package/dist/esm/identity.js +255 -0
  64. package/dist/esm/inboxPush.js +21 -0
  65. package/dist/esm/index.js +172 -0
  66. package/dist/esm/inference/accountBilling.js +331 -0
  67. package/dist/esm/inference/aliaModelRelease.js +259 -0
  68. package/dist/esm/inference/attribution.js +103 -0
  69. package/dist/esm/inference/catalogue.js +484 -0
  70. package/dist/esm/inference/entitlement.js +214 -0
  71. package/dist/esm/inference/errors.js +306 -0
  72. package/dist/esm/inference/identifiers.js +221 -0
  73. package/dist/esm/inference/inbox.js +102 -0
  74. package/dist/esm/inference/modelDocumentation.js +430 -0
  75. package/dist/esm/inference/money.js +185 -0
  76. package/dist/esm/inference/priceVersion.js +107 -0
  77. package/dist/esm/inference/providerConnection.js +452 -0
  78. package/dist/esm/inference/request.js +474 -0
  79. package/dist/esm/inference/routingPolicy.js +315 -0
  80. package/dist/esm/inference/streamEvents.js +255 -0
  81. package/dist/esm/inference/usage.js +326 -0
  82. package/dist/esm/inference/version.js +102 -0
  83. package/dist/esm/keyRecovery.js +88 -0
  84. package/dist/esm/keyRotation.js +72 -0
  85. package/dist/esm/links.js +65 -0
  86. package/dist/esm/moderationReputation.js +295 -0
  87. package/dist/esm/oauth.js +63 -0
  88. package/dist/esm/oxyRecordTypes.js +68 -0
  89. package/dist/esm/protocol.js +50 -0
  90. package/dist/esm/recommendations.js +165 -0
  91. package/dist/esm/reputation.js +293 -0
  92. package/dist/esm/sessionStatus.js +118 -0
  93. package/dist/esm/transparency.js +86 -0
  94. package/dist/esm/updates.js +249 -0
  95. package/dist/esm/userInvalidation.js +85 -0
  96. package/dist/esm/userResponse.js +240 -0
  97. package/dist/esm/username.js +283 -0
  98. package/dist/esm/webauthn.js +68 -0
  99. package/dist/types/.tsbuildinfo +1 -0
  100. package/dist/types/accountGraph.d.ts +378 -0
  101. package/dist/types/agency.d.ts +2162 -0
  102. package/dist/types/browserHub.d.ts +856 -0
  103. package/dist/types/civic.d.ts +338 -0
  104. package/dist/types/commonsSignIn.d.ts +58 -0
  105. package/dist/types/deviceBoot.d.ts +74 -0
  106. package/dist/types/deviceDirectory.d.ts +1317 -0
  107. package/dist/types/devicePairing.d.ts +130 -0
  108. package/dist/types/deviceSession.d.ts +411 -0
  109. package/dist/types/emailAgentContext.d.ts +248 -0
  110. package/dist/types/followGraph.d.ts +150 -0
  111. package/dist/types/identity.d.ts +402 -0
  112. package/dist/types/inboxPush.d.ts +30 -0
  113. package/dist/types/index.d.ts +100 -0
  114. package/dist/types/inference/accountBilling.d.ts +738 -0
  115. package/dist/types/inference/aliaModelRelease.d.ts +609 -0
  116. package/dist/types/inference/attribution.d.ts +176 -0
  117. package/dist/types/inference/catalogue.d.ts +1618 -0
  118. package/dist/types/inference/entitlement.d.ts +519 -0
  119. package/dist/types/inference/errors.d.ts +242 -0
  120. package/dist/types/inference/identifiers.d.ts +182 -0
  121. package/dist/types/inference/inbox.d.ts +374 -0
  122. package/dist/types/inference/modelDocumentation.d.ts +1603 -0
  123. package/dist/types/inference/money.d.ts +185 -0
  124. package/dist/types/inference/priceVersion.d.ts +182 -0
  125. package/dist/types/inference/providerConnection.d.ts +968 -0
  126. package/dist/types/inference/request.d.ts +2800 -0
  127. package/dist/types/inference/routingPolicy.d.ts +616 -0
  128. package/dist/types/inference/streamEvents.d.ts +950 -0
  129. package/dist/types/inference/usage.d.ts +1164 -0
  130. package/dist/types/inference/version.d.ts +102 -0
  131. package/dist/types/keyRecovery.d.ts +138 -0
  132. package/dist/types/keyRotation.d.ts +103 -0
  133. package/dist/types/links.d.ts +96 -0
  134. package/dist/types/moderationReputation.d.ts +487 -0
  135. package/dist/types/oauth.d.ts +86 -0
  136. package/dist/types/oxyRecordTypes.d.ts +62 -0
  137. package/dist/types/protocol.d.ts +86 -0
  138. package/dist/types/recommendations.d.ts +542 -0
  139. package/dist/types/reputation.d.ts +457 -0
  140. package/dist/types/sessionStatus.d.ts +231 -0
  141. package/dist/types/transparency.d.ts +392 -0
  142. package/dist/types/updates.d.ts +545 -0
  143. package/dist/types/userInvalidation.d.ts +94 -0
  144. package/dist/types/userResponse.d.ts +1706 -0
  145. package/dist/types/username.d.ts +265 -0
  146. package/dist/types/webauthn.d.ts +77 -0
  147. package/package.json +87 -0
@@ -0,0 +1,338 @@
1
+ /**
2
+ * Civic / Commons API contracts (Fase 1 — DNI + crypto-owned reputation).
3
+ *
4
+ * SINGLE SOURCE OF TRUTH for the wire shape of the public "DNI" card a Commons
5
+ * user shows (and others scan): the user's DID, display identity, trust tier,
6
+ * personhood status, verified domains, and credential badges — sealed with an
7
+ * Oxy custodial attestation so a scanner can verify it OFFLINE against the Oxy
8
+ * public key (the same `ES256K-DER-SHA256` scheme as the signed data export).
9
+ *
10
+ * The QR encodes ONLY the DID (`oxydni://card?did=…`) — never trust data — so a
11
+ * card cannot be spoofed by crafting a QR; the scanner resolves the signed card
12
+ * server-side and verifies the Oxy signature. The attestation is computed over
13
+ * the canonical-JSON of the `card` object, so a consumer re-canonicalizes the
14
+ * card it received and verifies `attestation.signature` against
15
+ * `attestation.publicKey` (which MUST be a current verification method of the
16
+ * Oxy DID).
17
+ *
18
+ * Explicit-`interface` exports (PublicCard, SignedPublicCard) follow the same
19
+ * node-resolution rationale as `UserNameResponse` / the identity contracts: a
20
+ * nested `z.infer<>` can degrade to `{}` under a consumer's
21
+ * `moduleResolution: "node"`, so the load-bearing shapes are declared as literal
22
+ * interfaces and the runtime schemas are annotated `z.ZodType<Interface>`.
23
+ *
24
+ * The `attestation` reuses the export-bundle `ExportAttestation` shape from
25
+ * `./identity` (mirrored, not duplicated): `{ issuer, publicKey, alg, signature,
26
+ * signedAt }`. It is `null` ONLY when the Oxy signing key is unconfigured (dev).
27
+ *
28
+ * Platform-agnostic — zod only, no react/react-native/expo, ESM-safe.
29
+ */
30
+ import { z } from 'zod';
31
+ import { type ExportAttestation } from './identity';
32
+ /**
33
+ * The trust tier shown on the card. Mirrors the API's reputation `TRUST_TIERS`
34
+ * (lowest → highest, plus the punitive `restricted`). Declared as a literal
35
+ * union here (NOT imported from the API) so the contract package stays
36
+ * dependency-free while giving consumers an exhaustive type to render against.
37
+ */
38
+ export type CardTrustTier = 'restricted' | 'new' | 'trusted' | 'high_trust' | 'verified';
39
+ /**
40
+ * Personhood verification status. `unverified` for everyone in Fase 1; the
41
+ * web-of-trust pipeline (Fase 3) graduates users to `pending` / `verified`.
42
+ */
43
+ export type PersonhoodStatus = 'unverified' | 'pending' | 'verified';
44
+ /**
45
+ * The public, render-ready "DNI" card for a Commons user. Assembled server-side
46
+ * from the canonical account fields and signed by Oxy.
47
+ *
48
+ * - `name` is the canonical composed display name (`name.displayName`) — a
49
+ * consumer renders it directly and NEVER recomposes it from `name.first` etc.
50
+ * - `username` / `avatarUrl` are OPTIONAL (omitted entirely for accounts that
51
+ * have none) — `avatarUrl` is the public `cloud.oxy.so` URL when an avatar is
52
+ * set. The server emits ONLY present keys so a consumer re-canonicalizing the
53
+ * card it received derives byte-identical bytes for signature verification.
54
+ * - `trustTier` is the user's current reputation tier; `personhoodStatus` is
55
+ * `unverified` for everyone in Fase 1 (Fase 3 graduates users) and
56
+ * `credentialBadges` is `[]` until verifiable credentials land (Fase 4).
57
+ * - `issuedAt` is epoch milliseconds — part of the signed bytes (the attestation
58
+ * covers the canonical-JSON of the whole card), so a scanner can detect a
59
+ * stale/replayed card.
60
+ */
61
+ export interface PublicCard {
62
+ did: string;
63
+ userId: string;
64
+ name: string;
65
+ username?: string;
66
+ avatarUrl?: string;
67
+ trustTier: CardTrustTier;
68
+ personhoodStatus: PersonhoodStatus;
69
+ verifiedDomains: string[];
70
+ credentialBadges: string[];
71
+ issuedAt: number;
72
+ }
73
+ export declare const publicCardSchema: z.ZodType<PublicCard>;
74
+ /**
75
+ * A {@link PublicCard} sealed with an Oxy custodial attestation. The attestation
76
+ * is an `ES256K-DER-SHA256` signature over the canonical-JSON of `card` (the
77
+ * exact `ExportAttestation` shape reused from the signed data export). It is
78
+ * `null` ONLY when the Oxy signing key (`OXY_PRIVATE_KEY`/`OXY_PUBLIC_KEY`) is
79
+ * unconfigured (dev / pre-prod) — in production it is always present. A consumer
80
+ * MUST check `attestation !== null` and that `attestation.publicKey` is the Oxy
81
+ * custodial key before trusting the card.
82
+ */
83
+ export interface SignedPublicCard {
84
+ card: PublicCard;
85
+ attestation: ExportAttestation | null;
86
+ }
87
+ export declare const signedPublicCardSchema: z.ZodType<SignedPublicCard>;
88
+ /**
89
+ * The `record` payload of a `real_life_attestation` signed envelope. The
90
+ * COUNTERPARTY (B) signs this with their OWN key as a self-issued v2 record on
91
+ * THEIR chain (`subject === issuer === B.did`); the subject being attested (A)
92
+ * is referenced by `about` (A's DID). The server resolves `about` → A's account
93
+ * and awards A the HIGH-weight `real_life_attested` points, recording B as the
94
+ * attestor (so B can be slashed if A's action is later found fraudulent).
95
+ *
96
+ * - `context` is an opaque interaction id from the QR (`oxydni://attest?ctx=…`).
97
+ * - `nonce` is the single-use replay guard from the QR; `exp` is its expiry
98
+ * (epoch ms) — both are part of the signed bytes.
99
+ * - `geohash` (optional) is a coarse co-location proof; `biometricOk` (optional)
100
+ * signals B's device biometric gate fired before signing (a support signal,
101
+ * never sufficient alone).
102
+ */
103
+ export interface RealLifeAttestationRecord {
104
+ about: string;
105
+ context: string;
106
+ nonce: string;
107
+ exp: number;
108
+ geohash?: string;
109
+ biometricOk?: boolean;
110
+ }
111
+ export declare const realLifeAttestationRecordSchema: z.ZodType<RealLifeAttestationRecord>;
112
+ /**
113
+ * The result of `POST /civic/attestations` on success: the stored attestation
114
+ * record id (B's envelope), the subject + attestor account ids, and the points
115
+ * awarded to the subject.
116
+ */
117
+ export interface RealLifeAttestationResult {
118
+ accepted: true;
119
+ recordId: string;
120
+ subjectUserId: string;
121
+ attestorUserId: string;
122
+ points: number;
123
+ }
124
+ export declare const realLifeAttestationResultSchema: z.ZodType<RealLifeAttestationResult>;
125
+ /** A juror's verdict on a validation request. */
126
+ export type ValidationVerdict = 'valid' | 'invalid' | 'abstain';
127
+ /** The lifecycle status of a validation request. */
128
+ export type ValidationRequestStatus = 'pending' | 'quorum_met' | 'validated' | 'rejected' | 'expired';
129
+ /**
130
+ * The `record` payload of a `validation_verdict` signed envelope — a juror's
131
+ * SELF-ISSUED verdict, bound to the request id + the canonical payload hash (so
132
+ * a verdict cannot be replayed onto a different request or an altered payload).
133
+ */
134
+ export interface ValidationVerdictRecord {
135
+ requestId: string;
136
+ payloadHash: string;
137
+ verdict: ValidationVerdict;
138
+ }
139
+ export declare const validationVerdictRecordSchema: z.ZodType<ValidationVerdictRecord>;
140
+ /** Request body for opening a validation request (`POST /civic/validations`). */
141
+ export declare const validationOpenRequestSchema: z.ZodObject<{
142
+ subjectUserId: z.ZodString;
143
+ actionType: z.ZodString;
144
+ sourceActionId: z.ZodString;
145
+ payload: z.ZodRecord<z.ZodString, z.ZodUnknown>;
146
+ highValue: z.ZodOptional<z.ZodBoolean>;
147
+ }, "strip", z.ZodTypeAny, {
148
+ subjectUserId: string;
149
+ actionType: string;
150
+ sourceActionId: string;
151
+ payload: Record<string, unknown>;
152
+ highValue?: boolean | undefined;
153
+ }, {
154
+ subjectUserId: string;
155
+ actionType: string;
156
+ sourceActionId: string;
157
+ payload: Record<string, unknown>;
158
+ highValue?: boolean | undefined;
159
+ }>;
160
+ export type ValidationOpenRequest = z.infer<typeof validationOpenRequestSchema>;
161
+ /** The result of opening a validation request (`POST /civic/validations`). */
162
+ export interface ValidationOpenResult {
163
+ requestId: string;
164
+ selectedValidatorCount: number;
165
+ expiresAt: string;
166
+ }
167
+ export declare const validationOpenResultSchema: z.ZodType<ValidationOpenResult>;
168
+ /**
169
+ * A pending validation request as shown in a juror's inbox. `payload` is the
170
+ * claim the juror inspects; `payloadHash` is what their verdict must bind to.
171
+ */
172
+ export interface ValidationRequestSummary {
173
+ id: string;
174
+ subjectUserId: string;
175
+ actionType: string;
176
+ payload: Record<string, unknown>;
177
+ payloadHash: string;
178
+ status: ValidationRequestStatus;
179
+ highValue: boolean;
180
+ expiresAt: string;
181
+ }
182
+ export declare const validationRequestSummarySchema: z.ZodType<ValidationRequestSummary>;
183
+ /** The result of casting a vote (`POST /civic/validations/:id/vote`). */
184
+ export interface ValidationVoteResult {
185
+ recorded: true;
186
+ requestId: string;
187
+ verdict: ValidationVerdict;
188
+ status: ValidationRequestStatus;
189
+ }
190
+ export declare const validationVoteResultSchema: z.ZodType<ValidationVoteResult>;
191
+ /**
192
+ * The `record` payload of a `personhood_vouch` signed envelope. The VOUCHER (B)
193
+ * signs this with their OWN key as a self-issued v2 record on THEIR chain
194
+ * (`subject === issuer === B.did`); the person being vouched for (A) is
195
+ * referenced by `about` (A's DID). The server resolves `about` → A's account,
196
+ * stakes the voucher, awards A the `personhood_vouched` points, and recomputes
197
+ * A's personhood.
198
+ *
199
+ * - `about` is A's DID (`did:web:oxy.so:u:<userId>`).
200
+ * - `context` (optional) is an opaque note from the vouching UI.
201
+ * - `stake` (optional) is the voucher's chosen stake; the server clamps it into
202
+ * `[PERSONHOOD_VOUCH_MIN_STAKE, PERSONHOOD_VOUCH_MAX_STAKE]` and defaults it
203
+ * when omitted. (Note: the wire field is `stake`, NOT `stakeAmount` — the
204
+ * latter is the server's clamped, awarded value echoed in {@link VouchResult}.)
205
+ */
206
+ export interface PersonhoodVouchRecord {
207
+ about: string;
208
+ context?: string;
209
+ stake?: number;
210
+ }
211
+ export declare const personhoodVouchRecordSchema: z.ZodType<PersonhoodVouchRecord>;
212
+ /**
213
+ * The signal sub-scores behind a personhood score (audit / UI breakdown),
214
+ * mirroring the API `PersonhoodStatus` model's embedded `breakdown`.
215
+ */
216
+ export interface PersonhoodBreakdown {
217
+ /** Saturated [0,1] vouch signal from the weighted vouch sum. */
218
+ vouchSignal: number;
219
+ /** Saturated [0,1] real-life-attestation signal. */
220
+ realLifeSignal: number;
221
+ /** 1 when the account is biometric-bound, else 0. */
222
+ biometricSignal: number;
223
+ /** Weighted blend of the three signals before the sybil penalty. */
224
+ evidence: number;
225
+ /** The [0,1] sybil penalty subtracted from the evidence. */
226
+ sybilPenalty: number;
227
+ /** True when the score came from the seed-verifier genesis short-circuit. */
228
+ seed: boolean;
229
+ }
230
+ export declare const personhoodBreakdownSchema: z.ZodType<PersonhoodBreakdown>;
231
+ /**
232
+ * The public personhood status snapshot returned by
233
+ * `GET /civic/personhood/:userId` (and `POST /civic/personhood/:userId/recompute`).
234
+ * Mirrors the API `PersonhoodStatus` model's serialized response exactly — a
235
+ * cached, recomputable proof-of-personhood snapshot.
236
+ *
237
+ * - `score` is in `[0,1]`; `isRealPerson` is `score >= θ`.
238
+ * - `breakdown` is `null` ONLY on a public read of a user who has no status
239
+ * document yet (the zeroed `unverified` shape); otherwise it is the full
240
+ * {@link PersonhoodBreakdown}.
241
+ * - `updatedAt` is the ISO-8601 timestamp of the last recompute, or `null` when
242
+ * no status document exists yet. (Distinct from the card's coarse
243
+ * {@link PersonhoodStatus} enum, which is `'unverified' | 'pending' |
244
+ * 'verified'`.)
245
+ */
246
+ export interface PersonhoodStatusResult {
247
+ userId: string;
248
+ score: number;
249
+ isRealPerson: boolean;
250
+ vouchCount: number;
251
+ realLifeCount: number;
252
+ biometricBound: boolean;
253
+ sybilPenalty: number;
254
+ breakdown: PersonhoodBreakdown | null;
255
+ updatedAt: string | null;
256
+ }
257
+ export declare const personhoodStatusResultSchema: z.ZodType<PersonhoodStatusResult>;
258
+ /**
259
+ * The result of `POST /civic/personhood/vouch` on success: the stored vouch
260
+ * record id (the voucher's envelope), the subject + voucher account ids, the
261
+ * clamped stake the server recorded, and the points awarded to the subject.
262
+ */
263
+ export interface VouchResult {
264
+ accepted: true;
265
+ recordId: string;
266
+ subjectUserId: string;
267
+ voucherUserId: string;
268
+ stakeAmount: number;
269
+ points: number;
270
+ }
271
+ export declare const vouchResultSchema: z.ZodType<VouchResult>;
272
+ /** The lifecycle status of a stored verifiable credential. */
273
+ export type CredentialStatus = 'active' | 'revoked' | 'expired';
274
+ /**
275
+ * The `record` payload of a `credential` signed envelope — the W3C-VC-flavoured
276
+ * claim the issuer signs.
277
+ *
278
+ * - `about` is the HOLDER's DID (`did:web:oxy.so:u:<userId>`), i.e. the W3C
279
+ * `credentialSubject.id`. (Named `about` to match the sibling civic records
280
+ * and to avoid colliding with the envelope's own chain `subject` field.)
281
+ * - `types` are the VC type tags; `'VerifiableCredential'` MUST be present as the
282
+ * base type, with at least one specific type (e.g. `'EmploymentCredential'`).
283
+ * - `claims` is the arbitrary, issuer-asserted claim set about the holder.
284
+ * - `expiresAt` (optional) is epoch milliseconds; absent = non-expiring. It is
285
+ * part of the signed bytes, so a holder cannot extend a credential's validity.
286
+ */
287
+ export interface CredentialRecord {
288
+ about: string;
289
+ types: string[];
290
+ claims: Record<string, unknown>;
291
+ expiresAt?: number;
292
+ }
293
+ export declare const credentialRecordSchema: z.ZodType<CredentialRecord>;
294
+ /**
295
+ * The serialized verifiable credential as returned by the list + verify routes.
296
+ * `issuerUserId` is present only for user-issued credentials (absent for
297
+ * app/org-issued credentials signed by the Oxy custodial key). All timestamps
298
+ * are epoch milliseconds.
299
+ */
300
+ export interface VerifiableCredentialResponse {
301
+ id: string;
302
+ recordId: string;
303
+ holderUserId: string;
304
+ holderDid: string;
305
+ issuerUserId?: string;
306
+ issuerDid: string;
307
+ types: string[];
308
+ claims: Record<string, unknown>;
309
+ status: CredentialStatus;
310
+ issuedAt: number;
311
+ expiresAt?: number;
312
+ revokedAt?: number;
313
+ }
314
+ export declare const verifiableCredentialResponseSchema: z.ZodType<VerifiableCredentialResponse>;
315
+ /** The result of `POST /civic/credentials` on success. */
316
+ export interface CredentialIssueResult {
317
+ accepted: true;
318
+ credential: VerifiableCredentialResponse;
319
+ }
320
+ export declare const credentialIssueResultSchema: z.ZodType<CredentialIssueResult>;
321
+ /** The result of `GET /civic/credentials/:holderUserId` (list). */
322
+ export interface CredentialListResult {
323
+ credentials: VerifiableCredentialResponse[];
324
+ }
325
+ export declare const credentialListResultSchema: z.ZodType<CredentialListResult>;
326
+ /**
327
+ * The result of `GET /civic/credentials/by-record/:recordId/verify`. `valid` is
328
+ * `true` ONLY when the signature verifies against a CURRENT verification method
329
+ * of the issuer DID AND the credential is neither revoked nor expired. `reason`
330
+ * is a stable, machine-readable rejection code when `valid` is `false`.
331
+ * `credential` is `null` when no credential exists for the record id.
332
+ */
333
+ export interface CredentialVerifyResult {
334
+ valid: boolean;
335
+ reason?: string;
336
+ credential: VerifiableCredentialResponse | null;
337
+ }
338
+ export declare const credentialVerifyResultSchema: z.ZodType<CredentialVerifyResult>;
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Canonical contract for the "Sign in with Oxy" approval handoff.
3
+ *
4
+ * SINGLE SOURCE OF TRUTH for the closed set of reasons an approver may attach
5
+ * when it DENIES a pending request via
6
+ * `POST /auth/session/deny/:authorizeCode`.
7
+ *
8
+ * That endpoint is UNAUTHENTICATED — the public `authorizeCode` is the only
9
+ * credential — so a free-form string from it is never stored: it would be an
10
+ * unauthenticated write of arbitrary text onto a record other surfaces read.
11
+ * The set is therefore deliberately tiny, and closed:
12
+ *
13
+ * - `'declined'` the approver rejected a request they recognised ("Not now").
14
+ * - `'not_me'` the approver did not start the request ("This wasn't me").
15
+ * The ONE value that records the denial as suspicious rather
16
+ * than an ordinary cancel, so a UI may only offer it where the
17
+ * user genuinely said so.
18
+ *
19
+ * Why this lives in `@oxy.so/contracts` rather than in either consumer: the same
20
+ * closed set is enforced in three places — the request schema of the API route,
21
+ * the `enum` of the persisted `AuthSession.deniedReason` field, and the client
22
+ * SDK's `denyCommonsSignIn` parameter. Two hand-maintained copies of a wire
23
+ * contract drift the moment a value is added on one side only, and the failure
24
+ * lands at runtime, in an auth path, as a generic validation error. One
25
+ * declaration makes that impossible.
26
+ *
27
+ * Platform-agnostic — zod only, no react/react-native/expo. ESM-safe (no
28
+ * `require()`).
29
+ */
30
+ import { z } from 'zod';
31
+ /**
32
+ * The closed set, as a value — consumed directly where a runtime list is
33
+ * required (e.g. the Mongoose `enum` of `AuthSession.deniedReason`, which is
34
+ * the storage-level guarantee that an unauthenticated caller can never write
35
+ * free-form text into the field).
36
+ */
37
+ export declare const COMMONS_DENY_REASONS: readonly ["declined", "not_me"];
38
+ /**
39
+ * The same set as a zod enum — the edge validator. Anything outside it
40
+ * (including free-form text) is rejected with 400 before any handler runs.
41
+ */
42
+ export declare const commonsDenyReasonSchema: z.ZodEnum<["declined", "not_me"]>;
43
+ /** Why the approver denied a "Sign in with Oxy" request. */
44
+ export type CommonsDenyReason = z.infer<typeof commonsDenyReasonSchema>;
45
+ /**
46
+ * Android notification channel id the identity-approval push is sent on.
47
+ *
48
+ * A wire contract for the same reason the deny set is: Android 8+ DROPS a
49
+ * notification whose channel id the app has not created, silently and with no
50
+ * client-side error. The API attaches this id when it sends, and the vault
51
+ * creates the channel with it before registering a push token — two hand-typed
52
+ * copies of that string would fail as "the notification never arrived", which
53
+ * is the single hardest push symptom to diagnose.
54
+ *
55
+ * The channel's user-visible NAME and description are deliberately NOT here:
56
+ * those are localized app copy, and the vault owns them.
57
+ */
58
+ export declare const IDENTITY_APPROVAL_PUSH_CHANNEL = "auth-approval";
@@ -0,0 +1,74 @@
1
+ /**
2
+ * First-party login result contract.
3
+ *
4
+ * SINGLE SOURCE OF TRUTH for the first-party login result (the session arm). The
5
+ * API validates its OUTPUT against this schema; every consumer (`@oxy.so/core`'s
6
+ * auth mixin) validates its INPUT against the same definition, so producer and
7
+ * consumers cannot drift. Sign-in is passkey (WebAuthn) or Commons handoff —
8
+ * password and 2FA were removed, so the only outcome is a completed session.
9
+ *
10
+ * The device transport is `deviceId` + `deviceSecret` + `POST /session/device/token`
11
+ * (see `deviceSession.ts`). The legacy cookie/bootstrap/refresh-family lanes were
12
+ * removed in the zero-cookie cutover — nothing here carries a refresh token or a
13
+ * boot fragment.
14
+ *
15
+ * Nested-object response shapes are declared as explicit `interface`s with the
16
+ * runtime schema annotated `z.ZodType<Interface>` — the same rationale as
17
+ * `identity.ts` / `userResponse.ts`: a `z.infer<>` of a nested object schema can
18
+ * degrade to `{}` under a consumer's `moduleResolution: "node"` (node10), so the
19
+ * load-bearing shapes are pinned by literal interfaces. Flat request/response
20
+ * shapes (no nested-object hazard) are inferred via `z.infer<>`.
21
+ *
22
+ * Platform-agnostic — zod only, no react/react-native/expo. ESM-safe (no
23
+ * `require()`).
24
+ */
25
+ import { z } from 'zod';
26
+ /** One anomalous signal the server flagged on a sign-in (new device, location, …). */
27
+ export interface SecurityAlertAnomaly {
28
+ type: string;
29
+ reason: string;
30
+ details?: string;
31
+ }
32
+ /**
33
+ * The "New sign-in detected" payload the API attaches to a successful
34
+ * `POST /auth/login` when anomaly detection fires (`session.controller.ts`).
35
+ * The IdP renders `message` and gates the flow on user acknowledgement before
36
+ * continuing to the OAuth authorize step.
37
+ */
38
+ export interface SecurityAlert {
39
+ message: string;
40
+ anomalies: SecurityAlertAnomaly[];
41
+ }
42
+ /**
43
+ * A successful sign-in. Matches the API's `SessionAuthResponse` EXACTLY
44
+ * (`buildSessionAuthResponse`). `user` is the truncated session-user shape the
45
+ * sign-in endpoints emit (NOT the full `userResponseSchema`).
46
+ */
47
+ export interface LoginSessionResult {
48
+ sessionId: string;
49
+ deviceId: string;
50
+ expiresAt: string;
51
+ accessToken?: string;
52
+ /**
53
+ * The device secret (zero-cookie transport). Emitted on every successful
54
+ * sign-in; the client persists it first-party alongside `deviceId` and later
55
+ * mints access tokens via `POST /session/device/token`. Optional only because
56
+ * a best-effort mint can fail — it is the sole restore credential.
57
+ */
58
+ deviceSecret?: string;
59
+ /**
60
+ * Present only when the server's anomaly detection flagged this sign-in.
61
+ * The IdP shows a "New sign-in detected" acknowledgement before proceeding.
62
+ * The session is already established regardless — this is an interstitial,
63
+ * not a gate on the credential check.
64
+ */
65
+ securityAlert?: SecurityAlert;
66
+ user: {
67
+ id: string;
68
+ username?: string;
69
+ avatar?: string;
70
+ };
71
+ }
72
+ /** The outcome of a successful sign-in — always a completed session. */
73
+ export type LoginResult = LoginSessionResult;
74
+ export declare const loginResultSchema: z.ZodType<LoginResult>;