@tinycloud/web-sdk 3.11.1 → 3.12.0-beta.10
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.
- package/README.md +53 -3
- package/dist/adapters/BrowserSessionStorage.d.ts +8 -0
- package/dist/delegations-issued.cjs +2 -1
- package/dist/delegations-issued.cjs.LICENSE.txt +5 -0
- package/dist/delegations-issued.mjs +2 -1
- package/dist/delegations-issued.mjs.LICENSE.txt +5 -0
- package/dist/encryption-keys.cjs +1 -1
- package/dist/encryption-keys.cjs.LICENSE.txt +4 -0
- package/dist/encryption-keys.mjs +1 -1
- package/dist/encryption-keys.mjs.LICENSE.txt +4 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.LICENSE.txt +2 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.LICENSE.txt +2 -0
- package/dist/modules/tcw.d.ts +61 -42
- package/dist/openkey-signing-key.d.ts +51 -0
- package/dist/replica.cjs +1 -1
- package/dist/replica.mjs +1 -1
- package/dist/space-hosting-entry.d.ts +3 -0
- package/dist/space-hosting.cjs +1 -0
- package/dist/space-hosting.mjs +1 -0
- package/package.json +6 -5
|
@@ -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) */
|
package/dist/modules/tcw.d.ts
CHANGED
|
@@ -11,13 +11,13 @@
|
|
|
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
|
|
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";
|
|
18
18
|
import { RPCProviders, ClientConfig } from "../providers";
|
|
19
19
|
import type { NotificationConfig } from "../notifications/types";
|
|
20
|
-
import type { PortableDelegation, DelegatedAccess } from "@tinycloud/node-sdk/core";
|
|
20
|
+
import type { PortableDelegation, DelegatedAccess, SpaceHosting } from "@tinycloud/node-sdk/core";
|
|
21
21
|
import { CredentialsService } from "../credentials";
|
|
22
22
|
import { ShareReceiverService, type ShareReceiverServiceOptions } from "../share";
|
|
23
23
|
declare global {
|
|
@@ -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
|
|
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
|
-
/**
|
|
77
|
+
/** Chain ID used to distinguish a v1-only owner from an owner with no registry entry. Default 1. */
|
|
86
78
|
registryChainId?: number;
|
|
87
|
-
/**
|
|
79
|
+
/** Highest signed v2 sequence seen per owner. Default: a `localStorage`-backed store. */
|
|
88
80
|
registrySequenceStore?: RegistrySequenceStore;
|
|
89
|
-
/**
|
|
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
|
|
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;
|
|
@@ -181,6 +177,11 @@ export interface SessionRestoreResult {
|
|
|
181
177
|
session?: ClientSession;
|
|
182
178
|
error?: Error;
|
|
183
179
|
}
|
|
180
|
+
/** A session storage that can fence a signed-out session (BrowserSessionStorage); others rely on the in-memory block. */
|
|
181
|
+
export type FenceCapableStorage = ISessionStorage & {
|
|
182
|
+
markSignedOut?: (address: string, signature: string) => void;
|
|
183
|
+
isSignedOut?: (address: string, signature: string) => boolean;
|
|
184
|
+
};
|
|
184
185
|
/**
|
|
185
186
|
* Result of receiving a share link.
|
|
186
187
|
*/
|
|
@@ -189,12 +190,14 @@ export interface ShareReceiveResult<T = unknown> {
|
|
|
189
190
|
delegation: Delegation;
|
|
190
191
|
path: string;
|
|
191
192
|
spaceId: string;
|
|
192
|
-
/**
|
|
193
|
+
/** Identity-checked registry destination where the verified parent was activated. */
|
|
193
194
|
host: string;
|
|
194
195
|
}
|
|
195
196
|
export declare class TinyCloudWeb {
|
|
196
197
|
private openkeySignInInFlight;
|
|
197
198
|
private prepareSignInToken;
|
|
199
|
+
/** How long a restore waits for the node's hosting answer. */
|
|
200
|
+
private spaceHostingCapMs;
|
|
198
201
|
private preparedSignIn?;
|
|
199
202
|
private invalidatePreparedSignIn;
|
|
200
203
|
/** The connected wallet's raw EIP-1193 provider. */
|
|
@@ -226,11 +229,10 @@ export declare class TinyCloudWeb {
|
|
|
226
229
|
private signOutCount;
|
|
227
230
|
/** The signer set with `setRuntimePermissionSigner`, with the session it was set for. */
|
|
228
231
|
private runtimeSigner?;
|
|
229
|
-
/** Set when this instance's session was established through the configured OpenKey client; bound to that session like `runtimeSigner`. */
|
|
230
|
-
private openkeySession?;
|
|
231
232
|
private signOutInFlight;
|
|
232
233
|
private persistedRestoreBlocked;
|
|
233
234
|
private signOutCleanupFailed;
|
|
235
|
+
private remoteSignOutTimeoutMs;
|
|
234
236
|
private readonly pendingRestoreAddresses;
|
|
235
237
|
private _secrets;
|
|
236
238
|
private _credentialsService?;
|
|
@@ -273,6 +275,8 @@ export declare class TinyCloudWeb {
|
|
|
273
275
|
* @internal
|
|
274
276
|
*/
|
|
275
277
|
private ensureNode;
|
|
278
|
+
/** Bind a wrapper call to its entry-time authority before initialization can yield. */
|
|
279
|
+
private dispatchCurrentNode;
|
|
276
280
|
/**
|
|
277
281
|
* Get the TinyCloudNode instance synchronously.
|
|
278
282
|
* Throws if called before WASM initialization completes.
|
|
@@ -329,6 +333,8 @@ export declare class TinyCloudWeb {
|
|
|
329
333
|
get delegations(): DelegationManager;
|
|
330
334
|
get capabilityRegistry(): ICapabilityKeyRegistry;
|
|
331
335
|
get spaceId(): string | undefined;
|
|
336
|
+
/** The node's last answer for whether the primary space is hosted (`"unknown"` until it has answered). */
|
|
337
|
+
get spaceHosting(): SpaceHosting;
|
|
332
338
|
get accountSpaceId(): string | undefined;
|
|
333
339
|
get account(): AccountService;
|
|
334
340
|
get hosts(): string[];
|
|
@@ -377,6 +383,25 @@ export declare class TinyCloudWeb {
|
|
|
377
383
|
private trackRestoreAddress;
|
|
378
384
|
private untrackRestoreAddress;
|
|
379
385
|
restoreSession(address?: string): Promise<SessionRestoreResult>;
|
|
386
|
+
/** One node read for the restored session, held to {@link spaceHostingCapMs}; past it, or on any failure, the answer stays unknown. */
|
|
387
|
+
private probeSpaceHosting;
|
|
388
|
+
private spaceHostingInFlight?;
|
|
389
|
+
/**
|
|
390
|
+
* Host a restored session's primary space only when the node reports it
|
|
391
|
+
* missing. Reuses that session and its existing creation confirmation.
|
|
392
|
+
* Call from a user gesture so the approval popup can open.
|
|
393
|
+
*/
|
|
394
|
+
private restoredSessionNotHosted;
|
|
395
|
+
/**
|
|
396
|
+
* Ensure the primary space is hosted, asking for approval only when needed.
|
|
397
|
+
* Resolves `"hosted"` when the node reports hosting or the space is created;
|
|
398
|
+
* resolves `"not-hosted"` when creation is unavailable or declined; and
|
|
399
|
+
* resolves `"unknown"` when the node has no hosting answer.
|
|
400
|
+
* Rejects with `Error("Space hosting was cancelled by sign-out.")` if sign-out
|
|
401
|
+
* happens during the hosting run. Call from a user gesture so the approval popup can open.
|
|
402
|
+
* Also rejects if the initiating session is replaced before hosting finishes.
|
|
403
|
+
*/
|
|
404
|
+
ensureSpaceHosted(): Promise<SpaceHosting>;
|
|
380
405
|
clearPersistedSession(address?: string): Promise<void>;
|
|
381
406
|
private configuredManifestPermissions;
|
|
382
407
|
/**
|
|
@@ -399,6 +424,12 @@ export declare class TinyCloudWeb {
|
|
|
399
424
|
* unavailable until a fresh sign-in; prior persisted sessions cannot restore.
|
|
400
425
|
*/
|
|
401
426
|
signOut: () => Promise<void>;
|
|
427
|
+
/**
|
|
428
|
+
* Clears the stored session for `address` only while it is the signing-out session (`ownSignature`); a newer
|
|
429
|
+
* session saved for the same address is left alone. The session is fenced first, so that a clear that fails
|
|
430
|
+
* cannot let a reload restore it.
|
|
431
|
+
*/
|
|
432
|
+
private clearOwnPersistedSession;
|
|
402
433
|
session: () => ClientSession | undefined;
|
|
403
434
|
address: () => string | undefined;
|
|
404
435
|
chainId: () => number | undefined;
|
|
@@ -504,24 +535,12 @@ export declare class TinyCloudWeb {
|
|
|
504
535
|
requestPermissions(additional: PermissionEntry[], options?: RequestPermissionsOptions): Promise<RequestPermissionsResult>;
|
|
505
536
|
/**
|
|
506
537
|
* Signs the SIWE of a runtime permission grant. Precedence: the signer set with `setRuntimePermissionSigner`, then
|
|
507
|
-
* the OpenKey client
|
|
508
|
-
*
|
|
509
|
-
* `
|
|
538
|
+
* the configured OpenKey client's byte-exact `signMessage` (an OpenKey session's wallet provider does not implement
|
|
539
|
+
* `personal_sign`), signing with the keyId of the connected account after connecting the client first when it is not
|
|
540
|
+
* connected; a missing or ambiguous key throws `OpenKeySigningKeyError`. Without an OpenKey client or a session account,
|
|
541
|
+
* undefined: the connected wallet signs. Only `requestPermissions` calls this; sign-in and session setup never do.
|
|
510
542
|
*/
|
|
511
543
|
private runtimeMessageSigner;
|
|
512
|
-
/**
|
|
513
|
-
* Whether the OpenKey client may sign a runtime grant: always, unless there is POSITIVE evidence that it is not connected. It may sign when
|
|
514
|
-
* this instance's session was established through it (and is still the live session), or when its in-memory `lastAuth` is set (`connect()` ran
|
|
515
|
-
* 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
|
|
516
|
-
* does not know: today's behaviour, fail open). `lastAuth` is read here because nothing public says it: `@openkey/sdk` 0.12.2 declares
|
|
517
|
-
* `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`.
|
|
518
|
-
* `getSessionToken()` always answers null in 0.12.2 and `isConnected()` reads the OpenKey cookie, which can be true when `connect()` never ran
|
|
519
|
-
* 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
|
|
520
|
-
* `signMessage()` rejecting when not connected, in `@openkey/sdk`. Trade-off: an app that connects through a DIFFERENT OpenKey instance than
|
|
521
|
-
* `config.openkey.client`, or restores after an authorize-only sign-in, must call `openkey.connect()` on the configured client or
|
|
522
|
-
* `setRuntimePermissionSigner`.
|
|
523
|
-
*/
|
|
524
|
-
private openkeyClientMaySign;
|
|
525
544
|
/**
|
|
526
545
|
* Sets the signer for runtime permission grants (`requestPermissions`, and the panel's "allow" buttons), or clears
|
|
527
546
|
* it with no argument. For apps whose sign-in is not the SDK's OpenKey flow, for example a restored session whose
|
|
@@ -561,7 +580,7 @@ export declare class TinyCloudWeb {
|
|
|
561
580
|
checkPermission(path: string, action: string): Promise<Result<boolean, DelegationError>>;
|
|
562
581
|
/**
|
|
563
582
|
* Receive and retrieve data from a native TinyCloud bearer delegation.
|
|
564
|
-
* Static method — no
|
|
583
|
+
* Static method — no sign-in required. Verifies the parent with browser WASM and routes through the owner's registry.
|
|
565
584
|
*/
|
|
566
585
|
static receiveShare<T = unknown>(link: string, key?: string, options?: {
|
|
567
586
|
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
|