From 24e578f8dc3d35fb62dc7ab277c53851efdc3145 Mon Sep 17 00:00:00 2001 From: 17012 Date: Mon, 4 Apr 2022 06:41:27 +0700 Subject: [PATCH] Add clikey support --- src/config.test.ts | 4 ++-- src/config.ts | 24 +++++++++++++++++------- src/template/keys.terrain.js | 3 +++ 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/config.test.ts b/src/config.test.ts index 167e2df..17c1f00 100644 --- a/src/config.test.ts +++ b/src/config.test.ts @@ -166,12 +166,12 @@ test('load config', () => { test('load wallets', () => { const wallets = loadKeys() - const ct1 = wallets.customtester1 as MnemonicKey + const ct1 = wallets.custom_tester_1 as MnemonicKey expect(ct1.mnemonic).toBe( 'shiver position copy catalog upset verify cheap library enjoy extend second peasant basic kit polar business document shrug pass chuckle lottery blind ecology stand' ) - const ct2 = wallets.customtester2 as RawKey + const ct2 = wallets.custom_tester_2 as RawKey expect(ct2.privateKey.toString('base64')).toBe( 'fGl1yNoUnnNUqTUXXhxH9vJU0htlz9lWwBt3fQw+ixw=' ) diff --git a/src/config.ts b/src/config.ts index af0e649..ef69ff9 100644 --- a/src/config.ts +++ b/src/config.ts @@ -2,6 +2,7 @@ import * as R from "ramda"; import * as fs from "fs-extra"; import { LCDClientConfig, MnemonicKey, RawKey } from "@terra-money/terra.js"; import { cli } from "cli-ux"; +import { CLIKey } from "@terra-money/terra.js/dist/key/CLIKey"; type Fee = { gasLimit: number; @@ -88,14 +89,23 @@ export const loadKeys = ( ): { [keyName: string]: RawKey } => { const keys = require(path); return R.map( - (w) => - w.privateKey - ? new RawKey(Buffer.from(w.privateKey, "base64")) - : w.mnemonic - ? new MnemonicKey(w) - : cli.error( - "Error: Key must be defined with either `privateKey` or `mnemonic`" + R.cond([ + [ + R.has('privateKey'), + ({privateKey}) => { + return new RawKey(Buffer.from(privateKey, 'base64')) + }, + ], + [R.has('mnemonic'), w => new MnemonicKey(w)], + [R.has('keyName'), w => new CLIKey(w)], + [ + R.T, + () => + cli.error( + 'Error: Key must be defined with either `privateKey`, `mnemonic` or `keyName`' ), + ], + ]), keys ); }; diff --git a/src/template/keys.terrain.js b/src/template/keys.terrain.js index b3428ae..a6044a9 100644 --- a/src/template/keys.terrain.js +++ b/src/template/keys.terrain.js @@ -9,4 +9,7 @@ module.exports = { custom_tester_2: { privateKey: "fGl1yNoUnnNUqTUXXhxH9vJU0htlz9lWwBt3fQw+ixw=", }, + // custom_tester_3: { + // keyName: "example", + // }, };