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

[DEV-1319] Add helper to convert ed25519 pubkeys to jwk #321

Merged
merged 3 commits into from
May 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions architecture/adr-list/adr-006-community-tax.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ The aim of this ADR is to define how ["community tax" as described in the Cosmos

`communityTax` is a value set in genesis for each Cosmos network and defined as a percentage that is applied to the fees collected in each block.

Tokens collected through this process accumulate in the **community pool**. The percentage charged as `communityTax` can be changed by [making proposals on the network and voting for acceptance](https://docs.cosmos.network/v0.42/modules/gov/) by the network.
Tokens collected through this process accumulate in the **community pool**. The percentage charged as `communityTax` can be changed by [making proposals on the network and voting for acceptance](https://docs.cosmos.network/v0.44/modules/gov/) by the network.

### Community tax collection

Expand Down Expand Up @@ -74,5 +74,5 @@ More information about fee distribution is available in the [**End Block** secti
## References

* [Cosmos SDK `distribution` module parameters](https://docs.cosmos.network/v0.44/modules/distribution/07_params.html#parameters)
* [Cosmos SDK `governance` module](https://docs.cosmos.network/v0.42/modules/gov/)
* [Cosmos SDK `governance` module](https://docs.cosmos.network/v0.44/modules/gov/)

45 changes: 40 additions & 5 deletions cmd/cheqd-noded/cmd/debug_extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"encoding/base64"
"encoding/json"
"fmt"

"github.com/lestrrat-go/jwx/jwk"
"github.com/multiformats/go-multibase"
"github.com/spf13/cobra"
)
Expand All @@ -24,7 +26,7 @@ func ed25519Cmd() *cobra.Command {
Short: "ed25519 tools",
}

cmd.AddCommand(ed25519RandomCmd())
cmd.AddCommand(ed25519RandomCmd(), ed25519PubKeyBase64ToJwkCmd())

return cmd
}
Expand All @@ -41,10 +43,10 @@ func ed25519RandomCmd() *cobra.Command {
}

keyInfo := struct {
PubKeyBase64 string `json:"pub_key_base_64"`
PrivKeyBase64 string `json:"priv_key_base_64"`
PubKeyBase64 string `json:"pub_key_base_64"`
PrivKeyBase64 string `json:"priv_key_base_64"`
}{
PubKeyBase64: base64.StdEncoding.EncodeToString(pubKey),
PubKeyBase64: base64.StdEncoding.EncodeToString(pubKey),
PrivKeyBase64: base64.StdEncoding.EncodeToString(privKey),
}

Expand All @@ -61,6 +63,39 @@ func ed25519RandomCmd() *cobra.Command {
return cmd
}

// ed25519PubKeyBase64ToJwk returns cobra Command.
func ed25519PubKeyBase64ToJwkCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "pubkey-base64-to-jwk",
Short: "Convert ed25519 pubkey base64 to jwk",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
pubKeyBase64 := args[0]
pubKeyBytes, err := base64.StdEncoding.DecodeString(pubKeyBase64)
if err != nil {
return err
}

pubKey := ed25519.PublicKey(pubKeyBytes)

pubKeyJwk, err := jwk.New(pubKey)
if err != nil {
return err
}

pubKeyJwkJson, err := json.Marshal(pubKeyJwk)
if err != nil {
return err
}

_, err = fmt.Fprintln(cmd.OutOrStdout(), string(pubKeyJwkJson))
return err
},
}

return cmd
}

// encoding returns cobra Command.
func encodingCmd() *cobra.Command {
cmd := &cobra.Command{
Expand All @@ -78,7 +113,7 @@ func base64toMultibase58Cmd() *cobra.Command {
cmd := &cobra.Command{
Use: "base64-multibase58 [input]",
Short: "Convert base64 string to multibase58 string",
Args: cobra.ExactArgs(1),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
base64Str := args[0]
bytes, err := base64.StdEncoding.DecodeString(base64Str)
Expand Down