@veilo/sdk-core 0.3.3 → 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.
Files changed (195) hide show
  1. package/README.md +42 -3
  2. package/SHIELD_INTEGRATION.md +143 -0
  3. package/config.d.ts +2 -0
  4. package/config.js +4 -0
  5. package/dist/cjs/client.d.ts +5 -5
  6. package/dist/cjs/client.js +79 -42
  7. package/dist/cjs/compactNote.d.ts +107 -0
  8. package/dist/cjs/compactNote.js +167 -0
  9. package/dist/cjs/events.d.ts +1 -1
  10. package/dist/cjs/events.js +2 -2
  11. package/dist/cjs/idl/privacy_pool.d.ts +5 -0
  12. package/dist/cjs/idl/privacy_pool.js +15218 -0
  13. package/dist/cjs/index.d.ts +16 -13
  14. package/dist/cjs/index.js +40 -30
  15. package/dist/cjs/merkle.d.ts +13 -0
  16. package/dist/cjs/merkle.js +31 -8
  17. package/dist/cjs/program.d.ts +11 -0
  18. package/dist/cjs/program.js +26 -3
  19. package/dist/cjs/proof.d.ts +1 -1
  20. package/dist/cjs/proof.js +37 -37
  21. package/dist/cjs/prover.d.ts +1 -1
  22. package/dist/cjs/prover.js +2 -2
  23. package/dist/cjs/random.d.ts +16 -0
  24. package/dist/cjs/random.js +28 -0
  25. package/dist/cjs/relayer.d.ts +27 -4
  26. package/dist/cjs/relayer.js +16 -5
  27. package/dist/cjs/shield/alt.d.ts +87 -0
  28. package/dist/cjs/shield/alt.js +194 -0
  29. package/dist/cjs/shield/computeBudget.d.ts +61 -0
  30. package/dist/cjs/shield/computeBudget.js +64 -0
  31. package/dist/cjs/shield/errors.d.ts +58 -0
  32. package/dist/cjs/shield/errors.js +121 -0
  33. package/dist/cjs/shield/finalize.d.ts +45 -0
  34. package/dist/cjs/shield/finalize.js +119 -0
  35. package/dist/cjs/shield/index.d.ts +35 -0
  36. package/dist/cjs/shield/index.js +68 -0
  37. package/dist/cjs/shield/ix.d.ts +54 -0
  38. package/dist/cjs/shield/ix.js +119 -0
  39. package/dist/cjs/shield/owner.d.ts +36 -0
  40. package/dist/cjs/shield/owner.js +126 -0
  41. package/dist/cjs/shield/ports.d.ts +43 -0
  42. package/dist/cjs/shield/ports.js +153 -0
  43. package/dist/cjs/shield/preflight.d.ts +30 -0
  44. package/dist/cjs/shield/preflight.js +154 -0
  45. package/dist/cjs/shield/shield.d.ts +68 -0
  46. package/dist/cjs/shield/shield.js +499 -0
  47. package/dist/cjs/shield/types.d.ts +202 -0
  48. package/dist/cjs/shield/types.js +2 -0
  49. package/dist/cjs/utxo.d.ts +20 -0
  50. package/dist/cjs/utxo.js +41 -28
  51. package/dist/esm/client.d.ts +407 -0
  52. package/dist/esm/client.js +9 -5
  53. package/dist/esm/compactNote.d.ts +107 -0
  54. package/dist/esm/compactNote.js +156 -0
  55. package/dist/esm/config.d.ts +82 -0
  56. package/dist/esm/events.d.ts +77 -0
  57. package/dist/esm/events.js +1 -1
  58. package/dist/esm/idl/privacy_pool.d.ts +5 -0
  59. package/dist/esm/idl/privacy_pool.js +15216 -0
  60. package/dist/esm/index.d.ts +16 -0
  61. package/dist/esm/index.js +18 -11
  62. package/dist/esm/merkle.d.ts +77 -0
  63. package/dist/esm/merkle.js +23 -1
  64. package/dist/esm/package.json +1 -0
  65. package/dist/esm/poseidon.d.ts +29 -0
  66. package/dist/esm/program.d.ts +37 -0
  67. package/dist/esm/program.js +23 -1
  68. package/dist/esm/proof.d.ts +183 -0
  69. package/dist/esm/proof.js +2 -2
  70. package/dist/esm/prover.d.ts +54 -0
  71. package/dist/esm/prover.js +1 -1
  72. package/dist/esm/random.d.ts +16 -0
  73. package/dist/esm/random.js +21 -0
  74. package/dist/esm/relayer.d.ts +318 -0
  75. package/dist/esm/relayer.js +16 -5
  76. package/dist/esm/retry.d.ts +32 -0
  77. package/dist/esm/shield/alt.d.ts +87 -0
  78. package/dist/esm/shield/alt.js +186 -0
  79. package/dist/esm/shield/computeBudget.d.ts +61 -0
  80. package/dist/esm/shield/computeBudget.js +61 -0
  81. package/dist/esm/shield/errors.d.ts +58 -0
  82. package/dist/esm/shield/errors.js +115 -0
  83. package/dist/esm/shield/finalize.d.ts +45 -0
  84. package/dist/esm/shield/finalize.js +83 -0
  85. package/dist/esm/shield/index.d.ts +35 -0
  86. package/dist/esm/shield/index.js +32 -0
  87. package/dist/esm/shield/ix.d.ts +54 -0
  88. package/dist/esm/shield/ix.js +82 -0
  89. package/dist/esm/shield/owner.d.ts +36 -0
  90. package/dist/esm/shield/owner.js +122 -0
  91. package/dist/esm/shield/ports.d.ts +43 -0
  92. package/dist/esm/shield/ports.js +147 -0
  93. package/dist/esm/shield/preflight.d.ts +30 -0
  94. package/dist/esm/shield/preflight.js +151 -0
  95. package/dist/esm/shield/shield.d.ts +68 -0
  96. package/dist/esm/shield/shield.js +492 -0
  97. package/dist/esm/shield/types.d.ts +202 -0
  98. package/dist/esm/shield/types.js +1 -0
  99. package/dist/esm/utxo.d.ts +235 -0
  100. package/dist/esm/utxo.js +18 -8
  101. package/dist/src/client.d.ts +407 -0
  102. package/dist/src/client.js +951 -0
  103. package/dist/src/compactNote.d.ts +107 -0
  104. package/dist/src/compactNote.js +167 -0
  105. package/dist/src/config.d.ts +82 -0
  106. package/dist/src/config.js +57 -0
  107. package/dist/src/events.d.ts +77 -0
  108. package/dist/src/events.js +167 -0
  109. package/dist/src/idl/privacy_pool.d.ts +5 -0
  110. package/dist/src/idl/privacy_pool.js +15218 -0
  111. package/dist/src/index.d.ts +16 -0
  112. package/dist/src/index.js +67 -0
  113. package/dist/src/merkle.d.ts +77 -0
  114. package/dist/src/merkle.js +156 -0
  115. package/dist/src/poseidon.d.ts +29 -0
  116. package/dist/src/poseidon.js +100 -0
  117. package/dist/src/program.d.ts +37 -0
  118. package/dist/src/program.js +61 -0
  119. package/dist/src/proof.d.ts +183 -0
  120. package/dist/src/proof.js +292 -0
  121. package/dist/src/prover.d.ts +54 -0
  122. package/dist/src/prover.js +112 -0
  123. package/dist/src/random.d.ts +16 -0
  124. package/dist/src/random.js +28 -0
  125. package/dist/src/relayer.d.ts +318 -0
  126. package/dist/src/relayer.js +257 -0
  127. package/dist/src/retry.d.ts +32 -0
  128. package/dist/src/retry.js +75 -0
  129. package/dist/src/shield/alt.d.ts +87 -0
  130. package/dist/src/shield/alt.js +194 -0
  131. package/dist/src/shield/computeBudget.d.ts +61 -0
  132. package/dist/src/shield/computeBudget.js +64 -0
  133. package/dist/src/shield/errors.d.ts +58 -0
  134. package/dist/src/shield/errors.js +121 -0
  135. package/dist/src/shield/finalize.d.ts +45 -0
  136. package/dist/src/shield/finalize.js +119 -0
  137. package/dist/src/shield/index.d.ts +35 -0
  138. package/dist/src/shield/index.js +68 -0
  139. package/dist/src/shield/ix.d.ts +54 -0
  140. package/dist/src/shield/ix.js +119 -0
  141. package/dist/src/shield/owner.d.ts +36 -0
  142. package/dist/src/shield/owner.js +126 -0
  143. package/dist/src/shield/ports.d.ts +43 -0
  144. package/dist/src/shield/ports.js +153 -0
  145. package/dist/src/shield/preflight.d.ts +30 -0
  146. package/dist/src/shield/preflight.js +154 -0
  147. package/dist/src/shield/shield.d.ts +68 -0
  148. package/dist/src/shield/shield.js +499 -0
  149. package/dist/src/shield/types.d.ts +202 -0
  150. package/dist/src/shield/types.js +2 -0
  151. package/dist/src/utxo.d.ts +235 -0
  152. package/dist/src/utxo.js +407 -0
  153. package/dist/tests/compact-note.test.d.ts +1 -0
  154. package/dist/tests/compact-note.test.js +173 -0
  155. package/dist/tests/config.test.d.ts +1 -0
  156. package/dist/tests/config.test.js +102 -0
  157. package/dist/tests/edge-cases.test.d.ts +1 -0
  158. package/dist/tests/edge-cases.test.js +220 -0
  159. package/dist/tests/encryption.test.d.ts +1 -0
  160. package/dist/tests/encryption.test.js +215 -0
  161. package/dist/tests/events.test.d.ts +1 -0
  162. package/dist/tests/events.test.js +78 -0
  163. package/dist/tests/multi-tree.test.d.ts +1 -0
  164. package/dist/tests/multi-tree.test.js +405 -0
  165. package/dist/tests/pda.test.d.ts +1 -0
  166. package/dist/tests/pda.test.js +229 -0
  167. package/dist/tests/poseidon-builder-parity.test.d.ts +1 -0
  168. package/dist/tests/poseidon-builder-parity.test.js +72 -0
  169. package/dist/tests/poseidon.test.d.ts +1 -0
  170. package/dist/tests/poseidon.test.js +142 -0
  171. package/dist/tests/proof.test.d.ts +1 -0
  172. package/dist/tests/proof.test.js +296 -0
  173. package/dist/tests/relayer.test.d.ts +1 -0
  174. package/dist/tests/relayer.test.js +271 -0
  175. package/dist/tests/sdk.integration.test.d.ts +1 -0
  176. package/dist/tests/sdk.integration.test.js +330 -0
  177. package/dist/tests/shield-owner.test.d.ts +1 -0
  178. package/dist/tests/shield-owner.test.js +89 -0
  179. package/dist/tests/shield-preflight.test.d.ts +1 -0
  180. package/dist/tests/shield-preflight.test.js +87 -0
  181. package/dist/tests/shield-realproof.test.d.ts +1 -0
  182. package/dist/tests/shield-realproof.test.js +272 -0
  183. package/dist/tests/shield.test.d.ts +1 -0
  184. package/dist/tests/shield.test.js +403 -0
  185. package/dist/tests/utxo.test.d.ts +1 -0
  186. package/dist/tests/utxo.test.js +140 -0
  187. package/package.json +69 -11
  188. package/poseidon.d.ts +2 -0
  189. package/poseidon.js +4 -0
  190. package/proof.d.ts +2 -0
  191. package/proof.js +4 -0
  192. package/prover.d.ts +2 -0
  193. package/prover.js +4 -0
  194. package/shield.d.ts +2 -0
  195. package/shield.js +4 -0
