@tinycloud/node-sdk 3.0.0-beta.13 → 3.0.0-beta.14

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, AccountApplicationRegisterOptions, AccountDelegation, AccountDelegationListOptions, AccountDelegationRevokeOptions, AccountIndexEnsureResult, AccountIndexRebuildResult, AccountIndexStatus, AccountIndexedReadOptions, AccountService, AccountServiceConfig, AccountSpace, AccountSpaceListOptions, AccountStatus, AutoApproveSpaceCreationHandler, AutoRejectStrategy, AutoSignStrategy, BatchOptions, BatchResponse, CallbackStrategy, CanonicalAddress, CanonicalParsedNetworkId, CapabilityEntry, CapabilityKeyRegistry, CapabilityKeyRegistryErrorCode, CapabilityKeyRegistryErrorCodes, CaveatedDelegationUnsupportedError, ClientSession, ColumnInfo, ComposeManifestOptions, ComposedManifestRequest, CreateDelegationParams, DEFAULT_MANIFEST_SPACE, DEFAULT_MANIFEST_VERSION, DEFAULT_SIGNED_READ_URL_EXPIRY_MS, DataVaultConfig, DataVaultService, DatabaseHandle, DelegateReceivedShareParams, DelegatedShareAccess, 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, KVBatchReadResponse, KVCreateSignedReadUrlOptions, KVResponse, KVService, KVServiceConfig, KVSignedReadUrlResponse, KeyInfo, KeyProvider, KeyType, Manifest, ManifestDefaults, ManifestRegistryRecord, ManifestSecretActions, ManifestValidationError, OpenKeyCallbackStrategy, OpenKeySigningRequestBody, OpenKeySigningResponseBody, OpenKeySigningStrategyOptions, ParsedSecretCatalogKey, PermissionEntry, PermissionNotInManifestError, PersistedSessionData, PkhDidParts, PrefixedKVService, ProtocolMismatchError, QueryOptions, QueryResponse, ReceiveOptions, RegisterBatchSuccess, RegisterPolicyV3Input, RegisterPolicyV3Receipt, ResolvedCapabilities, ResolvedDelegate, ResolvedSecretPath, ResourceCapability, SECRET_NAME_RE, SQLAction, SQLActionType, SQLService, SQLServiceConfig, SchemaInfo, SecretCatalogEntry, 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, VaultNetworkReadResult, 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, parseSecretCatalogKey, parseSpaceUri, pkhDid, principalDid, principalDidEquals, resolveManifest, resolveSecretListPrefix, resolveSecretPath, resourceCapabilitiesToSpaceAbilitiesMap, tinyCloudDebugLogger, validateManifest } from '@tinycloud/sdk-core';
2
- export { e as BootstrapWarning, C as CompactRuntimeDelegationInput, f as CreateOwnerDelegationParams, D as DelegateToOptions, g as DelegateToResult, h as DelegatedAccess, E as EnsureEncryptionNetworkOptions, F as FileSessionStorage, M as MemorySessionStorage, N as NodeEventEmitterStrategy, j as NodeUserAuthorization, k as NodeUserAuthorizationConfig, O as OwnerDelegationReceipt, P as PortableDelegation, m as RuntimePermissionGrantOptions, S as SecretPermissionHint, n as SecretReadInput, o as SecretReadResult, p as SignStrategy, T as TinyCloudNode, q as TinyCloudNodeConfig, U as UnifiedOwnerRootInput, r as UnifiedOwnerRootReceipt, s as UnsupportedSessionRestoreError, V as ValidatedRuntimeDelegation, W as WasmKeyProvider, t as WasmKeyProviderConfig, u as activateCompactRuntimeDelegation, w as createWasmKeyProvider, x as defaultSignStrategy, y as deserializeDelegation, G as serializeDelegation } from './core-DWFGaDwP.cjs';
2
+ export { e as BootstrapWarning, C as CompactRuntimeDelegationInput, f as CreateOwnerDelegationParams, D as DelegateToOptions, g as DelegateToResult, h as DelegatedAccess, E as EnsureEncryptionNetworkOptions, F as FileSessionStorage, I as InvalidRestoredSessionError, M as MemorySessionStorage, N as NodeEventEmitterStrategy, j as NodeUserAuthorization, k as NodeUserAuthorizationConfig, O as OwnerDelegationReceipt, P as PortableDelegation, m as RuntimePermissionGrantOptions, S as SecretPermissionHint, n as SecretReadInput, o as SecretReadResult, p as SignStrategy, T as TinyCloudNode, q as TinyCloudNodeConfig, U as UnifiedOwnerRootInput, r as UnifiedOwnerRootReceipt, s as UnsupportedSessionRestoreError, V as ValidatedRuntimeDelegation, W as WasmKeyProvider, t as WasmKeyProviderConfig, u as activateCompactRuntimeDelegation, w as createWasmKeyProvider, x as defaultSignStrategy, y as deserializeDelegation, G as serializeDelegation } from './core-D4IVgDr5.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, AccountApplicationRegisterOptions, AccountDelegation, AccountDelegationListOptions, AccountDelegationRevokeOptions, AccountIndexEnsureResult, AccountIndexRebuildResult, AccountIndexStatus, AccountIndexedReadOptions, AccountService, AccountServiceConfig, AccountSpace, AccountSpaceListOptions, AccountStatus, AutoApproveSpaceCreationHandler, AutoRejectStrategy, AutoSignStrategy, BatchOptions, BatchResponse, CallbackStrategy, CanonicalAddress, CanonicalParsedNetworkId, CapabilityEntry, CapabilityKeyRegistry, CapabilityKeyRegistryErrorCode, CapabilityKeyRegistryErrorCodes, CaveatedDelegationUnsupportedError, ClientSession, ColumnInfo, ComposeManifestOptions, ComposedManifestRequest, CreateDelegationParams, DEFAULT_MANIFEST_SPACE, DEFAULT_MANIFEST_VERSION, DEFAULT_SIGNED_READ_URL_EXPIRY_MS, DataVaultConfig, DataVaultService, DatabaseHandle, DelegateReceivedShareParams, DelegatedShareAccess, 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, KVBatchReadResponse, KVCreateSignedReadUrlOptions, KVResponse, KVService, KVServiceConfig, KVSignedReadUrlResponse, KeyInfo, KeyProvider, KeyType, Manifest, ManifestDefaults, ManifestRegistryRecord, ManifestSecretActions, ManifestValidationError, OpenKeyCallbackStrategy, OpenKeySigningRequestBody, OpenKeySigningResponseBody, OpenKeySigningStrategyOptions, ParsedSecretCatalogKey, PermissionEntry, PermissionNotInManifestError, PersistedSessionData, PkhDidParts, PrefixedKVService, ProtocolMismatchError, QueryOptions, QueryResponse, ReceiveOptions, RegisterBatchSuccess, RegisterPolicyV3Input, RegisterPolicyV3Receipt, ResolvedCapabilities, ResolvedDelegate, ResolvedSecretPath, ResourceCapability, SECRET_NAME_RE, SQLAction, SQLActionType, SQLService, SQLServiceConfig, SchemaInfo, SecretCatalogEntry, 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, VaultNetworkReadResult, 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, parseSecretCatalogKey, parseSpaceUri, pkhDid, principalDid, principalDidEquals, resolveManifest, resolveSecretListPrefix, resolveSecretPath, resourceCapabilitiesToSpaceAbilitiesMap, tinyCloudDebugLogger, validateManifest } from '@tinycloud/sdk-core';
2
- export { e as BootstrapWarning, C as CompactRuntimeDelegationInput, f as CreateOwnerDelegationParams, D as DelegateToOptions, g as DelegateToResult, h as DelegatedAccess, E as EnsureEncryptionNetworkOptions, F as FileSessionStorage, M as MemorySessionStorage, N as NodeEventEmitterStrategy, j as NodeUserAuthorization, k as NodeUserAuthorizationConfig, O as OwnerDelegationReceipt, P as PortableDelegation, m as RuntimePermissionGrantOptions, S as SecretPermissionHint, n as SecretReadInput, o as SecretReadResult, p as SignStrategy, T as TinyCloudNode, q as TinyCloudNodeConfig, U as UnifiedOwnerRootInput, r as UnifiedOwnerRootReceipt, s as UnsupportedSessionRestoreError, V as ValidatedRuntimeDelegation, W as WasmKeyProvider, t as WasmKeyProviderConfig, u as activateCompactRuntimeDelegation, w as createWasmKeyProvider, x as defaultSignStrategy, y as deserializeDelegation, G as serializeDelegation } from './core-DWFGaDwP.js';
2
+ export { e as BootstrapWarning, C as CompactRuntimeDelegationInput, f as CreateOwnerDelegationParams, D as DelegateToOptions, g as DelegateToResult, h as DelegatedAccess, E as EnsureEncryptionNetworkOptions, F as FileSessionStorage, I as InvalidRestoredSessionError, M as MemorySessionStorage, N as NodeEventEmitterStrategy, j as NodeUserAuthorization, k as NodeUserAuthorizationConfig, O as OwnerDelegationReceipt, P as PortableDelegation, m as RuntimePermissionGrantOptions, S as SecretPermissionHint, n as SecretReadInput, o as SecretReadResult, p as SignStrategy, T as TinyCloudNode, q as TinyCloudNodeConfig, U as UnifiedOwnerRootInput, r as UnifiedOwnerRootReceipt, s as UnsupportedSessionRestoreError, V as ValidatedRuntimeDelegation, W as WasmKeyProvider, t as WasmKeyProviderConfig, u as activateCompactRuntimeDelegation, w as createWasmKeyProvider, x as defaultSignStrategy, y as deserializeDelegation, G as serializeDelegation } from './core-D4IVgDr5.js';
3
3
  import 'events';
