Skip to content

Commit

Permalink
Key gen GUI refinement
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed Apr 30, 2024
1 parent 41a9a91 commit 4fd3558
Showing 1 changed file with 18 additions and 26 deletions.
44 changes: 18 additions & 26 deletions convex-gui/src/main/java/convex/gui/keys/KeyGenPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.util.List;

Expand All @@ -13,7 +12,6 @@
import javax.swing.JSpinner;
import javax.swing.JTextArea;
import javax.swing.SpinnerNumberModel;
import javax.swing.border.EmptyBorder;

import convex.core.crypto.AKeyPair;
import convex.core.crypto.BIP39;
Expand All @@ -25,6 +23,7 @@
import convex.core.util.Utils;
import convex.gui.components.ActionPanel;
import convex.gui.components.Identicon;
import convex.gui.components.RightCopyMenu;
import convex.gui.peer.PeerGUI;
import convex.gui.utils.Toolkit;
import net.miginfocom.swing.MigLayout;
Expand All @@ -50,8 +49,8 @@ public class KeyGenPanel extends JPanel {
JPanel formPanel;


int FONT_SIZE=16;
Font HEX_FONT=new Font("Monospaced", Font.BOLD, FONT_SIZE);
static int FONT_SIZE=(int)Toolkit.SCALE*15;
static Font HEX_FONT=Toolkit.SMALL_MONO_FONT.deriveFont((float)FONT_SIZE);

/**
* Format a hex string in blocks for digits
Expand Down Expand Up @@ -196,13 +195,11 @@ private void generatePublicKey() {
public KeyGenPanel(PeerGUI manager) {
setLayout(new BorderLayout());



// Main Key generation form

formPanel = new JPanel();
formPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
formPanel.setLayout(new MigLayout("fillx,wrap 2","[fill,min:250]10[grow,fill]",""));
// formPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
formPanel.setLayout(new MigLayout("wrap 2","[]10[grow,fill]",""));
add(formPanel, BorderLayout.CENTER);

{ // Mnemonic entry box
Expand All @@ -211,7 +208,6 @@ public KeyGenPanel(PeerGUI manager) {
mnemonicArea.setWrapStyleWord(true);
mnemonicArea.setLineWrap(true);
mnemonicArea.setRows(2);
mnemonicArea.setFont(HEX_FONT);
mnemonicArea.setBackground(Color.BLACK);

formPanel.add(mnemonicArea,TEXTAREA_CONSTRAINT);
Expand All @@ -226,7 +222,6 @@ public KeyGenPanel(PeerGUI manager) {
{ // Passphrase entry box
addLabel("Passphrase");
passArea = new JPasswordField();
passArea.setFont(HEX_FONT);
passArea.setBackground(Color.BLACK);
formPanel.add(passArea,"grow,width 10:300:400");
passArea.getDocument().addDocumentListener(Toolkit.createDocumentListener(() -> {
Expand All @@ -238,8 +233,7 @@ public KeyGenPanel(PeerGUI manager) {
{
addLabel("BIP39 Seed");
seedArea = makeTextArea();
seedArea.setFont(HEX_FONT);
seedArea.setColumns(64);
seedArea.setRows(2);
seedArea.setLineWrap(true);
seedArea.setWrapStyleWord(false);
seedArea.setBackground(Color.BLACK);
Expand All @@ -251,13 +245,12 @@ public KeyGenPanel(PeerGUI manager) {
}));
}

addNote("NOTE: \nOnce the BIP39 seed is generated, we use SLIP-10 to create a derivation path to an Ed25519 private key. Instead of a BIP39 seed, you can also use another good secret source of random entropy, e.g. SLIP-0039.");
addNote("NOTE: Once the BIP39 seed is generated, we use SLIP-10 to create a derivation path to an Ed25519 private key. Instead of a BIP39 seed, you can also use another good secret source of random entropy, e.g. SLIP-0039.");

{
addLabel("SLIP-10 Master Key");
masterKeyArea = makeTextArea();
masterKeyArea.setFont(HEX_FONT);
masterKeyArea.setColumns(64);

masterKeyArea.setLineWrap(true);
masterKeyArea.setWrapStyleWord(false);
masterKeyArea.setEditable(false);
Expand All @@ -268,8 +261,7 @@ public KeyGenPanel(PeerGUI manager) {
{
addLabel("BIP32 Path");
derivationArea = makeTextArea();
derivationArea.setFont(HEX_FONT);
derivationArea.setColumns(64);

derivationArea.setLineWrap(true);
derivationArea.setWrapStyleWord(false);
derivationArea.setBackground(Color.BLACK);
Expand All @@ -285,22 +277,19 @@ public KeyGenPanel(PeerGUI manager) {
{
addLabel("SLIP-10 Ext. Priv. Key");
derivedKeyArea = makeTextArea();
derivedKeyArea.setFont(HEX_FONT);
derivedKeyArea.setColumns(64);
derivedKeyArea.setLineWrap(true);
derivedKeyArea.setWrapStyleWord(false);
derivedKeyArea.setEditable(false);
formPanel.add(derivedKeyArea,TEXTAREA_CONSTRAINT);
derivedKeyArea.setText("(not ready)");
}

addNote("NOTE: \nThe first 32 bytes of the SLIP-10 extended private key are used as the Ed25519 seed. This is all you strictly need to sign transactions in Convex. Any 32-byte hex value will work: you can enter this directly if you obtained a good secret random seed from another source.");
addNote("NOTE: The first 32 bytes of the SLIP-10 extended private key are used as the Ed25519 seed. This is all you strictly need to sign transactions in Convex. Any 32-byte hex value will work: you can enter this directly if you obtained a good secret random seed from another source.");


{
addLabel("Private Ed25519 seed");
privateKeyArea = makeTextArea();
privateKeyArea.setFont(HEX_FONT);
privateKeyArea.setBackground(Color.BLACK);

formPanel.add(privateKeyArea,TEXTAREA_CONSTRAINT);
Expand Down Expand Up @@ -364,7 +353,7 @@ public KeyGenPanel(PeerGUI manager) {
pks = Utils.stripWhiteSpace(pks);
HotWalletEntry we = HotWalletEntry.create(AKeyPair.create(Utils.hexToBytes(pks)));
KeyRingPanel.addWalletEntry(we);
manager.switchPanel("Keyring");
if (manager!=null) manager.switchPanel("Keyring");
});
}

Expand All @@ -374,8 +363,11 @@ private void addNote(String s) {
}

private JTextArea makeTextArea() {
JTextArea ta= new JTextArea();
ta.setMinimumSize(new Dimension(10,10));
JTextArea ta= new JTextArea(0,64);
ta.setFont(HEX_FONT);
RightCopyMenu.addTo(ta);

// ta.setMinimumSize(new Dimension(10,10));
return ta;
}

Expand All @@ -385,8 +377,8 @@ private JTextArea makeTextArea() {
* @param string
*/
private void addLabel(String labelText) {
JLabel lblMnemonic = new JLabel(labelText);
formPanel.add(lblMnemonic);
JLabel lblMnemonic = new JLabel(labelText);
formPanel.add(lblMnemonic);
}


Expand Down

0 comments on commit 4fd3558

Please sign in to comment.