@tinycloud/node-sdk 3.12.0-beta.1 → 3.12.0-beta.3
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 +39 -0
- package/dist/{NodeUserAuthorization-BtoDI9in.d.cts → NodeUserAuthorization-B_TFUlua.d.cts} +19 -53
- package/dist/{NodeUserAuthorization-BtoDI9in.d.ts → NodeUserAuthorization-B_TFUlua.d.ts} +19 -53
- package/dist/{TinyCloudNode-DLrINr98.d.ts → TinyCloudNode-Brcu8QoX.d.cts} +33 -59
- package/dist/{TinyCloudNode-C24728N_.d.cts → TinyCloudNode-DBJUnsMN.d.ts} +33 -59
- package/dist/{authority-BQN2Z3st.d.ts → authority-BFc5lesl.d.ts} +1 -1
- package/dist/{authority-DDdheOL6.d.cts → authority-DQ6R1HEG.d.cts} +1 -1
- package/dist/core.cjs +555 -320
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.cts +5 -5
- package/dist/core.d.ts +5 -5
- package/dist/core.js +581 -324
- package/dist/core.js.map +1 -1
- package/dist/credentials-core.d.cts +1 -1
- package/dist/credentials-core.d.ts +1 -1
- package/dist/credentials.d.cts +1 -1
- package/dist/credentials.d.ts +1 -1
- package/dist/{delegation-BQbAuKad.d.cts → delegation-CeOWDnBB.d.cts} +7 -0
- package/dist/{delegation-BQbAuKad.d.ts → delegation-CeOWDnBB.d.ts} +7 -0
- package/dist/encryption-keys.d.cts +3 -3
- package/dist/encryption-keys.d.ts +3 -3
- package/dist/index.cjs +572 -337
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -4
- package/dist/index.d.ts +5 -4
- package/dist/index.js +582 -325
- package/dist/index.js.map +1 -1
- package/dist/replication/authority.d.cts +4 -4
- package/dist/replication/authority.d.ts +4 -4
- package/dist/space-hosting.cjs +48 -6
- package/dist/space-hosting.cjs.map +1 -1
- package/dist/space-hosting.d.cts +23 -8
- package/dist/space-hosting.d.ts +23 -8
- package/dist/space-hosting.js +48 -6
- package/dist/space-hosting.js.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,5 +1,44 @@
|
|
|
1
1
|
# @tinycloud/node-sdk
|
|
2
2
|
|
|
3
|
+
## Registry v2 resource routing
|
|
4
|
+
|
|
5
|
+
Node SDK and the Web SDK's shared Node client use owner-signed registry v2 records by default. Set `tinycloudRegistryUrl` to select a registry; isolated development may use a loopback HTTP origin.
|
|
6
|
+
|
|
7
|
+
Routing uses the complete space URI, not a short space name or a single account-wide host. Reads use that space's listed members; writes target every listed `read-write` member. Read-only members may register a session and host their listed replica, but do not receive ordinary writes. Advertised node DIDs are checked against `/info` and `/.well-known/tinycloud/node-keys` before use.
|
|
8
|
+
|
|
9
|
+
Encryption is resolved separately: descriptor reads, network creation, and decrypt requests use the signed `encryptionNode`, including its invocation audience. A data-space host does not become an encryption destination, or vice versa.
|
|
10
|
+
|
|
11
|
+
Explicit `host`, saved-profile hosts, local discovery, and new-user defaults are onboarding hints. The lookup checks v2 first, then v1 to distinguish absence from an existing v1 registration. Cold HTTP5xx, transport errors and timeouts without cached or remembered registration retain configured/default-host compatibility, including direct Core callers without a cache adapter; the verdict is marked `offline`, not genuine registry absence. HTTP4xx refusals, v1-only registrations, corrupt caches, invalid responses, remembered registrations, empty registered memberships and missing encryption destinations never authorize fallback. Signed strings are validated without rewriting them.
|
|
12
|
+
|
|
13
|
+
`NodeNotRespondingError` has code `NODE_NOT_RESPONDING`. Registry refusals and node-identity mismatches remain distinct errors. Multi-node writes are not atomic: `PartialNodeWriteError` exposes `succeeded` URLs and `failed` destinations/statuses/causes so callers do not mistake incomplete writes for success.
|
|
14
|
+
|
|
15
|
+
Mixed signed grants register unchanged on the union of their listed data destinations and `encryptionNode`. Restoring a stored valid grant does not request new consent when a destination is unavailable: canonical operations preserve `NODE_NOT_RESPONDING`, `NODE_IDENTITY_MISMATCH`, and `REGISTRY_UNAVAILABLE` separately from invalid or expired authority.
|
|
16
|
+
|
|
17
|
+
Request-bound imports keep the original request/profile binding. A differing grant transport host is accepted only after validated permissions resolve through verified full-resource registry memberships; the derived destination replaces neither the saved hint nor signed bytes. Genuine no-entry still requires the original host match.
|
|
18
|
+
|
|
19
|
+
### Signed registry cache
|
|
20
|
+
|
|
21
|
+
`registryCacheStore` accepts a `RegistryCacheStore` from `@tinycloud/sdk-core`; the default is in-memory. The store keeps the exact fetched UTF-8 response text separately from `ownerKey`, `sequence` and `fetchedAt` metadata. EOA keys use the canonical EIP-55 address across wallet chains; `did:key` keys remain exact. Every read and replacement comparison reuses the canonical signed-v2 verifier.
|
|
22
|
+
|
|
23
|
+
Persistent adapters implement `get`, required `getRevision(ownerKey)`, atomic `update(ownerKey, (current, revision) => ...)`, and `delete(ownerKey, expectedRevision?, maximumSequence?)`. The callback receives the current revision under the same store lock as the entry. Conditional deletion refuses without mutation when the revision differs or a current signed entry has a higher sequence than `maximumSequence`; validate supplied bounds as non-negative safe integers. Instrumented adapters must forward both callback arguments and all deletion arguments.
|
|
24
|
+
|
|
25
|
+
Each real deletion atomically replaces the entry with `{ ownerKey, revision: previousRevision + 1, invalidated: true }`, even when already empty. Tombstones contain no signed bytes and `get` returns `undefined` for them; `getRevision` still reads their generation. Live entries may carry local `revision` metadata; legacy entries without it have revision zero. Accepted updates preserve the store's revision, not a callback-supplied value. Persist the tombstone and counter in one value/file under the existing queue or per-entry lock; never use a separate counter write. Corrupt or overflowing revisions refuse.
|
|
26
|
+
|
|
27
|
+
Routing captures the revision before network I/O and checks it under the commit lock and before cached fallback. A persisted positive revision remains known-owner evidence even without a sequence adapter; it is not a signed sequence. Only a higher verified sequence replaces signed bytes. Equal-sequence renewal requires the identical canonical signed payload; differing response formatting preserves exact old raw bytes. Failed, invalid, conflicting or lower-sequence responses never renew age. Keep `registrySequenceStore` for complete signed high-water history. Ordinary accepted-sequence persistence remains best-effort; authoritative deletion retains known-owner evidence before invalidating.
|
|
28
|
+
|
|
29
|
+
Every owner routing decision awaits a bounded registry refresh. Overlapping refreshes coalesce per owner; later decisions fetch again, without a retry loop or polling daemon. During transport errors, timeouts or HTTP 502/503/504 only, routing may use a canonically reverified cache whose `fetchedAt` age is strictly less than one hour. HTTP 500 and every other status do not authorize warm fallback. Authoritative HTTP4xx responses and fresh signed records without the required route delete cached settings while retaining known-owner evidence; later outages do not select a default for that owner.
|
|
30
|
+
|
|
31
|
+
Each caller retains registration evidence observed before joining an in-flight refresh and checks current cache/high-water state before routing. Non-replicating `restoreSession()` verifies and hydrates signed session authority locally without registry or node I/O. Later live operations still resolve fresh routing through the service graph. The first live routing decision also starts background prefetch for the canonically verified wallet owner, independently of the requested resource's owner. Web startup's hosting probe and real held-grant activation use that same boundary; local-only inspection does not. Explicitly enabled replication retains its routing and node preflight.
|
|
32
|
+
|
|
33
|
+
Restored host hints install alongside the replacement session and service graph. Subsequent public delegation preparation uses that installed hint when fresh routing permits onboarding; verified signed destinations still take precedence.
|
|
34
|
+
|
|
35
|
+
Actual cold fallback logs `registry unavailable; using the default node`; warm fallback logs `Storage settings are unreachable; using cached settings checked less than 1 hour ago.` Each diagnostic is emitted once per owner/client cache and fallback kind, only after a route is selected. `onRegistryFallback(reason, code?)` collects these value-free diagnostics instead of the default console warning; semantic codes are `using_default_node` and `using_cached_settings`. Background refresh alone does not warn.
|
|
36
|
+
|
|
37
|
+
This is a client cache: a node that performs online registry admission still needs its own registry connectivity. It is not a whole-service-outage guarantee.
|
|
38
|
+
|
|
39
|
+
Details: TC-2481
|
|
40
|
+
|
|
41
|
+
|
|
3
42
|
## Signed SIWE metadata
|
|
4
43
|
|
|
5
44
|
Set `siweConfig.resources` to `urn:tinycloud:recipients:<base64url>` URI strings to include a recipients declaration in the signed SIWE. The payload uses only unpadded base64url characters (`A–Z`, `a–z`, `0–9`, `_`, `-`). Node-sdk inserts these URIs immediately before the original ReCap resource, which remains last. Ordinary sign-in, external/OpenKey preparation, and bootstrap sessions use the same insertion path; completion and session storage retain the signed message unchanged.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, CapabilityPresentationEnvelopeV1, IUserAuthorization, ISigner, ISessionStorage, ISpaceCreationHandler, RegistryPolicy, RegistrySequenceStore, OnNodeNotFound, LocalNodeIdentityStore, IWasmBindings, ISessionManager, SiweConfig, Manifest, ComposedManifestRequest, ReplicationOptions, TinyCloudSession, PersistedSessionData, ClientSession, PermissionEntry, Extension, SignRequest, SpaceHostResult, SignInOptions } from '@tinycloud/sdk-core';
|
|
1
|
+
import { AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, CapabilityPresentationEnvelopeV1, IUserAuthorization, ISigner, ISessionStorage, ISpaceCreationHandler, RegistryPolicy, RegistrySequenceStore, RegistryCacheStore, RegistryFallbackReason, OnNodeNotFound, LocalNodeIdentityStore, IWasmBindings, ISessionManager, SiweConfig, Manifest, ComposedManifestRequest, ReplicationOptions, TinyCloudSession, PersistedSessionData, ClientSession, PermissionEntry, Extension, SignRequest, SpaceHostResult, SignInOptions } from '@tinycloud/sdk-core';
|
|
2
|
+
import { ResourceAccess, ResourceDestination } from '@tinycloud/sdk-services';
|
|
2
3
|
import { EventEmitter } from 'events';
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -213,29 +214,13 @@ interface NodeUserAuthorizationConfig {
|
|
|
213
214
|
autoCreateSpace?: boolean;
|
|
214
215
|
/** Custom space creation handler. If provided, takes precedence over autoCreateSpace. */
|
|
215
216
|
spaceCreationHandler?: ISpaceCreationHandler;
|
|
216
|
-
/**
|
|
217
|
+
/** Host hints used only for owners absent from both registry namespaces. */
|
|
217
218
|
tinycloudHosts?: string[];
|
|
218
219
|
/** TinyCloud location registry URL. Default: https://registry.tinycloud.xyz. */
|
|
219
220
|
tinycloudRegistryUrl?: string | null;
|
|
220
|
-
/**
|
|
221
|
-
* Fallback TinyCloud hosts. Default: hosted TinyCloud node. Used only by the
|
|
222
|
-
* default `registryPolicy` ("legacy-fallback"), whose silent fallback is
|
|
223
|
-
* deprecated and will be removed in a future major release.
|
|
224
|
-
*/
|
|
221
|
+
/** Host hints for genuine no-entry onboarding. Never used for registered or unavailable owners. */
|
|
225
222
|
tinycloudFallbackHosts?: string[] | null;
|
|
226
|
-
/**
|
|
227
|
-
* How sign-in uses the location registry when no host is configured.
|
|
228
|
-
*
|
|
229
|
-
* - `"legacy-fallback"` (default, deprecated): a registry miss or failure
|
|
230
|
-
* silently uses `tinycloudFallbackHosts`, with a one-time warning.
|
|
231
|
-
* - `"fail-closed"`: sign-in acts on the registry verdict for the signer
|
|
232
|
-
* address. Registered owners go to their listed hosts, unregistered owners
|
|
233
|
-
* to `newUserHost`, and an unavailable registry is
|
|
234
|
-
* `RegistryUnavailableError`, never a new account. Automatic space
|
|
235
|
-
* creation is refused on a host the owner's record does not list
|
|
236
|
-
* (`NodeRegistryEntryExistsError`) or when the registry gives no verdict
|
|
237
|
-
* (`RegistryUnavailableError`).
|
|
238
|
-
*/
|
|
223
|
+
/** Registry routing is always v2-first and fail-closed. */
|
|
239
224
|
registryPolicy?: RegistryPolicy;
|
|
240
225
|
/**
|
|
241
226
|
* `fail-closed` only: host for owners with no registry record (and only
|
|
@@ -250,6 +235,9 @@ interface NodeUserAuthorizationConfig {
|
|
|
250
235
|
registryChainId?: number;
|
|
251
236
|
/** `fail-closed` only: highest registry sequence seen per owner. Default: in-memory. */
|
|
252
237
|
registrySequenceStore?: RegistrySequenceStore;
|
|
238
|
+
registryCacheStore?: RegistryCacheStore;
|
|
239
|
+
/** Value-free warning after an actual cached-settings or default-node fallback. */
|
|
240
|
+
onRegistryFallback?: (reason: string, code?: RegistryFallbackReason) => void;
|
|
253
241
|
/**
|
|
254
242
|
* `fail-closed` only: called when sign-in resolves no host
|
|
255
243
|
* (`NodeNotFoundError` or `RegistryUnavailableError`) to retry, use another
|
|
@@ -371,11 +359,12 @@ declare class NodeUserAuthorization implements IUserAuthorization {
|
|
|
371
359
|
private tinycloudHosts?;
|
|
372
360
|
private readonly tinycloudRegistryUrl?;
|
|
373
361
|
private readonly tinycloudFallbackHosts?;
|
|
374
|
-
private readonly registryPolicy?;
|
|
375
362
|
private readonly newUserHost?;
|
|
376
363
|
private readonly registryChainId?;
|
|
377
364
|
private readonly registrySequenceStore;
|
|
365
|
+
private readonly registryCacheStore;
|
|
378
366
|
private readonly onNodeNotFound?;
|
|
367
|
+
private readonly onRegistryFallback?;
|
|
379
368
|
/** Verdict from the last `fail-closed` host resolution, reused by {@link assertMayCreateSpace}. */
|
|
380
369
|
private registryVerdict?;
|
|
381
370
|
private readonly autoDiscoverLocalNode?;
|
|
@@ -466,13 +455,8 @@ declare class NodeUserAuthorization implements IUserAuthorization {
|
|
|
466
455
|
* undefined for missing SIWEs and the SDK then treats the session as
|
|
467
456
|
* expired-at-epoch-zero.
|
|
468
457
|
*
|
|
469
|
-
* @param hosts -
|
|
470
|
-
*
|
|
471
|
-
* present (and non-empty) they are adopted directly so the restored
|
|
472
|
-
* session resolves to the same node as the original sign-in without
|
|
473
|
-
* re-running registry/fallback resolution. When absent (old session)
|
|
474
|
-
* hosts are resolved lazily on the first host-needing call via
|
|
475
|
-
* {@link ensureTinyCloudHosts}.
|
|
458
|
+
* @param hosts - Persisted host hints for genuine no-entry onboarding.
|
|
459
|
+
* Current signed registry membership always takes precedence.
|
|
476
460
|
*/
|
|
477
461
|
setRestoredTinyCloudSession(session: TinyCloudSession, hosts?: string[]): void;
|
|
478
462
|
/**
|
|
@@ -486,32 +470,14 @@ declare class NodeUserAuthorization implements IUserAuthorization {
|
|
|
486
470
|
private enqueuePersistence;
|
|
487
471
|
/** @internal Atomically adopt the state staged by TinyCloudNode.restoreSession. */
|
|
488
472
|
installRestoredSession(sessionManager: ISessionManager, session: TinyCloudSession | undefined, hosts?: string[], nodeFeatures?: string[]): void;
|
|
489
|
-
/**
|
|
490
|
-
* Ensure `tinycloudHosts` are resolved before a host-needing call.
|
|
491
|
-
*
|
|
492
|
-
* Fresh sign-in resolves hosts up front; a restored session may not have
|
|
493
|
-
* (old persisted sessions predate {@link PersistedSessionData.tinycloudHosts}).
|
|
494
|
-
* This guard makes a restored session resolve the node exactly like a fresh
|
|
495
|
-
* sign-in — persisted hosts are preferred (already set by
|
|
496
|
-
* {@link setRestoredTinyCloudSession}), otherwise the registry/fallback
|
|
497
|
-
* resolution runs lazily here. Idempotent: {@link resolveTinyCloudHostsForSignIn}
|
|
498
|
-
* early-returns when hosts are already set.
|
|
499
|
-
*
|
|
500
|
-
* Throws if hosts are unset and the restored session has no address/chainId
|
|
501
|
-
* to resolve from — a real failure that must surface, not be masked.
|
|
502
|
-
*/
|
|
473
|
+
/** Refresh the primary space's registry destinations, including after restore. */
|
|
503
474
|
ensureTinyCloudHosts(): Promise<void>;
|
|
504
475
|
private resolveTinyCloudHostsForSignIn;
|
|
505
|
-
/**
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
* verdict. Reuses this session's sign-in verdict unless it was
|
|
511
|
-
* `unavailable`, else looks it up now (explicit-host apps). Under the
|
|
512
|
-
* default policy it returns at once and performs no lookup.
|
|
513
|
-
*/
|
|
514
|
-
assertMayCreateSpace(): Promise<void>;
|
|
476
|
+
/** Current full-resource registry routing; saved hosts are only no-entry hints. */
|
|
477
|
+
resolveResourceDestinations(resource: string, access: ResourceAccess, noEntryHosts?: readonly string[]): Promise<ResourceDestination[]>;
|
|
478
|
+
get registryRecordPresent(): boolean;
|
|
479
|
+
/** Refresh membership before hosting; a saved no-entry verdict never authorizes a later creation. */
|
|
480
|
+
assertMayCreateSpace(spaceId?: string | undefined, host?: string): Promise<void>;
|
|
515
481
|
private requireTinyCloudHosts;
|
|
516
482
|
private get primaryTinyCloudHost();
|
|
517
483
|
get nodeFeatures(): string[];
|
|
@@ -670,7 +636,7 @@ declare class NodeUserAuthorization implements IUserAuthorization {
|
|
|
670
636
|
*
|
|
671
637
|
* @throws Error if the creation handler fails or times out, or hosting fails
|
|
672
638
|
*/
|
|
673
|
-
ensurePrimarySpaceHosted(hosting: SpaceHosting): Promise<void>;
|
|
639
|
+
ensurePrimarySpaceHosted(hosting: SpaceHosting, signal?: AbortSignal): Promise<void>;
|
|
674
640
|
/** {@link assertMayCreateSpace}, reporting a refusal to the creation handler before rethrowing it. */
|
|
675
641
|
private guardSpaceCreation;
|
|
676
642
|
private recordActivationSkippedSpaces;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, CapabilityPresentationEnvelopeV1, IUserAuthorization, ISigner, ISessionStorage, ISpaceCreationHandler, RegistryPolicy, RegistrySequenceStore, OnNodeNotFound, LocalNodeIdentityStore, IWasmBindings, ISessionManager, SiweConfig, Manifest, ComposedManifestRequest, ReplicationOptions, TinyCloudSession, PersistedSessionData, ClientSession, PermissionEntry, Extension, SignRequest, SpaceHostResult, SignInOptions } from '@tinycloud/sdk-core';
|
|
1
|
+
import { AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, CapabilityPresentationEnvelopeV1, IUserAuthorization, ISigner, ISessionStorage, ISpaceCreationHandler, RegistryPolicy, RegistrySequenceStore, RegistryCacheStore, RegistryFallbackReason, OnNodeNotFound, LocalNodeIdentityStore, IWasmBindings, ISessionManager, SiweConfig, Manifest, ComposedManifestRequest, ReplicationOptions, TinyCloudSession, PersistedSessionData, ClientSession, PermissionEntry, Extension, SignRequest, SpaceHostResult, SignInOptions } from '@tinycloud/sdk-core';
|
|
2
|
+
import { ResourceAccess, ResourceDestination } from '@tinycloud/sdk-services';
|
|
2
3
|
import { EventEmitter } from 'events';
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -213,29 +214,13 @@ interface NodeUserAuthorizationConfig {
|
|
|
213
214
|
autoCreateSpace?: boolean;
|
|
214
215
|
/** Custom space creation handler. If provided, takes precedence over autoCreateSpace. */
|
|
215
216
|
spaceCreationHandler?: ISpaceCreationHandler;
|
|
216
|
-
/**
|
|
217
|
+
/** Host hints used only for owners absent from both registry namespaces. */
|
|
217
218
|
tinycloudHosts?: string[];
|
|
218
219
|
/** TinyCloud location registry URL. Default: https://registry.tinycloud.xyz. */
|
|
219
220
|
tinycloudRegistryUrl?: string | null;
|
|
220
|
-
/**
|
|
221
|
-
* Fallback TinyCloud hosts. Default: hosted TinyCloud node. Used only by the
|
|
222
|
-
* default `registryPolicy` ("legacy-fallback"), whose silent fallback is
|
|
223
|
-
* deprecated and will be removed in a future major release.
|
|
224
|
-
*/
|
|
221
|
+
/** Host hints for genuine no-entry onboarding. Never used for registered or unavailable owners. */
|
|
225
222
|
tinycloudFallbackHosts?: string[] | null;
|
|
226
|
-
/**
|
|
227
|
-
* How sign-in uses the location registry when no host is configured.
|
|
228
|
-
*
|
|
229
|
-
* - `"legacy-fallback"` (default, deprecated): a registry miss or failure
|
|
230
|
-
* silently uses `tinycloudFallbackHosts`, with a one-time warning.
|
|
231
|
-
* - `"fail-closed"`: sign-in acts on the registry verdict for the signer
|
|
232
|
-
* address. Registered owners go to their listed hosts, unregistered owners
|
|
233
|
-
* to `newUserHost`, and an unavailable registry is
|
|
234
|
-
* `RegistryUnavailableError`, never a new account. Automatic space
|
|
235
|
-
* creation is refused on a host the owner's record does not list
|
|
236
|
-
* (`NodeRegistryEntryExistsError`) or when the registry gives no verdict
|
|
237
|
-
* (`RegistryUnavailableError`).
|
|
238
|
-
*/
|
|
223
|
+
/** Registry routing is always v2-first and fail-closed. */
|
|
239
224
|
registryPolicy?: RegistryPolicy;
|
|
240
225
|
/**
|
|
241
226
|
* `fail-closed` only: host for owners with no registry record (and only
|
|
@@ -250,6 +235,9 @@ interface NodeUserAuthorizationConfig {
|
|
|
250
235
|
registryChainId?: number;
|
|
251
236
|
/** `fail-closed` only: highest registry sequence seen per owner. Default: in-memory. */
|
|
252
237
|
registrySequenceStore?: RegistrySequenceStore;
|
|
238
|
+
registryCacheStore?: RegistryCacheStore;
|
|
239
|
+
/** Value-free warning after an actual cached-settings or default-node fallback. */
|
|
240
|
+
onRegistryFallback?: (reason: string, code?: RegistryFallbackReason) => void;
|
|
253
241
|
/**
|
|
254
242
|
* `fail-closed` only: called when sign-in resolves no host
|
|
255
243
|
* (`NodeNotFoundError` or `RegistryUnavailableError`) to retry, use another
|
|
@@ -371,11 +359,12 @@ declare class NodeUserAuthorization implements IUserAuthorization {
|
|
|
371
359
|
private tinycloudHosts?;
|
|
372
360
|
private readonly tinycloudRegistryUrl?;
|
|
373
361
|
private readonly tinycloudFallbackHosts?;
|
|
374
|
-
private readonly registryPolicy?;
|
|
375
362
|
private readonly newUserHost?;
|
|
376
363
|
private readonly registryChainId?;
|
|
377
364
|
private readonly registrySequenceStore;
|
|
365
|
+
private readonly registryCacheStore;
|
|
378
366
|
private readonly onNodeNotFound?;
|
|
367
|
+
private readonly onRegistryFallback?;
|
|
379
368
|
/** Verdict from the last `fail-closed` host resolution, reused by {@link assertMayCreateSpace}. */
|
|
380
369
|
private registryVerdict?;
|
|
381
370
|
private readonly autoDiscoverLocalNode?;
|
|
@@ -466,13 +455,8 @@ declare class NodeUserAuthorization implements IUserAuthorization {
|
|
|
466
455
|
* undefined for missing SIWEs and the SDK then treats the session as
|
|
467
456
|
* expired-at-epoch-zero.
|
|
468
457
|
*
|
|
469
|
-
* @param hosts -
|
|
470
|
-
*
|
|
471
|
-
* present (and non-empty) they are adopted directly so the restored
|
|
472
|
-
* session resolves to the same node as the original sign-in without
|
|
473
|
-
* re-running registry/fallback resolution. When absent (old session)
|
|
474
|
-
* hosts are resolved lazily on the first host-needing call via
|
|
475
|
-
* {@link ensureTinyCloudHosts}.
|
|
458
|
+
* @param hosts - Persisted host hints for genuine no-entry onboarding.
|
|
459
|
+
* Current signed registry membership always takes precedence.
|
|
476
460
|
*/
|
|
477
461
|
setRestoredTinyCloudSession(session: TinyCloudSession, hosts?: string[]): void;
|
|
478
462
|
/**
|
|
@@ -486,32 +470,14 @@ declare class NodeUserAuthorization implements IUserAuthorization {
|
|
|
486
470
|
private enqueuePersistence;
|
|
487
471
|
/** @internal Atomically adopt the state staged by TinyCloudNode.restoreSession. */
|
|
488
472
|
installRestoredSession(sessionManager: ISessionManager, session: TinyCloudSession | undefined, hosts?: string[], nodeFeatures?: string[]): void;
|
|
489
|
-
/**
|
|
490
|
-
* Ensure `tinycloudHosts` are resolved before a host-needing call.
|
|
491
|
-
*
|
|
492
|
-
* Fresh sign-in resolves hosts up front; a restored session may not have
|
|
493
|
-
* (old persisted sessions predate {@link PersistedSessionData.tinycloudHosts}).
|
|
494
|
-
* This guard makes a restored session resolve the node exactly like a fresh
|
|
495
|
-
* sign-in — persisted hosts are preferred (already set by
|
|
496
|
-
* {@link setRestoredTinyCloudSession}), otherwise the registry/fallback
|
|
497
|
-
* resolution runs lazily here. Idempotent: {@link resolveTinyCloudHostsForSignIn}
|
|
498
|
-
* early-returns when hosts are already set.
|
|
499
|
-
*
|
|
500
|
-
* Throws if hosts are unset and the restored session has no address/chainId
|
|
501
|
-
* to resolve from — a real failure that must surface, not be masked.
|
|
502
|
-
*/
|
|
473
|
+
/** Refresh the primary space's registry destinations, including after restore. */
|
|
503
474
|
ensureTinyCloudHosts(): Promise<void>;
|
|
504
475
|
private resolveTinyCloudHostsForSignIn;
|
|
505
|
-
/**
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
* verdict. Reuses this session's sign-in verdict unless it was
|
|
511
|
-
* `unavailable`, else looks it up now (explicit-host apps). Under the
|
|
512
|
-
* default policy it returns at once and performs no lookup.
|
|
513
|
-
*/
|
|
514
|
-
assertMayCreateSpace(): Promise<void>;
|
|
476
|
+
/** Current full-resource registry routing; saved hosts are only no-entry hints. */
|
|
477
|
+
resolveResourceDestinations(resource: string, access: ResourceAccess, noEntryHosts?: readonly string[]): Promise<ResourceDestination[]>;
|
|
478
|
+
get registryRecordPresent(): boolean;
|
|
479
|
+
/** Refresh membership before hosting; a saved no-entry verdict never authorizes a later creation. */
|
|
480
|
+
assertMayCreateSpace(spaceId?: string | undefined, host?: string): Promise<void>;
|
|
515
481
|
private requireTinyCloudHosts;
|
|
516
482
|
private get primaryTinyCloudHost();
|
|
517
483
|
get nodeFeatures(): string[];
|
|
@@ -670,7 +636,7 @@ declare class NodeUserAuthorization implements IUserAuthorization {
|
|
|
670
636
|
*
|
|
671
637
|
* @throws Error if the creation handler fails or times out, or hosting fails
|
|
672
638
|
*/
|
|
673
|
-
ensurePrimarySpaceHosted(hosting: SpaceHosting): Promise<void>;
|
|
639
|
+
ensurePrimarySpaceHosted(hosting: SpaceHosting, signal?: AbortSignal): Promise<void>;
|
|
674
640
|
/** {@link assertMayCreateSpace}, reporting a refusal to the creation handler before rethrowing it. */
|
|
675
641
|
private guardSpaceCreation;
|
|
676
642
|
private recordActivationSkippedSpaces;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as _tinycloud_sdk_core from '@tinycloud/sdk-core';
|
|
2
|
-
import { TinyCloudSession, TelemetryConfig, ServiceContext, IKVService, ISQLService, IDuckDbService, IHooksService, CreateOwnerDelegationParams as CreateOwnerDelegationParams$1, OwnerDelegationReceipt as OwnerDelegationReceipt$1, Delegation, IWasmBindings, ISigner, StorageFullEvent, IStorageService, RegistryPolicy, RegistrySequenceStore, OnNodeNotFound, LocalNodeIdentityStore, ISessionStorage, INotificationHandler, IENSResolver, ISpaceCreationHandler, SiweConfig, Manifest, ComposedManifestRequest, RetryPolicy, ReplicationOptions, KVReplicaStorage, PermissionEntry, AccountService, SignInOptions, InvokeAnyFunction as InvokeAnyFunction$1, UnifiedPolicyCapability, RegisterPolicyV3Input, RegisterPolicyV3Receipt, CanonicalJson, ShareDeliveryAuthorizationV3Receipt, IDataVaultService, IEncryptionService, NetworkDescriptor, ISecretsService, ICapabilityKeyRegistry, DelegationManager, ISpaceService, ISpace, ISharingService, DelegationResult, DelegationRevocationReceipt, DelegationStatus, ServiceSession, ReplicationControl, ResolvedDelegate } from '@tinycloud/sdk-core';
|
|
2
|
+
import { TinyCloudSession, TelemetryConfig, ServiceContext, IKVService, ISQLService, IDuckDbService, IHooksService, CreateOwnerDelegationParams as CreateOwnerDelegationParams$1, OwnerDelegationReceipt as OwnerDelegationReceipt$1, Delegation, IWasmBindings, ISigner, StorageFullEvent, IStorageService, RegistryPolicy, RegistrySequenceStore, RegistryCacheStore, RegistryFallbackReason, OnNodeNotFound, LocalNodeIdentityStore, ISessionStorage, INotificationHandler, IENSResolver, ISpaceCreationHandler, SiweConfig, Manifest, ComposedManifestRequest, RetryPolicy, ReplicationOptions, KVReplicaStorage, PermissionEntry, AccountService, SignInOptions, InvokeAnyFunction as InvokeAnyFunction$1, UnifiedPolicyCapability, RegisterPolicyV3Input, RegisterPolicyV3Receipt, CanonicalJson, ShareDeliveryAuthorizationV3Receipt, IDataVaultService, IEncryptionService, NetworkDescriptor, ISecretsService, ICapabilityKeyRegistry, DelegationManager, ISpaceService, ISpace, ISharingService, DelegationResult, DelegationRevocationReceipt, DelegationStatus, ServiceSession, ReplicationControl, ResolvedDelegate } from '@tinycloud/sdk-core';
|
|
3
3
|
import { ReplicaPurgeFailedEvent, ReplicaSessionStamp } from '@tinycloud/sdk-services/kv/replication';
|
|
4
4
|
import { InvokeFunction, InvokeAnyFunction, FetchFunction, RequestSink, RequestLogReader } from '@tinycloud/sdk-services';
|
|
5
5
|
import { NamedKeyClient } from '@tinycloud/sdk-services/encryption/named-keys';
|
|
6
|
-
import { S as SpaceHosting, c as SignStrategy, a as NodeUserAuthorization, P as PreparedOpenKeyAuthorization } from './NodeUserAuthorization-
|
|
7
|
-
import { P as PortableDelegation, S as SessionGrantProof, e as VerifiedSessionGrant } from './delegation-
|
|
6
|
+
import { S as SpaceHosting, c as SignStrategy, a as NodeUserAuthorization, P as PreparedOpenKeyAuthorization } from './NodeUserAuthorization-B_TFUlua.cjs';
|
|
7
|
+
import { P as PortableDelegation, S as SessionGrantProof, e as VerifiedSessionGrant } from './delegation-CeOWDnBB.cjs';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* The handles needed to rehydrate this delegation activation in a fresh
|
|
@@ -192,32 +192,15 @@ interface TinyCloudNodeConfig {
|
|
|
192
192
|
signer?: ISigner;
|
|
193
193
|
/** Strategy for root signature requests. Defaults to auto-sign for local keys. */
|
|
194
194
|
signStrategy?: SignStrategy;
|
|
195
|
-
/**
|
|
195
|
+
/** Host hint for genuine no-entry onboarding; a signed registry entry takes precedence. */
|
|
196
196
|
host?: string;
|
|
197
197
|
/** Build a developer request log (sanitized, in-memory, bounded). Off by default. */
|
|
198
198
|
requestLog?: boolean;
|
|
199
199
|
/** TinyCloud location registry URL. Default: https://registry.tinycloud.xyz. */
|
|
200
200
|
tinycloudRegistryUrl?: string | null;
|
|
201
|
-
/**
|
|
202
|
-
* Fallback TinyCloud hosts. Default: hosted TinyCloud node. Used only by the
|
|
203
|
-
* default `registryPolicy` ("legacy-fallback"), whose silent fallback is
|
|
204
|
-
* deprecated and will be removed in a future major release.
|
|
205
|
-
*/
|
|
201
|
+
/** Host hints for genuine no-entry onboarding. Never used for registered or unavailable owners. */
|
|
206
202
|
tinycloudFallbackHosts?: string[] | null;
|
|
207
|
-
/**
|
|
208
|
-
* How sign-in uses the location registry when no `host` is configured.
|
|
209
|
-
* Default `"legacy-fallback"` (deprecated): a registry miss or failure
|
|
210
|
-
* silently uses `tinycloudFallbackHosts`, with a one-time warning.
|
|
211
|
-
* `"fail-closed"`: routing acts on the registry verdict for the signer
|
|
212
|
-
* address, an unavailable registry is `RegistryUnavailableError` (never a
|
|
213
|
-
* new account), record hosts are used only if HTTPS or loopback, and
|
|
214
|
-
* automatic space creation (sign-in, account bootstrap, owned-space
|
|
215
|
-
* hosting, the public space the vault creates) is refused on a host the
|
|
216
|
-
* owner's registry record does not list (`NodeRegistryEntryExistsError`)
|
|
217
|
-
* or when the registry gives no verdict. An explicit `hostOwnedSpace()`
|
|
218
|
-
* call is not guarded. `newUserHost` governs routing only: a pinned host
|
|
219
|
-
* may still create spaces for an unregistered owner.
|
|
220
|
-
*/
|
|
203
|
+
/** Registry routing is always v2-first and fail-closed. */
|
|
221
204
|
registryPolicy?: RegistryPolicy;
|
|
222
205
|
/** `fail-closed` only: host for owners with no registry record. Default https://node.tinycloud.xyz; `null` refuses them with `NodeNotFoundError`. */
|
|
223
206
|
newUserHost?: string | null;
|
|
@@ -225,9 +208,13 @@ interface TinyCloudNodeConfig {
|
|
|
225
208
|
registryChainId?: number;
|
|
226
209
|
/** `fail-closed` only: highest registry sequence seen per owner. Default: in-memory for this client. */
|
|
227
210
|
registrySequenceStore?: RegistrySequenceStore;
|
|
228
|
-
/**
|
|
211
|
+
/** Exact signed-v2 responses; pass a persistent adapter to survive restarts. */
|
|
212
|
+
registryCacheStore?: RegistryCacheStore;
|
|
213
|
+
/** Value-free warning after an actual cached-settings or default-node fallback. */
|
|
214
|
+
onRegistryFallback?: (reason: string, code?: RegistryFallbackReason) => void;
|
|
215
|
+
/** Retry or abort when registry resolution fails; `use-host` is accepted only for genuine no-entry onboarding. */
|
|
229
216
|
onNodeNotFound?: OnNodeNotFound;
|
|
230
|
-
/** Probe configured
|
|
217
|
+
/** Probe configured local nodes only for genuine no-entry onboarding. Default: true. */
|
|
231
218
|
autoDiscoverLocalNode?: boolean;
|
|
232
219
|
/** Local loopback node URL to probe. Omit to avoid probing loopback. */
|
|
233
220
|
localNodeUrl?: string;
|
|
@@ -487,6 +474,7 @@ declare class TinyCloudNode {
|
|
|
487
474
|
static registerNodeDefaults(defaults: NodeDefaults): void;
|
|
488
475
|
private config;
|
|
489
476
|
private readonly explicitHost?;
|
|
477
|
+
private readonly registryRefreshOwners;
|
|
490
478
|
private signer;
|
|
491
479
|
private auth;
|
|
492
480
|
private readonly consumedOpenKeyPendings;
|
|
@@ -698,6 +686,8 @@ declare class TinyCloudNode {
|
|
|
698
686
|
* `unknown` answer leaves the previous one in place.
|
|
699
687
|
*/
|
|
700
688
|
checkSpaceHosting(space?: string): Promise<SpaceHosting>;
|
|
689
|
+
/** Run the existing primary-space creation flow for the restored session. */
|
|
690
|
+
ensurePrimarySpaceHosted(hosting: SpaceHosting): Promise<void>;
|
|
701
691
|
/**
|
|
702
692
|
* The node's last answer for the primary space: recorded at sign-in from the
|
|
703
693
|
* activation, or by {@link checkSpaceHosting}. `unknown` after a restore until
|
|
@@ -756,7 +746,12 @@ declare class TinyCloudNode {
|
|
|
756
746
|
private shouldUseBootstrapSignInRequest;
|
|
757
747
|
/** Sanitized developer request events; undefined unless the node was built with `requestLog: true`. */
|
|
758
748
|
get requests(): RequestLogReader | undefined;
|
|
749
|
+
private throwRegistryRefusal;
|
|
759
750
|
private createServiceGraphLifetime;
|
|
751
|
+
private routingDestinations;
|
|
752
|
+
/** Transport hints cannot override verified full-resource registry routing. */
|
|
753
|
+
resolveRegisteredDelegationHost(permissions: readonly PermissionEntry[], noEntryHost: string): Promise<string | undefined>;
|
|
754
|
+
private bindRoutedAudience;
|
|
760
755
|
private syncResolvedHostFromAuth;
|
|
761
756
|
/**
|
|
762
757
|
* Install or replace the manifest that drives the SIWE recap at
|
|
@@ -809,6 +804,9 @@ declare class TinyCloudNode {
|
|
|
809
804
|
* rather than treating a malformed session as unrestricted authority.
|
|
810
805
|
*/
|
|
811
806
|
getVerifiedSessionCapabilities(): PermissionEntry[];
|
|
807
|
+
/** Start one background refresh for each owner derived from verified authority. */
|
|
808
|
+
refreshRegistryForCapabilities(permissions: readonly PermissionEntry[]): void;
|
|
809
|
+
private refreshRegistryOwner;
|
|
812
810
|
/** Normalize signed capabilities without collapsing nested encryption into raw authority. */
|
|
813
811
|
private projectSignedRecapCapabilities;
|
|
814
812
|
/**
|
|
@@ -1051,23 +1049,15 @@ declare class TinyCloudNode {
|
|
|
1051
1049
|
* session's recap doesn't cover it and the registry has no record; the host
|
|
1052
1050
|
* SIWE is idempotent server-side. Must be called after {@link signIn}.
|
|
1053
1051
|
*
|
|
1054
|
-
*
|
|
1055
|
-
*
|
|
1056
|
-
*
|
|
1057
|
-
* verdict. {@link hostOwnedSpace} itself is an explicit action and is not
|
|
1058
|
-
* guarded.
|
|
1052
|
+
* Current signed per-space membership is checked before both automatic and
|
|
1053
|
+
* explicit hosting. Registered replicas use the session grant; no-entry
|
|
1054
|
+
* onboarding retains the host-SIWE flow.
|
|
1059
1055
|
*
|
|
1060
1056
|
* @param name - The owned space name (e.g. `"secrets"`).
|
|
1061
1057
|
* @returns The hosted owned-space URI.
|
|
1062
1058
|
*/
|
|
1063
1059
|
ensureOwnedSpaceHosted(name: string): Promise<string>;
|
|
1064
|
-
/**
|
|
1065
|
-
* Space-creation guard (TC-1443) for the automatic hosting paths: sign-in's
|
|
1066
|
-
* owned spaces, account bootstrap, {@link ensureOwnedSpaceHosted} and
|
|
1067
|
-
* {@link ensurePublicSpace}. Only `registryPolicy: "fail-closed"` consults
|
|
1068
|
-
* the registry ({@link NodeUserAuthorization.assertMayCreateSpace}); the
|
|
1069
|
-
* default policy performs no lookup.
|
|
1070
|
-
*/
|
|
1060
|
+
/** Refresh full-space membership before any automatic or explicit hosting. */
|
|
1071
1061
|
private assertMayCreateSpace;
|
|
1072
1062
|
/** Registry-policy settings shared by every authorization this client creates. */
|
|
1073
1063
|
private registryPolicyConfig;
|
|
@@ -1149,13 +1139,8 @@ declare class TinyCloudNode {
|
|
|
1149
1139
|
*/
|
|
1150
1140
|
expiresAt?: string;
|
|
1151
1141
|
/**
|
|
1152
|
-
*
|
|
1153
|
-
*
|
|
1154
|
-
* adopted so the restored session targets the same node as the
|
|
1155
|
-
* original sign-in — without this, service calls fall back to the
|
|
1156
|
-
* default host and the auth layer throws "TinyCloud hosts have not
|
|
1157
|
-
* been resolved". When absent (old persisted session) hosts resolve
|
|
1158
|
-
* lazily via the registry/fallback on the first host-needing call.
|
|
1142
|
+
* Persisted node origins are no-entry hints only. Restore resolves the
|
|
1143
|
+
* current signed entry before selecting any data destination.
|
|
1159
1144
|
*/
|
|
1160
1145
|
tinycloudHosts?: string[];
|
|
1161
1146
|
/**
|
|
@@ -1171,21 +1156,6 @@ declare class TinyCloudNode {
|
|
|
1171
1156
|
}): Promise<void>;
|
|
1172
1157
|
private stagePrimarySessionState;
|
|
1173
1158
|
private stageRestoredServiceGraph;
|
|
1174
|
-
/**
|
|
1175
|
-
* Resolve the host a restored session should target.
|
|
1176
|
-
*
|
|
1177
|
-
* Mirrors fresh sign-in host resolution but for the restore path:
|
|
1178
|
-
* an explicit/pinned host always wins, then the hosts the session was
|
|
1179
|
-
* persisted with, then a lazy registry/fallback resolution for sessions
|
|
1180
|
-
* that predate the persisted `tinycloudHosts` field. Returns `undefined`
|
|
1181
|
-
* only when there's nothing to resolve from (no explicit host, no
|
|
1182
|
-
* persisted hosts, and no address/chainId) — in which case the existing
|
|
1183
|
-
* `config.host` (default) is left in place.
|
|
1184
|
-
*
|
|
1185
|
-
* Resolution failures are surfaced, not swallowed: a genuinely broken
|
|
1186
|
-
* registry lookup throws rather than silently falling back to a wrong host.
|
|
1187
|
-
*/
|
|
1188
|
-
private resolveRestoredHost;
|
|
1189
1159
|
/**
|
|
1190
1160
|
* Resolve the currently-active TinyCloudSession, preferring the auth
|
|
1191
1161
|
* layer's value (wallet mode) and falling back to the node-level
|
|
@@ -1288,6 +1258,7 @@ declare class TinyCloudNode {
|
|
|
1288
1258
|
*/
|
|
1289
1259
|
private fetchNodeId;
|
|
1290
1260
|
private signRawNetworkAuthorization;
|
|
1261
|
+
private encryptionDestination;
|
|
1291
1262
|
private fetchEncryptionNetworkAt;
|
|
1292
1263
|
private createEncryptionService;
|
|
1293
1264
|
private getEncryptionService;
|
|
@@ -1534,6 +1505,9 @@ declare class TinyCloudNode {
|
|
|
1534
1505
|
* which also refuses decrypt-only grants.
|
|
1535
1506
|
*/
|
|
1536
1507
|
verifySessionGrant(grant: SessionGrantProof): VerifiedSessionGrant;
|
|
1508
|
+
private activateResourceSession;
|
|
1509
|
+
private activateRoutedDelegation;
|
|
1510
|
+
private activateSignedSession;
|
|
1537
1511
|
/**
|
|
1538
1512
|
* Install a portable runtime permission delegation into this SDK instance so
|
|
1539
1513
|
* matching service calls and downstream `delegateTo()` calls can use it.
|