139 |
Sign Data Test & Verification
140 |
141 |
142 | Test different types of data signing: text, binary, and cell formats with signature verification
143 |
144 |
145 | {wallet ? (
146 |
147 |
150 |
153 |
156 |
157 | ) : (
158 |
159 | Connect wallet to test signing
160 |
161 | )}
162 |
163 | {signDataRequest && (
164 |
165 |
📤 Sign Data Request
166 |
167 |
168 |
169 |
170 | )}
171 |
172 | {signDataResponse && (
173 |
174 |
📥 Sign Data Response
175 |
176 |
177 |
178 |
179 | )}
180 |
181 | {verificationResult && (
182 |
183 |
✅ Verification Result
184 |
185 |
186 |
187 |
188 | )}
189 |
190 | );
191 | }
192 |
--------------------------------------------------------------------------------
/src/server/services/sign-data-service.ts:
--------------------------------------------------------------------------------
1 | import {
2 | Address,
3 | beginCell,
4 | Cell,
5 | contractAddress,
6 | loadStateInit,
7 | } from "@ton/core";
8 | import { sha256 } from "@ton/crypto";
9 | import { Buffer } from "buffer";
10 | import nacl from "tweetnacl";
11 | import crc32 from "crc-32";
12 | import {
13 | CheckSignDataRequestDto,
14 | SignDataPayloadText,
15 | SignDataPayloadBinary,
16 | SignDataPayload,
17 | } from "../dto/check-sign-data-request-dto";
18 | import { tryParsePublicKey } from "../wrappers/wallets-data";
19 |
20 | const allowedDomains = [
21 | 'tonconnect-demo-dapp-with-react-ui.vercel.app',
22 | 'ton-connect.github.io',
23 | 'localhost:5173'
24 | ];
25 | const validAuthTime = 15 * 60; // 15 minutes
26 |
27 | export class SignDataService {
28 | /**
29 | * Verifies sign-data signature.
30 | *
31 | * Supports three payload types:
32 | * 1. text - for text messages
33 | * 2. binary - for arbitrary binary data
34 | * 3. cell - for TON Cell with TL-B schema
35 | */
36 | public async checkSignData(
37 | payload: CheckSignDataRequestDto,
38 | getWalletPublicKey: (address: string) => Promise