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: ADR-005: Support multisig chain link #708

Merged
merged 46 commits into from
Jan 14, 2022
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
b476e11
Apply SignatureData in Proof
dadamu Dec 22, 2021
11e307d
Fix types tests
dadamu Dec 22, 2021
45b6567
Add signature testutil
dadamu Dec 22, 2021
b6df42d
changed how signature data should be provided inside the proof
RiccardoM Jan 5, 2022
2fc266d
Register interface
dadamu Jan 6, 2022
cdeb8a5
Fix panic in test
dadamu Jan 6, 2022
bef25df
Remove signature nil checking since it causes panic
dadamu Jan 6, 2022
73e6016
Add back gogoproto.equal
dadamu Jan 6, 2022
73430a8
Update profiles types unit tests on multisig chainlink
dadamu Jan 7, 2022
e05f47a
Update keeper unit tests
dadamu Jan 7, 2022
4772a51
Update cli unit tests
dadamu Jan 7, 2022
6b35fe3
Update cli and v210 migration test
dadamu Jan 10, 2022
a9de5f0
Fix proof verify unpack issue
dadamu Jan 10, 2022
3a84c6c
Fix lint
dadamu Jan 10, 2022
7752995
Add invalid signature test for Proof
dadamu Jan 10, 2022
144fac9
Move SignatureDataFromCosmosSignatureData to types
dadamu Jan 10, 2022
c82287e
Build multisig chain link json cli
dadamu Jan 10, 2022
1bc9de5
Add unit test for chain link from multisign cli
dadamu Jan 10, 2022
9c6981e
Remove unused config
dadamu Jan 10, 2022
7d1bf62
Fix lint
dadamu Jan 10, 2022
61753db
Fix SignatureDataFromCosmosSignatureData to handle error properly
dadamu Jan 10, 2022
37cb980
Update create chain link json
dadamu Jan 10, 2022
1e919a3
Update app/desmos/cmd/chainlink/create_json.go
dadamu Jan 10, 2022
d5c3dc9
Update app/desmos/cmd/chainlink/types/getter.go
dadamu Jan 10, 2022
25eeaf2
Apply suggestions create chain link json cmd
dadamu Jan 11, 2022
58675f3
Add doc for testutil
dadamu Jan 11, 2022
69716b5
Merge branch 'paul/adr-005-multisig-chainlink-impl' of github.com:des…
dadamu Jan 11, 2022
86b8b2c
Merge branch 'master' of github.com:desmos-labs/desmos into paul/adr-…
dadamu Jan 11, 2022
b04b997
Fix doc in the getter
dadamu Jan 12, 2022
fc4dd7d
Update changeset
dadamu Jan 12, 2022
b017cca
Revert generateChainLinkJSON
dadamu Jan 12, 2022
bd5bd67
Update app/desmos/cmd/chainlink/create_json.go
dadamu Jan 12, 2022
2f0dae5
Fix the comment in cli test
dadamu Jan 12, 2022
65417f4
Merge branch 'paul/adr-005-multisig-chainlink-impl' of github.com:des…
dadamu Jan 12, 2022
a364e24
Add test to check if signature is nil
dadamu Jan 12, 2022
31854ac
Remove unused function
dadamu Jan 12, 2022
60deaa2
Add more tests for multisig proof
dadamu Jan 12, 2022
41c7496
improved the overall code organization
RiccardoM Jan 12, 2022
40637f3
Merge branch 'paul/adr-005-multisig-chainlink-impl' of github.com:des…
RiccardoM Jan 12, 2022
1769abb
improved the overall code organization
RiccardoM Jan 12, 2022
f198b21
Fix sign mode and test builder
dadamu Jan 13, 2022
ef18023
Rerange the files
dadamu Jan 13, 2022
3f274d9
Update .changeset/entries/a492eff6c4ec45c98cb555b14de9f27ba50da5b147f…
dadamu Jan 14, 2022
04b9181
small doc fixes
RiccardoM Jan 14, 2022
9eb1093
Merge remote-tracking branch 'origin/paul/adr-005-multisig-chainlink-…
RiccardoM Jan 14, 2022
78be05b
Merge branch 'master' into paul/adr-005-multisig-chainlink-impl
mergify[bot] Jan 14, 2022
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: 708
description: Support multisig chain link
dadamu marked this conversation as resolved.
Show resolved Hide resolved
backward_compatible: false
date: 2022-01-12T03:49:42.2638125Z
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,12 @@ proto-update-deps:
@mkdir -p $(IBC_TYPES)/core/client/v1
@curl -sSL $(IBC_URL)/core/client/v1/client.proto > $(IBC_TYPES)/core/client/v1/client.proto

