spruceid / siwe-py

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

fix CustomDateTime issue #52

Closed zhangjun725 closed 11 months ago

zhangjun725 commented 11 months ago

It appears that the current implementation of the CustomDateTime class has a problem when used with certain date-time formats. I've observed this issue when running the following test code:


from siwe import SiweMessage

message = {
    'domain': 'localhost:3000',
    'statement': 'Sign in with Ethereum to the app.',
    'uri': 'http://localhost:3000',
    'version': '1',
    'chain_id': 1,
    'nonce': 12345678,
    'not_before': '2023-09-28T14:35:42.031383+08:00',
    'address': '0x0000000000000000000000000000000000000000',
    'expiration_time': '2023-09-30T14:35:42.035047+08:00',
    'issued_at': '2023-09-28T14:35:42.035060+08:00'
}

siwe_message = SiweMessage(message)
print(siwe_message.expiration_time)
print(siwe_message.expiration_time.date)

# output:
# 2023-09-30T14:35:42.035047+08:00
# 2023-09-28 14:35:42.031383+08:00 (incorrect)
sbihel commented 11 months ago

This is expected, expiration_time is the string whilst expiration_time.date is the date object that can be used for comparisons/manipulations.

But the wrapper isn't necessarily great and is confusing. So I am going to close this PR is favour of #50