Fix CheckBlockSignature, add docks
Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
This commit is contained in:
parent
cb05001e5a
commit
5bc1cb2aa3
9
lib/sigs/doc.go
Normal file
9
lib/sigs/doc.go
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
// Sigs package allows for signing, verifying signatures and key generation
|
||||||
|
// using key types selected by package user.
|
||||||
|
//
|
||||||
|
// For support of secp256k1 import:
|
||||||
|
// _ "github.com/filecoin-project/lotus/lib/sigs/secp"
|
||||||
|
//
|
||||||
|
// For support of Filecoin BLS import:
|
||||||
|
// _ "github.com/filecoin-project/lotus/lib/sigs/bls"
|
||||||
|
package sigs
|
@ -10,23 +10,8 @@ import (
|
|||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SigShim interface {
|
// Sign takes in signature type, private key and message. Returns a signature for that message.
|
||||||
GenPrivate() ([]byte, error)
|
// Valid sigTypes are: "secp256k1" and "bls"
|
||||||
ToPublic(pk []byte) ([]byte, error)
|
|
||||||
Sign(pk []byte, msg []byte) ([]byte, error)
|
|
||||||
Verify(sig []byte, a address.Address, msg []byte) error
|
|
||||||
}
|
|
||||||
|
|
||||||
var sigs map[string]SigShim
|
|
||||||
|
|
||||||
// RegisterSig should be only used during init
|
|
||||||
func RegisterSignature(name string, vs SigShim) {
|
|
||||||
if sigs == nil {
|
|
||||||
sigs = make(map[string]SigShim)
|
|
||||||
}
|
|
||||||
sigs[name] = vs
|
|
||||||
}
|
|
||||||
|
|
||||||
func Sign(sigType string, privkey []byte, msg []byte) (*types.Signature, error) {
|
func Sign(sigType string, privkey []byte, msg []byte) (*types.Signature, error) {
|
||||||
sv, ok := sigs[sigType]
|
sv, ok := sigs[sigType]
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -43,6 +28,7 @@ func Sign(sigType string, privkey []byte, msg []byte) (*types.Signature, error)
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Verify verifies signatures
|
||||||
func Verify(sig *types.Signature, addr address.Address, msg []byte) error {
|
func Verify(sig *types.Signature, addr address.Address, msg []byte) error {
|
||||||
if sig == nil {
|
if sig == nil {
|
||||||
return xerrors.Errorf("signature is nil")
|
return xerrors.Errorf("signature is nil")
|
||||||
@ -60,6 +46,7 @@ func Verify(sig *types.Signature, addr address.Address, msg []byte) error {
|
|||||||
return sv.Verify(sig.Data, addr, msg)
|
return sv.Verify(sig.Data, addr, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Generate generates private key of given type
|
||||||
func Generate(sigType string) ([]byte, error) {
|
func Generate(sigType string) ([]byte, error) {
|
||||||
sv, ok := sigs[sigType]
|
sv, ok := sigs[sigType]
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -69,6 +56,7 @@ func Generate(sigType string) ([]byte, error) {
|
|||||||
return sv.GenPrivate()
|
return sv.GenPrivate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ToPublic converts private key to public key
|
||||||
func ToPublic(sigType string, pk []byte) ([]byte, error) {
|
func ToPublic(sigType string, pk []byte) ([]byte, error) {
|
||||||
sv, ok := sigs[sigType]
|
sv, ok := sigs[sigType]
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -92,6 +80,23 @@ func CheckBlockSignature(blk *types.BlockHeader, ctx context.Context, worker add
|
|||||||
}
|
}
|
||||||
|
|
||||||
_ = sigb
|
_ = sigb
|
||||||
//return blk.BlockSig.Verify(worker, sigb)
|
return Verify(blk.BlockSig, worker, sigb)
|
||||||
return nil
|
}
|
||||||
|
|
||||||
|
// SigShim is used for introducing signature functions
|
||||||
|
type SigShim interface {
|
||||||
|
GenPrivate() ([]byte, error)
|
||||||
|
ToPublic(pk []byte) ([]byte, error)
|
||||||
|
Sign(pk []byte, msg []byte) ([]byte, error)
|
||||||
|
Verify(sig []byte, a address.Address, msg []byte) error
|
||||||
|
}
|
||||||
|
|
||||||
|
var sigs map[string]SigShim
|
||||||
|
|
||||||
|
// RegisterSig should be only used during init
|
||||||
|
func RegisterSignature(name string, vs SigShim) {
|
||||||
|
if sigs == nil {
|
||||||
|
sigs = make(map[string]SigShim)
|
||||||
|
}
|
||||||
|
sigs[name] = vs
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user