Skip to content

Commit 330ce57

Browse files
eduv09RafaelAPB
authored andcommitted
feat(satp-hermes): bungee & ethereum bridge
* added logic for satp-bridge supporting the ethereum connector * finished the integration with bungee * changed common stringify for safeStableStringify across the package * added test for the new bridge & end-to-end tests for the new features * fabric-connector: fix bug handling empty read-write sets * bungee: strategy fabric fix bug handling empty read-write sets * bungee: hole package introduce safeStableStringify * ethereum-connector: bump web3 packages versions to fix (web3/web3.js#6798) Signed-off-by: Eduardo Vasques <[email protected]>
1 parent 530ea58 commit 330ce57

File tree

53 files changed

+3935
-237
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+3935
-237
lines changed

examples/cactus-example-cbdc-bridging-backend/src/main/typescript/infrastructure/cbdc-bridging-app-dummy-infrastructure.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ import {
7676
AdminApi,
7777
TransactionApi,
7878
} from "@hyperledger/cactus-plugin-satp-hermes/src/main/typescript/generated/gateway-client/typescript-axios/api";
79+
import { ClaimFormat } from "@hyperledger/cactus-plugin-satp-hermes/src/main/typescript/generated/proto/cacti/satp/v02/common/message_pb";
7980

8081
export interface ICbdcBridgingAppDummyInfrastructureOptions {
8182
logLevel?: LogLevelDesc;
@@ -439,6 +440,7 @@ export class CbdcBridgingAppDummyInfrastructure {
439440
contractName: CbdcBridgingAppDummyInfrastructure.SATP_WRAPPER,
440441
options: this.fabricConnectorBridgeOptions,
441442
bungeeOptions: pluginBungeeFabricOptions,
443+
claimFormat: ClaimFormat.DEFAULT,
442444
} as FabricConfig;
443445

444446
const besuConfig = {
@@ -454,6 +456,7 @@ export class CbdcBridgingAppDummyInfrastructure {
454456
options: this.besuOptions,
455457
bungeeOptions: pluginBungeeBesuOptions,
456458
gas: 999999999999999,
459+
claimFormat: ClaimFormat.DEFAULT,
457460
};
458461

459462
const besuGatewayOptions: SATPGatewayConfig = {

packages/cactus-plugin-ledger-connector-ethereum/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@
8282
"sanitize-html": "2.12.1",
8383
"socket.io-client-fixed-types": "4.5.4",
8484
"typescript-optional": "2.0.1",
85-
"web3": "4.4.0",
86-
"web3-eth": "4.4.0",
87-
"web3-eth-contract": "4.2.0"
85+
"web3": "4.14.0",
86+
"web3-eth": "4.10.0",
87+
"web3-eth-contract": "4.7.0"
8888
},
8989
"devDependencies": {
9090
"@hyperledger/cactus-plugin-keychain-memory": "2.1.0",

packages/cactus-plugin-satp-hermes/cache/solidity-files-cache.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

packages/cactus-plugin-satp-hermes/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
"@bufbuild/buf": "1.30.0",
121121
"@bufbuild/protoc-gen-es": "1.8.0",
122122
"@grpc/proto-loader": "0.7.13",
123+
"@hyperledger/cactus-test-geth-ledger": "2.0.0-rc.7",
123124
"@quobix/vacuum": "0.9.16",
124125
"@types/body-parser": "1.19.4",
125126
"@types/crypto-js": "4.0.1",

packages/cactus-plugin-satp-hermes/src/main/proto/cacti/satp/v02/common/message.proto

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -209,46 +209,57 @@ enum Error {
209209
ERROR_MESSAGE_OUT_OF_SEQUENCE = 11;
210210
}
211211

212-
212+
enum ClaimFormat {
213+
DEFAULT = 0;
214+
BUNGEE = 1;
215+
}
216+
message WrapAssertionClaimFormat {
217+
ClaimFormat format = 1;
218+
}
213219
message LockAssertionClaimFormat {
214-
220+
ClaimFormat format = 1;
215221
}
216222

217223
message MintAssertionClaimFormat {
218-
224+
ClaimFormat format = 1;
219225
}
220226

221227
message BurnAssertionClaimFormat {
222-
228+
ClaimFormat format = 1;
223229
}
224230

225231
message AssignmentAssertionClaimFormat {
226-
232+
ClaimFormat format = 1;
227233
}
228234

229235
message LockAssertionClaim {
230236
string receipt = 1;
231-
string signature = 2;
237+
string proof = 2;
238+
string signature = 3;
232239
}
233240

234241
message MintAssertionClaim {
235242
string receipt = 1;
236-
string signature = 2;
243+
string proof = 2;
244+
string signature = 3;
237245
}
238246

239247
message BurnAssertionClaim {
240248
string receipt = 1;
241-
string signature = 2;
249+
string proof = 2;
250+
string signature = 3;
242251
}
243252

244253
message AssignmentAssertionClaim {
245254
string receipt = 1;
246-
string signature = 2;
255+
string proof = 2;
256+
string signature = 3;
247257
}
248258

249259
message WrapAssertionClaim {
250260
string receipt = 1;
251-
string signature = 2;
261+
string proof = 2;
262+
string signature = 3;
252263
}
253264

254265
enum TokenType {

packages/cactus-plugin-satp-hermes/src/main/typescript/blo/admin/get-status-handler-service.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,31 @@ export async function GetStatusService(
7070
dltProtocol: "besu",
7171
dltSubnetworkID: "v24.4.0-RC1",
7272
};
73-
destinationChain = {
73+
} else if (sessionData.senderGatewayNetworkId === SupportedChain.FABRIC) {
74+
originChain = {
7475
dltProtocol: "fabric",
7576
dltSubnetworkID: "v2.0.0",
7677
};
7778
} else {
7879
originChain = {
80+
dltProtocol: "ethereum",
81+
dltSubnetworkID: "v24.4.0-RC1",
82+
};
83+
}
84+
85+
if (sessionData.recipientGatewayNetworkId === SupportedChain.BESU) {
86+
destinationChain = {
87+
dltProtocol: "besu",
88+
dltSubnetworkID: "v24.4.0-RC1",
89+
};
90+
} else if (sessionData.recipientGatewayNetworkId === SupportedChain.FABRIC) {
91+
destinationChain = {
7992
dltProtocol: "fabric",
8093
dltSubnetworkID: "v2.0.0",
8194
};
95+
} else {
8296
destinationChain = {
83-
dltProtocol: "besu",
97+
dltProtocol: "ethereum",
8498
dltSubnetworkID: "v24.4.0-RC1",
8599
};
86100
}

packages/cactus-plugin-satp-hermes/src/main/typescript/core/satp-session.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { v4 as uuidv4 } from "uuid";
2+
import { stringify as safeStableStringify } from "safe-stable-stringify";
3+
24
import {
35
MessageStagesHashes,
46
MessageStagesSignatures,
@@ -257,7 +259,7 @@ export class SATPSession {
257259
) {
258260
throw new SessionDataNotLoadedCorrectlyError(
259261
tag,
260-
JSON.stringify(sessionData),
262+
safeStableStringify(sessionData)!,
261263
);
262264
}
263265
if (sessionData.version != SATP_VERSION) {
@@ -267,7 +269,7 @@ export class SATPSession {
267269
console.error(`${tag}, error: ${error}`);
268270
throw new SessionDataNotLoadedCorrectlyError(
269271
tag,
270-
JSON.stringify(sessionData),
272+
safeStableStringify(sessionData)!,
271273
error,
272274
);
273275
}

packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-handlers/stage0-handler.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import {
77
SATPHandlerType,
88
Stage,
99
} from "../../types/satp-protocol";
10+
import { stringify as safeStableStringify } from "safe-stable-stringify";
11+
1012
import { ConnectRouter, HandlerContext } from "@connectrpc/connect";
1113
import { SatpStage0Service } from "../../generated/proto/cacti/satp/v02/stage_0_connect";
1214
import {
@@ -67,7 +69,7 @@ export class Stage0SATPHandler implements SATPHandler {
6769
try {
6870
this.Log.debug(`${fnTag}, New Session...`);
6971
this.Log.debug(
70-
`${fnTag}, Request: ${JSON.stringify(req)}, Context: ${JSON.stringify(context)}`,
72+
`${fnTag}, Request: ${safeStableStringify(req)}, Context: ${safeStableStringify(context)}`,
7173
);
7274

7375
let session = this.sessions.get(req.sessionId);
@@ -111,7 +113,7 @@ export class Stage0SATPHandler implements SATPHandler {
111113
try {
112114
this.Log.debug(`${fnTag}, PreSATPTransfer...`);
113115
this.Log.debug(
114-
`${fnTag}, Request: ${JSON.stringify(req)}, Context: ${JSON.stringify(context)}`,
116+
`${fnTag}, Request: ${safeStableStringify(req)}, Context: ${safeStableStringify(context)}`,
115117
);
116118

117119
const session = this.sessions.get(req.sessionId);

packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-handlers/stage1-handler.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
} from "../errors/satp-handler-errors";
2525
import { getSessionId } from "./handler-utils";
2626
import { PreSATPTransferResponse } from "../../generated/proto/cacti/satp/v02/stage_0_pb";
27+
import { stringify as safeStableStringify } from "safe-stable-stringify";
2728

2829
export class Stage1SATPHandler implements SATPHandler {
2930
public static readonly CLASS_NAME = SATPHandlerType.STAGE1;
@@ -66,7 +67,7 @@ export class Stage1SATPHandler implements SATPHandler {
6667
try {
6768
this.Log.debug(`${fnTag}, Transfer Proposal...`);
6869
this.Log.debug(
69-
`${fnTag}, Request: ${JSON.stringify(req)}, Context: ${JSON.stringify(context)}`,
70+
`${fnTag}, Request: ${safeStableStringify(req)}, Context: ${safeStableStringify(context)}`,
7071
);
7172

7273
const session = this.sessions.get(getSessionId(req));
@@ -86,7 +87,7 @@ export class Stage1SATPHandler implements SATPHandler {
8687
);
8788

8889
this.Log.debug(
89-
`${fnTag}, Returning response: ${JSON.stringify(message)}`,
90+
`${fnTag}, Returning response: ${safeStableStringify(message)}`,
9091
);
9192

9293
if (!message) {
@@ -107,7 +108,7 @@ export class Stage1SATPHandler implements SATPHandler {
107108
try {
108109
this.Log.debug(`${fnTag}, Transfer Commence...`);
109110
this.Log.debug(
110-
`${fnTag}, Request: ${JSON.stringify(req)}, Context: ${JSON.stringify(context)}`,
111+
`${fnTag}, Request: ${safeStableStringify(req)}, Context: ${safeStableStringify(context)}`,
111112
);
112113

113114
const session = this.sessions.get(getSessionId(req));
@@ -125,7 +126,7 @@ export class Stage1SATPHandler implements SATPHandler {
125126
);
126127

127128
this.Log.debug(
128-
`${fnTag}, Returning response: ${JSON.stringify(message)}`,
129+
`${fnTag}, Returning response: ${safeStableStringify(message)}`,
129130
);
130131

131132
if (!message) {

packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/client/stage0-client-service.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import {
88
NewSessionResponse,
99
PreSATPTransferRequest,
1010
} from "../../../generated/proto/cacti/satp/v02/stage_0_pb";
11+
import { stringify as safeStableStringify } from "safe-stable-stringify";
12+
1113
import { SATPBridgesManager } from "../../../gol/satp-bridges-manager";
1214
import { FailedToProcessError } from "../../errors/satp-handler-errors";
1315
import {
@@ -90,7 +92,7 @@ export class Stage0ClientService extends SATPService {
9092
sessionData.senderGatewayNetworkId;
9193
newSessionRequestMessage.gatewayId = thisGatewayId;
9294
const messageSignature = bufArray2HexStr(
93-
sign(this.Signer, JSON.stringify(newSessionRequestMessage)),
95+
sign(this.Signer, safeStableStringify(newSessionRequestMessage)),
9496
);
9597

9698
newSessionRequestMessage.clientSignature = messageSignature;
@@ -251,7 +253,7 @@ export class Stage0ClientService extends SATPService {
251253
);
252254

253255
const messageSignature = bufArray2HexStr(
254-
sign(this.Signer, JSON.stringify(preSATPTransferRequest)),
256+
sign(this.Signer, safeStableStringify(preSATPTransferRequest)),
255257
);
256258

257259
preSATPTransferRequest.clientSignature = messageSignature;
@@ -303,7 +305,7 @@ export class Stage0ClientService extends SATPService {
303305
const assetId = token.tokenId;
304306
const amount = token.amount.toString();
305307

306-
this.Log.debug(`${fnTag}, Wrap: ${JSON.stringify(token)}`);
308+
this.Log.debug(`${fnTag}, Wrap: ${safeStableStringify(token)}`);
307309

308310
this.Log.debug(`${fnTag}, Wrap Asset ID: ${assetId} amount: ${amount}`);
309311
if (assetId == undefined) {

packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/client/stage1-client-service.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import {
1616
saveSignature,
1717
SessionType,
1818
} from "../../session-utils";
19+
import { stringify as safeStableStringify } from "safe-stable-stringify";
20+
1921
import { SupportedChain } from "../../types";
2022
import { SATPSession } from "../../../core/satp-session";
2123
import {
@@ -181,7 +183,7 @@ export class Stage1ClientService extends SATPService {
181183
}
182184

183185
const messageSignature = bufArray2HexStr(
184-
sign(this.Signer, JSON.stringify(transferProposalRequestMessage)),
186+
sign(this.Signer, safeStableStringify(transferProposalRequestMessage)),
185187
);
186188

187189
transferProposalRequestMessage.clientSignature = messageSignature;
@@ -199,7 +201,7 @@ export class Stage1ClientService extends SATPService {
199201
sessionID: sessionID,
200202
type: "transferProposalRequest",
201203
operation: "validate",
202-
data: JSON.stringify(sessionData),
204+
data: safeStableStringify(sessionData),
203205
});
204206
*/
205207
this.Log.info(`${fnTag}, sending TransferProposalRequest...`);
@@ -248,7 +250,7 @@ export class Stage1ClientService extends SATPService {
248250
sessionData.hashTransferInitClaims;
249251

250252
const messageSignature = bufArray2HexStr(
251-
sign(this.Signer, JSON.stringify(transferCommenceRequestMessage)),
253+
sign(this.Signer, safeStableStringify(transferCommenceRequestMessage)),
252254
);
253255

254256
transferCommenceRequestMessage.clientSignature = messageSignature;
@@ -270,7 +272,7 @@ export class Stage1ClientService extends SATPService {
270272
sessionID: sessionData.id,
271273
type: "transferCommenceRequest",
272274
operation: "validate",
273-
data: JSON.stringify(sessionData),
275+
data: safeStableStringify(sessionData),
274276
});
275277
*/
276278
this.Log.info(`${fnTag}, sending TransferCommenceRequest...`);

packages/cactus-plugin-satp-hermes/src/main/typescript/core/stage-services/client/stage2-client-service.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import {
1414
SessionType,
1515
} from "../../session-utils";
1616
import { SATPSession } from "../../../core/satp-session";
17+
import { stringify as safeStableStringify } from "safe-stable-stringify";
18+
1719
import {
1820
SATPService,
1921
ISATPClientServiceOptions,
@@ -125,7 +127,7 @@ export class Stage2ClientService extends SATPService {
125127
}
126128

127129
const messageSignature = bufArray2HexStr(
128-
sign(this.Signer, JSON.stringify(lockAssertionRequestMessage)),
130+
sign(this.Signer, safeStableStringify(lockAssertionRequestMessage)),
129131
);
130132

131133
lockAssertionRequestMessage.clientSignature = messageSignature;
@@ -143,7 +145,7 @@ export class Stage2ClientService extends SATPService {
143145
sessionID: sessionData.id,
144146
type: "lockAssertionRequest",
145147
operation: "lock",
146-
data: JSON.stringify(sessionData),
148+
data: safeStableStringify(sessionData),
147149
});
148150
*/
149151
this.Log.info(`${fnTag}, sending LockAssertionMessage...`);
@@ -228,8 +230,10 @@ export class Stage2ClientService extends SATPService {
228230
assetId,
229231
Number(amount),
230232
);
233+
sessionData.lockAssertionClaim.proof = await bridge.getProof(assetId);
231234

232235
sessionData.lockAssertionClaimFormat = new LockAssertionClaimFormat();
236+
sessionData.lockAssertionClaimFormat.format = bridge.getReceiptFormat();
233237

234238
sessionData.lockAssertionExpiration = BigInt(99999999999); //todo implement
235239

0 commit comments

Comments
 (0)