👏 `pigeon create identity` works!

This commit is contained in:
Netscape Navigator 2020-09-09 07:42:56 -05:00
parent 5d946ac9a0
commit fcee853237
3 changed files with 36 additions and 20 deletions

View File

@ -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 | |Done?|Verb |Noun | Flag / arg 1 | Flag 2 |
|-----|------------|--------|---------------|-----------| |-----|------------|--------|---------------|-----------|
| |create |identity| | |
| |show |identity| | | | |show |identity| | |
| |create |draft | | | | |create |draft | | |
| |show |blob | | | | |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 | | |
| |show |peers | --blocked | | | |show |peers | --blocked | |
| |unfollow |peer | | | | |unfollow |peer | | |
| X |create |identity| | |
| X |help | | | | | X |help | | | |
| X |version | | | | | X |version | | | |

25
cli.go
View File

@ -9,27 +9,40 @@ import (
var rootCmd = &cobra.Command{ var rootCmd = &cobra.Command{
Use: "pigeon", 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 Long: `Pigeon is an off-grid, serverless, peer-to-peer
database for building software that works on poor internet database for building software that works on poor internet
connections, or entirely offline.`, connections, or entirely offline.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("It works!")
},
} }
var versionCmd = &cobra.Command{ var versionCmd = &cobra.Command{
Use: "version", Use: "version",
Short: "This is the short description of version", Short: "Print the software version.",
Long: `This one is longer.`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("Pigeon CLI Client (Golang), version %s\n", Version) 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. // BootstrapCLI wires up all the relevant commands.
func BootstrapCLI() { func BootstrapCLI() {
createCmd.AddCommand(createIdentityCmd)
rootCmd.AddCommand(versionCmd) rootCmd.AddCommand(versionCmd)
rootCmd.AddCommand(createCmd)
if err := rootCmd.Execute(); err != nil { if err := rootCmd.Execute(); err != nil {
fmt.Println(err) fmt.Println(err)
os.Exit(1) os.Exit(1)

29
util.go
View File

@ -5,6 +5,18 @@ import (
"log" "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 // CreateIdentity is used by the CLI to create an ED25519
// keypair and store it to disk. It returns the private key // keypair and store it to disk. It returns the private key
// as a Base32 encoded string // as a Base32 encoded string
@ -18,16 +30,7 @@ func CreateIdentity() (ed25519.PublicKey, ed25519.PrivateKey) {
return pub, priv return pub, priv
} }
// EncodeUserMhash Takes a []byte and converts it to a B32 func encodeUserMhash(pubKey []byte) string {
// string in the format "USER.DATA.ED25519" sigil := "USER."
// func EncodeUserMhash(pubKey []byte) string { return sigil + B32Encode(pubKey)
// 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)
// }