@tinycloud/node-sdk 2.0.2-beta.0 → 2.0.3-beta.0

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.js CHANGED
@@ -17299,6 +17299,7 @@ var NodeUserAuthorization = class {
17299
17299
  this.spaceCreationHandler = config.spaceCreationHandler;
17300
17300
  this.tinycloudHosts = config.tinycloudHosts ?? ["https://node.tinycloud.xyz"];
17301
17301
  this.enablePublicSpace = config.enablePublicSpace ?? true;
17302
+ this.siweConfig = config.siweConfig;
17302
17303
  this.sessionManager = this.wasm.createSessionManager();
17303
17304
  }
17304
17305
  /**
@@ -17317,6 +17318,31 @@ var NodeUserAuthorization = class {
17317
17318
  get nodeFeatures() {
17318
17319
  return this._nodeFeatures;
17319
17320
  }
17321
+ /**
17322
+ * Build SIWE overrides from siweConfig.
17323
+ * - statement is prepended to the default statement
17324
+ * - resources are appended to the default resources
17325
+ * - uri triggers a warning (overwriting delegation target)
17326
+ * - all other fields override directly
17327
+ */
17328
+ buildSiweOverrides() {
17329
+ if (!this.siweConfig) return { uri: this.uri };
17330
+ const { statement, resources, uri, ...rest } = this.siweConfig;
17331
+ const overrides = { uri: this.uri, ...rest };
17332
+ if (statement) {
17333
+ overrides.statement = this.statement ? `${statement} ${this.statement}` : statement;
17334
+ }
17335
+ if (resources && resources.length > 0) {
17336
+ overrides.resources = resources;
17337
+ }
17338
+ if (uri) {
17339
+ console.warn(
17340
+ "[tinycloud] siweConfig.uri is overwriting the delegation target URI. This may break delegation chain validation if the URI does not match the session key DID."
17341
+ );
17342
+ overrides.uri = uri;
17343
+ }
17344
+ return overrides;
17345
+ }
17320
17346
  /**
17321
17347
  * Add an extension to the authorization flow.
17322
17348
  */
@@ -17491,7 +17517,8 @@ var NodeUserAuthorization = class {
17491
17517
  issuedAt: now.toISOString(),
17492
17518
  expirationTime: expirationTime.toISOString(),
17493
17519
  spaceId,
17494
- jwk
17520
+ jwk,
17521
+ ...this.buildSiweOverrides()
17495
17522
  });
