@tinycloud/web-sdk 3.12.0-beta.2 → 3.12.0-beta.21

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.
@@ -9,6 +9,8 @@
9
9
 
10
10
  /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
11
11
 
12
+ /*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */
13
+
12
14
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
13
15
 
14
16
  /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
@@ -6,6 +6,7 @@ export declare const prepareSession: TinyCloudModule['prepareSession'];
6
6
  export declare const completeSessionSetup: TinyCloudModule['completeSessionSetup'];
7
7
  export declare const invoke: InvokeFunction;
8
8
  export declare const invokeAny: TinyCloudModule['invokeAny'];
9
+ export declare const invokeDelegationStatus: TinyCloudModule["invokeDelegationStatus"];
9
10
  export declare const generateHostSIWEMessage: TinyCloudModule['generateHostSIWEMessage'];
10
11
  export declare const siweToDelegationHeaders: TinyCloudModule['siweToDelegationHeaders'];
11
12
  export {};
@@ -36,10 +36,10 @@ export declare const SessionConfigSchema: z.ZodObject<{
36
36
  domain?: string;
37
37
  actions?: Record<string, Record<string, string[]>>;
38
38
  spaceId?: string;
39
- jwk?: Record<string, unknown>;
40
39
  address?: string;
41
40
  chainId?: number;
42
41
  issuedAt?: string;
42
+ jwk?: Record<string, unknown>;
43
43
  notBefore?: string;
44
44
  expirationTime?: string;
45
45
  parents?: string[];
@@ -47,10 +47,10 @@ export declare const SessionConfigSchema: z.ZodObject<{
47
47
  domain?: string;
48
48
  actions?: Record<string, Record<string, string[]>>;
49
49
  spaceId?: string;
50
- jwk?: Record<string, unknown>;
51
50
  address?: string;
52
51
  chainId?: number;
53
52
  issuedAt?: string;
53
+ jwk?: Record<string, unknown>;
54
54
  notBefore?: string;
55
55
  expirationTime?: string;
56
56
  parents?: string[];
@@ -78,18 +78,18 @@ export declare const SessionSchema: z.ZodObject<{
78
78
  verificationMethod: z.ZodString;
79
79
  }, "strip", z.ZodTypeAny, {
80
80
  spaceId?: string;
81
- jwk?: Record<string, unknown>;
82
81
  delegationHeader?: {
83
82
  Authorization?: string;
84
83
  };
84
+ jwk?: Record<string, unknown>;
85
85
  delegationCid?: string;
86
86
  verificationMethod?: string;
87
87
  }, {
88
88
  spaceId?: string;
89
- jwk?: Record<string, unknown>;
90
89
  delegationHeader?: {
91
90
  Authorization?: string;
92
91
  };
92
+ jwk?: Record<string, unknown>;
93
93
  delegationCid?: string;
94
94
  verificationMethod?: string;
95
95
  }>;
@@ -15,8 +15,6 @@ import type { PortableDelegation } from "@tinycloud/node-sdk/core";
15
15
  export interface RequestPermissionsCoreDeps {
16
16
  /** Current stored manifest. Must be defined — caller validates first. */
17
17
  manifest: Manifest;
18
- /** Authenticated owner from the current node, never from a requested resource. */
19
- ownerDid?: string;
20
18
  /**
21
19
  * Show the permission request modal. Resolves with `{ approved }`
22
20
  * once the user interacts. In tests this is a stub; in production it
@@ -51,11 +49,6 @@ export interface RequestPermissionsOptions {
51
49
  * the same error text.
52
50
  */
53
51
  export declare function validateAdditionalPermissions(additional: PermissionEntry[]): void;
54
- /**
55
- * Normalize only encryption key creation here. Other runtime entries retain
56
- * their existing Web consent representation; the node validates them.
57
- */
58
- export declare function normalizeRuntimeKeyCreatePermissions(additional: PermissionEntry[], ownerDid?: string): PermissionEntry[];
59
52
  /**
60
53
  * Core escalation flow. See the TinyCloudWeb.requestPermissions JSDoc
61
54
  * for the full spec-level description — this function is the plumbing.
@@ -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`;
@@ -11,7 +11,7 @@
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
13
  import { type LocalCopyPurgeFailedEvent } from "./replica-wiring";
14
- 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 RegistryPolicy, type RegistrySequenceStore, SignInOptions, type StorageFullEvent, type IStorageService } from "@tinycloud/sdk-core";
14
+ 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
15
  import { type RequestPermissionsOptions } from "./requestPermissionsCore";
16
16
  import { type BrowserProvider, type BrowserWalletProvider } from "../adapters/browserProvider";
17
17
  import { type TinyCloudUI, type UiConfig } from "../ui";
@@ -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
  *
@@ -62,33 +68,23 @@ export interface Config extends ClientConfig {
62
68
  spacePrefix?: string;
63
69
  /** Local KV replication. Off unless set; node-sdk validates the config and owns the storage. */
64
70
  replication?: TinyCloudNodeConfig["replication"];
65
- /** Explicit TinyCloud server hosts. When omitted, signIn resolves the user's host. */
71
+ /** Explicit host hints for owners absent from both registry namespaces. Signed v2 entries select their own hosts. */
66
72
  tinycloudHosts?: string[];
67
73
  /** TinyCloud location registry URL. Default: https://registry.tinycloud.xyz. */
68
74
  tinycloudRegistryUrl?: string | null;
69
- /**
70
- * Fallback TinyCloud hosts. Default: hosted TinyCloud node. Used only by the
71
- * default `registryPolicy` ("legacy-fallback"), whose silent fallback is
72
- * deprecated and will be removed in a future major release.
73
- */
74
- tinycloudFallbackHosts?: string[] | null;
75
- /**
76
- * How sign-in uses the location registry when no `tinycloudHosts` are set.
77
- * Default `"legacy-fallback"` (deprecated). `"fail-closed"` routes on the
78
- * registry verdict for the wallet address and refuses automatic space
79
- * creation on a host the owner's registry record does not list, or when
80
- * the registry gives no verdict. See `TinyCloudNodeConfig.registryPolicy`.
81
- */
82
- registryPolicy?: RegistryPolicy;
83
- /** `fail-closed` only: host for owners with no registry record. Default https://node.tinycloud.xyz; `null` refuses them. */
75
+ /** Host hint for owners absent from both v2 and v1 registries. Default https://node.tinycloud.xyz; null disables onboarding. */
84
76
  newUserHost?: string | null;
85
- /** `fail-closed` only: chain ID of the v1 registry subject built from the wallet address. Default 1. */
77
+ /** Chain ID used to distinguish a v1-only owner from an owner with no registry entry. Default 1. */
86
78
  registryChainId?: number;
87
- /** `fail-closed` only: highest registry sequence seen per owner. Default: a `localStorage`-backed store. */
79
+ /** Highest signed v2 sequence seen per owner. Default: a `localStorage`-backed store. */
88
80
  registrySequenceStore?: RegistrySequenceStore;
89
- /** `fail-closed` only: retry, use another host (not identity-checked; it persists with the session), or abort when sign-in resolves no host. Without it, sign-in throws. */
81
+ /** Exact signed responses in browser storage, reverified on every routing read. */
82
+ registryCacheStore?: RegistryCacheStore;
83
+ /** Called after an actual cached-settings or default-node fallback. */
84
+ onRegistryFallback?: TinyCloudNodeConfig["onRegistryFallback"];
85
+ /** Called only when no host resolves for a genuinely unregistered owner. */
90
86
  onNodeNotFound?: OnNodeNotFound;
91
- /** Probe configured/registered local nodes before registry/fallback resolution. Default: true. */
87
+ /** Probe local nodes only for owners absent from both registry namespaces. Default: true. */
92
88
  autoDiscoverLocalNode?: boolean;
93
89
  /** Local loopback node URL to probe. Omit to avoid probing loopback. */
94
90
  localNodeUrl?: string;
@@ -194,14 +190,15 @@ export interface ShareReceiveResult<T = unknown> {
194
190
  delegation: Delegation;
195
191
  path: string;
196
192
  spaceId: string;
197
- /** Owner Node named by the link; that node independently verifies the accompanying delegation. */
193
+ /** Identity-checked registry destination where the verified parent was activated. */
198
194
  host: string;
199
195
  }
200
196
  export declare class TinyCloudWeb {
201
197
  private openkeySignInInFlight;
202
198
  private prepareSignInToken;
203
- /** How long a restore waits for the node's hosting answer. */
199
+ /** Time bound for the background hosting probe. */
204
200
  private spaceHostingCapMs;
201
+ private restoredNetworkWork?;
205
202
  private preparedSignIn?;
206
203
  private invalidatePreparedSignIn;
207
204
  /** The connected wallet's raw EIP-1193 provider. */
@@ -233,9 +230,8 @@ export declare class TinyCloudWeb {
233
230
  private signOutCount;
234
231
  /** The signer set with `setRuntimePermissionSigner`, with the session it was set for. */
235
232
  private runtimeSigner?;
236
- /** Set when this instance's session was established through the configured OpenKey client; bound to that session like `runtimeSigner`. */
237
- private openkeySession?;
238
233
  private signOutInFlight;
234
+ private signOutOperation?;
239
235
  private persistedRestoreBlocked;
240
236
  private signOutCleanupFailed;
241
237
  private remoteSignOutTimeoutMs;
@@ -281,6 +277,8 @@ export declare class TinyCloudWeb {
281
277
  * @internal
282
278
  */
283
279
  private ensureNode;
280
+ /** Bind a wrapper call to its entry-time authority before initialization can yield. */
281
+ private dispatchCurrentNode;
284
282
  /**
285
283
  * Get the TinyCloudNode instance synchronously.
286
284
  * Throws if called before WASM initialization completes.
@@ -337,7 +335,7 @@ export declare class TinyCloudWeb {
337
335
  get delegations(): DelegationManager;
338
336
  get capabilityRegistry(): ICapabilityKeyRegistry;
339
337
  get spaceId(): string | undefined;
340
- /** The node's last answer for whether the primary space is hosted (`"unknown"` until it has answered). */
338
+ /** Hosting display hint bound to account, space and host, corrected by the automatic background probe. */
341
339
  get spaceHosting(): SpaceHosting;
342
340
  get accountSpaceId(): string | undefined;
343
341
  get account(): AccountService;
@@ -387,6 +385,14 @@ export declare class TinyCloudWeb {
387
385
  private trackRestoreAddress;
388
386
  private untrackRestoreAddress;
389
387
  restoreSession(address?: string): Promise<SessionRestoreResult>;
388
+ /**
389
+ * Restore an expired browser session only when the owner-signed lease admission
390
+ * and the node's independently verified renewal history extend its authority.
391
+ * The lease authorization must come from an owner-approved source, not storage metadata.
392
+ */
393
+ restoreSessionWithRenewal(leaseAuthorization: string, address?: string): Promise<SessionRestoreResult>;
394
+ private restoreSessionInternal;
395
+ private startRestoredNetworkWork;
390
396
  /** One node read for the restored session, held to {@link spaceHostingCapMs}; past it, or on any failure, the answer stays unknown. */
391
397
  private probeSpaceHosting;
392
398
  private spaceHostingInFlight?;
@@ -403,6 +409,7 @@ export declare class TinyCloudWeb {
403
409
  * resolves `"unknown"` when the node has no hosting answer.
404
410
  * Rejects with `Error("Space hosting was cancelled by sign-out.")` if sign-out
405
411
  * happens during the hosting run. Call from a user gesture so the approval popup can open.
412
+ * Also rejects if the initiating session is replaced before hosting finishes.
406
413
  */
407
414
  ensureSpaceHosted(): Promise<SpaceHosting>;
408
415
  clearPersistedSession(address?: string): Promise<void>;
@@ -469,6 +476,10 @@ export declare class TinyCloudWeb {
469
476
  disableSubDelegation?: boolean;
470
477
  expiryMs?: number;
471
478
  }): Promise<PortableDelegation>;
479
+ /** Owner-sign and admit a bounded renewal lease for the current session. */
480
+ createRenewalLease(expiresAt: Date): Promise<Awaited<ReturnType<TinyCloudNode["createRenewalLease"]>>>;
481
+ /** Verify current node-admitted renewal authority for the current session. */
482
+ getRenewalEffectiveExpiry(leaseAuthorization: string): Promise<number>;
472
483
  /** Create and activate a wallet-rooted delegation for an ephemeral share key. */
473
484
  createOwnerDelegation(params: CreateOwnerDelegationParams extends infer PermissionShape ? PermissionShape extends CreateOwnerDelegationParams ? Omit<PermissionShape, "spaceId"> & {
474
485
  readonly spaceId?: string;
@@ -524,8 +535,6 @@ export declare class TinyCloudWeb {
524
535
  * On approve, this does not mutate the manifest or force a new sign-in.
525
536
  * The underlying node creates a secondary delegation to the current
526
537
  * session key and records it in the invocation permission map.
527
- * Exact current-owner `default/share/<id>` key creation is bound to this
528
- * live signed session across consent. Native shells cannot request it.
529
538
  *
530
539
  * `options.expiryMs` sets the requested lifetime of the issued step-up
531
540
  * delegation, in milliseconds. Omitted, the node's default applies. The
@@ -538,24 +547,12 @@ export declare class TinyCloudWeb {
538
547
  requestPermissions(additional: PermissionEntry[], options?: RequestPermissionsOptions): Promise<RequestPermissionsResult>;
539
548
  /**
540
549
  * Signs the SIWE of a runtime permission grant. Precedence: the signer set with `setRuntimePermissionSigner`, then
541
- * the OpenKey client the session was established with (its byte-exact `signMessage`; an OpenKey session's wallet
542
- * provider does not implement `personal_sign`), then undefined: the connected wallet signs. Only
543
- * `requestPermissions` calls this; sign-in and session setup never do.
550
+ * the configured OpenKey client's byte-exact `signMessage` (an OpenKey session's wallet provider does not implement
551
+ * `personal_sign`), signing with the keyId of the connected account after connecting the client first when it is not
552
+ * connected; a missing or ambiguous key throws `OpenKeySigningKeyError`. Without an OpenKey client or a session account,
553
+ * undefined: the connected wallet signs. Only `requestPermissions` calls this; sign-in and session setup never do.
544
554
  */
545
555
  private runtimeMessageSigner;
546
- /**
547
- * Whether the OpenKey client may sign a runtime grant: always, unless there is POSITIVE evidence that it is not connected. It may sign when
548
- * this instance's session was established through it (and is still the live session), or when its in-memory `lastAuth` is set (`connect()` ran
549
- * 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
550
- * does not know: today's behaviour, fail open). `lastAuth` is read here because nothing public says it: `@openkey/sdk` 0.12.2 declares
551
- * `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`.
552
- * `getSessionToken()` always answers null in 0.12.2 and `isConnected()` reads the OpenKey cookie, which can be true when `connect()` never ran
553
- * 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
554
- * `signMessage()` rejecting when not connected, in `@openkey/sdk`. Trade-off: an app that connects through a DIFFERENT OpenKey instance than
555
- * `config.openkey.client`, or restores after an authorize-only sign-in, must call `openkey.connect()` on the configured client or
556
- * `setRuntimePermissionSigner`.
557
- */
558
- private openkeyClientMaySign;
559
556
  /**
560
557
  * Sets the signer for runtime permission grants (`requestPermissions`, and the panel's "allow" buttons), or clears
561
558
  * it with no argument. For apps whose sign-in is not the SDK's OpenKey flow, for example a restored session whose
@@ -595,7 +592,7 @@ export declare class TinyCloudWeb {
595
592
  checkPermission(path: string, action: string): Promise<Result<boolean, DelegationError>>;
596
593
  /**
597
594
  * Receive and retrieve data from a native TinyCloud bearer delegation.
598
- * Static method — no auth required. Uses browser WASM.
595
+ * Static method — no sign-in required. Verifies the parent with browser WASM and routes through the owner's registry.
599
596
  */
600
597
  static receiveShare<T = unknown>(link: string, key?: string, options?: {
601
598
  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