Skip to content

Commit 75d7b28

Browse files
authored
Update README.MD
1 parent 000dad3 commit 75d7b28

1 file changed

Lines changed: 201 additions & 10 deletions

File tree

README.MD

Lines changed: 201 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ This reflects the functionality already added to the library as well as that pla
2626
- [x] Sending Toncoin between wallets,
2727
- [x] Sending Jettons between wallets,
2828
- [x] Sending NFT items between wallets,
29+
- [x] Signing message with payload in wallets,
30+
- [x] Verifying the payload of a signed message,
2931
- [ ] Swapping Jettons to Toncoin and reverse,
3032
- [ ] Burning NFT items on a wallet,
3133
- [ ] Loading last successful transactions with Toncoin,
@@ -109,16 +111,18 @@ You can test the SDK without installation on a demo app [in your browser](https:
109111

110112
# SDK Interaction Types & Available Features
111113

112-
| Features | Client-Side | Client+Server-Side |
113-
| ---------------------------------------- | :----------: | :----------------: |
114-
| **Connecting TON Wallets** | ✔️ | ✔️ |
115-
| **Reading Toncoin balance** | ✔️ | ✔️ |
116-
| **Reading Jettons balance** || ✔️ |
117-
| **Reading NFT collections** || ✔️ |
118-
| **Sending Toncoin between wallets** | ✔️ | ✔️ |
119-
| **Sending Jettons between wallets** || ✔️ |
120-
| **Sending NFTs between wallets** || ✔️ |
121-
| **Loading Jettons transactions history** || ✔️ |
114+
| Features | Client-Side | Client+Server-Side |
115+
| --------------------------------------------- | :----------: | :----------------: |
116+
| **Connecting TON Wallets** | ✔️ | ✔️ |
117+
| **Reading Toncoin balance** | ✔️ | ✔️ |
118+
| **Reading Jettons balance** || ✔️ |
119+
| **Reading NFT collections** || ✔️ |
120+
| **Sending Toncoin between wallets** | ✔️ | ✔️ |
121+
| **Sending Jettons between wallets** || ✔️ |
122+
| **Sending NFTs between wallets** || ✔️ |
123+
| **Loading Jettons transactions history** || ✔️ |
124+
| **Signing message with payload** | ✔️ | ✔️ |
125+
| **Verifying the payload of a signed message** || ✔️ |
122126

123127
<sub>✔️ Supported</sub> &nbsp; <sub>❌ Not Supported</sub> &nbsp; <sub>⚠️ In progress</sub>
124128

@@ -915,6 +919,191 @@ _jettonWallet.GetLastTransactions(TransactionTypes.Received, 10,
915919

916920
**IMPORTANT:** The `QueryId` property is unique and is generated each time a payload is created for a transaction token. Thus, in addition to additional data in the form of `transaction hash`, `attached message`, it is also possible to check the successful sending status by it too.
917921

922+
### Sign data in wallet
923+
924+
Starting with `version 0.5.5`, the feature **to sign messages** within a connected wallet has been added.
925+
This functionality allows you to **verify the authenticity** of the wallet connection to your dApp, similar to the `TonProof` function.
926+
927+
Below is an example of how to use this option:
928+
929+
```c#
930+
public sealed class SignWalletMessageExample: MonoBehaviour
931+
{
932+
[SerializeField, Space] private Button _signButton;
933+
934+
private UnitonConnectSDK _unitonConnect;
935+
936+
private void OnDestroy()
937+
{
938+
_unitonConnect.OnWalletMessageSigned -= WalletMessageSigned;
939+
_unitonConnect.OnWalletMessageSignFailed -= WalletMessageSignFailed;
940+
}
941+
942+
private void Start()
943+
{
944+
_unitonConnect = UnitonConnectSDK.Instance;
945+
946+
_signButton.onClick.AddListener(Sign);
947+
948+
_unitonConnect.OnWalletMessageSigned += WalletMessageSigned;
949+
_unitonConnect.OnWalletMessageSignFailed += WalletMessageSignFailed;
950+
}
951+
952+
private void Sign()
953+
{
954+
// with readable text in the wallet
955+
var message = new SignMessageData(
956+
SignWalletDataTypes.text)
957+
{
958+
Text = "Message from Uniton Connect",
959+
From = _unitonConnect.Wallet.ToHex()
960+
};
961+
962+
// with binary data (the wallet will display a warning about unknown content)
963+
var message = new SignMessageData(
964+
SignWalletDataTypes.bytes)
965+
{
966+
Bytes = "1Z/SGh+3HFMKlVHSkN91DpcCzT4C5jzHT3sA/24C5A==",
967+
From = _unitonConnect.Wallet.ToHex()
968+
};
969+
970+
// with blockchain data in the form of a TL-B scheme (the wallet can display the data scheme if it is valid)
971+
var message = new SignMessageData(
972+
SignWalletDataTypes.cell)
973+
{
974+
Schema = "transfer#0f8a7ea5 query_id:uint64 amount:(VarUInteger 16) destination:MsgAddress response_destination:MsgAddress custom_payload:(Maybe ^Cell) forward_ton_amount:(VarUInteger 16) forward_payload:(Either Cell ^Cell) = InternalMsgBody;",
975+
Cell = "te6ccgEBAQEAVwAAqg+KfqVUbeTvKqB4h0AcnDgIAZucsOi6TLrfP6FcuPKEeTI6oB3fF/NBjyqtdov/KtutACCLqvfmyV9kH+Pyo5lcsrJzJDzjBJK6fd+ZnbFQe4+XggI=",
976+
From = _unitonConnect.Wallet.ToHex()
977+
};
978+
979+
_unitonConnect.SignData(message);
980+
}
981+
982+
private void WalletMessageSigned(
983+
SignedMessageData payload)
984+
{
985+
Debug.Log($"Wallet message successfully signed, " +
986+
$"payload: {JsonConvert.SerializeObject(payload)}"");
987+
}
988+
989+
private void WalletMessageSignFailed()
990+
{
991+
Debug.LogError($"Failed to sign wallet message, reason: '{errorMessage}'");
992+
}
993+
}
994+
```
995+
996+
After the message is successfully signed, a request will be sent to verify the signature and the validity of the data signature in it.
997+
998+
You can subscribe to the `OnWalletMessageVerified` event and get the signature status if you need it:
999+
1000+
```c#
1001+
private void Start()
1002+
{
1003+
_unitonSDK.OnWalletMessageVerified += WalletMessagePayloadVerified;
1004+
}
1005+
1006+
private void WalletMessagePayloadVerified(bool isVerified)
1007+
{
1008+
Debug.Log($"Signed wallet message verified with status '{isSuccess}'");
1009+
}
1010+
```
1011+
1012+
### Modal state
1013+
1014+
Starting with `version 0.5.5`, a feature **for loading the state** of the SDK modal window has been added.
1015+
1016+
```c#
1017+
public sealed class LoadModalStateExample: MonoBehaviour
1018+
{
1019+
[SerializeField, Space] private Button _loadButton;
1020+
1021+
private UnitonConnectSDK _unitonConnect;
1022+
1023+
private WalletModal _walletModal;
1024+
1025+
private void OnDestroy()
1026+
{
1027+
_unitonSDK.OnInitiliazed -= SdkInitialized;
1028+
1029+
_walletModal.OnStateClaimed -= ModalStateClaimed;
1030+
_walletModal.OnStateChanged -= ModalStateChanged;
1031+
}
1032+
1033+
private void Start()
1034+
{
1035+
_unitonConnect = UnitonConnectSDK.Instance;
1036+
1037+
_loadButton.onClick.AddListener(LoadState);
1038+
1039+
_unitonSDK.OnInitiliazed += SdkInitialized;
1040+
}
1041+
1042+
private void LoadState()
1043+
{
1044+
_walletModal.LoadStatus();
1045+
}
1046+
1047+
private void SdkInitialized(bool isSuccess)
1048+
{
1049+
if (!isSuccess)
1050+
{
1051+
return;
1052+
}
1053+
1054+
_walletModal = _unitonConnect.Modal;
1055+
1056+
_walletModal.OnStateClaimed += ModalStateClaimed;
1057+
_walletModal.OnStateChanged += ModalStateChanged;
1058+
}
1059+
1060+
private void ModalStateClaimed(ModalStatusTypes state)
1061+
{
1062+
Debug.Log("Loaded current modal state '{state}'");
1063+
}
1064+
1065+
private void ModalStateChanged(ModalStatusTypes state)
1066+
{
1067+
Debug.Log($"Loaded changed modal state '{state}'");
1068+
}
1069+
}
1070+
```
1071+
1072+
P.S: In addition to getting the current state of the modal window,
1073+
you can subscribe to the `OnStateChanged` event and receive **the current state** if it has changed.
1074+
1075+
# Possible errors
1076+
1077+
**Error:**
1078+
`Assertion failed on expression: 'm_LockCount == 0'`
1079+
1080+
**Reason for appearance:**
1081+
When replacing the library icon with your own instead of the default one.
1082+
1083+
**Solution:**
1084+
Enable the `Read/Write` property (under "Advanced") in the icon import settings
1085+
and disable compression by switching the "Format" field to `RGBA 32 bit`.
1086+
1087+
# Update guidline
1088+
1089+
**Problem:**
1090+
I added a new version of `Uniton Connect` to my project and did **not delete** the previous files.
1091+
The project refuses to build and crashes with an error. What should I do? :c
1092+
1093+
**Solution:**
1094+
When updating the library from a previous version to the current one,
1095+
**DELETE THE PREVIOUS** sdk files to avoid **build issues** or other conflicts between versions.
1096+
1097+
1098+
**Problem:**
1099+
I updated the library to the latest version, but I'm getting errors when compiling
1100+
the project related to non-existent methods in `TonConnectBridge.jslib`. What should I do? :c
1101+
1102+
**Solution:**
1103+
First, make sure you have the `Uniton Connect` build template selected in `Build Settings -> Player Settings -> Resolution and Presentation -> WebGL Template`.
1104+
Once you have selected it and tried building again, everything will work without any problems!
1105+
If you are using your own **CUSTOM BUILD** template, compare the versions of the native libraries used to run `Uniton Connect` and make changes if they differ.
1106+
9181107
# Build
9191108

9201109
In order to create a project, you must first configure several settings in the `Player Settings` window:
@@ -953,11 +1142,13 @@ PORT=3000
9531142

9541143
TON_API_KEY="YOUR-TON-API-KEY"
9551144
TON_CENTER_API_KEY="YOUR-TON-CENTER-API-KEY"
1145+
APP_DOMAIN="YOUR-APP-DOMAIN-IN-MANIFEST"
9561146
```
9571147

9581148
- The `PORT` variable is a free port that the api server will listen on to receive requests and send responses to the unity client,
9591149
- The `TON_API_KEY` variable is the api key that will be used by the sdk client to send requests `to the Ton Api`. To get it, you need to log in via telegram [on their dashboard](https://tonconsole.com/) and then enter it here,
9601150
- The `TON_CENTER_API_KEY` variable is an api key, which is also used to send requests, but now `in Ton Center V3`, due to the unavailability of some features in the first provider. To get it, you need to enter [their official bot](https://t.me/toncenter) via telegram.
1151+
- The `APP_DOMAIN` variable is the domain name where your application is deployed. It is required **to verify the data signature** after signing inside the wallet. As an example, the library's demo application specifies `mrveit.github.io`.
9611152

9621153
Now you can run the `backend locally`, for full access to `all SDK features`.
9631154
To do this, open a terminal in the code editor in which you opened the project and enter the following command:

0 commit comments

Comments
 (0)