@tinycloud/node-sdk 2.6.4-beta.1 → 2.7.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { ISessionStorage, PersistedSessionData, AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, IUserAuthorization, ISigner, ISpaceCreationHandler, IWasmBindings, ISessionManager, SiweConfig, Manifest, ComposedManifestRequest, ClientSession, TinyCloudSession, Extension, SignRequest, SignInOptions, Delegation, DelegatedResource, PermissionEntry, TelemetryConfig, IKVService, ISQLService, IDuckDbService, IHooksService, INotificationHandler, IENSResolver, AccountService, IDataVaultService, IEncryptionService, NetworkDescriptor, ISecretsService, ICapabilityKeyRegistry, DelegationManager, ISpaceService, ISpace, ISharingService, CreateDelegationParams, DelegationResult, ResolvedDelegate, KeyProvider, JWK } from '@tinycloud/sdk-core';
1
+ import { ISessionStorage, PersistedSessionData, AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, IUserAuthorization, ISigner, ISpaceCreationHandler, IWasmBindings, ISessionManager, SiweConfig, Manifest, ComposedManifestRequest, ClientSession, TinyCloudSession, Extension, SignRequest, SignInOptions, Delegation, DelegatedResource, PermissionEntry, TelemetryConfig, IKVService, ISQLService, IDuckDbService, IHooksService, INotificationHandler, IENSResolver, AccountService, IDataVaultService, IEncryptionService, NetworkDescriptor, ISecretsService, ICapabilityKeyRegistry, DelegationManager, ISpaceService, ISpace, ISharingService, CreateDelegationParams, DelegationResult, DelegationStatus, ResolvedDelegate, KeyProvider, JWK } from '@tinycloud/sdk-core';
2
2
  import { EventEmitter } from 'events';
3
3
  import { InvokeFunction, InvokeAnyFunction } from '@tinycloud/sdk-services';
4
4
 
