Skip to content
Closed
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
42 changes: 39 additions & 3 deletions Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/Web3Auth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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 != "")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"));
}
Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "Web3AuthError.h"
49 changes: 47 additions & 2 deletions Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3Auth.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
}

};


Expand Down Expand Up @@ -482,6 +503,11 @@ struct FWeb3AuthOptions
UPROPERTY(BlueprintReadWrite)
TMap<FString, FLoginConfigItem> loginConfig;

UPROPERTY(EditAnywhere, BlueprintReadWrite)
FChainNamespace chainNamespace;

UPROPERTY(EditAnywhere, BlueprintReadWrite)
bool useCoreKitKey;

FWeb3AuthOptions() {};

Expand All @@ -492,6 +518,8 @@ struct FWeb3AuthOptions
network = other.network;
whiteLabel = other.whiteLabel;
loginConfig = other.loginConfig;
chainNamespace = other.chainNamespace;
useCoreKitKey = other.useCoreKitKey;
}

};
Expand All @@ -517,6 +545,12 @@ struct FWeb3AuthResponse
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FUserInfo userInfo;

UPROPERTY(EditAnywhere, BlueprintReadWrite)
FString coreKitKey;

UPROPERTY(EditAnywhere, BlueprintReadWrite)
FString coreKitEd25519PrivKey;

FWeb3AuthResponse() {};

};
Expand All @@ -532,6 +566,7 @@ class WEB3AUTHSDK_API AWeb3Auth : public AActor
GENERATED_BODY()

FWeb3AuthOptions web3AuthOptions;
static FWeb3AuthResponse web3AuthResponse;

TSharedPtr<IHttpRouter> httpRouter;
TArray<TPair<TSharedPtr<IHttpRouter>, FHttpRouteHandle>> httpRoutes;
Expand Down Expand Up @@ -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
Expand All @@ -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);

};
43 changes: 43 additions & 0 deletions Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3AuthError.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#pragma once

#include "CoreMinimal.h"
#include <string>

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 "";
}
};