@proveanything/smartlinks 1.15.16 → 1.15.18

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.
@@ -250,6 +250,12 @@ export interface CreateThreadInput {
250
250
  data?: Record<string, unknown>;
251
251
  owner?: Record<string, unknown>;
252
252
  admin?: Record<string, unknown>;
253
+ /**
254
+ * Optional atomic first reply. Posting a comment no longer needs a separate
255
+ * create-thread-then-reply round trip (which could orphan an empty thread on
256
+ * partial failure). The reply is stored with a generated `id` and timestamp.
257
+ */
258
+ firstReply?: ReplyInput;
253
259
  }
254
260
  /**
255
261
  * Input for updating a thread
@@ -279,8 +285,16 @@ export interface ReplyInput {
279
285
  export interface ThreadListQueryParams extends ListQueryParams {
280
286
  slug?: string;
281
287
  authorId?: string;
288
+ /** Disambiguates the parent entity kind (e.g. "memory", "case", "proof"). */
282
289
  parentType?: string;
290
+ /** Anchor to a single app entity id (text — SmartLinks short ids, not UUIDs). */
283
291
  parentId?: string;
292
+ /** Batch-fetch threads for many app entities in one call (e.g. a memory feed). */
293
+ parentIds?: string[];
294
+ /** Anchor threads to a proof. For grant-token callers this is the enforced filter. */
295
+ proofId?: string;
296
+ /** Anchor threads to a product (one tier up from proof). */
297
+ productId?: string;
284
298
  tag?: string;
285
299
  contactId?: string;
286
300
  }
