@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/core.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { ISessionStorage, PersistedSessionData, AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, IUserAuthorization, ISigner, ISpaceCreationHandler, IWasmBindings, ClientSession, TinyCloudSession, Extension, Delegation, IKVService, ISQLService, IDuckDbService, INotificationHandler, IENSResolver, IDataVaultService, ICapabilityKeyRegistry, DelegationManager, ISpaceService, ISharingService, CreateDelegationParams, DelegationResult, KeyProvider, ISessionManager, JWK } from '@tinycloud/sdk-core';
1
+ import { ISessionStorage, PersistedSessionData, AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, IUserAuthorization, ISigner, ISpaceCreationHandler, IWasmBindings, SiweConfig, ClientSession, TinyCloudSession, Extension, Delegation, IKVService, ISQLService, IDuckDbService, INotificationHandler, IENSResolver, IDataVaultService, ICapabilityKeyRegistry, DelegationManager, ISpaceService, ISharingService, CreateDelegationParams, DelegationResult, KeyProvider, ISessionManager, JWK } from '@tinycloud/sdk-core';
2
2
  export { AutoApproveSpaceCreationHandler, AutoRejectStrategy, AutoSignStrategy, BatchOptions, BatchResponse, CallbackStrategy, CapabilityEntry, CapabilityKeyRegistry, CapabilityKeyRegistryErrorCode, CapabilityKeyRegistryErrorCodes, ClientSession, ColumnInfo, CreateDelegationParams, 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, PersistedSessionData, PrefixedKVService, ProtocolMismatchError, QueryOptions, QueryResponse, ReceiveOptions, SQLAction, SQLActionType, SQLService, SQLServiceConfig, SchemaInfo, ServiceContext, ServiceContextConfig, ServiceSession, ShareAccess, ShareLink, ShareLinkData, ShareSchema, SharingService, SharingServiceConfig, SignCallback, SignRequest, SignResponse, SilentNotificationHandler, Space, 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, createCapabilityKeyRegistry, createSharingService, createSpaceService, createVaultCrypto, defaultSpaceCreationHandler, makePublicSpaceId, parseSpaceUri } from '@tinycloud/sdk-core';
3
3
  import { EventEmitter } from 'events';
4
4
  import { InvokeFunction } from '@tinycloud/sdk-services';
@@ -196,6 +196,8 @@ interface NodeUserAuthorizationConfig {
196
196
  enablePublicSpace?: boolean;
197
197
  /** WASM bindings for cryptographic operations. Required. */
198
198
  wasmBindings: IWasmBindings;
199
+ /** Optional SIWE configuration overrides (e.g., nonce for server-provided nonces) */
200
+ siweConfig?: SiweConfig;
199
201
  }
200
202
  /**
201
203
  * Node.js implementation of IUserAuthorization.
@@ -243,6 +245,7 @@ declare class NodeUserAuthorization implements IUserAuthorization {
243
245
  private readonly spaceCreationHandler?;
244
246
  private readonly tinycloudHosts;
245
247
  private readonly enablePublicSpace;
248
+ private readonly siweConfig?;
246
249
  private readonly wasm;
247
250
  private sessionManager;
248
251
  private extensions;
@@ -262,6 +265,14 @@ declare class NodeUserAuthorization implements IUserAuthorization {
262
265
  */
263
266
  get tinyCloudSession(): TinyCloudSession | undefined;
264
267
  get nodeFeatures(): string[];
268
+ /**
269
+ * Build SIWE overrides from siweConfig.
270
+ * - statement is prepended to the default statement
271
+ * - resources are appended to the default resources
272
+ * - uri triggers a warning (overwriting delegation target)
273
+ * - all other fields override directly
274
+ */
275
+ private buildSiweOverrides;
265
276
  /**
266
277
  * Add an extension to the authorization flow.
267
278
  */
@@ -519,6 +530,8 @@ interface TinyCloudNodeConfig {
519
530
  ensResolver?: IENSResolver;
520
531
  /** Custom space creation handler (default: auto-approve when autoCreateSpace is true) */
521
532
  spaceCreationHandler?: ISpaceCreationHandler;
533
+ /** Optional SIWE configuration overrides (e.g., nonce for server-provided nonces) */
534
+ siweConfig?: SiweConfig;
522
535
  }
