@oxyhq/contracts 0.23.0 → 0.25.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,27 @@
1
+ /**
2
+ * The follow graph wire contract (`/v2/follows`).
3
+ *
4
+ * These types are the boundary between the API that owns the graph and every
5
+ * application that reads it. They live here — not in the API and not in the
6
+ * SDK — because both ends have to agree, and a shape defined on one side is a
7
+ * shape the other side re-declares slightly differently within a release or two.
8
+ *
9
+ * ## Why the state is three fields and not a boolean
10
+ *
11
+ * A user can follow something globally and turn it off in ONE application. That
12
+ * is a state the user themselves created, so the client has to be able to see
13
+ * it and say so — "following, but not shown here" is a sentence a boolean
14
+ * cannot express. `globalState`, `applicationMode` and `effectiveState` are
15
+ * therefore reported separately, and only the last one answers "does this
16
+ * appear in my feed right now".
17
+ *
18
+ * ## Why kinds are strings
19
+ *
20
+ * `FollowTargetKind` is a plain `string`, not a union. Applications register
21
+ * their own kinds at runtime (`mercaria.store`, `syra.artist`), so a union here
22
+ * would mean every new application in the ecosystem needs a release of this
23
+ * package before it can follow anything. The namespace rule is enforced by the
24
+ * database, which is the one place that can enforce it for applications this
25
+ * package has never heard of.
26
+ */
27
+ export {};
@@ -1,26 +1,54 @@
1
1
  /**
2
2
  * Oxy-scoped signed-record types.
3
3
  *
4
- * The base `signedRecordEnvelopeSchema` (`./identity`) now treats `type` as an
5
- * OPEN, non-empty string so ANY Oxy app may define its own record categories
6
- * (e.g. `app.mention.*`'s `app_record`) on the shared envelope grammar. The Oxy
7
- * identity/civic/node STORE, however, accepts ONLY the closed set of categories
8
- * it knows how to verify and materialize — this module is that closed set.
4
+ * The base `signedRecordEnvelopeSchema` (`./identity`) treats `type` as an OPEN,
5
+ * non-empty string so ANY Oxy app may sign on the shared envelope grammar. The
6
+ * Oxy STORE re-narrows it to the closed set in this module — a `type` outside it
7
+ * is rejected as `invalid_envelope`.
9
8
  *
10
- * `oxySignedRecordTypeSchema` is the runtime gate the Oxy store re-narrows with
11
- * (the API's `verifyEnvelope` rejects any `type` outside it; the Mongoose
12
- * `SignedRecord.type` enum is derived from `.options`); `OxySignedRecordType` is
13
- * the matching compile-time union the SDK identity/civic mixins type against.
9
+ * `oxySignedRecordTypeSchema` is that runtime gate (the API's `verifyEnvelope`
10
+ * re-narrows with it; the Mongoose `SignedRecord.type` enum and the Postgres
11
+ * CHECK on `signed_records.type` are both derived from `.options`);
12
+ * `OxySignedRecordType` is the matching compile-time union the SDK
13
+ * identity/civic mixins type against.
14
14
  *
15
15
  * The signing input INCLUDES `type`, so this set is part of the signed bytes —
16
- * a record cannot have its category swapped after signing.
16
+ * a record cannot have its category swapped after signing, and a value once
17
+ * signed can never be renamed.
17
18
  *
18
19
  * v1 only ever carried `identity` / `profile` (already in production); v2 added
19
20
  * the civic record types (reputation attestations, real-life / peer validations,
20
21
  * personhood vouches, verifiable credentials) and the user-node registration
21
- * record. Every value here is an Oxy `app.oxy.*` (or legacy v1) category — an
22
- * app's own `type` (e.g. `app_record`) is intentionally NOT in this set and is
23
- * rejected by the Oxy store.
22
+ * record.
23
+ *
24
+ * ## Why `app_record` is here, when it deliberately was not
25
+ *
26
+ * This set used to hold Oxy's own categories only, and said so: an app's `type`
27
+ * was "intentionally NOT in this set". The reason given was that the store
28
+ * accepts only what it knows how to **verify and materialize**. Verification
29
+ * turned out not to argue for the exclusion — the engine verifies a signature
30
+ * against the subject's keys whatever the category says — and materialization
31
+ * is the app's job, not the store's: an app projects its own feed tables from
32
+ * records it reads back.
33
+ *
34
+ * What changed is the decision the exclusion blocked. One chain per PERSON, held
35
+ * by Oxy, is the ecosystem substrate: apps append their records to the subject's
36
+ * one chain instead of each keeping a private chain for the same person. A
37
+ * closed set that admits no app category makes that unrepresentable.
38
+ *
39
+ * `app_record` is ONE value rather than an open lane, and the lexicon lives in
40
+ * the envelope's `collection` (`app.mention.feed.post`, `app.syra.*`), which the
41
+ * store denormalizes to `signed_records.nsid` and indexes. So a new app needs no
42
+ * change here — it picks its own collection namespace and signs `app_record`,
43
+ * exactly as Mention already does in production. Keeping the set closed is what
44
+ * keeps the CHECK a real constraint.
45
+ *
46
+ * **Admitting the category is not the whole of that decision.** Two gates sit
47
+ * beside it and are unchanged: an app record must arrive as a v2 (chained)
48
+ * envelope, and `oxyVerificationResolver` accepts exactly one custodial issuer
49
+ * (`OXY_DID`). So a record a user signs themselves verifies here today, while
50
+ * one an app signs custodially under its OWN issuer DID does not — that needs a
51
+ * separate, deliberate answer about which issuers may write to a person's chain.
24
52
  *
25
53
  * Platform-agnostic — zod only, no react/react-native/expo, ESM-safe.
26
54
  */
@@ -34,4 +62,7 @@ export const oxySignedRecordTypeSchema = z.enum([
34
62
  'personhood_vouch',
35
63
  'credential',
36
64
  'node',
65
+ // Any Oxy app's own record. The LEXICON is the envelope's `collection`, not
66
+ // this value — see the header.
67
+ 'app_record',
37
68
  ]);