Skip to main content

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.

Metadata

Release files for siws 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for siws 0.0.2
File Size Uploaded
siws-0.0.2.tar.gz 8.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for siws 0.0.2
File Interpreter ABI Platform
siws-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 18.1 kB

Release files / siws-0.0.2.tar.gz

Download URL siws-0.0.2.tar.gz
Size 8.4 kB
Tags Source
SHA-256 checksum
How to use checksums
1d43dda898174167e4fb97cf22d8a6b2744c6667538d36f36a6a8d4784b5c1f4
BLAKE2b-256 checksum
How to use checksums
9b8847ee2ffcf7a0ae5741dcf2eb0d730dd70c14cce9046e63f53d286a433830
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.2

Release files / siws-0.0.2-py3-none-any.whl

Download URL siws-0.0.2-py3-none-any.whl
Size 9.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0138bfe2323743a3e7f7c447b41a3f62a26eebb01fec4d816e7d98fa62e1c518
BLAKE2b-256 checksum
How to use checksums
e0f71beb107ac4ada063cd6410d400fa5977e820d2ef63eadbe84a5b1974a2a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.2

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page