@tinycloud/node-sdk 2.2.0-beta.6 → 2.2.0-beta.7

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/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ISigner, Bytes, IWasmBindings, ISessionManager } from '@tinycloud/sdk-core';
2
- export { ACCOUNT_REGISTRY_PATH, ACCOUNT_REGISTRY_SPACE, AutoApproveSpaceCreationHandler, AutoRejectStrategy, AutoSignStrategy, BatchOptions, BatchResponse, CallbackStrategy, CapabilityEntry, CapabilityKeyRegistry, CapabilityKeyRegistryErrorCode, CapabilityKeyRegistryErrorCodes, ClientSession, ColumnInfo, ComposeManifestOptions, ComposedManifestRequest, CreateDelegationParams, DEFAULT_MANIFEST_SPACE, DEFAULT_MANIFEST_VERSION, DataVaultConfig, DataVaultService, DatabaseHandle, Delegation, DelegationChain, DelegationChainV2, DelegationDirection, DelegationError, DelegationErrorCode, DelegationErrorCodes, DelegationFilters, DelegationManager, DelegationManagerConfig, DelegationRecord, DelegationResult, DuckDbAction, DuckDbActionType, DuckDbBatchOptions, DuckDbBatchResponse, DuckDbDatabaseHandle, DuckDbExecuteOptions, DuckDbExecuteResponse, DuckDbOptions, DuckDbQueryOptions, DuckDbQueryResponse, DuckDbService, DuckDbServiceConfig, DuckDbStatement, DuckDbValue, EncodedShareData, ExecuteOptions, ExecuteResponse, Extension, FetchFunction, GenerateShareParams, HookEvent, HookServiceName, HookStreamEvent, HookSubscription, HookWebhookListOptions, HookWebhookRecord, HookWebhookRegistration, HookWebhookScope, HookWebhookUnregisterOptions, HooksService, HooksServiceConfig, ICapabilityKeyRegistry, IDataVaultService, IDatabaseHandle, IDuckDbDatabaseHandle, IDuckDbService, IENSResolver, IHooksService, IKVService, INotificationHandler, IPrefixedKVService, ISQLService, ISessionManager, ISessionStorage, ISharingService, ISigner, ISpace, ISpaceCreationHandler, ISpaceScopedDelegations, ISpaceScopedSharing, ISpaceService, IUserAuthorization, IWasmBindings, IngestOptions, InvokeFunction, JWK, KVResponse, KVService, KVServiceConfig, KeyInfo, KeyProvider, KeyType, Manifest, ManifestDefaults, ManifestRegistryRecord, ManifestValidationError, PermissionEntry, PermissionNotInManifestError, PersistedSessionData, PrefixedKVService, ProtocolMismatchError, QueryOptions, QueryResponse, ReceiveOptions, ResolvedCapabilities, ResolvedDelegate, ResourceCapability, SQLAction, SQLActionType, SQLService, SQLServiceConfig, SchemaInfo, 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, SubscribeOptions, TableInfo, TinyCloud, TinyCloudConfig, TinyCloudSession, UnsupportedFeatureError, VaultCrypto, VaultEntry, VaultError, VaultGetOptions, VaultGrantOptions, VaultHeaders, VaultListOptions, VaultPublicSpaceKVActions, VaultPutOptions, VersionCheckError, ViewInfo, WasmVaultFunctions, buildSpaceUri, checkNodeInfo, composeManifestRequest, createCapabilityKeyRegistry, createSharingService, createSpaceService, createVaultCrypto, defaultSpaceCreationHandler, expandActionShortNames, isCapabilitySubset, loadManifest, makePublicSpaceId, parseExpiry, parseSpaceUri, resolveManifest, resourceCapabilitiesToSpaceAbilitiesMap, validateManifest } from '@tinycloud/sdk-core';
3
- export { D as DelegateToOptions, a as DelegateToResult, b as DelegatedAccess, F as FileSessionStorage, M as MemorySessionStorage, N as NodeEventEmitterStrategy, c as NodeUserAuthorization, d as NodeUserAuthorizationConfig, P as PortableDelegation, R as RestorableSession, S as SignStrategy, T as TinyCloudNode, e as TinyCloudNodeConfig, W as WasmKeyProvider, f as WasmKeyProviderConfig, g as createWasmKeyProvider, h as defaultSignStrategy, i as deserializeDelegation, s as serializeDelegation } from './core-DdMPUB5s.cjs';
2
+ export { ACCOUNT_REGISTRY_PATH, ACCOUNT_REGISTRY_SPACE, AutoApproveSpaceCreationHandler, AutoRejectStrategy, AutoSignStrategy, BatchOptions, BatchResponse, CallbackStrategy, CapabilityEntry, CapabilityKeyRegistry, CapabilityKeyRegistryErrorCode, CapabilityKeyRegistryErrorCodes, ClientSession, ColumnInfo, ComposeManifestOptions, ComposedManifestRequest, CreateDelegationParams, DEFAULT_MANIFEST_SPACE, DEFAULT_MANIFEST_VERSION, DataVaultConfig, DataVaultService, DatabaseHandle, Delegation, DelegationChain, DelegationChainV2, DelegationDirection, DelegationError, DelegationErrorCode, DelegationErrorCodes, DelegationFilters, DelegationManager, DelegationManagerConfig, DelegationRecord, DelegationResult, DuckDbAction, DuckDbActionType, DuckDbBatchOptions, DuckDbBatchResponse, DuckDbDatabaseHandle, DuckDbExecuteOptions, DuckDbExecuteResponse, DuckDbOptions, DuckDbQueryOptions, DuckDbQueryResponse, DuckDbService, DuckDbServiceConfig, DuckDbStatement, DuckDbValue, EncodedShareData, ExecuteOptions, ExecuteResponse, Extension, FetchFunction, GenerateShareParams, HookEvent, HookServiceName, HookStreamEvent, HookSubscription, HookWebhookListOptions, HookWebhookRecord, HookWebhookRegistration, HookWebhookScope, HookWebhookUnregisterOptions, HooksService, HooksServiceConfig, ICapabilityKeyRegistry, IDataVaultService, IDatabaseHandle, IDuckDbDatabaseHandle, IDuckDbService, IENSResolver, IHooksService, IKVService, INotificationHandler, IPrefixedKVService, ISQLService, ISecretsService, ISessionManager, ISessionStorage, ISharingService, ISigner, ISpace, ISpaceCreationHandler, ISpaceScopedDelegations, ISpaceScopedSharing, ISpaceService, IUserAuthorization, IWasmBindings, IngestOptions, InvokeFunction, JWK, KVResponse, KVService, KVServiceConfig, KeyInfo, KeyProvider, KeyType, Manifest, ManifestDefaults, ManifestRegistryRecord, ManifestSecretActions, ManifestValidationError, PermissionEntry, PermissionNotInManifestError, PersistedSessionData, PrefixedKVService, ProtocolMismatchError, QueryOptions, QueryResponse, ReceiveOptions, ResolvedCapabilities, ResolvedDelegate, ResourceCapability, SQLAction, SQLActionType, SQLService, SQLServiceConfig, SchemaInfo, SecretPayload, 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, SubscribeOptions, TableInfo, TinyCloud, TinyCloudConfig, TinyCloudSession, UnsupportedFeatureError, VaultCrypto, VaultEntry, VaultError, VaultGetOptions, VaultGrantOptions, VaultHeaders, VaultListOptions, VaultPublicSpaceKVActions, VaultPutOptions, VersionCheckError, ViewInfo, WasmVaultFunctions, buildSpaceUri, checkNodeInfo, composeManifestRequest, createCapabilityKeyRegistry, createSharingService, createSpaceService, createVaultCrypto, defaultSpaceCreationHandler, expandActionShortNames, isCapabilitySubset, loadManifest, makePublicSpaceId, parseExpiry, parseSpaceUri, resolveManifest, resourceCapabilitiesToSpaceAbilitiesMap, validateManifest } from '@tinycloud/sdk-core';
3
+ export { D as DelegateToOptions, a as DelegateToResult, b as DelegatedAccess, F as FileSessionStorage, M as MemorySessionStorage, N as NodeEventEmitterStrategy, c as NodeUserAuthorization, d as NodeUserAuthorizationConfig, P as PortableDelegation, R as RestorableSession, S as SignStrategy, T as TinyCloudNode, e as TinyCloudNodeConfig, W as WasmKeyProvider, f as WasmKeyProviderConfig, g as createWasmKeyProvider, h as defaultSignStrategy, i as deserializeDelegation, s as serializeDelegation } from './core-C3s0bgRe.cjs';
4
4
  import { invoke, invokeAny, prepareSession, completeSessionSetup, ensureEip55, makeSpaceId, createDelegation, parseRecapFromSiwe, generateHostSIWEMessage, siweToDelegationHeaders, protocolVersion, vault_encrypt, vault_decrypt, vault_derive_key, vault_x25519_from_seed, vault_x25519_dh, vault_random_bytes, vault_sha256 } from '@tinycloud/node-sdk-wasm';