@mkdir -p $(COSMOS_TYPES)/tx/signing/v1beta1
@curl -sSL $(COSMOS_URL)/tx/signing/v1beta1/signing.proto > $(COSMOS_TYPES)/tx/signing/v1beta1/signing.proto

@mkdir -p $(COSMOS_TYPES)/crypto/multisig/v1beta1
@curl -sSL $(COSMOS_URL)/crypto/multisig/v1beta1/multisig.proto > $(COSMOS_TYPES)/crypto/multisig/v1beta1/multisig.proto

## Importing of tendermint protobuf definitions currently requires the
## use of `sed` in order to build properly with cosmos-sdk's proto file layout
## (which is the standard Buf.build FILE_LAYOUT)
Expand Down
125 changes: 113 additions & 12 deletions app/desmos/cmd/chainlink/create_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ import (

chainlinktypes "github.com/desmos-labs/desmos/v2/app/desmos/cmd/chainlink/types"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
authclient "github.com/cosmos/cosmos-sdk/x/auth/client"
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
"github.com/spf13/cobra"

"github.com/desmos-labs/desmos/v2/app"
Expand All @@ -31,8 +36,8 @@ desmos tx profiles link-chain [/path/to/json/file.json]
Note that this command will ask you the mnemonic that should be used to generate the private key of the address you want to link.
The mnemonic is only used temporarily and never stored anywhere.`,
RunE: func(cmd *cobra.Command, args []string) error {
// Get the data
mnemonic, err := getter.GetMnemonic()

isSingleSignatureAccount, err := getter.IsSingleSignatureAccount()
if err != nil {
return err
}
Expand All @@ -42,15 +47,37 @@ The mnemonic is only used temporarily and never stored anywhere.`,
return err
}

filename, err := getter.GetFilename()
if err != nil {
return err
}
var chainLinkJSON profilescliutils.ChainLinkJSON
if isSingleSignatureAccount {
// Get the data
mnemonic, err := getter.GetMnemonic()
if err != nil {
return err
}

// Build che chain link JSON
chainLinkJSON, err := generateChainLinkJSON(mnemonic, chain)
if err != nil {
return err
// Build che chain link JSON
dadamu marked this conversation as resolved.
Show resolved Hide resolved
chainLinkJSON, err = generateChainLinkJSON(mnemonic, chain)
if err != nil {
return err
}
} else {
multiSignedTxFile, err := getter.GetMultiSignedTxFile()
if err != nil {
return err
}
signedChainID, err := getter.GetSignedChainID()
if err != nil {
return err
}
txCfg, txBuilder, txFactory, err := getMultisignedTxReference(cmd, multiSignedTxFile, signedChainID)
if err != nil {
return err
}

chainLinkJSON, err = getChainLinkJSONFromMultiSign(txCfg, txBuilder, txFactory, chain)
if err != nil {
return err
}
}

cdc, _ := app.MakeCodecs()
Expand All @@ -59,6 +86,10 @@ The mnemonic is only used temporarily and never stored anywhere.`,
return err
}

filename, err := getter.GetFilename()
if err != nil {
return err
}
if filename != "" {
err = ioutil.WriteFile(filename, bz, 0600)
if err != nil {
Expand All @@ -73,7 +104,7 @@ The mnemonic is only used temporarily and never stored anywhere.`,
}
}