@@ -757,6 +757,26 @@ declare class DelegatedAccess {
757
757
  * ```
758
758
  */
759
759
 
760
+ interface CreateOwnerDelegationParams {
761
+ readonly delegateDid: string;
762
+ readonly spaceId: string;
763
+ readonly path: string;
764
+ readonly actions: readonly string[];
765
+ readonly expiresAt: Date;
766
+ }
767
+ interface OwnerDelegationReceipt {
768
+ readonly delegation: Delegation;
769
+ /** Exact signed DAG-CBOR bytes submitted in the Authorization header. */
770
+ readonly signedDagCbor: Uint8Array;
771
+ /** Locally derived by the node WASM implementation; this is delegation identity. */
772
+ readonly delegationCid: string;
773
+ readonly nodeReceipt: {
774
+ /** Raw /delegate response CID: a commit-event id, not delegation identity. */
775
+ readonly commitEventCid?: string;
776
+ readonly activated: readonly string[];
777
+ readonly skipped: readonly string[];
778
+ };
779
+ }
760
780
  /**
761
781
  * Configuration for TinyCloudNode.
762
782
  * All fields are optional - TinyCloudNode can work with zero configuration.
@@ -1351,6 +1371,7 @@ declare class TinyCloudNode {
1351
1371
  * with expiry longer than the current session.
1352
1372
  * @internal
1353
1373
  */
1374
+ createOwnerDelegation(params: CreateOwnerDelegationParams): Promise<OwnerDelegationReceipt>;
1354
1375
  private createRootDelegationForSharing;
1355
1376
  /**
1356
1377
  * Track a received delegation in the capability registry.
@@ -1627,6 +1648,10 @@ declare class TinyCloudNode {
1627
1648
  * @returns Result indicating success or failure
1628
1649
  */
1629
1650
  revokeDelegation(cid: string): Promise<DelegationResult<void>>;
1651
+ /** Read node-confirmed lifecycle state for one delegation. */
1652
+ getDelegationStatus(cid: string): Promise<DelegationResult<DelegationStatus>>;
1653
+ /** Compute the canonical CID of a compact delegation authorization. */
1654
+ computeDelegationCid(authorization: string): string;
1630
1655
  /**
1631
1656
  * List all delegations for the current session's space.
1632
1657
  *
@@ -1956,4 +1981,4 @@ declare class WasmKeyProvider implements KeyProvider {
1956
1981
  */
1957
1982
  declare function createWasmKeyProvider(sessionManager: SessionManagerWithListing): WasmKeyProvider;
1958
1983
 
1959
- export { type AuthDelegationArtifact as A, type DelegateToOptions as D, FileSessionStorage as F, MemorySessionStorage as M, type NodeEventEmitterStrategy as N, type PortableDelegation as P, type RestorableSession as R, type SignStrategy as S, TinyCloudNode as T, WasmKeyProvider as W, type AuthRequestArtifact as a, type DelegateToResult as b, DelegatedAccess as c, type DelegationAuthority as d, NodeUserAuthorization as e, type NodeUserAuthorizationConfig as f, type RuntimePermissionGrantOptions as g, type TinyCloudNodeConfig as h, type WasmKeyProviderConfig as i, createWasmKeyProvider as j, defaultSignStrategy as k, deserializeDelegation as l, grantAuthRequest as m, serializeDelegation as s };
1984
+ export { type AuthDelegationArtifact as A, type CreateOwnerDelegationParams as C, type DelegateToOptions as D, FileSessionStorage as F, MemorySessionStorage as M, type NodeEventEmitterStrategy as N, type OwnerDelegationReceipt as O, type PortableDelegation as P, type RestorableSession as R, type SignStrategy as S, TinyCloudNode as T, WasmKeyProvider as W, type AuthRequestArtifact as a, type DelegateToResult as b, DelegatedAccess as c, type DelegationAuthority as d, NodeUserAuthorization as e, type NodeUserAuthorizationConfig as f, type RuntimePermissionGrantOptions as g, type TinyCloudNodeConfig as h, type WasmKeyProviderConfig as i, createWasmKeyProvider as j, defaultSignStrategy as k, deserializeDelegation as l, grantAuthRequest as m, serializeDelegation as s };
@@ -1,4 +1,4 @@
1
- import { ISessionStorage, PersistedSessionData, AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, IUserAuthorization, ISigner, ISpaceCreationHandler, IWasmBindings, ISessionManager, SiweConfig, Manifest, ComposedManifestRequest, ClientSession, TinyCloudSession, Extension, SignRequest, SignInOptions, Delegation, DelegatedResource, PermissionEntry, TelemetryConfig, IKVService, ISQLService, IDuckDbService, IHooksService, INotificationHandler, IENSResolver, AccountService, IDataVaultService, IEncryptionService, NetworkDescriptor, ISecretsService, ICapabilityKeyRegistry, DelegationManager, ISpaceService, ISpace, ISharingService, CreateDelegationParams, DelegationResult, ResolvedDelegate, KeyProvider, JWK } from '@tinycloud/sdk-core';
1
+ import { ISessionStorage, PersistedSessionData, AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, IUserAuthorization, ISigner, ISpaceCreationHandler, IWasmBindings, ISessionManager, SiweConfig, Manifest, ComposedManifestRequest, ClientSession, TinyCloudSession, Extension, SignRequest, SignInOptions, Delegation, DelegatedResource, PermissionEntry, TelemetryConfig, IKVService, ISQLService, IDuckDbService, IHooksService, INotificationHandler, IENSResolver, AccountService, IDataVaultService, IEncryptionService, NetworkDescriptor, ISecretsService, ICapabilityKeyRegistry, DelegationManager, ISpaceService, ISpace, ISharingService, CreateDelegationParams, DelegationResult, DelegationStatus, ResolvedDelegate, KeyProvider, JWK } from '@tinycloud/sdk-core';
2
2
  import { EventEmitter } from 'events';
3
3
  import { InvokeFunction, InvokeAnyFunction } from '@tinycloud/sdk-services';
4
4
 
@@ -757,6 +757,26 @@ declare class DelegatedAccess {
757
757
  * ```
758
758
  */
759
759
 
760
+ interface CreateOwnerDelegationParams {
761
+ readonly delegateDid: string;
762
+ readonly spaceId: string;
763
+ readonly path: string;
764
+ readonly actions: readonly string[];
765
+ readonly expiresAt: Date;
766
+ }
767
+ interface OwnerDelegationReceipt {
768
+ readonly delegation: Delegation;
769
+ /** Exact signed DAG-CBOR bytes submitted in the Authorization header. */
770
+ readonly signedDagCbor: Uint8Array;
771
+ /** Locally derived by the node WASM implementation; this is delegation identity. */
772
+ readonly delegationCid: string;
773
+ readonly nodeReceipt: {
774
+ /** Raw /delegate response CID: a commit-event id, not delegation identity. */
775
+ readonly commitEventCid?: string;
776
+ readonly activated: readonly string[];
777
+ readonly skipped: readonly string[];
778
+ };
779
+ }
760
780
  /**
761
781
  * Configuration for TinyCloudNode.
762
782
  * All fields are optional - TinyCloudNode can work with zero configuration.
@@ -1351,6 +1371,7 @@ declare class TinyCloudNode {
1351
1371
  * with expiry longer than the current session.
1352
1372
  * @internal
1353
1373
  */
1374
+ createOwnerDelegation(params: CreateOwnerDelegationParams): Promise<OwnerDelegationReceipt>;
1354
1375
  private createRootDelegationForSharing;
1355
1376
  /**
1356
1377
  * Track a received delegation in the capability registry.
@@ -1627,6 +1648,10 @@ declare class TinyCloudNode {
1627
1648
  * @returns Result indicating success or failure
1628
1649
  */
1629
1650
  revokeDelegation(cid: string): Promise<DelegationResult<void>>;
1651
+ /** Read node-confirmed lifecycle state for one delegation. */
1652
+ getDelegationStatus(cid: string): Promise<DelegationResult<DelegationStatus>>;
1653
+ /** Compute the canonical CID of a compact delegation authorization. */
1654
+ computeDelegationCid(authorization: string): string;
1630
1655
  /**
1631
1656
  * List all delegations for the current session's space.
1632
1657
  *
@@ -1956,4 +1981,4 @@ declare class WasmKeyProvider implements KeyProvider {
1956
1981
  */
1957
1982
  declare function createWasmKeyProvider(sessionManager: SessionManagerWithListing): WasmKeyProvider;
1958
1983
 
1959
- export { type AuthDelegationArtifact as A, type DelegateToOptions as D, FileSessionStorage as F, MemorySessionStorage as M, type NodeEventEmitterStrategy as N, type PortableDelegation as P, type RestorableSession as R, type SignStrategy as S, TinyCloudNode as T, WasmKeyProvider as W, type AuthRequestArtifact as a, type DelegateToResult as b, DelegatedAccess as c, type DelegationAuthority as d, NodeUserAuthorization as e, type NodeUserAuthorizationConfig as f, type RuntimePermissionGrantOptions as g, type TinyCloudNodeConfig as h, type WasmKeyProviderConfig as i, createWasmKeyProvider as j, defaultSignStrategy as k, deserializeDelegation as l, grantAuthRequest as m, serializeDelegation as s };
1984
+ export { type AuthDelegationArtifact as A, type CreateOwnerDelegationParams as C, type DelegateToOptions as D, FileSessionStorage as F, MemorySessionStorage as M, type NodeEventEmitterStrategy as N, type OwnerDelegationReceipt as O, type PortableDelegation as P, type RestorableSession as R, type SignStrategy as S, TinyCloudNode as T, WasmKeyProvider as W, type AuthRequestArtifact as a, type DelegateToResult as b, DelegatedAccess as c, type DelegationAuthority as d, NodeUserAuthorization as e, type NodeUserAuthorizationConfig as f, type RuntimePermissionGrantOptions as g, type TinyCloudNodeConfig as h, type WasmKeyProviderConfig as i, createWasmKeyProvider as j, defaultSignStrategy as k, deserializeDelegation as l, grantAuthRequest as m, serializeDelegation as s };
package/dist/core.cjs CHANGED
@@ -1680,6 +1680,22 @@ var ROOT_DELEGATION_ACTIONS = [
1680
1680
  import_sdk_core8.DUCKDB.ALL
1681
1681
  ];
1682
1682
  var DEFAULT_SESSION_EXPIRATION_MS = import_sdk_core8.EXPIRY.SESSION_MS;
1683
+ function decodeAuthorizationBytes(authorization) {
1684
+ const encoded = authorization.replace(/^Bearer /i, "");
1685
+ const match = /^([A-Za-z0-9_-]+)(={1,2})?$/.exec(encoded);
1686
+ const unpadded = match?.[1];
1687
+ const paddingLength = match?.[2]?.length ?? 0;
1688
+ const remainder = unpadded === void 0 ? 1 : unpadded.length % 4;
1689
+ const expectedPaddingLength = remainder === 2 ? 2 : remainder === 3 ? 1 : 0;
1690
+ if (unpadded === void 0 || remainder === 1 || paddingLength !== 0 && paddingLength !== expectedPaddingLength) {
1691
+ throw new Error("Delegation Authorization is not canonical base64url DAG-CBOR");
1692
+ }
1693
+ const decoded = Uint8Array.from(Buffer.from(unpadded, "base64url"));
1694
+ if (Buffer.from(decoded).toString("base64url") !== unpadded) {
1695
+ throw new Error("Delegation Authorization is not canonical base64url DAG-CBOR");
1696
+ }
1697
+ return decoded;
1698
+ }
1683
1699
  function isOpenKeyAutoSignStrategy(strategy) {
1684
1700
  return strategy?.openKeyAutoSign === true;
1685
1701
  }
@@ -1904,6 +1920,11 @@ var _TinyCloudNode = class _TinyCloudNode {
1904
1920
  fetch: globalThis.fetch.bind(globalThis),
1905
1921
  keyProvider: this._keyProvider,
1906
1922
  registry: this._capabilityRegistry,
1923
+ createDelegationWasm: (params) => this.createDelegationWrapper(params),
1924
+ computeCid: (data, codec) => {
1925
+ if (!this.wasmBindings.computeCid) throw new Error("computeCid is unavailable");
1926
+ return this.wasmBindings.computeCid(data, codec);
1927
+ },
1907
1928
  // delegationManager: undefined - not needed for receive()
1908
1929
  createKVService: (config2) => {
1909
1930
  const prefix = config2.pathPrefix?.replace(/\/$/, "");
@@ -3374,6 +3395,7 @@ var _TinyCloudNode = class _TinyCloudNode {
3374
3395
  hosts: [this.config.host],
3375
3396
  session: serviceSession,
3376
3397
  invoke: this.invokeWithRuntimePermissions,
3398
+ invokeAny: this.invokeAnyWithRuntimePermissions,
3377
3399
  fetch: globalThis.fetch.bind(globalThis)
3378
3400
  });
3379
3401
  this._spaceService = new import_sdk_core8.SpaceService({
@@ -3511,56 +3533,69 @@ var _TinyCloudNode = class _TinyCloudNode {
3511
3533
  * with expiry longer than the current session.
3512
3534
  * @internal
3513
3535
  */
3514
- async createRootDelegationForSharing(params) {
3515
- if (!this.signer) {
3516
- return void 0;
3536
+ async createOwnerDelegation(params) {
3537
+ if (!params.delegateDid.startsWith("did:key:") || params.actions.length === 0 || params.path.length === 0) {
3538
+ throw new Error("Owner delegation requires an external did:key audience and bounded capabilities");
3517
3539
  }
3540
+ const now = /* @__PURE__ */ new Date();
3541
+ if (params.expiresAt.getTime() <= now.getTime() || params.expiresAt.getTime() - now.getTime() > import_sdk_core8.EXPIRY.MAX_MS) {
3542
+ throw new Error("Owner delegation expiry must be explicit, future, and within EXPIRY.MAX_MS");
3543
+ }
3544
+ if (!this.signer) throw new Error("Owner wallet signer is required");
3518
3545
  const session = this.currentTinyCloudSession();
3519
- if (!session) {
3520
- return void 0;
3546
+ if (!session) throw new Error("Owner session is required");
3547
+ const abilities = sharingActionsToAbilities(params.path, [...params.actions]);
3548
+ if (!abilities) throw new Error("Owner delegation capabilities are unsupported");
3549
+ const host = this.config.host;
3550
+ const prepared = this.wasmBindings.prepareSession({
3551
+ abilities,
3552
+ address: this.wasmBindings.ensureEip55(session.address),
3553
+ chainId: session.chainId,
3554
+ domain: this.siweDomain,
3555
+ issuedAt: now.toISOString(),
3556
+ expirationTime: params.expiresAt.toISOString(),
3557
+ spaceId: params.spaceId,
3558
+ delegateUri: params.delegateDid
3559
+ });
3560
+ const signature = await this.signer.signMessage(prepared.siwe);
3561
+ const delegationSession = this.wasmBindings.completeSessionSetup({ ...prepared, signature });
3562
+ const activation = await (0, import_sdk_core8.activateSessionWithHost)(host, delegationSession.delegationHeader);
3563
+ if (!activation.success) {
3564
+ throw new Error(`Owner delegation import failed: ${activation.status} ${activation.error ?? ""}`.trim());
3521
3565
  }
3522
- try {
3523
- const host = this.config.host;
3524
- const now = /* @__PURE__ */ new Date();
3525
- const abilities = sharingActionsToAbilities(params.path, params.actions);
3526
- if (!abilities) {
3527
- return void 0;
3528
- }
3529
- const prepared = this.wasmBindings.prepareSession({
3530
- abilities,
3531
- address: this.wasmBindings.ensureEip55(session.address),
3532
- chainId: session.chainId,
3533
- domain: this.siweDomain,
3534
- issuedAt: now.toISOString(),
3535
- expirationTime: params.requestedExpiry.toISOString(),
3536
- spaceId: params.spaceId,
3537
- delegateUri: params.shareKeyDID
3538
- });
3539
- const signature = await this.signer.signMessage(prepared.siwe);
3540
- const delegationSession = this.wasmBindings.completeSessionSetup({
3541
- ...prepared,
3542
- signature
3543
- });
3544
- const activateResult = await (0, import_sdk_core8.activateSessionWithHost)(
3545
- host,
3546
- delegationSession.delegationHeader
3547
- );
3548
- if (!activateResult.success) {
3549
- return void 0;
3566
+ const delegation = {
3567
+ cid: delegationSession.delegationCid,
3568
+ delegateDID: params.delegateDid,
3569
+ delegatorDID: (0, import_sdk_core8.pkhDid)(session.address, session.chainId),
3570
+ spaceId: params.spaceId,
3571
+ path: params.path,
3572
+ actions: [...params.actions],
3573
+ expiry: params.expiresAt,
3574
+ isRevoked: false,
3575
+ allowSubDelegation: true,
3576
+ createdAt: now,
3577
+ authHeader: delegationSession.delegationHeader.Authorization
3578
+ };
3579
+ return {
3580
+ delegation,
3581
+ signedDagCbor: decodeAuthorizationBytes(delegationSession.delegationHeader.Authorization),
3582
+ delegationCid: delegationSession.delegationCid,
3583
+ nodeReceipt: {
3584
+ commitEventCid: activation.commitEventCid,
3585
+ activated: activation.activated ?? [],
3586
+ skipped: activation.skipped ?? []
3550
3587
  }
3551
- return {
3552
- cid: delegationSession.delegationCid,
3553
- delegateDID: params.shareKeyDID,
3554
- delegatorDID: (0, import_sdk_core8.pkhDid)(session.address, session.chainId),
3588
+ };
3589
+ }
3590
+ async createRootDelegationForSharing(params) {
3591
+ try {
3592
+ return (await this.createOwnerDelegation({
3593
+ delegateDid: params.shareKeyDID,
3555
3594
  spaceId: params.spaceId,
3556
3595
  path: params.path,
3557
3596
  actions: params.actions,
3558
- expiry: params.requestedExpiry,
3559
- isRevoked: false,
3560
- allowSubDelegation: true,
3561
- createdAt: now,
3562
- authHeader: delegationSession.delegationHeader.Authorization
3563
- };
3597
+ expiresAt: params.requestedExpiry
3598
+ })).delegation;
3564
3599
  } catch {
3565
3600
  return void 0;
3566
3601
  }
@@ -4328,6 +4363,20 @@ var _TinyCloudNode = class _TinyCloudNode {
4328
4363
  async revokeDelegation(cid) {
4329
4364
  return this.delegationManager.revoke(cid);
4330
4365
  }
4366
+ /** Read node-confirmed lifecycle state for one delegation. */
4367
+ async getDelegationStatus(cid) {
4368
+ return this.delegationManager.status(cid);
4369
+ }
4370
+ /** Compute the canonical CID of a compact delegation authorization. */
4371
+ computeDelegationCid(authorization) {
4372
+ if (!authorization || !this.wasmBindings.computeCid) {
4373
+ throw new Error("Delegation CID computation is unavailable");
4374
+ }
4375
+ return this.wasmBindings.computeCid(
4376
+ new TextEncoder().encode(authorization),
4377
+ 0x55n
4378
+ );
4379
+ }
4331
4380
  /**
4332
4381
  * List all delegations for the current session's space.
4333
4382
  *