-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release/2.2.0' into 3954-add-hw-multisig-support
- Loading branch information
Showing
15 changed files
with
350 additions
and
288 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...eens/signMessage/signMessageInput.test.js → ...ts/screens/signMessage/form/index.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/components/screens/signMessage/messageSignature/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { cryptography } from '@liskhq/lisk-client'; // eslint-disable-line | ||
|
||
import { loginTypes } from '@constants'; | ||
import { signMessageByHW, getDeviceType } from '@utils/hwManager'; | ||
import Illustration from '@toolbox/illustration'; | ||
import BoxContent from '@toolbox/box/content'; | ||
import styles from '../signMessage.css'; | ||
|
||
const MessageSignature = ({ | ||
nextStep, | ||
message, | ||
account, | ||
t, | ||
}) => { | ||
const [signature, setSignature] = useState(); | ||
const [error, setError] = useState(); | ||
const deviceType = getDeviceType(account.hwInfo?.deviceModel); | ||
|
||
const signUsingPrivateKey = () => { | ||
const msgBytes = cryptography.digestMessage(message); | ||
const signedMessage = cryptography.signDataWithPrivateKey(msgBytes, Buffer.from(account.summary.privateKey, 'hex')); | ||
const result = cryptography.printSignedMessage({ | ||
message, | ||
publicKey: account.summary.publicKey, | ||
signature: signedMessage, | ||
}); | ||
return result; | ||
}; | ||
|
||
const signUsingHW = async () => { | ||
let signedMessage = await signMessageByHW({ | ||
account, | ||
message, | ||
}); | ||
if (signedMessage instanceof Uint8Array) { | ||
signedMessage = Buffer.from(signedMessage); | ||
} | ||
const result = cryptography.printSignedMessage({ | ||
message, | ||
publicKey: account.summary.publicKey, | ||
signature: signedMessage, | ||
}); | ||
return result; | ||
}; | ||
|
||
useEffect(() => { | ||
if (!signature && !error) { | ||
if (account.loginType === loginTypes.passphrase.code) { | ||
setSignature(signUsingPrivateKey()); | ||
} else { | ||
signUsingHW() | ||
.then(setSignature) | ||
.catch(setError); | ||
} | ||
} else { | ||
nextStep({ signature, error }); | ||
} | ||
}, [signature, error]); | ||
|
||
if (!deviceType) { | ||
return (<div />); | ||
} | ||
|
||
return ( | ||
<BoxContent className={styles.pendingWrapper}> | ||
<Illustration name={deviceType} /> | ||
<h5> | ||
{t('Please confirm the message on your {{deviceModel}}', { deviceModel: account.hwInfo.deviceModel })} | ||
</h5> | ||
</BoxContent> | ||
); | ||
}; | ||
|
||
export default MessageSignature; |
Oops, something went wrong.