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(textual): Add client-side infra #14661

Merged
merged 117 commits into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from 103 commits
Commits
Show all changes
117 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
a4cc711
Merge branch 'main' of ssh://github.com/cosmos/cosmos-sdk into am/tex…
amaury1093 Jan 18, 2023
ad84318
Update ledger-cosmos-go
amaury1093 Jan 18, 2023
283690f
add experimental
amaury1093 Jan 18, 2023
9b8eac2
Add back test
amaury1093 Jan 18, 2023
44b9b5f
Add comments
amaury1093 Jan 18, 2023
1ba1a9b
Fix
amaury1093 Jan 18, 2023
c525dd0
SignLedgerAminoJSON
amaury1093 Jan 18, 2023
df2da96
Add client textual
amaury1093 Jan 18, 2023
db3fcb9
Merge branch 'main' of ssh://github.com/cosmos/cosmos-sdk into am/137…
amaury1093 Jan 18, 2023
1c7551b
Fix ledger_mock
amaury1093 Jan 18, 2023
edd02a3
Fix tests
amaury1093 Jan 18, 2023
764dff9
proto-gen
amaury1093 Jan 18, 2023
5e9e13a
Move to same pkg
amaury1093 Jan 23, 2023
b424a5c
Merge branch 'main' of ssh://github.com/cosmos/cosmos-sdk into am/137…
amaury1093 Jan 23, 2023
1117acc
gofumpt
amaury1093 Jan 23, 2023
01de8e7
Merge branch 'main' into am/13747-textual-client
JeancarloBarrios Jan 23, 2023
f68f4e1
Merge branch 'main' of ssh://github.com/cosmos/cosmos-sdk into am/137…
amaury1093 Jan 24, 2023
eb85bc9
go mod tidy
amaury1093 Jan 24, 2023
4dcf5ae
Merge branch 'main' into am/13747-textual-client
amaury1093 Jan 24, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### API Breaking Changes

