* 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:
2022-10-18 15:53:43 +02:00
committed by GitHub
parent f1f5e44b54
commit 56a8103582
58 changed files with 2701 additions and 4705 deletions

32
src/crypto/hash.ts Normal file
View 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
}
}