@tinycloud/node-sdk 3.0.0-beta.8 → 3.0.0-beta.9

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.
@@ -1,4 +1,5 @@
1
- import { ISessionStorage, PersistedSessionData, AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, IUserAuthorization, ISigner, ISpaceCreationHandler, LocalNodeIdentityStore, IWasmBindings, ISessionManager, SiweConfig, Manifest, ComposedManifestRequest, ClientSession, TinyCloudSession, Extension, SignRequest, SignInOptions, CapabilityPresentationEnvelopeV1, Delegation, DelegatedResource, PermissionEntry, TelemetryConfig, IKVService, ISQLService, IDuckDbService, IHooksService, CreateOwnerDelegationParams as CreateOwnerDelegationParams$1, OwnerDelegationReceipt as OwnerDelegationReceipt$1, INotificationHandler, IENSResolver, AccountService, InvokeAnyFunction as InvokeAnyFunction$1, UnifiedPolicyCapability, RegisterPolicyV3Input, RegisterPolicyV3Receipt, ShareDeliveryAuthorizationReceipt, CanonicalJson, ShareDeliveryAuthorizationV3Receipt, IDataVaultService, IEncryptionService, NetworkDescriptor, ISecretsService, ICapabilityKeyRegistry, DelegationManager, ISpaceService, ISpace, ISharingService, CreateDelegationParams, DelegationResult, DelegationRevocationReceipt, DelegationStatus, ResolvedDelegate, KeyProvider, JWK } from '@tinycloud/sdk-core';
1
+ import * as _tinycloud_sdk_core from '@tinycloud/sdk-core';
2
+ import { ISessionStorage, PersistedSessionData, AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, IUserAuthorization, ISigner, ISpaceCreationHandler, LocalNodeIdentityStore, IWasmBindings, ISessionManager, SiweConfig, Manifest, ComposedManifestRequest, ClientSession, TinyCloudSession, Extension, SignRequest, SignInOptions, CapabilityPresentationEnvelopeV1, Delegation, DelegatedResource, PermissionEntry, TelemetryConfig, IKVService, ISQLService, IDuckDbService, IHooksService, CreateOwnerDelegationParams as CreateOwnerDelegationParams$1, OwnerDelegationReceipt as OwnerDelegationReceipt$1, INotificationHandler, IENSResolver, AccountService, InvokeAnyFunction as InvokeAnyFunction$1, UnifiedPolicyCapability, RegisterPolicyV3Input, RegisterPolicyV3Receipt, CanonicalJson, ShareDeliveryAuthorizationV3Receipt, IDataVaultService, IEncryptionService, NetworkDescriptor, ISecretsService, ICapabilityKeyRegistry, DelegationManager, ISpaceService, ISpace, ISharingService, CreateDelegationParams, DelegationResult, DelegationRevocationReceipt, DelegationStatus, ResolvedDelegate, KeyProvider, JWK } from '@tinycloud/sdk-core';
2
3
  import { EventEmitter } from 'events';
3
4
  import { InvokeFunction, InvokeAnyFunction } from '@tinycloud/sdk-services';
4
5
 
@@ -955,39 +956,6 @@ declare class DelegatedAccess {
955
956
  get restorable(): RestorableSession;
956
957
  }
957
958
 
958
- /**
959
- * TinyCloudNode - High-level API for Node.js users.
960
- *
961
- * Each user has their own TinyCloudNode instance with their own key.
962
- * This class provides a simplified interface for:
963
- * - Signing in and managing sessions
964
- * - Key-value storage operations on own space
965
- * - Creating and using delegations
966
- *
967
- * @example
968
- * ```typescript
969
- * const alice = new TinyCloudNode({
970
- * privateKey: process.env.ALICE_PRIVATE_KEY,
971
- * host: "https://node.tinycloud.xyz",
972
- * prefix: "myapp",
973
- * });
974
- *
975
- * await alice.signIn();
976
- * await alice.kv.put("greeting", "Hello, world!");
977
- *
978
- * // Delegate access to Bob
979
- * const delegation = await alice.createDelegation({
980
- * path: "shared/",
981
- * actions: ["tinycloud.kv/get", "tinycloud.kv/put"],
982
- * delegateDID: bob.did,
983
- * });
984
- *
985
- * // Bob uses the delegation
986
- * const access = await bob.useDelegation(delegation);
987
- * const data = await access.kv.get("shared/data");
988
- * ```
989
- */
990
-
991
959
  declare const BOOTSTRAP_COMPLETION_MARKER_KEY = "system/bootstrap/complete";
