@tinycloud/node-sdk 1.6.0 → 2.0.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.cjs CHANGED
@@ -17025,55 +17025,92 @@ var require_utils2 = __commonJS({
17025
17025
  // src/index.ts
17026
17026
  var index_exports = {};
17027
17027
  __export(index_exports, {
17028
- CapabilityKeyRegistry: () => import_sdk_core11.CapabilityKeyRegistry,
17029
- CapabilityKeyRegistryErrorCodes: () => import_sdk_core11.CapabilityKeyRegistryErrorCodes,
17030
- DataVaultService: () => import_sdk_core9.DataVaultService,
17031
- DatabaseHandle: () => import_sdk_core7.DatabaseHandle,
17028
+ AutoApproveSpaceCreationHandler: () => import_sdk_core6.AutoApproveSpaceCreationHandler,
17029
+ CapabilityKeyRegistry: () => import_sdk_core12.CapabilityKeyRegistry,
17030
+ CapabilityKeyRegistryErrorCodes: () => import_sdk_core12.CapabilityKeyRegistryErrorCodes,
17031
+ DataVaultService: () => import_sdk_core10.DataVaultService,
17032
+ DatabaseHandle: () => import_sdk_core8.DatabaseHandle,
17032
17033
  DelegatedAccess: () => DelegatedAccess,
17033
- DelegationErrorCodes: () => import_sdk_core10.DelegationErrorCodes,
17034
- DelegationManager: () => import_sdk_core10.DelegationManager,
17035
- DuckDbAction: () => import_sdk_core8.DuckDbAction,
17036
- DuckDbDatabaseHandle: () => import_sdk_core8.DuckDbDatabaseHandle,
17037
- DuckDbService: () => import_sdk_core8.DuckDbService,
17034
+ DelegationErrorCodes: () => import_sdk_core11.DelegationErrorCodes,
17035
+ DelegationManager: () => import_sdk_core11.DelegationManager,
17036
+ DuckDbAction: () => import_sdk_core9.DuckDbAction,
17037
+ DuckDbDatabaseHandle: () => import_sdk_core9.DuckDbDatabaseHandle,
17038
+ DuckDbService: () => import_sdk_core9.DuckDbService,
17038
17039
  FileSessionStorage: () => FileSessionStorage,
17039
- KVService: () => import_sdk_core6.KVService,
17040
+ KVService: () => import_sdk_core7.KVService,
17040
17041
  MemorySessionStorage: () => MemorySessionStorage,
17041
17042
  NodeUserAuthorization: () => NodeUserAuthorization,
17042
- PrefixedKVService: () => import_sdk_core6.PrefixedKVService,
17043
+ NodeWasmBindings: () => NodeWasmBindings,
17044
+ PrefixedKVService: () => import_sdk_core7.PrefixedKVService,
17043
17045
  PrivateKeySigner: () => PrivateKeySigner,
17044
- ProtocolMismatchError: () => import_sdk_core13.ProtocolMismatchError,
17045
- SQLAction: () => import_sdk_core7.SQLAction,
17046
- SQLService: () => import_sdk_core7.SQLService,
17047
- ServiceContext: () => import_sdk_core14.ServiceContext,
17048
- SharingService: () => import_sdk_core10.SharingService,
17049
- Space: () => import_sdk_core12.Space,
17050
- SpaceErrorCodes: () => import_sdk_core12.SpaceErrorCodes,
17051
- SpaceService: () => import_sdk_core12.SpaceService,
17046
+ ProtocolMismatchError: () => import_sdk_core14.ProtocolMismatchError,
17047
+ SQLAction: () => import_sdk_core8.SQLAction,
17048
+ SQLService: () => import_sdk_core8.SQLService,
17049
+ ServiceContext: () => import_sdk_core15.ServiceContext,
17050
+ SharingService: () => import_sdk_core11.SharingService,
17051
+ SilentNotificationHandler: () => import_sdk_core6.SilentNotificationHandler,
17052
+ Space: () => import_sdk_core13.Space,
17053
+ SpaceErrorCodes: () => import_sdk_core13.SpaceErrorCodes,
17054
+ SpaceService: () => import_sdk_core13.SpaceService,
17052
17055
  TinyCloud: () => import_sdk_core5.TinyCloud,
17053
17056
  TinyCloudNode: () => TinyCloudNode,
17054
- UnsupportedFeatureError: () => import_sdk_core13.UnsupportedFeatureError,
17055
- VaultAction: () => import_sdk_core9.VaultAction,
17056
- VaultHeaders: () => import_sdk_core9.VaultHeaders,
17057
- VersionCheckError: () => import_sdk_core13.VersionCheckError,
17057
+ UnsupportedFeatureError: () => import_sdk_core14.UnsupportedFeatureError,
17058
+ VaultHeaders: () => import_sdk_core10.VaultHeaders,
17059
+ VaultPublicSpaceKVActions: () => import_sdk_core10.VaultPublicSpaceKVActions,
17060
+ VersionCheckError: () => import_sdk_core14.VersionCheckError,
17058
17061
  WasmKeyProvider: () => WasmKeyProvider,
17059
- buildSpaceUri: () => import_sdk_core12.buildSpaceUri,
17060
- checkNodeVersion: () => import_sdk_core13.checkNodeVersion,
17061
- createCapabilityKeyRegistry: () => import_sdk_core11.createCapabilityKeyRegistry,
17062
- createSharingService: () => import_sdk_core10.createSharingService,
17063
- createSpaceService: () => import_sdk_core12.createSpaceService,
17064
- createVaultCrypto: () => import_sdk_core9.createVaultCrypto,
17062
+ buildSpaceUri: () => import_sdk_core13.buildSpaceUri,
17063
+ checkNodeInfo: () => import_sdk_core14.checkNodeInfo,
17064
+ createCapabilityKeyRegistry: () => import_sdk_core12.createCapabilityKeyRegistry,
17065
+ createSharingService: () => import_sdk_core11.createSharingService,
17066
+ createSpaceService: () => import_sdk_core13.createSpaceService,
17067
+ createVaultCrypto: () => import_sdk_core10.createVaultCrypto,
17065
17068
  createWasmKeyProvider: () => createWasmKeyProvider,
17066
17069
  defaultSignStrategy: () => defaultSignStrategy,
17070
+ defaultSpaceCreationHandler: () => import_sdk_core6.defaultSpaceCreationHandler,
17067
17071
  deserializeDelegation: () => deserializeDelegation,
17068
- makePublicSpaceId: () => import_sdk_core12.makePublicSpaceId,
17069
- parseSpaceUri: () => import_sdk_core12.parseSpaceUri,
17072
+ makePublicSpaceId: () => import_sdk_core13.makePublicSpaceId,
17073
+ parseSpaceUri: () => import_sdk_core13.parseSpaceUri,
17070
17074
  serializeDelegation: () => serializeDelegation
17071
17075
  });
17072
17076
  module.exports = __toCommonJS(index_exports);
17073
- var import_sdk_core5 = require("@tinycloud/sdk-core");
17074
17077
 
17075
- // src/signers/PrivateKeySigner.ts
17078
+ // src/NodeWasmBindings.ts
17076
17079
  var import_node_sdk_wasm = require("@tinycloud/node-sdk-wasm");
17080
+ var _NodeWasmBindings = class _NodeWasmBindings {
17081
+ constructor() {
17082
+ this.invoke = import_node_sdk_wasm.invoke;
17083
+ this.prepareSession = import_node_sdk_wasm.prepareSession;
17084
+ this.completeSessionSetup = import_node_sdk_wasm.completeSessionSetup;
17085
+ this.ensureEip55 = import_node_sdk_wasm.ensureEip55;
17086
+ this.makeSpaceId = import_node_sdk_wasm.makeSpaceId;
17087
+ this.createDelegation = import_node_sdk_wasm.createDelegation;
17088
+ this.generateHostSIWEMessage = import_node_sdk_wasm.generateHostSIWEMessage;
17089
+ this.siweToDelegationHeaders = import_node_sdk_wasm.siweToDelegationHeaders;
17090
+ this.protocolVersion = import_node_sdk_wasm.protocolVersion;
17091
+ // Vault crypto
17092
+ this.vault_encrypt = import_node_sdk_wasm.vault_encrypt;
17093
+ this.vault_decrypt = import_node_sdk_wasm.vault_decrypt;
17094
+ this.vault_derive_key = import_node_sdk_wasm.vault_derive_key;
17095
+ this.vault_x25519_from_seed = import_node_sdk_wasm.vault_x25519_from_seed;
17096
+ this.vault_x25519_dh = import_node_sdk_wasm.vault_x25519_dh;
17097
+ this.vault_random_bytes = import_node_sdk_wasm.vault_random_bytes;
17098
+ this.vault_sha256 = import_node_sdk_wasm.vault_sha256;
17099
+ if (!_NodeWasmBindings.panicHookInitialized) {
17100
+ (0, import_node_sdk_wasm.initPanicHook)();
17101
+ _NodeWasmBindings.panicHookInitialized = true;
17102
+ }
17103
+ }
17104
+ createSessionManager() {
17105
+ return new import_node_sdk_wasm.TCWSessionManager();
17106
+ }
17107
+ // No ensureInitialized needed — Node WASM is synchronous
17108
+ };
17109
+ _NodeWasmBindings.panicHookInitialized = false;
17110
+ var NodeWasmBindings = _NodeWasmBindings;
17111
+
17112
+ // src/signers/PrivateKeySigner.ts
17113
+ var import_node_sdk_wasm2 = require("@tinycloud/node-sdk-wasm");
17077
17114
  var PrivateKeySigner = class {
17078
17115
  /**
17079
17116
  * Create a new PrivateKeySigner.
@@ -17111,7 +17148,7 @@ var PrivateKeySigner = class {
17111
17148
  const pubKeyWithoutPrefix = publicKey.slice(4);
17112
17149
  const hash3 = keccak2563("0x" + pubKeyWithoutPrefix);
17113
17150
  const address = "0x" + hash3.slice(-40);
17114
- return (0, import_node_sdk_wasm.ensureEip55)(address);
17151
+ return (0, import_node_sdk_wasm2.ensureEip55)(address);
17115
17152
  } catch {
17116
17153
  return "0x" + this.privateKeyHex.slice(0, 40);
17117
17154
  }
@@ -17130,11 +17167,20 @@ var PrivateKeySigner = class {
17130
17167
  */
17131
17168
  async signMessage(message) {
17132
17169
  const messageStr = typeof message === "string" ? message : Buffer.from(message).toString("utf-8");
17133
- const signature2 = (0, import_node_sdk_wasm.signEthereumMessage)(messageStr, this.privateKeyHex);
17170
+ const signature2 = (0, import_node_sdk_wasm2.signEthereumMessage)(messageStr, this.privateKeyHex);
17134
17171
  return signature2.startsWith("0x") ? signature2 : "0x" + signature2;
17135
17172
  }
17136
17173
  };
17137
17174
 
17175
+ // src/TinyCloudNode.ts
17176
+ var import_sdk_core3 = require("@tinycloud/sdk-core");
17177
+
17178
+ // src/authorization/NodeUserAuthorization.ts
17179
+ var import_sdk_core = require("@tinycloud/sdk-core");
17180
+
17181
+ // src/authorization/strategies.ts
17182
+ var defaultSignStrategy = { type: "auto-sign" };
17183
+
17138
17184
  // src/storage/MemorySessionStorage.ts
17139
17185
  var MemorySessionStorage = class {
17140
17186
  constructor() {
@@ -17206,142 +17252,12 @@ var MemorySessionStorage = class {
17206
17252
  }
17207
17253
  };
17208
17254
 
17209
- // src/storage/FileSessionStorage.ts
17210
- var import_sdk_core = require("@tinycloud/sdk-core");
17211
- var import_fs = require("fs");
17212
- var import_path = require("path");
17213
- var FileSessionStorage = class {
17214
- /**
17215
- * Create a new FileSessionStorage.
17216
- *
17217
- * @param baseDir - Directory to store session files (default: ~/.tinycloud/sessions)
17218
- */
17219
- constructor(baseDir) {
17220
- this.baseDir = baseDir || this.getDefaultDir();
17221
- this.ensureDirectoryExists();
17222
- }
17223
- /**
17224
- * Get the default session storage directory.
17225
- */
17226
- getDefaultDir() {
17227
- const home = process.env.HOME || process.env.USERPROFILE || "/tmp";
17228
- return (0, import_path.join)(home, ".tinycloud", "sessions");
17229
- }
17230
- /**
17231
- * Ensure the storage directory exists.
17232
- */
17233
- ensureDirectoryExists() {
17234
- if (!(0, import_fs.existsSync)(this.baseDir)) {
17235
- (0, import_fs.mkdirSync)(this.baseDir, { recursive: true });
17236
- }
17237
- }
17238
- /**
17239
- * Get the file path for an address.
17240
- */
17241
- getFilePath(address) {
17242
- const normalizedAddress = address.toLowerCase();
17243
- const filename = `${normalizedAddress.replace("0x", "")}.json`;
17244
- return (0, import_path.join)(this.baseDir, filename);
17245
- }
17246
- /**
17247
- * Save a session for an address.
17248
- */
17249
- async save(address, session) {
17250
- const filePath = this.getFilePath(address);
17251
- const data = JSON.stringify(session, null, 2);
17252
- (0, import_fs.writeFileSync)(filePath, data, "utf-8");
17253
- }
17254
- /**
17255
- * Load a session for an address.
17256
- */
17257
- async load(address) {
17258
- const filePath = this.getFilePath(address);
17259
- if (!(0, import_fs.existsSync)(filePath)) {
17260
- return null;
17261
- }
17262
- try {
17263
- const data = (0, import_fs.readFileSync)(filePath, "utf-8");
17264
- const parsed = JSON.parse(data);
17265
- const validation = (0, import_sdk_core.validatePersistedSessionData)(parsed);
17266
- if (!validation.ok) {
17267
- console.warn(`Invalid session data for ${address}:`, validation.error.message);
17268
- (0, import_fs.unlinkSync)(filePath);
17269
- return null;
17270
- }
17271
- const session = validation.data;
17272
- const expiresAt = new Date(session.expiresAt);
17273
- if (expiresAt < /* @__PURE__ */ new Date()) {
17274
- (0, import_fs.unlinkSync)(filePath);
17275
- return null;
17276
- }
17277
- return session;
17278
- } catch (error) {
17279
- try {
17280
- (0, import_fs.unlinkSync)(filePath);
17281
- } catch {
17282
- }
17283
- return null;
17284
- }
17285
- }
17286
- /**
17287
- * Clear a session for an address.
17288
- */
17289
- async clear(address) {
17290
- const filePath = this.getFilePath(address);
17291
- if ((0, import_fs.existsSync)(filePath)) {
17292
- (0, import_fs.unlinkSync)(filePath);
17293
- }
17294
- }
17295
- /**
17296
- * Check if a session exists for an address.
17297
- */
17298
- exists(address) {
17299
- const filePath = this.getFilePath(address);
17300
- if (!(0, import_fs.existsSync)(filePath)) {
17301
- return false;
17302
- }
17303
- try {
17304
- const data = (0, import_fs.readFileSync)(filePath, "utf-8");
17305
- const session = JSON.parse(data);
17306
- const expiresAt = new Date(session.expiresAt);
17307
- if (expiresAt < /* @__PURE__ */ new Date()) {
17308
- (0, import_fs.unlinkSync)(filePath);
17309
- return false;
17310
- }
17311
- return true;
17312
- } catch {
17313
- return false;
17314
- }
17315
- }
17316
- /**
17317
- * Check if file system storage is available.
17318
- */
17319
- isAvailable() {
17320
- try {
17321
- this.ensureDirectoryExists();
17322
- return (0, import_fs.existsSync)(this.baseDir);
17323
- } catch {
17324
- return false;
17325
- }
17326
- }
17327
- };
17328
-
17329
17255
  // src/authorization/NodeUserAuthorization.ts
17330
- var import_sdk_core2 = require("@tinycloud/sdk-core");
17331
- var import_node_sdk_wasm2 = require("@tinycloud/node-sdk-wasm");
17332
-
17333
- // src/authorization/strategies.ts
17334
- var defaultSignStrategy = { type: "auto-sign" };
17335
-
17336
- // src/authorization/NodeUserAuthorization.ts
17337
- var _NodeUserAuthorization = class _NodeUserAuthorization {
17256
+ var NodeUserAuthorization = class {
17338
17257
  constructor(config) {
17339
17258
  this.extensions = [];
17340
17259
  this._nodeFeatures = [];
17341
- if (!_NodeUserAuthorization.wasmInitialized) {
17342
- (0, import_node_sdk_wasm2.initPanicHook)();
17343
- _NodeUserAuthorization.wasmInitialized = true;
17344
- }
17260
+ this.wasm = config.wasmBindings;
17345
17261
  this.signer = config.signer;
17346
17262
  this.signStrategy = config.signStrategy ?? defaultSignStrategy;
17347
17263
  this.sessionStorage = config.sessionStorage ?? new MemorySessionStorage();
@@ -17384,9 +17300,10 @@ var _NodeUserAuthorization = class _NodeUserAuthorization {
17384
17300
  };
17385
17301
  this.sessionExpirationMs = config.sessionExpirationMs ?? 60 * 60 * 1e3;
17386
17302
  this.autoCreateSpace = config.autoCreateSpace ?? false;
17303
+ this.spaceCreationHandler = config.spaceCreationHandler;
17387
17304
  this.tinycloudHosts = config.tinycloudHosts ?? ["https://node.tinycloud.xyz"];
17388
17305
  this.enablePublicSpace = config.enablePublicSpace ?? true;
17389
- this.sessionManager = new import_node_sdk_wasm2.TCWSessionManager();
17306
+ this.sessionManager = this.wasm.createSessionManager();
17390
17307
  }
17391
17308
  /**
17392
17309
  * The current active session (web-core compatible).
@@ -17426,8 +17343,8 @@ var _NodeUserAuthorization = class _NodeUserAuthorization {
17426
17343
  }
17427
17344
  const host = this.tinycloudHosts[0];
17428
17345
  const spaceId = targetSpaceId ?? this._tinyCloudSession.spaceId;
17429
- const peerId = await (0, import_sdk_core2.fetchPeerId)(host, spaceId);
17430
- const siwe = (0, import_node_sdk_wasm2.generateHostSIWEMessage)({
17346
+ const peerId = await (0, import_sdk_core.fetchPeerId)(host, spaceId);
17347
+ const siwe = this.wasm.generateHostSIWEMessage({
17431
17348
  address: this._address,
17432
17349
  chainId: this._chainId,
17433
17350
  domain: this.domain,
@@ -17436,8 +17353,8 @@ var _NodeUserAuthorization = class _NodeUserAuthorization {
17436
17353
  peerId
17437
17354
  });
17438
17355
  const signature2 = await this.signMessage(siwe);
17439
- const headers = (0, import_node_sdk_wasm2.siweToDelegationHeaders)({ siwe, signature: signature2 });
17440
- const result = await (0, import_sdk_core2.submitHostDelegation)(host, headers);
17356
+ const headers = this.wasm.siweToDelegationHeaders({ siwe, signature: signature2 });
17357
+ const result = await (0, import_sdk_core.submitHostDelegation)(host, headers);
17441
17358
  return result.success;
17442
17359
  }
17443
17360
  /**
@@ -17461,52 +17378,87 @@ var _NodeUserAuthorization = class _NodeUserAuthorization {
17461
17378
  }
17462
17379
  const host = this.tinycloudHosts[0];
17463
17380
  const primarySpaceId = this._tinyCloudSession.spaceId;
17464
- const result = await (0, import_sdk_core2.activateSessionWithHost)(
17381
+ const result = await (0, import_sdk_core.activateSessionWithHost)(
17465
17382
  host,
17466
17383
  this._tinyCloudSession.delegationHeader
17467
17384
  );
17385
+ const handler = this.spaceCreationHandler ?? (this.autoCreateSpace ? new import_sdk_core.AutoApproveSpaceCreationHandler() : void 0);
17386
+ const creationContext = {
17387
+ spaceId: primarySpaceId,
17388
+ address: this._address,
17389
+ chainId: this._chainId,
17390
+ host
17391
+ };
17468
17392
  if (result.success) {
17469
17393
  const primarySkipped = result.skipped?.includes(primarySpaceId);
17470
17394
  if (!primarySkipped) {
17471
17395
  return;
17472
17396
  }
17473
- if (!this.autoCreateSpace) {
17397
+ if (!handler) {
17398
+ return;
17399
+ }
17400
+ const confirmed = await handler.confirmSpaceCreation(creationContext);
17401
+ if (!confirmed) {
17474
17402
  return;
17475
17403
  }
17476
- const created = await this.hostSpace();
17477
- if (!created) {
17478
- throw new Error(`Failed to create space: ${primarySpaceId}`);
17404
+ try {
17405
+ const created = await this.hostSpace();
17406
+ if (!created) {
17407
+ const err = new Error(`Failed to create space: ${primarySpaceId}`);
17408
+ handler.onSpaceCreationFailed?.(creationContext, err);
17409
+ throw err;
17410
+ }
17411
+ } catch (error) {
17412
+ handler.onSpaceCreationFailed?.(creationContext, error instanceof Error ? error : new Error(String(error)));
17413
+ throw error;
17479
17414
  }
17480
17415
  await new Promise((resolve) => setTimeout(resolve, 100));
17481
- const retryResult = await (0, import_sdk_core2.activateSessionWithHost)(
17416
+ const retryResult = await (0, import_sdk_core.activateSessionWithHost)(
17482
17417
  host,
17483
17418
  this._tinyCloudSession.delegationHeader
17484
17419
  );
17485
17420
  if (!retryResult.success) {
17486
- throw new Error(
17421
+ const err = new Error(
17487
17422
  `Failed to activate session after creating space: ${retryResult.error}`
17488
17423
  );
17424
+ handler.onSpaceCreationFailed?.(creationContext, err);
17425
+ throw err;
17489
17426
  }
17427
+ handler.onSpaceCreated?.(creationContext);
17490
17428
  return;
17491
17429
  }
17492
17430
  if (result.status === 404) {
17493
- if (!this.autoCreateSpace) {
17431
+ if (!handler) {
17494
17432
  return;
17495
17433
  }
17496
- const created = await this.hostSpace();
17497
- if (!created) {
17498
- throw new Error(`Failed to create space: ${primarySpaceId}`);
17434
+ const confirmed = await handler.confirmSpaceCreation(creationContext);
17435
+ if (!confirmed) {
17436
+ return;
17437
+ }
17438
+ try {
17439
+ const created = await this.hostSpace();
17440
+ if (!created) {
17441
+ const err = new Error(`Failed to create space: ${primarySpaceId}`);
17442
+ handler.onSpaceCreationFailed?.(creationContext, err);
17443
+ throw err;
17444
+ }
17445
+ } catch (error) {
17446
+ handler.onSpaceCreationFailed?.(creationContext, error instanceof Error ? error : new Error(String(error)));
17447
+ throw error;
17499
17448
  }
17500
17449
  await new Promise((resolve) => setTimeout(resolve, 100));
17501
- const retryResult = await (0, import_sdk_core2.activateSessionWithHost)(
17450
+ const retryResult = await (0, import_sdk_core.activateSessionWithHost)(
17502
17451
  host,
17503
17452
  this._tinyCloudSession.delegationHeader
17504
17453
  );
17505
17454
  if (!retryResult.success) {
17506
- throw new Error(
17455
+ const err = new Error(
17507
17456
  `Failed to activate session after creating space: ${retryResult.error}`
17508
17457
  );
17458
+ handler.onSpaceCreationFailed?.(creationContext, err);
17459
+ throw err;
17509
17460
  }
17461
+ handler.onSpaceCreated?.(creationContext);
17510
17462
  return;
17511
17463
  }
17512
17464
  throw new Error(`Failed to activate session: ${result.error}`);
@@ -17523,7 +17475,7 @@ var _NodeUserAuthorization = class _NodeUserAuthorization {
17523
17475
  async signIn() {
17524
17476
  this._address = await this.signer.getAddress();
17525
17477
  this._chainId = await this.signer.getChainId();
17526
- const address = (0, import_node_sdk_wasm2.ensureEip55)(this._address);
17478
+ const address = this.wasm.ensureEip55(this._address);
17527
17479
  const chainId = this._chainId;
17528
17480
  const keyId = `session-${Date.now()}`;
17529
17481
  this.sessionManager.renameSessionKeyId("default", keyId);
@@ -17532,10 +17484,10 @@ var _NodeUserAuthorization = class _NodeUserAuthorization {
17532
17484
  throw new Error("Failed to create session key");
17533
17485
  }
17534
17486
  const jwk = JSON.parse(jwkString);
17535
- const spaceId = (0, import_node_sdk_wasm2.makeSpaceId)(address, chainId, this.spacePrefix);
17487
+ const spaceId = this.wasm.makeSpaceId(address, chainId, this.spacePrefix);
17536
17488
  const now = /* @__PURE__ */ new Date();
17537
17489
  const expirationTime = new Date(now.getTime() + this.sessionExpirationMs);
17538
- const prepared = (0, import_node_sdk_wasm2.prepareSession)({
17490
+ const prepared = this.wasm.prepareSession({
17539
17491
  abilities: this.defaultActions,
17540
17492
  address,
17541
17493
  chainId,
@@ -17551,7 +17503,7 @@ var _NodeUserAuthorization = class _NodeUserAuthorization {
17551
17503
  message: prepared.siwe,
17552
17504
  type: "siwe"
17553
17505
  });
17554
- const session = (0, import_node_sdk_wasm2.completeSessionSetup)({
17506
+ const session = this.wasm.completeSessionSetup({
17555
17507
  ...prepared,
17556
17508
  signature: signature2
17557
17509
  });
@@ -17563,7 +17515,7 @@ var _NodeUserAuthorization = class _NodeUserAuthorization {
17563
17515
  siwe: prepared.siwe,
17564
17516
  signature: signature2
17565
17517
  };
17566
- const spacesMetadata = this.enablePublicSpace ? { public: (0, import_node_sdk_wasm2.makeSpaceId)(address, chainId, "public") } : void 0;
17518
+ const spacesMetadata = this.enablePublicSpace ? { public: this.wasm.makeSpaceId(address, chainId, "public") } : void 0;
17567
17519
  const tinyCloudSession = {
17568
17520
  address,
17569
17521
  chainId,
@@ -17599,7 +17551,8 @@ var _NodeUserAuthorization = class _NodeUserAuthorization {
17599
17551
  this._tinyCloudSession = tinyCloudSession;
17600
17552
  this._address = address;
17601
17553
  this._chainId = chainId;
17602
- this._nodeFeatures = await (0, import_sdk_core2.checkNodeVersion)(this.tinycloudHosts[0], (0, import_node_sdk_wasm2.protocolVersion)());
17554
+ const nodeInfo = await (0, import_sdk_core.checkNodeInfo)(this.tinycloudHosts[0], this.wasm.protocolVersion());
17555
+ this._nodeFeatures = nodeInfo.features;
17603
17556
  for (const ext of this.extensions) {
17604
17557
  if (ext.afterSignIn) {
17605
17558
  await ext.afterSignIn(clientSession);
@@ -17661,7 +17614,7 @@ var _NodeUserAuthorization = class _NodeUserAuthorization {
17661
17614
  * ```
17662
17615
  */
17663
17616
  async prepareSessionForSigning() {
17664
- const address = (0, import_node_sdk_wasm2.ensureEip55)(await this.signer.getAddress());
17617
+ const address = this.wasm.ensureEip55(await this.signer.getAddress());
17665
17618
  const chainId = await this.signer.getChainId();
17666
17619
  const keyId = `session-${Date.now()}`;
17667
17620
  this.sessionManager.renameSessionKeyId("default", keyId);
@@ -17670,10 +17623,10 @@ var _NodeUserAuthorization = class _NodeUserAuthorization {
17670
17623
  throw new Error("Failed to create session key");
17671
17624
  }
17672
17625
  const jwk = JSON.parse(jwkString);
17673
- const spaceId = (0, import_node_sdk_wasm2.makeSpaceId)(address, chainId, this.spacePrefix);
17626
+ const spaceId = this.wasm.makeSpaceId(address, chainId, this.spacePrefix);
17674
17627
  const now = /* @__PURE__ */ new Date();
17675
17628
  const expirationTime = new Date(now.getTime() + this.sessionExpirationMs);
17676
- const prepared = (0, import_node_sdk_wasm2.prepareSession)({
17629
+ const prepared = this.wasm.prepareSession({
17677
17630
  abilities: this.defaultActions,
17678
17631
  address,
17679
17632
  chainId,
@@ -17703,11 +17656,11 @@ var _NodeUserAuthorization = class _NodeUserAuthorization {
17703
17656
  * @param jwk - The JWK from `prepareSessionForSigning()`
17704
17657
  */
17705
17658
  async signInWithPreparedSession(prepared, signature2, keyId, jwk) {
17706
- const session = (0, import_node_sdk_wasm2.completeSessionSetup)({
17659
+ const session = this.wasm.completeSessionSetup({
17707
17660
  ...prepared,
17708
17661
  signature: signature2
17709
17662
  });
17710
- const address = (0, import_node_sdk_wasm2.ensureEip55)(await this.signer.getAddress());
17663
+ const address = this.wasm.ensureEip55(await this.signer.getAddress());
17711
17664
  const chainId = await this.signer.getChainId();
17712
17665
  const clientSession = {
17713
17666
  address,
@@ -17717,7 +17670,7 @@ var _NodeUserAuthorization = class _NodeUserAuthorization {
17717
17670
  siwe: prepared.siwe,
17718
17671
  signature: signature2
17719
17672
  };
17720
- const spacesMetadata = this.enablePublicSpace ? { public: (0, import_node_sdk_wasm2.makeSpaceId)(address, chainId, "public") } : void 0;
17673
+ const spacesMetadata = this.enablePublicSpace ? { public: this.wasm.makeSpaceId(address, chainId, "public") } : void 0;
17721
17674
  const tinyCloudSession = {
17722
17675
  address,
17723
17676
  chainId,
@@ -17757,7 +17710,8 @@ var _NodeUserAuthorization = class _NodeUserAuthorization {
17757
17710
  this._tinyCloudSession = tinyCloudSession;
17758
17711
  this._address = address;
17759
17712
  this._chainId = chainId;
17760
- this._nodeFeatures = await (0, import_sdk_core2.checkNodeVersion)(this.tinycloudHosts[0], (0, import_node_sdk_wasm2.protocolVersion)());
17713
+ const nodeInfo = await (0, import_sdk_core.checkNodeInfo)(this.tinycloudHosts[0], this.wasm.protocolVersion());
17714
+ this._nodeFeatures = nodeInfo.features;
17761
17715
  for (const ext of this.extensions) {
17762
17716
  if (ext.afterSignIn) {
17763
17717
  await ext.afterSignIn(clientSession);
@@ -17833,35 +17787,27 @@ var _NodeUserAuthorization = class _NodeUserAuthorization {
17833
17787
  });
17834
17788
  }
17835
17789
  };
17836
- /** Flag to ensure WASM panic hook is only initialized once */
17837
- _NodeUserAuthorization.wasmInitialized = false;
17838
- var NodeUserAuthorization = _NodeUserAuthorization;
17839
-
17840
- // src/TinyCloudNode.ts
17841
- var import_sdk_core4 = require("@tinycloud/sdk-core");
17842
- var import_node_sdk_wasm4 = require("@tinycloud/node-sdk-wasm");
17843
17790
 
17844
17791
  // src/DelegatedAccess.ts
17845
- var import_sdk_core3 = require("@tinycloud/sdk-core");
17846
- var import_node_sdk_wasm3 = require("@tinycloud/node-sdk-wasm");
17792
+ var import_sdk_core2 = require("@tinycloud/sdk-core");
17847
17793
  var DelegatedAccess = class {
17848
- constructor(session, delegation, host) {
17794
+ constructor(session, delegation, host, invoke2) {
17849
17795
  this.session = session;
17850
17796
  this._delegation = delegation;
17851
17797
  this.host = host;
17852
- this._serviceContext = new import_sdk_core3.ServiceContext({
17853
- invoke: import_node_sdk_wasm3.invoke,
17798
+ this._serviceContext = new import_sdk_core2.ServiceContext({
17799
+ invoke: invoke2,
17854
17800
  fetch: globalThis.fetch.bind(globalThis),
17855
17801
  hosts: [host]
17856
17802
  });
17857
17803
  const prefix = this._delegation.path.replace(/\/$/, "");
17858
- this._kv = new import_sdk_core3.KVService({ prefix });
17804
+ this._kv = new import_sdk_core2.KVService({ prefix });
17859
17805
  this._kv.initialize(this._serviceContext);
17860
17806
  this._serviceContext.registerService("kv", this._kv);
17861
- this._sql = new import_sdk_core3.SQLService({});
17807
+ this._sql = new import_sdk_core2.SQLService({});
17862
17808
  this._sql.initialize(this._serviceContext);
17863
17809
  this._serviceContext.registerService("sql", this._sql);
17864
- this._duckdb = new import_sdk_core3.DuckDbService({});
17810
+ this._duckdb = new import_sdk_core2.DuckDbService({});
17865
17811
  this._duckdb.initialize(this._serviceContext);
17866
17812
  this._serviceContext.registerService("duckdb", this._duckdb);
17867
17813
  const serviceSession = {
@@ -17968,7 +17914,7 @@ var WasmKeyProvider = class {
17968
17914
  * @returns Array of key IDs
17969
17915
  */
17970
17916
  listKeys() {
17971
- const keys = this.sessionManager.listSessionKeys();
17917
+ const keys = this.sessionManager.listSessionKeys?.();
17972
17918
  return Array.isArray(keys) ? keys : [];
17973
17919
  }
17974
17920
  /**
@@ -17988,7 +17934,7 @@ function createWasmKeyProvider(sessionManager) {
17988
17934
 
17989
17935
  // src/TinyCloudNode.ts
17990
17936
  var DEFAULT_HOST = "https://node.tinycloud.xyz";
17991
- var _TinyCloudNode = class _TinyCloudNode {
17937
+ var TinyCloudNode = class _TinyCloudNode {
17992
17938
  /**
17993
17939
  * Create a new TinyCloudNode instance.
17994
17940
  *
@@ -18017,15 +17963,20 @@ var _TinyCloudNode = class _TinyCloudNode {
18017
17963
  this.auth = null;
18018
17964
  this.tc = null;
18019
17965
  this._chainId = 1;
18020
- if (!_TinyCloudNode.wasmInitialized) {
18021
- (0, import_node_sdk_wasm4.initPanicHook)();
18022
- _TinyCloudNode.wasmInitialized = true;
18023
- }
18024
17966
  this.config = {
18025
17967
  ...config,
18026
17968
  host: config.host ?? DEFAULT_HOST
18027
17969
  };
18028
- this.sessionManager = new import_node_sdk_wasm4.TCWSessionManager();
17970
+ if (config.wasmBindings) {
17971
+ this.wasmBindings = config.wasmBindings;
17972
+ } else if (_TinyCloudNode.nodeDefaults) {
17973
+ this.wasmBindings = _TinyCloudNode.nodeDefaults.createWasmBindings();
17974
+ } else {
17975
+ throw new Error(
17976
+ "wasmBindings must be provided in config. Import from '@tinycloud/node-sdk' (not '/core') for automatic Node.js defaults."
17977
+ );
17978
+ }
17979
+ this.sessionManager = this.wasmBindings.createSessionManager();
18029
17980
  const defaultKeyId = "default";
18030
17981
  let jwkStr = this.sessionManager.jwk(defaultKeyId);
18031
17982
  if (jwkStr) {
@@ -18038,22 +17989,23 @@ var _TinyCloudNode = class _TinyCloudNode {
18038
17989
  throw new Error("Failed to get session key JWK");
18039
17990
  }
18040
17991
  this.sessionKeyJwk = JSON.parse(jwkStr);
18041
- this._capabilityRegistry = new import_sdk_core4.CapabilityKeyRegistry();
17992
+ this._capabilityRegistry = new import_sdk_core3.CapabilityKeyRegistry();
18042
17993
  this._keyProvider = new WasmKeyProvider({
18043
17994
  sessionManager: this.sessionManager
18044
17995
  });
18045
- this._sharingService = new import_sdk_core4.SharingService({
17996
+ this.notificationHandler = config.notificationHandler ?? new import_sdk_core3.SilentNotificationHandler();
17997
+ this._sharingService = new import_sdk_core3.SharingService({
18046
17998
  hosts: [this.config.host],
18047
17999
  // session: undefined - not needed for receive()
18048
- invoke: import_node_sdk_wasm4.invoke,
18000
+ invoke: this.wasmBindings.invoke,
18049
18001
  fetch: globalThis.fetch.bind(globalThis),
18050
18002
  keyProvider: this._keyProvider,
18051
18003
  registry: this._capabilityRegistry,
18052
18004
  // delegationManager: undefined - not needed for receive()
18053
18005
  createKVService: (config2) => {
18054
18006
  const prefix = config2.pathPrefix?.replace(/\/$/, "");
18055
- const kvService = new import_sdk_core4.KVService({ prefix });
18056
- const kvContext = new import_sdk_core4.ServiceContext({
18007
+ const kvService = new import_sdk_core3.KVService({ prefix });
18008
+ const kvContext = new import_sdk_core3.ServiceContext({
18057
18009
  invoke: config2.invoke,
18058
18010
  fetch: config2.fetch ?? globalThis.fetch.bind(globalThis),
18059
18011
  hosts: config2.hosts
@@ -18063,27 +18015,48 @@ var _TinyCloudNode = class _TinyCloudNode {
18063
18015
  return kvService;
18064
18016
  }
18065
18017
  });
18066
- if (config.privateKey) {
18067
- this.signer = new PrivateKeySigner(config.privateKey, this._chainId);
18068
- const host = this.config.host;
18069
- const domain = config.domain ?? new URL(host).hostname;
18070
- this.auth = new NodeUserAuthorization({
18071
- signer: this.signer,
18072
- signStrategy: { type: "auto-sign" },
18073
- sessionStorage: config.sessionStorage ?? new MemorySessionStorage(),
18074
- domain,
18075
- spacePrefix: config.prefix,
18076
- sessionExpirationMs: config.sessionExpirationMs ?? 60 * 60 * 1e3,
18077
- tinycloudHosts: [host],
18078
- autoCreateSpace: config.autoCreateSpace,
18079
- enablePublicSpace: config.enablePublicSpace ?? true
18080
- });
18081
- this.tc = new import_sdk_core4.TinyCloud(this.auth);
18018
+ if (config.signer) {
18019
+ this.signer = config.signer;
18020
+ this.setupAuth(config);
18021
+ } else if (config.privateKey) {
18022
+ if (!_TinyCloudNode.nodeDefaults) {
18023
+ throw new Error(
18024
+ "privateKey requires PrivateKeySigner. Either provide a signer in config, or import from '@tinycloud/node-sdk' (not '/core') for automatic Node.js defaults."
18025
+ );
18026
+ }
18027
+ this.signer = _TinyCloudNode.nodeDefaults.createSigner(config.privateKey, this._chainId);
18028
+ this.setupAuth(config);
18082
18029
  }
18083
18030
  }
18031
+ /** @internal Register Node.js-specific defaults (NodeWasmBindings, PrivateKeySigner) */
18032
+ static registerNodeDefaults(defaults) {
18033
+ _TinyCloudNode.nodeDefaults = defaults;
18034
+ }
18084
18035
  get nodeFeatures() {
18085
18036
  return this.auth?.nodeFeatures ?? [];
18086
18037
  }
18038
+ /**
18039
+ * Set up authorization handler and TinyCloud instance.
18040
+ * @internal
18041
+ */
18042
+ setupAuth(config) {
18043
+ const host = this.config.host;
18044
+ const domain = config.domain ?? new URL(host).hostname;
18045
+ this.auth = new NodeUserAuthorization({
18046
+ signer: this.signer,
18047
+ signStrategy: { type: "auto-sign" },
18048
+ wasmBindings: this.wasmBindings,
18049
+ sessionStorage: config.sessionStorage ?? new MemorySessionStorage(),
18050
+ domain,
18051
+ spacePrefix: config.prefix,
18052
+ sessionExpirationMs: config.sessionExpirationMs ?? 60 * 60 * 1e3,
18053
+ tinycloudHosts: [host],
18054
+ autoCreateSpace: config.autoCreateSpace,
18055
+ enablePublicSpace: config.enablePublicSpace ?? true,
18056
+ spaceCreationHandler: config.spaceCreationHandler
18057
+ });
18058
+ this.tc = new import_sdk_core3.TinyCloud(this.auth);
18059
+ }
18087
18060
  /**
18088
18061
  * Get the primary identity DID for this user.
18089
18062
  * - If wallet connected and signed in: returns PKH DID (did:pkh:eip155:{chainId}:{address})
@@ -18145,6 +18118,7 @@ var _TinyCloudNode = class _TinyCloudNode {
18145
18118
  "Cannot signIn() in session-only mode. Provide a privateKey in config to create your own space."
18146
18119
  );
18147
18120
  }
18121
+ await this.wasmBindings.ensureInitialized?.();
18148
18122
  this._address = await this.signer.getAddress();
18149
18123
  this._chainId = await this.signer.getChainId();
18150
18124
  this._kv = void 0;
@@ -18153,6 +18127,7 @@ var _TinyCloudNode = class _TinyCloudNode {
18153
18127
  this._serviceContext = void 0;
18154
18128
  await this.tc.signIn();
18155
18129
  this.initializeServices();
18130
+ this.notificationHandler.success("Successfully signed in");
18156
18131
  }
18157
18132
  /**
18158
18133
  * Restore a previously established session from stored delegation data.
@@ -18164,6 +18139,7 @@ var _TinyCloudNode = class _TinyCloudNode {
18164
18139
  * @param sessionData - The stored delegation data from the browser flow
18165
18140
  */
18166
18141
  async restoreSession(sessionData) {
18142
+ await this.wasmBindings.ensureInitialized?.();
18167
18143
  this._kv = void 0;
18168
18144
  this._sql = void 0;
18169
18145
  this._duckdb = void 0;
@@ -18174,18 +18150,18 @@ var _TinyCloudNode = class _TinyCloudNode {
18174
18150
  if (sessionData.chainId) {
18175
18151
  this._chainId = sessionData.chainId;
18176
18152
  }
18177
- this._serviceContext = new import_sdk_core4.ServiceContext({
18178
- invoke: import_node_sdk_wasm4.invoke,
18153
+ this._serviceContext = new import_sdk_core3.ServiceContext({
18154
+ invoke: this.wasmBindings.invoke,
18179
18155
  fetch: globalThis.fetch.bind(globalThis),
18180
18156
  hosts: [this.config.host]
18181
18157
  });
18182
- this._kv = new import_sdk_core4.KVService({});
18158
+ this._kv = new import_sdk_core3.KVService({});
18183
18159
  this._kv.initialize(this._serviceContext);
18184
18160
  this._serviceContext.registerService("kv", this._kv);
18185
- this._sql = new import_sdk_core4.SQLService({});
18161
+ this._sql = new import_sdk_core3.SQLService({});
18186
18162
  this._sql.initialize(this._serviceContext);
18187
18163
  this._serviceContext.registerService("sql", this._sql);
18188
- this._duckdb = new import_sdk_core4.DuckDbService({});
18164
+ this._duckdb = new import_sdk_core3.DuckDbService({});
18189
18165
  this._duckdb.initialize(this._serviceContext);
18190
18166
  this._serviceContext.registerService("duckdb", this._duckdb);
18191
18167
  const serviceSession = {
@@ -18196,6 +18172,43 @@ var _TinyCloudNode = class _TinyCloudNode {
18196
18172
  jwk: sessionData.jwk
18197
18173
  };
18198
18174
  this._serviceContext.setSession(serviceSession);
18175
+ const wasm = this.wasmBindings;
18176
+ const vaultCrypto = (0, import_sdk_core3.createVaultCrypto)({
18177
+ vault_encrypt: wasm.vault_encrypt,
18178
+ vault_decrypt: wasm.vault_decrypt,
18179
+ vault_derive_key: wasm.vault_derive_key,
18180
+ vault_x25519_from_seed: wasm.vault_x25519_from_seed,
18181
+ vault_x25519_dh: wasm.vault_x25519_dh,
18182
+ vault_random_bytes: wasm.vault_random_bytes,
18183
+ vault_sha256: wasm.vault_sha256
18184
+ });
18185
+ const self2 = this;
18186
+ this._vault = new import_sdk_core3.DataVaultService({
18187
+ spaceId: sessionData.spaceId,
18188
+ crypto: vaultCrypto,
18189
+ tc: {
18190
+ kv: this._kv,
18191
+ ensurePublicSpace: async () => {
18192
+ try {
18193
+ await self2.ensurePublicSpace();
18194
+ return { ok: true, data: void 0 };
18195
+ } catch (error) {
18196
+ return { ok: false, error: { code: "STORAGE_ERROR", message: error instanceof Error ? error.message : String(error), service: "vault" } };
18197
+ }
18198
+ },
18199
+ get publicKV() {
18200
+ return self2._publicKV ?? self2.tc.publicKV;
18201
+ },
18202
+ readPublicSpace: (host, spaceId, key2) => import_sdk_core3.TinyCloud.readPublicSpace(host, spaceId, key2),
18203
+ makePublicSpaceId: import_sdk_core3.TinyCloud.makePublicSpaceId,
18204
+ did: this.did,
18205
+ address: sessionData.address ?? this._address ?? "",
18206
+ chainId: sessionData.chainId ?? this._chainId,
18207
+ hosts: [this.config.host]
18208
+ }
18209
+ });
18210
+ this._vault.initialize(this._serviceContext);
18211
+ this._serviceContext.registerService("vault", this._vault);
18199
18212
  this.initializeV2Services(serviceSession);
18200
18213
  }
18201
18214
  /**
@@ -18230,19 +18243,63 @@ var _TinyCloudNode = class _TinyCloudNode {
18230
18243
  const prefix = options?.prefix ?? "default";
18231
18244
  const host = this.config.host;
18232
18245
  const domain = new URL(host).hostname;
18233
- this.signer = new PrivateKeySigner(privateKey);
18246
+ if (!_TinyCloudNode.nodeDefaults) {
18247
+ throw new Error(
18248
+ "connectWallet() requires PrivateKeySigner. Use connectSigner() instead, or import from '@tinycloud/node-sdk' (not '/core') for automatic Node.js defaults."
18249
+ );
18250
+ }
18251
+ this.signer = _TinyCloudNode.nodeDefaults.createSigner(privateKey);
18234
18252
  this.auth = new NodeUserAuthorization({
18235
18253
  signer: this.signer,
18236
18254
  signStrategy: { type: "auto-sign" },
18255
+ wasmBindings: this.wasmBindings,
18237
18256
  sessionStorage: options?.sessionStorage ?? this.config.sessionStorage ?? new MemorySessionStorage(),
18238
18257
  domain,
18239
18258
  spacePrefix: prefix,
18240
18259
  sessionExpirationMs: this.config.sessionExpirationMs ?? 60 * 60 * 1e3,
18241
18260
  tinycloudHosts: [host],
18242
18261
  autoCreateSpace: this.config.autoCreateSpace,
18243
- enablePublicSpace: this.config.enablePublicSpace ?? true
18262
+ enablePublicSpace: this.config.enablePublicSpace ?? true,
18263
+ spaceCreationHandler: this.config.spaceCreationHandler
18244
18264
  });
18245
- this.tc = new import_sdk_core4.TinyCloud(this.auth);
18265
+ this.tc = new import_sdk_core3.TinyCloud(this.auth);
18266
+ this.config.prefix = prefix;
18267
+ }
18268
+ /**
18269
+ * Connect any ISigner to upgrade from session-only mode to wallet mode.
18270
+ *
18271
+ * Same as connectWallet() but accepts any ISigner implementation instead
18272
+ * of a raw private key string. Use this for browser wallets, hardware wallets,
18273
+ * or custom signing backends.
18274
+ *
18275
+ * Note: This does NOT automatically sign in. Call signIn() after connecting.
18276
+ *
18277
+ * @param signer - Any ISigner implementation
18278
+ * @param options - Optional configuration
18279
+ * @param options.prefix - Space name prefix (defaults to "default")
18280
+ */
18281
+ connectSigner(signer, options) {
18282
+ if (this.signer) {
18283
+ throw new Error("Signer already connected. Cannot connect another signer.");
18284
+ }
18285
+ const prefix = options?.prefix ?? "default";
18286
+ const host = this.config.host;
18287
+ const domain = new URL(host).hostname;
18288
+ this.signer = signer;
18289
+ this.auth = new NodeUserAuthorization({
18290
+ signer: this.signer,
18291
+ signStrategy: { type: "auto-sign" },
18292
+ wasmBindings: this.wasmBindings,
18293
+ sessionStorage: options?.sessionStorage ?? this.config.sessionStorage ?? new MemorySessionStorage(),
18294
+ domain,
18295
+ spacePrefix: prefix,
18296
+ sessionExpirationMs: this.config.sessionExpirationMs ?? 60 * 60 * 1e3,
18297
+ tinycloudHosts: [host],
18298
+ autoCreateSpace: this.config.autoCreateSpace,
18299
+ enablePublicSpace: this.config.enablePublicSpace ?? true,
18300
+ spaceCreationHandler: this.config.spaceCreationHandler
18301
+ });
18302
+ this.tc = new import_sdk_core3.TinyCloud(this.auth);
18246
18303
  this.config.prefix = prefix;
18247
18304
  }
18248
18305
  /**
@@ -18254,23 +18311,23 @@ var _TinyCloudNode = class _TinyCloudNode {
18254
18311
  if (!session) {
18255
18312
  return;
18256
18313
  }
18257
- this.tc.initializeServices(import_node_sdk_wasm4.invoke, [this.config.host]);
18258
- this._serviceContext = new import_sdk_core4.ServiceContext({
18259
- invoke: import_node_sdk_wasm4.invoke,
18314
+ this.tc.initializeServices(this.wasmBindings.invoke, [this.config.host]);
18315
+ this._serviceContext = new import_sdk_core3.ServiceContext({
18316
+ invoke: this.wasmBindings.invoke,
18260
18317
  fetch: globalThis.fetch.bind(globalThis),
18261
18318
  hosts: [this.config.host]
18262
18319
  });
18263
- this._kv = new import_sdk_core4.KVService({});
18320
+ this._kv = new import_sdk_core3.KVService({});
18264
18321
  this._kv.initialize(this._serviceContext);
18265
18322
  this._serviceContext.registerService("kv", this._kv);
18266
18323
  const features = this.nodeFeatures;
18267
18324
  if (features.length === 0 || features.includes("sql")) {
18268
- this._sql = new import_sdk_core4.SQLService({});
18325
+ this._sql = new import_sdk_core3.SQLService({});
18269
18326
  this._sql.initialize(this._serviceContext);
18270
18327
  this._serviceContext.registerService("sql", this._sql);
18271
18328
  }
18272
18329
  if (features.length === 0 || features.includes("duckdb")) {
18273
- this._duckdb = new import_sdk_core4.DuckDbService({});
18330
+ this._duckdb = new import_sdk_core3.DuckDbService({});
18274
18331
  this._duckdb.initialize(this._serviceContext);
18275
18332
  this._serviceContext.registerService("duckdb", this._duckdb);
18276
18333
  }
@@ -18283,17 +18340,18 @@ var _TinyCloudNode = class _TinyCloudNode {
18283
18340
  };
18284
18341
  this._serviceContext.setSession(serviceSession);
18285
18342
  this.tc.serviceContext.setSession(serviceSession);
18286
- const vaultCrypto = (0, import_sdk_core4.createVaultCrypto)({
18287
- vault_encrypt: import_node_sdk_wasm4.vault_encrypt,
18288
- vault_decrypt: import_node_sdk_wasm4.vault_decrypt,
18289
- vault_derive_key: import_node_sdk_wasm4.vault_derive_key,
18290
- vault_x25519_from_seed: import_node_sdk_wasm4.vault_x25519_from_seed,
18291
- vault_x25519_dh: import_node_sdk_wasm4.vault_x25519_dh,
18292
- vault_random_bytes: import_node_sdk_wasm4.vault_random_bytes,
18293
- vault_sha256: import_node_sdk_wasm4.vault_sha256
18343
+ const wasm = this.wasmBindings;
18344
+ const vaultCrypto = (0, import_sdk_core3.createVaultCrypto)({
18345
+ vault_encrypt: wasm.vault_encrypt,
18346
+ vault_decrypt: wasm.vault_decrypt,
18347
+ vault_derive_key: wasm.vault_derive_key,
18348
+ vault_x25519_from_seed: wasm.vault_x25519_from_seed,
18349
+ vault_x25519_dh: wasm.vault_x25519_dh,
18350
+ vault_random_bytes: wasm.vault_random_bytes,
18351
+ vault_sha256: wasm.vault_sha256
18294
18352
  });
18295
18353
  const self2 = this;
18296
- this._vault = new import_sdk_core4.DataVaultService({
18354
+ this._vault = new import_sdk_core3.DataVaultService({
18297
18355
  spaceId: session.spaceId,
18298
18356
  crypto: vaultCrypto,
18299
18357
  tc: {
@@ -18309,8 +18367,8 @@ var _TinyCloudNode = class _TinyCloudNode {
18309
18367
  get publicKV() {
18310
18368
  return self2._publicKV ?? self2.tc.publicKV;
18311
18369
  },
18312
- readPublicSpace: (host, spaceId, key2) => import_sdk_core4.TinyCloud.readPublicSpace(host, spaceId, key2),
18313
- makePublicSpaceId: import_sdk_core4.TinyCloud.makePublicSpaceId,
18370
+ readPublicSpace: (host, spaceId, key2) => import_sdk_core3.TinyCloud.readPublicSpace(host, spaceId, key2),
18371
+ makePublicSpaceId: import_sdk_core3.TinyCloud.makePublicSpaceId,
18314
18372
  did: this.did,
18315
18373
  address: this._address,
18316
18374
  chainId: this._chainId,
@@ -18326,7 +18384,7 @@ var _TinyCloudNode = class _TinyCloudNode {
18326
18384
  * @internal
18327
18385
  */
18328
18386
  initializeV2Services(serviceSession) {
18329
- this._capabilityRegistry = new import_sdk_core4.CapabilityKeyRegistry();
18387
+ this._capabilityRegistry = new import_sdk_core3.CapabilityKeyRegistry();
18330
18388
  const tcSession = this.auth?.tinyCloudSession;
18331
18389
  if (tcSession && this._address) {
18332
18390
  const sessionKey = {
@@ -18400,23 +18458,23 @@ var _TinyCloudNode = class _TinyCloudNode {
18400
18458
  }
18401
18459
  this._capabilityRegistry.registerKey(sessionKey, delegations);
18402
18460
  }
18403
- this._delegationManager = new import_sdk_core4.DelegationManager({
18461
+ this._delegationManager = new import_sdk_core3.DelegationManager({
18404
18462
  hosts: [this.config.host],
18405
18463
  session: serviceSession,
18406
- invoke: import_node_sdk_wasm4.invoke,
18464
+ invoke: this.wasmBindings.invoke,
18407
18465
  fetch: globalThis.fetch.bind(globalThis)
18408
18466
  });
18409
- this._spaceService = new import_sdk_core4.SpaceService({
18467
+ this._spaceService = new import_sdk_core3.SpaceService({
18410
18468
  hosts: [this.config.host],
18411
18469
  session: serviceSession,
18412
- invoke: import_node_sdk_wasm4.invoke,
18470
+ invoke: this.wasmBindings.invoke,
18413
18471
  fetch: globalThis.fetch.bind(globalThis),
18414
18472
  capabilityRegistry: this._capabilityRegistry,
18415
18473
  userDid: this.did,
18416
18474
  createKVService: (spaceId) => {
18417
- const kvService = new import_sdk_core4.KVService({});
18475
+ const kvService = new import_sdk_core3.KVService({});
18418
18476
  if (this._serviceContext) {
18419
- const spaceScopedContext = new import_sdk_core4.ServiceContext({
18477
+ const spaceScopedContext = new import_sdk_core3.ServiceContext({
18420
18478
  invoke: this._serviceContext.invoke,
18421
18479
  fetch: this._serviceContext.fetch,
18422
18480
  hosts: this._serviceContext.hosts
@@ -18470,7 +18528,10 @@ var _TinyCloudNode = class _TinyCloudNode {
18470
18528
  delegationManager: this._delegationManager,
18471
18529
  sessionExpiry: this.getSessionExpiry(),
18472
18530
  // WASM-based delegation creation (preferred - no server roundtrip)
18473
- createDelegationWasm: (params) => this.createDelegationWrapper(params)
18531
+ createDelegationWasm: (params) => this.createDelegationWrapper(params),
18532
+ // Root delegation for long-lived share links (bypasses session expiry)
18533
+ // In node-sdk we have direct signer access, so no popup needed
18534
+ onRootDelegationNeeded: this.signer ? async (params) => this.createRootDelegationForSharing(params) : void 0
18474
18535
  });
18475
18536
  this._spaceService.updateConfig({
18476
18537
  sharingService: this._sharingService
@@ -18497,7 +18558,7 @@ var _TinyCloudNode = class _TinyCloudNode {
18497
18558
  spaceId: params.session.spaceId,
18498
18559
  verificationMethod: params.session.verificationMethod
18499
18560
  };
18500
- const result = (0, import_node_sdk_wasm4.createDelegation)(
18561
+ const result = this.wasmBindings.createDelegation(
18501
18562
  wasmSession,
18502
18563
  params.delegateDID,
18503
18564
  params.spaceId,
@@ -18515,6 +18576,67 @@ var _TinyCloudNode = class _TinyCloudNode {
18515
18576
  expiry: new Date(result.expiry * 1e3)
18516
18577
  };
18517
18578
  }
18579
+ /**
18580
+ * Create a direct root delegation from the wallet to a share key.
18581
+ * This bypasses the session delegation chain, allowing share links
18582
+ * with expiry longer than the current session.
18583
+ * @internal
18584
+ */
18585
+ async createRootDelegationForSharing(params) {
18586
+ if (!this.signer) {
18587
+ return void 0;
18588
+ }
18589
+ const session = this.auth?.tinyCloudSession;
18590
+ if (!session) {
18591
+ return void 0;
18592
+ }
18593
+ try {
18594
+ const host = this.config.host;
18595
+ const now = /* @__PURE__ */ new Date();
18596
+ const abilities = {
18597
+ kv: {
18598
+ [params.path]: params.actions
18599
+ }
18600
+ };
18601
+ const prepared = this.wasmBindings.prepareSession({
18602
+ abilities,
18603
+ address: this.wasmBindings.ensureEip55(session.address),
18604
+ chainId: session.chainId,
18605
+ domain: new URL(host).hostname,
18606
+ issuedAt: now.toISOString(),
18607
+ expirationTime: params.requestedExpiry.toISOString(),
18608
+ spaceId: params.spaceId,
18609
+ delegateUri: params.shareKeyDID
18610
+ });
18611
+ const signature2 = await this.signer.signMessage(prepared.siwe);
18612
+ const delegationSession = this.wasmBindings.completeSessionSetup({
18613
+ ...prepared,
18614
+ signature: signature2
18615
+ });
18616
+ const activateResult = await (0, import_sdk_core3.activateSessionWithHost)(
18617
+ host,
18618
+ delegationSession.delegationHeader
18619
+ );
18620
+ if (!activateResult.success) {
18621
+ return void 0;
18622
+ }
18623
+ return {
18624
+ cid: delegationSession.delegationCid,
18625
+ delegateDID: params.shareKeyDID,
18626
+ delegatorDID: `did:pkh:eip155:${session.chainId}:${session.address}`,
18627
+ spaceId: params.spaceId,
18628
+ path: params.path,
18629
+ actions: params.actions,
18630
+ expiry: params.requestedExpiry,
18631
+ isRevoked: false,
18632
+ allowSubDelegation: true,
18633
+ createdAt: now,
18634
+ authHeader: delegationSession.delegationHeader.Authorization
18635
+ };
18636
+ } catch {
18637
+ return void 0;
18638
+ }
18639
+ }
18518
18640
  /**
18519
18641
  * Track a received delegation in the capability registry.
18520
18642
  * @internal
@@ -18558,7 +18680,7 @@ var _TinyCloudNode = class _TinyCloudNode {
18558
18680
  if (!this._sql) {
18559
18681
  const features = this.nodeFeatures;
18560
18682
  if (features.length > 0 && !features.includes("sql")) {
18561
- throw new import_sdk_core4.UnsupportedFeatureError("sql", this.config.host, features);
18683
+ throw new import_sdk_core3.UnsupportedFeatureError("sql", this.config.host, features);
18562
18684
  }
18563
18685
  throw new Error("Not signed in. Call signIn() first.");
18564
18686
  }
@@ -18571,7 +18693,7 @@ var _TinyCloudNode = class _TinyCloudNode {
18571
18693
  if (!this._duckdb) {
18572
18694
  const features = this.nodeFeatures;
18573
18695
  if (features.length > 0 && !features.includes("duckdb")) {
18574
- throw new import_sdk_core4.UnsupportedFeatureError("duckdb", this.config.host, features);
18696
+ throw new import_sdk_core3.UnsupportedFeatureError("duckdb", this.config.host, features);
18575
18697
  }
18576
18698
  throw new Error("Not signed in. Call signIn() first.");
18577
18699
  }
@@ -18785,9 +18907,9 @@ var _TinyCloudNode = class _TinyCloudNode {
18785
18907
  const now = /* @__PURE__ */ new Date();
18786
18908
  const expiryMs = 60 * 60 * 1e3;
18787
18909
  const expirationTime = new Date(now.getTime() + expiryMs);
18788
- const prepared = (0, import_node_sdk_wasm4.prepareSession)({
18910
+ const prepared = this.wasmBindings.prepareSession({
18789
18911
  abilities,
18790
- address: (0, import_node_sdk_wasm4.ensureEip55)(this.session.address),
18912
+ address: this.wasmBindings.ensureEip55(this.session.address),
18791
18913
  chainId: this.session.chainId,
18792
18914
  domain: new URL(this.config.host).hostname,
18793
18915
  issuedAt: now.toISOString(),
@@ -18797,11 +18919,11 @@ var _TinyCloudNode = class _TinyCloudNode {
18797
18919
  parents: [this.session.delegationCid]
18798
18920
  });
18799
18921
  const signature2 = await this.signer.signMessage(prepared.siwe);
18800
- const delegationSession = (0, import_node_sdk_wasm4.completeSessionSetup)({
18922
+ const delegationSession = this.wasmBindings.completeSessionSetup({
18801
18923
  ...prepared,
18802
18924
  signature: signature2
18803
18925
  });
18804
- const activateResult = await (0, import_sdk_core4.activateSessionWithHost)(
18926
+ const activateResult = await (0, import_sdk_core3.activateSessionWithHost)(
18805
18927
  this.config.host,
18806
18928
  delegationSession.delegationHeader
18807
18929
  );
@@ -18828,9 +18950,9 @@ var _TinyCloudNode = class _TinyCloudNode {
18828
18950
  }]);
18829
18951
  }
18830
18952
  if (this._serviceContext) {
18831
- const publicKV = new import_sdk_core4.KVService({ prefix: "" });
18832
- const publicContext = new import_sdk_core4.ServiceContext({
18833
- invoke: import_node_sdk_wasm4.invoke,
18953
+ const publicKV = new import_sdk_core3.KVService({ prefix: "" });
18954
+ const publicContext = new import_sdk_core3.ServiceContext({
18955
+ invoke: this.wasmBindings.invoke,
18834
18956
  fetch: this._serviceContext.fetch,
18835
18957
  hosts: this._serviceContext.hosts
18836
18958
  });
@@ -18931,6 +19053,11 @@ var _TinyCloudNode = class _TinyCloudNode {
18931
19053
  if (!session) {
18932
19054
  throw new Error("Not signed in. Call signIn() first.");
18933
19055
  }
19056
+ if (params.delegateDID.endsWith(".eth") && this.config.ensResolver) {
19057
+ const address = await this.config.ensResolver.resolveAddress(params.delegateDID);
19058
+ if (!address) throw new Error(`Could not resolve ENS name: ${params.delegateDID}`);
19059
+ params = { ...params, delegateDID: `did:pkh:eip155:1:${address}` };
19060
+ }
18934
19061
  const abilities = {};
18935
19062
  const kvActions = params.actions.filter((a) => a.startsWith("tinycloud.kv/"));
18936
19063
  const sqlActions = params.actions.filter((a) => a.startsWith("tinycloud.sql/"));
@@ -18947,9 +19074,9 @@ var _TinyCloudNode = class _TinyCloudNode {
18947
19074
  const now = /* @__PURE__ */ new Date();
18948
19075
  const expiryMs = params.expiryMs ?? 60 * 60 * 1e3;
18949
19076
  const expirationTime = new Date(now.getTime() + expiryMs);
18950
- const prepared = (0, import_node_sdk_wasm4.prepareSession)({
19077
+ const prepared = this.wasmBindings.prepareSession({
18951
19078
  abilities,
18952
- address: (0, import_node_sdk_wasm4.ensureEip55)(session.address),
19079
+ address: this.wasmBindings.ensureEip55(session.address),
18953
19080
  chainId: session.chainId,
18954
19081
  domain: new URL(this.config.host).hostname,
18955
19082
  issuedAt: now.toISOString(),
@@ -18959,18 +19086,18 @@ var _TinyCloudNode = class _TinyCloudNode {
18959
19086
  parents: [session.delegationCid]
18960
19087
  });
18961
19088
  const signature2 = await this.signer.signMessage(prepared.siwe);
18962
- const delegationSession = (0, import_node_sdk_wasm4.completeSessionSetup)({
19089
+ const delegationSession = this.wasmBindings.completeSessionSetup({
18963
19090
  ...prepared,
18964
19091
  signature: signature2
18965
19092
  });
18966
- const activateResult = await (0, import_sdk_core4.activateSessionWithHost)(
19093
+ const activateResult = await (0, import_sdk_core3.activateSessionWithHost)(
18967
19094
  this.config.host,
18968
19095
  delegationSession.delegationHeader
18969
19096
  );
18970
19097
  if (!activateResult.success) {
18971
19098
  throw new Error(`Failed to activate delegation: ${activateResult.error}`);
18972
19099
  }
18973
- return {
19100
+ const result = {
18974
19101
  cid: delegationSession.delegationCid,
18975
19102
  delegationHeader: delegationSession.delegationHeader,
18976
19103
  spaceId: params.spaceIdOverride ?? session.spaceId,
@@ -18983,6 +19110,52 @@ var _TinyCloudNode = class _TinyCloudNode {
18983
19110
  chainId: session.chainId,
18984
19111
  host: this.config.host
18985
19112
  };
19113
+ const hasKvActions = params.actions.some((a) => a.startsWith("tinycloud.kv/"));
19114
+ if (hasKvActions && params.includePublicSpace !== false) {
19115
+ const publicSpaceId = (0, import_sdk_core3.makePublicSpaceId)(
19116
+ this.wasmBindings.ensureEip55(session.address),
19117
+ session.chainId
19118
+ );
19119
+ const publicAbilities = {
19120
+ kv: { "": ["tinycloud.kv/get", "tinycloud.kv/put", "tinycloud.kv/metadata"] }
19121
+ };
19122
+ const publicPrepared = this.wasmBindings.prepareSession({
19123
+ abilities: publicAbilities,
19124
+ address: this.wasmBindings.ensureEip55(session.address),
19125
+ chainId: session.chainId,
19126
+ domain: new URL(this.config.host).hostname,
19127
+ issuedAt: now.toISOString(),
19128
+ expirationTime: expirationTime.toISOString(),
19129
+ spaceId: publicSpaceId,
19130
+ delegateUri: params.delegateDID,
19131
+ parents: [session.delegationCid]
19132
+ });
19133
+ const publicSignature = await this.signer.signMessage(publicPrepared.siwe);
19134
+ const publicSession = this.wasmBindings.completeSessionSetup({
19135
+ ...publicPrepared,
19136
+ signature: publicSignature
19137
+ });
19138
+ const publicActivateResult = await (0, import_sdk_core3.activateSessionWithHost)(
19139
+ this.config.host,
19140
+ publicSession.delegationHeader
19141
+ );
19142
+ if (publicActivateResult.success) {
19143
+ result.publicDelegation = {
19144
+ cid: publicSession.delegationCid,
19145
+ delegationHeader: publicSession.delegationHeader,
19146
+ spaceId: publicSpaceId,
19147
+ path: "",
19148
+ actions: ["tinycloud.kv/get", "tinycloud.kv/put", "tinycloud.kv/metadata"],
19149
+ disableSubDelegation: params.disableSubDelegation ?? false,
19150
+ expiry: expirationTime,
19151
+ delegateDID: params.delegateDID,
19152
+ ownerAddress: session.address,
19153
+ chainId: session.chainId,
19154
+ host: this.config.host
19155
+ };
19156
+ }
19157
+ }
19158
+ return result;
18986
19159
  }
18987
19160
  /**
18988
19161
  * Use a delegation received from another user.
@@ -19022,7 +19195,7 @@ var _TinyCloudNode = class _TinyCloudNode {
19022
19195
  // Not used in session-only mode
19023
19196
  };
19024
19197
  this.trackReceivedDelegation(delegation, this.sessionKeyJwk);
19025
- return new DelegatedAccess(session2, delegation, targetHost);
19198
+ return new DelegatedAccess(session2, delegation, targetHost, this.wasmBindings.invoke);
19026
19199
  }
19027
19200
  const mySession = this.auth?.tinyCloudSession;
19028
19201
  if (!mySession) {
@@ -19045,9 +19218,9 @@ var _TinyCloudNode = class _TinyCloudNode {
19045
19218
  const now = /* @__PURE__ */ new Date();
19046
19219
  const maxExpiry = new Date(now.getTime() + 60 * 60 * 1e3);
19047
19220
  const expirationTime = delegation.expiry < maxExpiry ? delegation.expiry : maxExpiry;
19048
- const prepared = (0, import_node_sdk_wasm4.prepareSession)({
19221
+ const prepared = this.wasmBindings.prepareSession({
19049
19222
  abilities,
19050
- address: (0, import_node_sdk_wasm4.ensureEip55)(mySession.address),
19223
+ address: this.wasmBindings.ensureEip55(mySession.address),
19051
19224
  chainId: mySession.chainId,
19052
19225
  domain: new URL(targetHost).hostname,
19053
19226
  issuedAt: now.toISOString(),
@@ -19057,11 +19230,11 @@ var _TinyCloudNode = class _TinyCloudNode {
19057
19230
  parents: [delegation.cid]
19058
19231
  });
19059
19232
  const signature2 = await this.signer.signMessage(prepared.siwe);
19060
- const invokerSession = (0, import_node_sdk_wasm4.completeSessionSetup)({
19233
+ const invokerSession = this.wasmBindings.completeSessionSetup({
19061
19234
  ...prepared,
19062
19235
  signature: signature2
19063
19236
  });
19064
- const activateResult = await (0, import_sdk_core4.activateSessionWithHost)(
19237
+ const activateResult = await (0, import_sdk_core3.activateSessionWithHost)(
19065
19238
  targetHost,
19066
19239
  invokerSession.delegationHeader
19067
19240
  );
@@ -19081,7 +19254,7 @@ var _TinyCloudNode = class _TinyCloudNode {
19081
19254
  signature: signature2
19082
19255
  };
19083
19256
  this.trackReceivedDelegation(delegation, jwk);
19084
- return new DelegatedAccess(session, delegation, targetHost);
19257
+ return new DelegatedAccess(session, delegation, targetHost, this.wasmBindings.invoke);
19085
19258
  }
19086
19259
  /**
19087
19260
  * Create a sub-delegation from a received delegation.
@@ -19134,9 +19307,9 @@ var _TinyCloudNode = class _TinyCloudNode {
19134
19307
  abilities.duckdb = { [params.path]: duckdbActions };
19135
19308
  }
19136
19309
  const targetHost = parentDelegation.host ?? this.config.host;
19137
- const prepared = (0, import_node_sdk_wasm4.prepareSession)({
19310
+ const prepared = this.wasmBindings.prepareSession({
19138
19311
  abilities,
19139
- address: (0, import_node_sdk_wasm4.ensureEip55)(this._address),
19312
+ address: this.wasmBindings.ensureEip55(this._address),
19140
19313
  chainId: this._chainId,
19141
19314
  domain: new URL(targetHost).hostname,
19142
19315
  issuedAt: now.toISOString(),
@@ -19146,11 +19319,11 @@ var _TinyCloudNode = class _TinyCloudNode {
19146
19319
  parents: [parentDelegation.cid]
19147
19320
  });
19148
19321
  const signature2 = await this.signer.signMessage(prepared.siwe);
19149
- const subDelegationSession = (0, import_node_sdk_wasm4.completeSessionSetup)({
19322
+ const subDelegationSession = this.wasmBindings.completeSessionSetup({
19150
19323
  ...prepared,
19151
19324
  signature: signature2
19152
19325
  });
19153
- const activateResult = await (0, import_sdk_core4.activateSessionWithHost)(
19326
+ const activateResult = await (0, import_sdk_core3.activateSessionWithHost)(
19154
19327
  targetHost,
19155
19328
  subDelegationSession.delegationHeader
19156
19329
  );
@@ -19172,9 +19345,136 @@ var _TinyCloudNode = class _TinyCloudNode {
19172
19345
  };
19173
19346
  }
19174
19347
  };
19175
- /** Flag to ensure WASM panic hook is only initialized once */
19176
- _TinyCloudNode.wasmInitialized = false;
19177
- var TinyCloudNode = _TinyCloudNode;
19348
+
19349
+ // src/nodeDefaults.ts
19350
+ TinyCloudNode.registerNodeDefaults({
19351
+ createWasmBindings: () => new NodeWasmBindings(),
19352
+ createSigner: (privateKey, chainId) => new PrivateKeySigner(privateKey, chainId)
19353
+ });
19354
+
19355
+ // src/index.ts
19356
+ var import_sdk_core5 = require("@tinycloud/sdk-core");
19357
+ var import_sdk_core6 = require("@tinycloud/sdk-core");
19358
+
19359
+ // src/storage/FileSessionStorage.ts
19360
+ var import_sdk_core4 = require("@tinycloud/sdk-core");
19361
+ var import_fs = require("fs");
19362
+ var import_path = require("path");
19363
+ var FileSessionStorage = class {
19364
+ /**
19365
+ * Create a new FileSessionStorage.
19366
+ *
19367
+ * @param baseDir - Directory to store session files (default: ~/.tinycloud/sessions)
19368
+ */
19369
+ constructor(baseDir) {
19370
+ this.baseDir = baseDir || this.getDefaultDir();
19371
+ this.ensureDirectoryExists();
19372
+ }
19373
+ /**
19374
+ * Get the default session storage directory.
19375
+ */
19376
+ getDefaultDir() {
19377
+ const home = process.env.HOME || process.env.USERPROFILE || "/tmp";
19378
+ return (0, import_path.join)(home, ".tinycloud", "sessions");
19379
+ }
19380
+ /**
19381
+ * Ensure the storage directory exists.
19382
+ */
19383
+ ensureDirectoryExists() {
19384
+ if (!(0, import_fs.existsSync)(this.baseDir)) {
19385
+ (0, import_fs.mkdirSync)(this.baseDir, { recursive: true });
19386
+ }
19387
+ }
19388
+ /**
19389
+ * Get the file path for an address.
19390
+ */
19391
+ getFilePath(address) {
19392
+ const normalizedAddress = address.toLowerCase();
19393
+ const filename = `${normalizedAddress.replace("0x", "")}.json`;
19394
+ return (0, import_path.join)(this.baseDir, filename);
19395
+ }
19396
+ /**
19397
+ * Save a session for an address.
19398
+ */
19399
+ async save(address, session) {
19400
+ const filePath = this.getFilePath(address);
19401
+ const data = JSON.stringify(session, null, 2);
19402
+ (0, import_fs.writeFileSync)(filePath, data, "utf-8");
19403
+ }
19404
+ /**
19405
+ * Load a session for an address.
19406
+ */
19407
+ async load(address) {
19408
+ const filePath = this.getFilePath(address);
19409
+ if (!(0, import_fs.existsSync)(filePath)) {
19410
+ return null;
19411
+ }
19412
+ try {
19413
+ const data = (0, import_fs.readFileSync)(filePath, "utf-8");
19414
+ const parsed = JSON.parse(data);
19415
+ const validation = (0, import_sdk_core4.validatePersistedSessionData)(parsed);
19416
+ if (!validation.ok) {
19417
+ console.warn(`Invalid session data for ${address}:`, validation.error.message);
19418
+ (0, import_fs.unlinkSync)(filePath);
19419
+ return null;
19420
+ }
19421
+ const session = validation.data;
19422
+ const expiresAt = new Date(session.expiresAt);
19423
+ if (expiresAt < /* @__PURE__ */ new Date()) {
19424
+ (0, import_fs.unlinkSync)(filePath);
19425
+ return null;
19426
+ }
19427
+ return session;
19428
+ } catch (error) {
19429
+ try {
19430
+ (0, import_fs.unlinkSync)(filePath);
19431
+ } catch {
19432
+ }
19433
+ return null;
19434
+ }
19435
+ }
19436
+ /**
19437
+ * Clear a session for an address.
19438
+ */
19439
+ async clear(address) {
19440
+ const filePath = this.getFilePath(address);
19441
+ if ((0, import_fs.existsSync)(filePath)) {
19442
+ (0, import_fs.unlinkSync)(filePath);
19443
+ }
19444
+ }
19445
+ /**
19446
+ * Check if a session exists for an address.
19447
+ */
19448
+ exists(address) {
19449
+ const filePath = this.getFilePath(address);
19450
+ if (!(0, import_fs.existsSync)(filePath)) {
19451
+ return false;
19452
+ }
19453
+ try {
19454
+ const data = (0, import_fs.readFileSync)(filePath, "utf-8");
19455
+ const session = JSON.parse(data);
19456
+ const expiresAt = new Date(session.expiresAt);
19457
+ if (expiresAt < /* @__PURE__ */ new Date()) {
19458
+ (0, import_fs.unlinkSync)(filePath);
19459
+ return false;
19460
+ }
19461
+ return true;
19462
+ } catch {
19463
+ return false;
19464
+ }
19465
+ }
19466
+ /**
19467
+ * Check if file system storage is available.
19468
+ */
19469
+ isAvailable() {
19470
+ try {
19471
+ this.ensureDirectoryExists();
19472
+ return (0, import_fs.existsSync)(this.baseDir);
19473
+ } catch {
19474
+ return false;
19475
+ }
19476
+ }
19477
+ };
19178
19478
 
19179
19479
  // src/delegation.ts
19180
19480
  function serializeDelegation(delegation) {
@@ -19193,7 +19493,6 @@ function deserializeDelegation(data) {
19193
19493
  }
19194
19494
 
19195
19495
  // src/index.ts
19196
- var import_sdk_core6 = require("@tinycloud/sdk-core");
19197
19496
  var import_sdk_core7 = require("@tinycloud/sdk-core");
19198
19497
  var import_sdk_core8 = require("@tinycloud/sdk-core");
19199
19498
  var import_sdk_core9 = require("@tinycloud/sdk-core");
@@ -19202,8 +19501,10 @@ var import_sdk_core11 = require("@tinycloud/sdk-core");
19202
19501
  var import_sdk_core12 = require("@tinycloud/sdk-core");
19203
19502
  var import_sdk_core13 = require("@tinycloud/sdk-core");
19204
19503
  var import_sdk_core14 = require("@tinycloud/sdk-core");
19504
+ var import_sdk_core15 = require("@tinycloud/sdk-core");
19205
19505
  // Annotate the CommonJS export names for ESM import in node:
19206
19506
  0 && (module.exports = {
19507
+ AutoApproveSpaceCreationHandler,
19207
19508
  CapabilityKeyRegistry,
19208
19509
  CapabilityKeyRegistryErrorCodes,
19209
19510
  DataVaultService,
@@ -19218,6 +19519,7 @@ var import_sdk_core14 = require("@tinycloud/sdk-core");
19218
19519
  KVService,
19219
19520
  MemorySessionStorage,
19220
19521
  NodeUserAuthorization,
19522
+ NodeWasmBindings,
19221
19523
  PrefixedKVService,
19222
19524
  PrivateKeySigner,
19223
19525
  ProtocolMismatchError,
@@ -19225,24 +19527,26 @@ var import_sdk_core14 = require("@tinycloud/sdk-core");
19225
19527
  SQLService,
19226
19528
  ServiceContext,
19227
19529
  SharingService,
19530
+ SilentNotificationHandler,
19228
19531
  Space,
19229
19532
  SpaceErrorCodes,
19230
19533
  SpaceService,
19231
19534
  TinyCloud,
19232
19535
  TinyCloudNode,
19233
19536
  UnsupportedFeatureError,
19234
- VaultAction,
19235
19537
  VaultHeaders,
19538
+ VaultPublicSpaceKVActions,
19236
19539
  VersionCheckError,
19237
19540
  WasmKeyProvider,
19238
19541
  buildSpaceUri,
19239
- checkNodeVersion,
19542
+ checkNodeInfo,
19240
19543
  createCapabilityKeyRegistry,
19241
19544
  createSharingService,
19242
19545
  createSpaceService,
19243
19546
  createVaultCrypto,
19244
19547
  createWasmKeyProvider,
19245
19548
  defaultSignStrategy,
19549
+ defaultSpaceCreationHandler,
19246
19550
  deserializeDelegation,
19247
19551
  makePublicSpaceId,
19248
19552
  parseSpaceUri,