From d9c9ae8dae4ccb8c4fd7f967961bfc061359e03c Mon Sep 17 00:00:00 2001 From: Cody Henthorne Date: Mon, 14 Jun 2021 13:25:50 -0400 Subject: [PATCH] Update MobileCoin dependency and add new configuration. --- app/build.gradle | 2 +- .../payments/MobileCoinMainNetConfig.java | 27 ++++++++++++------- .../payments/MobileCoinTestNetConfig.java | 8 +++--- .../securesms/payments/Wallet.java | 13 ++++----- app/witness-verifications.gradle | 4 +-- 5 files changed, 32 insertions(+), 22 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 884aa1a424..751fa99902 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -379,7 +379,7 @@ dependencies { implementation 'org.whispersystems:signal-client-android:0.8.0' implementation 'com.google.protobuf:protobuf-javalite:3.10.0' - implementation('com.mobilecoin:android-sdk:1.0.0') { + implementation('com.mobilecoin:android-sdk:1.1.0') { exclude group: 'com.google.protobuf' } diff --git a/app/src/main/java/org/thoughtcrime/securesms/payments/MobileCoinMainNetConfig.java b/app/src/main/java/org/thoughtcrime/securesms/payments/MobileCoinMainNetConfig.java index 8767b688b9..d989fadf7c 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/payments/MobileCoinMainNetConfig.java +++ b/app/src/main/java/org/thoughtcrime/securesms/payments/MobileCoinMainNetConfig.java @@ -60,22 +60,31 @@ final class MobileCoinMainNetConfig extends MobileCoinConfig { @Override @NonNull ClientConfig getConfig() { try { - byte[] mrEnclaveConsensus = Hex.toByteArray("e66db38b8a43a33f6c1610d335a361963bb2b31e056af0dc0a895ac6c857cab9"); - byte[] mrEnclaveReport = Hex.toByteArray("709ab90621e3a8d9eb26ed9e2830e091beceebd55fb01c5d7c31d27e83b9b0d1"); - byte[] mrEnclaveLedger = Hex.toByteArray("511eab36de691ded50eb08b173304194da8b9d86bfdd7102001fe6bb279c3666"); - byte[] mrEnclaveView = Hex.toByteArray("ddd59da874fdf3239d5edb1ef251df07a8728c9ef63057dd0b50ade5a9ddb041"); + byte[] mrEnclaveConsensus = Hex.toByteArray("e66db38b8a43a33f6c1610d335a361963bb2b31e056af0dc0a895ac6c857cab9"); + byte[] mrEnclaveConsensusNew = Hex.toByteArray("653228afd2b02a6c28f1dc3b108b1dfa457d170b32ae8ec2978f941bd1655c83"); + byte[] mrEnclaveReport = Hex.toByteArray("709ab90621e3a8d9eb26ed9e2830e091beceebd55fb01c5d7c31d27e83b9b0d1"); + byte[] mrEnclaveReportNew = Hex.toByteArray("f3f7e9a674c55fb2af543513527b6a7872de305bac171783f6716a0bf6919499"); + byte[] mrEnclaveLedger = Hex.toByteArray("511eab36de691ded50eb08b173304194da8b9d86bfdd7102001fe6bb279c3666"); + byte[] mrEnclaveLedgerNew = Hex.toByteArray("89db0d1684fcc98258295c39f4ab68f7de5917ef30f0004d9a86f29930cebbbd"); + byte[] mrEnclaveView = Hex.toByteArray("ddd59da874fdf3239d5edb1ef251df07a8728c9ef63057dd0b50ade5a9ddb041"); + byte[] mrEnclaveViewNew = Hex.toByteArray("dd84abda7f05116e21fcd1ee6361b0ec29445fff0472131eaf37bf06255b567a"); + Set trustRoots = getTrustRoots(R.raw.signal_mobilecoin_authority); ClientConfig config = new ClientConfig(); - String[] hardeningAdvisories = {"INTEL-SA-00334"}; + String[] hardeningAdvisories = { "INTEL-SA-00334" }; config.logAdapter = new MobileCoinLogAdapter(); config.fogView = new ClientConfig.Service().withTrustRoots(trustRoots) - .withVerifier(new Verifier().withMrEnclave(mrEnclaveView, null, hardeningAdvisories)); + .withVerifier(new Verifier().withMrEnclave(mrEnclaveView, null, hardeningAdvisories) + .withMrEnclave(mrEnclaveViewNew, null, hardeningAdvisories)); config.fogLedger = new ClientConfig.Service().withTrustRoots(trustRoots) - .withVerifier(new Verifier().withMrEnclave(mrEnclaveLedger, null, hardeningAdvisories)); + .withVerifier(new Verifier().withMrEnclave(mrEnclaveLedger, null, hardeningAdvisories) + .withMrEnclave(mrEnclaveLedgerNew, null, hardeningAdvisories)); config.consensus = new ClientConfig.Service().withTrustRoots(trustRoots) - .withVerifier(new Verifier().withMrEnclave(mrEnclaveConsensus, null, hardeningAdvisories)); - config.report = new ClientConfig.Service().withVerifier(new Verifier().withMrEnclave(mrEnclaveReport, null, hardeningAdvisories)); + .withVerifier(new Verifier().withMrEnclave(mrEnclaveConsensus, null, hardeningAdvisories) + .withMrEnclave(mrEnclaveConsensusNew, null, hardeningAdvisories)); + config.report = new ClientConfig.Service().withVerifier(new Verifier().withMrEnclave(mrEnclaveReport, null, hardeningAdvisories) + .withMrEnclave(mrEnclaveReportNew, null, hardeningAdvisories)); return config; } catch (AttestationException ex) { throw new IllegalStateException(); diff --git a/app/src/main/java/org/thoughtcrime/securesms/payments/MobileCoinTestNetConfig.java b/app/src/main/java/org/thoughtcrime/securesms/payments/MobileCoinTestNetConfig.java index 24ac563c76..58c16d6f2c 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/payments/MobileCoinTestNetConfig.java +++ b/app/src/main/java/org/thoughtcrime/securesms/payments/MobileCoinTestNetConfig.java @@ -66,10 +66,10 @@ final class MobileCoinTestNetConfig extends MobileCoinConfig { @Override @NonNull ClientConfig getConfig() { try { - byte[] mrEnclaveConsensus = Hex.toByteArray("9268c3220a5260e51e4b586f00e4677fed2b80380f1eeaf775af60f8e880fde8"); - byte[] mrEnclaveReport = Hex.toByteArray("185875464ccd67a879d58181055383505a719b364b12d56d9bef90a40bed07ca"); - byte[] mrEnclaveLedger = Hex.toByteArray("7330c9987f21b91313b39dcdeaa7da8da5ca101c929f5740c207742c762e6dcd"); - byte[] mrEnclaveView = Hex.toByteArray("4e598799faa4bb08a3bd55c0bcda7e1d22e41151d0c591f6c2a48b3562b0881e"); + byte[] mrEnclaveConsensus = Hex.toByteArray("9659ea738275b3999bf1700398b60281be03af5cb399738a89b49ea2496595af"); + byte[] mrEnclaveReport = Hex.toByteArray("a4764346f91979b4906d4ce26102228efe3aba39216dec1e7d22e6b06f919f11"); + byte[] mrEnclaveLedger = Hex.toByteArray("768f7bea6171fb83d775ee8485e4b5fcebf5f664ca7e8b9ceef9c7c21e9d9bf3"); + byte[] mrEnclaveView = Hex.toByteArray("e154f108c7758b5aa7161c3824c176f0c20f63012463bf3cc5651e678f02fb9e"); byte[] mrSigner = Hex.toByteArray("bf7fa957a6a94acb588851bc8767e0ca57706c79f4fc2aa6bcb993012c3c386c"); Set trustRoots = getTrustRoots(R.raw.signal_mobilecoin_authority); ClientConfig config = new ClientConfig(); diff --git a/app/src/main/java/org/thoughtcrime/securesms/payments/Wallet.java b/app/src/main/java/org/thoughtcrime/securesms/payments/Wallet.java index 3df1470c51..f5d511b65d 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/payments/Wallet.java +++ b/app/src/main/java/org/thoughtcrime/securesms/payments/Wallet.java @@ -104,7 +104,8 @@ public final class Wallet { paymentsValues.setMobileCoinFullLedger(Objects.requireNonNull(ledger)); } catch (IOException e) { if ((retryOnAuthFailure && e.getCause() instanceof NetworkException) && - (((NetworkException) e.getCause()).statusCode == 401)) { + (((NetworkException) e.getCause()).statusCode == 401)) + { Log.w(TAG, "Failed to get up to date ledger, due to temp auth failure, retrying", e); return getFullLedger(false); } else { @@ -124,6 +125,7 @@ public final class Wallet { UnsignedLong highestBlockIndex = UnsignedLong.ZERO; final long asOfTimestamp = System.currentTimeMillis(); AccountSnapshot accountSnapshot = mobileCoinClient.getAccountSnapshot(); + final BigInteger minimumTxFee = mobileCoinClient.getOrFetchMinimumTxFee(); if (minimumBlockIndex != null) { long snapshotBlockIndex = accountSnapshot.getBlockIndex().longValue(); @@ -140,8 +142,7 @@ public final class Wallet { .setKeyImage(ByteString.copyFrom(txOut.getKeyImage().getData())) .setPublicKey(ByteString.copyFrom(txOut.getPublicKey().getKeyBytes())); if (txOut.getSpentBlockIndex() != null && - (minimumBlockIndex == null || - txOut.isSpent(UnsignedLong.valueOf(minimumBlockIndex)))) + (minimumBlockIndex == null || txOut.isSpent(UnsignedLong.valueOf(minimumBlockIndex)))) { txoBuilder.setSpentInBlock(getBlock(txOut.getSpentBlockIndex(), txOut.getSpentBlockTimestamp())); builder.addSpentTxos(txoBuilder); @@ -167,7 +168,7 @@ public final class Wallet { } } builder.setBalance(Uint64Util.bigIntegerToUInt64(totalUnspent)) - .setTransferableBalance(Uint64Util.bigIntegerToUInt64(accountSnapshot.getTransferableAmount())) + .setTransferableBalance(Uint64Util.bigIntegerToUInt64(accountSnapshot.getTransferableAmount(minimumTxFee))) .setAsOfTimeStamp(asOfTimestamp) .setHighestBlock(MobileCoinLedger.Block.newBuilder() .setBlockNumber(highestBlockIndex.longValue()) @@ -399,7 +400,7 @@ public final class Wallet { public enum TransactionStatus { COMPLETE, IN_PROGRESS, - FAILED; + FAILED } public static final class TransactionStatusResult { @@ -491,7 +492,7 @@ public final class Wallet { @Override public boolean onStepReady(@NonNull PendingTransaction pendingTransaction, @NonNull BigInteger fee) - throws NetworkException, InvalidTransactionException, AttestationException + throws NetworkException, InvalidTransactionException, AttestationException { Log.i(TAG, "Submitting defrag transaction"); mobileCoinClient.submitTransaction(pendingTransaction.getTransaction()); diff --git a/app/witness-verifications.gradle b/app/witness-verifications.gradle index 334e20514e..016f998a42 100644 --- a/app/witness-verifications.gradle +++ b/app/witness-verifications.gradle @@ -405,8 +405,8 @@ dependencyVerification { ['com.melnykov:floatingactionbutton:1.3.0', '15d58d4fac0f7a288d0e5301bbaf501a146f5b3f5921277811bf99bd3b397263'], - ['com.mobilecoin:android-sdk:1.0.0', - '607b6d2bcbac6f4906fef84404f0e3dc30436eb86239db744f780e9112963359'], + ['com.mobilecoin:android-sdk:1.1.0', + 'a57b73613c8fb255bf735d910268f945a6c690ff24d45cc6034aa34e9a3ae4d5'], ['com.nineoldandroids:library:2.4.0', '68025a14e3e7673d6ad2f95e4b46d78d7d068343aa99256b686fe59de1b3163a'],