@veilo/sdk-core 0.1.17 → 0.4.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/README.md +1296 -272
- package/SHIELD_INTEGRATION.md +143 -0
- package/config.d.ts +2 -0
- package/config.js +4 -0
- package/dist/cjs/client.d.ts +407 -0
- package/dist/cjs/client.js +951 -0
- package/dist/cjs/compactNote.d.ts +107 -0
- package/dist/cjs/compactNote.js +167 -0
- package/dist/cjs/config.d.ts +82 -0
- package/dist/cjs/config.js +57 -0
- package/dist/cjs/events.d.ts +77 -0
- package/dist/cjs/events.js +167 -0
- package/dist/cjs/idl/privacy_pool.d.ts +5 -0
- package/dist/cjs/idl/privacy_pool.js +15218 -0
- package/dist/cjs/idl/privacy_pool.json +10313 -0
- package/dist/cjs/index.d.ts +16 -0
- package/dist/cjs/index.js +67 -0
- package/dist/cjs/merkle.d.ts +77 -0
- package/dist/cjs/merkle.js +156 -0
- package/dist/cjs/poseidon.d.ts +29 -0
- package/dist/cjs/poseidon.js +100 -0
- package/dist/cjs/program.d.ts +37 -0
- package/dist/cjs/program.js +61 -0
- package/dist/cjs/proof.d.ts +183 -0
- package/dist/cjs/proof.js +292 -0
- package/dist/cjs/prover.d.ts +54 -0
- package/dist/cjs/prover.js +112 -0
- package/dist/cjs/random.d.ts +16 -0
- package/dist/cjs/random.js +28 -0
- package/dist/cjs/relayer.d.ts +318 -0
- package/dist/cjs/relayer.js +257 -0
- package/dist/cjs/retry.d.ts +32 -0
- package/dist/cjs/retry.js +75 -0
- package/dist/cjs/shield/alt.d.ts +87 -0
- package/dist/cjs/shield/alt.js +194 -0
- package/dist/cjs/shield/computeBudget.d.ts +61 -0
- package/dist/cjs/shield/computeBudget.js +64 -0
- package/dist/cjs/shield/errors.d.ts +58 -0
- package/dist/cjs/shield/errors.js +121 -0
- package/dist/cjs/shield/finalize.d.ts +45 -0
- package/dist/cjs/shield/finalize.js +119 -0
- package/dist/cjs/shield/index.d.ts +35 -0
- package/dist/cjs/shield/index.js +68 -0
- package/dist/cjs/shield/ix.d.ts +54 -0
- package/dist/cjs/shield/ix.js +119 -0
- package/dist/cjs/shield/owner.d.ts +36 -0
- package/dist/cjs/shield/owner.js +126 -0
- package/dist/cjs/shield/ports.d.ts +43 -0
- package/dist/cjs/shield/ports.js +153 -0
- package/dist/cjs/shield/preflight.d.ts +30 -0
- package/dist/cjs/shield/preflight.js +154 -0
- package/dist/cjs/shield/shield.d.ts +68 -0
- package/dist/cjs/shield/shield.js +499 -0
- package/dist/cjs/shield/types.d.ts +202 -0
- package/dist/cjs/shield/types.js +2 -0
- package/dist/cjs/utxo.d.ts +235 -0
- package/dist/cjs/utxo.js +407 -0
- package/dist/esm/client.d.ts +407 -0
- package/dist/esm/client.js +891 -0
- package/dist/esm/compactNote.d.ts +107 -0
- package/dist/esm/compactNote.js +156 -0
- package/dist/esm/config.d.ts +82 -0
- package/dist/esm/config.js +51 -0
- package/dist/esm/events.d.ts +77 -0
- package/dist/esm/events.js +129 -0
- package/dist/esm/idl/privacy_pool.d.ts +5 -0
- package/dist/esm/idl/privacy_pool.js +15216 -0
- package/dist/esm/idl/privacy_pool.json +10313 -0
- package/dist/esm/index.d.ts +16 -0
- package/dist/esm/index.js +29 -0
- package/dist/esm/merkle.d.ts +77 -0
- package/dist/esm/merkle.js +151 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/poseidon.d.ts +29 -0
- package/dist/esm/poseidon.js +87 -0
- package/dist/esm/program.d.ts +37 -0
- package/dist/esm/program.js +53 -0
- package/dist/esm/proof.d.ts +183 -0
- package/dist/esm/proof.js +281 -0
- package/dist/esm/prover.d.ts +54 -0
- package/dist/esm/prover.js +75 -0
- package/dist/esm/random.d.ts +16 -0
- package/dist/esm/random.js +21 -0
- package/dist/esm/relayer.d.ts +318 -0
- package/dist/esm/relayer.js +249 -0
- package/dist/esm/retry.d.ts +32 -0
- package/dist/esm/retry.js +71 -0
- package/dist/esm/shield/alt.d.ts +87 -0
- package/dist/esm/shield/alt.js +186 -0
- package/dist/esm/shield/computeBudget.d.ts +61 -0
- package/dist/esm/shield/computeBudget.js +61 -0
- package/dist/esm/shield/errors.d.ts +58 -0
- package/dist/esm/shield/errors.js +115 -0
- package/dist/esm/shield/finalize.d.ts +45 -0
- package/dist/esm/shield/finalize.js +83 -0
- package/dist/esm/shield/index.d.ts +35 -0
- package/dist/esm/shield/index.js +32 -0
- package/dist/esm/shield/ix.d.ts +54 -0
- package/dist/esm/shield/ix.js +82 -0
- package/dist/esm/shield/owner.d.ts +36 -0
- package/dist/esm/shield/owner.js +122 -0
- package/dist/esm/shield/ports.d.ts +43 -0
- package/dist/esm/shield/ports.js +147 -0
- package/dist/esm/shield/preflight.d.ts +30 -0
- package/dist/esm/shield/preflight.js +151 -0
- package/dist/esm/shield/shield.d.ts +68 -0
- package/dist/esm/shield/shield.js +492 -0
- package/dist/esm/shield/types.d.ts +202 -0
- package/dist/esm/shield/types.js +1 -0
- package/dist/esm/utxo.d.ts +235 -0
- package/dist/esm/utxo.js +382 -0
- package/dist/src/client.d.ts +407 -0
- package/dist/src/client.js +951 -0
- package/dist/src/compactNote.d.ts +107 -0
- package/dist/src/compactNote.js +167 -0
- package/dist/src/config.d.ts +82 -0
- package/dist/src/config.js +57 -0
- package/dist/src/events.d.ts +77 -0
- package/dist/src/events.js +167 -0
- package/dist/src/idl/privacy_pool.d.ts +5 -0
- package/dist/src/idl/privacy_pool.js +15218 -0
- package/dist/src/index.d.ts +16 -0
- package/dist/src/index.js +67 -0
- package/dist/src/merkle.d.ts +77 -0
- package/dist/src/merkle.js +156 -0
- package/dist/src/poseidon.d.ts +29 -0
- package/dist/src/poseidon.js +100 -0
- package/dist/src/program.d.ts +37 -0
- package/dist/src/program.js +61 -0
- package/dist/src/proof.d.ts +183 -0
- package/dist/src/proof.js +292 -0
- package/dist/src/prover.d.ts +54 -0
- package/dist/src/prover.js +112 -0
- package/dist/src/random.d.ts +16 -0
- package/dist/src/random.js +28 -0
- package/dist/src/relayer.d.ts +318 -0
- package/dist/src/relayer.js +257 -0
- package/dist/src/retry.d.ts +32 -0
- package/dist/src/retry.js +75 -0
- package/dist/src/shield/alt.d.ts +87 -0
- package/dist/src/shield/alt.js +194 -0
- package/dist/src/shield/computeBudget.d.ts +61 -0
- package/dist/src/shield/computeBudget.js +64 -0
- package/dist/src/shield/errors.d.ts +58 -0
- package/dist/src/shield/errors.js +121 -0
- package/dist/src/shield/finalize.d.ts +45 -0
- package/dist/src/shield/finalize.js +119 -0
- package/dist/src/shield/index.d.ts +35 -0
- package/dist/src/shield/index.js +68 -0
- package/dist/src/shield/ix.d.ts +54 -0
- package/dist/src/shield/ix.js +119 -0
- package/dist/src/shield/owner.d.ts +36 -0
- package/dist/src/shield/owner.js +126 -0
- package/dist/src/shield/ports.d.ts +43 -0
- package/dist/src/shield/ports.js +153 -0
- package/dist/src/shield/preflight.d.ts +30 -0
- package/dist/src/shield/preflight.js +154 -0
- package/dist/src/shield/shield.d.ts +68 -0
- package/dist/src/shield/shield.js +499 -0
- package/dist/src/shield/types.d.ts +202 -0
- package/dist/src/shield/types.js +2 -0
- package/dist/src/utxo.d.ts +235 -0
- package/dist/src/utxo.js +407 -0
- package/dist/tests/compact-note.test.d.ts +1 -0
- package/dist/tests/compact-note.test.js +173 -0
- package/dist/tests/config.test.d.ts +1 -0
- package/dist/tests/config.test.js +102 -0
- package/dist/tests/edge-cases.test.d.ts +1 -0
- package/dist/tests/edge-cases.test.js +220 -0
- package/dist/tests/encryption.test.d.ts +1 -0
- package/dist/tests/encryption.test.js +215 -0
- package/dist/tests/events.test.d.ts +1 -0
- package/dist/tests/events.test.js +78 -0
- package/dist/tests/multi-tree.test.d.ts +1 -0
- package/dist/tests/multi-tree.test.js +405 -0
- package/dist/tests/pda.test.d.ts +1 -0
- package/dist/tests/pda.test.js +229 -0
- package/dist/tests/poseidon-builder-parity.test.d.ts +1 -0
- package/dist/tests/poseidon-builder-parity.test.js +72 -0
- package/dist/tests/poseidon.test.d.ts +1 -0
- package/dist/tests/poseidon.test.js +142 -0
- package/dist/tests/proof.test.d.ts +1 -0
- package/dist/tests/proof.test.js +296 -0
- package/dist/tests/relayer.test.d.ts +1 -0
- package/dist/tests/relayer.test.js +271 -0
- package/dist/tests/sdk.integration.test.d.ts +1 -0
- package/dist/tests/sdk.integration.test.js +330 -0
- package/dist/tests/shield-owner.test.d.ts +1 -0
- package/dist/tests/shield-owner.test.js +89 -0
- package/dist/tests/shield-preflight.test.d.ts +1 -0
- package/dist/tests/shield-preflight.test.js +87 -0
- package/dist/tests/shield-realproof.test.d.ts +1 -0
- package/dist/tests/shield-realproof.test.js +272 -0
- package/dist/tests/shield.test.d.ts +1 -0
- package/dist/tests/shield.test.js +403 -0
- package/dist/tests/utxo.test.d.ts +1 -0
- package/dist/tests/utxo.test.js +140 -0
- package/package.json +105 -11
- package/poseidon.d.ts +2 -0
- package/poseidon.js +4 -0
- package/proof.d.ts +2 -0
- package/proof.js +4 -0
- package/prover.d.ts +2 -0
- package/prover.js +4 -0
- package/shield.d.ts +2 -0
- package/shield.js +4 -0
- package/src/client.ts +0 -352
- package/src/config.ts +0 -13
- package/src/index.ts +0 -6
- package/src/merkle.ts +0 -178
- package/src/note.ts +0 -193
- package/src/poseidon.ts +0 -62
- package/src/proof.ts +0 -170
- package/test/script.js +0 -0
- package/test-tsconfig.json +0 -19
- package/tests/note.test.ts +0 -50
- package/tests/sdk.integration.test.ts +0 -210
- package/tsconfig.json +0 -18
package/package.json
CHANGED
|
@@ -1,26 +1,112 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@veilo/sdk-core",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
5
|
-
"homepage": "https://github.com/
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "TypeScript SDK for the Veilo Privacy Pool - UTXO-based privacy protocol on Solana with ZK-SNARKs",
|
|
5
|
+
"homepage": "https://github.com/VeiloSolana/veilo-sdk#readme",
|
|
6
6
|
"bugs": {
|
|
7
|
-
"url": "https://github.com/
|
|
7
|
+
"url": "https://github.com/VeiloSolana/veilo-sdk/issues"
|
|
8
8
|
},
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/
|
|
11
|
+
"url": "git+https://github.com/VeiloSolana/veilo-sdk.git"
|
|
12
12
|
},
|
|
13
13
|
"license": "ISC",
|
|
14
|
-
"author": "",
|
|
14
|
+
"author": "Veilo <https://github.com/VeiloSolana>",
|
|
15
15
|
"type": "commonjs",
|
|
16
|
-
"main": "dist/index.js",
|
|
17
|
-
"
|
|
16
|
+
"main": "dist/cjs/index.js",
|
|
17
|
+
"module": "dist/esm/index.js",
|
|
18
|
+
"types": "dist/cjs/index.d.ts",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"import": {
|
|
22
|
+
"types": "./dist/esm/index.d.ts",
|
|
23
|
+
"default": "./dist/esm/index.js"
|
|
24
|
+
},
|
|
25
|
+
"require": {
|
|
26
|
+
"types": "./dist/cjs/index.d.ts",
|
|
27
|
+
"default": "./dist/cjs/index.js"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"./config": {
|
|
31
|
+
"import": {
|
|
32
|
+
"types": "./dist/esm/config.d.ts",
|
|
33
|
+
"default": "./dist/esm/config.js"
|
|
34
|
+
},
|
|
35
|
+
"require": {
|
|
36
|
+
"types": "./dist/cjs/config.d.ts",
|
|
37
|
+
"default": "./dist/cjs/config.js"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"./poseidon": {
|
|
41
|
+
"import": {
|
|
42
|
+
"types": "./dist/esm/poseidon.d.ts",
|
|
43
|
+
"default": "./dist/esm/poseidon.js"
|
|
44
|
+
},
|
|
45
|
+
"require": {
|
|
46
|
+
"types": "./dist/cjs/poseidon.d.ts",
|
|
47
|
+
"default": "./dist/cjs/poseidon.js"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"./proof": {
|
|
51
|
+
"import": {
|
|
52
|
+
"types": "./dist/esm/proof.d.ts",
|
|
53
|
+
"default": "./dist/esm/proof.js"
|
|
54
|
+
},
|
|
55
|
+
"require": {
|
|
56
|
+
"types": "./dist/cjs/proof.d.ts",
|
|
57
|
+
"default": "./dist/cjs/proof.js"
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"./prover": {
|
|
61
|
+
"import": {
|
|
62
|
+
"types": "./dist/esm/prover.d.ts",
|
|
63
|
+
"default": "./dist/esm/prover.js"
|
|
64
|
+
},
|
|
65
|
+
"require": {
|
|
66
|
+
"types": "./dist/cjs/prover.d.ts",
|
|
67
|
+
"default": "./dist/cjs/prover.js"
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
"./shield": {
|
|
71
|
+
"import": {
|
|
72
|
+
"types": "./dist/esm/shield/index.d.ts",
|
|
73
|
+
"default": "./dist/esm/shield/index.js"
|
|
74
|
+
},
|
|
75
|
+
"require": {
|
|
76
|
+
"types": "./dist/cjs/shield/index.d.ts",
|
|
77
|
+
"default": "./dist/cjs/shield/index.js"
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
"./package.json": "./package.json"
|
|
81
|
+
},
|
|
82
|
+
"publishConfig": {
|
|
83
|
+
"access": "public"
|
|
84
|
+
},
|
|
85
|
+
"sideEffects": false,
|
|
86
|
+
"files": [
|
|
87
|
+
"dist/",
|
|
88
|
+
"config.js",
|
|
89
|
+
"config.d.ts",
|
|
90
|
+
"poseidon.js",
|
|
91
|
+
"poseidon.d.ts",
|
|
92
|
+
"proof.js",
|
|
93
|
+
"proof.d.ts",
|
|
94
|
+
"prover.js",
|
|
95
|
+
"prover.d.ts",
|
|
96
|
+
"shield.js",
|
|
97
|
+
"shield.d.ts",
|
|
98
|
+
"README.md",
|
|
99
|
+
"SHIELD_INTEGRATION.md",
|
|
100
|
+
"LICENSE"
|
|
101
|
+
],
|
|
18
102
|
"directories": {
|
|
19
103
|
"test": "tests"
|
|
20
104
|
},
|
|
21
105
|
"scripts": {
|
|
22
|
-
"
|
|
23
|
-
"
|
|
106
|
+
"gen:idl": "node scripts/gen-idl.mjs",
|
|
107
|
+
"verify:cipher-parity": "npm run build && node scripts/verify-compact-cipher-parity.mjs",
|
|
108
|
+
"build": "rm -rf dist/ && tsc -p tsconfig.json && tsc -p tsconfig.esm.json && echo '{\"type\":\"module\"}' > dist/esm/package.json",
|
|
109
|
+
"test": "rm -rf dist/ && export ANCHOR_PROVIDER_URL=https://api.devnet.solana.com && export ANCHOR_WALLET=$HOME/.config/solana/id.json && tsc -p test-tsconfig.json && mocha -t 1000000 \"dist/tests/**/*.js\""
|
|
24
110
|
},
|
|
25
111
|
"dependencies": {
|
|
26
112
|
"@coral-xyz/anchor": "^0.30.0",
|
|
@@ -28,12 +114,20 @@
|
|
|
28
114
|
"@solana/spl-token": "^0.4.6",
|
|
29
115
|
"@solana/web3.js": "^1.95.0",
|
|
30
116
|
"circomlibjs": "^0.1.7",
|
|
31
|
-
"mocha": "^11.7.5",
|
|
32
117
|
"tweetnacl": "^1.0.3"
|
|
33
118
|
},
|
|
119
|
+
"peerDependencies": {
|
|
120
|
+
"snarkjs": ">=0.7.0"
|
|
121
|
+
},
|
|
122
|
+
"peerDependenciesMeta": {
|
|
123
|
+
"snarkjs": {
|
|
124
|
+
"optional": true
|
|
125
|
+
}
|
|
126
|
+
},
|
|
34
127
|
"devDependencies": {
|
|
35
128
|
"@types/circomlibjs": "^0.1.6",
|
|
36
129
|
"@types/mocha": "^10.0.10",
|
|
130
|
+
"mocha": "^11.7.5",
|
|
37
131
|
"@types/node": "^24.10.1",
|
|
38
132
|
"chai": "^6.2.1",
|
|
39
133
|
"ts-node": "^10.9.2",
|
package/poseidon.d.ts
ADDED
package/poseidon.js
ADDED
package/proof.d.ts
ADDED
package/proof.js
ADDED
package/prover.d.ts
ADDED
package/prover.js
ADDED
package/shield.d.ts
ADDED
package/shield.js
ADDED
package/src/client.ts
DELETED
|
@@ -1,352 +0,0 @@
|
|
|
1
|
-
import * as anchor from "@coral-xyz/anchor";
|
|
2
|
-
import { Program, BN, Idl } from "@coral-xyz/anchor";
|
|
3
|
-
import { PublicKey, SystemProgram, Keypair } from "@solana/web3.js";
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
ProofBuilder,
|
|
7
|
-
WithdrawCircuitInputs,
|
|
8
|
-
WithdrawProofStruct,
|
|
9
|
-
deriveNullifier,
|
|
10
|
-
encodeSnarkjsProofToWithdrawProof,
|
|
11
|
-
} from "./proof";
|
|
12
|
-
|
|
13
|
-
import {
|
|
14
|
-
createNoteWithCommitment,
|
|
15
|
-
EncryptedNotePlaintext,
|
|
16
|
-
encryptNote,
|
|
17
|
-
SerializedNote,
|
|
18
|
-
} from "./note";
|
|
19
|
-
|
|
20
|
-
import { MerklePath, MerkleTree } from "./merkle";
|
|
21
|
-
import { randomBytes } from "crypto";
|
|
22
|
-
|
|
23
|
-
// -----------------------------------------------------------------------------
|
|
24
|
-
// Types
|
|
25
|
-
// -----------------------------------------------------------------------------
|
|
26
|
-
|
|
27
|
-
export type NoteAndMerkleData = {
|
|
28
|
-
note: SerializedNote;
|
|
29
|
-
leafIndex: number;
|
|
30
|
-
root: Uint8Array;
|
|
31
|
-
merklePath: MerklePath;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
// -----------------------------------------------------------------------------
|
|
35
|
-
// High-level deposit helper (off-chain Merkle is just for zk / demos)
|
|
36
|
-
// -----------------------------------------------------------------------------
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* High-level helper:
|
|
40
|
-
* - Creates a random note + commitment
|
|
41
|
-
* - Inserts the commitment into an *off-chain* Merkle tree (your zk tree)
|
|
42
|
-
* - Calls on-chain `depositFixed` with the commitment
|
|
43
|
-
* - Returns note + index + Merkle path (+ off-chain root)
|
|
44
|
-
*
|
|
45
|
-
* The on-chain program *also* keeps its own rolling 32-byte root, but that is
|
|
46
|
-
* intentionally minimal and independent from this off-chain tree. For a real
|
|
47
|
-
* zk circuit you’d want both to share the same hash function.
|
|
48
|
-
*/
|
|
49
|
-
export async function createNoteDepositWithMerkle<T extends Idl>(params: {
|
|
50
|
-
program: Program<T>;
|
|
51
|
-
depositor: anchor.Wallet;
|
|
52
|
-
denomIndex: number;
|
|
53
|
-
valueLamports: bigint;
|
|
54
|
-
tree: MerkleTree;
|
|
55
|
-
}): Promise<NoteAndMerkleData> {
|
|
56
|
-
const { program, depositor, denomIndex, valueLamports, tree } = params;
|
|
57
|
-
|
|
58
|
-
const note = createNoteWithCommitment({
|
|
59
|
-
value: valueLamports,
|
|
60
|
-
owner: depositor.publicKey,
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
// Maintain your off-chain mirror (for proofs)
|
|
64
|
-
const { index, root } = tree.insert(note.commitment);
|
|
65
|
-
const merklePath = tree.getPath(index);
|
|
66
|
-
|
|
67
|
-
// Call low-level deposit with just the commitment
|
|
68
|
-
await depositFixedSol({
|
|
69
|
-
program,
|
|
70
|
-
depositor,
|
|
71
|
-
denomIndex,
|
|
72
|
-
commitment: note.commitment,
|
|
73
|
-
note,
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
return {
|
|
77
|
-
note,
|
|
78
|
-
leafIndex: index,
|
|
79
|
-
root,
|
|
80
|
-
merklePath,
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// -----------------------------------------------------------------------------
|
|
85
|
-
// PDA helpers (v3 seeds)
|
|
86
|
-
// -----------------------------------------------------------------------------
|
|
87
|
-
|
|
88
|
-
export function getPoolPdas(programId: PublicKey, commitmentSeed?: Uint8Array) {
|
|
89
|
-
const [config] = PublicKey.findProgramAddressSync(
|
|
90
|
-
[Buffer.from("privacy_config_v3")],
|
|
91
|
-
programId
|
|
92
|
-
);
|
|
93
|
-
const [vault] = PublicKey.findProgramAddressSync(
|
|
94
|
-
[Buffer.from("privacy_vault_v3")],
|
|
95
|
-
programId
|
|
96
|
-
);
|
|
97
|
-
const [noteTree] = PublicKey.findProgramAddressSync(
|
|
98
|
-
[Buffer.from("privacy_note_tree_v3")],
|
|
99
|
-
programId
|
|
100
|
-
);
|
|
101
|
-
const [nullifiers] = PublicKey.findProgramAddressSync(
|
|
102
|
-
[Buffer.from("privacy_nullifiers_v3")],
|
|
103
|
-
programId
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
const [noteHint] = PublicKey.findProgramAddressSync(
|
|
107
|
-
[Buffer.from("privacy_note_hint_v3"), commitmentSeed ?? Buffer.alloc(0)],
|
|
108
|
-
programId
|
|
109
|
-
);
|
|
110
|
-
|
|
111
|
-
return { config, vault, noteTree, nullifiers, noteHint };
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// -----------------------------------------------------------------------------
|
|
115
|
-
// Pool initialization
|
|
116
|
-
// -----------------------------------------------------------------------------
|
|
117
|
-
|
|
118
|
-
export async function initializePool<T extends Idl>(params: {
|
|
119
|
-
program: Program<T>;
|
|
120
|
-
admin: anchor.Wallet;
|
|
121
|
-
denomsLamports: (bigint | number)[];
|
|
122
|
-
feeBps: number; // 0–10000
|
|
123
|
-
}) {
|
|
124
|
-
const { program, admin, denomsLamports, feeBps } = params;
|
|
125
|
-
const { config, vault, noteTree, nullifiers } = getPoolPdas(
|
|
126
|
-
program.programId
|
|
127
|
-
);
|
|
128
|
-
|
|
129
|
-
await (program.methods as any)
|
|
130
|
-
.initialize(
|
|
131
|
-
denomsLamports.map((d) => new BN(d.toString())),
|
|
132
|
-
feeBps
|
|
133
|
-
)
|
|
134
|
-
.accounts({
|
|
135
|
-
config,
|
|
136
|
-
vault,
|
|
137
|
-
noteTree,
|
|
138
|
-
nullifiers,
|
|
139
|
-
admin: admin.publicKey,
|
|
140
|
-
systemProgram: SystemProgram.programId,
|
|
141
|
-
} as any)
|
|
142
|
-
.rpc();
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// -----------------------------------------------------------------------------
|
|
146
|
-
// Deposit helpers
|
|
147
|
-
// -----------------------------------------------------------------------------
|
|
148
|
-
|
|
149
|
-
export type DepositNoteResult = {
|
|
150
|
-
commitment: Uint8Array; // 32 bytes
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Low-level deposit helper.
|
|
155
|
-
* Expects a 32-byte commitment; on-chain NoteTree keeps a rolling 32-byte root.
|
|
156
|
-
*/
|
|
157
|
-
export async function depositFixedSol<T extends Idl>(params: {
|
|
158
|
-
program: Program<T>;
|
|
159
|
-
depositor: anchor.Wallet;
|
|
160
|
-
denomIndex: number;
|
|
161
|
-
commitment: Uint8Array; // 32
|
|
162
|
-
note: SerializedNote;
|
|
163
|
-
}) {
|
|
164
|
-
const { program, depositor, denomIndex, commitment, note } = params;
|
|
165
|
-
const { config, vault, noteTree, noteHint } = getPoolPdas(
|
|
166
|
-
program.programId,
|
|
167
|
-
commitment
|
|
168
|
-
);
|
|
169
|
-
|
|
170
|
-
if (commitment.length !== 32) {
|
|
171
|
-
throw new Error("commitment must be 32 bytes");
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
const notePlain: EncryptedNotePlaintext = {
|
|
175
|
-
secret: randomBytes(32),
|
|
176
|
-
nullifier: deriveNullifier(note),
|
|
177
|
-
denomIndex: 0,
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
const sharedKey = randomBytes(32); // derive from recipient pubkey in real wallet
|
|
181
|
-
const encryptedNote = encryptNote(notePlain, sharedKey);
|
|
182
|
-
|
|
183
|
-
await (program.methods as any)
|
|
184
|
-
.depositFixed(
|
|
185
|
-
denomIndex,
|
|
186
|
-
Array.from(commitment) // [u8;32]
|
|
187
|
-
)
|
|
188
|
-
.accounts({
|
|
189
|
-
config,
|
|
190
|
-
vault,
|
|
191
|
-
noteTree,
|
|
192
|
-
noteHint,
|
|
193
|
-
depositor: depositor.publicKey,
|
|
194
|
-
systemProgram: SystemProgram.programId,
|
|
195
|
-
} as any)
|
|
196
|
-
.rpc();
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Convenience: build a random Note off-chain, commit it, and call deposit.
|
|
201
|
-
*/
|
|
202
|
-
export async function createNoteAndDeposit<T extends Idl>(params: {
|
|
203
|
-
program: Program<T>;
|
|
204
|
-
depositor: anchor.Wallet;
|
|
205
|
-
denomIndex: number;
|
|
206
|
-
valueLamports: bigint;
|
|
207
|
-
}) {
|
|
208
|
-
const { program, depositor, denomIndex, valueLamports } = params;
|
|
209
|
-
|
|
210
|
-
const note = createNoteWithCommitment({
|
|
211
|
-
value: valueLamports,
|
|
212
|
-
owner: depositor.publicKey,
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
await depositFixedSol({
|
|
216
|
-
program,
|
|
217
|
-
depositor,
|
|
218
|
-
denomIndex,
|
|
219
|
-
commitment: note.commitment,
|
|
220
|
-
note,
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
return note;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
// -----------------------------------------------------------------------------
|
|
227
|
-
// Relayers & Withdrawals
|
|
228
|
-
// -----------------------------------------------------------------------------
|
|
229
|
-
|
|
230
|
-
export async function addRelayer<T extends Idl>(params: {
|
|
231
|
-
program: Program<T>;
|
|
232
|
-
admin: anchor.Wallet;
|
|
233
|
-
newRelayer: PublicKey;
|
|
234
|
-
}) {
|
|
235
|
-
const { program, admin, newRelayer } = params;
|
|
236
|
-
const { config } = getPoolPdas(program.programId);
|
|
237
|
-
|
|
238
|
-
await (program.methods as any)
|
|
239
|
-
.addRelayer(newRelayer)
|
|
240
|
-
.accounts({
|
|
241
|
-
config,
|
|
242
|
-
admin: admin.publicKey,
|
|
243
|
-
} as any)
|
|
244
|
-
.rpc();
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* Low-level withdraw:
|
|
249
|
-
* - Expects the **already packed** WithdrawProofStruct
|
|
250
|
-
* (matching Rust `WithdrawProof` fields).
|
|
251
|
-
*/
|
|
252
|
-
export async function withdrawViaRelayer<T extends Idl>(params: {
|
|
253
|
-
program: Program<T>;
|
|
254
|
-
relayer: Keypair;
|
|
255
|
-
recipient: PublicKey;
|
|
256
|
-
denomIndex: number;
|
|
257
|
-
root: Uint8Array; // 32 bytes
|
|
258
|
-
nullifier: Uint8Array; // 32 bytes
|
|
259
|
-
proof: WithdrawProofStruct;
|
|
260
|
-
}) {
|
|
261
|
-
const { program, relayer, recipient, denomIndex, root, nullifier, proof } =
|
|
262
|
-
params;
|
|
263
|
-
const { config, vault, noteTree, nullifiers } = getPoolPdas(
|
|
264
|
-
program.programId
|
|
265
|
-
);
|
|
266
|
-
|
|
267
|
-
if (root.length !== 32) throw new Error("root must be 32 bytes");
|
|
268
|
-
if (nullifier.length !== 32) throw new Error("nullifier must be 32 bytes");
|
|
269
|
-
|
|
270
|
-
await (program.methods as any)
|
|
271
|
-
.withdraw(
|
|
272
|
-
Array.from(root),
|
|
273
|
-
Array.from(nullifier),
|
|
274
|
-
denomIndex,
|
|
275
|
-
recipient,
|
|
276
|
-
proof // <- Anchor / IDL maps this to WithdrawProof { proof_a, proof_b, proof_c }
|
|
277
|
-
)
|
|
278
|
-
.accounts({
|
|
279
|
-
config,
|
|
280
|
-
vault,
|
|
281
|
-
noteTree,
|
|
282
|
-
nullifiers,
|
|
283
|
-
relayer: relayer.publicKey,
|
|
284
|
-
recipient,
|
|
285
|
-
systemProgram: SystemProgram.programId,
|
|
286
|
-
} as any)
|
|
287
|
-
.signers([relayer])
|
|
288
|
-
.rpc();
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
/**
|
|
292
|
-
* High-level withdraw:
|
|
293
|
-
* - Takes note + Merkle path + denom + fee info
|
|
294
|
-
* - Uses a pluggable ProofBuilder (snarkjs.groth16) to create a RawProof
|
|
295
|
-
* - Encodes RawProof into WithdrawProofStruct
|
|
296
|
-
* - Calls the low-level withdrawViaRelayer
|
|
297
|
-
*
|
|
298
|
-
* In production, you'd typically call a relayer HTTP API instead, and let it
|
|
299
|
-
* build/verify the proof server-side. But this is handy for tools / tests.
|
|
300
|
-
*/
|
|
301
|
-
export async function withdrawViaRelayerWithProof<T extends Idl>(params: {
|
|
302
|
-
program: Program<T>;
|
|
303
|
-
relayer: Keypair;
|
|
304
|
-
recipient: PublicKey;
|
|
305
|
-
denomIndex: number;
|
|
306
|
-
feeBps: number;
|
|
307
|
-
root: Uint8Array;
|
|
308
|
-
nullifier: Uint8Array;
|
|
309
|
-
noteData: SerializedNote;
|
|
310
|
-
merklePath: MerklePath;
|
|
311
|
-
builder: ProofBuilder; // must produce a valid snarkjs Groth16 proof
|
|
312
|
-
}) {
|
|
313
|
-
const {
|
|
314
|
-
program,
|
|
315
|
-
relayer,
|
|
316
|
-
recipient,
|
|
317
|
-
denomIndex,
|
|
318
|
-
feeBps,
|
|
319
|
-
root,
|
|
320
|
-
nullifier,
|
|
321
|
-
noteData,
|
|
322
|
-
merklePath,
|
|
323
|
-
builder,
|
|
324
|
-
} = params;
|
|
325
|
-
|
|
326
|
-
const inputs: WithdrawCircuitInputs = {
|
|
327
|
-
root,
|
|
328
|
-
note: noteData,
|
|
329
|
-
merklePath,
|
|
330
|
-
nullifier,
|
|
331
|
-
denomIndex,
|
|
332
|
-
recipient,
|
|
333
|
-
relayer: relayer.publicKey,
|
|
334
|
-
feeBps,
|
|
335
|
-
};
|
|
336
|
-
|
|
337
|
-
// Build snarkjs proof off-chain
|
|
338
|
-
const rawProof = await builder(inputs);
|
|
339
|
-
|
|
340
|
-
// Pack into the struct expected by the on-chain Rust program
|
|
341
|
-
const withdrawProof = encodeSnarkjsProofToWithdrawProof(rawProof);
|
|
342
|
-
|
|
343
|
-
await withdrawViaRelayer({
|
|
344
|
-
program,
|
|
345
|
-
relayer,
|
|
346
|
-
recipient,
|
|
347
|
-
denomIndex,
|
|
348
|
-
root,
|
|
349
|
-
nullifier,
|
|
350
|
-
proof: withdrawProof,
|
|
351
|
-
});
|
|
352
|
-
}
|
package/src/config.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// config.ts
|
|
2
|
-
import { LAMPORTS_PER_SOL } from "@solana/web3.js";
|
|
3
|
-
|
|
4
|
-
export const DEFAULT_FEE_BPS = 50; // 0.5%
|
|
5
|
-
|
|
6
|
-
export function sol(n: number): bigint {
|
|
7
|
-
return BigInt(n) * BigInt(LAMPORTS_PER_SOL);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export type PoolInitConfig = {
|
|
11
|
-
denomsSol: number[]; // [1, 5] etc
|
|
12
|
-
feeBps?: number;
|
|
13
|
-
};
|