@tinycloud/sdk-core 3.0.0-beta.9 → 3.0.1-beta.0

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.
@@ -718,17 +718,28 @@ interface CompactPolicyInvocationInput {
718
718
  }
719
719
  /** Sign a fresh one-parent ordinary invocation; S0 itself is never a bearer. */
720
720
  declare function createCompactPolicyInvocation(input: CompactPolicyInvocationInput): CompactUcanAuthorizationV1;
721
- declare function createCompactPolicyDescendant(input: {
721
+ interface CompactPolicyDescendantInput {
722
722
  readonly parentAuthorization: string;
723
723
  readonly parentCid: string;
724
724
  readonly issuerDid: string;
725
725
  readonly audienceDid: string;
726
726
  readonly attenuation: Readonly<Record<string, Readonly<Record<string, readonly unknown[]>>>>;
727
- readonly privateKey: Uint8Array;
727
+ /** Start of the window; defaults to one second after the parent's start. */
728
728
  readonly now?: number;
729
+ /** Defaults to the longest window the parent allows: one second inside it. */
729
730
  readonly expiresAt?: number;
730
731
  readonly nonce?: string;
732
+ }
733
+ declare function createCompactPolicyDescendant(input: CompactPolicyDescendantInput & {
734
+ readonly privateKey: Uint8Array;
731
735
  }): CompactUcanAuthorizationV1;
736
+ /**
737
+ * The same descendant, signed by a caller-owned key that may be
738
+ * non-extractable. The result is verified against the issuer DID.
739
+ */
740
+ declare function signCompactPolicyDescendant(input: CompactPolicyDescendantInput & {
741
+ readonly sign: (bytes: Uint8Array) => Promise<Uint8Array>;
742
+ }): Promise<CompactUcanAuthorizationV1>;
732
743
  /** Byte-independent semantic containment shared by S0, descendants and mint requests. */
733
744
  declare function compactAttenuationContains(parent: Readonly<Record<string, Readonly<Record<string, readonly unknown[]>>>>, child: Readonly<Record<string, Readonly<Record<string, readonly unknown[]>>>>): boolean;
734
745
  declare function parseCompactUcanAuthorization(input: string, expectedCid?: string): CompactUcanAuthorizationV1;
@@ -864,6 +875,8 @@ interface AdmitPolicyCredentialV3Input extends Omit<BuildPolicyCredentialPresent
864
875
  readonly accountAuthorizationCid: string;
865
876
  /** Recipient-owned `credentials` space covered by the account authorization. */
866
877
  readonly credentialSpaceId: string;
878
+ /** See {@link AdmitPolicyCredentialV4Input.requestedExpiresAt}. */
879
+ readonly requestedExpiresAt?: string | null;
867
880
  readonly fetch?: typeof fetch;
868
881
  readonly signal?: AbortSignal;
869
882
  }
@@ -885,6 +898,13 @@ interface AdmitPolicyCredentialV4Input extends Omit<BuildPolicyCredentialPresent
885
898
  readonly nodeOrigin: string;
886
899
  /** Path to the embedded Node policy runtime. Defaults to `/policy/v3`. */
887
900
  readonly policyRuntimePath?: string;
901
+ /**
902
+ * How long the minted session should last. Defaults to the policy's own
903
+ * expiry, the longest the Node will grant; it caps the session at the
904
+ * policy, its roots and any account authorization. `null` asks for the
905
+ * legacy 60-second session.
906
+ */
907
+ readonly requestedExpiresAt?: string | null;
888
908
  readonly fetch?: typeof fetch;
889
909
  readonly signal?: AbortSignal;
890
910
  }
