@tinycloud/sdk-core 2.3.0-beta.2 → 2.3.0-beta.4

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,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { InvokeFunction, InvokeAnyFunction, ServiceError, Result as Result$1, ServiceSession, FetchFunction, ServiceConstructor, RetryPolicy, IServiceContext, IService, IKVService, ISQLService, IDuckDbService, IHooksService, IDataVaultService, IEncryptionService } from '@tinycloud/sdk-services';
2
+ import { InvokeFunction, InvokeAnyFunction, ParsedNetworkId, ServiceError, Result as Result$1, ServiceSession, FetchFunction, ServiceConstructor, RetryPolicy, IServiceContext, IService, IKVService, ISQLService, IDuckDbService, IHooksService, IDataVaultService, IEncryptionService } from '@tinycloud/sdk-services';
3
3
  export { BatchOptions, BatchResponse, BuildCanonicalDecryptRequestInput, BuildDecryptFactsInput, BuildDecryptInvocationInput, BuiltDecryptInvocation, CanonicalDecryptRequest, CanonicalJson, ColumnInfo, DECRYPT_ACTION, DECRYPT_FACT_TYPE, DECRYPT_RESULT_TYPE, DEFAULT_ENCRYPTION_ALG, DEFAULT_KEY_VERSION, DataVaultConfig, DataVaultService, DatabaseHandle, DecryptCapabilityProof, DecryptEnvelopeOptions, DecryptInvocationFact, DecryptInvocationSigner, DecryptRequestBody, DecryptResponseBody, DecryptTransport, DiscoverNetworkInput, DiscoveredNetwork, DiscoverySource, DuckDbAction, DuckDbActionType, DuckDbBatchOptions, DuckDbBatchResponse, DuckDbDatabaseHandle, DuckDbExecuteOptions, DuckDbExecuteResponse, DuckDbOptions, DuckDbQueryOptions, DuckDbQueryResponse, DuckDbService, DuckDbServiceConfig, DuckDbStatement, DuckDbValue, ENCRYPTION_NETWORK_URN_PREFIX, ENCRYPTION_SERVICE, ENCRYPTION_SERVICE_SHORT, ENVELOPE_VERSION, EncryptToNetworkInput, EncryptToNetworkOptions, EncryptToNetworkResult, EncryptionCrypto, EncryptionError, EncryptionErrorInput, EncryptionService, EncryptionServiceConfig, ErrorCode, ErrorCodes, ExecuteOptions, ExecuteResponse, FetchFunction, HookEvent, HookServiceName, HookStreamEvent, HookSubscription, HookWebhookListOptions, HookWebhookRecord, HookWebhookRegistration, HookWebhookScope, HookWebhookUnregisterOptions, HooksService, HooksServiceConfig, IDataVaultService, IDatabaseHandle, IDuckDbDatabaseHandle, IDuckDbService, IEncryptionService, IHooksService, IKVService, IPrefixedKVService, ISQLService, ISecretsService, IService, IServiceContext, InlineEncryptedEnvelope, InvokeAnyEntry, InvokeAnyFunction, InvokeFunction, KVCreateSignedReadUrlOptions, KVDeleteOptions, KVGetOptions, KVHeadOptions, KVListOptions, KVListResponse, KVPutOptions, KVResponse, KVResponseHeaders, KVService, KVServiceConfig, KVSignedReadUrlResponse, NETWORK_NAME_PATTERN, NetworkDescriptor, NetworkIdError, NodeDescriptorFetcher, ParsedNetworkId, PrefixedKVService, QueryOptions, QueryResponse, RandomReceiverKeyInput, ReceiverKeyPair, ReceiverKeySigner, ResolvedSecretPath, Result, RetryPolicy, SECRET_NAME_RE, SQLAction, SQLActionType, SQLService, SQLServiceConfig, SchemaInfo, SecretPayload, SecretScopeOptions, SecretsError, SecretsService, ServiceContext, ServiceContextConfig, ServiceError, ServiceSession, SignedReceiverKeyInput, SqlStatement, SqlValue, SubscribeOptions, TableInfo, VaultCrypto, VaultEntry, VaultError, VaultGetOptions, VaultGrantOptions, VaultHeaders, VaultListOptions, VaultPublicSpaceKVActions, VaultPutOptions, VerifyDecryptResponseInput, ViewInfo, WasmVaultFunctions, WellKnownDescriptorFetcher, buildCanonicalDecryptRequest, buildDecryptAttenuation, buildDecryptFacts, buildDecryptInvocation, buildNetworkId, canonicalHashHex, canonicalSignedResponse, canonicalizeEncryptionJson, canonicalizeSecretScope, checkDecryptInvocationInput, createVaultCrypto, decryptEnvelopeWithKey, defaultRetryPolicy, deriveSignedReceiverKey, discoverNetwork, encryptToNetwork, base64Decode as encryptionBase64Decode, base64Encode as encryptionBase64Encode, encryptionError, utf8Decode as encryptionUtf8Decode, utf8Encode as encryptionUtf8Encode, ensureNetworkUsableForDecrypt, err, generateRandomReceiverKey, hexDecode, hexEncode, isNetworkId, networkDiscoveryKey, ok, openWrappedKey, parseNetworkId, resolveSecretListPrefix, resolveSecretPath, serviceError, validateEnvelope, verifyDecryptResponse } from '@tinycloud/sdk-services';
4
4
  export { SiweMessage } from 'siwe';
5
5
 
@@ -798,6 +798,50 @@ interface ISigner {
798
798
  signMessage(message: Bytes | string): Promise<string>;
799
799
  }
800
800
 
