Skip to content
Merged
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
4 changes: 0 additions & 4 deletions Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/ECCrypto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
#include <vector>
#include <iostream>

#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];
Expand Down
51 changes: 22 additions & 29 deletions Plugins/Web3AuthSDK/Source/Web3AuthSDK/Private/KeyStoreUtils.cpp
Original file line number Diff line number Diff line change
@@ -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<UWeb3StorageAdapter>(UGameplayStatics::LoadGameFromSlot(TEXT("Web3AuthDataSlot"), 0));
UWeb3StorageAdapter* UKeyStoreUtils::GetInstance() {
if(StorageInstance == nullptr) {
StorageInstance = Cast<UWeb3StorageAdapter>(UGameplayStatics::CreateSaveGameObject(UWeb3StorageAdapter::StaticClass()));
// Try load
// StorageInstance = Cast<UWeb3StorageAdapter>(UGameplayStatics::LoadGameFromSlot(SlotName, UserIndex);

// Instantiate new
if(StorageInstance == nullptr) {
StorageInstance = Cast<UWeb3StorageAdapter>(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);
}
12 changes: 6 additions & 6 deletions Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/ECCrypto.h
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -26,7 +27,6 @@ THIRD_PARTY_INCLUDES_END
#include "Misc/SecureHash.h"
#include <string>
#include "Keccak256.h"

#include "ECCrypto.generated.h"

UCLASS()
Expand Down
10 changes: 2 additions & 8 deletions Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Keccak256.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma once

/*
* Bitcoin cryptography library
* Copyright (c) Project Nayuki
Expand All @@ -6,12 +8,9 @@
* https://github.com/nayuki/Bitcoin-Cryptography-Library
*/

#pragma once

#include <cstddef>
#include <cstdint>


/*
* Computes the Keccak-256 hash of a sequence of bytes. The hash value is 32 bytes long.
* Provides just one static method.
Expand All @@ -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];

};
10 changes: 7 additions & 3 deletions Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/KeyStoreUtils.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
Expand All @@ -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();
};
12 changes: 0 additions & 12 deletions Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3Auth.h
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -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"
Expand All @@ -28,11 +24,9 @@
#endif

#include "Web3AuthError.h"

#include "Web3Auth.generated.h"



UENUM(BlueprintType)
enum class FDisplay : uint8
{
Expand Down Expand Up @@ -443,8 +437,6 @@ struct FUserInfo

};



USTRUCT(BlueprintType)
struct FWhiteLabelData
{
Expand Down Expand Up @@ -481,7 +473,6 @@ struct FWhiteLabelData

};


USTRUCT(BlueprintType)
struct FWeb3AuthOptions
{
Expand Down Expand Up @@ -526,7 +517,6 @@ struct FWeb3AuthOptions

};


USTRUCT(BlueprintType)
struct FWeb3AuthResponse
{
Expand Down Expand Up @@ -556,7 +546,6 @@ struct FWeb3AuthResponse
FWeb3AuthResponse() {};

};

USTRUCT(BlueprintType)
struct FShareMetaData
{
Expand All @@ -580,7 +569,6 @@ struct FShareMetaData
DECLARE_DYNAMIC_DELEGATE_OneParam(FOnLogin, FWeb3AuthResponse, response);
DECLARE_DYNAMIC_DELEGATE(FOnLogout);


UCLASS()
class WEB3AUTHSDK_API AWeb3Auth : public AActor
{
Expand Down
2 changes: 0 additions & 2 deletions Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3AuthApi.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
Expand Down
2 changes: 0 additions & 2 deletions Plugins/Web3AuthSDK/Source/Web3AuthSDK/Public/Web3AuthSDK.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// Copyright Epic Games, Inc. All Rights Reserved.

#pragma once

#include "CoreMinimal.h"
Expand Down