Skip to content

Commit

Permalink
feat(satp-hermes): fabric and besu bridges
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Amaro <[email protected]>
  • Loading branch information
LordKubaya committed Jul 4, 2024
1 parent b818aa8 commit ae970fe
Show file tree
Hide file tree
Showing 90 changed files with 197,484 additions and 13,234 deletions.
124,951 changes: 124,951 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
"PrivacyPolicyOpts":{
"description": "identifier of the policy used to process a view",
"type": "string",
"enum": ["pruneState"],
"x-enum-varnames":["PruneState"]
"enum": ["pruneState", "singleTransaction"],
"x-enum-varnames":["PruneState", "SingleTransaction"]
},
"MergePolicyOpts":{
"description": "identifier of the policy used to merge views (can be none)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ export interface MergeViewsResponse {
*/

export const PrivacyPolicyOpts = {
PruneState: 'pruneState'
PruneState: 'pruneState',
SingleTransaction: 'singleTransaction'
} as const;

export type PrivacyPolicyOpts = typeof PrivacyPolicyOpts[keyof typeof PrivacyPolicyOpts];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,24 @@ export class PrivacyPolicies {
return view;
}

public singleTransaction(
view: View,
stateId: string,
transactionId: string,
): View {
const snapshot = view.getSnapshot();
snapshot.filterTransaction(stateId, transactionId);
return view;
}

public getPrivacyPolicy(opts: PrivacyPolicyOpts): IPrivacyPolicy | undefined {
switch (opts) {
case PrivacyPolicyOpts.PruneState:
return this.pruneState;
break;
case PrivacyPolicyOpts.SingleTransaction:
return this.singleTransaction;
break;
default:
return undefined;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,22 @@ export class Snapshot {
this.stateBins = stateBins;
}

public selectStates(states: string[]): void {
const stateBins: State[] = [];
for (const state of this.stateBins) {
if (states.includes(state.getId())) {
stateBins.push(state);
}
}
this.stateBins = stateBins;
}

public filterTransaction(stateId: string, transaction: string): void {
this.selectStates([stateId]);
const state = this.stateBins[0];
state.selectTransactions([transaction]);
}

public getSnapshotJson(): string {
const snapshotJson = {
id: this.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ export class State {
return this.transactions;
}

public selectTransactions(txs: string[]): void {
const transactions: Transaction[] = [];
for (const tx of this.transactions) {
if (txs.includes(tx.getId())) {
transactions.push(tx);
}
}
this.transactions = transactions;
}

public getInitialTime(): string {
if (this.transactions.length >= 1) {
return this.transactions[0].getTimeStamp();
Expand Down
1 change: 1 addition & 0 deletions packages/cactus-plugin-satp-hermes/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ src/main/typescript/generated/gateway-client/typescript-axios/.openapi-generator
src/main/typescript/generated/gateway-client/typescript-axios/api.ts
src/main/typescript/generated/gateway-client/typescript-axios/git_push.sh
src/main/typescript/generated/gateway-client/typescript-axios/.openapi-generator/FILES
src/main/typescript/fabric-contracts/satp/chaincode-typescript/.yarn/
26 changes: 17 additions & 9 deletions packages/cactus-plugin-satp-hermes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
{
"name": "Rafael Belchior",
"url": "https://github.com/RafaelAPB"
},
{
"name": "Carlos Amaro",
"url": "https://github.com/LordKubaya"
}
],
"main": "dist/lib/main/typescript/index.js",
Expand Down Expand Up @@ -80,15 +84,17 @@
"@connectrpc/connect-express": "1.3.0",
"@connectrpc/connect-node": "1.3.0",
"@connectrpc/protoc-gen-connect-es": "1.3.0",
"@hyperledger/cactus-cmd-api-server": "2.0.0-alpha.2",
"@hyperledger/cactus-common": "2.0.0-alpha.2",
"@hyperledger/cactus-core": "2.0.0-alpha.2",
"@hyperledger/cactus-core-api": "2.0.0-alpha.2",
"@hyperledger/cactus-plugin-keychain-memory": "2.0.0-alpha.2",
"@hyperledger/cactus-plugin-ledger-connector-besu": "2.0.0-alpha.2",
"@hyperledger/cactus-plugin-ledger-connector-fabric": "2.0.0-alpha.2",
"@hyperledger/cactus-plugin-object-store-ipfs": "2.0.0-alpha.2",
"@hyperledger/cactus-test-tooling": "2.0.0-alpha.2",
"@hyperledger/cactus-cmd-api-server": "2.0.0-rc.1",
"@hyperledger/cactus-common": "2.0.0-rc.1",
"@hyperledger/cactus-core": "2.0.0-rc.1",
"@hyperledger/cactus-core-api": "2.0.0-rc.1",
"@hyperledger/cactus-plugin-bungee-hermes": "^2.0.0-rc.1",
"@hyperledger/cactus-plugin-keychain-memory": "2.0.0-rc.1",
"@hyperledger/cactus-plugin-ledger-connector-besu": "2.0.0-rc.1",
"@hyperledger/cactus-plugin-ledger-connector-fabric": "2.0.0-rc.1",
"@hyperledger/cactus-plugin-object-store-ipfs": "2.0.0-rc.1",
"@hyperledger/cactus-test-tooling": "2.0.0-rc.1",
"@openzeppelin/contracts": "4.4.0",
"axios": "1.6.0",
"body-parser": "1.20.2",
"class-transformer": "0.5.1",
Expand All @@ -97,8 +103,10 @@
"express": "4.17.2",
"fabric-network": "2.2.19",
"fs-extra": "11.1.1",
"hardhat": "2.22.5",
"knex": "2.4.0",
"kubo-rpc-client": "3.0.1",
"openzeppelin-solidity": "3.4.2",
"secp256k1": "4.0.3",
"socket.io": "4.5.4",
"sqlite3": "5.1.5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,34 +192,19 @@ enum Error {
ERROR_MESSAGE_OUT_OF_SEQUENCE = 11;
}

message LockAssertionClaim {

}

message LockAssertionFormat {

}

message MintAssertionClaims {

}

message MintAssertionClaimsFormat {

}

message BurnAssertionClaim {

}

message BurnAssertionClaimFormat {

}

message AssignmentAssertionClaim {

}

message AssignmentAssertionClaimFormat {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,22 @@ message SessionData {
string last_message_received_timestamp = 41;
MessageStagesTimestamps processed_timestamps = 42;
MessageStagesTimestamps received_timestamps = 43;
cacti.satp.v02.common.LockAssertionClaim lock_assertion_claim = 44;
string lock_assertion_claim = 44;
cacti.satp.v02.common.LockAssertionFormat lock_assertion_format = 45;
cacti.satp.v02.common.MintAssertionClaims mint_assertion_claims = 46;
string mint_assertion_claims = 46;
cacti.satp.v02.common.MintAssertionClaimsFormat mint_assertion_claims_format = 47;
cacti.satp.v02.common.BurnAssertionClaim burn_assertion_claim = 48;
string burn_assertion_claim = 48;
cacti.satp.v02.common.BurnAssertionClaimFormat burn_assertion_claim_format = 49;
cacti.satp.v02.common.AssignmentAssertionClaim assignment_assertion_claim = 50;
string assignment_assertion_claim = 50;
cacti.satp.v02.common.AssignmentAssertionClaimFormat assignment_assertion_claim_format = 51;
bool completed = 52;
ACCEPTANCE acceptance = 53;
string last_message_hash = 54;
cacti.satp.v02.common.TransferClaimsFormat transfer_claims_format = 55;
string client_transfer_number = 56;
string server_transfer_number = 57;
string lock_assertion_expiration = 58;
cacti.satp.v02.common.AssetProfile asset_profile = 59;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ message TransferCommenceRequestMessage {

message TransferCommenceResponseMessage {
cacti.satp.v02.common.CommonSatp common = 1;
string server_transfer_number = 2;
}

service SatpStage1Service {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import "cacti/satp/v02/common/message.proto";

message LockAssertionRequestMessage {
cacti.satp.v02.common.CommonSatp common = 1;
cacti.satp.v02.common.LockAssertionClaim lock_assertion_claim = 2;
string lock_assertion_claim = 2;
cacti.satp.v02.common.LockAssertionFormat lock_assertion_format = 3;
string lock_assertion_expiration = 4;
string client_transfer_number = 5;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ message CommitPreparationRequestMessage {

message CommitReadyResponseMessage {
cacti.satp.v02.common.CommonSatp common = 1;
cacti.satp.v02.common.MintAssertionClaims mint_assertion_claims = 2;
string mint_assertion_claims = 2;
cacti.satp.v02.common.MintAssertionClaimsFormat mint_assertion_claims_format = 3;
string server_transfer_number = 4;
string server_signature = 5;
}

message CommitFinalAssertionRequestMessage {
cacti.satp.v02.common.CommonSatp common = 1;
cacti.satp.v02.common.BurnAssertionClaim burn_assertion_claim = 2;
string burn_assertion_claim = 2;
cacti.satp.v02.common.BurnAssertionClaimFormat burn_assertion_claim_format = 3;
string client_transfer_number = 4;
string client_signature = 5;
Expand All @@ -30,7 +30,7 @@ message CommitFinalAssertionRequestMessage {

message CommitFinalAcknowledgementReceiptResponseMessage {
cacti.satp.v02.common.CommonSatp common = 1;
cacti.satp.v02.common.AssignmentAssertionClaim assignment_assertion_claim = 2;
string assignment_assertion_claim = 2;
cacti.satp.v02.common.AssignmentAssertionClaimFormat assignment_assertion_claim_format = 3;
string server_transfer_number = 4;
string server_signature = 5;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
StatusRequest,
StatusResponse,
Transact200ResponseStatusResponseOriginChain,
} from "../../generated/gateway-client/typescript-axios";
} from "../../generated/gateway-client/typescript-axios/api";
import { Logger } from "@hyperledger/cactus-common";

export async function ExecuteGetStatus(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ConnectRouter, HandlerContext } from "@connectrpc/connect";
import { ConnectRouter } from "@connectrpc/connect";
import { SatpStage1Service } from "../../generated/proto/cacti/satp/v02/stage_1_connect";
import {
TransferCommenceRequestMessage,
Expand Down Expand Up @@ -75,7 +75,7 @@ export class Stage1SATPHandler implements SATPHandler {
);
console.log("Returning response", message);
console.log("Returning response", sessionData);
const response = new TransferProposalReceiptMessage();
const response = new TransferCommenceResponseMessage();
return response;
} catch (error) {
console.error("Error handling TransferCommenceRequest:", error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
ISATPClientServiceOptions,
ISATPServiceOptions,
} from "../satp-service";
import { ACCEPTANCE } from "../../../generated/proto/cacti/satp/v02/common/session_pb";

export class Stage1ClientService extends SATPService {
public static readonly SATP_STAGE = "1";
Expand Down Expand Up @@ -210,7 +211,7 @@ export class Stage1ClientService extends SATPService {
const stepTag = `transferCommenceRequest()`;
const fnTag = `${this.getServiceIdentifier()}#${stepTag}`;

if (!response || !response.common) {
if (response.common == undefined) {
throw new Error("Response or response.common is undefined");
}

Expand All @@ -225,11 +226,17 @@ export class Stage1ClientService extends SATPService {
commonBody.messageType = MessageType.TRANSFER_COMMENCE_REQUEST;
commonBody.sequenceNumber = response.common.sequenceNumber + BigInt(1);

//todo check when reject
commonBody.hashPreviousMessage = getMessageHash(
sessionData,
MessageType.INIT_RECEIPT,
);
if (sessionData.acceptance == ACCEPTANCE.ACCEPTANCE_ACCEPTED) {
commonBody.hashPreviousMessage = getMessageHash(
sessionData,
MessageType.INIT_RECEIPT,
);
} else if (sessionData.acceptance == ACCEPTANCE.ACCEPTANCE_CONDITIONAL) {
commonBody.hashPreviousMessage = getMessageHash(
sessionData,
MessageType.INIT_REJECT,
);
}

commonBody.clientGatewayPubkey = sessionData.clientGatewayPubkey;
commonBody.serverGatewayPubkey = sessionData.serverGatewayPubkey;
Expand All @@ -242,7 +249,15 @@ export class Stage1ClientService extends SATPService {
transferCommenceRequestMessage.hashTransferInitClaims =
sessionData.hashTransferInitClaims;

// transferCommenceRequestMessage.clientTransferNumber = sessionData.clientTransferNumber;
if (sessionData.transferContextId != undefined) {
transferCommenceRequestMessage.common.transferContextId =
sessionData.transferContextId;
}

if (sessionData.clientTransferNumber != undefined) {
transferCommenceRequestMessage.clientTransferNumber =
sessionData.clientTransferNumber;
}

const messageSignature = bufArray2HexStr(
sign(this.Signer, JSON.stringify(transferCommenceRequestMessage)),
Expand Down Expand Up @@ -294,8 +309,6 @@ export class Stage1ClientService extends SATPService {
throw new Error(`${fnTag}, satp common body is missing required fields`);
}

// const sessionId = response.common.sessionId;

const sessionData = session.getSessionData();

if (sessionData == undefined) {
Expand Down Expand Up @@ -367,6 +380,15 @@ export class Stage1ClientService extends SATPService {
);
}

if (
sessionData.transferContextId != undefined &&
response.common.transferContextId != sessionData.transferContextId
) {
throw new Error(
`${fnTag}, TransferProposalReceipt transferContextId mismatch or not received`,
);
}

if (
response.common.messageType == MessageType.INIT_REJECT &&
response.transferCounterClaims == undefined
Expand Down
Loading

0 comments on commit ae970fe

Please sign in to comment.