// generateChainLinkJSON returns build a new ChainLinkJSON intance using the provided mnemonic and chain configuration
// generateChainLinkJSON build a new ChainLinkJSON instance using the provided mnemonic and chain configuration
func generateChainLinkJSON(mnemonic string, chain chainlinktypes.Chain) (profilescliutils.ChainLinkJSON, error) {
// Create an in-memory keybase for signing
keyBase := keyring.NewInMemory()
Expand All @@ -91,10 +122,80 @@ func generateChainLinkJSON(mnemonic string, chain chainlinktypes.Chain) (profile
if err != nil {
return profilescliutils.ChainLinkJSON{}, err
}
sigData := &profilestypes.SingleSignatureData{
Mode: signing.SignMode_SIGN_MODE_DIRECT,
Signature: sig,
}

return profilescliutils.NewChainLinkJSON(
profilestypes.NewBech32Address(addr, chain.Prefix),
profilestypes.NewProof(pubkey, hex.EncodeToString(sig), hex.EncodeToString(value)),
profilestypes.NewProof(pubkey, sigData, hex.EncodeToString(value)),
profilestypes.NewChainConfig(chain.Name),
), nil
}

// getMultisignedTxReference returns the multisigned tx reference to build the chain link json
func getMultisignedTxReference(
cmd *cobra.Command,
txFile string,
signedChainID string,
) (client.TxConfig, client.TxBuilder, tx.Factory, error) {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return nil, nil, tx.Factory{}, err
}
parsedTx, err := authclient.ReadTxFromFile(clientCtx, txFile)
if err != nil {
return nil, nil, tx.Factory{}, err
}
txCfg := clientCtx.TxConfig
txBuilder, err := txCfg.WrapTxBuilder(parsedTx)
if err != nil {
return nil, txBuilder, tx.Factory{}, err
}
txFactory := tx.NewFactoryCLI(clientCtx, cmd.Flags()).WithChainID(signedChainID)
if txFactory.SignMode() == signing.SignMode_SIGN_MODE_UNSPECIFIED {
txFactory = txFactory.WithSignMode(signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON)
}
return txCfg, txBuilder, txFactory, err
}

// getChainLinkJSONFromMultiSign generates the chain-link JSON from the multisign tx reference
func getChainLinkJSONFromMultiSign(
txCfg client.TxConfig,
txBuilder client.TxBuilder,
txFactory tx.Factory,
chain chainlinktypes.Chain,
) (profilescliutils.ChainLinkJSON, error) {
sigs, err := txBuilder.GetTx().GetSignaturesV2()
if err != nil {
return profilescliutils.ChainLinkJSON{}, err
}
// make sure there is only one signature for the multisig account
if len(sigs) != 1 {
return profilescliutils.ChainLinkJSON{}, fmt.Errorf("invalid number of signatures")
}
multisigSig := sigs[0]
signingData := authsigning.SignerData{
ChainID: txFactory.ChainID(),
AccountNumber: txFactory.AccountNumber(),
Sequence: txFactory.Sequence(),
}
// the bytes of plain text
value, err := txCfg.SignModeHandler().GetSignBytes(txFactory.SignMode(), signingData, txBuilder.GetTx())
if err != nil {
return profilescliutils.ChainLinkJSON{}, err
}

addr, err := sdk.Bech32ifyAddressBytes(chain.Prefix, multisigSig.PubKey.Address().Bytes())
if err != nil {
return profilescliutils.ChainLinkJSON{}, err
}

sigData, err := profilestypes.SignatureDataFromCosmosSignatureData(multisigSig.Data)
return profilescliutils.NewChainLinkJSON(
profilestypes.NewBech32Address(addr, chain.Prefix),
profilestypes.NewProof(multisigSig.PubKey, sigData, hex.EncodeToString(value)),
profilestypes.NewChainConfig(chain.Name),
), err
}
Loading