Signing requests
Owners sign requests to the Privy API to take actions on a resource, like a wallet or a policy. Follow the guide below to learn how to sign requests to the Privy API.
If the desired resource has a user owner, make sure to request the user key before signing requests with it.
Privy’s NodeJS SDK automatically handles signing requests with your provided key. You can specify with key to sign with using the updateAuthorizationKey
method of the Privy client.
Pass the base-64 encoded private key of your user key or authorization key into the Privy client’s updateAuthorizationKey
method:
The Privy client will now automatically sign requests to the Privy API with the provided key. You can simply use the privy.walletApi.ethereum.*
and privy.walletApi.solana.*
interfaces to take actions with wallets, and the SDK will automatically sign requests under the hood.
Privy’s NodeJS SDK automatically handles signing requests with your provided key. You can specify with key to sign with using the updateAuthorizationKey
method of the Privy client.
Pass the base-64 encoded private key of your user key or authorization key into the Privy client’s updateAuthorizationKey
method:
The Privy client will now automatically sign requests to the Privy API with the provided key. You can simply use the privy.walletApi.ethereum.*
and privy.walletApi.solana.*
interfaces to take actions with wallets, and the SDK will automatically sign requests under the hood.
Directly signing requests to the REST API is an advanced integration. If you are using a Privy SDK, you do not need to explicitly sign requests with authorization keys, as that is automatically handled.
To sign requests with your own signing logic, follow the steps below.
Build signature payload
Generate a JSON payload containing the following fields. All fields are required unless otherwise specified.
Field | Type | Description | |||
---|---|---|---|---|---|
version | 1 | Authorization signature version. Currently, 1 is the only version. | |||
method | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | HTTP method for the request. Signatures are not required on 'GET' requests. | |||
url | string | The full URL for the request. Should not include a trailing slash. | |||
body | JSON | JSON body for the request. | |||
headers | JSON | JSON object containing any Privy-specific headers, e.g. those that are prefixed with 'privy-' . This should not include any other headers, such as authentication headers, content-type , or trace headers. | |||
headers['privy-app-id'] | string | Privy app ID header (required). | |||
headers['privy-idempotency-key'] | string | Privy idempotency key header (optional). If the request does not contain an idempotency key, leave this field out of the payload. |
Format signature payload
Canonicalize the payload per RFC 8785 and serialize it to a string. This GitHub repository links to various libraries for JSON canonicalization in different languages.
You can easily format your request payload using the formatRequestForAuthorizationSignature
method from Privy’s NodeJS SDK, as shown below. If you do not plan to use Privy’s NodeJS SDK, see the Vanilla TypeScript
or non-TypeScript code examples below.
Sign signature payload
Sign the serialized JSON with ECDSA P-256 using the private key of your user key or authorization key and serialize it to a base64-encoded string.
You can easily sign the request payload using the generateAuthorizationSignature
method from Privy’s NodeJS SDK, as shown below. If you do not plan to use Privy’s NodeJS SDK, see the Vanilla TypeScript
or non-TypeScript code examples below.
See code examples of generating authorization signatures.
See code examples of generating authorization signatures.