Skip to content

Commit

Permalink
Ziga/fix og user id and address problems (#1426)
Browse files Browse the repository at this point in the history
  • Loading branch information
zkokelj authored Aug 7, 2023
1 parent 4852e28 commit 3d4fabe
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
5 changes: 3 additions & 2 deletions go/common/viewingkey/viewing_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"crypto/ecdsa"
"encoding/hex"
"fmt"
"strings"

"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/crypto"
Expand Down Expand Up @@ -103,8 +104,8 @@ func GenerateSignMessage(vkPubKey []byte) string {
}

// GenerateSignMessageOG creates the message to be signed by Obscuro Gateway (new format)
// format is expected to be "Register <userID> for <Account>"
// format is expected to be "Register <userID> for <Account>" (with the account in lowercase)
func GenerateSignMessageOG(vkPubKey []byte, addr *gethcommon.Address) string {
userID := crypto.Keccak256Hash(vkPubKey).Bytes()
return fmt.Sprintf("Register %s for %s", hex.EncodeToString(userID), addr.Hex())
return fmt.Sprintf("Register %s for %s", hex.EncodeToString(userID), strings.ToLower(addr.Hex()))
}
5 changes: 2 additions & 3 deletions tools/walletextension/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ func BytesToPrivateKey(keyBytes []byte) (*ecies.PrivateKey, error) {
}

// CalculateUserID calculates userID from public key
func CalculateUserID(pk *ecdsa.PrivateKey) []byte {
viewingPublicKeyBytes := crypto.CompressPubkey(&pk.PublicKey)
return crypto.Keccak256Hash(viewingPublicKeyBytes).Bytes()
func CalculateUserID(publicKeyBytes []byte) []byte {
return crypto.Keccak256Hash(publicKeyBytes).Bytes()
}

// GetUserIDAndAddressFromMessage checks if message is in correct format and extracts userID and address from it
Expand Down
2 changes: 1 addition & 1 deletion tools/walletextension/wallet_extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func (w *WalletExtension) GenerateAndStoreNewUser() (string, error) {
}

// create UserID and store it in the database with the private key
userID := common.CalculateUserID(viewingKeyPrivate)
userID := common.CalculateUserID(common.PublicKeyBytesFromPrivateKey(viewingPrivateKeyEcies))
err = w.storage.AddUser(userID, crypto.FromECDSA(viewingPrivateKeyEcies.ExportECDSA()))
if err != nil {
w.Logger().Error(fmt.Sprintf("failed to save user to the database: %s", err))
Expand Down

0 comments on commit 3d4fabe

Please sign in to comment.