Skip to main content

Turnkey Wallet Stamper

The @turnkey/wallet-stamper package provides a mechanism to stamp requests using a wallet public key and signature. This package supports both Solana and Ethereum wallets, allowing for seamless integration with various blockchain applications.

Installation

Before you start using the Turnkey Wallet Stamper, make sure to install the necessary packages in your project. This guide assumes you have a Node.js environment ready for development. Install the required packages using NPM, Yarn, or PNPM:

Usage

Prerequisites

Add Wallet Public Key as Authenticator

To use the wallet stamper, you must add the user’s wallet public key as an API key authenticator. This can be achieved either by creating a sub-organization activity or by generating a new API key and passing in the wallet’s public key. The API key stamper is necessary because we need to use the parent organization’s API key to add the authenticator initially. Once this is done, the wallet can stamp activity requests independently without needing the parent organization’s API private and public keys. Below are the steps to add a Solana public key as a wallet authenticator:

Using the Wallet Stamper

To use the @turnkey/wallet-stamper package, follow these steps:
  1. Choose Your Wallet Type: Decide whether you will use an EVM-based wallet (e.g., Ethereum) or a Solana-based wallet.
  2. Implement the Wallet Interface: Depending on your chosen blockchain, implement the wallet interface. This involves creating methods to sign messages and recover public keys.
Note: We’ve provided a default implementation for Ethereum wallets via the EthereumWallet class. For custom implementations, you may implement the WalletInterface yourself.
  1. Instantiate the WalletStamper: Create an instance of the WalletStamper using the wallet interface.
  2. Instantiate the TurnkeyClient: Create an instance of the TurnkeyClient with the WalletStamper instance.
  3. Stamp Requests: Now when making request using the TurnkeyClient, the wallet stamper will automatically stamp the request with the user’s wallet public key and signature.

Example: Signing with a Solana Wallet

In this example, we are using a local Solana wallet. For information on using an injected Solana wallet such as Solflare, please refer to the with-wallet-stamper example.

Example: Signing with an Ethereum Wallet

The main distinction between signing with an Ethereum Wallet and a Solana Wallet lies in how the public key is obtained. For Solana, the public key can be directly derived from the wallet. In contrast, with Ethereum, the secp256k1 public key isn’t directly accessible. Instead, you need to first obtain a signature from the user and then recover the public key from that signature.

Contributing

Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.

License

The @turnkey/wallet-stamper package is licensed under the MIT License.

Documents

Modules