# StateBridge

Defined in: [packages/wire/src/state-bridge.ts:20](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/wire/src/state-bridge.ts#L20)

The bridge a package’s factories and serializers share to reach state that has no place in the public interface, without widening that interface and without `instanceof`-style dispatch.

## Type Parameters

### State

`State`

## Properties

### attach

> `readonly` **attach**: (`structure`, `state`) => `void`

Defined in: [packages/wire/src/state-bridge.ts:29](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/wire/src/state-bridge.ts#L29)

Attach `state` to `structure` as a non-enumerable own property, so `Object.keys`, `for...in`, `JSON.stringify`, and spread copies never observe it.

#### Parameters

##### structure

`object`

##### state

`State`

#### Returns

`void`

#### Throws

With `INVALID_ARGUMENT` when `structure` is not an extensible object, or when a state is already attached.

***

### stateOf

> `readonly` **stateOf**: (`structure`) => `State` | `undefined`

Defined in: [packages/wire/src/state-bridge.ts:42](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/wire/src/state-bridge.ts#L42)

Return the state attached to `structure`, or `undefined` when it carries none. Structural: a structure produced by another copy of the package is readable here, and a foreign object is simply `undefined`, which the caller maps to its own `FOREIGN_STRUCTURE` code.

Reads the own data property only. An inherited descriptor is not state, and an accessor is neither read nor invoked, so an object cannot run caller-supplied code through a getter. A `Proxy` can still observe the descriptor read itself; the bridge narrows what an ordinary object can do, not what a hostile proxy can intercept.

#### Parameters

##### structure

`unknown`

#### Returns

`State` | `undefined`
