Skip to content

Commit

Permalink
Fix: use hash for big tx on verify (#1006)
Browse files Browse the repository at this point in the history
  • Loading branch information
Asmadek authored Aug 4, 2023
1 parent fde3ee9 commit 3d83345
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/renderer/services/transaction/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export type ITransactionService = {
getTransactionDeposit: (threshold: Threshold, api: ApiPromise) => string;
getTransactionHash: (transaction: Transaction, api: ApiPromise) => HashData;
decodeCallData: (api: ApiPromise, accountId: Address, callData: CallData) => DecodedTransaction;
verifySignature: (payload: string | Uint8Array, signature: HexString, accountId: AccountId) => Boolean;
verifySignature: (payload: Uint8Array, signature: HexString, accountId: AccountId) => Boolean;
};

// =====================================================
Expand Down
8 changes: 5 additions & 3 deletions src/renderer/services/transaction/transactionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
UnsignedTransaction,
} from '@substrate/txwrapper-polkadot';
import { Weight } from '@polkadot/types/interfaces';
import { signatureVerify } from '@polkadot/util-crypto';
import { blake2AsU8a, signatureVerify } from '@polkadot/util-crypto';

import { AccountId, HexString, Threshold } from '@renderer/domain/shared-kernel';
import { Transaction, TransactionType } from '@renderer/domain/transaction';
Expand Down Expand Up @@ -440,8 +440,10 @@ export const useTransaction = (): ITransactionService => {
});
};

const verifySignature = (payload: string | Uint8Array, signature: HexString, accountId: AccountId): Boolean => {
return signatureVerify(payload, signature, accountId).isValid;
const verifySignature = (payload: Uint8Array, signature: HexString, accountId: AccountId): Boolean => {
const payloadToVerify = payload.length > 256 ? blake2AsU8a(payload) : payload;

return signatureVerify(payloadToVerify, signature, accountId).isValid;
};

return {
Expand Down

0 comments on commit 3d83345

Please sign in to comment.