* (crypto/keyring) [#13734](https://github.com/cosmos/cosmos-sdk/pull/13834) The keyring's `Sign` method now takes a new `signMode` argument. It is only used if the signing key is a Ledger hardware device. You can set it to 0 in all other cases.
* (tx) [#14634](https://github.com/cosmos/cosmos-sdk/pull/14634) Move the `tx` go module to `x/tx`.
* (snapshots) [#14597](https://github.com/cosmos/cosmos-sdk/pull/14597) Move `snapshots` to `store/snapshots`, rename and bump proto package to v1.
* (crypto/keyring) [#14151](https://github.com/cosmos/cosmos-sdk/pull/14151) Move keys presentation from `crypto/keyring` to `client/keys`
Expand Down
10 changes: 9 additions & 1 deletion client/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,18 @@ func readTxCommandFlags(clientCtx Context, flagSet *pflag.FlagSet) (Context, err

clientCtx = clientCtx.WithFrom(from).WithFromAddress(fromAddr).WithFromName(fromName)

// TODO Remove this once SIGN_MODE_TEXTUAL is released
// ref: https://github.com/cosmos/cosmos-sdk/issues/11970
if keyType == keyring.TypeLedger && clientCtx.SignModeStr == flags.SignModeTextual {
return clientCtx, fmt.Errorf("SIGN_MODE_TEXTUAL is currently not supported, please follow https://github.com/cosmos/cosmos-sdk/issues/11970")
}

// If the `from` signer account is a ledger key, we need to use
// SIGN_MODE_AMINO_JSON, because ledger doesn't support proto yet.
// ref: https://github.com/cosmos/cosmos-sdk/issues/8109
if keyType == keyring.TypeLedger && clientCtx.SignModeStr != flags.SignModeLegacyAminoJSON && !clientCtx.LedgerHasProtobuf {
if keyType == keyring.TypeLedger &&
clientCtx.SignModeStr != flags.SignModeLegacyAminoJSON &&
!clientCtx.LedgerHasProtobuf {
fmt.Println("Default sign-mode 'direct' not supported by Ledger, using sign-mode 'amino-json'.")
clientCtx = clientCtx.WithSignModeStr(flags.SignModeLegacyAminoJSON)
}
Expand Down
5 changes: 5 additions & 0 deletions client/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ const (
SignModeLegacyAminoJSON = "amino-json"
// SignModeDirectAux is the value of the --sign-mode flag for SIGN_MODE_DIRECT_AUX
SignModeDirectAux = "direct-aux"
// SignModeTextual is the value of the --sign-mode flag for SIGN_MODE_TEXTUAL.
// Choosing this flag will result in an error for now, unless you enable
// Textual manually in your sign modes. In any case, Textual should be used
// only for TESTING purposes for now.
SignModeTextual = "textual"
// SignModeEIP191 is the value of the --sign-mode flag for SIGN_MODE_EIP_191
SignModeEIP191 = "eip-191"
)
Expand Down
2 changes: 2 additions & 0 deletions client/tx/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ func NewFactoryCLI(clientCtx client.Context, flagSet *pflag.FlagSet) Factory {
signMode = signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON
case flags.SignModeDirectAux:
signMode = signing.SignMode_SIGN_MODE_DIRECT_AUX
case flags.SignModeTextual:
signMode = signing.SignMode_SIGN_MODE_TEXTUAL
case flags.SignModeEIP191:
signMode = signing.SignMode_SIGN_MODE_EIP_191
}
Expand Down
35 changes: 35 additions & 0 deletions client/tx/textual.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package tx

import (
"context"

bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1"
"cosmossdk.io/x/tx/textual"
"github.com/cosmos/cosmos-sdk/client"
"google.golang.org/grpc/codes"
grpcstatus "google.golang.org/grpc/status"
)

// NewTextualWithClientCtx returns a new Textual instance where the metadata
// queries are done via gRPC using the provided client.Context.
func NewTextualWithClientCtx(clientCtx client.Context) textual.Textual {
return textual.NewTextual(func(ctx context.Context, denom string) (*bankv1beta1.Metadata, error) {
bankQueryClient := bankv1beta1.NewQueryClient(clientCtx)
res, err := bankQueryClient.DenomMetadata(ctx, &bankv1beta1.QueryDenomMetadataRequest{
Denom: denom,
})

status, ok := grpcstatus.FromError(err)
if !ok {
return nil, err
}

// This means we didn't find any metadata for this denom. Returning
// empty metadata.
if status.Code() == codes.NotFound {
return nil, nil
}

return res.Metadata, nil
})
}
4 changes: 2 additions & 2 deletions client/tx/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ func Sign(ctx context.Context, txf Factory, name string, txBuilder client.TxBuil
}

// Sign those bytes
sigBytes, _, err := txf.keybase.Sign(name, bytesToSign)
sigBytes, _, err := txf.keybase.Sign(name, bytesToSign, signMode)
if err != nil {
return err
}
Expand Down Expand Up @@ -409,7 +409,7 @@ func makeAuxSignerData(clientCtx client.Context, f Factory, msgs ...sdk.Msg) (tx
return tx.AuxSignerData{}, err
}

sig, _, err := clientCtx.Keyring.Sign(name, signBz)
sig, _, err := clientCtx.Keyring.Sign(name, signBz, f.signMode)
if err != nil {
return tx.AuxSignerData{}, err
}
Expand Down
2 changes: 1 addition & 1 deletion client/v2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ require (
github.com/cosmos/gogoproto v1.4.3 // indirect
github.com/cosmos/gorocksdb v1.2.0 // indirect
github.com/cosmos/iavl v0.19.4 // indirect
github.com/cosmos/ledger-cosmos-go v0.12.2 // indirect
github.com/cosmos/ledger-cosmos-go v0.13.0 // indirect
github.com/danieljoos/wincred v1.1.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions client/v2/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ github.com/cosmos/gorocksdb v1.2.0 h1:d0l3jJG8M4hBouIZq0mDUHZ+zjOx044J3nGRskwTb4
github.com/cosmos/gorocksdb v1.2.0/go.mod h1:aaKvKItm514hKfNJpUJXnnOWeBnk2GL4+Qw9NHizILw=
github.com/cosmos/iavl v0.19.4 h1:t82sN+Y0WeqxDLJRSpNd8YFX5URIrT+p8n6oJbJ2Dok=
github.com/cosmos/iavl v0.19.4/go.mod h1:X9PKD3J0iFxdmgNLa7b2LYWdsGd90ToV5cAONApkEPw=
github.com/cosmos/ledger-cosmos-go v0.12.2 h1:/XYaBlE2BJxtvpkHiBm97gFGSGmYGKunKyF3nNqAXZA=
github.com/cosmos/ledger-cosmos-go v0.12.2/go.mod h1:ZcqYgnfNJ6lAXe4HPtWgarNEY+B74i+2/8MhZw4ziiI=
github.com/cosmos/ledger-cosmos-go v0.13.0 h1:ex0CvCxToSR7j5WjrghPu2Bu9sSXKikjnVvUryNnx4s=
github.com/cosmos/ledger-cosmos-go v0.13.0/go.mod h1:ZcqYgnfNJ6lAXe4HPtWgarNEY+B74i+2/8MhZw4ziiI=
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creachadair/taskgroup v0.3.2 h1:zlfutDS+5XG40AOxcHDSThxKzns8Tnr9jnr6VqkYlkM=
Expand Down
31 changes: 21 additions & 10 deletions crypto/keyring/keyring.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
"github.com/cosmos/go-bip39"
)

Expand Down Expand Up @@ -103,10 +104,10 @@ type Keyring interface {
// Signer is implemented by key stores that want to provide signing capabilities.
type Signer interface {
// Sign sign byte messages with a user key.
Sign(uid string, msg []byte) ([]byte, types.PubKey, error)
Sign(uid string, msg []byte, signMode signing.SignMode) ([]byte, types.PubKey, error)

// SignByAddress sign byte messages with a user key providing the address.
SignByAddress(address sdk.Address, msg []byte) ([]byte, types.PubKey, error)
SignByAddress(address sdk.Address, msg []byte, signMode signing.SignMode) ([]byte, types.PubKey, error)
}

// Importer is implemented by key stores that support import of public and private keys.
Expand Down Expand Up @@ -356,7 +357,7 @@ func (ks keystore) ImportPubKey(uid string, armor string) error {
return nil
}

func (ks keystore) Sign(uid string, msg []byte) ([]byte, types.PubKey, error) {
func (ks keystore) Sign(uid string, msg []byte, signMode signing.SignMode) ([]byte, types.PubKey, error) {
k, err := ks.Key(uid)
if err != nil {
return nil, nil, err
Expand All @@ -377,7 +378,7 @@ func (ks keystore) Sign(uid string, msg []byte) ([]byte, types.PubKey, error) {
return sig, priv.PubKey(), nil

case k.GetLedger() != nil:
return SignWithLedger(k, msg)
return SignWithLedger(k, msg, signMode)

// multi or offline record
default:
Expand All @@ -390,13 +391,13 @@ func (ks keystore) Sign(uid string, msg []byte) ([]byte, types.PubKey, error) {
}
}

func (ks keystore) SignByAddress(address sdk.Address, msg []byte) ([]byte, types.PubKey, error) {
func (ks keystore) SignByAddress(address sdk.Address, msg []byte, signMode signing.SignMode) ([]byte, types.PubKey, error) {
k, err := ks.KeyByAddress(address)
if err != nil {
return nil, nil, err
}

return ks.Sign(k.Name, msg)
return ks.Sign(k.Name, msg, signMode)
}

func (ks keystore) SaveLedgerKey(uid string, algo SignatureAlgo, hrp string, coinType, account, index uint32) (*Record, error) {
Expand Down Expand Up @@ -598,7 +599,7 @@ func (ks keystore) SupportedAlgorithms() (SigningAlgoList, SigningAlgoList) {
// SignWithLedger signs a binary message with the ledger device referenced by an Info object
// and returns the signed bytes and the public key. It returns an error if the device could
// not be queried or it returned an error.
func SignWithLedger(k *Record, msg []byte) (sig []byte, pub types.PubKey, err error) {
func SignWithLedger(k *Record, msg []byte, signMode signing.SignMode) (sig []byte, pub types.PubKey, err error) {
ledgerInfo := k.GetLedger()
if ledgerInfo == nil {
return nil, nil, errors.New("not a ledger object")
Expand All @@ -611,9 +612,19 @@ func SignWithLedger(k *Record, msg []byte) (sig []byte, pub types.PubKey, err er
return
}

sig, err = priv.Sign(msg)
if err != nil {
return nil, nil, err
switch signMode {
case signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON:
sig, err = priv.Sign(msg)
if err != nil {
return nil, nil, err
}
case signing.SignMode_SIGN_MODE_TEXTUAL:
sig, err = priv.SignLedgerTextual(msg)
if err != nil {
return nil, nil, err
}
default:
return nil, nil, fmt.Errorf("got invalid sign mode %d, expected LEGACY_AMINO_JSON or TEXTUAL", signMode)
}

if !priv.PubKey().VerifySignature(msg, sig) {
Expand Down
28 changes: 22 additions & 6 deletions crypto/ledger/ledger_secp256k1.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ type (
// Returns a compressed pubkey and bech32 address (requires user confirmation)
GetAddressPubKeySECP256K1([]uint32, string) ([]byte, string, error)
// Signs a message (requires user confirmation)
SignSECP256K1([]uint32, []byte) ([]byte, error)
// The last byte denotes the SIGN_MODE to be used by Ledger: 0 for
// LEGACY_AMINO_JSON, 1 for TEXTUAL. It corresponds to the P2 value
// in https://github.com/cosmos/ledger-cosmos/blob/main/docs/APDUSPEC.md
SignSECP256K1([]uint32, []byte, byte) ([]byte, error)
}

// Options hosts customization options to account for differences in Ledger
Expand Down Expand Up @@ -94,7 +97,7 @@ func SetSkipDERConversion() {
// This function is marked as unsafe as it will retrieve a pubkey without user verification.
// It can only be used to verify a pubkey but never to create new accounts/keys. In that case,
// please refer to NewPrivKeySecp256k1
func NewPrivKeySecp256k1Unsafe(path hd.BIP44Params) (types.LedgerPrivKey, error) {
func NewPrivKeySecp256k1Unsafe(path hd.BIP44Params) (types.LedgerPrivKeyTextual, error) {
device, err := getDevice()
if err != nil {
return nil, err
Expand Down Expand Up @@ -131,15 +134,28 @@ func (pkl PrivKeyLedgerSecp256k1) PubKey() types.PubKey {
return pkl.CachedPubKey
}

// Sign returns a secp256k1 signature for the corresponding message
// Sign returns a secp256k1 signature for the corresponding message using
// SIGN_MODE_LEGACY_AMINO_JSON.
func (pkl PrivKeyLedgerSecp256k1) Sign(message []byte) ([]byte, error) {
device, err := getDevice()
if err != nil {
return nil, err
}
defer warnIfErrors(device.Close)

return sign(device, pkl, message)
return sign(device, pkl, message, 0)
}

// SignLedgerTextual returns a secp256k1 signature for the corresponding message using
// SIGN_MODE_TEXTUAL.
func (pkl PrivKeyLedgerSecp256k1) SignLedgerTextual(message []byte) ([]byte, error) {
device, err := getDevice()
if err != nil {
return nil, err
}
defer warnIfErrors(device.Close)

return sign(device, pkl, message, 1)
}

// ShowAddress triggers a ledger device to show the corresponding address.
Expand Down Expand Up @@ -260,13 +276,13 @@ func validateKey(device SECP256K1, pkl PrivKeyLedgerSecp256k1) error {
// Communication is checked on NewPrivKeyLedger and PrivKeyFromBytes, returning
// an error, so this should only trigger if the private key is held in memory
// for a while before use.
func sign(device SECP256K1, pkl PrivKeyLedgerSecp256k1, msg []byte) ([]byte, error) {
func sign(device SECP256K1, pkl PrivKeyLedgerSecp256k1, msg []byte, p2 byte) ([]byte, error) {
err := validateKey(device, pkl)
if err != nil {
return nil, err
}

sig, err := device.SignSECP256K1(pkl.Path.DerivationPath(), msg)
sig, err := device.SignSECP256K1(pkl.Path.DerivationPath(), msg, p2)
if err != nil {
return nil, err
}
Expand Down
9 changes: 9 additions & 0 deletions crypto/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ type LedgerPrivKey interface {
Type() string
}

// LedgerPrivKeyTextual is a Ledger PrivKey type that supports signing with
// SIGN_MODE_TEXTUAL. It is added as a non-breaking change, instead of directly
// on the LedgerPrivKey interface.
type LedgerPrivKeyTextual interface {
LedgerPrivKey
// SignLedgerTextual signs a messages on the Ledger device using Textual.
SignLedgerTextual(msg []byte) ([]byte, error)
}

// PrivKey defines a private key and extends proto.Message. For now, it extends
// LedgerPrivKey (see godoc for LedgerPrivKey). Ultimately, we should remove
// LedgerPrivKey and add its methods here directly.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ require (
github.com/cosmos/gogogateway v1.2.0
github.com/cosmos/gogoproto v1.4.3
github.com/cosmos/iavl v0.20.0-alpha1
github.com/cosmos/ledger-cosmos-go v0.12.2
github.com/cosmos/ledger-cosmos-go v0.13.0
github.com/golang/mock v1.6.0
github.com/golang/protobuf v1.5.2
github.com/google/gofuzz v1.2.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ github.com/cosmos/iavl v0.20.0-alpha1 h1:tP+Qv4MdnLVmrrhIAGpLRQOOhFGgci0hpJ4VI3x
github.com/cosmos/iavl v0.20.0-alpha1/go.mod h1:25YJYzilTErJ2mKfNB3xyWL9IsCwEQdNzdIutg2mh3U=
github.com/cosmos/keyring v1.2.0 h1:8C1lBP9xhImmIabyXW4c3vFjjLiBdGCmfLUfeZlV1Yo=
github.com/cosmos/keyring v1.2.0/go.mod h1:fc+wB5KTk9wQ9sDx0kFXB3A0MaeGHM9AwRStKOQ5vOA=
github.com/cosmos/ledger-cosmos-go v0.12.2 h1:/XYaBlE2BJxtvpkHiBm97gFGSGmYGKunKyF3nNqAXZA=
github.com/cosmos/ledger-cosmos-go v0.12.2/go.mod h1:ZcqYgnfNJ6lAXe4HPtWgarNEY+B74i+2/8MhZw4ziiI=
github.com/cosmos/ledger-cosmos-go v0.13.0 h1:ex0CvCxToSR7j5WjrghPu2Bu9sSXKikjnVvUryNnx4s=
github.com/cosmos/ledger-cosmos-go v0.13.0/go.mod h1:ZcqYgnfNJ6lAXe4HPtWgarNEY+B74i+2/8MhZw4ziiI=
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
Expand Down
1 change: 1 addition & 0 deletions scripts/mockgen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ $mockgen_cmd -source=x/feegrant/expected_keepers.go -package testutil -destinati
$mockgen_cmd -source=x/mint/types/expected_keepers.go -package testutil -destination x/mint/testutil/expected_keepers_mocks.go
$mockgen_cmd -source=x/params/proposal_handler_test.go -package testutil -destination x/params/testutil/staking_keeper_mock.go
$mockgen_cmd -source=x/crisis/types/expected_keepers.go -package testutil -destination x/crisis/testutil/expected_keepers_mocks.go
$mockgen_cmd -source=x/auth/tx/config/expected_keepers.go -package testutil -destination x/auth/tx/testutil/expected_keepers_mocks.go
$mockgen_cmd -source=x/auth/types/expected_keepers.go -package testutil -destination x/auth/testutil/expected_keepers_mocks.go
$mockgen_cmd -source=x/auth/ante/expected_keepers.go -package testutil -destination x/auth/ante/testutil/expected_keepers_mocks.go
$mockgen_cmd -source=x/authz/expected_keepers.go -package testutil -destination x/authz/testutil/expected_keepers_mocks.go
Expand Down
4 changes: 2 additions & 2 deletions simapp/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ require (
github.com/golang/mock v1.6.0
github.com/spf13/cast v1.5.0
github.com/spf13/cobra v1.6.1
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.14.0
github.com/stretchr/testify v1.8.1
github.com/tendermint/tendermint v0.37.0-rc2
Expand Down Expand Up @@ -62,7 +63,7 @@ require (
github.com/cosmos/gogoproto v1.4.3 // indirect
github.com/cosmos/gorocksdb v1.2.0 // indirect
github.com/cosmos/iavl v0.20.0-alpha1 // indirect
github.com/cosmos/ledger-cosmos-go v0.12.2 // indirect
github.com/cosmos/ledger-cosmos-go v0.13.0 // indirect
github.com/cosmos/rosetta-sdk-go v0.9.0 // indirect
github.com/creachadair/atomicfile v0.2.7 // indirect
github.com/creachadair/taskgroup v0.3.2 // indirect
Expand Down Expand Up @@ -151,7 +152,6 @@ require (
github.com/sasha-s/go-deadlock v0.3.1 // indirect
github.com/spf13/afero v1.9.2 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.1 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
github.com/tendermint/btcd v0.1.1 // indirect
Expand Down
4 changes: 2 additions & 2 deletions simapp/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ github.com/cosmos/iavl v0.20.0-alpha1 h1:tP+Qv4MdnLVmrrhIAGpLRQOOhFGgci0hpJ4VI3x
github.com/cosmos/iavl v0.20.0-alpha1/go.mod h1:25YJYzilTErJ2mKfNB3xyWL9IsCwEQdNzdIutg2mh3U=
github.com/cosmos/keyring v1.2.0 h1:8C1lBP9xhImmIabyXW4c3vFjjLiBdGCmfLUfeZlV1Yo=
github.com/cosmos/keyring v1.2.0/go.mod h1:fc+wB5KTk9wQ9sDx0kFXB3A0MaeGHM9AwRStKOQ5vOA=
github.com/cosmos/ledger-cosmos-go v0.12.2 h1:/XYaBlE2BJxtvpkHiBm97gFGSGmYGKunKyF3nNqAXZA=
github.com/cosmos/ledger-cosmos-go v0.12.2/go.mod h1:ZcqYgnfNJ6lAXe4HPtWgarNEY+B74i+2/8MhZw4ziiI=
github.com/cosmos/ledger-cosmos-go v0.13.0 h1:ex0CvCxToSR7j5WjrghPu2Bu9sSXKikjnVvUryNnx4s=
github.com/cosmos/ledger-cosmos-go v0.13.0/go.mod h1:ZcqYgnfNJ6lAXe4HPtWgarNEY+B74i+2/8MhZw4ziiI=
github.com/cosmos/rosetta-sdk-go v0.9.0 h1:3mj2naR+GUhUXabtb96WWSsPFZDCYkdtp6r0jffgugg=
github.com/cosmos/rosetta-sdk-go v0.9.0/go.mod h1:2v41yXL25xxAXrczVSnbDHcQH9CgildruDlGQGKW/JU=
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
Expand Down
Loading