mirror of
https://github.com/cupcakearmy/occulto.git
synced 2025-09-06 05:00:42 +00:00
2.0.0 (#3)
* rewrite * testing worklflow * sprcify version * config stuff * add hash as buffer * delete docs * use typedarray everywhere and docs * readme * aes * cleanup * rsa * testing with playwright * fix playwright * readme * docs * update deps * use headless * add prepublish * build pipeline * move types up * move types up * add types legacy * packaging * versions bump * cleanup * maybe this time * drop support for commonjs * version bump * cleanup
This commit is contained in:
32
src/crypto/hash.ts
Normal file
32
src/crypto/hash.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { type TypedArray } from '../utils/base.js'
|
||||
import { getCrypto } from './crypto.js'
|
||||
import { Bytes, Hex } from './encoding.js'
|
||||
|
||||
/**
|
||||
* List of available hash functions.
|
||||
*
|
||||
* @remarks
|
||||
* For cryptographic details refer to: https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest#supported_algorithms
|
||||
* Reference: https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf
|
||||
*/
|
||||
export enum Hashes {
|
||||
/**
|
||||
* @remarks SHA-1 is not recommended for new applications as it's not cryptographically secure.
|
||||
*/
|
||||
SHA_1 = 'SHA-1',
|
||||
SHA_256 = 'SHA-256',
|
||||
SHA_384 = 'SHA-384',
|
||||
SHA_512 = 'SHA-512',
|
||||
}
|
||||
|
||||
export class Hash {
|
||||
static async hash(data: string, hash: Hashes): Promise<string>
|
||||
static async hash(data: TypedArray, hash: Hashes): Promise<TypedArray>
|
||||
static async hash(data: string | TypedArray, hash: Hashes): Promise<string | TypedArray> {
|
||||
const isString = typeof data === 'string'
|
||||
const c = await getCrypto()
|
||||
const result = await c.subtle.digest(hash, isString ? Bytes.encode(data) : data)
|
||||
const buf = new Uint8Array(result)
|
||||
return isString ? Hex.encode(buf) : buf
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user