@tinycloud/node-sdk 2.4.0-beta.9 → 2.4.1-beta.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.
package/dist/core.cjs CHANGED
@@ -30,95 +30,103 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/core.ts
31
31
  var core_exports = {};
32
32
  __export(core_exports, {
33
- ACCOUNT_REGISTRY_PATH: () => import_sdk_core10.ACCOUNT_REGISTRY_PATH,
34
- ACCOUNT_REGISTRY_SPACE: () => import_sdk_core10.ACCOUNT_REGISTRY_SPACE,
35
- AccountService: () => import_sdk_core3.AccountService,
36
- AutoApproveSpaceCreationHandler: () => import_sdk_core9.AutoApproveSpaceCreationHandler,
37
- CapabilityKeyRegistry: () => import_sdk_core16.CapabilityKeyRegistry,
38
- CapabilityKeyRegistryErrorCodes: () => import_sdk_core16.CapabilityKeyRegistryErrorCodes,
39
- DEFAULT_MANIFEST_SPACE: () => import_sdk_core10.DEFAULT_MANIFEST_SPACE,
40
- DEFAULT_MANIFEST_VERSION: () => import_sdk_core10.DEFAULT_MANIFEST_VERSION,
41
- DEFAULT_SIGNED_READ_URL_EXPIRY_MS: () => import_sdk_core11.DEFAULT_SIGNED_READ_URL_EXPIRY_MS,
42
- DataVaultService: () => import_sdk_core14.DataVaultService,
43
- DatabaseHandle: () => import_sdk_core12.DatabaseHandle,
33
+ ACCOUNT_REGISTRY_PATH: () => import_sdk_core11.ACCOUNT_REGISTRY_PATH,
34
+ ACCOUNT_REGISTRY_SPACE: () => import_sdk_core11.ACCOUNT_REGISTRY_SPACE,
35
+ AccountService: () => import_sdk_core4.AccountService,
36
+ AutoApproveSpaceCreationHandler: () => import_sdk_core10.AutoApproveSpaceCreationHandler,
37
+ CapabilityKeyRegistry: () => import_sdk_core17.CapabilityKeyRegistry,
38
+ CapabilityKeyRegistryErrorCodes: () => import_sdk_core17.CapabilityKeyRegistryErrorCodes,
39
+ DEFAULT_MANIFEST_SPACE: () => import_sdk_core11.DEFAULT_MANIFEST_SPACE,
40
+ DEFAULT_MANIFEST_VERSION: () => import_sdk_core11.DEFAULT_MANIFEST_VERSION,
41
+ DEFAULT_SIGNED_READ_URL_EXPIRY_MS: () => import_sdk_core12.DEFAULT_SIGNED_READ_URL_EXPIRY_MS,
42
+ DataVaultService: () => import_sdk_core15.DataVaultService,
43
+ DatabaseHandle: () => import_sdk_core13.DatabaseHandle,
44
44
  DelegatedAccess: () => DelegatedAccess,
45
- DelegationErrorCodes: () => import_sdk_core15.DelegationErrorCodes,
46
- DelegationManager: () => import_sdk_core15.DelegationManager,
47
- DuckDbAction: () => import_sdk_core13.DuckDbAction,
48
- DuckDbDatabaseHandle: () => import_sdk_core13.DuckDbDatabaseHandle,
49
- DuckDbService: () => import_sdk_core13.DuckDbService,
45
+ DelegationErrorCodes: () => import_sdk_core16.DelegationErrorCodes,
46
+ DelegationManager: () => import_sdk_core16.DelegationManager,
47
+ DuckDbAction: () => import_sdk_core14.DuckDbAction,
48
+ DuckDbDatabaseHandle: () => import_sdk_core14.DuckDbDatabaseHandle,
49
+ DuckDbService: () => import_sdk_core14.DuckDbService,
50
50
  FileSessionStorage: () => FileSessionStorage,
51
- IdentityParseError: () => import_sdk_core9.IdentityParseError,
52
- KVService: () => import_sdk_core11.KVService,
53
- ManifestValidationError: () => import_sdk_core10.ManifestValidationError,
51
+ IdentityParseError: () => import_sdk_core10.IdentityParseError,
52
+ KVService: () => import_sdk_core12.KVService,
53
+ ManifestValidationError: () => import_sdk_core11.ManifestValidationError,
54
54
  MemorySessionStorage: () => MemorySessionStorage,
55
55
  NodeUserAuthorization: () => NodeUserAuthorization,
56
- PermissionNotInManifestError: () => import_sdk_core10.PermissionNotInManifestError,
57
- PrefixedKVService: () => import_sdk_core11.PrefixedKVService,
58
- ProtocolMismatchError: () => import_sdk_core18.ProtocolMismatchError,
59
- SECRET_NAME_RE: () => import_sdk_core14.SECRET_NAME_RE,
60
- SQLAction: () => import_sdk_core12.SQLAction,
61
- SQLService: () => import_sdk_core12.SQLService,
62
- SecretsService: () => import_sdk_core14.SecretsService,
63
- ServiceContext: () => import_sdk_core19.ServiceContext,
64
- SessionExpiredError: () => import_sdk_core10.SessionExpiredError,
65
- SharingService: () => import_sdk_core15.SharingService,
66
- SilentNotificationHandler: () => import_sdk_core9.SilentNotificationHandler,
67
- Space: () => import_sdk_core17.Space,
68
- SpaceErrorCodes: () => import_sdk_core17.SpaceErrorCodes,
69
- SpaceService: () => import_sdk_core17.SpaceService,
70
- TinyCloud: () => import_sdk_core8.TinyCloud,
56
+ PermissionNotInManifestError: () => import_sdk_core11.PermissionNotInManifestError,
57
+ PrefixedKVService: () => import_sdk_core12.PrefixedKVService,
58
+ ProtocolMismatchError: () => import_sdk_core19.ProtocolMismatchError,
59
+ SECRET_NAME_RE: () => import_sdk_core15.SECRET_NAME_RE,
60
+ SQLAction: () => import_sdk_core13.SQLAction,
61
+ SQLService: () => import_sdk_core13.SQLService,
62
+ SecretsService: () => import_sdk_core15.SecretsService,
63
+ ServiceContext: () => import_sdk_core20.ServiceContext,
64
+ SessionExpiredError: () => import_sdk_core11.SessionExpiredError,
65
+ SharingService: () => import_sdk_core16.SharingService,
66
+ SilentNotificationHandler: () => import_sdk_core10.SilentNotificationHandler,
67
+ Space: () => import_sdk_core18.Space,
68
+ SpaceErrorCodes: () => import_sdk_core18.SpaceErrorCodes,
69
+ SpaceService: () => import_sdk_core18.SpaceService,
70
+ TinyCloud: () => import_sdk_core9.TinyCloud,
71
+ TinyCloudDebugLogger: () => import_sdk_core10.TinyCloudDebugLogger,
71
72
  TinyCloudNode: () => TinyCloudNode,
72
- UnsupportedFeatureError: () => import_sdk_core18.UnsupportedFeatureError,
73
- VAULT_PERMISSION_SERVICE: () => import_sdk_core10.VAULT_PERMISSION_SERVICE,
74
- VaultHeaders: () => import_sdk_core14.VaultHeaders,
75
- VaultPublicSpaceKVActions: () => import_sdk_core14.VaultPublicSpaceKVActions,
76
- VersionCheckError: () => import_sdk_core18.VersionCheckError,
73
+ UnsupportedFeatureError: () => import_sdk_core19.UnsupportedFeatureError,
74
+ VAULT_PERMISSION_SERVICE: () => import_sdk_core11.VAULT_PERMISSION_SERVICE,
75
+ VaultHeaders: () => import_sdk_core15.VaultHeaders,
76
+ VaultPublicSpaceKVActions: () => import_sdk_core15.VaultPublicSpaceKVActions,
77
+ VersionCheckError: () => import_sdk_core19.VersionCheckError,
77
78
  WasmKeyProvider: () => WasmKeyProvider,
78
- addressStorageKey: () => import_sdk_core9.addressStorageKey,
79
- buildSpaceUri: () => import_sdk_core17.buildSpaceUri,
80
- canonicalizeAddress: () => import_sdk_core9.canonicalizeAddress,
81
- canonicalizeDid: () => import_sdk_core9.canonicalizeDid,
82
- canonicalizeDidUrl: () => import_sdk_core9.canonicalizeDidUrl,
83
- canonicalizeNetworkId: () => import_sdk_core9.canonicalizeNetworkId,
84
- canonicalizeSecretScope: () => import_sdk_core14.canonicalizeSecretScope,
85
- checkNodeInfo: () => import_sdk_core18.checkNodeInfo,
86
- composeManifestRequest: () => import_sdk_core10.composeManifestRequest,
87
- createCapabilityKeyRegistry: () => import_sdk_core16.createCapabilityKeyRegistry,
88
- createSharingService: () => import_sdk_core15.createSharingService,
89
- createSpaceService: () => import_sdk_core17.createSpaceService,
90
- createVaultCrypto: () => import_sdk_core14.createVaultCrypto,
79
+ addressStorageKey: () => import_sdk_core10.addressStorageKey,
80
+ buildSpaceUri: () => import_sdk_core18.buildSpaceUri,
81
+ canonicalizeAddress: () => import_sdk_core10.canonicalizeAddress,
82
+ canonicalizeDid: () => import_sdk_core10.canonicalizeDid,
83
+ canonicalizeDidUrl: () => import_sdk_core10.canonicalizeDidUrl,
84
+ canonicalizeNetworkId: () => import_sdk_core10.canonicalizeNetworkId,
85
+ canonicalizeSecretScope: () => import_sdk_core15.canonicalizeSecretScope,
86
+ checkNodeInfo: () => import_sdk_core19.checkNodeInfo,
87
+ clearTinyCloudDebugLogs: () => import_sdk_core10.clearTinyCloudDebugLogs,
88
+ composeManifestRequest: () => import_sdk_core11.composeManifestRequest,
89
+ createCapabilityKeyRegistry: () => import_sdk_core17.createCapabilityKeyRegistry,
90
+ createOpenKeyCallbackSigningStrategy: () => import_sdk_core2.createOpenKeyCallbackSigningStrategy,
91
+ createSharingService: () => import_sdk_core16.createSharingService,
92
+ createSpaceService: () => import_sdk_core18.createSpaceService,
93
+ createVaultCrypto: () => import_sdk_core15.createVaultCrypto,
91
94
  createWasmKeyProvider: () => createWasmKeyProvider,
92
95
  defaultSignStrategy: () => defaultSignStrategy,
93
- defaultSpaceCreationHandler: () => import_sdk_core9.defaultSpaceCreationHandler,
96
+ defaultSpaceCreationHandler: () => import_sdk_core10.defaultSpaceCreationHandler,
94
97
  deserializeDelegation: () => deserializeDelegation,
95
- didCacheKey: () => import_sdk_core9.didCacheKey,
96
- didEquals: () => import_sdk_core9.didEquals,
97
- expandActionShortNames: () => import_sdk_core10.expandActionShortNames,
98
- expandPermissionEntries: () => import_sdk_core10.expandPermissionEntries,
99
- expandPermissionEntry: () => import_sdk_core10.expandPermissionEntry,
100
- isCapabilitySubset: () => import_sdk_core10.isCapabilitySubset,
101
- isEvmAddress: () => import_sdk_core9.isEvmAddress,
102
- loadManifest: () => import_sdk_core10.loadManifest,
103
- makePkhSpaceId: () => import_sdk_core9.makePkhSpaceId,
104
- makePublicSpaceId: () => import_sdk_core17.makePublicSpaceId,
105
- parseCanonicalNetworkId: () => import_sdk_core9.parseCanonicalNetworkId,
106
- parseExpiry: () => import_sdk_core10.parseExpiry,
107
- parsePkhDid: () => import_sdk_core9.parsePkhDid,
108
- parseSpaceUri: () => import_sdk_core17.parseSpaceUri,
109
- pkhDid: () => import_sdk_core9.pkhDid,
110
- principalDid: () => import_sdk_core9.principalDid,
111
- principalDidEquals: () => import_sdk_core9.principalDidEquals,
112
- resolveManifest: () => import_sdk_core10.resolveManifest,
113
- resolveSecretListPrefix: () => import_sdk_core14.resolveSecretListPrefix,
114
- resolveSecretPath: () => import_sdk_core14.resolveSecretPath,
115
- resourceCapabilitiesToSpaceAbilitiesMap: () => import_sdk_core10.resourceCapabilitiesToSpaceAbilitiesMap,
98
+ didCacheKey: () => import_sdk_core10.didCacheKey,
99
+ didEquals: () => import_sdk_core10.didEquals,
100
+ disableTinyCloudDebug: () => import_sdk_core10.disableTinyCloudDebug,
101
+ enableTinyCloudDebug: () => import_sdk_core10.enableTinyCloudDebug,
102
+ expandActionShortNames: () => import_sdk_core11.expandActionShortNames,
103
+ expandPermissionEntries: () => import_sdk_core11.expandPermissionEntries,
104
+ expandPermissionEntry: () => import_sdk_core11.expandPermissionEntry,
105
+ getTinyCloudDebugLogs: () => import_sdk_core10.getTinyCloudDebugLogs,
106
+ installTinyCloudDebugGlobals: () => import_sdk_core10.installTinyCloudDebugGlobals,
107
+ isCapabilitySubset: () => import_sdk_core11.isCapabilitySubset,
108
+ isEvmAddress: () => import_sdk_core10.isEvmAddress,
109
+ loadManifest: () => import_sdk_core11.loadManifest,
110
+ makePkhSpaceId: () => import_sdk_core10.makePkhSpaceId,
111
+ makePublicSpaceId: () => import_sdk_core18.makePublicSpaceId,
112
+ parseCanonicalNetworkId: () => import_sdk_core10.parseCanonicalNetworkId,
113
+ parseExpiry: () => import_sdk_core11.parseExpiry,
114
+ parsePkhDid: () => import_sdk_core10.parsePkhDid,
115
+ parseSpaceUri: () => import_sdk_core18.parseSpaceUri,
116
+ pkhDid: () => import_sdk_core10.pkhDid,
117
+ principalDid: () => import_sdk_core10.principalDid,
118
+ principalDidEquals: () => import_sdk_core10.principalDidEquals,
119
+ resolveManifest: () => import_sdk_core11.resolveManifest,
120
+ resolveSecretListPrefix: () => import_sdk_core15.resolveSecretListPrefix,
121
+ resolveSecretPath: () => import_sdk_core15.resolveSecretPath,
122
+ resourceCapabilitiesToSpaceAbilitiesMap: () => import_sdk_core11.resourceCapabilitiesToSpaceAbilitiesMap,
116
123
  serializeDelegation: () => serializeDelegation,
117
- validateManifest: () => import_sdk_core10.validateManifest
124
+ tinyCloudDebugLogger: () => import_sdk_core10.tinyCloudDebugLogger,
125
+ validateManifest: () => import_sdk_core11.validateManifest
118
126
  });
119
127
  module.exports = __toCommonJS(core_exports);
120
- var import_sdk_core8 = require("@tinycloud/sdk-core");
121
128
  var import_sdk_core9 = require("@tinycloud/sdk-core");
129
+ var import_sdk_core10 = require("@tinycloud/sdk-core");
122
130
 
123
131
  // src/storage/MemorySessionStorage.ts
