diff --git a/app/package-lock.json b/app/package-lock.json index fd42d971..01a415f8 100644 --- a/app/package-lock.json +++ b/app/package-lock.json @@ -4067,8 +4067,8 @@ } }, "lbryinc": { - "version": "github:lbryio/lbryinc#437260f3dad2321e892388b68749ee6af01aff2b", - "from": "github:lbryio/lbryinc", + "version": "github:lbryio/lbryinc#416f27c945e14deef4c0f4915a72c7bd0f39775e", + "from": "github:lbryio/lbryinc#test-api", "requires": { "bluebird": "^3.5.1", "reselect": "^3.0.0" diff --git a/app/package.json b/app/package.json index df5a09e1..a0bb4782 100644 --- a/app/package.json +++ b/app/package.json @@ -9,7 +9,7 @@ "base-64": "^0.1.0", "@expo/vector-icons": "^8.1.0", "lbry-redux": "lbryio/lbry-redux", - "lbryinc": "lbryio/lbryinc", + "lbryinc": "lbryio/lbryinc#test-api", "lodash": ">=4.17.11", "merge": ">=1.2.1", "moment": "^2.22.1", diff --git a/app/src/constants.js b/app/src/constants.js index 26541ad0..6a978084 100644 --- a/app/src/constants.js +++ b/app/src/constants.js @@ -1,5 +1,11 @@ const Constants = { + FIRST_RUN_PAGE_WELCOME: "welcome", + FIRST_RUN_PAGE_EMAIL_COLLECT: "email-collect", + FIRST_RUN_PAGE_WALLET: "wallet", + FIRST_RUN_PAGE_SKIP_ACCOUNT: "skip-account", + KEY_FIRST_RUN_EMAIL: "firstRunEmail", + KEY_FIRST_RUN_PASSWORD: "firstRunPassword", KEY_SHOULD_VERIFY_EMAIL: "shouldVerifyEmail", KEY_EMAIL_VERIFY_PENDING: "emailVerifyPending", diff --git a/app/src/page/firstRun/internal/email-collect-page.js b/app/src/page/firstRun/internal/email-collect-page.js index aa69ac87..dc6ce7a3 100644 --- a/app/src/page/firstRun/internal/email-collect-page.js +++ b/app/src/page/firstRun/internal/email-collect-page.js @@ -10,9 +10,9 @@ import { TextInput, View } from 'react-native'; -import Colors from '../../../styles/colors'; -import Constants from '../../../constants'; -import firstRunStyle from '../../../styles/firstRun'; +import Colors from 'styles/colors'; +import Constants from 'constants'; +import firstRunStyle from 'styles/firstRun'; class EmailCollectPage extends React.PureComponent { static MAX_STATUS_TRIES = 30; @@ -52,7 +52,7 @@ class EmailCollectPage extends React.PureComponent { this.setState({ authenticationStarted: true, authenticationFailed: false }); NativeModules.VersionInfo.getAppVersion().then(appVersion => { Lbry.status().then(info => { - authenticate(appVersion, Platform.OS) + authenticate(appVersion, Platform.OS); }).catch(error => { if (this.state.statusTries >= EmailCollectPage.MAX_STATUS_TRIES) { this.setState({ authenticationFailed: true }); @@ -98,9 +98,7 @@ class EmailCollectPage extends React.PureComponent { } else { content = ( - Rewards. - You can earn LBRY Credits (LBC) rewards by completing various tasks in the app. - Please provide a valid email address below to be able to claim your rewards. + Setup account - This information is disclosed only to LBRY, Inc. and not to the LBRY network. It is only required to earn LBRY rewards and may be used to sync usage data across devices. + Setting up your account will allow you to earn rewards and keep your content and settings synced.. + This information is disclosed only to LBRY, Inc. and not to the LBRY network. ); } diff --git a/app/src/page/firstRun/internal/skip-account-page.js b/app/src/page/firstRun/internal/skip-account-page.js new file mode 100644 index 00000000..6ad8dfcf --- /dev/null +++ b/app/src/page/firstRun/internal/skip-account-page.js @@ -0,0 +1,37 @@ +import React from 'react'; +import { Lbry } from 'lbry-redux'; +import { + ActivityIndicator, + AsyncStorage, + Linking, + NativeModules, + Platform, + Text, + TextInput, + View +} from 'react-native'; +import Colors from 'styles/colors'; +import Constants from 'constants'; +import firstRunStyle from 'styles/firstRun'; + +class SkipAccountPage extends React.PureComponent { + render() { + const { onSkipAccountViewLayout } = this.props; + + const content = ( + + Are you sure? + If you do not provide an email address, you will not be eligible for free LBC from LBRY, Inc. + Additionally, all of your earnings and settings will be stored locally on this device. Uninstalling the app will delete all of your content and credits permanently. + + ); + + return ( + + {content} + + ); + } +} + +export default SkipAccountPage; diff --git a/app/src/page/firstRun/internal/wallet-page.js b/app/src/page/firstRun/internal/wallet-page.js new file mode 100644 index 00000000..aade76f0 --- /dev/null +++ b/app/src/page/firstRun/internal/wallet-page.js @@ -0,0 +1,75 @@ +import React from 'react'; +import { Lbry } from 'lbry-redux'; +import { + ActivityIndicator, + AsyncStorage, + Linking, + NativeModules, + Platform, + Text, + TextInput, + View +} from 'react-native'; +import Colors from 'styles/colors'; +import Constants from 'constants'; +import firstRunStyle from 'styles/firstRun'; + +class WalletPage extends React.PureComponent { + state = { + password: null, + placeholder: 'passphrase', + statusTries: 0 + }; + + handleChangeText = (text) => { + // save the value to the state email + const { onPasswordChanged } = this.props; + this.setState({ password: text }); + if (onPasswordChanged) { + onPasswordChanged(text); + } + + if (NativeModules.UtilityModule) { + NativeModules.UtilityModule.setSecureValue(Constants.KEY_FIRST_RUN_PASSWORD, text); + // simply set any string value to indicate that a passphrase was set on first run + AsyncStorage.setItem(Constants.KEY_FIRST_RUN_PASSWORD, "true"); + } + } + + render() { + const { onPasswordChanged, onWalletViewLayout } = this.props; + + const content = ( + + Your Wallet + LBRY Credits (or LBC) are tokens which you can use to purchase content and support creators in the digital marketplace. + We use a wallet to store these tokens, which needs to be secured. Please enter a passphrase to secure your wallet. + this.handleChangeText(text)} + onFocus={() => { + if (!this.state.password || this.state.password.length === 0) { + this.setState({ placeholder: '' }); + } + }} + onBlur={() => { + if (!this.state.password || this.state.password.length === 0) { + this.setState({ placeholder: 'passphrase' }); + } + }} + /> + If you forget your passphrase, you will be unable to make use of your LBC. Make sure to use a memorable passphrase. + + ); + + return ( + + {content} + + ); + } +} + +export default WalletPage; diff --git a/app/src/page/firstRun/internal/welcome-page.js b/app/src/page/firstRun/internal/welcome-page.js index abc0eaea..ec079795 100644 --- a/app/src/page/firstRun/internal/welcome-page.js +++ b/app/src/page/firstRun/internal/welcome-page.js @@ -1,8 +1,8 @@ import React from 'react'; import { Lbry } from 'lbry-redux'; import { View, Text, Linking } from 'react-native'; -import Colors from '../../../styles/colors'; -import firstRunStyle from '../../../styles/firstRun'; +import Colors from 'styles/colors'; +import firstRunStyle from 'styles/firstRun'; class WelcomePage extends React.PureComponent { render() { diff --git a/app/src/page/firstRun/view.js b/app/src/page/firstRun/view.js index bfc96aa6..cdd094ce 100644 --- a/app/src/page/firstRun/view.js +++ b/app/src/page/firstRun/view.js @@ -10,16 +10,20 @@ import { View } from 'react-native'; import { NavigationActions, StackActions } from 'react-navigation'; -import Colors from '../../styles/colors'; -import Constants from '../../constants'; +import Colors from 'styles/colors'; +import Constants from 'constants'; +import WalletPage from './internal/wallet-page'; import WelcomePage from './internal/welcome-page'; import EmailCollectPage from './internal/email-collect-page'; -import firstRunStyle from '../../styles/firstRun'; +import SkipAccountPage from './internal/skip-account-page'; +import firstRunStyle from 'styles/firstRun'; class FirstRunScreen extends React.PureComponent { static pages = [ - 'welcome', - 'email-collect' + Constants.FIRST_RUN_PAGE_WELCOME, + Constants.FIRST_RUN_PAGE_EMAIL_COLLECT, + Constants.FIRST_RUN_PAGE_WALLET, + Constants.FIRST_RUN_PAGE_SKIP_ACCOUNT, ]; state = { @@ -28,7 +32,8 @@ class FirstRunScreen extends React.PureComponent { isFirstRun: false, launchUrl: null, showSkip: false, - showBottomContainer: true + showBottomContainer: true, + walletPassword: null }; componentDidMount() { @@ -63,8 +68,9 @@ class FirstRunScreen extends React.PureComponent { if (emailNewErrorMessage) { notify ({ message: String(emailNewErrorMessage), isError: true }); } else { - // Request successful. Navigate to discover. - this.closeFinalPage(); + // Request successful. Navigate to next page (wallet). + this.showNextPage(); + //this.closeFinalPage(); } } } @@ -80,14 +86,29 @@ class FirstRunScreen extends React.PureComponent { navigation.dispatch(resetAction); } + handleBackPressed = () => { + if (this.state.currentPage === Constants.FIRST_RUN_PAGE_SKIP_ACCOUNT) { + this.showPage(Constants.FIRST_RUN_PAGE_EMAIL_COLLECT); + } + } + handleContinuePressed = () => { + const { notify } = this.props; const pageIndex = FirstRunScreen.pages.indexOf(this.state.currentPage); - if (this.state.currentPage !== 'email-collect' && - pageIndex === (FirstRunScreen.pages.length - 1)) { + if (Constants.FIRST_RUN_PAGE_WALLET == this.state.currentPage) { + if (!this.state.walletPassword || this.state.walletPassword.trim().length < 6) { + return notify({ message: 'Your wallet passphrase should be at least 6 characters long' }); + } + + this.closeFinalPage(); + return; + } + + if (this.state.currentPage !== Constants.FIRST_RUN_PAGE_EMAIL_COLLECT && pageIndex === (FirstRunScreen.pages.length - 1)) { this.closeFinalPage(); } else { // TODO: Actions and page verification for specific pages - if (this.state.currentPage === 'email-collect') { + if (this.state.currentPage === Constants.FIRST_RUN_PAGE_EMAIL_COLLECT) { // handle email collect this.handleEmailCollectPageContinue(); } else { @@ -103,10 +124,9 @@ class FirstRunScreen extends React.PureComponent { AsyncStorage.getItem(Constants.KEY_FIRST_RUN_EMAIL).then(email => { if (!email || email.trim().length === 0) { // no email provided. Skip. - if (this.state.currentPage === 'email-collect' && pageIndex === (FirstRunScreen.pages.length - 1)) { - this.closeFinalPage(); - } else { - this.showNextPage(); + if (this.state.currentPage === Constants.FIRST_RUN_PAGE_EMAIL_COLLECT) { + // go directly to the "Are You Sure?" page (instead of "Your Wwallet" first run page) + this.showPage(Constants.FIRST_RUN_PAGE_SKIP_ACCOUNT); } return; } @@ -133,6 +153,13 @@ class FirstRunScreen extends React.PureComponent { } } + showPage(pageName) { + const pageIndex = FirstRunScreen.pages.indexOf(pageName); + if (pageIndex > -1) { + this.setState({ currentPage: pageName }); + } + } + closeFinalPage() { // Final page. Let the app know that first run experience is completed. if (NativeModules.FirstRun) { @@ -144,7 +171,7 @@ class FirstRunScreen extends React.PureComponent { } onEmailChanged = (email) => { - if ('email-collect' == this.state.currentPage) { + if (Constants.FIRST_RUN_PAGE_EMAIL_COLLECT == this.state.currentPage) { this.setState({ showSkip: (!email || email.trim().length === 0) }); } else { this.setState({ showSkip: false }); @@ -158,6 +185,14 @@ class FirstRunScreen extends React.PureComponent { }); } + onWalletPasswordChanged = (password) => { + this.setState({ walletPassword: password }); + } + + onWalletViewLayout = () => { + this.setState({ showBottomContainer: true }); + } + render() { const { authenticate, @@ -178,6 +213,12 @@ class FirstRunScreen extends React.PureComponent { authenticate={authenticate} onEmailChanged={this.onEmailChanged} onEmailViewLayout={this.onEmailViewLayout} />); + } else if (this.state.currentPage === 'wallet') { + page = (); + } else if (this.state.currentPage === 'skip-account') { + page = (); } return ( @@ -188,10 +229,22 @@ class FirstRunScreen extends React.PureComponent { {emailNewPending && } - {!emailNewPending && - - {this.state.showSkip ? 'Skip': 'Continue'} - } + + {this.state.currentPage !== Constants.FIRST_RUN_PAGE_SKIP_ACCOUNT && } + {this.state.currentPage === Constants.FIRST_RUN_PAGE_SKIP_ACCOUNT && + + Setup account + } + + {!emailNewPending && + + {this.state.currentPage === Constants.FIRST_RUN_PAGE_SKIP_ACCOUNT && + Continue without account} + {this.state.currentPage !== Constants.FIRST_RUN_PAGE_SKIP_ACCOUNT && + {this.state.showSkip ? 'No, thanks': 'Continue'}} + } + + } ); diff --git a/app/src/page/splash/view.js b/app/src/page/splash/view.js index defbbf0d..f7a304bf 100644 --- a/app/src/page/splash/view.js +++ b/app/src/page/splash/view.js @@ -12,11 +12,11 @@ import { } from 'react-native'; import { NavigationActions, StackActions } from 'react-navigation'; import { decode as atob } from 'base-64'; -import { navigateToUri } from '../../utils/helper'; +import { navigateToUri } from 'utils/helper'; import PropTypes from 'prop-types'; -import Colors from '../../styles/colors'; -import Constants from '../../constants'; -import splashStyle from '../../styles/splash'; +import Colors from 'styles/colors'; +import Constants from 'constants'; +import splashStyle from 'styles/splash'; const BLOCK_HEIGHT_INTERVAL = 1000 * 60 * 2.5; // every 2.5 minutes @@ -121,6 +121,31 @@ class SplashScreen extends React.PureComponent { } } + finishSplashScreen = () => { + Lbry.resolve({ urls: 'lbry://one' }).then(() => { + // Leave the splash screen + const { + authenticate, + balanceSubscribe, + blacklistedOutpointsSubscribe, + checkSubscriptionsInit, + updateBlockHeight, + navigation, + notify + } = this.props; + + balanceSubscribe(); + blacklistedOutpointsSubscribe(); + checkSubscriptionsInit(); + updateBlockHeight(); + setInterval(() => { updateBlockHeight(); }, BLOCK_HEIGHT_INTERVAL); + NativeModules.VersionInfo.getAppVersion().then(appVersion => { + this.setState({ shouldAuthenticate: true }); + authenticate(appVersion, Platform.OS); + }); + }); + } + _updateStatusCallback(status) { const { deleteCompleteBlobs, fetchSubscriptions } = this.props; const startupStatus = status.startup_status; @@ -141,30 +166,28 @@ class SplashScreen extends React.PureComponent { isRunning: true, }); - // fetch subscriptions, so that we can check for new content after resolve - Lbry.resolve({ urls: 'lbry://one' }).then(() => { - // Leave the splash screen - const { - authenticate, - balanceSubscribe, - blacklistedOutpointsSubscribe, - checkSubscriptionsInit, - updateBlockHeight, - navigation, - notify - } = this.props; + AsyncStorage.getItem(Constants.KEY_FIRST_RUN_PASSWORD).then(passwordSet => { + if ("true" === passwordSet) { + // enrypt the wallet + NativeModules.UtilityModule.getSecureValue(Constants.KEY_FIRST_RUN_PASSWORD).then(password => { + if (!password || password.trim().length === 0) { + this.finishSplashScreen(); + return; + } - balanceSubscribe(); - blacklistedOutpointsSubscribe(); - checkSubscriptionsInit(); - updateBlockHeight(); - setInterval(() => { updateBlockHeight(); }, BLOCK_HEIGHT_INTERVAL); - NativeModules.VersionInfo.getAppVersion().then(appVersion => { - this.setState({ shouldAuthenticate: true }); - authenticate(appVersion, Platform.OS); - }); + Lbry.account_encrypt({ new_password: password }).then((result) => { + AsyncStorage.removeItem(Constants.KEY_FIRST_RUN_PASSWORD); + this.finishSplashScreen(); + }); + }); + + return; + } + + this.finishSplashScreen(); }); + return; } diff --git a/app/src/styles/firstRun.js b/app/src/styles/firstRun.js index ec021f59..274905c1 100644 --- a/app/src/styles/firstRun.js +++ b/app/src/styles/firstRun.js @@ -46,15 +46,30 @@ const firstRunStyle = StyleSheet.create({ marginBottom: 20, textAlign: 'center' }, + passwordInput: { + fontFamily: 'Inter-UI-Regular', + fontSize: 24, + lineHeight: 24, + marginLeft: 32, + marginRight: 32, + marginBottom: 20, + textAlign: 'center' + }, leftButton: { flex: 1, - alignSelf: 'flex-start', + alignSelf: 'flex-end', + paddingBottom: 16, marginLeft: 32, marginRight: 32 }, bottomContainer: { flex: 1 }, + buttonRow: { + flex: 1, + flexDirection: 'row', + justifyContent: 'space-between' + }, actionButton: { backgroundColor: Colors.White, alignSelf: 'center', @@ -71,7 +86,12 @@ const firstRunStyle = StyleSheet.create({ }, buttonText: { fontFamily: 'Inter-UI-Regular', - fontSize: 24, + fontSize: 20, + color: Colors.White + }, + smallButtonText: { + fontFamily: 'Inter-UI-Regular', + fontSize: 14, color: Colors.White }, waiting: { diff --git a/buildozer.spec.sample b/buildozer.spec.sample index c6fba0ef..377e95fc 100644 --- a/buildozer.spec.sample +++ b/buildozer.spec.sample @@ -36,7 +36,7 @@ version.filename = %(source.dir)s/main.py # (list) Application requirements # comma seperated e.g. requirements = sqlite3,kivy -requirements = python3crystax, openssl, sqlite3, hostpython3crystax, android, distro, pyjnius, certifi==2018.4.16, constantly, incremental, miniupnpc==1.9, gmpy, appdirs==1.4.3, argparse==1.2.1, docopt, base58==1.0.0, colorama==0.3.7, dnspython==1.12.0, ecdsa==0.13, envparse, jsonrpclib==0.1.7, jsonschema==2.5.1, pbkdf2, pyyaml, qrcode==5.2.2, requests, seccure==0.3.1.3, attrs==18.1.0, pyasn1, pyasn1-modules, service_identity==16.0.0, six==1.9.0, txJSON-RPC, zope.interface==4.3.3, protobuf==3.6.1, keyring==10.4.0, txupnp, git+https://github.com/lbryio/lbryschema.git#egg=lbryschema, git+https://github.com/lbryio/lbry.git@v0.32.4#egg=lbrynet, git+https://github.com/lbryio/aioupnp.git#egg=aioupnp, asn1crypto, treq==17.8.0, funcsigs, mock, pbr, pyopenssl, twisted, idna, Automat, hyperlink, PyHamcrest, netifaces, cryptography, aiohttp==3.5.4, multidict==4.5.2, idna_ssl==1.1.0, typing_extensions==3.6.5, yarl, chardet==3.0.4, async_timeout==3.0.1, aiorpcX==0.9.0, git+https://github.com/lbryio/torba#egg=torba, coincurve +requirements = python3crystax, openssl, sqlite3, hostpython3crystax, android, distro, pyjnius, certifi==2018.4.16, constantly, incremental, miniupnpc==1.9, gmpy, appdirs==1.4.3, argparse==1.2.1, docopt, base58==1.0.0, colorama==0.3.7, dnspython==1.12.0, ecdsa==0.13, envparse, jsonrpclib==0.1.7, jsonschema==2.5.1, pbkdf2, pyyaml, qrcode==5.2.2, requests, seccure==0.3.1.3, attrs==18.1.0, pyasn1, pyasn1-modules, service_identity==16.0.0, six==1.9.0, txJSON-RPC, zope.interface==4.3.3, protobuf==3.6.1, keyring==10.4.0, txupnp, git+https://github.com/lbryio/lbryschema.git#egg=lbryschema, git+https://github.com/lbryio/lbry.git@v0.34.0#egg=lbrynet, git+https://github.com/lbryio/aioupnp.git#egg=aioupnp, asn1crypto, treq==17.8.0, funcsigs, mock, pbr, pyopenssl, twisted, idna, Automat, hyperlink, PyHamcrest, netifaces, cryptography, aiohttp==3.5.4, multidict==4.5.2, idna_ssl==1.1.0, typing_extensions==3.6.5, yarl, chardet==3.0.4, async_timeout==3.0.1, aiorpcX==0.9.0, git+https://github.com/lbryio/torba#egg=torba, coincurve # (str) Custom source folders for requirements # Sets custom source for any requirements with recipes diff --git a/buildozer.spec.travis b/buildozer.spec.travis index c6fba0ef..377e95fc 100644 --- a/buildozer.spec.travis +++ b/buildozer.spec.travis @@ -36,7 +36,7 @@ version.filename = %(source.dir)s/main.py # (list) Application requirements # comma seperated e.g. requirements = sqlite3,kivy -requirements = python3crystax, openssl, sqlite3, hostpython3crystax, android, distro, pyjnius, certifi==2018.4.16, constantly, incremental, miniupnpc==1.9, gmpy, appdirs==1.4.3, argparse==1.2.1, docopt, base58==1.0.0, colorama==0.3.7, dnspython==1.12.0, ecdsa==0.13, envparse, jsonrpclib==0.1.7, jsonschema==2.5.1, pbkdf2, pyyaml, qrcode==5.2.2, requests, seccure==0.3.1.3, attrs==18.1.0, pyasn1, pyasn1-modules, service_identity==16.0.0, six==1.9.0, txJSON-RPC, zope.interface==4.3.3, protobuf==3.6.1, keyring==10.4.0, txupnp, git+https://github.com/lbryio/lbryschema.git#egg=lbryschema, git+https://github.com/lbryio/lbry.git@v0.32.4#egg=lbrynet, git+https://github.com/lbryio/aioupnp.git#egg=aioupnp, asn1crypto, treq==17.8.0, funcsigs, mock, pbr, pyopenssl, twisted, idna, Automat, hyperlink, PyHamcrest, netifaces, cryptography, aiohttp==3.5.4, multidict==4.5.2, idna_ssl==1.1.0, typing_extensions==3.6.5, yarl, chardet==3.0.4, async_timeout==3.0.1, aiorpcX==0.9.0, git+https://github.com/lbryio/torba#egg=torba, coincurve +requirements = python3crystax, openssl, sqlite3, hostpython3crystax, android, distro, pyjnius, certifi==2018.4.16, constantly, incremental, miniupnpc==1.9, gmpy, appdirs==1.4.3, argparse==1.2.1, docopt, base58==1.0.0, colorama==0.3.7, dnspython==1.12.0, ecdsa==0.13, envparse, jsonrpclib==0.1.7, jsonschema==2.5.1, pbkdf2, pyyaml, qrcode==5.2.2, requests, seccure==0.3.1.3, attrs==18.1.0, pyasn1, pyasn1-modules, service_identity==16.0.0, six==1.9.0, txJSON-RPC, zope.interface==4.3.3, protobuf==3.6.1, keyring==10.4.0, txupnp, git+https://github.com/lbryio/lbryschema.git#egg=lbryschema, git+https://github.com/lbryio/lbry.git@v0.34.0#egg=lbrynet, git+https://github.com/lbryio/aioupnp.git#egg=aioupnp, asn1crypto, treq==17.8.0, funcsigs, mock, pbr, pyopenssl, twisted, idna, Automat, hyperlink, PyHamcrest, netifaces, cryptography, aiohttp==3.5.4, multidict==4.5.2, idna_ssl==1.1.0, typing_extensions==3.6.5, yarl, chardet==3.0.4, async_timeout==3.0.1, aiorpcX==0.9.0, git+https://github.com/lbryio/torba#egg=torba, coincurve # (str) Custom source folders for requirements # Sets custom source for any requirements with recipes diff --git a/buildozer.spec.vagrant b/buildozer.spec.vagrant index c6fba0ef..377e95fc 100644 --- a/buildozer.spec.vagrant +++ b/buildozer.spec.vagrant @@ -36,7 +36,7 @@ version.filename = %(source.dir)s/main.py # (list) Application requirements # comma seperated e.g. requirements = sqlite3,kivy -requirements = python3crystax, openssl, sqlite3, hostpython3crystax, android, distro, pyjnius, certifi==2018.4.16, constantly, incremental, miniupnpc==1.9, gmpy, appdirs==1.4.3, argparse==1.2.1, docopt, base58==1.0.0, colorama==0.3.7, dnspython==1.12.0, ecdsa==0.13, envparse, jsonrpclib==0.1.7, jsonschema==2.5.1, pbkdf2, pyyaml, qrcode==5.2.2, requests, seccure==0.3.1.3, attrs==18.1.0, pyasn1, pyasn1-modules, service_identity==16.0.0, six==1.9.0, txJSON-RPC, zope.interface==4.3.3, protobuf==3.6.1, keyring==10.4.0, txupnp, git+https://github.com/lbryio/lbryschema.git#egg=lbryschema, git+https://github.com/lbryio/lbry.git@v0.32.4#egg=lbrynet, git+https://github.com/lbryio/aioupnp.git#egg=aioupnp, asn1crypto, treq==17.8.0, funcsigs, mock, pbr, pyopenssl, twisted, idna, Automat, hyperlink, PyHamcrest, netifaces, cryptography, aiohttp==3.5.4, multidict==4.5.2, idna_ssl==1.1.0, typing_extensions==3.6.5, yarl, chardet==3.0.4, async_timeout==3.0.1, aiorpcX==0.9.0, git+https://github.com/lbryio/torba#egg=torba, coincurve +requirements = python3crystax, openssl, sqlite3, hostpython3crystax, android, distro, pyjnius, certifi==2018.4.16, constantly, incremental, miniupnpc==1.9, gmpy, appdirs==1.4.3, argparse==1.2.1, docopt, base58==1.0.0, colorama==0.3.7, dnspython==1.12.0, ecdsa==0.13, envparse, jsonrpclib==0.1.7, jsonschema==2.5.1, pbkdf2, pyyaml, qrcode==5.2.2, requests, seccure==0.3.1.3, attrs==18.1.0, pyasn1, pyasn1-modules, service_identity==16.0.0, six==1.9.0, txJSON-RPC, zope.interface==4.3.3, protobuf==3.6.1, keyring==10.4.0, txupnp, git+https://github.com/lbryio/lbryschema.git#egg=lbryschema, git+https://github.com/lbryio/lbry.git@v0.34.0#egg=lbrynet, git+https://github.com/lbryio/aioupnp.git#egg=aioupnp, asn1crypto, treq==17.8.0, funcsigs, mock, pbr, pyopenssl, twisted, idna, Automat, hyperlink, PyHamcrest, netifaces, cryptography, aiohttp==3.5.4, multidict==4.5.2, idna_ssl==1.1.0, typing_extensions==3.6.5, yarl, chardet==3.0.4, async_timeout==3.0.1, aiorpcX==0.9.0, git+https://github.com/lbryio/torba#egg=torba, coincurve # (str) Custom source folders for requirements # Sets custom source for any requirements with recipes diff --git a/src/main/java/io/lbry/browser/Utils.java b/src/main/java/io/lbry/browser/Utils.java index 9b374f52..f41c94d0 100644 --- a/src/main/java/io/lbry/browser/Utils.java +++ b/src/main/java/io/lbry/browser/Utils.java @@ -124,6 +124,35 @@ public final class Utils { return null; } + public static void setSecureValue(String key, String value, Context context, KeyStore keyStore) { + try { + String encryptedValue = encrypt(value.getBytes(), context, keyStore); + SharedPreferences pref = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE); + SharedPreferences.Editor editor = pref.edit(); + editor.putString(key, encryptedValue); + editor.commit(); + } catch (Exception ex) { + Log.e(TAG, "utils - Could not set a secure value", ex); + } + } + + public static String getSecureValue(String key, Context context, KeyStore keyStore) { + try { + SharedPreferences pref = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE); + String encryptedValue = pref.getString(key, null); + if (encryptedValue == null || encryptedValue.trim().length() == 0) { + return null; + } + + byte[] decoded = Base64.decode(encryptedValue, Base64.DEFAULT); + return new String(decrypt(decoded, context, keyStore), Charset.forName("UTF8")); + } catch (Exception ex) { + Log.e(TAG, "utils - Could not retrieve a secure value", ex); + } + + return null; + } + public static void setPassword(String serviceName, String username, String password, Context context, KeyStore keyStore) { try { String encryptedUsername = String.format("u_%s_%s", serviceName, encrypt(username.getBytes(), context, keyStore)); diff --git a/src/main/java/io/lbry/browser/reactmodules/UtilityModule.java b/src/main/java/io/lbry/browser/reactmodules/UtilityModule.java index 518eab02..261a6a19 100644 --- a/src/main/java/io/lbry/browser/reactmodules/UtilityModule.java +++ b/src/main/java/io/lbry/browser/reactmodules/UtilityModule.java @@ -33,6 +33,7 @@ import java.io.IOException; import java.util.HashMap; import java.util.Map; import java.util.Random; +import java.security.KeyStore; import io.lbry.browser.MainActivity; import io.lbry.browser.R; @@ -52,9 +53,16 @@ public class UtilityModule extends ReactContextBaseJavaModule { private Context context; + private KeyStore keyStore; + public UtilityModule(ReactApplicationContext reactContext) { super(reactContext); this.context = reactContext; + try { + this.keyStore = Utils.initKeyStore(context); + } catch (Exception ex) { + // continue without keystore + } } @Override @@ -300,4 +308,21 @@ public class UtilityModule extends ReactContextBaseJavaModule { (Build.BRAND.startsWith("generic") && Build.DEVICE.startsWith("generic")) ); } + + @ReactMethod + public void setSecureValue(String key, String value) { + if (keyStore != null) { + Utils.setSecureValue(key, value, context, keyStore); + } + } + + @ReactMethod + public void getSecureValue(String key, Promise promise) { + if (keyStore == null) { + promise.reject("no keyStore found"); + return; + } + + promise.resolve(Utils.getSecureValue(key, context, keyStore)); + } }