class · Browser and Node

# MandateEngine

`@toip-tools/mandates` · [View source](https://github.com/yourbuddyconner/toip-tools/blob/main/packages/mandates/src/engine.ts#L142)

Import:

```ts
import { MandateEngine } from "@toip-tools/mandates";
```

## Constructor

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

## Properties

- **`policyHash` (required · readonly)**: `string`

## Methods

### `evaluate`

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

Signature:

```ts
evaluate(input: PolicyInput): PolicyOutput;
```

#### Parameters

**`input` (required)**

`PolicyInput`

**Fields of `input`**

**`nowS` (required)**

`number`

**`action` (required)**

`Pick<Action, "attrs" | "type"> & Partial<Action>`

**`actionHash` (required)**

`string`

**`chain` (required)**

`LinkFacts[]`

**`structural` (required)**

`Reason[]`

Reasons from steps 1 to 8, and presentation problems.

**`approvalProblems` (required)**

`Reason[]`

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

**`state` (required)**

`{ spent: Record<string, Partial<Record<Period, Units>>>; }`

**`approvals` (required)**

`{ id: string; approverLink: number; actionHash: string; validUntilS: number; used: boolean; }[]`

Approvals whose signatures and bindings TypeScript checked.

**`requirements` (required)**

`Omit<Requirements, "maxStatusAgeSeconds">`

**`facts` (required)**

`{ rootCredentials: string[]; passport?: { issuer: string; subject: string; } | null; }`

**`options` (optional)**

`{ skipNarrowing?: boolean; } | undefined`

#### Returns

`PolicyOutput`

### `narrowing`

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

Signature:

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

#### Parameters

- **`parent` (required)**: `LinkFacts`
- **`child` (required)**: `LinkFacts`

#### Returns

`Reason[]`

### `narrows`

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

Signature:

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

#### Parameters

- **`parent` (required)**: `Mandate`
- **`child` (required)**: `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.

Signature:

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

#### Parameters

- **`i` (required)**: `{ chain: Mandate[]; presenter: string; clock: Clock; status?: StatusResolver; requirements?: Requirements; }`

#### Returns

`Promise<Reason[]>`

### `decide`

Decides an action against a chain (§8.2).

Signature:

```ts
decide(i: DecideInput): Promise<Decision>;
```

#### Parameters

- **`i` (required)**: `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.

Signature:

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

#### Parameters

- **`p` (required)**: `Presentation`
- **`o` (required)**: `{ 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).

Signature:

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

#### Parameters

- **`wasm` (optional)**: `BufferSource | undefined`

#### Returns

`Promise<MandateEngine>`

[Usage guide](https://toip.tools/toolkit/mandates/#usage) · [Error handling](https://toip.tools/toolkit/mandates/#errors) · [All exports](https://toip.tools/toolkit/mandates/api/)

---

This is the Markdown version of https://toip.tools/toolkit/mandates/api/MandateEngine/. An index of the documentation for AI assistants is at https://toip.tools/llms.txt.
