Overview
Privy is Grid’s default provider in a multi-provider authentication system
that includes Turnkey, Passkey, and optional external signers. To learn more
about the multi-provider authentication system, see how Grid
Accounts work.
Implementation Process
1
Initiate Account Creation
Call POST /accounts to start the account creation process
2
Generate HPKE Keypair
Create client-side HPKE keys using P-256 curve while waiting for OTP
3
Verify OTP
Complete account creation via POST /accounts/verify with HPKE public key
4
Receive Encrypted Authorization Key
Grid returns the authorization key encrypted with HPKE
5
Decrypt Authorization Key
Use your private key to decrypt the authorization key for transaction signing
6
Sign Transaction Payloads
Sign payloads using JSON canonicalization and ECDSA
Implementation Responsibilities
Client-side requirements:- Generate HPKE keypairs using P-256 curve and proper key formatting
- Decrypt authorization keys received from Privy using HPKE
- Sign transaction payloads with JSON canonicalization and ECDSA
- Creates Grid Accounts on Solana blockchain
- Generates authorization keys in Privy
- Returns encrypted authorization keys using your HPKE public key
- Submits signed transactions for payment intents, KYC operations, and other transactions
Complete Implementation Flow
The Grid SDK account creation and transaction signing flow consists of cryptographic key generation, 2 API calls, and transaction signing:1
POST /accounts - Initiate Account Creation
Use the account creation endpoint to initiate the account creation process.What Happens:
- Server creates account record in pending state
- Server generates and sends 6-digit OTP to email address
- Server returns account metadata with 15-minute expiration
2
Generate HPKE Keypair
While waiting for OTP: Create P-256 HPKE keys with SPKI/PKCS#8 DER
formatting and store private key securely. See the HPKE Keypair
Generation section below for detailed
implementation.
3
POST /accounts/verify - Verify Account OTP
Submit the OTP code to the verification endpoint to complete the account creation process.Request:Response:What Happens:
- Server verifies OTP code against email (15-minute window)
- Server creates Grid Account on Solana blockchain
- Privy generates authorization key in TEE using the HPKE keypair generated
- Privy encrypts authorization key using client’s HPKE public key
- Grid returns Grid Account address and encrypted authorization key
4
HPKE Decryption
Decrypt authorization key using ECDH + HKDF + ChaCha20-Poly1305 with your
private key. See the Decrypting Authorization
Keys section below for detailed
implementation.
5
Extract Auth Key
Remove “wallet-auth:” prefix from decrypted plaintext if present.
6
Get KMS Payload
When making API calls that require signing, endpoints will return a KMS
payload that you need to sign with the authorization key.
7
Canonicalize JSON
Recursively sort all object keys in KMS payload alphabetically. See the JSON
Canonicalization section for implementation details.
8
Extract Signing Key
Find [0x04, 0x20] pattern in auth key, extract 32 bytes following it. See the
Extract Signing Key section for implementation.
9
Sign Payload
ECDSA P-256 SHA-256 sign the canonicalized JSON string. See the Sign the
Payload section for implementation.
10
Submit Transaction
Send signed transaction to Grid API to the Transaction Submission endpoint with the signature.
Existing Account Authentication
For existing accounts, use POST /auth/verify with the same encrypted authorization key format.HPKE Keypair Generation
Before calling the verification endpoint, you must generate an HPKE keypair client-side using P-256 curve with proper DER formatting.Required Cryptographic Libraries
- Elliptic Curve Cryptography: P-256 (secp256r1) curve support
- HKDF: HMAC-based Key Derivation Function (RFC 5869)
- ChaCha20-Poly1305: AEAD encryption (RFC 8439)
- DER Encoding/Decoding: PKCS#8 and SPKI format support
- Base64 Encoding/Decoding: Standard base64 operations
Key Format Specifications
SPKI Public Key Structure (DER-encoded):Generate HPKE Keys
Using the Public Key in API Calls
Include your public key in thekms_provider_config when calling:
Account Verification: