## Privacy Cash SDK This is the SDK for Privacy Cash. It has been audited by Zigtur (https://x.com/zigtur). ### Disclaimer This SDK powers Privacy Cash's frontend, assuming the single wallet use case. It is NOT supposed to support hardware wallet. If you use it or published npm library from this repo, please fully test and beware of the inherent software risks or potential bugs. Our team is not responsible for any losses. THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ### Usage This SDK provides APIs for developers to interact with Privacy Cash relayers easily. Developers can easily deposit/withdraw/query balances in Privacy Cash solana program. Main APIs for this SDK are: a. for SOL: deposit(), withdraw(), getPrivateBalance() b. for SPL (currently supporting USDC and USDT): depositSPL(), withdrawSPL(), getPrivateBalanceSpl() For backend integration: Check the example project under /example folder. The code should be fairly self-explanatory. For SDK referral attribution, pass the database-assigned partner id when withdrawing, for example `privacyCash.withdraw({ lamports: 10000000, referralId: 'partner_id' })`. The same `referralId` option is available on `withdrawUSDC` and `withdrawSPL`. Invalid or inactive ids are rejected before the withdrawal is submitted. The old `referrer` wallet-address option does not enroll a withdrawal in this program. When a referral id is supplied, check `referralRecorded` in the result; a false value means the withdrawal succeeded but the referral entry needs reconciliation using `tx`. For frontend integration: Check the example project above, but also refer to: https://gist.github.com/SocialfiPanda/c63786b5dd156e59847e9a4afca31a77 Temporary emergency behavior: when a relayer response is not accepted as a successful transaction and its `error` string contains `risk` or equals `Service rejected` (case-insensitive, ignoring surrounding whitespace), the SDK throws that error immediately instead of polling chain status for 30 seconds. This applies to SOL/SPL deposits and withdrawals. Other errors keep their existing handling. This text matching is temporary and should later be replaced with structured error codes. Common Issues: Next.js project needs to update the postinstall build scripts: ``` "scripts": { "postinstall": "cp node_modules/@lightprotocol/hasher.rs/dist/hasher_wasm_simd_bg.wasm node_modules/@lightprotocol/hasher.rs/dist/browser-fat/es/ && cp node_modules/@lightprotocol/hasher.rs/dist/light_wasm_hasher_bg.wasm node_modules/@lightprotocol/hasher.rs/dist/browser-fat/es/", },..} ``` Use node version 24 or above. ### Warnings Privacy Cash SDK requires consistent signature generation, otherwise the deposited tokens might be lost forever since the encrypted UTXO can't be decrypted. For frontend, please make sure deriveEncryptionKeyFromSignature() generates the same result for the same params passed in, and for backend, please make sure deriveEncryptionKeyFromWallet() generates the same result. Most wallets returns the same result, but some non major wallets might generate different result. ### Tests 1. To run unit tests: ``` npm test ``` 2. To run e2e test (on Mainnet), you need to put your private key (PRIVATE_KEY) inside .env file under the project root directory, and then run: ``` npm run teste2e ``` Running e2e tests will cost some transaction fees on your wallet, so don't put too much SOL into your wallet. Maybe put 0.1 SOL, and the tests might cost 0.02 SOL.