增加key chain的读写, 将本地密钥写入key chain
This commit is contained in:
parent
34b1b00c74
commit
721814c93b
@ -11,6 +11,7 @@
|
||||
#include "platform/CCApplication.h"
|
||||
#include "base/CCScheduler.h"
|
||||
#include "scrypt/native-crypto.h"
|
||||
#include "rustwallet.h"
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
|
||||
#include "AppDelegate.h"
|
||||
@ -219,6 +220,7 @@ static bool getOrCreatePlainObject_r(const char* name, se::Object* parent, se::O
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool jsb_wallet_callback(se::State& s) {
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
@ -258,39 +260,8 @@ bool jsb_scanQRCode(se::State& s) {
|
||||
}
|
||||
SE_BIND_FUNC(jsb_scanQRCode)
|
||||
|
||||
static bool JSB_showQRCode(se::State& s)
|
||||
{
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
CC_UNUSED bool ok = true;
|
||||
if (argc > 4) {
|
||||
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!");
|
||||
std::string oid;
|
||||
ok = seval_to_std_string(args[3], &oid);
|
||||
SE_PRECONDITION2(ok, false, "data id is invalid!");
|
||||
NSString *ntitle = [NSString stringWithCString:title.c_str() encoding:NSUTF8StringEncoding];
|
||||
NSString *nfunid = [NSString stringWithCString:funid.c_str() encoding:NSUTF8StringEncoding];
|
||||
NSString *ncontent = [NSString stringWithCString:text.c_str() encoding:NSUTF8StringEncoding];
|
||||
NSString *noid = [NSString stringWithCString:oid.c_str() encoding:NSUTF8StringEncoding];
|
||||
UIWindow* window = [[[UIApplication sharedApplication] delegate] window];
|
||||
[window.rootViewController showQRCode:nfunid content:ncontent title:ntitle oid: noid];
|
||||
return true;
|
||||
}
|
||||
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 4);
|
||||
return false;
|
||||
}
|
||||
SE_BIND_FUNC(JSB_showQRCode)
|
||||
|
||||
static bool JSB_restoreKey(se::State& s)
|
||||
bool JSB_restoreKey(se::State& s)
|
||||
{
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
@ -308,7 +279,6 @@ static bool JSB_restoreKey(se::State& s)
|
||||
[window.rootViewController loadRestoreKey:nfunid oid: noid];
|
||||
return true;
|
||||
}
|
||||
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 2);
|
||||
return false;
|
||||
}
|
||||
@ -349,14 +319,11 @@ bool jsb_signOutGoogle(se::State& s) {
|
||||
SE_BIND_FUNC(jsb_signOutGoogle)
|
||||
|
||||
|
||||
|
||||
|
||||
bool jsb_register_walletevent_modules(se::Object* global) {
|
||||
getOrCreatePlainObject_r("jsb", global, &__jsbObj);
|
||||
__jsbObj->defineFunction("jcCallback", _SE(jsb_wallet_callback));
|
||||
__jsbObj->defineFunction("scanQRCode", _SE(jsb_scanQRCode));
|
||||
__jsbObj->defineFunction("restoreKey", _SE(JSB_restoreKey));
|
||||
__jsbObj->defineFunction("showQRCode", _SE(JSB_showQRCode));
|
||||
__jsbObj->defineFunction("signWithGoogle", _SE(jsb_signWithGoogle));
|
||||
__jsbObj->defineFunction("signOutGoogle", _SE(jsb_signOutGoogle));
|
||||
return true;
|
||||
|
357
Classes_cocos/SSKeychain.h
Normal file
357
Classes_cocos/SSKeychain.h
Normal file
@ -0,0 +1,357 @@
|
||||
//
|
||||
// SSKeychain.h
|
||||
// SSToolkit
|
||||
//
|
||||
// Created by Sam Soffes on 5/19/10.
|
||||
// Copyright (c) 2009-2011 Sam Soffes. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <Security/Security.h>
|
||||
|
||||
/** Error codes that can be returned in NSError objects. */
|
||||
typedef enum {
|
||||
/** No error. */
|
||||
SSKeychainErrorNone = noErr,
|
||||
|
||||
/** Some of the arguments were invalid. */
|
||||
SSKeychainErrorBadArguments = -1001,
|
||||
|
||||
/** There was no password. */
|
||||
SSKeychainErrorNoPassword = -1002,
|
||||
|
||||
/** One or more parameters passed internally were not valid. */
|
||||
SSKeychainErrorInvalidParameter = errSecParam,
|
||||
|
||||
/** Failed to allocate memory. */
|
||||
SSKeychainErrorFailedToAllocated = errSecAllocate,
|
||||
|
||||
/** No trust results are available. */
|
||||
SSKeychainErrorNotAvailable = errSecNotAvailable,
|
||||
|
||||
/** Authorization/Authentication failed. */
|
||||
SSKeychainErrorAuthorizationFailed = errSecAuthFailed,
|
||||
|
||||
/** The item already exists. */
|
||||
SSKeychainErrorDuplicatedItem = errSecDuplicateItem,
|
||||
|
||||
/** The item cannot be found.*/
|
||||
SSKeychainErrorNotFound = errSecItemNotFound,
|
||||
|
||||
/** Interaction with the Security Server is not allowed. */
|
||||
SSKeychainErrorInteractionNotAllowed = errSecInteractionNotAllowed,
|
||||
|
||||
/** Unable to decode the provided data. */
|
||||
SSKeychainErrorFailedToDecode = errSecDecode
|
||||
} SSKeychainErrorCode;
|
||||
|
||||
extern NSString *const kSSKeychainErrorDomain;
|
||||
|
||||
/** Account name. */
|
||||
extern NSString *const kSSKeychainAccountKey;
|
||||
|
||||
/**
|
||||
Time the item was created.
|
||||
|
||||
The value will be a string.
|
||||
*/
|
||||
extern NSString *const kSSKeychainCreatedAtKey;
|
||||
|
||||
/** Item class. */
|
||||
extern NSString *const kSSKeychainClassKey;
|
||||
|
||||
/** Item description. */
|
||||
extern NSString *const kSSKeychainDescriptionKey;
|
||||
|
||||
/** Item label. */
|
||||
extern NSString *const kSSKeychainLabelKey;
|
||||
|
||||
/** Time the item was last modified.
|
||||
|
||||
The value will be a string.
|
||||
*/
|
||||
extern NSString *const kSSKeychainLastModifiedKey;
|
||||
|
||||
/** Where the item was created. */
|
||||
extern NSString *const kSSKeychainWhereKey;
|
||||
|
||||
/**
|
||||
Simple wrapper for accessing accounts, getting passwords, setting passwords, and deleting passwords using the system
|
||||
Keychain on Mac OS X and iOS.
|
||||
|
||||
This was originally inspired by EMKeychain and SDKeychain (both of which are now gone). Thanks to the authors.
|
||||
SSKeychain has since switched to a simpler implementation that was abstracted from [SSToolkit](http://sstoolk.it).
|
||||
*/
|
||||
@interface SSKeychain : NSObject
|
||||
|
||||
///-----------------------
|
||||
/// @name Getting Accounts
|
||||
///-----------------------
|
||||
|
||||
/**
|
||||
Returns an array containing the Keychain's accounts, or `nil` if the Keychain has no accounts.
|
||||
|
||||
See the `NSString` constants declared in SSKeychain.h for a list of keys that can be used when accessing the
|
||||
dictionaries returned by this method.
|
||||
|
||||
@return An array of dictionaries containing the Keychain's accounts, or `nil` if the Keychain doesn't have any
|
||||
accounts. The order of the objects in the array isn't defined.
|
||||
|
||||
@see allAccounts:
|
||||
*/
|
||||
+ (NSArray *)allAccounts;
|
||||
|
||||
/**
|
||||
Returns an array containing the Keychain's accounts, or `nil` if the Keychain doesn't have any
|
||||
accounts.
|
||||
|
||||
See the `NSString` constants declared in SSKeychain.h for a list of keys that can be used when accessing the
|
||||
dictionaries returned by this method.
|
||||
|
||||
@param error If accessing the accounts fails, upon return contains an error that describes the problem.
|
||||
|
||||
@return An array of dictionaries containing the Keychain's accounts, or `nil` if the Keychain doesn't have any
|
||||
accounts. The order of the objects in the array isn't defined.
|
||||
|
||||
@see allAccounts
|
||||
*/
|
||||
+ (NSArray *)allAccounts:(NSError **)error;
|
||||
|
||||
/**
|
||||
Returns an array containing the Keychain's accounts for a given service, or `nil` if the Keychain doesn't have any
|
||||
accounts for the given service.
|
||||
|
||||
See the `NSString` constants declared in SSKeychain.h for a list of keys that can be used when accessing the
|
||||
dictionaries returned by this method.
|
||||
|
||||
@param serviceName The service for which to return the corresponding accounts.
|
||||
|
||||
@return An array of dictionaries containing the Keychain's accountsfor a given `serviceName`, or `nil` if the Keychain
|
||||
doesn't have any accounts for the given `serviceName`. The order of the objects in the array isn't defined.
|
||||
|
||||
@see accountsForService:error:
|
||||
*/
|
||||
+ (NSArray *)accountsForService:(NSString *)serviceName;
|
||||
|
||||
/**
|
||||
Returns an array containing the Keychain's accounts for a given service, or `nil` if the Keychain doesn't have any
|
||||
accounts for the given service.
|
||||
|
||||
@param serviceName The service for which to return the corresponding accounts.
|
||||
|
||||
@param error If accessing the accounts fails, upon return contains an error that describes the problem.
|
||||
|
||||
@return An array of dictionaries containing the Keychain's accountsfor a given `serviceName`, or `nil` if the Keychain
|
||||
doesn't have any accounts for the given `serviceName`. The order of the objects in the array isn't defined.
|
||||
|
||||
@see accountsForService:
|
||||
*/
|
||||
+ (NSArray *)accountsForService:(NSString *)serviceName error:(NSError **)error;
|
||||
|
||||
|
||||
///------------------------
|
||||
/// @name Getting Passwords
|
||||
///------------------------
|
||||
|
||||
/**
|
||||
Returns a string containing the password for a given account and service, or `nil` if the Keychain doesn't have a
|
||||
password for the given parameters.
|
||||
|
||||
@param serviceName The service for which to return the corresponding password.
|
||||
|
||||
@param account The account for which to return the corresponding password.
|
||||
|
||||
@return Returns a string containing the password for a given account and service, or `nil` if the Keychain doesn't
|
||||
have a password for the given parameters.
|
||||
|
||||
@see passwordForService:account:error:
|
||||
*/
|
||||
+ (NSString *)passwordForService:(NSString *)serviceName account:(NSString *)account;
|
||||
|
||||
/**
|
||||
Returns a string containing the password for a given account and service, or `nil` if the Keychain doesn't have a
|
||||
password for the given parameters.
|
||||
|
||||
@param serviceName The service for which to return the corresponding password.
|
||||
|
||||
@param account The account for which to return the corresponding password.
|
||||
|
||||
@param error If accessing the password fails, upon return contains an error that describes the problem.
|
||||
|
||||
@return Returns a string containing the password for a given account and service, or `nil` if the Keychain doesn't
|
||||
have a password for the given parameters.
|
||||
|
||||
@see passwordForService:account:
|
||||
*/
|
||||
+ (NSString *)passwordForService:(NSString *)serviceName account:(NSString *)account error:(NSError **)error;
|
||||
|
||||
/**
|
||||
Returns the password data for a given account and service, or `nil` if the Keychain doesn't have data
|
||||
for the given parameters.
|
||||
|
||||
@param serviceName The service for which to return the corresponding password.
|
||||
|
||||
@param account The account for which to return the corresponding password.
|
||||
|
||||
@param error If accessing the password fails, upon return contains an error that describes the problem.
|
||||
|
||||
@return Returns a the password data for the given account and service, or `nil` if the Keychain doesn't
|
||||
have data for the given parameters.
|
||||
|
||||
@see passwordDataForService:account:error:
|
||||
*/
|
||||
+ (NSData *)passwordDataForService:(NSString *)serviceName account:(NSString *)account;
|
||||
|
||||
/**
|
||||
Returns the password data for a given account and service, or `nil` if the Keychain doesn't have data
|
||||
for the given parameters.
|
||||
|
||||
@param serviceName The service for which to return the corresponding password.
|
||||
|
||||
@param account The account for which to return the corresponding password.
|
||||
|
||||
@param error If accessing the password fails, upon return contains an error that describes the problem.
|
||||
|
||||
@return Returns a the password data for the given account and service, or `nil` if the Keychain doesn't
|
||||
have a password for the given parameters.
|
||||
|
||||
@see passwordDataForService:account:
|
||||
*/
|
||||
+ (NSData *)passwordDataForService:(NSString *)serviceName account:(NSString *)account error:(NSError **)error;
|
||||
|
||||
|
||||
///-------------------------
|
||||
/// @name Deleting Passwords
|
||||
///-------------------------
|
||||
|
||||
/**
|
||||
Deletes a password from the Keychain.
|
||||
|
||||
@param serviceName The service for which to delete the corresponding password.
|
||||
|
||||
@param account The account for which to delete the corresponding password.
|
||||
|
||||
@return Returns `YES` on success, or `NO` on failure.
|
||||
|
||||
@see deletePasswordForService:account:error:
|
||||
*/
|
||||
+ (BOOL)deletePasswordForService:(NSString *)serviceName account:(NSString *)account;
|
||||
|
||||
/**
|
||||
Deletes a password from the Keychain.
|
||||
|
||||
@param serviceName The service for which to delete the corresponding password.
|
||||
|
||||
@param account The account for which to delete the corresponding password.
|
||||
|
||||
@param error If deleting the password fails, upon return contains an error that describes the problem.
|
||||
|
||||
@return Returns `YES` on success, or `NO` on failure.
|
||||
|
||||
@see deletePasswordForService:account:
|
||||
*/
|
||||
+ (BOOL)deletePasswordForService:(NSString *)serviceName account:(NSString *)account error:(NSError **)error;
|
||||
|
||||
|
||||
///------------------------
|
||||
/// @name Setting Passwords
|
||||
///------------------------
|
||||
|
||||
/**
|
||||
Sets a password in the Keychain.
|
||||
|
||||
@param password The password to store in the Keychain.
|
||||
|
||||
@param serviceName The service for which to set the corresponding password.
|
||||
|
||||
@param account The account for which to set the corresponding password.
|
||||
|
||||
@return Returns `YES` on success, or `NO` on failure.
|
||||
|
||||
@see setPassword:forService:account:error:
|
||||
*/
|
||||
+ (BOOL)setPassword:(NSString *)password forService:(NSString *)serviceName account:(NSString *)account;
|
||||
|
||||
/**
|
||||
Sets a password in the Keychain.
|
||||
|
||||
@param password The password to store in the Keychain.
|
||||
|
||||
@param serviceName The service for which to set the corresponding password.
|
||||
|
||||
@param account The account for which to set the corresponding password.
|
||||
|
||||
@param error If setting the password fails, upon return contains an error that describes the problem.
|
||||
|
||||
@return Returns `YES` on success, or `NO` on failure.
|
||||
|
||||
@see setPassword:forService:account:
|
||||
*/
|
||||
+ (BOOL)setPassword:(NSString *)password forService:(NSString *)serviceName account:(NSString *)account error:(NSError **)error;
|
||||
|
||||
/**
|
||||
Sets arbirary data in the Keychain.
|
||||
|
||||
@param password The data to store in the Keychain.
|
||||
|
||||
@param serviceName The service for which to set the corresponding password.
|
||||
|
||||
@param account The account for which to set the corresponding password.
|
||||
|
||||
@param error If setting the password fails, upon return contains an error that describes the problem.
|
||||
|
||||
@return Returns `YES` on success, or `NO` on failure.
|
||||
|
||||
@see setPasswordData:forService:account:error:
|
||||
*/
|
||||
+ (BOOL)setPasswordData:(NSData *)password forService:(NSString *)serviceName account:(NSString *)account;
|
||||
|
||||
/**
|
||||
Sets arbirary data in the Keychain.
|
||||
|
||||
@param password The data to store in the Keychain.
|
||||
|
||||
@param serviceName The service for which to set the corresponding password.
|
||||
|
||||
@param account The account for which to set the corresponding password.
|
||||
|
||||
@param error If setting the password fails, upon return contains an error that describes the problem.
|
||||
|
||||
@return Returns `YES` on success, or `NO` on failure.
|
||||
|
||||
@see setPasswordData:forService:account:
|
||||
*/
|
||||
+ (BOOL)setPasswordData:(NSData *)password forService:(NSString *)serviceName account:(NSString *)account error:(NSError **)error;
|
||||
|
||||
|
||||
///--------------------
|
||||
/// @name Configuration
|
||||
///--------------------
|
||||
|
||||
#if __IPHONE_4_0 && TARGET_OS_IPHONE
|
||||
/**
|
||||
Returns the accessibility type for all future passwords saved to the Keychain.
|
||||
|
||||
@return Returns the accessibility type.
|
||||
|
||||
The return value will be `NULL` or one of the "Keychain Item Accessibility Constants" used for determining when a
|
||||
keychain item should be readable.
|
||||
|
||||
@see accessibilityType
|
||||
*/
|
||||
+ (CFTypeRef)accessibilityType;
|
||||
|
||||
/**
|
||||
Sets the accessibility type for all future passwords saved to the Keychain.
|
||||
|
||||
@param accessibilityType One of the "Keychain Item Accessibility Constants" used for determining when a keychain item
|
||||
should be readable.
|
||||
|
||||
If the value is `NULL` (the default), the Keychain default will be used.
|
||||
|
||||
@see accessibilityType
|
||||
*/
|
||||
+ (void)setAccessibilityType:(CFTypeRef)accessibilityType;
|
||||
#endif
|
||||
|
||||
@end
|
262
Classes_cocos/SSKeychain.m
Normal file
262
Classes_cocos/SSKeychain.m
Normal file
@ -0,0 +1,262 @@
|
||||
//
|
||||
// SSKeychain.m
|
||||
// SSToolkit
|
||||
//
|
||||
// Created by Sam Soffes on 5/19/10.
|
||||
// Copyright (c) 2009-2011 Sam Soffes. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SSKeychain.h"
|
||||
|
||||
NSString *const kSSKeychainErrorDomain = @"com.samsoffes.sskeychain";
|
||||
|
||||
NSString *const kSSKeychainAccountKey = @"acct";
|
||||
NSString *const kSSKeychainCreatedAtKey = @"cdat";
|
||||
NSString *const kSSKeychainClassKey = @"labl";
|
||||
NSString *const kSSKeychainDescriptionKey = @"desc";
|
||||
NSString *const kSSKeychainLabelKey = @"labl";
|
||||
NSString *const kSSKeychainLastModifiedKey = @"mdat";
|
||||
NSString *const kSSKeychainWhereKey = @"svce";
|
||||
|
||||
#if __IPHONE_4_0 && TARGET_OS_IPHONE
|
||||
CFTypeRef SSKeychainAccessibilityType = NULL;
|
||||
#endif
|
||||
|
||||
@interface SSKeychain ()
|
||||
+ (NSMutableDictionary *)_queryForService:(NSString *)service account:(NSString *)account;
|
||||
@end
|
||||
|
||||
@implementation SSKeychain
|
||||
|
||||
#pragma mark - Getting Accounts
|
||||
|
||||
+ (NSArray *)allAccounts {
|
||||
return [self accountsForService:nil error:nil];
|
||||
}
|
||||
|
||||
|
||||
+ (NSArray *)allAccounts:(NSError **)error {
|
||||
return [self accountsForService:nil error:error];
|
||||
}
|
||||
|
||||
|
||||
+ (NSArray *)accountsForService:(NSString *)service {
|
||||
return [self accountsForService:service error:nil];
|
||||
}
|
||||
|
||||
|
||||
+ (NSArray *)accountsForService:(NSString *)service error:(NSError **)error {
|
||||
OSStatus status = SSKeychainErrorBadArguments;
|
||||
NSMutableDictionary *query = [self _queryForService:service account:nil];
|
||||
#if __has_feature(objc_arc)
|
||||
[query setObject:(__bridge id)kCFBooleanTrue forKey:(__bridge id)kSecReturnAttributes];
|
||||
[query setObject:(__bridge id)kSecMatchLimitAll forKey:(__bridge id)kSecMatchLimit];
|
||||
#else
|
||||
[query setObject:(id)kCFBooleanTrue forKey:(id)kSecReturnAttributes];
|
||||
[query setObject:(id)kSecMatchLimitAll forKey:(id)kSecMatchLimit];
|
||||
#endif
|
||||
|
||||
CFTypeRef result = NULL;
|
||||
#if __has_feature(objc_arc)
|
||||
status = SecItemCopyMatching((__bridge CFDictionaryRef)query, &result);
|
||||
#else
|
||||
status = SecItemCopyMatching((CFDictionaryRef)query, &result);
|
||||
#endif
|
||||
if (status != noErr && error != NULL) {
|
||||
*error = [NSError errorWithDomain:kSSKeychainErrorDomain code:status userInfo:nil];
|
||||
return nil;
|
||||
}
|
||||
|
||||
#if __has_feature(objc_arc)
|
||||
return (__bridge_transfer NSArray *)result;
|
||||
#else
|
||||
return [(NSArray *)result autorelease];
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#pragma mark - Getting Passwords
|
||||
|
||||
+ (NSString *)passwordForService:(NSString *)service account:(NSString *)account {
|
||||
return [self passwordForService:service account:account error:nil];
|
||||
}
|
||||
|
||||
|
||||
+ (NSString *)passwordForService:(NSString *)service account:(NSString *)account error:(NSError **)error {
|
||||
NSData *data = [self passwordDataForService:service account:account error:error];
|
||||
if (data.length > 0) {
|
||||
NSString *string = [[NSString alloc] initWithData:(NSData *)data encoding:NSUTF8StringEncoding];
|
||||
#if !__has_feature(objc_arc)
|
||||
[string autorelease];
|
||||
#endif
|
||||
return string;
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
||||
+ (NSData *)passwordDataForService:(NSString *)service account:(NSString *)account {
|
||||
return [self passwordDataForService:service account:account error:nil];
|
||||
}
|
||||
|
||||
|
||||
+ (NSData *)passwordDataForService:(NSString *)service account:(NSString *)account error:(NSError **)error {
|
||||
OSStatus status = SSKeychainErrorBadArguments;
|
||||
if (!service || !account) {
|
||||
if (error) {
|
||||
*error = [NSError errorWithDomain:kSSKeychainErrorDomain code:status userInfo:nil];
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
CFTypeRef result = NULL;
|
||||
NSMutableDictionary *query = [self _queryForService:service account:account];
|
||||
#if __has_feature(objc_arc)
|
||||
[query setObject:(__bridge id)kCFBooleanTrue forKey:(__bridge id)kSecReturnData];
|
||||
[query setObject:(__bridge id)kSecMatchLimitOne forKey:(__bridge id)kSecMatchLimit];
|
||||
status = SecItemCopyMatching((__bridge CFDictionaryRef)query, &result);
|
||||
#else
|
||||
[query setObject:(id)kCFBooleanTrue forKey:(id)kSecReturnData];
|
||||
[query setObject:(id)kSecMatchLimitOne forKey:(id)kSecMatchLimit];
|
||||
status = SecItemCopyMatching((CFDictionaryRef)query, &result);
|
||||
#endif
|
||||
|
||||
if (status != noErr && error != NULL) {
|
||||
*error = [NSError errorWithDomain:kSSKeychainErrorDomain code:status userInfo:nil];
|
||||
return nil;
|
||||
}
|
||||
|
||||
#if __has_feature(objc_arc)
|
||||
return (__bridge_transfer NSData *)result;
|
||||
#else
|
||||
return [(NSData *)result autorelease];
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#pragma mark - Deleting Passwords
|
||||
|
||||
+ (BOOL)deletePasswordForService:(NSString *)service account:(NSString *)account {
|
||||
return [self deletePasswordForService:service account:account error:nil];
|
||||
}
|
||||
|
||||
|
||||
+ (BOOL)deletePasswordForService:(NSString *)service account:(NSString *)account error:(NSError **)error {
|
||||
OSStatus status = SSKeychainErrorBadArguments;
|
||||
if (service && account) {
|
||||
NSMutableDictionary *query = [self _queryForService:service account:account];
|
||||
#if __has_feature(objc_arc)
|
||||
status = SecItemDelete((__bridge CFDictionaryRef)query);
|
||||
#else
|
||||
status = SecItemDelete((CFDictionaryRef)query);
|
||||
#endif
|
||||
}
|
||||
if (status != noErr && error != NULL) {
|
||||
*error = [NSError errorWithDomain:kSSKeychainErrorDomain code:status userInfo:nil];
|
||||
}
|
||||
return (status == noErr);
|
||||
|
||||
}
|
||||
|
||||
|
||||
#pragma mark - Setting Passwords
|
||||
|
||||
+ (BOOL)setPassword:(NSString *)password forService:(NSString *)service account:(NSString *)account {
|
||||
return [self setPassword:password forService:service account:account error:nil];
|
||||
}
|
||||
|
||||
|
||||
+ (BOOL)setPassword:(NSString *)password forService:(NSString *)service account:(NSString *)account error:(NSError **)error {
|
||||
NSData *data = [password dataUsingEncoding:NSUTF8StringEncoding];
|
||||
return [self setPasswordData:data forService:service account:account error:error];
|
||||
}
|
||||
|
||||
|
||||
+ (BOOL)setPasswordData:(NSData *)password forService:(NSString *)service account:(NSString *)account {
|
||||
return [self setPasswordData:password forService:service account:account error:nil];
|
||||
}
|
||||
|
||||
|
||||
+ (BOOL)setPasswordData:(NSData *)password forService:(NSString *)service account:(NSString *)account error:(NSError **)error {
|
||||
OSStatus status = SSKeychainErrorBadArguments;
|
||||
if (password && service && account) {
|
||||
[self deletePasswordForService:service account:account];
|
||||
NSMutableDictionary *query = [self _queryForService:service account:account];
|
||||
#if __has_feature(objc_arc)
|
||||
[query setObject:password forKey:(__bridge id)kSecValueData];
|
||||
#else
|
||||
[query setObject:password forKey:(id)kSecValueData];
|
||||
#endif
|
||||
|
||||
#if __IPHONE_4_0 && TARGET_OS_IPHONE
|
||||
if (SSKeychainAccessibilityType) {
|
||||
#if __has_feature(objc_arc)
|
||||
[query setObject:(id)[self accessibilityType] forKey:(__bridge id)kSecAttrAccessible];
|
||||
#else
|
||||
[query setObject:(id)[self accessibilityType] forKey:(id)kSecAttrAccessible];
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#if __has_feature(objc_arc)
|
||||
status = SecItemAdd((__bridge CFDictionaryRef)query, NULL);
|
||||
#else
|
||||
status = SecItemAdd((CFDictionaryRef)query, NULL);
|
||||
#endif
|
||||
}
|
||||
if (status != noErr && error != NULL) {
|
||||
*error = [NSError errorWithDomain:kSSKeychainErrorDomain code:status userInfo:nil];
|
||||
}
|
||||
return (status == noErr);
|
||||
}
|
||||
|
||||
|
||||
#pragma mark - Configuration
|
||||
|
||||
#if __IPHONE_4_0 && TARGET_OS_IPHONE
|
||||
+ (CFTypeRef)accessibilityType {
|
||||
return SSKeychainAccessibilityType;
|
||||
}
|
||||
|
||||
|
||||
+ (void)setAccessibilityType:(CFTypeRef)accessibilityType {
|
||||
CFRetain(accessibilityType);
|
||||
if (SSKeychainAccessibilityType) {
|
||||
CFRelease(SSKeychainAccessibilityType);
|
||||
}
|
||||
SSKeychainAccessibilityType = accessibilityType;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#pragma mark - Private
|
||||
|
||||
+ (NSMutableDictionary *)_queryForService:(NSString *)service account:(NSString *)account {
|
||||
NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithCapacity:3];
|
||||
#if __has_feature(objc_arc)
|
||||
[dictionary setObject:(__bridge id)kSecClassGenericPassword forKey:(__bridge id)kSecClass];
|
||||
#else
|
||||
[dictionary setObject:(id)kSecClassGenericPassword forKey:(id)kSecClass];
|
||||
#endif
|
||||
|
||||
if (service) {
|
||||
#if __has_feature(objc_arc)
|
||||
[dictionary setObject:service forKey:(__bridge id)kSecAttrService];
|
||||
#else
|
||||
[dictionary setObject:service forKey:(id)kSecAttrService];
|
||||
#endif
|
||||
}
|
||||
|
||||
if (account) {
|
||||
#if __has_feature(objc_arc)
|
||||
[dictionary setObject:account forKey:(__bridge id)kSecAttrAccount];
|
||||
#else
|
||||
[dictionary setObject:account forKey:(id)kSecAttrAccount];
|
||||
#endif
|
||||
}
|
||||
|
||||
return dictionary;
|
||||
}
|
||||
|
||||
@end
|
@ -14,8 +14,10 @@
|
||||
|
||||
+(void)toWallet:(NSString *)url;
|
||||
-(void)scanQRCode:(NSString *)funid title:(NSString *) title;
|
||||
-(void)showQRCode:(NSString *)funid content:(NSString *) content title:(NSString *) title oid:(NSString *) oid;
|
||||
-(void)showQRCode:(NSString *) content title:(NSString *) title oid:(NSString *) oid;
|
||||
-(void)loadRestoreKey:(NSString *)funid oid:(NSString *) oid;
|
||||
-(void)signWithGoogle:(NSString *)funid;
|
||||
-(void)signOutGoogle:(NSString *)funid;
|
||||
-(void)saveKey:(NSString *) account key:(NSString *) key;
|
||||
-(NSString *)loadKey:(NSString *) account;
|
||||
@end
|
||||
|
@ -13,10 +13,12 @@
|
||||
#include "WalletEvent.h"
|
||||
#include "JcWallet.h"
|
||||
#import <GoogleSignIn/GoogleSignIn.h>
|
||||
#include "SSKeychain.h"
|
||||
@import GoogleSignIn;
|
||||
|
||||
static NSString * const kClientID =
|
||||
@"53206975661-qan0rnefniegjv53ohild375pv0p7ekd.apps.googleusercontent.com";
|
||||
@"53206975661-0d6q9pqljn84n9l63gm0to1ulap9cbk4.apps.googleusercontent.com";
|
||||
static NSString * const cebgWalletService = @"CEBG-wallet";
|
||||
|
||||
@implementation UIViewController (Wallet)
|
||||
|
||||
@ -25,11 +27,28 @@ static NSString * const kClientID =
|
||||
[app openURL:[NSURL URLWithString:url]];
|
||||
}
|
||||
|
||||
-(void)showQRCode:(NSString *)funid content:(NSString *) content title:(NSString *) title oid:(NSString *) oid {
|
||||
|
||||
-(void)showQRCode:(NSString *) content title:(NSString *) title oid:(NSString *) oid {
|
||||
NSLog(@"showQRCode content: %@, title: %@, oid: %@", content, title, oid);
|
||||
}
|
||||
-(void)loadRestoreKey:(NSString *)funid oid:(NSString *) oid{
|
||||
|
||||
NSLog(@"loadRestoreKey::funid: %@, oid:%@", funid, oid);
|
||||
}
|
||||
-(void)saveKey:(NSString *) account key:(NSString *) key {
|
||||
NSLog(@"saveKey::account:%@, key: %@", account, key);
|
||||
[SSKeychain setPassword:key forService:cebgWalletService account:account];
|
||||
[SSKeychain setAccessibilityType:kSecAttrAccessibleWhenUnlocked];
|
||||
}
|
||||
-(NSString *)loadKey:(NSString *) account {
|
||||
NSLog(@"loadKey::account:%@", account);
|
||||
NSError *error = nil;
|
||||
NSString *password = [SSKeychain passwordForService:cebgWalletService account:account error:&error];
|
||||
if ([error code] == SSKeychainErrorNotFound) {
|
||||
NSLog(@"password not found, account: %@", account);
|
||||
return @"";
|
||||
} else {
|
||||
NSLog(@"password for %@ is %@", account, password);
|
||||
return password;
|
||||
}
|
||||
}
|
||||
|
||||
-(void)scanQRCode:(NSString *)funid title:(NSString *) title{
|
||||
|
@ -27,7 +27,7 @@
|
||||
<string>Editor</string>
|
||||
<key>CFBundleURLSchemes</key>
|
||||
<array>
|
||||
<string>com.googleusercontent.apps.165555585193-alshovj5m91vlmj8uuhb11e6msvq32gm</string>
|
||||
<string>com.googleusercontent.apps.53206975661-0d6q9pqljn84n9l63gm0to1ulap9cbk4</string>
|
||||
</array>
|
||||
</dict>
|
||||
</array>
|
||||
|
2
Podfile
2
Podfile
@ -2,5 +2,5 @@ platform :ios, '9.0'
|
||||
use_frameworks!
|
||||
|
||||
target 'Unity-iPhone' do
|
||||
pod 'GoogleSignIn', :path => '/Users/zhl/Downloads/sourcecode/ios/GoogleSignIn-iOS/'
|
||||
pod 'GoogleSignIn', :path => '/Users/zhl/Downloads/sourcecode/google/GoogleSignIn-iOS/'
|
||||
end
|
||||
|
@ -80,6 +80,8 @@
|
||||
D52A8DA1288E6547006574E8 /* libuv_a.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D52A8D9F288E6547006574E8 /* libuv_a.a */; };
|
||||
D5538BA5287E9908000BDFB6 /* WalletEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D5538BA3287E9908000BDFB6 /* WalletEvent.cpp */; };
|
||||
D589C9BB28B62D93002CAA34 /* cacert.pem in Resources */ = {isa = PBXBuildFile; fileRef = D589C9B928B62D93002CAA34 /* cacert.pem */; };
|
||||
D59AB424292DBACE00714392 /* CloudKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D59AB423292DBACE00714392 /* CloudKit.framework */; };
|
||||
D59AB427292DD91D00714392 /* SSKeychain.m in Sources */ = {isa = PBXBuildFile; fileRef = D59AB426292DD91D00714392 /* SSKeychain.m */; };
|
||||
D5AB1D3328BF782300AA6AFA /* QRToggleTorchButton.m in Sources */ = {isa = PBXBuildFile; fileRef = D5AB1D2928BF782200AA6AFA /* QRToggleTorchButton.m */; };
|
||||
D5AB1D3428BF782300AA6AFA /* QRCameraSwitchButton.m in Sources */ = {isa = PBXBuildFile; fileRef = D5AB1D2B28BF782200AA6AFA /* QRCameraSwitchButton.m */; };
|
||||
D5AB1D3528BF782300AA6AFA /* QRCodeReaderViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D5AB1D2D28BF782200AA6AFA /* QRCodeReaderViewController.m */; };
|
||||
@ -362,6 +364,10 @@
|
||||
D5538BA3287E9908000BDFB6 /* WalletEvent.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WalletEvent.cpp; sourceTree = "<group>"; };
|
||||
D5538BA4287E9908000BDFB6 /* WalletEvent.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WalletEvent.h; sourceTree = "<group>"; };
|
||||
D589C9B928B62D93002CAA34 /* cacert.pem */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = cacert.pem; sourceTree = "<group>"; };
|
||||
D59AB422292DBABA00714392 /* Unity-iPhone.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; name = "Unity-iPhone.entitlements"; path = "Unity-iPhone/Unity-iPhone.entitlements"; sourceTree = "<group>"; };
|
||||
D59AB423292DBACE00714392 /* CloudKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CloudKit.framework; path = System/Library/Frameworks/CloudKit.framework; sourceTree = SDKROOT; };
|
||||
D59AB425292DD8E500714392 /* SSKeychain.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SSKeychain.h; sourceTree = "<group>"; };
|
||||
D59AB426292DD91D00714392 /* SSKeychain.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SSKeychain.m; sourceTree = "<group>"; };
|
||||
D5AB1D2828BF782200AA6AFA /* QRCodeReaderView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QRCodeReaderView.h; sourceTree = "<group>"; };
|
||||
D5AB1D2928BF782200AA6AFA /* QRToggleTorchButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QRToggleTorchButton.m; sourceTree = "<group>"; };
|
||||
D5AB1D2A28BF782200AA6AFA /* QRCodeReaderDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QRCodeReaderDelegate.h; sourceTree = "<group>"; };
|
||||
@ -523,6 +529,7 @@
|
||||
D52A8DA1288E6547006574E8 /* libuv_a.a in Frameworks */,
|
||||
56FD43960ED4745200FE3770 /* CFNetwork.framework in Frameworks */,
|
||||
56B7959B1442E0F20026B3DD /* CoreGraphics.framework in Frameworks */,
|
||||
D59AB424292DBACE00714392 /* CloudKit.framework in Frameworks */,
|
||||
7F36C11113C5C673007FBDD9 /* CoreMedia.framework in Frameworks */,
|
||||
56B7960F1442E1770026B3DD /* CoreMotion.framework in Frameworks */,
|
||||
7F36C11213C5C673007FBDD9 /* CoreVideo.framework in Frameworks */,
|
||||
@ -564,6 +571,7 @@
|
||||
29B97314FDCFA39411CA2CEA /* CustomTemplate */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
D59AB422292DBABA00714392 /* Unity-iPhone.entitlements */,
|
||||
D589C9B928B62D93002CAA34 /* cacert.pem */,
|
||||
D5AB1D2728BF782200AA6AFA /* QRCodeReaderViewController */,
|
||||
D5F2CFD1287BF83C003C2B62 /* js */,
|
||||
@ -591,6 +599,7 @@
|
||||
29B97323FDCFA39411CA2CEA /* Frameworks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
D59AB423292DBACE00714392 /* CloudKit.framework */,
|
||||
D5F2CFCF287BF80A003C2B62 /* libz.tbd */,
|
||||
D5F2CFCD287BF7FE003C2B62 /* JavaScriptCore.framework */,
|
||||
D5F2CFCB287BF7ED003C2B62 /* libsqlite3.tbd */,
|
||||
@ -890,6 +899,8 @@
|
||||
D5F2D104287C12DD003C2B62 /* JcWallet.mm */,
|
||||
D5538BA4287E9908000BDFB6 /* WalletEvent.h */,
|
||||
D5538BA3287E9908000BDFB6 /* WalletEvent.cpp */,
|
||||
D59AB425292DD8E500714392 /* SSKeychain.h */,
|
||||
D59AB426292DD91D00714392 /* SSKeychain.m */,
|
||||
);
|
||||
path = Classes_cocos;
|
||||
sourceTree = "<group>";
|
||||
@ -994,7 +1005,7 @@
|
||||
attributes = {
|
||||
TargetAttributes = {
|
||||
1D6058900D05DD3D006BFB54 = {
|
||||
DevelopmentTeam = 3M965CAG25;
|
||||
DevelopmentTeam = 299H75LKGK;
|
||||
ProvisioningStyle = Automatic;
|
||||
SystemCapabilities = {
|
||||
com.apple.GameControllers.appletvos = {
|
||||
@ -1268,6 +1279,7 @@
|
||||
D5F2D106287C12DD003C2B62 /* JcWallet.mm in Sources */,
|
||||
D5F2CF8B287BEC0D003C2B62 /* Bulk_System.Diagnostics.StackTrace_0.cpp in Sources */,
|
||||
D5F2CF63287BEC0D003C2B62 /* Il2CppCompilerCalculateTypeValues_10Table.cpp in Sources */,
|
||||
D59AB427292DD91D00714392 /* SSKeychain.m in Sources */,
|
||||
D5F2CF88287BEC0D003C2B62 /* Bulk_UnityEngine.UIModule_0.cpp in Sources */,
|
||||
D5F2CF5E287BEC0D003C2B62 /* GenericMethods3.cpp in Sources */,
|
||||
D5F2CF72287BEC0D003C2B62 /* Bulk_mscorlib_2.cpp in Sources */,
|
||||
@ -1336,10 +1348,7 @@
|
||||
baseConfigurationReference = 64D951E2E197936FF46DBB4A /* Pods-Unity-iPhone.debug.xcconfig */;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
ARCHS = (
|
||||
armv7,
|
||||
arm64,
|
||||
);
|
||||
ARCHS = arm64;
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++17";
|
||||
@ -1347,11 +1356,12 @@
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CLANG_ENABLE_OBJC_ARC = YES;
|
||||
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
|
||||
CODE_SIGN_ENTITLEMENTS = "Unity-iPhone/Unity-iPhone.entitlements";
|
||||
CODE_SIGN_IDENTITY = "Apple Development";
|
||||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
COPY_PHASE_STRIP = NO;
|
||||
DEVELOPMENT_TEAM = 3M965CAG25;
|
||||
DEVELOPMENT_TEAM = 299H75LKGK;
|
||||
ENABLE_BITCODE = NO;
|
||||
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
|
||||
GCC_DYNAMIC_NO_PIC = NO;
|
||||
@ -1410,6 +1420,7 @@
|
||||
TARGETED_DEVICE_FAMILY = "1,2";
|
||||
UNITY_RUNTIME_VERSION = 2018.4.23f1;
|
||||
UNITY_SCRIPTING_BACKEND = il2cpp;
|
||||
USER_HEADER_SEARCH_PATHS = "/Users/zhl/Documents/workspace/cocos/cocos2d-x /Users/zhl/Documents/workspace/cocos/cocos2d-x/cocos /Users/zhl/Documents/workspace/cocos/cocos2d-x/cocos/network /Users/zhl/Documents/workspace/cocos/cocos2d-x/cocos/base /Users/zhl/Documents/workspace/cocos/cocos2d-x/extensions /Users/zhl/Documents/workspace/cocos/cocos2d-x/external /Users/zhl/Documents/workspace/cocos/cocos2d-x/external/sources /Users/zhl/Documents/workspace/cocos/cocos2d-x/external/chipmunk/include/chipmunk /Users/zhl/Documents/workspace/cocos/cocos2d-x/cocos/scripting/js-bindings/manual /Users/zhl/Documents/workspace/cocos/cocos2d-x/cocos/scrypt /Users/zhl/Documents/workspace/cocos/cocos2d-x/external/ios/include/uv /Users/zhl/Documents/workspace/cocos/cocos2d-x/external/ios/include/rustwallet";
|
||||
WARNING_CFLAGS = (
|
||||
"$(inherited)",
|
||||
"-Wno-missing-declarations",
|
||||
@ -1425,10 +1436,7 @@
|
||||
baseConfigurationReference = B41A4D99DD320B1E06F51AE6 /* Pods-Unity-iPhone.release.xcconfig */;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
ARCHS = (
|
||||
armv7,
|
||||
arm64,
|
||||
);
|
||||
ARCHS = arm64;
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++17";
|
||||
@ -1436,11 +1444,12 @@
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CLANG_ENABLE_OBJC_ARC = YES;
|
||||
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
|
||||
CODE_SIGN_ENTITLEMENTS = "Unity-iPhone/Unity-iPhone.entitlements";
|
||||
CODE_SIGN_IDENTITY = "Apple Development";
|
||||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
COPY_PHASE_STRIP = YES;
|
||||
DEVELOPMENT_TEAM = 3M965CAG25;
|
||||
DEVELOPMENT_TEAM = 299H75LKGK;
|
||||
ENABLE_BITCODE = NO;
|
||||
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
|
||||
GCC_ENABLE_CPP_EXCEPTIONS = YES;
|
||||
@ -1496,6 +1505,7 @@
|
||||
TARGETED_DEVICE_FAMILY = "1,2";
|
||||
UNITY_RUNTIME_VERSION = 2018.4.23f1;
|
||||
UNITY_SCRIPTING_BACKEND = il2cpp;
|
||||
USER_HEADER_SEARCH_PATHS = "/Users/zhl/Documents/workspace/cocos/cocos2d-x /Users/zhl/Documents/workspace/cocos/cocos2d-x/cocos /Users/zhl/Documents/workspace/cocos/cocos2d-x/cocos/network /Users/zhl/Documents/workspace/cocos/cocos2d-x/cocos/base /Users/zhl/Documents/workspace/cocos/cocos2d-x/extensions /Users/zhl/Documents/workspace/cocos/cocos2d-x/external /Users/zhl/Documents/workspace/cocos/cocos2d-x/external/sources /Users/zhl/Documents/workspace/cocos/cocos2d-x/external/chipmunk/include/chipmunk /Users/zhl/Documents/workspace/cocos/cocos2d-x/cocos/scripting/js-bindings/manual /Users/zhl/Documents/workspace/cocos/cocos2d-x/cocos/scrypt /Users/zhl/Documents/workspace/cocos/cocos2d-x/external/ios/include/uv /Users/zhl/Documents/workspace/cocos/cocos2d-x/external/ios/include/rustwallet";
|
||||
WARNING_CFLAGS = (
|
||||
"$(inherited)",
|
||||
"-Wno-missing-declarations",
|
||||
@ -1617,7 +1627,7 @@
|
||||
56E860801D6757FF00A1AB2B /* ReleaseForRunning */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ARCHS = armv7;
|
||||
ARCHS = arm64;
|
||||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
||||
ENABLE_BITCODE = NO;
|
||||
GCC_C_LANGUAGE_STANDARD = c99;
|
||||
@ -1640,10 +1650,7 @@
|
||||
baseConfigurationReference = DF09136C644F6C0DE6044DC4 /* Pods-Unity-iPhone.releaseforrunning.xcconfig */;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
ARCHS = (
|
||||
armv7,
|
||||
arm64,
|
||||
);
|
||||
ARCHS = arm64;
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++17";
|
||||
@ -1651,12 +1658,13 @@
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CLANG_ENABLE_OBJC_ARC = YES;
|
||||
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
|
||||
CODE_SIGN_ENTITLEMENTS = "Unity-iPhone/Unity-iPhone.entitlements";
|
||||
CODE_SIGN_IDENTITY = "Apple Development";
|
||||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
COPY_PHASE_STRIP = YES;
|
||||
DEBUG_INFORMATION_FORMAT = dwarf;
|
||||
DEVELOPMENT_TEAM = 3M965CAG25;
|
||||
DEVELOPMENT_TEAM = 299H75LKGK;
|
||||
ENABLE_BITCODE = NO;
|
||||
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
|
||||
GCC_ENABLE_CPP_EXCEPTIONS = YES;
|
||||
@ -1712,6 +1720,7 @@
|
||||
TARGETED_DEVICE_FAMILY = "1,2";
|
||||
UNITY_RUNTIME_VERSION = 2018.4.23f1;
|
||||
UNITY_SCRIPTING_BACKEND = il2cpp;
|
||||
USER_HEADER_SEARCH_PATHS = "/Users/zhl/Documents/workspace/cocos/cocos2d-x /Users/zhl/Documents/workspace/cocos/cocos2d-x/cocos /Users/zhl/Documents/workspace/cocos/cocos2d-x/cocos/network /Users/zhl/Documents/workspace/cocos/cocos2d-x/cocos/base /Users/zhl/Documents/workspace/cocos/cocos2d-x/extensions /Users/zhl/Documents/workspace/cocos/cocos2d-x/external /Users/zhl/Documents/workspace/cocos/cocos2d-x/external/sources /Users/zhl/Documents/workspace/cocos/cocos2d-x/external/chipmunk/include/chipmunk /Users/zhl/Documents/workspace/cocos/cocos2d-x/cocos/scripting/js-bindings/manual /Users/zhl/Documents/workspace/cocos/cocos2d-x/cocos/scrypt /Users/zhl/Documents/workspace/cocos/cocos2d-x/external/ios/include/uv /Users/zhl/Documents/workspace/cocos/cocos2d-x/external/ios/include/rustwallet";
|
||||
WARNING_CFLAGS = (
|
||||
"$(inherited)",
|
||||
"-Wno-missing-declarations",
|
||||
@ -1776,7 +1785,7 @@
|
||||
56E860831D67581C00A1AB2B /* ReleaseForProfiling */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ARCHS = armv7;
|
||||
ARCHS = arm64;
|
||||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
||||
ENABLE_BITCODE = NO;
|
||||
GCC_C_LANGUAGE_STANDARD = c99;
|
||||
@ -1799,10 +1808,7 @@
|
||||
baseConfigurationReference = FD1C45EFD70F96442D46270D /* Pods-Unity-iPhone.releaseforprofiling.xcconfig */;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
ARCHS = (
|
||||
armv7,
|
||||
arm64,
|
||||
);
|
||||
ARCHS = arm64;
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++17";
|
||||
@ -1810,11 +1816,12 @@
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CLANG_ENABLE_OBJC_ARC = YES;
|
||||
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
|
||||
CODE_SIGN_ENTITLEMENTS = "Unity-iPhone/Unity-iPhone.entitlements";
|
||||
CODE_SIGN_IDENTITY = "Apple Development";
|
||||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
COPY_PHASE_STRIP = YES;
|
||||
DEVELOPMENT_TEAM = 3M965CAG25;
|
||||
DEVELOPMENT_TEAM = 299H75LKGK;
|
||||
ENABLE_BITCODE = NO;
|
||||
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
|
||||
GCC_ENABLE_CPP_EXCEPTIONS = YES;
|
||||
@ -1870,6 +1877,7 @@
|
||||
TARGETED_DEVICE_FAMILY = "1,2";
|
||||
UNITY_RUNTIME_VERSION = 2018.4.23f1;
|
||||
UNITY_SCRIPTING_BACKEND = il2cpp;
|
||||
USER_HEADER_SEARCH_PATHS = "/Users/zhl/Documents/workspace/cocos/cocos2d-x /Users/zhl/Documents/workspace/cocos/cocos2d-x/cocos /Users/zhl/Documents/workspace/cocos/cocos2d-x/cocos/network /Users/zhl/Documents/workspace/cocos/cocos2d-x/cocos/base /Users/zhl/Documents/workspace/cocos/cocos2d-x/extensions /Users/zhl/Documents/workspace/cocos/cocos2d-x/external /Users/zhl/Documents/workspace/cocos/cocos2d-x/external/sources /Users/zhl/Documents/workspace/cocos/cocos2d-x/external/chipmunk/include/chipmunk /Users/zhl/Documents/workspace/cocos/cocos2d-x/cocos/scripting/js-bindings/manual /Users/zhl/Documents/workspace/cocos/cocos2d-x/cocos/scrypt /Users/zhl/Documents/workspace/cocos/cocos2d-x/external/ios/include/uv /Users/zhl/Documents/workspace/cocos/cocos2d-x/external/ios/include/rustwallet";
|
||||
WARNING_CFLAGS = (
|
||||
"$(inherited)",
|
||||
"-Wno-missing-declarations",
|
||||
@ -1934,7 +1942,7 @@
|
||||
C01FCF4F08A954540054247B /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ARCHS = armv7;
|
||||
ARCHS = arm64;
|
||||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
||||
DEBUG_INFORMATION_FORMAT = dwarf;
|
||||
ENABLE_BITCODE = NO;
|
||||
@ -1957,7 +1965,7 @@
|
||||
C01FCF5008A954540054247B /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ARCHS = armv7;
|
||||
ARCHS = arm64;
|
||||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
||||
ENABLE_BITCODE = NO;
|
||||
GCC_C_LANGUAGE_STANDARD = c99;
|
||||
|
Binary file not shown.
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Bucket
|
||||
uuid = "4586287E-7F74-459A-8E79-D70F30E5B074"
|
||||
type = "0"
|
||||
version = "2.0">
|
||||
<Breakpoints>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
uuid = "E0288EC9-2219-448E-B2DD-6DDA4F630BA8"
|
||||
shouldBeEnabled = "No"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "Classes_cocos/UIViewController+Wallet.mm"
|
||||
startingColumnNumber = "9"
|
||||
endingColumnNumber = "9"
|
||||
startingLineNumber = "134"
|
||||
endingLineNumber = "134"
|
||||
landmarkName = "-refreshTokenID:funid:"
|
||||
landmarkType = "7">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
uuid = "9F010FF7-8933-4BD6-BC43-6849397915A8"
|
||||
shouldBeEnabled = "No"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "Classes_cocos/UIViewController+Wallet.mm"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "140"
|
||||
endingLineNumber = "140"
|
||||
landmarkName = "-refreshTokenID:funid:"
|
||||
landmarkType = "7">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
uuid = "0122C416-0F1D-462A-BC01-2963ECF9616B"
|
||||
shouldBeEnabled = "No"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "Classes_cocos/UIViewController+Wallet.mm"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "142"
|
||||
endingLineNumber = "142"
|
||||
landmarkName = "-refreshTokenID:funid:"
|
||||
landmarkType = "7">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
uuid = "15F1FD11-897D-4AA2-89F0-86DCB06070A1"
|
||||
shouldBeEnabled = "No"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "Classes_cocos/JcWallet.mm"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "189"
|
||||
endingLineNumber = "189"
|
||||
landmarkName = "nativeCallBack(funId, methodName, cparams)"
|
||||
landmarkType = "9">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
uuid = "82332A3C-7E7D-474A-946A-216488F38FF0"
|
||||
shouldBeEnabled = "No"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "Classes_cocos/UIViewController+Wallet.mm"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "141"
|
||||
endingLineNumber = "141"
|
||||
landmarkName = "-refreshTokenID:funid:"
|
||||
landmarkType = "7">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
uuid = "E16E4501-C8B9-4FBB-B5DD-797119FF44F9"
|
||||
shouldBeEnabled = "No"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "Classes_cocos/UIViewController+Wallet.mm"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "147"
|
||||
endingLineNumber = "147"
|
||||
landmarkName = "-signWithGoogle:"
|
||||
landmarkType = "7">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
uuid = "4D1CEFCB-9F08-4069-BC1B-9139709C217E"
|
||||
shouldBeEnabled = "No"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "Classes_cocos/JcWallet.mm"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "135"
|
||||
endingLineNumber = "135"
|
||||
landmarkName = "JcWallet::runJsMethod(data)"
|
||||
landmarkType = "7">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
</Breakpoints>
|
||||
</Bucket>
|
27
Unity-iPhone/Unity-iPhone.entitlements
Normal file
27
Unity-iPhone/Unity-iPhone.entitlements
Normal file
@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>aps-environment</key>
|
||||
<string>development</string>
|
||||
<key>com.apple.developer.applesignin</key>
|
||||
<array>
|
||||
<string>Default</string>
|
||||
</array>
|
||||
<key>com.apple.developer.icloud-container-identifiers</key>
|
||||
<array>
|
||||
<string>iCloud.com.jc.tebg</string>
|
||||
</array>
|
||||
<key>com.apple.developer.icloud-services</key>
|
||||
<array>
|
||||
<string>CloudDocuments</string>
|
||||
<string>CloudKit</string>
|
||||
</array>
|
||||
<key>com.apple.developer.ubiquity-container-identifiers</key>
|
||||
<array>
|
||||
<string>iCloud.com.jc.tebg</string>
|
||||
</array>
|
||||
<key>com.apple.developer.ubiquity-kvstore-identifier</key>
|
||||
<string>$(TeamIdentifierPrefix)$(CFBundleIdentifier)</string>
|
||||
</dict>
|
||||
</plist>
|
File diff suppressed because one or more lines are too long
639
js/main.js
639
js/main.js
@ -1,259 +1,624 @@
|
||||
console.log('>>begin load wallet main file');
|
||||
console.log(">>begin load wallet main file");
|
||||
|
||||
/**
|
||||
* 初始化钱包, 所有操作进行前, 必须调用此方法
|
||||
* @param {string} type: 钱包类型, 0: 内置钱包, 1: 第三方钱包
|
||||
* @param {string} password: 用于加密钱包数据的密码
|
||||
* init wallet, must call this before all other method
|
||||
* @param {string} type: wallet type, 0: internal wallet, 1: third party wallet
|
||||
|
||||
*/
|
||||
function initWallet(funId, type, password) {
|
||||
function initWallet(funId, type, chain) {
|
||||
// chain = chain || 80001
|
||||
type = 0
|
||||
chain = 80001
|
||||
try {
|
||||
var wallet;
|
||||
if ( !window.jc || !jc.wallet ) {
|
||||
wallet = new jcwallet.default({chain: 322, type, password});
|
||||
if (!window.jc || !jc.wallet) {
|
||||
wallet = new jcwallet.default({
|
||||
chain,
|
||||
type
|
||||
});
|
||||
} else {
|
||||
wallet = jc.wallet;
|
||||
}
|
||||
type = parseInt(type);
|
||||
if (type === 1) {
|
||||
console.log('wallet inited, begin connect')
|
||||
wallet.initThirdPartyWallet()
|
||||
.then(() => {
|
||||
console.log('walletconnect inited')
|
||||
var account = jc.wallet.currentAccount();
|
||||
jsb.jcCallback(funId, JSON.stringify({errcode: 0, data: account}));
|
||||
})
|
||||
.catch(err =>{
|
||||
console.log('walletconnect inited error: ' + JSON.stringify(err));
|
||||
jsb.jcCallback(funId, JSON.stringify({errcode: 1, errmsg: err}));
|
||||
})
|
||||
console.log("wallet init success, begin connect");
|
||||
wallet
|
||||
.initThirdPartyWallet()
|
||||
.then(() => {
|
||||
console.log("walletconnect connect success");
|
||||
var account = jc.wallet.currentAccount();
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 0,data: account}));
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log("walletconnect connect error: " + JSON.stringify(err));
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 1,errmsg: err}));
|
||||
});
|
||||
} else {
|
||||
let address = jc.wallet.currentAccount().address
|
||||
jsb.jcCallback(funId, JSON.stringify({errcode: 0, data: address}));
|
||||
wallet.initInternalWallet()
|
||||
.then(() => {
|
||||
console.log("internal init success");
|
||||
var address = jc.wallet.nativeAccount;
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 0,data: address}));
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log("internal wallet error: " + JSON.stringify(err));
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 1,errmsg: err}));
|
||||
});
|
||||
|
||||
}
|
||||
} catch(err) {
|
||||
console.error('error init wallet: ' + JSON.stringify(err));
|
||||
jsb.jcCallback(funId, JSON.stringify({errcode: 1, errmsg: err}));
|
||||
} catch (err) {
|
||||
console.error("wallet init with error: " + JSON.stringify(err));
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 1,errmsg: err}));
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 钱包当前激活的帐号的详细信息
|
||||
* current account for internal wallet
|
||||
*/
|
||||
function currentAccount(funId) {
|
||||
try {
|
||||
let data = jc.wallet.currentAccountData;
|
||||
return JSON.stringify({errcode: 0, data});
|
||||
} catch(err) {
|
||||
return JSON.stringify({errcode: 0,data});
|
||||
} catch (err) {
|
||||
return JSON.stringify({errcode: 1, errmsg: err});
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 获取当前链所有帐号列表
|
||||
* all account for internal wallet
|
||||
*/
|
||||
function accountList(funId) {
|
||||
try {
|
||||
let data = jc.wallet.accounts;
|
||||
return JSON.stringify({errcode: 0, data});
|
||||
}catch(err) {
|
||||
return JSON.stringify({errcode: 1, errmsg: err});
|
||||
return JSON.stringify({errcode: 0,data});
|
||||
} catch (err) {
|
||||
return JSON.stringify({
|
||||
errcode: 1,
|
||||
errmsg: err,
|
||||
});
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 获取所有支持的链的列表
|
||||
* all chain list we supported
|
||||
*/
|
||||
function chainList(funId) {
|
||||
try {
|
||||
let data = jc.wallet.chainList;
|
||||
return JSON.stringify({errcode: 0, data});
|
||||
}catch(err) {
|
||||
return JSON.stringify({errcode: 1, errmsg: err});
|
||||
return JSON.stringify({errcode: 0,data});
|
||||
} catch (err) {
|
||||
return JSON.stringify({
|
||||
errcode: 1,
|
||||
errmsg: err,
|
||||
});
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 当前链的信息
|
||||
* chain active
|
||||
*/
|
||||
function currentChain(funId) {
|
||||
try {
|
||||
let data = jc.wallet.currentChain;
|
||||
return JSON.stringify({errcode: 0, data});
|
||||
}catch(err) {
|
||||
return JSON.stringify({errcode: 1, errmsg: err});
|
||||
return JSON.stringify({errcode: 0,data});
|
||||
} catch (err) {
|
||||
return JSON.stringify({
|
||||
errcode: 1,
|
||||
errmsg: err,
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* [BOTH]切换当前链
|
||||
* 切换链需要调用currentAccount方法, 以刷新界面显示
|
||||
* [BOTH]change chain
|
||||
*/
|
||||
function changeChain(funId, chainId) {
|
||||
// chainId = parseInt(chainId);
|
||||
// chainId = parseInt(chainId);
|
||||
chainId = 80001;
|
||||
jc.wallet.updateCurrentChain(chainId)
|
||||
.then(result => {
|
||||
jsb.jcCallback(funId, JSON.stringify({errcode: 0, data: result}));
|
||||
})
|
||||
.catch(err => {
|
||||
jsb.jcCallback(funId, JSON.stringify({errcode: 1, errmsg: err}));
|
||||
})
|
||||
jc.wallet
|
||||
.updateCurrentChain(chainId)
|
||||
.then((result) => {
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 0,data: result}));
|
||||
})
|
||||
.catch((err) => {
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 1,errmsg: err}));
|
||||
});
|
||||
}
|
||||
/**
|
||||
* [BOTH]获取当前帐户的登录签名
|
||||
* @param {string} nonce: 从服务端获取的nonce
|
||||
* @param {string} tips: 签名时的提示
|
||||
* [BOTH] get sign for login
|
||||
* @param {string} nonce: nonce from server
|
||||
* @param {string} tips: tips message when sign
|
||||
*/
|
||||
function loginSign(funId, nonce, tips) {
|
||||
jc.wallet.loginSign(nonce, tips)
|
||||
.then(result => {
|
||||
jsb.jcCallback(funId, JSON.stringify({errcode: 0, data: result}));
|
||||
})
|
||||
.catch(err => {
|
||||
jsb.jcCallback(funId, JSON.stringify({errcode: 1, errmsg: err}));
|
||||
})
|
||||
jc.wallet
|
||||
.loginSign(nonce, tips)
|
||||
.then((result) => {
|
||||
jsb.jcCallback(
|
||||
funId,
|
||||
JSON.stringify({
|
||||
errcode: 0,
|
||||
data: result,
|
||||
})
|
||||
);
|
||||
})
|
||||
.catch((err) => {
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 1,errmsg: err}));
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 创建一个新帐号, 并将新建帐号设为当前激活帐号
|
||||
* @return {string} 当前激活帐户的地址
|
||||
* add one new account, then active this account
|
||||
* @return {string} account actived
|
||||
*/
|
||||
function createAccount(funId) {
|
||||
try {
|
||||
let result = jc.wallet.createAccount();
|
||||
return JSON.stringify({errcode: 0, data: result});
|
||||
} catch(err) {
|
||||
return JSON.stringify({errcode: 1, errmsg: err});
|
||||
return JSON.stringify({
|
||||
errcode: 0,
|
||||
data: result,
|
||||
});
|
||||
} catch (err) {
|
||||
return JSON.stringify({
|
||||
errcode: 1,
|
||||
errmsg: err,
|
||||
});
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 用导入一个密钥, 并将导入的帐号设为当前激活帐号
|
||||
* @return {string} 当前激活帐户的地址
|
||||
* import account with private key
|
||||
* @return {string} account actived
|
||||
*/
|
||||
function importAccount(funId, privateKey) {
|
||||
try {
|
||||
let address = jc.wallet.importAccount(privateKey)
|
||||
return JSON.stringify({errcode: 0, data: address});
|
||||
} catch(err) {
|
||||
return JSON.stringify({errcode: 1, errmsg: err});
|
||||
let address = jc.wallet.importAccount(privateKey);
|
||||
return JSON.stringify({
|
||||
errcode: 0,
|
||||
data: address,
|
||||
});
|
||||
} catch (err) {
|
||||
return JSON.stringify({
|
||||
errcode: 1,
|
||||
errmsg: err,
|
||||
});
|
||||
}
|
||||
// jc.wallet.erc20Standard.transfer({
|
||||
// address: '0xC76c692450d6221A8B1E035CB8bdB639bC60658D',
|
||||
// from: '0x50A8e60041A206AcaA5F844a1104896224be6F39',
|
||||
// to: '0x746338765a8FbDD1c5aB61bfb92CD6D960C3C662',
|
||||
// amount: 101
|
||||
// }).then((res) => {
|
||||
// console.log(JSON.stringify(res))
|
||||
// }).catch(err => {
|
||||
// console.log(JSON.stringify(err))
|
||||
// })
|
||||
}
|
||||
/**
|
||||
* 将一个帐号地址设为当前激活帐号
|
||||
* active one account
|
||||
*/
|
||||
function selectAccount(funId, address) {
|
||||
try {
|
||||
let result = jc.wallet.selectAccount(address);
|
||||
return JSON.stringify({errcode: 0, data: result});
|
||||
} catch(err) {
|
||||
return JSON.stringify({errcode: 1, errmsg: err});
|
||||
return JSON.stringify({
|
||||
errcode: 0,
|
||||
data: result,
|
||||
});
|
||||
} catch (err) {
|
||||
return JSON.stringify({
|
||||
errcode: 1,
|
||||
errmsg: err,
|
||||
});
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 获取当前链上基础代币的余额
|
||||
* @param {string} address: 待查询的帐户地址
|
||||
* 不传的话, 则获取当前帐户的余额
|
||||
* get balance of ETH
|
||||
* @param {string} address: account
|
||||
* if account is null, we`ll query for current account of wallet
|
||||
*/
|
||||
function getEthBalance(funId, address) {
|
||||
jc.wallet.getBalance(address)
|
||||
.then(result => {
|
||||
jsb.jcCallback(funId, JSON.stringify({errcode: 0, data: result}));
|
||||
}).catch(err => {
|
||||
jsb.jcCallback(funId, JSON.stringify({errcode: 1, errmsg: err}));
|
||||
jc.wallet
|
||||
.getBalance(address)
|
||||
.then((result) => {
|
||||
jsb.jcCallback(
|
||||
funId,
|
||||
JSON.stringify({
|
||||
errcode: 0,
|
||||
data: result,
|
||||
})
|
||||
);
|
||||
})
|
||||
.catch((err) => {
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 1,errmsg: err}));
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 将当前帐户里的基础代币转账给别人
|
||||
* @param {string} to: 转账目标地址
|
||||
* @param {string} amount: 转账数量
|
||||
* send ETH from current account
|
||||
* @param {string} to: target account
|
||||
* @param {string} amount:
|
||||
*/
|
||||
function sendEth(funId, to, amount) {
|
||||
jc.wallet.sendEth(to, amount)
|
||||
.then(result => {
|
||||
jsb.jcCallback(funId, JSON.stringify({errcode: 0, data: result}));
|
||||
}).catch(err => {
|
||||
jsb.jcCallback(funId, JSON.stringify({errcode: 1, errmsg: err}));
|
||||
jc.wallet
|
||||
.sendEth(to, amount)
|
||||
.then((result) => {
|
||||
jsb.jcCallback(
|
||||
funId,
|
||||
JSON.stringify({
|
||||
errcode: 0,
|
||||
data: result,
|
||||
})
|
||||
);
|
||||
})
|
||||
.catch((err) => {
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 1,errmsg: err}));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* [BOTH]生成hash图片
|
||||
* @param {string} msg: 要生成图片的内容
|
||||
* @param {string} diameter: 图片尺寸
|
||||
* [BOTH] generate ICON with hashed message
|
||||
* @param {string} msg:
|
||||
* @param {string} diameter: size of icon
|
||||
*/
|
||||
function generateIcon(funId, msg, diameter) {
|
||||
try {
|
||||
diameter = parseFloat(diameter);
|
||||
let result = jc.wallet.generateIconData(msg, diameter);
|
||||
return JSON.stringify({errcode: 0, data: result});
|
||||
} catch(err) {
|
||||
return JSON.stringify({errcode: 1, errmsg: err});
|
||||
return JSON.stringify({
|
||||
errcode: 0,
|
||||
data: result,
|
||||
});
|
||||
} catch (err) {
|
||||
return JSON.stringify({
|
||||
errcode: 1,
|
||||
errmsg: err,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取ERC20代币的基本信息, 包括symbol和decimal
|
||||
* 这些信息一般都不会变化, 客户端需缓存这些信息
|
||||
* @param {string} address: 代币的地址
|
||||
* get symbol and decimal of ERC20, symbol and decimal
|
||||
* @param {string} address: address of ERC20
|
||||
*/
|
||||
function erc20Info(funId, address) {
|
||||
jc.wallet.erc20Info(address)
|
||||
.then(result => {
|
||||
jsb.jcCallback(funId, JSON.stringify({errcode: 0, data: result}));
|
||||
}).catch(err => {
|
||||
jsb.jcCallback(funId, JSON.stringify({errcode: 1, errmsg: err}));
|
||||
jc.wallet
|
||||
.erc20Info(address)
|
||||
.then((result) => {
|
||||
jsb.jcCallback(
|
||||
funId,
|
||||
JSON.stringify({
|
||||
errcode: 0,
|
||||
data: result,
|
||||
})
|
||||
);
|
||||
})
|
||||
.catch((err) => {
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 1,errmsg: err}));
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 获取erc20代币的余额
|
||||
* @param {string} address: 代币地址
|
||||
* @param {string} account: 所属帐户的地址, 不传该参数的话, 获取当前钱包激活帐户的余额
|
||||
* get balance of ERC20
|
||||
* @param {string} address:
|
||||
* @param {string} account:
|
||||
*/
|
||||
function erc20Balance(funId, address, account) {
|
||||
jc.wallet.erc20Balance(address, account)
|
||||
.then(result => {
|
||||
jsb.jcCallback(funId, JSON.stringify({errcode: 0, data: result}));
|
||||
}).catch(err => {
|
||||
jsb.jcCallback(funId, JSON.stringify({errcode: 1, errmsg: err}));
|
||||
jc.wallet
|
||||
.erc20Balance(address, account)
|
||||
.then((result) => {
|
||||
jsb.jcCallback(
|
||||
funId,
|
||||
JSON.stringify({
|
||||
errcode: 0,
|
||||
data: result,
|
||||
})
|
||||
);
|
||||
})
|
||||
.catch((err) => {
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 1,errmsg: err}));
|
||||
});
|
||||
}
|
||||
|
||||
function sendErc20(funId, address, to, amount) {
|
||||
jc.wallet.sendErc20(address, to, amount)
|
||||
.then(result => {
|
||||
jsb.jcCallback(funId, JSON.stringify({errcode: 0, data: result}));
|
||||
}).catch(err => {
|
||||
jsb.jcCallback(funId, JSON.stringify({errcode: 1, errmsg: err}));
|
||||
jc.wallet
|
||||
.sendErc20(address, to, amount)
|
||||
.then((result) => {
|
||||
jsb.jcCallback(
|
||||
funId,
|
||||
JSON.stringify({
|
||||
errcode: 0,
|
||||
data: result,
|
||||
})
|
||||
);
|
||||
})
|
||||
.catch((err) => {
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 1,errmsg: err}));
|
||||
});
|
||||
}
|
||||
|
||||
function restoreFromMnemonic(funId, mnemonic, password) {
|
||||
try {
|
||||
diameter = parseFloat(diameter);
|
||||
let result = jc.wallet.restoreFromMnemonic(mnemonic, password);
|
||||
return JSON.stringify({errcode: 0, data: result});
|
||||
} catch(err) {
|
||||
return JSON.stringify({errcode: 1, errmsg: err});
|
||||
return JSON.stringify({
|
||||
errcode: 0,
|
||||
data: result,
|
||||
});
|
||||
} catch (err) {
|
||||
return JSON.stringify({
|
||||
errcode: 1,
|
||||
errmsg: err,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function scanQRCode(funId, title) {
|
||||
try {
|
||||
jsb.scanQRCode(funId, title);
|
||||
} catch(err) {
|
||||
return JSON.stringify({errcode: 1, errmsg: err});
|
||||
}
|
||||
try {
|
||||
jsb.scanQRCode(funId, title);
|
||||
} catch (err) {
|
||||
return JSON.stringify({
|
||||
errcode: 1,
|
||||
errmsg: err,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function signWithGoogle(funId) {
|
||||
try {
|
||||
jsb.signWithGoogle(funId);
|
||||
} catch(err) {
|
||||
return JSON.stringify({errcode: 1, errmsg: err});
|
||||
}
|
||||
jc.wallet.nativeSvr.signWithGoogle(funId)
|
||||
.then(res => {
|
||||
console.log(`google sign result: ${typeof res}`)
|
||||
console.log(res)
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 0,data: res}));
|
||||
})
|
||||
.catch(err => {
|
||||
console.log('google sign error: ' + err);
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 1,errmsg: err}));
|
||||
})
|
||||
}
|
||||
|
||||
function signOutGoogle(funId) {
|
||||
try {
|
||||
jsb.signOutGoogle(funId);
|
||||
return JSON.stringify({errcode: 0, data: 'success'});
|
||||
} catch(err) {
|
||||
return JSON.stringify({errcode: 1, errmsg: err});
|
||||
}
|
||||
jc.wallet.nativeSvr.signOutGoogle(funId)
|
||||
then(res => {
|
||||
console.log(`google sign out result: ${typeof res}`)
|
||||
console.log(res)
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 0,data: res}));
|
||||
})
|
||||
.catch(err => {
|
||||
console.log('google sign out error: ' + err);
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 1,errmsg: err}));
|
||||
})
|
||||
}
|
||||
|
||||
//function toWalletJNI(funId, url) {
|
||||
// try {
|
||||
// jsb.toWallet(url);
|
||||
// return JSON.stringify({errcode: 0});
|
||||
// } catch(err) {
|
||||
// return JSON.stringify({errcode: 1, errmsg: err});
|
||||
// }
|
||||
//}
|
||||
|
||||
function buyNft721(funId, addresses, values, signature) {
|
||||
jc.wallet.jcStandard
|
||||
.buyNft721({
|
||||
addresses,
|
||||
values,
|
||||
signature,
|
||||
})
|
||||
.then((result) => {
|
||||
jsb.jcCallback(
|
||||
funId,
|
||||
JSON.stringify({
|
||||
errcode: 0,
|
||||
data: result,
|
||||
})
|
||||
);
|
||||
})
|
||||
.catch((err) => {
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 1,errmsg: err}));
|
||||
});
|
||||
}
|
||||
|
||||
function buyNft1155(funId, addresses, values, ids, amounts, signature) {
|
||||
jc.wallet.jcStandard
|
||||
.buyNft1155({
|
||||
addresses,
|
||||
values,
|
||||
ids,
|
||||
amounts,
|
||||
signature,
|
||||
})
|
||||
.then((result) => {
|
||||
jsb.jcCallback(
|
||||
funId,
|
||||
JSON.stringify({
|
||||
errcode: 0,
|
||||
data: result,
|
||||
})
|
||||
);
|
||||
})
|
||||
.catch((err) => {
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 1,errmsg: err}));
|
||||
});
|
||||
}
|
||||
|
||||
function evolveNft721(
|
||||
funId,
|
||||
nftAddress,
|
||||
tokenIds,
|
||||
startTime,
|
||||
nonce,
|
||||
signature
|
||||
) {
|
||||
{
|
||||
jc.wallet.jcStandard
|
||||
.evolve721NFT({
|
||||
nftAddress,
|
||||
tokenIds,
|
||||
startTime,
|
||||
nonce,
|
||||
signature,
|
||||
})
|
||||
.then((result) => {
|
||||
jsb.jcCallback(
|
||||
funId,
|
||||
JSON.stringify({
|
||||
errcode: 0,
|
||||
data: result,
|
||||
})
|
||||
);
|
||||
})
|
||||
.catch((err) => {
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 1,errmsg: err}));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function evolveChip(funId, tokenIds, startTime, nonce, signature) {
|
||||
jc.wallet.jcStandard
|
||||
.evolveChip({
|
||||
tokenIds,
|
||||
startTime,
|
||||
nonce,
|
||||
signature,
|
||||
})
|
||||
.then((result) => {
|
||||
jsb.jcCallback(
|
||||
funId,
|
||||
JSON.stringify({
|
||||
errcode: 0,
|
||||
data: result,
|
||||
})
|
||||
);
|
||||
})
|
||||
.catch((err) => {
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 1,errmsg: err}));
|
||||
});
|
||||
}
|
||||
|
||||
function mintShardBatchUser(
|
||||
funId,
|
||||
tokenIds,
|
||||
amounts,
|
||||
startTime,
|
||||
nonce,
|
||||
signature
|
||||
) {
|
||||
jc.wallet.jcStandard
|
||||
.mintShardBatchUser({
|
||||
tokenIds,
|
||||
amounts,
|
||||
startTime,
|
||||
nonce,
|
||||
signature,
|
||||
})
|
||||
.then((result) => {
|
||||
jsb.jcCallback(
|
||||
funId,
|
||||
JSON.stringify({
|
||||
errcode: 0,
|
||||
data: result,
|
||||
})
|
||||
);
|
||||
})
|
||||
.catch((err) => {
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 1,errmsg: err}));
|
||||
});
|
||||
}
|
||||
|
||||
function shardMixByUser(
|
||||
funId,
|
||||
tokenId,
|
||||
nftType,
|
||||
payToken,
|
||||
payAmount,
|
||||
ids,
|
||||
amounts,
|
||||
startTime,
|
||||
nonce,
|
||||
signature
|
||||
) {
|
||||
jc.wallet.jcStandard
|
||||
.shardMixByUser({
|
||||
tokenId,
|
||||
nftType,
|
||||
payToken,
|
||||
payAmount,
|
||||
ids,
|
||||
amounts,
|
||||
startTime,
|
||||
nonce,
|
||||
signature,
|
||||
})
|
||||
.then((result) => {
|
||||
jsb.jcCallback(
|
||||
funId,
|
||||
JSON.stringify({
|
||||
errcode: 0,
|
||||
data: result,
|
||||
})
|
||||
);
|
||||
})
|
||||
.catch((err) => {
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 1,errmsg: err}));
|
||||
});
|
||||
}
|
||||
|
||||
// addresses: [nftId, chip, sign_address]
|
||||
// values: [token_id,salt_nonce,startTime]
|
||||
// chipIds: [...chipIds]
|
||||
function pluginChip(
|
||||
funId,
|
||||
addresses,
|
||||
values,
|
||||
chipIds,
|
||||
slots,
|
||||
signature
|
||||
) {
|
||||
console.log('addresses:' + addresses)
|
||||
console.log('values:' + values)
|
||||
console.log('chipIds:' + chipIds)
|
||||
console.log('slots:' + slots)
|
||||
console.log('signature:' + signature)
|
||||
|
||||
addresses = JSON.parse(addresses)
|
||||
values = JSON.parse(values)
|
||||
chipIds = JSON.parse(chipIds)
|
||||
slots = JSON.parse(slots)
|
||||
jc.wallet.jcStandard
|
||||
.pluginChip({
|
||||
addresses,
|
||||
values,
|
||||
chipIds,
|
||||
slots,
|
||||
signature
|
||||
})
|
||||
.then((result) => {
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 0,data: JSON.stringify(result)}));
|
||||
})
|
||||
.catch((err) => {
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 1,errmsg: err}));
|
||||
});
|
||||
}
|
||||
|
||||
// addresses: [nftId, chip, sign_address]
|
||||
// values: [token_id,salt_nonce,startTime]
|
||||
// chipIds: [...chipIds]
|
||||
function unplugChip(
|
||||
funId,
|
||||
addresses,
|
||||
values,
|
||||
chipIds,
|
||||
slots,
|
||||
signature
|
||||
) {
|
||||
|
||||
addresses = JSON.parse(addresses)
|
||||
values = JSON.parse(values)
|
||||
chipIds = JSON.parse(chipIds)
|
||||
slots = JSON.parse(slots)
|
||||
|
||||
jc.wallet.jcStandard
|
||||
.unplugChip({
|
||||
addresses,
|
||||
values,
|
||||
chipIds,
|
||||
slots,
|
||||
signature
|
||||
})
|
||||
.then((result) => {
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 0,data: JSON.stringify(result)}));
|
||||
})
|
||||
.catch((err) => {
|
||||
jsb.jcCallback(funId,JSON.stringify({errcode: 1,errmsg: err}));
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user