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

Commit fc02edc

Browse files
committed
ledger backup and recovery
1 parent d623694 commit fc02edc

13 files changed

+343
-9
lines changed

app/extensions/brave/locales/en-US/preferences.properties

+20
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ bitcoinVisitAccount=Transfer BTC
5959
bitcoinBalance=Please transfer: 
6060
bitcoinWalletNotAvailable=Wallet information not available. :(
6161
usd=$
62+
cancel=Cancel
6263
done=Done
6364
off=off
6465
on=on
@@ -71,6 +72,11 @@ add=Fund with debit/credit
7172
transferTime=Transfer may take up to 40 minutes
7273
addFundsTitle=Add funds…
7374
addFunds=Three ways to add funds to your Brave Wallet
75+
copy=Copy
76+
firstKey=Key 1
77+
secondKey=Key 2
78+
firstRecoveryKey=Recovery Key 1
79+
secondRecoveryKey=Recovery Key 2
7480
copyToClipboard=Copy to clipboard
7581
smartphoneTitle=Use your smartphone app to transfer Bitcoin
7682
displayQRCode=Display QR code
@@ -110,6 +116,20 @@ offerSearchSuggestions=Autocomplete search term as you type
110116
doNotTrackTitle=Do Not Track
111117
doNotTrack=Send a 'Do Not Track' header with browsing requests (requires browser restart)
112118
blockCanvasFingerprinting=Fingerprinting Protection (may break some websites)
119+
advancedSettings=Advanced Settings...
120+
advancedSettingsTitle=Advanced Settings for Brave Payments
121+
ledgerRecoveryTitle=Recover your Brave wallet
122+
ledgerRecoverySubtitle=Enter your recovery keys below
123+
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.
124+
ledgerBackupTitle=Backup your Brave wallet
125+
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!
126+
minimumPageTimeSetting=Minimum page time before logging a visit
127+
minimumVisitsSetting=Minimum visits for publisher relevancy
128+
backupLedger=Backup your wallet
129+
recoverLedger=Recover your wallet
130+
recover=Recover
131+
printKeys=Print keys
132+
saveRecoveryFile=Save recovery file...
113133
advancedPrivacySettings=Advanced Privacy Settings:
114134
braveryDefaults=Bravery Defaults
115135
blockAttackSites=Block reported attack sites (not available yet)

app/ledger.js

+45-2
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,25 @@ const doAction = (action) => {
133133
case settings.PAYMENTS_ENABLED:
134134
initialize(action.value)
135135
break
136+
136137
case settings.PAYMENTS_CONTRIBUTION_AMOUNT:
137138
setPaymentInfo(action.value)
138139
break
140+
141+
case settings.MINIMUM_VISIT_TIME:
142+
if (action.value <= 0) break
143+
144+
synopsis.options.minDuration = action.value
145+
updatePublisherInfo()
146+
break
147+
148+
case settings.MINIMUM_VISTS:
149+
if (action.value <= 0) break
150+
151+
synopsis.options.minPublisherVisits = action.value
152+
updatePublisherInfo()
153+
break
154+
139155
default:
140156
break
141157
}
@@ -294,6 +310,16 @@ if (ipc) {
294310
if (balanceTimeoutId) clearTimeout(balanceTimeoutId)
295311
balanceTimeoutId = setTimeout(getBalance, 5 * msecs.second)
296312
})
313+
314+
ipc.on(messages.LEDGER_RECOVER_WALLET, (firstRecoveryKey, secondRecoveryKey) => {
315+
client.recoverWallet(firstRecoveryKey, secondRecoveryKey, (response1, response2) => {
316+
if (!response1) {
317+
console.log('it worked!')
318+
} else {
319+
console.log('it failed!')
320+
}
321+
})
322+
})
297323
}
298324

299325
/*
@@ -571,6 +597,8 @@ var enable = (paymentsEnabled) => {
571597
*/
572598