@@ -0,0 +1,82 @@
1
+ import { PublicKey } from "@solana/web3.js";
2
+ /** Default relayer fee in basis points (50 = 0.5%). */
3
+ export declare const DEFAULT_FEE_BPS = 50;
4
+ /** Merkle tree depth - matches on-chain MerkleTreeAccount subtrees array size */
5
+ export declare const MERKLE_TREE_DEPTH = 22;
6
+ /** Root history size - matches on-chain MerkleTreeAccount root_history array size */
7
+ export declare const ROOT_HISTORY_SIZE = 256;
8
+ /** Native SOL mint address (Pubkey::default() = all zeros) */
9
+ export declare const NATIVE_SOL_MINT: PublicKey;
10
+ /** Convert SOL to lamports (e.g. `sol(1.5)` → `1_500_000_000n`). */
11
+ export declare function sol(n: number): bigint;
12
+ /** Configuration for initializing a privacy pool */
13
+ export type PoolInitConfig = {
14
+ /** Fee in basis points (0-10000, where 10000 = 100%) */
15
+ feeBps?: number;
16
+ /** Token mint address (use NATIVE_SOL_MINT for SOL pools) */
17
+ mintAddress: PublicKey;
18
+ /** Minimum deposit amount in lamports/token units */
19
+ minDepositAmount?: bigint;
20
+ /** Maximum deposit amount in lamports/token units */
21
+ maxDepositAmount?: bigint;
22
+ /** Minimum withdrawal amount in lamports/token units */
23
+ minWithdrawAmount?: bigint;
24
+ /** Maximum withdrawal amount in lamports/token units */
25
+ maxWithdrawAmount?: bigint;
26
+ };
27
+ /** On-chain PrivacyConfig account structure */
28
+ export type PrivacyConfigAccount = {
29
+ bump: number;
30
+ vaultBump: number;
31
+ admin: PublicKey;
32
+ feeBps: number;
33
+ feeErrorMarginBps: number;
34
+ minWithdrawalFee: bigint;
35
+ /** Minimum fee kept by relayer on swaps (in destination token base units) */
36
+ minSwapFee: bigint;
37
+ /** Fee rate applied to swap output in basis points */
38
+ swapFeeBps: number;
39
+ totalTvl: bigint;
40
+ mintAddress: PublicKey;
41
+ minDepositAmount: bigint;
42
+ maxDepositAmount: bigint;
43
+ minWithdrawAmount: bigint;
44
+ maxWithdrawAmount: bigint;
45
+ numRelayers: number;
46
+ relayers: PublicKey[];
47
+ numTrees: number;
48
+ nextTreeIndex: number;
49
+ };
50
+ /** On-chain GlobalConfig account structure */
51
+ export type GlobalConfigAccount = {
52
+ bump: number;
53
+ admin: PublicKey;
54
+ relayerEnabled: boolean;
55
+ };
56
+ /**
57
+ * Compute the relayer fee for a withdrawal.
58
+ * Mirrors the formula in the relayer-server:
59
+ * fee = max(amount * feeBps / 10_000, minWithdrawalFee)
60
+ *
61
+ * @returns fee in base token units, and the amount that reaches the recipient
62
+ */
63
+ export declare function computeWithdrawalFee(amount: bigint, feeBps: number, minWithdrawalFee: bigint): {
64
+ fee: bigint;
65
+ toRecipient: bigint;
66
+ };
67
+ /**
68
+ * Compute the relayer fee for a cross-pool swap.
69
+ * Mirrors the formula in the relayer-server:
70
+ * relayerFee = max(estimatedOutput * swapFeeBps / 10_000, minSwapFee)
71
+ * destAmount = minAmountOut - relayerFee
72
+ *
73
+ * @param estimatedOutput Jupiter quote output amount
74
+ * @param swapFeeBps From the destination pool's PrivacyConfigAccount
75
+ * @param minSwapFee From the destination pool's PrivacyConfigAccount
76
+ * @param minAmountOut User-agreed minimum swap output (after slippage)
77
+ * @returns relayerFee and the amount committed into the destination UTXO
78
+ */
79
+ export declare function computeSwapFee(estimatedOutput: bigint, swapFeeBps: number, minSwapFee: bigint, minAmountOut: bigint): {
80
+ relayerFee: bigint;
81
+ destAmount: bigint;
82
+ };
@@ -0,0 +1,77 @@
1
+ import { PublicKey } from "@solana/web3.js";
2
+ import { Program, Idl } from "@coral-xyz/anchor";
3
+ import { MerkleTree } from "./merkle.js";
4
+ /**
5
+ * On-chain CommitmentEvent emitted by `transact` and `transact_swap`.
6
+ * Mirrors the IDL CommitmentEvent struct.
7
+ */
8
+ export type CommitmentEvent = {
9
+ commitment: Uint8Array;
10
+ leafIndex: number;
11
+ newRoot: Uint8Array;
12
+ timestamp: number;
13
+ mintAddress: PublicKey;
14
+ treeId: number;
15
+ txSignature: string;
16
+ slot: number;
17
+ };
18
+ /**
19
+ * On-chain NullifierSpent event emitted when a UTXO is consumed.
20
+ * Mirrors the IDL NullifierSpent struct.
21
+ */
22
+ export type NullifierSpentEvent = {
23
+ nullifier: Uint8Array;
24
+ timestamp: number;
25
+ mintAddress: PublicKey;
26
+ treeId: number;
27
+ txSignature: string;
28
+ slot: number;
29
+ };
30
+ /**
31
+ * Fetch and parse CommitmentEvents for a program, optionally filtered by mint.
32
+ *
33
+ * @param program - Anchor program instance
34
+ * @param mintAddress - Filter to a specific pool; omit to get all pools
35
+ * @param before - Start paging before this signature (exclusive)
36
+ * @param until - Stop paging at this signature (exclusive)
37
+ * @param limit - Max signatures to fetch per page (default 1000)
38
+ */
39
+ export declare function scanCommitmentEvents<T extends Idl>(params: {
40
+ program: Program<T>;
41
+ mintAddress?: PublicKey;
42
+ before?: string;
43
+ until?: string;
44
+ limit?: number;
45
+ }): Promise<CommitmentEvent[]>;
46
+ /**
47
+ * Fetch and parse NullifierSpent events for a program, optionally filtered by mint.
48
+ */
49
+ export declare function scanNullifierEvents<T extends Idl>(params: {
50
+ program: Program<T>;
51
+ mintAddress?: PublicKey;
52
+ before?: string;
53
+ until?: string;
54
+ limit?: number;
55
+ }): Promise<NullifierSpentEvent[]>;
56
+ /**
57
+ * Rebuild a local MerkleTree from on-chain CommitmentEvents.
58
+ * Use this to get a valid inclusion proof for spending any UTXO.
59
+ *
60
+ * CommitmentEvents are sorted by (treeId, leafIndex) so the local tree
61
+ * matches the on-chain state exactly.
62
+ *
63
+ * @param program - Anchor program instance
64
+ * @param mintAddress - Pool to reconstruct
65
+ * @param treeId - Which tree to reconstruct (default 0)
66
+ * @param depth - Merkle tree depth (default 22, must match on-chain)
67
+ */
68
+ export declare function buildTreeFromEvents<T extends Idl>(params: {
69
+ program: Program<T>;
70
+ mintAddress: PublicKey;
71
+ treeId?: number;
72
+ depth?: number;
73
+ }): Promise<{
74
+ tree: MerkleTree;
75
+ events: CommitmentEvent[];
76
+ latestSignature?: string;
77
+ }>;
@@ -1,5 +1,5 @@
1
1
  import * as anchor from "@coral-xyz/anchor";
2
- import { MerkleTree } from "./merkle";
2
+ import { MerkleTree } from "./merkle.js";
3
3
  // -----------------------------------------------------------------------------
4
4
  // Event Scanning
5
5
  // -----------------------------------------------------------------------------
@@ -0,0 +1,5 @@
1
+ import type { Idl } from "@coral-xyz/anchor";
2
+ declare const IDL_JSON: Idl & {
3
+ address: string;
4
+ };
5
+ export default IDL_JSON;