@tinycloud/node-sdk 3.11.0 → 3.12.0-beta.1
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/dist/NodeUserAuthorization-BtoDI9in.d.cts +900 -0
- package/dist/NodeUserAuthorization-BtoDI9in.d.ts +900 -0
- package/dist/{TinyCloudNode-BlNcvo1c.d.ts → TinyCloudNode-C24728N_.d.cts} +30 -874
- package/dist/{TinyCloudNode-CnVaWnAX.d.cts → TinyCloudNode-DLrINr98.d.ts} +30 -874
- package/dist/{WasmKeyProvider-BKCPRC-c.d.cts → WasmKeyProvider-OA0LqmTg.d.cts} +2 -0
- package/dist/{WasmKeyProvider-BKCPRC-c.d.ts → WasmKeyProvider-OA0LqmTg.d.ts} +2 -0
- package/dist/{authority-DHIk5QvV.d.ts → authority-BQN2Z3st.d.ts} +1 -1
- package/dist/{authority-B2SLx27M.d.cts → authority-DDdheOL6.d.cts} +1 -1
- package/dist/core.cjs +179 -100
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.cts +6 -5
- package/dist/core.d.ts +6 -5
- package/dist/core.js +180 -101
- 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-Ckc3UETl.d.cts → delegation-BQbAuKad.d.cts} +1 -1
- package/dist/{delegation-Ckc3UETl.d.ts → delegation-BQbAuKad.d.ts} +1 -1
- package/dist/encryption-keys.d.cts +3 -2
- package/dist/encryption-keys.d.ts +3 -2
- package/dist/index.cjs +179 -100
- 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 +180 -101
- package/dist/index.js.map +1 -1
- package/dist/replication/authority.d.cts +4 -3
- package/dist/replication/authority.d.ts +4 -3
- package/dist/space-hosting.cjs +141 -0
- package/dist/space-hosting.cjs.map +1 -0
- package/dist/space-hosting.d.cts +69 -0
- package/dist/space-hosting.d.ts +69 -0
- package/dist/space-hosting.js +115 -0
- package/dist/space-hosting.js.map +1 -0
- package/package.json +11 -1
package/dist/core.d.cts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { ReplicationOptions, Manifest, PermissionEntry } from '@tinycloud/sdk-core';
|
|
2
2
|
export { ACCOUNT_REGISTRY_PATH, ACCOUNT_REGISTRY_SPACE, AccountApplication, AccountApplicationListOptions, AccountApplicationRegisterOptions, AccountDelegation, AccountDelegationListOptions, AccountDelegationRevokeOptions, AccountIndexEnsureResult, AccountIndexRebuildResult, AccountIndexStatus, AccountIndexedReadOptions, AccountService, AccountServiceConfig, AccountSpace, AccountSpaceListOptions, AccountStatus, AuthorityRefusal, AutoApproveSpaceCreationHandler, AutoRejectStrategy, AutoSignStrategy, BatchOptions, BatchResponse, CallbackStrategy, CanonicalAddress, CanonicalParsedNetworkId, CapabilityEntry, CapabilityKeyRegistry, CapabilityKeyRegistryErrorCode, CapabilityKeyRegistryErrorCodes, CaveatedDelegationUnsupportedError, ClientSession, ColumnInfo, ComposeManifestOptions, ComposedManifestRequest, CreateDelegationParams, DEFAULT_MANIFEST_SPACE, DEFAULT_MANIFEST_VERSION, DEFAULT_SIGNED_READ_URL_EXPIRY_MS, DataVaultConfig, DataVaultService, DatabaseHandle, DelegateReceivedShareParams, DelegatedShareAccess, Delegation, DelegationChain, DelegationChainV2, DelegationDirection, DelegationError, DelegationErrorCode, DelegationErrorCodes, DelegationFilters, DelegationManager, DelegationManagerConfig, DelegationRecord, DelegationResult, DidCacheKeyOptions, DidEqualsOptions, DuckDbAction, DuckDbActionType, DuckDbBatchOptions, DuckDbBatchResponse, DuckDbDatabaseHandle, DuckDbExecuteOptions, DuckDbExecuteResponse, DuckDbOptions, DuckDbQueryOptions, DuckDbQueryResponse, DuckDbService, DuckDbServiceConfig, DuckDbStatement, DuckDbValue, EncodedShareData, ExecuteOptions, ExecuteResponse, Extension, FetchFunction, GenerateShareParams, ICapabilityKeyRegistry, IDataVaultService, IDatabaseHandle, IDuckDbDatabaseHandle, IDuckDbService, IENSResolver, IKVService, INotificationHandler, IPrefixedKVService, ISQLService, ISecretsService, ISessionManager, ISessionStorage, ISharingService, ISigner, ISpace, ISpaceCreationHandler, ISpaceScopedDelegations, ISpaceScopedSharing, ISpaceService, IUserAuthorization, IWasmBindings, IdentityParseError, IngestOptions, InvokeFunction, JWK, KVBatchReadResponse, KVCreateSignedReadUrlOptions, KVListPage, KVReadThrough, KVReplicaHandle, KVReplicaSpec, KVReplicaStorage, KVReplicationController, KVReplicationDeps, KVResponse, KVService, KVServiceConfig, KVSignedReadUrlResponse, KeyInfo, KeyProvider, KeyType, LocalGetResult, LocalListResult, LocalReadMeta, LocalReplicaStatus, LocalSyncResult, Manifest, ManifestDefaults, ManifestRegistryRecord, ManifestSecretActions, ManifestValidationError, OpenKeyCallbackStrategy, OpenKeySigningRequestBody, OpenKeySigningResponseBody, OpenKeySigningStrategyOptions, ParsedSecretCatalogKey, PendingWriteRecord, PendingWriteState, PendingWriteStore, PermissionEntry, PermissionNotInManifestError, PersistedSessionData, PinnedKey, PkhDidParts, PrefixedKVService, ProtocolMismatchError, PurgeTarget, QueryOptions, QueryResponse, ReceiveOptions, RegisterBatchSuccess, RegisterPolicyV3Input, RegisterPolicyV3Receipt, ReplicaAuthorityState, ReplicaCoverage, ReplicaDevice, ReplicaGatedHandle, ReplicaGrantInfo, ReplicaInspectedStatus, ReplicaState, ReplicaStatusEntry, ReplicationAuthority, ReplicationControl, ReplicationEvent, ReplicationIdentity, ReplicationOptions, ReplicationPurgeReport, ReplicationReason, ReplicationScheduler, ResolvedCapabilities, ResolvedDelegate, ResolvedReplicationOptions, ResolvedSecretPath, ResourceCapability, SECRET_NAME_RE, SQLAction, SQLActionType, SQLService, SQLServiceConfig, SchemaInfo, SecretCatalogEntry, SecretPayload, SecretScopeOptions, SecretsError, SecretsService, ServiceContext, ServiceContextConfig, ServiceSession, SessionExpiredError, ShareAccess, ShareLink, ShareLinkData, ShareSchema, SharingService, SharingServiceConfig, SignCallback, SignInOptions, SignRequest, SignResponse, SilentNotificationHandler, Space, SpaceAbilitiesMap, SpaceConfig, SpaceCreationContext, SpaceErrorCode, SpaceErrorCodes, SpaceInfo, SpaceOwnership, SpaceService, SpaceServiceConfig, SqlStatement, SqlValue, StoredDelegationChain, TableInfo, TelemetryConfig, TelemetryEventHandler, TinyCloud, TinyCloudConfig, TinyCloudDebugEnableOptions, TinyCloudDebugEvent, TinyCloudDebugLevel, TinyCloudDebugLogger, TinyCloudDebugTimer, TinyCloudSession, UnsupportedFeatureError, VAULT_PERMISSION_SERVICE, VaultCrypto, VaultEntry, VaultError, VaultGetOptions, VaultGrantOptions, VaultHeaders, VaultListOptions, VaultNetworkReadResult, VaultPublicSpaceKVActions, VaultPutOptions, VersionCheckError, ViewInfo, WasmVaultFunctions, addressStorageKey, buildSpaceUri, canonicalizeAddress, canonicalizeDid, canonicalizeDidUrl, canonicalizeNetworkId, canonicalizeSecretScope, checkNodeInfo, clearTinyCloudDebugLogs, composeManifestRequest, createCapabilityKeyRegistry, createOpenKeyCallbackSigningStrategy, createSharingService, createSpaceService, createVaultCrypto, defaultSpaceCreationHandler, didCacheKey, didEquals, disableTinyCloudDebug, enableTinyCloudDebug, expandActionShortNames, expandPermissionEntries, expandPermissionEntry, getTinyCloudDebugLogs, installTinyCloudDebugGlobals, isCapabilitySubset, isEvmAddress, loadManifest, makePkhSpaceId, makePublicSpaceId, parseCanonicalNetworkId, parseExpiry, parsePkhDid, parseSecretCatalogKey, parseSpaceUri, pkhDid, principalDid, principalDidEquals, resolveManifest, resolveSecretListPrefix, resolveSecretPath, resourceCapabilitiesToSpaceAbilitiesMap, tinyCloudDebugLogger, validateManifest } from '@tinycloud/sdk-core';
|
|
3
3
|
import { _ as __gated_network } from './gated-network-BEF2XSTC.cjs';
|
|
4
|
-
import { _ as __authority } from './authority-
|
|
4
|
+
import { _ as __authority } from './authority-DDdheOL6.cjs';
|
|
5
5
|
import { _ as __runtime } from './runtime-mRhSu-vJ.cjs';
|
|
6
6
|
import { ReplicaDenyInput } from '@tinycloud/sdk-services/kv/replication';
|
|
7
|
-
export { F as FileSessionStorage, M as MemorySessionStorage, W as WasmKeyProvider, a as WasmKeyProviderConfig, c as createWasmKeyProvider, i as isAppKeyHostBound } from './WasmKeyProvider-
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
7
|
+
export { F as FileSessionStorage, M as MemorySessionStorage, W as WasmKeyProvider, a as WasmKeyProviderConfig, c as createWasmKeyProvider, i as isAppKeyHostBound } from './WasmKeyProvider-OA0LqmTg.cjs';
|
|
8
|
+
export { N as NodeEventEmitterStrategy, a as NodeUserAuthorization, b as NodeUserAuthorizationConfig, O as OpenKeyAuthorizeTinyCloud, P as PreparedOpenKeyAuthorization, c as SignStrategy, S as SpaceHosting, d as defaultSignStrategy, w as wireOpenKeyAuthorize } from './NodeUserAuthorization-BtoDI9in.cjs';
|
|
9
|
+
export { B as BootstrapWarning, C as CreateOwnerDelegationParams, D as DelegateToOptions, a as DelegateToResult, b as DelegatedAccess, E as EnsureEncryptionNetworkOptions, I as InvalidRestoredSessionError, O as OwnerDelegationReceipt, R as RuntimePermissionGrantOptions, S as SecretPermissionHint, c as SecretReadInput, d as SecretReadResult, T as TinyCloudNode, e as TinyCloudNodeConfig, U as UnifiedOwnerRootInput, f as UnifiedOwnerRootReceipt, g as UnsupportedSessionRestoreError } from './TinyCloudNode-C24728N_.cjs';
|
|
10
|
+
export { C as CompactRuntimeDelegationInput, P as PortableDelegation, R as RuntimeDelegationRejectedError, a as RuntimeDelegationRejection, V as ValidatedRuntimeDelegation, b as activateCompactRuntimeDelegation, c as activateValidatedRuntimeDelegation, d as deserializeDelegation, s as serializeDelegation } from './delegation-BQbAuKad.cjs';
|
|
10
11
|
import '@tinycloud/sdk-services';
|
|
11
|
-
import '@tinycloud/sdk-services/encryption/named-keys';
|
|
12
12
|
import 'events';
|
|
13
|
+
import '@tinycloud/sdk-services/encryption/named-keys';
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* The `@tinycloud/replica/profile-gate` members the node adapter uses, typed structurally: node-sdk
|
package/dist/core.d.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { ReplicationOptions, Manifest, PermissionEntry } from '@tinycloud/sdk-core';
|
|
2
2
|
export { ACCOUNT_REGISTRY_PATH, ACCOUNT_REGISTRY_SPACE, AccountApplication, AccountApplicationListOptions, AccountApplicationRegisterOptions, AccountDelegation, AccountDelegationListOptions, AccountDelegationRevokeOptions, AccountIndexEnsureResult, AccountIndexRebuildResult, AccountIndexStatus, AccountIndexedReadOptions, AccountService, AccountServiceConfig, AccountSpace, AccountSpaceListOptions, AccountStatus, AuthorityRefusal, AutoApproveSpaceCreationHandler, AutoRejectStrategy, AutoSignStrategy, BatchOptions, BatchResponse, CallbackStrategy, CanonicalAddress, CanonicalParsedNetworkId, CapabilityEntry, CapabilityKeyRegistry, CapabilityKeyRegistryErrorCode, CapabilityKeyRegistryErrorCodes, CaveatedDelegationUnsupportedError, ClientSession, ColumnInfo, ComposeManifestOptions, ComposedManifestRequest, CreateDelegationParams, DEFAULT_MANIFEST_SPACE, DEFAULT_MANIFEST_VERSION, DEFAULT_SIGNED_READ_URL_EXPIRY_MS, DataVaultConfig, DataVaultService, DatabaseHandle, DelegateReceivedShareParams, DelegatedShareAccess, Delegation, DelegationChain, DelegationChainV2, DelegationDirection, DelegationError, DelegationErrorCode, DelegationErrorCodes, DelegationFilters, DelegationManager, DelegationManagerConfig, DelegationRecord, DelegationResult, DidCacheKeyOptions, DidEqualsOptions, DuckDbAction, DuckDbActionType, DuckDbBatchOptions, DuckDbBatchResponse, DuckDbDatabaseHandle, DuckDbExecuteOptions, DuckDbExecuteResponse, DuckDbOptions, DuckDbQueryOptions, DuckDbQueryResponse, DuckDbService, DuckDbServiceConfig, DuckDbStatement, DuckDbValue, EncodedShareData, ExecuteOptions, ExecuteResponse, Extension, FetchFunction, GenerateShareParams, ICapabilityKeyRegistry, IDataVaultService, IDatabaseHandle, IDuckDbDatabaseHandle, IDuckDbService, IENSResolver, IKVService, INotificationHandler, IPrefixedKVService, ISQLService, ISecretsService, ISessionManager, ISessionStorage, ISharingService, ISigner, ISpace, ISpaceCreationHandler, ISpaceScopedDelegations, ISpaceScopedSharing, ISpaceService, IUserAuthorization, IWasmBindings, IdentityParseError, IngestOptions, InvokeFunction, JWK, KVBatchReadResponse, KVCreateSignedReadUrlOptions, KVListPage, KVReadThrough, KVReplicaHandle, KVReplicaSpec, KVReplicaStorage, KVReplicationController, KVReplicationDeps, KVResponse, KVService, KVServiceConfig, KVSignedReadUrlResponse, KeyInfo, KeyProvider, KeyType, LocalGetResult, LocalListResult, LocalReadMeta, LocalReplicaStatus, LocalSyncResult, Manifest, ManifestDefaults, ManifestRegistryRecord, ManifestSecretActions, ManifestValidationError, OpenKeyCallbackStrategy, OpenKeySigningRequestBody, OpenKeySigningResponseBody, OpenKeySigningStrategyOptions, ParsedSecretCatalogKey, PendingWriteRecord, PendingWriteState, PendingWriteStore, PermissionEntry, PermissionNotInManifestError, PersistedSessionData, PinnedKey, PkhDidParts, PrefixedKVService, ProtocolMismatchError, PurgeTarget, QueryOptions, QueryResponse, ReceiveOptions, RegisterBatchSuccess, RegisterPolicyV3Input, RegisterPolicyV3Receipt, ReplicaAuthorityState, ReplicaCoverage, ReplicaDevice, ReplicaGatedHandle, ReplicaGrantInfo, ReplicaInspectedStatus, ReplicaState, ReplicaStatusEntry, ReplicationAuthority, ReplicationControl, ReplicationEvent, ReplicationIdentity, ReplicationOptions, ReplicationPurgeReport, ReplicationReason, ReplicationScheduler, ResolvedCapabilities, ResolvedDelegate, ResolvedReplicationOptions, ResolvedSecretPath, ResourceCapability, SECRET_NAME_RE, SQLAction, SQLActionType, SQLService, SQLServiceConfig, SchemaInfo, SecretCatalogEntry, SecretPayload, SecretScopeOptions, SecretsError, SecretsService, ServiceContext, ServiceContextConfig, ServiceSession, SessionExpiredError, ShareAccess, ShareLink, ShareLinkData, ShareSchema, SharingService, SharingServiceConfig, SignCallback, SignInOptions, SignRequest, SignResponse, SilentNotificationHandler, Space, SpaceAbilitiesMap, SpaceConfig, SpaceCreationContext, SpaceErrorCode, SpaceErrorCodes, SpaceInfo, SpaceOwnership, SpaceService, SpaceServiceConfig, SqlStatement, SqlValue, StoredDelegationChain, TableInfo, TelemetryConfig, TelemetryEventHandler, TinyCloud, TinyCloudConfig, TinyCloudDebugEnableOptions, TinyCloudDebugEvent, TinyCloudDebugLevel, TinyCloudDebugLogger, TinyCloudDebugTimer, TinyCloudSession, UnsupportedFeatureError, VAULT_PERMISSION_SERVICE, VaultCrypto, VaultEntry, VaultError, VaultGetOptions, VaultGrantOptions, VaultHeaders, VaultListOptions, VaultNetworkReadResult, VaultPublicSpaceKVActions, VaultPutOptions, VersionCheckError, ViewInfo, WasmVaultFunctions, addressStorageKey, buildSpaceUri, canonicalizeAddress, canonicalizeDid, canonicalizeDidUrl, canonicalizeNetworkId, canonicalizeSecretScope, checkNodeInfo, clearTinyCloudDebugLogs, composeManifestRequest, createCapabilityKeyRegistry, createOpenKeyCallbackSigningStrategy, createSharingService, createSpaceService, createVaultCrypto, defaultSpaceCreationHandler, didCacheKey, didEquals, disableTinyCloudDebug, enableTinyCloudDebug, expandActionShortNames, expandPermissionEntries, expandPermissionEntry, getTinyCloudDebugLogs, installTinyCloudDebugGlobals, isCapabilitySubset, isEvmAddress, loadManifest, makePkhSpaceId, makePublicSpaceId, parseCanonicalNetworkId, parseExpiry, parsePkhDid, parseSecretCatalogKey, parseSpaceUri, pkhDid, principalDid, principalDidEquals, resolveManifest, resolveSecretListPrefix, resolveSecretPath, resourceCapabilitiesToSpaceAbilitiesMap, tinyCloudDebugLogger, validateManifest } from '@tinycloud/sdk-core';
|
|
3
3
|
import { _ as __gated_network } from './gated-network-BEF2XSTC.js';
|
|
4
|
-
import { _ as __authority } from './authority-
|
|
4
|
+
import { _ as __authority } from './authority-BQN2Z3st.js';
|
|
5
5
|
import { _ as __runtime } from './runtime-CO4VXnPq.js';
|
|
6
6
|
import { ReplicaDenyInput } from '@tinycloud/sdk-services/kv/replication';
|
|
7
|
-
export { F as FileSessionStorage, M as MemorySessionStorage, W as WasmKeyProvider, a as WasmKeyProviderConfig, c as createWasmKeyProvider, i as isAppKeyHostBound } from './WasmKeyProvider-
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
7
|
+
export { F as FileSessionStorage, M as MemorySessionStorage, W as WasmKeyProvider, a as WasmKeyProviderConfig, c as createWasmKeyProvider, i as isAppKeyHostBound } from './WasmKeyProvider-OA0LqmTg.js';
|
|
8
|
+
export { N as NodeEventEmitterStrategy, a as NodeUserAuthorization, b as NodeUserAuthorizationConfig, O as OpenKeyAuthorizeTinyCloud, P as PreparedOpenKeyAuthorization, c as SignStrategy, S as SpaceHosting, d as defaultSignStrategy, w as wireOpenKeyAuthorize } from './NodeUserAuthorization-BtoDI9in.js';
|
|
9
|
+
export { B as BootstrapWarning, C as CreateOwnerDelegationParams, D as DelegateToOptions, a as DelegateToResult, b as DelegatedAccess, E as EnsureEncryptionNetworkOptions, I as InvalidRestoredSessionError, O as OwnerDelegationReceipt, R as RuntimePermissionGrantOptions, S as SecretPermissionHint, c as SecretReadInput, d as SecretReadResult, T as TinyCloudNode, e as TinyCloudNodeConfig, U as UnifiedOwnerRootInput, f as UnifiedOwnerRootReceipt, g as UnsupportedSessionRestoreError } from './TinyCloudNode-DLrINr98.js';
|
|
10
|
+
export { C as CompactRuntimeDelegationInput, P as PortableDelegation, R as RuntimeDelegationRejectedError, a as RuntimeDelegationRejection, V as ValidatedRuntimeDelegation, b as activateCompactRuntimeDelegation, c as activateValidatedRuntimeDelegation, d as deserializeDelegation, s as serializeDelegation } from './delegation-BQbAuKad.js';
|
|
10
11
|
import '@tinycloud/sdk-services';
|
|
11
|
-
import '@tinycloud/sdk-services/encryption/named-keys';
|
|
12
12
|
import 'events';
|
|
13
|
+
import '@tinycloud/sdk-services/encryption/named-keys';
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* The `@tinycloud/replica/profile-gate` members the node adapter uses, typed structurally: node-sdk
|
package/dist/core.js
CHANGED
|
@@ -115,7 +115,7 @@ var MemorySessionStorage = class {
|
|
|
115
115
|
|
|
116
116
|
// src/storage/FileSessionStorage.ts
|
|
117
117
|
import { validatePersistedSessionData } from "@tinycloud/sdk-core";
|
|
118
|
-
import { readFileSync, writeFileSync, existsSync, mkdirSync, unlinkSync } from "fs";
|
|
118
|
+
import { readFileSync, writeFileSync, existsSync, mkdirSync, renameSync, unlinkSync } from "fs";
|
|
119
119
|
import { join } from "path";
|
|
120
120
|
var FileSessionStorage = class {
|
|
121
121
|
/**
|
|
@@ -156,10 +156,22 @@ var FileSessionStorage = class {
|
|
|
156
156
|
async save(address, session) {
|
|
157
157
|
const filePath = this.getFilePath(address);
|
|
158
158
|
const data = JSON.stringify(session, null, 2);
|
|
159
|
-
|
|
159
|
+
const tempPath = `${filePath}.${process.pid}.${process.hrtime.bigint()}.tmp`;
|
|
160
|
+
try {
|
|
161
|
+
writeFileSync(tempPath, data, { mode: 384, flag: "wx" });
|
|
162
|
+
renameSync(tempPath, filePath);
|
|
163
|
+
} catch (error) {
|
|
164
|
+
try {
|
|
165
|
+
unlinkSync(tempPath);
|
|
166
|
+
} catch {
|
|
167
|
+
}
|
|
168
|
+
throw error;
|
|
169
|
+
}
|
|
160
170
|
}
|
|
161
171
|
/**
|
|
162
172
|
* Load a session for an address.
|
|
173
|
+
*
|
|
174
|
+
* Rejects when the file exists but cannot be read or parsed; the file is left in place.
|
|
163
175
|
*/
|
|
164
176
|
async load(address) {
|
|
165
177
|
const filePath = this.getFilePath(address);
|
|
@@ -183,11 +195,9 @@ var FileSessionStorage = class {
|
|
|
183
195
|
}
|
|
184
196
|
return session;
|
|
185
197
|
} catch (error) {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
}
|
|
190
|
-
return null;
|
|
198
|
+
throw new Error(
|
|
199
|
+
`Could not read session file ${filePath}: ${error}`
|
|
200
|
+
);
|
|
191
201
|
}
|
|
192
202
|
}
|
|
193
203
|
/**
|
|
@@ -385,6 +395,18 @@ function refuseCaveated(input) {
|
|
|
385
395
|
import { createOpenKeyCallbackSigningStrategy } from "@tinycloud/sdk-core";
|
|
386
396
|
var defaultSignStrategy = { type: "auto-sign" };
|
|
387
397
|
|
|
398
|
+
// src/storage/clearPersistedSessionIfOwn.ts
|
|
399
|
+
async function clearPersistedSessionIfOwn(storage, address, ownSignature) {
|
|
400
|
+
if (ownSignature !== void 0) {
|
|
401
|
+
try {
|
|
402
|
+
const stored = await storage.load(address);
|
|
403
|
+
if (stored !== null && stored.signature !== ownSignature) return;
|
|
404
|
+
} catch {
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
await storage.clear(address);
|
|
408
|
+
}
|
|
409
|
+
|
|
388
410
|
// src/authorization/NodeUserAuthorization.ts
|
|
389
411
|
function assertMaxExpiresAt(value) {
|
|
390
412
|
if (value === void 0 || typeof value === "function") return;
|
|
@@ -478,6 +500,8 @@ var NodeUserAuthorization = class {
|
|
|
478
500
|
* delegation lists them: the node answers a repeat with empty lists.
|
|
479
501
|
*/
|
|
480
502
|
this._lastActivationActivatedSpaceIds = [];
|
|
503
|
+
/** See {@link spaceHosting}. Written only from node answers. */
|
|
504
|
+
this._spaceHosting = "unknown";
|
|
481
505
|
this.wasm = config.wasmBindings;
|
|
482
506
|
this.signer = config.signer;
|
|
483
507
|
this.signStrategy = config.signStrategy ?? defaultSignStrategy;
|
|
@@ -637,6 +661,7 @@ var NodeUserAuthorization = class {
|
|
|
637
661
|
this.registryVerdict = void 0;
|
|
638
662
|
this._lastActivationSkippedSpaceIds = [];
|
|
639
663
|
this._lastActivationActivatedSpaceIds = [];
|
|
664
|
+
this._spaceHosting = "unknown";
|
|
640
665
|
if (!session) {
|
|
641
666
|
this._session = void 0;
|
|
642
667
|
this._tinyCloudSession = void 0;
|
|
@@ -777,6 +802,18 @@ var NodeUserAuthorization = class {
|
|
|
777
802
|
get lastActivationActivatedSpaceIds() {
|
|
778
803
|
return [...this._lastActivationActivatedSpaceIds];
|
|
779
804
|
}
|
|
805
|
+
/**
|
|
806
|
+
* The node's last answer for whether this session's primary space is hosted:
|
|
807
|
+
* recorded from the sign-in activation, or by {@link noteSpaceHosting}.
|
|
808
|
+
* `unknown` until one of them answers, and after a restore.
|
|
809
|
+
*/
|
|
810
|
+
get spaceHosting() {
|
|
811
|
+
return this._spaceHosting;
|
|
812
|
+
}
|
|
813
|
+
/** @internal Record the hosting probe's answer for the primary space. */
|
|
814
|
+
noteSpaceHosting(hosting) {
|
|
815
|
+
this._spaceHosting = hosting;
|
|
816
|
+
}
|
|
780
817
|
/**
|
|
781
818
|
* Compute the `abilities` map the WASM `prepareSession` call should
|
|
782
819
|
* see at sign-in time.
|
|
@@ -1237,103 +1274,55 @@ var NodeUserAuthorization = class {
|
|
|
1237
1274
|
this._tinyCloudSession.delegationHeader
|
|
1238
1275
|
);
|
|
1239
1276
|
this.recordActivationSkippedSpaces(result, primarySpaceId);
|
|
1277
|
+
if (!result.success && result.status !== 404) {
|
|
1278
|
+
throw Object.assign(
|
|
1279
|
+
new Error(`Failed to activate session: ${describeHostFailure(result)}`),
|
|
1280
|
+
{ cause: result }
|
|
1281
|
+
);
|
|
1282
|
+
}
|
|
1283
|
+
await this.ensurePrimarySpaceHosted(this._spaceHosting);
|
|
1284
|
+
}
|
|
1285
|
+
/**
|
|
1286
|
+
* The create step of {@link ensureSpaceExists}: given the node's answer for
|
|
1287
|
+
* the primary space, host it through the space creation handler when it is
|
|
1288
|
+
* `not-hosted`. Any other answer, and a missing handler, change nothing. The
|
|
1289
|
+
* caller supplies the answer (sign-in's activation, or the hosting probe);
|
|
1290
|
+
* an empty activation list is never one.
|
|
1291
|
+
*
|
|
1292
|
+
* @throws Error if the creation handler fails or times out, or hosting fails
|
|
1293
|
+
*/
|
|
1294
|
+
async ensurePrimarySpaceHosted(hosting) {
|
|
1295
|
+
if (hosting !== "not-hosted") {
|
|
1296
|
+
return;
|
|
1297
|
+
}
|
|
1298
|
+
const session = this._tinyCloudSession;
|
|
1299
|
+
if (!session) {
|
|
1300
|
+
throw new Error("Must be signed in to host the primary space");
|
|
1301
|
+
}
|
|
1240
1302
|
const handler = this.spaceCreationHandler ?? (this.autoCreateSpace ? new AutoApproveSpaceCreationHandler() : void 0);
|
|
1303
|
+
if (!handler) {
|
|
1304
|
+
return;
|
|
1305
|
+
}
|
|
1306
|
+
await this.ensureTinyCloudHosts();
|
|
1307
|
+
const host = this.primaryTinyCloudHost;
|
|
1308
|
+
const primarySpaceId = session.spaceId;
|
|
1241
1309
|
const creationContext = {
|
|
1242
1310
|
spaceId: primarySpaceId,
|
|
1243
1311
|
address: this._address,
|
|
1244
1312
|
chainId: this._chainId,
|
|
1245
1313
|
host
|
|
1246
1314
|
};
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
return;
|
|
1259
|
-
}
|
|
1260
|
-
try {
|
|
1261
|
-
const created = await this.hostSpace();
|
|
1262
|
-
if (!created.success) {
|
|
1263
|
-
const err2 = Object.assign(
|
|
1264
|
-
new Error(`Failed to create space ${primarySpaceId}: ${describeHostFailure(created)}`),
|
|
1265
|
-
{ cause: created }
|
|
1266
|
-
);
|
|
1267
|
-
throw err2;
|
|
1268
|
-
}
|
|
1269
|
-
} catch (error) {
|
|
1270
|
-
handler.onSpaceCreationFailed?.(
|
|
1271
|
-
creationContext,
|
|
1272
|
-
error instanceof Error ? error : new Error(String(error))
|
|
1273
|
-
);
|
|
1274
|
-
throw error;
|
|
1275
|
-
}
|
|
1276
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
1277
|
-
const retryResult = await activateSessionWithHost(
|
|
1278
|
-
host,
|
|
1279
|
-
this._tinyCloudSession.delegationHeader
|
|
1280
|
-
);
|
|
1281
|
-
if (!retryResult.success) {
|
|
1282
|
-
const err2 = Object.assign(
|
|
1283
|
-
new Error(`Failed to activate session after creating space: ${describeHostFailure(retryResult)}`),
|
|
1284
|
-
{ cause: retryResult }
|
|
1285
|
-
);
|
|
1286
|
-
handler.onSpaceCreationFailed?.(creationContext, err2);
|
|
1287
|
-
throw err2;
|
|
1288
|
-
}
|
|
1289
|
-
handler.onSpaceCreated?.(creationContext);
|
|
1290
|
-
return;
|
|
1291
|
-
}
|
|
1292
|
-
if (result.status === 404) {
|
|
1293
|
-
if (!handler) {
|
|
1294
|
-
return;
|
|
1295
|
-
}
|
|
1296
|
-
await this.guardSpaceCreation(handler, creationContext);
|
|
1297
|
-
const confirmed = await handler.confirmSpaceCreation(creationContext);
|
|
1298
|
-
if (!confirmed) {
|
|
1299
|
-
return;
|
|
1300
|
-
}
|
|
1301
|
-
try {
|
|
1302
|
-
const created = await this.hostSpace();
|
|
1303
|
-
if (!created.success) {
|
|
1304
|
-
const err2 = Object.assign(
|
|
1305
|
-
new Error(`Failed to create space ${primarySpaceId}: ${describeHostFailure(created)}`),
|
|
1306
|
-
{ cause: created }
|
|
1307
|
-
);
|
|
1308
|
-
throw err2;
|
|
1309
|
-
}
|
|
1310
|
-
} catch (error) {
|
|
1311
|
-
handler.onSpaceCreationFailed?.(
|
|
1312
|
-
creationContext,
|
|
1313
|
-
error instanceof Error ? error : new Error(String(error))
|
|
1314
|
-
);
|
|
1315
|
-
throw error;
|
|
1316
|
-
}
|
|
1317
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
1318
|
-
const retryResult = await activateSessionWithHost(
|
|
1319
|
-
host,
|
|
1320
|
-
this._tinyCloudSession.delegationHeader
|
|
1321
|
-
);
|
|
1322
|
-
if (!retryResult.success) {
|
|
1323
|
-
const err2 = Object.assign(
|
|
1324
|
-
new Error(`Failed to activate session after creating space: ${describeHostFailure(retryResult)}`),
|
|
1325
|
-
{ cause: retryResult }
|
|
1326
|
-
);
|
|
1327
|
-
handler.onSpaceCreationFailed?.(creationContext, err2);
|
|
1328
|
-
throw err2;
|
|
1329
|
-
}
|
|
1330
|
-
handler.onSpaceCreated?.(creationContext);
|
|
1331
|
-
return;
|
|
1332
|
-
}
|
|
1333
|
-
throw Object.assign(
|
|
1334
|
-
new Error(`Failed to activate session: ${describeHostFailure(result)}`),
|
|
1335
|
-
{ cause: result }
|
|
1336
|
-
);
|
|
1315
|
+
const { createPrimarySpace } = await import("./space-hosting.js");
|
|
1316
|
+
await createPrimarySpace({
|
|
1317
|
+
handler,
|
|
1318
|
+
context: creationContext,
|
|
1319
|
+
guard: () => this.guardSpaceCreation(handler, creationContext),
|
|
1320
|
+
host: () => this.hostSpace(primarySpaceId),
|
|
1321
|
+
onHosted: () => {
|
|
1322
|
+
this._spaceHosting = "hosted";
|
|
1323
|
+
},
|
|
1324
|
+
activate: () => activateSessionWithHost(host, session.delegationHeader)
|
|
1325
|
+
});
|
|
1337
1326
|
}
|
|
1338
1327
|
/** {@link assertMayCreateSpace}, reporting a refusal to the creation handler before rethrowing it. */
|
|
1339
1328
|
async guardSpaceCreation(handler, context) {
|
|
@@ -1349,10 +1338,12 @@ var NodeUserAuthorization = class {
|
|
|
1349
1338
|
if (result.success) {
|
|
1350
1339
|
this._lastActivationSkippedSpaceIds = result.skipped ?? [];
|
|
1351
1340
|
this._lastActivationActivatedSpaceIds = result.activated ?? [];
|
|
1341
|
+
this._spaceHosting = this._lastActivationSkippedSpaceIds.includes(primarySpaceId) ? "not-hosted" : this._lastActivationActivatedSpaceIds.includes(primarySpaceId) ? "hosted" : "unknown";
|
|
1352
1342
|
return;
|
|
1353
1343
|
}
|
|
1354
1344
|
this._lastActivationActivatedSpaceIds = [];
|
|
1355
1345
|
this._lastActivationSkippedSpaceIds = result.status === 404 ? [primarySpaceId] : [];
|
|
1346
|
+
this._spaceHosting = result.status === 404 ? "not-hosted" : "unknown";
|
|
1356
1347
|
}
|
|
1357
1348
|
async createBootstrapSession(options) {
|
|
1358
1349
|
refuseCaveated(options.capabilityRequest.manifests);
|
|
@@ -2201,12 +2192,13 @@ var NodeUserAuthorization = class {
|
|
|
2201
2192
|
};
|
|
2202
2193
|
}
|
|
2203
2194
|
/**
|
|
2204
|
-
* Clear persisted session data.
|
|
2195
|
+
* Clear persisted session data. With `ownSignature`, a stored session that provably has a different
|
|
2196
|
+
* signature (a newer sign-in for the same address) is left alone.
|
|
2205
2197
|
*/
|
|
2206
|
-
async clearPersistedSession(address) {
|
|
2198
|
+
async clearPersistedSession(address, ownSignature) {
|
|
2207
2199
|
const targetAddress = address ?? this._address;
|
|
2208
2200
|
if (targetAddress) {
|
|
2209
|
-
await this.sessionStorage
|
|
2201
|
+
await clearPersistedSessionIfOwn(this.sessionStorage, targetAddress, ownSignature);
|
|
2210
2202
|
}
|
|
2211
2203
|
}
|
|
2212
2204
|
/**
|
|
@@ -4093,6 +4085,8 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4093
4085
|
* hosting is confirmed against the session that was active at the time.
|
|
4094
4086
|
*/
|
|
4095
4087
|
this.confirmedHostedSpaceIds = /* @__PURE__ */ new Set();
|
|
4088
|
+
/** The primary space's hosting answer when no authorization layer holds it (a session-only restore). */
|
|
4089
|
+
this._restoredSpaceHosting = "unknown";
|
|
4096
4090
|
/**
|
|
4097
4091
|
* Owned space ids known to be hosted for the current session: the sign-in
|
|
4098
4092
|
* activation listed them as `activated`, or this session hosted them. Unlike
|
|
@@ -4431,6 +4425,84 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4431
4425
|
));
|
|
4432
4426
|
}
|
|
4433
4427
|
}
|
|
4428
|
+
/**
|
|
4429
|
+
* Whether the TinyCloud node hosts the primary space (the default) or a named
|
|
4430
|
+
* or full-id space: `"hosted"`, `"not-hosted"`, or `"unknown"` when the node
|
|
4431
|
+
* cannot say.
|
|
4432
|
+
*
|
|
4433
|
+
* Sends one authorized read the session already holds on that space (a kv
|
|
4434
|
+
* list under a granted prefix, else kv metadata, `tinycloud.space/info`, or
|
|
4435
|
+
* a kv get of a key that does not exist), signed for that space. A session
|
|
4436
|
+
* with no such read sends nothing and answers `unknown`. A 401/403 registers
|
|
4437
|
+
* the session delegation with the node once and asks again once. Network
|
|
4438
|
+
* failures, 5xx and a 5 s timeout answer `unknown`; this never throws.
|
|
4439
|
+
*
|
|
4440
|
+
* `hosted` is remembered for the session and `not-hosted` never is. The
|
|
4441
|
+
* answer for the primary space is also what {@link spaceHosting} reports; a
|
|
4442
|
+
* `unknown` answer leaves the previous one in place.
|
|
4443
|
+
*/
|
|
4444
|
+
async checkSpaceHosting(space) {
|
|
4445
|
+
try {
|
|
4446
|
+
return await this.probeSpaceHosting(space);
|
|
4447
|
+
} catch {
|
|
4448
|
+
return "unknown";
|
|
4449
|
+
}
|
|
4450
|
+
}
|
|
4451
|
+
/**
|
|
4452
|
+
* The node's last answer for the primary space: recorded at sign-in from the
|
|
4453
|
+
* activation, or by {@link checkSpaceHosting}. `unknown` after a restore until
|
|
4454
|
+
* something asks.
|
|
4455
|
+
*/
|
|
4456
|
+
get spaceHosting() {
|
|
4457
|
+
return this.auth ? this.auth.spaceHosting : this._restoredSpaceHosting;
|
|
4458
|
+
}
|
|
4459
|
+
async probeSpaceHosting(space) {
|
|
4460
|
+
const context = this._serviceContext;
|
|
4461
|
+
const session = context?.session;
|
|
4462
|
+
const host = context?.hosts[0];
|
|
4463
|
+
if (!context || !session || !host) {
|
|
4464
|
+
return "unknown";
|
|
4465
|
+
}
|
|
4466
|
+
const spaceId = space === void 0 ? session.spaceId : space.startsWith("tinycloud:") ? space : this.ownedSpaceId(space);
|
|
4467
|
+
const graph = this._serviceGraph;
|
|
4468
|
+
const epoch = this.sessionEpoch;
|
|
4469
|
+
const assertCurrent = () => {
|
|
4470
|
+
graph.assertActive();
|
|
4471
|
+
if (epoch !== this.sessionEpoch || graph !== this._serviceGraph || this._serviceContext !== context) {
|
|
4472
|
+
throw new Error("The session changed during the hosting check.");
|
|
4473
|
+
}
|
|
4474
|
+
};
|
|
4475
|
+
const { askSpaceHosting } = await import("./space-hosting.js");
|
|
4476
|
+
assertCurrent();
|
|
4477
|
+
this.pruneExpiredRuntimePermissionGrants();
|
|
4478
|
+
const primary = this.currentTinyCloudSession();
|
|
4479
|
+
const answer = await askSpaceHosting({
|
|
4480
|
+
spaceId,
|
|
4481
|
+
operations: [
|
|
4482
|
+
...this.runtimePermissionGrants.flatMap((grant) => grant.operations),
|
|
4483
|
+
...primary ? this.recapOperationsFromSession(primary) : []
|
|
4484
|
+
],
|
|
4485
|
+
covers: (granted, requested) => this.operationCovers(granted, requested),
|
|
4486
|
+
scope: context,
|
|
4487
|
+
host,
|
|
4488
|
+
fetch: unrecordedFetchOf(context),
|
|
4489
|
+
sign: (entries) => {
|
|
4490
|
+
assertCurrent();
|
|
4491
|
+
return graph.invokeAny({ ...session, spaceId }, entries);
|
|
4492
|
+
},
|
|
4493
|
+
// A session saved but never registered on this node is refused: it registers once.
|
|
4494
|
+
activate: (signal) => {
|
|
4495
|
+
assertCurrent();
|
|
4496
|
+
return activateSessionWithHost2(host, session.delegationHeader, AbortSignal.any([signal, graph.signal]));
|
|
4497
|
+
}
|
|
4498
|
+
});
|
|
4499
|
+
assertCurrent();
|
|
4500
|
+
if (answer !== "unknown" && this.spaceIdsEqual(spaceId, session.spaceId)) {
|
|
4501
|
+
if (this.auth) this.auth.noteSpaceHosting(answer);
|
|
4502
|
+
else this._restoredSpaceHosting = answer;
|
|
4503
|
+
}
|
|
4504
|
+
return answer;
|
|
4505
|
+
}
|
|
4434
4506
|
get nodeFeatures() {
|
|
4435
4507
|
return this.auth?.nodeFeatures ?? this._restoredNodeFeatures ?? [];
|
|
4436
4508
|
}
|
|
@@ -4799,6 +4871,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4799
4871
|
const leavingChainId = this._chainId;
|
|
4800
4872
|
const leavingPrincipal = this.replicaSessionPrincipal ?? (leavingAddress ? pkhDid2(leavingAddress, leavingChainId) : void 0);
|
|
4801
4873
|
const leavingAuth = this.auth;
|
|
4874
|
+
const leavingSignature = leavingAuth?.tinyCloudSession?.signature ?? this._restoredTcSession?.signature;
|
|
4802
4875
|
const leavingContext = this._serviceContext;
|
|
4803
4876
|
let denied;
|
|
4804
4877
|
let erased;
|
|
@@ -4815,7 +4888,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4815
4888
|
if (denied) erased = await this.eraseReplicaLocalCopy("sign_out", denied.status);
|
|
4816
4889
|
} finally {
|
|
4817
4890
|
if (leavingAddress) {
|
|
4818
|
-
await (leavingAuth ? leavingAuth.clearPersistedSession(leavingAddress) : this.config.sessionStorage
|
|
4891
|
+
await (leavingAuth ? leavingAuth.clearPersistedSession(leavingAddress, leavingSignature) : this.config.sessionStorage && clearPersistedSessionIfOwn(this.config.sessionStorage, leavingAddress, leavingSignature));
|
|
4819
4892
|
}
|
|
4820
4893
|
}
|
|
4821
4894
|
}
|
|
@@ -4921,6 +4994,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
4921
4994
|
this._spaceService = void 0;
|
|
4922
4995
|
this.runtimePermissionGrants = [];
|
|
4923
4996
|
this._recapOperationsCache = void 0;
|
|
4997
|
+
this._restoredSpaceHosting = "unknown";
|
|
4924
4998
|
this.confirmedHostedSpaceIds.clear();
|
|
4925
4999
|
this.hostedOwnedSpaceIds.clear();
|
|
4926
5000
|
this.cancelOwnedSpaceHosts();
|
|
@@ -5114,6 +5188,10 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
5114
5188
|
const primarySession = this.currentTinyCloudSession();
|
|
5115
5189
|
if (primarySession) {
|
|
5116
5190
|
this.registerPrimarySessionGrant(primarySession);
|
|
5191
|
+
if (this.auth?.spaceHosting === "unknown") {
|
|
5192
|
+
await this.checkSpaceHosting();
|
|
5193
|
+
this.assertSessionEpoch(epoch, "Sign-in");
|
|
5194
|
+
}
|
|
5117
5195
|
}
|
|
5118
5196
|
const bootstrapped = await this.bootstrapAccountIfNeeded();
|
|
5119
5197
|
this.assertSessionEpoch(epoch, "Sign-in");
|
|
@@ -6493,6 +6571,7 @@ var _TinyCloudNode = class _TinyCloudNode {
|
|
|
6493
6571
|
this.tc = stagedGraph.core;
|
|
6494
6572
|
this._recapOperationsCache = stagedPrimary.cache;
|
|
6495
6573
|
this.runtimePermissionGrants = stagedPrimary.grants;
|
|
6574
|
+
this._restoredSpaceHosting = "unknown";
|
|
6496
6575
|
this.confirmedHostedSpaceIds.clear();
|
|
6497
6576
|
this.hostedOwnedSpaceIds.clear();
|
|
6498
6577
|
this.cancelOwnedSpaceHosts();
|