Skip to content

Add bittensor.timelock module description#2833

Merged
basfroman merged 2 commits intostagingfrom
feat/roma/extend-the-timelock-module-description
Apr 17, 2025
Merged

Add bittensor.timelock module description#2833
basfroman merged 2 commits intostagingfrom
feat/roma/extend-the-timelock-module-description

Conversation

@basfroman
Copy link
Collaborator

In addition to the basic usage, the user can use the logic to encrypt and decrypt custom objects. The description of the process is added to the module.

import pickle
from dataclasses import dataclass

from bittensor import timelock


@dataclass
class Person:
    name: str
    age: int

# get instance of your data
x_person = Person("X Lynch", 123)

# get bytes of your instance
byte_data = pickle.dumps(x_person)

# get TLE encoded bytes
encrypted, reveal_round = timelock.encrypt(byte_data, 1)

# wait when reveal round appears in Drand QuickNet and get decrypted data
decrypted = timelock.wait_reveal_and_decrypt(encrypted_data=encrypted)

# convert bytes into your instance back
x_person_2 = pickle.loads(decrypted)

# make sure initial and decoded instances are the same
assert x_person == x_person_2

@basfroman basfroman requested a review from a team April 17, 2025 19:21
@basfroman basfroman self-assigned this Apr 17, 2025
@basfroman basfroman added the documentation Improvements or additions to documentation label Apr 17, 2025
Co-authored-by: Cameron Fairchild <cameron@opentensor.dev>
@basfroman basfroman merged commit 3f02967 into staging Apr 17, 2025
125 checks passed
@thewhaleking thewhaleking deleted the feat/roma/extend-the-timelock-module-description branch April 17, 2025 20:02
@ibraheem-abe ibraheem-abe mentioned this pull request Apr 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants