Skip to content

Commit f1b6b66

Browse files
Merge pull request #18 from Web3Auth/refactor
Refactor: Convert from AActor to UGameInstanceSubsystem
2 parents 03a3d08 + c18f5e0 commit f1b6b66

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+121
-219
lines changed

.DS_Store

-6 KB
Binary file not shown.

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,4 @@ DerivedDataCache/*
7575
/Config/HoloLens
7676

7777
# MAC
78-
.DS_Store
78+
**/*.DS_Store

.vscode/settings.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
"ratio": "cpp",
1313
"system_error": "cpp",
1414
"tuple": "cpp",
15-
"vector": "cpp"
15+
"vector": "cpp",
16+
"__locale": "cpp",
17+
"__threading_support": "cpp",
18+
"string": "cpp",
19+
"string_view": "cpp",
20+
"variant": "cpp",
21+
"__config": "cpp",
22+
"array": "cpp"
1623
}
1724
}

Config/DefaultEngine.ini

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11

22

33
[/Script/EngineSettings.GameMapsSettings]
4-
GameDefaultMap=/Web3AuthSDK/Sample.Sample
5-
EditorStartupMap=/Web3AuthSDK/Sample.Sample
4+
GameDefaultMap=/Game/Example.Example
5+
EditorStartupMap=/Game/Example.Example
6+
GlobalDefaultGameMode=/Game/BaseGameMode.BaseGameMode_C
67

78
[/Script/HardwareTargeting.HardwareTargetingSettings]
89
TargetedHardwareClass=Desktop
@@ -75,3 +76,9 @@ AdditionalPlistData=<key>CFBundleURLTypes</key><array> <dict> <key>CFB
7576
[/Script/UnrealEd.CookerSettings]
7677
bCookOnTheFlyForLaunchOn=False
7778

79+
[/Web3AuthSDK/AuthInterface.AuthInterface_C]
80+
Web3AuthOptionsClientId=BAwFgL-r7wzQKmtcdiz2uHJKNZdK7gzEf2q-m55xfzSZOw8jLOyIi4AVvvzaEQO5nv2dFLEmf9LBkF8kaq3aErg
81+
Web3AuthOptionsRedirectUrl=torusapp://com.torus.Web3AuthUnity/auth
82+
Web3AuthOptionsSdkUrl=https://sdk.openlogin.com
83+
Web3AuthOptionsNetwork=MAINNET
84+

Content/BaseGameMode.uasset

19.2 KB
Binary file not shown.

Content/Example.umap

9.76 KB
Binary file not shown.

Content/Player.uasset

23.6 KB
Binary file not shown.

Plugins/.DS_Store

-6 KB
Binary file not shown.

Plugins/Web3AuthSDK/.DS_Store

-6 KB
Binary file not shown.

Plugins/Web3AuthSDK/Content/.DS_Store

-6 KB
Binary file not shown.
43.7 KB
Binary file not shown.
-18.7 KB
Binary file not shown.
-8.83 KB
Binary file not shown.
-29.7 KB
Binary file not shown.
-53 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.

Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/ECCrypto.cpp

+33-8
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ FString UECCrypto::decrypt(FString data, FString privateKeyHex, FString ephemPub
6767
// Create a new encryption context for AES-256 CBC mode with the key and IV
6868
EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new();
6969
EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, key, iv);
70-
70+
EVP_CIPHER_CTX_set_padding(ctx, 0);
7171
// Allocate a string buffer for the decrypted data
7272
std::string dst;
7373
dst.resize(srclen + EVP_CIPHER_block_size(EVP_aes_256_cbc()));
@@ -162,21 +162,27 @@ FString UECCrypto::encrypt(FString data, FString privateKeyHex, FString ephemPub
162162
EC_KEY_free(pub_key);
163163
EVP_cleanup();
164164

165-
return FString(UTF8_TO_TCHAR(dst.c_str()));
165+
const char* buf = dst.c_str();
166+
167+
FString hex;
168+
for (int i = 0; i < strlen(buf); ++i) {
169+
hex += FString::Printf(TEXT("%02x"), buf[i]);
170+
}
171+
return hex;
166172
}
167173

