@tinycloud/share-sdk 1.2.0-beta.1 → 1.2.0-beta.2

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.
@@ -1,5 +1,39 @@
1
1
  import { CompactUcanAuthorization } from '@tinycloud/share-envelope';
2
- import { C as CreateOwnerDelegationParams, r as OwnerDelegationReceipt, D as DelegatedShareKey, A as AddressedOwnerRootInput, i as AddressedOwnerRootReceipt } from './addressed-publish-CsUS7-SI.cjs';
2
+ import { C as CreateOwnerDelegationParams, r as OwnerDelegationReceipt, A as AddressedOwnerRootInput, i as AddressedOwnerRootReceipt, D as DelegatedShareKey, l as AddressedPublishAuthority } from './addressed-publish-CsUS7-SI.cjs';
3
+
4
+ /**
5
+ * The fields of an owner-signed SIWE CACAO that bound its authority. Read
6
+ * from the exact bytes the Node imported; nothing here is taken from the
7
+ * SDK's own echo of the request.
8
+ */
9
+ interface DecodedOwnerRootCacao {
10
+ /** CIDv1 (raw, BLAKE3) of the exact CACAO bytes, as the Node computes it. */
11
+ readonly cid: string;
12
+ readonly issuer: string;
13
+ readonly audience: string;
14
+ readonly issuedAt: string;
15
+ readonly expiresAt?: string;
16
+ readonly notBefore?: string;
17
+ /** Every SIWE resource, in signed order. */
18
+ readonly resources: readonly string[];
19
+ /** The ReCap `att` of the last resource; null-prototype maps. */
20
+ readonly attenuation: Readonly<Record<string, Readonly<Record<string, readonly unknown[]>>>>;
21
+ /** The ReCap `prf` list (parent capabilities); a root has none. */
22
+ readonly reCapProofs: readonly unknown[];
23
+ }
24
+ /** CIDv1 (raw, BLAKE3) of exact CACAO bytes, as the Node computes a delegation CID. */
25
+ declare function ownerRootCacaoCid(bytes: Uint8Array): string;
26
+ /**
27
+ * Decode the exact bytes of an owner-signed SIWE CACAO. Checks size, CBOR
28
+ * strictness, the envelope shape (eip4361 payload, 65-byte eip191 signature)
29
+ * and, when given, that the bytes hash to `expectedCid`.
30
+ *
31
+ * It does not verify the wallet signature: the Node verifies it when it
32
+ * imports the delegation and is the authority on it. This decoder exists so
33
+ * a caller can check what was signed (scope, audience, lifetime) instead of
34
+ * trusting the request it made.
35
+ */
36
+ declare function decodeOwnerRootCacao(bytes: Uint8Array, expectedCid?: string): DecodedOwnerRootCacao;
3
37
 
4
38
  /** KV prefix every share lives under; the root never reaches outside it. */
5
39
  declare const SHARE_ROOT_PREFIX = "xyz.tinycloud.share/shares/";
@@ -157,8 +191,9 @@ declare const defaultPolicyOwnerModeProbe: PolicyOwnerModeProbe;
157
191
  * - Scope: `kv/get` + `kv/metadata` on the share prefix. `:share` decrypt is
158
192
  * added (scope `kv+share-decrypt`) only when the root is created while
159
193
  * `shareRootPolicyRoots` is on and its Node advertises owner-authority mode
160
- * `enforce`; a `kv` root holds no decrypt, so the Node refuses any Policy/v3
161
- * registration it signs. Never put, del, list, `capabilities/read`,
194
+ * `enforce`; a `kv` root holds no `:share` decrypt, so its key cannot own a
195
+ * policy over `:share`-encrypted content (the Node answers
196
+ * `policy-owner-not-authorized`). Never put, del, list, `capabilities/read`,
162
197
  * `network.create` or `:default`.
163
198
  * - Created only through `createOwnerDelegation({ permissions })`; the signed
164
199
  * bytes are decoded and checked here.
@@ -305,38 +340,139 @@ interface ShareKeyDelegationInput {
305
340
  */
306
341
  declare function signShareKeyDelegation(input: ShareKeyDelegationInput): Promise<CompactUcanAuthorization>;
307
342
 
343
+ /** `view`: kv get + metadata. `edit`: also kv put. Both on one exact key. */
344
+ type ShareGrantAccess = "view" | "edit";
345
+ /** Persistable grant metadata. Holds no key material. */
346
+ interface ShareGrantRecord {
347
+ readonly version: 1;
348
+ readonly cid: string;
349
+ /** Base64url of the exact owner-signed CACAO bytes. */
350
+ readonly authorization: string;
351
+ readonly spaceId: string;
352
+ readonly ownerDid: string;
353
+ readonly keyDid: string;
354
+ readonly nodeOrigin: string;
355
+ /** The one exact KV key under `xyz.tinycloud.share/shares/`. */
356
+ readonly path: string;
357
+ readonly access: ShareGrantAccess;
358
+ readonly expiresAt: string;
359
+ }
308
360
  /**
309
- * The fields of an owner-signed SIWE CACAO that bound its authority. Read
310
- * from the exact bytes the Node imported; nothing here is taken from the
311
- * SDK's own echo of the request.
361
+ * A per-share owner grant (TC-1423 D3, the interim path for addressed shares
362
+ * while the Node does not enforce owner-authority binding).
363
+ *
364
+ * The owner signs one CACAO (one approval per share) to a FRESH per-share
365
+ * key, never the share-root key:
366
+ * - kv `get` + `metadata` (+ `put` for `edit`) on exactly one KV key under
367
+ * the share prefix, in the `applications` space;
368
+ * - `decrypt` on the owner's `:share` network, which a Policy/v3 owner must
369
+ * hold (every v3 policy's capability ceiling includes decrypt on the
370
+ * source's network; without it the Node answers
371
+ * `policy-owner-not-authorized`);
372
+ * - at most 30 days, and exactly the requested expiry.
373
+ * The per-share key then owns that one share's policy: `publishAuthority`
374
+ * signs its two policy roots (bounded by the grant's expiry and exact path)
375
+ * and its 32-byte policy and envelope digests.
376
+ *
377
+ * Revoking the grant (one owner SIWE `POST /revoke` on `cid`) cuts the
378
+ * per-share key's own reads and its decrypt, for this share only. Until the
379
+ * Node binds policy registrations to the owner delegation (NODE-B2), an
380
+ * already-registered policy keeps admitting recipients until its own expiry,
381
+ * which never exceeds the grant's.
382
+ *
383
+ * Key custody: `create` generates a non-extractable key and never exposes
384
+ * it. Keep the grant (in memory, or a CLI 0600 key file via `restore`) until
385
+ * the share expires, to sign `RootRevocation` later. No browser persistence:
386
+ * that needs the composer on its own origin first (REVIEW-D3 V2-2).
312
387
  */
313
- interface DecodedOwnerRootCacao {
314
- /** CIDv1 (raw, BLAKE3) of the exact CACAO bytes, as the Node computes it. */
388
+ declare class ShareGrant {
389
+ #private;
315
390
  readonly cid: string;
316
- readonly issuer: string;
317
- readonly audience: string;
318
- readonly issuedAt: string;
319
- readonly expiresAt?: string;
320
- readonly notBefore?: string;
321
- /** Every SIWE resource, in signed order. */
322
- readonly resources: readonly string[];
323
- /** The ReCap `att` of the last resource; null-prototype maps. */
324
- readonly attenuation: Readonly<Record<string, Readonly<Record<string, readonly unknown[]>>>>;
325
- /** The ReCap `prf` list (parent capabilities); a root has none. */
326
- readonly reCapProofs: readonly unknown[];
391
+ readonly ownerDid: string;
392
+ readonly spaceId: string;
393
+ readonly keyDid: string;
394
+ readonly nodeOrigin: string;
395
+ readonly path: string;
396
+ readonly access: ShareGrantAccess;
397
+ readonly issuedAt: Date;
398
+ readonly expiresAt: Date;
399
+ private constructor();
400
+ /**
401
+ * Ask the owner for one per-share grant (one approval). Path, access,
402
+ * expiry, space and Node origin are checked before the wallet is asked; the
403
+ * signed CACAO is decoded and must match exactly, or the key is cleared and
404
+ * the error carries the imported CID (`mustRevoke` when it may be wider).
405
+ */
406
+ static create(input: {
407
+ readonly owner: ShareRootOwnerAuthority;
408
+ readonly spaceId: string;
409
+ readonly nodeOrigin: string;
410
+ readonly path: string;
411
+ readonly access: ShareGrantAccess;
412
+ readonly expiresAt: Date;
413
+ readonly keyFactory?: () => Promise<DelegatedShareKey>;
414
+ readonly now?: () => number;
415
+ }): Promise<ShareGrant>;
416
+ /** Rebuild a stored grant with its key (e.g. a CLI 0600 key file); the signed bytes are checked again. */
417
+ static restore(input: {
418
+ readonly record: ShareGrantRecord;
419
+ readonly key: DelegatedShareKey;
420
+ readonly now?: () => number;
421
+ }): Promise<ShareGrant>;
422
+ /** The `Authorization` value the Node knows this grant by (base64url CACAO). */
423
+ get authorization(): string;
424
+ /** The exact KV resource this grant covers. */
425
+ get resource(): string;
426
+ toRecord(): ShareGrantRecord;
427
+ /**
428
+ * Policy/v3 owner signing for this one share. Every call checks the key is
429
+ * held and the grant is live. Policy roots must be owned by the per-share
430
+ * key, expire no later than the grant, and name only this grant's exact
431
+ * KV resource (with no action the grant lacks) and decrypt on `:share`.
432
+ */
433
+ policySigner(): ShareRootPolicySigner;
434
+ /** `publishAddressedShare`'s `authority` for this share: the policy signer plus the caller's `registerPolicy`. */
435
+ publishAuthority(registerPolicy: AddressedPublishAuthority["registerPolicy"]): AddressedPublishAuthority;
436
+ /** Drop the per-share key. It does not revoke the grant: only the owner does that. */
437
+ clear(): void;
438
+ }
439
+
440
+ interface ShareNetworkResult {
441
+ /** `urn:tinycloud:encryption:<owner did:pkh>:share`. */
442
+ readonly networkId: string;
443
+ /** Owner wallet approvals this call used: 0 when the network already existed, else 1. */
444
+ readonly approvals: 0 | 1;
327
445
  }
328
- /** CIDv1 (raw, BLAKE3) of exact CACAO bytes, as the Node computes a delegation CID. */
329
- declare function ownerRootCacaoCid(bytes: Uint8Array): string;
330
446
  /**
331
- * Decode the exact bytes of an owner-signed SIWE CACAO. Checks size, CBOR
332
- * strictness, the envelope shape (eip4361 payload, 65-byte eip191 signature)
333
- * and, when given, that the bytes hash to `expectedCid`.
447
+ * The owner's `:share` network URN, `urn:tinycloud:encryption:<owner
448
+ * did:pkh>:share`: where Share sources are encrypted, and the network a
449
+ * per-share grant or a `kv+share-decrypt` root may decrypt. The Node compares
450
+ * the did:pkh address case-insensitively.
451
+ */
452
+ declare function shareNetworkIdFor(ownerDid: string): string;
453
+ type FetchFn = (input: URL, init?: RequestInit) => Promise<Response>;
454
+ /**
455
+ * Make sure the owner's dedicated `:share` encryption network exists (D3
456
+ * addendum §1, review B1). Per owner: `urn:tinycloud:encryption:<owner
457
+ * did:pkh>:share`. The owner owns it, never a share key or per-share key: a
458
+ * network whose owner is the key would be root authority for that key
459
+ * (tinycloud-node `delegation.rs:792-809`), so revoking its grant would not
460
+ * cut decrypt.
334
461
  *
335
- * It does not verify the wallet signature: the Node verifies it when it
336
- * imports the delegation and is the authority on it. This decoder exists so
337
- * a caller can check what was signed (scope, audience, lifetime) instead of
338
- * trusting the request it made.
462
+ * Idempotent: when the Node already has it, nothing is signed (0 approvals).
463
+ * Otherwise the owner signs one short-lived CACAO (one approval, once per
464
+ * owner) granting only `network.create` on that URN to a throwaway
465
+ * non-extractable key, which creates the network with the owner as
466
+ * `ownerDid` and is then cleared. A 409 from a concurrent creator counts as
467
+ * created. Share sources encrypt to it; vault and secrets stay on `:default`.
339
468
  */
340
- declare function decodeOwnerRootCacao(bytes: Uint8Array, expectedCid?: string): DecodedOwnerRootCacao;
469
+ declare function ensureShareNetwork(input: {
470
+ readonly owner: ShareRootOwnerAuthority;
471
+ readonly spaceId: string;
472
+ readonly nodeOrigin: string;
473
+ readonly fetch?: FetchFn;
474
+ readonly keyFactory?: () => Promise<DelegatedShareKey>;
475
+ readonly now?: () => number;
476
+ }): Promise<ShareNetworkResult>;
341
477
 
342
- export { AGENT_SHARE_ROOT_MAX_LIFETIME_MS, type DecodedOwnerRootCacao, POLICY_OWNER_AUTHORITY_FEATURES, POLICY_OWNER_AUTHORITY_PROBE_TTL_MS, type PolicyOwnerModeProbe, SHARE_ROOT_CLOCK_SKEW_MS, SHARE_ROOT_LINK_MAX_LIFETIME_MS, SHARE_ROOT_MAX_LIFETIME_MS, SHARE_ROOT_PREFIX, SHARE_ROOT_REQUEST_MARGIN_MS, type ShareKeyDelegationInput, type ShareKeySigner, ShareRoot, ShareRootError, type ShareRootErrorCode, type ShareRootErrorDetails, type ShareRootKind, type ShareRootLink, type ShareRootOptions, type ShareRootOwnerAuthority, type ShareRootPolicySigner, type ShareRootRecord, type ShareRootScope, assertNonExtractableShareKey, createPolicyOwnerModeProbe, decodeOwnerRootCacao, defaultPolicyOwnerModeProbe, ensureShareRoot, ownerRootCacaoCid, readPolicyOwnerAuthorityMode, signShareKeyDelegation };
478
+ export { AGENT_SHARE_ROOT_MAX_LIFETIME_MS, type DecodedOwnerRootCacao, POLICY_OWNER_AUTHORITY_FEATURES, POLICY_OWNER_AUTHORITY_PROBE_TTL_MS, type PolicyOwnerModeProbe, SHARE_ROOT_CLOCK_SKEW_MS, SHARE_ROOT_LINK_MAX_LIFETIME_MS, SHARE_ROOT_MAX_LIFETIME_MS, SHARE_ROOT_PREFIX, SHARE_ROOT_REQUEST_MARGIN_MS, ShareGrant, type ShareGrantAccess, type ShareGrantRecord, type ShareKeyDelegationInput, type ShareKeySigner, type ShareNetworkResult, ShareRoot, ShareRootError, type ShareRootErrorCode, type ShareRootErrorDetails, type ShareRootKind, type ShareRootLink, type ShareRootOptions, type ShareRootOwnerAuthority, type ShareRootPolicySigner, type ShareRootRecord, type ShareRootScope, assertNonExtractableShareKey, createPolicyOwnerModeProbe, decodeOwnerRootCacao, defaultPolicyOwnerModeProbe, ensureShareNetwork, ensureShareRoot, ownerRootCacaoCid, readPolicyOwnerAuthorityMode, shareNetworkIdFor, signShareKeyDelegation };
@@ -1,5 +1,39 @@
1
1
  import { CompactUcanAuthorization } from '@tinycloud/share-envelope';
2
- import { C as CreateOwnerDelegationParams, r as OwnerDelegationReceipt, D as DelegatedShareKey, A as AddressedOwnerRootInput, i as AddressedOwnerRootReceipt } from './addressed-publish-CsUS7-SI.js';
2
+ import { C as CreateOwnerDelegationParams, r as OwnerDelegationReceipt, A as AddressedOwnerRootInput, i as AddressedOwnerRootReceipt, D as DelegatedShareKey, l as AddressedPublishAuthority } from './addressed-publish-CsUS7-SI.js';
3
+
4
+ /**
5
+ * The fields of an owner-signed SIWE CACAO that bound its authority. Read
6
+ * from the exact bytes the Node imported; nothing here is taken from the
7
+ * SDK's own echo of the request.
8
+ */
9
+ interface DecodedOwnerRootCacao {
10
+ /** CIDv1 (raw, BLAKE3) of the exact CACAO bytes, as the Node computes it. */
11
+ readonly cid: string;
12
+ readonly issuer: string;
13
+ readonly audience: string;
14
+ readonly issuedAt: string;
15
+ readonly expiresAt?: string;
16
+ readonly notBefore?: string;
17
+ /** Every SIWE resource, in signed order. */
18
+ readonly resources: readonly string[];
19
+ /** The ReCap `att` of the last resource; null-prototype maps. */
20
+ readonly attenuation: Readonly<Record<string, Readonly<Record<string, readonly unknown[]>>>>;
21
+ /** The ReCap `prf` list (parent capabilities); a root has none. */
22
+ readonly reCapProofs: readonly unknown[];
23
+ }
24
+ /** CIDv1 (raw, BLAKE3) of exact CACAO bytes, as the Node computes a delegation CID. */
25
+ declare function ownerRootCacaoCid(bytes: Uint8Array): string;
26
+ /**
27
+ * Decode the exact bytes of an owner-signed SIWE CACAO. Checks size, CBOR
28
+ * strictness, the envelope shape (eip4361 payload, 65-byte eip191 signature)
29
+ * and, when given, that the bytes hash to `expectedCid`.
30
+ *
31
+ * It does not verify the wallet signature: the Node verifies it when it
32
+ * imports the delegation and is the authority on it. This decoder exists so
33
+ * a caller can check what was signed (scope, audience, lifetime) instead of
34
+ * trusting the request it made.
35
+ */
36
+ declare function decodeOwnerRootCacao(bytes: Uint8Array, expectedCid?: string): DecodedOwnerRootCacao;
3
37
 
4
38
  /** KV prefix every share lives under; the root never reaches outside it. */
5
39
  declare const SHARE_ROOT_PREFIX = "xyz.tinycloud.share/shares/";
@@ -157,8 +191,9 @@ declare const defaultPolicyOwnerModeProbe: PolicyOwnerModeProbe;
157
191
  * - Scope: `kv/get` + `kv/metadata` on the share prefix. `:share` decrypt is
158
192
  * added (scope `kv+share-decrypt`) only when the root is created while
159
193
  * `shareRootPolicyRoots` is on and its Node advertises owner-authority mode
160
- * `enforce`; a `kv` root holds no decrypt, so the Node refuses any Policy/v3
161
- * registration it signs. Never put, del, list, `capabilities/read`,
194
+ * `enforce`; a `kv` root holds no `:share` decrypt, so its key cannot own a
195
+ * policy over `:share`-encrypted content (the Node answers
196
+ * `policy-owner-not-authorized`). Never put, del, list, `capabilities/read`,
162
197
  * `network.create` or `:default`.
163
198
  * - Created only through `createOwnerDelegation({ permissions })`; the signed
164
199
  * bytes are decoded and checked here.
@@ -305,38 +340,139 @@ interface ShareKeyDelegationInput {
305
340
  */
306
341
  declare function signShareKeyDelegation(input: ShareKeyDelegationInput): Promise<CompactUcanAuthorization>;
307
342
 
343
+ /** `view`: kv get + metadata. `edit`: also kv put. Both on one exact key. */
344
+ type ShareGrantAccess = "view" | "edit";
345
+ /** Persistable grant metadata. Holds no key material. */
346
+ interface ShareGrantRecord {
347
+ readonly version: 1;
348
+ readonly cid: string;
349
+ /** Base64url of the exact owner-signed CACAO bytes. */
350
+ readonly authorization: string;
351
+ readonly spaceId: string;
352
+ readonly ownerDid: string;
353
+ readonly keyDid: string;
354
+ readonly nodeOrigin: string;
355
+ /** The one exact KV key under `xyz.tinycloud.share/shares/`. */
356
+ readonly path: string;
357
+ readonly access: ShareGrantAccess;
358
+ readonly expiresAt: string;
359
+ }
308
360
  /**
309
- * The fields of an owner-signed SIWE CACAO that bound its authority. Read
310
- * from the exact bytes the Node imported; nothing here is taken from the
311
- * SDK's own echo of the request.
361
+ * A per-share owner grant (TC-1423 D3, the interim path for addressed shares
362
+ * while the Node does not enforce owner-authority binding).
363
+ *
364
+ * The owner signs one CACAO (one approval per share) to a FRESH per-share
365
+ * key, never the share-root key:
366
+ * - kv `get` + `metadata` (+ `put` for `edit`) on exactly one KV key under
367
+ * the share prefix, in the `applications` space;
368
+ * - `decrypt` on the owner's `:share` network, which a Policy/v3 owner must
369
+ * hold (every v3 policy's capability ceiling includes decrypt on the
370
+ * source's network; without it the Node answers
371
+ * `policy-owner-not-authorized`);
372
+ * - at most 30 days, and exactly the requested expiry.
373
+ * The per-share key then owns that one share's policy: `publishAuthority`
374
+ * signs its two policy roots (bounded by the grant's expiry and exact path)
375
+ * and its 32-byte policy and envelope digests.
376
+ *
377
+ * Revoking the grant (one owner SIWE `POST /revoke` on `cid`) cuts the
378
+ * per-share key's own reads and its decrypt, for this share only. Until the
379
+ * Node binds policy registrations to the owner delegation (NODE-B2), an
380
+ * already-registered policy keeps admitting recipients until its own expiry,
381
+ * which never exceeds the grant's.
382
+ *
383
+ * Key custody: `create` generates a non-extractable key and never exposes
384
+ * it. Keep the grant (in memory, or a CLI 0600 key file via `restore`) until
385
+ * the share expires, to sign `RootRevocation` later. No browser persistence:
386
+ * that needs the composer on its own origin first (REVIEW-D3 V2-2).
312
387
  */
313
- interface DecodedOwnerRootCacao {
314
- /** CIDv1 (raw, BLAKE3) of the exact CACAO bytes, as the Node computes it. */
388
+ declare class ShareGrant {
389
+ #private;
315
390
  readonly cid: string;
316
- readonly issuer: string;
317
- readonly audience: string;
318
- readonly issuedAt: string;
319
- readonly expiresAt?: string;
320
- readonly notBefore?: string;
321
- /** Every SIWE resource, in signed order. */
322
- readonly resources: readonly string[];
323
- /** The ReCap `att` of the last resource; null-prototype maps. */
324
- readonly attenuation: Readonly<Record<string, Readonly<Record<string, readonly unknown[]>>>>;
325
- /** The ReCap `prf` list (parent capabilities); a root has none. */
326
- readonly reCapProofs: readonly unknown[];
391
+ readonly ownerDid: string;
392
+ readonly spaceId: string;
393
+ readonly keyDid: string;
394
+ readonly nodeOrigin: string;
395
+ readonly path: string;
396
+ readonly access: ShareGrantAccess;
397
+ readonly issuedAt: Date;
398
+ readonly expiresAt: Date;
399
+ private constructor();
400
+ /**
401
+ * Ask the owner for one per-share grant (one approval). Path, access,
402
+ * expiry, space and Node origin are checked before the wallet is asked; the
403
+ * signed CACAO is decoded and must match exactly, or the key is cleared and
404
+ * the error carries the imported CID (`mustRevoke` when it may be wider).
405
+ */
406
+ static create(input: {
407
+ readonly owner: ShareRootOwnerAuthority;
408
+ readonly spaceId: string;
409
+ readonly nodeOrigin: string;
410
+ readonly path: string;
411
+ readonly access: ShareGrantAccess;
412
+ readonly expiresAt: Date;
413
+ readonly keyFactory?: () => Promise<DelegatedShareKey>;
414
+ readonly now?: () => number;
415
+ }): Promise<ShareGrant>;
416
+ /** Rebuild a stored grant with its key (e.g. a CLI 0600 key file); the signed bytes are checked again. */
417
+ static restore(input: {
418
+ readonly record: ShareGrantRecord;
419
+ readonly key: DelegatedShareKey;
420
+ readonly now?: () => number;
421
+ }): Promise<ShareGrant>;
422
+ /** The `Authorization` value the Node knows this grant by (base64url CACAO). */
423
+ get authorization(): string;
424
+ /** The exact KV resource this grant covers. */
425
+ get resource(): string;
426
+ toRecord(): ShareGrantRecord;
427
+ /**
428
+ * Policy/v3 owner signing for this one share. Every call checks the key is
429
+ * held and the grant is live. Policy roots must be owned by the per-share
430
+ * key, expire no later than the grant, and name only this grant's exact
431
+ * KV resource (with no action the grant lacks) and decrypt on `:share`.
432
+ */
433
+ policySigner(): ShareRootPolicySigner;
434
+ /** `publishAddressedShare`'s `authority` for this share: the policy signer plus the caller's `registerPolicy`. */
435
+ publishAuthority(registerPolicy: AddressedPublishAuthority["registerPolicy"]): AddressedPublishAuthority;
436
+ /** Drop the per-share key. It does not revoke the grant: only the owner does that. */
437
+ clear(): void;
438
+ }
439
+
440
+ interface ShareNetworkResult {
441
+ /** `urn:tinycloud:encryption:<owner did:pkh>:share`. */
442
+ readonly networkId: string;
443
+ /** Owner wallet approvals this call used: 0 when the network already existed, else 1. */
444
+ readonly approvals: 0 | 1;
327
445
  }
328
- /** CIDv1 (raw, BLAKE3) of exact CACAO bytes, as the Node computes a delegation CID. */
329
- declare function ownerRootCacaoCid(bytes: Uint8Array): string;
330
446
  /**
331
- * Decode the exact bytes of an owner-signed SIWE CACAO. Checks size, CBOR
332
- * strictness, the envelope shape (eip4361 payload, 65-byte eip191 signature)
333
- * and, when given, that the bytes hash to `expectedCid`.
447
+ * The owner's `:share` network URN, `urn:tinycloud:encryption:<owner
448
+ * did:pkh>:share`: where Share sources are encrypted, and the network a
449
+ * per-share grant or a `kv+share-decrypt` root may decrypt. The Node compares
450
+ * the did:pkh address case-insensitively.
451
+ */
452
+ declare function shareNetworkIdFor(ownerDid: string): string;
453
+ type FetchFn = (input: URL, init?: RequestInit) => Promise<Response>;
454
+ /**
455
+ * Make sure the owner's dedicated `:share` encryption network exists (D3
456
+ * addendum §1, review B1). Per owner: `urn:tinycloud:encryption:<owner
457
+ * did:pkh>:share`. The owner owns it, never a share key or per-share key: a
458
+ * network whose owner is the key would be root authority for that key
459
+ * (tinycloud-node `delegation.rs:792-809`), so revoking its grant would not
460
+ * cut decrypt.
334
461
  *
335
- * It does not verify the wallet signature: the Node verifies it when it
336
- * imports the delegation and is the authority on it. This decoder exists so
337
- * a caller can check what was signed (scope, audience, lifetime) instead of
338
- * trusting the request it made.
462
+ * Idempotent: when the Node already has it, nothing is signed (0 approvals).
463
+ * Otherwise the owner signs one short-lived CACAO (one approval, once per
464
+ * owner) granting only `network.create` on that URN to a throwaway
465
+ * non-extractable key, which creates the network with the owner as
466
+ * `ownerDid` and is then cleared. A 409 from a concurrent creator counts as
467
+ * created. Share sources encrypt to it; vault and secrets stay on `:default`.
339
468
  */
340
- declare function decodeOwnerRootCacao(bytes: Uint8Array, expectedCid?: string): DecodedOwnerRootCacao;
469
+ declare function ensureShareNetwork(input: {
470
+ readonly owner: ShareRootOwnerAuthority;
471
+ readonly spaceId: string;
472
+ readonly nodeOrigin: string;
473
+ readonly fetch?: FetchFn;
474
+ readonly keyFactory?: () => Promise<DelegatedShareKey>;
475
+ readonly now?: () => number;
476
+ }): Promise<ShareNetworkResult>;
341
477
 
342
- export { AGENT_SHARE_ROOT_MAX_LIFETIME_MS, type DecodedOwnerRootCacao, POLICY_OWNER_AUTHORITY_FEATURES, POLICY_OWNER_AUTHORITY_PROBE_TTL_MS, type PolicyOwnerModeProbe, SHARE_ROOT_CLOCK_SKEW_MS, SHARE_ROOT_LINK_MAX_LIFETIME_MS, SHARE_ROOT_MAX_LIFETIME_MS, SHARE_ROOT_PREFIX, SHARE_ROOT_REQUEST_MARGIN_MS, type ShareKeyDelegationInput, type ShareKeySigner, ShareRoot, ShareRootError, type ShareRootErrorCode, type ShareRootErrorDetails, type ShareRootKind, type ShareRootLink, type ShareRootOptions, type ShareRootOwnerAuthority, type ShareRootPolicySigner, type ShareRootRecord, type ShareRootScope, assertNonExtractableShareKey, createPolicyOwnerModeProbe, decodeOwnerRootCacao, defaultPolicyOwnerModeProbe, ensureShareRoot, ownerRootCacaoCid, readPolicyOwnerAuthorityMode, signShareKeyDelegation };
478
+ export { AGENT_SHARE_ROOT_MAX_LIFETIME_MS, type DecodedOwnerRootCacao, POLICY_OWNER_AUTHORITY_FEATURES, POLICY_OWNER_AUTHORITY_PROBE_TTL_MS, type PolicyOwnerModeProbe, SHARE_ROOT_CLOCK_SKEW_MS, SHARE_ROOT_LINK_MAX_LIFETIME_MS, SHARE_ROOT_MAX_LIFETIME_MS, SHARE_ROOT_PREFIX, SHARE_ROOT_REQUEST_MARGIN_MS, ShareGrant, type ShareGrantAccess, type ShareGrantRecord, type ShareKeyDelegationInput, type ShareKeySigner, type ShareNetworkResult, ShareRoot, ShareRootError, type ShareRootErrorCode, type ShareRootErrorDetails, type ShareRootKind, type ShareRootLink, type ShareRootOptions, type ShareRootOwnerAuthority, type ShareRootPolicySigner, type ShareRootRecord, type ShareRootScope, assertNonExtractableShareKey, createPolicyOwnerModeProbe, decodeOwnerRootCacao, defaultPolicyOwnerModeProbe, ensureShareNetwork, ensureShareRoot, ownerRootCacaoCid, readPolicyOwnerAuthorityMode, shareNetworkIdFor, signShareKeyDelegation };