5
5
  import 'events';
6
6
  import '@tinycloud/sdk-services';
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ISigner, Bytes, IWasmBindings, ISessionManager } from '@tinycloud/sdk-core';
2
- export { ACCOUNT_REGISTRY_PATH, ACCOUNT_REGISTRY_SPACE, AutoApproveSpaceCreationHandler, AutoRejectStrategy, AutoSignStrategy, BatchOptions, BatchResponse, CallbackStrategy, CapabilityEntry, CapabilityKeyRegistry, CapabilityKeyRegistryErrorCode, CapabilityKeyRegistryErrorCodes, ClientSession, ColumnInfo, ComposeManifestOptions, ComposedManifestRequest, CreateDelegationParams, DEFAULT_MANIFEST_SPACE, DEFAULT_MANIFEST_VERSION, DataVaultConfig, DataVaultService, DatabaseHandle, Delegation, DelegationChain, DelegationChainV2, DelegationDirection, DelegationError, DelegationErrorCode, DelegationErrorCodes, DelegationFilters, DelegationManager, DelegationManagerConfig, DelegationRecord, DelegationResult, DuckDbAction, DuckDbActionType, DuckDbBatchOptions, DuckDbBatchResponse, DuckDbDatabaseHandle, DuckDbExecuteOptions, DuckDbExecuteResponse, DuckDbOptions, DuckDbQueryOptions, DuckDbQueryResponse, DuckDbService, DuckDbServiceConfig, DuckDbStatement, DuckDbValue, EncodedShareData, ExecuteOptions, ExecuteResponse, Extension, FetchFunction, GenerateShareParams, HookEvent, HookServiceName, HookStreamEvent, HookSubscription, HookWebhookListOptions, HookWebhookRecord, HookWebhookRegistration, HookWebhookScope, HookWebhookUnregisterOptions, HooksService, HooksServiceConfig, ICapabilityKeyRegistry, IDataVaultService, IDatabaseHandle, IDuckDbDatabaseHandle, IDuckDbService, IENSResolver, IHooksService, IKVService, INotificationHandler, IPrefixedKVService, ISQLService, ISessionManager, ISessionStorage, ISharingService, ISigner, ISpace, ISpaceCreationHandler, ISpaceScopedDelegations, ISpaceScopedSharing, ISpaceService, IUserAuthorization, IWasmBindings, IngestOptions, InvokeFunction, JWK, KVResponse, KVService, KVServiceConfig, KeyInfo, KeyProvider, KeyType, Manifest, ManifestDefaults, ManifestRegistryRecord, ManifestValidationError, PermissionEntry, PermissionNotInManifestError, PersistedSessionData, PrefixedKVService, ProtocolMismatchError, QueryOptions, QueryResponse, ReceiveOptions, ResolvedCapabilities, ResolvedDelegate, ResourceCapability, SQLAction, SQLActionType, SQLService, SQLServiceConfig, SchemaInfo, 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, SubscribeOptions, TableInfo, TinyCloud, TinyCloudConfig, TinyCloudSession, UnsupportedFeatureError, VaultCrypto, VaultEntry, VaultError, VaultGetOptions, VaultGrantOptions, VaultHeaders, VaultListOptions, VaultPublicSpaceKVActions, VaultPutOptions, VersionCheckError, ViewInfo, WasmVaultFunctions, buildSpaceUri, checkNodeInfo, composeManifestRequest, createCapabilityKeyRegistry, createSharingService, createSpaceService, createVaultCrypto, defaultSpaceCreationHandler, expandActionShortNames, isCapabilitySubset, loadManifest, makePublicSpaceId, parseExpiry, parseSpaceUri, resolveManifest, resourceCapabilitiesToSpaceAbilitiesMap, validateManifest } from '@tinycloud/sdk-core';
3
- export { D as DelegateToOptions, a as DelegateToResult, b as DelegatedAccess, F as FileSessionStorage, M as MemorySessionStorage, N as NodeEventEmitterStrategy, c as NodeUserAuthorization, d as NodeUserAuthorizationConfig, P as PortableDelegation, R as RestorableSession, S as SignStrategy, T as TinyCloudNode, e as TinyCloudNodeConfig, W as WasmKeyProvider, f as WasmKeyProviderConfig, g as createWasmKeyProvider, h as defaultSignStrategy, i as deserializeDelegation, s as serializeDelegation } from './core-DdMPUB5s.js';
2
+ export { ACCOUNT_REGISTRY_PATH, ACCOUNT_REGISTRY_SPACE, AutoApproveSpaceCreationHandler, AutoRejectStrategy, AutoSignStrategy, BatchOptions, BatchResponse, CallbackStrategy, CapabilityEntry, CapabilityKeyRegistry, CapabilityKeyRegistryErrorCode, CapabilityKeyRegistryErrorCodes, ClientSession, ColumnInfo, ComposeManifestOptions, ComposedManifestRequest, CreateDelegationParams, DEFAULT_MANIFEST_SPACE, DEFAULT_MANIFEST_VERSION, DataVaultConfig, DataVaultService, DatabaseHandle, Delegation, DelegationChain, DelegationChainV2, DelegationDirection, DelegationError, DelegationErrorCode, DelegationErrorCodes, DelegationFilters, DelegationManager, DelegationManagerConfig, DelegationRecord, DelegationResult, DuckDbAction, DuckDbActionType, DuckDbBatchOptions, DuckDbBatchResponse, DuckDbDatabaseHandle, DuckDbExecuteOptions, DuckDbExecuteResponse, DuckDbOptions, DuckDbQueryOptions, DuckDbQueryResponse, DuckDbService, DuckDbServiceConfig, DuckDbStatement, DuckDbValue, EncodedShareData, ExecuteOptions, ExecuteResponse, Extension, FetchFunction, GenerateShareParams, HookEvent, HookServiceName, HookStreamEvent, HookSubscription, HookWebhookListOptions, HookWebhookRecord, HookWebhookRegistration, HookWebhookScope, HookWebhookUnregisterOptions, HooksService, HooksServiceConfig, ICapabilityKeyRegistry, IDataVaultService, IDatabaseHandle, IDuckDbDatabaseHandle, IDuckDbService, IENSResolver, IHooksService, IKVService, INotificationHandler, IPrefixedKVService, ISQLService, ISecretsService, ISessionManager, ISessionStorage, ISharingService, ISigner, ISpace, ISpaceCreationHandler, ISpaceScopedDelegations, ISpaceScopedSharing, ISpaceService, IUserAuthorization, IWasmBindings, IngestOptions, InvokeFunction, JWK, KVResponse, KVService, KVServiceConfig, KeyInfo, KeyProvider, KeyType, Manifest, ManifestDefaults, ManifestRegistryRecord, ManifestSecretActions, ManifestValidationError, PermissionEntry, PermissionNotInManifestError, PersistedSessionData, PrefixedKVService, ProtocolMismatchError, QueryOptions, QueryResponse, ReceiveOptions, ResolvedCapabilities, ResolvedDelegate, ResourceCapability, SQLAction, SQLActionType, SQLService, SQLServiceConfig, SchemaInfo, SecretPayload, 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, SubscribeOptions, TableInfo, TinyCloud, TinyCloudConfig, TinyCloudSession, UnsupportedFeatureError, VaultCrypto, VaultEntry, VaultError, VaultGetOptions, VaultGrantOptions, VaultHeaders, VaultListOptions, VaultPublicSpaceKVActions, VaultPutOptions, VersionCheckError, ViewInfo, WasmVaultFunctions, buildSpaceUri, checkNodeInfo, composeManifestRequest, createCapabilityKeyRegistry, createSharingService, createSpaceService, createVaultCrypto, defaultSpaceCreationHandler, expandActionShortNames, isCapabilitySubset, loadManifest, makePublicSpaceId, parseExpiry, parseSpaceUri, resolveManifest, resourceCapabilitiesToSpaceAbilitiesMap, validateManifest } from '@tinycloud/sdk-core';
3
+ export { D as DelegateToOptions, a as DelegateToResult, b as DelegatedAccess, F as FileSessionStorage, M as MemorySessionStorage, N as NodeEventEmitterStrategy, c as NodeUserAuthorization, d as NodeUserAuthorizationConfig, P as PortableDelegation, R as RestorableSession, S as SignStrategy, T as TinyCloudNode, e as TinyCloudNodeConfig, W as WasmKeyProvider, f as WasmKeyProviderConfig, g as createWasmKeyProvider, h as defaultSignStrategy, i as deserializeDelegation, s as serializeDelegation } from './core-C3s0bgRe.js';
4
4
  import { invoke, invokeAny, prepareSession, completeSessionSetup, ensureEip55, makeSpaceId, createDelegation, parseRecapFromSiwe, generateHostSIWEMessage, siweToDelegationHeaders, protocolVersion, vault_encrypt, vault_decrypt, vault_derive_key, vault_x25519_from_seed, vault_x25519_dh, vault_random_bytes, vault_sha256 } from '@tinycloud/node-sdk-wasm';
