Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
ledger backup and recovery
Browse files Browse the repository at this point in the history
  • Loading branch information
jkup committed Oct 4, 2016
1 parent c9e23a3 commit 85e9db8
Show file tree
Hide file tree
Showing 13 changed files with 337 additions and 7 deletions.
20 changes: 20 additions & 0 deletions app/extensions/brave/locales/en-US/preferences.properties
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ bitcoinVisitAccount=Transfer BTC
bitcoinBalance=Please transfer: 
bitcoinWalletNotAvailable=Wallet information not available. :(
usd=$
cancel=Cancel
done=Done
off=off
on=on
Expand All @@ -71,6 +72,11 @@ add=Fund with debit/credit
transferTime=Transfer may take up to 40 minutes
addFundsTitle=Add funds…
addFunds=Three ways to add funds to your Brave Wallet
copy=Copy
firstKey=Key 1
secondKey=Key 2
firstRecoveryKey=Recovery Key 1
secondRecoveryKey=Recovery Key 2
copyToClipboard=Copy to clipboard
smartphoneTitle=Use your smartphone app to transfer Bitcoin
displayQRCode=Display QR code
Expand Down Expand Up @@ -110,6 +116,20 @@ offerSearchSuggestions=Autocomplete search term as you type
doNotTrackTitle=Do Not Track
doNotTrack=Send a 'Do Not Track' header with browsing requests (requires browser restart)
blockCanvasFingerprinting=Fingerprinting Protection (may break some websites)
advancedSettings=Advanced Settings...
advancedSettingsTitle=Advanced Settings for Brave Payments
ledgerRecoveryTitle=Recover your Brave wallet
ledgerRecoverySubtitle=Enter your recovery keys below
ledgerRecoveryContent=The balance of the recovered wallet will be transferred to your new Brave wallet. The old wallet will still exist as an empty wallet.
ledgerBackupTitle=Backup your Brave wallet
ledgerBackupContent=Below, you will find the anonymized recovery keys that are required if you ever lose access to this computer. We recommend that you print or save these keys and store them in a safe place, like your local safe deposit box, or under your mattress. It's really up to you!
minimumPageTimeSetting=Minimum page time before logging a visit
minimumVisitsSetting=Minimum visits for publisher relevancy
backupLedger=Backup your wallet
recoverLedger=Recover your wallet
recover=Recover
printKeys=Print keys
saveRecoveryFile=Save recovery file...
advancedPrivacySettings=Advanced Privacy Settings:
braveryDefaults=Bravery Defaults
blockAttackSites=Block reported attack sites (not available yet)
Expand Down
44 changes: 42 additions & 2 deletions app/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,25 @@ const doAction = (action) => {
case settings.PAYMENTS_ENABLED:
initialize(action.value, 'changeSettingPaymentsEnabled')
break

case settings.PAYMENTS_CONTRIBUTION_AMOUNT:
setPaymentInfo(action.value)
break

case settings.MINIMUM_VISIT_TIME:
if (action.value <= 0) break

synopsis.options.minDuration = action.value
updatePublisherInfo()
break

case settings.MINIMUM_VISTS:
if (action.value <= 0) break

synopsis.options.minPublisherVisits = action.value
updatePublisherInfo()
break

default:
break
}
Expand Down Expand Up @@ -294,6 +310,13 @@ if (ipc) {
if (balanceTimeoutId) clearTimeout(balanceTimeoutId)
balanceTimeoutId = setTimeout(getBalance, 5 * msecs.second)
})

ipc.on(messages.LEDGER_RECOVER_WALLET, (firstRecoveryKey, secondRecoveryKey) => {
console.log('in here')
ledgerClient.recoverWallet(firstRecoveryKey, secondRecoveryKey, (body, body2) => {
console.log(body, body2)
})
})
}

/*
Expand Down Expand Up @@ -569,6 +592,8 @@ var enable = (paymentsEnabled) => {
*/