801
+ type CanonicalAddress = `0x${string}`;
802
+ interface PkhDidParts {
803
+ method: "pkh";
804
+ namespace: "eip155";
805
+ chainId: number;
806
+ address: CanonicalAddress;
807
+ }
808
+ interface DidEqualsOptions {
809
+ ignoreFragment?: boolean;
810
+ }
811
+ interface DidCacheKeyOptions {
812
+ preserveFragment?: boolean;
813
+ }
814
+ declare class IdentityParseError extends Error {
815
+ constructor(message: string);
816
+ }
817
+ declare function isEvmAddress(input: string): boolean;
818
+ declare function canonicalizeAddress(address: string): CanonicalAddress;
819
+ declare function addressStorageKey(address: string): CanonicalAddress;
820
+ declare function pkhDid(address: string, chainId?: number): string;
821
+ declare function parsePkhDid(did: string): PkhDidParts | null;
822
+ declare function canonicalizeDid(did: string): string;
823
+ declare function canonicalizeDidUrl(didUrl: string): string;
824
+ declare function principalDid(didUrl: string): string;
825
+ declare function didEquals(a: string, b: string, options?: DidEqualsOptions): boolean;
826
+ declare function principalDidEquals(a: string, b: string): boolean;
827
+ declare function didCacheKey(input: string, options?: DidCacheKeyOptions): string;
828
+ declare function makePkhSpaceId(address: string, chainId: number, name: string): string;
829
+
830
+ interface CanonicalParsedNetworkId extends ParsedNetworkId {
831
+ /** Owner DID canonicalized with TinyCloud identity rules. */
832
+ ownerDid: string;
833
+ }
834
+ /**
835
+ * Canonicalize a TinyCloud encryption network id.
836
+ *
837
+ * Network ids embed an owner DID. For `did:pkh:eip155` owners, address casing
838
+ * can vary between SIWE/session tokens and delegated network resources. This
839
+ * helper parses the network id, canonicalizes the owner DID, and rebuilds the
840
+ * URN so comparisons can use one stable representation.
841
+ */
842
+ declare function canonicalizeNetworkId(networkId: string): string;
843
+ declare function parseCanonicalNetworkId(networkId: string): CanonicalParsedNetworkId;
844
+
801
845
  /**
802
846
  * Zod schemas for session persistence types.
803
847
  *
@@ -4649,4 +4693,4 @@ declare const EXPIRY: {
4649
4693
  declare const DEFAULT_SIGNED_READ_URL_EXPIRY_MS: number;
4650
4694
  type ExpiryTier = keyof typeof EXPIRY;
4651
4695
 
4652
- export { ACCOUNT_REGISTRY_PATH, ACCOUNT_REGISTRY_SPACE, type AbilitiesMap, AutoApproveSpaceCreationHandler, type AutoRejectStrategy, type AutoSignStrategy, type Bytes, type CallbackStrategy, type CapabilityEntry, CapabilityKeyRegistry, type CapabilityKeyRegistryErrorCode, CapabilityKeyRegistryErrorCodes, type ClientSession, ClientSessionSchema, CloudLocationResolutionError, type ComposeManifestOptions, type ComposedManifestRequest, type CreateDelegationFunction, type CreateDelegationParams, type CreateDelegationWasmParams, type CreateDelegationWasmResult, DEFAULT_DEFAULTS, DEFAULT_EXPIRY, DEFAULT_MANIFEST_SPACE, DEFAULT_MANIFEST_VERSION, DEFAULT_SIGNED_READ_URL_EXPIRY_MS, DEFAULT_TINYCLOUD_FALLBACK_HOST, DEFAULT_TINYCLOUD_LOCATION_REGISTRY_URL, type DelegatedResource, type Delegation, type DelegationApiResponse, type DelegationChain, type DelegationChainV2, type DelegationDirection, type DelegationError, type DelegationErrorCode, DelegationErrorCodes, type DelegationFilters, DelegationManager, type DelegationManagerConfig, type DelegationRecord, type Result as DelegationResult, ENCRYPTION_MANIFEST_SPACE, ENCRYPTION_PERMISSION_SERVICE, EXPIRY, type EncodedShareData, type EnsData, EnsDataSchema, type EventEmitterStrategy, type ExpiryTier, type Extension, type GenerateShareParams, type ICapabilityKeyRegistry, type IENSResolver, type INotificationHandler, type ISessionManager, type ISessionStorage, type ISharingService, type ISigner, type ISpace, type ISpaceCreationHandler, type ISpaceScopedDelegations, type ISpaceScopedSharing, type ISpaceService, type IUserAuthorization, type IWasmBindings, type IngestOptions, type JWK, type KeyInfo, type KeyProvider, type KeyType, type LocationCandidate, type LocationCandidateInput, type LocationRecord, type LocationRecordPayload, type LocationRecordSigner, LocationRecordValidationError, type LocationResolutionAttempt, type LocationSource, type Manifest, type ManifestDefaults, type ManifestRegistryRecord, type ManifestSecretActions, ManifestValidationError, type NodeInfo, type ParseRecapFromSiwe, type PartialSiweMessage, type PermissionEntry, PermissionNotInManifestError, type PersistedSessionData, type PersistedTinyCloudSession, ProtocolMismatchError, type ReceiveOptions, type ResolveCloudLocationOptions, type ResolveTinyCloudHostsOptions, type ResolvedCapabilities, type ResolvedCloudLocation, type ResolvedDelegate, type ResolvedTinyCloudHosts, type ResourceCapability, SERVICE_LONG_TO_SHORT, SERVICE_SHORT_TO_LONG, type ServerHost, SessionExpiredError, type ShareAccess, type ShareLink, type ShareLinkData, type ShareSchema, SharingService, type SharingServiceConfig, type SignCallback, type SignInOptions, type SignRequest, type SignResponse, type SignStrategy, SilentNotificationHandler, type SiweConfig, SiweConfigSchema, Space, type SpaceAbilitiesMap, type SpaceConfig, type SpaceCreationContext, type SpaceDelegationParams, type SpaceErrorCode, SpaceErrorCodes, type SpaceHostResult, type SpaceInfo, type SpaceOwnership, SpaceService, type SpaceServiceConfig, type StoredDelegationChain, type SubsetCheckResult, TinyCloud, type TinyCloudConfig, type TinyCloudSession, UnsupportedFeatureError, type UserAuthorizationConfig, VAULT_PERMISSION_SERVICE, type ValidationError, VersionCheckError, type WasmRecapEntry, activateSessionWithHost, applyPrefix, buildSpaceUri, canonicalLocationPayload, checkNodeInfo, composeManifestRequest, createCapabilityKeyRegistry, createSharingService, createSpaceService, defaultSignStrategy, defaultSpaceCreationHandler, expandActionShortNames, expandPermissionEntries, expandPermissionEntry, fetchLocationRecord, fetchPeerId, httpUrlToMultiaddr, isCapabilitySubset, loadManifest, locationPayloadForRecord, makePublicSpaceId, manifestAbilitiesUnion, multiaddrToHttpUrl, normalizeDefaults, parseExpiry, parseRecapCapabilities, parseSpaceUri, resolveCloudLocation, resolveManifest, resolveTinyCloudHosts, resourceCapabilitiesToAbilitiesMap, resourceCapabilitiesToSpaceAbilitiesMap, signLocationRecord, submitHostDelegation, validateClientSession, validateLocationRecord, validateLocationRecordPayload, validateManifest, validatePersistedSessionData, verifyDidKeyEd25519Signature, verifyLocationRecord };
4696
+ export { ACCOUNT_REGISTRY_PATH, ACCOUNT_REGISTRY_SPACE, type AbilitiesMap, AutoApproveSpaceCreationHandler, type AutoRejectStrategy, type AutoSignStrategy, type Bytes, type CallbackStrategy, type CanonicalAddress, type CanonicalParsedNetworkId, type CapabilityEntry, CapabilityKeyRegistry, type CapabilityKeyRegistryErrorCode, CapabilityKeyRegistryErrorCodes, type ClientSession, ClientSessionSchema, CloudLocationResolutionError, type ComposeManifestOptions, type ComposedManifestRequest, type CreateDelegationFunction, type CreateDelegationParams, type CreateDelegationWasmParams, type CreateDelegationWasmResult, DEFAULT_DEFAULTS, DEFAULT_EXPIRY, DEFAULT_MANIFEST_SPACE, DEFAULT_MANIFEST_VERSION, DEFAULT_SIGNED_READ_URL_EXPIRY_MS, DEFAULT_TINYCLOUD_FALLBACK_HOST, DEFAULT_TINYCLOUD_LOCATION_REGISTRY_URL, type DelegatedResource, type Delegation, type DelegationApiResponse, type DelegationChain, type DelegationChainV2, type DelegationDirection, type DelegationError, type DelegationErrorCode, DelegationErrorCodes, type DelegationFilters, DelegationManager, type DelegationManagerConfig, type DelegationRecord, type Result as DelegationResult, type DidCacheKeyOptions, type DidEqualsOptions, ENCRYPTION_MANIFEST_SPACE, ENCRYPTION_PERMISSION_SERVICE, EXPIRY, type EncodedShareData, type EnsData, EnsDataSchema, type EventEmitterStrategy, type ExpiryTier, type Extension, type GenerateShareParams, type ICapabilityKeyRegistry, type IENSResolver, type INotificationHandler, type ISessionManager, type ISessionStorage, type ISharingService, type ISigner, type ISpace, type ISpaceCreationHandler, type ISpaceScopedDelegations, type ISpaceScopedSharing, type ISpaceService, type IUserAuthorization, type IWasmBindings, IdentityParseError, type IngestOptions, type JWK, type KeyInfo, type KeyProvider, type KeyType, type LocationCandidate, type LocationCandidateInput, type LocationRecord, type LocationRecordPayload, type LocationRecordSigner, LocationRecordValidationError, type LocationResolutionAttempt, type LocationSource, type Manifest, type ManifestDefaults, type ManifestRegistryRecord, type ManifestSecretActions, ManifestValidationError, type NodeInfo, type ParseRecapFromSiwe, type PartialSiweMessage, type PermissionEntry, PermissionNotInManifestError, type PersistedSessionData, type PersistedTinyCloudSession, type PkhDidParts, ProtocolMismatchError, type ReceiveOptions, type ResolveCloudLocationOptions, type ResolveTinyCloudHostsOptions, type ResolvedCapabilities, type ResolvedCloudLocation, type ResolvedDelegate, type ResolvedTinyCloudHosts, type ResourceCapability, SERVICE_LONG_TO_SHORT, SERVICE_SHORT_TO_LONG, type ServerHost, SessionExpiredError, type ShareAccess, type ShareLink, type ShareLinkData, type ShareSchema, SharingService, type SharingServiceConfig, type SignCallback, type SignInOptions, type SignRequest, type SignResponse, type SignStrategy, SilentNotificationHandler, type SiweConfig, SiweConfigSchema, Space, type SpaceAbilitiesMap, type SpaceConfig, type SpaceCreationContext, type SpaceDelegationParams, type SpaceErrorCode, SpaceErrorCodes, type SpaceHostResult, type SpaceInfo, type SpaceOwnership, SpaceService, type SpaceServiceConfig, type StoredDelegationChain, type SubsetCheckResult, TinyCloud, type TinyCloudConfig, type TinyCloudSession, UnsupportedFeatureError, type UserAuthorizationConfig, VAULT_PERMISSION_SERVICE, type ValidationError, VersionCheckError, type WasmRecapEntry, activateSessionWithHost, addressStorageKey, applyPrefix, buildSpaceUri, canonicalLocationPayload, canonicalizeAddress, canonicalizeDid, canonicalizeDidUrl, canonicalizeNetworkId, checkNodeInfo, composeManifestRequest, createCapabilityKeyRegistry, createSharingService, createSpaceService, defaultSignStrategy, defaultSpaceCreationHandler, didCacheKey, didEquals, expandActionShortNames, expandPermissionEntries, expandPermissionEntry, fetchLocationRecord, fetchPeerId, httpUrlToMultiaddr, isCapabilitySubset, isEvmAddress, loadManifest, locationPayloadForRecord, makePkhSpaceId, makePublicSpaceId, manifestAbilitiesUnion, multiaddrToHttpUrl, normalizeDefaults, parseCanonicalNetworkId, parseExpiry, parsePkhDid, parseRecapCapabilities, parseSpaceUri, pkhDid, principalDid, principalDidEquals, resolveCloudLocation, resolveManifest, resolveTinyCloudHosts, resourceCapabilitiesToAbilitiesMap, resourceCapabilitiesToSpaceAbilitiesMap, signLocationRecord, submitHostDelegation, validateClientSession, validateLocationRecord, validateLocationRecordPayload, validateManifest, validatePersistedSessionData, verifyDidKeyEd25519Signature, verifyLocationRecord };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { InvokeFunction, InvokeAnyFunction, ServiceError, Result as Result$1, ServiceSession, FetchFunction, ServiceConstructor, RetryPolicy, IServiceContext, IService, IKVService, ISQLService, IDuckDbService, IHooksService, IDataVaultService, IEncryptionService } from '@tinycloud/sdk-services';
2
+ import { InvokeFunction, InvokeAnyFunction, ParsedNetworkId, ServiceError, Result as Result$1, ServiceSession, FetchFunction, ServiceConstructor, RetryPolicy, IServiceContext, IService, IKVService, ISQLService, IDuckDbService, IHooksService, IDataVaultService, IEncryptionService } from '@tinycloud/sdk-services';
3
3
  export { BatchOptions, BatchResponse, BuildCanonicalDecryptRequestInput, BuildDecryptFactsInput, BuildDecryptInvocationInput, BuiltDecryptInvocation, CanonicalDecryptRequest, CanonicalJson, ColumnInfo, DECRYPT_ACTION, DECRYPT_FACT_TYPE, DECRYPT_RESULT_TYPE, DEFAULT_ENCRYPTION_ALG, DEFAULT_KEY_VERSION, DataVaultConfig, DataVaultService, DatabaseHandle, DecryptCapabilityProof, DecryptEnvelopeOptions, DecryptInvocationFact, DecryptInvocationSigner, DecryptRequestBody, DecryptResponseBody, DecryptTransport, DiscoverNetworkInput, DiscoveredNetwork, DiscoverySource, DuckDbAction, DuckDbActionType, DuckDbBatchOptions, DuckDbBatchResponse, DuckDbDatabaseHandle, DuckDbExecuteOptions, DuckDbExecuteResponse, DuckDbOptions, DuckDbQueryOptions, DuckDbQueryResponse, DuckDbService, DuckDbServiceConfig, DuckDbStatement, DuckDbValue, ENCRYPTION_NETWORK_URN_PREFIX, ENCRYPTION_SERVICE, ENCRYPTION_SERVICE_SHORT, ENVELOPE_VERSION, EncryptToNetworkInput, EncryptToNetworkOptions, EncryptToNetworkResult, EncryptionCrypto, EncryptionError, EncryptionErrorInput, EncryptionService, EncryptionServiceConfig, ErrorCode, ErrorCodes, ExecuteOptions, ExecuteResponse, FetchFunction, HookEvent, HookServiceName, HookStreamEvent, HookSubscription, HookWebhookListOptions, HookWebhookRecord, HookWebhookRegistration, HookWebhookScope, HookWebhookUnregisterOptions, HooksService, HooksServiceConfig, IDataVaultService, IDatabaseHandle, IDuckDbDatabaseHandle, IDuckDbService, IEncryptionService, IHooksService, IKVService, IPrefixedKVService, ISQLService, ISecretsService, IService, IServiceContext, InlineEncryptedEnvelope, InvokeAnyEntry, InvokeAnyFunction, InvokeFunction, KVCreateSignedReadUrlOptions, KVDeleteOptions, KVGetOptions, KVHeadOptions, KVListOptions, KVListResponse, KVPutOptions, KVResponse, KVResponseHeaders, KVService, KVServiceConfig, KVSignedReadUrlResponse, NETWORK_NAME_PATTERN, NetworkDescriptor, NetworkIdError, NodeDescriptorFetcher, ParsedNetworkId, PrefixedKVService, QueryOptions, QueryResponse, RandomReceiverKeyInput, ReceiverKeyPair, ReceiverKeySigner, ResolvedSecretPath, Result, RetryPolicy, SECRET_NAME_RE, SQLAction, SQLActionType, SQLService, SQLServiceConfig, SchemaInfo, SecretPayload, SecretScopeOptions, SecretsError, SecretsService, ServiceContext, ServiceContextConfig, ServiceError, ServiceSession, SignedReceiverKeyInput, SqlStatement, SqlValue, SubscribeOptions, TableInfo, VaultCrypto, VaultEntry, VaultError, VaultGetOptions, VaultGrantOptions, VaultHeaders, VaultListOptions, VaultPublicSpaceKVActions, VaultPutOptions, VerifyDecryptResponseInput, ViewInfo, WasmVaultFunctions, WellKnownDescriptorFetcher, buildCanonicalDecryptRequest, buildDecryptAttenuation, buildDecryptFacts, buildDecryptInvocation, buildNetworkId, canonicalHashHex, canonicalSignedResponse, canonicalizeEncryptionJson, canonicalizeSecretScope, checkDecryptInvocationInput, createVaultCrypto, decryptEnvelopeWithKey, defaultRetryPolicy, deriveSignedReceiverKey, discoverNetwork, encryptToNetwork, base64Decode as encryptionBase64Decode, base64Encode as encryptionBase64Encode, encryptionError, utf8Decode as encryptionUtf8Decode, utf8Encode as encryptionUtf8Encode, ensureNetworkUsableForDecrypt, err, generateRandomReceiverKey, hexDecode, hexEncode, isNetworkId, networkDiscoveryKey, ok, openWrappedKey, parseNetworkId, resolveSecretListPrefix, resolveSecretPath, serviceError, validateEnvelope, verifyDecryptResponse } from '@tinycloud/sdk-services';
4
4
  export { SiweMessage } from 'siwe';
5
5
 
@@ -798,6 +798,50 @@ interface ISigner {
798
798
  signMessage(message: Bytes | string): Promise<string>;
799
799
  }
800
800
 
801
+ type CanonicalAddress = `0x${string}`;
802
+ interface PkhDidParts {
803
+ method: "pkh";
804
+ namespace: "eip155";
805
+ chainId: number;
806
+ address: CanonicalAddress;
807
+ }
808
+ interface DidEqualsOptions {
809
+ ignoreFragment?: boolean;
810
+ }
811
+ interface DidCacheKeyOptions {
812
+ preserveFragment?: boolean;
813
+ }
814
+ declare class IdentityParseError extends Error {
815
+ constructor(message: string);
816
+ }
817
+ declare function isEvmAddress(input: string): boolean;
818
+ declare function canonicalizeAddress(address: string): CanonicalAddress;
819
+ declare function addressStorageKey(address: string): CanonicalAddress;
820
+ declare function pkhDid(address: string, chainId?: number): string;
821
+ declare function parsePkhDid(did: string): PkhDidParts | null;
822
+ declare function canonicalizeDid(did: string): string;
823
+ declare function canonicalizeDidUrl(didUrl: string): string;
824
+ declare function principalDid(didUrl: string): string;
825
+ declare function didEquals(a: string, b: string, options?: DidEqualsOptions): boolean;
826
+ declare function principalDidEquals(a: string, b: string): boolean;
827
+ declare function didCacheKey(input: string, options?: DidCacheKeyOptions): string;
828
+ declare function makePkhSpaceId(address: string, chainId: number, name: string): string;
829
+
830
+ interface CanonicalParsedNetworkId extends ParsedNetworkId {
831
+ /** Owner DID canonicalized with TinyCloud identity rules. */
832
+ ownerDid: string;
833
+ }
834
+ /**
835
+ * Canonicalize a TinyCloud encryption network id.
836
+ *
837
+ * Network ids embed an owner DID. For `did:pkh:eip155` owners, address casing
838
+ * can vary between SIWE/session tokens and delegated network resources. This
839
+ * helper parses the network id, canonicalizes the owner DID, and rebuilds the
840
+ * URN so comparisons can use one stable representation.
841
+ */
842
+ declare function canonicalizeNetworkId(networkId: string): string;
843
+ declare function parseCanonicalNetworkId(networkId: string): CanonicalParsedNetworkId;
844
+
801
845
  /**
802
846
  * Zod schemas for session persistence types.
803
847
  *
@@ -4649,4 +4693,4 @@ declare const EXPIRY: {
4649
4693
  declare const DEFAULT_SIGNED_READ_URL_EXPIRY_MS: number;
4650
4694
  type ExpiryTier = keyof typeof EXPIRY;
4651
4695
 
4652
- export { ACCOUNT_REGISTRY_PATH, ACCOUNT_REGISTRY_SPACE, type AbilitiesMap, AutoApproveSpaceCreationHandler, type AutoRejectStrategy, type AutoSignStrategy, type Bytes, type CallbackStrategy, type CapabilityEntry, CapabilityKeyRegistry, type CapabilityKeyRegistryErrorCode, CapabilityKeyRegistryErrorCodes, type ClientSession, ClientSessionSchema, CloudLocationResolutionError, type ComposeManifestOptions, type ComposedManifestRequest, type CreateDelegationFunction, type CreateDelegationParams, type CreateDelegationWasmParams, type CreateDelegationWasmResult, DEFAULT_DEFAULTS, DEFAULT_EXPIRY, DEFAULT_MANIFEST_SPACE, DEFAULT_MANIFEST_VERSION, DEFAULT_SIGNED_READ_URL_EXPIRY_MS, DEFAULT_TINYCLOUD_FALLBACK_HOST, DEFAULT_TINYCLOUD_LOCATION_REGISTRY_URL, type DelegatedResource, type Delegation, type DelegationApiResponse, type DelegationChain, type DelegationChainV2, type DelegationDirection, type DelegationError, type DelegationErrorCode, DelegationErrorCodes, type DelegationFilters, DelegationManager, type DelegationManagerConfig, type DelegationRecord, type Result as DelegationResult, ENCRYPTION_MANIFEST_SPACE, ENCRYPTION_PERMISSION_SERVICE, EXPIRY, type EncodedShareData, type EnsData, EnsDataSchema, type EventEmitterStrategy, type ExpiryTier, type Extension, type GenerateShareParams, type ICapabilityKeyRegistry, type IENSResolver, type INotificationHandler, type ISessionManager, type ISessionStorage, type ISharingService, type ISigner, type ISpace, type ISpaceCreationHandler, type ISpaceScopedDelegations, type ISpaceScopedSharing, type ISpaceService, type IUserAuthorization, type IWasmBindings, type IngestOptions, type JWK, type KeyInfo, type KeyProvider, type KeyType, type LocationCandidate, type LocationCandidateInput, type LocationRecord, type LocationRecordPayload, type LocationRecordSigner, LocationRecordValidationError, type LocationResolutionAttempt, type LocationSource, type Manifest, type ManifestDefaults, type ManifestRegistryRecord, type ManifestSecretActions, ManifestValidationError, type NodeInfo, type ParseRecapFromSiwe, type PartialSiweMessage, type PermissionEntry, PermissionNotInManifestError, type PersistedSessionData, type PersistedTinyCloudSession, ProtocolMismatchError, type ReceiveOptions, type ResolveCloudLocationOptions, type ResolveTinyCloudHostsOptions, type ResolvedCapabilities, type ResolvedCloudLocation, type ResolvedDelegate, type ResolvedTinyCloudHosts, type ResourceCapability, SERVICE_LONG_TO_SHORT, SERVICE_SHORT_TO_LONG, type ServerHost, SessionExpiredError, type ShareAccess, type ShareLink, type ShareLinkData, type ShareSchema, SharingService, type SharingServiceConfig, type SignCallback, type SignInOptions, type SignRequest, type SignResponse, type SignStrategy, SilentNotificationHandler, type SiweConfig, SiweConfigSchema, Space, type SpaceAbilitiesMap, type SpaceConfig, type SpaceCreationContext, type SpaceDelegationParams, type SpaceErrorCode, SpaceErrorCodes, type SpaceHostResult, type SpaceInfo, type SpaceOwnership, SpaceService, type SpaceServiceConfig, type StoredDelegationChain, type SubsetCheckResult, TinyCloud, type TinyCloudConfig, type TinyCloudSession, UnsupportedFeatureError, type UserAuthorizationConfig, VAULT_PERMISSION_SERVICE, type ValidationError, VersionCheckError, type WasmRecapEntry, activateSessionWithHost, applyPrefix, buildSpaceUri, canonicalLocationPayload, checkNodeInfo, composeManifestRequest, createCapabilityKeyRegistry, createSharingService, createSpaceService, defaultSignStrategy, defaultSpaceCreationHandler, expandActionShortNames, expandPermissionEntries, expandPermissionEntry, fetchLocationRecord, fetchPeerId, httpUrlToMultiaddr, isCapabilitySubset, loadManifest, locationPayloadForRecord, makePublicSpaceId, manifestAbilitiesUnion, multiaddrToHttpUrl, normalizeDefaults, parseExpiry, parseRecapCapabilities, parseSpaceUri, resolveCloudLocation, resolveManifest, resolveTinyCloudHosts, resourceCapabilitiesToAbilitiesMap, resourceCapabilitiesToSpaceAbilitiesMap, signLocationRecord, submitHostDelegation, validateClientSession, validateLocationRecord, validateLocationRecordPayload, validateManifest, validatePersistedSessionData, verifyDidKeyEd25519Signature, verifyLocationRecord };
4696
+ export { ACCOUNT_REGISTRY_PATH, ACCOUNT_REGISTRY_SPACE, type AbilitiesMap, AutoApproveSpaceCreationHandler, type AutoRejectStrategy, type AutoSignStrategy, type Bytes, type CallbackStrategy, type CanonicalAddress, type CanonicalParsedNetworkId, type CapabilityEntry, CapabilityKeyRegistry, type CapabilityKeyRegistryErrorCode, CapabilityKeyRegistryErrorCodes, type ClientSession, ClientSessionSchema, CloudLocationResolutionError, type ComposeManifestOptions, type ComposedManifestRequest, type CreateDelegationFunction, type CreateDelegationParams, type CreateDelegationWasmParams, type CreateDelegationWasmResult, DEFAULT_DEFAULTS, DEFAULT_EXPIRY, DEFAULT_MANIFEST_SPACE, DEFAULT_MANIFEST_VERSION, DEFAULT_SIGNED_READ_URL_EXPIRY_MS, DEFAULT_TINYCLOUD_FALLBACK_HOST, DEFAULT_TINYCLOUD_LOCATION_REGISTRY_URL, type DelegatedResource, type Delegation, type DelegationApiResponse, type DelegationChain, type DelegationChainV2, type DelegationDirection, type DelegationError, type DelegationErrorCode, DelegationErrorCodes, type DelegationFilters, DelegationManager, type DelegationManagerConfig, type DelegationRecord, type Result as DelegationResult, type DidCacheKeyOptions, type DidEqualsOptions, ENCRYPTION_MANIFEST_SPACE, ENCRYPTION_PERMISSION_SERVICE, EXPIRY, type EncodedShareData, type EnsData, EnsDataSchema, type EventEmitterStrategy, type ExpiryTier, type Extension, type GenerateShareParams, type ICapabilityKeyRegistry, type IENSResolver, type INotificationHandler, type ISessionManager, type ISessionStorage, type ISharingService, type ISigner, type ISpace, type ISpaceCreationHandler, type ISpaceScopedDelegations, type ISpaceScopedSharing, type ISpaceService, type IUserAuthorization, type IWasmBindings, IdentityParseError, type IngestOptions, type JWK, type KeyInfo, type KeyProvider, type KeyType, type LocationCandidate, type LocationCandidateInput, type LocationRecord, type LocationRecordPayload, type LocationRecordSigner, LocationRecordValidationError, type LocationResolutionAttempt, type LocationSource, type Manifest, type ManifestDefaults, type ManifestRegistryRecord, type ManifestSecretActions, ManifestValidationError, type NodeInfo, type ParseRecapFromSiwe, type PartialSiweMessage, type PermissionEntry, PermissionNotInManifestError, type PersistedSessionData, type PersistedTinyCloudSession, type PkhDidParts, ProtocolMismatchError, type ReceiveOptions, type ResolveCloudLocationOptions, type ResolveTinyCloudHostsOptions, type ResolvedCapabilities, type ResolvedCloudLocation, type ResolvedDelegate, type ResolvedTinyCloudHosts, type ResourceCapability, SERVICE_LONG_TO_SHORT, SERVICE_SHORT_TO_LONG, type ServerHost, SessionExpiredError, type ShareAccess, type ShareLink, type ShareLinkData, type ShareSchema, SharingService, type SharingServiceConfig, type SignCallback, type SignInOptions, type SignRequest, type SignResponse, type SignStrategy, SilentNotificationHandler, type SiweConfig, SiweConfigSchema, Space, type SpaceAbilitiesMap, type SpaceConfig, type SpaceCreationContext, type SpaceDelegationParams, type SpaceErrorCode, SpaceErrorCodes, type SpaceHostResult, type SpaceInfo, type SpaceOwnership, SpaceService, type SpaceServiceConfig, type StoredDelegationChain, type SubsetCheckResult, TinyCloud, type TinyCloudConfig, type TinyCloudSession, UnsupportedFeatureError, type UserAuthorizationConfig, VAULT_PERMISSION_SERVICE, type ValidationError, VersionCheckError, type WasmRecapEntry, activateSessionWithHost, addressStorageKey, applyPrefix, buildSpaceUri, canonicalLocationPayload, canonicalizeAddress, canonicalizeDid, canonicalizeDidUrl, canonicalizeNetworkId, checkNodeInfo, composeManifestRequest, createCapabilityKeyRegistry, createSharingService, createSpaceService, defaultSignStrategy, defaultSpaceCreationHandler, didCacheKey, didEquals, expandActionShortNames, expandPermissionEntries, expandPermissionEntry, fetchLocationRecord, fetchPeerId, httpUrlToMultiaddr, isCapabilitySubset, isEvmAddress, loadManifest, locationPayloadForRecord, makePkhSpaceId, makePublicSpaceId, manifestAbilitiesUnion, multiaddrToHttpUrl, normalizeDefaults, parseCanonicalNetworkId, parseExpiry, parsePkhDid, parseRecapCapabilities, parseSpaceUri, pkhDid, principalDid, principalDidEquals, resolveCloudLocation, resolveManifest, resolveTinyCloudHosts, resourceCapabilitiesToAbilitiesMap, resourceCapabilitiesToSpaceAbilitiesMap, signLocationRecord, submitHostDelegation, validateClientSession, validateLocationRecord, validateLocationRecordPayload, validateManifest, validatePersistedSessionData, verifyDidKeyEd25519Signature, verifyLocationRecord };
package/dist/index.js CHANGED
@@ -40,6 +40,111 @@ var SilentNotificationHandler = class {
40
40
  }
41
41
  };
42
42
 
43
+ // src/identity.ts
44
+ import { getAddress, isAddress } from "viem";
45
+ var IdentityParseError = class extends Error {
46
+ constructor(message) {
47
+ super(message);
48
+ this.name = "IdentityParseError";
49
+ }
50
+ };
51
+ var PKH_DID_RE = /^did:pkh:eip155:(\d+):(0x[a-fA-F0-9]{40})$/;
52
+ var DID_RE = /^did:[a-z0-9]+:.+$/;
53
+ function splitDidUrl(input) {
54
+ const fragmentIndex = input.indexOf("#");
55
+ if (fragmentIndex < 0) {
56
+ return { did: input, fragment: "" };
57
+ }
58
+ return {
59
+ did: input.slice(0, fragmentIndex),
60
+ fragment: input.slice(fragmentIndex)
61
+ };
62
+ }
63
+ function assertValidChainId(chainId) {
64
+ if (!Number.isSafeInteger(chainId) || chainId <= 0) {
65
+ throw new IdentityParseError(`Invalid EIP-155 chain ID: ${chainId}`);
66
+ }
67
+ }
68
+ function isEvmAddress(input) {
69
+ return isAddress(input, { strict: false });
70
+ }
71
+ function canonicalizeAddress(address) {
72
+ if (!isEvmAddress(address)) {
73
+ throw new IdentityParseError(`Invalid EVM address: ${address}`);
74
+ }
75
+ return getAddress(address);
76
+ }
77
+ function addressStorageKey(address) {
78
+ return canonicalizeAddress(address).toLowerCase();
79
+ }
80
+ function pkhDid(address, chainId = 1) {
81
+ assertValidChainId(chainId);
82
+ return `did:pkh:eip155:${chainId}:${canonicalizeAddress(address)}`;
83
+ }
84
+ function parsePkhDid(did) {
85
+ const match = did.match(PKH_DID_RE);
86
+ if (!match) return null;
87
+ const chainId = Number(match[1]);
88
+ assertValidChainId(chainId);
89
+ return {
90
+ method: "pkh",
91
+ namespace: "eip155",
92
+ chainId,
93
+ address: canonicalizeAddress(match[2])
94
+ };
95
+ }
96
+ function canonicalizeDid(did) {
97
+ const pkh = parsePkhDid(did);
98
+ if (pkh) {
99
+ return pkhDid(pkh.address, pkh.chainId);
100
+ }
101
+ if (DID_RE.test(did)) {
102
+ return did;
103
+ }
104
+ throw new IdentityParseError(`Invalid DID: ${did}`);
105
+ }
106
+ function canonicalizeDidUrl(didUrl) {
107
+ const { did, fragment } = splitDidUrl(didUrl);
108
+ return `${canonicalizeDid(did)}${fragment}`;
109
+ }
110
+ function principalDid(didUrl) {
111
+ return canonicalizeDid(splitDidUrl(didUrl).did);
112
+ }
113
+ function didEquals(a, b, options = {}) {
114
+ const canonicalize = options.ignoreFragment ? principalDid : canonicalizeDidUrl;
115
+ return canonicalize(a) === canonicalize(b);
116
+ }
117
+ function principalDidEquals(a, b) {
118
+ return didEquals(a, b, { ignoreFragment: true });
119
+ }
120
+ function didCacheKey(input, options = {}) {
121
+ const { did, fragment } = splitDidUrl(input);
122
+ const pkh = parsePkhDid(did);
123
+ const base = pkh ? `did:pkh:eip155:${pkh.chainId}:${addressStorageKey(pkh.address)}` : canonicalizeDid(did);
124
+ return options.preserveFragment ? `${base}${fragment}` : base;
125
+ }
126
+ function makePkhSpaceId(address, chainId, name) {
127
+ assertValidChainId(chainId);
128
+ if (!name) {
129
+ throw new IdentityParseError("Space name cannot be empty");
130
+ }
131
+ return `tinycloud:pkh:eip155:${chainId}:${canonicalizeAddress(address)}:${name}`;
132
+ }
133
+
134
+ // src/networkId.ts
135
+ import {
136
+ buildNetworkId,
137
+ parseNetworkId
138
+ } from "@tinycloud/sdk-services";
139
+ function canonicalizeNetworkId(networkId) {
140
+ const parsed = parseNetworkId(networkId);
141
+ return buildNetworkId(canonicalizeDid(parsed.ownerDid), parsed.name);
142
+ }
143
+ function parseCanonicalNetworkId(networkId) {
144
+ const canonical = canonicalizeNetworkId(networkId);
145
+ return parseNetworkId(canonical);
146
+ }
147
+
43
148
  // src/storage.schema.ts
44
149
  import { z as z2 } from "zod";
45
150
  var ethereumAddressPattern = /^0x[a-fA-F0-9]{40}$/;
@@ -747,6 +852,14 @@ var DEFAULT_SIGNED_READ_URL_EXPIRY_MS = EXPIRY.SIGNED_READ_URL_MS;
747
852
 
748
853
  // src/spaces/SpaceService.ts
749
854
  var SERVICE_NAME = "space";
855
+ function ownerDidEquals(a, b) {
856
+ if (!b) return false;
857
+ try {
858
+ return principalDidEquals(a, b);
859
+ } catch {
860
+ return a === b;
861
+ }
862
+ }
750
863
  var SpaceErrorCodes = {
751
864
  /** Space not found */
