Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function verifyTxSignedBy(
transaction: Transaction,
accountId: string,
): boolean {
const hashedSignatureBase = transaction.hash();
const keypair = Keypair.fromPublicKey(accountId);
return !!transaction.signatures.find((sig) => {
return keypair.verify(hashedSignatureBase, sig.signature());
});
}
throw Error('Wrong version');
}
let operation, params;
switch (tx.operation) {
case 1:
operation = 'create_account';
params = CreateAccountParams.decode(tx.params);
params.address = base32.encode(params.address);
Keypair.fromPublicKey(params.address);
break;
case 2:
operation = 'payment';
params = PaymentParams.decode(tx.params);
params.address = base32.encode(params.address);
Keypair.fromPublicKey(params.address);
break;
case 3:
operation = 'post';
params = PostParams.decode(tx.params);
break;
case 4:
operation = 'update_account';
params = UpdateAccountParams.decode(tx.params);
break;
case 5:
operation = 'interact';
params = InteractParams.decode(tx.params);
params.object = params.object.toString('hex').toUpperCase();
function verify(tx) {
const key = Keypair.fromPublicKey(tx.account);
return key.verify(getUnsignedHash(tx), tx.signature);
}