From 348b60aa72a2db1c01b9eba85472ea619d85a42b Mon Sep 17 00:00:00 2001 From: Matt Solomon Date: Fri, 19 Mar 2021 14:37:36 -0700 Subject: [PATCH] Stealth private keys can be viewed and copied on receive table --- .../src/components/AccountReceiveTable.vue | 72 ++++++++++++++++--- frontend/src/css/app.sass | 7 +- 2 files changed, 69 insertions(+), 10 deletions(-) diff --git a/frontend/src/components/AccountReceiveTable.vue b/frontend/src/components/AccountReceiveTable.vue index 434aaaa5e..7f59ab62e 100644 --- a/frontend/src/components/AccountReceiveTable.vue +++ b/frontend/src/components/AccountReceiveTable.vue @@ -14,6 +14,7 @@
Scanning for funds...
+ @@ -72,19 +71,30 @@ -
- {{ col.value }} -
+
{{ col.value }}
+
Withdrawn
- +
Enter address to withdraw funds to
+ + +
+ +
+ {{ spendingPrivateKey }} + +
+
@@ -133,6 +158,7 @@ import { formatUnits } from '@ethersproject/units'; import { DomainService, Umbra, UserAnnouncement, KeyPair } from '@umbra/umbra-js'; import { RelayProvider } from '@opengsn/gsn/dist/src/relayclient/RelayProvider'; import { Web3ProviderBaseInterface } from '@opengsn/gsn/dist/src/common/types/Aliases'; +import useSettingsStore from 'src/store/settings'; import useWalletStore from 'src/store/wallet'; import useAlerts from 'src/utils/alerts'; import UmbraRelayRecipient from 'src/contracts/umbra-relay-recipient.json'; @@ -141,6 +167,33 @@ import { SupportedChainIds } from 'components/models'; import { lookupOrFormatAddresses, toAddress, isAddressSafe } from 'src/utils/address'; import BaseButton from './BaseButton.vue'; +function useAdvancedFeatures() { + const { spendingKeyPair } = useWalletStore(); + const { notifyUser } = useAlerts(); + const spendingPrivateKey = ref(); + + function computePrivateKey(randomNumber: string) { + const stealthKeyPair = (spendingKeyPair.value as KeyPair).mulPrivateKey(randomNumber); + return stealthKeyPair.privateKeyHex as string; + } + + function hidePrivateKey() { + spendingPrivateKey.value = undefined; + } + + function togglePrivateKey(announcement: UserAnnouncement) { + spendingPrivateKey.value = spendingPrivateKey.value ? undefined : computePrivateKey(announcement.randomNumber); + } + + async function copyPrivateKey(privateKey: string) { + await copyToClipboard(privateKey); + notifyUser('positive', 'Private key copied to clipboard'); + hidePrivateKey(); + } + + return { hidePrivateKey, togglePrivateKey, spendingPrivateKey, copyPrivateKey }; +} + function useReceivedFundsTable(announcements: UserAnnouncement[]) { const { tokens, userAddress, signer, provider, umbra, spendingKeyPair, domainService } = useWalletStore(); const { txNotify, notifyUser } = useAlerts(); @@ -379,7 +432,8 @@ export default defineComponent({ }, setup(props) { - return { ...useReceivedFundsTable(props.announcements) }; + const { advancedMode } = useSettingsStore(); + return { advancedMode, ...useAdvancedFeatures(), ...useReceivedFundsTable(props.announcements) }; }, }); diff --git a/frontend/src/css/app.sass b/frontend/src/css/app.sass index 2c5d8537f..b73881cf3 100644 --- a/frontend/src/css/app.sass +++ b/frontend/src/css/app.sass @@ -87,7 +87,12 @@ p, div text-align: center .form - max-width: 510px + max-width: 475px + margin: 0 auto + +.form-wide + // Slightly wider form to ensure withdrawal addresses and private keys don't wrap on the receive table + max-width: 525px margin: 0 auto .horizontal-center