4
4
  import '@tinycloud/sdk-services';
package/dist/core.js CHANGED
@@ -2361,18 +2361,23 @@ var UnsupportedSessionRestoreError = class extends Error {
2361
2361
  this.name = "UnsupportedSessionRestoreError";
2362
2362
  }
2363
2363
  };
2364
+ var InvalidRestoredSessionError = class extends Error {
2365
+ constructor(message = "Persisted session authority is invalid or expired.") {
2366
+ super(message);
2367
+ this.code = "AUTH_EXPIRED";
2368
+ this.name = "InvalidRestoredSessionError";
2369
+ }
2370
+ };
2364
2371
  function canonicalRestoredVerificationMethod(canonicalVerificationMethod, persistedVerificationMethod) {
2365
2372
  if (typeof persistedVerificationMethod !== "string") return void 0;
2366
2373
  const principal = canonicalVerificationMethod.split("#", 1)[0];
2367
2374
  return persistedVerificationMethod === principal || persistedVerificationMethod === canonicalVerificationMethod ? canonicalVerificationMethod : void 0;
2368
2375
  }
2369
2376
  function persistedExpiry(value) {
2370
- if (typeof value !== "string") {
2371
- throw new Error("Persisted session without a SIWE expiration must include expiresAt.");
2372
- }
2377
+ if (typeof value !== "string") throw new InvalidRestoredSessionError("Persisted session must include expiresAt.");
2373
2378
  const expiry = new Date(value);
2374
2379
  if (!Number.isFinite(expiry.getTime()) || expiry.getTime() <= Date.now()) {
2375
- throw new Error("Persisted session expiry is invalid or expired.");
2380
+ throw new InvalidRestoredSessionError();
2376
2381
  }
2377
2382
  return expiry;
2378
2383
  }
