# contentAddressedStore

> **contentAddressedStore**(`options`): [`ContentAddressedStore`](/reference/knotkit/cas/interfaces/contentaddressedstore/)

Defined in: [packages/cas/src/content-addressed-store.ts:115](https://github.com/jkomyno/knotkit/blob/ef04dc6fd5182dca281abddf3e1dcb13118c15a4/packages/cas/src/content-addressed-store.ts#L115)

Create a store that names each artifact by the hash of its framed bytes.

Content addressing gives three properties a plain blob key cannot. Writing the same artifact twice stores one copy, because identical bytes produce one address. Reading an address cannot return different content later without failing, because the bytes are re-hashed before decoding. And an address is portable across processes and machines that share the hash function, which is why the hash is injected rather than chosen here.

A hash collision — two artifacts, one address — is detected rather than served: `add` compares the stored bytes with the ones it was about to write, and reports `ADDRESS_COLLISION` instead of returning an address whose content is the other artifact. That check costs one read on the duplicate path, which is the price of not depending on the hash being collision-free.

## Parameters

### options

[`ContentAddressedStoreOptions`](/reference/knotkit/cas/interfaces/contentaddressedstoreoptions/)

The backend, the hash, and the artifact family’s magic.

## Returns

[`ContentAddressedStore`](/reference/knotkit/cas/interfaces/contentaddressedstore/)

A store whose every failure carries a code from `CAS_ERROR_CODES`.

## Throws

With `INVALID_ARTIFACT` when `options.magic` is not four bytes, since no artifact of this family could ever be valid.
