-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
worktop/crypto
module (#11)
* chore: setup `worktop/crypto` submodule * feat(crypto): add `digest` export * feat(crrypto): add named `SHA*` exports
- Loading branch information
Showing
5 changed files
with
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ node_modules | |
|
||
/kv | ||
/cache | ||
/crypto | ||
/base64 | ||
/request | ||
/response | ||
|
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export function digest(algo: 'SHA-1' | 'SHA-256' | 'SHA-384' | 'SHA-512', message: string): Promise<string>; | ||
|
||
export function SHA1(message: string): Promise<string>; | ||
export function SHA256(message: string): Promise<string>; | ||
export function SHA384(message: string): Promise<string>; | ||
export function SHA512(message: string): Promise<string>; |
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,10 @@ | ||
import { encode, toHEX } from 'worktop/utils'; | ||
|
||
export function digest(algo: 'SHA-1' | 'SHA-256' | 'SHA-384' | 'SHA-512', message: string): Promise<string> { | ||
return crypto.subtle.digest(algo, encode(message)).then(toHEX); | ||
} | ||
|
||
export const SHA1 = /*#__PURE__*/ digest.bind(0, 'SHA-1'); | ||
export const SHA256 = /*#__PURE__*/ digest.bind(0, 'SHA-256'); | ||
export const SHA384 = /*#__PURE__*/ digest.bind(0, 'SHA-384'); | ||
export const SHA512 = /*#__PURE__*/ digest.bind(0, 'SHA-512'); |