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 Textual SignModeHandler #13734

Closed
wants to merge 98 commits into from
Closed
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
0b0f659
wip
amaury1093 Oct 20, 2022
ea7691b
wip
amaury1093 Oct 20, 2022
d857356
Add signer data to Textual
amaury1093 Oct 20, 2022
6c3c77a
Use any
amaury1093 Oct 20, 2022
94c0501
wip
amaury1093 Oct 24, 2022
49cff84
WIP
amaury1093 Oct 24, 2022
10891fd
add tx vr
amaury1093 Oct 25, 2022
9700665
Add examples
amaury1093 Oct 25, 2022
709dfb5
revert
amaury1093 Oct 25, 2022
460bce9
Add hash
amaury1093 Oct 25, 2022
eeaeaa9
Merge branch 'main' of ssh://github.com/cosmos/cosmos-sdk into am/135…
amaury1093 Oct 25, 2022
ae1fb1f
codegen
amaury1093 Oct 25, 2022
1513109
updates
amaury1093 Oct 25, 2022
18777bf
simplify test
amaury1093 Oct 25, 2022
b29e359
go mod tidy
amaury1093 Oct 25, 2022
b3a5670
Useless import
amaury1093 Oct 25, 2022
4d28d9c
Revert
amaury1093 Oct 25, 2022
f97e3ea
typo
amaury1093 Oct 25, 2022
8e363d5
remove textual fields
amaury1093 Oct 27, 2022
0bad609
create proto types
amaury1093 Oct 27, 2022
6d252e4
Fix tests
amaury1093 Oct 27, 2022
4e24b71
add comment
amaury1093 Oct 27, 2022
d1338ed
regenerate to internal
amaury1093 Nov 2, 2022
3cf05e5
Wire up sign mode handler
amaury1093 Nov 2, 2022
badc2c3
wip
amaury1093 Nov 2, 2022
a815747
Make it work?
amaury1093 Nov 2, 2022
cd038f5
Add comments
amaury1093 Nov 2, 2022
65e60ed
wip
amaury1093 Nov 7, 2022
75e0bc3
Merge branch 'main' of ssh://github.com/cosmos/cosmos-sdk into am/135…
amaury1093 Nov 14, 2022
025a9eb
go mod tidy
amaury1093 Nov 14, 2022
93d4b5d
Use MessageValueRenderer
amaury1093 Nov 14, 2022
9c87a2c
Merge branch 'main' of ssh://github.com/cosmos/cosmos-sdk into am/135…
amaury1093 Nov 28, 2022
f2b7a58
fix conflicts
amaury1093 Nov 28, 2022
0efbc25
Add part2
amaury1093 Nov 28, 2022
77a6ae1
Start doing parse
amaury1093 Nov 28, 2022
4f810fa
Merge branch 'main' of ssh://github.com/cosmos/cosmos-sdk into am/135…
amaury1093 Nov 28, 2022
00c313a
wip
amaury1093 Nov 29, 2022
7c3a6e6
Merge branch 'main' of ssh://github.com/cosmos/cosmos-sdk into am/135…
amaury1093 Nov 29, 2022
96e5137
Show transactions
amaury1093 Nov 29, 2022
bbee363
Add metadata
amaury1093 Nov 29, 2022
98c26e9
Add all fields
amaury1093 Nov 29, 2022
721e0c6
Merge branch 'main' of ssh://github.com/cosmos/cosmos-sdk into am/135…
amaury1093 Nov 30, 2022
bac3383
Add complex test case
amaury1093 Dec 1, 2022
db5dbfb
Link to JSON
amaury1093 Dec 1, 2022
45401a8
changelog
amaury1093 Dec 1, 2022
463a5e4
Merge branch 'main' of ssh://github.com/cosmos/cosmos-sdk into am/135…
amaury1093 Dec 1, 2022
7042623
Update
amaury1093 Dec 1, 2022
6fd8d79
update links
amaury1093 Dec 1, 2022
d0bb4f8
Merge branch 'main' of ssh://github.com/cosmos/cosmos-sdk into am/135…
amaury1093 Dec 2, 2022
201a1ff
go mod tidy
amaury1093 Dec 2, 2022
32a0608
Fix enum
amaury1093 Dec 2, 2022
01cfb3c
Make JSON clearer
amaury1093 Dec 2, 2022
2169ea1
Update links
amaury1093 Dec 2, 2022
b3e0fca
Refactor proto files
amaury1093 Dec 2, 2022
cc59b56
Clean up
amaury1093 Dec 2, 2022
5d96b7d
Merge branch 'main' of ssh://github.com/cosmos/cosmos-sdk into am/135…
amaury1093 Dec 2, 2022
727b93c
WIP parsing
amaury1093 Dec 2, 2022
79c6698
newlines
amaury1093 Dec 6, 2022
0106bc1
Pluralize
amaury1093 Dec 6, 2022
d05479d
Use enveloppe in approach 2a
amaury1093 Dec 6, 2022
cb0b6cc
Coin amounts are Ints
amaury1093 Dec 6, 2022
a1bc7dd
Add tests
amaury1093 Dec 6, 2022
37c9c52
buf format
amaury1093 Dec 6, 2022
82c0dd7
Add address
amaury1093 Dec 6, 2022
ee78038
Fix all tests
amaury1093 Dec 6, 2022
7c9dabc
Add address to spec
amaury1093 Dec 6, 2022
d05951f
Add changelog
amaury1093 Dec 6, 2022
d2d6d19
Update links to examples
amaury1093 Dec 6, 2022
f80932c
Merge branch 'main' into am/13579-textual-tx
amaury1093 Dec 6, 2022
f14e704
envelope
amaury1093 Dec 7, 2022
094abcd
2 test files
amaury1093 Dec 7, 2022
5647c04
Update exampls
amaury1093 Dec 7, 2022
f540695
Merge branch 'main' into am/13579-textual-tx
amaury1093 Dec 7, 2022
979e3ba
Merge branch 'main' into am/13579-textual-tx
amaury1093 Dec 12, 2022
c827732
Merge branch 'main' of ssh://github.com/cosmos/cosmos-sdk into am/135…
amaury1093 Jan 9, 2023
f54b831
Merge branch 'am/13579-textual-tx' into am/textual-wip-handler
amaury1093 Jan 9, 2023
317b327
Make it build
amaury1093 Jan 9, 2023
a462cb4
Improve any error message
amaury1093 Jan 9, 2023
cbeebaf
Add client-side stuff for textual
amaury1093 Jan 11, 2023
caf25d9
Add references to when to change Envelope
amaury1093 Jan 11, 2023
1a94bd7
Merge branch 'main' into am/13579-textual-tx
amaury1093 Jan 11, 2023
e0a1626
Fix tests
amaury1093 Jan 11, 2023
e3e55b5
Merge branch 'am/13579-textual-tx' of ssh://github.com/cosmos/cosmos-…
amaury1093 Jan 11, 2023
0d321f1
Merge branch 'am/13579-textual-tx' of ssh://github.com/cosmos/cosmos-…
amaury1093 Jan 11, 2023
e358af2
Merge branch 'main' of ssh://github.com/cosmos/cosmos-sdk into am/tex…
amaury1093 Jan 11, 2023
117cac6
Merge branch 'main' of ssh://github.com/cosmos/cosmos-sdk into am/tex…
amaury1093 Jan 16, 2023
41fdedd
go mod tidy
amaury1093 Jan 16, 2023
b0d9c4b
Fix build
amaury1093 Jan 16, 2023
3bb2b6f
Amino default still
amaury1093 Jan 16, 2023
6c595dd
revert
amaury1093 Jan 16, 2023
ceae2c5
revert
amaury1093 Jan 16, 2023
ac0b7af
Use local cosmos-ledger-go
amaury1093 Jan 16, 2023
65fd876
clean ups
amaury1093 Jan 16, 2023
17041c5
Update ot latest pacakge
amaury1093 Jan 16, 2023
e3785a5
Merge branch 'main' of ssh://github.com/cosmos/cosmos-sdk into am/tex…
amaury1093 Jan 17, 2023
f285a6d
x/tx
amaury1093 Jan 17, 2023
ee4e55b
Add ante tests
amaury1093 Jan 17, 2023
fb09df5
Make tests pass
amaury1093 Jan 17, 2023
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
754 changes: 754 additions & 0 deletions api/cosmos/msg/textual/v1/textual.pulsar.go

