Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #48 from primevprotocol/fix/pad32BytePrivKey
Browse files Browse the repository at this point in the history
padded 32 byte private key
  • Loading branch information
kant777 authored Oct 12, 2023
2 parents 2711643 + 4fa08fb commit 9893388
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/p2p/libp2p/libp2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"crypto/ecdsa"
"fmt"
"github.com/primevprotocol/mev-commit/pkg/util"
"log/slog"
"math/big"
"time"
Expand Down Expand Up @@ -51,7 +52,8 @@ type Options struct {
}

func New(opts *Options) (*Service, error) {
libp2pKey, err := libp2pcrypto.UnmarshalSecp256k1PrivateKey(opts.PrivKey.D.Bytes())
padded32BytePrivKey := util.PadKeyTo32Bytes(opts.PrivKey.D)
libp2pKey, err := libp2pcrypto.UnmarshalSecp256k1PrivateKey(padded32BytePrivKey)
if err != nil {
return nil, err
}
Expand Down
12 changes: 12 additions & 0 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package util

import "math/big"

func PadKeyTo32Bytes(key *big.Int) []byte {
keyBytes := key.Bytes()
if len(keyBytes) < 32 {
padding := make([]byte, 32-len(keyBytes))
keyBytes = append(padding, keyBytes...)
}
return keyBytes
}

0 comments on commit 9893388

Please sign in to comment.