@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
|
@@ -0,0 +1,571 @@
|
|
|
1
|
+
import { createU256BeBytes } from './chunk-UOFYS6M3.js';
|
|
2
|
+
import { decodeU256BeBytesToU256 } from './chunk-FQX6ZYGJ.js';
|
|
3
|
+
import { CryptographyAssertionError } from './chunk-4TZVXB5G.js';
|
|
4
|
+
import { U256_BYTE_LENGTH } from './chunk-CFTW5WNG.js';
|
|
5
|
+
import { __name } from './chunk-7QVYU63E.js';
|
|
6
|
+
|
|
7
|
+
// src/math/bn254/types.ts
|
|
8
|
+
var BN254_FIELD_PRIME = 21888242871839275222246405745257275088548364400416034343698204186575808495617n;
|
|
9
|
+
function assertBn254FieldElement(value, name = "value") {
|
|
10
|
+
const variableName = name;
|
|
11
|
+
if (typeof value !== "bigint") {
|
|
12
|
+
throw new CryptographyAssertionError(`${variableName}: Expected bigint, got ${typeof value}`, {
|
|
13
|
+
value,
|
|
14
|
+
expectedType: "Bn254FieldElement"
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
if (value < 0n) {
|
|
18
|
+
throw new CryptographyAssertionError(`${variableName}: Value ${String(value)} is negative`, {
|
|
19
|
+
value,
|
|
20
|
+
expectedType: "Bn254FieldElement",
|
|
21
|
+
constraint: "value >= 0"
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
if (value >= BN254_FIELD_PRIME) {
|
|
25
|
+
throw new CryptographyAssertionError(`${variableName}: Value exceeds BN254 field prime`, {
|
|
26
|
+
value,
|
|
27
|
+
expectedType: "Bn254FieldElement",
|
|
28
|
+
constraint: `value < ${String(BN254_FIELD_PRIME)}`
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
__name(assertBn254FieldElement, "assertBn254FieldElement");
|
|
33
|
+
|
|
34
|
+
// src/math/bn254/field-arithmetic.ts
|
|
35
|
+
var N64 = 64n;
|
|
36
|
+
var MASK64 = 0xffffffffffffffffn;
|
|
37
|
+
var P_LIMBS = [
|
|
38
|
+
0x43e1f593f0000001n,
|
|
39
|
+
// limb 0 (bits 0-63)
|
|
40
|
+
0x2833e84879b97091n,
|
|
41
|
+
// limb 1 (bits 64-127)
|
|
42
|
+
0xb85045b68181585dn,
|
|
43
|
+
// limb 2 (bits 128-191)
|
|
44
|
+
0x30644e72e131a029n
|
|
45
|
+
// limb 3 (bits 192-255)
|
|
46
|
+
];
|
|
47
|
+
var P_PRIME = 0xc2e1f593efffffffn;
|
|
48
|
+
var R2_LIMBS = [
|
|
49
|
+
0x1bb8e645ae216da7n,
|
|
50
|
+
0x53fe3ab1e35c59e3n,
|
|
51
|
+
0x8c49833d53bb8085n,
|
|
52
|
+
0x0216d0b17f4e44a5n
|
|
53
|
+
];
|
|
54
|
+
var ONE_MONT = [
|
|
55
|
+
0xac96341c4ffffffbn,
|
|
56
|
+
0x36fc76959f60cd29n,
|
|
57
|
+
0x666ea36f7879462en,
|
|
58
|
+
0x0e0a77c19a07df2fn
|
|
59
|
+
];
|
|
60
|
+
function ctSelect(bit, x, y) {
|
|
61
|
+
const mask = -bit;
|
|
62
|
+
return x & mask | y & ~mask;
|
|
63
|
+
}
|
|
64
|
+
__name(ctSelect, "ctSelect");
|
|
65
|
+
function bigintToLimbs(value) {
|
|
66
|
+
return [
|
|
67
|
+
value & MASK64,
|
|
68
|
+
value >> N64 & MASK64,
|
|
69
|
+
value >> N64 * 2n & MASK64,
|
|
70
|
+
value >> N64 * 3n & MASK64
|
|
71
|
+
];
|
|
72
|
+
}
|
|
73
|
+
__name(bigintToLimbs, "bigintToLimbs");
|
|
74
|
+
function limbsToBigint(limbs) {
|
|
75
|
+
return limbs[0] + (limbs[1] << N64) + (limbs[2] << N64 * 2n) + (limbs[3] << N64 * 3n);
|
|
76
|
+
}
|
|
77
|
+
__name(limbsToBigint, "limbsToBigint");
|
|
78
|
+
function addModuleLimbs(a, b) {
|
|
79
|
+
const t = [0n, 0n, 0n, 0n];
|
|
80
|
+
let carry = 0n;
|
|
81
|
+
for (let index = 0; index < 4; index++) {
|
|
82
|
+
const sum = a[index] + b[index] + carry;
|
|
83
|
+
t[index] = sum & MASK64;
|
|
84
|
+
carry = sum >> N64;
|
|
85
|
+
}
|
|
86
|
+
const tCarry = carry;
|
|
87
|
+
const d = [0n, 0n, 0n, 0n];
|
|
88
|
+
let borrow = 0n;
|
|
89
|
+
for (let index = 0; index < 4; index++) {
|
|
90
|
+
const sub = t[index] - P_LIMBS[index] - borrow;
|
|
91
|
+
d[index] = sub & MASK64;
|
|
92
|
+
borrow = -(sub >> N64);
|
|
93
|
+
}
|
|
94
|
+
const useD = tCarry | 1n - borrow;
|
|
95
|
+
return [
|
|
96
|
+
ctSelect(useD, d[0], t[0]),
|
|
97
|
+
ctSelect(useD, d[1], t[1]),
|
|
98
|
+
ctSelect(useD, d[2], t[2]),
|
|
99
|
+
ctSelect(useD, d[3], t[3])
|
|
100
|
+
];
|
|
101
|
+
}
|
|
102
|
+
__name(addModuleLimbs, "addModuleLimbs");
|
|
103
|
+
function subModuleLimbs(a, b) {
|
|
104
|
+
const out = [0n, 0n, 0n, 0n];
|
|
105
|
+
let borrow = 0n;
|
|
106
|
+
for (let index = 0; index < 4; index++) {
|
|
107
|
+
const sub = a[index] - b[index] - borrow;
|
|
108
|
+
out[index] = sub & MASK64;
|
|
109
|
+
borrow = -(sub >> N64);
|
|
110
|
+
}
|
|
111
|
+
const mask = -borrow;
|
|
112
|
+
let carry = 0n;
|
|
113
|
+
for (let index = 0; index < 4; index++) {
|
|
114
|
+
const addValue = P_LIMBS[index] & mask;
|
|
115
|
+
const sum = out[index] + addValue + carry;
|
|
116
|
+
out[index] = sum & MASK64;
|
|
117
|
+
carry = sum >> N64;
|
|
118
|
+
}
|
|
119
|
+
return [out[0], out[1], out[2], out[3]];
|
|
120
|
+
}
|
|
121
|
+
__name(subModuleLimbs, "subModuleLimbs");
|
|
122
|
+
function montgomeryMulLimbs(a, b) {
|
|
123
|
+
const t = [0n, 0n, 0n, 0n, 0n, 0n, 0n, 0n, 0n];
|
|
124
|
+
for (let index = 0; index < 4; index++) {
|
|
125
|
+
let carry = 0n;
|
|
126
|
+
for (let innerIndex = 0; innerIndex < 4; innerIndex++) {
|
|
127
|
+
const sum = t[index + innerIndex] + a[index] * b[innerIndex] + carry;
|
|
128
|
+
t[index + innerIndex] = sum & MASK64;
|
|
129
|
+
carry = sum >> N64;
|
|
130
|
+
}
|
|
131
|
+
t[index + 4] = t[index + 4] + carry;
|
|
132
|
+
const m = t[index] * P_PRIME & MASK64;
|
|
133
|
+
let carryRed = 0n;
|
|
134
|
+
for (let innerIndex = 0; innerIndex < 4; innerIndex++) {
|
|
135
|
+
const sum = t[index + innerIndex] + m * P_LIMBS[innerIndex] + carryRed;
|
|
136
|
+
t[index + innerIndex] = sum & MASK64;
|
|
137
|
+
carryRed = sum >> N64;
|
|
138
|
+
}
|
|
139
|
+
const sumUp = t[index + 4] + carryRed;
|
|
140
|
+
t[index + 4] = sumUp & MASK64;
|
|
141
|
+
t[index + 5] = t[index + 5] + (sumUp >> N64);
|
|
142
|
+
}
|
|
143
|
+
const result = [t[4], t[5], t[6], t[7]];
|
|
144
|
+
const subResult = [0n, 0n, 0n, 0n];
|
|
145
|
+
let borrow = 0n;
|
|
146
|
+
for (let k = 0; k < 4; k++) {
|
|
147
|
+
const s = result[k] - P_LIMBS[k] - borrow;
|
|
148
|
+
subResult[k] = s & MASK64;
|
|
149
|
+
borrow = -(s >> N64);
|
|
150
|
+
}
|
|
151
|
+
const useSub = 1n - borrow;
|
|
152
|
+
return [
|
|
153
|
+
ctSelect(useSub, subResult[0], result[0]),
|
|
154
|
+
ctSelect(useSub, subResult[1], result[1]),
|
|
155
|
+
ctSelect(useSub, subResult[2], result[2]),
|
|
156
|
+
ctSelect(useSub, subResult[3], result[3])
|
|
157
|
+
];
|
|
158
|
+
}
|
|
159
|
+
__name(montgomeryMulLimbs, "montgomeryMulLimbs");
|
|
160
|
+
function toMontgomery(a) {
|
|
161
|
+
return montgomeryMulLimbs(a, R2_LIMBS);
|
|
162
|
+
}
|
|
163
|
+
__name(toMontgomery, "toMontgomery");
|
|
164
|
+
function fromMontgomery(a) {
|
|
165
|
+
const one = [1n, 0n, 0n, 0n];
|
|
166
|
+
return montgomeryMulLimbs(a, one);
|
|
167
|
+
}
|
|
168
|
+
__name(fromMontgomery, "fromMontgomery");
|
|
169
|
+
function negModuleLimbs(a) {
|
|
170
|
+
const isZero = (a[0] | a[1] | a[2] | a[3]) === 0n ? 1n : 0n;
|
|
171
|
+
const result = subModuleLimbs(P_LIMBS, a);
|
|
172
|
+
return [
|
|
173
|
+
ctSelect(isZero, 0n, result[0]),
|
|
174
|
+
ctSelect(isZero, 0n, result[1]),
|
|
175
|
+
ctSelect(isZero, 0n, result[2]),
|
|
176
|
+
ctSelect(isZero, 0n, result[3])
|
|
177
|
+
];
|
|
178
|
+
}
|
|
179
|
+
__name(negModuleLimbs, "negModuleLimbs");
|
|
180
|
+
function moduleExpMontgomery(base, exp) {
|
|
181
|
+
let result = ONE_MONT;
|
|
182
|
+
let current = base;
|
|
183
|
+
while (exp > 0n) {
|
|
184
|
+
if ((exp & 1n) === 1n) {
|
|
185
|
+
result = montgomeryMulLimbs(result, current);
|
|
186
|
+
}
|
|
187
|
+
current = montgomeryMulLimbs(current, current);
|
|
188
|
+
exp >>= 1n;
|
|
189
|
+
}
|
|
190
|
+
return result;
|
|
191
|
+
}
|
|
192
|
+
__name(moduleExpMontgomery, "moduleExpMontgomery");
|
|
193
|
+
var bn254ModuloAdd = /* @__PURE__ */ __name((a, b) => {
|
|
194
|
+
const aLimbs = bigintToLimbs(a);
|
|
195
|
+
const bLimbs = bigintToLimbs(b);
|
|
196
|
+
const resultLimbs = addModuleLimbs(aLimbs, bLimbs);
|
|
197
|
+
return limbsToBigint(resultLimbs);
|
|
198
|
+
}, "bn254ModuloAdd");
|
|
199
|
+
var bn254ModuloSub = /* @__PURE__ */ __name((a, b) => {
|
|
200
|
+
const aLimbs = bigintToLimbs(a);
|
|
201
|
+
const bLimbs = bigintToLimbs(b);
|
|
202
|
+
const resultLimbs = subModuleLimbs(aLimbs, bLimbs);
|
|
203
|
+
return limbsToBigint(resultLimbs);
|
|
204
|
+
}, "bn254ModuloSub");
|
|
205
|
+
var bn254ModuloMul = /* @__PURE__ */ __name((a, b) => {
|
|
206
|
+
const aLimbs = bigintToLimbs(a);
|
|
207
|
+
const bLimbs = bigintToLimbs(b);
|
|
208
|
+
const aMont = toMontgomery(aLimbs);
|
|
209
|
+
const bMont = toMontgomery(bLimbs);
|
|
210
|
+
const resultMont = montgomeryMulLimbs(aMont, bMont);
|
|
211
|
+
const resultLimbs = fromMontgomery(resultMont);
|
|
212
|
+
return limbsToBigint(resultLimbs);
|
|
213
|
+
}, "bn254ModuloMul");
|
|
214
|
+
var bn254ModuloNeg = /* @__PURE__ */ __name((a) => {
|
|
215
|
+
const aLimbs = bigintToLimbs(a);
|
|
216
|
+
const resultLimbs = negModuleLimbs(aLimbs);
|
|
217
|
+
return limbsToBigint(resultLimbs);
|
|
218
|
+
}, "bn254ModuloNeg");
|
|
219
|
+
var bn254ModuloInv = /* @__PURE__ */ __name((a) => {
|
|
220
|
+
if (a === 0n) {
|
|
221
|
+
throw new Error("Cannot compute modular inverse of zero");
|
|
222
|
+
}
|
|
223
|
+
const aLimbs = bigintToLimbs(a);
|
|
224
|
+
const aMont = toMontgomery(aLimbs);
|
|
225
|
+
const exp = BN254_FIELD_PRIME - 2n;
|
|
226
|
+
const resultMont = moduleExpMontgomery(aMont, exp);
|
|
227
|
+
const resultLimbs = fromMontgomery(resultMont);
|
|
228
|
+
return limbsToBigint(resultLimbs);
|
|
229
|
+
}, "bn254ModuloInv");
|
|
230
|
+
var cachedModuleAdder = null;
|
|
231
|
+
var cachedModuleSubtractor = null;
|
|
232
|
+
var cachedModuleMultiplier = null;
|
|
233
|
+
var cachedModuleNegator = null;
|
|
234
|
+
var cachedModuleInverter = null;
|
|
235
|
+
function getBn254ModularAdder() {
|
|
236
|
+
cachedModuleAdder ??= bn254ModuloAdd;
|
|
237
|
+
return cachedModuleAdder;
|
|
238
|
+
}
|
|
239
|
+
__name(getBn254ModularAdder, "getBn254ModularAdder");
|
|
240
|
+
function getBn254ModularSubtractor() {
|
|
241
|
+
cachedModuleSubtractor ??= bn254ModuloSub;
|
|
242
|
+
return cachedModuleSubtractor;
|
|
243
|
+
}
|
|
244
|
+
__name(getBn254ModularSubtractor, "getBn254ModularSubtractor");
|
|
245
|
+
function getBn254ModularMultiplier() {
|
|
246
|
+
cachedModuleMultiplier ??= bn254ModuloMul;
|
|
247
|
+
return cachedModuleMultiplier;
|
|
248
|
+
}
|
|
249
|
+
__name(getBn254ModularMultiplier, "getBn254ModularMultiplier");
|
|
250
|
+
function getBn254ModularNegator() {
|
|
251
|
+
cachedModuleNegator ??= bn254ModuloNeg;
|
|
252
|
+
return cachedModuleNegator;
|
|
253
|
+
}
|
|
254
|
+
__name(getBn254ModularNegator, "getBn254ModularNegator");
|
|
255
|
+
function getBn254ModularInverter() {
|
|
256
|
+
cachedModuleInverter ??= bn254ModuloInv;
|
|
257
|
+
return cachedModuleInverter;
|
|
258
|
+
}
|
|
259
|
+
__name(getBn254ModularInverter, "getBn254ModularInverter");
|
|
260
|
+
function computeBn254LimbwiseSumInverse(limbs) {
|
|
261
|
+
const sum = (limbs.low + limbs.middle + limbs.high) % BN254_FIELD_PRIME;
|
|
262
|
+
if (sum === 0n) {
|
|
263
|
+
throw new Error(
|
|
264
|
+
"Cannot compute modular inverse of zero sum. The sum of Base85 limbs must be non-zero."
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
const inverse = bn254ModuloInv(sum);
|
|
268
|
+
assertBn254FieldElement(inverse);
|
|
269
|
+
return inverse;
|
|
270
|
+
}
|
|
271
|
+
__name(computeBn254LimbwiseSumInverse, "computeBn254LimbwiseSumInverse");
|
|
272
|
+
|
|
273
|
+
// src/math/bn254/field-element-sampler.ts
|
|
274
|
+
var N642 = 64n;
|
|
275
|
+
var MASK642 = 0xffffffffffffffffn;
|
|
276
|
+
var P_LIMBS2 = [
|
|
277
|
+
0x43e1f593f0000001n,
|
|
278
|
+
// limb 0 (bits 0-63)
|
|
279
|
+
0x2833e84879b97091n,
|
|
280
|
+
// limb 1 (bits 64-127)
|
|
281
|
+
0xb85045b68181585dn,
|
|
282
|
+
// limb 2 (bits 128-191)
|
|
283
|
+
0x30644e72e131a029n
|
|
284
|
+
// limb 3 (bits 192-255)
|
|
285
|
+
];
|
|
286
|
+
var R_MOD_P = 6350874878119819312338956282401532410528162663560392320966563075034087161851n;
|
|
287
|
+
function ctSelect2(bit, x, y) {
|
|
288
|
+
const mask = -bit;
|
|
289
|
+
return x & mask | y & ~mask;
|
|
290
|
+
}
|
|
291
|
+
__name(ctSelect2, "ctSelect");
|
|
292
|
+
function bigintToLimbs2(value) {
|
|
293
|
+
return [
|
|
294
|
+
value & MASK642,
|
|
295
|
+
value >> N642 & MASK642,
|
|
296
|
+
value >> N642 * 2n & MASK642,
|
|
297
|
+
value >> N642 * 3n & MASK642
|
|
298
|
+
];
|
|
299
|
+
}
|
|
300
|
+
__name(bigintToLimbs2, "bigintToLimbs");
|
|
301
|
+
function limbsToBigint2(limbs) {
|
|
302
|
+
return limbs[0] + (limbs[1] << N642) + (limbs[2] << N642 * 2n) + (limbs[3] << N642 * 3n);
|
|
303
|
+
}
|
|
304
|
+
__name(limbsToBigint2, "limbsToBigint");
|
|
305
|
+
function conditionalSubtractP(limbs) {
|
|
306
|
+
const [l0, l1, l2, l3] = limbs;
|
|
307
|
+
const [p0, p1, p2, p3] = P_LIMBS2;
|
|
308
|
+
const sub0 = l0 - p0;
|
|
309
|
+
const d0 = sub0 & MASK642;
|
|
310
|
+
const borrow0 = -(sub0 >> N642) & 1n;
|
|
311
|
+
const sub1 = l1 - p1 - borrow0;
|
|
312
|
+
const d1 = sub1 & MASK642;
|
|
313
|
+
const borrow1 = -(sub1 >> N642) & 1n;
|
|
314
|
+
const sub2 = l2 - p2 - borrow1;
|
|
315
|
+
const d2 = sub2 & MASK642;
|
|
316
|
+
const borrow2 = -(sub2 >> N642) & 1n;
|
|
317
|
+
const sub3 = l3 - p3 - borrow2;
|
|
318
|
+
const d3 = sub3 & MASK642;
|
|
319
|
+
const borrow3 = -(sub3 >> N642) & 1n;
|
|
320
|
+
const useOriginal = borrow3;
|
|
321
|
+
return [
|
|
322
|
+
ctSelect2(useOriginal, l0, d0),
|
|
323
|
+
ctSelect2(useOriginal, l1, d1),
|
|
324
|
+
ctSelect2(useOriginal, l2, d2),
|
|
325
|
+
ctSelect2(useOriginal, l3, d3)
|
|
326
|
+
];
|
|
327
|
+
}
|
|
328
|
+
__name(conditionalSubtractP, "conditionalSubtractP");
|
|
329
|
+
function reduce256(value) {
|
|
330
|
+
let limbs = bigintToLimbs2(value);
|
|
331
|
+
limbs = conditionalSubtractP(limbs);
|
|
332
|
+
limbs = conditionalSubtractP(limbs);
|
|
333
|
+
limbs = conditionalSubtractP(limbs);
|
|
334
|
+
limbs = conditionalSubtractP(limbs);
|
|
335
|
+
limbs = conditionalSubtractP(limbs);
|
|
336
|
+
return limbsToBigint2(limbs);
|
|
337
|
+
}
|
|
338
|
+
__name(reduce256, "reduce256");
|
|
339
|
+
function bytesToBigintBE(bytes, offset) {
|
|
340
|
+
const slice = bytes.slice(offset, offset + U256_BYTE_LENGTH);
|
|
341
|
+
const u256BeBytes = createU256BeBytes(slice);
|
|
342
|
+
return decodeU256BeBytesToU256(u256BeBytes);
|
|
343
|
+
}
|
|
344
|
+
__name(bytesToBigintBE, "bytesToBigintBE");
|
|
345
|
+
function getBn254FieldElementSampler(deps) {
|
|
346
|
+
const { modAdd: moduleAdd = bn254ModuloAdd, modMul: moduleMul = bn254ModuloMul } = deps ?? {};
|
|
347
|
+
return (input) => {
|
|
348
|
+
const high = bytesToBigintBE(input, 0);
|
|
349
|
+
const low = bytesToBigintBE(input, 32);
|
|
350
|
+
const lowReduced = reduce256(low);
|
|
351
|
+
const highReduced = reduce256(high);
|
|
352
|
+
const highTimesR = moduleMul(highReduced, R_MOD_P);
|
|
353
|
+
const result = moduleAdd(highTimesR, lowReduced);
|
|
354
|
+
return result;
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
__name(getBn254FieldElementSampler, "getBn254FieldElementSampler");
|
|
358
|
+
var bn254FieldElementSampler = getBn254FieldElementSampler();
|
|
359
|
+
|
|
360
|
+
// src/math/curve25519/types.ts
|
|
361
|
+
var CURVE25519_FIELD_PRIME = (1n << 255n) - 19n;
|
|
362
|
+
|
|
363
|
+
// src/math/curve25519/field-arithmetic.ts
|
|
364
|
+
var N643 = 64n;
|
|
365
|
+
var MASK643 = 0xffffffffffffffffn;
|
|
366
|
+
var P_LIMBS3 = [
|
|
367
|
+
0xffffffffffffffedn,
|
|
368
|
+
// limb 0 (bits 0-63): 2^64 - 19
|
|
369
|
+
0xffffffffffffffffn,
|
|
370
|
+
// limb 1 (bits 64-127): all 1s
|
|
371
|
+
0xffffffffffffffffn,
|
|
372
|
+
// limb 2 (bits 128-191): all 1s
|
|
373
|
+
0x7fffffffffffffffn
|
|
374
|
+
// limb 3 (bits 192-255): 2^63 - 1
|
|
375
|
+
];
|
|
376
|
+
function ctSelect3(bit, x, y) {
|
|
377
|
+
const mask = -bit;
|
|
378
|
+
return x & mask | y & ~mask;
|
|
379
|
+
}
|
|
380
|
+
__name(ctSelect3, "ctSelect");
|
|
381
|
+
function bigintToLimbs3(value) {
|
|
382
|
+
return [
|
|
383
|
+
value & MASK643,
|
|
384
|
+
value >> N643 & MASK643,
|
|
385
|
+
value >> N643 * 2n & MASK643,
|
|
386
|
+
value >> N643 * 3n & MASK643
|
|
387
|
+
];
|
|
388
|
+
}
|
|
389
|
+
__name(bigintToLimbs3, "bigintToLimbs");
|
|
390
|
+
function limbsToBigint3(limbs) {
|
|
391
|
+
return limbs[0] + (limbs[1] << N643) + (limbs[2] << N643 * 2n) + (limbs[3] << N643 * 3n);
|
|
392
|
+
}
|
|
393
|
+
__name(limbsToBigint3, "limbsToBigint");
|
|
394
|
+
function addModuleLimbs2(a, b) {
|
|
395
|
+
const t = [0n, 0n, 0n, 0n];
|
|
396
|
+
let carry = 0n;
|
|
397
|
+
for (let index = 0; index < 4; index++) {
|
|
398
|
+
const sum = a[index] + b[index] + carry;
|
|
399
|
+
t[index] = sum & MASK643;
|
|
400
|
+
carry = sum >> N643;
|
|
401
|
+
}
|
|
402
|
+
const tCarry = carry;
|
|
403
|
+
const d = [0n, 0n, 0n, 0n];
|
|
404
|
+
let borrow = 0n;
|
|
405
|
+
for (let index = 0; index < 4; index++) {
|
|
406
|
+
const sub = t[index] - P_LIMBS3[index] - borrow;
|
|
407
|
+
d[index] = sub & MASK643;
|
|
408
|
+
borrow = -(sub >> N643);
|
|
409
|
+
}
|
|
410
|
+
const useD = tCarry | 1n - borrow;
|
|
411
|
+
return [
|
|
412
|
+
ctSelect3(useD, d[0], t[0]),
|
|
413
|
+
ctSelect3(useD, d[1], t[1]),
|
|
414
|
+
ctSelect3(useD, d[2], t[2]),
|
|
415
|
+
ctSelect3(useD, d[3], t[3])
|
|
416
|
+
];
|
|
417
|
+
}
|
|
418
|
+
__name(addModuleLimbs2, "addModuleLimbs");
|
|
419
|
+
function subModuleLimbs2(a, b) {
|
|
420
|
+
const out = [0n, 0n, 0n, 0n];
|
|
421
|
+
let borrow = 0n;
|
|
422
|
+
for (let index = 0; index < 4; index++) {
|
|
423
|
+
const sub = a[index] - b[index] - borrow;
|
|
424
|
+
out[index] = sub & MASK643;
|
|
425
|
+
borrow = -(sub >> N643);
|
|
426
|
+
}
|
|
427
|
+
const mask = -borrow;
|
|
428
|
+
let carry = 0n;
|
|
429
|
+
for (let index = 0; index < 4; index++) {
|
|
430
|
+
const addValue = P_LIMBS3[index] & mask;
|
|
431
|
+
const sum = out[index] + addValue + carry;
|
|
432
|
+
out[index] = sum & MASK643;
|
|
433
|
+
carry = sum >> N643;
|
|
434
|
+
}
|
|
435
|
+
return [out[0], out[1], out[2], out[3]];
|
|
436
|
+
}
|
|
437
|
+
__name(subModuleLimbs2, "subModuleLimbs");
|
|
438
|
+
function mulModuleLimbs(a, b) {
|
|
439
|
+
const aBig = limbsToBigint3(a);
|
|
440
|
+
const bBig = limbsToBigint3(b);
|
|
441
|
+
const product = aBig * bBig % CURVE25519_FIELD_PRIME;
|
|
442
|
+
return bigintToLimbs3(product);
|
|
443
|
+
}
|
|
444
|
+
__name(mulModuleLimbs, "mulModuleLimbs");
|
|
445
|
+
function moduleExpLimbs(base, exp) {
|
|
446
|
+
let result = [1n, 0n, 0n, 0n];
|
|
447
|
+
let current = base;
|
|
448
|
+
while (exp > 0n) {
|
|
449
|
+
if ((exp & 1n) === 1n) {
|
|
450
|
+
result = mulModuleLimbs(result, current);
|
|
451
|
+
}
|
|
452
|
+
current = mulModuleLimbs(current, current);
|
|
453
|
+
exp >>= 1n;
|
|
454
|
+
}
|
|
455
|
+
return result;
|
|
456
|
+
}
|
|
457
|
+
__name(moduleExpLimbs, "moduleExpLimbs");
|
|
458
|
+
var curve25519ModuloAdd = /* @__PURE__ */ __name((a, b) => {
|
|
459
|
+
const aLimbs = bigintToLimbs3(a);
|
|
460
|
+
const bLimbs = bigintToLimbs3(b);
|
|
461
|
+
const resultLimbs = addModuleLimbs2(aLimbs, bLimbs);
|
|
462
|
+
return limbsToBigint3(resultLimbs);
|
|
463
|
+
}, "curve25519ModuloAdd");
|
|
464
|
+
var curve25519ModuloSub = /* @__PURE__ */ __name((a, b) => {
|
|
465
|
+
const aLimbs = bigintToLimbs3(a);
|
|
466
|
+
const bLimbs = bigintToLimbs3(b);
|
|
467
|
+
const resultLimbs = subModuleLimbs2(aLimbs, bLimbs);
|
|
468
|
+
return limbsToBigint3(resultLimbs);
|
|
469
|
+
}, "curve25519ModuloSub");
|
|
470
|
+
var curve25519ModuloMul = /* @__PURE__ */ __name((a, b) => {
|
|
471
|
+
const aLimbs = bigintToLimbs3(a);
|
|
472
|
+
const bLimbs = bigintToLimbs3(b);
|
|
473
|
+
const resultLimbs = mulModuleLimbs(aLimbs, bLimbs);
|
|
474
|
+
return limbsToBigint3(resultLimbs);
|
|
475
|
+
}, "curve25519ModuloMul");
|
|
476
|
+
var curve25519ModuloInv = /* @__PURE__ */ __name((a) => {
|
|
477
|
+
if (a === 0n) {
|
|
478
|
+
throw new Error("Cannot compute modular inverse of zero");
|
|
479
|
+
}
|
|
480
|
+
const aLimbs = bigintToLimbs3(a);
|
|
481
|
+
const exp = CURVE25519_FIELD_PRIME - 2n;
|
|
482
|
+
const resultLimbs = moduleExpLimbs(aLimbs, exp);
|
|
483
|
+
return limbsToBigint3(resultLimbs);
|
|
484
|
+
}, "curve25519ModuloInv");
|
|
485
|
+
var curve25519ModuloPow = /* @__PURE__ */ __name((base, exp) => {
|
|
486
|
+
if (exp === 0n) {
|
|
487
|
+
return 1n;
|
|
488
|
+
}
|
|
489
|
+
const baseLimbs = bigintToLimbs3(base);
|
|
490
|
+
const resultLimbs = moduleExpLimbs(baseLimbs, exp);
|
|
491
|
+
return limbsToBigint3(resultLimbs);
|
|
492
|
+
}, "curve25519ModuloPow");
|
|
493
|
+
var cachedModuleAddFunction = null;
|
|
494
|
+
var cachedModuleSubFunction = null;
|
|
495
|
+
var cachedModuleMulFunction = null;
|
|
496
|
+
var cachedModuleInvFunction = null;
|
|
497
|
+
var cachedModulePowFunction = null;
|
|
498
|
+
function getCurve25519ModularAddFunction() {
|
|
499
|
+
cachedModuleAddFunction ??= curve25519ModuloAdd;
|
|
500
|
+
return cachedModuleAddFunction;
|
|
501
|
+
}
|
|
502
|
+
__name(getCurve25519ModularAddFunction, "getCurve25519ModularAddFunction");
|
|
503
|
+
function getCurve25519ModularSubFunction() {
|
|
504
|
+
cachedModuleSubFunction ??= curve25519ModuloSub;
|
|
505
|
+
return cachedModuleSubFunction;
|
|
506
|
+
}
|
|
507
|
+
__name(getCurve25519ModularSubFunction, "getCurve25519ModularSubFunction");
|
|
508
|
+
function getCurve25519ModularMulFunction() {
|
|
509
|
+
cachedModuleMulFunction ??= curve25519ModuloMul;
|
|
510
|
+
return cachedModuleMulFunction;
|
|
511
|
+
}
|
|
512
|
+
__name(getCurve25519ModularMulFunction, "getCurve25519ModularMulFunction");
|
|
513
|
+
function getCurve25519ModularInvFunction() {
|
|
514
|
+
cachedModuleInvFunction ??= curve25519ModuloInv;
|
|
515
|
+
return cachedModuleInvFunction;
|
|
516
|
+
}
|
|
517
|
+
__name(getCurve25519ModularInvFunction, "getCurve25519ModularInvFunction");
|
|
518
|
+
function getCurve25519ModularPowFunction() {
|
|
519
|
+
cachedModulePowFunction ??= curve25519ModuloPow;
|
|
520
|
+
return cachedModulePowFunction;
|
|
521
|
+
}
|
|
522
|
+
__name(getCurve25519ModularPowFunction, "getCurve25519ModularPowFunction");
|
|
523
|
+
var R_MOD_P_CURVE25519 = 38n;
|
|
524
|
+
function reduce256Curve25519(value) {
|
|
525
|
+
const [l0, l1, l2, l3] = bigintToLimbs3(value);
|
|
526
|
+
const [p0, p1, p2, p3] = P_LIMBS3;
|
|
527
|
+
const sub0 = l0 - p0;
|
|
528
|
+
const d0 = sub0 & MASK643;
|
|
529
|
+
const borrow0 = -(sub0 >> N643) & 1n;
|
|
530
|
+
const sub1 = l1 - p1 - borrow0;
|
|
531
|
+
const d1 = sub1 & MASK643;
|
|
532
|
+
const borrow1 = -(sub1 >> N643) & 1n;
|
|
533
|
+
const sub2 = l2 - p2 - borrow1;
|
|
534
|
+
const d2 = sub2 & MASK643;
|
|
535
|
+
const borrow2 = -(sub2 >> N643) & 1n;
|
|
536
|
+
const sub3 = l3 - p3 - borrow2;
|
|
537
|
+
const d3 = sub3 & MASK643;
|
|
538
|
+
const borrow3 = -(sub3 >> N643) & 1n;
|
|
539
|
+
const useOriginal = borrow3;
|
|
540
|
+
return limbsToBigint3([
|
|
541
|
+
ctSelect3(useOriginal, l0, d0),
|
|
542
|
+
ctSelect3(useOriginal, l1, d1),
|
|
543
|
+
ctSelect3(useOriginal, l2, d2),
|
|
544
|
+
ctSelect3(useOriginal, l3, d3)
|
|
545
|
+
]);
|
|
546
|
+
}
|
|
547
|
+
__name(reduce256Curve25519, "reduce256Curve25519");
|
|
548
|
+
function bytesToBigintBECurve25519(bytes, offset) {
|
|
549
|
+
const slice = bytes.slice(offset, offset + U256_BYTE_LENGTH);
|
|
550
|
+
const u256BeBytes = createU256BeBytes(slice);
|
|
551
|
+
return decodeU256BeBytesToU256(u256BeBytes);
|
|
552
|
+
}
|
|
553
|
+
__name(bytesToBigintBECurve25519, "bytesToBigintBECurve25519");
|
|
554
|
+
function getCurve25519FieldElementSampler(deps) {
|
|
555
|
+
const { modAdd: moduleAdd = curve25519ModuloAdd, modMul: moduleMul = curve25519ModuloMul } = deps ?? {};
|
|
556
|
+
return (input) => {
|
|
557
|
+
const high = bytesToBigintBECurve25519(input, 0);
|
|
558
|
+
const low = bytesToBigintBECurve25519(input, 32);
|
|
559
|
+
const lowReduced = reduce256Curve25519(low);
|
|
560
|
+
const highReduced = reduce256Curve25519(high);
|
|
561
|
+
const highTimesR = moduleMul(highReduced, R_MOD_P_CURVE25519);
|
|
562
|
+
const result = moduleAdd(highTimesR, lowReduced);
|
|
563
|
+
return result;
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
__name(getCurve25519FieldElementSampler, "getCurve25519FieldElementSampler");
|
|
567
|
+
var curve25519FieldElementSampler = getCurve25519FieldElementSampler();
|
|
568
|
+
|
|
569
|
+
export { BN254_FIELD_PRIME, CURVE25519_FIELD_PRIME, assertBn254FieldElement, bn254FieldElementSampler, computeBn254LimbwiseSumInverse, curve25519FieldElementSampler, curve25519ModuloAdd, curve25519ModuloInv, curve25519ModuloMul, curve25519ModuloPow, curve25519ModuloSub, getBn254FieldElementSampler, getBn254ModularAdder, getBn254ModularInverter, getBn254ModularMultiplier, getBn254ModularNegator, getBn254ModularSubtractor, getCurve25519FieldElementSampler, getCurve25519ModularAddFunction, getCurve25519ModularInvFunction, getCurve25519ModularMulFunction, getCurve25519ModularPowFunction, getCurve25519ModularSubFunction };
|
|
570
|
+
//# sourceMappingURL=chunk-WN75ORDT.js.map
|
|
571
|
+
//# sourceMappingURL=chunk-WN75ORDT.js.map
|