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

Commit a637fc7

Browse files
committed
ledger backup and recovery
1 parent c543677 commit a637fc7

13 files changed

+358
-11
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

+47-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,18 @@ 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, (err, body) => {
316+
if (!err) {
317+
console.log('success')
318+
ipc.emit(messages.LEDGER_RECOVER_SUCCEED, body)
319+
} else {
320+
console.log('err')
321+
ipc.emit(messages.LEDGER_RECOVER_FAILED)
322+
}
323+
})
324+
})
297325
}
298326

299327
/*
@@ -571,6 +599,8 @@ var enable = (paymentsEnabled) => {
571599
*/
572600

573601
var publisherInfo = {
602+
options: undefined,
603+
574604
synopsis: undefined,
575605

576606
_internal: {
@@ -601,13 +631,15 @@ var updatePublisherInfo = () => {
601631
syncWriter(pathName(synopsisPath), synopsis, () => {})
602632
publisherInfo.synopsis = synopsisNormalizer()
603633

634+
publisherInfo.options = synopsis.options
635+
604636
if (publisherInfo._internal.debugP) {
605637
data = []
606638
publisherInfo.synopsis.forEach((entry) => {
607639
data.push(underscore.extend(underscore.omit(entry, [ 'faviconURL' ]), { faviconURL: entry.faviconURL && '...' }))
608640
})
609641

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

613645
appActions.updatePublisherInfo(underscore.omit(publisherInfo, [ '_internal' ]))
@@ -871,6 +903,14 @@ var ledgerInfo = {
871903
buyURL: undefined,
872904
bravery: undefined,
873905

906+
// wallet credentials
907+
paymentId: undefined,
908+
passphrase: undefined,
909+
910+
// advanced ledger settings
911+
minDuration: undefined,
912+
minPublisherVisits: undefined,
913+
874914
hasBitcoinHandler: false,
875915

876916
// geoIP/exchange information
@@ -1109,6 +1149,12 @@ var getStateInfo = (state) => {
11091149
var info = state.paymentInfo
11101150
var then = underscore.now() - msecs.year
11111151

1152+
ledgerInfo.paymentId = state.properties.wallet.paymentId
1153+
ledgerInfo.passphrase = state.properties.wallet.keychains.passphrase
1154+
1155+
ledgerInfo.minDuration = synopsis.options.minDuration / msecs.second
1156+
ledgerInfo.minPublisherVisits = synopsis.options.minPublisherVisits
1157+
11121158
ledgerInfo.created = !!state.properties.wallet
11131159
ledgerInfo.creating = !ledgerInfo.created
11141160

@@ -1230,7 +1276,6 @@ var getPaymentInfo = () => {
12301276

12311277
info = underscore.extend(info, underscore.pick(body, [ 'buyURL', 'buyURLExpires', 'balance', 'unconfirmed', 'satoshis' ]))
12321278
info.address = client.getWalletAddress()
1233-
info.passphrase = client.getWalletPassphrase()
12341279
if ((amount) && (currency)) {
12351280
info = underscore.extend(info, { amount: amount, currency: currency })
12361281
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)