diff --git a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/Web3Auth.cpp b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/Web3Auth.cpp index eb86d7e..5079755 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)) { @@ -63,7 +65,9 @@ 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; } if (web3AuthOptions.redirectUrl != "") @@ -125,6 +129,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 @@ -191,8 +202,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")); } @@ -331,6 +340,33 @@ void AWeb3Auth::callBackFromWebAuthenticateIOS(NSString* sResult) { } #endif +FString AWeb3Auth::getPrivKey() { + if (web3AuthResponse.coreKitKey.IsEmpty() || web3AuthResponse.privKey.IsEmpty()) { + return ""; + } + + return web3AuthOptions.useCoreKitKey ? web3AuthResponse.coreKitKey : web3AuthResponse.privKey; +} + +FString AWeb3Auth::getEd25519PrivKey() { + if (web3AuthResponse.coreKitEd25519PrivKey.IsEmpty() || web3AuthResponse.ed25519PrivKey.IsEmpty()) { + 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; +} + void AWeb3Auth::BeginPlay() { Super::BeginPlay(); } 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 f98a7d4..12b7a6f 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" @@ -109,9 +110,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 }; +UENUM(BlueprintType) +enum class FChainNamespace : uint8 +{ + EIP555, + SOLANA +}; USTRUCT(BlueprintType) struct WEB3AUTHSDK_API FExtraLoginOptions @@ -418,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(); + } + }; @@ -482,6 +503,11 @@ struct FWeb3AuthOptions UPROPERTY(BlueprintReadWrite) TMap loginConfig; + UPROPERTY(EditAnywhere, BlueprintReadWrite) + FChainNamespace chainNamespace; + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + bool useCoreKitKey; FWeb3AuthOptions() {}; @@ -492,6 +518,8 @@ struct FWeb3AuthOptions network = other.network; whiteLabel = other.whiteLabel; loginConfig = other.loginConfig; + chainNamespace = other.chainNamespace; + useCoreKitKey = other.useCoreKitKey; } }; @@ -517,6 +545,12 @@ struct FWeb3AuthResponse UPROPERTY(EditAnywhere, BlueprintReadWrite) FUserInfo userInfo; + UPROPERTY(EditAnywhere, BlueprintReadWrite) + FString coreKitKey; + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + FString coreKitEd25519PrivKey; + FWeb3AuthResponse() {}; }; @@ -532,6 +566,7 @@ class WEB3AUTHSDK_API AWeb3Auth : public AActor GENERATED_BODY() FWeb3AuthOptions web3AuthOptions; + static FWeb3AuthResponse web3AuthResponse; TSharedPtr httpRouter; TArray, FHttpRouteHandle>> httpRoutes; @@ -581,6 +616,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 @@ -600,4 +644,5 @@ class WEB3AUTHSDK_API AWeb3Auth : public AActor bool requestAuthCallback(const FHttpServerRequest& Request, const FHttpResultCallback& OnComplete); bool requestCompleteCallback(const FHttpServerRequest& Request, const FHttpResultCallback& OnComplete); + }; 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