From 486315fb9d574aaf500d25f30f74dcce69ae52fa Mon Sep 17 00:00:00 2001 From: Guillaume Louvigny Date: Mon, 20 May 2019 17:42:52 +0200 Subject: [PATCH] fix: force Secp256k1 key format --- entry/entry.go | 2 +- entry/entry_io.go | 2 +- identityprovider/identity.go | 6 +++--- identityprovider/orbitdb.go | 5 +++-- keystore/interface.go | 4 ++-- keystore/keystore.go | 8 ++++---- utils/lamportclock/lamportclock.go | 4 ++-- 7 files changed, 16 insertions(+), 15 deletions(-) diff --git a/entry/entry.go b/entry/entry.go index f66dbfa..13e5e51 100644 --- a/entry/entry.go +++ b/entry/entry.go @@ -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 diff --git a/entry/entry_io.go b/entry/entry_io.go index 41de417..7de96bc 100644 --- a/entry/entry_io.go +++ b/entry/entry_io.go @@ -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 () { diff --git a/identityprovider/identity.go b/identityprovider/identity.go index 726e119..8b1868a 100644 --- a/identityprovider/identity.go +++ b/identityprovider/identity.go @@ -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 diff --git a/identityprovider/orbitdb.go b/identityprovider/orbitdb.go index c78136b..00206b2 100644 --- a/identityprovider/orbitdb.go +++ b/identityprovider/orbitdb.go @@ -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" ) @@ -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(), diff --git a/keystore/interface.go b/keystore/interface.go index 17446d7..cc88a1f 100644 --- a/keystore/interface.go +++ b/keystore/interface.go @@ -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) } diff --git a/keystore/keystore.go b/keystore/keystore.go index 01b92eb..1e258af 100644 --- a/keystore/keystore.go +++ b/keystore/keystore.go @@ -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 { @@ -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) @@ -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{} diff --git a/utils/lamportclock/lamportclock.go b/utils/lamportclock/lamportclock.go index 40842a0..9ecfc54 100644 --- a/utils/lamportclock/lamportclock.go +++ b/utils/lamportclock/lamportclock.go @@ -7,7 +7,7 @@ import ( ) type LamportClock struct { - ID ic.PubKey + ID *ic.Secp256k1PublicKey Time int } @@ -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,