增加钱包新建, 恢复和签名方法
This commit is contained in:
parent
1b4f73b391
commit
42ed530566
@ -52,7 +52,6 @@ base/CCRenderTexture.cpp \
|
||||
storage/local-storage/LocalStorage-android.cpp \
|
||||
scrypt/base64.c \
|
||||
scrypt/sha256.c \
|
||||
scrypt/crypto_scrypt.h \
|
||||
scrypt/crypto_scrypt.c \
|
||||
scrypt/native-crypto.cpp \
|
||||
network/CCDownloader.cpp \
|
||||
@ -85,8 +84,7 @@ scripting/js-bindings/event/EventDispatcher.cpp \
|
||||
../external/sources/unzip/unzip.cpp \
|
||||
../external/sources/ConvertUTF/ConvertUTFWrapper.cpp \
|
||||
../external/sources/ConvertUTF/ConvertUTF.c \
|
||||
../external/sources/edtaa3func/edtaa3func.cpp \
|
||||
../external/sources/edtaa3func/edtaa3func.h
|
||||
../external/sources/edtaa3func/edtaa3func.cpp
|
||||
|
||||
# v8 debugger source files, always enable it
|
||||
LOCAL_SRC_FILES += \
|
||||
@ -145,6 +143,7 @@ LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) \
|
||||
|
||||
LOCAL_STATIC_LIBRARIES += cocos_png_static
|
||||
LOCAL_STATIC_LIBRARIES += cocos_jpeg_static
|
||||
LOCAL_STATIC_LIBRARIES += rust_wallet
|
||||
|
||||
ifeq ($(USE_TIFF),1)
|
||||
LOCAL_STATIC_LIBRARIES += cocos_tiff_static
|
||||
|
@ -111,7 +111,24 @@ public:
|
||||
inline void* getView() const { return _view; }
|
||||
inline std::shared_ptr<Scheduler> getScheduler() const { return _scheduler; }
|
||||
inline RenderTexture* getRenderTexture() const { return _renderTexture; }
|
||||
|
||||
inline char* getKeyMaster() {return key_master;}
|
||||
inline char* getKeySecond() {return key_second;}
|
||||
inline char* getKeyBackup() {return key_backup;}
|
||||
inline char* getKeySeed() {return key_seed;}
|
||||
void setKeyMaster(char *val) {
|
||||
key_master = val;
|
||||
}
|
||||
void setKeySecond(char *val) {
|
||||
key_second = val;
|
||||
}
|
||||
void setKeyBackup(char *val) {
|
||||
key_backup = val;
|
||||
}
|
||||
void setKeySeed(char *val) {
|
||||
key_seed = val;
|
||||
}
|
||||
|
||||
|
||||
void runOnMainThread();
|
||||
|
||||
void start();
|
||||
@ -206,6 +223,11 @@ private:
|
||||
void* _view = nullptr;
|
||||
void* _delegate = nullptr;
|
||||
RenderTexture* _renderTexture = nullptr;
|
||||
char* key_master = nullptr;
|
||||
char* key_second = nullptr;
|
||||
char* key_backup = nullptr;
|
||||
char* key_seed = nullptr;
|
||||
|
||||
int _fps = 60;
|
||||
GLint _mainFBO = 0;
|
||||
|
||||
|
@ -27,6 +27,7 @@ THE SOFTWARE.
|
||||
#include <EGL/egl.h>
|
||||
#include <cstring>
|
||||
#include <jni.h>
|
||||
|
||||
#include "platform/android/jni/JniImp.h"
|
||||
#include "platform/android/CCGL-android.h"
|
||||
#include "base/CCScheduler.h"
|
||||
|
@ -31,6 +31,13 @@
|
||||
#include "base/CCThreadPool.h"
|
||||
#include "network/HttpClient.h"
|
||||
#include "platform/CCApplication.h"
|
||||
#include "base/ccUTF8.h"
|
||||
#include "storage/local-storage/LocalStorage.h"
|
||||
extern "C"
|
||||
{
|
||||
#include "rustwallet/rustwallet.h"
|
||||
}
|
||||
|
||||
|
||||
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
|
||||
#include "platform/android/jni/JniImp.h"
|
||||
@ -871,6 +878,107 @@ static bool JSB_toWallet(se::State& s)
|
||||
}
|
||||
SE_BIND_FUNC(JSB_toWallet)
|
||||
|
||||
static bool JSB_generateWallet(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");
|
||||
CWallet wallet = new_wallet(seed.c_str());
|
||||
SE_LOGE("cwallet master key: %s \n", wallet.master_key);
|
||||
std::string address = get_address(&wallet);
|
||||
SE_LOGE("address: %s \n", address.c_str());
|
||||
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);
|
||||
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, 2);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(JSB_generateWallet)
|
||||
|
||||
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) {
|
||||
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 maskter key");
|
||||
std::string storageKey =StringUtils::format("cebg_wallet_%s", id.c_str());
|
||||
std::string localKey;
|
||||
localStorageGetItem(storageKey, &localKey);
|
||||
Application::getInstance()->setKeyMaster(const_cast<char *>(keyMaster.c_str()));
|
||||
Application::getInstance()->setKeySecond(const_cast<char *>(localKey.c_str()));
|
||||
Application::getInstance()->setKeySeed(const_cast<char *>(seed.c_str()));
|
||||
SE_LOGE("wallet master key: %s \n", Application::getInstance()->getKeyMaster());
|
||||
SE_LOGE("wallet second key: %s \n", Application::getInstance()->getKeySecond());
|
||||
SE_LOGE("wallet seed key: %s \n", Application::getInstance()->getKeySeed());
|
||||
// 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_prepareWallet)
|
||||
|
||||
static bool JSB_walletSign(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");
|
||||
SE_LOGE("sign with: %s \n", msg.c_str());
|
||||
SE_LOGE("wallet master key: %s \n", Application::getInstance()->getKeyMaster());
|
||||
SE_LOGE("wallet second key: %s \n", Application::getInstance()->getKeySecond());
|
||||
SE_LOGE("wallet seed key: %s \n", Application::getInstance()->getKeySeed());
|
||||
CWallet wallet = CWallet{
|
||||
.msg_key = Application::getInstance()->getKeySeed(),
|
||||
.master_key = Application::getInstance()->getKeyMaster(),
|
||||
.second_key = Application::getInstance()->getKeySecond(),
|
||||
.backup_key = ""
|
||||
};
|
||||
std::string sign_str = sign(&wallet, msg.c_str());
|
||||
SE_LOGE("sign result: %s \n", sign_str.c_str());
|
||||
s.rval().setString(sign_str);
|
||||
// free_cwallet(wallet);
|
||||
return true;
|
||||
}
|
||||
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(JSB_walletSign)
|
||||
|
||||
bool jsb_register_global_variables(se::Object* global)
|
||||
{
|
||||
g_threadPool.reset(ThreadPool::newFixedThreadPool(3));
|
||||
@ -896,6 +1004,9 @@ bool jsb_register_global_variables(se::Object* global)
|
||||
__jsbObj->defineFunction("scanQRCode", _SE(JSB_scanQRCode));
|
||||
__jsbObj->defineFunction("signWithGoogle", _SE(JSB_signWithGoogle));
|
||||
__jsbObj->defineFunction("signOutGoogle", _SE(JSB_signOutGoogle));
|
||||
__jsbObj->defineFunction("generateWallet", _SE(JSB_generateWallet));
|
||||
__jsbObj->defineFunction("prepareWallet", _SE(JSB_prepareWallet));
|
||||
__jsbObj->defineFunction("walletSign", _SE(JSB_walletSign));
|
||||
#endif
|
||||
__jsbObj->defineFunction("toWallet", _SE(JSB_toWallet));
|
||||
|
||||
|
@ -906,7 +906,8 @@
|
||||
"external/android/arm64-v8a/include/webp/encode.h",
|
||||
"external/android/arm64-v8a/include/webp/types.h",
|
||||
"external/android/arm64-v8a/include/websockets/libwebsockets.h",
|
||||
"external/android/arm64-v8a/include/websockets/lws_config.h",
|
||||
"external/android/arm64-v8a/include/websockets/lws_config.h",
|
||||
"external/android/arm64-v8a/include/rustwallet/rustwallet.h",
|
||||
"external/android/arm64-v8a/include/zlib/zconf.h",
|
||||
"external/android/arm64-v8a/include/zlib/zlib.h",
|
||||
"external/android/arm64-v8a/libcocos2djni.a",
|
||||
@ -1100,7 +1101,8 @@
|
||||
"external/android/armeabi-v7a/include/webp/encode.h",
|
||||
"external/android/armeabi-v7a/include/webp/types.h",
|
||||
"external/android/armeabi-v7a/include/websockets/libwebsockets.h",
|
||||
"external/android/armeabi-v7a/include/websockets/lws_config.h",
|
||||
"external/android/armeabi-v7a/include/websockets/lws_config.h",
|
||||
"external/android/armeabi-v7a/include/rustwallet/rustwallet.h",
|
||||
"external/android/armeabi-v7a/include/zlib/zconf.h",
|
||||
"external/android/armeabi-v7a/include/zlib/zlib.h",
|
||||
"external/android/armeabi-v7a/libcocos2djni.a",
|
||||
@ -1294,7 +1296,8 @@
|
||||
"external/android/x86/include/webp/encode.h",
|
||||
"external/android/x86/include/webp/types.h",
|
||||
"external/android/x86/include/websockets/libwebsockets.h",
|
||||
"external/android/x86/include/websockets/lws_config.h",
|
||||
"external/android/x86/include/websockets/lws_config.h",
|
||||
"external/android/x86/include/rustwallet/rustwallet.h",
|
||||
"external/android/x86/include/zlib/zconf.h",
|
||||
"external/android/x86/include/zlib/zlib.h",
|
||||
"external/android/x86/libcocos2djni.a",
|
||||
@ -1488,7 +1491,8 @@
|
||||
"external/android/x86_64/include/webp/encode.h",
|
||||
"external/android/x86_64/include/webp/types.h",
|
||||
"external/android/x86_64/include/websockets/libwebsockets.h",
|
||||
"external/android/x86_64/include/websockets/lws_config.h",
|
||||
"external/android/x86_64/include/websockets/lws_config.h",
|
||||
"external/android/x86_64/include/rustwallet/rustwallet.h",
|
||||
"external/android/x86_64/include/zlib/zconf.h",
|
||||
"external/android/x86_64/include/zlib/zlib.h",
|
||||
"external/android/x86_64/libcrypto.a",
|
||||
|
Loading…
x
Reference in New Issue
Block a user