Skip to main content

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)

Source distribution for bitcoinshamir 1.0.1
File Size Uploaded
bitcoinshamir-1.0.1.tar.gz 83.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for bitcoinshamir 1.0.1
File Interpreter ABI Platform
bitcoinshamir-1.0.1-py3-none-any.whl Python 3 none any Details

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

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

0.0.13

2 release files

0.0.12

2 release files

0.0.11

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page