@tinycloud/web-sdk 3.12.0-beta.2 → 3.12.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.
- package/README.md +62 -7
- package/dist/adapters/BrowserSessionStorage.d.ts +3 -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 +1 -0
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.LICENSE.txt +2 -0
- package/dist/modules/Storage/tinycloud/types.schema.d.ts +4 -4
- package/dist/modules/requestPermissionsCore.d.ts +0 -7
- package/dist/modules/runtimeGrantPersistence.d.ts +4 -2
- package/dist/modules/tcw.d.ts +31 -45
- 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 +1 -1
- package/dist/space-hosting.cjs +1 -1
- package/dist/space-hosting.mjs +1 -1
- package/package.json +8 -7
package/README.md
CHANGED
|
@@ -58,12 +58,20 @@ expiry. The permission check does not contact the node, so a session the node
|
|
|
58
58
|
rejects (a 401 after a revocation or a reset, for example) is still restored.
|
|
59
59
|
With OpenKey, `prepareSignIn()` makes the same check.
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
the
|
|
61
|
+
`restoreSession()` resolves from stored state. It automatically starts a
|
|
62
|
+
background hosting probe, capped at 5 seconds, and reactivates stored panel
|
|
63
|
+
grants. Read `tc.spaceHosting` (`"hosted"`, `"not-hosted"` or `"unknown"`) for
|
|
64
|
+
the current display hint. A stored hint applies only to the same account,
|
|
65
|
+
space and host. It can be one session stale until the probe corrects it at
|
|
66
|
+
runtime, and updates in storage when the signed session is next persisted.
|
|
67
|
+
Older records start at `"unknown"`. The hint never grants authority or skips
|
|
68
|
+
permission checks. The probe never prompts or fails the restore.
|
|
69
|
+
Panel permission requests wait up to 4 seconds for stored grants to reactivate
|
|
70
|
+
before showing a permission prompt.
|
|
71
|
+
`signIn()` waits for the probe when it restores a session. At fresh sign-in
|
|
72
|
+
the hosting answer comes from the node's activation of the new session.
|
|
73
|
+
`signIn()` on a restored session whose space is `"not-hosted"` returns the
|
|
74
|
+
restored session.
|
|
67
75
|
|
|
68
76
|
To force a fresh consent, sign out first. `signOut()` clears the stored session
|
|
69
77
|
and blocks restoring until the next sign-in succeeds, so `signIn()` prompts:
|
|
@@ -76,6 +84,53 @@ await tc.signIn();
|
|
|
76
84
|
There is no separate "fresh sign-in" option. Calling `restoreSession()` yourself
|
|
77
85
|
restores a stored session without the manifest check.
|
|
78
86
|
|
|
87
|
+
Sign-out reports session-storage failures. Replica cleanup has its own recovery markers; sign-out completion alone does not certify local-copy erase. Custom/native session adapters keep their existing storage contract, including the provider's durability and boot-handling responsibilities.
|
|
88
|
+
With an asynchronous custom runtime-grant store, sign-out waits for in-flight
|
|
89
|
+
load/save calls to settle.
|
|
90
|
+
|
|
91
|
+
### Runtime permission grants with OpenKey
|
|
92
|
+
|
|
93
|
+
`requestPermissions()` (and the panel's "allow" buttons) sign each runtime grant's SIWE as a byte-exact message through
|
|
94
|
+
`config.openkey.client.signMessage`, with the `keyId` of the connected OpenKey account. The SDK never sends `signMessage`
|
|
95
|
+
without a `keyId`. If the client is not connected (a restored session, or a sign-in through `authorizeTinyCloud`), the SDK
|
|
96
|
+
connects it first with `client.connect()`, in the configured `mode`:
|
|
97
|
+
|
|
98
|
+
- **`iframe` (and `redirect`)**: the grant connects and signs in one go, in one click.
|
|
99
|
+
- **`popup` (the default)**: a browser lets a page open a popup only soon after the user's click, and the user needs longer
|
|
100
|
+
than that to sign in inside the connect popup, so a sign popup opened right after it would be blocked. The first click
|
|
101
|
+
therefore connects and rejects with `OpenKeySigningKeyError` code `OPENKEY_CONNECTED_RETRY`, signing nothing. The client
|
|
102
|
+
is now connected: show your Allow button again, and the second click signs with the connected key in one popup. Once the
|
|
103
|
+
client is connected, every later grant is one click.
|
|
104
|
+
|
|
105
|
+
When no single key can be named, or the client was just connected in popup mode, `requestPermissions()` rejects with
|
|
106
|
+
`OpenKeySigningKeyError` before any sign request:
|
|
107
|
+
|
|
108
|
+
| `code` | Meaning |
|
|
109
|
+
| ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
|
|
110
|
+
| `OPENKEY_CONNECTED_RETRY` | Popup mode only. The SDK connected the client. Nothing was signed; ask the user to click Allow again. |
|
|
111
|
+
| `OPENKEY_KEY_MISSING` | The client is not connected and has no `connect()`, or `connect()` answered without a `keyId`. |
|
|
112
|
+
| `OPENKEY_KEY_AMBIGUOUS` | The connected key's address is not the signed-in account's, or it reports no address. |
|
|
113
|
+
|
|
114
|
+
`OPENKEY_KEY_MISSING` and `OPENKEY_KEY_AMBIGUOUS`: connect the configured client as the signed-in account
|
|
115
|
+
(`await openkey.connect()`), or sign runtime grants with `tc.setRuntimePermissionSigner(...)`. Connecting it yourself in the
|
|
116
|
+
click that starts sign-in avoids the extra click. A user closing the connect dialog rejects with `@openkey/sdk`'s own plain-object rejection `{ code: "USER_CANCELLED" }` (not an `Error`, and not an `OpenKeySigningKeyError`), so tell it apart from `OPENKEY_CONNECTED_RETRY`, which is an `OpenKeySigningKeyError`. A blocked popup rejects the same way with `{ code: "POPUP_BLOCKED" }`. If
|
|
117
|
+
the session ends or changes (sign-out, another account) while a dialog is open, the grant is cancelled and nothing is
|
|
118
|
+
signed. The two-click flow needs a client that keeps the connect result in `lastAuth`, as `@openkey/sdk` does.
|
|
119
|
+
|
|
120
|
+
## Signed registry cache
|
|
121
|
+
|
|
122
|
+
The browser client stores exact owner-signed v2 registry responses beside its identity pins, under `tinycloud.registryCache.v2:<ownerKey>`. Fetch time, invalidation revision and sequence metadata are outside the signed response. Every routing decision awaits a bounded, coalesced refresh and verifies cached responses again. Only a higher verified sequence replaces signed bytes; equal-sequence renewal requires identical canonical signed meaning, not identical HTTP formatting.
|
|
123
|
+
|
|
124
|
+
Registry v2 and v1 fetches use `cache: "no-store"` to bypass the browser HTTP cache. The separate signed-response cache remains independently verified and subject to the outage fallback age limit below.
|
|
125
|
+
|
|
126
|
+
Custom `RegistryCacheStore` adapters implement `get`, `getRevision`, atomic `update(ownerKey, (current, revision) => ...)`, and `delete(ownerKey, expectedRevision?, maximumSequence?)`. Forward both callback arguments and every deletion argument. The default persistent adapter uses the same per-entry Web Lock and storage key for updates and invalidation. Deletion atomically writes `{ ownerKey, revision: previousRevision + 1, invalidated: true }`, including when empty; `get` hides this metadata-only tombstone while `getRevision` preserves its history. Legacy live entries without revision are revision zero. Accepted writes retain the store's revision. Conditional deletion refuses without mutation if its revision differs or the current signed sequence exceeds the supplied maximum; malformed or overflowing revisions refuse.
|
|
127
|
+
|
|
128
|
+
Revision capture before lookup, atomic commit checks and final fallback checks prevent older in-flight responses from repopulating invalidated settings. Positive persisted revisions remain known-owner evidence without a sequence adapter. The independent `tinycloud.registrySequences.v2` map keeps signed maxima under its storage-key Web Lock across owners. Storage absence uses memory; unreadable/corrupt state refuses. Browsers without Web Locks must supply transactional persistent cache and sequence adapters; a separate revision counter write is not atomic enough.
|
|
129
|
+
|
|
130
|
+
Warm fallback requires a canonically reverified cache younger than one hour and a transport error, timeout or HTTP 502/503/504. HTTP 500, other statuses, invalid responses and invalid cached state refuse. Authoritative HTTP4xx responses and fresh signed records without the required route remove cached settings while retaining known-owner history. With no saved settings, cold HTTP5xx, transport errors and timeouts refuse live routing instead of selecting a configured/default host. Reachable genuine absence still permits onboarding. `onRegistryFallback(reason, code?)` receives `using_cached_settings` after selecting a verified cached route, once per owner/cache; without it the SDK logs a value-free warning. Non-replicating stored-session hydration is local-only; later live operations still refresh routing. Explicit replication retains preflight. Nodes performing online admission still require their registry connection.
|
|
131
|
+
|
|
132
|
+
Details: TC-2481
|
|
133
|
+
|
|
79
134
|
## Optional local KV replication
|
|
80
135
|
|
|
81
136
|
Install `@tinycloud/replica`, then load and register the optional browser plugin
|
|
@@ -503,4 +558,4 @@ If you encounter any issues or have questions, please file an issue on our [GitH
|
|
|
503
558
|
Join the TinyCloud community:
|
|
504
559
|
|
|
505
560
|
- [Twitter](https://twitter.com/TinyCloudLabs)
|
|
506
|
-
- [Telegram](https://t.me/+pplkv1XbbU01MDVh)
|
|
561
|
+
- [Telegram](https://t.me/+pplkv1XbbU01MDVh)
|
|
@@ -22,6 +22,9 @@ export declare class BrowserSessionStorage implements ISessionStorage {
|
|
|
22
22
|
private key;
|
|
23
23
|
private activeAddressKey;
|
|
24
24
|
private fenceKey;
|
|
25
|
+
private retirementKey;
|
|
26
|
+
private isRetired;
|
|
27
|
+
private invalidateSession;
|
|
25
28
|
/**
|
|
26
29
|
* Fences the session with `signature` stored for `address`, for when removing its record fails: a restore
|
|
27
30
|
* checks {@link isSignedOut} and refuses it. A successful `clear` lifts the fence, and so does saving a
|