@veilo/sdk-core 0.5.0 → 0.6.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 (236) hide show
  1. package/README.md +237 -19
  2. package/accounts.d.ts +2 -0
  3. package/accounts.js +3 -0
  4. package/cloak.d.ts +2 -0
  5. package/cloak.js +3 -0
  6. package/config.d.ts +2 -0
  7. package/config.js +3 -0
  8. package/dist/cjs/events/index.d.ts +6 -0
  9. package/dist/cjs/events/index.js +22 -0
  10. package/dist/cjs/events/parsing.d.ts +25 -0
  11. package/dist/cjs/events/parsing.js +158 -0
  12. package/dist/cjs/events/position.d.ts +26 -0
  13. package/dist/cjs/events/position.js +53 -0
  14. package/dist/cjs/events/recovery.d.ts +87 -0
  15. package/dist/cjs/events/recovery.js +281 -0
  16. package/dist/cjs/events/scanning.d.ts +35 -0
  17. package/dist/cjs/events/scanning.js +98 -0
  18. package/dist/cjs/events/tree.d.ts +27 -0
  19. package/dist/cjs/events/tree.js +63 -0
  20. package/dist/cjs/events/types.d.ts +39 -0
  21. package/dist/cjs/events/types.js +2 -0
  22. package/dist/cjs/events.d.ts +1 -77
  23. package/dist/cjs/events.js +6 -154
  24. package/dist/cjs/identity/encoding.d.ts +9 -0
  25. package/dist/cjs/identity/encoding.js +85 -0
  26. package/dist/cjs/identity/index.d.ts +4 -0
  27. package/dist/cjs/identity/index.js +20 -0
  28. package/dist/cjs/identity/noteKey.d.ts +33 -0
  29. package/dist/cjs/identity/noteKey.js +97 -0
  30. package/dist/cjs/identity/spending.d.ts +18 -0
  31. package/dist/cjs/identity/spending.js +46 -0
  32. package/dist/cjs/identity/viewKey.d.ts +38 -0
  33. package/dist/cjs/identity/viewKey.js +105 -0
  34. package/dist/cjs/idl/index.d.ts +18 -0
  35. package/dist/cjs/idl/index.js +24 -0
  36. package/dist/cjs/idl/privacy_pool.json +9907 -9907
  37. package/dist/cjs/idl/privacy_pool_legacy.d.ts +5 -0
  38. package/dist/cjs/idl/privacy_pool_legacy.js +3307 -0
  39. package/dist/cjs/idl/privacy_pool_legacy.json +2302 -0
  40. package/dist/cjs/idl/privacy_pool_legacy2.d.ts +5 -0
  41. package/dist/cjs/idl/privacy_pool_legacy2.js +3397 -0
  42. package/dist/cjs/idl/privacy_pool_legacy2.json +2376 -0
  43. package/dist/cjs/index.d.ts +8 -3
  44. package/dist/cjs/index.js +12 -2
  45. package/dist/cjs/notes/amount.d.ts +2 -0
  46. package/dist/cjs/notes/amount.js +21 -0
  47. package/dist/cjs/notes/index.d.ts +3 -0
  48. package/dist/cjs/notes/index.js +3 -0
  49. package/dist/cjs/notes/recovery.d.ts +16 -6
  50. package/dist/cjs/notes/recovery.js +33 -16
  51. package/dist/cjs/notes/selection.d.ts +77 -0
  52. package/dist/cjs/notes/selection.js +193 -0
  53. package/dist/cjs/notes/spent.d.ts +60 -0
  54. package/dist/cjs/notes/spent.js +101 -0
  55. package/dist/cjs/perps/constants.d.ts +16 -0
  56. package/dist/cjs/perps/constants.js +52 -0
  57. package/dist/cjs/perps/index.d.ts +5 -0
  58. package/dist/cjs/perps/index.js +21 -0
  59. package/dist/cjs/perps/keys.d.ts +16 -0
  60. package/dist/cjs/perps/keys.js +43 -0
  61. package/dist/cjs/perps/pdas.d.ts +29 -0
  62. package/dist/cjs/perps/pdas.js +55 -0
  63. package/dist/cjs/perps/relayer.d.ts +9 -0
  64. package/dist/cjs/perps/relayer.js +35 -0
  65. package/dist/cjs/perps/types.d.ts +126 -0
  66. package/dist/cjs/perps/types.js +2 -0
  67. package/dist/cjs/positions/index.d.ts +4 -0
  68. package/dist/cjs/positions/index.js +20 -0
  69. package/dist/cjs/positions/keys.d.ts +29 -0
  70. package/dist/cjs/positions/keys.js +71 -0
  71. package/dist/cjs/positions/pdas.d.ts +15 -0
  72. package/dist/cjs/positions/pdas.js +54 -0
  73. package/dist/cjs/positions/relayer.d.ts +4 -0
  74. package/dist/cjs/positions/relayer.js +15 -0
  75. package/dist/cjs/positions/types.d.ts +97 -0
  76. package/dist/cjs/positions/types.js +2 -0
  77. package/dist/cjs/predictions/client.d.ts +41 -0
  78. package/dist/cjs/predictions/client.js +147 -0
  79. package/dist/cjs/predictions/index.d.ts +5 -0
  80. package/dist/cjs/predictions/index.js +21 -0
  81. package/dist/cjs/predictions/keys.d.ts +14 -0
  82. package/dist/cjs/predictions/keys.js +40 -0
  83. package/dist/cjs/predictions/pdas.d.ts +6 -0
  84. package/dist/cjs/predictions/pdas.js +13 -0
  85. package/dist/cjs/predictions/relayer.d.ts +3 -0
  86. package/dist/cjs/predictions/relayer.js +11 -0
  87. package/dist/cjs/predictions/types.d.ts +178 -0
  88. package/dist/cjs/predictions/types.js +2 -0
  89. package/dist/cjs/program.d.ts +2 -0
  90. package/dist/cjs/program.js +8 -7
  91. package/dist/cjs/prover.d.ts +27 -4
  92. package/dist/cjs/prover.js +107 -48
  93. package/dist/cjs/relayer/api.d.ts +31 -0
  94. package/dist/cjs/relayer/api.js +86 -0
  95. package/dist/cjs/relayer/client.d.ts +29 -17
  96. package/dist/cjs/relayer/client.js +72 -17
  97. package/dist/cjs/relayer/errors.d.ts +1 -1
  98. package/dist/cjs/relayer/errors.js +1 -1
  99. package/dist/cjs/relayer/index.d.ts +4 -1
  100. package/dist/cjs/relayer/index.js +1 -1
  101. package/dist/cjs/relayer/internal-config.d.ts +36 -0
  102. package/dist/cjs/relayer/internal-config.js +9 -0
  103. package/dist/cjs/relayer/internal.d.ts +6 -0
  104. package/dist/cjs/relayer/internal.js +14 -0
  105. package/dist/cjs/relayer/transport.d.ts +4 -2
  106. package/dist/cjs/relayer/transport.js +10 -5
  107. package/dist/cjs/relayer/types.d.ts +9 -10
  108. package/dist/cjs/relayer/types.js +1 -1
  109. package/dist/cjs/shield/owner.js +1 -4
  110. package/dist/esm/events/index.d.ts +6 -0
  111. package/dist/esm/events/index.js +6 -0
  112. package/dist/esm/events/parsing.d.ts +25 -0
  113. package/dist/esm/events/parsing.js +120 -0
  114. package/dist/esm/events/position.d.ts +26 -0
  115. package/dist/esm/events/position.js +48 -0
  116. package/dist/esm/events/recovery.d.ts +87 -0
  117. package/dist/esm/events/recovery.js +237 -0
  118. package/dist/esm/events/scanning.d.ts +35 -0
  119. package/dist/esm/events/scanning.js +92 -0
  120. package/dist/esm/events/tree.d.ts +27 -0
  121. package/dist/esm/events/tree.js +58 -0
  122. package/dist/esm/events/types.d.ts +39 -0
  123. package/dist/esm/events/types.js +1 -0
  124. package/dist/esm/events.d.ts +1 -77
  125. package/dist/esm/events.js +3 -129
  126. package/dist/esm/identity/encoding.d.ts +9 -0
  127. package/dist/esm/identity/encoding.js +75 -0
  128. package/dist/esm/identity/index.d.ts +4 -0
  129. package/dist/esm/identity/index.js +4 -0
  130. package/dist/esm/identity/noteKey.d.ts +33 -0
  131. package/dist/esm/identity/noteKey.js +91 -0
  132. package/dist/esm/identity/spending.d.ts +18 -0
  133. package/dist/esm/identity/spending.js +35 -0
  134. package/dist/esm/identity/viewKey.d.ts +38 -0
  135. package/dist/esm/identity/viewKey.js +96 -0
  136. package/dist/esm/idl/index.d.ts +18 -0
  137. package/dist/esm/idl/index.js +18 -0
  138. package/dist/esm/idl/privacy_pool.json +9907 -9907
  139. package/dist/esm/idl/privacy_pool_legacy.d.ts +5 -0
  140. package/dist/esm/idl/privacy_pool_legacy.js +3305 -0
  141. package/dist/esm/idl/privacy_pool_legacy.json +2302 -0
  142. package/dist/esm/idl/privacy_pool_legacy2.d.ts +5 -0
  143. package/dist/esm/idl/privacy_pool_legacy2.js +3395 -0
  144. package/dist/esm/idl/privacy_pool_legacy2.json +2376 -0
  145. package/dist/esm/index.d.ts +8 -3
  146. package/dist/esm/index.js +8 -3
  147. package/dist/esm/notes/amount.d.ts +2 -0
  148. package/dist/esm/notes/amount.js +18 -0
  149. package/dist/esm/notes/index.d.ts +3 -0
  150. package/dist/esm/notes/index.js +3 -0
  151. package/dist/esm/notes/recovery.d.ts +16 -6
  152. package/dist/esm/notes/recovery.js +33 -16
  153. package/dist/esm/notes/selection.d.ts +77 -0
  154. package/dist/esm/notes/selection.js +188 -0
  155. package/dist/esm/notes/spent.d.ts +60 -0
  156. package/dist/esm/notes/spent.js +96 -0
  157. package/dist/esm/perps/constants.d.ts +16 -0
  158. package/dist/esm/perps/constants.js +48 -0
  159. package/dist/esm/perps/index.d.ts +5 -0
  160. package/dist/esm/perps/index.js +5 -0
  161. package/dist/esm/perps/keys.d.ts +16 -0
  162. package/dist/esm/perps/keys.js +35 -0
  163. package/dist/esm/perps/pdas.d.ts +29 -0
  164. package/dist/esm/perps/pdas.js +47 -0
  165. package/dist/esm/perps/relayer.d.ts +9 -0
  166. package/dist/esm/perps/relayer.js +25 -0
  167. package/dist/esm/perps/types.d.ts +126 -0
  168. package/dist/esm/perps/types.js +1 -0
  169. package/dist/esm/positions/index.d.ts +4 -0
  170. package/dist/esm/positions/index.js +4 -0
  171. package/dist/esm/positions/keys.d.ts +29 -0
  172. package/dist/esm/positions/keys.js +65 -0
  173. package/dist/esm/positions/pdas.d.ts +15 -0
  174. package/dist/esm/positions/pdas.js +44 -0
  175. package/dist/esm/positions/relayer.d.ts +4 -0
  176. package/dist/esm/positions/relayer.js +10 -0
  177. package/dist/esm/positions/types.d.ts +97 -0
  178. package/dist/esm/positions/types.js +1 -0
  179. package/dist/esm/predictions/client.d.ts +41 -0
  180. package/dist/esm/predictions/client.js +141 -0
  181. package/dist/esm/predictions/index.d.ts +5 -0
  182. package/dist/esm/predictions/index.js +5 -0
  183. package/dist/esm/predictions/keys.d.ts +14 -0
  184. package/dist/esm/predictions/keys.js +33 -0
  185. package/dist/esm/predictions/pdas.d.ts +6 -0
  186. package/dist/esm/predictions/pdas.js +10 -0
  187. package/dist/esm/predictions/relayer.d.ts +3 -0
  188. package/dist/esm/predictions/relayer.js +7 -0
  189. package/dist/esm/predictions/types.d.ts +178 -0
  190. package/dist/esm/predictions/types.js +1 -0
  191. package/dist/esm/program.d.ts +2 -0
  192. package/dist/esm/program.js +4 -3
  193. package/dist/esm/prover.d.ts +27 -4
  194. package/dist/esm/prover.js +106 -15
  195. package/dist/esm/relayer/api.d.ts +31 -0
  196. package/dist/esm/relayer/api.js +55 -0
  197. package/dist/esm/relayer/client.d.ts +29 -17
  198. package/dist/esm/relayer/client.js +72 -17
  199. package/dist/esm/relayer/errors.d.ts +1 -1
  200. package/dist/esm/relayer/errors.js +1 -1
  201. package/dist/esm/relayer/index.d.ts +4 -1
  202. package/dist/esm/relayer/index.js +1 -1
  203. package/dist/esm/relayer/internal-config.d.ts +36 -0
  204. package/dist/esm/relayer/internal-config.js +6 -0
  205. package/dist/esm/relayer/internal.d.ts +6 -0
  206. package/dist/esm/relayer/internal.js +10 -0
  207. package/dist/esm/relayer/transport.d.ts +4 -2
  208. package/dist/esm/relayer/transport.js +10 -5
  209. package/dist/esm/relayer/types.d.ts +9 -10
  210. package/dist/esm/relayer/types.js +1 -1
  211. package/dist/esm/shield/owner.js +1 -4
  212. package/identity.d.ts +2 -0
  213. package/identity.js +3 -0
  214. package/idl.d.ts +2 -0
  215. package/idl.js +3 -0
  216. package/notes.d.ts +2 -0
  217. package/notes.js +3 -0
  218. package/package.json +85 -3
  219. package/perps.d.ts +2 -0
  220. package/perps.js +3 -0
  221. package/poseidon.d.ts +2 -0
  222. package/poseidon.js +3 -0
  223. package/positions.d.ts +2 -0
  224. package/positions.js +3 -0
  225. package/predictions.d.ts +2 -0
  226. package/predictions.js +3 -0
  227. package/proof.d.ts +2 -0
  228. package/proof.js +3 -0
  229. package/prover.d.ts +2 -0
  230. package/prover.js +3 -0
  231. package/relayer.d.ts +2 -0
  232. package/relayer.js +3 -0
  233. package/shield.d.ts +2 -0
  234. package/shield.js +3 -0
  235. package/transactions.d.ts +2 -0
  236. package/transactions.js +3 -0
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.VEILO_VIEW_KEY_INFO = exports.VEILO_VIEW_KEY_SALT = void 0;
7
+ exports.deriveViewKeypairFromSpendingKey = deriveViewKeypairFromSpendingKey;
8
+ exports.deriveViewKeypairWithSigner = deriveViewKeypairWithSigner;
9
+ exports.openCompactNoteWithViewKey = openCompactNoteWithViewKey;
10
+ /**
11
+ * Derivation of a VIEW-ONLY note decryption key from a spending-key root.
12
+ *
13
+ * ⚠ PROVISIONAL — NOT YET CONSUMED BY ANY NOTE FORMAT.
14
+ * Today's compact note ciphers are ECDH'd to the recipient's *wallet* Ed25519
15
+ * key (see `createCompactNoteCipher`), so nothing on-chain or in the relayer is
16
+ * encrypted to the key this module derives. It exists so the v2 note format —
17
+ * where senders encrypt to a published `viewPublicKey` instead of the wallet
18
+ * key — can be built and tested against a fixed derivation. The labels below
19
+ * become permanent the moment the first note is written under them; until then
20
+ * they are safe to change.
21
+ *
22
+ * WHY THIS EXISTS
23
+ * ---------------
24
+ * Note decryption currently requires the wallet Ed25519 secret, which is the
25
+ * one thing a dapp cannot have. Spend authority, by contrast, is already
26
+ * signature-derived (`./noteKey.js`). So a dapp can reconstruct the ability to
27
+ * spend but not the ability to *read*, and since a spend witness needs each
28
+ * note's amount and blinding, reading gates spending. Publishing a
29
+ * signature-derived `viewPublicKey` and encrypting to it closes that gap.
30
+ *
31
+ * Splitting viewing from spending is the point: `viewSecretKey` decrypts notes
32
+ * and nothing more. It cannot produce a nullifier, so it cannot spend, and it
33
+ * cannot determine on its own whether a note is already spent — a view-only
34
+ * client relies on the relayer's `spent` flag for that.
35
+ *
36
+ * Derivation:
37
+ * viewSecretKey = clamp(HKDF-SHA256(ikm=spendingKey, salt="veilo_view_v1",
38
+ * info="x25519", len=32))
39
+ * viewPublicKey = X25519_base(viewSecretKey)
40
+ *
41
+ * Both salt and info are given explicitly rather than left empty, so a sibling
42
+ * implementation never has to guess how its HKDF library treats an absent salt.
43
+ */
44
+ const hkdf_1 = require("@noble/hashes/hkdf");
45
+ const sha256_1 = require("@noble/hashes/sha256");
46
+ const tweetnacl_1 = __importDefault(require("tweetnacl"));
47
+ const compactNote_js_1 = require("../compactNote.js");
48
+ const mailbox_js_1 = require("../notes/mailbox.js");
49
+ const encoding_js_1 = require("./encoding.js");
50
+ const spending_js_1 = require("./spending.js");
51
+ /** HKDF salt. Provisional — see the header. */
52
+ exports.VEILO_VIEW_KEY_SALT = "veilo_view_v1";
53
+ /** HKDF info. Provisional — see the header. */
54
+ exports.VEILO_VIEW_KEY_INFO = "x25519";
55
+ /**
56
+ * Apply RFC 7748 clamping so the stored scalar is canonical.
57
+ *
58
+ * TweetNaCl clamps internally on every scalar multiplication, so this changes
59
+ * no result; it means the bytes we hand out are the bytes actually used, which
60
+ * keeps a sibling implementation from disagreeing about what was stored.
61
+ */
62
+ function clampX25519(scalar) {
63
+ const clamped = new Uint8Array(scalar);
64
+ clamped[0] &= 248;
65
+ clamped[31] &= 127;
66
+ clamped[31] |= 64;
67
+ return clamped;
68
+ }
69
+ /** Derive the view keypair from a spending-key root. */
70
+ function deriveViewKeypairFromSpendingKey(spendingKey) {
71
+ (0, encoding_js_1.assertBytes)(spendingKey, 32, "spending key");
72
+ const viewSecretKey = clampX25519((0, hkdf_1.hkdf)(sha256_1.sha256, spendingKey, (0, encoding_js_1.utf8)(exports.VEILO_VIEW_KEY_SALT), (0, encoding_js_1.utf8)(exports.VEILO_VIEW_KEY_INFO), 32));
73
+ return { viewSecretKey, viewPublicKey: tweetnacl_1.default.scalarMult.base(viewSecretKey) };
74
+ }
75
+ /**
76
+ * One-shot derivation for a dapp holding only a wallet-standard `signMessage`.
77
+ *
78
+ * Uses the same signature as `deriveNoteKeypairWithSigner`, so a client that
79
+ * wants both prompts once and derives the spending key itself rather than
80
+ * calling both helpers.
81
+ */
82
+ async function deriveViewKeypairWithSigner(signMessage, index = 0) {
83
+ return deriveViewKeypairFromSpendingKey(await (0, spending_js_1.deriveSpendingKeyWithSigner)(signMessage, index));
84
+ }
85
+ /**
86
+ * Scan one candidate cipher with a view key.
87
+ *
88
+ * Returns `null` both for a view-tag miss and for a blob that was not encrypted
89
+ * to this key — the expected outcome for nearly every candidate. The shared
90
+ * secret is computed once and reused for the tag check and the open, which is
91
+ * the cheapest correct order for a scan loop: the tag rejects ~255/256
92
+ * candidates for one scalar multiplication and one hash.
93
+ *
94
+ * ⚠ Only decrypts notes encrypted TO `viewPublicKey`. Notes sealed to a wallet
95
+ * Ed25519 key — every note written before the v2 format — will not open here.
96
+ */
97
+ function openCompactNoteWithViewKey(viewSecretKey, cipher) {
98
+ (0, encoding_js_1.assertBytes)(viewSecretKey, 32, "view secret key");
99
+ (0, encoding_js_1.assertBytes)(cipher.ephemeralPublicKey, 32, "ephemeral public key");
100
+ const sharedSecret = tweetnacl_1.default.scalarMult(viewSecretKey, (0, mailbox_js_1.ed25519PublicKeyToX25519)(cipher.ephemeralPublicKey));
101
+ if (tweetnacl_1.default.hash(sharedSecret)[0] !== cipher.viewTag)
102
+ return null;
103
+ // walletSecretKey is unused once `sharedSecret` is supplied.
104
+ return (0, compactNote_js_1.decryptCompactNoteCipher)(viewSecretKey, cipher.ephemeralPublicKey, cipher.compactBlob, { sharedSecret });
105
+ }
@@ -0,0 +1,18 @@
1
+ import type { Idl } from "@coral-xyz/anchor";
2
+ /** Protocol generations used to decode Veilo's historical on-chain data. */
3
+ export type PrivacyPoolIdlVersion = "current" | "legacy" | "legacy2";
4
+ export type VersionedPrivacyPoolIdl = {
5
+ version: PrivacyPoolIdlVersion;
6
+ idl: Idl;
7
+ };
8
+ /** Current IDL used for building new instructions. */
9
+ export declare const PRIVACY_POOL_CURRENT_IDL: Idl;
10
+ /** Original event shape without compact note recovery fields. */
11
+ export declare const PRIVACY_POOL_LEGACY_IDL: Idl;
12
+ /** Intermediate event shape with compact cipher fields but no view tag. */
13
+ export declare const PRIVACY_POOL_LEGACY2_IDL: Idl;
14
+ /**
15
+ * IDLs in the same newest-to-oldest fallback order used by the relayer indexer.
16
+ * All three target the same deployed program address.
17
+ */
18
+ export declare const PRIVACY_POOL_IDLS: readonly VersionedPrivacyPoolIdl[];
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.PRIVACY_POOL_IDLS = exports.PRIVACY_POOL_LEGACY2_IDL = exports.PRIVACY_POOL_LEGACY_IDL = exports.PRIVACY_POOL_CURRENT_IDL = void 0;
7
+ const privacy_pool_js_1 = __importDefault(require("./privacy_pool.js"));
8
+ const privacy_pool_legacy_js_1 = __importDefault(require("./privacy_pool_legacy.js"));
9
+ const privacy_pool_legacy2_js_1 = __importDefault(require("./privacy_pool_legacy2.js"));
10
+ /** Current IDL used for building new instructions. */
11
+ exports.PRIVACY_POOL_CURRENT_IDL = privacy_pool_js_1.default;
12
+ /** Original event shape without compact note recovery fields. */
13
+ exports.PRIVACY_POOL_LEGACY_IDL = privacy_pool_legacy_js_1.default;
14
+ /** Intermediate event shape with compact cipher fields but no view tag. */
15
+ exports.PRIVACY_POOL_LEGACY2_IDL = privacy_pool_legacy2_js_1.default;
16
+ /**
17
+ * IDLs in the same newest-to-oldest fallback order used by the relayer indexer.
18
+ * All three target the same deployed program address.
19
+ */
20
+ exports.PRIVACY_POOL_IDLS = [
21
+ { version: "current", idl: exports.PRIVACY_POOL_CURRENT_IDL },
22
+ { version: "legacy", idl: exports.PRIVACY_POOL_LEGACY_IDL },
23
+ { version: "legacy2", idl: exports.PRIVACY_POOL_LEGACY2_IDL },
24
+ ];