@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
@@ -1,4 +1,5 @@
1
- export { AES_AUTH_TAG_LENGTH, AES_IV_LENGTH, AES_KEY_LENGTH, AES_METADATA_OVERHEAD, BASE85_LIMB_MAX, BN254_FIELD_PRIME, CURVE25519_FIELD_PRIME, CryptographyAssertionError, DAY_MAX, DAY_MIN, GROTH16_G1_BYTE_LENGTH, GROTH16_G2_BYTE_LENGTH, HOUR_MAX, HOUR_MIN, I1024_MAX, I1024_MIN, I128_MAX, I128_MIN, I16_MAX, I16_MIN, I256_MAX, I256_MIN, I32_MAX, I32_MIN, I512_MAX, I512_MIN, I64_MAX, I64_MIN, I8_MAX, I8_MIN, MINUTE_MAX, MINUTE_MIN, MONTH_MAX, MONTH_MIN, MathematicsAssertionError, OPTIONAL_DATA_BYTE_LENGTH, SECOND_MAX, SECOND_MIN, SIGNATURE_BYTE_LENGTH, SolanaAssertionError, TemporalAssertionError, U1024_BYTE_LENGTH, U1024_MAX, U128_BYTE_LENGTH, U128_MAX, U16_BYTE_LENGTH, U16_MAX, U256_BYTE_LENGTH, U256_MAX, U32_BYTE_LENGTH, U32_MAX, U512_BYTE_LENGTH, U512_MAX, U64_BYTE_LENGTH, U64_MAX, U8_BYTE_LENGTH, U8_MAX, X25519_BYTE_LENGTH, YEAR_MAX, YEAR_MIN, ZK_PROOF_BYTE_LENGTH, asRelayableSignedTransaction, assertAesCiphertextWithMetadata, assertAesKey, assertAesPlaintext, assertBase85Limb, assertBeBytes, assertBn254FieldElement, assertBytes, assertCurve25519FieldElement, assertDailyViewingKey, assertDay, assertGenerationSeed, assertGroth16ProofA, assertGroth16ProofB, assertGroth16ProofC, assertHour, assertHourlyViewingKey, assertI1024, assertI128, assertI16, assertI256, assertI32, assertI512, assertI64, assertI8, assertKeccak256Hash, assertKeccak512Hash, assertLeBytes, assertMasterSeed, assertMasterViewingKey, assertMintViewingKey, assertMinute, assertMinuteViewingKey, assertMonth, assertMonthlyViewingKey, assertOptionalData32, assertPoseidonCiphertext, assertPoseidonCounter, assertPoseidonHash, assertPoseidonKey, assertPoseidonKeystream, assertPoseidonPlaintext, assertRcCiphertext, assertRcCounter, assertRcEncryptionNonce, assertRcKey, assertRcPlaintext, assertSecond, assertSecondViewingKey, assertSharedSecret, assertSignatureBytes, assertSignedInteger, assertSolanaBytes, assertString, assertTimestampComponent, assertTransactionSignature, assertU1024, assertU1024BeBytes, assertU1024LeBytes, assertU128, assertU128BeBytes, assertU128LeBytes, assertU16, assertU16BeBytes, assertU16LeBytes, assertU256, assertU256BeBytes, assertU256LeBytes, assertU32, assertU32BeBytes, assertU32LeBytes, assertU512, assertU512BeBytes, assertU512LeBytes, assertU64, assertU64BeBytes, assertU64LeBytes, assertU8, assertU8BeBytes, assertU8LeBytes, assertUnsignedInteger, assertX25519Bytes, assertX25519Keypair, assertX25519PrivateKey, assertX25519PublicKey, assertYear, assertYearlyViewingKey, assertZkProofBytes } from '../chunk-BM7N6N7E.js';
1
+ export { DAY_MAX, DAY_MIN, HOUR_MAX, HOUR_MIN, MINUTE_MAX, MINUTE_MIN, MONTH_MAX, MONTH_MIN, SECOND_MAX, SECOND_MIN, SIGNATURE_BYTE_LENGTH, SolanaAssertionError, TemporalAssertionError, YEAR_MAX, YEAR_MIN, asRelayableSignedTransaction, assertDay, assertHour, assertMinute, assertMonth, assertSecond, assertSignatureBytes, assertSolanaBytes, assertString, assertTimestampComponent, assertTransactionSignature, assertYear } from '../chunk-DD2WCK4C.js';
2
+ export { AES_AUTH_TAG_LENGTH, AES_IV_LENGTH, AES_KEY_LENGTH, AES_METADATA_OVERHEAD, BASE85_LIMB_MAX, BN254_FIELD_PRIME, CURVE25519_FIELD_PRIME, CryptographyAssertionError, GROTH16_G1_BYTE_LENGTH, GROTH16_G2_BYTE_LENGTH, I1024_MAX, I1024_MIN, I128_MAX, I128_MIN, I16_MAX, I16_MIN, I256_MAX, I256_MIN, I32_MAX, I32_MIN, I512_MAX, I512_MIN, I64_MAX, I64_MIN, I8_MAX, I8_MIN, MathematicsAssertionError, OPTIONAL_DATA_BYTE_LENGTH, U1024_BYTE_LENGTH, U1024_MAX, U128_BYTE_LENGTH, U128_MAX, U16_BYTE_LENGTH, U16_MAX, U256_BYTE_LENGTH, U256_MAX, U32_BYTE_LENGTH, U32_MAX, U512_BYTE_LENGTH, U512_MAX, U64_BYTE_LENGTH, U64_MAX, U8_BYTE_LENGTH, U8_MAX, X25519_BYTE_LENGTH, ZK_PROOF_BYTE_LENGTH, assertAesCiphertextWithMetadata, assertAesKey, assertAesPlaintext, assertBase85Limb, assertBeBytes, assertBn254FieldElement, assertBytes, assertCurve25519FieldElement, assertDailyViewingKey, assertGenerationSeed, assertGroth16ProofA, assertGroth16ProofB, assertGroth16ProofC, assertHourlyViewingKey, assertI1024, assertI128, assertI16, assertI256, assertI32, assertI512, assertI64, assertI8, assertKeccak256Hash, assertKeccak512Hash, assertLeBytes, assertMasterSeed, assertMasterViewingKey, assertMintViewingKey, assertMinuteViewingKey, assertMonthlyViewingKey, assertOptionalData32, assertPoseidonCiphertext, assertPoseidonCounter, assertPoseidonHash, assertPoseidonKey, assertPoseidonKeystream, assertPoseidonPlaintext, assertRcCiphertext, assertRcCounter, assertRcEncryptionNonce, assertRcKey, assertRcPlaintext, assertSecondViewingKey, assertSharedSecret, assertSignedInteger, assertU1024, assertU1024BeBytes, assertU1024LeBytes, assertU128, assertU128BeBytes, assertU128LeBytes, assertU16, assertU16BeBytes, assertU16LeBytes, assertU256, assertU256BeBytes, assertU256LeBytes, assertU32, assertU32BeBytes, assertU32LeBytes, assertU512, assertU512BeBytes, assertU512LeBytes, assertU64, assertU64BeBytes, assertU64LeBytes, assertU8, assertU8BeBytes, assertU8LeBytes, assertUnsignedInteger, assertX25519Bytes, assertX25519Keypair, assertX25519PrivateKey, assertX25519PublicKey, assertYearlyViewingKey, assertZkProofBytes } from '../chunk-CFTW5WNG.js';
2
3
  import '../chunk-7QVYU63E.js';
