Skip to content

Commit

Permalink
refactor: clean up code
Browse files Browse the repository at this point in the history
Signed-off-by: chenchanglew <[email protected]>
  • Loading branch information
chenchanglew committed Jun 11, 2024
1 parent eafbf16 commit 8fb8b84
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 129 deletions.
2 changes: 1 addition & 1 deletion ecc_go/chaincode/enclave_go/skvs_stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func NewSkvsStub(cc shim.Chaincode) *skvsStub {
}

func (e *skvsStub) ChaincodeInvoke(stub shim.ChaincodeStubInterface, chaincodeRequestMessageBytes []byte) ([]byte, error) {
logger.Error("==== SKVS ChaincodeInvoke ====")
logger.Warning("==== SKVS ChaincodeInvoke ====")

signedProposal, err := stub.GetSignedProposal()
if err != nil {
Expand Down
128 changes: 0 additions & 128 deletions ecc_go/chaincode/singleKVS.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,131 +26,3 @@ func NewSkvsChaincode(cc shim.Chaincode) *chaincode.EnclaveChaincode {
}
return ecc
}

// type skvsStub struct {
// *enclave_go.EnclaveStub
// }

// func NewSkvsStub(cc shim.Chaincode) *skvsStub {
// enclaveStub := enclave_go.NewEnclaveStub(cc)
// return &skvsStub{enclaveStub}
// }

// func (e *skvsStub) ChaincodeInvoke(stub shim.ChaincodeStubInterface, chaincodeRequestMessageBytes []byte) ([]byte, error) {
// logger.Error("==== SKVS ChaincodeInvoke ====")

// signedProposal, err := stub.GetSignedProposal()
// if err != nil {
// shim.Error(err.Error())
// }

// if err := e.verifySignedProposal(stub, chaincodeRequestMessageBytes); err != nil {
// return nil, errors.Wrap(err, "signed proposal verification failed")
// }

// // unmarshal chaincodeRequest
// chaincodeRequestMessage := &protos.ChaincodeRequestMessage{}
// err = proto.Unmarshal(chaincodeRequestMessageBytes, chaincodeRequestMessage)
// if err != nil {
// return nil, err
// }

// // get key transport message including the encryption keys for request and response
// keyTransportMessage, err := e.extractKeyTransportMessage(chaincodeRequestMessage)
// if err != nil {
// return nil, errors.Wrap(err, "cannot extract keyTransportMessage")
// }

// // decrypt request
// cleartextChaincodeRequest, err := e.extractCleartextChaincodeRequest(chaincodeRequestMessage, keyTransportMessage)
// if err != nil {
// return nil, errors.Wrap(err, "cannot decrypt chaincode request")
// }

// // create a new instance of a FPC RWSet that we pass to the stub and later return with the response
// rwset := NewReadWriteSet()

// // Invoke chaincode
// // we wrap the stub with our FpcStubInterface
// // ** Implement our own FpcStubInterface
// skvsStub := NewSkvsStubInterface(stub, cleartextChaincodeRequest.GetInput(), rwset, e.ccKeys)
// ccResponse := e.ccRef.Invoke(skvsStub)
// // **
// // fpcStub := NewFpcStubInterface(stub, cleartextChaincodeRequest.GetInput(), rwset, e.ccKeys)
// // ccResponse := e.ccRef.Invoke(fpcStub)

// // marshal chaincode response
// ccResponseBytes, err := protoutil.Marshal(&ccResponse)
// if err != nil {
// return nil, err
// }

// //encrypt response
// encryptedResponse, err := e.csp.EncryptMessage(keyTransportMessage.GetResponseEncryptionKey(), ccResponseBytes)
// if err != nil {
// return nil, err
// }

// chaincodeRequestMessageHash := sha256.Sum256(chaincodeRequestMessageBytes)

// response := &protos.ChaincodeResponseMessage{
// EncryptedResponse: encryptedResponse,
// FpcRwSet: rwset.ToFPCKVSet(),
// EnclaveId: e.identity.GetEnclaveId(),
// Proposal: signedProposal,
// ChaincodeRequestMessageHash: chaincodeRequestMessageHash[:],
// }

// responseBytes, err := proto.Marshal(response)
// if err != nil {
// return nil, err
// }

// // create signature
// sig, err := e.identity.Sign(responseBytes)
// if err != nil {
// return nil, err
// }

// signedResponse := &protos.SignedChaincodeResponseMessage{
// ChaincodeResponseMessage: responseBytes,
// Signature: sig,
// }

// return proto.Marshal(signedResponse)
// }

// func (e *skvsStub) verifySignedProposal(stub shim.ChaincodeStubInterface, chaincodeRequestMessageBytes []byte) error {
// return e.EnclaveStub.verifySignedProposal(stub, chaincodeRequestMessageBytes)
// }

// type SkvsStubInterface struct {
// *enclave_go.FpcStubInterface
// }

// func NewSkvsStubInterface(stub shim.ChaincodeStubInterface, input *pb.ChaincodeInput, rwset *readWriteSet, sep StateEncryptionFunctions) *SkvsStubInterface {
// fpcStub := enclave_go.NewFpcStubInterface(stub, input, rwset, sep)
// return &SkvsStubInterface{fpcStub}
// }

// func (s *SkvsStubInterface) GetState(key string) ([]byte, error) {
// encValue, err := s.GetPublicState(SingleKey)
// if err != nil {
// return nil, err
// }

// // in case the key does not exist, return early
// if len(encValue) == 0 {
// return nil, nil
// }

// return s.sep.DecryptState(encValue)
// }

// func (s *SkvsStubInterface) PutState(key string, value []byte) error {
// encValue, err := s.sep.EncryptState(SingleKey)
// if err != nil {
// return err
// }
// return s.PutPublicState(key, encValue)
// }

0 comments on commit 8fb8b84

Please sign in to comment.