@tonconnect/ui 2.2.0-beta.0 → 2.3.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -344,6 +344,122 @@ tonConnectUI.uiOptions = {
344
344
  };
345
345
  ```
346
346
 
347
+ ## Sign data
348
+
349
+ Sign arbitrary data with the user's wallet. The wallet will display the data to the user for confirmation before signing. Wallet must be connected when you call `signData`, otherwise an error will be thrown.
350
+
351
+ ### Data Types
352
+
353
+ You can sign three types of data. Choose the right format based on your use case:
354
+
355
+ - **Text** - Use for human-readable text that users should see and understand
356
+ - **Cell** - Use for TON Blockchain data that should be used in smart contracts (wallet may show unknown content warning)
357
+ - **Binary** - For other arbitrary data (least preferred due to security warnings)
358
+
359
+ #### Text Format
360
+
361
+ Use when you need to sign human-readable text. The wallet displays the text to the user.
362
+
363
+ **Parameters:**
364
+ - `type` (string, required): Must be `"text"`
365
+ - `text` (string, required): UTF-8 text to sign
366
+ - `network` (string, optional): `"-239"` for mainnet, `"-3"` for testnet
367
+ - `from` (string, optional): Signer address in raw format `"0:<hex>"`
368
+
369
+ ```ts
370
+ const textData = {
371
+ type: "text",
372
+ text: "Confirm new 2fa number:\n+1 234 567 8901",
373
+ network: "-239", // MAINNET = '-239', TESTNET = '-3'
374
+ from: "0:348bcf827469c5fc38541c77fdd91d4e347eac200f6f2d9fd62dc08885f0415f"
375
+ };
376
+
377
+ try {
378
+ const result = await tonConnectUI.signData(textData);
379
+ console.log('Signed:', result);
380
+ } catch (e) {
381
+ console.error('Error:', e);
382
+ }
383
+ ```
384
+
385
+ #### Binary Format
386
+
387
+ Use for arbitrary binary data. The wallet shows a warning about unknown content.
388
+
389
+ **Parameters:**
390
+ - `type` (string, required): Must be `"binary"`
391
+ - `bytes` (string, required): Base64 encoded binary data (not url-safe)
392
+ - `network` (string, optional): `"-239"` for mainnet, `"-3"` for testnet
393
+ - `from` (string, optional): Signer address in raw format `"0:<hex>"`
394
+
395
+ ```ts
396
+ const binaryData = {
397
+ type: "binary",
398
+ bytes: "1Z/SGh+3HFMKlVHSkN91DpcCzT4C5jzHT3sA/24C5A==",
399
+ network: "-239", // MAINNET = '-239', TESTNET = '-3'
400
+ from: "0:348bcf827469c5fc38541c77fdd91d4e347eac200f6f2d9fd62dc08885f0415f"
401
+ };
402
+
403
+ try {
404
+ const result = await tonConnectUI.signData(binaryData);
405
+ console.log('Signed:', result);
406
+ } catch (e) {
407
+ console.error('Error:', e);
408
+ }
409
+ ```
410
+
411
+ #### Cell Format
412
+
413
+ Use for TON Blockchain data with TL-B schema. The wallet can parse and display the content if the schema is valid.
414
+
415
+ **Parameters:**
416
+ - `type` (string, required): Must be `"cell"`
417
+ - `schema` (string, required): TL-B schema of the cell payload
418
+ - `cell` (string, required): Base64 encoded BoC (not url-safe) with single-root cell
419
+ - `network` (string, optional): `"-239"` for mainnet, `"-3"` for testnet
420
+ - `from` (string, optional): Signer address in raw format `"0:<hex>"`
421
+
422
+ ```ts
423
+ const cellData = {
424
+ type: "cell",
425
+ 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;",
426
+ cell: "te6ccgEBAQEAVwAAqg+KfqVUbeTvKqB4h0AcnDgIAZucsOi6TLrfP6FcuPKEeTI6oB3fF/NBjyqtdov/KtutACCLqvfmyV9kH+Pyo5lcsrJzJDzjBJK6fd+ZnbFQe4+XggI=",
427
+ network: "-239", // MAINNET = '-239', TESTNET = '-3'
428
+ from: "0:348bcf827469c5fc38541c77fdd91d4e347eac200f6f2d9fd62dc08885f0415f"
429
+ };
430
+
431
+ try {
432
+ const result = await tonConnectUI.signData(cellData);
433
+ console.log('Signed:', result);
434
+ } catch (e) {
435
+ console.error('Error:', e);
436
+ }
437
+ ```
438
+
439
+ ### Response
440
+
441
+ All signData calls return the same response structure:
442
+
443
+ ```ts
444
+ interface SignDataResult {
445
+ signature: string; // Base64 encoded signature
446
+ address: string; // Wallet address in raw format
447
+ timestamp: number; // UNIX timestamp in seconds (UTC)
448
+ domain: string; // App domain name
449
+ payload: object; // Original payload from the request
450
+ }
451
+ ```
452
+
453
+ ### Signature Verification
454
+
455
+ After receiving the signed data, you need to verify the signature to ensure it's authentic and was signed by the claimed wallet address.
456
+
457
+ **For backend verification:** See [TypeScript verification example](https://github.com/ton-connect/demo-dapp-with-react-ui/blob/master/src/server/services/sign-data-service.ts#L32-L109) showing how to verify signatures on your server.
458
+
459
+ **For smart contract verification:** See [FunC verification example](https://github.com/p0lunin/sign-data-contract-verify-example/blob/master/contracts/sign_data_example.fc) showing how to verify signatures in TON smart contracts.
460
+
461
+ **For complete technical details:** See the [Sign Data specification](https://github.com/ton-blockchain/ton-connect/blob/main/requests-responses.md#sign-data) for full signature verification requirements.
462
+
347
463
  ## Universal links redirecting issues (IOS)
348
464
  Some operating systems, and especially iOS, have restrictions related to universal link usage.
349
465
  For instance, if you try to open a universal link on an iOS device via `window.open`, you can face the following problem:
@@ -925,3 +1041,9 @@ Please note that this is just a warning and should not affect the functionality
925
1041
  ```shell
926
1042
  npm install encoding
927
1043
  ```
1044
+
1045
+ ## How to find a sent transaction on the blockchain
1046
+
1047
+ See the detailed guide: [Transaction-by-external-message](../../guidelines/transaction-by-external-message.md)
1048
+
1049
+ This guide explains how to find the corresponding transaction on the TON blockchain by the BOC of an external-in message.