From b4c43671f8c012a0cbaeaf4233f67e58c1920624 Mon Sep 17 00:00:00 2001 From: Finn Date: Sun, 31 Jan 2021 05:19:51 -0800 Subject: [PATCH] Add some documentation --- README.md | 4 ++ cmd/signaldctl/README.md | 28 ++++++++++++ cmd/signaldctl/cmd/link.go | 79 ---------------------------------- cmd/signaldctl/cmd/register.go | 61 -------------------------- cmd/signaldctl/cmd/verify.go | 69 ----------------------------- 5 files changed, 32 insertions(+), 209 deletions(-) create mode 100644 README.md create mode 100644 cmd/signaldctl/README.md delete mode 100644 cmd/signaldctl/cmd/link.go delete mode 100644 cmd/signaldctl/cmd/register.go delete mode 100644 cmd/signaldctl/cmd/verify.go diff --git a/README.md b/README.md new file mode 100644 index 0000000..6fe8c06 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# signald-go +*a golang library for communicating with [signald](https://gitlab.org/signald/signald)* + +for signaldctl, see [signaldctl README](cmd/signaldctl/README.md) \ No newline at end of file diff --git a/cmd/signaldctl/README.md b/cmd/signaldctl/README.md new file mode 100644 index 0000000..118c0fc --- /dev/null +++ b/cmd/signaldctl/README.md @@ -0,0 +1,28 @@ +# signaldctl +*a command line tool for [signald](https://gitlab.com/signald/signald)* + +signaldctl is new and not well supported at this time. If you experience bugs, please report them. + + + +## Account Creation: Linking + +To link signald to an existing Signal account (by scanning a QR code): + +``` +signaldctl account create --link +``` + +## Account Creation: Registration + +To register a new account: + +``` +signaldctl account create --request-code --phone-number +15555555555 +``` + +you will receive an SMS verification code. Submit the code to create the account: + +``` +signaldctl account create --verify --phone-number +15555555555 --code 999-999 +``` \ No newline at end of file diff --git a/cmd/signaldctl/cmd/link.go b/cmd/signaldctl/cmd/link.go deleted file mode 100644 index 55b1010..0000000 --- a/cmd/signaldctl/cmd/link.go +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright © 2018 Finn Herzfeld -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -package cmd - -import ( - "fmt" - "log" - "math/rand" - "os" - - "github.com/mdp/qrterminal" - "github.com/spf13/cobra" - - "gitlab.com/signald/signald-go/cmd/signaldctl/common" - "gitlab.com/signald/signald-go/signald/client-protocol/v0" -) - -var uriOrQR bool - -// linkCmd represents the link command -var linkCmd = &cobra.Command{ - Use: "link", - Short: "Link to an existing Signal account", - Long: `Get a URI or QR code to link to an existing Signal account`, - Run: func(cmd *cobra.Command, args []string) { - requestID := fmt.Sprint("signaldctl-", rand.Intn(1000)) - err := common.Signald.RawRequest(v0.LegacyRequest{ - Type: "link", - ID: requestID, - }) - if err != nil { - log.Fatal("error sending request: ", err) - } - - c := make(chan v0.LegacyResponse) - go common.Signald.Listen(c) - for { - message := <-c - if message.ID == requestID { - switch message.Type { - case "linking_error": - log.Fatal(message.Data.Message) - os.Exit(1) - - case "linking_uri": - if uriOrQR { - fmt.Println(message.Data.URI) - } else { - qrterminal.Generate(message.Data.URI, qrterminal.M, os.Stdout) - } - - case "linking_successful": - if !uriOrQR { - fmt.Println("Successfully linked") - os.Exit(0) - } - } - } - } - }, -} - -func init() { - RootCmd.AddCommand(linkCmd) - linkCmd.Flags().BoolVarP(&uriOrQR, "uri", "u", false, "Print a URI instead of a QR code.") -} diff --git a/cmd/signaldctl/cmd/register.go b/cmd/signaldctl/cmd/register.go deleted file mode 100644 index bba9fc8..0000000 --- a/cmd/signaldctl/cmd/register.go +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright © 2020 Finn Herzfeld -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -package cmd - -import ( - "fmt" - "log" - "math/rand" - - "github.com/spf13/cobra" - - "gitlab.com/signald/signald-go/cmd/signaldctl/common" - "gitlab.com/signald/signald-go/signald/client-protocol/v0" -) - -// registerCmd represents the register command -var registerCmd = &cobra.Command{ - Use: "register", - Short: "Register a new account.", - Long: `Register a new signal account, generating new keys if the number was previously registered.`, - Run: func(cmd *cobra.Command, args []string) { - requestID := fmt.Sprint("signaldctl-", rand.Intn(1000)) - err := common.Signald.RawRequest(v0.LegacyRequest{ - Type: "register", - Username: username, - ID: requestID, - }) - if err != nil { - log.Fatal("error sending request: ", err) - } - go common.Signald.Listen(nil) - - defer common.Signald.CloseResponseListener(requestID) - r := <-common.Signald.GetResponseListener(requestID) - account, err := r.Data.MarshalJSON() - if err != nil { - log.Fatal("error rendering response:", err) - } - fmt.Println("validation code requested. submit the code using signaldctl verify", string(account)) - }, -} - -func init() { - RootCmd.AddCommand(registerCmd) - - registerCmd.Flags().StringVarP(&username, "username", "u", "", "The phone number of the new account to register)") - common.Must(registerCmd.MarkFlagRequired("username")) -} diff --git a/cmd/signaldctl/cmd/verify.go b/cmd/signaldctl/cmd/verify.go deleted file mode 100644 index ce4f1f0..0000000 --- a/cmd/signaldctl/cmd/verify.go +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright © 2020 Finn Herzfeld -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -package cmd - -import ( - "fmt" - "log" - "math/rand" - - "github.com/spf13/cobra" - - "gitlab.com/signald/signald-go/cmd/signaldctl/common" - "gitlab.com/signald/signald-go/signald/client-protocol/v0" -) - -var ( - code string -) - -// verify represents the verify command -var verify = &cobra.Command{ - Use: "verify", - Short: "Verify an account confirmation code and complete account setup", - Long: `Verify the phone number on a new account by submitting a verification code, completing the account registration process.`, - Run: func(cmd *cobra.Command, args []string) { - requestID := fmt.Sprint("signaldctl-", rand.Intn(1000)) - err := common.Signald.RawRequest(v0.LegacyRequest{ - Type: "verify", - Username: username, - Code: code, - ID: requestID, - }) - if err != nil { - log.Fatal("error sending request: ", err) - } - go common.Signald.Listen(nil) - - defer common.Signald.CloseResponseListener(requestID) - r := <-common.Signald.GetResponseListener(requestID) - account, err := r.Data.MarshalJSON() - if err != nil { - log.Fatal("error rendering response:", err) - } - fmt.Println("account created:", string(account)) - }, -} - -func init() { - RootCmd.AddCommand(verify) - - verify.Flags().StringVarP(&username, "username", "u", "", "The phone number the verification code was sent to") - common.Must(verify.MarkFlagRequired("username")) - - verify.Flags().StringVarP(&code, "code", "c", "", "The verification code") - common.Must(verify.MarkFlagRequired("code")) -}