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

Commit fbbfbe0

Browse files
bscliftonNejcZdovc
authored andcommitted
Merge pull request #12677 from NejcZdovc/hotfix/#12672-seed
Fixes recovery seed when you recover wallet with funds
1 parent d72f7a3 commit fbbfbe0

File tree

2 files changed

+79
-3
lines changed

2 files changed

+79
-3
lines changed

app/browser/api/ledger.js

+25-3
Original file line numberDiff line numberDiff line change
@@ -1011,8 +1011,7 @@ const onWalletRecovery = (state, error, result) => {
10111011
// convert buffer to Uint8Array
10121012
let seed = result && result.getIn(['properties', 'wallet', 'keyinfo', 'seed'])
10131013
if (seed) {
1014-
seed = new Uint8Array(Object.values(seed))
1015-
result = result.setIn(['properties', 'wallet', 'keyinfo', 'seed'], seed)
1014+
result = result.setIn(['properties', 'wallet', 'keyinfo', 'seed'], uintKeySeed(seed))
10161015
}
10171016

10181017
callback(error, result)
@@ -1637,12 +1636,29 @@ const onBraveryProperties = (state, error, result) => {
16371636
}
16381637

16391638
if (result) {
1639+
if (result.properties && result.properties.wallet && result.properties.wallet.keyinfo) {
1640+
result.properties.wallet.keyinfo.seed = uintKeySeed(result.properties.wallet.keyinfo.seed)
1641+
}
16401642
muonWriter(statePath, result)
16411643
}
16421644

16431645
return state
16441646
}
16451647

1648+
const uintKeySeed = (currentSeed) => {
1649+
if (currentSeed == null) {
1650+
return currentSeed
1651+
}
1652+
1653+
try {
1654+
currentSeed.toJSON()
1655+
const seed = new Uint8Array(Object.values(currentSeed))
1656+
currentSeed = seed
1657+
} catch (err) { }
1658+
1659+
return currentSeed
1660+
}
1661+
16461662
const getBalance = (state) => {
16471663
if (!client) return
16481664

@@ -1678,6 +1694,11 @@ const onCallback = (state, result, delayTime) => {
16781694
return state
16791695
}
16801696

1697+
const seed = result.getIn(['properties', 'wallet', 'keyinfo', 'seed'])
1698+
if (seed) {
1699+
result = result.setIn(['properties', 'wallet', 'keyinfo', 'seed'], uintKeySeed(seed))
1700+
}
1701+
16811702
const regularResults = result.toJS()
16821703

16831704
if (client && result.getIn(['properties', 'wallet'])) {
@@ -2591,7 +2612,8 @@ const getMethods = () => {
25912612
observeTransactions,
25922613
onWalletRecovery,
25932614
getStateInfo,
2594-
lockInContributionAmount
2615+
lockInContributionAmount,
2616+
uintKeySeed
25952617
}
25962618
}
25972619

test/unit/app/browser/api/ledgerTest.js

+54
Original file line numberDiff line numberDiff line change
@@ -1711,4 +1711,58 @@ describe('ledger api unit tests', function () {
17111711
})
17121712
})
17131713
})
1714+
1715+
describe('uintKeySeed', function () {
1716+
const buff = Buffer.from([
1717+
32,
1718+
87,
1719+
30,
1720+
26,
1721+
223,
1722+
56,
1723+
224,
1724+
31,
1725+
213,
1726+
136,
1727+
248,
1728+
95,
1729+
136,
1730+
56,
1731+
250,
1732+
78,
1733+
179,
1734+
121,
1735+
255,
1736+
162,
1737+
195,
1738+
39,
1739+
143,
1740+
136,
1741+
18,
1742+
140,
1743+
49,
1744+
216,
1745+
221,
1746+
154,
1747+
78,
1748+
173
1749+
])
1750+
1751+
const uint = new Uint8Array(Object.values(buff))
1752+
1753+
it('null case', function () {
1754+
const result = ledgerApi.uintKeySeed()
1755+
assert.equal(result, undefined)
1756+
})
1757+
1758+
it('seed is in the correct format', function () {
1759+
const result = ledgerApi.uintKeySeed(uint)
1760+
assert.deepStrictEqual(result, uint)
1761+
})
1762+
1763+
it('seed needs to be converted', function () {
1764+
const result = ledgerApi.uintKeySeed(buff)
1765+
assert.deepStrictEqual(result, uint)
1766+
})
1767+
})
17141768
})

0 commit comments

Comments
 (0)