@tinycloud/sdk-core 3.0.0-beta.8 → 3.0.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.
- package/dist/{credential-admission-CFjUChF8.d.cts → credential-admission-BxpkckU0.d.cts} +23 -3
- package/dist/{credential-admission-DIEPgQ0o.d.ts → credential-admission-CO9WMtGs.d.ts} +23 -3
- package/dist/delegations/index.cjs +101 -188
- package/dist/delegations/index.cjs.map +1 -1
- package/dist/delegations/index.d.cts +3 -3
- package/dist/delegations/index.d.ts +3 -3
- package/dist/delegations/index.js +102 -193
- package/dist/delegations/index.js.map +1 -1
- package/dist/index.cjs +381 -218
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +74 -7
- package/dist/index.d.ts +74 -7
- package/dist/index.js +382 -223
- package/dist/index.js.map +1 -1
- package/dist/policy/index.cjs +82 -36
- package/dist/policy/index.cjs.map +1 -1
- package/dist/policy/index.d.cts +2 -2
- package/dist/policy/index.d.ts +2 -2
- package/dist/policy/index.js +82 -36
- package/dist/policy/index.js.map +1 -1
- package/dist/{recipient-types.schema-DjmM_yJu.d.cts → recipient-types.schema-D9AI8tjN.d.cts} +42 -105
- package/dist/{recipient-types.schema-DjmM_yJu.d.ts → recipient-types.schema-D9AI8tjN.d.ts} +42 -105
- package/package.json +4 -4
package/dist/policy/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { P as PolicyEngineRecord, S as SignedObjectSigner, a as Policy, U as UnsignedPolicyEngineRecord } from '../credential-admission-
|
|
2
|
-
export { A as ATTESTED_ENFORCER_BINDING_V2_SCHEMA, b as AdmitPolicyCredentialV3Input, c as AdmitPolicyCredentialV4Input, d as AttestedEnforcerBindingV2, B as BuildPolicyCredentialPresentationV3Input, e as BuildPolicyCredentialPresentationV4Input, C as CONTENT_SOURCE_V1_DOMAIN, f as
|
|
1
|
+
import { P as PolicyEngineRecord, S as SignedObjectSigner, a as Policy, U as UnsignedPolicyEngineRecord } from '../credential-admission-BxpkckU0.cjs';
|
|
2
|
+
export { A as ATTESTED_ENFORCER_BINDING_V2_SCHEMA, b as AdmitPolicyCredentialV3Input, c as AdmitPolicyCredentialV4Input, d as AttestedEnforcerBindingV2, B as BuildPolicyCredentialPresentationV3Input, e as BuildPolicyCredentialPresentationV4Input, C as CONTENT_SOURCE_V1_DOMAIN, f as CompactPolicyDescendantInput, g as CompactPolicyInvocationInput, h as CompactUcanAuthorizationV1, E as ED25519_JCS_SIGNATURE_SUITE, i as EIP191_JCS_SIGNATURE_SUITE, J as JsonObject, L as LAST_V2_CREATE_AT, j as LAST_V2_READ_AT, M as MAX_LEGACY_ENVELOPE_EXPIRES_AT, N as NATIVE_PROJECTION_V1_DOMAIN, k as POLICY_CAPABILITY_V1_DOMAIN, l as POLICY_CAPABILITY_V1_SCHEMA, m as POLICY_CREDENTIAL_REQUIREMENT_V1_TYPE, n as POLICY_ENFORCEMENT_DELEGATION_V2_SCHEMA, o as POLICY_ENGINE_RECORD_SCHEMA, p as POLICY_PRESENTATION_V3_DOMAIN, q as POLICY_PRESENTATION_V3_SCHEMA, r as POLICY_PRESENTATION_V4_DOMAIN, s as POLICY_PRESENTATION_V4_SCHEMA, t as POLICY_SCHEMA, u as POLICY_SESSION_UCAN_V1_PROFILE, v as POLICY_STATUS_SCHEMA, w as POLICY_V1_DOMAIN, x as POLICY_V1_SCHEMA, y as POLICY_V2_DOMAIN, z as POLICY_V2_SCHEMA, D as PolicyChallengeV3, F as PolicyCredentialAdmissionV3, G as PolicyCredentialAdmissionV4, H as PolicyCredentialPresentationV3, I as PolicyCredentialPresentationV4, K as PolicyCredentialRequirementV1, O as PolicyRootStatusV3, Q as PolicyRootV3, R as PolicySessionUcanFactV1, T as PolicySessionUcanV1, V as PolicyStatus, W as ROOT_REVOCATION_V1_DOMAIN, X as ROOT_REVOCATION_V1_SCHEMA, Y as ROOT_STATUS_CHECKPOINT_V1_SCHEMA, Z as ROOT_STATUS_RENEWAL_V1_DOMAIN, _ as ROOT_STATUS_V1_DOMAIN, $ as RegisterPolicyV3Input, a0 as RegisterPolicyV3Receipt, a1 as SignCompactUcanAuthorizationInput, a2 as SignCompactUcanRootAuthorizationInput, a3 as SignatureMaterialError, a4 as SignatureSuite, a5 as SignatureVerificationError, a6 as SignedObjectCanonicalizationError, a7 as SignedObjectDigestError, a8 as SignedObjectErrorCode, a9 as SignedObjectIdError, aa as SignedObjectKind, ab as SignedObjectMaterial, ac as SignedObjectProfileError, ad as SignedObjectSchemaError, ae as SignedObjectSignature, af as SignedObjectVerificationResult, ag as SignedPolicyObject, ah as SigningKeyBindingError, ai as UnifiedContentSource, aj as UnifiedEncryptionCapability, ak as UnifiedKvCapability, al as UnifiedNativeCapability, am as UnifiedPolicyCapability, an as UnifiedPolicyV1, ao as UnifiedPolicyV2, ap as UnifiedResourceSelector, aq as UnsignedPolicy, ar as UnsignedPolicyCredentialPresentationV4, as as UnsignedPolicyObject, at as UnsignedPolicyStatus, au as UnsignedUnifiedPolicyV2, av as UnsupportedSignatureSuiteError, aw as admitPolicyCredentialV3, ax as admitPolicyCredentialV4, ay as buildPolicyCredentialPresentationV3, az as buildPolicyCredentialPresentationV4, aA as canonicalizeSignedObjectUnsigned, aB as canonicalizeUnifiedPolicyCapability, aC as compactAttenuationContains, aD as contentSourceDigestHex, aE as createAndSignPolicy, aF as createAndSignPolicyEngineRecord, aG as createAndSignPolicyStatus, aH as createAndSignSignedObject, aI as createCompactPolicyDescendant, aJ as createCompactPolicyInvocation, aK as deriveSignedObjectMaterial, aL as getPolicyRootStatusV3, aM as issuedCredentialEnvelopeFromVerified, aN as mintPolicySessionV3, aO as normalizeUnifiedPolicyCapability, aP as parseCompactUcanAuthorization, aQ as parsePolicySessionUcan, aR as policyCidFromCanonicalBytes, aS as policyDigestHex, aT as policyIdForDigestHex, aU as policyV2DigestHex, aV as projectUnifiedPolicyCapabilities, aW as projectUnifiedPolicyCapability, aX as registerPolicyV3, aY as renewPolicyRootStatusV3, aZ as requestPolicyChallengeV3, a_ as revokePolicyRootV3, a$ as signCompactPolicyDescendant, b0 as signCompactUcanAuthorization, b1 as signCompactUcanRootAuthorization, b2 as signPolicyCredentialPresentationV4, b3 as signedObjectIdFor, b4 as toSignedObjectError, b5 as unifiedNativeProjectionHashHex, b6 as unifiedPolicyCapabilityContains, b7 as unifiedPolicyCapabilityDigestHex, b8 as unifiedPolicyCapabilityFromNative, b9 as validatePolicyCredentialRequirementV1, ba as validatePolicyEngineRecordSigned, bb as validatePolicyEngineRecordSignedShape, bc as validatePolicyEngineRecordUnsigned, bd as validatePolicySigned, be as validatePolicySignedShape, bf as validatePolicyStatusSigned, bg as validatePolicyStatusSignedShape, bh as validatePolicyStatusUnsigned, bi as validatePolicyUnsigned, bj as validateUnifiedPolicyV2, bk as verifyPolicy, bl as verifyPolicyEngineRecord, bm as verifyPolicyRootRevocationV3, bn as verifyPolicyRootStatusCheckpointV3, bo as verifyPolicyStatus, bp as verifySignedObject } from '../credential-admission-BxpkckU0.cjs';
|
|
3
3
|
import { J as JsonObject, P as PolicyCapabilityError } from '../capability-BjzXwtNw.cjs';
|
|
4
4
|
export { a as JsonValue, b as PolicyCapability, c as PolicyCapabilityErrorCode, d as canonicalizePolicyCapability, j as jcsCanonicalize, n as normalizeJson, e as normalizePolicyCapability, p as policyCapabilityContains, f as policyCapabilityDigestHex, s as serializeJcsJson } from '../capability-BjzXwtNw.cjs';
|
|
5
5
|
import 'zod';
|
package/dist/policy/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { P as PolicyEngineRecord, S as SignedObjectSigner, a as Policy, U as UnsignedPolicyEngineRecord } from '../credential-admission-
|
|
2
|
-
export { A as ATTESTED_ENFORCER_BINDING_V2_SCHEMA, b as AdmitPolicyCredentialV3Input, c as AdmitPolicyCredentialV4Input, d as AttestedEnforcerBindingV2, B as BuildPolicyCredentialPresentationV3Input, e as BuildPolicyCredentialPresentationV4Input, C as CONTENT_SOURCE_V1_DOMAIN, f as
|
|
1
|
+
import { P as PolicyEngineRecord, S as SignedObjectSigner, a as Policy, U as UnsignedPolicyEngineRecord } from '../credential-admission-CO9WMtGs.js';
|
|
2
|
+
export { A as ATTESTED_ENFORCER_BINDING_V2_SCHEMA, b as AdmitPolicyCredentialV3Input, c as AdmitPolicyCredentialV4Input, d as AttestedEnforcerBindingV2, B as BuildPolicyCredentialPresentationV3Input, e as BuildPolicyCredentialPresentationV4Input, C as CONTENT_SOURCE_V1_DOMAIN, f as CompactPolicyDescendantInput, g as CompactPolicyInvocationInput, h as CompactUcanAuthorizationV1, E as ED25519_JCS_SIGNATURE_SUITE, i as EIP191_JCS_SIGNATURE_SUITE, J as JsonObject, L as LAST_V2_CREATE_AT, j as LAST_V2_READ_AT, M as MAX_LEGACY_ENVELOPE_EXPIRES_AT, N as NATIVE_PROJECTION_V1_DOMAIN, k as POLICY_CAPABILITY_V1_DOMAIN, l as POLICY_CAPABILITY_V1_SCHEMA, m as POLICY_CREDENTIAL_REQUIREMENT_V1_TYPE, n as POLICY_ENFORCEMENT_DELEGATION_V2_SCHEMA, o as POLICY_ENGINE_RECORD_SCHEMA, p as POLICY_PRESENTATION_V3_DOMAIN, q as POLICY_PRESENTATION_V3_SCHEMA, r as POLICY_PRESENTATION_V4_DOMAIN, s as POLICY_PRESENTATION_V4_SCHEMA, t as POLICY_SCHEMA, u as POLICY_SESSION_UCAN_V1_PROFILE, v as POLICY_STATUS_SCHEMA, w as POLICY_V1_DOMAIN, x as POLICY_V1_SCHEMA, y as POLICY_V2_DOMAIN, z as POLICY_V2_SCHEMA, D as PolicyChallengeV3, F as PolicyCredentialAdmissionV3, G as PolicyCredentialAdmissionV4, H as PolicyCredentialPresentationV3, I as PolicyCredentialPresentationV4, K as PolicyCredentialRequirementV1, O as PolicyRootStatusV3, Q as PolicyRootV3, R as PolicySessionUcanFactV1, T as PolicySessionUcanV1, V as PolicyStatus, W as ROOT_REVOCATION_V1_DOMAIN, X as ROOT_REVOCATION_V1_SCHEMA, Y as ROOT_STATUS_CHECKPOINT_V1_SCHEMA, Z as ROOT_STATUS_RENEWAL_V1_DOMAIN, _ as ROOT_STATUS_V1_DOMAIN, $ as RegisterPolicyV3Input, a0 as RegisterPolicyV3Receipt, a1 as SignCompactUcanAuthorizationInput, a2 as SignCompactUcanRootAuthorizationInput, a3 as SignatureMaterialError, a4 as SignatureSuite, a5 as SignatureVerificationError, a6 as SignedObjectCanonicalizationError, a7 as SignedObjectDigestError, a8 as SignedObjectErrorCode, a9 as SignedObjectIdError, aa as SignedObjectKind, ab as SignedObjectMaterial, ac as SignedObjectProfileError, ad as SignedObjectSchemaError, ae as SignedObjectSignature, af as SignedObjectVerificationResult, ag as SignedPolicyObject, ah as SigningKeyBindingError, ai as UnifiedContentSource, aj as UnifiedEncryptionCapability, ak as UnifiedKvCapability, al as UnifiedNativeCapability, am as UnifiedPolicyCapability, an as UnifiedPolicyV1, ao as UnifiedPolicyV2, ap as UnifiedResourceSelector, aq as UnsignedPolicy, ar as UnsignedPolicyCredentialPresentationV4, as as UnsignedPolicyObject, at as UnsignedPolicyStatus, au as UnsignedUnifiedPolicyV2, av as UnsupportedSignatureSuiteError, aw as admitPolicyCredentialV3, ax as admitPolicyCredentialV4, ay as buildPolicyCredentialPresentationV3, az as buildPolicyCredentialPresentationV4, aA as canonicalizeSignedObjectUnsigned, aB as canonicalizeUnifiedPolicyCapability, aC as compactAttenuationContains, aD as contentSourceDigestHex, aE as createAndSignPolicy, aF as createAndSignPolicyEngineRecord, aG as createAndSignPolicyStatus, aH as createAndSignSignedObject, aI as createCompactPolicyDescendant, aJ as createCompactPolicyInvocation, aK as deriveSignedObjectMaterial, aL as getPolicyRootStatusV3, aM as issuedCredentialEnvelopeFromVerified, aN as mintPolicySessionV3, aO as normalizeUnifiedPolicyCapability, aP as parseCompactUcanAuthorization, aQ as parsePolicySessionUcan, aR as policyCidFromCanonicalBytes, aS as policyDigestHex, aT as policyIdForDigestHex, aU as policyV2DigestHex, aV as projectUnifiedPolicyCapabilities, aW as projectUnifiedPolicyCapability, aX as registerPolicyV3, aY as renewPolicyRootStatusV3, aZ as requestPolicyChallengeV3, a_ as revokePolicyRootV3, a$ as signCompactPolicyDescendant, b0 as signCompactUcanAuthorization, b1 as signCompactUcanRootAuthorization, b2 as signPolicyCredentialPresentationV4, b3 as signedObjectIdFor, b4 as toSignedObjectError, b5 as unifiedNativeProjectionHashHex, b6 as unifiedPolicyCapabilityContains, b7 as unifiedPolicyCapabilityDigestHex, b8 as unifiedPolicyCapabilityFromNative, b9 as validatePolicyCredentialRequirementV1, ba as validatePolicyEngineRecordSigned, bb as validatePolicyEngineRecordSignedShape, bc as validatePolicyEngineRecordUnsigned, bd as validatePolicySigned, be as validatePolicySignedShape, bf as validatePolicyStatusSigned, bg as validatePolicyStatusSignedShape, bh as validatePolicyStatusUnsigned, bi as validatePolicyUnsigned, bj as validateUnifiedPolicyV2, bk as verifyPolicy, bl as verifyPolicyEngineRecord, bm as verifyPolicyRootRevocationV3, bn as verifyPolicyRootStatusCheckpointV3, bo as verifyPolicyStatus, bp as verifySignedObject } from '../credential-admission-CO9WMtGs.js';
|
|
3
3
|
import { J as JsonObject, P as PolicyCapabilityError } from '../capability-BjzXwtNw.js';
|
|
4
4
|
export { a as JsonValue, b as PolicyCapability, c as PolicyCapabilityErrorCode, d as canonicalizePolicyCapability, j as jcsCanonicalize, n as normalizeJson, e as normalizePolicyCapability, p as policyCapabilityContains, f as policyCapabilityDigestHex, s as serializeJcsJson } from '../capability-BjzXwtNw.js';
|
|
5
5
|
import 'zod';
|
package/dist/policy/index.js
CHANGED
|
@@ -3807,8 +3807,9 @@ async function signCompactUcanAuthorization(input) {
|
|
|
3807
3807
|
throw new Error("compact invocation lifetime must be between one and 60 seconds");
|
|
3808
3808
|
return signCompactUcan(input);
|
|
3809
3809
|
}
|
|
3810
|
+
var MAX_POLICY_ROOT_SECONDS = 31 * 24 * 60 * 60;
|
|
3810
3811
|
async function signCompactUcanRootAuthorization(input) {
|
|
3811
|
-
if (input.notBefore >= input.expiresAt || input.expiresAt - input.notBefore >
|
|
3812
|
+
if (input.notBefore >= input.expiresAt || input.expiresAt - input.notBefore > MAX_POLICY_ROOT_SECONDS)
|
|
3812
3813
|
throw new Error("compact policy root lifetime must be between one second and 31 days");
|
|
3813
3814
|
return signCompactUcan({ ...input, proofs: [] });
|
|
3814
3815
|
}
|
|
@@ -3843,7 +3844,7 @@ function createCompactPolicyInvocation(input) {
|
|
|
3843
3844
|
const signature = ed255192.sign(signingInput, input.privateKey);
|
|
3844
3845
|
return parseCompactUcanAuthorization(`${protectedSegment}.${payloadSegment}.${encodeBase64Url(signature)}`);
|
|
3845
3846
|
}
|
|
3846
|
-
function
|
|
3847
|
+
function compactPolicyDescendantClaims(input) {
|
|
3847
3848
|
const parent = parseCompactUcanAuthorization(input.parentAuthorization, input.parentCid);
|
|
3848
3849
|
if (parent.payload.aud !== input.issuerDid) throw new Error("policy descendant issuer is not the parent audience");
|
|
3849
3850
|
const parentFact = parent.payload.fct[0];
|
|
@@ -3851,29 +3852,53 @@ function createCompactPolicyDescendant(input) {
|
|
|
3851
3852
|
if (!Number.isInteger(depth) || depth <= 0) throw new Error("policy descendant depth is exhausted");
|
|
3852
3853
|
if (!compactAttenuationContains(parent.payload.att, input.attenuation))
|
|
3853
3854
|
throw new Error("policy descendant exceeds the parent attenuation");
|
|
3855
|
+
const now = Math.max(input.now ?? parent.payload.nbf + 1, parent.payload.nbf + 1);
|
|
3856
|
+
const exp = Math.min(input.expiresAt ?? parent.payload.exp - 1, parent.payload.exp - 1);
|
|
3857
|
+
if (exp <= now) throw new Error("policy parent has no strictly narrower validity window");
|
|
3858
|
+
return {
|
|
3859
|
+
parentCid: parent.cid,
|
|
3860
|
+
fact: { ...parentFact, remainingRedelegationDepth: depth - 1 },
|
|
3861
|
+
notBefore: now,
|
|
3862
|
+
expiresAt: exp,
|
|
3863
|
+
nonce: input.nonce ?? encodeBase64Url(crypto.getRandomValues(new Uint8Array(16)))
|
|
3864
|
+
};
|
|
3865
|
+
}
|
|
3866
|
+
function createCompactPolicyDescendant(input) {
|
|
3867
|
+
const claims = compactPolicyDescendantClaims(input);
|
|
3854
3868
|
const principal = input.issuerDid.split("#", 1)[0];
|
|
3855
3869
|
const didMaterial = base58btc.decode(principal.slice("did:key:".length));
|
|
3856
3870
|
const publicKey = ed255192.getPublicKey(input.privateKey);
|
|
3857
3871
|
if (didMaterial.length !== 34 || !equalBytes(publicKey, didMaterial.slice(2))) throw new Error("policy descendant signer does not bind issuer DID");
|
|
3858
|
-
const now = Math.max(input.now ?? Math.floor(Date.now() / 1e3), parent.payload.nbf + 1);
|
|
3859
|
-
const exp = Math.min(input.expiresAt ?? now + 60, now + 60, parent.payload.exp - 1);
|
|
3860
|
-
if (exp <= now) throw new Error("policy parent has no strictly narrower validity window");
|
|
3861
3872
|
const header = { alg: "EdDSA", jwk: { alg: "EdDSA", crv: "Ed25519", kty: "OKP", x: encodeBase64Url(publicKey) }, typ: "JWT", ucv: "0.10.0" };
|
|
3862
3873
|
const payload = {
|
|
3863
3874
|
att: input.attenuation,
|
|
3864
3875
|
aud: input.audienceDid,
|
|
3865
|
-
exp,
|
|
3866
|
-
fct: [
|
|
3876
|
+
exp: claims.expiresAt,
|
|
3877
|
+
fct: [claims.fact],
|
|
3867
3878
|
iss: input.issuerDid.includes("#") ? input.issuerDid : `${principal}#${principal.slice("did:key:".length)}`,
|
|
3868
|
-
nbf:
|
|
3869
|
-
nnc:
|
|
3870
|
-
prf: [
|
|
3879
|
+
nbf: claims.notBefore,
|
|
3880
|
+
nnc: claims.nonce,
|
|
3881
|
+
prf: [claims.parentCid]
|
|
3871
3882
|
};
|
|
3872
3883
|
const protectedSegment = encodeBase64Url(new TextEncoder().encode(jcsCanonicalize(header)));
|
|
3873
3884
|
const payloadSegment = encodeBase64Url(new TextEncoder().encode(jcsCanonicalize(payload)));
|
|
3874
3885
|
const signature = ed255192.sign(new TextEncoder().encode(`${protectedSegment}.${payloadSegment}`), input.privateKey);
|
|
3875
3886
|
return parseCompactUcanAuthorization(`${protectedSegment}.${payloadSegment}.${encodeBase64Url(signature)}`);
|
|
3876
3887
|
}
|
|
3888
|
+
async function signCompactPolicyDescendant(input) {
|
|
3889
|
+
const claims = compactPolicyDescendantClaims(input);
|
|
3890
|
+
return signCompactUcan({
|
|
3891
|
+
issuerDid: input.issuerDid,
|
|
3892
|
+
audienceDid: input.audienceDid,
|
|
3893
|
+
attenuation: input.attenuation,
|
|
3894
|
+
facts: [claims.fact],
|
|
3895
|
+
proofs: [claims.parentCid],
|
|
3896
|
+
notBefore: claims.notBefore,
|
|
3897
|
+
expiresAt: claims.expiresAt,
|
|
3898
|
+
nonce: claims.nonce,
|
|
3899
|
+
sign: input.sign
|
|
3900
|
+
});
|
|
3901
|
+
}
|
|
3877
3902
|
function compactAttenuationContains(parent, child) {
|
|
3878
3903
|
const selector = (value) => {
|
|
3879
3904
|
if (value.length !== 1 || !isRecordValue(value[0])) return void 0;
|
|
@@ -3943,7 +3968,7 @@ function parsePolicySessionUcan(authorization, expectedProofs) {
|
|
|
3943
3968
|
throw new Error("policy session UCAN fact is incomplete");
|
|
3944
3969
|
if (hasV4AuditFactShape && (!LOWER_SHA256_HEX.test(fact.credentialIdAuditDigestHex) || !LOWER_SHA256_HEX.test(fact.presentationJtiAuditDigestHex)))
|
|
3945
3970
|
throw new Error("policy session UCAN v4 audit facts are invalid");
|
|
3946
|
-
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 >
|
|
3971
|
+
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)
|
|
3947
3972
|
throw new Error("policy session UCAN fact is invalid");
|
|
3948
3973
|
return {
|
|
3949
3974
|
authorization,
|
|
@@ -4024,6 +4049,7 @@ var RECOVERABLE = /* @__PURE__ */ new Set([
|
|
|
4024
4049
|
"ISSUER_UNREADY",
|
|
4025
4050
|
"OFFLINE",
|
|
4026
4051
|
"POPUP_BLOCKED",
|
|
4052
|
+
"PROOF_REJECTED",
|
|
4027
4053
|
"REQUEST_EXPIRED",
|
|
4028
4054
|
"SIGNATURE_REJECTED",
|
|
4029
4055
|
"UNSUPPORTED_PROFILE",
|
|
@@ -4042,6 +4068,7 @@ var CredentialError = class extends Error {
|
|
|
4042
4068
|
|
|
4043
4069
|
// src/credentials/requirement.ts
|
|
4044
4070
|
var ID = /^[a-z0-9][a-z0-9._-]{0,127}(?:\/v1)?$/;
|
|
4071
|
+
var CLAIM_NAME = /^[a-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
4045
4072
|
function validateCredentialRequirement(value) {
|
|
4046
4073
|
if (typeof value !== "object" || value === null || Array.isArray(value)) throw new CredentialError("UNSUPPORTED_PROFILE", "Credential requirement is invalid");
|
|
4047
4074
|
const raw = value;
|
|
@@ -4055,7 +4082,7 @@ function validateCredentialRequirement(value) {
|
|
|
4055
4082
|
if (typeof raw.claims !== "object" || raw.claims === null || Array.isArray(raw.claims)) throw new CredentialError("UNSUPPORTED_PROFILE", "Credential claims are invalid");
|
|
4056
4083
|
const claims = {};
|
|
4057
4084
|
for (const [key, value2] of Object.entries(raw.claims).sort(([a], [b]) => a.localeCompare(b))) {
|
|
4058
|
-
if (!
|
|
4085
|
+
if (!CLAIM_NAME.test(key) || typeof value2 !== "string" || value2.length === 0 || value2.length > 4096) throw new CredentialError("UNSUPPORTED_PROFILE", "Credential claim is invalid");
|
|
4059
4086
|
claims[key] = value2;
|
|
4060
4087
|
}
|
|
4061
4088
|
if (raw.maxAgeSeconds !== void 0 && (!Number.isSafeInteger(raw.maxAgeSeconds) || raw.maxAgeSeconds < 1)) throw new CredentialError("UNSUPPORTED_PROFILE", "Credential freshness is invalid");
|
|
@@ -4436,24 +4463,21 @@ async function admitPolicyCredentialV3(input) {
|
|
|
4436
4463
|
policy,
|
|
4437
4464
|
challenge
|
|
4438
4465
|
});
|
|
4439
|
-
const response = await
|
|
4466
|
+
const response = await postPolicyDelegation(
|
|
4467
|
+
fetchFn,
|
|
4440
4468
|
new URL(`${policyRuntimeBasePath2(input.policyRuntimePath)}/delegations`, nodeOrigin),
|
|
4441
4469
|
{
|
|
4442
|
-
|
|
4443
|
-
|
|
4444
|
-
|
|
4445
|
-
|
|
4446
|
-
|
|
4447
|
-
|
|
4448
|
-
|
|
4449
|
-
|
|
4450
|
-
|
|
4451
|
-
|
|
4452
|
-
|
|
4453
|
-
credentialSpaceId,
|
|
4454
|
-
presentation
|
|
4455
|
-
})
|
|
4456
|
-
}
|
|
4470
|
+
policyCid: input.policyCid,
|
|
4471
|
+
challengeId: challenge.challengeId,
|
|
4472
|
+
nonce: challenge.nonce,
|
|
4473
|
+
requirement: validateCredentialRequirement(input.requirement),
|
|
4474
|
+
credential: envelopeFromVerified(input.credential),
|
|
4475
|
+
accountAuthorizationCid,
|
|
4476
|
+
credentialSpaceId,
|
|
4477
|
+
presentation
|
|
4478
|
+
},
|
|
4479
|
+
requestedSessionExpiry(input.requestedExpiresAt, policy),
|
|
4480
|
+
input.signal
|
|
4457
4481
|
);
|
|
4458
4482
|
if (!response.ok) throw new Error(`policy delegation rejected (${response.status})`);
|
|
4459
4483
|
const value = record(await response.json(), "policy delegation");
|
|
@@ -4494,20 +4518,20 @@ async function admitPolicyCredentialV4(input) {
|
|
|
4494
4518
|
policy,
|
|
4495
4519
|
challenge
|
|
4496
4520
|
});
|
|
4497
|
-
const response = await
|
|
4498
|
-
|
|
4499
|
-
|
|
4500
|
-
|
|
4501
|
-
headers: { accept: "application/json", "content-type": "application/json" },
|
|
4502
|
-
body: JSON.stringify({
|
|
4521
|
+
const response = await postPolicyDelegation(
|
|
4522
|
+
fetchFn,
|
|
4523
|
+
new URL(`${policyRuntimeBasePath2(input.policyRuntimePath)}/delegations`, nodeOrigin),
|
|
4524
|
+
{
|
|
4503
4525
|
policyCid: input.policyCid,
|
|
4504
4526
|
challengeId: challenge.challengeId,
|
|
4505
4527
|
nonce: challenge.nonce,
|
|
4506
4528
|
requirement: validateCredentialRequirement(input.requirement),
|
|
4507
4529
|
credential: envelopeFromVerified(input.credential),
|
|
4508
4530
|
presentation
|
|
4509
|
-
}
|
|
4510
|
-
|
|
4531
|
+
},
|
|
4532
|
+
requestedSessionExpiry(input.requestedExpiresAt, policy),
|
|
4533
|
+
input.signal
|
|
4534
|
+
);
|
|
4511
4535
|
if (!response.ok) throw new Error(`policy delegation rejected (${response.status})`);
|
|
4512
4536
|
const value = record(await response.json(), "policy delegation");
|
|
4513
4537
|
if (value.admitted !== true || typeof value.sessionCid !== "string" || typeof value.authorization !== "string") throw new Error("policy delegation response is invalid");
|
|
@@ -4531,6 +4555,27 @@ async function admitPolicyCredentialV4(input) {
|
|
|
4531
4555
|
input.signal?.throwIfAborted();
|
|
4532
4556
|
return Object.freeze({ challenge, presentation, session, delegationImported: true });
|
|
4533
4557
|
}
|
|
4558
|
+
function requestedSessionExpiry(requested, policy) {
|
|
4559
|
+
const value = requested === void 0 ? policy.expiresAt : requested;
|
|
4560
|
+
if (value === null || value === void 0) return void 0;
|
|
4561
|
+
const seconds = Math.floor(Date.parse(value) / 1e3);
|
|
4562
|
+
if (!Number.isFinite(seconds) || seconds <= Math.floor(Date.now() / 1e3) + 60) return void 0;
|
|
4563
|
+
return new Date(seconds * 1e3).toISOString().replace(/\.\d{3}Z$/, "Z");
|
|
4564
|
+
}
|
|
4565
|
+
async function postPolicyDelegation(fetchFn, url, body, requestedExpiresAt, signal) {
|
|
4566
|
+
const send = (payload) => fetchFn(url, {
|
|
4567
|
+
method: "POST",
|
|
4568
|
+
redirect: "error",
|
|
4569
|
+
signal,
|
|
4570
|
+
headers: { accept: "application/json", "content-type": "application/json" },
|
|
4571
|
+
body: JSON.stringify(payload)
|
|
4572
|
+
});
|
|
4573
|
+
if (requestedExpiresAt === void 0) return send(body);
|
|
4574
|
+
const response = await send({ ...body, requestedExpiresAt });
|
|
4575
|
+
if (response.status !== 422) return response;
|
|
4576
|
+
await response.body?.cancel().catch(() => void 0);
|
|
4577
|
+
return send(body);
|
|
4578
|
+
}
|
|
4534
4579
|
function policyRuntimeBasePath2(value) {
|
|
4535
4580
|
const path = value ?? "/policy/v3";
|
|
4536
4581
|
if (!/^\/policy(?:\/[a-z0-9-]+)*$/.test(path)) {
|
|
@@ -4625,6 +4670,7 @@ export {
|
|
|
4625
4670
|
requestPolicyChallengeV3,
|
|
4626
4671
|
revokePolicyRootV3,
|
|
4627
4672
|
serialize as serializeJcsJson,
|
|
4673
|
+
signCompactPolicyDescendant,
|
|
4628
4674
|
signCompactUcanAuthorization,
|
|
4629
4675
|
signCompactUcanRootAuthorization,
|
|
4630
4676
|
signPolicyCredentialPresentationV4,
|