👏 `pigeon create identity` works!
This commit is contained in:
parent
5d946ac9a0
commit
fcee853237
|
@ -16,7 +16,6 @@ Don't use the Go version yet. If you want something stable, there is a [Ruby ver
|
|||
|
||||
|Done?|Verb |Noun | Flag / arg 1 | Flag 2 |
|
||||
|-----|------------|--------|---------------|-----------|
|
||||
| |create |identity| | |
|
||||
| |show |identity| | |
|
||||
| |create |draft | | |
|
||||
| |show |blob | | |
|
||||
|
@ -36,6 +35,7 @@ Don't use the Go version yet. If you want something stable, there is a [Ruby ver
|
|||
| |show |peers | | |
|
||||
| |show |peers | --blocked | |
|
||||
| |unfollow |peer | | |
|
||||
| X |create |identity| | |
|
||||
| X |help | | | |
|
||||
| X |version | | | |
|
||||
|
||||
|
|
25
cli.go
25
cli.go
|
@ -9,27 +9,40 @@ import (
|
|||
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "pigeon",
|
||||
Short: "Pigeon is a peer-to-peer database for offline systems",
|
||||
Short: "Pigeon is a peer-to-peer database for offline systems.",
|
||||
Long: `Pigeon is an off-grid, serverless, peer-to-peer
|
||||
database for building software that works on poor internet
|
||||
connections, or entirely offline.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Println("It works!")
|
||||
},
|
||||
}
|
||||
|
||||
var versionCmd = &cobra.Command{
|
||||
Use: "version",
|
||||
Short: "This is the short description of version",
|
||||
Long: `This one is longer.`,
|
||||
Short: "Print the software version.",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Printf("Pigeon CLI Client (Golang), version %s\n", Version)
|
||||
},
|
||||
}
|
||||
|
||||
var createCmd = &cobra.Command{
|
||||
Use: "create [resource]",
|
||||
Short: "Create various resources",
|
||||
Long: `Creates resources, such as identities, drafts, messages, blobs, etc..`,
|
||||
}
|
||||
|
||||
var createIdentityCmd = &cobra.Command{
|
||||
Use: "identity",
|
||||
Short: "Create a new identity.",
|
||||
Long: `Creates a new identity.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Println(createOrShowIdentity())
|
||||
},
|
||||
}
|
||||
|
||||
// BootstrapCLI wires up all the relevant commands.
|
||||
func BootstrapCLI() {
|
||||
createCmd.AddCommand(createIdentityCmd)
|
||||
rootCmd.AddCommand(versionCmd)
|
||||
rootCmd.AddCommand(createCmd)
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
|
|
29
util.go
29
util.go
|
@ -5,6 +5,18 @@ import (
|
|||
"log"
|
||||
)
|
||||
|
||||
func createOrShowIdentity() string {
|
||||
var pubKey []byte
|
||||
oldKey := GetConfig("private_key")
|
||||
if len(oldKey) == 0 {
|
||||
newKey, _ := CreateIdentity()
|
||||
pubKey = newKey
|
||||
} else {
|
||||
pubKey = oldKey
|
||||
}
|
||||
return encodeUserMhash(pubKey)
|
||||
}
|
||||
|
||||
// CreateIdentity is used by the CLI to create an ED25519
|
||||
// keypair and store it to disk. It returns the private key
|
||||
// as a Base32 encoded string
|
||||
|
@ -18,16 +30,7 @@ func CreateIdentity() (ed25519.PublicKey, ed25519.PrivateKey) {
|
|||
return pub, priv
|
||||
}
|
||||
|
||||
// EncodeUserMhash Takes a []byte and converts it to a B32
|
||||
// string in the format "USER.DATA.ED25519"
|
||||
// func EncodeUserMhash(pubKey []byte) string {
|
||||
// b32 := B32Encode(pubKey)
|
||||
// b32Length := len(b32)
|
||||
|
||||
// if b32Length != 52 {
|
||||
// m := "Expected %s to be 52 bytes long. Got %d"
|
||||
// log.Fatal(m, b32, b32Length)
|
||||
// }
|
||||
|
||||
// return fmt.Sprintf("%s%s", UserSigil, b32)
|
||||
// }
|
||||
func encodeUserMhash(pubKey []byte) string {
|
||||
sigil := "USER."
|
||||
return sigil + B32Encode(pubKey)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue