@tinycloud/node-sdk 2.4.0-beta.3 → 2.4.0-beta.6

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
- export { ACCOUNT_REGISTRY_PATH, ACCOUNT_REGISTRY_SPACE, 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, 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, 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, composeManifestRequest, createCapabilityKeyRegistry, createSharingService, createSpaceService, createVaultCrypto, defaultSpaceCreationHandler, didCacheKey, didEquals, expandActionShortNames, expandPermissionEntries, expandPermissionEntry, isCapabilitySubset, isEvmAddress, loadManifest, makePkhSpaceId, makePublicSpaceId, parseCanonicalNetworkId, parseExpiry, parsePkhDid, parseSpaceUri, pkhDid, principalDid, principalDidEquals, resolveManifest, resolveSecretListPrefix, resolveSecretPath, resourceCapabilitiesToSpaceAbilitiesMap, 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-ClOKiSR_.cjs';
1
+ export { ACCOUNT_REGISTRY_PATH, ACCOUNT_REGISTRY_SPACE, AccountApplication, AccountDelegation, AccountDelegationListOptions, AccountDelegationRevokeOptions, AccountIndexRebuildResult, AccountService, AccountServiceConfig, 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, 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, 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, composeManifestRequest, createCapabilityKeyRegistry, createSharingService, createSpaceService, createVaultCrypto, defaultSpaceCreationHandler, didCacheKey, didEquals, expandActionShortNames, expandPermissionEntries, expandPermissionEntry, isCapabilitySubset, isEvmAddress, loadManifest, makePkhSpaceId, makePublicSpaceId, parseCanonicalNetworkId, parseExpiry, parsePkhDid, parseSpaceUri, pkhDid, principalDid, principalDidEquals, resolveManifest, resolveSecretListPrefix, resolveSecretPath, resourceCapabilitiesToSpaceAbilitiesMap, 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-zT0sxgtZ.cjs';
3
3
  import 'events';
4
4
  import '@tinycloud/sdk-services';
package/dist/core.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { ACCOUNT_REGISTRY_PATH, ACCOUNT_REGISTRY_SPACE, 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, 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, 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, composeManifestRequest, createCapabilityKeyRegistry, createSharingService, createSpaceService, createVaultCrypto, defaultSpaceCreationHandler, didCacheKey, didEquals, expandActionShortNames, expandPermissionEntries, expandPermissionEntry, isCapabilitySubset, isEvmAddress, loadManifest, makePkhSpaceId, makePublicSpaceId, parseCanonicalNetworkId, parseExpiry, parsePkhDid, parseSpaceUri, pkhDid, principalDid, principalDidEquals, resolveManifest, resolveSecretListPrefix, resolveSecretPath, resourceCapabilitiesToSpaceAbilitiesMap, 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-ClOKiSR_.js';
1
+ export { ACCOUNT_REGISTRY_PATH, ACCOUNT_REGISTRY_SPACE, AccountApplication, AccountDelegation, AccountDelegationListOptions, AccountDelegationRevokeOptions, AccountIndexRebuildResult, AccountService, AccountServiceConfig, 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, 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, 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, composeManifestRequest, createCapabilityKeyRegistry, createSharingService, createSpaceService, createVaultCrypto, defaultSpaceCreationHandler, didCacheKey, didEquals, expandActionShortNames, expandPermissionEntries, expandPermissionEntry, isCapabilitySubset, isEvmAddress, loadManifest, makePkhSpaceId, makePublicSpaceId, parseCanonicalNetworkId, parseExpiry, parsePkhDid, parseSpaceUri, pkhDid, principalDid, principalDidEquals, resolveManifest, resolveSecretListPrefix, resolveSecretPath, resourceCapabilitiesToSpaceAbilitiesMap, 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-zT0sxgtZ.js';
3
3
  import 'events';
4
4
  import '@tinycloud/sdk-services';
package/dist/core.js CHANGED
@@ -17,7 +17,7 @@ import {
17
17
  parsePkhDid,
18
18
  pkhDid as pkhDid3,
19
19
  principalDid,
20
- principalDidEquals as principalDidEquals2,
20
+ principalDidEquals as principalDidEquals3,
21
21
  parseCanonicalNetworkId
22
22
  } from "@tinycloud/sdk-core";
23
23
 
@@ -222,6 +222,8 @@ import {
222
222
  DEFAULT_MANIFEST_SPACE,
223
223
  ENCRYPTION_PERMISSION_SERVICE,
224
224
  composeManifestRequest,
225
+ parseNetworkId,
226
+ principalDidEquals,
225
227
  resourceCapabilitiesToAbilitiesMap,
226
228
  resourceCapabilitiesToSpaceAbilitiesMap,
227
229
  resolveTinyCloudHosts,
@@ -235,6 +237,25 @@ import {
235
237
  var defaultSignStrategy = { type: "auto-sign" };
236
238
 
237
239
  // src/authorization/NodeUserAuthorization.ts
240
+ var DECRYPT_ACTION = "tinycloud.encryption/decrypt";
241
+ var NETWORK_CREATE_ACTION = "tinycloud.encryption/network.create";
242
+ function didPrincipalMatches(actual, expected) {
243
+ try {
244
+ return principalDidEquals(actual, expected);
245
+ } catch {
246
+ return actual === expected;
247
+ }
248
+ }
249
+ function addRawAbility(rawAbilities, resource, action) {
250
+ const actions = rawAbilities[resource];
251
+ if (actions === void 0) {
252
+ rawAbilities[resource] = [action];
253
+ return;
254
+ }
255
+ if (!actions.includes(action)) {
256
+ actions.push(action);
257
+ }
258
+ }
238
259
  var NodeUserAuthorization = class {
239
260
  constructor(config) {
240
261
  this.extensions = [];
@@ -464,20 +485,18 @@ var NodeUserAuthorization = class {
464
485
  };
465
486
  }
466
487
  const rawAbilities = {};
488
+ const currentDid = pkhDid(address, chainId);
467
489
  const spaceResources = request.resources.filter((entry) => {
468
490
  if (entry.service !== ENCRYPTION_PERMISSION_SERVICE) {
469
491
  return true;
470
492
  }
471
- const existing = rawAbilities[entry.path];
472
- if (existing === void 0) {
473
- rawAbilities[entry.path] = [...entry.actions];
474
- } else {
475
- const seen = new Set(existing);
476
- for (const action of entry.actions) {
477
- if (!seen.has(action)) {
478
- existing.push(action);
479
- seen.add(action);
480
- }
493
+ for (const action of entry.actions) {
494
+ addRawAbility(rawAbilities, entry.path, action);
495
+ }
496
+ if (entry.actions.includes(DECRYPT_ACTION)) {
497
+ const parsed = parseNetworkId(entry.path);
498
+ if (didPrincipalMatches(parsed.ownerDid, currentDid)) {
499
+ addRawAbility(rawAbilities, entry.path, NETWORK_CREATE_ACTION);
481
500
  }
482
501
  }
483
502
  return false;
@@ -1070,9 +1089,13 @@ import {
1070
1089
  verifyDidKeyEd25519Signature,
1071
1090
  canonicalizeAddress as canonicalizeAddress2,
1072
1091
  pkhDid as pkhDid2,
1073
- principalDidEquals
1092
+ principalDidEquals as principalDidEquals2,
1093
+ parseNetworkId as parseNetworkId2
1074
1094
  } from "@tinycloud/sdk-core";
1075
1095
 
1096
+ // src/account/AccountService.ts
1097
+ import { AccountService } from "@tinycloud/sdk-core";
1098
+
1076
1099
  // src/DelegatedAccess.ts
1077
1100
  import {
1078
1101
  KVService,
@@ -1490,13 +1513,13 @@ var NodeSecretsService = class {
1490
1513
  // src/TinyCloudNode.ts
1491
1514
  var DEFAULT_HOST = "https://node.tinycloud.xyz";
1492
1515
  var DEFAULT_ENCRYPTION_NETWORK_NAME = "default";
1493
- var NETWORK_CREATE_ACTION = "tinycloud.encryption/network.create";
1494
- var DECRYPT_ACTION = "tinycloud.encryption/decrypt";
1516
+ var NETWORK_CREATE_ACTION2 = "tinycloud.encryption/network.create";
1517
+ var DECRYPT_ACTION2 = "tinycloud.encryption/decrypt";
1495
1518
  var NETWORK_ADMIN_TYPE = "tinycloud.encryption.network-admin/v1";
1496
1519
  var DEFAULT_SESSION_EXPIRATION_MS = EXPIRY3.SESSION_MS;
1497
- function didPrincipalMatches(actual, expected) {
1520
+ function didPrincipalMatches2(actual, expected) {
1498
1521
  try {
1499
- return principalDidEquals(actual, expected);
1522
+ return principalDidEquals2(actual, expected);
1500
1523
  } catch {
1501
1524
  return actual === expected;
1502
1525
  }
@@ -1833,6 +1856,37 @@ var _TinyCloudNode = class _TinyCloudNode {
1833
1856
  get spaceId() {
1834
1857
  return this.auth?.tinyCloudSession?.spaceId;
1835
1858
  }
1859
+ /**
1860
+ * Get the account space ID for this wallet identity.
1861
+ * Available after wallet-backed sign-in or a restored session with address metadata.
1862
+ */
1863
+ get accountSpaceId() {
1864
+ if (!this._address) {
1865
+ return void 0;
1866
+ }
1867
+ return this.wasmBindings.makeSpaceId(this._address, this._chainId, ACCOUNT_REGISTRY_SPACE);
1868
+ }
1869
+ /**
1870
+ * Account-level application and delegation helpers.
1871
+ */
1872
+ get account() {
1873
+ if (!this._account) {
1874
+ this._account = new AccountService({
1875
+ getDid: () => this.did,
1876
+ getHost: () => this.hosts[0] ?? this.config.host,
1877
+ getPrimarySpaceId: () => this.spaceId,
1878
+ getAccountSpaceId: () => this.accountSpaceId,
1879
+ getSpaces: () => this.spaces,
1880
+ getAccountDb: () => this.accountSpaceId ? this.sqlForSpace(this.accountSpaceId).db("account") : void 0,
1881
+ ensureAccountSpaceHosted: async () => {
1882
+ if (this.accountSpaceId && this.auth) {
1883
+ await this.ensureOwnedSpaceHosted(this.accountSpaceId);
1884
+ }
1885
+ }
1886
+ });
1887
+ }
1888
+ return this._account;
1889
+ }
1836
1890
  /**
1837
1891
  * Get the current TinyCloud session.
1838
1892
  * Available after signIn().
@@ -1870,6 +1924,7 @@ var _TinyCloudNode = class _TinyCloudNode {
1870
1924
  await this.tc.signIn(options);
1871
1925
  this.syncResolvedHostFromAuth();
1872
1926
  this.initializeServices();
1927
+ await this.ensureRequestedEncryptionNetworks();
1873
1928
  if (this.config.manifest === void 0 && this.config.capabilityRequest === void 0) {
1874
1929
  await this.ensureOwnedSpaceHosted(this.ownedSpaceId("secrets"));
1875
1930
  }
@@ -1906,6 +1961,31 @@ var _TinyCloudNode = class _TinyCloudNode {
1906
1961
  }
1907
1962
  }
1908
1963
  }
1964
+ requestedEncryptionNetworkIds() {
1965
+ const request = this.capabilityRequest;
1966
+ if (!request) {
1967
+ return [];
1968
+ }
1969
+ const networkIds = /* @__PURE__ */ new Set();
1970
+ for (const resource of request.resources) {
1971
+ if (resource.service === ENCRYPTION_PERMISSION_SERVICE2 && resource.path.startsWith("urn:tinycloud:encryption:") && resource.actions.includes(DECRYPT_ACTION2)) {
1972
+ networkIds.add(resource.path);
1973
+ }
1974
+ }
1975
+ return [...networkIds];
1976
+ }
1977
+ async ensureRequestedEncryptionNetworks() {
1978
+ if (!this.signer || !this.auth) {
1979
+ return;
1980
+ }
1981
+ for (const networkId of this.requestedEncryptionNetworkIds()) {
1982
+ const parsed = parseNetworkId2(networkId);
1983
+ if (!didPrincipalMatches2(parsed.ownerDid, this.did)) {
1984
+ continue;
1985
+ }
1986
+ await this.ensureEncryptionNetwork(networkId);
1987
+ }
1988
+ }
1909
1989
  async ensureOwnedSpaceHosted(spaceId) {
1910
1990
  if (!this.auth) {
1911
1991
  throw new Error("Owned space hosting requires wallet mode");
@@ -2374,7 +2454,7 @@ var _TinyCloudNode = class _TinyCloudNode {
2374
2454
  const signed = await this.signRawNetworkAuthorization({
2375
2455
  targetNode: input.targetNode,
2376
2456
  networkId: input.networkId,
2377
- action: DECRYPT_ACTION,
2457
+ action: DECRYPT_ACTION2,
2378
2458
  facts: input.facts
2379
2459
  });
2380
2460
  return {
@@ -2391,7 +2471,7 @@ var _TinyCloudNode = class _TinyCloudNode {
2391
2471
  },
2392
2472
  wellKnown: {
2393
2473
  fetchWellKnown: async (principal, discoveryKey) => {
2394
- if (!this._address || !didPrincipalMatches(principal, this.did)) {
2474
+ if (!this._address || !didPrincipalMatches2(principal, this.did)) {
2395
2475
  return null;
2396
2476
  }
2397
2477
  if (!this.config.host) {
@@ -2898,12 +2978,12 @@ var _TinyCloudNode = class _TinyCloudNode {
2898
2978
  crypto.sha256,
2899
2979
  body
2900
2980
  ),
2901
- action: NETWORK_CREATE_ACTION
2981
+ action: NETWORK_CREATE_ACTION2
2902
2982
  };
2903
2983
  const signed = await this.signRawNetworkAuthorization({
2904
2984
  targetNode,
2905
2985
  networkId,
2906
- action: NETWORK_CREATE_ACTION,
2986
+ action: NETWORK_CREATE_ACTION2,
2907
2987
  facts
2908
2988
  });
2909
2989
  const response = await fetch(`${this.config.host}/encryption/networks`, {
@@ -2924,12 +3004,19 @@ var _TinyCloudNode = class _TinyCloudNode {
2924
3004
  const created = await response.json();
2925
3005
  return created.descriptor;
2926
3006
  }
2927
- async ensureEncryptionNetwork(name = DEFAULT_ENCRYPTION_NETWORK_NAME) {
2928
- const existing = await this.getEncryptionNetwork(name);
3007
+ async ensureEncryptionNetwork(nameOrNetworkId = DEFAULT_ENCRYPTION_NETWORK_NAME) {
3008
+ const networkId = nameOrNetworkId.startsWith("urn:tinycloud:encryption:") ? nameOrNetworkId : this.getDefaultEncryptionNetworkId(nameOrNetworkId);
3009
+ const existing = await this.getEncryptionNetwork(networkId);
2929
3010
  if (existing) {
2930
3011
  return existing;
2931
3012
  }
2932
- return this.createEncryptionNetwork(name);
3013
+ const parsed = parseNetworkId2(networkId);
3014
+ if (!didPrincipalMatches2(parsed.ownerDid, this.did)) {
3015
+ throw new Error(
3016
+ `Cannot create encryption network ${networkId}: owner ${parsed.ownerDid} does not match signed-in DID ${this.did}`
3017
+ );
3018
+ }
3019
+ return this.createEncryptionNetwork(parsed.name);
2933
3020
  }
2934
3021
  /**
2935
3022
  * App-facing secrets API backed by the `secrets` space vault.
@@ -3077,7 +3164,7 @@ var _TinyCloudNode = class _TinyCloudNode {
3077
3164
  throw new SessionExpiredError(delegation.expiry);
3078
3165
  }
3079
3166
  const expectedDids = [session.verificationMethod, this.sessionDid];
3080
- if (!expectedDids.some((did) => didPrincipalMatches(delegation.delegateDID, did))) {
3167
+ if (!expectedDids.some((did) => didPrincipalMatches2(delegation.delegateDID, did))) {
3081
3168
  throw new Error(
3082
3169
  `Runtime delegation targets ${delegation.delegateDID} but this session key is ${session.verificationMethod}.`
3083
3170
  );
@@ -3606,7 +3693,7 @@ var _TinyCloudNode = class _TinyCloudNode {
3606
3693
  );
3607
3694
  }
3608
3695
  const target = request.delegationTargets.find(
3609
- (entry) => didPrincipalMatches(entry.did, did)
3696
+ (entry) => didPrincipalMatches2(entry.did, did)
3610
3697
  );
3611
3698
  if (!target) {
3612
3699
  throw new Error(`No manifest delegation target found for DID ${did}`);
@@ -4336,7 +4423,7 @@ var _TinyCloudNode = class _TinyCloudNode {
4336
4423
  const targetHost = delegation.host ?? this.config.host;
4337
4424
  if (this.isSessionOnly) {
4338
4425
  const myDid = this.did;
4339
- if (!didPrincipalMatches(delegation.delegateDID, myDid)) {
4426
+ if (!didPrincipalMatches2(delegation.delegateDID, myDid)) {
4340
4427
  throw new Error(
4341
4428
  `Delegation targets ${delegation.delegateDID} but this user's DID is ${myDid}. The delegation must target this user's DID.`
4342
4429
  );
@@ -4633,6 +4720,7 @@ import { ServiceContext as ServiceContext3 } from "@tinycloud/sdk-core";
4633
4720
  export {
4634
4721
  ACCOUNT_REGISTRY_PATH,
4635
4722
  ACCOUNT_REGISTRY_SPACE2 as ACCOUNT_REGISTRY_SPACE,
4723
+ AccountService,
4636
4724
  AutoApproveSpaceCreationHandler2 as AutoApproveSpaceCreationHandler,
4637
4725
  CapabilityKeyRegistry2 as CapabilityKeyRegistry,
4638
4726
  CapabilityKeyRegistryErrorCodes,
@@ -4708,7 +4796,7 @@ export {
4708
4796
  parseSpaceUri,
4709
4797
  pkhDid3 as pkhDid,
4710
4798
  principalDid,
4711
- principalDidEquals2 as principalDidEquals,
4799
+ principalDidEquals3 as principalDidEquals,
4712
4800
  resolveManifest2 as resolveManifest,
4713
4801
  resolveSecretListPrefix2 as resolveSecretListPrefix,
4714
4802
  resolveSecretPath2 as resolveSecretPath,