@tinycloud/node-sdk 2.2.0-beta.2 → 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/core.d.cts CHANGED
@@ -1,4 +1,4 @@
1
1
  export { ACCOUNT_REGISTRY_PATH, ACCOUNT_REGISTRY_SPACE, AutoApproveSpaceCreationHandler, AutoRejectStrategy, AutoSignStrategy, BatchOptions, BatchResponse, CallbackStrategy, CapabilityEntry, CapabilityKeyRegistry, CapabilityKeyRegistryErrorCode, CapabilityKeyRegistryErrorCodes, ClientSession, ColumnInfo, ComposeManifestOptions, ComposedManifestRequest, CreateDelegationParams, DEFAULT_MANIFEST_SPACE, DEFAULT_MANIFEST_VERSION, DataVaultConfig, DataVaultService, DatabaseHandle, Delegation, DelegationChain, DelegationChainV2, DelegationDirection, DelegationError, DelegationErrorCode, DelegationErrorCodes, DelegationFilters, DelegationManager, DelegationManagerConfig, DelegationRecord, DelegationResult, DuckDbAction, DuckDbActionType, DuckDbBatchOptions, DuckDbBatchResponse, DuckDbDatabaseHandle, DuckDbExecuteOptions, DuckDbExecuteResponse, DuckDbOptions, DuckDbQueryOptions, DuckDbQueryResponse, DuckDbService, DuckDbServiceConfig, DuckDbStatement, DuckDbValue, EncodedShareData, ExecuteOptions, ExecuteResponse, Extension, FetchFunction, GenerateShareParams, ICapabilityKeyRegistry, IDataVaultService, IDatabaseHandle, IDuckDbDatabaseHandle, IDuckDbService, IENSResolver, IKVService, INotificationHandler, IPrefixedKVService, ISQLService, ISessionManager, ISessionStorage, ISharingService, ISigner, ISpace, ISpaceCreationHandler, ISpaceScopedDelegations, ISpaceScopedSharing, ISpaceService, IUserAuthorization, IWasmBindings, IngestOptions, InvokeFunction, JWK, KVResponse, KVService, KVServiceConfig, KeyInfo, KeyProvider, KeyType, Manifest, ManifestDefaults, ManifestRegistryRecord, ManifestValidationError, PermissionEntry, PermissionNotInManifestError, PersistedSessionData, PrefixedKVService, ProtocolMismatchError, QueryOptions, QueryResponse, ReceiveOptions, ResolvedCapabilities, ResolvedDelegate, ResourceCapability, SQLAction, SQLActionType, SQLService, SQLServiceConfig, SchemaInfo, ServiceContext, ServiceContextConfig, ServiceSession, SessionExpiredError, ShareAccess, ShareLink, ShareLinkData, ShareSchema, SharingService, SharingServiceConfig, SignCallback, SignInOptions, SignRequest, SignResponse, SilentNotificationHandler, Space, SpaceAbilitiesMap, SpaceConfig, SpaceCreationContext, SpaceErrorCode, SpaceErrorCodes, SpaceInfo, SpaceOwnership, SpaceService, SpaceServiceConfig, SqlStatement, SqlValue, StoredDelegationChain, TableInfo, TinyCloud, TinyCloudConfig, TinyCloudSession, UnsupportedFeatureError, VaultCrypto, VaultEntry, VaultError, VaultGetOptions, VaultGrantOptions, VaultHeaders, VaultListOptions, VaultPublicSpaceKVActions, VaultPutOptions, VersionCheckError, ViewInfo, WasmVaultFunctions, buildSpaceUri, checkNodeInfo, composeManifestRequest, createCapabilityKeyRegistry, createSharingService, createSpaceService, createVaultCrypto, defaultSpaceCreationHandler, expandActionShortNames, isCapabilitySubset, loadManifest, makePublicSpaceId, parseExpiry, parseSpaceUri, resolveManifest, resourceCapabilitiesToSpaceAbilitiesMap, validateManifest } from '@tinycloud/sdk-core';
