siwe


Namesiwe JSON
Version 4.1.0 PyPI version JSON
download
home_pagehttps://login.xyz
SummaryA Python implementation of Sign-In with Ethereum (EIP-4361).
upload_time2024-05-08 14:26:07
maintainerNone
docs_urlNone
authorSpruce Systems, Inc.
requires_python<4.0,>=3.8
licenseMIT OR Apache-2.0
keywords siwe eip-4361 sign-in with ethereum spruce id
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Sign-In with Ethereum

This package provides a Python implementation of EIP-4361: Sign In With Ethereum.

## Installation

SIWE can be easily installed in any Python project with pip:

```bash
pip install siwe
```

## Usage

SIWE provides a `SiweMessage` class which implements EIP-4361.

### Parsing a SIWE Message

Parsing is done by initializing a `SiweMessage` object with an EIP-4361 formatted string:

```python
from siwe import SiweMessage
message = SiweMessage.from_message(message=eip_4361_string)
```

Or to initialize a `SiweMessage` as a `pydantic.BaseModel` right away:

```python
message = SiweMessage(domain="login.xyz", address="0x1234...", ...)
```

### Verifying and Authenticating a SIWE Message

Verification and authentication is performed via EIP-191, using the `address` field of the `SiweMessage` as the expected signer. The validate method checks message structural integrity, signature address validity, and time-based validity attributes.

```python
try:
    message.verify(signature="0x...")
    # You can also specify other checks (e.g. the nonce or domain expected).
except siwe.ValidationError:
    # Invalid
```

### Serialization of a SIWE Message

`SiweMessage` instances can also be serialized as their EIP-4361 string representations via the `prepare_message` method:

```python
print(message.prepare_message())
```

## Example

Parsing and verifying a `SiweMessage` is easy:

```python
try:
    message: SiweMessage = SiweMessage(message=eip_4361_string)
    message.verify(signature, nonce="abcdef", domain="example.com"):
except siwe.ValueError:
    # Invalid message
    print("Authentication attempt rejected.")
except siwe.ExpiredMessage:
    print("Authentication attempt rejected.")
except siwe.DomainMismatch:
    print("Authentication attempt rejected.")
except siwe.NonceMismatch:
    print("Authentication attempt rejected.")
except siwe.MalformedSession as e:
    # e.missing_fields contains the missing information needed for validation
    print("Authentication attempt rejected.")
except siwe.InvalidSignature:
    print("Authentication attempt rejected.")

# Message has been verified. Authentication complete. Continue with authorization/other.
```

## Testing

```bash
poetry install
git submodule update --init
poetry run pytest
```

## See Also

