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

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
@@ -17303,6 +17303,7 @@ var NodeUserAuthorization = class {
17303
17303
  this.spaceCreationHandler = config.spaceCreationHandler;
17304
17304
  this.tinycloudHosts = config.tinycloudHosts ?? ["https://node.tinycloud.xyz"];
17305
17305
  this.enablePublicSpace = config.enablePublicSpace ?? true;
17306
+ this.siweConfig = config.siweConfig;
17306
17307
  this.sessionManager = this.wasm.createSessionManager();
17307
17308
  }
17308
17309
  /**
@@ -17321,6 +17322,31 @@ var NodeUserAuthorization = class {
17321
17322
  get nodeFeatures() {
17322
17323
  return this._nodeFeatures;
17323
17324
  }
17325
+ /**
17326
+ * Build SIWE overrides from siweConfig.
17327
+ * - statement is prepended to the default statement
17328
+ * - resources are appended to the default resources
17329
+ * - uri triggers a warning (overwriting delegation target)
17330
+ * - all other fields override directly
17331
+ */
17332
+ buildSiweOverrides() {
17333
+ if (!this.siweConfig) return { uri: this.uri };
17334
+ const { statement, resources, uri, ...rest } = this.siweConfig;
17335
+ const overrides = { uri: this.uri, ...rest };
17336
+ if (statement) {
17337
+ overrides.statement = this.statement ? `${statement} ${this.statement}` : statement;
17338
+ }
17339
+ if (resources && resources.length > 0) {
17340
+ overrides.resources = resources;
17341
+ }
17342
+ if (uri) {
17343
+ console.warn(
17344
+ "[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."
17345
+ );
17346
+ overrides.uri = uri;
17347
+ }
17348
+ return overrides;
17349
+ }
17324
17350
  /**
17325
17351
  * Add an extension to the authorization flow.
17326
17352
  */
@@ -17495,7 +17521,8 @@ var NodeUserAuthorization = class {
17495
17521
  issuedAt: now.toISOString(),
17496
17522
  expirationTime: expirationTime.toISOString(),
17497
17523
  spaceId,
17498
- jwk
17524
+ jwk,
17525
+ ...this.buildSiweOverrides()
17499
17526
  });
