Add some documentation
This commit is contained in:
parent
9143f54783
commit
b4c43671f8
5 changed files with 32 additions and 209 deletions
4
README.md
Normal file
4
README.md
Normal file
|
@ -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)
|
28
cmd/signaldctl/README.md
Normal file
28
cmd/signaldctl/README.md
Normal file
|
@ -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
|
||||||
|
```
|
|
@ -1,79 +0,0 @@
|
||||||
// Copyright © 2018 Finn Herzfeld <finn@janky.solutions>
|
|
||||||
//
|
|
||||||
// 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 <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
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.")
|
|
||||||
}
|
|
|
@ -1,61 +0,0 @@
|
||||||
// Copyright © 2020 Finn Herzfeld <finn@janky.solutions>
|
|
||||||
//
|
|
||||||
// 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 <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
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"))
|
|
||||||
}
|
|
|
@ -1,69 +0,0 @@
|
||||||
// Copyright © 2020 Finn Herzfeld <finn@janky.solutions>
|
|
||||||
//
|
|
||||||
// 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 <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
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"))
|
|
||||||
}
|
|
Loading…
Reference in a new issue