@tinycloud/node-sdk 2.2.0-beta.11 → 2.2.0-beta.13

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.
@@ -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();
@@ -793,6 +806,13 @@ declare class TinyCloudNode {
793
806
  private _delegationManager?;
794
807
  private _spaceService?;
795
808
  private runtimePermissionGrants;
809
+ /**
810
+ * TinyCloudSession captured by {@link restoreSession} when there's no
811
+ * auth-layer signer available (session-only mode used by OpenKey-backed
812
+ * CLI restores, public-space replays, …). Read by
813
+ * {@link currentTinyCloudSession} as a fallback for `auth.tinyCloudSession`.
814
+ */
815
+ private _restoredTcSession?;
796
816
  private get nodeFeatures();
797
817
  /** SIWE domain — uses config override or defaults to app.tinycloud.xyz */
798
818
  private get siweDomain();
@@ -909,7 +929,28 @@ declare class TinyCloudNode {
909
929
  verificationMethod: string;
910
930
  address?: string;
911
931
  chainId?: number;
932
+ /**
933
+ * The SIWE message that authorized this session. Required for
934
+ * downstream operations that need the session's expiry (e.g.
935
+ * {@link grantRuntimePermissions}). When omitted the SDK can still
936
+ * invoke services with the existing delegation, but anything that
937
+ * reads `auth.tinyCloudSession.siwe` will treat the session as
938
+ * expired-at-epoch-zero.
939
+ */
940
+ siwe?: string;
941
+ /**
942
+ * The wallet/OpenKey signature over `siwe`. Optional because the
943
+ * runtime doesn't re-verify it — it's persisted alongside the SIWE
944
+ * for callers that need to round-trip the full session shape.
945
+ */
946
+ signature?: string;
912
947
  }): Promise<void>;
948
+ /**
949
+ * Resolve the currently-active TinyCloudSession, preferring the auth
950
+ * layer's value (wallet mode) and falling back to the node-level
951
+ * rehydration set by {@link restoreSession} (session-only mode).
952
+ */
953
+ private currentTinyCloudSession;
913
954
  /**
914
955
  * Connect a wallet to upgrade from session-only mode to wallet mode.
915
956
  *
@@ -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();
@@ -793,6 +806,13 @@ declare class TinyCloudNode {
793
806
  private _delegationManager?;
794
807
  private _spaceService?;
795
808
  private runtimePermissionGrants;
809
+ /**
810
+ * TinyCloudSession captured by {@link restoreSession} when there's no
811
+ * auth-layer signer available (session-only mode used by OpenKey-backed
812
+ * CLI restores, public-space replays, …). Read by
813
+ * {@link currentTinyCloudSession} as a fallback for `auth.tinyCloudSession`.
814
+ */
815
+ private _restoredTcSession?;
796
816
  private get nodeFeatures();
797
817
  /** SIWE domain — uses config override or defaults to app.tinycloud.xyz */
798
818
  private get siweDomain();
@@ -909,7 +929,28 @@ declare class TinyCloudNode {
909
929
  verificationMethod: string;
910
930
  address?: string;
911
931
  chainId?: number;
932
+ /**
933
+ * The SIWE message that authorized this session. Required for
934
+ * downstream operations that need the session's expiry (e.g.
935
+ * {@link grantRuntimePermissions}). When omitted the SDK can still
936
+ * invoke services with the existing delegation, but anything that
937
+ * reads `auth.tinyCloudSession.siwe` will treat the session as
938
+ * expired-at-epoch-zero.
939
+ */
940
+ siwe?: string;
941
+ /**
942
+ * The wallet/OpenKey signature over `siwe`. Optional because the
943
+ * runtime doesn't re-verify it — it's persisted alongside the SIWE
944
+ * for callers that need to round-trip the full session shape.
945
+ */
946
+ signature?: string;
912
947
  }): Promise<void>;
