mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2026-07-31 12:06:15 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a4e9ef989d | ||
|
|
4ed8550f1d | ||
|
|
4bec71e7c4 | ||
|
|
961fd94dd6 | ||
|
|
7915bbfa47 | ||
|
|
49e70e8e9b | ||
|
|
6063b02113 | ||
|
|
faa5a11c94 | ||
|
|
acab50cdcd | ||
|
|
4d7d897e06 | ||
|
|
af532e7fc9 | ||
|
|
fd2b383dbc | ||
|
|
98b33e184e | ||
|
|
3bc7c7473a | ||
|
|
4f6981b869 | ||
|
|
258d46a253 | ||
|
|
40a3eb5d4f | ||
|
|
35965235f3 | ||
|
|
368b24ea3b | ||
|
|
107b5ba36c | ||
|
|
84978a3d5d | ||
|
|
dd3b980c36 | ||
|
|
b9a553abf2 | ||
|
|
48b3dbc353 | ||
|
|
fb40d991bb | ||
|
|
5fe6a7196a | ||
|
|
f06b859c82 | ||
|
|
80dd59928e | ||
|
|
f22f76464a | ||
|
|
dfe1f16495 | ||
|
|
90a9030ecb | ||
|
|
4ab33a373c | ||
|
|
10e751d6e1 | ||
|
|
5f40669af7 | ||
|
|
97b4ed48db | ||
|
|
9fc096569a | ||
|
|
41636f7152 | ||
|
|
fc5d48de6f | ||
|
|
2a7f14a4ed | ||
|
|
1cb6778502 | ||
|
|
7f254e763d | ||
|
|
e0ff42b6a4 | ||
|
|
88fc8f5017 | ||
|
|
d7072928de | ||
|
|
0cc9ddba05 | ||
|
|
e3799cd0a8 | ||
|
|
ea6b30326e | ||
|
|
38768885e2 | ||
|
|
c360177c31 | ||
|
|
e88ea0bac1 | ||
|
|
a66b36c59c | ||
|
|
fb3b674b65 | ||
|
|
eff0e201f3 | ||
|
|
58d10cbba4 | ||
|
|
29bce8a9bc |
@@ -7,7 +7,7 @@ jobs:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [windows-latest, ubuntu-latest, macos-latest]
|
||||
os: [windows-2022, ubuntu-20.04, macos-12]
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
|
||||
@@ -16,7 +16,7 @@ or for those without SSH credentials:
|
||||
|
||||
`git clone --recursive https://github.com/sparrowwallet/sparrow.git`
|
||||
|
||||
In order to build, Sparrow requires Java 17 or higher to be installed.
|
||||
In order to build, Sparrow requires Java 18 or higher to be installed.
|
||||
The release binaries are built with [Eclipse Temurin 18.0.1+10](https://github.com/adoptium/temurin18-binaries/releases/tag/jdk-18.0.1%2B10).
|
||||
|
||||
Other packages may also be necessary to build depending on the platform. On Debian/Ubuntu systems:
|
||||
@@ -44,7 +44,7 @@ If you prefer to run Sparrow directly from source, it can be launched from withi
|
||||
|
||||
`./sparrow`
|
||||
|
||||
Java 17 or higher must be installed.
|
||||
Java 18 or higher must be installed.
|
||||
|
||||
## Configuration
|
||||
|
||||
|
||||
+151
-39
@@ -4,10 +4,10 @@ plugins {
|
||||
id 'application'
|
||||
id 'org-openjfx-javafxplugin'
|
||||
id 'extra-java-module-info'
|
||||
id 'org.beryx.jlink' version '2.25.0'
|
||||
id 'org.beryx.jlink' version '2.26.0'
|
||||
}
|
||||
|
||||
def sparrowVersion = '1.7.2'
|
||||
def sparrowVersion = '1.7.4'
|
||||
def os = org.gradle.internal.os.OperatingSystem.current()
|
||||
def osName = os.getFamilyName()
|
||||
if(os.macOsX) {
|
||||
@@ -23,6 +23,19 @@ if(System.getProperty("os.arch") == "aarch64") {
|
||||
}
|
||||
def headless = "true".equals(System.getProperty("java.awt.headless"))
|
||||
|
||||
def vTor = '4.7.13-4'
|
||||
def vKmpTor = '1.4.2'
|
||||
def kmpOs = osName
|
||||
if(os.macOsX) {
|
||||
kmpOs = "macos"
|
||||
} else if(os.windows) {
|
||||
kmpOs = "mingw"
|
||||
}
|
||||
def kmpArch = "x64"
|
||||
if(System.getProperty("os.arch") == "aarch64") {
|
||||
kmpArch = "arm64"
|
||||
}
|
||||
|
||||
group "com.sparrowwallet"
|
||||
version "${sparrowVersion}"
|
||||
|
||||
@@ -84,10 +97,15 @@ dependencies {
|
||||
implementation("com.github.sarxos:webcam-capture${targetName}:0.3.13-SNAPSHOT") {
|
||||
exclude group: 'com.nativelibs4java', module: 'bridj'
|
||||
}
|
||||
implementation("com.sparrowwallet:netlayer-jpms-${osName}${targetName}:0.6.8") {
|
||||
exclude group: 'org.jetbrains.kotlin'
|
||||
implementation "io.matthewnelson.kotlin-components:kmp-tor:${vTor}-${vKmpTor}"
|
||||
if(kmpOs == "linux" && kmpArch == "arm64") {
|
||||
implementation("com.sparrowwallet.kmp-tor-binary:kmp-tor-binary-${kmpOs}${kmpArch}-jvm:${vTor}")
|
||||
} else {
|
||||
implementation("io.matthewnelson.kotlin-components:kmp-tor-binary-${kmpOs}${kmpArch}:${vTor}")
|
||||
}
|
||||
implementation('org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.20')
|
||||
implementation("io.matthewnelson.kotlin-components:kmp-tor-binary-extract:${vTor}")
|
||||
implementation("io.matthewnelson.kotlin-components:kmp-tor-ext-callback-manager:${vKmpTor}")
|
||||
implementation('org.jetbrains.kotlinx:kotlinx-coroutines-javafx:1.6.4')
|
||||
implementation('de.codecentric.centerdevice:centerdevice-nsmenufx:2.1.7')
|
||||
implementation('org.controlsfx:controlsfx:11.1.0' ) {
|
||||
exclude group: 'org.openjfx', module: 'javafx-base'
|
||||
@@ -103,12 +121,12 @@ dependencies {
|
||||
implementation('org.slf4j:jul-to-slf4j:1.7.30') {
|
||||
exclude group: 'org.slf4j'
|
||||
}
|
||||
implementation('com.sparrowwallet.nightjar:nightjar:0.2.34')
|
||||
implementation('com.sparrowwallet.nightjar:nightjar:0.2.36')
|
||||
implementation('io.reactivex.rxjava2:rxjava:2.2.15')
|
||||
implementation('io.reactivex.rxjava2:rxjavafx:2.2.2')
|
||||
implementation('org.apache.commons:commons-lang3:3.7')
|
||||
implementation('net.sourceforge.streamsupport:streamsupport:1.7.0')
|
||||
implementation('com.github.librepdf:openpdf:1.3.27')
|
||||
implementation('com.github.librepdf:openpdf:1.3.30')
|
||||
implementation('com.googlecode.lanterna:lanterna:3.1.1')
|
||||
implementation('net.coobird:thumbnailator:0.4.18')
|
||||
implementation('com.github.hervegirod:fxsvgimage:1.0b2')
|
||||
@@ -160,9 +178,11 @@ run {
|
||||
"--add-opens=javafx.graphics/com.sun.javafx.menu=centerdevice.nsmenufx",
|
||||
"--add-opens=javafx.graphics/com.sun.glass.ui=com.sparrowwallet.sparrow",
|
||||
"--add-opens=javafx.graphics/com.sun.javafx.application=com.sparrowwallet.sparrow",
|
||||
"--add-opens=javafx.graphics/javafx.scene.input=com.sparrowwallet.sparrow",
|
||||
"--add-opens=java.base/java.net=com.sparrowwallet.sparrow",
|
||||
"--add-opens=java.base/java.io=com.google.gson",
|
||||
"--add-opens=java.smartcardio/sun.security.smartcardio=com.sparrowwallet.sparrow"]
|
||||
"--add-opens=java.smartcardio/sun.security.smartcardio=com.sparrowwallet.sparrow",
|
||||
"--add-reads=kotlin.stdlib=kotlinx.coroutines.core.jvm"]
|
||||
|
||||
if(os.macOsX) {
|
||||
applicationDefaultJvmArgs += ["-Dprism.lcdtext=false", "-Xdock:name=Sparrow", "-Xdock:icon=/Users/scy/git/sparrow/src/main/resources/sparrow-large.png",
|
||||
@@ -208,6 +228,7 @@ jlink {
|
||||
"--add-opens=javafx.controls/com.sun.javafx.scene.control=centerdevice.nsmenufx",
|
||||
"--add-opens=javafx.graphics/com.sun.javafx.menu=centerdevice.nsmenufx",
|
||||
"--add-opens=javafx.graphics/com.sun.glass.ui=com.sparrowwallet.sparrow",
|
||||
"--add-opens=javafx.graphics/javafx.scene.input=com.sparrowwallet.sparrow",
|
||||
"--add-opens=javafx.graphics/com.sun.javafx.application=com.sparrowwallet.sparrow",
|
||||
"--add-opens=java.base/java.net=com.sparrowwallet.sparrow",
|
||||
"--add-opens=java.base/java.io=com.google.gson",
|
||||
@@ -219,7 +240,8 @@ jlink {
|
||||
"--add-reads=com.sparrowwallet.merged.module=com.fasterxml.jackson.databind",
|
||||
"--add-reads=com.sparrowwallet.merged.module=com.fasterxml.jackson.annotation",
|
||||
"--add-reads=com.sparrowwallet.merged.module=com.fasterxml.jackson.core",
|
||||
"--add-reads=com.sparrowwallet.merged.module=co.nstant.in.cbor"]
|
||||
"--add-reads=com.sparrowwallet.merged.module=co.nstant.in.cbor",
|
||||
"--add-reads=kotlin.stdlib=kotlinx.coroutines.core.jvm"]
|
||||
|
||||
if(os.windows) {
|
||||
jvmArgs += ["-Djavax.accessibility.assistive_technologies", "-Djavax.accessibility.screen_magnifier_present=false"]
|
||||
@@ -401,11 +423,6 @@ extraJavaModuleInfo {
|
||||
requires('java.xml')
|
||||
requires('java.logging')
|
||||
}
|
||||
module('kotlin-logging-1.5.4.jar', 'io.github.microutils.kotlin.logging', '1.5.4') {
|
||||
exports('mu')
|
||||
requires('kotlin.stdlib')
|
||||
requires('org.slf4j')
|
||||
}
|
||||
module('failureaccess-1.0.1.jar', 'failureaccess', '1.0.1') {
|
||||
exports('com.google.common.util.concurrent.internal')
|
||||
}
|
||||
@@ -481,13 +498,6 @@ extraJavaModuleInfo {
|
||||
requires('javafx.graphics')
|
||||
}
|
||||
module('jai-imageio-core-1.4.0.jar', 'com.github.jai.imageio.jai.imageio.core', '1.4.0')
|
||||
module('kotlin-stdlib-jdk8-1.5.20.jar', 'org.jetbrains.kotlin.kotlin.stdlib.jdk8', '1.5.20')
|
||||
module('kotlin-stdlib-jdk7-1.5.20.jar', 'org.jetbrains.kotlin.kotlin.stdlib.jdk7', '1.5.20')
|
||||
module('kotlin-stdlib-1.5.20.jar', 'kotlin.stdlib', '1.5.20') {
|
||||
exports('kotlin')
|
||||
exports('kotlin.jvm')
|
||||
exports('kotlin.collections')
|
||||
}
|
||||
module('hummingbird-1.6.3.jar', 'com.sparrowwallet.hummingbird', '1.6.3') {
|
||||
exports('com.sparrowwallet.hummingbird')
|
||||
exports('com.sparrowwallet.hummingbird.registry')
|
||||
@@ -498,7 +508,7 @@ extraJavaModuleInfo {
|
||||
exports('co.nstant.in.cbor.model')
|
||||
exports('co.nstant.in.cbor.builder')
|
||||
}
|
||||
module('nightjar-0.2.34.jar', 'com.sparrowwallet.nightjar', '0.2.34') {
|
||||
module('nightjar-0.2.36.jar', 'com.sparrowwallet.nightjar', '0.2.36') {
|
||||
requires('com.google.common')
|
||||
requires('net.sourceforge.streamsupport')
|
||||
requires('org.slf4j')
|
||||
@@ -595,29 +605,131 @@ extraJavaModuleInfo {
|
||||
requires('javafx.graphics')
|
||||
requires('java.xml')
|
||||
}
|
||||
module("netlayer-jpms-${osName}${targetName}-0.6.8.jar", 'netlayer.jpms', '0.6.8') {
|
||||
exports('org.berndpruenster.netlayer.tor')
|
||||
requires('com.github.ravn.jsocks')
|
||||
requires('com.github.JesusMcCloud.jtorctl')
|
||||
module('kotlinx-coroutines-core-jvm-1.6.4.jar', 'kotlinx.coroutines.core.jvm', '1.6.4') {
|
||||
exports('kotlinx.coroutines')
|
||||
requires('kotlin.stdlib')
|
||||
requires('commons.compress')
|
||||
requires('org.tukaani.xz')
|
||||
requires('java.instrument')
|
||||
uses('kotlinx.coroutines.CoroutineExceptionHandler')
|
||||
uses('kotlinx.coroutines.internal.MainDispatcherFactory')
|
||||
}
|
||||
module('kotlinx-coroutines-javafx-1.6.4.jar', 'kotlinx.coroutines.javafx', '1.6.4') {
|
||||
exports('kotlinx.coroutines.javafx')
|
||||
requires('kotlinx.coroutines.core.jvm')
|
||||
requires('kotlin.stdlib')
|
||||
requires('javafx.graphics')
|
||||
}
|
||||
module("kmp-tor-jvm-${vKmpTor}.jar", 'kmp.tor.jvm', "${vTor}-${vKmpTor}") {
|
||||
exports('io.matthewnelson.kmp.tor')
|
||||
requires('kmp.tor.binary.extract.jvm')
|
||||
requires('kmp.tor.manager.jvm')
|
||||
requires('kmp.tor.manager.common.jvm')
|
||||
requires('kmp.tor.controller.common.jvm')
|
||||
requires('kotlin.stdlib')
|
||||
requires('kotlinx.coroutines.core.jvm')
|
||||
requires('java.management')
|
||||
requires('io.github.microutils.kotlin.logging')
|
||||
}
|
||||
module('jtorctl-1.5.jar', 'com.github.JesusMcCloud.jtorctl', '1.5') {
|
||||
exports('net.freehaven.tor.control')
|
||||
if(kmpOs == "linux" && kmpArch == "arm64") {
|
||||
module("kmp-tor-binary-${kmpOs}${kmpArch}-jvm-${vTor}.jar", "kmp.tor.binary.${kmpOs}${kmpArch}", "${vTor}") {
|
||||
exports("io.matthewnelson.kmp.tor.resource.${kmpOs}.${kmpArch}")
|
||||
exports("kmptor.${kmpOs}.${kmpArch}")
|
||||
}
|
||||
} else {
|
||||
module("kmp-tor-binary-${kmpOs}${kmpArch}-jvm-${vTor}.jar", "kmp.tor.binary.${kmpOs}${kmpArch}", "${vTor}") {
|
||||
exports("io.matthewnelson.kmp.tor.binary.${kmpOs}.${kmpArch}")
|
||||
exports("kmptor.${kmpOs}.${kmpArch}")
|
||||
}
|
||||
}
|
||||
module('commons-compress-1.18.jar', 'commons.compress', '1.18') {
|
||||
exports('org.apache.commons.compress')
|
||||
requires('org.tukaani.xz')
|
||||
module("kmp-tor-binary-extract-jvm-${vTor}.jar", 'kmp.tor.binary.extract.jvm', "${vTor}") {
|
||||
exports('io.matthewnelson.kmp.tor.binary.extract')
|
||||
exports('io.matthewnelson.kmp.tor.binary.extract.internal')
|
||||
requires('kotlin.stdlib')
|
||||
requires("kmp.tor.binary.${kmpOs}${kmpArch}")
|
||||
requires('kmp.tor.binary.geoip.jvm')
|
||||
}
|
||||
module('xz-1.6.jar', 'org.tukaani.xz', '1.6') {
|
||||
exports('org.tukaani.xz')
|
||||
module("kmp-tor-manager-jvm-${vKmpTor}.jar", 'kmp.tor.manager.jvm', "${vKmpTor}") {
|
||||
exports('io.matthewnelson.kmp.tor.manager')
|
||||
exports('io.matthewnelson.kmp.tor.manager.util')
|
||||
requires('kmp.tor.controller.common.jvm')
|
||||
requires('kmp.tor.manager.common.jvm')
|
||||
requires('kotlin.stdlib')
|
||||
requires('kotlinx.coroutines.core.jvm')
|
||||
requires('kotlinx.atomicfu')
|
||||
requires('kmp.tor.controller.jvm')
|
||||
requires('kmp.tor.common.jvm')
|
||||
}
|
||||
module('jsocks-1.0.jar', 'com.github.ravn.jsocks', '1.0') {
|
||||
exports('com.runjva.sourceforge.jsocks.protocol')
|
||||
requires('org.slf4j')
|
||||
module("kmp-tor-manager-common-jvm-${vKmpTor}.jar", 'kmp.tor.manager.common.jvm', "${vKmpTor}") {
|
||||
exports('io.matthewnelson.kmp.tor.manager.common')
|
||||
exports('io.matthewnelson.kmp.tor.manager.common.event')
|
||||
exports('io.matthewnelson.kmp.tor.manager.common.state')
|
||||
requires('kmp.tor.controller.common.jvm')
|
||||
requires('kmp.tor.common.jvm')
|
||||
requires('kotlin.stdlib')
|
||||
}
|
||||
module("kmp-tor-controller-common-jvm-${vKmpTor}.jar", 'kmp.tor.controller.common.jvm', "${vKmpTor}") {
|
||||
exports('io.matthewnelson.kmp.tor.controller.common.config')
|
||||
exports('io.matthewnelson.kmp.tor.controller.common.file')
|
||||
exports('io.matthewnelson.kmp.tor.controller.common.control')
|
||||
exports('io.matthewnelson.kmp.tor.controller.common.control.usecase')
|
||||
exports('io.matthewnelson.kmp.tor.controller.common.events')
|
||||
exports('io.matthewnelson.kmp.tor.controller.common.exceptions')
|
||||
requires('kmp.tor.common.jvm')
|
||||
requires('kotlin.stdlib')
|
||||
requires('kotlinx.atomicfu')
|
||||
}
|
||||
module("kmp-tor-common-jvm-${vKmpTor}.jar", 'kmp.tor.common.jvm', "${vKmpTor}") {
|
||||
exports('io.matthewnelson.kmp.tor.common.address')
|
||||
requires('parcelize.jvm')
|
||||
requires('kotlin.stdlib')
|
||||
}
|
||||
module("kmp-tor-controller-jvm-${vKmpTor}.jar", 'kmp.tor.controller.jvm', "${vKmpTor}") {
|
||||
exports('io.matthewnelson.kmp.tor.controller.internal.controller')
|
||||
requires('kmp.tor.common.jvm')
|
||||
requires('kmp.tor.controller.common.jvm')
|
||||
requires('kotlinx.coroutines.core.jvm')
|
||||
requires('kotlin.stdlib')
|
||||
requires('kotlinx.atomicfu')
|
||||
requires('encoding.core.jvm')
|
||||
requires('encoding.base16.jvm')
|
||||
}
|
||||
module("kmp-tor-ext-callback-common-jvm-${vKmpTor}.jar", 'kmp.tor.ext.callback.common.jvm', "${vKmpTor}") {
|
||||
exports('io.matthewnelson.kmp.tor.ext.callback.common')
|
||||
}
|
||||
module("kmp-tor-ext-callback-manager-jvm-${vKmpTor}.jar", 'kmp.tor.ext.callback.manager.jvm', "${vKmpTor}") {
|
||||
exports('io.matthewnelson.kmp.tor.ext.callback.manager')
|
||||
requires('kmp.tor.manager.jvm')
|
||||
requires('kmp.tor.ext.callback.common.jvm')
|
||||
requires('kmp.tor.ext.callback.manager.common.jvm')
|
||||
requires('kmp.tor.ext.callback.controller.common.jvm')
|
||||
requires('kmp.tor.manager.common.jvm')
|
||||
requires('kmp.tor.controller.common.jvm')
|
||||
requires('kotlin.stdlib')
|
||||
requires('kotlinx.coroutines.core.jvm')
|
||||
}
|
||||
module("kmp-tor-ext-callback-manager-common-jvm-${vKmpTor}.jar", 'kmp.tor.ext.callback.manager.common.jvm', "${vKmpTor}") {
|
||||
exports('io.matthewnelson.kmp.tor.ext.callback.manager.common')
|
||||
requires('kmp.tor.ext.callback.controller.common.jvm')
|
||||
}
|
||||
module("kmp-tor-ext-callback-controller-common-jvm-${vKmpTor}.jar", 'kmp.tor.ext.callback.controller.common.jvm', "${vKmpTor}") {
|
||||
exports('io.matthewnelson.kmp.tor.ext.callback.controller.common.control')
|
||||
exports('io.matthewnelson.kmp.tor.ext.callback.controller.common.control.usecase')
|
||||
}
|
||||
module("kmp-tor-binary-geoip-jvm-${vTor}.jar", 'kmp.tor.binary.geoip.jvm', "${vTor}") {
|
||||
exports('io.matthewnelson.kmp.tor.binary.geoip')
|
||||
exports('kmptor')
|
||||
}
|
||||
module("encoding-base16-jvm-1.2.1.jar", 'encoding.base16.jvm', "1.2.1") {
|
||||
exports('io.matthewnelson.encoding.base16')
|
||||
requires('encoding.core.jvm')
|
||||
requires('kotlin.stdlib')
|
||||
}
|
||||
module("encoding-base32-jvm-1.2.1.jar", 'encoding.base32.jvm', "1.2.1")
|
||||
module("encoding-base64-jvm-1.2.1.jar", 'encoding.base64.jvm', "1.2.1")
|
||||
module("encoding-core-jvm-1.2.1.jar", 'encoding.core.jvm', "1.2.1") {
|
||||
exports('io.matthewnelson.encoding.core')
|
||||
requires('kotlin.stdlib')
|
||||
}
|
||||
module("parcelize-jvm-0.1.2.jar", 'parcelize.jvm', "0.1.2") {
|
||||
exports('io.matthewnelson.component.parcelize')
|
||||
}
|
||||
module('jnacl-1.0.0.jar', 'eu.neilalexander.jnacl', '1.0.0')
|
||||
module('logback-core-1.2.8.jar', 'logback.core', '1.2.8') {
|
||||
|
||||
@@ -82,7 +82,7 @@ sudo apt install -y rpm fakeroot binutils
|
||||
First, assign a temporary variable in your shell for the specific release you want to build. For the current one specify:
|
||||
|
||||
```shell
|
||||
GIT_TAG="1.7.2"
|
||||
GIT_TAG="1.7.3"
|
||||
```
|
||||
|
||||
The project can then be initially cloned as follows:
|
||||
|
||||
+1
-1
Submodule drongo updated: d48054ac6b...fe19c86544
@@ -6,4 +6,5 @@ Icon=/opt/sparrow/lib/Sparrow.png
|
||||
Terminal=false
|
||||
Type=Application
|
||||
Categories=Finance;Network;
|
||||
MimeType=application/psbt;application/bitcoin-transaction;x-scheme-handler/bitcoin;x-scheme-handler/auth47;x-scheme-handler/lightning
|
||||
MimeType=application/psbt;application/bitcoin-transaction;x-scheme-handler/bitcoin;x-scheme-handler/auth47;x-scheme-handler/lightning
|
||||
StartupWMClass=Sparrow
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.7.2</string>
|
||||
<string>1.7.4</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<!-- See https://developer.apple.com/app-store/categories/ for list of AppStore categories -->
|
||||
|
||||
@@ -753,7 +753,7 @@ public class AppController implements Initializable {
|
||||
writer.print(transactionTabData.getPsbt().toBase64String(includeXpubs));
|
||||
writer.flush();
|
||||
} else {
|
||||
outputStream.write(transactionTabData.getPsbt().serialize(includeXpubs));
|
||||
outputStream.write(transactionTabData.getPsbt().serialize(includeXpubs, true));
|
||||
}
|
||||
} catch(IOException e) {
|
||||
log.error("Error saving PSBT", e);
|
||||
@@ -1073,7 +1073,18 @@ public class AppController implements Initializable {
|
||||
Optional<Wallet> optionalWallet = dlg.showAndWait();
|
||||
if(optionalWallet.isPresent()) {
|
||||
Wallet wallet = optionalWallet.get();
|
||||
if(selectedWalletForms.isEmpty() || wallet != selectedWalletForms.get(0).getWallet()) {
|
||||
|
||||
List<WalletTabData> walletTabData = getOpenWalletTabData();
|
||||
List<ExtendedKey> xpubs = wallet.getKeystores().stream().map(Keystore::getExtendedPublicKey).collect(Collectors.toList());
|
||||
Optional<WalletForm> optNewWalletForm = walletTabData.stream()
|
||||
.map(WalletTabData::getWalletForm)
|
||||
.filter(wf -> wf.getSettingsWalletForm() != null && wf.getSettingsWalletForm().getWallet().getPolicyType() == PolicyType.MULTI &&
|
||||
wf.getSettingsWalletForm().getWallet().getScriptType() == wallet.getScriptType() && !wf.getSettingsWalletForm().getWallet().isValid() &&
|
||||
wf.getSettingsWalletForm().getWallet().getKeystores().stream().map(Keystore::getExtendedPublicKey).anyMatch(xpubs::contains)).findFirst();
|
||||
if(optNewWalletForm.isPresent()) {
|
||||
EventManager.get().post(new ExistingWalletImportedEvent(optNewWalletForm.get().getWalletId(), wallet));
|
||||
selectTab(optNewWalletForm.get().getWallet());
|
||||
} else if(selectedWalletForms.isEmpty() || wallet != selectedWalletForms.get(0).getWallet()) {
|
||||
addImportedWallet(wallet);
|
||||
}
|
||||
}
|
||||
@@ -1117,7 +1128,7 @@ public class AppController implements Initializable {
|
||||
}
|
||||
|
||||
private void addImportedWallet(Wallet wallet) {
|
||||
WalletNameDialog nameDlg = new WalletNameDialog(wallet.getName());
|
||||
WalletNameDialog nameDlg = new WalletNameDialog(wallet.getName(), true, wallet.getBirthDate());
|
||||
Optional<WalletNameDialog.NameAndBirthDate> optNameAndBirthDate = nameDlg.showAndWait();
|
||||
if(optNameAndBirthDate.isPresent()) {
|
||||
WalletNameDialog.NameAndBirthDate nameAndBirthDate = optNameAndBirthDate.get();
|
||||
|
||||
@@ -50,7 +50,6 @@ import javafx.stage.Screen;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.stage.Window;
|
||||
import javafx.util.Duration;
|
||||
import org.berndpruenster.netlayer.tor.Tor;
|
||||
import org.controlsfx.glyphfont.Glyph;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -252,7 +251,7 @@ public class AppServices {
|
||||
}
|
||||
|
||||
if(Tor.getDefault() != null) {
|
||||
Tor.getDefault().shutdown();
|
||||
Tor.getDefault().getTorManager().destroy(true, success -> {});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -414,23 +413,6 @@ public class AppServices {
|
||||
EventManager.get().post(new TorReadyStatusEvent());
|
||||
});
|
||||
torService.setOnFailed(workerStateEvent -> {
|
||||
Throwable exception = workerStateEvent.getSource().getException();
|
||||
if(exception instanceof TorServerAlreadyBoundException) {
|
||||
String proxyServer = Config.get().getProxyServer();
|
||||
if(proxyServer == null || proxyServer.equals("")) {
|
||||
proxyServer = "localhost:9050";
|
||||
Config.get().setProxyServer(proxyServer);
|
||||
}
|
||||
|
||||
if(proxyServer.equals("localhost:9050") || proxyServer.equals("127.0.0.1:9050")) {
|
||||
Config.get().setUseProxy(true);
|
||||
torService.cancel();
|
||||
restartServices();
|
||||
EventManager.get().post(new TorExternalStatusEvent());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
EventManager.get().post(new TorFailedStatusEvent(workerStateEvent.getSource().getException()));
|
||||
});
|
||||
|
||||
@@ -490,8 +472,7 @@ public class AppServices {
|
||||
InetSocketAddress proxyAddress = new InetSocketAddress(proxyHostAndPort.getHost(), proxyHostAndPort.getPortOrDefault(ProxyTcpOverTlsTransport.DEFAULT_PROXY_PORT));
|
||||
proxy = new Proxy(Proxy.Type.SOCKS, proxyAddress);
|
||||
} else if(AppServices.isTorRunning()) {
|
||||
InetSocketAddress proxyAddress = new InetSocketAddress("localhost", TorService.PROXY_PORT);
|
||||
proxy = new Proxy(Proxy.Type.SOCKS, proxyAddress);
|
||||
proxy = Tor.getDefault().getProxy();
|
||||
}
|
||||
|
||||
//Setting new proxy authentication credentials will force a new Tor circuit to be created
|
||||
@@ -546,7 +527,7 @@ public class AppServices {
|
||||
|
||||
public static HostAndPort getTorProxy() {
|
||||
return AppServices.isTorRunning() ?
|
||||
HostAndPort.fromParts("localhost", TorService.PROXY_PORT) :
|
||||
Tor.getDefault().getProxyHostAndPort() :
|
||||
(Config.get().getProxyServer() == null || Config.get().getProxyServer().isEmpty() || !Config.get().isUseProxy() ? null : HostAndPort.fromString(Config.get().getProxyServer()));
|
||||
}
|
||||
|
||||
@@ -811,6 +792,24 @@ public class AppServices {
|
||||
}
|
||||
}
|
||||
|
||||
public static void openBlockExplorer(String txid) {
|
||||
if(Config.get().isBlockExplorerDisabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Server blockExplorer = Config.get().getBlockExplorer() == null ? BlockExplorer.MEMPOOL_SPACE.getServer() : Config.get().getBlockExplorer();
|
||||
String url = blockExplorer.getUrl();
|
||||
if(url.contains("{0}")) {
|
||||
url = url.replace("{0}", txid);
|
||||
} else {
|
||||
if(Network.get() != Network.MAINNET) {
|
||||
url += "/" + Network.get().getName();
|
||||
}
|
||||
url += "/tx/" + txid;
|
||||
}
|
||||
AppServices.get().getApplication().getHostServices().showDocument(url);
|
||||
}
|
||||
|
||||
static void parseFileUriArguments(List<String> fileUriArguments) {
|
||||
for(String fileUri : fileUriArguments) {
|
||||
try {
|
||||
|
||||
@@ -25,7 +25,7 @@ public abstract class BaseController {
|
||||
scriptArea.setMouseOverTextDelay(Duration.ofMillis(150));
|
||||
scriptArea.addEventHandler(MouseOverTextEvent.MOUSE_OVER_TEXT_BEGIN, e -> {
|
||||
TwoDimensional.Position position = scriptArea.getParagraph(0).getStyleSpans().offsetToPosition(e.getCharacterIndex(), Backward);
|
||||
if(position.getMajor() % 2 == 0) {
|
||||
if(position.getMajor() % 2 == 0 && scriptArea.getScript().getChunks().size() > position.getMajor() / 2) {
|
||||
ScriptChunk hoverChunk = scriptArea.getScript().getChunks().get(position.getMajor()/2);
|
||||
if(!hoverChunk.isOpCode()) {
|
||||
Point2D pos = e.getScreenPosition();
|
||||
|
||||
@@ -18,7 +18,7 @@ import java.util.*;
|
||||
public class SparrowWallet {
|
||||
public static final String APP_ID = "com.sparrowwallet.sparrow";
|
||||
public static final String APP_NAME = "Sparrow";
|
||||
public static final String APP_VERSION = "1.7.2";
|
||||
public static final String APP_VERSION = "1.7.4";
|
||||
public static final String APP_VERSION_SUFFIX = "";
|
||||
public static final String APP_HOME_PROPERTY = "sparrow.home";
|
||||
public static final String NETWORK_ENV_PROPERTY = "SPARROW_NETWORK";
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
package com.sparrowwallet.sparrow;
|
||||
|
||||
import com.sparrowwallet.drongo.LogHandler;
|
||||
import com.sparrowwallet.sparrow.event.TorStatusEvent;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.slf4j.event.Level;
|
||||
|
||||
public class TorLogHandler implements LogHandler {
|
||||
private static final Logger log = LoggerFactory.getLogger(TorLogHandler.class);
|
||||
|
||||
@Override
|
||||
public void handleLog(String threadName, Level level, String message, String loggerName, long timestamp, StackTraceElement[] callerData) {
|
||||
log.debug(message);
|
||||
EventManager.get().post(new TorStatusEvent(message));
|
||||
}
|
||||
}
|
||||
@@ -4,15 +4,16 @@ import com.sparrowwallet.drongo.BitcoinUnit;
|
||||
import com.sparrowwallet.drongo.protocol.Transaction;
|
||||
import com.sparrowwallet.drongo.wallet.BlockTransactionHash;
|
||||
import com.sparrowwallet.sparrow.UnitFormat;
|
||||
import com.sparrowwallet.sparrow.io.Config;
|
||||
import com.sparrowwallet.sparrow.wallet.Entry;
|
||||
import com.sparrowwallet.sparrow.wallet.HashIndexEntry;
|
||||
import com.sparrowwallet.sparrow.wallet.TransactionEntry;
|
||||
import com.sparrowwallet.sparrow.wallet.UtxoEntry;
|
||||
import javafx.beans.property.IntegerProperty;
|
||||
import javafx.beans.property.SimpleIntegerProperty;
|
||||
import javafx.scene.control.ContentDisplay;
|
||||
import javafx.scene.control.Tooltip;
|
||||
import javafx.scene.control.TreeTableCell;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.input.Clipboard;
|
||||
import javafx.scene.input.ClipboardContent;
|
||||
import javafx.scene.layout.Region;
|
||||
import javafx.util.Duration;
|
||||
import org.controlsfx.tools.Platform;
|
||||
@@ -21,6 +22,7 @@ import java.text.DecimalFormat;
|
||||
|
||||
class CoinCell extends TreeTableCell<Entry, Number> implements ConfirmationsListener {
|
||||
private final CoinTooltip tooltip;
|
||||
private final CoinContextMenu contextMenu;
|
||||
|
||||
private IntegerProperty confirmationsProperty;
|
||||
|
||||
@@ -28,6 +30,7 @@ class CoinCell extends TreeTableCell<Entry, Number> implements ConfirmationsList
|
||||
super();
|
||||
tooltip = new CoinTooltip();
|
||||
tooltip.setShowDelay(Duration.millis(500));
|
||||
contextMenu = new CoinContextMenu();
|
||||
getStyleClass().add("coin-cell");
|
||||
if(Platform.getCurrent() == Platform.OSX) {
|
||||
getStyleClass().add("number-field");
|
||||
@@ -42,6 +45,7 @@ class CoinCell extends TreeTableCell<Entry, Number> implements ConfirmationsList
|
||||
setText(null);
|
||||
setGraphic(null);
|
||||
setTooltip(null);
|
||||
setContextMenu(null);
|
||||
} else {
|
||||
Entry entry = getTreeTableView().getTreeItem(getIndex()).getValue();
|
||||
EntryCell.applyRowStyles(this, entry);
|
||||
@@ -62,6 +66,8 @@ class CoinCell extends TreeTableCell<Entry, Number> implements ConfirmationsList
|
||||
setText(satsValue);
|
||||
}
|
||||
setTooltip(tooltip);
|
||||
contextMenu.updateAmount(amount);
|
||||
setContextMenu(contextMenu);
|
||||
|
||||
if(entry instanceof TransactionEntry transactionEntry) {
|
||||
tooltip.showConfirmations(transactionEntry.confirmationsProperty());
|
||||
@@ -155,4 +161,36 @@ class CoinCell extends TreeTableCell<Entry, Number> implements ConfirmationsList
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class CoinContextMenu extends ContextMenu {
|
||||
private Number amount;
|
||||
|
||||
public void updateAmount(Number amount) {
|
||||
if(amount.equals(this.amount)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.amount = amount;
|
||||
getItems().clear();
|
||||
|
||||
MenuItem copySatsValue = new MenuItem("Copy Value in sats");
|
||||
copySatsValue.setOnAction(AE -> {
|
||||
hide();
|
||||
ClipboardContent content = new ClipboardContent();
|
||||
content.putString(amount.toString());
|
||||
Clipboard.getSystemClipboard().setContent(content);
|
||||
});
|
||||
|
||||
MenuItem copyBtcValue = new MenuItem("Copy Value in BTC");
|
||||
copyBtcValue.setOnAction(AE -> {
|
||||
hide();
|
||||
ClipboardContent content = new ClipboardContent();
|
||||
UnitFormat format = Config.get().getUnitFormat() == null ? UnitFormat.DOT : Config.get().getUnitFormat();
|
||||
content.putString(format.formatBtcValue(amount.longValue()));
|
||||
Clipboard.getSystemClipboard().setContent(content);
|
||||
});
|
||||
|
||||
getItems().addAll(copySatsValue, copyBtcValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -537,6 +537,13 @@ public class EntryCell extends TreeTableCell<Entry, Entry> implements Confirmati
|
||||
getItems().add(createCpfp);
|
||||
}
|
||||
|
||||
MenuItem openBlockExplorer = new MenuItem("Open in Block Explorer");
|
||||
openBlockExplorer.setOnAction(AE -> {
|
||||
hide();
|
||||
AppServices.openBlockExplorer(blockTransaction.getHashAsString());
|
||||
});
|
||||
getItems().add(openBlockExplorer);
|
||||
|
||||
MenuItem copyTxid = new MenuItem("Copy Transaction ID");
|
||||
copyTxid.setOnAction(AE -> {
|
||||
hide();
|
||||
@@ -558,6 +565,12 @@ public class EntryCell extends TreeTableCell<Entry, Entry> implements Confirmati
|
||||
EventManager.get().post(new ViewTransactionEvent(this.getOwnerWindow(), blockTransaction));
|
||||
});
|
||||
|
||||
MenuItem openBlockExplorer = new MenuItem("Open in Block Explorer");
|
||||
openBlockExplorer.setOnAction(AE -> {
|
||||
hide();
|
||||
AppServices.openBlockExplorer(blockTransaction.getHashAsString());
|
||||
});
|
||||
|
||||
MenuItem copyDate = new MenuItem("Copy Date");
|
||||
copyDate.setOnAction(AE -> {
|
||||
hide();
|
||||
@@ -582,7 +595,7 @@ public class EntryCell extends TreeTableCell<Entry, Entry> implements Confirmati
|
||||
Clipboard.getSystemClipboard().setContent(content);
|
||||
});
|
||||
|
||||
getItems().addAll(viewTransaction, copyDate, copyTxid, copyHeight);
|
||||
getItems().addAll(viewTransaction, openBlockExplorer, copyDate, copyTxid, copyHeight);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -162,8 +162,8 @@ public abstract class FileImportPane extends TitledDescriptionPane {
|
||||
setError("Import Error", e.getMessage());
|
||||
}
|
||||
} else if(result.outputDescriptor != null) {
|
||||
wallets = List.of(result.outputDescriptor.toKeystoreWallet(null));
|
||||
try {
|
||||
wallets = List.of(result.outputDescriptor.toWallet());
|
||||
importFile(importer.getName(), null, null);
|
||||
} catch(ImportException e) {
|
||||
log.error("Error importing QR", e);
|
||||
@@ -193,6 +193,10 @@ public abstract class FileImportPane extends TitledDescriptionPane {
|
||||
}
|
||||
}
|
||||
|
||||
protected List<Wallet> getScannedWallets() {
|
||||
return wallets;
|
||||
}
|
||||
|
||||
protected Keystore getScannedKeystore(ScriptType scriptType) throws ImportException {
|
||||
if(wallets != null) {
|
||||
for(Wallet wallet : wallets) {
|
||||
@@ -215,7 +219,7 @@ public abstract class FileImportPane extends TitledDescriptionPane {
|
||||
|
||||
private Node getPasswordEntry(File file) {
|
||||
CustomPasswordField passwordField = new ViewPasswordField();
|
||||
passwordField.setPromptText("Wallet password");
|
||||
passwordField.setPromptText("Password");
|
||||
password.bind(passwordField.textProperty());
|
||||
HBox.setHgrow(passwordField, Priority.ALWAYS);
|
||||
|
||||
|
||||
@@ -0,0 +1,168 @@
|
||||
package com.sparrowwallet.sparrow.control;
|
||||
|
||||
import com.sparrowwallet.drongo.protocol.ScriptType;
|
||||
import com.sparrowwallet.drongo.wallet.Keystore;
|
||||
import com.sparrowwallet.drongo.wallet.KeystoreSource;
|
||||
import com.sparrowwallet.drongo.wallet.Wallet;
|
||||
import com.sparrowwallet.hummingbird.registry.RegistryType;
|
||||
import com.sparrowwallet.sparrow.AppServices;
|
||||
import com.sparrowwallet.sparrow.EventManager;
|
||||
import com.sparrowwallet.sparrow.event.KeystoreExportEvent;
|
||||
import com.sparrowwallet.sparrow.glyphfont.FontAwesome5;
|
||||
import com.sparrowwallet.sparrow.io.*;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.ButtonType;
|
||||
import javafx.scene.control.Control;
|
||||
import javafx.scene.control.ToggleButton;
|
||||
import javafx.stage.FileChooser;
|
||||
import javafx.stage.Stage;
|
||||
import org.controlsfx.control.SegmentedButton;
|
||||
import org.controlsfx.glyphfont.Glyph;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class FileKeystoreExportPane extends TitledDescriptionPane {
|
||||
private final Keystore keystore;
|
||||
private final KeystoreFileExport exporter;
|
||||
private final boolean scannable;
|
||||
private final boolean file;
|
||||
|
||||
public FileKeystoreExportPane(Keystore keystore, KeystoreFileExport exporter) {
|
||||
super(exporter.getName(), "Keystore export", exporter.getKeystoreExportDescription(), "image/" + exporter.getWalletModel().getType() + ".png");
|
||||
this.keystore = keystore;
|
||||
this.exporter = exporter;
|
||||
this.scannable = exporter.isKeystoreExportScannable();
|
||||
this.file = exporter.isKeystoreExportFile();
|
||||
|
||||
buttonBox.getChildren().clear();
|
||||
buttonBox.getChildren().add(createButton());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Control createButton() {
|
||||
if(scannable && file) {
|
||||
ToggleButton showButton = new ToggleButton("Show...");
|
||||
Glyph cameraGlyph = new Glyph(FontAwesome5.FONT_NAME, FontAwesome5.Glyph.CAMERA);
|
||||
cameraGlyph.setFontSize(12);
|
||||
showButton.setGraphic(cameraGlyph);
|
||||
showButton.setOnAction(event -> {
|
||||
showButton.setSelected(false);
|
||||
exportQR();
|
||||
});
|
||||
|
||||
ToggleButton fileButton = new ToggleButton("Export File...");
|
||||
fileButton.setAlignment(Pos.CENTER_RIGHT);
|
||||
fileButton.setOnAction(event -> {
|
||||
fileButton.setSelected(false);
|
||||
exportFile();
|
||||
});
|
||||
|
||||
SegmentedButton segmentedButton = new SegmentedButton();
|
||||
segmentedButton.getButtons().addAll(showButton, fileButton);
|
||||
return segmentedButton;
|
||||
} else if(scannable) {
|
||||
Button showButton = new Button("Show...");
|
||||
Glyph cameraGlyph = new Glyph(FontAwesome5.FONT_NAME, FontAwesome5.Glyph.CAMERA);
|
||||
cameraGlyph.setFontSize(12);
|
||||
showButton.setGraphic(cameraGlyph);
|
||||
showButton.setOnAction(event -> {
|
||||
exportQR();
|
||||
});
|
||||
return showButton;
|
||||
} else {
|
||||
Button exportButton = new Button("Export File...");
|
||||
exportButton.setAlignment(Pos.CENTER_RIGHT);
|
||||
exportButton.setOnAction(event -> {
|
||||
exportFile();
|
||||
});
|
||||
return exportButton;
|
||||
}
|
||||
}
|
||||
|
||||
private void exportQR() {
|
||||
exportKeystore(null, keystore);
|
||||
}
|
||||
|
||||
private void exportFile() {
|
||||
Stage window = new Stage();
|
||||
|
||||
FileChooser fileChooser = new FileChooser();
|
||||
fileChooser.setTitle("Export " + exporter.getWalletModel().toDisplayString() + " File");
|
||||
String extension = exporter.getExportFileExtension(keystore);
|
||||
String fileName = keystore.getLabel();
|
||||
fileChooser.setInitialFileName(fileName + (extension == null || extension.isEmpty() ? "" : "." + extension));
|
||||
|
||||
AppServices.moveToActiveWindowScreen(window, 800, 450);
|
||||
File file = fileChooser.showSaveDialog(window);
|
||||
if(file != null) {
|
||||
exportKeystore(file, keystore);
|
||||
}
|
||||
}
|
||||
|
||||
private void exportKeystore(File file, Keystore exportKeystore) {
|
||||
try {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
exporter.exportKeystore(exportKeystore, baos);
|
||||
|
||||
if(exporter.requiresSignature()) {
|
||||
String message = baos.toString(StandardCharsets.UTF_8);
|
||||
|
||||
if(keystore.getSource() == KeystoreSource.HW_USB || keystore.getWalletModel().isCard()) {
|
||||
TextAreaDialog dialog = new TextAreaDialog(message, false);
|
||||
dialog.setTitle("Sign " + exporter.getName() + " Export");
|
||||
dialog.getDialogPane().setHeaderText("The following text needs to be signed by the device.\nClick OK to continue.");
|
||||
dialog.showAndWait();
|
||||
|
||||
Wallet wallet = new Wallet();
|
||||
wallet.setScriptType(ScriptType.P2PKH);
|
||||
wallet.getKeystores().add(keystore);
|
||||
List<String> operationFingerprints = List.of(keystore.getKeyDerivation().getMasterFingerprint());
|
||||
|
||||
DeviceSignMessageDialog deviceSignMessageDialog = new DeviceSignMessageDialog(operationFingerprints, wallet, message, keystore.getKeyDerivation());
|
||||
Optional<String> optSignature = deviceSignMessageDialog.showAndWait();
|
||||
if(optSignature.isPresent()) {
|
||||
exporter.addSignature(keystore, optSignature.get(), baos);
|
||||
}
|
||||
} else if(keystore.getSource() == KeystoreSource.SW_SEED) {
|
||||
String signature = keystore.getExtendedPrivateKey().getKey().signMessage(message, ScriptType.P2PKH);
|
||||
exporter.addSignature(keystore, signature, baos);
|
||||
} else {
|
||||
Optional<ButtonType> optButtonType = AppServices.showWarningDialog("Cannot sign export",
|
||||
"Signing the " + exporter.getName() + " export with " + keystore.getWalletModel().toDisplayString() + " is not supported." +
|
||||
"Proceed without signing?", ButtonType.NO, ButtonType.YES);
|
||||
if(optButtonType.isPresent() && optButtonType.get() == ButtonType.NO) {
|
||||
throw new RuntimeException("Export aborted due to lack of device message signing support.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(file != null) {
|
||||
try(OutputStream outputStream = new FileOutputStream(file)) {
|
||||
outputStream.write(baos.toByteArray());
|
||||
EventManager.get().post(new KeystoreExportEvent(exportKeystore));
|
||||
}
|
||||
} else {
|
||||
QRDisplayDialog qrDisplayDialog;
|
||||
if(exporter instanceof Bip129) {
|
||||
qrDisplayDialog = new QRDisplayDialog(RegistryType.BYTES.toString(), baos.toByteArray(), false);
|
||||
} else {
|
||||
qrDisplayDialog = new QRDisplayDialog(baos.toString(StandardCharsets.UTF_8));
|
||||
}
|
||||
qrDisplayDialog.showAndWait();
|
||||
}
|
||||
} catch(Exception e) {
|
||||
String errorMessage = e.getMessage();
|
||||
if(e.getCause() != null && e.getCause().getMessage() != null && !e.getCause().getMessage().isEmpty()) {
|
||||
errorMessage = e.getCause().getMessage();
|
||||
}
|
||||
setError("Export Error", errorMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -92,9 +92,11 @@ public class FileWalletExportPane extends TitledDescriptionPane {
|
||||
FileChooser fileChooser = new FileChooser();
|
||||
fileChooser.setTitle("Export " + exporter.getWalletModel().toDisplayString() + " File");
|
||||
String extension = exporter.getExportFileExtension(wallet);
|
||||
String fileName = wallet.getFullName() + "-" + exporter.getWalletModel().toDisplayString().toLowerCase(Locale.ROOT).replace(" ", "");
|
||||
String walletModel = exporter.getWalletModel().toDisplayString().toLowerCase(Locale.ROOT).replace(" ", "");
|
||||
String postfix = walletModel.equals(extension) ? "" : "-" + walletModel;
|
||||
String fileName = wallet.getFullName() + postfix;
|
||||
if(exporter.exportsAllWallets()) {
|
||||
fileName = wallet.getMasterName();
|
||||
fileName = wallet.getMasterName() + postfix;
|
||||
}
|
||||
fileChooser.setInitialFileName(fileName + (extension == null || extension.isEmpty() ? "" : "." + extension));
|
||||
|
||||
@@ -148,7 +150,7 @@ public class FileWalletExportPane extends TitledDescriptionPane {
|
||||
QRDisplayDialog qrDisplayDialog;
|
||||
if(exporter instanceof CoboVaultMultisig) {
|
||||
qrDisplayDialog = new QRDisplayDialog(RegistryType.BYTES.toString(), outputStream.toByteArray(), true);
|
||||
} else if(exporter instanceof PassportMultisig || exporter instanceof KeystoneMultisig || exporter instanceof JadeMultisig) {
|
||||
} else if(exporter instanceof PassportMultisig || exporter instanceof KeystoneMultisig || exporter instanceof JadeMultisig || exporter instanceof Bip129) {
|
||||
qrDisplayDialog = new QRDisplayDialog(RegistryType.BYTES.toString(), outputStream.toByteArray(), false);
|
||||
} else {
|
||||
qrDisplayDialog = new QRDisplayDialog(outputStream.toString(StandardCharsets.UTF_8));
|
||||
|
||||
@@ -18,7 +18,13 @@ public class FileWalletImportPane extends FileImportPane {
|
||||
|
||||
@Override
|
||||
protected void importFile(String fileName, InputStream inputStream, String password) throws ImportException {
|
||||
Wallet wallet = importer.importWallet(inputStream, password);
|
||||
Wallet wallet;
|
||||
if(getScannedWallets() != null && !getScannedWallets().isEmpty()) {
|
||||
wallet = getScannedWallets().iterator().next();
|
||||
} else {
|
||||
wallet = importer.importWallet(inputStream, password);
|
||||
}
|
||||
|
||||
if(wallet.getName() == null) {
|
||||
wallet.setName(fileName);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.sparrowwallet.sparrow.control;
|
||||
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import com.sparrowwallet.drongo.wallet.Keystore;
|
||||
import com.sparrowwallet.sparrow.AppServices;
|
||||
import com.sparrowwallet.sparrow.EventManager;
|
||||
import com.sparrowwallet.sparrow.event.KeystoreExportEvent;
|
||||
import com.sparrowwallet.sparrow.io.*;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.layout.StackPane;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class KeystoreExportDialog extends Dialog<Keystore> {
|
||||
public KeystoreExportDialog(Keystore keystore) {
|
||||
EventManager.get().register(this);
|
||||
setOnCloseRequest(event -> {
|
||||
EventManager.get().unregister(this);
|
||||
});
|
||||
|
||||
final DialogPane dialogPane = getDialogPane();
|
||||
AppServices.setStageIcon(dialogPane.getScene().getWindow());
|
||||
|
||||
StackPane stackPane = new StackPane();
|
||||
dialogPane.setContent(stackPane);
|
||||
|
||||
AnchorPane anchorPane = new AnchorPane();
|
||||
stackPane.getChildren().add(anchorPane);
|
||||
|
||||
ScrollPane scrollPane = new ScrollPane();
|
||||
scrollPane.setPrefHeight(200);
|
||||
scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
|
||||
anchorPane.getChildren().add(scrollPane);
|
||||
scrollPane.setFitToWidth(true);
|
||||
AnchorPane.setLeftAnchor(scrollPane, 0.0);
|
||||
AnchorPane.setRightAnchor(scrollPane, 0.0);
|
||||
|
||||
List<KeystoreFileExport> exporters = List.of(new Bip129());
|
||||
|
||||
Accordion exportAccordion = new Accordion();
|
||||
for(KeystoreFileExport exporter : exporters) {
|
||||
if(!exporter.isDeprecated() || Config.get().isShowDeprecatedImportExport()) {
|
||||
FileKeystoreExportPane exportPane = new FileKeystoreExportPane(keystore, exporter);
|
||||
exportAccordion.getPanes().add(exportPane);
|
||||
}
|
||||
}
|
||||
|
||||
exportAccordion.getPanes().sort(Comparator.comparing(o -> ((TitledDescriptionPane) o).getTitle()));
|
||||
scrollPane.setContent(exportAccordion);
|
||||
|
||||
final ButtonType cancelButtonType = new javafx.scene.control.ButtonType("Cancel", ButtonBar.ButtonData.CANCEL_CLOSE);
|
||||
dialogPane.getButtonTypes().addAll(cancelButtonType);
|
||||
dialogPane.setPrefWidth(500);
|
||||
dialogPane.setPrefHeight(280);
|
||||
AppServices.moveToActiveWindowScreen(this);
|
||||
|
||||
setResultConverter(dialogButton -> dialogButton != cancelButtonType ? keystore : null);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void keystoreExported(KeystoreExportEvent event) {
|
||||
setResult(event.getKeystore());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,374 @@
|
||||
package com.sparrowwallet.sparrow.control;
|
||||
|
||||
import com.sparrowwallet.drongo.wallet.Bip39MnemonicCode;
|
||||
import com.sparrowwallet.sparrow.AppServices;
|
||||
import com.sparrowwallet.sparrow.glyphfont.FontAwesome5;
|
||||
import com.sparrowwallet.sparrow.io.PdfUtils;
|
||||
import javafx.beans.binding.Bindings;
|
||||
import javafx.beans.property.BooleanProperty;
|
||||
import javafx.beans.property.SimpleBooleanProperty;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ListChangeListener;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.input.MouseEvent;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.stage.FileChooser;
|
||||
import org.controlsfx.control.spreadsheet.*;
|
||||
import org.controlsfx.glyphfont.Glyph;
|
||||
import org.controlsfx.tools.Platform;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
public class MnemonicGridDialog extends Dialog<List<String>> {
|
||||
private final SpreadsheetView spreadsheetView;
|
||||
|
||||
private final int GRID_COLUMN_COUNT = 16;
|
||||
|
||||
private final BooleanProperty initializedProperty = new SimpleBooleanProperty(false);
|
||||
private final BooleanProperty wordsSelectedProperty = new SimpleBooleanProperty(false);
|
||||
|
||||
public MnemonicGridDialog() {
|
||||
DialogPane dialogPane = new MnemonicGridDialogPane();
|
||||
setDialogPane(dialogPane);
|
||||
setTitle("Border Wallets Grid");
|
||||
dialogPane.getStylesheets().add(AppServices.class.getResource("general.css").toExternalForm());
|
||||
dialogPane.getStylesheets().add(AppServices.class.getResource("grid.css").toExternalForm());
|
||||
dialogPane.setHeaderText("Load a Border Wallets PDF, or generate a grid from a BIP39 seed.\nThen select 11 or 23 words in a pattern on the grid. Note the order of selection is important!");
|
||||
javafx.scene.image.Image image = new Image("/image/border-wallets.png");
|
||||
dialogPane.setGraphic(new ImageView(image));
|
||||
|
||||
String[][] emptyWordGrid = new String[128][GRID_COLUMN_COUNT];
|
||||
Grid grid = getGrid(emptyWordGrid);
|
||||
|
||||
spreadsheetView = new SpreadsheetView(grid);
|
||||
spreadsheetView.addEventFilter(MouseEvent.MOUSE_PRESSED, event -> {
|
||||
try {
|
||||
Field f = event.getClass().getDeclaredField(Platform.getCurrent() == Platform.OSX ? "metaDown" : "controlDown");
|
||||
f.setAccessible(true);
|
||||
f.set(event, true);
|
||||
} catch(IllegalAccessException | NoSuchFieldException e) {
|
||||
//ignore
|
||||
}
|
||||
});
|
||||
spreadsheetView.setId("grid");
|
||||
spreadsheetView.setEditable(false);
|
||||
spreadsheetView.setFixingColumnsAllowed(false);
|
||||
spreadsheetView.setFixingRowsAllowed(false);
|
||||
|
||||
spreadsheetView.getSelectionModel().getSelectedCells().addListener(new ListChangeListener<>() {
|
||||
@Override
|
||||
public void onChanged(Change<? extends TablePosition> c) {
|
||||
int numWords = c.getList().size();
|
||||
wordsSelectedProperty.set(numWords == 11 || numWords == 23);
|
||||
}
|
||||
});
|
||||
|
||||
StackPane stackPane = new StackPane();
|
||||
stackPane.getChildren().add(spreadsheetView);
|
||||
dialogPane.setContent(stackPane);
|
||||
|
||||
stackPane.widthProperty().addListener((observable, oldValue, newValue) -> {
|
||||
if(newValue != null) {
|
||||
for(SpreadsheetColumn column : spreadsheetView.getColumns()) {
|
||||
column.setPrefWidth((newValue.doubleValue() - spreadsheetView.getRowHeaderWidth() - 3) / 17);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
dialogPane.getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);
|
||||
|
||||
final ButtonType loadCsvButtonType = new javafx.scene.control.ButtonType("Load PDF...", ButtonBar.ButtonData.LEFT);
|
||||
dialogPane.getButtonTypes().add(loadCsvButtonType);
|
||||
|
||||
final ButtonType generateButtonType = new javafx.scene.control.ButtonType("Generate Grid...", ButtonBar.ButtonData.HELP);
|
||||
dialogPane.getButtonTypes().add(generateButtonType);
|
||||
|
||||
final ButtonType clearButtonType = new javafx.scene.control.ButtonType("Clear Selection", ButtonBar.ButtonData.OTHER);
|
||||
dialogPane.getButtonTypes().add(clearButtonType);
|
||||
|
||||
Button okButton = (Button)dialogPane.lookupButton(ButtonType.OK);
|
||||
okButton.disableProperty().bind(Bindings.not(Bindings.and(initializedProperty, wordsSelectedProperty)));
|
||||
|
||||
setResultConverter((dialogButton) -> {
|
||||
ButtonBar.ButtonData data = dialogButton == null ? null : dialogButton.getButtonData();
|
||||
return data == ButtonBar.ButtonData.OK_DONE ? getSelectedWords() : null;
|
||||
});
|
||||
|
||||
dialogPane.setPrefWidth(850);
|
||||
dialogPane.setPrefHeight(500);
|
||||
AppServices.setStageIcon(dialogPane.getScene().getWindow());
|
||||
AppServices.moveToActiveWindowScreen(this);
|
||||
}
|
||||
|
||||
private Grid getGrid(String[][] wordGrid) {
|
||||
int rowCount = wordGrid.length;
|
||||
int columnCount = wordGrid[0].length;
|
||||
GridBase grid = new GridBase(rowCount, columnCount);
|
||||
ObservableList<ObservableList<SpreadsheetCell>> rows = FXCollections.observableArrayList();
|
||||
grid.getColumnHeaders().setAll("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P");
|
||||
for(int i = 0; i < rowCount; i++) {
|
||||
final ObservableList<SpreadsheetCell> list = FXCollections.observableArrayList();
|
||||
for(int j = 0; j < columnCount; j++) {
|
||||
list.add(createCell(i, j, wordGrid[i][j]));
|
||||
}
|
||||
rows.add(list);
|
||||
grid.getRowHeaders().add(String.format("%03d", i + 1));
|
||||
}
|
||||
grid.setRows(rows);
|
||||
|
||||
return grid;
|
||||
}
|
||||
|
||||
private SpreadsheetCell createCell(int row, int column, String word) {
|
||||
return SpreadsheetCellType.STRING.createCell(row, column, 1, 1, word == null ? "" : word);
|
||||
}
|
||||
|
||||
private List<String> getSelectedWords() {
|
||||
List<String> abbreviations = spreadsheetView.getSelectionModel().getSelectedCells().stream()
|
||||
.map(position -> (String)spreadsheetView.getGrid().getRows().get(position.getRow()).get(position.getColumn()).getItem()).collect(Collectors.toList());
|
||||
|
||||
List<String> words = new ArrayList<>();
|
||||
for(String abbreviation : abbreviations) {
|
||||
for(String word : Bip39MnemonicCode.INSTANCE.getWordList()) {
|
||||
if((abbreviation.length() == 3 && word.equals(abbreviation)) || (abbreviation.length() >= 4 && word.startsWith(abbreviation))) {
|
||||
words.add(word);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(words.size() != abbreviations.size()) {
|
||||
abbreviations.removeIf(abbr -> words.stream().anyMatch(w -> w.startsWith(abbr)));
|
||||
throw new IllegalStateException("Could not find words for abbreviations: " + abbreviations);
|
||||
}
|
||||
|
||||
return words;
|
||||
}
|
||||
|
||||
public List<String> shuffle(List<String> mnemonic) {
|
||||
String mnemonicString = String.join(" ", mnemonic);
|
||||
List<String> words = new ArrayList<>(Bip39MnemonicCode.INSTANCE.getWordList());
|
||||
|
||||
UltraHighEntropyPrng uhePrng = new UltraHighEntropyPrng();
|
||||
uhePrng.initState();
|
||||
uhePrng.hashString(mnemonicString);
|
||||
for(int i = words.size() - 1; i > 0; i--) {
|
||||
int j = (int)uhePrng.random(i + 1);
|
||||
String tmp = words.get(i);
|
||||
words.set(i, words.get(j));
|
||||
words.set(j, tmp);
|
||||
}
|
||||
|
||||
return words;
|
||||
}
|
||||
|
||||
private String[][] toGrid(List<String> words) {
|
||||
String[][] grid = new String[words.size()/GRID_COLUMN_COUNT][GRID_COLUMN_COUNT];
|
||||
|
||||
int row = 0;
|
||||
int col = 0;
|
||||
for(String word : words) {
|
||||
String abbr = word.length() < 4 ? word : word.substring(0, 4);
|
||||
grid[row][col] = abbr;
|
||||
col++;
|
||||
if(col >= GRID_COLUMN_COUNT) {
|
||||
col = 0;
|
||||
row++;
|
||||
}
|
||||
}
|
||||
|
||||
return grid;
|
||||
}
|
||||
|
||||
private class MnemonicGridDialogPane extends DialogPane {
|
||||
@Override
|
||||
protected Node createButton(ButtonType buttonType) {
|
||||
Node button;
|
||||
if(buttonType.getButtonData() == ButtonBar.ButtonData.LEFT) {
|
||||
Button loadButton = new Button(buttonType.getText());
|
||||
loadButton.setGraphicTextGap(5);
|
||||
loadButton.setGraphic(getGlyph(FontAwesome5.Glyph.ARROW_UP));
|
||||
final ButtonBar.ButtonData buttonData = buttonType.getButtonData();
|
||||
ButtonBar.setButtonData(loadButton, buttonData);
|
||||
loadButton.setOnAction(event -> {
|
||||
FileChooser fileChooser = new FileChooser();
|
||||
fileChooser.setTitle("Open PDF");
|
||||
fileChooser.getExtensionFilters().addAll(
|
||||
new FileChooser.ExtensionFilter("All Files", org.controlsfx.tools.Platform.getCurrent().equals(org.controlsfx.tools.Platform.UNIX) ? "*" : "*.*"),
|
||||
new FileChooser.ExtensionFilter("PDF", "*.pdf")
|
||||
);
|
||||
|
||||
AppServices.moveToActiveWindowScreen(this.getScene().getWindow(), 800, 450);
|
||||
File file = fileChooser.showOpenDialog(this.getScene().getWindow());
|
||||
if(file != null) {
|
||||
try(BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(file))) {
|
||||
String[][] wordGrid = PdfUtils.getWordGrid(inputStream);
|
||||
spreadsheetView.setGrid(getGrid(wordGrid));
|
||||
initializedProperty.set(true);
|
||||
} catch(Exception e) {
|
||||
AppServices.showErrorDialog("Cannot load PDF", e.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
button = loadButton;
|
||||
} else if(buttonType.getButtonData() == ButtonBar.ButtonData.HELP) {
|
||||
Button generateButton = new Button(buttonType.getText());
|
||||
final ButtonBar.ButtonData buttonData = buttonType.getButtonData();
|
||||
ButtonBar.setButtonData(generateButton, buttonData);
|
||||
generateButton.setOnAction(event -> {
|
||||
SeedEntryDialog seedEntryDialog = new SeedEntryDialog(12);
|
||||
Optional<List<String>> optWords = seedEntryDialog.showAndWait();
|
||||
if(optWords.isPresent()) {
|
||||
List<String> mnemonicWords = optWords.get();
|
||||
List<String> shuffledWordList = shuffle(mnemonicWords);
|
||||
String[][] wordGrid = toGrid(shuffledWordList);
|
||||
spreadsheetView.setGrid(getGrid(wordGrid));
|
||||
initializedProperty.set(true);
|
||||
|
||||
if(seedEntryDialog.isGenerated()) {
|
||||
PdfUtils.saveWordGrid(wordGrid, mnemonicWords);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
button = generateButton;
|
||||
} else if(buttonType.getButtonData() == ButtonBar.ButtonData.OTHER) {
|
||||
Button clearButton = new Button(buttonType.getText());
|
||||
final ButtonBar.ButtonData buttonData = buttonType.getButtonData();
|
||||
ButtonBar.setButtonData(clearButton, buttonData);
|
||||
clearButton.setOnAction(event -> {
|
||||
spreadsheetView.getSelectionModel().clearSelection();
|
||||
});
|
||||
|
||||
button = clearButton;
|
||||
} else {
|
||||
button = super.createButton(buttonType);
|
||||
}
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
private Glyph getGlyph(FontAwesome5.Glyph glyphName) {
|
||||
Glyph glyph = new Glyph(FontAwesome5.FONT_NAME, glyphName);
|
||||
glyph.setFontSize(11);
|
||||
return glyph;
|
||||
}
|
||||
}
|
||||
|
||||
public static class UltraHighEntropyPrng {
|
||||
private final int order;
|
||||
private double carry;
|
||||
private int phase;
|
||||
private final double[] intermediates;
|
||||
private int i, j, k; // general purpose locals
|
||||
|
||||
public UltraHighEntropyPrng() {
|
||||
order = 48; // set the 'order' number of ENTROPY-holding 32-bit values
|
||||
carry = 1; // init the 'carry' used by the multiply-with-carry (MWC) algorithm
|
||||
phase = order; // init the 'phase' (max-1) of the intermediate variable pointer
|
||||
intermediates = new double[order]; // declare our intermediate variables array
|
||||
|
||||
for(i = 0; i < order; i++) {
|
||||
// Used to simulate javascript's Math.random
|
||||
Random random = new Random();
|
||||
intermediates[i] = mash(random.nextInt(Integer.MAX_VALUE)); // fill the array with initial mash hash values
|
||||
}
|
||||
}
|
||||
|
||||
public double random(int range) {
|
||||
return Math.floor(range * (rawPrng() + ((long)(rawPrng() * 0x200000L)) * 1.1102230246251565e-16)); // 2^-53
|
||||
}
|
||||
|
||||
private String randomString(int count) {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for(i = 0; i < count; i++) {
|
||||
char newChar = (char) (33 + random(94));
|
||||
stringBuilder.append(newChar);
|
||||
}
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
private double rawPrng() {
|
||||
if(++phase >= order) {
|
||||
phase = 0;
|
||||
}
|
||||
double t = 1768863 * intermediates[phase] + carry * 2.3283064365386963e-10; // 2^-32
|
||||
long temp = (long)t;
|
||||
return intermediates[phase] = t - (carry = temp);
|
||||
}
|
||||
|
||||
private void hash(String args) {
|
||||
for(i = 0; i < args.length(); i++) {
|
||||
for(j = 0; j < order; j++) {
|
||||
intermediates[j] -= mash(args.charAt(i));
|
||||
if(intermediates[j] < 0) {
|
||||
intermediates[j] = intermediates[j] + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void hashString(String input) {
|
||||
mash(input); // use the string to evolve the 'mash' state
|
||||
|
||||
char[] inputAry = input.toCharArray();
|
||||
for(i = 0; i < inputAry.length; i++) // scan through the characters in our string
|
||||
{
|
||||
k = inputAry[i]; // get the character code at the location
|
||||
for(j = 0; j < order; j++) // "mash" it into the UHEPRNG state
|
||||
{
|
||||
intermediates[j] -= mash(k);
|
||||
if(intermediates[j] < 0) {
|
||||
intermediates[j] += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void initState() {
|
||||
mash(null);
|
||||
for(i = 0; i < order; i++) {
|
||||
intermediates[i] = mash(' '); // fill the array with initial mash hash values
|
||||
}
|
||||
carry = 1; // init our multiply-with-carry carry
|
||||
phase = order; // init our phase
|
||||
}
|
||||
|
||||
double n = Integer.toUnsignedLong(0xefc8249d);
|
||||
|
||||
private double mash(Object data) {
|
||||
if(data != null) {
|
||||
String strData = data.toString();
|
||||
for(int i = 0; i < strData.length(); i++) {
|
||||
n += strData.charAt(i);
|
||||
double h = 0.02519603282416938 * n;
|
||||
n = Integer.toUnsignedLong((int)h);
|
||||
h -= n;
|
||||
h *= n;
|
||||
n = Integer.toUnsignedLong((int)h);
|
||||
h -= n;
|
||||
n += h * 0x100000000L; // 2^32
|
||||
}
|
||||
return ((long)n) * 2.3283064365386963e-10; // 2^-32
|
||||
} else {
|
||||
n = Integer.toUnsignedLong(0xefc8249d);
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.sparrowwallet.sparrow.control;
|
||||
|
||||
import com.sparrowwallet.drongo.wallet.DeterministicSeed;
|
||||
import com.sparrowwallet.drongo.wallet.Keystore;
|
||||
import com.sparrowwallet.drongo.wallet.WalletModel;
|
||||
import javafx.beans.property.SimpleListProperty;
|
||||
@@ -24,7 +23,8 @@ public class MnemonicKeystoreDisplayPane extends MnemonicKeystorePane {
|
||||
showWordList(keystore.getSeed());
|
||||
}
|
||||
|
||||
protected Node getMnemonicWordsEntry(int numWords) {
|
||||
@Override
|
||||
protected Node getMnemonicWordsEntry(int numWords, boolean showPassphrase, boolean editPassphrase) {
|
||||
VBox vBox = new VBox();
|
||||
vBox.setSpacing(10);
|
||||
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
package com.sparrowwallet.sparrow.control;
|
||||
|
||||
import com.sparrowwallet.drongo.wallet.Bip39MnemonicCode;
|
||||
import com.sparrowwallet.drongo.wallet.DeterministicSeed;
|
||||
import com.sparrowwallet.drongo.wallet.MnemonicException;
|
||||
import com.sparrowwallet.drongo.wallet.WalletModel;
|
||||
import javafx.beans.property.BooleanProperty;
|
||||
import javafx.beans.property.SimpleBooleanProperty;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.Button;
|
||||
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.List;
|
||||
|
||||
public class MnemonicKeystoreEntryPane extends MnemonicKeystorePane {
|
||||
private final BooleanProperty validProperty = new SimpleBooleanProperty(false);
|
||||
|
||||
private boolean generated;
|
||||
|
||||
public MnemonicKeystoreEntryPane(int numWords) {
|
||||
super(DeterministicSeed.Type.BIP39.getName(), "Enter seed words", "", "image/" + WalletModel.SEED.getType() + ".png");
|
||||
showHideLink.setVisible(false);
|
||||
buttonBox.getChildren().clear();
|
||||
|
||||
defaultWordSizeProperty.set(numWords);
|
||||
setDescription("Generate new or enter existing");
|
||||
showHideLink.setVisible(false);
|
||||
setContent(getMnemonicWordsEntry(numWords, false, true));
|
||||
setExpanded(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Node> createRightButtons() {
|
||||
Button button = new Button("Next");
|
||||
button.setVisible(false);
|
||||
return List.of(button);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onWordChange(boolean empty, boolean validWords, boolean validChecksum) {
|
||||
if(!empty && validWords) {
|
||||
try {
|
||||
Bip39MnemonicCode.INSTANCE.check(wordEntriesProperty.get());
|
||||
validChecksum = true;
|
||||
} catch(MnemonicException e) {
|
||||
invalidLabel.setText("Invalid checksum");
|
||||
invalidLabel.setTooltip(null);
|
||||
}
|
||||
}
|
||||
|
||||
validProperty.set(validChecksum);
|
||||
validLabel.setVisible(validChecksum);
|
||||
invalidLabel.setVisible(!validChecksum && !empty);
|
||||
}
|
||||
|
||||
public void generateNew() {
|
||||
int mnemonicSeedLength = wordEntriesProperty.get().size() * 11;
|
||||
int entropyLength = mnemonicSeedLength - (mnemonicSeedLength/33);
|
||||
|
||||
SecureRandom secureRandom;
|
||||
try {
|
||||
secureRandom = SecureRandom.getInstanceStrong();
|
||||
} catch(NoSuchAlgorithmException e) {
|
||||
secureRandom = new SecureRandom();
|
||||
}
|
||||
|
||||
DeterministicSeed deterministicSeed = new DeterministicSeed(secureRandom, entropyLength, "");
|
||||
displayMnemonicCode(deterministicSeed);
|
||||
generated = true;
|
||||
}
|
||||
|
||||
private void displayMnemonicCode(DeterministicSeed deterministicSeed) {
|
||||
setDescription("Write down these words");
|
||||
showHideLink.setVisible(false);
|
||||
|
||||
for (int i = 0; i < wordsPane.getChildren().size(); i++) {
|
||||
WordEntry wordEntry = (WordEntry)wordsPane.getChildren().get(i);
|
||||
wordEntry.getEditor().setText(deterministicSeed.getMnemonicCode().get(i));
|
||||
wordEntry.getEditor().setEditable(false);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return validProperty.get();
|
||||
}
|
||||
|
||||
public BooleanProperty validProperty() {
|
||||
return validProperty;
|
||||
}
|
||||
|
||||
public boolean isGenerated() {
|
||||
return generated;
|
||||
}
|
||||
}
|
||||
@@ -223,7 +223,7 @@ public class MnemonicKeystoreImportPane extends MnemonicKeystorePane {
|
||||
private void confirmBackup() {
|
||||
setDescription("Confirm backup by re-entering words");
|
||||
showHideLink.setVisible(false);
|
||||
setContent(getMnemonicWordsEntry(wordEntriesProperty.get().size()));
|
||||
setContent(getMnemonicWordsEntry(wordEntriesProperty.get().size(), true, false));
|
||||
setExpanded(true);
|
||||
backButton.setVisible(true);
|
||||
generateButton.setVisible(false);
|
||||
|
||||
@@ -12,6 +12,8 @@ import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ListChangeListener;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.concurrent.ScheduledService;
|
||||
import javafx.concurrent.Task;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.Orientation;
|
||||
import javafx.geometry.Pos;
|
||||
@@ -20,8 +22,8 @@ import javafx.scene.control.*;
|
||||
import javafx.scene.input.Clipboard;
|
||||
import javafx.scene.layout.*;
|
||||
import javafx.util.Callback;
|
||||
import javafx.util.Duration;
|
||||
import org.controlsfx.control.textfield.AutoCompletionBinding;
|
||||
import org.controlsfx.control.textfield.CustomTextField;
|
||||
import org.controlsfx.control.textfield.TextFields;
|
||||
import org.controlsfx.glyphfont.Glyph;
|
||||
import org.controlsfx.validation.ValidationResult;
|
||||
@@ -44,7 +46,7 @@ public class MnemonicKeystorePane extends TitledDescriptionPane {
|
||||
protected Label invalidLabel;
|
||||
|
||||
protected SimpleListProperty<String> wordEntriesProperty;
|
||||
protected final SimpleStringProperty passphraseProperty = new SimpleStringProperty();
|
||||
protected final SimpleStringProperty passphraseProperty = new SimpleStringProperty("");
|
||||
protected IntegerProperty defaultWordSizeProperty;
|
||||
|
||||
public MnemonicKeystorePane(String title, String description, String content, String imageUrl) {
|
||||
@@ -79,6 +81,12 @@ public class MnemonicKeystorePane extends TitledDescriptionPane {
|
||||
enterMnemonicButton.getItems().add(item);
|
||||
}
|
||||
enterMnemonicButton.getItems().add(new SeparatorMenuItem());
|
||||
MenuItem gridItem = new MenuItem("Border Wallets Grid...");
|
||||
gridItem.setOnAction(event -> {
|
||||
showGrid();
|
||||
});
|
||||
enterMnemonicButton.getItems().add(gridItem);
|
||||
|
||||
MenuItem scanItem = new MenuItem("Scan QR...");
|
||||
scanItem.setOnAction(event -> {
|
||||
scanQR();
|
||||
@@ -87,6 +95,42 @@ public class MnemonicKeystorePane extends TitledDescriptionPane {
|
||||
enterMnemonicButton.managedProperty().bind(enterMnemonicButton.visibleProperty());
|
||||
}
|
||||
|
||||
protected void showGrid() {
|
||||
MnemonicGridDialog mnemonicGridDialog = new MnemonicGridDialog();
|
||||
Optional<List<String>> optWords = mnemonicGridDialog.showAndWait();
|
||||
if(optWords.isPresent()) {
|
||||
List<String> words = optWords.get();
|
||||
setContent(getMnemonicWordsEntry(words.size() + 1, true, true));
|
||||
setExpanded(true);
|
||||
|
||||
for(int i = 0; i < wordsPane.getChildren().size(); i++) {
|
||||
WordEntry wordEntry = (WordEntry)wordsPane.getChildren().get(i);
|
||||
if(i < words.size()) {
|
||||
wordEntry.getEditor().setText(words.get(i));
|
||||
wordEntry.getEditor().setEditable(false);
|
||||
} else {
|
||||
ScheduledService<Void> service = new ScheduledService<>() {
|
||||
@Override
|
||||
protected Task<Void> createTask() {
|
||||
return new Task<>() {
|
||||
@Override
|
||||
protected Void call() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
service.setDelay(Duration.millis(500));
|
||||
service.setOnSucceeded(event1 -> {
|
||||
service.cancel();
|
||||
Platform.runLater(() -> wordEntry.getEditor().requestFocus());
|
||||
});
|
||||
service.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void scanQR() {
|
||||
QRScanDialog qrScanDialog = new QRScanDialog();
|
||||
Optional<QRScanDialog.Result> optionalResult = qrScanDialog.showAndWait();
|
||||
@@ -106,7 +150,7 @@ public class MnemonicKeystorePane extends TitledDescriptionPane {
|
||||
|
||||
protected void showWordList(DeterministicSeed seed) {
|
||||
List<String> words = seed.getMnemonicCode();
|
||||
setContent(getMnemonicWordsEntry(words.size()));
|
||||
setContent(getMnemonicWordsEntry(words.size(), true, true));
|
||||
setExpanded(true);
|
||||
|
||||
for(int i = 0; i < wordsPane.getChildren().size(); i++) {
|
||||
@@ -119,11 +163,11 @@ public class MnemonicKeystorePane extends TitledDescriptionPane {
|
||||
protected void enterMnemonic(int numWords) {
|
||||
setDescription("Generate new or enter existing");
|
||||
showHideLink.setVisible(false);
|
||||
setContent(getMnemonicWordsEntry(numWords));
|
||||
setContent(getMnemonicWordsEntry(numWords, true, true));
|
||||
setExpanded(true);
|
||||
}
|
||||
|
||||
protected Node getMnemonicWordsEntry(int numWords) {
|
||||
protected Node getMnemonicWordsEntry(int numWords, boolean showPassphrase, boolean editPassphrase) {
|
||||
VBox vBox = new VBox();
|
||||
vBox.setSpacing(10);
|
||||
|
||||
@@ -152,10 +196,12 @@ public class MnemonicKeystorePane extends TitledDescriptionPane {
|
||||
|
||||
vBox.getChildren().add(wordsPane);
|
||||
|
||||
PassphraseEntry passphraseEntry = new PassphraseEntry();
|
||||
wordEntries.get(wordEntries.size() - 1).setNextField(passphraseEntry.getEditor());
|
||||
passphraseEntry.setPadding(new Insets(0, 26, 10, 10));
|
||||
vBox.getChildren().add(passphraseEntry);
|
||||
if(showPassphrase) {
|
||||
PassphraseEntry passphraseEntry = new PassphraseEntry(editPassphrase);
|
||||
wordEntries.get(wordEntries.size() - 1).setNextField(passphraseEntry.getEditor());
|
||||
passphraseEntry.setPadding(new Insets(0, 26, 10, 10));
|
||||
vBox.getChildren().add(passphraseEntry);
|
||||
}
|
||||
|
||||
AnchorPane buttonPane = new AnchorPane();
|
||||
buttonPane.setPadding(new Insets(0, 26, 0, 10));
|
||||
@@ -250,9 +296,14 @@ public class MnemonicKeystorePane extends TitledDescriptionPane {
|
||||
if(clipboard.hasString() && clipboard.getString().matches("(?m).+[\\n\\s][\\S\\s]*")) {
|
||||
String[] words = clipboard.getString().split("[\\n\\s]");
|
||||
WordEntry entry = WordEntry.this;
|
||||
for(String word : words) {
|
||||
for(int i = 0; i < words.length; i++) {
|
||||
String word = words[i];
|
||||
if(entry.nextField != null) {
|
||||
entry.nextField.requestFocus();
|
||||
if(i == words.length - 2 && isValid(word)) {
|
||||
label.requestFocus();
|
||||
} else {
|
||||
entry.nextField.requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
entry.wordField.setText(word);
|
||||
@@ -282,7 +333,7 @@ public class MnemonicKeystorePane extends TitledDescriptionPane {
|
||||
wordField.setTextFormatter(formatter);
|
||||
|
||||
wordList = Bip39MnemonicCode.INSTANCE.getWordList();
|
||||
AutoCompletionBinding<String> autoCompletionBinding = TextFields.bindAutoCompletion(wordField, new WordlistSuggestionProvider(wordList));
|
||||
AutoCompletionBinding<String> autoCompletionBinding = TextFields.bindAutoCompletion(wordField, new WordlistSuggestionProvider(wordList, wordNumber, wordEntryList));
|
||||
autoCompletionBinding.setDelay(50);
|
||||
autoCompletionBinding.setOnAutoCompleted(event -> {
|
||||
if(nextField != null) {
|
||||
@@ -290,11 +341,20 @@ public class MnemonicKeystorePane extends TitledDescriptionPane {
|
||||
}
|
||||
});
|
||||
|
||||
//Show autocomplete for the last word on focus if empty
|
||||
boolean lastWord = wordNumber == wordEntryList.size() - 1;
|
||||
if(lastWord) {
|
||||
wordField.focusedProperty().addListener((observable, oldValue, focused) -> {
|
||||
if(focused && wordField.getText().isEmpty()) {
|
||||
autoCompletionBinding.setUserInput("");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ValidationSupport validationSupport = new ValidationSupport();
|
||||
validationSupport.setValidationDecorator(new StyleClassValidationDecoration());
|
||||
validationSupport.registerValidator(wordField, Validator.combine(
|
||||
Validator.createEmptyValidator("Word is required"),
|
||||
(Control c, String newValue) -> ValidationResult.fromErrorIf( c, "Invalid word", !wordList.contains(newValue))
|
||||
(Control c, String newValue) -> ValidationResult.fromErrorIf( c, "Invalid word", (newValue.length() > 0 || !lastWord) && !wordList.contains(newValue))
|
||||
));
|
||||
|
||||
wordField.textProperty().addListener((observable, oldValue, newValue) -> {
|
||||
@@ -323,13 +383,30 @@ public class MnemonicKeystorePane extends TitledDescriptionPane {
|
||||
|
||||
protected static class WordlistSuggestionProvider implements Callback<AutoCompletionBinding.ISuggestionRequest, Collection<String>> {
|
||||
private final List<String> wordList;
|
||||
private final int wordNumber;
|
||||
private final ObservableList<String> wordEntryList;
|
||||
|
||||
public WordlistSuggestionProvider(List<String> wordList) {
|
||||
public WordlistSuggestionProvider(List<String> wordList, int wordNumber, ObservableList<String> wordEntryList) {
|
||||
this.wordList = wordList;
|
||||
this.wordNumber = wordNumber;
|
||||
this.wordEntryList = wordEntryList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> call(AutoCompletionBinding.ISuggestionRequest request) {
|
||||
if(wordNumber == wordEntryList.size() - 1 && allPreviousWordsValid()) {
|
||||
try {
|
||||
List<String> possibleLastWords = Bip39MnemonicCode.INSTANCE.getPossibleLastWords(wordEntryList.subList(0, wordEntryList.size() - 1));
|
||||
if(!request.getUserText().isEmpty()) {
|
||||
possibleLastWords.removeIf(s -> !s.startsWith(request.getUserText()));
|
||||
}
|
||||
|
||||
return possibleLastWords;
|
||||
} catch(Exception e) {
|
||||
log.warn("Cannot determine possible last words", e);
|
||||
}
|
||||
}
|
||||
|
||||
List<String> suggestions = new ArrayList<>();
|
||||
if(!request.getUserText().isEmpty()) {
|
||||
for(String word : wordList) {
|
||||
@@ -341,26 +418,63 @@ public class MnemonicKeystorePane extends TitledDescriptionPane {
|
||||
|
||||
return suggestions;
|
||||
}
|
||||
|
||||
private boolean allPreviousWordsValid() {
|
||||
for(int i = 0; i < wordEntryList.size() - 1; i++) {
|
||||
if(!WordEntry.isValid(wordEntryList.get(i))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
protected class PassphraseEntry extends HBox {
|
||||
private final CustomTextField passphraseField;
|
||||
private final TextField passphraseField;
|
||||
|
||||
public PassphraseEntry() {
|
||||
public PassphraseEntry(boolean editable) {
|
||||
super();
|
||||
|
||||
setAlignment(Pos.CENTER_LEFT);
|
||||
setSpacing(10);
|
||||
Label usePassphraseLabel = new Label("Use passphrase?");
|
||||
usePassphraseLabel.managedProperty().bind(usePassphraseLabel.visibleProperty());
|
||||
CheckBox usePassphraseCheckbox = new CheckBox(" ");
|
||||
usePassphraseCheckbox.setDisable(!editable);
|
||||
usePassphraseCheckbox.managedProperty().bind(usePassphraseCheckbox.visibleProperty());
|
||||
usePassphraseLabel.visibleProperty().bind(usePassphraseCheckbox.visibleProperty());
|
||||
usePassphraseCheckbox.setVisible(passphraseProperty.isEmpty().get());
|
||||
usePassphraseCheckbox.selectedProperty().addListener((observable, oldValue, newValue) -> {
|
||||
if(newValue) {
|
||||
Optional<ButtonType> optType = AppServices.showWarningDialog("Add a passphrase?", "A passphrase is not a password! " +
|
||||
"Any variation entered in future loads a valid wallet, but with different addresses.\n\n" +
|
||||
"This feature provides optional added security for advanced users only. Are you sure?", ButtonType.NO, ButtonType.YES);
|
||||
if(optType.isPresent() && optType.get() == ButtonType.YES) {
|
||||
usePassphraseCheckbox.setVisible(false);
|
||||
} else {
|
||||
usePassphraseCheckbox.setSelected(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Label passphraseLabel = new Label("Passphrase:");
|
||||
passphraseField = (CustomTextField) TextFields.createClearableTextField();
|
||||
passphraseLabel.managedProperty().bind(passphraseLabel.visibleProperty());
|
||||
passphraseField = new TextField();
|
||||
passphraseField.setPromptText(passphraseProperty.isEmpty().get() ? "Leave blank for none" : "");
|
||||
passphraseField.setText(passphraseProperty.get());
|
||||
passphraseField.setDisable(!editable);
|
||||
passphraseField.managedProperty().bind(passphraseField.visibleProperty());
|
||||
passphraseLabel.visibleProperty().bind(passphraseField.visibleProperty());
|
||||
passphraseField.visibleProperty().bind(usePassphraseCheckbox.visibleProperty().not());
|
||||
passphraseProperty.bind(passphraseField.textProperty());
|
||||
passphraseField.setPromptText("Leave blank for none");
|
||||
|
||||
HelpLabel helpLabel = new HelpLabel();
|
||||
helpLabel.setPrefHeight(28);
|
||||
helpLabel.setStyle("-fx-padding: 0 0 0 0");
|
||||
helpLabel.setHelpText("A passphrase provides optional added security - it is not stored so it must be remembered!");
|
||||
helpLabel.setHelpText("Advanced feature: a passphrase provides optional added security, but it is not stored so it must be remembered!");
|
||||
|
||||
getChildren().addAll(passphraseLabel, passphraseField, helpLabel);
|
||||
getChildren().addAll(usePassphraseLabel, usePassphraseCheckbox, passphraseLabel, passphraseField, helpLabel);
|
||||
}
|
||||
|
||||
public TextField getEditor() {
|
||||
|
||||
+7
-2
@@ -10,9 +10,11 @@ import com.sparrowwallet.drongo.wallet.Wallet;
|
||||
import com.sparrowwallet.sparrow.AppServices;
|
||||
import com.sparrowwallet.sparrow.EventManager;
|
||||
import com.sparrowwallet.sparrow.event.WalletImportEvent;
|
||||
import com.sparrowwallet.sparrow.io.Config;
|
||||
import com.sparrowwallet.sparrow.io.ImportException;
|
||||
import com.sparrowwallet.sparrow.io.KeystoreMnemonicImport;
|
||||
import com.sparrowwallet.sparrow.net.ElectrumServer;
|
||||
import com.sparrowwallet.sparrow.net.ServerType;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.Pos;
|
||||
@@ -135,7 +137,10 @@ public class MnemonicWalletKeystoreImportPane extends MnemonicKeystorePane {
|
||||
EventManager.get().post(new WalletImportEvent(optWallet.get()));
|
||||
} else {
|
||||
discoverButton.setDisable(false);
|
||||
Optional<ButtonType> optButtonType = AppServices.showErrorDialog("No existing wallet found", "Could not find a wallet with existing transactions using this mnemonic. Import this wallet anyway?", ButtonType.NO, ButtonType.YES);
|
||||
Optional<ButtonType> optButtonType = AppServices.showErrorDialog("No existing wallet found",
|
||||
Config.get().getServerType() == ServerType.BITCOIN_CORE ? "The configured server type is Bitcoin Core, which does not support wallet discovery.\n\n" +
|
||||
"You can however import this wallet and scan the blockchain by supplying a start date. Do you want to import this wallet?" :
|
||||
"Could not find a wallet with existing transactions using this mnemonic. Import this wallet anyway?", ButtonType.NO, ButtonType.YES);
|
||||
if(optButtonType.isPresent() && optButtonType.get() == ButtonType.YES) {
|
||||
setContent(getScriptTypeEntry());
|
||||
setExpanded(true);
|
||||
@@ -183,7 +188,7 @@ public class MnemonicWalletKeystoreImportPane extends MnemonicKeystorePane {
|
||||
scriptTypeComboBox.setMaxWidth(170);
|
||||
|
||||
HelpLabel helpLabel = new HelpLabel();
|
||||
helpLabel.setHelpText("P2WPKH is a Native Segwit type and is usually the best choice for new wallets.\nP2SH-P2WPKH is a Wrapped Segwit type and is a reasonable choice for the widest compatibility.\nP2PKH is a Legacy type and should be avoided for new wallets.\nFor existing wallets, be sure to choose the type that matches the wallet you are importing.");
|
||||
helpLabel.setHelpText("Native Segwit is usually the best choice for new wallets.\nTaproot is a new type useful for specific needs.\nNested Segwit and Legacy are useful for recovering older wallets.\nFor existing wallets, be sure to choose the type that matches the wallet you are importing.");
|
||||
fieldBox.getChildren().addAll(scriptTypeComboBox, helpLabel);
|
||||
|
||||
Region region = new Region();
|
||||
|
||||
@@ -53,6 +53,7 @@ import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@@ -259,7 +260,7 @@ public class QRScanDialog extends Dialog<QRScanDialog.Result> {
|
||||
DeterministicSeed seed;
|
||||
try {
|
||||
extendedKey = ExtendedKey.fromDescriptor(qrtext);
|
||||
result = new Result(extendedKey);
|
||||
result = new Result(extendedKey, null);
|
||||
return;
|
||||
} catch(Exception e) {
|
||||
//Ignore, not a valid xpub
|
||||
@@ -408,7 +409,7 @@ public class QRScanDialog extends Dialog<QRScanDialog.Result> {
|
||||
} else if(urRegistryType.equals(RegistryType.CRYPTO_HDKEY)) {
|
||||
CryptoHDKey cryptoHDKey = (CryptoHDKey)ur.decodeFromRegistry();
|
||||
ExtendedKey extendedKey = getExtendedKey(cryptoHDKey);
|
||||
return new Result(extendedKey);
|
||||
return new Result(extendedKey, cryptoHDKey.getName());
|
||||
} else if(urRegistryType.equals(RegistryType.CRYPTO_OUTPUT)) {
|
||||
CryptoOutput cryptoOutput = (CryptoOutput)ur.decodeFromRegistry();
|
||||
OutputDescriptor outputDescriptor = getOutputDescriptor(cryptoOutput);
|
||||
@@ -542,7 +543,12 @@ public class QRScanDialog extends Dialog<QRScanDialog.Result> {
|
||||
|
||||
private KeyDerivation getKeyDerivation(CryptoKeypath cryptoKeypath) {
|
||||
if(cryptoKeypath != null) {
|
||||
return new KeyDerivation(Utils.bytesToHex(cryptoKeypath.getSourceFingerprint()), cryptoKeypath.getPath());
|
||||
if(cryptoKeypath.getComponents().stream().anyMatch(PathComponent::isWildcard)) {
|
||||
throw new IllegalArgumentException("Wildcard derivation paths are not supported");
|
||||
}
|
||||
|
||||
List<ChildNumber> path = cryptoKeypath.getComponents().stream().map(comp -> new ChildNumber(comp.getIndex(), comp.isHardened())).collect(Collectors.toList());
|
||||
return new KeyDerivation(Utils.bytesToHex(cryptoKeypath.getSourceFingerprint()), KeyDerivation.writePath(path));
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -656,6 +662,7 @@ public class QRScanDialog extends Dialog<QRScanDialog.Result> {
|
||||
public final PSBT psbt;
|
||||
public final BitcoinURI uri;
|
||||
public final ExtendedKey extendedKey;
|
||||
public final String extendedKeyName;
|
||||
public final OutputDescriptor outputDescriptor;
|
||||
public final List<Wallet> wallets;
|
||||
public final DeterministicSeed seed;
|
||||
@@ -667,6 +674,7 @@ public class QRScanDialog extends Dialog<QRScanDialog.Result> {
|
||||
this.psbt = null;
|
||||
this.uri = null;
|
||||
this.extendedKey = null;
|
||||
this.extendedKeyName = null;
|
||||
this.outputDescriptor = null;
|
||||
this.wallets = null;
|
||||
this.seed = null;
|
||||
@@ -679,6 +687,7 @@ public class QRScanDialog extends Dialog<QRScanDialog.Result> {
|
||||
this.psbt = psbt;
|
||||
this.uri = null;
|
||||
this.extendedKey = null;
|
||||
this.extendedKeyName = null;
|
||||
this.outputDescriptor = null;
|
||||
this.wallets = null;
|
||||
this.seed = null;
|
||||
@@ -691,6 +700,7 @@ public class QRScanDialog extends Dialog<QRScanDialog.Result> {
|
||||
this.psbt = null;
|
||||
this.uri = uri;
|
||||
this.extendedKey = null;
|
||||
this.extendedKeyName = null;
|
||||
this.outputDescriptor = null;
|
||||
this.wallets = null;
|
||||
this.seed = null;
|
||||
@@ -703,6 +713,7 @@ public class QRScanDialog extends Dialog<QRScanDialog.Result> {
|
||||
this.psbt = null;
|
||||
this.uri = BitcoinURI.fromAddress(address);
|
||||
this.extendedKey = null;
|
||||
this.extendedKeyName = null;
|
||||
this.outputDescriptor = null;
|
||||
this.wallets = null;
|
||||
this.seed = null;
|
||||
@@ -710,11 +721,12 @@ public class QRScanDialog extends Dialog<QRScanDialog.Result> {
|
||||
this.exception = null;
|
||||
}
|
||||
|
||||
public Result(ExtendedKey extendedKey) {
|
||||
public Result(ExtendedKey extendedKey, String name) {
|
||||
this.transaction = null;
|
||||
this.psbt = null;
|
||||
this.uri = null;
|
||||
this.extendedKey = extendedKey;
|
||||
this.extendedKeyName = name;
|
||||
this.outputDescriptor = null;
|
||||
this.wallets = null;
|
||||
this.seed = null;
|
||||
@@ -727,6 +739,7 @@ public class QRScanDialog extends Dialog<QRScanDialog.Result> {
|
||||
this.psbt = null;
|
||||
this.uri = null;
|
||||
this.extendedKey = null;
|
||||
this.extendedKeyName = null;
|
||||
this.outputDescriptor = outputDescriptor;
|
||||
this.wallets = null;
|
||||
this.seed = null;
|
||||
@@ -739,6 +752,7 @@ public class QRScanDialog extends Dialog<QRScanDialog.Result> {
|
||||
this.psbt = null;
|
||||
this.uri = null;
|
||||
this.extendedKey = null;
|
||||
this.extendedKeyName = null;
|
||||
this.outputDescriptor = null;
|
||||
this.wallets = wallets;
|
||||
this.seed = null;
|
||||
@@ -751,6 +765,7 @@ public class QRScanDialog extends Dialog<QRScanDialog.Result> {
|
||||
this.psbt = null;
|
||||
this.uri = null;
|
||||
this.extendedKey = null;
|
||||
this.extendedKeyName = null;
|
||||
this.outputDescriptor = null;
|
||||
this.wallets = null;
|
||||
this.seed = seed;
|
||||
@@ -763,6 +778,7 @@ public class QRScanDialog extends Dialog<QRScanDialog.Result> {
|
||||
this.psbt = null;
|
||||
this.uri = null;
|
||||
this.extendedKey = null;
|
||||
this.extendedKeyName = null;
|
||||
this.outputDescriptor = null;
|
||||
this.wallets = null;
|
||||
this.seed = null;
|
||||
@@ -775,6 +791,7 @@ public class QRScanDialog extends Dialog<QRScanDialog.Result> {
|
||||
this.psbt = null;
|
||||
this.uri = null;
|
||||
this.extendedKey = null;
|
||||
this.extendedKeyName = null;
|
||||
this.outputDescriptor = null;
|
||||
this.wallets = null;
|
||||
this.seed = null;
|
||||
|
||||
@@ -58,6 +58,8 @@ public class ScriptArea extends CodeArea {
|
||||
append("<signature" + signatureCount++ + ">", "script-signature");
|
||||
} else if(chunk.isPubKey()) {
|
||||
append("<pubkey" + pubKeyCount++ + ">", "script-pubkey");
|
||||
} else if(chunk.isString()) {
|
||||
append(chunk.toString(), "script-other");
|
||||
} else if(chunk.isScript()) {
|
||||
Script nestedScript = chunk.getScript();
|
||||
if (nestedScript.equals(redeemScript)) {
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
package com.sparrowwallet.sparrow.control;
|
||||
|
||||
import com.sparrowwallet.sparrow.AppServices;
|
||||
import javafx.application.Platform;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.layout.StackPane;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SeedEntryDialog extends Dialog<List<String>> {
|
||||
private final MnemonicKeystoreEntryPane keystorePane;
|
||||
|
||||
public SeedEntryDialog(int numWords) {
|
||||
final DialogPane dialogPane = new MnemonicGridDialogPane();
|
||||
setDialogPane(dialogPane);
|
||||
dialogPane.getStylesheets().add(AppServices.class.getResource("general.css").toExternalForm());
|
||||
AppServices.setStageIcon(dialogPane.getScene().getWindow());
|
||||
|
||||
int lines = numWords / 3;
|
||||
int height = lines * 40;
|
||||
|
||||
StackPane stackPane = new StackPane();
|
||||
dialogPane.setContent(stackPane);
|
||||
|
||||
AnchorPane anchorPane = new AnchorPane();
|
||||
ScrollPane scrollPane = new ScrollPane();
|
||||
scrollPane.getStyleClass().add("edge-to-edge");
|
||||
scrollPane.setPrefHeight(104 + height);
|
||||
scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
|
||||
scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
|
||||
anchorPane.getChildren().add(scrollPane);
|
||||
scrollPane.setFitToWidth(true);
|
||||
AnchorPane.setLeftAnchor(scrollPane, 0.0);
|
||||
AnchorPane.setRightAnchor(scrollPane, 0.0);
|
||||
|
||||
Accordion keystoreAccordion = new Accordion();
|
||||
scrollPane.setContent(keystoreAccordion);
|
||||
|
||||
keystorePane = new MnemonicKeystoreEntryPane(numWords);
|
||||
keystorePane.setAnimated(false);
|
||||
keystoreAccordion.getPanes().add(keystorePane);
|
||||
|
||||
stackPane.getChildren().addAll(anchorPane);
|
||||
|
||||
dialogPane.getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);
|
||||
|
||||
Button okButton = (Button)dialogPane.lookupButton(ButtonType.OK);
|
||||
okButton.disableProperty().bind(keystorePane.validProperty().not());
|
||||
|
||||
final ButtonType generateButtonType = new javafx.scene.control.ButtonType("Generate New", ButtonBar.ButtonData.LEFT);
|
||||
dialogPane.getButtonTypes().add(generateButtonType);
|
||||
|
||||
setResultConverter((dialogButton) -> {
|
||||
ButtonBar.ButtonData data = dialogButton == null ? null : dialogButton.getButtonData();
|
||||
return data == ButtonBar.ButtonData.OK_DONE ? keystorePane.wordEntriesProperty.get() : null;
|
||||
});
|
||||
|
||||
dialogPane.setPrefWidth(500);
|
||||
dialogPane.setPrefHeight(180 + height);
|
||||
AppServices.moveToActiveWindowScreen(this);
|
||||
|
||||
Platform.runLater(() -> keystoreAccordion.setExpandedPane(keystorePane));
|
||||
}
|
||||
|
||||
private class MnemonicGridDialogPane extends DialogPane {
|
||||
@Override
|
||||
protected Node createButton(ButtonType buttonType) {
|
||||
Node button;
|
||||
if(buttonType.getButtonData() == ButtonBar.ButtonData.LEFT) {
|
||||
Button generateButton = new Button(buttonType.getText());
|
||||
final ButtonBar.ButtonData buttonData = buttonType.getButtonData();
|
||||
ButtonBar.setButtonData(generateButton, buttonData);
|
||||
generateButton.setOnAction(event -> {
|
||||
keystorePane.generateNew();
|
||||
});
|
||||
|
||||
button = generateButton;
|
||||
} else {
|
||||
button = super.createButton(buttonType);
|
||||
}
|
||||
|
||||
return button;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isGenerated() {
|
||||
return keystorePane.isGenerated();
|
||||
}
|
||||
}
|
||||
@@ -11,10 +11,13 @@ import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Priority;
|
||||
import javafx.stage.FileChooser;
|
||||
import javafx.stage.Stage;
|
||||
import org.controlsfx.glyphfont.Glyph;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Optional;
|
||||
|
||||
public class TextAreaDialog extends Dialog<String> {
|
||||
@@ -22,6 +25,8 @@ public class TextAreaDialog extends Dialog<String> {
|
||||
|
||||
private final TextArea textArea;
|
||||
private final String defaultValue;
|
||||
private final String fileName;
|
||||
private final byte[] fileBytes;
|
||||
|
||||
public TextAreaDialog() {
|
||||
this("");
|
||||
@@ -31,7 +36,11 @@ public class TextAreaDialog extends Dialog<String> {
|
||||
this(defaultValue, true);
|
||||
}
|
||||
|
||||
public TextAreaDialog(@NamedArg("defaultValue") String defaultValue, @NamedArg("editable") boolean editable) {
|
||||
public TextAreaDialog(String defaultValue, boolean editable) {
|
||||
this(defaultValue, editable, null, null);
|
||||
}
|
||||
|
||||
public TextAreaDialog(@NamedArg("defaultValue") String defaultValue, @NamedArg("editable") boolean editable, @NamedArg("fileName") String fileName, @NamedArg("fileBytes") byte[] fileBytes) {
|
||||
final DialogPane dialogPane = new TextAreaDialogPane();
|
||||
setDialogPane(dialogPane);
|
||||
|
||||
@@ -48,6 +57,8 @@ public class TextAreaDialog extends Dialog<String> {
|
||||
HBox.setHgrow(this.textArea, Priority.ALWAYS);
|
||||
|
||||
this.defaultValue = defaultValue;
|
||||
this.fileName = fileName;
|
||||
this.fileBytes = fileBytes;
|
||||
|
||||
dialogPane.setContent(hbox);
|
||||
dialogPane.getStylesheets().add(AppServices.class.getResource("general.css").toExternalForm());
|
||||
@@ -60,6 +71,9 @@ public class TextAreaDialog extends Dialog<String> {
|
||||
|
||||
final ButtonType scanButtonType = new javafx.scene.control.ButtonType("Scan QR", ButtonBar.ButtonData.LEFT);
|
||||
dialogPane.getButtonTypes().add(scanButtonType);
|
||||
} else if(fileBytes != null) {
|
||||
final ButtonType saveButtonType = new javafx.scene.control.ButtonType("Save File...", ButtonBar.ButtonData.LEFT);
|
||||
dialogPane.getButtonTypes().add(saveButtonType);
|
||||
}
|
||||
|
||||
Platform.runLater(textArea::requestFocus);
|
||||
@@ -86,7 +100,7 @@ public class TextAreaDialog extends Dialog<String> {
|
||||
@Override
|
||||
protected Node createButton(ButtonType buttonType) {
|
||||
Node button;
|
||||
if(buttonType.getButtonData() == ButtonBar.ButtonData.LEFT) {
|
||||
if(buttonType.getButtonData() == ButtonBar.ButtonData.LEFT && buttonType.getText().equals("Scan QR")) {
|
||||
Button scanButton = new Button(buttonType.getText());
|
||||
scanButton.setGraphicTextGap(5);
|
||||
scanButton.setGraphic(getGlyph(FontAwesome5.Glyph.CAMERA));
|
||||
@@ -118,6 +132,38 @@ public class TextAreaDialog extends Dialog<String> {
|
||||
});
|
||||
|
||||
button = scanButton;
|
||||
} else if(buttonType.getButtonData() == ButtonBar.ButtonData.LEFT && buttonType.getText().equals("Save File...")) {
|
||||
Button saveButton = new Button(buttonType.getText());
|
||||
|
||||
final ButtonBar.ButtonData buttonData = buttonType.getButtonData();
|
||||
ButtonBar.setButtonData(saveButton, buttonData);
|
||||
|
||||
saveButton.setOnAction(event -> {
|
||||
Stage window = new Stage();
|
||||
|
||||
FileChooser fileChooser = new FileChooser();
|
||||
fileChooser.setTitle("Save File");
|
||||
|
||||
if(fileName != null) {
|
||||
fileChooser.setInitialFileName(fileName);
|
||||
}
|
||||
|
||||
AppServices.moveToActiveWindowScreen(window, 800, 450);
|
||||
File file = fileChooser.showSaveDialog(window);
|
||||
if(file != null) {
|
||||
try {
|
||||
try(OutputStream outputStream = new FileOutputStream(file)) {
|
||||
outputStream.write(fileBytes);
|
||||
outputStream.flush();
|
||||
}
|
||||
} catch(IOException e) {
|
||||
log.error("Error saving file", e);
|
||||
AppServices.showErrorDialog("Error saving file", "Cannot write to " + file.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
button = saveButton;
|
||||
} else {
|
||||
button = super.createButton(buttonType);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
package com.sparrowwallet.sparrow.control;
|
||||
|
||||
import com.sparrowwallet.sparrow.AppServices;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.NamedArg;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Priority;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class TextfieldDialog extends Dialog<String> {
|
||||
private static final Logger log = LoggerFactory.getLogger(TextAreaDialog.class);
|
||||
|
||||
private final TextField textField;
|
||||
private final String defaultValue;
|
||||
|
||||
public TextfieldDialog() {
|
||||
this("");
|
||||
}
|
||||
|
||||
public TextfieldDialog(String defaultValue) {
|
||||
this(defaultValue, true);
|
||||
}
|
||||
|
||||
public TextfieldDialog(@NamedArg("defaultValue") String defaultValue, @NamedArg("editable") boolean editable) {
|
||||
final DialogPane dialogPane = getDialogPane();
|
||||
setDialogPane(dialogPane);
|
||||
|
||||
Image image = new Image("/image/sparrow-small.png");
|
||||
dialogPane.setGraphic(new ImageView(image));
|
||||
|
||||
HBox hbox = new HBox();
|
||||
this.textField = new TextField(defaultValue);
|
||||
this.textField.setMaxWidth(Double.MAX_VALUE);
|
||||
this.textField.setEditable(editable);
|
||||
hbox.getChildren().add(textField);
|
||||
HBox.setHgrow(this.textField, Priority.ALWAYS);
|
||||
|
||||
this.defaultValue = defaultValue;
|
||||
|
||||
dialogPane.setContent(hbox);
|
||||
dialogPane.getStylesheets().add(AppServices.class.getResource("general.css").toExternalForm());
|
||||
AppServices.setStageIcon(dialogPane.getScene().getWindow());
|
||||
|
||||
dialogPane.getStyleClass().add("text-input-dialog");
|
||||
dialogPane.getButtonTypes().add(ButtonType.OK);
|
||||
if(editable) {
|
||||
dialogPane.getButtonTypes().add(ButtonType.CANCEL);
|
||||
}
|
||||
|
||||
Platform.runLater(textField::requestFocus);
|
||||
|
||||
setResultConverter((dialogButton) -> {
|
||||
ButtonBar.ButtonData data = dialogButton == null ? null : dialogButton.getButtonData();
|
||||
return data == ButtonBar.ButtonData.OK_DONE ? textField.getText() : null;
|
||||
});
|
||||
|
||||
dialogPane.setPrefWidth(600);
|
||||
dialogPane.setPrefHeight(230);
|
||||
AppServices.moveToActiveWindowScreen(this);
|
||||
}
|
||||
|
||||
public final TextField getEditor() {
|
||||
return textField;
|
||||
}
|
||||
|
||||
public final String getDefaultValue() {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import com.sparrowwallet.sparrow.glyphfont.FontAwesome5;
|
||||
import com.sparrowwallet.sparrow.io.Config;
|
||||
import javafx.concurrent.ScheduledService;
|
||||
import javafx.concurrent.Task;
|
||||
import javafx.concurrent.Worker;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.scene.Group;
|
||||
import javafx.scene.Node;
|
||||
@@ -33,15 +34,15 @@ public class TorStatusLabel extends Label {
|
||||
}
|
||||
|
||||
public void update() {
|
||||
boolean proxyInUse = AppServices.isUsingProxy();
|
||||
boolean internal = AppServices.isTorRunning();
|
||||
|
||||
if(!proxyInUse || internal) {
|
||||
if(!Config.get().isUseProxy()) {
|
||||
torConnectionTest.cancel();
|
||||
if(internal) {
|
||||
if(AppServices.isTorRunning()) {
|
||||
setTooltip(new Tooltip("Internal Tor proxy enabled"));
|
||||
}
|
||||
} else if(!torConnectionTest.isRunning()) {
|
||||
if(torConnectionTest.getState() == Worker.State.CANCELLED || torConnectionTest.getState() == Worker.State.FAILED) {
|
||||
torConnectionTest.reset();
|
||||
}
|
||||
torConnectionTest.setPeriod(Duration.seconds(20.0));
|
||||
torConnectionTest.setBackoffStrategy(null);
|
||||
torConnectionTest.setOnSucceeded(workerStateEvent -> {
|
||||
|
||||
@@ -44,7 +44,7 @@ public class WalletExportDialog extends Dialog<Wallet> {
|
||||
if(wallet.getPolicyType() == PolicyType.SINGLE) {
|
||||
exporters = List.of(new Electrum(), new ElectrumPersonalServer(), new Descriptor(), new SpecterDesktop(), new Sparrow(), new WalletLabels());
|
||||
} else if(wallet.getPolicyType() == PolicyType.MULTI) {
|
||||
exporters = List.of(new CaravanMultisig(), new ColdcardMultisig(), new CoboVaultMultisig(), new Electrum(), new ElectrumPersonalServer(), new KeystoneMultisig(), new Descriptor(), new JadeMultisig(), new PassportMultisig(), new SpecterDesktop(), new BlueWalletMultisig(), new SpecterDIY(), new Sparrow(), new WalletLabels());
|
||||
exporters = List.of(new Bip129(), new CaravanMultisig(), new ColdcardMultisig(), new CoboVaultMultisig(), new Electrum(), new ElectrumPersonalServer(), new KeystoneMultisig(), new Descriptor(), new JadeMultisig(), new PassportMultisig(), new SpecterDesktop(), new BlueWalletMultisig(), new SpecterDIY(), new Sparrow(), new WalletLabels());
|
||||
} else {
|
||||
throw new UnsupportedOperationException("Cannot export wallet with policy type " + wallet.getPolicyType());
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ public class WalletImportDialog extends Dialog<Wallet> {
|
||||
}
|
||||
}
|
||||
|
||||
List<WalletImport> walletImporters = new ArrayList<>(List.of(new CaravanMultisig(), new ColdcardMultisig(), new CoboVaultMultisig(), new Electrum(), new KeystoneMultisig(), new Descriptor(), new SpecterDesktop(), new BlueWalletMultisig(), new Sparrow()));
|
||||
List<WalletImport> walletImporters = new ArrayList<>(List.of(new Bip129(), new CaravanMultisig(), new ColdcardMultisig(), new CoboVaultMultisig(), new Electrum(), new KeystoneMultisig(), new Descriptor(), new SpecterDesktop(), new BlueWalletMultisig(), new Sparrow()));
|
||||
if(!selectedWalletForms.isEmpty()) {
|
||||
walletImporters.add(new WalletLabels(selectedWalletForms));
|
||||
}
|
||||
|
||||
@@ -34,6 +34,14 @@ public class WalletNameDialog extends Dialog<WalletNameDialog.NameAndBirthDate>
|
||||
}
|
||||
|
||||
public WalletNameDialog(String initialName) {
|
||||
this(initialName, false);
|
||||
}
|
||||
|
||||
public WalletNameDialog(String initialName, boolean hasExistingTransactions) {
|
||||
this(initialName, hasExistingTransactions, null);
|
||||
}
|
||||
|
||||
public WalletNameDialog(String initialName, boolean hasExistingTransactions, Date startDate) {
|
||||
final DialogPane dialogPane = getDialogPane();
|
||||
AppServices.setStageIcon(dialogPane.getScene().getWindow());
|
||||
boolean requestBirthDate = (Config.get().getServerType() == null || Config.get().getServerType() == ServerType.BITCOIN_CORE);
|
||||
@@ -91,6 +99,12 @@ public class WalletNameDialog extends Dialog<WalletNameDialog.NameAndBirthDate>
|
||||
|
||||
if(requestBirthDate) {
|
||||
content.getChildren().add(existingBox);
|
||||
if(hasExistingTransactions) {
|
||||
existingCheck.setSelected(true);
|
||||
}
|
||||
if(startDate != null) {
|
||||
existingPicker.setValue(startDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate());
|
||||
}
|
||||
}
|
||||
|
||||
dialogPane.setContent(content);
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.sparrowwallet.sparrow.event;
|
||||
|
||||
import com.sparrowwallet.drongo.wallet.Wallet;
|
||||
|
||||
public class ExistingWalletImportedEvent {
|
||||
private final String existingWalletId;
|
||||
private final Wallet importedWallet;
|
||||
|
||||
public ExistingWalletImportedEvent(String existingWalletId, Wallet importedWallet) {
|
||||
this.existingWalletId = existingWalletId;
|
||||
this.importedWallet = importedWallet;
|
||||
}
|
||||
|
||||
public String getExistingWalletId() {
|
||||
return existingWalletId;
|
||||
}
|
||||
|
||||
public Wallet getImportedWallet() {
|
||||
return importedWallet;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.sparrowwallet.sparrow.event;
|
||||
|
||||
import com.sparrowwallet.drongo.wallet.Keystore;
|
||||
|
||||
public class KeystoreExportEvent {
|
||||
private final Keystore keystore;
|
||||
|
||||
public KeystoreExportEvent(Keystore keystore) {
|
||||
this.keystore = keystore;
|
||||
}
|
||||
|
||||
public Keystore getKeystore() {
|
||||
return keystore;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.sparrowwallet.sparrow.event;
|
||||
|
||||
import com.sparrowwallet.drongo.wallet.Wallet;
|
||||
import com.sparrowwallet.sparrow.io.Storage;
|
||||
|
||||
public class NewChildWalletSavedEvent {
|
||||
private final Storage storage;
|
||||
private final Wallet masterWallet;
|
||||
private final Wallet childWallet;
|
||||
|
||||
public NewChildWalletSavedEvent(Storage storage, Wallet masterWallet, Wallet childWallet) {
|
||||
this.storage = storage;
|
||||
this.masterWallet = masterWallet;
|
||||
this.childWallet = childWallet;
|
||||
}
|
||||
|
||||
public String getMasterWalletId() {
|
||||
return storage.getWalletId(masterWallet);
|
||||
}
|
||||
|
||||
public Wallet getChildWallet() {
|
||||
return childWallet;
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,10 @@
|
||||
package com.sparrowwallet.sparrow.event;
|
||||
|
||||
import com.sparrowwallet.sparrow.net.TorServerAlreadyBoundException;
|
||||
|
||||
public class TorFailedStatusEvent extends TorStatusEvent {
|
||||
private final Throwable exception;
|
||||
|
||||
public TorFailedStatusEvent(Throwable exception) {
|
||||
super("Tor failed to start: " + (exception instanceof TorServerAlreadyBoundException ? exception.getCause().getMessage() + " Is a Tor proxy already running?" :
|
||||
(exception.getCause() != null ? exception.getCause().getMessage() : exception.getMessage())));
|
||||
super("Tor failed to start: " + (exception.getCause() != null ? exception.getCause().getMessage() : exception.getMessage()));
|
||||
this.exception = exception;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,17 +1,41 @@
|
||||
package com.sparrowwallet.sparrow.event;
|
||||
|
||||
import com.sparrowwallet.drongo.wallet.Wallet;
|
||||
import com.sparrowwallet.drongo.wallet.WalletNode;
|
||||
|
||||
/**
|
||||
* This event is posted if the wallet's gap limit has changed, and triggers a history fetch for the new nodes.
|
||||
*
|
||||
*/
|
||||
public class WalletGapLimitChangedEvent extends WalletChangedEvent {
|
||||
public WalletGapLimitChangedEvent(Wallet wallet) {
|
||||
private final String walletId;
|
||||
private final int previousGapLimit;
|
||||
|
||||
public WalletGapLimitChangedEvent(String walletId, Wallet wallet, int previousGapLimit) {
|
||||
super(wallet);
|
||||
this.walletId = walletId;
|
||||
this.previousGapLimit = previousGapLimit;
|
||||
}
|
||||
|
||||
public String getWalletId() {
|
||||
return walletId;
|
||||
}
|
||||
|
||||
public int getGapLimit() {
|
||||
return getWallet().getGapLimit();
|
||||
}
|
||||
|
||||
public int getPreviousGapLimit() {
|
||||
return previousGapLimit;
|
||||
}
|
||||
|
||||
public int getPreviousLookAheadIndex(WalletNode node) {
|
||||
int lookAheadIndex = getPreviousGapLimit() - 1;
|
||||
Integer highestUsed = node.getHighestUsedIndex();
|
||||
if(highestUsed != null) {
|
||||
lookAheadIndex = highestUsed + getPreviousGapLimit();
|
||||
}
|
||||
|
||||
return lookAheadIndex;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,6 +76,7 @@ public class FontAwesome5 extends GlyphFont {
|
||||
TOGGLE_OFF('\uf204'),
|
||||
TOGGLE_ON('\uf205'),
|
||||
TOOLS('\uf7d9'),
|
||||
UP_RIGHT_FROM_SQUARE('\uf35d'),
|
||||
UNDO('\uf0e2'),
|
||||
USER('\uf007'),
|
||||
USER_FRIENDS('\uf500'),
|
||||
|
||||
@@ -0,0 +1,253 @@
|
||||
package com.sparrowwallet.sparrow.io;
|
||||
|
||||
import com.google.common.io.CharStreams;
|
||||
import com.sparrowwallet.drongo.KeyPurpose;
|
||||
import com.sparrowwallet.drongo.OutputDescriptor;
|
||||
import com.sparrowwallet.drongo.Utils;
|
||||
import com.sparrowwallet.drongo.crypto.Pbkdf2KeyDeriver;
|
||||
import com.sparrowwallet.drongo.protocol.ScriptType;
|
||||
import com.sparrowwallet.drongo.protocol.Sha256Hash;
|
||||
import com.sparrowwallet.drongo.wallet.*;
|
||||
|
||||
import javax.crypto.*;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.io.*;
|
||||
import java.math.BigInteger;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Bip129 implements KeystoreFileExport, KeystoreFileImport, WalletExport, WalletImport {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "BSMS";
|
||||
}
|
||||
|
||||
@Override
|
||||
public WalletModel getWalletModel() {
|
||||
return WalletModel.BSMS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKeystoreExportDescription() {
|
||||
return "Exports the keystore in the Bitcoin Secure Multisig Setup (BSMS) format.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exportKeystore(Keystore keystore, OutputStream outputStream) throws ExportException {
|
||||
if(!keystore.isValid()) {
|
||||
throw new ExportException("Invalid keystore");
|
||||
}
|
||||
|
||||
try {
|
||||
String record = "BSMS 1.0\n00\n[" +
|
||||
keystore.getKeyDerivation().toString() +
|
||||
"]" +
|
||||
keystore.getExtendedPublicKey().toString() +
|
||||
"\n" +
|
||||
keystore.getLabel();
|
||||
outputStream.write(record.getBytes(StandardCharsets.UTF_8));
|
||||
} catch(Exception e) {
|
||||
throw new ExportException("Error writing BSMS file", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requiresSignature() {
|
||||
//Due to poor vendor support of multiline message signing at the xpub derivation path, signing BSMS keystore exports is configurable (default false)
|
||||
return Config.get().isSignBsmsExports();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSignature(Keystore keystore, String signature, OutputStream outputStream) throws ExportException {
|
||||
try {
|
||||
String append = "\n" + signature;
|
||||
outputStream.write(append.getBytes(StandardCharsets.UTF_8));
|
||||
} catch(Exception e) {
|
||||
throw new ExportException("Error writing BSMS file", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getExportFileExtension(Keystore keystore) {
|
||||
return "bsms";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isKeystoreExportScannable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEncrypted(File file) {
|
||||
try {
|
||||
try(BufferedReader reader = new BufferedReader(new FileReader(file, StandardCharsets.UTF_8))) {
|
||||
String text = CharStreams.toString(reader);
|
||||
return Utils.isHex(text.trim());
|
||||
}
|
||||
} catch(Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Keystore getKeystore(ScriptType scriptType, InputStream inputStream, String password) throws ImportException {
|
||||
try {
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
|
||||
if(password != null) {
|
||||
reader = decryptImport(password, reader);
|
||||
}
|
||||
|
||||
String header = reader.readLine();
|
||||
String token = reader.readLine();
|
||||
String descriptor = reader.readLine();
|
||||
String label = reader.readLine();
|
||||
String signature = reader.readLine();
|
||||
|
||||
return getKeystore(header, token, descriptor, label, signature);
|
||||
} catch(MnemonicException.MnemonicWordException e) {
|
||||
throw new ImportException("Error importing BSMS: Invalid mnemonic word " + e.badWord, e);
|
||||
} catch(MnemonicException.MnemonicChecksumException e) {
|
||||
throw new ImportException("Error importing BSMS: Invalid mnemonic checksum", e);
|
||||
} catch(Exception e) {
|
||||
throw new ImportException("Error importing BSMS", e);
|
||||
}
|
||||
}
|
||||
|
||||
private BufferedReader decryptImport(String password, BufferedReader streamReader) throws Exception {
|
||||
byte[] token;
|
||||
if((password.length() == 16 || password.length() == 32) && Utils.isHex(password)) {
|
||||
token = Utils.hexToBytes(password);
|
||||
} else if(Utils.isNumber(password)) {
|
||||
BigInteger bi = new BigInteger(password);
|
||||
token = Utils.bigIntegerToBytes(bi, bi.toByteArray().length >= 16 ? 16 : 8);
|
||||
} else if(password.split(" ").length == 6 || password.split(" ").length == 12) {
|
||||
List<String> mnemonicWords = Arrays.asList(password.split(" "));
|
||||
token = Bip39MnemonicCode.INSTANCE.toEntropy(mnemonicWords);
|
||||
} else {
|
||||
throw new ImportException("Provided password needs to be in hexadecimal, decimal or mnemonic format.");
|
||||
}
|
||||
|
||||
String hex = CharStreams.toString(streamReader).trim();
|
||||
byte[] data = Utils.hexToBytes(hex);
|
||||
byte[] mac = Arrays.copyOfRange(data, 0, 32);
|
||||
byte[] iv = Arrays.copyOfRange(mac, 0, 16);
|
||||
byte[] ciphertext = Arrays.copyOfRange(data, 32, data.length);
|
||||
|
||||
Cipher cipher = Cipher.getInstance("AES/CTR/NoPadding");
|
||||
|
||||
Pbkdf2KeyDeriver pbkdf2KeyDeriver = new Pbkdf2KeyDeriver(token, 2048, 256);
|
||||
byte[] key = pbkdf2KeyDeriver.deriveKey("No SPOF").getKeyBytes();
|
||||
|
||||
Key keySpec = new SecretKeySpec(key, "AES");
|
||||
IvParameterSpec ivSpec = new IvParameterSpec(iv);
|
||||
|
||||
cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);
|
||||
byte[] plaintext = cipher.doFinal(ciphertext);
|
||||
String plaintextString = new String(plaintext, StandardCharsets.UTF_8);
|
||||
|
||||
SecretKeySpec secretKeySpec = new SecretKeySpec(Sha256Hash.hash(key), "HmacSHA256");
|
||||
Mac hmac = Mac.getInstance("HmacSHA256");
|
||||
hmac.init(secretKeySpec);
|
||||
String macData = Utils.bytesToHex(token) + plaintextString;
|
||||
byte[] calculatedMac = hmac.doFinal(macData.getBytes(StandardCharsets.UTF_8));
|
||||
if(!Arrays.equals(mac, calculatedMac)) {
|
||||
throw new ImportException("Message digest authentication failed.");
|
||||
}
|
||||
|
||||
return new BufferedReader(new StringReader(plaintextString));
|
||||
}
|
||||
|
||||
private Keystore getKeystore(String header, String token, String descriptor, String label, String signature) throws ImportException {
|
||||
OutputDescriptor outputDescriptor = OutputDescriptor.getOutputDescriptor("sh(" + descriptor + ")");
|
||||
Wallet wallet = outputDescriptor.toWallet();
|
||||
Keystore keystore = wallet.getKeystores().get(0);
|
||||
keystore.setLabel(label);
|
||||
|
||||
if(signature != null) {
|
||||
try {
|
||||
String message = header + "\n" + token + "\n" + descriptor + "\n" + label;
|
||||
keystore.getExtendedPublicKey().getKey().verifyMessage(message, signature);
|
||||
} catch(SignatureException e) {
|
||||
throw new ImportException("Signature did not match provided public key", e);
|
||||
}
|
||||
}
|
||||
|
||||
return keystore;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKeystoreImportDescription(int account) {
|
||||
return "Imports a keystore that was exported using the Bitcoin Secure Multisig Setup (BSMS) format.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isKeystoreImportScannable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exportWallet(Wallet wallet, OutputStream outputStream) throws ExportException {
|
||||
try {
|
||||
String record = "BSMS 1.0\n" +
|
||||
OutputDescriptor.getOutputDescriptor(wallet) +
|
||||
"\n/0/*,/1/*\n" +
|
||||
wallet.getNode(KeyPurpose.RECEIVE).getChildren().iterator().next().getAddress();
|
||||
outputStream.write(record.getBytes(StandardCharsets.UTF_8));
|
||||
} catch(Exception e) {
|
||||
throw new ExportException("Error exporting BSMS format", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getWalletExportDescription() {
|
||||
return "Exports a multisig wallet in the Bitcoin Secure Multisig Setup (BSMS) format for import by other signers in the quorum.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getExportFileExtension(Wallet wallet) {
|
||||
return "bsms";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWalletExportScannable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean walletExportRequiresDecryption() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getWalletImportDescription() {
|
||||
return "Imports a multisig wallet in the Bitcoin Secure Multisig Setup (BSMS) format that has been created by another signer in the quorum.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Wallet importWallet(InputStream inputStream, String password) throws ImportException {
|
||||
try {
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
|
||||
if(password != null) {
|
||||
reader = decryptImport(password, reader);
|
||||
}
|
||||
|
||||
String header = reader.readLine();
|
||||
String descriptor = reader.readLine();
|
||||
String paths = reader.readLine();
|
||||
String address = reader.readLine();
|
||||
|
||||
OutputDescriptor outputDescriptor = OutputDescriptor.getOutputDescriptor(descriptor);
|
||||
return outputDescriptor.toWallet();
|
||||
} catch(Exception e) {
|
||||
throw new ImportException("Error importing BSMS format", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWalletImportScannable() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -99,6 +99,8 @@ public abstract class CardApi {
|
||||
Throwable cause = Throwables.getRootCause(e);
|
||||
if(cause.getMessage().equals("SCARD_E_NO_SERVICE")) {
|
||||
recoverNoService();
|
||||
} else if(cause.getMessage().equals("SCARD_E_NO_READERS_AVAILABLE")) {
|
||||
log.info("Error detecting card terminals", e);
|
||||
} else {
|
||||
log.error("Error detecting card terminals", e);
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ public class Config {
|
||||
private Mode mode;
|
||||
private BitcoinUnit bitcoinUnit;
|
||||
private UnitFormat unitFormat;
|
||||
private Server blockExplorer;
|
||||
private FeeRatesSource feeRatesSource;
|
||||
private FeeRatesSelection feeRatesSelection;
|
||||
private OptimizationStrategy sendOptimizationStrategy;
|
||||
@@ -48,6 +49,7 @@ public class Config {
|
||||
private boolean showLoadingLog = true;
|
||||
private boolean showAddressTransactionCount = false;
|
||||
private boolean showDeprecatedImportExport = false;
|
||||
private boolean signBsmsExports = false;
|
||||
private boolean preventSleep = false;
|
||||
private List<File> recentWalletFiles;
|
||||
private Integer keyDerivationPeriod;
|
||||
@@ -149,6 +151,19 @@ public class Config {
|
||||
flush();
|
||||
}
|
||||
|
||||
public boolean isBlockExplorerDisabled() {
|
||||
return BlockExplorer.NONE.getServer().equals(blockExplorer);
|
||||
}
|
||||
|
||||
public Server getBlockExplorer() {
|
||||
return blockExplorer;
|
||||
}
|
||||
|
||||
public void setBlockExplorer(Server blockExplorer) {
|
||||
this.blockExplorer = blockExplorer;
|
||||
flush();
|
||||
}
|
||||
|
||||
public FeeRatesSource getFeeRatesSource() {
|
||||
return feeRatesSource;
|
||||
}
|
||||
@@ -315,6 +330,15 @@ public class Config {
|
||||
flush();
|
||||
}
|
||||
|
||||
public boolean isSignBsmsExports() {
|
||||
return signBsmsExports;
|
||||
}
|
||||
|
||||
public void setSignBsmsExports(boolean signBsmsExports) {
|
||||
this.signBsmsExports = signBsmsExports;
|
||||
flush();
|
||||
}
|
||||
|
||||
public boolean isPreventSleep() {
|
||||
return preventSleep;
|
||||
}
|
||||
|
||||
@@ -136,6 +136,6 @@ public class Descriptor implements WalletImport, WalletExport {
|
||||
|
||||
@Override
|
||||
public boolean isWalletImportScannable() {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ public class Hwi {
|
||||
private static final Logger log = LoggerFactory.getLogger(Hwi.class);
|
||||
private static final String HWI_HOME_DIR = "hwi";
|
||||
private static final String HWI_VERSION_PREFIX = "hwi-";
|
||||
private static final String HWI_VERSION = "2.2.0";
|
||||
private static final String HWI_VERSION = "2.2.1";
|
||||
private static final String HWI_VERSION_DIR = HWI_VERSION_PREFIX + HWI_VERSION;
|
||||
|
||||
private static boolean isPromptActive = false;
|
||||
@@ -278,7 +278,7 @@ public class Hwi {
|
||||
} catch(IOException e) {
|
||||
throw new SignTransactionException("Could not sign PSBT", e);
|
||||
} catch(PSBTParseException e) {
|
||||
throw new SignTransactionException("Could not parse signed PSBT", e);
|
||||
throw new SignTransactionException("Could not parse signed PSBT" + (e.getMessage() != null ? ": " + e.getMessage() : ""), e);
|
||||
} finally {
|
||||
isPromptActive = false;
|
||||
}
|
||||
@@ -290,9 +290,7 @@ public class Hwi {
|
||||
try {
|
||||
ProcessBuilder processBuilder = new ProcessBuilder(command);
|
||||
process = processBuilder.start();
|
||||
try(InputStreamReader reader = new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8)) {
|
||||
return CharStreams.toString(reader);
|
||||
}
|
||||
return getProcessOutput(process);
|
||||
} finally {
|
||||
deleteExtractionOnFailure(process, start);
|
||||
}
|
||||
@@ -303,29 +301,54 @@ public class Hwi {
|
||||
Process process = null;
|
||||
try {
|
||||
List<String> processArguments = new ArrayList<>(arguments);
|
||||
processArguments.add("--stdin");
|
||||
|
||||
boolean useStdin = Arrays.stream(commandArguments).noneMatch(arg -> arg.contains("\n"));
|
||||
if(useStdin) {
|
||||
processArguments.add("--stdin");
|
||||
} else {
|
||||
processArguments.add(command.toString());
|
||||
processArguments.addAll(Arrays.asList(commandArguments));
|
||||
}
|
||||
|
||||
ProcessBuilder processBuilder = new ProcessBuilder(processArguments);
|
||||
process = processBuilder.start();
|
||||
|
||||
try(BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(process.getOutputStream(), StandardCharsets.UTF_8))) {
|
||||
writer.write(command.toString());
|
||||
for(String commandArgument : commandArguments) {
|
||||
writer.write(" \"");
|
||||
writer.write(commandArgument.replace("\\", "\\\\").replace("\"", "\\\""));
|
||||
writer.write("\"");
|
||||
if(useStdin) {
|
||||
try(BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(process.getOutputStream(), StandardCharsets.UTF_8))) {
|
||||
writer.write(command.toString());
|
||||
for(String commandArgument : commandArguments) {
|
||||
writer.write(" \"");
|
||||
writer.write(commandArgument.replace("\\", "\\\\").replace("\"", "\\\""));
|
||||
writer.write("\"");
|
||||
}
|
||||
writer.flush();
|
||||
}
|
||||
writer.flush();
|
||||
}
|
||||
|
||||
try(InputStreamReader reader = new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8)) {
|
||||
return CharStreams.toString(reader);
|
||||
}
|
||||
return getProcessOutput(process);
|
||||
} finally {
|
||||
deleteExtractionOnFailure(process, start);
|
||||
}
|
||||
}
|
||||
|
||||
private String getProcessOutput(Process process) throws IOException {
|
||||
String output;
|
||||
try(InputStreamReader reader = new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8)) {
|
||||
output = CharStreams.toString(reader);
|
||||
}
|
||||
|
||||
if(output.isEmpty() && process.getErrorStream() != null) {
|
||||
try(InputStreamReader reader = new InputStreamReader(process.getErrorStream(), StandardCharsets.UTF_8)) {
|
||||
String errorOutput = CharStreams.toString(reader);
|
||||
if(!errorOutput.isEmpty()) {
|
||||
throw new IOException(errorOutput);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
private synchronized File getHwiExecutable(Command command) {
|
||||
File hwiExecutable = Config.get().getHwi();
|
||||
if(hwiExecutable != null && hwiExecutable.exists()) {
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.sparrowwallet.sparrow.io;
|
||||
|
||||
public interface KeystoreExport extends ImportExport {
|
||||
String getKeystoreExportDescription();
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.sparrowwallet.sparrow.io;
|
||||
|
||||
import com.sparrowwallet.drongo.wallet.Keystore;
|
||||
|
||||
import java.io.OutputStream;
|
||||
|
||||
public interface KeystoreFileExport extends KeystoreExport {
|
||||
void exportKeystore(Keystore keystore, OutputStream outputStream) throws ExportException;
|
||||
boolean requiresSignature();
|
||||
void addSignature(Keystore keystore, String signature, OutputStream outputStream) throws ExportException;
|
||||
String getExportFileExtension(Keystore keystore);
|
||||
boolean isKeystoreExportScannable();
|
||||
default boolean isKeystoreExportFile() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -9,10 +9,14 @@ import com.google.zxing.qrcode.QRCodeWriter;
|
||||
import com.lowagie.text.*;
|
||||
import com.lowagie.text.Font;
|
||||
import com.lowagie.text.Image;
|
||||
import com.lowagie.text.Rectangle;
|
||||
import com.lowagie.text.alignment.HorizontalAlignment;
|
||||
import com.lowagie.text.alignment.VerticalAlignment;
|
||||
import com.lowagie.text.pdf.PdfReader;
|
||||
import com.lowagie.text.pdf.PdfWriter;
|
||||
import com.lowagie.text.pdf.parser.PdfTextExtractor;
|
||||
import com.sparrowwallet.drongo.OutputDescriptor;
|
||||
import com.sparrowwallet.drongo.Utils;
|
||||
import com.sparrowwallet.drongo.protocol.ScriptType;
|
||||
import com.sparrowwallet.hummingbird.UR;
|
||||
import com.sparrowwallet.hummingbird.UREncoder;
|
||||
@@ -25,7 +29,8 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.*;
|
||||
import java.util.Scanner;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
public class PdfUtils {
|
||||
private static final Logger log = LoggerFactory.getLogger(PdfUtils.class);
|
||||
@@ -99,7 +104,7 @@ public class PdfUtils {
|
||||
|
||||
private static javafx.scene.image.Image getQrCode(String fragment) throws IOException, WriterException {
|
||||
QRCodeWriter qrCodeWriter = new QRCodeWriter();
|
||||
BitMatrix qrMatrix = qrCodeWriter.encode(fragment, BarcodeFormat.QR_CODE, QR_WIDTH, QR_HEIGHT);
|
||||
BitMatrix qrMatrix = qrCodeWriter.encode(fragment.toUpperCase(Locale.ROOT), BarcodeFormat.QR_CODE, QR_WIDTH, QR_HEIGHT);
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
MatrixToImageWriter.writeToStream(qrMatrix, "PNG", baos, new MatrixToImageConfig());
|
||||
@@ -107,4 +112,104 @@ public class PdfUtils {
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
||||
return new javafx.scene.image.Image(bais);
|
||||
}
|
||||
|
||||
public static String[][] getWordGrid(InputStream inputStream) {
|
||||
try {
|
||||
PdfReader pdfReader = new PdfReader(inputStream);
|
||||
String allText = "";
|
||||
for(int page = 1; page <= pdfReader.getNumberOfPages(); page++) {
|
||||
PdfTextExtractor textExtractor = new PdfTextExtractor(pdfReader);
|
||||
allText += textExtractor.getTextFromPage(page) + "\n";
|
||||
}
|
||||
|
||||
List<String[]> rows = new ArrayList<>();
|
||||
Scanner scanner = new Scanner(allText);
|
||||
while(scanner.hasNextLine()) {
|
||||
String line = scanner.nextLine().trim();
|
||||
String[] words = line.split(" ");
|
||||
if(words.length > 16 && Utils.isNumber(words[0])) {
|
||||
rows.add(Arrays.copyOfRange(words, 1, 17));
|
||||
}
|
||||
}
|
||||
|
||||
if(rows.size() < 128) {
|
||||
throw new IllegalArgumentException("Not a valid Border Wallets PDF");
|
||||
}
|
||||
|
||||
return rows.toArray(new String[][]{new String[0]});
|
||||
} catch(Exception e) {
|
||||
throw new IllegalArgumentException("Not a valid Border Wallets PDF");
|
||||
}
|
||||
}
|
||||
|
||||
public static void saveWordGrid(String[][] wordGrid, List<String> mnemonicWords) {
|
||||
Stage window = new Stage();
|
||||
FileChooser fileChooser = new FileChooser();
|
||||
fileChooser.setTitle("Save Border Wallet Grid");
|
||||
fileChooser.setInitialFileName("BorderWalletEntropyGrid.pdf");
|
||||
AppServices.moveToActiveWindowScreen(window, 800, 450);
|
||||
File file = fileChooser.showSaveDialog(window);
|
||||
if(file != null) {
|
||||
try(Document document = new Document()) {
|
||||
document.setMargins(0, 0, 10, 10);
|
||||
PdfWriter.getInstance(document, new FileOutputStream(file));
|
||||
|
||||
Font headerFont = new Font(Font.HELVETICA, 8, Font.BOLD, Color.DARK_GRAY);
|
||||
Font font = new Font(Font.HELVETICA, 8, Font.NORMAL, Color.DARK_GRAY);
|
||||
|
||||
HeaderFooter footer = new HeaderFooter(false, new Phrase("Recovery Phrase: " + String.join(" ", mnemonicWords), font));
|
||||
footer.setAlignment(Element.ALIGN_CENTER);
|
||||
footer.setBorder(Rectangle.NO_BORDER);
|
||||
footer.setBorderWidth(0);
|
||||
document.setFooter(footer);
|
||||
|
||||
document.open();
|
||||
|
||||
int rowCount = wordGrid.length;
|
||||
int columnCount = wordGrid[0].length;
|
||||
|
||||
Table table = new Table(columnCount + 2);
|
||||
table.setBorderWidth(0.5f);
|
||||
table.setBorderColor(new Color(208, 208, 208));
|
||||
table.setBorderWidthLeft(0);
|
||||
table.setBorderWidthRight(0);
|
||||
|
||||
List<String> headers = List.of(" ", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", " ");
|
||||
for(String header : headers) {
|
||||
Paragraph paragraph = new Paragraph(header, headerFont);
|
||||
Cell cell = new Cell(paragraph);
|
||||
cell.setBackgroundColor(new Color(218, 218, 218));
|
||||
cell.setHorizontalAlignment(HorizontalAlignment.CENTER);
|
||||
cell.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||
cell.setBorderWidth(0.5f);
|
||||
cell.setBorderColor(new Color(208, 208, 208));
|
||||
cell.setHeader(true);
|
||||
table.addCell(cell);
|
||||
}
|
||||
table.endHeaders();
|
||||
|
||||
for(int i = 0; i < rowCount; i++) {
|
||||
for(int j = 0; j < columnCount + 2; j++) {
|
||||
Cell cell;
|
||||
if(j == 0 || j == columnCount + 1) {
|
||||
cell = new Cell(new Paragraph(String.format("%03d", i + 1), headerFont));
|
||||
cell.setBackgroundColor(new Color(218, 218, 218));
|
||||
} else {
|
||||
cell = new Cell(new Paragraph(wordGrid[i][j-1], font));
|
||||
}
|
||||
cell.setHorizontalAlignment(HorizontalAlignment.CENTER);
|
||||
cell.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||
cell.setBorderWidth(0.5f);
|
||||
cell.setBorderColor(new Color(208, 208, 208));
|
||||
table.addCell(cell);
|
||||
}
|
||||
}
|
||||
|
||||
document.add(table);
|
||||
} catch(Exception e) {
|
||||
log.error("Error creating word grid PDF", e);
|
||||
AppServices.showErrorDialog("Error creating word grid PDF", e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,6 +70,14 @@ public class Server {
|
||||
return url + (alias == null ? "" : "|" + alias);
|
||||
}
|
||||
|
||||
public boolean portEquals(String port) {
|
||||
if(port == null) {
|
||||
return !getHostAndPort().hasPort();
|
||||
}
|
||||
|
||||
return port.equals(getHostAndPort().hasPort() ? Integer.toString(getHostAndPort().getPort()) : "");
|
||||
}
|
||||
|
||||
public static Server fromString(String server) {
|
||||
String[] parts = server.split("\\|");
|
||||
if(parts.length >= 2) {
|
||||
|
||||
@@ -23,10 +23,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.smartcardio.CardException;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.*;
|
||||
|
||||
public class CkCardApi extends CardApi {
|
||||
private static final Logger log = LoggerFactory.getLogger(CkCardApi.class);
|
||||
@@ -227,8 +224,18 @@ public class CkCardApi extends CardApi {
|
||||
}
|
||||
|
||||
String signMessage(String message, ScriptType scriptType, List<ChildNumber> derivation) throws CardException {
|
||||
List<ChildNumber> keystoreDerivation = derivation.subList(0, derivation.size() - 2);
|
||||
List<ChildNumber> subPathDerivation = derivation.subList(derivation.size() - 2, derivation.size());
|
||||
List<ChildNumber> keystoreDerivation;
|
||||
List<ChildNumber> subPathDerivation;
|
||||
|
||||
Optional<ChildNumber> firstUnhardened = derivation.stream().filter(cn -> !cn.isHardened()).findFirst();
|
||||
if(firstUnhardened.isPresent()) {
|
||||
int index = derivation.indexOf(firstUnhardened.get());
|
||||
keystoreDerivation = derivation.subList(0, index);
|
||||
subPathDerivation = derivation.subList(index, derivation.size());
|
||||
} else {
|
||||
keystoreDerivation = derivation;
|
||||
subPathDerivation = Collections.emptyList();
|
||||
}
|
||||
|
||||
Keystore cardKeystore = getKeystore();
|
||||
KeyDerivation cardKeyDerivation = cardKeystore.getKeyDerivation();
|
||||
@@ -239,9 +246,15 @@ public class CkCardApi extends CardApi {
|
||||
signingKeystore = getKeystore();
|
||||
}
|
||||
|
||||
WalletNode addressNode = new WalletNode(KeyDerivation.writePath(subPathDerivation));
|
||||
ECKey addressPubKey = signingKeystore.getPubKey(addressNode);
|
||||
return addressPubKey.signMessage(message, scriptType, hash -> {
|
||||
ECKey signingPubKey;
|
||||
if(subPathDerivation.isEmpty()) {
|
||||
signingPubKey = signingKeystore.getExtendedPublicKey().getKey();
|
||||
} else {
|
||||
WalletNode addressNode = new WalletNode(KeyDerivation.writePath(subPathDerivation));
|
||||
signingPubKey = signingKeystore.getPubKey(addressNode);
|
||||
}
|
||||
|
||||
return signingPubKey.signMessage(message, scriptType, hash -> {
|
||||
try {
|
||||
CardSign cardSign = cardProtocol.sign(cvc, subPathDerivation, hash);
|
||||
return cardSign.getSignature();
|
||||
|
||||
@@ -28,7 +28,7 @@ public class HwAirgappedController extends KeystoreImportDetailController {
|
||||
if(getMasterController().getWallet().getPolicyType().equals(PolicyType.SINGLE)) {
|
||||
fileImporters = List.of(new ColdcardSinglesig(), new CoboVaultSinglesig(), new Jade(), new KeystoneSinglesig(), new PassportSinglesig(), new SeedSigner(), new GordianSeedTool(), new SpecterDIY());
|
||||
} else if(getMasterController().getWallet().getPolicyType().equals(PolicyType.MULTI)) {
|
||||
fileImporters = List.of(new ColdcardMultisig(), new CoboVaultMultisig(), new Jade(), new KeystoneMultisig(), new PassportMultisig(), new SeedSigner(), new GordianSeedTool(), new SpecterDIY());
|
||||
fileImporters = List.of(new Bip129(), new ColdcardMultisig(), new CoboVaultMultisig(), new Jade(), new KeystoneMultisig(), new PassportMultisig(), new SeedSigner(), new GordianSeedTool(), new SpecterDIY());
|
||||
}
|
||||
|
||||
for(KeystoreFileImport importer : fileImporters) {
|
||||
|
||||
@@ -128,7 +128,7 @@ public class Auth47 {
|
||||
}
|
||||
|
||||
Proxy proxy = AppServices.getProxy();
|
||||
if(proxy == null && callback.getHost().toLowerCase(Locale.ROOT).endsWith(TorService.TOR_ADDRESS_SUFFIX)) {
|
||||
if(proxy == null && callback.getHost().toLowerCase(Locale.ROOT).endsWith(Tor.TOR_ADDRESS_SUFFIX)) {
|
||||
throw new Auth47Exception("A Tor proxy must be configured to authenticate this resource.");
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.sparrowwallet.sparrow.net;
|
||||
|
||||
import com.sparrowwallet.sparrow.io.Server;
|
||||
|
||||
public enum BlockExplorer {
|
||||
MEMPOOL_SPACE("https://mempool.space"),
|
||||
BLOCKSTREAM_INFO("https://blockstream.info"),
|
||||
NONE("http://none");
|
||||
|
||||
private final Server server;
|
||||
|
||||
BlockExplorer(String url) {
|
||||
this.server = new Server(url);
|
||||
}
|
||||
|
||||
public Server getServer() {
|
||||
return server;
|
||||
}
|
||||
}
|
||||
@@ -146,6 +146,9 @@ public class Bwt {
|
||||
Config config = Config.get();
|
||||
if(config.getCoreServer() != null) {
|
||||
bwtConfig.bitcoindUrl = config.getCoreServer().getUrl();
|
||||
if(!config.getCoreServer().getHostAndPort().hasPort()) {
|
||||
bwtConfig.bitcoindUrl = config.getCoreServer().getUrl() + ":" + Network.get().getDefaultPort();
|
||||
}
|
||||
try {
|
||||
Protocol protocol = config.getCoreServer().getProtocol();
|
||||
HostAndPort hostAndPort = protocol.getServerHostAndPort(bwtConfig.bitcoindUrl);
|
||||
@@ -181,7 +184,7 @@ public class Bwt {
|
||||
|
||||
private HostAndPort getTorProxy() {
|
||||
return AppServices.isTorRunning() ?
|
||||
HostAndPort.fromParts("127.0.0.1", TorService.PROXY_PORT) :
|
||||
Tor.getDefault().getProxyHostAndPort() :
|
||||
(Config.get().getProxyServer() == null || Config.get().getProxyServer().isEmpty() || !Config.get().isUseProxy() ? null : HostAndPort.fromString(Config.get().getProxyServer().replace("localhost", "127.0.0.1")));
|
||||
}
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ public class LnurlAuth {
|
||||
}
|
||||
|
||||
Proxy proxy = AppServices.getProxy();
|
||||
if(proxy == null && callback.getHost().toLowerCase(Locale.ROOT).endsWith(TorService.TOR_ADDRESS_SUFFIX)) {
|
||||
if(proxy == null && callback.getHost().toLowerCase(Locale.ROOT).endsWith(Tor.TOR_ADDRESS_SUFFIX)) {
|
||||
throw new LnurlAuthException("A Tor proxy must be configured to authenticate this resource.");
|
||||
}
|
||||
|
||||
|
||||
@@ -129,7 +129,9 @@ public enum Protocol {
|
||||
public abstract CloseableTransport getTransport(HostAndPort server, File serverCert, HostAndPort proxy) throws IOException, CertificateException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException;
|
||||
|
||||
public HostAndPort getServerHostAndPort(String url) {
|
||||
return HostAndPort.fromString(url.substring(this.toUrlString().length()));
|
||||
String lessProtocol = url.substring(this.toUrlString().length());
|
||||
int pathStart = lessProtocol.indexOf('/');
|
||||
return HostAndPort.fromString(pathStart < 0 ? lessProtocol : lessProtocol.substring(0, pathStart));
|
||||
}
|
||||
|
||||
public String toUrlString() {
|
||||
@@ -149,7 +151,7 @@ public enum Protocol {
|
||||
}
|
||||
|
||||
public static boolean isOnionHost(String host) {
|
||||
return host != null && host.toLowerCase(Locale.ROOT).endsWith(TorService.TOR_ADDRESS_SUFFIX);
|
||||
return host != null && host.toLowerCase(Locale.ROOT).endsWith(Tor.TOR_ADDRESS_SUFFIX);
|
||||
}
|
||||
|
||||
public static boolean isOnionAddress(Server server) {
|
||||
|
||||
@@ -32,7 +32,7 @@ public class ProxyTcpOverTlsTransport extends TcpOverTlsTransport {
|
||||
protected void createSocket() throws IOException {
|
||||
InetSocketAddress proxyAddr = new InetSocketAddress(proxy.getHost(), proxy.getPortOrDefault(DEFAULT_PROXY_PORT));
|
||||
socket = new Socket(new Proxy(Proxy.Type.SOCKS, proxyAddr));
|
||||
socket.connect(new InetSocketAddress(server.getHost(), server.getPortOrDefault(Protocol.SSL.getDefaultPort())));
|
||||
socket.connect(new InetSocketAddress(server.getHost(), server.getPortOrDefault(getDefaultPort())));
|
||||
socket = sslSocketFactory.createSocket(socket, proxy.getHost(), proxy.getPortOrDefault(DEFAULT_PROXY_PORT), true);
|
||||
startHandshake((SSLSocket)socket);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ public enum PublicElectrumServer {
|
||||
LUKECHILDS_CO("bitcoin.lu.ke", "ssl://bitcoin.lu.ke:50002", Network.MAINNET),
|
||||
EMZY_DE("electrum.emzy.de", "ssl://electrum.emzy.de:50002", Network.MAINNET),
|
||||
BITAROO_NET("electrum.bitaroo.net", "ssl://electrum.bitaroo.net:50002", Network.MAINNET),
|
||||
DIYNODES_COM("electrum.diynodes.com", "ssl://electrum.diynodes.com:50022", Network.MAINNET),
|
||||
TESTNET_ARANGUREN_ORG("testnet.aranguren.org", "ssl://testnet.aranguren.org:51002", Network.TESTNET);
|
||||
|
||||
PublicElectrumServer(String name, String url, Network network) {
|
||||
|
||||
@@ -125,4 +125,9 @@ public class TcpOverTlsTransport extends TcpTransport {
|
||||
|
||||
return Storage.getCertificateFile(server.getHost()) == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getDefaultPort() {
|
||||
return Protocol.SSL.getDefaultPort();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -254,7 +254,11 @@ public class TcpTransport implements CloseableTransport, TimeoutCounter {
|
||||
|
||||
protected void createSocket() throws IOException {
|
||||
socket = socketFactory.createSocket();
|
||||
socket.connect(new InetSocketAddress(server.getHost(), server.getPortOrDefault(Protocol.TCP.getDefaultPort())));
|
||||
socket.connect(new InetSocketAddress(server.getHost(), server.getPortOrDefault(getDefaultPort())));
|
||||
}
|
||||
|
||||
protected int getDefaultPort() {
|
||||
return Protocol.TCP.getDefaultPort();
|
||||
}
|
||||
|
||||
public boolean isClosed() {
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
package com.sparrowwallet.sparrow.net;
|
||||
|
||||
import com.google.common.net.HostAndPort;
|
||||
import com.sparrowwallet.sparrow.EventManager;
|
||||
import com.sparrowwallet.sparrow.event.TorStatusEvent;
|
||||
import com.sparrowwallet.sparrow.io.Storage;
|
||||
import io.matthewnelson.kmp.tor.KmpTorLoaderJvm;
|
||||
import io.matthewnelson.kmp.tor.PlatformInstaller;
|
||||
import io.matthewnelson.kmp.tor.TorConfigProviderJvm;
|
||||
import io.matthewnelson.kmp.tor.binary.extract.TorBinaryResource;
|
||||
import io.matthewnelson.kmp.tor.common.address.Port;
|
||||
import io.matthewnelson.kmp.tor.common.address.ProxyAddress;
|
||||
import io.matthewnelson.kmp.tor.controller.common.config.TorConfig;
|
||||
import io.matthewnelson.kmp.tor.controller.common.file.Path;
|
||||
import io.matthewnelson.kmp.tor.ext.callback.manager.CallbackTorManager;
|
||||
import io.matthewnelson.kmp.tor.manager.TorManager;
|
||||
import io.matthewnelson.kmp.tor.manager.common.event.TorManagerEvent;
|
||||
import io.matthewnelson.kmp.tor.manager.util.PortUtil;
|
||||
import org.controlsfx.tools.Platform;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Proxy;
|
||||
import java.util.List;
|
||||
|
||||
public class Tor {
|
||||
private static final Logger log = LoggerFactory.getLogger(Tor.class);
|
||||
|
||||
public static final String TOR_DIR = "tor";
|
||||
public static final String TOR_ADDRESS_SUFFIX = ".onion";
|
||||
|
||||
private static Tor tor;
|
||||
|
||||
private final Path path = Path.invoke(Storage.getSparrowHome().getAbsolutePath()).builder().addSegment(TOR_DIR).build();
|
||||
private final CallbackTorManager instance;
|
||||
private ProxyAddress socksAddress;
|
||||
|
||||
public Tor() {
|
||||
Platform platform = Platform.getCurrent();
|
||||
String arch = System.getProperty("os.arch");
|
||||
PlatformInstaller installer;
|
||||
PlatformInstaller.InstallOption installOption = PlatformInstaller.InstallOption.CleanInstallIfMissing;
|
||||
|
||||
if(platform == Platform.OSX) {
|
||||
if(arch.equals("aarch64")) {
|
||||
installer = PlatformInstaller.macosArm64(installOption);
|
||||
} else {
|
||||
installer = PlatformInstaller.macosX64(installOption);
|
||||
}
|
||||
} else if(platform == Platform.WINDOWS) {
|
||||
installer = PlatformInstaller.mingwX64(installOption);
|
||||
} else if(platform == Platform.UNIX) {
|
||||
if(arch.equals("aarch64")) {
|
||||
TorBinaryResource linuxArm64 = TorBinaryResource.from(TorBinaryResource.OS.Linux, "arm64",
|
||||
"588496f3164d52b91f17e4db3372d8dfefa6366a8df265eebd4a28d4128992aa",
|
||||
List.of("libevent-2.1.so.7.gz", "libstdc++.so.6.gz", "libcrypto.so.1.1.gz", "tor.gz", "libssl.so.1.1.gz"));
|
||||
installer = PlatformInstaller.custom(installOption, linuxArm64);
|
||||
} else {
|
||||
installer = PlatformInstaller.linuxX64(installOption);
|
||||
}
|
||||
} else {
|
||||
throw new UnsupportedOperationException("Sparrow's bundled Tor is not supported on " + platform + " " + arch);
|
||||
}
|
||||
|
||||
TorConfigProviderJvm torConfigProviderJvm = new TorConfigProviderJvm() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Path getWorkDir() {
|
||||
return path.builder().addSegment("work").build();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Path getCacheDir() {
|
||||
return path.builder().addSegment("cache").build();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected TorConfig provide() {
|
||||
TorConfig.Builder builder = new TorConfig.Builder();
|
||||
|
||||
TorConfig.Setting.DormantCanceledByStartup dormantCanceledByStartup = new TorConfig.Setting.DormantCanceledByStartup();
|
||||
dormantCanceledByStartup.set(TorConfig.Option.AorTorF.getTrue());
|
||||
builder.put(dormantCanceledByStartup);
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
};
|
||||
|
||||
KmpTorLoaderJvm jvmLoader = new KmpTorLoaderJvm(installer, torConfigProviderJvm);
|
||||
TorManager torManager = TorManager.newInstance(jvmLoader);
|
||||
|
||||
torManager.debug(true);
|
||||
torManager.addListener(new TorManagerEvent.Listener() {
|
||||
@Override
|
||||
public void managerEventWarn(@NotNull String message) {
|
||||
log.warn(message);
|
||||
EventManager.get().post(new TorStatusEvent(message));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void managerEventInfo(@NotNull String message) {
|
||||
log.info(message);
|
||||
EventManager.get().post(new TorStatusEvent(message));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void managerEventDebug(@NotNull String message) {
|
||||
log.debug(message);
|
||||
EventManager.get().post(new TorStatusEvent(message));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void managerEventAddressInfo(@NotNull TorManagerEvent.AddressInfo info) {
|
||||
if(info.isNull) {
|
||||
socksAddress = null;
|
||||
} else {
|
||||
socksAddress = info.socksInfoToProxyAddress().iterator().next();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
this.instance = new CallbackTorManager(torManager, uncaughtException -> {
|
||||
log.error("Uncaught exception from CallbackTorManager", uncaughtException);
|
||||
});
|
||||
}
|
||||
|
||||
public static Tor getDefault() {
|
||||
return Tor.tor;
|
||||
}
|
||||
|
||||
public static void setDefault(Tor tor) {
|
||||
Tor.tor = tor;
|
||||
}
|
||||
|
||||
public CallbackTorManager getTorManager() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public Proxy getProxy() {
|
||||
if(socksAddress == null) {
|
||||
throw new IllegalStateException("Tor socks proxy is not yet instantiated");
|
||||
}
|
||||
|
||||
return new Proxy(Proxy.Type.SOCKS, new InetSocketAddress(socksAddress.address.getValue(), socksAddress.port.getValue()));
|
||||
}
|
||||
|
||||
public HostAndPort getProxyHostAndPort() {
|
||||
return HostAndPort.fromParts(socksAddress.address.getValue(), socksAddress.port.getValue());
|
||||
}
|
||||
|
||||
public static boolean isRunningExternally() {
|
||||
return !PortUtil.isTcpPortAvailable(Port.invoke(9050));
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package com.sparrowwallet.sparrow.net;
|
||||
|
||||
public class TorServerAlreadyBoundException extends TorServerException {
|
||||
public TorServerAlreadyBoundException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public TorServerAlreadyBoundException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,10 @@ public class TorServerException extends ServerException {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public TorServerException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public TorServerException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
@@ -1,86 +1,85 @@
|
||||
package com.sparrowwallet.sparrow.net;
|
||||
|
||||
import io.matthewnelson.kmp.tor.ext.callback.manager.CallbackTorManager;
|
||||
import io.matthewnelson.kmp.tor.manager.common.event.TorManagerEvent;
|
||||
import javafx.concurrent.ScheduledService;
|
||||
import javafx.concurrent.Task;
|
||||
import net.freehaven.tor.control.TorControlError;
|
||||
import org.berndpruenster.netlayer.tor.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.Socket;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.Condition;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
/**
|
||||
* Service to start internal Tor (including a Tor proxy running on localhost:9050)
|
||||
* Service to start internal Tor (including a Tor proxy running on localhost:9050, or another port if unavailable)
|
||||
*
|
||||
* This is a ScheduledService to take advantage of the retry on failure behaviour
|
||||
*/
|
||||
public class TorService extends ScheduledService<NativeTor> {
|
||||
public class TorService extends ScheduledService<Tor> {
|
||||
private static final Logger log = LoggerFactory.getLogger(TorService.class);
|
||||
|
||||
public static final int PROXY_PORT = 9050;
|
||||
public static final String TOR_DIR_PREFIX = "tor";
|
||||
public static final String TOR_ADDRESS_SUFFIX = ".onion";
|
||||
private final ReentrantLock startupLock = new ReentrantLock();
|
||||
private final Condition startupCondition = startupLock.newCondition();
|
||||
|
||||
@Override
|
||||
protected Task<NativeTor> createTask() {
|
||||
protected Task<Tor> createTask() {
|
||||
return new Task<>() {
|
||||
protected NativeTor call() throws IOException, TorServerException {
|
||||
if(Tor.getDefault() == null) {
|
||||
Path path = Files.createTempDirectory(TOR_DIR_PREFIX);
|
||||
File torInstallDir = path.toFile();
|
||||
torInstallDir.deleteOnExit();
|
||||
try {
|
||||
LinkedHashMap<String, String> torrcOptionsMap = new LinkedHashMap<>();
|
||||
torrcOptionsMap.put("SocksPort", Integer.toString(PROXY_PORT));
|
||||
torrcOptionsMap.put("HashedControlPassword", "16:D780432418F09B06609940000924317D3B9DF522A3191F8F4E597E9329");
|
||||
torrcOptionsMap.put("DisableNetwork", "0");
|
||||
Torrc override = new Torrc(torrcOptionsMap);
|
||||
private Exception startupException;
|
||||
|
||||
return new NativeTor(torInstallDir, Collections.emptyList(), override);
|
||||
} catch(TorCtlException e) {
|
||||
if(e.getCause() instanceof TorControlError) {
|
||||
if(e.getCause().getMessage().contains("Failed to bind")) {
|
||||
throw new TorServerAlreadyBoundException("Tor server already bound", e.getCause());
|
||||
@Override
|
||||
protected Tor call() throws Exception {
|
||||
Tor tor = Tor.getDefault();
|
||||
if(tor == null) {
|
||||
tor = new Tor();
|
||||
CallbackTorManager callbackTorManager = tor.getTorManager();
|
||||
callbackTorManager.addListener(new TorManagerEvent.Listener() {
|
||||
@Override
|
||||
public void managerEventAddressInfo(@NotNull TorManagerEvent.AddressInfo info) {
|
||||
if(!info.isNull) {
|
||||
try {
|
||||
startupLock.lock();
|
||||
startupCondition.signalAll();
|
||||
} finally {
|
||||
startupLock.unlock();
|
||||
}
|
||||
}
|
||||
log.error("Failed to start Tor", e);
|
||||
throw new TorServerException("Failed to start Tor", e.getCause());
|
||||
} else {
|
||||
log.error("Failed to start Tor", e);
|
||||
throw new TorServerException("Failed to start Tor", e);
|
||||
}
|
||||
});
|
||||
callbackTorManager.start(throwable -> {
|
||||
if(throwable instanceof Exception exception) {
|
||||
startupException = exception;
|
||||
} else {
|
||||
startupException = new Exception(throwable);
|
||||
}
|
||||
log.error("Error", throwable);
|
||||
try {
|
||||
startupLock.lock();
|
||||
startupCondition.signalAll();
|
||||
} finally {
|
||||
startupLock.unlock();
|
||||
}
|
||||
}, success -> {
|
||||
log.info("Tor daemon started successfully");
|
||||
});
|
||||
|
||||
try {
|
||||
startupLock.lock();
|
||||
if(!startupCondition.await(5, TimeUnit.MINUTES)) {
|
||||
throw new TorStartupException("Tor failed to start after 5 minutes, giving up");
|
||||
}
|
||||
|
||||
if(startupException != null) {
|
||||
throw startupException;
|
||||
}
|
||||
} finally {
|
||||
startupLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return tor;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static Socket getControlSocket() {
|
||||
Tor tor = Tor.getDefault();
|
||||
if(tor != null) {
|
||||
try {
|
||||
Class<?> torClass = Class.forName("org.berndpruenster.netlayer.tor.Tor");
|
||||
Field torControllerField = torClass.getDeclaredField("torController");
|
||||
torControllerField.setAccessible(true);
|
||||
TorController torController = (TorController)torControllerField.get(tor);
|
||||
|
||||
Class<?> torControllerClass = Class.forName("org.berndpruenster.netlayer.tor.TorController");
|
||||
Field socketField = torControllerClass.getDeclaredField("socket");
|
||||
socketField.setAccessible(true);
|
||||
return (Socket)socketField.get(torController);
|
||||
} catch(Exception e) {
|
||||
log.error("Error retrieving Tor control socket", e);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.sparrowwallet.sparrow.net;
|
||||
|
||||
public class TorStartupException extends TorServerException {
|
||||
public TorStartupException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public TorStartupException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public TorStartupException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
@@ -27,21 +27,15 @@ public class TorTcpOverTlsTransport extends TcpOverTlsTransport {
|
||||
|
||||
@Override
|
||||
protected void createSocket() throws IOException {
|
||||
TorTcpTransport torTcpTransport = new TorTcpTransport(server);
|
||||
TorTcpTransport torTcpTransport = new TorTcpTransport(server) {
|
||||
@Override
|
||||
protected int getDefaultPort() {
|
||||
return Protocol.SSL.getDefaultPort();
|
||||
}
|
||||
};
|
||||
torTcpTransport.createSocket();
|
||||
socket = torTcpTransport.socket;
|
||||
|
||||
try {
|
||||
Field socketField = socket.getClass().getDeclaredField("socket");
|
||||
socketField.setAccessible(true);
|
||||
Socket innerSocket = (Socket)socketField.get(socket);
|
||||
Field connectedField = innerSocket.getClass().getSuperclass().getDeclaredField("connected");
|
||||
connectedField.setAccessible(true);
|
||||
connectedField.set(innerSocket, true);
|
||||
} catch(Exception e) {
|
||||
log.error("Could not set socket connected status", e);
|
||||
}
|
||||
|
||||
socket = sslSocketFactory.createSocket(socket, server.getHost(), server.getPortOrDefault(Protocol.SSL.getDefaultPort()), true);
|
||||
startHandshake((SSLSocket)socket);
|
||||
}
|
||||
|
||||
@@ -2,14 +2,12 @@ package com.sparrowwallet.sparrow.net;
|
||||
|
||||
import com.google.common.net.HostAndPort;
|
||||
import com.sparrowwallet.sparrow.AppServices;
|
||||
import org.berndpruenster.netlayer.tor.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
|
||||
public class TorTcpTransport extends TcpTransport {
|
||||
public static final String TOR_DIR_PREFIX = "tor";
|
||||
|
||||
public TorTcpTransport(HostAndPort server) {
|
||||
super(server);
|
||||
}
|
||||
@@ -24,6 +22,7 @@ public class TorTcpTransport extends TcpTransport {
|
||||
throw new IllegalStateException("Can't create Tor socket, Tor is not running");
|
||||
}
|
||||
|
||||
socket = new TorSocket(server.getHost(), server.getPortOrDefault(Protocol.TCP.getDefaultPort()), "sparrow");
|
||||
socket = new Socket(Tor.getDefault().getProxy());
|
||||
socket.connect(new InetSocketAddress(server.getHost(), server.getPortOrDefault(getDefaultPort())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -444,7 +444,7 @@ public class BitcoindClient {
|
||||
|
||||
private String getTransaction(String txid) {
|
||||
try {
|
||||
return getBitcoindService().getTransaction(txid, false).get("hex").toString();
|
||||
return getBitcoindService().getTransaction(txid, true, false).get("hex").toString();
|
||||
} catch(JsonRpcException e) {
|
||||
return getBitcoindService().getRawTransaction(txid, false).toString();
|
||||
}
|
||||
@@ -539,7 +539,7 @@ public class BitcoindClient {
|
||||
try {
|
||||
if(syncing) {
|
||||
BlockchainInfo blockchainInfo = getBitcoindService().getBlockchainInfo();
|
||||
if(blockchainInfo.initialblockdownload()) {
|
||||
if(blockchainInfo.initialblockdownload() && !isEmptyBlockchain(blockchainInfo)) {
|
||||
int percent = blockchainInfo.getProgressPercent();
|
||||
Date tipDate = blockchainInfo.getTip();
|
||||
Platform.runLater(() -> EventManager.get().post(new CormorantSyncStatusEvent("Syncing" + (percent < 100 ? " (" + percent + "%)" : ""), percent, tipDate)));
|
||||
@@ -615,6 +615,10 @@ public class BitcoindClient {
|
||||
return scanningWallets;
|
||||
}
|
||||
|
||||
private boolean isEmptyBlockchain(BlockchainInfo blockchainInfo) {
|
||||
return blockchainInfo.blocks() == 0 && blockchainInfo.getProgressPercent() == 100;
|
||||
}
|
||||
|
||||
private record ScanDate(Date rescanSince, Integer range, boolean forceRescan) {
|
||||
public Object getTimestamp() {
|
||||
return rescanSince == null ? "now" : rescanSince.getTime() / 1000;
|
||||
|
||||
+4
-1
@@ -1,5 +1,7 @@
|
||||
package com.sparrowwallet.sparrow.net.cormorant.bitcoind;
|
||||
|
||||
import com.github.arteam.simplejsonrpc.client.JsonRpcParams;
|
||||
import com.github.arteam.simplejsonrpc.client.ParamsType;
|
||||
import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcMethod;
|
||||
import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcOptional;
|
||||
import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcParam;
|
||||
@@ -9,6 +11,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@JsonRpcService
|
||||
@JsonRpcParams(ParamsType.ARRAY)
|
||||
public interface BitcoindClientService {
|
||||
@JsonRpcMethod("uptime")
|
||||
long uptime();
|
||||
@@ -44,7 +47,7 @@ public interface BitcoindClientService {
|
||||
Object getRawTransaction(@JsonRpcParam("txid") String txid, @JsonRpcParam("verbose") boolean verbose);
|
||||
|
||||
@JsonRpcMethod("gettransaction")
|
||||
Map<String, Object> getTransaction(@JsonRpcParam("txid") String txid, @JsonRpcParam("verbose") boolean verbose);
|
||||
Map<String, Object> getTransaction(@JsonRpcParam("txid") String txid, @JsonRpcParam("include_watchonly") boolean includeWatchOnly, @JsonRpcParam("verbose") boolean verbose);
|
||||
|
||||
@JsonRpcMethod("getmempoolentry")
|
||||
MempoolEntry getMempoolEntry(@JsonRpcParam("txid") String txid);
|
||||
|
||||
+15
-7
@@ -4,6 +4,7 @@ import com.github.arteam.simplejsonrpc.client.Transport;
|
||||
import com.sparrowwallet.drongo.Network;
|
||||
import com.sparrowwallet.sparrow.AppServices;
|
||||
import com.sparrowwallet.sparrow.io.Server;
|
||||
import com.sparrowwallet.sparrow.net.Protocol;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -15,6 +16,7 @@ import java.net.Proxy;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.Base64;
|
||||
@@ -23,6 +25,7 @@ public class BitcoindTransport implements Transport {
|
||||
private static final Logger log = LoggerFactory.getLogger(BitcoindTransport.class);
|
||||
public static final String COOKIE_FILENAME = ".cookie";
|
||||
|
||||
private final Server bitcoindServer;
|
||||
private URL bitcoindUrl;
|
||||
private File cookieFile;
|
||||
private Long cookieFileTimestamp;
|
||||
@@ -39,8 +42,13 @@ public class BitcoindTransport implements Transport {
|
||||
}
|
||||
|
||||
private BitcoindTransport(Server bitcoindServer, String bitcoindWallet) {
|
||||
this.bitcoindServer = bitcoindServer;
|
||||
try {
|
||||
this.bitcoindUrl = new URL(bitcoindServer.getUrl() + "/wallet/" + bitcoindWallet);
|
||||
String serverUrl = bitcoindServer.getUrl();
|
||||
if(!bitcoindServer.getHostAndPort().hasPort()) {
|
||||
serverUrl += ":" + Network.get().getDefaultPort();
|
||||
}
|
||||
this.bitcoindUrl = new URL(serverUrl + "/wallet/" + bitcoindWallet);
|
||||
} catch(MalformedURLException e) {
|
||||
log.error("Malformed Bitcoin Core RPC URL", e);
|
||||
}
|
||||
@@ -49,7 +57,7 @@ public class BitcoindTransport implements Transport {
|
||||
@Override
|
||||
public String pass(String request) throws IOException {
|
||||
Proxy proxy = AppServices.getProxy();
|
||||
HttpURLConnection connection = proxy == null ? (HttpURLConnection)bitcoindUrl.openConnection() : (HttpURLConnection)bitcoindUrl.openConnection(proxy);
|
||||
HttpURLConnection connection = proxy != null && Protocol.isOnionAddress(bitcoindServer) ? (HttpURLConnection)bitcoindUrl.openConnection(proxy) : (HttpURLConnection)bitcoindUrl.openConnection();
|
||||
|
||||
if(connection instanceof HttpsURLConnection httpsURLConnection) {
|
||||
SSLSocketFactory sslSocketFactory = getTrustAllSocketFactory();
|
||||
@@ -68,7 +76,7 @@ public class BitcoindTransport implements Transport {
|
||||
|
||||
connection.setDoOutput(true);
|
||||
|
||||
log.trace("> " + request);
|
||||
log.debug("> " + request);
|
||||
|
||||
try(OutputStream os = connection.getOutputStream()) {
|
||||
byte[] jsonBytes = request.getBytes(StandardCharsets.UTF_8);
|
||||
@@ -94,7 +102,7 @@ public class BitcoindTransport implements Transport {
|
||||
}
|
||||
|
||||
String response = res.toString();
|
||||
log.trace("< " + response);
|
||||
log.debug("< " + response);
|
||||
|
||||
return response;
|
||||
}
|
||||
@@ -120,11 +128,11 @@ public class BitcoindTransport implements Transport {
|
||||
}
|
||||
|
||||
private static File getCookieDir(File bitcoindDir) {
|
||||
if(Network.get() == Network.TESTNET && !bitcoindDir.getName().contains("testnet")) {
|
||||
if(Network.get() == Network.TESTNET && Files.exists(Path.of(bitcoindDir.getAbsolutePath(), "testnet3", COOKIE_FILENAME))) {
|
||||
return new File(bitcoindDir, "testnet3");
|
||||
} else if(Network.get() == Network.REGTEST && !bitcoindDir.getName().contains("regtest")) {
|
||||
} else if(Network.get() == Network.REGTEST && Files.exists(Path.of(bitcoindDir.getAbsolutePath(), "regtest", COOKIE_FILENAME))) {
|
||||
return new File(bitcoindDir, "regtest");
|
||||
} else if(Network.get() == Network.SIGNET && !bitcoindDir.getName().contains("signet")) {
|
||||
} else if(Network.get() == Network.SIGNET && Files.exists(Path.of(bitcoindDir.getAbsolutePath(), "signet", COOKIE_FILENAME))) {
|
||||
return new File(bitcoindDir, "signet");
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ public record VerboseBlockHeader(String hash, int confirmations, int height, int
|
||||
String bits, double difficulty, String chainwork, int nTx, String previousblockhash) {
|
||||
public ElectrumBlockHeader getBlockHeader() {
|
||||
BigInteger nBits = new BigInteger(bits, 16);
|
||||
BlockHeader blockHeader = new BlockHeader(version, Sha256Hash.wrap(previousblockhash), Sha256Hash.wrap(merkleroot), null, time, nBits.longValue(), nonce);
|
||||
BlockHeader blockHeader = new BlockHeader(version, previousblockhash == null ? Sha256Hash.ZERO_HASH : Sha256Hash.wrap(previousblockhash), Sha256Hash.wrap(merkleroot), null, time, nBits.longValue(), nonce);
|
||||
return new ElectrumBlockHeader(height, Utils.bytesToHex(blockHeader.bitcoinSerialize()));
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -150,7 +150,7 @@ public class ElectrumServerService {
|
||||
return bitcoindClient.getBitcoindService().getRawTransaction(tx_hash, true);
|
||||
} catch(JsonRpcException e) {
|
||||
try {
|
||||
Map<String, Object> txInfo = bitcoindClient.getBitcoindService().getTransaction(tx_hash, true);
|
||||
Map<String, Object> txInfo = bitcoindClient.getBitcoindService().getTransaction(tx_hash, true, true);
|
||||
Object decoded = txInfo.get("decoded");
|
||||
if(decoded instanceof Map<?, ?>) {
|
||||
Map<String, Object> decodedMap = (Map<String, Object>)decoded;
|
||||
@@ -172,7 +172,7 @@ public class ElectrumServerService {
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
return bitcoindClient.getBitcoindService().getTransaction(tx_hash, false).get("hex");
|
||||
return bitcoindClient.getBitcoindService().getTransaction(tx_hash, true, false).get("hex");
|
||||
} catch(JsonRpcException e) {
|
||||
try {
|
||||
return bitcoindClient.getBitcoindService().getRawTransaction(tx_hash, false);
|
||||
|
||||
@@ -66,7 +66,7 @@ public class Payjoin {
|
||||
try {
|
||||
String base64Psbt = psbt.getPublicCopy().toBase64String();
|
||||
|
||||
String appendQuery = "v=1";
|
||||
String appendQuery = "v=1&minfeerate=" + AppServices.getMinimumRelayFeeRate();
|
||||
int changeOutputIndex = getChangeOutputIndex();
|
||||
long maxAdditionalFeeContribution = 0;
|
||||
if(changeOutputIndex > -1) {
|
||||
|
||||
@@ -441,6 +441,7 @@ public class PayNymController {
|
||||
if(!storage.isPersisted(addedWallet)) {
|
||||
try {
|
||||
storage.saveWallet(addedWallet);
|
||||
EventManager.get().post(new NewChildWalletSavedEvent(storage, masterWallet, addedWallet));
|
||||
} catch(Exception e) {
|
||||
log.error("Error saving wallet", e);
|
||||
AppServices.showErrorDialog("Error saving wallet " + addedWallet.getName(), e.getMessage());
|
||||
|
||||
@@ -33,7 +33,7 @@ public class PayNymService {
|
||||
private final JavaHttpClientService httpClientService;
|
||||
|
||||
public PayNymService(HostAndPort torProxy) {
|
||||
this.httpClientService = new JavaHttpClientService(torProxy);
|
||||
this.httpClientService = new JavaHttpClientService(torProxy, 120000);
|
||||
}
|
||||
|
||||
public Observable<Map<String, Object>> createPayNym(Wallet wallet) {
|
||||
|
||||
+88
-14
@@ -1,32 +1,44 @@
|
||||
package com.sparrowwallet.sparrow.preferences;
|
||||
|
||||
import com.sparrowwallet.drongo.BitcoinUnit;
|
||||
import com.sparrowwallet.drongo.wallet.Wallet;
|
||||
import com.sparrowwallet.sparrow.AppServices;
|
||||
import com.sparrowwallet.sparrow.EventManager;
|
||||
import com.sparrowwallet.sparrow.control.TextfieldDialog;
|
||||
import com.sparrowwallet.sparrow.control.UnlabeledToggleSwitch;
|
||||
import com.sparrowwallet.sparrow.event.*;
|
||||
import com.sparrowwallet.sparrow.io.Config;
|
||||
import com.sparrowwallet.sparrow.io.Server;
|
||||
import com.sparrowwallet.sparrow.net.BlockExplorer;
|
||||
import com.sparrowwallet.sparrow.net.ExchangeSource;
|
||||
import com.sparrowwallet.sparrow.net.FeeRatesSource;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.ComboBox;
|
||||
import javafx.util.StringConverter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Currency;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class GeneralPreferencesController extends PreferencesDetailController {
|
||||
private static final Logger log = LoggerFactory.getLogger(GeneralPreferencesController.class);
|
||||
|
||||
@FXML
|
||||
private ComboBox<BitcoinUnit> bitcoinUnit;
|
||||
private static final Server CUSTOM_BLOCK_EXPLORER = new Server("http://custom.block.explorer");
|
||||
|
||||
@FXML
|
||||
private ComboBox<FeeRatesSource> feeRatesSource;
|
||||
|
||||
@FXML
|
||||
private ComboBox<Server> blockExplorers;
|
||||
|
||||
@FXML
|
||||
private ComboBox<Currency> fiatCurrency;
|
||||
|
||||
@@ -63,17 +75,6 @@ public class GeneralPreferencesController extends PreferencesDetailController {
|
||||
|
||||
@Override
|
||||
public void initializeView(Config config) {
|
||||
if(config.getBitcoinUnit() != null) {
|
||||
bitcoinUnit.setValue(config.getBitcoinUnit());
|
||||
} else {
|
||||
bitcoinUnit.setValue(BitcoinUnit.AUTO);
|
||||
}
|
||||
|
||||
bitcoinUnit.valueProperty().addListener((observable, oldValue, newValue) -> {
|
||||
config.setBitcoinUnit(newValue);
|
||||
EventManager.get().post(new BitcoinUnitChangedEvent(newValue));
|
||||
});
|
||||
|
||||
if(config.getFeeRatesSource() != null) {
|
||||
feeRatesSource.setValue(config.getFeeRatesSource());
|
||||
} else {
|
||||
@@ -86,6 +87,62 @@ public class GeneralPreferencesController extends PreferencesDetailController {
|
||||
EventManager.get().post(new FeeRatesSourceChangedEvent(newValue));
|
||||
});
|
||||
|
||||
blockExplorers.setItems(getBlockExplorerList());
|
||||
blockExplorers.setConverter(new StringConverter<>() {
|
||||
@Override
|
||||
public String toString(Server server) {
|
||||
if(server == null || server == BlockExplorer.NONE.getServer()) {
|
||||
return "None";
|
||||
}
|
||||
|
||||
if(server == CUSTOM_BLOCK_EXPLORER) {
|
||||
return "Custom...";
|
||||
}
|
||||
|
||||
return server.getHost();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Server fromString(String string) {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
blockExplorers.valueProperty().addListener((observable, oldValue, newValue) -> {
|
||||
if(newValue != null) {
|
||||
if(newValue == CUSTOM_BLOCK_EXPLORER) {
|
||||
TextfieldDialog textfieldDialog = new TextfieldDialog();
|
||||
textfieldDialog.setTitle("Enter Block Explorer URL");
|
||||
textfieldDialog.setHeaderText("Enter the URL of the block explorer.\n\nIf present, the characters {0} will be replaced with the txid.\nFor example, https://localhost or https://localhost/tx/{0}\n");
|
||||
textfieldDialog.getEditor().setPromptText("https://localhost");
|
||||
Optional<String> optUrl = textfieldDialog.showAndWait();
|
||||
if(optUrl.isPresent() && !optUrl.get().isEmpty()) {
|
||||
try {
|
||||
Server server = getBlockExplorer(optUrl.get());
|
||||
config.setBlockExplorer(server);
|
||||
Platform.runLater(() -> {
|
||||
blockExplorers.getSelectionModel().select(-1);
|
||||
blockExplorers.setItems(getBlockExplorerList());
|
||||
blockExplorers.setValue(Config.get().getBlockExplorer());
|
||||
});
|
||||
} catch(Exception e) {
|
||||
AppServices.showErrorDialog("Invalid URL", "The URL " + optUrl.get() + " is not valid.");
|
||||
blockExplorers.setValue(oldValue);
|
||||
}
|
||||
} else {
|
||||
blockExplorers.setValue(oldValue);
|
||||
}
|
||||
} else {
|
||||
Config.get().setBlockExplorer(newValue);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if(config.getBlockExplorer() != null) {
|
||||
blockExplorers.setValue(config.getBlockExplorer());
|
||||
} else {
|
||||
blockExplorers.getSelectionModel().select(0);
|
||||
}
|
||||
|
||||
if(config.getExchangeSource() != null) {
|
||||
exchangeSource.setValue(config.getExchangeSource());
|
||||
} else {
|
||||
@@ -134,6 +191,23 @@ public class GeneralPreferencesController extends PreferencesDetailController {
|
||||
});
|
||||
}
|
||||
|
||||
private static Server getBlockExplorer(String serverUrl) {
|
||||
String url = serverUrl.trim();
|
||||
if(url.endsWith("/")) {
|
||||
url = url.substring(0, url.length() - 1);
|
||||
}
|
||||
return new Server(url);
|
||||
}
|
||||
|
||||
private ObservableList<Server> getBlockExplorerList() {
|
||||
List<Server> servers = Arrays.stream(BlockExplorer.values()).map(BlockExplorer::getServer).collect(Collectors.toList());
|
||||
if(Config.get().getBlockExplorer() != null && !servers.contains(Config.get().getBlockExplorer())) {
|
||||
servers.add(Config.get().getBlockExplorer());
|
||||
}
|
||||
servers.add(CUSTOM_BLOCK_EXPLORER);
|
||||
return FXCollections.observableList(servers);
|
||||
}
|
||||
|
||||
private void updateCurrencies(ExchangeSource exchangeSource) {
|
||||
ExchangeSource.CurrenciesService currenciesService = new ExchangeSource.CurrenciesService(exchangeSource);
|
||||
currenciesService.setOnSucceeded(event -> {
|
||||
|
||||
+9
-18
@@ -28,8 +28,6 @@ import javafx.stage.DirectoryChooser;
|
||||
import javafx.stage.FileChooser;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.util.Duration;
|
||||
import javafx.util.StringConverter;
|
||||
import org.berndpruenster.netlayer.tor.Tor;
|
||||
import org.controlsfx.control.SegmentedButton;
|
||||
import org.controlsfx.glyphfont.Glyph;
|
||||
import org.controlsfx.validation.ValidationResult;
|
||||
@@ -243,6 +241,7 @@ public class ServerPreferencesController extends PreferencesDetailController {
|
||||
proxyHost.textProperty().addListener(getProxyListener(config));
|
||||
proxyPort.textProperty().addListener(getProxyListener(config));
|
||||
|
||||
corePort.setPromptText("e.g. " + Network.get().getDefaultPort());
|
||||
coreDataDirField.managedProperty().bind(coreDataDirField.visibleProperty());
|
||||
coreUserPassField.managedProperty().bind(coreUserPassField.visibleProperty());
|
||||
coreUserPassField.visibleProperty().bind(coreDataDirField.visibleProperty().not());
|
||||
@@ -493,20 +492,6 @@ public class ServerPreferencesController extends PreferencesDetailController {
|
||||
torService.cancel();
|
||||
testResults.appendText("\nTor failed to start");
|
||||
showConnectionFailure(workerStateEvent.getSource().getException());
|
||||
|
||||
Throwable exception = workerStateEvent.getSource().getException();
|
||||
if(Config.get().getServerType() == ServerType.ELECTRUM_SERVER &&
|
||||
exception instanceof TorServerAlreadyBoundException &&
|
||||
useProxyOriginal == null && !useProxy.isSelected() &&
|
||||
(proxyHost.getText().isEmpty() || proxyHost.getText().equals("localhost") || proxyHost.getText().equals("127.0.0.1")) &&
|
||||
(proxyPort.getText().isEmpty() || proxyPort.getText().equals("9050"))) {
|
||||
useProxy.setSelected(true);
|
||||
proxyHost.setText("localhost");
|
||||
proxyPort.setText("9050");
|
||||
useProxyOriginal = false;
|
||||
testResults.appendText("\n\nAssuming Tor proxy is running on port 9050 and trying again...");
|
||||
startElectrumConnection();
|
||||
}
|
||||
});
|
||||
|
||||
torService.start();
|
||||
@@ -657,8 +642,6 @@ public class ServerPreferencesController extends PreferencesDetailController {
|
||||
reason = tlsServerException.getMessage() + "\n\n" + reason;
|
||||
} else if(exception instanceof ProxyServerException) {
|
||||
reason += ". Check if the proxy server is running.";
|
||||
} else if(exception instanceof TorServerAlreadyBoundException) {
|
||||
reason += "\nIs a Tor proxy already running on port " + TorService.PROXY_PORT + "?";
|
||||
} else if(reason != null && (reason.contains("Check if Bitcoin Core is running") || reason.contains("Could not connect to Bitcoin Core RPC"))) {
|
||||
reason += "\n\nSee https://sparrowwallet.com/docs/connect-node.html";
|
||||
} else if(reason != null && (reason.startsWith("Cannot connect to hidden service"))) {
|
||||
@@ -734,6 +717,10 @@ public class ServerPreferencesController extends PreferencesDetailController {
|
||||
private ChangeListener<String> getBitcoinCoreListener(Config config) {
|
||||
return (observable, oldValue, newValue) -> {
|
||||
Server existingServer = config.getRecentCoreServers().stream().filter(server -> coreHost.getText().equals(server.getAlias())).findFirst().orElse(null);
|
||||
if(existingServer != null && !existingServer.portEquals(corePort.getText())) {
|
||||
coreHost.setText(existingServer.getHost());
|
||||
existingServer = null;
|
||||
}
|
||||
coreHost.setLeft(existingServer == null ? null : getGlyph(FontAwesome5.Glyph.TAG, null));
|
||||
setCoreServerInConfig(config);
|
||||
};
|
||||
@@ -769,6 +756,10 @@ public class ServerPreferencesController extends PreferencesDetailController {
|
||||
private ChangeListener<String> getElectrumServerListener(Config config) {
|
||||
return (observable, oldValue, newValue) -> {
|
||||
Server existingServer = config.getRecentElectrumServers().stream().filter(server -> electrumHost.getText().equals(server.getAlias())).findFirst().orElse(null);
|
||||
if(existingServer != null && !existingServer.portEquals(electrumPort.getText())) {
|
||||
electrumHost.setText(existingServer.getHost());
|
||||
existingServer = null;
|
||||
}
|
||||
electrumHost.setLeft(existingServer == null ? null : getGlyph(FontAwesome5.Glyph.TAG, null));
|
||||
setElectrumServerInConfig(config);
|
||||
};
|
||||
|
||||
@@ -8,13 +8,9 @@ import com.samourai.wallet.cahoots.Cahoots;
|
||||
import com.samourai.wallet.cahoots.CahootsType;
|
||||
import com.sparrowwallet.drongo.protocol.Transaction;
|
||||
import com.sparrowwallet.drongo.psbt.PSBTParseException;
|
||||
import com.sparrowwallet.drongo.wallet.BlockTransactionHashIndex;
|
||||
import com.sparrowwallet.drongo.wallet.Status;
|
||||
import com.sparrowwallet.drongo.wallet.Wallet;
|
||||
import com.sparrowwallet.drongo.wallet.WalletNode;
|
||||
import com.sparrowwallet.drongo.wallet.*;
|
||||
import com.sparrowwallet.sparrow.AppServices;
|
||||
import com.sparrowwallet.sparrow.control.*;
|
||||
import com.sparrowwallet.sparrow.io.Config;
|
||||
import com.sparrowwallet.sparrow.paynym.PayNymDialog;
|
||||
import com.sparrowwallet.sparrow.paynym.PayNymService;
|
||||
import io.reactivex.rxjavafx.schedulers.JavaFxScheduler;
|
||||
|
||||
@@ -59,7 +59,7 @@ public class Soroban {
|
||||
ScriptType scriptType = wallet.getScriptType();
|
||||
int purpose = scriptType.getDefaultDerivation().get(0).num();
|
||||
List<String> words = keystore.getSeed().getMnemonicCode();
|
||||
String passphrase = keystore.getSeed().getPassphrase().asString();
|
||||
String passphrase = keystore.getSeed().getPassphrase() == null ? "" : keystore.getSeed().getPassphrase().asString();
|
||||
byte[] seed = hdWalletFactory.computeSeedFromWords(words);
|
||||
hdWallet = new HD_Wallet(purpose, new ArrayList<>(words), sorobanServer.getParams(), seed, passphrase);
|
||||
bip47Account = wallet.isMasterWallet() ? wallet.getAccountIndex() : wallet.getMasterWallet().getAccountIndex();
|
||||
|
||||
@@ -34,6 +34,12 @@ public class SparrowCahootsWallet extends SimpleCahootsWallet {
|
||||
this.bip47Account = bip47Account;
|
||||
bip84w.getAccount(account).getReceive().setAddrIdx(wallet.getFreshNode(KeyPurpose.RECEIVE).getIndex());
|
||||
bip84w.getAccount(account).getChange().setAddrIdx(wallet.getFreshNode(KeyPurpose.CHANGE).getIndex());
|
||||
|
||||
if(!wallet.isMasterWallet() && account != 0) {
|
||||
Wallet masterWallet = wallet.getMasterWallet();
|
||||
bip84w.getAccount(0).getReceive().setAddrIdx(masterWallet.getFreshNode(KeyPurpose.RECEIVE).getIndex());
|
||||
bip84w.getAccount(0).getChange().setAddrIdx(masterWallet.getFreshNode(KeyPurpose.CHANGE).getIndex());
|
||||
}
|
||||
}
|
||||
|
||||
public void addUtxo(WalletNode node, BlockTransaction blockTransaction, int index) {
|
||||
@@ -62,6 +68,10 @@ public class SparrowCahootsWallet extends SimpleCahootsWallet {
|
||||
addUtxo(account, cahootsUtxo);
|
||||
}
|
||||
|
||||
public Wallet getWallet() {
|
||||
return wallet;
|
||||
}
|
||||
|
||||
public int getAccount() {
|
||||
return account;
|
||||
}
|
||||
@@ -80,15 +90,23 @@ public class SparrowCahootsWallet extends SimpleCahootsWallet {
|
||||
public Pair<Integer, Integer> fetchReceiveIndex(int account) throws Exception {
|
||||
if(account == StandardAccount.WHIRLPOOL_POSTMIX.getAccountNumber()) {
|
||||
// force change chain
|
||||
return Pair.of(wallet.getFreshNode(KeyPurpose.CHANGE).getIndex(), 1);
|
||||
return Pair.of(getWallet(account).getFreshNode(KeyPurpose.CHANGE).getIndex(), 1);
|
||||
}
|
||||
|
||||
return Pair.of(wallet.getFreshNode(KeyPurpose.RECEIVE).getIndex(), 0);
|
||||
return Pair.of(getWallet(account).getFreshNode(KeyPurpose.RECEIVE).getIndex(), 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pair<Integer, Integer> fetchChangeIndex(int account) throws Exception {
|
||||
return Pair.of(wallet.getFreshNode(KeyPurpose.CHANGE).getIndex(), 1);
|
||||
return Pair.of(getWallet(account).getFreshNode(KeyPurpose.CHANGE).getIndex(), 1);
|
||||
}
|
||||
|
||||
private Wallet getWallet(int account) {
|
||||
if(account != this.account && account == 0 && !wallet.isMasterWallet()) {
|
||||
return wallet.getMasterWallet();
|
||||
}
|
||||
|
||||
return wallet;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -15,7 +15,6 @@ import com.sparrowwallet.sparrow.terminal.SparrowTerminal;
|
||||
import javafx.application.Platform;
|
||||
import javafx.scene.control.ButtonType;
|
||||
import javafx.util.Duration;
|
||||
import org.berndpruenster.netlayer.tor.Tor;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.DateFormat;
|
||||
@@ -203,8 +202,6 @@ public class ServerTestDialog extends DialogWindow {
|
||||
reason = tlsServerException.getMessage() + "\n\n" + reason;
|
||||
} else if(exception instanceof ProxyServerException) {
|
||||
reason += ". Check if the proxy server is running.";
|
||||
} else if(exception instanceof TorServerAlreadyBoundException) {
|
||||
reason += "\nIs a Tor proxy already running on port " + TorService.PROXY_PORT + "?";
|
||||
} else if(reason != null && reason.contains("Check if Bitcoin Core is running")) {
|
||||
reason += "\n\nSee https://sparrowwallet.com/docs/connect-node.html";
|
||||
}
|
||||
|
||||
@@ -197,6 +197,7 @@ public class MixPoolDialog extends WalletDialog {
|
||||
tx0Previews = null;
|
||||
whirlpool.setScode(mixConfig.getScode());
|
||||
whirlpool.setTx0FeeTarget(tx0FeeTarget);
|
||||
whirlpool.setMixFeeTarget(tx0FeeTarget);
|
||||
|
||||
Whirlpool.Tx0PreviewsService tx0PreviewsService = new Whirlpool.Tx0PreviewsService(whirlpool, utxoEntries);
|
||||
tx0PreviewsService.setOnRunning(workerStateEvent -> {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.sparrowwallet.sparrow.terminal.wallet;
|
||||
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import com.googlecode.lanterna.TerminalSize;
|
||||
import com.googlecode.lanterna.gui2.*;
|
||||
import com.googlecode.lanterna.gui2.dialogs.TextInputDialogBuilder;
|
||||
@@ -21,8 +22,8 @@ import com.sparrowwallet.sparrow.io.Storage;
|
||||
import com.sparrowwallet.sparrow.io.StorageException;
|
||||
import com.sparrowwallet.sparrow.terminal.SparrowTerminal;
|
||||
import com.sparrowwallet.sparrow.wallet.Function;
|
||||
import com.sparrowwallet.sparrow.wallet.SettingsWalletForm;
|
||||
import com.sparrowwallet.sparrow.wallet.WalletForm;
|
||||
import com.sparrowwallet.sparrow.whirlpool.WhirlpoolServices;
|
||||
import javafx.application.Platform;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -276,6 +277,13 @@ public class SettingsDialog extends WalletDialog {
|
||||
return lines;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void newChildWalletSaved(NewChildWalletSavedEvent event) {
|
||||
if(event.getMasterWalletId().equals(getWalletForm().getMasterWalletId())) {
|
||||
((SettingsWalletForm)getWalletForm()).childWalletSaved(event.getChildWallet());
|
||||
}
|
||||
}
|
||||
|
||||
public enum PasswordRequirement {
|
||||
UPDATE_NEW("Add a password to the wallet?\nLeave empty for no password:", "No Password"),
|
||||
UPDATE_EMPTY("This wallet has no password.\nAdd a password to the wallet?\nLeave empty for no password:", "No Password"),
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.googlecode.lanterna.TerminalSize;
|
||||
import com.googlecode.lanterna.gui2.*;
|
||||
import com.googlecode.lanterna.gui2.dialogs.DialogWindow;
|
||||
import com.sparrowwallet.drongo.wallet.Wallet;
|
||||
import com.sparrowwallet.sparrow.io.Storage;
|
||||
import com.sparrowwallet.sparrow.terminal.SparrowTerminal;
|
||||
import com.sparrowwallet.sparrow.wallet.Function;
|
||||
|
||||
@@ -48,7 +49,7 @@ public class WalletActionsDialog extends DialogWindow {
|
||||
SettingsDialog settingsDialog = getWalletData().getSettingsDialog();
|
||||
settingsDialog.showDialog(SparrowTerminal.get().getGui());
|
||||
});
|
||||
if(getWalletData().getWalletForm().getWallet().isEncrypted()) {
|
||||
if(!Storage.NO_PASSWORD_KEY.equals(getWalletData().getWalletForm().getStorage().getEncryptionPubKey())) {
|
||||
actions.addItem("Lock", () -> {
|
||||
close();
|
||||
SparrowTerminal.get().lockWallet(getWalletData().getWalletForm().getStorage());
|
||||
|
||||
@@ -16,10 +16,7 @@ import com.sparrowwallet.sparrow.AppServices;
|
||||
import com.sparrowwallet.sparrow.CurrencyRate;
|
||||
import com.sparrowwallet.sparrow.EventManager;
|
||||
import com.sparrowwallet.sparrow.UnitFormat;
|
||||
import com.sparrowwallet.sparrow.event.ChildWalletsAddedEvent;
|
||||
import com.sparrowwallet.sparrow.event.StorageEvent;
|
||||
import com.sparrowwallet.sparrow.event.TimedEvent;
|
||||
import com.sparrowwallet.sparrow.event.WalletHistoryClearedEvent;
|
||||
import com.sparrowwallet.sparrow.event.*;
|
||||
import com.sparrowwallet.sparrow.io.Config;
|
||||
import com.sparrowwallet.sparrow.io.Storage;
|
||||
import com.sparrowwallet.sparrow.terminal.SparrowTerminal;
|
||||
@@ -151,6 +148,7 @@ public class WalletDialog extends DialogWindow {
|
||||
if(!storage.isPersisted(childWallet)) {
|
||||
try {
|
||||
storage.saveWallet(childWallet);
|
||||
EventManager.get().post(new NewChildWalletSavedEvent(storage, masterWallet, childWallet));
|
||||
} catch(Exception e) {
|
||||
log.error("Error saving wallet", e);
|
||||
showErrorDialog("Error saving wallet " + childWallet.getName(), e.getMessage());
|
||||
|
||||
@@ -16,6 +16,7 @@ import com.sparrowwallet.sparrow.control.*;
|
||||
import com.sparrowwallet.sparrow.event.*;
|
||||
import com.sparrowwallet.sparrow.glyphfont.FontAwesome5;
|
||||
import com.sparrowwallet.sparrow.glyphfont.FontAwesome5Brands;
|
||||
import com.sparrowwallet.sparrow.io.Config;
|
||||
import com.sparrowwallet.sparrow.io.Device;
|
||||
import com.sparrowwallet.sparrow.net.ElectrumServer;
|
||||
import com.sparrowwallet.sparrow.io.Storage;
|
||||
@@ -78,6 +79,12 @@ public class HeadersController extends TransactionFormController implements Init
|
||||
@FXML
|
||||
private IdLabel id;
|
||||
|
||||
@FXML
|
||||
private ToggleButton copyTxid;
|
||||
|
||||
@FXML
|
||||
private ToggleButton openBlockExplorer;
|
||||
|
||||
@FXML
|
||||
private TransactionDiagram transactionDiagram;
|
||||
|
||||
@@ -806,11 +813,13 @@ public class HeadersController extends TransactionFormController implements Init
|
||||
addStyleClass(size, UNFINALIZED_TXID_CLASS);
|
||||
addStyleClass(virtualSize, UNFINALIZED_TXID_CLASS);
|
||||
addStyleClass(feeRate, UNFINALIZED_TXID_CLASS);
|
||||
openBlockExplorer.setDisable(true);
|
||||
} else {
|
||||
id.getStyleClass().remove(UNFINALIZED_TXID_CLASS);
|
||||
size.getStyleClass().remove(UNFINALIZED_TXID_CLASS);
|
||||
virtualSize.getStyleClass().remove(UNFINALIZED_TXID_CLASS);
|
||||
feeRate.getStyleClass().remove(UNFINALIZED_TXID_CLASS);
|
||||
openBlockExplorer.setDisable(Config.get().isBlockExplorerDisabled());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -821,11 +830,18 @@ public class HeadersController extends TransactionFormController implements Init
|
||||
}
|
||||
|
||||
public void copyId(ActionEvent event) {
|
||||
copyTxid.setSelected(false);
|
||||
ClipboardContent content = new ClipboardContent();
|
||||
content.putString(headersForm.getTransaction().calculateTxId(false).toString());
|
||||
Clipboard.getSystemClipboard().setContent(content);
|
||||
}
|
||||
|
||||
public void openInBlockExplorer(ActionEvent event) {
|
||||
openBlockExplorer.setSelected(false);
|
||||
String txid = headersForm.getTransaction().calculateTxId(false).toString();
|
||||
AppServices.openBlockExplorer(txid);
|
||||
}
|
||||
|
||||
public void setLocktimeToCurrentHeight(ActionEvent event) {
|
||||
if(AppServices.getCurrentBlockHeight() != null && locktimeBlock.isEditable()) {
|
||||
locktimeBlock.getValueFactory().setValue(AppServices.getCurrentBlockHeight());
|
||||
@@ -848,7 +864,9 @@ public class HeadersController extends TransactionFormController implements Init
|
||||
//TODO: Remove once Cobo Vault has upgraded to UR2.0
|
||||
boolean addLegacyEncodingOption = headersForm.getSigningWallet().getKeystores().stream().anyMatch(keystore -> keystore.getWalletModel().equals(WalletModel.COBO_VAULT));
|
||||
|
||||
CryptoPSBT cryptoPSBT = new CryptoPSBT(headersForm.getPsbt().serialize());
|
||||
//Don't include non witness utxo fields for segwit wallets when displaying the PSBT as a QR - it can add greatly to the time required for scanning
|
||||
boolean includeNonWitnessUtxos = !Arrays.asList(ScriptType.WITNESS_TYPES).contains(headersForm.getSigningWallet().getScriptType());
|
||||
CryptoPSBT cryptoPSBT = new CryptoPSBT(headersForm.getPsbt().serialize(true, includeNonWitnessUtxos));
|
||||
QRDisplayDialog qrDisplayDialog = new QRDisplayDialog(cryptoPSBT.toUR(), addLegacyEncodingOption);
|
||||
qrDisplayDialog.show();
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.sparrowwallet.sparrow.wallet;
|
||||
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import com.sparrowwallet.drongo.*;
|
||||
import com.sparrowwallet.drongo.policy.PolicyType;
|
||||
import com.sparrowwallet.drongo.wallet.*;
|
||||
import com.sparrowwallet.sparrow.AppServices;
|
||||
import com.sparrowwallet.sparrow.EventManager;
|
||||
@@ -34,6 +35,7 @@ import tornadofx.control.Field;
|
||||
|
||||
import javax.smartcardio.CardException;
|
||||
import java.net.URL;
|
||||
import java.util.Base64;
|
||||
import java.util.Optional;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -56,6 +58,9 @@ public class KeystoreController extends WalletFormController implements Initiali
|
||||
@FXML
|
||||
private Label type;
|
||||
|
||||
@FXML
|
||||
private Button exportButton;
|
||||
|
||||
@FXML
|
||||
private Button viewSeedButton;
|
||||
|
||||
@@ -129,6 +134,7 @@ public class KeystoreController extends WalletFormController implements Initiali
|
||||
}
|
||||
}
|
||||
|
||||
exportButton.managedProperty().bind(exportButton.visibleProperty());
|
||||
viewSeedButton.managedProperty().bind(viewSeedButton.visibleProperty());
|
||||
viewKeyButton.managedProperty().bind(viewKeyButton.visibleProperty());
|
||||
changePinButton.managedProperty().bind(changePinButton.visibleProperty());
|
||||
@@ -136,7 +142,7 @@ public class KeystoreController extends WalletFormController implements Initiali
|
||||
displayXpubQR.managedProperty().bind(displayXpubQR.visibleProperty());
|
||||
displayXpubQR.visibleProperty().bind(scanXpubQR.visibleProperty().not());
|
||||
|
||||
updateType();
|
||||
updateType(keystore.isValid() && !getWalletForm().getWallet().isValid());
|
||||
|
||||
label.setText(keystore.getLabel());
|
||||
|
||||
@@ -193,7 +199,9 @@ public class KeystoreController extends WalletFormController implements Initiali
|
||||
scanXpubQR.setVisible(!valid);
|
||||
});
|
||||
|
||||
setInputFieldsDisabled(keystore.getSource() != KeystoreSource.SW_WATCH && (!walletForm.getWallet().isMasterWallet() || !walletForm.getWallet().getChildWallets().isEmpty()));
|
||||
if(keystore.getSource() != KeystoreSource.SW_WATCH && (!walletForm.getWallet().isMasterWallet() || !walletForm.getWallet().getChildWallets().isEmpty())) {
|
||||
setInputFieldsDisabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void setXpubContext(ExtendedKey extendedKey) {
|
||||
@@ -280,9 +288,10 @@ public class KeystoreController extends WalletFormController implements Initiali
|
||||
));
|
||||
}
|
||||
|
||||
private void updateType() {
|
||||
private void updateType(boolean showExport) {
|
||||
type.setText(getTypeLabel(keystore));
|
||||
type.setGraphic(getTypeIcon(keystore));
|
||||
exportButton.setVisible(showExport && getWalletForm().getWallet().getPolicyType() == PolicyType.MULTI);
|
||||
viewSeedButton.setVisible(keystore.getSource() == KeystoreSource.SW_SEED && keystore.hasSeed());
|
||||
viewKeyButton.setVisible(keystore.getSource() == KeystoreSource.SW_SEED && keystore.hasMasterPrivateExtendedKey());
|
||||
changePinButton.setVisible(keystore.getWalletModel().isCard());
|
||||
@@ -309,9 +318,9 @@ public class KeystoreController extends WalletFormController implements Initiali
|
||||
private String getTypeLabel(Keystore keystore) {
|
||||
switch (keystore.getSource()) {
|
||||
case HW_USB:
|
||||
return "Connected Hardware Wallet (" + keystore.getWalletModel().toDisplayString() + ")";
|
||||
return "Connected Wallet (" + keystore.getWalletModel().toDisplayString() + ")";
|
||||
case HW_AIRGAPPED:
|
||||
return "Airgapped Hardware Wallet (" + keystore.getWalletModel().toDisplayString() + ")";
|
||||
return "Airgapped Wallet (" + keystore.getWalletModel().toDisplayString() + ")";
|
||||
case SW_SEED:
|
||||
return "Software Wallet";
|
||||
case SW_WATCH:
|
||||
@@ -348,7 +357,7 @@ public class KeystoreController extends WalletFormController implements Initiali
|
||||
}
|
||||
|
||||
private void launchImportDialog(KeystoreSource initialSource) {
|
||||
boolean restrictSource = keystoreSourceToggleGroup.getToggles().stream().anyMatch(toggle -> ((ToggleButton)toggle).isDisabled());
|
||||
boolean restrictSource = keystore.getSource() != KeystoreSource.SW_WATCH && keystoreSourceToggleGroup.getToggles().stream().anyMatch(toggle -> ((ToggleButton)toggle).isDisabled());
|
||||
KeyDerivation requiredDerivation = restrictSource ? keystore.getKeyDerivation() : null;
|
||||
WalletModel requiredModel = restrictSource ? keystore.getWalletModel() : null;
|
||||
KeystoreImportDialog dlg = new KeystoreImportDialog(getWalletForm().getWallet(), initialSource, requiredDerivation, requiredModel, restrictSource);
|
||||
@@ -367,7 +376,7 @@ public class KeystoreController extends WalletFormController implements Initiali
|
||||
keystore.setSeed(importedKeystore.getSeed());
|
||||
keystore.setBip47ExtendedPrivateKey(importedKeystore.getBip47ExtendedPrivateKey());
|
||||
|
||||
updateType();
|
||||
updateType(true);
|
||||
label.setText(keystore.getLabel());
|
||||
fingerprint.setText(keystore.getKeyDerivation().getMasterFingerprint());
|
||||
derivation.setText(keystore.getKeyDerivation().getDerivationPath());
|
||||
@@ -381,6 +390,11 @@ public class KeystoreController extends WalletFormController implements Initiali
|
||||
}
|
||||
}
|
||||
|
||||
public void export(ActionEvent event) {
|
||||
KeystoreExportDialog keystoreExportDialog = new KeystoreExportDialog(keystore);
|
||||
keystoreExportDialog.showAndWait();
|
||||
}
|
||||
|
||||
public void showPrivate(ActionEvent event) {
|
||||
int keystoreIndex = getWalletForm().getWallet().getKeystores().indexOf(keystore);
|
||||
Wallet copy = getWalletForm().getWallet().copy();
|
||||
@@ -465,7 +479,8 @@ public class KeystoreController extends WalletFormController implements Initiali
|
||||
Service<String> backupService = cardApi.getBackupService();
|
||||
backupService.setOnSucceeded(event -> {
|
||||
String backup = backupService.getValue();
|
||||
TextAreaDialog backupDialog = new TextAreaDialog(backup, false);
|
||||
String filename = fingerprint.getText() + ".aes";
|
||||
TextAreaDialog backupDialog = new TextAreaDialog(backup, false, filename, Base64.getDecoder().decode(backup));
|
||||
backupDialog.setTitle("Backup Private Key");
|
||||
backupDialog.getDialogPane().setHeaderText((requiresBackup ? "Please backup first by saving" : "Save") + " the following text in a safe place. It contains an encrypted copy of the card's private key, and can be decrypted using the backup key written on the back of the card.");
|
||||
backupDialog.showAndWait();
|
||||
@@ -502,6 +517,9 @@ public class KeystoreController extends WalletFormController implements Initiali
|
||||
QRScanDialog.Result result = optionalResult.get();
|
||||
if(result.extendedKey != null && result.extendedKey.getKey().isPubKeyOnly()) {
|
||||
xpub.setText(result.extendedKey.getExtendedKey());
|
||||
if(result.extendedKeyName != null) {
|
||||
label.setText(result.extendedKeyName);
|
||||
}
|
||||
} else if(result.outputDescriptor != null && !result.outputDescriptor.getExtendedPublicKeys().isEmpty()) {
|
||||
ExtendedKey extendedKey = result.outputDescriptor.getExtendedPublicKeys().iterator().next();
|
||||
KeyDerivation keyDerivation = result.outputDescriptor.getKeyDerivation(extendedKey);
|
||||
@@ -614,4 +632,11 @@ public class KeystoreController extends WalletFormController implements Initiali
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void walletSettingsChanged(WalletSettingsChangedEvent event) {
|
||||
if(event.getWalletId().equals(walletForm.getWalletId())) {
|
||||
exportButton.setVisible(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -413,7 +413,11 @@ public class PaymentController extends WalletFormController implements Initializ
|
||||
try {
|
||||
Wallet recipientBip47Wallet = getWalletForPayNym(payNym);
|
||||
if(recipientBip47Wallet != null) {
|
||||
int index = sendController.getPayNymSendIndex(this);
|
||||
WalletNode sendNode = recipientBip47Wallet.getFreshNode(KeyPurpose.SEND);
|
||||
for(int i = 0; i < index; i++) {
|
||||
sendNode = recipientBip47Wallet.getFreshNode(KeyPurpose.SEND, sendNode);
|
||||
}
|
||||
ECKey pubKey = sendNode.getPubKey();
|
||||
Address address = recipientBip47Wallet.getScriptType().getAddress(pubKey);
|
||||
if(sendController.getPaymentTabs().getTabs().size() > 1 || (getRecipientValueSats() != null && getRecipientValueSats() > getRecipientDustThreshold(address)) || maxButton.isSelected()) {
|
||||
@@ -433,6 +437,11 @@ public class PaymentController extends WalletFormController implements Initializ
|
||||
return masterWallet.getChildWallet(new PaymentCode(payNym.paymentCode().toString()), payNym.segwit() ? ScriptType.P2WPKH : ScriptType.P2PKH);
|
||||
}
|
||||
|
||||
boolean isSentToSamePayNym(PaymentController paymentController) {
|
||||
return (this != paymentController && payNymProperty.get() != null && !payNymProperty.get().isCollaborativeSend()
|
||||
&& payNymProperty.get().paymentCode().equals(paymentController.payNymProperty.get().paymentCode()));
|
||||
}
|
||||
|
||||
private Long getRecipientValueSats() {
|
||||
return getRecipientValueSats(amountUnit.getSelectionModel().getSelectedItem());
|
||||
}
|
||||
|
||||
@@ -189,6 +189,9 @@ public class ReceiveController extends WalletFormController implements Initializ
|
||||
|
||||
public void getNewAddress(ActionEvent event) {
|
||||
refreshAddress();
|
||||
if(currentEntry != null) {
|
||||
ensureSufficientGapLimit(currentEntry.getNode().getIndex());
|
||||
}
|
||||
}
|
||||
|
||||
public void refreshAddress() {
|
||||
@@ -196,6 +199,17 @@ public class ReceiveController extends WalletFormController implements Initializ
|
||||
setNodeEntry(freshEntry);
|
||||
}
|
||||
|
||||
private void ensureSufficientGapLimit(int index) {
|
||||
Wallet wallet = getWalletForm().getWallet();
|
||||
Integer highestIndex = wallet.getNode(KeyPurpose.RECEIVE).getHighestUsedIndex();
|
||||
int highestUsedIndex = highestIndex == null ? -1 : highestIndex;
|
||||
int existingGapLimit = wallet.getGapLimit();
|
||||
if(index > highestUsedIndex + existingGapLimit) {
|
||||
wallet.setGapLimit(Math.max(wallet.getGapLimit(), index - highestUsedIndex));
|
||||
EventManager.get().post(new WalletGapLimitChangedEvent(getWalletForm().getWalletId(), wallet, existingGapLimit));
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void displayAddress(ActionEvent event) {
|
||||
Wallet wallet = getWalletForm().getWallet();
|
||||
|
||||
@@ -542,6 +542,20 @@ public class SendController extends WalletFormController implements Initializabl
|
||||
}
|
||||
}
|
||||
|
||||
int getPayNymSendIndex(PaymentController paymentController) {
|
||||
int index = 0;
|
||||
for(Tab tab : paymentTabs.getTabs()) {
|
||||
PaymentController controller = (PaymentController)tab.getUserData();
|
||||
if(controller == paymentController) {
|
||||
break;
|
||||
} else if(controller.isSentToSamePayNym(paymentController)) {
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
public void updateTransaction() {
|
||||
updateTransaction(null);
|
||||
}
|
||||
@@ -1196,6 +1210,7 @@ public class SendController extends WalletFormController implements Initializabl
|
||||
if(!storage.isPersisted(childWallet)) {
|
||||
try {
|
||||
storage.saveWallet(childWallet);
|
||||
EventManager.get().post(new NewChildWalletSavedEvent(storage, masterWallet, childWallet));
|
||||
} catch(Exception e) {
|
||||
AppServices.showErrorDialog("Error saving wallet " + childWallet.getName(), e.getMessage());
|
||||
}
|
||||
@@ -1381,6 +1396,7 @@ public class SendController extends WalletFormController implements Initializabl
|
||||
if(!storage.isPersisted(addedWallet)) {
|
||||
try {
|
||||
storage.saveWallet(addedWallet);
|
||||
EventManager.get().post(new NewChildWalletSavedEvent(storage, masterWallet, addedWallet));
|
||||
} catch(Exception e) {
|
||||
log.error("Error saving wallet", e);
|
||||
AppServices.showErrorDialog("Error saving wallet " + addedWallet.getName(), e.getMessage());
|
||||
|
||||
@@ -416,24 +416,28 @@ public class SettingsController extends WalletFormController implements Initiali
|
||||
try {
|
||||
OutputDescriptor editedOutputDescriptor = OutputDescriptor.getOutputDescriptor(text.trim().replace("\\", ""));
|
||||
Wallet editedWallet = editedOutputDescriptor.toWallet();
|
||||
|
||||
editedWallet.setName(getWalletForm().getWallet().getName());
|
||||
editedWallet.setBirthDate(getWalletForm().getWallet().getBirthDate());
|
||||
editedWallet.setGapLimit(getWalletForm().getWallet().getGapLimit());
|
||||
editedWallet.setWatchLast(getWalletForm().getWallet().getWatchLast());
|
||||
keystoreTabs.getTabs().removeAll(keystoreTabs.getTabs());
|
||||
totalKeystores.unbind();
|
||||
totalKeystores.setValue(0);
|
||||
walletForm.setWallet(editedWallet);
|
||||
initialising = true;
|
||||
setFieldsFromWallet(editedWallet);
|
||||
|
||||
EventManager.get().post(new SettingsChangedEvent(editedWallet, SettingsChangedEvent.Type.POLICY));
|
||||
replaceWallet(editedWallet);
|
||||
} catch(Exception e) {
|
||||
AppServices.showErrorDialog("Invalid output descriptor", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void replaceWallet(Wallet editedWallet) {
|
||||
editedWallet.setName(getWalletForm().getWallet().getName());
|
||||
editedWallet.setBirthDate(getWalletForm().getWallet().getBirthDate());
|
||||
editedWallet.setGapLimit(getWalletForm().getWallet().getGapLimit());
|
||||
editedWallet.setWatchLast(getWalletForm().getWallet().getWatchLast());
|
||||
editedWallet.setMasterWallet(getWalletForm().getWallet().getMasterWallet());
|
||||
keystoreTabs.getTabs().removeAll(keystoreTabs.getTabs());
|
||||
totalKeystores.unbind();
|
||||
totalKeystores.setValue(0);
|
||||
walletForm.setWallet(editedWallet);
|
||||
initialising = true;
|
||||
setFieldsFromWallet(editedWallet);
|
||||
|
||||
EventManager.get().post(new SettingsChangedEvent(editedWallet, SettingsChangedEvent.Type.POLICY));
|
||||
}
|
||||
|
||||
public void showDescriptor(ActionEvent event) {
|
||||
OutputDescriptor outputDescriptor = OutputDescriptor.getOutputDescriptor(walletForm.getWallet(), KeyPurpose.DEFAULT_PURPOSES, null);
|
||||
String outputDescriptorString = outputDescriptor.toString(walletForm.getWallet().isValid());
|
||||
@@ -631,6 +635,7 @@ public class SettingsController extends WalletFormController implements Initiali
|
||||
if(!storage.isPersisted(childWallet)) {
|
||||
try {
|
||||
storage.saveWallet(childWallet);
|
||||
EventManager.get().post(new NewChildWalletSavedEvent(storage, masterWallet, childWallet));
|
||||
} catch(Exception e) {
|
||||
log.error("Error saving wallet", e);
|
||||
AppServices.showErrorDialog("Error saving wallet " + childWallet.getName(), e.getMessage());
|
||||
@@ -718,6 +723,38 @@ public class SettingsController extends WalletFormController implements Initiali
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void newChildWalletSaved(NewChildWalletSavedEvent event) {
|
||||
if(event.getMasterWalletId().equals(walletForm.getMasterWalletId())) {
|
||||
((SettingsWalletForm)walletForm).childWalletSaved(event.getChildWallet());
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void walletGapLimitChanged(WalletGapLimitChangedEvent event) {
|
||||
if(walletForm.getWalletId().equals(event.getWalletId())) {
|
||||
((SettingsWalletForm)walletForm).gapLimitChanged(event.getGapLimit());
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void existingWalletImported(ExistingWalletImportedEvent event) {
|
||||
if(event.getExistingWalletId().equals(getWalletForm().getWalletId())) {
|
||||
List<Keystore> importedKeystores = event.getImportedWallet().getKeystores();
|
||||
List<Keystore> nonWatchKeystores = walletForm.getWallet().getKeystores().stream().filter(k -> k.isValid() && k.getSource() != KeystoreSource.SW_WATCH).collect(Collectors.toList());
|
||||
for(Keystore nonWatchKeystore : nonWatchKeystores) {
|
||||
Optional<Keystore> optReplacedKeystore = importedKeystores.stream().filter(k -> nonWatchKeystore.getExtendedPublicKey().equals(k.getExtendedPublicKey())).findFirst();
|
||||
if(optReplacedKeystore.isPresent()) {
|
||||
int index = importedKeystores.indexOf(optReplacedKeystore.get());
|
||||
importedKeystores.remove(index);
|
||||
importedKeystores.add(index, nonWatchKeystore);
|
||||
}
|
||||
}
|
||||
|
||||
replaceWallet(event.getImportedWallet());
|
||||
}
|
||||
}
|
||||
|
||||
private void saveWallet(boolean changePassword, boolean suggestChangePassword) {
|
||||
ECKey existingPubKey = walletForm.getStorage().getEncryptionPubKey();
|
||||
|
||||
|
||||
@@ -242,4 +242,19 @@ public class SettingsWalletForm extends WalletForm {
|
||||
|
||||
return changedKeystores;
|
||||
}
|
||||
|
||||
public void childWalletSaved(Wallet childWallet) {
|
||||
//Update the child wallets for the master wallet of the local walletCopy to ensure all KeystoreEncryptionChangedEvents are posted
|
||||
Wallet masterWalletCopy = walletCopy.isMasterWallet() ? walletCopy : walletCopy.getMasterWallet();
|
||||
Wallet childWalletCopy = masterWalletCopy.getChildWallet(childWallet.getName());
|
||||
if(childWalletCopy == null) {
|
||||
childWalletCopy = childWallet.copy();
|
||||
childWalletCopy.setMasterWallet(masterWalletCopy);
|
||||
masterWalletCopy.getChildWallets().add(childWallet.copy());
|
||||
}
|
||||
}
|
||||
|
||||
public void gapLimitChanged(int gapLimit) {
|
||||
walletCopy.setGapLimit(gapLimit);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,6 +103,7 @@ public class WalletController extends WalletFormController implements Initializa
|
||||
WalletForm walletForm = getWalletForm();
|
||||
if(function.equals(Function.SETTINGS)) {
|
||||
walletForm = new SettingsWalletForm(getWalletForm().getStorage(), getWalletForm().getWallet());
|
||||
getWalletForm().setSettingsWalletForm(walletForm);
|
||||
}
|
||||
|
||||
controller.setWalletForm(walletForm);
|
||||
|
||||
@@ -41,6 +41,7 @@ public class WalletForm {
|
||||
|
||||
private final PublishSubject<WalletNode> refreshNodesSubject;
|
||||
|
||||
private WalletForm settingsWalletForm;
|
||||
private final List<WalletForm> nestedWalletForms = new ArrayList<>();
|
||||
|
||||
private WalletTransactionsEntry walletTransactionsEntry;
|
||||
@@ -96,6 +97,14 @@ public class WalletForm {
|
||||
throw new UnsupportedOperationException("Only SettingsWalletForm supports setWallet");
|
||||
}
|
||||
|
||||
public WalletForm getSettingsWalletForm() {
|
||||
return settingsWalletForm;
|
||||
}
|
||||
|
||||
void setSettingsWalletForm(WalletForm settingsWalletForm) {
|
||||
this.settingsWalletForm = settingsWalletForm;
|
||||
}
|
||||
|
||||
public List<WalletForm> getNestedWalletForms() {
|
||||
return nestedWalletForms;
|
||||
}
|
||||
@@ -189,6 +198,7 @@ public class WalletForm {
|
||||
if(!storage.isPersisted(addedWallet)) {
|
||||
try {
|
||||
storage.saveWallet(addedWallet);
|
||||
EventManager.get().post(new NewChildWalletSavedEvent(storage, wallet, addedWallet));
|
||||
} catch(Exception e) {
|
||||
log.error("Error saving wallet", e);
|
||||
AppServices.showErrorDialog("Error saving wallet " + addedWallet.getName(), e.getMessage());
|
||||
@@ -594,7 +604,9 @@ public class WalletForm {
|
||||
Optional<WalletNode> optPurposeNode = wallet.getPurposeNodes().stream().filter(node -> node.getKeyPurpose() == keyPurpose).findFirst();
|
||||
if(optPurposeNode.isPresent()) {
|
||||
WalletNode purposeNode = optPurposeNode.get();
|
||||
newNodes.addAll(purposeNode.fillToIndex(wallet, wallet.getLookAheadIndex(purposeNode)));
|
||||
purposeNode.fillToIndex(wallet, wallet.getLookAheadIndex(purposeNode));
|
||||
int previousLookAheadIndex = event.getPreviousLookAheadIndex(purposeNode);
|
||||
newNodes.addAll(purposeNode.getChildren().stream().filter(node -> node.getIndex() > previousLookAheadIndex).collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -68,6 +68,7 @@ public class Whirlpool {
|
||||
private final ExpirablePoolSupplier poolSupplier;
|
||||
private final Tx0Service tx0Service;
|
||||
private Tx0FeeTarget tx0FeeTarget = Tx0FeeTarget.BLOCKS_4;
|
||||
private Tx0FeeTarget mixFeeTarget = Tx0FeeTarget.BLOCKS_4;
|
||||
private HD_Wallet hdWallet;
|
||||
private String walletId;
|
||||
private String mixToWalletId;
|
||||
@@ -149,7 +150,6 @@ public class Whirlpool {
|
||||
}
|
||||
|
||||
private Tx0Config computeTx0Config() {
|
||||
Tx0FeeTarget mixFeeTarget = Tx0FeeTarget.BLOCKS_4;
|
||||
return new Tx0Config(tx0ParamService, poolSupplier, tx0FeeTarget, mixFeeTarget, WhirlpoolAccount.BADBANK);
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ public class Whirlpool {
|
||||
ScriptType scriptType = wallet.getScriptType();
|
||||
int purpose = scriptType.getDefaultDerivation().get(0).num();
|
||||
List<String> words = keystore.getSeed().getMnemonicCode();
|
||||
String passphrase = keystore.getSeed().getPassphrase().asString();
|
||||
String passphrase = keystore.getSeed().getPassphrase() == null ? "" : keystore.getSeed().getPassphrase().asString();
|
||||
HD_WalletFactoryGeneric hdWalletFactory = HD_WalletFactoryGeneric.getInstance();
|
||||
byte[] seed = hdWalletFactory.computeSeedFromWords(words);
|
||||
this.walletId = walletId;
|
||||
@@ -488,6 +488,14 @@ public class Whirlpool {
|
||||
this.tx0FeeTarget = tx0FeeTarget;
|
||||
}
|
||||
|
||||
public Tx0FeeTarget getMixFeeTarget() {
|
||||
return mixFeeTarget;
|
||||
}
|
||||
|
||||
public void setMixFeeTarget(Tx0FeeTarget mixFeeTarget) {
|
||||
this.mixFeeTarget = mixFeeTarget;
|
||||
}
|
||||
|
||||
public String getWalletId() {
|
||||
return walletId;
|
||||
}
|
||||
|
||||
@@ -55,6 +55,9 @@ public class WhirlpoolController {
|
||||
@FXML
|
||||
private CopyableLabel premixFeeRate;
|
||||
|
||||
@FXML
|
||||
private Label lowPremixFeeRate;
|
||||
|
||||
@FXML
|
||||
private ComboBox<Pool> pool;
|
||||
|
||||
@@ -139,9 +142,12 @@ public class WhirlpoolController {
|
||||
tx0Previews = null;
|
||||
tx0PreviewProperty.set(null);
|
||||
Tx0FeeTarget tx0FeeTarget = FEE_TARGETS.get(newValue.intValue());
|
||||
premixFeeRate.setText(SparrowMinerFeeSupplier.getFee(Integer.parseInt(tx0FeeTarget.getFeeTarget().getValue())) + " sats/vB");
|
||||
premixFeeRate.setText(getFeeRate(tx0FeeTarget) + " sats/vB");
|
||||
lowPremixFeeRate.setVisible(tx0FeeTarget == Tx0FeeTarget.MIN && getFeeRate(tx0FeeTarget) * 2 < getFeeRate(Tx0FeeTarget.BLOCKS_4));
|
||||
});
|
||||
premixPriority.setValue(1);
|
||||
lowPremixFeeRate.managedProperty().bind(lowPremixFeeRate.visibleProperty());
|
||||
lowPremixFeeRate.setVisible(false);
|
||||
|
||||
if(mixConfig.getScode() != null) {
|
||||
step1.setVisible(false);
|
||||
@@ -218,6 +224,10 @@ public class WhirlpoolController {
|
||||
});
|
||||
}
|
||||
|
||||
private int getFeeRate(Tx0FeeTarget tx0FeeTarget) {
|
||||
return SparrowMinerFeeSupplier.getFee(Integer.parseInt(tx0FeeTarget.getFeeTarget().getValue()));
|
||||
}
|
||||
|
||||
public boolean next() {
|
||||
if(step1.isVisible()) {
|
||||
step1.setVisible(false);
|
||||
@@ -318,6 +328,7 @@ public class WhirlpoolController {
|
||||
tx0Previews = null;
|
||||
whirlpool.setScode(mixConfig.getScode());
|
||||
whirlpool.setTx0FeeTarget(FEE_TARGETS.get(premixPriority.valueProperty().intValue()));
|
||||
whirlpool.setMixFeeTarget(FEE_TARGETS.get(premixPriority.valueProperty().intValue()));
|
||||
|
||||
Whirlpool.Tx0PreviewsService tx0PreviewsService = new Whirlpool.Tx0PreviewsService(whirlpool, utxoEntries);
|
||||
tx0PreviewsService.setOnRunning(workerStateEvent -> {
|
||||
|
||||
+10
-1
@@ -4,6 +4,7 @@ import com.samourai.wallet.client.indexHandler.AbstractIndexHandler;
|
||||
import com.sparrowwallet.drongo.KeyPurpose;
|
||||
import com.sparrowwallet.drongo.wallet.Wallet;
|
||||
import com.sparrowwallet.drongo.wallet.WalletNode;
|
||||
import com.sparrowwallet.sparrow.AppServices;
|
||||
import com.sparrowwallet.sparrow.EventManager;
|
||||
import com.sparrowwallet.sparrow.event.WalletGapLimitChangedEvent;
|
||||
import com.sparrowwallet.sparrow.event.WalletMixConfigChangedEvent;
|
||||
@@ -75,7 +76,15 @@ public class SparrowIndexHandler extends AbstractIndexHandler {
|
||||
int existingGapLimit = wallet.getGapLimit();
|
||||
if(index > highestUsedIndex + existingGapLimit) {
|
||||
wallet.setGapLimit(Math.max(wallet.getGapLimit(), index - highestUsedIndex));
|
||||
EventManager.get().post(new WalletGapLimitChangedEvent(wallet));
|
||||
EventManager.get().post(new WalletGapLimitChangedEvent(getWalletId(), wallet, existingGapLimit));
|
||||
}
|
||||
}
|
||||
|
||||
private String getWalletId() {
|
||||
try {
|
||||
return AppServices.get().getOpenWallets().get(wallet).getWalletId(wallet);
|
||||
} catch(Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,10 @@ package com.sparrowwallet.sparrow.whirlpool.tor;
|
||||
|
||||
import com.google.common.net.HostAndPort;
|
||||
import com.samourai.tor.client.TorClientService;
|
||||
import com.sparrowwallet.sparrow.net.TorService;
|
||||
import com.sparrowwallet.sparrow.AppServices;
|
||||
import com.sparrowwallet.sparrow.net.Tor;
|
||||
import com.sparrowwallet.sparrow.whirlpool.Whirlpool;
|
||||
import io.matthewnelson.kmp.tor.controller.common.control.usecase.TorControlSignal;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -23,13 +25,12 @@ public class SparrowTorClientService extends TorClientService {
|
||||
public void changeIdentity() {
|
||||
HostAndPort proxy = whirlpool.getTorProxy();
|
||||
if(proxy != null) {
|
||||
Socket controlSocket = TorService.getControlSocket();
|
||||
if(controlSocket != null) {
|
||||
try {
|
||||
writeNewNym(controlSocket);
|
||||
} catch(Exception e) {
|
||||
log.warn("Error sending NEWNYM to " + controlSocket, e);
|
||||
}
|
||||
if(AppServices.isTorRunning()) {
|
||||
Tor.getDefault().getTorManager().signal(TorControlSignal.Signal.NewNym, throwable -> {
|
||||
log.warn("Failed to signal newnym");
|
||||
}, successEvent -> {
|
||||
log.info("Signalled newnym for new Tor circuit");
|
||||
});
|
||||
} else {
|
||||
HostAndPort control = HostAndPort.fromParts(proxy.getHost(), proxy.getPort() + 1);
|
||||
try(Socket socket = new Socket(control.getHost(), control.getPort())) {
|
||||
|
||||
@@ -19,7 +19,19 @@ open module com.sparrowwallet.sparrow {
|
||||
requires org.jetbrains.annotations;
|
||||
requires com.fasterxml.jackson.databind;
|
||||
requires com.fasterxml.jackson.annotation;
|
||||
requires netlayer.jpms;
|
||||
requires kotlin.stdlib;
|
||||
requires kmp.tor.jvm;
|
||||
requires kmp.tor.binary.extract.jvm;
|
||||
requires kmp.tor.common.jvm;
|
||||
requires kmp.tor.controller.common.jvm;
|
||||
requires kmp.tor.manager.jvm;
|
||||
requires kmp.tor.manager.common.jvm;
|
||||
requires kmp.tor.ext.callback.manager.jvm;
|
||||
requires kmp.tor.ext.callback.common.jvm;
|
||||
requires kmp.tor.ext.callback.manager.common.jvm;
|
||||
requires kmp.tor.ext.callback.controller.common.jvm;
|
||||
requires parcelize.jvm;
|
||||
requires kotlinx.coroutines.javafx;
|
||||
requires org.slf4j;
|
||||
requires com.google.gson;
|
||||
requires org.jdbi.v3.core;
|
||||
@@ -31,7 +43,6 @@ open module com.sparrowwallet.sparrow {
|
||||
requires org.fxmisc.flowless;
|
||||
requires com.github.sarxos.webcam.capture;
|
||||
requires centerdevice.nsmenufx;
|
||||
requires com.github.JesusMcCloud.jtorctl;
|
||||
requires com.beust.jcommander;
|
||||
requires org.slf4j.jul.to.slf4j;
|
||||
requires net.sourceforge.javacsv;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
.root {
|
||||
-fx-accent: #1e88cf;
|
||||
-fx-accent: #166793;
|
||||
-fx-focus-color: -fx-accent;
|
||||
-fx-base: #373e43;
|
||||
-fx-control-inner-background: derive(-fx-base, 35%);
|
||||
-fx-base: #1b1d1f;
|
||||
-fx-control-inner-background: derive(-fx-base, 25%);
|
||||
-fx-control-inner-background-alt: -fx-control-inner-background ;
|
||||
-fx-default-button: -fx-accent;
|
||||
-fx-default-button: #1e88cf;
|
||||
-fx-box-border: ladder(-fx-color, black 20%, derive(-fx-color,40%) 30%);
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
-fx-text-fill: lightgray;
|
||||
}
|
||||
|
||||
.text-field {
|
||||
.text-field, .text-area {
|
||||
-fx-prompt-text-fill: gray;
|
||||
}
|
||||
|
||||
@@ -40,7 +40,11 @@
|
||||
}
|
||||
|
||||
.button:default {
|
||||
-fx-base: -fx-accent ;
|
||||
-fx-base: -fx-default-button;
|
||||
}
|
||||
|
||||
.split-menu-button.default-button > .label {
|
||||
-fx-text-fill: white;
|
||||
}
|
||||
|
||||
.table-view, .tree-view {
|
||||
@@ -54,12 +58,15 @@
|
||||
}
|
||||
|
||||
.list-cell:even,
|
||||
.list-cell:odd,
|
||||
.table-row-cell:even,
|
||||
.table-row-cell:odd{
|
||||
.table-row-cell:even{
|
||||
-fx-control-inner-background: derive(-fx-base, 15%);
|
||||
}
|
||||
|
||||
.list-cell:odd,
|
||||
.table-row-cell:odd{
|
||||
-fx-control-inner-background: derive(-fx-base, 20%);
|
||||
}
|
||||
|
||||
.list-cell:empty,
|
||||
.table-row-cell:empty {
|
||||
-fx-background-color: transparent;
|
||||
@@ -67,10 +74,42 @@
|
||||
|
||||
.list-cell,
|
||||
.table-row-cell{
|
||||
-fx-border-color: transparent;
|
||||
-fx-table-cell-border-color:transparent;
|
||||
}
|
||||
|
||||
.list-view:focused > .virtual-flow > .clipped-container > .sheet > .list-cell:filled:selected,
|
||||
.tree-table-view:focused > .virtual-flow > .clipped-container > .sheet > .tree-table-row-cell:filled:selected,
|
||||
.tree-table-view:focused > .virtual-flow > .clipped-container > .sheet > .tree-table-row-cell .tree-table-cell:selected {
|
||||
-fx-background: -fx-selection-bar;
|
||||
-fx-table-cell-border-color: derive(-fx-selection-bar, 20%);
|
||||
}
|
||||
|
||||
.list-cell:filled:selected,
|
||||
.tree-table-row-cell:filled:selected,
|
||||
.tree-table-row-cell:filled > .tree-table-cell:selected {
|
||||
-fx-background: derive(-fx-selection-bar-non-focused, -60%);
|
||||
-fx-table-cell-border-color: -fx-inner-border;
|
||||
}
|
||||
|
||||
.spreadsheet-cell {
|
||||
-fx-background-color: -fx-table-cell-border-color, derive(-fx-base, 25%);
|
||||
-fx-text-fill: -fx-text-inner-color;
|
||||
}
|
||||
|
||||
VerticalHeader > Label{
|
||||
-fx-background-color: derive(-fx-box-border, 50%), -fx-base;
|
||||
}
|
||||
|
||||
HorizontalHeaderColumn > TableColumnHeader.column-header.table-column{
|
||||
-fx-background-color: derive(-fx-box-border, 50%), -fx-base;
|
||||
}
|
||||
|
||||
.root #grid .spreadsheet-cell:selected,
|
||||
.root #grid .spreadsheet-cell:focused:selected,
|
||||
.root #grid .spreadsheet-cell:focused:selected:hover {
|
||||
-fx-background-color: rgb(159, 142, 0);
|
||||
}
|
||||
|
||||
.status-bar {
|
||||
-fx-background-color: derive(-fx-color,-15%), -fx-body-color;
|
||||
}
|
||||
@@ -95,6 +134,36 @@
|
||||
-fx-fill: #e06c75;
|
||||
}
|
||||
|
||||
.root .list-menu {
|
||||
-fx-background-color: #2284bb;
|
||||
}
|
||||
|
||||
.root .list-item {
|
||||
-fx-pref-width: 180;
|
||||
-fx-background-color: #2284bb;
|
||||
}
|
||||
|
||||
.root .list-item:hover {
|
||||
-fx-background-color: linear-gradient(to right, #2284bb, derive(#388fc7, 10%));
|
||||
}
|
||||
|
||||
.root .list-item:selected {
|
||||
-fx-background-color: linear-gradient(to right, #2284bb, derive(#1479bb, -10%));
|
||||
}
|
||||
|
||||
.root .list-item:disabled {
|
||||
-fx-background-color: #626367;
|
||||
-fx-border-color: #626367;
|
||||
}
|
||||
|
||||
.root .wallet-subtabs > .tab-header-area .tab {
|
||||
-fx-background-color: derive(#2284bb, 32%);
|
||||
}
|
||||
|
||||
.root .wallet-subtabs > .tab-header-area .tab:selected {
|
||||
-fx-background-color: #2284bb;
|
||||
}
|
||||
|
||||
#inputsPie .default-color0.chart-pie {
|
||||
-fx-pie-color: #e06c75;
|
||||
}
|
||||
@@ -157,6 +226,38 @@
|
||||
color-grey: #3e4451;
|
||||
}
|
||||
|
||||
.root .progress-bar {
|
||||
-fx-accent: derive(-fx-default-button, -15%);
|
||||
}
|
||||
|
||||
.root .segment1 .progress-bar {
|
||||
-fx-accent: derive(CHART_COLOR_3, -20%);
|
||||
}
|
||||
|
||||
.root .segment2 .progress-bar {
|
||||
-fx-accent: derive(CHART_COLOR_7, -20%);
|
||||
}
|
||||
|
||||
.root .segment3 .progress-bar {
|
||||
-fx-accent: derive(CHART_COLOR_5, -20%);
|
||||
}
|
||||
|
||||
.root .segment4 .progress-bar {
|
||||
-fx-accent: derive(CHART_COLOR_6, -20%);
|
||||
}
|
||||
|
||||
.root .segment5 .progress-bar {
|
||||
-fx-accent: derive(CHART_COLOR_2, -20%);
|
||||
}
|
||||
|
||||
.root .segment6 .progress-bar {
|
||||
-fx-accent: derive(CHART_COLOR_1, -20%);
|
||||
}
|
||||
|
||||
.root .segment7 .progress-bar {
|
||||
-fx-accent: derive(CHART_COLOR_8, -20%);
|
||||
}
|
||||
|
||||
.root .readonly.text-input {
|
||||
-fx-text-fill: lightgray;
|
||||
}
|
||||
@@ -221,4 +322,12 @@
|
||||
|
||||
.root .progress-indicator.progress-timer.warn > .determinate-indicator > .indicator {
|
||||
-fx-background-color: -fx-box-border, radial-gradient(center 50% 50%, radius 50%, #e06c75 70%, derive(-fx-control-inner-background, -9%) 100%);
|
||||
}
|
||||
}
|
||||
|
||||
.root .hyperlink {
|
||||
-fx-text-fill: #229df5;
|
||||
}
|
||||
|
||||
.root .hyperlink:visited {
|
||||
-fx-text-fill: #229df5;
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user