diff --git a/cocos/scripting/js-bindings/manual/jsb_global.cpp b/cocos/scripting/js-bindings/manual/jsb_global.cpp index 28364a4..55d24c4 100644 --- a/cocos/scripting/js-bindings/manual/jsb_global.cpp +++ b/cocos/scripting/js-bindings/manual/jsb_global.cpp @@ -1039,7 +1039,7 @@ static bool JSB_prepareWallet(se::State& s) const auto& args = s.args(); size_t argc = args.size(); CC_UNUSED bool ok = true; - if (argc > 0) { + if (argc == 5) { std::string id; ok = seval_to_std_string(args[0], &id); SE_PRECONDITION2(ok, false, "Error processing oid"); @@ -1051,7 +1051,7 @@ static bool JSB_prepareWallet(se::State& s) SE_PRECONDITION2(ok, false, "Error processing master key"); std::string salt; ok = seval_to_std_string(args[3], &salt); - SE_PRECONDITION2(ok, false, "Error processing pass"); + SE_PRECONDITION2(ok, false, "Error processing salt"); std::string pass; ok = seval_to_std_string(args[4], &pass); SE_PRECONDITION2(ok, false, "Error processing pass"); @@ -1074,6 +1074,53 @@ static bool JSB_prepareWallet(se::State& s) } SE_BIND_FUNC(JSB_prepareWallet) +static bool JSB_walletSecKey(se::State& s) +{ + const auto& args = s.args(); + size_t argc = args.size(); + CC_UNUSED bool ok = true; + if (argc == 5) { + std::string id; + ok = seval_to_std_string(args[0], &id); + SE_PRECONDITION2(ok, false, "Error processing oid"); + std::string openid; + ok = seval_to_std_string(args[1], &openid); + SE_PRECONDITION2(ok, false, "Error processing openid"); + std::string keyMaster; + ok = seval_to_std_string(args[2], &keyMaster); + SE_PRECONDITION2(ok, false, "Error processing master key"); + std::string salt; + ok = seval_to_std_string(args[3], &salt); + SE_PRECONDITION2(ok, false, "Error processing salt"); + std::string pass; + ok = seval_to_std_string(args[4], &pass); + SE_PRECONDITION2(ok, false, "Error processing pass"); + std::string localSKey = generate_client_key(pass.c_str(), openid.c_str(), salt.c_str()); + std::string seed = keccak256_hash((id + openid + salt).c_str()); + std::string address = get_address( + seed.c_str(), + keyMaster.c_str(), + localSKey.c_str() + ); + std::string key_str = generate_sec_key( + seed.c_str(), + keyMaster.c_str(), + localSKey.c_str() + ); + std::string result = StringUtils::format("{\"address\": \"%s\",\"key\": \"%s\"}\n", + address.c_str(), + key_str.c_str() + ); + + s.rval().setString(result); + return true; + } + + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 5); + return false; +} +SE_BIND_FUNC(JSB_walletSecKey) + static bool JSB_hashSvrPass(se::State& s) { @@ -1137,29 +1184,6 @@ static bool JSB_loadLocalStorage(se::State& s) } SE_BIND_FUNC(JSB_loadLocalStorage) -static bool JSB_walletSecKey(se::State& s) -{ - const auto& args = s.args(); - size_t argc = args.size(); - CC_UNUSED bool ok = true; - if (argc > 0) { - std::string funid; - ok = seval_to_std_string(args[0], &funid); - SE_PRECONDITION2(ok, false, "funid is invalid!"); - std::string key_str = generate_sec_key( - Application::getInstance()->getKeySeed(), - Application::getInstance()->getKeyMaster(), - Application::getInstance()->getKeySecond() - ); - s.rval().setString(key_str); - return true; - } - - SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1); - return false; -} -SE_BIND_FUNC(JSB_walletSecKey) - static bool JSB_walletSignTran(se::State& s) { const auto& args = s.args();