class · Browser and Node

# TrailProcessor

Processes a trail's messages against a verified KEL. Witnesses and watchers use it incrementally; verifyTrail uses it in one pass.

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

Import:

```ts
import { TrailProcessor } from "@toip-tools/eventlog";
```

## Constructor

Constructor:

```ts
new (kel: KelResult, opts?: TrailVerifyOptions): TrailProcessor;
```

### Parameters

**`kel` (required)**

`KelResult`

**`opts` (optional)**

`TrailVerifyOptions`

Default: `{}`

**Fields of `opts`**

**`endorserKels` (optional)**

`KelResult[] | undefined`

KELs of AIDs that may endorse entries with -F groups.

**`verifySig` (optional)**

`((input: { key: Qb64; message: Uint8Array; sig: IndexedSig; }) => Promise<boolean | undefined> | boolean | undefined) | undefined`

A pluggable verifier, tried first. Return undefined to fall back to the built-in checks.

**`webauthn` (optional)**

`false | WebAuthnPolicy | undefined`

How to check WebAuthn-wrapped signatures. `false` rejects them.

**`allowUnwitnessed` (optional)**

`boolean | undefined`

Don't require witness receipts (a controller checking its own log).

**`firstSeen` (optional)**

`LogStore | undefined`

Compare with this store's first-seen copies.

**`clock` (optional)**

`Clock | undefined`

### Returns

`TrailProcessor`

## Properties

- **`trailId` (optional)**: `string | undefined`
- **`controller` (required)**: `string`
- **`purpose` (required)**: `string`
- **`trunk` (required)**: `Rec[]`
- **`cut` (required)**: `Rec[]`
- **`invalid` (required)**: `Rec[]`
- **`problems` (required)**: `Problem[]`
- **`evidence` (required)**: `DuplicityEvidence[]`

## Methods

### `closed`

Signature:

```ts
closed(): boolean;
```

No parameters.

#### Returns

`boolean`

### `head`

Signature:

```ts
head(): {
    s: number;
    d: Qb64;
} | undefined;
```

No parameters.

#### Returns

`{ s: number; d: Qb64; } | undefined`

### `setKel`

Replaces the KEL (after a rotation) and re-runs every message.

Signature:

```ts
setKel(kel: KelResult): Promise<void>;
```

#### Parameters

- **`kel` (required)**: `KelResult`

#### Returns

`Promise<void>`

### `add`

Adds a tin, ten or tcl.

Signature:

```ts
add(m: SignedMessage): Promise<{
    result: "first" | "same" | "cut" | "duplicity" | "invalid";
    problem?: Problem;
    cutBy?: number;
}>;
```

#### Parameters

- **`m` (required)**: `SignedMessage`

#### Returns

`Promise<{ result: "first" | "same" | "cut" | "duplicity" | "invalid"; problem?: Problem; cutBy?: number; }>`

### `addReceipt`

Adds a trc. Returns what it was: a witness receipt, an endorsement, or nothing usable. A witness that receipted two versions at one location is recorded as witness duplicity.

Signature:

```ts
addReceipt(trc: SignedMessage): {
    kind: "witness" | "endorsement" | "none";
    signer?: string;
};
```

#### Parameters

- **`trc` (required)**: `SignedMessage`

#### Returns

`{ kind: "witness" | "endorsement" | "none"; signer?: string; }`

### `result`

Signature:

```ts
result(bodies?: Body[]): TrailResult;
```

#### Parameters

**`bodies` (optional)**

`Body[]`

Default: `[]`

#### Returns

`TrailResult`

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

---

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