@tinycloud/node-sdk 2.2.0-beta.9 → 2.2.0

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.
@@ -1,4 +1,4 @@
1
- import { ISessionStorage, PersistedSessionData, AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, IUserAuthorization, ISigner, ISpaceCreationHandler, IWasmBindings, SiweConfig, Manifest, ComposedManifestRequest, ClientSession, TinyCloudSession, Extension, SignInOptions, Delegation, DelegatedResource, IKVService, ISQLService, IDuckDbService, IHooksService, INotificationHandler, IENSResolver, IDataVaultService, ISecretsService, ICapabilityKeyRegistry, PermissionEntry, DelegationManager, ISpaceService, ISpace, ISharingService, CreateDelegationParams, DelegationResult, ResolvedDelegate, KeyProvider, ISessionManager, JWK } from '@tinycloud/sdk-core';
1
+ import { ISessionStorage, PersistedSessionData, AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, IUserAuthorization, ISigner, ISpaceCreationHandler, IWasmBindings, SiweConfig, Manifest, ComposedManifestRequest, ClientSession, TinyCloudSession, Extension, SignInOptions, Delegation, DelegatedResource, IKVService, ISQLService, IDuckDbService, IHooksService, INotificationHandler, IENSResolver, IDataVaultService, IEncryptionService, NetworkDescriptor, ISecretsService, ICapabilityKeyRegistry, PermissionEntry, DelegationManager, ISpaceService, ISpace, ISharingService, CreateDelegationParams, DelegationResult, ResolvedDelegate, KeyProvider, ISessionManager, JWK } from '@tinycloud/sdk-core';
2
2
  import { EventEmitter } from 'events';
3
3
  import { InvokeFunction } from '@tinycloud/sdk-services';
4
4
 