@@ -898,4 +918,4 @@ interface PolicyCredentialAdmissionV4 {
898
918
  /** Accountless admission. The request deliberately has no account custody fields. */
899
919
  declare function admitPolicyCredentialV4(input: AdmitPolicyCredentialV4Input): Promise<PolicyCredentialAdmissionV4>;
900
920
 
901
- export { type RegisterPolicyV3Receipt as $, ATTESTED_ENFORCER_BINDING_V2_SCHEMA as A, type BuildPolicyCredentialPresentationV3Input as B, CONTENT_SOURCE_V1_DOMAIN as C, type PolicyCredentialAdmissionV3 as D, ED25519_JCS_SIGNATURE_SUITE as E, type PolicyCredentialAdmissionV4 as F, type PolicyCredentialPresentationV3 as G, type PolicyCredentialPresentationV4 as H, type PolicyCredentialRequirementV1 as I, type JsonObject as J, type PolicyRootStatusV3 as K, LAST_V2_CREATE_AT as L, MAX_LEGACY_ENVELOPE_EXPIRES_AT as M, NATIVE_PROJECTION_V1_DOMAIN as N, type PolicyRootV3 as O, type PolicyEngineRecord as P, type PolicySessionUcanFactV1 as Q, type PolicySessionUcanV1 as R, type SignedObjectSigner as S, type PolicyStatus as T, type UnsignedPolicyEngineRecord as U, ROOT_REVOCATION_V1_DOMAIN as V, ROOT_REVOCATION_V1_SCHEMA as W, ROOT_STATUS_CHECKPOINT_V1_SCHEMA as X, ROOT_STATUS_RENEWAL_V1_DOMAIN as Y, ROOT_STATUS_V1_DOMAIN as Z, type RegisterPolicyV3Input as _, type Policy as a, signCompactUcanRootAuthorization as a$, type SignCompactUcanAuthorizationInput as a0, type SignCompactUcanRootAuthorizationInput as a1, SignatureMaterialError as a2, type SignatureSuite as a3, SignatureVerificationError as a4, SignedObjectCanonicalizationError as a5, SignedObjectDigestError as a6, type SignedObjectErrorCode as a7, SignedObjectIdError as a8, type SignedObjectKind as a9, canonicalizeUnifiedPolicyCapability as aA, compactAttenuationContains as aB, contentSourceDigestHex as aC, createAndSignPolicy as aD, createAndSignPolicyEngineRecord as aE, createAndSignPolicyStatus as aF, createAndSignSignedObject as aG, createCompactPolicyDescendant as aH, createCompactPolicyInvocation as aI, deriveSignedObjectMaterial as aJ, getPolicyRootStatusV3 as aK, issuedCredentialEnvelopeFromVerified as aL, mintPolicySessionV3 as aM, normalizeUnifiedPolicyCapability as aN, parseCompactUcanAuthorization as aO, parsePolicySessionUcan as aP, policyCidFromCanonicalBytes as aQ, policyDigestHex as aR, policyIdForDigestHex as aS, policyV2DigestHex as aT, projectUnifiedPolicyCapabilities as aU, projectUnifiedPolicyCapability as aV, registerPolicyV3 as aW, renewPolicyRootStatusV3 as aX, requestPolicyChallengeV3 as aY, revokePolicyRootV3 as aZ, signCompactUcanAuthorization as a_, type SignedObjectMaterial as aa, SignedObjectProfileError as ab, SignedObjectSchemaError as ac, type SignedObjectSignature as ad, type SignedObjectVerificationResult as ae, type SignedPolicyObject as af, SigningKeyBindingError as ag, type UnifiedContentSource as ah, type UnifiedEncryptionCapability as ai, type UnifiedKvCapability as aj, type UnifiedNativeCapability as ak, type UnifiedPolicyCapability as al, type UnifiedPolicyV1 as am, type UnifiedPolicyV2 as an, type UnifiedResourceSelector as ao, type UnsignedPolicy as ap, type UnsignedPolicyCredentialPresentationV4 as aq, type UnsignedPolicyObject as ar, type UnsignedPolicyStatus as as, type UnsignedUnifiedPolicyV2 as at, UnsupportedSignatureSuiteError as au, admitPolicyCredentialV3 as av, admitPolicyCredentialV4 as aw, buildPolicyCredentialPresentationV3 as ax, buildPolicyCredentialPresentationV4 as ay, canonicalizeSignedObjectUnsigned as az, type AdmitPolicyCredentialV3Input as b, signPolicyCredentialPresentationV4 as b0, signedObjectIdFor as b1, toSignedObjectError as b2, unifiedNativeProjectionHashHex as b3, unifiedPolicyCapabilityContains as b4, unifiedPolicyCapabilityDigestHex as b5, unifiedPolicyCapabilityFromNative as b6, validatePolicyCredentialRequirementV1 as b7, validatePolicyEngineRecordSigned as b8, validatePolicyEngineRecordSignedShape as b9, type CredentialClaimDescriptor as bA, type CredentialEndpointId as bB, type CredentialInputDescriptor as bC, type CredentialProgressEvent as bD, type CredentialStepDescriptor as bE, type CredentialStepType as bF, type CredentialUxState as bG, HOLDER_BINDING_DOMAIN as bH, type IssuerVerificationKey as bI, validatePolicyEngineRecordUnsigned as ba, validatePolicySigned as bb, validatePolicySignedShape as bc, validatePolicyStatusSigned as bd, validatePolicyStatusSignedShape as be, validatePolicyStatusUnsigned as bf, validatePolicyUnsigned as bg, validateUnifiedPolicyV2 as bh, verifyPolicy as bi, verifyPolicyEngineRecord as bj, verifyPolicyRootRevocationV3 as bk, verifyPolicyRootStatusCheckpointV3 as bl, verifyPolicyStatus as bm, verifySignedObject as bn, type CredentialHolderBinding as bo, type CredentialFlowDescriptor as bp, type CredentialRequirement as bq, type StoredCredentialRecord as br, type VerifiedCredential as bs, type CredentialStorageReceipt as bt, type IssuedCredentialEnvelope as bu, type CredentialIssuerMetadata as bv, CREDENTIAL_ACQUISITION_PROTOCOL as bw, CREDENTIAL_CONTRACT_VERSION as bx, CREDENTIAL_FORMAT as by, CREDENTIAL_STEP_REGISTRY_VERSION as bz, type AdmitPolicyCredentialV4Input as c, type AttestedEnforcerBindingV2 as d, type BuildPolicyCredentialPresentationV4Input as e, type CompactPolicyInvocationInput as f, type CompactUcanAuthorizationV1 as g, EIP191_JCS_SIGNATURE_SUITE as h, LAST_V2_READ_AT as i, POLICY_CAPABILITY_V1_DOMAIN as j, POLICY_CAPABILITY_V1_SCHEMA as k, POLICY_CREDENTIAL_REQUIREMENT_V1_TYPE as l, POLICY_ENFORCEMENT_DELEGATION_V2_SCHEMA as m, POLICY_ENGINE_RECORD_SCHEMA as n, POLICY_PRESENTATION_V3_DOMAIN as o, POLICY_PRESENTATION_V3_SCHEMA as p, POLICY_PRESENTATION_V4_DOMAIN as q, POLICY_PRESENTATION_V4_SCHEMA as r, POLICY_SCHEMA as s, POLICY_SESSION_UCAN_V1_PROFILE as t, POLICY_STATUS_SCHEMA as u, POLICY_V1_DOMAIN as v, POLICY_V1_SCHEMA as w, POLICY_V2_DOMAIN as x, POLICY_V2_SCHEMA as y, type PolicyChallengeV3 as z };
921
+ export { type RegisterPolicyV3Input as $, ATTESTED_ENFORCER_BINDING_V2_SCHEMA as A, type BuildPolicyCredentialPresentationV3Input as B, CONTENT_SOURCE_V1_DOMAIN as C, type PolicyChallengeV3 as D, ED25519_JCS_SIGNATURE_SUITE as E, type PolicyCredentialAdmissionV3 as F, type PolicyCredentialAdmissionV4 as G, type PolicyCredentialPresentationV3 as H, type PolicyCredentialPresentationV4 as I, type JsonObject as J, type PolicyCredentialRequirementV1 as K, LAST_V2_CREATE_AT as L, MAX_LEGACY_ENVELOPE_EXPIRES_AT as M, NATIVE_PROJECTION_V1_DOMAIN as N, type PolicyRootStatusV3 as O, type PolicyEngineRecord as P, type PolicyRootV3 as Q, type PolicySessionUcanFactV1 as R, type SignedObjectSigner as S, type PolicySessionUcanV1 as T, type UnsignedPolicyEngineRecord as U, type PolicyStatus as V, ROOT_REVOCATION_V1_DOMAIN as W, ROOT_REVOCATION_V1_SCHEMA as X, ROOT_STATUS_CHECKPOINT_V1_SCHEMA as Y, ROOT_STATUS_RENEWAL_V1_DOMAIN as Z, ROOT_STATUS_V1_DOMAIN as _, type Policy as a, signCompactPolicyDescendant as a$, type RegisterPolicyV3Receipt as a0, type SignCompactUcanAuthorizationInput as a1, type SignCompactUcanRootAuthorizationInput as a2, SignatureMaterialError as a3, type SignatureSuite as a4, SignatureVerificationError as a5, SignedObjectCanonicalizationError as a6, SignedObjectDigestError as a7, type SignedObjectErrorCode as a8, SignedObjectIdError as a9, canonicalizeSignedObjectUnsigned as aA, canonicalizeUnifiedPolicyCapability as aB, compactAttenuationContains as aC, contentSourceDigestHex as aD, createAndSignPolicy as aE, createAndSignPolicyEngineRecord as aF, createAndSignPolicyStatus as aG, createAndSignSignedObject as aH, createCompactPolicyDescendant as aI, createCompactPolicyInvocation as aJ, deriveSignedObjectMaterial as aK, getPolicyRootStatusV3 as aL, issuedCredentialEnvelopeFromVerified as aM, mintPolicySessionV3 as aN, normalizeUnifiedPolicyCapability as aO, parseCompactUcanAuthorization as aP, parsePolicySessionUcan as aQ, policyCidFromCanonicalBytes as aR, policyDigestHex as aS, policyIdForDigestHex as aT, policyV2DigestHex as aU, projectUnifiedPolicyCapabilities as aV, projectUnifiedPolicyCapability as aW, registerPolicyV3 as aX, renewPolicyRootStatusV3 as aY, requestPolicyChallengeV3 as aZ, revokePolicyRootV3 as a_, type SignedObjectKind as aa, type SignedObjectMaterial as ab, SignedObjectProfileError as ac, SignedObjectSchemaError as ad, type SignedObjectSignature as ae, type SignedObjectVerificationResult as af, type SignedPolicyObject as ag, SigningKeyBindingError as ah, type UnifiedContentSource as ai, type UnifiedEncryptionCapability as aj, type UnifiedKvCapability as ak, type UnifiedNativeCapability as al, type UnifiedPolicyCapability as am, type UnifiedPolicyV1 as an, type UnifiedPolicyV2 as ao, type UnifiedResourceSelector as ap, type UnsignedPolicy as aq, type UnsignedPolicyCredentialPresentationV4 as ar, type UnsignedPolicyObject as as, type UnsignedPolicyStatus as at, type UnsignedUnifiedPolicyV2 as au, UnsupportedSignatureSuiteError as av, admitPolicyCredentialV3 as aw, admitPolicyCredentialV4 as ax, buildPolicyCredentialPresentationV3 as ay, buildPolicyCredentialPresentationV4 as az, type AdmitPolicyCredentialV3Input as b, signCompactUcanAuthorization as b0, signCompactUcanRootAuthorization as b1, signPolicyCredentialPresentationV4 as b2, signedObjectIdFor as b3, toSignedObjectError as b4, unifiedNativeProjectionHashHex as b5, unifiedPolicyCapabilityContains as b6, unifiedPolicyCapabilityDigestHex as b7, unifiedPolicyCapabilityFromNative as b8, validatePolicyCredentialRequirementV1 as b9, CREDENTIAL_FORMAT as bA, CREDENTIAL_STEP_REGISTRY_VERSION as bB, type CredentialClaimDescriptor as bC, type CredentialEndpointId as bD, type CredentialInputDescriptor as bE, type CredentialProgressEvent as bF, type CredentialStepDescriptor as bG, type CredentialStepType as bH, type CredentialUxState as bI, HOLDER_BINDING_DOMAIN as bJ, type IssuerVerificationKey as bK, validatePolicyEngineRecordSigned as ba, validatePolicyEngineRecordSignedShape as bb, validatePolicyEngineRecordUnsigned as bc, validatePolicySigned as bd, validatePolicySignedShape as be, validatePolicyStatusSigned as bf, validatePolicyStatusSignedShape as bg, validatePolicyStatusUnsigned as bh, validatePolicyUnsigned as bi, validateUnifiedPolicyV2 as bj, verifyPolicy as bk, verifyPolicyEngineRecord as bl, verifyPolicyRootRevocationV3 as bm, verifyPolicyRootStatusCheckpointV3 as bn, verifyPolicyStatus as bo, verifySignedObject as bp, type CredentialHolderBinding as bq, type CredentialFlowDescriptor as br, type CredentialRequirement as bs, type StoredCredentialRecord as bt, type VerifiedCredential as bu, type CredentialStorageReceipt as bv, type IssuedCredentialEnvelope as bw, type CredentialIssuerMetadata as bx, CREDENTIAL_ACQUISITION_PROTOCOL as by, CREDENTIAL_CONTRACT_VERSION as bz, type AdmitPolicyCredentialV4Input as c, type AttestedEnforcerBindingV2 as d, type BuildPolicyCredentialPresentationV4Input as e, type CompactPolicyDescendantInput as f, type CompactPolicyInvocationInput as g, type CompactUcanAuthorizationV1 as h, EIP191_JCS_SIGNATURE_SUITE as i, LAST_V2_READ_AT as j, POLICY_CAPABILITY_V1_DOMAIN as k, POLICY_CAPABILITY_V1_SCHEMA as l, POLICY_CREDENTIAL_REQUIREMENT_V1_TYPE as m, POLICY_ENFORCEMENT_DELEGATION_V2_SCHEMA as n, POLICY_ENGINE_RECORD_SCHEMA as o, POLICY_PRESENTATION_V3_DOMAIN as p, POLICY_PRESENTATION_V3_SCHEMA as q, POLICY_PRESENTATION_V4_DOMAIN as r, POLICY_PRESENTATION_V4_SCHEMA as s, POLICY_SCHEMA as t, POLICY_SESSION_UCAN_V1_PROFILE as u, POLICY_STATUS_SCHEMA as v, POLICY_V1_DOMAIN as w, POLICY_V1_SCHEMA as x, POLICY_V2_DOMAIN as y, POLICY_V2_SCHEMA as z };
@@ -718,17 +718,28 @@ interface CompactPolicyInvocationInput {
718
718
  }
719
719
  /** Sign a fresh one-parent ordinary invocation; S0 itself is never a bearer. */
720
720
  declare function createCompactPolicyInvocation(input: CompactPolicyInvocationInput): CompactUcanAuthorizationV1;
721
- declare function createCompactPolicyDescendant(input: {
721
+ interface CompactPolicyDescendantInput {
722
722
  readonly parentAuthorization: string;
723
723
  readonly parentCid: string;
724
724
  readonly issuerDid: string;
725
725
  readonly audienceDid: string;
726
726
  readonly attenuation: Readonly<Record<string, Readonly<Record<string, readonly unknown[]>>>>;
727
- readonly privateKey: Uint8Array;
727
+ /** Start of the window; defaults to one second after the parent's start. */
728
728
  readonly now?: number;
729
+ /** Defaults to the longest window the parent allows: one second inside it. */
729
730
  readonly expiresAt?: number;
730
731
  readonly nonce?: string;
732
+ }
733
+ declare function createCompactPolicyDescendant(input: CompactPolicyDescendantInput & {
734
+ readonly privateKey: Uint8Array;
731
735
  }): CompactUcanAuthorizationV1;
736
+ /**
737
+ * The same descendant, signed by a caller-owned key that may be
738
+ * non-extractable. The result is verified against the issuer DID.
739
+ */
740
+ declare function signCompactPolicyDescendant(input: CompactPolicyDescendantInput & {
741
+ readonly sign: (bytes: Uint8Array) => Promise<Uint8Array>;
742
+ }): Promise<CompactUcanAuthorizationV1>;
732
743
  /** Byte-independent semantic containment shared by S0, descendants and mint requests. */
733
744
  declare function compactAttenuationContains(parent: Readonly<Record<string, Readonly<Record<string, readonly unknown[]>>>>, child: Readonly<Record<string, Readonly<Record<string, readonly unknown[]>>>>): boolean;
734
745
  declare function parseCompactUcanAuthorization(input: string, expectedCid?: string): CompactUcanAuthorizationV1;
@@ -864,6 +875,8 @@ interface AdmitPolicyCredentialV3Input extends Omit<BuildPolicyCredentialPresent
864
875
  readonly accountAuthorizationCid: string;
865
876
  /** Recipient-owned `credentials` space covered by the account authorization. */
866
877
  readonly credentialSpaceId: string;
878
+ /** See {@link AdmitPolicyCredentialV4Input.requestedExpiresAt}. */
879
+ readonly requestedExpiresAt?: string | null;
867
880
  readonly fetch?: typeof fetch;
868
881
  readonly signal?: AbortSignal;
869
882
  }
@@ -885,6 +898,13 @@ interface AdmitPolicyCredentialV4Input extends Omit<BuildPolicyCredentialPresent
885
898
  readonly nodeOrigin: string;
886
899
  /** Path to the embedded Node policy runtime. Defaults to `/policy/v3`. */
887
900
  readonly policyRuntimePath?: string;
901
+ /**
902
+ * How long the minted session should last. Defaults to the policy's own
903
+ * expiry, the longest the Node will grant; it caps the session at the
904
+ * policy, its roots and any account authorization. `null` asks for the
905
+ * legacy 60-second session.
906
+ */
907
+ readonly requestedExpiresAt?: string | null;
888
908
  readonly fetch?: typeof fetch;
889
909
  readonly signal?: AbortSignal;
890
910
  }
@@ -898,4 +918,4 @@ interface PolicyCredentialAdmissionV4 {
898
918
  /** Accountless admission. The request deliberately has no account custody fields. */
899
919
  declare function admitPolicyCredentialV4(input: AdmitPolicyCredentialV4Input): Promise<PolicyCredentialAdmissionV4>;
900
920
 
901
- export { type RegisterPolicyV3Receipt as $, ATTESTED_ENFORCER_BINDING_V2_SCHEMA as A, type BuildPolicyCredentialPresentationV3Input as B, CONTENT_SOURCE_V1_DOMAIN as C, type PolicyCredentialAdmissionV3 as D, ED25519_JCS_SIGNATURE_SUITE as E, type PolicyCredentialAdmissionV4 as F, type PolicyCredentialPresentationV3 as G, type PolicyCredentialPresentationV4 as H, type PolicyCredentialRequirementV1 as I, type JsonObject as J, type PolicyRootStatusV3 as K, LAST_V2_CREATE_AT as L, MAX_LEGACY_ENVELOPE_EXPIRES_AT as M, NATIVE_PROJECTION_V1_DOMAIN as N, type PolicyRootV3 as O, type PolicyEngineRecord as P, type PolicySessionUcanFactV1 as Q, type PolicySessionUcanV1 as R, type SignedObjectSigner as S, type PolicyStatus as T, type UnsignedPolicyEngineRecord as U, ROOT_REVOCATION_V1_DOMAIN as V, ROOT_REVOCATION_V1_SCHEMA as W, ROOT_STATUS_CHECKPOINT_V1_SCHEMA as X, ROOT_STATUS_RENEWAL_V1_DOMAIN as Y, ROOT_STATUS_V1_DOMAIN as Z, type RegisterPolicyV3Input as _, type Policy as a, signCompactUcanRootAuthorization as a$, type SignCompactUcanAuthorizationInput as a0, type SignCompactUcanRootAuthorizationInput as a1, SignatureMaterialError as a2, type SignatureSuite as a3, SignatureVerificationError as a4, SignedObjectCanonicalizationError as a5, SignedObjectDigestError as a6, type SignedObjectErrorCode as a7, SignedObjectIdError as a8, type SignedObjectKind as a9, canonicalizeUnifiedPolicyCapability as aA, compactAttenuationContains as aB, contentSourceDigestHex as aC, createAndSignPolicy as aD, createAndSignPolicyEngineRecord as aE, createAndSignPolicyStatus as aF, createAndSignSignedObject as aG, createCompactPolicyDescendant as aH, createCompactPolicyInvocation as aI, deriveSignedObjectMaterial as aJ, getPolicyRootStatusV3 as aK, issuedCredentialEnvelopeFromVerified as aL, mintPolicySessionV3 as aM, normalizeUnifiedPolicyCapability as aN, parseCompactUcanAuthorization as aO, parsePolicySessionUcan as aP, policyCidFromCanonicalBytes as aQ, policyDigestHex as aR, policyIdForDigestHex as aS, policyV2DigestHex as aT, projectUnifiedPolicyCapabilities as aU, projectUnifiedPolicyCapability as aV, registerPolicyV3 as aW, renewPolicyRootStatusV3 as aX, requestPolicyChallengeV3 as aY, revokePolicyRootV3 as aZ, signCompactUcanAuthorization as a_, type SignedObjectMaterial as aa, SignedObjectProfileError as ab, SignedObjectSchemaError as ac, type SignedObjectSignature as ad, type SignedObjectVerificationResult as ae, type SignedPolicyObject as af, SigningKeyBindingError as ag, type UnifiedContentSource as ah, type UnifiedEncryptionCapability as ai, type UnifiedKvCapability as aj, type UnifiedNativeCapability as ak, type UnifiedPolicyCapability as al, type UnifiedPolicyV1 as am, type UnifiedPolicyV2 as an, type UnifiedResourceSelector as ao, type UnsignedPolicy as ap, type UnsignedPolicyCredentialPresentationV4 as aq, type UnsignedPolicyObject as ar, type UnsignedPolicyStatus as as, type UnsignedUnifiedPolicyV2 as at, UnsupportedSignatureSuiteError as au, admitPolicyCredentialV3 as av, admitPolicyCredentialV4 as aw, buildPolicyCredentialPresentationV3 as ax, buildPolicyCredentialPresentationV4 as ay, canonicalizeSignedObjectUnsigned as az, type AdmitPolicyCredentialV3Input as b, signPolicyCredentialPresentationV4 as b0, signedObjectIdFor as b1, toSignedObjectError as b2, unifiedNativeProjectionHashHex as b3, unifiedPolicyCapabilityContains as b4, unifiedPolicyCapabilityDigestHex as b5, unifiedPolicyCapabilityFromNative as b6, validatePolicyCredentialRequirementV1 as b7, validatePolicyEngineRecordSigned as b8, validatePolicyEngineRecordSignedShape as b9, type CredentialClaimDescriptor as bA, type CredentialEndpointId as bB, type CredentialInputDescriptor as bC, type CredentialProgressEvent as bD, type CredentialStepDescriptor as bE, type CredentialStepType as bF, type CredentialUxState as bG, HOLDER_BINDING_DOMAIN as bH, type IssuerVerificationKey as bI, validatePolicyEngineRecordUnsigned as ba, validatePolicySigned as bb, validatePolicySignedShape as bc, validatePolicyStatusSigned as bd, validatePolicyStatusSignedShape as be, validatePolicyStatusUnsigned as bf, validatePolicyUnsigned as bg, validateUnifiedPolicyV2 as bh, verifyPolicy as bi, verifyPolicyEngineRecord as bj, verifyPolicyRootRevocationV3 as bk, verifyPolicyRootStatusCheckpointV3 as bl, verifyPolicyStatus as bm, verifySignedObject as bn, type CredentialHolderBinding as bo, type CredentialFlowDescriptor as bp, type CredentialRequirement as bq, type StoredCredentialRecord as br, type VerifiedCredential as bs, type CredentialStorageReceipt as bt, type IssuedCredentialEnvelope as bu, type CredentialIssuerMetadata as bv, CREDENTIAL_ACQUISITION_PROTOCOL as bw, CREDENTIAL_CONTRACT_VERSION as bx, CREDENTIAL_FORMAT as by, CREDENTIAL_STEP_REGISTRY_VERSION as bz, type AdmitPolicyCredentialV4Input as c, type AttestedEnforcerBindingV2 as d, type BuildPolicyCredentialPresentationV4Input as e, type CompactPolicyInvocationInput as f, type CompactUcanAuthorizationV1 as g, EIP191_JCS_SIGNATURE_SUITE as h, LAST_V2_READ_AT as i, POLICY_CAPABILITY_V1_DOMAIN as j, POLICY_CAPABILITY_V1_SCHEMA as k, POLICY_CREDENTIAL_REQUIREMENT_V1_TYPE as l, POLICY_ENFORCEMENT_DELEGATION_V2_SCHEMA as m, POLICY_ENGINE_RECORD_SCHEMA as n, POLICY_PRESENTATION_V3_DOMAIN as o, POLICY_PRESENTATION_V3_SCHEMA as p, POLICY_PRESENTATION_V4_DOMAIN as q, POLICY_PRESENTATION_V4_SCHEMA as r, POLICY_SCHEMA as s, POLICY_SESSION_UCAN_V1_PROFILE as t, POLICY_STATUS_SCHEMA as u, POLICY_V1_DOMAIN as v, POLICY_V1_SCHEMA as w, POLICY_V2_DOMAIN as x, POLICY_V2_SCHEMA as y, type PolicyChallengeV3 as z };
921
+ export { type RegisterPolicyV3Input as $, ATTESTED_ENFORCER_BINDING_V2_SCHEMA as A, type BuildPolicyCredentialPresentationV3Input as B, CONTENT_SOURCE_V1_DOMAIN as C, type PolicyChallengeV3 as D, ED25519_JCS_SIGNATURE_SUITE as E, type PolicyCredentialAdmissionV3 as F, type PolicyCredentialAdmissionV4 as G, type PolicyCredentialPresentationV3 as H, type PolicyCredentialPresentationV4 as I, type JsonObject as J, type PolicyCredentialRequirementV1 as K, LAST_V2_CREATE_AT as L, MAX_LEGACY_ENVELOPE_EXPIRES_AT as M, NATIVE_PROJECTION_V1_DOMAIN as N, type PolicyRootStatusV3 as O, type PolicyEngineRecord as P, type PolicyRootV3 as Q, type PolicySessionUcanFactV1 as R, type SignedObjectSigner as S, type PolicySessionUcanV1 as T, type UnsignedPolicyEngineRecord as U, type PolicyStatus as V, ROOT_REVOCATION_V1_DOMAIN as W, ROOT_REVOCATION_V1_SCHEMA as X, ROOT_STATUS_CHECKPOINT_V1_SCHEMA as Y, ROOT_STATUS_RENEWAL_V1_DOMAIN as Z, ROOT_STATUS_V1_DOMAIN as _, type Policy as a, signCompactPolicyDescendant as a$, type RegisterPolicyV3Receipt as a0, type SignCompactUcanAuthorizationInput as a1, type SignCompactUcanRootAuthorizationInput as a2, SignatureMaterialError as a3, type SignatureSuite as a4, SignatureVerificationError as a5, SignedObjectCanonicalizationError as a6, SignedObjectDigestError as a7, type SignedObjectErrorCode as a8, SignedObjectIdError as a9, canonicalizeSignedObjectUnsigned as aA, canonicalizeUnifiedPolicyCapability as aB, compactAttenuationContains as aC, contentSourceDigestHex as aD, createAndSignPolicy as aE, createAndSignPolicyEngineRecord as aF, createAndSignPolicyStatus as aG, createAndSignSignedObject as aH, createCompactPolicyDescendant as aI, createCompactPolicyInvocation as aJ, deriveSignedObjectMaterial as aK, getPolicyRootStatusV3 as aL, issuedCredentialEnvelopeFromVerified as aM, mintPolicySessionV3 as aN, normalizeUnifiedPolicyCapability as aO, parseCompactUcanAuthorization as aP, parsePolicySessionUcan as aQ, policyCidFromCanonicalBytes as aR, policyDigestHex as aS, policyIdForDigestHex as aT, policyV2DigestHex as aU, projectUnifiedPolicyCapabilities as aV, projectUnifiedPolicyCapability as aW, registerPolicyV3 as aX, renewPolicyRootStatusV3 as aY, requestPolicyChallengeV3 as aZ, revokePolicyRootV3 as a_, type SignedObjectKind as aa, type SignedObjectMaterial as ab, SignedObjectProfileError as ac, SignedObjectSchemaError as ad, type SignedObjectSignature as ae, type SignedObjectVerificationResult as af, type SignedPolicyObject as ag, SigningKeyBindingError as ah, type UnifiedContentSource as ai, type UnifiedEncryptionCapability as aj, type UnifiedKvCapability as ak, type UnifiedNativeCapability as al, type UnifiedPolicyCapability as am, type UnifiedPolicyV1 as an, type UnifiedPolicyV2 as ao, type UnifiedResourceSelector as ap, type UnsignedPolicy as aq, type UnsignedPolicyCredentialPresentationV4 as ar, type UnsignedPolicyObject as as, type UnsignedPolicyStatus as at, type UnsignedUnifiedPolicyV2 as au, UnsupportedSignatureSuiteError as av, admitPolicyCredentialV3 as aw, admitPolicyCredentialV4 as ax, buildPolicyCredentialPresentationV3 as ay, buildPolicyCredentialPresentationV4 as az, type AdmitPolicyCredentialV3Input as b, signCompactUcanAuthorization as b0, signCompactUcanRootAuthorization as b1, signPolicyCredentialPresentationV4 as b2, signedObjectIdFor as b3, toSignedObjectError as b4, unifiedNativeProjectionHashHex as b5, unifiedPolicyCapabilityContains as b6, unifiedPolicyCapabilityDigestHex as b7, unifiedPolicyCapabilityFromNative as b8, validatePolicyCredentialRequirementV1 as b9, CREDENTIAL_FORMAT as bA, CREDENTIAL_STEP_REGISTRY_VERSION as bB, type CredentialClaimDescriptor as bC, type CredentialEndpointId as bD, type CredentialInputDescriptor as bE, type CredentialProgressEvent as bF, type CredentialStepDescriptor as bG, type CredentialStepType as bH, type CredentialUxState as bI, HOLDER_BINDING_DOMAIN as bJ, type IssuerVerificationKey as bK, validatePolicyEngineRecordSigned as ba, validatePolicyEngineRecordSignedShape as bb, validatePolicyEngineRecordUnsigned as bc, validatePolicySigned as bd, validatePolicySignedShape as be, validatePolicyStatusSigned as bf, validatePolicyStatusSignedShape as bg, validatePolicyStatusUnsigned as bh, validatePolicyUnsigned as bi, validateUnifiedPolicyV2 as bj, verifyPolicy as bk, verifyPolicyEngineRecord as bl, verifyPolicyRootRevocationV3 as bm, verifyPolicyRootStatusCheckpointV3 as bn, verifyPolicyStatus as bo, verifySignedObject as bp, type CredentialHolderBinding as bq, type CredentialFlowDescriptor as br, type CredentialRequirement as bs, type StoredCredentialRecord as bt, type VerifiedCredential as bu, type CredentialStorageReceipt as bv, type IssuedCredentialEnvelope as bw, type CredentialIssuerMetadata as bx, CREDENTIAL_ACQUISITION_PROTOCOL as by, CREDENTIAL_CONTRACT_VERSION as bz, type AdmitPolicyCredentialV4Input as c, type AttestedEnforcerBindingV2 as d, type BuildPolicyCredentialPresentationV4Input as e, type CompactPolicyDescendantInput as f, type CompactPolicyInvocationInput as g, type CompactUcanAuthorizationV1 as h, EIP191_JCS_SIGNATURE_SUITE as i, LAST_V2_READ_AT as j, POLICY_CAPABILITY_V1_DOMAIN as k, POLICY_CAPABILITY_V1_SCHEMA as l, POLICY_CREDENTIAL_REQUIREMENT_V1_TYPE as m, POLICY_ENFORCEMENT_DELEGATION_V2_SCHEMA as n, POLICY_ENGINE_RECORD_SCHEMA as o, POLICY_PRESENTATION_V3_DOMAIN as p, POLICY_PRESENTATION_V3_SCHEMA as q, POLICY_PRESENTATION_V4_DOMAIN as r, POLICY_PRESENTATION_V4_SCHEMA as s, POLICY_SCHEMA as t, POLICY_SESSION_UCAN_V1_PROFILE as u, POLICY_STATUS_SCHEMA as v, POLICY_V1_DOMAIN as w, POLICY_V1_SCHEMA as x, POLICY_V2_DOMAIN as y, POLICY_V2_SCHEMA as z };
@@ -170,6 +170,7 @@ var DelegationErrorSchema = import_zod.z.object({
170
170
  });
171
171
  var DelegationErrorCodes = {
172
172
  AUTH_REQUIRED: "AUTH_REQUIRED",
173
+ AUTH_UNAUTHORIZED: "AUTH_UNAUTHORIZED",
173
174
  AUTH_EXPIRED: "AUTH_EXPIRED",
174
175
  NOT_INITIALIZED: "NOT_INITIALIZED",
175
176
  NOT_FOUND: "NOT_FOUND",
@@ -534,7 +535,7 @@ var CreateDelegationWasmResultSchema = import_zod.z.object({
534
535
  // src/expiry.ts
535
536
  var EPHEMERAL_MS = 60 * 60 * 1e3;
536
537
  var SIGNED_READ_URL_MS = 5 * 60 * 1e3;
537
- var SESSION_MS = 7 * 24 * 60 * 60 * 1e3;
538
+ var SESSION_MS = 30 * 24 * 60 * 60 * 1e3;
538
539
  var SHARE_MS = 7 * 24 * 60 * 60 * 1e3;
539
540
  var APP_MS = 30 * 24 * 60 * 60 * 1e3;
540
541
  var MAX_MS = 10 * 365 * 24 * 60 * 60 * 1e3;
@@ -2689,7 +2690,6 @@ var import_ed25519 = require("@noble/curves/ed25519");
2689
2690
  var import_blake3 = require("@noble/hashes/blake3");
2690
2691
  var import_sha256 = require("@noble/hashes/sha256");
2691
2692
  var ENVELOPE_SCHEMA = "xyz.tinycloud.share/envelope";
2692
- var INLINE_PREFIX = "tc2:";
2693
2693
  var RAW_CID_CODEC = 85;
2694
2694
  var BLAKE3_256_CODE = 30;
2695
2695
  var DEFAULT_MAX_INLINE_BYTES = 256 * 1024;
@@ -3395,31 +3395,6 @@ function parsePublishedShareLink(link, options = {}) {
3395
3395
  const origin = normalizeOrigin(url.origin);
3396
3396
  if (options.trustedOrigins !== void 0 && !options.trustedOrigins.map(normalizeOrigin).includes(origin)) throw new ShareEnvelopeError("origin-mismatch", "share link origin is not trusted");
3397
3397
  if (url.username !== "" || url.password !== "") throw new ShareEnvelopeError("invalid-link", "share link is not canonical");
3398
- if (url.pathname === "/viewer") {
3399
- const secretPayload = url.search === "" && url.hash.startsWith("#tc2=") ? url.hash.slice("#tc2=".length) : void 0;
3400
- const publicPayload = url.hash === "" && url.searchParams.size === 1 ? url.searchParams.get("tc2") ?? void 0 : void 0;
3401
- if (secretPayload === void 0 && publicPayload === void 0) throw new ShareEnvelopeError("invalid-link", "published share link is invalid");
3402
- if (publicPayload !== void 0 && url.search !== `?tc2=${publicPayload}`) throw new ShareEnvelopeError("invalid-link", "published share link is not canonical");
3403
- let payload;
3404
- try {
3405
- const bytes2 = base64UrlToBytes(secretPayload ?? publicPayload);
3406
- if (bytes2.length > (options.maxInlineBytes ?? DEFAULT_MAX_INLINE_BYTES) * 2) throw new Error("inline payload too large");
3407
- const text = new TextDecoder("utf-8", { fatal: true }).decode(bytes2);
3408
- const value = JSON.parse(text);
3409
- if (typeof value !== "object" || value === null || Array.isArray(value)) throw new Error("inline payload shape");
3410
- if (canonicalJson(value) !== text) throw new Error("inline payload is not canonical JSON");
3411
- payload = value;
3412
- } catch (error) {
3413
- throw new ShareEnvelopeError("invalid-link", error instanceof Error ? error.message : "invalid inline payload");
3414
- }
3415
- const payloadKeys = Object.keys(payload);
3416
- if (payload.v !== 2 || typeof payload.c !== "string" || typeof payload.cid !== "string" || payload.k !== void 0 && typeof payload.k !== "string" || payloadKeys.some((key3) => !["v", "c", "cid", "k"].includes(key3)) || publicPayload !== void 0 && (payloadKeys.length !== 3 || payload.k !== void 0)) throw new ShareEnvelopeError("invalid-link", "inline payload fields are invalid");
3417
- const sealed = base64UrlToBytes(payload.c);
3418
- if (!verifyPublishedShareCid(payload.cid, sealed)) throw new ShareEnvelopeError("cid-mismatch", "inline payload CID does not match");
3419
- const key2 = payload.k === void 0 ? void 0 : base64UrlToBytes(payload.k);
3420
- if (key2 !== void 0 && key2.length !== 32) throw new ShareEnvelopeError("invalid-link", "inline payload key is invalid");
3421
- return { origin, cid: payload.cid, ...key2 === void 0 ? {} : { key: key2 }, sealed };
3422
- }
3423
3398
  if (url.search !== "") throw new ShareEnvelopeError("invalid-link", "share link is not canonical");
3424
3399
  const match = /^\/s\/([a-z2-7]+)$/.exec(url.pathname);
3425
3400
  if (match === null || !url.hash.startsWith("#k=")) throw new ShareEnvelopeError("invalid-link", "published share link is invalid");
@@ -3442,10 +3417,7 @@ function parseShareUrl(link, options = {}) {
3442
3417
  }
3443
3418
  const origin = normalizeOrigin(url.origin);
3444
3419
  if (options.trustedOrigins !== void 0 && !options.trustedOrigins.map(normalizeOrigin).includes(origin)) throw new ShareEnvelopeError("origin-mismatch", "share link origin is not trusted");
3445
- if (url.pathname === "/viewer" && (url.hash.startsWith("#tc2=") || url.searchParams.has("tc2"))) {
3446
- const published = parsePublishedShareLink(link, options);
3447
- return { kind: "inline", origin, cid: published.cid, key: published.key, url: `${url.origin}${url.pathname}`, protocol: "share-envelope-v2" };
3448
- }
3420
+ if (url.pathname === "/viewer") throw new ShareEnvelopeError("invalid-link", "retired viewer links are not accepted");
3449
3421
  if (url.search !== "") throw new ShareEnvelopeError("invalid-link", "share links must not contain query parameters");
3450
3422
  const match = url.pathname.match(/^\/s\/(i\/)?([^/]+)$/);
3451
3423
  if (!match) throw new ShareEnvelopeError("invalid-link", "share link path is invalid");
@@ -3470,9 +3442,9 @@ function parseShareUrl(link, options = {}) {
3470
3442
  function isV2ShareLink(link) {
3471
3443
  try {
3472
3444
  const url = new URL(link);
3473
- return url.pathname.startsWith("/s/") || url.pathname === "/viewer";
3445
+ return url.search === "" && url.pathname.startsWith("/s/");
3474
3446
  } catch {
3475
- return link.startsWith(INLINE_PREFIX);
3447
+ return false;
3476
3448
  }
3477
3449
  }
3478
3450
  async function encryptShareBytes(bytes2, key) {
@@ -4033,6 +4005,7 @@ var CompactPayloadSchema = import_zod4.z.object({
4033
4005
  nnc: import_zod4.z.string().min(1),
4034
4006
  prf: import_zod4.z.array(import_zod4.z.string().min(1))
4035
4007
  }).strict();
4008
+ var MAX_POLICY_ROOT_SECONDS = 31 * 24 * 60 * 60;
4036
4009
  function createCompactPolicyInvocation(input) {
4037
4010
  const session = parsePolicySessionUcan(input.sessionAuthorization);
4038
4011
  if (session.cid !== input.sessionCid || session.aud !== input.recipientDid)
@@ -4064,7 +4037,7 @@ function createCompactPolicyInvocation(input) {
4064
4037
  const signature = import_ed255192.ed25519.sign(signingInput, input.privateKey);
4065
4038
  return parseCompactUcanAuthorization(`${protectedSegment}.${payloadSegment}.${encodeBase64Url(signature)}`);
4066
4039
  }
4067
- function createCompactPolicyDescendant(input) {
4040
+ function compactPolicyDescendantClaims(input) {
4068
4041
  const parent = parseCompactUcanAuthorization(input.parentAuthorization, input.parentCid);
4069
4042
  if (parent.payload.aud !== input.issuerDid) throw new Error("policy descendant issuer is not the parent audience");
4070
4043
  const parentFact = parent.payload.fct[0];
@@ -4072,23 +4045,33 @@ function createCompactPolicyDescendant(input) {
4072
4045
  if (!Number.isInteger(depth) || depth <= 0) throw new Error("policy descendant depth is exhausted");
4073
4046
  if (!compactAttenuationContains(parent.payload.att, input.attenuation))
4074
4047
  throw new Error("policy descendant exceeds the parent attenuation");
4048
+ const now = Math.max(input.now ?? parent.payload.nbf + 1, parent.payload.nbf + 1);
4049
+ const exp = Math.min(input.expiresAt ?? parent.payload.exp - 1, parent.payload.exp - 1);
4050
+ if (exp <= now) throw new Error("policy parent has no strictly narrower validity window");
4051
+ return {
4052
+ parentCid: parent.cid,
4053
+ fact: { ...parentFact, remainingRedelegationDepth: depth - 1 },
4054
+ notBefore: now,
4055
+ expiresAt: exp,
4056
+ nonce: input.nonce ?? encodeBase64Url(crypto.getRandomValues(new Uint8Array(16)))
4057
+ };
4058
+ }
4059
+ function createCompactPolicyDescendant(input) {
4060
+ const claims = compactPolicyDescendantClaims(input);
4075
4061
  const principal = input.issuerDid.split("#", 1)[0];
4076
4062
  const didMaterial = base58btc.decode(principal.slice("did:key:".length));
4077
4063
  const publicKey = import_ed255192.ed25519.getPublicKey(input.privateKey);
4078
4064
  if (didMaterial.length !== 34 || !equalBytes2(publicKey, didMaterial.slice(2))) throw new Error("policy descendant signer does not bind issuer DID");
4079
- const now = Math.max(input.now ?? Math.floor(Date.now() / 1e3), parent.payload.nbf + 1);
4080
- const exp = Math.min(input.expiresAt ?? now + 60, now + 60, parent.payload.exp - 1);
4081
- if (exp <= now) throw new Error("policy parent has no strictly narrower validity window");
4082
4065
  const header = { alg: "EdDSA", jwk: { alg: "EdDSA", crv: "Ed25519", kty: "OKP", x: encodeBase64Url(publicKey) }, typ: "JWT", ucv: "0.10.0" };
4083
4066
  const payload = {
4084
4067
  att: input.attenuation,
4085
4068
  aud: input.audienceDid,
4086
- exp,
4087
- fct: [{ ...parentFact, remainingRedelegationDepth: depth - 1 }],
4069
+ exp: claims.expiresAt,
4070
+ fct: [claims.fact],
4088
4071
  iss: input.issuerDid.includes("#") ? input.issuerDid : `${principal}#${principal.slice("did:key:".length)}`,
4089
- nbf: now,
4090
- nnc: input.nonce ?? encodeBase64Url(crypto.getRandomValues(new Uint8Array(16))),
4091
- prf: [parent.cid]
4072
+ nbf: claims.notBefore,
4073
+ nnc: claims.nonce,
4074
+ prf: [claims.parentCid]
4092
4075
  };
4093
4076
  const protectedSegment = encodeBase64Url(new TextEncoder().encode(jcsCanonicalize(header)));
4094
4077
  const payloadSegment = encodeBase64Url(new TextEncoder().encode(jcsCanonicalize(payload)));
@@ -4164,7 +4147,7 @@ function parsePolicySessionUcan(authorization, expectedProofs) {
4164
4147
  throw new Error("policy session UCAN fact is incomplete");
4165
4148
  if (hasV4AuditFactShape && (!LOWER_SHA256_HEX.test(fact.credentialIdAuditDigestHex) || !LOWER_SHA256_HEX.test(fact.presentationJtiAuditDigestHex)))
4166
4149
  throw new Error("policy session UCAN v4 audit facts are invalid");
4167
- if (fact.profile !== POLICY_SESSION_UCAN_V1_PROFILE || typeof fact.remainingRedelegationDepth !== "number" || !Number.isInteger(fact.remainingRedelegationDepth) || fact.remainingRedelegationDepth < 0 || fact.remainingRedelegationDepth > 8 || parsed.payload.exp - parsed.payload.nbf > 60 || parsed.payload.iss.split("#", 1)[0] !== fact.nodeAudience || parsed.payload.aud !== fact.recipientDid)
4150
+ if (fact.profile !== POLICY_SESSION_UCAN_V1_PROFILE || typeof fact.remainingRedelegationDepth !== "number" || !Number.isInteger(fact.remainingRedelegationDepth) || fact.remainingRedelegationDepth < 0 || fact.remainingRedelegationDepth > 8 || parsed.payload.exp - parsed.payload.nbf > MAX_POLICY_ROOT_SECONDS || parsed.payload.iss.split("#", 1)[0] !== fact.nodeAudience || parsed.payload.aud !== fact.recipientDid)
4168
4151
  throw new Error("policy session UCAN fact is invalid");
4169
4152
  return {
4170
4153
  authorization,
@@ -5385,6 +5368,13 @@ var ShareRecipientClient = class {
5385
5368
  };
5386
5369
 
5387
5370
  // src/delegations/SharingService.ts
5371
+ function spaceIdsEqual(left, right) {
5372
+ const normalizeOwnerAddress = (space) => {
5373
+ const match = /^(tinycloud:pkh:eip155:\d+:)(0x[0-9a-fA-F]{40})(:.+)$/.exec(space);
5374
+ return match === null ? space : `${match[1]}${match[2].toLowerCase()}${match[3]}`;
5375
+ };
5376
+ return normalizeOwnerAddress(left) === normalizeOwnerAddress(right);
5377
+ }
5388
5378
  function inferShortServiceFromActionUrns(actions) {
5389
5379
  let short;
5390
5380
  for (const action of actions) {
@@ -5620,11 +5610,11 @@ var SharingService = class {
5620
5610
  }
5621
5611
  return result;
5622
5612
  };
5623
- const canSatisfyFromRegistry = this.findSuitableKeyForDelegation(
5613
+ const canSatisfyFromRegistry = this.classifyDelegationAuthority(
5624
5614
  fullPath,
5625
5615
  actions,
5626
5616
  requestedExpiry
5627
- );
5617
+ ) === "ok";
5628
5618
  if (canSatisfyFromRegistry) {
5629
5619
  const delegationResult = await this.createSessionDelegation(plainDID, fullPath, actions, expiry);
5630
5620
  const childDelegationActiveError = this.retiredGraphError();
@@ -5694,49 +5684,58 @@ var SharingService = class {
5694
5684
  return { ok: true, data: shareLink };
5695
5685
  }
5696
5686
  /**
5697
- * Check if any key in the registry can satisfy the delegation request.
5698
- * A key can satisfy if it has a delegation that:
5699
- * 1. Covers the required path (exact match or parent path)
5700
- * 2. Has all required actions
5701
- * 3. Has sufficient expiry (delegation.expiry >= requestedExpiry)
5702
- * 4. Allows sub-delegation
5687
+ * Report, without side effects, whether this session's registry authority
5688
+ * can issue the child delegation {@link generate} would create for the same
5689
+ * `path`, `actions` and `expiry` (defaults and `pathPrefix` applied the
5690
+ * same way):
5691
+ *
5692
+ * - `"ok"`: an uncaveated entry covers it.
5693
+ * - `"caveated"`: only caveated entries cover it. SharingService cannot
5694
+ * carry signed ReCap caveats into a child delegation.
5695
+ * - `"not-covered"`: no entry covers it, or there is no session.
5696
+ *
5697
+ * It does not consult `onRootDelegationNeeded`, so a signer-backed session
5698
+ * may still generate when this is not `"ok"`.
5699
+ */
5700
+ preflightGenerate(params) {
5701
+ if (!this.session || !params.path) return "not-covered";
5702
+ const fullPath = this.pathPrefix ? `${this.pathPrefix}/${params.path}`.replace(/\/+/g, "/") : params.path;
5703
+ return this.classifyDelegationAuthority(
5704
+ fullPath,
5705
+ params.actions ?? DEFAULT_READ_ACTIONS,
5706
+ params.expiry ?? new Date(Date.now() + DEFAULT_EXPIRY_MS)
5707
+ );
5708
+ }
5709
+ /**
5710
+ * Classify the registry's authority for a child delegation. An entry
5711
+ * satisfies it when it is in the session space, valid, lasts at least until
5712
+ * `requestedExpiry`, allows sub-delegation, covers `path` (exact or parent)
5713
+ * and grants every action. Satisfying entries with caveats are unusable.
5703
5714
  * @internal
5704
5715
  */
5705
- findSuitableKeyForDelegation(path, actions, requestedExpiry) {
5706
- const allKeys = this.registry.getAllKeys();
5707
- for (const key of allKeys) {
5708
- const delegations = this.registry.getDelegationsForKey(key.id);
5709
- for (const delegation of delegations) {
5710
- if (delegation.spaceId !== this.session?.spaceId) {
5711
- continue;
5712
- }
5713
- if ((delegation.caveats?.length ?? 0) > 0) {
5714
- continue;
5715
- }
5716
- if (!this.registry.isDelegationValid(delegation)) {
5716
+ classifyDelegationAuthority(path, actions, requestedExpiry) {
5717
+ let coveredOnlyByCaveated = false;
5718
+ for (const key of this.registry.getAllKeys()) {
5719
+ for (const delegation of this.registry.getDelegationsForKey(key.id)) {
5720
+ if (delegation.spaceId === void 0 || !spaceIdsEqual(delegation.spaceId, this.session?.spaceId ?? "")) {
5717
5721
  continue;
5718
5722
  }
5719
- if (delegation.expiry < requestedExpiry) {
5720
- continue;
5721
- }
5722
- if (delegation.allowSubDelegation === false) {
5723
- continue;
5724
- }
5725
- const delegationPath = delegation.path || "";
5726
- if (!this.pathMatches(delegationPath, path)) {
5723
+ if (!this.registry.isDelegationValid(delegation)) continue;
5724
+ if (delegation.expiry < requestedExpiry) continue;
5725
+ if (delegation.allowSubDelegation === false) continue;
5726
+ if (!this.pathMatches(delegation.path || "", path)) continue;
5727
+ const delegationActions = delegation.actions || [];
5728
+ if (!actions.every((action) => delegationActions.includes(action) || delegationActions.includes("*"))) {
5727
5729
  continue;
5728
5730
  }
5729
- const delegationActions = delegation.actions || [];
5730
- const hasAllActions = actions.every(
5731
- (action) => delegationActions.includes(action) || delegationActions.includes("*")
5732
- );
5733
- if (!hasAllActions) {
5731
+ if ((delegation.caveats?.length ?? 0) > 0) {
5732
+ coveredOnlyByCaveated = true;
5734
5733
  continue;
5735
5734
  }
5736
- return true;
5735
+ return "ok";
5737
5736
  }
5738
5737
  }
5739
- return false;
5738
+ return coveredOnlyByCaveated ? "caveated" : "not-covered";
5740
5739
  }
5741
5740
  retiredGraphError() {
5742
5741
  try {
@@ -5835,11 +5834,23 @@ var SharingService = class {
5835
5834
  const errorText = await registerRes.text();
5836
5835
  const registrationTextActiveError = this.retiredGraphError();
5837
5836
  if (registrationTextActiveError) return { ok: false, error: registrationTextActiveError };
5837
+ const message = `Failed to register delegation with server: ${registerRes.status} ${errorText}`;
5838
+ if (registerRes.status === 401 || registerRes.status === 403) {
5839
+ return {
5840
+ ok: false,
5841
+ error: createError2(
5842
+ DelegationErrorCodes.AUTH_UNAUTHORIZED,
5843
+ message,
5844
+ void 0,
5845
+ { status: registerRes.status }
5846
+ )
5847
+ };
5848
+ }
5838
5849
  return {
5839
5850
  ok: false,
5840
5851
  error: createError2(
5841
5852
  DelegationErrorCodes.CREATION_FAILED,
5842
- `Failed to register delegation with server: ${registerRes.status} ${errorText}`
5853
+ message
5843
5854
  )
5844
5855
  };
5845
5856
  }