-
Notifications
You must be signed in to change notification settings - Fork 24
Add synchronous way to use scrypt. #14
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
Conversation
|
@evilaliv3 what do you think? |
|
let me say that i've a lot of criticism (constructive). i do not like the approach you had in creating the function in order to permit it to be called with some arguments or others. no javascript function is generally builded this way so that they accept some parameters and the mix them like you do internally with callback = interruptstep. this make code less clear (think that you code could be reused or grow up with more functionality. this is what i suggest to do in obtain the same goal: |
|
you can see here a packaging identical to the one i'm proposing: https://github.com/EvanHahn/HumanizeDuration.js/blob/master/humanize-duration.js so that we can package the library with the name scrypt-async-js and have:
|
|
Well, handling optional arguments like this is pretty common, however I agree that redefining how the function returns result based on this is uncommon. Another option that I like more than having two functions is to namespace the sync version under
|
|
i do not like so much the word sync to mean a module but also a function :) |
|
why you do not like calling them scrypt and scrypt_sync ? |
|
It should be |
|
i'm sure some fairies will die if you do that. do you mind? |
|
It's JavaScript, all fairies are already dead :-D |
|
damn. look a unicorn! |
|
anyway ok i see your point, this is why i liked more the idea of packaging all inside a module called "scrypt-async-js" with two public functions:
i do not see any issue in the retrocompatibility, as it's a one line fix and frankly i do not think a lot of project are using the library right now. |
Now there are three general ways to call scrypt: scrypt(password, salt, logN, r, dkLen, interruptStep, callback, [encoding]) Derives a key from password and salt and calls callback with derived key as the only argument. The calculations are interrupted with zero setTimeout at the given interruptSteps to avoid freezing the browser. Encoding is optional. scrypt(password, salt, logN, r, dkLen, callback, [encoding]) Same as first, but uses default interruptStep (1000). Encoding is optional. scrypt(password, salt, logN, r, dkLen, [encoding]) -> returns result Synchronous: doesn't interrupt calculations and returns the result instead of passing it to callback. Encoding is optional. Perfect for use in web workers.
If interruptStep is <= 0, avoid calling setTimeout, and calculate result immediately, passing it to callback.
|
All right, let's drop this sync thing for now and just merge setTimeout avoidance: #15. |
Now there are three general ways to call scrypt:
scrypt(password, salt, logN, r, dkLen, interruptStep, callback, [encoding])
Derives a key from password and salt and calls callback with derived key
as the only argument. The calculations are interrupted with zero
setTimeout at the given interruptSteps to avoid freezing the browser.
Encoding is optional.
scrypt(password, salt, logN, r, dkLen, callback, [encoding])
Same as first, but uses default interruptStep (1000). Encoding is
optional.
scrypt(password, salt, logN, r, dkLen, [encoding]) -> returns result
Synchronous: doesn't interrupt calculations and returns the result
instead of passing it to callback. Encoding is optional. Perfect for use
in web workers.