forked from gnolang/gno
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add contribs/gnokeykc (gnolang#1270)
## Done - add a `contribs/gnokeykc` wrapper (adding keychain support). - make `tm2/commands.IO` an interface instead of a struct. ## Usage ```console $ gnokeykc kc set Enter password. Successfully added password for key. $ gnokeykc maketx send --send 1ugnot --to g1fsu3z335h5qngf7t3lmakvpmpwg9ae76tqwh7c --chainid test3 --remote test3.gno.land:36657 --gas-fee "1000000ugnot" --gas-wanted "2000000" --broadcast moul OK! GAS WANTED: 2000000 GAS USED: 47072 ``` ## Links - [x] Depends on gnolang#1256 (for contribs/' Makefile & CI) --------- Signed-off-by: moul <[email protected]>
- Loading branch information
Showing
48 changed files
with
582 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# `gnokeykc` | ||
|
||
`gnokeykc` is a Go-based CLI tool that enhances [`gnokey`](../../gno.land/cmd/gnokey) by integrating with your system's keychain. It adds `gnokey kc ...` subcommands to set and unset passwords in the keychain, allowing Gnokey to fetch passwords directly from the keychain instead of prompting for terminal input. | ||
|
||
## Usage | ||
|
||
gnokey kc -h | ||
|
||
## Terminal Alias | ||
|
||
For ease of use, set up a terminal alias to replace `gnokey` with `gnokeykc`: | ||
|
||
echo "alias gnokey='gnokeykc'" >> ~/.bashrc && source ~/.bashrc | ||
|
||
Now, `gnokey` commands will use `gnokeykc`, fetching passwords from the keychain. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
module github.com/gnolang/gno/contribs/gnokeykc | ||
|
||
go 1.20 | ||
|
||
replace github.com/gnolang/gno => ../.. | ||
|
||
require ( | ||
github.com/gnolang/gno v0.0.0-00010101000000-000000000000 | ||
github.com/zalando/go-keyring v0.2.3 | ||
) | ||
|
||
require ( | ||
github.com/alessio/shellescape v1.4.1 // indirect | ||
github.com/btcsuite/btcd v0.22.0-beta.0.20220111032746-97732e52810c // indirect | ||
github.com/btcsuite/btcd/btcutil v1.0.0 // indirect | ||
github.com/cespare/xxhash v1.1.0 // indirect | ||
github.com/cespare/xxhash/v2 v2.1.1 // indirect | ||
github.com/cockroachdb/apd v1.1.0 // indirect | ||
github.com/danieljoos/wincred v1.2.0 // indirect | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/dgraph-io/badger/v3 v3.2103.4 // indirect | ||
github.com/dgraph-io/ristretto v0.1.1 // indirect | ||
github.com/dustin/go-humanize v1.0.0 // indirect | ||
github.com/gnolang/goleveldb v0.0.9 // indirect | ||
github.com/gnolang/overflow v0.0.0-20170615021017-4d914c927216 // indirect | ||
github.com/godbus/dbus/v5 v5.1.0 // indirect | ||
github.com/gogo/protobuf v1.3.2 // indirect | ||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b // indirect | ||
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6 // indirect | ||
github.com/golang/protobuf v1.5.3 // indirect | ||
github.com/golang/snappy v0.0.4 // indirect | ||
github.com/google/flatbuffers v1.12.1 // indirect | ||
github.com/gorilla/websocket v1.5.1 // indirect | ||
github.com/jmhodges/levigo v1.0.0 // indirect | ||
github.com/klauspost/compress v1.12.3 // indirect | ||
github.com/libp2p/go-buffer-pool v0.1.0 // indirect | ||
github.com/linxGnu/grocksdb v1.8.4 // indirect | ||
github.com/pelletier/go-toml v1.9.5 // indirect | ||
github.com/peterbourgon/ff/v3 v3.4.0 // indirect | ||
github.com/pkg/errors v0.9.1 // indirect | ||
github.com/rs/cors v1.10.1 // indirect | ||
github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c // indirect | ||
go.etcd.io/bbolt v1.3.7 // indirect | ||
go.opencensus.io v0.22.5 // indirect | ||
go.uber.org/atomic v1.7.0 // indirect | ||
go.uber.org/multierr v1.9.0 // indirect | ||
golang.org/x/crypto v0.14.0 // indirect | ||
golang.org/x/mod v0.14.0 // indirect | ||
golang.org/x/net v0.17.0 // indirect | ||
golang.org/x/sys v0.13.0 // indirect | ||
golang.org/x/term v0.13.0 // indirect | ||
golang.org/x/tools v0.13.0 // indirect | ||
google.golang.org/protobuf v1.31.0 // indirect | ||
) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"fmt" | ||
|
||
"github.com/gnolang/gno/tm2/pkg/commands" | ||
"github.com/zalando/go-keyring" | ||
) | ||
|
||
const ( | ||
kcService = "gnokey" | ||
kcName = "encryption" | ||
) | ||
|
||
func newKcCmd(io commands.IO) *commands.Command { | ||
cmd := commands.NewCommand( | ||
commands.Metadata{ | ||
Name: "kc", | ||
ShortUsage: "kc <command>", | ||
ShortHelp: "Manage OS keychain", | ||
}, | ||
commands.NewEmptyConfig(), | ||
commands.HelpExec, | ||
) | ||
cmd.AddSubCommands( | ||
newKcSetCmd(io), | ||
newKcUnsetCmd(io), | ||
) | ||
return cmd | ||
} | ||
|
||
func newKcSetCmd(io commands.IO) *commands.Command { | ||
return commands.NewCommand( | ||
commands.Metadata{ | ||
Name: "set", | ||
ShortUsage: "set", | ||
ShortHelp: "set encryption password in OS keychain", | ||
}, | ||
commands.NewEmptyConfig(), | ||
func(_ context.Context, args []string) error { | ||
return execKcSet(args, io) | ||
}, | ||
) | ||
} | ||
|
||
func execKcSet(args []string, io commands.IO) error { | ||
if len(args) != 0 { | ||
return flag.ErrHelp | ||
} | ||
|
||
insecurePasswordStdin := false // XXX: cfg.rootCfg.InsecurePasswordStdin | ||
password, err := io.GetPassword("Enter password.", insecurePasswordStdin) | ||
if err != nil { | ||
return fmt.Errorf("cannot read password: %w", err) | ||
} | ||
|
||
err = keyring.Set(kcService, kcName, password) | ||
if err != nil { | ||
return fmt.Errorf("cannot set password is OS keychain") | ||
} | ||
|
||
io.Printfln("Successfully added password for key.") | ||
return nil | ||
} | ||
|
||
func newKcUnsetCmd(io commands.IO) *commands.Command { | ||
return commands.NewCommand( | ||
commands.Metadata{ | ||
Name: "unset", | ||
ShortUsage: "unset", | ||
ShortHelp: "unset password in OS keychain", | ||
}, | ||
commands.NewEmptyConfig(), | ||
func(_ context.Context, args []string) error { | ||
return execKcUnset(args, io) | ||
}, | ||
) | ||
} | ||
|
||
func execKcUnset(args []string, io commands.IO) error { | ||
if len(args) != 0 { | ||
return flag.ErrHelp | ||
} | ||
|
||
err := keyring.Delete(kcService, kcName) | ||
if err != nil { | ||
return fmt.Errorf("cannot unset password from OS keychain") | ||
} | ||
|
||
io.Printfln("Successfully unset password") | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/gnolang/gno/tm2/pkg/commands" | ||
"github.com/gnolang/gno/tm2/pkg/crypto/keys/client" | ||
"github.com/zalando/go-keyring" | ||
) | ||
|
||
func main() { | ||
stdio := commands.NewDefaultIO() | ||
wrappedio := &wrappedIO{IO: stdio} | ||
cmd := client.NewRootCmd(wrappedio) | ||
cmd.AddSubCommands(newKcCmd(stdio)) | ||
|
||
if err := cmd.ParseAndRun(context.Background(), os.Args[1:]); err != nil { | ||
_, _ = fmt.Fprintf(os.Stderr, "%+v\n", err) | ||
|
||
os.Exit(1) | ||
} | ||
} | ||
|
||
type wrappedIO struct { | ||
commands.IO | ||
} | ||
|
||
func (io *wrappedIO) GetPassword(prompt string, insecure bool) (string, error) { | ||
return keyring.Get(kcService, kcName) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.