diff --git a/.gitignore b/.gitignore index 9bef09c..30d8ff9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ pigeon-cli +*nutsdb* *scratchpad* \ No newline at end of file diff --git a/README.md b/README.md index f49022a..93a1d67 100644 --- a/README.md +++ b/README.md @@ -42,13 +42,13 @@ Don't use the Go version yet. If you want sommething stable, there is a [Ruby ve Without coverage: ``` -go test ./cmd +go test -run pigeon ``` With coverage: ``` -go test ./cmd -coverprofile cp.out +go test -run pigeon -coverprofile cp.out ``` # Build Project diff --git a/main.go b/main.go deleted file mode 100644 index 3407d36..0000000 --- a/main.go +++ /dev/null @@ -1,7 +0,0 @@ -package main - -import "pigeon/cmd" - -func main() { - cmd.Execute() -} diff --git a/pigeon/constants.go b/pigeon/constants.go new file mode 100644 index 0000000..3f6999f --- /dev/null +++ b/pigeon/constants.go @@ -0,0 +1,17 @@ +package pigeon + +// BlobSigil is a string identifier that precedes a base32 +// hash (SHA256) representing arbitrary data. +const BlobSigil = "FILE." + +// MessageSigil is a string identifier that precedes a base32 +// hash (SHA256) representing arbitrary data. +const MessageSigil = "TEXT." + +// UserSigil is a string identifier that precedes a base32 +// representation of a particular user's ED25519 public key. +const UserSigil = "USER." + +// StringSigil is a character used to identify strings as +// defined by the pigeon protocol spec. +const StringSigil = "\"" diff --git a/pigeon/cp.out b/pigeon/cp.out new file mode 100644 index 0000000..1e5ce4e --- /dev/null +++ b/pigeon/cp.out @@ -0,0 +1,27 @@ +mode: set +pigeon/pigeon/b32.go:12.36,14.2 1 0 +pigeon/pigeon/b32.go:18.37,20.18 2 0 +pigeon/pigeon/b32.go:25.2,25.15 1 0 +pigeon/pigeon/b32.go:20.18,22.13 2 0 +pigeon/pigeon/db.go:10.28,16.16 4 1 +pigeon/pigeon/db.go:19.2,19.11 1 1 +pigeon/pigeon/db.go:16.16,18.3 1 0 +pigeon/pigeon/db.go:36.39,37.44 1 0 +pigeon/pigeon/db.go:37.44,39.18 2 0 +pigeon/pigeon/db.go:42.3,43.18 2 0 +pigeon/pigeon/db.go:46.3,46.13 1 0 +pigeon/pigeon/db.go:39.18,41.4 1 0 +pigeon/pigeon/db.go:43.18,45.4 1 0 +pigeon/pigeon/db.go:51.36,54.29 2 0 +pigeon/pigeon/db.go:62.2,62.15 1 0 +pigeon/pigeon/db.go:54.29,56.19 2 0 +pigeon/pigeon/db.go:59.4,60.14 2 0 +pigeon/pigeon/db.go:56.19,58.5 1 0 +pigeon/pigeon/util.go:15.62,17.16 2 0 +pigeon/pigeon/util.go:22.2,22.18 1 0 +pigeon/pigeon/util.go:17.16,20.3 2 0 +pigeon/pigeon/util.go:28.63,32.2 3 0 +pigeon/pigeon/util.go:35.27,37.2 1 0 +pigeon/pigeon/util.go:41.44,44.21 3 0 +pigeon/pigeon/util.go:49.2,49.44 1 0 +pigeon/pigeon/util.go:44.21,47.3 2 0 diff --git a/pigeon/db.go b/pigeon/db.go index 180b4d0..58e7a2a 100644 --- a/pigeon/db.go +++ b/pigeon/db.go @@ -11,7 +11,7 @@ func createDB() *nutsdb.DB { // Open the database located in the /tmp/nutsdb directory. // It will be created if it doesn't exist. opt := nutsdb.DefaultOptions - opt.Dir = "./nutsdb" + opt.Dir = "./pigeondb" db, err := nutsdb.Open(opt) if err != nil { log.Fatal(err) @@ -47,7 +47,8 @@ func PutConfig(k ConfigKey, v []byte) { }) } -func getConfig(k ConfigKey) []byte { +// GetConfig retrieves aconfiguration key from NutsDB +func GetConfig(k ConfigKey) []byte { var output []byte database.View( func(tx *nutsdb.Tx) error { diff --git a/pigeon/pigeondb/0.dat b/pigeon/pigeondb/0.dat new file mode 100644 index 0000000..ea1a949 Binary files /dev/null and b/pigeon/pigeondb/0.dat differ diff --git a/pigeon/util.go b/pigeon/util.go index 67dc05b..9165572 100644 --- a/pigeon/util.go +++ b/pigeon/util.go @@ -3,6 +3,7 @@ package pigeon import ( "crypto/ed25519" "fmt" + "log" "os" ) @@ -32,7 +33,19 @@ func CreateIdentity() (ed25519.PublicKey, ed25519.PrivateKey) { // GetIdentity retrieves the user's signing key func GetIdentity() []byte { - return getConfig(ConfigSecret) + return GetConfig(ConfigSecret) } -func EncodeUserMhash() {} +// 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) +}