Large diffs are not rendered by default.

1,305 changes: 1,040 additions & 265 deletions api/cosmos/tx/signing/v1beta1/signing.pulsar.go

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions docs/architecture/adr-050-sign-mode-textual.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ We define "transaction envelope" as all data in a transaction that is not in the
```
Chain ID: <string>
Account number: <uint64>
*Public Key: <hex_string>
Sequence: <uint64>
*Public Key: <hex_string>
<TxBody> // See #8.
Fee: <coins> // See value renderers for coins encoding.
*Fee payer: <string> // Skipped if no fee_payer set
Expand Down Expand Up @@ -306,8 +306,8 @@ SIGN_MODE_TEXTUAL:
```
Chain ID: simapp-1
Account number: 10
*Public Key: iQ...== // Hex pubkey
Sequence: 2
*Public Key: 0xA1DE...E5DE // Hex pubkey
This transaction has 1 message:
Message (1/1): bank v1beta1 send coins
From: cosmos1...abc
Expand Down Expand Up @@ -386,8 +386,8 @@ SIGN_MODE_TEXTUAL for the feepayer:
```
Chain ID: simapp-1
Account number: 10
*Public Key: iR...==
Sequence: 2
*Public Key: iR...==
This transaction has 1 message:
Message (1/1): bank v1beta1 send coins
From: cosmos1...abc
Expand All @@ -401,7 +401,7 @@ Tip: 200 ibc/CDC4587874B85BEA4FCEC3CEA5A1195139799A1FEE711A07D972537E18FDA39D
*Gas: 100'000
*This transaction has 1 other signer:
*Signer (1/2):
*Public Key: iQ...==
*Public Key: 0xA1DE...E5DE
*Sign mode: Direct Aux
*Sequence: 42
*End of other signers
Expand Down Expand Up @@ -515,8 +515,8 @@ SIGN_MODE_TEXTUAL for 1st signer `cosmos1...abc`:
```
Chain ID: simapp-1
Account number: 10
*Public Key: iQ...==
Sequence: 2
*Public Key: 0xA1DE...E5DE
This transaction has 2 messages:
Message (1/2): bank v1beta1 send coins
From: cosmos1...abc
Expand Down
22 changes: 22 additions & 0 deletions proto/cosmos/msg/textual/v1/textual.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
syntax = "proto3";

