wkw vor 3 Wochen
Ursprung
Commit
458e5d57a0

+ 2 - 1
src/stores/modules/walletStore.js

@@ -6,6 +6,7 @@ import { sysLogin } from "@/common/login.js";
 import { showNotify } from 'vant';
 import router from '@/router/index'
 import { hotTokens } from '@/api/path/login.api'
+import { cryptoDecode } from "@/utils/crypto.js"
 
 
 export const useWalletStore = defineStore("useWalletStore", {
@@ -137,7 +138,7 @@ export const useWalletStore = defineStore("useWalletStore", {
         showNotify({ type: 'warning', message: '钱包不存在' });
         return;
       }
-      if (wallet.accountPassword !== password) {
+      if (cryptoDecode(wallet.accountPassword) !== password) {
         showNotify({ type: 'warning', message: '请输入正确的密码' });
         return;
       }

+ 10 - 7
src/utils/crypto.js

@@ -22,14 +22,17 @@ export const cryptoEncode = (data) => {
 
 export const cryptoDecode = (data) => {
   const key = CryptoJS.enc.Utf8.parse(KEY);
-  const iv = CryptoJS.lib.WordArray.create(CryptoJS.enc.Utf8.parse(KEY).words.slice(0, 4)); // 前四个字节作为IV
-  const bytes = CryptoJS.AES.decrypt(data, key, {
-      iv: iv,
-      mode: CryptoJS.mode.ECB,
-      padding: CryptoJS.pad.Pkcs7
+  const ivBase64 = data.substring(0, 24); // 16字节的Base64编码是24字符
+  const encryptedBase64 = data.substring(24);
+  const iv = CryptoJS.enc.Base64.parse(ivBase64);
+  const decrypted = CryptoJS.AES.decrypt(encryptedBase64, key, {
+    iv: iv,
+    mode: CryptoJS.mode.CBC,
+    padding: CryptoJS.pad.Pkcs7,
   });
-  return bytes.toString(CryptoJS.enc.Utf8);
-}
+  return decrypted.toString(CryptoJS.enc.Utf8);
+};
+
 
 function getRandomString16() {
   const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';

+ 5 - 2
src/views/login/importWallet/index.vue

@@ -71,6 +71,7 @@
 
 <script setup>
 import _ from "lodash";
+import { cryptoEncode } from "@/utils/crypto.js"
 import { useRoute } from "vue-router";
 import { useWalletStore } from "@/stores/modules/walletStore";
  
@@ -93,8 +94,10 @@ const onSubmit = async () => {
     walletStore.privateKey = form.value.userKey;
   }else{
     walletStore.words = form.value.userKey.trim().split(',');
-  } 
-  walletStore.accountPassword = form.value.password;
+  }
+  let data = _.cloneDeep(form.value)
+  data.password = cryptoEncode(data.password) 
+  walletStore.accountPassword = data.password ;
   walletStore.accountHint = form.value.promptMessage;
   await walletStore.loginWithPrivateKey(type != 0);
   router.push({

+ 2 - 1
src/views/wallet/transferDetail/index.vue

@@ -102,6 +102,7 @@
 </template>
 
 <script setup>
+import { cryptoDecode } from "@/utils/crypto.js"
 import { useRouter,useRoute } from 'vue-router'
 import { useWalletStore } from "@/stores/modules/walletStore";
 import Web3 from "web3";
@@ -203,7 +204,7 @@ const cancel = () => {
 }
 // 密码确认
 const popConfirm = () => {
-    if(passWord.value != walletStore.accountPassword){
+    if(passWord.value != cryptoDecode(walletStore.accountPassword)){
         showNotify({ type: 'warning', message: '请输入正确的密码' });
     }else{
         getData();

+ 16 - 6
src/views/wallet/walletDetail/index.vue

@@ -19,7 +19,7 @@
                 title="錢包名稱"
                 :value="currentWallet.username"
                 is-link
-                @click="changePop(1)"
+                @click="changePop(1,'sy')"
             ></van-cell>
             <van-cell
                 title="查看私鑰"
@@ -27,6 +27,12 @@
                 is-link
                 @click="changePop(2)"
             ></van-cell>
+            <van-cell v-if="currentWallet.words"
+                title="查看助記詞"
+                value=""
+                is-link
+                @click="changePop(2,'zjc')"
+            ></van-cell>
         </van-list>
 
         <van-button class="footer-btn" size="large" @click="changePop(3)">删除钱包</van-button>
@@ -50,7 +56,7 @@
             <div>
                 <div class="pop-title-key">
                     <svg-icon style="width: 24px; height: 24px" name="left-arrow"/>
-                    <div class="title">查看私钥</div>
+                    <div class="title">{{status == 'zjc'?'查看助记词':'查看私钥'}}</div>
                 </div>
                 <div class="pop-text">{{ qrtext }}</div>
                 <div class="qrcode">
@@ -65,6 +71,7 @@
 </template>
 
 <script setup>
+import { cryptoDecode } from "@/utils/crypto.js"
 import { ref, computed } from 'vue';
 import QrcodeVue from 'qrcode.vue';
 import { useWalletStore } from '@/stores/modules/walletStore';
@@ -83,18 +90,21 @@ const currentWallet = computed(() => {
         return walletStore.walletList.find(item => item.id === id) || {};
     }
 });
-const qrtext = currentWallet.value.privateKey;
+const qrtext = ref('');
 
 // 弹窗控制
 const show = ref(false);
 const showkey = ref(false);
 const text = ref('');
 const type = ref('');
+const status = ref('');
 
 // 弹窗操作
-const changePop = v => {
+const changePop = (v,val) => {
     show.value = true;
     type.value = v;
+    status.value = val;
+    qrtext.value = val == 'zjc'?currentWallet.value.words.join(','):currentWallet.value.privateKey;
 };
 
 const cancel = () => {
@@ -110,8 +120,8 @@ const confirm = () => {
         // 删除钱包
         walletStore.deleteWallet(id, text.value);
     } else if (type.value == 2) {
-        // 查看私钥
-        if (text.value !== currentWallet.value.accountPassword) {
+        // 查看私钥或者密码
+        if (text.value !== cryptoDecode(currentWallet.value.accountPassword)) {
             showNotify({ type: 'warning', message: '请输入正确的密码' });
         } else {
             showkey.value = true;