@@ -13,31 +13,43 @@ cd server-example
13
13
yarn install
14
14
yarn start
15
15
```
16
- ## Install TonLoginServer
16
+ ## Install Ton Connect Server
17
+
18
+ ```
19
+ $ yarn add @tonapps/tonconnect-server
20
+ ```
21
+
22
+ ## Generate Static Secret
23
+
17
24
```
18
- yarn add @tonapps/tonlogin-server
25
+ $ npx tonconnect-generate-secret
19
26
```
27
+ Put generated static secret to env vars or config
28
+
29
+
20
30
## How to use the server API
21
31
22
32
``` js
23
- // Generate static secret with generateServerSecret();
24
- // and put static secret to env vars or config
25
- import { generateServerSecret } from ' @tonapps/tonlogin-server' ;
26
- console .log (generateServerSecret ());
27
-
33
+ import { TonConnectServer , AuthRequestTypes } from ' @tonapps/tonconnect-server' ;
28
34
29
- // Create a TonLogin object configured with a static secret.
30
- const tonlogin = new TonLoginServer ({ staticSecret: " %fsa$tgs..." });
35
+ // Create a TonConnectServer instance configured with a static secret.
36
+ const tonconnect = new TonConnectServer ({
37
+ staticSecret: process .env .TONCONNECT_SECRET
38
+ });
31
39
32
40
// When we need to authenticate the user, create an authentication request:
33
- const request = tonlogin . generateAuthRequest ({
34
- image_url: ' <logo-url> ' ,
35
- return_url : ' <endpoint-url> ' ,
41
+ const request = tonconnect . createRequest ({
42
+ image_url: ' https://ddejfvww7sqtk.cloudfront.net/images/landing/ton-nft-tegro-dog/avatar/image_d0315e1461.jpg ' ,
43
+ callback_url : ` ${ hostname } /tonconnect ` ,
36
44
items: [{
37
- type: ' ton-address' ,
38
- require: true
45
+ type: AuthRequestTypes .ADDRESS ,
46
+ required: true
47
+ }, {
48
+ type: AuthRequestTypes .OWNERSHIP ,
49
+ required: true
39
50
}],
40
- })
51
+ });
52
+
41
53
42
54
res .send (request);
43
55
@@ -50,9 +62,31 @@ const deeplinkURL = `https://app.tonkeeper.com/ton-login/${requestURL}`;
50
62
Decode Auth Response
51
63
52
64
``` js
53
- const decodedResponse = tonlogin .decodeAuthResponse (encodedResponse);
54
-
55
- console .log (decodedResponse .client_id , decodedResponse .payload );
65
+ try {
66
+ const response = tonconnect .decodeResponse (req .query .tonlogin );
67
+
68
+ console .log (' response' , response);
69
+
70
+ for (let payload of response .payload ) {
71
+ switch (payload .type ) {
72
+ case AuthRequestTypes .OWNERSHIP :
73
+ const isVerified = await tonconnect .verifyTonOwnership (payload, response .client_id );
74
+
75
+ if (isVerified) {
76
+ console .log (` ton-ownership is verified for ${ payload .address } ` );
77
+ } else {
78
+ console .log (` ton-ownership is NOT verified` );
79
+ }
80
+
81
+ break ;
82
+ case AuthRequestTypes .ADDRESS :
83
+ console .log (` ton-address ${ payload .address } ` );
84
+ break ;
85
+ }
86
+ }
87
+ } catch (err) {
88
+ console .log (err);
89
+ }
56
90
```
57
91
58
92
[ AuthPayload specification] ( TonConnectSpecification.md#auth-payload )
0 commit comments