752
865
  NOT_FOUND: "SPACE_NOT_FOUND",
@@ -764,7 +877,7 @@ var SpaceErrorCodes = {
764
877
  NOT_INITIALIZED: "NOT_INITIALIZED"
765
878
  };
766
879
  function makePublicSpaceId(address, chainId) {
767
- return `tinycloud:pkh:eip155:${chainId}:${address}:public`;
880
+ return makePkhSpaceId(address, chainId, "public");
768
881
  }
769
882
  function parseSpaceUri(uri) {
770
883
  const fullUriMatch = uri.match(
@@ -772,12 +885,18 @@ function parseSpaceUri(uri) {
772
885
  );
773
886
  if (fullUriMatch) {
774
887
  const [, chainId, address, name] = fullUriMatch;
775
- return {
776
- owner: `did:pkh:eip155:${chainId}:${address}`,
777
- name,
778
- chainId,
779
- address
780
- };
888
+ try {
889
+ const chainIdNumber = Number(chainId);
890
+ const canonicalAddress = canonicalizeAddress(address);
891
+ return {
892
+ owner: pkhDid(canonicalAddress, chainIdNumber),
893
+ name,
894
+ chainId: String(chainIdNumber),
895
+ address: canonicalAddress
896
+ };
897
+ } catch {
898
+ return null;
899
+ }
781
900
  }
782
901
  if (/^[a-zA-Z0-9_-]+$/.test(uri)) {
783
902
  return {
@@ -789,10 +908,9 @@ function parseSpaceUri(uri) {
789
908
  return null;
790
909
  }
791
910
  function buildSpaceUri(owner, name) {
792
- const pkhMatch = owner.match(/^did:pkh:eip155:(\d+):(0x[a-fA-F0-9]{40})$/);
793
- if (pkhMatch) {
794
- const [, chainId, address] = pkhMatch;
795
- return `tinycloud:pkh:eip155:${chainId}:${address}:${name}`;
911
+ const pkh = parsePkhDid(owner);
912
+ if (pkh) {
913
+ return makePkhSpaceId(pkh.address, pkh.chainId, name);
796
914
  }
797
915
  return `tinycloud:${owner}:${name}`;
798
916
  }
@@ -1241,7 +1359,7 @@ var SpaceService = class {
1241
1359
  id: data.id,
1242
1360
  name: data.name ?? this.extractNameFromId(data.id),
1243
1361
  owner: data.owner,
1244
- type: data.type ?? (data.owner === this.userDid ? "owned" : "delegated"),
1362
+ type: data.type ?? (ownerDidEquals(data.owner, this.userDid) ? "owned" : "delegated"),
1245
1363
  permissions: data.permissions,
1246
1364
  expiresAt: data.expiresAt ? new Date(data.expiresAt) : void 0
1247
1365
  };
@@ -2058,8 +2176,8 @@ import {
2058
2176
  resolveSecretListPrefix,
2059
2177
  resolveSecretPath as resolveSecretPath2,
2060
2178
  EncryptionService,
2061
- parseNetworkId,
2062
- buildNetworkId,
2179
+ parseNetworkId as parseNetworkId2,
2180
+ buildNetworkId as buildNetworkId2,
2063
2181
  isNetworkId,
2064
2182
  networkDiscoveryKey,
2065
2183
  NetworkIdError,
@@ -5199,6 +5317,7 @@ export {
5199
5317
  EnsDataSchema,
5200
5318
  ErrorCodes2 as ErrorCodes,
5201
5319
  HooksService2 as HooksService,
5320
+ IdentityParseError,
5202
5321
  KVService2 as KVService,
5203
5322
  LocationRecordValidationError,
5204
5323
  ManifestValidationError,
@@ -5229,17 +5348,22 @@ export {
5229
5348
  VaultPublicSpaceKVActions,
5230
5349
  VersionCheckError,
5231
5350
  activateSessionWithHost,
5351
+ addressStorageKey,
5232
5352
  applyPrefix,
5233
5353
  buildCanonicalDecryptRequest,
5234
5354
  buildDecryptAttenuation,
5235
5355
  buildDecryptFacts,
5236
5356
  buildDecryptInvocation,
5237
- buildNetworkId,
5357
+ buildNetworkId2 as buildNetworkId,
5238
5358
  buildSpaceUri,
5239
5359
  canonicalHashHex,
5240
5360
  canonicalLocationPayload,
5241
5361
  canonicalSignedResponse,
5362
+ canonicalizeAddress,
5363
+ canonicalizeDid,
5364
+ canonicalizeDidUrl,
5242
5365
  canonicalizeEncryptionJson,
5366
+ canonicalizeNetworkId,
5243
5367
  canonicalizeSecretScope,
5244
5368
  checkDecryptInvocationInput,
5245
5369
  checkNodeInfo,
@@ -5253,6 +5377,8 @@ export {
5253
5377
  defaultSignStrategy,
5254
5378
  defaultSpaceCreationHandler,
5255
5379
  deriveSignedReceiverKey,
5380
+ didCacheKey,
5381
+ didEquals,
5256
5382
  discoverNetwork,
5257
5383
  encryptToNetwork,
5258
5384
  base64Decode as encryptionBase64Decode,
@@ -5272,9 +5398,11 @@ export {
5272
5398
  hexEncode,
5273
5399
  httpUrlToMultiaddr,
5274
5400
  isCapabilitySubset,
5401
+ isEvmAddress,
5275
5402
  isNetworkId,
5276
5403
  loadManifest,
5277
5404
  locationPayloadForRecord,
5405
+ makePkhSpaceId,
5278
5406
  makePublicSpaceId,
5279
5407
  manifestAbilitiesUnion,
5280
5408
  multiaddrToHttpUrl,
@@ -5282,10 +5410,15 @@ export {
5282
5410
  normalizeDefaults,
5283
5411
  ok4 as ok,
5284
5412
  openWrappedKey,
5413
+ parseCanonicalNetworkId,
5285
5414
  parseExpiry,
5286
- parseNetworkId,
5415
+ parseNetworkId2 as parseNetworkId,
5416
+ parsePkhDid,
5287
5417
  parseRecapCapabilities,
5288
5418
  parseSpaceUri,
5419
+ pkhDid,
5420
+ principalDid,
5421
+ principalDidEquals,
5289
5422
  resolveCloudLocation,
5290
5423
  resolveManifest,
5291
5424
  resolveSecretListPrefix,