0

For reference, I am using React 16.9.0 and Typescript 3.5.3.

On this question Are there any SHA-256 javascript implementations that are generally considered trustworthy?, I learned about the forge node application to create 256 hashes from strings.

Here, you can find the implementation and usage of the sha256 function:

  1. https://github.com/digitalbazaar/forge/blob/master/lib/sha256.js
  2. https://github.com/digitalbazaar/forge#sha256

However, I cannot manage to import it on my create-react-app project with Typescript.

I installed the forge library with these commands:

npm install node-forge
npm install @types/node-forge

And when I try to import it, Typescript keeps telling me:

TypeScript error in /src/App.tsx(2,10):
Module '"node-forge"' has no exported member 'forge'.  TS2305

    1 | import React from 'react';
  > 2 | import { forge } from 'node-forge';
      |          ^
    3 | import './App.css';
    4 | 

How can I correctly import the forge hash library in my create-react-app project, so I can create a hash with this:

var md = forge.md.sha256.create();
md.update('The quick brown fox jumps over the lazy dog');
console.log(md.digest().toHex());
// output: d7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592
4
  • 2
    Have you tried import * as forge from 'node-forge'? Commented Sep 17, 2019 at 18:42
  • and what do you mean by "trustworthy"? If you mean "produces correct results", then you could test out a package by running it & checking the results against known values. If you mean something else, you should explain further. Commented Sep 17, 2019 at 18:45
  • @Kryten, I did not write trustworthy, who wrote trustworthy is the guy on the question I am linking. Commented Sep 17, 2019 at 18:53
  • Sorry, I misread the question! Commented Sep 17, 2019 at 18:57

1 Answer 1

1

What about import forge from 'node-forge' or import * as forge from "node-forge"; . Or you just use different library. For instance: bcrypt

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.