diff --git a/dist/index.js b/dist/index.js index 1474e3c..d5cfa8a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -60,13 +60,13 @@ const validateSecret = (req, res, next) => { } next(); }; +app.use(validateSecret); app.get('/', (req, res) => { res.json({ status: 'OK', supportedChains: handlers_1.default.getSupportedChains(), }); }); -app.use(validateSecret); app.post('/ping', async (req, res) => { try { const { chain, check, env } = req.body; diff --git a/dist/utils/initEvm.js b/dist/utils/initEvm.js index c634970..4cc2130 100644 --- a/dist/utils/initEvm.js +++ b/dist/utils/initEvm.js @@ -11,39 +11,37 @@ const initEthereum = ({ contractAddress, environment, }) => { const config = { dev: { chain: chains_1.sepolia, - evmPrivateKey: evmSk, - infuraUrl: ethRpcUrlSepolia, + evmSk, + ethRpcUrlSepolia, }, testnet: { chain: chains_1.sepolia, - evmPrivateKey: evmSk, - infuraUrl: ethRpcUrlSepolia, + evmSk, + ethRpcUrlSepolia, }, mainnet: { chain: chains_1.mainnet, - evmPrivateKey: evmSk, - infuraUrl: ethRpcUrlMainnet, + evmSk, + ethRpcUrlMainnet, }, }[environment]; - if (!config.infuraUrl) { - throw new Error(`Infura URL for ${environment} environment is missing. Please set the ${environment === 'mainnet' ? 'ethRpcUrlMainnet' : 'ethRpcUrlSepolia'} environment variable.`); + if (!config.ethRpcUrlSepolia) { + throw new Error(`Ethereum RPC URL for ${environment} environment is missing. Please set the ${environment === 'mainnet' ? 'ethRpcUrlMainnet' : 'ethRpcUrlSepolia'} environment variable.`); } - if (!config.evmPrivateKey) { - throw new Error(`EVM private key for ${environment} environment is missing. Please set the ${environment === 'mainnet' - ? 'evmPrivateKeyMainnet' - : 'evmPrivateKeySepolia'} environment variable.`); + if (!config.evmSk) { + throw new Error(`EVM secret key for ${environment} environment is missing. Please set the evmSk environment variable.`); } const publicClient = (0, viem_1.createPublicClient)({ chain: config.chain, - transport: (0, viem_1.http)(config.infuraUrl), + transport: (0, viem_1.http)(config.ethRpcUrlMainnet), }); - const account = (0, accounts_1.privateKeyToAccount)((config.evmPrivateKey.startsWith('0x') - ? config.evmPrivateKey - : `0x${config.evmPrivateKey}`)); + const account = (0, accounts_1.privateKeyToAccount)((config.evmSk.startsWith('0x') + ? config.evmSk + : `0x${config.evmSk}`)); const walletClient = (0, viem_1.createWalletClient)({ account, chain: config.chain, - transport: (0, viem_1.http)(config.infuraUrl), + transport: (0, viem_1.http)(config.ethRpcUrlMainnet), }); const chainSigContract = new signet_js_1.contracts.evm.ChainSignatureContract({ publicClient, diff --git a/src/index.ts b/src/index.ts index 98ab2e8..9be07d0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -33,6 +33,8 @@ const validateSecret = ( next(); }; +app.use(validateSecret as express.RequestHandler); + app.get('/', (req: express.Request, res: express.Response): void => { res.json({ status: 'OK', @@ -40,8 +42,6 @@ app.get('/', (req: express.Request, res: express.Response): void => { }); }); -app.use(validateSecret as express.RequestHandler); - app.post( '/ping', async (req: express.Request, res: express.Response): Promise => { diff --git a/src/utils/initEvm.ts b/src/utils/initEvm.ts index 3c78a97..68fb7e4 100644 --- a/src/utils/initEvm.ts +++ b/src/utils/initEvm.ts @@ -15,52 +15,48 @@ export const initEthereum = ({ const config = { dev: { chain: sepolia, - evmPrivateKey: evmSk, - infuraUrl: ethRpcUrlSepolia, + evmSk, + ethRpcUrlSepolia, }, testnet: { chain: sepolia, - evmPrivateKey: evmSk, - infuraUrl: ethRpcUrlSepolia, + evmSk, + ethRpcUrlSepolia, }, mainnet: { chain: mainnet, - evmPrivateKey: evmSk, - infuraUrl: ethRpcUrlMainnet, + evmSk, + ethRpcUrlMainnet, }, }[environment]; - if (!config.infuraUrl) { + if (!config.ethRpcUrlSepolia) { throw new Error( - `Infura URL for ${environment} environment is missing. Please set the ${ + `Ethereum RPC URL for ${environment} environment is missing. Please set the ${ environment === 'mainnet' ? 'ethRpcUrlMainnet' : 'ethRpcUrlSepolia' } environment variable.` ); } - if (!config.evmPrivateKey) { + if (!config.evmSk) { throw new Error( - `EVM private key for ${environment} environment is missing. Please set the ${ - environment === 'mainnet' - ? 'evmPrivateKeyMainnet' - : 'evmPrivateKeySepolia' - } environment variable.` + `EVM secret key for ${environment} environment is missing. Please set the evmSk environment variable.` ); } const publicClient = createPublicClient({ chain: config.chain, - transport: http(config.infuraUrl), + transport: http(config.ethRpcUrlMainnet), }); const account = privateKeyToAccount( - (config.evmPrivateKey.startsWith('0x') - ? config.evmPrivateKey - : `0x${config.evmPrivateKey}`) as `0x${string}` + (config.evmSk.startsWith('0x') + ? config.evmSk + : `0x${config.evmSk}`) as `0x${string}` ); const walletClient = createWalletClient({ account, chain: config.chain, - transport: http(config.infuraUrl), + transport: http(config.ethRpcUrlMainnet), }); const chainSigContract = new contracts.evm.ChainSignatureContract({ publicClient,