Skip to content

Commit

Permalink
add function to component
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkNerdi committed Aug 29, 2023
1 parent 6b4e199 commit 39360de
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/desktop/components/popups/SignMessagePopup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
import { onMount } from 'svelte'
import { selectedAccount } from '@core/account/stores'
import { JsonRpcResponse } from '@walletconnect/jsonrpc-types'
import { sleep, truncateString } from '@core/utils'
import { truncateString } from '@core/utils'
import { IConnectedDapp } from '@auxiliary/wallet-connect/interface'
import { IAccountState } from '@core/account'
import { IChain } from '@core/network'
import { signMessage } from '@core/wallet/actions'
export let _onMount: (..._: any[]) => Promise<void> = async () => {}
export let requestId: number
Expand Down Expand Up @@ -37,9 +38,10 @@
}
async function sign(): Promise<string> {
// TODO: Replace this with the correct signing implementation
await sleep(500)
return '0x3123'
const { chainId, coinType } = chain.getConfiguration()
const signedMessage = await signMessage(message, chainId, coinType, account)
return signedMessage
}
function onCancelClick(): void {
Expand Down
1 change: 1 addition & 0 deletions packages/shared/src/lib/core/wallet/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ export * from './mintNft'
export * from './rejectActivity'
export * from './sendOutput'
export * from './unwrapStardustAsset'
export * from './signMessage'

export * from './send'
45 changes: 45 additions & 0 deletions packages/shared/src/lib/core/wallet/actions/signMessage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { IAccountState } from '@core/account'
import { updateSelectedAccount } from '@core/account/stores'
import { handleError } from '@core/error/handlers'
import { EvmChainId } from '@core/network/enums'
import { isActiveLedgerProfile, isSoftwareProfile } from '@core/profile/stores'
import { get } from 'svelte/store'
import { closePopup } from '../../../../../../desktop/lib/auxiliary/popup'
import { signMessageWithStronghold } from '@core/stronghold/utils'

export async function signMessage(
message: string,
chainId: EvmChainId,
coinType: number,
account: IAccountState
): Promise<string | undefined> {
try {
updateSelectedAccount({ isTransferring: true })

const bip44Path = {
coinType,
account: account.index,
change: 0,
addressIndex: 0,
}
let signedMessage: string | undefined
if (get(isSoftwareProfile)) {
signedMessage = await signMessageWithStronghold(message, 'eth_sign', bip44Path, chainId, account)
// } else if (get(isActiveLedgerProfile)) {
// signedMessage = await Ledger.signEvmTransaction(txData, chainId, bip44Path)
}

if (!signedMessage) {
if (get(isActiveLedgerProfile)) {
closePopup(true)
}
throw new Error('No signature provided')
}

return signedMessage
} catch (err) {
handleError(err)
} finally {
updateSelectedAccount({ isTransferring: false })
}
}

0 comments on commit 39360de

Please sign in to comment.