chore_: endpoint for checking address checksum validity added to wallet api

- added `IsChecksumValidForAddress` function to `wallet` api
This commit is contained in:
Sale Djenic 2024-07-30 14:43:45 +02:00 committed by saledjenic
parent 855643757e
commit 19b5bcf3ce
2 changed files with 18 additions and 0 deletions

View File

@ -15,6 +15,7 @@ import (
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
gethrpc "github.com/ethereum/go-ethereum/rpc" gethrpc "github.com/ethereum/go-ethereum/rpc"
signercore "github.com/ethereum/go-ethereum/signer/core/apitypes" 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/account"
"github.com/status-im/status-go/eth-node/crypto" "github.com/status-im/status-go/eth-node/crypto"
"github.com/status-im/status-go/eth-node/types" "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 { func (api *API) RestartWalletReloadTimer(ctx context.Context) error {
return api.s.reader.Restart() 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)
}

View File

@ -29,3 +29,15 @@ func TestAPI_HashMessageEIP191(t *testing.T) {
res := api.HashMessageEIP191(context.Background(), []byte("test")) res := api.HashMessageEIP191(context.Background(), []byte("test"))
require.Equal(t, "0x4a5c5d454721bbbb25540c3317521e71c373ae36458f960d2ad46ef088110e95", res.String()) 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)
}