Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: BNC 3 backport #1814

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions apps/sdk-hardhat-integration/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { type HttpNetworkConfig } from 'hardhat/types';
*
* They have custom parameters:
* - debug: whether to enable debug mode
* - delegator: the delegator to use
* - gasPayer: the gasPayer to use
* - enableDelegation: whether to enable fee delegation
*/
const config: HardhatUserConfig = {
Expand Down Expand Up @@ -42,7 +42,7 @@ const config: HardhatUserConfig = {
'7f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158'
],
debug: false,
delegator: undefined,
gasPayer: undefined,
gas: 'auto',
gasPrice: 'auto',
gasMultiplier: 1,
Expand All @@ -65,7 +65,7 @@ const config: HardhatUserConfig = {
passphrase: 'vechainthor'
},
debug: true,
delegator: undefined,
gasPayer: undefined,
gas: 'auto',
gasPrice: 'auto',
gasMultiplier: 1,
Expand All @@ -74,7 +74,7 @@ const config: HardhatUserConfig = {
} satisfies HttpNetworkConfig,

/**
* Testnet configuration - with delegator url
* Testnet configuration - with gasPayer url
*/
vechain_testnet_delegator_url: {
// Testnet
Expand All @@ -88,8 +88,9 @@ const config: HardhatUserConfig = {
passphrase: 'vechainthor'
},
debug: true,
delegator: {
delegatorUrl: 'https://sponsor-testnet.vechain.energy/by/269'
gasPayer: {
gasPayerServiceUrl:
'https://sponsor-testnet.vechain.energy/by/269'
},
enableDelegation: true,
gas: 'auto',
Expand All @@ -100,7 +101,7 @@ const config: HardhatUserConfig = {
} satisfies HttpNetworkConfig,

/**
* Testnet configuration - with delegator private key
* Testnet configuration - with gasPayer private key
*/
vechain_testnet_delegator_private_key: {
// Testnet
Expand All @@ -114,8 +115,8 @@ const config: HardhatUserConfig = {
passphrase: 'vechainthor'
},
debug: true,
delegator: {
delegatorPrivateKey:
gasPayer: {
gasPayerPrivateKey:
'ea5383ac1f9e625220039a4afac6a7f868bf1ad4f48ce3a1dd78bd214ee4ace5'
},
enableDelegation: true,
Expand All @@ -137,7 +138,7 @@ const config: HardhatUserConfig = {
],
debug: false,
enableDelegation: false,
delegator: undefined,
gasPayer: undefined,
gas: 'auto',
gasPrice: 'auto',
gasMultiplier: 1,
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
41 changes: 21 additions & 20 deletions packages/rpc-proxy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,24 @@ So you can run the rpc-proxy with:
OR `npx rpc-proxy --accounts "7f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158 8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158"`

- `-m, --mnemonic <mnemonic>`: The mnemonic that the proxy server will use to sign transactions.
- `-mc, --mnemonicCount <mnemonicCount>`: The number of accounts to derive from the mnemonic.
- `-mi, --mnemonicInitialIndex <mnemonicInitialIndex>`: The index from which to start deriving accounts from the
- `--mnemonicCount <mnemonicCount>`: The number of accounts to derive from the mnemonic.
- `--mnemonicInitialIndex <mnemonicInitialIndex>`: The index from which to start deriving accounts from the
mnemonic.
- -e.g.- `npx rpc-proxy -m "denial kitchen pet squirrel other broom bar gas better priority spoil cross" -mc 10 -mi 1`
- -e.g.- `npx rpc-proxy -m "denial kitchen pet squirrel other broom bar gas better priority spoil cross" --mnemonicCount 10 --mnemonicInitialIndex 1`
OR `npx rpc-proxy --mnemonic "denial kitchen pet squirrel other broom bar gas better priority spoil cross" --mnemonicCount 10 --mnemonicInitialIndex 1`
- **NOTE**: --mnemonic, --mnemonicCount, and --mnemonicInitialIndex MUST be used together.

#### Use delegation

- `-e, --enableDelegation`: Whether to enable delegation.
- `-dp, --delegatorPrivateKey <delegatorPrivateKey>`: The private key of the delegator.
- `-du, --delegatorUrl <delegatorUrl>`: The URL of the delegator.
- -e.g.- `npx rpc-proxy -e -dp 8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158`
OR `npx rpc-proxy --enableDelegation --delegatorPrivateKey 8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158`
- -e.g.- `npx rpc-proxy -e -du 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 @@ -141,7 +141,7 @@ Simple thor solo configuration with accounts as a list of private keys:
}
```

Simple testnet configuration with a delegator private key:
Simple testnet configuration with a gasPayer private key:

``` json
{
Expand All @@ -152,14 +152,14 @@ Simple testnet configuration with a delegator private key:
"count": 10,
"initialIndex": 0
},
"delegator": {
"delegatorPrivateKey": "8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158"
"gasPayer": {
"gasPayerPrivateKey": "8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158"

Choose a reason for hiding this comment

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

🛑 Gitleaks has detected a secret with rule-id generic-api-key in commit 81dab7b.
If this secret is a true positive, please rotate the secret ASAP.

If this secret is a false positive, you can add the fingerprint below to your .gitleaksignore file and commit the change to this branch.

echo 81dab7bcb7ae247ae8e3c025fd3c424bf4c3c184:packages/rpc-proxy/README.md:generic-api-key:156 >> .gitleaksignore

},
"enableDelegation": true
}
```

Simple testnet configuration with a delegator private url:
Simple testnet configuration with a gasPayer private url:

``` json
{
Expand All @@ -170,8 +170,8 @@ Simple testnet configuration with a delegator private url:
"count": 10,
"initialIndex": 0
},
"delegator": {
"delegatorUrl": "https://sponsor-testnet.vechain.energy/by/..."
"gasPayer": {
"gasPayerServiceUrl": "https://sponsor-testnet.vechain.energy/by/..."
},
"enableDelegation": true
}
Expand All @@ -183,9 +183,10 @@ To run the RPC proxy as a Docker container, follow these steps:

``` bash
cd ../..
docker build -f docker/rpc-proxy/Dockerfile . -t vechain-rpc-proxy
# We are assuming that the config.json file is placed at the same level as the project root
docker run -d -p 8545:8545 -v ./config.json:/app/config.json -t vechain-rpc-proxy
docker build -f docker/rpc-proxy/Dockerfile . -t vechain/sdk-rpc-proxy
# To replace the default config file, update the config.json file and start a terminal from the folder in which the file is located.
# DISCLAIMER: Make sure you replace the default config file before using it for production software. By default, the docker will point to testnet and use a known mnemonic.
docker run -d -p 8545:8545 -v ./config.json:/app/packages/rpc-proxy/config.json -t vechain/sdk-rpc-proxy
```

If you do not pass a config.json file, the default solo network standard configuration will be used. Make sure to
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 delegator private key and delegator URL are provided. Only one can be provided',
'Both gasPayer private key and gasPayer service URL are provided. Only one can be provided',
{
flag: '{-dp , --delegatorPrivateKey}, {-du , --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,
delegator: {
delegatorPrivateKey: ArgsValidator.delegatorPrivateKey(
options.delegatorPrivateKey as string
gasPayer: {
gasPayerPrivateKey: ArgsValidator.gasPayerPrivateKey(
options.gasPayerPrivateKey as string
)
}
};
}

// Delegation is made with a delegator URL
// Delegation is made with a gasPayer URL
if (
options.delegatorUrl !== undefined &&
options.delegatorUrl !== null
options.gasPayerServiceUrl !== undefined &&
options.gasPayerServiceUrl !== null
) {
return {
...currentConfiguration,
delegator: {
delegatorUrl: ArgsValidator.delegatorUrl(
options.delegatorUrl as string
gasPayer: {
gasPayerServiceUrl: ArgsValidator.gasPayerServiceUrl(
options.gasPayerServiceUrl as string
)
}
};
Expand Down
55 changes: 29 additions & 26 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 @@ -226,7 +226,7 @@ const ArgsValidator = {
'ArgsValidator.mnemonicFields()',
'Invalid count provided. The parameter must be an integer',
{
flag: '-mc , --mnemonicCount',
flag: '--mnemonicCount',
value: String(mnemonicCount)
}
);
Expand All @@ -236,7 +236,7 @@ const ArgsValidator = {
'ArgsValidator.mnemonicFields()',
'Invalid initial index provided. The parameter must be an integer',
{
flag: '-mi , --mnemonicInitialIndex',
flag: '--mnemonicInitialIndex',
value: String(mnemonicInitialIndex)
}
);
Expand All @@ -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()',
'An invalid delegator private key provided.',
'ArgsValidator.gasPayerPrivateKey()',
'An invalid gasPayer private key provided.',
{
flag: '-dp , --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()',
'Invalid delegator url provided. The parameter must be a valid url',
'ArgsValidator.gasPayerServiceUrl()',
'Invalid gasPayer url provided. The parameter must be a valid url',
{
flag: '-du , --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
Loading
Loading