diff --git a/services/ens/api.go b/services/ens/api.go index 5021131c9..1c031ab54 100644 --- a/services/ens/api.go +++ b/services/ens/api.go @@ -5,7 +5,6 @@ import ( "encoding/binary" "encoding/hex" "fmt" - "math/big" "github.com/ipfs/go-cid" "github.com/multiformats/go-multibase" @@ -15,6 +14,7 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" + "github.com/status-im/status-go/eth-node/crypto" "github.com/status-im/status-go/rpc" ) @@ -32,11 +32,6 @@ type uri struct { Path string } -type publicKey struct { - X [32]byte - Y [32]byte -} - type API struct { contractMaker *contractMaker } @@ -106,29 +101,28 @@ func (api *API) ContentHash(ctx context.Context, chainID uint64, username string return contentHash, nil } -func (api *API) PublicKeyOf(ctx context.Context, chainID uint64, username string) (*publicKey, error) { +func (api *API) PublicKeyOf(ctx context.Context, chainID uint64, username string) (string, error) { err := validateENSUsername(username) if err != nil { - return nil, err + return "", err } resolverAddress, err := api.Resolver(ctx, chainID, username) if err != nil { - return nil, err + return "", err } resolver, err := api.contractMaker.newPublicResolver(chainID, resolverAddress) if err != nil { - return nil, err + return "", err } callOpts := &bind.CallOpts{Context: ctx, Pending: false} pubKey, err := resolver.Pubkey(callOpts, nameHash(username)) if err != nil { - return nil, err + return "", err } - - return &publicKey{pubKey.X, pubKey.Y}, nil + return "0x" + hex.EncodeToString(pubKey.X[:]) + hex.EncodeToString(pubKey.Y[:]), nil } func (api *API) AddressOf(ctx context.Context, chainID uint64, username string) (*common.Address, error) { @@ -156,39 +150,37 @@ func (api *API) AddressOf(ctx context.Context, chainID uint64, username string) return &addr, nil } -func (api *API) ExpireAt(ctx context.Context, chainID uint64, username string) (*big.Int, error) { - err := validateENSUsername(username) - if err != nil { - return nil, err - } - +func (api *API) ExpireAt(ctx context.Context, chainID uint64, username string) (string, error) { + usernameHashed := crypto.Keccak256([]byte(username)) + var label [32]byte + copy(label[:], usernameHashed) registrar, err := api.contractMaker.newUsernameRegistrar(chainID) if err != nil { - return nil, err + return "", err } callOpts := &bind.CallOpts{Context: ctx, Pending: false} - expTime, err := registrar.GetExpirationTime(callOpts, nameHash(username)) + expTime, err := registrar.GetExpirationTime(callOpts, label) if err != nil { - return nil, err + return "", err } - return expTime, nil + return fmt.Sprintf("%x", expTime), nil } -func (api *API) Price(ctx context.Context, chainID uint64) (*big.Int, error) { +func (api *API) Price(ctx context.Context, chainID uint64) (string, error) { registrar, err := api.contractMaker.newUsernameRegistrar(chainID) if err != nil { - return nil, err + return "", err } callOpts := &bind.CallOpts{Context: ctx, Pending: false} price, err := registrar.GetPrice(callOpts) if err != nil { - return nil, err + return "", err } - return price, nil + return fmt.Sprintf("%x", price), nil } // TODO: implement once the send tx as been refactored diff --git a/services/ens/api_test.go b/services/ens/api_test.go index b36a1eaf3..7cf89527e 100644 --- a/services/ens/api_test.go +++ b/services/ens/api_test.go @@ -92,8 +92,8 @@ func TestPublicKeyOf(t *testing.T) { require.NoError(t, err) require.Equal( t, - [32]byte{226, 93, 166, 153, 78, 162, 220, 74, 199, 7, 39, 224, 126, 202, 21, 58, 233, 43, 247, 96, 157, 183, 190, 251, 126, 189, 206, 170, 211, 72, 244, 252}, - pubKey.X, + "0xe25da6994ea2dc4ac70727e07eca153ae92bf7609db7befb7ebdceaad348f4fc55bbe90abf9501176301db5aa103fc0eb3bc3750272a26c424a10887db2a7ea8", + pubKey, ) } @@ -110,9 +110,9 @@ func TestExpireAt(t *testing.T) { api, cancel := setupTestAPI(t) defer cancel() - r, err := api.ExpireAt(context.Background(), 1, "rramos.eth") + r, err := api.ExpireAt(context.Background(), 1, "rramos") require.NoError(t, err) - require.Equal(t, "0", r.String()) + require.Equal(t, "5db32cb7", r) } func TestPrice(t *testing.T) { @@ -121,7 +121,7 @@ func TestPrice(t *testing.T) { r, err := api.Price(context.Background(), 1) require.NoError(t, err) - require.Equal(t, "10000000000000000000", r.String()) + require.Equal(t, "8ac7230489e80000", r) } func TestResourceURL(t *testing.T) { diff --git a/services/ens/contracts.go b/services/ens/contracts.go index ec7b2f32b..5bd17bd24 100644 --- a/services/ens/contracts.go +++ b/services/ens/contracts.go @@ -13,6 +13,7 @@ var errorNotAvailableOnChainID = errors.New("not available for chainID") var resolversByChainID = map[uint64]common.Address{ 1: common.HexToAddress("0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e"), // mainnet + 3: common.HexToAddress("0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e"), // ropsten } var usernameRegistrarsByChainID = map[uint64]common.Address{