-
-
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.
Some refactoring. Improve tree-shaking
- Loading branch information
Showing
10 changed files
with
84 additions
and
88 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
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
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,17 +1,15 @@ | ||
// We use WebCrypto aka globalThis.crypto, which exists in browsers and node.js 16+. | ||
// See utils.ts for details. | ||
declare const globalThis: Record<string, any> | undefined; | ||
const crypto = | ||
typeof globalThis === 'object' && 'crypto' in globalThis ? globalThis.crypto : undefined; | ||
const cr = typeof globalThis === 'object' && 'crypto' in globalThis ? globalThis.crypto : undefined; | ||
|
||
export function randomBytes(bytesLength = 32): Uint8Array { | ||
if (crypto && typeof crypto.getRandomValues === 'function') { | ||
return crypto.getRandomValues(new Uint8Array(bytesLength)); | ||
} | ||
if (cr && typeof cr.getRandomValues === 'function') | ||
return cr.getRandomValues(new Uint8Array(bytesLength)); | ||
throw new Error('crypto.getRandomValues must be defined'); | ||
} | ||
|
||
export function getWebcryptoSubtle() { | ||
if (crypto && typeof crypto.subtle === 'object' && crypto.subtle != null) return crypto.subtle; | ||
if (cr && typeof cr.subtle === 'object' && cr.subtle != null) return cr.subtle; | ||
throw new Error('crypto.subtle must be defined'); | ||
} |
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
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
Oops, something went wrong.