diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 7555719..0000000 Binary files a/.DS_Store and /dev/null differ diff --git a/.gitignore b/.gitignore index 0fb6fa1..9741a74 100644 --- a/.gitignore +++ b/.gitignore @@ -75,4 +75,4 @@ DerivedDataCache/* /Config/HoloLens # MAC -.DS_Store \ No newline at end of file +**/*.DS_Store diff --git a/.vscode/settings.json b/.vscode/settings.json index 78ea524..cba7d97 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -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" } } \ No newline at end of file diff --git a/Config/DefaultEngine.ini b/Config/DefaultEngine.ini index 2db72bb..ebea370 100644 --- a/Config/DefaultEngine.ini +++ b/Config/DefaultEngine.ini @@ -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 @@ -75,3 +76,9 @@ AdditionalPlistData=CFBundleURLTypes 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 + diff --git a/Content/BaseGameMode.uasset b/Content/BaseGameMode.uasset new file mode 100644 index 0000000..b0a0dff Binary files /dev/null and b/Content/BaseGameMode.uasset differ diff --git a/Content/Example.umap b/Content/Example.umap new file mode 100644 index 0000000..0fd5ce4 Binary files /dev/null and b/Content/Example.umap differ diff --git a/Content/Player.uasset b/Content/Player.uasset new file mode 100644 index 0000000..29ec305 Binary files /dev/null and b/Content/Player.uasset differ diff --git a/Plugins/.DS_Store b/Plugins/.DS_Store deleted file mode 100644 index 5e4a22c..0000000 Binary files a/Plugins/.DS_Store and /dev/null differ diff --git a/Plugins/Web3AuthSDK/.DS_Store b/Plugins/Web3AuthSDK/.DS_Store deleted file mode 100644 index b2c2f83..0000000 Binary files a/Plugins/Web3AuthSDK/.DS_Store and /dev/null differ diff --git a/Plugins/Web3AuthSDK/Content/.DS_Store b/Plugins/Web3AuthSDK/Content/.DS_Store deleted file mode 100644 index 0ac78c5..0000000 Binary files a/Plugins/Web3AuthSDK/Content/.DS_Store and /dev/null differ diff --git a/Plugins/Web3AuthSDK/Content/AuthInterface.uasset b/Plugins/Web3AuthSDK/Content/AuthInterface.uasset index 9a3071f..9602110 100644 Binary files a/Plugins/Web3AuthSDK/Content/AuthInterface.uasset and b/Plugins/Web3AuthSDK/Content/AuthInterface.uasset differ diff --git a/Plugins/Web3AuthSDK/Content/BaseGameMode.uasset b/Plugins/Web3AuthSDK/Content/BaseGameMode.uasset deleted file mode 100644 index e8c2370..0000000 Binary files a/Plugins/Web3AuthSDK/Content/BaseGameMode.uasset and /dev/null differ diff --git a/Plugins/Web3AuthSDK/Content/BaseSample.umap b/Plugins/Web3AuthSDK/Content/BaseSample.umap deleted file mode 100644 index 473ecc4..0000000 Binary files a/Plugins/Web3AuthSDK/Content/BaseSample.umap and /dev/null differ diff --git a/Plugins/Web3AuthSDK/Content/Player.uasset b/Plugins/Web3AuthSDK/Content/Player.uasset deleted file mode 100644 index fcef6d9..0000000 Binary files a/Plugins/Web3AuthSDK/Content/Player.uasset and /dev/null differ diff --git a/Plugins/Web3AuthSDK/Content/Sample.umap b/Plugins/Web3AuthSDK/Content/Sample.umap deleted file mode 100644 index 02c0b58..0000000 Binary files a/Plugins/Web3AuthSDK/Content/Sample.umap and /dev/null differ diff --git a/Plugins/Web3AuthSDK/Content/Sample_HLOD0_Instancing.uasset b/Plugins/Web3AuthSDK/Content/Sample_HLOD0_Instancing.uasset deleted file mode 100644 index 9b31bb4..0000000 Binary files a/Plugins/Web3AuthSDK/Content/Sample_HLOD0_Instancing.uasset and /dev/null differ diff --git a/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/1/9G/NOJMJAZSFYC4A9KB4G0K39.uasset b/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/1/9G/NOJMJAZSFYC4A9KB4G0K39.uasset deleted file mode 100644 index f1363ab..0000000 Binary files a/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/1/9G/NOJMJAZSFYC4A9KB4G0K39.uasset and /dev/null differ diff --git a/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/2/35/SJUXX2PIKI1STB4DE7ISJ8.uasset b/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/2/35/SJUXX2PIKI1STB4DE7ISJ8.uasset deleted file mode 100644 index 92e02f8..0000000 Binary files a/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/2/35/SJUXX2PIKI1STB4DE7ISJ8.uasset and /dev/null differ diff --git a/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/2/KG/NWWO5CQ0OSNZ0BV9L4D8OT.uasset b/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/2/KG/NWWO5CQ0OSNZ0BV9L4D8OT.uasset deleted file mode 100644 index c92485a..0000000 Binary files a/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/2/KG/NWWO5CQ0OSNZ0BV9L4D8OT.uasset and /dev/null differ diff --git a/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/2/VJ/SLJ4FXA6R7XBUELATY6C62.uasset b/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/2/VJ/SLJ4FXA6R7XBUELATY6C62.uasset deleted file mode 100644 index c273781..0000000 Binary files a/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/2/VJ/SLJ4FXA6R7XBUELATY6C62.uasset and /dev/null differ diff --git a/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/3/9B/VLUOQHI2UNZJX3FDWIMP0J.uasset b/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/3/9B/VLUOQHI2UNZJX3FDWIMP0J.uasset deleted file mode 100644 index 174f97f..0000000 Binary files a/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/3/9B/VLUOQHI2UNZJX3FDWIMP0J.uasset and /dev/null differ diff --git a/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/3/AP/USP0NX9Z85OQZB9YRUAZZ9.uasset b/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/3/AP/USP0NX9Z85OQZB9YRUAZZ9.uasset deleted file mode 100644 index d149592..0000000 Binary files a/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/3/AP/USP0NX9Z85OQZB9YRUAZZ9.uasset and /dev/null differ diff --git a/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/3/DH/PBMFX78P2CST4LOZFY7VZY.uasset b/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/3/DH/PBMFX78P2CST4LOZFY7VZY.uasset deleted file mode 100644 index 58f5390..0000000 Binary files a/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/3/DH/PBMFX78P2CST4LOZFY7VZY.uasset and /dev/null differ diff --git a/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/3/G9/3P8155XKEB0QZA1QZBONMI.uasset b/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/3/G9/3P8155XKEB0QZA1QZBONMI.uasset deleted file mode 100644 index f909f89..0000000 Binary files a/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/3/G9/3P8155XKEB0QZA1QZBONMI.uasset and /dev/null differ diff --git a/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/5/FJ/WEI5EYQBTB3LPAISOOK5YL.uasset b/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/5/FJ/WEI5EYQBTB3LPAISOOK5YL.uasset deleted file mode 100644 index 408c8de..0000000 Binary files a/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/5/FJ/WEI5EYQBTB3LPAISOOK5YL.uasset and /dev/null differ diff --git a/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/6/62/EN2SWKWES6YQNC750IBLP5.uasset b/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/6/62/EN2SWKWES6YQNC750IBLP5.uasset deleted file mode 100644 index b532c91..0000000 Binary files a/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/6/62/EN2SWKWES6YQNC750IBLP5.uasset and /dev/null differ diff --git a/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/6/IU/MIBGSC2SBLSC22BSE66RL2.uasset b/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/6/IU/MIBGSC2SBLSC22BSE66RL2.uasset deleted file mode 100644 index 77bd861..0000000 Binary files a/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/6/IU/MIBGSC2SBLSC22BSE66RL2.uasset and /dev/null differ diff --git a/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/7/H3/X1VQKQTCKBQQ6OU5YJZUUJ.uasset b/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/7/H3/X1VQKQTCKBQQ6OU5YJZUUJ.uasset deleted file mode 100644 index d85dafd..0000000 Binary files a/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/7/H3/X1VQKQTCKBQQ6OU5YJZUUJ.uasset and /dev/null differ diff --git a/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/7/TR/PV1IIXM0BNMIDB7C68IP11.uasset b/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/7/TR/PV1IIXM0BNMIDB7C68IP11.uasset deleted file mode 100644 index a5e519a..0000000 Binary files a/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/7/TR/PV1IIXM0BNMIDB7C68IP11.uasset and /dev/null differ diff --git a/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/8/WU/6DFL1K8U0U98UBVTQ0N62U.uasset b/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/8/WU/6DFL1K8U0U98UBVTQ0N62U.uasset deleted file mode 100644 index ca88adc..0000000 Binary files a/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/8/WU/6DFL1K8U0U98UBVTQ0N62U.uasset and /dev/null differ diff --git a/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/9/1P/I0PQYBC3PG9HAJWGGUQYFD.uasset b/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/9/1P/I0PQYBC3PG9HAJWGGUQYFD.uasset deleted file mode 100644 index 5aaba43..0000000 Binary files a/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/9/1P/I0PQYBC3PG9HAJWGGUQYFD.uasset and /dev/null differ diff --git a/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/9/RZ/5SABANM4UIK0GM096EU5KX.uasset b/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/9/RZ/5SABANM4UIK0GM096EU5KX.uasset deleted file mode 100644 index ee4b9bd..0000000 Binary files a/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/9/RZ/5SABANM4UIK0GM096EU5KX.uasset and /dev/null differ diff --git a/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/A/EX/72RNZH2ZYSBID65IK41320.uasset b/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/A/EX/72RNZH2ZYSBID65IK41320.uasset deleted file mode 100644 index 197e6b3..0000000 Binary files a/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/A/EX/72RNZH2ZYSBID65IK41320.uasset and /dev/null differ diff --git a/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/A/T9/BCVYVAHDAWAYGJ4TY0T2Z1.uasset b/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/A/T9/BCVYVAHDAWAYGJ4TY0T2Z1.uasset deleted file mode 100644 index 63a08cf..0000000 Binary files a/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/A/T9/BCVYVAHDAWAYGJ4TY0T2Z1.uasset and /dev/null differ diff --git a/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/B/4Z/3YJVV2WR2R7V7B6HHEEEC1.uasset b/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/B/4Z/3YJVV2WR2R7V7B6HHEEEC1.uasset deleted file mode 100644 index cb93447..0000000 Binary files a/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/B/4Z/3YJVV2WR2R7V7B6HHEEEC1.uasset and /dev/null differ diff --git a/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/B/GC/5IUBPZFXMIBZZEMJCXIO4I.uasset b/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/B/GC/5IUBPZFXMIBZZEMJCXIO4I.uasset deleted file mode 100644 index 1f7a90b..0000000 Binary files a/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/B/GC/5IUBPZFXMIBZZEMJCXIO4I.uasset and /dev/null differ diff --git a/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/B/IB/1DL79E9EETK4M8WDVTTI64.uasset b/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/B/IB/1DL79E9EETK4M8WDVTTI64.uasset deleted file mode 100644 index d74104f..0000000 Binary files a/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/B/IB/1DL79E9EETK4M8WDVTTI64.uasset and /dev/null differ diff --git a/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/C/1V/CAU9VQSGBAZMUFQX5X4GGN.uasset b/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/C/1V/CAU9VQSGBAZMUFQX5X4GGN.uasset deleted file mode 100644 index 8afd8fd..0000000 Binary files a/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/C/1V/CAU9VQSGBAZMUFQX5X4GGN.uasset and /dev/null differ diff --git a/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/E/8E/5696DB30GJP2XP9PR5M09G.uasset b/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/E/8E/5696DB30GJP2XP9PR5M09G.uasset deleted file mode 100644 index 06e541c..0000000 Binary files a/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/E/8E/5696DB30GJP2XP9PR5M09G.uasset and /dev/null differ diff --git a/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/E/SE/6M5XZORFO6DP19K7XVB83O.uasset b/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/E/SE/6M5XZORFO6DP19K7XVB83O.uasset deleted file mode 100644 index b417cee..0000000 Binary files a/Plugins/Web3AuthSDK/Content/__ExternalActors__/Sample/E/SE/6M5XZORFO6DP19K7XVB83O.uasset and /dev/null differ diff --git a/Plugins/Web3AuthSDK/Content/__ExternalObjects__/.DS_Store b/Plugins/Web3AuthSDK/Content/__ExternalObjects__/.DS_Store deleted file mode 100644 index d7baed3..0000000 Binary files a/Plugins/Web3AuthSDK/Content/__ExternalObjects__/.DS_Store and /dev/null differ diff --git a/Plugins/Web3AuthSDK/Content/__ExternalObjects__/Sample/0/OB/1FRSR38RDMHFNHBB9AYJFL.uasset b/Plugins/Web3AuthSDK/Content/__ExternalObjects__/Sample/0/OB/1FRSR38RDMHFNHBB9AYJFL.uasset deleted file mode 100644 index 4e86da3..0000000 Binary files a/Plugins/Web3AuthSDK/Content/__ExternalObjects__/Sample/0/OB/1FRSR38RDMHFNHBB9AYJFL.uasset and /dev/null differ diff --git a/Plugins/Web3AuthSDK/Content/__ExternalObjects__/Sample/1/K6/VTRNGWGOSO9NVOEPJZLH83.uasset b/Plugins/Web3AuthSDK/Content/__ExternalObjects__/Sample/1/K6/VTRNGWGOSO9NVOEPJZLH83.uasset deleted file mode 100644 index cf3246e..0000000 Binary files a/Plugins/Web3AuthSDK/Content/__ExternalObjects__/Sample/1/K6/VTRNGWGOSO9NVOEPJZLH83.uasset and /dev/null differ diff --git a/Plugins/Web3AuthSDK/Content/__ExternalObjects__/Sample/2/L6/72RJDE1KUM7VLQU0TQS6KD.uasset b/Plugins/Web3AuthSDK/Content/__ExternalObjects__/Sample/2/L6/72RJDE1KUM7VLQU0TQS6KD.uasset deleted file mode 100644 index 8c92a49..0000000 Binary files a/Plugins/Web3AuthSDK/Content/__ExternalObjects__/Sample/2/L6/72RJDE1KUM7VLQU0TQS6KD.uasset and /dev/null differ diff --git a/Plugins/Web3AuthSDK/Content/__ExternalObjects__/Sample/7/56/76B6BP1Z3K0FUY3QFDB638.uasset b/Plugins/Web3AuthSDK/Content/__ExternalObjects__/Sample/7/56/76B6BP1Z3K0FUY3QFDB638.uasset deleted file mode 100644 index f43b8cc..0000000 Binary files a/Plugins/Web3AuthSDK/Content/__ExternalObjects__/Sample/7/56/76B6BP1Z3K0FUY3QFDB638.uasset and /dev/null differ diff --git a/Plugins/Web3AuthSDK/Content/__ExternalObjects__/Sample/B/8H/9J6042P1HVM7691WIWTID9.uasset b/Plugins/Web3AuthSDK/Content/__ExternalObjects__/Sample/B/8H/9J6042P1HVM7691WIWTID9.uasset deleted file mode 100644 index dbd734a..0000000 Binary files a/Plugins/Web3AuthSDK/Content/__ExternalObjects__/Sample/B/8H/9J6042P1HVM7691WIWTID9.uasset and /dev/null differ diff --git a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/ECCrypto.cpp b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/ECCrypto.cpp index ad9e78e..e7b6cee 100644 --- a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/ECCrypto.cpp +++ b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/ECCrypto.cpp @@ -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())); @@ -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)); @@ -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); @@ -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(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) { @@ -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; } diff --git a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/IOS/ObjC/WebAuthenticate.mm b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/IOS/ObjC/WebAuthenticate.mm index 5bde56d..2232b70 100644 --- a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/IOS/ObjC/WebAuthenticate.mm +++ b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/IOS/ObjC/WebAuthenticate.mm @@ -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; } diff --git a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/KeyStoreUtils.cpp b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/KeyStoreUtils.cpp deleted file mode 100644 index bddc150..0000000 --- a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/KeyStoreUtils.cpp +++ /dev/null @@ -1,40 +0,0 @@ -#include "KeyStoreUtils.h" - -UKeyStoreUtils::UKeyStoreUtils() {} - -/* -UKeyStoreUtils::UKeyStoreUtils(FString filename, Int user) { - SlotName = filename; - UserIndex = user; -} -*/ - -UKeyStoreUtils::~UKeyStoreUtils() {} - -UWeb3StorageAdapter* UKeyStoreUtils::GetInstance() { - if(StorageInstance == nullptr) { - // Try load - // StorageInstance = Cast(UGameplayStatics::LoadGameFromSlot(SlotName, UserIndex); - - // Instantiate new - if(StorageInstance == nullptr) { - StorageInstance = Cast(UGameplayStatics::CreateSaveGameObject(UWeb3StorageAdapter::StaticClass())); - } - } - - return StorageInstance; -} - -void UKeyStoreUtils::Assign(FString value) { - GetInstance()->sessionId = value; - //UGameplayStatics::SaveGameToSlot(GetInstance(), SlotName, UserIndex); -} - -FString UKeyStoreUtils::Get() { - return GetInstance()->sessionId; -} - -void UKeyStoreUtils::Clear() { - GetInstance()->sessionId = FString(); - //UGameplayStatics::SaveGameToSlot(GetInstance(), SlotName, UserIndex); -} diff --git a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/Web3Auth.cpp b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/Web3Auth.cpp index cfcb614..7a4c3bf 100644 --- a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/Web3Auth.cpp +++ b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/Web3Auth.cpp @@ -8,14 +8,6 @@ #include "IOS/ObjC/WebAuthenticate.h" #endif -FOnLogin AWeb3Auth::loginEvent; -FOnLogout AWeb3Auth::logoutEvent; - -FWeb3AuthResponse AWeb3Auth::web3AuthResponse; - -UKeyStoreUtils* AWeb3Auth::keyStoreUtils; -UECCrypto* AWeb3Auth::crypto; - #if PLATFORM_ANDROID JNI_METHOD void Java_com_epicgames_unreal_GameActivity_onDeepLink(JNIEnv* env, jclass clazz, jstring uri) { if (JNIEnv* Env = FAndroidApplication::GetJavaEnv(true)) { @@ -24,14 +16,14 @@ JNI_METHOD void Java_com_epicgames_unreal_GameActivity_onDeepLink(JNIEnv* env, j FString result = FString(UTF8_TO_TCHAR(UTFString)); UE_LOG(LogTemp, Warning, TEXT("redirect %s"), *result); - AWeb3Auth::setResultUrl(result); + UWeb3Auth::setResultUrl(result); Env->ReleaseStringUTFChars(uri, UTFString); Env->DeleteLocalRef(uri); } } -void AWeb3Auth::CallJniVoidMethod(JNIEnv* Env, const jclass Class, jmethodID Method, ...) { +void UWeb3Auth::CallJniVoidMethod(JNIEnv* Env, const jclass Class, jmethodID Method, ...) { va_list Args; va_start(Args, Method); Env->CallStaticVoidMethodV(Class, Method, Args); @@ -41,22 +33,12 @@ void AWeb3Auth::CallJniVoidMethod(JNIEnv* Env, const jclass Class, jmethodID Met } #endif -// Sets default values -AWeb3Auth::AWeb3Auth() -{ - // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. - PrimaryActorTick.bCanEverTick = true; -} - -void AWeb3Auth::setOptions(FWeb3AuthOptions options) { +void UWeb3Auth::setOptions(FWeb3AuthOptions options) { this->web3AuthOptions = options; - this->keyStoreUtils = NewObject(); - this->crypto = NewObject(); - authorizeSession(); } -void AWeb3Auth::request(FString path, FLoginParams* loginParams = NULL, TSharedPtr extraParams = NULL) { +void UWeb3Auth::request(FString path, FLoginParams* loginParams = NULL, TSharedPtr extraParams = NULL) { TSharedPtr paramMap = MakeShareable(new FJsonObject); @@ -162,29 +144,16 @@ void AWeb3Auth::request(FString path, FLoginParams* loginParams = NULL, TShared #endif } -void AWeb3Auth::processLogin(FLoginParams loginParams) { +void UWeb3Auth::processLogin(FLoginParams loginParams) { UE_LOG(LogTemp, Warning, TEXT("login called")); this->request("login", &loginParams); } -/*void AWeb3Auth::logout(FJsonObject params) { - this->request("logout", NULL, ¶ms); -}*/ - -void AWeb3Auth::proccessLogout(FString redirectUrl, FString appState) { - TSharedPtr extraParams = MakeShareable(new FJsonObject); - - if (redirectUrl != "") - extraParams->SetStringField("redirectUrl", redirectUrl); - - if (appState != "") - extraParams->SetStringField("appState", appState); - - //this->request("logout", NULL, extraParams); +void UWeb3Auth::processLogout() { sessionTimeout(); } -void AWeb3Auth::setResultUrl(FString hash) { +void UWeb3Auth::setResultUrl(FString hash) { if (hash.IsEmpty()) { return; @@ -219,20 +188,20 @@ void AWeb3Auth::setResultUrl(FString hash) { } if (web3AuthResponse.privKey.IsEmpty() || web3AuthResponse.privKey == "0000000000000000000000000000000000000000000000000000000000000000") { - AWeb3Auth::logoutEvent.ExecuteIfBound(); + this->logoutEvent.ExecuteIfBound(); } else { - AWeb3Auth::keyStoreUtils->Assign(web3AuthResponse.sessionId); - AWeb3Auth::loginEvent.ExecuteIfBound(web3AuthResponse); + this->sessionId = web3AuthResponse.sessionId; + this->loginEvent.ExecuteIfBound(web3AuthResponse); } } template -void AWeb3Auth::GetJsonStringFromStruct(StructType FilledStruct, FString& StringOutput) { +void UWeb3Auth::GetJsonStringFromStruct(StructType FilledStruct, FString& StringOutput) { FJsonObjectConverter::UStructToJsonObjectString(StructType::StaticStruct(), &FilledStruct, StringOutput, 0, 0); } -FString AWeb3Auth::startLocalWebServer() { +FString UWeb3Auth::startLocalWebServer() { FHttpServerModule& httpServerModule = FHttpServerModule::Get(); httpServerModule.StopAllListeners(); @@ -264,11 +233,11 @@ FString AWeb3Auth::startLocalWebServer() { } -bool AWeb3Auth::requestAuthCallback(const FHttpServerRequest& Request, const FHttpResultCallback& OnComplete) { +bool UWeb3Auth::requestAuthCallback(const FHttpServerRequest& Request, const FHttpResultCallback& OnComplete) { FString code = Request.QueryParams["code"]; if (!code.IsEmpty()) { - AWeb3Auth::setResultUrl(code); + UWeb3Auth::setResultUrl(code); } TUniquePtr response = FHttpServerResponse::Create(TEXT("OK"), TEXT("text/html")); @@ -283,7 +252,7 @@ bool AWeb3Auth::requestAuthCallback(const FHttpServerRequest& Request, const FHt return true; } -bool AWeb3Auth::requestCompleteCallback(const FHttpServerRequest& Request, const FHttpResultCallback& OnComplete) +bool UWeb3Auth::requestCompleteCallback(const FHttpServerRequest& Request, const FHttpResultCallback& OnComplete) { FString text = R"html( @@ -330,23 +299,23 @@ bool AWeb3Auth::requestCompleteCallback(const FHttpServerRequest& Request, const return true; } -void AWeb3Auth::setLoginEvent(FOnLogin _event) { +void UWeb3Auth::setLoginEvent(FOnLogin _event) { loginEvent = _event; } -void AWeb3Auth::setLogoutEvent(FOnLogout _event) { +void UWeb3Auth::setLogoutEvent(FOnLogout _event) { logoutEvent = _event; } #if PLATFORM_IOS -void AWeb3Auth::callBackFromWebAuthenticateIOS(NSString* sResult) { +void UWeb3Auth::callBackFromWebAuthenticateIOS(NSString* sResult) { FString result = FString(sResult); - AWeb3Auth::setResultUrl(result); + UWeb3Auth::setResultUrl(result); } #endif -FString AWeb3Auth::getPrivKey() { +FString UWeb3Auth::getPrivKey() { if (web3AuthResponse.coreKitKey.IsEmpty() || web3AuthResponse.privKey.IsEmpty()) { return ""; } @@ -354,7 +323,7 @@ FString AWeb3Auth::getPrivKey() { return web3AuthOptions.useCoreKitKey ? web3AuthResponse.coreKitKey : web3AuthResponse.privKey; } -FString AWeb3Auth::getEd25519PrivKey() { +FString UWeb3Auth::getEd25519PrivKey() { if (web3AuthResponse.coreKitEd25519PrivKey.IsEmpty() || web3AuthResponse.ed25519PrivKey.IsEmpty()) { return ""; } @@ -362,7 +331,7 @@ FString AWeb3Auth::getEd25519PrivKey() { return web3AuthOptions.useCoreKitKey ? web3AuthResponse.coreKitEd25519PrivKey : web3AuthResponse.ed25519PrivKey; } -FUserInfo AWeb3Auth::getUserInfo() { +FUserInfo UWeb3Auth::getUserInfo() { if (web3AuthResponse.userInfo.IsEmpty()) { FString error = Web3AuthError::getError(ErrorCode::NOUSERFOUND); UE_LOG(LogTemp, Fatal, TEXT("%s"), *error); @@ -373,29 +342,12 @@ FUserInfo AWeb3Auth::getUserInfo() { return web3AuthResponse.userInfo; } -void AWeb3Auth::BeginPlay() { - Super::BeginPlay(); -} - - -void AWeb3Auth::EndPlay(const EEndPlayReason::Type EndPlayReason) { - Super::EndPlay(EndPlayReason); - - FHttpServerModule::Get().StopAllListeners(); - - for (auto route : httpRoutes) { - route.Key->UnbindRoute(route.Value); - } - httpRoutes.Empty(); -} - -void AWeb3Auth::authorizeSession() { - FString sessionId = AWeb3Auth::keyStoreUtils->Get(); - if (!sessionId.IsEmpty()) { - FString pubKey = crypto->generatePublicKey(sessionId); +void UWeb3Auth::authorizeSession() { + if (!this->sessionId.IsEmpty()) { + FString pubKey = crypto->generatePublicKey(this->sessionId); UE_LOG(LogTemp, Log, TEXT("public key %s"), *pubKey); - - web3AuthApi->AuthorizeSession(pubKey, [sessionId](FStoreApiResponse response) + FString session = this->sessionId; + web3AuthApi->AuthorizeSession(pubKey, [session, this](FStoreApiResponse response) { UE_LOG(LogTemp, Log, TEXT("Response: %s"), *response.message); @@ -406,7 +358,7 @@ void AWeb3Auth::authorizeSession() { return; } - FString output = crypto->decrypt(shareMetaData.ciphertext, sessionId, shareMetaData.ephemPublicKey, shareMetaData.iv); + FString output = crypto->decrypt(shareMetaData.ciphertext, session, shareMetaData.ephemPublicKey, shareMetaData.iv); UE_LOG(LogTemp, Log, TEXT("output %s"), *output); TSharedPtr tempJson; @@ -429,24 +381,20 @@ void AWeb3Auth::authorizeSession() { return; } - AWeb3Auth::loginEvent.ExecuteIfBound(web3AuthResponse); + this->loginEvent.ExecuteIfBound(web3AuthResponse); } }); } } -void AWeb3Auth::sessionTimeout() { - FString sessionId = AWeb3Auth::keyStoreUtils->Get(); +void UWeb3Auth::sessionTimeout() { - if (!sessionId.IsEmpty()) { - FString pubKey = crypto->generatePublicKey(sessionId); + if (!this->sessionId.IsEmpty()) { + FString pubKey = crypto->generatePublicKey(this->sessionId); UE_LOG(LogTemp, Log, TEXT("public key %s"), *pubKey); - - web3AuthApi->AuthorizeSession(pubKey, [pubKey, sessionId, this](FStoreApiResponse response) + web3AuthApi->AuthorizeSession(pubKey, [pubKey, this](FStoreApiResponse response) { - UE_LOG(LogTemp, Log, TEXT("Response: %s"), *response.message); - FShareMetaData shareMetaData; if (!FJsonObjectConverter::JsonObjectStringToUStruct(response.message, &shareMetaData, 0, 0)) { @@ -454,7 +402,7 @@ void AWeb3Auth::sessionTimeout() { return; } - FString encryptedData = crypto->encrypt("", sessionId, shareMetaData.ephemPublicKey, shareMetaData.iv); + FString encryptedData = crypto->encrypt("", this->sessionId, shareMetaData.ephemPublicKey, shareMetaData.iv); shareMetaData.ciphertext = encryptedData; @@ -464,29 +412,38 @@ void AWeb3Auth::sessionTimeout() { FString jsonString; TSharedRef> jsonWriter = TJsonWriterFactory<>::Create(&jsonString); FJsonSerializer::Serialize(jsonObject.ToSharedRef(), jsonWriter); + FString sig = crypto->generateECDSASignature(this->sessionId, jsonString); FLogoutApiRequest request; request.data = jsonString; request.key = pubKey; - request.signature = crypto->generateECDSASignature(sessionId, jsonString); + request.signature = sig; request.timeout = 1; - web3AuthApi->Logout(request, [](FString response) + web3AuthApi->Logout(request, [this](FString response) { UE_LOG(LogTemp, Log, TEXT("Response: %s"), *response); - AWeb3Auth::keyStoreUtils->Clear(); - AWeb3Auth::logoutEvent.ExecuteIfBound(); + this->logoutEvent.ExecuteIfBound(); + this->sessionId = FString(); }); }); - } } - -void AWeb3Auth::Tick(float DeltaTime) { - Super::Tick(DeltaTime); +void UWeb3Auth::Initialize(FSubsystemCollectionBase& Collection) { + Super::Initialize(Collection); + this->crypto = NewObject(); } -AWeb3Auth::~AWeb3Auth() { +void UWeb3Auth::Deinitialize() { + Super::Deinitialize(); + FHttpServerModule::Get().StopAllListeners(); + + for (auto route : httpRoutes) { + route.Key->UnbindRoute(route.Value); + } + httpRoutes.Empty(); + this->crypto = nullptr; + this->web3AuthApi = nullptr; } diff --git a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/ECCrypto.h b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/ECCrypto.h index f82679d..9c9db6d 100644 --- a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/ECCrypto.h +++ b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/ECCrypto.h @@ -11,9 +11,7 @@ #define UI UI_ST THIRD_PARTY_INCLUDES_START #include -#include #include -#include #include #include #include diff --git a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/KeyStoreUtils.h b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/KeyStoreUtils.h deleted file mode 100644 index f18bec3..0000000 --- a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/KeyStoreUtils.h +++ /dev/null @@ -1,37 +0,0 @@ -#pragma once - -#include "CoreMinimal.h" -#include "GameFramework/SaveGame.h" -#include "Kismet/GameplayStatics.h" - -#include "KeyStoreUtils.generated.h" - -UCLASS() -class UWeb3StorageAdapter : public USaveGame -{ - GENERATED_BODY() -public: - UPROPERTY() - FString sessionId; -}; - -UCLASS() -class WEB3AUTHSDK_API UKeyStoreUtils : public UObject -{ - GENERATED_BODY() -private: - UPROPERTY() - UWeb3StorageAdapter* StorageInstance; - // Int UserIndex - // FString SlotName - - UWeb3StorageAdapter* GetInstance(); -public: - void Assign(FString value); - FString Get(); - void Clear(); -public: - // UKeyStoreUtils(FString filename, Int user); - UKeyStoreUtils(); - ~UKeyStoreUtils(); -}; diff --git a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3Auth.h b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3Auth.h index 246a57e..02d88b0 100644 --- a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3Auth.h +++ b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3Auth.h @@ -7,7 +7,6 @@ #include "JsonUtilities.h" #include "Misc/Base64.h" -#include "KeyStoreUtils.h" #include "ECCrypto.h" #include "Web3AuthApi.h" @@ -570,37 +569,28 @@ DECLARE_DYNAMIC_DELEGATE_OneParam(FOnLogin, FWeb3AuthResponse, response); DECLARE_DYNAMIC_DELEGATE(FOnLogout); UCLASS() -class WEB3AUTHSDK_API AWeb3Auth : public AActor +class WEB3AUTHSDK_API UWeb3Auth : public UGameInstanceSubsystem { GENERATED_BODY() - FWeb3AuthOptions web3AuthOptions; - static FWeb3AuthResponse web3AuthResponse; - TSharedPtr httpRouter; TArray, FHttpRouteHandle>> httpRoutes; - - static FOnLogin loginEvent; - static FOnLogout logoutEvent; - - - static UKeyStoreUtils* keyStoreUtils; - static UECCrypto* crypto; - + FWeb3AuthResponse web3AuthResponse; + UPROPERTY(Transient) + UECCrypto* crypto; + UPROPERTY(Transient) UWeb3AuthApi* web3AuthApi = UWeb3AuthApi::GetInstance(); + FWeb3AuthOptions web3AuthOptions; + FOnLogin loginEvent; + FOnLogout logoutEvent; protected: - // Called when the game starts or when spawned - virtual void BeginPlay() override; - - virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override; - + virtual void Initialize(FSubsystemCollectionBase& Collection) override; + virtual void Deinitialize() override; public: - // Called every frame - virtual void Tick(float DeltaTime) override; -public: - AWeb3Auth(); + UPROPERTY() + FString sessionId = FString(); UFUNCTION(BlueprintCallable) void setOptions(FWeb3AuthOptions web3authOptions); @@ -608,23 +598,20 @@ class WEB3AUTHSDK_API AWeb3Auth : public AActor UFUNCTION(BlueprintCallable) void processLogin(FLoginParams loginParams); - /*UFUNCTION(BlueprintCallable) - void logout(FJsonObject params);*/ - UFUNCTION(BlueprintCallable) - void proccessLogout(FString redirectUrl = "", FString appState = ""); + void processLogout(); UFUNCTION(BlueprintCallable) - static void setResultUrl(FString code); + void setResultUrl(FString code); UFUNCTION(BlueprintCallable, Category = "Web3Auth") - static void setLoginEvent(FOnLogin _event); + void setLoginEvent(FOnLogin _event); UFUNCTION(BlueprintCallable, Category = "Web3Auth") - static void setLogoutEvent(FOnLogout _event); + void setLogoutEvent(FOnLogout _event); UFUNCTION(BlueprintCallable) - static FString Web3AuthResponseToJsonString(FWeb3AuthResponse response) { + FString Web3AuthResponseToJsonString(FWeb3AuthResponse response) { FString output; FJsonObjectConverter::UStructToJsonObjectString(FWeb3AuthResponse::StaticStruct(), &response, output, 0, 0); @@ -643,8 +630,6 @@ class WEB3AUTHSDK_API AWeb3Auth : public AActor #if PLATFORM_IOS static void callBackFromWebAuthenticateIOS(NSString* sResult); #endif - - ~AWeb3Auth(); private: void request(FString path, FLoginParams* loginParams, TSharedPtr extraParam); diff --git a/Source/.DS_Store b/Source/.DS_Store deleted file mode 100644 index c9c2b5f..0000000 Binary files a/Source/.DS_Store and /dev/null differ