@oxyhq/contracts 0.6.0 → 0.8.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.
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deviceSessionSyncSchema = exports.activeTokenSchema = exports.deviceSessionStateSchema = exports.sessionAccountSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ exports.sessionAccountSchema = zod_1.z.object({
6
+ accountId: zod_1.z.string(),
7
+ sessionId: zod_1.z.string(),
8
+ authuser: zod_1.z.number().int().nonnegative(),
9
+ operatedByUserId: zod_1.z.string().optional(),
10
+ });
11
+ exports.deviceSessionStateSchema = zod_1.z.object({
12
+ deviceId: zod_1.z.string(),
13
+ accounts: zod_1.z.array(exports.sessionAccountSchema),
14
+ activeAccountId: zod_1.z.string().nullable(),
15
+ revision: zod_1.z.number().int().nonnegative(),
16
+ updatedAt: zod_1.z.number(),
17
+ });
18
+ exports.activeTokenSchema = zod_1.z.object({
19
+ accessToken: zod_1.z.string(),
20
+ expiresAt: zod_1.z.string(),
21
+ });
22
+ exports.deviceSessionSyncSchema = zod_1.z.object({
23
+ state: exports.deviceSessionStateSchema,
24
+ activeToken: exports.activeTokenSchema.nullable(),
25
+ });
@@ -45,5 +45,12 @@ exports.fedcmTokenPayloadSchema = zod_1.z
45
45
  exp: zod_1.z.number().optional(),
46
46
  iat: zod_1.z.number().optional(),
47
47
  nonce: zod_1.z.string().optional(),
48
+ /**
49
+ * An explicit central deviceId minted by the IdP, threaded through so the
50
+ * RP session can inherit a unified device id instead of deriving one from
51
+ * the (userId, RP origin) stableDeviceKey. Optional and additive — omitted
52
+ * tokens fall back to the existing stableDeviceKey/UA-IP derivation.
53
+ */
54
+ deviceId: zod_1.z.string().optional(),
48
55
  })
49
56
  .passthrough();
@@ -41,12 +41,27 @@
41
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
42
  exports.exportBundleSchema = exports.exportAttestationSchema = exports.authMethodsResponseSchema = exports.authMethodEntrySchema = exports.domainVerificationInstructionsSchema = exports.domainVerificationRequestSchema = exports.verifiedDomainSchema = exports.signedRecordEnvelopeSchema = exports.didDocumentSchema = exports.didServiceSchema = exports.verificationMethodSchema = void 0;
43
43
  const zod_1 = require("zod");
