@veilo/sdk-core 0.4.0 → 0.5.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 (296) hide show
  1. package/LICENSE +15 -0
  2. package/README.md +286 -1298
  3. package/dist/cjs/accounts/admin.d.ts +84 -0
  4. package/dist/cjs/accounts/admin.js +208 -0
  5. package/dist/cjs/accounts/errors.d.ts +6 -0
  6. package/dist/cjs/accounts/errors.js +98 -0
  7. package/dist/cjs/accounts/index.d.ts +4 -0
  8. package/dist/cjs/accounts/index.js +20 -0
  9. package/dist/cjs/accounts/pdas.d.ts +23 -0
  10. package/dist/cjs/accounts/pdas.js +44 -0
  11. package/dist/cjs/accounts/queries.d.ts +41 -0
  12. package/dist/cjs/accounts/queries.js +95 -0
  13. package/dist/cjs/client.d.ts +2 -407
  14. package/dist/cjs/client.js +6 -938
  15. package/dist/cjs/cloak/client.d.ts +28 -0
  16. package/dist/cjs/cloak/client.js +68 -0
  17. package/dist/cjs/cloak/errors.d.ts +13 -0
  18. package/dist/cjs/cloak/errors.js +25 -0
  19. package/dist/cjs/cloak/helpers.d.ts +6 -0
  20. package/dist/cjs/cloak/helpers.js +35 -0
  21. package/dist/cjs/cloak/index.d.ts +6 -0
  22. package/dist/cjs/cloak/index.js +24 -0
  23. package/dist/cjs/cloak/polling.d.ts +7 -0
  24. package/dist/cjs/cloak/polling.js +66 -0
  25. package/dist/cjs/cloak/transport.d.ts +15 -0
  26. package/dist/cjs/cloak/transport.js +119 -0
  27. package/dist/cjs/cloak/types.d.ts +188 -0
  28. package/dist/cjs/cloak/types.js +5 -0
  29. package/dist/cjs/cloak.d.ts +1 -0
  30. package/dist/cjs/cloak.js +18 -0
  31. package/dist/cjs/compactNote.d.ts +21 -0
  32. package/dist/cjs/compactNote.js +31 -7
  33. package/dist/cjs/index.d.ts +2 -1
  34. package/dist/cjs/index.js +4 -1
  35. package/dist/cjs/notes/encryption.d.ts +41 -0
  36. package/dist/cjs/notes/encryption.js +75 -0
  37. package/dist/cjs/notes/index.d.ts +5 -0
  38. package/dist/cjs/notes/index.js +21 -0
  39. package/dist/cjs/notes/mailbox.d.ts +70 -0
  40. package/dist/cjs/notes/mailbox.js +164 -0
  41. package/dist/cjs/notes/model.d.ts +91 -0
  42. package/dist/cjs/notes/model.js +109 -0
  43. package/dist/cjs/notes/nullifier.d.ts +27 -0
  44. package/dist/cjs/notes/nullifier.js +45 -0
  45. package/dist/cjs/notes/recovery.d.ts +10 -0
  46. package/dist/cjs/notes/recovery.js +31 -0
  47. package/dist/cjs/proof.d.ts +1 -183
  48. package/dist/cjs/proof.js +16 -290
  49. package/dist/cjs/proofs/encoding.d.ts +17 -0
  50. package/dist/cjs/proofs/encoding.js +72 -0
  51. package/dist/cjs/proofs/formatting.d.ts +6 -0
  52. package/dist/cjs/proofs/formatting.js +34 -0
  53. package/dist/cjs/proofs/index.d.ts +5 -0
  54. package/dist/cjs/proofs/index.js +21 -0
  55. package/dist/cjs/proofs/swap.d.ts +87 -0
  56. package/dist/cjs/proofs/swap.js +144 -0
  57. package/dist/cjs/proofs/transaction.d.ts +28 -0
  58. package/dist/cjs/proofs/transaction.js +110 -0
  59. package/dist/cjs/proofs/types.d.ts +70 -0
  60. package/dist/cjs/prover.d.ts +4 -1
  61. package/dist/cjs/prover.js +12 -2
  62. package/dist/cjs/relayer/client.d.ts +61 -0
  63. package/dist/cjs/relayer/client.js +151 -0
  64. package/dist/cjs/relayer/crypto.d.ts +5 -0
  65. package/dist/cjs/relayer/crypto.js +26 -0
  66. package/dist/cjs/relayer/encoding.d.ts +2 -0
  67. package/dist/cjs/relayer/encoding.js +23 -0
  68. package/dist/cjs/relayer/errors.d.ts +7 -0
  69. package/dist/cjs/relayer/errors.js +17 -0
  70. package/dist/cjs/relayer/index.d.ts +3 -0
  71. package/dist/cjs/relayer/index.js +19 -0
  72. package/dist/cjs/relayer/transport.d.ts +17 -0
  73. package/dist/cjs/relayer/transport.js +63 -0
  74. package/dist/{src/relayer.d.ts → cjs/relayer/types.d.ts} +44 -86
  75. package/dist/cjs/relayer/types.js +5 -0
  76. package/dist/cjs/relayer.d.ts +1 -318
  77. package/dist/cjs/relayer.js +15 -254
  78. package/dist/cjs/shield/alt.js +8 -8
  79. package/dist/cjs/shield/errors.js +2 -2
  80. package/dist/cjs/shield/finalize.js +2 -2
  81. package/dist/cjs/shield/ix.d.ts +1 -1
  82. package/dist/cjs/shield/owner.js +9 -8
  83. package/dist/cjs/shield/ports.js +3 -3
  84. package/dist/cjs/shield/preflight.js +3 -3
  85. package/dist/cjs/shield/shield.js +20 -19
  86. package/dist/cjs/shield/types.d.ts +1 -1
  87. package/dist/cjs/transactions/deposit.d.ts +94 -0
  88. package/dist/cjs/transactions/deposit.js +234 -0
  89. package/dist/cjs/transactions/index.d.ts +7 -0
  90. package/dist/cjs/transactions/index.js +26 -0
  91. package/dist/cjs/transactions/swap.d.ts +71 -0
  92. package/dist/cjs/transactions/swap.js +184 -0
  93. package/dist/cjs/transactions/transact.d.ts +34 -0
  94. package/dist/cjs/transactions/transact.js +146 -0
  95. package/dist/cjs/transactions/transfer.d.ts +51 -0
  96. package/dist/cjs/transactions/transfer.js +106 -0
  97. package/dist/cjs/transactions/withdraw.d.ts +52 -0
  98. package/dist/cjs/transactions/withdraw.js +104 -0
  99. package/dist/cjs/utxo.d.ts +1 -235
  100. package/dist/cjs/utxo.js +15 -404
  101. package/dist/esm/accounts/admin.d.ts +84 -0
  102. package/dist/esm/accounts/admin.js +165 -0
  103. package/dist/esm/accounts/errors.d.ts +6 -0
  104. package/dist/esm/accounts/errors.js +95 -0
  105. package/dist/esm/accounts/index.d.ts +4 -0
  106. package/dist/esm/accounts/index.js +4 -0
  107. package/dist/esm/accounts/pdas.d.ts +23 -0
  108. package/dist/esm/accounts/pdas.js +38 -0
  109. package/dist/esm/accounts/queries.d.ts +41 -0
  110. package/dist/esm/accounts/queries.js +88 -0
  111. package/dist/esm/client.d.ts +2 -407
  112. package/dist/esm/client.js +3 -891
  113. package/dist/esm/cloak/client.d.ts +28 -0
  114. package/dist/esm/cloak/client.js +64 -0
  115. package/dist/esm/cloak/errors.d.ts +13 -0
  116. package/dist/esm/cloak/errors.js +21 -0
  117. package/dist/esm/cloak/helpers.d.ts +6 -0
  118. package/dist/esm/cloak/helpers.js +31 -0
  119. package/dist/esm/cloak/index.d.ts +6 -0
  120. package/dist/esm/cloak/index.js +6 -0
  121. package/dist/esm/cloak/polling.d.ts +7 -0
  122. package/dist/esm/cloak/polling.js +63 -0
  123. package/dist/esm/cloak/transport.d.ts +15 -0
  124. package/dist/esm/cloak/transport.js +115 -0
  125. package/dist/esm/cloak/types.d.ts +188 -0
  126. package/dist/esm/cloak/types.js +4 -0
  127. package/dist/esm/cloak.d.ts +1 -0
  128. package/dist/esm/cloak.js +2 -0
  129. package/dist/esm/compactNote.d.ts +21 -0
  130. package/dist/esm/compactNote.js +24 -1
  131. package/dist/esm/index.d.ts +2 -1
  132. package/dist/esm/index.js +3 -1
  133. package/dist/esm/notes/encryption.d.ts +41 -0
  134. package/dist/esm/notes/encryption.js +67 -0
  135. package/dist/esm/notes/index.d.ts +5 -0
  136. package/dist/esm/notes/index.js +5 -0
  137. package/dist/esm/notes/mailbox.d.ts +70 -0
  138. package/dist/esm/notes/mailbox.js +154 -0
  139. package/dist/esm/notes/model.d.ts +91 -0
  140. package/dist/esm/notes/model.js +99 -0
  141. package/dist/esm/notes/nullifier.d.ts +27 -0
  142. package/dist/esm/notes/nullifier.js +40 -0
  143. package/dist/esm/notes/recovery.d.ts +10 -0
  144. package/dist/esm/notes/recovery.js +28 -0
  145. package/dist/esm/proof.d.ts +1 -183
  146. package/dist/esm/proof.js +2 -281
  147. package/dist/esm/proofs/encoding.d.ts +17 -0
  148. package/dist/esm/proofs/encoding.js +68 -0
  149. package/dist/esm/proofs/formatting.d.ts +6 -0
  150. package/dist/esm/proofs/formatting.js +31 -0
  151. package/dist/esm/proofs/index.d.ts +5 -0
  152. package/dist/esm/proofs/index.js +5 -0
  153. package/dist/esm/proofs/swap.d.ts +87 -0
  154. package/dist/esm/proofs/swap.js +138 -0
  155. package/dist/esm/proofs/transaction.d.ts +28 -0
  156. package/dist/esm/proofs/transaction.js +105 -0
  157. package/dist/esm/proofs/types.d.ts +70 -0
  158. package/dist/esm/proofs/types.js +1 -0
  159. package/dist/esm/prover.d.ts +4 -1
  160. package/dist/esm/prover.js +10 -1
  161. package/dist/esm/relayer/client.d.ts +61 -0
  162. package/dist/esm/relayer/client.js +144 -0
  163. package/dist/esm/relayer/crypto.d.ts +5 -0
  164. package/dist/esm/relayer/crypto.js +20 -0
  165. package/dist/esm/relayer/encoding.d.ts +2 -0
  166. package/dist/esm/relayer/encoding.js +19 -0
  167. package/dist/esm/relayer/errors.d.ts +7 -0
  168. package/dist/esm/relayer/errors.js +13 -0
  169. package/dist/esm/relayer/index.d.ts +3 -0
  170. package/dist/esm/relayer/index.js +3 -0
  171. package/dist/esm/relayer/transport.d.ts +17 -0
  172. package/dist/esm/relayer/transport.js +59 -0
  173. package/dist/esm/relayer/types.d.ts +276 -0
  174. package/dist/esm/relayer/types.js +4 -0
  175. package/dist/esm/relayer.d.ts +1 -318
  176. package/dist/esm/relayer.js +2 -249
  177. package/dist/esm/shield/alt.js +1 -1
  178. package/dist/esm/shield/errors.js +1 -1
  179. package/dist/esm/shield/finalize.js +1 -1
  180. package/dist/esm/shield/ix.d.ts +1 -1
  181. package/dist/esm/shield/owner.js +2 -1
  182. package/dist/esm/shield/ports.js +1 -1
  183. package/dist/esm/shield/preflight.js +1 -1
  184. package/dist/esm/shield/shield.js +4 -3
  185. package/dist/esm/shield/types.d.ts +1 -1
  186. package/dist/esm/transactions/deposit.d.ts +94 -0
  187. package/dist/esm/transactions/deposit.js +198 -0
  188. package/dist/esm/transactions/index.d.ts +7 -0
  189. package/dist/esm/transactions/index.js +7 -0
  190. package/dist/esm/transactions/swap.d.ts +71 -0
  191. package/dist/esm/transactions/swap.js +144 -0
  192. package/dist/esm/transactions/transact.d.ts +34 -0
  193. package/dist/esm/transactions/transact.js +110 -0
  194. package/dist/esm/transactions/transfer.d.ts +51 -0
  195. package/dist/esm/transactions/transfer.js +103 -0
  196. package/dist/esm/transactions/withdraw.d.ts +52 -0
  197. package/dist/esm/transactions/withdraw.js +101 -0
  198. package/dist/esm/utxo.d.ts +1 -235
  199. package/dist/esm/utxo.js +2 -382
  200. package/package.json +54 -16
  201. package/SHIELD_INTEGRATION.md +0 -143
  202. package/config.d.ts +0 -2
  203. package/config.js +0 -4
  204. package/dist/src/client.d.ts +0 -407
  205. package/dist/src/client.js +0 -951
  206. package/dist/src/compactNote.d.ts +0 -107
  207. package/dist/src/compactNote.js +0 -167
  208. package/dist/src/config.d.ts +0 -82
  209. package/dist/src/config.js +0 -57
  210. package/dist/src/events.d.ts +0 -77
  211. package/dist/src/events.js +0 -167
  212. package/dist/src/idl/privacy_pool.d.ts +0 -5
  213. package/dist/src/idl/privacy_pool.js +0 -15218
  214. package/dist/src/index.d.ts +0 -16
  215. package/dist/src/index.js +0 -67
  216. package/dist/src/merkle.d.ts +0 -77
  217. package/dist/src/merkle.js +0 -156
  218. package/dist/src/poseidon.d.ts +0 -29
  219. package/dist/src/poseidon.js +0 -100
  220. package/dist/src/program.d.ts +0 -37
  221. package/dist/src/program.js +0 -61
  222. package/dist/src/proof.d.ts +0 -183
  223. package/dist/src/proof.js +0 -292
  224. package/dist/src/prover.d.ts +0 -54
  225. package/dist/src/prover.js +0 -112
  226. package/dist/src/random.d.ts +0 -16
  227. package/dist/src/random.js +0 -28
  228. package/dist/src/relayer.js +0 -257
  229. package/dist/src/retry.d.ts +0 -32
  230. package/dist/src/retry.js +0 -75
  231. package/dist/src/shield/alt.d.ts +0 -87
  232. package/dist/src/shield/alt.js +0 -194
  233. package/dist/src/shield/computeBudget.d.ts +0 -61
  234. package/dist/src/shield/computeBudget.js +0 -64
  235. package/dist/src/shield/errors.d.ts +0 -58
  236. package/dist/src/shield/errors.js +0 -121
  237. package/dist/src/shield/finalize.d.ts +0 -45
  238. package/dist/src/shield/finalize.js +0 -119
  239. package/dist/src/shield/index.d.ts +0 -35
  240. package/dist/src/shield/index.js +0 -68
  241. package/dist/src/shield/ix.d.ts +0 -54
  242. package/dist/src/shield/ix.js +0 -119
  243. package/dist/src/shield/owner.d.ts +0 -36
  244. package/dist/src/shield/owner.js +0 -126
  245. package/dist/src/shield/ports.d.ts +0 -43
  246. package/dist/src/shield/ports.js +0 -153
  247. package/dist/src/shield/preflight.d.ts +0 -30
  248. package/dist/src/shield/preflight.js +0 -154
  249. package/dist/src/shield/shield.d.ts +0 -68
  250. package/dist/src/shield/shield.js +0 -499
  251. package/dist/src/shield/types.d.ts +0 -202
  252. package/dist/src/utxo.d.ts +0 -235
  253. package/dist/src/utxo.js +0 -407
  254. package/dist/tests/compact-note.test.d.ts +0 -1
  255. package/dist/tests/compact-note.test.js +0 -173
  256. package/dist/tests/config.test.d.ts +0 -1
  257. package/dist/tests/config.test.js +0 -102
  258. package/dist/tests/edge-cases.test.d.ts +0 -1
  259. package/dist/tests/edge-cases.test.js +0 -220
  260. package/dist/tests/encryption.test.d.ts +0 -1
  261. package/dist/tests/encryption.test.js +0 -215
  262. package/dist/tests/events.test.d.ts +0 -1
  263. package/dist/tests/events.test.js +0 -78
  264. package/dist/tests/multi-tree.test.d.ts +0 -1
  265. package/dist/tests/multi-tree.test.js +0 -405
  266. package/dist/tests/pda.test.d.ts +0 -1
  267. package/dist/tests/pda.test.js +0 -229
  268. package/dist/tests/poseidon-builder-parity.test.d.ts +0 -1
  269. package/dist/tests/poseidon-builder-parity.test.js +0 -72
  270. package/dist/tests/poseidon.test.d.ts +0 -1
  271. package/dist/tests/poseidon.test.js +0 -142
  272. package/dist/tests/proof.test.d.ts +0 -1
  273. package/dist/tests/proof.test.js +0 -296
  274. package/dist/tests/relayer.test.d.ts +0 -1
  275. package/dist/tests/relayer.test.js +0 -271
  276. package/dist/tests/sdk.integration.test.d.ts +0 -1
  277. package/dist/tests/sdk.integration.test.js +0 -330
  278. package/dist/tests/shield-owner.test.d.ts +0 -1
  279. package/dist/tests/shield-owner.test.js +0 -89
  280. package/dist/tests/shield-preflight.test.d.ts +0 -1
  281. package/dist/tests/shield-preflight.test.js +0 -87
  282. package/dist/tests/shield-realproof.test.d.ts +0 -1
  283. package/dist/tests/shield-realproof.test.js +0 -272
  284. package/dist/tests/shield.test.d.ts +0 -1
  285. package/dist/tests/shield.test.js +0 -403
  286. package/dist/tests/utxo.test.d.ts +0 -1
  287. package/dist/tests/utxo.test.js +0 -140
  288. package/poseidon.d.ts +0 -2
  289. package/poseidon.js +0 -4
  290. package/proof.d.ts +0 -2
  291. package/proof.js +0 -4
  292. package/prover.d.ts +0 -2
  293. package/prover.js +0 -4
  294. package/shield.d.ts +0 -2
  295. package/shield.js +0 -4
  296. /package/dist/{src/shield → cjs/proofs}/types.js +0 -0
