Skip to content

Commit

Permalink
feat(core-api): add weaver protocol buffer definitions #1523
Browse files Browse the repository at this point in the history
Adding the .proto definitions from here as discussed earlier with @VRamakrishna

To-do: I skipped the fabric driver proto due to an error on account of the
Fabric peer definitions not being present (unresolved import error).

Fixes #1523

Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
  • Loading branch information
petermetz committed Nov 17, 2021
1 parent 10344b5 commit 716b804
Show file tree
Hide file tree
Showing 31 changed files with 3,566 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
"karma-webpack": "5.0.0",
"lerna": "4.0.0",
"lint-staged": "11.1.2",
"make-dir-cli": "3.0.0",
"node-polyfill-webpack-plugin": "1.1.4",
"npm-run-all": "4.1.5",
"npm-watch": "0.11.0",
Expand Down
6 changes: 6 additions & 0 deletions packages/cactus-core-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
"scripts": {
"generate-sdk": "openapi-generator-cli generate -i ./src/main/json/openapi.json -g typescript-axios -o ./src/main/typescript/generated/openapi/typescript-axios/ --reserved-words-mappings protected=protected",
"codegen:openapi": "npm run generate-sdk",
"preproto:protoc-gen-ts": "make-dir ./src/main/typescript/generated/proto/protoc-gen-ts/weaver/common/protos/",
"proto:protoc-gen-ts": "yarn run grpc_tools_node_protoc --plugin=protoc-gen-ts=../../node_modules/.bin/protoc-gen-ts --ts_out=grpc_js:./src/main/typescript/generated/proto/protoc-gen-ts/weaver/common/protos/ --proto_path ./src/main/proto/weaver/common/protos/ ./src/main/proto/weaver/common/protos/common/*.proto ./src/main/proto/weaver/common/protos/corda/*.proto ./src/main/proto/weaver/common/protos/driver/*.proto ./src/main/proto/weaver/common/protos/networks/*.proto ./src/main/proto/weaver/common/protos/relay/*.proto",
"codegen:proto": "run-s proto:protoc-gen-ts",
"codegen": "run-p 'codegen:*'",
"watch": "npm-watch",
"webpack": "npm-run-all webpack:dev",
Expand Down Expand Up @@ -69,7 +72,10 @@
},
"homepage": "https://github.com/hyperledger/cactus#readme",
"devDependencies": {
"@grpc/grpc-js": "1.3.6",
"@grpc/proto-loader": "0.6.4",
"@types/express": "4.17.13",
"make-dir-cli": "3.0.0",
"socket.io": "4.1.3",
"typescript-optional": "2.0.1"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!--
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: CC-BY-4.0
-->
## protos

This repository contains the grpc service and protocol buffer definitions for the relay, drivers and other interop modules. protos
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
syntax = "proto3";

package common.access_control;

option java_package = "com.weaver.protos.common.access_control";
option go_package = "github.com/hyperledger-labs/weaver-dlt-interoperability/common/protos-go/common";

// AccessControlPolicy specifies a set of data that can be accessed by some
// SecurityGroup
message AccessControlPolicy {
string securityDomain = 1;
repeated Rule rules = 2;
}

// Rule represents a single data access rule for the AccessControlPolicy
message Rule {
string principal = 1;
string principalType = 2;
string resource = 3;
bool read = 4;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
syntax = "proto3";

package common.ack;

option java_package = "com.weaver.protos.common.ack";
option go_package = "github.com/hyperledger-labs/weaver-dlt-interoperability/common/protos-go/common";

// This message respresents "ACKs" sent between relay-relay,
// relay-driver and relay-network
message Ack {
enum STATUS {
OK = 0;
ERROR = 1;
};
STATUS status = 2;
string request_id = 3;
// an error can have an associated string
// this is the best way to represent this in protobuf
string message = 4;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
syntax = "proto3";

package common.asset_locks;

option java_package = "com.weaver.protos.common.asset_locks";
option go_package = "github.com/hyperledger-labs/weaver-dlt-interoperability/common/protos-go/common";

enum LockMechanism {
HTLC = 0;
}

message AssetLock {
LockMechanism lockMechanism = 1;
bytes lockInfo = 2;
}

message AssetClaim {
LockMechanism lockMechanism = 1;
bytes claimInfo = 2;
}

message AssetLockHTLC {
bytes hashBase64 = 1;
uint64 expiryTimeSecs = 2;
enum TimeSpec {
EPOCH = 0;
DURATION = 1;
}
TimeSpec timeSpec = 3;
}

message AssetClaimHTLC {
bytes hashPreimageBase64 = 1;
}

message AssetExchangeAgreement {
string type = 1;
string id = 2;
string locker = 3;
string recipient = 4;
}

message FungibleAssetExchangeAgreement {
string type = 1;
uint64 numUnits = 2;
string locker = 3;
string recipient = 4;
}

message AssetContractHTLC {
string contractId = 1;
AssetExchangeAgreement agreement = 2;
AssetLockHTLC lock = 3;
AssetClaimHTLC claim = 4;
}

message FungibleAssetContractHTLC {
string contractId = 1;
FungibleAssetExchangeAgreement agreement = 2;
AssetLockHTLC lock = 3;
AssetClaimHTLC claim = 4;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
syntax = "proto3";

package common.interop_payload;

option java_package = "com.weaver.protos.common.interop_payload";
option go_package = "github.com/hyperledger-labs/weaver-dlt-interoperability/common/protos-go/common";

message InteropPayload {
bytes payload = 1;
string address = 2;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
syntax = "proto3";

package common.membership;

option java_package = "com.weaver.protos.common.membership";
option go_package = "github.com/hyperledger-labs/weaver-dlt-interoperability/common/protos-go/common";

// Membership captures the members of an external entity such as a thing,
// person, organization or groups of entities such as networks
message Membership {
string securityDomain = 1;
map<string, Member> members = 2;
}

// Member of a security group is represented by a set of public keys,
// certificates or certificate authorities
message Member {
string value = 1;
string type = 2;
repeated string chain = 3;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
syntax = "proto3";

package common.proofs;
option java_package = "com.weaver.protos.common.proofs";
option go_package = "github.com/hyperledger-labs/weaver-dlt-interoperability/common/protos-go/common";

message Proof {
string signature = 1;
string certificate = 2;
}

message Proofs { repeated Proof proofs = 1; }
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
syntax = "proto3";

package common.query;
option java_package = "com.weaver.protos.common.query";
option go_package = "github.com/hyperledger-labs/weaver-dlt-interoperability/common/protos-go/common";

// the payload to define the data that is being requested
message Query {
repeated string policy = 1;
string address = 2;
string requesting_relay = 3;
string requesting_network = 4;
string certificate = 5;
string requestor_signature = 6;
string nonce = 7;
string request_id = 8;
string requesting_org = 9;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
syntax = "proto3";

package common.state;
option java_package = "com.weaver.protos.common.state";
option go_package = "github.com/hyperledger-labs/weaver-dlt-interoperability/common/protos-go/common";

// Metadata for a View
message Meta {
enum Protocol {
BITCOIN = 0;
ETHEREUM = 1;
FABRIC = 3;
CORDA = 4;
}
// Underlying distributed ledger protocol.
Protocol protocol = 1;
// What notion of time?
// If the observer and network are synchronizing on a global clock
// there won't be a need to distinguish between static and dynamic views.
string timestamp = 2;
// Notorization, SPV, ZKP, etc. Possibly enum
string proof_type = 3;
// The data field's serialization format (e.g. JSON, XML, Protobuf)
string serialization_format = 4;
}

message View {
Meta meta = 1;
// Represents the data playload of this view.
// The representation of Fabric, Corda etc will be captured elsewhere.
// For some protocols, like Bitcoin, the structure of an SPV proof is well known.
bytes data = 2;
}

// View represents the response from a remote network
message ViewPayload {
string request_id = 1;
oneof state {
View view = 2;
string error = 3;
};
}

// the payload that is used for the communication between the requesting relay
// and its network
message RequestState {
enum STATUS {
// pending ACK from remote relay
PENDING_ACK = 0;
// Received ACK, waiting for data to be sent from remote relay
PENDING = 1;
ERROR = 2;
COMPLETED = 3;
};
string request_id = 1;
STATUS status = 2;
oneof state {
View view = 3;
string error = 4;
};
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
syntax = "proto3";

package common.verification_policy;

option java_package = "com.weaver.protos.common.verification_policy";
option go_package = "github.com/hyperledger-labs/weaver-dlt-interoperability/common/protos-go/common";

// VerificationPolicy stores the rules around which parties from a foreign
// network need to provide proof of a view in order for it to be deemed valid by
// the Fabric network
message VerificationPolicy {
string securityDomain = 1;
repeated Identifier identifiers = 2;
}

// The Policy captures the list of parties that are required to provide proofs
// of a view in order for the Fabric network to accept the view as valid.
message Policy {
string type = 1;
repeated string criteria = 2;
}

// List of identifiers for the VerificationPolicy
message Identifier {
// pattern defines the view/views that this rule applies to
// A rule may contain a "*" at the end of the pattern
string pattern = 1;
Policy policy = 2;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
syntax = "proto3";

package corda;

option java_package = "com.weaver.protos.corda";
option go_package = "github.com/hyperledger-labs/weaver-dlt-interoperability/common/protos-go/corda";

message ViewData {
message Notarization {
string signature = 1;
string certificate = 2;
string id = 3;
}
repeated Notarization notarizations = 1;
// Bytes of InteropPayload
bytes payload = 2;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
syntax = "proto3";

package driver.driver;

import "common/ack.proto";
import "common/query.proto";

option java_package = "com.weaver.protos.driver.driver";
option go_package = "github.com/hyperledger-labs/weaver-dlt-interoperability/common/protos-go/driver";

service DriverCommunication {
// the remote relay sends a RequestDriverState request to its driver with a
// query defining the data it wants to receive
rpc RequestDriverState(common.query.Query) returns (common.ack.Ack) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
syntax = "proto3";

package fabric.view_data;

option java_package = "com.weaver.protos.fabric.view_data";
option go_package = "github.com/hyperledger-labs/weaver-dlt-interoperability/common/protos-go/fabric";

import "peer/proposal_response.proto";

message FabricView {
// `Response` from the peers
// https://github.com/hyperledger/fabric-protos-go/blob/main/peer/proposal_response.pb.go#L113
// We only need the `Payload` field though.
protos.Response response = 1;
// `ProposalResponsePayload` is the output produced by each peer and signed as a serialized blob
// https://github.com/hyperledger/fabric-protos-go/blob/main/peer/proposal_response.pb.go#L176
// `ProposalResponsePayload` contains an `Extension` field which is of type `ChaincodeAction`
// https://github.com/hyperledger/fabric-protos-go/blob/main/peer/proposal.pb.go#L280
// We only need the `ProposalHash`, `ChaincodeId` and `Response` fields.
protos.ProposalResponsePayload proposal_response_payload = 3;
// Each `Endorsement` is an identity coupled with a signature
// https://github.com/hyperledger/fabric-protos-go/blob/main/peer/proposal_response.pb.go#L242
repeated protos.Endorsement endorsements = 4;
}
Loading

0 comments on commit 716b804

Please sign in to comment.