diff --git a/packages/rpc-proxy/README.md b/packages/rpc-proxy/README.md index 8f61dd1a1..f85785ef5 100644 --- a/packages/rpc-proxy/README.md +++ b/packages/rpc-proxy/README.md @@ -78,21 +78,21 @@ So you can run the rpc-proxy with: OR `npx rpc-proxy --accounts "7f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158 8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158"` - `-m, --mnemonic `: The mnemonic that the proxy server will use to sign transactions. -- `-mc, --mnemonicCount `: The number of accounts to derive from the mnemonic. -- `-mi, --mnemonicInitialIndex `: The index from which to start deriving accounts from the +- `--mnemonicCount `: The number of accounts to derive from the mnemonic. +- `--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 `: The private key of the delegator. -- `-du, --delegatorUrl `: The URL of the delegator. - - -e.g.- `npx rpc-proxy -e -dp 8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158` +- `--delegatorPrivateKey `: The private key of the delegator. +- `-d, --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 -du https://sponsor-testnet.vechain.energy/by/...` + - -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. diff --git a/packages/rpc-proxy/package.json b/packages/rpc-proxy/package.json index 6c8f165d1..632858671 100644 --- a/packages/rpc-proxy/package.json +++ b/packages/rpc-proxy/package.json @@ -43,7 +43,7 @@ "@vechain/sdk-errors": "2.0.0-beta.1", "@vechain/sdk-logging": "2.0.0-beta.1", "@vechain/sdk-network": "2.0.0-beta.1", - "commander": "^12.1.0", + "commander": "^13.0.0", "cors": "^2.8.5", "express": "^4.21.2" }, diff --git a/packages/rpc-proxy/src/utils/args-validator/args-validator-and-getter.ts b/packages/rpc-proxy/src/utils/args-validator/args-validator-and-getter.ts index 6f45e960f..d945ac251 100644 --- a/packages/rpc-proxy/src/utils/args-validator/args-validator-and-getter.ts +++ b/packages/rpc-proxy/src/utils/args-validator/args-validator-and-getter.ts @@ -154,7 +154,7 @@ const ArgsValidatorAndGetter = { 'ArgsValidatorAndGetter.delegation()', 'Both delegator private key and delegator URL are provided. Only one can be provided', { - flag: '{-dp , --delegatorPrivateKey}, {-du , --delegatorUrl}', + flag: '{--delegatorPrivateKey}, {-d , --delegatorUrl}', value: `{value not provided for security reason} , {${options.delegatorUrl as string}}` } ); diff --git a/packages/rpc-proxy/src/utils/args-validator/args-validator.ts b/packages/rpc-proxy/src/utils/args-validator/args-validator.ts index e41e6a28c..bc728ef16 100644 --- a/packages/rpc-proxy/src/utils/args-validator/args-validator.ts +++ b/packages/rpc-proxy/src/utils/args-validator/args-validator.ts @@ -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) } ); @@ -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) } ); @@ -266,7 +266,7 @@ const ArgsValidator = { 'ArgsValidator.delegatorPrivateKey()', 'An invalid delegator private key provided.', { - flag: '-dp , --delegatorPrivateKey', + flag: '--delegatorPrivateKey', value: 'Value will not be shown for security reasons' } ); @@ -290,7 +290,7 @@ const ArgsValidator = { 'ArgsValidator.delegatorUrl()', 'Invalid delegator url provided. The parameter must be a valid url', { - flag: '-du , --delegatorUrl', + flag: '-d , --delegatorUrl', value: delegatorUrl } ); diff --git a/packages/rpc-proxy/src/utils/args/args-options.ts b/packages/rpc-proxy/src/utils/args/args-options.ts index 03402196b..a8418ffdf 100644 --- a/packages/rpc-proxy/src/utils/args/args-options.ts +++ b/packages/rpc-proxy/src/utils/args/args-options.ts @@ -11,12 +11,12 @@ import { Command, Option, type OptionValues } from 'commander'; * * Where accounts is a space separated list of private keys (e.g. "PK1 PK2 PK3 ...") * * rpc-proxy {-m|--mnemonic} - Mnemonic to use for signing transactions - * rpc-proxy {-mc|--mnemonicCount} - Number of accounts to derive from the mnemonic - * rpc-proxy {-mi|--mnemonicInitialIndex} - Initial index to start deriving accounts from the mnemonic + * rpc-proxy {--mnemonicCount} - Number of accounts to derive from the mnemonic + * rpc-proxy {--mnemonicInitialIndex} - Initial index to start deriving accounts from the mnemonic * * rpc-proxy {-e|--enableDelegation} - Enable delegation - * rpc-proxy {-dp|--delegatorPrivateKey} - Delegator private key - * rpc-proxy {-du|--delegatorUrl} - Delegator URL + * rpc-proxy {--delegatorPrivateKey} - Delegator private key + * rpc-proxy {-d|--delegatorUrl} - Delegator URL * * rpc-proxy {-v|--verbose} - Enable verbose logging * @@ -63,13 +63,13 @@ function getOptionsFromCommandLine( ) .addOption( new Option( - '-mc, --mnemonicCount ', + '--mnemonicCount ', 'Number of accounts to derive from the mnemonic' ) ) .addOption( new Option( - '-mi, --mnemonicInitialIndex ', + '--mnemonicInitialIndex ', 'Initial index to start deriving accounts from the mnemonic' ) ) @@ -80,14 +80,14 @@ function getOptionsFromCommandLine( // Delegator configuration (private key) .addOption( new Option( - '-dp, --delegatorPrivateKey ', + '--delegatorPrivateKey ', 'Delegator private key' ) ) // Delegator configuration (url) .addOption( - new Option('-du, --delegatorUrl ', 'Delegator URL') + new Option('-d, --delegatorUrl ', 'Delegator URL') ) // Enable verbose logging diff --git a/packages/rpc-proxy/src/utils/args/env-to-args.ts b/packages/rpc-proxy/src/utils/args/env-to-args.ts index c3569d3a4..ef4b6bc12 100644 --- a/packages/rpc-proxy/src/utils/args/env-to-args.ts +++ b/packages/rpc-proxy/src/utils/args/env-to-args.ts @@ -33,9 +33,13 @@ function getArgsFromEnv(): string[] { getCliFieldFromEnv('-p', process.env.PORT, 'PORT'), getCliFieldFromEnv('-a', process.env.ACCOUNTS, 'ACCOUNTS'), getCliFieldFromEnv('-m', process.env.MNEMONIC, 'MNEMONIC'), - getCliFieldFromEnv('-mc', process.env.MNEMONIC_COUNT, 'MNEMONIC_COUNT'), getCliFieldFromEnv( - '-mi', + '--mnemonicCount', + process.env.MNEMONIC_COUNT, + 'MNEMONIC_COUNT' + ), + getCliFieldFromEnv( + '--mnemonicInitialIndex', process.env.MNEMONIC_INITIAL_INDEX, 'MNEMONIC_INITIAL_INDEX' ), @@ -45,11 +49,11 @@ function getArgsFromEnv(): string[] { 'ENABLE_DELEGATION' ), getCliFieldFromEnv( - '-dp', + '--delegatorPrivateKey', process.env.DELEGATOR_PRIVATE_KEY, 'DELEGATOR_PRIVATE_KEY' ), - getCliFieldFromEnv('-du', process.env.DELEGATOR_URL, 'DELEGATOR_URL'), + getCliFieldFromEnv('-d', process.env.DELEGATOR_URL, 'DELEGATOR_URL'), getCliFieldFromEnv('-v', process.env.VERBOSE, 'VERBOSE'), getCliFieldFromEnv( '-c', diff --git a/packages/rpc-proxy/tests/utils/args/args-options.unit.test.ts b/packages/rpc-proxy/tests/utils/args/args-options.unit.test.ts index 92e8bbfe8..3b03968c8 100644 --- a/packages/rpc-proxy/tests/utils/args/args-options.unit.test.ts +++ b/packages/rpc-proxy/tests/utils/args/args-options.unit.test.ts @@ -113,9 +113,9 @@ describe('Args options tests', () => { 'program', '-m', 'expire pair material agent north ostrich fortune level cousin snow mixture nurse', - '-mi', + '--mnemonicInitialIndex', '1', - '-mc', + '--mnemonicCount', '2' ] ].forEach((args) => { @@ -161,13 +161,6 @@ describe('Args options tests', () => { 'program', '--delegatorPrivateKey', '8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158' - ], - // Short syntax - [ - 'path', - 'program', - '-dp', - '8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158' ] ].forEach((args) => { const delegatorPrivateKeyOption = getOptionsFromCommandLine( @@ -190,7 +183,7 @@ describe('Args options tests', () => { // Normal syntax ['path', 'program', '--delegatorUrl', 'http://localhost:8080'], // Short syntax - ['path', 'program', '-du', 'http://localhost:8080'] + ['path', 'program', '-d', 'http://localhost:8080'] ].forEach((args) => { const delegatorUrlOption = getOptionsFromCommandLine( '1.0.0', diff --git a/packages/rpc-proxy/tests/utils/args/args-parser.unit.test.ts b/packages/rpc-proxy/tests/utils/args/args-parser.unit.test.ts index 86caf8ff2..ebf4860d9 100644 --- a/packages/rpc-proxy/tests/utils/args/args-parser.unit.test.ts +++ b/packages/rpc-proxy/tests/utils/args/args-parser.unit.test.ts @@ -166,9 +166,9 @@ describe('Args parser tests', () => { 'program', '-m', 'expire pair material agent north ostrich fortune level cousin snow mixture nurse', - '-mi', + '--mnemonicInitialIndex', '1', - '-mc', + '--mnemonicCount', '2' ] ].forEach((args) => { @@ -203,7 +203,7 @@ describe('Args parser tests', () => { 'path', 'program', '-e', - '-dp', + '--delegatorPrivateKey', '8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158' ] ].forEach((args) => { @@ -233,20 +233,13 @@ describe('Args parser tests', () => { '--delegatorPrivateKey', '8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158' ], - // Short syntax - [ - 'path', - 'program', - '-dp', - '8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158' - ], // Delegator URL // Normal syntax ['path', 'program', '--delegatorUrl', 'http://localhost:8080'], // Short syntax - ['path', 'program', '-du', 'http://localhost:8080'] + ['path', 'program', '-d', 'http://localhost:8080'] ].forEach((args) => { // Get options const options = getOptionsFromCommandLine('1.0.0', args); @@ -414,28 +407,9 @@ describe('Args parser tests', () => { 'program', '-m', 'expire pair material agent north ostrich fortune level cousin snow mixture nurse', - '-mi', - '1' - ], - - // Normal syntax - [ - 'path', - 'program', - '--mnemonic', - 'expire pair material agent north ostrich fortune level cousin snow mixture nurse', '--mnemonicInitialIndex', '1' ], - // Short syntax - [ - 'path', - 'program', - '-m', - 'expire pair material agent north ostrich fortune level cousin snow mixture nurse', - '-mi', - '1' - ], // Normal syntax [ @@ -454,8 +428,6 @@ describe('Args parser tests', () => { // Normal syntax ['path', 'program', '--mnemonicInitialIndex', '1'], - // Short syntax - ['path', 'program', '-mi', '1'], // Wrong format @@ -471,7 +443,16 @@ describe('Args parser tests', () => { '2' ], // Short syntax - ['path', 'program', '-m', 'INVALID', '-mi', '1', '-mc', '2'], + [ + 'path', + 'program', + '-m', + 'INVALID', + '--mnemonicInitialIndex', + '1', + '--mnemonicCount', + '2' + ], // Normal syntax [ @@ -490,9 +471,9 @@ describe('Args parser tests', () => { 'program', '-m', 'expire pair material agent north ostrich fortune level cousin snow mixture nurse', - '-mi', + '--mnemonicInitialIndex', '-1', - '-mc', + '--mnemonicCount', '2' ], @@ -513,9 +494,9 @@ describe('Args parser tests', () => { 'program', '-m', 'expire pair material agent north ostrich fortune level cousin snow mixture nurse', - '-mi', + '--mnemonicInitialIndex', '1', - '-mc', + '--mnemonicCount', '-2' ], @@ -533,7 +514,16 @@ describe('Args parser tests', () => { '2' ], // Short syntax - ['path', 'program', '-m', '', '-mi', '1', '-mc', '2'], + [ + 'path', + 'program', + '-m', + '', + '--mnemonicInitialIndex', + '1', + '--mnemonicCount', + '2' + ], // Normal syntax [ @@ -552,9 +542,9 @@ describe('Args parser tests', () => { 'program', '-m', 'expire pair material agent north ostrich fortune level cousin snow mixture nurse', - '-mi', + '--mnemonicInitialIndex', '', - '-mc', + '--mnemonicCount', '2' ], @@ -575,9 +565,9 @@ describe('Args parser tests', () => { 'program', '-m', 'expire pair material agent north ostrich fortune level cousin snow mixture nurse', - '-mi', + '--mnemonicInitialIndex', '1', - '-mc', + '--mnemonicCount', '' ] ].forEach((args) => { @@ -611,9 +601,9 @@ describe('Args parser tests', () => { [ 'path', 'program', - '-dp', + '--delegatorPrivateKey', '8f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158', - '-du', + '-d', 'http://localhost:8080' ], @@ -621,25 +611,21 @@ describe('Args parser tests', () => { // Normal syntax ['path', 'program', '--delegatorPrivateKey', 'INVALID'], - // Short syntax - ['path', 'program', '-dp', 'INVALID'], // Normal syntax ['path', 'program', '--delegatorUrl', 'INVALID'], // Short syntax - ['path', 'program', '-du', 'INVALID'], + ['path', 'program', '-d', 'INVALID'], // Empty fields // Normal syntax ['path', 'program', '--delegatorPrivateKey', ''], - // Short syntax - ['path', 'program', '-dp', ''], // Normal syntax ['path', 'program', '--delegatorUrl', ''], // Short syntax - ['path', 'program', '-du', ''], + ['path', 'program', '-d', ''], // Enable delegation without the delegator diff --git a/packages/rpc-proxy/tests/utils/args/env-to-args-positive-cases.unit.test.ts b/packages/rpc-proxy/tests/utils/args/env-to-args-positive-cases.unit.test.ts index 359a1171e..b0419b38a 100644 --- a/packages/rpc-proxy/tests/utils/args/env-to-args-positive-cases.unit.test.ts +++ b/packages/rpc-proxy/tests/utils/args/env-to-args-positive-cases.unit.test.ts @@ -44,15 +44,15 @@ describe('Environment variables to command line arguments positive cases', () => 'some accounts', '-m', 'some mnemonic', - '-mc', + '--mnemonicCount', '10', - '-mi', + '--mnemonicInitialIndex', '0', '-e', 'true', - '-dp', + '--delegatorPrivateKey', '0x1234567890abcdef', - '-du', + '-d', 'http://localhost:8669', '-v', 'true', diff --git a/yarn.lock b/yarn.lock index f622bfc9b..3ea9c2ac8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6818,10 +6818,10 @@ command-line-usage@^6.1.0: table-layout "^1.0.2" typical "^5.2.0" -commander@^12.1.0: - version "12.1.0" - resolved "https://registry.yarnpkg.com/commander/-/commander-12.1.0.tgz#01423b36f501259fdaac4d0e4d60c96c991585d3" - integrity sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA== +commander@^13.0.0: + version "13.0.0" + resolved "https://registry.yarnpkg.com/commander/-/commander-13.0.0.tgz#1b161f60ee3ceb8074583a0f95359a4f8701845c" + integrity sha512-oPYleIY8wmTVzkvQq10AEok6YcTC4sRUBl8F9gVuwchGVUCTbl/vhLTaQqutuuySYOsu8YTgV+OxKc/8Yvx+mQ== commander@^4.0.0: version "4.1.1"