Skip to content

Python TON Connect implementation (Tonkeeper login protocol)

License

Notifications You must be signed in to change notification settings

stspbu/ton-connect

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TON Connect

Inspired by: ts ton-connect
Implements: 📄 TON Connect Specification

This software is provided "as is" without warranty of any kind.
Do not use it in your production unless you know what you are doing.

The library has only been tested with Tonkeeper app.

Installation

Run 'install' from the repository folder:

pip install .

How to use on your server

Read the specification first.

Create an auth request for a user:

import base64
import secrets

from ton_connect import AuthRequestOptions, AuthRequestOption, AuthRequest


# Generating a secret key (32 bytes long)
secret_key = base64.b64encode(secrets.token_bytes(32))

# Creating the auth request: 
options = AuthRequestOptions(
    image_url=...,
    return_url=...,
    callback_url=...,
    items=[
        AuthRequestOption(AuthRequestOption.Kind.OWNERSHIP, required=True)
    ]
)
req = AuthRequest.create(options, secret_key)  # 'data' parameter can be passed with your custom data

# Use 'result' to reply from your server
result = req.to_dict()

When you receive a callback request after the user has been authorized, you can check the wallet ownership like this:

from ton_connect import AuthResponse


# Creating an auth response, where:
# - 'data' is taken from the request
# - 'secret_key' is your secret key from the previous step
res = AuthResponse.create_from_data(data, secret_key)
result = res.verify_ton_ownership(res.payload[0], res.client_id)

# True if the ownership has been verified
if result:
    # Extract the address and other data from the payload as simple as that:
    print(res.payload[0].address)

Donation

If my work helps you, you can donate to this TON wallet:
EQCBA764QkuNJ6__lo1qagfHsa511ohsu8dLW8roFE-jjF-K

Contacts

If you have any questions or suggestions, don't hesitate to open an issue or contact the developers at [email protected].

About

Python TON Connect implementation (Tonkeeper login protocol)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages