@tinycloud/node-sdk 2.2.0-beta.2 → 2.2.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ISigner, Bytes, IWasmBindings, ISessionManager } from '@tinycloud/sdk-core';
2
2
  export { ACCOUNT_REGISTRY_PATH, ACCOUNT_REGISTRY_SPACE, AutoApproveSpaceCreationHandler, AutoRejectStrategy, AutoSignStrategy, BatchOptions, BatchResponse, CallbackStrategy, CapabilityEntry, CapabilityKeyRegistry, CapabilityKeyRegistryErrorCode, CapabilityKeyRegistryErrorCodes, ClientSession, ColumnInfo, ComposeManifestOptions, ComposedManifestRequest, CreateDelegationParams, DEFAULT_MANIFEST_SPACE, DEFAULT_MANIFEST_VERSION, 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, HookEvent, HookServiceName, HookStreamEvent, HookSubscription, HookWebhookListOptions, HookWebhookRecord, HookWebhookRegistration, HookWebhookScope, HookWebhookUnregisterOptions, HooksService, HooksServiceConfig, ICapabilityKeyRegistry, IDataVaultService, IDatabaseHandle, IDuckDbDatabaseHandle, IDuckDbService, IENSResolver, IHooksService, IKVService, INotificationHandler, IPrefixedKVService, ISQLService, ISessionManager, ISessionStorage, ISharingService, ISigner, ISpace, ISpaceCreationHandler, ISpaceScopedDelegations, ISpaceScopedSharing, ISpaceService, IUserAuthorization, IWasmBindings, IngestOptions, InvokeFunction, JWK, KVResponse, KVService, KVServiceConfig, KeyInfo, KeyProvider, KeyType, Manifest, ManifestDefaults, ManifestRegistryRecord, ManifestValidationError, PermissionEntry, PermissionNotInManifestError, PersistedSessionData, PrefixedKVService, ProtocolMismatchError, QueryOptions, QueryResponse, ReceiveOptions, ResolvedCapabilities, ResolvedDelegate, ResourceCapability, SQLAction, SQLActionType, SQLService, SQLServiceConfig, SchemaInfo, ServiceContext, ServiceContextConfig, ServiceSession, SessionExpiredError, ShareAccess, ShareLink, ShareLinkData, ShareSchema, SharingService, SharingServiceConfig, SignCallback, SignInOptions, SignRequest, SignResponse, SilentNotificationHandler, Space, SpaceAbilitiesMap, SpaceConfig, SpaceCreationContext, SpaceErrorCode, SpaceErrorCodes, SpaceInfo, SpaceOwnership, SpaceService, SpaceServiceConfig, SqlStatement, SqlValue, StoredDelegationChain, SubscribeOptions, TableInfo, TinyCloud, TinyCloudConfig, TinyCloudSession, UnsupportedFeatureError, VaultCrypto, VaultEntry, VaultError, VaultGetOptions, VaultGrantOptions, VaultHeaders, VaultListOptions, VaultPublicSpaceKVActions, VaultPutOptions, VersionCheckError, ViewInfo, WasmVaultFunctions, buildSpaceUri, checkNodeInfo, composeManifestRequest, createCapabilityKeyRegistry, createSharingService, createSpaceService, createVaultCrypto, defaultSpaceCreationHandler, expandActionShortNames, isCapabilitySubset, loadManifest, makePublicSpaceId, parseExpiry, parseSpaceUri, resolveManifest, resourceCapabilitiesToSpaceAbilitiesMap, validateManifest } from '@tinycloud/sdk-core';
