Skip to content

Commit 54ab7ed

Browse files
committed
refactor: rename utils to keystore loader
I suspect there is an abstraction in here. I am moving the subset of utils out to a utils folder.
1 parent 6a1a7ca commit 54ab7ed

File tree

11 files changed

+58
-41
lines changed

11 files changed

+58
-41
lines changed

v-next/hardhat-keystore/src/hook-handlers/configuration-variables.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import type {
44
HookContext,
55
} from "@ignored/hardhat-vnext/types/hooks";
66

7+
import { getKeystore } from "../keystores/unencrypted-keystore-loader.js";
78
import get from "../tasks/get.js";
8-
import { getKeystore } from "../utils.js";
99

1010
export default async (): Promise<Partial<ConfigurationVariableHooks>> => {
1111
const handlers: Partial<ConfigurationVariableHooks> = {

v-next/hardhat-keystore/src/utils.ts v-next/hardhat-keystore/src/keystores/unencrypted-keystore-loader.ts

+6-33
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
import type { Keystore } from "./types.js";
1+
import type { Keystore } from "../types.js";
22

33
import path from "node:path";
44

5-
import { HardhatPluginError } from "@ignored/hardhat-vnext-errors";
65
import {
7-
ensureDir,
86
exists,
97
readJsonFile,
108
writeJsonFile,
119
} from "@ignored/hardhat-vnext-utils/fs";
1210
import chalk from "chalk";
13-
import envPaths from "env-paths";
1411

15-
import { PLUGIN_ID } from "./constants.js";
16-
import { io } from "./io.js";
17-
import { setUpPassword } from "./password-manager.js";
12+
import { io } from "../io.js";
13+
import { setUpPassword } from "../password-manager.js";
14+
import { assertFilePath } from "../utils/assert-file-path.js";
15+
import { assertKeyStore } from "../utils/assert-keystore.js";
16+
import { getConfigDir } from "../utils/get-config-dir.js";
1817

1918
let keystoreCache: Keystore | undefined;
2019
let keystoreFilePath: string | undefined;
@@ -113,29 +112,3 @@ async function getKeystoreFilePath(): Promise<string> {
113112
const configDirPath = await getConfigDir();
114113
return path.join(configDirPath, "keystore.json");
115114
}
116-
117-
function assertKeyStore(
118-
keystore: Keystore | undefined,
119-
): asserts keystore is Keystore {
120-
if (keystore === undefined) {
121-
throw new HardhatPluginError(
122-
PLUGIN_ID,
123-
"The keystore should be available at this point!",
124-
);
125-
}
126-
}
127-
128-
function assertFilePath(fileP: string | undefined): asserts fileP is string {
129-
if (fileP === undefined) {
130-
throw new HardhatPluginError(
131-
PLUGIN_ID,
132-
"The filePath should be available at this point!",
133-
);
134-
}
135-
}
136-
137-
async function getConfigDir(): Promise<string> {
138-
const { config } = envPaths("hardhat");
139-
await ensureDir(config);
140-
return config;
141-
}

v-next/hardhat-keystore/src/tasks/delete.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import type { NewTaskActionFunction } from "@ignored/hardhat-vnext/types/tasks";
22

3+
import {
4+
getKeystore,
5+
removeKey,
6+
} from "../keystores/unencrypted-keystore-loader.js";
37
import { isAuthorized } from "../password-manager.js";
48
import { showMsgNoKeystoreSet } from "../utils/show-msg-no-keystore-set.js";
5-
import { getKeystore, removeKey } from "../utils.js";
69

710
interface TaskDeleteArguments {
811
key: string;

v-next/hardhat-keystore/src/tasks/get.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import type { NewTaskActionFunction } from "@ignored/hardhat-vnext/types/tasks";
22

33
import { io } from "../io.js";
4+
import { getKeystore } from "../keystores/unencrypted-keystore-loader.js";
45
import { isAuthorized } from "../password-manager.js";
56
import { showMsgNoKeystoreSet } from "../utils/show-msg-no-keystore-set.js";
6-
import { getKeystore } from "../utils.js";
77

88
interface TaskGetArguments {
99
key: string;

v-next/hardhat-keystore/src/tasks/list.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { NewTaskActionFunction } from "@ignored/hardhat-vnext/types/tasks";
22

33
import { io } from "../io.js";
4+
import { getKeystore } from "../keystores/unencrypted-keystore-loader.js";
45
import { showMsgNoKeystoreSet } from "../utils/show-msg-no-keystore-set.js";
5-
import { getKeystore } from "../utils.js";
66

77
const taskList: NewTaskActionFunction = async () => {
88
const keystore = await getKeystore();

v-next/hardhat-keystore/src/tasks/set.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import type { NewTaskActionFunction } from "@ignored/hardhat-vnext/types/tasks";
22

33
import { io } from "../io.js";
4-
import { isAuthorized } from "../password-manager.js";
54
import {
65
addNewSecret,
76
getKeystore,
87
setupKeystore,
98
validateKey,
10-
} from "../utils.js";
9+
} from "../keystores/unencrypted-keystore-loader.js";
10+
import { isAuthorized } from "../password-manager.js";
1111

1212
interface TaskGetArguments {
1313
key: string;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { HardhatPluginError } from "@ignored/hardhat-vnext-errors";
2+
3+
import { PLUGIN_ID } from "../constants.js";
4+
5+
export function assertFilePath(
6+
fileP: string | undefined,
7+
): asserts fileP is string {
8+
if (fileP === undefined) {
9+
throw new HardhatPluginError(
10+
PLUGIN_ID,
11+
"The filePath should be available at this point!",
12+
);
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import type { Keystore } from "../types.js";
2+
3+
import { HardhatPluginError } from "@ignored/hardhat-vnext-errors";
4+
5+
import { PLUGIN_ID } from "../constants.js";
6+
7+
export function assertKeyStore(
8+
keystore: Keystore | undefined,
9+
): asserts keystore is Keystore {
10+
if (keystore === undefined) {
11+
throw new HardhatPluginError(
12+
PLUGIN_ID,
13+
"The keystore should be available at this point!",
14+
);
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { ensureDir } from "@ignored/hardhat-vnext-utils/fs";
2+
import envPaths from "env-paths";
3+
4+
export async function getConfigDir(): Promise<string> {
5+
const { config } = envPaths("hardhat");
6+
await ensureDir(config);
7+
return config;
8+
}

v-next/hardhat-keystore/test/hooks.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { afterEach, before, beforeEach, describe, it } from "node:test";
77
import { createHardhatRuntimeEnvironment } from "@ignored/hardhat-vnext/hre";
88

99
import hardhatKeystorePlugin from "../src/index.js";
10-
import { setKeystoreCache } from "../src/utils.js";
10+
import { setKeystoreCache } from "../src/keystores/unencrypted-keystore-loader.js";
1111

1212
import { createKeyStore, deleteKeystore } from "./helpers.js";
1313

v-next/hardhat-keystore/test/tasks.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ import chalk from "chalk";
1313

1414
import hardhatKeystorePlugin from "../src/index.js";
1515
import { io } from "../src/io.js";
16-
import { getKeystore, setKeystoreCache } from "../src/utils.js";
16+
import {
17+
getKeystore,
18+
setKeystoreCache,
19+
} from "../src/keystores/unencrypted-keystore-loader.js";
1720

1821
import {
1922
createKeyStore,

0 commit comments

Comments
 (0)