这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ea790be
checkpoint, IWalletProvider abstracted for web3auth but only signing …
rob1997 Jul 4, 2024
23a7da2
fixed send transaction
rob1997 Jul 4, 2024
f7a4bba
fixed signing
rob1997 Jul 4, 2024
9f88fe3
cleanup and docs
rob1997 Jul 5, 2024
93fd5b3
made requested changes
rob1997 Jul 5, 2024
ad14375
fixed WebGL issue with web3auth
rob1997 Jul 6, 2024
5e10cfb
checkpoint
rob1997 Jul 8, 2024
68fa2af
colors updated
rob1997 Jul 9, 2024
92a092b
checkpoint
rob1997 Jul 9, 2024
7132734
checkpoint
rob1997 Jul 9, 2024
540dc0e
checkpoint
rob1997 Jul 10, 2024
3d7da3b
editor code improved and added WC as a provider
rob1997 Jul 10, 2024
5370b57
meta file bug fix
rob1997 Jul 10, 2024
e818776
use resources instead of json to fetch providers, much nicer this way
rob1997 Jul 10, 2024
c8b7c03
font changed
rob1997 Jul 11, 2024
69ca0c3
checkpoint, web3auth modal initial run
rob1997 Jul 11, 2024
1ca6053
conflicts from dev
rob1997 Jul 11, 2024
ee7cf1d
Merge branch 'dev' into rob/wallet-prefab-connection-1014
rob1997 Jul 11, 2024
0a7b906
fixed some compile errors from merge
rob1997 Jul 11, 2024
35cf47f
revert from merge
rob1997 Jul 11, 2024
6c65e64
checkpoint
rob1997 Jul 12, 2024
71c8fd0
Web3Auth working (not WebGL)
rob1997 Jul 12, 2024
192c13a
working web3auth WebGL Modal
rob1997 Jul 16, 2024
bb4aa19
build error fix
rob1997 Jul 16, 2024
2792773
Merge branch 'dev' into rob/wallet-prefab-connection-1014
rob1997 Jul 17, 2024
6885e8f
documentation and namespace changes
rob1997 Jul 17, 2024
cff0b03
Merge branch 'dev' into rob/wallet-prefab-connection-1014
juans-chainsafe Jul 17, 2024
c9c8388
Merge branch 'dev' into rob/wallet-prefab-connection-1014
rob1997 Jul 17, 2024
eb75c7e
compile error fix
rob1997 Jul 17, 2024
8110fb5
HyperPlay platform fix and added Connect Modal scene to build settings
rob1997 Jul 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 1272c3d1812e95e408d945d25da049bb, type: 3}
m_Name: HyperPlayConnectionProviderConfig
m_EditorClassIdentifier:
<Name>k__BackingField: HyperPlay
<ProviderRow>k__BackingField: {fileID: 1727169539746137890, guid: 71b112e16f898d140935553a4b33ae1f, type: 3}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System.Threading.Tasks;
using ChainSafe.Gaming.UnityPackage.Connection;
using ChainSafe.Gaming.Web3.Build;
using ChainSafe.Gaming.Web3.Evm.Wallet;
using UnityEngine;

