This is an automated email from the ASF dual-hosted git repository. cmorris pushed a commit to branch splitroles-blockchain in repository https://gitbox.apache.org/repos/asf/incubator-milagro-dta.git
commit 516834fe1d58559257c0145b3138766798b4e724 Author: Christopher Morris <[email protected]> AuthorDate: Mon Sep 30 10:36:04 2019 +0100 Convert Order to Blockchain --- cmd/service/main.go | 13 +-- go.mod | 2 +- libs/documents/docs.go | 11 +++ libs/documents/docs.pb.go | 156 +++++++++++++++++++----------------- libs/documents/docs.proto | 1 + libs/documents/docs.validator.pb.go | 1 + pkg/api/client.go | 10 +++ pkg/api/proto.go | 4 +- pkg/bitcoinplugin/service.go | 2 +- pkg/common/chain.go | 44 ++++++++++ pkg/defaultservice/fulfill.go | 87 ++++++++++++++++++++ pkg/defaultservice/order.go | 74 +++++++++++------ pkg/defaultservice/plugable.go | 2 +- pkg/defaultservice/service.go | 28 +++++++ pkg/endpoints/endpoints.go | 21 ++--- pkg/safeguardsecret/service.go | 7 +- pkg/service/service.go | 4 +- pkg/tendermint/tendermint.go | 34 ++++---- pkg/tendermint/websockets.go | 14 ++-- 19 files changed, 368 insertions(+), 147 deletions(-) diff --git a/cmd/service/main.go b/cmd/service/main.go index 9548f0a..5eb56de 100644 --- a/cmd/service/main.go +++ b/cmd/service/main.go @@ -153,12 +153,6 @@ func startDaemon(args []string) error { return errors.Wrap(err, "init datastore") } - //Connect to Blockchain - Tendermint - go tendermint.Subscribe(store, logger, cfg.Node.NodeID, cfg.HTTP.ListenAddr) - if err != nil { - return errors.Wrap(err, "init Tendermint Blockchain") - } - logger.Info("IPFS connector type: %s", cfg.IPFS.Connector) var ipfsConnector ipfs.Connector switch cfg.IPFS.Connector { @@ -238,6 +232,13 @@ func startDaemon(args []string) error { logger.Info("Node Type: %v", strings.ToLower(cfg.Node.NodeType)) endpoints := endpoints.Endpoints(svcPlugin, cfg.HTTP.CorsAllow, authorizer, logger, cfg.Node.NodeType) httpHandler := transport.NewHTTPHandler(endpoints, logger, duration) + + //Connect to Blockchain - Tendermint + go tendermint.Subscribe(svcPlugin, store, logger, cfg.Node.NodeID, cfg.HTTP.ListenAddr) + if err != nil { + return errors.Wrap(err, "init Tendermint Blockchain") + } + // Start the application http server go func() { logger.Info("starting listener on %v, custody server %v", cfg.HTTP.ListenAddr, cfg.Node.MasterFiduciaryServer) diff --git a/go.mod b/go.mod index a526712..6225b74 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/golang/protobuf v1.3.2 github.com/google/uuid v1.1.1 github.com/gorilla/mux v1.7.3 - github.com/hokaccha/go-prettyjson v0.0.0-20190818114111-108c894c2c0e // indirect + github.com/hokaccha/go-prettyjson v0.0.0-20190818114111-108c894c2c0e github.com/ipfs/go-datastore v0.0.5 github.com/ipfs/go-ds-leveldb v0.0.2 github.com/ipfs/go-ipfs v0.4.22 diff --git a/libs/documents/docs.go b/libs/documents/docs.go index 8cc7c71..2845aad 100644 --- a/libs/documents/docs.go +++ b/libs/documents/docs.go @@ -96,6 +96,17 @@ func DecodeIDDocument(rawdoc []byte, tag string, idDocument *IDDoc) error { return nil } +//PeekOrderDocument - look at the header inside an order document before decryption +func OrderDocumentSigner(rawDoc []byte) (string, error) { + signedEnvelope := SignedEnvelope{} + err := proto.Unmarshal(rawDoc, &signedEnvelope) + if err != nil { + return "", errors.New("Protobuf - Failed to unmarshal Signed Envelope") + } + return signedEnvelope.SignerCID, nil + +} + //DecodeOrderDocument - func DecodeOrderDocument(rawdoc []byte, tag string, orderdoc *OrderDoc, sikeSK []byte, recipientCID string, sendersBlsPK []byte) error { cipherText := OrderDocument{} diff --git a/libs/documents/docs.pb.go b/libs/documents/docs.pb.go index 9d1de4d..0a5cb42 100644 --- a/libs/documents/docs.pb.go +++ b/libs/documents/docs.pb.go @@ -525,12 +525,13 @@ func (m *OrderDocument) GetOrderPart4() *OrderPart4 { } type OrderPart2 struct { - CommitmentPublicKey string `protobuf:"bytes,1,opt,name=CommitmentPublicKey,proto3" json:"CommitmentPublicKey,omitempty"` - PreviousOrderCID string `protobuf:"bytes,2,opt,name=PreviousOrderCID,proto3" json:"PreviousOrderCID,omitempty"` - Timestamp int64 `protobuf:"varint,3,opt,name=Timestamp,proto3" json:"Timestamp,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + CommitmentPublicKey string `protobuf:"bytes,1,opt,name=CommitmentPublicKey,proto3" json:"CommitmentPublicKey,omitempty"` + PreviousOrderCID string `protobuf:"bytes,2,opt,name=PreviousOrderCID,proto3" json:"PreviousOrderCID,omitempty"` + Timestamp int64 `protobuf:"varint,3,opt,name=Timestamp,proto3" json:"Timestamp,omitempty"` + Extension map[string]string `protobuf:"bytes,4,rep,name=Extension,proto3" json:"Extension,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *OrderPart2) Reset() { *m = OrderPart2{} } @@ -579,6 +580,13 @@ func (m *OrderPart2) GetTimestamp() int64 { return 0 } +func (m *OrderPart2) GetExtension() map[string]string { + if m != nil { + return m.Extension + } + return nil +} + type OrderPart3 struct { Redemption string `protobuf:"bytes,1,opt,name=Redemption,proto3" json:"Redemption,omitempty"` PreviousOrderCID string `protobuf:"bytes,2,opt,name=PreviousOrderCID,proto3" json:"PreviousOrderCID,omitempty"` @@ -870,6 +878,7 @@ func init() { proto.RegisterType((*IDDocument)(nil), "documents.IDDocument") proto.RegisterType((*OrderDocument)(nil), "documents.OrderDocument") proto.RegisterType((*OrderPart2)(nil), "documents.OrderPart2") + proto.RegisterMapType((map[string]string)(nil), "documents.OrderPart2.ExtensionEntry") proto.RegisterType((*OrderPart3)(nil), "documents.OrderPart3") proto.RegisterType((*OrderPart4)(nil), "documents.OrderPart4") proto.RegisterType((*Policy)(nil), "documents.Policy") @@ -881,70 +890,73 @@ func init() { func init() { proto.RegisterFile("docs.proto", fileDescriptor_2a25dace11219bce) } var fileDescriptor_2a25dace11219bce = []byte{ - // 1035 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xc4, 0x56, 0xcf, 0x6e, 0x23, 0xc5, - 0x13, 0xfe, 0x8d, 0xed, 0x38, 0x71, 0xc5, 0x9b, 0x78, 0x7b, 0x93, 0xdd, 0x51, 0x7e, 0xab, 0x4d, - 0x34, 0x8a, 0x50, 0x90, 0x48, 0x42, 0x6c, 0x6f, 0x04, 0x11, 0x12, 0x22, 0x76, 0x00, 0x6b, 0xf9, - 0x63, 0xc6, 0xd9, 0x80, 0xb4, 0xda, 0x8d, 0x26, 0x33, 0x15, 0xa7, 0x15, 0x4f, 0xf7, 0x68, 0xa6, - 0x9d, 0x60, 0x01, 0x67, 0x0e, 0x5c, 0x90, 0x38, 0x73, 0x41, 0xda, 0x2b, 0x47, 0x78, 0x01, 0xde, - 0x23, 0x22, 0x07, 0x10, 0x6f, 0xc0, 0x0d, 0xd4, 0x3d, 0x33, 0x76, 0x8f, 0xb1, 0x37, 0x7b, 0x40, - 0xc2, 0xa7, 0xae, 0xfa, 0xbe, 0xaa, 0xae, 0xea, 0xfa, 0xba, 0xc7, 0x00, 0x1e, 0x77, 0xa3, 0xad, - 0x20, 0xe4, 0x82, 0x93, 0x92, 0xc7, 0xdd, 0xbe, 0x8f, 0x4c, 0x44, 0x2b, 0xbb, 0x5d, 0x2a, 0xce, - 0xfa, 0x27, 0x5b, 0x2e, 0xf7, 0xb7, 0xfd, 0x4b, 0x2a, 0xce, 0xf9, 0xe5, 0x76, 0x97, 0x6f, 0x2a, - 0xde, 0xe6, 0x85, 0xd3, 0xa3, 0x9e, 0x23, 0x78, 0x18, 0x6d, 0x0f, 0x97, 0x71, 0x8a, 0x95, 0x4d, - 0x2d, 0xae, 0xcb, 0xbb, 0x7c, 0x5b, 0xb9, 0x4f, 0xf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0x26, 0x80, 0x34, 0x60, - 0x41, 0xdb, 0x5b, 0xa6, 0x98, 0xb9, 0x39, 0xc5, 0x58, 0x88, 0x7c, 0x69, 0x47, 0x52, 0x28, 0xaa, - 0x78, 0xa5, 0xff, 0xcf, 0x0c, 0x7b, 0x04, 0x64, 0x47, 0x30, 0x7b, 0xe3, 0x08, 0xc8, 0x43, 0x00, - 0x75, 0x58, 0x6d, 0x27, 0x14, 0x55, 0x75, 0x81, 0xe7, 0xab, 0xcb, 0xe3, 0xe7, 0xaa, 0x40, 0x5b, - 0x23, 0x66, 0xc2, 0x6a, 0xea, 0x22, 0x4f, 0x09, 0xab, 0x69, 0x61, 0xb5, 0x4c, 0x58, 0xdd, 0x84, - 0xe9, 0x61, 0x75, 0x2d, 0xac, 0x6e, 0x51, 0x58, 0x9a, 0x34, 0x51, 0xb2, 0x08, 0xf3, 0x8f, 0x59, - 0x14, 0xa0, 0x4b, 0x4f, 0x29, 0x7a, 0x95, 0xff, 0x91, 0x07, 0xb0, 0xa2, 0x71, 0x8e, 0x1f, 0x31, - 0x7e, 0xc9, 0x8e, 0x1d, 0x71, 0x1c, 0x09, 0x27, 0x14, 0x15, 0x83, 0xac, 0xc1, 0x7d, 0x1d, 0x7f, - 0xcc, 0xce, 0x53, 0x46, 0x47, 0x31, 0x72, 0xd6, 0xcf, 0x86, 0x7e, 0x20, 0xe4, 0x75, 0xb8, 0xd3, - 0xe0, 0xbe, 0x4f, 0x85, 0xac, 0x6f, 0x24, 0xfe, 0x58, 0x9e, 0x93, 0x20, 0xf2, 0x1e, 0x54, 0xd2, - 0x67, 0x5a, 0xe5, 0x79, 0xc9, 0x47, 0xe6, 0x1f, 0x41, 0xd9, 0x49, 0xe6, 0x6f, 0xbe, 0x4c, 0xbf, - 0xea, 0x95, 0xd7, 0xe4, 0x33, 0x64, 0xa3, 0x87, 0x7e, 0x20, 0xd2, 0xc7, 0xaf, 0x64, 0x6b, 0x9e, - 0x7f, 0xaf, 0xce, 0x3d, 0x30, 0xf5, 0x87, 0x25, 0x7d, 0xcc, 0x9b, 0x8e, 0x70, 0x92, 0x97, 0x64, - 0x2a, 0x9e, 0xed, 0xb1, 0x70, 0x73, 0x8f, 0xdf, 0xeb, 0x3d, 0xd6, 0xe5, 0x57, 0xb8, 0x83, 0x6e, - 0x88, 0x22, 0xfd, 0x0a, 0xc7, 0xd6, 0x7f, 0x37, 0x83, 0x5d, 0x28, 0xb6, 0x79, 0x8f, 0xba, 0x83, - 0x17, 0x7c, 0x78, 0x08, 0x14, 0x3e, 0x72, 0xfc, 0xf8, 0x0d, 0x2b, 0xd9, 0x6a, 0x6d, 0xed, 0xc0, - 0xed, 0x76, 0xcf, 0xa1, 0xec, 0x10, 0x23, 0x91, 0xfc, 0xbd, 0xd9, 0x21, 0xf7, 0xa1, 0x24, 0x41, - 0x81, 0x91, 0xd8, 0x49, 0x1a, 0x1c, 0x39, 0xac, 0x1a, 0xdc, 0x49, 0xce, 0x72, 0x5a, 0x50, 0x75, - 0x3c, 0xa8, 0x6a, 0x6d, 0x40, 0xb9, 0x43, 0xfd, 0xa0, 0x87, 0x1d, 0x11, 0x52, 0xd6, 0x95, 0x55, - 0x36, 0x38, 0x13, 0xc8, 0xd2, 0x13, 0x4c, 0xcd, 0x93, 0xa2, 0xfa, 0xc7, 0x57, 0xfb, 0x3b, 0x00, - 0x00, 0xff, 0xff, 0x32, 0xfe, 0x78, 0x15, 0x71, 0x0a, 0x00, 0x00, + // 1086 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xc4, 0x56, 0xcd, 0x6f, 0x1b, 0x45, + 0x14, 0x67, 0x6d, 0xc7, 0xc9, 0xbe, 0xb8, 0x8e, 0x3b, 0x75, 0xda, 0x55, 0xa8, 0x9a, 0x68, 0x15, + 0xa1, 0x20, 0x11, 0x87, 0x38, 0x6e, 0x54, 0xa2, 0x4a, 0x08, 0xdb, 0x01, 0xac, 0xf2, 0x61, 0xd6, + 0x69, 0x40, 0xaa, 0xda, 0x68, 0xb2, 0x3b, 0x71, 0x46, 0xf1, 0xce, 0xac, 0x76, 0xc7, 0x49, 0x2d, + 0xe0, 0xcc, 0x81, 0x0b, 0x12, 0x67, 0x2e, 0x48, 0xbd, 0x72, 0x44, 0xe2, 0xce, 0xff, 0x11, 0x91, + 0x03, 0x88, 0xff, 0x80, 0x1b, 0x68, 0x66, 0x3f, 0xbc, 0x6b, 0xec, 0xa6, 0x07, 0x24, 0x7c, 0x9a, + 0xf7, 0xde, 0xef, 0xbd, 0x79, 0x1f, 0xbf, 0x79, 0x5e, 0x00, 0x87, 0xdb, 0x41, 0xcd, 0xf3, 0xb9, + 0xe0, 0x48, 0x77, 0xb8, 0x3d, 0x74, 0x09, 0x13, 0xc1, 0xca, 0x6e, 0x9f, 0x8a, 0xd3, 0xe1, 0x71, + 0xcd, 0xe6, 0xee, 0x96, 0x7b, 0x41, 0xc5, 0x19, 0xbf, 0xd8, 0xea, 0xf3, 0x4d, 0x85, 0xdb, 0x3c, + 0xc7, 0x03, 0xea, 0x60, 0xc1, 0xfd, 0x60, 0x2b, 0x39, 0x86, 0x21, 0x56, 0x36, 0x53, 0x7e, 0x7d, + 0xde, 0xe7, 0x5b, 0x4a, 0x7d, 0x3c, 0x3c, 0x51, 0x92, 0x12, 0xd4, 0x29, 0x84, 0x9b, 0xdf, 0x6a, + 0x50, 0xee, 0xd1, 0x3e, 0x23, 0xce, 0x3e, 0x3b, 0x27, 0x03, 0xee, 0x11, 0xb4, 0x0e, 0xba, 0xd4, + 0x60, 0x31, 0xf4, 0x89, 0xa1, 0xad, 0x69, 0x1b, 0xa5, 0x66, 0xf1, 0xea, 0x72, 0x35, 0xe7, 0x55, + 0xad, 0xb1, 0x01, 0xbd, 0x13, 0xa2, 0x88, 0xdf, 0xea, 0xb4, 0x8d, 0xdc, 0x9a, 0xb6, 0xa1, 0x37, + 0x5f, 0xbf, 0xba, 0x5c, 0xbd, 0x03,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b1, 0xc0, + 0xd1, 0x2e, 0x9b, 0x69, 0xcf, 0x76, 0xb9, 0x70, 0xfd, 0xca, 0xfa, 0x21, 0x5d, 0x63, 0x43, 0x7e, + 0x07, 0xf4, 0x88, 0xed, 0x13, 0x11, 0x7f, 0x07, 0x84, 0xd2, 0xff, 0xc6, 0x02, 0x73, 0x17, 0x8a, + 0x5d, 0x3e, 0xa0, 0xf6, 0xe8, 0x25, 0x7f, 0x7d, 0x08, 0x0a, 0x9f, 0x60, 0x37, 0x1e, 0xa0, 0x3a, + 0x9b, 0xdb, 0x70, 0xb3, 0x3b, 0xc0, 0x94, 0x1d, 0x90, 0x40, 0x44, 0x1f, 0x58, 0xdb, 0xe8, 0x2e, + 0xe8, 0xd2, 0x28, 0x48, 0x20, 0xb6, 0xa3, 0x02, 0xc7, 0x0a, 0x73, 0x07, 0x6e, 0x45, 0xbd, 0x9c, + 0xe5, 0x54, 0x9f, 0x74, 0xaa, 0x9b, 0x1b, 0x50, 0xea, 0x51, 0xd7, 0x1b, 0x90, 0x9e, 0xf0, 0x29, + 0xeb, 0xcb, 0x2c, 0x5b, 0x9c, 0x09, 0xc2, 0xe2, 0x0e, 0xc6, 0xe2, 0x71, 0x51, 0x7d, 0x73, 0xee, + 0xfc, 0x13, 0x00, 0x00, 0xff, 0xff, 0x68, 0xf8, 0x5f, 0x01, 0xf3, 0x0a, 0x00, 0x00, } diff --git a/libs/documents/docs.proto b/libs/documents/docs.proto index 509a1b9..c60619f 100644 --- a/libs/documents/docs.proto +++ b/libs/documents/docs.proto @@ -99,6 +99,7 @@ message OrderPart2 { string CommitmentPublicKey = 1; string PreviousOrderCID = 2 [(validator.field) = {regex: "^Q[[:alnum:]]{45}$|^$"}]; int64 Timestamp = 3 [(validator.field) = {int_gt:1564050341,int_lt:32521429541}]; + map<string, string> Extension = 4; } message OrderPart3 { diff --git a/libs/documents/docs.validator.pb.go b/libs/documents/docs.validator.pb.go index c7b2cf8..66a1638 100644 --- a/libs/documents/docs.validator.pb.go +++ b/libs/documents/docs.validator.pb.go @@ -130,6 +130,7 @@ func (this *OrderPart2) Validate() error { if !(this.Timestamp < 32521429541) { return github_com_mwitkow_go_proto_validators.FieldError("Timestamp", fmt.Errorf(`value '%v' must be less than '32521429541'`, this.Timestamp)) } + // Validation of proto3 map<> fields is unsupported. return nil } diff --git a/pkg/api/client.go b/pkg/api/client.go index c3510a3..45ee0d3 100644 --- a/pkg/api/client.go +++ b/pkg/api/client.go @@ -34,9 +34,11 @@ var ( //ClientService - enables service to be mocked type ClientService interface { + BCFulfillOrder(tx *BlockChainTX) (string, error) FulfillOrder(req *FulfillOrderRequest) (*FulfillOrderResponse, error) FulfillOrderSecret(req *FulfillOrderSecretRequest) (*FulfillOrderSecretResponse, error) Status(token string) (*StatusResponse, error) + Dump(tx *BlockChainTX) error } // MilagroClientService - implements Service Interface @@ -113,3 +115,11 @@ func (c MilagroClientService) Status(token string) (*StatusResponse, error) { r := s.(*StatusResponse) return r, nil } + +func (c MilagroClientService) BCFulfillOrder(tx *BlockChainTX) (string, error) { + return "", nil +} + +func (c MilagroClientService) Dump(tx *BlockChainTX) error { + return nil +} diff --git a/pkg/api/proto.go b/pkg/api/proto.go index a4a7eea..d59ffd7 100644 --- a/pkg/api/proto.go +++ b/pkg/api/proto.go @@ -32,12 +32,12 @@ const ( TXOrderRequest = "v1/order1" TXFulfillRequest = "v1/fulfill/order" TXFulfillResponse = "v1/order2" - TXOrderResponse = "NONE" + TXOrderResponse = "dump" TXOrderSecretRequest = "v1/order/secret1" TXFulfillOrderSecretRequest = "v1/fulfill/order/secret" TXFulfillOrderSecretResponse = "v1/order/secret2" - TXOrderSecretResponse = "NONE" + TXOrderSecretResponse = "dump" ) //BlockChainTX - struct for on chain req/resp diff --git a/pkg/bitcoinplugin/service.go b/pkg/bitcoinplugin/service.go index 9c061c5..bab9bac 100644 --- a/pkg/bitcoinplugin/service.go +++ b/pkg/bitcoinplugin/service.go @@ -99,7 +99,7 @@ func (s *Service) PrepareOrderPart1(order *documents.OrderDoc, reqExtension map[ } // PrepareOrderResponse gets the updated order and returns the commitment and extension -func (s *Service) PrepareOrderResponse(orderPart2 *documents.OrderDoc, reqExtension, fulfillExtension map[string]string) (commitment string, extension map[string]string, err error) { +func (s *Service) PrepareOrderResponse(orderPart2 *documents.OrderDoc) (commitment string, extension map[string]string, err error) { pubKeyPart2of2 := orderPart2.OrderPart2.CommitmentPublicKey finalPublicKey, cryptoAddress, err := generateFinalPubKey(s, pubKeyPart2of2, *orderPart2) diff --git a/pkg/common/chain.go b/pkg/common/chain.go new file mode 100644 index 0000000..50d74ca --- /dev/null +++ b/pkg/common/chain.go @@ -0,0 +1,44 @@ +package common + +import ( + "crypto/sha256" + "encoding/hex" + + "github.com/apache/incubator-milagro-dta/libs/datastore" + "github.com/apache/incubator-milagro-dta/libs/documents" + "github.com/pkg/errors" +) + +// CreateTX creates the transaction ready for write to the chain +func CreateTX(nodeID string, store *datastore.Store, id string, order *documents.OrderDoc, recipients map[string]documents.IDDoc) ([]byte, []byte, error) { + secrets := &IdentitySecrets{} + if err := store.Get("id-doc", nodeID, secrets); err != nil { + return nil, nil, errors.New("load secrets from store") + } + blsSecretKey, err := hex.DecodeString(secrets.BLSSecretKey) + if err != nil { + return nil, nil, errors.Wrap(err, "Decode identity secrets") + } + rawDoc, err := documents.EncodeOrderDocument(nodeID, *order, blsSecretKey, "previousID", recipients) + if err != nil { + return nil, nil, errors.Wrap(err, "Failed to encode IDDocument") + } + TXID := sha256.Sum256(rawDoc) + // TXIDhex = hex.EncodeToString(TXID[:]) + //Write order to store + //if err := WriteOrderToStore(store, order.Reference, TXIDhex); err != nil { + // return nil, nil, errors.New("Save Order to store") + // } + return TXID[:], rawDoc, nil +} + +//Decode a transaction for header data but don't decrypt it +func PeekTX(tx []byte) (string, error) { + signerCID, err := documents.OrderDocumentSigner(tx) + print(signerCID) + if err != nil { + return "", errors.Wrap(err, "Error peeking signer") + } + return signerCID, nil + +} diff --git a/pkg/defaultservice/fulfill.go b/pkg/defaultservice/fulfill.go index 6f457c8..0aad725 100644 --- a/pkg/defaultservice/fulfill.go +++ b/pkg/defaultservice/fulfill.go @@ -18,14 +18,101 @@ package defaultservice import ( + "encoding/hex" "encoding/json" + "time" "github.com/apache/incubator-milagro-dta/libs/cryptowallet" + "github.com/apache/incubator-milagro-dta/libs/documents" "github.com/apache/incubator-milagro-dta/pkg/api" "github.com/apache/incubator-milagro-dta/pkg/common" "github.com/apache/incubator-milagro-dta/pkg/tendermint" ) +func (s *Service) BCFulfillOrder(tx *api.BlockChainTX) (string, error) { + + reqPayload := tx.Payload + txHashString := hex.EncodeToString(tx.TXhash) + + //Decode the incoming TX + //Peek inside the TX + //Pull out the header - to get PrincipalID + signerID, err := documents.OrderDocumentSigner(reqPayload) + if err != nil { + return "", err + } + + //orderPart1CID := req.OrderPart1CID + nodeID := s.NodeID() + remoteIDDocCID := signerID + + _, _, _, sikeSK, err := common.RetrieveIdentitySecrets(s.Store, nodeID) + if err != nil { + return "", err + } + + remoteIDDoc, err := common.RetrieveIDDocFromIPFS(s.Ipfs, remoteIDDocCID) + if err != nil { + return "", err + } + + //Retrieve the order from IPFS + order := &documents.OrderDoc{} + err = documents.DecodeOrderDocument(reqPayload, txHashString, order, sikeSK, nodeID, remoteIDDoc.BLSPublicKey) + + // order, err := common.RetrieveOrderFromIPFS(s.Ipfs, orderPart1CID, sikeSK, nodeID, remoteIDDoc.BLSPublicKey) + if err != nil { + return "", err + } + + recipientList, err := common.BuildRecipientList(s.Ipfs, order.PrincipalCID, nodeID) + if err != nil { + return "", err + } + + //Generate the secret and store for later redemption + seed, err := common.MakeRandomSeedAndStore(s.Store, s.Rng, order.Reference) + if err != nil { + return "", err + } + + //Generate the Public Key (Commitment) from the Seed/Secret + commitmentPublicKey, err := cryptowallet.RedeemPublicKey(seed) + if err != nil { + return "", err + } + + //Create an order part 2 + Part2 := documents.OrderPart2{ + CommitmentPublicKey: commitmentPublicKey, + PreviousOrderCID: txHashString, + Timestamp: time.Now().Unix(), + } + order.OrderPart2 = &Part2 + + txHash, payload, err := common.CreateTX(nodeID, s.Store, nodeID, order, recipientList) + //_ = txHashID + + // orderPart2CID, err := common.CreateAndStoreOrderPart2(s.Ipfs, s.Store, order, orderPart1CID, commitmentPublicKey, nodeID, recipientList) + // if err != nil { + // return "", err + // } + + //marshaledRequest, _ := json.Marshal(response) + + //Write the requests to the chain + chainTX := &api.BlockChainTX{ + Processor: api.TXFulfillResponse, + SenderID: nodeID, + RecipientID: []string{order.PrincipalCID, nodeID}, + Payload: payload, + TXhash: txHash, + Tags: map[string]string{"reference": order.Reference}, + } + return tendermint.PostToChain(chainTX, "FulfillOrder") + +} + // FulfillOrder - func (s *Service) FulfillOrder(req *api.FulfillOrderRequest) (string, error) { orderPart1CID := req.OrderPart1CID diff --git a/pkg/defaultservice/order.go b/pkg/defaultservice/order.go index 778189d..f89a08b 100644 --- a/pkg/defaultservice/order.go +++ b/pkg/defaultservice/order.go @@ -18,8 +18,8 @@ package defaultservice import ( + "encoding/hex" "encoding/json" - "time" "github.com/apache/incubator-milagro-dta/libs/cryptowallet" "github.com/apache/incubator-milagro-dta/libs/documents" @@ -152,21 +152,25 @@ func (s *Service) Order1(req *api.OrderRequest) (string, error) { return "", err } - //Fullfill the order on the remote Server request := &api.FulfillOrderRequest{ DocumentCID: nodeID, OrderPart1CID: orderPart1CID, Extension: fulfillExtension, } + //This is serialized and output to the chain + txHash, payload, err := common.CreateTX(nodeID, s.Store, nodeID, order, recipientList) + marshaledRequest, _ := json.Marshal(request) + _ = marshaledRequest //Write the requests to the chain chainTX := &api.BlockChainTX{ Processor: api.TXFulfillRequest, SenderID: nodeID, RecipientID: []string{s.MasterFiduciaryNodeID(), nodeID}, - Payload: marshaledRequest, + Payload: payload, //marshaledRequest, + TXhash: txHash, Tags: map[string]string{"reference": order.Reference}, } tendermint.PostToChain(chainTX, "Order1") @@ -174,8 +178,10 @@ func (s *Service) Order1(req *api.OrderRequest) (string, error) { } // Order2 - -func (s *Service) Order2(req *api.FulfillOrderResponse) (string, error) { +func (s *Service) Order2(tx *api.BlockChainTX) (string, error) { nodeID := s.NodeID() + reqPayload := tx.Payload + txHashString := hex.EncodeToString(tx.TXhash) remoteIDDoc, err := common.RetrieveIDDocFromIPFS(s.Ipfs, s.MasterFiduciaryNodeID()) if err != nil { @@ -187,39 +193,59 @@ func (s *Service) Order2(req *api.FulfillOrderResponse) (string, error) { if err != nil { return "", err } - updatedOrder, err := common.RetrieveOrderFromIPFS(s.Ipfs, req.OrderPart2CID, sikeSK, nodeID, remoteIDDoc.BLSPublicKey) - if err != nil { - return "", errors.Wrap(err, "Fail to retrieve Order from IPFS") - } + + order := &documents.OrderDoc{} + err = documents.DecodeOrderDocument(reqPayload, txHashString, order, sikeSK, nodeID, remoteIDDoc.BLSPublicKey) + + // updatedOrder, err := common.RetrieveOrderFromIPFS(s.Ipfs, req.OrderPart2CID, sikeSK, nodeID, remoteIDDoc.BLSPublicKey) + // if err != nil { + // return "", errors.Wrap(err, "Fail to retrieve Order from IPFS") + // } //update OrderPartCID for order id - commitment, extension, err := s.Plugin.PrepareOrderResponse(updatedOrder, req.Extension, req.Extension) + commitment, extension, err := s.Plugin.PrepareOrderResponse(order) if err != nil { return "", errors.Wrap(err, "Generating Final Public Key") } - err = common.WriteOrderToStore(s.Store, updatedOrder.Reference, req.OrderPart2CID) - if err != nil { - return "", errors.Wrap(err, "Saving new CID to Order reference") + order.OrderPart2.CommitmentPublicKey = commitment + + //Populate Extension + + if order.OrderPart2.Extension == nil { + order.OrderPart2.Extension = make(map[string]string) } + for key, value := range extension { - response := &api.OrderResponse{ - OrderReference: updatedOrder.Reference, - Commitment: commitment, - CreatedAt: time.Now().Unix(), - Extension: extension, + order.OrderPart2.Extension[key] = value } - marshaledRequest, _ := json.Marshal(response) + // err = common.WriteOrderToStore(s.Store, order.Reference, req.OrderPart2CID) + // if err != nil { + // return "", errors.Wrap(err, "Saving new CID to Order reference") + // } - //Write the requests to the chain + // response := &api.OrderResponse{ + // OrderReference: order.Reference, + // Commitment: commitment, + // CreatedAt: time.Now().Unix(), + // Extension: extension, + // } + recipientList, err := common.BuildRecipientList(s.Ipfs, nodeID, nodeID) + if err != nil { + return "", err + } + txHash, payload, err := common.CreateTX(nodeID, s.Store, nodeID, order, recipientList) + + //Write the Order2 results to the chain chainTX := &api.BlockChainTX{ - Processor: api.TXOrderSecretResponse, - SenderID: "", - RecipientID: []string{s.MasterFiduciaryNodeID(), nodeID}, - Payload: marshaledRequest, - Tags: map[string]string{"reference": updatedOrder.Reference}, + Processor: api.TXOrderResponse, + SenderID: "", //use no Sender so we can read our own Result for testing + RecipientID: []string{nodeID}, + Payload: payload, + TXhash: txHash, + Tags: map[string]string{"reference": order.Reference}, } return tendermint.PostToChain(chainTX, "Order2") diff --git a/pkg/defaultservice/plugable.go b/pkg/defaultservice/plugable.go index 9d49163..8fdfd34 100644 --- a/pkg/defaultservice/plugable.go +++ b/pkg/defaultservice/plugable.go @@ -32,7 +32,7 @@ type Plugable interface { ValidateOrderRequest(req *api.OrderRequest) error ValidateOrderSecretRequest(req *api.OrderSecretRequest, order documents.OrderDoc) error PrepareOrderPart1(order *documents.OrderDoc, reqExtension map[string]string) (fulfillExtension map[string]string, err error) - PrepareOrderResponse(orderPart2 *documents.OrderDoc, reqExtension, fulfillExtension map[string]string) (commitment string, extension map[string]string, err error) + PrepareOrderResponse(orderPart2 *documents.OrderDoc) (commitment string, extension map[string]string, err error) ProduceBeneficiaryEncryptedData(blsSK []byte, order *documents.OrderDoc, req *api.OrderSecretRequest) (encrypted []byte, extension map[string]string, err error) ProduceFinalSecret(seed, sikeSK []byte, order, orderPart4 *documents.OrderDoc, beneficiaryCID string) (secret, commitment string, extension map[string]string, err error) } diff --git a/pkg/defaultservice/service.go b/pkg/defaultservice/service.go index 0c4c671..9d1bc4f 100644 --- a/pkg/defaultservice/service.go +++ b/pkg/defaultservice/service.go @@ -21,14 +21,19 @@ Package defaultservice - Service that Milagro D-TA provides with no-plugins package defaultservice import ( + "encoding/hex" + "fmt" "io" "time" "github.com/apache/incubator-milagro-dta/libs/datastore" + "github.com/apache/incubator-milagro-dta/libs/documents" "github.com/apache/incubator-milagro-dta/libs/ipfs" "github.com/apache/incubator-milagro-dta/libs/logger" "github.com/apache/incubator-milagro-dta/pkg/api" + "github.com/apache/incubator-milagro-dta/pkg/common" "github.com/apache/incubator-milagro-dta/pkg/config" + "github.com/hokaccha/go-prettyjson" ) var ( @@ -112,3 +117,26 @@ func (s *Service) Status(apiVersion, nodeType string) (*api.StatusResponse, erro Plugin: s.Plugin.Name(), }, nil } + +func (s *Service) Dump(tx *api.BlockChainTX) error { + nodeID := s.NodeID() + txHashString := hex.EncodeToString(tx.TXhash) + + localIDDoc, err := common.RetrieveIDDocFromIPFS(s.Ipfs, nodeID) + if err != nil { + return err + } + + _, _, _, sikeSK, err := common.RetrieveIdentitySecrets(s.Store, nodeID) + if err != nil { + return err + } + + order := &documents.OrderDoc{} + err = documents.DecodeOrderDocument(tx.Payload, txHashString, order, sikeSK, nodeID, localIDDoc.BLSPublicKey) + + pp, _ := prettyjson.Marshal(order) + fmt.Println(string(pp)) + + return nil +} diff --git a/pkg/endpoints/endpoints.go b/pkg/endpoints/endpoints.go index 11c246b..eb9a385 100644 --- a/pkg/endpoints/endpoints.go +++ b/pkg/endpoints/endpoints.go @@ -340,16 +340,17 @@ func MakeOrder1Endpoint(m service.Service) endpoint.Endpoint { //MakeOrder2Endpoint - func MakeOrder2Endpoint(m service.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (response interface{}, err error) { - req, ok := request.(*api.FulfillOrderResponse) - if !ok { - return nil, transport.ErrInvalidRequest - } - if err := validateRequest(req); err != nil { - return "", err - } - return m.Order2(req) - } + // return func(ctx context.Context, request interface{}) (response interface{}, err error) { + // req, ok := request.(*api.FulfillOrderResponse) + // if !ok { + // return nil, transport.ErrInvalidRequest + // } + // if err := validateRequest(req); err != nil { + // return "", err + // } + // return m.Order2(req) + // } + return nil } //MakeOrderSecret1Endpoint - diff --git a/pkg/safeguardsecret/service.go b/pkg/safeguardsecret/service.go index f8c7a84..43f3e09 100644 --- a/pkg/safeguardsecret/service.go +++ b/pkg/safeguardsecret/service.go @@ -54,9 +54,10 @@ func (s *Service) Vendor() string { } // PrepareOrderResponse gets the updated order and returns the commitment and extension -func (s *Service) PrepareOrderResponse(orderPart2 *documents.OrderDoc, reqExtension, fulfillExtension map[string]string) (commitment string, extension map[string]string, err error) { - finalPublicKey := orderPart2.OrderPart2.CommitmentPublicKey - c, v, t, err := crypto.Secp256k1Encrypt(reqExtension["plainText"], finalPublicKey) +func (s *Service) PrepareOrderResponse(order *documents.OrderDoc) (commitment string, extension map[string]string, err error) { + finalPublicKey := order.OrderPart2.CommitmentPublicKey + plainText := order.OrderPart2.Extension["plainText"] + c, v, t, err := crypto.Secp256k1Encrypt(plainText, finalPublicKey) return finalPublicKey, map[string]string{"cypherText": c, "v": v, "t": t}, nil } diff --git a/pkg/service/service.go b/pkg/service/service.go index 7dbb7c6..c585584 100644 --- a/pkg/service/service.go +++ b/pkg/service/service.go @@ -38,9 +38,10 @@ type Service interface { OrderSecret2(req *api.FulfillOrderSecretResponse) (string, error) Order1(req *api.OrderRequest) (string, error) - Order2(req *api.FulfillOrderResponse) (string, error) + Order2(tx *api.BlockChainTX) (string, error) //Fullfill processing + BCFulfillOrder(tx *api.BlockChainTX) (string, error) FulfillOrder(req *api.FulfillOrderRequest) (string, error) FulfillOrderSecret(req *api.FulfillOrderSecretRequest) (string, error) @@ -50,5 +51,6 @@ type Service interface { SetMasterFiduciaryNodeID(masterFiduciaryNodeID string) //System + Dump(tx *api.BlockChainTX) error //Decrypt and dump the order Status(apiVersion, nopdeType string) (*api.StatusResponse, error) } diff --git a/pkg/tendermint/tendermint.go b/pkg/tendermint/tendermint.go index 1e46497..846c13f 100644 --- a/pkg/tendermint/tendermint.go +++ b/pkg/tendermint/tendermint.go @@ -12,8 +12,8 @@ import ( "os" "strings" - "github.com/TylerBrock/colorjson" "github.com/apache/incubator-milagro-dta/pkg/api" + "github.com/apache/incubator-milagro-dta/pkg/service" ) //QueryChain the blockchain for an index @@ -80,7 +80,7 @@ func HandleChainTX(myID string, tx string) error { return err } panic(nil) - err = callNextTX(blockChainTX, "5556") + err = callNextTX(nil, blockChainTX, "5556") if err != nil { return err } @@ -114,7 +114,7 @@ func decodeTX(payload string) (*api.BlockChainTX, string, error) { return tx, hash, nil } -func callNextTX(tx *api.BlockChainTX, listenPort string) error { +func callNextTX(svc service.Service, tx *api.BlockChainTX, listenPort string) error { // recipient := tx.RecipientID // sender := tx.SenderID //payloadJSON := tx.Payload @@ -125,6 +125,19 @@ func callNextTX(tx *api.BlockChainTX, listenPort string) error { return nil } + if tx.Processor == "dump" { + svc.Dump(tx) + return nil + } + if tx.Processor == "v1/fulfill/order" { + svc.BCFulfillOrder(tx) + return nil + } + if tx.Processor == "v1/order2" { + svc.Order2(tx) + return nil + } + desintationURL := fmt.Sprintf("http://localhost"+listenPort+"/%s", tx.Processor) body := strings.NewReader(payloadString) @@ -150,21 +163,6 @@ func callNextTX(tx *api.BlockChainTX, listenPort string) error { return nil } -//DumpTX - Decode the Payload into JSON and displays the entire Blockchain TX unencoded -func DumpTX(bctx *api.BlockChainTX) { - f := colorjson.NewFormatter() - f.Indent = 4 - var payloadObj map[string]interface{} - payload := bctx.Payload - json.Unmarshal([]byte(payload), &payloadObj) - jsonstring, _ := json.Marshal(bctx) - var obj map[string]interface{} - json.Unmarshal([]byte(jsonstring), &obj) - obj["Payload"] = payloadObj - s, _ := f.Marshal(obj) - fmt.Println(string(s)) -} - //DumpTXID - func DumpTXID(txid string) { value, raw := QueryChain(txid) diff --git a/pkg/tendermint/websockets.go b/pkg/tendermint/websockets.go index cb724f1..a17f192 100644 --- a/pkg/tendermint/websockets.go +++ b/pkg/tendermint/websockets.go @@ -13,6 +13,7 @@ import ( "github.com/apache/incubator-milagro-dta/libs/datastore" "github.com/apache/incubator-milagro-dta/libs/logger" "github.com/apache/incubator-milagro-dta/pkg/api" + "github.com/apache/incubator-milagro-dta/pkg/service" status "github.com/apache/incubator-milagro-dta/pkg/tendermint/status" "github.com/pkg/errors" tmclient "github.com/tendermint/tendermint/rpc/client" @@ -160,23 +161,20 @@ func parseHistory(txHistory []ctypes.ResultTx) { print("Finished loading - but not parsing the History\n") } -func processTXQueue(queue chan api.BlockChainTX, listenPort string) { +func processTXQueue(svc service.Service, queue chan api.BlockChainTX, listenPort string) { print("Processing queue\n") for payload := range queue { //blockchainTX, txid, err := decodeTX(string(tx)) //TXIDhex := hex.EncodeToString(payload.TXhash[:]) // logger.Info("Incoming TXHash:%s . Processor:%s", TXIDhex, payload.Processor) - if payload.Processor == "NONE" { - DumpTX(&payload) - } else { - callNextTX(&payload, listenPort) - } + callNextTX(svc, &payload, listenPort) } + print("Finished processing queue") } //Subscribe - Connect to the Tendermint websocket to collect events -func Subscribe(store *datastore.Store, logger *logger.Logger, nodeID string, listenPort string) error { +func Subscribe(svc service.Service, store *datastore.Store, logger *logger.Logger, nodeID string, listenPort string) error { //Subscribe to channel //Get height @@ -200,7 +198,7 @@ func Subscribe(store *datastore.Store, logger *logger.Logger, nodeID string, lis loadAllHistoricTX(processedToHeight, currentBlockHeight, txHistory, nodeID, listenPort) - processTXQueue(queueWaiting, listenPort) + processTXQueue(svc, queueWaiting, listenPort) // var height int // store.Get("chain", "height", &height)
