pvc-fork 1.0.0
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 +55 -0
- package/__tests__/e2e.test.ts +56 -0
- package/__tests__/e2espl.test.ts +73 -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 +9 -0
- package/dist/config.js +12 -0
- package/dist/deposit.d.ts +22 -0
- package/dist/deposit.js +405 -0
- package/dist/depositSPL.d.ts +24 -0
- package/dist/depositSPL.js +457 -0
- package/dist/exportUtils.d.ts +10 -0
- package/dist/exportUtils.js +10 -0
- package/dist/getUtxos.d.ts +29 -0
- package/dist/getUtxos.js +294 -0
- package/dist/getUtxosSPL.d.ts +33 -0
- package/dist/getUtxosSPL.js +401 -0
- package/dist/index.d.ts +138 -0
- package/dist/index.js +288 -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 +85 -0
- package/dist/utils/address_lookup_table.d.ts +9 -0
- package/dist/utils/address_lookup_table.js +44 -0
- package/dist/utils/constants.d.ts +27 -0
- package/dist/utils/constants.js +50 -0
- package/dist/utils/encryption.d.ts +107 -0
- package/dist/utils/encryption.js +376 -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 +36 -0
- package/dist/utils/prover.js +147 -0
- package/dist/utils/utils.d.ts +64 -0
- package/dist/utils/utils.js +165 -0
- package/dist/withdraw.d.ts +21 -0
- package/dist/withdraw.js +270 -0
- package/dist/withdrawSPL.d.ts +23 -0
- package/dist/withdrawSPL.js +306 -0
- package/package.json +51 -0
- package/src/config.ts +22 -0
- package/src/deposit.ts +508 -0
- package/src/depositSPL.ts +591 -0
- package/src/exportUtils.ts +12 -0
- package/src/getUtxos.ts +396 -0
- package/src/getUtxosSPL.ts +533 -0
- package/src/index.ts +338 -0
- package/src/models/keypair.ts +52 -0
- package/src/models/utxo.ts +106 -0
- package/src/utils/address_lookup_table.ts +77 -0
- package/src/utils/constants.ts +72 -0
- package/src/utils/encryption.ts +464 -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 +222 -0
- package/src/utils/utils.ts +222 -0
- package/src/withdraw.ts +332 -0
- package/src/withdrawSPL.ts +397 -0
- 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
|
|
@@ -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
|
+
})
|