### Running Whoami Example with Turnkey Rust SDK Source: https://github.com/tkhq/rust-sdk/blob/main/examples/README.md This command executes the `whoami` example program within the `turnkey_examples` package. The `whoami` example demonstrates how to authenticate to the Turnkey API and interact with its simplest endpoint, verifying the setup and credentials. ```Shell cargo run -p turnkey_examples --bin whoami ``` -------------------------------- ### Copying Environment File for Turnkey Rust Examples Source: https://github.com/tkhq/rust-sdk/blob/main/examples/README.md This command copies the example environment configuration file (`.env.example`) to a new file named `.env`. This `.env` file will then be populated with sensitive credentials required for the Turnkey API, such as organization ID, public key, and private key, as per the quickstart guide. ```Shell cp .env.example .env ``` -------------------------------- ### Running Wallet Management Example with Turnkey Rust SDK Source: https://github.com/tkhq/rust-sdk/blob/main/examples/README.md This command executes the `wallet` example program located in the `turnkey_examples` package. This example covers fundamental wallet management operations, including creation, signing transactions, exporting wallet data, and deleting wallets within the Turnkey API. ```Shell cargo run -p turnkey_examples --bin wallet ``` -------------------------------- ### Installing cargo-release for Rust Project Releases Source: https://github.com/tkhq/rust-sdk/blob/main/README.md This shell command installs `cargo-release`, a utility essential for managing releases of the Rust project. It's a one-time setup step required to utilize the project's defined release procedures. ```Shell cargo install cargo-release ``` -------------------------------- ### Running Sub-Organization Example with Turnkey Rust SDK Source: https://github.com/tkhq/rust-sdk/blob/main/examples/README.md This command executes the `sub_organization` example program from the `turnkey_examples` package. This example showcases the creation and deletion of sub-organizations within the Turnkey API, demonstrating organizational management capabilities. ```Shell cargo run -p turnkey_examples --bin sub_organization ``` -------------------------------- ### Creating an API Stamp for Turnkey Requests in Rust Source: https://github.com/tkhq/rust-sdk/blob/main/api_key_stamper/README.md This example demonstrates how to create an API stamp using an existing `TurnkeyP256ApiKey` instance. The `stamp` method takes the request body as input and produces a base64-encoded value, which is then ready to be used as a stamp header for signing Turnkey API requests. ```Rust use turnkey_api_key_stamper::TurnkeyP256ApiKey; let api_key = TurnkeyP256ApiKey::generate(); let stamp = api_key.stamp("POST request body goes here"); ``` -------------------------------- ### Encrypting Private Keys and Wallets for Import in Rust Source: https://github.com/tkhq/rust-sdk/blob/main/enclave_encrypt/README.md This example illustrates how to use the `ImportClient` to encrypt private keys or wallet mnemonic phrases before importing them into Turnkey enclaves. It shows the client initialization and provides methods for encrypting both private key bytes and wallet seed phrases, requiring the bundle, organization ID, and user ID for successful encryption. ```Rust use turnkey_enclave_encrypt::{ImportClient, QuorumPublicKey}; let mut client = ImportClient::new(&QuorumPublicKey::production_signer()); // Encrypt private keys let encrypted_key = client.encrypt_private_key_with_bundle( "", "", "", "" ).expect("encryption should succeed"); // Encrypt wallet seed phrase let encrypted_wallet = client.encrypt_wallet_with_bundle( "", "", "", "" ).expect("encryption should succeed"); ``` -------------------------------- ### Loading P-256 API Key from Environment Variables in Rust Source: https://github.com/tkhq/rust-sdk/blob/main/api_key_stamper/README.md This example illustrates how to load a P-256 API key from an environment variable, assuming the private key is stored as a hex-encoded string. It uses `std::env::var` to retrieve the variable and `TurnkeyP256ApiKey::from_strings` to parse it into an API key object. For `.env` files, the `dotenvy` crate is recommended. ```Rust 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"); ``` -------------------------------- ### Decrypting Exported Wallets and Private Keys in Rust Source: https://github.com/tkhq/rust-sdk/blob/main/enclave_encrypt/README.md This snippet demonstrates how to use the `ExportClient` to decrypt key material exported from Turnkey enclaves. It shows the initialization of the client with a production signer and provides examples for decrypting a wallet mnemonic phrase (resulting in a string) and a private key (resulting in bytes), both requiring the bundle and organization ID. ```Rust use turnkey_enclave_encrypt::{ExportClient, QuorumPublicKey}; let mut client = ExportClient::new(&QuorumPublicKey::production_signer()); // Decrypt a wallet (result: string) let wallet_mnemonic_phrase = client.decrypt_wallet_mnemonic_phrase("", ""); // Decrypt a private key (result: bytes) let private_key = client.decrypt_private_key("", ""); ``` -------------------------------- ### Decrypting Authentication Bundles from Persisted Client IKM in Rust Source: https://github.com/tkhq/rust-sdk/blob/main/enclave_encrypt/README.md This example illustrates how to decrypt an authentication bundle using an `AuthenticationClient` initialized from previously persisted client key material (IKM) via `dangerous_from_bytes`. It highlights the importance of decoding the client IKM and the one-shot semantic for decryption, emphasizing that the same client IKM should not be reused for multiple bundles. ```Rust use turnkey_enclave_encrypt::{AuthenticationClient, QuorumPublicKey}; let client_ikm = hex::decode("...private bytes from client...").expect("cannot decode client secret bytes"); let bundle = ""; let decrypted = AuthenticationClient::dangerous_from_bytes(client_ikm) .decrypt(bundle) .expect("decryption should succeed"); ``` -------------------------------- ### Manually Syncing Turnkey Proto Files (Shell) Source: https://github.com/tkhq/rust-sdk/blob/main/proto/README.md This snippet provides a series of shell commands to manually synchronize Turnkey proto files from a local monorepo to the current `rust-sdk` repository. It assumes the monorepo is located one directory level up (`../mono`) relative to the `rust-sdk` root, and copies specific proto directories and a JSON file. ```Shell cp -r ../mono/proto/external proto cp -r ../mono/proto/immutable proto cp -r ../mono/proto/vendor proto cp -r ../mono/proto/services/coordinator/public proto/services/coordinator cp ../mono/proto/activities.json proto/activities.json ``` -------------------------------- ### Making a Signature Request with Turnkey Client in Rust Source: https://github.com/tkhq/rust-sdk/blob/main/client/README.md This snippet demonstrates how to initialize the `turnkey_client` with an API key and make a `sign_raw_payload` request. It shows how to specify the signing address, payload, encoding, and hash function for the signature intent. ```Rust use turnkey_client::generated::SignRawPayloadIntentV2; use turnkey_client::generated::immutable::common::v1::HashFunction; use turnkey_client::generated::immutable::common::v1::PayloadEncoding; // You can load your API key from a file or from env let api_key = turnkey_client::TurnkeyP256ApiKey::from_strings("", None).expect("api key creation failed"); // Create a new client: let client = turnkey_client::TurnkeyClient::builder().api_key(api_key).build().expect("client builder failed"); // Make a request (for example, a signature request) let request = client.sign_raw_payload( "your-turnkey-organization-id".to_string(), client.current_timestamp(), SignRawPayloadIntentV2 { sign_with: "0x123456".to_string(), // Turnkey address payload: "hello from TKHQ".to_string(), encoding: PayloadEncoding::TextUtf8, hash_function: HashFunction::Keccak256, // assuming ETH }, ); // You can then call `request.await?` to get the signature result ``` -------------------------------- ### Configuring Reqwest Builder for Turnkey Client in Rust Source: https://github.com/tkhq/rust-sdk/blob/main/client/README.md This snippet illustrates how to access and configure the underlying `reqwest` builder used by the `turnkey_client`. It shows how to enable verbose connection logging, providing more control over the HTTP client's behavior. ```Rust let api_key = turnkey_client::TurnkeyP256ApiKey::generate(); let client = turnkey_client::TurnkeyClient::builder() .api_key(api_key) .with_reqwest_builder(|b| b.connection_verbose(true)); ``` -------------------------------- ### Running Tests for Turnkey Enclave Encrypt Crate Source: https://github.com/tkhq/rust-sdk/blob/main/enclave_encrypt/README.md This snippet provides the command to execute the test suite for the `turnkey_enclave_encrypt` Rust crate. Running this command verifies the functionality and correctness of the encryption and decryption primitives within the project. ```Shell cargo test ``` -------------------------------- ### Loading P-256 API Key from Files in Rust Source: https://github.com/tkhq/rust-sdk/blob/main/api_key_stamper/README.md This snippet shows how to load a P-256 API key from local files, which is useful if keys are generated by Turnkey's command-line tool. It utilizes `TurnkeyP256ApiKey::from_files` to load the private key from a specified path, with an optional public key path. ```Rust 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")); ``` -------------------------------- ### Initializing and Decrypting Authentication Bundles in Rust Source: https://github.com/tkhq/rust-sdk/blob/main/enclave_encrypt/README.md This snippet demonstrates how to initialize an `AuthenticationClient` to decrypt authentication bundles received from Turnkey secure enclaves. It shows the creation of a new client, retrieval of its target public key for activity parameters, and the decryption of a placeholder authentication bundle. The client is designed for one-shot use. ```Rust use turnkey_enclave_encrypt::{AuthenticationClient, QuorumPublicKey}; let mut client = AuthenticationClient::new(); let target_public_key = client.target_public_key(); // can be used in auth activity params let bundle = ""; let decrypted = client.decrypt(bundle).expect("decryption should succeed"); ``` -------------------------------- ### Requesting AWS Nitro Enclave Attestation Document using Turnkey CLI (Shell) Source: https://github.com/tkhq/rust-sdk/blob/main/proofs/README.md This shell snippet demonstrates how to request a fresh attestation document from a Turnkey enclave using the `turnkey` CLI. It requires specifying the API host, path, and a JSON body containing the organization ID and enclave type. The command outputs a base64-encoded attestation document. ```sh turnkey request --host api.turnkey.com --path /public/v1/query/get_attestation --body '{ "organizationId": "", "enclaveType": "signer" }' --organization ``` -------------------------------- ### Parsing and Verifying AWS Nitro Enclave Attestation in Rust Source: https://github.com/tkhq/rust-sdk/blob/main/proofs/README.md This Rust snippet illustrates how to parse and verify an AWS Nitro Enclave attestation document using the `parse_and_verify_aws_nitro_attestation` function from the `turnkey_proofs` crate. It then demonstrates extracting and displaying PCR values, user data, and the public key from the resulting `AttestationDoc`. ```rust use hex; use turnkey_proofs::parse_and_verify_aws_nitro_attestation; let attestation_document = "".to_string(); let attestation = parse_and_verify_aws_nitro_attestation(attestation_document) .expect("cannot parse and verify attestation document"); // Display PCR values println!("PCR0: {}", hex::encode(attestation.pcrs.get(&0).unwrap())); println!("PCR1: {}", hex::encode(attestation.pcrs.get(&1).unwrap())); println!("PCR2: {}", hex::encode(attestation.pcrs.get(&2).unwrap())); println!("PCR3: {}", hex::encode(attestation.pcrs.get(&3).unwrap())); // Display user data and public key fields println!("user_data: {}", hex::encode(attestation.user_data.unwrap())); println!( "public_key: {}", hex::encode(attestation.public_key.unwrap()) ); ``` -------------------------------- ### Generating a New P-256 API Key in Rust Source: https://github.com/tkhq/rust-sdk/blob/main/api_key_stamper/README.md This snippet demonstrates how to generate a new P-256 API key using the `TurnkeyP256ApiKey::generate()` method. This creates a fresh key pair that can be used for authentication with Turnkey services. ```Rust use turnkey_api_key_stamper::TurnkeyP256ApiKey; let api_key = TurnkeyP256ApiKey::generate(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.