var publisherInfo = {
options: undefined,

synopsis: undefined,

_internal: {
Expand Down Expand Up @@ -599,13 +624,15 @@ var updatePublisherInfo = () => {
syncWriter(pathName(synopsisPath), synopsis, () => {})
publisherInfo.synopsis = synopsisNormalizer()

publisherInfo.options = synopsis.options

if (publisherInfo._internal.debugP) {
data = []
publisherInfo.synopsis.forEach((entry) => {
data.push(underscore.extend(underscore.omit(entry, [ 'faviconURL' ]), { faviconURL: entry.faviconURL && '...' }))
})

console.log('\nupdatePublisherInfo: ' + JSON.stringify(data, null, 2))
console.log('\nupdatePublisherInfo: ' + JSON.stringify({ options: publisherInfo.options, synopsis: data }, null, 2))
}

appActions.updatePublisherInfo(underscore.omit(publisherInfo, [ '_internal' ]))
Expand Down Expand Up @@ -869,6 +896,14 @@ var ledgerInfo = {
buyURL: undefined,
bravery: undefined,

// wallet credentials
paymentId: undefined,
passphrase: undefined,

// advanced ledger settings
minDuration: undefined,
minPublisherVisits: undefined,

hasBitcoinHandler: false,

// geoIP/exchange information
Expand Down Expand Up @@ -1107,6 +1142,12 @@ var getStateInfo = (state) => {
var info = state.paymentInfo
var then = underscore.now() - msecs.year

ledgerInfo.paymentId = state.properties.wallet.paymentId
ledgerInfo.passphrase = state.properties.wallet.keychains.passphrase

ledgerInfo.minDuration = synopsis.options.minDuration / msecs.second
ledgerInfo.minPublisherVisits = synopsis.options.minPublisherVisits

ledgerInfo.created = !!state.properties.wallet
ledgerInfo.creating = !ledgerInfo.created

Expand Down Expand Up @@ -1228,7 +1269,6 @@ var getPaymentInfo = () => {

info = underscore.extend(info, underscore.pick(body, [ 'buyURL', 'buyURLExpires', 'balance', 'unconfirmed', 'satoshis' ]))
info.address = client.getWalletAddress()
info.passphrase = client.getWalletPassphrase()
if ((amount) && (currency)) {
info = underscore.extend(info, { amount: amount, currency: currency })
if ((body.rates) && (body.rates[currency])) {
Expand Down
10 changes: 7 additions & 3 deletions docs/state.md
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,8 @@ WindowStore
error: object // error object returned
}
},
publisherInfo: [ // one entry for each publisher having a non-zero `score`
{
publisherInfo: {
synopsis: [ { // one entry for each publisher having a non-zero `score`
rank: number, // i.e., 1, 2, 3, ...
verified: boolean, // there is a verified wallet for this publisher
site: string, // publisher name, e.g., "wikipedia.org"
Expand All @@ -493,8 +493,12 @@ WindowStore
percentage: number, // i.e., 0, 1, ... 100
publisherURL: string, // publisher site, e.g., "https://wikipedia.org/"
faviconURL: string // i.e., "data:image/...;base64,..."
} ],
options: {
minDuration: number, // e.g., 8000 for 8 seconds
minPublisherVisits: number // e.g., 0
}
],
}
autofillAddressDetail: {
name: string,
organization: string,
Expand Down
32 changes: 32 additions & 0 deletions js/about/aboutActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,38 @@ const AboutActions = {
})
},

/**
* Generates a file with the users backup keys
*/
generateKeyFile: function (backupAction) {
AboutActions.dispatchAction({
actionType: AppConstants.APP_BACKUP_KEYS,
backupAction
})
},

/**
* Recover wallet by merging old wallet into new one
*/
recoverWallet: function (firstRecoveryKey, secondRecoveryKey) {
AboutActions.dispatchAction({
actionType: AppConstants.APP_RECOVER_WALLET,
firstRecoveryKey,
secondRecoveryKey
})
},

/**
* Loads a URL in a new frame in a safe way.
* It is important that it is not a simple anchor because it should not
* preserve the about preload script. See #672
*/
viewKeyFile: function () {
AboutActions.dispatchAction({
actionType: WindowConstants.WINDOW_VIEW_KEY
})
},

/**
* Click through a certificate error.
*
Expand Down
Loading

0 comments on commit 85e9db8

Please sign in to comment.