privacycash 1.0.6
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.
- package/.github/workflows/npm-publish.yml +67 -0
- package/README.md +22 -0
- package/__tests__/e2e.test.ts +52 -0
- package/__tests__/encryption.test.ts +1635 -0
- package/circuit2/transaction2.wasm +0 -0
- package/circuit2/transaction2.zkey +0 -0
- package/dist/config.d.ts +7 -0
- package/dist/config.js +16 -0
- package/dist/deposit.d.ts +18 -0
- package/dist/deposit.js +402 -0
- package/dist/exportUtils.d.ts +6 -0
- package/dist/exportUtils.js +6 -0
- package/dist/getUtxos.d.ts +27 -0
- package/dist/getUtxos.js +352 -0
- package/dist/index.d.ts +61 -0
- package/dist/index.js +169 -0
- package/dist/models/keypair.d.ts +26 -0
- package/dist/models/keypair.js +43 -0
- package/dist/models/utxo.d.ts +49 -0
- package/dist/models/utxo.js +76 -0
- package/dist/utils/address_lookup_table.d.ts +8 -0
- package/dist/utils/address_lookup_table.js +21 -0
- package/dist/utils/constants.d.ts +14 -0
- package/dist/utils/constants.js +15 -0
- package/dist/utils/encryption.d.ts +107 -0
- package/dist/utils/encryption.js +374 -0
- package/dist/utils/logger.d.ts +9 -0
- package/dist/utils/logger.js +35 -0
- package/dist/utils/merkle_tree.d.ts +92 -0
- package/dist/utils/merkle_tree.js +186 -0
- package/dist/utils/node-shim.d.ts +5 -0
- package/dist/utils/node-shim.js +5 -0
- package/dist/utils/prover.d.ts +33 -0
- package/dist/utils/prover.js +123 -0
- package/dist/utils/utils.d.ts +67 -0
- package/dist/utils/utils.js +151 -0
- package/dist/withdraw.d.ts +21 -0
- package/dist/withdraw.js +270 -0
- package/package.json +48 -0
- package/src/config.ts +28 -0
- package/src/deposit.ts +496 -0
- package/src/exportUtils.ts +6 -0
- package/src/getUtxos.ts +466 -0
- package/src/index.ts +191 -0
- package/src/models/keypair.ts +52 -0
- package/src/models/utxo.ts +97 -0
- package/src/utils/address_lookup_table.ts +29 -0
- package/src/utils/constants.ts +26 -0
- package/src/utils/encryption.ts +461 -0
- package/src/utils/logger.ts +42 -0
- package/src/utils/merkle_tree.ts +207 -0
- package/src/utils/node-shim.ts +6 -0
- package/src/utils/prover.ts +189 -0
- package/src/utils/utils.ts +213 -0
- package/src/withdraw.ts +334 -0
- package/tsconfig.json +28 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
|
|
2
|
+
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
|
|
3
|
+
|
|
4
|
+
name: Publish to npm
|
|
5
|
+
|
|
6
|
+
on:
|
|
7
|
+
push:
|
|
8
|
+
branches:
|
|
9
|
+
- main
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
publish:
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
steps:
|
|
15
|
+
- name: Checkout repository
|
|
16
|
+
uses: actions/checkout@v3
|
|
17
|
+
with:
|
|
18
|
+
fetch-depth: 0
|
|
19
|
+
|
|
20
|
+
- name: Setup Node.js
|
|
21
|
+
uses: actions/setup-node@v4
|
|
22
|
+
with:
|
|
23
|
+
node-version: "20"
|
|
24
|
+
registry-url: "https://registry.npmjs.org"
|
|
25
|
+
cache: "npm"
|
|
26
|
+
|
|
27
|
+
# Get previous version from the last commit in origin/main
|
|
28
|
+
- name: Get previous package.json version
|
|
29
|
+
run: |
|
|
30
|
+
PREV=$(git show origin/main~1:package.json | jq -r .version)
|
|
31
|
+
echo "Previous version: $PREV"
|
|
32
|
+
echo "PREV_VERSION=$PREV" >> $GITHUB_ENV
|
|
33
|
+
|
|
34
|
+
# Get current version from package.json
|
|
35
|
+
- name: Get current package.json version
|
|
36
|
+
run: |
|
|
37
|
+
CURR=$(jq -r .version package.json)
|
|
38
|
+
echo "CURR_VERSION=$CURR"
|
|
39
|
+
echo "CURR_VERSION=$CURR" >> $GITHUB_ENV
|
|
40
|
+
|
|
41
|
+
# Compare previous and current versions
|
|
42
|
+
- name: Compare versions
|
|
43
|
+
run: |
|
|
44
|
+
if [ "$PREV_VERSION" = "$CURR_VERSION" ]; then
|
|
45
|
+
echo "Version unchanged, skip publish"
|
|
46
|
+
echo "SHOULD_PUBLISH=false" >> $GITHUB_ENV
|
|
47
|
+
else
|
|
48
|
+
echo "Version changed, will publish"
|
|
49
|
+
echo "SHOULD_PUBLISH=true" >> $GITHUB_ENV
|
|
50
|
+
fi
|
|
51
|
+
|
|
52
|
+
# Install dependencies only if publish is needed
|
|
53
|
+
- name: Install dependencies
|
|
54
|
+
if: env.SHOULD_PUBLISH == 'true'
|
|
55
|
+
run: npm ci
|
|
56
|
+
|
|
57
|
+
# Run build script before publishing
|
|
58
|
+
- name: Build project
|
|
59
|
+
if: env.SHOULD_PUBLISH == 'true'
|
|
60
|
+
run: npm run build
|
|
61
|
+
|
|
62
|
+
# Publish to npm
|
|
63
|
+
- name: Publish to npm
|
|
64
|
+
if: env.SHOULD_PUBLISH == 'true'
|
|
65
|
+
run: npm publish
|
|
66
|
+
env:
|
|
67
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/README.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
## Privacy Cash SDK
|
|
2
|
+
This is the SDK for Privacy Cash. It has been audited by Zigtur (https://x.com/zigtur).
|
|
3
|
+
|
|
4
|
+
### Usage
|
|
5
|
+
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.
|
|
6
|
+
|
|
7
|
+
Main APIs for this SDK are: deposit(), withdraw(), getPrivateBalance().
|
|
8
|
+
|
|
9
|
+
Check the example project under /example folder. The code should be fairly self-explanatory.
|
|
10
|
+
|
|
11
|
+
Use node version 24 or above.
|
|
12
|
+
|
|
13
|
+
### Tests
|
|
14
|
+
1. To run unit tests:
|
|
15
|
+
```
|
|
16
|
+
npm test
|
|
17
|
+
```
|
|
18
|
+
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:
|
|
19
|
+
```
|
|
20
|
+
npm run teste2e
|
|
21
|
+
```
|
|
22
|
+
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,52 @@
|
|
|
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
|
+
let client = new PrivacyCash({
|
|
13
|
+
RPC_url: 'https://rorie-6cdtt5-fast-mainnet.helius-rpc.com',
|
|
14
|
+
owner: process.env.PRIVATE_KEY
|
|
15
|
+
})
|
|
16
|
+
let balance_original = await client.getPrivateBalance()
|
|
17
|
+
|
|
18
|
+
// deposit
|
|
19
|
+
await client.deposit({
|
|
20
|
+
lamports: TEST_AMOUNT * LAMPORTS_PER_SOL
|
|
21
|
+
})
|
|
22
|
+
let balance_after_deposit = await client.getPrivateBalance()
|
|
23
|
+
|
|
24
|
+
// withdraw wrong amount
|
|
25
|
+
it(`show throw error if withdraw amount less than 0.01`, async () => {
|
|
26
|
+
await expect(client.withdraw({
|
|
27
|
+
lamports: 0.005 * LAMPORTS_PER_SOL
|
|
28
|
+
})).rejects.toThrow()
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
// withdraw
|
|
32
|
+
let withdrawRes = await client.withdraw({
|
|
33
|
+
lamports: TEST_AMOUNT * LAMPORTS_PER_SOL
|
|
34
|
+
})
|
|
35
|
+
let balance_after_withdraw = await client.getPrivateBalance()
|
|
36
|
+
|
|
37
|
+
it('balance is a number', () => {
|
|
38
|
+
expect(balance_original.lamports).to.be.a('number')
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it(`balance should be increased ${TEST_AMOUNT} sol`, () => {
|
|
42
|
+
expect(balance_after_deposit.lamports).equal(balance_after_withdraw.lamports + TEST_AMOUNT * LAMPORTS_PER_SOL)
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it('should keep balance unchanged after depositing and withdrawing the same amount', () => {
|
|
46
|
+
expect(balance_original.lamports).equal(balance_after_withdraw.lamports)
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
it(`withdraw real amount plus fee should be ${TEST_AMOUNT * LAMPORTS_PER_SOL}`, () => {
|
|
50
|
+
expect(withdrawRes.amount_in_lamports + withdrawRes.fee_in_lamports).equal(TEST_AMOUNT * LAMPORTS_PER_SOL)
|
|
51
|
+
})
|
|
52
|
+
})
|