spruceid / siwe-py

A Python implementation of Sign-In with Ethereum
https://login.xyz
Apache License 2.0
66 stars 28 forks source link

Exposes ISO8601Datetime so that users can import it #62

Closed KasparPeterson closed 3 months ago

KasparPeterson commented 3 months ago

It is currently quite confusing to get this issued_at correct. Would propose to make it able to import the ISO8601Datetime that you defined in the siwe.py for the end user.

The example usage would be like this then:

from datetime import datetime

from siwe import SiweMessage
from siwe import ISO8601Datetime

issued_at = ISO8601Datetime.from_datetime(datetime.now())

message = SiweMessage(
    issued_at=issued_at,
)

The current user experience as I understand is like this:

from datetime import datetime

from siwe import SiweMessage
from siwe import ISO8601Datetime

timespec: str = "milliseconds"
dt = datetime.now()
issued_at = (dt.astimezone(tz=timezone.utc)
             .isoformat(timespec=timespec)
             .replace("+00:00", "Z"))

message = SiweMessage(
    issued_at=issued_at,
)
sbihel commented 3 months ago

Thank you very much, published as v4.1.0