5
5
  import 'events';
6
6
  import '@tinycloud/sdk-services';
package/dist/index.js CHANGED
@@ -17159,6 +17159,7 @@ import {
17159
17159
  DuckDbService as DuckDbService2,
17160
17160
  HooksService as HooksService2,
17161
17161
  DataVaultService,
17162
+ SecretsService,
17162
17163
  createVaultCrypto,
17163
17164
  ServiceContext as ServiceContext2,
17164
17165
  SilentNotificationHandler,
@@ -18241,6 +18242,179 @@ function extractSiweExpiration(siwe) {
18241
18242
  return d;
18242
18243
  }
18243
18244
 
18245
+ // src/NodeSecretsService.ts
18246
+ import {
18247
+ ErrorCodes,
18248
+ resolveManifest
18249
+ } from "@tinycloud/sdk-core";
18250
+ var SECRET_NAME_RE = /^[A-Z][A-Z0-9_]*$/;
18251
+ var SECRET_PREFIX = "secrets/";
18252
+ var SECRETS_SPACE = "secrets";
18253
+ function ok() {
18254
+ return { ok: true, data: void 0 };
18255
+ }
18256
+ function secretsError(code, message, cause) {
18257
+ return {
18258
+ ok: false,
18259
+ error: {
18260
+ code,
18261
+ service: "secrets",
18262
+ message,
18263
+ ...cause ? { cause } : {}
18264
+ }
18265
+ };
18266
+ }
18267
+ function actionUrn(action) {
18268
+ return `tinycloud.kv/${action}`;
18269
+ }
18270
+ function secretResourcePath(base2, name) {
18271
+ return `${base2}/${SECRET_PREFIX}${name}`;
18272
+ }
18273
+ function secretPermissionEntries(name, action) {
18274
+ return [
18275
+ {
18276
+ service: "tinycloud.kv",
18277
+ space: SECRETS_SPACE,
18278
+ path: secretResourcePath("keys", name),
18279
+ actions: [action],
18280
+ skipPrefix: true
18281
+ },
18282
+ {
18283
+ service: "tinycloud.kv",
18284
+ space: SECRETS_SPACE,
18285
+ path: secretResourcePath("vault", name),
18286
+ actions: [action],
18287
+ skipPrefix: true
18288
+ }
18289
+ ];
18290
+ }
18291
+ function isSecretsSpace(space) {
18292
+ return space === SECRETS_SPACE || space.endsWith(`:${SECRETS_SPACE}`);
18293
+ }
18294
+ function composeEscalatedManifest(manifest, additional) {
18295
+ if (Array.isArray(manifest)) {
18296
+ const [primary, ...rest] = manifest;
18297
+ return [
18298
+ {
18299
+ ...primary,
18300
+ permissions: [...primary.permissions ?? [], ...additional]
18301
+ },
18302
+ ...rest
18303
+ ];
18304
+ }
18305
+ return {
18306
+ ...manifest,
18307
+ permissions: [...manifest.permissions ?? [], ...additional]
18308
+ };
18309
+ }
18310
+ var NodeSecretsService = class {
18311
+ constructor(config) {
18312
+ this.config = config;
18313
+ this.shouldRestoreUnlock = false;
18314
+ }
18315
+ get vault() {
18316
+ return this.service.vault;
18317
+ }
18318
+ get isUnlocked() {
18319
+ return this.service.isUnlocked;
18320
+ }
18321
+ async unlock(signer) {
18322
+ if (signer !== void 0) {
18323
+ this.unlockSigner = signer;
18324
+ }
18325
+ const result = await this.service.unlock(signer);
18326
+ if (result.ok) {
18327
+ this.shouldRestoreUnlock = true;
18328
+ }
18329
+ return result;
18330
+ }
18331
+ lock() {
18332
+ this.shouldRestoreUnlock = false;
18333
+ this.service.lock();
18334
+ }
18335
+ get(name) {
18336
+ return this.service.get(name);
18337
+ }
18338
+ async put(name, value) {
18339
+ const permission = await this.ensureMutationPermission(name, "put");
18340
+ if (!permission.ok) return permission;
18341
+ return this.service.put(name, value);
18342
+ }
18343
+ async delete(name) {
18344
+ const permission = await this.ensureMutationPermission(name, "del");
18345
+ if (!permission.ok) return permission;
18346
+ return this.service.delete(name);
18347
+ }
18348
+ list() {
18349
+ return this.service.list();
18350
+ }
18351
+ get service() {
18352
+ return this.config.getService();
18353
+ }
18354
+ async ensureMutationPermission(name, action) {
18355
+ if (!SECRET_NAME_RE.test(name)) {
18356
+ return secretsError(
18357
+ ErrorCodes.INVALID_INPUT,
18358
+ `Invalid secret name ${JSON.stringify(name)}. Secret names must match ${SECRET_NAME_RE.source}.`
18359
+ );
18360
+ }
18361
+ if (this.hasMutationPermission(name, action)) {
18362
+ return ok();
18363
+ }
18364
+ if (!this.config.canEscalate()) {
18365
+ return secretsError(
18366
+ ErrorCodes.PERMISSION_DENIED,
18367
+ `Cannot autosign ${actionUrn(action)} for ${name}; TinyCloudNode needs wallet mode with a signer or privateKey.`
18368
+ );
18369
+ }
18370
+ const manifest = this.config.getManifest();
18371
+ if (manifest === void 0) {
18372
+ return secretsError(
18373
+ ErrorCodes.PERMISSION_DENIED,
18374
+ `Cannot autosign ${actionUrn(action)} for ${name}; set a manifest before mutating secrets.`
18375
+ );
18376
+ }
18377
+ try {
18378
+ this.config.setManifest(
18379
+ composeEscalatedManifest(
18380
+ manifest,
18381
+ secretPermissionEntries(name, action)
18382
+ )
18383
+ );
18384
+ await this.config.signIn();
18385
+ return this.restoreUnlockAfterEscalation();
18386
+ } catch (error) {
18387
+ return secretsError(
18388
+ ErrorCodes.PERMISSION_DENIED,
18389
+ error instanceof Error ? error.message : `Autosign escalation for ${actionUrn(action)} on ${name} failed.`,
18390
+ error instanceof Error ? error : void 0
18391
+ );
18392
+ }
18393
+ }
18394
+ async restoreUnlockAfterEscalation() {
18395
+ if (!this.shouldRestoreUnlock) {
18396
+ return ok();
18397
+ }
18398
+ return this.service.unlock(this.unlockSigner);
18399
+ }
18400
+ hasMutationPermission(name, action) {
18401
+ const manifest = this.config.getManifest();
18402
+ if (manifest === void 0) {
18403
+ return false;
18404
+ }
18405
+ const manifests = Array.isArray(manifest) ? manifest : [manifest];
18406
+ const requiredAction = actionUrn(action);
18407
+ return manifests.some((entry) => {
18408
+ const resolved = resolveManifest(entry);
18409
+ return ["keys", "vault"].every(
18410
+ (base2) => resolved.resources.some(
18411
+ (resource) => resource.service === "tinycloud.kv" && isSecretsSpace(resource.space) && resource.path === secretResourcePath(base2, name) && resource.actions.includes(requiredAction)
18412
+ )
18413
+ );
18414
+ });
18415
+ }
18416
+ };
18417
+
18244
18418
  // src/TinyCloudNode.ts
18245
18419
  var DEFAULT_HOST = "https://node.tinycloud.xyz";
18246
18420
  var _TinyCloudNode = class _TinyCloudNode {
@@ -18495,6 +18669,10 @@ var _TinyCloudNode = class _TinyCloudNode {
18495
18669
  this._sql = void 0;
18496
18670
  this._duckdb = void 0;
18497
18671
  this._hooks = void 0;
18672
+ this._vault = void 0;
18673
+ this._baseSecrets = void 0;
18674
+ this._secrets = void 0;
18675
+ this._spaceService = void 0;
18498
18676
  this._serviceContext = void 0;
18499
18677
  await this.tc.signIn(options);
18500
18678
  this.syncResolvedHostFromAuth();
@@ -18580,6 +18758,10 @@ var _TinyCloudNode = class _TinyCloudNode {
18580
18758
  this._sql = void 0;
18581
18759
  this._duckdb = void 0;
18582
18760
  this._hooks = void 0;
18761
+ this._vault = void 0;
18762
+ this._baseSecrets = void 0;
18763
+ this._secrets = void 0;
18764
+ this._spaceService = void 0;
18583
18765
  this._serviceContext = void 0;
18584
18766
  if (sessionData.address) {
18585
18767
  this._address = sessionData.address;
@@ -18613,41 +18795,7 @@ var _TinyCloudNode = class _TinyCloudNode {
18613
18795
  jwk: sessionData.jwk
18614
18796
  };
18615
18797
  this._serviceContext.setSession(serviceSession);
18616
- const wasm = this.wasmBindings;
18617
- const vaultCrypto = createVaultCrypto({
18618
- vault_encrypt: wasm.vault_encrypt,
18619
- vault_decrypt: wasm.vault_decrypt,
18620
- vault_derive_key: wasm.vault_derive_key,
18621
- vault_x25519_from_seed: wasm.vault_x25519_from_seed,
18622
- vault_x25519_dh: wasm.vault_x25519_dh,
18623
- vault_random_bytes: wasm.vault_random_bytes,
18624
- vault_sha256: wasm.vault_sha256
18625
- });
18626
- const self2 = this;
18627
- this._vault = new DataVaultService({
18628
- spaceId: sessionData.spaceId,
18629
- crypto: vaultCrypto,
18630
- tc: {
18631
- kv: this._kv,
18632
- ensurePublicSpace: async () => {
18633
- try {
18634
- await self2.ensurePublicSpace();
18635
- return { ok: true, data: void 0 };
18636
- } catch (error) {
18637
- return { ok: false, error: { code: "STORAGE_ERROR", message: error instanceof Error ? error.message : String(error), service: "vault" } };
18638
- }
18639
- },
18640
- get publicKV() {
18641
- return self2._publicKV ?? self2.tc.publicKV;
18642
- },
18643
- readPublicSpace: (host, spaceId, key2) => TinyCloud.readPublicSpace(host, spaceId, key2),
18644
- makePublicSpaceId: TinyCloud.makePublicSpaceId,
18645
- did: this.did,
18646
- address: sessionData.address ?? this._address ?? "",
18647
- chainId: sessionData.chainId ?? this._chainId,
18648
- hosts: [this.config.host]
18649
- }
18650
- });
18798
+ this._vault = this.createVaultService(sessionData.spaceId, this._kv);
18651
18799
  this._vault.initialize(this._serviceContext);
18652
18800
  this._serviceContext.registerService("vault", this._vault);
18653
18801
  this.initializeV2Services(serviceSession);
@@ -18799,6 +18947,28 @@ var _TinyCloudNode = class _TinyCloudNode {
18799
18947
  };
18800
18948
  this._serviceContext.setSession(serviceSession);
18801
18949
  this.tc.serviceContext.setSession(serviceSession);
18950
+ this._vault = this.createVaultService(session.spaceId, this._kv);
18951
+ this._vault.initialize(this._serviceContext);
18952
+ this._serviceContext.registerService("vault", this._vault);
18953
+ this.initializeV2Services(serviceSession);
18954
+ }
18955
+ createSpaceScopedKVService(spaceId) {
18956
+ const kvService = new KVService2({});
18957
+ if (this._serviceContext) {
18958
+ const spaceScopedContext = new ServiceContext2({
18959
+ invoke: this._serviceContext.invoke,
18960
+ fetch: this._serviceContext.fetch,
18961
+ hosts: this._serviceContext.hosts
18962
+ });
18963
+ const session = this._serviceContext.session;
18964
+ if (session) {
18965
+ spaceScopedContext.setSession({ ...session, spaceId });
18966
+ }
18967
+ kvService.initialize(spaceScopedContext);
18968
+ }
18969
+ return kvService;
18970
+ }
18971
+ createVaultService(spaceId, kv) {
18802
18972
  const wasm = this.wasmBindings;
18803
18973
  const vaultCrypto = createVaultCrypto({
18804
18974
  vault_encrypt: wasm.vault_encrypt,
@@ -18810,11 +18980,11 @@ var _TinyCloudNode = class _TinyCloudNode {
18810
18980
  vault_sha256: wasm.vault_sha256
18811
18981
  });
18812
18982
  const self2 = this;
18813
- this._vault = new DataVaultService({
18814
- spaceId: session.spaceId,
18983
+ return new DataVaultService({
18984
+ spaceId,
18815
18985
  crypto: vaultCrypto,
18816
18986
  tc: {
18817
- kv: this._kv,
18987
+ kv,
18818
18988
  ensurePublicSpace: async () => {
18819
18989
  try {
18820
18990
  await self2.ensurePublicSpace();
@@ -18826,17 +18996,14 @@ var _TinyCloudNode = class _TinyCloudNode {
18826
18996
  get publicKV() {
18827
18997
  return self2._publicKV ?? self2.tc.publicKV;
18828
18998
  },
18829
- readPublicSpace: (host, spaceId, key2) => TinyCloud.readPublicSpace(host, spaceId, key2),
18999
+ readPublicSpace: (host, targetSpaceId, key2) => TinyCloud.readPublicSpace(host, targetSpaceId, key2),
18830
19000
  makePublicSpaceId: TinyCloud.makePublicSpaceId,
18831
19001
  did: this.did,
18832
- address: this._address,
19002
+ address: this._address ?? "",
18833
19003
  chainId: this._chainId,
18834
19004
  hosts: [this.config.host]
18835
19005
  }
18836
19006
  });
18837
- this._vault.initialize(this._serviceContext);
18838
- this._serviceContext.registerService("vault", this._vault);
18839
- this.initializeV2Services(serviceSession);
18840
19007
  }
18841
19008
  /**
18842
19009
  * Initialize the v2 delegation system services.
@@ -18931,20 +19098,15 @@ var _TinyCloudNode = class _TinyCloudNode {
18931
19098
  capabilityRegistry: this._capabilityRegistry,
18932
19099
  userDid: this.did,
18933
19100
  createKVService: (spaceId) => {
18934
- const kvService = new KVService2({});
19101
+ return this.createSpaceScopedKVService(spaceId);
19102
+ },
19103
+ createVaultService: (spaceId) => {
19104
+ const kvService = this.createSpaceScopedKVService(spaceId);
19105
+ const vaultService = this.createVaultService(spaceId, kvService);
18935
19106
  if (this._serviceContext) {
18936
- const spaceScopedContext = new ServiceContext2({
18937
- invoke: this._serviceContext.invoke,
18938
- fetch: this._serviceContext.fetch,
18939
- hosts: this._serviceContext.hosts
18940
- });
18941
- const session = this._serviceContext.session;
18942
- if (session) {
18943
- spaceScopedContext.setSession({ ...session, spaceId });
18944
- }
18945
- kvService.initialize(spaceScopedContext);
19107
+ vaultService.initialize(this._serviceContext);
18946
19108
  }
18947
- return kvService;
19109
+ return vaultService;
18948
19110
  },
18949
19111
  // Enable space.delegations.create() via SIWE-based delegation
18950
19112
  createDelegation: async (params) => {
@@ -19181,6 +19343,33 @@ var _TinyCloudNode = class _TinyCloudNode {
19181
19343
  }
19182
19344
  return this._vault;
19183
19345
  }
19346
+ /**
19347
+ * App-facing secrets API backed by the `secrets` space vault.
19348
+ */
19349
+ get secrets() {
19350
+ if (!this._spaceService) {
19351
+ throw new Error("Not signed in. Call signIn() first.");
19352
+ }
19353
+ if (!this._secrets) {
19354
+ this._secrets = new NodeSecretsService({
19355
+ getService: () => this.getBaseSecrets(),
19356
+ getManifest: () => this.manifest,
19357
+ setManifest: (manifest) => this.setManifest(manifest),
19358
+ signIn: () => this.signIn(),
19359
+ canEscalate: () => this.signer !== void 0 && this.tc !== void 0
19360
+ });
19361
+ }
19362
+ return this._secrets;
19363
+ }
19364
+ getBaseSecrets() {
19365
+ if (!this._spaceService) {
19366
+ throw new Error("Not signed in. Call signIn() first.");
19367
+ }
19368
+ if (!this._baseSecrets) {
19369
+ this._baseSecrets = new SecretsService(() => this.space("secrets").vault);
19370
+ }
19371
+ return this._baseSecrets;
19372
+ }
19184
19373
  /**
19185
19374
  * Hooks write stream subscription API.
19186
19375
  */
@@ -19319,6 +19508,12 @@ var _TinyCloudNode = class _TinyCloudNode {
19319
19508
  get spaceService() {
19320
19509
  return this.spaces;
19321
19510
  }
19511
+ /**
19512
+ * Get a Space object by short name or full URI.
19513
+ */
19514
+ space(nameOrUri) {
19515
+ return this.spaces.get(nameOrUri);
19516
+ }
19322
19517
  /**
19323
19518
  * Get the SharingService for creating and receiving v2 sharing links.
19324
19519
  *
@@ -20287,7 +20482,7 @@ import {
20287
20482
  SessionExpiredError as SessionExpiredError2,
20288
20483
  ManifestValidationError,
20289
20484
  composeManifestRequest as composeManifestRequest2,
20290
- resolveManifest,
20485
+ resolveManifest as resolveManifest2,
20291
20486
  validateManifest,
20292
20487
  loadManifest,
20293
20488
  isCapabilitySubset as isCapabilitySubset2,
@@ -20324,7 +20519,8 @@ import {
20324
20519
  DataVaultService as DataVaultService2,
20325
20520
  VaultHeaders,
20326
20521
  VaultPublicSpaceKVActions,
20327
- createVaultCrypto as createVaultCrypto2
20522
+ createVaultCrypto as createVaultCrypto2,
20523
+ SecretsService as SecretsService2
20328
20524
  } from "@tinycloud/sdk-core";
20329
20525
  import { HooksService as HooksService3 } from "@tinycloud/sdk-core";
20330
20526
  import {
@@ -20383,6 +20579,7 @@ export {
20383
20579
  ProtocolMismatchError,
20384
20580
  SQLAction,
20385
20581
  SQLService3 as SQLService,
20582
+ SecretsService2 as SecretsService,
20386
20583
  ServiceContext3 as ServiceContext,
20387
20584
  SessionExpiredError2 as SessionExpiredError,
20388
20585
  SharingService2 as SharingService,
@@ -20414,7 +20611,7 @@ export {
20414
20611
  makePublicSpaceId2 as makePublicSpaceId,
20415
20612
  parseExpiry2 as parseExpiry,
20416
20613
  parseSpaceUri,
20417
- resolveManifest,
20614
+ resolveManifest2 as resolveManifest,
20418
20615
  resourceCapabilitiesToSpaceAbilitiesMap2 as resourceCapabilitiesToSpaceAbilitiesMap,
20419
20616
  serializeDelegation,
20420
20617
  validateManifest