Skip to content

Commit

Permalink
♻️ Handle public key check to always be buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
ManuGowda authored and reyraa committed Jan 10, 2022
1 parent 326abd1 commit 0b88772
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/utils/hwManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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) {
Expand Down
3 changes: 0 additions & 3 deletions src/utils/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit 0b88772

Please sign in to comment.