A python adaptation from Sign it with ethereum for Stacks
Project description
Sign-In with Stacks
This package provides a Python adaptation of EIP-4361: Sign In With Ethereum to Stacks ecosystem.
Usage
SIWS provides a SiwsMessage
class.
Parsing a SIWS Message
Parsing is done by initializing a SiwsMessage
object with an EIP-4361 formatted string:
from siws import SiwsMessage
message: SiwsMessage = SiwsMessage(message=eip_4361_string)
Alternatively, initialization of a SiwsMessage
object can be done with a dictionary containing expected attributes:
message: SiwsMessage = SiwsMessage(message={"domain": "login.xyz", "address": "SP3...", ...})
Verifying and Authenticating a SIWS Message
Verification and authentication is performed, using the address
field of the SiwsMessage
as the expected signer. The validate method checks message structural integrity, signature address validity, and time-based validity attributes.
message.verify(signature="...", public_key="...")
Serialization of a SIWS Message
SiwsMessage
instances can also be serialized as a string representations via the prepare_message
method:
print(message.prepare_message())
Example
Parsing and verifying a SiwsMessage
is easy:
try:
message: SiwsMessage = SiwsMessage(message=eip_4361_string)
message.verify(signature, public_key, nonce="abcdef", domain="example.com"):
except siws.ValueError:
# Invalid message
print("Authentication attempt rejected.")
except siws.ExpiredMessage:
print("Authentication attempt rejected.")
except siws.DomainMismatch:
print("Authentication attempt rejected.")
except siws.NonceMismatch:
print("Authentication attempt rejected.")
except siws.MalformedSession as e:
# e.missing_fields contains the missing information needed for validation
print("Authentication attempt rejected.")
except siws.InvalidSignature:
print("Authentication attempt rejected.")
# Message has been verified. Authentication complete. Continue with authorization/other.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file siws-0.0.2.tar.gz
.
File metadata
- Download URL: siws-0.0.2.tar.gz
- Upload date:
- Size: 8.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d43dda898174167e4fb97cf22d8a6b2744c6667538d36f36a6a8d4784b5c1f4 |
|
MD5 | 6afdcff15e06e5f0ace068a264dbe49b |
|
BLAKE2b-256 | 9b8847ee2ffcf7a0ae5741dcf2eb0d730dd70c14cce9046e63f53d286a433830 |
File details
Details for the file siws-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: siws-0.0.2-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0138bfe2323743a3e7f7c447b41a3f62a26eebb01fec4d816e7d98fa62e1c518 |
|
MD5 | 504581fc82453163c9c131667c46ffc7 |
|
BLAKE2b-256 | e0f71beb107ac4ada063cd6410d400fa5977e820d2ef63eadbe84a5b1974a2a4 |