@tinycloud/node-sdk 2.3.1-beta.0 → 2.4.0-beta.10

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,94 +30,95 @@ 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_core9.ACCOUNT_REGISTRY_PATH,
34
- ACCOUNT_REGISTRY_SPACE: () => import_sdk_core9.ACCOUNT_REGISTRY_SPACE,
35
- AutoApproveSpaceCreationHandler: () => import_sdk_core8.AutoApproveSpaceCreationHandler,
36
- CapabilityKeyRegistry: () => import_sdk_core15.CapabilityKeyRegistry,
37
- CapabilityKeyRegistryErrorCodes: () => import_sdk_core15.CapabilityKeyRegistryErrorCodes,
38
- DEFAULT_MANIFEST_SPACE: () => import_sdk_core9.DEFAULT_MANIFEST_SPACE,
39
- DEFAULT_MANIFEST_VERSION: () => import_sdk_core9.DEFAULT_MANIFEST_VERSION,
40
- DEFAULT_SIGNED_READ_URL_EXPIRY_MS: () => import_sdk_core10.DEFAULT_SIGNED_READ_URL_EXPIRY_MS,
41
- DataVaultService: () => import_sdk_core13.DataVaultService,
42
- DatabaseHandle: () => import_sdk_core11.DatabaseHandle,
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,
43
44
  DelegatedAccess: () => DelegatedAccess,
44
- DelegationErrorCodes: () => import_sdk_core14.DelegationErrorCodes,
45
- DelegationManager: () => import_sdk_core14.DelegationManager,
46
- DuckDbAction: () => import_sdk_core12.DuckDbAction,
47
- DuckDbDatabaseHandle: () => import_sdk_core12.DuckDbDatabaseHandle,
48
- DuckDbService: () => import_sdk_core12.DuckDbService,
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,
49
50
  FileSessionStorage: () => FileSessionStorage,
50
- IdentityParseError: () => import_sdk_core8.IdentityParseError,
51
- KVService: () => import_sdk_core10.KVService,
52
- ManifestValidationError: () => import_sdk_core9.ManifestValidationError,
51
+ IdentityParseError: () => import_sdk_core9.IdentityParseError,
52
+ KVService: () => import_sdk_core11.KVService,
53
+ ManifestValidationError: () => import_sdk_core10.ManifestValidationError,
53
54
  MemorySessionStorage: () => MemorySessionStorage,
54
55
  NodeUserAuthorization: () => NodeUserAuthorization,
55
- PermissionNotInManifestError: () => import_sdk_core9.PermissionNotInManifestError,
56
- PrefixedKVService: () => import_sdk_core10.PrefixedKVService,
57
- ProtocolMismatchError: () => import_sdk_core17.ProtocolMismatchError,
58
- SECRET_NAME_RE: () => import_sdk_core13.SECRET_NAME_RE,
59
- SQLAction: () => import_sdk_core11.SQLAction,
60
- SQLService: () => import_sdk_core11.SQLService,
61
- SecretsService: () => import_sdk_core13.SecretsService,
62
- ServiceContext: () => import_sdk_core18.ServiceContext,
63
- SessionExpiredError: () => import_sdk_core9.SessionExpiredError,
64
- SharingService: () => import_sdk_core14.SharingService,
65
- SilentNotificationHandler: () => import_sdk_core8.SilentNotificationHandler,
66
- Space: () => import_sdk_core16.Space,
67
- SpaceErrorCodes: () => import_sdk_core16.SpaceErrorCodes,
68
- SpaceService: () => import_sdk_core16.SpaceService,
69
- TinyCloud: () => import_sdk_core7.TinyCloud,
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,
70
71
  TinyCloudNode: () => TinyCloudNode,
71
- UnsupportedFeatureError: () => import_sdk_core17.UnsupportedFeatureError,
72
- VAULT_PERMISSION_SERVICE: () => import_sdk_core9.VAULT_PERMISSION_SERVICE,
73
- VaultHeaders: () => import_sdk_core13.VaultHeaders,
74
- VaultPublicSpaceKVActions: () => import_sdk_core13.VaultPublicSpaceKVActions,
75
- VersionCheckError: () => import_sdk_core17.VersionCheckError,
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,
76
77
  WasmKeyProvider: () => WasmKeyProvider,
77
- addressStorageKey: () => import_sdk_core8.addressStorageKey,
78
- buildSpaceUri: () => import_sdk_core16.buildSpaceUri,
79
- canonicalizeAddress: () => import_sdk_core8.canonicalizeAddress,
80
- canonicalizeDid: () => import_sdk_core8.canonicalizeDid,
81
- canonicalizeDidUrl: () => import_sdk_core8.canonicalizeDidUrl,
82
- canonicalizeNetworkId: () => import_sdk_core8.canonicalizeNetworkId,
83
- canonicalizeSecretScope: () => import_sdk_core13.canonicalizeSecretScope,
84
- checkNodeInfo: () => import_sdk_core17.checkNodeInfo,
85
- composeManifestRequest: () => import_sdk_core9.composeManifestRequest,
86
- createCapabilityKeyRegistry: () => import_sdk_core15.createCapabilityKeyRegistry,
87
- createSharingService: () => import_sdk_core14.createSharingService,
88
- createSpaceService: () => import_sdk_core16.createSpaceService,
89
- createVaultCrypto: () => import_sdk_core13.createVaultCrypto,
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,
90
91
  createWasmKeyProvider: () => createWasmKeyProvider,
91
92
  defaultSignStrategy: () => defaultSignStrategy,
92
- defaultSpaceCreationHandler: () => import_sdk_core8.defaultSpaceCreationHandler,
93
+ defaultSpaceCreationHandler: () => import_sdk_core9.defaultSpaceCreationHandler,
93
94
  deserializeDelegation: () => deserializeDelegation,
94
- didCacheKey: () => import_sdk_core8.didCacheKey,
95
- didEquals: () => import_sdk_core8.didEquals,
96
- expandActionShortNames: () => import_sdk_core9.expandActionShortNames,
97
- expandPermissionEntries: () => import_sdk_core9.expandPermissionEntries,
98
- expandPermissionEntry: () => import_sdk_core9.expandPermissionEntry,
99
- isCapabilitySubset: () => import_sdk_core9.isCapabilitySubset,
100
- isEvmAddress: () => import_sdk_core8.isEvmAddress,
101
- loadManifest: () => import_sdk_core9.loadManifest,
102
- makePkhSpaceId: () => import_sdk_core8.makePkhSpaceId,
103
- makePublicSpaceId: () => import_sdk_core16.makePublicSpaceId,
104
- parseCanonicalNetworkId: () => import_sdk_core8.parseCanonicalNetworkId,
105
- parseExpiry: () => import_sdk_core9.parseExpiry,
106
- parsePkhDid: () => import_sdk_core8.parsePkhDid,
107
- parseSpaceUri: () => import_sdk_core16.parseSpaceUri,
108
- pkhDid: () => import_sdk_core8.pkhDid,
109
- principalDid: () => import_sdk_core8.principalDid,
110
- principalDidEquals: () => import_sdk_core8.principalDidEquals,
111
- resolveManifest: () => import_sdk_core9.resolveManifest,
112
- resolveSecretListPrefix: () => import_sdk_core13.resolveSecretListPrefix,
113
- resolveSecretPath: () => import_sdk_core13.resolveSecretPath,
114
- resourceCapabilitiesToSpaceAbilitiesMap: () => import_sdk_core9.resourceCapabilitiesToSpaceAbilitiesMap,
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,
115
116
  serializeDelegation: () => serializeDelegation,
116
- validateManifest: () => import_sdk_core9.validateManifest
117
+ validateManifest: () => import_sdk_core10.validateManifest
117
118
  });
118
119
  module.exports = __toCommonJS(core_exports);
119
- var import_sdk_core7 = require("@tinycloud/sdk-core");
120
120
  var import_sdk_core8 = require("@tinycloud/sdk-core");
121
+ var import_sdk_core9 = require("@tinycloud/sdk-core");
121
122
 
122
123
  // src/storage/MemorySessionStorage.ts
