js2pysecrets


Namejs2pysecrets JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttps://github.com/poing/JS2PySecrets/
SummaryShamir's Secret Sharing - A port of secrets.js-grempe to Python, allowing cross-platform compatible shares between JavaScript and Python.
upload_time2024-03-25 23:06:24
maintainerNone
docs_urlNone
authorBrian LaVallee
requires_python>=3.11
licenseNone
keywords adi adi shamir how to share a secret scheme secret secrets.js secrets shamir secret sharing scheme shamir's secret sharing shamir's shamir share shares sharing sss ssss
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![CI](https://github.com/poing/JS2PySecrets/actions/workflows/main.yml/badge.svg)](https://github.com/poing/JS2PySecrets/actions/workflows/main.yml)
[![codecov](https://codecov.io/gh/poing/JS2PySecrets/branch/main/graph/badge.svg?token=JS2PySecrets_token_here)](https://codecov.io/gh/poing/JS2PySecrets)
[![PyPI version](https://badge.fury.io/py/js2pysecrets.svg)](https://badge.fury.io/py/js2pysecrets)
[![Built with Material for MkDocs](https://img.shields.io/badge/Material_for_MkDocs-526CFE?logo=MaterialForMkDocs&logoColor=white)](https://squidfunk.github.io/mkdocs-material/)
[![JS2PySecrets Documentation](https://img.shields.io/badge/Documentation-white?labelColor=3F00FF&logo=data:image/svg%2bxml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48c3ZnIGlkPSJiIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNDEuNTUgMTUwLjUiPjxnIGlkPSJjIj48cGF0aCBkPSJNOTEuMy4yNWw1OC4yOC4wOGM2LjQ3LDAsMTEuNzIsNS4yNiwxMS43MiwxMS43M2gwYzAsNS4zLTIuMTEsMTAuMzktNS44NiwxNC4xNGwtMy41LDMuNWMtNi4wMyw2LjAzLTYuNDYsMTUuNjYtMS4wMSwyMi4yMWgwYzgsOS42LDIyLjczLDkuNiwzMC43MywwaDBjNS40Ni02LjU1LDUuMDItMTYuMTgtMS4wMS0yMi4yMWwtMy41LTMuNWMtMy43NS0zLjc1LTUuODYtOC44NC01Ljg2LTE0LjE0aDBjMC02LjQ3LDUuMjQtMTEuNzIsMTEuNzItMTEuNzNsNTguMjgtLjA4YzAsODIuMjktNjcuNzEsMTUwLTE1MCwxNTAtMjYuMzMsMC01Mi4yLTYuOTMtNzUtMjAuMWwyOS4xNy01MC41MmMzLjI0LTUuNiwxLjMyLTEyLjc3LTQuMjktMTZoMGMtNC41OS0yLjY1LTEwLjA1LTMuMzctMTUuMTgtMmwtNC43OCwxLjI4Yy04LjIzLDIuMjEtMTYuNzktMi4yMy0xOS43My0xMC4yM2gwYy00LjMxLTExLjcyLDMuMDYtMjQuNDgsMTUuMzYtMjYuNjFoMGM4LjQtMS40NSwxNi41MiwzLjc0LDE4LjczLDExLjk4bDEuMjgsNC43OGMxLjM3LDUuMTIsNC43Miw5LjQ5LDkuMzIsMTIuMTRoMGM1LjYsMy4yNCwxMi43NywxLjMyLDE2LTQuMjlMOTEuMy4yNVoiIHN0eWxlPSJmaWxsOiNmZmZmZmY7ICIvPjwvZz48L3N2Zz4=)](https://poing.github.io/JS2PySecrets/)

# About

`js2pysecrets` is a port of the [`secrets.js-grempe`](https://github.com/grempe/secrets.js) JavaScript package to Python. 

This package allows for cross-platform compatible shares, *generated using [Shamir's Secret Sharing](http://en.wikipedia.org/wiki/Shamir's_Secret_Sharing)*, to seamlessly interoperate between JavaScript and Python.

Function names and arguments used in the JavaScript package have been maintained for consistency and maintainability. 

The functionality is essentially the same as the JavaScript package, with an exception around random number generation.  Python doesn't have to adapt to different environments for random number generation like the JavaScript does.

*For additional details, see the [documentation](https://poing.github.io/JS2PySecrets/).*


## Installation and Usage

Install the PyPI package:

```
pip install js2pysecrets
```

Import the library:

```
import js2pysecrets as secrets
```

### Examples

Divide a 512-bit key, expressed in hexadecimal form, into 10 shares, requiring that any 5 of them are necessary to reconstruct the original key:

```python
import js2pysecrets as secrets

# generate a 512-bit key
key = secrets.random(512) 
print(key) # => key is a hex string

# split into 10 shares with a threshold of 5
shares = secrets.share(key, 10, 5)
print(shares) # => ['801xxx...xxx','802xxx...xxx', ... ,'809xxx...xxx','80axxx...xxx']

# combine 4 shares
comb = secrets.combine(shares[:4])
print(comb == key) # => False

# combine 5 shares
comb = secrets.combine(shares[:5])
print(comb == key) # => True

# combine ALL shares
comb = secrets.combine(shares)
print(comb == key) # => True

# create another share with id 8
new_share = secrets.newShare(8, shares)
print(new_share) # => '808xxx...xxx'

# reconstruct using 4 original shares and the new share:
comb = secrets.combine(shares[:4] + [new_share])
print(comb == key) # => True
```

Divide a password containing a mix of numbers, letters, and other characters, requiring that any 3 shares must be present to reconstruct the original password:

```python
import js2pysecrets as secrets

pw = "<<PassWord123>>"

# convert the text into a hex string
pwHex = secrets.str2hex(pw)
print(pwHex) # => hex string

# split into 5 shares, with a threshold of 3
shares = secrets.share(pwHex, 5, 3)
print(shares) # => ['801xxx...xxx','802xxx...xxx', ... ,'804xxx...xxx','805xxx...xxx']

# combine 2 shares:
comb = secrets.combine(shares[:2])

# convert back to UTF string:
comb = secrets.hex2str(comb)
print(comb == pw) # => False

# combine 3 shares:
comb = secrets.combine([shares[1], shares[3], shares[4]])

# convert back to UTF string:
comb = secrets.hex2str(comb)
print(comb == pw) # => True
```

## License

`js2pysecrets` is released under the MIT License. See the `LICENSE` file.

## Development and Testing

Read the [CONTRIBUTING.md](https://github.com/poing/JS2PySecrets/blob/main/CONTRIBUTING.md) file.

## To Do

- Restructure and split into separate modules
    - Move the backend functions outside the main module 
- Restructure and clean-up the tests

## Changelog

- 0.0.x

  - Documentation, documentation, documentation...
  - Configured automatic release to PyPI 
  - Converted `secrets.js`[^1] to Python
  - Disabled the `tests_win` GitHub action, #24
  - Moved docs to use [Material for MkDocs](https://squidfunk.github.io/mkdocs-material/)
  - Converted `secrets.js-grempe` Jasmine tests to `pytest` versions
  - Added package.json as a stub
  - Built Node.js wrapper for testing
  - Enable CodeCov
  - Started with the [Python Project Template](https://github.com/rochacbruno/python-project-template)
  
[^1]: `secrets.js-grempe` and `secrets.js` are basically the same.  The difference is the execution environment, JavaScript or Node.js.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/poing/JS2PySecrets/",
    "name": "js2pysecrets",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": null,
    "keywords": "Adi, Adi Shamir, how to share a secret, scheme, secret, secrets.js, secrets, Shamir Secret Sharing Scheme, Shamir's Secret Sharing, Shamir's, Shamir, share, shares, sharing, sss, ssss",
    "author": "Brian LaVallee",
    "author_email": "brian.lavallee@invite-comm.jp",
    "download_url": "https://files.pythonhosted.org/packages/40/f2/d1ed98a50151648324df789b5022fffe081ebda9b038b5bfa30fb195f019/js2pysecrets-0.1.0.tar.gz",
    "platform": null,
    "description": "[![CI](https://github.com/poing/JS2PySecrets/actions/workflows/main.yml/badge.svg)](https://github.com/poing/JS2PySecrets/actions/workflows/main.yml)\n[![codecov](https://codecov.io/gh/poing/JS2PySecrets/branch/main/graph/badge.svg?token=JS2PySecrets_token_here)](https://codecov.io/gh/poing/JS2PySecrets)\n[![PyPI version](https://badge.fury.io/py/js2pysecrets.svg)](https://badge.fury.io/py/js2pysecrets)\n[![Built with Material for MkDocs](https://img.shields.io/badge/Material_for_MkDocs-526CFE?logo=MaterialForMkDocs&logoColor=white)](https://squidfunk.github.io/mkdocs-material/)\n[![JS2PySecrets Documentation](https://img.shields.io/badge/Documentation-white?labelColor=3F00FF&logo=data:image/svg%2bxml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48c3ZnIGlkPSJiIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNDEuNTUgMTUwLjUiPjxnIGlkPSJjIj48cGF0aCBkPSJNOTEuMy4yNWw1OC4yOC4wOGM2LjQ3LDAsMTEuNzIsNS4yNiwxMS43MiwxMS43M2gwYzAsNS4zLTIuMTEsMTAuMzktNS44NiwxNC4xNGwtMy41LDMuNWMtNi4wMyw2LjAzLTYuNDYsMTUuNjYtMS4wMSwyMi4yMWgwYzgsOS42LDIyLjczLDkuNiwzMC43MywwaDBjNS40Ni02LjU1LDUuMDItMTYuMTgtMS4wMS0yMi4yMWwtMy41LTMuNWMtMy43NS0zLjc1LTUuODYtOC44NC01Ljg2LTE0LjE0aDBjMC02LjQ3LDUuMjQtMTEuNzIsMTEuNzItMTEuNzNsNTguMjgtLjA4YzAsODIuMjktNjcuNzEsMTUwLTE1MCwxNTAtMjYuMzMsMC01Mi4yLTYuOTMtNzUtMjAuMWwyOS4xNy01MC41MmMzLjI0LTUuNiwxLjMyLTEyLjc3LTQuMjktMTZoMGMtNC41OS0yLjY1LTEwLjA1LTMuMzctMTUuMTgtMmwtNC43OCwxLjI4Yy04LjIzLDIuMjEtMTYuNzktMi4yMy0xOS43My0xMC4yM2gwYy00LjMxLTExLjcyLDMuMDYtMjQuNDgsMTUuMzYtMjYuNjFoMGM4LjQtMS40NSwxNi41MiwzLjc0LDE4LjczLDExLjk4bDEuMjgsNC43OGMxLjM3LDUuMTIsNC43Miw5LjQ5LDkuMzIsMTIuMTRoMGM1LjYsMy4yNCwxMi43NywxLjMyLDE2LTQuMjlMOTEuMy4yNVoiIHN0eWxlPSJmaWxsOiNmZmZmZmY7ICIvPjwvZz48L3N2Zz4=)](https://poing.github.io/JS2PySecrets/)\n\n# About\n\n`js2pysecrets` is a port of the [`secrets.js-grempe`](https://github.com/grempe/secrets.js) JavaScript package to Python. \n\nThis package allows for cross-platform compatible shares, *generated using [Shamir's Secret Sharing](http://en.wikipedia.org/wiki/Shamir's_Secret_Sharing)*, to seamlessly interoperate between JavaScript and Python.\n\nFunction names and arguments used in the JavaScript package have been maintained for consistency and maintainability. \n\nThe functionality is essentially the same as the JavaScript package, with an exception around random number generation.  Python doesn't have to adapt to different environments for random number generation like the JavaScript does.\n\n*For additional details, see the [documentation](https://poing.github.io/JS2PySecrets/).*\n\n\n## Installation and Usage\n\nInstall the PyPI package:\n\n```\npip install js2pysecrets\n```\n\nImport the library:\n\n```\nimport js2pysecrets as secrets\n```\n\n### Examples\n\nDivide a 512-bit key, expressed in hexadecimal form, into 10 shares, requiring that any 5 of them are necessary to reconstruct the original key:\n\n```python\nimport js2pysecrets as secrets\n\n# generate a 512-bit key\nkey = secrets.random(512) \nprint(key) # => key is a hex string\n\n# split into 10 shares with a threshold of 5\nshares = secrets.share(key, 10, 5)\nprint(shares) # => ['801xxx...xxx','802xxx...xxx', ... ,'809xxx...xxx','80axxx...xxx']\n\n# combine 4 shares\ncomb = secrets.combine(shares[:4])\nprint(comb == key) # => False\n\n# combine 5 shares\ncomb = secrets.combine(shares[:5])\nprint(comb == key) # => True\n\n# combine ALL shares\ncomb = secrets.combine(shares)\nprint(comb == key) # => True\n\n# create another share with id 8\nnew_share = secrets.newShare(8, shares)\nprint(new_share) # => '808xxx...xxx'\n\n# reconstruct using 4 original shares and the new share:\ncomb = secrets.combine(shares[:4] + [new_share])\nprint(comb == key) # => True\n```\n\nDivide a password containing a mix of numbers, letters, and other characters, requiring that any 3 shares must be present to reconstruct the original password:\n\n```python\nimport js2pysecrets as secrets\n\npw = \"<<PassWord123>>\"\n\n# convert the text into a hex string\npwHex = secrets.str2hex(pw)\nprint(pwHex) # => hex string\n\n# split into 5 shares, with a threshold of 3\nshares = secrets.share(pwHex, 5, 3)\nprint(shares) # => ['801xxx...xxx','802xxx...xxx', ... ,'804xxx...xxx','805xxx...xxx']\n\n# combine 2 shares:\ncomb = secrets.combine(shares[:2])\n\n# convert back to UTF string:\ncomb = secrets.hex2str(comb)\nprint(comb == pw) # => False\n\n# combine 3 shares:\ncomb = secrets.combine([shares[1], shares[3], shares[4]])\n\n# convert back to UTF string:\ncomb = secrets.hex2str(comb)\nprint(comb == pw) # => True\n```\n\n## License\n\n`js2pysecrets` is released under the MIT License. See the `LICENSE` file.\n\n## Development and Testing\n\nRead the [CONTRIBUTING.md](https://github.com/poing/JS2PySecrets/blob/main/CONTRIBUTING.md) file.\n\n## To Do\n\n- Restructure and split into separate modules\n    - Move the backend functions outside the main module \n- Restructure and clean-up the tests\n\n## Changelog\n\n- 0.0.x\n\n  - Documentation, documentation, documentation...\n  - Configured automatic release to PyPI \n  - Converted `secrets.js`[^1] to Python\n  - Disabled the `tests_win` GitHub action, #24\n  - Moved docs to use [Material for MkDocs](https://squidfunk.github.io/mkdocs-material/)\n  - Converted `secrets.js-grempe` Jasmine tests to `pytest` versions\n  - Added package.json as a stub\n  - Built Node.js wrapper for testing\n  - Enable CodeCov\n  - Started with the [Python Project Template](https://github.com/rochacbruno/python-project-template)\n  \n[^1]: `secrets.js-grempe` and `secrets.js` are basically the same.  The difference is the execution environment, JavaScript or Node.js.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Shamir's Secret Sharing - A port of secrets.js-grempe to Python, allowing cross-platform compatible shares between JavaScript and Python.",
    "version": "0.1.0",
    "project_urls": {
        "Bug Tracker": "https://github.com/poing/JS2PySecrets/issues/",
        "Documentation": "https://poing.github.io/JS2PySecrets",
        "Homepage": "https://github.com/poing/JS2PySecrets/",
        "Source": "https://github.com/poing/JS2PySecrets"
    },
    "split_keywords": [
        "adi",
        " adi shamir",
        " how to share a secret",
        " scheme",
        " secret",
        " secrets.js",
        " secrets",
        " shamir secret sharing scheme",
        " shamir's secret sharing",
        " shamir's",
        " shamir",
        " share",
        " shares",
        " sharing",
        " sss",
        " ssss"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f41669aa592e2979e593e06a07da052b688233f82cf06969cb05dae8ac657e23",
                "md5": "38847b49577c4d285a8a6c5b0cf146a6",
                "sha256": "d466aa7d1e07617e7c4e3766d8581b063b2d7b17e20d9ce5cb737ba2c14a3c00"
            },
            "downloads": -1,
            "filename": "js2pysecrets-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "38847b49577c4d285a8a6c5b0cf146a6",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 16068,
            "upload_time": "2024-03-25T23:06:22",
            "upload_time_iso_8601": "2024-03-25T23:06:22.584063Z",
            "url": "https://files.pythonhosted.org/packages/f4/16/69aa592e2979e593e06a07da052b688233f82cf06969cb05dae8ac657e23/js2pysecrets-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "40f2d1ed98a50151648324df789b5022fffe081ebda9b038b5bfa30fb195f019",
                "md5": "def23711c953f2cd77902582cf0bbff2",
                "sha256": "b0bdafc2b4cf7f34667687d17aee5689a59d5af7476acfd22be1d9a4003fc34b"
            },
            "downloads": -1,
            "filename": "js2pysecrets-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "def23711c953f2cd77902582cf0bbff2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 33087,
            "upload_time": "2024-03-25T23:06:24",
            "upload_time_iso_8601": "2024-03-25T23:06:24.677107Z",
            "url": "https://files.pythonhosted.org/packages/40/f2/d1ed98a50151648324df789b5022fffe081ebda9b038b5bfa30fb195f019/js2pysecrets-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-25 23:06:24",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "poing",
    "github_project": "JS2PySecrets",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "js2pysecrets"
}
        
Elapsed time: 0.35164s