@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
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { randomBytes } from "../random.js";
|
|
2
|
+
import { BN254_FR_MODULUS, bigIntToBytesBE, bytesToBigIntBE, poseidon1, poseidon4, pubkeyToField, } from "../poseidon.js";
|
|
3
|
+
// -----------------------------------------------------------------------------
|
|
4
|
+
// Keypair Functions
|
|
5
|
+
// -----------------------------------------------------------------------------
|
|
6
|
+
/**
|
|
7
|
+
* Generate a random keypair.
|
|
8
|
+
* Private key is a random 32-byte scalar.
|
|
9
|
+
* Public key is derived via Poseidon: pubkey = Poseidon(privateKey)
|
|
10
|
+
*/
|
|
11
|
+
export function generateKeypair() {
|
|
12
|
+
const privateKeyBytes = new Uint8Array(randomBytes(32));
|
|
13
|
+
const privateKey = bytesToBigIntBE(privateKeyBytes) % BN254_FR_MODULUS;
|
|
14
|
+
const publicKey = derivePublicKey(privateKey);
|
|
15
|
+
return { privateKey, publicKey };
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Derive public key from private key.
|
|
19
|
+
* Matches circuit's Keypair template: publicKey = Poseidon(privateKey)
|
|
20
|
+
*/
|
|
21
|
+
export function derivePublicKey(privateKey) {
|
|
22
|
+
return poseidon1(privateKey);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Create keypair from a known private key.
|
|
26
|
+
*/
|
|
27
|
+
export function keypairFromPrivateKey(privateKey) {
|
|
28
|
+
return {
|
|
29
|
+
privateKey: privateKey % BN254_FR_MODULUS,
|
|
30
|
+
publicKey: derivePublicKey(privateKey % BN254_FR_MODULUS),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
// -----------------------------------------------------------------------------
|
|
34
|
+
// UTXO Commitment Functions
|
|
35
|
+
// -----------------------------------------------------------------------------
|
|
36
|
+
/**
|
|
37
|
+
* Compute UTXO commitment.
|
|
38
|
+
* Matches circuit's UTXOCommitment template:
|
|
39
|
+
* commitment = Poseidon(amount, pubkey, blinding, mintAddress)
|
|
40
|
+
*/
|
|
41
|
+
export function commitUTXO(utxo) {
|
|
42
|
+
const commitment = poseidon4(utxo.amount, utxo.pubkey, utxo.blinding, utxo.mintAddress);
|
|
43
|
+
return bigIntToBytesBE(commitment);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Create a random UTXO with the given parameters.
|
|
47
|
+
*/
|
|
48
|
+
export function createUTXO(params) {
|
|
49
|
+
const blindingBytes = new Uint8Array(randomBytes(32));
|
|
50
|
+
const blinding = bytesToBigIntBE(blindingBytes) % BN254_FR_MODULUS;
|
|
51
|
+
const utxo = {
|
|
52
|
+
amount: params.amount,
|
|
53
|
+
pubkey: params.pubkey,
|
|
54
|
+
blinding,
|
|
55
|
+
mintAddress: pubkeyToField(params.mintAddress),
|
|
56
|
+
};
|
|
57
|
+
const commitment = commitUTXO(utxo);
|
|
58
|
+
return {
|
|
59
|
+
...utxo,
|
|
60
|
+
commitment,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Create a UTXO with a specified private key (for owned UTXOs).
|
|
65
|
+
*/
|
|
66
|
+
export function createOwnedUTXO(params) {
|
|
67
|
+
const keypair = keypairFromPrivateKey(params.privateKey);
|
|
68
|
+
const utxo = createUTXO({
|
|
69
|
+
amount: params.amount,
|
|
70
|
+
pubkey: keypair.publicKey,
|
|
71
|
+
mintAddress: params.mintAddress,
|
|
72
|
+
});
|
|
73
|
+
return {
|
|
74
|
+
...utxo,
|
|
75
|
+
privateKey: keypair.privateKey,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Create a zero UTXO (for deposits where no input exists).
|
|
80
|
+
* Zero UTXOs have amount=0 and are used as placeholders in 2-in-2-out transactions.
|
|
81
|
+
*/
|
|
82
|
+
export function createZeroUTXO(pubkey, mintAddress) {
|
|
83
|
+
return createUTXO({
|
|
84
|
+
amount: 0n,
|
|
85
|
+
pubkey,
|
|
86
|
+
mintAddress,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Create a zero UTXO with private key (for owned zero UTXOs).
|
|
91
|
+
*/
|
|
92
|
+
export function createOwnedZeroUTXO(privateKey, mintAddress) {
|
|
93
|
+
const keypair = keypairFromPrivateKey(privateKey);
|
|
94
|
+
const utxo = createZeroUTXO(keypair.publicKey, mintAddress);
|
|
95
|
+
return {
|
|
96
|
+
...utxo,
|
|
97
|
+
privateKey: keypair.privateKey,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { InputUTXO, SerializedUTXO } from "./model.js";
|
|
2
|
+
/**
|
|
3
|
+
* Compute signature for nullifier derivation.
|
|
4
|
+
* Matches circuit's Signature template:
|
|
5
|
+
* signature = Poseidon(privateKey, commitment, pathIndex)
|
|
6
|
+
*/
|
|
7
|
+
export declare function computeSignature(privateKey: bigint, commitment: bigint, pathIndex: bigint): bigint;
|
|
8
|
+
/**
|
|
9
|
+
* Derive nullifier for a UTXO.
|
|
10
|
+
* Matches circuit's UTXONullifier template:
|
|
11
|
+
* signature = Poseidon(privateKey, commitment, pathIndex)
|
|
12
|
+
* nullifier = Poseidon(commitment, pathIndex, signature)
|
|
13
|
+
*
|
|
14
|
+
* The signature-based nullifier ensures only the private key holder can spend.
|
|
15
|
+
*/
|
|
16
|
+
export declare function deriveNullifier(utxo: SerializedUTXO, pathIndex: number, privateKey: bigint): Uint8Array;
|
|
17
|
+
/**
|
|
18
|
+
* Convert InputUTXO to the format expected by the circuit.
|
|
19
|
+
*/
|
|
20
|
+
export declare function inputUTXOToCircuitFormat(input: InputUTXO): {
|
|
21
|
+
amount: bigint;
|
|
22
|
+
pubkey: bigint;
|
|
23
|
+
blinding: bigint;
|
|
24
|
+
pathElements: bigint[];
|
|
25
|
+
pathIndex: number;
|
|
26
|
+
privateKey: bigint;
|
|
27
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { BN254_FR_MODULUS, bigIntToBytesBE, bytesToBigIntBE, poseidon3, } from "../poseidon.js";
|
|
2
|
+
// -----------------------------------------------------------------------------
|
|
3
|
+
// Nullifier Functions
|
|
4
|
+
// -----------------------------------------------------------------------------
|
|
5
|
+
/**
|
|
6
|
+
* Compute signature for nullifier derivation.
|
|
7
|
+
* Matches circuit's Signature template:
|
|
8
|
+
* signature = Poseidon(privateKey, commitment, pathIndex)
|
|
9
|
+
*/
|
|
10
|
+
export function computeSignature(privateKey, commitment, pathIndex) {
|
|
11
|
+
return poseidon3(privateKey, commitment, pathIndex);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Derive nullifier for a UTXO.
|
|
15
|
+
* Matches circuit's UTXONullifier template:
|
|
16
|
+
* signature = Poseidon(privateKey, commitment, pathIndex)
|
|
17
|
+
* nullifier = Poseidon(commitment, pathIndex, signature)
|
|
18
|
+
*
|
|
19
|
+
* The signature-based nullifier ensures only the private key holder can spend.
|
|
20
|
+
*/
|
|
21
|
+
export function deriveNullifier(utxo, pathIndex, privateKey) {
|
|
22
|
+
const commitment = bytesToBigIntBE(utxo.commitment) % BN254_FR_MODULUS;
|
|
23
|
+
const pathIndexField = BigInt(pathIndex) % BN254_FR_MODULUS;
|
|
24
|
+
const signature = computeSignature(privateKey, commitment, pathIndexField);
|
|
25
|
+
const nullifier = poseidon3(commitment, pathIndexField, signature);
|
|
26
|
+
return bigIntToBytesBE(nullifier);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Convert InputUTXO to the format expected by the circuit.
|
|
30
|
+
*/
|
|
31
|
+
export function inputUTXOToCircuitFormat(input) {
|
|
32
|
+
return {
|
|
33
|
+
amount: input.amount,
|
|
34
|
+
pubkey: input.pubkey,
|
|
35
|
+
blinding: input.blinding,
|
|
36
|
+
pathElements: input.pathElements.map((e) => bytesToBigIntBE(e) % BN254_FR_MODULUS),
|
|
37
|
+
pathIndex: input.pathIndex,
|
|
38
|
+
privateKey: input.privateKey,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { DecryptedNote } from "./mailbox.js";
|
|
2
|
+
/**
|
|
3
|
+
* Fetch all encrypted notes for a wallet from the relayer's Blind Mailbox endpoint
|
|
4
|
+
* and decrypt them using the wallet's secret key.
|
|
5
|
+
*
|
|
6
|
+
* @param walletPublicKey Base58 wallet address used to query the relayer
|
|
7
|
+
* @param walletSecretKey Full 64-byte keypair.secretKey for decryption
|
|
8
|
+
* @param relayerUrl Relayer base URL (e.g. "https://relay.veilo.app")
|
|
9
|
+
*/
|
|
10
|
+
export declare function fetchAndDecryptNotes(walletPublicKey: string, walletSecretKey: Uint8Array, relayerUrl: string): Promise<DecryptedNote[]>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { decryptBlindMailboxNote } from "./mailbox.js";
|
|
2
|
+
/**
|
|
3
|
+
* Fetch all encrypted notes for a wallet from the relayer's Blind Mailbox endpoint
|
|
4
|
+
* and decrypt them using the wallet's secret key.
|
|
5
|
+
*
|
|
6
|
+
* @param walletPublicKey Base58 wallet address used to query the relayer
|
|
7
|
+
* @param walletSecretKey Full 64-byte keypair.secretKey for decryption
|
|
8
|
+
* @param relayerUrl Relayer base URL (e.g. "https://relay.veilo.app")
|
|
9
|
+
*/
|
|
10
|
+
export async function fetchAndDecryptNotes(walletPublicKey, walletSecretKey, relayerUrl) {
|
|
11
|
+
const resp = await fetch(`${relayerUrl}/api/notes?recipientPublicKey=${walletPublicKey}`);
|
|
12
|
+
if (!resp.ok) {
|
|
13
|
+
throw new Error(`fetchAndDecryptNotes: ${resp.status} ${resp.statusText}`);
|
|
14
|
+
}
|
|
15
|
+
const { notes } = (await resp.json());
|
|
16
|
+
const results = [];
|
|
17
|
+
for (const note of notes) {
|
|
18
|
+
try {
|
|
19
|
+
const epk = Buffer.from(note.ephemeralPublicKey, "base64");
|
|
20
|
+
const decrypted = decryptBlindMailboxNote(walletSecretKey, new Uint8Array(epk), note.encryptedBlob);
|
|
21
|
+
results.push(decrypted);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
// Note not for this key or corrupted — skip silently
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return results;
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { PublicKey } from "@solana/web3.js";
|
|
2
|
+
/** Poseidon hash function type from circomlibjs. */
|
|
3
|
+
export type PoseidonFn = ((inputs: bigint[]) => any) & {
|
|
4
|
+
F: {
|
|
5
|
+
toObject: (e: any) => bigint;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
/** Initialize the Poseidon hash instance. Must be called once before using any UTXO/merkle/proof helpers. */
|
|
9
|
+
export declare function initPoseidon(): Promise<void>;
|
|
10
|
+
/** Get the initialized Poseidon instance. Throws if `initPoseidon()` has not been called. */
|
|
11
|
+
export declare function getPoseidon(): PoseidonFn;
|
|
12
|
+
/** The BN254 (alt_bn128) scalar field modulus. All Poseidon outputs are reduced modulo this value. */
|
|
13
|
+
export declare const BN254_FR_MODULUS: bigint;
|
|
14
|
+
/** Convert a big-endian byte array to a bigint. */
|
|
15
|
+
export declare function bytesToBigIntBE(bytes: Uint8Array): bigint;
|
|
16
|
+
/** Convert a bigint to a 32-byte big-endian array. */
|
|
17
|
+
export declare function bigIntToBytesBE(x: bigint): Uint8Array;
|
|
18
|
+
/** Convert ffjavascript field element → bigint safely */
|
|
19
|
+
export declare function frToBigInt(fe: any): bigint;
|
|
20
|
+
/** Poseidon hash with 1 input - used for keypair derivation: pubkey = Poseidon(privateKey) */
|
|
21
|
+
export declare function poseidon1(a: bigint): bigint;
|
|
22
|
+
/** Poseidon hash with 2 inputs */
|
|
23
|
+
export declare function poseidon2(a: bigint, b: bigint): bigint;
|
|
24
|
+
/** Poseidon hash with 3 inputs - used for signature: Poseidon(privateKey, commitment, pathIndex) */
|
|
25
|
+
export declare function poseidon3(a: bigint, b: bigint, c: bigint): bigint;
|
|
26
|
+
/** Poseidon hash with 4 inputs - used for UTXO commitment: Poseidon(amount, pubkey, blinding, mintAddress) */
|
|
27
|
+
export declare function poseidon4(a: bigint, b: bigint, c: bigint, d: bigint): bigint;
|
|
28
|
+
/** Convert a Solana PublicKey to a BN254 field element */
|
|
29
|
+
export declare function pubkeyToField(pubkey: PublicKey): bigint;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Program, Idl, Wallet } from "@coral-xyz/anchor";
|
|
2
|
+
import { Connection, PublicKey } from "@solana/web3.js";
|
|
3
|
+
export declare const PRIVACY_POOL_IDL: Idl;
|
|
4
|
+
/** Deployed program ID extracted from the bundled IDL. */
|
|
5
|
+
export declare const PRIVACY_POOL_PROGRAM_ID: PublicKey;
|
|
6
|
+
/**
|
|
7
|
+
* Create an Anchor `Program` instance for the Veilo Privacy Pool.
|
|
8
|
+
*
|
|
9
|
+
* @param connection Solana RPC connection
|
|
10
|
+
* @param wallet Anchor-compatible wallet (must implement `publicKey` and `signTransaction`)
|
|
11
|
+
* @param opts Optional commitment level (default: "confirmed")
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { createVeiloProgram } from "@veilo/sdk-core";
|
|
16
|
+
* import { Connection } from "@solana/web3.js";
|
|
17
|
+
*
|
|
18
|
+
* const program = createVeiloProgram(
|
|
19
|
+
* new Connection("https://api.devnet.solana.com"),
|
|
20
|
+
* wallet,
|
|
21
|
+
* );
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function createVeiloProgram(connection: Connection, wallet: Wallet, opts?: {
|
|
25
|
+
commitment?: "processed" | "confirmed" | "finalized";
|
|
26
|
+
}): Program;
|
|
27
|
+
/**
|
|
28
|
+
* Create a `Program` for reading on-chain accounts, with no wallet.
|
|
29
|
+
*
|
|
30
|
+
* The shield path never signs, so requiring a `Wallet` just to decode a
|
|
31
|
+
* `MerkleTreeAccount` would force integrators to invent a dummy one. This is
|
|
32
|
+
* safe for `program.account.*.fetch` and the coders; anything that would submit
|
|
33
|
+
* a transaction will fail, which is the intent.
|
|
34
|
+
*/
|
|
35
|
+
export declare function createReadonlyVeiloProgram(connection: Connection, opts?: {
|
|
36
|
+
commitment?: "processed" | "confirmed" | "finalized";
|
|
37
|
+
}): Program;
|
package/dist/esm/program.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Program, AnchorProvider } from "@coral-xyz/anchor";
|
|
2
2
|
import { PublicKey } from "@solana/web3.js";
|
|
3
|
-
import IDL_JSON from "./idl/privacy_pool.
|
|
3
|
+
import IDL_JSON from "./idl/privacy_pool.js";
|
|
4
4
|
// Re-export so consumers can access the raw IDL if needed
|
|
5
5
|
export const PRIVACY_POOL_IDL = IDL_JSON;
|
|
6
6
|
/** Deployed program ID extracted from the bundled IDL. */
|
|
@@ -29,3 +29,25 @@ export function createVeiloProgram(connection, wallet, opts) {
|
|
|
29
29
|
});
|
|
30
30
|
return new Program(PRIVACY_POOL_IDL, provider);
|
|
31
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Create a `Program` for reading on-chain accounts, with no wallet.
|
|
34
|
+
*
|
|
35
|
+
* The shield path never signs, so requiring a `Wallet` just to decode a
|
|
36
|
+
* `MerkleTreeAccount` would force integrators to invent a dummy one. This is
|
|
37
|
+
* safe for `program.account.*.fetch` and the coders; anything that would submit
|
|
38
|
+
* a transaction will fail, which is the intent.
|
|
39
|
+
*/
|
|
40
|
+
export function createReadonlyVeiloProgram(connection, opts) {
|
|
41
|
+
const provider = new AnchorProvider(connection,
|
|
42
|
+
// No signing surface: reads only.
|
|
43
|
+
{
|
|
44
|
+
publicKey: PublicKey.default,
|
|
45
|
+
signTransaction: () => {
|
|
46
|
+
throw new Error("createReadonlyVeiloProgram: this program cannot sign");
|
|
47
|
+
},
|
|
48
|
+
signAllTransactions: () => {
|
|
49
|
+
throw new Error("createReadonlyVeiloProgram: this program cannot sign");
|
|
50
|
+
},
|
|
51
|
+
}, { commitment: opts?.commitment ?? "confirmed" });
|
|
52
|
+
return new Program(PRIVACY_POOL_IDL, provider);
|
|
53
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./proofs/index.js";
|
package/dist/esm/proof.js
CHANGED
|
@@ -1,281 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { deriveNullifier } from "./utxo";
|
|
4
|
-
// -----------------------------------------------------------------------------
|
|
5
|
-
// ExtData Hash Computation
|
|
6
|
-
// -----------------------------------------------------------------------------
|
|
7
|
-
/**
|
|
8
|
-
* Compute the external data hash.
|
|
9
|
-
* Matches on-chain computation:
|
|
10
|
-
* hash1 = Poseidon(recipient, relayer)
|
|
11
|
-
* hash2 = Poseidon(fee, refund)
|
|
12
|
-
* extDataHash = Poseidon(hash1, hash2, claimant)
|
|
13
|
-
*/
|
|
14
|
-
export function computeExtDataHash(extData) {
|
|
15
|
-
const recipientField = pubkeyToField(extData.recipient);
|
|
16
|
-
const relayerField = pubkeyToField(extData.relayer);
|
|
17
|
-
const feeField = extData.fee % BN254_FR_MODULUS;
|
|
18
|
-
const refundField = extData.refund % BN254_FR_MODULUS;
|
|
19
|
-
const claimantField = pubkeyToField(extData.claimant);
|
|
20
|
-
const hash1 = poseidon2(recipientField, relayerField);
|
|
21
|
-
const hash2 = poseidon2(feeField, refundField);
|
|
22
|
-
const finalHash = poseidon3(hash1, hash2, claimantField);
|
|
23
|
-
return bigIntToBytesBE(finalHash);
|
|
24
|
-
}
|
|
25
|
-
// -----------------------------------------------------------------------------
|
|
26
|
-
// Circuit Input Preparation
|
|
27
|
-
// -----------------------------------------------------------------------------
|
|
28
|
-
/**
|
|
29
|
-
* Convert i64 to field element (handles negative via modular arithmetic).
|
|
30
|
-
* For negative values, we add the field modulus to get the equivalent positive representation.
|
|
31
|
-
*/
|
|
32
|
-
export function i64ToField(value) {
|
|
33
|
-
if (value >= 0n) {
|
|
34
|
-
return value % BN254_FR_MODULUS;
|
|
35
|
-
}
|
|
36
|
-
return (BN254_FR_MODULUS + value) % BN254_FR_MODULUS;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Prepare transaction circuit inputs from high-level parameters.
|
|
40
|
-
* This converts the SDK types into the format expected by the circuit.
|
|
41
|
-
*/
|
|
42
|
-
export function prepareTransactionInputs(params) {
|
|
43
|
-
const { inputUTXOs, outputUTXOs, root, publicAmount, extData, mintAddress } = params;
|
|
44
|
-
const extDataHash = computeExtDataHash(extData);
|
|
45
|
-
const mintField = pubkeyToField(mintAddress);
|
|
46
|
-
// Prepare input UTXO data
|
|
47
|
-
const inAmount = [
|
|
48
|
-
inputUTXOs[0].amount,
|
|
49
|
-
inputUTXOs[1].amount,
|
|
50
|
-
];
|
|
51
|
-
const inPubkey = [
|
|
52
|
-
inputUTXOs[0].pubkey,
|
|
53
|
-
inputUTXOs[1].pubkey,
|
|
54
|
-
];
|
|
55
|
-
const inBlinding = [
|
|
56
|
-
inputUTXOs[0].blinding,
|
|
57
|
-
inputUTXOs[1].blinding,
|
|
58
|
-
];
|
|
59
|
-
const inPathIndex = [
|
|
60
|
-
inputUTXOs[0].pathIndex,
|
|
61
|
-
inputUTXOs[1].pathIndex,
|
|
62
|
-
];
|
|
63
|
-
const inPathElements = [
|
|
64
|
-
inputUTXOs[0].pathElements.map((e) => bytesToBigIntBE(e) % BN254_FR_MODULUS),
|
|
65
|
-
inputUTXOs[1].pathElements.map((e) => bytesToBigIntBE(e) % BN254_FR_MODULUS),
|
|
66
|
-
];
|
|
67
|
-
const inPrivateKey = [
|
|
68
|
-
inputUTXOs[0].privateKey,
|
|
69
|
-
inputUTXOs[1].privateKey,
|
|
70
|
-
];
|
|
71
|
-
// Prepare output UTXO data
|
|
72
|
-
const outAmount = [
|
|
73
|
-
outputUTXOs[0].amount,
|
|
74
|
-
outputUTXOs[1].amount,
|
|
75
|
-
];
|
|
76
|
-
const outPubkey = [
|
|
77
|
-
outputUTXOs[0].pubkey,
|
|
78
|
-
outputUTXOs[1].pubkey,
|
|
79
|
-
];
|
|
80
|
-
const outBlinding = [
|
|
81
|
-
outputUTXOs[0].blinding,
|
|
82
|
-
outputUTXOs[1].blinding,
|
|
83
|
-
];
|
|
84
|
-
// Derive nullifiers for input UTXOs
|
|
85
|
-
const inputNullifiers = [
|
|
86
|
-
deriveNullifier(inputUTXOs[0], inputUTXOs[0].pathIndex, inputUTXOs[0].privateKey),
|
|
87
|
-
deriveNullifier(inputUTXOs[1], inputUTXOs[1].pathIndex, inputUTXOs[1].privateKey),
|
|
88
|
-
];
|
|
89
|
-
return {
|
|
90
|
-
root,
|
|
91
|
-
publicAmount,
|
|
92
|
-
extDataHash,
|
|
93
|
-
mintAddress,
|
|
94
|
-
inputNullifiers,
|
|
95
|
-
outputCommitments: [outputUTXOs[0].commitment, outputUTXOs[1].commitment],
|
|
96
|
-
inAmount,
|
|
97
|
-
inPubkey,
|
|
98
|
-
inBlinding,
|
|
99
|
-
inPathIndex,
|
|
100
|
-
inPathElements,
|
|
101
|
-
inPrivateKey,
|
|
102
|
-
outAmount,
|
|
103
|
-
outPubkey,
|
|
104
|
-
outBlinding,
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
// -----------------------------------------------------------------------------
|
|
108
|
-
// Proof Packing
|
|
109
|
-
// -----------------------------------------------------------------------------
|
|
110
|
-
/**
|
|
111
|
-
* Convert bigint to 32-byte big-endian representation.
|
|
112
|
-
* The alt_bn128 Solana precompile (and ark-works via change_endianness) expect BE.
|
|
113
|
-
*/
|
|
114
|
-
function bigintTo32BytesBE(x) {
|
|
115
|
-
const out = new Uint8Array(32);
|
|
116
|
-
let v = x;
|
|
117
|
-
for (let i = 31; i >= 0; i--) {
|
|
118
|
-
out[i] = Number(v & 0xffn);
|
|
119
|
-
v >>= 8n;
|
|
120
|
-
}
|
|
121
|
-
return out;
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Turn a snarkjs Groth16 proof into 256 bytes:
|
|
125
|
-
* A(G1) | B(G2) | C(G1)
|
|
126
|
-
* where:
|
|
127
|
-
* A = (ax, ay) -> 64 bytes
|
|
128
|
-
* B = (bx1, bx0, by1, by0) -> 128 bytes (swapped pairs for alt_bn128)
|
|
129
|
-
* C = (cx, cy) -> 64 bytes
|
|
130
|
-
*
|
|
131
|
-
* Each field element is encoded as 32-byte BE to match the on-chain verifier.
|
|
132
|
-
* We ignore the extra projective/z components snarkjs keeps.
|
|
133
|
-
*/
|
|
134
|
-
export function packProofToBytes(proof) {
|
|
135
|
-
const chunks = [];
|
|
136
|
-
const ax = BigInt(proof.pi_a[0]);
|
|
137
|
-
const ay = BigInt(proof.pi_a[1]);
|
|
138
|
-
chunks.push(bigintTo32BytesBE(ax), bigintTo32BytesBE(ay));
|
|
139
|
-
const bx = proof.pi_b[0];
|
|
140
|
-
const by = proof.pi_b[1];
|
|
141
|
-
const bx0 = BigInt(bx[0]);
|
|
142
|
-
const bx1 = BigInt(bx[1]);
|
|
143
|
-
const by0 = BigInt(by[0]);
|
|
144
|
-
const by1 = BigInt(by[1]);
|
|
145
|
-
// alt_bn128 expects the G2 pairs swapped: bx1 before bx0, by1 before by0
|
|
146
|
-
chunks.push(bigintTo32BytesBE(bx1), bigintTo32BytesBE(bx0), bigintTo32BytesBE(by1), bigintTo32BytesBE(by0));
|
|
147
|
-
const cx = BigInt(proof.pi_c[0]);
|
|
148
|
-
const cy = BigInt(proof.pi_c[1]);
|
|
149
|
-
chunks.push(bigintTo32BytesBE(cx), bigintTo32BytesBE(cy));
|
|
150
|
-
const out = new Uint8Array(32 * (2 + 4 + 2)); // 256
|
|
151
|
-
let offset = 0;
|
|
152
|
-
for (const c of chunks) {
|
|
153
|
-
out.set(c, offset);
|
|
154
|
-
offset += c.length;
|
|
155
|
-
}
|
|
156
|
-
return out;
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Encode a snarkjs proof into the TransactionProofStruct format expected by the on-chain program.
|
|
160
|
-
*/
|
|
161
|
-
export function encodeSnarkjsProofToTransactionProof(proof) {
|
|
162
|
-
const full = packProofToBytes(proof);
|
|
163
|
-
if (full.length !== 256) {
|
|
164
|
-
throw new Error(`Expected 256 proof bytes, got ${full.length}`);
|
|
165
|
-
}
|
|
166
|
-
const proofA = full.slice(0, 64);
|
|
167
|
-
const proofB = full.slice(64, 192);
|
|
168
|
-
const proofC = full.slice(192, 256);
|
|
169
|
-
return {
|
|
170
|
-
proofA: Array.from(proofA),
|
|
171
|
-
proofB: Array.from(proofB),
|
|
172
|
-
proofC: Array.from(proofC),
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
// -----------------------------------------------------------------------------
|
|
176
|
-
// Snarkjs Input Formatting
|
|
177
|
-
// -----------------------------------------------------------------------------
|
|
178
|
-
/**
|
|
179
|
-
* Convert TransactionCircuitInputs to the format expected by snarkjs.groth16.fullProve().
|
|
180
|
-
* All values are converted to strings (snarkjs expects string inputs for field elements).
|
|
181
|
-
*/
|
|
182
|
-
export function formatInputsForSnarkjs(inputs) {
|
|
183
|
-
return {
|
|
184
|
-
// Public inputs
|
|
185
|
-
root: bytesToBigIntBE(inputs.root).toString(),
|
|
186
|
-
publicAmount: i64ToField(inputs.publicAmount).toString(),
|
|
187
|
-
extDataHash: bytesToBigIntBE(inputs.extDataHash).toString(),
|
|
188
|
-
mintAddress: pubkeyToField(inputs.mintAddress).toString(),
|
|
189
|
-
inputNullifier: inputs.inputNullifiers.map((n) => bytesToBigIntBE(n).toString()),
|
|
190
|
-
outputCommitment: inputs.outputCommitments.map((c) => bytesToBigIntBE(c).toString()),
|
|
191
|
-
// Private inputs - Input UTXOs
|
|
192
|
-
inAmount: inputs.inAmount.map((a) => a.toString()),
|
|
193
|
-
inPubkey: inputs.inPubkey.map((p) => p.toString()),
|
|
194
|
-
inBlinding: inputs.inBlinding.map((b) => b.toString()),
|
|
195
|
-
inPathIndex: inputs.inPathIndex.map((i) => i.toString()),
|
|
196
|
-
inPathElements: inputs.inPathElements.map((path) => path.map((e) => e.toString())),
|
|
197
|
-
inPrivateKey: inputs.inPrivateKey.map((k) => k.toString()),
|
|
198
|
-
// Private inputs - Output UTXOs
|
|
199
|
-
outAmount: inputs.outAmount.map((a) => a.toString()),
|
|
200
|
-
outPubkey: inputs.outPubkey.map((p) => p.toString()),
|
|
201
|
-
outBlinding: inputs.outBlinding.map((b) => b.toString()),
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
* Convert SwapCircuitInputs into the shape expected by
|
|
206
|
-
* snarkjs.groth16.fullProve() for swap.circom. Every value is emitted as a
|
|
207
|
-
* decimal string (or string array) because snarkjs only accepts field
|
|
208
|
-
* elements as strings.
|
|
209
|
-
*
|
|
210
|
-
* Mirrors `generateSwapProof` in
|
|
211
|
-
* relayer-server/src/controllers/swap.helpers.ts so SDK-side swap proofs
|
|
212
|
-
* verify against the same circuit the relayer uses.
|
|
213
|
-
*/
|
|
214
|
-
export function formatSwapInputsForSnarkjs(inputs) {
|
|
215
|
-
return {
|
|
216
|
-
// Public inputs
|
|
217
|
-
sourceRoot: bytesToBigIntBE(inputs.sourceRoot).toString(),
|
|
218
|
-
swapParamsHash: bytesToBigIntBE(inputs.swapParamsHash).toString(),
|
|
219
|
-
extDataHash: bytesToBigIntBE(inputs.extDataHash).toString(),
|
|
220
|
-
sourceMint: pubkeyToField(inputs.sourceMint).toString(),
|
|
221
|
-
destMint: pubkeyToField(inputs.destMint).toString(),
|
|
222
|
-
inputNullifier: inputs.inputNullifiers.map((n) => bytesToBigIntBE(n).toString()),
|
|
223
|
-
changeCommitment: bytesToBigIntBE(inputs.changeCommitment).toString(),
|
|
224
|
-
destCommitment: bytesToBigIntBE(inputs.destCommitment).toString(),
|
|
225
|
-
swapAmount: inputs.swapAmount.toString(),
|
|
226
|
-
// Private inputs - Input UTXOs
|
|
227
|
-
inAmount: inputs.inAmount.map((a) => a.toString()),
|
|
228
|
-
inPubkey: inputs.inPubkey.map((p) => p.toString()),
|
|
229
|
-
inBlinding: inputs.inBlinding.map((b) => b.toString()),
|
|
230
|
-
inPathIndex: inputs.inPathIndex.map((i) => i.toString()),
|
|
231
|
-
inPathElements: inputs.inPathElements.map((path) => path.map((e) => e.toString())),
|
|
232
|
-
inPrivateKey: inputs.inPrivateKey.map((k) => k.toString()),
|
|
233
|
-
// Private inputs - Change UTXO
|
|
234
|
-
changeAmount: inputs.changeAmount.toString(),
|
|
235
|
-
changePubkey: inputs.changePubkey.toString(),
|
|
236
|
-
changeBlinding: inputs.changeBlinding.toString(),
|
|
237
|
-
// Private inputs - Destination UTXO
|
|
238
|
-
destAmount: inputs.destAmount.toString(),
|
|
239
|
-
destPubkey: inputs.destPubkey.toString(),
|
|
240
|
-
destBlinding: inputs.destBlinding.toString(),
|
|
241
|
-
// Swap params
|
|
242
|
-
minAmountOut: inputs.minAmountOut.toString(),
|
|
243
|
-
deadline: inputs.deadline.toString(),
|
|
244
|
-
};
|
|
245
|
-
}
|
|
246
|
-
// -----------------------------------------------------------------------------
|
|
247
|
-
// Swap Parameter Hashing
|
|
248
|
-
// -----------------------------------------------------------------------------
|
|
249
|
-
/**
|
|
250
|
-
* Compute the swap params hash that the swap circuit and on-chain program verify.
|
|
251
|
-
* Mirrors relayer-server/src/controllers/swap.helpers.ts `computeSwapParamsHash`.
|
|
252
|
-
*
|
|
253
|
-
* Circuit formula (swap.circom lines 293-307):
|
|
254
|
-
* mintPairHash = Poseidon(sourceMint, destMint)
|
|
255
|
-
* swapTermsHash = Poseidon(minAmountOut, deadline, destAmount)
|
|
256
|
-
* swapParamsHash = Poseidon(mintPairHash, swapTermsHash)
|
|
257
|
-
*
|
|
258
|
-
* @param sourceMint Source pool mint
|
|
259
|
-
* @param destMint Destination pool mint
|
|
260
|
-
* @param minAmountOut Minimum accepted output amount (slippage protected)
|
|
261
|
-
* @param deadline Unix timestamp deadline (i64, 0 = no deadline)
|
|
262
|
-
* @param destAmount Actual amount committed to destination UTXO (≥ minAmountOut -
|
|
263
|
-
* relayerFee). If omitted, defaults to minAmountOut.
|
|
264
|
-
*/
|
|
265
|
-
export function computeSwapParamsHash(sourceMint, destMint, minAmountOut, deadline, destAmount) {
|
|
266
|
-
const srcField = pubkeyToField(sourceMint);
|
|
267
|
-
const dstField = pubkeyToField(destMint);
|
|
268
|
-
const mintPairHash = poseidon2(srcField, dstField);
|
|
269
|
-
const dest = destAmount ?? minAmountOut;
|
|
270
|
-
const swapTermsHash = poseidon3(minAmountOut, deadline, dest);
|
|
271
|
-
const paramsHash = poseidon2(mintPairHash, swapTermsHash);
|
|
272
|
-
return bigIntToBytesBE(paramsHash);
|
|
273
|
-
}
|
|
274
|
-
/**
|
|
275
|
-
* Compute the swap data hash committed on-chain for Jupiter instruction integrity.
|
|
276
|
-
* SHA-256 of the raw Jupiter swap instruction data bytes.
|
|
277
|
-
* Mirrors relayer-server/src/controllers/swap.helpers.ts `computeSwapDataHash`.
|
|
278
|
-
*/
|
|
279
|
-
export function computeSwapDataHash(swapData) {
|
|
280
|
-
return sha256(swapData instanceof Buffer ? new Uint8Array(swapData) : swapData);
|
|
281
|
-
}
|
|
1
|
+
// Backward-compatible entry point. Proof responsibilities live in src/proofs.
|
|
2
|
+
export * from "./proofs/index.js";
|
|
@@ -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;
|