Thoughts from an ergonomic perspective:
- Base58 is nice and makes easy-to-handle values which is nice
- Naming of shortToken, longToken, and token are confusing to me, because it makes it sound like all of these values are tokens/secrets of some sort, rather than components of the token. Not to bikeshed, but what jumps to my mind is more like "prefix_id_secret", which helps make it clear what role each one plays.
- I don't think keyPrefix should have a default, I think your function should raise an error if it's not provided. Otherwise more than one user of your library is going to end up with "mycompany" keys in the wild.
- You probably ought to validate that keyPrefix does not contain an underscore and raise an exception if it does, otherwise that way lies pain for people trying to handle these keys.
Thoughts from a security perspective:
- You should probably use crypto.timingSafeEquals(buffer, buffer) [1] instead of comparing strings
- If you're trying to store the secret's hash, isn't something like bcrypt/scrypt preferred over raw sha256 these days?
[1] https://nodejs.org/api/crypto.html#cryptotimingsafeequala-b