Skip to main content

Privacy API

REST endpoints for privacy module operations.

Get Shielded Pool Stats

GET /rp1/privacy/v1/pool_stats

Response

{
"total_shielded": "1000000000000",
"total_transactions": "50000",
"last_update": "2024-01-15T10:30:00Z"
}

Get Commitment

GET /rp1/privacy/v1/commitment/{hash}

Response

{
"commitment": {
"hash": "abc123...",
"merkle_index": "1234",
"created_at": "2024-01-15T10:30:00Z"
}
}

Check Nullifier

GET /rp1/privacy/v1/nullifier/{hash}

Returns whether a nullifier has been spent.

Response

{
"spent": true,
"spent_at_height": "12345"
}

Get Merkle Root

GET /rp1/privacy/v1/merkle_root

Response

{
"root": "abc123...",
"tree_size": "50000",
"height": "12345"
}

Get Viewing Key Grants

GET /rp1/privacy/v1/viewing_keys/{owner}

Response

{
"grants": [
{
"grantee": "rp1auditor...",
"grant_type": "full",
"granted_at": "2024-01-01T00:00:00Z",
"expires_at": "2025-01-01T00:00:00Z"
}
]
}

Privacy Module Parameters

GET /rp1/privacy/v1/params

Response

{
"params": {
"ring_size": "11",
"min_shield_amount": "1000",
"max_viewing_key_duration": "31536000s",
"proof_verification_gas": "200000"
}
}

Transaction Messages

Shield Tokens

{
"@type": "/rp1.privacy.v1.MsgShield",
"sender": "rp1sender...",
"amount": {
"denom": "urp1",
"amount": "1000000"
}
}

Private Transfer

{
"@type": "/rp1.privacy.v1.MsgPrivateTransfer",
"sender": "rp1sender...",
"recipient": "rp1recipient...",
"proof": "base64_encoded_proof",
"encrypted_amount": "base64_encrypted",
"ring_members": ["member1...", "member2...", ...]
}

Unshield Tokens

{
"@type": "/rp1.privacy.v1.MsgUnshield",
"sender": "rp1sender...",
"amount": {
"denom": "urp1",
"amount": "500000"
},
"proof": "base64_encoded_proof",
"nullifier": "abc123..."
}

Create Viewing Key

{
"@type": "/rp1.privacy.v1.MsgCreateViewingKey",
"grantor": "rp1owner...",
"grantee": "rp1auditor...",
"grant_type": "full",
"expires_at": "2025-12-31T23:59:59Z"
}

Revoke Viewing Key

{
"@type": "/rp1.privacy.v1.MsgRevokeViewingKey",
"grantor": "rp1owner...",
"grantee": "rp1auditor..."
}

Events

EventAttributes
privacy_shieldsender, amount, commitment
privacy_transfernullifier, new_commitment
privacy_unshieldrecipient, amount, nullifier
viewing_key_createdgrantor, grantee, type
viewing_key_revokedgrantor, grantee

TypeScript Example

import { PrivacyModule } from '@rp1/sdk';

const privacy = new PrivacyModule(client);

// Get pool stats
const stats = await privacy.getPoolStats();
console.log(`Total Shielded: ${stats.totalShielded}`);

// Check if nullifier is spent
const isSpent = await privacy.isNullifierSpent('abc123...');

// Get viewing key grants
const grants = await privacy.getViewingKeyGrants('rp1owner...');

// Shield tokens
const shieldTx = await privacy.shield(wallet, '1000000', 'urp1');

// Create viewing key
const grantTx = await privacy.createViewingKey(wallet, {
grantee: 'rp1auditor...',
type: 'full',
expiresAt: '2025-12-31T23:59:59Z',
});

Next Steps