@tinycloud/node-sdk 2.4.0 → 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.d.cts CHANGED
@@ -1,4 +1,4 @@
1
1
  export { ACCOUNT_REGISTRY_PATH, ACCOUNT_REGISTRY_SPACE, AccountApplication, AccountApplicationListOptions, AccountDelegation, AccountDelegationListOptions, AccountDelegationRevokeOptions, AccountIndexEnsureResult, AccountIndexRebuildResult, AccountIndexStatus, AccountIndexedReadOptions, AccountService, AccountServiceConfig, AccountSpace, AccountSpaceListOptions, AccountStatus, AutoApproveSpaceCreationHandler, AutoRejectStrategy, AutoSignStrategy, BatchOptions, BatchResponse, CallbackStrategy, CanonicalAddress, CanonicalParsedNetworkId, CapabilityEntry, CapabilityKeyRegistry, CapabilityKeyRegistryErrorCode, CapabilityKeyRegistryErrorCodes, ClientSession, ColumnInfo, ComposeManifestOptions, ComposedManifestRequest, CreateDelegationParams, DEFAULT_MANIFEST_SPACE, DEFAULT_MANIFEST_VERSION, DEFAULT_SIGNED_READ_URL_EXPIRY_MS, DataVaultConfig, DataVaultService, DatabaseHandle, Delegation, DelegationChain, DelegationChainV2, DelegationDirection, DelegationError, DelegationErrorCode, DelegationErrorCodes, DelegationFilters, DelegationManager, DelegationManagerConfig, DelegationRecord, DelegationResult, DidCacheKeyOptions, DidEqualsOptions, DuckDbAction, DuckDbActionType, DuckDbBatchOptions, DuckDbBatchResponse, DuckDbDatabaseHandle, DuckDbExecuteOptions, DuckDbExecuteResponse, DuckDbOptions, DuckDbQueryOptions, DuckDbQueryResponse, DuckDbService, DuckDbServiceConfig, DuckDbStatement, DuckDbValue, EncodedShareData, ExecuteOptions, ExecuteResponse, Extension, FetchFunction, GenerateShareParams, ICapabilityKeyRegistry, IDataVaultService, IDatabaseHandle, IDuckDbDatabaseHandle, IDuckDbService, IENSResolver, IKVService, INotificationHandler, IPrefixedKVService, ISQLService, ISecretsService, ISessionManager, ISessionStorage, ISharingService, ISigner, ISpace, ISpaceCreationHandler, ISpaceScopedDelegations, ISpaceScopedSharing, ISpaceService, IUserAuthorization, IWasmBindings, IdentityParseError, IngestOptions, InvokeFunction, JWK, KVCreateSignedReadUrlOptions, KVResponse, KVService, KVServiceConfig, KVSignedReadUrlResponse, KeyInfo, KeyProvider, KeyType, Manifest, ManifestDefaults, ManifestRegistryRecord, ManifestSecretActions, ManifestValidationError, OpenKeyCallbackStrategy, OpenKeySigningRequestBody, OpenKeySigningResponseBody, OpenKeySigningStrategyOptions, PermissionEntry, PermissionNotInManifestError, PersistedSessionData, PkhDidParts, PrefixedKVService, ProtocolMismatchError, QueryOptions, QueryResponse, ReceiveOptions, ResolvedCapabilities, ResolvedDelegate, ResolvedSecretPath, ResourceCapability, SECRET_NAME_RE, SQLAction, SQLActionType, SQLService, SQLServiceConfig, SchemaInfo, SecretPayload, SecretScopeOptions, SecretsError, SecretsService, ServiceContext, ServiceContextConfig, ServiceSession, SessionExpiredError, ShareAccess, ShareLink, ShareLinkData, ShareSchema, SharingService, SharingServiceConfig, SignCallback, SignInOptions, SignRequest, SignResponse, SilentNotificationHandler, Space, SpaceAbilitiesMap, SpaceConfig, SpaceCreationContext, SpaceErrorCode, SpaceErrorCodes, SpaceInfo, SpaceOwnership, SpaceService, SpaceServiceConfig, SqlStatement, SqlValue, StoredDelegationChain, TableInfo, TelemetryConfig, TelemetryEventHandler, TinyCloud, TinyCloudConfig, TinyCloudDebugEnableOptions, TinyCloudDebugEvent, TinyCloudDebugLevel, TinyCloudDebugLogger, TinyCloudDebugTimer, TinyCloudSession, UnsupportedFeatureError, VAULT_PERMISSION_SERVICE, VaultCrypto, VaultEntry, VaultError, VaultGetOptions, VaultGrantOptions, VaultHeaders, VaultListOptions, VaultPublicSpaceKVActions, VaultPutOptions, VersionCheckError, ViewInfo, WasmVaultFunctions, addressStorageKey, buildSpaceUri, canonicalizeAddress, canonicalizeDid, canonicalizeDidUrl, canonicalizeNetworkId, canonicalizeSecretScope, checkNodeInfo, clearTinyCloudDebugLogs, composeManifestRequest, createCapabilityKeyRegistry, createOpenKeyCallbackSigningStrategy, createSharingService, createSpaceService, createVaultCrypto, defaultSpaceCreationHandler, didCacheKey, didEquals, disableTinyCloudDebug, enableTinyCloudDebug, expandActionShortNames, expandPermissionEntries, expandPermissionEntry, getTinyCloudDebugLogs, installTinyCloudDebugGlobals, isCapabilitySubset, isEvmAddress, loadManifest, makePkhSpaceId, makePublicSpaceId, parseCanonicalNetworkId, parseExpiry, parsePkhDid, parseSpaceUri, pkhDid, principalDid, principalDidEquals, resolveManifest, resolveSecretListPrefix, resolveSecretPath, resourceCapabilitiesToSpaceAbilitiesMap, tinyCloudDebugLogger, validateManifest } from '@tinycloud/sdk-core';
2
- export { D as DelegateToOptions, b as DelegateToResult, c as DelegatedAccess, F as FileSessionStorage, M as MemorySessionStorage, N as NodeEventEmitterStrategy, e as NodeUserAuthorization, f as NodeUserAuthorizationConfig, P as PortableDelegation, g as RuntimePermissionGrantOptions, S as SignStrategy, T as TinyCloudNode, h as TinyCloudNodeConfig, W as WasmKeyProvider, i as WasmKeyProviderConfig, j as createWasmKeyProvider, k as defaultSignStrategy, l as deserializeDelegation, s as serializeDelegation } from './core-DfE4s_Rg.cjs';
2
+ export { D as DelegateToOptions, b as DelegateToResult, c as DelegatedAccess, F as FileSessionStorage, M as MemorySessionStorage, N as NodeEventEmitterStrategy, e as NodeUserAuthorization, f as NodeUserAuthorizationConfig, P as PortableDelegation, g as RuntimePermissionGrantOptions, S as SignStrategy, T as TinyCloudNode, h as TinyCloudNodeConfig, W as WasmKeyProvider, i as WasmKeyProviderConfig, j as createWasmKeyProvider, k as defaultSignStrategy, l as deserializeDelegation, s as serializeDelegation } from './core-D01sn2vf.cjs';
3
3
  import 'events';
4
4
  import '@tinycloud/sdk-services';
