diff --git a/Config/DefaultEngine.ini b/Config/DefaultEngine.ini index 880e9c6..ab56795 100644 --- a/Config/DefaultEngine.ini +++ b/Config/DefaultEngine.ini @@ -106,13 +106,15 @@ AdditionalPlistData=CFBundleURLTypes CFB bCookOnTheFlyForLaunchOn=False [/Web3AuthSDK/AuthInterface.AuthInterface_C] -Web3AuthOptionsClientId="BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ" +Web3AuthOptionsClientId="BHgArYmWwSeq21czpcarYh0EVq2WWOzflX-NTK-tY1-1pauPzHKRRLgpABkmYiIV_og9jAvoIxQ8L3Smrwe04Lw" Web3AuthOptionsRedirectUrl="torusapp://com.torus.web3authunity/auth" -Web3AuthOptionsSdkUrl="https://sdk.openlogin.com/" -Web3AuthOptionsNetwork=SAPPHIRE_MAINNET +Web3AuthOptionsNetwork=SAPPHIRE_DEVNET +Web3AuthOptionsBuildEnv=TESTING WhiteLabelAppName="Web3AuthUnrealDemo" WhiteLabelDefaultLanguage=en -WhiteLabelTheme=dark -Web3AuthOptionsBuildEnv=PRODUCTION LoginParamsMfaLevel=NONE +ChainConfigChainId="0x1" +ChainConfigRpcTarget="https://mainnet.infura.io/v3/daeee53504be4cd3a997d4f2718d33e0" +ChainConfigTicker="ETH" +ExtraLoginOptionsLoginHint="testtkey@gmail.com" diff --git a/Plugins/Web3AuthSDK/Content/AuthInterface.uasset b/Plugins/Web3AuthSDK/Content/AuthInterface.uasset index b573830..c48ddee 100644 Binary files a/Plugins/Web3AuthSDK/Content/AuthInterface.uasset and b/Plugins/Web3AuthSDK/Content/AuthInterface.uasset differ diff --git a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/Web3Auth.cpp b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/Web3Auth.cpp index 22b0516..65b183c 100644 --- a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/Web3Auth.cpp +++ b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/Web3Auth.cpp @@ -28,7 +28,7 @@ JNI_METHOD void Java_com_epicgames_unreal_GameActivity_onDeepLink(JNIEnv* env, j const char* UTFString = Env->GetStringUTFChars(uri, 0); FString result = FString(UTF8_TO_TCHAR(UTFString)); - UE_LOG(LogTemp, Warning, TEXT("redirect %s"), *result); + UE_LOG(LogTemp, Warning, TEXT("result %s"), *result); thiz_instance->setResultUrl(result); Env->ReleaseStringUTFChars(uri, UTFString); @@ -51,7 +51,7 @@ void UWeb3Auth::setOptions(FWeb3AuthOptions options) { authorizeSession(); } -void UWeb3Auth::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); @@ -120,6 +120,10 @@ void UWeb3Auth::request(FString path, FLoginParams* loginParams = NULL, TShared initParams->SetStringField("whiteLabel", output); } + FString chainConfigOutput; + FJsonObjectConverter::UStructToJsonObjectString(FChainConfig::StaticStruct(), &web3AuthOptions.chainConfig, chainConfigOutput); + initParams->SetStringField("chainConfig", chainConfigOutput); + if (!web3AuthOptions.loginConfig.IsEmpty()) { FString output; @@ -132,14 +136,18 @@ void UWeb3Auth::request(FString path, FLoginParams* loginParams = NULL, TShared loginConfigMap->SetObjectField(item.Key, loginConfigObject); } - TSharedRef< TJsonWriter<> > Writer = TJsonWriterFactory<>::Create(&output); + TSharedRef> Writer = TJsonWriterFactory<>::Create(&output); FJsonSerializer::Serialize(loginConfigMap.ToSharedRef(), Writer); initParams->SetStringField("loginConfig", output); } paramMap->SetObjectField("options", initParams.ToSharedRef()); - paramMap->SetStringField("actionType", "login"); + paramMap->SetStringField("actionType", path); + + if (path.Equals("enable_mfa")) { + paramMap->SetStringField("sessionId", this->sessionId); + } TSharedPtr params = MakeShareable(new FJsonObject); @@ -189,24 +197,194 @@ void UWeb3Auth::request(FString path, FLoginParams* loginParams = NULL, TShared FJsonSerializer::Serialize(paramMap.ToSharedRef(), jsonWriter); if (web3AuthOptions.buildEnv == FBuildEnv::STAGING) { - web3AuthOptions.sdkUrl = "https://staging-auth.web3auth.io/v6"; + web3AuthOptions.sdkUrl = "https://staging-auth.web3auth.io/v8"; } else if(web3AuthOptions.buildEnv == FBuildEnv::TESTING) { web3AuthOptions.sdkUrl = "https://develop-auth.web3auth.io"; } else { - web3AuthOptions.sdkUrl = "https://auth.web3auth.io/v6"; + web3AuthOptions.sdkUrl = "https://auth.web3auth.io/v8"; } - createSession(json, 600); + if (web3AuthOptions.buildEnv == FBuildEnv::STAGING) { + web3AuthOptions.walletSdkUrl = "https://staging-wallet.web3auth.io/v1"; + } else if (web3AuthOptions.buildEnv == FBuildEnv::TESTING) { + web3AuthOptions.walletSdkUrl = "https://develop-wallet.web3auth.io"; + } else { + web3AuthOptions.walletSdkUrl = "https://wallet.web3auth.io/v1"; + } + + createSession(json, 600, false); +} + +void UWeb3Auth::launchWalletServices(FLoginParams loginParams, FChainConfig chainConfig) { + this->sessionId = keyStoreUtils->Get(); + if (!this->sessionId.IsEmpty()) { + TSharedPtr paramMap = MakeShareable(new FJsonObject); + + TSharedPtr initParams = MakeShareable(new FJsonObject); + initParams->SetStringField("clientId", web3AuthOptions.clientId); + + switch (web3AuthOptions.network) { + case FNetwork::MAINNET: + initParams->SetStringField("network", "mainnet"); + break; + case FNetwork::TESTNET: + initParams->SetStringField("network", "testnet"); + break; + case FNetwork::CYAN: + initParams->SetStringField("network", "cyan"); + break; + case FNetwork::AQUA: + initParams->SetStringField("network", "aqua"); + break; + case FNetwork::SAPPHIRE_DEVNET: + initParams->SetStringField("network", "sapphire_devnet"); + break; + case FNetwork::SAPPHIRE_MAINNET: + initParams->SetStringField("network", "sapphire_mainnet"); + break; + } + + FMfaSettings defaultMFA; + + if (!(web3AuthOptions.mfaSettings == defaultMFA)) { + FString mfaSettingsJson; + FJsonObjectConverter::UStructToJsonObjectString(web3AuthOptions.mfaSettings, + mfaSettingsJson); + initParams->SetStringField(TEXT("mfaSettings"), mfaSettingsJson); + } + + if (web3AuthOptions.sessionTime > 0) { + initParams->SetNumberField(TEXT("sessionTime"), web3AuthOptions.sessionTime); + } + +#if !PLATFORM_ANDROID && !PLATFORM_IOS + FString redirectUrl = startLocalWebServer(); + initParams->SetStringField("redirectUrl", redirectUrl); +#else + if (web3AuthOptions.redirectUrl != "") + initParams->SetStringField("redirectUrl", web3AuthOptions.redirectUrl); +#endif + + switch (web3AuthOptions.buildEnv) { + case FBuildEnv::PRODUCTION: + initParams->SetStringField("buildEnv", "production"); + break; + case FBuildEnv::TESTING: + initParams->SetStringField("buildEnv", "testing"); + break; + case FBuildEnv::STAGING: + initParams->SetStringField("buildEnv", "staging"); + break; + } + + if (web3AuthOptions.whiteLabel.appName != "") { + FString output; + FJsonObjectConverter::UStructToJsonObjectString(FWhiteLabelData::StaticStruct(), + &web3AuthOptions.whiteLabel, output); + + initParams->SetStringField("whiteLabel", output); + } + + FString chainConfigOutput; + FJsonObjectConverter::UStructToJsonObjectString(FChainConfig::StaticStruct(), &chainConfig, chainConfigOutput); + initParams->SetStringField("chainConfig", chainConfigOutput); + + if (!web3AuthOptions.loginConfig.IsEmpty()) { + FString output; + + TSharedPtr loginConfigMap = MakeShareable(new FJsonObject); + + for (auto item: web3AuthOptions.loginConfig) { + TSharedPtr loginConfigObject = MakeShareable(new FJsonObject); + FJsonObjectConverter::UStructToJsonObject(FLoginConfigItem::StaticStruct(), + &item.Value, + loginConfigObject.ToSharedRef(), 0, 0); + + loginConfigMap->SetObjectField(item.Key, loginConfigObject); + } + + TSharedRef > Writer = TJsonWriterFactory<>::Create(&output); + FJsonSerializer::Serialize(loginConfigMap.ToSharedRef(), Writer); + + initParams->SetStringField("loginConfig", output); + } + + paramMap->SetObjectField("options", initParams.ToSharedRef()); + paramMap->SetStringField("actionType", "login"); + + TSharedPtr params = MakeShareable(new FJsonObject); + + if (loginParams.curve == FCurve::SECP256K1) + params->SetStringField("curve", "secp256k1"); + else { + params->SetStringField("curve", "ed25519"); + } + + for (auto& o : loginParams.getJsonObject().Values) { + params->SetField(o.Key, o.Value); + } + + if (loginParams.dappShare != "") { + params->SetStringField("dappShare", loginParams.dappShare); + } + + switch (loginParams.mfaLevel) { + case FMFALevel::DEFAULT: + params->SetStringField("mfaLevel", "default"); + break; + case FMFALevel::OPTIONAL: + params->SetStringField("mfaLevel", "optional"); + break; + case FMFALevel::MANDATORY: + params->SetStringField("mfaLevel", "mandatory"); + break; + case FMFALevel::NONE: + params->SetStringField("mfaLevel", "none"); + break; + } + +#if !PLATFORM_ANDROID && !PLATFORM_IOS + params->SetStringField("redirectUrl", redirectUrl); +#endif + + paramMap->SetObjectField("params", params.ToSharedRef()); + + FString json; + TSharedRef > jsonWriter = TJsonWriterFactory<>::Create(&json); + FJsonSerializer::Serialize(paramMap.ToSharedRef(), jsonWriter); + + if (web3AuthOptions.buildEnv == FBuildEnv::STAGING) { + web3AuthOptions.walletSdkUrl = "https://staging-wallet.web3auth.io/v1"; + } else if (web3AuthOptions.buildEnv == FBuildEnv::TESTING) { + web3AuthOptions.walletSdkUrl = "https://develop-wallet.web3auth.io"; + } else { + web3AuthOptions.walletSdkUrl = "https://wallet.web3auth.io/v1"; + } + + createSession(json, 86400, true); + } else { + UE_LOG(LogTemp, Error, TEXT("SessionId not found. Please login first.")); + } } void UWeb3Auth::processLogin(FLoginParams loginParams) { UE_LOG(LogTemp, Warning, TEXT("login called")); - this->request("start", &loginParams); + this->request("login", &loginParams); } void UWeb3Auth::processLogout() { - sessionTimeout(); + sessionTimeout(); +} + +void UWeb3Auth::enableMFA(FLoginParams loginParams) { + UE_LOG(LogTemp, Warning, TEXT("enableMFA called")); + this->sessionId = keyStoreUtils->Get(); + if (!this->sessionId.IsEmpty()) { + this->request("enable_mfa", &loginParams); + } else { + UE_LOG(LogTemp, Error, TEXT("SessionId not found. Please login first.")); + } } void UWeb3Auth::setResultUrl(FString hash) { @@ -215,14 +393,26 @@ void UWeb3Auth::setResultUrl(FString hash) { return; } + //UE_LOG(LogTemp, Warning, TEXT("respose base64 %s"), *hash); - UE_LOG(LogTemp, Warning, TEXT("respose base64 %s"), *hash); + TArray decodedBytes; + FBase64::Decode(hash, decodedBytes); - int32 equalsIndex; - if (hash.FindChar('=', equalsIndex)) { - FString newSessionId = hash.Mid(equalsIndex + 1); - keyStoreUtils->Assign(newSessionId); - this->sessionId = newSessionId; + // Convert the decoded bytes to a UTF-8 string + FString decodedString = FString(UTF8_TO_TCHAR(decodedBytes.GetData())); + int32 braceIndex = decodedString.Find(TEXT("}")); + FString substringBeforeBrace = decodedString.Left(braceIndex + 1); + //UE_LOG(LogTemp, Warning, TEXT("substringBeforeBrace: %s"), *substringBeforeBrace); + + FSessionResponse response; + TSharedPtr jsonObject; + TSharedRef> reader = TJsonReaderFactory<>::Create(substringBeforeBrace); + if (FJsonSerializer::Deserialize(reader, jsonObject) && jsonObject.IsValid()) + { + jsonObject->TryGetStringField(TEXT("sessionId"), response.sessionId); + //UE_LOG(LogTemp, Warning, TEXT("Session-ID: %s"), *response.sessionId); + keyStoreUtils->Assign(*response.sessionId); + this->sessionId = *response.sessionId; } authorizeSession(); @@ -266,8 +456,8 @@ FString UWeb3Auth::startLocalWebServer() { bool UWeb3Auth::requestAuthCallback(const FHttpServerRequest& Request, const FHttpResultCallback& OnComplete) { - FString code = Request.QueryParams["code"]; - + FString code = Request.QueryParams["b64Params"]; + //UE_LOG(LogTemp, Warning, TEXT("code %s"), *code); if (!code.IsEmpty()) { setResultUrl(code); } @@ -339,6 +529,10 @@ void UWeb3Auth::setLogoutEvent(FOnLogout _event) { logoutEvent = _event; } +void UWeb3Auth::setMfaEvent(FOnMfaSetup _event) { + mfaEvent = _event; +} + #if PLATFORM_IOS void UWeb3Auth::callBackFromWebAuthenticateIOS(NSString* sResult) { FString result = FString(sResult); @@ -380,7 +574,7 @@ void UWeb3Auth::authorizeSession() { FString session = this->sessionId; web3AuthApi->AuthorizeSession(pubKey, [session, this](FStoreApiResponse response) { - UE_LOG(LogTemp, Log, TEXT("Response: %s"), *response.message); + //UE_LOG(LogTemp, Log, TEXT("Response: %s"), *response.message); FShareMetaData shareMetaData; @@ -390,7 +584,7 @@ void UWeb3Auth::authorizeSession() { } FString output = crypto->decrypt(shareMetaData.ciphertext, session, shareMetaData.ephemPublicKey, shareMetaData.iv, shareMetaData.mac); - UE_LOG(LogTemp, Log, TEXT("output %s"), *output); + //UE_LOG(LogTemp, Log, TEXT("output %s"), *output); TSharedPtr tempJson; TSharedRef> JsonReader = TJsonReaderFactory::Create(output); @@ -410,6 +604,7 @@ void UWeb3Auth::authorizeSession() { } this->loginEvent.ExecuteIfBound(web3AuthResponse); + this->mfaEvent.ExecuteIfBound(true); } }); @@ -422,7 +617,7 @@ void UWeb3Auth::sessionTimeout() { this->sessionId = keyStoreUtils->Get(); if (!this->sessionId.IsEmpty()) { FString pubKey = crypto->generatePublicKey(this->sessionId); - UE_LOG(LogTemp, Log, TEXT("public key %s"), *pubKey); + web3AuthApi->AuthorizeSession(pubKey, [pubKey, this](FStoreApiResponse response) { FShareMetaData shareMetaData; @@ -461,13 +656,12 @@ void UWeb3Auth::sessionTimeout() { } } -void UWeb3Auth::createSession(const FString& jsonData, int32 sessionTime) { +void UWeb3Auth::createSession(const FString& jsonData, int32 sessionTime, bool isWalletService) { + //UE_LOG(LogTemp, Log, TEXT("CreateSessionJson: %s"), *jsonData); FString newSessionKey = crypto->generateRandomSessionKey(); FString ephemPublicKey = crypto->generatePublicKey(newSessionKey); FString ivKey = crypto->generateRandomBytes(16); - UE_LOG(LogTemp, Warning, TEXT("jsonData => %s"), *jsonData); - FString macKeyHex = FString(); FString encryptedData = crypto->encrypt(jsonData, newSessionKey, ephemPublicKey, ivKey, macKeyHex); @@ -500,17 +694,26 @@ void UWeb3Auth::createSession(const FString& jsonData, int32 sessionTime) { request.signature = sig; request.timeout = FMath::Min(sessionTime, 7 * 86400); - web3AuthApi->CreateSession(request, [this, newSessionKey](FString response) + web3AuthApi->CreateSession(request, [this, newSessionKey, isWalletService](FString response) { UE_LOG(LogTemp, Log, TEXT("Response: %s"), *response); - handleCreateSessionResponse("start", newSessionKey); + if(isWalletService) { + handleCreateSessionResponse("wallet", newSessionKey, isWalletService); + } else { + handleCreateSessionResponse("start", newSessionKey, isWalletService); + } }); } -void UWeb3Auth::handleCreateSessionResponse(FString path, FString newSessionKey) { +void UWeb3Auth::handleCreateSessionResponse(FString path, FString newSessionKey, bool isWalletService) { TSharedPtr loginIdObject = MakeShareable(new FJsonObject); loginIdObject->SetStringField(TEXT("loginId"), newSessionKey); + if(isWalletService) { + this->sessionId = keyStoreUtils->Get(); + loginIdObject->SetStringField(TEXT("sessionId"), this->sessionId); + } + // Convert to Base64 FString output; TSharedRef< TJsonWriter<> > outputWriter = TJsonWriterFactory<>::Create(&output); @@ -518,7 +721,12 @@ void UWeb3Auth::handleCreateSessionResponse(FString path, FString newSessionKey) FString encode = FBase64::Encode(output); // Build the URI - FString url = web3AuthOptions.sdkUrl + "/" + path + "#" + "b64Params=" + encode; + FString url; + if(isWalletService) { + url = web3AuthOptions.walletSdkUrl + "/" + path + "#" + "b64Params=" + encode; + } else { + url = web3AuthOptions.sdkUrl + "/" + path + "#" + "b64Params=" + encode; + } #if PLATFORM_ANDROID thiz_instance = this; diff --git a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/Web3AuthApi.cpp b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/Web3AuthApi.cpp index 1061d71..9b2eb43 100644 --- a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/Web3AuthApi.cpp +++ b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/Web3AuthApi.cpp @@ -18,7 +18,7 @@ void UWeb3AuthApi::AuthorizeSession(const FString& key, const TFunction request = FHttpModule::Get().CreateRequest(); request->SetVerb(TEXT("POST")); - request->SetURL(TEXT("https://broadcast-server.tor.us/store/get?key=" + key)); + request->SetURL(TEXT("https://session.web3auth.io/store/get?key=" + key)); FString FormString = "key=" + key; @@ -51,7 +51,7 @@ void UWeb3AuthApi::Logout(const FLogoutApiRequest logoutApiRequest, const TFunct { TSharedRef request = FHttpModule::Get().CreateRequest(); request->SetVerb(TEXT("POST")); - request->SetURL(TEXT("https://broadcast-server.tor.us/store/set")); + request->SetURL(TEXT("https://session.web3auth.io/store/set")); FString FormString = "key=" + logoutApiRequest.key + "&data=" + FGenericPlatformHttp::UrlEncode(logoutApiRequest.data) + "&signature=" + logoutApiRequest.signature + "&timeout=" + FString::FromInt(logoutApiRequest.timeout); @@ -78,7 +78,7 @@ void UWeb3AuthApi::CreateSession(const FLogoutApiRequest logoutApiRequest, const { TSharedRef request = FHttpModule::Get().CreateRequest(); request->SetVerb(TEXT("POST")); - request->SetURL(TEXT("https://broadcast-server.tor.us/store/set")); + request->SetURL(TEXT("https://session.web3auth.io/store/set")); FString FormString = "key=" + logoutApiRequest.key + "&data=" + FGenericPlatformHttp::UrlEncode(logoutApiRequest.data) + "&signature=" + logoutApiRequest.signature + "&timeout=" + FString::FromInt(logoutApiRequest.timeout); diff --git a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3Auth.h b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3Auth.h index e89d0ca..100ffa8 100644 --- a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3Auth.h +++ b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3Auth.h @@ -11,6 +11,10 @@ #include "Web3AuthApi.h" #include "KeyStoreUtils.h" +#include "Containers/UnrealString.h" +#include "Serialization/JsonSerializer.h" +#include "Serialization/JsonReader.h" + #include "Runtime/Online/HTTPServer/Public/HttpPath.h" #include "Runtime/Online/HTTPServer/Public/IHttpRouter.h" #include "Runtime/Online/HTTPServer/Public/HttpServerHttpVersion.h" @@ -106,7 +110,7 @@ enum class FMFALevel : uint8 UENUM(BlueprintType) enum class FLanguage : uint8 { - en, de, ja, ko, zh, es, fr, pt, nl + en, de, ja, ko, zh, es, fr, pt, nl, tr }; UENUM(BlueprintType) @@ -376,6 +380,9 @@ struct FLoginParams UPROPERTY(EditAnywhere, BlueprintReadWrite) FCurve curve = FCurve::SECP256K1; + UPROPERTY(EditAnywhere, BlueprintReadWrite) + FString dappUrl; + FLoginParams() {}; FJsonObject getJsonObject() { @@ -396,6 +403,9 @@ struct FLoginParams if (extraLoginOptions.getJsonObject() != nullptr) output.SetObjectField("extraLoginOptions", extraLoginOptions.getJsonObject()); + if(!dappUrl.IsEmpty()) + output.SetStringField("dappUrl", dappUrl); + return output; } }; @@ -504,6 +514,53 @@ struct FWhiteLabelData }; +USTRUCT(BlueprintType) +struct FChainConfig +{ + GENERATED_BODY() + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + FChainNamespace chainNamespace = FChainNamespace::EIP155; + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + int32 decimals = 18; + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + FString blockExplorerUrl; + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + FString chainId; + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + FString displayName; + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + FString logo; + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + FString rpcTarget; + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + FString ticker; + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + FString tickerName; + + FChainConfig() {}; + + void operator= (const FChainConfig& other) { + chainNamespace = other.chainNamespace; + decimals = other.decimals; + blockExplorerUrl = other.blockExplorerUrl; + chainId = other.chainId; + displayName = other.displayName; + logo = other.logo; + rpcTarget = other.rpcTarget; + ticker = other.ticker; + tickerName = other.tickerName; + } +}; + USTRUCT(BlueprintType) struct FMfaSetting { @@ -555,6 +612,12 @@ struct FMfaSettings UPROPERTY(EditAnywhere, BlueprintReadWrite) FMfaSetting passwordFactor; + UPROPERTY(EditAnywhere, BlueprintReadWrite) + FMfaSetting passkeysFactor; + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + FMfaSetting authenticatorFactor; + FMfaSettings() {}; void operator= (const FMfaSettings& other) { @@ -562,6 +625,8 @@ struct FMfaSettings backUpShareFactor = other.backUpShareFactor; socialBackupFactor = other.socialBackupFactor; passwordFactor = other.passwordFactor; + passkeysFactor = other.passkeysFactor; + authenticatorFactor = other.authenticatorFactor; } bool operator==(const FMfaSettings& other) const @@ -569,7 +634,9 @@ struct FMfaSettings if (deviceShareFactor == other.deviceShareFactor && backUpShareFactor == other.backUpShareFactor && socialBackupFactor == other.socialBackupFactor && - passwordFactor == other.passwordFactor) + passwordFactor == other.passwordFactor && + passkeysFactor == other.passkeysFactor && + authenticatorFactor == other.authenticatorFactor) { return true; } @@ -590,7 +657,10 @@ struct FWeb3AuthOptions FString redirectUrl; UPROPERTY(EditAnywhere, BlueprintReadWrite) - FString sdkUrl = "https://sdk.openlogin.com"; + FString sdkUrl = "https://sdk.openlogin.com/v8"; + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + FString walletSdkUrl = "https://wallet.web3auth.io/v1"; UPROPERTY(EditAnywhere, BlueprintReadWrite) FNetwork network; @@ -616,12 +686,16 @@ struct FWeb3AuthOptions UPROPERTY(EditAnywhere, BlueprintReadWrite) int32 sessionTime = 86400; + UPROPERTY(EditAnywhere, BlueprintReadWrite) + FChainConfig chainConfig; + FWeb3AuthOptions() {}; void operator= (const FWeb3AuthOptions& other) { clientId = other.clientId; redirectUrl = other.redirectUrl; sdkUrl = other.sdkUrl; + redirectUrl = other.redirectUrl; network = other.network; buildEnv = other.buildEnv; whiteLabel = other.whiteLabel; @@ -630,6 +704,7 @@ struct FWeb3AuthOptions useCoreKitKey = other.useCoreKitKey; mfaSettings = other.mfaSettings; sessionTime = other.sessionTime; + chainConfig = other.chainConfig; } }; @@ -685,6 +760,7 @@ struct FShareMetaData DECLARE_DYNAMIC_DELEGATE_OneParam(FOnLogin, FWeb3AuthResponse, response); DECLARE_DYNAMIC_DELEGATE(FOnLogout); +DECLARE_DYNAMIC_DELEGATE_OneParam(FOnMfaSetup, bool, response); UCLASS() class WEB3AUTHSDK_API UWeb3Auth : public UGameInstanceSubsystem @@ -700,6 +776,7 @@ class WEB3AUTHSDK_API UWeb3Auth : public UGameInstanceSubsystem FWeb3AuthOptions web3AuthOptions; FOnLogin loginEvent; FOnLogout logoutEvent; + FOnMfaSetup mfaEvent; UKeyStoreUtils* keyStoreUtils; protected: @@ -721,6 +798,12 @@ class WEB3AUTHSDK_API UWeb3Auth : public UGameInstanceSubsystem UFUNCTION(BlueprintCallable) void processLogout(); + UFUNCTION(BlueprintCallable) + void enableMFA(FLoginParams loginParams); + + UFUNCTION(BlueprintCallable) + void launchWalletServices(FLoginParams loginParams, FChainConfig chainConfig); + UFUNCTION(BlueprintCallable) void setResultUrl(FString code); @@ -730,6 +813,9 @@ class WEB3AUTHSDK_API UWeb3Auth : public UGameInstanceSubsystem UFUNCTION(BlueprintCallable, Category = "Web3Auth") void setLogoutEvent(FOnLogout _event); + UFUNCTION(BlueprintCallable, Category = "Web3Auth") + void setMfaEvent(FOnMfaSetup _event); + UFUNCTION(BlueprintCallable) FString Web3AuthResponseToJsonString(FWeb3AuthResponse response) { FString output; @@ -767,6 +853,6 @@ class WEB3AUTHSDK_API UWeb3Auth : public UGameInstanceSubsystem void authorizeSession(); void sessionTimeout(); - void createSession(const FString& jsonData, int32 sessionTime); - void handleCreateSessionResponse(FString path, FString newSessionKey); + void createSession(const FString& jsonData, int32 sessionTime, bool isWalletService); + void handleCreateSessionResponse(FString path, FString newSessionKey, bool isWalletService); }; diff --git a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3AuthApi.h b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3AuthApi.h index 2e343a3..4075d87 100644 --- a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3AuthApi.h +++ b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3AuthApi.h @@ -36,6 +36,15 @@ struct FLogoutApiRequest int32 timeout; }; +USTRUCT() +struct FSessionResponse +{ + GENERATED_BODY() + + UPROPERTY() + FString sessionId; +}; + UCLASS() class WEB3AUTHSDK_API UWeb3AuthApi : public UObject {