@veilo/sdk-core 0.1.17 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1296 -272
- package/SHIELD_INTEGRATION.md +143 -0
- package/config.d.ts +2 -0
- package/config.js +4 -0
- package/dist/cjs/client.d.ts +407 -0
- package/dist/cjs/client.js +951 -0
- package/dist/cjs/compactNote.d.ts +107 -0
- package/dist/cjs/compactNote.js +167 -0
- package/dist/cjs/config.d.ts +82 -0
- package/dist/cjs/config.js +57 -0
- package/dist/cjs/events.d.ts +77 -0
- package/dist/cjs/events.js +167 -0
- package/dist/cjs/idl/privacy_pool.d.ts +5 -0
- package/dist/cjs/idl/privacy_pool.js +15218 -0
- package/dist/cjs/idl/privacy_pool.json +10313 -0
- package/dist/cjs/index.d.ts +16 -0
- package/dist/cjs/index.js +67 -0
- package/dist/cjs/merkle.d.ts +77 -0
- package/dist/cjs/merkle.js +156 -0
- package/dist/cjs/poseidon.d.ts +29 -0
- package/dist/cjs/poseidon.js +100 -0
- package/dist/cjs/program.d.ts +37 -0
- package/dist/cjs/program.js +61 -0
- package/dist/cjs/proof.d.ts +183 -0
- package/dist/cjs/proof.js +292 -0
- package/dist/cjs/prover.d.ts +54 -0
- package/dist/cjs/prover.js +112 -0
- package/dist/cjs/random.d.ts +16 -0
- package/dist/cjs/random.js +28 -0
- package/dist/cjs/relayer.d.ts +318 -0
- package/dist/cjs/relayer.js +257 -0
- package/dist/cjs/retry.d.ts +32 -0
- package/dist/cjs/retry.js +75 -0
- 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 +126 -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 +499 -0
- package/dist/cjs/shield/types.d.ts +202 -0
- package/dist/cjs/shield/types.js +2 -0
- package/dist/cjs/utxo.d.ts +235 -0
- package/dist/cjs/utxo.js +407 -0
- package/dist/esm/client.d.ts +407 -0
- package/dist/esm/client.js +891 -0
- package/dist/esm/compactNote.d.ts +107 -0
- package/dist/esm/compactNote.js +156 -0
- package/dist/esm/config.d.ts +82 -0
- package/dist/esm/config.js +51 -0
- package/dist/esm/events.d.ts +77 -0
- package/dist/esm/events.js +129 -0
- package/dist/esm/idl/privacy_pool.d.ts +5 -0
- package/dist/esm/idl/privacy_pool.js +15216 -0
- package/dist/esm/idl/privacy_pool.json +10313 -0
- package/dist/esm/index.d.ts +16 -0
- package/dist/esm/index.js +29 -0
- package/dist/esm/merkle.d.ts +77 -0
- package/dist/esm/merkle.js +151 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/poseidon.d.ts +29 -0
- package/dist/esm/poseidon.js +87 -0
- package/dist/esm/program.d.ts +37 -0
- package/dist/esm/program.js +53 -0
- package/dist/esm/proof.d.ts +183 -0
- package/dist/esm/proof.js +281 -0
- package/dist/esm/prover.d.ts +54 -0
- package/dist/esm/prover.js +75 -0
- package/dist/esm/random.d.ts +16 -0
- package/dist/esm/random.js +21 -0
- package/dist/esm/relayer.d.ts +318 -0
- package/dist/esm/relayer.js +249 -0
- package/dist/esm/retry.d.ts +32 -0
- package/dist/esm/retry.js +71 -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 +122 -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 +492 -0
- package/dist/esm/shield/types.d.ts +202 -0
- package/dist/esm/shield/types.js +1 -0
- package/dist/esm/utxo.d.ts +235 -0
- package/dist/esm/utxo.js +382 -0
- package/dist/src/client.d.ts +407 -0
- package/dist/src/client.js +951 -0
- package/dist/src/compactNote.d.ts +107 -0
- package/dist/src/compactNote.js +167 -0
- package/dist/src/config.d.ts +82 -0
- package/dist/src/config.js +57 -0
- package/dist/src/events.d.ts +77 -0
- package/dist/src/events.js +167 -0
- package/dist/src/idl/privacy_pool.d.ts +5 -0
- package/dist/src/idl/privacy_pool.js +15218 -0
- package/dist/src/index.d.ts +16 -0
- package/dist/src/index.js +67 -0
- package/dist/src/merkle.d.ts +77 -0
- package/dist/src/merkle.js +156 -0
- package/dist/src/poseidon.d.ts +29 -0
- package/dist/src/poseidon.js +100 -0
- package/dist/src/program.d.ts +37 -0
- package/dist/src/program.js +61 -0
- package/dist/src/proof.d.ts +183 -0
- package/dist/src/proof.js +292 -0
- package/dist/src/prover.d.ts +54 -0
- package/dist/src/prover.js +112 -0
- package/dist/src/random.d.ts +16 -0
- package/dist/src/random.js +28 -0
- package/dist/src/relayer.d.ts +318 -0
- package/dist/src/relayer.js +257 -0
- package/dist/src/retry.d.ts +32 -0
- package/dist/src/retry.js +75 -0
- package/dist/src/shield/alt.d.ts +87 -0
- package/dist/src/shield/alt.js +194 -0
- package/dist/src/shield/computeBudget.d.ts +61 -0
- package/dist/src/shield/computeBudget.js +64 -0
- package/dist/src/shield/errors.d.ts +58 -0
- package/dist/src/shield/errors.js +121 -0
- package/dist/src/shield/finalize.d.ts +45 -0
- package/dist/src/shield/finalize.js +119 -0
- package/dist/src/shield/index.d.ts +35 -0
- package/dist/src/shield/index.js +68 -0
- package/dist/src/shield/ix.d.ts +54 -0
- package/dist/src/shield/ix.js +119 -0
- package/dist/src/shield/owner.d.ts +36 -0
- package/dist/src/shield/owner.js +126 -0
- package/dist/src/shield/ports.d.ts +43 -0
- package/dist/src/shield/ports.js +153 -0
- package/dist/src/shield/preflight.d.ts +30 -0
- package/dist/src/shield/preflight.js +154 -0
- package/dist/src/shield/shield.d.ts +68 -0
- package/dist/src/shield/shield.js +499 -0
- package/dist/src/shield/types.d.ts +202 -0
- package/dist/src/shield/types.js +2 -0
- package/dist/src/utxo.d.ts +235 -0
- package/dist/src/utxo.js +407 -0
- package/dist/tests/compact-note.test.d.ts +1 -0
- package/dist/tests/compact-note.test.js +173 -0
- package/dist/tests/config.test.d.ts +1 -0
- package/dist/tests/config.test.js +102 -0
- package/dist/tests/edge-cases.test.d.ts +1 -0
- package/dist/tests/edge-cases.test.js +220 -0
- package/dist/tests/encryption.test.d.ts +1 -0
- package/dist/tests/encryption.test.js +215 -0
- package/dist/tests/events.test.d.ts +1 -0
- package/dist/tests/events.test.js +78 -0
- package/dist/tests/multi-tree.test.d.ts +1 -0
- package/dist/tests/multi-tree.test.js +405 -0
- package/dist/tests/pda.test.d.ts +1 -0
- package/dist/tests/pda.test.js +229 -0
- package/dist/tests/poseidon-builder-parity.test.d.ts +1 -0
- package/dist/tests/poseidon-builder-parity.test.js +72 -0
- package/dist/tests/poseidon.test.d.ts +1 -0
- package/dist/tests/poseidon.test.js +142 -0
- package/dist/tests/proof.test.d.ts +1 -0
- package/dist/tests/proof.test.js +296 -0
- package/dist/tests/relayer.test.d.ts +1 -0
- package/dist/tests/relayer.test.js +271 -0
- package/dist/tests/sdk.integration.test.d.ts +1 -0
- package/dist/tests/sdk.integration.test.js +330 -0
- package/dist/tests/shield-owner.test.d.ts +1 -0
- package/dist/tests/shield-owner.test.js +89 -0
- package/dist/tests/shield-preflight.test.d.ts +1 -0
- package/dist/tests/shield-preflight.test.js +87 -0
- package/dist/tests/shield-realproof.test.d.ts +1 -0
- package/dist/tests/shield-realproof.test.js +272 -0
- package/dist/tests/shield.test.d.ts +1 -0
- package/dist/tests/shield.test.js +403 -0
- package/dist/tests/utxo.test.d.ts +1 -0
- package/dist/tests/utxo.test.js +140 -0
- package/package.json +105 -11
- package/poseidon.d.ts +2 -0
- package/poseidon.js +4 -0
- package/proof.d.ts +2 -0
- package/proof.js +4 -0
- package/prover.d.ts +2 -0
- package/prover.js +4 -0
- package/shield.d.ts +2 -0
- package/shield.js +4 -0
- package/src/client.ts +0 -352
- package/src/config.ts +0 -13
- package/src/index.ts +0 -6
- package/src/merkle.ts +0 -178
- package/src/note.ts +0 -193
- package/src/poseidon.ts +0 -62
- package/src/proof.ts +0 -170
- package/test/script.js +0 -0
- package/test-tsconfig.json +0 -19
- package/tests/note.test.ts +0 -50
- package/tests/sdk.integration.test.ts +0 -210
- package/tsconfig.json +0 -18
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { AddressLookupTableAccount, Connection, PublicKey, VersionedTransaction } from "@solana/web3.js";
|
|
2
|
+
import type { TransactionProofBuilder, TransactionProofStruct } from "../proof.js";
|
|
3
|
+
import type { CompactNoteCipher } from "../compactNote.js";
|
|
4
|
+
/**
|
|
5
|
+
* Who owns the resulting note. Both halves are required and neither is derived
|
|
6
|
+
* from the other:
|
|
7
|
+
*
|
|
8
|
+
* - `veiloPublicKey` is the Poseidon field element bound into the output
|
|
9
|
+
* commitment. It is the **spending** authority.
|
|
10
|
+
* - `noteViewingKey` is the Ed25519 wallet key the compact cipher is encrypted
|
|
11
|
+
* to. It is the **detection** authority.
|
|
12
|
+
*
|
|
13
|
+
* If these two belong to different people, the note is *spendable but
|
|
14
|
+
* invisible*: the owner can never find it, so the funds are effectively gone.
|
|
15
|
+
* Nothing on-chain and nothing in this type can detect that — which is why
|
|
16
|
+
* `resolveShieldOwner()` exists and why hand-constructing this requires an
|
|
17
|
+
* explicit acknowledgement.
|
|
18
|
+
*
|
|
19
|
+
* See veilo-browser-extension/.../privateStealthWallet.ts:403-415 for the
|
|
20
|
+
* production comment describing this failure mode.
|
|
21
|
+
*/
|
|
22
|
+
export type ShieldOwner = {
|
|
23
|
+
veiloPublicKey: bigint;
|
|
24
|
+
noteViewingKey: PublicKey;
|
|
25
|
+
/**
|
|
26
|
+
* Set automatically by {@link resolveShieldOwner}, which fetches both halves
|
|
27
|
+
* from a single relayer response and can therefore guarantee they match.
|
|
28
|
+
*
|
|
29
|
+
* Hand-built owners must set this explicitly — it is the only mechanism
|
|
30
|
+
* standing between an integration mistake and silent fund loss.
|
|
31
|
+
*/
|
|
32
|
+
acknowledgeOwnerInvariant?: true;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Who signs and pays. Public key only — the SDK never receives a secret key.
|
|
36
|
+
*
|
|
37
|
+
* The signer is unavoidably the fee payer, the funding source, and the payer of
|
|
38
|
+
* ~0.00192 SOL of nullifier-marker rent (the program hardcodes
|
|
39
|
+
* `payer = relayer` on both marker accounts). A wallet with no SOL cannot
|
|
40
|
+
* shield through this path regardless of who submits the transaction.
|
|
41
|
+
*/
|
|
42
|
+
export type ShieldSigner = {
|
|
43
|
+
publicKey: PublicKey;
|
|
44
|
+
/**
|
|
45
|
+
* Source token account for SPL shields. Defaults to the signer's canonical
|
|
46
|
+
* ATA. Must be owned by `publicKey` with no delegate set.
|
|
47
|
+
*/
|
|
48
|
+
tokenAccount?: PublicKey;
|
|
49
|
+
};
|
|
50
|
+
/** Where the target tree and its root come from. */
|
|
51
|
+
export interface TreeSource {
|
|
52
|
+
getDepositTarget(mint: PublicKey): Promise<DepositTarget>;
|
|
53
|
+
}
|
|
54
|
+
export type DepositTarget = {
|
|
55
|
+
/** Always 0 — the tree whose root the dummy inputs nominally prove against. */
|
|
56
|
+
inputTreeId: number;
|
|
57
|
+
/** 32-byte root, read from that tree's on-chain root history. */
|
|
58
|
+
inputRoot: Uint8Array;
|
|
59
|
+
/** Tree the new commitments are appended to. */
|
|
60
|
+
outputTreeId: number;
|
|
61
|
+
/** `nextIndex` at build time. A prediction — see `predictedLeafIndex`. */
|
|
62
|
+
outputNextIndex: number;
|
|
63
|
+
};
|
|
64
|
+
/** Where the address lookup table comes from. */
|
|
65
|
+
export interface AltSource {
|
|
66
|
+
resolve(ctx: {
|
|
67
|
+
connection: Connection;
|
|
68
|
+
mint: PublicKey;
|
|
69
|
+
outputTreeId: number;
|
|
70
|
+
programId: PublicKey;
|
|
71
|
+
}): Promise<AddressLookupTableAccount>;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Caching for values that are stable across builds (the ALT account, rent
|
|
75
|
+
* exemption minimums, pool config).
|
|
76
|
+
*
|
|
77
|
+
* Deliberately an interface: the three production deposit implementations
|
|
78
|
+
* differ on exactly this axis — `localStorage`, `chrome.storage`, and
|
|
79
|
+
* `AsyncStorage` — and none of them belongs in a published SDK.
|
|
80
|
+
*/
|
|
81
|
+
export interface ShieldCachePort {
|
|
82
|
+
get<T>(key: string): Promise<T | undefined>;
|
|
83
|
+
set<T>(key: string, value: T, ttlMs?: number): Promise<void>;
|
|
84
|
+
}
|
|
85
|
+
export type PreflightOptions = {
|
|
86
|
+
/** Skip the SPL token-account inspection (owner, delegate, balance). */
|
|
87
|
+
skipTokenAccount?: boolean;
|
|
88
|
+
/** Skip the signer balance check. */
|
|
89
|
+
skipBalance?: boolean;
|
|
90
|
+
/** Skip pool state checks (paused, min/max, tree capacity). */
|
|
91
|
+
skipPoolState?: boolean;
|
|
92
|
+
};
|
|
93
|
+
export type ShieldParams = {
|
|
94
|
+
connection: Connection;
|
|
95
|
+
/** Net amount to shield, in base units. No fee is taken on deposits. */
|
|
96
|
+
amount: bigint;
|
|
97
|
+
/** Defaults to native SOL. */
|
|
98
|
+
mint?: PublicKey;
|
|
99
|
+
owner: ShieldOwner;
|
|
100
|
+
signer: ShieldSigner;
|
|
101
|
+
/** Proof generation. `createTransactionProver(artifacts)` satisfies this. */
|
|
102
|
+
prover: TransactionProofBuilder;
|
|
103
|
+
treeSource?: TreeSource;
|
|
104
|
+
alt?: AltSource;
|
|
105
|
+
cache?: ShieldCachePort;
|
|
106
|
+
programId?: PublicKey;
|
|
107
|
+
computeUnitLimit?: number;
|
|
108
|
+
/** Set to 0 to omit the priority-fee instruction entirely. */
|
|
109
|
+
computeUnitPriceMicroLamports?: number;
|
|
110
|
+
deadlineSeconds?: number;
|
|
111
|
+
/** Supply to avoid an RPC round-trip; otherwise fetched just before compiling. */
|
|
112
|
+
blockhash?: {
|
|
113
|
+
blockhash: string;
|
|
114
|
+
lastValidBlockHeight: number;
|
|
115
|
+
};
|
|
116
|
+
preflight?: boolean | PreflightOptions;
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* The recoverable secret material for the note this shield creates.
|
|
120
|
+
*
|
|
121
|
+
* SECRET. Anyone holding this can locate the note. It must never be persisted
|
|
122
|
+
* server-side in the clear or transmitted alongside {@link ShieldProofCache},
|
|
123
|
+
* which is deliberately public.
|
|
124
|
+
*/
|
|
125
|
+
export type ShieldNote = {
|
|
126
|
+
commitment: Uint8Array;
|
|
127
|
+
blinding: bigint;
|
|
128
|
+
amount: bigint;
|
|
129
|
+
ownerVeiloPublicKey: bigint;
|
|
130
|
+
mint: PublicKey;
|
|
131
|
+
treeId: number;
|
|
132
|
+
compact: CompactNoteCipher;
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* Everything needed to re-assemble the transaction with a fresh blockhash.
|
|
136
|
+
*
|
|
137
|
+
* PUBLIC and JSON-serializable by construction: it carries no blinding, no
|
|
138
|
+
* private key, and no note plaintext. A platform can build server-side, ship
|
|
139
|
+
* this to a client for signature, and rebuild in a different process without
|
|
140
|
+
* ever moving a secret.
|
|
141
|
+
*/
|
|
142
|
+
export type ShieldProofCache = {
|
|
143
|
+
version: 1;
|
|
144
|
+
programId: string;
|
|
145
|
+
mint: string;
|
|
146
|
+
signer: string;
|
|
147
|
+
altAddress: string;
|
|
148
|
+
inputTreeId: number;
|
|
149
|
+
outputTreeId: number;
|
|
150
|
+
root: string;
|
|
151
|
+
publicAmount: string;
|
|
152
|
+
extData: {
|
|
153
|
+
recipient: string;
|
|
154
|
+
relayer: string;
|
|
155
|
+
fee: string;
|
|
156
|
+
refund: string;
|
|
157
|
+
claimant: string;
|
|
158
|
+
};
|
|
159
|
+
extDataHash: string;
|
|
160
|
+
inputNullifiers: [string, string];
|
|
161
|
+
outputCommitments: [string, string];
|
|
162
|
+
proof: TransactionProofStruct;
|
|
163
|
+
noteCiphers: {
|
|
164
|
+
note0EphemeralKey: string;
|
|
165
|
+
note0Encrypted: string;
|
|
166
|
+
note0ViewTag: number;
|
|
167
|
+
note1EphemeralKey: string;
|
|
168
|
+
note1Encrypted: string;
|
|
169
|
+
note1ViewTag: number;
|
|
170
|
+
};
|
|
171
|
+
/** Resolved instruction accounts, keyed by IDL account name. */
|
|
172
|
+
accounts: Record<string, string>;
|
|
173
|
+
computeUnitLimit: number;
|
|
174
|
+
};
|
|
175
|
+
export type ShieldQuote = {
|
|
176
|
+
/** Serialized size including the signature. Must be <= 1232. */
|
|
177
|
+
serializedSize: number;
|
|
178
|
+
computeUnitLimit: number;
|
|
179
|
+
computeUnitPriceMicroLamports: number;
|
|
180
|
+
estimatedFeeLamports: bigint;
|
|
181
|
+
/** Nullifier-marker rent, permanently burned by the signer. */
|
|
182
|
+
estimatedRentLamports: bigint;
|
|
183
|
+
};
|
|
184
|
+
export type ShieldResult = {
|
|
185
|
+
/** UNSIGNED. The caller signs and submits — this SDK never broadcasts. */
|
|
186
|
+
transaction: VersionedTransaction;
|
|
187
|
+
blockhash: string;
|
|
188
|
+
lastValidBlockHeight: number;
|
|
189
|
+
deadline: bigint;
|
|
190
|
+
note: ShieldNote;
|
|
191
|
+
/**
|
|
192
|
+
* Leaf index the output commitment is *expected* to land at.
|
|
193
|
+
*
|
|
194
|
+
* A prediction, read before submission. Under concurrent deposits into the
|
|
195
|
+
* same tree it will be wrong. Use `finalizeShield()` to read the authoritative
|
|
196
|
+
* index from the confirmed transaction's `CommitmentEvent` before persisting
|
|
197
|
+
* anything that depends on it.
|
|
198
|
+
*/
|
|
199
|
+
predictedLeafIndex: number;
|
|
200
|
+
quote: ShieldQuote;
|
|
201
|
+
proofCache: ShieldProofCache;
|
|
202
|
+
};
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { PublicKey } from "@solana/web3.js";
|
|
2
|
+
/**
|
|
3
|
+
* Keypair for UTXO ownership.
|
|
4
|
+
* Public key is derived via Poseidon: pubkey = Poseidon(privateKey)
|
|
5
|
+
*/
|
|
6
|
+
export type Keypair = {
|
|
7
|
+
privateKey: bigint;
|
|
8
|
+
publicKey: bigint;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* UTXO structure matching the circuit's UTXOCommitment template.
|
|
12
|
+
* commitment = Poseidon(amount, pubkey, blinding, mintAddress)
|
|
13
|
+
*/
|
|
14
|
+
export type UTXO = {
|
|
15
|
+
/** Amount in lamports/token units */
|
|
16
|
+
amount: bigint;
|
|
17
|
+
/** Owner's public key (derived from private key via Poseidon) */
|
|
18
|
+
pubkey: bigint;
|
|
19
|
+
/** Random blinding factor for commitment privacy */
|
|
20
|
+
blinding: bigint;
|
|
21
|
+
/** Token mint address as field element */
|
|
22
|
+
mintAddress: bigint;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Serialized UTXO with precomputed commitment and optional ownership data.
|
|
26
|
+
*/
|
|
27
|
+
export type SerializedUTXO = UTXO & {
|
|
28
|
+
/** 32-byte commitment: Poseidon(amount, pubkey, blinding, mintAddress) */
|
|
29
|
+
commitment: Uint8Array;
|
|
30
|
+
/** Private key for spending (only present for owned UTXOs) */
|
|
31
|
+
privateKey?: bigint;
|
|
32
|
+
/** Leaf index in the Merkle tree (set after insertion) */
|
|
33
|
+
pathIndex?: number;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Input UTXO with Merkle proof data for spending.
|
|
37
|
+
*/
|
|
38
|
+
export type InputUTXO = SerializedUTXO & {
|
|
39
|
+
/** Leaf index in the Merkle tree */
|
|
40
|
+
pathIndex: number;
|
|
41
|
+
/** Merkle path elements (sibling hashes from leaf to root) */
|
|
42
|
+
pathElements: Uint8Array[];
|
|
43
|
+
/** Private key for nullifier derivation */
|
|
44
|
+
privateKey: bigint;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Generate a random keypair.
|
|
48
|
+
* Private key is a random 32-byte scalar.
|
|
49
|
+
* Public key is derived via Poseidon: pubkey = Poseidon(privateKey)
|
|
50
|
+
*/
|
|
51
|
+
export declare function generateKeypair(): Keypair;
|
|
52
|
+
/**
|
|
53
|
+
* Derive public key from private key.
|
|
54
|
+
* Matches circuit's Keypair template: publicKey = Poseidon(privateKey)
|
|
55
|
+
*/
|
|
56
|
+
export declare function derivePublicKey(privateKey: bigint): bigint;
|
|
57
|
+
/**
|
|
58
|
+
* Create keypair from a known private key.
|
|
59
|
+
*/
|
|
60
|
+
export declare function keypairFromPrivateKey(privateKey: bigint): Keypair;
|
|
61
|
+
/**
|
|
62
|
+
* Compute UTXO commitment.
|
|
63
|
+
* Matches circuit's UTXOCommitment template:
|
|
64
|
+
* commitment = Poseidon(amount, pubkey, blinding, mintAddress)
|
|
65
|
+
*/
|
|
66
|
+
export declare function commitUTXO(utxo: UTXO): Uint8Array;
|
|
67
|
+
/**
|
|
68
|
+
* Create a random UTXO with the given parameters.
|
|
69
|
+
*/
|
|
70
|
+
export declare function createUTXO(params: {
|
|
71
|
+
amount: bigint;
|
|
72
|
+
pubkey: bigint;
|
|
73
|
+
mintAddress: PublicKey;
|
|
74
|
+
}): SerializedUTXO;
|
|
75
|
+
/**
|
|
76
|
+
* Create a UTXO with a specified private key (for owned UTXOs).
|
|
77
|
+
*/
|
|
78
|
+
export declare function createOwnedUTXO(params: {
|
|
79
|
+
amount: bigint;
|
|
80
|
+
privateKey: bigint;
|
|
81
|
+
mintAddress: PublicKey;
|
|
82
|
+
}): SerializedUTXO;
|
|
83
|
+
/**
|
|
84
|
+
* Create a zero UTXO (for deposits where no input exists).
|
|
85
|
+
* Zero UTXOs have amount=0 and are used as placeholders in 2-in-2-out transactions.
|
|
86
|
+
*/
|
|
87
|
+
export declare function createZeroUTXO(pubkey: bigint, mintAddress: PublicKey): SerializedUTXO;
|
|
88
|
+
/**
|
|
89
|
+
* Create a zero UTXO with private key (for owned zero UTXOs).
|
|
90
|
+
*/
|
|
91
|
+
export declare function createOwnedZeroUTXO(privateKey: bigint, mintAddress: PublicKey): SerializedUTXO;
|
|
92
|
+
/**
|
|
93
|
+
* Compute signature for nullifier derivation.
|
|
94
|
+
* Matches circuit's Signature template:
|
|
95
|
+
* signature = Poseidon(privateKey, commitment, pathIndex)
|
|
96
|
+
*/
|
|
97
|
+
export declare function computeSignature(privateKey: bigint, commitment: bigint, pathIndex: bigint): bigint;
|
|
98
|
+
/**
|
|
99
|
+
* Derive nullifier for a UTXO.
|
|
100
|
+
* Matches circuit's UTXONullifier template:
|
|
101
|
+
* signature = Poseidon(privateKey, commitment, pathIndex)
|
|
102
|
+
* nullifier = Poseidon(commitment, pathIndex, signature)
|
|
103
|
+
*
|
|
104
|
+
* The signature-based nullifier ensures only the private key holder can spend.
|
|
105
|
+
*/
|
|
106
|
+
export declare function deriveNullifier(utxo: SerializedUTXO, pathIndex: number, privateKey: bigint): Uint8Array;
|
|
107
|
+
/**
|
|
108
|
+
* Convert InputUTXO to the format expected by the circuit.
|
|
109
|
+
*/
|
|
110
|
+
export declare function inputUTXOToCircuitFormat(input: InputUTXO): {
|
|
111
|
+
amount: bigint;
|
|
112
|
+
pubkey: bigint;
|
|
113
|
+
blinding: bigint;
|
|
114
|
+
pathElements: bigint[];
|
|
115
|
+
pathIndex: number;
|
|
116
|
+
privateKey: bigint;
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* Encrypted UTXO note — can be broadcast alongside a transaction so the
|
|
120
|
+
* recipient can recover their note without a server.
|
|
121
|
+
*/
|
|
122
|
+
export type EncryptedNote = {
|
|
123
|
+
/** 24-byte NaCl box nonce */
|
|
124
|
+
nonce: Uint8Array;
|
|
125
|
+
/** Ciphertext containing amount + blinding + privateKey */
|
|
126
|
+
ciphertext: Uint8Array;
|
|
127
|
+
/** Sender's ephemeral 32-byte X25519 public key */
|
|
128
|
+
senderEphemeralPubkey: Uint8Array;
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
* Derive a NaCl X25519 encryption keypair from a UTXO private key.
|
|
132
|
+
* The keypair is deterministic: same privateKey always yields the same pair.
|
|
133
|
+
*/
|
|
134
|
+
export declare function deriveEncryptionKeypair(privateKey: bigint): {
|
|
135
|
+
publicKey: Uint8Array;
|
|
136
|
+
secretKey: Uint8Array;
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* Encrypt a UTXO so the recipient can recover it from on-chain events.
|
|
140
|
+
*
|
|
141
|
+
* Plaintext layout (72 bytes):
|
|
142
|
+
* [0..8] amount — 8-byte little-endian u64
|
|
143
|
+
* [8..40] blinding — 32-byte big-endian field element
|
|
144
|
+
* [40..72] privateKey — 32-byte big-endian field element
|
|
145
|
+
*
|
|
146
|
+
* Uses ephemeral-key NaCl box so the sender key is single-use.
|
|
147
|
+
*/
|
|
148
|
+
export declare function encryptUTXONote(utxo: SerializedUTXO & {
|
|
149
|
+
privateKey: bigint;
|
|
150
|
+
}, recipientEncPubkey: Uint8Array): EncryptedNote;
|
|
151
|
+
/**
|
|
152
|
+
* Try to decrypt an encrypted UTXO note using the recipient's private key.
|
|
153
|
+
* Returns the SerializedUTXO if decryption succeeds and the commitment
|
|
154
|
+
* matches, or `null` if the note was not intended for this key.
|
|
155
|
+
*/
|
|
156
|
+
export declare function decryptUTXONote(note: EncryptedNote, recipientPrivateKey: bigint, commitment: Uint8Array, mintAddress: PublicKey): SerializedUTXO | null;
|
|
157
|
+
/** Note data stored inside a Blind Mailbox encrypted blob */
|
|
158
|
+
export type BlindMailboxNoteData = {
|
|
159
|
+
blinding: Uint8Array;
|
|
160
|
+
leafIndex: number;
|
|
161
|
+
commitment: Uint8Array;
|
|
162
|
+
amount: bigint;
|
|
163
|
+
mintAddress: string;
|
|
164
|
+
treeId: number;
|
|
165
|
+
};
|
|
166
|
+
/** Encrypted note as returned by the relayer's /api/notes endpoint */
|
|
167
|
+
export type BlindMailboxNote = {
|
|
168
|
+
commitment: string;
|
|
169
|
+
ephemeralPublicKey: string;
|
|
170
|
+
encryptedBlob: string;
|
|
171
|
+
timestamp?: number;
|
|
172
|
+
blockHeight?: number;
|
|
173
|
+
txSignature?: string;
|
|
174
|
+
};
|
|
175
|
+
/** Decrypted note data after calling decryptBlindMailboxNote */
|
|
176
|
+
export type DecryptedNote = {
|
|
177
|
+
blinding: Uint8Array;
|
|
178
|
+
leafIndex: number;
|
|
179
|
+
commitment: Uint8Array;
|
|
180
|
+
amount: bigint;
|
|
181
|
+
timestamp: number;
|
|
182
|
+
mintAddress?: string;
|
|
183
|
+
treeId: number;
|
|
184
|
+
};
|
|
185
|
+
/** Derive 32-byte encryption key from a shared secret using SHA-512 truncated.
|
|
186
|
+
* Must match the production "sha256" helper which uses nacl.hash (SHA-512) [0:32].
|
|
187
|
+
*
|
|
188
|
+
* DO NOT "fix" this to real SHA-256. The name in the sibling implementations
|
|
189
|
+
* (`sha256ForNotes`) is a misnomer, but the bytes are load-bearing: changing the
|
|
190
|
+
* KDF makes every historical note undecryptable.
|
|
191
|
+
*
|
|
192
|
+
* @internal Exported for `compactNote.ts`. Not part of the stable public API. */
|
|
193
|
+
export declare function kdfSHA512_256(secret: Uint8Array): Uint8Array;
|
|
194
|
+
/** Convert an Ed25519 private seed (32 bytes) to an X25519 scalar.
|
|
195
|
+
* Equivalent to ed2curve.convertSecretKey(seed).
|
|
196
|
+
*
|
|
197
|
+
* @internal Exported for `compactNote.ts`. Not part of the stable public API. */
|
|
198
|
+
export declare function ed25519SeedToX25519Private(seed: Uint8Array): Uint8Array;
|
|
199
|
+
/** Convert an Ed25519 compressed public key (32 bytes) to X25519.
|
|
200
|
+
* Equivalent to ed2curve.convertPublicKey(pubkey).
|
|
201
|
+
* Edwards y-coord → Montgomery u via: u = (1 + y) / (1 - y) (mod p).
|
|
202
|
+
*
|
|
203
|
+
* @internal Exported for `compactNote.ts`. Not part of the stable public API. */
|
|
204
|
+
export declare function ed25519PublicKeyToX25519(pubkey: Uint8Array): Uint8Array;
|
|
205
|
+
/**
|
|
206
|
+
* Encrypt a UTXO note for a recipient identified by their Solana wallet public key.
|
|
207
|
+
* Produces a blob the relayer will store and serve via POST /notes/save.
|
|
208
|
+
*
|
|
209
|
+
* @param recipientWalletPubkey 32-byte Ed25519 public key (wallet.publicKey.toBytes())
|
|
210
|
+
* @param noteData UTXO details to encrypt
|
|
211
|
+
*/
|
|
212
|
+
export declare function encryptBlindMailboxNote(recipientWalletPubkey: Uint8Array, noteData: BlindMailboxNoteData): {
|
|
213
|
+
ephemeralPublicKey: Uint8Array;
|
|
214
|
+
encryptedBlob: string;
|
|
215
|
+
};
|
|
216
|
+
/**
|
|
217
|
+
* Decrypt a Blind Mailbox note using the recipient's Solana wallet private seed.
|
|
218
|
+
*
|
|
219
|
+
* @param walletSecretKey Full 64-byte wallet.secretKey — the first 32 bytes are the seed
|
|
220
|
+
* @param ephemeralPublicKey 32-byte raw public key stored alongside the encrypted blob.
|
|
221
|
+
* This may be either an Ed25519 pubkey (from Keypair.generate())
|
|
222
|
+
* or a raw X25519 pubkey — the decryption path handles both:
|
|
223
|
+
* if it is an Ed25519 key it is converted; otherwise used directly.
|
|
224
|
+
* @param encryptedBlob Base64 string as stored by the relayer
|
|
225
|
+
*/
|
|
226
|
+
export declare function decryptBlindMailboxNote(walletSecretKey: Uint8Array, ephemeralPublicKey: Uint8Array, encryptedBlob: string): DecryptedNote;
|
|
227
|
+
/**
|
|
228
|
+
* Fetch all encrypted notes for a wallet from the relayer's Blind Mailbox endpoint
|
|
229
|
+
* and decrypt them using the wallet's secret key.
|
|
230
|
+
*
|
|
231
|
+
* @param walletPublicKey Base58 wallet address used to query the relayer
|
|
232
|
+
* @param walletSecretKey Full 64-byte keypair.secretKey for decryption
|
|
233
|
+
* @param relayerUrl Relayer base URL (e.g. "https://relay.veilo.app")
|
|
234
|
+
*/
|
|
235
|
+
export declare function fetchAndDecryptNotes(walletPublicKey: string, walletSecretKey: Uint8Array, relayerUrl: string): Promise<DecryptedNote[]>;
|