Skip to content
This repository has been archived by the owner on Nov 27, 2018. It is now read-only.

Commit

Permalink
0.8.128: new recovery algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
mrose17 committed Feb 16, 2017
1 parent bb62249 commit d2eed50
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
25 changes: 19 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,16 +348,29 @@ Client.prototype.report = function () {
Client.prototype.recoverWallet = function (recoveryId, passPhrase, callback) {
var self = this

var path, payload
var path

path = '/v1/wallet/' + self.state.properties.wallet.paymentId + '/recover'
payload = { recoveryId: recoveryId, passPhrase: passPhrase }
self.roundtrip({ path: path, method: 'PUT', payload: payload }, function (err, response, body) {
self._log('recoverWallet', { method: 'PUT', path: '/v1/wallet/.../recover', errP: !!err })
path = '/v2/wallet/' + recoveryId + '/recover'
self.roundtrip({ path: path, method: 'GET' }, function (err, response, body) {
self._log('recoverWallet', { method: 'GET', path: '/v2/wallet/.../recover', errP: !!err })
if (err) return callback(err)

self._log('recoverWallet', body)
callback(null, body)

if ((!body.address) || (!body.keychains) || (!body.keychains.user) || (!body.keychains.user.xpub) ||
(!body.keychains.user.encryptedXprv) || (!body.keychains.user.path)) return callback(new Error('invalid response'))

try {
underscore.extend(body.keychains.user,
{ xprv: bitgo.decrypt({ password: passPhrase, input: body.keychains.user.encryptedXprv }),
passphrase: passPhrase })
} catch (ex) {
return callback(new Error('invalid passphrase'))
}

self.state.properties.wallet = underscore.defaults({ paymentId: recoveryId }, underscore.omit(body, [ 'satoshis' ]))

callback(null, self.state, body.satoshis)
})
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ledger-client",
"version": "0.8.127",
"version": "0.8.128",
"description": "An example of client code for the Brave ledger.",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit d2eed50

Please sign in to comment.