@@ -3564,7 +3569,7 @@ var _TinyCloudNode = class _TinyCloudNode {
3564
3569
  return;
3565
3570
  } catch (error) {
3566
3571
  const message = error instanceof Error ? error.message : String(error);
3567
- if (/Unauthorized Action|\b401\b/.test(message)) {
3572
+ if (/Unauthorized Action|\b(?:401|403)\b/.test(message)) {
3568
3573
  console.warn(
3569
3574
  "TinyCloud account registry sync stopped: authorization verdict is not retryable",
3570
3575
  error
@@ -3814,9 +3819,14 @@ var _TinyCloudNode = class _TinyCloudNode {
3814
3819
  */
3815
3820
  async restoreSession(sessionData) {
3816
3821
  await this.wasmBindings.ensureInitialized?.();
3817
- const restoredJwk = clonePersistedSessionJwk(sessionData.jwk);
3822
+ let restoredJwk;
3823
+ try {
3824
+ restoredJwk = clonePersistedSessionJwk(sessionData.jwk);
3825
+ } catch {
3826
+ throw new InvalidRestoredSessionError("Persisted session has an invalid private Ed25519 session key.");
3827
+ }
3818
3828
  if (sessionData.chainId !== void 0 && (!Number.isSafeInteger(sessionData.chainId) || sessionData.chainId <= 0)) {
3819
- throw new Error("Persisted session chain ID must be a positive safe integer.");
3829
+ throw new InvalidRestoredSessionError("Persisted session chain ID must be a positive safe integer.");
3820
3830
  }
3821
3831
  const stagedManager = this.wasmBindings.createSessionManager();
3822
3832
  const stagedReplace = stagedManager.replaceSessionKey;
@@ -3828,32 +3838,31 @@ var _TinyCloudNode = class _TinyCloudNode {
3828
3838
  let stagedKeyId;
3829
3839
  let stagedJwk;
3830
3840
  let canonicalVerificationMethod;
3841
+ const keyIds = liveKeys.call(this.sessionManager);
3842
+ if (!Array.isArray(keyIds) || !keyIds.every((keyId) => typeof keyId === "string")) {
3843
+ throw new UnsupportedSessionRestoreError("it cannot reliably enumerate every live session signer");
3844
+ }
3845
+ for (const keyId of keyIds) {
3846
+ if (keyId === this.sessionKeyId) continue;
3847
+ const jwk = this.sessionManager.jwk(keyId);
3848
+ if (!jwk) throw new Error("missing live session key");
3849
+ stagedReplace.call(stagedManager, clonePersistedSessionJwk(JSON.parse(jwk)), keyId);
3850
+ }
3831
3851
  try {
3832
- const keyIds = liveKeys.call(this.sessionManager);
3833
- if (!Array.isArray(keyIds) || !keyIds.every((keyId) => typeof keyId === "string")) {
3834
- throw new UnsupportedSessionRestoreError("it cannot reliably enumerate every live session signer");
3835
- }
3836
- for (const keyId of keyIds) {
3837
- if (keyId === this.sessionKeyId) continue;
3838
- const jwk = this.sessionManager.jwk(keyId);
3839
- if (!jwk) throw new Error("missing live session key");
3840
- stagedReplace.call(stagedManager, clonePersistedSessionJwk(JSON.parse(jwk)), keyId);
3841
- }
3842
3852
  stagedKeyId = stagedReplace.call(stagedManager, restoredJwk, this.sessionKeyId);
3843
- const stagedJwkJson = stagedManager.jwk(stagedKeyId);
3844
- if (!stagedJwkJson) throw new Error("missing restored session key");
3845
- stagedJwk = clonePersistedSessionJwk(JSON.parse(stagedJwkJson));
3846
- canonicalVerificationMethod = stagedManager.getDID(stagedKeyId);
3847
- } catch (error) {
3848
- if (error instanceof UnsupportedSessionRestoreError) throw error;
3849
- throw new Error("Persisted session has an invalid private Ed25519 session key.");
3853
+ } catch {
3854
+ throw new InvalidRestoredSessionError("Persisted session has an invalid private Ed25519 session key.");
3850
3855
  }
3856
+ const stagedJwkJson = stagedManager.jwk(stagedKeyId);
3857
+ if (!stagedJwkJson) throw new Error("missing restored session key");
3858
+ stagedJwk = clonePersistedSessionJwk(JSON.parse(stagedJwkJson));
3859
+ canonicalVerificationMethod = stagedManager.getDID(stagedKeyId);
3851
3860
  const restoredVerificationMethod = canonicalRestoredVerificationMethod(
3852
3861
  canonicalVerificationMethod,
3853
3862
  sessionData.verificationMethod
3854
3863
  );
3855
3864
  if (!restoredVerificationMethod) {
3856
- throw new Error(
3865
+ throw new InvalidRestoredSessionError(
3857
3866
  "Persisted session verification method does not match its private Ed25519 session key."
3858
3867
  );
3859
3868
  }
@@ -3865,25 +3874,36 @@ var _TinyCloudNode = class _TinyCloudNode {
3865
3874
  ];
3866
3875
  const hasPersistedProof = proofValues.every((value) => value !== void 0);
3867
3876
  if (!hasPersistedProof && (proofValues.some((value) => value !== void 0) || sessionData.expiresAt !== void 0)) {
3868
- throw new Error("Persisted session authority metadata is incomplete.");
3877
+ throw new InvalidRestoredSessionError("Persisted session authority metadata is incomplete.");
3878
+ }
3879
+ let restoredAddress;
3880
+ try {
3881
+ restoredAddress = hasPersistedProof ? canonicalizeAddress2(sessionData.address) : void 0;
3882
+ } catch {
3883
+ throw new InvalidRestoredSessionError("Persisted session has an invalid wallet address.");
3869
3884
  }
3870
- const restoredAddress = hasPersistedProof ? canonicalizeAddress2(sessionData.address) : void 0;
3871
3885
  let stagedSessionExpiry = /* @__PURE__ */ new Date(0);
3872
3886
  let stagedRecap = [];
3873
3887
  if (hasPersistedProof) {
3874
3888
  if (typeof this.wasmBindings.validatePersistedSession !== "function") {
3875
3889
  throw new UnsupportedSessionRestoreError("it cannot verify persisted SIWE authority");
3876
3890
  }
3877
- const verified = this.wasmBindings.validatePersistedSession({
3878
- delegationHeader: sessionData.delegationHeader,
3879
- delegationCid: sessionData.delegationCid,
3880
- spaceId: sessionData.spaceId,
3881
- jwk: stagedJwk,
3882
- address: restoredAddress,
3883
- chainId: sessionData.chainId,
3884
- siwe: sessionData.siwe,
3885
- signature: sessionData.signature
3886
- });
3891
+ const verified = (() => {
3892
+ try {
3893
+ return this.wasmBindings.validatePersistedSession({
3894
+ delegationHeader: sessionData.delegationHeader,
3895
+ delegationCid: sessionData.delegationCid,
3896
+ spaceId: sessionData.spaceId,
3897
+ jwk: stagedJwk,
3898
+ address: restoredAddress,
3899
+ chainId: sessionData.chainId,
3900
+ siwe: sessionData.siwe,
3901
+ signature: sessionData.signature
3902
+ });
3903
+ } catch (error) {
3904
+ throw new InvalidRestoredSessionError(error instanceof Error ? error.message : String(error));
3905
+ }
3906
+ })();
3887
3907
  const exactRecap = verified.verifiedRecap;
3888
3908
  if (!Array.isArray(exactRecap) || !exactRecap.every(
3889
3909
  (entry) => entry !== null && typeof entry === "object" && typeof entry.service === "string" && typeof entry.space === "string" && typeof entry.path === "string" && Array.isArray(entry.actions) && entry.actions.every((action) => typeof action === "string") && Array.isArray(entry.caveats) && entry.caveats.every(
@@ -3904,7 +3924,7 @@ var _TinyCloudNode = class _TinyCloudNode {
3904
3924
  const signedExpiry = verified.expiresAt === void 0 ? void 0 : persistedExpiry(verified.expiresAt);
3905
3925
  const persistedPolicyExpiry = sessionData.expiresAt === void 0 ? void 0 : persistedExpiry(sessionData.expiresAt);
3906
3926
  if (signedExpiry && persistedPolicyExpiry && !sameInstant(signedExpiry, persistedPolicyExpiry)) {
3907
- throw new Error("Persisted session expiry does not match its signed SIWE authority.");
3927
+ throw new InvalidRestoredSessionError("Persisted session expiry does not match its signed SIWE authority.");
3908
3928
  }
3909
3929
  stagedSessionExpiry = signedExpiry ?? persistedPolicyExpiry ?? persistedExpiry(void 0);
3910
3930
  }
@@ -4097,7 +4117,7 @@ var _TinyCloudNode = class _TinyCloudNode {
4097
4117
  const delegations = input.recap.map((entry) => ({
4098
4118
  cid: session.delegationCid,
4099
4119
  delegateDID: session.verificationMethod,
4100
- spaceId: entry.space,
4120
+ spaceId: this.spaceIdsEqual(entry.space, session.spaceId) ? session.spaceId : entry.space,
4101
4121
  path: entry.path,
4102
4122
  actions: [...entry.actions],
4103
4123
  caveats: cloneRecapCaveats(entry.caveats),
@@ -6867,21 +6887,15 @@ var _TinyCloudNode = class _TinyCloudNode {
6867
6887
  }
6868
6888
  return granted.spaceId !== void 0 && requested.spaceId !== void 0 && this.spaceIdsEqual(granted.spaceId, requested.spaceId) && this.pathContains(granted.path, requested.path);
6869
6889
  }
6870
- // Space IDs are `tinycloud:pkh:eip155:<chain>:<0xADDR>:<name>`. The embedded
6871
- // EIP-155 address is case-insensitive, but the CLI canonicalizes it to
6872
- // lowercase when building a space URI while stored runtime delegations keep
6873
- // the EIP-55 checksummed form — so a byte-for-byte compare spuriously rejects
6874
- // an otherwise-valid grant. Lowercase ONLY the `eip155:<chain>:0x<addr>`
6875
- // segment and leave everything else (crucially the case-sensitive space NAME)
6876
- // byte-exact. Mirrors the CLI's `normalizeSpaceForCompare` (OPENKEY_SCOPE_MISMATCH fix).
6890
+ // Space IDs are `tinycloud:pkh:eip155:<chain>:<0xADDR>:<name>`. Compare
6891
+ // only the embedded EIP-155 address without case sensitivity; chain, name,
6892
+ // and all non-PKH space identifiers remain byte-exact.
6877
6893
  spaceIdsEqual(a, b) {
6878
6894
  return this.normalizeSpaceAddress(a) === this.normalizeSpaceAddress(b);
6879
6895
  }
6880
6896
  normalizeSpaceAddress(space) {
6881
- return space.replace(
6882
- /(eip155:\d+:)(0x[0-9a-fA-F]{40})/,
6883
- (_match, prefix, addr) => prefix + addr.toLowerCase()
6884
- );
6897
+ const match = /^(tinycloud:pkh:eip155:\d+:)(0x[0-9a-fA-F]{40})(:.+)$/.exec(space);
6898
+ return match === null ? space : `${match[1]}${match[2].toLowerCase()}${match[3]}`;
6885
6899
  }
6886
6900
  actionContains(grantedAction, requestedAction) {
6887
6901
  if (grantedAction === requestedAction) {
@@ -7825,6 +7839,7 @@ export {
7825
7839
  DuckDbService3 as DuckDbService,
7826
7840
  FileSessionStorage,
7827
7841
  IdentityParseError,
7842
+ InvalidRestoredSessionError,
7828
7843
  KVService3 as KVService,
7829
7844
  ManifestValidationError,
7830
7845
  MemorySessionStorage,