package cosmos.msg.textual.v1;

import "cosmos/tx/signing/v1beta1/signing.proto";

// TextualData represents all the information needed to generate
// the textual SignDoc (which is a []Screen). It is meant to be
// used as an internal type in Textual's implementations.
message TextualData {
// body_bytes is a protobuf serialization of a TxBody that matches the
// representation in SignDoc.
bytes body_bytes = 1;

// auth_info_bytes is a protobuf serialization of an AuthInfo that matches the
// representation in SignDoc.
bytes auth_info_bytes = 2;

// signer_data represents all data in Textual's SignDoc that are not
// inside the Tx body and auth_info.
cosmos.tx.signing.v1beta1.SignerData signer_data = 3;
}
32 changes: 32 additions & 0 deletions proto/cosmos/tx/signing/v1beta1/signing.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cosmos.tx.signing.v1beta1;

import "cosmos/crypto/multisig/v1beta1/multisig.proto";
import "google/protobuf/any.proto";
import "cosmos_proto/cosmos.proto";

option go_package = "github.com/cosmos/cosmos-sdk/types/tx/signing";

Expand Down Expand Up @@ -104,3 +105,34 @@ message SignatureDescriptor {
}
}
}

// SignerData is the specific information needed to sign a transaction that generally
// isn't included in the transaction body itself.
message SignerData {
// address is the address of the signer.
//
// In case of multisigs, this should be the multisig's address.
string address = 1 [(cosmos_proto.scalar) = "AddressString"];

// chain_id is the chain that this transaction is targeted.
string chain_id = 2;

// account_number is the account number of the signer.
//
// In case of multisigs, this should be the multisig account number.
uint64 account_number = 3;

// sequence is the account sequence number of the signer that is used
// for replay protection. This field is only useful for Legacy Amino signing,
// since in SIGN_MODE_DIRECT the account sequence is already in the signer
// info.
//
// In case of multisigs, this should be the multisig sequence.
uint64 sequence = 4;

// pub_key is the public key of the signer.
//
// In case of multisigs, this should be the pubkey of the member of the
// multisig that is signing the current sign doc.
google.protobuf.Any pub_key = 5;
}
9 changes: 9 additions & 0 deletions simapp/app_legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ import (
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
"github.com/cosmos/cosmos-sdk/x/auth/posthandler"
authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation"
"github.com/cosmos/cosmos-sdk/x/auth/tx"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
txmodule "github.com/cosmos/cosmos-sdk/x/auth/tx/module"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
Expand Down Expand Up @@ -498,6 +500,13 @@ func NewSimApp(
}

func (app *SimApp) setAnteHandler(txConfig client.TxConfig) {
// Enable textual in TxConfig
textual := txmodule.NewTextual(app.BankKeeper)
// Optionally, you can define custom field-level and message-level
// renderers here, using respectively `textual.DefineScalar` and
// `textual.DefineMessageRenderer`.
app.txConfig = authtx.NewTxConfigWithTextual(app.appCodec.(codec.ProtoCodecMarshaler), tx.DefaultSignModes, textual)

anteHandler, err := ante.NewAnteHandler(
ante.HandlerOptions{
AccountKeeper: app.AccountKeeper,
Expand Down
1 change: 1 addition & 0 deletions tx/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ require (

// temporary until we tag a new go module
replace (
cosmossdk.io/api => ../api
cosmossdk.io/core => ../core
cosmossdk.io/math => ../math
)
2 changes: 0 additions & 2 deletions tx/go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
cosmossdk.io/api v0.2.1 h1:4m6vIHKJygrixSIfOsD3Mhij9vZlQC/+BTeb+Un9os0=
cosmossdk.io/api v0.2.1/go.mod h1:kNpfY0UY7Cz4ZuLJ4hm9auUGfmj23UFpOQ/Bo8IKCFw=
github.com/cosmos/cosmos-proto v1.0.0-alpha8 h1:d3pCRuMYYvGA5bM0ZbbjKn+AoQD4A7dyNG2wzwWalUw=
github.com/cosmos/cosmos-proto v1.0.0-alpha8/go.mod h1:6/p+Bc4O8JKeZqe0VqUGTX31eoYqemTT4C1hLCWsO7I=
github.com/cosmos/gogoproto v1.4.2 h1:UeGRcmFW41l0G0MiefWhkPEVEwvu78SZsHBvI78dAYw=
Expand Down
34 changes: 34 additions & 0 deletions tx/signing/sign_mode_handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package signing

import "google.golang.org/protobuf/types/known/anypb"

// SignerData is the specific information needed to sign a transaction that generally
// isn't included in the transaction body itself
type SignerData struct {
// The address of the signer.
//
// In case of multisigs, this should be the multisig's address.
Address string

// ChainID is the chain that this transaction is targeted
ChainID string

// AccountNumber is the account number of the signer.
//
// In case of multisigs, this should be the multisig account number.
AccountNumber uint64

// Sequence is the account sequence number of the signer that is used
// for replay protection. This field is only useful for Legacy Amino signing,
// since in SIGN_MODE_DIRECT the account sequence is already in the signer
// info.
//
// In case of multisigs, this should be the multisig sequence.
Sequence uint64

// PubKey is the public key of the signer.
//
// In case of multisigs, this should be the pubkey of the member of the
// multisig that is signing the current sign doc.
PubKey *anypb.Any
}
162 changes: 162 additions & 0 deletions tx/textual/internal/testdata/tx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
[
{
"proto": {
"body": {
"messages": [
{
"@type": "/cosmos.bank.v1beta1.MsgSend",
"from_address": "cosmos1ulav3hsenupswqfkw2y3sup5kgtqwnvqa8eyhs",
"to_address": "cosmos1ejrf4cur2wy6kfurg9f2jppp2h3afe5h6pkh5t",
"amount": [
{
"denom": "uatom",
"amount": "5000"
}
]
}
]
},
"auth_info": {
"signer_infos": [
{
"public_key": {
"@type": "/cosmos.crypto.secp256k1.PubKey",
"key": "Auvdf+T963bciiBe9l15DNMOijdaXCUo6zqSOvH7TXlN"
},
"mode_info": { "single": { "mode": "SIGN_MODE_TEXTUAL" } },
"sequence": 2
}
],
"fee": {
"amount": [
{
"denom": "uatom",
"amount": "5000"
}
],
"gas_limit": 100000
}
},
"signer_data": {
"chainId": "my-chain",
"pubKey": {
"@type": "/cosmos.crypto.secp256k1.PubKey",
"key": "Auvdf+T963bciiBe9l15DNMOijdaXCUo6zqSOvH7TXlN"
},
"sequence": 2
}
},
"screens": [
{ "text": "Chain ID: my-chain" },
{ "text": "Account number: 0" },
{ "text": "Sequence: 2" },
{ "text": "Fees: 5'000 uatom" },
{ "text": "Gas limit: 100'000", "expert": true },
{
"text": "Hash of raw bytes: e237dc2e3f8f0b1d0310e1cd0b0ab5fc4a59e4bc3454d67eb65c3fdb0fa599c9",
"expert": true
}
]
},
{
"proto": {
"body": {
"messages": []
},
"auth_info": {
"signer_infos": [
{
"public_key": {
"@type": "/cosmos.crypto.secp256k1.PubKey",
"key": "Auvdf+T963bciiBe9l15DNMOijdaXCUo6zqSOvH7TXlN"
},
"mode_info": { "single": { "mode": "SIGN_MODE_TEXTUAL" } },
"sequence": 2
},
{
"public_key": {
"@type": "/cosmos.crypto.multisig.LegacyAminoPubKey",
"threshold": 2,
"public_keys": [
{
"@type": "/cosmos.crypto.secp256k1.PubKey",
"key": "AldOvgv8dU9ZZzuhGydQD5FYreLhfhoBgrDKi8ZSTbCQ"
},
{
"@type": "/cosmos.crypto.secp256k1.PubKey",
"key": "AxUMR/GKoycWplR+2otzaQZ9zhHRQWJFt3h1bPg1ltha"
},
{
"@type": "/cosmos.crypto.secp256k1.PubKey",
"key": "AlI9yVj2Aejow6bYl2nTRylfU+9LjQLEl3keq0sERx9+"
},
{
"@type": "/cosmos.crypto.secp256k1.PubKey",
"key": "A0UvHPcvCCaIoFY9Ygh0Pxq9SZTAWtduOyinit/8uo+Q"
},
{
"@type": "/cosmos.crypto.secp256k1.PubKey",
"key": "As7R9fDUnwsUVLDr1cxspp+cY9UfXfUf7i9/w+N0EzKA"
}
]
},
"mode_info": {
"multi": {
"bitarray": {
"extra_bits_stored": 5,
"elems": "SA=="
},
"mode_infos": [
{
"single": {
"mode": "SIGN_MODE_LEGACY_AMINO_JSON"
}
},
{
"single": {
"mode": "SIGN_MODE_LEGACY_AMINO_JSON"
}
}
]
}
},
"sequence": "102"
}
],
"fee": {
"amount": [
{
"denom": "uatom",
"amount": "5000"
}
],
"gas_limit": 100000,
"payer": "cosmos1ey69r37gfxvxg62sh4r0ktpuc46pzjrmz29g45",
"granter": "cosmos1ey69r37gfxvxg62sh4r0ktpuc46pzjrmz29g45"
}
},
"signer_data": {
"chainId": "my-chain",
"pubKey": {
"@type": "/cosmos.crypto.secp256k1.PubKey",
"key": "Auvdf+T963bciiBe9l15DNMOijdaXCUo6zqSOvH7TXlN"
}
}
},
"screens": [
{ "text": "Chain ID: my-chain" },
{ "text": "Account number: 0" },
{ "text": "Sequence: 0" },
{ "text": "Fees: 5'000 uatom" },
{
"text": "Fee payer: cosmos1ey69r37gfxvxg62sh4r0ktpuc46pzjrmz29g45",
"expert": true
},
{
"text": "Fee granter: cosmos1ey69r37gfxvxg62sh4r0ktpuc46pzjrmz29g45",
"expert": true
},
{ "text": "Gas limit: 100'000", "expert": true }
]
}
]
2 changes: 1 addition & 1 deletion tx/textual/valuerenderer/bytes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestBytesJsonTestCases(t *testing.T) {
err = json.Unmarshal(raw, &testcases)
require.NoError(t, err)

textual := valuerenderer.NewTextual(mockCoinMetadataQuerier)
textual := valuerenderer.NewTextual(nil)

for _, tc := range testcases {
data, err := base64.StdEncoding.DecodeString(tc.base64)
Expand Down
Loading