Add EncodeUserMhash()
helper
This commit is contained in:
parent
6d1231dcde
commit
53c69e1f14
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
||||||
pigeon-cli
|
pigeon-cli
|
||||||
|
*nutsdb*
|
||||||
*scratchpad*
|
*scratchpad*
|
|
@ -42,13 +42,13 @@ Don't use the Go version yet. If you want sommething stable, there is a [Ruby ve
|
||||||
Without coverage:
|
Without coverage:
|
||||||
|
|
||||||
```
|
```
|
||||||
go test ./cmd
|
go test -run pigeon
|
||||||
```
|
```
|
||||||
|
|
||||||
With coverage:
|
With coverage:
|
||||||
|
|
||||||
```
|
```
|
||||||
go test ./cmd -coverprofile cp.out
|
go test -run pigeon -coverprofile cp.out
|
||||||
```
|
```
|
||||||
|
|
||||||
# Build Project
|
# Build Project
|
||||||
|
|
17
pigeon/constants.go
Normal file
17
pigeon/constants.go
Normal file
|
@ -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 = "\""
|
27
pigeon/cp.out
Normal file
27
pigeon/cp.out
Normal file
|
@ -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
|
|
@ -11,7 +11,7 @@ func createDB() *nutsdb.DB {
|
||||||
// Open the database located in the /tmp/nutsdb directory.
|
// Open the database located in the /tmp/nutsdb directory.
|
||||||
// It will be created if it doesn't exist.
|
// It will be created if it doesn't exist.
|
||||||
opt := nutsdb.DefaultOptions
|
opt := nutsdb.DefaultOptions
|
||||||
opt.Dir = "./nutsdb"
|
opt.Dir = "./pigeondb"
|
||||||
db, err := nutsdb.Open(opt)
|
db, err := nutsdb.Open(opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
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
|
var output []byte
|
||||||
database.View(
|
database.View(
|
||||||
func(tx *nutsdb.Tx) error {
|
func(tx *nutsdb.Tx) error {
|
||||||
|
|
BIN
pigeon/pigeondb/0.dat
Normal file
BIN
pigeon/pigeondb/0.dat
Normal file
Binary file not shown.
|
@ -3,6 +3,7 @@ package pigeon
|
||||||
import (
|
import (
|
||||||
"crypto/ed25519"
|
"crypto/ed25519"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -32,7 +33,19 @@ func CreateIdentity() (ed25519.PublicKey, ed25519.PrivateKey) {
|
||||||
|
|
||||||
// GetIdentity retrieves the user's signing key
|
// GetIdentity retrieves the user's signing key
|
||||||
func GetIdentity() []byte {
|
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)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user