-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(node:crypto): properly call web crypto methods (#122)
* Add deno compatibility to the webCrypto node implementation * refactor: simplify and decouple node proxy * simplify type * reorder export --------- Co-authored-by: Pooya Parsa <pooya@pi0.io>
- Loading branch information
1 parent
10781a4
commit 2fcf9b8
Showing
2 changed files
with
15 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,12 @@ | ||
// https://nodejs.org/api/crypto.html | ||
// https://github.com/unjs/uncrypto | ||
import type nodeCrypto from "node:crypto"; | ||
|
||
export const CryptoKey = | ||
globalThis.CryptoKey as unknown as typeof nodeCrypto.webcrypto.CryptoKey; | ||
|
||
export const webcrypto: Crypto & typeof nodeCrypto.webcrypto = { | ||
CryptoKey, | ||
...globalThis.crypto, | ||
}; | ||
|
||
export const subtle: SubtleCrypto = webcrypto.subtle; | ||
export const subtle: SubtleCrypto = globalThis.crypto?.subtle; | ||
|
||
export const randomUUID: Crypto["randomUUID"] = () => { | ||
return webcrypto.randomUUID(); | ||
return globalThis.crypto?.randomUUID(); | ||
}; | ||
|
||
export const getRandomValues: Crypto["getRandomValues"] = (array: any) => { | ||
return webcrypto.getRandomValues(array); | ||
return globalThis.crypto?.getRandomValues(array); | ||
}; |