From 19b5bcf3ce29d21be4b90a06a7ad9fd4cbd77150 Mon Sep 17 00:00:00 2001 From: Sale Djenic Date: Tue, 30 Jul 2024 14:43:45 +0200 Subject: [PATCH] chore_: endpoint for checking address checksum validity added to wallet api - added `IsChecksumValidForAddress` function to `wallet` api --- services/wallet/api.go | 6 ++++++ services/wallet/api_test.go | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/services/wallet/api.go b/services/wallet/api.go index 08cf11a26..28f916303 100644 --- a/services/wallet/api.go +++ b/services/wallet/api.go @@ -15,6 +15,7 @@ import ( "github.com/ethereum/go-ethereum/log" gethrpc "github.com/ethereum/go-ethereum/rpc" signercore "github.com/ethereum/go-ethereum/signer/core/apitypes" + abi_spec "github.com/status-im/status-go/abi-spec" "github.com/status-im/status-go/account" "github.com/status-im/status-go/eth-node/crypto" "github.com/status-im/status-go/eth-node/types" @@ -905,3 +906,8 @@ func (api *API) SafeSignTypedDataForDApps(typedJson string, address string, pass func (api *API) RestartWalletReloadTimer(ctx context.Context) error { return api.s.reader.Restart() } + +func (api *API) IsChecksumValidForAddress(address string) (bool, error) { + log.Debug("wallet.api.isChecksumValidForAddress", "address", address) + return abi_spec.CheckAddressChecksum(address) +} diff --git a/services/wallet/api_test.go b/services/wallet/api_test.go index f76c6d13a..75688868f 100644 --- a/services/wallet/api_test.go +++ b/services/wallet/api_test.go @@ -29,3 +29,15 @@ func TestAPI_HashMessageEIP191(t *testing.T) { res := api.HashMessageEIP191(context.Background(), []byte("test")) require.Equal(t, "0x4a5c5d454721bbbb25540c3317521e71c373ae36458f960d2ad46ef088110e95", res.String()) } + +func TestAPI_IsChecksumValidForAddress(t *testing.T) { + api := &API{} + + res, err := api.IsChecksumValidForAddress("0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") + require.NoError(t, err) + require.False(t, res) + + res, err = api.IsChecksumValidForAddress("0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa") + require.NoError(t, err) + require.True(t, res) +}