17500
17527
  const signature2 = await this.requestSignature({
17501
17528
  address,
@@ -17634,7 +17661,8 @@ var NodeUserAuthorization = class {
17634
17661
  issuedAt: now.toISOString(),
17635
17662
  expirationTime: expirationTime.toISOString(),
17636
17663
  spaceId,
17637
- jwk
17664
+ jwk,
17665
+ ...this.buildSiweOverrides()
17638
17666
  });
17639
17667
  return {
17640
17668
  prepared,
@@ -18035,25 +18063,29 @@ var TinyCloudNode = class _TinyCloudNode {
18035
18063
  get nodeFeatures() {
18036
18064
  return this.auth?.nodeFeatures ?? [];
18037
18065
  }
18066
+ /** SIWE domain — uses config override or defaults to app.tinycloud.xyz */
18067
+ get siweDomain() {
18068
+ return this.config.domain ?? "app.tinycloud.xyz";
18069
+ }
18038
18070
  /**
18039
18071
  * Set up authorization handler and TinyCloud instance.
18040
18072
  * @internal
18041
18073
  */
18042
18074
  setupAuth(config) {
18043
18075
  const host = this.config.host;
18044
- const domain = config.domain ?? new URL(host).hostname;
18045
18076
  this.auth = new NodeUserAuthorization({
18046
18077
  signer: this.signer,
18047
18078
  signStrategy: { type: "auto-sign" },
18048
18079
  wasmBindings: this.wasmBindings,
18049
18080
  sessionStorage: config.sessionStorage ?? new MemorySessionStorage(),
18050
- domain,
18081
+ domain: this.siweDomain,
18051
18082
  spacePrefix: config.prefix,
18052
18083
  sessionExpirationMs: config.sessionExpirationMs ?? 60 * 60 * 1e3,
18053
18084
  tinycloudHosts: [host],
18054
18085
  autoCreateSpace: config.autoCreateSpace,
18055
18086
  enablePublicSpace: config.enablePublicSpace ?? true,
18056
- spaceCreationHandler: config.spaceCreationHandler
18087
+ spaceCreationHandler: config.spaceCreationHandler,
18088
+ siweConfig: config.siweConfig
18057
18089
  });
18058
18090
  this.tc = new import_sdk_core3.TinyCloud(this.auth);
18059
18091
  }
@@ -18242,7 +18274,6 @@ var TinyCloudNode = class _TinyCloudNode {
18242
18274
  }
18243
18275
  const prefix = options?.prefix ?? "default";
18244
18276
  const host = this.config.host;
18245
- const domain = new URL(host).hostname;
18246
18277
  if (!_TinyCloudNode.nodeDefaults) {
18247
18278
  throw new Error(
18248
18279
  "connectWallet() requires PrivateKeySigner. Use connectSigner() instead, or import from '@tinycloud/node-sdk' (not '/core') for automatic Node.js defaults."
@@ -18254,7 +18285,7 @@ var TinyCloudNode = class _TinyCloudNode {
18254
18285
  signStrategy: { type: "auto-sign" },
18255
18286
  wasmBindings: this.wasmBindings,
18256
18287
  sessionStorage: options?.sessionStorage ?? this.config.sessionStorage ?? new MemorySessionStorage(),
18257
- domain,
18288
+ domain: this.siweDomain,
18258
18289
  spacePrefix: prefix,
18259
18290
  sessionExpirationMs: this.config.sessionExpirationMs ?? 60 * 60 * 1e3,
18260
18291
  tinycloudHosts: [host],
@@ -18284,14 +18315,13 @@ var TinyCloudNode = class _TinyCloudNode {
18284
18315
  }
18285
18316
  const prefix = options?.prefix ?? "default";
18286
18317
  const host = this.config.host;
18287
- const domain = new URL(host).hostname;
18288
18318
  this.signer = signer;
18289
18319
  this.auth = new NodeUserAuthorization({
18290
18320
  signer: this.signer,
18291
18321
  signStrategy: { type: "auto-sign" },
18292
18322
  wasmBindings: this.wasmBindings,
18293
18323
  sessionStorage: options?.sessionStorage ?? this.config.sessionStorage ?? new MemorySessionStorage(),
18294
- domain,
18324
+ domain: this.siweDomain,
18295
18325
  spacePrefix: prefix,
18296
18326
  sessionExpirationMs: this.config.sessionExpirationMs ?? 60 * 60 * 1e3,
18297
18327
  tinycloudHosts: [host],
@@ -18602,7 +18632,7 @@ var TinyCloudNode = class _TinyCloudNode {
18602
18632
  abilities,
18603
18633
  address: this.wasmBindings.ensureEip55(session.address),
18604
18634
  chainId: session.chainId,
18605
- domain: new URL(host).hostname,
18635
+ domain: this.siweDomain,
18606
18636
  issuedAt: now.toISOString(),
18607
18637
  expirationTime: params.requestedExpiry.toISOString(),
18608
18638
  spaceId: params.spaceId,
@@ -18911,7 +18941,7 @@ var TinyCloudNode = class _TinyCloudNode {
18911
18941
  abilities,
18912
18942
  address: this.wasmBindings.ensureEip55(this.session.address),
18913
18943
  chainId: this.session.chainId,
18914
- domain: new URL(this.config.host).hostname,
18944
+ domain: this.siweDomain,
18915
18945
  issuedAt: now.toISOString(),
18916
18946
  expirationTime: expirationTime.toISOString(),
18917
18947
  spaceId: publicSpaceId,
@@ -19078,7 +19108,7 @@ var TinyCloudNode = class _TinyCloudNode {
19078
19108
  abilities,
19079
19109
  address: this.wasmBindings.ensureEip55(session.address),
19080
19110
  chainId: session.chainId,
19081
- domain: new URL(this.config.host).hostname,
19111
+ domain: this.siweDomain,
19082
19112
  issuedAt: now.toISOString(),
19083
19113
  expirationTime: expirationTime.toISOString(),
19084
19114
  spaceId: params.spaceIdOverride ?? session.spaceId,
@@ -19123,7 +19153,7 @@ var TinyCloudNode = class _TinyCloudNode {
19123
19153
  abilities: publicAbilities,
19124
19154
  address: this.wasmBindings.ensureEip55(session.address),
19125
19155
  chainId: session.chainId,
19126
- domain: new URL(this.config.host).hostname,
19156
+ domain: this.siweDomain,
19127
19157
  issuedAt: now.toISOString(),
19128
19158
  expirationTime: expirationTime.toISOString(),
19129
19159
  spaceId: publicSpaceId,
@@ -19222,7 +19252,7 @@ var TinyCloudNode = class _TinyCloudNode {
19222
19252
  abilities,
19223
19253
  address: this.wasmBindings.ensureEip55(mySession.address),
19224
19254
  chainId: mySession.chainId,
19225
- domain: new URL(targetHost).hostname,
19255
+ domain: this.siweDomain,
19226
19256
  issuedAt: now.toISOString(),
19227
19257
  expirationTime: expirationTime.toISOString(),
19228
19258
  spaceId: delegation.spaceId,
@@ -19311,7 +19341,7 @@ var TinyCloudNode = class _TinyCloudNode {
19311
19341
  abilities,
19312
19342
  address: this.wasmBindings.ensureEip55(this._address),
19313
19343
  chainId: this._chainId,
19314
- domain: new URL(targetHost).hostname,
19344
+ domain: this.siweDomain,
19315
19345
  issuedAt: now.toISOString(),
19316
19346
  expirationTime: actualExpiry.toISOString(),
19317
19347
  spaceId: parentDelegation.spaceId,