From c26869a1df21f9e0e7dde83a811614e0f5f06931 Mon Sep 17 00:00:00 2001 From: vantuz-subhuman Date: Wed, 11 Dec 2024 17:43:47 +0300 Subject: [PATCH] not asserting withdrawals to be strictly local --- .../api/ada/transactions/shelley/ledgerTx.js | 32 +++++++++++++++---- .../api/ada/transactions/shelley/trezorTx.js | 11 ++++--- .../app/connector/stores/ConnectorStore.js | 2 +- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/packages/yoroi-extension/app/api/ada/transactions/shelley/ledgerTx.js b/packages/yoroi-extension/app/api/ada/transactions/shelley/ledgerTx.js index bd5c4300bc..d1b842f953 100644 --- a/packages/yoroi-extension/app/api/ada/transactions/shelley/ledgerTx.js +++ b/packages/yoroi-extension/app/api/ada/transactions/shelley/ledgerTx.js @@ -304,17 +304,37 @@ function formatLedgerWithdrawals( for (const [rewardAddress, withdrawalAmount] of iterateLenGetMap(withdrawals).nonNullValue()) { const rewardAddressPayload = rewardAddress.to_address().to_hex(); const addressing = addressingMap(rewardAddressPayload); - if (addressing == null) { - throw new Error(`${nameof(formatLedgerWithdrawals)} Ledger can only withdraw from own address ${rewardAddressPayload}`); + let stakeCredential; + if (addressing != null) { + stakeCredential = { + type: CredentialParamsType.KEY_PATH, + keyPath: addressing.path, + }; + } else { + const cred = rewardAddress.payment_cred(); + const maybeKeyHash = cred.to_keyhash(); + const maybeScriptHash = cred.to_scripthash(); + if (maybeKeyHash) { + stakeCredential = { + type: CredentialParamsType.KEY_HASH, + keyHashHex: maybeKeyHash.to_hex(), + }; + } else if (maybeScriptHash) { + stakeCredential = { + type: CredentialParamsType.SCRIPT_HASH, + keyHashHex: maybeScriptHash.to_hex(), + }; + } + } + if (stakeCredential == null) { + throw new Error('Failed to resolve credential type for reward address: ' + rewardAddressPayload); } result.push({ amount: withdrawalAmount.to_str(), - stakeCredential: { - type: CredentialParamsType.KEY_PATH, - keyPath: addressing.path, - }, + stakeCredential, }); } + // $FlowIgnore[incompatible-return] return result; } diff --git a/packages/yoroi-extension/app/api/ada/transactions/shelley/trezorTx.js b/packages/yoroi-extension/app/api/ada/transactions/shelley/trezorTx.js index 9164d0150d..da6bebe6cf 100644 --- a/packages/yoroi-extension/app/api/ada/transactions/shelley/trezorTx.js +++ b/packages/yoroi-extension/app/api/ada/transactions/shelley/trezorTx.js @@ -760,12 +760,13 @@ export function toTrezorSignRequest( for (const [rewardAddress, withdrawalAmount] of iterateLenGetMap(withdrawals).nonNullValue()) { const rewardAddressPayload = rewardAddress.to_address().to_hex(); const path = ownAddressMap(rewardAddressPayload); - if (path != null) { - result.push({ - amount: withdrawalAmount.to_str(), - path, - }); + if (path == null) { + throw new Error('foreign withdrawal reward address'); } + result.push({ + amount: withdrawalAmount.to_str(), + path, + }); } formattedWithdrawals = result; } diff --git a/packages/yoroi-extension/app/connector/stores/ConnectorStore.js b/packages/yoroi-extension/app/connector/stores/ConnectorStore.js index 896ac1c92b..3c5d160ca3 100644 --- a/packages/yoroi-extension/app/connector/stores/ConnectorStore.js +++ b/packages/yoroi-extension/app/connector/stores/ConnectorStore.js @@ -1065,7 +1065,7 @@ export default class ConnectorStore extends Store { addressedUtxos, ); } catch (e) { - console.error('Failed to construct the Ledger sign request: ', e); + console.error('toTrezorSignRequest failed: ', e); runInAction(() => { this.hwWalletError = unsupportedTransactionError; this.isHwWalletErrorRecoverable = false;