bnb-chain / tss-lib

Threshold Signature Scheme, for ECDSA and EDDSA
MIT License
755 stars 260 forks source link

Can provide a demo for building an eth tx and sign it then send to endpoint? #296

Open Eric0718 opened 2 months ago

Eric0718 commented 2 months ago

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.

Eric0718 commented 2 months ago

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?

tuanna7593 commented 1 month ago

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)
huantt commented 4 weeks ago

You can follow this sample:

https://github.com/IBM/TSS/tree/main/mpc/binance/ecdsa