Skip to content

Commit

Permalink
Acadia
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTrunk committed Dec 20, 2018
1 parent 6be5e66 commit e8569c2
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 19 deletions.
18 changes: 14 additions & 4 deletions src/java/com/vaklinov/zcashui/AddressesPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ public AddressesPanel(ZelCashJFrame parentFrame, ZCashClientCaller clientCaller,
ZelCashJButton newTAddressButton = new ZelCashJButton(langUtil.getString("panel.address.button.new.address"));
buttonPanel.add(newTAddressButton);
ZelCashJButton newZAddressButton = new ZelCashJButton(langUtil.getString("panel.address.button.new.z.address"));
ZelCashJButton newZAddressButtonSapling = new ZelCashJButton(langUtil.getString("panel.address.button.new.sapling.address"));
buttonPanel.add(newZAddressButtonSapling);
buttonPanel.add(newZAddressButton);
buttonPanel.add(new ZelCashJLabel(" "));
ZelCashJButton refreshButton = new ZelCashJButton(langUtil.getString("panel.address.button.refresh"));
Expand Down Expand Up @@ -208,15 +210,23 @@ public void actionPerformed(ActionEvent e)
{
public void actionPerformed(ActionEvent e)
{
createNewAddress(false);
createNewAddress(false, false);
}
});

newZAddressButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
createNewAddress(true);
createNewAddress(true, false);
}
});

newZAddressButtonSapling.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
createNewAddress(true, true);
}
});

Expand All @@ -239,7 +249,7 @@ public String getSelectedAddress()
}


