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

Commit 85e9db8

Browse files
committed
ledger backup and recovery
1 parent c9e23a3 commit 85e9db8

13 files changed

+337
-7
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

+42-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, 'changeSettingPaymentsEnabled')
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,13 @@ 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+
console.log('in here')
316+
ledgerClient.recoverWallet(firstRecoveryKey, secondRecoveryKey, (body, body2) => {
317+
console.log(body, body2)
318+
})
319+
})
297320
}
298321

299322
/*
@@ -569,6 +592,8 @@ var enable = (paymentsEnabled) => {
569592
*/
570593

571594
var publisherInfo = {
595+
options: undefined,
596+
572597
synopsis: undefined,
573598

574599
_internal: {
@@ -599,13 +624,15 @@ var updatePublisherInfo = () => {
599624
syncWriter(pathName(synopsisPath), synopsis, () => {})
600625
publisherInfo.synopsis = synopsisNormalizer()
601626

627+
publisherInfo.options = synopsis.options
628+
602629
if (publisherInfo._internal.debugP) {
603630
data = []
604631
publisherInfo.synopsis.forEach((entry) => {
605632
data.push(underscore.extend(underscore.omit(entry, [ 'faviconURL' ]), { faviconURL: entry.faviconURL && '...' }))
606633
})
607634

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

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

899+
// wallet credentials
900+
paymentId: undefined,
901+
passphrase: undefined,
902+
903+
// advanced ledger settings
904+
minDuration: undefined,
905+
minPublisherVisits: undefined,
906+
872907
hasBitcoinHandler: false,
873908

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

1145+
ledgerInfo.paymentId = state.properties.wallet.paymentId
1146+
ledgerInfo.passphrase = state.properties.wallet.keychains.passphrase
1147+
1148+
ledgerInfo.minDuration = synopsis.options.minDuration / msecs.second
1149+
ledgerInfo.minPublisherVisits = synopsis.options.minPublisherVisits
1150+
11101151
ledgerInfo.created = !!state.properties.wallet
11111152
ledgerInfo.creating = !ledgerInfo.created
11121153

@@ -1228,7 +1269,6 @@ var getPaymentInfo = () => {
12281269

12291270
info = underscore.extend(info, underscore.pick(body, [ 'buyURL', 'buyURLExpires', 'balance', 'unconfirmed', 'satoshis' ]))
12301271
info.address = client.getWalletAddress()
1231-
info.passphrase = client.getWalletPassphrase()
12321272
if ((amount) && (currency)) {
12331273
info = underscore.extend(info, { amount: amount, currency: currency })
12341274
if ((body.rates) && (body.rates[currency])) {

docs/state.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -478,8 +478,8 @@ WindowStore
478478
error: object // error object returned
479479
}
480480
},
481-
publisherInfo: [ // one entry for each publisher having a non-zero `score`
482-
{
481+
publisherInfo: {
482+
synopsis: [ { // one entry for each publisher having a non-zero `score`
483483
rank: number, // i.e., 1, 2, 3, ...
484484
verified: boolean, // there is a verified wallet for this publisher
485485
site: string, // publisher name, e.g., "wikipedia.org"
@@ -493,8 +493,12 @@ WindowStore
493493
percentage: number, // i.e., 0, 1, ... 100
494494
publisherURL: string, // publisher site, e.g., "https://wikipedia.org/"
495495
faviconURL: string // i.e., "data:image/...;base64,..."
496+
} ],
497+
options: {
498+
minDuration: number, // e.g., 8000 for 8 seconds
499+
minPublisherVisits: number // e.g., 0
496500
}
497-
],
501+
}
498502
autofillAddressDetail: {
499503
name: string,
500504
organization: string,

js/about/aboutActions.js

+32
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,38 @@ const AboutActions = {
7575
})
7676
},
7777

78+
/**
79+
* Generates a file with the users backup keys
80+
*/
81+
generateKeyFile: function (backupAction) {
82+
AboutActions.dispatchAction({
83+
actionType: AppConstants.APP_BACKUP_KEYS,
84+
backupAction
85+
})
86+
},
87+
88+
/**
89+
* Recover wallet by merging old wallet into new one
90+
*/
91+
recoverWallet: function (firstRecoveryKey, secondRecoveryKey) {
92+
AboutActions.dispatchAction({
93+
actionType: AppConstants.APP_RECOVER_WALLET,
94+
firstRecoveryKey,
95+
secondRecoveryKey
96+
})
97+
},
98+
99+
/**
100+
* Loads a URL in a new frame in a safe way.
101+
* It is important that it is not a simple anchor because it should not
102+
* preserve the about preload script. See #672
103+
*/
104+
viewKeyFile: function () {
105+
AboutActions.dispatchAction({
106+
actionType: WindowConstants.WINDOW_VIEW_KEY
107+
})
108+
},
109+
78110
/**
79111
* Click through a certificate error.
80112
*

0 commit comments

Comments
 (0)