diff --git a/relayer/local_relayer.go b/relayer/local_relayer.go index 6b8fb25e..88367919 100644 --- a/relayer/local_relayer.go +++ b/relayer/local_relayer.go @@ -219,6 +219,8 @@ func (r *LocalRelayer) Relay(ctx context.Context, signedTxs *sequence.SignedTran } func (r *LocalRelayer) RelayV3(ctx context.Context, signedTxs *sequence.SignedTransactions, quote ...*sequence.RelayerFeeQuote) (sequence.MetaTxnID, *types.Transaction, ethtxn.WaitReceipt, error) { + fmt.Println("Relaying V3 Local Relayer") + sender := r.Sender to, execdata, err := sequence.EncodeTransactionsForRelayingV3( diff --git a/wallet.go b/wallet.go index 030f64ad..323e9456 100644 --- a/wallet.go +++ b/wallet.go @@ -536,8 +536,7 @@ func (w *Wallet[C]) SignDigest(ctx context.Context, digest common.Hash, optChain // Sequence Wallet SignDigest returns a signature without a type _, pc1 := signer.(*Wallet[*v1.WalletConfig]) _, pc2 := signer.(*Wallet[*v2.WalletConfig]) - _, pc3 := signer.(*Wallet[*v3.WalletConfig]) - if pc1 || pc2 || pc3 { + if pc1 || pc2 { return core.SignerSignatureTypeEIP1271, sigValue, nil } return core.SignerSignatureType(sigValue[len(sigValue)-1]), sigValue[:len(sigValue)-1], nil @@ -558,6 +557,63 @@ func (w *Wallet[C]) SignDigest(ctx context.Context, digest common.Hash, optChain return res, err } +func (w *Wallet[C]) SignV3Payload(ctx context.Context, payload v3.DecodedPayload, optChainID ...*big.Int) ([]byte, error) { + if (optChainID == nil && len(optChainID) == 0) && w.chainID == nil { + return nil, fmt.Errorf("sequence.Wallet#SignDigest: %w", ErrUnknownChainID) + } + + var chainID *big.Int + if len(optChainID) > 0 { + chainID = optChainID[0] + } else { + chainID = w.chainID + } + + opHash, err := v3.HashPayload(w.address, chainID, payload) + if err != nil { + return nil, fmt.Errorf("SignV3Payload, HashPayload: %w", err) + } + + sign := func(ctx context.Context, signerAddress common.Address, signatures []core.SignerSignature) (core.SignerSignatureType, []byte, error) { + signer, _ := w.GetSigner(signerAddress) + + if signer == nil { + // signer isn't available, just include the config value of address + // without it's signature + return 0, nil, core.ErrSigningNoSigner + } + + switch signerTyped := signer.(type) { + // sequence.Wallet / Signing Service / Guard + case DigestSigner: + sigValue, err := signerTyped.SignDigest(ctx, opHash, chainID) + if err != nil { + return 0, nil, fmt.Errorf("signer.SignDigest subDigest: %w", err) + } + + // Sequence Wallet SignDigest returns a signature without a type + _, pc3 := signer.(*Wallet[*v3.WalletConfig]) + if pc3 { + return core.SignerSignatureTypeEIP1271, sigValue, nil + } + return core.SignerSignatureType(sigValue[len(sigValue)-1]), sigValue[:len(sigValue)-1], nil + // Ethereum Wallet Signer + case MessageSigner: + sigValue, err := signerTyped.SignMessage(opHash[:]) + if err != nil { + return 0, nil, fmt.Errorf("signer.SignMessage subDigest: %w", err) + } + + return core.SignerSignatureTypeEthSign, sigValue, nil + default: + return 0, nil, fmt.Errorf("signer %T is not supported", signer) + } + } + + res, _, err := w.buildSignature(ctx, sign, chainID) + return res, err +} + var _ DigestSigner = (*Wallet[*v1.WalletConfig])(nil) var _ DigestSigner = (*Wallet[*v2.WalletConfig])(nil) @@ -652,7 +708,7 @@ func (w *Wallet[C]) SignTransactions(ctx context.Context, txns Transactions) (*S } // Sign the transactions - sig, err := w.SignDigest(ctx, digest) + sig, err := w.SignV3Payload(ctx, payload) if err != nil { return nil, err }