@tinycloud/node-sdk 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.cjs CHANGED
@@ -17327,9 +17327,9 @@ var NodeUserAuthorization = class {
17327
17327
  this.sessionExpirationMs = config.sessionExpirationMs ?? 60 * 60 * 1e3;
17328
17328
  this.autoCreateSpace = config.autoCreateSpace ?? false;
17329
17329
  this.spaceCreationHandler = config.spaceCreationHandler;
17330
- this.tinycloudHosts = config.tinycloudHosts ?? [
17331
- "https://node.tinycloud.xyz"
17332
- ];
17330
+ this.tinycloudHosts = config.tinycloudHosts;
17331
+ this.tinycloudRegistryUrl = config.tinycloudRegistryUrl;
17332
+ this.tinycloudFallbackHosts = config.tinycloudFallbackHosts;
17333
17333
  this.enablePublicSpace = config.enablePublicSpace ?? true;
17334
17334
  this.nonce = config.nonce;
17335
17335
  this.siweConfig = config.siweConfig;
@@ -17350,6 +17350,9 @@ var NodeUserAuthorization = class {
17350
17350
  get capabilityRequest() {
17351
17351
  return this.getCapabilityRequest();
17352
17352
  }
17353
+ get hosts() {
17354
+ return this.tinycloudHosts ? [...this.tinycloudHosts] : [];
17355
+ }
17353
17356
  /**
17354
17357
  * Install or replace the stored manifest. Takes effect on the next
17355
17358
  * `signIn()` call — the current session (if any) is not touched.
@@ -17374,6 +17377,26 @@ var NodeUserAuthorization = class {
17374
17377
  get tinyCloudSession() {
17375
17378
  return this._tinyCloudSession;
17376
17379
  }
17380
+ async resolveTinyCloudHostsForSignIn(address, chainId) {
17381
+ if (this.tinycloudHosts && this.tinycloudHosts.length > 0) {
17382
+ return;
17383
+ }
17384
+ const subject = `did:pkh:eip155:${chainId}:${address}`;
17385
+ const resolved = await (0, import_sdk_core.resolveTinyCloudHosts)(subject, {
17386
+ registryUrl: this.tinycloudRegistryUrl,
17387
+ fallbackHosts: this.tinycloudFallbackHosts
17388
+ });
17389
+ this.tinycloudHosts = resolved.hosts;
17390
+ }
17391
+ requireTinyCloudHosts() {
17392
+ if (!this.tinycloudHosts || this.tinycloudHosts.length === 0) {
17393
+ throw new Error("TinyCloud hosts have not been resolved. Call signIn() first.");
17394
+ }
17395
+ return this.tinycloudHosts;
17396
+ }
17397
+ get primaryTinyCloudHost() {
17398
+ return this.requireTinyCloudHosts()[0];
17399
+ }
17377
17400
  get nodeFeatures() {
17378
17401
  return this._nodeFeatures;
17379
17402
  }
@@ -17505,7 +17528,7 @@ var NodeUserAuthorization = class {
17505
17528
  if (!this._tinyCloudSession || !this._address || !this._chainId) {
17506
17529
  throw new Error("Must be signed in to host space");
17507
17530
  }
17508
- const host = this.tinycloudHosts[0];
17531
+ const host = this.primaryTinyCloudHost;
17509
17532
  const spaceId = targetSpaceId ?? this._tinyCloudSession.spaceId;
17510
17533
  const peerId = await (0, import_sdk_core.fetchPeerId)(host, spaceId);
17511
17534
  const siwe = this.wasm.generateHostSIWEMessage({
@@ -17547,7 +17570,7 @@ var NodeUserAuthorization = class {
17547
17570
  if (!this._tinyCloudSession) {
17548
17571
  throw new Error("Must be signed in to ensure space exists");
17549
17572
  }
17550
- const host = this.tinycloudHosts[0];
17573
+ const host = this.primaryTinyCloudHost;
17551
17574
  const primarySpaceId = this._tinyCloudSession.spaceId;
17552
17575
  const result = await (0, import_sdk_core.activateSessionWithHost)(
17553
17576
  host,
@@ -17656,6 +17679,7 @@ var NodeUserAuthorization = class {
17656
17679
  this._chainId = await this.signer.getChainId();
17657
17680
  const address = this.wasm.ensureEip55(this._address);
17658
17681
  const chainId = this._chainId;
17682
+ await this.resolveTinyCloudHostsForSignIn(address, chainId);
17659
17683
  const keyId = `session-${Date.now()}`;
17660
17684
  this.sessionManager.renameSessionKeyId("default", keyId);
17661
17685
  const jwkString = this.sessionManager.jwk(keyId);
@@ -17734,7 +17758,7 @@ var NodeUserAuthorization = class {
17734
17758
  this._address = address;
17735
17759
  this._chainId = chainId;
17736
17760
  const nodeInfo = await (0, import_sdk_core.checkNodeInfo)(
17737
- this.tinycloudHosts[0],
17761
+ this.primaryTinyCloudHost,
17738
17762
  this.wasm.protocolVersion()
17739
17763
  );
17740
17764
  this._nodeFeatures = nodeInfo.features;
@@ -17850,6 +17874,7 @@ var NodeUserAuthorization = class {
17850
17874
  });
17851
17875
  const address = this.wasm.ensureEip55(await this.signer.getAddress());
17852
17876
  const chainId = await this.signer.getChainId();
17877
+ await this.resolveTinyCloudHostsForSignIn(address, chainId);
17853
17878
  const clientSession = {
17854
17879
  address,
17855
17880
  walletAddress: address,
@@ -17899,7 +17924,7 @@ var NodeUserAuthorization = class {
17899
17924
  this._address = address;
17900
17925
  this._chainId = chainId;
17901
17926
  const nodeInfo = await (0, import_sdk_core.checkNodeInfo)(
17902
- this.tinycloudHosts[0],
17927
+ this.primaryTinyCloudHost,
17903
17928
  this.wasm.protocolVersion()
17904
17929
  );
17905
17930
  this._nodeFeatures = nodeInfo.features;
@@ -18243,6 +18268,7 @@ var _TinyCloudNode = class _TinyCloudNode {
18243
18268
  this.auth = null;
18244
18269
  this.tc = null;
18245
18270
  this._chainId = 1;
18271
+ this.explicitHost = config.host;
18246
18272
  this.config = {
18247
18273
  ...config,
18248
18274
  host: config.host ?? DEFAULT_HOST
@@ -18324,7 +18350,6 @@ var _TinyCloudNode = class _TinyCloudNode {
18324
18350
  * @internal
18325
18351
  */
18326
18352
  setupAuth(config) {
18327
- const host = this.config.host;
18328
18353
  this.auth = new NodeUserAuthorization({
18329
18354
  signer: this.signer,
18330
18355
  signStrategy: { type: "auto-sign" },
@@ -18333,7 +18358,9 @@ var _TinyCloudNode = class _TinyCloudNode {
18333
18358
  domain: this.siweDomain,
18334
18359
  spacePrefix: config.prefix,
18335
18360
  sessionExpirationMs: config.sessionExpirationMs ?? 60 * 60 * 1e3,
18336
- tinycloudHosts: [host],
18361
+ tinycloudHosts: this.explicitHost ? [this.explicitHost] : void 0,
18362
+ tinycloudRegistryUrl: config.tinycloudRegistryUrl,
18363
+ tinycloudFallbackHosts: config.tinycloudFallbackHosts,
18337
18364
  autoCreateSpace: config.autoCreateSpace,
18338
18365
  enablePublicSpace: config.enablePublicSpace ?? true,
18339
18366
  spaceCreationHandler: config.spaceCreationHandler,
@@ -18347,6 +18374,12 @@ var _TinyCloudNode = class _TinyCloudNode {
18347
18374
  invokeAny: this.wasmBindings.invokeAny
18348
18375
  });
18349
18376
  }
18377
+ syncResolvedHostFromAuth() {
18378
+ const host = this.auth?.hosts[0];
18379
+ if (host) {
18380
+ this.config.host = host;
18381
+ }
18382
+ }
18350
18383
  /**
18351
18384
  * Install or replace the manifest that drives the SIWE recap at
18352
18385
  * sign-in. Takes effect on the next `signIn()` call — the current
@@ -18384,6 +18417,10 @@ var _TinyCloudNode = class _TinyCloudNode {
18384
18417
  get capabilityRequest() {
18385
18418
  return this.auth?.capabilityRequest;
18386
18419
  }
18420
+ get hosts() {
18421
+ const authHosts = this.auth?.hosts ?? [];
18422
+ return authHosts.length > 0 ? authHosts : [this.config.host];
18423
+ }
18387
18424
  /**
18388
18425
  * Get the primary identity DID for this user.
18389
18426
  * - If wallet connected and signed in: returns PKH DID (did:pkh:eip155:{chainId}:{address})
@@ -18456,6 +18493,7 @@ var _TinyCloudNode = class _TinyCloudNode {
18456
18493
  this._hooks = void 0;
18457
18494
  this._serviceContext = void 0;
18458
18495
  await this.tc.signIn(options);
18496
+ this.syncResolvedHostFromAuth();
18459
18497
  this.initializeServices();
18460
18498
  await this.writeManifestRegistryRecords();
18461
18499
  this.notificationHandler.success("Successfully signed in");
@@ -18607,7 +18645,6 @@ var _TinyCloudNode = class _TinyCloudNode {
18607
18645
  throw new Error("Wallet already connected. Cannot connect another wallet.");
18608
18646
  }
18609
18647
  const prefix = options?.prefix ?? "default";
18610
- const host = this.config.host;
18611
18648
  if (!_TinyCloudNode.nodeDefaults) {
18612
18649
  throw new Error(
18613
18650
  "connectWallet() requires PrivateKeySigner. Use connectSigner() instead, or import from '@tinycloud/node-sdk' (not '/core') for automatic Node.js defaults."
@@ -18622,7 +18659,9 @@ var _TinyCloudNode = class _TinyCloudNode {
18622
18659
  domain: this.siweDomain,
18623
18660
  spacePrefix: prefix,
18624
18661
  sessionExpirationMs: this.config.sessionExpirationMs ?? 60 * 60 * 1e3,
18625
- tinycloudHosts: [host],
18662
+ tinycloudHosts: this.explicitHost ? [this.explicitHost] : void 0,
18663
+ tinycloudRegistryUrl: this.config.tinycloudRegistryUrl,
18664
+ tinycloudFallbackHosts: this.config.tinycloudFallbackHosts,
18626
18665
  autoCreateSpace: this.config.autoCreateSpace,
18627
18666
  enablePublicSpace: this.config.enablePublicSpace ?? true,
18628
18667
  spaceCreationHandler: this.config.spaceCreationHandler,
@@ -18655,7 +18694,6 @@ var _TinyCloudNode = class _TinyCloudNode {
18655
18694
  throw new Error("Signer already connected. Cannot connect another signer.");
18656
18695
  }
18657
18696
  const prefix = options?.prefix ?? "default";
18658
- const host = this.config.host;
18659
18697
  this.signer = signer;
18660
18698
  this.auth = new NodeUserAuthorization({
18661
18699
  signer: this.signer,
@@ -18665,7 +18703,9 @@ var _TinyCloudNode = class _TinyCloudNode {
18665
18703
  domain: this.siweDomain,
18666
18704
  spacePrefix: prefix,
18667
18705
  sessionExpirationMs: this.config.sessionExpirationMs ?? 60 * 60 * 1e3,
18668
- tinycloudHosts: [host],
18706
+ tinycloudHosts: this.explicitHost ? [this.explicitHost] : void 0,
18707
+ tinycloudRegistryUrl: this.config.tinycloudRegistryUrl,
18708
+ tinycloudFallbackHosts: this.config.tinycloudFallbackHosts,
18669
18709
  autoCreateSpace: this.config.autoCreateSpace,
18670
18710
  enablePublicSpace: this.config.enablePublicSpace ?? true,
18671
18711
  spaceCreationHandler: this.config.spaceCreationHandler,