use of com.toshi.crypto.HDWallet in project toshi-android-client by toshiapp.
the class SignInPresenter method tryCreateWallet.
private void tryCreateWallet(final String masterSeed) {
if (this.onGoingTask)
return;
startLoadingTask();
final Subscription sub = new HDWallet().createFromMasterSeed(masterSeed).flatMapCompletable(this::initWallet).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).doOnCompleted(AppPrefs.INSTANCE::setHasBackedUpPhrase).subscribe(this::handleWalletSuccess, this::handleWalletError);
this.subscriptions.add(sub);
}
use of com.toshi.crypto.HDWallet in project toshi-android-client by toshiapp.
the class SigningInterceptor method intercept.
@Override
public Response intercept(final Chain chain) throws IOException {
final Request original = chain.request();
final String timestamp = original.url().queryParameter(TIMESTAMP_QUERY_PARAMETER);
if (timestamp == null) {
// Only signing outgoing requests that have a timestamp argument
return chain.proceed(original);
}
final HDWallet wallet = getWallet();
if (wallet == null) {
// Only signing outgoing requests that have a timestamp argument
return chain.proceed(original);
}
final Buffer buffer = new Buffer();
final String method = original.method();
final String path = original.url().encodedPath();
String encodedBody = "";
if (original.body() != null) {
original.body().writeTo(buffer);
final byte[] body = buffer.readByteArray();
final byte[] hashedBody = HashUtil.sha3(body);
encodedBody = Base64.encodeToString(hashedBody, Base64.NO_WRAP);
}
final String forSigning = method + "\n" + path + "\n" + timestamp + "\n" + encodedBody;
final String signature = wallet.signIdentity(forSigning);
final HttpUrl url = chain.request().url().newBuilder().removeAllQueryParameters(TIMESTAMP_QUERY_PARAMETER).build();
final Request request = original.newBuilder().removeHeader(TIMESTAMP_QUERY_PARAMETER).method(original.method(), original.body()).addHeader(TIMESTAMP_HEADER, timestamp).addHeader(SIGNATURE_HEADER, signature).addHeader(ADDRESS_HEADER, wallet.getOwnerAddress()).url(url).build();
return chain.proceed(request);
}
Aggregations