From d6abcf82ecf98c968af59446a31a313766c87991 Mon Sep 17 00:00:00 2001 From: Gaurav Goel Date: Wed, 29 Mar 2023 09:55:11 +0530 Subject: [PATCH 1/5] coreKitKey and coreKitEd25519PrivKey added in FWeb3AuthResponse --- .../Source/Web3AuthSDK/Private/Web3Auth.cpp | 6 ++++++ .../Source/Web3AuthSDK/Public/Web3Auth.h | 21 ++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/Web3Auth.cpp b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/Web3Auth.cpp index eb86d7e..1d0555a 100644 --- a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/Web3Auth.cpp +++ b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/Web3Auth.cpp @@ -63,6 +63,12 @@ void AWeb3Auth::request(FString path, FLoginParams* loginParams = NULL, TShared case FNetwork::CYAN: initParams->SetStringField("network", "cyan"); break; + case FNetwork::AQUA: + initParams->SetStringField("network", "aqua"); + break; + case FNetwork::CELESTE: + initParams->SetStringField("network", "celeste"); + break; } diff --git a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3Auth.h b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3Auth.h index f98a7d4..9131864 100644 --- a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3Auth.h +++ b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3Auth.h @@ -109,9 +109,15 @@ enum class FMFALevel : uint8 UENUM(BlueprintType) enum class FNetwork : uint8 { - MAINNET = 0, TESTNET = 1, CYAN = 2 + MAINNET = 0, TESTNET = 1, CYAN = 2, AQUA = 3, CELESTE = 4 }; +UENUM(BlueprintType) +enum class FChainNamespace : uint8 +{ + EIP555, + SOLANA +}; USTRUCT(BlueprintType) struct WEB3AUTHSDK_API FExtraLoginOptions @@ -482,6 +488,11 @@ struct FWeb3AuthOptions UPROPERTY(BlueprintReadWrite) TMap loginConfig; + UPROPERTY(EditAnywhere, BlueprintReadWrite) + FChainNamespace chainNamespace; + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + FBool useCoreKitKey; FWeb3AuthOptions() {}; @@ -492,6 +503,8 @@ struct FWeb3AuthOptions network = other.network; whiteLabel = other.whiteLabel; loginConfig = other.loginConfig; + chainNamespace = other.chainNamespace; + useCoreKitKey = other.useCoreKitKey } }; @@ -517,6 +530,12 @@ struct FWeb3AuthResponse UPROPERTY(EditAnywhere, BlueprintReadWrite) FUserInfo userInfo; + UPROPERTY(EditAnywhere, BlueprintReadWrite) + FString coreKitKey; + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + FString coreKitEd25519PrivKey; + FWeb3AuthResponse() {}; }; From e885d9e4a37b734784adf7898f4f22e3fcef76c5 Mon Sep 17 00:00:00 2001 From: Muhammad Usman Date: Wed, 5 Apr 2023 12:46:55 +0500 Subject: [PATCH 2/5] code fixes --- .../Source/Web3AuthSDK/Private/Web3Auth.cpp | 23 +++++++++++++++++-- .../Source/Web3AuthSDK/Public/Web3Auth.h | 15 ++++++++++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/Web3Auth.cpp b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/Web3Auth.cpp index 1d0555a..e579690 100644 --- a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/Web3Auth.cpp +++ b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/Web3Auth.cpp @@ -10,6 +10,8 @@ FOnLogin AWeb3Auth::loginEvent; FOnLogout AWeb3Auth::logoutEvent; +FWeb3AuthResponse AWeb3Auth::web3AuthResponse; + #if PLATFORM_ANDROID JNI_METHOD void Java_com_epicgames_unreal_GameActivity_onDeepLink(JNIEnv* env, jclass clazz, jstring uri) { if (JNIEnv* Env = FAndroidApplication::GetJavaEnv(true)) { @@ -131,6 +133,13 @@ void AWeb3Auth::request(FString path, FLoginParams* loginParams = NULL, TShared const FString jsonOutput = json; FString base64 = FBase64::Encode(jsonOutput); + if (web3AuthOptions.network == FNetwork::TESTNET) { + web3AuthOptions.sdkUrl = "https://dev-sdk.openlogin.com"; + } + else { + web3AuthOptions.sdkUrl = "https://sdk.openlogin.com"; + } + FString url = web3AuthOptions.sdkUrl + "/" + path + "#" + base64; #if PLATFORM_ANDROID @@ -197,8 +206,6 @@ void AWeb3Auth::setResultUrl(FString hash) { UE_LOG(LogTemp, Warning, TEXT("respose json %s"), *json); - FWeb3AuthResponse web3AuthResponse; - if (!FJsonObjectConverter::JsonObjectStringToUStruct(json, &web3AuthResponse, 0, 0)) { UE_LOG(LogTemp, Warning, TEXT("failed to parse json")); } @@ -337,6 +344,18 @@ void AWeb3Auth::callBackFromWebAuthenticateIOS(NSString* sResult) { } #endif +FString AWeb3Auth::getPrivKey() { + return web3AuthOptions.useCoreKitKey ? web3AuthResponse.coreKitKey : web3AuthResponse.privKey; +} + +FString AWeb3Auth::getEd25519PrivKey() { + return web3AuthOptions.useCoreKitKey ? web3AuthResponse.coreKitEd25519PrivKey : web3AuthResponse.ed25519PrivKey; +} + +FUserInfo AWeb3Auth::getUserInfo() { + return web3AuthResponse.userInfo; +} + void AWeb3Auth::BeginPlay() { Super::BeginPlay(); } diff --git a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3Auth.h b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3Auth.h index 9131864..4c658ed 100644 --- a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3Auth.h +++ b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3Auth.h @@ -492,7 +492,7 @@ struct FWeb3AuthOptions FChainNamespace chainNamespace; UPROPERTY(EditAnywhere, BlueprintReadWrite) - FBool useCoreKitKey; + bool useCoreKitKey; FWeb3AuthOptions() {}; @@ -504,7 +504,7 @@ struct FWeb3AuthOptions whiteLabel = other.whiteLabel; loginConfig = other.loginConfig; chainNamespace = other.chainNamespace; - useCoreKitKey = other.useCoreKitKey + useCoreKitKey = other.useCoreKitKey; } }; @@ -551,6 +551,7 @@ class WEB3AUTHSDK_API AWeb3Auth : public AActor GENERATED_BODY() FWeb3AuthOptions web3AuthOptions; + static FWeb3AuthResponse web3AuthResponse; TSharedPtr httpRouter; TArray, FHttpRouteHandle>> httpRoutes; @@ -600,6 +601,15 @@ class WEB3AUTHSDK_API AWeb3Auth : public AActor return output; } + UFUNCTION(BlueprintCallable) + FString getPrivKey(); + + UFUNCTION(BlueprintCallable) + FString getEd25519PrivKey(); + + UFUNCTION(BlueprintCallable) + FUserInfo getUserInfo(); + #if PLATFORM_IOS static void callBackFromWebAuthenticateIOS(NSString* sResult); #endif @@ -619,4 +629,5 @@ class WEB3AUTHSDK_API AWeb3Auth : public AActor bool requestAuthCallback(const FHttpServerRequest& Request, const FHttpResultCallback& OnComplete); bool requestCompleteCallback(const FHttpServerRequest& Request, const FHttpResultCallback& OnComplete); + }; From e53dd3c760f0df5256ea937e9e8499324c22f4f9 Mon Sep 17 00:00:00 2001 From: Muhammad Usman Date: Mon, 17 Apr 2023 16:59:57 +0500 Subject: [PATCH 3/5] updates --- .../Source/Web3AuthSDK/Private/Web3Auth.cpp | 25 ++++++++++- .../Web3AuthSDK/Private/Web3AuthError.cpp | 1 + .../Source/Web3AuthSDK/Public/Web3Auth.h | 17 +++++++- .../Source/Web3AuthSDK/Public/Web3AuthError.h | 43 +++++++++++++++++++ 4 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/Web3AuthError.cpp create mode 100644 Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3AuthError.h diff --git a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/Web3Auth.cpp b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/Web3Auth.cpp index e579690..65ac48c 100644 --- a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/Web3Auth.cpp +++ b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/Web3Auth.cpp @@ -345,14 +345,35 @@ void AWeb3Auth::callBackFromWebAuthenticateIOS(NSString* sResult) { #endif FString AWeb3Auth::getPrivKey() { - return web3AuthOptions.useCoreKitKey ? web3AuthResponse.coreKitKey : web3AuthResponse.privKey; + if (web3AuthResponse.coreKitKey.IsEmpty() || web3AuthResponse.privKey.IsEmpty()) { + FString error = Web3AuthError::getError(ErrorCode::NOUSERFOUND); + UE_LOG(LogTemp, Fatal, TEXT("%s"), *error); + + return ""; + } + + return web3AuthOptions.useCoreKitKey ? web3AuthResponse.coreKitKey : web3AuthResponse.privKey; } FString AWeb3Auth::getEd25519PrivKey() { - return web3AuthOptions.useCoreKitKey ? web3AuthResponse.coreKitEd25519PrivKey : web3AuthResponse.ed25519PrivKey; + if (web3AuthResponse.coreKitEd25519PrivKey.IsEmpty() || web3AuthResponse.ed25519PrivKey.IsEmpty()) { + FString error = Web3AuthError::getError(ErrorCode::NOUSERFOUND); + UE_LOG(LogTemp, Fatal, TEXT("%s"), *error); + + return ""; + } + + return web3AuthOptions.useCoreKitKey ? web3AuthResponse.coreKitEd25519PrivKey : web3AuthResponse.ed25519PrivKey; } FUserInfo AWeb3Auth::getUserInfo() { + if (web3AuthResponse.userInfo.IsEmpty()) { + FString error = Web3AuthError::getError(ErrorCode::NOUSERFOUND); + UE_LOG(LogTemp, Fatal, TEXT("%s"), *error); + + return FUserInfo(); + } + return web3AuthResponse.userInfo; } diff --git a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/Web3AuthError.cpp b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/Web3AuthError.cpp new file mode 100644 index 0000000..be82a42 --- /dev/null +++ b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/Web3AuthError.cpp @@ -0,0 +1 @@ +#include "Web3AuthError.h" diff --git a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3Auth.h b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3Auth.h index 4c658ed..686d9e3 100644 --- a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3Auth.h +++ b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3Auth.h @@ -19,12 +19,13 @@ #include "Runtime/Online/HTTPServer/Public/HttpServerModule.h" #include "Runtime/Online/HTTPServer/Public/HttpServerResponse.h" - #if PLATFORM_ANDROID #include "../../../Launch/Public/Android/AndroidJNI.h" #include "Android/AndroidApplication.h" #endif +#include "Web3AuthError.h" + #include "Web3Auth.generated.h" @@ -424,6 +425,20 @@ struct FUserInfo FUserInfo() {}; + bool IsEmpty() const { + return email.IsEmpty() + && name.IsEmpty() + && profileImage.IsEmpty() + && aggregateVerifier.IsEmpty() + && verifier.IsEmpty() + && verifierId.IsEmpty() + && typeOfLogin.IsEmpty() + && dappShare.IsEmpty() + && idToken.IsEmpty() + && oAuthIdToken.IsEmpty() + && oAuthAccessToken.IsEmpty(); + } + }; diff --git a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3AuthError.h b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3AuthError.h new file mode 100644 index 0000000..5994e0c --- /dev/null +++ b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3AuthError.h @@ -0,0 +1,43 @@ +#pragma once + +#include "CoreMinimal.h" +#include + +enum ErrorCode +{ + NOUSERFOUND, + ENCODING_ERROR, + DECODING_ERROR, + SOMETHING_WENT_WRONG, + RUNTIME_ERROR, + APP_CANCELLED +}; + +class Web3AuthError +{ +public: + static FString getError(ErrorCode code) { + switch (code) + { + case ErrorCode::NOUSERFOUND: + return "No user found, please login again!"; + break; + case ErrorCode::ENCODING_ERROR: + return "Encoding Error"; + break; + case ErrorCode::DECODING_ERROR: + return "Decoding Error"; + break; + case ErrorCode::SOMETHING_WENT_WRONG: + return "Something went wrong!"; + break; + case ErrorCode::RUNTIME_ERROR: + return "Runtime Error"; + break; + case ErrorCode::APP_CANCELLED: + return "App Cancelled"; + break; + } + return ""; + } +}; \ No newline at end of file From f5eda73b75e03045abc6cbc26532eb49e8699fe7 Mon Sep 17 00:00:00 2001 From: Gaurav Goel Date: Wed, 7 Jun 2023 09:47:37 +0530 Subject: [PATCH 4/5] removing celeste network and exception from getPrivKey and getEd25519PrivKey method --- .../Source/Web3AuthSDK/Private/Web3Auth.cpp | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/Web3Auth.cpp b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/Web3Auth.cpp index 65ac48c..5079755 100644 --- a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/Web3Auth.cpp +++ b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/Web3Auth.cpp @@ -68,10 +68,6 @@ void AWeb3Auth::request(FString path, FLoginParams* loginParams = NULL, TShared case FNetwork::AQUA: initParams->SetStringField("network", "aqua"); break; - case FNetwork::CELESTE: - initParams->SetStringField("network", "celeste"); - break; - } if (web3AuthOptions.redirectUrl != "") @@ -346,9 +342,6 @@ void AWeb3Auth::callBackFromWebAuthenticateIOS(NSString* sResult) { FString AWeb3Auth::getPrivKey() { if (web3AuthResponse.coreKitKey.IsEmpty() || web3AuthResponse.privKey.IsEmpty()) { - FString error = Web3AuthError::getError(ErrorCode::NOUSERFOUND); - UE_LOG(LogTemp, Fatal, TEXT("%s"), *error); - return ""; } @@ -357,9 +350,6 @@ FString AWeb3Auth::getPrivKey() { FString AWeb3Auth::getEd25519PrivKey() { if (web3AuthResponse.coreKitEd25519PrivKey.IsEmpty() || web3AuthResponse.ed25519PrivKey.IsEmpty()) { - FString error = Web3AuthError::getError(ErrorCode::NOUSERFOUND); - UE_LOG(LogTemp, Fatal, TEXT("%s"), *error); - return ""; } From 3de98d868fc23c98ed2018da6535b10e3207d8fd Mon Sep 17 00:00:00 2001 From: Gaurav Goel Date: Wed, 7 Jun 2023 09:54:44 +0530 Subject: [PATCH 5/5] removing celeste network --- Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3Auth.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3Auth.h b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3Auth.h index 686d9e3..12b7a6f 100644 --- a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3Auth.h +++ b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3Auth.h @@ -110,7 +110,7 @@ enum class FMFALevel : uint8 UENUM(BlueprintType) enum class FNetwork : uint8 { - MAINNET = 0, TESTNET = 1, CYAN = 2, AQUA = 3, CELESTE = 4 + MAINNET = 0, TESTNET = 1, CYAN = 2, AQUA = 3 }; UENUM(BlueprintType)