@tinycloud/node-sdk 2.4.0-beta.1 → 2.4.0-beta.3

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, SiweConfig, Manifest, ComposedManifestRequest, ClientSession, TinyCloudSession, Extension, SignInOptions, Delegation, DelegatedResource, TelemetryConfig, IKVService, ISQLService, IDuckDbService, IHooksService, INotificationHandler, IENSResolver, IDataVaultService, IEncryptionService, NetworkDescriptor, ISecretsService, ICapabilityKeyRegistry, PermissionEntry, DelegationManager, ISpaceService, ISpace, ISharingService, CreateDelegationParams, DelegationResult, ResolvedDelegate, KeyProvider, ISessionManager, JWK } from '@tinycloud/sdk-core';
1
+ import { ISessionStorage, PersistedSessionData, AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, IUserAuthorization, ISigner, ISpaceCreationHandler, IWasmBindings, SiweConfig, Manifest, ComposedManifestRequest, ClientSession, TinyCloudSession, Extension, SignInOptions, Delegation, DelegatedResource, PermissionEntry, TelemetryConfig, IKVService, ISQLService, IDuckDbService, IHooksService, INotificationHandler, IENSResolver, IDataVaultService, IEncryptionService, NetworkDescriptor, ISecretsService, ICapabilityKeyRegistry, DelegationManager, ISpaceService, ISpace, ISharingService, CreateDelegationParams, DelegationResult, ResolvedDelegate, KeyProvider, ISessionManager, JWK } from '@tinycloud/sdk-core';
2
2
  import { EventEmitter } from 'events';
3
3
  import { InvokeFunction } from '@tinycloud/sdk-services';
4
4
 
@@ -540,6 +540,69 @@ interface PortableDelegation extends Omit<Delegation, "isRevoked"> {
540
540
  */
541
541
  resources?: DelegatedResource[];
542
542
  }
543
+ /**
544
+ * The transport shape `tc auth request --emit` produces and that an owner
545
+ * grants to its requester. Only the fields the grant logic needs are declared;
546
+ * the CLI artifact carries more (posture, captured command, ...) and remains a
547
+ * structural superset of this interface.
548
+ */
549
+ interface AuthRequestArtifact {
550
+ kind: "tinycloud.auth.request";
551
+ version: 1;
552
+ requestId: string;
553
+ /** The requester's session DID — the audience the grant is issued to. */
554
+ sessionDid: string;
555
+ /** The capabilities the requester is asking the owner to delegate. */
556
+ requested: PermissionEntry[];
557
+ /** Optional lifetime override carried from the request. */
558
+ requestedExpiry?: string | number;
559
+ }
560
+ /**
561
+ * The transport shape returned by {@link grantAuthRequest} (and written by
562
+ * `tc auth grant`). `tc auth import` accepts this artifact directly.
563
+ */
564
+ interface AuthDelegationArtifact {
565
+ kind: "tinycloud.auth.delegation";
566
+ version: 1;
567
+ requestId: string;
568
+ delegationCid: string;
569
+ delegation: PortableDelegation;
570
+ permissions: PermissionEntry[];
571
+ expiry: string;
572
+ /** Whether issuing the delegation triggered a wallet prompt. */
573
+ prompted: boolean;
574
+ }
575
+ /**
576
+ * Minimal owner-side capability {@link grantAuthRequest} needs: the signed
577
+ * `delegateTo` primitive. `TinyCloudNode` satisfies this directly; web/SDK
578
+ * contexts can supply any object that exposes the same method.
579
+ */
580
+ interface DelegationAuthority {
581
+ delegateTo(did: string, permissions: PermissionEntry[], options?: {
582
+ expiry?: string | number;
583
+ forceWalletSign?: boolean;
584
+ }): Promise<{
585
+ delegation: PortableDelegation;
586
+ prompted: boolean;
587
+ }>;
588
+ }
589
+ /**
590
+ * Turn a delegation REQUEST into a signed GRANT.
591
+ *
592
+ * Lifts the body of `tc auth grant` into the SDK so the request→grant
593
+ * handshake is callable programmatically (future SDK/web owner tooling and the
594
+ * KV delegation inbox), with the CLI verb reduced to a thin wrapper. The owner
595
+ * `authority` (a `TinyCloudNode`) signs a delegation scoped to exactly the
596
+ * requested caps, audienced to the requester's `sessionDid`, honoring the
597
+ * request's expiry. The returned artifact round-trips through `tc auth import`.
598
+ *
599
+ * Authorization is enforced cryptographically by `delegateTo`: caps that are
600
+ * not derivable from the owner's own session capability chain are rejected
601
+ * (it throws), so this never widens authority the owner doesn't hold.
602
+ */
603
+ declare function grantAuthRequest(authority: DelegationAuthority, request: AuthRequestArtifact, options?: {
604
+ expiry?: string | number;
605
+ }): Promise<AuthDelegationArtifact>;
543
606
  /**
544
607
  * Serialize a PortableDelegation for transport (e.g., over network).
545
608
  */
