pctestupgrade2 1.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/.github/workflows/npm-publish.yml +55 -0
  2. package/README.md +31 -0
  3. package/__tests__/e2e.test.ts +56 -0
  4. package/__tests__/e2espl.test.ts +73 -0
  5. package/__tests__/encryption.test.ts +1635 -0
  6. package/circuit2/transaction2.wasm +0 -0
  7. package/circuit2/transaction2.zkey +0 -0
  8. package/dist/config.d.ts +9 -0
  9. package/dist/config.js +12 -0
  10. package/dist/deposit.d.ts +19 -0
  11. package/dist/deposit.js +396 -0
  12. package/dist/depositSPL.d.ts +21 -0
  13. package/dist/depositSPL.js +452 -0
  14. package/dist/exportUtils.d.ts +10 -0
  15. package/dist/exportUtils.js +10 -0
  16. package/dist/getUtxos.d.ts +29 -0
  17. package/dist/getUtxos.js +294 -0
  18. package/dist/getUtxosSPL.d.ts +33 -0
  19. package/dist/getUtxosSPL.js +395 -0
  20. package/dist/index.d.ts +128 -0
  21. package/dist/index.js +305 -0
  22. package/dist/models/keypair.d.ts +26 -0
  23. package/dist/models/keypair.js +43 -0
  24. package/dist/models/utxo.d.ts +49 -0
  25. package/dist/models/utxo.js +85 -0
  26. package/dist/utils/address_lookup_table.d.ts +9 -0
  27. package/dist/utils/address_lookup_table.js +45 -0
  28. package/dist/utils/constants.d.ts +27 -0
  29. package/dist/utils/constants.js +56 -0
  30. package/dist/utils/encryption.d.ts +107 -0
  31. package/dist/utils/encryption.js +376 -0
  32. package/dist/utils/logger.d.ts +9 -0
  33. package/dist/utils/logger.js +35 -0
  34. package/dist/utils/merkle_tree.d.ts +92 -0
  35. package/dist/utils/merkle_tree.js +186 -0
  36. package/dist/utils/node-shim.d.ts +5 -0
  37. package/dist/utils/node-shim.js +5 -0
  38. package/dist/utils/prover.d.ts +36 -0
  39. package/dist/utils/prover.js +147 -0
  40. package/dist/utils/utils.d.ts +64 -0
  41. package/dist/utils/utils.js +165 -0
  42. package/dist/withdraw.d.ts +22 -0
  43. package/dist/withdraw.js +272 -0
  44. package/dist/withdrawSPL.d.ts +24 -0
  45. package/dist/withdrawSPL.js +308 -0
  46. package/package.json +51 -0
  47. package/src/config.ts +22 -0
  48. package/src/deposit.ts +493 -0
  49. package/src/depositSPL.ts +575 -0
  50. package/src/exportUtils.ts +12 -0
  51. package/src/getUtxos.ts +396 -0
  52. package/src/getUtxosSPL.ts +528 -0
  53. package/src/index.ts +356 -0
  54. package/src/models/keypair.ts +52 -0
  55. package/src/models/utxo.ts +106 -0
  56. package/src/utils/address_lookup_table.ts +78 -0
  57. package/src/utils/constants.ts +77 -0
  58. package/src/utils/encryption.ts +464 -0
  59. package/src/utils/logger.ts +42 -0
  60. package/src/utils/merkle_tree.ts +207 -0
  61. package/src/utils/node-shim.ts +6 -0
  62. package/src/utils/prover.ts +222 -0
  63. package/src/utils/utils.ts +222 -0
  64. package/src/withdraw.ts +335 -0
  65. package/src/withdrawSPL.ts +399 -0
  66. package/tsconfig.json +28 -0
