diff --git a/src/JCWallet.d.ts b/src/JCWallet.d.ts index 29f2c78..94bbdf5 100644 --- a/src/JCWallet.d.ts +++ b/src/JCWallet.d.ts @@ -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, diff --git a/src/index.ts b/src/index.ts index 978fd01..7aa2a8a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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); } diff --git a/src/manage/WalletManage.ts b/src/manage/WalletManage.ts index 0d20119..2976ad8 100644 --- a/src/manage/WalletManage.ts +++ b/src/manage/WalletManage.ts @@ -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;