3
- export { D as DelegateToOptions, a as DelegateToResult, b as DelegatedAccess, F as FileSessionStorage, M as MemorySessionStorage, N as NodeEventEmitterStrategy, c as NodeUserAuthorization, d as NodeUserAuthorizationConfig, P as PortableDelegation, R as RestorableSession, S as SignStrategy, T as TinyCloudNode, e as TinyCloudNodeConfig, W as WasmKeyProvider, f as WasmKeyProviderConfig, g as createWasmKeyProvider, h as defaultSignStrategy, i as deserializeDelegation, s as serializeDelegation } from './core-NsTndW58.cjs';
3
+ export { D as DelegateToOptions, a as DelegateToResult, b as DelegatedAccess, F as FileSessionStorage, M as MemorySessionStorage, N as NodeEventEmitterStrategy, c as NodeUserAuthorization, d as NodeUserAuthorizationConfig, P as PortableDelegation, R as RestorableSession, S as SignStrategy, T as TinyCloudNode, e as TinyCloudNodeConfig, W as WasmKeyProvider, f as WasmKeyProviderConfig, g as createWasmKeyProvider, h as defaultSignStrategy, i as deserializeDelegation, s as serializeDelegation } from './core-BC3y7xTF.cjs';
4
4
  import { invoke, invokeAny, prepareSession, completeSessionSetup, ensureEip55, makeSpaceId, createDelegation, parseRecapFromSiwe, generateHostSIWEMessage, siweToDelegationHeaders, protocolVersion, vault_encrypt, vault_decrypt, vault_derive_key, vault_x25519_from_seed, vault_x25519_dh, vault_random_bytes, vault_sha256 } from '@tinycloud/node-sdk-wasm';
5
5
  import 'events';
6
6
  import '@tinycloud/sdk-services';
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ISigner, Bytes, IWasmBindings, ISessionManager } from '@tinycloud/sdk-core';
2
2
  export { ACCOUNT_REGISTRY_PATH, ACCOUNT_REGISTRY_SPACE, AutoApproveSpaceCreationHandler, AutoRejectStrategy, AutoSignStrategy, BatchOptions, BatchResponse, CallbackStrategy, CapabilityEntry, CapabilityKeyRegistry, CapabilityKeyRegistryErrorCode, CapabilityKeyRegistryErrorCodes, ClientSession, ColumnInfo, ComposeManifestOptions, ComposedManifestRequest, CreateDelegationParams, DEFAULT_MANIFEST_SPACE, DEFAULT_MANIFEST_VERSION, 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, HookEvent, HookServiceName, HookStreamEvent, HookSubscription, HookWebhookListOptions, HookWebhookRecord, HookWebhookRegistration, HookWebhookScope, HookWebhookUnregisterOptions, HooksService, HooksServiceConfig, ICapabilityKeyRegistry, IDataVaultService, IDatabaseHandle, IDuckDbDatabaseHandle, IDuckDbService, IENSResolver, IHooksService, IKVService, INotificationHandler, IPrefixedKVService, ISQLService, ISessionManager, ISessionStorage, ISharingService, ISigner, ISpace, ISpaceCreationHandler, ISpaceScopedDelegations, ISpaceScopedSharing, ISpaceService, IUserAuthorization, IWasmBindings, IngestOptions, InvokeFunction, JWK, KVResponse, KVService, KVServiceConfig, KeyInfo, KeyProvider, KeyType, Manifest, ManifestDefaults, ManifestRegistryRecord, ManifestValidationError, PermissionEntry, PermissionNotInManifestError, PersistedSessionData, PrefixedKVService, ProtocolMismatchError, QueryOptions, QueryResponse, ReceiveOptions, ResolvedCapabilities, ResolvedDelegate, ResourceCapability, SQLAction, SQLActionType, SQLService, SQLServiceConfig, SchemaInfo, ServiceContext, ServiceContextConfig, ServiceSession, SessionExpiredError, ShareAccess, ShareLink, ShareLinkData, ShareSchema, SharingService, SharingServiceConfig, SignCallback, SignInOptions, SignRequest, SignResponse, SilentNotificationHandler, Space, SpaceAbilitiesMap, SpaceConfig, SpaceCreationContext, SpaceErrorCode, SpaceErrorCodes, SpaceInfo, SpaceOwnership, SpaceService, SpaceServiceConfig, SqlStatement, SqlValue, StoredDelegationChain, SubscribeOptions, TableInfo, TinyCloud, TinyCloudConfig, TinyCloudSession, UnsupportedFeatureError, VaultCrypto, VaultEntry, VaultError, VaultGetOptions, VaultGrantOptions, VaultHeaders, VaultListOptions, VaultPublicSpaceKVActions, VaultPutOptions, VersionCheckError, ViewInfo, WasmVaultFunctions, buildSpaceUri, checkNodeInfo, composeManifestRequest, createCapabilityKeyRegistry, createSharingService, createSpaceService, createVaultCrypto, defaultSpaceCreationHandler, expandActionShortNames, isCapabilitySubset, loadManifest, makePublicSpaceId, parseExpiry, parseSpaceUri, resolveManifest, resourceCapabilitiesToSpaceAbilitiesMap, validateManifest } from '@tinycloud/sdk-core';
3
- export { D as DelegateToOptions, a as DelegateToResult, b as DelegatedAccess, F as FileSessionStorage, M as MemorySessionStorage, N as NodeEventEmitterStrategy, c as NodeUserAuthorization, d as NodeUserAuthorizationConfig, P as PortableDelegation, R as RestorableSession, S as SignStrategy, T as TinyCloudNode, e as TinyCloudNodeConfig, W as WasmKeyProvider, f as WasmKeyProviderConfig, g as createWasmKeyProvider, h as defaultSignStrategy, i as deserializeDelegation, s as serializeDelegation } from './core-NsTndW58.js';
3
+ export { D as DelegateToOptions, a as DelegateToResult, b as DelegatedAccess, F as FileSessionStorage, M as MemorySessionStorage, N as NodeEventEmitterStrategy, c as NodeUserAuthorization, d as NodeUserAuthorizationConfig, P as PortableDelegation, R as RestorableSession, S as SignStrategy, T as TinyCloudNode, e as TinyCloudNodeConfig, W as WasmKeyProvider, f as WasmKeyProviderConfig, g as createWasmKeyProvider, h as defaultSignStrategy, i as deserializeDelegation, s as serializeDelegation } from './core-BC3y7xTF.js';
4
4
  import { invoke, invokeAny, prepareSession, completeSessionSetup, ensureEip55, makeSpaceId, createDelegation, parseRecapFromSiwe, generateHostSIWEMessage, siweToDelegationHeaders, protocolVersion, vault_encrypt, vault_decrypt, vault_derive_key, vault_x25519_from_seed, vault_x25519_dh, vault_random_bytes, vault_sha256 } from '@tinycloud/node-sdk-wasm';
5
5
  import 'events';
6
6
  import '@tinycloud/sdk-services';
package/dist/index.js CHANGED
@@ -17187,7 +17187,8 @@ import {
17187
17187
  DEFAULT_MANIFEST_SPACE,
17188
17188
  composeManifestRequest,
17189
17189
  resourceCapabilitiesToAbilitiesMap,
17190
- resourceCapabilitiesToSpaceAbilitiesMap
17190
+ resourceCapabilitiesToSpaceAbilitiesMap,
17191
+ resolveTinyCloudHosts
17191
17192
  } from "@tinycloud/sdk-core";
17192
17193
 
17193
17194
  // src/authorization/strategies.ts
