@tinycloud/node-sdk 3.1.0-beta.1 → 3.1.0-beta.11

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.
@@ -758,6 +758,17 @@ interface PortableDelegation extends Omit<Delegation, "isRevoked"> {
758
758
  * fields are authoritative (legacy single-resource shape).
759
759
  */
760
760
  resources?: DelegatedResource[];
761
+ /**
762
+ * The wallet-signed SIWE message and EIP-191 signature behind a
763
+ * `delegationHeader` that is a CACAO session grant (OpenKey `/delegate`,
764
+ * {@link TinyCloudNode.grantRuntimePermissions}) rather than a compact UCAN.
765
+ * Not authority: activation rebuilds the CACAO from them and accepts only
766
+ * byte-identical authorization bytes.
767
+ */
768
+ siweProof?: {
769
+ siwe: string;
770
+ signature: string;
771
+ };
761
772
  }
762
773
  /**
763
774
  * The transport shape `tc auth request --emit` produces and that an owner
@@ -819,6 +830,11 @@ interface RuntimeDelegationActivator {
819
830
  useRuntimeDelegation(delegation: PortableDelegation): Promise<void>;
820
831
  useDelegation?(delegation: PortableDelegation): Promise<unknown>;
821
832
  getRuntimePermissionDelegations(): PortableDelegation[];
833
+ /**
834
+ * Verify a wallet-signed session grant issued to this runtime's live session
835
+ * key. Required to activate a CACAO grant; compact UCANs do not use it.
836
+ */
837
+ verifySessionGrant?(grant: SessionGrantProof): VerifiedSessionGrant;
822
838
  }
823
839
  /** The installed authority returned by {@link activateValidatedRuntimeDelegation}. */
824
840
  interface ValidatedRuntimeDelegation {
@@ -842,16 +858,59 @@ interface CompactRuntimeDelegationInput {
842
858
  readonly ownerAddress: string;
843
859
  readonly chainId: number;
844
860
  }
861
+ /** A CACAO session grant and the signed SIWE proof it was built from. */
862
+ interface SessionGrantProof {
863
+ readonly delegationHeader: {
864
+ Authorization: string;
865
+ };
866
+ readonly delegationCid: string;
867
+ readonly spaceId: string;
868
+ readonly address: string;
869
+ readonly chainId: number;
870
+ readonly siwe: string;
871
+ readonly signature: string;
872
+ }
873
+ /** Authority read from a verified session grant's signed ReCap. */
874
+ interface VerifiedSessionGrant {
875
+ readonly recap: readonly {
876
+ service: string;
877
+ space: string;
878
+ path: string;
879
+ actions: string[];
880
+ caveats?: Record<string, unknown>[];
881
+ }[];
882
+ readonly expiresAt: Date;
883
+ }
884
+ /**
885
+ * Stable reasons {@link activateValidatedRuntimeDelegation} refuses a
886
+ * delegation for. The error message is for the caller and may quote
887
+ * transport fields or a node's response; the reason is safe to publish.
888
+ */
889
+ declare const RUNTIME_DELEGATION_REJECTIONS: readonly ["host_mismatch", "expired", "cid_mismatch", "authority_invalid", "proof_missing", "proof_invalid", "owner_mismatch", "audience_mismatch", "resources_mismatch", "unsupported", "activation_rejected"];
890
+ type RuntimeDelegationRejection = typeof RUNTIME_DELEGATION_REJECTIONS[number];
891
+ declare class RuntimeDelegationRejectedError extends Error {
892
+ readonly reason: RuntimeDelegationRejection;
893
+ constructor(reason: RuntimeDelegationRejection, message: string);
894
+ }
845
895
  /**
846
- * CID-bind and activate one compact runtime delegation.
896
+ * CID-bind and activate one runtime delegation.
897
+ *
898
+ * A compact UCAN's audience, expiry and permissions come from its signed
899
+ * payload, and its transport fields must agree with them. A CACAO session
900
+ * grant (OpenKey `/delegate`, `grantRuntimePermissions`) is verified from its
901
+ * `siweProof` against this runtime's live session key; its installed
902
+ * authority is exactly the verified ReCap, and its transport `resources` are
903
+ * display data that is never consulted. Either way the helper then invokes
904
+ * {@link TinyCloudNode.useRuntimeDelegation}; the node activation call remains
905
+ * the authority and delegation-chain validation boundary.
847
906
  *
848
- * The helper derives audience, expiry, and effective permissions from the
849
- * compact UCAN's signed payload, verifies the transport fields agree, then
850
- * invokes {@link TinyCloudNode.useRuntimeDelegation}. The node activation call
851
- * remains the authority and delegation-chain validation boundary.
907
+ * `options.authorize`, when given, sees the signed capabilities before
908
+ * anything is activated or installed; returning `false` refuses the
909
+ * delegation.
852
910
  */
853
911
  declare function activateValidatedRuntimeDelegation(node: RuntimeDelegationActivator, delegation: PortableDelegation, options: {
854
912
  host: string;
913
+ authorize?: (effectivePermissions: readonly PermissionEntry[]) => boolean;
855
914
  }): Promise<ValidatedRuntimeDelegation>;
856
915
  /**
857
916
  * Import compact UCAN bytes returned by an authority ceremony through the
@@ -1445,6 +1504,9 @@ declare class TinyCloudNode {
1445
1504
  private resolveBootstrapDecision;
1446
1505
  private readBootstrapCompletionMarker;
1447
1506
  private writeBootstrapCompletionMarker;
1507
+ /**
1508
+ * A marker written before a canonical space was added triggers one bounded repair.
1509
+ */
1448
1510
  private isAcceptedBootstrapCompletionMarker;
1449
1511
  private markerReadIsUnhostedSpace;
1450
1512
  private runAccountBootstrap;
@@ -1966,6 +2028,18 @@ declare class TinyCloudNode {
1966
2028
  * live authority must combine this with {@link getVerifiedSessionCapabilities}.
1967
2029
  */
1968
2030
  getEffectiveRuntimePermissionEntries(): PermissionEntry[];
2031
+ /**
2032
+ * Verify a wallet-signed session grant (a CACAO built from a SIWE and its
2033
+ * EIP-191 signature) issued to this instance's live session key. The
2034
+ * verifier rebuilds the CACAO from `siwe` and `signature`, so the grant is
2035
+ * accepted only when its authorization bytes and CID are exactly that CACAO,
2036
+ * its signer is `address`, its audience is this session key, it is valid
2037
+ * now, and its ReCap covers `spaceId` or names only raw encryption networks
2038
+ * (a decrypt-only grant has no space). Returns the signed ReCap and expiry.
2039
+ * Bindings without `validateSessionGrant` fall back to the session verifier,
2040
+ * which also refuses decrypt-only grants.
2041
+ */
2042
+ verifySessionGrant(grant: SessionGrantProof): VerifiedSessionGrant;
1969
2043
  /**
1970
2044
  * Install a portable runtime permission delegation into this SDK instance so
1971
2045
  * matching service calls and downstream `delegateTo()` calls can use it.
@@ -2474,4 +2548,4 @@ declare class WasmKeyProvider implements KeyProvider {
2474
2548
  */
2475
2549
  declare function createWasmKeyProvider(sessionManager: SessionManagerWithListing): WasmKeyProvider;
2476
2550
 
2477
- export { ACCEPTED_MARKER_VERSIONS as A, BOOTSTRAP_COMPLETION_MARKER_KEY as B, type CompactRuntimeDelegationInput as C, type DelegateToOptions as D, type EnsureEncryptionNetworkOptions as E, FileSessionStorage as F, serializeDelegation as G, InvalidRestoredSessionError as I, MemorySessionStorage as M, type NodeEventEmitterStrategy as N, type OwnerDelegationReceipt as O, type PortableDelegation as P, type RestorableSession as R, type SecretPermissionHint as S, TinyCloudNode as T, type UnifiedOwnerRootInput as U, type ValidatedRuntimeDelegation as V, WasmKeyProvider as W, type AuthDelegationArtifact as a, type AuthRequestArtifact as b, BOOTSTRAP_COMPLETION_MARKER_VERSION as c, type BootstrapCompletionMarker as d, type BootstrapWarning as e, type CreateOwnerDelegationParams as f, type DelegateToResult as g, DelegatedAccess as h, type DelegationAuthority as i, NodeUserAuthorization as j, type NodeUserAuthorizationConfig as k, type RuntimeDelegationActivator as l, type RuntimePermissionGrantOptions as m, type SecretReadInput as n, type SecretReadResult as o, type SignStrategy as p, type TinyCloudNodeConfig as q, type UnifiedOwnerRootReceipt as r, UnsupportedSessionRestoreError as s, type WasmKeyProviderConfig as t, activateCompactRuntimeDelegation as u, activateValidatedRuntimeDelegation as v, createWasmKeyProvider as w, defaultSignStrategy as x, deserializeDelegation as y, grantAuthRequest as z };
2551
+ export { ACCEPTED_MARKER_VERSIONS as A, BOOTSTRAP_COMPLETION_MARKER_KEY as B, type CompactRuntimeDelegationInput as C, type DelegateToOptions as D, type EnsureEncryptionNetworkOptions as E, FileSessionStorage as F, activateValidatedRuntimeDelegation as G, createWasmKeyProvider as H, InvalidRestoredSessionError as I, defaultSignStrategy as J, deserializeDelegation as K, grantAuthRequest as L, MemorySessionStorage as M, type NodeEventEmitterStrategy as N, type OwnerDelegationReceipt as O, type PortableDelegation as P, serializeDelegation as Q, RUNTIME_DELEGATION_REJECTIONS as R, type SecretPermissionHint as S, TinyCloudNode as T, type UnifiedOwnerRootInput as U, type ValidatedRuntimeDelegation as V, WasmKeyProvider as W, type AuthDelegationArtifact as a, type AuthRequestArtifact as b, BOOTSTRAP_COMPLETION_MARKER_VERSION as c, type BootstrapCompletionMarker as d, type BootstrapWarning as e, type CreateOwnerDelegationParams as f, type DelegateToResult as g, DelegatedAccess as h, type DelegationAuthority as i, NodeUserAuthorization as j, type NodeUserAuthorizationConfig as k, type RestorableSession as l, type RuntimeDelegationActivator as m, RuntimeDelegationRejectedError as n, type RuntimeDelegationRejection as o, type RuntimePermissionGrantOptions as p, type SecretReadInput as q, type SecretReadResult as r, type SessionGrantProof as s, type SignStrategy as t, type TinyCloudNodeConfig as u, type UnifiedOwnerRootReceipt as v, UnsupportedSessionRestoreError as w, type VerifiedSessionGrant as x, type WasmKeyProviderConfig as y, activateCompactRuntimeDelegation as z };
@@ -758,6 +758,17 @@ interface PortableDelegation extends Omit<Delegation, "isRevoked"> {
758
758
  * fields are authoritative (legacy single-resource shape).
759
759
  */
760
760
  resources?: DelegatedResource[];
761
+ /**
762
+ * The wallet-signed SIWE message and EIP-191 signature behind a
763
+ * `delegationHeader` that is a CACAO session grant (OpenKey `/delegate`,
764
+ * {@link TinyCloudNode.grantRuntimePermissions}) rather than a compact UCAN.
765
+ * Not authority: activation rebuilds the CACAO from them and accepts only
766
+ * byte-identical authorization bytes.
767
+ */
768
+ siweProof?: {
769
+ siwe: string;
770
+ signature: string;
771
+ };
761
772
  }
762
773
  /**
763
774
  * The transport shape `tc auth request --emit` produces and that an owner
@@ -819,6 +830,11 @@ interface RuntimeDelegationActivator {
819
830
  useRuntimeDelegation(delegation: PortableDelegation): Promise<void>;
820
831
  useDelegation?(delegation: PortableDelegation): Promise<unknown>;
821
832
  getRuntimePermissionDelegations(): PortableDelegation[];
833
+ /**
834
+ * Verify a wallet-signed session grant issued to this runtime's live session
835
+ * key. Required to activate a CACAO grant; compact UCANs do not use it.
836
+ */
837
+ verifySessionGrant?(grant: SessionGrantProof): VerifiedSessionGrant;
822
838
  }
823
839
  /** The installed authority returned by {@link activateValidatedRuntimeDelegation}. */
824
840
  interface ValidatedRuntimeDelegation {
@@ -842,16 +858,59 @@ interface CompactRuntimeDelegationInput {
842
858
  readonly ownerAddress: string;
843
859
  readonly chainId: number;
844
860
  }
861
+ /** A CACAO session grant and the signed SIWE proof it was built from. */
862
+ interface SessionGrantProof {
863
+ readonly delegationHeader: {
864
+ Authorization: string;
865
+ };
866
+ readonly delegationCid: string;
867
+ readonly spaceId: string;
868
+ readonly address: string;
869
+ readonly chainId: number;
870
+ readonly siwe: string;
871
+ readonly signature: string;
872
+ }
873
+ /** Authority read from a verified session grant's signed ReCap. */
874
+ interface VerifiedSessionGrant {
875
+ readonly recap: readonly {
876
+ service: string;
877
+ space: string;
878
+ path: string;
879
+ actions: string[];
880
+ caveats?: Record<string, unknown>[];
881
+ }[];
882
+ readonly expiresAt: Date;
883
+ }
884
+ /**
885
+ * Stable reasons {@link activateValidatedRuntimeDelegation} refuses a
886
+ * delegation for. The error message is for the caller and may quote
887
+ * transport fields or a node's response; the reason is safe to publish.
888
+ */
889
+ declare const RUNTIME_DELEGATION_REJECTIONS: readonly ["host_mismatch", "expired", "cid_mismatch", "authority_invalid", "proof_missing", "proof_invalid", "owner_mismatch", "audience_mismatch", "resources_mismatch", "unsupported", "activation_rejected"];
890
+ type RuntimeDelegationRejection = typeof RUNTIME_DELEGATION_REJECTIONS[number];
891
+ declare class RuntimeDelegationRejectedError extends Error {
892
+ readonly reason: RuntimeDelegationRejection;
893
+ constructor(reason: RuntimeDelegationRejection, message: string);
894
+ }
845
895
  /**
846
- * CID-bind and activate one compact runtime delegation.
896
+ * CID-bind and activate one runtime delegation.
897
+ *
898
+ * A compact UCAN's audience, expiry and permissions come from its signed
899
+ * payload, and its transport fields must agree with them. A CACAO session
900
+ * grant (OpenKey `/delegate`, `grantRuntimePermissions`) is verified from its
901
+ * `siweProof` against this runtime's live session key; its installed
902
+ * authority is exactly the verified ReCap, and its transport `resources` are
903
+ * display data that is never consulted. Either way the helper then invokes
904
+ * {@link TinyCloudNode.useRuntimeDelegation}; the node activation call remains
905
+ * the authority and delegation-chain validation boundary.
847
906
  *
848
- * The helper derives audience, expiry, and effective permissions from the
849
- * compact UCAN's signed payload, verifies the transport fields agree, then
850
- * invokes {@link TinyCloudNode.useRuntimeDelegation}. The node activation call
851
- * remains the authority and delegation-chain validation boundary.
907
+ * `options.authorize`, when given, sees the signed capabilities before
908
+ * anything is activated or installed; returning `false` refuses the
909
+ * delegation.
852
910
  */
853
911
  declare function activateValidatedRuntimeDelegation(node: RuntimeDelegationActivator, delegation: PortableDelegation, options: {
854
912
  host: string;
913
+ authorize?: (effectivePermissions: readonly PermissionEntry[]) => boolean;
855
914
  }): Promise<ValidatedRuntimeDelegation>;
856
915
  /**
857
916
  * Import compact UCAN bytes returned by an authority ceremony through the
@@ -1445,6 +1504,9 @@ declare class TinyCloudNode {
1445
1504
  private resolveBootstrapDecision;
1446
1505
  private readBootstrapCompletionMarker;
1447
1506
  private writeBootstrapCompletionMarker;
1507
+ /**
1508
+ * A marker written before a canonical space was added triggers one bounded repair.
1509
+ */
1448
1510
  private isAcceptedBootstrapCompletionMarker;
1449
1511
  private markerReadIsUnhostedSpace;
1450
1512
  private runAccountBootstrap;
@@ -1966,6 +2028,18 @@ declare class TinyCloudNode {
1966
2028
  * live authority must combine this with {@link getVerifiedSessionCapabilities}.
1967
2029
  */
1968
2030
  getEffectiveRuntimePermissionEntries(): PermissionEntry[];
2031
+ /**
2032
+ * Verify a wallet-signed session grant (a CACAO built from a SIWE and its
2033
+ * EIP-191 signature) issued to this instance's live session key. The
2034
+ * verifier rebuilds the CACAO from `siwe` and `signature`, so the grant is
2035
+ * accepted only when its authorization bytes and CID are exactly that CACAO,
2036
+ * its signer is `address`, its audience is this session key, it is valid
2037
+ * now, and its ReCap covers `spaceId` or names only raw encryption networks
2038
+ * (a decrypt-only grant has no space). Returns the signed ReCap and expiry.
2039
+ * Bindings without `validateSessionGrant` fall back to the session verifier,
2040
+ * which also refuses decrypt-only grants.
2041
+ */
2042
+ verifySessionGrant(grant: SessionGrantProof): VerifiedSessionGrant;
1969
2043
  /**
1970
2044
  * Install a portable runtime permission delegation into this SDK instance so
1971
2045
  * matching service calls and downstream `delegateTo()` calls can use it.
@@ -2474,4 +2548,4 @@ declare class WasmKeyProvider implements KeyProvider {
2474
2548
  */
2475
2549
  declare function createWasmKeyProvider(sessionManager: SessionManagerWithListing): WasmKeyProvider;
2476
2550
 
2477
- export { ACCEPTED_MARKER_VERSIONS as A, BOOTSTRAP_COMPLETION_MARKER_KEY as B, type CompactRuntimeDelegationInput as C, type DelegateToOptions as D, type EnsureEncryptionNetworkOptions as E, FileSessionStorage as F, serializeDelegation as G, InvalidRestoredSessionError as I, MemorySessionStorage as M, type NodeEventEmitterStrategy as N, type OwnerDelegationReceipt as O, type PortableDelegation as P, type RestorableSession as R, type SecretPermissionHint as S, TinyCloudNode as T, type UnifiedOwnerRootInput as U, type ValidatedRuntimeDelegation as V, WasmKeyProvider as W, type AuthDelegationArtifact as a, type AuthRequestArtifact as b, BOOTSTRAP_COMPLETION_MARKER_VERSION as c, type BootstrapCompletionMarker as d, type BootstrapWarning as e, type CreateOwnerDelegationParams as f, type DelegateToResult as g, DelegatedAccess as h, type DelegationAuthority as i, NodeUserAuthorization as j, type NodeUserAuthorizationConfig as k, type RuntimeDelegationActivator as l, type RuntimePermissionGrantOptions as m, type SecretReadInput as n, type SecretReadResult as o, type SignStrategy as p, type TinyCloudNodeConfig as q, type UnifiedOwnerRootReceipt as r, UnsupportedSessionRestoreError as s, type WasmKeyProviderConfig as t, activateCompactRuntimeDelegation as u, activateValidatedRuntimeDelegation as v, createWasmKeyProvider as w, defaultSignStrategy as x, deserializeDelegation as y, grantAuthRequest as z };
2551
+ export { ACCEPTED_MARKER_VERSIONS as A, BOOTSTRAP_COMPLETION_MARKER_KEY as B, type CompactRuntimeDelegationInput as C, type DelegateToOptions as D, type EnsureEncryptionNetworkOptions as E, FileSessionStorage as F, activateValidatedRuntimeDelegation as G, createWasmKeyProvider as H, InvalidRestoredSessionError as I, defaultSignStrategy as J, deserializeDelegation as K, grantAuthRequest as L, MemorySessionStorage as M, type NodeEventEmitterStrategy as N, type OwnerDelegationReceipt as O, type PortableDelegation as P, serializeDelegation as Q, RUNTIME_DELEGATION_REJECTIONS as R, type SecretPermissionHint as S, TinyCloudNode as T, type UnifiedOwnerRootInput as U, type ValidatedRuntimeDelegation as V, WasmKeyProvider as W, type AuthDelegationArtifact as a, type AuthRequestArtifact as b, BOOTSTRAP_COMPLETION_MARKER_VERSION as c, type BootstrapCompletionMarker as d, type BootstrapWarning as e, type CreateOwnerDelegationParams as f, type DelegateToResult as g, DelegatedAccess as h, type DelegationAuthority as i, NodeUserAuthorization as j, type NodeUserAuthorizationConfig as k, type RestorableSession as l, type RuntimeDelegationActivator as m, RuntimeDelegationRejectedError as n, type RuntimeDelegationRejection as o, type RuntimePermissionGrantOptions as p, type SecretReadInput as q, type SecretReadResult as r, type SessionGrantProof as s, type SignStrategy as t, type TinyCloudNodeConfig as u, type UnifiedOwnerRootReceipt as v, UnsupportedSessionRestoreError as w, type VerifiedSessionGrant as x, type WasmKeyProviderConfig as y, activateCompactRuntimeDelegation as z };