add hash as buffer

This commit is contained in:
2022-10-14 13:31:52 +02:00
parent 7a6a24d631
commit 0c08dcc678
5 changed files with 75 additions and 15 deletions

View File

@@ -1,4 +1,4 @@
import { hash, Hashes } from '../dist/esm/index.js'
import { Bytes, hash, Hashes, Hex } from '../dist/esm/index.js'
import { Precomputed } from './values.js'
describe('Hash', () => {
@@ -6,10 +6,17 @@ describe('Hash', () => {
describe(type, () => {
const values = Precomputed.Hash[type]
for (const [input, output] of Object.entries(values)) {
it(`Should hash ${input} to ${output}`, async () => {
it(`Should hash "${input}" to "${output.slice(0, 8)}..."`, async () => {
const hashed = await hash(input, Hashes[type])
chai.expect(hashed).to.equal(output)
})
it(`Should hash "${input}" to "${output.slice(0, 8)}..." as buffer`, async () => {
const outputBuffer = Hex.decode(output)
const inputBuffer = Bytes.encode(input)
const hashed = await hash(inputBuffer, Hashes[type])
chai.expect(hashed).to.deep.equal(outputBuffer)
})
}
})
}