124
132
  var MemorySessionStorage = class {
@@ -312,9 +320,10 @@ var FileSessionStorage = class {
312
320
  };
313
321
 
314
322
  // src/authorization/NodeUserAuthorization.ts
315
- var import_sdk_core2 = require("@tinycloud/sdk-core");
323
+ var import_sdk_core3 = require("@tinycloud/sdk-core");
316
324
 
317
325
  // src/authorization/strategies.ts
326
+ var import_sdk_core2 = require("@tinycloud/sdk-core");
318
327
  var defaultSignStrategy = { type: "auto-sign" };
319
328
 
320
329
  // src/authorization/NodeUserAuthorization.ts
@@ -322,7 +331,7 @@ var DECRYPT_ACTION = "tinycloud.encryption/decrypt";
322
331
  var NETWORK_CREATE_ACTION = "tinycloud.encryption/network.create";
323
332
  function didPrincipalMatches(actual, expected) {
324
333
  try {
325
- return (0, import_sdk_core2.principalDidEquals)(actual, expected);
334
+ return (0, import_sdk_core3.principalDidEquals)(actual, expected);
326
335
  } catch {
327
336
  return actual === expected;
328
337
  }
@@ -341,6 +350,7 @@ var NodeUserAuthorization = class {
341
350
  constructor(config) {
342
351
  this.extensions = [];
343
352
  this._nodeFeatures = [];
353
+ this._lastActivationSkippedSpaceIds = [];
344
354
  this.wasm = config.wasmBindings;
345
355
  this.signer = config.signer;
346
356
  this.signStrategy = config.signStrategy ?? defaultSignStrategy;
@@ -363,7 +373,7 @@ var NodeUserAuthorization = class {
363
373
  "": [
364
374
  "tinycloud.sql/read",
365
375
  "tinycloud.sql/write",
366
- "tinycloud.sql/ddl",
376
+ "tinycloud.sql/schema",
367
377
  "tinycloud.sql/admin",
368
378
  "tinycloud.sql/export"
369
379
  ]
@@ -391,7 +401,7 @@ var NodeUserAuthorization = class {
391
401
  ]
392
402
  }
393
403
  };
394
- this.sessionExpirationMs = config.sessionExpirationMs ?? import_sdk_core2.EXPIRY.SESSION_MS;
404
+ this.sessionExpirationMs = config.sessionExpirationMs ?? import_sdk_core3.EXPIRY.SESSION_MS;
395
405
  this.autoCreateSpace = config.autoCreateSpace ?? false;
396
406
  this.spaceCreationHandler = config.spaceCreationHandler;
397
407
  this.tinycloudHosts = config.tinycloudHosts;
@@ -455,19 +465,55 @@ var NodeUserAuthorization = class {
455
465
  * `siwe` is the load-bearing one because `extractSiweExpiration` returns
456
466
  * undefined for missing SIWEs and the SDK then treats the session as
457
467
  * expired-at-epoch-zero.
468
+ *
469
+ * @param hosts - The TinyCloud hosts this session was created against,
470
+ * as persisted in {@link PersistedSessionData.tinycloudHosts}. When
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
476
  */
459
- setRestoredTinyCloudSession(session) {
460
- const address = (0, import_sdk_core2.canonicalizeAddress)(session.address);
477
+ setRestoredTinyCloudSession(session, hosts) {
478
+ const address = (0, import_sdk_core3.canonicalizeAddress)(session.address);
461
479
  this._tinyCloudSession = { ...session, address };
462
480
  this._address = address;
463
481
  this._chainId = session.chainId;
482
+ if ((!this.tinycloudHosts || this.tinycloudHosts.length === 0) && hosts && hosts.length > 0) {
483
+ this.tinycloudHosts = [...hosts];
484
+ }
485
+ }
486
+ /**
487
+ * Ensure `tinycloudHosts` are resolved before a host-needing call.
488
+ *
489
+ * Fresh sign-in resolves hosts up front; a restored session may not have
490
+ * (old persisted sessions predate {@link PersistedSessionData.tinycloudHosts}).
491
+ * This guard makes a restored session resolve the node exactly like a fresh
492
+ * sign-in — persisted hosts are preferred (already set by
493
+ * {@link setRestoredTinyCloudSession}), otherwise the registry/fallback
494
+ * resolution runs lazily here. Idempotent: {@link resolveTinyCloudHostsForSignIn}
495
+ * early-returns when hosts are already set.
496
+ *
497
+ * Throws if hosts are unset and the restored session has no address/chainId
498
+ * to resolve from — a real failure that must surface, not be masked.
499
+ */
500
+ async ensureTinyCloudHosts() {
501
+ if (this.tinycloudHosts && this.tinycloudHosts.length > 0) {
502
+ return;
503
+ }
504
+ if (this._address === void 0 || this._chainId === void 0) {
505
+ throw new Error(
506
+ "Cannot resolve TinyCloud hosts: no address/chainId available. Sign in or restore a session first."
507
+ );
508
+ }
509
+ await this.resolveTinyCloudHostsForSignIn(this._address, this._chainId);
464
510
  }
465
511
  async resolveTinyCloudHostsForSignIn(address, chainId) {
466
512
  if (this.tinycloudHosts && this.tinycloudHosts.length > 0) {
467
513
  return;
468
514
  }
469
- const subject = (0, import_sdk_core2.pkhDid)(address, chainId);
470
- const resolved = await (0, import_sdk_core2.resolveTinyCloudHosts)(subject, {
515
+ const subject = (0, import_sdk_core3.pkhDid)(address, chainId);
516
+ const resolved = await (0, import_sdk_core3.resolveTinyCloudHosts)(subject, {
471
517
  registryUrl: this.tinycloudRegistryUrl,
472
518
  fallbackHosts: this.tinycloudFallbackHosts
473
519
  });
@@ -485,6 +531,9 @@ var NodeUserAuthorization = class {
485
531
  get nodeFeatures() {
486
532
  return this._nodeFeatures;
487
533
  }
534
+ get lastActivationSkippedSpaceIds() {
535
+ return [...this._lastActivationSkippedSpaceIds];
536
+ }
488
537
  /**
489
538
  * Compute the `abilities` map the WASM `prepareSession` call should
490
539
  * see at sign-in time.
@@ -518,7 +567,7 @@ var NodeUserAuthorization = class {
518
567
  if (this._manifest === void 0) {
519
568
  return void 0;
520
569
  }
521
- this._capabilityRequest = (0, import_sdk_core2.composeManifestRequest)(
570
+ this._capabilityRequest = (0, import_sdk_core3.composeManifestRequest)(
522
571
  Array.isArray(this._manifest) ? this._manifest : [this._manifest],
523
572
  {
524
573
  includeAccountRegistryPermissions: this.includeAccountRegistryPermissions
@@ -530,17 +579,17 @@ var NodeUserAuthorization = class {
530
579
  if (space.startsWith("tinycloud:")) {
531
580
  return space;
532
581
  }
533
- return (0, import_sdk_core2.makePkhSpaceId)(address, chainId, space);
582
+ return (0, import_sdk_core3.makePkhSpaceId)(address, chainId, space);
534
583
  }
535
584
  defaultEncryptionNetworkId(address, chainId) {
536
- return `urn:tinycloud:encryption:${(0, import_sdk_core2.pkhDid)(address, chainId)}:default`;
585
+ return `urn:tinycloud:encryption:${(0, import_sdk_core3.pkhDid)(address, chainId)}:default`;
537
586
  }
538
587
  resolveSignInCapabilities(address, chainId) {
539
588
  const request = this.getCapabilityRequest();
540
589
  if (request === void 0) {
541
590
  const defaultNetworkId = this.defaultEncryptionNetworkId(address, chainId);
542
- const primarySpaceId2 = (0, import_sdk_core2.makePkhSpaceId)(address, chainId, this.spacePrefix);
543
- const secretsSpaceId = (0, import_sdk_core2.makePkhSpaceId)(address, chainId, "secrets");
591
+ const primarySpaceId2 = (0, import_sdk_core3.makePkhSpaceId)(address, chainId, this.spacePrefix);
592
+ const secretsSpaceId = (0, import_sdk_core3.makePkhSpaceId)(address, chainId, "secrets");
544
593
  return {
545
594
  abilities: this.defaultActions,
546
595
  spaceId: primarySpaceId2,
@@ -567,35 +616,35 @@ var NodeUserAuthorization = class {
567
616
  };
568
617
  }
569
618
  const rawAbilities = {};
570
- const currentDid = (0, import_sdk_core2.pkhDid)(address, chainId);
619
+ const currentDid = (0, import_sdk_core3.pkhDid)(address, chainId);
571
620
  const spaceResources = request.resources.filter((entry) => {
572
- if (entry.service !== import_sdk_core2.ENCRYPTION_PERMISSION_SERVICE) {
621
+ if (entry.service !== import_sdk_core3.ENCRYPTION_PERMISSION_SERVICE) {
573
622
  return true;
574
623
  }
575
624
  for (const action of entry.actions) {
576
625
  addRawAbility(rawAbilities, entry.path, action);
577
626
  }
578
627
  if (entry.actions.includes(DECRYPT_ACTION)) {
579
- const parsed = (0, import_sdk_core2.parseNetworkId)(entry.path);
628
+ const parsed = (0, import_sdk_core3.parseNetworkId)(entry.path);
580
629
  if (didPrincipalMatches(parsed.ownerDid, currentDid)) {
581
630
  addRawAbility(rawAbilities, entry.path, NETWORK_CREATE_ACTION);
582
631
  }
583
632
  }
584
633
  return false;
585
634
  });
586
- const primarySpaceName = spaceResources.find((entry) => entry.space !== "account")?.space ?? import_sdk_core2.DEFAULT_MANIFEST_SPACE;
635
+ const primarySpaceName = spaceResources.find((entry) => entry.space !== "account")?.space ?? import_sdk_core3.DEFAULT_MANIFEST_SPACE;
587
636
  const primarySpaceId = this.resolveSpaceName(
588
637
  primarySpaceName,
589
638
  address,
590
639
  chainId
591
640
  );
592
- const bySpace = (0, import_sdk_core2.resourceCapabilitiesToSpaceAbilitiesMap)(spaceResources);
641
+ const bySpace = (0, import_sdk_core3.resourceCapabilitiesToSpaceAbilitiesMap)(spaceResources);
593
642
  const spaceAbilities = {};
594
643
  for (const [space, abilities] of Object.entries(bySpace)) {
595
644
  spaceAbilities[this.resolveSpaceName(space, address, chainId)] = abilities;
596
645
  }
597
646
  return {
598
- abilities: spaceAbilities[primarySpaceId] ?? (0, import_sdk_core2.resourceCapabilitiesToAbilitiesMap)([]),
647
+ abilities: spaceAbilities[primarySpaceId] ?? (0, import_sdk_core3.resourceCapabilitiesToAbilitiesMap)([]),
599
648
  spaceId: primarySpaceId,
600
649
  spaceAbilities,
601
650
  rawAbilities: Object.keys(rawAbilities).length > 0 ? rawAbilities : void 0
@@ -657,9 +706,10 @@ var NodeUserAuthorization = class {
657
706
  if (!this._tinyCloudSession || !this._address || !this._chainId) {
658
707
  throw new Error("Must be signed in to host space");
659
708
  }
709
+ await this.ensureTinyCloudHosts();
660
710
  const host = this.primaryTinyCloudHost;
661
711
  const spaceId = targetSpaceId ?? this._tinyCloudSession.spaceId;
662
- const peerId = await (0, import_sdk_core2.fetchPeerId)(host, spaceId);
712
+ const peerId = await (0, import_sdk_core3.fetchPeerId)(host, spaceId);
663
713
  const siwe = this.wasm.generateHostSIWEMessage({
664
714
  address: this._address,
665
715
  chainId: this._chainId,
@@ -670,7 +720,7 @@ var NodeUserAuthorization = class {
670
720
  });
671
721
  const signature = await this.signMessage(siwe);
672
722
  const headers = this.wasm.siweToDelegationHeaders({ siwe, signature });
673
- const result = await (0, import_sdk_core2.submitHostDelegation)(host, headers);
723
+ const result = await (0, import_sdk_core3.submitHostDelegation)(host, headers);
674
724
  return result.success;
675
725
  }
676
726
  /**
@@ -699,13 +749,15 @@ var NodeUserAuthorization = class {
699
749
  if (!this._tinyCloudSession) {
700
750
  throw new Error("Must be signed in to ensure space exists");
701
751
  }
752
+ await this.ensureTinyCloudHosts();
702
753
  const host = this.primaryTinyCloudHost;
703
754
  const primarySpaceId = this._tinyCloudSession.spaceId;
704
- const result = await (0, import_sdk_core2.activateSessionWithHost)(
755
+ const result = await (0, import_sdk_core3.activateSessionWithHost)(
705
756
  host,
706
757
  this._tinyCloudSession.delegationHeader
707
758
  );
708
- const handler = this.spaceCreationHandler ?? (this.autoCreateSpace ? new import_sdk_core2.AutoApproveSpaceCreationHandler() : void 0);
759
+ this.recordActivationSkippedSpaces(result, primarySpaceId);
760
+ const handler = this.spaceCreationHandler ?? (this.autoCreateSpace ? new import_sdk_core3.AutoApproveSpaceCreationHandler() : void 0);
709
761
  const creationContext = {
710
762
  spaceId: primarySpaceId,
711
763
  address: this._address,
@@ -739,7 +791,7 @@ var NodeUserAuthorization = class {
739
791
  throw error;
740
792
  }
741
793
  await new Promise((resolve) => setTimeout(resolve, 100));
742
- const retryResult = await (0, import_sdk_core2.activateSessionWithHost)(
794
+ const retryResult = await (0, import_sdk_core3.activateSessionWithHost)(
743
795
  host,
744
796
  this._tinyCloudSession.delegationHeader
745
797
  );
@@ -776,7 +828,7 @@ var NodeUserAuthorization = class {
776
828
  throw error;
777
829
  }
778
830
  await new Promise((resolve) => setTimeout(resolve, 100));
779
- const retryResult = await (0, import_sdk_core2.activateSessionWithHost)(
831
+ const retryResult = await (0, import_sdk_core3.activateSessionWithHost)(
780
832
  host,
781
833
  this._tinyCloudSession.delegationHeader
782
834
  );
@@ -792,6 +844,66 @@ var NodeUserAuthorization = class {
792
844
  }
793
845
  throw new Error(`Failed to activate session: ${result.error}`);
794
846
  }
847
+ recordActivationSkippedSpaces(result, primarySpaceId) {
848
+ if (result.success) {
849
+ this._lastActivationSkippedSpaceIds = result.skipped ?? [];
850
+ return;
851
+ }
852
+ this._lastActivationSkippedSpaceIds = result.status === 404 ? [primarySpaceId] : [];
853
+ }
854
+ async createBootstrapSession(options) {
855
+ if (!this._address || !this._chainId) {
856
+ throw new Error("Must be signed in before creating bootstrap sessions");
857
+ }
858
+ const address = this._address;
859
+ const chainId = this._chainId;
860
+ const keyId = `bootstrap-${Date.now()}-${Math.random().toString(36).slice(2)}`;
861
+ this.sessionManager.createSessionKey(keyId);
862
+ const jwkString = this.sessionManager.jwk(keyId);
863
+ if (!jwkString) {
864
+ throw new Error("Failed to create bootstrap session key");
865
+ }
866
+ const jwk = JSON.parse(jwkString);
867
+ const now = /* @__PURE__ */ new Date();
868
+ const expirationTime = new Date(now.getTime() + this.sessionExpirationMs);
869
+ const abilities = (0, import_sdk_core3.resourceCapabilitiesToAbilitiesMap)(
870
+ options.capabilityRequest.resources
871
+ );
872
+ const prepared = this.wasm.prepareSession({
873
+ abilities,
874
+ ...options.rawAbilities !== void 0 ? { rawAbilities: options.rawAbilities } : {},
875
+ address,
876
+ chainId,
877
+ domain: this.domain,
878
+ issuedAt: now.toISOString(),
879
+ expirationTime: expirationTime.toISOString(),
880
+ spaceId: options.spaceId,
881
+ jwk,
882
+ ...this.buildSiweOverrides()
883
+ });
884
+ const signature = await this.requestSignature({
885
+ address,
886
+ chainId,
887
+ message: prepared.siwe,
888
+ type: "siwe"
889
+ });
890
+ const session = this.wasm.completeSessionSetup({
891
+ ...prepared,
892
+ signature
893
+ });
894
+ return {
895
+ address,
896
+ chainId,
897
+ sessionKey: keyId,
898
+ spaceId: options.spaceId,
899
+ delegationCid: session.delegationCid,
900
+ delegationHeader: session.delegationHeader,
901
+ verificationMethod: this.sessionManager.getDID(keyId),
902
+ jwk,
903
+ siwe: prepared.siwe,
904
+ signature
905
+ };
906
+ }
795
907
  /**
796
908
  * Sign in and create a new session.
797
909
  *
@@ -804,7 +916,7 @@ var NodeUserAuthorization = class {
804
916
  * @param options - Optional per-call SIWE overrides for this sign-in only
805
917
  */
806
918
  async signIn(options) {
807
- this._address = (0, import_sdk_core2.canonicalizeAddress)(await this.signer.getAddress());
919
+ this._address = (0, import_sdk_core3.canonicalizeAddress)(await this.signer.getAddress());
808
920
  this._chainId = await this.signer.getChainId();
809
921
  const address = this._address;
810
922
  const chainId = this._chainId;
@@ -851,7 +963,7 @@ var NodeUserAuthorization = class {
851
963
  siwe: prepared.siwe,
852
964
  signature
853
965
  };
854
- const spacesMetadata = this.enablePublicSpace ? { public: (0, import_sdk_core2.makePkhSpaceId)(address, chainId, "public") } : void 0;
966
+ const spacesMetadata = this.enablePublicSpace ? { public: (0, import_sdk_core3.makePkhSpaceId)(address, chainId, "public") } : void 0;
855
967
  const tinyCloudSession = {
856
968
  address,
857
969
  chainId,
@@ -880,14 +992,15 @@ var NodeUserAuthorization = class {
880
992
  },
881
993
  expiresAt: expirationTime.toISOString(),
882
994
  createdAt: now.toISOString(),
883
- version: "1.0"
995
+ version: "1.0",
996
+ tinycloudHosts: this.tinycloudHosts
884
997
  };
885
998
  await this.sessionStorage.save(address, persistedData);
886
999
  this._session = clientSession;
887
1000
  this._tinyCloudSession = tinyCloudSession;
888
1001
  this._address = address;
889
1002
  this._chainId = chainId;
890
- const nodeInfo = await (0, import_sdk_core2.checkNodeInfo)(
1003
+ const nodeInfo = await (0, import_sdk_core3.checkNodeInfo)(
891
1004
  this.primaryTinyCloudHost,
892
1005
  this.wasm.protocolVersion()
893
1006
  );
@@ -926,7 +1039,7 @@ var NodeUserAuthorization = class {
926
1039
  */
927
1040
  async signMessage(message) {
928
1041
  if (!this._address) {
929
- this._address = (0, import_sdk_core2.canonicalizeAddress)(await this.signer.getAddress());
1042
+ this._address = (0, import_sdk_core3.canonicalizeAddress)(await this.signer.getAddress());
930
1043
  }
931
1044
  if (!this._chainId) {
932
1045
  this._chainId = await this.signer.getChainId();
@@ -953,7 +1066,7 @@ var NodeUserAuthorization = class {
953
1066
  * ```
954
1067
  */
955
1068
  async prepareSessionForSigning() {
956
- const address = (0, import_sdk_core2.canonicalizeAddress)(await this.signer.getAddress());
1069
+ const address = (0, import_sdk_core3.canonicalizeAddress)(await this.signer.getAddress());
957
1070
  const chainId = await this.signer.getChainId();
958
1071
  const keyId = `session-${Date.now()}`;
959
1072
  this.sessionManager.renameSessionKeyId("default", keyId);
@@ -1003,7 +1116,7 @@ var NodeUserAuthorization = class {
1003
1116
  ...prepared,
1004
1117
  signature
1005
1118
  });
1006
- const address = (0, import_sdk_core2.canonicalizeAddress)(await this.signer.getAddress());
1119
+ const address = (0, import_sdk_core3.canonicalizeAddress)(await this.signer.getAddress());
1007
1120
  const chainId = await this.signer.getChainId();
1008
1121
  await this.resolveTinyCloudHostsForSignIn(address, chainId);
1009
1122
  const clientSession = {
@@ -1014,7 +1127,7 @@ var NodeUserAuthorization = class {
1014
1127
  siwe: prepared.siwe,
1015
1128
  signature
1016
1129
  };
1017
- const spacesMetadata = this.enablePublicSpace ? { public: (0, import_sdk_core2.makePkhSpaceId)(address, chainId, "public") } : void 0;
1130
+ const spacesMetadata = this.enablePublicSpace ? { public: (0, import_sdk_core3.makePkhSpaceId)(address, chainId, "public") } : void 0;
1018
1131
  const tinyCloudSession = {
1019
1132
  address,
1020
1133
  chainId,
@@ -1047,14 +1160,15 @@ var NodeUserAuthorization = class {
1047
1160
  },
1048
1161
  expiresAt,
1049
1162
  createdAt,
1050
- version: "1.0"
1163
+ version: "1.0",
1164
+ tinycloudHosts: this.tinycloudHosts
1051
1165
  };
1052
1166
  await this.sessionStorage.save(address, persistedData);
1053
1167
  this._session = clientSession;
1054
1168
  this._tinyCloudSession = tinyCloudSession;
1055
1169
  this._address = address;
1056
1170
  this._chainId = chainId;
1057
- const nodeInfo = await (0, import_sdk_core2.checkNodeInfo)(
1171
+ const nodeInfo = await (0, import_sdk_core3.checkNodeInfo)(
1058
1172
  this.primaryTinyCloudHost,
1059
1173
  this.wasm.protocolVersion()
1060
1174
  );
@@ -1138,35 +1252,36 @@ var NodeUserAuthorization = class {
1138
1252
  };
1139
1253
 
1140
1254
  // src/TinyCloudNode.ts
1141
- var import_sdk_core7 = require("@tinycloud/sdk-core");
1255
+ var import_sdk_core8 = require("@tinycloud/sdk-core");
1142
1256
 
1143
1257
  // src/account/AccountService.ts
1144
- var import_sdk_core3 = require("@tinycloud/sdk-core");
1258
+ var import_sdk_core4 = require("@tinycloud/sdk-core");
1145
1259
 
1146
1260
  // src/DelegatedAccess.ts
1147
- var import_sdk_core4 = require("@tinycloud/sdk-core");
1261
+ var import_sdk_core5 = require("@tinycloud/sdk-core");
1148
1262
  var DelegatedAccess = class {
1149
- constructor(session, delegation, host, invoke, telemetry) {
1263
+ constructor(session, delegation, host, invoke, invokeAny, telemetry) {
1150
1264
  this.session = session;
1151
1265
  this._delegation = delegation;
1152
1266
  this.host = host;
1153
- this._serviceContext = new import_sdk_core4.ServiceContext({
1267
+ this._serviceContext = new import_sdk_core5.ServiceContext({
1154
1268
  invoke,
1269
+ invokeAny,
1155
1270
  fetch: globalThis.fetch.bind(globalThis),
1156
1271
  hosts: [host],
1157
1272
  telemetry
1158
1273
  });
1159
1274
  const prefix = this._delegation.path.replace(/\/$/, "");
1160
- this._kv = new import_sdk_core4.KVService({ prefix });
1275
+ this._kv = new import_sdk_core5.KVService({ prefix });
1161
1276
  this._kv.initialize(this._serviceContext);
1162
1277
  this._serviceContext.registerService("kv", this._kv);
1163
- this._sql = new import_sdk_core4.SQLService({});
1278
+ this._sql = new import_sdk_core5.SQLService({});
1164
1279
  this._sql.initialize(this._serviceContext);
1165
1280
  this._serviceContext.registerService("sql", this._sql);
1166
- this._duckdb = new import_sdk_core4.DuckDbService({});
1281
+ this._duckdb = new import_sdk_core5.DuckDbService({});
1167
1282
  this._duckdb.initialize(this._serviceContext);
1168
1283
  this._serviceContext.registerService("duckdb", this._duckdb);
1169
- this._hooks = new import_sdk_core4.HooksService({});
1284
+ this._hooks = new import_sdk_core5.HooksService({});
1170
1285
  this._hooks.initialize(this._serviceContext);
1171
1286
  this._serviceContext.registerService("hooks", this._hooks);
1172
1287
  const serviceSession = {
@@ -1316,7 +1431,7 @@ function createWasmKeyProvider(sessionManager) {
1316
1431
  }
1317
1432
 
1318
1433
  // src/delegateToHelpers.ts
1319
- var import_sdk_core5 = require("@tinycloud/sdk-core");
1434
+ var import_sdk_core6 = require("@tinycloud/sdk-core");
1320
1435
  function legacyParamsToPermissionEntries(actions, path, spaceIdOverride) {
1321
1436
  const byService = /* @__PURE__ */ new Map();
1322
1437
  for (const a of actions) {
@@ -1347,7 +1462,7 @@ function legacyParamsToPermissionEntries(actions, path, spaceIdOverride) {
1347
1462
  }
1348
1463
  return entries;
1349
1464
  }
1350
- var DEFAULT_DELEGATION_EXPIRY_MS = import_sdk_core5.EXPIRY.SESSION_MS;
1465
+ var DEFAULT_DELEGATION_EXPIRY_MS = import_sdk_core6.EXPIRY.SESSION_MS;
1351
1466
  function resolveExpiryMs(expiry) {
1352
1467
  if (expiry === void 0) {
1353
1468
  return DEFAULT_DELEGATION_EXPIRY_MS;
@@ -1360,10 +1475,10 @@ function resolveExpiryMs(expiry) {
1360
1475
  }
1361
1476
  return expiry;
1362
1477
  }
1363
- return (0, import_sdk_core5.parseExpiry)(expiry);
1478
+ return (0, import_sdk_core6.parseExpiry)(expiry);
1364
1479
  }
1365
1480
  function extractSiweExpiration(siwe) {
1366
- const parsed = new import_sdk_core5.SiweMessage(siwe);
1481
+ const parsed = new import_sdk_core6.SiweMessage(siwe);
1367
1482
  if (parsed.expirationTime === void 0 || parsed.expirationTime === null) {
1368
1483
  return void 0;
1369
1484
  }
@@ -1377,7 +1492,7 @@ function extractSiweExpiration(siwe) {
1377
1492
  }
1378
1493
 
1379
1494
  // src/NodeSecretsService.ts
1380
- var import_sdk_core6 = require("@tinycloud/sdk-core");
1495
+ var import_sdk_core7 = require("@tinycloud/sdk-core");
1381
1496
  var SECRETS_SPACE = "secrets";
1382
1497
  function ok() {
1383
1498
  return { ok: true, data: void 0 };
@@ -1408,12 +1523,12 @@ function displayActionUrn(action) {
1408
1523
  function secretActionName(action) {
1409
1524
  return action;
1410
1525
  }
1411
- function secretPermissionEntries(name, options, action, encryptionNetworkId) {
1526
+ function secretPermissionEntries(name, options, action, space, encryptionNetworkId) {
1412
1527
  const entries = [];
1413
- const path = action === "list" ? (0, import_sdk_core6.resolveSecretListPrefix)(options) : (0, import_sdk_core6.resolveSecretPath)(name, options).permissionPaths.vault;
1528
+ const path = action === "list" ? (0, import_sdk_core7.resolveSecretListPrefix)(options) : (0, import_sdk_core7.resolveSecretPath)(name, options).permissionPaths.vault;
1414
1529
  entries.push({
1415
1530
  service: "tinycloud.kv",
1416
- space: SECRETS_SPACE,
1531
+ space,
1417
1532
  path,
1418
1533
  actions: [secretActionName(action)],
1419
1534
  skipPrefix: true
@@ -1428,11 +1543,23 @@ function secretPermissionEntries(name, options, action, encryptionNetworkId) {
1428
1543
  }
1429
1544
  return entries;
1430
1545
  }
1546
+ function normalizeSpace(space, resolveSpace) {
1547
+ if (!space) return void 0;
1548
+ if (space.startsWith("tinycloud:")) return space;
1549
+ return resolveSpace?.(space) ?? space;
1550
+ }
1551
+ function spaceMatches(granted, requested, resolveSpace) {
1552
+ if (!granted || !requested) return false;
1553
+ return normalizeSpace(granted, resolveSpace) === normalizeSpace(requested, resolveSpace);
1554
+ }
1431
1555
  var NodeSecretsService = class {
1432
1556
  constructor(config) {
1433
1557
  this.config = config;
1434
1558
  this.shouldRestoreUnlock = false;
1435
1559
  }
1560
+ get space() {
1561
+ return this.config.space ?? SECRETS_SPACE;
1562
+ }
1436
1563
  get vault() {
1437
1564
  return this.service.vault;
1438
1565
  }
@@ -1485,11 +1612,12 @@ var NodeSecretsService = class {
1485
1612
  name,
1486
1613
  options,
1487
1614
  action,
1615
+ this.space,
1488
1616
  action === "get" ? this.config.getEncryptionNetworkId?.() : void 0
1489
1617
  );
1490
1618
  } catch (error) {
1491
1619
  return secretsError(
1492
- import_sdk_core6.ErrorCodes.INVALID_INPUT,
1620
+ import_sdk_core7.ErrorCodes.INVALID_INPUT,
1493
1621
  error instanceof Error ? error.message : String(error),
1494
1622
  error instanceof Error ? error : void 0
1495
1623
  );
@@ -1499,7 +1627,7 @@ var NodeSecretsService = class {
1499
1627
  }
1500
1628
  if (!this.config.canEscalate()) {
1501
1629
  return secretsError(
1502
- import_sdk_core6.ErrorCodes.PERMISSION_DENIED,
1630
+ import_sdk_core7.ErrorCodes.PERMISSION_DENIED,
1503
1631
  `Cannot autosign ${displayActionUrn(action)} for ${target}; TinyCloudNode needs wallet mode with a signer or privateKey.`
1504
1632
  );
1505
1633
  }
@@ -1508,7 +1636,7 @@ var NodeSecretsService = class {
1508
1636
  return this.restoreUnlockAfterEscalation();
1509
1637
  } catch (error) {
1510
1638
  return secretsError(
1511
- import_sdk_core6.ErrorCodes.PERMISSION_DENIED,
1639
+ import_sdk_core7.ErrorCodes.PERMISSION_DENIED,
1512
1640
  error instanceof Error ? error.message : `Autosign escalation for ${displayActionUrn(action)} on ${target} failed.`,
1513
1641
  error instanceof Error ? error : void 0
1514
1642
  );
@@ -1529,12 +1657,12 @@ var NodeSecretsService = class {
1529
1657
  return false;
1530
1658
  }
1531
1659
  const manifests = Array.isArray(manifest) ? manifest : [manifest];
1532
- const requestedEntries = (0, import_sdk_core6.expandPermissionEntries)(permissionEntries);
1660
+ const requestedEntries = (0, import_sdk_core7.expandPermissionEntries)(permissionEntries);
1533
1661
  return requestedEntries.every(
1534
1662
  (entry) => manifests.some((candidate) => {
1535
- const resolved = (0, import_sdk_core6.resolveManifest)(candidate);
1663
+ const resolved = (0, import_sdk_core7.resolveManifest)(candidate);
1536
1664
  return resolved.resources.some(
1537
- (resource) => resource.service === entry.service && resource.space === entry.space && resource.path === entry.path && entry.actions.every((action) => resource.actions.includes(action))
1665
+ (resource) => resource.service === entry.service && spaceMatches(resource.space, entry.space, this.config.resolveSpace) && resource.path === entry.path && entry.actions.every((action) => resource.actions.includes(action))
1538
1666
  );
1539
1667
  })
1540
1668
  );
@@ -1547,14 +1675,31 @@ var DEFAULT_ENCRYPTION_NETWORK_NAME = "default";
1547
1675
  var NETWORK_CREATE_ACTION2 = "tinycloud.encryption/network.create";
1548
1676
  var DECRYPT_ACTION2 = "tinycloud.encryption/decrypt";
1549
1677
  var NETWORK_ADMIN_TYPE = "tinycloud.encryption.network-admin/v1";
1550
- var DEFAULT_SESSION_EXPIRATION_MS = import_sdk_core7.EXPIRY.SESSION_MS;
1678
+ var DEFAULT_SESSION_EXPIRATION_MS = import_sdk_core8.EXPIRY.SESSION_MS;
1679
+ function isOpenKeyAutoSignStrategy(strategy) {
1680
+ return strategy?.openKeyAutoSign === true;
1681
+ }
1551
1682
  function didPrincipalMatches2(actual, expected) {
1552
1683
  try {
1553
- return (0, import_sdk_core7.principalDidEquals)(actual, expected);
1684
+ return (0, import_sdk_core8.principalDidEquals)(actual, expected);
1554
1685
  } catch {
1555
1686
  return actual === expected;
1556
1687
  }
1557
1688
  }
1689
+ function sharingActionsToAbilities(path, actions) {
1690
+ var _a;
1691
+ const abilities = {};
1692
+ for (const action of actions) {
1693
+ const slash = action.indexOf("/");
1694
+ if (slash === -1) return void 0;
1695
+ const shortService = import_sdk_core8.SERVICE_LONG_TO_SHORT[action.slice(0, slash)];
1696
+ if (shortService === void 0) return void 0;
1697
+ abilities[shortService] ?? (abilities[shortService] = {});
1698
+ (_a = abilities[shortService])[path] ?? (_a[path] = []);
1699
+ abilities[shortService][path].push(action);
1700
+ }
1701
+ return Object.keys(abilities).length > 0 ? abilities : void 0;
1702
+ }
1558
1703
  function base64UrlEncode(bytes) {
1559
1704
  const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
1560
1705
  let output = "";
@@ -1667,6 +1812,8 @@ var _TinyCloudNode = class _TinyCloudNode {
1667
1812
  this.auth = null;
1668
1813
  this.tc = null;
1669
1814
  this._chainId = 1;
1815
+ this._baseSecrets = /* @__PURE__ */ new Map();
1816
+ this._secrets = /* @__PURE__ */ new Map();
1670
1817
  this.runtimePermissionGrants = [];
1671
1818
  this.invokeWithRuntimePermissions = (session, service, path, action, facts) => {
1672
1819
  return this.wasmBindings.invoke(
@@ -1716,12 +1863,12 @@ var _TinyCloudNode = class _TinyCloudNode {
1716
1863
  throw new Error("Failed to get session key JWK");
1717
1864
  }
1718
1865
  this.sessionKeyJwk = JSON.parse(jwkStr);
1719
- this._capabilityRegistry = new import_sdk_core7.CapabilityKeyRegistry();
1866
+ this._capabilityRegistry = new import_sdk_core8.CapabilityKeyRegistry();
1720
1867
  this._keyProvider = new WasmKeyProvider({
1721
1868
  sessionManager: this.sessionManager
1722
1869
  });
1723
- this.notificationHandler = config.notificationHandler ?? new import_sdk_core7.SilentNotificationHandler();
1724
- this._sharingService = new import_sdk_core7.SharingService({
1870
+ this.notificationHandler = config.notificationHandler ?? new import_sdk_core8.SilentNotificationHandler();
1871
+ this._sharingService = new import_sdk_core8.SharingService({
1725
1872
  hosts: [this.config.host],
1726
1873
  // session: undefined - not needed for receive()
1727
1874
  invoke: this.invokeWithRuntimePermissions,
@@ -1731,8 +1878,8 @@ var _TinyCloudNode = class _TinyCloudNode {
1731
1878
  // delegationManager: undefined - not needed for receive()
1732
1879
  createKVService: (config2) => {
1733
1880
  const prefix = config2.pathPrefix?.replace(/\/$/, "");
1734
- const kvService = new import_sdk_core7.KVService({ prefix });
1735
- const kvContext = new import_sdk_core7.ServiceContext({
1881
+ const kvService = new import_sdk_core8.KVService({ prefix });
1882
+ const kvContext = new import_sdk_core8.ServiceContext({
1736
1883
  invoke: config2.invoke,
1737
1884
  fetch: config2.fetch ?? globalThis.fetch.bind(globalThis),
1738
1885
  hosts: config2.hosts,
@@ -1772,9 +1919,10 @@ var _TinyCloudNode = class _TinyCloudNode {
1772
1919
  * @internal
1773
1920
  */
1774
1921
  setupAuth(config) {
1922
+ const useBootstrapSignInRequest = this.shouldUseBootstrapSignInRequest(config);
1775
1923
  this.auth = new NodeUserAuthorization({
1776
1924
  signer: this.signer,
1777
- signStrategy: { type: "auto-sign" },
1925
+ signStrategy: config.signStrategy ?? { type: "auto-sign" },
1778
1926
  wasmBindings: this.wasmBindings,
1779
1927
  sessionStorage: config.sessionStorage ?? new MemorySessionStorage(),
1780
1928
  domain: this.siweDomain,
@@ -1783,20 +1931,23 @@ var _TinyCloudNode = class _TinyCloudNode {
1783
1931
  tinycloudHosts: this.explicitHost ? [this.explicitHost] : void 0,
1784
1932
  tinycloudRegistryUrl: config.tinycloudRegistryUrl,
1785
1933
  tinycloudFallbackHosts: config.tinycloudFallbackHosts,
1786
- autoCreateSpace: config.autoCreateSpace,
1934
+ autoCreateSpace: useBootstrapSignInRequest ? false : config.autoCreateSpace,
1787
1935
  enablePublicSpace: config.enablePublicSpace ?? true,
1788
- spaceCreationHandler: config.spaceCreationHandler,
1936
+ spaceCreationHandler: useBootstrapSignInRequest ? void 0 : config.spaceCreationHandler,
1789
1937
  nonce: config.nonce,
1790
1938
  siweConfig: config.siweConfig,
1791
- manifest: config.manifest,
1792
- capabilityRequest: config.capabilityRequest,
1793
- includeAccountRegistryPermissions: config.includeAccountRegistryPermissions
1939
+ manifest: useBootstrapSignInRequest ? void 0 : config.manifest,
1940
+ capabilityRequest: useBootstrapSignInRequest ? import_sdk_core8.BOOTSTRAP_SESSION_REQUESTS.default : config.capabilityRequest,
1941
+ includeAccountRegistryPermissions: useBootstrapSignInRequest ? false : config.includeAccountRegistryPermissions
1794
1942
  });
1795
- this.tc = new import_sdk_core7.TinyCloud(this.auth, {
1943
+ this.tc = new import_sdk_core8.TinyCloud(this.auth, {
1796
1944
  invokeAny: this.invokeAnyWithRuntimePermissions,
1797
1945
  telemetry: config.telemetry
1798
1946
  });
1799
1947
  }
1948
+ shouldUseBootstrapSignInRequest(config) {
1949
+ return config.autoBootstrapAccount !== false && config.manifest === void 0 && config.capabilityRequest === void 0 && (config.prefix ?? "default") === "default" && isOpenKeyAutoSignStrategy(config.signStrategy);
1950
+ }
1800
1951
  syncResolvedHostFromAuth() {
1801
1952
  const host = this.auth?.hosts[0];
1802
1953
  if (host) {
@@ -1853,7 +2004,7 @@ var _TinyCloudNode = class _TinyCloudNode {
1853
2004
  */
1854
2005
  get did() {
1855
2006
  if (this._address) {
1856
- return (0, import_sdk_core7.pkhDid)(this._address, this._chainId);
2007
+ return (0, import_sdk_core8.pkhDid)(this._address, this._chainId);
1857
2008
  }
1858
2009
  return this.sessionManager.getDID(this.sessionKeyId);
1859
2010
  }
@@ -1895,14 +2046,14 @@ var _TinyCloudNode = class _TinyCloudNode {
1895
2046
  if (!this._address) {
1896
2047
  return void 0;
1897
2048
  }
1898
- return this.wasmBindings.makeSpaceId(this._address, this._chainId, import_sdk_core7.ACCOUNT_REGISTRY_SPACE);
2049
+ return this.wasmBindings.makeSpaceId(this._address, this._chainId, import_sdk_core8.ACCOUNT_REGISTRY_SPACE);
1899
2050
  }
1900
2051
  /**
1901
2052
  * Account-level application and delegation helpers.
1902
2053
  */
1903
2054
  get account() {
1904
2055
  if (!this._account) {
1905
- this._account = new import_sdk_core3.AccountService({
2056
+ this._account = new import_sdk_core4.AccountService({
1906
2057
  getDid: () => this.did,
1907
2058
  getHost: () => this.hosts[0] ?? this.config.host,
1908
2059
  getPrimarySpaceId: () => this.spaceId,
@@ -1911,7 +2062,7 @@ var _TinyCloudNode = class _TinyCloudNode {
1911
2062
  getAccountDb: () => this.accountSpaceId ? this.sqlForSpace(this.accountSpaceId).db("account") : void 0,
1912
2063
  ensureAccountSpaceHosted: async () => {
1913
2064
  if (this.accountSpaceId && this.auth) {
1914
- await this.ensureOwnedSpaceHosted(this.accountSpaceId);
2065
+ await this.ensureOwnedSpaceHostedById(this.accountSpaceId);
1915
2066
  }
1916
2067
  }
1917
2068
  });
@@ -1925,6 +2076,13 @@ var _TinyCloudNode = class _TinyCloudNode {
1925
2076
  get session() {
1926
2077
  return this.auth?.tinyCloudSession;
1927
2078
  }
2079
+ /**
2080
+ * Get the currently active session in the shape callers can persist and later
2081
+ * pass back to {@link restoreSession}.
2082
+ */
2083
+ get restorableSession() {
2084
+ return this.currentTinyCloudSession();
2085
+ }
1928
2086
  /**
1929
2087
  * Sign in and create a new session.
1930
2088
  * This creates the user's space if it doesn't exist.
@@ -1939,7 +2097,7 @@ var _TinyCloudNode = class _TinyCloudNode {
1939
2097
  );
1940
2098
  }
1941
2099
  await this.wasmBindings.ensureInitialized?.();
1942
- this._address = (0, import_sdk_core7.canonicalizeAddress)(await this.signer.getAddress());
2100
+ this._address = (0, import_sdk_core8.canonicalizeAddress)(await this.signer.getAddress());
1943
2101
  this._chainId = await this.signer.getChainId();
1944
2102
  this._kv = void 0;
1945
2103
  this._sql = void 0;
@@ -1947,19 +2105,22 @@ var _TinyCloudNode = class _TinyCloudNode {
1947
2105
  this._hooks = void 0;
1948
2106
  this._vault = void 0;
1949
2107
  this._encryption = void 0;
1950
- this._baseSecrets = void 0;
1951
- this._secrets = void 0;
2108
+ this._baseSecrets.clear();
2109
+ this._secrets.clear();
1952
2110
  this._spaceService = void 0;
1953
2111
  this._serviceContext = void 0;
1954
2112
  this.runtimePermissionGrants = [];
1955
2113
  await this.tc.signIn(options);
1956
2114
  this.syncResolvedHostFromAuth();
1957
2115
  this.initializeServices();
2116
+ const bootstrapped = await this.bootstrapAccountIfNeeded();
1958
2117
  await this.ensureRequestedEncryptionNetworks();
1959
- if (this.config.manifest === void 0 && this.config.capabilityRequest === void 0) {
1960
- await this.ensureOwnedSpaceHosted(this.ownedSpaceId("secrets"));
2118
+ if (!bootstrapped && this.config.manifest === void 0 && this.config.capabilityRequest === void 0) {
2119
+ await this.ensureOwnedSpaceHostedById(this.ownedSpaceId(import_sdk_core8.SECRETS_SPACE));
2120
+ }
2121
+ if (!bootstrapped) {
2122
+ this.scheduleAccountRegistrySync();
1961
2123
  }
1962
- this.scheduleAccountRegistrySync();
1963
2124
  this.notificationHandler.success("Successfully signed in");
1964
2125
  }
1965
2126
  ownedSpaceId(name) {
@@ -1968,6 +2129,208 @@ var _TinyCloudNode = class _TinyCloudNode {
1968
2129
  }
1969
2130
  return this.wasmBindings.makeSpaceId(this._address, this._chainId, name);
1970
2131
  }
2132
+ async bootstrapAccountIfNeeded() {
2133
+ if (this.config.autoBootstrapAccount === false) {
2134
+ return false;
2135
+ }
2136
+ if (!this.auth || !this._address) {
2137
+ return false;
2138
+ }
2139
+ const steps = (0, import_sdk_core8.bootstrapSteps)(this._address, this._chainId);
2140
+ if (!await this.isFreshBootstrapAccount(steps)) {
2141
+ return false;
2142
+ }
2143
+ await this.runAccountBootstrap(steps);
2144
+ return true;
2145
+ }
2146
+ async isFreshBootstrapAccount(steps) {
2147
+ const enshrinedSpaceIds = /* @__PURE__ */ new Set();
2148
+ for (const step of steps) {
2149
+ if (step.kind === "session") {
2150
+ enshrinedSpaceIds.add(step.spaceId);
2151
+ }
2152
+ }
2153
+ const skipped = this.auth.lastActivationSkippedSpaceIds;
2154
+ if (skipped.some((spaceId) => enshrinedSpaceIds.has(spaceId))) {
2155
+ return true;
2156
+ }
2157
+ try {
2158
+ const indexed = await this.account.index.spaces.list();
2159
+ if (indexed.ok && indexed.data.length === 0) {
2160
+ return true;
2161
+ }
2162
+ } catch {
2163
+ }
2164
+ try {
2165
+ const spaces = await this.account.spaces.list();
2166
+ return spaces.ok && spaces.data.length === 0;
2167
+ } catch {
2168
+ return false;
2169
+ }
2170
+ }
2171
+ async runAccountBootstrap(steps) {
2172
+ if (!this.auth || !this._address) {
2173
+ throw new Error("Account bootstrap requires an active wallet session");
2174
+ }
2175
+ const host = this.hosts[0] ?? this.config.host;
2176
+ if (!host) {
2177
+ throw new Error("Account bootstrap requires a TinyCloud host");
2178
+ }
2179
+ const auth = this.auth;
2180
+ const sessions = /* @__PURE__ */ new Map();
2181
+ const rawAbilitiesBySpace = /* @__PURE__ */ new Map();
2182
+ const primarySession = auth.tinyCloudSession;
2183
+ const defaultSpaceId = this.ownedSpaceId("default");
2184
+ const canReusePrimaryBootstrapSession = primarySession?.spaceId === defaultSpaceId && auth.capabilityRequest === import_sdk_core8.BOOTSTRAP_SESSION_REQUESTS.default;
2185
+ for (const step of steps) {
2186
+ if (step.kind !== "session") continue;
2187
+ if (step.space === "default" && canReusePrimaryBootstrapSession && primarySession) {
2188
+ sessions.set(step.space, primarySession);
2189
+ continue;
2190
+ }
2191
+ const rawAbilities = step.rawAbilities;
2192
+ if (rawAbilities) {
2193
+ rawAbilitiesBySpace.set(step.space, rawAbilities);
2194
+ }
2195
+ const session = await auth.createBootstrapSession({
2196
+ spaceId: step.spaceId,
2197
+ capabilityRequest: step.request ?? import_sdk_core8.BOOTSTRAP_SESSION_REQUESTS[step.space],
2198
+ rawAbilities
2199
+ });
2200
+ sessions.set(step.space, session);
2201
+ }
2202
+ for (const step of steps) {
2203
+ if (step.kind !== "host") continue;
2204
+ const hosted = await auth.hostOwnedSpace(step.spaceId);
2205
+ if (!hosted) {
2206
+ throw new Error(`Failed to host bootstrap space: ${step.spaceId}`);
2207
+ }
2208
+ }
2209
+ await new Promise((resolve) => setTimeout(resolve, 100));
2210
+ for (const step of steps) {
2211
+ if (step.kind !== "activate") continue;
2212
+ const session = sessions.get(step.space);
2213
+ if (!session) {
2214
+ throw new Error(`Missing bootstrap session for ${step.space}`);
2215
+ }
2216
+ const activated = await (0, import_sdk_core8.activateSessionWithHost)(host, session.delegationHeader);
2217
+ if (!activated.success || activated.skipped?.includes(step.spaceId)) {
2218
+ throw new Error(
2219
+ `Failed to activate bootstrap session for ${step.spaceId}: ${activated.error ?? "space was skipped"}`
2220
+ );
2221
+ }
2222
+ this.registerBootstrapRuntimeGrant(
2223
+ session,
2224
+ import_sdk_core8.BOOTSTRAP_SESSION_REQUESTS[step.space],
2225
+ rawAbilitiesBySpace.get(step.space)
2226
+ );
2227
+ }
2228
+ for (const step of steps) {
2229
+ if (step.kind === "account-index-schema") {
2230
+ const ensured = await this.account.index.ensure();
2231
+ if (!ensured.ok) {
2232
+ throw new Error(`Failed to create account index schema: ${ensured.error.message}`);
2233
+ }
2234
+ }
2235
+ if (step.kind === "seed-spaces") {
2236
+ for (const space of step.spaces) {
2237
+ const registered = await this.account.spaces.register({
2238
+ spaceId: space.spaceId,
2239
+ name: space.name,
2240
+ ownerDid: this.did,
2241
+ type: "owned",
2242
+ permissions: ["*"],
2243
+ status: "active"
2244
+ });
2245
+ if (!registered.ok) {
2246
+ throw new Error(
2247
+ `Failed to seed account space ${space.spaceId}: ${registered.error.message}`
2248
+ );
2249
+ }
2250
+ }
2251
+ }
2252
+ if (step.kind === "seed-applications") {
2253
+ const registered = await this.account.applications.register(
2254
+ step.manifests.length > 0 ? [...step.manifests] : import_sdk_core8.TINYCLOUD_SECRETS_BOOTSTRAP_MANIFEST
2255
+ );
2256
+ if (!registered.ok) {
2257
+ throw new Error(`Failed to seed bootstrap applications: ${registered.error.message}`);
2258
+ }
2259
+ }
2260
+ if (step.kind === "encryption-network-create") {
2261
+ await this.ensureEncryptionNetwork(step.networkId);
2262
+ }
2263
+ if (step.kind === "secret-records-schema") {
2264
+ const db = this.sqlForSpace(step.spaceId).db(step.database);
2265
+ const migrated = await db.migrations.apply({
2266
+ namespace: "tinycloud.secrets.records",
2267
+ migrations: [
2268
+ {
2269
+ id: "001_initial",
2270
+ sql: [...import_sdk_core8.SECRET_RECORDS_SCHEMA]
2271
+ }
2272
+ ]
2273
+ });
2274
+ if (!migrated.ok) {
2275
+ throw new Error(
2276
+ `Failed to create secret_records schema: ${migrated.error.message}`
2277
+ );
2278
+ }
2279
+ }
2280
+ }
2281
+ }
2282
+ registerBootstrapRuntimeGrant(session, request, rawAbilities) {
2283
+ const operations = [];
2284
+ for (const resource of request.resources) {
2285
+ const service = resource.service.startsWith("tinycloud.") ? this.shortServiceName(resource.service) : resource.service;
2286
+ const spaceId = resource.space.startsWith("tinycloud:") ? resource.space : this.ownedSpaceId(resource.space);
2287
+ for (const action of resource.actions) {
2288
+ operations.push({
2289
+ spaceId,
2290
+ service,
2291
+ path: resource.path,
2292
+ action
2293
+ });
2294
+ }
2295
+ }
2296
+ for (const [resource, actions2] of Object.entries(rawAbilities ?? {})) {
2297
+ for (const action of actions2) {
2298
+ operations.push({
2299
+ resource,
2300
+ service: "encryption",
2301
+ path: resource,
2302
+ action
2303
+ });
2304
+ }
2305
+ }
2306
+ const expiresAt = extractSiweExpiration(session.siwe) ?? this.getSessionExpiry();
2307
+ const actions = [...new Set(operations.map((operation) => operation.action))];
2308
+ this.runtimePermissionGrants.push({
2309
+ session: {
2310
+ delegationHeader: session.delegationHeader,
2311
+ delegationCid: session.delegationCid,
2312
+ spaceId: session.spaceId,
2313
+ verificationMethod: session.verificationMethod,
2314
+ jwk: session.jwk
2315
+ },
2316
+ delegation: {
2317
+ cid: session.delegationCid,
2318
+ delegationHeader: session.delegationHeader,
2319
+ delegateDID: session.verificationMethod,
2320
+ delegatorDID: this.did,
2321
+ spaceId: session.spaceId,
2322
+ path: "",
2323
+ actions,
2324
+ expiry: expiresAt,
2325
+ allowSubDelegation: true,
2326
+ ownerAddress: session.address,
2327
+ chainId: session.chainId,
2328
+ host: this.config.host
2329
+ },
2330
+ operations,
2331
+ expiresAt
2332
+ });
2333
+ }
1971
2334
  async writeManifestRegistryRecords() {
1972
2335
  const request = this.capabilityRequest;
1973
2336
  if (!request || request.registryRecords.length === 0) {
@@ -1976,8 +2339,8 @@ var _TinyCloudNode = class _TinyCloudNode {
1976
2339
  if (!this.auth || !this.signer) {
1977
2340
  throw new Error("Manifest registry write requires wallet mode");
1978
2341
  }
1979
- const accountSpaceId = this.ownedSpaceId(import_sdk_core7.ACCOUNT_REGISTRY_SPACE);
1980
- await this.ensureOwnedSpaceHosted(accountSpaceId);
2342
+ const accountSpaceId = this.ownedSpaceId(import_sdk_core8.ACCOUNT_REGISTRY_SPACE);
2343
+ await this.ensureOwnedSpaceHostedById(accountSpaceId);
1981
2344
  const result = await this.account.applications.register(request.manifests);
1982
2345
  if (!result.ok) {
1983
2346
  throw new Error(
@@ -1987,6 +2350,7 @@ var _TinyCloudNode = class _TinyCloudNode {
1987
2350
  }
1988
2351
  scheduleAccountRegistrySync() {
1989
2352
  void this.withAccountRegistryRetry(async () => {
2353
+ void this.account.index.ensure();
1990
2354
  await this.writeManifestRegistryRecords();
1991
2355
  const spaces = await this.account.spaces.syncAccessible();
1992
2356
  if (!spaces.ok) {
@@ -2020,7 +2384,7 @@ var _TinyCloudNode = class _TinyCloudNode {
2020
2384
  }
2021
2385
  const networkIds = /* @__PURE__ */ new Set();
2022
2386
  for (const resource of request.resources) {
2023
- if (resource.service === import_sdk_core7.ENCRYPTION_PERMISSION_SERVICE && resource.path.startsWith("urn:tinycloud:encryption:") && resource.actions.includes(DECRYPT_ACTION2)) {
2387
+ if (resource.service === import_sdk_core8.ENCRYPTION_PERMISSION_SERVICE && resource.path.startsWith("urn:tinycloud:encryption:") && resource.actions.includes(DECRYPT_ACTION2)) {
2024
2388
  networkIds.add(resource.path);
2025
2389
  }
2026
2390
  }
@@ -2031,14 +2395,14 @@ var _TinyCloudNode = class _TinyCloudNode {
2031
2395
  return;
2032
2396
  }
2033
2397
  for (const networkId of this.requestedEncryptionNetworkIds()) {
2034
- const parsed = (0, import_sdk_core7.parseNetworkId)(networkId);
2398
+ const parsed = (0, import_sdk_core8.parseNetworkId)(networkId);
2035
2399
  if (!didPrincipalMatches2(parsed.ownerDid, this.did)) {
2036
2400
  continue;
2037
2401
  }
2038
2402
  await this.ensureEncryptionNetwork(networkId);
2039
2403
  }
2040
2404
  }
2041
- async ensureOwnedSpaceHosted(spaceId) {
2405
+ async ensureOwnedSpaceHostedById(spaceId) {
2042
2406
  if (!this.auth) {
2043
2407
  throw new Error("Owned space hosting requires wallet mode");
2044
2408
  }
@@ -2050,7 +2414,7 @@ var _TinyCloudNode = class _TinyCloudNode {
2050
2414
  if (!host) {
2051
2415
  throw new Error("Owned space hosting requires a TinyCloud host");
2052
2416
  }
2053
- const activation = await (0, import_sdk_core7.activateSessionWithHost)(host, session.delegationHeader);
2417
+ const activation = await (0, import_sdk_core8.activateSessionWithHost)(host, session.delegationHeader);
2054
2418
  if (activation.success && !activation.skipped?.includes(spaceId)) {
2055
2419
  return;
2056
2420
  }
@@ -2064,7 +2428,7 @@ var _TinyCloudNode = class _TinyCloudNode {
2064
2428
  throw new Error(`Failed to create owned space: ${spaceId}`);
2065
2429
  }
2066
2430
  await new Promise((resolve) => setTimeout(resolve, 100));
2067
- const retry = await (0, import_sdk_core7.activateSessionWithHost)(host, session.delegationHeader);
2431
+ const retry = await (0, import_sdk_core8.activateSessionWithHost)(host, session.delegationHeader);
2068
2432
  if (!retry.success || retry.skipped?.includes(spaceId)) {
2069
2433
  throw new Error(
2070
2434
  `Failed to activate session after creating owned space ${spaceId}: ${retry.error ?? "space was skipped"}`
@@ -2081,7 +2445,7 @@ var _TinyCloudNode = class _TinyCloudNode {
2081
2445
  * caller is the root authority of their own owned spaces, so no additional
2082
2446
  * delegation is required.
2083
2447
  *
2084
- * Unlike {@link ensureOwnedSpaceHosted}, this always submits the host
2448
+ * Unlike {@link ensureOwnedSpaceHostedById}, this always submits the host
2085
2449
  * delegation rather than inferring hosting from session activation: a space
2086
2450
  * the current session has never referenced is reported neither as
2087
2451
  * `activated` nor `skipped`, so activation-based detection would wrongly
@@ -2106,7 +2470,7 @@ var _TinyCloudNode = class _TinyCloudNode {
2106
2470
  if (!hosted) {
2107
2471
  throw new Error(`Failed to host owned space: ${spaceId}`);
2108
2472
  }
2109
- const activation = await (0, import_sdk_core7.activateSessionWithHost)(
2473
+ const activation = await (0, import_sdk_core8.activateSessionWithHost)(
2110
2474
  host,
2111
2475
  this.auth.tinyCloudSession.delegationHeader
2112
2476
  );
@@ -2126,6 +2490,91 @@ var _TinyCloudNode = class _TinyCloudNode {
2126
2490
  });
2127
2491
  return spaceId;
2128
2492
  }
2493
+ /**
2494
+ * Ensure one of this user's owned spaces (e.g. `"secrets"`) is hosted on the
2495
+ * server.
2496
+ *
2497
+ * At sign-in, a full-authority session auto-hosts the owner's `secrets`
2498
+ * space, but a session created with a manifest / capabilityRequest does not.
2499
+ * Such a session can therefore hold valid `tinycloud.kv/*` capabilities for
2500
+ * the owned `secrets` space yet still fail its first scoped
2501
+ * `secrets.put(...)` with `404 Space not found`, because the space was never
2502
+ * registered on the node.
2503
+ *
2504
+ * Calling this resolves `name` to the owner's owned-space URI
2505
+ * (`tinycloud:pkh:eip155:<chain>:<addr>:<name>`). It first consults the
2506
+ * account-space spaces registry (`account/spaces/{space_id}`, the canonical
2507
+ * KV source of truth, fronted by a best-effort SQLite index): if the space is
2508
+ * already registered/hosted it returns the URI WITHOUT submitting a host
2509
+ * delegation, avoiding a redundant host-SIWE signature prompt for owners who
2510
+ * already use the space. Only when the space is absent — or the registry
2511
+ * check fails for any reason (e.g. a cold SQLite index reporting
2512
+ * `no such table: spaces`) — does it fall through to {@link hostOwnedSpace}.
2513
+ *
2514
+ * The registry check is purely an optimization: any failure falls back to
2515
+ * hosting, and the host SIWE is idempotent server-side, so re-hosting an
2516
+ * existing space remains a safe no-op. Must be called after {@link signIn}.
2517
+ *
2518
+ * @param name - The owned space name (e.g. `"secrets"`).
2519
+ * @returns The hosted owned-space URI.
2520
+ */
2521
+ async ensureOwnedSpaceHosted(name) {
2522
+ if (!this.auth || !this.auth.tinyCloudSession) {
2523
+ throw new Error("Not signed in. Call signIn() first.");
2524
+ }
2525
+ const spaceId = this.ownedSpaceId(name);
2526
+ if (await this.isOwnedSpaceRegistered(spaceId)) {
2527
+ return spaceId;
2528
+ }
2529
+ const hosted = await this.hostOwnedSpace(name);
2530
+ try {
2531
+ await this.account.spaces.register({
2532
+ spaceId,
2533
+ name,
2534
+ ownerDid: this.did,
2535
+ type: "owned",
2536
+ permissions: ["*"],
2537
+ status: "active"
2538
+ });
2539
+ } catch {
2540
+ }
2541
+ return hosted;
2542
+ }
2543
+ /**
2544
+ * Check whether an owned space is already registered/hosted by consulting the
2545
+ * account spaces registry.
2546
+ *
2547
+ * Source of truth is the canonical KV registry record
2548
+ * `account/spaces/{space_id}`, read here via `account.spaces.get(spaceId)`.
2549
+ * The KV path is used (rather than `syncAccessible()`) because it works under
2550
+ * a manifest/recap session with NO extra prompt: the composed manifest recap
2551
+ * already grants `tinycloud.kv get/list` on the account space `spaces/`
2552
+ * prefix, whereas `syncAccessible()` depends on `tinycloud.space/list`, which
2553
+ * a recap session does not hold. Before reading, it consults the fast SQLite
2554
+ * index (`account.index.spaces.list()`) as a best-effort short-circuit; on a
2555
+ * cold index (`no such table: spaces`) or any other index failure it falls
2556
+ * back to the canonical KV read.
2557
+ *
2558
+ * This is a best-effort optimization. ANY failure of the check path (missing
2559
+ * table, KV error, missing record, thrown exception) resolves to `false` so
2560
+ * the caller falls through to hosting — per the directive, "if it fails in any
2561
+ * way then create the space".
2562
+ */
2563
+ async isOwnedSpaceRegistered(spaceId) {
2564
+ try {
2565
+ const indexed = await this.account.index.spaces.list();
2566
+ if (indexed.ok && indexed.data.some((space) => space.spaceId === spaceId)) {
2567
+ return true;
2568
+ }
2569
+ } catch {
2570
+ }
2571
+ try {
2572
+ const record = await this.account.spaces.get(spaceId);
2573
+ return record.ok;
2574
+ } catch {
2575
+ return false;
2576
+ }
2577
+ }
2129
2578
  /**
2130
2579
  * Restore a previously established session from stored delegation data.
2131
2580
  *
@@ -2143,35 +2592,43 @@ var _TinyCloudNode = class _TinyCloudNode {
2143
2592
  this._hooks = void 0;
2144
2593
  this._vault = void 0;
2145
2594
  this._encryption = void 0;
2146
- this._baseSecrets = void 0;
2147
- this._secrets = void 0;
2595
+ this._baseSecrets.clear();
2596
+ this._secrets.clear();
2148
2597
  this._spaceService = void 0;
2149
2598
  this._serviceContext = void 0;
2150
2599
  this.runtimePermissionGrants = [];
2151
- const restoredAddress = sessionData.address ? (0, import_sdk_core7.canonicalizeAddress)(sessionData.address) : void 0;
2600
+ const restoredAddress = sessionData.address ? (0, import_sdk_core8.canonicalizeAddress)(sessionData.address) : void 0;
2152
2601
  if (restoredAddress) {
2153
2602
  this._address = restoredAddress;
2154
2603
  }
2155
2604
  if (sessionData.chainId) {
2156
2605
  this._chainId = sessionData.chainId;
2157
2606
  }
2158
- this._serviceContext = new import_sdk_core7.ServiceContext({
2607
+ const resolvedHost = await this.resolveRestoredHost(
2608
+ sessionData.tinycloudHosts,
2609
+ restoredAddress,
2610
+ sessionData.chainId
2611
+ );
2612
+ if (resolvedHost) {
2613
+ this.config.host = resolvedHost;
2614
+ }
2615
+ this._serviceContext = new import_sdk_core8.ServiceContext({
2159
2616
  invoke: this.invokeWithRuntimePermissions,
2160
2617
  invokeAny: this.invokeAnyWithRuntimePermissions,
2161
2618
  fetch: globalThis.fetch.bind(globalThis),
2162
2619
  hosts: [this.config.host],
2163
2620
  telemetry: this.config.telemetry
2164
2621
  });
2165
- this._kv = new import_sdk_core7.KVService({});
2622
+ this._kv = new import_sdk_core8.KVService({});
2166
2623
  this._kv.initialize(this._serviceContext);
2167
2624
  this._serviceContext.registerService("kv", this._kv);
2168
- this._sql = new import_sdk_core7.SQLService({});
2625
+ this._sql = new import_sdk_core8.SQLService({});
2169
2626
  this._sql.initialize(this._serviceContext);
2170
2627
  this._serviceContext.registerService("sql", this._sql);
2171
- this._duckdb = new import_sdk_core7.DuckDbService({});
2628
+ this._duckdb = new import_sdk_core8.DuckDbService({});
2172
2629
  this._duckdb.initialize(this._serviceContext);
2173
2630
  this._serviceContext.registerService("duckdb", this._duckdb);
2174
- this._hooks = new import_sdk_core7.HooksService({});
2631
+ this._hooks = new import_sdk_core8.HooksService({});
2175
2632
  this._hooks.initialize(this._serviceContext);
2176
2633
  this._serviceContext.registerService("hooks", this._hooks);
2177
2634
  const serviceSession = {
@@ -2200,12 +2657,45 @@ var _TinyCloudNode = class _TinyCloudNode {
2200
2657
  signature: sessionData.signature ?? ""
2201
2658
  };
2202
2659
  if (this.auth) {
2203
- this.auth.setRestoredTinyCloudSession(tcSession);
2660
+ this.auth.setRestoredTinyCloudSession(
2661
+ tcSession,
2662
+ this.config.host ? [this.config.host] : void 0
2663
+ );
2204
2664
  } else {
2205
2665
  this._restoredTcSession = tcSession;
2206
2666
  }
2207
2667
  }
2208
2668
  }
2669
+ /**
2670
+ * Resolve the host a restored session should target.
2671
+ *
2672
+ * Mirrors fresh sign-in host resolution but for the restore path:
2673
+ * an explicit/pinned host always wins, then the hosts the session was
2674
+ * persisted with, then a lazy registry/fallback resolution for sessions
2675
+ * that predate the persisted `tinycloudHosts` field. Returns `undefined`
2676
+ * only when there's nothing to resolve from (no explicit host, no
2677
+ * persisted hosts, and no address/chainId) — in which case the existing
2678
+ * `config.host` (default) is left in place.
2679
+ *
2680
+ * Resolution failures are surfaced, not swallowed: a genuinely broken
2681
+ * registry lookup throws rather than silently falling back to a wrong host.
2682
+ */
2683
+ async resolveRestoredHost(persistedHosts, address, chainId) {
2684
+ if (this.explicitHost) {
2685
+ return this.explicitHost;
2686
+ }
2687
+ if (persistedHosts && persistedHosts.length > 0) {
2688
+ return persistedHosts[0];
2689
+ }
2690
+ if (address === void 0 || chainId === void 0) {
2691
+ return void 0;
2692
+ }
2693
+ const resolved = await (0, import_sdk_core8.resolveTinyCloudHosts)((0, import_sdk_core8.pkhDid)(address, chainId), {
2694
+ registryUrl: this.config.tinycloudRegistryUrl,
2695
+ fallbackHosts: this.config.tinycloudFallbackHosts
2696
+ });
2697
+ return resolved.hosts[0];
2698
+ }
2209
2699
  /**
2210
2700
  * Resolve the currently-active TinyCloudSession, preferring the auth
2211
2701
  * layer's value (wallet mode) and falling back to the node-level
@@ -2250,9 +2740,11 @@ var _TinyCloudNode = class _TinyCloudNode {
2250
2740
  );
2251
2741
  }
2252
2742
  this.signer = _TinyCloudNode.nodeDefaults.createSigner(privateKey);
2743
+ const authConfig = { ...this.config, prefix };
2744
+ const useBootstrapSignInRequest = this.shouldUseBootstrapSignInRequest(authConfig);
2253
2745
  this.auth = new NodeUserAuthorization({
2254
2746
  signer: this.signer,
2255
- signStrategy: { type: "auto-sign" },
2747
+ signStrategy: this.config.signStrategy ?? { type: "auto-sign" },
2256
2748
  wasmBindings: this.wasmBindings,
2257
2749
  sessionStorage: options?.sessionStorage ?? this.config.sessionStorage ?? new MemorySessionStorage(),
2258
2750
  domain: this.siweDomain,
@@ -2261,16 +2753,16 @@ var _TinyCloudNode = class _TinyCloudNode {
2261
2753
  tinycloudHosts: this.explicitHost ? [this.explicitHost] : void 0,
2262
2754
  tinycloudRegistryUrl: this.config.tinycloudRegistryUrl,
2263
2755
  tinycloudFallbackHosts: this.config.tinycloudFallbackHosts,
2264
- autoCreateSpace: this.config.autoCreateSpace,
2756
+ autoCreateSpace: useBootstrapSignInRequest ? false : this.config.autoCreateSpace,
2265
2757
  enablePublicSpace: this.config.enablePublicSpace ?? true,
2266
- spaceCreationHandler: this.config.spaceCreationHandler,
2758
+ spaceCreationHandler: useBootstrapSignInRequest ? void 0 : this.config.spaceCreationHandler,
2267
2759
  nonce: this.config.nonce,
2268
2760
  siweConfig: this.config.siweConfig,
2269
- manifest: this.config.manifest,
2270
- capabilityRequest: this.config.capabilityRequest,
2271
- includeAccountRegistryPermissions: this.config.includeAccountRegistryPermissions
2761
+ manifest: useBootstrapSignInRequest ? void 0 : this.config.manifest,
2762
+ capabilityRequest: useBootstrapSignInRequest ? import_sdk_core8.BOOTSTRAP_SESSION_REQUESTS.default : this.config.capabilityRequest,
2763
+ includeAccountRegistryPermissions: useBootstrapSignInRequest ? false : this.config.includeAccountRegistryPermissions
2272
2764
  });
2273
- this.tc = new import_sdk_core7.TinyCloud(this.auth, {
2765
+ this.tc = new import_sdk_core8.TinyCloud(this.auth, {
2274
2766
  invokeAny: this.invokeAnyWithRuntimePermissions,
2275
2767
  telemetry: this.config.telemetry
2276
2768
  });
@@ -2295,9 +2787,11 @@ var _TinyCloudNode = class _TinyCloudNode {
2295
2787
  }
2296
2788
  const prefix = options?.prefix ?? "default";
2297
2789
  this.signer = signer;
2790
+ const authConfig = { ...this.config, prefix };
2791
+ const useBootstrapSignInRequest = this.shouldUseBootstrapSignInRequest(authConfig);
2298
2792
  this.auth = new NodeUserAuthorization({
2299
2793
  signer: this.signer,
2300
- signStrategy: { type: "auto-sign" },
2794
+ signStrategy: this.config.signStrategy ?? { type: "auto-sign" },
2301
2795
  wasmBindings: this.wasmBindings,
2302
2796
  sessionStorage: options?.sessionStorage ?? this.config.sessionStorage ?? new MemorySessionStorage(),
2303
2797
  domain: this.siweDomain,
@@ -2306,16 +2800,16 @@ var _TinyCloudNode = class _TinyCloudNode {
2306
2800
  tinycloudHosts: this.explicitHost ? [this.explicitHost] : void 0,
2307
2801
  tinycloudRegistryUrl: this.config.tinycloudRegistryUrl,
2308
2802
  tinycloudFallbackHosts: this.config.tinycloudFallbackHosts,
2309
- autoCreateSpace: this.config.autoCreateSpace,
2803
+ autoCreateSpace: useBootstrapSignInRequest ? false : this.config.autoCreateSpace,
2310
2804
  enablePublicSpace: this.config.enablePublicSpace ?? true,
2311
- spaceCreationHandler: this.config.spaceCreationHandler,
2805
+ spaceCreationHandler: useBootstrapSignInRequest ? void 0 : this.config.spaceCreationHandler,
2312
2806
  nonce: this.config.nonce,
2313
2807
  siweConfig: this.config.siweConfig,
2314
- manifest: this.config.manifest,
2315
- capabilityRequest: this.config.capabilityRequest,
2316
- includeAccountRegistryPermissions: this.config.includeAccountRegistryPermissions
2808
+ manifest: useBootstrapSignInRequest ? void 0 : this.config.manifest,
2809
+ capabilityRequest: useBootstrapSignInRequest ? import_sdk_core8.BOOTSTRAP_SESSION_REQUESTS.default : this.config.capabilityRequest,
2810
+ includeAccountRegistryPermissions: useBootstrapSignInRequest ? false : this.config.includeAccountRegistryPermissions
2317
2811
  });
2318
- this.tc = new import_sdk_core7.TinyCloud(this.auth, {
2812
+ this.tc = new import_sdk_core8.TinyCloud(this.auth, {
2319
2813
  invokeAny: this.invokeAnyWithRuntimePermissions,
2320
2814
  telemetry: this.config.telemetry
2321
2815
  });
@@ -2331,28 +2825,28 @@ var _TinyCloudNode = class _TinyCloudNode {
2331
2825
  return;
2332
2826
  }
2333
2827
  this.tc.initializeServices(this.invokeWithRuntimePermissions, [this.config.host]);
2334
- this._serviceContext = new import_sdk_core7.ServiceContext({
2828
+ this._serviceContext = new import_sdk_core8.ServiceContext({
2335
2829
  invoke: this.invokeWithRuntimePermissions,
2336
2830
  invokeAny: this.invokeAnyWithRuntimePermissions,
2337
2831
  fetch: globalThis.fetch.bind(globalThis),
2338
2832
  hosts: [this.config.host],
2339
2833
  telemetry: this.config.telemetry
2340
2834
  });
2341
- this._kv = new import_sdk_core7.KVService({});
2835
+ this._kv = new import_sdk_core8.KVService({});
2342
2836
  this._kv.initialize(this._serviceContext);
2343
2837
  this._serviceContext.registerService("kv", this._kv);
2344
2838
  const features = this.nodeFeatures;
2345
2839
  if (features.length === 0 || features.includes("sql")) {
2346
- this._sql = new import_sdk_core7.SQLService({});
2840
+ this._sql = new import_sdk_core8.SQLService({});
2347
2841
  this._sql.initialize(this._serviceContext);
2348
2842
  this._serviceContext.registerService("sql", this._sql);
2349
2843
  }
2350
2844
  if (features.length === 0 || features.includes("duckdb")) {
2351
- this._duckdb = new import_sdk_core7.DuckDbService({});
2845
+ this._duckdb = new import_sdk_core8.DuckDbService({});
2352
2846
  this._duckdb.initialize(this._serviceContext);
2353
2847
  this._serviceContext.registerService("duckdb", this._duckdb);
2354
2848
  }
2355
- this._hooks = new import_sdk_core7.HooksService({});
2849
+ this._hooks = new import_sdk_core8.HooksService({});
2356
2850
  this._hooks.initialize(this._serviceContext);
2357
2851
  this._serviceContext.registerService("hooks", this._hooks);
2358
2852
  const serviceSession = {
@@ -2370,9 +2864,9 @@ var _TinyCloudNode = class _TinyCloudNode {
2370
2864
  this.initializeV2Services(serviceSession);
2371
2865
  }
2372
2866
  createSpaceScopedKVService(spaceId) {
2373
- const kvService = new import_sdk_core7.KVService({});
2867
+ const kvService = new import_sdk_core8.KVService({});
2374
2868
  if (this._serviceContext) {
2375
- const spaceScopedContext = new import_sdk_core7.ServiceContext({
2869
+ const spaceScopedContext = new import_sdk_core8.ServiceContext({
2376
2870
  invoke: this._serviceContext.invoke,
2377
2871
  fetch: this._serviceContext.fetch,
2378
2872
  hosts: this._serviceContext.hosts,
@@ -2389,6 +2883,20 @@ var _TinyCloudNode = class _TinyCloudNode {
2389
2883
  getDefaultEncryptionNetworkId(name = DEFAULT_ENCRYPTION_NETWORK_NAME) {
2390
2884
  return `urn:tinycloud:encryption:${this.did}:${name}`;
2391
2885
  }
2886
+ getEncryptionNetworkIdForSpace(spaceId, name = DEFAULT_ENCRYPTION_NETWORK_NAME) {
2887
+ const ownerDid = this.ownerDidFromSpaceId(spaceId) ?? this.did;
2888
+ return `urn:tinycloud:encryption:${ownerDid}:${name}`;
2889
+ }
2890
+ ownerDidFromSpaceId(spaceId) {
2891
+ if (!spaceId.startsWith("tinycloud:")) return void 0;
2892
+ const body = spaceId.slice("tinycloud:".length);
2893
+ const lastSeparator = body.lastIndexOf(":");
2894
+ if (lastSeparator <= 0) return void 0;
2895
+ const owner = body.slice(0, lastSeparator);
2896
+ if (owner.startsWith("did:")) return owner;
2897
+ if (!owner.includes(":")) return void 0;
2898
+ return `did:${owner}`;
2899
+ }
2392
2900
  requireServiceSession() {
2393
2901
  const session = this._serviceContext?.session;
2394
2902
  if (!session) {
@@ -2437,7 +2945,7 @@ var _TinyCloudNode = class _TinyCloudNode {
2437
2945
  const shared = wasm.vault_x25519_dh(receiverPrivateKey, peerPublic);
2438
2946
  return columnDecrypt(shared, ciphertext);
2439
2947
  },
2440
- verifyNodeSignature: (nodeId, message, signature) => (0, import_sdk_core7.verifyDidKeyEd25519Signature)(nodeId, message, signature)
2948
+ verifyNodeSignature: (nodeId, message, signature) => (0, import_sdk_core8.verifyDidKeyEd25519Signature)(nodeId, message, signature)
2441
2949
  };
2442
2950
  }
2443
2951
  async fetchNodeId() {
@@ -2508,7 +3016,7 @@ var _TinyCloudNode = class _TinyCloudNode {
2508
3016
  return await response.json();
2509
3017
  }
2510
3018
  };
2511
- return new import_sdk_core7.EncryptionService({
3019
+ return new import_sdk_core8.EncryptionService({
2512
3020
  crypto,
2513
3021
  signer: {
2514
3022
  signDecryptInvocation: async (input) => {
@@ -2520,7 +3028,7 @@ var _TinyCloudNode = class _TinyCloudNode {
2520
3028
  });
2521
3029
  return {
2522
3030
  ...signed,
2523
- canonicalBody: (0, import_sdk_core7.canonicalizeEncryptionJson)(
3031
+ canonicalBody: (0, import_sdk_core8.canonicalizeEncryptionJson)(
2524
3032
  input.body
2525
3033
  )
2526
3034
  };
@@ -2538,8 +3046,8 @@ var _TinyCloudNode = class _TinyCloudNode {
2538
3046
  if (!this.config.host) {
2539
3047
  return null;
2540
3048
  }
2541
- const publicSpaceId = (0, import_sdk_core7.makePublicSpaceId)(this._address, this._chainId);
2542
- const result = await import_sdk_core7.TinyCloud.readPublicSpace(this.config.host, publicSpaceId, discoveryKey);
3049
+ const publicSpaceId = (0, import_sdk_core8.makePublicSpaceId)(this._address, this._chainId);
3050
+ const result = await import_sdk_core8.TinyCloud.readPublicSpace(this.config.host, publicSpaceId, discoveryKey);
2543
3051
  if (!result.ok) {
2544
3052
  return null;
2545
3053
  }
@@ -2562,7 +3070,7 @@ var _TinyCloudNode = class _TinyCloudNode {
2562
3070
  }
2563
3071
  createVaultService(spaceId, kv) {
2564
3072
  const wasm = this.wasmBindings;
2565
- const vaultCrypto = (0, import_sdk_core7.createVaultCrypto)({
3073
+ const vaultCrypto = (0, import_sdk_core8.createVaultCrypto)({
2566
3074
  vault_encrypt: wasm.vault_encrypt,
2567
3075
  vault_decrypt: wasm.vault_decrypt,
2568
3076
  vault_derive_key: wasm.vault_derive_key,
@@ -2572,11 +3080,11 @@ var _TinyCloudNode = class _TinyCloudNode {
2572
3080
  vault_sha256: wasm.vault_sha256
2573
3081
  });
2574
3082
  const self = this;
2575
- return new import_sdk_core7.DataVaultService({
3083
+ return new import_sdk_core8.DataVaultService({
2576
3084
  spaceId,
2577
3085
  crypto: vaultCrypto,
2578
3086
  encryption: {
2579
- networkId: this.getDefaultEncryptionNetworkId(),
3087
+ networkId: this.getEncryptionNetworkIdForSpace(spaceId),
2580
3088
  service: this.getEncryptionService(),
2581
3089
  decryptCapabilityProof: () => ({
2582
3090
  proofs: [this.requireServiceSession().delegationCid]
@@ -2595,8 +3103,8 @@ var _TinyCloudNode = class _TinyCloudNode {
2595
3103
  get publicKV() {
2596
3104
  return self._publicKV ?? self.tc.publicKV;
2597
3105
  },
2598
- readPublicSpace: (host, targetSpaceId, key) => import_sdk_core7.TinyCloud.readPublicSpace(host, targetSpaceId, key),
2599
- makePublicSpaceId: import_sdk_core7.TinyCloud.makePublicSpaceId,
3106
+ readPublicSpace: (host, targetSpaceId, key) => import_sdk_core8.TinyCloud.readPublicSpace(host, targetSpaceId, key),
3107
+ makePublicSpaceId: import_sdk_core8.TinyCloud.makePublicSpaceId,
2600
3108
  did: this.did,
2601
3109
  address: this._address ?? "",
2602
3110
  chainId: this._chainId,
@@ -2609,7 +3117,7 @@ var _TinyCloudNode = class _TinyCloudNode {
2609
3117
  * @internal
2610
3118
  */
2611
3119
  initializeV2Services(serviceSession) {
2612
- this._capabilityRegistry = new import_sdk_core7.CapabilityKeyRegistry();
3120
+ this._capabilityRegistry = new import_sdk_core8.CapabilityKeyRegistry();
2613
3121
  const tcSession = this.auth?.tinyCloudSession;
2614
3122
  if (tcSession && this._address) {
2615
3123
  const sessionKey = {
@@ -2683,13 +3191,13 @@ var _TinyCloudNode = class _TinyCloudNode {
2683
3191
  }
2684
3192
  this._capabilityRegistry.registerKey(sessionKey, delegations);
2685
3193
  }
2686
- this._delegationManager = new import_sdk_core7.DelegationManager({
3194
+ this._delegationManager = new import_sdk_core8.DelegationManager({
2687
3195
  hosts: [this.config.host],
2688
3196
  session: serviceSession,
2689
3197
  invoke: this.invokeWithRuntimePermissions,
2690
3198
  fetch: globalThis.fetch.bind(globalThis)
2691
3199
  });
2692
- this._spaceService = new import_sdk_core7.SpaceService({
3200
+ this._spaceService = new import_sdk_core8.SpaceService({
2693
3201
  hosts: [this.config.host],
2694
3202
  session: serviceSession,
2695
3203
  invoke: this.wasmBindings.invoke,
@@ -2707,6 +3215,9 @@ var _TinyCloudNode = class _TinyCloudNode {
2707
3215
  }
2708
3216
  return vaultService;
2709
3217
  },
3218
+ createSecretsService: (spaceId) => {
3219
+ return this.secretsForSpace(spaceId);
3220
+ },
2710
3221
  // Enable space.delegations.create() via SIWE-based delegation
2711
3222
  createDelegation: async (params) => {
2712
3223
  try {
@@ -2829,11 +3340,10 @@ var _TinyCloudNode = class _TinyCloudNode {
2829
3340
  try {
2830
3341
  const host = this.config.host;
2831
3342
  const now = /* @__PURE__ */ new Date();
2832
- const abilities = {
2833
- kv: {
2834
- [params.path]: params.actions
2835
- }
2836
- };
3343
+ const abilities = sharingActionsToAbilities(params.path, params.actions);
3344
+ if (!abilities) {
3345
+ return void 0;
3346
+ }
2837
3347
  const prepared = this.wasmBindings.prepareSession({
2838
3348
  abilities,
2839
3349
  address: this.wasmBindings.ensureEip55(session.address),
@@ -2849,7 +3359,7 @@ var _TinyCloudNode = class _TinyCloudNode {
2849
3359
  ...prepared,
2850
3360
  signature
2851
3361
  });
2852
- const activateResult = await (0, import_sdk_core7.activateSessionWithHost)(
3362
+ const activateResult = await (0, import_sdk_core8.activateSessionWithHost)(
2853
3363
  host,
2854
3364
  delegationSession.delegationHeader
2855
3365
  );
@@ -2859,7 +3369,7 @@ var _TinyCloudNode = class _TinyCloudNode {
2859
3369
  return {
2860
3370
  cid: delegationSession.delegationCid,
2861
3371
  delegateDID: params.shareKeyDID,
2862
- delegatorDID: (0, import_sdk_core7.pkhDid)(session.address, session.chainId),
3372
+ delegatorDID: (0, import_sdk_core8.pkhDid)(session.address, session.chainId),
2863
3373
  spaceId: params.spaceId,
2864
3374
  path: params.path,
2865
3375
  actions: params.actions,
@@ -2916,7 +3426,7 @@ var _TinyCloudNode = class _TinyCloudNode {
2916
3426
  if (!this._sql) {
2917
3427
  const features = this.nodeFeatures;
2918
3428
  if (features.length > 0 && !features.includes("sql")) {
2919
- throw new import_sdk_core7.UnsupportedFeatureError("sql", this.config.host, features);
3429
+ throw new import_sdk_core8.UnsupportedFeatureError("sql", this.config.host, features);
2920
3430
  }
2921
3431
  throw new Error("Not signed in. Call signIn() first.");
2922
3432
  }
@@ -2940,8 +3450,8 @@ var _TinyCloudNode = class _TinyCloudNode {
2940
3450
  if (!this._serviceContext || !this._serviceContext.session) {
2941
3451
  throw new Error("Not signed in. Call signIn() first.");
2942
3452
  }
2943
- const sql = new import_sdk_core7.SQLService({});
2944
- const spaceScopedContext = new import_sdk_core7.ServiceContext({
3453
+ const sql = new import_sdk_core8.SQLService({});
3454
+ const spaceScopedContext = new import_sdk_core8.ServiceContext({
2945
3455
  invoke: this._serviceContext.invoke,
2946
3456
  fetch: this._serviceContext.fetch,
2947
3457
  hosts: this._serviceContext.hosts,
@@ -2969,8 +3479,8 @@ var _TinyCloudNode = class _TinyCloudNode {
2969
3479
  if (!this._serviceContext || !this._serviceContext.session) {
2970
3480
  throw new Error("Not signed in. Call signIn() first.");
2971
3481
  }
2972
- const kv = new import_sdk_core7.KVService({});
2973
- const spaceScopedContext = new import_sdk_core7.ServiceContext({
3482
+ const kv = new import_sdk_core8.KVService({});
3483
+ const spaceScopedContext = new import_sdk_core8.ServiceContext({
2974
3484
  invoke: this._serviceContext.invoke,
2975
3485
  fetch: this._serviceContext.fetch,
2976
3486
  hosts: this._serviceContext.hosts
@@ -2986,7 +3496,7 @@ var _TinyCloudNode = class _TinyCloudNode {
2986
3496
  if (!this._duckdb) {
2987
3497
  const features = this.nodeFeatures;
2988
3498
  if (features.length > 0 && !features.includes("duckdb")) {
2989
- throw new import_sdk_core7.UnsupportedFeatureError("duckdb", this.config.host, features);
3499
+ throw new import_sdk_core8.UnsupportedFeatureError("duckdb", this.config.host, features);
2990
3500
  }
2991
3501
  throw new Error("Not signed in. Call signIn() first.");
2992
3502
  }
@@ -3038,7 +3548,7 @@ var _TinyCloudNode = class _TinyCloudNode {
3038
3548
  type: NETWORK_ADMIN_TYPE,
3039
3549
  targetNode,
3040
3550
  networkId,
3041
- bodyHash: (0, import_sdk_core7.canonicalHashHex)(
3551
+ bodyHash: (0, import_sdk_core8.canonicalHashHex)(
3042
3552
  crypto.sha256,
3043
3553
  body
3044
3554
  ),
@@ -3056,7 +3566,7 @@ var _TinyCloudNode = class _TinyCloudNode {
3056
3566
  Authorization: signed.authorization,
3057
3567
  "Content-Type": "application/json"
3058
3568
  },
3059
- body: (0, import_sdk_core7.canonicalizeEncryptionJson)(
3569
+ body: (0, import_sdk_core8.canonicalizeEncryptionJson)(
3060
3570
  body
3061
3571
  )
3062
3572
  });
@@ -3074,7 +3584,7 @@ var _TinyCloudNode = class _TinyCloudNode {
3074
3584
  if (existing) {
3075
3585
  return existing;
3076
3586
  }
3077
- const parsed = (0, import_sdk_core7.parseNetworkId)(networkId);
3587
+ const parsed = (0, import_sdk_core8.parseNetworkId)(networkId);
3078
3588
  if (!didPrincipalMatches2(parsed.ownerDid, this.did)) {
3079
3589
  throw new Error(
3080
3590
  `Cannot create encryption network ${networkId}: owner ${parsed.ownerDid} does not match signed-in DID ${this.did}`
@@ -3089,27 +3599,49 @@ var _TinyCloudNode = class _TinyCloudNode {
3089
3599
  if (!this._spaceService) {
3090
3600
  throw new Error("Not signed in. Call signIn() first.");
3091
3601
  }
3092
- if (!this._secrets) {
3093
- this._secrets = new NodeSecretsService({
3094
- getService: () => this.getBaseSecrets(),
3602
+ return this.secretsForSpace("secrets");
3603
+ }
3604
+ /**
3605
+ * App-facing secrets API backed by the requested space's vault.
3606
+ */
3607
+ secretsForSpace(spaceId) {
3608
+ if (!this._spaceService) {
3609
+ throw new Error("Not signed in. Call signIn() first.");
3610
+ }
3611
+ const resolvedSpace = spaceId.startsWith("tinycloud:") ? spaceId : this.ownedSpaceId(spaceId);
3612
+ let secrets = this._secrets.get(resolvedSpace);
3613
+ if (!secrets) {
3614
+ secrets = new NodeSecretsService({
3615
+ getService: () => this.getBaseSecrets(resolvedSpace),
3616
+ space: resolvedSpace,
3095
3617
  getManifest: () => this.manifest,
3096
3618
  hasPermissions: (permissions) => this.hasRuntimePermissions(permissions),
3097
3619
  grantPermissions: (additional) => this.grantRuntimePermissions(additional),
3098
3620
  canEscalate: () => this.signer !== void 0 && this.tc !== void 0,
3099
- getEncryptionNetworkId: () => this.getDefaultEncryptionNetworkId(),
3621
+ getEncryptionNetworkId: () => this.getEncryptionNetworkIdForSpace(resolvedSpace),
3622
+ resolveSpace: (space) => space.startsWith("tinycloud:") ? space : this.ownedSpaceId(space),
3100
3623
  getUnlockSigner: () => this.signer ?? void 0
3101
3624
  });
3625
+ this._secrets.set(resolvedSpace, secrets);
3102
3626
  }
3103
- return this._secrets;
3627
+ return secrets;
3104
3628
  }
3105
- getBaseSecrets() {
3629
+ getBaseSecrets(spaceId) {
3106
3630
  if (!this._spaceService) {
3107
3631
  throw new Error("Not signed in. Call signIn() first.");
3108
3632
  }
3109
- if (!this._baseSecrets) {
3110
- this._baseSecrets = new import_sdk_core7.SecretsService(() => this.space("secrets").vault);
3633
+ const resolvedSpace = spaceId.startsWith("tinycloud:") ? spaceId : this.ownedSpaceId(spaceId);
3634
+ let secrets = this._baseSecrets.get(resolvedSpace);
3635
+ if (!secrets) {
3636
+ const kvService = this.createSpaceScopedKVService(resolvedSpace);
3637
+ const vaultService = this.createVaultService(resolvedSpace, kvService);
3638
+ if (this._serviceContext) {
3639
+ vaultService.initialize(this._serviceContext);
3640
+ }
3641
+ secrets = new import_sdk_core8.SecretsService(() => vaultService);
3642
+ this._baseSecrets.set(resolvedSpace, secrets);
3111
3643
  }
3112
- return this._baseSecrets;
3644
+ return secrets;
3113
3645
  }
3114
3646
  /**
3115
3647
  * Hooks write stream subscription API.
@@ -3222,10 +3754,10 @@ var _TinyCloudNode = class _TinyCloudNode {
3222
3754
  async useRuntimeDelegation(delegation) {
3223
3755
  const session = this.currentTinyCloudSession();
3224
3756
  if (!session) {
3225
- throw new import_sdk_core7.SessionExpiredError(/* @__PURE__ */ new Date(0));
3757
+ throw new import_sdk_core8.SessionExpiredError(/* @__PURE__ */ new Date(0));
3226
3758
  }
3227
3759
  if (delegation.expiry.getTime() <= Date.now()) {
3228
- throw new import_sdk_core7.SessionExpiredError(delegation.expiry);
3760
+ throw new import_sdk_core8.SessionExpiredError(delegation.expiry);
3229
3761
  }
3230
3762
  const expectedDids = [session.verificationMethod, this.sessionDid];
3231
3763
  if (!expectedDids.some((did) => didPrincipalMatches2(delegation.delegateDID, did))) {
@@ -3234,7 +3766,7 @@ var _TinyCloudNode = class _TinyCloudNode {
3234
3766
  );
3235
3767
  }
3236
3768
  const targetHost = delegation.host ?? this.config.host;
3237
- const activateResult = await (0, import_sdk_core7.activateSessionWithHost)(
3769
+ const activateResult = await (0, import_sdk_core8.activateSessionWithHost)(
3238
3770
  targetHost,
3239
3771
  delegation.delegationHeader
3240
3772
  );
@@ -3261,13 +3793,13 @@ var _TinyCloudNode = class _TinyCloudNode {
3261
3793
  }
3262
3794
  const session = this.currentTinyCloudSession();
3263
3795
  if (!session) {
3264
- throw new import_sdk_core7.SessionExpiredError(/* @__PURE__ */ new Date(0));
3796
+ throw new import_sdk_core8.SessionExpiredError(/* @__PURE__ */ new Date(0));
3265
3797
  }
3266
3798
  const sessionExpiry = extractSiweExpiration(session.siwe);
3267
3799
  if (sessionExpiry !== void 0) {
3268
3800
  const marginMs = _TinyCloudNode.SESSION_EXPIRY_SAFETY_MARGIN_MS;
3269
3801
  if (sessionExpiry.getTime() <= Date.now() + marginMs) {
3270
- throw new import_sdk_core7.SessionExpiredError(sessionExpiry);
3802
+ throw new import_sdk_core8.SessionExpiredError(sessionExpiry);
3271
3803
  }
3272
3804
  }
3273
3805
  const expanded = this.expandPermissionEntries(permissions);
@@ -3330,7 +3862,7 @@ var _TinyCloudNode = class _TinyCloudNode {
3330
3862
  ...prepared,
3331
3863
  signature
3332
3864
  });
3333
- const activateResult = await (0, import_sdk_core7.activateSessionWithHost)(
3865
+ const activateResult = await (0, import_sdk_core8.activateSessionWithHost)(
3334
3866
  this.config.host,
3335
3867
  delegatedSession.delegationHeader
3336
3868
  );
@@ -3503,7 +4035,7 @@ var _TinyCloudNode = class _TinyCloudNode {
3503
4035
  ];
3504
4036
  const abilities = { kv: { "": kvActions } };
3505
4037
  const now = /* @__PURE__ */ new Date();
3506
- const expiryMs = import_sdk_core7.EXPIRY.EPHEMERAL_MS;
4038
+ const expiryMs = import_sdk_core8.EXPIRY.EPHEMERAL_MS;
3507
4039
  const expirationTime = new Date(now.getTime() + expiryMs);
3508
4040
  const prepared = this.wasmBindings.prepareSession({
3509
4041
  abilities,
@@ -3521,7 +4053,7 @@ var _TinyCloudNode = class _TinyCloudNode {
3521
4053
  ...prepared,
3522
4054
  signature
3523
4055
  });
3524
- const activateResult = await (0, import_sdk_core7.activateSessionWithHost)(
4056
+ const activateResult = await (0, import_sdk_core8.activateSessionWithHost)(
3525
4057
  this.config.host,
3526
4058
  delegationSession.delegationHeader
3527
4059
  );
@@ -3548,8 +4080,8 @@ var _TinyCloudNode = class _TinyCloudNode {
3548
4080
  }]);
3549
4081
  }
3550
4082
  if (this._serviceContext) {
3551
- const publicKV = new import_sdk_core7.KVService({ prefix: "" });
3552
- const publicContext = new import_sdk_core7.ServiceContext({
4083
+ const publicKV = new import_sdk_core8.KVService({ prefix: "" });
4084
+ const publicContext = new import_sdk_core8.ServiceContext({
3553
4085
  invoke: this.invokeWithRuntimePermissions,
3554
4086
  fetch: this._serviceContext.fetch,
3555
4087
  hosts: this._serviceContext.hosts,
@@ -3676,14 +4208,14 @@ var _TinyCloudNode = class _TinyCloudNode {
3676
4208
  async delegateTo(did, permissions, options) {
3677
4209
  const session = this.currentTinyCloudSession();
3678
4210
  if (!session) {
3679
- throw new import_sdk_core7.SessionExpiredError(/* @__PURE__ */ new Date(0));
4211
+ throw new import_sdk_core8.SessionExpiredError(/* @__PURE__ */ new Date(0));
3680
4212
  }
3681
4213
  const sessionExpiry = extractSiweExpiration(session.siwe);
3682
4214
  if (sessionExpiry !== void 0) {
3683
4215
  const now2 = Date.now();
3684
4216
  const marginMs = _TinyCloudNode.SESSION_EXPIRY_SAFETY_MARGIN_MS;
3685
4217
  if (sessionExpiry.getTime() <= now2 + marginMs) {
3686
- throw new import_sdk_core7.SessionExpiredError(sessionExpiry);
4218
+ throw new import_sdk_core8.SessionExpiredError(sessionExpiry);
3687
4219
  }
3688
4220
  }
3689
4221
  if (!Array.isArray(permissions) || permissions.length === 0) {
@@ -3712,11 +4244,11 @@ var _TinyCloudNode = class _TinyCloudNode {
3712
4244
  );
3713
4245
  return { delegation: delegation2, prompted: true };
3714
4246
  }
3715
- const granted = (0, import_sdk_core7.parseRecapCapabilities)(
4247
+ const granted = (0, import_sdk_core8.parseRecapCapabilities)(
3716
4248
  (siwe) => this.wasmBindings.parseRecapFromSiwe(siwe),
3717
4249
  session.siwe
3718
4250
  );
3719
- const { subset, missing } = (0, import_sdk_core7.isCapabilitySubset)(expandedEntries, granted);
4251
+ const { subset, missing } = (0, import_sdk_core8.isCapabilitySubset)(expandedEntries, granted);
3720
4252
  if (!subset) {
3721
4253
  const runtimeGrant = this.findGrantForOperations(
3722
4254
  this.permissionEntriesToOperations(expandedEntries, session)
@@ -3724,7 +4256,7 @@ var _TinyCloudNode = class _TinyCloudNode {
3724
4256
  if (runtimeGrant) {
3725
4257
  const marginMs = _TinyCloudNode.SESSION_EXPIRY_SAFETY_MARGIN_MS;
3726
4258
  if (runtimeGrant.expiresAt.getTime() <= Date.now() + marginMs) {
3727
- throw new import_sdk_core7.SessionExpiredError(runtimeGrant.expiresAt);
4259
+ throw new import_sdk_core8.SessionExpiredError(runtimeGrant.expiresAt);
3728
4260
  }
3729
4261
  const runtimeExpiration = runtimeGrant.expiresAt < effectiveExpiration ? runtimeGrant.expiresAt : effectiveExpiration;
3730
4262
  const delegation2 = await this.createDelegationViaRuntimeGrant(
@@ -3735,7 +4267,7 @@ var _TinyCloudNode = class _TinyCloudNode {
3735
4267
  );
3736
4268
  return { delegation: delegation2, prompted: false };
3737
4269
  }
3738
- throw new import_sdk_core7.PermissionNotInManifestError(missing, granted);
4270
+ throw new import_sdk_core8.PermissionNotInManifestError(missing, granted);
3739
4271
  }
3740
4272
  const delegation = await this.createDelegationViaWasmPath(
3741
4273
  did,
@@ -3817,7 +4349,7 @@ var _TinyCloudNode = class _TinyCloudNode {
3817
4349
  const spaceId = resolvedSpaces.size === 1 ? [...resolvedSpaces][0] : session.spaceId;
3818
4350
  const abilities = {};
3819
4351
  for (const entry of entries) {
3820
- const shortService = import_sdk_core7.SERVICE_LONG_TO_SHORT[entry.service];
4352
+ const shortService = import_sdk_core8.SERVICE_LONG_TO_SHORT[entry.service];
3821
4353
  if (shortService === void 0) {
3822
4354
  throw new Error(
3823
4355
  `delegateTo: unknown service '${entry.service}' \u2014 no short-form mapping`
@@ -3857,7 +4389,7 @@ var _TinyCloudNode = class _TinyCloudNode {
3857
4389
  });
3858
4390
  const primary = result.resources[0];
3859
4391
  const delegationHeader = { Authorization: result.delegation };
3860
- const activateResult = await (0, import_sdk_core7.activateSessionWithHost)(
4392
+ const activateResult = await (0, import_sdk_core8.activateSessionWithHost)(
3861
4393
  this.config.host,
3862
4394
  delegationHeader
3863
4395
  );
@@ -3892,7 +4424,7 @@ var _TinyCloudNode = class _TinyCloudNode {
3892
4424
  const primary = result.resources[0];
3893
4425
  const delegationHeader = { Authorization: result.delegation };
3894
4426
  const targetHost = grant.delegation.host ?? this.config.host;
3895
- const activateResult = await (0, import_sdk_core7.activateSessionWithHost)(
4427
+ const activateResult = await (0, import_sdk_core8.activateSessionWithHost)(
3896
4428
  targetHost,
3897
4429
  delegationHeader
3898
4430
  );
@@ -3933,10 +4465,10 @@ var _TinyCloudNode = class _TinyCloudNode {
3933
4465
  return this.wasmBindings.makeSpaceId(session.address, session.chainId, space);
3934
4466
  }
3935
4467
  expandPermissionEntries(permissions) {
3936
- return (0, import_sdk_core7.expandPermissionEntries)(permissions);
4468
+ return (0, import_sdk_core8.expandPermissionEntries)(permissions);
3937
4469
  }
3938
4470
  shortServiceName(service) {
3939
- const short = import_sdk_core7.SERVICE_LONG_TO_SHORT[service];
4471
+ const short = import_sdk_core8.SERVICE_LONG_TO_SHORT[service];
3940
4472
  if (short === void 0) {
3941
4473
  throw new Error(
3942
4474
  `unknown service '${service}' \u2014 no short-form mapping`
@@ -3962,7 +4494,7 @@ var _TinyCloudNode = class _TinyCloudNode {
3962
4494
  return abilities;
3963
4495
  }
3964
4496
  isEncryptionPermissionEntry(entry) {
3965
- return entry.service === import_sdk_core7.ENCRYPTION_PERMISSION_SERVICE && entry.path.startsWith("urn:tinycloud:encryption:");
4497
+ return entry.service === import_sdk_core8.ENCRYPTION_PERMISSION_SERVICE && entry.path.startsWith("urn:tinycloud:encryption:");
3966
4498
  }
3967
4499
  permissionsToRawAbilities(entries) {
3968
4500
  const rawAbilities = {};
@@ -3995,11 +4527,11 @@ var _TinyCloudNode = class _TinyCloudNode {
3995
4527
  }
3996
4528
  sessionCoversPermissionEntries(session, entries) {
3997
4529
  try {
3998
- const granted = (0, import_sdk_core7.parseRecapCapabilities)(
4530
+ const granted = (0, import_sdk_core8.parseRecapCapabilities)(
3999
4531
  (siwe) => this.wasmBindings.parseRecapFromSiwe(siwe),
4000
4532
  session.siwe
4001
4533
  );
4002
- return (0, import_sdk_core7.isCapabilitySubset)(entries, granted).subset;
4534
+ return (0, import_sdk_core8.isCapabilitySubset)(entries, granted).subset;
4003
4535
  } catch {
4004
4536
  return false;
4005
4537
  }
@@ -4330,7 +4862,7 @@ var _TinyCloudNode = class _TinyCloudNode {
4330
4862
  if (resolvedDelegateDID.endsWith(".eth") && this.config.ensResolver) {
4331
4863
  const address = await this.config.ensResolver.resolveAddress(resolvedDelegateDID);
4332
4864
  if (!address) throw new Error(`Could not resolve ENS name: ${resolvedDelegateDID}`);
4333
- resolvedDelegateDID = (0, import_sdk_core7.pkhDid)(address, 1);
4865
+ resolvedDelegateDID = (0, import_sdk_core8.pkhDid)(address, 1);
4334
4866
  }
4335
4867
  const entries = legacyParamsToPermissionEntries(
4336
4868
  params.actions,
@@ -4345,7 +4877,7 @@ var _TinyCloudNode = class _TinyCloudNode {
4345
4877
  );
4346
4878
  return result.delegation;
4347
4879
  } catch (err) {
4348
- if (err instanceof import_sdk_core7.PermissionNotInManifestError) {
4880
+ if (err instanceof import_sdk_core8.PermissionNotInManifestError) {
4349
4881
  } else {
4350
4882
  throw err;
4351
4883
  }
@@ -4402,7 +4934,7 @@ var _TinyCloudNode = class _TinyCloudNode {
4402
4934
  ...prepared,
4403
4935
  signature
4404
4936
  });
4405
- const activateResult = await (0, import_sdk_core7.activateSessionWithHost)(
4937
+ const activateResult = await (0, import_sdk_core8.activateSessionWithHost)(
4406
4938
  this.config.host,
4407
4939
  delegationSession.delegationHeader
4408
4940
  );
@@ -4424,7 +4956,7 @@ var _TinyCloudNode = class _TinyCloudNode {
4424
4956
  };
4425
4957
  const hasKvActions = params.actions.some((a) => a.startsWith("tinycloud.kv/"));
4426
4958
  if (hasKvActions && params.includePublicSpace !== false) {
4427
- const publicSpaceId = (0, import_sdk_core7.makePublicSpaceId)(
4959
+ const publicSpaceId = (0, import_sdk_core8.makePublicSpaceId)(
4428
4960
  this.wasmBindings.ensureEip55(session.address),
4429
4961
  session.chainId
4430
4962
  );
@@ -4447,7 +4979,7 @@ var _TinyCloudNode = class _TinyCloudNode {
4447
4979
  ...publicPrepared,
4448
4980
  signature: publicSignature
4449
4981
  });
4450
- const publicActivateResult = await (0, import_sdk_core7.activateSessionWithHost)(
4982
+ const publicActivateResult = await (0, import_sdk_core8.activateSessionWithHost)(
4451
4983
  this.config.host,
4452
4984
  publicSession.delegationHeader
4453
4985
  );
@@ -4523,6 +5055,7 @@ var _TinyCloudNode = class _TinyCloudNode {
4523
5055
  delegation,
4524
5056
  targetHost,
4525
5057
  this.wasmBindings.invoke,
5058
+ this.wasmBindings.invokeAny,
4526
5059
  this.config.telemetry
4527
5060
  );
4528
5061
  }
@@ -4552,7 +5085,7 @@ var _TinyCloudNode = class _TinyCloudNode {
4552
5085
  ...prepared,
4553
5086
  signature
4554
5087
  });
4555
- const activateResult = await (0, import_sdk_core7.activateSessionWithHost)(
5088
+ const activateResult = await (0, import_sdk_core8.activateSessionWithHost)(
4556
5089
  targetHost,
4557
5090
  invokerSession.delegationHeader
4558
5091
  );
@@ -4588,6 +5121,7 @@ var _TinyCloudNode = class _TinyCloudNode {
4588
5121
  delegation,
4589
5122
  targetHost,
4590
5123
  this.wasmBindings.invoke,
5124
+ this.wasmBindings.invokeAny,
4591
5125
  this.config.telemetry
4592
5126
  );
4593
5127
  }
@@ -4658,7 +5192,7 @@ var _TinyCloudNode = class _TinyCloudNode {
4658
5192
  ...prepared,
4659
5193
  signature
4660
5194
  });
4661
- const activateResult = await (0, import_sdk_core7.activateSessionWithHost)(
5195
+ const activateResult = await (0, import_sdk_core8.activateSessionWithHost)(
4662
5196
  targetHost,
4663
5197
  subDelegationSession.delegationHeader
4664
5198
  );
@@ -4694,7 +5228,7 @@ _TinyCloudNode.SESSION_EXPIRY_SAFETY_MARGIN_MS = 6e4;
4694
5228
  var TinyCloudNode = _TinyCloudNode;
4695
5229
 
4696
5230
  // src/core.ts
4697
- var import_sdk_core10 = require("@tinycloud/sdk-core");
5231
+ var import_sdk_core11 = require("@tinycloud/sdk-core");
4698
5232
 
4699
5233
  // src/delegation.ts
4700
5234
  function serializeDelegation(delegation) {
@@ -4713,7 +5247,6 @@ function deserializeDelegation(data) {
4713
5247
  }
4714
5248
 
4715
5249
  // src/core.ts
4716
- var import_sdk_core11 = require("@tinycloud/sdk-core");
4717
5250
  var import_sdk_core12 = require("@tinycloud/sdk-core");
4718
5251
  var import_sdk_core13 = require("@tinycloud/sdk-core");
4719
5252
  var import_sdk_core14 = require("@tinycloud/sdk-core");
@@ -4722,6 +5255,7 @@ var import_sdk_core16 = require("@tinycloud/sdk-core");
4722
5255
  var import_sdk_core17 = require("@tinycloud/sdk-core");
4723
5256
  var import_sdk_core18 = require("@tinycloud/sdk-core");
4724
5257
  var import_sdk_core19 = require("@tinycloud/sdk-core");
5258
+ var import_sdk_core20 = require("@tinycloud/sdk-core");
4725
5259
  // Annotate the CommonJS export names for ESM import in node:
4726
5260
  0 && (module.exports = {
4727
5261
  ACCOUNT_REGISTRY_PATH,
@@ -4762,6 +5296,7 @@ var import_sdk_core19 = require("@tinycloud/sdk-core");
4762
5296
  SpaceErrorCodes,
4763
5297
  SpaceService,
4764
5298
  TinyCloud,
5299
+ TinyCloudDebugLogger,
4765
5300
  TinyCloudNode,
4766
5301
  UnsupportedFeatureError,
4767
5302
  VAULT_PERMISSION_SERVICE,
@@ -4777,8 +5312,10 @@ var import_sdk_core19 = require("@tinycloud/sdk-core");
4777
5312
  canonicalizeNetworkId,
4778
5313
  canonicalizeSecretScope,
4779
5314
  checkNodeInfo,
5315
+ clearTinyCloudDebugLogs,
4780
5316
  composeManifestRequest,
4781
5317
  createCapabilityKeyRegistry,
5318
+ createOpenKeyCallbackSigningStrategy,
4782
5319
  createSharingService,
4783
5320
  createSpaceService,
4784
5321
  createVaultCrypto,
@@ -4788,9 +5325,13 @@ var import_sdk_core19 = require("@tinycloud/sdk-core");
4788
5325
  deserializeDelegation,
4789
5326
  didCacheKey,
4790
5327
  didEquals,
5328
+ disableTinyCloudDebug,
5329
+ enableTinyCloudDebug,
4791
5330
  expandActionShortNames,
4792
5331
  expandPermissionEntries,
4793
5332
  expandPermissionEntry,
5333
+ getTinyCloudDebugLogs,
5334
+ installTinyCloudDebugGlobals,
4794
5335
  isCapabilitySubset,
4795
5336
  isEvmAddress,
4796
5337
  loadManifest,
@@ -4808,6 +5349,7 @@ var import_sdk_core19 = require("@tinycloud/sdk-core");
4808
5349
  resolveSecretPath,
4809
5350
  resourceCapabilitiesToSpaceAbilitiesMap,
4810
5351
  serializeDelegation,
5352
+ tinyCloudDebugLogger,
4811
5353
  validateManifest
4812
5354
  });
4813
5355
  //# sourceMappingURL=core.cjs.map