diff --git a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/ECCrypto.cpp b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/ECCrypto.cpp index 564e4a8..ad9e78e 100644 --- a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/ECCrypto.cpp +++ b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/ECCrypto.cpp @@ -3,10 +3,6 @@ #include #include -#pragma comment(lib, "crypt32.lib") -#pragma comment(lib, "WS2_32.lib") - - unsigned char* toByteArray(const std::string& s) { size_t len = s.length() / 2; unsigned char* data = new unsigned char[len]; diff --git a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/KeyStoreUtils.cpp b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/KeyStoreUtils.cpp index c448acf..bddc150 100644 --- a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/KeyStoreUtils.cpp +++ b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/KeyStoreUtils.cpp @@ -1,47 +1,40 @@ #include "KeyStoreUtils.h" -// Note: Slot name and user index (2nd and 3rd parameters) should be configurable, -// since a game could have multiple different profiles and users on the same machine. +UKeyStoreUtils::UKeyStoreUtils() {} -// Note: Class should have a lock on accessing the KeyValuePair collection. Probably is not thread-safe. +/* +UKeyStoreUtils::UKeyStoreUtils(FString filename, Int user) { + SlotName = filename; + UserIndex = user; +} +*/ -// Note: This class should also most likely be a singleton that persists for the lifetime of the application +UKeyStoreUtils::~UKeyStoreUtils() {} -UKeyStoreUtils::UKeyStoreUtils() { - StorageInstance = Cast(UGameplayStatics::LoadGameFromSlot(TEXT("Web3AuthDataSlot"), 0)); +UWeb3StorageAdapter* UKeyStoreUtils::GetInstance() { if(StorageInstance == nullptr) { - StorageInstance = Cast(UGameplayStatics::CreateSaveGameObject(UWeb3StorageAdapter::StaticClass())); + // Try load + // StorageInstance = Cast(UGameplayStatics::LoadGameFromSlot(SlotName, UserIndex); + + // Instantiate new + if(StorageInstance == nullptr) { + StorageInstance = Cast(UGameplayStatics::CreateSaveGameObject(UWeb3StorageAdapter::StaticClass())); + } } -} -UKeyStoreUtils::~UKeyStoreUtils() { + return StorageInstance; } void UKeyStoreUtils::Assign(FString value) { - if (StorageInstance == nullptr) - { - // log error here - return; - } - StorageInstance->sessionId = value; - //UGameplayStatics::SaveGameToSlot(StorageInstance, TEXT("Web3AuthDataSlot"), 0); + GetInstance()->sessionId = value; + //UGameplayStatics::SaveGameToSlot(GetInstance(), SlotName, UserIndex); } FString UKeyStoreUtils::Get() { - if (StorageInstance == nullptr) - { - // log error here - return FString(); - } - return StorageInstance->sessionId; + return GetInstance()->sessionId; } void UKeyStoreUtils::Clear() { - if (StorageInstance == nullptr) - { - // log error here - return; - } - StorageInstance->sessionId = FString(); - //UGameplayStatics::SaveGameToSlot(StorageInstance, TEXT("Web3AuthDataSlot"), 0); + GetInstance()->sessionId = FString(); + //UGameplayStatics::SaveGameToSlot(GetInstance(), SlotName, UserIndex); } diff --git a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/ECCrypto.h b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/ECCrypto.h index f6650f9..f82679d 100644 --- a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/ECCrypto.h +++ b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/ECCrypto.h @@ -1,11 +1,12 @@ -// Fill out your copyright notice in the Description page of Project Settings. - #pragma once -#include "CoreMinimal.h" +#if PLATFORM_WINDOWS + #pragma warning(disable:4996) + #pragma comment(lib, "crypt32.lib") + #pragma comment(lib, "WS2_32.lib") +#endif -#pragma warning(disable:4996) -#pragma comment(lib,"WS2_32.Lib") //Winsock Library +#include "CoreMinimal.h" #define UI UI_ST THIRD_PARTY_INCLUDES_START @@ -26,7 +27,6 @@ THIRD_PARTY_INCLUDES_END #include "Misc/SecureHash.h" #include #include "Keccak256.h" - #include "ECCrypto.generated.h" UCLASS() diff --git a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Keccak256.h b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Keccak256.h index ccbb170..e8debb3 100644 --- a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Keccak256.h +++ b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Keccak256.h @@ -1,3 +1,5 @@ +#pragma once + /* * Bitcoin cryptography library * Copyright (c) Project Nayuki @@ -6,12 +8,9 @@ * https://github.com/nayuki/Bitcoin-Cryptography-Library */ -#pragma once - #include #include - /* * Computes the Keccak-256 hash of a sequence of bytes. The hash value is 32 bytes long. * Provides just one static method. @@ -22,20 +21,15 @@ public: static constexpr int HASH_LEN = 32; private: static constexpr int BLOCK_SIZE = 200 - HASH_LEN * 2; private: static constexpr int NUM_ROUNDS = 24; - public: static void getHash(const std::uint8_t msg[], std::size_t len, std::uint8_t hashResult[HASH_LEN]); - private: static void absorb(std::uint64_t state[5][5]); - // Requires 0 <= i <= 63 private: static std::uint64_t rotl64(std::uint64_t x, int i); - Keccak256() = delete; // Not instantiable - private: static const unsigned char ROTATION[5][5]; }; \ No newline at end of file diff --git a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/KeyStoreUtils.h b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/KeyStoreUtils.h index 0c9c8da..f18bec3 100644 --- a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/KeyStoreUtils.h +++ b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/KeyStoreUtils.h @@ -1,5 +1,3 @@ -// Fill out your copyright notice in the Description page of Project Settings. - #pragma once #include "CoreMinimal.h" @@ -22,12 +20,18 @@ class WEB3AUTHSDK_API UKeyStoreUtils : public UObject { GENERATED_BODY() private: - UWeb3StorageAdapter* StorageInstance; + UPROPERTY() + UWeb3StorageAdapter* StorageInstance; + // Int UserIndex + // FString SlotName + + UWeb3StorageAdapter* GetInstance(); public: void Assign(FString value); FString Get(); void Clear(); public: + // UKeyStoreUtils(FString filename, Int user); UKeyStoreUtils(); ~UKeyStoreUtils(); }; diff --git a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3Auth.h b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3Auth.h index bb9c8c2..246a57e 100644 --- a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3Auth.h +++ b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3Auth.h @@ -1,11 +1,8 @@ -// Fill out your copyright notice in the Description page of Project Settings. - #pragma once #include "CoreMinimal.h" #include "GameFramework/Actor.h" - #include "Json.h" #include "JsonUtilities.h" @@ -14,7 +11,6 @@ #include "ECCrypto.h" #include "Web3AuthApi.h" - #include "Runtime/Online/HTTPServer/Public/HttpPath.h" #include "Runtime/Online/HTTPServer/Public/IHttpRouter.h" #include "Runtime/Online/HTTPServer/Public/HttpServerHttpVersion.h" @@ -28,11 +24,9 @@ #endif #include "Web3AuthError.h" - #include "Web3Auth.generated.h" - UENUM(BlueprintType) enum class FDisplay : uint8 { @@ -443,8 +437,6 @@ struct FUserInfo }; - - USTRUCT(BlueprintType) struct FWhiteLabelData { @@ -481,7 +473,6 @@ struct FWhiteLabelData }; - USTRUCT(BlueprintType) struct FWeb3AuthOptions { @@ -526,7 +517,6 @@ struct FWeb3AuthOptions }; - USTRUCT(BlueprintType) struct FWeb3AuthResponse { @@ -556,7 +546,6 @@ struct FWeb3AuthResponse FWeb3AuthResponse() {}; }; - USTRUCT(BlueprintType) struct FShareMetaData { @@ -580,7 +569,6 @@ struct FShareMetaData DECLARE_DYNAMIC_DELEGATE_OneParam(FOnLogin, FWeb3AuthResponse, response); DECLARE_DYNAMIC_DELEGATE(FOnLogout); - UCLASS() class WEB3AUTHSDK_API AWeb3Auth : public AActor { diff --git a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3AuthApi.h b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3AuthApi.h index 5198b91..8d04656 100644 --- a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3AuthApi.h +++ b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3AuthApi.h @@ -1,5 +1,3 @@ -// Fill out your copyright notice in the Description page of Project Settings. - #pragma once #include "CoreMinimal.h" diff --git a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3AuthSDK.h b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3AuthSDK.h index a5e3b54..4d98f3a 100644 --- a/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3AuthSDK.h +++ b/Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3AuthSDK.h @@ -1,5 +1,3 @@ -// Copyright Epic Games, Inc. All Rights Reserved. - #pragma once #include "CoreMinimal.h"