Can provide a demo for building an eth tx and sign it then send to endpoint?
Opened this issue · 5 comments
I'm a little confused, how to construct an eth transaction and sign it with tss signing, and finally send it to the target blockchain.
func rebuildSignature(unsignedTx *types.Transaction, siger types.EIP155Signer, sigData *MPCSignatureData) (*types.Transaction, error) {
mpcSignature, err := hex.DecodeString(sigData.Signature)
if err != nil {
return nil, err
}
if len(mpcSignature) != 64 {
return nil, errors.New("signature length not 64!")
}
//does recid use 0 or 1 ??
var recid int64 = 0
V := byte(big.NewInt(recid).Uint64())
mpcSignature = append(mpcSignature, V)
return unsignedTx.WithSignature(siger, mpcSignature)
}
//I'm trying to reconstruct an eth signature using MPC signatureData without the V , can anyone tell me if this is correct? And does recid choose 0 or 1?
You can reconstruct signature by combine Signature
and SignatureRecovery
from SignatureData
that you got from the endCh
channel.
https://github.com/bnb-chain/tss-lib/blob/master/common/signature.pb.go#L36-L38
signatureData <- endCh
signature := append(signatureData.GetSignature(), signatureData.GetSignatureRecovery()...)
unsignedTx.WithSignature(siger, signature)
You can follow this sample:
Hi, I'm getting failed when trying to sign a constructed transaction.
Is there any particular way to construct transaction that will be signed?
https://github.com/bnb-chain/tss-lib/blob/master/common/signature.pb.go#L36-L38
Hi, I try to reconstruct the signature this way along with the transaction. But when I do ecrecover, the address is always different on every attempt of signing while the transaction data still the same.
Here my code
addr := common.HexToAddress("0x000000000000000000000000000000000000aaaa")
tx := types.NewTransaction(0, addr, new(big.Int), 0, new(big.Int), nil)
... Signing process, got the signature
// Recover the address from the signed transaction
signer := types.NewEIP155Signer(big.NewInt(18))
dataWithSignature, err := tx.WithSignature(signer, signature)
recoveredAddress, err := types.Sender(signer, dataWithSignature)
if err != nil {
log.Fatalf("Failed to recover address from transaction: %v", err)
}
fmt.Printf("Recovered Address: %s\n", recoveredAddress.Hex())
On this case, the recovered address alwayd produce different address.
Is there something wrong on my code?