Skip to content

Commit

Permalink
refactor: check Address type not string
Browse files Browse the repository at this point in the history
  • Loading branch information
hopeyen committed Dec 21, 2024
1 parent 719821b commit 196085c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
11 changes: 7 additions & 4 deletions core/auth/v2/authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"

core "github.com/Layr-Labs/eigenda/core/v2"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
)

Expand Down Expand Up @@ -37,9 +38,10 @@ func (*authenticator) AuthenticateBlobRequest(header *core.BlobHeader) error {
}

accountId := header.PaymentMetadata.AccountID
pubKey := crypto.PubkeyToAddress(*sigPublicKeyECDSA).Hex()
accountAddr := common.HexToAddress(accountId)
pubKeyAddr := crypto.PubkeyToAddress(*sigPublicKeyECDSA)

if pubKey != accountId {
if accountAddr.Cmp(pubKeyAddr) != 0 {
return errors.New("signature doesn't match with provided public key")
}

Expand All @@ -59,9 +61,10 @@ func (*authenticator) AuthenticatePaymentStateRequest(sig []byte, accountId stri
return fmt.Errorf("failed to recover public key from signature: %v", err)
}

pubKey := crypto.PubkeyToAddress(*sigPublicKeyECDSA).Hex()
accountAddr := common.HexToAddress(accountId)
pubKeyAddr := crypto.PubkeyToAddress(*sigPublicKeyECDSA)

if pubKey != accountId {
if accountAddr.Cmp(pubKeyAddr) != 0 {
return errors.New("signature doesn't match with provided public key")
}

Expand Down
1 change: 0 additions & 1 deletion core/auth/v2/signer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

func TestGetAccountID(t *testing.T) {
// Test case with known private key and expected account ID
// privateKey := "73ae7e3a40b59caacb1cda8fa04f4e7fa5bb2b37101f9f3506290c201f57bf7b"
privateKey := "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcded"
expectedAccountID := "0x1aa8226f6d354380dDE75eE6B634875c4203e522"

Expand Down

0 comments on commit 196085c

Please sign in to comment.