@veilo/sdk-core 0.3.3 → 0.5.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/LICENSE +15 -0
- package/README.md +289 -1262
- package/dist/cjs/accounts/admin.d.ts +84 -0
- package/dist/cjs/accounts/admin.js +208 -0
- package/dist/cjs/accounts/errors.d.ts +6 -0
- package/dist/cjs/accounts/errors.js +98 -0
- package/dist/cjs/accounts/index.d.ts +4 -0
- package/dist/cjs/accounts/index.js +20 -0
- package/dist/cjs/accounts/pdas.d.ts +23 -0
- package/dist/cjs/accounts/pdas.js +44 -0
- package/dist/cjs/accounts/queries.d.ts +41 -0
- package/dist/cjs/accounts/queries.js +95 -0
- package/dist/cjs/client.d.ts +2 -407
- package/dist/cjs/client.js +17 -912
- package/dist/cjs/cloak/client.d.ts +28 -0
- package/dist/cjs/cloak/client.js +68 -0
- package/dist/cjs/cloak/errors.d.ts +13 -0
- package/dist/cjs/cloak/errors.js +25 -0
- package/dist/cjs/cloak/helpers.d.ts +6 -0
- package/dist/cjs/cloak/helpers.js +35 -0
- package/dist/cjs/cloak/index.d.ts +6 -0
- package/dist/cjs/cloak/index.js +24 -0
- package/dist/cjs/cloak/polling.d.ts +7 -0
- package/dist/cjs/cloak/polling.js +66 -0
- package/dist/cjs/cloak/transport.d.ts +15 -0
- package/dist/cjs/cloak/transport.js +119 -0
- package/dist/cjs/cloak/types.d.ts +188 -0
- package/dist/cjs/cloak/types.js +5 -0
- package/dist/cjs/cloak.d.ts +1 -0
- package/dist/cjs/cloak.js +18 -0
- package/dist/cjs/compactNote.d.ts +128 -0
- package/dist/cjs/compactNote.js +191 -0
- package/dist/cjs/events.d.ts +1 -1
- package/dist/cjs/events.js +2 -2
- package/dist/cjs/idl/privacy_pool.d.ts +5 -0
- package/dist/cjs/idl/privacy_pool.js +15218 -0
- package/dist/cjs/index.d.ts +17 -13
- package/dist/cjs/index.js +43 -30
- package/dist/cjs/merkle.d.ts +13 -0
- package/dist/cjs/merkle.js +31 -8
- package/dist/cjs/notes/encryption.d.ts +41 -0
- package/dist/cjs/notes/encryption.js +75 -0
- package/dist/cjs/notes/index.d.ts +5 -0
- package/dist/cjs/notes/index.js +21 -0
- package/dist/cjs/notes/mailbox.d.ts +70 -0
- package/dist/cjs/notes/mailbox.js +164 -0
- package/dist/cjs/notes/model.d.ts +91 -0
- package/dist/cjs/notes/model.js +109 -0
- package/dist/cjs/notes/nullifier.d.ts +27 -0
- package/dist/cjs/notes/nullifier.js +45 -0
- package/dist/cjs/notes/recovery.d.ts +10 -0
- package/dist/cjs/notes/recovery.js +31 -0
- package/dist/cjs/program.d.ts +11 -0
- package/dist/cjs/program.js +26 -3
- package/dist/cjs/proof.d.ts +1 -183
- package/dist/cjs/proof.js +16 -290
- package/dist/cjs/proofs/encoding.d.ts +17 -0
- package/dist/cjs/proofs/encoding.js +72 -0
- package/dist/cjs/proofs/formatting.d.ts +6 -0
- package/dist/cjs/proofs/formatting.js +34 -0
- package/dist/cjs/proofs/index.d.ts +5 -0
- package/dist/cjs/proofs/index.js +21 -0
- package/dist/cjs/proofs/swap.d.ts +87 -0
- package/dist/cjs/proofs/swap.js +144 -0
- package/dist/cjs/proofs/transaction.d.ts +28 -0
- package/dist/cjs/proofs/transaction.js +110 -0
- package/dist/cjs/proofs/types.d.ts +70 -0
- package/dist/cjs/proofs/types.js +2 -0
- package/dist/cjs/prover.d.ts +4 -1
- package/dist/cjs/prover.js +12 -2
- package/dist/cjs/random.d.ts +16 -0
- package/dist/cjs/random.js +28 -0
- package/dist/cjs/relayer/client.d.ts +61 -0
- package/dist/cjs/relayer/client.js +151 -0
- package/dist/cjs/relayer/crypto.d.ts +5 -0
- package/dist/cjs/relayer/crypto.js +26 -0
- package/dist/cjs/relayer/encoding.d.ts +2 -0
- package/dist/cjs/relayer/encoding.js +23 -0
- package/dist/cjs/relayer/errors.d.ts +7 -0
- package/dist/cjs/relayer/errors.js +17 -0
- package/dist/cjs/relayer/index.d.ts +3 -0
- package/dist/cjs/relayer/index.js +19 -0
- package/dist/cjs/relayer/transport.d.ts +17 -0
- package/dist/cjs/relayer/transport.js +63 -0
- package/dist/cjs/relayer/types.d.ts +276 -0
- package/dist/cjs/relayer/types.js +5 -0
- package/dist/cjs/relayer.d.ts +1 -295
- package/dist/cjs/relayer.js +15 -243
- package/dist/cjs/shield/alt.d.ts +87 -0
- package/dist/cjs/shield/alt.js +194 -0
- package/dist/cjs/shield/computeBudget.d.ts +61 -0
- package/dist/cjs/shield/computeBudget.js +64 -0
- package/dist/cjs/shield/errors.d.ts +58 -0
- package/dist/cjs/shield/errors.js +121 -0
- package/dist/cjs/shield/finalize.d.ts +45 -0
- package/dist/cjs/shield/finalize.js +119 -0
- package/dist/cjs/shield/index.d.ts +35 -0
- package/dist/cjs/shield/index.js +68 -0
- package/dist/cjs/shield/ix.d.ts +54 -0
- package/dist/cjs/shield/ix.js +119 -0
- package/dist/cjs/shield/owner.d.ts +36 -0
- package/dist/cjs/shield/owner.js +127 -0
- package/dist/cjs/shield/ports.d.ts +43 -0
- package/dist/cjs/shield/ports.js +153 -0
- package/dist/cjs/shield/preflight.d.ts +30 -0
- package/dist/cjs/shield/preflight.js +154 -0
- package/dist/cjs/shield/shield.d.ts +68 -0
- package/dist/cjs/shield/shield.js +500 -0
- package/dist/cjs/shield/types.d.ts +202 -0
- package/dist/cjs/shield/types.js +2 -0
- package/dist/cjs/transactions/deposit.d.ts +94 -0
- package/dist/cjs/transactions/deposit.js +234 -0
- package/dist/cjs/transactions/index.d.ts +7 -0
- package/dist/cjs/transactions/index.js +26 -0
- package/dist/cjs/transactions/swap.d.ts +71 -0
- package/dist/cjs/transactions/swap.js +184 -0
- package/dist/cjs/transactions/transact.d.ts +34 -0
- package/dist/cjs/transactions/transact.js +146 -0
- package/dist/cjs/transactions/transfer.d.ts +51 -0
- package/dist/cjs/transactions/transfer.js +106 -0
- package/dist/cjs/transactions/withdraw.d.ts +52 -0
- package/dist/cjs/transactions/withdraw.js +104 -0
- package/dist/cjs/utxo.d.ts +1 -215
- package/dist/cjs/utxo.js +15 -391
- package/dist/esm/accounts/admin.d.ts +84 -0
- package/dist/esm/accounts/admin.js +165 -0
- package/dist/esm/accounts/errors.d.ts +6 -0
- package/dist/esm/accounts/errors.js +95 -0
- package/dist/esm/accounts/index.d.ts +4 -0
- package/dist/esm/accounts/index.js +4 -0
- package/dist/esm/accounts/pdas.d.ts +23 -0
- package/dist/esm/accounts/pdas.js +38 -0
- package/dist/esm/accounts/queries.d.ts +41 -0
- package/dist/esm/accounts/queries.js +88 -0
- package/dist/esm/client.d.ts +2 -0
- package/dist/esm/client.js +3 -887
- package/dist/esm/cloak/client.d.ts +28 -0
- package/dist/esm/cloak/client.js +64 -0
- package/dist/esm/cloak/errors.d.ts +13 -0
- package/dist/esm/cloak/errors.js +21 -0
- package/dist/esm/cloak/helpers.d.ts +6 -0
- package/dist/esm/cloak/helpers.js +31 -0
- package/dist/esm/cloak/index.d.ts +6 -0
- package/dist/esm/cloak/index.js +6 -0
- package/dist/esm/cloak/polling.d.ts +7 -0
- package/dist/esm/cloak/polling.js +63 -0
- package/dist/esm/cloak/transport.d.ts +15 -0
- package/dist/esm/cloak/transport.js +115 -0
- package/dist/esm/cloak/types.d.ts +188 -0
- package/dist/esm/cloak/types.js +4 -0
- package/dist/esm/cloak.d.ts +1 -0
- package/dist/esm/cloak.js +2 -0
- package/dist/esm/compactNote.d.ts +128 -0
- package/dist/esm/compactNote.js +179 -0
- package/dist/esm/config.d.ts +82 -0
- package/dist/esm/events.d.ts +77 -0
- package/dist/esm/events.js +1 -1
- package/dist/esm/idl/privacy_pool.d.ts +5 -0
- package/dist/esm/idl/privacy_pool.js +15216 -0
- package/dist/esm/index.d.ts +17 -0
- package/dist/esm/index.js +20 -11
- package/dist/esm/merkle.d.ts +77 -0
- package/dist/esm/merkle.js +23 -1
- package/dist/esm/notes/encryption.d.ts +41 -0
- package/dist/esm/notes/encryption.js +67 -0
- package/dist/esm/notes/index.d.ts +5 -0
- package/dist/esm/notes/index.js +5 -0
- package/dist/esm/notes/mailbox.d.ts +70 -0
- package/dist/esm/notes/mailbox.js +154 -0
- package/dist/esm/notes/model.d.ts +91 -0
- package/dist/esm/notes/model.js +99 -0
- package/dist/esm/notes/nullifier.d.ts +27 -0
- package/dist/esm/notes/nullifier.js +40 -0
- package/dist/esm/notes/recovery.d.ts +10 -0
- package/dist/esm/notes/recovery.js +28 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/poseidon.d.ts +29 -0
- package/dist/esm/program.d.ts +37 -0
- package/dist/esm/program.js +23 -1
- package/dist/esm/proof.d.ts +1 -0
- package/dist/esm/proof.js +2 -281
- package/dist/esm/proofs/encoding.d.ts +17 -0
- package/dist/esm/proofs/encoding.js +68 -0
- package/dist/esm/proofs/formatting.d.ts +6 -0
- package/dist/esm/proofs/formatting.js +31 -0
- package/dist/esm/proofs/index.d.ts +5 -0
- package/dist/esm/proofs/index.js +5 -0
- package/dist/esm/proofs/swap.d.ts +87 -0
- package/dist/esm/proofs/swap.js +138 -0
- package/dist/esm/proofs/transaction.d.ts +28 -0
- package/dist/esm/proofs/transaction.js +105 -0
- package/dist/esm/proofs/types.d.ts +70 -0
- package/dist/esm/proofs/types.js +1 -0
- package/dist/esm/prover.d.ts +57 -0
- package/dist/esm/prover.js +10 -1
- package/dist/esm/random.d.ts +16 -0
- package/dist/esm/random.js +21 -0
- package/dist/esm/relayer/client.d.ts +61 -0
- package/dist/esm/relayer/client.js +144 -0
- package/dist/esm/relayer/crypto.d.ts +5 -0
- package/dist/esm/relayer/crypto.js +20 -0
- package/dist/esm/relayer/encoding.d.ts +2 -0
- package/dist/esm/relayer/encoding.js +19 -0
- package/dist/esm/relayer/errors.d.ts +7 -0
- package/dist/esm/relayer/errors.js +13 -0
- package/dist/esm/relayer/index.d.ts +3 -0
- package/dist/esm/relayer/index.js +3 -0
- package/dist/esm/relayer/transport.d.ts +17 -0
- package/dist/esm/relayer/transport.js +59 -0
- package/dist/esm/relayer/types.d.ts +276 -0
- package/dist/esm/relayer/types.js +4 -0
- package/dist/esm/relayer.d.ts +1 -0
- package/dist/esm/relayer.js +2 -238
- package/dist/esm/retry.d.ts +32 -0
- package/dist/esm/shield/alt.d.ts +87 -0
- package/dist/esm/shield/alt.js +186 -0
- package/dist/esm/shield/computeBudget.d.ts +61 -0
- package/dist/esm/shield/computeBudget.js +61 -0
- package/dist/esm/shield/errors.d.ts +58 -0
- package/dist/esm/shield/errors.js +115 -0
- package/dist/esm/shield/finalize.d.ts +45 -0
- package/dist/esm/shield/finalize.js +83 -0
- package/dist/esm/shield/index.d.ts +35 -0
- package/dist/esm/shield/index.js +32 -0
- package/dist/esm/shield/ix.d.ts +54 -0
- package/dist/esm/shield/ix.js +82 -0
- package/dist/esm/shield/owner.d.ts +36 -0
- package/dist/esm/shield/owner.js +123 -0
- package/dist/esm/shield/ports.d.ts +43 -0
- package/dist/esm/shield/ports.js +147 -0
- package/dist/esm/shield/preflight.d.ts +30 -0
- package/dist/esm/shield/preflight.js +151 -0
- package/dist/esm/shield/shield.d.ts +68 -0
- package/dist/esm/shield/shield.js +493 -0
- package/dist/esm/shield/types.d.ts +202 -0
- package/dist/esm/shield/types.js +1 -0
- package/dist/esm/transactions/deposit.d.ts +94 -0
- package/dist/esm/transactions/deposit.js +198 -0
- package/dist/esm/transactions/index.d.ts +7 -0
- package/dist/esm/transactions/index.js +7 -0
- package/dist/esm/transactions/swap.d.ts +71 -0
- package/dist/esm/transactions/swap.js +144 -0
- package/dist/esm/transactions/transact.d.ts +34 -0
- package/dist/esm/transactions/transact.js +110 -0
- package/dist/esm/transactions/transfer.d.ts +51 -0
- package/dist/esm/transactions/transfer.js +103 -0
- package/dist/esm/transactions/withdraw.d.ts +52 -0
- package/dist/esm/transactions/withdraw.js +101 -0
- package/dist/esm/utxo.d.ts +1 -0
- package/dist/esm/utxo.js +2 -372
- package/package.json +111 -15
package/dist/cjs/proof.js
CHANGED
|
@@ -1,292 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
exports.encodeSnarkjsProofToTransactionProof = encodeSnarkjsProofToTransactionProof;
|
|
8
|
-
exports.formatInputsForSnarkjs = formatInputsForSnarkjs;
|
|
9
|
-
exports.formatSwapInputsForSnarkjs = formatSwapInputsForSnarkjs;
|
|
10
|
-
exports.computeSwapParamsHash = computeSwapParamsHash;
|
|
11
|
-
exports.computeSwapDataHash = computeSwapDataHash;
|
|
12
|
-
const sha256_1 = require("@noble/hashes/sha256");
|
|
13
|
-
const poseidon_1 = require("./poseidon");
|
|
14
|
-
const utxo_1 = require("./utxo");
|
|
15
|
-
// -----------------------------------------------------------------------------
|
|
16
|
-
// ExtData Hash Computation
|
|
17
|
-
// -----------------------------------------------------------------------------
|
|
18
|
-
/**
|
|
19
|
-
* Compute the external data hash.
|
|
20
|
-
* Matches on-chain computation:
|
|
21
|
-
* hash1 = Poseidon(recipient, relayer)
|
|
22
|
-
* hash2 = Poseidon(fee, refund)
|
|
23
|
-
* extDataHash = Poseidon(hash1, hash2, claimant)
|
|
24
|
-
*/
|
|
25
|
-
function computeExtDataHash(extData) {
|
|
26
|
-
const recipientField = (0, poseidon_1.pubkeyToField)(extData.recipient);
|
|
27
|
-
const relayerField = (0, poseidon_1.pubkeyToField)(extData.relayer);
|
|
28
|
-
const feeField = extData.fee % poseidon_1.BN254_FR_MODULUS;
|
|
29
|
-
const refundField = extData.refund % poseidon_1.BN254_FR_MODULUS;
|
|
30
|
-
const claimantField = (0, poseidon_1.pubkeyToField)(extData.claimant);
|
|
31
|
-
const hash1 = (0, poseidon_1.poseidon2)(recipientField, relayerField);
|
|
32
|
-
const hash2 = (0, poseidon_1.poseidon2)(feeField, refundField);
|
|
33
|
-
const finalHash = (0, poseidon_1.poseidon3)(hash1, hash2, claimantField);
|
|
34
|
-
return (0, poseidon_1.bigIntToBytesBE)(finalHash);
|
|
35
|
-
}
|
|
36
|
-
// -----------------------------------------------------------------------------
|
|
37
|
-
// Circuit Input Preparation
|
|
38
|
-
// -----------------------------------------------------------------------------
|
|
39
|
-
/**
|
|
40
|
-
* Convert i64 to field element (handles negative via modular arithmetic).
|
|
41
|
-
* For negative values, we add the field modulus to get the equivalent positive representation.
|
|
42
|
-
*/
|
|
43
|
-
function i64ToField(value) {
|
|
44
|
-
if (value >= 0n) {
|
|
45
|
-
return value % poseidon_1.BN254_FR_MODULUS;
|
|
46
|
-
}
|
|
47
|
-
return (poseidon_1.BN254_FR_MODULUS + value) % poseidon_1.BN254_FR_MODULUS;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Prepare transaction circuit inputs from high-level parameters.
|
|
51
|
-
* This converts the SDK types into the format expected by the circuit.
|
|
52
|
-
*/
|
|
53
|
-
function prepareTransactionInputs(params) {
|
|
54
|
-
const { inputUTXOs, outputUTXOs, root, publicAmount, extData, mintAddress } = params;
|
|
55
|
-
const extDataHash = computeExtDataHash(extData);
|
|
56
|
-
const mintField = (0, poseidon_1.pubkeyToField)(mintAddress);
|
|
57
|
-
// Prepare input UTXO data
|
|
58
|
-
const inAmount = [
|
|
59
|
-
inputUTXOs[0].amount,
|
|
60
|
-
inputUTXOs[1].amount,
|
|
61
|
-
];
|
|
62
|
-
const inPubkey = [
|
|
63
|
-
inputUTXOs[0].pubkey,
|
|
64
|
-
inputUTXOs[1].pubkey,
|
|
65
|
-
];
|
|
66
|
-
const inBlinding = [
|
|
67
|
-
inputUTXOs[0].blinding,
|
|
68
|
-
inputUTXOs[1].blinding,
|
|
69
|
-
];
|
|
70
|
-
const inPathIndex = [
|
|
71
|
-
inputUTXOs[0].pathIndex,
|
|
72
|
-
inputUTXOs[1].pathIndex,
|
|
73
|
-
];
|
|
74
|
-
const inPathElements = [
|
|
75
|
-
inputUTXOs[0].pathElements.map((e) => (0, poseidon_1.bytesToBigIntBE)(e) % poseidon_1.BN254_FR_MODULUS),
|
|
76
|
-
inputUTXOs[1].pathElements.map((e) => (0, poseidon_1.bytesToBigIntBE)(e) % poseidon_1.BN254_FR_MODULUS),
|
|
77
|
-
];
|
|
78
|
-
const inPrivateKey = [
|
|
79
|
-
inputUTXOs[0].privateKey,
|
|
80
|
-
inputUTXOs[1].privateKey,
|
|
81
|
-
];
|
|
82
|
-
// Prepare output UTXO data
|
|
83
|
-
const outAmount = [
|
|
84
|
-
outputUTXOs[0].amount,
|
|
85
|
-
outputUTXOs[1].amount,
|
|
86
|
-
];
|
|
87
|
-
const outPubkey = [
|
|
88
|
-
outputUTXOs[0].pubkey,
|
|
89
|
-
outputUTXOs[1].pubkey,
|
|
90
|
-
];
|
|
91
|
-
const outBlinding = [
|
|
92
|
-
outputUTXOs[0].blinding,
|
|
93
|
-
outputUTXOs[1].blinding,
|
|
94
|
-
];
|
|
95
|
-
// Derive nullifiers for input UTXOs
|
|
96
|
-
const inputNullifiers = [
|
|
97
|
-
(0, utxo_1.deriveNullifier)(inputUTXOs[0], inputUTXOs[0].pathIndex, inputUTXOs[0].privateKey),
|
|
98
|
-
(0, utxo_1.deriveNullifier)(inputUTXOs[1], inputUTXOs[1].pathIndex, inputUTXOs[1].privateKey),
|
|
99
|
-
];
|
|
100
|
-
return {
|
|
101
|
-
root,
|
|
102
|
-
publicAmount,
|
|
103
|
-
extDataHash,
|
|
104
|
-
mintAddress,
|
|
105
|
-
inputNullifiers,
|
|
106
|
-
outputCommitments: [outputUTXOs[0].commitment, outputUTXOs[1].commitment],
|
|
107
|
-
inAmount,
|
|
108
|
-
inPubkey,
|
|
109
|
-
inBlinding,
|
|
110
|
-
inPathIndex,
|
|
111
|
-
inPathElements,
|
|
112
|
-
inPrivateKey,
|
|
113
|
-
outAmount,
|
|
114
|
-
outPubkey,
|
|
115
|
-
outBlinding,
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
// -----------------------------------------------------------------------------
|
|
119
|
-
// Proof Packing
|
|
120
|
-
// -----------------------------------------------------------------------------
|
|
121
|
-
/**
|
|
122
|
-
* Convert bigint to 32-byte big-endian representation.
|
|
123
|
-
* The alt_bn128 Solana precompile (and ark-works via change_endianness) expect BE.
|
|
124
|
-
*/
|
|
125
|
-
function bigintTo32BytesBE(x) {
|
|
126
|
-
const out = new Uint8Array(32);
|
|
127
|
-
let v = x;
|
|
128
|
-
for (let i = 31; i >= 0; i--) {
|
|
129
|
-
out[i] = Number(v & 0xffn);
|
|
130
|
-
v >>= 8n;
|
|
131
|
-
}
|
|
132
|
-
return out;
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Turn a snarkjs Groth16 proof into 256 bytes:
|
|
136
|
-
* A(G1) | B(G2) | C(G1)
|
|
137
|
-
* where:
|
|
138
|
-
* A = (ax, ay) -> 64 bytes
|
|
139
|
-
* B = (bx1, bx0, by1, by0) -> 128 bytes (swapped pairs for alt_bn128)
|
|
140
|
-
* C = (cx, cy) -> 64 bytes
|
|
141
|
-
*
|
|
142
|
-
* Each field element is encoded as 32-byte BE to match the on-chain verifier.
|
|
143
|
-
* We ignore the extra projective/z components snarkjs keeps.
|
|
144
|
-
*/
|
|
145
|
-
function packProofToBytes(proof) {
|
|
146
|
-
const chunks = [];
|
|
147
|
-
const ax = BigInt(proof.pi_a[0]);
|
|
148
|
-
const ay = BigInt(proof.pi_a[1]);
|
|
149
|
-
chunks.push(bigintTo32BytesBE(ax), bigintTo32BytesBE(ay));
|
|
150
|
-
const bx = proof.pi_b[0];
|
|
151
|
-
const by = proof.pi_b[1];
|
|
152
|
-
const bx0 = BigInt(bx[0]);
|
|
153
|
-
const bx1 = BigInt(bx[1]);
|
|
154
|
-
const by0 = BigInt(by[0]);
|
|
155
|
-
const by1 = BigInt(by[1]);
|
|
156
|
-
// alt_bn128 expects the G2 pairs swapped: bx1 before bx0, by1 before by0
|
|
157
|
-
chunks.push(bigintTo32BytesBE(bx1), bigintTo32BytesBE(bx0), bigintTo32BytesBE(by1), bigintTo32BytesBE(by0));
|
|
158
|
-
const cx = BigInt(proof.pi_c[0]);
|
|
159
|
-
const cy = BigInt(proof.pi_c[1]);
|
|
160
|
-
chunks.push(bigintTo32BytesBE(cx), bigintTo32BytesBE(cy));
|
|
161
|
-
const out = new Uint8Array(32 * (2 + 4 + 2)); // 256
|
|
162
|
-
let offset = 0;
|
|
163
|
-
for (const c of chunks) {
|
|
164
|
-
out.set(c, offset);
|
|
165
|
-
offset += c.length;
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
166
7
|
}
|
|
167
|
-
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
const proofB = full.slice(64, 192);
|
|
179
|
-
const proofC = full.slice(192, 256);
|
|
180
|
-
return {
|
|
181
|
-
proofA: Array.from(proofA),
|
|
182
|
-
proofB: Array.from(proofB),
|
|
183
|
-
proofC: Array.from(proofC),
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
// -----------------------------------------------------------------------------
|
|
187
|
-
// Snarkjs Input Formatting
|
|
188
|
-
// -----------------------------------------------------------------------------
|
|
189
|
-
/**
|
|
190
|
-
* Convert TransactionCircuitInputs to the format expected by snarkjs.groth16.fullProve().
|
|
191
|
-
* All values are converted to strings (snarkjs expects string inputs for field elements).
|
|
192
|
-
*/
|
|
193
|
-
function formatInputsForSnarkjs(inputs) {
|
|
194
|
-
return {
|
|
195
|
-
// Public inputs
|
|
196
|
-
root: (0, poseidon_1.bytesToBigIntBE)(inputs.root).toString(),
|
|
197
|
-
publicAmount: i64ToField(inputs.publicAmount).toString(),
|
|
198
|
-
extDataHash: (0, poseidon_1.bytesToBigIntBE)(inputs.extDataHash).toString(),
|
|
199
|
-
mintAddress: (0, poseidon_1.pubkeyToField)(inputs.mintAddress).toString(),
|
|
200
|
-
inputNullifier: inputs.inputNullifiers.map((n) => (0, poseidon_1.bytesToBigIntBE)(n).toString()),
|
|
201
|
-
outputCommitment: inputs.outputCommitments.map((c) => (0, poseidon_1.bytesToBigIntBE)(c).toString()),
|
|
202
|
-
// Private inputs - Input UTXOs
|
|
203
|
-
inAmount: inputs.inAmount.map((a) => a.toString()),
|
|
204
|
-
inPubkey: inputs.inPubkey.map((p) => p.toString()),
|
|
205
|
-
inBlinding: inputs.inBlinding.map((b) => b.toString()),
|
|
206
|
-
inPathIndex: inputs.inPathIndex.map((i) => i.toString()),
|
|
207
|
-
inPathElements: inputs.inPathElements.map((path) => path.map((e) => e.toString())),
|
|
208
|
-
inPrivateKey: inputs.inPrivateKey.map((k) => k.toString()),
|
|
209
|
-
// Private inputs - Output UTXOs
|
|
210
|
-
outAmount: inputs.outAmount.map((a) => a.toString()),
|
|
211
|
-
outPubkey: inputs.outPubkey.map((p) => p.toString()),
|
|
212
|
-
outBlinding: inputs.outBlinding.map((b) => b.toString()),
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* Convert SwapCircuitInputs into the shape expected by
|
|
217
|
-
* snarkjs.groth16.fullProve() for swap.circom. Every value is emitted as a
|
|
218
|
-
* decimal string (or string array) because snarkjs only accepts field
|
|
219
|
-
* elements as strings.
|
|
220
|
-
*
|
|
221
|
-
* Mirrors `generateSwapProof` in
|
|
222
|
-
* relayer-server/src/controllers/swap.helpers.ts so SDK-side swap proofs
|
|
223
|
-
* verify against the same circuit the relayer uses.
|
|
224
|
-
*/
|
|
225
|
-
function formatSwapInputsForSnarkjs(inputs) {
|
|
226
|
-
return {
|
|
227
|
-
// Public inputs
|
|
228
|
-
sourceRoot: (0, poseidon_1.bytesToBigIntBE)(inputs.sourceRoot).toString(),
|
|
229
|
-
swapParamsHash: (0, poseidon_1.bytesToBigIntBE)(inputs.swapParamsHash).toString(),
|
|
230
|
-
extDataHash: (0, poseidon_1.bytesToBigIntBE)(inputs.extDataHash).toString(),
|
|
231
|
-
sourceMint: (0, poseidon_1.pubkeyToField)(inputs.sourceMint).toString(),
|
|
232
|
-
destMint: (0, poseidon_1.pubkeyToField)(inputs.destMint).toString(),
|
|
233
|
-
inputNullifier: inputs.inputNullifiers.map((n) => (0, poseidon_1.bytesToBigIntBE)(n).toString()),
|
|
234
|
-
changeCommitment: (0, poseidon_1.bytesToBigIntBE)(inputs.changeCommitment).toString(),
|
|
235
|
-
destCommitment: (0, poseidon_1.bytesToBigIntBE)(inputs.destCommitment).toString(),
|
|
236
|
-
swapAmount: inputs.swapAmount.toString(),
|
|
237
|
-
// Private inputs - Input UTXOs
|
|
238
|
-
inAmount: inputs.inAmount.map((a) => a.toString()),
|
|
239
|
-
inPubkey: inputs.inPubkey.map((p) => p.toString()),
|
|
240
|
-
inBlinding: inputs.inBlinding.map((b) => b.toString()),
|
|
241
|
-
inPathIndex: inputs.inPathIndex.map((i) => i.toString()),
|
|
242
|
-
inPathElements: inputs.inPathElements.map((path) => path.map((e) => e.toString())),
|
|
243
|
-
inPrivateKey: inputs.inPrivateKey.map((k) => k.toString()),
|
|
244
|
-
// Private inputs - Change UTXO
|
|
245
|
-
changeAmount: inputs.changeAmount.toString(),
|
|
246
|
-
changePubkey: inputs.changePubkey.toString(),
|
|
247
|
-
changeBlinding: inputs.changeBlinding.toString(),
|
|
248
|
-
// Private inputs - Destination UTXO
|
|
249
|
-
destAmount: inputs.destAmount.toString(),
|
|
250
|
-
destPubkey: inputs.destPubkey.toString(),
|
|
251
|
-
destBlinding: inputs.destBlinding.toString(),
|
|
252
|
-
// Swap params
|
|
253
|
-
minAmountOut: inputs.minAmountOut.toString(),
|
|
254
|
-
deadline: inputs.deadline.toString(),
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
// -----------------------------------------------------------------------------
|
|
258
|
-
// Swap Parameter Hashing
|
|
259
|
-
// -----------------------------------------------------------------------------
|
|
260
|
-
/**
|
|
261
|
-
* Compute the swap params hash that the swap circuit and on-chain program verify.
|
|
262
|
-
* Mirrors relayer-server/src/controllers/swap.helpers.ts `computeSwapParamsHash`.
|
|
263
|
-
*
|
|
264
|
-
* Circuit formula (swap.circom lines 293-307):
|
|
265
|
-
* mintPairHash = Poseidon(sourceMint, destMint)
|
|
266
|
-
* swapTermsHash = Poseidon(minAmountOut, deadline, destAmount)
|
|
267
|
-
* swapParamsHash = Poseidon(mintPairHash, swapTermsHash)
|
|
268
|
-
*
|
|
269
|
-
* @param sourceMint Source pool mint
|
|
270
|
-
* @param destMint Destination pool mint
|
|
271
|
-
* @param minAmountOut Minimum accepted output amount (slippage protected)
|
|
272
|
-
* @param deadline Unix timestamp deadline (i64, 0 = no deadline)
|
|
273
|
-
* @param destAmount Actual amount committed to destination UTXO (≥ minAmountOut -
|
|
274
|
-
* relayerFee). If omitted, defaults to minAmountOut.
|
|
275
|
-
*/
|
|
276
|
-
function computeSwapParamsHash(sourceMint, destMint, minAmountOut, deadline, destAmount) {
|
|
277
|
-
const srcField = (0, poseidon_1.pubkeyToField)(sourceMint);
|
|
278
|
-
const dstField = (0, poseidon_1.pubkeyToField)(destMint);
|
|
279
|
-
const mintPairHash = (0, poseidon_1.poseidon2)(srcField, dstField);
|
|
280
|
-
const dest = destAmount ?? minAmountOut;
|
|
281
|
-
const swapTermsHash = (0, poseidon_1.poseidon3)(minAmountOut, deadline, dest);
|
|
282
|
-
const paramsHash = (0, poseidon_1.poseidon2)(mintPairHash, swapTermsHash);
|
|
283
|
-
return (0, poseidon_1.bigIntToBytesBE)(paramsHash);
|
|
284
|
-
}
|
|
285
|
-
/**
|
|
286
|
-
* Compute the swap data hash committed on-chain for Jupiter instruction integrity.
|
|
287
|
-
* SHA-256 of the raw Jupiter swap instruction data bytes.
|
|
288
|
-
* Mirrors relayer-server/src/controllers/swap.helpers.ts `computeSwapDataHash`.
|
|
289
|
-
*/
|
|
290
|
-
function computeSwapDataHash(swapData) {
|
|
291
|
-
return (0, sha256_1.sha256)(swapData instanceof Buffer ? new Uint8Array(swapData) : swapData);
|
|
292
|
-
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
// Backward-compatible entry point. Proof responsibilities live in src/proofs.
|
|
18
|
+
__exportStar(require("./proofs/index.js"), exports);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { RawProof, TransactionProofStruct } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Turn a snarkjs Groth16 proof into 256 bytes:
|
|
4
|
+
* A(G1) | B(G2) | C(G1)
|
|
5
|
+
* where:
|
|
6
|
+
* A = (ax, ay) -> 64 bytes
|
|
7
|
+
* B = (bx1, bx0, by1, by0) -> 128 bytes (swapped pairs for alt_bn128)
|
|
8
|
+
* C = (cx, cy) -> 64 bytes
|
|
9
|
+
*
|
|
10
|
+
* Each field element is encoded as 32-byte BE to match the on-chain verifier.
|
|
11
|
+
* We ignore the extra projective/z components snarkjs keeps.
|
|
12
|
+
*/
|
|
13
|
+
export declare function packProofToBytes(proof: RawProof): Uint8Array;
|
|
14
|
+
/**
|
|
15
|
+
* Encode a snarkjs proof into the TransactionProofStruct format expected by the on-chain program.
|
|
16
|
+
*/
|
|
17
|
+
export declare function encodeSnarkjsProofToTransactionProof(proof: RawProof): TransactionProofStruct;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.packProofToBytes = packProofToBytes;
|
|
4
|
+
exports.encodeSnarkjsProofToTransactionProof = encodeSnarkjsProofToTransactionProof;
|
|
5
|
+
// -----------------------------------------------------------------------------
|
|
6
|
+
// Proof Packing
|
|
7
|
+
// -----------------------------------------------------------------------------
|
|
8
|
+
/**
|
|
9
|
+
* Convert bigint to 32-byte big-endian representation.
|
|
10
|
+
* The alt_bn128 Solana precompile (and ark-works via change_endianness) expect BE.
|
|
11
|
+
*/
|
|
12
|
+
function bigintTo32BytesBE(x) {
|
|
13
|
+
const out = new Uint8Array(32);
|
|
14
|
+
let v = x;
|
|
15
|
+
for (let i = 31; i >= 0; i--) {
|
|
16
|
+
out[i] = Number(v & 0xffn);
|
|
17
|
+
v >>= 8n;
|
|
18
|
+
}
|
|
19
|
+
return out;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Turn a snarkjs Groth16 proof into 256 bytes:
|
|
23
|
+
* A(G1) | B(G2) | C(G1)
|
|
24
|
+
* where:
|
|
25
|
+
* A = (ax, ay) -> 64 bytes
|
|
26
|
+
* B = (bx1, bx0, by1, by0) -> 128 bytes (swapped pairs for alt_bn128)
|
|
27
|
+
* C = (cx, cy) -> 64 bytes
|
|
28
|
+
*
|
|
29
|
+
* Each field element is encoded as 32-byte BE to match the on-chain verifier.
|
|
30
|
+
* We ignore the extra projective/z components snarkjs keeps.
|
|
31
|
+
*/
|
|
32
|
+
function packProofToBytes(proof) {
|
|
33
|
+
const chunks = [];
|
|
34
|
+
const ax = BigInt(proof.pi_a[0]);
|
|
35
|
+
const ay = BigInt(proof.pi_a[1]);
|
|
36
|
+
chunks.push(bigintTo32BytesBE(ax), bigintTo32BytesBE(ay));
|
|
37
|
+
const bx = proof.pi_b[0];
|
|
38
|
+
const by = proof.pi_b[1];
|
|
39
|
+
const bx0 = BigInt(bx[0]);
|
|
40
|
+
const bx1 = BigInt(bx[1]);
|
|
41
|
+
const by0 = BigInt(by[0]);
|
|
42
|
+
const by1 = BigInt(by[1]);
|
|
43
|
+
// alt_bn128 expects the G2 pairs swapped: bx1 before bx0, by1 before by0
|
|
44
|
+
chunks.push(bigintTo32BytesBE(bx1), bigintTo32BytesBE(bx0), bigintTo32BytesBE(by1), bigintTo32BytesBE(by0));
|
|
45
|
+
const cx = BigInt(proof.pi_c[0]);
|
|
46
|
+
const cy = BigInt(proof.pi_c[1]);
|
|
47
|
+
chunks.push(bigintTo32BytesBE(cx), bigintTo32BytesBE(cy));
|
|
48
|
+
const out = new Uint8Array(32 * (2 + 4 + 2)); // 256
|
|
49
|
+
let offset = 0;
|
|
50
|
+
for (const c of chunks) {
|
|
51
|
+
out.set(c, offset);
|
|
52
|
+
offset += c.length;
|
|
53
|
+
}
|
|
54
|
+
return out;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Encode a snarkjs proof into the TransactionProofStruct format expected by the on-chain program.
|
|
58
|
+
*/
|
|
59
|
+
function encodeSnarkjsProofToTransactionProof(proof) {
|
|
60
|
+
const full = packProofToBytes(proof);
|
|
61
|
+
if (full.length !== 256) {
|
|
62
|
+
throw new Error(`Expected 256 proof bytes, got ${full.length}`);
|
|
63
|
+
}
|
|
64
|
+
const proofA = full.slice(0, 64);
|
|
65
|
+
const proofB = full.slice(64, 192);
|
|
66
|
+
const proofC = full.slice(192, 256);
|
|
67
|
+
return {
|
|
68
|
+
proofA: Array.from(proofA),
|
|
69
|
+
proofB: Array.from(proofB),
|
|
70
|
+
proofC: Array.from(proofC),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { TransactionCircuitInputs } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Convert TransactionCircuitInputs to the format expected by snarkjs.groth16.fullProve().
|
|
4
|
+
* All values are converted to strings (snarkjs expects string inputs for field elements).
|
|
5
|
+
*/
|
|
6
|
+
export declare function formatInputsForSnarkjs(inputs: TransactionCircuitInputs): Record<string, any>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatInputsForSnarkjs = formatInputsForSnarkjs;
|
|
4
|
+
const poseidon_js_1 = require("../poseidon.js");
|
|
5
|
+
const transaction_js_1 = require("./transaction.js");
|
|
6
|
+
// -----------------------------------------------------------------------------
|
|
7
|
+
// Snarkjs Input Formatting
|
|
8
|
+
// -----------------------------------------------------------------------------
|
|
9
|
+
/**
|
|
10
|
+
* Convert TransactionCircuitInputs to the format expected by snarkjs.groth16.fullProve().
|
|
11
|
+
* All values are converted to strings (snarkjs expects string inputs for field elements).
|
|
12
|
+
*/
|
|
13
|
+
function formatInputsForSnarkjs(inputs) {
|
|
14
|
+
return {
|
|
15
|
+
// Public inputs
|
|
16
|
+
root: (0, poseidon_js_1.bytesToBigIntBE)(inputs.root).toString(),
|
|
17
|
+
publicAmount: (0, transaction_js_1.i64ToField)(inputs.publicAmount).toString(),
|
|
18
|
+
extDataHash: (0, poseidon_js_1.bytesToBigIntBE)(inputs.extDataHash).toString(),
|
|
19
|
+
mintAddress: (0, poseidon_js_1.pubkeyToField)(inputs.mintAddress).toString(),
|
|
20
|
+
inputNullifier: inputs.inputNullifiers.map((n) => (0, poseidon_js_1.bytesToBigIntBE)(n).toString()),
|
|
21
|
+
outputCommitment: inputs.outputCommitments.map((c) => (0, poseidon_js_1.bytesToBigIntBE)(c).toString()),
|
|
22
|
+
// Private inputs - Input UTXOs
|
|
23
|
+
inAmount: inputs.inAmount.map((a) => a.toString()),
|
|
24
|
+
inPubkey: inputs.inPubkey.map((p) => p.toString()),
|
|
25
|
+
inBlinding: inputs.inBlinding.map((b) => b.toString()),
|
|
26
|
+
inPathIndex: inputs.inPathIndex.map((i) => i.toString()),
|
|
27
|
+
inPathElements: inputs.inPathElements.map((path) => path.map((e) => e.toString())),
|
|
28
|
+
inPrivateKey: inputs.inPrivateKey.map((k) => k.toString()),
|
|
29
|
+
// Private inputs - Output UTXOs
|
|
30
|
+
outAmount: inputs.outAmount.map((a) => a.toString()),
|
|
31
|
+
outPubkey: inputs.outPubkey.map((p) => p.toString()),
|
|
32
|
+
outBlinding: inputs.outBlinding.map((b) => b.toString()),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./types.js"), exports);
|
|
18
|
+
__exportStar(require("./transaction.js"), exports);
|
|
19
|
+
__exportStar(require("./encoding.js"), exports);
|
|
20
|
+
__exportStar(require("./formatting.js"), exports);
|
|
21
|
+
__exportStar(require("./swap.js"), exports);
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { PublicKey } from "@solana/web3.js";
|
|
2
|
+
import type { InputUTXO, SerializedUTXO } from "../notes/model.js";
|
|
3
|
+
import type { ExtData, RawProof } from "./types.js";
|
|
4
|
+
/**
|
|
5
|
+
* Swap circuit inputs. Matches the signal shape declared by swap.circom's
|
|
6
|
+
* main component (see zk-circuits/swap.circom lines 208-238). Unlike the
|
|
7
|
+
* transaction circuit, the swap circuit distinguishes a "change" output
|
|
8
|
+
* (same mint as source) from a "dest" output (dest mint) and takes a
|
|
9
|
+
* swap-specific params hash and swapAmount alongside the usual inputs.
|
|
10
|
+
*/
|
|
11
|
+
export type SwapCircuitInputs = {
|
|
12
|
+
sourceRoot: Uint8Array;
|
|
13
|
+
swapParamsHash: Uint8Array;
|
|
14
|
+
extDataHash: Uint8Array;
|
|
15
|
+
sourceMint: PublicKey;
|
|
16
|
+
destMint: PublicKey;
|
|
17
|
+
inputNullifiers: [Uint8Array, Uint8Array];
|
|
18
|
+
changeCommitment: Uint8Array;
|
|
19
|
+
destCommitment: Uint8Array;
|
|
20
|
+
swapAmount: bigint;
|
|
21
|
+
inAmount: [bigint, bigint];
|
|
22
|
+
inPubkey: [bigint, bigint];
|
|
23
|
+
inBlinding: [bigint, bigint];
|
|
24
|
+
inPathIndex: [number, number];
|
|
25
|
+
inPathElements: [bigint[], bigint[]];
|
|
26
|
+
inPrivateKey: [bigint, bigint];
|
|
27
|
+
changeAmount: bigint;
|
|
28
|
+
changePubkey: bigint;
|
|
29
|
+
changeBlinding: bigint;
|
|
30
|
+
destAmount: bigint;
|
|
31
|
+
destPubkey: bigint;
|
|
32
|
+
destBlinding: bigint;
|
|
33
|
+
minAmountOut: bigint;
|
|
34
|
+
deadline: bigint;
|
|
35
|
+
};
|
|
36
|
+
/** Proof builder accepted by SDK-side private swap flows. */
|
|
37
|
+
export type SwapProofBuilder = (inputs: SwapCircuitInputs) => Promise<RawProof>;
|
|
38
|
+
/**
|
|
39
|
+
* Prepare the exact witness/public inputs used by the relayer's swap circuit.
|
|
40
|
+
* Output 0 must be source-mint change and output 1 the destination-mint note.
|
|
41
|
+
*/
|
|
42
|
+
export declare function prepareSwapInputs(params: {
|
|
43
|
+
inputUTXOs: [InputUTXO, InputUTXO];
|
|
44
|
+
changeUTXO: SerializedUTXO;
|
|
45
|
+
destUTXO: SerializedUTXO;
|
|
46
|
+
sourceRoot: Uint8Array;
|
|
47
|
+
sourceMint: PublicKey;
|
|
48
|
+
destMint: PublicKey;
|
|
49
|
+
swapAmount: bigint;
|
|
50
|
+
minAmountOut: bigint;
|
|
51
|
+
deadline: bigint;
|
|
52
|
+
extData: ExtData;
|
|
53
|
+
}): SwapCircuitInputs;
|
|
54
|
+
/**
|
|
55
|
+
* Convert SwapCircuitInputs into the shape expected by
|
|
56
|
+
* snarkjs.groth16.fullProve() for swap.circom. Every value is emitted as a
|
|
57
|
+
* decimal string (or string array) because snarkjs only accepts field
|
|
58
|
+
* elements as strings.
|
|
59
|
+
*
|
|
60
|
+
* Mirrors `generateSwapProof` in
|
|
61
|
+
* relayer-server/src/controllers/swap.helpers.ts so SDK-side swap proofs
|
|
62
|
+
* verify against the same circuit the relayer uses.
|
|
63
|
+
*/
|
|
64
|
+
export declare function formatSwapInputsForSnarkjs(inputs: SwapCircuitInputs): Record<string, any>;
|
|
65
|
+
/**
|
|
66
|
+
* Compute the swap params hash that the swap circuit and on-chain program verify.
|
|
67
|
+
* Mirrors relayer-server/src/controllers/swap.helpers.ts `computeSwapParamsHash`.
|
|
68
|
+
*
|
|
69
|
+
* Circuit formula (swap.circom lines 293-307):
|
|
70
|
+
* mintPairHash = Poseidon(sourceMint, destMint)
|
|
71
|
+
* swapTermsHash = Poseidon(minAmountOut, deadline, destAmount)
|
|
72
|
+
* swapParamsHash = Poseidon(mintPairHash, swapTermsHash)
|
|
73
|
+
*
|
|
74
|
+
* @param sourceMint Source pool mint
|
|
75
|
+
* @param destMint Destination pool mint
|
|
76
|
+
* @param minAmountOut Minimum accepted output amount (slippage protected)
|
|
77
|
+
* @param deadline Positive Unix timestamp deadline (the program rejects 0)
|
|
78
|
+
* @param destAmount Actual amount committed to destination UTXO (≥ minAmountOut -
|
|
79
|
+
* relayerFee). If omitted, defaults to minAmountOut.
|
|
80
|
+
*/
|
|
81
|
+
export declare function computeSwapParamsHash(sourceMint: PublicKey, destMint: PublicKey, minAmountOut: bigint, deadline: bigint, destAmount?: bigint): Uint8Array;
|
|
82
|
+
/**
|
|
83
|
+
* Compute the swap data hash committed on-chain for Jupiter instruction integrity.
|
|
84
|
+
* SHA-256 of the raw Jupiter swap instruction data bytes.
|
|
85
|
+
* Mirrors relayer-server/src/controllers/swap.helpers.ts `computeSwapDataHash`.
|
|
86
|
+
*/
|
|
87
|
+
export declare function computeSwapDataHash(swapData: Uint8Array | Buffer): Uint8Array;
|