Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions services/wallet/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
12 changes: 12 additions & 0 deletions services/wallet/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}