523
536
  /**
524
537
  * High-level TinyCloud API for Node.js environments.
@@ -563,6 +576,8 @@ declare class TinyCloudNode {
563
576
  private _delegationManager?;
564
577
  private _spaceService?;
565
578
  private get nodeFeatures();
579
+ /** SIWE domain — uses config override or defaults to app.tinycloud.xyz */
580
+ private get siweDomain();
566
581
  /**
567
582
  * Create a new TinyCloudNode instance.
568
583
  *
package/dist/core.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ISessionStorage, PersistedSessionData, AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, IUserAuthorization, ISigner, ISpaceCreationHandler, IWasmBindings, ClientSession, TinyCloudSession, Extension, Delegation, IKVService, ISQLService, IDuckDbService, INotificationHandler, IENSResolver, IDataVaultService, ICapabilityKeyRegistry, DelegationManager, ISpaceService, ISharingService, CreateDelegationParams, DelegationResult, KeyProvider, ISessionManager, JWK } from '@tinycloud/sdk-core';
1
+ import { ISessionStorage, PersistedSessionData, AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, IUserAuthorization, ISigner, ISpaceCreationHandler, IWasmBindings, SiweConfig, ClientSession, TinyCloudSession, Extension, Delegation, IKVService, ISQLService, IDuckDbService, INotificationHandler, IENSResolver, IDataVaultService, ICapabilityKeyRegistry, DelegationManager, ISpaceService, ISharingService, CreateDelegationParams, DelegationResult, KeyProvider, ISessionManager, JWK } from '@tinycloud/sdk-core';
2
2
  export { AutoApproveSpaceCreationHandler, AutoRejectStrategy, AutoSignStrategy, BatchOptions, BatchResponse, CallbackStrategy, CapabilityEntry, CapabilityKeyRegistry, CapabilityKeyRegistryErrorCode, CapabilityKeyRegistryErrorCodes, ClientSession, ColumnInfo, CreateDelegationParams, 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, PersistedSessionData, PrefixedKVService, ProtocolMismatchError, QueryOptions, QueryResponse, ReceiveOptions, SQLAction, SQLActionType, SQLService, SQLServiceConfig, SchemaInfo, ServiceContext, ServiceContextConfig, ServiceSession, ShareAccess, ShareLink, ShareLinkData, ShareSchema, SharingService, SharingServiceConfig, SignCallback, SignRequest, SignResponse, SilentNotificationHandler, Space, 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, createCapabilityKeyRegistry, createSharingService, createSpaceService, createVaultCrypto, defaultSpaceCreationHandler, makePublicSpaceId, parseSpaceUri } from '@tinycloud/sdk-core';
3
3
  import { EventEmitter } from 'events';
4
4
  import { InvokeFunction } from '@tinycloud/sdk-services';
@@ -196,6 +196,8 @@ interface NodeUserAuthorizationConfig {
196
196
  enablePublicSpace?: boolean;
197
197
  /** WASM bindings for cryptographic operations. Required. */
198
198
  wasmBindings: IWasmBindings;
199
+ /** Optional SIWE configuration overrides (e.g., nonce for server-provided nonces) */
200
+ siweConfig?: SiweConfig;
199
201
  }
200
202
  /**
201
203
  * Node.js implementation of IUserAuthorization.
@@ -243,6 +245,7 @@ declare class NodeUserAuthorization implements IUserAuthorization {
243
245
  private readonly spaceCreationHandler?;
244
246
  private readonly tinycloudHosts;
245
247
  private readonly enablePublicSpace;
248
+ private readonly siweConfig?;
246
249
  private readonly wasm;
247
250
  private sessionManager;
248
251
  private extensions;
@@ -262,6 +265,14 @@ declare class NodeUserAuthorization implements IUserAuthorization {
262
265
  */
263
266
  get tinyCloudSession(): TinyCloudSession | undefined;
264
267
  get nodeFeatures(): string[];
268
+ /**
269
+ * Build SIWE overrides from siweConfig.
270
+ * - statement is prepended to the default statement
271
+ * - resources are appended to the default resources
272
+ * - uri triggers a warning (overwriting delegation target)
273
+ * - all other fields override directly
274
+ */
275
+ private buildSiweOverrides;
265
276
  /**
266
277
  * Add an extension to the authorization flow.
267
278
  */
@@ -519,6 +530,8 @@ interface TinyCloudNodeConfig {
519
530
  ensResolver?: IENSResolver;
520
531
  /** Custom space creation handler (default: auto-approve when autoCreateSpace is true) */
521
532
  spaceCreationHandler?: ISpaceCreationHandler;
533
+ /** Optional SIWE configuration overrides (e.g., nonce for server-provided nonces) */
534
+ siweConfig?: SiweConfig;
522
535
  }
523
536
  /**
524
537
  * High-level TinyCloud API for Node.js environments.
@@ -563,6 +576,8 @@ declare class TinyCloudNode {
563
576
  private _delegationManager?;
564
577
  private _spaceService?;
565
578
  private get nodeFeatures();
579
+ /** SIWE domain — uses config override or defaults to app.tinycloud.xyz */
580
+ private get siweDomain();
566
581
  /**
567
582
  * Create a new TinyCloudNode instance.
568
583
  *
package/dist/core.js CHANGED
@@ -260,6 +260,7 @@ var NodeUserAuthorization = class {
260
260
  this.spaceCreationHandler = config.spaceCreationHandler;
261
261
  this.tinycloudHosts = config.tinycloudHosts ?? ["https://node.tinycloud.xyz"];
262
262
  this.enablePublicSpace = config.enablePublicSpace ?? true;
263
+ this.siweConfig = config.siweConfig;
263
264
  this.sessionManager = this.wasm.createSessionManager();
264
265
  }
265
266
  /**
@@ -278,6 +279,31 @@ var NodeUserAuthorization = class {
278
279
  get nodeFeatures() {
279
280
  return this._nodeFeatures;
280
281
  }
282
+ /**
283
+ * Build SIWE overrides from siweConfig.
284
+ * - statement is prepended to the default statement
285
+ * - resources are appended to the default resources
286
+ * - uri triggers a warning (overwriting delegation target)
287
+ * - all other fields override directly
288
+ */
289
+ buildSiweOverrides() {
290
+ if (!this.siweConfig) return { uri: this.uri };
291
+ const { statement, resources, uri, ...rest } = this.siweConfig;
292
+ const overrides = { uri: this.uri, ...rest };
293
+ if (statement) {
294
+ overrides.statement = this.statement ? `${statement} ${this.statement}` : statement;
295
+ }
296
+ if (resources && resources.length > 0) {
297
+ overrides.resources = resources;
298
+ }
299
+ if (uri) {
300
+ console.warn(
301
+ "[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."
302
+ );
303
+ overrides.uri = uri;
304
+ }
305
+ return overrides;
306
+ }
281
307
  /**
282
308
  * Add an extension to the authorization flow.
283
309
  */
@@ -452,7 +478,8 @@ var NodeUserAuthorization = class {
452
478
  issuedAt: now.toISOString(),
453
479
  expirationTime: expirationTime.toISOString(),
454
480
  spaceId,
455
- jwk
481
+ jwk,
482
+ ...this.buildSiweOverrides()
456
483
  });