@@ -37,6 +37,11 @@ export type LinkTarget = {
37
37
  kind: 'app';
38
38
  /** The target app's `appId`. */
39
39
  appId: string;
40
+ /**
41
+ * App-specific query params (e.g. `{ proofId, shareToken }` for a share link).
42
+ * Platform context params are injected automatically.
43
+ */
44
+ params?: Record<string, string>;
40
45
  target?: LinkOpenTarget;
41
46
  } | {
42
47
  kind: 'deep';
@@ -65,3 +65,58 @@ export type ProofFieldDef = ScopedFieldDef & {
65
65
  export interface ProofFieldsConfig {
66
66
  fields: ProofFieldDef[];
67
67
  }
68
+ /** What a grant authorises the bearer to do on the proof. */
69
+ export type GrantScope = 'read' | 'comment' | 'admin' | 'verify_owner';
70
+ /** Who may redeem a grant. */
71
+ export interface GrantAudience {
72
+ kind: 'public_link' | 'named';
73
+ email?: string;
74
+ userId?: string;
75
+ }
76
+ /** A share grant issued on a proof. */
77
+ export interface ProofGrant {
78
+ grantId: string;
79
+ proofId: string;
80
+ productId?: string | null;
81
+ scope: GrantScope[];
82
+ audience: GrantAudience;
83
+ createdBy: string;
84
+ expiresAt?: string | null;
85
+ revokedAt?: string | null;
86
+ redeemedBy?: {
87
+ userId?: string;
88
+ guestName?: string;
89
+ redeemedAt: string;
90
+ };
91
+ redeemCount: number;
92
+ createdAt: string;
93
+ updatedAt: string;
94
+ /** The opaque bearer token — present ONLY on the `createGrant` response, never on `listGrants`. */
95
+ token?: string;
96
+ }
97
+ export interface CreateGrantOptions {
98
+ /** At least one scope is required. */
99
+ scope: GrantScope[];
100
+ /** Defaults to `{ kind: 'public_link' }`. */
101
+ audience?: GrantAudience;
102
+ /** Optional expiry — a `Date` or ISO string. */
103
+ expiresAt?: Date | string;
104
+ }
105
+ export interface RedeemGrantOptions {
106
+ /** Display name to stamp on guest activity when the redeemer is not signed in. */
107
+ guestName?: string;
108
+ }
109
+ /**
110
+ * Result of redeeming a grant. For read/comment/admin grants this is the granted
111
+ * scope; for a `verify_owner` grant it is an ownership assertion (never the account).
112
+ */
113
+ export type RedeemGrantResult = {
114
+ scope: GrantScope[];
115
+ redeemedAt: string;
116
+ } | {
117
+ proofId: string;
118
+ assertsOwnership: true;
119
+ ownerDisplayName?: string;
120
+ issuedAt?: string;
121
+ expiresAt?: string;
122
+ };
@@ -1,6 +1,6 @@
1
1
  # Smartlinks API Summary
2
2
 
3
- Version: 1.15.16 | Generated: 2026-08-15T11:42:50.997Z
3
+ Version: 1.15.18 | Generated: 2026-08-19T06:40:47.505Z
4
4
 
5
5
  This is a concise summary of all available API functions and types.
6
6
 
@@ -170,6 +170,12 @@ Replace or augment globally applied custom headers.
170
170
  **setBearerToken**(token: string | undefined) → `void`
171
171
  Allows setting the bearerToken at runtime (e.g. after login/logout). Clears the HTTP cache whenever the token actually changes so that stale user-scoped responses (e.g. /account/profile) are not served after a login or logout event.
172
172
 
173
+ **setGrantToken**(token: string | undefined) → `void`
174
+ Set (or clear) the per-proof share-grant token. When set, it is attached as the `X-Grant-Token` header on every request, so a recipient who has opened a shared link can read/comment on the granted proof's data. Pass `undefined` to clear it. The server re-checks the grant against the database on every request, so calling `revokeGrant` invalidates an in-flight token immediately. Clears the GET cache on change so grant-tier responses are not served after the token changes. ```ts // On opening ?proofId=…&shareToken=abc setGrantToken(shareToken) const { attestations } = await proof.get(...) // now sees owner-tier memories ```
175
+
176
+ **getGrantToken**() → `string | undefined`
177
+ Returns the currently-set share-grant token, or `undefined`.
178
+
173
179
  **getBearerToken**() → `string | undefined`
174
180
  Returns the bearer token currently held by the SDK, or `undefined` if none is set. In proxy mode, credentials are held by the parent frame, not the local SDK, so this returns `undefined` even when the caller is authenticated.
175
181
 
@@ -1987,6 +1993,10 @@ interface CreateThreadInput {
1987
1993
  data?: Record<string, unknown>
1988
1994
  owner?: Record<string, unknown>
1989
1995
  admin?: Record<string, unknown> // admin only
1996
+ * Optional atomic first reply. Posting a comment no longer needs a separate
1997
+ * create-thread-then-reply round trip (which could orphan an empty thread on
1998
+ * partial failure). The reply is stored with a generated `id` and timestamp.
1999
+ firstReply?: ReplyInput
1990
2000
  }
1991
2001
  ```
1992
2002
 
@@ -7287,6 +7297,50 @@ interface ProofFieldsConfig {
7287
7297
  }
7288
7298
  ```
7289
7299
 
7300
+ **GrantAudience** (interface)
7301
+ ```typescript
7302
+ interface GrantAudience {
7303
+ kind: 'public_link' | 'named'
7304
+ email?: string
7305
+ userId?: string
7306
+ }
7307
+ ```
7308
+
7309
+ **ProofGrant** (interface)
7310
+ ```typescript
7311
+ interface ProofGrant {
7312
+ grantId: string
7313
+ proofId: string
7314
+ productId?: string | null
7315
+ scope: GrantScope[]
7316
+ audience: GrantAudience
7317
+ createdBy: string
7318
+ expiresAt?: string | null
7319
+ revokedAt?: string | null
7320
+ redeemedBy?: { userId?: string; guestName?: string; redeemedAt: string }
7321
+ redeemCount: number
7322
+ createdAt: string
7323
+ updatedAt: string
7324
+ token?: string
7325
+ }
7326
+ ```
7327
+
7328
+ **CreateGrantOptions** (interface)
7329
+ ```typescript
7330
+ interface CreateGrantOptions {
7331
+ scope: GrantScope[]
7332
+ audience?: GrantAudience
7333
+ expiresAt?: Date | string
7334
+ }
7335
+ ```
7336
+
7337
+ **RedeemGrantOptions** (interface)
7338
+ ```typescript
7339
+ interface RedeemGrantOptions {
7340
+ guestName?: string
7341
+ }
7342
+ ```
7343
+
7290
7344
  **ProofResponse** = `Proof`
7291
7345
 
7292
7346
  **ProofUpdateRequest** = `Partial<ProofCreateRequest>`
@@ -7297,6 +7351,10 @@ interface ProofFieldsConfig {
7297
7351
 
7298
7352
  **ProofFieldDef** = `ScopedFieldDef & { scope?: ProofFieldScope }`
7299
7353
 
7354
+ **GrantScope** = `'read' | 'comment' | 'admin' | 'verify_owner'`
7355
+
7356
+ **RedeemGrantResult** = ``
7357
+
7300
7358
  ### qr
7301
7359
 
7302
7360
  **QrShortCodeLookupResponse** (interface)
@@ -8381,6 +8439,13 @@ Soft delete a thread DELETE /threads/:threadId
8381
8439
  admin: boolean = false) → `Promise<AppThread>`
8382
8440
  Add a reply to a thread POST /threads/:threadId/reply Atomically appends to replies array, increments replyCount, updates lastReplyAt
8383
8441
 
8442
+ **deleteReply**(collectionId: string,
8443
+ appId: string,
8444
+ threadId: string,
8445
+ replyId: string,
8446
+ admin: boolean = false) → `Promise<AppThread>`
8447
+ Delete a single reply from a thread by its reply id (moderation). DELETE /threads/:threadId/reply/:replyId Authorised for the reply's author, the proof owner, or a collection admin.
8448
+
8384
8449
  **aggregate**(collectionId: string,
8385
8450
  appId: string,
8386
8451
  request: AggregateRequest,
@@ -9937,6 +10002,30 @@ Get proofs for a batch (admin only). GET /admin/collection/:collectionId/product
9937
10002
  data: { targetProductId: string }) → `Promise<ProofResponse>`
9938
10003
  Migrate a proof to a different product within the same collection (admin only). Because the Firestore ledger document ID is `{productId}-{proofId}`, a proof cannot simply be re-assigned to another product by updating a field — the document must be re-keyed. This endpoint handles that atomically: 1. Reads the source ledger document (`{sourceProductId}-{proofId}`). 2. Writes a new document (`{targetProductId}-{proofId}`) with `productId` and `proofGroup` updated. The short `proofId` (nanoid) is unchanged. 3. Writes a migration history entry to the new document's `history` subcollection (snapshot of the original proof + migration metadata). 4. Copies all subcollections — `assets`, `attestations`, `history` — from the old document to the new one. 5. Deletes the old subcollections and then the old document. Repeated migrations are safe — each one appends a history record; no migration metadata is stored on the proof document itself. ```typescript const migrated = await proof.migrate('coll_123', 'prod_old', 'proof_abc', { targetProductId: 'prod_new', }) console.log(migrated.productId) // 'prod_new' ```
9939
10004
 
10005
+ **createGrant**(collectionId: string,
10006
+ productId: string,
10007
+ proofId: string,
10008
+ options: CreateGrantOptions) → `Promise<ProofGrant>`
10009
+ Create a share grant on a proof (owner / collection admin only). The returned grant includes `token` — the opaque bearer secret, available ONLY on this response. Embed it in a share link and hand recipients {@link redeemGrant} / {@link setGrantToken}.
10010
+
10011
+ **listGrants**(collectionId: string,
10012
+ productId: string,
10013
+ proofId: string) → `Promise<ProofGrant[]>`
10014
+ List the active + past grants on a proof (owner / collection admin only). Tokens are never returned here.
10015
+
10016
+ **revokeGrant**(collectionId: string,
10017
+ productId: string,
10018
+ proofId: string,
10019
+ grantId: string) → `Promise<void>`
10020
+ Revoke a grant by id (owner / collection admin only). Takes effect immediately.
10021
+
10022
+ **redeemGrant**(collectionId: string,
10023
+ productId: string,
10024
+ proofId: string,
10025
+ token: string,
10026
+ options?: RedeemGrantOptions) → `Promise<RedeemGrantResult>`
10027
+ Redeem a grant token (anonymous or signed-in). Records the redemption and returns the granted scope, or — for a `verify_owner` grant — an ownership assertion (never the account). After redeeming, call {@link setGrantToken} so subsequent data requests carry the token.
10028
+
9940
10029
  ### publicClient
9941
10030
 
9942
10031
  **chat**(collectionId: string,
@@ -429,6 +429,71 @@ const productComments = await app.threads.list(collectionId, appId, {
429
429
  });
430
430
  ```
431
431
 
432
+ ### Anchoring to app entities and proofs
433
+
434
+ Anchor a thread to your own entity with `parentType` + `parentId`. `parentId` is a
435
+ free-form string (SmartLinks short ids, not just UUIDs), so you can use your app's
436
+ native ids directly — no need to stash them in `body` or a tag.
437
+
438
+ ```typescript
439
+ await app.threads.create(collectionId, appId, {
440
+ parentType: 'memory',
441
+ parentId: memoryId, // e.g. "dVdthBQLAjQEnitU7aWy" — text, not a UUID
442
+ proofId, // anchor to a proof (enables grant-tier reads)
443
+ body: { text: 'Lovely photo' },
444
+ });
445
+ ```
446
+
447
+ List filters that pair with this (see `ThreadListQueryParams`):
448
+
449
+ | Param | Purpose |
450
+ |-------|---------|
451
+ | `parentType` / `parentId` | one app entity's threads |
452
+ | `parentIds` | **batch** — every thread for many entities in one call (e.g. a feed) |
453
+ | `proofId` / `productId` | threads anchored to a proof / product |
454
+
455
+ ```typescript
456
+ // One request for the 30 memories currently on screen:
457
+ const feed = await app.threads.list(collectionId, appId, {
458
+ parentType: 'memory',
459
+ parentIds: visibleMemoryIds,
460
+ sort: 'createdAt:desc',
461
+ });
462
+ ```
463
+
464
+ ### Atomic first comment (`firstReply`)
465
+
466
+ Posting the first comment no longer needs a create-thread-then-reply two-step (which
467
+ could leave an orphan empty thread if the reply failed). Pass `firstReply` to create
468
+ the thread and its first reply in one atomic call:
469
+
470
+ ```typescript
471
+ await app.threads.create(collectionId, appId, {
472
+ parentType: 'memory', parentId: memoryId, proofId,
473
+ firstReply: { text: 'Lovely photo', authorName: 'Sam' },
474
+ });
475
+ ```
476
+
477
+ ### Deleting a reply (moderation)
478
+
479
+ Replies carry a stable `id`. Remove a single one — authorised for the reply's author,
480
+ the proof owner, or a collection admin:
481
+
482
+ ```typescript
483
+ await app.threads.deleteReply(collectionId, appId, threadId, replyId);
484
+ ```
485
+
486
+ ### Grant-tier access (private, shareable comments)
487
+
488
+ A comment thread on a shared album should be `visibility: 'owner'` (private to the
489
+ proof), with access coming from a **share grant** rather than opening the data to the
490
+ world. A holder of an active `read`/`comment` grant on the proof is treated as
491
+ owner-tier **for that proof only**. Enable it with the `publicCreate.threads.grant`
492
+ policy branch and carry the token via `setGrantToken`.
493
+
494
+ See **[Proof Share Grants](proof-share-grants.md)** for the full flow (create/redeem
495
+ grants, guest commenting, revocation, and the app config).
496
+
432
497
  ---
433
498
 
434
499
  ## Records
package/docs/assets.md CHANGED
@@ -243,6 +243,87 @@ await Api.asset.bulkDelete({
243
243
 
244
244
  ---
245
245
 
246
+ ## Resumable uploads (large files, e.g. video)
247
+
248
+ `asset.upload()` is a single request — if the connection drops, the whole file
249
+ restarts. For large files on flaky connections (e.g. phone video), use a
250
+ **resumable** upload: the file is chunked directly to storage and can be paused,
251
+ resumed, and — crucially — **continued after a page reload or app restart**.
252
+
253
+ ```typescript
254
+ import { asset } from '@proveanything/smartlinks'
255
+
256
+ // 1. Open a resumable upload.
257
+ const handle = await asset.createResumableUpload({
258
+ file, // a File (input[type=file] / drag-drop)
259
+ scope: { type: 'proof', collectionId, productId, proofId },
260
+ appId: 'photo-memory',
261
+ // token: uploadToken, // for public/token uploads (see below)
262
+ })
263
+
264
+ // 2. Persist handle.id so the upload survives a reload.
265
+ localStorage.setItem('pendingUpload', handle.id)
266
+
267
+ // 3. Upload. Resumes automatically from the offset storage already holds.
268
+ const uploaded = await handle.start({
269
+ onProgress: (pct) => setProgress(pct), // 0–100
270
+ signal: abortController.signal, // optional: cancel a stalled upload
271
+ })
272
+ localStorage.removeItem('pendingUpload')
273
+ ```
274
+
275
+ ### Pause / resume, and resume after a reload
276
+
277
+ ```typescript
278
+ handle.pause() // stop after the current chunk
279
+ await handle.resume({ onProgress }) // continue
280
+
281
+ // After a reload / app kill — rehydrate from the persisted id and the same file:
282
+ const saved = localStorage.getItem('pendingUpload')
283
+ if (saved) {
284
+ const handle = await asset.resumeUpload(saved, file)
285
+ await handle.start({ onProgress }) // continues, does not restart
286
+ }
287
+ ```
288
+
289
+ ### API
290
+
291
+ ```typescript
292
+ namespace asset {
293
+ createResumableUpload(options: CreateResumableUploadOptions): Promise<ResumableUploadHandle>
294
+ resumeUpload(handleId: string, file: File): Promise<ResumableUploadHandle>
295
+ }
296
+
297
+ interface CreateResumableUploadOptions {
298
+ file: File
299
+ scope: { type: 'collection'; collectionId: string }
300
+ | { type: 'product'; collectionId: string; productId: string }
301
+ | { type: 'proof'; collectionId: string; productId: string; proofId: string }
302
+ name?: string
303
+ metadata?: Record<string, any>
304
+ appId?: string
305
+ admin?: boolean // admin route (default is the public route)
306
+ token?: string // upload token for public/unauthenticated uploads
307
+ }
308
+
309
+ interface ResumableUploadHandle {
310
+ readonly id: string // durable, persistable — pass to resumeUpload() after a reload
311
+ readonly size: number // total bytes
312
+ start(opts?: { onProgress?: (pct: number) => void; signal?: AbortSignal }): Promise<Asset>
313
+ pause(): void
314
+ resume(opts?: { onProgress?: (pct: number) => void; signal?: AbortSignal }): Promise<Asset>
315
+ }
316
+ ```
317
+
318
+ **Notes**
319
+
320
+ - `handle.id` is an opaque string that carries everything needed to resume — persist it as-is.
321
+ - On completion, `start()`/`resume()` resolves to the finalized `Asset` record.
322
+ - `pause()` causes the in-flight `start()`/`resume()` promise to reject with an `UploadPausedError`; call `resume()` to continue.
323
+ - `asset.upload()` also now accepts an `AbortSignal` (`upload({ ..., signal })`) for cancelling a stalled single-shot upload.
324
+
325
+ ---
326
+
246
327
  ## Public (token-based) uploads
247
328
 
248
329
  For anonymous or contact-initiated uploads from the portal — no admin auth required.
@@ -0,0 +1,232 @@
1
+ # Proof Share Grants
2
+
3
+ Delegated, scoped, **revocable** bearer access to a single proof — the middle tier
4
+ between "public" (everyone) and "owner" (only the signed-in owner).
5
+
6
+ A grant lets an owner hand out a link that lets specific recipients **see or do
7
+ specific things on one proof for a limited time**, without those recipients needing
8
+ a SmartLinks account or a proof claim. Typical uses: sharing a private photo album,
9
+ letting guests comment on it, or publishing a verifiable "I own this" assertion.
10
+
11
+ ---
12
+
13
+ ## Concepts
14
+
15
+ A **grant** is a row issued by the proof owner (or a collection admin) and redeemed
16
+ by a bearer holding an opaque token. Every data request that touches the proof
17
+ re-checks the grant **server-side** against the database, so revocation is immediate.
18
+
19
+ ### Scopes — what a grant authorises
20
+
21
+ | Scope | Grants the bearer… |
22
+ |-------|--------------------|
23
+ | `read` | read owner-tier data on the proof (attestations, threads, records, cases) |
24
+ | `comment` | create threads/replies on the proof (guest comments) |
25
+ | `admin` | read owner-tier data (reserved for elevated share cases; never exposes the platform admin zone) |
26
+ | `verify_owner` | redeem a shareable ownership **assertion** (not the account) |
27
+
28
+ A grant can carry several scopes, e.g. `['read', 'comment']` for a shareable,
29
+ commentable album.
30
+
31
+ ### Security & lifecycle
32
+
33
+ - The token is opaque, unguessable, and returned to the issuer **exactly once** (on `createGrant`). It is never returned by `listGrants`.
34
+ - **Revocation is immediate** — the grant is re-checked on every request, so `revokeGrant` invalidates a token across all clients at once.
35
+ - **Auto-invalidation on transfer** — every grant is voided the moment the proof's `ownerId` changes (e.g. a resale/re-claim), so a stale "I own this" link cannot keep resolving.
36
+ - A grant is scoped to **one proof**; it can never widen access to other proofs or collection-level data.
37
+
38
+ ---
39
+
40
+ ## Owner flow — create, list, revoke
41
+
42
+ ```typescript
43
+ import { proof } from '@proveanything/smartlinks'
44
+
45
+ // Create a read+comment grant that expires in 7 days.
46
+ const grant = await proof.createGrant(collectionId, productId, proofId, {
47
+ scope: ['read', 'comment'],
48
+ audience: { kind: 'public_link' },
49
+ expiresAt: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000),
50
+ })
51
+
52
+ // `grant.token` is available ONLY here — embed it in your share link now.
53
+ const shareUrl = `https://app.example.com/album?proofId=${proofId}&shareToken=${grant.token}`
54
+
55
+ // List active + past grants (tokens are never included).
56
+ const grants = await proof.listGrants(collectionId, productId, proofId)
57
+
58
+ // Stop sharing — takes effect on the very next request from any client.
59
+ await proof.revokeGrant(collectionId, productId, proofId, grant.grantId)
60
+ ```
61
+
62
+ `createGrant` / `listGrants` / `revokeGrant` require the caller to be the **proof
63
+ owner** (or a collection admin) — i.e. a signed-in user whose `bearerToken` is set.
64
+
65
+ ---
66
+
67
+ ## Recipient flow — redeem, then carry the token
68
+
69
+ A recipient opens the share link, redeems the token once, then sets it as the
70
+ active grant token. From then on **every** SDK request carries the token
71
+ (`X-Grant-Token`), so all proof reads/writes are evaluated against the grant.
72
+
73
+ ```typescript
74
+ import { proof, setGrantToken } from '@proveanything/smartlinks'
75
+
76
+ const shareToken = new URLSearchParams(location.search).get('shareToken')!
77
+
78
+ // Redeem once (anonymous or signed-in). Records the redemption; optionally names the guest.
79
+ await proof.redeemGrant(collectionId, productId, proofId, shareToken, {
80
+ guestName: 'Sam', // stamped on guest activity when not signed in
81
+ })
82
+
83
+ // Attach the token to every subsequent request.
84
+ setGrantToken(shareToken)
85
+
86
+ // Now grant-tier reads succeed — e.g. owner-visibility memories on the proof:
87
+ const { attestations } = await attestation.publicList(collectionId, {
88
+ subjectType: 'proof', subjectId: proofId,
89
+ })
90
+
91
+ // Clear it when leaving the shared view:
92
+ setGrantToken(undefined)
93
+ ```
94
+
95
+ > **Persisting across reloads.** `setGrantToken` holds the token in memory. To keep a
96
+ > shared session across reloads, persist `shareToken` yourself (e.g. in `localStorage`)
97
+ > and call `setGrantToken` again on load.
98
+
99
+ ---
100
+
101
+ ## Guest commenting
102
+
103
+ With a `comment` scope grant, a bearer can post comments even when they are not
104
+ signed in. The app must enable the **grant branch** of the thread create policy
105
+ (see [App config](#app-config)); comments are then created at `visibility: 'owner'`
106
+ (private to the proof) and stamped `authorType: 'guest'`.
107
+
108
+ ```typescript
109
+ import { app } from '@proveanything/smartlinks'
110
+ // setGrantToken(shareToken) has already been called.
111
+
112
+ // One atomic call — no separate create-then-reply round trip.
113
+ await app.threads.create(collectionId, 'photo-memory', {
114
+ parentType: 'memory',
115
+ parentId: memoryId, // text — SmartLinks short ids are fine (not just UUIDs)
116
+ proofId, // anchor to the proof so grant readers see it
117
+ firstReply: { text: 'Lovely photo', authorName: 'Sam' },
118
+ })
119
+ ```
120
+
121
+ Other grant holders (and the owner) see these comments because a `read` grant reveals
122
+ `owner`-visibility threads for the proof. See
123
+ [App Objects → Threads](app-objects.md#threads) for the full threads API.
124
+
125
+ ---
126
+
127
+ ## Proof of ownership — `verify_owner`
128
+
129
+ Ownership itself is **not** a grant — it is `proof.ownerId`, established via the
130
+ existing [claim flow](proof-claiming-methods.md). A `verify_owner` grant only
131
+ publishes a shareable, verifiable **assertion** derived from that ownership, without
132
+ handing over the account:
133
+
134
+ ```typescript
135
+ const grant = await proof.createGrant(collectionId, productId, proofId, {
136
+ scope: ['verify_owner'],
137
+ })
138
+
139
+ // The recipient redeems it and gets the assertion — never the account:
140
+ const result = await proof.redeemGrant(collectionId, productId, proofId, grant.token)
141
+ // { proofId, assertsOwnership: true, ownerDisplayName?, issuedAt, expiresAt }
142
+ ```
143
+
144
+ Because grants auto-invalidate on transfer, a resale cannot leave a stale
145
+ "I own this" link in circulation.
146
+
147
+ ---
148
+
149
+ ## What a grant gates
150
+
151
+ When a valid grant token is present, these public reads elevate to owner-tier for the
152
+ granted proof (and only that proof):
153
+
154
+ - **Attestations** — `attestation.publicList({ subjectType: 'proof', subjectId })`
155
+ - **Threads / Records / Cases** — `app.threads.list`, `app.records.*`, `app.cases.list`, and the single-item GETs, filtered to the granted proof
156
+ - **Thread creation / replies** — with a `comment` scope grant (see below)
157
+
158
+ The token never exposes the platform `admin` zone, and only reveals `owner`-visibility
159
+ rows for the granted `proofId`.
160
+
161
+ ---
162
+
163
+ ## App config
164
+
165
+ Grant-based commenting is opt-in per app, configured on the app's Firestore config
166
+ at `sites/{collectionId}/apps/{appId}` — a `grant` branch alongside
167
+ `anonymous` / `authenticated`:
168
+
169
+ ```jsonc
170
+ {
171
+ "publicCreate": {
172
+ "threads": {
173
+ "grant": {
174
+ "allow": true,
175
+ "requireScope": "comment",
176
+ "enforce": { "visibility": "owner", "status": "open" }
177
+ }
178
+ }
179
+ }
180
+ }
181
+ ```
182
+
183
+ This enables grant-scoped commenting **without** opening up anonymous creation. The
184
+ `enforce.visibility: "owner"` keeps comments private to the proof (visible to the
185
+ owner and other grant holders, not the wider public).
186
+
187
+ ---
188
+
189
+ ## API reference
190
+
191
+ ```typescript
192
+ namespace proof {
193
+ createGrant(collectionId, productId, proofId, options: CreateGrantOptions): Promise<ProofGrant>
194
+ listGrants(collectionId, productId, proofId): Promise<ProofGrant[]>
195
+ revokeGrant(collectionId, productId, proofId, grantId): Promise<void>
196
+ redeemGrant(collectionId, productId, proofId, token, options?: RedeemGrantOptions): Promise<RedeemGrantResult>
197
+ }
198
+
199
+ // Attach / clear the active grant token (sent as X-Grant-Token on every request).
200
+ function setGrantToken(token: string | undefined): void
201
+ function getGrantToken(): string | undefined
202
+
203
+ type GrantScope = 'read' | 'comment' | 'admin' | 'verify_owner'
204
+
205
+ interface CreateGrantOptions {
206
+ scope: GrantScope[] // at least one
207
+ audience?: { kind: 'public_link' } | { kind: 'named'; email?: string; userId?: string }
208
+ expiresAt?: Date | string
209
+ }
210
+
211
+ interface RedeemGrantOptions { guestName?: string }
212
+
213
+ type RedeemGrantResult =
214
+ | { scope: GrantScope[]; redeemedAt: string }
215
+ | { proofId: string; assertsOwnership: true; ownerDisplayName?: string; issuedAt?: string; expiresAt?: string }
216
+
217
+ interface ProofGrant {
218
+ grantId: string
219
+ proofId: string
220
+ productId?: string | null
221
+ scope: GrantScope[]
222
+ audience: { kind: 'public_link' | 'named'; email?: string; userId?: string }
223
+ createdBy: string
224
+ expiresAt?: string | null
225
+ revokedAt?: string | null
226
+ redeemedBy?: { userId?: string; guestName?: string; redeemedAt: string }
227
+ redeemCount: number
228
+ createdAt: string
229
+ updatedAt: string
230
+ token?: string // present ONLY on the createGrant response
231
+ }
232
+ ```