-
Notifications
You must be signed in to change notification settings - Fork 2
[Deno] get code coverage working / solve rare crypto-related failures #129
Comments
Importing it from It replaces
|
I've committed the above change to imports. Code coverage now fails with a deno crash when it's parsing the coverage data. The tests all pass though.
|
Also getting rare test failures where an async op wasn't finished before the test finished, somewhere in the crypto code. Maybe a result of forcing noble-ed25519 to use deno crypto instead of node crypto...
|
noble-ed25519 is indeed calling crypto.web.subtle.digest here, and it is correctly awaiting the result: https://github.com/paulmillr/noble-ed25519/blob/main/index.ts#L835-L839 if (crypto.web) {
const buffer = await crypto.web.subtle.digest('SHA-512', message.buffer);
return new Uint8Array(buffer);
} else if (crypto.node) {
return Uint8Array.from(crypto.node.createHash('sha512').update(message).digest()); But! It should be using the node version of crypto, as seen by running |
Here's the problem, noble-ed25519 is sniffing to see if it's in a browser or in Node: https://github.com/paulmillr/noble-ed25519/blob/main/index.ts#L797-L802 // Global symbol available in browsers only. Ensure we do not depend on @types/dom
declare const self: Record<string, any> | undefined;
const crypto: { node?: any; web?: any } = {
node: nodeCrypto,
web: typeof self === 'object' && 'crypto' in self ? self.crypto : undefined,
}; Deno acts like a browser in this case, but we probably want it to use the node version of its code to avoid crashes. |
related PR: #130 |
I did a little investigating into this this morning.
This makes me think the following:
The good news is ed25519 works and there is no underlying async leak with Deno + linux. This leaves the issue with coverage. I have another motivation for removing the need for an import map from the project: Deno does not automatically detect import maps and we would thus be requiring all downstream users of Earthstar to have an import map for ed25519's sake. I've made an issue for that here. I have another idea to deal with this that I'm going to try now and report back on. |
Please see the above PR, which I think has unravelled this mystery. |
I think this is fixed by #132. The async crypto related failures are definitely fixed, and generating coverage seems to work for me pretty consistently (the trick seems to be always running |
What's the problem you want solved?
deno coverage
doesn't let you specify an import map, so we get this error from inside noble-ed25519:To reproduce this, add to the Makefile:
Is there a solution you'd like to recommend?
Maybe we can import noble-ed25519 through skypack or esm.sh to fix this? It's also a pretty small package, we could just copy it and modify it.
The text was updated successfully, but these errors were encountered: