BitcoinShamir 1.0.1
A pure python implementation of the Shamir Secret Sharing scheme for use with BIP-39 mnemonic codes. Split a 24-word mnemonic phrase into several shares, and set a minimum threshold to recover your original phrase.
Install
pip install bitcoinshamir
Quick Start
>>> from bitcoinshamir import *
>>>
>>> # Generate a random mnemonic phrase.
>>> mnemonic = Mnemonic.generate_random()
>>> mnemonic_phrase = get_phrase(mnemonic, Language.English)
>>>
>>> # Create a 3 of 5 sharing scheme, for which any 3 shares can recover the
>>> # original mnemonic phrase.
>>> shares = create_shares(3, 5, mnemonic)
>>>
>>> # Write down each share phrase and pass out to participants.
>>> phrase_1 = get_phrase(shares[0], Language.English)
>>> phrase_2 = get_phrase(shares[1], Language.English)
>>> phrase_3 = get_phrase(shares[2], Language.English)
>>> phrase_4 = get_phrase(shares[3], Language.English)
>>> phrase_5 = get_phrase(shares[4], Language.English)
>>>
>>> # The original mnemonic phrase can be recovered with any three of the share
>>> # phrases.
>>> recovery_share_1 = Share.from_share_phrase(phrase_4, Language.English)
>>> recovery_share_2 = Share.from_share_phrase(phrase_2, Language.English)
>>> recovery_share_3 = Share.from_share_phrase(phrase_5, Language.English)
>>> recovery_shares = [recovery_share_1, recovery_share_2, recovery_share_3]
>>>
>>> recovered_mnemonic = recover_mnemonic(recovery_shares)
>>> recovered_phrase = get_phrase(recovered_mnemonic, Language.English)
>>>
>>> # You can also use recovery shares to generate new shares.
>>> recovery_points = [share.point for share in recovery_shares]
>>> X = 7
>>> Y = Lagrange.interpolate(recovery_points, PRIME_MODULUS, X)
>>> point = Point(X, Y)
>>> threshold = recovery_shares[0].threshold
>>> seed_checksum = recovery_shares[0].seed_checksum
>>>
>>> share_6 = Share(point, threshold, seed_checksum)
>>>
>>> # You can change the language of your share phrase or mnemonic phrase.
>>> mnemonic = Mnemonic()
>>> english_phrase = ["team", "lend", "rice"] # Set this to your actual phrase
>>>
>>> for i, word in enumerate(english_phrase):
>>> mnemonic.set_word(i, word, Language.English)
>>>
>>> spanish_phrase = get_phrase(mnemonic, Language.Spanish)
>>> italian_phrase = get_phrase(mnemonic, Language.Italian)
>>> korean_phrase = get_phrase(mnemonic, Language.Korean)
Notes
- You must have the minimum threshold shares to recover your original phrase.
- Even 1 less share will not reveal a single word from the original phrase.
- Using more shares than the threshold will still recover the original phrase.
- Share phrases use the same BIP-39 word lists as mnemonic phrases do.
- Each share has a checksum, which will raise an error for any miskeyed words.
- Each share uses the original mnemonic checksum as a group ID.
- Shares do not need to be in the same language. They are not stored as text.
Share Construction
Each share represents an (X, Y) coordinate on a graph. It is 37 bytes, in order of the following:
- 32 bytes - The Y-value of the share
- 1 byte - The original mnemonic's checksum
- 5 bits - The version, xor the share checksum
- 4 bits - The threshold, xor the share checksum
- 7 bits - The X-value, xor the share checksum
- 2 bytes - The share checksum
The version, threshold, and X-value are all concatenated and applied the xor of the share checksum at the same time. The share checksum is the first 2 bytes of the sha256 hash of the first 35 bytes.
Metadata
Release files for bitcoinshamir 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| bitcoinshamir-1.0.1.tar.gz | 83.4 kB | Without provenance | Details for bitcoinshamir-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bitcoinshamir-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for bitcoinshamir-1.0.1-py3-none-any.whl |
Total release size: 170.2 kB
Release files / bitcoinshamir-1.0.1.tar.gz
| Download URL | bitcoinshamir-1.0.1.tar.gz |
|---|---|
| Size | 83.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a5e73d58340b3183a1bd2975280a54b9d9bdca415b41606138caf9a7d99cf576
|
|
BLAKE2b-256 checksum How to use checksums |
6f03bea183765263dcc73c9208bc7902cd238e419f4e8d919fe55fdc3edb87a4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.8
|
Release files / bitcoinshamir-1.0.1-py3-none-any.whl
| Download URL | bitcoinshamir-1.0.1-py3-none-any.whl |
|---|---|
| Size | 86.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
32f6268174c438a9415e4d77752c9199d7da686e2de6a8d7bc3e3cf15031440d
|
|
BLAKE2b-256 checksum How to use checksums |
7e99a0276230f5f1f20ce216a4c6639cd6e45e06231d07801653b953da309853
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.8
|
Security for bitcoinshamir 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.