From 03bc0dd083279a2c9e6db464197db959ce1d8f53 Mon Sep 17 00:00:00 2001 From: 0xFirekeeper <0xFirekeeper@gmail.com> Date: Mon, 13 Jan 2025 18:52:33 +0700 Subject: [PATCH 1/2] Rust Sharded -> Enclave Auto Migration Libs updated, In-App Wallet is now an Ecosystem Wallet with no Ecosystem ID and Partner ID --- Source/ThirdParty/Android/libthirdweb.a | 4 +- Source/ThirdParty/IOS/libthirdweb.a | 4 +- Source/ThirdParty/IOS/libthirdweb.sim.a | 4 +- Source/ThirdParty/Linux/libthirdweb.a | 4 +- Source/ThirdParty/LinuxArm64/libthirdweb.a | 4 +- Source/ThirdParty/Mac/libthirdweb.a | 4 +- Source/ThirdParty/Win64/libthirdweb.lib | 4 +- .../Wallets/ThirdwebInAppWalletHandle.cpp | 944 ++++++++---------- Source/Thirdweb/Public/Thirdweb.h | 130 +-- 9 files changed, 492 insertions(+), 610 deletions(-) diff --git a/Source/ThirdParty/Android/libthirdweb.a b/Source/ThirdParty/Android/libthirdweb.a index a1cf3b2..fa12eda 100644 --- a/Source/ThirdParty/Android/libthirdweb.a +++ b/Source/ThirdParty/Android/libthirdweb.a @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:94a0fdc0cc6b30ea32c43b92f09f90ec35a37d2a06c47d47408779af8815adaa -size 91787038 +oid sha256:617c78289975d7edde4fa2ea065a3b00ab1f2587cce252d402ffd53075a331ba +size 93470514 diff --git a/Source/ThirdParty/IOS/libthirdweb.a b/Source/ThirdParty/IOS/libthirdweb.a index 5737417..bb177ed 100644 --- a/Source/ThirdParty/IOS/libthirdweb.a +++ b/Source/ThirdParty/IOS/libthirdweb.a @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c522cd478144b864a56b8b6104ebd00b1a513a7e0a7318eb4f0f5b7ef7104042 -size 61882640 +oid sha256:52c14601df591368073a5a6114a52ab41e9620e2b8e86afe7962bb0e37df40d0 +size 62611232 diff --git a/Source/ThirdParty/IOS/libthirdweb.sim.a b/Source/ThirdParty/IOS/libthirdweb.sim.a index 242c976..bb177ed 100644 --- a/Source/ThirdParty/IOS/libthirdweb.sim.a +++ b/Source/ThirdParty/IOS/libthirdweb.sim.a @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9b732291859c3fe4881cafdbfec2f66f776cc837e5333a5ceb78cda3e3786458 -size 61751072 +oid sha256:52c14601df591368073a5a6114a52ab41e9620e2b8e86afe7962bb0e37df40d0 +size 62611232 diff --git a/Source/ThirdParty/Linux/libthirdweb.a b/Source/ThirdParty/Linux/libthirdweb.a index 75915cf..6af1054 100644 --- a/Source/ThirdParty/Linux/libthirdweb.a +++ b/Source/ThirdParty/Linux/libthirdweb.a @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:8a5457f4b833a1455b61b399194ee46ba97139b1940c9e9f75fc73afd935bb60 -size 94684478 +oid sha256:54c73e17d6d459f48fb2b4f1fcec0d778cc1c6e9ba258f409abd6eeac0f2d020 +size 95652038 diff --git a/Source/ThirdParty/LinuxArm64/libthirdweb.a b/Source/ThirdParty/LinuxArm64/libthirdweb.a index ffe366b..a862c0f 100644 --- a/Source/ThirdParty/LinuxArm64/libthirdweb.a +++ b/Source/ThirdParty/LinuxArm64/libthirdweb.a @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:db2818e3466200d1c5f0932c603e4b6387b527fccbbb6a7606b7fdc58f5fa3ed -size 94829242 +oid sha256:437857dc8838522e7dd8983fd2bd1bf5c21d14baf8a677b8cf5704e16cd5054a +size 96084128 diff --git a/Source/ThirdParty/Mac/libthirdweb.a b/Source/ThirdParty/Mac/libthirdweb.a index 95b4a61..4dfefed 100644 --- a/Source/ThirdParty/Mac/libthirdweb.a +++ b/Source/ThirdParty/Mac/libthirdweb.a @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:bbb4e43a6b8e46c29798ac0a59de4271202275053e1a1a09e3a8036bf22abcbb -size 124142080 +oid sha256:85ea6b3ea8022d0eeeda3ba838071fb9848e68ef8327f4359c35d82e5e7c83da +size 125389472 diff --git a/Source/ThirdParty/Win64/libthirdweb.lib b/Source/ThirdParty/Win64/libthirdweb.lib index 824b36c..5228ee0 100644 --- a/Source/ThirdParty/Win64/libthirdweb.lib +++ b/Source/ThirdParty/Win64/libthirdweb.lib @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:edc8ca7017f5fa09dd015e54e64d7d6f8c4953ac0d80ef35ed04e173236fd511 -size 95627746 +oid sha256:0b920c2fc4e0ae9310c088bf883240da6a489c5c9f197cc5c5b9919e71acbe1a +size 96788268 diff --git a/Source/Thirdweb/Private/Wallets/ThirdwebInAppWalletHandle.cpp b/Source/Thirdweb/Private/Wallets/ThirdwebInAppWalletHandle.cpp index 0c41270..882d0cc 100644 --- a/Source/Thirdweb/Private/Wallets/ThirdwebInAppWalletHandle.cpp +++ b/Source/Thirdweb/Private/Wallets/ThirdwebInAppWalletHandle.cpp @@ -4,39 +4,39 @@ #include "Wallets/ThirdwebInAppWalletHandle.h" +#include "Containers/ThirdwebLinkedAccount.h" +#include "Misc/DefaultValueHelper.h" +#include "Tasks/Task.h" #include "Thirdweb.h" #include "ThirdwebCommon.h" #include "ThirdwebLog.h" #include "ThirdwebMacros.h" #include "ThirdwebRuntimeSettings.h" #include "ThirdwebUtils.h" -#include "Containers/ThirdwebLinkedAccount.h" -#include "Misc/DefaultValueHelper.h" -#include "Tasks/Task.h" -#define CHECK_ECOSYSTEM(ErrorDelegate) \ - if (UThirdwebRuntimeSettings::GetEcosystemId().IsEmpty()) \ - { \ - TW_LOG(Error, TEXT("Ecosystem ID not set in settings")) \ - if (ErrorDelegate.IsBound()) \ - { \ +#define CHECK_ECOSYSTEM(ErrorDelegate) \ + if (UThirdwebRuntimeSettings::GetEcosystemId().IsEmpty()) \ + { \ + TW_LOG(Error, TEXT("Ecosystem ID not set in settings")) \ + if (ErrorDelegate.IsBound()) \ + { \ ErrorDelegate.Execute(TEXT("Ecosystem ID not set in settings")); \ - } \ - return; \ + } \ + return; \ } -#define CHECK_SOURCE(InSource, ErrorDelegate) \ - if (Source != InSource) \ - { \ +#define CHECK_SOURCE(InSource, ErrorDelegate) \ + if (Source != InSource) \ + { \ ErrorDelegate.Execute(FString::Printf(TEXT("Wallet handle is not %s source"), GetSourceString(InSource))); \ - return; \ + return; \ } -#define CHECK_WALLET_SOURCE(InWallet, InSource, ErrorDelegate) \ - if (InWallet.GetSource() != InSource) \ - { \ +#define CHECK_WALLET_SOURCE(InWallet, InSource, ErrorDelegate) \ + if (InWallet.GetSource() != InSource) \ + { \ ErrorDelegate.Execute(FString::Printf(TEXT("Wallet handle is not %s source"), GetSourceString(InSource))); \ - return; \ + return; \ } FInAppWalletHandle::FInAppWalletHandle() @@ -84,185 +84,98 @@ bool FInAppWalletHandle::IsValid() const return Super::IsValid() && Source != InvalidSource; } -void FInAppWalletHandle::CreateEmailWallet(const FString& Email, const FCreateInAppWalletDelegate& SuccessDelegate, const FStringDelegate& ErrorDelegate) +void FInAppWalletHandle::CreateEmailWallet( + const FString& Email, const FCreateInAppWalletDelegate& SuccessDelegate, const FStringDelegate& ErrorDelegate) { CHECK_DELEGATES(SuccessDelegate, ErrorDelegate) - UE::Tasks::Launch(UE_SOURCE_LOCATION, [Email, SuccessDelegate, ErrorDelegate] - { - FString Error; - if (UThirdwebRuntimeSettings::IsEcosystem()) - { - if (Thirdweb::create_ecosystem_wallet( - TO_RUST_STRING(UThirdwebRuntimeSettings::GetEcosystemId()), - TO_RUST_STRING(UThirdwebRuntimeSettings::GetPartnerId()), - TO_RUST_STRING(UThirdwebRuntimeSettings::GetClientId()), - TO_RUST_STRING(UThirdwebRuntimeSettings::GetBundleId()), - nullptr, - TO_RUST_STRING(Email), - nullptr, - TO_RUST_STRING(UThirdwebRuntimeSettings::GetStorageDirectory()), - nullptr - ).AssignResult(Error)) + UE::Tasks::Launch(UE_SOURCE_LOCATION, + [Email, SuccessDelegate, ErrorDelegate] { + FString Error; + if (Thirdweb::create_ecosystem_wallet(TO_RUST_STRING(UThirdwebRuntimeSettings::GetEcosystemId()), + TO_RUST_STRING(UThirdwebRuntimeSettings::GetPartnerId()), + TO_RUST_STRING(UThirdwebRuntimeSettings::GetClientId()), + TO_RUST_STRING(UThirdwebRuntimeSettings::GetBundleId()), nullptr, TO_RUST_STRING(Email), nullptr, + TO_RUST_STRING(UThirdwebRuntimeSettings::GetStorageDirectory()), nullptr, nullptr) + .AssignResult(Error)) { SuccessDelegate.Execute(FInAppWalletHandle(EInAppSource::Email, Error)); return; } - } - else - { - if (Thirdweb::create_in_app_wallet( - TO_RUST_STRING(UThirdwebRuntimeSettings::GetClientId()), - TO_RUST_STRING(UThirdwebRuntimeSettings::GetBundleId()), - nullptr, - TO_RUST_STRING(Email), - nullptr, - TO_RUST_STRING(UThirdwebRuntimeSettings::GetStorageDirectory()), - nullptr - ).AssignResult(Error)) - { - SuccessDelegate.Execute(FInAppWalletHandle(EInAppSource::Email, Error)); - return; - } - } - ErrorDelegate.Execute(Error); - }); + ErrorDelegate.Execute(Error); + }); } -void FInAppWalletHandle::CreateOAuthWallet(const EThirdwebOAuthProvider Provider, const FCreateInAppWalletDelegate& SuccessDelegate, const FStringDelegate& ErrorDelegate) +void FInAppWalletHandle::CreateOAuthWallet( + const EThirdwebOAuthProvider Provider, const FCreateInAppWalletDelegate& SuccessDelegate, const FStringDelegate& ErrorDelegate) { CHECK_DELEGATES(SuccessDelegate, ErrorDelegate) - UE::Tasks::Launch(UE_SOURCE_LOCATION, [Provider, SuccessDelegate, ErrorDelegate] - { - FString Error; - if (UThirdwebRuntimeSettings::IsEcosystem()) - { - if (Thirdweb::create_ecosystem_wallet( - TO_RUST_STRING(UThirdwebRuntimeSettings::GetEcosystemId()), - TO_RUST_STRING(UThirdwebRuntimeSettings::GetPartnerId()), - TO_RUST_STRING(UThirdwebRuntimeSettings::GetClientId()), - TO_RUST_STRING(UThirdwebRuntimeSettings::GetBundleId()), - nullptr, - nullptr, - nullptr, - TO_RUST_STRING(UThirdwebRuntimeSettings::GetStorageDirectory()), - TO_RUST_STRING(ThirdwebUtils::ToString(Provider)) - ).AssignResult(Error)) - { - SuccessDelegate.Execute(FInAppWalletHandle(Provider, Error)); - return; - } - } - else - { - if (Thirdweb::create_in_app_wallet( - TO_RUST_STRING(UThirdwebRuntimeSettings::GetClientId()), - TO_RUST_STRING(UThirdwebRuntimeSettings::GetBundleId()), - nullptr, - nullptr, - nullptr, - TO_RUST_STRING(UThirdwebRuntimeSettings::GetStorageDirectory()), - TO_RUST_STRING(ThirdwebUtils::ToString(Provider)) - ).AssignResult(Error)) - { - SuccessDelegate.Execute(FInAppWalletHandle(Provider, Error)); - return; - } - } - ErrorDelegate.Execute(Error); - }); + UE::Tasks::Launch(UE_SOURCE_LOCATION, + [Provider, SuccessDelegate, ErrorDelegate] { + FString Error; + if (UThirdwebRuntimeSettings::IsEcosystem()) + if (Thirdweb::create_ecosystem_wallet(TO_RUST_STRING(UThirdwebRuntimeSettings::GetEcosystemId()), + TO_RUST_STRING(UThirdwebRuntimeSettings::GetPartnerId()), + TO_RUST_STRING(UThirdwebRuntimeSettings::GetClientId()), + TO_RUST_STRING(UThirdwebRuntimeSettings::GetBundleId()), nullptr, nullptr, nullptr, + TO_RUST_STRING(UThirdwebRuntimeSettings::GetStorageDirectory()), + TO_RUST_STRING(ThirdwebUtils::ToString(Provider)), nullptr) + .AssignResult(Error)) + { + SuccessDelegate.Execute(FInAppWalletHandle(Provider, Error)); + return; + } + ErrorDelegate.Execute(Error); + }); } -void FInAppWalletHandle::CreatePhoneWallet(const FString& Phone, const FCreateInAppWalletDelegate& SuccessDelegate, const FStringDelegate& ErrorDelegate) +void FInAppWalletHandle::CreatePhoneWallet( + const FString& Phone, const FCreateInAppWalletDelegate& SuccessDelegate, const FStringDelegate& ErrorDelegate) { CHECK_DELEGATES(SuccessDelegate, ErrorDelegate) - UE::Tasks::Launch(UE_SOURCE_LOCATION, [Phone, SuccessDelegate, ErrorDelegate] - { - FString Error; - if (UThirdwebRuntimeSettings::IsEcosystem()) - { - if (Thirdweb::create_ecosystem_wallet( - TO_RUST_STRING(UThirdwebRuntimeSettings::GetEcosystemId()), - TO_RUST_STRING(UThirdwebRuntimeSettings::GetPartnerId()), - TO_RUST_STRING(UThirdwebRuntimeSettings::GetClientId()), - TO_RUST_STRING(UThirdwebRuntimeSettings::GetBundleId()), - nullptr, - nullptr, - TO_RUST_STRING(Phone), - TO_RUST_STRING(UThirdwebRuntimeSettings::GetStorageDirectory()), - nullptr - ).AssignResult(Error)) - { - SuccessDelegate.Execute(FInAppWalletHandle(EInAppSource::Phone, Error)); - return; - } - } - else - { - if (Thirdweb::create_in_app_wallet( - TO_RUST_STRING(UThirdwebRuntimeSettings::GetClientId()), - TO_RUST_STRING(UThirdwebRuntimeSettings::GetBundleId()), - nullptr, - nullptr, - TO_RUST_STRING(Phone), - TO_RUST_STRING(UThirdwebRuntimeSettings::GetStorageDirectory()), - nullptr - ).AssignResult(Error)) + UE::Tasks::Launch(UE_SOURCE_LOCATION, + [Phone, SuccessDelegate, ErrorDelegate] { + FString Error; + + if (Thirdweb::create_ecosystem_wallet(TO_RUST_STRING(UThirdwebRuntimeSettings::GetEcosystemId()), + TO_RUST_STRING(UThirdwebRuntimeSettings::GetPartnerId()), + TO_RUST_STRING(UThirdwebRuntimeSettings::GetClientId()), + TO_RUST_STRING(UThirdwebRuntimeSettings::GetBundleId()), nullptr, nullptr, TO_RUST_STRING(Phone), + TO_RUST_STRING(UThirdwebRuntimeSettings::GetStorageDirectory()), nullptr, nullptr) + .AssignResult(Error)) { SuccessDelegate.Execute(FInAppWalletHandle(EInAppSource::Phone, Error)); return; } - } - ErrorDelegate.Execute(Error); - }); + + ErrorDelegate.Execute(Error); + }); } void FInAppWalletHandle::CreateSiweWallet(const FCreateInAppWalletDelegate& SuccessDelegate, const FStringDelegate& ErrorDelegate) { CHECK_DELEGATES(SuccessDelegate, ErrorDelegate) - UE::Tasks::Launch(UE_SOURCE_LOCATION, [SuccessDelegate, ErrorDelegate] - { - static FString Provider = TEXT("SIWE"); - FString Error; - if (UThirdwebRuntimeSettings::IsEcosystem()) - { - if (Thirdweb::create_ecosystem_wallet( - TO_RUST_STRING(UThirdwebRuntimeSettings::GetEcosystemId()), - TO_RUST_STRING(UThirdwebRuntimeSettings::GetPartnerId()), - TO_RUST_STRING(UThirdwebRuntimeSettings::GetClientId()), - TO_RUST_STRING(UThirdwebRuntimeSettings::GetBundleId()), - nullptr, - nullptr, - nullptr, - TO_RUST_STRING(UThirdwebRuntimeSettings::GetStorageDirectory()), - TO_RUST_STRING(Provider) - ).AssignResult(Error)) + UE::Tasks::Launch(UE_SOURCE_LOCATION, + [SuccessDelegate, ErrorDelegate] { + static FString Provider = TEXT("SIWE"); + FString Error; + + if (Thirdweb::create_ecosystem_wallet(TO_RUST_STRING(UThirdwebRuntimeSettings::GetEcosystemId()), + TO_RUST_STRING(UThirdwebRuntimeSettings::GetPartnerId()), + TO_RUST_STRING(UThirdwebRuntimeSettings::GetClientId()), + TO_RUST_STRING(UThirdwebRuntimeSettings::GetBundleId()), nullptr, nullptr, nullptr, + TO_RUST_STRING(UThirdwebRuntimeSettings::GetStorageDirectory()), TO_RUST_STRING(Provider), nullptr) + .AssignResult(Error)) { SuccessDelegate.Execute(FInAppWalletHandle(Siwe, Error)); return; } - } - else - { - if (Thirdweb::create_in_app_wallet( - TO_RUST_STRING(UThirdwebRuntimeSettings::GetClientId()), - TO_RUST_STRING(UThirdwebRuntimeSettings::GetBundleId()), - nullptr, - nullptr, - nullptr, - TO_RUST_STRING(UThirdwebRuntimeSettings::GetStorageDirectory()), - TO_RUST_STRING(Provider) - ).AssignResult(Error)) - { - SuccessDelegate.Execute(FInAppWalletHandle(Siwe, Error)); - return; - } - } - ErrorDelegate.Execute(Error); - }); + ErrorDelegate.Execute(Error); + }); } -void FInAppWalletHandle::CreateCustomAuthWallet(const EInAppSource Source, const FCreateInAppWalletDelegate& SuccessDelegate, const FStringDelegate& ErrorDelegate) +void FInAppWalletHandle::CreateCustomAuthWallet( + const EInAppSource Source, const FCreateInAppWalletDelegate& SuccessDelegate, const FStringDelegate& ErrorDelegate) { CHECK_DELEGATES(SuccessDelegate, ErrorDelegate) if (Source != Jwt && Source != AuthEndpoint && Source != Guest) @@ -273,45 +186,24 @@ void FInAppWalletHandle::CreateCustomAuthWallet(const EInAppSource Source, const } return; } - UE::Tasks::Launch(UE_SOURCE_LOCATION, [Source, SuccessDelegate, ErrorDelegate] - { - FString Error; - if (UThirdwebRuntimeSettings::IsEcosystem()) - { - if (Thirdweb::create_ecosystem_wallet( - TO_RUST_STRING(UThirdwebRuntimeSettings::GetEcosystemId()), - TO_RUST_STRING(UThirdwebRuntimeSettings::GetPartnerId()), - TO_RUST_STRING(UThirdwebRuntimeSettings::GetClientId()), - TO_RUST_STRING(UThirdwebRuntimeSettings::GetBundleId()), - nullptr, - nullptr, - nullptr, - TO_RUST_STRING(UThirdwebRuntimeSettings::GetStorageDirectory()), - TO_RUST_STRING(FString(GetSourceString(Source))) - ).AssignResult(Error)) - { - SuccessDelegate.Execute(FInAppWalletHandle(Source, Error)); - return; - } - } - else - { - if (Thirdweb::create_in_app_wallet( - TO_RUST_STRING(UThirdwebRuntimeSettings::GetClientId()), - TO_RUST_STRING(UThirdwebRuntimeSettings::GetBundleId()), - nullptr, - nullptr, - nullptr, - TO_RUST_STRING(UThirdwebRuntimeSettings::GetStorageDirectory()), - TO_RUST_STRING(FString(GetSourceString(Source))) - ).AssignResult(Error)) + UE::Tasks::Launch(UE_SOURCE_LOCATION, + [Source, SuccessDelegate, ErrorDelegate] { + FString Error; + if (Thirdweb::create_ecosystem_wallet(TO_RUST_STRING(UThirdwebRuntimeSettings::GetEcosystemId()), + TO_RUST_STRING(UThirdwebRuntimeSettings::GetPartnerId()), + TO_RUST_STRING(UThirdwebRuntimeSettings::GetClientId()), + TO_RUST_STRING(UThirdwebRuntimeSettings::GetBundleId()), nullptr, nullptr, nullptr, + TO_RUST_STRING(UThirdwebRuntimeSettings::GetStorageDirectory()), + TO_RUST_STRING(FString(GetSourceString(Source))), + TO_RUST_STRING(UThirdwebRuntimeSettings::GetEncryptionKey()) // legacy, will be used if migrating only + ) + .AssignResult(Error)) { SuccessDelegate.Execute(FInAppWalletHandle(Source, Error)); return; } - } - ErrorDelegate.Execute(Error); - }); + ErrorDelegate.Execute(Error); + }); } bool FInAppWalletHandle::IsConnected() const @@ -329,72 +221,73 @@ void FInAppWalletHandle::SendOTP(const FStreamableDelegate& SuccessDelegate, con CHECK_DELEGATES(SuccessDelegate, ErrorDelegate) CHECK_VALIDITY(ErrorDelegate) FInAppWalletHandle ThisCopy = *this; - UE::Tasks::Launch(UE_SOURCE_LOCATION, [ThisCopy, SuccessDelegate, ErrorDelegate] - { - FString Error; - if (UThirdwebRuntimeSettings::IsEcosystem()) - { - switch (ThisCopy.GetSource()) + UE::Tasks::Launch(UE_SOURCE_LOCATION, + [ThisCopy, SuccessDelegate, ErrorDelegate] { + FString Error; + if (UThirdwebRuntimeSettings::IsEcosystem()) { - case Phone: + switch (ThisCopy.GetSource()) { - if (Thirdweb::ecosystem_wallet_send_otp_phone(ThisCopy.GetID()).AssignResult(Error, true)) + case Phone: { - SuccessDelegate.Execute(); - return; + if (Thirdweb::ecosystem_wallet_send_otp_phone(ThisCopy.GetID()).AssignResult(Error, true)) + { + SuccessDelegate.Execute(); + return; + } + break; } - break; - } - case Email: - { - if (Thirdweb::ecosystem_wallet_send_otp_email(ThisCopy.GetID()).AssignResult(Error, true)) + case Email: { - SuccessDelegate.Execute(); + if (Thirdweb::ecosystem_wallet_send_otp_email(ThisCopy.GetID()).AssignResult(Error, true)) + { + SuccessDelegate.Execute(); + return; + } + break; + } + default: + { + ErrorDelegate.Execute(TEXT("Wallet handle is not email/phone source")); return; } - break; - } - default: - { - ErrorDelegate.Execute(TEXT("Wallet handle is not email/phone source")); - return; } } - } - else - { - switch (ThisCopy.GetSource()) + else { - case Phone: + switch (ThisCopy.GetSource()) { - if (Thirdweb::in_app_wallet_send_otp_phone(ThisCopy.GetID()).AssignResult(Error, true)) + case Phone: { - SuccessDelegate.Execute(); - return; + if (Thirdweb::ecosystem_wallet_send_otp_phone(ThisCopy.GetID()).AssignResult(Error, true)) + { + SuccessDelegate.Execute(); + return; + } + break; } - break; - } - case Email: - { - if (Thirdweb::in_app_wallet_send_otp_email(ThisCopy.GetID()).AssignResult(Error, true)) + case Email: { - SuccessDelegate.Execute(); + if (Thirdweb::ecosystem_wallet_send_otp_email(ThisCopy.GetID()).AssignResult(Error, true)) + { + SuccessDelegate.Execute(); + return; + } + break; + } + default: + { + ErrorDelegate.Execute(TEXT("Wallet handle is not email/phone source")); return; } - break; - } - default: - { - ErrorDelegate.Execute(TEXT("Wallet handle is not email/phone source")); - return; } } - } - ErrorDelegate.Execute(Error); - }); + ErrorDelegate.Execute(Error); + }); } -void FInAppWalletHandle::SignInWithOTP(const FString& OTP, const FStreamableDelegate& SuccessDelegate, const FStringDelegate& ErrorDelegate) +void FInAppWalletHandle::SignInWithOTP( + const FString& OTP, const FStreamableDelegate& SuccessDelegate, const FStringDelegate& ErrorDelegate) { CHECK_DELEGATES(SuccessDelegate, ErrorDelegate) CHECK_VALIDITY(ErrorDelegate) @@ -404,66 +297,73 @@ void FInAppWalletHandle::SignInWithOTP(const FString& OTP, const FStreamableDele return; } FInAppWalletHandle ThisCopy = *this; - UE::Tasks::Launch(UE_SOURCE_LOCATION, [ThisCopy, OTP, SuccessDelegate, ErrorDelegate] - { - FString Error; - if (UThirdwebRuntimeSettings::IsEcosystem()) - { - switch (ThisCopy.GetSource()) + UE::Tasks::Launch(UE_SOURCE_LOCATION, + [ThisCopy, OTP, SuccessDelegate, ErrorDelegate] { + FString Error; + if (UThirdwebRuntimeSettings::IsEcosystem()) { - case Phone: + switch (ThisCopy.GetSource()) { - if (Thirdweb::ecosystem_wallet_sign_in_with_otp_phone(ThisCopy.GetID(), TO_RUST_STRING(OTP)).AssignResult(Error, true)) + case Phone: { - ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); - SuccessDelegate.Execute(); - return; + if (Thirdweb::ecosystem_wallet_sign_in_with_otp_phone(ThisCopy.GetID(), TO_RUST_STRING(OTP)) + .AssignResult(Error, true)) + { + ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); + SuccessDelegate.Execute(); + return; + } + break; } - break; - } - case Email: - { - if (Thirdweb::ecosystem_wallet_sign_in_with_otp_email(ThisCopy.GetID(), TO_RUST_STRING(OTP)).AssignResult(Error, true)) + case Email: { - ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); - SuccessDelegate.Execute(); - return; + if (Thirdweb::ecosystem_wallet_sign_in_with_otp_email(ThisCopy.GetID(), TO_RUST_STRING(OTP)) + .AssignResult(Error, true)) + { + ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); + SuccessDelegate.Execute(); + return; + } + break; } - break; + default: + return; } - default: return; } - } - else - { - switch (ThisCopy.GetSource()) + else { - case Phone: + switch (ThisCopy.GetSource()) { - if (Thirdweb::in_app_wallet_sign_in_with_otp_phone(ThisCopy.GetID(), TO_RUST_STRING(OTP)).AssignResult(Error, true)) + case Phone: { - ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); - SuccessDelegate.Execute(); - return; + if (Thirdweb::ecosystem_wallet_sign_in_with_otp_phone(ThisCopy.GetID(), TO_RUST_STRING(OTP)) + .AssignResult(Error, true)) + { + ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); + SuccessDelegate.Execute(); + return; + } } - } - case Email: - { - if (Thirdweb::in_app_wallet_sign_in_with_otp_email(ThisCopy.GetID(), TO_RUST_STRING(OTP)).AssignResult(Error, true)) + case Email: { - ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); - SuccessDelegate.Execute(); - return; + if (Thirdweb::ecosystem_wallet_sign_in_with_otp_email(ThisCopy.GetID(), TO_RUST_STRING(OTP)) + .AssignResult(Error, true)) + { + ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); + SuccessDelegate.Execute(); + return; + } } + default: + return; } - default: return; } - } - ErrorDelegate.Execute(Error); - }); + ErrorDelegate.Execute(Error); + }); } -void FInAppWalletHandle::LinkOTP(const FInAppWalletHandle& Wallet, const FString& OTP, const FStreamableDelegate& SuccessDelegate, const FStringDelegate& ErrorDelegate) +void FInAppWalletHandle::LinkOTP(const FInAppWalletHandle& Wallet, const FString& OTP, const FStreamableDelegate& SuccessDelegate, + const FStringDelegate& ErrorDelegate) { CHECK_DELEGATES(SuccessDelegate, ErrorDelegate) CHECK_VALIDITY(ErrorDelegate) @@ -474,33 +374,37 @@ void FInAppWalletHandle::LinkOTP(const FInAppWalletHandle& Wallet, const FString return; } FInAppWalletHandle ThisCopy = *this; - UE::Tasks::Launch(UE_SOURCE_LOCATION, [ThisCopy, Wallet, OTP, SuccessDelegate, ErrorDelegate] - { - FString Error; - switch (ThisCopy.GetSource()) - { - case Phone: + UE::Tasks::Launch(UE_SOURCE_LOCATION, + [ThisCopy, Wallet, OTP, SuccessDelegate, ErrorDelegate] { + FString Error; + switch (ThisCopy.GetSource()) { - if (Thirdweb::ecosystem_wallet_link_account(ThisCopy.GetID(), Wallet.GetID(), TO_RUST_STRING(OTP), nullptr, nullptr, nullptr, nullptr, nullptr, nullptr).AssignResult(Error, true)) + case Phone: { - SuccessDelegate.Execute(); - return; + if (Thirdweb::ecosystem_wallet_link_account(ThisCopy.GetID(), Wallet.GetID(), TO_RUST_STRING(OTP), nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr) + .AssignResult(Error, true)) + { + SuccessDelegate.Execute(); + return; + } + break; } - break; - } - case Email: - { - if (Thirdweb::ecosystem_wallet_sign_in_with_otp_email(ThisCopy.GetID(), TO_RUST_STRING(OTP)).AssignResult(Error, true)) + case Email: { - SuccessDelegate.Execute(); - return; + if (Thirdweb::ecosystem_wallet_sign_in_with_otp_email(ThisCopy.GetID(), TO_RUST_STRING(OTP)) + .AssignResult(Error, true)) + { + SuccessDelegate.Execute(); + return; + } + break; } - break; + default: + return; } - default: return; - } - ErrorDelegate.Execute(Error); - }); + ErrorDelegate.Execute(Error); + }); } bool FInAppWalletHandle::FetchOAuthLoginURL(const FString& RedirectUrl, FString& LoginLink, FString& Error) @@ -527,7 +431,7 @@ bool FInAppWalletHandle::FetchOAuthLoginURL(const FString& RedirectUrl, FString& } else { - if (Thirdweb::in_app_wallet_fetch_oauth_login_link(ThisCopy.GetID(), TO_RUST_STRING(RedirectUrl)).AssignResult(Error)) + if (Thirdweb::ecosystem_wallet_fetch_oauth_login_link(ThisCopy.GetID(), TO_RUST_STRING(RedirectUrl)).AssignResult(Error)) { LoginLink = Error; Error.Empty(); @@ -538,7 +442,8 @@ bool FInAppWalletHandle::FetchOAuthLoginURL(const FString& RedirectUrl, FString& return false; } -void FInAppWalletHandle::SignInWithOAuth(const FString& AuthResult, const FStreamableDelegate& SuccessDelegate, const FStringDelegate& ErrorDelegate) +void FInAppWalletHandle::SignInWithOAuth( + const FString& AuthResult, const FStreamableDelegate& SuccessDelegate, const FStringDelegate& ErrorDelegate) { CHECK_DELEGATES(SuccessDelegate, ErrorDelegate) CHECK_VALIDITY(ErrorDelegate) @@ -549,93 +454,100 @@ void FInAppWalletHandle::SignInWithOAuth(const FString& AuthResult, const FStrea ErrorDelegate.Execute(TEXT("Empty Auth Result")); return; } - FString Result = ThirdwebUtils::ParseAuthResult(AuthResult); + FString Result = ThirdwebUtils::ParseAuthResult(AuthResult); FInAppWalletHandle ThisCopy = *this; - UE::Tasks::Launch(UE_SOURCE_LOCATION, [ThisCopy, Result, SuccessDelegate, ErrorDelegate] - { - FString Error; - if (UThirdwebRuntimeSettings::IsEcosystem()) - { - TW_LOG(VeryVerbose, TEXT("FInAppWalletHandle::SignInWithOAuth::Task::%s"), *Result) - if (Thirdweb::ecosystem_wallet_sign_in_with_oauth(ThisCopy.GetID(), TO_RUST_STRING(Result)).AssignResult(Error, true)) + UE::Tasks::Launch(UE_SOURCE_LOCATION, + [ThisCopy, Result, SuccessDelegate, ErrorDelegate] { + FString Error; + if (UThirdwebRuntimeSettings::IsEcosystem()) { - ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); - SuccessDelegate.Execute(); - return; + TW_LOG(VeryVerbose, TEXT("FInAppWalletHandle::SignInWithOAuth::Task::%s"), *Result) + if (Thirdweb::ecosystem_wallet_sign_in_with_oauth(ThisCopy.GetID(), TO_RUST_STRING(Result)) + .AssignResult(Error, true)) + { + ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); + SuccessDelegate.Execute(); + return; + } } - } - else - { - if (Thirdweb::in_app_wallet_sign_in_with_oauth(ThisCopy.GetID(), TO_RUST_STRING(Result)).AssignResult(Error, true)) + else { - ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); - SuccessDelegate.Execute(); - return; + if (Thirdweb::ecosystem_wallet_sign_in_with_oauth(ThisCopy.GetID(), TO_RUST_STRING(Result)) + .AssignResult(Error, true)) + { + ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); + SuccessDelegate.Execute(); + return; + } } - } - ErrorDelegate.Execute(Error); - }); + ErrorDelegate.Execute(Error); + }); } -void FInAppWalletHandle::LinkOAuth(const FInAppWalletHandle& Wallet, const FString& AuthResult, const FStreamableDelegate& SuccessDelegate, const FStringDelegate& ErrorDelegate) +void FInAppWalletHandle::LinkOAuth(const FInAppWalletHandle& Wallet, const FString& AuthResult, + const FStreamableDelegate& SuccessDelegate, const FStringDelegate& ErrorDelegate) { CHECK_DELEGATES(SuccessDelegate, ErrorDelegate) CHECK_VALIDITY(ErrorDelegate) CHECK_ECOSYSTEM(ErrorDelegate) CHECK_WALLET_SOURCE(Wallet, OAuthProvider, ErrorDelegate) - FString Result = ThirdwebUtils::ParseAuthResult(AuthResult); + FString Result = ThirdwebUtils::ParseAuthResult(AuthResult); FInAppWalletHandle ThisCopy = *this; - UE::Tasks::Launch(UE_SOURCE_LOCATION, [ThisCopy, Wallet, Result, SuccessDelegate, ErrorDelegate] - { - FString Error; - if (Thirdweb::ecosystem_wallet_link_account(ThisCopy.GetID(), Wallet.GetID(), nullptr, TO_RUST_STRING(Result), nullptr, nullptr, nullptr, nullptr, nullptr).AssignResult(Error, true)) - { - SuccessDelegate.Execute(); - return; - } - ErrorDelegate.Execute(Error); - }); + UE::Tasks::Launch(UE_SOURCE_LOCATION, + [ThisCopy, Wallet, Result, SuccessDelegate, ErrorDelegate] { + FString Error; + if (Thirdweb::ecosystem_wallet_link_account( + ThisCopy.GetID(), Wallet.GetID(), nullptr, TO_RUST_STRING(Result), nullptr, nullptr, nullptr, nullptr, nullptr) + .AssignResult(Error, true)) + { + SuccessDelegate.Execute(); + return; + } + ErrorDelegate.Execute(Error); + }); } -void FInAppWalletHandle::SignInWithJwt(const FString& Jwt, const FStreamableDelegate& SuccessDelegate, const FStringDelegate& ErrorDelegate) +void FInAppWalletHandle::SignInWithJwt( + const FString& Jwt, const FStreamableDelegate& SuccessDelegate, const FStringDelegate& ErrorDelegate) { CHECK_DELEGATES(SuccessDelegate, ErrorDelegate) CHECK_VALIDITY(ErrorDelegate) CHECK_SOURCE(EInAppSource::Jwt, ErrorDelegate) FInAppWalletHandle ThisCopy = *this; - UE::Tasks::Launch(UE_SOURCE_LOCATION, [ThisCopy, Jwt, SuccessDelegate, ErrorDelegate] - { - FString Error; - if (UThirdwebRuntimeSettings::IsEcosystem()) - { - if (Thirdweb::ecosystem_wallet_sign_in_with_jwt(ThisCopy.GetID(), TO_RUST_STRING(Jwt)).AssignResult(Error, true)) + UE::Tasks::Launch(UE_SOURCE_LOCATION, + [ThisCopy, Jwt, SuccessDelegate, ErrorDelegate] { + FString Error; + if (UThirdwebRuntimeSettings::IsEcosystem()) { - ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); - SuccessDelegate.Execute(); - return; - } - } - else - { - if (UThirdwebRuntimeSettings::GetEncryptionKey().IsEmpty()) - { - ErrorDelegate.Execute(TEXT("No encryption key set")); - return; + if (Thirdweb::ecosystem_wallet_sign_in_with_jwt(ThisCopy.GetID(), TO_RUST_STRING(Jwt)).AssignResult(Error, true)) + { + ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); + SuccessDelegate.Execute(); + return; + } } - if (Thirdweb::in_app_wallet_sign_in_with_jwt(ThisCopy.GetID(), TO_RUST_STRING(Jwt), TO_RUST_STRING(UThirdwebRuntimeSettings::GetEncryptionKey())).AssignResult(Error, true)) + else { - ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); - SuccessDelegate.Execute(); - return; + if (UThirdwebRuntimeSettings::GetEncryptionKey().IsEmpty()) + { + ErrorDelegate.Execute(TEXT("No encryption key set")); + return; + } + if (Thirdweb::ecosystem_wallet_sign_in_with_jwt(ThisCopy.GetID(), TO_RUST_STRING(Jwt)).AssignResult(Error, true)) + { + ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); + SuccessDelegate.Execute(); + return; + } } - } - ErrorDelegate.Execute(Error); - }); + ErrorDelegate.Execute(Error); + }); } -void FInAppWalletHandle::LinkJwt(const FInAppWalletHandle& Wallet, const FString& Jwt, const FStreamableDelegate& SuccessDelegate, const FStringDelegate& ErrorDelegate) +void FInAppWalletHandle::LinkJwt(const FInAppWalletHandle& Wallet, const FString& Jwt, const FStreamableDelegate& SuccessDelegate, + const FStringDelegate& ErrorDelegate) { CHECK_DELEGATES(SuccessDelegate, ErrorDelegate) CHECK_VALIDITY(ErrorDelegate) @@ -643,56 +555,62 @@ void FInAppWalletHandle::LinkJwt(const FInAppWalletHandle& Wallet, const FString CHECK_WALLET_SOURCE(Wallet, EInAppSource::Jwt, ErrorDelegate) FInAppWalletHandle ThisCopy = *this; - UE::Tasks::Launch(UE_SOURCE_LOCATION, [ThisCopy, Wallet, Jwt, SuccessDelegate, ErrorDelegate] - { - FString Error; - if (Thirdweb::ecosystem_wallet_link_account(ThisCopy.GetID(), Wallet.GetID(), nullptr, nullptr, TO_RUST_STRING(Jwt), nullptr, nullptr, nullptr, nullptr).AssignResult(Error, true)) - { - SuccessDelegate.Execute(); - return; - } - ErrorDelegate.Execute(Error); - }); + UE::Tasks::Launch(UE_SOURCE_LOCATION, + [ThisCopy, Wallet, Jwt, SuccessDelegate, ErrorDelegate] { + FString Error; + if (Thirdweb::ecosystem_wallet_link_account( + ThisCopy.GetID(), Wallet.GetID(), nullptr, nullptr, TO_RUST_STRING(Jwt), nullptr, nullptr, nullptr, nullptr) + .AssignResult(Error, true)) + { + SuccessDelegate.Execute(); + return; + } + ErrorDelegate.Execute(Error); + }); } -void FInAppWalletHandle::SignInWithAuthEndpoint(const FString& Payload, const FStreamableDelegate& SuccessDelegate, const FStringDelegate& ErrorDelegate) +void FInAppWalletHandle::SignInWithAuthEndpoint( + const FString& Payload, const FStreamableDelegate& SuccessDelegate, const FStringDelegate& ErrorDelegate) { CHECK_DELEGATES(SuccessDelegate, ErrorDelegate) CHECK_VALIDITY(ErrorDelegate) CHECK_SOURCE(AuthEndpoint, ErrorDelegate) FInAppWalletHandle ThisCopy = *this; - UE::Tasks::Launch(UE_SOURCE_LOCATION, [ThisCopy, Payload, SuccessDelegate, ErrorDelegate] - { - FString Error; - if (UThirdwebRuntimeSettings::IsEcosystem()) - { - if (Thirdweb::ecosystem_wallet_sign_in_with_auth_endpoint(ThisCopy.GetID(), TO_RUST_STRING(Payload)).AssignResult(Error, true)) + UE::Tasks::Launch(UE_SOURCE_LOCATION, + [ThisCopy, Payload, SuccessDelegate, ErrorDelegate] { + FString Error; + if (UThirdwebRuntimeSettings::IsEcosystem()) { - ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); - SuccessDelegate.Execute(); - return; - } - } - else - { - if (UThirdwebRuntimeSettings::GetEncryptionKey().IsEmpty()) - { - ErrorDelegate.Execute(TEXT("No encryption key set")); - return; + if (Thirdweb::ecosystem_wallet_sign_in_with_auth_endpoint(ThisCopy.GetID(), TO_RUST_STRING(Payload)) + .AssignResult(Error, true)) + { + ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); + SuccessDelegate.Execute(); + return; + } } - if (Thirdweb::in_app_wallet_sign_in_with_auth_endpoint(ThisCopy.GetID(), TO_RUST_STRING(Payload), TO_RUST_STRING(UThirdwebRuntimeSettings::GetEncryptionKey())).AssignResult(Error, true)) + else { - ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); - SuccessDelegate.Execute(); - return; + if (UThirdwebRuntimeSettings::GetEncryptionKey().IsEmpty()) + { + ErrorDelegate.Execute(TEXT("No encryption key set")); + return; + } + if (Thirdweb::ecosystem_wallet_sign_in_with_auth_endpoint(ThisCopy.GetID(), TO_RUST_STRING(Payload)) + .AssignResult(Error, true)) + { + ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); + SuccessDelegate.Execute(); + return; + } } - } - ErrorDelegate.Execute(Error); - }); + ErrorDelegate.Execute(Error); + }); } -void FInAppWalletHandle::LinkAuthEndpoint(const FInAppWalletHandle& Wallet, const FString& Payload, const FStreamableDelegate& SuccessDelegate, const FStringDelegate& ErrorDelegate) +void FInAppWalletHandle::LinkAuthEndpoint(const FInAppWalletHandle& Wallet, const FString& Payload, + const FStreamableDelegate& SuccessDelegate, const FStringDelegate& ErrorDelegate) { CHECK_DELEGATES(SuccessDelegate, ErrorDelegate) CHECK_VALIDITY(ErrorDelegate) @@ -700,16 +618,18 @@ void FInAppWalletHandle::LinkAuthEndpoint(const FInAppWalletHandle& Wallet, cons CHECK_WALLET_SOURCE(Wallet, AuthEndpoint, ErrorDelegate) FInAppWalletHandle ThisCopy = *this; - UE::Tasks::Launch(UE_SOURCE_LOCATION, [ThisCopy, Wallet, Payload, SuccessDelegate, ErrorDelegate] - { - FString Error; - if (Thirdweb::ecosystem_wallet_link_account(ThisCopy.GetID(), Wallet.GetID(), nullptr, nullptr, nullptr, TO_RUST_STRING(Payload), nullptr, nullptr, nullptr).AssignResult(Error, true)) - { - SuccessDelegate.Execute(); - return; - } - ErrorDelegate.Execute(Error); - }); + UE::Tasks::Launch(UE_SOURCE_LOCATION, + [ThisCopy, Wallet, Payload, SuccessDelegate, ErrorDelegate] { + FString Error; + if (Thirdweb::ecosystem_wallet_link_account( + ThisCopy.GetID(), Wallet.GetID(), nullptr, nullptr, nullptr, TO_RUST_STRING(Payload), nullptr, nullptr, nullptr) + .AssignResult(Error, true)) + { + SuccessDelegate.Execute(); + return; + } + ErrorDelegate.Execute(Error); + }); } void FInAppWalletHandle::SignInWithGuest(const FStreamableDelegate& SuccessDelegate, const FStringDelegate& ErrorDelegate) @@ -719,32 +639,35 @@ void FInAppWalletHandle::SignInWithGuest(const FStreamableDelegate& SuccessDeleg CHECK_SOURCE(Guest, ErrorDelegate) FInAppWalletHandle ThisCopy = *this; - UE::Tasks::Launch(UE_SOURCE_LOCATION, [ThisCopy, SuccessDelegate, ErrorDelegate] - { - FString Error; - if (UThirdwebRuntimeSettings::IsEcosystem()) - { - if (Thirdweb::ecosystem_wallet_sign_in_with_guest(ThisCopy.GetID(), TO_RUST_STRING(FPlatformMisc::GetLoginId())).AssignResult(Error, true)) + UE::Tasks::Launch(UE_SOURCE_LOCATION, + [ThisCopy, SuccessDelegate, ErrorDelegate] { + FString Error; + if (UThirdwebRuntimeSettings::IsEcosystem()) { - ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); - SuccessDelegate.Execute(); - return; + if (Thirdweb::ecosystem_wallet_sign_in_with_guest(ThisCopy.GetID(), TO_RUST_STRING(FPlatformMisc::GetLoginId())) + .AssignResult(Error, true)) + { + ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); + SuccessDelegate.Execute(); + return; + } } - } - else - { - if (Thirdweb::in_app_wallet_sign_in_with_guest(ThisCopy.GetID(), TO_RUST_STRING(FPlatformMisc::GetLoginId())).AssignResult(Error, true)) + else { - ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); - SuccessDelegate.Execute(); - return; + if (Thirdweb::ecosystem_wallet_sign_in_with_guest(ThisCopy.GetID(), TO_RUST_STRING(FPlatformMisc::GetLoginId())) + .AssignResult(Error, true)) + { + ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); + SuccessDelegate.Execute(); + return; + } } - } - ErrorDelegate.Execute(Error); - }); + ErrorDelegate.Execute(Error); + }); } -void FInAppWalletHandle::LinkGuest(const FInAppWalletHandle& Wallet, const FStreamableDelegate& SuccessDelegate, const FStringDelegate& ErrorDelegate) +void FInAppWalletHandle::LinkGuest( + const FInAppWalletHandle& Wallet, const FStreamableDelegate& SuccessDelegate, const FStringDelegate& ErrorDelegate) { CHECK_DELEGATES(SuccessDelegate, ErrorDelegate) CHECK_VALIDITY(ErrorDelegate) @@ -752,53 +675,63 @@ void FInAppWalletHandle::LinkGuest(const FInAppWalletHandle& Wallet, const FStre CHECK_WALLET_SOURCE(Wallet, Guest, ErrorDelegate) FInAppWalletHandle ThisCopy = *this; - UE::Tasks::Launch(UE_SOURCE_LOCATION, [ThisCopy, Wallet, SuccessDelegate, ErrorDelegate] - { - FString Error; - if (Thirdweb::ecosystem_wallet_link_account(ThisCopy.GetID(), Wallet.GetID(), nullptr, nullptr, nullptr, nullptr, TO_RUST_STRING(FPlatformMisc::GetLoginId()), nullptr, nullptr). - AssignResult(Error, true)) - { - SuccessDelegate.Execute(); - return; - } - ErrorDelegate.Execute(Error); - }); + UE::Tasks::Launch(UE_SOURCE_LOCATION, + [ThisCopy, Wallet, SuccessDelegate, ErrorDelegate] { + FString Error; + if (Thirdweb::ecosystem_wallet_link_account(ThisCopy.GetID(), Wallet.GetID(), nullptr, nullptr, nullptr, nullptr, + TO_RUST_STRING(FPlatformMisc::GetLoginId()), nullptr, nullptr) + .AssignResult(Error, true)) + { + SuccessDelegate.Execute(); + return; + } + ErrorDelegate.Execute(Error); + }); } -void FInAppWalletHandle::SignInWithEthereum(const FString& Payload, const FString& Signature, const FStreamableDelegate& SuccessDelegate, const FStringDelegate& ErrorDelegate) +void FInAppWalletHandle::SignInWithEthereum(const FString& Payload, const FString& Signature, + const FStreamableDelegate& SuccessDelegate, const FStringDelegate& ErrorDelegate) { CHECK_DELEGATES(SuccessDelegate, ErrorDelegate) CHECK_VALIDITY(ErrorDelegate) CHECK_SOURCE(Siwe, ErrorDelegate) FInAppWalletHandle ThisCopy = *this; - UE::Tasks::Launch(UE_SOURCE_LOCATION, [ThisCopy, Payload, Signature, SuccessDelegate, ErrorDelegate] - { - UE_LOG(LogTemp, VeryVerbose, TEXT("FInAppWalletHandle::SignInWithEthereum::Task::WalletHandle=%lld | Signature=%s | Payload=%s"), ThisCopy.GetID(), *Signature, *Payload); - FString Error; - if (UThirdwebRuntimeSettings::IsEcosystem()) - { - if (Thirdweb::ecosystem_wallet_sign_in_with_siwe(ThisCopy.GetID(), TO_RUST_STRING(Payload), TO_RUST_STRING(Signature)).AssignResult(Error, true)) + UE::Tasks::Launch(UE_SOURCE_LOCATION, + [ThisCopy, Payload, Signature, SuccessDelegate, ErrorDelegate] { + UE_LOG(LogTemp, VeryVerbose, + TEXT("FInAppWalletHandle::SignInWithEthereum::Task::WalletHandle=%" + "lld | Signature=%s | Payload=%s"), + ThisCopy.GetID(), *Signature, *Payload); + FString Error; + if (UThirdwebRuntimeSettings::IsEcosystem()) { - ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); - SuccessDelegate.Execute(); - return; + if (Thirdweb::ecosystem_wallet_sign_in_with_siwe( + ThisCopy.GetID(), TO_RUST_STRING(Payload), TO_RUST_STRING(Signature)) + .AssignResult(Error, true)) + { + ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); + SuccessDelegate.Execute(); + return; + } } - } - else - { - if (Thirdweb::in_app_wallet_sign_in_with_siwe(ThisCopy.GetID(), TO_RUST_STRING(Payload), TO_RUST_STRING(Signature)).AssignResult(Error, true)) + else { - ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); - SuccessDelegate.Execute(); - return; + if (Thirdweb::ecosystem_wallet_sign_in_with_siwe( + ThisCopy.GetID(), TO_RUST_STRING(Payload), TO_RUST_STRING(Signature)) + .AssignResult(Error, true)) + { + ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); + SuccessDelegate.Execute(); + return; + } } - } - ErrorDelegate.Execute(Error); - }); + ErrorDelegate.Execute(Error); + }); } -void FInAppWalletHandle::LinkSiwe(const FInAppWalletHandle& Wallet, const FString& Payload, const FString& Signature, const FStreamableDelegate& SuccessDelegate, const FStringDelegate& ErrorDelegate) +void FInAppWalletHandle::LinkSiwe(const FInAppWalletHandle& Wallet, const FString& Payload, const FString& Signature, + const FStreamableDelegate& SuccessDelegate, const FStringDelegate& ErrorDelegate) { CHECK_DELEGATES(SuccessDelegate, ErrorDelegate) CHECK_VALIDITY(ErrorDelegate) @@ -806,17 +739,18 @@ void FInAppWalletHandle::LinkSiwe(const FInAppWalletHandle& Wallet, const FStrin CHECK_WALLET_SOURCE(Wallet, Siwe, ErrorDelegate) FInAppWalletHandle ThisCopy = *this; - UE::Tasks::Launch(UE_SOURCE_LOCATION, [ThisCopy, Wallet, Payload, Signature, SuccessDelegate, ErrorDelegate] - { - FString Error; - if (Thirdweb::ecosystem_wallet_link_account(ThisCopy.GetID(), Wallet.GetID(), nullptr, nullptr, nullptr, nullptr, nullptr, TO_RUST_STRING(Signature), TO_RUST_STRING(Payload)). - AssignResult(Error, true)) - { - SuccessDelegate.Execute(); - return; - } - ErrorDelegate.Execute(Error); - }); + UE::Tasks::Launch(UE_SOURCE_LOCATION, + [ThisCopy, Wallet, Payload, Signature, SuccessDelegate, ErrorDelegate] { + FString Error; + if (Thirdweb::ecosystem_wallet_link_account(ThisCopy.GetID(), Wallet.GetID(), nullptr, nullptr, nullptr, nullptr, + nullptr, TO_RUST_STRING(Signature), TO_RUST_STRING(Payload)) + .AssignResult(Error, true)) + { + SuccessDelegate.Execute(); + return; + } + ErrorDelegate.Execute(Error); + }); } void FInAppWalletHandle::GetLinkedAccounts(const FGetLinkedAccountsDelegate& SuccessDelegate, const FStringDelegate& ErrorDelegate) @@ -826,35 +760,33 @@ void FInAppWalletHandle::GetLinkedAccounts(const FGetLinkedAccountsDelegate& Suc CHECK_ECOSYSTEM(ErrorDelegate) FInAppWalletHandle ThisCopy = *this; - UE::Tasks::Launch(UE_SOURCE_LOCATION, [ThisCopy, SuccessDelegate, ErrorDelegate] - { - FString Output; - if (Thirdweb::ecosystem_wallet_get_linked_accounts(ThisCopy.GetID()).AssignResult(Output)) - { - TArray LinkedAccounts; - TArray> JsonValueArray = ThirdwebUtils::Json::ToJsonArray(Output); - for (int i = 0; i < JsonValueArray.Num(); i++) + UE::Tasks::Launch(UE_SOURCE_LOCATION, + [ThisCopy, SuccessDelegate, ErrorDelegate] { + FString Output; + if (Thirdweb::ecosystem_wallet_get_linked_accounts(ThisCopy.GetID()).AssignResult(Output)) { - if (JsonValueArray[i]->Type == EJson::Object) + TArray LinkedAccounts; + TArray> JsonValueArray = ThirdwebUtils::Json::ToJsonArray(Output); + for (int i = 0; i < JsonValueArray.Num(); i++) { - LinkedAccounts.Emplace(FThirdwebLinkedAccount::FromJson(JsonValueArray[i]->AsObject())); + if (JsonValueArray[i]->Type == EJson::Object) + { + LinkedAccounts.Emplace(FThirdwebLinkedAccount::FromJson(JsonValueArray[i]->AsObject())); + } } + SuccessDelegate.Execute(LinkedAccounts); + return; } - SuccessDelegate.Execute(LinkedAccounts); - return; - } - ErrorDelegate.Execute(Output); - }); + ErrorDelegate.Execute(Output); + }); } FString FInAppWalletHandle::GetDisplayName() const { - return IsValid() - ? FString::Printf( - TEXT("%sWallet::%s::%lld"), - GetTypeString(), - Source == OAuthProvider - ? *FString::Printf(TEXT("%s::%s"), GetSourceString(), *ThirdwebUtils::ToString(Provider)) - : GetSourceString(), ID) - : TEXT("InAppWallet::INVALID"); + return IsValid() ? FString::Printf(TEXT("%sWallet::%s::%lld"), GetTypeString(), + Source == OAuthProvider + ? *FString::Printf(TEXT("%s::%s"), GetSourceString(), *ThirdwebUtils::ToString(Provider)) + : GetSourceString(), + ID) + : TEXT("InAppWallet::INVALID"); } diff --git a/Source/Thirdweb/Public/Thirdweb.h b/Source/Thirdweb/Public/Thirdweb.h index 0e65202..7846d84 100644 --- a/Source/Thirdweb/Public/Thirdweb.h +++ b/Source/Thirdweb/Public/Thirdweb.h @@ -3,24 +3,22 @@ // ReSharper disable CppUE4CodingStandardNamingViolationWarning,CppUE4CodingStandardNamingViolationWarning #pragma once +#include "Containers/StringConv.h" +#include "Containers/UnrealString.h" +#include "HAL/Platform.h" +#include "ThirdwebMacros.h" + #include #include #include #include #include -#include "ThirdwebMacros.h" - -#include "Containers/StringConv.h" -#include "Containers/UnrealString.h" - -#include "HAL/Platform.h" - namespace Thirdweb { struct FFIResult { - bool success; + bool success; const char* message; // Assign's result to variables and then frees the underlying FFIResult @@ -33,49 +31,19 @@ namespace Thirdweb FString GetOutput() const; }; - extern "C" { - // Wallet Management - - /// Private Key Wallet + extern "C" + { + // Private Key Wallet Methods FFIResult create_private_key_wallet(const char* private_key); FFIResult generate_private_key_wallet(); FFIResult private_key_wallet_export(uintptr_t handle_id); - /// In App Wallet - - FFIResult create_in_app_wallet( - const char* client_id, - const char* bundle_id, - const char* secret_key, - const char* email, - const char* phone, - const char* storage_directory_path, - const char* auth_provider - ); - FFIResult in_app_wallet_send_otp_email(uintptr_t handle_id); - FFIResult in_app_wallet_sign_in_with_otp_email(uintptr_t handle_id, const char* otp); - FFIResult in_app_wallet_send_otp_phone(uintptr_t handle_id); - FFIResult in_app_wallet_sign_in_with_otp_phone(uintptr_t handle_id, const char* otp); - FFIResult in_app_wallet_fetch_oauth_login_link(uintptr_t handle_id, const char* redirect_url); - FFIResult in_app_wallet_sign_in_with_oauth(uintptr_t handle_id, const char* auth_result); - FFIResult in_app_wallet_sign_in_with_jwt(uintptr_t handle_id, const char* jwt, const char* encryption_key); - FFIResult in_app_wallet_sign_in_with_auth_endpoint(uintptr_t handle_id, const char* payload, const char* encryption_key); - FFIResult in_app_wallet_sign_in_with_guest(uintptr_t handle_id, const char* session_id); - FFIResult in_app_wallet_sign_in_with_siwe(intptr_t handle_id, const char* payload, const char* signature); - - // In App (Ecosystem) Wallets - FFIResult create_ecosystem_wallet( - const char* ecosystem_id, - const char* ecosystem_partner_id, - const char* client_id, - const char* bundle_id, - const char* secret_key, - const char* email, - const char* phone, - const char* storage_directory_path, - const char* auth_provider - ); + // In-App & Ecosystem Wallet Methods (In-App is now an Ecosystem Wallet without an ecosystem ID and partner ID) + + FFIResult create_ecosystem_wallet(const char* ecosystem_id, const char* ecosystem_partner_id, const char* client_id, + const char* bundle_id, const char* secret_key, const char* email, const char* phone, const char* storage_directory_path, + const char* auth_provider, const char* legacy_encryption_key); FFIResult ecosystem_wallet_send_otp_email(uintptr_t handle_id); FFIResult ecosystem_wallet_sign_in_with_otp_email(uintptr_t handle_id, const char* otp); FFIResult ecosystem_wallet_send_otp_phone(uintptr_t handle_id); @@ -84,66 +52,48 @@ namespace Thirdweb FFIResult ecosystem_wallet_sign_in_with_oauth(uintptr_t handle_id, const char* auth_result); FFIResult ecosystem_wallet_sign_in_with_jwt(uintptr_t handle_id, const char* jwt); FFIResult ecosystem_wallet_sign_in_with_auth_endpoint(uintptr_t handle_id, const char* payload); + FFIResult ecosystem_wallet_sign_in_with_siwe(uintptr_t handle_id, const char* payload, const char* signature); + FFIResult ecosystem_wallet_sign_in_with_guest(uintptr_t handle_id, const char* session_id); - FFIResult ecosystem_wallet_sign_in_with_siwe(intptr_t handle_id, const char* payload, const char* signature); - - FFIResult ecosystem_wallet_link_account( - uintptr_t handle_id, - uintptr_t wallet_to_link_handle_id, - const char* otp, - const char* oauth_result, - const char* jwt, - const char* payload, - const char* session_id, - const char* siwe_payload, - const char* siwe_signature - ); + FFIResult ecosystem_wallet_link_account(uintptr_t handle_id, uintptr_t wallet_to_link_handle_id, const char* otp, + const char* oauth_result, const char* jwt, const char* payload, const char* session_id, const char* siwe_payload, + const char* siwe_signature); + FFIResult ecosystem_wallet_get_linked_accounts(uintptr_t handle_id); - // Smart Wallet management - - FFIResult create_smart_wallet( - const char* client_id, - const char* bundle_id, - const char* secret_key, - uintptr_t personal_wallet_handle_id, - const char* chain_id, - bool gasless, - const char* factory, - const char* account_override - ); + // Smart Wallet Methods + + FFIResult create_smart_wallet(const char* client_id, const char* bundle_id, const char* secret_key, + uintptr_t personal_wallet_handle_id, const char* chain_id, bool gasless, const char* factory, const char* account_override); FFIResult smart_wallet_is_deployed(uintptr_t handle_id); FFIResult smart_wallet_get_all_admins(uintptr_t handle_id); FFIResult smart_wallet_get_all_active_signers(uintptr_t handle_id); - FFIResult smart_wallet_create_session_key( - uintptr_t handle_id, - const char* signer_address, - const char* const * approved_targets, - uintptr_t approved_targets_count, - const char* native_token_limit_per_transaction_in_wei, - uint64_t permission_start_timestamp, - uint64_t permission_end_timestamp, - uint64_t req_validity_start_timestamp, - uint64_t req_validity_end_timestamp - ); + FFIResult smart_wallet_create_session_key(uintptr_t handle_id, const char* signer_address, const char* const* approved_targets, + uintptr_t approved_targets_count, const char* native_token_limit_per_transaction_in_wei, + uint64_t permission_start_timestamp, uint64_t permission_end_timestamp, uint64_t req_validity_start_timestamp, + uint64_t req_validity_end_timestamp); FFIResult smart_wallet_revoke_session_key(uintptr_t handle_id, const char* signer_address); FFIResult smart_wallet_add_admin(uintptr_t handle_id, const char* signer_address); FFIResult smart_wallet_remove_admin(uintptr_t handle_id, const char* signer_address); - // Utility Methods + // Shared Wallet Methods FFIResult get_wallet_address(uintptr_t handle_id); FFIResult sign_message(uintptr_t handle_id, const char* message); FFIResult is_connected(uintptr_t handle_id); FFIResult disconnect(uintptr_t handle_id); - void free_wallet(uintptr_t handle_id); - void free_ffi_result(FFIResult result); - void free_string(char* s); + + // Utility Methods + + void free_ffi_result(FFIResult result); + void free_wallet(uintptr_t handle_id); + void free_string(char* s); + FFIResult get_unix_timestamp_now(); + FFIResult get_unix_timestamp_in_ten_years(); FFIResult is_valid_address(const char* address, bool check_checksum); FFIResult to_checksummed_address(const char* address); FFIResult is_valid_private_key(const char* private_key); FFIResult compute_client_id_from_secret_key(const char* secret_key); - FFIResult get_unix_timestamp_now(); - FFIResult get_unix_timestamp_in_ten_years(); - } -} + } // extern c + +} // namespace Thirdweb From 9ae0e32d9058e3c366c1d233471db8e35b43c611 Mon Sep 17 00:00:00 2001 From: 0xFirekeeper <0xFirekeeper@gmail.com> Date: Mon, 13 Jan 2025 21:38:40 +0700 Subject: [PATCH 2/2] fmt --- .../Wallets/ThirdwebInAppWalletHandle.cpp | 993 ++++++++++-------- Source/Thirdweb/Public/Thirdweb.h | 136 +-- 2 files changed, 601 insertions(+), 528 deletions(-) diff --git a/Source/Thirdweb/Private/Wallets/ThirdwebInAppWalletHandle.cpp b/Source/Thirdweb/Private/Wallets/ThirdwebInAppWalletHandle.cpp index 882d0cc..5ed728e 100644 --- a/Source/Thirdweb/Private/Wallets/ThirdwebInAppWalletHandle.cpp +++ b/Source/Thirdweb/Private/Wallets/ThirdwebInAppWalletHandle.cpp @@ -90,43 +90,50 @@ void FInAppWalletHandle::CreateEmailWallet( CHECK_DELEGATES(SuccessDelegate, ErrorDelegate) UE::Tasks::Launch(UE_SOURCE_LOCATION, - [Email, SuccessDelegate, ErrorDelegate] { - FString Error; - if (Thirdweb::create_ecosystem_wallet(TO_RUST_STRING(UThirdwebRuntimeSettings::GetEcosystemId()), - TO_RUST_STRING(UThirdwebRuntimeSettings::GetPartnerId()), - TO_RUST_STRING(UThirdwebRuntimeSettings::GetClientId()), - TO_RUST_STRING(UThirdwebRuntimeSettings::GetBundleId()), nullptr, TO_RUST_STRING(Email), nullptr, - TO_RUST_STRING(UThirdwebRuntimeSettings::GetStorageDirectory()), nullptr, nullptr) - .AssignResult(Error)) - { - SuccessDelegate.Execute(FInAppWalletHandle(EInAppSource::Email, Error)); - return; - } - ErrorDelegate.Execute(Error); - }); + [Email, SuccessDelegate, ErrorDelegate] + { + FString Error; + if (Thirdweb::create_ecosystem_wallet( + TO_RUST_STRING(UThirdwebRuntimeSettings::GetEcosystemId()), + TO_RUST_STRING(UThirdwebRuntimeSettings::GetPartnerId()), + TO_RUST_STRING(UThirdwebRuntimeSettings::GetClientId()), + TO_RUST_STRING(UThirdwebRuntimeSettings::GetBundleId()), nullptr, + TO_RUST_STRING(Email), nullptr, + TO_RUST_STRING(UThirdwebRuntimeSettings::GetStorageDirectory()), nullptr, nullptr) + .AssignResult(Error)) + { + SuccessDelegate.Execute(FInAppWalletHandle(EInAppSource::Email, Error)); + return; + } + ErrorDelegate.Execute(Error); + }); } void FInAppWalletHandle::CreateOAuthWallet( - const EThirdwebOAuthProvider Provider, const FCreateInAppWalletDelegate& SuccessDelegate, const FStringDelegate& ErrorDelegate) + const EThirdwebOAuthProvider Provider, const FCreateInAppWalletDelegate& SuccessDelegate, + const FStringDelegate& ErrorDelegate) { CHECK_DELEGATES(SuccessDelegate, ErrorDelegate) UE::Tasks::Launch(UE_SOURCE_LOCATION, - [Provider, SuccessDelegate, ErrorDelegate] { - FString Error; - if (UThirdwebRuntimeSettings::IsEcosystem()) - if (Thirdweb::create_ecosystem_wallet(TO_RUST_STRING(UThirdwebRuntimeSettings::GetEcosystemId()), - TO_RUST_STRING(UThirdwebRuntimeSettings::GetPartnerId()), - TO_RUST_STRING(UThirdwebRuntimeSettings::GetClientId()), - TO_RUST_STRING(UThirdwebRuntimeSettings::GetBundleId()), nullptr, nullptr, nullptr, - TO_RUST_STRING(UThirdwebRuntimeSettings::GetStorageDirectory()), - TO_RUST_STRING(ThirdwebUtils::ToString(Provider)), nullptr) - .AssignResult(Error)) - { - SuccessDelegate.Execute(FInAppWalletHandle(Provider, Error)); - return; - } - ErrorDelegate.Execute(Error); - }); + [Provider, SuccessDelegate, ErrorDelegate] + { + FString Error; + if (UThirdwebRuntimeSettings::IsEcosystem()) + if (Thirdweb::create_ecosystem_wallet( + TO_RUST_STRING(UThirdwebRuntimeSettings::GetEcosystemId()), + TO_RUST_STRING(UThirdwebRuntimeSettings::GetPartnerId()), + TO_RUST_STRING(UThirdwebRuntimeSettings::GetClientId()), + TO_RUST_STRING(UThirdwebRuntimeSettings::GetBundleId()), nullptr, nullptr, + nullptr, + TO_RUST_STRING(UThirdwebRuntimeSettings::GetStorageDirectory()), + TO_RUST_STRING(ThirdwebUtils::ToString(Provider)), nullptr) + .AssignResult(Error)) + { + SuccessDelegate.Execute(FInAppWalletHandle(Provider, Error)); + return; + } + ErrorDelegate.Execute(Error); + }); } void FInAppWalletHandle::CreatePhoneWallet( @@ -134,44 +141,51 @@ void FInAppWalletHandle::CreatePhoneWallet( { CHECK_DELEGATES(SuccessDelegate, ErrorDelegate) UE::Tasks::Launch(UE_SOURCE_LOCATION, - [Phone, SuccessDelegate, ErrorDelegate] { - FString Error; - - if (Thirdweb::create_ecosystem_wallet(TO_RUST_STRING(UThirdwebRuntimeSettings::GetEcosystemId()), - TO_RUST_STRING(UThirdwebRuntimeSettings::GetPartnerId()), - TO_RUST_STRING(UThirdwebRuntimeSettings::GetClientId()), - TO_RUST_STRING(UThirdwebRuntimeSettings::GetBundleId()), nullptr, nullptr, TO_RUST_STRING(Phone), - TO_RUST_STRING(UThirdwebRuntimeSettings::GetStorageDirectory()), nullptr, nullptr) - .AssignResult(Error)) - { - SuccessDelegate.Execute(FInAppWalletHandle(EInAppSource::Phone, Error)); - return; - } - - ErrorDelegate.Execute(Error); - }); + [Phone, SuccessDelegate, ErrorDelegate] + { + FString Error; + + if (Thirdweb::create_ecosystem_wallet( + TO_RUST_STRING(UThirdwebRuntimeSettings::GetEcosystemId()), + TO_RUST_STRING(UThirdwebRuntimeSettings::GetPartnerId()), + TO_RUST_STRING(UThirdwebRuntimeSettings::GetClientId()), + TO_RUST_STRING(UThirdwebRuntimeSettings::GetBundleId()), nullptr, nullptr, + TO_RUST_STRING(Phone), + TO_RUST_STRING(UThirdwebRuntimeSettings::GetStorageDirectory()), nullptr, nullptr) + .AssignResult(Error)) + { + SuccessDelegate.Execute(FInAppWalletHandle(EInAppSource::Phone, Error)); + return; + } + + ErrorDelegate.Execute(Error); + }); } -void FInAppWalletHandle::CreateSiweWallet(const FCreateInAppWalletDelegate& SuccessDelegate, const FStringDelegate& ErrorDelegate) +void FInAppWalletHandle::CreateSiweWallet(const FCreateInAppWalletDelegate& SuccessDelegate, + const FStringDelegate& ErrorDelegate) { CHECK_DELEGATES(SuccessDelegate, ErrorDelegate) UE::Tasks::Launch(UE_SOURCE_LOCATION, - [SuccessDelegate, ErrorDelegate] { - static FString Provider = TEXT("SIWE"); - FString Error; - - if (Thirdweb::create_ecosystem_wallet(TO_RUST_STRING(UThirdwebRuntimeSettings::GetEcosystemId()), - TO_RUST_STRING(UThirdwebRuntimeSettings::GetPartnerId()), - TO_RUST_STRING(UThirdwebRuntimeSettings::GetClientId()), - TO_RUST_STRING(UThirdwebRuntimeSettings::GetBundleId()), nullptr, nullptr, nullptr, - TO_RUST_STRING(UThirdwebRuntimeSettings::GetStorageDirectory()), TO_RUST_STRING(Provider), nullptr) - .AssignResult(Error)) - { - SuccessDelegate.Execute(FInAppWalletHandle(Siwe, Error)); - return; - } - ErrorDelegate.Execute(Error); - }); + [SuccessDelegate, ErrorDelegate] + { + static FString Provider = TEXT("SIWE"); + FString Error; + + if (Thirdweb::create_ecosystem_wallet( + TO_RUST_STRING(UThirdwebRuntimeSettings::GetEcosystemId()), + TO_RUST_STRING(UThirdwebRuntimeSettings::GetPartnerId()), + TO_RUST_STRING(UThirdwebRuntimeSettings::GetClientId()), + TO_RUST_STRING(UThirdwebRuntimeSettings::GetBundleId()), nullptr, nullptr, nullptr, + TO_RUST_STRING(UThirdwebRuntimeSettings::GetStorageDirectory()), + TO_RUST_STRING(Provider), nullptr) + .AssignResult(Error)) + { + SuccessDelegate.Execute(FInAppWalletHandle(Siwe, Error)); + return; + } + ErrorDelegate.Execute(Error); + }); } void FInAppWalletHandle::CreateCustomAuthWallet( @@ -187,23 +201,26 @@ void FInAppWalletHandle::CreateCustomAuthWallet( return; } UE::Tasks::Launch(UE_SOURCE_LOCATION, - [Source, SuccessDelegate, ErrorDelegate] { - FString Error; - if (Thirdweb::create_ecosystem_wallet(TO_RUST_STRING(UThirdwebRuntimeSettings::GetEcosystemId()), - TO_RUST_STRING(UThirdwebRuntimeSettings::GetPartnerId()), - TO_RUST_STRING(UThirdwebRuntimeSettings::GetClientId()), - TO_RUST_STRING(UThirdwebRuntimeSettings::GetBundleId()), nullptr, nullptr, nullptr, - TO_RUST_STRING(UThirdwebRuntimeSettings::GetStorageDirectory()), - TO_RUST_STRING(FString(GetSourceString(Source))), - TO_RUST_STRING(UThirdwebRuntimeSettings::GetEncryptionKey()) // legacy, will be used if migrating only - ) - .AssignResult(Error)) - { - SuccessDelegate.Execute(FInAppWalletHandle(Source, Error)); - return; - } - ErrorDelegate.Execute(Error); - }); + [Source, SuccessDelegate, ErrorDelegate] + { + FString Error; + if (Thirdweb::create_ecosystem_wallet( + TO_RUST_STRING(UThirdwebRuntimeSettings::GetEcosystemId()), + TO_RUST_STRING(UThirdwebRuntimeSettings::GetPartnerId()), + TO_RUST_STRING(UThirdwebRuntimeSettings::GetClientId()), + TO_RUST_STRING(UThirdwebRuntimeSettings::GetBundleId()), nullptr, nullptr, nullptr, + TO_RUST_STRING(UThirdwebRuntimeSettings::GetStorageDirectory()), + TO_RUST_STRING(FString(GetSourceString(Source))), + TO_RUST_STRING(UThirdwebRuntimeSettings::GetEncryptionKey()) + // legacy, will be used if migrating only + ) + .AssignResult(Error)) + { + SuccessDelegate.Execute(FInAppWalletHandle(Source, Error)); + return; + } + ErrorDelegate.Execute(Error); + }); } bool FInAppWalletHandle::IsConnected() const @@ -222,68 +239,73 @@ void FInAppWalletHandle::SendOTP(const FStreamableDelegate& SuccessDelegate, con CHECK_VALIDITY(ErrorDelegate) FInAppWalletHandle ThisCopy = *this; UE::Tasks::Launch(UE_SOURCE_LOCATION, - [ThisCopy, SuccessDelegate, ErrorDelegate] { - FString Error; - if (UThirdwebRuntimeSettings::IsEcosystem()) - { - switch (ThisCopy.GetSource()) - { - case Phone: - { - if (Thirdweb::ecosystem_wallet_send_otp_phone(ThisCopy.GetID()).AssignResult(Error, true)) - { - SuccessDelegate.Execute(); - return; - } - break; - } - case Email: - { - if (Thirdweb::ecosystem_wallet_send_otp_email(ThisCopy.GetID()).AssignResult(Error, true)) - { - SuccessDelegate.Execute(); - return; - } - break; - } - default: - { - ErrorDelegate.Execute(TEXT("Wallet handle is not email/phone source")); - return; - } - } - } - else - { - switch (ThisCopy.GetSource()) - { - case Phone: - { - if (Thirdweb::ecosystem_wallet_send_otp_phone(ThisCopy.GetID()).AssignResult(Error, true)) - { - SuccessDelegate.Execute(); - return; - } - break; - } - case Email: - { - if (Thirdweb::ecosystem_wallet_send_otp_email(ThisCopy.GetID()).AssignResult(Error, true)) - { - SuccessDelegate.Execute(); - return; - } - break; - } - default: - { - ErrorDelegate.Execute(TEXT("Wallet handle is not email/phone source")); - return; - } - } - } - ErrorDelegate.Execute(Error); - }); + [ThisCopy, SuccessDelegate, ErrorDelegate] + { + FString Error; + if (UThirdwebRuntimeSettings::IsEcosystem()) + { + switch (ThisCopy.GetSource()) + { + case Phone: + { + if (Thirdweb::ecosystem_wallet_send_otp_phone(ThisCopy.GetID()).AssignResult( + Error, true)) + { + SuccessDelegate.Execute(); + return; + } + break; + } + case Email: + { + if (Thirdweb::ecosystem_wallet_send_otp_email(ThisCopy.GetID()).AssignResult( + Error, true)) + { + SuccessDelegate.Execute(); + return; + } + break; + } + default: + { + ErrorDelegate.Execute(TEXT("Wallet handle is not email/phone source")); + return; + } + } + } + else + { + switch (ThisCopy.GetSource()) + { + case Phone: + { + if (Thirdweb::ecosystem_wallet_send_otp_phone(ThisCopy.GetID()).AssignResult( + Error, true)) + { + SuccessDelegate.Execute(); + return; + } + break; + } + case Email: + { + if (Thirdweb::ecosystem_wallet_send_otp_email(ThisCopy.GetID()).AssignResult( + Error, true)) + { + SuccessDelegate.Execute(); + return; + } + break; + } + default: + { + ErrorDelegate.Execute(TEXT("Wallet handle is not email/phone source")); + return; + } + } + } + ErrorDelegate.Execute(Error); + }); } void FInAppWalletHandle::SignInWithOTP( @@ -298,72 +320,78 @@ void FInAppWalletHandle::SignInWithOTP( } FInAppWalletHandle ThisCopy = *this; UE::Tasks::Launch(UE_SOURCE_LOCATION, - [ThisCopy, OTP, SuccessDelegate, ErrorDelegate] { - FString Error; - if (UThirdwebRuntimeSettings::IsEcosystem()) - { - switch (ThisCopy.GetSource()) - { - case Phone: - { - if (Thirdweb::ecosystem_wallet_sign_in_with_otp_phone(ThisCopy.GetID(), TO_RUST_STRING(OTP)) - .AssignResult(Error, true)) - { - ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); - SuccessDelegate.Execute(); - return; - } - break; - } - case Email: - { - if (Thirdweb::ecosystem_wallet_sign_in_with_otp_email(ThisCopy.GetID(), TO_RUST_STRING(OTP)) - .AssignResult(Error, true)) - { - ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); - SuccessDelegate.Execute(); - return; - } - break; - } - default: - return; - } - } - else - { - switch (ThisCopy.GetSource()) - { - case Phone: - { - if (Thirdweb::ecosystem_wallet_sign_in_with_otp_phone(ThisCopy.GetID(), TO_RUST_STRING(OTP)) - .AssignResult(Error, true)) - { - ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); - SuccessDelegate.Execute(); - return; - } - } - case Email: - { - if (Thirdweb::ecosystem_wallet_sign_in_with_otp_email(ThisCopy.GetID(), TO_RUST_STRING(OTP)) - .AssignResult(Error, true)) - { - ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); - SuccessDelegate.Execute(); - return; - } - } - default: - return; - } - } - ErrorDelegate.Execute(Error); - }); + [ThisCopy, OTP, SuccessDelegate, ErrorDelegate] + { + FString Error; + if (UThirdwebRuntimeSettings::IsEcosystem()) + { + switch (ThisCopy.GetSource()) + { + case Phone: + { + if (Thirdweb::ecosystem_wallet_sign_in_with_otp_phone( + ThisCopy.GetID(), TO_RUST_STRING(OTP)) + .AssignResult(Error, true)) + { + ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); + SuccessDelegate.Execute(); + return; + } + break; + } + case Email: + { + if (Thirdweb::ecosystem_wallet_sign_in_with_otp_email( + ThisCopy.GetID(), TO_RUST_STRING(OTP)) + .AssignResult(Error, true)) + { + ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); + SuccessDelegate.Execute(); + return; + } + break; + } + default: + return; + } + } + else + { + switch (ThisCopy.GetSource()) + { + case Phone: + { + if (Thirdweb::ecosystem_wallet_sign_in_with_otp_phone( + ThisCopy.GetID(), TO_RUST_STRING(OTP)) + .AssignResult(Error, true)) + { + ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); + SuccessDelegate.Execute(); + return; + } + } + case Email: + { + if (Thirdweb::ecosystem_wallet_sign_in_with_otp_email( + ThisCopy.GetID(), TO_RUST_STRING(OTP)) + .AssignResult(Error, true)) + { + ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); + SuccessDelegate.Execute(); + return; + } + } + default: + return; + } + } + ErrorDelegate.Execute(Error); + }); } -void FInAppWalletHandle::LinkOTP(const FInAppWalletHandle& Wallet, const FString& OTP, const FStreamableDelegate& SuccessDelegate, - const FStringDelegate& ErrorDelegate) +void FInAppWalletHandle::LinkOTP(const FInAppWalletHandle& Wallet, const FString& OTP, + const FStreamableDelegate& SuccessDelegate, + const FStringDelegate& ErrorDelegate) { CHECK_DELEGATES(SuccessDelegate, ErrorDelegate) CHECK_VALIDITY(ErrorDelegate) @@ -375,36 +403,39 @@ void FInAppWalletHandle::LinkOTP(const FInAppWalletHandle& Wallet, const FString } FInAppWalletHandle ThisCopy = *this; UE::Tasks::Launch(UE_SOURCE_LOCATION, - [ThisCopy, Wallet, OTP, SuccessDelegate, ErrorDelegate] { - FString Error; - switch (ThisCopy.GetSource()) - { - case Phone: - { - if (Thirdweb::ecosystem_wallet_link_account(ThisCopy.GetID(), Wallet.GetID(), TO_RUST_STRING(OTP), nullptr, - nullptr, nullptr, nullptr, nullptr, nullptr) - .AssignResult(Error, true)) - { - SuccessDelegate.Execute(); - return; - } - break; - } - case Email: - { - if (Thirdweb::ecosystem_wallet_sign_in_with_otp_email(ThisCopy.GetID(), TO_RUST_STRING(OTP)) - .AssignResult(Error, true)) - { - SuccessDelegate.Execute(); - return; - } - break; - } - default: - return; - } - ErrorDelegate.Execute(Error); - }); + [ThisCopy, Wallet, OTP, SuccessDelegate, ErrorDelegate] + { + FString Error; + switch (ThisCopy.GetSource()) + { + case Phone: + { + if (Thirdweb::ecosystem_wallet_link_account( + ThisCopy.GetID(), Wallet.GetID(), TO_RUST_STRING(OTP), nullptr, + nullptr, nullptr, nullptr, nullptr, nullptr) + .AssignResult(Error, true)) + { + SuccessDelegate.Execute(); + return; + } + break; + } + case Email: + { + if (Thirdweb::ecosystem_wallet_sign_in_with_otp_email( + ThisCopy.GetID(), TO_RUST_STRING(OTP)) + .AssignResult(Error, true)) + { + SuccessDelegate.Execute(); + return; + } + break; + } + default: + return; + } + ErrorDelegate.Execute(Error); + }); } bool FInAppWalletHandle::FetchOAuthLoginURL(const FString& RedirectUrl, FString& LoginLink, FString& Error) @@ -422,7 +453,8 @@ bool FInAppWalletHandle::FetchOAuthLoginURL(const FString& RedirectUrl, FString& FInAppWalletHandle ThisCopy = *this; if (UThirdwebRuntimeSettings::IsEcosystem()) { - if (Thirdweb::ecosystem_wallet_fetch_oauth_login_link(ThisCopy.GetID(), TO_RUST_STRING(RedirectUrl)).AssignResult(Error)) + if (Thirdweb::ecosystem_wallet_fetch_oauth_login_link(ThisCopy.GetID(), TO_RUST_STRING(RedirectUrl)). + AssignResult(Error)) { LoginLink = Error; Error.Empty(); @@ -431,7 +463,8 @@ bool FInAppWalletHandle::FetchOAuthLoginURL(const FString& RedirectUrl, FString& } else { - if (Thirdweb::ecosystem_wallet_fetch_oauth_login_link(ThisCopy.GetID(), TO_RUST_STRING(RedirectUrl)).AssignResult(Error)) + if (Thirdweb::ecosystem_wallet_fetch_oauth_login_link(ThisCopy.GetID(), TO_RUST_STRING(RedirectUrl)). + AssignResult(Error)) { LoginLink = Error; Error.Empty(); @@ -454,58 +487,63 @@ void FInAppWalletHandle::SignInWithOAuth( ErrorDelegate.Execute(TEXT("Empty Auth Result")); return; } - FString Result = ThirdwebUtils::ParseAuthResult(AuthResult); + FString Result = ThirdwebUtils::ParseAuthResult(AuthResult); FInAppWalletHandle ThisCopy = *this; UE::Tasks::Launch(UE_SOURCE_LOCATION, - [ThisCopy, Result, SuccessDelegate, ErrorDelegate] { - FString Error; - if (UThirdwebRuntimeSettings::IsEcosystem()) - { - TW_LOG(VeryVerbose, TEXT("FInAppWalletHandle::SignInWithOAuth::Task::%s"), *Result) - if (Thirdweb::ecosystem_wallet_sign_in_with_oauth(ThisCopy.GetID(), TO_RUST_STRING(Result)) - .AssignResult(Error, true)) - { - ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); - SuccessDelegate.Execute(); - return; - } - } - else - { - if (Thirdweb::ecosystem_wallet_sign_in_with_oauth(ThisCopy.GetID(), TO_RUST_STRING(Result)) - .AssignResult(Error, true)) - { - ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); - SuccessDelegate.Execute(); - return; - } - } - ErrorDelegate.Execute(Error); - }); + [ThisCopy, Result, SuccessDelegate, ErrorDelegate] + { + FString Error; + if (UThirdwebRuntimeSettings::IsEcosystem()) + { + TW_LOG(VeryVerbose, TEXT("FInAppWalletHandle::SignInWithOAuth::Task::%s"), *Result) + if (Thirdweb::ecosystem_wallet_sign_in_with_oauth( + ThisCopy.GetID(), TO_RUST_STRING(Result)) + .AssignResult(Error, true)) + { + ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); + SuccessDelegate.Execute(); + return; + } + } + else + { + if (Thirdweb::ecosystem_wallet_sign_in_with_oauth( + ThisCopy.GetID(), TO_RUST_STRING(Result)) + .AssignResult(Error, true)) + { + ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); + SuccessDelegate.Execute(); + return; + } + } + ErrorDelegate.Execute(Error); + }); } void FInAppWalletHandle::LinkOAuth(const FInAppWalletHandle& Wallet, const FString& AuthResult, - const FStreamableDelegate& SuccessDelegate, const FStringDelegate& ErrorDelegate) + const FStreamableDelegate& SuccessDelegate, const FStringDelegate& ErrorDelegate) { CHECK_DELEGATES(SuccessDelegate, ErrorDelegate) CHECK_VALIDITY(ErrorDelegate) CHECK_ECOSYSTEM(ErrorDelegate) CHECK_WALLET_SOURCE(Wallet, OAuthProvider, ErrorDelegate) - FString Result = ThirdwebUtils::ParseAuthResult(AuthResult); + FString Result = ThirdwebUtils::ParseAuthResult(AuthResult); FInAppWalletHandle ThisCopy = *this; UE::Tasks::Launch(UE_SOURCE_LOCATION, - [ThisCopy, Wallet, Result, SuccessDelegate, ErrorDelegate] { - FString Error; - if (Thirdweb::ecosystem_wallet_link_account( - ThisCopy.GetID(), Wallet.GetID(), nullptr, TO_RUST_STRING(Result), nullptr, nullptr, nullptr, nullptr, nullptr) - .AssignResult(Error, true)) - { - SuccessDelegate.Execute(); - return; - } - ErrorDelegate.Execute(Error); - }); + [ThisCopy, Wallet, Result, SuccessDelegate, ErrorDelegate] + { + FString Error; + if (Thirdweb::ecosystem_wallet_link_account( + ThisCopy.GetID(), Wallet.GetID(), nullptr, TO_RUST_STRING(Result), nullptr, nullptr, + nullptr, nullptr, nullptr) + .AssignResult(Error, true)) + { + SuccessDelegate.Execute(); + return; + } + ErrorDelegate.Execute(Error); + }); } void FInAppWalletHandle::SignInWithJwt( @@ -517,37 +555,41 @@ void FInAppWalletHandle::SignInWithJwt( FInAppWalletHandle ThisCopy = *this; UE::Tasks::Launch(UE_SOURCE_LOCATION, - [ThisCopy, Jwt, SuccessDelegate, ErrorDelegate] { - FString Error; - if (UThirdwebRuntimeSettings::IsEcosystem()) - { - if (Thirdweb::ecosystem_wallet_sign_in_with_jwt(ThisCopy.GetID(), TO_RUST_STRING(Jwt)).AssignResult(Error, true)) - { - ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); - SuccessDelegate.Execute(); - return; - } - } - else - { - if (UThirdwebRuntimeSettings::GetEncryptionKey().IsEmpty()) - { - ErrorDelegate.Execute(TEXT("No encryption key set")); - return; - } - if (Thirdweb::ecosystem_wallet_sign_in_with_jwt(ThisCopy.GetID(), TO_RUST_STRING(Jwt)).AssignResult(Error, true)) - { - ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); - SuccessDelegate.Execute(); - return; - } - } - ErrorDelegate.Execute(Error); - }); + [ThisCopy, Jwt, SuccessDelegate, ErrorDelegate] + { + FString Error; + if (UThirdwebRuntimeSettings::IsEcosystem()) + { + if (Thirdweb::ecosystem_wallet_sign_in_with_jwt(ThisCopy.GetID(), TO_RUST_STRING(Jwt)). + AssignResult(Error, true)) + { + ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); + SuccessDelegate.Execute(); + return; + } + } + else + { + if (UThirdwebRuntimeSettings::GetEncryptionKey().IsEmpty()) + { + ErrorDelegate.Execute(TEXT("No encryption key set")); + return; + } + if (Thirdweb::ecosystem_wallet_sign_in_with_jwt(ThisCopy.GetID(), TO_RUST_STRING(Jwt)). + AssignResult(Error, true)) + { + ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); + SuccessDelegate.Execute(); + return; + } + } + ErrorDelegate.Execute(Error); + }); } -void FInAppWalletHandle::LinkJwt(const FInAppWalletHandle& Wallet, const FString& Jwt, const FStreamableDelegate& SuccessDelegate, - const FStringDelegate& ErrorDelegate) +void FInAppWalletHandle::LinkJwt(const FInAppWalletHandle& Wallet, const FString& Jwt, + const FStreamableDelegate& SuccessDelegate, + const FStringDelegate& ErrorDelegate) { CHECK_DELEGATES(SuccessDelegate, ErrorDelegate) CHECK_VALIDITY(ErrorDelegate) @@ -556,17 +598,19 @@ void FInAppWalletHandle::LinkJwt(const FInAppWalletHandle& Wallet, const FString FInAppWalletHandle ThisCopy = *this; UE::Tasks::Launch(UE_SOURCE_LOCATION, - [ThisCopy, Wallet, Jwt, SuccessDelegate, ErrorDelegate] { - FString Error; - if (Thirdweb::ecosystem_wallet_link_account( - ThisCopy.GetID(), Wallet.GetID(), nullptr, nullptr, TO_RUST_STRING(Jwt), nullptr, nullptr, nullptr, nullptr) - .AssignResult(Error, true)) - { - SuccessDelegate.Execute(); - return; - } - ErrorDelegate.Execute(Error); - }); + [ThisCopy, Wallet, Jwt, SuccessDelegate, ErrorDelegate] + { + FString Error; + if (Thirdweb::ecosystem_wallet_link_account( + ThisCopy.GetID(), Wallet.GetID(), nullptr, nullptr, TO_RUST_STRING(Jwt), nullptr, + nullptr, nullptr, nullptr) + .AssignResult(Error, true)) + { + SuccessDelegate.Execute(); + return; + } + ErrorDelegate.Execute(Error); + }); } void FInAppWalletHandle::SignInWithAuthEndpoint( @@ -578,39 +622,43 @@ void FInAppWalletHandle::SignInWithAuthEndpoint( FInAppWalletHandle ThisCopy = *this; UE::Tasks::Launch(UE_SOURCE_LOCATION, - [ThisCopy, Payload, SuccessDelegate, ErrorDelegate] { - FString Error; - if (UThirdwebRuntimeSettings::IsEcosystem()) - { - if (Thirdweb::ecosystem_wallet_sign_in_with_auth_endpoint(ThisCopy.GetID(), TO_RUST_STRING(Payload)) - .AssignResult(Error, true)) - { - ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); - SuccessDelegate.Execute(); - return; - } - } - else - { - if (UThirdwebRuntimeSettings::GetEncryptionKey().IsEmpty()) - { - ErrorDelegate.Execute(TEXT("No encryption key set")); - return; - } - if (Thirdweb::ecosystem_wallet_sign_in_with_auth_endpoint(ThisCopy.GetID(), TO_RUST_STRING(Payload)) - .AssignResult(Error, true)) - { - ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); - SuccessDelegate.Execute(); - return; - } - } - ErrorDelegate.Execute(Error); - }); + [ThisCopy, Payload, SuccessDelegate, ErrorDelegate] + { + FString Error; + if (UThirdwebRuntimeSettings::IsEcosystem()) + { + if (Thirdweb::ecosystem_wallet_sign_in_with_auth_endpoint( + ThisCopy.GetID(), TO_RUST_STRING(Payload)) + .AssignResult(Error, true)) + { + ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); + SuccessDelegate.Execute(); + return; + } + } + else + { + if (UThirdwebRuntimeSettings::GetEncryptionKey().IsEmpty()) + { + ErrorDelegate.Execute(TEXT("No encryption key set")); + return; + } + if (Thirdweb::ecosystem_wallet_sign_in_with_auth_endpoint( + ThisCopy.GetID(), TO_RUST_STRING(Payload)) + .AssignResult(Error, true)) + { + ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); + SuccessDelegate.Execute(); + return; + } + } + ErrorDelegate.Execute(Error); + }); } void FInAppWalletHandle::LinkAuthEndpoint(const FInAppWalletHandle& Wallet, const FString& Payload, - const FStreamableDelegate& SuccessDelegate, const FStringDelegate& ErrorDelegate) + const FStreamableDelegate& SuccessDelegate, + const FStringDelegate& ErrorDelegate) { CHECK_DELEGATES(SuccessDelegate, ErrorDelegate) CHECK_VALIDITY(ErrorDelegate) @@ -619,20 +667,23 @@ void FInAppWalletHandle::LinkAuthEndpoint(const FInAppWalletHandle& Wallet, cons FInAppWalletHandle ThisCopy = *this; UE::Tasks::Launch(UE_SOURCE_LOCATION, - [ThisCopy, Wallet, Payload, SuccessDelegate, ErrorDelegate] { - FString Error; - if (Thirdweb::ecosystem_wallet_link_account( - ThisCopy.GetID(), Wallet.GetID(), nullptr, nullptr, nullptr, TO_RUST_STRING(Payload), nullptr, nullptr, nullptr) - .AssignResult(Error, true)) - { - SuccessDelegate.Execute(); - return; - } - ErrorDelegate.Execute(Error); - }); + [ThisCopy, Wallet, Payload, SuccessDelegate, ErrorDelegate] + { + FString Error; + if (Thirdweb::ecosystem_wallet_link_account( + ThisCopy.GetID(), Wallet.GetID(), nullptr, nullptr, nullptr, TO_RUST_STRING(Payload), + nullptr, nullptr, nullptr) + .AssignResult(Error, true)) + { + SuccessDelegate.Execute(); + return; + } + ErrorDelegate.Execute(Error); + }); } -void FInAppWalletHandle::SignInWithGuest(const FStreamableDelegate& SuccessDelegate, const FStringDelegate& ErrorDelegate) +void FInAppWalletHandle::SignInWithGuest(const FStreamableDelegate& SuccessDelegate, + const FStringDelegate& ErrorDelegate) { CHECK_DELEGATES(SuccessDelegate, ErrorDelegate) CHECK_VALIDITY(ErrorDelegate) @@ -640,30 +691,33 @@ void FInAppWalletHandle::SignInWithGuest(const FStreamableDelegate& SuccessDeleg FInAppWalletHandle ThisCopy = *this; UE::Tasks::Launch(UE_SOURCE_LOCATION, - [ThisCopy, SuccessDelegate, ErrorDelegate] { - FString Error; - if (UThirdwebRuntimeSettings::IsEcosystem()) - { - if (Thirdweb::ecosystem_wallet_sign_in_with_guest(ThisCopy.GetID(), TO_RUST_STRING(FPlatformMisc::GetLoginId())) - .AssignResult(Error, true)) - { - ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); - SuccessDelegate.Execute(); - return; - } - } - else - { - if (Thirdweb::ecosystem_wallet_sign_in_with_guest(ThisCopy.GetID(), TO_RUST_STRING(FPlatformMisc::GetLoginId())) - .AssignResult(Error, true)) - { - ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); - SuccessDelegate.Execute(); - return; - } - } - ErrorDelegate.Execute(Error); - }); + [ThisCopy, SuccessDelegate, ErrorDelegate] + { + FString Error; + if (UThirdwebRuntimeSettings::IsEcosystem()) + { + if (Thirdweb::ecosystem_wallet_sign_in_with_guest( + ThisCopy.GetID(), TO_RUST_STRING(FPlatformMisc::GetLoginId())) + .AssignResult(Error, true)) + { + ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); + SuccessDelegate.Execute(); + return; + } + } + else + { + if (Thirdweb::ecosystem_wallet_sign_in_with_guest( + ThisCopy.GetID(), TO_RUST_STRING(FPlatformMisc::GetLoginId())) + .AssignResult(Error, true)) + { + ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); + SuccessDelegate.Execute(); + return; + } + } + ErrorDelegate.Execute(Error); + }); } void FInAppWalletHandle::LinkGuest( @@ -676,21 +730,25 @@ void FInAppWalletHandle::LinkGuest( FInAppWalletHandle ThisCopy = *this; UE::Tasks::Launch(UE_SOURCE_LOCATION, - [ThisCopy, Wallet, SuccessDelegate, ErrorDelegate] { - FString Error; - if (Thirdweb::ecosystem_wallet_link_account(ThisCopy.GetID(), Wallet.GetID(), nullptr, nullptr, nullptr, nullptr, - TO_RUST_STRING(FPlatformMisc::GetLoginId()), nullptr, nullptr) - .AssignResult(Error, true)) - { - SuccessDelegate.Execute(); - return; - } - ErrorDelegate.Execute(Error); - }); + [ThisCopy, Wallet, SuccessDelegate, ErrorDelegate] + { + FString Error; + if (Thirdweb::ecosystem_wallet_link_account(ThisCopy.GetID(), Wallet.GetID(), nullptr, + nullptr, nullptr, nullptr, + TO_RUST_STRING(FPlatformMisc::GetLoginId()), + nullptr, nullptr) + .AssignResult(Error, true)) + { + SuccessDelegate.Execute(); + return; + } + ErrorDelegate.Execute(Error); + }); } void FInAppWalletHandle::SignInWithEthereum(const FString& Payload, const FString& Signature, - const FStreamableDelegate& SuccessDelegate, const FStringDelegate& ErrorDelegate) + const FStreamableDelegate& SuccessDelegate, + const FStringDelegate& ErrorDelegate) { CHECK_DELEGATES(SuccessDelegate, ErrorDelegate) CHECK_VALIDITY(ErrorDelegate) @@ -698,40 +756,41 @@ void FInAppWalletHandle::SignInWithEthereum(const FString& Payload, const FStrin FInAppWalletHandle ThisCopy = *this; UE::Tasks::Launch(UE_SOURCE_LOCATION, - [ThisCopy, Payload, Signature, SuccessDelegate, ErrorDelegate] { - UE_LOG(LogTemp, VeryVerbose, - TEXT("FInAppWalletHandle::SignInWithEthereum::Task::WalletHandle=%" - "lld | Signature=%s | Payload=%s"), - ThisCopy.GetID(), *Signature, *Payload); - FString Error; - if (UThirdwebRuntimeSettings::IsEcosystem()) - { - if (Thirdweb::ecosystem_wallet_sign_in_with_siwe( - ThisCopy.GetID(), TO_RUST_STRING(Payload), TO_RUST_STRING(Signature)) - .AssignResult(Error, true)) - { - ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); - SuccessDelegate.Execute(); - return; - } - } - else - { - if (Thirdweb::ecosystem_wallet_sign_in_with_siwe( - ThisCopy.GetID(), TO_RUST_STRING(Payload), TO_RUST_STRING(Signature)) - .AssignResult(Error, true)) - { - ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); - SuccessDelegate.Execute(); - return; - } - } - ErrorDelegate.Execute(Error); - }); + [ThisCopy, Payload, Signature, SuccessDelegate, ErrorDelegate] + { + UE_LOG(LogTemp, VeryVerbose, + TEXT("FInAppWalletHandle::SignInWithEthereum::Task::WalletHandle=%" + "lld | Signature=%s | Payload=%s"), + ThisCopy.GetID(), *Signature, *Payload); + FString Error; + if (UThirdwebRuntimeSettings::IsEcosystem()) + { + if (Thirdweb::ecosystem_wallet_sign_in_with_siwe( + ThisCopy.GetID(), TO_RUST_STRING(Payload), TO_RUST_STRING(Signature)) + .AssignResult(Error, true)) + { + ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); + SuccessDelegate.Execute(); + return; + } + } + else + { + if (Thirdweb::ecosystem_wallet_sign_in_with_siwe( + ThisCopy.GetID(), TO_RUST_STRING(Payload), TO_RUST_STRING(Signature)) + .AssignResult(Error, true)) + { + ThirdwebUtils::Internal::SendConnectEvent(ThisCopy); + SuccessDelegate.Execute(); + return; + } + } + ErrorDelegate.Execute(Error); + }); } void FInAppWalletHandle::LinkSiwe(const FInAppWalletHandle& Wallet, const FString& Payload, const FString& Signature, - const FStreamableDelegate& SuccessDelegate, const FStringDelegate& ErrorDelegate) + const FStreamableDelegate& SuccessDelegate, const FStringDelegate& ErrorDelegate) { CHECK_DELEGATES(SuccessDelegate, ErrorDelegate) CHECK_VALIDITY(ErrorDelegate) @@ -740,20 +799,24 @@ void FInAppWalletHandle::LinkSiwe(const FInAppWalletHandle& Wallet, const FStrin FInAppWalletHandle ThisCopy = *this; UE::Tasks::Launch(UE_SOURCE_LOCATION, - [ThisCopy, Wallet, Payload, Signature, SuccessDelegate, ErrorDelegate] { - FString Error; - if (Thirdweb::ecosystem_wallet_link_account(ThisCopy.GetID(), Wallet.GetID(), nullptr, nullptr, nullptr, nullptr, - nullptr, TO_RUST_STRING(Signature), TO_RUST_STRING(Payload)) - .AssignResult(Error, true)) - { - SuccessDelegate.Execute(); - return; - } - ErrorDelegate.Execute(Error); - }); + [ThisCopy, Wallet, Payload, Signature, SuccessDelegate, ErrorDelegate] + { + FString Error; + if (Thirdweb::ecosystem_wallet_link_account(ThisCopy.GetID(), Wallet.GetID(), nullptr, + nullptr, nullptr, nullptr, + nullptr, TO_RUST_STRING(Signature), + TO_RUST_STRING(Payload)) + .AssignResult(Error, true)) + { + SuccessDelegate.Execute(); + return; + } + ErrorDelegate.Execute(Error); + }); } -void FInAppWalletHandle::GetLinkedAccounts(const FGetLinkedAccountsDelegate& SuccessDelegate, const FStringDelegate& ErrorDelegate) +void FInAppWalletHandle::GetLinkedAccounts(const FGetLinkedAccountsDelegate& SuccessDelegate, + const FStringDelegate& ErrorDelegate) { CHECK_DELEGATES(SuccessDelegate, ErrorDelegate) CHECK_VALIDITY(ErrorDelegate) @@ -761,32 +824,36 @@ void FInAppWalletHandle::GetLinkedAccounts(const FGetLinkedAccountsDelegate& Suc FInAppWalletHandle ThisCopy = *this; UE::Tasks::Launch(UE_SOURCE_LOCATION, - [ThisCopy, SuccessDelegate, ErrorDelegate] { - FString Output; - if (Thirdweb::ecosystem_wallet_get_linked_accounts(ThisCopy.GetID()).AssignResult(Output)) - { - TArray LinkedAccounts; - TArray> JsonValueArray = ThirdwebUtils::Json::ToJsonArray(Output); - for (int i = 0; i < JsonValueArray.Num(); i++) - { - if (JsonValueArray[i]->Type == EJson::Object) - { - LinkedAccounts.Emplace(FThirdwebLinkedAccount::FromJson(JsonValueArray[i]->AsObject())); - } - } - SuccessDelegate.Execute(LinkedAccounts); - return; - } - ErrorDelegate.Execute(Output); - }); + [ThisCopy, SuccessDelegate, ErrorDelegate] + { + FString Output; + if (Thirdweb::ecosystem_wallet_get_linked_accounts(ThisCopy.GetID()).AssignResult(Output)) + { + TArray LinkedAccounts; + TArray> JsonValueArray = ThirdwebUtils::Json::ToJsonArray(Output); + for (int i = 0; i < JsonValueArray.Num(); i++) + { + if (JsonValueArray[i]->Type == EJson::Object) + { + LinkedAccounts.Emplace( + FThirdwebLinkedAccount::FromJson(JsonValueArray[i]->AsObject())); + } + } + SuccessDelegate.Execute(LinkedAccounts); + return; + } + ErrorDelegate.Execute(Output); + }); } FString FInAppWalletHandle::GetDisplayName() const { - return IsValid() ? FString::Printf(TEXT("%sWallet::%s::%lld"), GetTypeString(), - Source == OAuthProvider - ? *FString::Printf(TEXT("%s::%s"), GetSourceString(), *ThirdwebUtils::ToString(Provider)) - : GetSourceString(), - ID) - : TEXT("InAppWallet::INVALID"); + return IsValid() + ? FString::Printf(TEXT("%sWallet::%s::%lld"), GetTypeString(), + Source == OAuthProvider + ? *FString::Printf(TEXT("%s::%s"), GetSourceString(), + *ThirdwebUtils::ToString(Provider)) + : GetSourceString(), + ID) + : TEXT("InAppWallet::INVALID"); } diff --git a/Source/Thirdweb/Public/Thirdweb.h b/Source/Thirdweb/Public/Thirdweb.h index 7846d84..0fedf29 100644 --- a/Source/Thirdweb/Public/Thirdweb.h +++ b/Source/Thirdweb/Public/Thirdweb.h @@ -18,7 +18,7 @@ namespace Thirdweb { struct FFIResult { - bool success; + bool success; const char* message; // Assign's result to variables and then frees the underlying FFIResult @@ -31,69 +31,75 @@ namespace Thirdweb FString GetOutput() const; }; - extern "C" - { - // Private Key Wallet Methods - - FFIResult create_private_key_wallet(const char* private_key); - FFIResult generate_private_key_wallet(); - FFIResult private_key_wallet_export(uintptr_t handle_id); - - // In-App & Ecosystem Wallet Methods (In-App is now an Ecosystem Wallet without an ecosystem ID and partner ID) - - FFIResult create_ecosystem_wallet(const char* ecosystem_id, const char* ecosystem_partner_id, const char* client_id, - const char* bundle_id, const char* secret_key, const char* email, const char* phone, const char* storage_directory_path, - const char* auth_provider, const char* legacy_encryption_key); - FFIResult ecosystem_wallet_send_otp_email(uintptr_t handle_id); - FFIResult ecosystem_wallet_sign_in_with_otp_email(uintptr_t handle_id, const char* otp); - FFIResult ecosystem_wallet_send_otp_phone(uintptr_t handle_id); - FFIResult ecosystem_wallet_sign_in_with_otp_phone(uintptr_t handle_id, const char* otp); - FFIResult ecosystem_wallet_fetch_oauth_login_link(uintptr_t handle_id, const char* redirect_url); - FFIResult ecosystem_wallet_sign_in_with_oauth(uintptr_t handle_id, const char* auth_result); - FFIResult ecosystem_wallet_sign_in_with_jwt(uintptr_t handle_id, const char* jwt); - FFIResult ecosystem_wallet_sign_in_with_auth_endpoint(uintptr_t handle_id, const char* payload); - FFIResult ecosystem_wallet_sign_in_with_siwe(uintptr_t handle_id, const char* payload, const char* signature); - - FFIResult ecosystem_wallet_sign_in_with_guest(uintptr_t handle_id, const char* session_id); - FFIResult ecosystem_wallet_link_account(uintptr_t handle_id, uintptr_t wallet_to_link_handle_id, const char* otp, - const char* oauth_result, const char* jwt, const char* payload, const char* session_id, const char* siwe_payload, - const char* siwe_signature); - - FFIResult ecosystem_wallet_get_linked_accounts(uintptr_t handle_id); - - // Smart Wallet Methods - - FFIResult create_smart_wallet(const char* client_id, const char* bundle_id, const char* secret_key, - uintptr_t personal_wallet_handle_id, const char* chain_id, bool gasless, const char* factory, const char* account_override); - FFIResult smart_wallet_is_deployed(uintptr_t handle_id); - FFIResult smart_wallet_get_all_admins(uintptr_t handle_id); - FFIResult smart_wallet_get_all_active_signers(uintptr_t handle_id); - FFIResult smart_wallet_create_session_key(uintptr_t handle_id, const char* signer_address, const char* const* approved_targets, - uintptr_t approved_targets_count, const char* native_token_limit_per_transaction_in_wei, - uint64_t permission_start_timestamp, uint64_t permission_end_timestamp, uint64_t req_validity_start_timestamp, - uint64_t req_validity_end_timestamp); - FFIResult smart_wallet_revoke_session_key(uintptr_t handle_id, const char* signer_address); - FFIResult smart_wallet_add_admin(uintptr_t handle_id, const char* signer_address); - FFIResult smart_wallet_remove_admin(uintptr_t handle_id, const char* signer_address); - - // Shared Wallet Methods - - FFIResult get_wallet_address(uintptr_t handle_id); - FFIResult sign_message(uintptr_t handle_id, const char* message); - FFIResult is_connected(uintptr_t handle_id); - FFIResult disconnect(uintptr_t handle_id); - - // Utility Methods - - void free_ffi_result(FFIResult result); - void free_wallet(uintptr_t handle_id); - void free_string(char* s); - FFIResult get_unix_timestamp_now(); - FFIResult get_unix_timestamp_in_ten_years(); - FFIResult is_valid_address(const char* address, bool check_checksum); - FFIResult to_checksummed_address(const char* address); - FFIResult is_valid_private_key(const char* private_key); - FFIResult compute_client_id_from_secret_key(const char* secret_key); + extern "C" { + + + // Private Key Wallet Methods + + FFIResult create_private_key_wallet(const char* private_key); + FFIResult generate_private_key_wallet(); + FFIResult private_key_wallet_export(uintptr_t handle_id); + + // In-App & Ecosystem Wallet Methods (In-App is now an Ecosystem Wallet without an ecosystem ID and partner ID) + + FFIResult create_ecosystem_wallet(const char* ecosystem_id, const char* ecosystem_partner_id, const char* client_id, + const char* bundle_id, const char* secret_key, const char* email, + const char* phone, const char* storage_directory_path, + const char* auth_provider, const char* legacy_encryption_key); + FFIResult ecosystem_wallet_send_otp_email(uintptr_t handle_id); + FFIResult ecosystem_wallet_sign_in_with_otp_email(uintptr_t handle_id, const char* otp); + FFIResult ecosystem_wallet_send_otp_phone(uintptr_t handle_id); + FFIResult ecosystem_wallet_sign_in_with_otp_phone(uintptr_t handle_id, const char* otp); + FFIResult ecosystem_wallet_fetch_oauth_login_link(uintptr_t handle_id, const char* redirect_url); + FFIResult ecosystem_wallet_sign_in_with_oauth(uintptr_t handle_id, const char* auth_result); + FFIResult ecosystem_wallet_sign_in_with_jwt(uintptr_t handle_id, const char* jwt); + FFIResult ecosystem_wallet_sign_in_with_auth_endpoint(uintptr_t handle_id, const char* payload); + FFIResult ecosystem_wallet_sign_in_with_siwe(uintptr_t handle_id, const char* payload, const char* signature); + + FFIResult ecosystem_wallet_sign_in_with_guest(uintptr_t handle_id, const char* session_id); + FFIResult ecosystem_wallet_link_account(uintptr_t handle_id, uintptr_t wallet_to_link_handle_id, const char* otp, + const char* oauth_result, const char* jwt, const char* payload, + const char* session_id, const char* siwe_payload, + const char* siwe_signature); + + FFIResult ecosystem_wallet_get_linked_accounts(uintptr_t handle_id); + + // Smart Wallet Methods + + FFIResult create_smart_wallet(const char* client_id, const char* bundle_id, const char* secret_key, + uintptr_t personal_wallet_handle_id, const char* chain_id, bool gasless, + const char* factory, const char* account_override); + FFIResult smart_wallet_is_deployed(uintptr_t handle_id); + FFIResult smart_wallet_get_all_admins(uintptr_t handle_id); + FFIResult smart_wallet_get_all_active_signers(uintptr_t handle_id); + FFIResult smart_wallet_create_session_key(uintptr_t handle_id, const char* signer_address, + const char* const* approved_targets, + uintptr_t approved_targets_count, + const char* native_token_limit_per_transaction_in_wei, + uint64_t permission_start_timestamp, uint64_t permission_end_timestamp, + uint64_t req_validity_start_timestamp, + uint64_t req_validity_end_timestamp); + FFIResult smart_wallet_revoke_session_key(uintptr_t handle_id, const char* signer_address); + FFIResult smart_wallet_add_admin(uintptr_t handle_id, const char* signer_address); + FFIResult smart_wallet_remove_admin(uintptr_t handle_id, const char* signer_address); + + // Shared Wallet Methods + + FFIResult get_wallet_address(uintptr_t handle_id); + FFIResult sign_message(uintptr_t handle_id, const char* message); + FFIResult is_connected(uintptr_t handle_id); + FFIResult disconnect(uintptr_t handle_id); + + // Utility Methods + + void free_ffi_result(FFIResult result); + void free_wallet(uintptr_t handle_id); + void free_string(char* s); + FFIResult get_unix_timestamp_now(); + FFIResult get_unix_timestamp_in_ten_years(); + FFIResult is_valid_address(const char* address, bool check_checksum); + FFIResult to_checksummed_address(const char* address); + FFIResult is_valid_private_key(const char* private_key); + FFIResult compute_client_id_from_secret_key(const char* secret_key); } // extern c - } // namespace Thirdweb