2
- export { D as DelegateToOptions, a as DelegateToResult, b as DelegatedAccess, F as FileSessionStorage, M as MemorySessionStorage, N as NodeEventEmitterStrategy, c as NodeUserAuthorization, d as NodeUserAuthorizationConfig, P as PortableDelegation, S as SignStrategy, T as TinyCloudNode, e as TinyCloudNodeConfig, W as WasmKeyProvider, f as WasmKeyProviderConfig, g as createWasmKeyProvider, h as defaultSignStrategy, i as deserializeDelegation, s as serializeDelegation } from './core-NsTndW58.cjs';
2
+ export { D as DelegateToOptions, a as DelegateToResult, b as DelegatedAccess, F as FileSessionStorage, M as MemorySessionStorage, N as NodeEventEmitterStrategy, c as NodeUserAuthorization, d as NodeUserAuthorizationConfig, P as PortableDelegation, S as SignStrategy, T as TinyCloudNode, e as TinyCloudNodeConfig, W as WasmKeyProvider, f as WasmKeyProviderConfig, g as createWasmKeyProvider, h as defaultSignStrategy, i as deserializeDelegation, s as serializeDelegation } from './core-BC3y7xTF.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, AutoApproveSpaceCreationHandler, AutoRejectStrategy, AutoSignStrategy, BatchOptions, BatchResponse, CallbackStrategy, CapabilityEntry, CapabilityKeyRegistry, CapabilityKeyRegistryErrorCode, CapabilityKeyRegistryErrorCodes, ClientSession, ColumnInfo, ComposeManifestOptions, ComposedManifestRequest, CreateDelegationParams, DEFAULT_MANIFEST_SPACE, DEFAULT_MANIFEST_VERSION, DataVaultConfig, DataVaultService, DatabaseHandle, Delegation, DelegationChain, DelegationChainV2, DelegationDirection, DelegationError, DelegationErrorCode, DelegationErrorCodes, DelegationFilters, DelegationManager, DelegationManagerConfig, DelegationRecord, DelegationResult, DuckDbAction, DuckDbActionType, DuckDbBatchOptions, DuckDbBatchResponse, DuckDbDatabaseHandle, DuckDbExecuteOptions, DuckDbExecuteResponse, DuckDbOptions, DuckDbQueryOptions, DuckDbQueryResponse, DuckDbService, DuckDbServiceConfig, DuckDbStatement, DuckDbValue, EncodedShareData, ExecuteOptions, ExecuteResponse, Extension, FetchFunction, GenerateShareParams, ICapabilityKeyRegistry, IDataVaultService, IDatabaseHandle, IDuckDbDatabaseHandle, IDuckDbService, IENSResolver, IKVService, INotificationHandler, IPrefixedKVService, ISQLService, ISessionManager, ISessionStorage, ISharingService, ISigner, ISpace, ISpaceCreationHandler, ISpaceScopedDelegations, ISpaceScopedSharing, ISpaceService, IUserAuthorization, IWasmBindings, IngestOptions, InvokeFunction, JWK, KVResponse, KVService, KVServiceConfig, KeyInfo, KeyProvider, KeyType, Manifest, ManifestDefaults, ManifestRegistryRecord, ManifestValidationError, PermissionEntry, PermissionNotInManifestError, PersistedSessionData, PrefixedKVService, ProtocolMismatchError, QueryOptions, QueryResponse, ReceiveOptions, ResolvedCapabilities, ResolvedDelegate, ResourceCapability, SQLAction, SQLActionType, SQLService, SQLServiceConfig, SchemaInfo, ServiceContext, ServiceContextConfig, ServiceSession, SessionExpiredError, ShareAccess, ShareLink, ShareLinkData, ShareSchema, SharingService, SharingServiceConfig, SignCallback, SignInOptions, SignRequest, SignResponse, SilentNotificationHandler, Space, SpaceAbilitiesMap, SpaceConfig, SpaceCreationContext, SpaceErrorCode, SpaceErrorCodes, SpaceInfo, SpaceOwnership, SpaceService, SpaceServiceConfig, SqlStatement, SqlValue, StoredDelegationChain, TableInfo, TinyCloud, TinyCloudConfig, TinyCloudSession, UnsupportedFeatureError, VaultCrypto, VaultEntry, VaultError, VaultGetOptions, VaultGrantOptions, VaultHeaders, VaultListOptions, VaultPublicSpaceKVActions, VaultPutOptions, VersionCheckError, ViewInfo, WasmVaultFunctions, buildSpaceUri, checkNodeInfo, composeManifestRequest, createCapabilityKeyRegistry, createSharingService, createSpaceService, createVaultCrypto, defaultSpaceCreationHandler, expandActionShortNames, isCapabilitySubset, loadManifest, makePublicSpaceId, parseExpiry, parseSpaceUri, resolveManifest, resourceCapabilitiesToSpaceAbilitiesMap, validateManifest } from '@tinycloud/sdk-core';
2
- export { D as DelegateToOptions, a as DelegateToResult, b as DelegatedAccess, F as FileSessionStorage, M as MemorySessionStorage, N as NodeEventEmitterStrategy, c as NodeUserAuthorization, d as NodeUserAuthorizationConfig, P as PortableDelegation, S as SignStrategy, T as TinyCloudNode, e as TinyCloudNodeConfig, W as WasmKeyProvider, f as WasmKeyProviderConfig, g as createWasmKeyProvider, h as defaultSignStrategy, i as deserializeDelegation, s as serializeDelegation } from './core-NsTndW58.js';
2
+ export { D as DelegateToOptions, a as DelegateToResult, b as DelegatedAccess, F as FileSessionStorage, M as MemorySessionStorage, N as NodeEventEmitterStrategy, c as NodeUserAuthorization, d as NodeUserAuthorizationConfig, P as PortableDelegation, S as SignStrategy, T as TinyCloudNode, e as TinyCloudNodeConfig, W as WasmKeyProvider, f as WasmKeyProviderConfig, g as createWasmKeyProvider, h as defaultSignStrategy, i as deserializeDelegation, s as serializeDelegation } from './core-BC3y7xTF.js';
3
3
  import 'events';
