From 39be0ab97f7707247644eb77b08fc35e51fce82b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emanuel=20Tesa=C5=99?= Date: Thu, 28 Sep 2023 11:19:07 +0200 Subject: [PATCH] Remove storing private key from state --- packages/data-pusher/src/api-requests/signed-api.ts | 7 +++---- packages/data-pusher/src/state.ts | 7 +------ 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/packages/data-pusher/src/api-requests/signed-api.ts b/packages/data-pusher/src/api-requests/signed-api.ts index feafe361..01007b60 100644 --- a/packages/data-pusher/src/api-requests/signed-api.ts +++ b/packages/data-pusher/src/api-requests/signed-api.ts @@ -14,9 +14,8 @@ export type SignedResponse = [TemplateId, SignedData]; export const postSignedApiData = async (group: SignedApiNameUpdateDelayGroup) => { const { - config: { signedApis }, + config: { signedApis, airnodeWalletMnemonic }, templateValues, - walletPrivateKey, } = getState(); const { signedApiName, templateIds, updateDelay } = group; const logContext = { signedApiName, updateDelay }; @@ -24,7 +23,7 @@ export const postSignedApiData = async (group: SignedApiNameUpdateDelayGroup) => const provider = signedApis.find((a) => a.name === signedApiName)!; - const airnode = new ethers.Wallet(walletPrivateKey).address; + const airnode = ethers.Wallet.fromMnemonic(airnodeWalletMnemonic).address; const batchPayloadOrNull = templateIds.map((templateId): SignedApiPayload | null => { const delayedSignedData = templateValues[templateId]!.get(updateDelay); if (isNil(delayedSignedData)) return null; @@ -80,7 +79,7 @@ export const signTemplateResponses = async (templateResponses: TemplateResponse[ const encodedValue = response.data.encodedValue; const timestamp = Math.floor(Date.now() / 1000).toString(); - const wallet = new ethers.Wallet(getState().walletPrivateKey); + const wallet = ethers.Wallet.fromMnemonic(getState().config.airnodeWalletMnemonic); const goSignWithTemplateId = await go(() => signWithTemplateId(wallet, templateId, timestamp, encodedValue)); if (!goSignWithTemplateId.success) { const message = `Failed to sign response. Error: "${goSignWithTemplateId.error}"`; diff --git a/packages/data-pusher/src/state.ts b/packages/data-pusher/src/state.ts index a3610344..7b3863eb 100644 --- a/packages/data-pusher/src/state.ts +++ b/packages/data-pusher/src/state.ts @@ -1,5 +1,4 @@ import Bottleneck from 'bottleneck'; -import { ethers } from 'ethers'; import { Config, SignedData, TemplateId } from './validation/schema'; import { OIS_MAX_CONCURRENCY_DEFAULT, OIS_MIN_TIME_DEFAULT_MS } from './constants'; import { deriveEndpointId, getRandomId } from './utils'; @@ -9,8 +8,6 @@ export type TemplateValueStorage = Record; export interface State { config: Config; templateValues: TemplateValueStorage; - // TODO: this can be trivially derived from config - remove. - walletPrivateKey: string; apiLimiters: Record; } @@ -71,13 +68,11 @@ export const buildApiLimiters = (config: Config) => { export const buildTemplateStorages = (config: Config) => Object.fromEntries(Object.keys(config.templates).map((templateId) => [templateId, new DelayedSignedDataQueue()])); -export const getInitialState = (config: Config) => { +export const getInitialState = (config: Config): State => { return { config, templateValues: buildTemplateStorages(config), apiLimiters: buildApiLimiters(config), - walletPrivateKey: ethers.Wallet.fromMnemonic(config.airnodeWalletMnemonic).privateKey, - sponsorWalletsPrivateKey: {}, }; };