Skip to content

Commit ac39cb7

Browse files
feat(satp-hermes): improve satp gateway configuration object
Signed-off-by: Tomas Silva <[email protected]>
1 parent 32090e3 commit ac39cb7

File tree

16 files changed

+359
-248
lines changed

16 files changed

+359
-248
lines changed

packages/cactus-plugin-satp-hermes/src/main/typescript/cross-chain-mechanisms/bridge/bridge-manager.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,14 @@ import { SATPLoggerProvider as LoggerProvider } from "../../core/satp-logger-pro
33
import { SATPLogger as Logger } from "../../core/satp-logger";
44
import { BridgeLeaf } from "./bridge-leaf";
55
import { LedgerType } from "@hyperledger/cactus-core-api";
6-
import { BesuLeaf, IBesuLeafNeworkOptions } from "./leafs/besu-leaf";
6+
import { BesuLeaf } from "./leafs/besu-leaf";
77
import {
88
DeployLeafError,
99
LeafError,
1010
UnsupportedNetworkError,
1111
WrapperContractAlreadyCreatedError,
1212
} from "../common/errors";
13-
import {
14-
EthereumLeaf,
15-
IEthereumLeafNeworkOptions,
16-
} from "./leafs/ethereum-leaf";
13+
import { EthereumLeaf } from "./leafs/ethereum-leaf";
1714
import { FabricLeaf, IFabricLeafNeworkOptions } from "./leafs/fabric-leaf";
1815
import { BridgeManagerAdminInterface } from "./interfaces/bridge-manager-admin-interface";
1916
import { BridgeManagerClientInterface } from "./interfaces/bridge-manager-client-interface";
@@ -23,7 +20,11 @@ import {
2320
} from "../../generated/proto/cacti/satp/v02/common/message_pb";
2421
import { SATPBridgeExecutionLayer } from "./satp-bridge-execution-layer";
2522
import { SATPBridgeExecutionLayerImpl } from "./satp-bridge-execution-layer-implementation";
26-
import { INetworkOptions } from "./bridge-types";
23+
import {
24+
IBesuNetworkConfig,
25+
IEthereumNetworkConfig,
26+
INetworkOptions,
27+
} from "./bridge-types";
2728
import {
2829
IOntologyManagerOptions,
2930
OntologyManager,
@@ -148,7 +149,7 @@ export class BridgeManager
148149
)}`,
149150
);
150151
const besuNetworkOptions =
151-
leafNetworkOptions as unknown as IBesuLeafNeworkOptions;
152+
leafNetworkOptions as unknown as IBesuNetworkConfig;
152153
if (!this.ontologyManager) {
153154
throw new Error(`${fnTag}, Ontology Manager is not defined`);
154155
}
@@ -178,7 +179,7 @@ export class BridgeManager
178179
)}`,
179180
);
180181
const ethereumNetworkOptions =
181-
leafNetworkOptions as unknown as IEthereumLeafNeworkOptions;
182+
leafNetworkOptions as unknown as IEthereumNetworkConfig;
182183
if (!this.ontologyManager) {
183184
throw new Error(`${fnTag}, Ontology Manager is not defined`);
184185
}

packages/cactus-plugin-satp-hermes/src/main/typescript/cross-chain-mechanisms/bridge/bridge-types.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
import { NetworkId } from "../../public-api";
1+
import {
2+
GasTransactionConfig,
3+
Web3SigningCredential as EthereumWeb3SigningCredential,
4+
} from "@hyperledger/cactus-plugin-ledger-connector-ethereum/";
5+
import { Web3SigningCredential as BesuWeb3SigningCredential } from "@hyperledger/cactus-plugin-ledger-connector-besu/";
6+
import { ClaimFormat, NetworkId } from "../../public-api";
7+
import { IdentificationCredential } from "../../services/validation/config-validating-functions/validate-cc-config";
8+
import { IBridgeLeafOptions } from "./bridge-leaf";
9+
import { IPluginLedgerConnectorEthereumOptions } from "@hyperledger/cactus-plugin-ledger-connector-ethereum/";
10+
import { IPluginLedgerConnectorBesuOptions } from "@hyperledger/cactus-plugin-ledger-connector-besu/";
11+
import { BesuGasConfig } from "../../services/validation/config-validating-functions/bridges-config-validating-functions/validate-besu-config";
212

