Closed ahtremblay closed 3 years ago
compilerOptions
:"module": "ES2020",
"moduleResolution": "node",
something.ts
:import * as secp256k1 from 'tiny-secp256k1';
console.log(
// One of the methods of the library, will return true if working.
secp256k1.isPrivate(
Buffer.from(
// Random 32 byte key
'f816cde505015173a81858e5969ac9f2' +
'99b3d15ad9f1d9806c230cfdf0e7739f',
'hex',
),
),
);
node something.js
(if you named it something.ts
)Note: ts-node
is broken in regards to ES modules, so running something.ts via ts-node something.ts
doesn't work.
@junderw
Thank you for the response.
Your example code on line 4 return 'true', so it is working. However the line:
import * as secp256k1 from 'tiny-secp256k1';
produces this error in the IDE:
TS7016: Could not find a declaration file for module 'tiny-secp256k1'. '/Users/alexandreharvey-tremblay/Dropbox/software/cryptocom/node_modules/tiny-secp256k1/index.js' implicitly has an 'any' type. Try
npm i --save-dev @types/tiny-secp256k1if it exists or add a new declaration (.d.ts) file containing
declare module 'tiny-secp256k1';``
Something to worry about?
Are you sure you're using v2.0.0 of this library?
Also, is "moduleResolution": "node",
in your tsconfig?
v2.0.0 has type definitions and you don't need to install any types separately.
@junderw
You are correct it has installed "tiny-secp256k1": "^1.1.6"
but I did run
npm install tiny-secp256k1
now having run
npm install tiny-secp256k1@latest
it has installed "tiny-secp256k1": "^2.0.0"
and the error is gone.
Thanks.
I have run
npm install tiny-secp256k1
How do I then import it into a typescript file? This does not work.
import * as secp256k1 from "secp256k1";
This does not work either:
import * as any from "tiny-secp256k1";
Finally, I have tried
npm i --save-dev @types/tiny-secp256k1
but it outputs: npm WARN deprecated @types/tiny-secp256k1@2.0.1: This is a stub types definition. tiny-secp256k1 provides its own type definitions, so you do not need this installed.