scrypt-kdf
scrypt-kdf copied to clipboard
Buffer.from() does not appear to work
I attempted to incorporate version 2.0.1 of this library into my project, but hit a snag in the following code:
import scrypt from 'scrypt-kdf'
...
const storedKdf = Buffer.from(storedPassword, 'hex');
return scrypt.verify(storedKdf, passwordToTest);
which results in an error on this line in the scrypt library: https://github.com/chrisveness/scrypt-kdf/blob/f557392d652c809a9a7a322fa55893958733d59c/scrypt.js#L126
I initially thought it was my use of 'hex' as the encoding, but changing both the password storage and decoding to 'base64' yields the same error. As far as I know a Node.js Buffer object is also an instance of Uint8Array, so I'm wondering what's causing this issue.
Could you try checking the types & values of storedPassword & storedKdf: i.e.
console.log('storedPassword', typeof storedPassword, storedPassword);
console.log('storedKdf', typeof storedKdf, storedKdf);
@mdhornet90
I ran into a similar issue when writing unit tests with Jest for this lib. So if you've this issue when running tests it's probably not scrypt-kdf.
https://github.com/facebook/jest/issues/4422
@Jimjardland thanks for that suggestion: I don't think I would have worked that one out!
@mdhornet90 would that explain your issues? Are you using Jest for your tests?
I have added an indication of the type received to the parameter type checks to assist with any such issues in the future.
@Jimjardland I ran into the same issue. Could you please share your solution?
@alexeychikk
Sorry for the later answer, didn't notice until now.
I made a custom Jest environment where i included Uint8Array and ArrayBuffer.
You can find it here: https://github.com/Jimjardland/custom-jest-environment