313
export interface TransactionResponse {
414
transactionId?: string;
@@ -9,3 +19,31 @@ export interface TransactionResponse {
919
export interface INetworkOptions {
1020
networkIdentification: NetworkId;
1121
}
22+
export interface IEthereumNetworkConfig extends INetworkOptions {
23+
signingCredential: EthereumWeb3SigningCredential;
24+
connectorOptions: Partial<IPluginLedgerConnectorEthereumOptions>;
25+
wrapperContractName?: string;
26+
wrapperContractAddress?: string;
27+
gasConfig?: GasTransactionConfig;
28+
leafId?: string;
29+
identificationCredentials?: IdentificationCredential;
30+
claimFormats?: ClaimFormat[];
31+
}
32+
export interface IEthereumLeafOptions
33+
extends IBridgeLeafOptions,
34+
IEthereumNetworkConfig {}
35+
36+
export interface IBesuNetworkConfig extends INetworkOptions {
37+
signingCredential: BesuWeb3SigningCredential;
38+
connectorOptions: Partial<IPluginLedgerConnectorBesuOptions>;
39+
leafId?: string;
40+
identificationCredentials?: IdentificationCredential;
41+
claimFormats?: ClaimFormat[];
42+
wrapperContractName?: string;
43+
wrapperContractAddress?: string;
44+
gasConfig?: BesuGasConfig;
45+
}
46+
47+
export interface IBesuLeafOptions
48+
extends IBridgeLeafOptions,
49+
IBesuNetworkConfig {}

packages/cactus-plugin-satp-hermes/src/main/typescript/cross-chain-mechanisms/bridge/leafs/besu-leaf.ts

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import { INetworkOptions, TransactionResponse } from "../bridge-types";
1+
import {
2+
IBesuLeafOptions,
3+
TransactionResponse,
4+
} from "../bridge-types";
25
import {
36
EthContractInvocationType,
47
IPluginLedgerConnectorBesuOptions,
58
PluginLedgerConnectorBesu,
69
RunTransactionResponse,
7-
Web3SigningCredential,
810
Web3SigningCredentialCactusKeychainRef,
911
Web3SigningCredentialPrivateKeyHex,
1012
Web3TransactionReceipt,
@@ -29,7 +31,6 @@ import { LedgerType } from "@hyperledger/cactus-core-api";
2931
import { BridgeLeafFungible } from "../bridge-leaf-fungible";
3032
import { BridgeLeafNonFungible } from "../bridge-leaf-non-fungible";
3133
import { BridgeLeaf } from "../bridge-leaf";
32-
import { IBridgeLeafOptions } from "../bridge-leaf";
3334
import { v4 as uuidv4 } from "uuid";
3435
import {
3536
NoSigningCredentialError,
@@ -59,21 +60,7 @@ import { getUint8Key } from "./leafs-utils";
5960
import { isWeb3SigningCredentialNone } from "../../common/utils";
6061
import { MonitorService } from "../../../services/monitoring/monitor";
6162
import { context, SpanStatusCode } from "@opentelemetry/api";
62-
63-
export interface IBesuLeafNeworkOptions extends INetworkOptions {
64-
signingCredential: Web3SigningCredential;
65-
connectorOptions: Partial<IPluginLedgerConnectorBesuOptions>;
66-
leafId?: string;
67-
keyPair?: ISignerKeyPair;
68-
claimFormats?: ClaimFormat[];
69-
wrapperContractName?: string;
70-
wrapperContractAddress?: string;
71-
gas?: number;
72-
}
73-
74-
export interface IBesuLeafOptions
75-
extends IBridgeLeafOptions,
76-
IBesuLeafNeworkOptions {}
63+
import { BesuSupportedSigningAlgorithms } from "../../../services/validation/config-validating-functions/bridges-config-validating-functions/validate-besu-config";
7764

7865
/**
7966
* Represents the response from an Besu transaction.
@@ -209,7 +196,25 @@ export class BesuLeaf
209196
};
210197

211198
this.id = this.options.leafId || this.createId(BesuLeaf.CLASS_NAME);
212-
this.keyPair = options.keyPair || Secp256k1Keys.generateKeyPairsBuffer();
199+
200+
if (options.identificationCredentials) {
201+
switch (options.identificationCredentials.signingAlgorithm) {
202+
case BesuSupportedSigningAlgorithms.SECP256K1:
203+
if (options.identificationCredentials.keyPair) {
204+
this.keyPair = options.identificationCredentials.keyPair;
205+
} else {
206+
this.keyPair =
207+
options.keyPair || Secp256k1Keys.generateKeyPairsBuffer();
208+
}
209+
break;
210+
default:
211+
throw new Error(
212+
"Specified signing algorithm is not supported by Besu",
213+
);
214+
}
215+
} else {
216+
this.keyPair = options.keyPair || Secp256k1Keys.generateKeyPairsBuffer();
217+
}
213218

214219
this.claimFormats = options.claimFormats
215220
? options.claimFormats.concat(ClaimFormat.DEFAULT)
@@ -220,7 +225,14 @@ export class BesuLeaf
220225
"Invalid options provided to the BesuLeaf constructor. Please provide a valid IPluginLedgerConnectorBesuOptions object.",
221226
);
222227
}
223-
this.gas = options.gas || 999999999999999; // TODO: set default gas
228+
229+
if (options.gasConfig && "gas" in options.gasConfig) {
230+
this.gas = Number(options.gasConfig?.gas);
231+
} else if (options.gasConfig && "gasLimit" in options.gasConfig) {
232+
this.gas = Number(options.gasConfig?.gasLimit);
233+
} else {
234+
this.gas = 999999999999999;
235+
}
224236

225237
this.connector = new PluginLedgerConnectorBesu(
226238
options.connectorOptions as IPluginLedgerConnectorBesuOptions,

packages/cactus-plugin-satp-hermes/src/main/typescript/cross-chain-mechanisms/bridge/leafs/ethereum-leaf.ts

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { INetworkOptions, TransactionResponse } from "../bridge-types";
1+
import { IEthereumLeafOptions, TransactionResponse } from "../bridge-types";
22
import {
33
EthContractInvocationType,
44
GasTransactionConfig,
@@ -7,7 +7,6 @@ import {
77
isWeb3SigningCredentialNone,
88
PluginLedgerConnectorEthereum,
99
RunTransactionResponse,
10-
Web3SigningCredential,
1110
Web3SigningCredentialCactiKeychainRef,
1211
Web3SigningCredentialGethKeychainPassword,
1312
Web3SigningCredentialPrivateKeyHex,
@@ -34,7 +33,7 @@ import { OntologyManager } from "../ontology/ontology-manager";
3433
import { Web3TransactionReceipt } from "@hyperledger/cactus-plugin-ledger-connector-ethereum";
3534
import { BridgeLeafFungible } from "../bridge-leaf-fungible";
3635
import { BridgeLeafNonFungible } from "../bridge-leaf-non-fungible";
37-
import { BridgeLeaf, IBridgeLeafOptions } from "../bridge-leaf";
36+
import { BridgeLeaf } from "../bridge-leaf";
3837
import {
3938
ApproveAddressError,
4039
BungeeError,
@@ -61,20 +60,6 @@ import { getUint8Key } from "./leafs-utils";
6160
import { MonitorService } from "../../../services/monitoring/monitor";
6261
import { context, SpanStatusCode } from "@opentelemetry/api";
6362

64-
export interface IEthereumLeafNeworkOptions extends INetworkOptions {
65-
signingCredential: Web3SigningCredential;
66-
connectorOptions: Partial<IPluginLedgerConnectorEthereumOptions>;
67-
wrapperContractName?: string;
68-
wrapperContractAddress?: string;
69-
gasConfig?: GasTransactionConfig;
70-
leafId?: string;
71-
keyPair?: ISignerKeyPair;
72-
claimFormats?: ClaimFormat[];
73-
}
74-
export interface IEthereumLeafOptions
75-
extends IBridgeLeafOptions,
76-
IEthereumLeafNeworkOptions {}
77-
7863
/**
7964
* Represents the response from an Ethereum transaction.
8065
*

packages/cactus-plugin-satp-hermes/src/main/typescript/cross-chain-mechanisms/oracle/implementations/oracle-besu.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ import {
1919
import { ClaimFormat } from "../../../generated/proto/cacti/satp/v02/common/message_pb";
2020
import {
2121
BusinessLogicContract,
22+
IBesuNetworkConfig,
2223
NetworkId,
2324
OracleOperation,
2425
OracleResponse,
2526
} from "../../../public-api";
2627

2728
import { getUint8Key } from "../../bridge/leafs/leafs-utils";
2829
import { v4 as uuidv4 } from "uuid";
29-
import { IBesuLeafNeworkOptions } from "../../bridge/leafs/besu-leaf";
3030
import {
3131
EthContractInvocationType,
3232
IPluginLedgerConnectorBesuOptions,
@@ -47,7 +47,7 @@ export interface IBesuOracleEntry extends IOracleEntryBase {
4747

4848
export interface IOracleBesuOptions
4949
extends OracleAbstractOptions,
50-
IBesuLeafNeworkOptions {}
50+
IBesuNetworkConfig {}
5151

5252
export class OracleBesu extends OracleAbstract {
5353
public static CLASS_NAME = "OracleBesu";
@@ -96,7 +96,11 @@ export class OracleBesu extends OracleAbstract {
9696
};
9797

9898
this.id = this.options.leafId || this.createId(OracleBesu.CLASS_NAME);
99-
this.keyPair = options.keyPair || Secp256k1Keys.generateKeyPairsBuffer();
99+
if (options.identificationCredentials) {
100+
this.keyPair = options.identificationCredentials.keyPair;
101+
} else {
102+
this.keyPair = Secp256k1Keys.generateKeyPairsBuffer();
103+
}
100104

101105
this.claimFormats = options.claimFormats
102106
? options.claimFormats.concat(ClaimFormat.DEFAULT)

packages/cactus-plugin-satp-hermes/src/main/typescript/cross-chain-mechanisms/oracle/implementations/oracle-evm.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ import {
2121
Web3SigningCredentialPrivateKeyHex,
2222
} from "@hyperledger/cactus-plugin-ledger-connector-ethereum";
2323
import { IOracleEntryBase, IOracleListenerBase } from "../oracle-types";
24-
import {
25-
EthereumLeaf,
26-
IEthereumLeafNeworkOptions,
27-
} from "../../bridge/leafs/ethereum-leaf";
24+
import { EthereumLeaf } from "../../bridge/leafs/ethereum-leaf";
2825
import { LedgerType } from "@hyperledger/cactus-core-api";
2926
import {
3027
ClaimFormatError,
@@ -46,6 +43,7 @@ import { keccak256 } from "web3-utils";
4643
import { AbiEventFragment, DecodedParams } from "web3";
4744
import { MonitorService } from "../../../services/monitoring/monitor";
4845
import { context, SpanStatusCode } from "@opentelemetry/api";
46+
import { IEthereumNetworkConfig } from "../../bridge/bridge-types";
4947

5048
export interface IEVMOracleEntry extends IOracleEntryBase {
5149
contractAddress: string;
@@ -55,7 +53,7 @@ export interface IEVMOracleEntry extends IOracleEntryBase {
5553

5654
export interface IOracleEVMOptions
5755
extends OracleAbstractOptions,
58-
IEthereumLeafNeworkOptions {}
56+
IEthereumNetworkConfig {}
5957

6058
export class OracleEVM extends OracleAbstract {
6159
public static CLASS_NAME = "OracleEVM";
@@ -105,7 +103,11 @@ export class OracleEVM extends OracleAbstract {
105103
};
106104

107105
this.id = this.options.leafId || this.createId(EthereumLeaf.CLASS_NAME);
108-
this.keyPair = options.keyPair || Secp256k1Keys.generateKeyPairsBuffer();
106+
if (options.identificationCredentials) {
107+
this.keyPair = options.identificationCredentials.keyPair;
108+
} else {
109+
this.keyPair = Secp256k1Keys.generateKeyPairsBuffer();
110+
}
109111

110112
this.claimFormats = options.claimFormats
111113
? options.claimFormats.concat(ClaimFormat.DEFAULT)

packages/cactus-plugin-satp-hermes/src/main/typescript/public-api.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ export * from "./generated/gateway-client/typescript-axios";
33

44
// TODO: Should we export the gateway backend
55
export { ClaimFormat } from "./generated/proto/cacti/satp/v02/common/message_pb";
6-
export { IBesuLeafNeworkOptions } from "./cross-chain-mechanisms/bridge/leafs/besu-leaf";
76
export { SATPGateway, SATPGatewayConfig } from "./plugin-satp-hermes-gateway";
87
export { PluginFactorySATPGateway } from "./factory/plugin-factory-gateway-orchestrator";
9-
export { INetworkOptions } from "./cross-chain-mechanisms/bridge/bridge-types";
8+
export {
9+
INetworkOptions,
10+
IBesuNetworkConfig,
11+
} from "./cross-chain-mechanisms/bridge/bridge-types";
1012
export {
1113
DEFAULT_PORT_GATEWAY_CLIENT,
1214
DEFAULT_PORT_GATEWAY_SERVER,

0 commit comments

Comments
 (0)