File tree 10 files changed +97
-105
lines changed
v-next/hardhat-keystore/src
10 files changed +97
-105
lines changed Original file line number Diff line number Diff line change
1
+ export const PLUGIN_ID = "hardhat-keystore" ;
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import type {
4
4
HookContext ,
5
5
} from "@ignored/hardhat-vnext/types/hooks" ;
6
6
7
- import { get } from "../methods .js" ;
7
+ import get from "../tasks/get .js" ;
8
8
import { getKeystore } from "../utils.js" ;
9
9
10
10
export default async ( ) : Promise < Partial < ConfigurationVariableHooks > > => {
@@ -20,7 +20,8 @@ export default async (): Promise<Partial<ConfigurationVariableHooks>> => {
20
20
return next ( context , variable ) ;
21
21
}
22
22
23
- const value = await get ( variable . name ) ;
23
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- this is temporary as part of a refactor
24
+ const value = await get ( { key : variable . name } , null as any ) ;
24
25
25
26
return value ?? next ( context , variable ) ;
26
27
} ,
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ const hardhatKeystorePlugin: HardhatPlugin = {
13
13
} ,
14
14
tasks : [
15
15
task ( "keystore" , "Store your keys in a secure way" )
16
- . setAction ( async ( _ , _hre ) => { } )
16
+ . setAction ( async ( ) => { } )
17
17
. build ( ) ,
18
18
19
19
task (
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1
1
import type { NewTaskActionFunction } from "@ignored/hardhat-vnext/types/tasks" ;
2
2
3
- import { remove } from "../methods.js" ;
3
+ import { isAuthorized } from "../password-manager.js" ;
4
+ import { showMsgNoKeystoreSet } from "../utils/show-msg-no-keystore-set.js" ;
5
+ import { getKeystore , removeKey } from "../utils.js" ;
4
6
5
7
interface TaskDeleteArguments {
6
8
key : string ;
@@ -9,7 +11,17 @@ interface TaskDeleteArguments {
9
11
const taskDelete : NewTaskActionFunction < TaskDeleteArguments > = async ( {
10
12
key,
11
13
} ) => {
12
- await remove ( key ) ;
14
+ const keystore = await getKeystore ( ) ;
15
+
16
+ if ( keystore === undefined ) {
17
+ return showMsgNoKeystoreSet ( ) ;
18
+ }
19
+
20
+ if ( ( await isAuthorized ( ) ) === false ) {
21
+ return ;
22
+ }
23
+
24
+ await removeKey ( key ) ;
13
25
} ;
14
26
15
27
export default taskDelete ;
Original file line number Diff line number Diff line change 1
1
import type { NewTaskActionFunction } from "@ignored/hardhat-vnext/types/tasks" ;
2
2
3
- import { get } from "../methods.js" ;
3
+ import { io } from "../io.js" ;
4
+ import { isAuthorized } from "../password-manager.js" ;
5
+ import { showMsgNoKeystoreSet } from "../utils/show-msg-no-keystore-set.js" ;
6
+ import { getKeystore } from "../utils.js" ;
4
7
5
8
interface TaskGetArguments {
6
9
key : string ;
7
10
}
8
11
9
12
const taskGet : NewTaskActionFunction < TaskGetArguments > = async ( { key } ) => {
10
- await get ( key ) ;
13
+ const keystore = await getKeystore ( ) ;
14
+
15
+ if ( keystore === undefined ) {
16
+ showMsgNoKeystoreSet ( ) ;
17
+ return ;
18
+ }
19
+
20
+ if ( ( await isAuthorized ( ) ) === false ) {
21
+ return ;
22
+ }
23
+
24
+ if ( keystore . keys [ key ] === undefined ) {
25
+ console . log ( keystore ) ;
26
+ io . error ( `Key "${ key } " not found` ) ;
27
+ return ;
28
+ }
29
+
30
+ io . info ( keystore . keys [ key ] ) ;
31
+
32
+ return keystore . keys [ key ] ;
11
33
} ;
12
34
13
35
export default taskGet ;
Original file line number Diff line number Diff line change 1
1
import type { NewTaskActionFunction } from "@ignored/hardhat-vnext/types/tasks" ;
2
2
3
- import { list } from "../methods.js" ;
3
+ import { io } from "../io.js" ;
4
+ import { showMsgNoKeystoreSet } from "../utils/show-msg-no-keystore-set.js" ;
5
+ import { getKeystore } from "../utils.js" ;
4
6
5
7
const taskList : NewTaskActionFunction = async ( ) => {
6
- await list ( ) ;
8
+ const keystore = await getKeystore ( ) ;
9
+
10
+ if ( keystore === undefined ) {
11
+ return showMsgNoKeystoreSet ( ) ;
12
+ }
13
+
14
+ // No authorization needed, it only shows the keys, not the secret values
15
+ if ( Object . keys ( keystore . keys ) . length === 0 ) {
16
+ io . info ( "The keystore does not contain any keys." ) ;
17
+ return ;
18
+ }
19
+
20
+ io . info ( "Keys:" ) ;
21
+ for ( const key of Object . keys ( keystore . keys ) ) {
22
+ io . info ( key ) ;
23
+ }
7
24
} ;
8
25
9
26
export default taskList ;
Original file line number Diff line number Diff line change 1
1
import type { NewTaskActionFunction } from "@ignored/hardhat-vnext/types/tasks" ;
2
2
3
- import { set } from "../methods.js" ;
3
+ import { io } from "../io.js" ;
4
+ import { isAuthorized } from "../password-manager.js" ;
5
+ import {
6
+ addNewSecret ,
7
+ getKeystore ,
8
+ setupKeystore ,
9
+ validateKey ,
10
+ } from "../utils.js" ;
4
11
5
12
interface TaskGetArguments {
6
13
key : string ;
@@ -11,7 +18,23 @@ const taskSet: NewTaskActionFunction<TaskGetArguments> = async ({
11
18
key,
12
19
force,
13
20
} ) => {
14
- await set ( key , force ) ;
21
+ const keystore = await getKeystore ( ) ;
22
+
23
+ if ( keystore === undefined ) {
24
+ await setupKeystore ( ) ;
25
+ }
26
+
27
+ if ( ! validateKey ( key ) ) {
28
+ return ;
29
+ }
30
+
31
+ if ( ( await isAuthorized ( ) ) === false ) {
32
+ return ;
33
+ }
34
+
35
+ await addNewSecret ( key , force ) ;
36
+
37
+ io . info ( `Key "${ key } " set` ) ;
15
38
} ;
16
39
17
40
export default taskSet ;
Original file line number Diff line number Diff line change @@ -12,8 +12,8 @@ import {
12
12
import chalk from "chalk" ;
13
13
import envPaths from "env-paths" ;
14
14
15
+ import { PLUGIN_ID } from "./constants.js" ;
15
16
import { io } from "./io.js" ;
16
- import { PLUGIN_ID } from "./methods.js" ;
17
17
import { setUpPassword } from "./password-manager.js" ;
18
18
19
19
let keystoreCache : Keystore | undefined ;
Original file line number Diff line number Diff line change
1
+ import chalk from "chalk" ;
2
+
3
+ import { io } from "../io.js" ;
4
+
5
+ export function showMsgNoKeystoreSet ( ) : void {
6
+ io . info (
7
+ `No keystore found. Please set one up using ${ chalk . blue . italic ( "npx hardhat keystore set {key}" ) } ` ,
8
+ ) ;
9
+ }
You can’t perform that action at this time.
0 commit comments