Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/*
* 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 */
} = await ledger.signPersonalMessage(
derivationPathNormalizer(derivationPath),
/*
* The message needs to be sent in as an hex string
*
* Also, Flow don't know about Buffer
*/
/* $FlowFixMe */
Buffer.from(toSign).toString(HEX_HASH_TYPE),
);
/*
* Combine the (R), and (S) signature components, alogn with the reco(V)ery param (that
* gets converted into `hex`)
*/
return hexSequenceNormalizer(
`${rSignatureComponent}` +
`${sSignatureComponent}` +
`${recoveryParameter.toString(16)}`,
),
},
getChainDefinition(chainId),
);
/*
* Modify the default payload to set the transaction details
*/
const modifiedPayloadObject: Object = Object.assign(
{},
PAYLOAD_SIGNTX,
{
/*
* Path needs to be sent in as an derivation path array
*/
address_n: fromString(
derivationPathNormalizer(derivationPath),
true,
).toPathArray(),
/*
* @TODO Add `bigNumber` `toHexString` wrapper method
*
* Flow confuses bigNumber's `toString` with the String object
* prototype `toString` method
*/
/* $FlowFixMe */
gas_price: multipleOfTwoHexValueNormalizer(gasPrice.toString(16)),
/*
* @TODO Add `bigNumber` `toHexString` wrapper method
*
* Flow confuses bigNumber's `toString` with the String object
* prototype `toString` method
*/
to ? { to: addressNormalizer(to) } : {},
),
getChainDefinition(chainId),
);
/*
* Sign the transaction object via your Ledger Wallet
*
* We also warn the user here, since the device will need confirmation, but only in dev mode.
*/
warning(messages.userSignInteractionWarning);
const {
r: rSignatureComponent,
s: sSignatureComponent,
v: recoveryParameter,
} = await ledger.signTransaction(
derivationPathNormalizer(derivationPath),
unsignedTransaction.serialize().toString(HEX_HASH_TYPE),
);
/*
* Proving that we signed the above transaction.
*
* @NOTE We need to modify the original transaction
* Otherwise EthereumTx will complain because internally it checks for the valid instance
*/
unsignedTransaction.r = hexSequenceNormalizer(rSignatureComponent);
unsignedTransaction.s = hexSequenceNormalizer(sSignatureComponent);
unsignedTransaction.v = hexSequenceNormalizer(recoveryParameter);
const serializedSignedTransaction = unsignedTransaction
.serialize()
.toString(HEX_HASH_TYPE);
/*
* Add the hex prefix