Skip to content
Open
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
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"visualstudiotoolsforunity.vstuc"
]
}
10 changes: 10 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach to Unity",
"type": "vstuc",
"request": "attach"
}
]
}
70 changes: 70 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"files.exclude": {
"**/.DS_Store": true,
"**/.git": true,
"**/.vs": true,
"**/.gitmodules": true,
"**/.vsconfig": true,
"**/*.booproj": true,
"**/*.pidb": true,
"**/*.suo": true,
"**/*.user": true,
"**/*.userprefs": true,
"**/*.unityproj": true,
"**/*.dll": true,
"**/*.exe": true,
"**/*.pdf": true,
"**/*.mid": true,
"**/*.midi": true,
"**/*.wav": true,
"**/*.gif": true,
"**/*.ico": true,
"**/*.jpg": true,
"**/*.jpeg": true,
"**/*.png": true,
"**/*.psd": true,
"**/*.tga": true,
"**/*.tif": true,
"**/*.tiff": true,
"**/*.3ds": true,
"**/*.3DS": true,
"**/*.fbx": true,
"**/*.FBX": true,
"**/*.lxo": true,
"**/*.LXO": true,
"**/*.ma": true,
"**/*.MA": true,
"**/*.obj": true,
"**/*.OBJ": true,
"**/*.asset": true,
"**/*.cubemap": true,
"**/*.flare": true,
"**/*.mat": true,
"**/*.meta": true,
"**/*.prefab": true,
"**/*.unity": true,
"build/": true,
"Build/": true,
"Library/": true,
"library/": true,
"obj/": true,
"Obj/": true,
"Logs/": true,
"logs/": true,
"ProjectSettings/": true,
"UserSettings/": true,
"temp/": true,
"Temp/": true
},
"files.associations": {
"*.asset": "yaml",
"*.meta": "yaml",
"*.prefab": "yaml",
"*.unity": "yaml",
},
"explorer.fileNesting.enabled": true,
"explorer.fileNesting.patterns": {
"*.sln": "*.csproj",
},
"dotnet.defaultSolution": "Sui-Unity-SDK.sln"
}
17 changes: 14 additions & 3 deletions Assets/Sui-Unity-SDK/Code/Sui.Seal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,21 @@ SealBridge.Instance.SetServerObjectIds(
### 2. Encrypt/Decrypt data

Encrypt the given plaintext for a specific Sui address.
Returns a TransactionBlock ready to be signed and executed on-chain.
Returns an EncryptionResult containing encrypted bytes and nonce for transaction construction.
<pre><code class="language-csharp">
var tx = await SealBridge.Instance.Encrypt("my secret text", suiAddress);
await suiClient.SignAndExecuteTransactionBlock(tx);
EncryptionResult result = await SealBridge.Instance.Encrypt("my secret text", suiAddress);
TransactionBlock tx_block = new TransactionBlock();
tx_block.AddMoveCallTx
(
SuiMoveNormalizedStructType.FromStr($"{_packageId}::{_moduleName}::{_funcName}"),
new SerializableTypeTag[] { },
new TransactionArgument[]
{
tx_block.AddPure(new OpenDive.BCS.Bytes(encryptionResult.NonceBytes)),
tx_block.AddPure(new OpenDive.BCS.Bytes(encryptionResult.EncryptedBytes))
}
);
await suiClient.SignAndExecuteTransactionBlock(tx_block);
</code></pre>

Decrypt the encrypted payload using a standard private key.
Expand Down
44 changes: 24 additions & 20 deletions Assets/Sui-Unity-SDK/Code/Sui.Seal/Scripts/SealBridge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ public void SetPackageInformation(string packageId, string moduleName, string fu
/// </summary>
/// <param name="data">The plaintext data to encrypt.</param>
/// <param name="suiAddressHex">The Sui address in hexadecimal format.</param>
/// <returns>A <see cref="TransactionBlock"/> containing encrypted data ready for submission.</returns>
public async Task<TransactionBlock> Encrypt(string data, string suiAddressHex)
/// <returns>An <see cref="EncryptionResult"/> containing encrypted bytes and nonce for transaction construction.</returns>
public async Task<EncryptionResult> Encrypt(string data, string suiAddressHex)
{
_canceled = false;
_encryptedBytes = null;
Expand All @@ -128,7 +128,7 @@ public async Task<TransactionBlock> Encrypt(string data, string suiAddressHex)
{
return null;
}
return PrepareTransactionBlock(_encryptedBytes, nonceBytes);
return new EncryptionResult(_encryptedBytes, nonceBytes);
}

/// <summary>
Expand Down Expand Up @@ -243,27 +243,31 @@ void OnDecryptionCompleted(string decryptedObjectBase64)
}
_decryptedBytes = Convert.FromBase64String(decryptedObjectBase64);
}
}

