Open jjangga0214 opened 1 year ago
I am also curious. I have full stack code. When computing the hash on the client, it does not match the one computed on the server. E.g. MD5 hashes:
V3YnvMxZAHSv+yLZTqWfdQ==
for:
{
fromCode: 'SJC',
toCode: 'LAX',
departureTime: 1715695200,
duration: 5470,
flight: 'AS-3445',
classCode: 'F',
seat: '2E',
aircraft: null,
registration: null,
notes: null,
status: 'A'
}
LUUV3I4vtEoqZ7gEvZi84g==
for:
{
aircraft: null
classCode: "F"
departureTime: 1715695200
duration: 5470
flight: "AS-3445"
fromCode: "SJC"
notes: null
registration: null
seat: "2E"
status: "A",
toCode: "LAX"
}
Both are obtained with hash(object, { algorithm: 'md5', encoding: 'base64' , unorderedObjects: true })
.
PS: I found out what causes the issue. It is the difference of object prototype. To obtain the same hash, the following should be used: hash(object, { algorithm: 'md5', encoding: 'base64' , respectType: false })
.
For basic untyped objects, it seems that it should by default ignore the prototype. It is also possible that some library code adds a function to prototype, so I would advocate that the default for respectType
should be false
, not true
like it is right now. It seems less likely that a user would be surprised by the behavior if it is false
, because if they turn on respectType
, they will be made aware of the fact that the prototype is part of the hash.
Hi!
I wonder how strong the determinism is guaranteed.
For example,
Thanks!!