Skip to main content

JavaScript SDK

The Inco JavaScript SDK provides client-side utilities for building privacy-preserving applications on Solana. It handles encryption and decryption workflows.

Installation

npm install @inco/solana-sdk

Features

Quick Start

import { encryptValue } from '@inco/solana-sdk/encryption';
import { decrypt } from '@inco/solana-sdk/attested-decrypt';
import { hexToBuffer } from '@inco/solana-sdk/utils';

// 1. Encrypt a value before sending to your program
const encrypted = await encryptValue(1000n);

// 2. Use in your program instruction
await program.methods
  .someOperation(hexToBuffer(encrypted), 0)
  .accounts({ authority: wallet.publicKey })
  .rpc();

// 3. Decrypt the result handle (requires wallet signature)
const result = await decrypt([handle], {
  address: wallet.publicKey,
  signMessage: wallet.signMessage,
});
console.log(result.plaintexts[0]);  // Decrypted value

Supported Value Types

TypeExampleNotes
number42, 100Integers only (no floats)
bigint1000000000nFor large values
booleantrue, falseEncrypted as 0 or 1

Attested Reveal vs Attested Decrypt

Both use the same decrypt() function. The difference is how you use the result:
FeatureAttested RevealAttested Decrypt
PurposeDisplay values in UIVerify values on-chain
What you useresult.plaintextsresult.ed25519Instructions + program IX
On-chain TXNoYes
Use caseShow user their balanceConditional logic based on decrypted values
const result = await decrypt([handle]);

// Attested Reveal: Just read the plaintext
console.log(result.plaintexts[0]);

// Attested Decrypt: Build on-chain verification transaction
const tx = new Transaction();
result.ed25519Instructions.forEach(ix => tx.add(ix));
tx.add(yourProgramInstruction);