@oxyhq/contracts 0.2.1 → 0.4.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.
- package/dist/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/civic.js +163 -0
- package/dist/cjs/identity.js +216 -0
- package/dist/cjs/index.js +36 -1
- package/dist/cjs/userResponse.js +18 -0
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/civic.js +160 -0
- package/dist/esm/identity.js +213 -0
- package/dist/esm/index.js +8 -0
- package/dist/esm/userResponse.js +18 -0
- package/dist/types/.tsbuildinfo +1 -1
- package/dist/types/civic.d.ts +338 -0
- package/dist/types/identity.d.ts +279 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/recommendations.d.ts +14 -14
- package/dist/types/sessionStatus.d.ts +2 -2
- package/dist/types/userResponse.d.ts +379 -22
- package/package.json +1 -1
|
@@ -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,279 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Self-sovereign identity API contracts.
|
|
3
|
+
*
|
|
4
|
+
* SINGLE SOURCE OF TRUTH for the wire shape of Oxy's AtProto/Bluesky-flavoured
|
|
5
|
+
* identity & portability layer: the W3C DID document the API derives on demand,
|
|
6
|
+
* the signed-record envelope clients sign with their cryptographic key (and the
|
|
7
|
+
* server verifies), the verified-domain badge, the auth-method ↔ DID
|
|
8
|
+
* verification-method mapping, and the signed data-export ("credible exit")
|
|
9
|
+
* bundle. The API validates its OUTPUT against these schemas; every consumer
|
|
10
|
+
* (the Commons vault app, `@oxyhq/core`'s identity mixin) validates its INPUT
|
|
11
|
+
* against the same definitions, so producer and consumers cannot drift.
|
|
12
|
+
*
|
|
13
|
+
* Design anchors (from the identity-layer plan):
|
|
14
|
+
* - DID = `did:web:oxy.so:u:<userId>` — anchored on the stable account id, NOT
|
|
15
|
+
* the keypair. The keypair is a *verification method* that maps 1:1 to the
|
|
16
|
+
* existing `authMethods[]`. Custodial (password-only) users get a DID
|
|
17
|
+
* controlled solely by Oxy (`OXY_DID`); creating a Commons key upgrades them
|
|
18
|
+
* to self-sovereign (`controller = [userDid, OXY_DID]`); fully reversible.
|
|
19
|
+
* - Verification methods use the secp256k1 `EcdsaSecp256k1VerificationKey2019`
|
|
20
|
+
* type with `publicKeyHex` for now (a `Multikey`/`publicKeyMultibase` form may
|
|
21
|
+
* be added later — see the plan's open risks).
|
|
22
|
+
* - Signed records carry an envelope whose signing input is the canonical-JSON
|
|
23
|
+
* of every field EXCEPT `publicKey` and `signature`; `alg` is
|
|
24
|
+
* `ES256K-DER-SHA256` (secp256k1 over the SHA-256 of the canonical bytes,
|
|
25
|
+
* DER-encoded signature) — the same scheme `SignatureService` uses.
|
|
26
|
+
*
|
|
27
|
+
* Explicit-`interface` exports (DidDocument, SignedRecordEnvelope, ExportBundle,
|
|
28
|
+
* VerifiedDomain, AuthMethodsResponse and their sub-parts) follow the same
|
|
29
|
+
* rationale as `UserNameResponse` in `./userResponse`: a `z.infer<>` of a nested
|
|
30
|
+
* object schema can degrade under a consumer's `moduleResolution: "node"`
|
|
31
|
+
* (node10) resolution, so the load-bearing response shapes are declared as
|
|
32
|
+
* literal interfaces and the runtime schemas are annotated `z.ZodType<Interface>`
|
|
33
|
+
* — the emitted `.d.ts` then states the field types verbatim and survives BOTH
|
|
34
|
+
* `node` and `bundler` resolution. Request schemas (no nested-object hazard) are
|
|
35
|
+
* inferred via `z.infer<>`.
|
|
36
|
+
*
|
|
37
|
+
* Platform-agnostic — zod only, no react/react-native/expo. ESM-safe (no
|
|
38
|
+
* `require()`).
|
|
39
|
+
*/
|
|
40
|
+
import { z } from 'zod';
|
|
41
|
+
/**
|
|
42
|
+
* A single DID verification method. Mirrors the secp256k1 key entries the API
|
|
43
|
+
* derives from `User.publicKey` + each `authMethods[]` of type `identity`.
|
|
44
|
+
* `id` is a fragment reference within the DID document (e.g.
|
|
45
|
+
* `did:web:oxy.so:u:<id>#key-1`); `controller` is the controlling DID;
|
|
46
|
+
* `publicKeyHex` is the uncompressed/compressed secp256k1 public key in hex.
|
|
47
|
+
*/
|
|
48
|
+
export interface VerificationMethod {
|
|
49
|
+
id: string;
|
|
50
|
+
type: 'EcdsaSecp256k1VerificationKey2019';
|
|
51
|
+
controller: string;
|
|
52
|
+
publicKeyHex: string;
|
|
53
|
+
}
|
|
54
|
+
export declare const verificationMethodSchema: z.ZodType<VerificationMethod>;
|
|
55
|
+
/**
|
|
56
|
+
* A DID service entry (the `service[]` array). Oxy publishes its API root and
|
|
57
|
+
* profile endpoints here so a resolver can discover where to fetch the user's
|
|
58
|
+
* data. `serviceEndpoint` is a URL string.
|
|
59
|
+
*/
|
|
60
|
+
export interface DidService {
|
|
61
|
+
id: string;
|
|
62
|
+
type: string;
|
|
63
|
+
serviceEndpoint: string;
|
|
64
|
+
}
|
|
65
|
+
export declare const didServiceSchema: z.ZodType<DidService>;
|
|
66
|
+
/**
|
|
67
|
+
* A W3C DID document derived on demand by the API (no stored document).
|
|
68
|
+
*
|
|
69
|
+
* - `controller` is `[userDid, OXY_DID]` for a self-sovereign account (it holds
|
|
70
|
+
* at least one `identity` verification method) or `[OXY_DID]` for a custodial
|
|
71
|
+
* (password-only) account.
|
|
72
|
+
* - `verificationMethod[]` is composed from the account's secp256k1 keys.
|
|
73
|
+
* - `authentication` / `assertionMethod` reference verification-method ids.
|
|
74
|
+
* - `alsoKnownAs[]` carries the account's other identifiers (`acct:` handle,
|
|
75
|
+
* profile URL, any verified-domain URLs).
|
|
76
|
+
*/
|
|
77
|
+
export interface DidDocument {
|
|
78
|
+
'@context': string[];
|
|
79
|
+
id: string;
|
|
80
|
+
controller: string[];
|
|
81
|
+
verificationMethod: VerificationMethod[];
|
|
82
|
+
authentication: string[];
|
|
83
|
+
assertionMethod: string[];
|
|
84
|
+
alsoKnownAs: string[];
|
|
85
|
+
service: DidService[];
|
|
86
|
+
}
|
|
87
|
+
export declare const didDocumentSchema: z.ZodType<DidDocument>;
|
|
88
|
+
/**
|
|
89
|
+
* The category of a signed record. v1 only ever carried `identity` / `profile`
|
|
90
|
+
* (already in production); v2 widens the union with the civic record types
|
|
91
|
+
* (reputation attestations, real-life / peer validations, personhood vouches,
|
|
92
|
+
* verifiable credentials) and the user-node registration record. The signing
|
|
93
|
+
* input includes `type`, so this union is part of the signed bytes.
|
|
94
|
+
*/
|
|
95
|
+
export type SignedRecordType = 'identity' | 'profile' | 'reputation_attestation' | 'real_life_attestation' | 'validation_verdict' | 'personhood_vouch' | 'credential' | 'node';
|
|
96
|
+
/**
|
|
97
|
+
* A signed record envelope. `record` is the arbitrary payload; the signing
|
|
98
|
+
* input is the canonical-JSON of every envelope field EXCEPT `publicKey` and
|
|
99
|
+
* `signature`. `subject` and `issuer` are DIDs (the subject the record is about
|
|
100
|
+
* and the signer's DID — equal for self-issued records, `OXY_DID` for a
|
|
101
|
+
* custodial provenance attestation). `issuedAt` is epoch milliseconds.
|
|
102
|
+
*
|
|
103
|
+
* ## Versioning
|
|
104
|
+
*
|
|
105
|
+
* - **v1** is the original shape (`{version, type, subject, issuer, record,
|
|
106
|
+
* issuedAt}` + `publicKey/alg/signature`). It carries NONE of the v2 chain
|
|
107
|
+
* fields and remains accepted unchanged — every `identity`/`profile` record
|
|
108
|
+
* already in production verifies byte-identically.
|
|
109
|
+
* - **v2** adds a per-subject hash-chain (an append-only "personal blockchain"
|
|
110
|
+
* of a single signer, no consensus/mining). The four chain fields are part of
|
|
111
|
+
* the signed bytes (so the chain cannot be forged):
|
|
112
|
+
* - `seq` — strictly-increasing sequence number per subject.
|
|
113
|
+
* - `prev` — the `recordId` (content address) of the previous record in this
|
|
114
|
+
* subject's chain, or `null` at genesis.
|
|
115
|
+
* - `collection` + `rkey` — an AtProto-style record key (e.g.
|
|
116
|
+
* `collection: 'app.oxy.identity'`, `rkey: 'self'`) used for
|
|
117
|
+
* materialization and last-writer-wins reconciliation.
|
|
118
|
+
*
|
|
119
|
+
* The chain fields are OPTIONAL on the interface so v1 envelopes (which omit
|
|
120
|
+
* them) still type-check; the schema enforces "present iff version === 2".
|
|
121
|
+
*/
|
|
122
|
+
export interface SignedRecordEnvelope {
|
|
123
|
+
version: 1 | 2;
|
|
124
|
+
type: SignedRecordType;
|
|
125
|
+
subject: string;
|
|
126
|
+
issuer: string;
|
|
127
|
+
record: Record<string, unknown>;
|
|
128
|
+
issuedAt: number;
|
|
129
|
+
/** v2 only: strictly-increasing sequence number for this subject's chain. */
|
|
130
|
+
seq?: number;
|
|
131
|
+
/** v2 only: `recordId` of the previous record in the chain, `null` at genesis. */
|
|
132
|
+
prev?: string | null;
|
|
133
|
+
/** v2 only: AtProto-style collection namespace (e.g. `app.oxy.identity`). */
|
|
134
|
+
collection?: string;
|
|
135
|
+
/** v2 only: AtProto-style record key within the collection (e.g. `self`). */
|
|
136
|
+
rkey?: string;
|
|
137
|
+
publicKey: string;
|
|
138
|
+
alg: 'ES256K-DER-SHA256';
|
|
139
|
+
signature: string;
|
|
140
|
+
}
|
|
141
|
+
export declare const signedRecordEnvelopeSchema: z.ZodType<SignedRecordEnvelope>;
|
|
142
|
+
/**
|
|
143
|
+
* A proven domain ownership badge. `method` records how ownership was proven —
|
|
144
|
+
* a DNS-TXT record (`_oxy-identity.<domain>`) or a `/.well-known/oxy-domain`
|
|
145
|
+
* HTTP file. `verifiedAt` is a string on the wire (ISO timestamp) but accepts a
|
|
146
|
+
* `Date` so the API can validate its own pre-serialization model objects.
|
|
147
|
+
*/
|
|
148
|
+
export interface VerifiedDomain {
|
|
149
|
+
domain: string;
|
|
150
|
+
verifiedAt: string | Date;
|
|
151
|
+
method: 'dns-txt' | 'well-known';
|
|
152
|
+
}
|
|
153
|
+
export declare const verifiedDomainSchema: z.ZodType<VerifiedDomain>;
|
|
154
|
+
/** Request body for `POST /identity/domains` — the domain to start verifying. */
|
|
155
|
+
export declare const domainVerificationRequestSchema: z.ZodObject<{
|
|
156
|
+
domain: z.ZodString;
|
|
157
|
+
}, "strip", z.ZodTypeAny, {
|
|
158
|
+
domain: string;
|
|
159
|
+
}, {
|
|
160
|
+
domain: string;
|
|
161
|
+
}>;
|
|
162
|
+
export type DomainVerificationRequest = z.infer<typeof domainVerificationRequestSchema>;
|
|
163
|
+
/**
|
|
164
|
+
* The instructions the API returns when a domain verification is requested. The
|
|
165
|
+
* caller may prove ownership EITHER by publishing the `dns` TXT record OR by
|
|
166
|
+
* serving the `wellKnown` file; either path then satisfies
|
|
167
|
+
* `POST /identity/domains/:domain/verify`.
|
|
168
|
+
*/
|
|
169
|
+
export declare const domainVerificationInstructionsSchema: z.ZodObject<{
|
|
170
|
+
domain: z.ZodString;
|
|
171
|
+
token: z.ZodString;
|
|
172
|
+
dns: z.ZodObject<{
|
|
173
|
+
name: z.ZodString;
|
|
174
|
+
value: z.ZodString;
|
|
175
|
+
}, "strip", z.ZodTypeAny, {
|
|
176
|
+
value: string;
|
|
177
|
+
name: string;
|
|
178
|
+
}, {
|
|
179
|
+
value: string;
|
|
180
|
+
name: string;
|
|
181
|
+
}>;
|
|
182
|
+
wellKnown: z.ZodObject<{
|
|
183
|
+
url: z.ZodString;
|
|
184
|
+
body: z.ZodString;
|
|
185
|
+
}, "strip", z.ZodTypeAny, {
|
|
186
|
+
url: string;
|
|
187
|
+
body: string;
|
|
188
|
+
}, {
|
|
189
|
+
url: string;
|
|
190
|
+
body: string;
|
|
191
|
+
}>;
|
|
192
|
+
}, "strip", z.ZodTypeAny, {
|
|
193
|
+
domain: string;
|
|
194
|
+
token: string;
|
|
195
|
+
dns: {
|
|
196
|
+
value: string;
|
|
197
|
+
name: string;
|
|
198
|
+
};
|
|
199
|
+
wellKnown: {
|
|
200
|
+
url: string;
|
|
201
|
+
body: string;
|
|
202
|
+
};
|
|
203
|
+
}, {
|
|
204
|
+
domain: string;
|
|
205
|
+
token: string;
|
|
206
|
+
dns: {
|
|
207
|
+
value: string;
|
|
208
|
+
name: string;
|
|
209
|
+
};
|
|
210
|
+
wellKnown: {
|
|
211
|
+
url: string;
|
|
212
|
+
body: string;
|
|
213
|
+
};
|
|
214
|
+
}>;
|
|
215
|
+
export type DomainVerificationInstructions = z.infer<typeof domainVerificationInstructionsSchema>;
|
|
216
|
+
/**
|
|
217
|
+
* One linked authentication method. Mirrors a `User.authMethods[]` entry.
|
|
218
|
+
* `verificationMethodId` is present for `identity` methods (a key) and absent
|
|
219
|
+
* for `password`/social methods, linking the auth method to its DID
|
|
220
|
+
* verification-method fragment.
|
|
221
|
+
*/
|
|
222
|
+
export interface AuthMethodEntry {
|
|
223
|
+
type: 'identity' | 'password' | 'google' | 'apple' | 'github';
|
|
224
|
+
linkedAt: string | Date;
|
|
225
|
+
verificationMethodId?: string;
|
|
226
|
+
}
|
|
227
|
+
export declare const authMethodEntrySchema: z.ZodType<AuthMethodEntry>;
|
|
228
|
+
/**
|
|
229
|
+
* Wire shape of `GET /auth/methods` — the account's DID plus every linked
|
|
230
|
+
* authentication method.
|
|
231
|
+
*/
|
|
232
|
+
export interface AuthMethodsResponse {
|
|
233
|
+
did: string;
|
|
234
|
+
methods: AuthMethodEntry[];
|
|
235
|
+
}
|
|
236
|
+
export declare const authMethodsResponseSchema: z.ZodType<AuthMethodsResponse>;
|
|
237
|
+
/**
|
|
238
|
+
* A cryptographic attestation over the canonical-JSON of an export bundle.
|
|
239
|
+
* Reused for both the mandatory Oxy provenance `attestation` (signed with the
|
|
240
|
+
* Oxy custodial key) and the optional client `proof` (signed with the user's
|
|
241
|
+
* own key when they hold one). `signedAt` is epoch milliseconds.
|
|
242
|
+
*/
|
|
243
|
+
export interface ExportAttestation {
|
|
244
|
+
issuer: string;
|
|
245
|
+
publicKey: string;
|
|
246
|
+
alg: 'ES256K-DER-SHA256';
|
|
247
|
+
signature: string;
|
|
248
|
+
signedAt: number;
|
|
249
|
+
}
|
|
250
|
+
export declare const exportAttestationSchema: z.ZodType<ExportAttestation>;
|
|
251
|
+
/**
|
|
252
|
+
* The signed, open-format data-export bundle from `GET /users/me/export`. A
|
|
253
|
+
* portable snapshot of the account: its DID document, profile, verified
|
|
254
|
+
* domains, auth methods (no secrets), published signed records, per-app data,
|
|
255
|
+
* and social graph.
|
|
256
|
+
*
|
|
257
|
+
* `attestation` is the Oxy custodial provenance signature. It is `null` only
|
|
258
|
+
* when the Oxy custodial signing key (`OXY_PRIVATE_KEY`) is unset (dev /
|
|
259
|
+
* pre-prod); in production it is always present. Carries an optional client
|
|
260
|
+
* `proof` when the user signed the bundle with their own key.
|
|
261
|
+
*/
|
|
262
|
+
export interface ExportBundle {
|
|
263
|
+
'$schema': string;
|
|
264
|
+
exportedAt: string;
|
|
265
|
+
did: string;
|
|
266
|
+
didDocument: DidDocument;
|
|
267
|
+
profile: Record<string, unknown>;
|
|
268
|
+
verifiedDomains: VerifiedDomain[];
|
|
269
|
+
authMethods: AuthMethodEntry[];
|
|
270
|
+
signedRecords: SignedRecordEnvelope[];
|
|
271
|
+
appData: Record<string, unknown>[];
|
|
272
|
+
social: {
|
|
273
|
+
following: string[];
|
|
274
|
+
followers: string[];
|
|
275
|
+
};
|
|
276
|
+
attestation: ExportAttestation | null;
|
|
277
|
+
proof?: ExportAttestation;
|
|
278
|
+
}
|
|
279
|
+
export declare const exportBundleSchema: z.ZodType<ExportBundle>;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -17,3 +17,7 @@ export { fedcmTokenPayloadSchema, } from './fedcmToken';
|
|
|
17
17
|
export type { FedcmTokenPayload, } from './fedcmToken';
|
|
18
18
|
export { recommendationExcludeTypeSchema, recommendationBoostSchema, recommendationSignalWeightsSchema, recommendationRequestSchema, recommendationCountSchema, recommendationItemSchema, recommendationResponseSchema, appEndorsementInputSchema, appInterestInputSchema, appUserSignalIngestSchema, } from './recommendations';
|
|
19
19
|
export type { RecommendationExcludeType, RecommendationBoost, RecommendationSignalWeights, RecommendationRequest, RecommendationCount, RecommendationItem, RecommendationResponse, AppEndorsementInput, AppInterestInput, AppUserSignalIngest, } from './recommendations';
|
|
20
|
+
export { verificationMethodSchema, didServiceSchema, didDocumentSchema, signedRecordEnvelopeSchema, verifiedDomainSchema, domainVerificationRequestSchema, domainVerificationInstructionsSchema, authMethodEntrySchema, authMethodsResponseSchema, exportAttestationSchema, exportBundleSchema, } from './identity';
|
|
21
|
+
export type { VerificationMethod, DidService, DidDocument, SignedRecordEnvelope, SignedRecordType, VerifiedDomain, DomainVerificationRequest, DomainVerificationInstructions, AuthMethodEntry, AuthMethodsResponse, ExportAttestation, ExportBundle, } from './identity';
|
|
22
|
+
export { publicCardSchema, signedPublicCardSchema, realLifeAttestationRecordSchema, realLifeAttestationResultSchema, validationVerdictRecordSchema, validationOpenRequestSchema, validationOpenResultSchema, validationRequestSummarySchema, validationVoteResultSchema, personhoodVouchRecordSchema, personhoodBreakdownSchema, personhoodStatusResultSchema, vouchResultSchema, credentialRecordSchema, verifiableCredentialResponseSchema, credentialIssueResultSchema, credentialListResultSchema, credentialVerifyResultSchema, } from './civic';
|
|
23
|
+
export type { CardTrustTier, PersonhoodStatus, PublicCard, SignedPublicCard, RealLifeAttestationRecord, RealLifeAttestationResult, ValidationVerdict, ValidationRequestStatus, ValidationVerdictRecord, ValidationOpenRequest, ValidationOpenResult, ValidationRequestSummary, ValidationVoteResult, PersonhoodVouchRecord, PersonhoodBreakdown, PersonhoodStatusResult, VouchResult, CredentialStatus, CredentialRecord, VerifiableCredentialResponse, CredentialIssueResult, CredentialListResult, CredentialVerifyResult, } from './civic';
|