When you receive a transaction in the http request, you are getting a string with the XRD base64 form of the client signed transaction:
{"transaction": "AAAAAGjeCRajN67nRkVtYO+lpxax9gvitX9FxhZYGXQvs16hAAAAZAAAAAAAAAAAAAAAAQAAAABbcutKAAAAAFty7HYAAAAAAAAAAQAAAAEAAAAAVIx5odtAgqQ+dp4m4QfWntHbOq0hxRCLGI+2Sm0P6EMAAAAKAAAAC01vYml1cyBhdXRoAAAAAAEAAABAG01TL/Ha0YGVrAF6t0UEKP/0Q/NDUymciQBA/CXzYMVlEx2KcHrq3MkpQ9+9sCbCiOYa7wCtusa1tHKygvZRSwAAAAAAAAABL7NeoQAAAEC9v5jdxReIxoCcCXw90dVsIpXwHXkSHUUthCs98D/zpd6TNPvcMgUsQd6cDHzjNk+/00P8M5bHP4rIpFTm7MwN"}
If you are using JS, you can use the following to verify that the transaction was signed by the server PK:
const tx = new Transaction(req.body.transaction);
const op = tx.operations[0];
const { signatures } = tx;
const hash = tx.hash();
// Source account is ours
if (tx.source != SERVER_KEY_PAIR.publicKey()) {
return res.json({ error: "Invalid source account." });
}
// Challenge transaction was generated by us
if (
!signatures.some(signature =>
SERVER_KEY_PAIR.verify(hash, signature.signature())
)
) {
return res.json({ error: "Server signature is missing or invalid." });
}
I'm using Golang, but I think I'm using the wrong types and methods because the verification is failing.
var txXDR xdr.TransactionEnvelope
err = xdr.SafeUnmarshalBase64(txeBase64, &txXDR)
if err != nil {
return fmt.Errorf("Error Unmarhsaling TX: %s", err)
}
The problem using that Transaction Envelope is that I do not see in the Go-SDK the equivalent of
const hash = tx.hash();
SERVER_KEY_PAIR.verify(hash, signat`ure.signature())
when using that XDR Tx.
Can anyone point me to the right direction?