I am trying to port a pre-existing NodeJS project to NestJS.
Rather than using require I am importing the library like so:
import * as crypto from 'crypto';
Most of the code works. However I am having issues with the following line:
const hash_digest = hash.update(nonce + message).digest('binary');
The issue is "binary" does not appear to be a valid type. And indeed when I click through into the source located at node_modules/@types/node/crypto.d.ts, I see BinaryToTextEncoding = 'base64' | 'hex'; are the only valid types for the digest method.
However, when I read the documentation it states:
hash.digest([encoding])
Calculates the digest of all of the passed data to be hashed. The encoding can be 'hex', 'binary' or 'base64'.
So is this a difference between the "node" and "nestJS" versions of this library or what am I missing?
And if this is not a valid approach, how else to solve this problem? As it stands now, my nonce gets rejected as invalid if I try any of the following:
const hash_digest = hash.update(nonce + message, 'binary').digest();
const hash_digest = hash.update(nonce + message).digest();
const hash_digest = hash.update(nonce + message, 'binary');
hash_digest = hash.update(nonce + message).digest(<BinaryToTextEncoding>'binary');