From 2db473a36541293a4138085e510d9012e9d81e1b Mon Sep 17 00:00:00 2001 From: zhl Date: Wed, 17 May 2023 14:16:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AF=BC=E5=87=BA=E5=AF=86?= =?UTF-8?q?=E9=92=A5=EF=BC=8C=20=E5=A2=9E=E5=8A=A0=E5=AF=86=E7=A0=81?= =?UTF-8?q?=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/JCWallet.d.ts | 7 +++++++ src/index.ts | 5 +++++ src/manage/WalletManage.ts | 20 ++++++++++++++++++++ 3 files changed, 32 insertions(+) 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;