Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ DerivedDataCache/*
/Config/HoloLens

# MAC
.DS_Store
**/*.DS_Store
9 changes: 8 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
"ratio": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"vector": "cpp"
"vector": "cpp",
"__locale": "cpp",
"__threading_support": "cpp",
"string": "cpp",
"string_view": "cpp",
"variant": "cpp",
"__config": "cpp",
"array": "cpp"
}
}
11 changes: 9 additions & 2 deletions Config/DefaultEngine.ini
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@


[/Script/EngineSettings.GameMapsSettings]
GameDefaultMap=/Web3AuthSDK/Sample.Sample
EditorStartupMap=/Web3AuthSDK/Sample.Sample
GameDefaultMap=/Game/Example.Example
EditorStartupMap=/Game/Example.Example
GlobalDefaultGameMode=/Game/BaseGameMode.BaseGameMode_C

[/Script/HardwareTargeting.HardwareTargetingSettings]
TargetedHardwareClass=Desktop
Expand Down Expand Up @@ -75,3 +76,9 @@ AdditionalPlistData=<key>CFBundleURLTypes</key><array> <dict> <key>CFB
[/Script/UnrealEd.CookerSettings]
bCookOnTheFlyForLaunchOn=False

[/Web3AuthSDK/AuthInterface.AuthInterface_C]
Web3AuthOptionsClientId=BAwFgL-r7wzQKmtcdiz2uHJKNZdK7gzEf2q-m55xfzSZOw8jLOyIi4AVvvzaEQO5nv2dFLEmf9LBkF8kaq3aErg
Web3AuthOptionsRedirectUrl=torusapp://com.torus.Web3AuthUnity/auth
Web3AuthOptionsSdkUrl=https://sdk.openlogin.com
Web3AuthOptionsNetwork=MAINNET

Binary file added Content/BaseGameMode.uasset
Binary file not shown.
Binary file added Content/Example.umap
Binary file not shown.
Binary file added Content/Player.uasset
Binary file not shown.
Binary file removed Plugins/.DS_Store
Binary file not shown.
Binary file removed Plugins/Web3AuthSDK/.DS_Store
Binary file not shown.
Binary file removed Plugins/Web3AuthSDK/Content/.DS_Store
Binary file not shown.
Binary file modified Plugins/Web3AuthSDK/Content/AuthInterface.uasset
Binary file not shown.
Binary file removed Plugins/Web3AuthSDK/Content/BaseGameMode.uasset
Binary file not shown.
Binary file removed Plugins/Web3AuthSDK/Content/BaseSample.umap
Binary file not shown.
Binary file removed Plugins/Web3AuthSDK/Content/Player.uasset
Binary file not shown.
Binary file removed Plugins/Web3AuthSDK/Content/Sample.umap
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
41 changes: 33 additions & 8 deletions Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/ECCrypto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ FString UECCrypto::decrypt(FString data, FString privateKeyHex, FString ephemPub
// Create a new encryption context for AES-256 CBC mode with the key and IV
EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, key, iv);

EVP_CIPHER_CTX_set_padding(ctx, 0);
// Allocate a string buffer for the decrypted data
std::string dst;
dst.resize(srclen + EVP_CIPHER_block_size(EVP_aes_256_cbc()));
Expand Down Expand Up @@ -162,21 +162,27 @@ FString UECCrypto::encrypt(FString data, FString privateKeyHex, FString ephemPub
EC_KEY_free(pub_key);
EVP_cleanup();

return FString(UTF8_TO_TCHAR(dst.c_str()));
const char* buf = dst.c_str();

FString hex;
for (int i = 0; i < strlen(buf); ++i) {
hex += FString::Printf(TEXT("%02x"), buf[i]);
}
return hex;
}

