@hinkal/common 0.2.33 → 0.2.34
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/constants/bridging.constants.cjs +1 -1
- package/constants/bridging.constants.d.ts +1 -1
- package/constants/bridging.constants.mjs +6 -5
- package/constants/chains.constants.cjs +1 -1
- package/constants/chains.constants.d.ts +11 -1
- package/constants/chains.constants.mjs +86 -18
- package/constants/protocol.constants.cjs +1 -1
- package/constants/protocol.constants.d.ts +1 -0
- package/constants/protocol.constants.mjs +2 -2
- package/constants/token-data/ERC20Registry.cjs +1 -1
- package/constants/token-data/ERC20Registry.mjs +49 -14
- package/constants/token-data/avalancheRegistry.json.cjs +1 -0
- package/constants/token-data/avalancheRegistry.json.mjs +44 -0
- package/constants/token-data/bnbMainnetRegistry.json.cjs +1 -0
- package/constants/token-data/bnbMainnetRegistry.json.mjs +44 -0
- package/constants/token-data/cronosRegistry.json.cjs +1 -0
- package/constants/token-data/cronosRegistry.json.mjs +44 -0
- package/constants/token-data/hyperEvmRegistry.json.cjs +1 -0
- package/constants/token-data/hyperEvmRegistry.json.mjs +36 -0
- package/constants/token-data/index.cjs +1 -1
- package/constants/token-data/index.d.ts +57 -1
- package/constants/token-data/index.mjs +9 -2
- package/constants/token-data/inkRegistry.json.cjs +1 -0
- package/constants/token-data/inkRegistry.json.mjs +28 -0
- package/constants/token-data/monadRegistry.json.cjs +1 -0
- package/constants/token-data/monadRegistry.json.mjs +36 -0
- package/constants/token-data/plasmaRegistry.json.cjs +1 -0
- package/constants/token-data/plasmaRegistry.json.mjs +28 -0
- package/constants/tokens.constants.cjs +1 -1
- package/constants/tokens.constants.mjs +8 -1
- package/data-structures/Hinkal/Hinkal.cjs +1 -1
- package/data-structures/Hinkal/Hinkal.d.ts +1 -1
- package/data-structures/Hinkal/Hinkal.mjs +1 -1
- package/data-structures/Hinkal/IHinkal.d.ts +1 -1
- package/data-structures/Hinkal/handleAutoDepositBack.cjs +1 -1
- package/data-structures/Hinkal/handleAutoDepositBack.mjs +15 -15
- package/data-structures/Hinkal/hinkalClaimUtxo.cjs +1 -1
- package/data-structures/Hinkal/hinkalClaimUtxo.mjs +33 -35
- package/data-structures/Hinkal/hinkalDepositAndBridge.cjs +1 -1
- package/data-structures/Hinkal/hinkalDepositAndBridge.mjs +43 -49
- package/data-structures/Hinkal/hinkalDepositAndWithdraw.cjs +1 -1
- package/data-structures/Hinkal/hinkalDepositAndWithdraw.mjs +38 -40
- package/data-structures/Hinkal/hinkalPrivateWallet.cjs +1 -1
- package/data-structures/Hinkal/hinkalPrivateWallet.mjs +21 -26
- package/data-structures/Hinkal/hinkalSolanaClaimUtxo.cjs +1 -1
- package/data-structures/Hinkal/hinkalSolanaClaimUtxo.mjs +62 -64
- package/data-structures/Hinkal/hinkalSolanaDepositAndWithdraw.cjs +1 -1
- package/data-structures/Hinkal/hinkalSolanaDepositAndWithdraw.mjs +49 -50
- package/data-structures/Hinkal/hinkalSolanaProxySend.cjs +1 -1
- package/data-structures/Hinkal/hinkalSolanaProxySend.mjs +7 -7
- package/data-structures/Hinkal/hinkalSolanaProxyShield.cjs +1 -1
- package/data-structures/Hinkal/hinkalSolanaProxyShield.mjs +9 -9
- package/data-structures/Hinkal/hinkalSolanaProxySwap.cjs +1 -1
- package/data-structures/Hinkal/hinkalSolanaProxySwap.mjs +8 -8
- package/data-structures/Hinkal/hinkalSolanaSwap.cjs +1 -1
- package/data-structures/Hinkal/hinkalSolanaSwap.mjs +50 -51
- package/data-structures/Hinkal/hinkalSolanaTransfer.cjs +1 -1
- package/data-structures/Hinkal/hinkalSolanaTransfer.mjs +45 -46
- package/data-structures/Hinkal/hinkalSolanaWithdraw.cjs +1 -1
- package/data-structures/Hinkal/hinkalSolanaWithdraw.mjs +38 -39
- package/data-structures/Hinkal/hinkalSwap.cjs +1 -1
- package/data-structures/Hinkal/hinkalSwap.mjs +18 -19
- package/data-structures/Hinkal/hinkalTransfer.cjs +1 -1
- package/data-structures/Hinkal/hinkalTransfer.mjs +21 -22
- package/data-structures/Hinkal/hinkalWithdraw.cjs +1 -1
- package/data-structures/Hinkal/hinkalWithdraw.mjs +24 -25
- package/data-structures/Hinkal/hinkalWithdrawStuckUtxos.cjs +1 -1
- package/data-structures/Hinkal/hinkalWithdrawStuckUtxos.mjs +39 -41
- package/error-handling/error-codes.constants.cjs +1 -1
- package/error-handling/error-codes.constants.d.ts +2 -0
- package/error-handling/error-codes.constants.mjs +2 -0
- package/error-handling/get-error.message.cjs +1 -1
- package/error-handling/get-error.message.mjs +2 -1
- package/functions/index.cjs +1 -1
- package/functions/index.mjs +7 -6
- package/functions/pre-transaction/buildCommitmentValidationData.cjs +1 -1
- package/functions/pre-transaction/buildCommitmentValidationData.d.ts +12 -2
- package/functions/pre-transaction/buildCommitmentValidationData.mjs +43 -36
- package/functions/pre-transaction/sendV0Transaction.cjs +1 -1
- package/functions/pre-transaction/sendV0Transaction.d.ts +2 -2
- package/functions/pre-transaction/sendV0Transaction.mjs +63 -58
- package/functions/snarkjs/constructGeneralZkProof.cjs +1 -1
- package/functions/snarkjs/constructGeneralZkProof.d.ts +1 -0
- package/functions/snarkjs/constructGeneralZkProof.mjs +6 -5
- package/functions/snarkjs/constructSolanaZkProof.cjs +1 -1
- package/functions/snarkjs/constructSolanaZkProof.d.ts +1 -0
- package/functions/snarkjs/constructSolanaZkProof.mjs +35 -34
- package/functions/snarkjs/generateMainAndCommitmentZkProof.cjs +1 -0
- package/functions/snarkjs/generateMainAndCommitmentZkProof.d.ts +11 -0
- package/functions/snarkjs/generateMainAndCommitmentZkProof.mjs +16 -0
- package/functions/snarkjs/generateZkProof.cjs +1 -1
- package/functions/snarkjs/generateZkProof.d.ts +3 -3
- package/functions/snarkjs/generateZkProof.mjs +5 -9
- package/functions/snarkjs/generateZkProofEnclave.cjs +1 -1
- package/functions/snarkjs/generateZkProofEnclave.d.ts +2 -2
- package/functions/snarkjs/generateZkProofEnclave.mjs +8 -8
- package/functions/snarkjs/generateZkProofSelf.cjs +1 -1
- package/functions/snarkjs/generateZkProofSelf.mjs +5 -5
- package/functions/snarkjs/index.cjs +1 -1
- package/functions/snarkjs/index.d.ts +1 -0
- package/functions/snarkjs/index.mjs +1 -0
- package/functions/snarkjs/verifyCommitmentValidationData.cjs +1 -1
- package/functions/snarkjs/verifyCommitmentValidationData.mjs +5 -5
- package/functions/utils/customEnclaveFunctionsRegister.d.ts +3 -3
- package/functions/utils/index.cjs +1 -1
- package/functions/utils/index.mjs +5 -5
- package/functions/web3/oneInchAPI.cjs +1 -1
- package/functions/web3/oneInchAPI.mjs +1 -1
- package/index.cjs +1 -1
- package/index.mjs +316 -315
- package/package.json +1 -1
- package/webworker/{logError-fCJ4HXQz.js → logError-DZiJbbaT.js} +1 -1
- package/webworker/package.json +1 -1
- package/webworker/snarkjsWorker/snarkjsWorkerLauncher.ts?worker&url.cjs +1 -1
- package/webworker/snarkjsWorker/snarkjsWorkerLauncher.ts?worker&url.mjs +1 -1
- package/webworker/snarkjsWorkerNode.cjs +1 -1
- package/webworker/utxoWorker/utxoWorkerLauncher.ts?worker&url.cjs +1 -1
- package/webworker/utxoWorker/utxoWorkerLauncher.ts?worker&url.mjs +1 -1
- package/webworker/utxoWorkerNode.cjs +1 -1
- package/webworker/viteWorkerURL.constant.cjs +3 -3
- package/webworker/viteWorkerURL.constant.mjs +3 -3
- package/webworker/{workerProxy-BNBqYien.js → workerProxy-DQJE57Ye.js} +1 -1
- package/webworker/zkProofWorker/zkProofWorkerLauncher.ts?worker&url.cjs +1 -1
- package/webworker/zkProofWorker/zkProofWorkerLauncher.ts?worker&url.mjs +1 -1
- package/webworker/zkProofWorkerNode.cjs +1 -1
|
@@ -1,36 +1,40 @@
|
|
|
1
1
|
import { safeJsonStringify as e } from "../utils/serialize.utils.mjs";
|
|
2
|
-
import { COMPUTE_UNIT_PADDING_PERCENTAGE as t, MAX_COMPUTE_UNIT_LIMIT as n,
|
|
3
|
-
import { AccountActions as
|
|
4
|
-
import { SolanaPriorityFeeMode as
|
|
5
|
-
import { getSolanaPriorityFee as
|
|
6
|
-
import { pollForValue as
|
|
7
|
-
import { shouldRetryForSolanaError as
|
|
8
|
-
import { ComputeBudgetProgram as
|
|
9
|
-
import { ASSOCIATED_TOKEN_PROGRAM_ID as
|
|
2
|
+
import { COMPUTE_UNIT_PADDING_PERCENTAGE as t, MAX_COMPUTE_UNIT_LIMIT as n, MAX_SOLANA_HEAP_FRAME_BYTES as r, MIN_COMPUTE_UNIT_LIMIT as i } from "../../constants/protocol.constants.mjs";
|
|
3
|
+
import { AccountActions as a } from "../../data-structures/AccountActions/AccountActions.mjs";
|
|
4
|
+
import { SolanaPriorityFeeMode as o } from "../../types/fee.types.mjs";
|
|
5
|
+
import { getSolanaPriorityFee as s } from "../web3/getSolanaPriorityFee.mjs";
|
|
6
|
+
import { pollForValue as c } from "../utils/process.utils.mjs";
|
|
7
|
+
import { shouldRetryForSolanaError as l } from "../../error-handling/retrySolanaError.mjs";
|
|
8
|
+
import { ComputeBudgetProgram as u, PublicKey as d, TransactionMessage as f, VersionedTransaction as p } from "@solana/web3.js";
|
|
9
|
+
import { ASSOCIATED_TOKEN_PROGRAM_ID as m, TOKEN_PROGRAM_ID as h, createAssociatedTokenAccountInstruction as g, getAssociatedTokenAddress as _ } from "@solana/spl-token";
|
|
10
10
|
//#region libs/shared/common/src/functions/pre-transaction/sendV0Transaction.ts
|
|
11
|
-
var
|
|
11
|
+
var v = 5e3, y = 6e4, b = 7, x = async (e, t, n = "confirmed") => await c(() => e.getTransaction(t, {
|
|
12
12
|
commitment: n,
|
|
13
13
|
maxSupportedTransactionVersion: 0
|
|
14
14
|
}), {
|
|
15
|
-
timeoutMs:
|
|
16
|
-
intervalMs:
|
|
17
|
-
}) ?? null,
|
|
15
|
+
timeoutMs: y,
|
|
16
|
+
intervalMs: v
|
|
17
|
+
}) ?? null, S = async (e, a, o, s, c = !1) => {
|
|
18
18
|
try {
|
|
19
|
-
let { blockhash:
|
|
20
|
-
payerKey:
|
|
21
|
-
recentBlockhash:
|
|
22
|
-
instructions: [
|
|
23
|
-
|
|
19
|
+
let { blockhash: l } = await e.getLatestBlockhash(), d = new p(new f({
|
|
20
|
+
payerKey: a,
|
|
21
|
+
recentBlockhash: l,
|
|
22
|
+
instructions: [
|
|
23
|
+
u.setComputeUnitLimit({ units: n }),
|
|
24
|
+
...c ? [u.requestHeapFrame({ bytes: r })] : [],
|
|
25
|
+
...o
|
|
26
|
+
]
|
|
27
|
+
}).compileToV0Message(s)), { unitsConsumed: m } = (await e.simulateTransaction(d, {
|
|
24
28
|
sigVerify: !1,
|
|
25
29
|
replaceRecentBlockhash: !0
|
|
26
30
|
})).value;
|
|
27
|
-
if (!
|
|
28
|
-
let
|
|
29
|
-
return Math.max(
|
|
31
|
+
if (!m) return n;
|
|
32
|
+
let h = Math.ceil(m * (1 + t));
|
|
33
|
+
return Math.max(i, Math.min(h, n));
|
|
30
34
|
} catch {
|
|
31
35
|
return n;
|
|
32
36
|
}
|
|
33
|
-
},
|
|
37
|
+
}, C = (e, t, n, r) => {
|
|
34
38
|
let i = /* @__PURE__ */ new Set();
|
|
35
39
|
return t && i.add(t.toBase58()), n?.forEach((e) => i.add(e.toBase58())), e.forEach((e) => {
|
|
36
40
|
i.add(e.programId.toBase58()), e.keys.forEach((e) => {
|
|
@@ -40,77 +44,78 @@ var _ = 5e3, v = 6e4, y = 7, b = async (e, t, n = "confirmed") => await s(() =>
|
|
|
40
44
|
i.add(e.key.toBase58()), e.state.addresses.forEach((e) => {
|
|
41
45
|
i.add(e.toBase58());
|
|
42
46
|
});
|
|
43
|
-
}), [...i].map((e) => new
|
|
44
|
-
},
|
|
47
|
+
}), [...i].map((e) => new d(e));
|
|
48
|
+
}, w = (t) => {
|
|
45
49
|
if (!t) throw Error("Failed to fetch Solana transaction details for signature");
|
|
46
50
|
if (t.meta?.err) {
|
|
47
51
|
let n = e(t.meta.err);
|
|
48
52
|
throw Error(`Solana transaction failed on-chain: ${n}`);
|
|
49
53
|
}
|
|
50
|
-
},
|
|
51
|
-
if (
|
|
52
|
-
let
|
|
54
|
+
}, T = async (e, t, i, a, o, c = !1) => {
|
|
55
|
+
if (i.some((e) => e.programId.equals(u.programId))) return i.map((e) => e.programId.equals(u.programId) && e.data[0] === 2 ? u.setComputeUnitLimit({ units: n }) : e);
|
|
56
|
+
let l = i.filter((e) => !e.programId.equals(u.programId)), d = await S(e, t, l, a, c), f = u.setComputeUnitLimit({ units: d }), p = e.rpcEndpoint.includes("helius") ? await s(C(l, t, [u.programId], a), o) : 0;
|
|
53
57
|
return [
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
...
|
|
58
|
+
f,
|
|
59
|
+
u.setComputeUnitPrice({ microLamports: p }),
|
|
60
|
+
...c ? [u.requestHeapFrame({ bytes: r })] : [],
|
|
61
|
+
...l
|
|
57
62
|
];
|
|
58
|
-
},
|
|
63
|
+
}, E = async (e, t, n, r, i, a = !1) => {
|
|
59
64
|
if (t.length === 0) return "";
|
|
60
|
-
for (let
|
|
61
|
-
let
|
|
65
|
+
for (let s = 0; s < 10; s += 1) {
|
|
66
|
+
let c = s === 9;
|
|
62
67
|
try {
|
|
63
|
-
let
|
|
68
|
+
let c = await T(e, n.publicKey, t, i, s >= b ? o.HIGH : o.RECOMMENDED, a), { blockhash: l, lastValidBlockHeight: u } = await e.getLatestBlockhash(), d = new p(new f({
|
|
64
69
|
payerKey: n.publicKey,
|
|
65
|
-
instructions:
|
|
66
|
-
recentBlockhash:
|
|
70
|
+
instructions: c,
|
|
71
|
+
recentBlockhash: l
|
|
67
72
|
}).compileToV0Message(i));
|
|
68
|
-
|
|
69
|
-
let
|
|
73
|
+
d.sign(r);
|
|
74
|
+
let m = await e.sendTransaction(d);
|
|
70
75
|
return await e.confirmTransaction({
|
|
71
|
-
signature:
|
|
72
|
-
blockhash:
|
|
73
|
-
lastValidBlockHeight:
|
|
74
|
-
}, "confirmed"),
|
|
76
|
+
signature: m,
|
|
77
|
+
blockhash: l,
|
|
78
|
+
lastValidBlockHeight: u
|
|
79
|
+
}, "confirmed"), w(await x(e, m)), m;
|
|
75
80
|
} catch (e) {
|
|
76
|
-
if (
|
|
81
|
+
if (l(e) && !c) continue;
|
|
77
82
|
throw e;
|
|
78
83
|
}
|
|
79
84
|
}
|
|
80
85
|
return "";
|
|
81
|
-
},
|
|
86
|
+
}, D = async (e, t, n, r) => {
|
|
82
87
|
if (!n) return null;
|
|
83
|
-
let i = await
|
|
84
|
-
return await e.getAccountInfo(i) || await
|
|
85
|
-
},
|
|
86
|
-
let
|
|
87
|
-
if (!
|
|
88
|
+
let i = await _(n, r, !0, h, m);
|
|
89
|
+
return await e.getAccountInfo(i) || await E(e, [g(t.publicKey, i, r, n, h, m)], t, [t]), i;
|
|
90
|
+
}, O = async ({ connection: e, chainId: t, subAccount: n, payerPublicKey: r, instructions: i, lookupTableAccounts: s }) => {
|
|
91
|
+
let c = a.getPrivateKeyFromSubAccount(t, n);
|
|
92
|
+
if (!c) throw Error("Private key is not available");
|
|
88
93
|
for (let t = 0; t < 10; t += 1) {
|
|
89
94
|
let n = t === 9;
|
|
90
95
|
try {
|
|
91
|
-
let t = await
|
|
96
|
+
let t = await T(e, r, i, s, n ? o.HIGH : o.RECOMMENDED), { blockhash: l, lastValidBlockHeight: u } = await e.getLatestBlockhash(), d = new p(new f({
|
|
92
97
|
payerKey: r,
|
|
93
|
-
recentBlockhash:
|
|
98
|
+
recentBlockhash: l,
|
|
94
99
|
instructions: t
|
|
95
|
-
}).compileToV0Message(s)), m = await
|
|
100
|
+
}).compileToV0Message(s)), m = await a.sendAndSignSolanaTransactionFromPrivateKey(e, c, d, !0);
|
|
96
101
|
return await e.confirmTransaction({
|
|
97
102
|
signature: m,
|
|
98
|
-
blockhash:
|
|
103
|
+
blockhash: l,
|
|
99
104
|
lastValidBlockHeight: u
|
|
100
|
-
}, "confirmed"),
|
|
105
|
+
}, "confirmed"), w(await x(e, m)), m;
|
|
101
106
|
} catch (e) {
|
|
102
|
-
if (
|
|
107
|
+
if (l(e) && !n) continue;
|
|
103
108
|
throw e;
|
|
104
109
|
}
|
|
105
110
|
}
|
|
106
111
|
throw Error("Failed to send proxy v0 transaction due to expired blockheight after all retries");
|
|
107
|
-
},
|
|
108
|
-
let { blockhash: i } = await e.getLatestBlockhash(), a = new
|
|
112
|
+
}, k = async (e, t, n, r) => {
|
|
113
|
+
let { blockhash: i } = await e.getLatestBlockhash(), a = new p(new f({
|
|
109
114
|
payerKey: t,
|
|
110
115
|
recentBlockhash: i,
|
|
111
|
-
instructions: await
|
|
116
|
+
instructions: await T(e, t, n, r)
|
|
112
117
|
}).compileToV0Message(r));
|
|
113
118
|
return Buffer.from(a.serialize()).toString("base64");
|
|
114
119
|
};
|
|
115
120
|
//#endregion
|
|
116
|
-
export {
|
|
121
|
+
export { D as ensureAtaExists, S as estimateComputeUnitLimit, x as fetchSolanaTransaction, C as getAccountsFromInstructions, O as sendProxyV0Transaction, E as sendV0Transaction, k as serializeProxyV0Transaction };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../../types/external-action.types.cjs`),t=require(`../../constants/chains.constants.cjs`),n=require(`../../constants/protocol.constants.cjs`),r=require(`../web3/etherFunctions.cjs`),ee=require(`../../crypto/poseidon.cjs`),te=require(`../../data-structures/crypto-keys/keys.cjs`),ne=require(`../utils/time.utils.cjs`),i=require(`../utils/bit.operations.cjs`),a=require(`../../error-handling/logger.cjs`),o=require(`./common.snarkjs.cjs`),s=require(`./signedMessageHash.cjs`),c=require(`./generateCircomData.cjs`),l=require(
|
|
1
|
+
const e=require(`../../types/external-action.types.cjs`),t=require(`../../constants/chains.constants.cjs`),n=require(`../../constants/protocol.constants.cjs`),r=require(`../web3/etherFunctions.cjs`),ee=require(`../../crypto/poseidon.cjs`),te=require(`../../data-structures/crypto-keys/keys.cjs`),ne=require(`../utils/time.utils.cjs`),i=require(`../utils/bit.operations.cjs`),a=require(`../../error-handling/logger.cjs`),o=require(`./common.snarkjs.cjs`),s=require(`./signedMessageHash.cjs`),c=require(`./generateCircomData.cjs`),l=require(`../../data-structures/AccountActions/AccountActions.cjs`),u=require(`./generateMainAndCommitmentZkProof.cjs`),d=require(`./getMerkleTreeSiblingsAndRootHashes.cjs`),f=require(`../private-wallet/emporium.helpers.cjs`);var p=async(p,m,h,g,_,v,y,b,x,S=n.zeroAddress,C=t.chainIds.localhost,w=m.map(()=>!1),T=void 0,E,D)=>{let O=o.getZkProofVerifierName(m,h),k=o.calcAmountChanges(m,h),A=m.map(e=>e[0].erc20TokenAddress),j=o.calcEncryptedOutputs(h),M=n.defaultSignatureData,N=g.getShieldedPrivateKey(),{pubSpendingBJJPoint:P}=g.getSpendingKeyPair(),F=o.calcStealthAddressStructure(te.UserKeys.findCorrectRandomization(r.randomBigInt(31),N),N,g.getSpendingKeyPair().pubSpendingBJJPoint),{inCommitmentSiblings:I,inCommitmentSiblingSides:re,rootHashHinkal:L,inNullifiers:R}=await d.getDataFromWorkers(C,p,m.map(e=>e.map(e=>e.getConstructableParams()))),z=o.buildOutCommitments(h),B=r.randomBigInt(31),V=ee.poseidonFunction(B),H=BigInt(h.length>0?h[0][0].timeStamp:ne.getCurrentTimeInSeconds()),U={rootHashHinkal:L,spendingPublicKey:P,nullifyingPrivateKey:N,erc20TokenAddresses:A,amountChanges:k,inAmounts:m.map(e=>e.map(e=>e.amount.toString())),inRandomizations:m.map(e=>e.map(e=>o.getUtxoCircuitInRandomization(e))),inH0Ax:m.map(e=>e.map(e=>o.getUtxoCircuitH0Coords(e)[0].toString())),inH0Ay:m.map(e=>e.map(e=>o.getUtxoCircuitH0Coords(e)[1].toString())),isNewStyle:m.map(e=>e.map(e=>!!e.isNewStyle)),inTimeStamps:m.map(e=>e.map(e=>e.timeStamp)),inNullifiers:R,inCommitmentSiblings:I,inCommitmentSiblingSides:re,outAmounts:h.map(e=>e.map(e=>e.amount.toString())),outTimeStamp:H,outPublicKeys:h.map(e=>e.map(e=>e.getStealthAddress())),outCommitments:z,calldataHash:0n,messageSeed:B,H0Ax:i.takeOffHighestBit(F.extraRandomization),H0Ay:F.H0},W=o.calcPublicSignalCount(O,U.erc20TokenAddresses,U.amountChanges,U.inNullifiers,U.outCommitments),G=o.calcAmountChanges(m,h,!0),K=o.getSlippageValues(G);a.Logger.log({publicSignalCount:W});let q=Array.isArray(y)?y:[y],J=t.getOnchainChainId(C),Y=D?l.AccountActions.getSignerAddressFromPrivateKey(J,D):void 0,X=_===e.ExternalActionId.Emporium?await f.encodeEmporiumMetadata(C,v??n.zeroAddress,D,q,V,Y):await f.encodeEmporiumMetadata(C,n.zeroAddress,void 0,_===0n?[]:q,V,n.zeroAddress);U.calldataHash=o.createCallDataHash(W,S,v,_,X,j,T,K,w,x,M,E);let Z=s.computeSignedMessageHashEvm({rootHashHinkal:L,erc20TokenAddresses:A,amountChanges:k,outTimeStamp:H,inNullifiers:R,outCommitments:z,calldataHash:U.calldataHash,message:V,outH1Ay:F.H1,H0Ax:U.H0Ax,H0Ay:F.H0}),{R8:Q,S:ie}=g.signEddsa(Z);U.eddsaSignature=[Q[0],Q[1],ie],U.signedMessageHash=Z;let $=O.startsWith(`mainEVMCircuitMin0`),ae={outTimeStamp:H,calldataHash:U.calldataHash,messageSeed:B},{zkCallData:oe,commitmentValidationData:se}=await u.generateMainAndCommitmentZkProof(C,g,A,m,O,$?ae:U,b);return{zkCallData:oe,circomData:c.generateCircomData(z,R,L,G,A,h,j,W,_,v,X,S,U.calldataHash,F,w,T,$?Number(H):void 0,K,x,M,E),dimData:{tokenNumber:m.length,nullifierAmount:m.length>0?m[0].length:0,outputAmount:h.length>0?h[0].length:0},encryptedOutputs:j,commitmentValidationData:se}};exports.constructZkProof=p;
|
|
@@ -10,8 +10,8 @@ import { Logger as ie } from "../../error-handling/logger.mjs";
|
|
|
10
10
|
import { buildOutCommitments as ae, calcAmountChanges as o, calcEncryptedOutputs as s, calcPublicSignalCount as c, calcStealthAddressStructure as l, createCallDataHash as u, getSlippageValues as d, getUtxoCircuitH0Coords as f, getUtxoCircuitInRandomization as oe, getZkProofVerifierName as se } from "./common.snarkjs.mjs";
|
|
11
11
|
import { computeSignedMessageHashEvm as ce } from "./signedMessageHash.mjs";
|
|
12
12
|
import { generateCircomData as le } from "./generateCircomData.mjs";
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
13
|
+
import { AccountActions as ue } from "../../data-structures/AccountActions/AccountActions.mjs";
|
|
14
|
+
import { generateMainAndCommitmentZkProof as de } from "./generateMainAndCommitmentZkProof.mjs";
|
|
15
15
|
import { getDataFromWorkers as p } from "./getMerkleTreeSiblingsAndRootHashes.mjs";
|
|
16
16
|
import { encodeEmporiumMetadata as m } from "../private-wallet/emporium.helpers.mjs";
|
|
17
17
|
//#region libs/shared/common/src/functions/snarkjs/constructGeneralZkProof.ts
|
|
@@ -41,7 +41,7 @@ var h = async (h, g, _, v, y, b, x, fe, S, C = i, w = t.localhost, T = g.map(()
|
|
|
41
41
|
H0Ay: I.H0
|
|
42
42
|
}, K = c(k, G.erc20TokenAddresses, G.amountChanges, G.inNullifiers, G.outCommitments), q = o(g, _, !0), J = d(q);
|
|
43
43
|
ie.log({ publicSignalCount: K });
|
|
44
|
-
let Y = Array.isArray(x) ? x : [x], pe = n(w), me = O ?
|
|
44
|
+
let Y = Array.isArray(x) ? x : [x], pe = n(w), me = O ? ue.getSignerAddressFromPrivateKey(pe, O) : void 0, X = y === e.Emporium ? await m(w, b ?? i, O, Y, U, me) : await m(w, i, void 0, y === 0n ? [] : Y, U, i);
|
|
45
45
|
G.calldataHash = u(K, C, b, y, X, M, E, J, T, S, N, D);
|
|
46
46
|
let Z = ce({
|
|
47
47
|
rootHashHinkal: z,
|
|
@@ -65,7 +65,7 @@ var h = async (h, g, _, v, y, b, x, fe, S, C = i, w = t.localhost, T = g.map(()
|
|
|
65
65
|
outTimeStamp: W,
|
|
66
66
|
calldataHash: G.calldataHash,
|
|
67
67
|
messageSeed: H
|
|
68
|
-
}, { zkCallData: _e } = await
|
|
68
|
+
}, { zkCallData: _e, commitmentValidationData: ve } = await de(w, v, j, g, k, $ ? ge : G, fe);
|
|
69
69
|
return {
|
|
70
70
|
zkCallData: _e,
|
|
71
71
|
circomData: le(V, B, z, q, j, _, M, K, y, b, X, C, G.calldataHash, I, T, E, $ ? Number(W) : void 0, J, S, N, D),
|
|
@@ -74,7 +74,8 @@ var h = async (h, g, _, v, y, b, x, fe, S, C = i, w = t.localhost, T = g.map(()
|
|
|
74
74
|
nullifierAmount: g.length > 0 ? g[0].length : 0,
|
|
75
75
|
outputAmount: _.length > 0 ? _[0].length : 0
|
|
76
76
|
},
|
|
77
|
-
encryptedOutputs: M
|
|
77
|
+
encryptedOutputs: M,
|
|
78
|
+
commitmentValidationData: ve
|
|
78
79
|
};
|
|
79
80
|
};
|
|
80
81
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
require(`../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../constants/chains.constants.cjs`),t=require(`../web3/etherFunctions.cjs`),n=require(`../../crypto/poseidon.cjs`),r=require(`../utils/bit.operations.cjs`),i=require(`../utils/solanaMint.utils.cjs`),a=require(`./common.snarkjs.cjs`),o=require(`../pre-transaction/solana.cjs`),s=require(`./signedMessageHash.cjs`)
|
|
1
|
+
require(`../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../constants/chains.constants.cjs`),t=require(`../web3/etherFunctions.cjs`),n=require(`../../crypto/poseidon.cjs`),r=require(`../utils/bit.operations.cjs`),i=require(`../utils/solanaMint.utils.cjs`),a=require(`./common.snarkjs.cjs`),o=require(`../pre-transaction/solana.cjs`),s=require(`./signedMessageHash.cjs`);require(`../pre-transaction/index.cjs`);const c=require(`./generateMainAndCommitmentZkProof.cjs`);require(`../utils/index.cjs`);const l=require(`./getMerkleTreeSiblingsAndRootHashes.cjs`),u=require(`../pre-transaction/getSolanaCalldataHash.cjs`);require(`../web3/index.cjs`);let d=require(`@solana/web3.js`);var f=async(f,p,m,h,g,_,v,y,b,x,S,C,w,T=e.chainIds.solanaLocalnet,E=[],D=[],O=0n)=>{let k=new d.PublicKey(x),A=new d.PublicKey(S),j=m.getShieldedPrivateKey(),{pubSpendingBJJPoint:M}=m.getSpendingKeyPair(),N=a.calcStealthAddressStructure(v,j,m.getSpendingKeyPair().pubSpendingBJJPoint),P=t.randomBigInt(31),F=n.poseidonFunction(P),I=n.poseidonFunction(O),L=h.map(e=>i.formatMintAddress(e)),R=L.map(e=>e.mintAccountPart1),z=L.map(e=>e.mintAccountPart2),B=u.getSolanaCalldataHash(C,k,A,w,y,b,E,D),V=`${C.tokenNumber}x${C.nullifierAmount}x${C.outputAmount}`,H=a.calcAmountChanges(g,_),{inCommitmentSiblings:U,inCommitmentSiblingSides:W,rootHashHinkal:G,inNullifiers:K}=await l.getDataFromWorkers(T,p,g.map(e=>e.map(e=>e.getConstructableParams()))),q=a.buildOutCommitments(_),J=r.takeOffHighestBit(N.extraRandomization),Y=N.H0,X=s.computeSignedMessageHashSolana({rootHashHinkal:G,mintAccountPart1:R,mintAccountPart2:z,amountChanges:H,outTimeStamp:BigInt(_[0][0].timeStamp),inNullifiers:K,outCommitments:q,calldataHash:B,message:F,swapperAccountAdditionalSeed:I,outH1Ay:N.H1,H0Ax:J,H0Ay:Y}),{R8:Z,S:Q}=m.signEddsa(X),$={rootHashHinkal:G,spendingPublicKey:M,eddsaSignature:[Z[0],Z[1],Q],signedMessageHash:X,nullifyingPrivateKey:j,mintAccountPart1:R,mintAccountPart2:z,amountChanges:H,inAmounts:g.map(e=>e.map(e=>e.amount.toString())),inRandomizations:g.map(e=>e.map(e=>a.getUtxoCircuitInRandomization(e))),inH0Ax:g.map(e=>e.map(e=>a.getUtxoCircuitH0Coords(e)[0].toString())),inH0Ay:g.map(e=>e.map(e=>a.getUtxoCircuitH0Coords(e)[1].toString())),isNewStyle:g.map(e=>e.map(e=>!!e.isNewStyle)),inTimeStamps:g.map(e=>e.map(e=>e.timeStamp)),inNullifiers:K,inCommitmentSiblings:U,inCommitmentSiblingSides:W,outAmounts:_.map(e=>e.map(e=>e.amount.toString())),outTimeStamp:BigInt(_[0][0].timeStamp),outPublicKeys:_.map(e=>e.map(e=>e.getStealthAddress())),outCommitments:q,calldataHash:B,messageSeed:P,swapperAccountSalt:O,H0Ax:J,H0Ay:Y},{zkCallData:ee,publicSignals:te,commitmentValidationData:ne}=await c.generateMainAndCommitmentZkProof(T,m,h,g,`mainSolanaCircuit${V}`,$,f),[re,ie,ae]=ee;return{proofAArr:re.map(BigInt).map(o.encodeToByte32Array).flat(),proofBArr:ie.flat().map(BigInt).map(o.encodeToByte32Array).flat(),proofCArr:ae.map(BigInt).map(o.encodeToByte32Array).flat(),publicInputsArr:te.map(BigInt).map(o.encodeToByte32Array),commitmentValidationData:ne}};exports.constructSolanaZkProof=f;
|
|
@@ -3,69 +3,70 @@ import { randomBigInt as t } from "../web3/etherFunctions.mjs";
|
|
|
3
3
|
import { poseidonFunction as n } from "../../crypto/poseidon.mjs";
|
|
4
4
|
import { takeOffHighestBit as r } from "../utils/bit.operations.mjs";
|
|
5
5
|
import { formatMintAddress as i } from "../utils/solanaMint.utils.mjs";
|
|
6
|
-
import { buildOutCommitments as a, calcAmountChanges as
|
|
7
|
-
import { encodeToByte32Array as
|
|
8
|
-
import { computeSignedMessageHashSolana as
|
|
9
|
-
import { generateZkProof as d } from "./generateZkProof.mjs";
|
|
6
|
+
import { buildOutCommitments as a, calcAmountChanges as o, calcStealthAddressStructure as s, getUtxoCircuitH0Coords as c, getUtxoCircuitInRandomization as l } from "./common.snarkjs.mjs";
|
|
7
|
+
import { encodeToByte32Array as u } from "../pre-transaction/solana.mjs";
|
|
8
|
+
import { computeSignedMessageHashSolana as d } from "./signedMessageHash.mjs";
|
|
10
9
|
import "../pre-transaction/index.mjs";
|
|
10
|
+
import { generateMainAndCommitmentZkProof as ee } from "./generateMainAndCommitmentZkProof.mjs";
|
|
11
11
|
import "../utils/index.mjs";
|
|
12
12
|
import { getDataFromWorkers as f } from "./getMerkleTreeSiblingsAndRootHashes.mjs";
|
|
13
13
|
import { getSolanaCalldataHash as p } from "../pre-transaction/getSolanaCalldataHash.mjs";
|
|
14
14
|
import "../web3/index.mjs";
|
|
15
15
|
import { PublicKey as m } from "@solana/web3.js";
|
|
16
16
|
//#region libs/shared/common/src/functions/snarkjs/constructSolanaZkProof.ts
|
|
17
|
-
var h = async (h, g, _,
|
|
18
|
-
let
|
|
17
|
+
var h = async (h, g, _, v, y, b, x, S, C, w, T, E, D, O = e.solanaLocalnet, k = [], A = [], j = 0n) => {
|
|
18
|
+
let M = new m(w), N = new m(T), P = _.getShieldedPrivateKey(), { pubSpendingBJJPoint: F } = _.getSpendingKeyPair(), I = s(x, P, _.getSpendingKeyPair().pubSpendingBJJPoint), L = t(31), R = n(L), z = n(j), B = v.map((e) => i(e)), V = B.map((e) => e.mintAccountPart1), H = B.map((e) => e.mintAccountPart2), U = p(E, M, N, D, S, C, k, A), te = `${E.tokenNumber}x${E.nullifierAmount}x${E.outputAmount}`, W = o(y, b), { inCommitmentSiblings: G, inCommitmentSiblingSides: K, rootHashHinkal: q, inNullifiers: J } = await f(O, g, y.map((e) => e.map((e) => e.getConstructableParams()))), Y = a(b), X = r(I.extraRandomization), Z = I.H0, Q = d({
|
|
19
19
|
rootHashHinkal: q,
|
|
20
|
-
mintAccountPart1:
|
|
21
|
-
mintAccountPart2:
|
|
20
|
+
mintAccountPart1: V,
|
|
21
|
+
mintAccountPart2: H,
|
|
22
22
|
amountChanges: W,
|
|
23
|
-
outTimeStamp: BigInt(
|
|
23
|
+
outTimeStamp: BigInt(b[0][0].timeStamp),
|
|
24
24
|
inNullifiers: J,
|
|
25
25
|
outCommitments: Y,
|
|
26
|
-
calldataHash:
|
|
27
|
-
message:
|
|
28
|
-
swapperAccountAdditionalSeed:
|
|
29
|
-
outH1Ay:
|
|
26
|
+
calldataHash: U,
|
|
27
|
+
message: R,
|
|
28
|
+
swapperAccountAdditionalSeed: z,
|
|
29
|
+
outH1Ay: I.H1,
|
|
30
30
|
H0Ax: X,
|
|
31
31
|
H0Ay: Z
|
|
32
32
|
}), { R8: $, S: ne } = _.signEddsa(Q), re = {
|
|
33
33
|
rootHashHinkal: q,
|
|
34
|
-
spendingPublicKey:
|
|
34
|
+
spendingPublicKey: F,
|
|
35
35
|
eddsaSignature: [
|
|
36
36
|
$[0],
|
|
37
37
|
$[1],
|
|
38
38
|
ne
|
|
39
39
|
],
|
|
40
40
|
signedMessageHash: Q,
|
|
41
|
-
nullifyingPrivateKey:
|
|
42
|
-
mintAccountPart1:
|
|
43
|
-
mintAccountPart2:
|
|
41
|
+
nullifyingPrivateKey: P,
|
|
42
|
+
mintAccountPart1: V,
|
|
43
|
+
mintAccountPart2: H,
|
|
44
44
|
amountChanges: W,
|
|
45
|
-
inAmounts:
|
|
46
|
-
inRandomizations:
|
|
47
|
-
inH0Ax:
|
|
48
|
-
inH0Ay:
|
|
49
|
-
isNewStyle:
|
|
50
|
-
inTimeStamps:
|
|
45
|
+
inAmounts: y.map((e) => e.map((e) => e.amount.toString())),
|
|
46
|
+
inRandomizations: y.map((e) => e.map((e) => l(e))),
|
|
47
|
+
inH0Ax: y.map((e) => e.map((e) => c(e)[0].toString())),
|
|
48
|
+
inH0Ay: y.map((e) => e.map((e) => c(e)[1].toString())),
|
|
49
|
+
isNewStyle: y.map((e) => e.map((e) => !!e.isNewStyle)),
|
|
50
|
+
inTimeStamps: y.map((e) => e.map((e) => e.timeStamp)),
|
|
51
51
|
inNullifiers: J,
|
|
52
52
|
inCommitmentSiblings: G,
|
|
53
53
|
inCommitmentSiblingSides: K,
|
|
54
|
-
outAmounts:
|
|
55
|
-
outTimeStamp: BigInt(
|
|
56
|
-
outPublicKeys:
|
|
54
|
+
outAmounts: b.map((e) => e.map((e) => e.amount.toString())),
|
|
55
|
+
outTimeStamp: BigInt(b[0][0].timeStamp),
|
|
56
|
+
outPublicKeys: b.map((e) => e.map((e) => e.getStealthAddress())),
|
|
57
57
|
outCommitments: Y,
|
|
58
|
-
calldataHash:
|
|
59
|
-
messageSeed:
|
|
60
|
-
swapperAccountSalt:
|
|
58
|
+
calldataHash: U,
|
|
59
|
+
messageSeed: L,
|
|
60
|
+
swapperAccountSalt: j,
|
|
61
61
|
H0Ax: X,
|
|
62
62
|
H0Ay: Z
|
|
63
|
-
}, {
|
|
63
|
+
}, { zkCallData: ie, publicSignals: ae, commitmentValidationData: oe } = await ee(O, _, v, y, `mainSolanaCircuit${te}`, re, h), [se, ce, le] = ie;
|
|
64
64
|
return {
|
|
65
|
-
proofAArr:
|
|
66
|
-
proofBArr:
|
|
67
|
-
proofCArr:
|
|
68
|
-
publicInputsArr:
|
|
65
|
+
proofAArr: se.map(BigInt).map(u).flat(),
|
|
66
|
+
proofBArr: ce.flat().map(BigInt).map(u).flat(),
|
|
67
|
+
proofCArr: le.map(BigInt).map(u).flat(),
|
|
68
|
+
publicInputsArr: ae.map(BigInt).map(u),
|
|
69
|
+
commitmentValidationData: oe
|
|
69
70
|
};
|
|
70
71
|
};
|
|
71
72
|
//#endregion
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require(`../pre-transaction/buildCommitmentValidationData.cjs`);require(`../pre-transaction/index.cjs`);const t=require(`./generateZkProof.cjs`);var n=async(n,r,i,a,o,s,c)=>{let l=await e.buildCommitmentValidationData(n,r,i,a),u=[o],d=[s];l&&(u.push(l.verifierName),d.push(l.commitmentInput));let f=await t.generateZkProof(n,u,d,c),{zkCallData:p,publicSignals:m}=f[0];return{zkCallData:p,publicSignals:m,commitmentValidationData:e.buildCommitmentValidationDataFromProof(l,f[1])}};exports.generateMainAndCommitmentZkProof=n;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { UserKeys } from '../../data-structures/crypto-keys/keys';
|
|
2
|
+
import { Utxo } from '../../data-structures/utxo/Utxo';
|
|
3
|
+
import { CommitmentValidationDataType } from '../../types/circom-data.types';
|
|
4
|
+
import { NewZkCallDataType } from '../../types/snark.types';
|
|
5
|
+
interface GenerateMainAndCommitmentZkProofResponse {
|
|
6
|
+
zkCallData: NewZkCallDataType;
|
|
7
|
+
publicSignals: string[];
|
|
8
|
+
commitmentValidationData: CommitmentValidationDataType | undefined;
|
|
9
|
+
}
|
|
10
|
+
export declare const generateMainAndCommitmentZkProof: (chainId: number, userKeys: UserKeys, tokenAddresses: string[], inputUtxos: Utxo[][], mainVerifierName: string, mainCircuitInput: unknown, generateProofRemotely: boolean) => Promise<GenerateMainAndCommitmentZkProofResponse>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { buildCommitmentValidationData as e, buildCommitmentValidationDataFromProof as t } from "../pre-transaction/buildCommitmentValidationData.mjs";
|
|
2
|
+
import "../pre-transaction/index.mjs";
|
|
3
|
+
import { generateZkProof as n } from "./generateZkProof.mjs";
|
|
4
|
+
//#region libs/shared/common/src/functions/snarkjs/generateMainAndCommitmentZkProof.ts
|
|
5
|
+
var r = async (r, i, a, o, s, c, l) => {
|
|
6
|
+
let u = await e(r, i, a, o), d = [s], f = [c];
|
|
7
|
+
u && (d.push(u.verifierName), f.push(u.commitmentInput));
|
|
8
|
+
let p = await n(r, d, f, l), { zkCallData: m, publicSignals: h } = p[0];
|
|
9
|
+
return {
|
|
10
|
+
zkCallData: m,
|
|
11
|
+
publicSignals: h,
|
|
12
|
+
commitmentValidationData: t(u, p[1])
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
//#endregion
|
|
16
|
+
export { r as generateMainAndCommitmentZkProof };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../utils/customEnclaveFunctionsRegister.cjs`),t=require(`../../error-handling/logger.cjs`),n=require(`./getZKFiles.cjs`),r=require(`./generateZkProofEnclave.cjs`),i=require(`./generateZkProofSelf.cjs`);var a=async(a,o,s,c)=>{if(c)try{let t=e.getCustomProofGenerator();
|
|
1
|
+
const e=require(`../utils/customEnclaveFunctionsRegister.cjs`),t=require(`../../error-handling/logger.cjs`),n=require(`./getZKFiles.cjs`),r=require(`./generateZkProofEnclave.cjs`),i=require(`./generateZkProofSelf.cjs`);var a=async(a,o,s,c)=>{if(c)try{let t=e.getCustomProofGenerator();return t?(await t(s,o.map(e=>n.getWASMFile(e,a)),o.map(e=>n.getZKeyFile(e,a)))).map(({zkCallData:e,publicSignals:t})=>({zkCallData:e,publicSignals:t})):await r.generateZkProofEnclave(a,o,s)}catch(e){t.Logger.error(`enclave proof error`,e)}return Promise.all(o.map((e,t)=>i.generateZkProofSelf(a,e,s[t])))};exports.generateZkProof=a;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { NewZkCallDataType } from '../../types';
|
|
2
|
-
export declare const generateZkProof: (chainId: number,
|
|
1
|
+
import { NewZkCallDataType } from '../../types/snark.types';
|
|
2
|
+
export declare const generateZkProof: (chainId: number, verifierNames: string[], inputs: any[], remotely?: boolean) => Promise<{
|
|
3
3
|
zkCallData: NewZkCallDataType;
|
|
4
4
|
publicSignals: string[];
|
|
5
|
-
}>;
|
|
5
|
+
}[]>;
|
|
@@ -7,18 +7,14 @@ import { generateZkProofSelf as a } from "./generateZkProofSelf.mjs";
|
|
|
7
7
|
var o = async (o, s, c, l) => {
|
|
8
8
|
if (l) try {
|
|
9
9
|
let t = e();
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
publicSignals: i
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
return await i(o, s, c);
|
|
10
|
+
return t ? (await t(c, s.map((e) => n(e, o)), s.map((e) => r(e, o)))).map(({ zkCallData: e, publicSignals: t }) => ({
|
|
11
|
+
zkCallData: e,
|
|
12
|
+
publicSignals: t
|
|
13
|
+
})) : await i(o, s, c);
|
|
18
14
|
} catch (e) {
|
|
19
15
|
t.error("enclave proof error", e);
|
|
20
16
|
}
|
|
21
|
-
return a(o,
|
|
17
|
+
return Promise.all(s.map((e, t) => a(o, e, c[t])));
|
|
22
18
|
};
|
|
23
19
|
//#endregion
|
|
24
20
|
export { o as generateZkProof };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../../data-structures/http/HttpClient.cjs`);require(`../../data-structures/http/index.cjs`);const t=require(`./constant.cjs`),n=require(`../utils/encryptInputForEnclave.cjs`),r=require(`./getZKFiles.cjs`);var i=e=>{if(e.startsWith(`http`)){let t=e.split(`/`).at(-1);if(!t)throw Error(`invalid verifierName`);return t}return e},a=async(a,o,s)=>{let c=i(r.getWASMFile(
|
|
1
|
+
const e=require(`../../data-structures/http/HttpClient.cjs`);require(`../../data-structures/http/index.cjs`);const t=require(`./constant.cjs`),n=require(`../utils/encryptInputForEnclave.cjs`),r=require(`./getZKFiles.cjs`);var i=e=>{if(e.startsWith(`http`)){let t=e.split(`/`).at(-1);if(!t)throw Error(`invalid verifierName`);return t}return e},a=async(a,o,s)=>{let c=o.map(e=>i(r.getWASMFile(e,a))),l=o.map(e=>i(r.getZKeyFile(e,a))),{keyCiphertext:u,inputCiphertext:d}=await n.makeEnclaveHandshakeAndEncryptInput(s),f={circuit_wasms:c,circuit_zkeys:l,inputs:d,key:u};return(await e.httpClient.post(`${t.ENCLAVE_URL}/generate-proofs`,f)).map(({zk_calldata:e,public_signals:t})=>({zkCallData:e,publicSignals:t}))};exports.generateZkProofEnclave=a;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NewZkCallDataType } from '../../types/snark.types';
|
|
2
|
-
export declare const generateZkProofEnclave: (chainId: number,
|
|
2
|
+
export declare const generateZkProofEnclave: (chainId: number, verifierNames: string[], inputs: any[]) => Promise<{
|
|
3
3
|
zkCallData: NewZkCallDataType;
|
|
4
4
|
publicSignals: string[];
|
|
5
|
-
}>;
|
|
5
|
+
}[]>;
|
|
@@ -12,16 +12,16 @@ var a = (e) => {
|
|
|
12
12
|
}
|
|
13
13
|
return e;
|
|
14
14
|
}, o = async (o, s, c) => {
|
|
15
|
-
let l = a(r(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
let l = s.map((e) => a(r(e, o))), u = s.map((e) => a(i(e, o))), { keyCiphertext: d, inputCiphertext: f } = await n(c), p = {
|
|
16
|
+
circuit_wasms: l,
|
|
17
|
+
circuit_zkeys: u,
|
|
18
|
+
inputs: f,
|
|
19
19
|
key: d
|
|
20
|
-
}, { public_signals: m, zk_calldata: h } = await e.post(`${t}/generate`, p);
|
|
21
|
-
return {
|
|
22
|
-
zkCallData: h,
|
|
23
|
-
publicSignals: m
|
|
24
20
|
};
|
|
21
|
+
return (await e.post(`${t}/generate-proofs`, p)).map(({ zk_calldata: e, public_signals: t }) => ({
|
|
22
|
+
zkCallData: e,
|
|
23
|
+
publicSignals: t
|
|
24
|
+
}));
|
|
25
25
|
};
|
|
26
26
|
//#endregion
|
|
27
27
|
export { o as generateZkProofEnclave };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(
|
|
1
|
+
const e=require(`../../webworker/worker.registry.cjs`),t=require(`../../webworker/performTaskWithWorker.cjs`),n=require(`./getZKFiles.cjs`),r=require(`../../webworker/snarkjsWorker/snarkjsWorker.types.cjs`);var i=async(i,a,o)=>{let s=n.getWASMFile(a,i),c=n.getZKeyFile(a,i),{publicSignals:l,zkCallData:u}=await t.performTaskWithWorker({type:e.WorkerVariant.SnarkJS,payload:{type:r.SnarkJSWorkerActionType.FULL_PROVE,data:{input:o,chainId:i,wasmFilePath:s,zKeyFilePath:c}}});return{zkCallData:u,publicSignals:l}};exports.generateZkProofSelf=i;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { WorkerVariant as e } from "../../webworker/worker.registry.mjs";
|
|
2
|
+
import { performTaskWithWorker as t } from "../../webworker/performTaskWithWorker.mjs";
|
|
3
|
+
import { getWASMFile as n, getZKeyFile as r } from "./getZKFiles.mjs";
|
|
4
4
|
import { SnarkJSWorkerActionType as i } from "../../webworker/snarkjsWorker/snarkjsWorker.types.mjs";
|
|
5
5
|
//#region libs/shared/common/src/functions/snarkjs/generateZkProofSelf.ts
|
|
6
6
|
var a = async (a, o, s) => {
|
|
7
|
-
let c =
|
|
8
|
-
type:
|
|
7
|
+
let c = n(o, a), l = r(o, a), { publicSignals: u, zkCallData: d } = await t({
|
|
8
|
+
type: e.SnarkJS,
|
|
9
9
|
payload: {
|
|
10
10
|
type: i.FULL_PROVE,
|
|
11
11
|
data: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
require(`./common.snarkjs.cjs`),require(`./signedMessageHash.cjs`),require(`./generateZkProof.cjs`),require(`./fetchOnChainRootHashes.cjs`),require(`./constructGeneralZkProof.cjs`),require(`./constructSolanaZkProof.cjs`),require(`./verifyCommitmentValidationData.cjs`);
|
|
1
|
+
require(`./common.snarkjs.cjs`),require(`./signedMessageHash.cjs`),require(`./generateZkProof.cjs`),require(`./generateMainAndCommitmentZkProof.cjs`),require(`./fetchOnChainRootHashes.cjs`),require(`./constructGeneralZkProof.cjs`),require(`./constructSolanaZkProof.cjs`),require(`./verifyCommitmentValidationData.cjs`);
|
|
@@ -2,6 +2,7 @@ export * from './constructGeneralZkProof';
|
|
|
2
2
|
export * from './common.snarkjs';
|
|
3
3
|
export * from './signedMessageHash';
|
|
4
4
|
export * from './generateZkProof';
|
|
5
|
+
export * from './generateMainAndCommitmentZkProof';
|
|
5
6
|
export * from './constructSolanaZkProof';
|
|
6
7
|
export * from './fetchOnChainRootHashes';
|
|
7
8
|
export * from './verifyCommitmentValidationData';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import "./common.snarkjs.mjs";
|
|
2
2
|
import "./signedMessageHash.mjs";
|
|
3
3
|
import "./generateZkProof.mjs";
|
|
4
|
+
import "./generateMainAndCommitmentZkProof.mjs";
|
|
4
5
|
import "./fetchOnChainRootHashes.mjs";
|
|
5
6
|
import "./constructGeneralZkProof.mjs";
|
|
6
7
|
import "./constructSolanaZkProof.mjs";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../../_virtual/_rolldown/runtime.cjs`),t=require(`../../data-structures/http/HttpClient.cjs`),n=require(`../utils/bytes32.utils.cjs`),r=require(`./common.snarkjs.cjs`),i=require(
|
|
1
|
+
const e=require(`../../_virtual/_rolldown/runtime.cjs`),t=require(`../../data-structures/http/HttpClient.cjs`),n=require(`../utils/bytes32.utils.cjs`),r=require(`./common.snarkjs.cjs`),i=require(`../pre-transaction/solana-public-signals.cjs`),a=require(`./getZKFiles.cjs`);let o=require(`ethers`),s=require(`snarkjs`);s=e.__toESM(s);var c=e=>e.flat().map(e=>BigInt(e).toString()),l=(e,t)=>{let n=t.inNullifiers[0]?.length??0;return a.getVKFile(`commitmentCalculator${t.tokenAddresses.length}x${n}`,e)},u=async(e,n)=>{let r=l(e,n);return t.httpClient.get(r)},d=e=>({pi_a:[...e.a],pi_b:[[e.b[0][1],e.b[0][0]],[e.b[1][1],e.b[1][0]]],pi_c:[...e.c],protocol:`groth16`}),f=e=>{let t=e.tokenAddresses.map(e=>o.ethers.getBigInt(e).toString()),n=c(e.inCommitments),r=c(e.inNullifiers);return[...t,...n,...r]},p=async(e,t,n)=>{if(c(t.inNullifiers).join(`,`)!==n.join(`,`))throw Error(`commitmentValidationData.inNullifiers mismatch with request input`);let r=await u(e,t),i=f(t),a=d(t.proof);if(!await s.groth16.verify(r,i,a))throw Error(`Invalid commitment validation proof`)},m=async e=>{let t=e.commitmentValidationData;if(!t)return;let n=c(r.deserializeCircomData(e.circomData).inputNullifiers);await p(e.chainId,t,n)},h=async e=>{let t=e.commitmentValidationData;if(!t)return;let r=i.convertSolanaPublicSignals(e.args.publicInputsArr,e.args.dimensions).inNullifiers.flat().map(e=>n.convertBytes32ToBigInt(e).toString());await p(e.chainId,t,r)};exports.verifyCommitmentValidationData=m,exports.verifyCommitmentValidationDataSolana=h;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { httpClient as e } from "../../data-structures/http/HttpClient.mjs";
|
|
2
2
|
import { convertBytes32ToBigInt as t } from "../utils/bytes32.utils.mjs";
|
|
3
3
|
import { deserializeCircomData as n } from "./common.snarkjs.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { convertSolanaPublicSignals as r } from "../pre-transaction/solana-public-signals.mjs";
|
|
5
|
+
import { getVKFile as i } from "./getZKFiles.mjs";
|
|
6
6
|
import { ethers as a } from "ethers";
|
|
7
7
|
import * as o from "snarkjs";
|
|
8
8
|
//#region libs/shared/common/src/functions/snarkjs/verifyCommitmentValidationData.ts
|
|
9
9
|
var s = (e) => e.flat().map((e) => BigInt(e).toString()), c = (e, t) => {
|
|
10
10
|
let n = t.inNullifiers[0]?.length ?? 0;
|
|
11
|
-
return
|
|
11
|
+
return i(`commitmentCalculator${t.tokenAddresses.length}x${n}`, e);
|
|
12
12
|
}, l = async (t, n) => {
|
|
13
13
|
let r = c(t, n);
|
|
14
14
|
return e.get(r);
|
|
@@ -36,8 +36,8 @@ var s = (e) => e.flat().map((e) => BigInt(e).toString()), c = (e, t) => {
|
|
|
36
36
|
}, m = async (e) => {
|
|
37
37
|
let n = e.commitmentValidationData;
|
|
38
38
|
if (!n) return;
|
|
39
|
-
let
|
|
40
|
-
await f(e.chainId, n,
|
|
39
|
+
let i = r(e.args.publicInputsArr, e.args.dimensions).inNullifiers.flat().map((e) => t(e).toString());
|
|
40
|
+
await f(e.chainId, n, i);
|
|
41
41
|
};
|
|
42
42
|
//#endregion
|
|
43
43
|
export { p as verifyCommitmentValidationData, m as verifyCommitmentValidationDataSolana };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { NewZkCallDataType } from '../../types/snark.types';
|
|
2
1
|
import { RemoteProofType } from '../../types/remote-proof.types';
|
|
3
2
|
import { EncryptedOutputWithSign } from '../../types/commitments.types';
|
|
4
3
|
import { IUtxoConstructor } from '../../data-structures/utxo/Utxo';
|
|
5
|
-
|
|
4
|
+
import { NewZkCallDataType } from '../../types/snark.types';
|
|
5
|
+
export type ProofGeneratorFn = (inputs: any[], circuitWasmFilenames: string[], circuitZkeyFilenames: string[]) => Promise<{
|
|
6
6
|
proof: RemoteProofType;
|
|
7
7
|
publicSignals: string[];
|
|
8
8
|
zkCallData: NewZkCallDataType;
|
|
9
|
-
}>;
|
|
9
|
+
}[]>;
|
|
10
10
|
export type UtxoDecryptorFn = (chainId: number, keysData: Uint8Array) => Promise<{
|
|
11
11
|
utxos: IUtxoConstructor<string>[];
|
|
12
12
|
encryptedOutputs: EncryptedOutputWithSign[];
|