Shielded SDK
The Mersennet JavaScript SDK (@prime-chain/sdk) ships a shielded surface for wallets and apps that connect to a chain with the ZK privacy hard fork activated. It covers client-side proving, note scanning, balance/position/order reconstruction, selective-disclosure reads, and migration.
All shielded crypto runs client-side. The node is never asked to decrypt your data; it only verifies proofs and gates authorized reads. See Privacy on Mersennet for the conceptual model.
Installโ
npm install @prime-chain/sdk
# or, from a checkout:
npm install /path/to/prime-chain/sdk
Modules at a glanceโ
| Area | Exports |
|---|---|
| Shielded client | ShieldedClient, ViewingKeyHelpers, createOwnerViewingMaterial, createMockNoteDecryptor |
| Note scanning | scanGrantedNotes, parseEncryptedNotePayload, parseShieldedNotePlaintext |
| Reconstruction | reconstructPortfolio, scanAndReconstructBalances, defaultNullifierDeriver |
| Positions & orders | reconstructPositions, reconstructOpenOrders |
| Client-side proving | NoirWasmProver |
| Migration | planMigration, confirmMigration, deriveMigrationNote, matchesMigrationNote, defaultNoteCommitment |
Client-side proving (NoirWasmProver)โ
Shielded transactions require a Noir proof generated in the wallet, so keys never leave the device. NoirWasmProver wraps a proving backend that the wallet injects (built on @noir-lang/noir_js + @aztec/bb.js).
import { NoirWasmProver } from '@prime-chain/sdk';
const prover = new NoirWasmProver({ backend }); // backend: NoirProvingBackend
const proof = await prover.prove('OrderPlace', inputs); // NoirCircuitName + NoirInputValue map
Relevant types: NoirCircuitName, NoirInputValue, NoirProvingBackend, NoirWasmProverOptions.
Note scanning & balance reconstructionโ
Rebuild private balances locally from encrypted notes (see Note scanning):
import { scanAndReconstructBalances } from '@prime-chain/sdk';
const portfolio = await scanAndReconstructBalances({
encryptedNotes, // from prime_viewNotes / prime_getShieldedNotes
viewingMaterial, // owner or grantee material
spentNullifiers, // from the chain's nullifier set
});
// portfolio.balances โ per-asset totals with spent notes excluded
Lower-level building blocks are also exported: scanGrantedNotes (decrypt authorized notes), defaultNullifierDeriver (derive nullifiers), and reconstructPortfolio (sum unspent notes).
Types: Note, EncryptedNote, GrantedDecryptedNote, GrantedNoteScanOptions, GrantedNoteScanResult, GrantedViewingMaterial, ShieldedBalance, ViewingKey, PortfolioNote, ReconstructedPortfolio, NullifierDeriver, BalanceReconstructionResult.
Positions & open ordersโ
import { reconstructPositions, reconstructOpenOrders } from '@prime-chain/sdk';
const positions = reconstructPositions({ orders, fills /* local records */ });
const openOrders = reconstructOpenOrders({ orders });
Types: OrderSide, OrderRecord, FillRecord, OpenOrder, ReconstructedPosition, ReconstructTradingOptions.
Selective disclosureโ
A grantee uses the same reconstruction primitives, but over the data a viewing grant authorizes. Fetch authorized notes/records via the grant-gated RPC methods (prime_viewNotes, prime_viewBalances, prime_viewPositions, prime_viewOrders) and run reconstructPortfolio / reconstructPositions / reconstructOpenOrders client-side.
Migrationโ
Drive transparent โ shielded migration with a plan-then-confirm flow (see Migration):
import { planMigration, confirmMigration } from '@prime-chain/sdk';
const plan = planMigration({ amount, asset, ownerPubKey });
// ... submit via prime_submitShield ...
const result = confirmMigration({ plan, onChainCommitment });
Types: MigrationNote, MigrationNoteParams, MigrationPlan, MigrationConfirmation, NoteCommitmentHasher.
See alsoโ
- Shielded JSON-RPC reference โ the methods these helpers call.
- JavaScript SDK โ the transparent (eth_* / prime_* / primeorders_*) surface.