@@ -1475,6 +1538,8 @@ declare class TinyCloudNode {
1475
1538
  private findGrantForOperation;
1476
1539
  private pruneExpiredRuntimePermissionGrants;
1477
1540
  private operationCovers;
1541
+ private spaceIdsEqual;
1542
+ private normalizeSpaceAddress;
1478
1543
  private actionContains;
1479
1544
  private invocationServiceName;
1480
1545
  private isEncryptionNetworkOperation;
@@ -1669,4 +1734,4 @@ declare class WasmKeyProvider implements KeyProvider {
1669
1734
  */
1670
1735
  declare function createWasmKeyProvider(sessionManager: SessionManagerWithListing): WasmKeyProvider;
1671
1736
 
1672
- export { 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 DelegateToResult as a, DelegatedAccess as b, NodeUserAuthorization as c, type NodeUserAuthorizationConfig as d, type RuntimePermissionGrantOptions as e, type TinyCloudNodeConfig as f, type WasmKeyProviderConfig as g, createWasmKeyProvider as h, defaultSignStrategy as i, deserializeDelegation as j, serializeDelegation as s };
1737
+ 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 };
@@ -1,4 +1,4 @@
1
- import { ISessionStorage, PersistedSessionData, AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, IUserAuthorization, ISigner, ISpaceCreationHandler, IWasmBindings, SiweConfig, Manifest, ComposedManifestRequest, ClientSession, TinyCloudSession, Extension, SignInOptions, Delegation, DelegatedResource, TelemetryConfig, IKVService, ISQLService, IDuckDbService, IHooksService, INotificationHandler, IENSResolver, IDataVaultService, IEncryptionService, NetworkDescriptor, ISecretsService, ICapabilityKeyRegistry, PermissionEntry, DelegationManager, ISpaceService, ISpace, ISharingService, CreateDelegationParams, DelegationResult, ResolvedDelegate, KeyProvider, ISessionManager, JWK } from '@tinycloud/sdk-core';
1
+ import { ISessionStorage, PersistedSessionData, AutoSignStrategy, AutoRejectStrategy, CallbackStrategy, IUserAuthorization, ISigner, ISpaceCreationHandler, IWasmBindings, SiweConfig, Manifest, ComposedManifestRequest, ClientSession, TinyCloudSession, Extension, SignInOptions, Delegation, DelegatedResource, PermissionEntry, TelemetryConfig, IKVService, ISQLService, IDuckDbService, IHooksService, INotificationHandler, IENSResolver, IDataVaultService, IEncryptionService, NetworkDescriptor, ISecretsService, ICapabilityKeyRegistry, DelegationManager, ISpaceService, ISpace, ISharingService, CreateDelegationParams, DelegationResult, ResolvedDelegate, KeyProvider, ISessionManager, JWK } from '@tinycloud/sdk-core';
2
2
  import { EventEmitter } from 'events';
3
3
  import { InvokeFunction } from '@tinycloud/sdk-services';
4
4
 
@@ -540,6 +540,69 @@ interface PortableDelegation extends Omit<Delegation, "isRevoked"> {
540
540
  */
541
541
  resources?: DelegatedResource[];
542
542
  }
543
+ /**
544
+ * The transport shape `tc auth request --emit` produces and that an owner
545
+ * grants to its requester. Only the fields the grant logic needs are declared;
546
+ * the CLI artifact carries more (posture, captured command, ...) and remains a
547
+ * structural superset of this interface.
548
+ */
549
+ interface AuthRequestArtifact {
550
+ kind: "tinycloud.auth.request";
551
+ version: 1;
552
+ requestId: string;
553
+ /** The requester's session DID — the audience the grant is issued to. */
554
+ sessionDid: string;
555
+ /** The capabilities the requester is asking the owner to delegate. */
556
+ requested: PermissionEntry[];
557
+ /** Optional lifetime override carried from the request. */
558
+ requestedExpiry?: string | number;
559
+ }
560
+ /**
561
+ * The transport shape returned by {@link grantAuthRequest} (and written by
562
+ * `tc auth grant`). `tc auth import` accepts this artifact directly.
563
+ */
564
+ interface AuthDelegationArtifact {
565
+ kind: "tinycloud.auth.delegation";
566
+ version: 1;
567
+ requestId: string;
568
+ delegationCid: string;
569
+ delegation: PortableDelegation;
570
+ permissions: PermissionEntry[];
571
+ expiry: string;
572
+ /** Whether issuing the delegation triggered a wallet prompt. */
573
+ prompted: boolean;
574
+ }
575
+ /**
576
+ * Minimal owner-side capability {@link grantAuthRequest} needs: the signed
577
+ * `delegateTo` primitive. `TinyCloudNode` satisfies this directly; web/SDK
578
+ * contexts can supply any object that exposes the same method.
579
+ */
580
+ interface DelegationAuthority {
581
+ delegateTo(did: string, permissions: PermissionEntry[], options?: {
582
+ expiry?: string | number;
583
+ forceWalletSign?: boolean;
584
+ }): Promise<{
585
+ delegation: PortableDelegation;
586
+ prompted: boolean;
587
+ }>;
588
+ }
589
+ /**
590
+ * Turn a delegation REQUEST into a signed GRANT.
591
+ *
592
+ * Lifts the body of `tc auth grant` into the SDK so the request→grant
593
+ * handshake is callable programmatically (future SDK/web owner tooling and the
594
+ * KV delegation inbox), with the CLI verb reduced to a thin wrapper. The owner
595
+ * `authority` (a `TinyCloudNode`) signs a delegation scoped to exactly the
596
+ * requested caps, audienced to the requester's `sessionDid`, honoring the
597
+ * request's expiry. The returned artifact round-trips through `tc auth import`.
598
+ *
599
+ * Authorization is enforced cryptographically by `delegateTo`: caps that are
600
+ * not derivable from the owner's own session capability chain are rejected
601
+ * (it throws), so this never widens authority the owner doesn't hold.
602
+ */
603
+ declare function grantAuthRequest(authority: DelegationAuthority, request: AuthRequestArtifact, options?: {
604
+ expiry?: string | number;
605
+ }): Promise<AuthDelegationArtifact>;
543
606
  /**
544
607
  * Serialize a PortableDelegation for transport (e.g., over network).
545
608
  */
@@ -1475,6 +1538,8 @@ declare class TinyCloudNode {
1475
1538
  private findGrantForOperation;
1476
1539
  private pruneExpiredRuntimePermissionGrants;
1477
1540
  private operationCovers;
1541
+ private spaceIdsEqual;
1542
+ private normalizeSpaceAddress;
1478
1543
  private actionContains;
1479
1544
  private invocationServiceName;
1480
1545
  private isEncryptionNetworkOperation;
@@ -1669,4 +1734,4 @@ declare class WasmKeyProvider implements KeyProvider {
1669
1734
  */
1670
1735
  declare function createWasmKeyProvider(sessionManager: SessionManagerWithListing): WasmKeyProvider;
1671
1736
 
1672
- export { 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 DelegateToResult as a, DelegatedAccess as b, NodeUserAuthorization as c, type NodeUserAuthorizationConfig as d, type RuntimePermissionGrantOptions as e, type TinyCloudNodeConfig as f, type WasmKeyProviderConfig as g, createWasmKeyProvider as h, defaultSignStrategy as i, deserializeDelegation as j, serializeDelegation as s };
1737
+ 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 };
package/dist/core.cjs CHANGED
@@ -4088,7 +4088,23 @@ var _TinyCloudNode = class _TinyCloudNode {
4088
4088
  if (granted.resource !== void 0 || requested.resource !== void 0) {
4089
4089
  return granted.resource !== void 0 && requested.resource !== void 0 && granted.resource === requested.resource && this.pathContains(granted.path, requested.path);
4090
4090
  }
4091
- return granted.spaceId !== void 0 && requested.spaceId !== void 0 && granted.spaceId === requested.spaceId && this.pathContains(granted.path, requested.path);
4091
+ return granted.spaceId !== void 0 && requested.spaceId !== void 0 && this.spaceIdsEqual(granted.spaceId, requested.spaceId) && this.pathContains(granted.path, requested.path);
4092
+ }
4093
+ // Space IDs are `tinycloud:pkh:eip155:<chain>:<0xADDR>:<name>`. The embedded
4094
+ // EIP-155 address is case-insensitive, but the CLI canonicalizes it to
4095
+ // lowercase when building a space URI while stored runtime delegations keep
4096
+ // the EIP-55 checksummed form — so a byte-for-byte compare spuriously rejects
4097
+ // an otherwise-valid grant. Lowercase ONLY the `eip155:<chain>:0x<addr>`
4098
+ // segment and leave everything else (crucially the case-sensitive space NAME)
4099
+ // byte-exact. Mirrors the CLI's `normalizeSpaceForCompare` (OPENKEY_SCOPE_MISMATCH fix).
4100
+ spaceIdsEqual(a, b) {
4101
+ return this.normalizeSpaceAddress(a) === this.normalizeSpaceAddress(b);
4102
+ }
4103
+ normalizeSpaceAddress(space) {
4104
+ return space.replace(
4105
+ /(eip155:\d+:)(0x[0-9a-fA-F]{40})/,
4106
+ (_match, prefix, addr) => prefix + addr.toLowerCase()
4107
+ );
4092
4108
  }
4093
4109
  actionContains(grantedAction, requestedAction) {
4094
4110
  if (grantedAction === requestedAction) {