Skip to content

Commit

Permalink
[panthalassa] added utils to sign profile
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Lenz committed May 30, 2018
1 parent 7f909c6 commit a4a5c6d
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 4 deletions.
21 changes: 21 additions & 0 deletions mobile_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
deviceApi "github.com/Bit-Nation/panthalassa/api/device"
keyManager "github.com/Bit-Nation/panthalassa/keyManager"
mesh "github.com/Bit-Nation/panthalassa/mesh"
"github.com/Bit-Nation/panthalassa/profile"
log "github.com/ipfs/go-log"
"github.com/segmentio/objconv/json"
valid "gopkg.in/asaskevich/govalidator.v4"
Expand Down Expand Up @@ -175,6 +176,26 @@ func GetMnemonic() (string, error) {
return panthalassaInstance.km.GetMnemonic().String(), nil
}

func SignProfile(name, location, image string) (string, error) {

if panthalassaInstance == nil {
return "", errors.New("you have to start panthalassa")
}

p, err := profile.SignProfile(name, location, image, *panthalassaInstance.km)
if err != nil {
return "", err
}

rawProfile, err := p.Marshal()
if err != nil {
return "", err
}

return string(rawProfile), nil

}

//Stop panthalassa
func Stop() error {

Expand Down
6 changes: 6 additions & 0 deletions profile/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ type Profile struct {
Signatures Signatures `json:"signatures"`
}

func (p *Profile) Marshal() ([]byte, error) {

return json.Marshal(p)

}

// check if signatures of profile are correct
func (p Profile) SignaturesValid() (bool, error) {

Expand Down
32 changes: 28 additions & 4 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package panthalassa

import (
"errors"
"strings"

cid "github.com/Bit-Nation/panthalassa/crypto/cid"
scrypt "github.com/Bit-Nation/panthalassa/crypto/scrypt"
"github.com/Bit-Nation/panthalassa/keyManager"
"github.com/Bit-Nation/panthalassa/keyStore"
keyManager "github.com/Bit-Nation/panthalassa/keyManager"
keyStore "github.com/Bit-Nation/panthalassa/keyStore"
mnemonic "github.com/Bit-Nation/panthalassa/mnemonic"
"github.com/tyler-smith/go-bip39"
"strings"
"github.com/Bit-Nation/panthalassa/profile"
bip39 "github.com/tyler-smith/go-bip39"
)

//Encrypt's data
Expand Down Expand Up @@ -101,3 +102,26 @@ func IsValidMnemonic(mne string) bool {

return bip39.IsMnemonicValid(mne)
}

// sign profile
func SignProfileStandAlone(name, location, image, keyManagerStore, password string) (string, error) {

p, err := profile.SignWithKeyManagerStore(name, location, image, keyManagerStore, password)

if err != nil {
return "", nil
}

_, err = p.SignaturesValid()
if err != nil {
return "", err
}

rawProfile, err := p.Marshal()
if err != nil {
return "", err
}

return string(rawProfile), nil

}

0 comments on commit a4a5c6d

Please sign in to comment.