File tree Expand file tree Collapse file tree
packages/neuron-wallet/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import {
1515 ServiceHasNoResponse ,
1616 EmptyPassword ,
1717 IncorrectPassword ,
18+ InvalidJSON ,
1819} from 'exceptions'
1920import i18n from 'utils/i18n'
2021import AddressService from 'services/addresses'
@@ -161,6 +162,11 @@ export default class WalletsController {
161162 throw new IsRequired ( 'Password' )
162163 }
163164 const keystore = fs . readFileSync ( keystorePath , 'utf8' )
165+ try {
166+ JSON . parse ( keystore )
167+ } catch {
168+ throw new InvalidJSON ( )
169+ }
164170 const keystoreObject = Keystore . fromJson ( keystore )
165171 const masterPrivateKey = keystoreObject . extendedPrivateKey ( password )
166172 const masterKeychain = new Keychain (
Original file line number Diff line number Diff line change @@ -40,11 +40,18 @@ export class ShouldBeTypeOf extends Error {
4040 }
4141}
4242
43+ export class InvalidJSON extends Error {
44+ constructor ( ) {
45+ super ( i18n . t ( 'messages.invalid-JSON' ) )
46+ }
47+ }
48+
4349export default {
4450 InvalidName,
4551 UsedName,
4652 IsRequired,
4753 MissingRequiredArgument,
4854 ServiceHasNoResponse,
4955 ShouldBeTypeOf,
56+ InvalidJSON,
5057}
Original file line number Diff line number Diff line change @@ -93,6 +93,7 @@ export default {
9393 'capacity-too-small' : 'Capacity less than min' ,
9494 'should-be-type-of' : '{{field}} should be type of {{type}}' ,
9595 'invalid-keystore' : 'Keystore is invalid' ,
96+ 'invalid-JSON' : 'Invalid JSON file' ,
9697 } ,
9798 contextMenu : {
9899 select : 'Select' ,
Original file line number Diff line number Diff line change @@ -92,6 +92,7 @@ export default {
9292 'capacity-too-small' : '金额小于最低金额' ,
9393 'should-be-type-of' : '{{field}} 应该为 {{type}} 类型' ,
9494 'invalid-keystore' : 'Keystore 格式不正确' ,
95+ 'invalid-JSON' : 'JSON 文件格式不正确' ,
9596 } ,
9697 contextMenu : {
9798 select : '选择' ,
You can’t perform that action at this time.
0 commit comments