Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions Assets/Thirdweb/Core/Plugin/thirdweb.jslib
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,75 @@ var plugin = {
dynCall_viii(cb, idPtr, null, buffer);
});
},
ThirdwebSmartWalletAddAdmin: async function (taskId, admin, cb) {
// convert taskId from pointer to str and allocate it to keep in memory
var id = UTF8ToString(taskId);
var idSize = lengthBytesUTF8(id) + 1;
var idPtr = _malloc(idSize);
stringToUTF8(id, idPtr, idSize);
// execute bridge call
window.bridge
.smartWalletAddAdmin(UTF8ToString(admin))
.then((returnStr) => {
var bufferSize = lengthBytesUTF8(returnStr) + 1;
var buffer = _malloc(bufferSize);
stringToUTF8(returnStr, buffer, bufferSize);
dynCall_viii(cb, idPtr, buffer, null);
})
.catch((err) => {
var msg = err.message;
var bufferSize = lengthBytesUTF8(msg) + 1;
var buffer = _malloc(bufferSize);
stringToUTF8(msg, buffer, bufferSize);
dynCall_viii(cb, idPtr, null, buffer);
});
},
ThirdwebSmartWalletRemoveAdmin: async function (taskId, admin, cb) {
// convert taskId from pointer to str and allocate it to keep in memory
var id = UTF8ToString(taskId);
var idSize = lengthBytesUTF8(id) + 1;
var idPtr = _malloc(idSize);
stringToUTF8(id, idPtr, idSize);
// execute bridge call
window.bridge
.smartWalletRemoveAdmin(UTF8ToString(admin))
.then((returnStr) => {
var bufferSize = lengthBytesUTF8(returnStr) + 1;
var buffer = _malloc(bufferSize);
stringToUTF8(returnStr, buffer, bufferSize);
dynCall_viii(cb, idPtr, buffer, null);
})
.catch((err) => {
var msg = err.message;
var bufferSize = lengthBytesUTF8(msg) + 1;
var buffer = _malloc(bufferSize);
stringToUTF8(msg, buffer, bufferSize);
dynCall_viii(cb, idPtr, null, buffer);
});
},
ThirdwebSmartWalletCreateSessionKey: async function (taskId, options, cb) {
// convert taskId from pointer to str and allocate it to keep in memory
var id = UTF8ToString(taskId);
var idSize = lengthBytesUTF8(id) + 1;
var idPtr = _malloc(idSize);
stringToUTF8(id, idPtr, idSize);
// execute bridge call
window.bridge
.smartWalletCreateSessionKey(UTF8ToString(options))
.then((returnStr) => {
var bufferSize = lengthBytesUTF8(returnStr) + 1;
var buffer = _malloc(bufferSize);
stringToUTF8(returnStr, buffer, bufferSize);
dynCall_viii(cb, idPtr, buffer, null);
})
.catch((err) => {
var msg = err.message;
var bufferSize = lengthBytesUTF8(msg) + 1;
var buffer = _malloc(bufferSize);
stringToUTF8(msg, buffer, bufferSize);
dynCall_viii(cb, idPtr, null, buffer);
});
},
};

mergeInto(LibraryManager.library, plugin);
57 changes: 57 additions & 0 deletions Assets/Thirdweb/Core/Scripts/Bridge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,57 @@ public static async Task<string> ExportWallet(string password)
return result;
}

public static async Task<T> SmartWalletAddAdmin<T>(string admin)
{
if (!Utils.IsWebGLBuild())
{
ThirdwebDebug.LogWarning("Interacting with the thirdweb SDK is not fully supported in the editor.");
return default;
}
string taskId = Guid.NewGuid().ToString();
var task = new TaskCompletionSource<string>();
taskMap[taskId] = task;
#if UNITY_WEBGL
ThirdwebSmartWalletAddAdmin(taskId, admin, jsCallback);
#endif
string result = await task.Task;
return JsonConvert.DeserializeObject<Result<T>>(result).result;
}

