alderconfidential DA on Solana
Reference

@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

ts
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

ts
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 FieldTypeDefaultDescription
publisherstringrequiredPublisher Solana public key (base58)
payload`Uint8Array \string`requiredPlaintext bytes or UTF-8 string (never leaves client)
blobIdstringblob_<ms>_<8hex>Unique blob ID (4..64 chars, [a-zA-Z0-9_-])
knumber4Data matrix width (2..16; coded width n = 2 * k)
retentionDepthnumber2TCDA retention depth (1..4)
policyIdstring'private'Disclosure policy string (1..64 chars)
expirySlotsnumber216000Slots until blob expiry (100..50000000)

Returns `Promise<PutPrivateBlobResult>`:

FieldTypeDescription
blobIdstringFinal blob identifier
commitmentRootstring32-byte commitment root (64-char hex)
contentKeyBase64stringRandom 32-byte AES-256-GCM key (store locally)
nonceBase64stringRandom 12-byte AES-GCM IV
matrixTcdaMatrixFull encoded n x n matrix and row/col commitments
txBuildTxBuildResponseUnsigned 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.

ParameterTypeDefaultDescription
blobIdstringrequiredTarget blob ID
opts.matrixSizeNnumberrequiredCoded matrix width n = 2k (4..32)
opts.sampleCountnumber16Number of distinct cells to sample (1..64)
opts.expectedCommitmentRootstring?noneExplicit 32-byte on-chain root (hex) if already read from Solana
opts.rpcUrlstring?noneSolana RPC URL (required with blobPda when expectedCommitmentRoot is omitted)
opts.blobPdastring?noneOn-chain BlobRecord PDA address (base58)

Returns `Promise<SampleAvailabilityResult>`:

  • sample: SampleBlobResponse from /v1/blobs/:id/sample
  • onChainCommitmentRoot: string (the verified on-chain 32-byte root)
  • onChainSlot: number | undefined (RPC context slot when fetched via rpcUrl + 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 FieldTypeDescription
contentKeyBase64string?Owner 32-byte base64 content key (takes precedence if set)
wrappedKeyBase64string?Auditor 93-byte X25519 v2 wrapped viewing-key envelope (base64)
auditorPrivateKeyBase64string?Auditor X25519 PKCS8 private key (base64)
scopestring?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.

ParamTypeDefaultDescription
blobIdstringrequiredTarget blob ID
issuerstringrequiredIssuer Solana public key (base58)
contentKeyBase64stringrequiredLocal 32-byte AES-256-GCM content key
auditorPubkeystringrequiredAuditor Solana public key (base58)
auditorX25519PubkeyBase64stringrequiredAuditor 32-byte raw X25519 public key (base64)
scopestring'compliance-read'Scoped label (1..64 chars)
expiresAtstring?noneOptional ISO-8601 UTC expiry timestamp
authTokenstring?noneSIWS 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 (binding alder:blob:v1:<blobId> as AAD when blobId is 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 returns contentKeyBase64.
  • 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>: 2D GF(256) (0x11d) Reed-Solomon encoder (2 <= k <= 16, cell size <= 512 bytes) returning k, n, cellSizeBytes, payloadSizeBytes, commitmentRoot, rowCommitments, colCommitments, and cells.
  • 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 all n * n cells form a valid 2D Reed-Solomon codeword over GF(256).
  • rsEncodeVector(chunks, k, n) / rsDecodeVector(present, k): 1D systematic GF(256) Reed-Solomon vector codec.
  • hashCell(row, col, data): Promise<string>: Domain-separated SHA-256("alder:cell:v1:<row>:<col>:" || data).
  • merkleRoot(leaves: string[]): Promise<{ root: string; layers: string[][] }>: Binary Merkle tree with SHA-256("alder:node:" || left || ":" || right).
  • fetchOnChainBlobCommitmentRoot(rpcUrl: string, blobPda: string): Promise<{ commitmentRoot: string; slot: number }>: Reads BlobRecord.commitment_root (bytes 72..104) directly from Solana RPC via getAccountInfo.
  • 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, wrong merkleIndex or Merkle depth, missing requested coords, bad cell hashes, bad Merkle paths, or mismatched transcript digests.

Next Steps