Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const signMessage = async ({
derivationPath,
message,
messageData,
}: Object = {}): Promise => {
/*
* Validate input values: derivationPath and message
*/
derivationPathValidator(derivationPath);
const toSign = messageOrDataValidator({ message, messageData });
warning(messages.messageSignatureOnlyTrezor);
try {
const { signature: signedMessage = '' } = await payloadListener({
payload: Object.assign({}, PAYLOAD_SIGNMSG, {
/*
* Path needs to be sent in as an derivation path array
*
* We also normalize it first (but for some reason Flow doesn't pick up
* the default value value of `path` and assumes it's undefined -- it can be,
* but it will not pass the validator)
*/
path: fromString(
derivationPathNormalizer(derivationPath),
true,
).toPathArray(),
// $FlowFixMe need Buffer types
export const signMessage = async ({
derivationPath,
message,
messageData,
}: Object = {}): Promise => {
/*
* Validate input values: derivationPath and message
*/
derivationPathValidator(derivationPath);
const toSign = messageOrDataValidator({ message, messageData });
try {
const ledger: LedgerInstanceType = await ledgerConnection();
/*
* Sign the message object via your Ledger Wallet
*
* We also warn the user here, since the device will need confirmation, but only in dev mode.
*/
warning(messages.userSignMessageInteractionWarning);
const {
r: rSignatureComponent,
s: sSignatureComponent,
v: recoveryParameter,
/*
* Flow bugs out here claiming the `r` property is not available on the return object.
*/
/* $FlowFixMe */
export const signMessage = async ({
currentAddress,
message,
messageData,
}: Object = {}): Promise => {
addressValidator(currentAddress);
const toSign = messageOrDataValidator({ message, messageData });
/*
* We must check for the Metamask injected in-page proxy every time we
* try to access it. This is because something can change it from the time
* of last detection until now.
*/
return methodCaller(
/*
* @TODO Move into own (non-anonymous) method
* This way we could better test it
*/
() =>
new Promise((resolve, reject) => {
/*
* Sign the message. This will prompt the user via Metamask's UI
*/
signMessageMethodLink(
export const signMessage = async (
{ message, messageData, callback }: Object = {},
): Promise => {
/*
* Validate input value
*/
const toSign = messageOrDataValidator({ message, messageData });
try {
const messageSignature: string = await callback(toSign);
/*
* Normalize the message signature
*/
return hexSequenceNormalizer(messageSignature);
} catch (caughtError) {
throw new Error(
`${messages.cannotSignMessage}: ${message} Error: ${caughtError.message}`,
);
}
};