# key-manager

## 编译

make build

## 使用

```
./key-manager -h
NAME:
   key-manager - eth and tron key manager service

USAGE:
   key-manager [global options] command [command options] [arguments...]

COMMANDS:
   init       init key-manager service
   run        run key-manager process
   whitelist  whitelist tools
   help, h    Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --help, -h  show help (default: false)
```

### 步骤

#### 1.配置

服务依赖于mysql，需在conf.yaml中完成mysql的配置

```
mysql:
  user: root
  password: 123456789
  host: 127.0.0.1:3306
  db: key-manager
```

#### 2.初始化

使用前需要设置密码，用来加密助记词使用，并且在启动前将检查输入的密码是否正确。在真实环境启动时，采取的是后台启动，所以可以先将密码写在一个文件中，将这个文件的路径传递给key-manager，当key-manager启动后，**删除密码文件来保证安全**。

命令示例：

`./key-manager init --config ./conf/conf.yaml`

#### 3.白名单

可通过mysql插入白名单地址，key-manager也提供了命令方便查询和查询以及删除白名单地址

```
 ./key-manager whitelist -h
NAME:
   key-manager whitelist - whitelist tools

USAGE:
   key-manager whitelist command [command options] [arguments...]

COMMANDS:
   list     list whitelist address
   add      add whitelist address
   delete   delete whitelist address
   help, h  Shows a list of commands or help for one command

OPTIONS:
   --help, -h  show help (default: false)

```

命令示例：

```
./key-manager whitelist --config ./conf/conf.yaml list

./key-manager whitelist add --config ./conf/conf.yaml t5 0x138d5D3C2d7d68bFC653726c8a5E8bA301452202

./key-manager whitelist delete --config ./conf/conf.yaml t2
```

#### 4.启动

```
./key-manager run -h
NAME:
   key-manager run - run key-manager process

USAGE:
   key-manager run [command options] [arguments...]

OPTIONS:
   --config value    config file path
   --listen value    The host address and port on which the key manager will listen (default: "127.0.0.1:5556")
   --password value  password file path
```

- --listen 可指定服务启动的端口
- --password 当后台启动时，可指定服务的密码，启动后，一定删除密码文件

命令示例：

`./key-manager run --config ./conf/conf.yaml`
