kryptein cryptography package for Node.js
think I should prefix this by saying I'm not a JS or Crypto nerd, but am interested in both!  to other people seeing this question, this code/module seems to mostly reimplement the CCM demo at the bottom of the Crypto docs:  https://nodejs.org/api/crypto.html#crypto_ccm_mode

anyway on with a few issues I noticed:


why isn't _iv just returning crypto.randomBytes(iv_size)?  encoding to a string and then getting bytes seems counterproductive at best, it just seems to throw away entropy
why use PBKDF2 over just hashing the secret?  it's not being saved anywhere, and by using the secret as the salt you've just opened it wide up to rainbow table exploitation again.  further, by doing your string encoding things you've just thrown away even more entropy
your use of regexes in _matrix looks suspect.  why not just match against a few common patterns (e.g. /^\w+-\w+-\w+/) and handle the groups explicitly.  allowing modes like ECB at all here looks like a mistake
catching exceptions just to immediately rethrow doesn't seem very useful
can you think of a better name for the member variable flag?  maybe something like is_aead_mode


update:

another big issue just occurred to me; that you're not including any cryptographic details in the structure.  this allows the suite used to be upgraded (e.g. NIST update their recommendations) while maintaining backwards compatibility.  i.e. you should be saying that you're hashing the secret with SHA512, which algorithm was used for encryption, what you've used as a HMAC (if you've used it, CCM already includes its own MAC so HMAC isn't needed).