@@ -1,235 +1 @@
1
- import { PublicKey } from "@solana/web3.js";
2
- /**
3
- * Keypair for UTXO ownership.
4
- * Public key is derived via Poseidon: pubkey = Poseidon(privateKey)
5
- */
6
- export type Keypair = {
7
- privateKey: bigint;
8
- publicKey: bigint;
9
- };
10
- /**
11
- * UTXO structure matching the circuit's UTXOCommitment template.
12
- * commitment = Poseidon(amount, pubkey, blinding, mintAddress)
13
- */
14
- export type UTXO = {
15
- /** Amount in lamports/token units */
16
- amount: bigint;
17
- /** Owner's public key (derived from private key via Poseidon) */
18
- pubkey: bigint;
19
- /** Random blinding factor for commitment privacy */
20
- blinding: bigint;
21
- /** Token mint address as field element */
22
- mintAddress: bigint;
23
- };
24
- /**
25
- * Serialized UTXO with precomputed commitment and optional ownership data.
26
- */
27
- export type SerializedUTXO = UTXO & {
28
- /** 32-byte commitment: Poseidon(amount, pubkey, blinding, mintAddress) */
29
- commitment: Uint8Array;
30
- /** Private key for spending (only present for owned UTXOs) */
31
- privateKey?: bigint;
32
- /** Leaf index in the Merkle tree (set after insertion) */
33
- pathIndex?: number;
34
- };
35
- /**
36
- * Input UTXO with Merkle proof data for spending.
37
- */
38
- export type InputUTXO = SerializedUTXO & {
39
- /** Leaf index in the Merkle tree */
40
- pathIndex: number;
41
- /** Merkle path elements (sibling hashes from leaf to root) */
42
- pathElements: Uint8Array[];
43
- /** Private key for nullifier derivation */
44
- privateKey: bigint;
45
- };
46
- /**
47
- * Generate a random keypair.
48
- * Private key is a random 32-byte scalar.
49
- * Public key is derived via Poseidon: pubkey = Poseidon(privateKey)
50
- */
51
- export declare function generateKeypair(): Keypair;
52
- /**
53
- * Derive public key from private key.
54
- * Matches circuit's Keypair template: publicKey = Poseidon(privateKey)
55
- */
56
- export declare function derivePublicKey(privateKey: bigint): bigint;
57
- /**
58
- * Create keypair from a known private key.
59
- */
60
- export declare function keypairFromPrivateKey(privateKey: bigint): Keypair;
61
- /**
62
- * Compute UTXO commitment.
63
- * Matches circuit's UTXOCommitment template:
64
- * commitment = Poseidon(amount, pubkey, blinding, mintAddress)
65
- */
66
- export declare function commitUTXO(utxo: UTXO): Uint8Array;
67
- /**
68
- * Create a random UTXO with the given parameters.
69
- */
70
- export declare function createUTXO(params: {
71
- amount: bigint;
72
- pubkey: bigint;
73
- mintAddress: PublicKey;
74
- }): SerializedUTXO;
75
- /**
76
- * Create a UTXO with a specified private key (for owned UTXOs).
77
- */
78
- export declare function createOwnedUTXO(params: {
79
- amount: bigint;
80
- privateKey: bigint;
81
- mintAddress: PublicKey;
82
- }): SerializedUTXO;
83
- /**
84
- * Create a zero UTXO (for deposits where no input exists).
85
- * Zero UTXOs have amount=0 and are used as placeholders in 2-in-2-out transactions.
86
- */
87
- export declare function createZeroUTXO(pubkey: bigint, mintAddress: PublicKey): SerializedUTXO;
88
- /**
89
- * Create a zero UTXO with private key (for owned zero UTXOs).
90
- */
91
- export declare function createOwnedZeroUTXO(privateKey: bigint, mintAddress: PublicKey): SerializedUTXO;
92
- /**
93
- * Compute signature for nullifier derivation.
94
- * Matches circuit's Signature template:
95
- * signature = Poseidon(privateKey, commitment, pathIndex)
96
- */
97
- export declare function computeSignature(privateKey: bigint, commitment: bigint, pathIndex: bigint): bigint;
98
- /**
99
- * Derive nullifier for a UTXO.
100
- * Matches circuit's UTXONullifier template:
101
- * signature = Poseidon(privateKey, commitment, pathIndex)
102
- * nullifier = Poseidon(commitment, pathIndex, signature)
103
- *
104
- * The signature-based nullifier ensures only the private key holder can spend.
105
- */
106
- export declare function deriveNullifier(utxo: SerializedUTXO, pathIndex: number, privateKey: bigint): Uint8Array;
107
- /**
108
- * Convert InputUTXO to the format expected by the circuit.
109
- */
110
- export declare function inputUTXOToCircuitFormat(input: InputUTXO): {
111
- amount: bigint;
112
- pubkey: bigint;
113
- blinding: bigint;
114
- pathElements: bigint[];
115
- pathIndex: number;
116
- privateKey: bigint;
117
- };
118
- /**
119
- * Encrypted UTXO note — can be broadcast alongside a transaction so the
120
- * recipient can recover their note without a server.
121
- */
122
- export type EncryptedNote = {
123
- /** 24-byte NaCl box nonce */
124
- nonce: Uint8Array;
125
- /** Ciphertext containing amount + blinding + privateKey */
126
- ciphertext: Uint8Array;
127
- /** Sender's ephemeral 32-byte X25519 public key */
128
- senderEphemeralPubkey: Uint8Array;
129
- };
130
- /**
131
- * Derive a NaCl X25519 encryption keypair from a UTXO private key.
132
- * The keypair is deterministic: same privateKey always yields the same pair.
133
- */
134
- export declare function deriveEncryptionKeypair(privateKey: bigint): {
135
- publicKey: Uint8Array;
136
- secretKey: Uint8Array;
137
- };
138
- /**
139
- * Encrypt a UTXO so the recipient can recover it from on-chain events.
140
- *
141
- * Plaintext layout (72 bytes):
142
- * [0..8] amount — 8-byte little-endian u64
143
- * [8..40] blinding — 32-byte big-endian field element
144
- * [40..72] privateKey — 32-byte big-endian field element
145
- *
146
- * Uses ephemeral-key NaCl box so the sender key is single-use.
147
- */
148
- export declare function encryptUTXONote(utxo: SerializedUTXO & {
149
- privateKey: bigint;
150
- }, recipientEncPubkey: Uint8Array): EncryptedNote;
151
- /**
152
- * Try to decrypt an encrypted UTXO note using the recipient's private key.
153
- * Returns the SerializedUTXO if decryption succeeds and the commitment
154
- * matches, or `null` if the note was not intended for this key.
155
- */
156
- export declare function decryptUTXONote(note: EncryptedNote, recipientPrivateKey: bigint, commitment: Uint8Array, mintAddress: PublicKey): SerializedUTXO | null;
157
- /** Note data stored inside a Blind Mailbox encrypted blob */
158
- export type BlindMailboxNoteData = {
159
- blinding: Uint8Array;
160
- leafIndex: number;
161
- commitment: Uint8Array;
162
- amount: bigint;
163
- mintAddress: string;
164
- treeId: number;
165
- };
166
- /** Encrypted note as returned by the relayer's /api/notes endpoint */
167
- export type BlindMailboxNote = {
168
- commitment: string;
169
- ephemeralPublicKey: string;
170
- encryptedBlob: string;
171
- timestamp?: number;
172
- blockHeight?: number;
173
- txSignature?: string;
174
- };
175
- /** Decrypted note data after calling decryptBlindMailboxNote */
176
- export type DecryptedNote = {
177
- blinding: Uint8Array;
178
- leafIndex: number;
179
- commitment: Uint8Array;
180
- amount: bigint;
181
- timestamp: number;
182
- mintAddress?: string;
183
- treeId: number;
184
- };
185
- /** Derive 32-byte encryption key from a shared secret using SHA-512 truncated.
186
- * Must match the production "sha256" helper which uses nacl.hash (SHA-512) [0:32].
187
- *
188
- * DO NOT "fix" this to real SHA-256. The name in the sibling implementations
189
- * (`sha256ForNotes`) is a misnomer, but the bytes are load-bearing: changing the
190
- * KDF makes every historical note undecryptable.
191
- *
192
- * @internal Exported for `compactNote.ts`. Not part of the stable public API. */
193
- export declare function kdfSHA512_256(secret: Uint8Array): Uint8Array;
194
- /** Convert an Ed25519 private seed (32 bytes) to an X25519 scalar.
195
- * Equivalent to ed2curve.convertSecretKey(seed).
196
- *
197
- * @internal Exported for `compactNote.ts`. Not part of the stable public API. */
198
- export declare function ed25519SeedToX25519Private(seed: Uint8Array): Uint8Array;
199
- /** Convert an Ed25519 compressed public key (32 bytes) to X25519.
200
- * Equivalent to ed2curve.convertPublicKey(pubkey).
201
- * Edwards y-coord → Montgomery u via: u = (1 + y) / (1 - y) (mod p).
202
- *
203
- * @internal Exported for `compactNote.ts`. Not part of the stable public API. */
204
- export declare function ed25519PublicKeyToX25519(pubkey: Uint8Array): Uint8Array;
205
- /**
206
- * Encrypt a UTXO note for a recipient identified by their Solana wallet public key.
207
- * Produces a blob the relayer will store and serve via POST /notes/save.
208
- *
209
- * @param recipientWalletPubkey 32-byte Ed25519 public key (wallet.publicKey.toBytes())
210
- * @param noteData UTXO details to encrypt
211
- */
212
- export declare function encryptBlindMailboxNote(recipientWalletPubkey: Uint8Array, noteData: BlindMailboxNoteData): {
213
- ephemeralPublicKey: Uint8Array;
214
- encryptedBlob: string;
215
- };
216
- /**
217
- * Decrypt a Blind Mailbox note using the recipient's Solana wallet private seed.
218
- *
219
- * @param walletSecretKey Full 64-byte wallet.secretKey — the first 32 bytes are the seed
220
- * @param ephemeralPublicKey 32-byte raw public key stored alongside the encrypted blob.
221
- * This may be either an Ed25519 pubkey (from Keypair.generate())
222
- * or a raw X25519 pubkey — the decryption path handles both:
223
- * if it is an Ed25519 key it is converted; otherwise used directly.
224
- * @param encryptedBlob Base64 string as stored by the relayer
225
- */
226
- export declare function decryptBlindMailboxNote(walletSecretKey: Uint8Array, ephemeralPublicKey: Uint8Array, encryptedBlob: string): DecryptedNote;
227
- /**
228
- * Fetch all encrypted notes for a wallet from the relayer's Blind Mailbox endpoint
229
- * and decrypt them using the wallet's secret key.
230
- *
231
- * @param walletPublicKey Base58 wallet address used to query the relayer
232
- * @param walletSecretKey Full 64-byte keypair.secretKey for decryption
233
- * @param relayerUrl Relayer base URL (e.g. "https://relay.veilo.app")
234
- */
235
- export declare function fetchAndDecryptNotes(walletPublicKey: string, walletSecretKey: Uint8Array, relayerUrl: string): Promise<DecryptedNote[]>;
1
+ export * from "./notes/index.js";
package/dist/cjs/utxo.js CHANGED
@@ -1,407 +1,18 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
4
15
  };
5
16
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.generateKeypair = generateKeypair;
7
- exports.derivePublicKey = derivePublicKey;
8
- exports.keypairFromPrivateKey = keypairFromPrivateKey;
9
- exports.commitUTXO = commitUTXO;
10
- exports.createUTXO = createUTXO;
11
- exports.createOwnedUTXO = createOwnedUTXO;
12
- exports.createZeroUTXO = createZeroUTXO;
13
- exports.createOwnedZeroUTXO = createOwnedZeroUTXO;
14
- exports.computeSignature = computeSignature;
15
- exports.deriveNullifier = deriveNullifier;
16
- exports.inputUTXOToCircuitFormat = inputUTXOToCircuitFormat;
17
- exports.deriveEncryptionKeypair = deriveEncryptionKeypair;
18
- exports.encryptUTXONote = encryptUTXONote;
19
- exports.decryptUTXONote = decryptUTXONote;
20
- exports.kdfSHA512_256 = kdfSHA512_256;
21
- exports.ed25519SeedToX25519Private = ed25519SeedToX25519Private;
22
- exports.ed25519PublicKeyToX25519 = ed25519PublicKeyToX25519;
23
- exports.encryptBlindMailboxNote = encryptBlindMailboxNote;
24
- exports.decryptBlindMailboxNote = decryptBlindMailboxNote;
25
- exports.fetchAndDecryptNotes = fetchAndDecryptNotes;
26
- const random_js_1 = require("./random.js");
27
- const tweetnacl_1 = __importDefault(require("tweetnacl"));
28
- const sha256_1 = require("@noble/hashes/sha256");
29
- const poseidon_js_1 = require("./poseidon.js");
30
- // -----------------------------------------------------------------------------
31
- // Keypair Functions
32
- // -----------------------------------------------------------------------------
33
- /**
34
- * Generate a random keypair.
35
- * Private key is a random 32-byte scalar.
36
- * Public key is derived via Poseidon: pubkey = Poseidon(privateKey)
37
- */
38
- function generateKeypair() {
39
- const privateKeyBytes = new Uint8Array((0, random_js_1.randomBytes)(32));
40
- const privateKey = (0, poseidon_js_1.bytesToBigIntBE)(privateKeyBytes) % poseidon_js_1.BN254_FR_MODULUS;
41
- const publicKey = derivePublicKey(privateKey);
42
- return { privateKey, publicKey };
43
- }
44
- /**
45
- * Derive public key from private key.
46
- * Matches circuit's Keypair template: publicKey = Poseidon(privateKey)
47
- */
48
- function derivePublicKey(privateKey) {
49
- return (0, poseidon_js_1.poseidon1)(privateKey);
50
- }
51
- /**
52
- * Create keypair from a known private key.
53
- */
54
- function keypairFromPrivateKey(privateKey) {
55
- return {
56
- privateKey: privateKey % poseidon_js_1.BN254_FR_MODULUS,
57
- publicKey: derivePublicKey(privateKey % poseidon_js_1.BN254_FR_MODULUS),
58
- };
59
- }
60
- // -----------------------------------------------------------------------------
61
- // UTXO Commitment Functions
62
- // -----------------------------------------------------------------------------
63
- /**
64
- * Compute UTXO commitment.
65
- * Matches circuit's UTXOCommitment template:
66
- * commitment = Poseidon(amount, pubkey, blinding, mintAddress)
67
- */
68
- function commitUTXO(utxo) {
69
- const commitment = (0, poseidon_js_1.poseidon4)(utxo.amount, utxo.pubkey, utxo.blinding, utxo.mintAddress);
70
- return (0, poseidon_js_1.bigIntToBytesBE)(commitment);
71
- }
72
- /**
73
- * Create a random UTXO with the given parameters.
74
- */
75
- function createUTXO(params) {
76
- const blindingBytes = new Uint8Array((0, random_js_1.randomBytes)(32));
77
- const blinding = (0, poseidon_js_1.bytesToBigIntBE)(blindingBytes) % poseidon_js_1.BN254_FR_MODULUS;
78
- const utxo = {
79
- amount: params.amount,
80
- pubkey: params.pubkey,
81
- blinding,
82
- mintAddress: (0, poseidon_js_1.pubkeyToField)(params.mintAddress),
83
- };
84
- const commitment = commitUTXO(utxo);
85
- return {
86
- ...utxo,
87
- commitment,
88
- };
89
- }
90
- /**
91
- * Create a UTXO with a specified private key (for owned UTXOs).
92
- */
93
- function createOwnedUTXO(params) {
94
- const keypair = keypairFromPrivateKey(params.privateKey);
95
- const utxo = createUTXO({
96
- amount: params.amount,
97
- pubkey: keypair.publicKey,
98
- mintAddress: params.mintAddress,
99
- });
100
- return {
101
- ...utxo,
102
- privateKey: keypair.privateKey,
103
- };
104
- }
105
- /**
106
- * Create a zero UTXO (for deposits where no input exists).
107
- * Zero UTXOs have amount=0 and are used as placeholders in 2-in-2-out transactions.
108
- */
109
- function createZeroUTXO(pubkey, mintAddress) {
110
- return createUTXO({
111
- amount: 0n,
112
- pubkey,
113
- mintAddress,
114
- });
115
- }
116
- /**
117
- * Create a zero UTXO with private key (for owned zero UTXOs).
118
- */
119
- function createOwnedZeroUTXO(privateKey, mintAddress) {
120
- const keypair = keypairFromPrivateKey(privateKey);
121
- const utxo = createZeroUTXO(keypair.publicKey, mintAddress);
122
- return {
123
- ...utxo,
124
- privateKey: keypair.privateKey,
125
- };
126
- }
127
- // -----------------------------------------------------------------------------
128
- // Nullifier Functions
129
- // -----------------------------------------------------------------------------
130
- /**
131
- * Compute signature for nullifier derivation.
132
- * Matches circuit's Signature template:
133
- * signature = Poseidon(privateKey, commitment, pathIndex)
134
- */
135
- function computeSignature(privateKey, commitment, pathIndex) {
136
- return (0, poseidon_js_1.poseidon3)(privateKey, commitment, pathIndex);
137
- }
138
- /**
139
- * Derive nullifier for a UTXO.
140
- * Matches circuit's UTXONullifier template:
141
- * signature = Poseidon(privateKey, commitment, pathIndex)
142
- * nullifier = Poseidon(commitment, pathIndex, signature)
143
- *
144
- * The signature-based nullifier ensures only the private key holder can spend.
145
- */
146
- function deriveNullifier(utxo, pathIndex, privateKey) {
147
- const commitment = (0, poseidon_js_1.bytesToBigIntBE)(utxo.commitment) % poseidon_js_1.BN254_FR_MODULUS;
148
- const pathIndexField = BigInt(pathIndex) % poseidon_js_1.BN254_FR_MODULUS;
149
- const signature = computeSignature(privateKey, commitment, pathIndexField);
150
- const nullifier = (0, poseidon_js_1.poseidon3)(commitment, pathIndexField, signature);
151
- return (0, poseidon_js_1.bigIntToBytesBE)(nullifier);
152
- }
153
- /**
154
- * Convert InputUTXO to the format expected by the circuit.
155
- */
156
- function inputUTXOToCircuitFormat(input) {
157
- return {
158
- amount: input.amount,
159
- pubkey: input.pubkey,
160
- blinding: input.blinding,
161
- pathElements: input.pathElements.map((e) => (0, poseidon_js_1.bytesToBigIntBE)(e) % poseidon_js_1.BN254_FR_MODULUS),
162
- pathIndex: input.pathIndex,
163
- privateKey: input.privateKey,
164
- };
165
- }
166
- /**
167
- * Derive a NaCl X25519 encryption keypair from a UTXO private key.
168
- * The keypair is deterministic: same privateKey always yields the same pair.
169
- */
170
- function deriveEncryptionKeypair(privateKey) {
171
- const seed = (0, sha256_1.sha256)((0, poseidon_js_1.bigIntToBytesBE)(privateKey));
172
- return tweetnacl_1.default.box.keyPair.fromSecretKey(seed);
173
- }
174
- /**
175
- * Encrypt a UTXO so the recipient can recover it from on-chain events.
176
- *
177
- * Plaintext layout (72 bytes):
178
- * [0..8] amount — 8-byte little-endian u64
179
- * [8..40] blinding — 32-byte big-endian field element
180
- * [40..72] privateKey — 32-byte big-endian field element
181
- *
182
- * Uses ephemeral-key NaCl box so the sender key is single-use.
183
- */
184
- function encryptUTXONote(utxo, recipientEncPubkey) {
185
- const nonce = tweetnacl_1.default.randomBytes(tweetnacl_1.default.box.nonceLength); // 24 bytes
186
- const ephemeral = tweetnacl_1.default.box.keyPair();
187
- const amountBuf = new Uint8Array(8);
188
- let v = utxo.amount;
189
- for (let i = 0; i < 8; i++) {
190
- amountBuf[i] = Number(v & 0xffn);
191
- v >>= 8n;
192
- }
193
- const plaintext = new Uint8Array(72);
194
- plaintext.set(amountBuf, 0);
195
- plaintext.set((0, poseidon_js_1.bigIntToBytesBE)(utxo.blinding), 8);
196
- plaintext.set((0, poseidon_js_1.bigIntToBytesBE)(utxo.privateKey), 40);
197
- const sharedKey = tweetnacl_1.default.box.before(recipientEncPubkey, ephemeral.secretKey);
198
- const ciphertext = tweetnacl_1.default.box.after(plaintext, nonce, sharedKey);
199
- return { nonce, ciphertext, senderEphemeralPubkey: ephemeral.publicKey };
200
- }
201
- /**
202
- * Try to decrypt an encrypted UTXO note using the recipient's private key.
203
- * Returns the SerializedUTXO if decryption succeeds and the commitment
204
- * matches, or `null` if the note was not intended for this key.
205
- */
206
- function decryptUTXONote(note, recipientPrivateKey, commitment, mintAddress) {
207
- const { secretKey } = deriveEncryptionKeypair(recipientPrivateKey);
208
- const sharedKey = tweetnacl_1.default.box.before(note.senderEphemeralPubkey, secretKey);
209
- const plaintext = tweetnacl_1.default.box.open.after(note.ciphertext, note.nonce, sharedKey);
210
- if (!plaintext || plaintext.length < 72)
211
- return null;
212
- let amount = 0n;
213
- for (let i = 7; i >= 0; i--)
214
- amount = (amount << 8n) | BigInt(plaintext[i]);
215
- const blinding = (0, poseidon_js_1.bytesToBigIntBE)(plaintext.slice(8, 40)) % poseidon_js_1.BN254_FR_MODULUS;
216
- const privateKey = (0, poseidon_js_1.bytesToBigIntBE)(plaintext.slice(40, 72)) % poseidon_js_1.BN254_FR_MODULUS;
217
- const pubkey = derivePublicKey(privateKey);
218
- const utxo = {
219
- amount,
220
- pubkey,
221
- blinding,
222
- mintAddress: (0, poseidon_js_1.pubkeyToField)(mintAddress),
223
- };
224
- const expectedCommitment = commitUTXO(utxo);
225
- if (!expectedCommitment.every((b, i) => b === commitment[i]))
226
- return null;
227
- return { ...utxo, commitment, privateKey };
228
- }
229
- // -- Internal crypto helpers (no extra dependencies) --------------------------
230
- /** Derive 32-byte encryption key from a shared secret using SHA-512 truncated.
231
- * Must match the production "sha256" helper which uses nacl.hash (SHA-512) [0:32].
232
- *
233
- * DO NOT "fix" this to real SHA-256. The name in the sibling implementations
234
- * (`sha256ForNotes`) is a misnomer, but the bytes are load-bearing: changing the
235
- * KDF makes every historical note undecryptable.
236
- *
237
- * @internal Exported for `compactNote.ts`. Not part of the stable public API. */
238
- function kdfSHA512_256(secret) {
239
- return tweetnacl_1.default.hash(secret).slice(0, 32);
240
- }
241
- /** Convert an Ed25519 private seed (32 bytes) to an X25519 scalar.
242
- * Equivalent to ed2curve.convertSecretKey(seed).
243
- *
244
- * @internal Exported for `compactNote.ts`. Not part of the stable public API. */
245
- function ed25519SeedToX25519Private(seed) {
246
- const h = tweetnacl_1.default.hash(seed); // SHA-512
247
- const scalar = h.slice(0, 32);
248
- scalar[0] &= 248;
249
- scalar[31] &= 127;
250
- scalar[31] |= 64;
251
- return scalar;
252
- }
253
- const P25519 = (1n << 255n) - 19n;
254
- function modpow25519(b, e) {
255
- let r = 1n;
256
- b = b % P25519;
257
- while (e > 0n) {
258
- if (e & 1n)
259
- r = (r * b) % P25519;
260
- e >>= 1n;
261
- b = (b * b) % P25519;
262
- }
263
- return r;
264
- }
265
- /** Convert an Ed25519 compressed public key (32 bytes) to X25519.
266
- * Equivalent to ed2curve.convertPublicKey(pubkey).
267
- * Edwards y-coord → Montgomery u via: u = (1 + y) / (1 - y) (mod p).
268
- *
269
- * @internal Exported for `compactNote.ts`. Not part of the stable public API. */
270
- function ed25519PublicKeyToX25519(pubkey) {
271
- const pk = new Uint8Array(pubkey);
272
- pk[31] &= 0x7f; // clear sign bit to get y as LE integer
273
- // Decode little-endian y
274
- let y = 0n;
275
- for (let i = 31; i >= 0; i--)
276
- y = (y << 8n) | BigInt(pk[i]);
277
- // u = (1 + y) / (1 - y) mod p
278
- const num = (1n + y) % P25519;
279
- const den = (((1n - y) % P25519) + P25519) % P25519;
280
- const u = (num * modpow25519(den, P25519 - 2n)) % P25519;
281
- // Encode as 32-byte LE
282
- const out = new Uint8Array(32);
283
- let v = u;
284
- for (let i = 0; i < 32; i++) {
285
- out[i] = Number(v & 0xffn);
286
- v >>= 8n;
287
- }
288
- return out;
289
- }
290
- // -- Public API ---------------------------------------------------------------
291
- /**
292
- * Encrypt a UTXO note for a recipient identified by their Solana wallet public key.
293
- * Produces a blob the relayer will store and serve via POST /notes/save.
294
- *
295
- * @param recipientWalletPubkey 32-byte Ed25519 public key (wallet.publicKey.toBytes())
296
- * @param noteData UTXO details to encrypt
297
- */
298
- function encryptBlindMailboxNote(recipientWalletPubkey, noteData) {
299
- // 1. Generate ephemeral Ed25519 keypair seed
300
- const ephemeralSeed = (0, random_js_1.randomBytes)(32);
301
- // Ed25519 public key stored by relayer; dapp recovers X25519 via ed2curve.convertPublicKey()
302
- const ephemeralEdPublicKey = tweetnacl_1.default.sign.keyPair.fromSeed(new Uint8Array(ephemeralSeed)).publicKey;
303
- // X25519 scalar (ed2curve.convertSecretKey equivalent)
304
- const ephemeralX25519Private = ed25519SeedToX25519Private(new Uint8Array(ephemeralSeed));
305
- // X25519 public key (ed2curve.convertPublicKey equivalent)
306
- const recipientX25519Public = ed25519PublicKeyToX25519(recipientWalletPubkey);
307
- const sharedSecret = tweetnacl_1.default.scalarMult(ephemeralX25519Private, recipientX25519Public);
308
- const key = kdfSHA512_256(sharedSecret);
309
- // JSON format matches production relayer notes schema
310
- const hexArr = (b) => Array.from(b)
311
- .map((x) => x.toString(16).padStart(2, "0"))
312
- .join("");
313
- const noteJson = JSON.stringify({
314
- blinding: hexArr(noteData.blinding),
315
- leafIndex: noteData.leafIndex,
316
- commitment: hexArr(noteData.commitment),
317
- amount: noteData.amount.toString(),
318
- mintAddress: noteData.mintAddress,
319
- timestamp: Date.now(),
320
- treeId: noteData.treeId,
321
- });
322
- const nonce = tweetnacl_1.default.randomBytes(24);
323
- const plaintext = new TextEncoder().encode(noteJson);
324
- const encrypted = tweetnacl_1.default.secretbox(plaintext, nonce, key);
325
- const combined = new Uint8Array(nonce.length + encrypted.length);
326
- combined.set(nonce);
327
- combined.set(encrypted, nonce.length);
328
- const encryptedBlob = Buffer.from(combined).toString("base64");
329
- // Return Ed25519 public key (dapp calls ed2curve.convertPublicKey() to recover X25519)
330
- return { ephemeralPublicKey: ephemeralEdPublicKey, encryptedBlob };
331
- }
332
- /**
333
- * Decrypt a Blind Mailbox note using the recipient's Solana wallet private seed.
334
- *
335
- * @param walletSecretKey Full 64-byte wallet.secretKey — the first 32 bytes are the seed
336
- * @param ephemeralPublicKey 32-byte raw public key stored alongside the encrypted blob.
337
- * This may be either an Ed25519 pubkey (from Keypair.generate())
338
- * or a raw X25519 pubkey — the decryption path handles both:
339
- * if it is an Ed25519 key it is converted; otherwise used directly.
340
- * @param encryptedBlob Base64 string as stored by the relayer
341
- */
342
- function decryptBlindMailboxNote(walletSecretKey, ephemeralPublicKey, encryptedBlob) {
343
- // 1. Derive recipient X25519 from Ed25519 seed
344
- const seed = walletSecretKey.slice(0, 32);
345
- const myX25519Private = ed25519SeedToX25519Private(seed);
346
- // ephemeralPublicKey may be an Ed25519 pubkey (dapp's Keypair.generate()) or raw X25519;
347
- // try Ed25519→X25519 conversion first, fall back to using it directly.
348
- let theirPublic;
349
- try {
350
- theirPublic = ed25519PublicKeyToX25519(ephemeralPublicKey);
351
- }
352
- catch {
353
- theirPublic = ephemeralPublicKey; // already X25519
354
- }
355
- const sharedSecret = tweetnacl_1.default.scalarMult(myX25519Private, theirPublic);
356
- const key = kdfSHA512_256(sharedSecret);
357
- const combined = Buffer.from(encryptedBlob, "base64");
358
- const nonce = combined.slice(0, 24);
359
- const ciphertext = combined.slice(24);
360
- const decrypted = tweetnacl_1.default.secretbox.open(new Uint8Array(ciphertext), new Uint8Array(nonce), key);
361
- if (!decrypted) {
362
- throw new Error("decryptBlindMailboxNote: decryption failed — wrong key or corrupted blob");
363
- }
364
- const parsed = JSON.parse(new TextDecoder().decode(decrypted));
365
- const hexToBytes = (hex) => {
366
- const out = new Uint8Array(hex.length / 2);
367
- for (let i = 0; i < hex.length; i += 2)
368
- out[i / 2] = parseInt(hex.slice(i, i + 2), 16);
369
- return out;
370
- };
371
- return {
372
- blinding: hexToBytes(parsed.blinding),
373
- leafIndex: parsed.leafIndex,
374
- commitment: hexToBytes(parsed.commitment),
375
- amount: BigInt(parsed.amount),
376
- timestamp: parsed.timestamp ?? 0,
377
- mintAddress: parsed.mintAddress,
378
- treeId: parsed.treeId,
379
- };
380
- }
381
- /**
382
- * Fetch all encrypted notes for a wallet from the relayer's Blind Mailbox endpoint
383
- * and decrypt them using the wallet's secret key.
384
- *
385
- * @param walletPublicKey Base58 wallet address used to query the relayer
386
- * @param walletSecretKey Full 64-byte keypair.secretKey for decryption
387
- * @param relayerUrl Relayer base URL (e.g. "https://relay.veilo.app")
388
- */
389
- async function fetchAndDecryptNotes(walletPublicKey, walletSecretKey, relayerUrl) {
390
- const resp = await fetch(`${relayerUrl}/api/notes?recipientPublicKey=${walletPublicKey}`);
391
- if (!resp.ok) {
392
- throw new Error(`fetchAndDecryptNotes: ${resp.status} ${resp.statusText}`);
393
- }
394
- const { notes } = (await resp.json());
395
- const results = [];
396
- for (const note of notes) {
397
- try {
398
- const epk = Buffer.from(note.ephemeralPublicKey, "base64");
399
- const decrypted = decryptBlindMailboxNote(walletSecretKey, new Uint8Array(epk), note.encryptedBlob);
400
- results.push(decrypted);
401
- }
402
- catch {
403
- // Note not for this key or corrupted — skip silently
404
- }
405
- }
406
- return results;
407
- }
17
+ // Backward-compatible entry point. Note responsibilities live in src/notes.
18
+ __exportStar(require("./notes/index.js"), exports);