Skip to content

Commit

Permalink
authorize cli for the engine's admin api
Browse files Browse the repository at this point in the history
  • Loading branch information
antho1404 committed Apr 5, 2020
1 parent 6145c8a commit 629bc51
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
16 changes: 14 additions & 2 deletions packages/cli/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"@oclif/plugin-update": "^1.3.9",
"@oclif/plugin-warn-if-update-available": "^1.7.0",
"axios": "^0.19.0",
"bech32": "^1.1.3",
"chalk": "^2.4.2",
"cli-ux": "^5.3.2",
"debug": "^4.1.1",
Expand Down Expand Up @@ -70,6 +71,7 @@
"@oclif/dev-cli": "^1.22.2",
"@oclif/test": "^1.2.5",
"@oclif/tslint": "^3.1.1",
"@types/bech32": "^1.1.2",
"@types/chai": "^4.2.3",
"@types/hosted-git-info": "^2.7.0",
"@types/inquirer": "0.0.43",
Expand Down
9 changes: 8 additions & 1 deletion packages/cli/src/utils/config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { existsSync, readFileSync, rmdirSync, writeFileSync, unlinkSync } from "fs"
import { safeLoad, safeDump } from "js-yaml"
import { join } from "path"
import Account from "@mesg/api/lib/account-lcd"
import { toWords, encode } from 'bech32'
import Account, { bech32Prefix } from "@mesg/api/lib/account-lcd"

export type Config = {
engine: {
authorized_pubkeys: string[],
account: {
mnemonic: string
}
Expand Down Expand Up @@ -36,6 +38,8 @@ const write = (path: string, config: Config): Config => {
}

export const hasTestAccount = (path: string): boolean => {
if (!existsSync(join(path, ENGINE_FILE))) return false
if (!existsSync(join(path, CLI_FILE))) return false
const config = read(join(path, CLI_FILE))
return !!config.mnemonic && !!config.engine.account.mnemonic
}
Expand All @@ -44,6 +48,9 @@ export const generateConfig = (path: string): Config => {
const mnemonic = Account.generateMnemonic()
const config = {
engine: {
authorized_pubkeys: [
encode(bech32Prefix + 'pub', toWords(Account.deriveMnemonic(mnemonic).identifier))
],
account: {
mnemonic: Account.generateMnemonic()
}
Expand Down

0 comments on commit 629bc51

Please sign in to comment.