17496
17523
  const signature2 = await this.requestSignature({
17497
17524
  address,
@@ -17630,7 +17657,8 @@ var NodeUserAuthorization = class {
17630
17657
  issuedAt: now.toISOString(),
17631
17658
  expirationTime: expirationTime.toISOString(),
17632
17659
  spaceId,
17633
- jwk
17660
+ jwk,
17661
+ ...this.buildSiweOverrides()
17634
17662
  });
17635
17663
  return {
17636
17664
  prepared,
@@ -18036,25 +18064,29 @@ var TinyCloudNode = class _TinyCloudNode {
18036
18064
  get nodeFeatures() {
18037
18065
  return this.auth?.nodeFeatures ?? [];
18038
18066
  }
18067
+ /** SIWE domain — uses config override or defaults to app.tinycloud.xyz */
18068
+ get siweDomain() {
18069
+ return this.config.domain ?? "app.tinycloud.xyz";
18070
+ }
18039
18071
  /**
18040
18072
  * Set up authorization handler and TinyCloud instance.
18041
18073
  * @internal
18042
18074
  */
18043
18075
  setupAuth(config) {
18044
18076
  const host = this.config.host;
18045
- const domain = config.domain ?? new URL(host).hostname;
18046
18077
  this.auth = new NodeUserAuthorization({
18047
18078
  signer: this.signer,
18048
18079
  signStrategy: { type: "auto-sign" },
18049
18080
  wasmBindings: this.wasmBindings,
18050
18081
  sessionStorage: config.sessionStorage ?? new MemorySessionStorage(),
18051
- domain,
18082
+ domain: this.siweDomain,
18052
18083
  spacePrefix: config.prefix,
18053
18084
  sessionExpirationMs: config.sessionExpirationMs ?? 60 * 60 * 1e3,
18054
18085
  tinycloudHosts: [host],
18055
18086
  autoCreateSpace: config.autoCreateSpace,
18056
18087
  enablePublicSpace: config.enablePublicSpace ?? true,
18057
- spaceCreationHandler: config.spaceCreationHandler
18088
+ spaceCreationHandler: config.spaceCreationHandler,
18089
+ siweConfig: config.siweConfig
18058
18090
  });
18059
18091
  this.tc = new TinyCloud(this.auth);
18060
18092
  }
@@ -18243,7 +18275,6 @@ var TinyCloudNode = class _TinyCloudNode {
18243
18275
  }
18244
18276
  const prefix = options?.prefix ?? "default";
18245
18277
  const host = this.config.host;
18246
- const domain = new URL(host).hostname;
18247
18278
  if (!_TinyCloudNode.nodeDefaults) {
18248
18279
  throw new Error(
18249
18280
  "connectWallet() requires PrivateKeySigner. Use connectSigner() instead, or import from '@tinycloud/node-sdk' (not '/core') for automatic Node.js defaults."
@@ -18255,7 +18286,7 @@ var TinyCloudNode = class _TinyCloudNode {
18255
18286
  signStrategy: { type: "auto-sign" },
18256
18287
  wasmBindings: this.wasmBindings,
18257
18288
  sessionStorage: options?.sessionStorage ?? this.config.sessionStorage ?? new MemorySessionStorage(),
18258
- domain,
18289
+ domain: this.siweDomain,
18259
18290
  spacePrefix: prefix,
18260
18291
  sessionExpirationMs: this.config.sessionExpirationMs ?? 60 * 60 * 1e3,
18261
18292
  tinycloudHosts: [host],
@@ -18285,14 +18316,13 @@ var TinyCloudNode = class _TinyCloudNode {
18285
18316
  }
18286
18317
  const prefix = options?.prefix ?? "default";
18287
18318
  const host = this.config.host;
18288
- const domain = new URL(host).hostname;
18289
18319
  this.signer = signer;
18290
18320
  this.auth = new NodeUserAuthorization({
18291
18321
  signer: this.signer,
18292
18322
  signStrategy: { type: "auto-sign" },
18293
18323
  wasmBindings: this.wasmBindings,
18294
18324
  sessionStorage: options?.sessionStorage ?? this.config.sessionStorage ?? new MemorySessionStorage(),
18295
- domain,
18325
+ domain: this.siweDomain,
18296
18326
  spacePrefix: prefix,
18297
18327
  sessionExpirationMs: this.config.sessionExpirationMs ?? 60 * 60 * 1e3,
18298
18328
  tinycloudHosts: [host],
@@ -18603,7 +18633,7 @@ var TinyCloudNode = class _TinyCloudNode {
18603
18633
  abilities,
18604
18634
  address: this.wasmBindings.ensureEip55(session.address),
18605
18635
  chainId: session.chainId,
18606
- domain: new URL(host).hostname,
18636
+ domain: this.siweDomain,
18607
18637
  issuedAt: now.toISOString(),
18608
18638
  expirationTime: params.requestedExpiry.toISOString(),
18609
18639
  spaceId: params.spaceId,
@@ -18912,7 +18942,7 @@ var TinyCloudNode = class _TinyCloudNode {
18912
18942
  abilities,
18913
18943
  address: this.wasmBindings.ensureEip55(this.session.address),
18914
18944
  chainId: this.session.chainId,
18915
- domain: new URL(this.config.host).hostname,
18945
+ domain: this.siweDomain,
18916
18946
  issuedAt: now.toISOString(),
18917
18947
  expirationTime: expirationTime.toISOString(),
18918
18948
  spaceId: publicSpaceId,
@@ -19079,7 +19109,7 @@ var TinyCloudNode = class _TinyCloudNode {
19079
19109
  abilities,
19080
19110
  address: this.wasmBindings.ensureEip55(session.address),
19081
19111
  chainId: session.chainId,
19082
- domain: new URL(this.config.host).hostname,
19112
+ domain: this.siweDomain,
19083
19113
  issuedAt: now.toISOString(),
19084
19114
  expirationTime: expirationTime.toISOString(),
19085
19115
  spaceId: params.spaceIdOverride ?? session.spaceId,
@@ -19124,7 +19154,7 @@ var TinyCloudNode = class _TinyCloudNode {
19124
19154
  abilities: publicAbilities,
19125
19155
  address: this.wasmBindings.ensureEip55(session.address),
19126
19156
  chainId: session.chainId,
19127
- domain: new URL(this.config.host).hostname,
19157
+ domain: this.siweDomain,
19128
19158
  issuedAt: now.toISOString(),
19129
19159
  expirationTime: expirationTime.toISOString(),
19130
19160
  spaceId: publicSpaceId,
@@ -19223,7 +19253,7 @@ var TinyCloudNode = class _TinyCloudNode {
19223
19253
  abilities,
19224
19254
  address: this.wasmBindings.ensureEip55(mySession.address),
19225
19255
  chainId: mySession.chainId,
19226
- domain: new URL(targetHost).hostname,
19256
+ domain: this.siweDomain,
19227
19257
  issuedAt: now.toISOString(),
19228
19258
  expirationTime: expirationTime.toISOString(),
19229
19259
  spaceId: delegation.spaceId,
@@ -19312,7 +19342,7 @@ var TinyCloudNode = class _TinyCloudNode {
19312
19342
  abilities,
19313
19343
  address: this.wasmBindings.ensureEip55(this._address),
19314
19344
  chainId: this._chainId,
19315
- domain: new URL(targetHost).hostname,
19345
+ domain: this.siweDomain,
19316
19346
  issuedAt: now.toISOString(),
19317
19347
  expirationTime: actualExpiry.toISOString(),
19318
19348
  spaceId: parentDelegation.spaceId,