Skip to main content
Passkeys provide a secure way to authorize actions on Privy wallets. This guide shows how to integrate your existing passkey implementation as an authorization mechanism for Privy wallets, combining modern authentication with powerful onchain actions.

Overview

Authorization keys provide a way to ensure that actions taken by your app’s wallets can only be authorized by an explicit user request. When you specify an owner of a resource, all requests to update that resource must be signed with this key. This security measure verifies that each request comes from your authorized passkey owner and helps prevent unauthorized operations.

Setting up passkeys

If you need a passkey implementation set up for your application, we recommend using the simpleWebAuthn SDKs, which provides simple passkey registration and authentication flows.
If you have not already done so, install the dependencies necessary for a simple passkey integration. sh npm install @simplewebauthn/server @simplewebauthn/browser

Server-side registration endpoints

First, create the registration begin endpoint:
Next, create the registration verify endpoint:

Client-side registration

Creating and registering wallets with passkey authorization

Follow these steps to create a wallet and register it with a user’s passkey for authorization.
  1. Retrieve the user’s passkey P-256 PEM-formatted public key and send it to your backend.
After registering a passkey, you’ll need to convert the WebAuthn public key from COSE format to PEM format that Privy expects:
Use this function after successful passkey registration to get the PEM-formatted public key that Privy requires.
  1. From your backend, call the Privy API to create a wallet with that P-256 public key as the owner. You can do this via the Privy SDK (below) or by hitting the Privy API directly.
  1. Associate the returned wallet ID with the user on your backend for use in future requests.

Sending transactions with passkey authorization

Below are the steps necessary to create a transaction request, have the user sign it with their passkey using WebAuthn, and submit the signed request to Privy:
  1. Create and format the transaction request payload
Create your transaction and format it into the required request payload structure:
  1. Sign the payload with the user’s passkey
Use the WebAuthn authentication flow to sign the formatted payload:
  1. Format the authorization signature
Create the specially formatted authorization signature that Privy expects:
  1. Send the transaction to Privy
Send the transaction request with the WebAuthn authorization signature using direct API calls:
That’s it! Your users can now securely authorize transactions on wallets using their passkeys with WebAuthn standard authentication. 🎉

Signing messages with passkey authorization

Similar to transactions, you can also sign messages using passkey authorization. Below are the steps to create a message signing request and submit it with passkey authorization:
When signing messages, it’s important to use utf-8 encoding for the message and include chain_type: 'ethereum' in the request payload. These parameters ensure proper signature generation and verification.
  1. Create and format the message signing request payload
Create your message and format it into the required request payload structure:
  1. Sign the payload with the user’s passkey
Use the WebAuthn authentication flow to sign the formatted payload:
  1. Format the authorization signature
Create the specially formatted authorization signature that Privy expects:
  1. Send the message signing request to Privy
Send the message signing request with the WebAuthn authorization signature using direct API calls: