Skip to content

Commit

Permalink
Shield fixes (#354)
Browse files Browse the repository at this point in the history
* Remove sapling prover loader and add target to shield UTXOs

* Avoid recreating a double wrapped error

* Fix restore wallet shield bug

* Update jsdoc

* Prettier

* Fix typo

* Add `target` jsdoc

* Add isCreatingTransaction

* Add loading SHIELD parameters on tx creation

* Fix use wallet test

* fix percentage
  • Loading branch information
Duddino committed May 1, 2024
1 parent 8c3522d commit 6d9dfa5
Show file tree
Hide file tree
Showing 23 changed files with 74 additions and 48 deletions.
3 changes: 2 additions & 1 deletion locale/cnr/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ syncStatusStarting = "<b>Vaš novčanik se sinhronizuje!</b><br>Moći ćete ga p
syncStatusFinished = "<b>Završena sinhronizacija!</b><br>Vaš novčanik je spreman za upotrebu!" # <b>Sync Finished!</b><br>Your wallet is ready to use!
activityReceivedWith = "Primljeno sa {s}" # Received with {s}
accountDeleted = "Vaš nalog je uspešno obrisan!" # Your account has been successfully deleted!
syncLoadingSaplingProver = "" # Loading Sapling Prover
syncLoadingSaplingProver = "" # Loading SHIELD parameters...
syncShieldProgress = "" # Loading shielded blocks {current} of {total}
chartImmatureBalance = "" # Immature balance
useShieldInputs = "" # Use shield inputs
Expand All @@ -220,6 +220,7 @@ settingsToggleAutoLockWallet = "" # Auto Lock the Wallet
saveWalletFile = "" # Save Wallet File
proposalOverBudget = "" # Over Budget
badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root)
creatingShieldTransaction = "" # Creating SHIELD transaction...

[ALERTS]
INTERNAL_ERROR = "Interna greška, molimo pokušajte ponovo kasnije" # Internal error, please try again later
Expand Down
3 changes: 2 additions & 1 deletion locale/de/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ accountDeleted = "Deine Geldbörse wurde erfolgreich gelöscht" # Your account h
activitySelf = "Eigenüberweisung" # self
activityReceivedWith = "Erhalten über {s}" # Received with {s}
chartImmatureBalance = "" # Immature balance
syncLoadingSaplingProver = "" # Loading Sapling Prover
syncLoadingSaplingProver = "" # Loading SHIELD parameters...
syncShieldProgress = "" # Loading shielded blocks {current} of {total}
useShieldInputs = "" # Use shield inputs
newShieldAddress = "" # Get new shield address
Expand All @@ -220,6 +220,7 @@ settingsToggleAutoLockWallet = "" # Auto Lock the Wallet
saveWalletFile = "" # Save Wallet File
proposalOverBudget = "" # Over Budget
badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root)
creatingShieldTransaction = "" # Creating SHIELD transaction...

[ALERTS]
INTERNAL_ERROR = "Interner Fehler, bitte versuche es später erneut" # Internal error, please try again later
Expand Down
3 changes: 2 additions & 1 deletion locale/en/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ syncStatusFinished = "<b>Sync Finished!</b><br>Your wallet is ready to use!" # <
activityReceivedWith = "Received with {s}" # Received with {s}
accountDeleted = "Your account has been successfully deleted!" # Your account has been successfully deleted!
chartImmatureBalance = "Immature balance" # Immature balance
syncLoadingSaplingProver = "Loading Sapling Prover" # Loading Sapling Prover
syncLoadingSaplingProver = "Loading SHIELD parameters..." # Loading SHIELD parameters...
syncShieldProgress = "Loading shielded blocks {current} of {total}" # Loading shielded blocks {current} of {total}
useShieldInputs = "Use shield inputs" # Use shield inputs
newShieldAddress = "Get new shield address" # Get new shield address
Expand All @@ -220,6 +220,7 @@ settingsToggleAutoLockWallet = "Auto Lock the Wallet" # Auto Lock the Wallet
saveWalletFile = "Save Wallet File" # Save Wallet File
proposalOverBudget = "Over Budget" # Over Budget
badSaplingRoot = "There was an error while syncing. Resyncing from scratch (Bad sapling root)" # There was an error while syncing. Resyncing from scratch (Bad sapling root)
creatingShieldTransaction = "Creating SHIELD transaction..." # Creating SHIELD transaction...

[ALERTS]
INTERNAL_ERROR = "Internal error, please try again later" # Internal error, please try again later
Expand Down
3 changes: 2 additions & 1 deletion locale/es-mx/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ contestedProposalsTitle = "" # Contested Proposals
accountDeleted = "" # Your account has been successfully deleted!
activityReceivedWith = "" # Received with {s}
chartImmatureBalance = "" # Immature balance
syncLoadingSaplingProver = "" # Loading Sapling Prover
syncLoadingSaplingProver = "" # Loading SHIELD parameters...
syncShieldProgress = "" # Loading shielded blocks {current} of {total}
useShieldInputs = "" # Use shield inputs
newShieldAddress = "" # Get new shield address
Expand All @@ -220,6 +220,7 @@ settingsToggleAutoLockWallet = "" # Auto Lock the Wallet
saveWalletFile = "" # Save Wallet File
proposalOverBudget = "" # Over Budget
badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root)
creatingShieldTransaction = "" # Creating SHIELD transaction...

[ALERTS]
INTERNAL_ERROR = "Error interno, vuelve a intentarlo más tarde" # Internal error, please try again later
Expand Down
3 changes: 2 additions & 1 deletion locale/fr/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ contestedProposalsTitle = "Propositions contestées" # Contested Proposals
accountDeleted = "" # Your account has been successfully deleted!
activityReceivedWith = "Reçu avec {s}" # Received with {s}
chartImmatureBalance = "" # Immature balance
syncLoadingSaplingProver = "" # Loading Sapling Prover
syncLoadingSaplingProver = "" # Loading SHIELD parameters...
syncShieldProgress = "" # Loading shielded blocks {current} of {total}
useShieldInputs = "" # Use shield inputs
newShieldAddress = "" # Get new shield address
Expand All @@ -220,6 +220,7 @@ settingsToggleAutoLockWallet = "" # Auto Lock the Wallet
saveWalletFile = "" # Save Wallet File
proposalOverBudget = "" # Over Budget
badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root)
creatingShieldTransaction = "" # Creating SHIELD transaction...

[ALERTS]
INTERNAL_ERROR = "Erreur interne, veuillez réessayer plus tard" # Internal error, please try again later
Expand Down
3 changes: 2 additions & 1 deletion locale/it/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ settingsToggleAdvancedModeSubtext = "Sblocca funzionalità e personalizzazioni p
accountDeleted = "Il tuo account è stato eliminato con successo!" # Your account has been successfully deleted!
activityReceivedWith = "Ricevuto con {s}" # Received with {s}
chartImmatureBalance = "Saldo immaturo" # Immature balance
syncLoadingSaplingProver = "Caricamento del Sapling Prover" # Loading Sapling Prover
syncLoadingSaplingProver = "Caricamento del Sapling Prover" # Loading SHIELD parameters...
syncShieldProgress = "Caricamento blocchi shield {current}/{total}" # Loading shielded blocks {current} of {total}
useShieldInputs = "Usa input shield" # Use shield inputs
newShieldAddress = "Genera un nuovo indirizzo shield" # Get new shield address
Expand All @@ -220,6 +220,7 @@ settingsToggleAutoLockWallet = "" # Auto Lock the Wallet
saveWalletFile = "" # Save Wallet File
proposalOverBudget = "" # Over Budget
badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root)
creatingShieldTransaction = "" # Creating SHIELD transaction...

[ALERTS]
INTERNAL_ERROR = "Errore interno, rirova più tardi" # Internal error, please try again later
Expand Down
3 changes: 2 additions & 1 deletion locale/nl/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ syncStatusFinished = "" # <b>Sync Finished!</b><br>Your wallet is ready to use!
accountDeleted = "" # Your account has been successfully deleted!
activityReceivedWith = "" # Received with {s}
chartImmatureBalance = "" # Immature balance
syncLoadingSaplingProver = "" # Loading Sapling Prover
syncLoadingSaplingProver = "" # Loading SHIELD parameters...
syncShieldProgress = "" # Loading shielded blocks {current} of {total}
useShieldInputs = "" # Use shield inputs
newShieldAddress = "" # Get new shield address
Expand All @@ -220,6 +220,7 @@ settingsToggleAutoLockWallet = "" # Auto Lock the Wallet
saveWalletFile = "" # Save Wallet File
proposalOverBudget = "" # Over Budget
badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root)
creatingShieldTransaction = "" # Creating SHIELD transaction...

