import { md5 as md5js } from "js-md5" import { blobToArrayBuffer, isBlob } from "../../bit" import { base58 } from "./base58" export function md5( data: Blob, options: { outMore: true } ): Promise<{ base64: string; base58: string; hex: string; arrayBuffer: ArrayBuffer }> export function md5(data: Blob, options?: { outBase64?: boolean }): Promise export function md5(data: string | ArrayBuffer, options?: { outBase64?: boolean }): string export function md5( data: string | ArrayBuffer, options: { outMore: true } ): { base64: string; base58: string; hex: string; arrayBuffer: ArrayBuffer } export function md5(data: string | ArrayBuffer | Blob, options?: { outBase64?: boolean; outMore?: boolean }) { if (isBlob(data)) { return blobToArrayBuffer(data).then((arrayBuffer) => { return md5(arrayBuffer, options) }) } else { if (options?.outBase64) { return md5js.base64(data) } else if (options?.outMore) { var md5_hash = md5js.create() md5_hash.update(data) let arrayBuffer = md5_hash.arrayBuffer() return { base64: md5_hash.base64(), base58: base58.encode(arrayBuffer), arrayBuffer: arrayBuffer, hex: md5_hash.hex(), } } else { return md5js.hex(data) } } } const MD5 = md5 export { MD5 }