From 0b88772fa4cf508cdf574f22546e4d58dc65b265 Mon Sep 17 00:00:00 2001 From: ManuGowda Date: Sun, 9 Jan 2022 23:12:30 +0100 Subject: [PATCH] :recycle: Handle public key check to always be buffer --- src/utils/hwManager.js | 8 ++++++-- src/utils/transaction.js | 3 --- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/utils/hwManager.js b/src/utils/hwManager.js index 660d9f160f..ae2caf6194 100644 --- a/src/utils/hwManager.js +++ b/src/utils/hwManager.js @@ -32,6 +32,10 @@ const getAccountsFromDevice = async ({ device: { deviceId }, network }) => { return accounts; }; +const isKeyMatch = (aPublicKey, signerPublicKey) => (Buffer.isBuffer(aPublicKey) + ? aPublicKey.equals(signerPublicKey) + : Buffer.from(aPublicKey, 'hex').equals(signerPublicKey)); + /** * updateTransactionSignatures - Function. * This function updates transaction object to include the signatures at correct index. @@ -55,10 +59,10 @@ const updateTransactionSignatures = ( const { mandatoryKeys, optionalKeys } = keys; if (mandatoryKeys.length + optionalKeys.length > 0) { const mandatoryKeyIndex = mandatoryKeys.findIndex( - aPublicKey => aPublicKey.equals(signerPublicKey), + aPublicKey => isKeyMatch(aPublicKey, signerPublicKey), ); const optionalKeyIndex = optionalKeys.findIndex( - aPublicKey => aPublicKey.equals(signerPublicKey), + aPublicKey => isKeyMatch(aPublicKey, signerPublicKey), ); const signatureOffset = isMultiSignatureRegistration ? 1 : 0; if (mandatoryKeyIndex !== -1) { diff --git a/src/utils/transaction.js b/src/utils/transaction.js index 2375e0f406..08808ef963 100644 --- a/src/utils/transaction.js +++ b/src/utils/transaction.js @@ -462,7 +462,6 @@ const signMultisigUsingPrivateKey = ( ]; const senderIndex = members.indexOf(publicKey); const isSender = rawTransaction.senderPublicKey === publicKey; - console.log(isMultiSignatureRegistration, isSender, senderIndex); if (isMultiSignatureRegistration && isSender && senderIndex > -1) { const signatures = Array.from(Array(members.length + 1).keys()).map((index) => { @@ -513,8 +512,6 @@ const signUsingHW = async ( const senderIndex = members.indexOf(account.summary.publicKey); const isSender = rawTransaction.senderPublicKey === account.summary.publicKey; - console.log(isMultiSignatureRegistration, isSender, senderIndex); - if (isMultiSignatureRegistration && isSender && senderIndex > -1) { const signatures = Array.from(Array(members.length + 1).keys()).map((index) => { if (signedTransaction.signatures[index]) return signedTransaction.signatures[index];