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

feat: add support for hex address in chain link #688

Merged
merged 41 commits into from
Dec 20, 2021
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
5d08b84
Init proto message
dadamu Dec 7, 2021
91aab8e
Implement eth address data
dadamu Dec 9, 2021
653c707
Rename hex address into eth address
dadamu Dec 9, 2021
c3d959d
Fix tests
dadamu Dec 9, 2021
2fca200
Revert mod
dadamu Dec 9, 2021
0ea0890
Add comments
dadamu Dec 9, 2021
1dd59b0
Fix typo
dadamu Dec 9, 2021
651fb21
Run go mod tidy
dadamu Dec 9, 2021
38f0bb5
Update proto/desmos/profiles/v1beta1/models_chain_links.proto
dadamu Dec 10, 2021
62947af
Update x/profiles/types/models_chain_links.go
dadamu Dec 10, 2021
d946c68
Update x/profiles/types/models_chain_links.go
dadamu Dec 10, 2021
d4be22d
Update x/profiles/types/models_chain_links.go
dadamu Dec 10, 2021
f1d7837
Update x/profiles/types/models_chain_links.go
dadamu Dec 10, 2021
8b1fa03
Add lost tests
dadamu Dec 10, 2021
03c40ee
Add spaced address test
dadamu Dec 10, 2021
e392738
Update changelog
dadamu Dec 10, 2021
21e0dc4
Remove extra space
dadamu Dec 10, 2021
e23ecf9
Remove strings trimspace in prefix and address length checking
dadamu Dec 10, 2021
aae6d0b
Register interface
dadamu Dec 10, 2021
c2897d7
Remove prefix
dadamu Dec 10, 2021
f55623a
Rename eth address into eth hex address
dadamu Dec 10, 2021
c63a524
Fix test name
dadamu Dec 10, 2021
4a8c9c4
Merge branch 'master' of github.com:desmos-labs/desmos into paul/supp…
dadamu Dec 10, 2021
5580de9
Rename EthHexAddress into HexAddress
dadamu Dec 13, 2021
5fdf226
Fix typo
dadamu Dec 13, 2021
74d2313
Update comment
dadamu Dec 13, 2021
8a37f06
Update changeset
dadamu Dec 13, 2021
e677d13
Update proto/desmos/profiles/v1beta1/models_chain_links.proto
dadamu Dec 13, 2021
bf5c129
Update proto/desmos/profiles/v1beta1/models_chain_links.proto
dadamu Dec 13, 2021
2afd707
Apply suggestions
dadamu Dec 13, 2021
de49d17
Update x/profiles/types/models_chain_links.go
dadamu Dec 16, 2021
ac2c218
Update proto/desmos/profiles/v1beta1/models_chain_links.proto
dadamu Dec 16, 2021
54c3afb
Apply suggestions
dadamu Dec 16, 2021
11a855d
Add prefix
dadamu Dec 20, 2021
fd395d8
Remove duplicated checking
dadamu Dec 20, 2021
aa0af94
Merge branch 'master' of github.com:desmos-labs/desmos into paul/supp…
dadamu Dec 20, 2021
1dc6dea
Update x/profiles/types/models_chain_links_test.go
dadamu Dec 20, 2021
be63ecb
Update proto/desmos/profiles/v1beta1/models_chain_links.proto
dadamu Dec 20, 2021
ee6bb4b
Update x/profiles/types/models_chain_links_test.go
dadamu Dec 20, 2021
60f40f5
Apply suggestions
dadamu Dec 20, 2021
9f8c160
Merge branch 'master' into paul/support-hex-address-chain-link
mergify[bot] Dec 20, 2021
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type: feat
module: x/profiles
pull_request: 688
description: add support for hex address in chain link
backward_compatible: true
date: 2021-12-10T03:38:53.1017055Z
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ go 1.15

