-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better keyring interface for Convex Desktop GUI
- Loading branch information
Showing
13 changed files
with
276 additions
and
291 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
convex-core/src/main/java/convex/core/crypto/wallet/AWalletEntry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,20 @@ | ||
package convex.core.crypto.wallet; | ||
|
||
import convex.core.data.AArrayBlob; | ||
|
||
public abstract class AWalletEntry implements IWalletEntry { | ||
|
||
@Override | ||
public void unlock(char[] password) { | ||
if (tryUnlock(password)) return; | ||
|
||
throw new IllegalStateException("Invalid password"); | ||
} | ||
|
||
/** | ||
* Returns the data to be used for a wallet identicon. Should be the public account key | ||
* @return | ||
*/ | ||
public abstract AArrayBlob getIdenticonData(); | ||
|
||
} |
105 changes: 0 additions & 105 deletions
105
convex-core/src/main/java/convex/core/crypto/wallet/BasicWalletEntry.java
This file was deleted.
Oops, something went wrong.
93 changes: 93 additions & 0 deletions
93
convex-core/src/main/java/convex/core/crypto/wallet/HotWalletEntry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package convex.core.crypto.wallet; | ||
|
||
import convex.core.crypto.AKeyPair; | ||
import convex.core.data.AArrayBlob; | ||
import convex.core.data.ACell; | ||
import convex.core.data.AccountKey; | ||
import convex.core.data.Hash; | ||
import convex.core.data.SignedData; | ||
import convex.core.data.Strings; | ||
|
||
/** | ||
* Class implementing a Hot Wallet Entry. Hot keys are stored in memory, and are accessible to | ||
* attackers able to gain full control of the machine. | ||
* | ||
* May be in a locked locked or unlocked state. Unlocking requires passphrase. | ||
*/ | ||
public class HotWalletEntry extends AWalletEntry { | ||
private final AKeyPair keyPair; | ||
private Hash passHash=null; | ||
boolean locked=false; | ||
|
||
private HotWalletEntry(AKeyPair kp) { | ||
this.keyPair = kp; | ||
} | ||
|
||
public static HotWalletEntry create(AKeyPair kp) { | ||
return new HotWalletEntry(kp); | ||
} | ||
|
||
@Override | ||
public AccountKey getPublicKey() { | ||
if (keyPair==null) return null; | ||
return keyPair.getAccountKey(); | ||
} | ||
|
||
@Override | ||
public AKeyPair getKeyPair() { | ||
if (keyPair == null) throw new IllegalStateException("Wallet not unlocked!"); | ||
return keyPair; | ||
} | ||
|
||
|
||
@Override | ||
public boolean isLocked() { | ||
return locked; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
AccountKey pubKey=getPublicKey(); | ||
String ks="0x"+pubKey.toChecksumHex(); | ||
return "Wallet Entry for: "+ks; | ||
} | ||
|
||
public <R extends ACell> SignedData<R> sign(R message) { | ||
return keyPair.signData(message); | ||
} | ||
|
||
@Override | ||
public AArrayBlob getIdenticonData() { | ||
return keyPair.getAccountKey(); | ||
} | ||
|
||
@Override | ||
public synchronized boolean tryUnlock(char[] password) { | ||
if (!isLocked()) return true; | ||
Hash h=getPasswordHash(password); | ||
if (h.equals(passHash)) { | ||
locked=false; | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
@Override | ||
public synchronized void lock(char[] password) { | ||
Hash h=getPasswordHash(password); | ||
if (locked) { | ||
throw new IllegalStateException("Wallet already locked)"); | ||
} else { | ||
passHash=h; | ||
locked=true; | ||
} | ||
} | ||
|
||
protected Hash getPasswordHash(char[] password) { | ||
String s=new String(password); | ||
Hash h=Strings.create(s).getHash(); | ||
return h; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.