4
4
  import '@tinycloud/sdk-services';
package/dist/core.js CHANGED
@@ -207,7 +207,8 @@ import {
207
207
  DEFAULT_MANIFEST_SPACE,
208
208
  composeManifestRequest,
209
209
  resourceCapabilitiesToAbilitiesMap,
210
- resourceCapabilitiesToSpaceAbilitiesMap
210
+ resourceCapabilitiesToSpaceAbilitiesMap,
211
+ resolveTinyCloudHosts
211
212
  } from "@tinycloud/sdk-core";
212
213
 
213
214
  // src/authorization/strategies.ts
@@ -270,9 +271,9 @@ var NodeUserAuthorization = class {
270
271
  this.sessionExpirationMs = config.sessionExpirationMs ?? 60 * 60 * 1e3;
271
272
  this.autoCreateSpace = config.autoCreateSpace ?? false;
272
273
  this.spaceCreationHandler = config.spaceCreationHandler;
273
- this.tinycloudHosts = config.tinycloudHosts ?? [
274
- "https://node.tinycloud.xyz"
275
- ];
274
+ this.tinycloudHosts = config.tinycloudHosts;
275
+ this.tinycloudRegistryUrl = config.tinycloudRegistryUrl;
276
+ this.tinycloudFallbackHosts = config.tinycloudFallbackHosts;
276
277
  this.enablePublicSpace = config.enablePublicSpace ?? true;
277
278
  this.nonce = config.nonce;
278
279
  this.siweConfig = config.siweConfig;
@@ -293,6 +294,9 @@ var NodeUserAuthorization = class {
293
294
  get capabilityRequest() {
294
295
  return this.getCapabilityRequest();
295
296
  }
297
+ get hosts() {
298
+ return this.tinycloudHosts ? [...this.tinycloudHosts] : [];
299
+ }
296
300
  /**
297
301
  * Install or replace the stored manifest. Takes effect on the next
298
302
  * `signIn()` call — the current session (if any) is not touched.
@@ -317,6 +321,26 @@ var NodeUserAuthorization = class {
317
321
  get tinyCloudSession() {
318
322
  return this._tinyCloudSession;
319
323
  }
324
+ async resolveTinyCloudHostsForSignIn(address, chainId) {
325
+ if (this.tinycloudHosts && this.tinycloudHosts.length > 0) {
326
+ return;
327
+ }
328
+ const subject = `did:pkh:eip155:${chainId}:${address}`;
329
+ const resolved = await resolveTinyCloudHosts(subject, {
330
+ registryUrl: this.tinycloudRegistryUrl,
331
+ fallbackHosts: this.tinycloudFallbackHosts
332
+ });
333
+ this.tinycloudHosts = resolved.hosts;
334
+ }
335
+ requireTinyCloudHosts() {
336
+ if (!this.tinycloudHosts || this.tinycloudHosts.length === 0) {
337
+ throw new Error("TinyCloud hosts have not been resolved. Call signIn() first.");
338
+ }
339
+ return this.tinycloudHosts;
340
+ }
341
+ get primaryTinyCloudHost() {
342
+ return this.requireTinyCloudHosts()[0];
343
+ }
320
344
  get nodeFeatures() {
321
345
  return this._nodeFeatures;
322
346
  }
@@ -448,7 +472,7 @@ var NodeUserAuthorization = class {
448
472
  if (!this._tinyCloudSession || !this._address || !this._chainId) {
449
473
  throw new Error("Must be signed in to host space");
450
474
  }
451
- const host = this.tinycloudHosts[0];
475
+ const host = this.primaryTinyCloudHost;
452
476
  const spaceId = targetSpaceId ?? this._tinyCloudSession.spaceId;
453
477
  const peerId = await fetchPeerId(host, spaceId);
454
478
  const siwe = this.wasm.generateHostSIWEMessage({
@@ -490,7 +514,7 @@ var NodeUserAuthorization = class {
490
514
  if (!this._tinyCloudSession) {
491
515
  throw new Error("Must be signed in to ensure space exists");
492
516
  }
493
- const host = this.tinycloudHosts[0];
517
+ const host = this.primaryTinyCloudHost;
494
518
  const primarySpaceId = this._tinyCloudSession.spaceId;
495
519
  const result = await activateSessionWithHost(
496
520
  host,
@@ -599,6 +623,7 @@ var NodeUserAuthorization = class {
599
623
  this._chainId = await this.signer.getChainId();
600
624
  const address = this.wasm.ensureEip55(this._address);
601
625
  const chainId = this._chainId;
626
+ await this.resolveTinyCloudHostsForSignIn(address, chainId);
602
627
  const keyId = `session-${Date.now()}`;
603
628
  this.sessionManager.renameSessionKeyId("default", keyId);
604
629
  const jwkString = this.sessionManager.jwk(keyId);
@@ -677,7 +702,7 @@ var NodeUserAuthorization = class {
677
702
  this._address = address;
678
703
  this._chainId = chainId;
679
704
  const nodeInfo = await checkNodeInfo(
680
- this.tinycloudHosts[0],
705
+ this.primaryTinyCloudHost,
681
706
  this.wasm.protocolVersion()
682
707
  );
683
708
  this._nodeFeatures = nodeInfo.features;
@@ -793,6 +818,7 @@ var NodeUserAuthorization = class {
793
818
  });
794
819
  const address = this.wasm.ensureEip55(await this.signer.getAddress());
795
820
  const chainId = await this.signer.getChainId();
821
+ await this.resolveTinyCloudHostsForSignIn(address, chainId);
796
822
  const clientSession = {
797
823
  address,
798
824
  walletAddress: address,
@@ -842,7 +868,7 @@ var NodeUserAuthorization = class {
842
868
  this._address = address;
843
869
  this._chainId = chainId;
844
870
  const nodeInfo = await checkNodeInfo(
845
- this.tinycloudHosts[0],
871
+ this.primaryTinyCloudHost,
846
872
  this.wasm.protocolVersion()
847
873
  );
848
874
  this._nodeFeatures = nodeInfo.features;
@@ -1222,6 +1248,7 @@ var _TinyCloudNode = class _TinyCloudNode {
1222
1248
  this.auth = null;
1223
1249
  this.tc = null;
1224
1250
  this._chainId = 1;
1251
+ this.explicitHost = config.host;
1225
1252
  this.config = {
1226
1253
  ...config,
1227
1254
  host: config.host ?? DEFAULT_HOST
@@ -1303,7 +1330,6 @@ var _TinyCloudNode = class _TinyCloudNode {
1303
1330
  * @internal
1304
1331
  */
1305
1332
  setupAuth(config) {
1306
- const host = this.config.host;
1307
1333
  this.auth = new NodeUserAuthorization({
1308
1334
  signer: this.signer,
1309
1335
  signStrategy: { type: "auto-sign" },
@@ -1312,7 +1338,9 @@ var _TinyCloudNode = class _TinyCloudNode {
1312
1338
  domain: this.siweDomain,
1313
1339
  spacePrefix: config.prefix,
1314
1340
  sessionExpirationMs: config.sessionExpirationMs ?? 60 * 60 * 1e3,
1315
- tinycloudHosts: [host],
1341
+ tinycloudHosts: this.explicitHost ? [this.explicitHost] : void 0,
1342
+ tinycloudRegistryUrl: config.tinycloudRegistryUrl,
1343
+ tinycloudFallbackHosts: config.tinycloudFallbackHosts,
1316
1344
  autoCreateSpace: config.autoCreateSpace,
1317
1345
  enablePublicSpace: config.enablePublicSpace ?? true,
1318
1346
  spaceCreationHandler: config.spaceCreationHandler,
@@ -1326,6 +1354,12 @@ var _TinyCloudNode = class _TinyCloudNode {
1326
1354
  invokeAny: this.wasmBindings.invokeAny
1327
1355
  });
1328
1356
  }
1357
+ syncResolvedHostFromAuth() {
1358
+ const host = this.auth?.hosts[0];
1359
+ if (host) {
1360
+ this.config.host = host;
1361
+ }
1362
+ }
1329
1363
  /**
1330
1364
  * Install or replace the manifest that drives the SIWE recap at
1331
1365
  * sign-in. Takes effect on the next `signIn()` call — the current
@@ -1363,6 +1397,10 @@ var _TinyCloudNode = class _TinyCloudNode {
1363
1397
  get capabilityRequest() {
1364
1398
  return this.auth?.capabilityRequest;
1365
1399
  }
1400
+ get hosts() {
1401
+ const authHosts = this.auth?.hosts ?? [];
1402
+ return authHosts.length > 0 ? authHosts : [this.config.host];
1403
+ }
1366
1404
  /**
1367
1405
  * Get the primary identity DID for this user.
1368
1406
  * - If wallet connected and signed in: returns PKH DID (did:pkh:eip155:{chainId}:{address})
@@ -1435,6 +1473,7 @@ var _TinyCloudNode = class _TinyCloudNode {
1435
1473
  this._hooks = void 0;
1436
1474
  this._serviceContext = void 0;
1437
1475
  await this.tc.signIn(options);
1476
+ this.syncResolvedHostFromAuth();
1438
1477
  this.initializeServices();
1439
1478
  await this.writeManifestRegistryRecords();
1440
1479
  this.notificationHandler.success("Successfully signed in");
@@ -1586,7 +1625,6 @@ var _TinyCloudNode = class _TinyCloudNode {
1586
1625
  throw new Error("Wallet already connected. Cannot connect another wallet.");
1587
1626
  }
1588
1627
  const prefix = options?.prefix ?? "default";
1589
- const host = this.config.host;
1590
1628
  if (!_TinyCloudNode.nodeDefaults) {
1591
1629
  throw new Error(
1592
1630
  "connectWallet() requires PrivateKeySigner. Use connectSigner() instead, or import from '@tinycloud/node-sdk' (not '/core') for automatic Node.js defaults."
@@ -1601,7 +1639,9 @@ var _TinyCloudNode = class _TinyCloudNode {
1601
1639
  domain: this.siweDomain,
1602
1640
  spacePrefix: prefix,
1603
1641
  sessionExpirationMs: this.config.sessionExpirationMs ?? 60 * 60 * 1e3,
1604
- tinycloudHosts: [host],
1642
+ tinycloudHosts: this.explicitHost ? [this.explicitHost] : void 0,
1643
+ tinycloudRegistryUrl: this.config.tinycloudRegistryUrl,
1644
+ tinycloudFallbackHosts: this.config.tinycloudFallbackHosts,
1605
1645
  autoCreateSpace: this.config.autoCreateSpace,
1606
1646
  enablePublicSpace: this.config.enablePublicSpace ?? true,
1607
1647
  spaceCreationHandler: this.config.spaceCreationHandler,
@@ -1634,7 +1674,6 @@ var _TinyCloudNode = class _TinyCloudNode {
1634
1674
  throw new Error("Signer already connected. Cannot connect another signer.");
1635
1675
  }
1636
1676
  const prefix = options?.prefix ?? "default";
1637
- const host = this.config.host;
1638
1677
  this.signer = signer;
1639
1678
  this.auth = new NodeUserAuthorization({
1640
1679
  signer: this.signer,
@@ -1644,7 +1683,9 @@ var _TinyCloudNode = class _TinyCloudNode {
1644
1683
  domain: this.siweDomain,
1645
1684
  spacePrefix: prefix,
1646
1685
  sessionExpirationMs: this.config.sessionExpirationMs ?? 60 * 60 * 1e3,
1647
- tinycloudHosts: [host],
1686
+ tinycloudHosts: this.explicitHost ? [this.explicitHost] : void 0,
1687
+ tinycloudRegistryUrl: this.config.tinycloudRegistryUrl,
1688
+ tinycloudFallbackHosts: this.config.tinycloudFallbackHosts,
1648
1689
  autoCreateSpace: this.config.autoCreateSpace,
1649
1690
  enablePublicSpace: this.config.enablePublicSpace ?? true,
1650
1691
  spaceCreationHandler: this.config.spaceCreationHandler,