@@ -321,6 +321,19 @@ declare class NodeUserAuthorization implements IUserAuthorization {
321
321
  * Includes spaceId, delegationHeader, and delegationCid.
322
322
  */
323
323
  get tinyCloudSession(): TinyCloudSession | undefined;
324
+ /**
325
+ * Rehydrate the auth-layer session from previously-persisted delegation
326
+ * data. Used by {@link TinyCloudNode.restoreSession} so that downstream
327
+ * surfaces that read from `tinyCloudSession` (notably
328
+ * `grantRuntimePermissions`, which extracts the SIWE expiry from it) work
329
+ * without re-running the full sign-in flow.
330
+ *
331
+ * Caller must supply the same fields that `signIn` would have written —
332
+ * `siwe` is the load-bearing one because `extractSiweExpiration` returns
333
+ * undefined for missing SIWEs and the SDK then treats the session as
334
+ * expired-at-epoch-zero.
335
+ */
336
+ setRestoredTinyCloudSession(session: TinyCloudSession): void;
324
337
  private resolveTinyCloudHostsForSignIn;
325
338
  private requireTinyCloudHosts;
326
339
  private get primaryTinyCloudHost();
@@ -353,6 +366,7 @@ declare class NodeUserAuthorization implements IUserAuthorization {
353
366
  */
354
367
  private getCapabilityRequest;
355
368
  private resolveSpaceName;
369
+ private defaultEncryptionNetworkId;
356
370
  private resolveSignInCapabilities;
357
371
  /**
358
372
  * Build SIWE overrides from the top-level nonce and siweConfig.
@@ -777,6 +791,7 @@ declare class TinyCloudNode {
777
791
  private _duckdb?;
778
792
  private _hooks?;
779
793
  private _vault?;
794
+ private _encryption?;
780
795
  private _baseSecrets?;
781
796
  private _secrets?;
782
797
  /** Cached public KV with proper delegation (set by ensurePublicSpace) */
@@ -793,6 +808,13 @@ declare class TinyCloudNode {
793
808
  private _delegationManager?;
794
809
  private _spaceService?;
795
810
  private runtimePermissionGrants;
811
+ /**
812
+ * TinyCloudSession captured by {@link restoreSession} when there's no
813
+ * auth-layer signer available (session-only mode used by OpenKey-backed
814
+ * CLI restores, public-space replays, …). Read by
815
+ * {@link currentTinyCloudSession} as a fallback for `auth.tinyCloudSession`.
816
+ */
817
+ private _restoredTcSession?;
796
818
  private get nodeFeatures();
797
819
  /** SIWE domain — uses config override or defaults to app.tinycloud.xyz */
798
820
  private get siweDomain();
@@ -909,7 +931,28 @@ declare class TinyCloudNode {
909
931
  verificationMethod: string;
910
932
  address?: string;
911
933
  chainId?: number;
934
+ /**
935
+ * The SIWE message that authorized this session. Required for
936
+ * downstream operations that need the session's expiry (e.g.
937
+ * {@link grantRuntimePermissions}). When omitted the SDK can still
938
+ * invoke services with the existing delegation, but anything that
939
+ * reads `auth.tinyCloudSession.siwe` will treat the session as
940
+ * expired-at-epoch-zero.
941
+ */
942
+ siwe?: string;
943
+ /**
944
+ * The wallet/OpenKey signature over `siwe`. Optional because the
945
+ * runtime doesn't re-verify it — it's persisted alongside the SIWE
946
+ * for callers that need to round-trip the full session shape.
947
+ */
948
+ signature?: string;
912
949
  }): Promise<void>;
950
+ /**
951
+ * Resolve the currently-active TinyCloudSession, preferring the auth
952
+ * layer's value (wallet mode) and falling back to the node-level
953
+ * rehydration set by {@link restoreSession} (session-only mode).
954
+ */
955
+ private currentTinyCloudSession;
913
956
  /**
914
957
  * Connect a wallet to upgrade from session-only mode to wallet mode.
915
958
  *
@@ -962,6 +1005,13 @@ declare class TinyCloudNode {
962
1005
  */
963
1006
  private initializeServices;
964
1007
  private createSpaceScopedKVService;
1008
+ getDefaultEncryptionNetworkId(name?: string): string;
1009
+ private requireServiceSession;
1010
+ private createEncryptionCrypto;
1011
+ private fetchNodeId;
1012
+ private signRawNetworkAuthorization;
1013
+ private createEncryptionService;
1014
+ private getEncryptionService;
965
1015
  private createVaultService;
966
1016
  /**
967
1017
  * Initialize the v2 delegation system services.
@@ -1011,6 +1061,21 @@ declare class TinyCloudNode {
1011
1061
  * SQL database operations on this user's space.
1012
1062
  */
1013
1063
  get sql(): ISQLService;
1064
+ /**
1065
+ * Get an SQL service scoped to a specific space.
1066
+ *
1067
+ * Mirrors {@link SpaceService}'s per-space KV factory: clones the active
1068
+ * service context and overrides its session's spaceId so that subsequent
1069
+ * `sql/<dbName>/<action>` invocations route to that space. Useful when
1070
+ * the caller already holds a delegation covering the target space (e.g.
1071
+ * via {@link grantRuntimePermissions} or {@link useRuntimeDelegation})
1072
+ * but the SDK's per-space SQL surface isn't otherwise exposed.
1073
+ *
1074
+ * Does NOT auto-create the space.
1075
+ *
1076
+ * @param spaceId - Full space URI (`tinycloud:pkh:eip155:<chain>:<addr>:<name>`).
1077
+ */
1078
+ sqlForSpace(spaceId: string): ISQLService;
1014
1079
  /**
1015
1080
  * DuckDB database operations on this user's space.
1016
1081
  */
@@ -1020,6 +1085,13 @@ declare class TinyCloudNode {
1020
1085
  * Call `vault.unlock(signer)` after signIn() to derive encryption keys.
1021
1086
  */
1022
1087
  get vault(): IDataVaultService;
1088
+ /**
1089
+ * Network-scoped encryption/decrypt service.
1090
+ */
1091
+ get encryption(): IEncryptionService;
1092
+ getEncryptionNetwork(nameOrNetworkId?: string): Promise<NetworkDescriptor | null>;
1093
+ createEncryptionNetwork(name?: string): Promise<NetworkDescriptor>;
1094
+ ensureEncryptionNetwork(name?: string): Promise<NetworkDescriptor>;
1023
1095
  /**
1024
1096
  * App-facing secrets API backed by the `secrets` space vault.
1025
1097
  */
@@ -1315,11 +1387,8 @@ declare class TinyCloudNode {
1315
1387
  * the current session; we build one multi-resource abilities map
1316
1388
  * and emit one signed UCAN covering them all.
1317
1389
  *
1318
- * All entries must share the same target space (the UCAN is
1319
- * scoped to a single space). If they don't, this throws mixing
1320
- * spaces in a single delegation is not supported by the underlying
1321
- * Rust create_delegation call and the resulting UCAN would be
1322
- * under-specified.
1390
+ * Non-encryption entries must share the same target space. Encryption
1391
+ * entries are raw network URNs and do not participate in space grouping.
1323
1392
  *
1324
1393
  * @internal
1325
1394
  */
@@ -1329,12 +1398,15 @@ declare class TinyCloudNode {
1329
1398
  private expandPermissionEntries;
1330
1399
  private shortServiceName;
1331
1400
  private permissionsToAbilities;
1401
+ private isEncryptionPermissionEntry;
1402
+ private permissionsToRawAbilities;
1332
1403
  private permissionOperations;
1333
1404
  private sessionCoversPermissionEntries;
1334
1405
  private permissionEntriesToOperations;
1335
1406
  private findRuntimeGrantsForPermissionEntries;
1336
1407
  private runtimeDelegationFromSession;
1337
1408
  private runtimeGrantFromDelegation;
1409
+ private installRuntimeGrantFromServiceSession;
1338
1410
  private delegatedResourcesForEntries;
1339
1411
  private operationsFromDelegation;
1340
1412
  private flatDelegationResources;
@@ -1345,6 +1417,8 @@ declare class TinyCloudNode {
1345
1417
  private operationCovers;
1346
1418
  private actionContains;
1347
1419
  private invocationServiceName;
1420
+ private isEncryptionNetworkOperation;
1421
+ private operationFromInvokeAnyEntry;
1348
1422
  private pathContains;
1349
1423
  /**
1350
1424
  * Issue a delegation via the legacy wallet-signed SIWE path for a single
@@ -1,4 +1,4 @@
1
- import { ISessionStorage, PersistedSessionData, AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, IUserAuthorization, ISigner, ISpaceCreationHandler, IWasmBindings, SiweConfig, Manifest, ComposedManifestRequest, ClientSession, TinyCloudSession, Extension, SignInOptions, Delegation, DelegatedResource, IKVService, ISQLService, IDuckDbService, IHooksService, INotificationHandler, IENSResolver, IDataVaultService, ISecretsService, ICapabilityKeyRegistry, PermissionEntry, DelegationManager, ISpaceService, ISpace, ISharingService, CreateDelegationParams, DelegationResult, ResolvedDelegate, KeyProvider, ISessionManager, JWK } from '@tinycloud/sdk-core';
1
+ import { ISessionStorage, PersistedSessionData, AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, IUserAuthorization, ISigner, ISpaceCreationHandler, IWasmBindings, SiweConfig, Manifest, ComposedManifestRequest, ClientSession, TinyCloudSession, Extension, SignInOptions, Delegation, DelegatedResource, IKVService, ISQLService, IDuckDbService, IHooksService, INotificationHandler, IENSResolver, IDataVaultService, IEncryptionService, NetworkDescriptor, ISecretsService, ICapabilityKeyRegistry, PermissionEntry, DelegationManager, ISpaceService, ISpace, ISharingService, CreateDelegationParams, DelegationResult, ResolvedDelegate, KeyProvider, ISessionManager, JWK } from '@tinycloud/sdk-core';
2
2
  import { EventEmitter } from 'events';
3
3
  import { InvokeFunction } from '@tinycloud/sdk-services';
4
4
 
@@ -321,6 +321,19 @@ declare class NodeUserAuthorization implements IUserAuthorization {
321
321
  * Includes spaceId, delegationHeader, and delegationCid.
322
322
  */
323
323
  get tinyCloudSession(): TinyCloudSession | undefined;
324
+ /**
325
+ * Rehydrate the auth-layer session from previously-persisted delegation
326
+ * data. Used by {@link TinyCloudNode.restoreSession} so that downstream
327
+ * surfaces that read from `tinyCloudSession` (notably
328
+ * `grantRuntimePermissions`, which extracts the SIWE expiry from it) work
329
+ * without re-running the full sign-in flow.
330
+ *
331
+ * Caller must supply the same fields that `signIn` would have written —
332
+ * `siwe` is the load-bearing one because `extractSiweExpiration` returns
333
+ * undefined for missing SIWEs and the SDK then treats the session as
334
+ * expired-at-epoch-zero.
335
+ */
336
+ setRestoredTinyCloudSession(session: TinyCloudSession): void;
324
337
  private resolveTinyCloudHostsForSignIn;
325
338
  private requireTinyCloudHosts;
326
339
  private get primaryTinyCloudHost();
@@ -353,6 +366,7 @@ declare class NodeUserAuthorization implements IUserAuthorization {
353
366
  */
354
367
  private getCapabilityRequest;
355
368
  private resolveSpaceName;
369
+ private defaultEncryptionNetworkId;
356
370
  private resolveSignInCapabilities;
357
371
  /**
358
372
  * Build SIWE overrides from the top-level nonce and siweConfig.
@@ -777,6 +791,7 @@ declare class TinyCloudNode {
777
791
  private _duckdb?;
778
792
  private _hooks?;
779
793
  private _vault?;
794
+ private _encryption?;
780
795
  private _baseSecrets?;
781
796
  private _secrets?;
782
797
  /** Cached public KV with proper delegation (set by ensurePublicSpace) */
@@ -793,6 +808,13 @@ declare class TinyCloudNode {
793
808
  private _delegationManager?;
794
809
  private _spaceService?;
795
810
  private runtimePermissionGrants;
811
+ /**
812
+ * TinyCloudSession captured by {@link restoreSession} when there's no
813
+ * auth-layer signer available (session-only mode used by OpenKey-backed
814
+ * CLI restores, public-space replays, …). Read by
815
+ * {@link currentTinyCloudSession} as a fallback for `auth.tinyCloudSession`.
816
+ */
817
+ private _restoredTcSession?;
796
818
  private get nodeFeatures();
797
819
  /** SIWE domain — uses config override or defaults to app.tinycloud.xyz */
798
820
  private get siweDomain();
@@ -909,7 +931,28 @@ declare class TinyCloudNode {
909
931
  verificationMethod: string;
910
932
  address?: string;
911
933
  chainId?: number;
934
+ /**
935
+ * The SIWE message that authorized this session. Required for
936
+ * downstream operations that need the session's expiry (e.g.
937
+ * {@link grantRuntimePermissions}). When omitted the SDK can still
938
+ * invoke services with the existing delegation, but anything that
939
+ * reads `auth.tinyCloudSession.siwe` will treat the session as
940
+ * expired-at-epoch-zero.
941
+ */
942
+ siwe?: string;
943
+ /**
944
+ * The wallet/OpenKey signature over `siwe`. Optional because the
945
+ * runtime doesn't re-verify it — it's persisted alongside the SIWE
946
+ * for callers that need to round-trip the full session shape.
947
+ */
948
+ signature?: string;
912
949
  }): Promise<void>;
950
+ /**
951
+ * Resolve the currently-active TinyCloudSession, preferring the auth
952
+ * layer's value (wallet mode) and falling back to the node-level
953
+ * rehydration set by {@link restoreSession} (session-only mode).
954
+ */
955
+ private currentTinyCloudSession;
913
956
  /**
914
957
  * Connect a wallet to upgrade from session-only mode to wallet mode.
915
958
  *
@@ -962,6 +1005,13 @@ declare class TinyCloudNode {
962
1005
  */
963
1006
  private initializeServices;
964
1007
  private createSpaceScopedKVService;
1008
+ getDefaultEncryptionNetworkId(name?: string): string;
1009
+ private requireServiceSession;
1010
+ private createEncryptionCrypto;
1011
+ private fetchNodeId;
1012
+ private signRawNetworkAuthorization;
1013
+ private createEncryptionService;
1014
+ private getEncryptionService;
965
1015
  private createVaultService;
966
1016
  /**
967
1017
  * Initialize the v2 delegation system services.
@@ -1011,6 +1061,21 @@ declare class TinyCloudNode {
1011
1061
  * SQL database operations on this user's space.
1012
1062
  */
1013
1063
  get sql(): ISQLService;
1064
+ /**
1065
+ * Get an SQL service scoped to a specific space.
1066
+ *
1067
+ * Mirrors {@link SpaceService}'s per-space KV factory: clones the active
1068
+ * service context and overrides its session's spaceId so that subsequent
1069
+ * `sql/<dbName>/<action>` invocations route to that space. Useful when
1070
+ * the caller already holds a delegation covering the target space (e.g.
1071
+ * via {@link grantRuntimePermissions} or {@link useRuntimeDelegation})
1072
+ * but the SDK's per-space SQL surface isn't otherwise exposed.
1073
+ *
1074
+ * Does NOT auto-create the space.
1075
+ *
1076
+ * @param spaceId - Full space URI (`tinycloud:pkh:eip155:<chain>:<addr>:<name>`).
1077
+ */
1078
+ sqlForSpace(spaceId: string): ISQLService;
1014
1079
  /**
1015
1080
  * DuckDB database operations on this user's space.
1016
1081
  */
@@ -1020,6 +1085,13 @@ declare class TinyCloudNode {
1020
1085
  * Call `vault.unlock(signer)` after signIn() to derive encryption keys.
1021
1086
  */
1022
1087
  get vault(): IDataVaultService;
1088
+ /**
1089
+ * Network-scoped encryption/decrypt service.
1090
+ */
1091
+ get encryption(): IEncryptionService;
1092
+ getEncryptionNetwork(nameOrNetworkId?: string): Promise<NetworkDescriptor | null>;
1093
+ createEncryptionNetwork(name?: string): Promise<NetworkDescriptor>;
1094
+ ensureEncryptionNetwork(name?: string): Promise<NetworkDescriptor>;
1023
1095
  /**
1024
1096
  * App-facing secrets API backed by the `secrets` space vault.
1025
1097
  */
@@ -1315,11 +1387,8 @@ declare class TinyCloudNode {
1315
1387
  * the current session; we build one multi-resource abilities map
1316
1388
  * and emit one signed UCAN covering them all.
1317
1389
  *
1318
- * All entries must share the same target space (the UCAN is
1319
- * scoped to a single space). If they don't, this throws mixing
1320
- * spaces in a single delegation is not supported by the underlying
1321
- * Rust create_delegation call and the resulting UCAN would be
1322
- * under-specified.
1390
+ * Non-encryption entries must share the same target space. Encryption
1391
+ * entries are raw network URNs and do not participate in space grouping.
1323
1392
  *
1324
1393
  * @internal
1325
1394
  */
@@ -1329,12 +1398,15 @@ declare class TinyCloudNode {
1329
1398
  private expandPermissionEntries;
1330
1399
  private shortServiceName;
1331
1400
  private permissionsToAbilities;
1401
+ private isEncryptionPermissionEntry;
1402
+ private permissionsToRawAbilities;
1332
1403
  private permissionOperations;
1333
1404
  private sessionCoversPermissionEntries;
1334
1405
  private permissionEntriesToOperations;
1335
1406
  private findRuntimeGrantsForPermissionEntries;
1336
1407
  private runtimeDelegationFromSession;
1337
1408
  private runtimeGrantFromDelegation;
1409
+ private installRuntimeGrantFromServiceSession;
1338
1410
  private delegatedResourcesForEntries;
1339
1411
  private operationsFromDelegation;
1340
1412
  private flatDelegationResources;
@@ -1345,6 +1417,8 @@ declare class TinyCloudNode {
1345
1417
  private operationCovers;
1346
1418
  private actionContains;
1347
1419
  private invocationServiceName;
1420
+ private isEncryptionNetworkOperation;
1421
+ private operationFromInvokeAnyEntry;
1348
1422
  private pathContains;
1349
1423
  /**
1350
1424
  * Issue a delegation via the legacy wallet-signed SIWE path for a single