Skip to content

Commit

Permalink
wallet: support building NoChainID signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
patrislav committed Dec 10, 2024
1 parent 1723324 commit 71e7645
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ func (w *Wallet[C]) SignDigest(ctx context.Context, digest common.Hash, optChain
}
}

res, _, err := w.buildSignature(ctx, sign)
res, _, err := w.buildSignature(ctx, sign, chainID)
return res, err
}

Expand Down Expand Up @@ -729,12 +729,23 @@ func (w *Wallet[C]) IsValidSignature(digest common.Hash, signature []byte) (bool
}
}

func (w *Wallet[C]) buildSignature(ctx context.Context, sign core.SigningFunction) ([]byte, core.Signature[C], error) {
func (w *Wallet[C]) buildSignature(ctx context.Context, sign core.SigningFunction, chainID *big.Int) ([]byte, core.Signature[C], error) {
var coreWalletConfig core.WalletConfig = w.config
if config, ok := coreWalletConfig.(*v2.WalletConfig); ok {
sig, err := config.BuildRegularSignature(ctx, sign, false)
if err != nil {
return nil, nil, fmt.Errorf("SignDigest, BuildRegularSignature: %w", err)
var (
sig core.Signature[*v2.WalletConfig]
err error
)
if chainID.Cmp(big.NewInt(0)) == 0 {
sig, err = config.BuildNoChainIDSignature(ctx, sign, false)
if err != nil {
return nil, nil, fmt.Errorf("SignDigest, BuildNoChainIDSignature: %w", err)
}
} else {
sig, err = config.BuildRegularSignature(ctx, sign, false)
if err != nil {
return nil, nil, fmt.Errorf("SignDigest, BuildRegularSignature: %w", err)
}
}

sigEnc, err := sig.Data()
Expand Down

0 comments on commit 71e7645

Please sign in to comment.