#api-key #p256 #stamp #turnkey #api-bindings

turnkey_api_key_stamper

Generate signatures over Turnkey API requests using a P-256 key

6 releases (breaking)

0.5.0 Oct 17, 2025
0.4.0 Sep 29, 2025
0.3.0 Aug 28, 2025
0.2.0 Aug 15, 2025
0.0.2 May 10, 2025

#1181 in Cryptography

Download history 1002/week @ 2025-08-25 1065/week @ 2025-09-01 1833/week @ 2025-09-08 1257/week @ 2025-09-15 977/week @ 2025-09-22 908/week @ 2025-09-29 572/week @ 2025-10-06 1206/week @ 2025-10-13 884/week @ 2025-10-20 1587/week @ 2025-10-27 4233/week @ 2025-11-03 4613/week @ 2025-11-10 4612/week @ 2025-11-17 4509/week @ 2025-11-24 6844/week @ 2025-12-01 6722/week @ 2025-12-08

22,896 downloads per month
Used in 10 crates (2 directly)

Apache-2.0

28KB
507 lines

turnkey_api_key_stamper

This crate contains structs and utilities to work with P-256 keys, which Turnkey uses as a primary way of authentication.

Creating a new P-256 API key

use turnkey_api_key_stamper::TurnkeyP256ApiKey;

let api_key = TurnkeyP256ApiKey::generate();

Loading API keys from env

If you keep API keys in env vars, load it with from_bytes or from_strings:

use std::env;
use turnkey_api_key_stamper::TurnkeyP256ApiKey;

// Assuming the env var is a hex-encoded string
let api_private_key = env::var("TURNKEY_API_PRIVATE_KEY").expect("cannot load TURNKEY_API_PRIVATE_KEY");
let api_key = TurnkeyP256ApiKey::from_strings(api_private_key, None).expect("loading API key failed");

If you want to store API keys in .env files, use dotenvy.

Load API keys from files

If you have generated API keys with Turnkey's command-line tool you can load them with:

use turnkey_api_key_stamper::TurnkeyP256ApiKey;

let api_key = TurnkeyP256ApiKey::from_files(
    "/home/user/.config/turnkey/keys/key.priv",
    Some("/home/user/.config/turnkey/keys/key.pub"
).expect("loading should succeed"));

Creating an API stamp to sign Turnkey requests

The API is straightforward, once you have a handle on an API key, call stamp:

use turnkey_api_key_stamper::{TurnkeyP256ApiKey, Stamp};

let api_key = TurnkeyP256ApiKey::generate();
let stamp = api_key.stamp("POST request body goes here".as_bytes());

The stamp produced is a base64-encoded value, ready to be used as a stamp header. See our documentation for more information.

Error handling

Errors are centralized in StamperError.

Dependencies

~5.5MB
~117K SLoC