# ContentAddressedStore

Defined in: [packages/cas/src/artifact.ts:54](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/cas/src/artifact.ts#L54)

A store that names artifacts by the hash of their framing bytes.

## Properties

### addressOf

> `readonly` **addressOf**: (`artifact`) => `string`

Defined in: [packages/cas/src/artifact.ts:62](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/cas/src/artifact.ts#L62)

Address the artifact would receive, without writing it. O(bytes); pure.

#### Parameters

##### artifact

[`Artifact`](/reference/knotkit/cas/interfaces/artifact/)

#### Returns

`string`

#### Throws

With `INVALID_ARTIFACT` when the artifact cannot be framed, `INVALID_HASH` when the hash does not return an address-shaped string, or `HASH_FAILURE` when the hash throws.

***

### add

> `readonly` **add**: (`artifact`) => `Promise`<`string`>

Defined in: [packages/cas/src/artifact.ts:73](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/cas/src/artifact.ts#L73)

Frame the artifact, then store it under its address unless the same bytes are already there. Returns the address. O(bytes).

#### Parameters

##### artifact

[`Artifact`](/reference/knotkit/cas/interfaces/artifact/)

#### Returns

`Promise`<`string`>

#### Throws

As [addressOf](/reference/knotkit/cas/interfaces/contentaddressedstore/#addressof), plus `BACKEND_FAILURE` when the backend throws.

#### Throws

With `ADDRESS_COLLISION` when the address is present but holds different bytes, which means the injected hash mapped two artifacts to one address.

***

### has

> `readonly` **has**: (`address`) => `Promise`<`boolean`>

Defined in: [packages/cas/src/artifact.ts:80](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/cas/src/artifact.ts#L80)

Whether `address` holds an artifact. O(1) expected, plus one validation.

#### Parameters

##### address

`string`

#### Returns

`Promise`<`boolean`>

#### Throws

With `INVALID_ADDRESS` when the address is not a safe storage key, or `BACKEND_FAILURE` when the backend throws.

***

### get

> `readonly` **get**: (`address`) => `Promise`<[`WireEnvelope`](/reference/knotkit/wire/interfaces/wireenvelope/) | `undefined`>

Defined in: [packages/cas/src/artifact.ts:95](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/cas/src/artifact.ts#L95)

Read and verify the artifact stored under `address`, or `undefined` when the address is absent. O(bytes).

The bytes are re-hashed before decoding, so a backend that returned the wrong content, or a hash that stopped being deterministic, fails as `ADDRESS_MISMATCH` rather than as a payload that happens to decode.

#### Parameters

##### address

`string`

#### Returns

`Promise`<[`WireEnvelope`](/reference/knotkit/wire/interfaces/wireenvelope/) | `undefined`>

#### Throws

With `INVALID_ADDRESS` when the address is not a safe storage key, or `BACKEND_FAILURE` when the backend throws.

#### Throws

With `ADDRESS_MISMATCH` when the stored bytes do not hash to their address, or with any `knotkit/wire` failure the envelope raises under this store’s magic.
