veilix-sdk 0.3.0 → 0.3.1
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/dist/{VeilixSDK-BfiPKwIa.d.ts → VeilixSDK-BLZZ5yVj.d.ts} +83 -81
- package/dist/{VeilixSDK-sbYKDbdy.d.cts → VeilixSDK-CpjyQiV7.d.cts} +83 -81
- package/dist/circuits/paths.cjs.map +1 -1
- package/dist/circuits/paths.js.map +1 -1
- package/dist/index.cjs +46 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +46 -16
- package/dist/index.js.map +1 -1
- package/dist/react/index.cjs +46 -16
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.js +46 -16
- package/dist/react/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { N as Network } from './VeilixSDK-
|
|
2
|
-
export { B as BuildDepositTxParams, a as BuildRelayPayloadParams, b as BuildSwapPayloadOptions, c as BuildWithdrawPayloadOptions, C as CommitmentStatus, E as EncryptKeyWallet, d as ExtData, F as FetchWalletBalanceOptions, G as GenerateDepositParamsResult, e as GetQuoteParams, f as GetQuoteResponse, g as GetSwapQuoteParams, I as IndexedLeaf, h as IndexerAsset, i as NOTE_PREFIX, j as NoteStatus, k as NullifierStatus, P as ParsedNote, l as PlatformFeeWallet, m as PoolTransaction, n as PreparedCircuitArtifacts, o as ProvedTransaction, Q as Quote, p as QuoteRelayer, q as QuoteTransaction, R as RelayPayload, r as Relayer, s as RelayerJob, t as ResolvedNoteAsset, S as ScanOwnedNotesOptions, u as Submission, v as SubmissionItem, w as SwapParams, x as SwapQuote, y as SwapRelayBundle, z as SwapRelayPayload, A as SwapResult, T as TokenDecimalsSymbol, D as TokenSymbol, H as TransactionProof, J as TreeAccountState, K as TreeState, L as TxStatus, U as Utxo, V as VeilixKeypair, M as VeilixMerkleTree, O as VeilixSDK, W as VeilixSdkInitOptions, X as VeilixSdkRuntimeConfig, Y as VeilixTransferDepositFailure, Z as VeilixTransferItem, _ as VeilixTransferOptions, $ as VeilixTransferResult, a0 as VeilixTransferWithdrawFailure, a1 as WithdrawParams, a2 as WithdrawRelayBundle, a3 as WithdrawResult, a4 as WithdrawStatus, a5 as buildMerkleTree, a6 as decodeNote, a7 as decryptData, a8 as decryptNoteOutput, O as default, a9 as encodeNote, aa as encryptData, ab as encryptNoteOutput, ac as encryptSwapNoteOutput, ad as extDataHash, ae as formatNoteForDisplay, af as getQuote, ag as isLegacyNote, ah as mintToField, ai as parseSecretNote, aj as prepareCircuitArtifacts, ak as proveTransaction, al as swapOutputNote } from './VeilixSDK-
|
|
1
|
+
import { N as Network } from './VeilixSDK-CpjyQiV7.cjs';
|
|
2
|
+
export { B as BuildDepositTxParams, a as BuildRelayPayloadParams, b as BuildSwapPayloadOptions, c as BuildWithdrawPayloadOptions, C as CommitmentStatus, E as EncryptKeyWallet, d as ExtData, F as FetchWalletBalanceOptions, G as GenerateDepositParamsResult, e as GetQuoteParams, f as GetQuoteResponse, g as GetSwapQuoteParams, I as IndexedLeaf, h as IndexerAsset, i as NOTE_PREFIX, j as NoteStatus, k as NullifierStatus, P as ParsedNote, l as PlatformFeeWallet, m as PoolTransaction, n as PreparedCircuitArtifacts, o as ProvedTransaction, Q as Quote, p as QuoteRelayer, q as QuoteTransaction, R as RelayPayload, r as Relayer, s as RelayerJob, t as ResolvedNoteAsset, S as ScanOwnedNotesOptions, u as Submission, v as SubmissionItem, w as SwapParams, x as SwapQuote, y as SwapRelayBundle, z as SwapRelayPayload, A as SwapResult, T as TokenDecimalsSymbol, D as TokenSymbol, H as TransactionProof, J as TreeAccountState, K as TreeState, L as TxStatus, U as Utxo, V as VeilixKeypair, M as VeilixMerkleTree, O as VeilixSDK, W as VeilixSdkInitOptions, X as VeilixSdkRuntimeConfig, Y as VeilixTransferDepositFailure, Z as VeilixTransferItem, _ as VeilixTransferOptions, $ as VeilixTransferResult, a0 as VeilixTransferWithdrawFailure, a1 as WithdrawParams, a2 as WithdrawRelayBundle, a3 as WithdrawResult, a4 as WithdrawStatus, a5 as buildMerkleTree, a6 as decodeNote, a7 as decryptData, a8 as decryptNoteOutput, O as default, a9 as encodeNote, aa as encryptData, ab as encryptNoteOutput, ac as encryptSwapNoteOutput, ad as extDataHash, ae as formatNoteForDisplay, af as getQuote, ag as isLegacyNote, ah as mintToField, ai as parseSecretNote, aj as prepareCircuitArtifacts, ak as proveTransaction, al as swapOutputNote } from './VeilixSDK-CpjyQiV7.cjs';
|
|
3
3
|
export { C as CircuitPaths, a as WITHDRAW_CIRCUIT_WASM, b as WITHDRAW_CIRCUIT_ZKEY, c as resolveCircuitPathsFromBase, d as resolveNpmCdnCircuitBase } from './constants-C-u6nmCv.cjs';
|
|
4
4
|
import { PublicKey, Connection } from '@solana/web3.js';
|
|
5
5
|
export { Wallet } from '@coral-xyz/anchor/dist/cjs/provider';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { N as Network } from './VeilixSDK-
|
|
2
|
-
export { B as BuildDepositTxParams, a as BuildRelayPayloadParams, b as BuildSwapPayloadOptions, c as BuildWithdrawPayloadOptions, C as CommitmentStatus, E as EncryptKeyWallet, d as ExtData, F as FetchWalletBalanceOptions, G as GenerateDepositParamsResult, e as GetQuoteParams, f as GetQuoteResponse, g as GetSwapQuoteParams, I as IndexedLeaf, h as IndexerAsset, i as NOTE_PREFIX, j as NoteStatus, k as NullifierStatus, P as ParsedNote, l as PlatformFeeWallet, m as PoolTransaction, n as PreparedCircuitArtifacts, o as ProvedTransaction, Q as Quote, p as QuoteRelayer, q as QuoteTransaction, R as RelayPayload, r as Relayer, s as RelayerJob, t as ResolvedNoteAsset, S as ScanOwnedNotesOptions, u as Submission, v as SubmissionItem, w as SwapParams, x as SwapQuote, y as SwapRelayBundle, z as SwapRelayPayload, A as SwapResult, T as TokenDecimalsSymbol, D as TokenSymbol, H as TransactionProof, J as TreeAccountState, K as TreeState, L as TxStatus, U as Utxo, V as VeilixKeypair, M as VeilixMerkleTree, O as VeilixSDK, W as VeilixSdkInitOptions, X as VeilixSdkRuntimeConfig, Y as VeilixTransferDepositFailure, Z as VeilixTransferItem, _ as VeilixTransferOptions, $ as VeilixTransferResult, a0 as VeilixTransferWithdrawFailure, a1 as WithdrawParams, a2 as WithdrawRelayBundle, a3 as WithdrawResult, a4 as WithdrawStatus, a5 as buildMerkleTree, a6 as decodeNote, a7 as decryptData, a8 as decryptNoteOutput, O as default, a9 as encodeNote, aa as encryptData, ab as encryptNoteOutput, ac as encryptSwapNoteOutput, ad as extDataHash, ae as formatNoteForDisplay, af as getQuote, ag as isLegacyNote, ah as mintToField, ai as parseSecretNote, aj as prepareCircuitArtifacts, ak as proveTransaction, al as swapOutputNote } from './VeilixSDK-
|
|
1
|
+
import { N as Network } from './VeilixSDK-BLZZ5yVj.js';
|
|
2
|
+
export { B as BuildDepositTxParams, a as BuildRelayPayloadParams, b as BuildSwapPayloadOptions, c as BuildWithdrawPayloadOptions, C as CommitmentStatus, E as EncryptKeyWallet, d as ExtData, F as FetchWalletBalanceOptions, G as GenerateDepositParamsResult, e as GetQuoteParams, f as GetQuoteResponse, g as GetSwapQuoteParams, I as IndexedLeaf, h as IndexerAsset, i as NOTE_PREFIX, j as NoteStatus, k as NullifierStatus, P as ParsedNote, l as PlatformFeeWallet, m as PoolTransaction, n as PreparedCircuitArtifacts, o as ProvedTransaction, Q as Quote, p as QuoteRelayer, q as QuoteTransaction, R as RelayPayload, r as Relayer, s as RelayerJob, t as ResolvedNoteAsset, S as ScanOwnedNotesOptions, u as Submission, v as SubmissionItem, w as SwapParams, x as SwapQuote, y as SwapRelayBundle, z as SwapRelayPayload, A as SwapResult, T as TokenDecimalsSymbol, D as TokenSymbol, H as TransactionProof, J as TreeAccountState, K as TreeState, L as TxStatus, U as Utxo, V as VeilixKeypair, M as VeilixMerkleTree, O as VeilixSDK, W as VeilixSdkInitOptions, X as VeilixSdkRuntimeConfig, Y as VeilixTransferDepositFailure, Z as VeilixTransferItem, _ as VeilixTransferOptions, $ as VeilixTransferResult, a0 as VeilixTransferWithdrawFailure, a1 as WithdrawParams, a2 as WithdrawRelayBundle, a3 as WithdrawResult, a4 as WithdrawStatus, a5 as buildMerkleTree, a6 as decodeNote, a7 as decryptData, a8 as decryptNoteOutput, O as default, a9 as encodeNote, aa as encryptData, ab as encryptNoteOutput, ac as encryptSwapNoteOutput, ad as extDataHash, ae as formatNoteForDisplay, af as getQuote, ag as isLegacyNote, ah as mintToField, ai as parseSecretNote, aj as prepareCircuitArtifacts, ak as proveTransaction, al as swapOutputNote } from './VeilixSDK-BLZZ5yVj.js';
|
|
3
3
|
export { C as CircuitPaths, a as WITHDRAW_CIRCUIT_WASM, b as WITHDRAW_CIRCUIT_ZKEY, c as resolveCircuitPathsFromBase, d as resolveNpmCdnCircuitBase } from './constants-C-u6nmCv.js';
|
|
4
4
|
import { PublicKey, Connection } from '@solana/web3.js';
|
|
5
5
|
export { Wallet } from '@coral-xyz/anchor/dist/cjs/provider';
|
package/dist/index.js
CHANGED
|
@@ -8260,7 +8260,7 @@ function getDepositQueueForNetwork(network) {
|
|
|
8260
8260
|
// package.json
|
|
8261
8261
|
var package_default = {
|
|
8262
8262
|
name: "veilix-sdk",
|
|
8263
|
-
version: "0.3.
|
|
8263
|
+
version: "0.3.1"};
|
|
8264
8264
|
|
|
8265
8265
|
// src/circuits/constants.ts
|
|
8266
8266
|
var PACKAGE_NAME = package_default.name;
|
|
@@ -8435,10 +8435,19 @@ async function createRuntimeConfig(options) {
|
|
|
8435
8435
|
};
|
|
8436
8436
|
}
|
|
8437
8437
|
function pushRuntimeContext(config) {
|
|
8438
|
+
const active = runtimeContextStack.find((other) => other.programId !== config.programId);
|
|
8439
|
+
if (active) {
|
|
8440
|
+
throw new Error(
|
|
8441
|
+
`veilix-sdk: another SDK instance is running on program ${active.programId}; instances on different networks must run one at a time`
|
|
8442
|
+
);
|
|
8443
|
+
}
|
|
8438
8444
|
runtimeContextStack.push(config);
|
|
8439
8445
|
}
|
|
8440
|
-
function popRuntimeContext() {
|
|
8441
|
-
runtimeContextStack.
|
|
8446
|
+
function popRuntimeContext(config) {
|
|
8447
|
+
const index = runtimeContextStack.lastIndexOf(config);
|
|
8448
|
+
if (index !== -1) {
|
|
8449
|
+
runtimeContextStack.splice(index, 1);
|
|
8450
|
+
}
|
|
8442
8451
|
}
|
|
8443
8452
|
function getConfig() {
|
|
8444
8453
|
const active = runtimeContextStack.at(-1);
|
|
@@ -17629,9 +17638,11 @@ async function buildDepositTx({
|
|
|
17629
17638
|
onChainBackup = false,
|
|
17630
17639
|
computeUnitPrice = 5e3,
|
|
17631
17640
|
computeUnitLimit = DEPOSIT_COMPUTE_UNIT_LIMIT,
|
|
17632
|
-
circuitArtifacts
|
|
17641
|
+
circuitArtifacts,
|
|
17642
|
+
encryptKey
|
|
17633
17643
|
}) {
|
|
17634
17644
|
const { connection } = getConfig();
|
|
17645
|
+
const sealKey = onChainBackup ? encryptKey ?? requireEncryptKey() : null;
|
|
17635
17646
|
const sender = toPublicKey(senderPublicKey);
|
|
17636
17647
|
const utxo = decodeNote(note);
|
|
17637
17648
|
const mint = utxo.mint;
|
|
@@ -17644,7 +17655,7 @@ async function buildDepositTx({
|
|
|
17644
17655
|
`veilix-sdk: deposit amount ${utxo.amount} exceeds the tree limit of ${tree.maxDepositAmount}`
|
|
17645
17656
|
);
|
|
17646
17657
|
}
|
|
17647
|
-
const encryptedOutput1 =
|
|
17658
|
+
const encryptedOutput1 = sealKey ? encryptNoteOutput(sealKey, utxo) : new Uint8Array();
|
|
17648
17659
|
const encryptedOutput2 = new Uint8Array();
|
|
17649
17660
|
const proved = await withCircuitArtifacts(
|
|
17650
17661
|
circuitArtifacts,
|
|
@@ -17699,16 +17710,15 @@ async function buildInitNotesInstructionIfNeeded(sender) {
|
|
|
17699
17710
|
if (await fetchNotesAccount(sender)) return null;
|
|
17700
17711
|
return program.methods.initNotes().accountsPartial({ user: sender }).instruction();
|
|
17701
17712
|
}
|
|
17702
|
-
async function resolveEncryptKey() {
|
|
17703
|
-
const config = getConfig();
|
|
17713
|
+
async function resolveEncryptKey(config) {
|
|
17704
17714
|
if (!config.encryptKey) {
|
|
17705
17715
|
config.encryptKey = await getEncryptionKey(config.wallet);
|
|
17706
17716
|
}
|
|
17707
17717
|
return config.encryptKey;
|
|
17708
17718
|
}
|
|
17709
|
-
async function buildBackupNotesInstruction(sender, notes) {
|
|
17710
|
-
const { program } =
|
|
17711
|
-
const key2 = await resolveEncryptKey();
|
|
17719
|
+
async function buildBackupNotesInstruction(sender, notes, config = getConfig()) {
|
|
17720
|
+
const { program } = config;
|
|
17721
|
+
const key2 = await resolveEncryptKey(config);
|
|
17712
17722
|
return program.methods.backupNotes(notes.map((note) => encryptData(key2, note))).accountsPartial({ user: sender }).instruction();
|
|
17713
17723
|
}
|
|
17714
17724
|
async function isExtendBackupPdaNeeded(walletPubkey, newNotesLength) {
|
|
@@ -17721,7 +17731,8 @@ function buildRequestHeapIx() {
|
|
|
17721
17731
|
return ComputeBudgetProgram.requestHeapFrame({ bytes: 32 * 1024 });
|
|
17722
17732
|
}
|
|
17723
17733
|
async function buildBackupNotesTx(senderPublicKey, notes) {
|
|
17724
|
-
const
|
|
17734
|
+
const config = getConfig();
|
|
17735
|
+
const { connection } = config;
|
|
17725
17736
|
const sender = toPublicKey(senderPublicKey);
|
|
17726
17737
|
const tx = new Transaction();
|
|
17727
17738
|
const initIx = await buildInitNotesInstructionIfNeeded(sender);
|
|
@@ -17730,7 +17741,7 @@ async function buildBackupNotesTx(senderPublicKey, notes) {
|
|
|
17730
17741
|
} else if (await isExtendBackupPdaNeeded(sender, notes.length)) {
|
|
17731
17742
|
tx.add(buildRequestHeapIx());
|
|
17732
17743
|
}
|
|
17733
|
-
tx.add(await buildBackupNotesInstruction(sender, notes));
|
|
17744
|
+
tx.add(await buildBackupNotesInstruction(sender, notes, config));
|
|
17734
17745
|
tx.recentBlockhash = (await connection.getLatestBlockhash()).blockhash;
|
|
17735
17746
|
tx.feePayer = sender;
|
|
17736
17747
|
return tx;
|
|
@@ -18862,6 +18873,8 @@ var SEND_OPTIONS = { skipPreflight: false, maxRetries: 3 };
|
|
|
18862
18873
|
var SUBMIT_MAX_PROOFS = 8;
|
|
18863
18874
|
var NOTE_INDEX_TIMEOUT_MS = 12e4;
|
|
18864
18875
|
var NOTE_INDEX_POLL_MS = 4e3;
|
|
18876
|
+
var SEND_ATTEMPTS = 4;
|
|
18877
|
+
var SEND_RETRY_MS = 2e3;
|
|
18865
18878
|
function sleep(ms) {
|
|
18866
18879
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
18867
18880
|
}
|
|
@@ -18883,7 +18896,18 @@ async function signTransactions(wallet, transactions) {
|
|
|
18883
18896
|
}
|
|
18884
18897
|
async function sendAndConfirm(signed) {
|
|
18885
18898
|
const { connection } = getConfig();
|
|
18886
|
-
const
|
|
18899
|
+
const raw = signed.serialize();
|
|
18900
|
+
let signature;
|
|
18901
|
+
for (let attempt = 1; signature === void 0; attempt++) {
|
|
18902
|
+
try {
|
|
18903
|
+
signature = await connection.sendRawTransaction(raw, SEND_OPTIONS);
|
|
18904
|
+
} catch (error) {
|
|
18905
|
+
if (attempt >= SEND_ATTEMPTS || !/blockhash not found/i.test(errorMessage(error))) {
|
|
18906
|
+
throw error;
|
|
18907
|
+
}
|
|
18908
|
+
await sleep(SEND_RETRY_MS);
|
|
18909
|
+
}
|
|
18910
|
+
}
|
|
18887
18911
|
const { value } = await connection.confirmTransaction(signature, "confirmed");
|
|
18888
18912
|
if (value.err) {
|
|
18889
18913
|
throw new Error(`Deposit transaction failed: ${JSON.stringify(value.err)}`);
|
|
@@ -18929,6 +18953,7 @@ async function executeVeilixTransfer(items, options = {}) {
|
|
|
18929
18953
|
const { wallet, network, relayers, encryptKey } = getConfig();
|
|
18930
18954
|
const sender = wallet.publicKey;
|
|
18931
18955
|
const onChainBackup = options.onChainBackup ?? !!encryptKey;
|
|
18956
|
+
const sealKey = onChainBackup ? encryptKey ?? requireEncryptKey() : void 0;
|
|
18932
18957
|
const prepared = prepareDeposits(items);
|
|
18933
18958
|
result.notes = prepared.map((deposit) => deposit.note);
|
|
18934
18959
|
const circuitArtifacts = await prepareWithdrawCircuitArtifacts();
|
|
@@ -18939,7 +18964,8 @@ async function executeVeilixTransfer(items, options = {}) {
|
|
|
18939
18964
|
senderPublicKey: sender,
|
|
18940
18965
|
note: deposit.note,
|
|
18941
18966
|
onChainBackup,
|
|
18942
|
-
circuitArtifacts
|
|
18967
|
+
circuitArtifacts,
|
|
18968
|
+
...sealKey ? { encryptKey: sealKey } : {}
|
|
18943
18969
|
});
|
|
18944
18970
|
} catch (error) {
|
|
18945
18971
|
result.depositFailed.push(toDepositFailure(deposit, error));
|
|
@@ -18950,6 +18976,10 @@ async function executeVeilixTransfer(items, options = {}) {
|
|
|
18950
18976
|
result.error = true;
|
|
18951
18977
|
return result;
|
|
18952
18978
|
}
|
|
18979
|
+
const { blockhash } = await getConfig().connection.getLatestBlockhash();
|
|
18980
|
+
toSend.forEach((deposit) => {
|
|
18981
|
+
deposit.tx.message.recentBlockhash = blockhash;
|
|
18982
|
+
});
|
|
18953
18983
|
const signed = await signTransactions(wallet, toSend.map((deposit) => deposit.tx));
|
|
18954
18984
|
if (options.downloadNotes ?? true) {
|
|
18955
18985
|
downloadNotesCsv(toSend.map((deposit) => deposit.note));
|
|
@@ -19053,7 +19083,7 @@ var VeilixSDK = class _VeilixSDK {
|
|
|
19053
19083
|
try {
|
|
19054
19084
|
return fn();
|
|
19055
19085
|
} finally {
|
|
19056
|
-
popRuntimeContext();
|
|
19086
|
+
popRuntimeContext(this.config);
|
|
19057
19087
|
}
|
|
19058
19088
|
}
|
|
19059
19089
|
async runAsync(fn) {
|
|
@@ -19061,7 +19091,7 @@ var VeilixSDK = class _VeilixSDK {
|
|
|
19061
19091
|
try {
|
|
19062
19092
|
return await fn();
|
|
19063
19093
|
} finally {
|
|
19064
|
-
popRuntimeContext();
|
|
19094
|
+
popRuntimeContext(this.config);
|
|
19065
19095
|
}
|
|
19066
19096
|
}
|
|
19067
19097
|
// ── Config ───────────────────────────────────────────────────────────
|