defaultClassifyRisk
Default ClassifyRiskFn implementation that evaluates the ConsentRiskAssessment for a presentmentData given the trustedRequesterIdentity, the active selections per use-case, and the classified purposes.
Implementation Details
The risk level and accompanying ConsentRiskReasons are evaluated in the following order:
Requester trust baseline:
The requester is considered trusted (
isRequesterTrusted = true) if and only if trustedRequesterIdentity is non-null.When
isRequesterTrustedisfalse, the requester is either unverified (requester.requesterIdentities.isNotEmpty(), i.e. signed with a certificate chain whose root is not in the wallet's trust list) or anonymous (requester.requesterIdentities.isEmpty(), i.e. did not provide a digital signature/certificate).Whenever
isRequesterTrustedisfalseand the evaluated risk level is ConsentRiskLevel.WARNING or ConsentRiskLevel.HIGH_RISK, either ConsentRiskReason.UNTRUSTED_REQUESTER (for an unverified requester) or ConsentRiskReason.ANONYMOUS_REQUESTER (for an anonymous requester) is included in the returned ConsentRiskAssessment.reasons.No credentials selected (all use-cases are optional and omitted with selection
-1):If
isRequesterTrustedistrue, returns ConsentRiskLevel.NORMAL with no reasons.If
isRequesterTrustedisfalseand Requester.isProximity istrue, returns ConsentRiskLevel.NORMAL with ConsentRiskReason.UNTRUSTED_REQUESTER or ConsentRiskReason.ANONYMOUS_REQUESTER.Otherwise (untrusted over-the-Internet or app-to-app requester), returns ConsentRiskLevel.WARNING with ConsentRiskReason.UNTRUSTED_REQUESTER or ConsentRiskReason.ANONYMOUS_REQUESTER.
Unusual request or unknown schema attribute (checked for both trusted and untrusted requesters):
If any selected credential match contains a claim whose
attribute == null(not defined in the credential schema), or if purposes is empty and the selection violates the claim rules of a known document type, violates declared PresentmentUseCase.purposeHints, or consists entirely of known document types (whose purposes were rejected by a custom classifier), returns ConsentRiskLevel.HIGH_RISK with ConsentRiskReason.UNUSUAL_REQUEST (plus ConsentRiskReason.UNTRUSTED_REQUESTER or ConsentRiskReason.ANONYMOUS_REQUESTER if the requester is untrusted/anonymous).If purposes is empty solely because a selected credential uses a custom or generic document type (whose requested claims are all defined in its schema and no PresentmentUseCase.purposeHints are violated), the request is not flagged as ConsentRiskReason.UNUSUAL_REQUEST and evaluation continues below.
Untrusted claim-level encryption target (checked for both trusted and untrusted requesters):
If any selected credential match requests encryption (
encryptionRequested == true) and its encryption target is not in a trust list (encryptionTargetTrustMetadata == null), ConsentRiskReason.UNTRUSTED_ENCRYPTION_TARGET is added.If any such untrusted encryption target is anonymous (
encryptionTargetCertificationChain == null), the request is escalated to ConsentRiskLevel.HIGH_RISK; if all such targets are unverified (encryptionTargetCertificationChain != null, i.e. presented a certificate chain not in the trust list), it escalates to ConsentRiskLevel.WARNING (unless another condition escalates to ConsentRiskLevel.HIGH_RISK).Untrusted requester checks (when
isRequesterTrustedisfalse):Sensitive request escalations (all matching reasons are collected together alongside ConsentRiskReason.UNTRUSTED_REQUESTER / ConsentRiskReason.ANONYMOUS_REQUESTER and any ConsentRiskReason.UNTRUSTED_ENCRYPTION_TARGET):
PII requested: If the maximum claim sensitivity across the selected matches is at least DocumentAttributeSensitivity.PII, adds ConsentRiskReason.PII_REQUESTED. Note that by default this check inspects all selected matches—including matches encrypted for a trusted encryption target—because the untrusted intermediary still has knowledge of the transaction; however, this is a policy decision, and a wallet whose threat model accepts an untrusted intermediary forwarding encrypted claims to a trusted encryption target could override ClassifyRiskFn to classify such requests as ConsentRiskLevel.NORMAL.
Intent to retain: If any requested mdoc claim in the selected matches has MdocRequestedClaim.intentToRetain set to
trueand its attribute sensitivity is at least DocumentAttributeSensitivity.PII (for proximity requests, where Requester.isProximity istrue) or at least DocumentAttributeSensitivity.PORTRAIT_IMAGE (for over-the-Internet or app-to-app requests, where Requester.isProximity isfalse), adds ConsentRiskReason.INTENT_TO_RETAIN.Transaction data: If any selected credential match includes non-empty
transactionData, adds ConsentRiskReason.TRANSACTION_DATA.If one or more of the above sensitive reasons matched:
If the requester is anonymous (
requester.requesterIdentities.isEmpty()) and non-proximity (!requester.isProximity, i.e. over-the-Internet or app-to-app), or if an anonymous encryption target is present, returns ConsentRiskLevel.HIGH_RISK with all matched reasons.Otherwise (the requester signed the request with an unverified certificate chain, or the request is over proximity), returns ConsentRiskLevel.WARNING with all matched reasons.
Low-sensitivity request: Otherwise (e.g., an untrusted requester asking only for non-PII claims without sensitive retention or transaction data):
If an untrusted encryption target is present, returns ConsentRiskLevel.HIGH_RISK (for an anonymous encryption target) or ConsentRiskLevel.WARNING (for an unverified encryption target) with
UNTRUSTED_REQUESTERandUNTRUSTED_ENCRYPTION_TARGET.If Requester.isProximity is
true, returns ConsentRiskLevel.NORMAL with ConsentRiskReason.UNTRUSTED_REQUESTER or ConsentRiskReason.ANONYMOUS_REQUESTER, since the user is physically in proximity to the relying party (which is already free to observe and capture their likeness).If Requester.isProximity is
false(over-the-Internet or app-to-app), returns ConsentRiskLevel.WARNING with ConsentRiskReason.UNTRUSTED_REQUESTER.Trusted requester:
When
isRequesterTrustedistrueand step 3 did not trigger:If an untrusted encryption target is present (step 4), returns ConsentRiskLevel.HIGH_RISK (when
encryptionTargetCertificationChain == null) or ConsentRiskLevel.WARNING (whenencryptionTargetCertificationChain != null) with ConsentRiskReason.UNTRUSTED_ENCRYPTION_TARGET.Otherwise returns ConsentRiskLevel.NORMAL with an empty set of reasons.
Return
the evaluated ConsentRiskAssessment.
Parameters
the relying party which is requesting the data.
trust information for the requester, or null if untrusted.
the combinations of credentials and claims that the user can select.
the selected solution indices for each PresentmentUseCase in PresentmentData.useCases, or an empty list for an omitted optional use-case. Defaults to PresentmentData.defaultSelections.
the classified PresentmentPurposes for selections. Defaults to defaultClassifyPurposes(requester, trustedRequesterIdentity, presentmentData, selections).