@@ -0,0 +1,55 @@
1
+ name: Publish to npm when version changes
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ - master
8
+ paths:
9
+ - "package.json"
10
+
11
+ permissions:
12
+ id-token: write
13
+ contents: read
14
+
15
+ jobs:
16
+ publish:
17
+ runs-on: ubuntu-latest
18
+
19
+ steps:
20
+ - name: Checkout repository
21
+ uses: actions/checkout@v4
22
+
23
+ - name: Setup Node.js
24
+ uses: actions/setup-node@v4
25
+ with:
26
+ node-version: 24
27
+ registry-url: https://registry.npmjs.org/
28
+
29
+ - name: Get current package version
30
+ id: pkg
31
+ run: echo "version=$(node -p 'require(\"./package.json\").version')" >> $GITHUB_OUTPUT
32
+
33
+ - name: Check if version already exists on npm
34
+ id: check
35
+ run: |
36
+ PKG_NAME=$(node -p 'require("./package.json").name')
37
+ PUBLISHED=$(npm view $PKG_NAME versions --json | grep -o "\"${{ steps.pkg.outputs.version }}\"" || true)
38
+ if [ -n "$PUBLISHED" ]; then
39
+ echo "exists=true" >> $GITHUB_OUTPUT
40
+ echo "Version ${{ steps.pkg.outputs.version }} already exists on npm. Skipping publish."
41
+ else
42
+ echo "exists=false" >> $GITHUB_OUTPUT
43
+ fi
44
+
45
+ - name: Install dependencies
46
+ run: npm install
47
+
48
+ - name: Build source
49
+ run: npm run build || echo "No build script defined."
50
+
51
+ - name: Publish to npm
52
+ if: steps.check.outputs.exists == 'false'
53
+ run: |
54
+ echo "Publishing version ${{ steps.pkg.outputs.version }}..."
55
+ npm publish --access public
package/README.md ADDED
@@ -0,0 +1,31 @@
1
+ ## Privacy Cash SDK
2
+ This is the SDK for Privacy Cash. It has been audited by Zigtur (https://x.com/zigtur).
3
+
4
+ ### Disclaimer
5
+ This SDK powers Privacy Cash's frontend, assuming the single wallet use case. If you use it or published npm library from this repo, please fully test and beware of the inherent software risks or potential bugs.
6
+
7
+ 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.
8
+
9
+ ### Usage
10
+ 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.
11
+
12
+ Main APIs for this SDK are:
13
+ a. for SOL:
14
+ deposit(), withdraw(), getPrivateBalance()
15
+ b. for SPL (currently supporting USDC and USDT):
16
+ depositSPL(), withdrawSPL(), getPrivateBalanceSpl()
17
+
18
+ Check the example project under /example folder. The code should be fairly self-explanatory.
19
+
20
+ Use node version 24 or above.
21
+
22
+ ### Tests
23
+ 1. To run unit tests:
24
+ ```
25
+ npm test
26
+ ```
27
+ 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:
28
+ ```
29
+ npm run teste2e
30
+ ```
31
+ 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.
@@ -0,0 +1,56 @@
1
+ import { describe, it, expect, vi, beforeAll, beforeEach, type Mock } from "vitest";
2
+ import dotenv from 'dotenv';
3
+ import { PrivacyCash } from "../src";
4
+ import { LAMPORTS_PER_SOL } from "@solana/web3.js";
5
+ dotenv.config();
6
+ const TEST_AMOUNT = 0.01
7
+
8
+ describe('e2e test', async () => {
9
+ if (!process.env.PRIVATE_KEY) {
10
+ throw new Error('missing PRIVATE_KEY in .env')
11
+ }
12
+ if (!process.env.RPC_URL) {
13
+ throw new Error('missing RPC_URL in .env')
14
+ }
15
+
16
+ let client = new PrivacyCash({
17
+ RPC_url: process.env.RPC_URL,
18
+ owner: process.env.PRIVATE_KEY
19
+ })
20
+ let balance_original = await client.getPrivateBalance()
21
+
22
+ // deposit
23
+ await client.deposit({
24
+ lamports: TEST_AMOUNT * LAMPORTS_PER_SOL
25
+ })
26
+ let balance_after_deposit = await client.getPrivateBalance()
27
+
28
+ // withdraw wrong amount
29
+ it(`show throw error if withdraw amount less than 0.01`, async () => {
30
+ await expect(client.withdraw({
31
+ lamports: 0.005 * LAMPORTS_PER_SOL
32
+ })).rejects.toThrow()
33
+ })
34
+
35
+ // withdraw
36
+ let withdrawRes = await client.withdraw({
37
+ lamports: TEST_AMOUNT * LAMPORTS_PER_SOL
38
+ })
39
+ let balance_after_withdraw = await client.getPrivateBalance()
40
+
41
+ it('balance is a number', () => {
42
+ expect(balance_original.lamports).to.be.a('number')
43
+ })
44
+
45
+ it(`balance should be increased ${TEST_AMOUNT} sol`, () => {
46
+ expect(balance_after_deposit.lamports).equal(balance_after_withdraw.lamports + TEST_AMOUNT * LAMPORTS_PER_SOL)
47
+ })
48
+
49
+ it('should keep balance unchanged after depositing and withdrawing the same amount', () => {
50
+ expect(balance_original.lamports).equal(balance_after_withdraw.lamports)
51
+ })
52
+
53
+ it(`withdraw real amount plus fee should be ${TEST_AMOUNT * LAMPORTS_PER_SOL}`, () => {
54
+ expect(withdrawRes.amount_in_lamports + withdrawRes.fee_in_lamports).equal(TEST_AMOUNT * LAMPORTS_PER_SOL)
55
+ })
56
+ })
@@ -0,0 +1,73 @@
1
+ import { describe, it, expect, vi, beforeAll, beforeEach, type Mock } from "vitest";
2
+ import dotenv from 'dotenv';
3
+ import { PrivacyCash } from "../src";
4
+ import { getAccount, getAssociatedTokenAddress } from "@solana/spl-token";
5
+ import { FEE_RECIPIENT, USDC_MINT } from "../src/utils/constants";
6
+ import { Connection } from "@solana/web3.js";
7
+ dotenv.config();
8
+ const TEST_AMOUNT = 2
9
+ const units_per_token = 1_000_000
10
+ describe('e2e test', async () => {
11
+ if (!process.env.PRIVATE_KEY) {
12
+ throw new Error('missing PRIVATE_KEY in .env')
13
+ }
14
+ if (!process.env.RPC_URL) {
15
+ throw new Error('missing RPC_URL in .env')
16
+ }
17
+
18
+ const connection = new Connection(process.env.RPC_URL)
19
+ let fee_recipient_ata = await getAssociatedTokenAddress(USDC_MINT, FEE_RECIPIENT, true)
20
+ let feeRecipientAccount = await getAccount(connection, fee_recipient_ata)
21
+ let feeRecipientBalance_before = feeRecipientAccount.amount
22
+
23
+ let client = new PrivacyCash({
24
+ RPC_url: process.env.RPC_URL,
25
+ owner: process.env.PRIVATE_KEY
26
+ })
27
+ let balance_original = await client.getPrivateBalanceUSDC()
28
+
29
+ // deposit
30
+ await client.depositUSDC({
31
+ base_units: TEST_AMOUNT * units_per_token
32
+ })
33
+ let balance_after_deposit = await client.getPrivateBalanceUSDC()
34
+
35
+ // withdraw wrong amount
36
+ it(`show throw error if withdraw amount less than 1`, async () => {
37
+ await expect(client.withdrawUSDC({
38
+ base_units: 0.9 * units_per_token
39
+ })).rejects.toThrow()
40
+ })
41
+
42
+ // withdraw
43
+ let withdrawRes = await client.withdrawUSDC({
44
+ base_units: TEST_AMOUNT * units_per_token
45
+ })
46
+
47
+ await new Promise(r => setTimeout(r, 10_000));
48
+
49
+ feeRecipientAccount = await getAccount(connection, fee_recipient_ata)
50
+ let feeRecipientBalance_after = feeRecipientAccount.amount
51
+
52
+ let balance_after_withdraw = await client.getPrivateBalanceUSDC()
53
+
54
+ it('balance is a number', () => {
55
+ expect(balance_original.base_units).to.be.a('number')
56
+ })
57
+
58
+ it(`balance should be increased ${TEST_AMOUNT} USDC`, () => {
59
+ expect(balance_after_deposit.base_units).equal(balance_after_withdraw.base_units + TEST_AMOUNT * units_per_token)
60
+ })
61
+
62
+ it('should keep balance unchanged after depositing and withdrawing the same amount', () => {
63
+ expect(balance_original.base_units).equal(balance_after_withdraw.base_units)
64
+ })
65
+
66
+ it(`withdraw real amount plus fee should be ${TEST_AMOUNT * units_per_token}`, () => {
67
+ expect(withdrawRes.base_units + withdrawRes.fee_base_units).equal(TEST_AMOUNT * units_per_token)
68
+ })
69
+
70
+ it('fee recipient amount should be inceased by the withdraw fee', () => {
71
+ expect(withdrawRes.fee_base_units).equal(Number(feeRecipientBalance_after - feeRecipientBalance_before))
72
+ })
73
+ })