> ## Documentation Index
> Fetch the complete documentation index at: https://docs.turnkey.com/llms.txt
> Use this file to discover all available pages before exploring further.

# ApiKeyStamper

## Introduction

The [`@turnkey/api-key-stamper`](https://www.npmjs.com/package/@turnkey/api-key-stamper) package simplifies the process of using your public/private API keys and passkeys to stamp and approve activity requests for Turnkey's API. This stamping mechanism is central to the API's security, ensuring that each request is authenticated and authorized. For an in-depth understanding of API keys see [this section](/faq#why-do-you-require-a-public--private-key-pair-to-access-turnkey-api).

## Installing

To get started install the [`@turnkey/api-key-stamper`](https://www.npmjs.com/package/@turnkey/api-key-stamper) client.

<CodeGroup>
  ```bash npm theme={"system"}
  pnpm i @turnkey/api-key-stamper
  ```

  ```bash pnpm theme={"system"}
  pnpm i @turnkey/api-key-stamper
  ```

  ```bash yarn theme={"system"}
  yarn add @turnkey/api-key-stamper
  ```
</CodeGroup>

## Initializing

The `ApiKeyStamper` class implements the `TStamper` interface used by the [TurnkeyClient](/sdks/advanced/turnkey-client) in the `@turnkey/http` module. It encapsulates the logic necessary to sign activity requests and generates the appropriate HTTP headers for authentication. To get started with an `ApiKeyStamper`, you can initialize it using its constructor:

### `constructor(config: TApiKeyStamperConfig): TStamper`

<ParamField body="config" type="TApiKeyStamperConfig" required>
  An object containing configuration settings for the stamper.
</ParamField>

<ParamField body="apiPrivateKey" type="string" required>
  Your Turnkey API private key.
</ParamField>

<ParamField body="apiPublicKey" type="string" required>
  Your Turnkey API public key.
</ParamField>

### Types

#### `TApiKeyStamperConfig`

```js theme={"system"}
type TApiKeyStamperConfig = {
  apiPublicKey: string;
  apiPrivateKey: string;
};
```

#### `TStamper`

```js theme={"system"}
interface TStamper {
  stamp: (input: string) => Promise<TStamp>;
};
```

#### Example

The example below shows how to initialize and use the `ApiKeyStamper` with the `TurnkeyClient` to make a request to Turnkey's [`/public/v1/query/whoami`](/api-reference/sessions/who-am-i) endpoint:

```js theme={"system"}
import { TurnkeyClient } from "@turnkey/http";
import { ApiKeyStamper } from "@turnkey/api-key-stamper";

// Following best practices, define parameters in your .env file
const baseUrl = process.env.TURNKEY_BASE_URL || "https://api.turnkey.com";
const apiPublicKey = process.env.TURNKEY_API_PUBLIC_KEY;
const apiPrivateKey = process.env.TURNKEY_API_PRIVATE_KEY;

// Initialize the API key stamper
const stamper = new ApiKeyStamper({ apiPublicKey, apiPrivateKey });

// Initialize the Turnkey client
const tk = new TurnkeyClient({ baseUrl }, stamper);

// Now you can make authenticated requests using the APIKeyStamper
const whoami = await tk.getWhoami({
  organizationId: "<Your Org ID>",
});
```

## Methods

### `stamp: (input: string) => Promise<TStamp>`

Creates a digital stamp which includes the public key, signature scheme, and a signature.

#### Parameters

<ParamField body="payload" type="string" required>
  The payload that needs to be stamped.
</ParamField>

#### Types

##### `TStamp`

```js theme={"system"}
type TStamp = {
  stampHeaderName: string;
  stampHeaderValue: string;
};
```