private void createNewAddress(boolean isZAddress)
private void createNewAddress(boolean isZAddress, boolean isSapling)
{
Cursor oldCursor = this.getCursor();
try
Expand Down Expand Up @@ -269,7 +279,7 @@ private void createNewAddress(boolean isZAddress)
double dBalance = 0;
do
{
address = this.clientCaller.createNewAddress(isZAddress);
address = this.clientCaller.createNewAddress(isZAddress, isSapling);
Log.info("Newly obtained address is: {0}", address);
String sBalance = this.clientCaller.getBalanceForAddress(address);
if (!Util.stringIsEmpty(sBalance))
Expand Down
143 changes: 140 additions & 3 deletions src/java/com/vaklinov/zcashui/ProvingKeyFetcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ public class ProvingKeyFetcher {

private static final int PROVING_KEY_SIZE = 910173851;
private static final String SHA256 = "8bc20a7f013b2b58970cddd2e7ea028975c88ae7ceb9259a5344a16bc2c0eef7";
private static final String pathURL = "https://zensystem.io/downloads/sprout-proving.key";
private static final String pathURL = "https://z.cash/downloads/sprout-proving.key";
private static final int SPROUT_GROTH_SIZE = 725523612;
private static final String SHA256SG = "b685d700c60328498fbde589c8c7c484c722b788b265b72af448a5bf0ee55b50";
private static final String pathURLSG = "https://z.cash/downloads/sprout-groth16.params";
private static final int SAPLING_SPEND_SIZE = 47958396;
private static final String SHA256SS = "8e48ffd23abb3a5fd9c5589204f32d9c31285a04b78096ba40a79b75677efc13";
private static final String pathURLSS = "https://z.cash/downloads/sapling-spend.params";
// TODO: add backups
private LanguageUtil langUtil;

Expand Down Expand Up @@ -65,9 +71,13 @@ private void verifyOrFetch(StartupProgressDialog parent)
zCashParams = zCashParams.getCanonicalFile();

boolean needsFetch = false;
boolean needsFetchSG = false;
boolean needsFetchSS = false;
if (!zCashParams.exists())
{
needsFetch = true;
needsFetchSG = true;
needsFetchSS = true;
zCashParams.mkdirs();
}

Expand All @@ -78,16 +88,45 @@ private void verifyOrFetch(StartupProgressDialog parent)
copy(is,fos);
fos.close();
is = null;

// sapling output params is small, always copy it
File saplingOutputFile = new File(zCashParams,"sapling-output.params");
FileOutputStream fosB = new FileOutputStream(saplingOutputFile);
InputStream isB = ProvingKeyFetcher.class.getClassLoader().getResourceAsStream("keys/sapling-output.params");
copy(isB,fosB);
fosB.close();
isB = null;

File provingKeyFile = new File(zCashParams,"sprout-proving.key");
provingKeyFile = provingKeyFile.getCanonicalFile();
File sproutGrothFile = new File(zCashParams,"sprout-groth16.params");
sproutGrothFile = sproutGrothFile.getCanonicalFile();
File saplingSpendFile = new File(zCashParams,"sapling-spend.params");
saplingSpendFile = saplingSpendFile.getCanonicalFile();
if (!provingKeyFile.exists())
{
needsFetch = true;
} else if (provingKeyFile.length() != PROVING_KEY_SIZE)
{
needsFetch = true;
}

if (!sproutGrothFile.exists())
{
needsFetchSG = true;
} else if (sproutGrothFile.length() != SPROUT_GROTH_SIZE)
{
needsFetchSG = true;
}

if (!saplingSpendFile.exists())
{
needsFetchSS = true;
} else if (saplingSpendFile.length() != SAPLING_SPEND_SIZE)
{
needsFetchSS = true;
}

/*
* We skip proving key verification every start - this is impractical.
* If the proving key exists and is the correct size, then it should be OK.
Expand All @@ -97,7 +136,7 @@ private void verifyOrFetch(StartupProgressDialog parent)
needsFetch = !checkSHA256(provingKeyFile,parent);
}*/

if (!needsFetch)
if (!needsFetch && !needsFetchSG && !needsFetchSS)
{
return;
}
Expand All @@ -107,6 +146,7 @@ private void verifyOrFetch(StartupProgressDialog parent)
langUtil.getString("proving.key.fetcher.option.pane.verify.message"));

parent.setProgressText(langUtil.getString("proving.key.fetcher.option.pane.verify.progress.text"));
if (needsFetch) {
provingKeyFile.delete();
OutputStream os = new BufferedOutputStream(new FileOutputStream(provingKeyFile));
URL keyURL = new URL(pathURL);
Expand All @@ -132,6 +172,61 @@ private void verifyOrFetch(StartupProgressDialog parent)
JOptionPane.showMessageDialog(parent, langUtil.getString("proving.key.fetcher.option.pane.verify.key.failed.text"));
System.exit(-4);
}
}
if (needsFetchSG) {
provingKeyFile.delete();
OutputStream os = new BufferedOutputStream(new FileOutputStream(sproutGrothFile));
URL keyURL = new URL(pathURLSG);
URLConnection urlc = keyURL.openConnection();
urlc.setRequestProperty("User-Agent", "Wget/1.17.1 (linux-gnu)");

try
{
is = urlc.getInputStream();
ProgressMonitorInputStream pmis = new ProgressMonitorInputStream(parent, langUtil.getString("sprout.groth.fetcher.option.pane.verify.progress.monitor.text"), is);
pmis.getProgressMonitor().setMaximum(SPROUT_GROTH_SIZE);
pmis.getProgressMonitor().setMillisToPopup(10);

copy(pmis,os);
os.close();
} finally
{
try { if (is != null) is.close(); } catch (IOException ignore){}
}
parent.setProgressText(langUtil.getString("sprout.groth.fetcher.option.pane.verify.key.text"));
if (!checkSHA256SG(sproutGrothFile, parent))
{
JOptionPane.showMessageDialog(parent, langUtil.getString("sapsproutling.groth.fetcher.option.pane.verify.key.failed.text"));
System.exit(-4);
}
}
if (needsFetchSS) {
provingKeyFile.delete();
OutputStream os = new BufferedOutputStream(new FileOutputStream(saplingSpendFile));
URL keyURL = new URL(pathURLSS);
URLConnection urlc = keyURL.openConnection();
urlc.setRequestProperty("User-Agent", "Wget/1.17.1 (linux-gnu)");

try
{
is = urlc.getInputStream();
ProgressMonitorInputStream pmis = new ProgressMonitorInputStream(parent, langUtil.getString("sapling.spend.fetcher.option.pane.verify.progress.monitor.text"), is);
pmis.getProgressMonitor().setMaximum(SAPLING_SPEND_SIZE);
pmis.getProgressMonitor().setMillisToPopup(10);

copy(pmis,os);
os.close();
} finally
{
try { if (is != null) is.close(); } catch (IOException ignore){}
}
parent.setProgressText(langUtil.getString("sapling.spend.fetcher.option.pane.verify.key.text"));
if (!checkSHA256SS(saplingSpendFile, parent))
{
JOptionPane.showMessageDialog(parent, langUtil.getString("sapling.spend.fetcher.option.pane.verify.key.failed.text"));
System.exit(-4);
}
}
}


Expand Down Expand Up @@ -164,4 +259,46 @@ private static boolean checkSHA256(File provingKey, Component parent) throws IOE
return SHA256.equalsIgnoreCase(DatatypeConverter.printHexBinary(digest));
}
}
}

private static boolean checkSHA256SG(File sproutGroth, Component parent) throws IOException {
MessageDigest sha256;
try {
sha256 = MessageDigest.getInstance("SHA-256");
} catch (NoSuchAlgorithmException impossible) {
throw new IOException(impossible);
}
try (InputStream is = new BufferedInputStream(new FileInputStream(sproutGroth))) {
ProgressMonitorInputStream pmis = new ProgressMonitorInputStream(parent,
LanguageUtil.instance().getString("sprout.groth.fetcher.option.pane.verify.progress.monitor.text"),
is);
pmis.getProgressMonitor().setMaximum(SPROUT_GROTH_SIZE);
pmis.getProgressMonitor().setMillisToPopup(10);
DigestInputStream dis = new DigestInputStream(pmis, sha256);
byte [] temp = new byte[0x1 << 13];
while(dis.read(temp) >= 0);
byte [] digest = sha256.digest();
return SHA256SG.equalsIgnoreCase(DatatypeConverter.printHexBinary(digest));
}
}

private static boolean checkSHA256SS(File saplingSpend, Component parent) throws IOException {
MessageDigest sha256;
try {
sha256 = MessageDigest.getInstance("SHA-256");
} catch (NoSuchAlgorithmException impossible) {
throw new IOException(impossible);
}
try (InputStream is = new BufferedInputStream(new FileInputStream(saplingSpend))) {
ProgressMonitorInputStream pmis = new ProgressMonitorInputStream(parent,
LanguageUtil.instance().getString("sapling.spend.fetcher.option.pane.verify.progress.monitor.text"),
is);
pmis.getProgressMonitor().setMaximum(SAPLING_SPEND_SIZE);
pmis.getProgressMonitor().setMillisToPopup(10);
DigestInputStream dis = new DigestInputStream(pmis, sha256);
byte [] temp = new byte[0x1 << 13];
while(dis.read(temp) >= 0);
byte [] digest = sha256.digest();
return SHA256SS.equalsIgnoreCase(DatatypeConverter.printHexBinary(digest));
}
}
}
3 changes: 2 additions & 1 deletion src/java/com/vaklinov/zcashui/SendCashPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ private void sendCash()
if (!installationObserver.isOnTestNet())
{
if (!(destinationAddress.startsWith("zc") ||
destinationAddress.startsWith("za") ||
destinationAddress.startsWith("t1") ||
destinationAddress.startsWith("t3")))
{
Expand Down Expand Up @@ -914,7 +915,7 @@ private void reportCompleteOperationToTheUser(String amount, String sourceAddres
String urlPrefix = "https://explorer.zel.cash/tx/";
if (installationObserver.isOnTestNet())
{
urlPrefix = "https://testnet.zelcash.online/tx/";
urlPrefix = "https://testnet.zel.cash/tx/";
}
Desktop.getDesktop().browse(new URL(urlPrefix + TXID).toURI());
}
Expand Down
4 changes: 2 additions & 2 deletions src/java/com/vaklinov/zcashui/ZCashClientCaller.java
Original file line number Diff line number Diff line change
Expand Up @@ -521,10 +521,10 @@ public synchronized String getUnconfirmedBalanceForAddress(String address)
}


public synchronized String createNewAddress(boolean isZAddress)
public synchronized String createNewAddress(boolean isZAddress, boolean isSapling)
throws WalletCallException, IOException, InterruptedException
{
String strResponse = this.executeCommandAndGetSingleStringResponse((isZAddress ? "z_" : "") + "getnewaddress");
String strResponse = this.executeCommandAndGetSingleStringResponse((isZAddress ? "z_" : "") + "getnewaddress", (isZAddress ? (isSapling ? "sapling" : "sprout") : ""));

return strResponse.trim();
}
Expand Down
6 changes: 3 additions & 3 deletions src/java/com/vaklinov/zcashui/msg/MessagingPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -660,15 +660,15 @@ public boolean openOwnIdentityDialog()
String TAddress = null;
for (int i = 0; i < 10; i++)
{
TAddress = this.clientCaller.createNewAddress(false);
TAddress = this.clientCaller.createNewAddress(false, false);
String balance = this.clientCaller.getBalanceForAddress(TAddress);
if (Double.valueOf(balance) <= 0)
{
break;
}
}

String ZAddress = this.clientCaller.createNewAddress(true);
// Generate sapling addresses for messages
String ZAddress = this.clientCaller.createNewAddress(true, true);

// Update the labels for the two addresses
this.labelStorage.setLabel(TAddress, langUtil.getString("messaging.panel.own.t"));
Expand Down
Binary file added src/resources/keys/sapling-output.params
Binary file not shown.
18 changes: 12 additions & 6 deletions src/resources/messages/zelcash_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ panel.address.book.table.address=address


panel.address.button.new.address=New T (Transparent) address
panel.address.button.new.z.address=New Z (Private) address
panel.address.button.new.z.address=New Z (Private) Sprout address
panel.address.button.new.sapling.address=New Z (Private) Sapling address
panel.address.button.refresh=Refresh
panel.address.label.warning=<html><span style=\font-size:0.8em;\> \
* If the balance of an address is flagged as not confirmed, the address is currently taking \
Expand Down Expand Up @@ -313,14 +314,19 @@ dialog.password.encryption.confirmation.label.text=Confirmation:\u0020
dialog.password.encryption.option.pane.mismatch.text=The password and the confirmation do not match!
dialog.password.encryption.option.pane.mismatch.title=Password mismatch...

proving.key.fetcher.option.pane.message=The ZelCash wallet cannot proceed without a proving key.
proving.key.fetcher.option.pane.verify.message=The wallet needs to download the Z cryptographic proving key (approx. 900 MB).\n\
proving.key.fetcher.option.pane.message=The ZelCash wallet cannot proceed without proving keys.
proving.key.fetcher.option.pane.verify.message=The wallet needs to download the Z cryptographic proving key (approx. 900 MB) and Sprout Groth parameter (700MB) and Sapling Spend parameter (50MB).\n\
This will be done only once. Please be patient... Press OK to continue
proving.key.fetcher.option.pane.verify.progress.text=Downloading proving key...
proving.key.fetcher.option.pane.verify.progress.text=Downloading Sapling and Sprout parameters...
proving.key.fetcher.option.pane.verify.progress.monitor.text=Downloading proving key
proving.key.fetcher.option.pane.verify.key.text=Verifying downloaded proving key...
proving.key.fetcher.option.pane.verify.key.failed.text=Failed to download proving key properly. Cannot continue!

sprout.groth.fetcher.option.pane.verify.progress.monitor.text=Downloading Sprout Groth parameter
sprout.groth.fetcher.option.pane.verify.key.text=Verifying downloaded Sprout Groth parameter...
sprout.groth.fetcher.option.pane.verify.key.failed.text=Failed to download Sprout Groth parameter properly. Cannot continue!
sapling.spend.fetcher.option.pane.verify.progress.monitor.text=Downloading Sapling Spend parameter
sapling.spend.fetcher.option.pane.verify.key.text=Verifying downloaded Sapling Spend parameter...
sapling.spend.fetcher.option.pane.verify.key.failed.text=Failed to download Sapling Spend parameter properly. Cannot continue!
send.cash.panel.label=Send cash from:\u0020\u0020\u0020\u0020\u0020\u0020\u0020
send.cash.panel.label.info=<html><span style=\"font-size:0.8em;\"> \
* Only addresses with a confirmed balance are shown as sources for sending! </span>
Expand Down Expand Up @@ -356,7 +362,7 @@ send.cash.panel.option.pane.error.destination.address.too.short=Destination addr
send.cash.panel.option.pane.error.destination.address.too.long=Destination address is invalid; it is too long.
send.cash.panel.option.pane.error.destination.address.has.spaces=Destination address is invalid; it has leading or trailing white-space characters.
send.cash.panel.option.pane.error.destination.address.incorrect.text=The destination address to send ZEL to: \n {0} \n\
does not appear to be a valid ZEL address. ZEL addresses start with zc, t1 or t3!
does not appear to be a valid ZEL address. ZEL addresses start with zc, za, t1 or t3!
send.cash.panel.option.pane.error.destination.address.incorrect.title=Destination address is incorrect...
send.cash.panel.option.pane.error.destination.address.notz.text=The destination address to send ZEL to: \n {0} \n\
does not appear to be a Z address. However a text memo is specified to be sent. A text memo may\nbe included in a \
Expand Down

0 comments on commit e8569c2

Please sign in to comment.