[ALERTS]
INTERNAL_ERROR = "Interne fout, probeer het later opnieuw" # Internal error, please try again later
Expand Down
3 changes: 2 additions & 1 deletion locale/ph/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ accountDeleted = "" # Your account has been successfully deleted!
activityReceivedWith = "" # Received with {s}
popupProposalName = "" # Proposal Name
chartImmatureBalance = "" # Immature balance
syncLoadingSaplingProver = "" # Loading Sapling Prover
syncLoadingSaplingProver = "" # Loading SHIELD parameters...
syncShieldProgress = "" # Loading shielded blocks {current} of {total}
useShieldInputs = "" # Use shield inputs
newShieldAddress = "" # Get new shield address
Expand All @@ -220,6 +220,7 @@ settingsToggleAutoLockWallet = "" # Auto Lock the Wallet
saveWalletFile = "" # Save Wallet File
proposalOverBudget = "" # Over Budget
badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root)
creatingShieldTransaction = "" # Creating SHIELD transaction...

[ALERTS]
INTERNAL_ERROR = "Internal error, Pakiusap uliting muli" # Internal error, please try again later
Expand Down
3 changes: 2 additions & 1 deletion locale/pl/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ syncStatusStarting = "<b>Twój portfel jest w trakcie synchronizacji!</b><br>Po
syncStatusFinished = "<b>Synchronizacja Zakończona!</b><br>Twój portfel jest gotowy do użycia!" # <b>Sync Finished!</b><br>Your wallet is ready to use!
activityReceivedWith = "Otrzymano z {s}" # Received with {s}
accountDeleted = "Twoje konto zostało pomyślnie usunięte!" # Your account has been successfully deleted!
syncLoadingSaplingProver = "" # Loading Sapling Prover
syncLoadingSaplingProver = "" # Loading SHIELD parameters...
syncShieldProgress = "" # Loading shielded blocks {current} of {total}
chartImmatureBalance = "" # Immature balance
useShieldInputs = "" # Use shield inputs
Expand All @@ -220,6 +220,7 @@ settingsToggleAutoLockWallet = "" # Auto Lock the Wallet
saveWalletFile = "" # Save Wallet File
proposalOverBudget = "" # Over Budget
badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root)
creatingShieldTransaction = "" # Creating SHIELD transaction...

[ALERTS]
INTERNAL_ERROR = "Błąd wewnętrzny, spróbuj ponownie później" # Internal error, please try again later
Expand Down
3 changes: 2 additions & 1 deletion locale/pt-br/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ syncStatusStarting = "<b>Sua carteira está sincronizando!</b><br>Você poderá
syncStatusFinished = "<b> Sincronização Terminada!</b><br>Sua carteira está pronta para ser utilizada" # <b>Sync Finished!</b><br>Your wallet is ready to use!
accountDeleted = "Sua conta foi deletada com successo" # Your account has been successfully deleted!
chartImmatureBalance = "" # Immature balance
syncLoadingSaplingProver = "" # Loading Sapling Prover
syncLoadingSaplingProver = "" # Loading SHIELD parameters...
syncShieldProgress = "" # Loading shielded blocks {current} of {total}
useShieldInputs = "" # Use shield inputs
newShieldAddress = "" # Get new shield address
Expand All @@ -87,6 +87,7 @@ settingsToggleAutoLockWallet = "" # Auto Lock the Wallet
saveWalletFile = "" # Save Wallet File
proposalOverBudget = "" # Over Budget
badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root)
creatingShieldTransaction = "" # Creating SHIELD transaction...

[ALERTS]
STAKE_ADDR_SET = "<b>Endereço de Cold Staking definido!</b><br>Ao fazer Stake no futuro este endereço irá ser usado." # <b>Cold Address set!</b><br>Future stakes will use this address.
Expand Down
3 changes: 2 additions & 1 deletion locale/pt-pt/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ syncStatusStarting = "<b>Sua carteira está sincronizando!</b><br>Você poderá
syncStatusFinished = "<b>Sincronização concluída!</b><br>Sua carteira está pronta para uso!" # <b>Sync Finished!</b><br>Your wallet is ready to use!
accountDeleted = "Sua conta foi excluída com sucesso!" # Your account has been successfully deleted!
chartImmatureBalance = "" # Immature balance
syncLoadingSaplingProver = "" # Loading Sapling Prover
syncLoadingSaplingProver = "" # Loading SHIELD parameters...
syncShieldProgress = "" # Loading shielded blocks {current} of {total}
useShieldInputs = "" # Use shield inputs
newShieldAddress = "" # Get new shield address
Expand All @@ -87,6 +87,7 @@ settingsToggleAutoLockWallet = "" # Auto Lock the Wallet
saveWalletFile = "" # Save Wallet File
proposalOverBudget = "" # Over Budget
badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root)
creatingShieldTransaction = "" # Creating SHIELD transaction...

