tulliolo.bip39


Nametulliolo.bip39 JSON
Version 0.2 PyPI version JSON
download
home_page
SummaryA bip39 implementation, with a collection of tools
upload_time2023-05-14 09:31:39
maintainer
docs_urlNone
author
requires_python>=3.9
licenseCopyright (c) 2023 Tullio Loffredo (@tulliolo) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords bitcoin bip39 entropy mnemonic seed cryptography steganography
VCS
bugtrack_url
requirements Pillow cryptography
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Bip39
A Bip39 library, with a CLI and a collection of tools.

This project provides a full implementation of the [Bip39 specs](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki), along with a CLI that offers some mnemonic key management tools such as:
- **generate** and **validate** mnemonics;
- **correct** the last word according to the checksum (e.g. when a mnemonic is generated by rolling dices);
- **transform** (and **restore**) mnemonics, e.g. to create side-wallets hiding the original;
- **hide** or **reveal** a mnemonic in an image file, with a steganography algorithm.

For further details, please refer to the [documentation folder](https://github.com/tulliolo/bip39/wiki).

**For security reasons, it is highly recommended to run the CLI on an offline system, without any Internet or LAN connection.**

## Requirements
python 3.9+

## Installation
This project is distributed on [PyPI](https://pypi.org/):
```
pip install tulliolo.bip39
```

## Usage Examples
Here are some examples of using the library and CLI.

### CLI
**Generate** a new 24 words mnemonic:
```
$ bip39-cli generate -s 24
******************
* bip39-cli v0.2 *
******************

generating a 24 words mnemonic...

generate success!
view fresh drink impulse doctor wise another smoke license collect unaware immense normal trick second owner subway bright chaos upper ribbon kite debris quote
```

**Validate** a mnemonic, fixing the checksum:
```
$ bip39-cli validate -f
******************
* bip39-cli v0.2 *
******************

enter a mnemonic:
₿ view fresh drink impulse doctor wise another smoke license collect unaware immense
invalid checksum | expected: 0 | obtained: c

validation success... with fixed checksum:
view fresh drink impulse doctor wise another smoke license collect unaware hybrid
```

**Transform** and **restore** a mnemonic with a _negative_ (default) transformation:
```
$ bip39-cli transform
******************
* bip39-cli v0.2 *
******************

enter a mnemonic
₿ view fresh drink impulse doctor wise another smoke license collect unaware hybrid

applying negative transformation...

transformation success!
army permit rude miss sausage adjust wait creek learn sponsor bean mixed

$ bip39-cli transform
******************
* bip39-cli v0.2 *
******************

enter a mnemonic
₿ army permit rude miss sausage adjust wait creek learn sponsor bean mixed

applying negative transformation...

transformation success!
view fresh drink impulse doctor wise another smoke license collect unaware hybrid
```

**Encrypt** a mnemonic and **hide** it in an image with steganography:
```
$ bip39-cli steganography encode -i tests/data/test_image.jpg -o tests/data/output/
******************
* bip39-cli v0.2 *
******************

enter a mnemonic:
₿ view fresh drink impulse doctor wise another smoke license collect unaware hybrid

enter a password to encrypt the mnemonic (or leave blank):
₿ 
insert again...:
₿ 
encrypting mnemonic...

encoding image...

encoding success!
tests/data/output/test_image_horizontal_20230510-120631.png
```

**Reveal** a mnemonic from an image with steganography and **decrypt** it:
```
$ bip39-cli steganography decode -i tests/data/output/test_image_horizontal_20230510-120631.png 
******************
* bip39-cli v0.2 *
******************

enter a password to decrypt the mnemonic (or leave blank):
₿ 
insert again...:
₿ 

decoding image...
decoding success!

decrypting mnemonic...
decrypting success!
view fresh drink impulse doctor wise another smoke license collect unaware hybrid
```

### Library
**Generate** a 12 words mnemonic:

```
from tulliolo.bip39.mnemonic import Mnemonic

mnemonic = Mnemonic.generate(12)
print(" ".join(mnemonic.value))

absent deny citizen next velvet where mixture glimpse deposit sentence hat manual
```

**Import** a mnemonic and fix the checksum:
```
from tulliolo.bip39.mnemonic import Mnemonic

mnemonic = Mnemonic.from_value("view fresh drink impulse doctor wise another smoke license collect unaware immense", fix_checksum=True)
print(mnemonic.info)

{'entropy': 'f3eb990c391405f8c266668125b3b1b8', 'checksum': '0', 'value': {1: 'view', 2: 'fresh', 3: 'drink', 4: 'impulse', 5: 'doctor', 6: 'wise', 7: 'another', 8: 'smoke', 9: 'license', 10: 'collect', 11: 'unaware', 12: 'hybrid'}}
```

Generate the **seed**, that can be later used to generate bip32 wallets:
```
from tulliolo.bip39.mnemonic import Mnemonic

seed = Mnemonic.generate(24).encode(passphrase="my_optional_passphrase")
print(seed.hex())

d24027e4b7dae545b95dca96a7b8e539e0a0d7ae2ef6cd2247e346907f7b842bb93d2268ee3bd28eede481b0ddab0b44f04ed49b4a4904ee7882677dd2677ac2
```

**Transform** and **restore** a mnemonic with a _mirror_ transformation:
```
from tulliolo.bip39.mnemonic import Mnemonic
from tulliolo.bip39.utils.transformation import Transformation

mnemonic_o = Mnemonic.from_value("view fresh drink impulse doctor wise another smoke license collect unaware hybrid")
mnemonic_t = mnemonic_o.transform(Transformation.MIRROR)
print(mnemonic_t.value)

('budget', 'hover', 'hard', 'actress', 'grid', 'canoe', 'leader', 'agree', 'order', 'luggage', 'invest', 'paddle')

mnemonic_t = mnemonic_t.transform(Transformation.MIRROR)
assert mnemonic_o == mnemonic_t
print(mnemonic_t.value)

('view', 'fresh', 'drink', 'impulse', 'doctor', 'wise', 'another', 'smoke', 'license', 'collect', 'unaware', 'hybrid')
```

**Encrypt** a mnemonic and **hide** it in an image with steganography:
```
import pathlib
from tulliolo.bip39.utils import encryption, steganography

words = "view fresh drink impulse doctor wise another smoke license collect unaware hybrid"

# encrypt words
words = encryption.encrypt(words, "my_password")

# create paths
input_file = pathlib.Path("tests/data/test_image.jpg")
output_path = pathlib.Path("tests/data/output")

# hide message
output_file = steganography.encode(words, input_file, output_path)
print(output_file)

tests/data/output/test_image_horizontal_20230513-103831.png
```

**Reveal** a mnemonic from an image with steganography and **decrypt** it:
```
import pathlib
from tulliolo.bip39.utils import encryption, steganography

# create path
input_file = pathlib.Path("tests/data/output/test_image_horizontal_20230513-103831.png")

# reveal message
message = steganography.decode(input_file)

# decrypt message
message = encryption.decrypt(message, "my_password").decode("utf-8")
print(message)

view fresh drink impulse doctor wise another smoke license collect unaware hybrid
```

## Disclaimer

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "tulliolo.bip39",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "",
    "keywords": "bitcoin,bip39,entropy,mnemonic,seed,cryptography,steganography",
    "author": "",
    "author_email": "\"Tullio Loffredo (@tulliolo)\" <tulliolo@yahoo.com>",
    "download_url": "https://files.pythonhosted.org/packages/83/e7/3d96ced4249adf9f1ead1e60f0c865ea2bf63530b09117bcd54cabf7d2d4/tulliolo.bip39-0.2.tar.gz",
    "platform": null,
    "description": "# Bip39\nA Bip39 library, with a CLI and a collection of tools.\n\nThis project provides a full implementation of the [Bip39 specs](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki), along with a CLI that offers some mnemonic key management tools such as:\n- **generate** and **validate** mnemonics;\n- **correct** the last word according to the checksum (e.g. when a mnemonic is generated by rolling dices);\n- **transform** (and **restore**) mnemonics, e.g. to create side-wallets hiding the original;\n- **hide** or **reveal** a mnemonic in an image file, with a steganography algorithm.\n\nFor further details, please refer to the [documentation folder](https://github.com/tulliolo/bip39/wiki).\n\n**For security reasons, it is highly recommended to run the CLI on an offline system, without any Internet or LAN connection.**\n\n## Requirements\npython 3.9+\n\n## Installation\nThis project is distributed on [PyPI](https://pypi.org/):\n```\npip install tulliolo.bip39\n```\n\n## Usage Examples\nHere are some examples of using the library and CLI.\n\n### CLI\n**Generate** a new 24 words mnemonic:\n```\n$ bip39-cli generate -s 24\n******************\n* bip39-cli v0.2 *\n******************\n\ngenerating a 24 words mnemonic...\n\ngenerate success!\nview fresh drink impulse doctor wise another smoke license collect unaware immense normal trick second owner subway bright chaos upper ribbon kite debris quote\n```\n\n**Validate** a mnemonic, fixing the checksum:\n```\n$ bip39-cli validate -f\n******************\n* bip39-cli v0.2 *\n******************\n\nenter a mnemonic:\n\u20bf view fresh drink impulse doctor wise another smoke license collect unaware immense\ninvalid checksum | expected: 0 | obtained: c\n\nvalidation success... with fixed checksum:\nview fresh drink impulse doctor wise another smoke license collect unaware hybrid\n```\n\n**Transform** and **restore** a mnemonic with a _negative_ (default) transformation:\n```\n$ bip39-cli transform\n******************\n* bip39-cli v0.2 *\n******************\n\nenter a mnemonic\n\u20bf view fresh drink impulse doctor wise another smoke license collect unaware hybrid\n\napplying negative transformation...\n\ntransformation success!\narmy permit rude miss sausage adjust wait creek learn sponsor bean mixed\n\n$ bip39-cli transform\n******************\n* bip39-cli v0.2 *\n******************\n\nenter a mnemonic\n\u20bf army permit rude miss sausage adjust wait creek learn sponsor bean mixed\n\napplying negative transformation...\n\ntransformation success!\nview fresh drink impulse doctor wise another smoke license collect unaware hybrid\n```\n\n**Encrypt** a mnemonic and **hide** it in an image with steganography:\n```\n$ bip39-cli steganography encode -i tests/data/test_image.jpg -o tests/data/output/\n******************\n* bip39-cli v0.2 *\n******************\n\nenter a mnemonic:\n\u20bf view fresh drink impulse doctor wise another smoke license collect unaware hybrid\n\nenter a password to encrypt the mnemonic (or leave blank):\n\u20bf \ninsert again...:\n\u20bf \nencrypting mnemonic...\n\nencoding image...\n\nencoding success!\ntests/data/output/test_image_horizontal_20230510-120631.png\n```\n\n**Reveal** a mnemonic from an image with steganography and **decrypt** it:\n```\n$ bip39-cli steganography decode -i tests/data/output/test_image_horizontal_20230510-120631.png \n******************\n* bip39-cli v0.2 *\n******************\n\nenter a password to decrypt the mnemonic (or leave blank):\n\u20bf \ninsert again...:\n\u20bf \n\ndecoding image...\ndecoding success!\n\ndecrypting mnemonic...\ndecrypting success!\nview fresh drink impulse doctor wise another smoke license collect unaware hybrid\n```\n\n### Library\n**Generate** a 12 words mnemonic:\n\n```\nfrom tulliolo.bip39.mnemonic import Mnemonic\n\nmnemonic = Mnemonic.generate(12)\nprint(\" \".join(mnemonic.value))\n\nabsent deny citizen next velvet where mixture glimpse deposit sentence hat manual\n```\n\n**Import** a mnemonic and fix the checksum:\n```\nfrom tulliolo.bip39.mnemonic import Mnemonic\n\nmnemonic = Mnemonic.from_value(\"view fresh drink impulse doctor wise another smoke license collect unaware immense\", fix_checksum=True)\nprint(mnemonic.info)\n\n{'entropy': 'f3eb990c391405f8c266668125b3b1b8', 'checksum': '0', 'value': {1: 'view', 2: 'fresh', 3: 'drink', 4: 'impulse', 5: 'doctor', 6: 'wise', 7: 'another', 8: 'smoke', 9: 'license', 10: 'collect', 11: 'unaware', 12: 'hybrid'}}\n```\n\nGenerate the **seed**, that can be later used to generate bip32 wallets:\n```\nfrom tulliolo.bip39.mnemonic import Mnemonic\n\nseed = Mnemonic.generate(24).encode(passphrase=\"my_optional_passphrase\")\nprint(seed.hex())\n\nd24027e4b7dae545b95dca96a7b8e539e0a0d7ae2ef6cd2247e346907f7b842bb93d2268ee3bd28eede481b0ddab0b44f04ed49b4a4904ee7882677dd2677ac2\n```\n\n**Transform** and **restore** a mnemonic with a _mirror_ transformation:\n```\nfrom tulliolo.bip39.mnemonic import Mnemonic\nfrom tulliolo.bip39.utils.transformation import Transformation\n\nmnemonic_o = Mnemonic.from_value(\"view fresh drink impulse doctor wise another smoke license collect unaware hybrid\")\nmnemonic_t = mnemonic_o.transform(Transformation.MIRROR)\nprint(mnemonic_t.value)\n\n('budget', 'hover', 'hard', 'actress', 'grid', 'canoe', 'leader', 'agree', 'order', 'luggage', 'invest', 'paddle')\n\nmnemonic_t = mnemonic_t.transform(Transformation.MIRROR)\nassert mnemonic_o == mnemonic_t\nprint(mnemonic_t.value)\n\n('view', 'fresh', 'drink', 'impulse', 'doctor', 'wise', 'another', 'smoke', 'license', 'collect', 'unaware', 'hybrid')\n```\n\n**Encrypt** a mnemonic and **hide** it in an image with steganography:\n```\nimport pathlib\nfrom tulliolo.bip39.utils import encryption, steganography\n\nwords = \"view fresh drink impulse doctor wise another smoke license collect unaware hybrid\"\n\n# encrypt words\nwords = encryption.encrypt(words, \"my_password\")\n\n# create paths\ninput_file = pathlib.Path(\"tests/data/test_image.jpg\")\noutput_path = pathlib.Path(\"tests/data/output\")\n\n# hide message\noutput_file = steganography.encode(words, input_file, output_path)\nprint(output_file)\n\ntests/data/output/test_image_horizontal_20230513-103831.png\n```\n\n**Reveal** a mnemonic from an image with steganography and **decrypt** it:\n```\nimport pathlib\nfrom tulliolo.bip39.utils import encryption, steganography\n\n# create path\ninput_file = pathlib.Path(\"tests/data/output/test_image_horizontal_20230513-103831.png\")\n\n# reveal message\nmessage = steganography.decode(input_file)\n\n# decrypt message\nmessage = encryption.decrypt(message, \"my_password\").decode(\"utf-8\")\nprint(message)\n\nview fresh drink impulse doctor wise another smoke license collect unaware hybrid\n```\n\n## Disclaimer\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n",
    "bugtrack_url": null,
    "license": "Copyright (c) 2023 Tullio Loffredo (@tulliolo)  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "A bip39 implementation, with a collection of tools",
    "version": "0.2",
    "project_urls": {
        "Bug Tracker": "https://github.com/tulliolo/bip39/issues",
        "Documentation": "https://github.com/tulliolo/bip39/wiki",
        "Homepage": "https://github.com/tulliolo/bip39"
    },
    "split_keywords": [
        "bitcoin",
        "bip39",
        "entropy",
        "mnemonic",
        "seed",
        "cryptography",
        "steganography"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2a7a344ffce297d61bdb7a3a628000f8d7c2279eebe2914ab783d3a98364efe4",
                "md5": "e0726a563dca35a581a1c35b33f84b53",
                "sha256": "11564efafb148676f3ef6b8ae9e19c41d5bfd70853c0c8d362d2dd38248460f3"
            },
            "downloads": -1,
            "filename": "tulliolo.bip39-0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e0726a563dca35a581a1c35b33f84b53",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 31107,
            "upload_time": "2023-05-14T09:31:33",
            "upload_time_iso_8601": "2023-05-14T09:31:33.472362Z",
            "url": "https://files.pythonhosted.org/packages/2a/7a/344ffce297d61bdb7a3a628000f8d7c2279eebe2914ab783d3a98364efe4/tulliolo.bip39-0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "83e73d96ced4249adf9f1ead1e60f0c865ea2bf63530b09117bcd54cabf7d2d4",
                "md5": "13f61626ed5aa4eed55caaed2d3d3c52",
                "sha256": "16f116a1bf5b437fd96c63a05c15f66e14852f8aef806ca7f8ee4ba9b9807bf4"
            },
            "downloads": -1,
            "filename": "tulliolo.bip39-0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "13f61626ed5aa4eed55caaed2d3d3c52",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 645155,
            "upload_time": "2023-05-14T09:31:39",
            "upload_time_iso_8601": "2023-05-14T09:31:39.703695Z",
            "url": "https://files.pythonhosted.org/packages/83/e7/3d96ced4249adf9f1ead1e60f0c865ea2bf63530b09117bcd54cabf7d2d4/tulliolo.bip39-0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-05-14 09:31:39",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "tulliolo",
    "github_project": "bip39",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "Pillow",
            "specs": [
                [
                    "~=",
                    "9.4.0"
                ]
            ]
        },
        {
            "name": "cryptography",
            "specs": [
                [
                    "~=",
                    "39.0.1"
                ]
            ]
        }
    ],
    "lcname": "tulliolo.bip39"
}
        
Elapsed time: 0.05855s