From 8fb8b84cd1a83de40d9ef331434a5669f1607275 Mon Sep 17 00:00:00 2001 From: chenchanglew Date: Tue, 11 Jun 2024 15:02:37 +0200 Subject: [PATCH] refactor: clean up code Signed-off-by: chenchanglew --- ecc_go/chaincode/enclave_go/skvs_stub.go | 2 +- ecc_go/chaincode/singleKVS.go | 128 ----------------------- 2 files changed, 1 insertion(+), 129 deletions(-) diff --git a/ecc_go/chaincode/enclave_go/skvs_stub.go b/ecc_go/chaincode/enclave_go/skvs_stub.go index 3d68f116d..03152d312 100644 --- a/ecc_go/chaincode/enclave_go/skvs_stub.go +++ b/ecc_go/chaincode/enclave_go/skvs_stub.go @@ -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 { diff --git a/ecc_go/chaincode/singleKVS.go b/ecc_go/chaincode/singleKVS.go index e756b8cbd..b34e0137a 100644 --- a/ecc_go/chaincode/singleKVS.go +++ b/ecc_go/chaincode/singleKVS.go @@ -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) -// }