forked from Hyperledger-TWGC/tape
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Arch refactor alpha (Hyperledger-TWGC#190)
* add crpto interface as repare for Hyperledger-TWGC#127 Signed-off-by: Sam Yuan <yy19902439@126.com> * adding Worker interface for Hyperledger-TWGC#56 and decouple Assembler and Integrator Signed-off-by: Sam Yuan <yy19902439@126.com> * refactor for worker interface Signed-off-by: Sam Yuan <yy19902439@126.com> * package structure Signed-off-by: Sam Yuan <yy19902439@126.com> * fix up Signed-off-by: Sam Yuan <yy19902439@126.com> * package refactor Signed-off-by: Sam Yuan <yy19902439@126.com> * fix up Signed-off-by: Sam Yuan <yy19902439@126.com> * fix up Signed-off-by: Sam Yuan <yy19902439@126.com> * remove Envelope from elements Signed-off-by: Sam Yuan <yy19902439@126.com> * add memeory free Signed-off-by: Sam Yuan <yy19902439@126.com> * remove Proposal from Elements Signed-off-by: Sam Yuan <yy19902439@126.com> * fix up Signed-off-by: Sam Yuan <yy19902439@126.com> * move start time to ctx Signed-off-by: Sam Yuan <yy19902439@126.com>
- Loading branch information
1 parent
b0fb13e
commit a8e4cf2
Showing
32 changed files
with
842 additions
and
630 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package basic_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestBasic(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Basic Suite") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package infra | ||
package basic | ||
|
||
import ( | ||
"context" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package basic | ||
|
||
import ( | ||
"crypto/ecdsa" | ||
"crypto/rand" | ||
"crypto/sha256" | ||
"crypto/x509" | ||
"encoding/asn1" | ||
"math/big" | ||
|
||
"tape/internal/fabric/bccsp/utils" | ||
"tape/internal/fabric/common/crypto" | ||
|
||
"github.com/hyperledger/fabric-protos-go/common" | ||
) | ||
|
||
type CryptoConfig struct { | ||
MSPID string | ||
PrivKey string | ||
SignCert string | ||
TLSCACerts []string | ||
} | ||
|
||
type ECDSASignature struct { | ||
R, S *big.Int | ||
} | ||
|
||
type CryptoImpl struct { | ||
Creator []byte | ||
PrivKey *ecdsa.PrivateKey | ||
SignCert *x509.Certificate | ||
} | ||
|
||
func (s *CryptoImpl) Sign(message []byte) ([]byte, error) { | ||
ri, si, err := ecdsa.Sign(rand.Reader, s.PrivKey, digest(message)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
si, _, err = utils.ToLowS(&s.PrivKey.PublicKey, si) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return asn1.Marshal(ECDSASignature{ri, si}) | ||
} | ||
|
||
func (s *CryptoImpl) Serialize() ([]byte, error) { | ||
return s.Creator, nil | ||
} | ||
|
||
func (s *CryptoImpl) NewSignatureHeader() (*common.SignatureHeader, error) { | ||
creator, err := s.Serialize() | ||
if err != nil { | ||
return nil, err | ||
} | ||
nonce, err := crypto.GetRandomNonce() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &common.SignatureHeader{ | ||
Creator: creator, | ||
Nonce: nonce, | ||
}, nil | ||
} | ||
|
||
func digest(in []byte) []byte { | ||
h := sha256.New() | ||
h.Write(in) | ||
return h.Sum(nil) | ||
} |
Oops, something went wrong.