package/dist/core.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export { ACCOUNT_REGISTRY_PATH, ACCOUNT_REGISTRY_SPACE, AccountApplication, AccountApplicationListOptions, AccountDelegation, AccountDelegationListOptions, AccountDelegationRevokeOptions, AccountIndexEnsureResult, AccountIndexRebuildResult, AccountIndexStatus, AccountIndexedReadOptions, AccountService, AccountServiceConfig, AccountSpace, AccountSpaceListOptions, AccountStatus, AutoApproveSpaceCreationHandler, AutoRejectStrategy, AutoSignStrategy, BatchOptions, BatchResponse, CallbackStrategy, CanonicalAddress, CanonicalParsedNetworkId, CapabilityEntry, CapabilityKeyRegistry, CapabilityKeyRegistryErrorCode, CapabilityKeyRegistryErrorCodes, ClientSession, ColumnInfo, ComposeManifestOptions, ComposedManifestRequest, CreateDelegationParams, DEFAULT_MANIFEST_SPACE, DEFAULT_MANIFEST_VERSION, DEFAULT_SIGNED_READ_URL_EXPIRY_MS, DataVaultConfig, DataVaultService, DatabaseHandle, Delegation, DelegationChain, DelegationChainV2, DelegationDirection, DelegationError, DelegationErrorCode, DelegationErrorCodes, DelegationFilters, DelegationManager, DelegationManagerConfig, DelegationRecord, DelegationResult, DidCacheKeyOptions, DidEqualsOptions, DuckDbAction, DuckDbActionType, DuckDbBatchOptions, DuckDbBatchResponse, DuckDbDatabaseHandle, DuckDbExecuteOptions, DuckDbExecuteResponse, DuckDbOptions, DuckDbQueryOptions, DuckDbQueryResponse, DuckDbService, DuckDbServiceConfig, DuckDbStatement, DuckDbValue, EncodedShareData, ExecuteOptions, ExecuteResponse, Extension, FetchFunction, GenerateShareParams, ICapabilityKeyRegistry, IDataVaultService, IDatabaseHandle, IDuckDbDatabaseHandle, IDuckDbService, IENSResolver, IKVService, INotificationHandler, IPrefixedKVService, ISQLService, ISecretsService, ISessionManager, ISessionStorage, ISharingService, ISigner, ISpace, ISpaceCreationHandler, ISpaceScopedDelegations, ISpaceScopedSharing, ISpaceService, IUserAuthorization, IWasmBindings, IdentityParseError, IngestOptions, InvokeFunction, JWK, KVCreateSignedReadUrlOptions, KVResponse, KVService, KVServiceConfig, KVSignedReadUrlResponse, KeyInfo, KeyProvider, KeyType, Manifest, ManifestDefaults, ManifestRegistryRecord, ManifestSecretActions, ManifestValidationError, OpenKeyCallbackStrategy, OpenKeySigningRequestBody, OpenKeySigningResponseBody, OpenKeySigningStrategyOptions, PermissionEntry, PermissionNotInManifestError, PersistedSessionData, PkhDidParts, PrefixedKVService, ProtocolMismatchError, QueryOptions, QueryResponse, ReceiveOptions, ResolvedCapabilities, ResolvedDelegate, ResolvedSecretPath, ResourceCapability, SECRET_NAME_RE, SQLAction, SQLActionType, SQLService, SQLServiceConfig, SchemaInfo, SecretPayload, SecretScopeOptions, SecretsError, SecretsService, ServiceContext, ServiceContextConfig, ServiceSession, SessionExpiredError, ShareAccess, ShareLink, ShareLinkData, ShareSchema, SharingService, SharingServiceConfig, SignCallback, SignInOptions, SignRequest, SignResponse, SilentNotificationHandler, Space, SpaceAbilitiesMap, SpaceConfig, SpaceCreationContext, SpaceErrorCode, SpaceErrorCodes, SpaceInfo, SpaceOwnership, SpaceService, SpaceServiceConfig, SqlStatement, SqlValue, StoredDelegationChain, TableInfo, TelemetryConfig, TelemetryEventHandler, TinyCloud, TinyCloudConfig, TinyCloudDebugEnableOptions, TinyCloudDebugEvent, TinyCloudDebugLevel, TinyCloudDebugLogger, TinyCloudDebugTimer, TinyCloudSession, UnsupportedFeatureError, VAULT_PERMISSION_SERVICE, VaultCrypto, VaultEntry, VaultError, VaultGetOptions, VaultGrantOptions, VaultHeaders, VaultListOptions, VaultPublicSpaceKVActions, VaultPutOptions, VersionCheckError, ViewInfo, WasmVaultFunctions, addressStorageKey, buildSpaceUri, canonicalizeAddress, canonicalizeDid, canonicalizeDidUrl, canonicalizeNetworkId, canonicalizeSecretScope, checkNodeInfo, clearTinyCloudDebugLogs, composeManifestRequest, createCapabilityKeyRegistry, createOpenKeyCallbackSigningStrategy, createSharingService, createSpaceService, createVaultCrypto, defaultSpaceCreationHandler, didCacheKey, didEquals, disableTinyCloudDebug, enableTinyCloudDebug, expandActionShortNames, expandPermissionEntries, expandPermissionEntry, getTinyCloudDebugLogs, installTinyCloudDebugGlobals, isCapabilitySubset, isEvmAddress, loadManifest, makePkhSpaceId, makePublicSpaceId, parseCanonicalNetworkId, parseExpiry, parsePkhDid, parseSpaceUri, pkhDid, principalDid, principalDidEquals, resolveManifest, resolveSecretListPrefix, resolveSecretPath, resourceCapabilitiesToSpaceAbilitiesMap, tinyCloudDebugLogger, validateManifest } from '@tinycloud/sdk-core';
2
- export { D as DelegateToOptions, b as DelegateToResult, c as DelegatedAccess, F as FileSessionStorage, M as MemorySessionStorage, N as NodeEventEmitterStrategy, e as NodeUserAuthorization, f as NodeUserAuthorizationConfig, P as PortableDelegation, g as RuntimePermissionGrantOptions, S as SignStrategy, T as TinyCloudNode, h as TinyCloudNodeConfig, W as WasmKeyProvider, i as WasmKeyProviderConfig, j as createWasmKeyProvider, k as defaultSignStrategy, l as deserializeDelegation, s as serializeDelegation } from './core-DfE4s_Rg.js';
2
+ export { D as DelegateToOptions, b as DelegateToResult, c as DelegatedAccess, F as FileSessionStorage, M as MemorySessionStorage, N as NodeEventEmitterStrategy, e as NodeUserAuthorization, f as NodeUserAuthorizationConfig, P as PortableDelegation, g as RuntimePermissionGrantOptions, S as SignStrategy, T as TinyCloudNode, h as TinyCloudNodeConfig, W as WasmKeyProvider, i as WasmKeyProviderConfig, j as createWasmKeyProvider, k as defaultSignStrategy, l as deserializeDelegation, s as serializeDelegation } from './core-D01sn2vf.js';
3
3
  import 'events';
