Normalize CipherOwl results into one decision: clear, review or
block, with the reasons and score behind it.
The thresholds are yours: this module has no built-in defaults, so
a policy states every rule it applies (see the README for suggested
starting points). decide takes any mix of screening, risk-score,
risk-breakdown and detail results (one Map or a Vec of them) and a
policy:
found-risk(required): the decision when screening reportsfoundRisk: trueand no stricter rule fires,"review"or"block"(or"clear"to rely on the score and categories only).review-score/block-score: ariskScore(0-100) at or above the value escalates.review-bands/block-bands: risk bands that escalate, as"severe"or CipherOwl's"Severe Risk"spelling (both work).review-categories/block-categories: risk categories (e.g."ofac","hack","jp_sanctioned") that escalate when found withinmax-hops(unset: any distance).direct-block-categories: categories that block only on direct exposure (hops 0 or type/directionDIRECT).
Evidence that says nothing (no foundRisk, score or reasons) gives
review, never clear.
Values
DECISIONS
DECISIONS: Vec [
"clear",
"review",
"block"
]
Functions
decide
fn (results: Any, policy: Map): Map
Decide on one address from its results and your policy. Returns
{decision, triggers, score, band ("low" | "medium" | "high" | "severe"), found-risk, config, reasons}:
triggers are the rules that fired, e.g. "block-score>=75",
"block-category:ofac", "found-risk"; reasons are the
normalized categories ({category, direction, hops, direct, source}), without paths or counterparty addresses. An invalid
policy is an Err.
Example
policy {found-risk: "review", review-score: 40, block-score: 75, block-categories: ["ofac"], max-hops: 2}
out ::cipherowl::decisions/decide([
{foundRisk: true, config: "co-sandbox"},
{riskScore: 100, riskBand: "Severe Risk", breakdown: [{category: "ofac", direction: "RECEIVE", hops: 1}]}
], policy)
out.decision
decide-batch
fn (batch-result: Any, policy: Map): Vec<Map>
Decide on every address in a batch screening result with the same policy
(screening alone carries only foundRisk, so found-risk decides).
Returns [{address, decision, triggers}].
Example
batch {results: [
{address: "0x93df2c9c8786242b8fdca3f96b3914b8b4a9f704", foundRisk: true},
{address: "0x0000000000000000000000000000000000000001", foundRisk: false}
]}
::cipherowl::decisions/decide-batch(batch, {found-risk: "review"})
// [{address: "0x93df2c9c8786242b8fdca3f96b3914b8b4a9f704", decision: "review", triggers: ["found-risk"]}, {address: "0x0000000000000000000000000000000000000001", decision: "clear", triggers: []}]
evidence
fn (results: Any): Map
Collect the decision inputs from one or more results: {found-risk, score, band, config, reasons}. found-risk is true when any result
says so; score is the highest riskScore; band the riskBand of
that score. Exposed for testing.
Example
found ::cipherowl::decisions/evidence([{foundRisk: true}, {riskScore: 82, riskBand: "High Risk"}])
found.found-risk // true
found.score // 82
found.band // "high"
reason-of
fn (item: Map, source: Str): Map
One normalized reason {category, direction, hops, direct, source} from
a detail reason, a score breakdown item or a breakdown risk. Paths,
counterparty addresses and USD values are left out. Exposed for testing.
Example
::cipherowl::decisions/reason-of({category: "OFAC", direction: "RECEIVE", hops: 1}, "risk-score")
// {category: "ofac", direction: "receive", hops: 1, direct: false, source: "risk-score"}
validate-policy
fn (policy: Map): Map
The policy when it is well formed, otherwise an Err naming the problem:
found-risk must be one of DECISIONS; scores numbers from 0 to 100
with review-score not above block-score; bands and categories Vecs
of Str; max-hops an Int from 0 to 8. Exposed for testing.
Example
::cipherowl::decisions/validate-policy({found-risk: "review", block-score: 75}) // {found-risk: "review", block-score: 75}
is-err(::cipherowl::decisions/validate-policy({review-score: 40})) // true