Commit 2e3af931 authored by zeroleak's avatar zeroleak
Browse files

move BIP39/en.txt to Bip39English + remove HD_WalletFactoryJava + adapt for Sparrow

parent 6e0545d3
......@@ -2,7 +2,6 @@ package com.samourai.wallet.api.backend;
import com.samourai.wallet.api.backend.beans.*;
import com.samourai.wallet.util.oauth.OAuthManager;
import java8.util.Optional;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -24,18 +23,19 @@ public class BackendApi {
private IBackendClient httpClient;
private String urlBackend;
private Optional<OAuthManager> oAuthManager;
private OAuthManager oAuthManager; // may be null
public BackendApi(IBackendClient httpClient, String urlBackend, Optional<OAuthManager> oAuthManager) {
public BackendApi(IBackendClient httpClient, String urlBackend) {
this(httpClient, urlBackend, null);
}
public BackendApi(IBackendClient httpClient, String urlBackend, OAuthManager oAuthManager) {
this.httpClient = httpClient;
this.urlBackend = urlBackend;
if (oAuthManager == null) {
oAuthManager = Optional.empty();
}
this.oAuthManager = oAuthManager;
if (log.isDebugEnabled()) {
String oAuthStr = oAuthManager.isPresent() ? "yes" : "no";
String oAuthStr = oAuthManager != null ? "yes" : "no";
log.debug("urlBackend=" + urlBackend + ", oAuth=" + oAuthStr);
}
}
......@@ -250,9 +250,9 @@ public class BackendApi {
protected Map<String,String> computeHeaders() throws Exception {
Map<String,String> headers = new HashMap<String, String>();
if (oAuthManager.isPresent()) {
if (oAuthManager != null) {
// add auth token
headers.put("Authorization", "Bearer " + oAuthManager.get().getOAuthAccessToken());
headers.put("Authorization", "Bearer " + oAuthManager.getOAuthAccessToken());
}
return headers;
}
......
......@@ -20,19 +20,19 @@ public class BackendWsApi {
private boolean connected;
private IWebsocketClient wsClient;
private String urlBackend;
private Optional<OAuthManager> oAuthManager;
private OAuthManager oAuthManager; // or null
private MessageListener<WSResponseBlock> blockListener;
private MessageListener<WSResponseUtxo> addressListener;
private boolean terminated;
public BackendWsApi(IWebsocketClient wsClient, String urlBackend, Optional<OAuthManager> oAuthManager) {
public BackendWsApi(IWebsocketClient wsClient, String urlBackend, OAuthManager oAuthManager) {
this.connected = false;
this.wsClient = wsClient;
this.urlBackend = urlBackend;
this.oAuthManager = oAuthManager != null ? oAuthManager : Optional.empty();
this.oAuthManager = oAuthManager;
if (log.isDebugEnabled()) {
String oAuthStr = oAuthManager.isPresent() ? "yes" : "no";
String oAuthStr = oAuthManager != null ? "yes" : "no";
log.debug("urlBackend=" + urlBackend + ", oAuth=" + oAuthStr);
}
......@@ -206,9 +206,9 @@ public class BackendWsApi {
}
private String getAccessToken() throws Exception {
if (!oAuthManager.isPresent()) {
if (oAuthManager == null) {
return null;
}
return oAuthManager.get().getOAuthAccessToken();
return oAuthManager.getOAuthAccessToken();
}
}
This diff is collapsed.
......@@ -13,11 +13,20 @@ import java.util.Arrays;
import java.util.List;
public class HD_WalletFactoryGeneric {
public static final String BIP39_ENGLISH_SHA256 = "ad90bf3beb7b0eb7e5acd74727dc0da96e0a280a258354e7293fb7e211ac03db";
public static final String BIP39_ENGLISH_FILENAME = "/BIP39/en.txt";
private static HD_WalletFactoryGeneric instance = null;
public static HD_WalletFactoryGeneric getInstance() {
if(instance == null) {
instance = new HD_WalletFactoryGeneric();
}
return instance;
}
private MnemonicCode mc;
public HD_WalletFactoryGeneric() {
this(Bip39English.getInstance().getMnemonicCode());
}
public HD_WalletFactoryGeneric(MnemonicCode mc) {
this.mc = mc;
}
......
package com.samourai.wallet.hd.java;
import com.samourai.wallet.hd.HD_WalletFactoryGeneric;
import java.io.IOException;
import java.io.InputStream;
import org.bitcoinj.crypto.MnemonicCode;
public class HD_WalletFactoryJava extends HD_WalletFactoryGeneric {
private static HD_WalletFactoryJava instance = null;
public HD_WalletFactoryJava() {
super(computeMnemonicCode());
}
public static HD_WalletFactoryJava getInstance() {
if(instance == null) {
instance = new HD_WalletFactoryJava();
}
return instance;
}
public static MnemonicCode computeMnemonicCode() {
try {
InputStream wis = HD_WalletFactoryJava.class
.getResourceAsStream(HD_WalletFactoryJava.BIP39_ENGLISH_FILENAME);
MnemonicCode mc = new MnemonicCode(wis, HD_WalletFactoryJava.BIP39_ENGLISH_SHA256);
wis.close();
return mc;
} catch(IOException e) {
throw new RuntimeException(e);
}
}
}
......@@ -2,7 +2,7 @@ package com.samourai.wallet.util;
import com.samourai.wallet.bip47.rpc.BIP47Wallet;
import com.samourai.wallet.hd.HD_Wallet;
import com.samourai.wallet.hd.java.HD_WalletFactoryJava;
import com.samourai.wallet.hd.HD_WalletFactoryGeneric;
import com.samourai.wallet.segwit.SegwitAddress;
import com.samourai.wallet.segwit.bech32.Bech32UtilGeneric;
import org.bitcoinj.core.*;
......@@ -11,7 +11,7 @@ import org.bitcoinj.wallet.KeyChain;
import org.bitcoinj.wallet.KeyChainGroup;
public class CryptoTestUtil {
private static final HD_WalletFactoryJava hdWalletFactory = HD_WalletFactoryJava.getInstance();
private static final HD_WalletFactoryGeneric hdWalletFactory = HD_WalletFactoryGeneric.getInstance();
private CryptoTestUtil() {}
private static CryptoTestUtil instance = null;
......
abandon
ability
able
about
above
absent
absorb
abstract
absurd
abuse
access
accident
account
accuse
achieve
acid
acoustic
acquire
across
act
action
actor
actress
actual
adapt
add
addict
address
adjust
admit
adult
advance
advice
aerobic
affair
afford
afraid
again
age
agent
agree
ahead
aim
air
airport
aisle
alarm
album
alcohol
alert
alien
all
alley
allow
almost
alone
alpha
already
also
alter
always
amateur
amazing
among
amount
amused
analyst
anchor
ancient
anger
angle
angry
animal
ankle
announce
annual
another
answer
antenna
antique
anxiety
any
apart
apology
appear
apple
approve
april
arch
arctic
area
arena
argue
arm
armed
armor
army
around
arrange
arrest
arrive
arrow
art
artefact
artist
artwork
ask
aspect
assault
asset
assist
assume
asthma
athlete
atom
attack
attend
attitude
attract
auction
audit
august
aunt
author
auto
autumn
average
avocado
avoid
awake
aware
away
awesome
awful
awkward
axis
baby
bachelor
bacon
badge
bag
balance
balcony
ball
bamboo
banana
banner
bar
barely
bargain
barrel
base
basic
basket
battle
beach
bean
beauty
because
become
beef
before
begin
behave
behind
believe
below
belt
bench
benefit
best
betray
better
between
beyond
bicycle
bid
bike
bind
biology
bird
birth
bitter
black
blade
blame
blanket
blast
bleak
bless
blind
blood
blossom
blouse
blue
blur
blush
board
boat
body
boil
bomb
bone
bonus
book
boost
border
boring
borrow
boss
bottom
bounce
box
boy
bracket
brain
brand
brass
brave
bread
breeze
brick
bridge
brief
bright
bring
brisk
broccoli
broken
bronze
broom
brother
brown
brush
bubble
buddy
budget
buffalo
build
bulb
bulk
bullet
bundle
bunker
burden
burger
burst
bus
business
busy
butter
buyer
buzz
cabbage
cabin
cable
cactus
cage
cake
call
calm
camera
camp
can
canal
cancel
candy
cannon
canoe
canvas
canyon
capable
capital
captain
car
carbon
card
cargo
carpet
carry
cart
case
cash
casino
castle
casual
cat
catalog
catch
category
cattle
caught
cause
caution
cave
ceiling
celery
cement
census
century
cereal
certain
chair
chalk
champion
change
chaos
chapter
charge
chase
chat
cheap
check
cheese
chef
cherry
chest
chicken
chief
child
chimney
choice
choose
chronic
chuckle
chunk
churn
cigar
cinnamon
circle
citizen
city
civil
claim
clap
clarify
claw
clay
clean
clerk
clever
click
client
cliff
climb
clinic
clip
clock
clog
close
cloth
cloud
clown
club
clump
cluster
clutch
coach
coast
coconut
code
coffee
coil
coin
collect
color
column
combine
come
comfort
comic
common
company
concert
conduct
confirm
congress
connect
consider
control
convince
cook
cool
copper
copy
coral
core
corn
correct
cost
cotton
couch
country
couple
course
cousin
cover
coyote
crack
cradle
craft
cram
crane
crash
crater
crawl
crazy
cream
credit
creek
crew
cricket
crime
crisp
critic
crop
cross
crouch
crowd
crucial
cruel
cruise
crumble
crunch
crush
cry
crystal
cube
culture
cup
cupboard
curious
current
curtain
curve
cushion
custom
cute
cycle
dad
damage
damp
dance
danger
daring
dash
daughter
dawn
day
deal
debate
debris
decade
december
decide
decline
decorate
decrease
deer
defense
define
defy
degree
delay
deliver
demand
demise
denial
dentist
deny
depart
depend
deposit
depth
deputy
derive
describe
desert
design