toip.tools

class · Browser and Node

MandateEngine

@toip-tools/mandatesView source
TypeScriptImport
import { MandateEngine } from "@toip-tools/mandates";

Constructor

This class has no public constructor. Use its public factory methods below to create an instance.

Properties

policyHashrequired · readonly
string

Methods

evaluate

Runs the policy on facts. Deterministic: the same input gives the same output.

TypeScriptSignature
evaluate(input: PolicyInput): PolicyOutput;

Parameters

inputrequired
PolicyInput
Fields of input
nowSrequired
number
actionrequired
Pick<Action, "attrs" | "type"> & Partial<Action>
actionHashrequired
string
chainrequired
LinkFacts[]
structuralrequired
Reason[]

Reasons from steps 1 to 8, and presentation problems.

approvalProblemsrequired
Reason[]

Problems with approvals; those approvals are left out of approvals.

staterequired
{ spent: Record<string, Partial<Record<Period, Units>>>; }
approvalsrequired
{ id: string; approverLink: number; actionHash: string; validUntilS: number; used: boolean; }[]

Approvals whose signatures and bindings TypeScript checked.

requirementsrequired
Omit<Requirements, "maxStatusAgeSeconds">
factsrequired
{ rootCredentials: string[]; passport?: { issuer: string; subject: string; } | null; }
optionsoptional
{ skipNarrowing?: boolean; } | undefined

Returns

narrowing

The narrowing step for one parent and child, on facts. Empty means the child narrows.

TypeScriptSignature
narrowing(parent: LinkFacts, child: LinkFacts): Reason[];

Parameters

parentrequired
LinkFacts
childrequired
LinkFacts

Returns

narrows

Whether child narrows parent (§7.2, §7.3). Empty means it does. Signatures and links aren't checked here.

TypeScriptSignature
narrows(parent: Mandate, child: Mandate): Promise<Reason[]>;

Parameters

parentrequired
Mandate
childrequired
Mandate

Returns

Promise<Reason[]>

checkChain

Checks a chain without an action: steps 1 to 9. Status lists are checked only with a resolver. A delegate uses it on a mandate it receives.

TypeScriptSignature
checkChain(i: {
    chain: Mandate[];
    presenter: string;
    clock: Clock;
    status?: StatusResolver;
    requirements?: Requirements;
}): Promise<Reason[]>;

Parameters

irequired
{ chain: Mandate[]; presenter: string; clock: Clock; status?: StatusResolver; requirements?: Requirements; }

Returns

Promise<Reason[]>

decide

Decides an action against a chain (§8.2).

TypeScriptSignature
decide(i: DecideInput): Promise<Decision>;

Parameters

irequired
DecideInput

Returns

Promise<Decision>

verifyPresentation

What a counterparty runs on a presentation (§8.7). sender is the TSP sender; me is this verifier's DID. The presentation's spend statement is the budget state, and its status lists are hints: the newest valid list wins.

TypeScriptSignature
verifyPresentation(p: Presentation, o: {
    sender: string;
    me: string;
    status: StatusResolver;
    requirements?: Requirements;
    clock: Clock;
}): Promise<Decision>;

Parameters

prequired
Presentation
orequired
{ sender: string; me: string; status: StatusResolver; requirements?: Requirements; clock: Clock; }

Returns

Promise<Decision>

static load

Loads the policy. Without wasm, the bundled policy/policy.wasm (read from disk in Node, fetched in a browser).

TypeScriptSignature
load(wasm?: BufferSource): Promise<MandateEngine>;

Parameters

wasmoptional
BufferSource | undefined

Returns

Promise<MandateEngine>