Skip to content

Commit

Permalink
fix: force Secp256k1 key format
Browse files Browse the repository at this point in the history
  • Loading branch information
glouvigny authored and aeddi committed Jun 12, 2019
1 parent b7df538 commit 486315f
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion entry/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type Entry struct {
LogID string
Next []cid.Cid
V uint64
Key ic.PubKey
Key *ic.Secp256k1PublicKey
Sig mh.Multihash
Identity *identityprovider.Identity
Hash cid.Cid
Expand Down
2 changes: 1 addition & 1 deletion entry/entry_io.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func FetchAll (ipfs *io.IpfsServices, hashes []cid.Cid, options *FetchOptions) [
}

shouldFetchMore := func () bool {
return len(loadingQueue) > 0 && (len(result) < options.Length || options.Length < 0)
return len(loadingQueue) > 0 && (len(result) < options.Length || options.Length <= 0)
}

fetchEntry := func () {
Expand Down
6 changes: 3 additions & 3 deletions identityprovider/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import (

type IdentitySignature struct {
ID []byte
PublicKey ic.PubKey
PublicKey *ic.Secp256k1PublicKey
}

type Identity struct {
ID string
PublicKey ic.PubKey
PrivateKey ic.PrivKey
PublicKey *ic.Secp256k1PublicKey
PrivateKey *ic.Secp256k1PrivateKey
Signatures *IdentitySignature
Type pb.KeyType
Provider Interface
Expand Down
5 changes: 3 additions & 2 deletions identityprovider/orbitdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package identityprovider
import (
"fmt"
"github.com/berty/go-ipfs-log/keystore"
crypto "github.com/libp2p/go-libp2p-crypto"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -38,10 +39,10 @@ func (p *OrbitDBIdentityProvider) GetID(id string) (*Identity, error) {

return &Identity{
ID: id,
PublicKey: pubKey,
PublicKey: pubKey.(*crypto.Secp256k1PublicKey),
Signatures: &IdentitySignature{
ID: keySign,
PublicKey: pubKey,
PublicKey: pubKey.(*crypto.Secp256k1PublicKey),
},
PrivateKey: private,
Type: private.Type(),
Expand Down
4 changes: 2 additions & 2 deletions keystore/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "github.com/libp2p/go-libp2p-crypto"
type Interface interface {
HasKey(id string) (bool, error)

CreateKey(id string) (crypto.PrivKey, error)
CreateKey(id string) (*crypto.Secp256k1PrivateKey, error)

GetKey(id string) (crypto.PrivKey, error)
GetKey(id string) (*crypto.Secp256k1PrivateKey, error)
}
8 changes: 4 additions & 4 deletions keystore/keystore.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (k *Keystore) HasKey(id string) (bool, error) {
return hasKey, nil
}

func (k *Keystore) CreateKey(id string) (crypto.PrivKey, error) {
func (k *Keystore) CreateKey(id string) (*crypto.Secp256k1PrivateKey, error) {
// FIXME: I kept Secp256k1 for compatibility with OrbitDB, should we change this?
priv, _, err := crypto.GenerateSecp256k1Key(rand.Reader)
if err != nil {
Expand All @@ -65,10 +65,10 @@ func (k *Keystore) CreateKey(id string) (crypto.PrivKey, error) {

k.cache.Add(id, priv)

return priv, nil
return priv.(*crypto.Secp256k1PrivateKey), nil
}

func (k *Keystore) GetKey(id string) (crypto.PrivKey, error) {
func (k *Keystore) GetKey(id string) (*crypto.Secp256k1PrivateKey, error) {
var err error

cachedKey, ok := k.cache.Get(id)
Expand All @@ -92,7 +92,7 @@ func (k *Keystore) GetKey(id string) (crypto.PrivKey, error) {
return nil, err
}

return privateKey, nil
return privateKey.(*crypto.Secp256k1PrivateKey), nil
}

var _ Interface = &Keystore{}
4 changes: 2 additions & 2 deletions utils/lamportclock/lamportclock.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

type LamportClock struct {
ID ic.PubKey
ID *ic.Secp256k1PublicKey
Time int
}

Expand Down Expand Up @@ -63,7 +63,7 @@ func Compare(a *LamportClock, b *LamportClock) (int, error) {
return int(dist), nil
}

func New(identity ic.PubKey, time int) *LamportClock {
func New(identity *ic.Secp256k1PublicKey, time int) *LamportClock {
return &LamportClock{
ID: identity,
Time: time,
Expand Down

0 comments on commit 486315f

Please sign in to comment.