From 338481a3def739a7bb500f1f62a1e1433c8c90e2 Mon Sep 17 00:00:00 2001 From: Marcos Rodriguez Date: Thu, 2 Jan 2020 22:02:41 -0600 Subject: [PATCH] TST --- class/abstract-hd-electrum-wallet.js | 6 ++- class/deeplinkSchemaMatch.js | 21 ++++++++++ class/watch-only-wallet.js | 4 +- ios/BlueWallet/BlueWalletRelease.entitlements | 2 + screen/send/details.js | 6 +-- screen/send/psbtWithHardwareWallet.js | 38 +++++++++++++------ screen/send/scanQrAddress.js | 4 +- screen/wallets/details.js | 32 +--------------- 8 files changed, 60 insertions(+), 53 deletions(-) diff --git a/class/abstract-hd-electrum-wallet.js b/class/abstract-hd-electrum-wallet.js index 04371cd58..0d8f287be 100644 --- a/class/abstract-hd-electrum-wallet.js +++ b/class/abstract-hd-electrum-wallet.js @@ -759,7 +759,8 @@ export class AbstractHDElectrumWallet extends AbstractHDWallet { let pubkey = this._getPubkeyByAddress(input.address); let masterFingerprintBuffer; if (masterFingerprint) { - masterFingerprintBuffer = Buffer.from(masterFingerprint, 'hex'); + const hexBuffer = Buffer.from(Number(masterFingerprint).toString(16), 'hex'); + masterFingerprintBuffer = Buffer.from(reverse(hexBuffer)); } else { masterFingerprintBuffer = Buffer.from([0x00, 0x00, 0x00, 0x00]); } @@ -798,7 +799,8 @@ export class AbstractHDElectrumWallet extends AbstractHDWallet { let masterFingerprintBuffer; if (masterFingerprint) { - masterFingerprintBuffer = Buffer.from(masterFingerprint, 'hex'); + const hexBuffer = Buffer.from(Number(masterFingerprint).toString(16), 'hex'); + masterFingerprintBuffer = Buffer.from(reverse(hexBuffer)); } else { masterFingerprintBuffer = Buffer.from([0x00, 0x00, 0x00, 0x00]); } diff --git a/class/deeplinkSchemaMatch.js b/class/deeplinkSchemaMatch.js index 194b0c440..1b452871c 100644 --- a/class/deeplinkSchemaMatch.js +++ b/class/deeplinkSchemaMatch.js @@ -1,6 +1,8 @@ import { AppStorage, LightningCustodianWallet } from './'; import AsyncStorage from '@react-native-community/async-storage'; import BitcoinBIP70TransactionDecode from '../bip70/bip70'; +import RNFS from 'react-native-fs'; +import url from 'url'; const bitcoin = require('bitcoinjs-lib'); const BlueApp = require('../BlueApp'); class DeeplinkSchemaMatch { @@ -30,6 +32,21 @@ class DeeplinkSchemaMatch { if (typeof event.url !== 'string') { return; } + if (DeeplinkSchemaMatch.isPossiblyPSBTFile(event.url)) { + RNFS.readFile(event.url) + .then(file => { + if (file) { + completionHandler({ + routeName: 'PsbtWithHardwareWallet', + params: { + deepLinkPSBT: file, + }, + }); + } + }) + .catch(e => console.warn(e)); + return; + } let isBothBitcoinAndLightning; try { isBothBitcoinAndLightning = DeeplinkSchemaMatch.isBothBitcoinAndLightning(event.url); @@ -146,6 +163,10 @@ class DeeplinkSchemaMatch { } } + static isPossiblyPSBTFile(filePath) { + return filePath.toLowerCase().startsWith('file:') && filePath.toLowerCase().endsWith('-signed.psbt'); + } + static isBitcoinAddress(address) { address = address .replace('bitcoin:', '') diff --git a/class/watch-only-wallet.js b/class/watch-only-wallet.js index 88616a387..868d6405c 100644 --- a/class/watch-only-wallet.js +++ b/class/watch-only-wallet.js @@ -51,9 +51,7 @@ export class WatchOnlyWallet extends LegacyWallet { let masterFingerprint = false; if (parsedSecret.keystore.ckcc_xfp) { // It is a ColdCard Hardware Wallet - masterFingerprint = Buffer.from(Number(parsedSecret.keystore.ckcc_xfp).toString(16), 'hex') - .reverse() - .toString('hex'); + masterFingerprint = Number(parsedSecret.keystore.ckcc_xfp); } this.setSecret(parsedSecret.keystore.xpub); this.masterFingerprint = masterFingerprint; diff --git a/ios/BlueWallet/BlueWalletRelease.entitlements b/ios/BlueWallet/BlueWalletRelease.entitlements index 16a6e901d..51aaf8ba8 100644 --- a/ios/BlueWallet/BlueWalletRelease.entitlements +++ b/ios/BlueWallet/BlueWalletRelease.entitlements @@ -10,6 +10,8 @@ com.apple.developer.ubiquity-container-identifiers + com.apple.developer.ubiquity-kvstore-identifier + $(TeamIdentifierPrefix)$(CFBundleIdentifier) com.apple.security.application-groups group.io.bluewallet.bluewallet diff --git a/screen/send/details.js b/screen/send/details.js index 3b2e07a8d..aa54fa964 100644 --- a/screen/send/details.js +++ b/screen/send/details.js @@ -711,10 +711,11 @@ export default class SendDetails extends Component { importTransaction = async () => { try { - const res = await DocumentPicker.pick(); + const res = await DocumentPicker.pick({ type: ['io.bluewallet.psbt'] }); const file = await RNFS.readFile(res.uri, 'ascii'); const bufferDecoded = Buffer.from(file, 'ascii').toString('base64'); if (bufferDecoded) { + this.setState({ isAdvancedTransactionOptionsVisible: false }); if (this.state.fromWallet.type === WatchOnlyWallet.type) { // watch-only wallets with enabled HW wallet support have different flow. we have to show PSBT to user as QR code // so he can scan it and sign it. then we have to scan it back from user (via camera and QR code), and ask @@ -722,7 +723,7 @@ export default class SendDetails extends Component { this.props.navigation.navigate('PsbtWithHardwareWallet', { memo: this.state.memo, fromWallet: this.state.fromWallet, - psbt: bufferDecoded, + psbt: file, isFirstPSBTAlreadyBase64: true, }); this.setState({ isLoading: false }); @@ -736,7 +737,6 @@ export default class SendDetails extends Component { alert('The selected file does not contain a signed transaction that can be imported.'); } } - this.setState({ isAdvancedTransactionOptionsVisible: false }); }; renderAdvancedTransactionOptionsModal = () => { diff --git a/screen/send/psbtWithHardwareWallet.js b/screen/send/psbtWithHardwareWallet.js index 8ac8c02f6..c848a1428 100644 --- a/screen/send/psbtWithHardwareWallet.js +++ b/screen/send/psbtWithHardwareWallet.js @@ -51,10 +51,7 @@ export default class PsbtWithHardwareWallet extends Component { this.setState({ renderScanner: false }, () => { console.log(ret.data); try { - let Tx = this.state.fromWallet.combinePsbt( - this.state.isFirstPSBTAlreadyBase64 ? this.state.psbt : this.state.psbt.toBase64(), - this.state.isSecondPSBTAlreadyBase64 ? ret.data : ret.data.toBase64(), - ); + let Tx = this.state.fromWallet.combinePsbt(this.state.psbt, ret.data); this.setState({ txhex: Tx.toHex() }); } catch (Err) { alert(Err); @@ -73,9 +70,29 @@ export default class PsbtWithHardwareWallet extends Component { fromWallet: props.navigation.getParam('fromWallet'), isFirstPSBTAlreadyBase64: props.navigation.getParam('isFirstPSBTAlreadyBase64'), isSecondPSBTAlreadyBase64: false, + deepLinkPSBT: undefined, }; } + static getDerivedStateFromProps(nextProps, prevState) { + const deepLinkPSBT = nextProps.navigation.state.params.deepLinkPSBT; + if (deepLinkPSBT) { + try { + let Tx = prevState.fromWallet.combinePsbt( + prevState.isFirstPSBTAlreadyBase64 ? prevState.psbt : prevState.psbt.toBase64(), + deepLinkPSBT, + ); + return { + ...prevState, + txhex: Tx.toHex(), + }; + } catch (Err) { + alert(Err); + } + } + return prevState; + } + componentDidMount() { console.log('send/psbtWithHardwareWallet - componentDidMount'); } @@ -207,8 +224,8 @@ export default class PsbtWithHardwareWallet extends Component { exportPSBT = async () => { const fileName = `${Date.now()}.psbt`; if (Platform.OS === 'ios') { - const filePath = RNFS.TemporaryDirectoryPath + `/${Date.now()}.psbt`; - await RNFS.writeFile(filePath, this.state.isFirstPSBTAlreadyBase64 ? this.state.psbt : this.state.psbt.toBase64(), 'ascii'); + const filePath = RNFS.TemporaryDirectoryPath + `/${fileName}`; + await RNFS.writeFile(filePath, this.state.isFirstPSBTAlreadyBase64 ? this.state.psbt : this.state.psbt.toBase64()); Share.open({ url: 'file://' + filePath, }) @@ -242,11 +259,10 @@ export default class PsbtWithHardwareWallet extends Component { openSignedTransaction = async () => { try { - const res = await DocumentPicker.pick(); - const file = await RNFS.readFile(res.uri, 'ascii'); - const bufferDecoded = Buffer.from(file, 'ascii').toString('base64'); - if (bufferDecoded) { - this.setState({ isSecondPSBTAlreadyBase64: true }, () => this.onBarCodeRead({ data: bufferDecoded })); + const res = await DocumentPicker.pick({ type: ['io.bluewallet.psbt'] }); + const file = await RNFS.readFile(res.uri); + if (file) { + this.setState({ isSecondPSBTAlreadyBase64: true }, () => this.onBarCodeRead({ data: file })); } else { this.setState({ isSecondPSBTAlreadyBase64: false }); throw new Error(); diff --git a/screen/send/scanQrAddress.js b/screen/send/scanQrAddress.js index ebd89bdb5..04ed47011 100644 --- a/screen/send/scanQrAddress.js +++ b/screen/send/scanQrAddress.js @@ -48,9 +48,7 @@ const ScanQRCode = ({ if (fileParsed.keystore.xpub) { let masterFingerprint; if (fileParsed.keystore.ckcc_xfp) { - masterFingerprint = Buffer.from(Number(fileParsed.keystore.ckcc_xfp).toString(16), 'hex') - .reverse() - .toString('hex'); + masterFingerprint = Number(fileParsed.keystore.ckcc_xfp); } onBarCodeRead({ data: fileParsed.keystore.xpub, additionalProperties: { masterFingerprint } }); } else { diff --git a/screen/wallets/details.js b/screen/wallets/details.js index e0fd16e41..ce0f5e2d3 100644 --- a/screen/wallets/details.js +++ b/screen/wallets/details.js @@ -51,13 +51,13 @@ export default class WalletDetails extends Component { super(props); const wallet = props.navigation.getParam('wallet'); + console.warn(wallet.masterFingerprint) const isLoading = true; this.state = { isLoading, walletName: wallet.getLabel(), wallet, useWithHardwareWallet: !!wallet.use_with_hardware_wallet, - masterFingerprint: wallet.masterFingerprint ? String(wallet.masterFingerprint) : '', }; this.props.navigation.setParams({ isLoading, saveAction: () => this.setLabel() }); } @@ -74,7 +74,6 @@ export default class WalletDetails extends Component { this.props.navigation.setParams({ isLoading: true }); this.setState({ isLoading: true }, async () => { this.state.wallet.setLabel(this.state.walletName); - this.state.wallet.masterFingerprint = String(this.state.masterFingerprint); BlueApp.saveToDisk(); alert('Wallet updated.'); this.props.navigation.goBack(null); @@ -192,35 +191,6 @@ export default class WalletDetails extends Component { {this.state.wallet.type === WatchOnlyWallet.type && this.state.wallet.getSecret().startsWith('zpub') && ( <> {'advanced'} - Master Fingerprint - - - { - this.setState({ masterFingerprint: text }); - }} - numberOfLines={1} - style={{ flex: 1, marginHorizontal: 8, minHeight: 33 }} - editable={!this.state.isLoading} - underlineColorAndroid="transparent" - /> - - {'Use with hardware wallet'}