@tinycloud/web-sdk 3.14.0-beta.2 → 3.14.0-beta.20

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.
@@ -25,8 +25,18 @@ export declare function isPanelResourceSet(resources: readonly Resource[], owner
25
25
  /** True when `grant` is exactly a panel grant of the session owned by `address`. */
26
26
  export declare function isPanelGrant(grant: PortableDelegation, address: string): boolean;
27
27
  /**
28
- * Stores the panel's own grants among `grants` for `address`, replacing a stored grant with the same cid. Other
29
- * delegations (an app's larger grant that already covered the request) are never stored.
28
+ * Matches exact secret keys on the owner's default network, or the reserved bot-history
29
+ * key by itself. Only decrypt and/or key.create, and no caveats.
30
+ */
31
+ export declare function isSecretKeyResourceSet(resources: readonly Resource[], owner: {
32
+ readonly address: string;
33
+ readonly chainId: number;
34
+ }): boolean;
35
+ /** True when `grant` is exactly a grant of the session owner's own secrets' keys (see `isSecretKeyResourceSet`). */
36
+ export declare function isSecretKeyGrant(grant: PortableDelegation, address: string): boolean;
37
+ /**
38
+ * Stores the panel's own grants and the owner's secret-key grants among `grants` for `address`, replacing a stored
39
+ * grant with the same cid. Other delegations (an app's larger grant that already covered the request) are never stored.
30
40
  */
31
41
  export declare function rememberRuntimeGrants(store: RuntimeGrantStore, address: string, grants: readonly PortableDelegation[], isCurrent?: () => boolean): Promise<void>;
32
42
  /**
@@ -39,5 +49,35 @@ export declare function reuseRuntimeGrants(store: RuntimeGrantStore, address: st
39
49
  readonly budgetMs?: number;
40
50
  readonly isCurrent?: () => boolean;
41
51
  }): Promise<void>;
52
+ /** A stored grant. `askedBy` names the apps it was approved for (the `onBehalfOf` of each approving request). */
53
+ export type StoredRuntimeGrant = PortableDelegation & {
54
+ readonly askedBy?: readonly string[];
55
+ };
56
+ /** The apps a stored grant was approved for; anything else in the field is ignored. */
57
+ export declare function storedGrantAskers(grant: PortableDelegation): readonly string[];
58
+ /**
59
+ * True when a grant entry is elevated: any service this module does not know (decrypt and key creation among them),
60
+ * anything in the secrets space, or a caveat of any shape. Failing closed: an entry this function cannot classify is
61
+ * elevated, and an elevated grant is never written to storage.
62
+ */
63
+ export declare function isElevatedResource(resource: {
64
+ readonly service: string;
65
+ readonly space?: string | undefined;
66
+ readonly caveats?: unknown;
67
+ }): boolean;
68
+ /** True when every resource is in a space the owner owns and none is elevated. An empty set is not rememberable. */
69
+ export declare function isRememberableResourceSet(resources: readonly Resource[], owner: {
70
+ readonly address: string;
71
+ readonly chainId: number;
72
+ }): boolean;
73
+ /** True when `grant` is an unexpired, non-elevated grant of the session owned by `address`. */
74
+ export declare function isRememberableGrant(grant: PortableDelegation, address: string): boolean;
75
+ /**
76
+ * Stores the non-elevated grants among `grants` for `address`, with `asker` added to the apps each was approved for,
77
+ * replacing a stored grant with the same cid. An elevated grant is never stored. A signed grant that spans several
78
+ * spaces arrives as several delegations with one cid; it is not stored, because a restore rebuilds its resources from
79
+ * the signed bytes, not from the delegation. A stored grant keeps its own signed expiry.
80
+ */
81
+ export declare function rememberAskedGrants(store: RuntimeGrantStore, address: string, grants: readonly PortableDelegation[], asker: string | undefined, isCurrent?: () => boolean): Promise<void>;
42
82
  export {};
43
83
  //# sourceMappingURL=runtimeGrantPersistence.d.ts.map
@@ -10,9 +10,11 @@
10
10
  * @packageDocumentation
11
11
  */
12
12
  import { TinyCloudNode, TinyCloudNodeConfig, type OpenKeyAuthorizeTinyCloud, type BootstrapWarning, type DelegateToOptions, type DelegateToResult, type ISessionStorage, type SignStrategy, type ValidatedRuntimeDelegation, type UnifiedOwnerRootInput, type UnifiedOwnerRootReceipt, type RegisterPolicyV3Input, type RegisterPolicyV3Receipt } from "@tinycloud/node-sdk/core";
13
+ import type { NodeSignOutStatus } from "@tinycloud/node-sdk";
13
14
  import { type LocalCopyPurgeFailedEvent } from "./replica-wiring";
14
15
  import { IKVService, ISQLService, IDuckDbService, IDataVaultService, ISecretsService, ISpaceService, ISpace, ISharingService, ICapabilityKeyRegistry, IHooksService, IEncryptionService, DelegationManager, Delegation, DelegationRevocationReceipt, Result, DelegationError, ClientSession, Extension, type TelemetryConfig, type RetryPolicy, ISpaceCreationHandler, type Manifest, type ComposedManifestRequest, type AccountService, type ResolvedDelegate, type PermissionEntry, type NetworkDescriptor, type CreateOwnerDelegationParams, type OwnerDelegationReceipt, type LocalNodeIdentityStore, type OnNodeNotFound, type RegistrySequenceStore, SignInOptions, type RegistryCacheStore, type StorageFullEvent, type IStorageService } from "@tinycloud/sdk-core";
15
16
  import { type RequestPermissionsOptions } from "./requestPermissionsCore";
17
+ import { type OpenKeySignPresentation } from "./openKeySignPresentation";
16
18
  import { type BrowserProvider, type BrowserWalletProvider } from "../adapters/browserProvider";
17
19
  import { type TinyCloudUI, type UiConfig } from "../ui";
18
20
  import { RPCProviders, ClientConfig } from "../providers";
@@ -25,9 +27,12 @@ declare global {
25
27
  ethereum?: any;
26
28
  }
27
29
  }
28
- /** Signs a message for a runtime permission grant; see `TinyCloudWeb.setRuntimePermissionSigner`. */
30
+ /**
31
+ * Signs a message for a runtime permission grant; see `TinyCloudWeb.setRuntimePermissionSigner`. A signer set with
32
+ * `{ openKey: true }` also receives the `presentation` to pass on to OpenKey's approval; display-only, never signed.
33
+ */
29
34
  export interface RuntimePermissionSigner {
30
- signMessage(message: string): Promise<string>;
35
+ signMessage(message: string, presentation?: OpenKeySignPresentation): Promise<string>;
31
36
  }
32
37
  /**
33
38
  * Configuration for TinyCloudWeb.
@@ -120,7 +125,7 @@ export interface Config extends ClientConfig {
120
125
  * modal handler is in use.
121
126
  */
122
127
  spaceCreationTimeoutMs?: number;
123
- /** Session expiration time in milliseconds (default: 30 days, `EXPIRY.SESSION_MS`) */
128
+ /** Session expiration time in milliseconds (default: 7 days, `EXPIRY.SESSION_MS`) */
124
129
  sessionExpirationMs?: number;
125
130
  /** Persist browser sessions so signIn() can restore before prompting. Default true. */
126
131
  persistSession?: boolean;
@@ -146,6 +151,10 @@ export interface Config extends ClientConfig {
146
151
  * manifest's `name` and `icon` to title the permission modal. The
147
152
  * manifest is forwarded into the underlying {@link TinyCloudNode}
148
153
  * so `signIn()` drives its SIWE recap from it directly.
154
+ *
155
+ * Without this or `capabilityRequest`, `signIn()` asks only for the app's
156
+ * own folder (`applications/<reversed host>/`, KV and SQL, 7 days) and
157
+ * logs a console warning.
149
158
  */
150
159
  manifest?: Manifest | Manifest[];
151
160
  /** Pre-composed manifest request. Takes precedence over `manifest`. */
@@ -234,6 +243,8 @@ export declare class TinyCloudWeb {
234
243
  private runtimeSigner?;
235
244
  private signOutInFlight;
236
245
  private signOutOperation?;
246
+ /** The node the latest sign-out ended; it holds that sign-out's node status. */
247
+ private signedOutNode?;
237
248
  private persistedRestoreBlocked;
238
249
  private signOutCleanupFailed;
239
250
  private remoteSignOutTimeoutMs;
@@ -270,6 +281,8 @@ export declare class TinyCloudWeb {
270
281
  private _testHooks?;
271
282
  constructor(callerConfig?: Config);
272
283
  private bootstrapSignInPolicy;
284
+ /** Outside a browser, an app with no domain and no manifest gets the folder every such app shares. */
285
+ private warnIfWithoutAppHost;
273
286
  /**
274
287
  * Async initialization: ensure WASM is ready, then create TinyCloudNode.
275
288
  * @internal
@@ -437,6 +450,13 @@ export declare class TinyCloudWeb {
437
450
  * unavailable until a fresh sign-in; prior persisted sessions cannot restore.
438
451
  */
439
452
  signOut: () => Promise<void>;
453
+ /**
454
+ * Which nodes stopped accepting the session key at the latest sign-out that ended a session; see
455
+ * `TinyCloudNode.nodeSignOutStatus()`. Resolves `undefined` before any. `signOut()` does not wait for these node
456
+ * calls, and only a node's first request, within a 48 KiB keepalive allowance, may outlive a page that unloads
457
+ * right after it, once the retire code (loaded when the session starts) has loaded.
458
+ */
459
+ nodeSignOutStatus: () => Promise<NodeSignOutStatus | undefined>;
440
460
  /**
441
461
  * Clears the stored session for `address` only while it is the signing-out session (`ownSignature`); a newer
442
462
  * session saved for the same address is left alone. The session is fenced first, so that a clear that fails
@@ -446,8 +466,23 @@ export declare class TinyCloudWeb {
446
466
  session: () => ClientSession | undefined;
447
467
  address: () => string | undefined;
448
468
  chainId: () => number | undefined;
449
- /** Returns whether the session or an unexpired runtime grant covers all entries. Never prompts. */
450
- hasPermissions(entries: PermissionEntry[]): boolean;
469
+ /**
470
+ * Returns whether the session or an unexpired runtime grant covers all entries. Never prompts. With
471
+ * `options.onBehalfOf`, only the session's own permissions and the grants approved for that app count; a grant
472
+ * approved for no app, or for another one, does not. Without it, every grant counts.
473
+ */
474
+ hasPermissions(entries: PermissionEntry[], options?: {
475
+ readonly onBehalfOf?: string;
476
+ }): boolean;
477
+ /** The apps each installed grant was approved for, by cid. Per node, so a new sign-in starts empty. */
478
+ private readonly grantAskers;
479
+ private grantAskersOf;
480
+ private grantCidsAskedBy;
481
+ /**
482
+ * Resolves once the grants kept from before a page reload are active again, or after at most four seconds. Never
483
+ * rejects. Call it before `hasPermissions` right after a reload, so an app is not under-granted.
484
+ */
485
+ permissionsReady(): Promise<void>;
451
486
  get did(): string;
452
487
  get sessionDid(): string;
453
488
  get credentialHolderDid(): string;
@@ -548,16 +583,47 @@ export declare class TinyCloudWeb {
548
583
  * `expiryMs` does not apply to them.
549
584
  *
550
585
  * `options.onBehalfOf` names the app the permissions are for when this
551
- * app asks on its behalf; the prompt names both. `options.allowPromptSuppression: false`
552
- * always shows the prompt, ignoring an earlier 30-day opt-out, and offers none.
586
+ * app asks on its behalf; the prompt names both. With it, only the session's own
587
+ * permissions and approvals given for that app count as already covering the request,
588
+ * and a new approval is signed for it even when another app's approval covers the same
589
+ * access. `options.allowPromptSuppression: false`
590
+ * always shows the prompt, ignoring an earlier 30-day opt-out, and offers none; a request
591
+ * to decrypt, create keys or read secrets always does so.
592
+ *
593
+ * An approved request that is not elevated (no decrypt or key creation, nothing in the secrets
594
+ * space, no caveats) is kept with the session and active again after a page reload, with its own
595
+ * signed expiry. An elevated one is not kept across a reload, except a grant made only of exact keys of the owner's
596
+ * own secrets (decrypt and/or key creation, any number of keys), which is kept for its signed expiry.
553
597
  */
554
598
  requestPermissions(additional: PermissionEntry[], options?: RequestPermissionsOptions): Promise<RequestPermissionsResult>;
599
+ /** `requestPermissions`; `keep` stores the issued non-elevated grants beside the session. The panel stores its own. */
600
+ private requestPermissionsKeeping;
601
+ /**
602
+ * Records which app approved each grant. A grant of one of the owner's secrets' own keys is always stored beside the
603
+ * session (TC-3284); the other non-elevated grants are stored when `keep`.
604
+ */
605
+ private keepGrants;
606
+ /**
607
+ * The signer a valid `setRuntimePermissionSigner` call bound to the current session, or undefined. A signer bound to a
608
+ * session that has ended or been replaced is cleared.
609
+ */
610
+ private boundRuntimeSigner;
611
+ /** Whether OpenKey signs the runtime grants: the bound signer declared itself OpenKey, or none is bound and `openkey` is configured. */
612
+ private runtimeSignedByOpenKey;
613
+ /**
614
+ * Whether OpenKey's own approval shows the request, so the SDK prompt is skipped: a bound signer that declared itself
615
+ * OpenKey passes the presentation on; the configured OpenKey client accepts one (`signMessagePresentation` is 1) and
616
+ * reports its approval screen shows the request (`signMessageShowsApproval` is true, which an external-wallet key is not).
617
+ * Otherwise the SDK prompt is shown as it is for any other signer, with its 30-day option.
618
+ */
619
+ private openKeyShowsApp;
555
620
  /**
556
621
  * Signs the SIWE of a runtime permission grant. Precedence: the signer set with `setRuntimePermissionSigner`, then
557
622
  * the configured OpenKey client's byte-exact `signMessage` (an OpenKey session's wallet provider does not implement
558
623
  * `personal_sign`), signing with the keyId of the connected account after connecting the client first when it is not
559
624
  * connected; a missing or ambiguous key throws `OpenKeySigningKeyError`. Without an OpenKey client or a session account,
560
625
  * undefined: the connected wallet signs. Only `requestPermissions` calls this; sign-in and session setup never do.
626
+ * `presentation` names the app beside the requesting origin in the OpenKey approval.
561
627
  */
562
628
  private runtimeMessageSigner;
563
629
  /**
@@ -569,8 +635,14 @@ export declare class TinyCloudWeb {
569
635
  * Call it after the session is established; it throws without one. It is bound to that session: sign-out, a new
570
636
  * sign-in, a restore, or a session for another account clear it. It is never used for sign-in or session setup.
571
637
  * Without it, grants sign through the `openkey` client when configured, else the connected wallet.
638
+ *
639
+ * `options.openKey: true` declares that the signer signs through OpenKey and passes the `presentation` it receives with
640
+ * the message on to OpenKey's approval. Permission requests then skip the SDK's own prompt, which OpenKey's approval replaces.
641
+ * Set it only for a signer that shows its own approval screen for every request; it is read from this call alone.
572
642
  */
573
- setRuntimePermissionSigner(signer?: RuntimePermissionSigner): void;
643
+ setRuntimePermissionSigner(signer?: RuntimePermissionSigner, options?: {
644
+ openKey?: boolean;
645
+ }): void;
574
646
  /** True when the panel may ask for a permission: a manifest, a page signer and a live session exist. */
575
647
  private canRequestPanelPermissions;
576
648
  /**