573599
var publisherInfo = {
600+
options: undefined,
601+
574602
synopsis: undefined,
575603

576604
_internal: {
@@ -601,13 +629,15 @@ var updatePublisherInfo = () => {
601629
syncWriter(pathName(synopsisPath), synopsis, () => {})
602630
publisherInfo.synopsis = synopsisNormalizer()
603631

632+
publisherInfo.options = synopsis.options
633+
604634
if (publisherInfo._internal.debugP) {
605635
data = []
606636
publisherInfo.synopsis.forEach((entry) => {
607637
data.push(underscore.extend(underscore.omit(entry, [ 'faviconURL' ]), { faviconURL: entry.faviconURL && '...' }))
608638
})
609639

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

613643
appActions.updatePublisherInfo(underscore.omit(publisherInfo, [ '_internal' ]))
@@ -871,6 +901,14 @@ var ledgerInfo = {
871901
buyURL: undefined,
872902
bravery: undefined,
873903

904+
// wallet credentials
905+
paymentId: undefined,
906+
passphrase: undefined,
907+
908+
// advanced ledger settings
909+
minDuration: undefined,
910+
minPublisherVisits: undefined,
911+
874912
hasBitcoinHandler: false,
875913

876914
// geoIP/exchange information
@@ -1109,6 +1147,12 @@ var getStateInfo = (state) => {
11091147
var info = state.paymentInfo
11101148
var then = underscore.now() - msecs.year
11111149

1150+
ledgerInfo.paymentId = state.properties.wallet.paymentId
1151+
ledgerInfo.passphrase = state.properties.wallet.keychains.passphrase
1152+
1153+
ledgerInfo.minDuration = synopsis.options.minDuration / msecs.second
1154+
ledgerInfo.minPublisherVisits = synopsis.options.minPublisherVisits
1155+
11121156
ledgerInfo.created = !!state.properties.wallet
11131157
ledgerInfo.creating = !ledgerInfo.created
11141158

@@ -1230,7 +1274,6 @@ var getPaymentInfo = () => {
12301274

12311275
info = underscore.extend(info, underscore.pick(body, [ 'buyURL', 'buyURLExpires', 'balance', 'unconfirmed', 'satoshis' ]))
12321276
info.address = client.getWalletAddress()
1233-
info.passphrase = client.getWalletPassphrase()
12341277
if ((amount) && (currency)) {
12351278
info = underscore.extend(info, { amount: amount, currency: currency })
12361279
if ((body.rates) && (body.rates[currency])) {

docs/state.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,8 @@ WindowStore
463463
error: object // error object returned
464464
}
465465
},
466-
publisherInfo: [ // one entry for each publisher having a non-zero `score`
467-
{
466+
publisherInfo: {
467+
synopsis: [ { // one entry for each publisher having a non-zero `score`
468468
rank: number, // i.e., 1, 2, 3, ...
469469
verified: boolean, // there is a verified wallet for this publisher
470470
site: string, // publisher name, e.g., "wikipedia.org"
@@ -478,8 +478,12 @@ WindowStore
478478
percentage: number, // i.e., 0, 1, ... 100
479479
publisherURL: string, // publisher site, e.g., "https://wikipedia.org/"
480480
faviconURL: string // i.e., "data:image/...;base64,..."
481+
} ],
482+
options: {
483+
minDuration: number, // e.g., 8000 for 8 seconds
484+
minPublisherVisits: number // e.g., 0
481485
}
482-
],
486+
}
483487
autofillAddressDetail: {
484488
name: string,
485489
organization: string,

js/about/aboutActions.js

+32
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,38 @@ const aboutActions = {
8787
})
8888
},
8989

90+
/**
91+
* Generates a file with the users backup keys
92+
*/
93+
generateKeyFile: function (backupAction) {
94+
AboutActions.dispatchAction({
95+
actionType: AppConstants.APP_BACKUP_KEYS,
96+
backupAction
97+
})
98+
},
99+
100+
/**
101+
* Recover wallet by merging old wallet into new one
102+
*/
103+
recoverWallet: function (firstRecoveryKey, secondRecoveryKey) {
104+
AboutActions.dispatchAction({
105+
actionType: AppConstants.APP_RECOVER_WALLET,
106+
firstRecoveryKey,
107+
secondRecoveryKey
108+
})
109+
},
110+
111+
/**
112+
* Loads a URL in a new frame in a safe way.
113+
* It is important that it is not a simple anchor because it should not
114+
* preserve the about preload script. See #672
115+
*/
116+
viewKeyFile: function () {
117+
AboutActions.dispatchAction({
118+
actionType: WindowConstants.WINDOW_VIEW_KEY
119+
})
120+
},
121+
90122
/**
91123
* Click through a certificate error.
92124
*

0 commit comments

Comments
 (0)