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/react/index.d.cts
CHANGED
package/dist/react/index.d.ts
CHANGED
package/dist/react/index.js
CHANGED
|
@@ -8264,7 +8264,7 @@ function getDepositQueueForNetwork(network) {
|
|
|
8264
8264
|
// package.json
|
|
8265
8265
|
var package_default = {
|
|
8266
8266
|
name: "veilix-sdk",
|
|
8267
|
-
version: "0.3.
|
|
8267
|
+
version: "0.3.1"};
|
|
8268
8268
|
|
|
8269
8269
|
// src/circuits/constants.ts
|
|
8270
8270
|
var PACKAGE_NAME = package_default.name;
|
|
@@ -8439,10 +8439,19 @@ async function createRuntimeConfig(options) {
|
|
|
8439
8439
|
};
|
|
8440
8440
|
}
|
|
8441
8441
|
function pushRuntimeContext(config) {
|
|
8442
|
+
const active = runtimeContextStack.find((other) => other.programId !== config.programId);
|
|
8443
|
+
if (active) {
|
|
8444
|
+
throw new Error(
|
|
8445
|
+
`veilix-sdk: another SDK instance is running on program ${active.programId}; instances on different networks must run one at a time`
|
|
8446
|
+
);
|
|
8447
|
+
}
|
|
8442
8448
|
runtimeContextStack.push(config);
|
|
8443
8449
|
}
|
|
8444
|
-
function popRuntimeContext() {
|
|
8445
|
-
runtimeContextStack.
|
|
8450
|
+
function popRuntimeContext(config) {
|
|
8451
|
+
const index = runtimeContextStack.lastIndexOf(config);
|
|
8452
|
+
if (index !== -1) {
|
|
8453
|
+
runtimeContextStack.splice(index, 1);
|
|
8454
|
+
}
|
|
8446
8455
|
}
|
|
8447
8456
|
function getConfig() {
|
|
8448
8457
|
const active = runtimeContextStack.at(-1);
|
|
@@ -17633,9 +17642,11 @@ async function buildDepositTx({
|
|
|
17633
17642
|
onChainBackup = false,
|
|
17634
17643
|
computeUnitPrice = 5e3,
|
|
17635
17644
|
computeUnitLimit = DEPOSIT_COMPUTE_UNIT_LIMIT,
|
|
17636
|
-
circuitArtifacts
|
|
17645
|
+
circuitArtifacts,
|
|
17646
|
+
encryptKey
|
|
17637
17647
|
}) {
|
|
17638
17648
|
const { connection } = getConfig();
|
|
17649
|
+
const sealKey = onChainBackup ? encryptKey ?? requireEncryptKey() : null;
|
|
17639
17650
|
const sender = toPublicKey(senderPublicKey);
|
|
17640
17651
|
const utxo = decodeNote(note);
|
|
17641
17652
|
const mint = utxo.mint;
|
|
@@ -17648,7 +17659,7 @@ async function buildDepositTx({
|
|
|
17648
17659
|
`veilix-sdk: deposit amount ${utxo.amount} exceeds the tree limit of ${tree.maxDepositAmount}`
|
|
17649
17660
|
);
|
|
17650
17661
|
}
|
|
17651
|
-
const encryptedOutput1 =
|
|
17662
|
+
const encryptedOutput1 = sealKey ? encryptNoteOutput(sealKey, utxo) : new Uint8Array();
|
|
17652
17663
|
const encryptedOutput2 = new Uint8Array();
|
|
17653
17664
|
const proved = await withCircuitArtifacts(
|
|
17654
17665
|
circuitArtifacts,
|
|
@@ -17703,16 +17714,15 @@ async function buildInitNotesInstructionIfNeeded(sender) {
|
|
|
17703
17714
|
if (await fetchNotesAccount(sender)) return null;
|
|
17704
17715
|
return program.methods.initNotes().accountsPartial({ user: sender }).instruction();
|
|
17705
17716
|
}
|
|
17706
|
-
async function resolveEncryptKey() {
|
|
17707
|
-
const config = getConfig();
|
|
17717
|
+
async function resolveEncryptKey(config) {
|
|
17708
17718
|
if (!config.encryptKey) {
|
|
17709
17719
|
config.encryptKey = await getEncryptionKey(config.wallet);
|
|
17710
17720
|
}
|
|
17711
17721
|
return config.encryptKey;
|
|
17712
17722
|
}
|
|
17713
|
-
async function buildBackupNotesInstruction(sender, notes) {
|
|
17714
|
-
const { program } =
|
|
17715
|
-
const key2 = await resolveEncryptKey();
|
|
17723
|
+
async function buildBackupNotesInstruction(sender, notes, config = getConfig()) {
|
|
17724
|
+
const { program } = config;
|
|
17725
|
+
const key2 = await resolveEncryptKey(config);
|
|
17716
17726
|
return program.methods.backupNotes(notes.map((note) => encryptData(key2, note))).accountsPartial({ user: sender }).instruction();
|
|
17717
17727
|
}
|
|
17718
17728
|
async function isExtendBackupPdaNeeded(walletPubkey, newNotesLength) {
|
|
@@ -17725,7 +17735,8 @@ function buildRequestHeapIx() {
|
|
|
17725
17735
|
return ComputeBudgetProgram.requestHeapFrame({ bytes: 32 * 1024 });
|
|
17726
17736
|
}
|
|
17727
17737
|
async function buildBackupNotesTx(senderPublicKey, notes) {
|
|
17728
|
-
const
|
|
17738
|
+
const config = getConfig();
|
|
17739
|
+
const { connection } = config;
|
|
17729
17740
|
const sender = toPublicKey(senderPublicKey);
|
|
17730
17741
|
const tx = new Transaction();
|
|
17731
17742
|
const initIx = await buildInitNotesInstructionIfNeeded(sender);
|
|
@@ -17734,7 +17745,7 @@ async function buildBackupNotesTx(senderPublicKey, notes) {
|
|
|
17734
17745
|
} else if (await isExtendBackupPdaNeeded(sender, notes.length)) {
|
|
17735
17746
|
tx.add(buildRequestHeapIx());
|
|
17736
17747
|
}
|
|
17737
|
-
tx.add(await buildBackupNotesInstruction(sender, notes));
|
|
17748
|
+
tx.add(await buildBackupNotesInstruction(sender, notes, config));
|
|
17738
17749
|
tx.recentBlockhash = (await connection.getLatestBlockhash()).blockhash;
|
|
17739
17750
|
tx.feePayer = sender;
|
|
17740
17751
|
return tx;
|
|
@@ -18866,6 +18877,8 @@ var SEND_OPTIONS = { skipPreflight: false, maxRetries: 3 };
|
|
|
18866
18877
|
var SUBMIT_MAX_PROOFS = 8;
|
|
18867
18878
|
var NOTE_INDEX_TIMEOUT_MS = 12e4;
|
|
18868
18879
|
var NOTE_INDEX_POLL_MS = 4e3;
|
|
18880
|
+
var SEND_ATTEMPTS = 4;
|
|
18881
|
+
var SEND_RETRY_MS = 2e3;
|
|
18869
18882
|
function sleep(ms) {
|
|
18870
18883
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
18871
18884
|
}
|
|
@@ -18887,7 +18900,18 @@ async function signTransactions(wallet, transactions) {
|
|
|
18887
18900
|
}
|
|
18888
18901
|
async function sendAndConfirm(signed) {
|
|
18889
18902
|
const { connection } = getConfig();
|
|
18890
|
-
const
|
|
18903
|
+
const raw = signed.serialize();
|
|
18904
|
+
let signature;
|
|
18905
|
+
for (let attempt = 1; signature === void 0; attempt++) {
|
|
18906
|
+
try {
|
|
18907
|
+
signature = await connection.sendRawTransaction(raw, SEND_OPTIONS);
|
|
18908
|
+
} catch (error) {
|
|
18909
|
+
if (attempt >= SEND_ATTEMPTS || !/blockhash not found/i.test(errorMessage(error))) {
|
|
18910
|
+
throw error;
|
|
18911
|
+
}
|
|
18912
|
+
await sleep(SEND_RETRY_MS);
|
|
18913
|
+
}
|
|
18914
|
+
}
|
|
18891
18915
|
const { value } = await connection.confirmTransaction(signature, "confirmed");
|
|
18892
18916
|
if (value.err) {
|
|
18893
18917
|
throw new Error(`Deposit transaction failed: ${JSON.stringify(value.err)}`);
|
|
@@ -18933,6 +18957,7 @@ async function executeVeilixTransfer(items, options = {}) {
|
|
|
18933
18957
|
const { wallet, network, relayers, encryptKey } = getConfig();
|
|
18934
18958
|
const sender = wallet.publicKey;
|
|
18935
18959
|
const onChainBackup = options.onChainBackup ?? !!encryptKey;
|
|
18960
|
+
const sealKey = onChainBackup ? encryptKey ?? requireEncryptKey() : void 0;
|
|
18936
18961
|
const prepared = prepareDeposits(items);
|
|
18937
18962
|
result.notes = prepared.map((deposit) => deposit.note);
|
|
18938
18963
|
const circuitArtifacts = await prepareWithdrawCircuitArtifacts();
|
|
@@ -18943,7 +18968,8 @@ async function executeVeilixTransfer(items, options = {}) {
|
|
|
18943
18968
|
senderPublicKey: sender,
|
|
18944
18969
|
note: deposit.note,
|
|
18945
18970
|
onChainBackup,
|
|
18946
|
-
circuitArtifacts
|
|
18971
|
+
circuitArtifacts,
|
|
18972
|
+
...sealKey ? { encryptKey: sealKey } : {}
|
|
18947
18973
|
});
|
|
18948
18974
|
} catch (error) {
|
|
18949
18975
|
result.depositFailed.push(toDepositFailure(deposit, error));
|
|
@@ -18954,6 +18980,10 @@ async function executeVeilixTransfer(items, options = {}) {
|
|
|
18954
18980
|
result.error = true;
|
|
18955
18981
|
return result;
|
|
18956
18982
|
}
|
|
18983
|
+
const { blockhash } = await getConfig().connection.getLatestBlockhash();
|
|
18984
|
+
toSend.forEach((deposit) => {
|
|
18985
|
+
deposit.tx.message.recentBlockhash = blockhash;
|
|
18986
|
+
});
|
|
18957
18987
|
const signed = await signTransactions(wallet, toSend.map((deposit) => deposit.tx));
|
|
18958
18988
|
if (options.downloadNotes ?? true) {
|
|
18959
18989
|
downloadNotesCsv(toSend.map((deposit) => deposit.note));
|
|
@@ -19057,7 +19087,7 @@ var VeilixSDK = class _VeilixSDK {
|
|
|
19057
19087
|
try {
|
|
19058
19088
|
return fn();
|
|
19059
19089
|
} finally {
|
|
19060
|
-
popRuntimeContext();
|
|
19090
|
+
popRuntimeContext(this.config);
|
|
19061
19091
|
}
|
|
19062
19092
|
}
|
|
19063
19093
|
async runAsync(fn) {
|
|
@@ -19065,7 +19095,7 @@ var VeilixSDK = class _VeilixSDK {
|
|
|
19065
19095
|
try {
|
|
19066
19096
|
return await fn();
|
|
19067
19097
|
} finally {
|
|
19068
|
-
popRuntimeContext();
|
|
19098
|
+
popRuntimeContext(this.config);
|
|
19069
19099
|
}
|
|
19070
19100
|
}
|
|
19071
19101
|
// ── Config ───────────────────────────────────────────────────────────
|