FString UECCrypto::generatePublicKey(const FString& privateKeyHex) {
BIGNUM* bn_private_key = NULL;
BN_hex2bn(&bn_private_key, TCHAR_TO_ANSI(*privateKeyHex));
BIGNUM* bn_private_key = nullptr;
BN_hex2bn(&bn_private_key, FStringToCharArray(*privateKeyHex));

EC_KEY* ec_key = EC_KEY_new_by_curve_name(NID_secp256k1);
EC_KEY_set_private_key(ec_key, bn_private_key);

EC_POINT* ec_point = EC_POINT_new(EC_KEY_get0_group(ec_key));
EC_POINT_mul(EC_KEY_get0_group(ec_key), ec_point, EC_KEY_get0_private_key(ec_key), NULL, NULL, NULL);
EC_POINT_mul(EC_KEY_get0_group(ec_key), ec_point, EC_KEY_get0_private_key(ec_key), nullptr, nullptr, nullptr);
EC_KEY_set_public_key(ec_key, ec_point);

BIGNUM* bn = EC_POINT_point2bn(EC_KEY_get0_group(ec_key), EC_KEY_get0_public_key(ec_key), POINT_CONVERSION_UNCOMPRESSED, NULL, NULL);
BIGNUM* bn = EC_POINT_point2bn(EC_KEY_get0_group(ec_key), EC_KEY_get0_public_key(ec_key), POINT_CONVERSION_UNCOMPRESSED, nullptr, nullptr);

char* hex = BN_bn2hex(bn);
FString result(UTF8_TO_TCHAR(hex));
Expand All @@ -191,7 +197,7 @@ FString UECCrypto::generateECDSASignature(const FString& privateKeyHex, const FS
// Initialize OpenSSL's elliptic curve library
EC_KEY* key = EC_KEY_new_by_curve_name(NID_secp256k1);

BIGNUM* priv_bn = BN_new();
BIGNUM* priv_bn = nullptr;
BN_hex2bn(&priv_bn, FStringToCharArray(privateKeyHex));

EC_KEY_set_private_key(key, priv_bn);
Expand All @@ -205,8 +211,26 @@ FString UECCrypto::generateECDSASignature(const FString& privateKeyHex, const FS
unsigned char* sig_buf = nullptr;

ECDSA_SIG* signature = ECDSA_do_sign(hash, SHA256_DIGEST_LENGTH, key);
int n = i2d_ECDSA_SIG(signature, &sig_buf);

BN_CTX *ctx = BN_CTX_new();
BN_CTX_start(ctx);
const EC_GROUP *group = EC_KEY_get0_group(key);
BIGNUM *order = BN_CTX_get(ctx);
BIGNUM *halforder = BN_CTX_get(ctx);
EC_GROUP_get_order(group, order, ctx);
BN_rshift1(halforder, order);
const BIGNUM* pr = nullptr;
const BIGNUM* ps = nullptr;
ECDSA_SIG_get0(signature, &pr, &ps);
if (BN_cmp(ps, halforder) > 0) {
// enforce low S values. libsecp256k1 does this by default, openssl does not.
BN_sub(const_cast<BIGNUM*>(ps), order, ps);
}
BN_CTX_end(ctx);
BN_CTX_free(ctx);

int n = i2d_ECDSA_SIG(signature, &sig_buf);

//// Convert signature to hex string
FString signature_hex;
for (int i = 0; i < n; ++i) {
Expand All @@ -215,6 +239,7 @@ FString UECCrypto::generateECDSASignature(const FString& privateKeyHex, const FS

EC_KEY_free(key);
ECDSA_SIG_free(signature);
BN_free(priv_bn);

return signature_hex;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ - (void) launchUrl:(const char*)url
ASWebAuthenticationSession* authSession = [[ASWebAuthenticationSession alloc] initWithURL:URL callbackURLScheme:bundleIdentifier completionHandler:^(NSURL * _Nullable callbackURL, NSError * _Nullable error) {

if(callbackURL) {
AWeb3Auth::callBackFromWebAuthenticateIOS(callbackURL.fragment);
UWeb3Auth::callBackFromWebAuthenticateIOS(callbackURL.fragment);
} else {
return;
}
Expand Down
40 changes: 0 additions & 40 deletions Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/KeyStoreUtils.cpp

This file was deleted.

Loading