Using user owners
Once your application has successfully configured authentication settings, users can update and take actions with resources they own per the following flow.
Request a user key for a user
Make a request to the Privy API with the user’s access token to request a user key. If the token is valid per your configured authentication settings, Privy will return a time-bound user key that can be used to sign requests.
Sign the request with the user key
Given the returned user key, sign the request to update or take actions with a resource the user owns.
Pass the signature in request headers
Lastly, pass the signature from the user key
in a privy-authorization-signature
header for the request. Privy will verify the signature and
execute the request only if the signature is valid.
Follow the guide below to learn how to request and use user keys from the Privy API.
1. Request a user key for a user
To request a user key with the NodeJS SDK, use the generateUserSigner
method of the Privy client.
As a parameter to the method, pass an object containing the following.
The user’s JWT, to authenticate the user.
If your app is using your own authentication provider, the user’s JWT should verify against the JWKS.json endpoint you registered in the Dashboard.
If your app is using Privy as your authentication provider, the user’s JWT should be the access token issued by Privy.
Under the hood, the generateUserSigner
method handles the encryption and decryption of the
user’s authorization key returned by the Privy API. This means your application does not need to
handle the encryption of the user’s authorization key.
2. Update the Privy client to use the user’s keypair
Once you’ve generated an authorization key for the user, update the Privy client to use the authorization key via the updateAuthorizationKey
method. This will configure the Privy client to sign requests with the provided key.
As a parameter to this method, pass the authorization key returned by the generateUserSigner
method as a string
.
3. Execute requests with the user’s authorization key
Once the Privy client has been updated with a specific user’s authorization key, the client will automatically sign requests made by the privy.walletApi.ethereum.*
and privy.walletApi.solana.*
methods. You do not need to take any extra steps to sign requests.
1. Request a user key for a user
To request a user key with the NodeJS SDK, use the generateUserSigner
method of the Privy client.
As a parameter to the method, pass an object containing the following.
The user’s JWT, to authenticate the user.
If your app is using your own authentication provider, the user’s JWT should verify against the JWKS.json endpoint you registered in the Dashboard.
If your app is using Privy as your authentication provider, the user’s JWT should be the access token issued by Privy.
Under the hood, the generateUserSigner
method handles the encryption and decryption of the
user’s authorization key returned by the Privy API. This means your application does not need to
handle the encryption of the user’s authorization key.
2. Update the Privy client to use the user’s keypair
Once you’ve generated an authorization key for the user, update the Privy client to use the authorization key via the updateAuthorizationKey
method. This will configure the Privy client to sign requests with the provided key.
As a parameter to this method, pass the authorization key returned by the generateUserSigner
method as a string
.
3. Execute requests with the user’s authorization key
Once the Privy client has been updated with a specific user’s authorization key, the client will automatically sign requests made by the privy.walletApi.ethereum.*
and privy.walletApi.solana.*
methods. You do not need to take any extra steps to sign requests.
Directly managing user authorization keys via the REST API is an advanced integration. If you are using a Privy SDK, you do not need to directly manage the user’s authorization key or manually generate authorization signatures.
For security, Privy encrypts user authorization keys under a public key you provide to ensure that only your app can decrypt them. If you are just getting started with your integration, you can test the flow without encryption by following the Without encryption sections of the guide below.
In production environments, we strongly recommend requesting user authorization keys with encryption as a security best practice.
1. Generate an ECH P-256 keypair
To begin, create an ECH P-256 public-private keypair to encrypt and decrypt your user’s authorization key. Privy will encrypt the authorization under the public key for your keypair, and your server can decrypt the authorization key using the keypair’s corresponding private key.
When interacting with the Privy API, your ECH P-256 public-private keypair must be in the SPKI format.
As an example, you can create an ECH P-256 keypair like so.
Show code examples of creating ECH P-256 keypairs
Show code examples of creating ECH P-256 keypairs
To begin, create an ECH P-256 public-private keypair to encrypt and decrypt your user’s authorization key. Privy will encrypt the authorization under the public key for your keypair, and your server can decrypt the authorization key using the keypair’s corresponding private key.
When interacting with the Privy API, your ECH P-256 public-private keypair must be in the SPKI format.
As an example, you can create an ECH P-256 keypair like so.
Show code examples of creating ECH P-256 keypairs
Show code examples of creating ECH P-256 keypairs
If you are requesting user authorization keys without encryption, you can skip this step.
2. Request a user’s authorization key
If you are just getting started with your integration and skipped step 1, you should omit the
encryption_type
and recipient_public_key
parameters of the request body blank.
Once you’ve created your P-256 keypair, use the user’s access token and your generated public key to request an authorization key for the user.
Make a request to
In the request body, pass the following parameters.
Show request body
Show request body
The user’s JWT, to be used to authenticate the user.
If your app is using your own authentication provider, the user’s JWT should verify against the JWKS.json endpoint you registered in the Dashboard.
If your app is using Privy as your authentication provider, the user’s JWT should be the access token issued by Privy.
The encryption type for the authentication response. Currently only supports HPKE. Omit this field if you are requesting the authorization key unencrypted.
The public key of your ECDH keypair, in base64-encoded, SPKI-format, whose private key will be able to decrypt the session key. This keypair must be generated securely and the private key must be kept confidential. The public key sent should be in DER or PEM format. It is recommended to use DER format.
The user’s JWT, to be used to authenticate the user.
If your app is using your own authentication provider, the user’s JWT should verify against the JWKS.json endpoint you registered in the Dashboard.
If your app is using Privy as your authentication provider, the user’s JWT should be the access token issued by Privy.
The encryption type for the authentication response. Currently only supports HPKE. Omit this field if you are requesting the authorization key unencrypted.
The public key of your ECDH keypair, in base64-encoded, SPKI-format, whose private key will be able to decrypt the session key. This keypair must be generated securely and the private key must be kept confidential. The public key sent should be in DER or PEM format. It is recommended to use DER format.
The user’s JWT, to be used to authenticate the user.
If your app is using your own authentication provider, the user’s JWT should verify against the JWKS.json endpoint you registered in the Dashboard.
If your app is using Privy as your authentication provider, the user’s JWT should be the access token issued by Privy.
In the response, Privy will return the following. Make sure to save the encrypted_authorization_key.encapsulated_key
and encrypted._authorization_key.ciphertext
fields to use later.
Show response body
Show response body
The encrypted authorization key, once decrypted, can be used to sign transactions on the wallet, acting as a temporary AuthorizationPrivateKey.
Once decrypted, you will need to generate an authorization signature and pass it as a header under privy-authorization-signature
.
The expiration time of the authorization key in seconds since the epoch.
The wallets that the signer has access to.
The encrypted authorization key, once decrypted, can be used to sign transactions on the wallet, acting as a temporary AuthorizationPrivateKey.
Once decrypted, you will need to generate an authorization signature and pass it as a header under privy-authorization-signature
.
The expiration time of the authorization key in seconds since the epoch.
The wallets that the signer has access to.
The raw authorization key. Using this key, you will need to generate an authorization signature and pass it as a header under privy-authorization-signature
.
The expiration time of the authorization key in seconds since the epoch.
The wallets that the signer has access to.
See an example request and successful response below.
Show example request and response
Show example request and response
An example request for an authorization key with encryption might look like the following:
A successful sample response will look like the following:
An example request for an authorization key with encryption might look like the following:
A successful sample response will look like the following:
An example request for an authorization key without encryption might look like the following:
A successful sample response will look like the following:
3. Decrypt the authorization key
Finally, decrypt the authorization key using the returned encrypted_authorization_key.encapsulated_key
and encrypted_authorization_key.ciphertext
fields, as well as the private key you generated in step 1.
Show code examples for decrypting the authorization key
Show code examples for decrypting the authorization key
Finally, decrypt the authorization key using the returned encrypted_authorization_key.encapsulated_key
and encrypted_authorization_key.ciphertext
fields, as well as the private key you generated in step 1.
Show code examples for decrypting the authorization key
Show code examples for decrypting the authorization key
If you did not provide a public key with which Privy encrypted the authorization key, you can skip this step. You can simply used the returned user authorization_key
to sign requests.
4. Sign requests with the authorization key
Now that you have successfully retrieved the authorization key for your user, continue to this guide to learn how to sign requests to the Privy API.