@umbra-privacy/sdk 1.0.0 → 2.0.1

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 (181) hide show
  1. package/README.md +104 -25
  2. package/dist/{addresses-Brzgurv_.d.ts → addresses-B7HybtbJ.d.ts} +2 -1
  3. package/dist/{addresses-D_0YAS6B.d.cts → addresses-CTVY1oi7.d.cts} +2 -1
  4. package/dist/arcium-BXXlryfe.d.cts +20 -0
  5. package/dist/arcium-BXXlryfe.d.ts +20 -0
  6. package/dist/chunk-3LS5P32X.cjs +10892 -0
  7. package/dist/chunk-3LS5P32X.cjs.map +1 -0
  8. package/dist/chunk-4RHXVBNI.js +203 -0
  9. package/dist/chunk-4RHXVBNI.js.map +1 -0
  10. package/dist/chunk-4TZVXB5G.js +324 -0
  11. package/dist/chunk-4TZVXB5G.js.map +1 -0
  12. package/dist/chunk-5GUSMQ74.cjs +549 -0
  13. package/dist/chunk-5GUSMQ74.cjs.map +1 -0
  14. package/dist/chunk-5KPQXPQM.js +36 -0
  15. package/dist/chunk-5KPQXPQM.js.map +1 -0
  16. package/dist/chunk-AXD7LXYY.cjs +405 -0
  17. package/dist/chunk-AXD7LXYY.cjs.map +1 -0
  18. package/dist/{chunk-HOEXDXRC.cjs → chunk-BL6WXLPV.cjs} +32 -360
  19. package/dist/chunk-BL6WXLPV.cjs.map +1 -0
  20. package/dist/chunk-CFFLOE7D.cjs +598 -0
  21. package/dist/chunk-CFFLOE7D.cjs.map +1 -0
  22. package/dist/{chunk-BM7N6N7E.js → chunk-CFTW5WNG.js} +3 -325
  23. package/dist/chunk-CFTW5WNG.js.map +1 -0
  24. package/dist/chunk-DD2WCK4C.js +327 -0
  25. package/dist/chunk-DD2WCK4C.js.map +1 -0
  26. package/dist/chunk-DMPMQ74B.cjs +246 -0
  27. package/dist/chunk-DMPMQ74B.cjs.map +1 -0
  28. package/dist/{chunk-2Q75CQQJ.js → chunk-EEKF4553.js} +2 -2
  29. package/dist/chunk-EEKF4553.js.map +1 -0
  30. package/dist/chunk-ENVYYEM4.cjs +113 -0
  31. package/dist/chunk-ENVYYEM4.cjs.map +1 -0
  32. package/dist/chunk-FQX6ZYGJ.js +500 -0
  33. package/dist/chunk-FQX6ZYGJ.js.map +1 -0
  34. package/dist/chunk-FSK2ICMB.cjs +39 -0
  35. package/dist/chunk-FSK2ICMB.cjs.map +1 -0
  36. package/dist/chunk-FZYWLQAF.cjs +355 -0
  37. package/dist/chunk-FZYWLQAF.cjs.map +1 -0
  38. package/dist/chunk-GP26R377.js +436 -0
  39. package/dist/chunk-GP26R377.js.map +1 -0
  40. package/dist/chunk-HA5FLM63.js +393 -0
  41. package/dist/chunk-HA5FLM63.js.map +1 -0
  42. package/dist/chunk-INJ73LXQ.js +1107 -0
  43. package/dist/chunk-INJ73LXQ.js.map +1 -0
  44. package/dist/chunk-KMRROOME.js +10750 -0
  45. package/dist/chunk-KMRROOME.js.map +1 -0
  46. package/dist/{chunk-MDFSBU5W.cjs → chunk-LTCKPTZC.cjs} +2 -351
  47. package/dist/chunk-LTCKPTZC.cjs.map +1 -0
  48. package/dist/chunk-MKNCBUFA.js +564 -0
  49. package/dist/chunk-MKNCBUFA.js.map +1 -0
  50. package/dist/chunk-NKVMSABR.cjs +207 -0
  51. package/dist/chunk-NKVMSABR.cjs.map +1 -0
  52. package/dist/chunk-OFDWNWCL.js +70 -0
  53. package/dist/chunk-OFDWNWCL.js.map +1 -0
  54. package/dist/chunk-QJAUUYZU.cjs +331 -0
  55. package/dist/chunk-QJAUUYZU.cjs.map +1 -0
  56. package/dist/chunk-TLR7A64G.js +103 -0
  57. package/dist/chunk-TLR7A64G.js.map +1 -0
  58. package/dist/{chunk-MVKTV3FT.cjs → chunk-TQQZGNOI.cjs} +2 -2
  59. package/dist/chunk-TQQZGNOI.cjs.map +1 -0
  60. package/dist/chunk-UOFYS6M3.js +219 -0
  61. package/dist/chunk-UOFYS6M3.js.map +1 -0
  62. package/dist/chunk-UXMQI6B7.js +2406 -0
  63. package/dist/chunk-UXMQI6B7.js.map +1 -0
  64. package/dist/chunk-WN75ORDT.js +571 -0
  65. package/dist/chunk-WN75ORDT.js.map +1 -0
  66. package/dist/chunk-Y55PYKXH.cjs +595 -0
  67. package/dist/chunk-Y55PYKXH.cjs.map +1 -0
  68. package/dist/chunk-YEZBTYCP.cjs +77 -0
  69. package/dist/chunk-YEZBTYCP.cjs.map +1 -0
  70. package/dist/chunk-ZQOIYCGA.cjs +1126 -0
  71. package/dist/chunk-ZQOIYCGA.cjs.map +1 -0
  72. package/dist/chunk-ZY3TSHMJ.cjs +2665 -0
  73. package/dist/chunk-ZY3TSHMJ.cjs.map +1 -0
  74. package/dist/client-DkVBHMWb.d.cts +2613 -0
  75. package/dist/client-V4AF6Bz9.d.ts +2613 -0
  76. package/dist/common/pda/index.cjs +145 -0
  77. package/dist/common/pda/index.cjs.map +1 -0
  78. package/dist/common/pda/index.d.cts +1250 -0
  79. package/dist/common/pda/index.d.ts +1250 -0
  80. package/dist/common/pda/index.js +8 -0
  81. package/dist/common/pda/index.js.map +1 -0
  82. package/dist/constants/index.cjs +38 -164
  83. package/dist/constants/index.cjs.map +1 -1
  84. package/dist/constants/index.d.cts +8 -425
  85. package/dist/constants/index.d.ts +8 -425
  86. package/dist/constants/index.js +15 -124
  87. package/dist/constants/index.js.map +1 -1
  88. package/dist/crypto/index.cjs +583 -0
  89. package/dist/crypto/index.cjs.map +1 -0
  90. package/dist/crypto/index.d.cts +6731 -0
  91. package/dist/crypto/index.d.ts +6731 -0
  92. package/dist/crypto/index.js +14 -0
  93. package/dist/crypto/index.js.map +1 -0
  94. package/dist/{cryptography-BTGC72u-.d.ts → cryptography-BFSJcvi6.d.ts} +3 -2465
  95. package/dist/{cryptography-BTGC72u-.d.cts → cryptography-D6tPDh-Y.d.cts} +3 -2465
  96. package/dist/errors/index.cjs +64 -54
  97. package/dist/errors/index.d.cts +7 -797
  98. package/dist/errors/index.d.ts +7 -797
  99. package/dist/errors/index.js +3 -1
  100. package/dist/errors-B9EoPeWV.d.cts +593 -0
  101. package/dist/errors-B9EoPeWV.d.ts +593 -0
  102. package/dist/errors-DAIrstEL.d.cts +300 -0
  103. package/dist/errors-DPNMfyh0.d.ts +300 -0
  104. package/dist/index-BG0yjL7C.d.cts +6006 -0
  105. package/dist/index-ByynoyBO.d.ts +6006 -0
  106. package/dist/index.cjs +5133 -16116
  107. package/dist/index.cjs.map +1 -1
  108. package/dist/index.d.cts +1031 -7685
  109. package/dist/index.d.ts +1031 -7685
  110. package/dist/index.js +3228 -14905
  111. package/dist/index.js.map +1 -1
  112. package/dist/interfaces/index.d.cts +14 -6
  113. package/dist/interfaces/index.d.ts +14 -6
  114. package/dist/interfaces-43cReBcS.d.cts +3346 -0
  115. package/dist/interfaces-B8xKNl_6.d.ts +997 -0
  116. package/dist/interfaces-D2NO6kDD.d.cts +997 -0
  117. package/dist/interfaces-z_xYJlgV.d.ts +3346 -0
  118. package/dist/math/index.cjs +115 -0
  119. package/dist/math/index.cjs.map +1 -0
  120. package/dist/math/index.d.cts +1327 -0
  121. package/dist/math/index.d.ts +1327 -0
  122. package/dist/math/index.js +10 -0
  123. package/dist/math/index.js.map +1 -0
  124. package/dist/networks-RMd3abPE.d.ts +44 -0
  125. package/dist/networks-yAoO8peQ.d.cts +44 -0
  126. package/dist/relayer-NRRMSMNB.js +4 -0
  127. package/dist/relayer-NRRMSMNB.js.map +1 -0
  128. package/dist/relayer-RJHEIXJG.cjs +21 -0
  129. package/dist/relayer-RJHEIXJG.cjs.map +1 -0
  130. package/dist/solana/index.cjs +56 -0
  131. package/dist/solana/index.cjs.map +1 -0
  132. package/dist/solana/index.d.cts +105 -0
  133. package/dist/solana/index.d.ts +105 -0
  134. package/dist/solana/index.js +7 -0
  135. package/dist/solana/index.js.map +1 -0
  136. package/dist/{index-CLj_zWSD.d.ts → temporal-BbRaEPoO.d.ts} +1 -1
  137. package/dist/{index-CX6_pIRS.d.cts → temporal-oUj7iCaq.d.cts} +1 -1
  138. package/dist/transaction-forwarder-5mAMTjw6.d.ts +1155 -0
  139. package/dist/transaction-forwarder-C6gMUG7a.d.cts +1155 -0
  140. package/dist/types/index.cjs +232 -231
  141. package/dist/types/index.d.cts +15 -1485
  142. package/dist/types/index.d.ts +15 -1485
  143. package/dist/types/index.js +2 -1
  144. package/dist/types-BohhvPth.d.cts +87 -0
  145. package/dist/types-CW0oTT0j.d.ts +87 -0
  146. package/dist/types-C_V_CaKK.d.cts +2468 -0
  147. package/dist/types-C_V_CaKK.d.ts +2468 -0
  148. package/dist/types-Ca7frykr.d.ts +793 -0
  149. package/dist/types-CuKeoI19.d.cts +1296 -0
  150. package/dist/types-CxfTIpN9.d.ts +1052 -0
  151. package/dist/{types-n-sHFcgr.d.ts → types-D1jDUjfN.d.ts} +2 -2
  152. package/dist/types-DKEDUlH9.d.ts +1296 -0
  153. package/dist/types-EKuIfxTz.d.cts +1052 -0
  154. package/dist/{types-BBuELtY8.d.cts → types-IMGYmlv-.d.cts} +2 -2
  155. package/dist/types-PwNLi_2k.d.cts +793 -0
  156. package/dist/utils/index.cjs +823 -525
  157. package/dist/utils/index.d.cts +1711 -4021
  158. package/dist/utils/index.d.ts +1711 -4021
  159. package/dist/utils/index.js +9 -3
  160. package/dist/{versions-D9PqsEvj.d.cts → versions-BRlR36EA.d.cts} +1 -0
  161. package/dist/{versions-D9PqsEvj.d.ts → versions-BRlR36EA.d.ts} +1 -0
  162. package/package.json +79 -18
  163. package/dist/chunk-2Q75CQQJ.js.map +0 -1
  164. package/dist/chunk-BM7N6N7E.js.map +0 -1
  165. package/dist/chunk-GXKSUB2U.cjs +0 -4416
  166. package/dist/chunk-GXKSUB2U.cjs.map +0 -1
  167. package/dist/chunk-HOEXDXRC.cjs.map +0 -1
  168. package/dist/chunk-MDFSBU5W.cjs.map +0 -1
  169. package/dist/chunk-MQY7HDIA.js +0 -600
  170. package/dist/chunk-MQY7HDIA.js.map +0 -1
  171. package/dist/chunk-MVKTV3FT.cjs.map +0 -1
  172. package/dist/chunk-PG2J6V6Y.js +0 -4094
  173. package/dist/chunk-PG2J6V6Y.js.map +0 -1
  174. package/dist/chunk-VEGLTTYQ.cjs +0 -621
  175. package/dist/chunk-VEGLTTYQ.cjs.map +0 -1
  176. package/dist/chunk-WVHQ46DD.js +0 -758
  177. package/dist/chunk-WVHQ46DD.js.map +0 -1
  178. package/dist/index-B9pDY73x.d.ts +0 -12933
  179. package/dist/index-D33yo0qB.d.cts +0 -12933
  180. package/dist/networks-C-orpSFW.d.ts +0 -65
  181. package/dist/networks-FxYERGD1.d.cts +0 -65
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/common/pda/umbra.ts","../src/common/pda/user.ts","../src/common/pda/arcium.ts","../src/common/pda/compliance.ts","../src/common/pda/global.ts","../src/common/pda/pool.ts","../src/common/pda/relayer.ts","../src/common/pda/fees.ts","../src/common/pda/zk.ts"],"names":["getAddressEncoder","getProgramDerivedAddress","sha256","getAccountOffsetEncoder"],"mappings":";;;;;;;;AA6EO,SAAS,kBAAkB,IAAA,EAA0B;AAC1D,EAAA,OAAO,OAAO,IAAI,WAAA,EAAY,CAAE,MAAA,CAAO,IAAI,CAAC,CAAA;AAC9C;AAFgB,MAAA,CAAA,iBAAA,EAAA,mBAAA,CAAA;AAYhB,IAAM,iBAAA,GAAoB,kBAAkB,aAAa,CAAA;AAUzD,IAAM,qBAAA,GAAwB,kBAAkB,mCAAmC,CAAA;AAUnF,IAAM,oBAAA,GAAuB,kBAAkB,6BAA6B,CAAA;AAU5E,IAAM,UAAA,GAAa,kBAAkB,OAAO,CAAA;AA2B5C,eAAsB,kBAAA,CAAmB,OAAa,YAAA,EAAyC;AAC7F,EAAA,MAAM,CAAC,GAAG,CAAA,GAAI,MAAM,wBAAA,CAAyB;AAAA,IAC3C,cAAA,EAAgB,YAAA;AAAA,IAChB,KAAA,EAAO,CAAC,iBAAA,EAAmB,uBAAA,CAAwB,KAAK,CAAC;AAAA,GAC1D,CAAA;AA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EAAgB,YAAA;AAAA,IAChB,KAAA,EAAO;AAAA,MACL,8BAAA;AAAA,MACAD,iBAAAA,EAAkB,CAAE,MAAA,CAAO,gBAAgB,CAAA;AAAA,MAC3CG,uBAAAA,GAA0B,MAAA,CAAO,EAAE,OAAO,MAAA,CAAO,MAAM,GAAG;AAAA;AAC5D,GACD,CAAA;AACD,EAAA,OAAO,GAAA;AACT;AAdsB,MAAA,CAAA,4BAAA,EAAA,8BAAA,CAAA;AA8CtB,eAAsB,6BAAA,CACpB,cAAA,EACA,MAAA,EACA,YAAA,EACkB;AAClB,EAAA,MAAM,CAAC,GAAG,CAAA,GAAI,MAAMF,wBAAAA,CAAyB;AAAA,IAC3C,cAAA,EAAgB,YAAA;AAAA,IAChB,KAAA,EAAO;AAAA,MACL,+BAAA;AAAA,MACAD,iBAAAA,EAAkB,CAAE,MAAA,CAAO,cAAc,CAAA;AAAA,MACzCG,uBAAAA,GAA0B,MAAA,CAAO,EAAE,OAAO,MAAA,CAAO,MAAM,GAAG;AAAA;AAC5D,GACD,CAAA;AACD,EAAA,OAAO,GAAA;AACT;AAdsB,MAAA,CAAA,6BAAA,EAAA,+BAAA,CAAA;AAgDtB,eAAsB,iCAAA,CACpB,cAAA,EACA,MAAA,EACA,YAAA,EACqC;AACrC,EAAA,OAAOF,wBAAAA,CAAyB;AAAA,IAC9B,cAAA,EAAgB,YAAA;AAAA,IAChB,KAAA,EAAO;AAAA,MACL,uCAAA;AAAA,MACAD,iBAAAA,EAAkB,CAAE,MAAA,CAAO,cAAc,CAAA;AAAA,MACzCG,uBAAAA,GAA0B,MAAA,CAAO,EAAE,OAAO,MAAA,CAAO,MAAM,GAAG;AAAA;AAC5D,GACD,CAAA;AACH;AAbsB,MAAA,CAAA,iCAAA,EAAA,mCAAA,CAAA","file":"chunk-MKNCBUFA.js","sourcesContent":["/**\n * Umbra PDA (Program Derived Address) Generator Utilities\n *\n * This module provides functions for deriving Umbra protocol account addresses,\n * specifically for mixer tree accounts used in the privacy-preserving UTXO system.\n *\n * @remarks\n * ## Mixer Tree Overview\n *\n * The mixer tree is an Indexed Merkle Tree (IMT) that stores Poseidon H2 hash\n * commitments to UTXOs. Multiple mixer trees can exist, with each tree indexed\n * sequentially (0, 1, 2, ...). When a tree reaches capacity, a new tree is\n * created and becomes the active tree. Old trees remain readable for proof\n * generation and claiming.\n *\n * ## Nullifier Set Overview\n *\n * Each mixer tree has five associated nullifier set accounts (variants 0-4). These\n * accounts form an Indexed Merkle Tree of nullifiers and serve as the primary\n * double-spend prevention mechanism: before a UTXO can be claimed its\n * nullifier is checked against -- and then inserted into -- the nullifier set.\n *\n * ## UTXO Burner Accounts\n *\n * Confidential and public UTXO burner accounts act as temporary storage for\n * nullifiers during relayer-submitted claim transactions. They are scoped to\n * a `(relayer, receiver_address, offset)` triple and are created and closed\n * within the same transaction.\n *\n * ## Utility Functions\n *\n * `computeStructSeed` is re-exported from this module because every other PDA module\n * depends on it to compute seed constants.\n *\n * @see {@link findStealthPoolPda}\n * @see {@link findActiveStealthPoolPda}\n * @see {@link findNullifierSetPdas}\n * @see {@link findConfidentialNullifierBufferPda}\n * @see {@link findPublicNullifierBufferPda}\n * @see {@link computeStructSeed}\n *\n * @packageDocumentation\n * @since 2.0.0\n * @module utils/pda/umbra\n */\n\nimport { type Address, getAddressEncoder, getProgramDerivedAddress } from \"@solana/kit\";\nimport { getAccountOffsetEncoder } from \"@umbra-privacy/umbra-codama\";\nimport { sha256 } from \"@noble/hashes/sha2.js\";\nimport type { U128 } from \"../../types\";\nimport { encodeU128ToU128LeBytes } from \"../converters/mathematics\";\n\n/**\n * Computes the SHA-256 hash of a struct/seed name string and returns the\n * result as a 32-byte `Uint8Array`.\n *\n * This mirrors the `sha256_seed!` macro and the `#[umbra_account]` macro used\n * in the Rust smart contract. Every PDA seed constant in the Umbra program is\n * derived as `SHA-256(struct_name_utf8)`.\n *\n * This function is also exported from the barrel (`index.ts`) for callers that\n * need to compute arbitrary struct seeds outside the SDK, for example when\n * verifying a PDA derivation manually or in tests.\n *\n * @param name - The struct or domain name to hash (UTF-8 string, e.g. `\"TokenPool\"`).\n * @returns A 32-byte `Uint8Array` containing the SHA-256 digest.\n *\n * @example\n * ```typescript\n * import { computeStructSeed } from \"@umbra-privacy/sdk\";\n *\n * const poolSeed = computeStructSeed(\"TokenPool\");\n * // poolSeed is SHA-256(\"TokenPool\") as a 32-byte Uint8Array\n * ```\n *\n * @public\n */\nexport function computeStructSeed(name: string): Uint8Array {\n return sha256(new TextEncoder().encode(name));\n}\n\n/**\n * SHA-256 of the string `\"StealthPool\"`, stored as a 32-byte `Uint8Array`.\n *\n * Matches `sha256_seed!(\"StealthPool\")` in the Rust smart contract. Used as\n * the first seed when deriving `StealthPool` PDAs.\n *\n * @internal\n */\nconst STEALTH_POOL_SEED = computeStructSeed(\"StealthPool\");\n\n/**\n * SHA-256 of the string `\"ConfidentialNullifierLinkerBuffer\"`, stored as a 32-byte `Uint8Array`.\n *\n * Matches `sha256_seed!(\"ConfidentialNullifierLinkerBuffer\")` in the Rust smart contract.\n * Used as the first seed when deriving confidential UTXO burner PDAs.\n *\n * @internal\n */\nconst CONF_UTXO_BURNER_SEED = computeStructSeed(\"ConfidentialNullifierLinkerBuffer\");\n\n/**\n * SHA-256 of the string `\"PublicNullifierLinkerBuffer\"`, stored as a 32-byte `Uint8Array`.\n *\n * Matches `sha256_seed!(\"PublicNullifierLinkerBuffer\")` in the Rust smart contract.\n * Used as the first seed when deriving public UTXO burner PDAs.\n *\n * @internal\n */\nconst PUB_UTXO_BURNER_SEED = computeStructSeed(\"PublicNullifierLinkerBuffer\");\n\n/**\n * SHA-256 of the string `\"Treap\"`, stored as a 32-byte `Uint8Array`.\n *\n * Matches `sha256_seed!(\"Treap\")` in the Rust smart contract. Used as the\n * first seed when deriving nullifier set account PDAs.\n *\n * @internal\n */\nconst TREAP_SEED = computeStructSeed(\"Treap\");\n\n/**\n * Derives the Program Derived Address for a stealth pool (mixer tree) at the given index.\n * Seeds: [StealthPool::SEED, index_u128_le]\n *\n * The mixer tree is an Indexed Merkle Tree (IMT) that stores Poseidon H2 hash\n * commitments for UTXOs. Multiple trees can exist simultaneously, each\n * identified by a sequential integer index.\n *\n * @param index - The mixer tree index, starting from `0n`.\n * @param umbraProgram - The Umbra program address.\n * @returns A Promise resolving to the derived PDA `Address`.\n *\n * @example\n * ```typescript\n * import { findStealthPoolPda } from \"@umbra-privacy/sdk\";\n *\n * const mixerTree0 = await findStealthPoolPda(0n as U128, networkConfig.programId);\n * ```\n *\n * @see {@link findActiveStealthPoolPda} for the convenience wrapper that always returns tree index 0\n * @see {@link findNullifierSetPdas} for the nullifier storage accounts associated with each tree\n * @see {@link findProtocolConfigPda} for the global account that stores the active tree index\n *\n * @public\n */\nexport async function findStealthPoolPda(index: U128, umbraProgram: Address): Promise<Address> {\n const [pda] = await getProgramDerivedAddress({\n programAddress: umbraProgram,\n seeds: [STEALTH_POOL_SEED, encodeU128ToU128LeBytes(index)],\n });\n\n return pda;\n}\n\n/**\n * Derives the Program Derived Address for the currently active stealth pool (tree index 0).\n * Seeds: [StealthPool::SEED, 0_u128_le]\n *\n * This is a convenience wrapper around `findStealthPoolPda(0n)` for the\n * common case where a caller needs the genesis tree address.\n *\n * @param umbraProgram - The Umbra program address.\n * @returns A Promise resolving to the PDA `Address` of tree index 0.\n *\n * @example\n * ```typescript\n * import { findActiveStealthPoolPda } from \"@umbra-privacy/sdk\";\n *\n * const activeMixer = await findActiveStealthPoolPda(networkConfig.programId);\n * ```\n *\n * @see {@link findStealthPoolPda} for arbitrary tree index derivation\n * @see {@link findProtocolConfigPda} for the account that tracks the true active index\n *\n * @public\n */\nexport async function findActiveStealthPoolPda(umbraProgram: Address): Promise<Address> {\n return findStealthPoolPda(0n as U128, umbraProgram);\n}\n\n/**\n * Derives the Program Derived Address for a confidential nullifier buffer account.\n * Seeds: [ConfidentialNullifierLinkerBuffer::SEED, relayer_pubkey, receiver_address, offset_u128_le]\n *\n * Confidential nullifier buffer accounts are temporary storage PDAs that hold\n * the nullifier set for a batch of confidential UTXOs being claimed in a\n * single relayer-submitted transaction.\n *\n * @param relayerAddress - The relayer's public key.\n * @param receiverAddress - The receiver's public key (claim destination address).\n * @param burnerAccountOffset - The U128 offset discriminator.\n * @param umbraProgram - The Umbra program address.\n * @returns A Promise resolving to the derived PDA `Address`.\n *\n * @example\n * ```typescript\n * import { findConfidentialNullifierBufferPda } from \"@umbra-privacy/sdk\";\n *\n * const burnerPda = await findConfidentialNullifierBufferPda(\n * relayerAddress,\n * receiverAddress,\n * 0n as U128,\n * networkConfig.programId,\n * );\n * ```\n *\n * @see {@link findPublicNullifierBufferPda} for the public-balance variant\n * @see {@link findNullifierSetPdas} for the nullifier storage accounts the burner writes into\n *\n * @public\n */\nexport async function findConfidentialNullifierBufferPda(\n relayerAddress: Address,\n receiverAddress: Address,\n burnerAccountOffset: U128,\n umbraProgram: Address,\n): Promise<Address> {\n const addressEncoder = getAddressEncoder();\n\n const [pda] = await getProgramDerivedAddress({\n programAddress: umbraProgram,\n seeds: [\n CONF_UTXO_BURNER_SEED,\n addressEncoder.encode(relayerAddress),\n addressEncoder.encode(receiverAddress),\n getAccountOffsetEncoder().encode({\n first: BigInt(burnerAccountOffset),\n }),\n ],\n });\n\n return pda;\n}\n\n/**\n * Derives the Program Derived Address for a public nullifier buffer account.\n * Seeds: [PublicNullifierLinkerBuffer::SEED, relayer_pubkey, receiver_address, offset_u128_le]\n *\n * Public nullifier buffer accounts serve the same purpose as confidential\n * nullifier buffer accounts but for claims that deposit into a public ATA\n * rather than an encrypted balance.\n *\n * @param relayerAddress - The relayer's public key.\n * @param receiverAddress - The receiver's public key (claim destination address).\n * @param burnerAccountOffset - The U128 offset discriminator.\n * @param umbraProgram - The Umbra program address.\n * @returns A Promise resolving to the derived PDA `Address`.\n *\n * @example\n * ```typescript\n * import { findPublicNullifierBufferPda } from \"@umbra-privacy/sdk\";\n *\n * const burnerPda = await findPublicNullifierBufferPda(\n * relayerAddress,\n * receiverAddress,\n * 0n as U128,\n * networkConfig.programId,\n * );\n * ```\n *\n * @see {@link findConfidentialNullifierBufferPda} for the confidential-balance variant\n * @see {@link findNullifierSetPdas} for the nullifier storage accounts the burner writes into\n *\n * @public\n */\nexport async function findPublicNullifierBufferPda(\n relayerAddress: Address,\n receiverAddress: Address,\n burnerAccountOffset: U128,\n umbraProgram: Address,\n): Promise<Address> {\n const addressEncoder = getAddressEncoder();\n\n const [pda] = await getProgramDerivedAddress({\n programAddress: umbraProgram,\n seeds: [\n PUB_UTXO_BURNER_SEED,\n addressEncoder.encode(relayerAddress),\n addressEncoder.encode(receiverAddress),\n getAccountOffsetEncoder().encode({\n first: BigInt(burnerAccountOffset),\n }),\n ],\n });\n\n return pda;\n}\n\n/**\n * Return type for `findNullifierSetPdas` containing all five nullifier set\n * account addresses for a given mixer tree index.\n *\n * @remarks\n * Each mixer tree has exactly five associated nullifier set accounts (variants 0-4).\n * Together they form the Indexed Merkle Tree of nullifiers that prevents\n * double-spending. All five accounts must be passed to claim instructions\n * so the program can update the correct nullifier set node.\n *\n * @see {@link findNullifierSetPdas}\n *\n * @public\n */\nexport interface NullifierSetPdas {\n /** Nullifier set account variant 0 (first segment of the nullifier IMT). @readonly */\n readonly treap0: Address;\n /** Nullifier set account variant 1 (second segment of the nullifier IMT). @readonly */\n readonly treap1: Address;\n /** Nullifier set account variant 2 (third segment of the nullifier IMT). @readonly */\n readonly treap2: Address;\n /** Nullifier set account variant 3 (fourth segment of the nullifier IMT). @readonly */\n readonly treap3: Address;\n /** Nullifier set account variant 4 (fifth segment of the nullifier IMT). @readonly */\n readonly treap4: Address;\n}\n\n/**\n * Derives all five nullifier set PDAs for a given mixer tree index.\n * Seeds (per variant): [Treap::SEED, stealth_pool_index_u128_le, variant_byte]\n *\n * Nullifier set accounts implement the Indexed Merkle Tree (IMT) of nullifiers\n * used to prevent double-spending of UTXOs. There are exactly five accounts\n * per mixer tree, addressed by variant byte 0-4.\n *\n * @param stealthPoolIndex - The mixer tree index whose nullifier set PDAs to derive.\n * @param umbraProgram - The Umbra program address.\n * @returns A Promise resolving to a {@link NullifierSetPdas} object containing all\n * five nullifier set account addresses (`treap0` through `treap4`).\n *\n * @example\n * ```typescript\n * import { findNullifierSetPdas } from \"@umbra-privacy/sdk\";\n *\n * const nullifierSetPdas = await findNullifierSetPdas(0n as U128, networkConfig.programId);\n * console.log(nullifierSetPdas.treap0, nullifierSetPdas.treap1, nullifierSetPdas.treap2);\n * ```\n *\n * @see {@link findStealthPoolPda} for the Merkle commitment tree PDAs\n * @see {@link NullifierSetPdas} for the return type shape\n *\n * @public\n */\nexport async function findNullifierSetPdas(\n stealthPoolIndex: U128,\n umbraProgram: Address,\n): Promise<NullifierSetPdas> {\n const treapSeedBytes = TREAP_SEED;\n const indexBytes = encodeU128ToU128LeBytes(stealthPoolIndex);\n\n const derivePda = async (variant: number): Promise<Address> => {\n const [pda] = await getProgramDerivedAddress({\n programAddress: umbraProgram,\n seeds: [treapSeedBytes, indexBytes, new Uint8Array([variant])],\n });\n return pda;\n };\n\n const [treap0, treap1, treap2, treap3, treap4] = await Promise.all([\n derivePda(0),\n derivePda(1),\n derivePda(2),\n derivePda(3),\n derivePda(4),\n ]);\n\n return { treap0, treap1, treap2, treap3, treap4 };\n}\n","/**\n * User PDA Utilities\n *\n * This module provides functions to derive Program Derived Addresses (PDAs)\n * for user-related accounts in the Umbra protocol.\n *\n * @remarks\n * Umbra users have two distinct on-chain account types, both stored as\n * Arcium-encrypted accounts so their contents are opaque to on-chain\n * observers:\n *\n * - **`EncryptedUserAccount`** — stores the user's protocol-level state,\n * including their registered X25519 public key and account generation index.\n * Created once per user wallet via `RegisterUser`. Referenced by all\n * confidential and compliance instructions that need to look up the user's\n * encryption key.\n *\n * - **`EncryptedTokenAccount`** — stores the user's encrypted SPL token\n * balance for a specific mint. Created once per `(user, mint)` pair via\n * `InitialiseUserTokenAccount`. Modified by deposit, withdrawal, transfer,\n * and claim instructions.\n *\n * Both PDAs are keyed under the Umbra program address (not the Arcium program)\n * because the Umbra program owns and manages these accounts through its\n * instruction handlers and Arcium callbacks.\n *\n * @see {@link findEncryptedUserAccountPda}\n * @see {@link findEncryptedTokenAccountPda}\n *\n * @packageDocumentation\n * @since 2.0.0\n * @module utils/pda/user\n */\n\nimport { type Address, getAddressEncoder, getProgramDerivedAddress } from \"@solana/kit\";\nimport { computeStructSeed } from \"./umbra\";\n\n/**\n * SHA-256 of the string `\"EncryptedUserAccount\"`, stored as a 32-byte `Uint8Array`.\n *\n * Matches `EncryptedUserAccount::SEED` as generated by the\n * `#[umbra_account]` macro in `state/arcium/arcium_encrypted_user_account.rs`.\n * Used as the first seed when deriving encrypted user account PDAs.\n *\n * @internal\n */\nconst ENCRYPTED_USER_ACCOUNT_SEED = computeStructSeed(\"EncryptedUserAccount\");\n\n/**\n * SHA-256 of the string `\"EncryptedTokenAccount\"`, stored as a 32-byte `Uint8Array`.\n *\n * Matches `EncryptedTokenAccount::SEED` as generated by the\n * `#[umbra_account]` macro in `state/arcium/arcium_encrypted_token_account.rs`.\n * Used as the first seed when deriving encrypted token account PDAs.\n *\n * @internal\n */\nconst ENCRYPTED_TOKEN_ACCOUNT_SEED = computeStructSeed(\"EncryptedTokenAccount\");\n\n/**\n * Derives the Program Derived Address for an encrypted user account.\n * Seeds: [EncryptedUserAccount::SEED, user_pubkey]\n *\n * The `EncryptedUserAccount` is the user's top-level protocol identity\n * within Umbra. It is a singleton per user wallet and stores the user's\n * registered X25519 public key and account generation index.\n *\n * @param userPubkey - The user's wallet public key (Solana Ed25519 address).\n * @param umbraProgram - The Umbra program address.\n * @returns A Promise resolving to the derived PDA `Address`.\n *\n * @example\n * ```typescript\n * import { findEncryptedUserAccountPda } from \"@umbra-privacy/sdk\";\n *\n * const userAccountPda = await findEncryptedUserAccountPda(\n * userWalletAddress,\n * networkConfig.programId,\n * );\n * ```\n *\n * @see {@link findEncryptedTokenAccountPda} for per-mint encrypted balance accounts\n *\n * @public\n */\nexport async function findEncryptedUserAccountPda(\n userPubkey: Address,\n umbraProgram: Address,\n): Promise<Address> {\n const addressEncoder = getAddressEncoder();\n\n const [pda] = await getProgramDerivedAddress({\n programAddress: umbraProgram,\n seeds: [ENCRYPTED_USER_ACCOUNT_SEED, addressEncoder.encode(userPubkey)],\n });\n\n return pda;\n}\n\n/**\n * Derives the Program Derived Address for an encrypted token account.\n * Seeds: [EncryptedTokenAccount::SEED, user_pubkey, mint_pubkey]\n *\n * The `EncryptedTokenAccount` holds the user's encrypted SPL token\n * balance for a specific mint. A separate account exists for each\n * `(user, mint)` pair.\n *\n * @param userPubkey - The user's wallet public key (Solana Ed25519 address).\n * @param mintPubkey - The SPL token mint address.\n * @param umbraProgram - The Umbra program address.\n * @returns A Promise resolving to the derived PDA `Address`.\n *\n * @example\n * ```typescript\n * import { findEncryptedTokenAccountPda } from \"@umbra-privacy/sdk\";\n *\n * const tokenAccountPda = await findEncryptedTokenAccountPda(\n * userWalletAddress,\n * usdcMint,\n * networkConfig.programId,\n * );\n * ```\n *\n * @see {@link findEncryptedUserAccountPda} for the top-level user identity account\n * @see {@link findTokenPoolPda} for the per-mint pool configuration that governs this account's features\n *\n * @public\n */\nexport async function findEncryptedTokenAccountPda(\n userPubkey: Address,\n mintPubkey: Address,\n umbraProgram: Address,\n): Promise<Address> {\n const addressEncoder = getAddressEncoder();\n\n const [pda] = await getProgramDerivedAddress({\n programAddress: umbraProgram,\n seeds: [\n ENCRYPTED_TOKEN_ACCOUNT_SEED,\n addressEncoder.encode(userPubkey),\n addressEncoder.encode(mintPubkey),\n ],\n });\n\n return pda;\n}\n","/**\n * Arcium PDA (Program Derived Address) Generator Utilities\n *\n * This module provides functions for deriving Arcium protocol account addresses.\n * These PDAs are used to locate various Arcium accounts on-chain, including\n * MXE accounts, computation accounts, and cluster accounts.\n *\n * @see {@link findArciumMxePda}\n * @see {@link findArciumMempoolPda}\n * @see {@link findArciumExecutingPoolPda}\n * @see {@link findArciumComputationPda}\n * @see {@link findArciumCompDefPda}\n * @see {@link findArciumClusterPda}\n * @see {@link findArciumInfrastructurePdas}\n * @see {@link computeCompDefOffset}\n *\n * @packageDocumentation\n * @since 2.0.0\n * @module utils/pda/arcium\n */\n\nimport { type Address, getAddressEncoder, getProgramDerivedAddress } from \"@solana/kit\";\nimport { sha256 } from \"@noble/hashes/sha2.js\";\nimport {\n ARCIUM_MXE_ACCOUNT_SEED,\n ARCIUM_MEMPOOL_SEED,\n ARCIUM_EXEC_POOL_SEED,\n ARCIUM_COMPUTATION_SEED,\n ARCIUM_COMP_DEF_SEED,\n ARCIUM_CLUSTER_SEED,\n} from \"../../constants/arcium\";\nimport { type U32, assertU32, assertU64 } from \"../../types\";\nimport { encodeU32ToU32LeBytes, encodeU64ToU64LeBytes } from \"../converters/mathematics\";\n\n/* =============================================================================\n * COMPUTATION DEFINITION OFFSET DERIVATION\n * ============================================================================= */\n\n/**\n * Computes the computation definition offset from an Arcium instruction name.\n *\n * The comp-def offset uniquely identifies which comp-def account corresponds\n * to a given Umbra instruction. It is derived deterministically by taking the\n * SHA-256 hash of the instruction name and interpreting the first four bytes\n * as a little-endian u32.\n *\n * @param instructionName - The Arcium instruction name in snake_case format\n * (e.g. `\"register_user\"`, `\"deposit_into_existing_mxe_v3\"`).\n * @returns The computation definition offset as an unsigned 32-bit integer.\n *\n * @example\n * ```typescript\n * import { computeCompDefOffset } from \"@umbra-privacy/sdk\";\n *\n * const offset = computeCompDefOffset(\"register_user\");\n *\n * const compDefPda = await findArciumCompDefPda(\n * networkConfig.programId,\n * networkConfig.arciumProgramAddress,\n * offset,\n * );\n * ```\n *\n * @see {@link findArciumCompDefPda} for deriving the full comp-def PDA\n * @see {@link findArciumInfrastructurePdas} for deriving all Arcium accounts at once\n *\n * @public\n */\nexport function computeCompDefOffset(instructionName: string): number {\n // Hash the instruction name with SHA256\n const hash = sha256(new TextEncoder().encode(instructionName));\n\n // Take first 4 bytes and interpret as little-endian u32\n\n const byte0 = hash[0];\n\n const byte1 = hash[1];\n\n const byte2 = hash[2];\n\n const byte3 = hash[3];\n\n const offset = byte0 | (byte1 << 8) | (byte2 << 16) | (byte3 << 24);\n\n // Return as unsigned 32-bit integer\n return offset >>> 0;\n}\n\n/* =============================================================================\n * PDA DERIVATION FUNCTIONS\n * ============================================================================= */\n\n/**\n * Derives the Program Derived Address for the Arcium MXE registration account.\n * Seeds: [ARCIUM_MXE_ACCOUNT_SEED, umbra_program_pubkey] (against Arcium program)\n *\n * The MXE account is the Arcium protocol's main registration account for a\n * guest program (Umbra). Required as a read-only account on every\n * Arcium-integrated instruction.\n *\n * @param umbraProgram - The Umbra program address.\n * @param arciumProgram - The Arcium program address.\n * @returns A Promise resolving to the derived MXE account `Address`.\n *\n * @example\n * ```typescript\n * import { findArciumMxePda } from \"@umbra-privacy/sdk\";\n *\n * const mxeAccount = await findArciumMxePda(\n * networkConfig.programId,\n * networkConfig.arciumProgramAddress,\n * );\n * ```\n *\n * @see {@link findArciumInfrastructurePdas} for deriving all Arcium accounts at once\n *\n * @public\n */\nexport async function findArciumMxePda(\n umbraProgram: Address,\n arciumProgram: Address,\n): Promise<Address> {\n const [address] = await getProgramDerivedAddress({\n programAddress: arciumProgram,\n seeds: [\n new TextEncoder().encode(ARCIUM_MXE_ACCOUNT_SEED),\n getAddressEncoder().encode(umbraProgram),\n ],\n });\n return address;\n}\n\n/**\n * Derives the Program Derived Address for an Arcium cluster mempool account.\n * Seeds: [ARCIUM_MEMPOOL_SEED, cluster_offset_u32_le] (against Arcium program)\n *\n * The mempool account is a queue that holds pending computation requests\n * waiting to be picked up by cluster nodes.\n *\n * @param arciumProgram - The Arcium program address.\n * @param clusterOffset - The cluster offset (u32).\n * @returns A Promise resolving to the derived mempool account `Address`.\n *\n * @example\n * ```typescript\n * import { findArciumMempoolPda } from \"@umbra-privacy/sdk\";\n *\n * const mempoolAccount = await findArciumMempoolPda(\n * networkConfig.arciumProgramAddress,\n * networkConfig.clusterOffset,\n * );\n * ```\n *\n * @see {@link findArciumClusterPda} for the parent cluster account\n *\n * @public\n */\nexport async function findArciumMempoolPda(\n arciumProgram: Address,\n clusterOffset: number,\n): Promise<Address> {\n assertU32(BigInt(clusterOffset));\n const [address] = await getProgramDerivedAddress({\n programAddress: arciumProgram,\n seeds: [\n new TextEncoder().encode(ARCIUM_MEMPOOL_SEED),\n encodeU32ToU32LeBytes(BigInt(clusterOffset) as U32),\n ],\n });\n return address;\n}\n\n/**\n * Derives the Program Derived Address for an Arcium cluster executing pool account.\n * Seeds: [ARCIUM_EXEC_POOL_SEED, cluster_offset_u32_le] (against Arcium program)\n *\n * The executing pool account tracks computations currently being processed\n * by cluster nodes.\n *\n * @param arciumProgram - The Arcium program address.\n * @param clusterOffset - The cluster offset (u32).\n * @returns A Promise resolving to the derived executing pool account `Address`.\n *\n * @example\n * ```typescript\n * import { findArciumExecutingPoolPda } from \"@umbra-privacy/sdk\";\n *\n * const execPoolAccount = await findArciumExecutingPoolPda(\n * networkConfig.arciumProgramAddress,\n * networkConfig.clusterOffset,\n * );\n * ```\n *\n * @see {@link findArciumMempoolPda} for the pending computation queue\n * @see {@link findArciumClusterPda} for the parent cluster account\n *\n * @public\n */\nexport async function findArciumExecutingPoolPda(\n arciumProgram: Address,\n clusterOffset: number,\n): Promise<Address> {\n assertU32(BigInt(clusterOffset));\n const [address] = await getProgramDerivedAddress({\n programAddress: arciumProgram,\n seeds: [\n new TextEncoder().encode(ARCIUM_EXEC_POOL_SEED),\n encodeU32ToU32LeBytes(BigInt(clusterOffset) as U32),\n ],\n });\n return address;\n}\n\n/**\n * Derives the Program Derived Address for an individual Arcium computation account.\n * Seeds: [ARCIUM_COMPUTATION_SEED, cluster_offset_u32_le, computation_offset_u64_le] (against Arcium program)\n *\n * Each computation request gets its own account that stores the computation's\n * state. Created by `queue_computation` and closed when the callback executes.\n *\n * @param arciumProgram - The Arcium program address.\n * @param clusterOffset - The cluster offset (u32).\n * @param computationOffset - The computation offset (u64).\n * @returns A Promise resolving to the derived computation account `Address`.\n *\n * @example\n * ```typescript\n * import { findArciumComputationPda } from \"@umbra-privacy/sdk\";\n *\n * const computationAccount = await findArciumComputationPda(\n * networkConfig.arciumProgramAddress,\n * networkConfig.clusterOffset,\n * computationOffset,\n * );\n * ```\n *\n * @see {@link findArciumInfrastructurePdas} for deriving all required accounts at once\n * @see {@link findArciumCompDefPda} for the computation definition account\n *\n * @public\n */\nexport async function findArciumComputationPda(\n arciumProgram: Address,\n clusterOffset: number,\n computationOffset: bigint,\n): Promise<Address> {\n assertU32(BigInt(clusterOffset));\n assertU64(computationOffset);\n const [address] = await getProgramDerivedAddress({\n programAddress: arciumProgram,\n seeds: [\n new TextEncoder().encode(ARCIUM_COMPUTATION_SEED),\n encodeU32ToU32LeBytes(BigInt(clusterOffset) as U32),\n encodeU64ToU64LeBytes(computationOffset),\n ],\n });\n return address;\n}\n\n/**\n * Derives the Program Derived Address for an Arcium computation definition account.\n * Seeds: [ARCIUM_COMP_DEF_SEED, umbra_program_pubkey, comp_def_offset_u32_le] (against Arcium program)\n *\n * A computation definition account stores the encrypted circuit program that\n * cluster nodes execute for a specific Arcium instruction. One comp-def\n * account exists per Umbra instruction that uses Arcium MPC.\n *\n * @param umbraProgram - The Umbra program address.\n * @param arciumProgram - The Arcium program address.\n * @param compDefOffset - The computation definition offset, derived via\n * `computeCompDefOffset(instructionName)`.\n * @returns A Promise resolving to the derived comp-def account `Address`.\n *\n * @example\n * ```typescript\n * import { computeCompDefOffset, findArciumCompDefPda } from \"@umbra-privacy/sdk\";\n *\n * const offset = computeCompDefOffset(\"deposit_into_existing_mxe_v3\");\n * const compDefAccount = await findArciumCompDefPda(\n * networkConfig.programId,\n * networkConfig.arciumProgramAddress,\n * offset,\n * );\n * ```\n *\n * @see {@link computeCompDefOffset} for computing the offset from an instruction name\n * @see {@link findArciumInfrastructurePdas} for deriving all required accounts at once\n *\n * @public\n */\nexport async function findArciumCompDefPda(\n umbraProgram: Address,\n arciumProgram: Address,\n compDefOffset: number,\n): Promise<Address> {\n assertU32(BigInt(compDefOffset));\n const [address] = await getProgramDerivedAddress({\n programAddress: arciumProgram,\n seeds: [\n new TextEncoder().encode(ARCIUM_COMP_DEF_SEED),\n getAddressEncoder().encode(umbraProgram),\n encodeU32ToU32LeBytes(BigInt(compDefOffset) as U32),\n ],\n });\n return address;\n}\n\n/**\n * Derives the Program Derived Address for an Arcium cluster account.\n * Seeds: [ARCIUM_CLUSTER_SEED, cluster_offset_u32_le] (against Arcium program)\n *\n * A cluster account represents a group of Arcium MXE nodes that jointly\n * process computations using multi-party computation (MPC).\n *\n * @param arciumProgram - The Arcium program address.\n * @param clusterOffset - The cluster offset (u32).\n * @returns A Promise resolving to the derived cluster account `Address`.\n *\n * @example\n * ```typescript\n * import { findArciumClusterPda } from \"@umbra-privacy/sdk\";\n *\n * const clusterAccount = await findArciumClusterPda(\n * networkConfig.arciumProgramAddress,\n * networkConfig.clusterOffset,\n * );\n * ```\n *\n * @see {@link findArciumMempoolPda} for the cluster's pending computation queue\n * @see {@link findArciumExecutingPoolPda} for the cluster's active computation pool\n *\n * @public\n */\nexport async function findArciumClusterPda(\n arciumProgram: Address,\n clusterOffset: number,\n): Promise<Address> {\n assertU32(BigInt(clusterOffset));\n const [address] = await getProgramDerivedAddress({\n programAddress: arciumProgram,\n seeds: [\n new TextEncoder().encode(ARCIUM_CLUSTER_SEED),\n encodeU32ToU32LeBytes(BigInt(clusterOffset) as U32),\n ],\n });\n return address;\n}\n\n/* =============================================================================\n * AGGREGATE ADDRESS GENERATION\n * ============================================================================= */\n\n/**\n * Collection of all Arcium infrastructure account addresses needed to submit\n * a computation to the Arcium MPC network.\n *\n * @see {@link findArciumInfrastructurePdas} for the function that produces this object\n *\n * @public\n */\nexport interface ArciumInfrastructurePdas {\n /** The MXE protocol account address for the Umbra program. @readonly */\n readonly mxeAccount: Address;\n\n /** The mempool account address for the cluster. @readonly */\n readonly mempoolAccount: Address;\n\n /** The executing pool account address for the cluster. @readonly */\n readonly executingPoolAccount: Address;\n\n /** The computation account address for this specific computation request. @readonly */\n readonly computationAccount: Address;\n\n /** The computation definition account address for the target instruction. @readonly */\n readonly compDefAccount: Address;\n\n /** The cluster account address. @readonly */\n readonly clusterAccount: Address;\n}\n\n/**\n * Derives all Arcium infrastructure account addresses required for a single\n * computation request.\n *\n * This is a convenience function that computes all six required Arcium PDAs in\n * parallel and returns them as an {@link ArciumInfrastructurePdas} object.\n *\n * @param umbraProgram - The Umbra program address.\n * @param arciumProgram - The Arcium program address.\n * @param clusterOffset - The cluster offset identifying which Arcium cluster to use.\n * @param computationOffset - The unique u64 offset for this specific computation.\n * @param instructionName - The snake_case Arcium instruction name used to derive\n * the comp-def offset.\n * @returns A Promise resolving to an {@link ArciumInfrastructurePdas} object.\n *\n * @example\n * ```typescript\n * import { findArciumInfrastructurePdas } from \"@umbra-privacy/sdk\";\n *\n * const arciumAccounts = await findArciumInfrastructurePdas(\n * networkConfig.programId,\n * networkConfig.arciumProgramAddress,\n * networkConfig.clusterOffset,\n * computationOffset,\n * \"deposit_into_existing_mxe_v3\",\n * );\n * ```\n *\n * @see {@link computeCompDefOffset} for the comp-def offset derivation\n * @see {@link ArciumInfrastructurePdas} for the return type shape\n *\n * @public\n */\nexport async function findArciumInfrastructurePdas(\n umbraProgram: Address,\n arciumProgram: Address,\n clusterOffset: number,\n computationOffset: bigint,\n instructionName: string,\n): Promise<ArciumInfrastructurePdas> {\n const compDefOffset = computeCompDefOffset(instructionName);\n\n // Derive all addresses in parallel for efficiency\n const [\n mxeAccount,\n mempoolAccount,\n executingPoolAccount,\n computationAccount,\n compDefAccount,\n clusterAccount,\n ] = await Promise.all([\n findArciumMxePda(umbraProgram, arciumProgram),\n findArciumMempoolPda(arciumProgram, clusterOffset),\n findArciumExecutingPoolPda(arciumProgram, clusterOffset),\n findArciumComputationPda(arciumProgram, clusterOffset, computationOffset),\n findArciumCompDefPda(umbraProgram, arciumProgram, compDefOffset),\n findArciumClusterPda(arciumProgram, clusterOffset),\n ]);\n\n return {\n mxeAccount,\n mempoolAccount,\n executingPoolAccount,\n computationAccount,\n compDefAccount,\n clusterAccount,\n };\n}\n","/**\n * Compliance Grant PDA Utilities\n *\n * This module provides functions to derive Program Derived Addresses (PDAs)\n * for compliance grant accounts in the Umbra protocol.\n *\n * @remarks\n * Umbra implements a master viewing key system that allows authorised parties\n * to decrypt encrypted user data without gaining control over funds. Three\n * grant variants exist, each modelling a different trust relationship:\n *\n * - **Network grant** — the Arcium MXE network itself can decrypt the\n * user's data; the granter is implicitly the network. Used for regulatory\n * or protocol-level compliance.\n * - **Shared grant** — the user explicitly shares a re-encrypted view\n * key with the network for a specific receiver, scoped to a nonce to\n * prevent replay.\n * - **User grant** — the user directly grants a named receiver (e.g. an\n * auditor) the ability to read their encrypted data by re-encrypting the\n * view key under the receiver's X25519 public key.\n *\n * All three grant PDAs share a common prefix (`VIEWING_GRANT_SEED`)\n * and are disambiguated by a variant seed (`USER_GRANT_VARIANT_SEED`, etc.).\n * The nonce component prevents one grant from accidentally overwriting another.\n *\n * @see {@link findUserComplianceGrantPda}\n * @see {@link findNetworkComplianceGrantPda}\n * @see {@link findSharedComplianceGrantPda}\n *\n * @packageDocumentation\n * @since 2.0.0\n * @module utils/pda/compliance\n */\n\nimport { type Address, getProgramDerivedAddress } from \"@solana/kit\";\nimport {\n getArciumX25519NonceEncoder,\n getArciumX25519PublicKeyEncoder,\n} from \"@umbra-privacy/umbra-codama\";\nimport type { RcEncryptionNonce } from \"../../types\";\n\n/**\n * Seed prefix shared by all compliance grant PDAs.\n *\n * This is the SHA-256 hash of the UTF-8 string `\"ViewingGrant\"`,\n * encoded as a 32-byte `Uint8Array`. It matches the `SEED` constant generated\n * by the `#[umbra_account]` macro on the `ViewingGrant` struct in\n * `state/arcium/arcium_compliance_grant.rs`.\n *\n * @internal\n */\nconst VIEWING_GRANT_SEED = new Uint8Array([\n 209, 198, 56, 240, 66, 199, 19, 205, 112, 18, 168, 165, 236, 235, 81, 198, 191, 71, 73, 191, 110,\n 113, 189, 97, 139, 226, 152, 252, 229, 184, 187, 253,\n]);\n\n/**\n * Variant discriminator seed for user-granted compliance grants.\n *\n * This is the SHA-256 hash of the UTF-8 string `\"UserGrant\"`, encoded as a\n * 32-byte `Uint8Array`.\n *\n * @internal\n */\nconst USER_GRANT_VARIANT_SEED = new Uint8Array([\n 184, 137, 63, 24, 18, 54, 138, 200, 151, 217, 219, 241, 119, 150, 66, 8, 27, 105, 131, 187, 58,\n 182, 24, 203, 146, 119, 188, 210, 197, 104, 238, 33,\n]);\n\n/**\n * Variant discriminator seed for network MXE compliance grants.\n *\n * This is the SHA-256 hash of the UTF-8 string `\"NetworkMxeGrant\"`, encoded\n * as a 32-byte `Uint8Array`.\n *\n * @internal\n */\nconst NETWORK_MXE_GRANT_VARIANT_SEED = new Uint8Array([\n 142, 219, 209, 143, 158, 68, 71, 58, 193, 244, 116, 159, 48, 68, 160, 95, 175, 131, 151, 209, 81,\n 213, 51, 159, 98, 98, 138, 109, 254, 69, 221, 95,\n]);\n\n/**\n * Variant discriminator seed for network shared compliance grants.\n *\n * This is the SHA-256 hash of the UTF-8 string `\"NetworkSharedGrant\"`, encoded\n * as a 32-byte `Uint8Array`.\n *\n * @internal\n */\nconst NETWORK_SHARED_GRANT_VARIANT_SEED = new Uint8Array([\n 172, 245, 86, 61, 89, 235, 170, 92, 253, 117, 241, 14, 2, 33, 164, 107, 22, 131, 100, 113, 39,\n 173, 185, 55, 254, 100, 108, 218, 180, 105, 75, 184,\n]);\n\n/**\n * Derives the Program Derived Address for a user-granted compliance grant.\n * Seeds: [ViewingGrant::SEED, UserGrant::VARIANT, granter_x25519, nonce, receiver_x25519]\n *\n * A user-granted compliance grant stores a re-encrypted view of the granter's\n * private data under the receiver's X25519 public key, enabling a specific\n * party (e.g. an auditor) to decrypt the granter's encrypted balances.\n *\n * @param granterX25519 - The 32-byte X25519 public key of the granter.\n * @param nonce - A `RcEncryptionNonce` (u128) uniquely identifying this grant issuance.\n * @param receiverX25519 - The 32-byte X25519 public key of the receiver.\n * @param umbraProgram - The Umbra program address.\n * @returns A Promise resolving to the derived PDA `Address`.\n *\n * @example\n * ```typescript\n * import { findUserComplianceGrantPda } from \"@umbra-privacy/sdk\";\n *\n * const grantPda = await findUserComplianceGrantPda(\n * granterX25519PublicKey,\n * nonce,\n * auditorX25519PublicKey,\n * networkConfig.programId,\n * );\n * ```\n *\n * @see {@link findNetworkComplianceGrantPda} for network-level MXE grants\n * @see {@link findSharedComplianceGrantPda} for network shared grants\n *\n * @public\n */\nexport async function findUserComplianceGrantPda(\n granterX25519: Uint8Array,\n nonce: RcEncryptionNonce,\n receiverX25519: Uint8Array,\n umbraProgram: Address,\n): Promise<Address> {\n const [pda] = await getProgramDerivedAddress({\n programAddress: umbraProgram,\n seeds: [\n VIEWING_GRANT_SEED,\n USER_GRANT_VARIANT_SEED,\n getArciumX25519PublicKeyEncoder().encode({ first: granterX25519 }),\n getArciumX25519NonceEncoder().encode({ first: nonce }),\n getArciumX25519PublicKeyEncoder().encode({ first: receiverX25519 }),\n ],\n });\n return pda;\n}\n\n/**\n * Derives the Program Derived Address for a network (MXE) compliance grant.\n * Seeds: [ViewingGrant::SEED, NetworkMxeGrant::VARIANT, nonce, receiver_x25519]\n *\n * A network compliance grant allows the Arcium MXE network itself to\n * decrypt a user's encrypted data. There is no explicit granter key in the\n * seeds -- the granter is implicitly the network.\n *\n * @param nonce - A `RcEncryptionNonce` (u128) uniquely identifying this grant issuance.\n * @param receiverX25519 - The 32-byte X25519 public key of the receiver.\n * @param umbraProgram - The Umbra program address.\n * @returns A Promise resolving to the derived PDA `Address`.\n *\n * @example\n * ```typescript\n * import { findNetworkComplianceGrantPda } from \"@umbra-privacy/sdk\";\n *\n * const grantPda = await findNetworkComplianceGrantPda(\n * nonce,\n * networkX25519PublicKey,\n * networkConfig.programId,\n * );\n * ```\n *\n * @see {@link findUserComplianceGrantPda} for user-to-auditor grants\n * @see {@link findSharedComplianceGrantPda} for network shared grants\n *\n * @public\n */\nexport async function findNetworkComplianceGrantPda(\n nonce: RcEncryptionNonce,\n receiverX25519: Uint8Array,\n umbraProgram: Address,\n): Promise<Address> {\n const [pda] = await getProgramDerivedAddress({\n programAddress: umbraProgram,\n seeds: [\n VIEWING_GRANT_SEED,\n NETWORK_MXE_GRANT_VARIANT_SEED,\n getArciumX25519NonceEncoder().encode({ first: nonce }),\n getArciumX25519PublicKeyEncoder().encode({ first: receiverX25519 }),\n ],\n });\n return pda;\n}\n\n/**\n * Derives the Program Derived Address for a shared (network-shared) compliance grant.\n * Seeds: [ViewingGrant::SEED, NetworkSharedGrant::VARIANT, granter_x25519, nonce, receiver_x25519]\n *\n * A shared compliance grant is issued by a specific user to share a\n * re-encrypted view key with a named receiver via the Arcium network.\n * Unlike the network compliance grant, this variant includes the granter's\n * key so multiple users can each issue independent shared grants.\n *\n * @param granterX25519 - The 32-byte X25519 public key of the granter.\n * @param nonce - A `RcEncryptionNonce` (u128) uniquely identifying this grant issuance.\n * @param receiverX25519 - The 32-byte X25519 public key of the receiver.\n * @param umbraProgram - The Umbra program address.\n * @returns A Promise resolving to the derived PDA `Address`.\n *\n * @example\n * ```typescript\n * import { findSharedComplianceGrantPda } from \"@umbra-privacy/sdk\";\n *\n * const grantPda = await findSharedComplianceGrantPda(\n * granterX25519PublicKey,\n * nonce,\n * receiverX25519PublicKey,\n * networkConfig.programId,\n * );\n * ```\n *\n * @see {@link findUserComplianceGrantPda} for direct user-to-auditor grants\n * @see {@link findNetworkComplianceGrantPda} for implicit network-level grants\n *\n * @public\n */\nexport async function findSharedComplianceGrantPda(\n granterX25519: Uint8Array,\n nonce: RcEncryptionNonce,\n receiverX25519: Uint8Array,\n umbraProgram: Address,\n): Promise<Address> {\n const [pda] = await getProgramDerivedAddress({\n programAddress: umbraProgram,\n seeds: [\n VIEWING_GRANT_SEED,\n NETWORK_SHARED_GRANT_VARIANT_SEED,\n getArciumX25519PublicKeyEncoder().encode({ first: granterX25519 }),\n getArciumX25519NonceEncoder().encode({ first: nonce }),\n getArciumX25519PublicKeyEncoder().encode({ first: receiverX25519 }),\n ],\n });\n return pda;\n}\n","/**\n * Global PDA Utilities\n *\n * This module provides functions to derive Program Derived Addresses (PDAs)\n * for singleton program-level accounts in the Umbra protocol.\n *\n * Mirrors the smart contract's `state/global/` module, which holds\n * `ProtocolConfig` — a singleton account storing protocol-wide state.\n *\n * @remarks\n * There is exactly one `ProtocolConfig` account per Umbra program\n * deployment. It acts as the canonical source of truth for cross-instruction\n * protocol state: the index of the currently active mixer tree, global\n * feature activation flags, and the program upgrade authority. Most\n * instructions pass it as a read-only account for validation.\n *\n * @see {@link findProtocolConfigPda} for the derivation function\n * @see {@link findTokenPoolPda} for per-mint pool configuration\n *\n * @packageDocumentation\n * @since 2.0.0\n * @module utils/pda/global\n */\n\nimport { type Address, getProgramDerivedAddress } from \"@solana/kit\";\nimport { computeStructSeed } from \"./umbra\";\n\n/**\n * SHA-256 of the string `\"ProtocolConfig\"`, stored as a 32-byte `Uint8Array`.\n *\n * Matches `ProtocolConfig::SEED` as generated by the `#[umbra_account]`\n * macro in `state/global/program_information.rs`. This is the sole seed used\n * when deriving the singleton `ProtocolConfig` PDA.\n *\n * @internal\n */\nconst PROTOCOL_CONFIG_SEED = computeStructSeed(\"ProtocolConfig\");\n\n/**\n * Derives the Program Derived Address for the singleton protocol configuration account.\n * Seeds: [ProtocolConfig::SEED]\n *\n * The `ProtocolConfig` account stores global configuration state including\n * the active mixer tree index, feature flags, and the upgrade authority.\n *\n * @param umbraProgram - The Umbra program address.\n * @returns A Promise resolving to the derived PDA `Address`.\n *\n * @example\n * ```typescript\n * import { findProtocolConfigPda } from \"@umbra-privacy/sdk\";\n *\n * const protocolConfig = await findProtocolConfigPda(networkConfig.programId);\n * ```\n *\n * @see {@link findTokenPoolPda} for per-mint pool configuration\n * @see {@link findStealthPoolPda} for per-index mixer tree accounts\n *\n * @public\n */\nexport async function findProtocolConfigPda(umbraProgram: Address): Promise<Address> {\n const [pda] = await getProgramDerivedAddress({\n programAddress: umbraProgram,\n seeds: [PROTOCOL_CONFIG_SEED],\n });\n return pda;\n}\n","/**\n * Pool PDA Utilities\n *\n * This module provides functions to derive Program Derived Addresses (PDAs)\n * for pool-related accounts in the Umbra protocol.\n *\n * Mirrors the smart contract's `state/pool/` module, which holds the `Pool`\n * account — a per-mint configuration account that enables confidentiality and\n * mixer features for a specific SPL token.\n *\n * @remarks\n * The `Pool` account is a singleton per SPL token mint. It is created by the\n * protocol administrator and acts as the root configuration object for all\n * privacy operations involving that mint. Instructions that add or remove\n * privacy features (confidentiality, mixer) modify this account.\n *\n * @see {@link findTokenPoolPda} for the derivation function\n * @see {@link findProtocolConfigPda} for the global singleton that tracks active tree index\n *\n * @packageDocumentation\n * @since 2.0.0\n * @module utils/pda/pool\n */\n\nimport { type Address, getAddressEncoder, getProgramDerivedAddress } from \"@solana/kit\";\nimport { computeStructSeed } from \"./umbra\";\n\n/**\n * SHA-256 of the string `\"TokenPool\"`, stored as a 32-byte `Uint8Array`.\n *\n * Matches `Pool::SEED` as generated by the `#[umbra_account]` macro\n * in `state/pool/pool.rs`. Used as the first seed when deriving Pool PDAs.\n *\n * Also re-exported from the barrel (`index.ts`) as `TOKEN_POOL_SEED` for callers\n * that need the raw bytes — for example, to verify a PDA server-side without\n * calling `findTokenPoolPda`.\n *\n * @internal\n */\nexport const TOKEN_POOL_SEED = computeStructSeed(\"TokenPool\");\n\n/**\n * Derives the Program Derived Address for a token pool configuration account.\n * Seeds: [TokenPool::SEED, mint_pubkey]\n *\n * The `Pool` account is a per-mint singleton that stores whether\n * confidentiality and mixer features are activated for a specific SPL token.\n *\n * @param mintAddress - The SPL token mint address for this pool.\n * @param umbraProgram - The Umbra program address.\n * @returns A Promise resolving to the derived PDA `Address`.\n *\n * @example\n * ```typescript\n * import { findTokenPoolPda } from \"@umbra-privacy/sdk\";\n *\n * const pool = await findTokenPoolPda(mintAddress, networkConfig.programId);\n * ```\n *\n * @see {@link TOKEN_POOL_SEED} for the raw seed bytes\n * @see {@link findProtocolConfigPda} for the global singleton account\n *\n * @public\n */\nexport async function findTokenPoolPda(mintAddress: Address, umbraProgram: Address): Promise<Address> {\n const [pda] = await getProgramDerivedAddress({\n programAddress: umbraProgram,\n seeds: [TOKEN_POOL_SEED, getAddressEncoder().encode(mintAddress)],\n });\n return pda;\n}\n","/**\n * Relayer PDA Utilities\n *\n * This module provides functions to derive Program Derived Addresses (PDAs)\n * for relayer-related accounts in the Umbra protocol.\n *\n * Mirrors the smart contract's `state/relayer/` module, which holds:\n * - `Relayer` — a per-relayer, per-mint account that stores the\n * relayer's registration state and fee configuration references.\n *\n * @remarks\n * Relayers are permissioned transaction forwarders in the Umbra privacy\n * protocol. They submit user-generated proofs and encrypted payloads\n * on-chain, collecting a commission fee for the service. Each relayer must\n * register a `Relayer` for every SPL token mint they wish to support.\n *\n * The `Relayer` PDA is scoped to a `(relayer, mint)` pair so that a\n * single relayer wallet can independently manage fee configurations for\n * multiple mints without conflicting accounts.\n *\n * @see {@link findRelayerPda} for the derivation function\n * @see {@link findRelayerFeeVaultPda} for the associated fee pool derivation\n *\n * @packageDocumentation\n * @since 2.0.0\n * @module utils/pda/relayer\n */\n\nimport { type Address, getAddressEncoder, getProgramDerivedAddress } from \"@solana/kit\";\nimport { computeStructSeed } from \"./umbra\";\n\n/**\n * SHA-256 of the string `\"Relayer\"`, stored as a 32-byte `Uint8Array`.\n *\n * Matches `Relayer::SEED` as generated by the `#[umbra_account]`\n * macro in `state/relayer/relayer_account.rs`. Used as the first seed when\n * deriving `Relayer` PDAs.\n *\n * @internal\n */\nconst RELAYER_SEED = computeStructSeed(\"Relayer\");\n\n/**\n * Derives the Program Derived Address for a relayer registration account.\n * Seeds: [Relayer::SEED, relayer_pubkey, mint_pubkey]\n *\n * The `Relayer` stores a relayer's registration data and fee\n * configuration for a specific SPL token mint. A unique account exists per\n * `(relayer, mint)` pair.\n *\n * @param relayerAddress - The relayer's wallet public key.\n * @param mintAddress - The SPL token mint address that this relayer supports.\n * @param umbraProgram - The Umbra program address.\n * @returns A Promise resolving to the derived PDA `Address`.\n *\n * @example\n * ```typescript\n * import { findRelayerPda } from \"@umbra-privacy/sdk\";\n *\n * const relayerAccount = await findRelayerPda(\n * relayerPublicKey,\n * mintAddress,\n * networkConfig.programId,\n * );\n * ```\n *\n * @see {@link findRelayerFeeVaultPda} for the associated unified fee pool\n * @see {@link findFeeSchedulePda} for the fee rate configuration account\n *\n * @public\n */\nexport async function findRelayerPda(\n relayerAddress: Address,\n mintAddress: Address,\n umbraProgram: Address,\n): Promise<Address> {\n const addressEncoder = getAddressEncoder();\n const [pda] = await getProgramDerivedAddress({\n programAddress: umbraProgram,\n seeds: [\n RELAYER_SEED,\n addressEncoder.encode(relayerAddress),\n addressEncoder.encode(mintAddress),\n ],\n });\n return pda;\n}\n","/**\n * Fees PDA Utilities\n *\n * This module provides functions to derive Program Derived Addresses (PDAs)\n * for protocol and relayer fee accounts in the Umbra protocol.\n *\n * Mirrors the smart contract's `state/fees/` module, which holds:\n * - `FeeVault` — a single account storing both protocol and relayer fees,\n * partitioned by a domain seed into two variants:\n * - Protocol-only pools (deposits, withdrawals, public UTXO creation)\n * - Relayer pools (transfers, confidential/public claims)\n * - `FeeSchedule` — admin-managed fee rate config per mint\n *\n * @remarks\n * Umbra separates fee collection from fee disbursement by accumulating fees in\n * dedicated PDA accounts (`FeeVault`) that can be swept by the protocol\n * treasury or relayer at any time. The fee amount charged per instruction is\n * governed by the `FeeSchedule` account for that instruction + mint\n * pair.\n *\n * Both `FeeVault` variants and `FeeSchedule` include an\n * `offset` seed, following the canonical seed pattern:\n *\n * `SEED -> domain_seed (for fees pool) -> instructionSeed -> entity_key -> mint -> offset`\n *\n * The `offset` allows the protocol to create multiple fee pool or config\n * accounts for the same instruction + mint combination if needed in future.\n * Currently `offset` is always `0n` for `FeeSchedule` and an\n * instruction-specific constant for `FeeVault`.\n *\n * @see {@link findProtocolFeeVaultPda}\n * @see {@link findRelayerFeeVaultPda}\n * @see {@link findFeeSchedulePda}\n *\n * @packageDocumentation\n * @since 2.0.0\n * @module utils/pda/fees\n */\n\nimport { type Address, getAddressEncoder, getProgramDerivedAddress } from \"@solana/kit\";\nimport { getAccountOffsetEncoder } from \"@umbra-privacy/umbra-codama\";\nimport type { U128 } from \"../../types\";\nimport { encodeU128ToU128LeBytes } from \"../converters/mathematics\";\nimport { computeStructSeed } from \"./umbra\";\n\n/**\n * SHA-256 of the string `\"FeeVault\"`, stored as a 32-byte `Uint8Array`.\n *\n * Matches `FeeVault::SEED` as generated by the `#[umbra_account]`\n * macro in `state/fees/unified_fees_pool.rs`. Used as the first seed when\n * deriving all `FeeVault` PDAs (both protocol-only and relayer variants).\n *\n * @internal\n */\nconst FEE_VAULT_SEED = computeStructSeed(\"FeeVault\");\n\n/**\n * Domain separator that identifies protocol-only fee pools.\n *\n * This is the SHA-256 hash of `\"ProtocolFees\"`, matching\n * `FeeVault::DOMAIN_PROTOCOL_FEES` (`sha256_seed!(\"ProtocolFees\")`)\n * in `state/fees/unified_fees_pool.rs`.\n *\n * @internal\n */\nconst DOMAIN_PROTOCOL_FEES = computeStructSeed(\"ProtocolFees\");\n\n/**\n * Domain separator that identifies combined protocol + relayer fee pools.\n *\n * This is the SHA-256 hash of `\"ProtocolRelayerFees\"`, matching\n * `FeeVault::DOMAIN_PROTOCOL_RELAYER_FEES`\n * (`sha256_seed!(\"ProtocolRelayerFees\")`) in `state/fees/unified_fees_pool.rs`.\n *\n * @internal\n */\nconst DOMAIN_PROTOCOL_RELAYER_FEES = computeStructSeed(\"ProtocolRelayerFees\");\n\n/**\n * SHA-256 of the string `\"FeeSchedule\"`, stored as a 32-byte `Uint8Array`.\n *\n * Matches `FeeSchedule::SEED` as generated by the\n * `#[umbra_account]` macro in `state/fees/protocol_fees_configuration.rs`.\n * Used as the first seed when deriving `FeeSchedule` PDAs.\n *\n * @internal\n */\nconst FEE_SCHEDULE_SEED = computeStructSeed(\"FeeSchedule\");\n\n/**\n * SHA-256 of the string `\"RelayerFeeSchedule\"`, stored as a 32-byte `Uint8Array`.\n *\n * Matches `RelayerFeeSchedule::SEED` as generated by the `#[umbra_account]`\n * macro in `state/relayer/relayer_fees_configuration.rs`. Used as the first seed\n * when deriving `RelayerFeeSchedule` PDAs.\n *\n * @internal\n */\nconst RELAYER_FEE_SCHEDULE_SEED = computeStructSeed(\"RelayerFeeSchedule\");\n\n/**\n * Derives the Program Derived Address for a protocol-only fee vault account.\n * Seeds: [FeeVault::SEED, ProtocolFees::DOMAIN, instruction_seed, mint_pubkey, offset]\n *\n * Protocol-only fee pools accumulate the protocol's share of fees for\n * instructions that have no relayer commission component (deposits,\n * withdrawals, and public UTXO creation).\n *\n * @param instructionSeed - The instruction-specific U128 seed constant.\n * @param mintAddress - The SPL token mint address for this pool.\n * @param offset - The account offset discriminator (U128).\n * @param umbraProgram - The Umbra program address.\n * @returns A Promise resolving to the `[pda, bump]` tuple.\n *\n * @example\n * ```typescript\n * import { findProtocolFeeVaultPda } from \"@umbra-privacy/sdk\";\n *\n * const [feesPoolPda] = await findProtocolFeeVaultPda(\n * instructionSeed as U128,\n * mintAddress,\n * PROTOCOL_FEES_POOL_OFFSET as U128,\n * networkConfig.programId,\n * );\n * ```\n *\n * @see {@link findRelayerFeeVaultPda} for the relayer commission pool variant\n * @see {@link findFeeSchedulePda} for the fee rate configuration account\n *\n * @public\n */\nexport async function findProtocolFeeVaultPda(\n instructionSeed: U128,\n mintAddress: Address,\n offset: U128,\n umbraProgram: Address,\n): Promise<readonly [Address, number]> {\n const addressEncoder = getAddressEncoder();\n return getProgramDerivedAddress({\n programAddress: umbraProgram,\n seeds: [\n FEE_VAULT_SEED,\n DOMAIN_PROTOCOL_FEES,\n encodeU128ToU128LeBytes(instructionSeed),\n addressEncoder.encode(mintAddress),\n getAccountOffsetEncoder().encode({ first: BigInt(offset) }),\n ],\n });\n}\n\n/**\n * Derives the Program Derived Address for a relayer fee vault account.\n * Seeds: [FeeVault::SEED, ProtocolRelayerFees::DOMAIN, instruction_seed, relayer_pubkey, mint_pubkey, offset]\n *\n * Relayer fee pools accumulate both the protocol's share and the relayer's\n * commission for instructions that involve a relayer (claims and transfers).\n *\n * @param instructionSeed - The instruction-specific U128 seed constant.\n * @param relayerAddress - The relayer's wallet public key.\n * @param mintAddress - The SPL token mint address for this pool.\n * @param offset - The account offset discriminator (U128).\n * @param umbraProgram - The Umbra program address.\n * @returns A Promise resolving to the `[pda, bump]` tuple.\n *\n * @example\n * ```typescript\n * import { findRelayerFeeVaultPda } from \"@umbra-privacy/sdk\";\n *\n * const [unifiedFeesPoolPda] = await findRelayerFeeVaultPda(\n * instructionSeed as U128,\n * relayerPublicKey,\n * mintAddress,\n * PROTOCOL_FEES_POOL_OFFSET as U128,\n * networkConfig.programId,\n * );\n * ```\n *\n * @see {@link findProtocolFeeVaultPda} for the protocol-only pool variant\n * @see {@link findRelayerPda} for the relayer registration account\n *\n * @public\n */\nexport async function findRelayerFeeVaultPda(\n instructionSeed: U128,\n relayerAddress: Address,\n mintAddress: Address,\n offset: U128,\n umbraProgram: Address,\n): Promise<readonly [Address, number]> {\n const addressEncoder = getAddressEncoder();\n return getProgramDerivedAddress({\n programAddress: umbraProgram,\n seeds: [\n FEE_VAULT_SEED,\n DOMAIN_PROTOCOL_RELAYER_FEES,\n encodeU128ToU128LeBytes(instructionSeed),\n addressEncoder.encode(relayerAddress),\n addressEncoder.encode(mintAddress),\n getAccountOffsetEncoder().encode({ first: BigInt(offset) }),\n ],\n });\n}\n\n/**\n * Derives the Program Derived Address for a protocol fee schedule account.\n * Seeds: [FeeSchedule::SEED, instruction_seed, mint_pubkey, offset]\n *\n * The `FeeSchedule` account defines the fee rates for a specific instruction\n * variant and SPL token mint. Consulted during instruction validation to\n * calculate how much the user must pay.\n *\n * @param instructionSeed - The instruction-specific U128 seed constant.\n * @param mintAddress - The SPL token mint address for this fee configuration.\n * @param offset - The account offset discriminator (U128).\n * @param umbraProgram - The Umbra program address.\n * @returns A Promise resolving to the `[pda, bump]` tuple.\n *\n * @example\n * ```typescript\n * import { findFeeSchedulePda } from \"@umbra-privacy/sdk\";\n *\n * const [feeConfigPda] = await findFeeSchedulePda(\n * instructionSeed as U128,\n * mintAddress,\n * 0n as U128,\n * networkConfig.programId,\n * );\n * ```\n *\n * @see {@link findProtocolFeeVaultPda} for the corresponding fee collection account\n * @see {@link findRelayerFeeVaultPda} for the relayer fee collection account\n *\n * @public\n */\nexport async function findFeeSchedulePda(\n instructionSeed: U128,\n mintAddress: Address,\n offset: U128,\n umbraProgram: Address,\n): Promise<readonly [Address, number]> {\n const addressEncoder = getAddressEncoder();\n return getProgramDerivedAddress({\n programAddress: umbraProgram,\n seeds: [\n FEE_SCHEDULE_SEED,\n encodeU128ToU128LeBytes(instructionSeed),\n addressEncoder.encode(mintAddress),\n getAccountOffsetEncoder().encode({ first: BigInt(offset) }),\n ],\n });\n}\n\n/**\n * Derives the Program Derived Address for a relayer fee schedule account.\n * Seeds: [RelayerFeeSchedule::SEED, instruction_seed, relayer_pubkey, mint_pubkey, offset]\n *\n * The `RelayerFeeSchedule` account defines the fee rates a specific relayer\n * charges for a given instruction variant and SPL token mint.\n *\n * @param instructionSeed - The instruction-specific U128 seed constant.\n * @param relayerAddress - The relayer's wallet public key.\n * @param mintAddress - The SPL token mint address for this fee configuration.\n * @param offset - The account offset discriminator (U128).\n * @param umbraProgram - The Umbra program address.\n * @returns A Promise resolving to the `[pda, bump]` tuple.\n *\n * @public\n */\nexport async function findRelayerFeeSchedulePda(\n instructionSeed: U128,\n relayerAddress: Address,\n mintAddress: Address,\n offset: U128,\n umbraProgram: Address,\n): Promise<readonly [Address, number]> {\n const addressEncoder = getAddressEncoder();\n return getProgramDerivedAddress({\n programAddress: umbraProgram,\n seeds: [\n RELAYER_FEE_SCHEDULE_SEED,\n encodeU128ToU128LeBytes(instructionSeed),\n addressEncoder.encode(relayerAddress),\n addressEncoder.encode(mintAddress),\n getAccountOffsetEncoder().encode({ first: BigInt(offset) }),\n ],\n });\n}\n","/**\n * ZK and MPC Callback PDA Utilities\n *\n * This module provides functions to derive Program Derived Addresses (PDAs)\n * for zero-knowledge proof accounts and MPC callback data accounts in the\n * Umbra protocol.\n *\n * @see {@link findVerifyingKeyPda}\n * @see {@link findClaimInputBufferPda}\n * @see {@link findUtxoInputBufferPda}\n * @see {@link findPublicClaimInputBufferPda}\n * @see {@link findPublicClaimComputationDataPda}\n *\n * @packageDocumentation\n * @since 2.0.0\n * @module utils/pda/zk\n */\n\nimport { type Address, getAddressEncoder, getProgramDerivedAddress } from \"@solana/kit\";\nimport { getAccountOffsetEncoder } from \"@umbra-privacy/umbra-codama\";\nimport type { U128 } from \"../../types\";\nimport { encodeU128ToU128LeBytes } from \"../converters/mathematics\";\nimport { computeStructSeed } from \"./umbra\";\n\n/**\n * SHA-256 of the string `\"Groth16VerifyingKey\"`, stored as a 32-byte `Uint8Array`.\n * @internal\n */\nconst GROTH16_VERIFYING_KEY_SEED = computeStructSeed(\"Groth16VerifyingKey\");\n\n/**\n * SHA-256 of the string `\"ConfidentialClaimProofAccount\"`, stored as a 32-byte `Uint8Array`.\n * @internal\n */\nconst CONFIDENTIAL_CLAIM_PROOF_ACCOUNT_SEED = computeStructSeed(\"ConfidentialClaimProofAccount\");\n\n/**\n * SHA-256 of the string `\"ConfidentialUtxoProofAccount\"`, stored as a 32-byte `Uint8Array`.\n * @internal\n */\nconst CONFIDENTIAL_UTXO_PROOF_ACCOUNT_SEED = computeStructSeed(\"ConfidentialUtxoProofAccount\");\n\n/**\n * SHA-256 of the string `\"PublicUtxoProofAccount\"`, stored as a 32-byte `Uint8Array`.\n * @internal\n */\nconst PUBLIC_UTXO_PROOF_ACCOUNT_SEED = computeStructSeed(\"PublicUtxoProofAccount\");\n\n/**\n * SHA-256 of the string `\"PublicClaimProofAccount\"`, stored as a 32-byte `Uint8Array`.\n * @internal\n */\nconst PUBLIC_CLAIM_PROOF_ACCOUNT_SEED = computeStructSeed(\"PublicClaimProofAccount\");\n\n/**\n * SHA-256 of the string `\"PublicClaimMxeMpcCallbackData\"`, stored as a 32-byte `Uint8Array`.\n * @internal\n */\nconst PUBLIC_CLAIM_MXE_MPC_CALLBACK_DATA_SEED = computeStructSeed(\"PublicClaimMxeMpcCallbackData\");\n\n/**\n * Derives the Program Derived Address for a Groth16 verifying key account.\n * Seeds: [Groth16VerifyingKey::SEED, instruction_seed]\n *\n * Stores the on-chain Groth16 verifying key for a specific proof circuit\n * variant. Set up by the protocol administrator and read as immutable input\n * in claim and UTXO instructions.\n *\n * @param instructionSeed - The U128 seed identifying the specific verifying key.\n * @param umbraProgram - The Umbra program address.\n * @returns A Promise resolving to the derived PDA `Address`.\n *\n * @example\n * ```typescript\n * import { findVerifyingKeyPda } from \"@umbra-privacy/sdk\";\n *\n * const zkVerifyingKeyAccount = await findVerifyingKeyPda(\n * zkSeed as U128,\n * networkConfig.programId,\n * );\n * ```\n *\n * @see {@link findClaimInputBufferPda} for the proof buffer read alongside this account\n *\n * @public\n */\nexport async function findVerifyingKeyPda(\n instructionSeed: U128,\n umbraProgram: Address,\n): Promise<Address> {\n const [pda] = await getProgramDerivedAddress({\n programAddress: umbraProgram,\n seeds: [GROTH16_VERIFYING_KEY_SEED, encodeU128ToU128LeBytes(instructionSeed)],\n });\n return pda;\n}\n\n/**\n * Derives the Program Derived Address for a confidential claim input buffer account.\n * Seeds: [ConfidentialClaimProofAccount::SEED, payer_pubkey, offset]\n *\n * An ephemeral buffer account that holds the Groth16 proof bytes and encrypted\n * public inputs required for a confidential claim instruction. Created by the\n * relayer, consumed by the claim instruction, and closed in the MPC callback.\n *\n * @param payerAddress - The relayer's public key (proof account creator).\n * @param offset - The U128 offset discriminator.\n * @param umbraProgram - The Umbra program address.\n * @returns A Promise resolving to the derived PDA `Address`.\n *\n * @example\n * ```typescript\n * import { findClaimInputBufferPda } from \"@umbra-privacy/sdk\";\n *\n * const proofAccountPda = await findClaimInputBufferPda(\n * relayerPublicKey,\n * proofAccountOffset as U128,\n * networkConfig.programId,\n * );\n * ```\n *\n * @see {@link findVerifyingKeyPda} for the verifying key used to check this proof\n * @see {@link findPublicClaimInputBufferPda} for the public-balance claim variant\n *\n * @public\n */\nexport async function findClaimInputBufferPda(\n payerAddress: Address,\n offset: U128,\n umbraProgram: Address,\n): Promise<Address> {\n const [pda] = await getProgramDerivedAddress({\n programAddress: umbraProgram,\n seeds: [\n CONFIDENTIAL_CLAIM_PROOF_ACCOUNT_SEED,\n getAddressEncoder().encode(payerAddress),\n getAccountOffsetEncoder().encode({ first: BigInt(offset) }),\n ],\n });\n return pda;\n}\n\n/**\n * Derives the Program Derived Address for a confidential UTXO input buffer account.\n * Seeds: [ConfidentialUtxoProofAccount::SEED, depositor_pubkey, offset]\n *\n * An ephemeral buffer account that holds the Groth16 proof data required to\n * create a new confidential UTXO from an existing encrypted MXE balance.\n *\n * @param depositorAddress - The depositor's public key (account creator).\n * @param offset - The U128 offset discriminator.\n * @param umbraProgram - The Umbra program address.\n * @returns A Promise resolving to the derived PDA `Address`.\n *\n * @example\n * ```typescript\n * import { findUtxoInputBufferPda } from \"@umbra-privacy/sdk\";\n *\n * const proofAccountPda = await findUtxoInputBufferPda(\n * client.signer.address,\n * offset as U128,\n * networkConfig.programId,\n * );\n * ```\n *\n * @see {@link findVerifyingKeyPda} for the verifying key used to check this proof\n * @see {@link findClaimInputBufferPda} for the claim-side proof buffer\n *\n * @public\n */\nexport async function findUtxoInputBufferPda(\n depositorAddress: Address,\n offset: U128,\n umbraProgram: Address,\n): Promise<Address> {\n const [pda] = await getProgramDerivedAddress({\n programAddress: umbraProgram,\n seeds: [\n CONFIDENTIAL_UTXO_PROOF_ACCOUNT_SEED,\n getAddressEncoder().encode(depositorAddress),\n getAccountOffsetEncoder().encode({ first: BigInt(offset) }),\n ],\n });\n return pda;\n}\n\n/**\n * Derives the Program Derived Address for a public UTXO input buffer account.\n * Seeds: [PublicUtxoProofAccount::SEED, depositor_pubkey, offset]\n *\n * An ephemeral buffer account that holds cryptographic proof data for the\n * `create_deposit_into_mixer_tree_from_public_balance` instruction.\n *\n * @param depositorAddress - The depositor's public key (account creator).\n * @param offset - The U128 offset discriminator.\n * @param umbraProgram - The Umbra program address.\n * @returns A Promise resolving to the derived PDA `Address`.\n *\n * @public\n */\nexport async function findPublicUtxoInputBufferPda(\n depositorAddress: Address,\n offset: U128,\n umbraProgram: Address,\n): Promise<Address> {\n const [pda] = await getProgramDerivedAddress({\n programAddress: umbraProgram,\n seeds: [\n PUBLIC_UTXO_PROOF_ACCOUNT_SEED,\n getAddressEncoder().encode(depositorAddress),\n getAccountOffsetEncoder().encode({ first: BigInt(offset) }),\n ],\n });\n return pda;\n}\n\n/**\n * Derives the Program Derived Address for a public claim input buffer account.\n * Seeds: [PublicClaimProofAccount::SEED, relayer_pubkey, offset]\n *\n * An ephemeral buffer account that holds the Groth16 proof data for a\n * public-balance claim instruction (claiming UTXOs into a standard SPL\n * token ATA).\n *\n * @param relayerAddress - The relayer's public key (proof account creator).\n * @param offset - The U128 offset discriminator.\n * @param umbraProgram - The Umbra program address.\n * @returns A Promise resolving to the derived PDA `Address`.\n *\n * @example\n * ```typescript\n * import { findPublicClaimInputBufferPda } from \"@umbra-privacy/sdk\";\n *\n * const proofAccountPda = await findPublicClaimInputBufferPda(\n * relayerPublicKey,\n * proofAccountOffset as U128,\n * networkConfig.programId,\n * );\n * ```\n *\n * @see {@link findVerifyingKeyPda} for the verifying key used to check this proof\n * @see {@link findClaimInputBufferPda} for the confidential-balance claim variant\n * @see {@link findPublicClaimComputationDataPda} for the companion MPC callback data account\n *\n * @public\n */\nexport async function findPublicClaimInputBufferPda(\n relayerAddress: Address,\n offset: U128,\n umbraProgram: Address,\n): Promise<Address> {\n const [pda] = await getProgramDerivedAddress({\n programAddress: umbraProgram,\n seeds: [\n PUBLIC_CLAIM_PROOF_ACCOUNT_SEED,\n getAddressEncoder().encode(relayerAddress),\n getAccountOffsetEncoder().encode({ first: BigInt(offset) }),\n ],\n });\n return pda;\n}\n\n/**\n * Derives the Program Derived Address for a public claim MPC computation data account.\n * Seeds: [PublicClaimMxeMpcCallbackData::SEED, relayer_pubkey, offset]\n *\n * Stores all data needed by the Arcium MPC callback handler for a public\n * claim instruction. Initialised in the handler and closed when the callback\n * executes.\n *\n * Returns the full `[address, bump]` tuple because the canonical bump must be\n * passed as the `mpcCallbackDataCanonicalBump` instruction argument.\n *\n * @param relayerAddress - The relayer's public key.\n * @param offset - The U128 offset discriminator.\n * @param umbraProgram - The Umbra program address.\n * @returns A Promise resolving to the `[pda, bump]` tuple.\n *\n * @example\n * ```typescript\n * import { findPublicClaimComputationDataPda } from \"@umbra-privacy/sdk\";\n *\n * const [callbackDataPda, mpcCallbackDataCanonicalBump] =\n * await findPublicClaimComputationDataPda(\n * relayerPublicKey,\n * 0n as U128,\n * networkConfig.programId,\n * );\n * ```\n *\n * @see {@link findPublicClaimInputBufferPda} for the companion proof buffer account\n *\n * @public\n */\nexport async function findPublicClaimComputationDataPda(\n relayerAddress: Address,\n offset: U128,\n umbraProgram: Address,\n): Promise<readonly [Address, number]> {\n return getProgramDerivedAddress({\n programAddress: umbraProgram,\n seeds: [\n PUBLIC_CLAIM_MXE_MPC_CALLBACK_DATA_SEED,\n getAddressEncoder().encode(relayerAddress),\n getAccountOffsetEncoder().encode({ first: BigInt(offset) }),\n ],\n });\n}\n"]}
@@ -0,0 +1,207 @@
1
+ 'use strict';
2
+
3
+ var chunkPK6SKIKE_cjs = require('./chunk-PK6SKIKE.cjs');
4
+ var kit = require('@solana/kit');
5
+
6
+ var ENDPOINTS = {
7
+ /** Fetches relayer address, supported mints, and active stealth pool indices. */
8
+ RELAYER_INFO: `/v1/relayer/info`,
9
+ /** Submits a claim request (relayer builds transactions from crypto data). */
10
+ CLAIM_SUBMIT: `/v1/claims`,
11
+ /** Polls claim status by request ID. `{id}` is replaced at call time. */
12
+ CLAIM_STATUS: `/v1/claims/{id}`
13
+ };
14
+ var RelayerError = class _RelayerError extends Error {
15
+ static {
16
+ chunkPK6SKIKE_cjs.__name(this, "RelayerError");
17
+ }
18
+ /** The relayer operation that failed (e.g. `"getRelayerAddress"`, `"claimSubmit"`). */
19
+ operation;
20
+ /** HTTP status code if the server responded, `undefined` for transport errors. */
21
+ statusCode;
22
+ /** Machine-readable error code from the API error body. */
23
+ errorCode;
24
+ constructor(operation, message, statusCode, errorCode, cause) {
25
+ super(`Relayer operation '${operation}' failed: ${message}`);
26
+ this.name = "RelayerError";
27
+ this.operation = operation;
28
+ this.statusCode = statusCode;
29
+ this.errorCode = errorCode;
30
+ this.cause = cause;
31
+ if (Error.captureStackTrace !== void 0) {
32
+ Error.captureStackTrace(this, _RelayerError);
33
+ }
34
+ }
35
+ };
36
+ async function makeRequest(endpoint, fetchImpl, options) {
37
+ const { method = "GET", body, operation } = options;
38
+ try {
39
+ const requestInit = {
40
+ method,
41
+ headers: {
42
+ "Content-Type": "application/json",
43
+ Accept: "application/json"
44
+ }
45
+ };
46
+ if (body !== void 0) {
47
+ requestInit.body = JSON.stringify(body);
48
+ }
49
+ const response = await fetchImpl(endpoint, requestInit);
50
+ const data = await response.json();
51
+ if (!response.ok) {
52
+ const errorData = data;
53
+ const message = errorData.error?.message ?? errorData.message ?? `HTTP ${String(response.status)}`;
54
+ const code = errorData.error?.code ?? errorData.error_code;
55
+ throw new RelayerError(operation, message, response.status, code);
56
+ }
57
+ return data;
58
+ } catch (error) {
59
+ if (error instanceof RelayerError) {
60
+ throw error;
61
+ }
62
+ throw new RelayerError(
63
+ operation,
64
+ error instanceof Error ? error.message : "Unknown error",
65
+ void 0,
66
+ void 0,
67
+ error instanceof Error ? error : void 0
68
+ );
69
+ }
70
+ }
71
+ chunkPK6SKIKE_cjs.__name(makeRequest, "makeRequest");
72
+ function convertClaimStatusResponse(api) {
73
+ return {
74
+ requestId: api.request_id,
75
+ status: api.status,
76
+ variant: api.variant,
77
+ resolvedVariant: api.resolved_variant,
78
+ txSignature: api.tx_signature,
79
+ callbackSignature: api.callback_signature,
80
+ computationAccount: api.computation_account,
81
+ failureReason: api.failure_reason,
82
+ createdAt: api.created_at,
83
+ updatedAt: api.updated_at
84
+ };
85
+ }
86
+ chunkPK6SKIKE_cjs.__name(convertClaimStatusResponse, "convertClaimStatusResponse");
87
+ function getUmbraRelayer(args, deps) {
88
+ const { apiEndpoint } = args;
89
+ const fetchImpl = deps?.fetch ?? globalThis.fetch;
90
+ if (apiEndpoint === "") {
91
+ throw new RelayerError("initialization", "apiEndpoint must be a non-empty string");
92
+ }
93
+ const normalizedEndpoint = apiEndpoint.replace(/\/$/, "");
94
+ let cachedAddress = null;
95
+ let cachedInfo = null;
96
+ async function fetchInfo() {
97
+ if (cachedInfo !== null) {
98
+ return cachedInfo;
99
+ }
100
+ const response = await makeRequest(
101
+ `${normalizedEndpoint}${ENDPOINTS.RELAYER_INFO}`,
102
+ fetchImpl,
103
+ { operation: "getRelayerInfo" }
104
+ );
105
+ cachedInfo = response;
106
+ cachedAddress = kit.address(response.address);
107
+ return response;
108
+ }
109
+ chunkPK6SKIKE_cjs.__name(fetchInfo, "fetchInfo");
110
+ return {
111
+ apiEndpoint: normalizedEndpoint,
112
+ async getFeePayer() {
113
+ if (cachedAddress !== null) {
114
+ return cachedAddress;
115
+ }
116
+ const info = await fetchInfo();
117
+ return kit.address(info.address);
118
+ },
119
+ async getRelayerAddress() {
120
+ if (cachedAddress !== null) {
121
+ return cachedAddress;
122
+ }
123
+ const info = await fetchInfo();
124
+ return kit.address(info.address);
125
+ },
126
+ async getSupportedMints() {
127
+ const info = await fetchInfo();
128
+ return {
129
+ relayer: info.address,
130
+ mints: info.supported_mints,
131
+ count: BigInt(info.supported_mints.length)
132
+ };
133
+ },
134
+ async submitClaim(request) {
135
+ const response = await makeRequest(
136
+ `${normalizedEndpoint}${ENDPOINTS.CLAIM_SUBMIT}`,
137
+ fetchImpl,
138
+ { method: "POST", body: request, operation: "claimSubmit" }
139
+ );
140
+ return {
141
+ requestId: response.request_id,
142
+ status: response.status
143
+ };
144
+ },
145
+ async pollClaimStatus(requestId) {
146
+ const url = `${normalizedEndpoint}${ENDPOINTS.CLAIM_STATUS.replace("{id}", requestId)}`;
147
+ const response = await makeRequest(url, fetchImpl, {
148
+ operation: "claimStatus"
149
+ });
150
+ return convertClaimStatusResponse(response);
151
+ }
152
+ };
153
+ }
154
+ chunkPK6SKIKE_cjs.__name(getUmbraRelayer, "getUmbraRelayer");
155
+ var TERMINAL_CLAIM_STATUSES = /* @__PURE__ */ new Set([
156
+ "completed",
157
+ "failed",
158
+ "timed_out"
159
+ ]);
160
+ async function pollClaimUntilTerminal(pollClaimStatus, requestId, options) {
161
+ const pollingIntervalMs = options?.pollingIntervalMs ?? 3e3;
162
+ const timeoutMs = options?.timeoutMs ?? 12e4;
163
+ const onProgress = options?.onProgress;
164
+ const startTime = Date.now();
165
+ while (true) {
166
+ const status = await pollClaimStatus(requestId);
167
+ if (onProgress !== void 0) {
168
+ onProgress({
169
+ requestId: status.requestId,
170
+ status: status.status,
171
+ resolvedVariant: status.resolvedVariant,
172
+ txSignature: status.txSignature,
173
+ callbackSignature: status.callbackSignature,
174
+ failureReason: status.failureReason
175
+ });
176
+ }
177
+ if (TERMINAL_CLAIM_STATUSES.has(status.status)) {
178
+ const result = {
179
+ requestId: status.requestId,
180
+ status: status.status,
181
+ txSignature: status.txSignature,
182
+ callbackSignature: status.callbackSignature,
183
+ resolvedVariant: status.resolvedVariant,
184
+ failureReason: status.failureReason
185
+ };
186
+ return result;
187
+ }
188
+ if (Date.now() - startTime >= timeoutMs) {
189
+ const timedOutResult = {
190
+ requestId: status.requestId,
191
+ status: "timed_out",
192
+ failureReason: `Polling timed out after ${String(timeoutMs)}ms (last status: ${String(status.status)})`
193
+ };
194
+ return timedOutResult;
195
+ }
196
+ await new Promise((resolve) => {
197
+ setTimeout(resolve, pollingIntervalMs);
198
+ });
199
+ }
200
+ }
201
+ chunkPK6SKIKE_cjs.__name(pollClaimUntilTerminal, "pollClaimUntilTerminal");
202
+
203
+ exports.RelayerError = RelayerError;
204
+ exports.getUmbraRelayer = getUmbraRelayer;
205
+ exports.pollClaimUntilTerminal = pollClaimUntilTerminal;
206
+ //# sourceMappingURL=chunk-NKVMSABR.cjs.map
207
+ //# sourceMappingURL=chunk-NKVMSABR.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/umbra/relayer.ts"],"names":["__name","address"],"mappings":";;;;;AAkDA,IAAM,SAAA,GAAY;AAAA;AAAA,EAEhB,YAAA,EAAc,CAAA,gBAAA,CAAA;AAAA;AAAA,EAEd,YAAA,EAAc,CAAA,UAAA,CAAA;AAAA;AAAA,EAEd,YAAA,EAAc,CAAA,eAAA;AAChB,CAAA;AAgBO,IAAM,YAAA,GAAN,MAAM,aAAA,SAAqB,KAAA,CAAM;AAAA,EAzExC;AAyEwC,IAAAA,wBAAA,CAAA,IAAA,EAAA,cAAA,CAAA;AAAA;AAAA;AAAA,EAEtB,SAAA;AAAA;AAAA,EAEA,UAAA;AAAA;AAAA,EAEA,SAAA;AAAA,EAEhB,WAAA,CACE,SAAA,EACA,OAAA,EACA,UAAA,EACA,WACA,KAAA,EACA;AACA,IAAA,KAAA,CAAM,CAAA,mBAAA,EAAsB,SAAS,CAAA,UAAA,EAAa,OAAO,CAAA,CAAE,CAAA;AAC3D,IAAA,IAAA,CAAK,IAAA,GAAO,cAAA;AACZ,IAAA,IAAA,CAAK,SAAA,GAAY,SAAA;AACjB,IAAA,IAAA,CAAK,UAAA,GAAa,UAAA;AAClB,IAAA,IAAA,CAAK,SAAA,GAAY,SAAA;AACjB,IAAA,IAAA,CAAK,KAAA,GAAQ,KAAA;AAEb,IAAA,IAAI,KAAA,CAAM,sBAAsB,MAAA,EAAW;AACzC,MAAA,KAAA,CAAM,iBAAA,CAAkB,MAAM,aAAY,CAAA;AAAA,IAC5C;AAAA,EACF;AACF;AAoDA,eAAe,WAAA,CACb,QAAA,EACA,SAAA,EACA,OAAA,EAKY;AACZ,EAAA,MAAM,EAAE,MAAA,GAAS,KAAA,EAAO,IAAA,EAAM,WAAU,GAAI,OAAA;AAE5C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AAI,MAAA,CAAO,MAAM,CAAA,EAAG;AAC9C,MAAA,MAAM,MAAA,GAA2B;AAAA,QAC/B,WAAW,MAAA,CAAO,SAAA;AAAA,QAClB,QAAQ,MAAA,CAAO,MAAA;AAAA,QACf,aAAa,MAAA,CAAO,WAAA;AAAA,QACpB,mBAAmB,MAAA,CAAO,iBAAA;AAAA,QAC1B,iBAAiB,MAAA,CAAO,eAAA;AAAA,QACxB,eAAe,MAAA,CAAO;AAAA,OACxB;AACA,MAAA,OAAO,MAAA;AAAA,IACT;AAEA,IAAA,IAAI,IAAA,CAAK,GAAA,EAAI,GAAI,SAAA,IAAa,SAAA,EAAW;AACvC,MAAA,MAAM,cAAA,GAAmC;AAAA,QACvC,WAAW,MAAA,CAAO,SAAA;AAAA,QAClB,MAAA,EAAQ,WAAA;AAAA,QACR,aAAA,EAAe,2BAA2B,MAAA,CAAO,SAAS,CAAC,CAAA,iBAAA,EAAoB,MAAA,CAAO,MAAA,CAAO,MAAM,CAAC,CAAA,CAAA;AAAA,OACtG;AACA,MAAA,OAAO,cAAA;AAAA,IACT;AAEA,IAAA,MAAM,IAAI,OAAA,CAAc,CAAC,OAAA,KAAY;AACnC,MAAA,UAAA,CAAW,SAAS,iBAAiB,CAAA;AAAA,IACvC,CAAC,CAAA;AAAA,EACH;AACF;AA9DsBA,wBAAA,CAAA,sBAAA,EAAA,wBAAA,CAAA","file":"chunk-NKVMSABR.cjs","sourcesContent":["/**\n * Relayer Module (V2 API).\n *\n * @remarks\n * This module provides the `getUmbraRelayer` factory for creating relayer instances\n * that interact with the Umbra relayer's V2 API. The relayer builds, signs, and\n * submits claim transactions on behalf of users.\n *\n * **What is the Relayer?**\n * The Umbra relayer is a semi-trusted intermediary that submits privacy-preserving\n * transactions on behalf of users. It receives cryptographic data (ZK proofs,\n * nullifiers, linker encryptions) and builds all Solana transactions server-side.\n *\n * **Trust Model (Semi-Trusted):**\n * The relayer is SEMI-TRUSTED. It can observe transaction contents (amounts,\n * mints, timing) because it must broadcast them. However, it CANNOT:\n * - Steal funds — ZK proofs and nullifier commitments prevent double-spending\n * - Forge signatures — Transactions use cryptographic commitments verified on-chain\n * - Link sender to recipient — Merkle commitments and ZK proofs sever that link\n *\n * **API Endpoints Used:**\n * - `GET /v1/relayer/info` — Get relayer address, supported mints, active pools\n * - `POST /v1/claims` — Submit a claim request (relayer builds transactions)\n * - `GET /v1/claims/{id}` — Poll claim status\n *\n * @packageDocumentation\n */\n\nimport { address, type Address } from \"@solana/kit\";\nimport type { U32 } from \"../types\";\nimport type {\n IUmbraRelayer,\n GetUmbraRelayerArgs,\n GetUmbraRelayerDeps,\n SupportedMintsResponse,\n ClaimRequest,\n ClaimSubmitResponse,\n ClaimStatusResponse,\n ClaimStatus,\n ClaimBatchResult,\n} from \"./interfaces\";\n\n// ============================================================================\n// Constants\n// ============================================================================\n\n/**\n * Canonical endpoint paths for all relayer API operations.\n * @internal\n */\nconst ENDPOINTS = {\n /** Fetches relayer address, supported mints, and active stealth pool indices. */\n RELAYER_INFO: `/v1/relayer/info`,\n /** Submits a claim request (relayer builds transactions from crypto data). */\n CLAIM_SUBMIT: `/v1/claims`,\n /** Polls claim status by request ID. `{id}` is replaced at call time. */\n CLAIM_STATUS: `/v1/claims/{id}`,\n} as const;\n\n// ============================================================================\n// Error Class\n// ============================================================================\n\n/**\n * Error class for relayer-related failures.\n *\n * @remarks\n * Thrown when relayer API calls fail due to network issues, invalid responses,\n * transaction rejections, or server errors. Provides structured fields for\n * programmatic error handling.\n *\n * @public\n */\nexport class RelayerError extends Error {\n /** The relayer operation that failed (e.g. `\"getRelayerAddress\"`, `\"claimSubmit\"`). */\n public readonly operation: string;\n /** HTTP status code if the server responded, `undefined` for transport errors. */\n public readonly statusCode: number | undefined;\n /** Machine-readable error code from the API error body. */\n public readonly errorCode: string | undefined;\n\n constructor(\n operation: string,\n message: string,\n statusCode?: number,\n errorCode?: string,\n cause?: Error,\n ) {\n super(`Relayer operation '${operation}' failed: ${message}`);\n this.name = \"RelayerError\";\n this.operation = operation;\n this.statusCode = statusCode;\n this.errorCode = errorCode;\n this.cause = cause;\n\n if (Error.captureStackTrace !== undefined) {\n Error.captureStackTrace(this, RelayerError);\n }\n }\n}\n\n// ============================================================================\n// Internal Types (API Response Shapes)\n// ============================================================================\n\n/** @internal */\ninterface ApiErrorResponse {\n error?: {\n code: string;\n message: string;\n };\n success?: false;\n error_code?: string;\n message?: string;\n}\n\n/** Shape of `GET /v1/relayer/info` response. @internal */\ninterface ApiRelayerInfoResponse {\n address: string;\n supported_mints: string[];\n active_stealth_pool_indices: string[];\n}\n\n/** Shape of `POST /v1/claims` response. @internal */\ninterface ApiClaimSubmitResponse {\n request_id: string;\n status: \"received\";\n}\n\n/** Shape of `GET /v1/claims/{id}` response. @internal */\ninterface ApiClaimStatusResponse {\n request_id: string;\n status: string;\n variant: string;\n resolved_variant?: string;\n tx_signature?: string;\n callback_signature?: string;\n computation_account?: string;\n failure_reason?: string | null;\n created_at: string;\n updated_at: string;\n}\n\n// ============================================================================\n// Internal Helpers\n// ============================================================================\n\n/**\n * Generic HTTP request helper with structured error handling.\n * @internal\n */\nasync function makeRequest<T>(\n endpoint: string,\n fetchImpl: typeof globalThis.fetch,\n options: {\n method?: \"GET\" | \"POST\";\n body?: unknown;\n operation: string;\n },\n): Promise<T> {\n const { method = \"GET\", body, operation } = options;\n\n try {\n const requestInit: RequestInit = {\n method,\n headers: {\n \"Content-Type\": \"application/json\",\n Accept: \"application/json\",\n },\n };\n if (body !== undefined) {\n requestInit.body = JSON.stringify(body);\n }\n const response = await fetchImpl(endpoint, requestInit);\n\n const data = (await response.json()) as T | ApiErrorResponse;\n\n if (!response.ok) {\n const errorData = data as ApiErrorResponse;\n const message =\n errorData.error?.message ?? errorData.message ?? `HTTP ${String(response.status)}`;\n const code = errorData.error?.code ?? errorData.error_code;\n throw new RelayerError(operation, message, response.status, code);\n }\n\n return data as T;\n } catch (error) {\n if (error instanceof RelayerError) {\n throw error;\n }\n throw new RelayerError(\n operation,\n error instanceof Error ? error.message : \"Unknown error\",\n undefined,\n undefined,\n error instanceof Error ? error : undefined,\n );\n }\n}\n\n/** Converts wire-format claim status response to SDK type. @internal */\nfunction convertClaimStatusResponse(api: ApiClaimStatusResponse): ClaimStatusResponse {\n return {\n requestId: api.request_id,\n status: api.status as ClaimStatus,\n variant: api.variant as ClaimStatusResponse[\"variant\"],\n resolvedVariant: api.resolved_variant,\n txSignature: api.tx_signature,\n callbackSignature: api.callback_signature,\n computationAccount: api.computation_account,\n failureReason: api.failure_reason,\n createdAt: api.created_at,\n updatedAt: api.updated_at,\n };\n}\n\n// ============================================================================\n// Core Relayer Factory\n// ============================================================================\n\n/**\n * Creates an Umbra relayer instance.\n *\n * @remarks\n * The returned `IUmbraRelayer` object provides all methods needed by claim\n * services: relayer info, claim submission, and status polling. Pass it\n * directly as the `relayer` dependency to any claim function.\n *\n * **Address caching:**\n * `getRelayerAddress()` and `getFeePayer()` cache the result after the first\n * HTTP call. The cache is per-instance.\n *\n * @param args - Required arguments\n * @param args.apiEndpoint - The base URL of the relayer API\n * @param deps - Optional dependencies for testing\n * @param deps.fetch - Custom fetch implementation; defaults to `globalThis.fetch`\n * @returns An {@link IUmbraRelayer} instance\n *\n * @example\n * ```typescript\n * const relayer = getUmbraRelayer({ apiEndpoint: \"https://relayer.umbra.finance\" });\n *\n * // Use directly with claim functions\n * const claim = getSelfClaimableUtxoToEncryptedBalanceClaimerFunction(\n * { client },\n * { zkProver, relayer },\n * );\n * ```\n *\n * @public\n */\nexport function getUmbraRelayer(\n args: GetUmbraRelayerArgs,\n deps?: GetUmbraRelayerDeps,\n): IUmbraRelayer {\n const { apiEndpoint } = args;\n const fetchImpl = deps?.fetch ?? globalThis.fetch;\n\n if (apiEndpoint === \"\") {\n throw new RelayerError(\"initialization\", \"apiEndpoint must be a non-empty string\");\n }\n\n const normalizedEndpoint = apiEndpoint.replace(/\\/$/, \"\");\n\n // Shared cache for relayer address (used by both getFeePayer and getRelayerAddress)\n let cachedAddress: Address | null = null;\n let cachedInfo: ApiRelayerInfoResponse | null = null;\n\n async function fetchInfo(): Promise<ApiRelayerInfoResponse> {\n if (cachedInfo !== null) {\n return cachedInfo;\n }\n const response = await makeRequest<ApiRelayerInfoResponse>(\n `${normalizedEndpoint}${ENDPOINTS.RELAYER_INFO}`,\n fetchImpl,\n { operation: \"getRelayerInfo\" },\n );\n cachedInfo = response;\n cachedAddress = address(response.address);\n return response;\n }\n\n return {\n apiEndpoint: normalizedEndpoint,\n\n async getFeePayer(): Promise<Address> {\n if (cachedAddress !== null) {\n return cachedAddress;\n }\n const info = await fetchInfo();\n return address(info.address);\n },\n\n async getRelayerAddress(): Promise<Address> {\n if (cachedAddress !== null) {\n return cachedAddress;\n }\n const info = await fetchInfo();\n return address(info.address);\n },\n\n async getSupportedMints(): Promise<SupportedMintsResponse> {\n const info = await fetchInfo();\n return {\n relayer: info.address,\n mints: info.supported_mints,\n count: BigInt(info.supported_mints.length) as U32,\n };\n },\n\n async submitClaim(request: ClaimRequest): Promise<ClaimSubmitResponse> {\n const response = await makeRequest<ApiClaimSubmitResponse>(\n `${normalizedEndpoint}${ENDPOINTS.CLAIM_SUBMIT}`,\n fetchImpl,\n { method: \"POST\", body: request, operation: \"claimSubmit\" },\n );\n return {\n requestId: response.request_id,\n status: response.status,\n };\n },\n\n async pollClaimStatus(requestId: string): Promise<ClaimStatusResponse> {\n const url = `${normalizedEndpoint}${ENDPOINTS.CLAIM_STATUS.replace(\"{id}\", requestId)}`;\n const response = await makeRequest<ApiClaimStatusResponse>(url, fetchImpl, {\n operation: \"claimStatus\",\n });\n return convertClaimStatusResponse(response);\n },\n };\n}\n\n// ============================================================================\n// Claim Polling Utility\n// ============================================================================\n\n/**\n * Terminal claim statuses. Polling stops when the status matches one of these.\n * @internal\n */\nconst TERMINAL_CLAIM_STATUSES: ReadonlySet<ClaimStatus> = new Set([\n \"completed\",\n \"failed\",\n \"timed_out\",\n]);\n\n/**\n * Polls a claim request until it reaches a terminal status or times out.\n *\n * @remarks\n * Terminal statuses are: `completed`, `failed`, `timed_out`.\n * The `onProgress` callback is invoked after each poll with the latest status.\n *\n * @param pollClaimStatus - Function to poll claim status\n * @param requestId - The claim request ID to poll\n * @param options - Polling configuration\n * @returns The final {@link ClaimBatchResult}\n *\n * @public\n */\nexport async function pollClaimUntilTerminal(\n pollClaimStatus: (requestId: string) => Promise<ClaimStatusResponse>,\n requestId: string,\n options?: {\n pollingIntervalMs?: number;\n timeoutMs?: number;\n onProgress?: (event: {\n readonly requestId: string;\n readonly status: ClaimStatus;\n readonly resolvedVariant?: string;\n readonly txSignature?: string;\n readonly callbackSignature?: string;\n readonly failureReason?: string | null;\n }) => void;\n },\n): Promise<ClaimBatchResult> {\n const pollingIntervalMs: number = options?.pollingIntervalMs ?? 3000;\n const timeoutMs: number = options?.timeoutMs ?? 120_000;\n const onProgress = options?.onProgress;\n\n const startTime: number = Date.now();\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- polling loop\n while (true) {\n const status: ClaimStatusResponse = await pollClaimStatus(requestId);\n\n if (onProgress !== undefined) {\n onProgress({\n requestId: status.requestId,\n status: status.status,\n resolvedVariant: status.resolvedVariant,\n txSignature: status.txSignature,\n callbackSignature: status.callbackSignature,\n failureReason: status.failureReason,\n });\n }\n\n if (TERMINAL_CLAIM_STATUSES.has(status.status)) {\n const result: ClaimBatchResult = {\n requestId: status.requestId,\n status: status.status,\n txSignature: status.txSignature,\n callbackSignature: status.callbackSignature,\n resolvedVariant: status.resolvedVariant,\n failureReason: status.failureReason,\n };\n return result;\n }\n\n if (Date.now() - startTime >= timeoutMs) {\n const timedOutResult: ClaimBatchResult = {\n requestId: status.requestId,\n status: \"timed_out\" as ClaimStatus,\n failureReason: `Polling timed out after ${String(timeoutMs)}ms (last status: ${String(status.status)})`,\n };\n return timedOutResult;\n }\n\n await new Promise<void>((resolve) => {\n setTimeout(resolve, pollingIntervalMs);\n });\n }\n}\n"]}
@@ -0,0 +1,70 @@
1
+ import { BN254_FIELD_PRIME, assertBn254FieldElement } from './chunk-WN75ORDT.js';
2
+ import { CryptographyError } from './chunk-5KPQXPQM.js';
3
+ import { __name } from './chunk-7QVYU63E.js';
4
+
5
+ // src/math/bn254/operations.ts
6
+ function modulePow(base, exp, modulus) {
7
+ if (modulus === 1n) {
8
+ return 0n;
9
+ }
10
+ let result = 1n;
11
+ base = (base % modulus + modulus) % modulus;
12
+ while (exp > 0n) {
13
+ if (exp % 2n === 1n) {
14
+ result = result * base % modulus;
15
+ }
16
+ exp = exp >> 1n;
17
+ base = base * base % modulus;
18
+ }
19
+ return result;
20
+ }
21
+ __name(modulePow, "modulePow");
22
+ function computeBn254ModularInverse(value) {
23
+ const normalizedValue = (BigInt(value) % BN254_FIELD_PRIME + BN254_FIELD_PRIME) % BN254_FIELD_PRIME;
24
+ if (normalizedValue === 0n) {
25
+ throw new CryptographyError("Cannot compute inverse of zero in BN254 field");
26
+ }
27
+ const inverse = modulePow(normalizedValue, BN254_FIELD_PRIME - 2n, BN254_FIELD_PRIME);
28
+ assertBn254FieldElement(inverse, "inverse");
29
+ return inverse;
30
+ }
31
+ __name(computeBn254ModularInverse, "computeBn254ModularInverse");
32
+ function computeBn254LimbwiseSumInverse(limbs) {
33
+ const sum = (BigInt(limbs[0]) + BigInt(limbs[1]) + BigInt(limbs[2])) % BN254_FIELD_PRIME;
34
+ if (sum === 0n) {
35
+ throw new CryptographyError("Cannot compute inverse: sum of limbs is zero");
36
+ }
37
+ const inverse = modulePow(sum, BN254_FIELD_PRIME - 2n, BN254_FIELD_PRIME);
38
+ assertBn254FieldElement(inverse, "inverse");
39
+ return inverse;
40
+ }
41
+ __name(computeBn254LimbwiseSumInverse, "computeBn254LimbwiseSumInverse");
42
+ function bn254ModuloPow(base, exp) {
43
+ const result = modulePow(BigInt(base), exp, BN254_FIELD_PRIME);
44
+ assertBn254FieldElement(result, "result");
45
+ return result;
46
+ }
47
+ __name(bn254ModuloPow, "bn254ModuloPow");
48
+ function bn254Add(a, b) {
49
+ const result = (BigInt(a) + BigInt(b)) % BN254_FIELD_PRIME;
50
+ assertBn254FieldElement(result, "result");
51
+ return result;
52
+ }
53
+ __name(bn254Add, "bn254Add");
54
+ function bn254Sub(a, b) {
55
+ const diff = BigInt(a) - BigInt(b);
56
+ const result = (diff % BN254_FIELD_PRIME + BN254_FIELD_PRIME) % BN254_FIELD_PRIME;
57
+ assertBn254FieldElement(result, "result");
58
+ return result;
59
+ }
60
+ __name(bn254Sub, "bn254Sub");
61
+ function bn254Mul(a, b) {
62
+ const result = BigInt(a) * BigInt(b) % BN254_FIELD_PRIME;
63
+ assertBn254FieldElement(result, "result");
64
+ return result;
65
+ }
66
+ __name(bn254Mul, "bn254Mul");
67
+
68
+ export { bn254Add, bn254ModuloPow, bn254Mul, bn254Sub, computeBn254LimbwiseSumInverse, computeBn254ModularInverse };
69
+ //# sourceMappingURL=chunk-OFDWNWCL.js.map
70
+ //# sourceMappingURL=chunk-OFDWNWCL.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/math/bn254/operations.ts"],"names":[],"mappings":";;;;;AAuFA,SAAS,SAAA,CAAU,IAAA,EAAc,GAAA,EAAa,OAAA,EAAyB;AACrE,EAAA,IAAI,YAAY,EAAA,EAAI;AAClB,IAAA,OAAO,EAAA;AAAA,EACT;AACA,EAAA,IAAI,MAAA,GAAS,EAAA;AACb,EAAA,IAAA,GAAA,CAAS,IAAA,GAAO,UAAW,OAAA,IAAW,OAAA;AACtC,EAAA,OAAO,MAAM,EAAA,EAAI;AACf,IAAA,IAAI,GAAA,GAAM,OAAO,EAAA,EAAI;AACnB,MAAA,MAAA,GAAU,SAAS,IAAA,GAAQ,OAAA;AAAA,IAC7B;AACA,IAAA,GAAA,GAAM,GAAA,IAAO,EAAA;AACb,IAAA,IAAA,GAAQ,OAAO,IAAA,GAAQ,OAAA;AAAA,EACzB;AACA,EAAA,OAAO,MAAA;AACT;AAdS,MAAA,CAAA,SAAA,EAAA,WAAA,CAA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T,SAAS,QAAA,CAAS,GAAsB,CAAA,EAAyC;AACtF,EAAA,MAAM,UAAU,MAAA,CAAO,CAAC,CAAA,GAAI,MAAA,CAAO,CAAC,CAAA,IAAK,iBAAA;AACzC,EAAA,uBAAA,CAAwB,QAAQ,QAAQ,CAAA;AACxC,EAAA,OAAO,MAAA;AACT;AAJgB,MAAA,CAAA,QAAA,EAAA,UAAA,CAAA;AAwDT,SAAS,QAAA,CAAS,GAAsB,CAAA,EAAyC;AACtF,EAAA,MAAM,IAAA,GAAO,MAAA,CAAO,CAAC,CAAA,GAAI,OAAO,CAAC,CAAA;AACjC,EAAA,MAAM,MAAA,GAAA,CAAW,IAAA,GAAO,iBAAA,GAAqB,iBAAA,IAAqB,iBAAA;AAClE,EAAA,uBAAA,CAAwB,QAAQ,QAAQ,CAAA;AACxC,EAAA,OAAO,MAAA;AACT;AALgB,MAAA,CAAA,QAAA,EAAA,UAAA,CAAA;AA2DT,SAAS,QAAA,CAAS,GAAsB,CAAA,EAAyC;AACtF,EAAA,MAAM,SAAU,MAAA,CAAO,CAAC,CAAA,GAAI,MAAA,CAAO,CAAC,CAAA,GAAK,iBAAA;AACzC,EAAA,uBAAA,CAAwB,QAAQ,QAAQ,CAAA;AACxC,EAAA,OAAO,MAAA;AACT;AAJgB,MAAA,CAAA,QAAA,EAAA,UAAA,CAAA","file":"chunk-OFDWNWCL.js","sourcesContent":["/**\n * BN254 Field Operations Module\n *\n * This module provides higher-level arithmetic operations over the BN254 scalar\n * field F_r, including modular exponentiation, multiplicative inverse computation,\n * and the basic field operations (add, subtract, multiply). These functions build\n * on the branded type system defined in `types.ts` and are intended for use in\n * cryptographic protocols such as Groth16 proof generation, Fiat-Shamir challenges,\n * and ZK circuit witness computation.\n *\n * @remarks\n * ## BN254 and the Scalar Field\n *\n * The BN254 curve (also known as alt_bn128 or bn256) is a pairing-friendly\n * elliptic curve whose scalar field has prime order:\n * ```\n * r = 21888242871839275222246405745257275088548364400416034343698204186575808495617\n * ```\n * All operations in this module reduce their results modulo `r`, ensuring that\n * outputs are always valid field elements in the range `[0, r-1]`.\n *\n * ## Performance Characteristics\n *\n * - `bn254Add`, `bn254Sub`, `bn254Mul`: O(1) — single BigInt operation + reduction\n * - `bn254ModuloPow`: O(log exp) squarings and multiplications via square-and-multiply\n * - `computeBn254ModularInverse`: O(log p) — Fermat exponentiation with p-2 as exponent\n * - `computeBn254LimbwiseSumInverse`: O(log p) — three additions followed by inversion\n *\n * ## Security Note\n *\n * The inverse functions use Fermat's Little Theorem (`a^(p-2) mod p`) rather than\n * the Extended Euclidean Algorithm. This choice trades a small performance overhead\n * for a simpler, more auditable implementation. The underlying `modulePow` helper\n * is intentionally non-constant-time (uses the `bigint` `%` operator internally);\n * for constant-time arithmetic, use the functions in `field-arithmetic.ts`.\n *\n * @see {@link ./field-arithmetic} Constant-time field arithmetic\n * @see {@link ./types} BN254 field element types and validation\n *\n * @packageDocumentation\n * @module math/bn254/operations\n */\n\nimport { type Bn254FieldElement, assertBn254FieldElement, BN254_FIELD_PRIME } from \"./types\";\nimport type { Base85Limb } from \"../../crypto/poseidon/types\";\nimport { CryptographyError } from \"../../crypto/errors\";\n\n/**\n * Computes modular exponentiation: `base^exp mod modulus` using the\n * square-and-multiply (binary exponentiation) algorithm.\n *\n * @remarks\n * This is a general-purpose helper used internally by the BN254-specific\n * exported functions. It handles negative bases by first normalizing to the\n * canonical representative in `[0, modulus - 1]` via `((base % modulus) + modulus) % modulus`.\n *\n * ## Algorithm: Square-and-Multiply\n *\n * The square-and-multiply algorithm achieves O(log exp) multiplications by\n * processing the bits of the exponent from least significant to most significant:\n * ```\n * result = 1\n * while exp > 0:\n * if exp is odd: result = result * base mod modulus\n * exp = exp >> 1\n * base = base * base mod modulus\n * ```\n *\n * ## Special Case\n *\n * When `modulus === 1n`, all values are congruent to 0 modulo 1, so the function\n * immediately returns `0n`.\n *\n * @param base - The base value (any integer; negative values are normalized)\n * @param exp - The exponent (must be a non-negative `bigint`)\n * @param modulus - The modulus (must be a positive `bigint`)\n * @returns `base^exp mod modulus`, always in the range `[0, modulus - 1]`\n *\n * @example\n * ```typescript\n * // Internal usage — not exported. Used by bn254ModuloPow and the inverse functions.\n * const result = modulePow(2n, 10n, 1000n); // 1024 mod 1000 = 24\n * const fermat = modulePow(7n, BN254_FIELD_PRIME - 2n, BN254_FIELD_PRIME); // 7^-1 mod p\n * ```\n *\n * @internal\n */\nfunction modulePow(base: bigint, exp: bigint, modulus: bigint): bigint {\n if (modulus === 1n) {\n return 0n;\n }\n let result = 1n;\n base = ((base % modulus) + modulus) % modulus;\n while (exp > 0n) {\n if (exp % 2n === 1n) {\n result = (result * base) % modulus;\n }\n exp = exp >> 1n;\n base = (base * base) % modulus;\n }\n return result;\n}\n\n/**\n * Computes the multiplicative inverse of a BN254 field element using\n * Fermat's Little Theorem.\n *\n * @remarks\n * ## Mathematical Background\n *\n * For a prime field F_p, every non-zero element `a` has a unique multiplicative\n * inverse `a^(-1)` satisfying:\n * ```\n * a * a^(-1) ≡ 1 (mod p)\n * ```\n *\n * By Fermat's Little Theorem, for prime `p` and `a != 0 (mod p)`:\n * ```\n * a^(p-1) ≡ 1 (mod p)\n * ```\n * Multiplying both sides by `a^(-1)`:\n * ```\n * a^(p-2) ≡ a^(-1) (mod p)\n * ```\n *\n * This function evaluates `a^(p-2) mod p` via the square-and-multiply algorithm\n * in O(log p) field multiplications (approximately 254 squarings for BN254).\n *\n * ## Input Normalization\n *\n * The input is first normalized to its canonical representative in `[0, p-1]`\n * via double reduction. If the normalized value is `0n`, there is no inverse and\n * a `CryptographyError` is thrown.\n *\n * ## Complexity\n *\n * O(log p) ≈ O(254) field multiplications (squarings and multiplications via\n * the square-and-multiply algorithm on a 254-bit exponent `p-2`).\n *\n * @param value - The BN254 field element to invert. Must be non-zero in the field.\n * @returns The multiplicative inverse of `value` in `[1, BN254_FIELD_PRIME - 1]`.\n *\n * @throws {CryptographyError} If `value` is congruent to zero modulo the field prime,\n * because zero has no multiplicative inverse in any field.\n *\n * @example\n * ```typescript\n * import {\n * computeBn254ModularInverse,\n * bn254Mul,\n * BN254_FIELD_PRIME,\n * } from \"@umbra/sdk\";\n * import { assertBn254FieldElement } from \"@umbra/sdk\";\n *\n * const a = 12345n;\n * assertBn254FieldElement(a, \"a\");\n *\n * const aInv = computeBn254ModularInverse(a);\n *\n * // Verify: a * a^(-1) = 1 (mod p)\n * const product = bn254Mul(a, aInv);\n * console.log(product === 1n); // true\n *\n * // Division by a: b / a = b * a^(-1) mod p\n * const b = 99999n;\n * assertBn254FieldElement(b, \"b\");\n * const quotient = bn254Mul(b, aInv); // b / a mod p\n * ```\n *\n * @see {@link bn254ModuloPow} For general modular exponentiation in the BN254 field\n * @see {@link computeBn254LimbwiseSumInverse} For the inverse of a Base85 limb sum\n *\n * @public\n */\nexport function computeBn254ModularInverse(value: Bn254FieldElement): Bn254FieldElement {\n // Ensure the value is in the field\n const normalizedValue =\n ((BigInt(value) % BN254_FIELD_PRIME) + BN254_FIELD_PRIME) % BN254_FIELD_PRIME;\n\n if (normalizedValue === 0n) {\n throw new CryptographyError(\"Cannot compute inverse of zero in BN254 field\");\n }\n\n // Use Fermat's Little Theorem: a^(-1) = a^(p-2) mod p\n const inverse = modulePow(normalizedValue, BN254_FIELD_PRIME - 2n, BN254_FIELD_PRIME);\n\n assertBn254FieldElement(inverse, \"inverse\");\n return inverse;\n}\n\n/**\n * Computes the multiplicative inverse of the sum of three Base85 limbs in the\n * BN254 scalar field.\n *\n * @remarks\n * ## Context: Base85 Limb Representation\n *\n * In ZK circuits that use the Circom/Groth16 toolchain, 255-bit field element\n * inputs are commonly represented as three 85-bit limbs (sometimes called\n * \"Base85 limbs\") to allow efficient constraint generation. Each limb holds\n * a 85-bit chunk of the full value:\n * ```\n * full_value = limbs[0] + limbs[1] * 2^85 + limbs[2] * 2^170\n * ```\n *\n * ## Circuit Non-Zero Validation\n *\n * Proving that a value is non-zero in a ZK circuit requires the circuit to\n * supply the multiplicative inverse of that value as an auxiliary witness.\n * When the value is represented in limbwise form, the circuit sometimes needs\n * the inverse of the *sum of the limbs* rather than the inverse of the\n * reconstructed value. This function computes exactly that:\n * ```\n * sum = (limbs[0] + limbs[1] + limbs[2]) mod p\n * result = sum^(-1) mod p\n * ```\n *\n * ## Why Limbwise Sum Instead of Reconstructed Value?\n *\n * The sum `limbs[0] + limbs[1] + limbs[2]` is a cheaper operation in\n * the circuit compared to the full positional reconstruction\n * `limbs[0] + limbs[1]*2^85 + limbs[2]*2^170`. The sum-based non-zero check\n * works because if all three limbs are zero, their sum is also zero; otherwise\n * the sum is guaranteed to be non-zero (given the limb range constraints enforced\n * by the circuit).\n *\n * @param limbs - A tuple of three `Base85Limb` values: `[low, middle, high]`.\n * Each limb must be in the range `[0, 2^85 - 1]`.\n * @returns The multiplicative inverse of `(limbs[0] + limbs[1] + limbs[2]) mod p`\n * as a `Bn254FieldElement` in the range `[1, BN254_FIELD_PRIME - 1]`.\n *\n * @throws {CryptographyError} If the sum of all three limbs is congruent to zero\n * modulo the BN254 field prime, meaning no inverse exists.\n *\n * @example\n * ```typescript\n * import {\n * computeBn254LimbwiseSumInverse,\n * BN254_FIELD_PRIME,\n * } from \"@umbra/sdk\";\n * import { assertBase85Limb } from \"@umbra/sdk\";\n *\n * const low = 0x1234n;\n * const mid = 0x5678n;\n * const high = 0x9ABCn;\n * assertBase85Limb(low, \"low\");\n * assertBase85Limb(mid, \"mid\");\n * assertBase85Limb(high, \"high\");\n *\n * const inverse = computeBn254LimbwiseSumInverse([low, mid, high]);\n *\n * // Verify: (low + mid + high) * inverse ≡ 1 (mod p)\n * const sum = (low + mid + high) % BN254_FIELD_PRIME;\n * const check = (sum * inverse) % BN254_FIELD_PRIME;\n * console.log(check === 1n); // true\n * ```\n *\n * @see {@link computeBn254ModularInverse} For inverting a single field element\n * @see {@link Base85Limb} The branded limb type from `crypto/poseidon/types`\n *\n * @public\n */\nexport function computeBn254LimbwiseSumInverse(\n limbs: [Base85Limb, Base85Limb, Base85Limb],\n): Bn254FieldElement {\n // Sum the limbs\n const sum = (BigInt(limbs[0]) + BigInt(limbs[1]) + BigInt(limbs[2])) % BN254_FIELD_PRIME;\n\n if (sum === 0n) {\n throw new CryptographyError(\"Cannot compute inverse: sum of limbs is zero\");\n }\n\n // Compute the inverse\n const inverse = modulePow(sum, BN254_FIELD_PRIME - 2n, BN254_FIELD_PRIME);\n\n assertBn254FieldElement(inverse, \"inverse\");\n return inverse;\n}\n\n/**\n * Computes modular exponentiation in the BN254 scalar field: `base^exp mod p`.\n *\n * @remarks\n * This is a type-safe wrapper around the internal `modulePow` helper that\n * constrains both the input and output to the BN254 scalar field. It delegates\n * to the square-and-multiply algorithm with O(log exp) multiplications.\n *\n * ## Typical Use Cases\n *\n * - Computing powers of a Fiat-Shamir challenge scalar\n * - Evaluating polynomial commitments at a challenge point\n * - Batch inversion via exponentiation (less efficient than Extended GCD but simpler)\n *\n * ## Exponent Sign\n *\n * The exponent must be a non-negative `bigint`. Negative exponents are not supported;\n * use `computeBn254ModularInverse` for `base^(-1)` and compose with `bn254ModuloPow`\n * for general negative powers.\n *\n * @param base - The base field element in `[0, BN254_FIELD_PRIME - 1]`.\n * @param exp - The non-negative integer exponent (a plain `bigint`, not necessarily in the field).\n * @returns `base^exp mod BN254_FIELD_PRIME` as a `Bn254FieldElement`.\n *\n * @example\n * ```typescript\n * import { bn254ModuloPow, assertBn254FieldElement } from \"@umbra/sdk\";\n *\n * const challenge = 999n;\n * assertBn254FieldElement(challenge, \"challenge\");\n *\n * // Compute challenge^3 mod p (evaluating a cubic polynomial coefficient)\n * const cubed = bn254ModuloPow(challenge, 3n);\n *\n * // Compute challenge^0 = 1 (identity)\n * const identity = bn254ModuloPow(challenge, 0n);\n * console.log(identity === 1n); // true\n * ```\n *\n * @see {@link computeBn254ModularInverse} For the special case exp = -1\n * @see {@link bn254Mul} For a single multiplication\n *\n * @public\n */\nexport function bn254ModuloPow(base: Bn254FieldElement, exp: bigint): Bn254FieldElement {\n const result = modulePow(BigInt(base), exp, BN254_FIELD_PRIME);\n assertBn254FieldElement(result, \"result\");\n return result;\n}\n\n/**\n * Computes the sum of two BN254 scalar field elements modulo the field prime.\n *\n * @remarks\n * ## Formula\n *\n * ```\n * result = (a + b) mod BN254_FIELD_PRIME\n * ```\n *\n * Because both `a` and `b` are in `[0, p-1]`, their sum is in `[0, 2p-2]`,\n * which requires at most one modular reduction step. This is implemented directly\n * via JavaScript's `%` operator on `bigint`.\n *\n * ## Overflow Behavior\n *\n * JavaScript `bigint` arithmetic is arbitrary precision, so there is no risk of\n * overflow. The modular reduction always yields a result in `[0, p-1]`.\n *\n * @param a - First summand, a valid BN254 field element in `[0, BN254_FIELD_PRIME - 1]`.\n * @param b - Second summand, a valid BN254 field element in `[0, BN254_FIELD_PRIME - 1]`.\n * @returns `(a + b) mod BN254_FIELD_PRIME` as a `Bn254FieldElement`.\n *\n * @example\n * ```typescript\n * import { bn254Add, assertBn254FieldElement, BN254_FIELD_PRIME } from \"@umbra/sdk\";\n *\n * const a = 10n;\n * const b = 20n;\n * assertBn254FieldElement(a, \"a\");\n * assertBn254FieldElement(b, \"b\");\n *\n * const sum = bn254Add(a, b);\n * console.log(sum === 30n); // true\n *\n * // Demonstrates wraparound at the field boundary\n * const nearPrime = BN254_FIELD_PRIME - 1n;\n * assertBn254FieldElement(nearPrime, \"nearPrime\");\n * const wrapped = bn254Add(nearPrime, b);\n * // (p - 1 + 20) mod p = 19\n * console.log(wrapped === 19n); // true\n * ```\n *\n * @see {@link bn254Sub} For modular subtraction\n * @see {@link bn254Mul} For modular multiplication\n *\n * @public\n */\nexport function bn254Add(a: Bn254FieldElement, b: Bn254FieldElement): Bn254FieldElement {\n const result = (BigInt(a) + BigInt(b)) % BN254_FIELD_PRIME;\n assertBn254FieldElement(result, \"result\");\n return result;\n}\n\n/**\n * Computes the difference of two BN254 scalar field elements modulo the field prime.\n *\n * @remarks\n * ## Formula\n *\n * ```\n * result = (a - b) mod BN254_FIELD_PRIME\n * ```\n *\n * Because `a - b` can be negative when `b > a`, the result is obtained by\n * adding the prime before taking the modulo to ensure canonicalization into\n * `[0, p-1]`:\n * ```\n * diff = a - b\n * result = ((diff % p) + p) % p\n * ```\n *\n * This pattern handles both the case where `a >= b` (no wrap-around needed)\n * and the case where `a < b` (wrap-around by adding `p`).\n *\n * @param a - Minuend, a valid BN254 field element in `[0, BN254_FIELD_PRIME - 1]`.\n * @param b - Subtrahend, a valid BN254 field element in `[0, BN254_FIELD_PRIME - 1]`.\n * @returns `(a - b) mod BN254_FIELD_PRIME` as a `Bn254FieldElement` in `[0, p-1]`.\n *\n * @example\n * ```typescript\n * import { bn254Sub, assertBn254FieldElement, BN254_FIELD_PRIME } from \"@umbra/sdk\";\n *\n * const a = 30n;\n * const b = 10n;\n * assertBn254FieldElement(a, \"a\");\n * assertBn254FieldElement(b, \"b\");\n *\n * const diff = bn254Sub(a, b);\n * console.log(diff === 20n); // true\n *\n * // Underflow wraps around the field prime\n * const small = 5n;\n * assertBn254FieldElement(small, \"small\");\n * const wrapped = bn254Sub(small, b);\n * // (5 - 10 + p) mod p = p - 5\n * console.log(wrapped === BN254_FIELD_PRIME - 5n); // true\n * ```\n *\n * @see {@link bn254Add} For modular addition\n * @see {@link bn254Mul} For modular multiplication\n *\n * @public\n */\nexport function bn254Sub(a: Bn254FieldElement, b: Bn254FieldElement): Bn254FieldElement {\n const diff = BigInt(a) - BigInt(b);\n const result = ((diff % BN254_FIELD_PRIME) + BN254_FIELD_PRIME) % BN254_FIELD_PRIME;\n assertBn254FieldElement(result, \"result\");\n return result;\n}\n\n/**\n * Computes the product of two BN254 scalar field elements modulo the field prime.\n *\n * @remarks\n * ## Formula\n *\n * ```\n * result = (a * b) mod BN254_FIELD_PRIME\n * ```\n *\n * Because both `a` and `b` are approximately 254-bit values, their product is\n * approximately 508 bits before reduction. JavaScript's `bigint` type handles\n * arbitrary precision arithmetic natively, so no overflow occurs. The result\n * is reduced to `[0, p-1]` via a single `%` operation.\n *\n * ## Performance Note\n *\n * This function uses JavaScript's built-in `bigint` multiplication, which is not\n * constant-time. For cryptographic contexts where timing side-channels are a\n * concern (e.g., secret-key operations), use `bn254ModuloMul` from\n * `field-arithmetic.ts` which uses constant-time Montgomery multiplication.\n *\n * @param a - First factor, a valid BN254 field element in `[0, BN254_FIELD_PRIME - 1]`.\n * @param b - Second factor, a valid BN254 field element in `[0, BN254_FIELD_PRIME - 1]`.\n * @returns `(a * b) mod BN254_FIELD_PRIME` as a `Bn254FieldElement`.\n *\n * @example\n * ```typescript\n * import { bn254Mul, assertBn254FieldElement, BN254_FIELD_PRIME } from \"@umbra/sdk\";\n *\n * const a = 7n;\n * const b = 8n;\n * assertBn254FieldElement(a, \"a\");\n * assertBn254FieldElement(b, \"b\");\n *\n * const product = bn254Mul(a, b);\n * console.log(product === 56n); // true\n *\n * // Product of two large field elements wraps around\n * const large = BN254_FIELD_PRIME - 1n;\n * assertBn254FieldElement(large, \"large\");\n * const result = bn254Mul(large, 2n as unknown as typeof large);\n * // (p - 1) * 2 mod p = p - 2\n * console.log(result === BN254_FIELD_PRIME - 2n); // true\n * ```\n *\n * @see {@link bn254Add} For modular addition\n * @see {@link bn254Sub} For modular subtraction\n * @see {@link computeBn254ModularInverse} For multiplicative inverse (division)\n *\n * @public\n */\nexport function bn254Mul(a: Bn254FieldElement, b: Bn254FieldElement): Bn254FieldElement {\n const result = (BigInt(a) * BigInt(b)) % BN254_FIELD_PRIME;\n assertBn254FieldElement(result, \"result\");\n return result;\n}\n"]}