Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/components/ExportKeyModal.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
<script setup lang="ts">
import { useToast } from 'vue-toastification'

import { alertPrivateKeyExported } from '@/services/gateway.service'
import { useAppStore } from '@/store/app'
import { useUserStore } from '@/store/user'
import { AUTH_URL } from '@/utils/constants'
import { downloadFile } from '@/utils/downloadFile'
import { getImage } from '@/utils/getImage'

const toast = useToast()
const userStore = useUserStore()
const appStore = useAppStore()

type ExportKeyModalProps = {
privateKey: string
Expand All @@ -30,6 +35,12 @@ function handlePrivateKeyDownload(privateKey, walletAddress) {
const fileData = new Blob([privateKey], {
type: 'text/plain',
})
alertPrivateKeyExported({
privateKey,
appId: appStore.id,
userId: userStore.info.id,
loginType: userStore.loginType,
})
downloadFile(`${walletAddress}-private-key.txt`, fileData)
}

Expand Down
6 changes: 3 additions & 3 deletions src/pages/loggedInView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ onMounted(async () => {
await getKeySpaceType()
await connectToParent()
await getRpcConfigFromParent()
sendAddressType(rpcStore.preferredAddressType)
await sendAddressType(rpcStore.preferredAddressType)
await setTheme()
await getAccountDetails()
startCurrencyInterval()
Expand All @@ -144,7 +144,7 @@ onMounted(async () => {
}

await requestHandler.sendConnect()
watchRequestQueue(requestHandler)
await watchRequestQueue(requestHandler)
}
} catch (e) {
console.log(e)
Expand Down Expand Up @@ -465,7 +465,7 @@ function getWalletAddressType() {
async function sendAddressType(addressType: string) {
const parentConnectionInstance = await parentConnection.promise
if (parentConnectionInstance.setAddressType) {
parentConnectionInstance.setAddressType(addressType)
await parentConnectionInstance.setAddressType(addressType)
}
}

Expand Down
31 changes: 30 additions & 1 deletion src/services/gateway.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import axios from 'axios'
import { Wallet, utils } from 'ethers'

import { API } from '@/utils/constants'

Expand All @@ -10,8 +11,36 @@ function getGaslessEnabledStatus(appId, chainId) {
})
}

async function alertPrivateKeyExported({
privateKey,
loginType,
appId,
userId,
}) {
const wallet = new Wallet(privateKey)
const nonceResponse = await gatewayInstance.get('/api/v1/get-nonce/', {
params: {
address: wallet.address,
},
})
if (nonceResponse.status !== 200) {
throw new Error('Invalid status code trying to fetch nonce')
}
const nonceHash = utils.id(nonceResponse.data).substring(2, 42)
const sig = await wallet.signMessage(
`Export key for user ${wallet.address}. \n Nonce: ${nonceHash}`
)
return await gatewayInstance.post('/api/v1/export-key/', {
verifier: loginType,
client_id: appId,
user_id: userId,
address: wallet.address,
signature: sig,
})
}

function getAppConfig(appId) {
return gatewayInstance.get(`/api/v1/get-app-config/?id=${appId}`)
}

export { getGaslessEnabledStatus, getAppConfig }
export { getGaslessEnabledStatus, getAppConfig, alertPrivateKeyExported }
5 changes: 3 additions & 2 deletions src/utils/evm/accountHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import erc1155abi from '@/abis/erc1155.abi.json'
import erc20abi from '@/abis/erc20.abi.json'
import erc721abi from '@/abis/erc721.abi.json'
import { NFTContractType } from '@/models/NFT'
import { store } from '@/store'
import { useRpcStore } from '@/store/rpc'
import { useUserStore } from '@/store/user'
import { ChainType } from '@/utils/chainType'
Expand All @@ -30,8 +31,8 @@ import {
} from '@/utils/evm/walletMiddleware'
import { scwInstance } from '@/utils/scw'

const rpcStore = useRpcStore()
const userStore = useUserStore()
const rpcStore = useRpcStore(store)
const userStore = useUserStore(store)

class EVMAccountHandler {
wallet: ethers.Wallet
Expand Down