@oxyhq/contracts 0.2.1 → 0.3.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/identity.js +135 -0
- package/dist/cjs/index.js +14 -1
- package/dist/cjs/userResponse.js +18 -0
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/identity.js +132 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/userResponse.js +18 -0
- package/dist/types/.tsbuildinfo +1 -1
- package/dist/types/identity.d.ts +244 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/recommendations.d.ts +14 -14
- package/dist/types/userResponse.d.ts +365 -8
- package/package.json +1 -1
|
@@ -0,0 +1,132 @@
|
|
|
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
|
+
export const verificationMethodSchema = z.object({
|
|
42
|
+
id: z.string(),
|
|
43
|
+
type: z.literal('EcdsaSecp256k1VerificationKey2019'),
|
|
44
|
+
controller: z.string(),
|
|
45
|
+
publicKeyHex: z.string(),
|
|
46
|
+
});
|
|
47
|
+
export const didServiceSchema = z.object({
|
|
48
|
+
id: z.string(),
|
|
49
|
+
type: z.string(),
|
|
50
|
+
serviceEndpoint: z.string(),
|
|
51
|
+
});
|
|
52
|
+
export const didDocumentSchema = z.object({
|
|
53
|
+
'@context': z.array(z.string()),
|
|
54
|
+
id: z.string(),
|
|
55
|
+
controller: z.array(z.string()),
|
|
56
|
+
verificationMethod: z.array(verificationMethodSchema),
|
|
57
|
+
authentication: z.array(z.string()),
|
|
58
|
+
assertionMethod: z.array(z.string()),
|
|
59
|
+
alsoKnownAs: z.array(z.string()),
|
|
60
|
+
service: z.array(didServiceSchema),
|
|
61
|
+
});
|
|
62
|
+
export const signedRecordEnvelopeSchema = z.object({
|
|
63
|
+
version: z.literal(1),
|
|
64
|
+
type: z.enum(['identity', 'profile']),
|
|
65
|
+
subject: z.string(),
|
|
66
|
+
issuer: z.string(),
|
|
67
|
+
record: z.record(z.unknown()),
|
|
68
|
+
issuedAt: z.number(),
|
|
69
|
+
publicKey: z.string(),
|
|
70
|
+
alg: z.literal('ES256K-DER-SHA256'),
|
|
71
|
+
signature: z.string(),
|
|
72
|
+
});
|
|
73
|
+
export const verifiedDomainSchema = z.object({
|
|
74
|
+
domain: z.string(),
|
|
75
|
+
verifiedAt: z.union([z.string(), z.date()]),
|
|
76
|
+
method: z.enum(['dns-txt', 'well-known']),
|
|
77
|
+
});
|
|
78
|
+
/** Request body for `POST /identity/domains` — the domain to start verifying. */
|
|
79
|
+
export const domainVerificationRequestSchema = z.object({
|
|
80
|
+
domain: z.string().trim().min(1),
|
|
81
|
+
});
|
|
82
|
+
/**
|
|
83
|
+
* The instructions the API returns when a domain verification is requested. The
|
|
84
|
+
* caller may prove ownership EITHER by publishing the `dns` TXT record OR by
|
|
85
|
+
* serving the `wellKnown` file; either path then satisfies
|
|
86
|
+
* `POST /identity/domains/:domain/verify`.
|
|
87
|
+
*/
|
|
88
|
+
export const domainVerificationInstructionsSchema = z.object({
|
|
89
|
+
domain: z.string(),
|
|
90
|
+
token: z.string(),
|
|
91
|
+
dns: z.object({
|
|
92
|
+
name: z.string(),
|
|
93
|
+
value: z.string(),
|
|
94
|
+
}),
|
|
95
|
+
wellKnown: z.object({
|
|
96
|
+
url: z.string(),
|
|
97
|
+
body: z.string(),
|
|
98
|
+
}),
|
|
99
|
+
});
|
|
100
|
+
export const authMethodEntrySchema = z.object({
|
|
101
|
+
type: z.enum(['identity', 'password', 'google', 'apple', 'github']),
|
|
102
|
+
linkedAt: z.union([z.string(), z.date()]),
|
|
103
|
+
verificationMethodId: z.string().optional(),
|
|
104
|
+
});
|
|
105
|
+
export const authMethodsResponseSchema = z.object({
|
|
106
|
+
did: z.string(),
|
|
107
|
+
methods: z.array(authMethodEntrySchema),
|
|
108
|
+
});
|
|
109
|
+
export const exportAttestationSchema = z.object({
|
|
110
|
+
issuer: z.string(),
|
|
111
|
+
publicKey: z.string(),
|
|
112
|
+
alg: z.literal('ES256K-DER-SHA256'),
|
|
113
|
+
signature: z.string(),
|
|
114
|
+
signedAt: z.number(),
|
|
115
|
+
});
|
|
116
|
+
export const exportBundleSchema = z.object({
|
|
117
|
+
'$schema': z.string(),
|
|
118
|
+
exportedAt: z.string(),
|
|
119
|
+
did: z.string(),
|
|
120
|
+
didDocument: didDocumentSchema,
|
|
121
|
+
profile: z.record(z.unknown()),
|
|
122
|
+
verifiedDomains: z.array(verifiedDomainSchema),
|
|
123
|
+
authMethods: z.array(authMethodEntrySchema),
|
|
124
|
+
signedRecords: z.array(signedRecordEnvelopeSchema),
|
|
125
|
+
appData: z.array(z.record(z.unknown())),
|
|
126
|
+
social: z.object({
|
|
127
|
+
following: z.array(z.string()),
|
|
128
|
+
followers: z.array(z.string()),
|
|
129
|
+
}),
|
|
130
|
+
attestation: exportAttestationSchema.nullable(),
|
|
131
|
+
proof: exportAttestationSchema.optional(),
|
|
132
|
+
});
|
package/dist/esm/index.js
CHANGED
|
@@ -23,3 +23,6 @@ fedcmTokenPayloadSchema, } from './fedcmToken.js';
|
|
|
23
23
|
export {
|
|
24
24
|
// Schemas
|
|
25
25
|
recommendationExcludeTypeSchema, recommendationBoostSchema, recommendationSignalWeightsSchema, recommendationRequestSchema, recommendationCountSchema, recommendationItemSchema, recommendationResponseSchema, appEndorsementInputSchema, appInterestInputSchema, appUserSignalIngestSchema, } from './recommendations.js';
|
|
26
|
+
export {
|
|
27
|
+
// Schemas
|
|
28
|
+
verificationMethodSchema, didServiceSchema, didDocumentSchema, signedRecordEnvelopeSchema, verifiedDomainSchema, domainVerificationRequestSchema, domainVerificationInstructionsSchema, authMethodEntrySchema, authMethodsResponseSchema, exportAttestationSchema, exportBundleSchema, } from './identity.js';
|
package/dist/esm/userResponse.js
CHANGED
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
* `require()`).
|
|
32
32
|
*/
|
|
33
33
|
import { z } from 'zod';
|
|
34
|
+
import { verifiedDomainSchema } from './identity.js';
|
|
34
35
|
export const userNameSchema = z
|
|
35
36
|
.object({
|
|
36
37
|
first: z.string().optional(),
|
|
@@ -63,6 +64,9 @@ export const userResponseSchema = z
|
|
|
63
64
|
publicKey: z.string().optional(),
|
|
64
65
|
username: z.string().optional(),
|
|
65
66
|
email: z.string().optional(),
|
|
67
|
+
phone: z.string().optional(),
|
|
68
|
+
address: z.string().optional(),
|
|
69
|
+
birthday: z.string().optional(),
|
|
66
70
|
/** Avatar file id (string) or null. */
|
|
67
71
|
avatar: z.string().nullable().optional(),
|
|
68
72
|
/** Named Bloom color preset (e.g. `"blue"`) or null. */
|
|
@@ -70,6 +74,17 @@ export const userResponseSchema = z
|
|
|
70
74
|
name: userNameSchema,
|
|
71
75
|
verified: z.boolean().optional(),
|
|
72
76
|
language: z.string().optional(),
|
|
77
|
+
/**
|
|
78
|
+
* The account's self-sovereign identifier
|
|
79
|
+
* (`did:web:<FEDERATION_DOMAIN>:u:<userId>`). Surfaced as a `User`
|
|
80
|
+
* virtual; present on formatted DTOs once the identity layer is live.
|
|
81
|
+
*/
|
|
82
|
+
did: z.string().optional(),
|
|
83
|
+
/**
|
|
84
|
+
* Proven domain-ownership badges. Each is a {@link verifiedDomainSchema}
|
|
85
|
+
* entry; present only when the account has verified at least one domain.
|
|
86
|
+
*/
|
|
87
|
+
verifiedDomains: z.array(verifiedDomainSchema).optional(),
|
|
73
88
|
})
|
|
74
89
|
.passthrough();
|
|
75
90
|
export const userProfileUpdateSchema = z
|
|
@@ -86,6 +101,9 @@ export const userProfileUpdateSchema = z
|
|
|
86
101
|
color: z.string().nullable().optional(),
|
|
87
102
|
bio: z.string().optional(),
|
|
88
103
|
description: z.string().optional(),
|
|
104
|
+
phone: z.string().optional(),
|
|
105
|
+
address: z.string().optional(),
|
|
106
|
+
birthday: z.string().optional(),
|
|
89
107
|
location: z.string().optional(),
|
|
90
108
|
locations: z.array(z.unknown()).optional(),
|
|
91
109
|
links: z.array(z.string()).optional(),
|