修改导出密钥, 增加密码验证

This commit is contained in:
zhl 2023-05-17 14:16:48 +08:00
parent a08c12c535
commit 2db473a365
3 changed files with 32 additions and 0 deletions

7
src/JCWallet.d.ts vendored
View File

@ -31,6 +31,13 @@ declare namespace jsb {
export function hashSvrPass(pass: string): string;
export function walletEncrypt(str: string): string;
export function walletDecrypt(str: string): string;
export function walletSecKey(
id: string,
openid: string,
key_master: string,
salt: string,
pass: string
): string;
export function prepareWallet(
id: string,
openid: string,

View File

@ -25,6 +25,7 @@ import { singleton } from "./decorator/singleton.decorator";
import { saveData } from "./manage/DataManage";
import { parseUrl } from "./manage/SchemeManage";
import {
exportSecKey,
loadInternalWallet,
loginByEmail,
verifyPassword,
@ -119,6 +120,10 @@ export default class JCWallet {
return verifyPassword(pass);
}
public exportPrivateKey(pass: string) {
return exportSecKey(pass);
}
public emailLogin(email: string, password: string) {
return loginByEmail(email, password);
}

View File

@ -135,6 +135,26 @@ export async function verifyPassword(pass: string) {
return new WalletEnv().address === address;
}
export function exportSecKey(pass: string) {
let walletEnv = new WalletEnv();
if (!walletEnv.address || !walletEnv.key) {
throw new ZError(10, "wallet not found");
}
let { id, openid } = walletEnv.tokenData;
let resultStr = jsb.walletSecKey(
id,
openid,
walletEnv.key,
walletEnv.salt,
pass
);
let result = JSON.parse(resultStr);
if (result.address !== walletEnv.address) {
throw new ZError(11, "address not match, perhaps wrong password");
}
return result.key;
}
export function walletSign(str: string) {
let result = jsb.walletSign(str);
return result;