992
960
  declare const BOOTSTRAP_COMPLETION_MARKER_VERSION = 1;
993
961
  declare const ACCEPTED_MARKER_VERSIONS: readonly number[];
@@ -1382,6 +1350,13 @@ declare class TinyCloudNode {
1382
1350
  get manifest(): Manifest | Manifest[] | undefined;
1383
1351
  get capabilityRequest(): ComposedManifestRequest | undefined;
1384
1352
  get hosts(): string[];
1353
+ /** The registry-resolved Node endpoint and the identity returned by that exact Node. */
1354
+ activeNodeIdentity(): Promise<{
1355
+ readonly origin: string;
1356
+ readonly nodeDid: string;
1357
+ }>;
1358
+ /** Publish the active owner Node as a session-signed registry record. */
1359
+ publishActiveNodeLocation(registryUrl: string, fetchFn?: typeof fetch): Promise<_tinycloud_sdk_core.LocationRecord>;
1385
1360
  /**
1386
1361
  * Get the primary identity DID for this user.
1387
1362
  * - If wallet connected and signed in: returns PKH DID (did:pkh:eip155:{chainId}:{address})
@@ -1813,45 +1788,16 @@ declare class TinyCloudNode {
1813
1788
  createOwnerDelegation(params: CreateOwnerDelegationParams, assertActive?: () => void): Promise<OwnerDelegationReceipt>;
1814
1789
  /** Register a signed policy and sibling roots with this Node's Policy/v3 runtime. */
1815
1790
  registerPolicy(params: Omit<RegisterPolicyV3Input, "nodeOrigin" | "fetch">): Promise<RegisterPolicyV3Receipt>;
1816
- /** @deprecated Policy/v2 delivery transport is retired. Use authorizeShareDeliveryV3. */
1817
- authorizeShareDelivery(input: {
1818
- readonly envelopeCid: string;
1819
- readonly shareCid: string;
1820
- readonly shareId: string;
1821
- readonly registrationCid: string;
1822
- readonly policyCid: string;
1823
- readonly delegationCid: string;
1824
- readonly enforcementDelegationCid: string;
1825
- readonly resourcePath: string;
1826
- readonly recipientEmail: string;
1827
- readonly shareUrl: string;
1828
- readonly documentName: string;
1829
- readonly idempotencyKey: string;
1830
- readonly expiresAt: string;
1831
- /** The enrolled receipt key from the node trust bundle. */
1832
- readonly nodeProof: {
1833
- readonly kid: string;
1834
- readonly publicKey: Uint8Array;
1835
- };
1836
- /** The trusted OpenCredentials witness origin from the same trust bundle as `nodeProof`. */
1837
- readonly credentialsAudience: string;
1838
- }): Promise<ShareDeliveryAuthorizationReceipt>;
1839
1791
  /** Authorize one short-lived v3 delivery against the signed v3 envelope and registered roots. */
1840
1792
  authorizeShareDeliveryV3(input: {
1841
1793
  readonly envelope: Record<string, CanonicalJson | undefined>;
1842
- readonly sealedEnvelope: string;
1843
- readonly envelopeKey: string;
1844
1794
  readonly shareCid: string;
1845
1795
  readonly resourcePath: string;
1846
1796
  readonly recipientEmail: string;
1847
1797
  readonly shareUrl: string;
1848
1798
  readonly documentName: string;
1849
1799
  readonly expiresAt: string;
1850
- readonly nodeProof: {
1851
- readonly kid: string;
1852
- readonly publicKey: Uint8Array;
1853
- };
1854
- readonly credentialsAudience: string;
1800
+ readonly deliveryAudience: string;
1855
1801
  }): Promise<ShareDeliveryAuthorizationV3Receipt>;
1856
1802
  private createRootDelegationForSharing;
1857
1803
  /**
@@ -1,4 +1,5 @@
1
- import { ISessionStorage, PersistedSessionData, AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, IUserAuthorization, ISigner, ISpaceCreationHandler, LocalNodeIdentityStore, IWasmBindings, ISessionManager, SiweConfig, Manifest, ComposedManifestRequest, ClientSession, TinyCloudSession, Extension, SignRequest, SignInOptions, CapabilityPresentationEnvelopeV1, Delegation, DelegatedResource, PermissionEntry, TelemetryConfig, IKVService, ISQLService, IDuckDbService, IHooksService, CreateOwnerDelegationParams as CreateOwnerDelegationParams$1, OwnerDelegationReceipt as OwnerDelegationReceipt$1, INotificationHandler, IENSResolver, AccountService, InvokeAnyFunction as InvokeAnyFunction$1, UnifiedPolicyCapability, RegisterPolicyV3Input, RegisterPolicyV3Receipt, ShareDeliveryAuthorizationReceipt, CanonicalJson, ShareDeliveryAuthorizationV3Receipt, IDataVaultService, IEncryptionService, NetworkDescriptor, ISecretsService, ICapabilityKeyRegistry, DelegationManager, ISpaceService, ISpace, ISharingService, CreateDelegationParams, DelegationResult, DelegationRevocationReceipt, DelegationStatus, ResolvedDelegate, KeyProvider, JWK } from '@tinycloud/sdk-core';
1
+ import * as _tinycloud_sdk_core from '@tinycloud/sdk-core';
2
+ import { ISessionStorage, PersistedSessionData, AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, IUserAuthorization, ISigner, ISpaceCreationHandler, LocalNodeIdentityStore, IWasmBindings, ISessionManager, SiweConfig, Manifest, ComposedManifestRequest, ClientSession, TinyCloudSession, Extension, SignRequest, SignInOptions, CapabilityPresentationEnvelopeV1, Delegation, DelegatedResource, PermissionEntry, TelemetryConfig, IKVService, ISQLService, IDuckDbService, IHooksService, CreateOwnerDelegationParams as CreateOwnerDelegationParams$1, OwnerDelegationReceipt as OwnerDelegationReceipt$1, INotificationHandler, IENSResolver, AccountService, InvokeAnyFunction as InvokeAnyFunction$1, UnifiedPolicyCapability, RegisterPolicyV3Input, RegisterPolicyV3Receipt, CanonicalJson, ShareDeliveryAuthorizationV3Receipt, IDataVaultService, IEncryptionService, NetworkDescriptor, ISecretsService, ICapabilityKeyRegistry, DelegationManager, ISpaceService, ISpace, ISharingService, CreateDelegationParams, DelegationResult, DelegationRevocationReceipt, DelegationStatus, ResolvedDelegate, KeyProvider, JWK } from '@tinycloud/sdk-core';
2
3
  import { EventEmitter } from 'events';
3
4
  import { InvokeFunction, InvokeAnyFunction } from '@tinycloud/sdk-services';
4
5
 
@@ -955,39 +956,6 @@ declare class DelegatedAccess {
955
956
  get restorable(): RestorableSession;
956
957
  }
957
958
 
958
- /**
959
- * TinyCloudNode - High-level API for Node.js users.
960
- *
961
- * Each user has their own TinyCloudNode instance with their own key.
962
- * This class provides a simplified interface for:
963
- * - Signing in and managing sessions
964
- * - Key-value storage operations on own space
965
- * - Creating and using delegations
966
- *
967
- * @example
968
- * ```typescript
969
- * const alice = new TinyCloudNode({
970
- * privateKey: process.env.ALICE_PRIVATE_KEY,
971
- * host: "https://node.tinycloud.xyz",
972
- * prefix: "myapp",
973
- * });
974
- *
975
- * await alice.signIn();
976
- * await alice.kv.put("greeting", "Hello, world!");
977
- *
978
- * // Delegate access to Bob
979
- * const delegation = await alice.createDelegation({
980
- * path: "shared/",
981
- * actions: ["tinycloud.kv/get", "tinycloud.kv/put"],
982
- * delegateDID: bob.did,
983
- * });
984
- *
985
- * // Bob uses the delegation
986
- * const access = await bob.useDelegation(delegation);
987
- * const data = await access.kv.get("shared/data");
988
- * ```
989
- */
990
-
991
959
  declare const BOOTSTRAP_COMPLETION_MARKER_KEY = "system/bootstrap/complete";
992
960
  declare const BOOTSTRAP_COMPLETION_MARKER_VERSION = 1;
993
961
  declare const ACCEPTED_MARKER_VERSIONS: readonly number[];
@@ -1382,6 +1350,13 @@ declare class TinyCloudNode {
1382
1350
  get manifest(): Manifest | Manifest[] | undefined;
1383
1351
  get capabilityRequest(): ComposedManifestRequest | undefined;
1384
1352
  get hosts(): string[];
1353
+ /** The registry-resolved Node endpoint and the identity returned by that exact Node. */
1354
+ activeNodeIdentity(): Promise<{
1355
+ readonly origin: string;
1356
+ readonly nodeDid: string;
1357
+ }>;
1358
+ /** Publish the active owner Node as a session-signed registry record. */
1359
+ publishActiveNodeLocation(registryUrl: string, fetchFn?: typeof fetch): Promise<_tinycloud_sdk_core.LocationRecord>;
1385
1360
  /**
1386
1361
  * Get the primary identity DID for this user.
1387
1362
  * - If wallet connected and signed in: returns PKH DID (did:pkh:eip155:{chainId}:{address})
@@ -1813,45 +1788,16 @@ declare class TinyCloudNode {
1813
1788
  createOwnerDelegation(params: CreateOwnerDelegationParams, assertActive?: () => void): Promise<OwnerDelegationReceipt>;
1814
1789
  /** Register a signed policy and sibling roots with this Node's Policy/v3 runtime. */
1815
1790
  registerPolicy(params: Omit<RegisterPolicyV3Input, "nodeOrigin" | "fetch">): Promise<RegisterPolicyV3Receipt>;
1816
- /** @deprecated Policy/v2 delivery transport is retired. Use authorizeShareDeliveryV3. */
1817
- authorizeShareDelivery(input: {
1818
- readonly envelopeCid: string;
1819
- readonly shareCid: string;
1820
- readonly shareId: string;
1821
- readonly registrationCid: string;
1822
- readonly policyCid: string;
1823
- readonly delegationCid: string;
1824
- readonly enforcementDelegationCid: string;
1825
- readonly resourcePath: string;
1826
- readonly recipientEmail: string;
1827
- readonly shareUrl: string;
1828
- readonly documentName: string;
1829
- readonly idempotencyKey: string;
1830
- readonly expiresAt: string;
1831
- /** The enrolled receipt key from the node trust bundle. */
1832
- readonly nodeProof: {
1833
- readonly kid: string;
1834
- readonly publicKey: Uint8Array;
1835
- };
1836
- /** The trusted OpenCredentials witness origin from the same trust bundle as `nodeProof`. */
1837
- readonly credentialsAudience: string;
1838
- }): Promise<ShareDeliveryAuthorizationReceipt>;
1839
1791
  /** Authorize one short-lived v3 delivery against the signed v3 envelope and registered roots. */
1840
1792
  authorizeShareDeliveryV3(input: {
1841
1793
  readonly envelope: Record<string, CanonicalJson | undefined>;
1842
- readonly sealedEnvelope: string;
1843
- readonly envelopeKey: string;
1844
1794
  readonly shareCid: string;
1845
1795
  readonly resourcePath: string;
1846
1796
  readonly recipientEmail: string;
1847
1797
  readonly shareUrl: string;
1848
1798
  readonly documentName: string;
1849
1799
  readonly expiresAt: string;
1850
- readonly nodeProof: {
1851
- readonly kid: string;
1852
- readonly publicKey: Uint8Array;
1853
- };
1854
- readonly credentialsAudience: string;
1800
+ readonly deliveryAudience: string;
1855
1801
  }): Promise<ShareDeliveryAuthorizationV3Receipt>;
1856
1802
  private createRootDelegationForSharing;
1857
1803
  /**
package/dist/core.cjs CHANGED
@@ -2847,6 +2847,29 @@ var _TinyCloudNode = class _TinyCloudNode {
2847
2847
  const authHosts = this.auth?.hosts ?? [];
2848
2848
  return authHosts.length > 0 ? authHosts : [this.config.host];
2849
2849
  }
2850
+ /** The registry-resolved Node endpoint and the identity returned by that exact Node. */
2851
+ async activeNodeIdentity() {
2852
+ const host = this.hosts[0];
2853
+ if (host === void 0) throw new Error("TinyCloud node host has not been resolved");
2854
+ const parsed = new URL(host);
2855
+ if (parsed.protocol !== "https:" && !(parsed.protocol === "http:" && (parsed.hostname === "127.0.0.1" || parsed.hostname === "localhost")) || parsed.origin !== host) {
2856
+ throw new Error("TinyCloud node host is not a canonical origin");
2857
+ }
2858
+ const nodeDid = await this.fetchNodeId();
2859
+ if (!nodeDid.startsWith("did:key:z")) throw new Error("TinyCloud node identity is not a did:key");
2860
+ return Object.freeze({ origin: parsed.origin, nodeDid });
2861
+ }
2862
+ /** Publish the active owner Node as a session-signed registry record. */
2863
+ async publishActiveNodeLocation(registryUrl, fetchFn = globalThis.fetch.bind(globalThis)) {
2864
+ const node = await this.activeNodeIdentity();
2865
+ return (0, import_sdk_core8.publishLocationRecord)({
2866
+ registryUrl,
2867
+ subject: this.credentialHolderDid,
2868
+ nodeOrigin: node.origin,
2869
+ signer: { type: "did:key", signBytes: (bytes) => this.signSessionBytes(bytes) },
2870
+ fetch: fetchFn
2871
+ });
2872
+ }
2850
2873
  /**
2851
2874
  * Get the primary identity DID for this user.
2852
2875
  * - If wallet connected and signed in: returns PKH DID (did:pkh:eip155:{chainId}:{address})
@@ -5203,11 +5226,6 @@ var _TinyCloudNode = class _TinyCloudNode {
5203
5226
  fetch: globalThis.fetch.bind(globalThis)
5204
5227
  });
5205
5228
  }
5206
- /** @deprecated Policy/v2 delivery transport is retired. Use authorizeShareDeliveryV3. */
5207
- async authorizeShareDelivery(input) {
5208
- void input;
5209
- throw new Error("Policy/v2 share delivery is retired; use authorizeShareDeliveryV3");
5210
- }
5211
5229
  /** Authorize one short-lived v3 delivery against the signed v3 envelope and registered roots. */
5212
5230
  async authorizeShareDeliveryV3(input) {
5213
5231
  const session = this.currentTinyCloudSession();
@@ -5215,8 +5233,6 @@ var _TinyCloudNode = class _TinyCloudNode {
5215
5233
  if (!session || !serviceSession) throw new Error("Share delivery requires an authenticated session");
5216
5234
  const body = {
5217
5235
  envelope: input.envelope,
5218
- sealedEnvelope: input.sealedEnvelope,
5219
- envelopeKey: input.envelopeKey,
5220
5236
  shareCid: input.shareCid,
5221
5237
  recipientEmail: input.recipientEmail,
5222
5238
  shareUrl: input.shareUrl,
@@ -5236,9 +5252,8 @@ var _TinyCloudNode = class _TinyCloudNode {
5236
5252
  const verified = (0, import_sdk_core8.validateShareDeliveryAuthorizationV3Bytes)(new Uint8Array(await response.arrayBuffer()), {
5237
5253
  request,
5238
5254
  senderKeyDid: this.credentialHolderDid,
5239
- credentialsAudience: input.credentialsAudience
5255
+ deliveryAudience: input.deliveryAudience
5240
5256
  });
5241
- void input.nodeProof;
5242
5257
  const requestDigest = new Uint8Array(await crypto.subtle.digest(
5243
5258
  "SHA-256",
5244
5259
  new TextEncoder().encode(`${import_sdk_core8.CREDENTIAL_INVITATION_REQUEST_DOMAIN}${(0, import_sdk_core8.canonicalizeEncryptionJson)(verified.request)}`)