@umbra-privacy/sdk 1.0.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +104 -25
- package/dist/{addresses-Brzgurv_.d.ts → addresses-B7HybtbJ.d.ts} +2 -1
- package/dist/{addresses-D_0YAS6B.d.cts → addresses-CTVY1oi7.d.cts} +2 -1
- package/dist/arcium-BXXlryfe.d.cts +20 -0
- package/dist/arcium-BXXlryfe.d.ts +20 -0
- package/dist/chunk-4RHXVBNI.js +203 -0
- package/dist/chunk-4RHXVBNI.js.map +1 -0
- package/dist/chunk-4TZVXB5G.js +324 -0
- package/dist/chunk-4TZVXB5G.js.map +1 -0
- package/dist/chunk-5GUSMQ74.cjs +549 -0
- package/dist/chunk-5GUSMQ74.cjs.map +1 -0
- package/dist/chunk-5KPQXPQM.js +36 -0
- package/dist/chunk-5KPQXPQM.js.map +1 -0
- package/dist/chunk-AXD7LXYY.cjs +405 -0
- package/dist/chunk-AXD7LXYY.cjs.map +1 -0
- package/dist/{chunk-HOEXDXRC.cjs → chunk-BL6WXLPV.cjs} +32 -360
- package/dist/chunk-BL6WXLPV.cjs.map +1 -0
- package/dist/chunk-CFFLOE7D.cjs +598 -0
- package/dist/chunk-CFFLOE7D.cjs.map +1 -0
- package/dist/{chunk-BM7N6N7E.js → chunk-CFTW5WNG.js} +3 -325
- package/dist/chunk-CFTW5WNG.js.map +1 -0
- package/dist/chunk-DD2WCK4C.js +327 -0
- package/dist/chunk-DD2WCK4C.js.map +1 -0
- package/dist/chunk-DMPMQ74B.cjs +246 -0
- package/dist/chunk-DMPMQ74B.cjs.map +1 -0
- package/dist/{chunk-2Q75CQQJ.js → chunk-EEKF4553.js} +2 -2
- package/dist/chunk-EEKF4553.js.map +1 -0
- package/dist/chunk-ENVYYEM4.cjs +113 -0
- package/dist/chunk-ENVYYEM4.cjs.map +1 -0
- package/dist/chunk-FQX6ZYGJ.js +500 -0
- package/dist/chunk-FQX6ZYGJ.js.map +1 -0
- package/dist/chunk-FSK2ICMB.cjs +39 -0
- package/dist/chunk-FSK2ICMB.cjs.map +1 -0
- package/dist/chunk-FZYWLQAF.cjs +355 -0
- package/dist/chunk-FZYWLQAF.cjs.map +1 -0
- package/dist/chunk-GP26R377.js +436 -0
- package/dist/chunk-GP26R377.js.map +1 -0
- package/dist/chunk-HA5FLM63.js +393 -0
- package/dist/chunk-HA5FLM63.js.map +1 -0
- package/dist/chunk-INJ73LXQ.js +1107 -0
- package/dist/chunk-INJ73LXQ.js.map +1 -0
- package/dist/chunk-JPDF7BIT.cjs +10892 -0
- package/dist/chunk-JPDF7BIT.cjs.map +1 -0
- package/dist/{chunk-MDFSBU5W.cjs → chunk-LTCKPTZC.cjs} +2 -351
- package/dist/chunk-LTCKPTZC.cjs.map +1 -0
- package/dist/chunk-MKNCBUFA.js +564 -0
- package/dist/chunk-MKNCBUFA.js.map +1 -0
- package/dist/chunk-NKVMSABR.cjs +207 -0
- package/dist/chunk-NKVMSABR.cjs.map +1 -0
- package/dist/chunk-OFDWNWCL.js +70 -0
- package/dist/chunk-OFDWNWCL.js.map +1 -0
- package/dist/chunk-QJAUUYZU.cjs +331 -0
- package/dist/chunk-QJAUUYZU.cjs.map +1 -0
- package/dist/chunk-RVUYPKKD.js +10750 -0
- package/dist/chunk-RVUYPKKD.js.map +1 -0
- package/dist/chunk-TLR7A64G.js +103 -0
- package/dist/chunk-TLR7A64G.js.map +1 -0
- package/dist/{chunk-MVKTV3FT.cjs → chunk-TQQZGNOI.cjs} +2 -2
- package/dist/chunk-TQQZGNOI.cjs.map +1 -0
- package/dist/chunk-UOFYS6M3.js +219 -0
- package/dist/chunk-UOFYS6M3.js.map +1 -0
- package/dist/chunk-UXMQI6B7.js +2406 -0
- package/dist/chunk-UXMQI6B7.js.map +1 -0
- package/dist/chunk-WN75ORDT.js +571 -0
- package/dist/chunk-WN75ORDT.js.map +1 -0
- package/dist/chunk-Y55PYKXH.cjs +595 -0
- package/dist/chunk-Y55PYKXH.cjs.map +1 -0
- package/dist/chunk-YEZBTYCP.cjs +77 -0
- package/dist/chunk-YEZBTYCP.cjs.map +1 -0
- package/dist/chunk-ZQOIYCGA.cjs +1126 -0
- package/dist/chunk-ZQOIYCGA.cjs.map +1 -0
- package/dist/chunk-ZY3TSHMJ.cjs +2665 -0
- package/dist/chunk-ZY3TSHMJ.cjs.map +1 -0
- package/dist/client-DkVBHMWb.d.cts +2613 -0
- package/dist/client-V4AF6Bz9.d.ts +2613 -0
- package/dist/common/pda/index.cjs +145 -0
- package/dist/common/pda/index.cjs.map +1 -0
- package/dist/common/pda/index.d.cts +1250 -0
- package/dist/common/pda/index.d.ts +1250 -0
- package/dist/common/pda/index.js +8 -0
- package/dist/common/pda/index.js.map +1 -0
- package/dist/constants/index.cjs +38 -164
- package/dist/constants/index.cjs.map +1 -1
- package/dist/constants/index.d.cts +8 -425
- package/dist/constants/index.d.ts +8 -425
- package/dist/constants/index.js +15 -124
- package/dist/constants/index.js.map +1 -1
- package/dist/crypto/index.cjs +583 -0
- package/dist/crypto/index.cjs.map +1 -0
- package/dist/crypto/index.d.cts +6731 -0
- package/dist/crypto/index.d.ts +6731 -0
- package/dist/crypto/index.js +14 -0
- package/dist/crypto/index.js.map +1 -0
- package/dist/{cryptography-BTGC72u-.d.ts → cryptography-BFSJcvi6.d.ts} +3 -2465
- package/dist/{cryptography-BTGC72u-.d.cts → cryptography-D6tPDh-Y.d.cts} +3 -2465
- package/dist/errors/index.cjs +64 -54
- package/dist/errors/index.d.cts +7 -797
- package/dist/errors/index.d.ts +7 -797
- package/dist/errors/index.js +3 -1
- package/dist/errors-B9EoPeWV.d.cts +593 -0
- package/dist/errors-B9EoPeWV.d.ts +593 -0
- package/dist/errors-DAIrstEL.d.cts +300 -0
- package/dist/errors-DPNMfyh0.d.ts +300 -0
- package/dist/index-BG0yjL7C.d.cts +6006 -0
- package/dist/index-ByynoyBO.d.ts +6006 -0
- package/dist/index.cjs +5126 -16118
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1031 -7685
- package/dist/index.d.ts +1031 -7685
- package/dist/index.js +3219 -14905
- package/dist/index.js.map +1 -1
- package/dist/interfaces/index.d.cts +14 -6
- package/dist/interfaces/index.d.ts +14 -6
- package/dist/interfaces-43cReBcS.d.cts +3346 -0
- package/dist/interfaces-B8xKNl_6.d.ts +997 -0
- package/dist/interfaces-D2NO6kDD.d.cts +997 -0
- package/dist/interfaces-z_xYJlgV.d.ts +3346 -0
- package/dist/math/index.cjs +115 -0
- package/dist/math/index.cjs.map +1 -0
- package/dist/math/index.d.cts +1327 -0
- package/dist/math/index.d.ts +1327 -0
- package/dist/math/index.js +10 -0
- package/dist/math/index.js.map +1 -0
- package/dist/networks-RMd3abPE.d.ts +44 -0
- package/dist/networks-yAoO8peQ.d.cts +44 -0
- package/dist/relayer-NRRMSMNB.js +4 -0
- package/dist/relayer-NRRMSMNB.js.map +1 -0
- package/dist/relayer-RJHEIXJG.cjs +21 -0
- package/dist/relayer-RJHEIXJG.cjs.map +1 -0
- package/dist/solana/index.cjs +56 -0
- package/dist/solana/index.cjs.map +1 -0
- package/dist/solana/index.d.cts +105 -0
- package/dist/solana/index.d.ts +105 -0
- package/dist/solana/index.js +7 -0
- package/dist/solana/index.js.map +1 -0
- package/dist/{index-CLj_zWSD.d.ts → temporal-BbRaEPoO.d.ts} +1 -1
- package/dist/{index-CX6_pIRS.d.cts → temporal-oUj7iCaq.d.cts} +1 -1
- package/dist/transaction-forwarder-5mAMTjw6.d.ts +1155 -0
- package/dist/transaction-forwarder-C6gMUG7a.d.cts +1155 -0
- package/dist/types/index.cjs +232 -231
- package/dist/types/index.d.cts +15 -1485
- package/dist/types/index.d.ts +15 -1485
- package/dist/types/index.js +2 -1
- package/dist/types-BohhvPth.d.cts +87 -0
- package/dist/types-CW0oTT0j.d.ts +87 -0
- package/dist/types-C_V_CaKK.d.cts +2468 -0
- package/dist/types-C_V_CaKK.d.ts +2468 -0
- package/dist/types-Ca7frykr.d.ts +793 -0
- package/dist/types-CuKeoI19.d.cts +1296 -0
- package/dist/types-CxfTIpN9.d.ts +1052 -0
- package/dist/{types-n-sHFcgr.d.ts → types-D1jDUjfN.d.ts} +2 -2
- package/dist/types-DKEDUlH9.d.ts +1296 -0
- package/dist/types-EKuIfxTz.d.cts +1052 -0
- package/dist/{types-BBuELtY8.d.cts → types-IMGYmlv-.d.cts} +2 -2
- package/dist/types-PwNLi_2k.d.cts +793 -0
- package/dist/utils/index.cjs +823 -525
- package/dist/utils/index.d.cts +1711 -4021
- package/dist/utils/index.d.ts +1711 -4021
- package/dist/utils/index.js +9 -3
- package/dist/{versions-D9PqsEvj.d.cts → versions-BRlR36EA.d.cts} +1 -0
- package/dist/{versions-D9PqsEvj.d.ts → versions-BRlR36EA.d.ts} +1 -0
- package/package.json +79 -18
- package/dist/chunk-2Q75CQQJ.js.map +0 -1
- package/dist/chunk-BM7N6N7E.js.map +0 -1
- package/dist/chunk-GXKSUB2U.cjs +0 -4416
- package/dist/chunk-GXKSUB2U.cjs.map +0 -1
- package/dist/chunk-HOEXDXRC.cjs.map +0 -1
- package/dist/chunk-MDFSBU5W.cjs.map +0 -1
- package/dist/chunk-MQY7HDIA.js +0 -600
- package/dist/chunk-MQY7HDIA.js.map +0 -1
- package/dist/chunk-MVKTV3FT.cjs.map +0 -1
- package/dist/chunk-PG2J6V6Y.js +0 -4094
- package/dist/chunk-PG2J6V6Y.js.map +0 -1
- package/dist/chunk-VEGLTTYQ.cjs +0 -621
- package/dist/chunk-VEGLTTYQ.cjs.map +0 -1
- package/dist/chunk-WVHQ46DD.js +0 -758
- package/dist/chunk-WVHQ46DD.js.map +0 -1
- package/dist/index-B9pDY73x.d.ts +0 -12933
- package/dist/index-D33yo0qB.d.cts +0 -12933
- package/dist/networks-C-orpSFW.d.ts +0 -65
- package/dist/networks-FxYERGD1.d.cts +0 -65
package/dist/types/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export {
|
|
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 };
|