Skip to content

Commit

Permalink
Merge pull request #166 from MickWang/master
Browse files Browse the repository at this point in the history
update import common wallet
  • Loading branch information
MickWang committed Jun 11, 2019
2 parents 8049949 + b40ca92 commit b7b3b9f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/common/lang/en.js
Expand Up @@ -193,7 +193,8 @@ export default {
success: 'Import wallet successfully!',
saveDbFailed: 'Save to keystore failed. Please try later.',
invalidPrivateKey: 'Please enter valid private key.',
setPassword: 'Set password'
setPassword: 'Set password',
importFirstDefault: 'Will only import the default wallet or the first wallet in the .dat file'
},

createSharedWallet: {
Expand Down
3 changes: 2 additions & 1 deletion src/common/lang/zh.js
Expand Up @@ -192,7 +192,8 @@ export default {
success: '导入钱包成功',
saveDbFailed: '保存到Keystore失败。请稍后重试。',
invalidPrivateKey: '请输入正确的私钥',
setPassword: '设置密码'
setPassword: '设置密码',
importFirstDefault: '只导入.dat文件中的默认钱包或第一个钱包'
},

createSharedWallet: {
Expand Down
9 changes: 9 additions & 0 deletions src/core/utils.js
Expand Up @@ -75,6 +75,15 @@ export function validateAddress(address) {
}
}

export function convertScryptParams({n, r, p, dkLen}) {
return {
cost: n,
blockSize: r,
parallel: p,
size: dkLen
}
}

// 创建axios实例
const service = axios.create({
timeout: 15000 // 请求超时时间
Expand Down
40 changes: 30 additions & 10 deletions src/renderer/components/JsonWallet/Import/BasicInfo.vue
Expand Up @@ -121,6 +121,10 @@
.nav-item a {
font-size:14px !important;
}
.tip {
font-size:14px;
}
</style>
<template>
<div class="container json-import-container">
Expand Down Expand Up @@ -189,6 +193,10 @@

<div class="tab-pane fade" id="import-json-dat-pills" role="tabpanel"
aria-labelledby="import-json-dat-pills-tab">
<p>
<a-icon type="info-circle-o" class="redeem-info-icon" />
<span class="tip">{{$t('importJsonWallet.importFirstDefault')}}</span>
</p>
<a-input class="input" :placeholder="$t('importJsonWallet.label')" v-model="datLabel" name="datLabel"
v-validate="{required: true}"></a-input>
<span class="v-validate-span-errors" v-show="errors.has('datLabel')">{{ errors.first('datLabel') }}</span>
Expand Down Expand Up @@ -250,7 +258,7 @@
import dbService from '../../../../core/dbService'
import {DEFAULT_SCRYPT} from '../../../../core/consts'
import $ from 'jquery'
import {isHexString} from '../../../../core/utils'
import {isHexString, convertScryptParams} from '../../../../core/utils'
export default {
name: 'BasicInfo',
Expand Down Expand Up @@ -363,15 +371,25 @@
this.dat = files[0]
},
validateWalletFile(wallet) {
if(!wallet.accounts || wallet.accounts.length < 1) {
if(!wallet.scrypt || !wallet.accounts || wallet.accounts.length < 1) {
return false;
}
//Only import the first account
const account = wallet.accounts[0]
if(!account.key || !account.address || !account.salt) {
//Only import the default account or the first account
debugger
let account;
for (const acct of wallet.accounts) {
if(acct.isDefault || acct.isDefault == 'true') {
account = acct;
break;
}
}
if(!account) {
account = wallet.accounts[0]
}
if(!account || !account.key || !account.address || !account.salt) {
return false;
}
return true;
return account;
},
importAccountForDat() {
/**
Expand All @@ -391,17 +409,19 @@
return;
}
//TODO: validate file content
if(!this.validateWalletFile(wallet)) {
const account = this.validateWalletFile(wallet)
if(!account) {
this.$store.dispatch('hideLoadingModals')
this.$message.error(this.$t('importJsonWallet.invalidDatFile'))
return;
}
const account = wallet.accounts[0]
const enc = new Crypto.PrivateKey(account.key);
const address = new Crypto.Address(account.address)
let scrypt = convertScryptParams(wallet.scrypt)
debugger
try {
enc.decrypt(this.datPassword, address, account.salt, DEFAULT_SCRYPT)
enc.decrypt(this.datPassword, address, account.salt, scrypt)
} catch (err) {
console.log(err)
this.$store.dispatch('hideLoadingModals')
Expand Down

0 comments on commit b7b3b9f

Please sign in to comment.