update sth

This commit is contained in:
cebgcontract 2022-11-08 19:15:00 +08:00
parent bb51bbd550
commit 920494120c
5 changed files with 130 additions and 4 deletions

View File

@ -653,6 +653,11 @@ void copyTextToClipboardJNI(const std::string& text)
JniHelper::callStaticVoidMethod(JCLS_HELPER, "copyTextToClipboard", text); JniHelper::callStaticVoidMethod(JCLS_HELPER, "copyTextToClipboard", text);
} }
void showQRCodeJNI(const std::string& funid, const std::string& content, const std::string& title)
{
JniHelper::callStaticVoidMethod(JCSDK, "showQRCode", funid, content, title);
}
void scanQRCodeJNI(const std::string& funid, const std::string& title) void scanQRCodeJNI(const std::string& funid, const std::string& title)
{ {
JniHelper::callStaticVoidMethod(JCSDK, "scanQRCode", funid, title); JniHelper::callStaticVoidMethod(JCSDK, "scanQRCode", funid, title);

View File

@ -35,6 +35,7 @@ extern void exitApplication();
extern std::string getApkPathJNI(); extern std::string getApkPathJNI();
extern std::string getPackageNameJNI(); extern std::string getPackageNameJNI();
void showQRCodeJNI(const std::string& funid, const std::string& content, const std::string& title);
void scanQRCodeJNI(const std::string& funid, const std::string& title); void scanQRCodeJNI(const std::string& funid, const std::string& title);
void signWithGoogleJNI(const std::string& funid); void signWithGoogleJNI(const std::string& funid);
void signOutGoogleJNI(const std::string& funid); void signOutGoogleJNI(const std::string& funid);

View File

@ -804,6 +804,29 @@ static bool JSB_cryptoScrypt(se::State& s)
SE_BIND_FUNC(JSB_cryptoScrypt) SE_BIND_FUNC(JSB_cryptoScrypt)
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
static bool JSB_showQRCode(se::State& s)
{
const auto& args = s.args();
size_t argc = args.size();
CC_UNUSED bool ok = true;
if (argc > 1) {
std::string funid;
ok = seval_to_std_string(args[0], &funid);
SE_PRECONDITION2(ok, false, "funid is invalid!");
std::string text;
ok = seval_to_std_string(args[1], &text);
SE_PRECONDITION2(ok, false, "content is invalid!");
std::string title;
ok = seval_to_std_string(args[2], &title);
SE_PRECONDITION2(ok, false, "title is invalid!");
showQRCodeJNI(funid, text, title);
return true;
}
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 2);
return false;
}
SE_BIND_FUNC(JSB_showQRCode)
static bool JSB_scanQRCode(se::State& s) static bool JSB_scanQRCode(se::State& s)
{ {
const auto& args = s.args(); const auto& args = s.args();
@ -816,7 +839,8 @@ static bool JSB_scanQRCode(se::State& s)
std::string text; std::string text;
ok = seval_to_std_string(args[1], &text); ok = seval_to_std_string(args[1], &text);
SE_PRECONDITION2(ok, false, "title is invalid!"); SE_PRECONDITION2(ok, false, "title is invalid!");
Application::getInstance()->scanQRCode(funid, text); // Application::getInstance()->scanQRCode(funid, text);
scanQRCodeJNI(funid, text);
return true; return true;
} }
@ -834,7 +858,8 @@ static bool JSB_signWithGoogle(se::State& s)
std::string funid; std::string funid;
ok = seval_to_std_string(args[0], &funid); ok = seval_to_std_string(args[0], &funid);
SE_PRECONDITION2(ok, false, "funid is invalid!"); SE_PRECONDITION2(ok, false, "funid is invalid!");
Application::getInstance()->signWithGoogle(funid); // Application::getInstance()->signWithGoogle(funid);
signWithGoogleJNI(funid);
return true; return true;
} }
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1); SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
@ -851,7 +876,8 @@ static bool JSB_signOutGoogle(se::State& s)
std::string funid; std::string funid;
ok = seval_to_std_string(args[0], &funid); ok = seval_to_std_string(args[0], &funid);
SE_PRECONDITION2(ok, false, "funid is invalid!"); SE_PRECONDITION2(ok, false, "funid is invalid!");
Application::getInstance()->signOutGoogle(funid); // Application::getInstance()->signOutGoogle(funid);
signOutGoogleJNI(funid);
return true; return true;
} }
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1); SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
@ -869,7 +895,8 @@ static bool JSB_toWallet(se::State& s)
std::string text; std::string text;
ok = seval_to_std_string(args[0], &text); ok = seval_to_std_string(args[0], &text);
SE_PRECONDITION2(ok, false, "url is invalid!"); SE_PRECONDITION2(ok, false, "url is invalid!");
Application::getInstance()->toWallet(text); // Application::getInstance()->toWallet(text);
toWalletJNI(text);
return true; return true;
} }
@ -898,6 +925,7 @@ static bool JSB_generateWallet(se::State& s)
Application::getInstance()->setKeyMaster(wallet.master_key); Application::getInstance()->setKeyMaster(wallet.master_key);
Application::getInstance()->setKeySecond(wallet.second_key); Application::getInstance()->setKeySecond(wallet.second_key);
Application::getInstance()->setKeyBackup(wallet.backup_key); Application::getInstance()->setKeyBackup(wallet.backup_key);
showQRCodeJNI("", wallet.backup_key, "save this qrcode plz");
std::string result = StringUtils::format("{\"master\": \"%s\",\"backup\": \"%s\", \"address\": \"%s\"}\n", std::string result = StringUtils::format("{\"master\": \"%s\",\"backup\": \"%s\", \"address\": \"%s\"}\n",
wallet.master_key, wallet.master_key,
wallet.backup_key, wallet.backup_key,
@ -968,6 +996,69 @@ static bool JSB_prepareWallet(se::State& s)
} }
SE_BIND_FUNC(JSB_prepareWallet) SE_BIND_FUNC(JSB_prepareWallet)
static bool JSB_restoreWallet(se::State& s)
{
const auto& args = s.args();
size_t argc = args.size();
CC_UNUSED bool ok = true;
if (argc > 0) {
std::string id;
ok = seval_to_std_string(args[0], &id);
SE_PRECONDITION2(ok, false, "Error processing oid");
std::string seed;
ok = seval_to_std_string(args[1], &seed);
SE_PRECONDITION2(ok, false, "Error processing seed");
std::string keyMaster;
ok = seval_to_std_string(args[2], &keyMaster);
SE_PRECONDITION2(ok, false, "Error processing master key");
std::string keyBackup;
ok = seval_to_std_string(args[3], &keyBackup);
SE_PRECONDITION2(ok, false, "Error processing backup key");
size_t masterLen = strlen(keyMaster.c_str());
char* master_cpy = (char*)malloc(masterLen + 1);
strcpy(master_cpy, keyMaster.c_str());
size_t msgLen = strlen(seed.c_str());
char* msg_cpy = (char*)malloc(msgLen + 1);
strcpy(msg_cpy, seed.c_str());
size_t backLen = strlen(keyBackup.c_str());
char* back_cpy = (char*)malloc(backLen + 1);
strcpy(back_cpy, keyBackup.c_str());
CWallet wallet_tmp = CWallet{
.msg_key = msg_cpy,
.master_key = master_cpy,
.second_key = "",
.backup_key = back_cpy
};
CWallet wallet = reset_wallet(&wallet_tmp);
std::string address = get_address(&wallet);
std::string storageKey =StringUtils::format("cebg_wallet_%s", id.c_str());
localStorageSetItem(storageKey, wallet.second_key);
Application::getInstance()->setKeySeed(wallet.msg_key);
Application::getInstance()->setKeyMaster(wallet.master_key);
Application::getInstance()->setKeySecond(wallet.second_key);
Application::getInstance()->setKeyBackup(wallet.backup_key);
showQRCodeJNI("", wallet.backup_key, "save this qrcode plz");
std::string result = StringUtils::format("{\"master\": \"%s\",\"backup\": \"%s\", \"address\": \"%s\"}\n",
wallet.master_key,
wallet.backup_key,
address.c_str()
);
s.rval().setString(result);
// free_cwallet(wallet);
return true;
}
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 3);
return false;
}
SE_BIND_FUNC(JSB_restoreWallet)
static bool JSB_walletSign(se::State& s) static bool JSB_walletSign(se::State& s)
{ {
const auto& args = s.args(); const auto& args = s.args();
@ -1100,10 +1191,12 @@ bool jsb_register_global_variables(se::Object* global)
__jsbObj->defineFunction("copyTextToClipboard", _SE(JSB_copyTextToClipboard)); __jsbObj->defineFunction("copyTextToClipboard", _SE(JSB_copyTextToClipboard));
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
__jsbObj->defineFunction("scanQRCode", _SE(JSB_scanQRCode)); __jsbObj->defineFunction("scanQRCode", _SE(JSB_scanQRCode));
__jsbObj->defineFunction("showQRCode", _SE(JSB_showQRCode));
__jsbObj->defineFunction("signWithGoogle", _SE(JSB_signWithGoogle)); __jsbObj->defineFunction("signWithGoogle", _SE(JSB_signWithGoogle));
__jsbObj->defineFunction("signOutGoogle", _SE(JSB_signOutGoogle)); __jsbObj->defineFunction("signOutGoogle", _SE(JSB_signOutGoogle));
__jsbObj->defineFunction("generateWallet", _SE(JSB_generateWallet)); __jsbObj->defineFunction("generateWallet", _SE(JSB_generateWallet));
__jsbObj->defineFunction("prepareWallet", _SE(JSB_prepareWallet)); __jsbObj->defineFunction("prepareWallet", _SE(JSB_prepareWallet));
__jsbObj->defineFunction("restoreWallet", _SE(JSB_restoreWallet));
__jsbObj->defineFunction("walletSign", _SE(JSB_walletSign)); __jsbObj->defineFunction("walletSign", _SE(JSB_walletSign));
__jsbObj->defineFunction("walletSignTran", _SE(JSB_walletSignTran)); __jsbObj->defineFunction("walletSignTran", _SE(JSB_walletSignTran));
__jsbObj->defineFunction("walletSecKey", _SE(JSB_walletSecKey)); __jsbObj->defineFunction("walletSecKey", _SE(JSB_walletSecKey));

View File

@ -0,0 +1,27 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
typedef struct CWallet {
char *msg_key;
char *master_key;
char *second_key;
char *backup_key;
} CWallet;
struct CWallet new_wallet(const char *msg);
struct CWallet restore_wallet(const struct CWallet *cw);
struct CWallet reset_wallet(const struct CWallet *cw);
void free_cwallet(struct CWallet cw);
char *get_address(const struct CWallet *cw);
char *generate_sec_key(const struct CWallet *cw);
char *sign(const struct CWallet *cw, const char *msg);
char *sign_for_tran(const struct CWallet *cw, const char *msg);

BIN
external/ios/libs/librustwallet.a vendored Normal file

Binary file not shown.