import { HashFunction , instantiateRustWasm , sha512Base64Bytes , } from '../bin/bin' ; import { base64ToBin } from '../format/format' ; export interface Sha512 extends HashFunction { param rawState readonly final : ( rawState : Uint8Array ) => Uint8Array ; param input readonly hash : ( input : Uint8Array ) => Uint8Array ; /**
     * Begin an incremental sha512 hashing computation.
     *
     * The returned raw state can be provided to `update` with additional input to
     * advance the computation.
     *
     * ## Example
     * ```ts
     * const state1 = sha512.init();
     * const state2 = sha512.update(state1, new Uint8Array([1, 2, 3]));
     * const state3 = sha512.update(state2, new Uint8Array([4, 5, 6]));
     * const hash = sha512.final(state3);
     * ```
     */ readonly init : ( ) => Uint8Array ; param rawState param input readonly update : ( rawState : Uint8Array , input : Uint8Array ) => Uint8Array ; } param webassemblyBytes export const instantiateSha512Bytes = async ( webassemblyBytes ) : Promise < Sha512 > => { const wasm = await instantiateRustWasm ( webassemblyBytes , './sha512' , 'sha512' , 'sha512_init' , 'sha512_update' , 'sha512_final' ) ; return { final : wasm . final , hash : wasm . hash , init : wasm . init , update : wasm . update , } ; } ; export const getEmbeddedSha512Binary = ( ) => base64ToBin ( sha512Base64Bytes ) . buffer ; const cachedSha512 = { } ; /**
 * An ultimately-portable (but slower) version of `instantiateSha512Bytes`
 * which does not require the consumer to provide the sha512 binary buffer.
 */ export const instantiateSha512 = async ( ) : Promise < Sha512 > => { if ( cachedSha512 . cache !== undefined ) { return cachedSha512 . cache ; } const result = instantiateSha512Bytes ( getEmbeddedSha512Binary ( ) ) ; cachedSha512 . cache = result ; return result ; } ;