nkeys


Namenkeys JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttps://github.com/nats-io/nkeys.py
SummaryA public-key signature system based on Ed25519 for the NATS ecosystem.
upload_time2019-05-13 00:54:02
maintainer
docs_urlNone
authorWaldemar Quevedo
requires_python>=3.6.0
licenseApache 2 License
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            # NKEYS for Python3

[![License Apache 2](https://img.shields.io/badge/License-Apache2-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)

A public-key signature system based on [Ed25519](https://ed25519.cr.yp.to/) for the NATS ecosystem.

## About

The NATS ecosystem will be moving to [Ed25519](https://ed25519.cr.yp.to/) keys for identity, authentication and authorization for entities such as Accounts, Users, Servers and Clusters.

Ed25519 is fast and resistant to side channel attacks. Generation of a seed key is all that is needed to be stored and kept safe, as the seed can generate both the public and private keys.

The NATS system will utilize Ed25519 keys, meaning that NATS systems will never store or even have access to any private keys. Authentication will utilize a random challenge response mechanism.

Dealing with 32 byte and 64 byte raw keys can be challenging. NKEYS is designed to formulate keys in a much friendlier fashion and references work done in cryptocurrencies, specifically [Stellar](https://www.stellar.org/).	Bitcoin and others used a form of Base58 (or Base58Check) to endode raw keys. Stellar utilized a more traditonal Base32 with a CRC16 and a version or prefix byte. NKEYS utilizes a similar format where the prefix will be 1 byte for public and private keys and will be 2 bytes for seeds. The base32 encoding of these prefixes will yield friendly human readbable prefixes, e.g. '**N**' = server, '**C**' = cluster, '**O**' = operator, '**A**' = account, and '**U**' = user. '**P**' is used for private keys. For seeds, the first encoded prefix is '**S**', and the second character will be the type for the public key, e.g. "**SU**" is a seed for a user key pair, "**SA**" is a seed for an account key pair.

## Installation

```sh
pip install nkeys
```

## Basic API Usage

```python
import nkeys
import os

# Create an NKEYS KeyPair from a seed file.
user = None
with open("user.nkey", 'rb', buffering=0) as f:

  # We compute the size of the file to allocate the required
  # bytearray size in order to have control over the memory
  # and be able to wipe it once the keys are not needed anymore.
  seed = bytearray(os.fstat(f.fileno()).st_size)
  f.readinto(seed)
  user = nkeys.from_seed(seed)

# Sign some data with the KeyPair user.
data = b'arGTKH8q7XDmgy0'
sig = user.sign(data)

# Verify the signature
try: 
  user.verify(data, sig)
except nkeys.ErrInvalidSignature as e:
  print("Error:", e)

# Access the seed, the only thing that needs to be stored and kept safe.
print(user.seed)

# Remove any secrets that were in use by the KeyPair.
user.wipe()
```

## License

Unless otherwise noted, the NATS source files are distributed under the Apache Version 2.0 license found in the LICENSE file.
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/nats-io/nkeys.py",
    "name": "nkeys",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6.0",
    "maintainer_email": "",
    "keywords": "",
    "author": "Waldemar Quevedo",
    "author_email": "wally@nats.io",
    "download_url": "https://files.pythonhosted.org/packages/73/fe/d788a4fe70442e527d73f52d3091be3a980d539b63b8574349b5a3732881/nkeys-0.1.0.tar.gz",
    "platform": "",
    "description": "# NKEYS for Python3\n\n[![License Apache 2](https://img.shields.io/badge/License-Apache2-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)\n\nA public-key signature system based on [Ed25519](https://ed25519.cr.yp.to/) for the NATS ecosystem.\n\n## About\n\nThe NATS ecosystem will be moving to [Ed25519](https://ed25519.cr.yp.to/) keys for identity, authentication and authorization for entities such as Accounts, Users, Servers and Clusters.\n\nEd25519 is fast and resistant to side channel attacks. Generation of a seed key is all that is needed to be stored and kept safe, as the seed can generate both the public and private keys.\n\nThe NATS system will utilize Ed25519 keys, meaning that NATS systems will never store or even have access to any private keys. Authentication will utilize a random challenge response mechanism.\n\nDealing with 32 byte and 64 byte raw keys can be challenging. NKEYS is designed to formulate keys in a much friendlier fashion and references work done in cryptocurrencies, specifically [Stellar](https://www.stellar.org/).\tBitcoin and others used a form of Base58 (or Base58Check) to endode raw keys. Stellar utilized a more traditonal Base32 with a CRC16 and a version or prefix byte. NKEYS utilizes a similar format where the prefix will be 1 byte for public and private keys and will be 2 bytes for seeds. The base32 encoding of these prefixes will yield friendly human readbable prefixes, e.g. '**N**' = server, '**C**' = cluster, '**O**' = operator, '**A**' = account, and '**U**' = user. '**P**' is used for private keys. For seeds, the first encoded prefix is '**S**', and the second character will be the type for the public key, e.g. \"**SU**\" is a seed for a user key pair, \"**SA**\" is a seed for an account key pair.\n\n## Installation\n\n```sh\npip install nkeys\n```\n\n## Basic API Usage\n\n```python\nimport nkeys\nimport os\n\n# Create an NKEYS KeyPair from a seed file.\nuser = None\nwith open(\"user.nkey\", 'rb', buffering=0) as f:\n\n  # We compute the size of the file to allocate the required\n  # bytearray size in order to have control over the memory\n  # and be able to wipe it once the keys are not needed anymore.\n  seed = bytearray(os.fstat(f.fileno()).st_size)\n  f.readinto(seed)\n  user = nkeys.from_seed(seed)\n\n# Sign some data with the KeyPair user.\ndata = b'arGTKH8q7XDmgy0'\nsig = user.sign(data)\n\n# Verify the signature\ntry: \n  user.verify(data, sig)\nexcept nkeys.ErrInvalidSignature as e:\n  print(\"Error:\", e)\n\n# Access the seed, the only thing that needs to be stored and kept safe.\nprint(user.seed)\n\n# Remove any secrets that were in use by the KeyPair.\nuser.wipe()\n```\n\n## License\n\nUnless otherwise noted, the NATS source files are distributed under the Apache Version 2.0 license found in the LICENSE file.",
    "bugtrack_url": null,
    "license": "Apache 2 License",
    "summary": "A public-key signature system based on Ed25519 for the NATS ecosystem.",
    "version": "0.1.0",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "73fed788a4fe70442e527d73f52d3091be3a980d539b63b8574349b5a3732881",
                "md5": "870fd02211baf8536c19fe6713c29ba4",
                "sha256": "93482ab08ff9625882b988c3ea58fd1a6ef0061b60f95946742cc1394578760a"
            },
            "downloads": -1,
            "filename": "nkeys-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "870fd02211baf8536c19fe6713c29ba4",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6.0",
            "size": 6216,
            "upload_time": "2019-05-13T00:54:02",
            "upload_time_iso_8601": "2019-05-13T00:54:02.871481Z",
            "url": "https://files.pythonhosted.org/packages/73/fe/d788a4fe70442e527d73f52d3091be3a980d539b63b8574349b5a3732881/nkeys-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2019-05-13 00:54:02",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "nats-io",
    "github_project": "nkeys.py",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "lcname": "nkeys"
}
        
Elapsed time: 0.03431s