123
124
  var MemorySessionStorage = class {
@@ -317,6 +318,25 @@ var import_sdk_core2 = require("@tinycloud/sdk-core");
317
318
  var defaultSignStrategy = { type: "auto-sign" };
318
319
 
319
320
  // src/authorization/NodeUserAuthorization.ts
321
+ var DECRYPT_ACTION = "tinycloud.encryption/decrypt";
322
+ var NETWORK_CREATE_ACTION = "tinycloud.encryption/network.create";
323
+ function didPrincipalMatches(actual, expected) {
324
+ try {
325
+ return (0, import_sdk_core2.principalDidEquals)(actual, expected);
326
+ } catch {
327
+ return actual === expected;
328
+ }
329
+ }
330
+ function addRawAbility(rawAbilities, resource, action) {
331
+ const actions = rawAbilities[resource];
332
+ if (actions === void 0) {
333
+ rawAbilities[resource] = [action];
334
+ return;
335
+ }
336
+ if (!actions.includes(action)) {
337
+ actions.push(action);
338
+ }
339
+ }
320
340
  var NodeUserAuthorization = class {
321
341
  constructor(config) {
322
342
  this.extensions = [];
@@ -343,6 +363,7 @@ var NodeUserAuthorization = class {
343
363
  "": [
344
364
  "tinycloud.sql/read",
345
365
  "tinycloud.sql/write",
366
+ "tinycloud.sql/ddl",
346
367
  "tinycloud.sql/admin",
347
368
  "tinycloud.sql/export"
348
369
  ]
@@ -546,20 +567,18 @@ var NodeUserAuthorization = class {
546
567
  };
547
568
  }
548
569
  const rawAbilities = {};
570
+ const currentDid = (0, import_sdk_core2.pkhDid)(address, chainId);
549
571
  const spaceResources = request.resources.filter((entry) => {
550
572
  if (entry.service !== import_sdk_core2.ENCRYPTION_PERMISSION_SERVICE) {
551
573
  return true;
552
574
  }
553
- const existing = rawAbilities[entry.path];
554
- if (existing === void 0) {
555
- rawAbilities[entry.path] = [...entry.actions];
556
- } else {
557
- const seen = new Set(existing);
558
- for (const action of entry.actions) {
559
- if (!seen.has(action)) {
560
- existing.push(action);
561
- seen.add(action);
562
- }
575
+ for (const action of entry.actions) {
576
+ addRawAbility(rawAbilities, entry.path, action);
577
+ }
578
+ if (entry.actions.includes(DECRYPT_ACTION)) {
579
+ const parsed = (0, import_sdk_core2.parseNetworkId)(entry.path);
580
+ if (didPrincipalMatches(parsed.ownerDid, currentDid)) {
581
+ addRawAbility(rawAbilities, entry.path, NETWORK_CREATE_ACTION);
563
582
  }
564
583
  }
565
584
  return false;
@@ -1119,32 +1138,35 @@ var NodeUserAuthorization = class {
1119
1138
  };
1120
1139
 
1121
1140
  // src/TinyCloudNode.ts
1122
- var import_sdk_core6 = require("@tinycloud/sdk-core");
1141
+ var import_sdk_core7 = require("@tinycloud/sdk-core");
1123
1142
 
1124
- // src/DelegatedAccess.ts
1143
+ // src/account/AccountService.ts
1125
1144
  var import_sdk_core3 = require("@tinycloud/sdk-core");
1145
+
1146
+ // src/DelegatedAccess.ts
1147
+ var import_sdk_core4 = require("@tinycloud/sdk-core");
1126
1148
  var DelegatedAccess = class {
1127
1149
  constructor(session, delegation, host, invoke, telemetry) {
1128
1150
  this.session = session;
1129
1151
  this._delegation = delegation;
1130
1152
  this.host = host;
1131
- this._serviceContext = new import_sdk_core3.ServiceContext({
1153
+ this._serviceContext = new import_sdk_core4.ServiceContext({
1132
1154
  invoke,
1133
1155
  fetch: globalThis.fetch.bind(globalThis),
1134
1156
  hosts: [host],
1135
1157
  telemetry
1136
1158
  });
1137
1159
  const prefix = this._delegation.path.replace(/\/$/, "");
1138
- this._kv = new import_sdk_core3.KVService({ prefix });
1160
+ this._kv = new import_sdk_core4.KVService({ prefix });
1139
1161
  this._kv.initialize(this._serviceContext);
1140
1162
  this._serviceContext.registerService("kv", this._kv);
1141
- this._sql = new import_sdk_core3.SQLService({});
1163
+ this._sql = new import_sdk_core4.SQLService({});
1142
1164
  this._sql.initialize(this._serviceContext);
1143
1165
  this._serviceContext.registerService("sql", this._sql);
1144
- this._duckdb = new import_sdk_core3.DuckDbService({});
1166
+ this._duckdb = new import_sdk_core4.DuckDbService({});
1145
1167
  this._duckdb.initialize(this._serviceContext);
1146
1168
  this._serviceContext.registerService("duckdb", this._duckdb);
1147
- this._hooks = new import_sdk_core3.HooksService({});
1169
+ this._hooks = new import_sdk_core4.HooksService({});
1148
1170
  this._hooks.initialize(this._serviceContext);
1149
1171
  this._serviceContext.registerService("hooks", this._hooks);
1150
1172
  const serviceSession = {
@@ -1294,7 +1316,7 @@ function createWasmKeyProvider(sessionManager) {
1294
1316
  }
1295
1317
 
1296
1318
  // src/delegateToHelpers.ts
1297
- var import_sdk_core4 = require("@tinycloud/sdk-core");
1319
+ var import_sdk_core5 = require("@tinycloud/sdk-core");
1298
1320
  function legacyParamsToPermissionEntries(actions, path, spaceIdOverride) {
1299
1321
  const byService = /* @__PURE__ */ new Map();
1300
1322
  for (const a of actions) {
@@ -1325,7 +1347,7 @@ function legacyParamsToPermissionEntries(actions, path, spaceIdOverride) {
1325
1347
  }
1326
1348
  return entries;
1327
1349
  }
1328
- var DEFAULT_DELEGATION_EXPIRY_MS = import_sdk_core4.EXPIRY.SESSION_MS;
1350
+ var DEFAULT_DELEGATION_EXPIRY_MS = import_sdk_core5.EXPIRY.SESSION_MS;
1329
1351
  function resolveExpiryMs(expiry) {
1330
1352
  if (expiry === void 0) {
1331
1353
  return DEFAULT_DELEGATION_EXPIRY_MS;
@@ -1338,10 +1360,10 @@ function resolveExpiryMs(expiry) {
1338
1360
  }
1339
1361
  return expiry;
1340
1362
  }
1341
- return (0, import_sdk_core4.parseExpiry)(expiry);
1363
+ return (0, import_sdk_core5.parseExpiry)(expiry);
1342
1364
  }
1343
1365
  function extractSiweExpiration(siwe) {
1344
- const parsed = new import_sdk_core4.SiweMessage(siwe);
1366
+ const parsed = new import_sdk_core5.SiweMessage(siwe);
1345
1367
  if (parsed.expirationTime === void 0 || parsed.expirationTime === null) {
1346
1368
  return void 0;
1347
1369
  }
@@ -1355,7 +1377,7 @@ function extractSiweExpiration(siwe) {
1355
1377
  }
1356
1378
 
1357
1379
  // src/NodeSecretsService.ts
1358
- var import_sdk_core5 = require("@tinycloud/sdk-core");
1380
+ var import_sdk_core6 = require("@tinycloud/sdk-core");
1359
1381
  var SECRETS_SPACE = "secrets";
1360
1382
  function ok() {
1361
1383
  return { ok: true, data: void 0 };
@@ -1388,7 +1410,7 @@ function secretActionName(action) {
1388
1410
  }
1389
1411
  function secretPermissionEntries(name, options, action, encryptionNetworkId) {
1390
1412
  const entries = [];
1391
- const path = action === "list" ? (0, import_sdk_core5.resolveSecretListPrefix)(options) : (0, import_sdk_core5.resolveSecretPath)(name, options).permissionPaths.vault;
1413
+ const path = action === "list" ? (0, import_sdk_core6.resolveSecretListPrefix)(options) : (0, import_sdk_core6.resolveSecretPath)(name, options).permissionPaths.vault;
1392
1414
  entries.push({
1393
1415
  service: "tinycloud.kv",
1394
1416
  space: SECRETS_SPACE,
@@ -1467,7 +1489,7 @@ var NodeSecretsService = class {
1467
1489
  );
1468
1490
  } catch (error) {
1469
1491
  return secretsError(
1470
- import_sdk_core5.ErrorCodes.INVALID_INPUT,
1492
+ import_sdk_core6.ErrorCodes.INVALID_INPUT,
1471
1493
  error instanceof Error ? error.message : String(error),
1472
1494
  error instanceof Error ? error : void 0
1473
1495
  );
@@ -1477,7 +1499,7 @@ var NodeSecretsService = class {
1477
1499
  }
1478
1500
  if (!this.config.canEscalate()) {
1479
1501
  return secretsError(
1480
- import_sdk_core5.ErrorCodes.PERMISSION_DENIED,
1502
+ import_sdk_core6.ErrorCodes.PERMISSION_DENIED,
1481
1503
  `Cannot autosign ${displayActionUrn(action)} for ${target}; TinyCloudNode needs wallet mode with a signer or privateKey.`
1482
1504
  );
1483
1505
  }
@@ -1486,7 +1508,7 @@ var NodeSecretsService = class {
1486
1508
  return this.restoreUnlockAfterEscalation();
1487
1509
  } catch (error) {
1488
1510
  return secretsError(
1489
- import_sdk_core5.ErrorCodes.PERMISSION_DENIED,
1511
+ import_sdk_core6.ErrorCodes.PERMISSION_DENIED,
1490
1512
  error instanceof Error ? error.message : `Autosign escalation for ${displayActionUrn(action)} on ${target} failed.`,
1491
1513
  error instanceof Error ? error : void 0
1492
1514
  );
@@ -1507,10 +1529,10 @@ var NodeSecretsService = class {
1507
1529
  return false;
1508
1530
  }
1509
1531
  const manifests = Array.isArray(manifest) ? manifest : [manifest];
1510
- const requestedEntries = (0, import_sdk_core5.expandPermissionEntries)(permissionEntries);
1532
+ const requestedEntries = (0, import_sdk_core6.expandPermissionEntries)(permissionEntries);
1511
1533
  return requestedEntries.every(
1512
1534
  (entry) => manifests.some((candidate) => {
1513
- const resolved = (0, import_sdk_core5.resolveManifest)(candidate);
1535
+ const resolved = (0, import_sdk_core6.resolveManifest)(candidate);
1514
1536
  return resolved.resources.some(
1515
1537
  (resource) => resource.service === entry.service && resource.space === entry.space && resource.path === entry.path && entry.actions.every((action) => resource.actions.includes(action))
1516
1538
  );
@@ -1522,13 +1544,13 @@ var NodeSecretsService = class {
1522
1544
  // src/TinyCloudNode.ts
1523
1545
  var DEFAULT_HOST = "https://node.tinycloud.xyz";
1524
1546
  var DEFAULT_ENCRYPTION_NETWORK_NAME = "default";
1525
- var NETWORK_CREATE_ACTION = "tinycloud.encryption/network.create";
1526
- var DECRYPT_ACTION = "tinycloud.encryption/decrypt";
1547
+ var NETWORK_CREATE_ACTION2 = "tinycloud.encryption/network.create";
1548
+ var DECRYPT_ACTION2 = "tinycloud.encryption/decrypt";
1527
1549
  var NETWORK_ADMIN_TYPE = "tinycloud.encryption.network-admin/v1";
1528
- var DEFAULT_SESSION_EXPIRATION_MS = import_sdk_core6.EXPIRY.SESSION_MS;
1529
- function didPrincipalMatches(actual, expected) {
1550
+ var DEFAULT_SESSION_EXPIRATION_MS = import_sdk_core7.EXPIRY.SESSION_MS;
1551
+ function didPrincipalMatches2(actual, expected) {
1530
1552
  try {
1531
- return (0, import_sdk_core6.principalDidEquals)(actual, expected);
1553
+ return (0, import_sdk_core7.principalDidEquals)(actual, expected);
1532
1554
  } catch {
1533
1555
  return actual === expected;
1534
1556
  }
@@ -1694,12 +1716,12 @@ var _TinyCloudNode = class _TinyCloudNode {
1694
1716
  throw new Error("Failed to get session key JWK");
1695
1717
  }
1696
1718
  this.sessionKeyJwk = JSON.parse(jwkStr);
1697
- this._capabilityRegistry = new import_sdk_core6.CapabilityKeyRegistry();
1719
+ this._capabilityRegistry = new import_sdk_core7.CapabilityKeyRegistry();
1698
1720
  this._keyProvider = new WasmKeyProvider({
1699
1721
  sessionManager: this.sessionManager
1700
1722
  });
1701
- this.notificationHandler = config.notificationHandler ?? new import_sdk_core6.SilentNotificationHandler();
1702
- this._sharingService = new import_sdk_core6.SharingService({
1723
+ this.notificationHandler = config.notificationHandler ?? new import_sdk_core7.SilentNotificationHandler();
1724
+ this._sharingService = new import_sdk_core7.SharingService({
1703
1725
  hosts: [this.config.host],
1704
1726
  // session: undefined - not needed for receive()
1705
1727
  invoke: this.invokeWithRuntimePermissions,
@@ -1709,8 +1731,8 @@ var _TinyCloudNode = class _TinyCloudNode {
1709
1731
  // delegationManager: undefined - not needed for receive()
1710
1732
  createKVService: (config2) => {
1711
1733
  const prefix = config2.pathPrefix?.replace(/\/$/, "");
1712
- const kvService = new import_sdk_core6.KVService({ prefix });
1713
- const kvContext = new import_sdk_core6.ServiceContext({
1734
+ const kvService = new import_sdk_core7.KVService({ prefix });
1735
+ const kvContext = new import_sdk_core7.ServiceContext({
1714
1736
  invoke: config2.invoke,
1715
1737
  fetch: config2.fetch ?? globalThis.fetch.bind(globalThis),
1716
1738
  hosts: config2.hosts,
@@ -1770,7 +1792,7 @@ var _TinyCloudNode = class _TinyCloudNode {
1770
1792
  capabilityRequest: config.capabilityRequest,
1771
1793
  includeAccountRegistryPermissions: config.includeAccountRegistryPermissions
1772
1794
  });
1773
- this.tc = new import_sdk_core6.TinyCloud(this.auth, {
1795
+ this.tc = new import_sdk_core7.TinyCloud(this.auth, {
1774
1796
  invokeAny: this.invokeAnyWithRuntimePermissions,
1775
1797
  telemetry: config.telemetry
1776
1798
  });
@@ -1831,7 +1853,7 @@ var _TinyCloudNode = class _TinyCloudNode {
1831
1853
  */
1832
1854
  get did() {
1833
1855
  if (this._address) {
1834
- return (0, import_sdk_core6.pkhDid)(this._address, this._chainId);
1856
+ return (0, import_sdk_core7.pkhDid)(this._address, this._chainId);
1835
1857
  }
1836
1858
  return this.sessionManager.getDID(this.sessionKeyId);
1837
1859
  }
@@ -1865,6 +1887,37 @@ var _TinyCloudNode = class _TinyCloudNode {
1865
1887
  get spaceId() {
1866
1888
  return this.auth?.tinyCloudSession?.spaceId;
1867
1889
  }
1890
+ /**
1891
+ * Get the account space ID for this wallet identity.
1892
+ * Available after wallet-backed sign-in or a restored session with address metadata.
1893
+ */
1894
+ get accountSpaceId() {
1895
+ if (!this._address) {
1896
+ return void 0;
1897
+ }
1898
+ return this.wasmBindings.makeSpaceId(this._address, this._chainId, import_sdk_core7.ACCOUNT_REGISTRY_SPACE);
1899
+ }
1900
+ /**
1901
+ * Account-level application and delegation helpers.
1902
+ */
1903
+ get account() {
1904
+ if (!this._account) {
1905
+ this._account = new import_sdk_core3.AccountService({
1906
+ getDid: () => this.did,
1907
+ getHost: () => this.hosts[0] ?? this.config.host,
1908
+ getPrimarySpaceId: () => this.spaceId,
1909
+ getAccountSpaceId: () => this.accountSpaceId,
1910
+ getSpaces: () => this.spaces,
1911
+ getAccountDb: () => this.accountSpaceId ? this.sqlForSpace(this.accountSpaceId).db("account") : void 0,
1912
+ ensureAccountSpaceHosted: async () => {
1913
+ if (this.accountSpaceId && this.auth) {
1914
+ await this.ensureOwnedSpaceHostedById(this.accountSpaceId);
1915
+ }
1916
+ }
1917
+ });
1918
+ }
1919
+ return this._account;
1920
+ }
1868
1921
  /**
1869
1922
  * Get the current TinyCloud session.
1870
1923
  * Available after signIn().
@@ -1886,7 +1939,7 @@ var _TinyCloudNode = class _TinyCloudNode {
1886
1939
  );
1887
1940
  }
1888
1941
  await this.wasmBindings.ensureInitialized?.();
1889
- this._address = (0, import_sdk_core6.canonicalizeAddress)(await this.signer.getAddress());
1942
+ this._address = (0, import_sdk_core7.canonicalizeAddress)(await this.signer.getAddress());
1890
1943
  this._chainId = await this.signer.getChainId();
1891
1944
  this._kv = void 0;
1892
1945
  this._sql = void 0;
@@ -1902,10 +1955,11 @@ var _TinyCloudNode = class _TinyCloudNode {
1902
1955
  await this.tc.signIn(options);
1903
1956
  this.syncResolvedHostFromAuth();
1904
1957
  this.initializeServices();
1958
+ await this.ensureRequestedEncryptionNetworks();
1905
1959
  if (this.config.manifest === void 0 && this.config.capabilityRequest === void 0) {
1906
- await this.ensureOwnedSpaceHosted(this.ownedSpaceId("secrets"));
1960
+ await this.ensureOwnedSpaceHostedById(this.ownedSpaceId("secrets"));
1907
1961
  }
1908
- await this.writeManifestRegistryRecords();
1962
+ this.scheduleAccountRegistrySync();
1909
1963
  this.notificationHandler.success("Successfully signed in");
1910
1964
  }
1911
1965
  ownedSpaceId(name) {
@@ -1922,23 +1976,69 @@ var _TinyCloudNode = class _TinyCloudNode {
1922
1976
  if (!this.auth || !this.signer) {
1923
1977
  throw new Error("Manifest registry write requires wallet mode");
1924
1978
  }
1925
- const accountSpaceId = this.ownedSpaceId(import_sdk_core6.ACCOUNT_REGISTRY_SPACE);
1926
- await this.ensureOwnedSpaceHosted(accountSpaceId);
1927
- const accountKV = this.spaces.get(accountSpaceId).kv;
1928
- for (const record of request.registryRecords) {
1929
- const result = await accountKV.put(record.key, {
1930
- app_id: record.app_id,
1931
- manifests: record.manifests,
1932
- updated_at: (/* @__PURE__ */ new Date()).toISOString()
1933
- });
1934
- if (!result.ok) {
1935
- throw new Error(
1936
- `Failed to write manifest registry record ${record.key}: ${result.error.message}`
1937
- );
1979
+ const accountSpaceId = this.ownedSpaceId(import_sdk_core7.ACCOUNT_REGISTRY_SPACE);
1980
+ await this.ensureOwnedSpaceHostedById(accountSpaceId);
1981
+ const result = await this.account.applications.register(request.manifests);
1982
+ if (!result.ok) {
1983
+ throw new Error(
1984
+ `Failed to write manifest registry records: ${result.error.message}`
1985
+ );
1986
+ }
1987
+ }
1988
+ scheduleAccountRegistrySync() {
1989
+ void this.withAccountRegistryRetry(async () => {
1990
+ await this.writeManifestRegistryRecords();
1991
+ const spaces = await this.account.spaces.syncAccessible();
1992
+ if (!spaces.ok) {
1993
+ throw new Error(`Failed to sync account spaces: ${spaces.error.message}`);
1994
+ }
1995
+ });
1996
+ }
1997
+ async withAccountRegistryRetry(task) {
1998
+ const delays = [250, 1e3, 3e3];
1999
+ let lastError;
2000
+ for (let attempt = 0; attempt < delays.length; attempt += 1) {
2001
+ try {
2002
+ await task();
2003
+ return;
2004
+ } catch (error) {
2005
+ lastError = error;
2006
+ if (attempt < delays.length - 1) {
2007
+ await new Promise((resolve) => setTimeout(resolve, delays[attempt]));
2008
+ }
1938
2009
  }
1939
2010
  }
2011
+ console.warn(
2012
+ "TinyCloud account registry sync failed after retries",
2013
+ lastError
2014
+ );
1940
2015
  }
1941
- async ensureOwnedSpaceHosted(spaceId) {
2016
+ requestedEncryptionNetworkIds() {
2017
+ const request = this.capabilityRequest;
2018
+ if (!request) {
2019
+ return [];
2020
+ }
2021
+ const networkIds = /* @__PURE__ */ new Set();
2022
+ 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)) {
2024
+ networkIds.add(resource.path);
2025
+ }
2026
+ }
2027
+ return [...networkIds];
2028
+ }
2029
+ async ensureRequestedEncryptionNetworks() {
2030
+ if (!this.signer || !this.auth) {
2031
+ return;
2032
+ }
2033
+ for (const networkId of this.requestedEncryptionNetworkIds()) {
2034
+ const parsed = (0, import_sdk_core7.parseNetworkId)(networkId);
2035
+ if (!didPrincipalMatches2(parsed.ownerDid, this.did)) {
2036
+ continue;
2037
+ }
2038
+ await this.ensureEncryptionNetwork(networkId);
2039
+ }
2040
+ }
2041
+ async ensureOwnedSpaceHostedById(spaceId) {
1942
2042
  if (!this.auth) {
1943
2043
  throw new Error("Owned space hosting requires wallet mode");
1944
2044
  }
@@ -1950,7 +2050,7 @@ var _TinyCloudNode = class _TinyCloudNode {
1950
2050
  if (!host) {
1951
2051
  throw new Error("Owned space hosting requires a TinyCloud host");
1952
2052
  }
1953
- const activation = await (0, import_sdk_core6.activateSessionWithHost)(host, session.delegationHeader);
2053
+ const activation = await (0, import_sdk_core7.activateSessionWithHost)(host, session.delegationHeader);
1954
2054
  if (activation.success && !activation.skipped?.includes(spaceId)) {
1955
2055
  return;
1956
2056
  }
@@ -1964,13 +2064,91 @@ var _TinyCloudNode = class _TinyCloudNode {
1964
2064
  throw new Error(`Failed to create owned space: ${spaceId}`);
1965
2065
  }
1966
2066
  await new Promise((resolve) => setTimeout(resolve, 100));
1967
- const retry = await (0, import_sdk_core6.activateSessionWithHost)(host, session.delegationHeader);
2067
+ const retry = await (0, import_sdk_core7.activateSessionWithHost)(host, session.delegationHeader);
1968
2068
  if (!retry.success || retry.skipped?.includes(spaceId)) {
1969
2069
  throw new Error(
1970
2070
  `Failed to activate session after creating owned space ${spaceId}: ${retry.error ?? "space was skipped"}`
1971
2071
  );
1972
2072
  }
1973
2073
  }
2074
+ /**
2075
+ * Host one of this user's owned spaces by name (e.g. `"applications"`).
2076
+ *
2077
+ * Resolves the name to the owned space URI
2078
+ * (`tinycloud:pkh:eip155:<chain>:<addr>:<name>`) and registers it on the
2079
+ * server via the host-SIWE delegation flow, so subsequent KV/SQL writes to
2080
+ * that space succeed instead of returning `404 - Space not found`. The
2081
+ * caller is the root authority of their own owned spaces, so no additional
2082
+ * delegation is required.
2083
+ *
2084
+ * Unlike {@link ensureOwnedSpaceHostedById}, this always submits the host
2085
+ * delegation rather than inferring hosting from session activation: a space
2086
+ * the current session has never referenced is reported neither as
2087
+ * `activated` nor `skipped`, so activation-based detection would wrongly
2088
+ * skip the host. The host SIWE is idempotent server-side, so re-hosting an
2089
+ * existing space is a safe no-op. Must be called after {@link signIn}.
2090
+ *
2091
+ * @param name - The owned space name (e.g. `"applications"`).
2092
+ * @returns The hosted space URI.
2093
+ */
2094
+ async hostOwnedSpace(name) {
2095
+ if (!this.auth || !this.auth.tinyCloudSession) {
2096
+ throw new Error("Not signed in. Call signIn() first.");
2097
+ }
2098
+ const spaceId = this.ownedSpaceId(name);
2099
+ const host = this.hosts[0] ?? this.config.host;
2100
+ if (!host) {
2101
+ throw new Error("Owned space hosting requires a TinyCloud host");
2102
+ }
2103
+ const hosted = await this.auth.hostOwnedSpace(
2104
+ spaceId
2105
+ );
2106
+ if (!hosted) {
2107
+ throw new Error(`Failed to host owned space: ${spaceId}`);
2108
+ }
2109
+ const activation = await (0, import_sdk_core7.activateSessionWithHost)(
2110
+ host,
2111
+ this.auth.tinyCloudSession.delegationHeader
2112
+ );
2113
+ if (!activation.success || activation.skipped?.includes(spaceId)) {
2114
+ throw new Error(
2115
+ `Failed to activate session for owned space ${spaceId}: ${activation.error ?? "space was skipped"}`
2116
+ );
2117
+ }
2118
+ void this.account.spaces.register({
2119
+ spaceId,
2120
+ name,
2121
+ ownerDid: this.did,
2122
+ type: "owned",
2123
+ permissions: ["*"],
2124
+ status: "active"
2125
+ }).catch(() => {
2126
+ });
2127
+ return spaceId;
2128
+ }
2129
+ /**
2130
+ * Ensure one of this user's owned spaces (e.g. `"secrets"`) is hosted on the
2131
+ * server.
2132
+ *
2133
+ * At sign-in, a full-authority session auto-hosts the owner's `secrets`
2134
+ * space, but a session created with a manifest / capabilityRequest does not.
2135
+ * Such a session can therefore hold valid `tinycloud.kv/*` capabilities for
2136
+ * the owned `secrets` space yet still fail its first scoped
2137
+ * `secrets.put(...)` with `404 Space not found`, because the space was never
2138
+ * registered on the node.
2139
+ *
2140
+ * Calling this resolves `name` to the owner's owned-space URI
2141
+ * (`tinycloud:pkh:eip155:<chain>:<addr>:<name>`) and hosts it via the
2142
+ * host-SIWE delegation flow. The host SIWE is idempotent server-side, so it
2143
+ * is safe to call whether or not the space already exists; do not gate it on
2144
+ * a prior existence check. Must be called after {@link signIn}.
2145
+ *
2146
+ * @param name - The owned space name (e.g. `"secrets"`).
2147
+ * @returns The hosted owned-space URI.
2148
+ */
2149
+ async ensureOwnedSpaceHosted(name) {
2150
+ return this.hostOwnedSpace(name);
2151
+ }
1974
2152
  /**
1975
2153
  * Restore a previously established session from stored delegation data.
1976
2154
  *
@@ -1993,30 +2171,30 @@ var _TinyCloudNode = class _TinyCloudNode {
1993
2171
  this._spaceService = void 0;
1994
2172
  this._serviceContext = void 0;
1995
2173
  this.runtimePermissionGrants = [];
1996
- const restoredAddress = sessionData.address ? (0, import_sdk_core6.canonicalizeAddress)(sessionData.address) : void 0;
2174
+ const restoredAddress = sessionData.address ? (0, import_sdk_core7.canonicalizeAddress)(sessionData.address) : void 0;
1997
2175
  if (restoredAddress) {
1998
2176
  this._address = restoredAddress;
1999
2177
  }
2000
2178
  if (sessionData.chainId) {
2001
2179
  this._chainId = sessionData.chainId;
2002
2180
  }
2003
- this._serviceContext = new import_sdk_core6.ServiceContext({
2181
+ this._serviceContext = new import_sdk_core7.ServiceContext({
2004
2182
  invoke: this.invokeWithRuntimePermissions,
2005
2183
  invokeAny: this.invokeAnyWithRuntimePermissions,
2006
2184
  fetch: globalThis.fetch.bind(globalThis),
2007
2185
  hosts: [this.config.host],
2008
2186
  telemetry: this.config.telemetry
2009
2187
  });
2010
- this._kv = new import_sdk_core6.KVService({});
2188
+ this._kv = new import_sdk_core7.KVService({});
2011
2189
  this._kv.initialize(this._serviceContext);
2012
2190
  this._serviceContext.registerService("kv", this._kv);
2013
- this._sql = new import_sdk_core6.SQLService({});
2191
+ this._sql = new import_sdk_core7.SQLService({});
2014
2192
  this._sql.initialize(this._serviceContext);
2015
2193
  this._serviceContext.registerService("sql", this._sql);
2016
- this._duckdb = new import_sdk_core6.DuckDbService({});
2194
+ this._duckdb = new import_sdk_core7.DuckDbService({});
2017
2195
  this._duckdb.initialize(this._serviceContext);
2018
2196
  this._serviceContext.registerService("duckdb", this._duckdb);
2019
- this._hooks = new import_sdk_core6.HooksService({});
2197
+ this._hooks = new import_sdk_core7.HooksService({});
2020
2198
  this._hooks.initialize(this._serviceContext);
2021
2199
  this._serviceContext.registerService("hooks", this._hooks);
2022
2200
  const serviceSession = {
@@ -2115,7 +2293,7 @@ var _TinyCloudNode = class _TinyCloudNode {
2115
2293
  capabilityRequest: this.config.capabilityRequest,
2116
2294
  includeAccountRegistryPermissions: this.config.includeAccountRegistryPermissions
2117
2295
  });
2118
- this.tc = new import_sdk_core6.TinyCloud(this.auth, {
2296
+ this.tc = new import_sdk_core7.TinyCloud(this.auth, {
2119
2297
  invokeAny: this.invokeAnyWithRuntimePermissions,
2120
2298
  telemetry: this.config.telemetry
2121
2299
  });
@@ -2160,7 +2338,7 @@ var _TinyCloudNode = class _TinyCloudNode {
2160
2338
  capabilityRequest: this.config.capabilityRequest,
2161
2339
  includeAccountRegistryPermissions: this.config.includeAccountRegistryPermissions
2162
2340
  });
2163
- this.tc = new import_sdk_core6.TinyCloud(this.auth, {
2341
+ this.tc = new import_sdk_core7.TinyCloud(this.auth, {
2164
2342
  invokeAny: this.invokeAnyWithRuntimePermissions,
2165
2343
  telemetry: this.config.telemetry
2166
2344
  });
@@ -2176,28 +2354,28 @@ var _TinyCloudNode = class _TinyCloudNode {
2176
2354
  return;
2177
2355
  }
2178
2356
  this.tc.initializeServices(this.invokeWithRuntimePermissions, [this.config.host]);
2179
- this._serviceContext = new import_sdk_core6.ServiceContext({
2357
+ this._serviceContext = new import_sdk_core7.ServiceContext({
2180
2358
  invoke: this.invokeWithRuntimePermissions,
2181
2359
  invokeAny: this.invokeAnyWithRuntimePermissions,
2182
2360
  fetch: globalThis.fetch.bind(globalThis),
2183
2361
  hosts: [this.config.host],
2184
2362
  telemetry: this.config.telemetry
2185
2363
  });
2186
- this._kv = new import_sdk_core6.KVService({});
2364
+ this._kv = new import_sdk_core7.KVService({});
2187
2365
  this._kv.initialize(this._serviceContext);
2188
2366
  this._serviceContext.registerService("kv", this._kv);
2189
2367
  const features = this.nodeFeatures;
2190
2368
  if (features.length === 0 || features.includes("sql")) {
2191
- this._sql = new import_sdk_core6.SQLService({});
2369
+ this._sql = new import_sdk_core7.SQLService({});
2192
2370
  this._sql.initialize(this._serviceContext);
2193
2371
  this._serviceContext.registerService("sql", this._sql);
2194
2372
  }
2195
2373
  if (features.length === 0 || features.includes("duckdb")) {
2196
- this._duckdb = new import_sdk_core6.DuckDbService({});
2374
+ this._duckdb = new import_sdk_core7.DuckDbService({});
2197
2375
  this._duckdb.initialize(this._serviceContext);
2198
2376
  this._serviceContext.registerService("duckdb", this._duckdb);
2199
2377
  }
2200
- this._hooks = new import_sdk_core6.HooksService({});
2378
+ this._hooks = new import_sdk_core7.HooksService({});
2201
2379
  this._hooks.initialize(this._serviceContext);
2202
2380
  this._serviceContext.registerService("hooks", this._hooks);
2203
2381
  const serviceSession = {
@@ -2215,9 +2393,9 @@ var _TinyCloudNode = class _TinyCloudNode {
2215
2393
  this.initializeV2Services(serviceSession);
2216
2394
  }
2217
2395
  createSpaceScopedKVService(spaceId) {
2218
- const kvService = new import_sdk_core6.KVService({});
2396
+ const kvService = new import_sdk_core7.KVService({});
2219
2397
  if (this._serviceContext) {
2220
- const spaceScopedContext = new import_sdk_core6.ServiceContext({
2398
+ const spaceScopedContext = new import_sdk_core7.ServiceContext({
2221
2399
  invoke: this._serviceContext.invoke,
2222
2400
  fetch: this._serviceContext.fetch,
2223
2401
  hosts: this._serviceContext.hosts,
@@ -2282,7 +2460,7 @@ var _TinyCloudNode = class _TinyCloudNode {
2282
2460
  const shared = wasm.vault_x25519_dh(receiverPrivateKey, peerPublic);
2283
2461
  return columnDecrypt(shared, ciphertext);
2284
2462
  },
2285
- verifyNodeSignature: (nodeId, message, signature) => (0, import_sdk_core6.verifyDidKeyEd25519Signature)(nodeId, message, signature)
2463
+ verifyNodeSignature: (nodeId, message, signature) => (0, import_sdk_core7.verifyDidKeyEd25519Signature)(nodeId, message, signature)
2286
2464
  };
2287
2465
  }
2288
2466
  async fetchNodeId() {
@@ -2353,19 +2531,19 @@ var _TinyCloudNode = class _TinyCloudNode {
2353
2531
  return await response.json();
2354
2532
  }
2355
2533
  };
2356
- return new import_sdk_core6.EncryptionService({
2534
+ return new import_sdk_core7.EncryptionService({
2357
2535
  crypto,
2358
2536
  signer: {
2359
2537
  signDecryptInvocation: async (input) => {
2360
2538
  const signed = await this.signRawNetworkAuthorization({
2361
2539
  targetNode: input.targetNode,
2362
2540
  networkId: input.networkId,
2363
- action: DECRYPT_ACTION,
2541
+ action: DECRYPT_ACTION2,
2364
2542
  facts: input.facts
2365
2543
  });
2366
2544
  return {
2367
2545
  ...signed,
2368
- canonicalBody: (0, import_sdk_core6.canonicalizeEncryptionJson)(
2546
+ canonicalBody: (0, import_sdk_core7.canonicalizeEncryptionJson)(
2369
2547
  input.body
2370
2548
  )
2371
2549
  };
@@ -2377,14 +2555,14 @@ var _TinyCloudNode = class _TinyCloudNode {
2377
2555
  },
2378
2556
  wellKnown: {
2379
2557
  fetchWellKnown: async (principal, discoveryKey) => {
2380
- if (!this._address || !didPrincipalMatches(principal, this.did)) {
2558
+ if (!this._address || !didPrincipalMatches2(principal, this.did)) {
2381
2559
  return null;
2382
2560
  }
2383
2561
  if (!this.config.host) {
2384
2562
  return null;
2385
2563
  }
2386
- const publicSpaceId = (0, import_sdk_core6.makePublicSpaceId)(this._address, this._chainId);
2387
- const result = await import_sdk_core6.TinyCloud.readPublicSpace(this.config.host, publicSpaceId, discoveryKey);
2564
+ const publicSpaceId = (0, import_sdk_core7.makePublicSpaceId)(this._address, this._chainId);
2565
+ const result = await import_sdk_core7.TinyCloud.readPublicSpace(this.config.host, publicSpaceId, discoveryKey);
2388
2566
  if (!result.ok) {
2389
2567
  return null;
2390
2568
  }
@@ -2407,7 +2585,7 @@ var _TinyCloudNode = class _TinyCloudNode {
2407
2585
  }
2408
2586
  createVaultService(spaceId, kv) {
2409
2587
  const wasm = this.wasmBindings;
2410
- const vaultCrypto = (0, import_sdk_core6.createVaultCrypto)({
2588
+ const vaultCrypto = (0, import_sdk_core7.createVaultCrypto)({
2411
2589
  vault_encrypt: wasm.vault_encrypt,
2412
2590
  vault_decrypt: wasm.vault_decrypt,
2413
2591
  vault_derive_key: wasm.vault_derive_key,
@@ -2417,7 +2595,7 @@ var _TinyCloudNode = class _TinyCloudNode {
2417
2595
  vault_sha256: wasm.vault_sha256
2418
2596
  });
2419
2597
  const self = this;
2420
- return new import_sdk_core6.DataVaultService({
2598
+ return new import_sdk_core7.DataVaultService({
2421
2599
  spaceId,
2422
2600
  crypto: vaultCrypto,
2423
2601
  encryption: {
@@ -2440,8 +2618,8 @@ var _TinyCloudNode = class _TinyCloudNode {
2440
2618
  get publicKV() {
2441
2619
  return self._publicKV ?? self.tc.publicKV;
2442
2620
  },
2443
- readPublicSpace: (host, targetSpaceId, key) => import_sdk_core6.TinyCloud.readPublicSpace(host, targetSpaceId, key),
2444
- makePublicSpaceId: import_sdk_core6.TinyCloud.makePublicSpaceId,
2621
+ readPublicSpace: (host, targetSpaceId, key) => import_sdk_core7.TinyCloud.readPublicSpace(host, targetSpaceId, key),
2622
+ makePublicSpaceId: import_sdk_core7.TinyCloud.makePublicSpaceId,
2445
2623
  did: this.did,
2446
2624
  address: this._address ?? "",
2447
2625
  chainId: this._chainId,
@@ -2454,7 +2632,7 @@ var _TinyCloudNode = class _TinyCloudNode {
2454
2632
  * @internal
2455
2633
  */
2456
2634
  initializeV2Services(serviceSession) {
2457
- this._capabilityRegistry = new import_sdk_core6.CapabilityKeyRegistry();
2635
+ this._capabilityRegistry = new import_sdk_core7.CapabilityKeyRegistry();
2458
2636
  const tcSession = this.auth?.tinyCloudSession;
2459
2637
  if (tcSession && this._address) {
2460
2638
  const sessionKey = {
@@ -2528,13 +2706,13 @@ var _TinyCloudNode = class _TinyCloudNode {
2528
2706
  }
2529
2707
  this._capabilityRegistry.registerKey(sessionKey, delegations);
2530
2708
  }
2531
- this._delegationManager = new import_sdk_core6.DelegationManager({
2709
+ this._delegationManager = new import_sdk_core7.DelegationManager({
2532
2710
  hosts: [this.config.host],
2533
2711
  session: serviceSession,
2534
2712
  invoke: this.invokeWithRuntimePermissions,
2535
2713
  fetch: globalThis.fetch.bind(globalThis)
2536
2714
  });
2537
- this._spaceService = new import_sdk_core6.SpaceService({
2715
+ this._spaceService = new import_sdk_core7.SpaceService({
2538
2716
  hosts: [this.config.host],
2539
2717
  session: serviceSession,
2540
2718
  invoke: this.wasmBindings.invoke,
@@ -2586,6 +2764,9 @@ var _TinyCloudNode = class _TinyCloudNode {
2586
2764
  }
2587
2765
  };
2588
2766
  }
2767
+ },
2768
+ onSpaceRegistered: async (space) => {
2769
+ await this.account.spaces.register(space);
2589
2770
  }
2590
2771
  });
2591
2772
  this._sharingService.updateConfig({
@@ -2691,7 +2872,7 @@ var _TinyCloudNode = class _TinyCloudNode {
2691
2872
  ...prepared,
2692
2873
  signature
2693
2874
  });
2694
- const activateResult = await (0, import_sdk_core6.activateSessionWithHost)(
2875
+ const activateResult = await (0, import_sdk_core7.activateSessionWithHost)(
2695
2876
  host,
2696
2877
  delegationSession.delegationHeader
2697
2878
  );
@@ -2701,7 +2882,7 @@ var _TinyCloudNode = class _TinyCloudNode {
2701
2882
  return {
2702
2883
  cid: delegationSession.delegationCid,
2703
2884
  delegateDID: params.shareKeyDID,
2704
- delegatorDID: (0, import_sdk_core6.pkhDid)(session.address, session.chainId),
2885
+ delegatorDID: (0, import_sdk_core7.pkhDid)(session.address, session.chainId),
2705
2886
  spaceId: params.spaceId,
2706
2887
  path: params.path,
2707
2888
  actions: params.actions,
@@ -2758,7 +2939,7 @@ var _TinyCloudNode = class _TinyCloudNode {
2758
2939
  if (!this._sql) {
2759
2940
  const features = this.nodeFeatures;
2760
2941
  if (features.length > 0 && !features.includes("sql")) {
2761
- throw new import_sdk_core6.UnsupportedFeatureError("sql", this.config.host, features);
2942
+ throw new import_sdk_core7.UnsupportedFeatureError("sql", this.config.host, features);
2762
2943
  }
2763
2944
  throw new Error("Not signed in. Call signIn() first.");
2764
2945
  }
@@ -2782,8 +2963,8 @@ var _TinyCloudNode = class _TinyCloudNode {
2782
2963
  if (!this._serviceContext || !this._serviceContext.session) {
2783
2964
  throw new Error("Not signed in. Call signIn() first.");
2784
2965
  }
2785
- const sql = new import_sdk_core6.SQLService({});
2786
- const spaceScopedContext = new import_sdk_core6.ServiceContext({
2966
+ const sql = new import_sdk_core7.SQLService({});
2967
+ const spaceScopedContext = new import_sdk_core7.ServiceContext({
2787
2968
  invoke: this._serviceContext.invoke,
2788
2969
  fetch: this._serviceContext.fetch,
2789
2970
  hosts: this._serviceContext.hosts,
@@ -2811,8 +2992,8 @@ var _TinyCloudNode = class _TinyCloudNode {
2811
2992
  if (!this._serviceContext || !this._serviceContext.session) {
2812
2993
  throw new Error("Not signed in. Call signIn() first.");
2813
2994
  }
2814
- const kv = new import_sdk_core6.KVService({});
2815
- const spaceScopedContext = new import_sdk_core6.ServiceContext({
2995
+ const kv = new import_sdk_core7.KVService({});
2996
+ const spaceScopedContext = new import_sdk_core7.ServiceContext({
2816
2997
  invoke: this._serviceContext.invoke,
2817
2998
  fetch: this._serviceContext.fetch,
2818
2999
  hosts: this._serviceContext.hosts
@@ -2828,7 +3009,7 @@ var _TinyCloudNode = class _TinyCloudNode {
2828
3009
  if (!this._duckdb) {
2829
3010
  const features = this.nodeFeatures;
2830
3011
  if (features.length > 0 && !features.includes("duckdb")) {
2831
- throw new import_sdk_core6.UnsupportedFeatureError("duckdb", this.config.host, features);
3012
+ throw new import_sdk_core7.UnsupportedFeatureError("duckdb", this.config.host, features);
2832
3013
  }
2833
3014
  throw new Error("Not signed in. Call signIn() first.");
2834
3015
  }
@@ -2880,16 +3061,16 @@ var _TinyCloudNode = class _TinyCloudNode {
2880
3061
  type: NETWORK_ADMIN_TYPE,
2881
3062
  targetNode,
2882
3063
  networkId,
2883
- bodyHash: (0, import_sdk_core6.canonicalHashHex)(
3064
+ bodyHash: (0, import_sdk_core7.canonicalHashHex)(
2884
3065
  crypto.sha256,
2885
3066
  body
2886
3067
  ),
2887
- action: NETWORK_CREATE_ACTION
3068
+ action: NETWORK_CREATE_ACTION2
2888
3069
  };
2889
3070
  const signed = await this.signRawNetworkAuthorization({
2890
3071
  targetNode,
2891
3072
  networkId,
2892
- action: NETWORK_CREATE_ACTION,
3073
+ action: NETWORK_CREATE_ACTION2,
2893
3074
  facts
2894
3075
  });
2895
3076
  const response = await fetch(`${this.config.host}/encryption/networks`, {
@@ -2898,7 +3079,7 @@ var _TinyCloudNode = class _TinyCloudNode {
2898
3079
  Authorization: signed.authorization,
2899
3080
  "Content-Type": "application/json"
2900
3081
  },
2901
- body: (0, import_sdk_core6.canonicalizeEncryptionJson)(
3082
+ body: (0, import_sdk_core7.canonicalizeEncryptionJson)(
2902
3083
  body
2903
3084
  )
2904
3085
  });
@@ -2910,12 +3091,19 @@ var _TinyCloudNode = class _TinyCloudNode {
2910
3091
  const created = await response.json();
2911
3092
  return created.descriptor;
2912
3093
  }
2913
- async ensureEncryptionNetwork(name = DEFAULT_ENCRYPTION_NETWORK_NAME) {
2914
- const existing = await this.getEncryptionNetwork(name);
3094
+ async ensureEncryptionNetwork(nameOrNetworkId = DEFAULT_ENCRYPTION_NETWORK_NAME) {
3095
+ const networkId = nameOrNetworkId.startsWith("urn:tinycloud:encryption:") ? nameOrNetworkId : this.getDefaultEncryptionNetworkId(nameOrNetworkId);
3096
+ const existing = await this.getEncryptionNetwork(networkId);
2915
3097
  if (existing) {
2916
3098
  return existing;
2917
3099
  }
2918
- return this.createEncryptionNetwork(name);
3100
+ const parsed = (0, import_sdk_core7.parseNetworkId)(networkId);
3101
+ if (!didPrincipalMatches2(parsed.ownerDid, this.did)) {
3102
+ throw new Error(
3103
+ `Cannot create encryption network ${networkId}: owner ${parsed.ownerDid} does not match signed-in DID ${this.did}`
3104
+ );
3105
+ }
3106
+ return this.createEncryptionNetwork(parsed.name);
2919
3107
  }
2920
3108
  /**
2921
3109
  * App-facing secrets API backed by the `secrets` space vault.
@@ -2942,7 +3130,7 @@ var _TinyCloudNode = class _TinyCloudNode {
2942
3130
  throw new Error("Not signed in. Call signIn() first.");
2943
3131
  }
2944
3132
  if (!this._baseSecrets) {
2945
- this._baseSecrets = new import_sdk_core6.SecretsService(() => this.space("secrets").vault);
3133
+ this._baseSecrets = new import_sdk_core7.SecretsService(() => this.space("secrets").vault);
2946
3134
  }
2947
3135
  return this._baseSecrets;
2948
3136
  }
@@ -3057,19 +3245,19 @@ var _TinyCloudNode = class _TinyCloudNode {
3057
3245
  async useRuntimeDelegation(delegation) {
3058
3246
  const session = this.currentTinyCloudSession();
3059
3247
  if (!session) {
3060
- throw new import_sdk_core6.SessionExpiredError(/* @__PURE__ */ new Date(0));
3248
+ throw new import_sdk_core7.SessionExpiredError(/* @__PURE__ */ new Date(0));
3061
3249
  }
3062
3250
  if (delegation.expiry.getTime() <= Date.now()) {
3063
- throw new import_sdk_core6.SessionExpiredError(delegation.expiry);
3251
+ throw new import_sdk_core7.SessionExpiredError(delegation.expiry);
3064
3252
  }
3065
3253
  const expectedDids = [session.verificationMethod, this.sessionDid];
3066
- if (!expectedDids.some((did) => didPrincipalMatches(delegation.delegateDID, did))) {
3254
+ if (!expectedDids.some((did) => didPrincipalMatches2(delegation.delegateDID, did))) {
3067
3255
  throw new Error(
3068
3256
  `Runtime delegation targets ${delegation.delegateDID} but this session key is ${session.verificationMethod}.`
3069
3257
  );
3070
3258
  }
3071
3259
  const targetHost = delegation.host ?? this.config.host;
3072
- const activateResult = await (0, import_sdk_core6.activateSessionWithHost)(
3260
+ const activateResult = await (0, import_sdk_core7.activateSessionWithHost)(
3073
3261
  targetHost,
3074
3262
  delegation.delegationHeader
3075
3263
  );
@@ -3096,13 +3284,13 @@ var _TinyCloudNode = class _TinyCloudNode {
3096
3284
  }
3097
3285
  const session = this.currentTinyCloudSession();
3098
3286
  if (!session) {
3099
- throw new import_sdk_core6.SessionExpiredError(/* @__PURE__ */ new Date(0));
3287
+ throw new import_sdk_core7.SessionExpiredError(/* @__PURE__ */ new Date(0));
3100
3288
  }
3101
3289
  const sessionExpiry = extractSiweExpiration(session.siwe);
3102
3290
  if (sessionExpiry !== void 0) {
3103
3291
  const marginMs = _TinyCloudNode.SESSION_EXPIRY_SAFETY_MARGIN_MS;
3104
3292
  if (sessionExpiry.getTime() <= Date.now() + marginMs) {
3105
- throw new import_sdk_core6.SessionExpiredError(sessionExpiry);
3293
+ throw new import_sdk_core7.SessionExpiredError(sessionExpiry);
3106
3294
  }
3107
3295
  }
3108
3296
  const expanded = this.expandPermissionEntries(permissions);
@@ -3165,7 +3353,7 @@ var _TinyCloudNode = class _TinyCloudNode {
3165
3353
  ...prepared,
3166
3354
  signature
3167
3355
  });
3168
- const activateResult = await (0, import_sdk_core6.activateSessionWithHost)(
3356
+ const activateResult = await (0, import_sdk_core7.activateSessionWithHost)(
3169
3357
  this.config.host,
3170
3358
  delegatedSession.delegationHeader
3171
3359
  );
@@ -3338,7 +3526,7 @@ var _TinyCloudNode = class _TinyCloudNode {
3338
3526
  ];
3339
3527
  const abilities = { kv: { "": kvActions } };
3340
3528
  const now = /* @__PURE__ */ new Date();
3341
- const expiryMs = import_sdk_core6.EXPIRY.EPHEMERAL_MS;
3529
+ const expiryMs = import_sdk_core7.EXPIRY.EPHEMERAL_MS;
3342
3530
  const expirationTime = new Date(now.getTime() + expiryMs);
3343
3531
  const prepared = this.wasmBindings.prepareSession({
3344
3532
  abilities,
@@ -3356,7 +3544,7 @@ var _TinyCloudNode = class _TinyCloudNode {
3356
3544
  ...prepared,
3357
3545
  signature
3358
3546
  });
3359
- const activateResult = await (0, import_sdk_core6.activateSessionWithHost)(
3547
+ const activateResult = await (0, import_sdk_core7.activateSessionWithHost)(
3360
3548
  this.config.host,
3361
3549
  delegationSession.delegationHeader
3362
3550
  );
@@ -3383,8 +3571,8 @@ var _TinyCloudNode = class _TinyCloudNode {
3383
3571
  }]);
3384
3572
  }
3385
3573
  if (this._serviceContext) {
3386
- const publicKV = new import_sdk_core6.KVService({ prefix: "" });
3387
- const publicContext = new import_sdk_core6.ServiceContext({
3574
+ const publicKV = new import_sdk_core7.KVService({ prefix: "" });
3575
+ const publicContext = new import_sdk_core7.ServiceContext({
3388
3576
  invoke: this.invokeWithRuntimePermissions,
3389
3577
  fetch: this._serviceContext.fetch,
3390
3578
  hosts: this._serviceContext.hosts,
@@ -3511,14 +3699,14 @@ var _TinyCloudNode = class _TinyCloudNode {
3511
3699
  async delegateTo(did, permissions, options) {
3512
3700
  const session = this.currentTinyCloudSession();
3513
3701
  if (!session) {
3514
- throw new import_sdk_core6.SessionExpiredError(/* @__PURE__ */ new Date(0));
3702
+ throw new import_sdk_core7.SessionExpiredError(/* @__PURE__ */ new Date(0));
3515
3703
  }
3516
3704
  const sessionExpiry = extractSiweExpiration(session.siwe);
3517
3705
  if (sessionExpiry !== void 0) {
3518
3706
  const now2 = Date.now();
3519
3707
  const marginMs = _TinyCloudNode.SESSION_EXPIRY_SAFETY_MARGIN_MS;
3520
3708
  if (sessionExpiry.getTime() <= now2 + marginMs) {
3521
- throw new import_sdk_core6.SessionExpiredError(sessionExpiry);
3709
+ throw new import_sdk_core7.SessionExpiredError(sessionExpiry);
3522
3710
  }
3523
3711
  }
3524
3712
  if (!Array.isArray(permissions) || permissions.length === 0) {
@@ -3547,11 +3735,11 @@ var _TinyCloudNode = class _TinyCloudNode {
3547
3735
  );
3548
3736
  return { delegation: delegation2, prompted: true };
3549
3737
  }
3550
- const granted = (0, import_sdk_core6.parseRecapCapabilities)(
3738
+ const granted = (0, import_sdk_core7.parseRecapCapabilities)(
3551
3739
  (siwe) => this.wasmBindings.parseRecapFromSiwe(siwe),
3552
3740
  session.siwe
3553
3741
  );
3554
- const { subset, missing } = (0, import_sdk_core6.isCapabilitySubset)(expandedEntries, granted);
3742
+ const { subset, missing } = (0, import_sdk_core7.isCapabilitySubset)(expandedEntries, granted);
3555
3743
  if (!subset) {
3556
3744
  const runtimeGrant = this.findGrantForOperations(
3557
3745
  this.permissionEntriesToOperations(expandedEntries, session)
@@ -3559,7 +3747,7 @@ var _TinyCloudNode = class _TinyCloudNode {
3559
3747
  if (runtimeGrant) {
3560
3748
  const marginMs = _TinyCloudNode.SESSION_EXPIRY_SAFETY_MARGIN_MS;
3561
3749
  if (runtimeGrant.expiresAt.getTime() <= Date.now() + marginMs) {
3562
- throw new import_sdk_core6.SessionExpiredError(runtimeGrant.expiresAt);
3750
+ throw new import_sdk_core7.SessionExpiredError(runtimeGrant.expiresAt);
3563
3751
  }
3564
3752
  const runtimeExpiration = runtimeGrant.expiresAt < effectiveExpiration ? runtimeGrant.expiresAt : effectiveExpiration;
3565
3753
  const delegation2 = await this.createDelegationViaRuntimeGrant(
@@ -3570,7 +3758,7 @@ var _TinyCloudNode = class _TinyCloudNode {
3570
3758
  );
3571
3759
  return { delegation: delegation2, prompted: false };
3572
3760
  }
3573
- throw new import_sdk_core6.PermissionNotInManifestError(missing, granted);
3761
+ throw new import_sdk_core7.PermissionNotInManifestError(missing, granted);
3574
3762
  }
3575
3763
  const delegation = await this.createDelegationViaWasmPath(
3576
3764
  did,
@@ -3592,7 +3780,7 @@ var _TinyCloudNode = class _TinyCloudNode {
3592
3780
  );
3593
3781
  }
3594
3782
  const target = request.delegationTargets.find(
3595
- (entry) => didPrincipalMatches(entry.did, did)
3783
+ (entry) => didPrincipalMatches2(entry.did, did)
3596
3784
  );
3597
3785
  if (!target) {
3598
3786
  throw new Error(`No manifest delegation target found for DID ${did}`);
@@ -3652,7 +3840,7 @@ var _TinyCloudNode = class _TinyCloudNode {
3652
3840
  const spaceId = resolvedSpaces.size === 1 ? [...resolvedSpaces][0] : session.spaceId;
3653
3841
  const abilities = {};
3654
3842
  for (const entry of entries) {
3655
- const shortService = import_sdk_core6.SERVICE_LONG_TO_SHORT[entry.service];
3843
+ const shortService = import_sdk_core7.SERVICE_LONG_TO_SHORT[entry.service];
3656
3844
  if (shortService === void 0) {
3657
3845
  throw new Error(
3658
3846
  `delegateTo: unknown service '${entry.service}' \u2014 no short-form mapping`
@@ -3692,7 +3880,7 @@ var _TinyCloudNode = class _TinyCloudNode {
3692
3880
  });
3693
3881
  const primary = result.resources[0];
3694
3882
  const delegationHeader = { Authorization: result.delegation };
3695
- const activateResult = await (0, import_sdk_core6.activateSessionWithHost)(
3883
+ const activateResult = await (0, import_sdk_core7.activateSessionWithHost)(
3696
3884
  this.config.host,
3697
3885
  delegationHeader
3698
3886
  );
@@ -3727,7 +3915,7 @@ var _TinyCloudNode = class _TinyCloudNode {
3727
3915
  const primary = result.resources[0];
3728
3916
  const delegationHeader = { Authorization: result.delegation };
3729
3917
  const targetHost = grant.delegation.host ?? this.config.host;
3730
- const activateResult = await (0, import_sdk_core6.activateSessionWithHost)(
3918
+ const activateResult = await (0, import_sdk_core7.activateSessionWithHost)(
3731
3919
  targetHost,
3732
3920
  delegationHeader
3733
3921
  );
@@ -3768,10 +3956,10 @@ var _TinyCloudNode = class _TinyCloudNode {
3768
3956
  return this.wasmBindings.makeSpaceId(session.address, session.chainId, space);
3769
3957
  }
3770
3958
  expandPermissionEntries(permissions) {
3771
- return (0, import_sdk_core6.expandPermissionEntries)(permissions);
3959
+ return (0, import_sdk_core7.expandPermissionEntries)(permissions);
3772
3960
  }
3773
3961
  shortServiceName(service) {
3774
- const short = import_sdk_core6.SERVICE_LONG_TO_SHORT[service];
3962
+ const short = import_sdk_core7.SERVICE_LONG_TO_SHORT[service];
3775
3963
  if (short === void 0) {
3776
3964
  throw new Error(
3777
3965
  `unknown service '${service}' \u2014 no short-form mapping`
@@ -3797,7 +3985,7 @@ var _TinyCloudNode = class _TinyCloudNode {
3797
3985
  return abilities;
3798
3986
  }
3799
3987
  isEncryptionPermissionEntry(entry) {
3800
- return entry.service === import_sdk_core6.ENCRYPTION_PERMISSION_SERVICE && entry.path.startsWith("urn:tinycloud:encryption:");
3988
+ return entry.service === import_sdk_core7.ENCRYPTION_PERMISSION_SERVICE && entry.path.startsWith("urn:tinycloud:encryption:");
3801
3989
  }
3802
3990
  permissionsToRawAbilities(entries) {
3803
3991
  const rawAbilities = {};
@@ -3830,11 +4018,11 @@ var _TinyCloudNode = class _TinyCloudNode {
3830
4018
  }
3831
4019
  sessionCoversPermissionEntries(session, entries) {
3832
4020
  try {
3833
- const granted = (0, import_sdk_core6.parseRecapCapabilities)(
4021
+ const granted = (0, import_sdk_core7.parseRecapCapabilities)(
3834
4022
  (siwe) => this.wasmBindings.parseRecapFromSiwe(siwe),
3835
4023
  session.siwe
3836
4024
  );
3837
- return (0, import_sdk_core6.isCapabilitySubset)(entries, granted).subset;
4025
+ return (0, import_sdk_core7.isCapabilitySubset)(entries, granted).subset;
3838
4026
  } catch {
3839
4027
  return false;
3840
4028
  }
@@ -4042,7 +4230,23 @@ var _TinyCloudNode = class _TinyCloudNode {
4042
4230
  if (granted.resource !== void 0 || requested.resource !== void 0) {
4043
4231
  return granted.resource !== void 0 && requested.resource !== void 0 && granted.resource === requested.resource && this.pathContains(granted.path, requested.path);
4044
4232
  }
4045
- return granted.spaceId !== void 0 && requested.spaceId !== void 0 && granted.spaceId === requested.spaceId && this.pathContains(granted.path, requested.path);
4233
+ return granted.spaceId !== void 0 && requested.spaceId !== void 0 && this.spaceIdsEqual(granted.spaceId, requested.spaceId) && this.pathContains(granted.path, requested.path);
4234
+ }
4235
+ // Space IDs are `tinycloud:pkh:eip155:<chain>:<0xADDR>:<name>`. The embedded
4236
+ // EIP-155 address is case-insensitive, but the CLI canonicalizes it to
4237
+ // lowercase when building a space URI while stored runtime delegations keep
4238
+ // the EIP-55 checksummed form — so a byte-for-byte compare spuriously rejects
4239
+ // an otherwise-valid grant. Lowercase ONLY the `eip155:<chain>:0x<addr>`
4240
+ // segment and leave everything else (crucially the case-sensitive space NAME)
4241
+ // byte-exact. Mirrors the CLI's `normalizeSpaceForCompare` (OPENKEY_SCOPE_MISMATCH fix).
4242
+ spaceIdsEqual(a, b) {
4243
+ return this.normalizeSpaceAddress(a) === this.normalizeSpaceAddress(b);
4244
+ }
4245
+ normalizeSpaceAddress(space) {
4246
+ return space.replace(
4247
+ /(eip155:\d+:)(0x[0-9a-fA-F]{40})/,
4248
+ (_match, prefix, addr) => prefix + addr.toLowerCase()
4249
+ );
4046
4250
  }
4047
4251
  actionContains(grantedAction, requestedAction) {
4048
4252
  if (grantedAction === requestedAction) {
@@ -4149,7 +4353,7 @@ var _TinyCloudNode = class _TinyCloudNode {
4149
4353
  if (resolvedDelegateDID.endsWith(".eth") && this.config.ensResolver) {
4150
4354
  const address = await this.config.ensResolver.resolveAddress(resolvedDelegateDID);
4151
4355
  if (!address) throw new Error(`Could not resolve ENS name: ${resolvedDelegateDID}`);
4152
- resolvedDelegateDID = (0, import_sdk_core6.pkhDid)(address, 1);
4356
+ resolvedDelegateDID = (0, import_sdk_core7.pkhDid)(address, 1);
4153
4357
  }
4154
4358
  const entries = legacyParamsToPermissionEntries(
4155
4359
  params.actions,
@@ -4164,7 +4368,7 @@ var _TinyCloudNode = class _TinyCloudNode {
4164
4368
  );
4165
4369
  return result.delegation;
4166
4370
  } catch (err) {
4167
- if (err instanceof import_sdk_core6.PermissionNotInManifestError) {
4371
+ if (err instanceof import_sdk_core7.PermissionNotInManifestError) {
4168
4372
  } else {
4169
4373
  throw err;
4170
4374
  }
@@ -4221,7 +4425,7 @@ var _TinyCloudNode = class _TinyCloudNode {
4221
4425
  ...prepared,
4222
4426
  signature
4223
4427
  });
4224
- const activateResult = await (0, import_sdk_core6.activateSessionWithHost)(
4428
+ const activateResult = await (0, import_sdk_core7.activateSessionWithHost)(
4225
4429
  this.config.host,
4226
4430
  delegationSession.delegationHeader
4227
4431
  );
@@ -4243,7 +4447,7 @@ var _TinyCloudNode = class _TinyCloudNode {
4243
4447
  };
4244
4448
  const hasKvActions = params.actions.some((a) => a.startsWith("tinycloud.kv/"));
4245
4449
  if (hasKvActions && params.includePublicSpace !== false) {
4246
- const publicSpaceId = (0, import_sdk_core6.makePublicSpaceId)(
4450
+ const publicSpaceId = (0, import_sdk_core7.makePublicSpaceId)(
4247
4451
  this.wasmBindings.ensureEip55(session.address),
4248
4452
  session.chainId
4249
4453
  );
@@ -4266,7 +4470,7 @@ var _TinyCloudNode = class _TinyCloudNode {
4266
4470
  ...publicPrepared,
4267
4471
  signature: publicSignature
4268
4472
  });
4269
- const publicActivateResult = await (0, import_sdk_core6.activateSessionWithHost)(
4473
+ const publicActivateResult = await (0, import_sdk_core7.activateSessionWithHost)(
4270
4474
  this.config.host,
4271
4475
  publicSession.delegationHeader
4272
4476
  );
@@ -4306,7 +4510,7 @@ var _TinyCloudNode = class _TinyCloudNode {
4306
4510
  const targetHost = delegation.host ?? this.config.host;
4307
4511
  if (this.isSessionOnly) {
4308
4512
  const myDid = this.did;
4309
- if (!didPrincipalMatches(delegation.delegateDID, myDid)) {
4513
+ if (!didPrincipalMatches2(delegation.delegateDID, myDid)) {
4310
4514
  throw new Error(
4311
4515
  `Delegation targets ${delegation.delegateDID} but this user's DID is ${myDid}. The delegation must target this user's DID.`
4312
4516
  );
@@ -4371,7 +4575,7 @@ var _TinyCloudNode = class _TinyCloudNode {
4371
4575
  ...prepared,
4372
4576
  signature
4373
4577
  });
4374
- const activateResult = await (0, import_sdk_core6.activateSessionWithHost)(
4578
+ const activateResult = await (0, import_sdk_core7.activateSessionWithHost)(
4375
4579
  targetHost,
4376
4580
  invokerSession.delegationHeader
4377
4581
  );
@@ -4477,7 +4681,7 @@ var _TinyCloudNode = class _TinyCloudNode {
4477
4681
  ...prepared,
4478
4682
  signature
4479
4683
  });
4480
- const activateResult = await (0, import_sdk_core6.activateSessionWithHost)(
4684
+ const activateResult = await (0, import_sdk_core7.activateSessionWithHost)(
4481
4685
  targetHost,
4482
4686
  subDelegationSession.delegationHeader
4483
4687
  );
@@ -4513,7 +4717,7 @@ _TinyCloudNode.SESSION_EXPIRY_SAFETY_MARGIN_MS = 6e4;
4513
4717
  var TinyCloudNode = _TinyCloudNode;
4514
4718
 
4515
4719
  // src/core.ts
4516
- var import_sdk_core9 = require("@tinycloud/sdk-core");
4720
+ var import_sdk_core10 = require("@tinycloud/sdk-core");
4517
4721
 
4518
4722
  // src/delegation.ts
4519
4723
  function serializeDelegation(delegation) {
@@ -4532,7 +4736,6 @@ function deserializeDelegation(data) {
4532
4736
  }
4533
4737
 
4534
4738
  // src/core.ts
4535
- var import_sdk_core10 = require("@tinycloud/sdk-core");
4536
4739
  var import_sdk_core11 = require("@tinycloud/sdk-core");
4537
4740
  var import_sdk_core12 = require("@tinycloud/sdk-core");
4538
4741
  var import_sdk_core13 = require("@tinycloud/sdk-core");
@@ -4541,10 +4744,12 @@ var import_sdk_core15 = require("@tinycloud/sdk-core");
4541
4744
  var import_sdk_core16 = require("@tinycloud/sdk-core");
4542
4745
  var import_sdk_core17 = require("@tinycloud/sdk-core");
4543
4746
  var import_sdk_core18 = require("@tinycloud/sdk-core");
4747
+ var import_sdk_core19 = require("@tinycloud/sdk-core");
4544
4748
  // Annotate the CommonJS export names for ESM import in node:
4545
4749
  0 && (module.exports = {
4546
4750
  ACCOUNT_REGISTRY_PATH,
4547
4751
  ACCOUNT_REGISTRY_SPACE,
4752
+ AccountService,
4548
4753
  AutoApproveSpaceCreationHandler,
4549
4754
  CapabilityKeyRegistry,
4550
4755
  CapabilityKeyRegistryErrorCodes,