[ALERTS]
STAKE_ADDR_SET = "<b>Endereço de Cold Staking definido!</b><br>Ao fazer Stake no futuro irá ser usado este endereço." # <b>Cold Address set!</b><br>Future stakes will use this address.
Expand Down
3 changes: 2 additions & 1 deletion locale/template/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ secureYourWallet = "Secure your wallet"
unlockWallet = "Unlock wallet"
lockWallet = "Lock wallet"
syncStatusHistoryProgress = "Syncing History Chunks {current} of {total}"
syncLoadingSaplingProver = "Loading Sapling Prover"
syncLoadingSaplingProver = "Loading SHIELD parameters..."
syncShieldProgress = "Loading shielded blocks {current} of {total}"
syncStatusStarting = "<b>Your wallet is syncing!</b><br>You'll be able to use it fully once this is complete."
syncStatusFinished = "<b>Sync Finished!</b><br>Your wallet is ready to use!"
Expand Down Expand Up @@ -244,6 +244,7 @@ newShieldAddress = "Get new shield address"
shieldAddress = "Shield address"
cantShieldToExc = "This address does not support shield transfers"
badSaplingRoot = "There was an error while syncing. Resyncing from scratch (Bad sapling root)"
creatingShieldTransaction = "Creating SHIELD transaction..."

[ALERTS]
INTERNAL_ERROR = "Internal error, please try again later"
Expand Down
3 changes: 2 additions & 1 deletion locale/uwu/translation.toml
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ accountDeleted = "" # Your account has been successfully deleted!
activityShieldedAddress = "" # Shielded address
activityReceivedWith = "" # Received with {s}
chartImmatureBalance = "" # Immature balance
syncLoadingSaplingProver = "" # Loading Sapling Prover
syncLoadingSaplingProver = "" # Loading SHIELD parameters...
syncShieldProgress = "" # Loading shielded blocks {current} of {total}
useShieldInputs = "" # Use shield inputs
newShieldAddress = "" # Get new shield address
Expand All @@ -220,6 +220,7 @@ settingsToggleAutoLockWallet = "" # Auto Lock the Wallet
saveWalletFile = "Save Wawwet File" # Save Wallet File
proposalOverBudget = "Over Budgey" # Over Budget
badSaplingRoot = "" # There was an error while syncing. Resyncing from scratch (Bad sapling root)
creatingShieldTransaction = "" # Creating SHIELD transaction...

