Skip to content
This repository was archived by the owner on Aug 14, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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='
)
Expand Down
24 changes: 17 additions & 7 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
);
};
Expand Down
3 changes: 3 additions & 0 deletions src/template/keys.terrain.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ module.exports = {
custom_tester_2: {
privateKey: "fGl1yNoUnnNUqTUXXhxH9vJU0htlz9lWwBt3fQw+ixw=",
},
// custom_tester_3: {
// keyName: "example",
// },
};