Key generation
TypeScript
createUserKeypair() uses crypto.getRandomValues - browser-safe and works in Node 20+.
Use a fresh keypair per bet. Reusing a keypair across bets doesn’t break the cipher (nonces rotate), but it leaks that two positions belong to the same wallet to anyone watching EncryptedPosition.userPubkey on-chain.
The high-level placeBetAction generates a keypair automatically. Only call createUserKeypair manually if you want to pre-generate and show it to the user before the bet is submitted.
Shared secret derivation
TypeScript
Cipher construction
TypeScript
fetchMxePublicKey is cached per CypherClient instance. The MXE key rotates only during Arcium cluster upgrades.
Encrypting bet inputs
TypeScript
amount is the net stake after fees, not the gross bet. placeBetAction computes this automatically. If you are building instructions directly, compute fees via computeFees(grossAmount, { protocolFeeRateBps, lpFeeRateBps }).
Decrypt flow
To display an encrypted position’s stake and side, you need:- The user’s x25519 private key (from
saveSecret/loadSecret) - The current MXE public key
- The position’s nonce (on-chain as a
u128bigint)
TypeScript
Key persistence
UsesaveSecret / loadSecret to persist the private key in localStorage. The key format is cypher:pos:{marketBase58}:{betIndex}.
TypeScript
TypeScript