Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

Commit

Permalink
refactor: make privateKeyEncrypted nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
rndquu committed Oct 16, 2023
1 parent 0a26b93 commit 9c58746
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/bindings/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const loadConfig = async (context: Context): Promise<BotConfig> => {
payout: {
networkId: networkId,
rpc: rpc,
privateKeyEncrypted: privateKeyEncrypted || "",
privateKeyEncrypted: privateKeyEncrypted || null,
paymentToken: paymentToken,
permitBaseUrl: process.env.PERMIT_BASE_URL || permitBaseUrl,
},
Expand Down Expand Up @@ -113,7 +113,7 @@ export const loadConfig = async (context: Context): Promise<BotConfig> => {
newContributorGreeting: newContributorGreeting,
};

if (botConfig.payout.privateKeyEncrypted == "") {
if (!botConfig.payout.privateKeyEncrypted) {
botConfig.mode.paymentPermitMaxPrice = 0;
}

Expand Down
4 changes: 2 additions & 2 deletions src/handlers/payout/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface IncentivesCalculationResult {
paymentToken: string;
rpc: string;
networkId: number;
privateKeyEncrypted: string;
privateKeyEncrypted: string | null;
paymentPermitMaxPrice: number;
baseMultiplier: number;
incentives: Incentives;
Expand Down Expand Up @@ -147,7 +147,7 @@ export const incentivesCalculation = async (): Promise<IncentivesCalculationResu
throw new Error("No incentive mode. skipping to process");
}

if (privateKeyEncrypted == "") {
if (!privateKeyEncrypted) {
logger.info("Permit generation disabled because wallet private key is not set.");
throw new Error("Permit generation disabled because wallet private key is not set.");
}
Expand Down
2 changes: 1 addition & 1 deletion src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export type LogNotification = Static<typeof LogNotificationSchema>;
export const PayoutConfigSchema = Type.Object({
networkId: Type.Number(),
rpc: Type.String(),
privateKeyEncrypted: Type.String(),
privateKeyEncrypted: Type.Union([Type.Null(), Type.String()]),
paymentToken: Type.String(),
permitBaseUrl: Type.String(),
});
Expand Down
4 changes: 3 additions & 1 deletion src/utils/private.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ export const getOrgAndRepoFromPath = (path: string) => {
return { org, repo };
};

export const getPrivateKey = async (cipherText: string): Promise<string> => {
export const getPrivateKey = async (cipherText: string | null): Promise<string> => {
try {
if (!cipherText) throw new Error("Cipher text is empty");

await _sodium.ready;
const sodium = _sodium;

Expand Down

0 comments on commit 9c58746

Please sign in to comment.