4
4
  import '@tinycloud/sdk-services';
package/dist/core.js CHANGED
@@ -1498,12 +1498,12 @@ function displayActionUrn(action) {
1498
1498
  function secretActionName(action) {
1499
1499
  return action;
1500
1500
  }
1501
- function secretPermissionEntries(name, options, action, encryptionNetworkId) {
1501
+ function secretPermissionEntries(name, options, action, space, encryptionNetworkId) {
1502
1502
  const entries = [];
1503
1503
  const path = action === "list" ? resolveSecretListPrefix(options) : resolveSecretPath(name, options).permissionPaths.vault;
1504
1504
  entries.push({
1505
1505
  service: "tinycloud.kv",
1506
- space: SECRETS_SPACE,
1506
+ space,
1507
1507
  path,
1508
1508
  actions: [secretActionName(action)],
1509
1509
  skipPrefix: true
@@ -1518,11 +1518,23 @@ function secretPermissionEntries(name, options, action, encryptionNetworkId) {
1518
1518
  }
1519
1519
  return entries;
1520
1520
  }
1521
+ function normalizeSpace(space, resolveSpace) {
1522
+ if (!space) return void 0;
1523
+ if (space.startsWith("tinycloud:")) return space;
1524
+ return resolveSpace?.(space) ?? space;
1525
+ }
1526
+ function spaceMatches(granted, requested, resolveSpace) {
1527
+ if (!granted || !requested) return false;
1528
+ return normalizeSpace(granted, resolveSpace) === normalizeSpace(requested, resolveSpace);
1529
+ }
1521
1530
  var NodeSecretsService = class {
1522
1531
  constructor(config) {
1523
1532
  this.config = config;
1524
1533
  this.shouldRestoreUnlock = false;
1525
1534
  }
1535
+ get space() {
1536
+ return this.config.space ?? SECRETS_SPACE;
1537
+ }
1526
1538
  get vault() {
1527
1539
  return this.service.vault;
1528
1540
  }
@@ -1575,6 +1587,7 @@ var NodeSecretsService = class {
1575
1587
  name,
1576
1588
  options,
1577
1589
  action,
1590
+ this.space,
1578
1591
  action === "get" ? this.config.getEncryptionNetworkId?.() : void 0
1579
1592
  );
1580
1593
  } catch (error) {
@@ -1624,7 +1637,7 @@ var NodeSecretsService = class {
1624
1637
  (entry) => manifests.some((candidate) => {
1625
1638
  const resolved = resolveManifest(candidate);
1626
1639
  return resolved.resources.some(
1627
- (resource) => resource.service === entry.service && resource.space === entry.space && resource.path === entry.path && entry.actions.every((action) => resource.actions.includes(action))
1640
+ (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))
1628
1641
  );
1629
1642
  })
1630
1643
  );
@@ -1648,6 +1661,20 @@ function didPrincipalMatches2(actual, expected) {
1648
1661
  return actual === expected;
1649
1662
  }
1650
1663
  }
1664
+ function sharingActionsToAbilities(path, actions) {
1665
+ var _a;
1666
+ const abilities = {};
1667
+ for (const action of actions) {
1668
+ const slash = action.indexOf("/");
1669
+ if (slash === -1) return void 0;
1670
+ const shortService = SERVICE_LONG_TO_SHORT[action.slice(0, slash)];
1671
+ if (shortService === void 0) return void 0;
1672
+ abilities[shortService] ?? (abilities[shortService] = {});
1673
+ (_a = abilities[shortService])[path] ?? (_a[path] = []);
1674
+ abilities[shortService][path].push(action);
1675
+ }
1676
+ return Object.keys(abilities).length > 0 ? abilities : void 0;
1677
+ }
1651
1678
  function base64UrlEncode(bytes) {
1652
1679
  const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
1653
1680
  let output = "";
@@ -1760,6 +1787,8 @@ var _TinyCloudNode = class _TinyCloudNode {
1760
1787
  this.auth = null;
1761
1788
  this.tc = null;
1762
1789
  this._chainId = 1;
1790
+ this._baseSecrets = /* @__PURE__ */ new Map();
1791
+ this._secrets = /* @__PURE__ */ new Map();
1763
1792
  this.runtimePermissionGrants = [];
1764
1793
  this.invokeWithRuntimePermissions = (session, service, path, action, facts) => {
1765
1794
  return this.wasmBindings.invoke(
@@ -2022,6 +2051,13 @@ var _TinyCloudNode = class _TinyCloudNode {
2022
2051
  get session() {
2023
2052
  return this.auth?.tinyCloudSession;
2024
2053
  }
2054
+ /**
2055
+ * Get the currently active session in the shape callers can persist and later
2056
+ * pass back to {@link restoreSession}.
2057
+ */
2058
+ get restorableSession() {
2059
+ return this.currentTinyCloudSession();
2060
+ }
2025
2061
  /**
2026
2062
  * Sign in and create a new session.
2027
2063
  * This creates the user's space if it doesn't exist.
@@ -2044,8 +2080,8 @@ var _TinyCloudNode = class _TinyCloudNode {
2044
2080
  this._hooks = void 0;
2045
2081
  this._vault = void 0;
2046
2082
  this._encryption = void 0;
2047
- this._baseSecrets = void 0;
2048
- this._secrets = void 0;
2083
+ this._baseSecrets.clear();
2084
+ this._secrets.clear();
2049
2085
  this._spaceService = void 0;
2050
2086
  this._serviceContext = void 0;
2051
2087
  this.runtimePermissionGrants = [];
@@ -2531,8 +2567,8 @@ var _TinyCloudNode = class _TinyCloudNode {
2531
2567
  this._hooks = void 0;
2532
2568
  this._vault = void 0;
2533
2569
  this._encryption = void 0;
2534
- this._baseSecrets = void 0;
2535
- this._secrets = void 0;
2570
+ this._baseSecrets.clear();
2571
+ this._secrets.clear();
2536
2572
  this._spaceService = void 0;
2537
2573
  this._serviceContext = void 0;
2538
2574
  this.runtimePermissionGrants = [];
@@ -2822,6 +2858,20 @@ var _TinyCloudNode = class _TinyCloudNode {
2822
2858
  getDefaultEncryptionNetworkId(name = DEFAULT_ENCRYPTION_NETWORK_NAME) {
2823
2859
  return `urn:tinycloud:encryption:${this.did}:${name}`;
2824
2860
  }
2861
+ getEncryptionNetworkIdForSpace(spaceId, name = DEFAULT_ENCRYPTION_NETWORK_NAME) {
2862
+ const ownerDid = this.ownerDidFromSpaceId(spaceId) ?? this.did;
2863
+ return `urn:tinycloud:encryption:${ownerDid}:${name}`;
2864
+ }
2865
+ ownerDidFromSpaceId(spaceId) {
2866
+ if (!spaceId.startsWith("tinycloud:")) return void 0;
2867
+ const body = spaceId.slice("tinycloud:".length);
2868
+ const lastSeparator = body.lastIndexOf(":");
2869
+ if (lastSeparator <= 0) return void 0;
2870
+ const owner = body.slice(0, lastSeparator);
2871
+ if (owner.startsWith("did:")) return owner;
2872
+ if (!owner.includes(":")) return void 0;
2873
+ return `did:${owner}`;
2874
+ }
2825
2875
  requireServiceSession() {
2826
2876
  const session = this._serviceContext?.session;
2827
2877
  if (!session) {
@@ -3009,7 +3059,7 @@ var _TinyCloudNode = class _TinyCloudNode {
3009
3059
  spaceId,
3010
3060
  crypto: vaultCrypto,
3011
3061
  encryption: {
3012
- networkId: this.getDefaultEncryptionNetworkId(),
3062
+ networkId: this.getEncryptionNetworkIdForSpace(spaceId),
3013
3063
  service: this.getEncryptionService(),
3014
3064
  decryptCapabilityProof: () => ({
3015
3065
  proofs: [this.requireServiceSession().delegationCid]
@@ -3140,6 +3190,9 @@ var _TinyCloudNode = class _TinyCloudNode {
3140
3190
  }
3141
3191
  return vaultService;
3142
3192
  },
3193
+ createSecretsService: (spaceId) => {
3194
+ return this.secretsForSpace(spaceId);
3195
+ },
3143
3196
  // Enable space.delegations.create() via SIWE-based delegation
3144
3197
  createDelegation: async (params) => {
3145
3198
  try {
@@ -3262,11 +3315,10 @@ var _TinyCloudNode = class _TinyCloudNode {
3262
3315
  try {
3263
3316
  const host = this.config.host;
3264
3317
  const now = /* @__PURE__ */ new Date();
3265
- const abilities = {
3266
- kv: {
3267
- [params.path]: params.actions
3268
- }
3269
- };
3318
+ const abilities = sharingActionsToAbilities(params.path, params.actions);
3319
+ if (!abilities) {
3320
+ return void 0;
3321
+ }
3270
3322
  const prepared = this.wasmBindings.prepareSession({
3271
3323
  abilities,
3272
3324
  address: this.wasmBindings.ensureEip55(session.address),
@@ -3522,27 +3574,49 @@ var _TinyCloudNode = class _TinyCloudNode {
3522
3574
  if (!this._spaceService) {
3523
3575
  throw new Error("Not signed in. Call signIn() first.");
3524
3576
  }
3525
- if (!this._secrets) {
3526
- this._secrets = new NodeSecretsService({
3527
- getService: () => this.getBaseSecrets(),
3577
+ return this.secretsForSpace("secrets");
3578
+ }
3579
+ /**
3580
+ * App-facing secrets API backed by the requested space's vault.
3581
+ */
3582
+ secretsForSpace(spaceId) {
3583
+ if (!this._spaceService) {
3584
+ throw new Error("Not signed in. Call signIn() first.");
3585
+ }
3586
+ const resolvedSpace = spaceId.startsWith("tinycloud:") ? spaceId : this.ownedSpaceId(spaceId);
3587
+ let secrets = this._secrets.get(resolvedSpace);
3588
+ if (!secrets) {
3589
+ secrets = new NodeSecretsService({
3590
+ getService: () => this.getBaseSecrets(resolvedSpace),
3591
+ space: resolvedSpace,
3528
3592
  getManifest: () => this.manifest,
3529
3593
  hasPermissions: (permissions) => this.hasRuntimePermissions(permissions),
3530
3594
  grantPermissions: (additional) => this.grantRuntimePermissions(additional),
3531
3595
  canEscalate: () => this.signer !== void 0 && this.tc !== void 0,
3532
- getEncryptionNetworkId: () => this.getDefaultEncryptionNetworkId(),
3596
+ getEncryptionNetworkId: () => this.getEncryptionNetworkIdForSpace(resolvedSpace),
3597
+ resolveSpace: (space) => space.startsWith("tinycloud:") ? space : this.ownedSpaceId(space),
3533
3598
  getUnlockSigner: () => this.signer ?? void 0
3534
3599
  });
3600
+ this._secrets.set(resolvedSpace, secrets);
3535
3601
  }
3536
- return this._secrets;
3602
+ return secrets;
3537
3603
  }
3538
- getBaseSecrets() {
3604
+ getBaseSecrets(spaceId) {
3539
3605
  if (!this._spaceService) {
3540
3606
  throw new Error("Not signed in. Call signIn() first.");
3541
3607
  }
3542
- if (!this._baseSecrets) {
3543
- this._baseSecrets = new SecretsService(() => this.space("secrets").vault);
3608
+ const resolvedSpace = spaceId.startsWith("tinycloud:") ? spaceId : this.ownedSpaceId(spaceId);
3609
+ let secrets = this._baseSecrets.get(resolvedSpace);
3610
+ if (!secrets) {
3611
+ const kvService = this.createSpaceScopedKVService(resolvedSpace);
3612
+ const vaultService = this.createVaultService(resolvedSpace, kvService);
3613
+ if (this._serviceContext) {
3614
+ vaultService.initialize(this._serviceContext);
3615
+ }
3616
+ secrets = new SecretsService(() => vaultService);
3617
+ this._baseSecrets.set(resolvedSpace, secrets);
3544
3618
  }
3545
- return this._baseSecrets;
3619
+ return secrets;
3546
3620
  }
3547
3621
  /**
3548
3622
  * Hooks write stream subscription API.