Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/components/SignVerifyMsg/SignVerifyMsg.js
Show All 18 Lines | import { | ||||
generalNotification, | generalNotification, | ||||
} from 'components/Common/Notifications'; | } from 'components/Common/Notifications'; | ||||
import { CustomCollapseCtn } from 'components/Common/StyledCollapse'; | import { CustomCollapseCtn } from 'components/Common/StyledCollapse'; | ||||
import { | import { | ||||
AntdFormWrapper, | AntdFormWrapper, | ||||
DestinationAddressSingleWithoutQRScan, | DestinationAddressSingleWithoutQRScan, | ||||
} from 'components/Common/EnhancedInputs'; | } from 'components/Common/EnhancedInputs'; | ||||
const { TextArea } = Input; | const { TextArea } = Input; | ||||
import { convertToEcashPrefix, getWalletState } from 'utils/cashMethods'; | import { | ||||
convertToEcashPrefix, | |||||
getWalletState, | |||||
getECPairFromWIF, | |||||
} from 'utils/cashMethods'; | |||||
import CopyToClipboard from 'components/Common/CopyToClipboard'; | import CopyToClipboard from 'components/Common/CopyToClipboard'; | ||||
import { ThemedCopySolid } from 'components/Common/CustomIcons'; | import { ThemedCopySolid } from 'components/Common/CustomIcons'; | ||||
import { SmartButton } from 'components/Common/PrimaryButton'; | import { SmartButton } from 'components/Common/PrimaryButton'; | ||||
import { PlusSquareOutlined } from '@ant-design/icons'; | import { PlusSquareOutlined } from '@ant-design/icons'; | ||||
import { currency, parseAddressForParams } from 'components/Common/Ticker.js'; | import { currency, parseAddressForParams } from 'components/Common/Ticker.js'; | ||||
import { isValidXecAddress, isValidEtokenAddress } from 'utils/validation'; | import { isValidXecAddress, isValidEtokenAddress } from 'utils/validation'; | ||||
import xecMessage from 'xecjs-message'; | import xecMessage from 'xecjs-message'; | ||||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | const SignVerifyMsg = ({ jestBCH }) => { | ||||
const [messageVerificationSigError, setMessageVerificationSigError] = | const [messageVerificationSigError, setMessageVerificationSigError] = | ||||
useState(false); | useState(false); | ||||
const signMessageByPk = () => { | const signMessageByPk = () => { | ||||
try { | try { | ||||
const messageSignature = bchObj.BitcoinCash.signMessageWithPrivKey( | const messageSignature = bchObj.BitcoinCash.signMessageWithPrivKey( | ||||
wallet.Path1899.fundingWif, | wallet.Path1899.fundingWif, | ||||
msgToSign, | msgToSign, | ||||
); | ); | ||||
// Get local messageSignature | |||||
// First, get required params | |||||
const keyPair = getECPairFromWIF(wallet.Path1899.fundingWif); | |||||
// Reference https://github.com/Permissionless-Software-Foundation/bch-js/blob/master/src/bitcoincash.js#L161 | |||||
const privKey = keyPair.d.toBuffer(32); | |||||
// Now you can get the local signature | |||||
const localMessageSignature = xecMessage | |||||
.sign(msgToSign, privKey, keyPair.compressed) | |||||
.toString('base64'); | |||||
// Compare to legacy method | |||||
console.log(`legacy signature`, messageSignature); | |||||
console.log(`local signature`, localMessageSignature); | |||||
if (messageSignature === localMessageSignature) { | |||||
console.log(`The signatures match`); | |||||
} | |||||
setMessageSignature(messageSignature); | setMessageSignature(messageSignature); | ||||
messageSignedNotification(messageSignature); | messageSignedNotification(messageSignature); | ||||
} catch (err) { | } catch (err) { | ||||
let message; | let message; | ||||
if (!err.error && !err.message) { | if (!err.error && !err.message) { | ||||
message = err.message || err.error || JSON.stringify(err); | message = err.message || err.error || JSON.stringify(err); | ||||
} | } | ||||
errorNotification(err, message, 'Message Signing Error'); | errorNotification(err, message, 'Message Signing Error'); | ||||
▲ Show 20 Lines • Show All 355 Lines • Show Last 20 Lines |