@@ -17321,9 +17322,9 @@ var NodeUserAuthorization = class {
17321
17322
  this.sessionExpirationMs = config.sessionExpirationMs ?? 60 * 60 * 1e3;
17322
17323
  this.autoCreateSpace = config.autoCreateSpace ?? false;
17323
17324
  this.spaceCreationHandler = config.spaceCreationHandler;
17324
- this.tinycloudHosts = config.tinycloudHosts ?? [
17325
- "https://node.tinycloud.xyz"
17326
- ];
17325
+ this.tinycloudHosts = config.tinycloudHosts;
17326
+ this.tinycloudRegistryUrl = config.tinycloudRegistryUrl;
17327
+ this.tinycloudFallbackHosts = config.tinycloudFallbackHosts;
17327
17328
  this.enablePublicSpace = config.enablePublicSpace ?? true;
17328
17329
  this.nonce = config.nonce;
17329
17330
  this.siweConfig = config.siweConfig;
@@ -17344,6 +17345,9 @@ var NodeUserAuthorization = class {
17344
17345
  get capabilityRequest() {
17345
17346
  return this.getCapabilityRequest();
17346
17347
  }
17348
+ get hosts() {
17349
+ return this.tinycloudHosts ? [...this.tinycloudHosts] : [];
17350
+ }
17347
17351
  /**
17348
17352
  * Install or replace the stored manifest. Takes effect on the next
17349
17353
  * `signIn()` call — the current session (if any) is not touched.
@@ -17368,6 +17372,26 @@ var NodeUserAuthorization = class {
17368
17372
  get tinyCloudSession() {
17369
17373
  return this._tinyCloudSession;
17370
17374
  }
17375
+ async resolveTinyCloudHostsForSignIn(address, chainId) {
17376
+ if (this.tinycloudHosts && this.tinycloudHosts.length > 0) {
17377
+ return;
17378
+ }
17379
+ const subject = `did:pkh:eip155:${chainId}:${address}`;
17380
+ const resolved = await resolveTinyCloudHosts(subject, {
17381
+ registryUrl: this.tinycloudRegistryUrl,
17382
+ fallbackHosts: this.tinycloudFallbackHosts
17383
+ });
17384
+ this.tinycloudHosts = resolved.hosts;
17385
+ }
17386
+ requireTinyCloudHosts() {
17387
+ if (!this.tinycloudHosts || this.tinycloudHosts.length === 0) {
17388
+ throw new Error("TinyCloud hosts have not been resolved. Call signIn() first.");
17389
+ }
17390
+ return this.tinycloudHosts;
17391
+ }
17392
+ get primaryTinyCloudHost() {
17393
+ return this.requireTinyCloudHosts()[0];
17394
+ }
17371
17395
  get nodeFeatures() {
17372
17396
  return this._nodeFeatures;
17373
17397
  }
@@ -17499,7 +17523,7 @@ var NodeUserAuthorization = class {
17499
17523
  if (!this._tinyCloudSession || !this._address || !this._chainId) {
17500
17524
  throw new Error("Must be signed in to host space");
17501
17525
  }
17502
- const host = this.tinycloudHosts[0];
17526
+ const host = this.primaryTinyCloudHost;
17503
17527
  const spaceId = targetSpaceId ?? this._tinyCloudSession.spaceId;
17504
17528
  const peerId = await fetchPeerId(host, spaceId);
17505
17529
  const siwe = this.wasm.generateHostSIWEMessage({
@@ -17541,7 +17565,7 @@ var NodeUserAuthorization = class {
17541
17565
  if (!this._tinyCloudSession) {
17542
17566
  throw new Error("Must be signed in to ensure space exists");
17543
17567
  }
17544
- const host = this.tinycloudHosts[0];
17568
+ const host = this.primaryTinyCloudHost;
17545
17569
  const primarySpaceId = this._tinyCloudSession.spaceId;
17546
17570
  const result = await activateSessionWithHost(
17547
17571
  host,
@@ -17650,6 +17674,7 @@ var NodeUserAuthorization = class {
17650
17674
  this._chainId = await this.signer.getChainId();
17651
17675
  const address = this.wasm.ensureEip55(this._address);
17652
17676
  const chainId = this._chainId;
17677
+ await this.resolveTinyCloudHostsForSignIn(address, chainId);
17653
17678
  const keyId = `session-${Date.now()}`;
17654
17679
  this.sessionManager.renameSessionKeyId("default", keyId);
17655
17680
  const jwkString = this.sessionManager.jwk(keyId);
@@ -17728,7 +17753,7 @@ var NodeUserAuthorization = class {
17728
17753
  this._address = address;
17729
17754
  this._chainId = chainId;
17730
17755
  const nodeInfo = await checkNodeInfo(
17731
- this.tinycloudHosts[0],
17756
+ this.primaryTinyCloudHost,
17732
17757
  this.wasm.protocolVersion()
17733
17758
  );
17734
17759
  this._nodeFeatures = nodeInfo.features;
@@ -17844,6 +17869,7 @@ var NodeUserAuthorization = class {
17844
17869
  });
17845
17870
  const address = this.wasm.ensureEip55(await this.signer.getAddress());
17846
17871
  const chainId = await this.signer.getChainId();
17872
+ await this.resolveTinyCloudHostsForSignIn(address, chainId);
17847
17873
  const clientSession = {
17848
17874
  address,
17849
17875
  walletAddress: address,
@@ -17893,7 +17919,7 @@ var NodeUserAuthorization = class {
17893
17919
  this._address = address;
17894
17920
  this._chainId = chainId;
17895
17921
  const nodeInfo = await checkNodeInfo(
17896
- this.tinycloudHosts[0],
17922
+ this.primaryTinyCloudHost,
17897
17923
  this.wasm.protocolVersion()
17898
17924
  );
17899
17925
  this._nodeFeatures = nodeInfo.features;
@@ -18246,6 +18272,7 @@ var _TinyCloudNode = class _TinyCloudNode {
18246
18272
  this.auth = null;
18247
18273
  this.tc = null;
18248
18274
  this._chainId = 1;
18275
+ this.explicitHost = config.host;
18249
18276
  this.config = {
18250
18277
  ...config,
18251
18278
  host: config.host ?? DEFAULT_HOST
@@ -18327,7 +18354,6 @@ var _TinyCloudNode = class _TinyCloudNode {
18327
18354
  * @internal
18328
18355
  */
18329
18356
  setupAuth(config) {
18330
- const host = this.config.host;
18331
18357
  this.auth = new NodeUserAuthorization({
18332
18358
  signer: this.signer,
18333
18359
  signStrategy: { type: "auto-sign" },
@@ -18336,7 +18362,9 @@ var _TinyCloudNode = class _TinyCloudNode {
18336
18362
  domain: this.siweDomain,
18337
18363
  spacePrefix: config.prefix,
18338
18364
  sessionExpirationMs: config.sessionExpirationMs ?? 60 * 60 * 1e3,
18339
- tinycloudHosts: [host],
18365
+ tinycloudHosts: this.explicitHost ? [this.explicitHost] : void 0,
18366
+ tinycloudRegistryUrl: config.tinycloudRegistryUrl,
18367
+ tinycloudFallbackHosts: config.tinycloudFallbackHosts,
18340
18368
  autoCreateSpace: config.autoCreateSpace,
18341
18369
  enablePublicSpace: config.enablePublicSpace ?? true,
18342
18370
  spaceCreationHandler: config.spaceCreationHandler,
@@ -18350,6 +18378,12 @@ var _TinyCloudNode = class _TinyCloudNode {
18350
18378
  invokeAny: this.wasmBindings.invokeAny
18351
18379
  });
18352
18380
  }
18381
+ syncResolvedHostFromAuth() {
18382
+ const host = this.auth?.hosts[0];
18383
+ if (host) {
18384
+ this.config.host = host;
18385
+ }
18386
+ }
18353
18387
  /**
18354
18388
  * Install or replace the manifest that drives the SIWE recap at
18355
18389
  * sign-in. Takes effect on the next `signIn()` call — the current
@@ -18387,6 +18421,10 @@ var _TinyCloudNode = class _TinyCloudNode {
18387
18421
  get capabilityRequest() {
18388
18422
  return this.auth?.capabilityRequest;
18389
18423
  }
18424
+ get hosts() {
18425
+ const authHosts = this.auth?.hosts ?? [];
18426
+ return authHosts.length > 0 ? authHosts : [this.config.host];
18427
+ }
18390
18428
  /**
18391
18429
  * Get the primary identity DID for this user.
18392
18430
  * - If wallet connected and signed in: returns PKH DID (did:pkh:eip155:{chainId}:{address})
@@ -18459,6 +18497,7 @@ var _TinyCloudNode = class _TinyCloudNode {
18459
18497
  this._hooks = void 0;
18460
18498
  this._serviceContext = void 0;
18461
18499
  await this.tc.signIn(options);
18500
+ this.syncResolvedHostFromAuth();
18462
18501
  this.initializeServices();
18463
18502
  await this.writeManifestRegistryRecords();
18464
18503
  this.notificationHandler.success("Successfully signed in");
@@ -18610,7 +18649,6 @@ var _TinyCloudNode = class _TinyCloudNode {
18610
18649
  throw new Error("Wallet already connected. Cannot connect another wallet.");
18611
18650
  }
18612
18651
  const prefix = options?.prefix ?? "default";
18613
- const host = this.config.host;
18614
18652
  if (!_TinyCloudNode.nodeDefaults) {
18615
18653
  throw new Error(
18616
18654
  "connectWallet() requires PrivateKeySigner. Use connectSigner() instead, or import from '@tinycloud/node-sdk' (not '/core') for automatic Node.js defaults."
@@ -18625,7 +18663,9 @@ var _TinyCloudNode = class _TinyCloudNode {
18625
18663
  domain: this.siweDomain,
18626
18664
  spacePrefix: prefix,
18627
18665
  sessionExpirationMs: this.config.sessionExpirationMs ?? 60 * 60 * 1e3,
18628
- tinycloudHosts: [host],
18666
+ tinycloudHosts: this.explicitHost ? [this.explicitHost] : void 0,
18667
+ tinycloudRegistryUrl: this.config.tinycloudRegistryUrl,
18668
+ tinycloudFallbackHosts: this.config.tinycloudFallbackHosts,
18629
18669
  autoCreateSpace: this.config.autoCreateSpace,
18630
18670
  enablePublicSpace: this.config.enablePublicSpace ?? true,
18631
18671
  spaceCreationHandler: this.config.spaceCreationHandler,
@@ -18658,7 +18698,6 @@ var _TinyCloudNode = class _TinyCloudNode {
18658
18698
  throw new Error("Signer already connected. Cannot connect another signer.");
18659
18699
  }
18660
18700
  const prefix = options?.prefix ?? "default";
18661
- const host = this.config.host;
18662
18701
  this.signer = signer;
18663
18702
  this.auth = new NodeUserAuthorization({
18664
18703
  signer: this.signer,
@@ -18668,7 +18707,9 @@ var _TinyCloudNode = class _TinyCloudNode {
18668
18707
  domain: this.siweDomain,
18669
18708
  spacePrefix: prefix,
18670
18709
  sessionExpirationMs: this.config.sessionExpirationMs ?? 60 * 60 * 1e3,
18671
- tinycloudHosts: [host],
18710
+ tinycloudHosts: this.explicitHost ? [this.explicitHost] : void 0,
18711
+ tinycloudRegistryUrl: this.config.tinycloudRegistryUrl,
18712
+ tinycloudFallbackHosts: this.config.tinycloudFallbackHosts,
18672
18713
  autoCreateSpace: this.config.autoCreateSpace,
18673
18714
  enablePublicSpace: this.config.enablePublicSpace ?? true,
18674
18715
  spaceCreationHandler: this.config.spaceCreationHandler,