Skip to content

Commit

Permalink
Add addess in AuxSignerData
Browse files Browse the repository at this point in the history
  • Loading branch information
amaury1093 committed Nov 9, 2021
1 parent b9f3cf3 commit 0917b76
Show file tree
Hide file tree
Showing 9 changed files with 175 additions and 86 deletions.
6 changes: 6 additions & 0 deletions client/tx/aux_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ func NewAuxTxBuilder() AuxTxBuilder {
return AuxTxBuilder{}
}

func (b *AuxTxBuilder) SetAddress(addr string) {
b.checkEmptyFields()

b.auxSignerData.Address = addr
}

func (b *AuxTxBuilder) SetMemo(memo string) {
b.checkEmptyFields()

Expand Down
21 changes: 21 additions & 0 deletions client/tx/aux_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,30 @@ func TestAuxTxBuilder(t *testing.T) {
},
false, "",
},
{
"GetAuxSignerData address should not be empty",
func() error {
b.SetMsgs(msg)
b.SetPubKey(pk)
b.SetTip(tip)
err := b.SetSignMode(signing.SignMode_SIGN_MODE_DIRECT_AUX)
require.NoError(t, err)

_, err = b.GetSignBytes()
require.NoError(t, err)

_, err = b.GetAuxSignerData()
return err
},
true, "address cannot be empty: invalid request",
},
{
"GetAuxSignerData signature should not be empty",
func() error {
b.SetMsgs(msg)
b.SetPubKey(pk)
b.SetTip(tip)
b.SetAddress(addr.String())
err := b.SetSignMode(signing.SignMode_SIGN_MODE_DIRECT_AUX)
require.NoError(t, err)

Expand All @@ -144,6 +162,7 @@ func TestAuxTxBuilder(t *testing.T) {
b.SetMsgs(msg)
b.SetPubKey(pk)
b.SetTip(tip)
b.SetAddress(addr.String())
err := b.SetSignMode(signing.SignMode_SIGN_MODE_DIRECT_AUX)
require.NoError(t, err)

Expand Down Expand Up @@ -180,6 +199,7 @@ func TestAuxTxBuilder(t *testing.T) {
b.SetMsgs(msg)
b.SetPubKey(pk)
b.SetTip(tip)
b.SetAddress(addr.String())
err := b.SetSignMode(signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON)
require.NoError(t, err)

Expand All @@ -194,6 +214,7 @@ func TestAuxTxBuilder(t *testing.T) {
b.SetMsgs(msg)
b.SetPubKey(pk)
b.SetTip(tip)
b.SetAddress(addr.String())
err := b.SetSignMode(signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON)
require.NoError(t, err)

Expand Down
1 change: 1 addition & 0 deletions docs/core/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -9488,6 +9488,7 @@ Since: cosmos-sdk 0.45

| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `address` | [string](#string) | | address is the bech32-encoded address of the auxiliary signer. If using AuxSignerData across different chains, the bech32 prefix of the target chain (where the final transaction is broadcasted) should be used. |
| `sign_doc` | [SignDocDirectAux](#cosmos.tx.v1beta1.SignDocDirectAux) | | sign_doc is the SIGN_MOD_DIRECT_AUX sign doc that the auxiliary signer signs. Note: we use the same sign doc even if we're signing with LEGACY_AMINO_JSON. |
| `mode` | [cosmos.tx.signing.v1beta1.SignMode](#cosmos.tx.signing.v1beta1.SignMode) | | mode is the signing mode of the single signer |
| `sig` | [bytes](#bytes) | | sig is the signature of the sign doc. |
Expand Down
10 changes: 7 additions & 3 deletions proto/cosmos/tx/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,16 @@ message Tip {
//
// Since: cosmos-sdk 0.45
message AuxSignerData {
// address is the bech32-encoded address of the auxiliary signer. If using
// AuxSignerData across different chains, the bech32 prefix of the target
// chain (where the final transaction is broadcasted) should be used.
string address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// sign_doc is the SIGN_MOD_DIRECT_AUX sign doc that the auxiliary signer
// signs. Note: we use the same sign doc even if we're signing with
// LEGACY_AMINO_JSON.
SignDocDirectAux sign_doc = 1;
SignDocDirectAux sign_doc = 2;
// mode is the signing mode of the single signer
cosmos.tx.signing.v1beta1.SignMode mode = 2;
cosmos.tx.signing.v1beta1.SignMode mode = 3;
// sig is the signature of the sign doc.
bytes sig = 3;
bytes sig = 4;
}
4 changes: 4 additions & 0 deletions types/tx/aux.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ func (s *SignDocDirectAux) UnpackInterfaces(unpacker codectypes.AnyUnpacker) err

// ValidateBasic performs stateless validation of the auxiliary tx.
func (a *AuxSignerData) ValidateBasic() error {
if a.Address == "" {
return sdkerrors.ErrInvalidRequest.Wrapf("address cannot be empty")
}

if a.Mode != signing.SignMode_SIGN_MODE_DIRECT_AUX && a.Mode != signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON {
return sdkerrors.ErrInvalidRequest.Wrapf("AuxTxBuilder can only sign with %s or %s", signing.SignMode_SIGN_MODE_DIRECT_AUX, signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON)
}
Expand Down
13 changes: 7 additions & 6 deletions types/tx/aux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestSignDocDirectAux(t *testing.T) {

func TestAuxSignerData(t *testing.T) {
bodyBz := []byte{42}
_, pk, _ := testdata.KeyTestPubAddr()
_, pk, addr := testdata.KeyTestPubAddr()
pkAny, err := codectypes.NewAnyWithValue(pk)
require.NoError(t, err)
sig := []byte{42}
Expand All @@ -61,11 +61,12 @@ func TestAuxSignerData(t *testing.T) {
sd tx.AuxSignerData
expErr bool
}{
{"empty sign mode", tx.AuxSignerData{}, true},
{"SIGN_MODE_DIRECT", tx.AuxSignerData{Mode: signing.SignMode(signing.SignMode_SIGN_MODE_DIRECT)}, true},
{"no sig", tx.AuxSignerData{Mode: signing.SignMode(signing.SignMode_SIGN_MODE_DIRECT)}, true},
{"happy case WITH DIRECT_AUX", tx.AuxSignerData{Mode: signing.SignMode_SIGN_MODE_DIRECT_AUX, SignDoc: sd, Sig: sig}, false},
{"happy case WITH DIRECT_AUX", tx.AuxSignerData{Mode: signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, SignDoc: sd, Sig: sig}, false},
{"empty address", tx.AuxSignerData{}, true},
{"empty sign mode", tx.AuxSignerData{Address: addr.String()}, true},
{"SIGN_MODE_DIRECT", tx.AuxSignerData{Address: addr.String(), Mode: signing.SignMode(signing.SignMode_SIGN_MODE_DIRECT)}, true},
{"no sig", tx.AuxSignerData{Address: addr.String(), Mode: signing.SignMode(signing.SignMode_SIGN_MODE_DIRECT)}, true},
{"happy case WITH DIRECT_AUX", tx.AuxSignerData{Address: addr.String(), Mode: signing.SignMode_SIGN_MODE_DIRECT_AUX, SignDoc: sd, Sig: sig}, false},
{"happy case WITH DIRECT_AUX", tx.AuxSignerData{Address: addr.String(), Mode: signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, SignDoc: sd, Sig: sig}, false},
}

for _, tc := range testcases {
Expand Down
Loading

0 comments on commit 0917b76

Please sign in to comment.