457
484
  const signature = await this.requestSignature({
458
485
  address,
@@ -591,7 +618,8 @@ var NodeUserAuthorization = class {
591
618
  issuedAt: now.toISOString(),
592
619
  expirationTime: expirationTime.toISOString(),
593
620
  spaceId,
594
- jwk
621
+ jwk,
622
+ ...this.buildSiweOverrides()
595
623
  });
596
624
  return {
597
625
  prepared,
@@ -1016,25 +1044,29 @@ var TinyCloudNode = class _TinyCloudNode {
1016
1044
  get nodeFeatures() {
1017
1045
  return this.auth?.nodeFeatures ?? [];
1018
1046
  }
1047
+ /** SIWE domain — uses config override or defaults to app.tinycloud.xyz */
1048
+ get siweDomain() {
1049
+ return this.config.domain ?? "app.tinycloud.xyz";
1050
+ }
1019
1051
  /**
1020
1052
  * Set up authorization handler and TinyCloud instance.
1021
1053
  * @internal
1022
1054
  */
1023
1055
  setupAuth(config) {
1024
1056
  const host = this.config.host;
1025
- const domain = config.domain ?? new URL(host).hostname;
1026
1057
  this.auth = new NodeUserAuthorization({
1027
1058
  signer: this.signer,
1028
1059
  signStrategy: { type: "auto-sign" },
1029
1060
  wasmBindings: this.wasmBindings,
1030
1061
  sessionStorage: config.sessionStorage ?? new MemorySessionStorage(),
1031
- domain,
1062
+ domain: this.siweDomain,
1032
1063
  spacePrefix: config.prefix,
1033
1064
  sessionExpirationMs: config.sessionExpirationMs ?? 60 * 60 * 1e3,
1034
1065
  tinycloudHosts: [host],
1035
1066
  autoCreateSpace: config.autoCreateSpace,
1036
1067
  enablePublicSpace: config.enablePublicSpace ?? true,
1037
- spaceCreationHandler: config.spaceCreationHandler
1068
+ spaceCreationHandler: config.spaceCreationHandler,
1069
+ siweConfig: config.siweConfig
1038
1070
  });
1039
1071
  this.tc = new TinyCloud(this.auth);
1040
1072
  }
@@ -1223,7 +1255,6 @@ var TinyCloudNode = class _TinyCloudNode {
1223
1255
  }
1224
1256
  const prefix = options?.prefix ?? "default";
1225
1257
  const host = this.config.host;
1226
- const domain = new URL(host).hostname;
1227
1258
  if (!_TinyCloudNode.nodeDefaults) {
1228
1259
  throw new Error(
1229
1260
  "connectWallet() requires PrivateKeySigner. Use connectSigner() instead, or import from '@tinycloud/node-sdk' (not '/core') for automatic Node.js defaults."
@@ -1235,7 +1266,7 @@ var TinyCloudNode = class _TinyCloudNode {
1235
1266
  signStrategy: { type: "auto-sign" },
1236
1267
  wasmBindings: this.wasmBindings,
1237
1268
  sessionStorage: options?.sessionStorage ?? this.config.sessionStorage ?? new MemorySessionStorage(),
1238
- domain,
1269
+ domain: this.siweDomain,
1239
1270
  spacePrefix: prefix,
1240
1271
  sessionExpirationMs: this.config.sessionExpirationMs ?? 60 * 60 * 1e3,
1241
1272
  tinycloudHosts: [host],
@@ -1265,14 +1296,13 @@ var TinyCloudNode = class _TinyCloudNode {
1265
1296
  }
1266
1297
  const prefix = options?.prefix ?? "default";
1267
1298
  const host = this.config.host;
1268
- const domain = new URL(host).hostname;
1269
1299
  this.signer = signer;
1270
1300
  this.auth = new NodeUserAuthorization({
1271
1301
  signer: this.signer,
1272
1302
  signStrategy: { type: "auto-sign" },
1273
1303
  wasmBindings: this.wasmBindings,
1274
1304
  sessionStorage: options?.sessionStorage ?? this.config.sessionStorage ?? new MemorySessionStorage(),
1275
- domain,
1305
+ domain: this.siweDomain,
1276
1306
  spacePrefix: prefix,
1277
1307
  sessionExpirationMs: this.config.sessionExpirationMs ?? 60 * 60 * 1e3,
1278
1308
  tinycloudHosts: [host],
@@ -1583,7 +1613,7 @@ var TinyCloudNode = class _TinyCloudNode {
1583
1613
  abilities,
1584
1614
  address: this.wasmBindings.ensureEip55(session.address),
1585
1615
  chainId: session.chainId,
1586
- domain: new URL(host).hostname,
1616
+ domain: this.siweDomain,
1587
1617
  issuedAt: now.toISOString(),
1588
1618
  expirationTime: params.requestedExpiry.toISOString(),
1589
1619
  spaceId: params.spaceId,
@@ -1892,7 +1922,7 @@ var TinyCloudNode = class _TinyCloudNode {
1892
1922
  abilities,
1893
1923
  address: this.wasmBindings.ensureEip55(this.session.address),
1894
1924
  chainId: this.session.chainId,
1895
- domain: new URL(this.config.host).hostname,
1925
+ domain: this.siweDomain,
1896
1926
  issuedAt: now.toISOString(),
1897
1927
  expirationTime: expirationTime.toISOString(),
1898
1928
  spaceId: publicSpaceId,
@@ -2059,7 +2089,7 @@ var TinyCloudNode = class _TinyCloudNode {
2059
2089
  abilities,
2060
2090
  address: this.wasmBindings.ensureEip55(session.address),
2061
2091
  chainId: session.chainId,
2062
- domain: new URL(this.config.host).hostname,
2092
+ domain: this.siweDomain,
2063
2093
  issuedAt: now.toISOString(),
2064
2094
  expirationTime: expirationTime.toISOString(),
2065
2095
  spaceId: params.spaceIdOverride ?? session.spaceId,
@@ -2104,7 +2134,7 @@ var TinyCloudNode = class _TinyCloudNode {
2104
2134
  abilities: publicAbilities,
2105
2135
  address: this.wasmBindings.ensureEip55(session.address),
2106
2136
  chainId: session.chainId,
2107
- domain: new URL(this.config.host).hostname,
2137
+ domain: this.siweDomain,
2108
2138
  issuedAt: now.toISOString(),
2109
2139
  expirationTime: expirationTime.toISOString(),
2110
2140
  spaceId: publicSpaceId,
@@ -2203,7 +2233,7 @@ var TinyCloudNode = class _TinyCloudNode {
2203
2233
  abilities,
2204
2234
  address: this.wasmBindings.ensureEip55(mySession.address),
2205
2235
  chainId: mySession.chainId,
2206
- domain: new URL(targetHost).hostname,
2236
+ domain: this.siweDomain,
2207
2237
  issuedAt: now.toISOString(),
2208
2238
  expirationTime: expirationTime.toISOString(),
2209
2239
  spaceId: delegation.spaceId,
@@ -2292,7 +2322,7 @@ var TinyCloudNode = class _TinyCloudNode {
2292
2322
  abilities,
2293
2323
  address: this.wasmBindings.ensureEip55(this._address),
2294
2324
  chainId: this._chainId,
2295
- domain: new URL(targetHost).hostname,
2325
+ domain: this.siweDomain,
2296
2326
  issuedAt: now.toISOString(),
2297
2327
  expirationTime: actualExpiry.toISOString(),
2298
2328
  spaceId: parentDelegation.spaceId,