diff --git a/api/api_full.go b/api/api_full.go index 6d2d0c7b5..7b7574c26 100644 --- a/api/api_full.go +++ b/api/api_full.go @@ -244,6 +244,8 @@ type FullNode interface { WalletImport(context.Context, *types.KeyInfo) (address.Address, error) // WalletDelete deletes an address from the wallet. WalletDelete(context.Context, address.Address) error + // WalletValidateAddress validates whether a given string can be decoded as a well-formed address + WalletValidateAddress(context.Context, string) (address.Address, error) // Other diff --git a/api/apistruct/struct.go b/api/apistruct/struct.go index d5b6950ad..73c4d8ed5 100644 --- a/api/apistruct/struct.go +++ b/api/apistruct/struct.go @@ -129,18 +129,19 @@ type FullNodeStruct struct { MinerGetBaseInfo func(context.Context, address.Address, abi.ChainEpoch, types.TipSetKey) (*api.MiningBaseInfo, error) `perm:"read"` MinerCreateBlock func(context.Context, *api.BlockTemplate) (*types.BlockMsg, error) `perm:"write"` - WalletNew func(context.Context, crypto.SigType) (address.Address, error) `perm:"write"` - WalletHas func(context.Context, address.Address) (bool, error) `perm:"write"` - WalletList func(context.Context) ([]address.Address, error) `perm:"write"` - WalletBalance func(context.Context, address.Address) (types.BigInt, error) `perm:"read"` - WalletSign func(context.Context, address.Address, []byte) (*crypto.Signature, error) `perm:"sign"` - WalletSignMessage func(context.Context, address.Address, *types.Message) (*types.SignedMessage, error) `perm:"sign"` - WalletVerify func(context.Context, address.Address, []byte, *crypto.Signature) (bool, error) `perm:"read"` - WalletDefaultAddress func(context.Context) (address.Address, error) `perm:"write"` - WalletSetDefault func(context.Context, address.Address) error `perm:"admin"` - WalletExport func(context.Context, address.Address) (*types.KeyInfo, error) `perm:"admin"` - WalletImport func(context.Context, *types.KeyInfo) (address.Address, error) `perm:"admin"` - WalletDelete func(context.Context, address.Address) error `perm:"write"` + WalletNew func(context.Context, crypto.SigType) (address.Address, error) `perm:"write"` + WalletHas func(context.Context, address.Address) (bool, error) `perm:"write"` + WalletList func(context.Context) ([]address.Address, error) `perm:"write"` + WalletBalance func(context.Context, address.Address) (types.BigInt, error) `perm:"read"` + WalletSign func(context.Context, address.Address, []byte) (*crypto.Signature, error) `perm:"sign"` + WalletSignMessage func(context.Context, address.Address, *types.Message) (*types.SignedMessage, error) `perm:"sign"` + WalletVerify func(context.Context, address.Address, []byte, *crypto.Signature) (bool, error) `perm:"read"` + WalletDefaultAddress func(context.Context) (address.Address, error) `perm:"write"` + WalletSetDefault func(context.Context, address.Address) error `perm:"admin"` + WalletExport func(context.Context, address.Address) (*types.KeyInfo, error) `perm:"admin"` + WalletImport func(context.Context, *types.KeyInfo) (address.Address, error) `perm:"admin"` + WalletDelete func(context.Context, address.Address) error `perm:"write"` + WalletValidateAddress func(context.Context, string) (address.Address, error) `perm:"read"` ClientImport func(ctx context.Context, ref api.FileRef) (*api.ImportRes, error) `perm:"admin"` ClientListImports func(ctx context.Context) ([]api.Import, error) `perm:"write"` @@ -631,6 +632,10 @@ func (c *FullNodeStruct) WalletDelete(ctx context.Context, addr address.Address) return c.Internal.WalletDelete(ctx, addr) } +func (c *FullNodeStruct) WalletValidateAddress(ctx context.Context, str string) (address.Address, error) { + return c.Internal.WalletValidateAddress(ctx, str) +} + func (c *FullNodeStruct) MpoolGetNonce(ctx context.Context, addr address.Address) (uint64, error) { return c.Internal.MpoolGetNonce(ctx, addr) } diff --git a/documentation/en/api-methods.md b/documentation/en/api-methods.md index ed082ccbf..beaf7f3b6 100644 --- a/documentation/en/api-methods.md +++ b/documentation/en/api-methods.md @@ -181,6 +181,7 @@ * [WalletSetDefault](#WalletSetDefault) * [WalletSign](#WalletSign) * [WalletSignMessage](#WalletSignMessage) + * [WalletValidateAddress](#WalletValidateAddress) * [WalletVerify](#WalletVerify) ## @@ -4585,6 +4586,21 @@ Response: } ``` +### WalletValidateAddress +WalletValidateAddress validates whether a given string can be decoded as a well-formed address + + +Perms: read + +Inputs: +```json +[ + "string value" +] +``` + +Response: `"t01234"` + ### WalletVerify WalletVerify takes an address, a signature, and some bytes, and indicates whether the signature is valid. The address does not have to be in the wallet. diff --git a/node/impl/full/wallet.go b/node/impl/full/wallet.go index 64231b74e..b2ecdebbd 100644 --- a/node/impl/full/wallet.go +++ b/node/impl/full/wallet.go @@ -90,3 +90,7 @@ func (a *WalletAPI) WalletImport(ctx context.Context, ki *types.KeyInfo) (addres func (a *WalletAPI) WalletDelete(ctx context.Context, addr address.Address) error { return a.Wallet.DeleteKey(addr) } + +func (a *WalletAPI) WalletValidateAddress(ctx context.Context, str string) (address.Address, error) { + return address.NewFromString(str) +}