Skip to content

Instantly share code, notes, and snippets.

View matejcik's full-sized avatar

matejcik matejcik

View GitHub Profile
@matejcik
matejcik / restic.py
Created April 14, 2022 14:20
Restic backup password generated by Trezor
from trezorlib.client import get_default_client
from trezorlib.misc import encrypt_keyvalue
from trezorlib.tools import parse_path
client = get_default_client()
PATH = parse_path("m/10016'/0'")
KEY = "Generate Restic backup password?"
VALUE = b"\x00" * 16
@matejcik
matejcik / lazy_cbor_collection.py
Last active August 10, 2021 14:16
cardano streamed transactions
class HashBuilderCollection:
def __init__(self, size: int) -> None:
self.size = size
self.remaining = size
self.hash_fn: HashContext | None = None
self.parent: "HashBuilderCollection" | None = None
self.have_nested_child = False
def start(self, hash_fn: HashContext) -> "HashBuilderCollection":
@matejcik
matejcik / minikey-to-wif.py
Created January 26, 2020 12:26
Cassacius mini private key to WIF in pure Python 3.6
import hashlib
MINIKEY = "S6c56bnXQiBjk9mqSYE7ykVQ7NzrRy"
ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
def sha256(x):
return hashlib.sha256(x).digest()
@matejcik
matejcik / re-sign.py
Created October 29, 2019 14:49
Re-sign existing firmware with a different firmware header
#!/usr/bin/env python3
# Place this script into trezor-firmware/core
# usage: ./re-sign.py trezor-2.0.6.bin trezor-2.0.6-unsigned.bin
from hashlib import blake2s
import os
from typing import List, Tuple
@matejcik
matejcik / refactor.py
Created August 29, 2019 13:30
code for refactoring `self.client` to `client` and related changes
#%%
import libcst as cst
from glob import glob
#%%
from collections import Counter
self_symbols = set()
setup_mnemonics = Counter()
@matejcik
matejcik / redline.py
Last active April 8, 2019 18:55
redline - insert a red line in terminal when you press Enter
#!/usr/bin/env python3
# script to insert red lines to passthrough output
# usage:
# redline.py command -w -args ...
import os
import sys
import subprocess
p = subprocess.Popen(sys.argv[1:], stdout=sys.stdout, stderr=sys.stderr, stdin=subprocess.PIPE, bufsize=0)
@matejcik
matejcik / foxmingus.py
Created September 14, 2018 20:56
FoxMingus
# foxmingus - an rudimentary interface from mingus to foxdot
#
# install mingus from a fork with:
# pip install git+https://github.com/edudobay/python-mingus@python3
#
# place this file somewhere convenient, and run the following
# in FoxDot:
# -->8--
# import sys
# sys.path.insert(0, "/path/to/foxmingus/directory")
@matejcik
matejcik / dumper.py
Created June 14, 2018 17:19
Dumper for protobuf bridge messages
import binascii, struct, io, sys
from trezorlib import mapping, protobuf
def dump_message(msg):
data = binascii.unhexlify(msg)
headerlen = struct.calcsize('>HL')
msg_type, datalen = struct.unpack('>HL', data[:headerlen])
data = io.BytesIO(data[headerlen:headerlen + datalen])
msg = protobuf.load_message(data, mapping.get_class(msg_type))
@matejcik
matejcik / firmware.py
Created June 8, 2018 13:44
Firmware validation with Construct
import binascii
import construct as c
import pyblake2
from trezorlib import cosi
Toif = c.Struct(
"magic" / c.Const(b"TOI"),
"format" / c.Enum(c.Byte, full_color=b"f", grayscale=b"g"),
@matejcik
matejcik / test_matrix.md
Created May 9, 2018 14:21
python-trezor test markers matrix
from .conftest import TREZOR_VERSION
import pytest

Skip markers

@pytest.mark.skip_t1
@pytest.mark.skip_t2