namespace ChainSafe.Gaming.HyperPlay
{
/// <summary>
/// Connection provider for connecting via HyperPlay Launcher.
/// </summary>
public class HyperPlayConnectionProvider : ConnectionProvider
{
public override bool IsAvailable => Application.isEditor || !Application.isMobilePlatform;

public override Task Initialize()
{
return Task.CompletedTask;
}

public override Web3Builder ConfigureServices(Web3Builder web3Builder)
{
return web3Builder.Configure(services =>
{
var config = new HyperPlayConfig
{
// RememberSession = rememberMeToggle.isOn || _storedSessionAvailable,
};
#if UNITY_WEBGL && !UNITY_EDITOR
services.UseHyperPlay<HyperPlayWebGLProvider>(config);
#else
services.UseHyperPlay(config);
#endif
services.UseWalletSigner().UseWalletTransactionExecutor();
});
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using ChainSafe.Gaming.UnityPackage.Common;
using ChainSafe.Gaming.UnityPackage.Connection;
using ChainSafe.Gaming.Web3.Build;
using UnityEngine;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
var Web3AuthWebGLNoModal = {
$Web3AuthWebGLNoModal : {},

SetLoginCallback: function (login) {
Web3AuthWebGLNoModal.loginCallback = function(sessionId){
var returnStr = sessionId;
var bufferSize = lengthBytesUTF8(returnStr) + 1;
var buffer = _malloc(bufferSize);
stringToUTF8(returnStr, buffer, bufferSize);
Module.dynCall_vi(login, [buffer]);
};
},
InitWeb3Auth: function (clientId, chainId, rpcTarget, displayName, blockExplorerUrl, ticker, tickerName, network) {
InitWeb3Auth: function (clientId, chainId, rpcTarget, displayName, blockExplorerUrl, ticker, tickerName, network, callback, fallback) {

window.web3auth = null;
window.walletServicesPlugin = null;



(async function init() {
try {
Expand Down Expand Up @@ -53,23 +43,39 @@ var Web3AuthWebGLNoModal = {
window.web3auth.configureAdapter(openloginAdapter);

await window.web3auth.init();
console.log("Web3Auth Initialized Successfully!");

Module.dynCall_v(callback);
} catch (error) {
console.error("Error during Web3Auth initialization:", error);
var stringToReturn = error.message;
var bufferSize = lengthBytesUTF8(stringToReturn) + 1;
var buffer = _malloc(bufferSize);
stringToUTF8(stringToReturn, buffer, bufferSize);
Module.dynCall_vi(fallback, [buffer]);
}
})();
},

Web3AuthLogin: async function (provider, rememberMe) {
Web3AuthLogin: async function (provider, rememberMe, callback, fallback) {
try {
Web3AuthWebGLNoModal.loginCallback = function(sessionId){
var bufferSize = lengthBytesUTF8(sessionId) + 1;
var buffer = _malloc(bufferSize);
stringToUTF8(sessionId, buffer, bufferSize);
Module.dynCall_vi(callback, [buffer]);
};

await window.web3auth.connectTo("openlogin", {
loginProvider: UTF8ToString(provider)
});
if (!rememberMe){
localStorage.removeItem("openlogin_store");
}
} catch (error) {
console.log(error.message);
var stringToReturn = error.message;
var bufferSize = lengthBytesUTF8(error.message) + 1;
var buffer = _malloc(bufferSize);
stringToUTF8(stringToReturn, buffer, bufferSize);
Module.dynCall_vi(fallback, [buffer]);
}
},
};
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 1272c3d1812e95e408d945d25da049bb, type: 3}
m_Name: Web3AuthConnectionProviderConfig
m_EditorClassIdentifier:
<Name>k__BackingField: Web3Auth
<ProviderRow>k__BackingField: {fileID: 8841964981256285308, guid: 163bbaaeb51883442a20ea7532888a43, type: 3}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
using System;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using AOT;
using ChainSafe.Gaming;
using ChainSafe.Gaming.UnityPackage;
using ChainSafe.Gaming.UnityPackage.Connection;
using ChainSafe.Gaming.Web3;
using ChainSafe.Gaming.Web3.Build;
using ChainSafe.GamingSdk.Web3Auth;
using Nethereum.Hex.HexTypes;
using UnityEngine;
using Network = Web3Auth.Network;

/// <summary>
/// ConnectionProvider for connecting wallet via Web3Auth.
/// </summary>
public class Web3AuthConnectionProvider : ConnectionProvider
{
[SerializeField] private string clientId;
[SerializeField] private string redirectUri;
[SerializeField] private Network network;

[Space]

[SerializeField] public GameObject modalPrefab;

private Web3AuthModal _modal;

public override bool IsAvailable => true;

#if UNITY_WEBGL && !UNITY_EDITOR

private TaskCompletionSource<string> _initializeTcs;

private TaskCompletionSource<string> _connectionTcs;

[DllImport("__Internal")]
private static extern void InitWeb3Auth(string clientId, string chainId, string rpcTarget, string displayName, string blockExplorerUrl, string ticker, string tickerName, string network, Action callback, Action<string> fallback);

[DllImport("__Internal")]
private static extern void Web3AuthLogin(string provider, bool rememberMe, Action<string> callback, Action<string> fallback);

private static Web3AuthConnectionProvider _instance;

private void Awake()
{
_instance = this;
}

public override async Task Initialize()
{
_initializeTcs = new TaskCompletionSource<string>();

var projectConfig = ProjectConfigUtilities.Load();

//1155 is a decimal number, we need to convert it to an integer
InitWeb3Auth(clientId, new HexBigInteger(BigInteger.Parse(projectConfig.ChainId)).HexValue,
projectConfig.Rpc, projectConfig.Network, "", projectConfig.Symbol, "", network.ToString().ToLower(), Initialized, InitializeError);

await _initializeTcs.Task;

Debug.Log("Web3Auth Initialized Successfully.");

// Don't allow connection before initialization.
ConnectButton.interactable = true;
}
#else
public override Task Initialize()
{
ConnectButton.interactable = true;

return Task.CompletedTask;
}
#endif

public override Web3Builder ConfigureServices(Web3Builder web3Builder)
{
DisplayModal();

return web3Builder.Configure(services =>
{
var web3AuthConfig = new Web3AuthWalletConfig
{
Web3AuthOptions = new()
{
clientId = clientId,
redirectUrl = new Uri(redirectUri),
network = network,
whiteLabel = new()
{
mode = Web3Auth.ThemeModes.dark,
defaultLanguage = Web3Auth.Language.en,
appName = "ChainSafe Gaming SDK",
}
},
// RememberMe = rememberMe
};

web3AuthConfig.CancellationToken = _modal.CancellationToken;

web3AuthConfig.ProviderTask = _modal.SelectProvider();

#if UNITY_WEBGL && !UNITY_EDITOR
web3AuthConfig.CancellationToken.Register(delegate
{
if (_connectionTcs != null && !_connectionTcs.Task.IsCompleted)
{
_connectionTcs.SetCanceled();
}
});

web3AuthConfig.SessionTask = Connect();
#endif

services.UseWeb3AuthWallet(web3AuthConfig);
});
}

public override void HandleException(Exception exception)
{
_modal.Close();

base.HandleException(exception);
}

private void DisplayModal()
{
if (_modal != null)
{
_modal.gameObject.SetActive(true);
}

else
{
var obj = Instantiate(modalPrefab);

_modal = obj.GetComponentInChildren<Web3AuthModal>();
}
}

#if UNITY_WEBGL && !UNITY_EDITOR

[MonoPInvokeCallback(typeof(Action))]
private static void Initialized()
{
_instance._initializeTcs.SetResult(string.Empty);
}

[MonoPInvokeCallback(typeof(Action<string>))]
private static void InitializeError(string message)
{
_instance._initializeTcs.SetException(new Web3Exception(message));
}

private async Task<string> Connect()
{
if (_connectionTcs != null && !_connectionTcs.Task.IsCompleted)
{
_connectionTcs.SetCanceled();
}

_connectionTcs = new TaskCompletionSource<string>();

var provider = await _modal.SelectProvider();

Web3AuthLogin(provider.ToString().ToLower(), false, Connected, ConnectError);

return await _connectionTcs.Task;
}

[MonoPInvokeCallback(typeof(Action<string>))]
private static void Connected(string sessionId)
{
_instance._connectionTcs.SetResult(sessionId);
}

[MonoPInvokeCallback(typeof(Action<string>))]
private static void ConnectError(string message)
{
_instance._connectionTcs.SetException(new Web3Exception(message));
}
#endif
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading