Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

question: degree of determinism #125

Open
9 tasks
jjangga0214 opened this issue Jun 17, 2023 · 1 comment
Open
9 tasks

question: degree of determinism #125

jjangga0214 opened this issue Jun 17, 2023 · 1 comment

Comments

@jjangga0214
Copy link

jjangga0214 commented Jun 17, 2023

Hi!

I wonder how strong the determinism is guaranteed.

For example,

  • On the same version of Node.js.
  • On the same browser.
  • Across different versions of Node.js.
  • Across different versions of browsers of the same kind.
  • Across different kinds of browsers.
  • Across JavaScript engines.
  • Across JavaScript engines version.
  • Is there special things to take care? To say, like floating point numbers and dates.
  • etc

Thanks!!

@jjangga0214 jjangga0214 changed the title Determinism question: how strong the determinism is guaranteed Jun 17, 2023
@jjangga0214 jjangga0214 changed the title question: how strong the determinism is guaranteed question: degree of determinism Jun 17, 2023
@FunMiles
Copy link

FunMiles commented Dec 26, 2023

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:

  • On the server, hash of 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'
}
  • On the client, hash of 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants