Closed golddydev closed 10 months ago
Hi @eageringdev ! Unfortunately I can not help with additional information like a code example, cbor of transaction
At least, verifying signed transaction is doable? The blockchain itself certainly do. But how can we do on our own code?
You can check it by CSL:
FixedTransaction
and and body hash by TransactionHash.from_bytes(blake2b(32).update(raw_body).digest('binary'))
PublicKey
typeThanks, @lisicky Your answer inspires me. Extract the public key from transaction body.
import { C } from 'lucid-cardano';
export const decodeSignedData = ({ signedData }) => {
const { signature, data } = signedData;
const txVkeyWitnesses = C.TransactionWitnessSet.from_bytes(
Buffer.from(signature, 'hex')
);
const pubKeyHash = txVkeyWitnesses
.vkeys()
?.get(0)
.vkey()
.public_key()
.hash()
.to_hex();
const tx = C.Transaction.from_bytes(Buffer.from(data, 'hex'));
const txSignerPubKeyHash = tx.body().required_signers()?.get(0).to_hex();
const isVerified = pubKeyHash?.length > 0 && pubKeyHash == txSignerPubKeyHash;
const rewardAddress = C.RewardAddress.new(
C.NetworkInfo.mainnet().network_id(),
C.StakeCredential.from_keyhash(C.Ed25519KeyHash.from_hex(pubKeyHash))
);
return {
isVerified,
signerAddress: rewardAddress.to_address().to_bech32(),
};
};
This is the code snippet to verify the signed transaction. Where the signedData.signature is signed transaction and signedData.data is transaction data (hex string).
What do you think?
Hello everybody. I am now facing an issue while I tried to verify the signed Tx.
I was trying to verify this signed Tx in the same way I verify the signed Data using
I send the signedData like this
But I got error like this.
I think it is because the transaction format and the message (signedData) format is different. But how to fix this?
Can anyone help?
Thank you.