digitalbazaar / ed25519-verification-key-2020

Javascript library for generating and working with Ed25519VerificationKey2020 key pairs, for use with crypto-ld.
BSD 3-Clause "New" or "Revised" License
3 stars 10 forks source link

Is TypeScript support planned? #22

Closed qertis closed 1 year ago

qertis commented 1 year ago

When initializing my TypeScript project, I encountered an error while using the following import statement:

import { Ed25519VerificationKey2020 } from '@digitalbazaar/ed25519-verification-key-2020'

The error message displayed is:

TS2307: Cannot find module '@digitalbazaar/ed25519-verification-key-2020' or its corresponding type declarations.

To resolve this error, I tried to use @ts-ignore while running the following code:

const newKeyPair = await Ed25519VerificationKey2020.generate({})

But now in browser (Safari, FF) I am encountering a new error:

[Error] Unhandled Promise Rejection: TypeError: undefined is not an object (evaluating 'crypto.web.subtle.digest')

Can you please guide me on how to fix these issues?

dmitrizagidulin commented 1 year ago

Hi @qertis, Try the DCC fork of this library (we've modified it for TypeScript compatibility): https://github.com/digitalcredentials/ed25519-verification-key-2020

qertis commented 1 year ago

Ok, but doesn't work after init.

...
"dependencies": {
  "@digitalcredentials/ed25519-verification-key-2020": "github:digitalcredentials/ed25519-verification-key-2020"
}
...

Screenshot 2023-05-11 at 22 55 35 Screenshot 2023-05-11 at 22 55 09

davidlehn commented 1 year ago

[Error] Unhandled Promise Rejection: TypeError: undefined is not an object (evaluating 'crypto.web.subtle.digest')

Where does crypto.web.subtle.digest come from? It would normally be crypto.subtle.digest in browsers, and crypto.webcrypto.subtle.digest or crypto.subtle.digest in Node.js (depending on your version).

Can you please guide me on how to fix these issues?

We use standard ECMAScript/JavaScript everywhere, and support modern Node.js and browser APIs, so the incompatibilities are likely minimal once TypeScript related tooling understands modern ECMAScript like ESM and similar. We don't have the time and resources to find workarounds for TypeScript tool problems but would appreciate non-invasive patches that fix compatibility issues.

Ok, but doesn't work after init.

...
"dependencies": {
  "@digitalcredentials/ed25519-verification-key-2020": "github:digitalcredentials/ed25519-verification-key-2020"
}
...

I don't know how their fork works, but I think it has a build step, so maybe I suggest trying the published npm version. You should probably ask questions about their fork in their repo.

qertis commented 1 year ago

Okay, thank you for the response. I rolled back to your version without TypeScript, as it is more stable.

I noticed that you are using JSDoc. Have you considered converting your annotations to .d.ts files using automated conversion tools like tsd-jsdoc? They might also help catch errors in your JSDoc annotations.

davidlehn commented 1 year ago

@dmitrizagidulin may be interested in fixing stability issues of their fork.

We don't use TypeScript so probably won't include ts related files or tooling in our process. Sorry about that. We are aware people use those type definitions. I think our hope is that someone else, human or robot, will maintain those in the 3rd party repos of type definitions.

In case you're wondering, we will likely support type defs and similar once they are standardized enough that the tech works natively in browsers and Node.js. That seems to be taking a long time though. Transpiling code and keeping complex toolchains up-to-date on many hundreds of packages is difficult otherwise.

Do we have jsdoc annotation errors? Likely... please report issues if you fine problems.

qertis commented 1 year ago

Thank you for discussion