class · Browser and Node

# Endpoint

Sends and receives Trust Task documents as real TSP Direct messages. Every document it sends carries a Data Integrity proof by its identity, responses included.

`@toip-tools/trust-core` · [View source](https://github.com/yourbuddyconner/toip-tools/blob/main/packages/trust-core/src/tasks.ts#L80)

Import:

```ts
import { Endpoint } from "@toip-tools/trust-core";
```

## Constructor

Constructor:

```ts
new (opts: {
    identity: Identity;
    transport: Transport;
    clock: Clock;
    timeoutMs?: number;
    freshness?: FreshnessPolicy;
    onTraffic?: (t: Traffic) => void;
    bodyCodecFor?: (to: string) => BodyCodec | undefined;
    replayGuard?: ReplayGuard;
}): Endpoint;
```

### Parameters

**`opts` (required)**

`{ identity: Identity; transport: Transport; clock: Clock; timeoutMs?: number; freshness?: FreshnessPolicy; onTraffic?: (t: Traffic) => void; bodyCodecFor?: (to: string) => BodyCodec | undefined; replayGuard?: ReplayGuard; }`

**Fields of `opts`**

**`identity` (required)**

`Identity`

**`transport` (required)**

`Transport`

**`clock` (required)**

`Clock`

**`timeoutMs` (optional)**

`number | undefined`

**`freshness` (optional)**

`FreshnessPolicy | undefined`

**`onTraffic` (optional)**

`((t: Traffic) => void) | undefined`

**`bodyCodecFor` (optional)**

`((to: string) => BodyCodec | undefined) | undefined`

The body format to seal for `to`. Undefined (the default) means the standard JSON body. Every Endpoint reads both.

**`replayGuard` (optional)**

`ReplayGuard | undefined`

The duplicate-execution record. Defaults to one in memory; a PersistentReplayGuard keeps it across restarts.

### Returns

`Endpoint`

## Properties

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

## Methods

### `handle`

Signature:

```ts
handle<P, R>(spec: SpecPolicy, handler: Handler<P, R>): void;
```

#### Parameters

- **`spec` (required)**: `SpecPolicy`
- **`handler` (required)**: `Handler<P, R>`

#### Returns

`void`

### `seal`

Builds, signs and seals a request document for `to`.

Signature:

```ts
seal(to: string, spec: SpecPolicy, payload: unknown): Promise<Uint8Array>;
```

#### Parameters

- **`to` (required)**: `string`
- **`spec` (required)**: `SpecPolicy`
- **`payload` (required)**: `unknown`

#### Returns

`Promise<Uint8Array<ArrayBufferLike>>`

### `notify`

Sends a one-way message. No reply is expected.

Signature:

```ts
notify(to: string, spec: SpecPolicy, payload: unknown): Promise<Delivery>;
```

#### Parameters

- **`to` (required)**: `string`
- **`spec` (required)**: `SpecPolicy`
- **`payload` (required)**: `unknown`

#### Returns

`Promise<Delivery>`

### `request`

Sends a request and waits for its response. `opts.timeoutMs` overrides the endpoint's default for this call.

Signature:

```ts
request<P, R>(to: string, spec: SpecPolicy, payload: P, opts?: {
    timeoutMs?: number;
}): Promise<TrustTaskDocument<R>>;
```

#### Parameters

- **`to` (required)**: `string`
- **`spec` (required)**: `SpecPolicy`
- **`payload` (required)**: `P`
- **`opts` (optional)**: `{ timeoutMs?: number; } | undefined`

#### Returns

`Promise<TrustTaskDocument<R>>`

### `ingest`

Processes a sealed message that arrived some other way, e.g. collected from a relay.

Signature:

```ts
ingest(wire: Uint8Array): Promise<void>;
```

#### Parameters

- **`wire` (required)**: `Uint8Array<ArrayBufferLike>`

#### Returns

`Promise<void>`

### `close`

Signature:

```ts
close(): void;
```

No parameters.

#### Returns

`void`

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

---

This is the Markdown version of https://toip.tools/toolkit/trust-core/api/Endpoint/. An index of the documentation for AI assistants is at https://toip.tools/llms.txt.
