Giter Club home page Giter Club logo

esp32_upy_bitcoin's Introduction

esp32_upy_bitcoin

Installation

Download submodules:

git submodule update --init --recursive

Cross-compile micropython

cd micropython/mpy-cross
make
cd ../..

Also added 2 lines in micropython/ports/esp32/mpconfigport.h:

#define MODULE_HASHLIB_ENABLED      (1)
#define MODULE_ECC_ENABLED          (1)

Copy over the micropython files:

cp -r libs/* micropython/ports/esp32/modules/

Compile firmware:

ESPIDF=~/esp/esp-idf make USER_C_MODULES=../../../usermods

Upload firmware

esptool.py --chip esp32 --port <port> --baud 460800 erase_flash
esptool.py --chip esp32 --port <port> --baud 460800 write_flash -z 0x1000 build/firmware.bin

Then we have two new modules:

  • bitcoin.ecc containing ecc primitives
  • hashlib with all hash functions
$ screen /dev/ttyUSB0 115200
>>> import bitcoin
>>> dir(bitcoin)
['__class__', '__name__', '__path__', 'helper', 'PrivateKey', 'PublicKey', 'ecc']
>>> dir(bitcoin.ecc)
['__class__', '__name__', 'BytesIO', '_ecc', 'hashlib', 'hexlify', 'hash160', 'encode_base58_checksum', 'decode_base58', 'p2pkh_script', 'hmac', 'N', 'FieldElement', 'PrivateKey', 'PublicKey', 'G']
>>> import hashlib
>>> dir(hashlib)
['__class__', '__name__', 'ripemd160', 'sha1', 'sha256', 'sha512']

Example - show Bitcoin address on m5stack screen

import m5stack
from m5stack import LCD, fonts, color565
from bitcoin import PrivateKey

lcd = LCD()
lcd.set_font(fonts.tt24)
lcd.set_color(color565(0,50,250), color565(255,255,255)) # text color, background color
lcd.erase()

pk = PrivateKey.parse("Kyo7UhSKAXDSddUWE7FmUiTfZnvgmyVcapjUyPkhKxHF6ZXD7n2T")
# pk = PrivateKey(0x473628abb8917391, compressed=True, testnet=True)
lcd.set_pos(50,50)
lcd.print(pk.address())

Reference

esp32_upy_bitcoin's People

Contributors

justinmoon avatar stepansnigirev avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.