@tinycloud/sdk-core 2.2.0-beta.3 → 2.2.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
@@ -4454,6 +4454,8 @@ interface LocationRecord extends LocationRecordPayload {
4454
4454
  signature: string;
4455
4455
  }
4456
4456
  type LocationSource = "explicit" | "blockchain" | "centralized" | "fallback";
4457
+ declare const DEFAULT_TINYCLOUD_LOCATION_REGISTRY_URL = "https://registry.tinycloud.xyz";
4458
+ declare const DEFAULT_TINYCLOUD_FALLBACK_HOST = "https://node.tinycloud.xyz";
4457
4459
  interface LocationCandidate {
4458
4460
  source: LocationSource;
4459
4461
  multiaddrs: string[];
@@ -4486,6 +4488,24 @@ interface ResolveCloudLocationOptions {
4486
4488
  /** Verify centralized/blockchain record signatures. Default true. */
4487
4489
  verifyRecords?: boolean;
4488
4490
  }
4491
+ interface ResolvedTinyCloudHosts {
4492
+ hosts: string[];
4493
+ location: ResolvedCloudLocation;
4494
+ }
4495
+ interface ResolveTinyCloudHostsOptions {
4496
+ /** Highest-priority TinyCloud HTTP host URLs or multiaddrs supplied directly. */
4497
+ explicitHosts?: string[];
4498
+ /** Optional blockchain resolver adapter. */
4499
+ blockchain?: ResolveCloudLocationOptions["blockchain"];
4500
+ /** Centralized location registry URL. Default https://registry.tinycloud.xyz. */
4501
+ registryUrl?: string | null;
4502
+ /** Lowest-priority fallback HTTP host URLs or multiaddrs. Default hosted TinyCloud node. */
4503
+ fallbackHosts?: string[] | null;
4504
+ /** Custom fetch implementation. Defaults to globalThis.fetch. */
4505
+ fetch?: typeof fetch;
4506
+ /** Verify centralized/blockchain record signatures. Default true. */
4507
+ verifyRecords?: boolean;
4508
+ }
4489
4509
  type LocationCandidateInput = string[] | LocationRecord | {
4490
4510
  multiaddrs: string[];
4491
4511
  record?: LocationRecord;
@@ -4512,7 +4532,8 @@ declare function validateLocationRecord(input: unknown): LocationRecord;
4512
4532
  declare function verifyLocationRecord(input: LocationRecord): Promise<boolean>;
4513
4533
  declare function fetchLocationRecord(registryUrl: string, subject: string, fetchFn?: typeof fetch): Promise<LocationRecord | null>;
4514
4534
  declare function resolveCloudLocation(subject: string, options?: ResolveCloudLocationOptions): Promise<ResolvedCloudLocation>;
4535
+ declare function resolveTinyCloudHosts(subject: string, options?: ResolveTinyCloudHostsOptions): Promise<ResolvedTinyCloudHosts>;
4515
4536
  declare function multiaddrToHttpUrl(input: string): string;
4516
4537
  declare function httpUrlToMultiaddr(input: string): string;
4517
4538
 
4518
- 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, 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 EncodedShareData, type EnsData, EnsDataSchema, type EventEmitterStrategy, 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, ManifestValidationError, type NodeInfo, type ParseRecapFromSiwe, type PartialSiweMessage, type PermissionEntry, PermissionNotInManifestError, type PersistedSessionData, type PersistedTinyCloudSession, ProtocolMismatchError, type ReceiveOptions, type ResolveCloudLocationOptions, type ResolvedCapabilities, type ResolvedCloudLocation, type ResolvedDelegate, 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, type ValidationError, VersionCheckError, type WasmRecapEntry, activateSessionWithHost, applyPrefix, buildSpaceUri, canonicalLocationPayload, checkNodeInfo, composeManifestRequest, createCapabilityKeyRegistry, createSharingService, createSpaceService, defaultSignStrategy, defaultSpaceCreationHandler, expandActionShortNames, fetchLocationRecord, fetchPeerId, httpUrlToMultiaddr, isCapabilitySubset, loadManifest, locationPayloadForRecord, makePublicSpaceId, manifestAbilitiesUnion, multiaddrToHttpUrl, normalizeDefaults, parseExpiry, parseRecapCapabilities, parseSpaceUri, resolveCloudLocation, resolveManifest, resourceCapabilitiesToAbilitiesMap, resourceCapabilitiesToSpaceAbilitiesMap, signLocationRecord, submitHostDelegation, validateClientSession, validateLocationRecord, validateLocationRecordPayload, validateManifest, validatePersistedSessionData, verifyLocationRecord };
4539
+ 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_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 EncodedShareData, type EnsData, EnsDataSchema, type EventEmitterStrategy, 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, 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, type ValidationError, VersionCheckError, type WasmRecapEntry, activateSessionWithHost, applyPrefix, buildSpaceUri, canonicalLocationPayload, checkNodeInfo, composeManifestRequest, createCapabilityKeyRegistry, createSharingService, createSpaceService, defaultSignStrategy, defaultSpaceCreationHandler, expandActionShortNames, 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, verifyLocationRecord };
package/dist/index.d.ts CHANGED
@@ -4454,6 +4454,8 @@ interface LocationRecord extends LocationRecordPayload {
4454
4454
  signature: string;
4455
4455
  }
