Git Product home page Git Product logo

bip32_template_python_implementation's Introduction

Package version Package license Python versions Build Status

Python implementation of BIP32 path template parser finite state machine

(compatible with micropython)

This repository contains an implementation of specification of the parser for BIP32 path templates described in bip-path-templates.mediawiki and specified by TLA+ specification at https://github.com/dgpv/bip32_template_parse_tplaplus_spec

The implementation is in bip32template/__init__.py

The tests is in tests/

To run tests on micropython, use micropython_unittest.py (you will need micropython-os.path module to run the tests)

to run static type checking, use run_mypy.sh

Example usage:

>>> from bip32template import BIP32Template
>>> tpl=BIP32Template.parse('m/0h/[1-9,23]/*')
>>> tpl
BIP32Template([[(2147483648, 2147483648)], [(1, 9), (23, 23)], [(0, 2147483647)]], is_partial=False, hardened_marker="h")
>>> tpl.sections
[[(2147483648, 2147483648)], [(1, 9), (23, 23)], [(0, 2147483647)]]
>>> str(tpl)
'm/0h/[1-9,23]/*'
>>> str(BIP32Template(tpl.sections, hardened_marker="'", is_partial=True))
"0'/[1-9,23]/*"
>>> tpl.to_path() is None
True
>>> tpl.match([0x80000000, 3, 33])
True
>>> tpl.match([0x80000000, 99, 33])
False
>>> BIP32Template.parse('m/0/1/[2-3]', is_format_onlypath=True)
...
bip32template.BIP32TemplateExceptionUnexpectedCharacter: unexpected character at position 7
>>> ptpl = BIP32Template.parse('m/0h/1/2', is_format_onlypath=True)
>>> ptpl
BIP32Template([[(2147483648, 2147483648)], [(1, 1)], [(2, 2)]], is_partial=False, hardened_marker="h")
>>> ptpl.to_path()
[2147483648, 1, 2]
>>> tpl.match(ptpl.to_path())
True
>>> str(BIP32Template.from_path(ptpl.to_path(), is_partial=True))
"0'/1/2"
>>> str(BIP32Template.from_path(ptpl.to_path(), is_partial=False, hardened_marker="h"))
'm/0h/1/2'

Authors and contributors

This implementation was created by Dmitry Petukhov (https://github.com/dgpv/)

License

Released under MIT license.

bip32_template_python_implementation's People

Contributors

dgpv 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.