diff --git a/convex-cli/src/main/java/convex/cli/Main.java b/convex-cli/src/main/java/convex/cli/Main.java index 8e06ae5e3..3661f089a 100644 --- a/convex-cli/src/main/java/convex/cli/Main.java +++ b/convex-cli/src/main/java/convex/cli/Main.java @@ -460,7 +460,7 @@ public char[] readPassword(String prompt) { return c.readPassword(prompt); } - public String loadTextFile(String fname) { + public String loadFileAsString(String fname) { String result=null; try { fname=fname.trim(); diff --git a/convex-cli/src/main/java/convex/cli/key/KeyImport.java b/convex-cli/src/main/java/convex/cli/key/KeyImport.java index 932368a40..2317e405d 100644 --- a/convex-cli/src/main/java/convex/cli/key/KeyImport.java +++ b/convex-cli/src/main/java/convex/cli/key/KeyImport.java @@ -57,7 +57,7 @@ public void run() { // Ensure importText is filled if (importFilename != null && importFilename.length() > 0) { if (importText!=null) throw new CLIError("Please provide either --import-file or --text, not both!"); - importText=cli().loadTextFile(importFilename); + importText=cli().loadFileAsString(importFilename); } if (importText == null || importText.length() == 0) { throw new CLIError("You need to provide '--text' or import filename '--import-file' to import a private key"); @@ -72,9 +72,8 @@ public void run() { } } - // Parse input as hex string, just in case + // Parse input as hex string, will be null if not parsed. For BIP39 is 64 bytes, Ed25519 32 ABlob hex=Blobs.parse(importText.trim()); - if (type==null) { cli().printErr("No import file type specified, attempting to auto-detect"); if (hex!=null) { diff --git a/convex-cli/src/test/java/convex/cli/key/KeyImportTest.java b/convex-cli/src/test/java/convex/cli/key/KeyImportTest.java index b95ac9380..d98d227f8 100644 --- a/convex-cli/src/test/java/convex/cli/key/KeyImportTest.java +++ b/convex-cli/src/test/java/convex/cli/key/KeyImportTest.java @@ -56,6 +56,34 @@ public void testKeyImportPEM() { assertTrue(t2.getOutput().contains(accountKey.toHexString())); } + @Test + public void testKeyImportSeed() { + AKeyPair keyPair = AKeyPair.createSeeded(101); + AccountKey accountKey=keyPair.getAccountKey(); + + CLTester tester = CLTester.run( + "key", + "import", + "seed", + "--keystore-password", new String(KEYSTORE_PASSWORD), + "--keystore", KEYSTORE_FILENAME, + "--text", keyPair.getSeed().toString(), + "--import-password", new String("") + ); + assertEquals(ExitCodes.SUCCESS,tester.getResult()); + + // Should give Ed25519 Seed: 616421a4ea27c65919faa5555e923f6005d76695c7d9ba0fe2a484b90e23de89 + + CLTester t2=CLTester.run( + "key" , + "list", + "--keystore-password", new String(KEYSTORE_PASSWORD), + "--keystore", KEYSTORE_FILENAME); + + assertEquals(ExitCodes.SUCCESS,t2.getResult()); + assertTrue(t2.getOutput().contains(accountKey.toHexString())); + } + @Test public void testKeyImportBIP39() {