@alder/sdk Reference
Complete TypeScript API reference for @alder/sdk v0.3.0 including AlderSdk methods, Solana RPC commitment verification, 2D RS codeword verification, and X25519 viewing keys.
@alder/sdk (version 0.3.0) is the TypeScript client library for Alder. It runs in both modern browsers and Node.js 20+ using standard Web Crypto (globalThis.crypto.subtle, including X25519, HKDF, SHA-256, and AES-GCM) with zero native dependencies.
Package Exports
import {
AlderSdk,
createAlderSdk,
encryptPayload,
decryptPayload,
generateAuditorKeypair,
wrapViewingKey,
unwrapViewingKey,
sha256Bytes,
sha256Hex,
randomBytes,
encodeTcda,
decodeTcda,
verifyTcdaCodeword,
rsEncodeVector,
rsDecodeVector,
hashCell,
merkleRoot,
fetchOnChainBlobCommitmentRoot,
verifyMultiproof,
} from '@alder/sdk'createAlderSdk(baseUrl) and AlderSdk
const sdk = createAlderSdk('http://127.0.0.1:42102')AlderSdk exposes sdk.api (a typed AlderClient created via createClient(baseUrl) from @alder/contract) plus four high-level confidential DA methods.
sdk.putPrivateBlob(input)
Encrypts payload locally with AES-256-GCM binding alder:blob:v1:<blobId> as Additional Authenticated Data (AAD), encodes the ciphertext into a 2k x 2k GF(256) TCDA matrix (enforcing 2 <= k <= 16 and cell size <= 512 bytes), computes commitmentRoot, rowCommitments, and colCommitments, and calls POST /v1/blobs/anchor/build.
| Input Field | Type | Default | Description | |
|---|---|---|---|---|
publisher | string | required | Publisher Solana public key (base58) | |
payload | `Uint8Array \ | string` | required | Plaintext bytes or UTF-8 string (never leaves client) |
blobId | string | blob_<ms>_<8hex> | Unique blob ID (4..64 chars, [a-zA-Z0-9_-]) | |
k | number | 4 | Data matrix width (2..16; coded width n = 2 * k) | |
retentionDepth | number | 2 | TCDA retention depth (1..4) | |
policyId | string | 'private' | Disclosure policy string (1..64 chars) | |
expirySlots | number | 216000 | Slots until blob expiry (100..50000000) |
Returns `Promise<PutPrivateBlobResult>`:
| Field | Type | Description |
|---|---|---|
blobId | string | Final blob identifier |
commitmentRoot | string | 32-byte commitment root (64-char hex) |
contentKeyBase64 | string | Random 32-byte AES-256-GCM key (store locally) |
nonceBase64 | string | Random 12-byte AES-GCM IV |
matrix | TcdaMatrix | Full encoded n x n matrix and row/col commitments |
txBuild | TxBuildResponse | Unsigned v0 anchor_blob transaction payload and blobPda |
sdk.sampleAvailability(blobId, opts)
Generates distinct random (row, col) coordinates client-side, fetches cells from POST /v1/blobs/:id/sample, and verifies Merkle inclusion against an on-chain BlobRecord.commitment_root (either supplied explicitly via expectedCommitmentRoot or fetched directly from Solana RPC via rpcUrl + blobPda). Never defaults to the server's returned root.
| Parameter | Type | Default | Description |
|---|---|---|---|
blobId | string | required | Target blob ID |
opts.matrixSizeN | number | required | Coded matrix width n = 2k (4..32) |
opts.sampleCount | number | 16 | Number of distinct cells to sample (1..64) |
opts.expectedCommitmentRoot | string? | none | Explicit 32-byte on-chain root (hex) if already read from Solana |
opts.rpcUrl | string? | none | Solana RPC URL (required with blobPda when expectedCommitmentRoot is omitted) |
opts.blobPda | string? | none | On-chain BlobRecord PDA address (base58) |
Returns `Promise<SampleAvailabilityResult>`:
sample:SampleBlobResponsefrom/v1/blobs/:id/sampleonChainCommitmentRoot:string(the verified on-chain 32-byte root)onChainSlot:number | undefined(RPC context slot when fetched viarpcUrl+blobPda)localVerification:MultiproofVerificationResult(valid,verifiedCells,failedCells,verifyTimeMs,confidencePct,reason?)
sdk.reconstructBlob(blobId, keyInput)
Fetches coded cells from GET /v1/blobs/:id/cells, filters out any cell whose hashCell(row, col, raw) fails, runs iterative row + column 2D Reed-Solomon decoding (decodeTcda), unwraps the X25519 viewing key if needed, and decrypts the ciphertext locally with blobId AAD.
keyInput Field | Type | Description |
|---|---|---|
contentKeyBase64 | string? | Owner 32-byte base64 content key (takes precedence if set) |
wrappedKeyBase64 | string? | Auditor 93-byte X25519 v2 wrapped viewing-key envelope (base64) |
auditorPrivateKeyBase64 | string? | Auditor X25519 PKCS8 private key (base64) |
scope | string? | Viewing scope string (defaults to 'compliance-read') |
Returns `Promise<ReconstructBlobResult>`: { blobId, commitmentRoot, plaintext, plaintextText, cellsUsed }.
sdk.grantViewingKey(params)
Asymmetrically wraps contentKeyBase64 to the auditor's X25519 public key using ephemeral X25519 ECDH + HKDF-SHA256 + AES-256-GCM and registers the public envelope via POST /v1/blobs/:id/viewing-keys.
| Param | Type | Default | Description |
|---|---|---|---|
blobId | string | required | Target blob ID |
issuer | string | required | Issuer Solana public key (base58) |
contentKeyBase64 | string | required | Local 32-byte AES-256-GCM content key |
auditorPubkey | string | required | Auditor Solana public key (base58) |
auditorX25519PubkeyBase64 | string | required | Auditor 32-byte raw X25519 public key (base64) |
scope | string | 'compliance-read' | Scoped label (1..64 chars) |
expiresAt | string? | none | Optional ISO-8601 UTC expiry timestamp |
authToken | string? | none | SIWS Bearer session token (Authorization: Bearer <token>) required outside localnet |
Returns `Promise<GrantViewingKeyResult>`: { envelope: ViewingKeyEnvelope, ephemeralPubkeyBase64: string }.
Standalone Crypto and X25519 Viewing-Key Functions
encryptPayload(plaintext: Uint8Array | string, blobId?: string): Promise<EncryptedBlobPayload>: Generates a 32-byte key and 12-byte IV and encrypts with AES-256-GCM (bindingalder:blob:v1:<blobId>as AAD whenblobIdis provided).decryptPayload(ciphertext: Uint8Array, contentKeyBase64: string, nonceBase64: string, blobId?: string): Promise<Uint8Array>: Decrypts and authenticates AES-256-GCM ciphertext.generateAuditorKeypair(): Promise<AuditorX25519Keypair>: Generates a Web Crypto X25519 keypair returning{ publicKeyBase64, privateKeyBase64 }.wrapViewingKey({ blobId, contentKeyBase64, auditorX25519PubkeyBase64, scope }): Produces a 93-byte v2 envelope ([version=2 (1B) | ephemeralX25519Pub (32B) | iv (12B) | ciphertext+tag (48B)]) and returns{ wrappedKeyBase64, ephemeralPubkeyBase64 }.unwrapViewingKey({ wrappedKeyBase64, auditorPrivateKeyBase64, blobId, scope }): Runs X25519 ECDH + HKDF-SHA256 (info = "alder:viewing-key:x25519:v2:<blobId>:<scope>") and returnscontentKeyBase64.sha256Bytes(parts)/sha256Hex(parts)/randomBytes(length): Web Crypto SHA-256 and CSPRNG helpers.
Standalone TCDA, RPC, and Merkle DAS Functions
encodeTcda(ciphertext: Uint8Array, k = 4): Promise<TcdaMatrix>: 2DGF(256)(0x11d) Reed-Solomon encoder (2 <= k <= 16, cell size<= 512bytes) returningk,n,cellSizeBytes,payloadSizeBytes,commitmentRoot,rowCommitments,colCommitments, andcells.decodeTcda(cells, k, n): Uint8Array: Iterative row + column 2D Reed-Solomon decoder (deduplicates coordinates; handles column-only recovery patterns) returning exact ciphertext bytes.verifyTcdaCodeword(cells, k, n): boolean: Verifies that alln * ncells form a valid 2D Reed-Solomon codeword overGF(256).rsEncodeVector(chunks, k, n)/rsDecodeVector(present, k): 1D systematicGF(256)Reed-Solomon vector codec.hashCell(row, col, data): Promise<string>: Domain-separatedSHA-256("alder:cell:v1:<row>:<col>:" || data).merkleRoot(leaves: string[]): Promise<{ root: string; layers: string[][] }>: Binary Merkle tree withSHA-256("alder:node:" || left || ":" || right).fetchOnChainBlobCommitmentRoot(rpcUrl: string, blobPda: string): Promise<{ commitmentRoot: string; slot: number }>: ReadsBlobRecord.commitment_root(bytes72..104) directly from Solana RPC viagetAccountInfo.verifyMultiproof(sample: SampleBlobResponse, expectedCommitmentRoot: string, expectedCoordinates?: { row: number; col: number }[]): Promise<MultiproofVerificationResult>: Requires an explicit 64-char hex on-chain root; rejects out-of-bounds coords, duplicate(row, col)replays, wrongmerkleIndexor Merkle depth, missing requested coords, bad cell hashes, bad Merkle paths, or mismatched transcript digests.
Next Steps
- See every HTTP and SSE endpoint wrapped by
sdk.apiin REST and SSE API. - Inspect the on-chain program accounts and instructions in `alder_da` Program Reference.