This is an automated email from the ASF dual-hosted git repository. cmorris pushed a commit to branch policy in repository https://gitbox.apache.org/repos/asf/incubator-milagro-dta.git
commit 67702758a11307f9aa5d6d7f1444679f9f308143 Author: Christopher Morris <[email protected]> AuthorDate: Wed Aug 28 11:29:05 2019 +0100 Add policy to order --- cmd/servicetester/e2e_test.sh | 5 ++-- libs/documents/docs.proto | 1 + pkg/api/proto.go | 56 +++++++++++++++++++++++++++++++++++++++++++ pkg/common/common.go | 3 ++- pkg/defaultservice/order.go | 3 ++- 5 files changed, 64 insertions(+), 4 deletions(-) diff --git a/cmd/servicetester/e2e_test.sh b/cmd/servicetester/e2e_test.sh index 1b3588c..d3dbbce 100755 --- a/cmd/servicetester/e2e_test.sh +++ b/cmd/servicetester/e2e_test.sh @@ -2,6 +2,7 @@ #End to End Test of Services using curl/bash apiVersion="v1" +simplePolicy='{"policy":{ "example":"single fiduciary","walletRef": "CD-2367-227","beneficiarydocid":"","nodeId": "123","coin": 0,"sharingGroups": [{"groupref": "Back Office Team","threshold":1,"ids": [{"id": "alice","idType": "oidc","idRef": "Alice"}]}],"participantCount": 7}}' status () { #Determine if an extension is running @@ -22,7 +23,7 @@ status () { execute_bitcoin () { #Run 2 Tests against the Bitcoin Extension echo "Bitcoin Plugin Tests [2 Tests]" - output1=$(curl -s -X POST "http://localhost:5556/$apiVersion/order" -H "accept: */*" -H "Content-Type: application/json" -d "{\"beneficiaryIDDocumentCID\":\"\",\"extension\":{\"coin\":\"0\"}}") + output1=$(curl -s -X POST "http://localhost:5556/$apiVersion/order" -H "accept: */*" -H "Content-Type: application/json" -d "{\"policy\":$simplePolicy,\"beneficiaryIDDocumentCID\":\"\",\"extension\":{\"coin\":\"0\"}}") echo $output1 op1=$(echo $output1 | jq .orderReference) commitment1=$(echo $output1 | jq .commitment) @@ -108,7 +109,7 @@ execute_safeguardsecret () { execute_milagro () { echo "Milagro Tests [1 Test]" output1=$(curl -s -X POST "http://localhost:5556/$apiVersion/order" -H "accept: */*" -H "Content-Type: application/json" -d "{\"beneficiaryIDDocumentCID\":$identity}") - echo $output1 + echo $output1 op1=$(echo $output1 | jq .orderReference) diff --git a/libs/documents/docs.proto b/libs/documents/docs.proto index f57e42d..06ae5be 100644 --- a/libs/documents/docs.proto +++ b/libs/documents/docs.proto @@ -167,3 +167,4 @@ message SimpleString { // rtn = decodeEnv(char* encapsulationVersion, char* encapsulatedKey, char* SIKEprivKey) // rtn = sign( char* BLSsk, char* signature) // rtn = verify(char* signature, char* message) + diff --git a/pkg/api/proto.go b/pkg/api/proto.go index 866911d..52ed9bf 100644 --- a/pkg/api/proto.go +++ b/pkg/api/proto.go @@ -76,6 +76,7 @@ type IdentityListResponse struct { type OrderRequest struct { // BeneficiaryIDDocumentCID string `json:"BeneficiaryIDDocumentCID,omitempty" validate:"omitempty,IPFS"` BeneficiaryIDDocumentCID string `json:"beneficiaryIDDocumentCID,omitempty"` + Policy Policy `json:"Policy,omitempty"` Extension map[string]string `json:"extension,omitempty"` } @@ -168,3 +169,58 @@ type StatusResponse struct { Extension map[string]string `json:"extension,omitempty"` Plugin string `json:"plugin,omitempty"` } + +//Policy - JSON polciy definition +type Policy struct { + // WalletRef is the customer ref ID for the wallet + WalletRef string `json:"walletRef"` + // NodeID as provided by the customer registration + NodeID string `json:"nodeId"` + // coinType is the coin type + // 0 - Bitcoin + // 1 - Bitcoin test + CoinType int `json:"coin"` + // Sharing groups. Each group defines a list of identities. + // The leader and the node are added automatically. + SharingGroups []SharingGroup `json:"sharingGroups"` + // The number of participants + ParticipantCount uint `json:"participantCount"` + // The required number of signatures + Threshold uint `json:"threshold"` + // Slice that points to signer's keys + Signers []uint `json:"signers"` + //Public Address for deposit + PublicAddress string `json:"publicaddress"` + //The beneficiary who is able to spend + BeneficiaryDocID string `json:"beneficiarydocid"` + //TimeStamps + CreatedAt time.Time `json:"createdAt"` + UpdatedAt time.Time `json:"updatedAt"` +} + +// SharingGroup defines a list of identities that will hold +// the secret after split +type SharingGroup struct { + GroupID int `json:"groupId"` + GroupRef string `json:"groupref"` + IDs []Identity `json:"ids"` + Threshold int `json:"threshold"` + //Temporary store of pSig during withdrawal + Signature []byte `json:"signature,omitempty"` + TimeStamp time.Time `json:"timeStamp"` + Status string `json:"status"` +} + +// Identity of a sharing group +type Identity struct { + // ID is a verifiable identity of IDType + ID string `json:"id"` + // IDRef is the identity reference + IDRef string `json:"idRef"` + // IDType is the identity type, e.g. "phone" + IDType string `json:"idType"` + //Temporary store of vss shares during withdrawal + Share []byte `json:"share,omitempty"` + Status string `json:"status"` + TimeStamp time.Time `json:"timeStamp"` +} diff --git a/pkg/common/common.go b/pkg/common/common.go index b8b6b0c..3105cf8 100644 --- a/pkg/common/common.go +++ b/pkg/common/common.go @@ -31,6 +31,7 @@ import ( "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/pkg/api" "github.com/google/uuid" "github.com/pkg/errors" ) @@ -46,7 +47,7 @@ type IdentitySecrets struct { } // CreateNewDepositOrder - Generate an empty new Deposit Order with random reference -func CreateNewDepositOrder(BeneficiaryIDDocumentCID string, nodeID string) (*documents.OrderDoc, error) { +func CreateNewDepositOrder(BeneficiaryIDDocumentCID string, nodeID string, policy api.Policy) (*documents.OrderDoc, error) { //Create a reference for this order reference, err := uuid.NewUUID() if err != nil { diff --git a/pkg/defaultservice/order.go b/pkg/defaultservice/order.go index c88e0ab..8e3fb7a 100644 --- a/pkg/defaultservice/order.go +++ b/pkg/defaultservice/order.go @@ -93,6 +93,7 @@ func (s *Service) Order(req *api.OrderRequest) (*api.OrderResponse, error) { //Initialise values from Request object beneficiaryIDDocumentCID := req.BeneficiaryIDDocumentCID + policy := req.Policy iDDocID := s.NodeID() recipientList, err := common.BuildRecipientList(s.Ipfs, iDDocID, s.MasterFiduciaryNodeID()) if err != nil { @@ -105,7 +106,7 @@ func (s *Service) Order(req *api.OrderRequest) (*api.OrderResponse, error) { } //Create Order - order, err := common.CreateNewDepositOrder(beneficiaryIDDocumentCID, iDDocID) + order, err := common.CreateNewDepositOrder(beneficiaryIDDocumentCID, iDDocID, policy) if err != nil { return nil, err }