- [Sign-In with Ethereum: TypeScript](https://github.com/spruceid/siwe)
- [Example SIWE application: login.xyz](https://login.xyz)
- [EIP-4361 Specification Draft](https://eips.ethereum.org/EIPS/eip-4361)
- [EIP-191 Specification](https://eips.ethereum.org/EIPS/eip-191)

## Disclaimer

Our Python library for Sign-In with Ethereum has not yet undergone a formal
security audit. We welcome continued feedback on the usability, architecture,
and security of this implementation.

            

Raw data

            {
    "_id": null,
    "home_page": "https://login.xyz",
    "name": "siwe",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.8",
    "maintainer_email": null,
    "keywords": "SIWE, EIP-4361, Sign-In with Ethereum, Spruce ID",
    "author": "Spruce Systems, Inc.",
    "author_email": "hello@spruceid.com",
    "download_url": "https://files.pythonhosted.org/packages/3a/51/818340cb82c6894f2892d11957750a0186e78f06832630bc3443e4e8d0f5/siwe-4.1.0.tar.gz",
    "platform": null,
    "description": "# Sign-In with Ethereum\n\nThis package provides a Python implementation of EIP-4361: Sign In With Ethereum.\n\n## Installation\n\nSIWE can be easily installed in any Python project with pip:\n\n```bash\npip install siwe\n```\n\n## Usage\n\nSIWE provides a `SiweMessage` class which implements EIP-4361.\n\n### Parsing a SIWE Message\n\nParsing is done by initializing a `SiweMessage` object with an EIP-4361 formatted string:\n\n```python\nfrom siwe import SiweMessage\nmessage = SiweMessage.from_message(message=eip_4361_string)\n```\n\nOr to initialize a `SiweMessage` as a `pydantic.BaseModel` right away:\n\n```python\nmessage = SiweMessage(domain=\"login.xyz\", address=\"0x1234...\", ...)\n```\n\n### Verifying and Authenticating a SIWE Message\n\nVerification and authentication is performed via EIP-191, using the `address` field of the `SiweMessage` as the expected signer. The validate method checks message structural integrity, signature address validity, and time-based validity attributes.\n\n```python\ntry:\n    message.verify(signature=\"0x...\")\n    # You can also specify other checks (e.g. the nonce or domain expected).\nexcept siwe.ValidationError:\n    # Invalid\n```\n\n### Serialization of a SIWE Message\n\n`SiweMessage` instances can also be serialized as their EIP-4361 string representations via the `prepare_message` method:\n\n```python\nprint(message.prepare_message())\n```\n\n## Example\n\nParsing and verifying a `SiweMessage` is easy:\n\n```python\ntry:\n    message: SiweMessage = SiweMessage(message=eip_4361_string)\n    message.verify(signature, nonce=\"abcdef\", domain=\"example.com\"):\nexcept siwe.ValueError:\n    # Invalid message\n    print(\"Authentication attempt rejected.\")\nexcept siwe.ExpiredMessage:\n    print(\"Authentication attempt rejected.\")\nexcept siwe.DomainMismatch:\n    print(\"Authentication attempt rejected.\")\nexcept siwe.NonceMismatch:\n    print(\"Authentication attempt rejected.\")\nexcept siwe.MalformedSession as e:\n    # e.missing_fields contains the missing information needed for validation\n    print(\"Authentication attempt rejected.\")\nexcept siwe.InvalidSignature:\n    print(\"Authentication attempt rejected.\")\n\n# Message has been verified. Authentication complete. Continue with authorization/other.\n```\n\n## Testing\n\n```bash\npoetry install\ngit submodule update --init\npoetry run pytest\n```\n\n## See Also\n\n- [Sign-In with Ethereum: TypeScript](https://github.com/spruceid/siwe)\n- [Example SIWE application: login.xyz](https://login.xyz)\n- [EIP-4361 Specification Draft](https://eips.ethereum.org/EIPS/eip-4361)\n- [EIP-191 Specification](https://eips.ethereum.org/EIPS/eip-191)\n\n## Disclaimer\n\nOur Python library for Sign-In with Ethereum has not yet undergone a formal\nsecurity audit. We welcome continued feedback on the usability, architecture,\nand security of this implementation.\n",
    "bugtrack_url": null,
    "license": "MIT OR Apache-2.0",
    "summary": "A Python implementation of Sign-In with Ethereum (EIP-4361).",
    "version": "4.1.0",
    "project_urls": {
        "Discord": "https://discord.gg/Sf9tSFzrnt",
        "EIP": "https://github.com/ethereum/EIPs/blob/master/EIPS/eip-4361.md",
        "Homepage": "https://login.xyz",
        "Repository": "https://github.com/spruceid/siwe-py"
    },
    "split_keywords": [
        "siwe",
        " eip-4361",
        " sign-in with ethereum",
        " spruce id"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ba0fe766e0d8415038f95a24c47e6457df0463c30c9f2bbf1635a951f34a43ae",
                "md5": "55d28f3dba0d8a75e54783d3139dfa7b",
                "sha256": "8d0a21ff62e405f3a7c7626da94ad4d3a3e0a731dcecb3a461931d7cea4f8520"
            },
            "downloads": -1,
            "filename": "siwe-4.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "55d28f3dba0d8a75e54783d3139dfa7b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8",
            "size": 10366,
            "upload_time": "2024-05-08T14:26:04",
            "upload_time_iso_8601": "2024-05-08T14:26:04.223758Z",
            "url": "https://files.pythonhosted.org/packages/ba/0f/e766e0d8415038f95a24c47e6457df0463c30c9f2bbf1635a951f34a43ae/siwe-4.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3a51818340cb82c6894f2892d11957750a0186e78f06832630bc3443e4e8d0f5",
                "md5": "2f4986f2f11e55efa51ca3289bf008b0",
                "sha256": "e1a3496236f3e922434e4e060a32e6a3262f9f11e37ccc559862729a5e460728"
            },
            "downloads": -1,
            "filename": "siwe-4.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "2f4986f2f11e55efa51ca3289bf008b0",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8",
            "size": 14128,
            "upload_time": "2024-05-08T14:26:07",
            "upload_time_iso_8601": "2024-05-08T14:26:07.634313Z",
            "url": "https://files.pythonhosted.org/packages/3a/51/818340cb82c6894f2892d11957750a0186e78f06832630bc3443e4e8d0f5/siwe-4.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-08 14:26:07",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ethereum",
    "github_project": "EIPs",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "siwe"
}
        
Elapsed time: 0.27739s