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

Commit

Permalink
Merge pull request #12677 from NejcZdovc/hotfix/#12672-seed
Browse files Browse the repository at this point in the history
Fixes recovery seed when you recover wallet with funds
  • Loading branch information
bsclifton authored Jan 18, 2018
2 parents c576b37 + d1a9734 commit 6cb4303
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 3 deletions.
28 changes: 25 additions & 3 deletions app/browser/api/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -1048,8 +1048,7 @@ const onWalletRecovery = (state, error, result) => {
// convert buffer to Uint8Array
let seed = result && result.getIn(['properties', 'wallet', 'keyinfo', 'seed'])
if (seed) {
seed = new Uint8Array(Object.values(seed))
result = result.setIn(['properties', 'wallet', 'keyinfo', 'seed'], seed)
result = result.setIn(['properties', 'wallet', 'keyinfo', 'seed'], uintKeySeed(seed))
}

// remove old QR codes and addresses
Expand Down Expand Up @@ -1679,12 +1678,29 @@ const onBraveryProperties = (state, error, result) => {
}

if (result) {
if (result.properties && result.properties.wallet && result.properties.wallet.keyinfo) {
result.properties.wallet.keyinfo.seed = uintKeySeed(result.properties.wallet.keyinfo.seed)
}
muonWriter(statePath, result)
}

return state
}

const uintKeySeed = (currentSeed) => {
if (currentSeed == null) {
return currentSeed
}

try {
currentSeed.toJSON()
const seed = new Uint8Array(Object.values(currentSeed))
currentSeed = seed
} catch (err) { }

return currentSeed
}

const getBalance = (state) => {
if (!client) return

Expand Down Expand Up @@ -1727,6 +1743,11 @@ const onCallback = (state, result, delayTime) => {
state = ledgerState.setInfoProp(state, 'walletQR', Immutable.Map())
}

const seed = result.getIn(['properties', 'wallet', 'keyinfo', 'seed'])
if (seed) {
result = result.setIn(['properties', 'wallet', 'keyinfo', 'seed'], uintKeySeed(seed))
}

const regularResults = result.toJS()

if (client && result.getIn(['properties', 'wallet'])) {
Expand Down Expand Up @@ -2663,7 +2684,8 @@ const getMethods = () => {
onWalletRecovery,
getStateInfo,
lockInContributionAmount,
callback
callback,
uintKeySeed
}
}

Expand Down
54 changes: 54 additions & 0 deletions test/unit/app/browser/api/ledgerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -1878,4 +1878,58 @@ describe('ledger api unit tests', function () {
})
})
})

describe('uintKeySeed', function () {
const buff = Buffer.from([
32,
87,
30,
26,
223,
56,
224,
31,
213,
136,
248,
95,
136,
56,
250,
78,
179,
121,
255,
162,
195,
39,
143,
136,
18,
140,
49,
216,
221,
154,
78,
173
])

const uint = new Uint8Array(Object.values(buff))

it('null case', function () {
const result = ledgerApi.uintKeySeed()
assert.equal(result, undefined)
})

it('seed is in the correct format', function () {
const result = ledgerApi.uintKeySeed(uint)
assert.deepStrictEqual(result, uint)
})

it('seed needs to be converted', function () {
const result = ledgerApi.uintKeySeed(buff)
assert.deepStrictEqual(result, uint)
})
})
})

0 comments on commit 6cb4303

Please sign in to comment.