Tested signature middleware with standard tx wrappers

This commit is contained in:
Ethan Frey
2017-06-30 18:37:51 +02:00
parent b9ce148e8e
commit 4eef581396
5 changed files with 130 additions and 9 deletions
+2 -1
View File
@@ -9,7 +9,8 @@ import (
const (
// for utils...
ByteRaw = 0x1
ByteRaw = 0x1
// TODO: move fees into a module, multiplexer is standard
ByteFees = 0x2
ByteMulti = 0x3
ByteChain = 0x4
+17
View File
@@ -49,6 +49,7 @@ type OneSig struct {
}
var _ keys.Signable = &OneSig{}
var _ basecoin.TxLayer = &OneSig{}
func NewSig(tx basecoin.Tx) *OneSig {
return &OneSig{Tx: tx}
@@ -58,6 +59,10 @@ func (s *OneSig) Wrap() basecoin.Tx {
return basecoin.Tx{s}
}
func (s *OneSig) Next() basecoin.Tx {
return s.Tx
}
func (s *OneSig) ValidateBasic() error {
// TODO: VerifyBytes here, we do it in Signers?
if s.Empty() || !s.Pubkey.VerifyBytes(s.SignBytes(), s.Sig) {
@@ -119,6 +124,7 @@ type MultiSig struct {
}
var _ keys.Signable = &MultiSig{}
var _ basecoin.TxLayer = &MultiSig{}
func NewMulti(tx basecoin.Tx) *MultiSig {
return &MultiSig{Tx: tx}
@@ -128,6 +134,10 @@ func (s *MultiSig) Wrap() basecoin.Tx {
return basecoin.Tx{s}
}
func (s *MultiSig) Next() basecoin.Tx {
return s.Tx
}
func (s *MultiSig) ValidateBasic() error {
// TODO: more efficient
_, err := s.Signers()
@@ -185,3 +195,10 @@ func (s *MultiSig) Signers() ([]crypto.PubKey, error) {
return keys, nil
}
func Sign(tx keys.Signable, key crypto.PrivKey) error {
msg := tx.SignBytes()
pubkey := key.PubKey()
sig := key.Sign(msg)
return tx.Sign(pubkey, sig)
}