增加web端扫码登录

This commit is contained in:
zhl 2023-03-02 18:03:30 +08:00
parent 838d60e9a2
commit f78f450585
3 changed files with 162 additions and 0 deletions

View File

@ -1236,6 +1236,139 @@ static bool JSB_walletSignTran(se::State& s)
} }
SE_BIND_FUNC(JSB_walletSignTran) SE_BIND_FUNC(JSB_walletSignTran)
static bool JSB_hexDeflate(se::State& s)
{
const auto& args = s.args();
size_t argc = args.size();
if (argc == 1)
{
bool ok = true;
std::string value;
ok = seval_to_std_string(args[0], &value);
SE_PRECONDITION2(ok, false, "Error processing arguments");
std::string result = hex_deflate(value.c_str());
s.rval().setString(result);
return true;
}
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
return false;
}
SE_BIND_FUNC(JSB_hexDeflate)
static bool JSB_hexInflate(se::State& s)
{
const auto& args = s.args();
size_t argc = args.size();
if (argc == 1)
{
bool ok = true;
std::string value;
ok = seval_to_std_string(args[0], &value);
SE_PRECONDITION2(ok, false, "Error processing arguments");
std::string result = hex_inflate(value.c_str());
s.rval().setString(result);
return true;
}
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
return false;
}
SE_BIND_FUNC(JSB_hexInflate)
static bool JSB_walletEncrypt(se::State& s)
{
const auto& args = s.args();
size_t argc = args.size();
CC_UNUSED bool ok = true;
if (argc > 0) {
std::string msg;
ok = seval_to_std_string(args[0], &msg);
SE_PRECONDITION2(ok, false, "Error processing msg");
std::string str_encrypt = wallet_encrypt(
Application::getInstance()->getKeySeed(),
Application::getInstance()->getKeyMaster(),
Application::getInstance()->getKeySecond(),
Application::getInstance()->getKeyBackup(),
msg.c_str());
s.rval().setString(str_encrypt);
return true;
}
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
return false;
}
SE_BIND_FUNC(JSB_walletEncrypt)
static bool JSB_rencrypt(se::State& s)
{
const auto& args = s.args();
size_t argc = args.size();
CC_UNUSED bool ok = true;
if (argc > 1) {
std::string pk;
ok = seval_to_std_string(args[0], &pk);
SE_PRECONDITION2(ok, false, "Error processing pk");
std::string msg;
ok = seval_to_std_string(args[1], &msg);
SE_PRECONDITION2(ok, false, "Error processing msg");
std::string str_encrypt = rencrypt(
pk.c_str(),
msg.c_str());
s.rval().setString(str_encrypt);
return true;
}
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 2);
return false;
}
SE_BIND_FUNC(JSB_rencrypt)
static bool JSB_localKey(se::State& s)
{
const auto& args = s.args();
size_t argc = args.size();
CC_UNUSED bool ok = true;
if (argc > 0) {
std::string pk;
ok = seval_to_std_string(args[0], &pk);
SE_PRECONDITION2(ok, false, "Error processing pk");
char* key1 = Application::getInstance()->getKeySecond();
char* key2 = Application::getInstance()->getKeyBackup();
std::string str_encrypt = rencrypt(
pk.c_str(),
strlen(key1) > 0 ? key1 : key2);
str_encrypt += strlen(key1) > 0 ? "|0" : "|1";
s.rval().setString(str_encrypt);
return true;
}
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
return false;
}
SE_BIND_FUNC(JSB_localKey)
static bool JSB_walletDecrypt(se::State& s)
{
const auto& args = s.args();
size_t argc = args.size();
CC_UNUSED bool ok = true;
if (argc > 0) {
std::string msg;
ok = seval_to_std_string(args[0], &msg);
SE_PRECONDITION2(ok, false, "Error processing seed");
std::string str_encrypt = wallet_decrypt(
Application::getInstance()->getKeySeed(),
Application::getInstance()->getKeyMaster(),
Application::getInstance()->getKeySecond(),
Application::getInstance()->getKeyBackup(),
msg.c_str());
s.rval().setString(str_encrypt);
return true;
}
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
return false;
}
SE_BIND_FUNC(JSB_walletDecrypt)
bool jsb_register_global_variables(se::Object* global) bool jsb_register_global_variables(se::Object* global)
{ {
@ -1278,6 +1411,12 @@ bool jsb_register_global_variables(se::Object* global)
__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));
__jsbObj->defineFunction("hexDeflate", _SE(JSB_hexDeflate));
__jsbObj->defineFunction("hexInflate", _SE(JSB_hexInflate));
__jsbObj->defineFunction("rencrypt", _SE(JSB_rencrypt));
__jsbObj->defineFunction("encryptedLocalKey", _SE(JSB_localKey));
__jsbObj->defineFunction("walletEncrypt", _SE(JSB_walletEncrypt));
__jsbObj->defineFunction("walletDecrypt", _SE(JSB_walletDecrypt));
__jsbObj->defineFunction("loadLocalStorage", _SE(JSB_loadLocalStorage)); __jsbObj->defineFunction("loadLocalStorage", _SE(JSB_loadLocalStorage));
__jsbObj->defineFunction("setPreferredFramesPerSecond", _SE(JSB_setPreferredFramesPerSecond)); __jsbObj->defineFunction("setPreferredFramesPerSecond", _SE(JSB_setPreferredFramesPerSecond));

View File

@ -24,6 +24,11 @@ char *get_address(const char *msg_key,
const char *second_key, const char *second_key,
const char *backup_key); const char *backup_key);
char *get_public_key(const char *msg_key,
const char *master_key,
const char *second_key,
const char *backup_key);
char *generate_sec_key(const char *msg_key, char *generate_sec_key(const char *msg_key,
const char *master_key, const char *master_key,
const char *second_key, const char *second_key,
@ -40,3 +45,21 @@ char *sign_for_tran(const char *msg_key,
const char *second_key, const char *second_key,
const char *backup_key, const char *backup_key,
const char *msg); const char *msg);
char *rencrypt(const char *pk, const char *msg);
char *wallet_encrypt(const char *msg_key,
const char *master_key,
const char *second_key,
const char *backup_key,
const char *msg);
char *wallet_decrypt(const char *msg_key,
const char *master_key,
const char *second_key,
const char *backup_key,
const char *msg);
char *hex_deflate(const char *content);
char *hex_inflate(const char *content);

Binary file not shown.