@tinycloud/web-sdk 3.12.0-beta.3 → 3.12.0-beta.30

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.
Files changed (40) hide show
  1. package/README.md +59 -8
  2. package/dist/adapters/BrowserSessionStorage.d.ts +13 -3
  3. package/dist/adapters/BrowserWasmBindings.d.ts +2 -0
  4. package/dist/delegations-issued.cjs +2 -1
  5. package/dist/delegations-issued.cjs.LICENSE.txt +5 -0
  6. package/dist/delegations-issued.mjs +2 -1
  7. package/dist/delegations-issued.mjs.LICENSE.txt +5 -0
  8. package/dist/delegations-renewal-entry.d.ts +3 -0
  9. package/dist/delegations-renewal.cjs +2 -0
  10. package/dist/delegations-renewal.cjs.LICENSE.txt +21 -0
  11. package/dist/delegations-renewal.mjs +2 -0
  12. package/dist/delegations-renewal.mjs.LICENSE.txt +21 -0
  13. package/dist/encryption-keys.cjs +1 -1
  14. package/dist/encryption-keys.cjs.LICENSE.txt +4 -0
  15. package/dist/encryption-keys.mjs +1 -1
  16. package/dist/encryption-keys.mjs.LICENSE.txt +4 -0
  17. package/dist/index.cjs +1 -1
  18. package/dist/index.cjs.LICENSE.txt +2 -0
  19. package/dist/index.d.ts +2 -0
  20. package/dist/index.mjs +1 -1
  21. package/dist/index.mjs.LICENSE.txt +2 -0
  22. package/dist/modals.cjs +1 -1
  23. package/dist/modals.mjs +1 -1
  24. package/dist/modules/Storage/tinycloud/module.d.ts +1 -0
  25. package/dist/modules/Storage/tinycloud/types.schema.d.ts +12 -12
  26. package/dist/modules/requestPermissionsCore.d.ts +0 -7
  27. package/dist/modules/restoreAccount.d.ts +13 -0
  28. package/dist/modules/runtimeGrantPersistence.d.ts +4 -2
  29. package/dist/modules/tcw.d.ts +34 -26
  30. package/dist/openkey-signing-key.d.ts +51 -0
  31. package/dist/panel.cjs +1 -1
  32. package/dist/panel.mjs +1 -1
  33. package/dist/replica.cjs +1 -1
  34. package/dist/replica.mjs +1 -1
  35. package/dist/space-hosting-entry.d.ts +1 -1
  36. package/dist/space-hosting.cjs +1 -1
  37. package/dist/space-hosting.mjs +1 -1
  38. package/dist/ui/pending.d.ts +1 -1
  39. package/dist/ui/strings.d.ts +2 -0
  40. package/package.json +9 -8
@@ -0,0 +1,13 @@
1
+ import { type PersistedSessionData } from "@tinycloud/sdk-core";
2
+ export declare class SessionAccountMismatchError extends Error {
3
+ readonly code = "ACCOUNT_MISMATCH";
4
+ constructor();
5
+ }
6
+ /** Address-only callers retain their existing chain selection; DID/CAIP callers pin it. */
7
+ export declare function requestedRestoreAccount(account: string): {
8
+ address: string;
9
+ chainId?: number;
10
+ };
11
+ /** Bind the request to the verified CACAO owner before restoring any session state. */
12
+ export declare function assertRequestedRestoreAccount(requested: string, session: Pick<PersistedSessionData, "address" | "chainId" | "tinycloudSession">): Promise<void>;
13
+ //# sourceMappingURL=restoreAccount.d.ts.map
@@ -3,7 +3,9 @@ export interface RuntimeGrantStore {
3
3
  loadRuntimeGrants(address: string): Promise<PortableDelegation[]>;
4
4
  saveRuntimeGrants(address: string, grants: readonly PortableDelegation[]): Promise<void>;
5
5
  }