4456
4456
  type LocationSource = "explicit" | "blockchain" | "centralized" | "fallback";
4457
+ declare const DEFAULT_TINYCLOUD_LOCATION_REGISTRY_URL = "https://registry.tinycloud.xyz";
4458
+ declare const DEFAULT_TINYCLOUD_FALLBACK_HOST = "https://node.tinycloud.xyz";
4457
4459
  interface LocationCandidate {
4458
4460
  source: LocationSource;
4459
4461
  multiaddrs: string[];
@@ -4486,6 +4488,24 @@ interface ResolveCloudLocationOptions {
4486
4488
  /** Verify centralized/blockchain record signatures. Default true. */
4487
4489
  verifyRecords?: boolean;
4488
4490
  }
4491
+ interface ResolvedTinyCloudHosts {
4492
+ hosts: string[];
4493
+ location: ResolvedCloudLocation;
4494
+ }
4495
+ interface ResolveTinyCloudHostsOptions {
4496
+ /** Highest-priority TinyCloud HTTP host URLs or multiaddrs supplied directly. */
4497
+ explicitHosts?: string[];
4498
+ /** Optional blockchain resolver adapter. */
4499
+ blockchain?: ResolveCloudLocationOptions["blockchain"];
4500
+ /** Centralized location registry URL. Default https://registry.tinycloud.xyz. */
4501
+ registryUrl?: string | null;
4502
+ /** Lowest-priority fallback HTTP host URLs or multiaddrs. Default hosted TinyCloud node. */
4503
+ fallbackHosts?: string[] | null;
4504
+ /** Custom fetch implementation. Defaults to globalThis.fetch. */
4505
+ fetch?: typeof fetch;
4506
+ /** Verify centralized/blockchain record signatures. Default true. */
4507
+ verifyRecords?: boolean;
4508
+ }
4489
4509
  type LocationCandidateInput = string[] | LocationRecord | {
4490
4510
  multiaddrs: string[];
4491
4511
  record?: LocationRecord;
@@ -4512,7 +4532,8 @@ declare function validateLocationRecord(input: unknown): LocationRecord;
4512
4532
  declare function verifyLocationRecord(input: LocationRecord): Promise<boolean>;
4513
4533
  declare function fetchLocationRecord(registryUrl: string, subject: string, fetchFn?: typeof fetch): Promise<LocationRecord | null>;
4514
4534
  declare function resolveCloudLocation(subject: string, options?: ResolveCloudLocationOptions): Promise<ResolvedCloudLocation>;
4535
+ declare function resolveTinyCloudHosts(subject: string, options?: ResolveTinyCloudHostsOptions): Promise<ResolvedTinyCloudHosts>;
4515
4536
  declare function multiaddrToHttpUrl(input: string): string;
4516
4537
  declare function httpUrlToMultiaddr(input: string): string;
4517
4538
 
4518
- 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, 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 EncodedShareData, type EnsData, EnsDataSchema, type EventEmitterStrategy, 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, ManifestValidationError, type NodeInfo, type ParseRecapFromSiwe, type PartialSiweMessage, type PermissionEntry, PermissionNotInManifestError, type PersistedSessionData, type PersistedTinyCloudSession, ProtocolMismatchError, type ReceiveOptions, type ResolveCloudLocationOptions, type ResolvedCapabilities, type ResolvedCloudLocation, type ResolvedDelegate, 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, type ValidationError, VersionCheckError, type WasmRecapEntry, activateSessionWithHost, applyPrefix, buildSpaceUri, canonicalLocationPayload, checkNodeInfo, composeManifestRequest, createCapabilityKeyRegistry, createSharingService, createSpaceService, defaultSignStrategy, defaultSpaceCreationHandler, expandActionShortNames, fetchLocationRecord, fetchPeerId, httpUrlToMultiaddr, isCapabilitySubset, loadManifest, locationPayloadForRecord, makePublicSpaceId, manifestAbilitiesUnion, multiaddrToHttpUrl, normalizeDefaults, parseExpiry, parseRecapCapabilities, parseSpaceUri, resolveCloudLocation, resolveManifest, resourceCapabilitiesToAbilitiesMap, resourceCapabilitiesToSpaceAbilitiesMap, signLocationRecord, submitHostDelegation, validateClientSession, validateLocationRecord, validateLocationRecordPayload, validateManifest, validatePersistedSessionData, verifyLocationRecord };
4539
+ 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_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 EncodedShareData, type EnsData, EnsDataSchema, type EventEmitterStrategy, 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, 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, type ValidationError, VersionCheckError, type WasmRecapEntry, activateSessionWithHost, applyPrefix, buildSpaceUri, canonicalLocationPayload, checkNodeInfo, composeManifestRequest, createCapabilityKeyRegistry, createSharingService, createSpaceService, defaultSignStrategy, defaultSpaceCreationHandler, expandActionShortNames, 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, verifyLocationRecord };
package/dist/index.js CHANGED
@@ -4257,6 +4257,8 @@ import { uriToMultiaddr } from "@multiformats/uri-to-multiaddr";
4257
4257
  import { ed25519 } from "@noble/curves/ed25519";