public static async Task<T> SmartWalletRemoveAdmin<T>(string admin)
{
if (!Utils.IsWebGLBuild())
{
ThirdwebDebug.LogWarning("Interacting with the thirdweb SDK is not fully supported in the editor.");
return default;
}
string taskId = Guid.NewGuid().ToString();
var task = new TaskCompletionSource<string>();
taskMap[taskId] = task;
#if UNITY_WEBGL
ThirdwebSmartWalletRemoveAdmin(taskId, admin, jsCallback);
#endif
string result = await task.Task;
return JsonConvert.DeserializeObject<Result<T>>(result).result;
}

public static async Task<T> SmartWalletCreateSessionKey<T>(string options)
{
if (!Utils.IsWebGLBuild())
{
ThirdwebDebug.LogWarning("Interacting with the thirdweb SDK is not fully supported in the editor.");
return default;
}
string taskId = Guid.NewGuid().ToString();
var task = new TaskCompletionSource<string>();
taskMap[taskId] = task;
#if UNITY_WEBGL
ThirdwebSmartWalletCreateSessionKey(taskId, options, jsCallback);
#endif
string result = await task.Task;
return JsonConvert.DeserializeObject<Result<T>>(result).result;
}

#if UNITY_WEBGL
[DllImport("__Internal")]
private static extern string ThirdwebInvoke(string taskId, string route, string payload, Action<string, string, string> cb);
Expand All @@ -225,6 +276,12 @@ public static async Task<string> ExportWallet(string password)
private static extern string ThirdwebFundWallet(string taskId, string payload, Action<string, string, string> cb);
[DllImport("__Internal")]
private static extern string ThirdwebExportWallet(string taskId, string password, Action<string, string, string> cb);
[DllImport("__Internal")]
private static extern string ThirdwebSmartWalletAddAdmin(string taskId, string admin, Action<string, string, string> cb);
[DllImport("__Internal")]
private static extern string ThirdwebSmartWalletRemoveAdmin(string taskId, string admin, Action<string, string, string> cb);
[DllImport("__Internal")]
private static extern string ThirdwebSmartWalletCreateSessionKey(string taskId, string options, Action<string, string, string> cb);
#endif
}
}
20 changes: 17 additions & 3 deletions Assets/Thirdweb/Core/Scripts/Wallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Nethereum.Signer.EIP712;
using Newtonsoft.Json.Linq;
using Nethereum.Hex.HexTypes;
using Newtonsoft.Json;

namespace Thirdweb
{
Expand Down Expand Up @@ -476,7 +477,7 @@ public async Task<TransactionResult> AddAdmin(string admin)
{
if (Utils.IsWebGLBuild())
{
throw new UnityException("This functionality is not yet available on your current platform.");
return await Bridge.SmartWalletAddAdmin<TransactionResult>(admin);
}
else
{
Expand Down Expand Up @@ -510,7 +511,7 @@ public async Task<TransactionResult> RemoveAdmin(string admin)
{
if (Utils.IsWebGLBuild())
{
throw new UnityException("This functionality is not yet available on your current platform.");
return await Bridge.SmartWalletRemoveAdmin<TransactionResult>(admin);
}
else
{
Expand Down Expand Up @@ -558,7 +559,20 @@ string reqValidityEndTimestamp
{
if (Utils.IsWebGLBuild())
{
throw new UnityException("This functionality is not yet available on your current platform.");
return await Bridge.SmartWalletCreateSessionKey<TransactionResult>(
Utils.ToJson(
new
{
signerAddress,
approvedCallTargets = approvedTargets,
nativeTokenLimitPerTransactionInWei,
startDate = permissionStartTimestamp,
expirationDate = permissionEndTimestamp,
reqValidityStartTimestamp,
reqValidityEndTimestamp
}
)
);
}
else
{
Expand Down
347,686 changes: 347,322 additions & 364 deletions Assets/WebGLTemplates/Thirdweb/lib/thirdweb-unity-bridge.js

Large diffs are not rendered by default.