├── .gitignore ├── config.py ├── create_signed_message.py ├── requirements.txt ├── signed-message.json ├── signing-key ├── utils.py └── verify_signed_message.py /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .idea 3 | .vscode 4 | dump.rdb 5 | 6 | # Log files 7 | !logs/.gitkeep 8 | *.log 9 | logs/* 10 | 11 | # Django 12 | *.pot 13 | *.pyc 14 | __pycache__/ 15 | __pycache__/* 16 | db.sqlite3 17 | db.sqlite3-journal 18 | local_settings.py 19 | media 20 | 21 | # Byte-compiled / optimized / DLL files 22 | *$py.class 23 | *.py[cod] 24 | 25 | # C extensions 26 | *.so 27 | 28 | # Distribution / packaging 29 | *.egg 30 | *.egg-info/ 31 | .Python 32 | .eggs/ 33 | .installed.cfg 34 | MANIFEST 35 | develop-eggs/ 36 | downloads/ 37 | eggs/ 38 | lib/ 39 | lib64/ 40 | parts/ 41 | pip-wheel-metadata/ 42 | sdist/ 43 | share/python-wheels/ 44 | var/ 45 | wheels/ 46 | dist/ 47 | 48 | # Unit test / coverage reports 49 | *.cover 50 | *.py,cover 51 | .cache 52 | .coverage 53 | .coverage.* 54 | .hypothesis/ 55 | .nox/ 56 | .pytest_cache/ 57 | .tox/ 58 | coverage.xml 59 | htmlcov/ 60 | nosetests.xml 61 | 62 | # pytest 63 | .pytest_cache 64 | 65 | # pyenv 66 | .python-version 67 | 68 | # Celery 69 | celerybeat-schedule 70 | celerybeat.pid 71 | 72 | # Environments 73 | .env 74 | .venv 75 | ENV/ 76 | env.bak/ 77 | env/ 78 | venv 79 | venv.bak/ 80 | venv/ -------------------------------------------------------------------------------- /config.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | BASE_DIR = os.path.dirname(os.path.abspath(__file__)) 4 | SIGNING_KEY_FILE = os.path.join(BASE_DIR, 'signing-key') 5 | SIGNED_MESSAGE_FILE = os.path.join(BASE_DIR, 'signed-message.json') 6 | -------------------------------------------------------------------------------- /create_signed_message.py: -------------------------------------------------------------------------------- 1 | from thenewboston.accounts.key_files import read_signing_key_file 2 | 3 | from config import SIGNED_MESSAGE_FILE, SIGNING_KEY_FILE 4 | from utils import generate_signed_message, write_json 5 | 6 | SIGNING_KEY = read_signing_key_file(SIGNING_KEY_FILE) 7 | MESSAGE = 'My name is Bucky Roberts' 8 | 9 | account_number = SIGNING_KEY.verify_key 10 | signed_message = generate_signed_message( 11 | account_number=account_number, 12 | message=MESSAGE, 13 | signing_key=SIGNING_KEY 14 | ) 15 | write_json(file=SIGNED_MESSAGE_FILE, data=signed_message) 16 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | thenewboston==0.0.30 -------------------------------------------------------------------------------- /signed-message.json: -------------------------------------------------------------------------------- 1 | { 2 | "account_number": "53b0cb8520ebd36fde9a4d7d86c802aa71e51822eb89e70e3d4ee4fa375cda29", 3 | "message": "My name is Bucky Roberts", 4 | "signature": "79202cec90cec1c76b84b20c7b86fead0bd3511cc67d9a9a00f4bdfd5ddf2f620f9b9b10b6c0d05292c78e380544599f1c9dd139892f0acaf0f25bfd87989f06" 5 | } -------------------------------------------------------------------------------- /signing-key: -------------------------------------------------------------------------------- 1 | 4632b9f9bc903f571c1bd8dbea33eb8b3f178973ab162a2f243f50b7a66fef38 -------------------------------------------------------------------------------- /utils.py: -------------------------------------------------------------------------------- 1 | import json 2 | 3 | from thenewboston.verify_keys.verify_key import encode_verify_key 4 | 5 | 6 | def generate_signed_message(*, account_number, message, signing_key): 7 | block = { 8 | 'account_number': encode_verify_key(verify_key=account_number), 9 | 'message': message, 10 | 'signature': signing_key.sign(message.encode('utf-8')).signature.hex() 11 | } 12 | return block 13 | 14 | 15 | def read_json(file): 16 | try: 17 | with open(file, 'r') as f: 18 | data = json.load(f) 19 | except FileNotFoundError: 20 | data = None 21 | return data 22 | 23 | 24 | def write_json(file, data): 25 | with open(file, 'w') as f: 26 | json.dump(data, f, indent=2) 27 | -------------------------------------------------------------------------------- /verify_signed_message.py: -------------------------------------------------------------------------------- 1 | from thenewboston.blocks.signatures import verify_signature 2 | 3 | from config import SIGNED_MESSAGE_FILE 4 | from utils import read_json 5 | 6 | SIGNED_MESSAGE = read_json(SIGNED_MESSAGE_FILE) 7 | 8 | try: 9 | verify_signature( 10 | message=SIGNED_MESSAGE['message'].encode('utf-8'), 11 | signature=SIGNED_MESSAGE['signature'], 12 | verify_key=SIGNED_MESSAGE['account_number'] 13 | ) 14 | print('\nValid!') 15 | except Exception: 16 | print('\nInvalid') 17 | --------------------------------------------------------------------------------