require (
github.com/armon/go-metrics v0.3.10
github.com/btcsuite/btcd v0.22.0-beta
github.com/cosmos/cosmos-sdk v0.44.5
github.com/cosmos/go-bip39 v1.0.0
github.com/cosmos/ibc-go v1.2.4
github.com/ethereum/go-ethereum v1.10.13
github.com/ghodss/yaml v1.0.0
github.com/gogo/protobuf v1.3.3
github.com/golang/protobuf v1.5.2
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect
github.com/manifoldco/promptui v0.9.0
github.com/mr-tron/base58 v1.2.0
github.com/rakyll/statik v0.1.7
github.com/regen-network/cosmos-proto v0.3.1
github.com/spf13/cast v1.4.1
github.com/spf13/cobra v1.2.1
github.com/stretchr/testify v1.7.0
github.com/syndtr/goleveldb v1.0.1-0.20210305035536-64b5b1c73954 // indirect
github.com/tendermint/tendermint v0.34.15
github.com/tendermint/tm-db v0.6.6
google.golang.org/genproto v0.0.0-20210917145530-b395a37504d4
Expand Down
147 changes: 142 additions & 5 deletions go.sum

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions proto/desmos/profiles/v1beta1/models_chain_links.proto
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,15 @@ message Base58Address {

// Value contains the Base58-encoded address
string value = 1 [ (gogoproto.moretags) = "yaml:\"value\"" ];
}

// HexAddress represents an Hex-encoded address
dadamu marked this conversation as resolved.
Show resolved Hide resolved
message HexAddress {
option (gogoproto.goproto_getters) = false;
option (gogoproto.equal) = true;
option (gogoproto.goproto_stringer) = true;
option (cosmos_proto.implements_interface) = "AddressData";

// Value represents the hex address value
string value = 1 [ (gogoproto.moretags) = "yaml:\"value\"" ];
}
2 changes: 2 additions & 0 deletions x/profiles/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
cdc.RegisterInterface((*AddressData)(nil), nil)
cdc.RegisterConcrete(&Bech32Address{}, "desmos/Bech32Address", nil)
cdc.RegisterConcrete(&Base58Address{}, "desmos/Base58Address", nil)
cdc.RegisterConcrete(&HexAddress{}, "desmos/HexAddress", nil)

cdc.RegisterConcrete(&Profile{}, "desmos/Profile", nil)
}
Expand All @@ -42,6 +43,7 @@ func RegisterInterfaces(registry types.InterfaceRegistry) {
(*AddressData)(nil),
&Bech32Address{},
&Base58Address{},
&HexAddress{},
)

registry.RegisterImplementations((*sdk.Msg)(nil),
Expand Down
53 changes: 53 additions & 0 deletions x/profiles/types/models_chain_links.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"github.com/cosmos/cosmos-sdk/types/bech32"
"github.com/tendermint/tendermint/crypto/tmhash"

"github.com/btcsuite/btcd/btcec"
"github.com/ethereum/go-ethereum/crypto"
"github.com/gogo/protobuf/proto"
"github.com/mr-tron/base58"

Expand Down Expand Up @@ -202,6 +204,57 @@ func (b Base58Address) VerifyPubKey(key cryptotypes.PubKey) (bool, error) {

// --------------------------------------------------------------------------------------------------------------------

var _ AddressData = &HexAddress{}

// NewHexAddress returns a new HexAddress instance
// NOTE: Currently it only supports keccak256-uncompressed addresses
dadamu marked this conversation as resolved.
Show resolved Hide resolved
func NewHexAddress(value string) *HexAddress {
return &HexAddress{Value: value}
}

// Validate implements AddressData
func (h HexAddress) Validate() error {
if strings.TrimSpace(h.Value) == "" {
return fmt.Errorf("value cannot be empty or blank")
}

if len(h.Value) <= 2 {
return fmt.Errorf("address cannot be smaller than prefix")
}

prefix, addrWithoutPrefix := h.Value[:2], h.Value[2:]
if prefix != "0x" {
return fmt.Errorf("address prefix does not match the 0x prefix")
}
RiccardoM marked this conversation as resolved.
Show resolved Hide resolved

if _, err := hex.DecodeString(addrWithoutPrefix); err != nil {
return fmt.Errorf("invalid hex address")
}
return nil
}

// GetValue implements AddressData
func (h HexAddress) GetValue() string {
return h.Value
}

// VerifyPubKey implements AddressData
func (h HexAddress) VerifyPubKey(key cryptotypes.PubKey) (bool, error) {
addr := h.Value[2:]
bz, err := hex.DecodeString(addr)
if err != nil {
return false, err
}
pubKey, err := btcec.ParsePubKey(key.Bytes(), btcec.S256())
if err != nil {
return false, err
}
uncompressedPubKey := pubKey.SerializeUncompressed()
return bytes.Equal(crypto.Keccak256(uncompressedPubKey[1:])[12:], bz), err
}

// --------------------------------------------------------------------------------------------------------------------

// UnpackAddressData deserializes the given any type value as an address data using the provided unpacker
func UnpackAddressData(unpacker codectypes.AnyUnpacker, addressAny *codectypes.Any) (AddressData, error) {
var address AddressData
Expand Down
Loading