Skip to content

Commit

Permalink
use ssb.ParseRef
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptix committed Nov 6, 2019
1 parent fdab769 commit 7e5c71c
Show file tree
Hide file tree
Showing 3 changed files with 261 additions and 20 deletions.
32 changes: 13 additions & 19 deletions generate.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package hexagen // import "go.cryptoscope.co/hexagen"
package hexagen

import (
"encoding/base64"
"fmt"
"image/color"
"math"
"strings"

"github.com/pkg/errors"
"go.cryptoscope.co/ssb"
)

func adjacent(a, b FaceAddr) bool {
Expand Down Expand Up @@ -86,25 +85,20 @@ func inhexagon(addr FaceAddr) bool {
}

func Generate(id string, width float64) (*Grid, error) {
if id[0] != '@' && id[0] != '%' {
return nil, errors.New("hexagen: that does not look like an id")
}

idSplit := strings.Split(id[1:], ".")

if len(idSplit) != 2 {
return nil, errors.Errorf("hexagen: %q does not look like an id.", idSplit)
}

if idSplit[1] != "ed25519" && idSplit[1] != "sha256" {
return nil, errors.Errorf("hexagen: %q is no known suffix", idSplit[1])
ref, err := ssb.ParseRef(id)
if err != nil {
return nil, errors.Wrap(err, "hexagen: that does not look like an id")
}

b64Key := strings.Split(id[1:], ".")[0]
var key []byte

key, err := base64.StdEncoding.DecodeString(b64Key)
if err != nil {
return nil, errors.Wrapf(err, "hexagen: b64 decode failed")
switch rt := ref.(type) {
case *ssb.FeedRef:
key = rt.PubKey()
case *ssb.BlobRef:
key = rt.Hash
default:
return nil, errors.Errorf("hexagen: invalid ref type %T", ref)
}

var g Grid
Expand Down
7 changes: 6 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
module go.cryptoscope.co/hexagen

require github.com/pkg/errors v0.8.0
require (
github.com/pkg/errors v0.8.1
go.cryptoscope.co/ssb v0.0.0-20191030090955-5d1473dc10ec
)

go 1.13
Loading

0 comments on commit 7e5c71c

Please sign in to comment.