948
+ /**
949
+ * Resolve the currently-active TinyCloudSession, preferring the auth
950
+ * layer's value (wallet mode) and falling back to the node-level
951
+ * rehydration set by {@link restoreSession} (session-only mode).
952
+ */
953
+ private currentTinyCloudSession;
913
954
  /**
914
955
  * Connect a wallet to upgrade from session-only mode to wallet mode.
915
956
  *
package/dist/core.cjs CHANGED
@@ -27,6 +27,7 @@ __export(core_exports, {
27
27
  CapabilityKeyRegistryErrorCodes: () => import_sdk_core15.CapabilityKeyRegistryErrorCodes,
28
28
  DEFAULT_MANIFEST_SPACE: () => import_sdk_core9.DEFAULT_MANIFEST_SPACE,
29
29
  DEFAULT_MANIFEST_VERSION: () => import_sdk_core9.DEFAULT_MANIFEST_VERSION,
30
+ DEFAULT_SIGNED_READ_URL_EXPIRY_MS: () => import_sdk_core10.DEFAULT_SIGNED_READ_URL_EXPIRY_MS,
30
31
  DataVaultService: () => import_sdk_core13.DataVaultService,
31
32
  DatabaseHandle: () => import_sdk_core11.DatabaseHandle,
32
33
  DelegatedAccess: () => DelegatedAccess,
@@ -396,6 +397,23 @@ var NodeUserAuthorization = class {
396
397
  get tinyCloudSession() {
397
398
  return this._tinyCloudSession;
398
399
  }
400
+ /**
401
+ * Rehydrate the auth-layer session from previously-persisted delegation
402
+ * data. Used by {@link TinyCloudNode.restoreSession} so that downstream
403
+ * surfaces that read from `tinyCloudSession` (notably
404
+ * `grantRuntimePermissions`, which extracts the SIWE expiry from it) work
405
+ * without re-running the full sign-in flow.
406
+ *
407
+ * Caller must supply the same fields that `signIn` would have written —
408
+ * `siwe` is the load-bearing one because `extractSiweExpiration` returns
409
+ * undefined for missing SIWEs and the SDK then treats the session as
410
+ * expired-at-epoch-zero.
411
+ */
412
+ setRestoredTinyCloudSession(session) {
413
+ this._tinyCloudSession = session;
414
+ this._address = session.address;
415
+ this._chainId = session.chainId;
416
+ }
399
417
  async resolveTinyCloudHostsForSignIn(address, chainId) {
400
418
  if (this.tinycloudHosts && this.tinycloudHosts.length > 0) {
401
419
  return;
@@ -1813,6 +1831,33 @@ var _TinyCloudNode = class _TinyCloudNode {
1813
1831
  this._vault.initialize(this._serviceContext);
1814
1832
  this._serviceContext.registerService("vault", this._vault);
1815
1833
  this.initializeV2Services(serviceSession);
1834
+ if (sessionData.siwe && sessionData.address && sessionData.chainId) {
1835
+ const tcSession = {
1836
+ address: sessionData.address,
1837
+ chainId: sessionData.chainId,
1838
+ sessionKey: JSON.stringify(sessionData.jwk),
1839
+ spaceId: sessionData.spaceId,
1840
+ delegationCid: sessionData.delegationCid,
1841
+ delegationHeader: sessionData.delegationHeader,
1842
+ verificationMethod: sessionData.verificationMethod,
1843
+ jwk: sessionData.jwk,
1844
+ siwe: sessionData.siwe,
1845
+ signature: sessionData.signature ?? ""
1846
+ };
1847
+ if (this.auth) {
1848
+ this.auth.setRestoredTinyCloudSession(tcSession);
1849
+ } else {
1850
+ this._restoredTcSession = tcSession;
1851
+ }
1852
+ }
1853
+ }
1854
+ /**
1855
+ * Resolve the currently-active TinyCloudSession, preferring the auth
1856
+ * layer's value (wallet mode) and falling back to the node-level
1857
+ * rehydration set by {@link restoreSession} (session-only mode).
1858
+ */
1859
+ currentTinyCloudSession() {
1860
+ return this.auth?.tinyCloudSession ?? this._restoredTcSession;
1816
1861
  }
1817
1862
  /**
1818
1863
  * Connect a wallet to upgrade from session-only mode to wallet mode.
@@ -2487,7 +2532,7 @@ var _TinyCloudNode = class _TinyCloudNode {
2487
2532
  * every requested permission.
2488
2533
  */
2489
2534
  hasRuntimePermissions(permissions) {
2490
- const session = this.auth?.tinyCloudSession;
2535
+ const session = this.currentTinyCloudSession();
2491
2536
  if (!session || !Array.isArray(permissions) || permissions.length === 0) {
2492
2537
  return false;
2493
2538
  }
@@ -2507,7 +2552,7 @@ var _TinyCloudNode = class _TinyCloudNode {
2507
2552
  if (permissions === void 0) {
2508
2553
  return this.runtimePermissionGrants.map((grant) => grant.delegation);
2509
2554
  }
2510
- const session = this.auth?.tinyCloudSession;
2555
+ const session = this.currentTinyCloudSession();
2511
2556
  if (!session || !Array.isArray(permissions) || permissions.length === 0) {
2512
2557
  return [];
2513
2558
  }
@@ -2521,7 +2566,7 @@ var _TinyCloudNode = class _TinyCloudNode {
2521
2566
  * matching service calls and downstream `delegateTo()` calls can use it.
2522
2567
  */
2523
2568
  async useRuntimeDelegation(delegation) {
2524
- const session = this.auth?.tinyCloudSession;
2569
+ const session = this.currentTinyCloudSession();
2525
2570
  if (!session) {
2526
2571
  throw new import_sdk_core6.SessionExpiredError(/* @__PURE__ */ new Date(0));
2527
2572
  }
@@ -2560,7 +2605,7 @@ var _TinyCloudNode = class _TinyCloudNode {
2560
2605
  if (!Array.isArray(permissions) || permissions.length === 0) {
2561
2606
  throw new Error("grantRuntimePermissions requires a non-empty permissions array");
2562
2607
  }
2563
- const session = this.auth?.tinyCloudSession;
2608
+ const session = this.currentTinyCloudSession();
2564
2609
  if (!session) {
2565
2610
  throw new import_sdk_core6.SessionExpiredError(/* @__PURE__ */ new Date(0));
2566
2611
  }
@@ -3847,6 +3892,7 @@ var import_sdk_core18 = require("@tinycloud/sdk-core");
3847
3892
  CapabilityKeyRegistryErrorCodes,
3848
3893
  DEFAULT_MANIFEST_SPACE,
3849
3894
  DEFAULT_MANIFEST_VERSION,
3895
+ DEFAULT_SIGNED_READ_URL_EXPIRY_MS,
3850
3896
  DataVaultService,
3851
3897
  DatabaseHandle,
3852
3898
  DelegatedAccess,