4258
4258
  import { bases } from "multiformats/basics";
4259
4259
  import { verifyMessage } from "viem";
4260
+ var DEFAULT_TINYCLOUD_LOCATION_REGISTRY_URL = "https://registry.tinycloud.xyz";
4261
+ var DEFAULT_TINYCLOUD_FALLBACK_HOST = "https://node.tinycloud.xyz";
4260
4262
  var LocationRecordValidationError = class extends Error {
4261
4263
  constructor(message) {
4262
4264
  super(`Location record validation failed: ${message}`);
@@ -4291,7 +4293,9 @@ function canonicalLocationPayload(payload) {
4291
4293
  async function signLocationRecord(payload, signer) {
4292
4294
  validateLocationRecordPayload(payload);
4293
4295
  const message = canonicalLocationPayload(payload);
4294
- const signature = signer.type === "did:pkh" ? await signer.signMessage(message) : base64UrlEncode2(await signer.signBytes(new TextEncoder().encode(message)));
4296
+ const signature = signer.type === "did:pkh" ? await signer.signMessage(message) : base64UrlEncode2(
4297
+ await signer.signBytes(new TextEncoder().encode(message))
4298
+ );
4295
4299
  return { ...payload, signature };
4296
4300
  }
4297
4301
  function validateLocationRecordPayload(input) {
@@ -4305,7 +4309,9 @@ function validateLocationRecordPayload(input) {
4305
4309
  validateSubject(payload.subject);
4306
4310
  validateMultiaddrs(payload.multiaddrs);
4307
4311
  if (typeof payload.updated_at !== "string" || Number.isNaN(Date.parse(payload.updated_at))) {
4308
- throw new LocationRecordValidationError("updated_at must be an ISO timestamp");
4312
+ throw new LocationRecordValidationError(
4313
+ "updated_at must be an ISO timestamp"
4314
+ );
4309
4315
  }
4310
4316
  if (typeof payload.sequence !== "number" || !Number.isSafeInteger(payload.sequence) || payload.sequence < 0) {
4311
4317
  throw new LocationRecordValidationError(
@@ -4324,7 +4330,9 @@ function validateLocationRecord(input) {
4324
4330
  const payload = validateLocationRecordPayload(input);
4325
4331
  const signature = input.signature;
4326
4332
  if (typeof signature !== "string" || signature.length === 0) {
4327
- throw new LocationRecordValidationError("signature must be a non-empty string");
4333
+ throw new LocationRecordValidationError(
4334
+ "signature must be a non-empty string"
4335
+ );
4328
4336
  }
4329
4337
  return { ...payload, signature };
4330
4338
  }
@@ -4376,6 +4384,22 @@ async function resolveCloudLocation(subject, options = {}) {
4376
4384
  resolvedAt: (/* @__PURE__ */ new Date()).toISOString()
4377
4385
  };
4378
4386
  }
4387
+ async function resolveTinyCloudHosts(subject, options = {}) {
4388
+ const location = await resolveCloudLocation(subject, {
4389
+ explicitMultiaddrs: hostsToMultiaddrs(options.explicitHosts),
4390
+ blockchain: options.blockchain,
4391
+ centralizedRegistryUrl: options.registryUrl === null ? void 0 : options.registryUrl ?? DEFAULT_TINYCLOUD_LOCATION_REGISTRY_URL,
4392
+ fallbackMultiaddrs: hostsToMultiaddrs(
4393
+ options.fallbackHosts === null ? void 0 : options.fallbackHosts ?? [DEFAULT_TINYCLOUD_FALLBACK_HOST]
4394
+ ),
4395
+ fetch: options.fetch,
4396
+ verifyRecords: options.verifyRecords
4397
+ });
4398
+ return {
4399
+ hosts: location.multiaddrs.map((addr) => multiaddrToHttpUrl(addr)),
4400
+ location
4401
+ };
4402
+ }
4379
4403
  function multiaddrToHttpUrl(input) {
4380
4404
  const uri = multiaddrToUri(multiaddr(input));
4381
4405
  if (!uri.startsWith("http://") && !uri.startsWith("https://")) {
@@ -4392,6 +4416,14 @@ function httpUrlToMultiaddr(input) {
4392
4416
  }
4393
4417
  return uriToMultiaddr(url.toString()).toString();
4394
4418
  }
4419
+ function hostsToMultiaddrs(hosts) {
4420
+ if (hosts === void 0 || hosts.length === 0) {
4421
+ return void 0;
4422
+ }
4423
+ return hosts.map(
4424
+ (host) => host.startsWith("/") ? host : httpUrlToMultiaddr(host)
4425
+ );
4426
+ }
4395
4427
  async function resolveExplicit(subject, multiaddrs) {
4396
4428
  return resolveAttempt("explicit", async () => {
4397
4429
  if (multiaddrs === void 0 || multiaddrs.length === 0) {
@@ -4405,7 +4437,12 @@ async function resolveBlockchain(subject, resolver, verifyRecords) {
4405
4437
  if (!resolver) {
4406
4438
  return null;
4407
4439
  }
4408
- return toCandidate(subject, "blockchain", await resolver(subject), verifyRecords);
4440
+ return toCandidate(
4441
+ subject,
4442
+ "blockchain",
4443
+ await resolver(subject),
4444
+ verifyRecords
4445
+ );
4409
4446
  });
4410
4447
  }
4411
4448
  async function resolveCentralized(subject, options, verifyRecords) {
@@ -4457,13 +4494,17 @@ async function toCandidate(subject, source, input, verifyRecord) {
4457
4494
  );
4458
4495
  }
4459
4496
  if (verifyRecord && !await verifyLocationRecord(record)) {
4460
- throw new LocationRecordValidationError("location record signature is invalid");
4497
+ throw new LocationRecordValidationError(
4498
+ "location record signature is invalid"
4499
+ );
4461
4500
  }
4462
4501
  return { source, multiaddrs: [...record.multiaddrs], record };
4463
4502
  }
4464
4503
  const candidateInput = input;
4465
4504
  if (!Array.isArray(candidateInput.multiaddrs)) {
4466
- throw new LocationRecordValidationError("candidate multiaddrs must be an array");
4505
+ throw new LocationRecordValidationError(
4506
+ "candidate multiaddrs must be an array"
4507
+ );
4467
4508
  }
4468
4509
  validateMultiaddrs(candidateInput.multiaddrs);
4469
4510
  if (candidateInput.record !== void 0) {
@@ -4474,7 +4515,9 @@ async function toCandidate(subject, source, input, verifyRecord) {
4474
4515
  );
4475
4516
  }
4476
4517
  if (verifyRecord && !await verifyLocationRecord(record)) {
4477
- throw new LocationRecordValidationError("location record signature is invalid");
4518
+ throw new LocationRecordValidationError(
4519
+ "location record signature is invalid"
4520
+ );
4478
4521
  }
4479
4522
  return { source, multiaddrs: [...candidateInput.multiaddrs], record };
4480
4523
  }
@@ -4482,10 +4525,14 @@ async function toCandidate(subject, source, input, verifyRecord) {
4482
4525
  }
4483
4526
  function validateSubject(subject) {
4484
4527
  if (typeof subject !== "string" || subject.length === 0) {
4485
- throw new LocationRecordValidationError("subject must be a non-empty string");
4528
+ throw new LocationRecordValidationError(
4529
+ "subject must be a non-empty string"
4530
+ );
4486
4531
  }
4487
4532
  if (!subject.startsWith("did:pkh:") && !subject.startsWith("did:key:")) {
4488
- throw new LocationRecordValidationError("subject must be did:pkh or did:key");
4533
+ throw new LocationRecordValidationError(
4534
+ "subject must be did:pkh or did:key"
4535
+ );
4489
4536
  }
4490
4537
  }
4491
4538
  function validateMultiaddrs(input) {
@@ -4529,16 +4576,24 @@ function verifyDidKeySignature(did, payload, signature) {
4529
4576
  "did:key signature must be a base64url Ed25519 signature"
4530
4577
  );
4531
4578
  }
4532
- return ed25519.verify(signatureBytes, new TextEncoder().encode(payload), publicKey);
4579
+ return ed25519.verify(
4580
+ signatureBytes,
4581
+ new TextEncoder().encode(payload),
4582
+ publicKey
4583
+ );
4533
4584
  }
4534
4585
  function ed25519PublicKeyFromDidKey(did) {
4535
4586
  const identifier = did.slice("did:key:".length);
4536
4587
  if (!identifier.startsWith("z")) {
4537
- throw new LocationRecordValidationError("did:key must use base58btc multibase");
4588
+ throw new LocationRecordValidationError(
4589
+ "did:key must use base58btc multibase"
4590
+ );
4538
4591
  }
4539
4592
  const bytes = bases.base58btc.decode(identifier);
4540
4593
  if (bytes.length !== 34 || bytes[0] !== 237 || bytes[1] !== 1) {
4541
- throw new LocationRecordValidationError("did:key must be an Ed25519 public key");
4594
+ throw new LocationRecordValidationError(
4595
+ "did:key must be an Ed25519 public key"
4596
+ );
4542
4597
  }
4543
4598
  return bytes.slice(2);
4544
4599
  }
@@ -4708,6 +4763,8 @@ export {
4708
4763
  DEFAULT_EXPIRY,
4709
4764
  DEFAULT_MANIFEST_SPACE,
4710
4765
  DEFAULT_MANIFEST_VERSION,
4766
+ DEFAULT_TINYCLOUD_FALLBACK_HOST,
4767
+ DEFAULT_TINYCLOUD_LOCATION_REGISTRY_URL,
4711
4768
  DataVaultService,
4712
4769
  DatabaseHandle,
4713
4770
  DelegationErrorCodes,
@@ -4773,6 +4830,7 @@ export {
4773
4830
  parseSpaceUri,
4774
4831
  resolveCloudLocation,
4775
4832
  resolveManifest,
4833
+ resolveTinyCloudHosts,
4776
4834
  resourceCapabilitiesToAbilitiesMap,
4777
4835
  resourceCapabilitiesToSpaceAbilitiesMap,
4778
4836
  serviceError4 as serviceError,