@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.
@@ -189,8 +189,12 @@ interface NodeUserAuthorizationConfig {
189
189
  autoCreateSpace?: boolean;
190
190
  /** Custom space creation handler. If provided, takes precedence over autoCreateSpace. */
191
191
  spaceCreationHandler?: ISpaceCreationHandler;
192
- /** TinyCloud server endpoints (default: ["https://node.tinycloud.xyz"]) */
192
+ /** Explicit TinyCloud server endpoints. When omitted, signIn resolves the user's host. */
193
193
  tinycloudHosts?: string[];
194
+ /** TinyCloud location registry URL. Default: https://registry.tinycloud.xyz. */
195
+ tinycloudRegistryUrl?: string | null;
196
+ /** Fallback TinyCloud hosts. Default: hosted TinyCloud node. */
197
+ tinycloudFallbackHosts?: string[] | null;
194
198
  /** Whether to include public space capabilities in the session (default: true) */
195
199
  enablePublicSpace?: boolean;
196
200
  /** WASM bindings for cryptographic operations. Required. */
@@ -270,7 +274,9 @@ declare class NodeUserAuthorization implements IUserAuthorization {
270
274
  private readonly sessionExpirationMs;
271
275
  private readonly autoCreateSpace;
272
276
  private readonly spaceCreationHandler?;
273
- private readonly tinycloudHosts;
277
+ private tinycloudHosts?;
278
+ private readonly tinycloudRegistryUrl?;
279
+ private readonly tinycloudFallbackHosts?;
274
280
  private readonly enablePublicSpace;
275
281
  private readonly nonce?;
276
282
  private readonly siweConfig?;
@@ -299,6 +305,7 @@ declare class NodeUserAuthorization implements IUserAuthorization {
299
305
  */
300
306
  get manifest(): Manifest | Manifest[] | undefined;
301
307
  get capabilityRequest(): ComposedManifestRequest | undefined;
308
+ get hosts(): string[];
302
309
  /**
303
310
  * Install or replace the stored manifest. Takes effect on the next
304
311
  * `signIn()` call — the current session (if any) is not touched.
@@ -314,6 +321,9 @@ declare class NodeUserAuthorization implements IUserAuthorization {
314
321
  * Includes spaceId, delegationHeader, and delegationCid.
315
322
  */
316
323
  get tinyCloudSession(): TinyCloudSession | undefined;
324
+ private resolveTinyCloudHostsForSignIn;
325
+ private requireTinyCloudHosts;
326
+ private get primaryTinyCloudHost();
317
327
  get nodeFeatures(): string[];
318
328
  /**
319
329
  * Compute the `abilities` map the WASM `prepareSession` call should
@@ -644,8 +654,12 @@ interface TinyCloudNodeConfig {
644
654
  privateKey?: string;
645
655
  /** Custom signer implementation. If provided, takes precedence over privateKey. */
646
656
  signer?: ISigner;
647
- /** TinyCloud server URL (default: "https://node.tinycloud.xyz") */
657
+ /** Explicit TinyCloud server URL. When omitted, signIn resolves the user's host. */
648
658
  host?: string;
659
+ /** TinyCloud location registry URL. Default: https://registry.tinycloud.xyz. */
660
+ tinycloudRegistryUrl?: string | null;
661
+ /** Fallback TinyCloud hosts. Default: hosted TinyCloud node. */
662
+ tinycloudFallbackHosts?: string[] | null;
649
663
  /** Space prefix for this user's space. Optional - only needed for signIn() */
650
664
  prefix?: string;
651
665
  /** Domain for SIWE messages (default: derived from host) */
@@ -742,6 +756,7 @@ declare class TinyCloudNode {
742
756
  /** @internal Register Node.js-specific defaults (NodeWasmBindings, PrivateKeySigner) */
743
757
  static registerNodeDefaults(defaults: NodeDefaults): void;
744
758
  private config;
759
+ private readonly explicitHost?;
745
760
  private signer;
746
761
  private auth;
747
762
  private tc;
@@ -800,6 +815,7 @@ declare class TinyCloudNode {
800
815
  * @internal
801
816
  */
802
817
  private setupAuth;
818
+ private syncResolvedHostFromAuth;
803
819
  /**
804
820
  * Install or replace the manifest that drives the SIWE recap at
805
821
  * sign-in. Takes effect on the next `signIn()` call — the current
@@ -815,6 +831,7 @@ declare class TinyCloudNode {
815
831
  */
816
832
  get manifest(): Manifest | Manifest[] | undefined;
817
833
  get capabilityRequest(): ComposedManifestRequest | undefined;
834
+ get hosts(): string[];
818
835
  /**
819
836
  * Get the primary identity DID for this user.
820
837
  * - If wallet connected and signed in: returns PKH DID (did:pkh:eip155:{chainId}:{address})
@@ -189,8 +189,12 @@ interface NodeUserAuthorizationConfig {
189
189
  autoCreateSpace?: boolean;
190
190
  /** Custom space creation handler. If provided, takes precedence over autoCreateSpace. */
191
191
  spaceCreationHandler?: ISpaceCreationHandler;
192
- /** TinyCloud server endpoints (default: ["https://node.tinycloud.xyz"]) */
192
+ /** Explicit TinyCloud server endpoints. When omitted, signIn resolves the user's host. */
193
193
  tinycloudHosts?: string[];
194
+ /** TinyCloud location registry URL. Default: https://registry.tinycloud.xyz. */
195
+ tinycloudRegistryUrl?: string | null;
196
+ /** Fallback TinyCloud hosts. Default: hosted TinyCloud node. */
197
+ tinycloudFallbackHosts?: string[] | null;
194
198
  /** Whether to include public space capabilities in the session (default: true) */
195
199
  enablePublicSpace?: boolean;
196
200
  /** WASM bindings for cryptographic operations. Required. */
@@ -270,7 +274,9 @@ declare class NodeUserAuthorization implements IUserAuthorization {
270
274
  private readonly sessionExpirationMs;
271
275
  private readonly autoCreateSpace;
272
276
  private readonly spaceCreationHandler?;
273
- private readonly tinycloudHosts;
277
+ private tinycloudHosts?;
278
+ private readonly tinycloudRegistryUrl?;
279
+ private readonly tinycloudFallbackHosts?;
274
280
  private readonly enablePublicSpace;
275
281
  private readonly nonce?;
276
282
  private readonly siweConfig?;
@@ -299,6 +305,7 @@ declare class NodeUserAuthorization implements IUserAuthorization {
299
305
  */
300
306
  get manifest(): Manifest | Manifest[] | undefined;
301
307
  get capabilityRequest(): ComposedManifestRequest | undefined;
308
+ get hosts(): string[];
302
309
  /**
303
310
  * Install or replace the stored manifest. Takes effect on the next
304
311
  * `signIn()` call — the current session (if any) is not touched.
@@ -314,6 +321,9 @@ declare class NodeUserAuthorization implements IUserAuthorization {
314
321
  * Includes spaceId, delegationHeader, and delegationCid.
315
322
  */
316
323
  get tinyCloudSession(): TinyCloudSession | undefined;
324
+ private resolveTinyCloudHostsForSignIn;
325
+ private requireTinyCloudHosts;
326
+ private get primaryTinyCloudHost();
317
327
  get nodeFeatures(): string[];
318
328
  /**
319
329
  * Compute the `abilities` map the WASM `prepareSession` call should
@@ -644,8 +654,12 @@ interface TinyCloudNodeConfig {
644
654
  privateKey?: string;
645
655
  /** Custom signer implementation. If provided, takes precedence over privateKey. */
646
656
  signer?: ISigner;
647
- /** TinyCloud server URL (default: "https://node.tinycloud.xyz") */
657
+ /** Explicit TinyCloud server URL. When omitted, signIn resolves the user's host. */
648
658
  host?: string;
659
+ /** TinyCloud location registry URL. Default: https://registry.tinycloud.xyz. */
660
+ tinycloudRegistryUrl?: string | null;
661
+ /** Fallback TinyCloud hosts. Default: hosted TinyCloud node. */
662
+ tinycloudFallbackHosts?: string[] | null;
649
663
  /** Space prefix for this user's space. Optional - only needed for signIn() */
650
664
  prefix?: string;
651
665
  /** Domain for SIWE messages (default: derived from host) */
@@ -742,6 +756,7 @@ declare class TinyCloudNode {
742
756
  /** @internal Register Node.js-specific defaults (NodeWasmBindings, PrivateKeySigner) */
743
757
  static registerNodeDefaults(defaults: NodeDefaults): void;
744
758
  private config;
759
+ private readonly explicitHost?;
745
760
  private signer;
746
761
  private auth;
747
762
  private tc;
@@ -800,6 +815,7 @@ declare class TinyCloudNode {
800
815
  * @internal
801
816
  */
802
817
  private setupAuth;
818
+ private syncResolvedHostFromAuth;
803
819
  /**
804
820
  * Install or replace the manifest that drives the SIWE recap at
805
821
  * sign-in. Takes effect on the next `signIn()` call — the current
@@ -815,6 +831,7 @@ declare class TinyCloudNode {
815
831
  */
816
832
  get manifest(): Manifest | Manifest[] | undefined;
817
833
  get capabilityRequest(): ComposedManifestRequest | undefined;
834
+ get hosts(): string[];
818
835
  /**
819
836
  * Get the primary identity DID for this user.
820
837
  * - If wallet connected and signed in: returns PKH DID (did:pkh:eip155:{chainId}:{address})
package/dist/core.cjs CHANGED
@@ -339,9 +339,9 @@ var NodeUserAuthorization = class {
339
339
  this.sessionExpirationMs = config.sessionExpirationMs ?? 60 * 60 * 1e3;
340
340
  this.autoCreateSpace = config.autoCreateSpace ?? false;
341
341
  this.spaceCreationHandler = config.spaceCreationHandler;
342
- this.tinycloudHosts = config.tinycloudHosts ?? [
343
- "https://node.tinycloud.xyz"
344
- ];
342
+ this.tinycloudHosts = config.tinycloudHosts;
343
+ this.tinycloudRegistryUrl = config.tinycloudRegistryUrl;
344
+ this.tinycloudFallbackHosts = config.tinycloudFallbackHosts;
345
345
  this.enablePublicSpace = config.enablePublicSpace ?? true;
346
346
  this.nonce = config.nonce;
347
347
  this.siweConfig = config.siweConfig;
@@ -362,6 +362,9 @@ var NodeUserAuthorization = class {
362
362
  get capabilityRequest() {
363
363
  return this.getCapabilityRequest();
364
364
  }
365
+ get hosts() {
366
+ return this.tinycloudHosts ? [...this.tinycloudHosts] : [];
367
+ }
365
368
  /**
366
369
  * Install or replace the stored manifest. Takes effect on the next
367
370
  * `signIn()` call — the current session (if any) is not touched.
@@ -386,6 +389,26 @@ var NodeUserAuthorization = class {
386
389
  get tinyCloudSession() {
387
390
  return this._tinyCloudSession;
388
391
  }
392
+ async resolveTinyCloudHostsForSignIn(address, chainId) {
393
+ if (this.tinycloudHosts && this.tinycloudHosts.length > 0) {
394
+ return;
395
+ }
396
+ const subject = `did:pkh:eip155:${chainId}:${address}`;
397
+ const resolved = await (0, import_sdk_core2.resolveTinyCloudHosts)(subject, {
398
+ registryUrl: this.tinycloudRegistryUrl,
399
+ fallbackHosts: this.tinycloudFallbackHosts
400
+ });
401
+ this.tinycloudHosts = resolved.hosts;
402
+ }
403
+ requireTinyCloudHosts() {
404
+ if (!this.tinycloudHosts || this.tinycloudHosts.length === 0) {
405
+ throw new Error("TinyCloud hosts have not been resolved. Call signIn() first.");
406
+ }
407
+ return this.tinycloudHosts;
408
+ }
409
+ get primaryTinyCloudHost() {
410
+ return this.requireTinyCloudHosts()[0];
411
+ }
389
412
  get nodeFeatures() {
390
413
  return this._nodeFeatures;
391
414
  }
@@ -517,7 +540,7 @@ var NodeUserAuthorization = class {
517
540
  if (!this._tinyCloudSession || !this._address || !this._chainId) {
518
541
  throw new Error("Must be signed in to host space");
519
542
  }
520
- const host = this.tinycloudHosts[0];
543
+ const host = this.primaryTinyCloudHost;
521
544
  const spaceId = targetSpaceId ?? this._tinyCloudSession.spaceId;
522
545
  const peerId = await (0, import_sdk_core2.fetchPeerId)(host, spaceId);
523
546
  const siwe = this.wasm.generateHostSIWEMessage({
@@ -559,7 +582,7 @@ var NodeUserAuthorization = class {
559
582
  if (!this._tinyCloudSession) {
560
583
  throw new Error("Must be signed in to ensure space exists");
561
584
  }
562
- const host = this.tinycloudHosts[0];
585
+ const host = this.primaryTinyCloudHost;
563
586
  const primarySpaceId = this._tinyCloudSession.spaceId;
564
587
  const result = await (0, import_sdk_core2.activateSessionWithHost)(
565
588
  host,
@@ -668,6 +691,7 @@ var NodeUserAuthorization = class {
668
691
  this._chainId = await this.signer.getChainId();
669
692
  const address = this.wasm.ensureEip55(this._address);
670
693
  const chainId = this._chainId;
694
+ await this.resolveTinyCloudHostsForSignIn(address, chainId);
671
695
  const keyId = `session-${Date.now()}`;
672
696
  this.sessionManager.renameSessionKeyId("default", keyId);
673
697
  const jwkString = this.sessionManager.jwk(keyId);
@@ -746,7 +770,7 @@ var NodeUserAuthorization = class {
746
770
  this._address = address;
747
771
  this._chainId = chainId;
748
772
  const nodeInfo = await (0, import_sdk_core2.checkNodeInfo)(
749
- this.tinycloudHosts[0],
773
+ this.primaryTinyCloudHost,
750
774
  this.wasm.protocolVersion()
751
775
  );
752
776
  this._nodeFeatures = nodeInfo.features;
@@ -862,6 +886,7 @@ var NodeUserAuthorization = class {
862
886
  });
863
887
  const address = this.wasm.ensureEip55(await this.signer.getAddress());
864
888
  const chainId = await this.signer.getChainId();
889
+ await this.resolveTinyCloudHostsForSignIn(address, chainId);
865
890
  const clientSession = {
866
891
  address,
867
892
  walletAddress: address,
@@ -911,7 +936,7 @@ var NodeUserAuthorization = class {
911
936
  this._address = address;
912
937
  this._chainId = chainId;
913
938
  const nodeInfo = await (0, import_sdk_core2.checkNodeInfo)(
914
- this.tinycloudHosts[0],
939
+ this.primaryTinyCloudHost,
915
940
  this.wasm.protocolVersion()
916
941
  );
917
942
  this._nodeFeatures = nodeInfo.features;
@@ -1258,6 +1283,7 @@ var _TinyCloudNode = class _TinyCloudNode {
1258
1283
  this.auth = null;
1259
1284
  this.tc = null;
1260
1285
  this._chainId = 1;
1286
+ this.explicitHost = config.host;
1261
1287
  this.config = {
1262
1288
  ...config,
1263
1289
  host: config.host ?? DEFAULT_HOST
@@ -1339,7 +1365,6 @@ var _TinyCloudNode = class _TinyCloudNode {
1339
1365
  * @internal
1340
1366
  */
1341
1367
  setupAuth(config) {
1342
- const host = this.config.host;
1343
1368
  this.auth = new NodeUserAuthorization({
1344
1369
  signer: this.signer,
1345
1370
  signStrategy: { type: "auto-sign" },
@@ -1348,7 +1373,9 @@ var _TinyCloudNode = class _TinyCloudNode {
1348
1373
  domain: this.siweDomain,
1349
1374
  spacePrefix: config.prefix,
1350
1375
  sessionExpirationMs: config.sessionExpirationMs ?? 60 * 60 * 1e3,
1351
- tinycloudHosts: [host],
1376
+ tinycloudHosts: this.explicitHost ? [this.explicitHost] : void 0,
1377
+ tinycloudRegistryUrl: config.tinycloudRegistryUrl,
1378
+ tinycloudFallbackHosts: config.tinycloudFallbackHosts,
1352
1379
  autoCreateSpace: config.autoCreateSpace,
1353
1380
  enablePublicSpace: config.enablePublicSpace ?? true,
1354
1381
  spaceCreationHandler: config.spaceCreationHandler,
@@ -1362,6 +1389,12 @@ var _TinyCloudNode = class _TinyCloudNode {
1362
1389
  invokeAny: this.wasmBindings.invokeAny
1363
1390
  });
1364
1391
  }
1392
+ syncResolvedHostFromAuth() {
1393
+ const host = this.auth?.hosts[0];
1394
+ if (host) {
1395
+ this.config.host = host;
1396
+ }
1397
+ }
1365
1398
  /**
1366
1399
  * Install or replace the manifest that drives the SIWE recap at
1367
1400
  * sign-in. Takes effect on the next `signIn()` call — the current
@@ -1399,6 +1432,10 @@ var _TinyCloudNode = class _TinyCloudNode {
1399
1432
  get capabilityRequest() {
1400
1433
  return this.auth?.capabilityRequest;
1401
1434
  }
1435
+ get hosts() {
1436
+ const authHosts = this.auth?.hosts ?? [];
1437
+ return authHosts.length > 0 ? authHosts : [this.config.host];
1438
+ }
1402
1439
  /**
1403
1440
  * Get the primary identity DID for this user.
1404
1441
  * - If wallet connected and signed in: returns PKH DID (did:pkh:eip155:{chainId}:{address})
@@ -1471,6 +1508,7 @@ var _TinyCloudNode = class _TinyCloudNode {
1471
1508
  this._hooks = void 0;
1472
1509
  this._serviceContext = void 0;
1473
1510
  await this.tc.signIn(options);
1511
+ this.syncResolvedHostFromAuth();
1474
1512
  this.initializeServices();
1475
1513
  await this.writeManifestRegistryRecords();
1476
1514
  this.notificationHandler.success("Successfully signed in");
@@ -1622,7 +1660,6 @@ var _TinyCloudNode = class _TinyCloudNode {
1622
1660
  throw new Error("Wallet already connected. Cannot connect another wallet.");
1623
1661
  }
1624
1662
  const prefix = options?.prefix ?? "default";
1625
- const host = this.config.host;
1626
1663
  if (!_TinyCloudNode.nodeDefaults) {
1627
1664
  throw new Error(
1628
1665
  "connectWallet() requires PrivateKeySigner. Use connectSigner() instead, or import from '@tinycloud/node-sdk' (not '/core') for automatic Node.js defaults."
@@ -1637,7 +1674,9 @@ var _TinyCloudNode = class _TinyCloudNode {
1637
1674
  domain: this.siweDomain,
1638
1675
  spacePrefix: prefix,
1639
1676
  sessionExpirationMs: this.config.sessionExpirationMs ?? 60 * 60 * 1e3,
1640
- tinycloudHosts: [host],
1677
+ tinycloudHosts: this.explicitHost ? [this.explicitHost] : void 0,
1678
+ tinycloudRegistryUrl: this.config.tinycloudRegistryUrl,
1679
+ tinycloudFallbackHosts: this.config.tinycloudFallbackHosts,
1641
1680
  autoCreateSpace: this.config.autoCreateSpace,
1642
1681
  enablePublicSpace: this.config.enablePublicSpace ?? true,
1643
1682
  spaceCreationHandler: this.config.spaceCreationHandler,
@@ -1670,7 +1709,6 @@ var _TinyCloudNode = class _TinyCloudNode {
1670
1709
  throw new Error("Signer already connected. Cannot connect another signer.");
1671
1710
  }
1672
1711
  const prefix = options?.prefix ?? "default";
1673
- const host = this.config.host;
1674
1712
  this.signer = signer;
1675
1713
  this.auth = new NodeUserAuthorization({
1676
1714
  signer: this.signer,
@@ -1680,7 +1718,9 @@ var _TinyCloudNode = class _TinyCloudNode {
1680
1718
  domain: this.siweDomain,
1681
1719
  spacePrefix: prefix,
1682
1720
  sessionExpirationMs: this.config.sessionExpirationMs ?? 60 * 60 * 1e3,
1683
- tinycloudHosts: [host],
1721
+ tinycloudHosts: this.explicitHost ? [this.explicitHost] : void 0,
1722
+ tinycloudRegistryUrl: this.config.tinycloudRegistryUrl,
1723
+ tinycloudFallbackHosts: this.config.tinycloudFallbackHosts,
1684
1724
  autoCreateSpace: this.config.autoCreateSpace,
1685
1725
  enablePublicSpace: this.config.enablePublicSpace ?? true,
1686
1726
  spaceCreationHandler: this.config.spaceCreationHandler,