Skip to content

Commit

Permalink
Merge pull request #21 from TRON-US/extractSignAndVerify
Browse files Browse the repository at this point in the history
change sign and verify to common package
  • Loading branch information
jin-tron authored Nov 19, 2019
2 parents 6f2b5ee + 170dd14 commit 38d475b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
22 changes: 22 additions & 0 deletions crypto/crypto.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package crypto

import (
"github.com/gogo/protobuf/proto"
ic "github.com/libp2p/go-libp2p-core/crypto"
)

func Sign(key ic.PrivKey, channelMessage proto.Message) ([]byte, error) {
raw, err := proto.Marshal(channelMessage)
if err != nil {
return nil, err
}
return key.Sign(raw)
}

func Verify(key ic.PubKey, channelMessage proto.Message, sig []byte) (bool, error) {
raw, err := proto.Marshal(channelMessage)
if err != nil {
return false, err
}
return key.Verify(raw, sig)
}
14 changes: 0 additions & 14 deletions ledger/ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,4 @@ func CloseChannel(ctx context.Context, ledgerClient ledgerPb.ChannelsClient, sig
return nil
}

func Sign(key ic.PrivKey, channelMessage proto.Message) ([]byte, error) {
raw, err := proto.Marshal(channelMessage)
if err != nil {
return nil, err
}
return key.Sign(raw)
}

func Verify(key ic.PubKey, channelMessage proto.Message, sig []byte) (bool, error) {
raw, err := proto.Marshal(channelMessage)
if err != nil {
return false, err
}
return key.Verify(raw, sig)
}

0 comments on commit 38d475b

Please sign in to comment.