44
- exports.verificationMethodSchema = zod_1.z.object({
44
+ // The option schemas are left UN-annotated so they keep their concrete
45
+ // `ZodObject` type — `z.discriminatedUnion` requires object options and an
46
+ // explicit `z.ZodType<>` annotation would erase the shape it discriminates on.
47
+ // `z.object` already infers each option's type exactly (id/type/controller +
48
+ // the key field), so the union is structurally `VerificationMethod`.
49
+ const secp256k1VerificationMethodSchema = zod_1.z.object({
45
50
  id: zod_1.z.string(),
46
51
  type: zod_1.z.literal('EcdsaSecp256k1VerificationKey2019'),
47
52
  controller: zod_1.z.string(),
48
53
  publicKeyHex: zod_1.z.string(),
49
54
  });
55
+ const multikeyVerificationMethodSchema = zod_1.z.object({
56
+ id: zod_1.z.string(),
57
+ type: zod_1.z.literal('Multikey'),
58
+ controller: zod_1.z.string(),
59
+ publicKeyMultibase: zod_1.z.string(),
60
+ });
61
+ exports.verificationMethodSchema = zod_1.z.discriminatedUnion('type', [
62
+ secp256k1VerificationMethodSchema,
63
+ multikeyVerificationMethodSchema,
64
+ ]);
50
65
  exports.didServiceSchema = zod_1.z.object({
51
66
  id: zod_1.z.string(),
52
67
  type: zod_1.z.string(),
@@ -65,16 +80,9 @@ exports.didDocumentSchema = zod_1.z.object({
65
80
  exports.signedRecordEnvelopeSchema = zod_1.z
66
81
  .object({
67
82
  version: zod_1.z.union([zod_1.z.literal(1), zod_1.z.literal(2)]),
68
- type: zod_1.z.enum([
69
- 'identity',
70
- 'profile',
71
- 'reputation_attestation',
72
- 'real_life_attestation',
73
- 'validation_verdict',
74
- 'personhood_vouch',
75
- 'credential',
76
- 'node',
77
- ]),
83
+ // Open, app-defined category (see the `type` doc above). The Oxy STORE
84
+ // re-narrows to `oxySignedRecordTypeSchema`; an app to its own constant.
85
+ type: zod_1.z.string().min(1),
78
86
  subject: zod_1.z.string(),
79
87
  issuer: zod_1.z.string(),
80
88
  record: zod_1.z.record(zod_1.z.unknown()),
package/dist/cjs/index.js CHANGED
@@ -11,8 +11,8 @@
11
11
  * expo, no `require()` in the ESM build.
12
12
  */
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.verifiableCredentialResponseSchema = exports.credentialRecordSchema = exports.vouchResultSchema = exports.personhoodStatusResultSchema = exports.personhoodBreakdownSchema = exports.personhoodVouchRecordSchema = exports.validationVoteResultSchema = exports.validationRequestSummarySchema = exports.validationOpenResultSchema = exports.validationOpenRequestSchema = exports.validationVerdictRecordSchema = exports.realLifeAttestationResultSchema = exports.realLifeAttestationRecordSchema = exports.signedPublicCardSchema = exports.publicCardSchema = exports.exportBundleSchema = exports.exportAttestationSchema = exports.authMethodsResponseSchema = exports.authMethodEntrySchema = exports.domainVerificationInstructionsSchema = exports.domainVerificationRequestSchema = exports.verifiedDomainSchema = exports.signedRecordEnvelopeSchema = exports.didDocumentSchema = exports.didServiceSchema = exports.verificationMethodSchema = exports.appUserSignalIngestSchema = exports.appInterestInputSchema = exports.appEndorsementInputSchema = exports.recommendationResponseSchema = exports.recommendationItemSchema = exports.recommendationCountSchema = exports.recommendationRequestSchema = exports.recommendationSignalWeightsSchema = exports.recommendationBoostSchema = exports.recommendationExcludeTypeSchema = exports.fedcmTokenPayloadSchema = exports.sessionStatusSchema = exports.publicApplicationSchema = exports.applicationTypeSchema = exports.safeParseContract = exports.resolveUserId = exports.deviceSessionsResponseSchema = exports.deviceSessionAccountSchema = exports.currentUserResponseSchema = exports.refreshAllResponseSchema = exports.refreshAllAccountSchema = exports.userProfileUpdateSchema = exports.userResponseSchema = exports.userNameSchema = void 0;
15
- exports.linkPreviewResponseSchema = exports.linkPreviewBatchResponseSchema = exports.linkPreviewBatchRequestSchema = exports.linkPreviewSchema = exports.credentialVerifyResultSchema = exports.credentialListResultSchema = exports.credentialIssueResultSchema = void 0;
14
+ exports.personhoodStatusResultSchema = exports.personhoodBreakdownSchema = exports.personhoodVouchRecordSchema = exports.validationVoteResultSchema = exports.validationRequestSummarySchema = exports.validationOpenResultSchema = exports.validationOpenRequestSchema = exports.validationVerdictRecordSchema = exports.realLifeAttestationResultSchema = exports.realLifeAttestationRecordSchema = exports.signedPublicCardSchema = exports.publicCardSchema = exports.logPageResponseSchema = exports.chainHeadResponseSchema = exports.oxySignedRecordTypeSchema = exports.exportBundleSchema = exports.exportAttestationSchema = exports.authMethodsResponseSchema = exports.authMethodEntrySchema = exports.domainVerificationInstructionsSchema = exports.domainVerificationRequestSchema = exports.verifiedDomainSchema = exports.signedRecordEnvelopeSchema = exports.didDocumentSchema = exports.didServiceSchema = exports.verificationMethodSchema = exports.appUserSignalIngestSchema = exports.appInterestInputSchema = exports.appEndorsementInputSchema = exports.recommendationResponseSchema = exports.recommendationItemSchema = exports.recommendationCountSchema = exports.recommendationRequestSchema = exports.recommendationSignalWeightsSchema = exports.recommendationBoostSchema = exports.recommendationExcludeTypeSchema = exports.fedcmTokenPayloadSchema = exports.sessionStatusSchema = exports.publicApplicationSchema = exports.applicationTypeSchema = exports.safeParseContract = exports.resolveUserId = exports.deviceSessionsResponseSchema = exports.deviceSessionAccountSchema = exports.currentUserResponseSchema = exports.refreshAllResponseSchema = exports.refreshAllAccountSchema = exports.userProfileUpdateSchema = exports.userResponseSchema = exports.userNameSchema = void 0;
15
+ exports.deviceSessionSyncSchema = exports.activeTokenSchema = exports.deviceSessionStateSchema = exports.sessionAccountSchema = exports.linkPreviewResponseSchema = exports.linkPreviewBatchResponseSchema = exports.linkPreviewBatchRequestSchema = exports.linkPreviewSchema = exports.credentialVerifyResultSchema = exports.credentialListResultSchema = exports.credentialIssueResultSchema = exports.verifiableCredentialResponseSchema = exports.credentialRecordSchema = exports.vouchResultSchema = void 0;
16
16
  var userResponse_1 = require("./userResponse");
17
17
  // Schemas
18
18
  Object.defineProperty(exports, "userNameSchema", { enumerable: true, get: function () { return userResponse_1.userNameSchema; } });
@@ -59,6 +59,13 @@ Object.defineProperty(exports, "authMethodEntrySchema", { enumerable: true, get:
59
59
  Object.defineProperty(exports, "authMethodsResponseSchema", { enumerable: true, get: function () { return identity_1.authMethodsResponseSchema; } });
60
60
  Object.defineProperty(exports, "exportAttestationSchema", { enumerable: true, get: function () { return identity_1.exportAttestationSchema; } });
61
61
  Object.defineProperty(exports, "exportBundleSchema", { enumerable: true, get: function () { return identity_1.exportBundleSchema; } });
62
+ var oxyRecordTypes_1 = require("./oxyRecordTypes");
63
+ // Schemas
64
+ Object.defineProperty(exports, "oxySignedRecordTypeSchema", { enumerable: true, get: function () { return oxyRecordTypes_1.oxySignedRecordTypeSchema; } });
65
+ var protocol_1 = require("./protocol");
66
+ // Schemas
67
+ Object.defineProperty(exports, "chainHeadResponseSchema", { enumerable: true, get: function () { return protocol_1.chainHeadResponseSchema; } });
68
+ Object.defineProperty(exports, "logPageResponseSchema", { enumerable: true, get: function () { return protocol_1.logPageResponseSchema; } });
62
69
  var civic_1 = require("./civic");
63
70
  // Schemas
64
71
  Object.defineProperty(exports, "publicCardSchema", { enumerable: true, get: function () { return civic_1.publicCardSchema; } });
@@ -86,3 +93,8 @@ Object.defineProperty(exports, "linkPreviewSchema", { enumerable: true, get: fun
86
93
  Object.defineProperty(exports, "linkPreviewBatchRequestSchema", { enumerable: true, get: function () { return links_1.linkPreviewBatchRequestSchema; } });
87
94
  Object.defineProperty(exports, "linkPreviewBatchResponseSchema", { enumerable: true, get: function () { return links_1.linkPreviewBatchResponseSchema; } });
88
95
  Object.defineProperty(exports, "linkPreviewResponseSchema", { enumerable: true, get: function () { return links_1.linkPreviewResponseSchema; } });
96
+ var deviceSession_1 = require("./deviceSession");
97
+ Object.defineProperty(exports, "sessionAccountSchema", { enumerable: true, get: function () { return deviceSession_1.sessionAccountSchema; } });
98
+ Object.defineProperty(exports, "deviceSessionStateSchema", { enumerable: true, get: function () { return deviceSession_1.deviceSessionStateSchema; } });
99
+ Object.defineProperty(exports, "activeTokenSchema", { enumerable: true, get: function () { return deviceSession_1.activeTokenSchema; } });
100
+ Object.defineProperty(exports, "deviceSessionSyncSchema", { enumerable: true, get: function () { return deviceSession_1.deviceSessionSyncSchema; } });
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ /**
3
+ * Oxy-scoped signed-record types.
4
+ *
5
+ * The base `signedRecordEnvelopeSchema` (`./identity`) now treats `type` as an
6
+ * OPEN, non-empty string so ANY Oxy app may define its own record categories
7
+ * (e.g. `app.mention.*`'s `app_record`) on the shared envelope grammar. The Oxy
8
+ * identity/civic/node STORE, however, accepts ONLY the closed set of categories
9
+ * it knows how to verify and materialize — this module is that closed set.
10
+ *
11
+ * `oxySignedRecordTypeSchema` is the runtime gate the Oxy store re-narrows with
12
+ * (the API's `verifyEnvelope` rejects any `type` outside it; the Mongoose
13
+ * `SignedRecord.type` enum is derived from `.options`); `OxySignedRecordType` is
14
+ * the matching compile-time union the SDK identity/civic mixins type against.
15
+ *
16
+ * The signing input INCLUDES `type`, so this set is part of the signed bytes —
17
+ * a record cannot have its category swapped after signing.
18
+ *
19
+ * v1 only ever carried `identity` / `profile` (already in production); v2 added
20
+ * the civic record types (reputation attestations, real-life / peer validations,
21
+ * personhood vouches, verifiable credentials) and the user-node registration
22
+ * record. Every value here is an Oxy `app.oxy.*` (or legacy v1) category — an
23
+ * app's own `type` (e.g. `app_record`) is intentionally NOT in this set and is
24
+ * rejected by the Oxy store.
25
+ *
26
+ * Platform-agnostic — zod only, no react/react-native/expo, ESM-safe.
27
+ */
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.oxySignedRecordTypeSchema = void 0;
30
+ const zod_1 = require("zod");
31
+ exports.oxySignedRecordTypeSchema = zod_1.z.enum([
32
+ 'identity',
33
+ 'profile',
34
+ 'reputation_attestation',
35
+ 'real_life_attestation',
36
+ 'validation_verdict',
37
+ 'personhood_vouch',
38
+ 'credential',
39
+ 'node',
40
+ ]);
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ /**
3
+ * Generic "Oxy Protocol" record surface — the app-agnostic conventions every app
4
+ * follows to decentralize its own content on the shared signed-record substrate.
5
+ *
6
+ * The base `signedRecordEnvelopeSchema` (`./identity`) is the WIRE grammar: a
7
+ * signed envelope whose `type` is an open string and whose `record` is an opaque
8
+ * `Record<string, unknown>`. An app layers its own LEXICON on top of that
9
+ * grammar — a typed projection of the `record` payload, addressed by an
10
+ * AtProto-style `(collection, rkey)` key — WITHOUT forking the envelope schema.
11
+ *
12
+ * ## Recipe — defining an app lexicon record
13
+ *
14
+ * For each record kind an app wants to publish:
15
+ *
16
+ * 1. Define the `record` PAYLOAD schema as a `z.ZodType<XPayload>` (e.g.
17
+ * `app.mention.feed.post` → `mentionPostRecordSchema: z.ZodType<MentionPost>`).
18
+ * This validates ONLY the inner `record`, not the envelope.
19
+ * 2. Declare the `collection` NSID as a constant (e.g.
20
+ * `export const MENTION_POST_COLLECTION = 'app.mention.feed.post'`).
21
+ * 3. Reuse the UNCHANGED {@link signedRecordEnvelopeSchema} for the envelope. The
22
+ * base treats `record` as `z.record(z.unknown())`, so the app validates the
23
+ * envelope with the base schema first, then parses `envelope.record` with its
24
+ * own payload schema. {@link LexiconRecord} is the typed projection that pairs
25
+ * the `(collection, rkey)` key with the parsed payload.
26
+ *
27
+ * The Oxy civic contracts (`./civic`) already follow this convention implicitly:
28
+ * each civic record (`real_life_attestation`, `personhood_vouch`, `credential`,
29
+ * …) ships a `record`-payload schema and is carried by the base envelope.
30
+ *
31
+ * ## Chain-wire shapes
32
+ *
33
+ * {@link ChainHeadResponse} and {@link LogPageResponse} are the shared response
34
+ * shapes every chain store exposes (Oxy's `GET /identity/records/:userId/chain/head`,
35
+ * `GET /identity/head/:userId`, `GET /identity/log/:userId`, and any app node's
36
+ * equivalents). They are defined ONCE here so producers and consumers (the API
37
+ * handlers, the SDK identity/nodes mixins, app nodes) cannot drift.
38
+ *
39
+ * Platform-agnostic — zod only, no react/react-native/expo, ESM-safe.
40
+ */
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.logPageResponseSchema = exports.chainHeadResponseSchema = void 0;
43
+ const zod_1 = require("zod");
44
+ const identity_1 = require("./identity");
45
+ exports.chainHeadResponseSchema = zod_1.z.object({
46
+ headRecordId: zod_1.z.string().nullable(),
47
+ seq: zod_1.z.number().int(),
48
+ recordCount: zod_1.z.number().int().nonnegative(),
49
+ });
50
+ exports.logPageResponseSchema = zod_1.z.object({
51
+ records: zod_1.z.array(identity_1.signedRecordEnvelopeSchema),
52
+ count: zod_1.z.number().int().nonnegative(),
53
+ });