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 all 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.5
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.3.0
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-20211208223120-3a66f561d7aa
Expand Down
146 changes: 141 additions & 5 deletions go.sum

Large diffs are not rendered by default.

15 changes: 15 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,19 @@ 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
// NOTE: Currently it only supports keccak256-uncompressed addresses
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\"" ];

// Prefix represents the optional prefix used during address encoding (e.g. 0x)
string prefix = 2 [ (gogoproto.moretags) = "yaml:\"prefix\"" ];
RiccardoM marked this conversation as resolved.
Show resolved Hide resolved
}
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
52 changes: 52 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,56 @@ func (b Base58Address) VerifyPubKey(key cryptotypes.PubKey) (bool, error) {

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

var _ AddressData = &HexAddress{}

// NewHexAddress returns a new HexAddress instance
func NewHexAddress(value, prefix string) *HexAddress {
return &HexAddress{Value: value, Prefix: prefix}
}

// 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) <= len(h.Prefix) {
return fmt.Errorf("address cannot be smaller than prefix")
}

prefix, addrWithoutPrefix := h.Value[:len(h.Prefix)], h.Value[len(h.Prefix):]
if prefix != h.Prefix {
return fmt.Errorf("prefix does not match")
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[len(h.Prefix):]
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