|
|
|
@ -22,7 +22,6 @@ package p256 |
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
"bytes" |
|
|
|
|
"context" |
|
|
|
|
"crypto" |
|
|
|
|
"crypto/ecdsa" |
|
|
|
|
"crypto/elliptic" |
|
|
|
@ -34,13 +33,9 @@ import ( |
|
|
|
|
"encoding/binary" |
|
|
|
|
"encoding/pem" |
|
|
|
|
"errors" |
|
|
|
|
"fmt" |
|
|
|
|
"math/big" |
|
|
|
|
|
|
|
|
|
"github.com/google/trillian/crypto/keys" |
|
|
|
|
"github.com/harmony-one/harmony/crypto/vrf" |
|
|
|
|
|
|
|
|
|
"github.com/golang/protobuf/proto" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
var ( |
|
|
|
@ -229,23 +224,6 @@ func (pk *PublicKey) ProofToHash(m, proof []byte) (index [32]byte, err error) { |
|
|
|
|
return sha256.Sum256(vrf), nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// NewFromWrappedKey creates a VRF signer object from an encrypted private key.
|
|
|
|
|
// The opaque private key must resolve to an `ecdsa.PrivateKey` in order to work.
|
|
|
|
|
func NewFromWrappedKey(ctx context.Context, wrapped proto.Message) (vrf.PrivateKey, error) { |
|
|
|
|
// Unwrap.
|
|
|
|
|
signer, err := keys.NewSigner(ctx, wrapped) |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
switch key := signer.(type) { |
|
|
|
|
case *ecdsa.PrivateKey: |
|
|
|
|
return NewVRFSigner(key) |
|
|
|
|
default: |
|
|
|
|
return nil, fmt.Errorf("wrapped key has wrong type: %T, want ecdsa.PrivateKey", key) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// NewVRFSigner creates a signer object from a private key.
|
|
|
|
|
func NewVRFSigner(key *ecdsa.PrivateKey) (vrf.PrivateKey, error) { |
|
|
|
|
if *(key.Params()) != *curve.Params() { |
|
|
|
|