Skip to content

Commit

Permalink
chore: update sign v3 payload
Browse files Browse the repository at this point in the history
  • Loading branch information
shunkakinoki committed Mar 4, 2025
1 parent c9cf37a commit 42264bc
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 3 deletions.
2 changes: 2 additions & 0 deletions relayer/local_relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
62 changes: 59 additions & 3 deletions wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 42264bc

Please sign in to comment.