Skip to content

Commit

Permalink
1658 bnc part 3 (#1798)
Browse files Browse the repository at this point in the history
* fix: fix BNC...

* fix: fix BNC...

* fix: fix BNC...

* fix: fix BNC...

* fix: fix BNC...

* fix: fix BNC...

* fix: en_7 recommendations... (#1749)

* fix: fr9 recommendations

* fix: en_1 recommendations

* fix: en_1 recommendations

* fix: en_2 recommendations...

* fix: en_2 recommendations...

* fix: en_7 recommendations...

* fix: en_7 recommendations...

* fix: n_7 recommandations

* fix: n_7 recommandations

* Merge branch 'main' into 1656-fr9

* Merge branch '1661-en_2' into 1662-en_7

* fix: EN_7

* fix: EN_7

* fix: EN_7

---------

Co-authored-by: Fabio Rigamonti <73019897+fabiorigam@users.noreply.github.com>

(cherry picked from commit f52a556)

* fix: BNC (network)

* fix: BNC 2 network

* fix: BNC 2 network

* fix: BNC 2 network

* fix: BNC 2 network

* fix: BNC 2 network

* fix: BNC 2 network

* fix: BNC 2 network

* fix: BNC 2 network

* fix: BNC 2 network

* fix: BNC 2 network

* fix: BNC 2 network

* fix: BNC 2 network

* fix: BNC 2 network

* fix: BNC 2 network

* fix: BNC 2 network

* fix: BNC 2 network

* fix: BNC 2 network

* fix: BNC 2 network

* fix: BNC 2 network

* fix: BNC 2 network

* fix: BNC 2 network

* fix: BNC 2 network

* fix: BNC 2 network

* fix: BNC 2 network

* fix: BNC 2 network

* Update packages/rpc-proxy/src/utils/config-validator/config-validator.ts

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Signed-off-by: Luca Nicola Debiasi <63785793+lucanicoladebiasi@users.noreply.github.com>

* Update packages/rpc-proxy/src/utils/config-validator/config-validator.ts

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Signed-off-by: Luca Nicola Debiasi <63785793+lucanicoladebiasi@users.noreply.github.com>

* fix: BNC 2 network

* fix: `BNC` part 2 - network refactor

* fix: `BNC` part 2 - network refactor

* fix: `BNC` part 2 - network refactor

* fix: `BNC` part 2 - network refactor

* fix: `BNC` part 3 - rpc-proxy refactor

* fix: `BNC` part 3 - rpc-proxy refactor

* fix: `BNC` part 3 - rpc-proxy refactor

* fix: `BNC` part 3 - rpc-proxy refactor

* fix: `BNC` part 3 - rpc-proxy refactor

* fix: `BNC` part 2 - openssl fix

* fix: `BNC` part 2 - openssl fix

* fix: `BNC` part 2 - rpc-proxy README.md amended

---------

Signed-off-by: Luca Nicola Debiasi <63785793+lucanicoladebiasi@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
lucanicoladebiasi and coderabbitai[bot] authored Feb 13, 2025
1 parent 5121de3 commit f44714c
Show file tree
Hide file tree
Showing 17 changed files with 138 additions and 114 deletions.
5 changes: 3 additions & 2 deletions apps/sdk-hardhat-integration/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ const config: HardhatUserConfig = {
},
debug: true,
gasPayer: {
delegatorUrl: 'https://sponsor-testnet.vechain.energy/by/269'
gasPayerServiceUrl:
'https://sponsor-testnet.vechain.energy/by/269'
},
enableDelegation: true,
gas: 'auto',
Expand All @@ -115,7 +116,7 @@ const config: HardhatUserConfig = {
},
debug: true,
gasPayer: {
delegatorPrivateKey:
gasPayerPrivateKey:
'ea5383ac1f9e625220039a4afac6a7f868bf1ad4f48ce3a1dd78bd214ee4ace5'
},
enableDelegation: true,
Expand Down
15 changes: 9 additions & 6 deletions packages/hardhat-plugin/tests/helpers/fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ const createWalletFromHardhatNetworkConfigPositiveCasesFixture = [
'7f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa157'
],
delegator: {
delegatorPrivateKey:
gasPayerPrivateKey:
'ea5383ac1f9e625220039a4afac6a7f868bf1ad4f48ce3a1dd78bd214ee4ace5',
delegatorUrl: 'https://sponsor-testnet.vechain.energy/by/269'
gasPayerServiceUrl:
'https://sponsor-testnet.vechain.energy/by/269'
}
},
expectedAddresses: [
Expand Down Expand Up @@ -73,9 +74,10 @@ const createWalletFromHardhatNetworkConfigPositiveCasesFixture = [
'0x7f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa157'
],
delegator: {
delegatorPrivateKey:
gasPayerPrivateKey:
'ea5383ac1f9e625220039a4afac6a7f868bf1ad4f48ce3a1dd78bd214ee4ace5',
delegatorUrl: 'https://sponsor-testnet.vechain.energy/by/269'
gasPayerServiceUrl:
'https://sponsor-testnet.vechain.energy/by/269'
}
},
expectedAddresses: [
Expand Down Expand Up @@ -114,9 +116,10 @@ const createWalletFromHardhatNetworkConfigPositiveCasesFixture = [
initialIndex: 0
},
delegator: {
delegatorPrivateKey:
gasPayerPrivateKey:
'ea5383ac1f9e625220039a4afac6a7f868bf1ad4f48ce3a1dd78bd214ee4ace5',
delegatorUrl: 'https://sponsor-testnet.vechain.energy/by/269'
gasPayerServiceUrl:
'https://sponsor-testnet.vechain.energy/by/269'
}
},
expectedAddresses: [
Expand Down
20 changes: 10 additions & 10 deletions packages/rpc-proxy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ So you can run the rpc-proxy with:
#### Use delegation

- `-e, --enableDelegation`: Whether to enable delegation.
- `--delegatorPrivateKey <delegatorPrivateKey>`: The private key of the delegator.
- `-d, --delegatorUrl <delegatorUrl>`: The URL of the delegator.
- -e.g.- `npx rpc-proxy -e --delegatorPrivateKey 8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158`
OR `npx rpc-proxy --enableDelegation --delegatorPrivateKey 8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158`
- -e.g.- `npx rpc-proxy -e -d https://sponsor-testnet.vechain.energy/by/...`
OR `npx rpc-proxy --enableDelegation --delegatorUrl https://sponsor-testnet.vechain.energy/by/...`
- **NOTE**: --delegatorPrivateKey and --delegatorUrl are mutually exclusive.
- **NOTE**: if --enableDelegation is used, --delegatorPrivateKey OR --delegatorUrl MUST be used.
- `--gasPayerPrivateKey <gasPayerPrivateKey>`: The private key of the gasPayer.
- `-s, --gasPayerServiceUrl <gasPayerServiceUrl>`: The URL of the gasPayer.
- -e.g.- `npx rpc-proxy -e --gasPayerPrivateKey 8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158`
OR `npx rpc-proxy --enableDelegation --gasPayerPrivateKey 8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158`
- -e.g.- `npx rpc-proxy -e -s https://sponsor-testnet.vechain.energy/by/...`
OR `npx rpc-proxy --enableDelegation --gasPayerServiceUrl https://sponsor-testnet.vechain.energy/by/...`
- **NOTE**: --gasPayerPrivateKey and --gasPayerServiceUrl are mutually exclusive.
- **NOTE**: if --enableDelegation is used, --gasPayerPrivateKey OR --gasPayerServiceUrl MUST be used.

## Configuration file

Expand Down Expand Up @@ -153,7 +153,7 @@ Simple testnet configuration with a gasPayer private key:
"initialIndex": 0
},
"gasPayer": {
"delegatorPrivateKey": "8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158"
"gasPayerPrivateKey": "8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158"
},
"enableDelegation": true
}
Expand All @@ -171,7 +171,7 @@ Simple testnet configuration with a gasPayer private url:
"initialIndex": 0
},
"gasPayer": {
"delegatorUrl": "https://sponsor-testnet.vechain.energy/by/..."
"gasPayerServiceUrl": "https://sponsor-testnet.vechain.energy/by/..."
},
"enableDelegation": true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,46 +145,46 @@ const ArgsValidatorAndGetter = {
): Config => {
// Both delegation fields are provided - throw an error
if (
options.delegatorPrivateKey !== undefined &&
options.delegatorUrl !== undefined &&
options.delegatorPrivateKey !== null &&
options.delegatorUrl !== null
options.gasPayerPrivateKey !== undefined &&
options.gasPayerServiceUrl !== undefined &&
options.gasPayerPrivateKey !== null &&
options.gasPayerServiceUrl !== null
) {
throw new InvalidCommandLineArguments(
'ArgsValidatorAndGetter.delegation()',
'Both gasPayer private key and gasPayer URL are provided. Only one can be provided',
'Both gasPayer private key and gasPayer service URL are provided. Only one can be provided',
{
flag: '{--delegatorPrivateKey}, {-d , --delegatorUrl}',
value: `{value not provided for security reason} , {${options.delegatorUrl as string}}`
flag: '{--gasPayerPrivateKey}, {-s , --gasPayerServiceUrl}',
value: `{value not provided for security reason} , {${options.gasPayerServiceUrl as string}}`
}
);
}

// Delegation is made with a private key
if (
options.delegatorPrivateKey !== undefined &&
options.delegatorPrivateKey !== null
options.gasPayerPrivateKey !== undefined &&
options.gasPayerPrivateKey !== null
) {
return {
...currentConfiguration,
gasPayer: {
gasPayerPrivateKey: ArgsValidator.delegatorPrivateKey(
options.delegatorPrivateKey as string
gasPayerPrivateKey: ArgsValidator.gasPayerPrivateKey(
options.gasPayerPrivateKey as string
)
}
};
}

// Delegation is made with a gasPayer URL
if (
options.delegatorUrl !== undefined &&
options.delegatorUrl !== null
options.gasPayerServiceUrl !== undefined &&
options.gasPayerServiceUrl !== null
) {
return {
...currentConfiguration,
gasPayer: {
gasPayerServiceUrl: ArgsValidator.delegatorUrl(
options.delegatorUrl as string
gasPayerServiceUrl: ArgsValidator.gasPayerServiceUrl(
options.gasPayerServiceUrl as string
)
}
};
Expand Down
47 changes: 25 additions & 22 deletions packages/rpc-proxy/src/utils/args-validator/args-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { checkValidConfigurationFile } from '../config-validator';
import {
isValidAccountsAsListOfPrivateKeys,
isValidCount,
isValidDelegatorPrivateKey,
isValidDelegatorUrl,
isValidGasPayerPrivateKey,
isValidGasPayerServiceUrl,
isValidMnemonic,
isValidPort,
isValidUrl
Expand Down Expand Up @@ -252,54 +252,57 @@ const ArgsValidator = {

/**
* Delegate configuration
* Validate 'delegatorPrivateKey' configuration field.
* Validate 'gasPayerPrivateKey' configuration field.
*
* @param delegatorPrivateKey Delegator private key to validate
* @returns Delegator private key if provided AND valid, null otherwise
* @param gasPayerPrivateKey The gasPayer private key to validate
* @returns The gasPayer private key if provided AND valid, null otherwise
*/
delegatorPrivateKey: (delegatorPrivateKey: string): string => {
gasPayerPrivateKey: (gasPayerPrivateKey: string): string => {
if (
!isValidDelegatorPrivateKey(delegatorPrivateKey) ||
delegatorPrivateKey === ''
!isValidGasPayerPrivateKey(gasPayerPrivateKey) ||
gasPayerPrivateKey === ''
) {
throw new InvalidCommandLineArguments(
'ArgsValidator.delegatorPrivateKey()',
'ArgsValidator.gasPayerPrivateKey()',
'An invalid gasPayer private key provided.',
{
flag: '--delegatorPrivateKey',
flag: '--gasPayerPrivateKey',
value: 'Value will not be shown for security reasons'
}
);
}
console.log(
`[rpc-proxy]: Delegator private key provided with command line options`
`[rpc-proxy]: The gasPayer private key provided with command line options`
);

return delegatorPrivateKey;
return gasPayerPrivateKey;
},

/*
* Validate 'delgatorUrl' configuration field
* Validate 'gasPayerServiceUrl' configuration field
*
* @param delegatorUrl Delegator URL to validate
* @returns Delegator URL if provided AND valid, null otherwise
* @param gasPayerServiceUrl The gasPayer service URL to validate
* @returns The gasPayer service URL if provided AND valid, null otherwise
*/
delegatorUrl: (delegatorUrl: string): string => {
if (!isValidDelegatorUrl(delegatorUrl) || delegatorUrl === '') {
gasPayerServiceUrl: (gasPayerServiceUrl: string): string => {
if (
!isValidGasPayerServiceUrl(gasPayerServiceUrl) ||
gasPayerServiceUrl === ''
) {
throw new InvalidCommandLineArguments(
'ArgsValidator.delegatorUrl()',
'ArgsValidator.gasPayerServiceUrl()',
'Invalid gasPayer url provided. The parameter must be a valid url',
{
flag: '-d , --delegatorUrl',
value: delegatorUrl
flag: '-s , --gasPayerServiceUrl',
value: gasPayerServiceUrl
}
);
}
console.log(
`[rpc-proxy]: Delegator url provided with command line options: ${delegatorUrl}`
`[rpc-proxy]: The gasPayer service url provided with command line options: ${gasPayerServiceUrl}`
);

return delegatorUrl;
return gasPayerServiceUrl;
}
};

Expand Down
17 changes: 10 additions & 7 deletions packages/rpc-proxy/src/utils/args/args-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import { Command, Option, type OptionValues } from 'commander';
* rpc-proxy {--mnemonicInitialIndex} <index> - Initial index to start deriving accounts from the mnemonic
*
* rpc-proxy {-e|--enableDelegation} - Enable delegation
* rpc-proxy {--delegatorPrivateKey} <delegatorPrivateKey> - Delegator private key
* rpc-proxy {-d|--delegatorUrl} <delegatorUrl> - Delegator URL
* rpc-proxy {--gasPayerPrivateKey} <gasPayerPrivateKey> - The gasPayer private key
* rpc-proxy {-s|--gasPayerServiceUrl} <gasPayerServiceUrl> - The gasPayer service URL
*
* rpc-proxy {-v|--verbose} - Enable verbose logging
*
Expand Down Expand Up @@ -77,17 +77,20 @@ function getOptionsFromCommandLine(
// Enable delegation boolean
.addOption(new Option('-e, --enableDelegation', 'Enable delegation'))

// Delegator configuration (private key)
// The gasPayer configuration (private key)
.addOption(
new Option(
'--delegatorPrivateKey <delegatorPrivateKey>',
'Delegator private key'
'--gasPayerPrivateKey <gasPayerPrivateKey>',
'The gasPayer private key'
)
)

// Delegator configuration (url)
// The gasPayer configuration (url)
.addOption(
new Option('-d, --delegatorUrl <delegatorUrl>', 'Delegator URL')
new Option(
'-s, --gasPayerServiceUrl <gasPayerServiceUrl>',
'The gasPayer service URL'
)
)

// Enable verbose logging
Expand Down
4 changes: 2 additions & 2 deletions packages/rpc-proxy/src/utils/args/args-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ function parseAndGetFinalConfig(
) {
throw new InvalidCommandLineArguments(
'_checkIfConfigurationFileHasCorrectStructure()',
`Invalid configuration: Delegation cannot be enabled without a delegator`,
`Invalid configuration: Delegation cannot be enabled without a gasPayer`,
{
flag: '--enableDelegation , --delegatorPrivateKey, --delegatorUrl',
flag: '--enableDelegation , --gasPayerPrivateKey, --gasPayerServiceUrl',
value: `${options.enableDelegation}, Not provided, Not provided`
}
);
Expand Down
12 changes: 8 additions & 4 deletions packages/rpc-proxy/src/utils/args/env-to-args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,15 @@ function getArgsFromEnv(): string[] {
'ENABLE_DELEGATION'
),
getCliFieldFromEnv(
'--delegatorPrivateKey',
process.env.DELEGATOR_PRIVATE_KEY,
'DELEGATOR_PRIVATE_KEY'
'--gasPayerPrivateKey',
process.env.GAS_PAYER_PRIVATE_KEY,
'GAS_PAYER_PRIVATE_KEY'
),
getCliFieldFromEnv(
'-s',
process.env.GAS_PAYER_SERVICE_URL,
'GAS_PAYER_SERVICE_URL'
),
getCliFieldFromEnv('-d', process.env.DELEGATOR_URL, 'DELEGATOR_URL'),
getCliFieldFromEnv('-v', process.env.VERBOSE, 'VERBOSE'),
getCliFieldFromEnv(
'-c',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import type { Config } from '../../types';
import {
isValidAccountsAsListOfPrivateKeys,
isValidAccountsAsMnemonic,
isValidDelegatorPrivateKey,
isValidDelegatorUrl,
isValidGasPayerPrivateKey,
isValidGasPayerServiceUrl,
isValidPort,
isValidUrl
} from '../validators';
Expand Down Expand Up @@ -138,11 +138,11 @@ function _checkIfConfigurationFileHasCorrectStructure(filePath: string): void {
// Invalid gasPayer private key
if (
configFile.gasPayer.gasPayerPrivateKey !== undefined &&
!isValidDelegatorPrivateKey(configFile.gasPayer.gasPayerPrivateKey)
!isValidGasPayerPrivateKey(configFile.gasPayer.gasPayerPrivateKey)
) {
throw new InvalidConfigurationFile(
'_checkIfConfigurationFileHasCorrectStructure()',
`Invalid delegator private key in configuration file: ${absolutePath}. Delegator private key must be a valid private key`,
`Invalid gasPayer private key in configuration file: ${absolutePath}. The gasPayer private key must be a valid private key`,
{
filePath
}
Expand All @@ -152,11 +152,11 @@ function _checkIfConfigurationFileHasCorrectStructure(filePath: string): void {
// Invalid gasPayer url
if (
configFile.gasPayer.gasPayerServiceUrl !== undefined &&
!isValidDelegatorUrl(configFile.gasPayer.gasPayerServiceUrl)
!isValidGasPayerServiceUrl(configFile.gasPayer.gasPayerServiceUrl)
) {
throw new InvalidConfigurationFile(
'_checkIfConfigurationFileHasCorrectStructure()',
`Invalid delegator url in configuration file: ${absolutePath}. Delegator url must be a valid URL`,
`Invalid gasPayer service url in configuration file: ${absolutePath}. DThe gasPayer service url must be a valid URL`,
{
filePath
}
Expand Down
8 changes: 4 additions & 4 deletions packages/rpc-proxy/src/utils/validators/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function isValidAccountsAsMnemonic(account: {
* @param url - URL to check
* @returns True if the url is valid, false otherwise
*/
function isValidDelegatorUrl(url: string): boolean {
function isValidGasPayerServiceUrl(url: string): boolean {
return isValidUrl(url);
}

Expand All @@ -100,7 +100,7 @@ function isValidDelegatorUrl(url: string): boolean {
* @param privateKey - Private key to check
* @returns True if the private key is valid, false otherwise
*/
function isValidDelegatorPrivateKey(privateKey: string): boolean {
function isValidGasPayerPrivateKey(privateKey: string): boolean {
return isValidAccountsAsListOfPrivateKeys([privateKey]);
}

Expand All @@ -112,6 +112,6 @@ export {
isValidCount,
isValidInitialIndex,
isValidAccountsAsMnemonic,
isValidDelegatorUrl,
isValidDelegatorPrivateKey
isValidGasPayerServiceUrl,
isValidGasPayerPrivateKey
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"initialIndex": 0
},
"gasPayer": {
"delegatorPrivateKey": "8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158"
"gasPayerPrivateKey": "8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158"
},
"enableDelegation": false
}
Loading

1 comment on commit f44714c

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test Coverage

Summary

Lines Statements Branches Functions
Coverage: 98%
98.96% (4395/4441) 97.01% (1398/1441) 98.9% (906/916)
Title Tests Skipped Failures Errors Time
core 839 0 πŸ’€ 0 ❌ 0 πŸ”₯ 2m 36s ⏱️
network 728 0 πŸ’€ 0 ❌ 0 πŸ”₯ 5m 14s ⏱️
errors 40 0 πŸ’€ 0 ❌ 0 πŸ”₯ 18.461s ⏱️
logging 3 0 πŸ’€ 0 ❌ 0 πŸ”₯ 19.829s ⏱️
hardhat-plugin 19 0 πŸ’€ 0 ❌ 0 πŸ”₯ 1m 10s ⏱️
aws-kms-adapter 23 0 πŸ’€ 0 ❌ 0 πŸ”₯ 1m 29s ⏱️
ethers-adapter 5 0 πŸ’€ 0 ❌ 0 πŸ”₯ 1m 23s ⏱️
rpc-proxy 37 0 πŸ’€ 0 ❌ 0 πŸ”₯ 1m 29s ⏱️

Please sign in to comment.