Skip to content

Commit

Permalink
Remove storing private key from state
Browse files Browse the repository at this point in the history
  • Loading branch information
Siegrift committed Oct 1, 2023
1 parent de46069 commit 39be0ab
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
7 changes: 3 additions & 4 deletions packages/data-pusher/src/api-requests/signed-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@ 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 };
logger.debug('Posting signed API data.', { group, ...logContext });

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;
Expand Down Expand Up @@ -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}"`;
Expand Down
7 changes: 1 addition & 6 deletions packages/data-pusher/src/state.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -9,8 +8,6 @@ export type TemplateValueStorage = Record<TemplateId, DelayedSignedDataQueue>;
export interface State {
config: Config;
templateValues: TemplateValueStorage;
// TODO: this can be trivially derived from config - remove.
walletPrivateKey: string;
apiLimiters: Record<string, Bottleneck | undefined>;
}

Expand Down Expand Up @@ -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: {},
};
};

Expand Down

0 comments on commit 39be0ab

Please sign in to comment.