/// <summary>
/// Result class containing encrypted data and nonce from Seal encryption process.
/// Users can use these values to construct their own TransactionBlock for their specific contract.
///
/// Author: viol3
/// </summary>
[System.Serializable]
public class EncryptionResult
{
/// <summary>
/// The encrypted data bytes.
/// </summary>
public byte[] EncryptedBytes { get; set; }

/// <summary>
/// Prepares a Sui transaction block to store encrypted Seal data on-chain.
/// The nonce bytes used during encryption.
/// </summary>
/// <param name="encryptedBytes">The encrypted payload bytes.</param>
/// <param name="nonceBytes">The nonce bytes used during encryption.</param>
/// <returns>Configured <see cref="TransactionBlock"/> ready for signing and execution.</returns>
TransactionBlock PrepareTransactionBlock(byte[] encryptedBytes, byte[] nonceBytes)
public byte[] NonceBytes { get; set; }

public EncryptionResult(byte[] encryptedBytes, byte[] nonceBytes)
{
TransactionBlock tx_block = new TransactionBlock();
tx_block.AddMoveCallTx
(
SuiMoveNormalizedStructType.FromStr($"{_packageId}::{_moduleName}::{_funcName}"),
new SerializableTypeTag[] { },
new TransactionArgument[]
{
tx_block.AddPure(new OpenDive.BCS.Bytes(nonceBytes)),
tx_block.AddPure(new OpenDive.BCS.Bytes(encryptedBytes))
}
);
return tx_block;
EncryptedBytes = encryptedBytes;
NonceBytes = nonceBytes;
}
}

Expand Down
19 changes: 16 additions & 3 deletions Assets/Sui-Unity-SDK/Samples/Seal/Scripts/SealSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Sui.Rpc.Client;
using Sui.Rpc.Models;
using Sui.Transactions;
using Sui.Types;
using System.Linq;
using System.Text;
using TMPro;
Expand All @@ -27,7 +28,7 @@ namespace Sui.Seal
public class SealSample : MonoBehaviour
{
/// <summary>
/// Demonstrates Seal encryption and decryption flows integrated with Unity�s UI system.
/// Demonstrates Seal encryption and decryption flows integrated with Unity�s UI system.
///
/// The class handles creating a testnet client, signing transactions with the current account,
/// and displaying results in the user interface.
Expand Down Expand Up @@ -79,8 +80,20 @@ void Start()
public async void OnEncryptButtonClick()
{
string dataToEncrypt = _encryptTextField.text;
TransactionBlock txBlock = await SealBridge.Instance.Encrypt(dataToEncrypt, _account.SuiAddress().ToHex());
await _client.SignAndExecuteTransactionBlockAsync(txBlock, _account);
EncryptionResult encryptionResult = await SealBridge.Instance.Encrypt(dataToEncrypt, _account.SuiAddress().ToHex());

TransactionBlock tx_block = new TransactionBlock();
tx_block.AddMoveCallTx
(
SuiMoveNormalizedStructType.FromStr($"{_packageId}::{_moduleName}::{_funcName}"),
new SerializableTypeTag[] { },
new TransactionArgument[]
{
tx_block.AddPure(new OpenDive.BCS.Bytes(encryptionResult.NonceBytes)),
tx_block.AddPure(new OpenDive.BCS.Bytes(encryptionResult.EncryptedBytes))
}
);
await _client.SignAndExecuteTransactionBlockAsync(tx_block, _account);
_encryptedText.gameObject.SetActive(true);
}

Expand Down
16 changes: 14 additions & 2 deletions Assets/Sui-Unity-SDK/Samples/Seal/Scripts/SealZKLoginSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Sui.Rpc.Client;
using Sui.Rpc.Models;
using Sui.Transactions;
using Sui.Types;
using Sui.ZKLogin;
using Sui.ZKLogin.Enoki;
using Sui.ZKLogin.Enoki.Utils;
Expand Down Expand Up @@ -141,8 +142,19 @@ public async void OnLoginButtonClick()
public async void OnEncryptButtonClick()
{
string dataToEncrypt = _encryptTextField.text;
TransactionBlock txBlock = await SealBridge.Instance.Encrypt(dataToEncrypt, EnokiZKLogin.GetSuiAddress());
await EnokiZKLogin.SignAndExecuteTransactionBlock(txBlock);
EncryptionResult encryptionResult = await SealBridge.Instance.Encrypt(dataToEncrypt, EnokiZKLogin.GetSuiAddress());
TransactionBlock tx_block = new TransactionBlock();
tx_block.AddMoveCallTx
(
SuiMoveNormalizedStructType.FromStr($"{_packageId}::{_moduleName}::{_funcName}"),
new SerializableTypeTag[] { },
new TransactionArgument[]
{
tx_block.AddPure(new OpenDive.BCS.Bytes(encryptionResult.NonceBytes)),
tx_block.AddPure(new OpenDive.BCS.Bytes(encryptionResult.EncryptedBytes))
}
);
await EnokiZKLogin.SignAndExecuteTransactionBlock(tx_block);
_encryptedText.gameObject.SetActive(true);
}

Expand Down
8 changes: 0 additions & 8 deletions Assets/Sui-Unity-SDK/WebGLTemplates/0-Default-Hyper.meta

This file was deleted.

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

Loading