3
4
  //# sourceMappingURL=index.js.map
4
5
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,87 @@
1
+ import { S as SubSubBrandedType, f as U256 } from './types-C_V_CaKK.cjs';
2
+
3
+ /**
4
+ * BN254 Field Element Types
5
+ *
6
+ * This module defines the foundational type primitives for working with elements
7
+ * of the BN254 (alt_bn128) prime field. BN254 is a pairing-friendly elliptic curve
8
+ * widely used in zero-knowledge proof systems, including Groth16, PLONK, and the
9
+ * Circom/SnarkJS toolchain. Ethereum natively supports BN254 via the EIP-196 and
10
+ * EIP-197 precompiles.
11
+ *
12
+ * @remarks
13
+ * The BN254 scalar field F_r is the prime field whose order is the `r`-order of
14
+ * points on the curve — i.e., the number of points on the curve's cyclic group.
15
+ * All arithmetic in ZK circuits (Circom constraints, Groth16 witness values, etc.)
16
+ * is performed modulo this prime. The prime has approximately 254 significant bits,
17
+ * providing roughly 127 bits of symmetric security.
18
+ *
19
+ * The branded type system used here (`SubSubBrandedType`) enforces at compile time
20
+ * that raw `bigint` values have been validated and reduced into the field. This
21
+ * prevents accidentally passing an unreduced value (e.g., a product before modular
22
+ * reduction) where a field element is expected.
23
+ *
24
+ * @see {@link https://eips.ethereum.org/EIPS/eip-196} EIP-196: Precompile for elliptic curve addition and scalar multiplication on alt_bn128
25
+ * @see {@link https://eips.ethereum.org/EIPS/eip-197} EIP-197: Precompile for optimal ate pairing check on alt_bn128
26
+ * @see {@link https://eprint.iacr.org/2010/354} Original BN curve construction paper
27
+ *
28
+ * @packageDocumentation
29
+ * @module math/bn254/types
30
+ */
31
+
32
+ /**
33
+ * A type-safe branded representation of a BN254 (alt_bn128) scalar field element.
34
+ *
35
+ * BN254 is a pairing-friendly elliptic curve that is the foundation of Ethereum's
36
+ * SNARK precompiles and the Circom/Groth16 ecosystem. The scalar field F_r consists
37
+ * of all integers in the range `[0, BN254_FIELD_PRIME - 1]`.
38
+ *
39
+ * @remarks
40
+ * ## Why a Branded Type?
41
+ *
42
+ * A `bigint` can represent any integer, including values outside the field range.
43
+ * Using a branded type ensures that:
44
+ * 1. Only values that have been explicitly validated (via `assertBn254FieldElement`)
45
+ * can be assigned to this type.
46
+ * 2. The TypeScript compiler will reject attempts to pass an arbitrary `bigint` where
47
+ * a `Bn254FieldElement` is expected, catching a whole class of cryptographic bugs.
48
+ * 3. Intermediate values produced by field operations (e.g., `a * b` before reduction)
49
+ * cannot be accidentally used as field elements.
50
+ *
51
+ * ## BN254 Curve Properties
52
+ *
53
+ * - Curve equation: `y^2 = x^3 + 3` over F_p (where p is the base field prime)
54
+ * - Scalar field order: `r = 21888242871839275222246405745257275088548364400416034343698204186575808495617`
55
+ * - Embedding degree: 12 (makes it pairing-friendly)
56
+ * - Security level: ~100 bits (conservative estimate accounting for NFS attacks on pairings)
57
+ * - Supported operations: Groth16 verification, Poseidon hashing, EdDSA (Baby Jubjub)
58
+ *
59
+ * ## Usage
60
+ *
61
+ * Values of this type are inputs and outputs of all field arithmetic functions in
62
+ * this module (`bn254Add`, `bn254Mul`, etc.) and the Poseidon hash functions.
63
+ *
64
+ * @see {@link assertBn254FieldElement} The assertion function that produces values of this type
65
+ * @see {@link BN254_FIELD_PRIME} The modulus that defines the field
66
+ * @see {@link https://eips.ethereum.org/EIPS/eip-196} EIP-196
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * import { type Bn254FieldElement, assertBn254FieldElement, BN254_FIELD_PRIME } from "@umbra/sdk";
71
+ *
72
+ * // Validate and brand a known constant
73
+ * const one = 1n;
74
+ * assertBn254FieldElement(one, "one");
75
+ * // one is now typed as Bn254FieldElement
76
+ *
77
+ * // The type prevents mixing with plain bigint in function signatures
78
+ * function requiresFieldElement(x: Bn254FieldElement): void { /* ... *\/ }
79
+ * requiresFieldElement(42n); // TypeScript compile error
80
+ * requiresFieldElement(one); // OK
81
+ * ```
82
+ *
83
+ * @public
84
+ */
85
+ type Bn254FieldElement = SubSubBrandedType<U256, "Bn254FieldElement">;
86
+
87
+ export type { Bn254FieldElement as B };
@@ -0,0 +1,87 @@
1
+ import { S as SubSubBrandedType, f as U256 } from './types-C_V_CaKK.js';
2
+
3
+ /**
4
+ * BN254 Field Element Types
5
+ *
6
+ * This module defines the foundational type primitives for working with elements
7
+ * of the BN254 (alt_bn128) prime field. BN254 is a pairing-friendly elliptic curve
8
+ * widely used in zero-knowledge proof systems, including Groth16, PLONK, and the
9
+ * Circom/SnarkJS toolchain. Ethereum natively supports BN254 via the EIP-196 and
10
+ * EIP-197 precompiles.
11
+ *
12
+ * @remarks
13
+ * The BN254 scalar field F_r is the prime field whose order is the `r`-order of
14
+ * points on the curve — i.e., the number of points on the curve's cyclic group.
15
+ * All arithmetic in ZK circuits (Circom constraints, Groth16 witness values, etc.)
16
+ * is performed modulo this prime. The prime has approximately 254 significant bits,
17
+ * providing roughly 127 bits of symmetric security.
18
+ *
19
+ * The branded type system used here (`SubSubBrandedType`) enforces at compile time
20
+ * that raw `bigint` values have been validated and reduced into the field. This
21
+ * prevents accidentally passing an unreduced value (e.g., a product before modular
22
+ * reduction) where a field element is expected.
23
+ *
24
+ * @see {@link https://eips.ethereum.org/EIPS/eip-196} EIP-196: Precompile for elliptic curve addition and scalar multiplication on alt_bn128
25
+ * @see {@link https://eips.ethereum.org/EIPS/eip-197} EIP-197: Precompile for optimal ate pairing check on alt_bn128
26
+ * @see {@link https://eprint.iacr.org/2010/354} Original BN curve construction paper
27
+ *
28
+ * @packageDocumentation
29
+ * @module math/bn254/types
30
+ */
31
+
32
+ /**
33
+ * A type-safe branded representation of a BN254 (alt_bn128) scalar field element.
34
+ *
35
+ * BN254 is a pairing-friendly elliptic curve that is the foundation of Ethereum's
36
+ * SNARK precompiles and the Circom/Groth16 ecosystem. The scalar field F_r consists
37
+ * of all integers in the range `[0, BN254_FIELD_PRIME - 1]`.
38
+ *
39
+ * @remarks
40
+ * ## Why a Branded Type?
41
+ *
42
+ * A `bigint` can represent any integer, including values outside the field range.
43
+ * Using a branded type ensures that:
44
+ * 1. Only values that have been explicitly validated (via `assertBn254FieldElement`)
45
+ * can be assigned to this type.
46
+ * 2. The TypeScript compiler will reject attempts to pass an arbitrary `bigint` where
47
+ * a `Bn254FieldElement` is expected, catching a whole class of cryptographic bugs.
48
+ * 3. Intermediate values produced by field operations (e.g., `a * b` before reduction)
49
+ * cannot be accidentally used as field elements.
50
+ *
51
+ * ## BN254 Curve Properties
52
+ *
53
+ * - Curve equation: `y^2 = x^3 + 3` over F_p (where p is the base field prime)
54
+ * - Scalar field order: `r = 21888242871839275222246405745257275088548364400416034343698204186575808495617`
55
+ * - Embedding degree: 12 (makes it pairing-friendly)
56
+ * - Security level: ~100 bits (conservative estimate accounting for NFS attacks on pairings)
57
+ * - Supported operations: Groth16 verification, Poseidon hashing, EdDSA (Baby Jubjub)
58
+ *
59
+ * ## Usage
60
+ *
61
+ * Values of this type are inputs and outputs of all field arithmetic functions in
62
+ * this module (`bn254Add`, `bn254Mul`, etc.) and the Poseidon hash functions.
63
+ *
64
+ * @see {@link assertBn254FieldElement} The assertion function that produces values of this type
65
+ * @see {@link BN254_FIELD_PRIME} The modulus that defines the field
66
+ * @see {@link https://eips.ethereum.org/EIPS/eip-196} EIP-196
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * import { type Bn254FieldElement, assertBn254FieldElement, BN254_FIELD_PRIME } from "@umbra/sdk";
71
+ *
72
+ * // Validate and brand a known constant
73
+ * const one = 1n;
74
+ * assertBn254FieldElement(one, "one");
75
+ * // one is now typed as Bn254FieldElement
76
+ *
77
+ * // The type prevents mixing with plain bigint in function signatures
78
+ * function requiresFieldElement(x: Bn254FieldElement): void { /* ... *\/ }
79
+ * requiresFieldElement(42n); // TypeScript compile error
80
+ * requiresFieldElement(one); // OK
81
+ * ```
82
+ *
83
+ * @public
84
+ */
85
+ type Bn254FieldElement = SubSubBrandedType<U256, "Bn254FieldElement">;
86
+
87
+ export type { Bn254FieldElement as B };