[ALERTS]
INTERNAL_ERROR = "Internal error, pwease try again later" # Internal error, please try again later
Expand Down
6 changes: 4 additions & 2 deletions scripts/composables/use_wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export const useWallet = defineStore('wallet', () => {
const loadFromDisk = () => wallet.loadFromDisk();
const hasShield = ref(wallet.hasShield());

const setMasterKey = async (mk) => {
wallet.setMasterKey(mk);
const setMasterKey = async ({ mk, extsk }) => {
wallet.setMasterKey({ mk, extsk });
isImported.value = wallet.isLoaded();
isHardwareWallet.value = wallet.isHardwareWallet();
isHD.value = wallet.isHD();
Expand Down Expand Up @@ -90,6 +90,7 @@ export const useWallet = defineStore('wallet', () => {
return res;
}
);
const isCreatingTransaction = () => createAndSendTransaction.isLocked();

getEventEmitter().on('toggle-network', async () => {
isEncrypted.value = await hasEncryptedWallet();
Expand Down Expand Up @@ -122,6 +123,7 @@ export const useWallet = defineStore('wallet', () => {
wallet.wipePrivateData();
isViewOnly.value = wallet.isViewOnly();
},
isCreatingTransaction,
isHD,
balance,
hasShield,
Expand Down
11 changes: 4 additions & 7 deletions scripts/dashboard/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ async function importWallet({ type, secret, password = '' }) {
);
}
if (parsedSecret) {
await wallet.setMasterKey(parsedSecret.masterKey);
await wallet.setMasterKey({ mk: parsedSecret.masterKey });
wallet.setShield(parsedSecret.shield);
jdenticonValue.value = wallet.getAddress();
Expand Down Expand Up @@ -155,16 +155,13 @@ async function restoreWallet(strReason) {
async function importWif(wif, extsk) {
const secret = await ParsedSecret.parse(wif);
if (secret.masterKey) {
await wallet.setMasterKey(secret.masterKey);
await wallet.setMasterKey({ mk: secret.masterKey, extsk });
if (wallet.hasShield && !extsk) {
createAlert(
'warning',
'Could not decrypt sk even if password is correct, please contact a developer'
);
}
if (wallet.hasShield) {
await wallet.setExtsk(extsk);
}
createAlert('success', ALERTS.WALLET_UNLOCKED, 1500);
}
}
Expand Down Expand Up @@ -226,7 +223,7 @@ async function send(address, amount, useShieldInputs) {
}
// Make sure we are not already creating a (shield) tx
if (wallet.createAndSendTransaction.isLocked()) {
if (wallet.isCreatingTransaction()) {
return createAlert(
'warning',
'Already creating a transaction! please wait for it to finish'
Expand Down Expand Up @@ -357,7 +354,7 @@ function getMaxBalance(useShieldInputs) {
getEventEmitter().on('toggle-network', async () => {
const database = await Database.getInstance();
const account = await database.getAccount();
await wallet.setMasterKey(null);
await wallet.setMasterKey({ mk: null });
activity.value?.reset();
if (wallet.isEncrypted) {
Expand Down
10 changes: 8 additions & 2 deletions scripts/dashboard/WalletBalance.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const syncSStr = ref('');
// Shield transaction creation
const isCreatingTx = ref(false);
const txPercentageCreation = ref(0.0);
const txCreationStr = 'Creating SHIELD transaction...';
const txCreationStr = ref('Creating SHIELD transaction...');
const balanceStr = computed(() => {
const nCoins = balance.value / COIN;
Expand Down Expand Up @@ -116,9 +116,15 @@ getEventEmitter().on('shield-sync-status-update', (str, finished) => {
getEventEmitter().on(
'shield-transaction-creation-update',
async (percentage, finished) => {
if (percentage === 0.0 && !finished) {
txCreationStr.value = translation.syncLoadingSaplingProver;
} else {
txCreationStr.value = translation.creatingShieldTransaction;
}
// If it just finished sleep for 1 second before making everything invisible
txPercentageCreation.value = 100.0;
if (finished) {
txPercentageCreation.value = 100.0;
await sleep(1000);
}
isCreatingTx.value = !finished;
Expand Down
2 changes: 1 addition & 1 deletion scripts/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ export async function sweepAddress(arrUTXOs, sweepingMasterKey, nFixedFee) {

// Sign using the given Master Key, then broadcast the sweep, returning the TXID (or a failure)
const sweepingWallet = new Wallet({ nAccount: 0 });
sweepingWallet.setMasterKey(sweepingMasterKey);
sweepingWallet.setMasterKey({ mk: sweepingMasterKey });

await sweepingWallet.sign(tx);
return await getNetwork().sendTransaction(tx.serialize());
Expand Down
1 change: 1 addition & 0 deletions scripts/mempool.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ export class Mempool {
* By default it's `OutpointState.SPENT | OutpointState.IMMATURE | OutpointState.LOCKED`
* @param {number} [o.requirement] - A requirement to apply to all UTXOs. For example
* `OutpointState.P2CS` will only return P2CS transactions.
* @param {number} [o.target] - Number of satoshis needed. The method will return early when the value of the UTXOs has been reached, plus a bit to account for change
* By default it's MAX_SAFE_INTEGER
* @returns {UTXO[]} a list of unspent transaction outputs
*/
Expand Down
5 changes: 1 addition & 4 deletions scripts/stake/Stake.vue
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,13 @@ async function restoreWallet(strReason) {
async function importWif(wif, extsk) {
const secret = await ParsedSecret.parse(wif);
if (secret.masterKey) {
await wallet.setMasterKey(secret.masterKey);
await wallet.setMasterKey({ mk: secret.masterKey, extsk });
if (wallet.hasShield && !extsk) {
createAlert(
'warning',
'Could not decrypt sk even if password is correct, please contact a developer'
);
}
if (wallet.hasShield) {
await wallet.setExtsk(extsk);
}
createAlert('success', ALERTS.WALLET_UNLOCKED, 1500);
}
}
Expand Down
Loading

0 comments on commit 6d9dfa5

Please sign in to comment.