Selective Disclosure
Generate an auditor X25519 keypair, issue an asymmetrically wrapped viewing key, and reconstruct and decrypt a blob locally.
Selective disclosure lets a blob owner grant read access to a specific auditor or compliance counterparty using ephemeral X25519 ECDH + HKDF-SHA256 + AES-256-GCM wrapping. The raw content key never leaves the owner's device, and the public viewing-key envelope can only be unwrapped by the auditor's X25519 private key.
1. Generate an Auditor X25519 Keypair
The auditor generates an X25519 keypair locally via generateAuditorKeypair(), shares publicKeyBase64 (32-byte raw X25519 public key) with the publisher, and keeps privateKeyBase64 (PKCS8) secret:
import { generateAuditorKeypair } from '@alder/sdk'
const auditorKeys = await generateAuditorKeypair()
console.log('Share with publisher:', auditorKeys.publicKeyBase64)
// Keep auditorKeys.privateKeyBase64 strictly on the auditor's device2. Anchor a Blob with a Disclosure Policy
When calling putPrivateBlob, set policyId to privacy-rings or auditor-scoped (or a custom policy identifier up to 64 characters). The policy ID is hashed into BlobRecord.policy_id_hash on chain:
import { createAlderSdk } from '@alder/sdk'
const sdk = createAlderSdk('http://127.0.0.1:42102')
const published = await sdk.putPrivateBlob({
publisher: ownerPubkeyBase58,
payload: JSON.stringify({
ring: 'institutional-desk-01',
settlementId: 'settle-2026-11-22-09',
amountSol: 250,
}),
k: 4,
retentionDepth: 2,
policyId: 'privacy-rings',
})Complete wallet signing and attestation so the blob reaches Available status.
3. Issue an X25519 Viewing Key (grantViewingKey)
Call sdk.grantViewingKey with the blob's local contentKeyBase64, the auditor's Solana address (auditorPubkey) and X25519 public key (auditorX25519PubkeyBase64), a scope string (1..64 characters, default 'compliance-read'), and an optional UTC expiresAt timestamp:
const granted = await sdk.grantViewingKey({
blobId: published.blobId,
issuer: ownerPubkeyBase58,
contentKeyBase64: published.contentKeyBase64,
auditorPubkey: auditorSolanaPubkeyBase58,
auditorX25519PubkeyBase64: auditorKeys.publicKeyBase64,
scope: 'compliance-read',
expiresAt: '2026-12-31T23:59:59.000Z',
authToken: siwsSessionToken, // Required outside localnet (Authorization: Bearer <token>)
})
console.log('Envelope ID:', granted.envelope.id)
console.log('Wrapped key (93-byte X25519 v2 envelope):', granted.envelope.wrappedKeyBase64)
console.log('Ephemeral X25519 pubkey:', granted.ephemeralPubkeyBase64)grantViewingKey wraps contentKeyBase64 locally and posts only the 93-byte encrypted envelope to POST /v1/blobs/:id/viewing-keys.
/app/vault.4. List Viewing-Key Envelopes for a Blob
Auditors or compliance tooling can fetch registered envelopes for a blob via GET /v1/blobs/:id/viewing-keys:
const list = await sdk.api.listViewingKeys(published.blobId)
for (const env of list.items) {
console.log(env.id, env.auditorPubkey, env.scope, env.expiresAt)
}5. Reconstruct and Decrypt as an Auditor
The auditor fetches coded cells from GET /v1/blobs/:id/cells, runs 2D Reed-Solomon decoding, unwraps the 93-byte X25519 v2 envelope using auditorPrivateKeyBase64, and decrypts the ciphertext with sdk.reconstructBlob:
const auditorSdk = createAlderSdk('http://127.0.0.1:42102')
const recovered = await auditorSdk.reconstructBlob(published.blobId, {
wrappedKeyBase64: granted.envelope.wrappedKeyBase64,
auditorPrivateKeyBase64: auditorKeys.privateKeyBase64,
scope: 'compliance-read',
})
console.log('Cells used for RS decode:', recovered.cellsUsed)
console.log('Decrypted plaintext:', recovered.plaintextText)6. Offline Key Wrapping Without the API
If your application exchanges viewing-key envelopes directly without storing them on the Alder API, call wrapViewingKey and unwrapViewingKey directly:
import { wrapViewingKey, unwrapViewingKey } from '@alder/sdk'
const { wrappedKeyBase64 } = await wrapViewingKey({
blobId,
contentKeyBase64,
auditorX25519PubkeyBase64: auditorKeys.publicKeyBase64,
scope: 'ring-audit',
})
const unwrappedContentKey = await unwrapViewingKey({
wrappedKeyBase64,
auditorPrivateKeyBase64: auditorKeys.privateKeyBase64,
blobId,
scope: 'ring-audit',
})Next Steps
- Review the X25519 + HKDF-SHA256 + AES-256-GCM envelope layout in Viewing Keys and Privacy Rings.
- Inspect the full
ViewingKeyEnvelopeschema in REST and SSE API.