Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Open sidebar
deBeauvoir
samourai-wallet-android
Commits
c004f2de
Commit
c004f2de
authored
Dec 30, 2021
by
zeroleak
Browse files
reset BIPUtils on HD_WalletFactory.clear() + use extlibj 0.0.26-2
parent
b6122531
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
76 additions
and
47 deletions
+76
-47
app/build.gradle
app/build.gradle
+1
-1
app/src/main/java/com/samourai/wallet/hd/HD_WalletFactory.java
...rc/main/java/com/samourai/wallet/hd/HD_WalletFactory.java
+11
-7
app/src/main/java/com/samourai/wallet/payload/PayloadUtil.java
...rc/main/java/com/samourai/wallet/payload/PayloadUtil.java
+0
-21
app/src/main/java/com/samourai/wallet/settings/SettingsDetailsFragment.kt
...a/com/samourai/wallet/settings/SettingsDetailsFragment.kt
+4
-0
app/src/main/java/com/samourai/wallet/util/AddressFactory.java
...rc/main/java/com/samourai/wallet/util/AddressFactory.java
+37
-1
app/src/main/java/com/samourai/wallet/util/AppUtil.java
app/src/main/java/com/samourai/wallet/util/AppUtil.java
+23
-17
No files found.
app/build.gradle
View file @
c004f2de
...
...
@@ -145,7 +145,7 @@ dependencies {
exclude
group:
'org.json'
,
module:
'json'
exclude
group:
'io.samourai.code.wallet'
,
module:
'extlibj'
}
implementation
(
'io.samourai.code.wallet:extlibj:0.0.26-
1
'
)
{
implementation
(
'io.samourai.code.wallet:extlibj:0.0.26-
2
'
)
{
exclude
group:
'com.google.code.findbugs'
,
module:
'jsr305'
exclude
group:
'com.google.protobuf'
,
module:
'protobuf-java'
exclude
group:
'net.jcip'
,
module:
'jcip-annotations'
...
...
app/src/main/java/com/samourai/wallet/hd/HD_WalletFactory.java
View file @
c004f2de
...
...
@@ -8,6 +8,7 @@ import com.samourai.wallet.bip47.BIP47Util;
import
com.samourai.wallet.bip47.rpc.BIP47Wallet
;
import
com.samourai.wallet.segwit.BIP49Util
;
import
com.samourai.wallet.segwit.BIP84Util
;
import
com.samourai.wallet.util.AddressFactory
;
import
com.samourai.wallet.util.AppUtil
;
import
com.samourai.wallet.util.FormatsUtil
;
...
...
@@ -181,15 +182,24 @@ public class HD_WalletFactory {
}
public
void
set
(
HD_Wallet
wallet
)
{
// reset HD_WalletFactory
Log
.
d
(
TAG
,
"set wallet"
);
wallets
.
clear
();
if
(
wallet
!=
null
)
{
wallets
.
clear
();
wallets
.
add
(
wallet
);
}
// reset BIPUtils
BIP47Util
.
getInstance
(
context
).
reset
();
BIP49Util
.
getInstance
(
context
).
reset
();
BIP84Util
.
getInstance
(
context
).
reset
();
// reset AddressFactory from BIPUtils
AddressFactory
.
getInstance
(
context
).
reset
();
}
public
void
clear
()
{
set
(
null
);
}
public
boolean
holding
()
{
...
...
@@ -200,12 +210,6 @@ public class HD_WalletFactory {
return
wallets
;
}
public
void
clear
()
{
wallets
=
null
;
context
=
null
;
instance
=
null
;
}
private
MnemonicCode
computeMnemonicCode
()
throws
IOException
{
if
(
mc
==
null
)
{
InputStream
wis
=
context
.
getAssets
().
open
(
"BIP39/en.txt"
);
...
...
app/src/main/java/com/samourai/wallet/payload/PayloadUtil.java
View file @
c004f2de
...
...
@@ -15,7 +15,6 @@ import com.samourai.wallet.bip47.BIP47Util;
import
com.samourai.wallet.cahoots.CahootsFactory
;
import
com.samourai.wallet.crypto.AESUtil
;
import
com.samourai.wallet.crypto.DecryptionException
;
import
com.samourai.wallet.hd.HD_Account
;
import
com.samourai.wallet.hd.HD_Wallet
;
import
com.samourai.wallet.hd.HD_WalletFactory
;
import
com.samourai.wallet.hd.WALLET_INDEX
;
...
...
@@ -167,25 +166,6 @@ public class PayloadUtil {
public
synchronized
void
wipe
()
throws
IOException
{
BIP47Meta
.
getInstance
().
clear
();
DojoUtil
.
getInstance
(
context
).
clear
();
APIFactory
.
getInstance
(
context
).
reset
();
PrefsUtil
.
getInstance
(
context
).
setValue
(
PrefsUtil
.
ENABLE_TOR
,
false
);
PrefsUtil
.
getInstance
(
context
).
setValue
(
PrefsUtil
.
IS_RESTORE
,
false
);
PrefsUtil
.
getInstance
(
context
).
clear
();
RicochetMeta
.
getInstance
(
context
).
empty
();
RicochetMeta
.
getInstance
(
context
).
setIndex
(
0
);
HD_WalletFactory
.
getInstance
(
context
).
set
(
null
);
HD_WalletFactory
.
getInstance
(
context
).
clear
();
AddressFactory
.
getInstance
().
reset
();
AddressFactory
.
getInstance
().
wipe
();
File
dir
=
context
.
getDir
(
dataDir
,
Context
.
MODE_PRIVATE
);
File
datfile
=
new
File
(
dir
,
strFilename
);
File
tmpfile
=
new
File
(
dir
,
strTmpFilename
);
...
...
@@ -211,7 +191,6 @@ public class PayloadUtil {
}
}
}
public
JSONObject
getPayload
()
{
...
...
app/src/main/java/com/samourai/wallet/settings/SettingsDetailsFragment.kt
View file @
c004f2de
...
...
@@ -683,6 +683,10 @@ class SettingsDetailsFragment(private val key: String?) : PreferenceFragmentComp
"""
.
trimIndent
())
// debug consistency
val
debugConsistency
=
AddressFactory
.
getInstance
(
context
).
debugConsistency
()
builder
.
append
(
"\n-- AddressFactory consistency --\n"
+
debugConsistency
)
MaterialAlertDialogBuilder
(
requireContext
())
.
setTitle
(
R
.
string
.
app_name
)
.
setMessage
(
builder
.
toString
())
...
...
app/src/main/java/com/samourai/wallet/util/AddressFactory.java
View file @
c004f2de
...
...
@@ -6,9 +6,12 @@ import android.util.Log;
import
com.samourai.wallet.SamouraiWallet
;
import
com.samourai.wallet.hd.HD_Wallet
;
import
com.samourai.wallet.hd.HD_WalletFactory
;
import
com.samourai.wallet.hd.WALLET_INDEX
;
import
com.samourai.wallet.segwit.BIP49Util
;
import
com.samourai.wallet.segwit.BIP84Util
;
import
org.apache.commons.lang3.tuple.Pair
;
import
java.util.HashMap
;
public
class
AddressFactory
extends
AddressFactoryGeneric
{
...
...
@@ -41,7 +44,8 @@ public class AddressFactory extends AddressFactoryGeneric {
account2xpub
=
new
HashMap
<
Integer
,
String
>();
}
public
void
init
()
{
@Override
public
void
reset
()
{
Log
.
d
(
TAG
,
"reset"
);
HD_Wallet
bip44w
=
HD_WalletFactory
.
getInstance
(
context
).
get
();
HD_Wallet
bip49w
=
BIP49Util
.
getInstance
(
context
).
getWallet
();
...
...
@@ -49,6 +53,38 @@ public class AddressFactory extends AddressFactoryGeneric {
reset
(
bip44w
,
bip49w
,
bip84w
,
SamouraiWallet
.
getInstance
().
getCurrentNetworkParams
());
}
public
String
debugConsistency
()
{
StringBuilder
sb
=
new
StringBuilder
();
// check bip44
Pair
<
Integer
,
String
>
bip44Mine
=
getAddress
(
WALLET_INDEX
.
BIP44_RECEIVE
);
String
bip44External
=
HD_WalletFactory
.
getInstance
(
context
).
get
().
getAddressAt
(
0
,
0
,
bip44Mine
.
getLeft
()).
getAddressString
();
doDebugConsistency
(
bip44Mine
.
getRight
(),
bip44External
,
"HD_WalletFactory"
,
sb
);
// check bip49
Pair
<
Integer
,
String
>
bip49Mine
=
getAddress
(
WALLET_INDEX
.
BIP49_RECEIVE
);
String
bip49External
=
BIP49Util
.
getInstance
(
context
).
getAddressAt
(
0
,
bip49Mine
.
getLeft
()).
getAddressAsString
();
doDebugConsistency
(
bip49Mine
.
getRight
(),
bip49External
,
"BIP49Util"
,
sb
);
// check bip84
Pair
<
Integer
,
String
>
bip84Mine
=
getAddress
(
WALLET_INDEX
.
BIP84_RECEIVE
);
String
bip84External
=
BIP84Util
.
getInstance
(
context
).
getAddressAt
(
0
,
bip84Mine
.
getLeft
()).
getBech32AsString
();
doDebugConsistency
(
bip84Mine
.
getRight
(),
bip84External
,
"BIP84Util"
,
sb
);
return
sb
.
toString
();
}
private
void
doDebugConsistency
(
String
addressMine
,
String
addressExternal
,
String
nameExternal
,
StringBuilder
sb
)
{
sb
.
append
(
nameExternal
+
": "
);
if
(
addressMine
.
equals
(
addressExternal
))
{
sb
.
append
(
"OK\n"
);
}
else
{
sb
.
append
(
"KO!\n"
);
sb
.
append
(
"mine="
+
addressMine
+
"\n"
);
sb
.
append
(
nameExternal
+
"="
+
addressExternal
+
"\n"
);
}
}
public
HashMap
<
String
,
Integer
>
xpub2account
()
{
return
xpub2account
;
}
...
...
app/src/main/java/com/samourai/wallet/util/AppUtil.java
View file @
c004f2de
package
com.samourai.wallet.util
;
import
android.app.ActivityManager
;
import
android.content.ComponentName
;
import
android.content.Context
;
...
...
@@ -10,15 +10,16 @@ import android.util.Log;
import
android.widget.Toast
;
import
com.samourai.wallet.MainActivity2
;
import
com.samourai.wallet.R
;
import
com.samourai.wallet.access.AccessFactory
;
import
com.samourai.wallet.api.APIFactory
;
import
com.samourai.wallet.bip47.BIP47
Util
;
import
com.samourai.wallet.bip47.BIP47
Meta
;
import
com.samourai.wallet.hd.HD_Wallet
;
import
com.samourai.wallet.hd.HD_WalletFactory
;
import
com.samourai.wallet.network.dojo.DojoUtil
;
import
com.samourai.wallet.payload.PayloadUtil
;
import
com.samourai.wallet.prng.PRNGFixes
;
import
com.samourai.wallet.R
;
import
com.samourai.wallet.ricochet.RicochetMeta
;
import
com.samourai.wallet.segwit.BIP49Util
;
import
com.samourai.wallet.segwit.BIP84Util
;
import
com.samourai.wallet.send.BlockedUTXO
;
import
com.samourai.wallet.utxos.UTXOUtil
;
...
...
@@ -93,6 +94,7 @@ public class AppUtil {
public
void
wipeApp
()
{
try
{
// wipe whirlpool files
HD_Wallet
bip84w
=
BIP84Util
.
getInstance
(
context
).
getWallet
();
WhirlpoolUtils
.
getInstance
().
wipe
(
bip84w
,
context
);
}
...
...
@@ -114,9 +116,18 @@ public class AppUtil {
}
*/
BIP49Util
.
getInstance
(
context
).
reset
();
BIP84Util
.
getInstance
(
context
).
reset
();
BIP47Util
.
getInstance
(
context
).
reset
();
BIP47Meta
.
getInstance
().
clear
();
DojoUtil
.
getInstance
(
context
).
clear
();
try
{
PayloadUtil
.
getInstance
(
context
).
wipe
();
}
catch
(
IOException
ioe
)
{
ioe
.
printStackTrace
();
}
// reset HD_WalletFactory + BIP47Util + BIP49Util + BIP84Util + AddressFactory
HD_WalletFactory
.
getInstance
(
context
).
clear
();
deleteBackup
();
deleteQR
();
...
...
@@ -132,10 +143,13 @@ public class AppUtil {
APIFactory
.
getInstance
(
context
).
setXpubBalance
(
0L
);
APIFactory
.
getInstance
(
context
).
reset
();
PrefsUtil
.
getInstance
(
context
).
clear
();
PrefsUtil
.
getInstance
(
context
).
setValue
(
PrefsUtil
.
ENABLE_TOR
,
false
);
PrefsUtil
.
getInstance
(
context
).
setValue
(
PrefsUtil
.
IS_RESTORE
,
false
);
PrefsUtil
.
getInstance
(
context
).
clear
();
BlockedUTXO
.
getInstance
().
clear
();
BlockedUTXO
.
getInstance
().
clearPostMix
();
RicochetMeta
.
getInstance
(
context
).
empty
();
RicochetMeta
.
getInstance
(
context
).
setIndex
(
0
);
SendAddressUtil
.
getInstance
().
reset
();
SentToFromBIP47Util
.
getInstance
().
reset
();
BatchSendUtil
.
getInstance
().
clear
();
...
...
@@ -148,15 +162,7 @@ public class AppUtil {
catch
(
IOException
ioe
)
{
ioe
.
printStackTrace
();
}
try
{
PayloadUtil
.
getInstance
(
context
).
wipe
();
}
catch
(
IOException
ioe
)
{
ioe
.
printStackTrace
();
}
}
}
public
void
restartApp
()
{
Intent
intent
=
new
Intent
(
context
,
MainActivity2
.
class
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment