-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1771 from oasisprotocol/lw/migration-utils
Add utils for persisted state migration from old extension
- Loading branch information
Showing
11 changed files
with
552 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add utils for migration from V0 encrypted state to RootState |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
172 changes: 172 additions & 0 deletions
172
src/utils/__tests__/__snapshots__/walletExtensionV0.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`decryptWithPasswordV0 1`] = ` | ||
{ | ||
"invalidPrivateKeys": [ | ||
{ | ||
"address": "oasis1qpu7j3q3lhy0al2d4nspy0gmy9msy2s2yvap66r7", | ||
"name": "bad privatekey1", | ||
"privateKeyWithTypos": "1ab9bf560d4ca4044f31b99da44c5503d0e48f508c892cd82c5c4a9cfc76d1fb3e3a7c47f18a67b70410105d9444766269bb1a1e418b1cdf3a6aba8f18923d3a", | ||
}, | ||
], | ||
"language": "en", | ||
"mnemonic": "among scrap refuse hungry remove unhappy crack horn half cruel skull project dentist poet design paper eternal stool tomato cabin helmet funny victory happy", | ||
"state": { | ||
"contacts": { | ||
"oasis1qq3xrq0urs8qcffhvmhfhz4p0mu7ewc8rscnlwxe": { | ||
"address": "oasis1qq3xrq0urs8qcffhvmhfhz4p0mu7ewc8rscnlwxe", | ||
"name": "stakefish", | ||
}, | ||
"oasis1qqekv2ymgzmd8j2s2u7g0hhc7e77e654kvwqtjwm": { | ||
"address": "oasis1qqekv2ymgzmd8j2s2u7g0hhc7e77e654kvwqtjwm", | ||
"name": "Binance", | ||
}, | ||
}, | ||
"evmAccounts": { | ||
"0xbA1b346233E5bB5b44f5B4aC6bF224069f427b18": { | ||
"ethAddress": "0xbA1b346233E5bB5b44f5B4aC6bF224069f427b18", | ||
"ethPrivateKey": "6593a788d944bb3e25357df140fac5b0e6273f1500a3b37d6513bf9e9807afe2", | ||
}, | ||
}, | ||
"network": { | ||
"chainContext": "", | ||
"epoch": 0, | ||
"minimumStakingAmount": 0, | ||
"selectedNetwork": "local", | ||
"ticker": "", | ||
}, | ||
"theme": { | ||
"selected": "light", | ||
}, | ||
"wallet": { | ||
"selectedWallet": "oasis1qq30ejf9puuc6qnrazmy9dmn7f3gessveum5wnr6", | ||
"wallets": { | ||
"oasis1qpfltmpdyjvv88x9n7x0uvspjdtxycz9gc9zg429": { | ||
"address": "oasis1qpfltmpdyjvv88x9n7x0uvspjdtxycz9gc9zg429", | ||
"balance": { | ||
"available": null, | ||
"debonding": null, | ||
"delegations": null, | ||
"total": null, | ||
}, | ||
"name": "ledger5", | ||
"path": [ | ||
44, | ||
474, | ||
0, | ||
0, | ||
5, | ||
], | ||
"pathDisplay": "m/44'/474'/0'/0'/5'", | ||
"publicKey": "75c515b91e582698550aede5bcff710394eb2d5e89780a254220f11f0976fd06", | ||
"type": "ledger", | ||
}, | ||
"oasis1qpfq4k8s5r0yalyrjcrt8nu2agy4wcwen5xmukwk": { | ||
"address": "oasis1qpfq4k8s5r0yalyrjcrt8nu2agy4wcwen5xmukwk", | ||
"balance": { | ||
"available": null, | ||
"debonding": null, | ||
"delegations": null, | ||
"total": null, | ||
}, | ||
"name": "ledger1", | ||
"path": [ | ||
44, | ||
474, | ||
0, | ||
0, | ||
0, | ||
], | ||
"pathDisplay": "m/44'/474'/0'/0'/0'", | ||
"publicKey": "c7875b0f3dc2fdcb7fb6c05a1a2d6c0638eed37888d593d8a90ff18190fbab44", | ||
"type": "ledger", | ||
}, | ||
"oasis1qpw6nzr77u5nfucee5wjp544hzgmpjjj2gz5p6zq": { | ||
"address": "oasis1qpw6nzr77u5nfucee5wjp544hzgmpjjj2gz5p6zq", | ||
"balance": { | ||
"available": null, | ||
"debonding": null, | ||
"delegations": null, | ||
"total": null, | ||
}, | ||
"name": "Account 1", | ||
"path": [ | ||
44, | ||
474, | ||
0, | ||
], | ||
"pathDisplay": "m/44'/474'/0'", | ||
"privateKey": "86b12cfbcd816983fa2ac199c21b9b217391a7345d85c0c8fc7b715fc8fae19b7d3f6555015b70642912966317a3d084d0d9670415c45084e750ff5378535737", | ||
"publicKey": "7d3f6555015b70642912966317a3d084d0d9670415c45084e750ff5378535737", | ||
"type": "mnemonic", | ||
}, | ||
"oasis1qpwlwv5y25e8h3cwd3z0glevj20y2mv5pvfw7pme": { | ||
"address": "oasis1qpwlwv5y25e8h3cwd3z0glevj20y2mv5pvfw7pme", | ||
"balance": { | ||
"available": null, | ||
"debonding": null, | ||
"delegations": null, | ||
"total": null, | ||
}, | ||
"name": "Account 2", | ||
"path": [ | ||
44, | ||
474, | ||
1, | ||
], | ||
"pathDisplay": "m/44'/474'/1'", | ||
"privateKey": "c43b207bb525f5486649debeb0c8597c23db4fca0d60d6ba93b36c12b2a884186fef3b736a3286339c47f6c3fdeb0346aadc76677b7f889f6c78f768a289c1b5", | ||
"publicKey": "6fef3b736a3286339c47f6c3fdeb0346aadc76677b7f889f6c78f768a289c1b5", | ||
"type": "mnemonic", | ||
}, | ||
"oasis1qq30ejf9puuc6qnrazmy9dmn7f3gessveum5wnr6": { | ||
"address": "oasis1qq30ejf9puuc6qnrazmy9dmn7f3gessveum5wnr6", | ||
"balance": { | ||
"available": null, | ||
"debonding": null, | ||
"delegations": null, | ||
"total": null, | ||
}, | ||
"name": "short privatekey", | ||
"privateKey": "0521f84460c6b4b18bbb1e7535dc7841e08688bf7aaea76285083c052e9b28fad8ed928b97756739db1eb2019abfaabe970b903a8e95b6dfc3e03c25559516ea", | ||
"publicKey": "d8ed928b97756739db1eb2019abfaabe970b903a8e95b6dfc3e03c25559516ea", | ||
"type": "private_key", | ||
}, | ||
"oasis1qrf4y7aelwuusc270e8qx04ysr45w3q0zyavrpdk": { | ||
"address": "oasis1qrf4y7aelwuusc270e8qx04ysr45w3q0zyavrpdk", | ||
"balance": { | ||
"available": null, | ||
"debonding": null, | ||
"delegations": null, | ||
"total": null, | ||
}, | ||
"name": "ledger5-1", | ||
"path": [ | ||
44, | ||
474, | ||
0, | ||
0, | ||
6, | ||
], | ||
"pathDisplay": "m/44'/474'/0'/0'/6'", | ||
"publicKey": "603cb015cb9ec347b1f28ffa64b910b23c207c81a41f0a9b4cdbf5310b342bd3", | ||
"type": "ledger", | ||
}, | ||
"oasis1qzp9vfeafqg8ejpcjl8m947weympxja4dqarmu52": { | ||
"address": "oasis1qzp9vfeafqg8ejpcjl8m947weympxja4dqarmu52", | ||
"balance": { | ||
"available": null, | ||
"debonding": null, | ||
"delegations": null, | ||
"total": null, | ||
}, | ||
"name": "private key1", | ||
"privateKey": "0dd622997e9a8fdd7304bc1858857ac67291635bf741391a58920737b19dc717cb79bba4b4ee741688f9838ed03a5c3c8e6ae98f44fc5395cd04c75d251a90c0", | ||
"publicKey": "cb79bba4b4ee741688f9838ed03a5c3c8e6ae98f44fc5395cd04c75d251a90c0", | ||
"type": "private_key", | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { password, walletExtensionV0PersistedState, wrongPassword } from '../__fixtures__/test-inputs' | ||
import { decryptWithPasswordV0 } from '../walletExtensionV0' | ||
|
||
let jsdomCrypto: any | ||
beforeEach(() => { | ||
jsdomCrypto = global.crypto | ||
Object.defineProperty(global, 'crypto', { value: require('crypto') }) | ||
}) | ||
|
||
afterEach(() => { | ||
Object.defineProperty(global, 'crypto', { value: jsdomCrypto }) | ||
}) | ||
|
||
test('decryptWithPasswordV0', async () => { | ||
const migratedV0Fixture = await decryptWithPasswordV0(password, walletExtensionV0PersistedState) | ||
expect(migratedV0Fixture).toMatchSnapshot() | ||
|
||
await expect(decryptWithPasswordV0(wrongPassword, walletExtensionV0PersistedState)).rejects.toThrow( | ||
'Password wrong', | ||
) | ||
}) |
Oops, something went wrong.