Skip to main content

SLIP-39 Shamir Mnemonics

Project description

python-shamir-mnemonic

https://badge.fury.io/py/shamir-mnemonic.svg

Reference implementation of SLIP-0039: Shamir’s Secret-Sharing for Mnemonic Codes

Abstract

This SLIP describes a standard and interoperable implementation of Shamir’s secret sharing (SSS). SSS splits a secret into unique parts which can be distributed among participants, and requires a specified minimum number of parts to be supplied in order to reconstruct the original secret. Knowledge of fewer than the required number of parts does not leak information about the secret.

Specification

See https://github.com/satoshilabs/slips/blob/master/slip-0039.md for full specification.

Security

This implementation is not using any hardening techniques. Secrets are passed in the open, and calculations are most likely trivially vulnerable to side-channel attacks.

The purpose of this code is to verify correctness of other implementations. It should not be used for handling sensitive secrets.

Installation

With pip from GitHub:

$ pip3 install shamir-mnemonic

From local checkout for development:

$ python3 setup.py develop

CLI usage

CLI tool is included as a reference and UX testbed.

Warning: this tool makes no attempt to protect sensitive data! Use at your own risk. If you need this to recover your wallet seeds, make sure to do it on an air-gapped computer, preferably running a live system such as Tails.

When the shamir_mnemonic package is installed, you can use the shamir command:

$ shamir create 3of5   # create a 3-of-5 set of shares
$ shamir recover       # interactively recombine shares to get the master secret

You can supply your own master secret as a hexadecimal string:

$ shamir create 3of5 --master-secret=cb21904441dfd01a392701ecdc25d61c

You can specify a custom scheme. For example, to create three groups, with 2-of-3, 2-of-5, and 4-of-5, and require completion of all three groups, use:

$ shamir create custom --threshold 3 --group 2 3 --group 2 5 --group 4 5

Use shamir --help or shamir create --help to see all available options.

If you want to run the CLI from a local checkout without installing, use the following command:

$ python3 -m shamir_mnemonic.cli

Test vectors

The test vectors in vectors.json are given as a list of triples. The first member of the triple is a description of the test vector, the second member is a list of mnemonics and the third member is the master secret which results from combining the mnemonics. The master secret is encoded as a string containing two hexadecimal digits for each byte. If the string is empty, then attempting to combine the given set of mnemonics should result in error. The passphrase “TREZOR” is used for all valid sets of mnemonics.

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

Unreleased

No changes yet

0.2.0 - 2021-02-03

Added

  • Introduce slip_ems and recover_ems to separate password-based encryption from the Shamir Secret recovery

  • Introduce classes representing a share and group-common parameters

  • Introduce RecoveryState class that allows reusing the logic of the shamir recover command

Changed

  • Use secrets module instead of os.urandom

  • Refactor and restructure code into separate modules

0.1.0 - 2019-07-19

Added

  • Initial implementation

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

shamir-mnemonic-0.2.0.tar.gz (21.4 kB view details)

Uploaded Source

Built Distribution

shamir_mnemonic-0.2.0-py3-none-any.whl (21.9 kB view details)

Uploaded Python 3

File details

Details for the file shamir-mnemonic-0.2.0.tar.gz.

File metadata

  • Download URL: shamir-mnemonic-0.2.0.tar.gz
  • Upload date:
  • Size: 21.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5

File hashes

Hashes for shamir-mnemonic-0.2.0.tar.gz
Algorithm Hash digest
SHA256 580e06d79d52f42954ac6b6876ae79c4f4ea78fcb95b2605a3bbf2f5767f7fb3
MD5 b089c4731c4e5199d2e3c339fef5ba6f
BLAKE2b-256 a563ac71ff58b1e7b66bb35b8e79bd386ed46fe86722809663b1e358da3a0c58

See more details on using hashes here.

File details

Details for the file shamir_mnemonic-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: shamir_mnemonic-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 21.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5

File hashes

Hashes for shamir_mnemonic-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6228c47add5253d9fd7ed716d9b28e7cb4feda9050cb06db29830940817d0180
MD5 8ac1b07c90191fcf920a7772a83841e3
BLAKE2b-256 b53606316b50128d2371577442e9e1b09a1948bc11f3729493b8984f3aac3ad3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page