6
- /** How long a restore waits for stored grants to be activated before it carries on without them. */
6
+ /** Serialize short storage mutations while grant activation runs independently. */
7
+ export declare function serializeRuntimeGrantMutation<T>(store: RuntimeGrantStore | undefined, mutation: () => Promise<T>): Promise<T>;
8
+ /** Bound for the automatic post-restore grant reactivation wait. */
7
9
  export declare const RESTORE_GRANT_BUDGET_MS = 4000;
8
10
  interface Resource {
9
11
  readonly service: string;
@@ -26,7 +28,7 @@ export declare function isPanelGrant(grant: PortableDelegation, address: string)
26
28
  * Stores the panel's own grants among `grants` for `address`, replacing a stored grant with the same cid. Other
27
29
  * delegations (an app's larger grant that already covered the request) are never stored.
28
30
  */
29
- export declare function rememberRuntimeGrants(store: RuntimeGrantStore, address: string, grants: readonly PortableDelegation[]): Promise<void>;
31
+ export declare function rememberRuntimeGrants(store: RuntimeGrantStore, address: string, grants: readonly PortableDelegation[], isCurrent?: () => boolean): Promise<void>;
30
32
  /**
31
33
  * Activates each stored grant through `use` (the SDK's validated activation). A grant refused for good is removed from
32
34
  * storage; the others stay, including one whose activation failed for a transient reason. Waits at most `budgetMs`;
@@ -35,6 +35,12 @@ export interface RuntimePermissionSigner {
35
35
  * Extends ClientConfig with browser-specific options.
36
36
  */
37
37
  export interface Config extends ClientConfig {
38
+ /** Write TCW2 network-key wraps. Disabled by default. */
39
+ keyWrapV2?: boolean;
40
+ /** Require TCW2 incoming network-key wraps, not signed receiver responses. Disabled by default. */
41
+ requireKeyWrapV2?: boolean;
42
+ /** Refuse explicitly designated legacy plaintext columns. Disabled by default. */
43
+ strictEncryption?: boolean;
38
44
  /**
39
45
  * OpenKey authorize-sign client. Requires @openkey/sdk >=0.12.2; popup is the default mode.
40
46
  *
@@ -118,7 +124,7 @@ export interface Config extends ClientConfig {
118
124
  persistSession?: boolean;
119
125
  /** Custom session storage implementation. */
120
126
  sessionStorage?: ISessionStorage;
121
- /** Whether to run node-sdk's canonical first-account bootstrap after sign-in. */
127
+ /** Enable first-party account bootstrap. Defaults on only at approved first-party page origins; false also omits implicit account and capabilities-read grants. */
122
128
  autoBootstrapAccount?: boolean;
123
129
  /** Browser storage key prefix for isolating apps/environments. */
124
130
  sessionStorageKeyPrefix?: string;
@@ -144,7 +150,7 @@ export interface Config extends ClientConfig {
144
150
  capabilityRequest?: ComposedManifestRequest;
145
151
  /** Strategy for TinyCloud root signature requests. */
146
152
  signStrategy?: SignStrategy;
147
- /** Include canonical account registry read/create-update/list permissions in plain sessions and composed manifests. Default true. */
153
+ /** Include implicit account registry/bootstrap authority. First-party only; false or autoBootstrapAccount:false disables it. Third-party origins always omit it. */
148
154
  includeAccountRegistryPermissions?: boolean;
149
155
  /** Default-off service telemetry. */
150
156
  telemetry?: TelemetryConfig;
@@ -184,14 +190,15 @@ export interface ShareReceiveResult<T = unknown> {
184
190
  delegation: Delegation;
185
191
  path: string;
186
192
  spaceId: string;
187
- /** Owner Node named by the link; that node independently verifies the accompanying delegation. */
193
+ /** Identity-checked registry destination where the verified parent was activated. */
188
194
  host: string;
189
195
  }
190
196
  export declare class TinyCloudWeb {
191
197
  private openkeySignInInFlight;
192
198
  private prepareSignInToken;
193
- /** How long a restore waits for the node's hosting answer. */
199
+ /** Time bound for the background hosting probe. */
194
200
  private spaceHostingCapMs;
201
+ private restoredNetworkWork?;
195
202
  private preparedSignIn?;
196
203
  private invalidatePreparedSignIn;
197
204
  /** The connected wallet's raw EIP-1193 provider. */
@@ -223,9 +230,8 @@ export declare class TinyCloudWeb {
223
230
  private signOutCount;
224
231
  /** The signer set with `setRuntimePermissionSigner`, with the session it was set for. */
225
232
  private runtimeSigner?;
226
- /** Set when this instance's session was established through the configured OpenKey client; bound to that session like `runtimeSigner`. */
227
- private openkeySession?;
228
233
  private signOutInFlight;
234
+ private signOutOperation?;
229
235
  private persistedRestoreBlocked;
230
236
  private signOutCleanupFailed;
231
237
  private remoteSignOutTimeoutMs;
@@ -261,6 +267,7 @@ export declare class TinyCloudWeb {
261
267
  */
262
268
  private _testHooks?;
263
269
  constructor(callerConfig?: Config);
270
+ private bootstrapSignInPolicy;
264
271
  /**
265
272
  * Async initialization: ensure WASM is ready, then create TinyCloudNode.
266
273
  * @internal
@@ -271,6 +278,8 @@ export declare class TinyCloudWeb {
271
278
  * @internal
272
279
  */
273
280
  private ensureNode;
281
+ /** Bind a wrapper call to its entry-time authority before initialization can yield. */
282
+ private dispatchCurrentNode;
274
283
  /**
275
284
  * Get the TinyCloudNode instance synchronously.
276
285
  * Throws if called before WASM initialization completes.
@@ -327,7 +336,7 @@ export declare class TinyCloudWeb {
327
336
  get delegations(): DelegationManager;
328
337
  get capabilityRegistry(): ICapabilityKeyRegistry;
329
338
  get spaceId(): string | undefined;
330
- /** The node's last answer for whether the primary space is hosted (`"unknown"` until it has answered). */
339
+ /** Hosting display hint bound to account, space and host, corrected by the automatic background probe. */
331
340
  get spaceHosting(): SpaceHosting;
332
341
  get accountSpaceId(): string | undefined;
333
342
  get account(): AccountService;
@@ -377,6 +386,14 @@ export declare class TinyCloudWeb {
377
386
  private trackRestoreAddress;
378
387
  private untrackRestoreAddress;
379
388
  restoreSession(address?: string): Promise<SessionRestoreResult>;
389
+ /**
390
+ * Restore an expired browser session only when the owner-signed lease admission
391
+ * and the node's independently verified renewal history extend its authority.
392
+ * The lease authorization must come from an owner-approved source, not storage metadata.
393
+ */
394
+ restoreSessionWithRenewal(leaseAuthorization: string, address?: string): Promise<SessionRestoreResult>;
395
+ private restoreSessionInternal;
396
+ private startRestoredNetworkWork;
380
397
  /** One node read for the restored session, held to {@link spaceHostingCapMs}; past it, or on any failure, the answer stays unknown. */
381
398
  private probeSpaceHosting;
382
399
  private spaceHostingInFlight?;
@@ -393,6 +410,7 @@ export declare class TinyCloudWeb {
393
410
  * resolves `"unknown"` when the node has no hosting answer.
394
411
  * Rejects with `Error("Space hosting was cancelled by sign-out.")` if sign-out
395
412
  * happens during the hosting run. Call from a user gesture so the approval popup can open.
413
+ * Also rejects if the initiating session is replaced before hosting finishes.
396
414
  */
397
415
  ensureSpaceHosted(): Promise<SpaceHosting>;
398
416
  clearPersistedSession(address?: string): Promise<void>;
@@ -459,6 +477,10 @@ export declare class TinyCloudWeb {
459
477
  disableSubDelegation?: boolean;
460
478
  expiryMs?: number;
461
479
  }): Promise<PortableDelegation>;
480
+ /** Owner-sign and admit a bounded renewal lease for the current session. */
481
+ createRenewalLease(expiresAt: Date): Promise<Awaited<ReturnType<TinyCloudNode["createRenewalLease"]>>>;
482
+ /** Verify current node-admitted renewal authority for the current session. */
483
+ getRenewalEffectiveExpiry(leaseAuthorization: string): Promise<number>;
462
484
  /** Create and activate a wallet-rooted delegation for an ephemeral share key. */
463
485
  createOwnerDelegation(params: CreateOwnerDelegationParams extends infer PermissionShape ? PermissionShape extends CreateOwnerDelegationParams ? Omit<PermissionShape, "spaceId"> & {
464
486
  readonly spaceId?: string;
@@ -514,8 +536,6 @@ export declare class TinyCloudWeb {
514
536
  * On approve, this does not mutate the manifest or force a new sign-in.
515
537
  * The underlying node creates a secondary delegation to the current
516
538
  * session key and records it in the invocation permission map.
517
- * Exact current-owner `default/share/<id>` key creation is bound to this
518
- * live signed session across consent. Native shells cannot request it.
519
539
  *
520
540
  * `options.expiryMs` sets the requested lifetime of the issued step-up
521
541
  * delegation, in milliseconds. Omitted, the node's default applies. The
@@ -528,24 +548,12 @@ export declare class TinyCloudWeb {
528
548
  requestPermissions(additional: PermissionEntry[], options?: RequestPermissionsOptions): Promise<RequestPermissionsResult>;
529
549
  /**
530
550
  * Signs the SIWE of a runtime permission grant. Precedence: the signer set with `setRuntimePermissionSigner`, then
531
- * the OpenKey client the session was established with (its byte-exact `signMessage`; an OpenKey session's wallet
532
- * provider does not implement `personal_sign`), then undefined: the connected wallet signs. Only
533
- * `requestPermissions` calls this; sign-in and session setup never do.
551
+ * the configured OpenKey client's byte-exact `signMessage` (an OpenKey session's wallet provider does not implement
552
+ * `personal_sign`), signing with the keyId of the connected account after connecting the client first when it is not
553
+ * connected; a missing or ambiguous key throws `OpenKeySigningKeyError`. Without an OpenKey client or a session account,
554
+ * undefined: the connected wallet signs. Only `requestPermissions` calls this; sign-in and session setup never do.
534
555
  */
535
556
  private runtimeMessageSigner;
536
- /**
537
- * Whether the OpenKey client may sign a runtime grant: always, unless there is POSITIVE evidence that it is not connected. It may sign when
538
- * this instance's session was established through it (and is still the live session), or when its in-memory `lastAuth` is set (`connect()` ran
539
- * on this client, for example because the app connected it after a restore), or when it exposes no `lastAuth` at all (a client shape this SDK
540
- * does not know: today's behaviour, fail open). `lastAuth` is read here because nothing public says it: `@openkey/sdk` 0.12.2 declares
541
- * `lastAuth = null`, sets it in `connect()` and clears it in `signOut()`; 0.9.0 declares it and sets it in `connect()` but has no `signOut`.
542
- * `getSessionToken()` always answers null in 0.12.2 and `isConnected()` reads the OpenKey cookie, which can be true when `connect()` never ran
543
- * on this page. web-sdk documents `@openkey/sdk` >= 0.12.2, so 0.12.2 is the lowest version this was checked against. The clean fix is
544
- * `signMessage()` rejecting when not connected, in `@openkey/sdk`. Trade-off: an app that connects through a DIFFERENT OpenKey instance than
545
- * `config.openkey.client`, or restores after an authorize-only sign-in, must call `openkey.connect()` on the configured client or
546
- * `setRuntimePermissionSigner`.
547
- */
548
- private openkeyClientMaySign;
549
557
  /**
550
558
  * Sets the signer for runtime permission grants (`requestPermissions`, and the panel's "allow" buttons), or clears
551
559
  * it with no argument. For apps whose sign-in is not the SDK's OpenKey flow, for example a restored session whose
@@ -585,7 +593,7 @@ export declare class TinyCloudWeb {
585
593
  checkPermission(path: string, action: string): Promise<Result<boolean, DelegationError>>;
586
594
  /**
587
595
  * Receive and retrieve data from a native TinyCloud bearer delegation.
588
- * Static method — no auth required. Uses browser WASM.
596
+ * Static method — no sign-in required. Verifies the parent with browser WASM and routes through the owner's registry.
589
597
  */
590
598
  static receiveShare<T = unknown>(link: string, key?: string, options?: {
591
599
  readonly binary?: boolean;
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Why the SDK did not ask OpenKey to sign.
3
+ *
4
+ * - `OPENKEY_KEY_MISSING`: there is no OpenKey key to sign with. The client is not connected and cannot connect, or its
5
+ * `connect()` answered without a `keyId`.
6
+ * - `OPENKEY_KEY_AMBIGUOUS`: the connected OpenKey key cannot be tied to the session's account: its address is another
7
+ * account's, or it reports none.
8
+ * - `OPENKEY_CONNECTED_RETRY`: popup mode only. The client was not connected, so the SDK connected it. The user needed longer in
9
+ * that popup than the click's user activation lasts, so a sign popup opened right after would be blocked by the browser.
10
+ * Nothing was signed. The client is now connected: ask the user to click Allow again, which signs with the connected key
11
+ * in one popup. Iframe and redirect mode connect and sign in one go and never throw this.
12
+ *
13
+ * None of these opens a sign dialog: the SDK never sends `signMessage` without the keyId of the connected account.
14
+ * Connect the configured client as the session's account (`await openkey.connect()`), or sign runtime grants with
15
+ * `TinyCloudWeb.setRuntimePermissionSigner`.
16
+ */
17
+ export type OpenKeySigningKeyErrorCode = "OPENKEY_KEY_MISSING" | "OPENKEY_KEY_AMBIGUOUS" | "OPENKEY_CONNECTED_RETRY";
18
+ /**
19
+ * Thrown by `TinyCloudWeb.requestPermissions` (and the panel's "allow" buttons, which call it) when the runtime grant
20
+ * must be signed through the configured OpenKey client but no single connected key can be named, or when the SDK just
21
+ * connected the client in popup mode and the user must click again.
22
+ * `code` is an {@link OpenKeySigningKeyErrorCode}; `name` is `"OpenKeySigningKeyError"`.
23
+ */
24
+ export declare class OpenKeySigningKeyError extends Error {
25
+ readonly code: OpenKeySigningKeyErrorCode;
26
+ readonly name = "OpenKeySigningKeyError";
27
+ constructor(code: OpenKeySigningKeyErrorCode, message: string);
28
+ }
29
+ /** What `@openkey/sdk`'s `connect()` answers (and keeps in `lastAuth`) that this SDK reads. */
30
+ export interface OpenKeyAuthLike {
31
+ readonly keyId?: unknown;
32
+ readonly address?: unknown;
33
+ }
34
+ /** The parts of an `@openkey/sdk` client the key lookup reads. `lastAuth` is set by `connect()` and cleared by `signOut()`; nothing public says whether the client is connected. */
35
+ export interface OpenKeyConnection {
36
+ readonly lastAuth?: OpenKeyAuthLike | null;
37
+ connect?(opts: {
38
+ mode: "iframe" | "popup" | "redirect";
39
+ }): Promise<OpenKeyAuthLike | null | undefined>;
40
+ }
41
+ /**
42
+ * The keyId OpenKey must sign with for `account`: the connected key (`lastAuth`; a getter that throws reads as not
43
+ * connected), else the key `client.connect()` returns, after connecting it first. The key's address must be `account`,
44
+ * case-insensitively. `assertCurrent` runs right after `connect()` and throws when the session ended or changed while the
45
+ * dialog was open.
46
+ *
47
+ * @throws {OpenKeySigningKeyError} no key, a key that is not `account`'s, or (popup mode) a client that was just connected.
48
+ * Whatever `connect()` rejects with (the user closing the dialog) propagates unchanged.
49
+ */
50
+ export declare function resolveOpenKeySigningKey(client: OpenKeyConnection, account: string, mode: "iframe" | "popup" | "redirect", assertCurrent: () => void): Promise<string>;
51
+ //# sourceMappingURL=openkey-signing-key.d.ts.map