-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: browser compatible webcrypto import
- Loading branch information
1 parent
31cb348
commit bde72e1
Showing
2 changed files
with
17 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export const webcrypto = (() => { | ||
// if we're in node, we need to use | ||
// webcrypto provided by the crypto module | ||
if(typeof window !== 'undefined') { | ||
return window.crypto | ||
} | ||
|
||
if(typeof self !== 'undefined' && self.crypto) { | ||
return self.crypto | ||
} | ||
|
||
const { webcrypto } = require('crypto') | ||
return webcrypto as Crypto | ||
})() |