168174
FString UECCrypto::generatePublicKey(const FString& privateKeyHex) {
169-
BIGNUM* bn_private_key = NULL;
170-
BN_hex2bn(&bn_private_key, TCHAR_TO_ANSI(*privateKeyHex));
175+
BIGNUM* bn_private_key = nullptr;
176+
BN_hex2bn(&bn_private_key, FStringToCharArray(*privateKeyHex));
171177

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

175181
EC_POINT* ec_point = EC_POINT_new(EC_KEY_get0_group(ec_key));
176-
EC_POINT_mul(EC_KEY_get0_group(ec_key), ec_point, EC_KEY_get0_private_key(ec_key), NULL, NULL, NULL);
182+
EC_POINT_mul(EC_KEY_get0_group(ec_key), ec_point, EC_KEY_get0_private_key(ec_key), nullptr, nullptr, nullptr);
177183
EC_KEY_set_public_key(ec_key, ec_point);
178184

179-
BIGNUM* bn = EC_POINT_point2bn(EC_KEY_get0_group(ec_key), EC_KEY_get0_public_key(ec_key), POINT_CONVERSION_UNCOMPRESSED, NULL, NULL);
185+
BIGNUM* bn = EC_POINT_point2bn(EC_KEY_get0_group(ec_key), EC_KEY_get0_public_key(ec_key), POINT_CONVERSION_UNCOMPRESSED, nullptr, nullptr);
180186

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

194-
BIGNUM* priv_bn = BN_new();
200+
BIGNUM* priv_bn = nullptr;
195201
BN_hex2bn(&priv_bn, FStringToCharArray(privateKeyHex));
196202

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

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

215+
BN_CTX *ctx = BN_CTX_new();
216+
BN_CTX_start(ctx);
217+
const EC_GROUP *group = EC_KEY_get0_group(key);
218+
BIGNUM *order = BN_CTX_get(ctx);
219+
BIGNUM *halforder = BN_CTX_get(ctx);
220+
EC_GROUP_get_order(group, order, ctx);
221+
BN_rshift1(halforder, order);
222+
const BIGNUM* pr = nullptr;
223+
const BIGNUM* ps = nullptr;
224+
ECDSA_SIG_get0(signature, &pr, &ps);
225+
if (BN_cmp(ps, halforder) > 0) {
226+
// enforce low S values. libsecp256k1 does this by default, openssl does not.
227+
BN_sub(const_cast<BIGNUM*>(ps), order, ps);
228+
}
229+
BN_CTX_end(ctx);
230+
BN_CTX_free(ctx);
231+
232+
int n = i2d_ECDSA_SIG(signature, &sig_buf);
233+
210234
//// Convert signature to hex string
211235
FString signature_hex;
212236
for (int i = 0; i < n; ++i) {
@@ -215,6 +239,7 @@ FString UECCrypto::generateECDSASignature(const FString& privateKeyHex, const FS
215239

216240
EC_KEY_free(key);
217241
ECDSA_SIG_free(signature);
242+
BN_free(priv_bn);
218243

219244
return signature_hex;
220245
}

Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/IOS/ObjC/WebAuthenticate.mm

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ - (void) launchUrl:(const char*)url
3232
ASWebAuthenticationSession* authSession = [[ASWebAuthenticationSession alloc] initWithURL:URL callbackURLScheme:bundleIdentifier completionHandler:^(NSURL * _Nullable callbackURL, NSError * _Nullable error) {
3333

3434
if(callbackURL) {
35-
AWeb3Auth::callBackFromWebAuthenticateIOS(callbackURL.fragment);
35+
UWeb3Auth::callBackFromWebAuthenticateIOS(callbackURL.fragment);
3636
} else {
3737
return;
3838
}

Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/KeyStoreUtils.cpp

-40
This file was deleted.

0 commit comments

Comments
 (0)