2019-09-07 06:42:03 +02:00
|
|
|
import * as assert from 'assert';
|
|
|
|
import { describe, it } from 'mocha';
|
2021-11-12 00:33:18 +01:00
|
|
|
import { crypto as bcrypto, TaggedHashPrefix } from '..';
|
2019-09-07 06:42:03 +02:00
|
|
|
import * as fixtures from './fixtures/crypto.json';
|
2014-04-08 15:39:22 +02:00
|
|
|
|
2019-04-09 08:09:50 +02:00
|
|
|
describe('crypto', () => {
|
|
|
|
['hash160', 'hash256', 'ripemd160', 'sha1', 'sha256'].forEach(algorithm => {
|
|
|
|
describe(algorithm, () => {
|
2021-11-12 00:33:18 +01:00
|
|
|
fixtures.hashes.forEach(f => {
|
2019-09-07 06:42:03 +02:00
|
|
|
const fn = (bcrypto as any)[algorithm];
|
|
|
|
const expected = (f as any)[algorithm];
|
2014-09-20 03:20:55 +02:00
|
|
|
|
2019-04-09 08:09:50 +02:00
|
|
|
it('returns ' + expected + ' for ' + f.hex, () => {
|
2019-09-07 06:42:03 +02:00
|
|
|
const data = Buffer.from(f.hex, 'hex');
|
|
|
|
const actual = fn(data).toString('hex');
|
2014-09-20 03:20:55 +02:00
|
|
|
|
2019-09-07 06:42:03 +02:00
|
|
|
assert.strictEqual(actual, expected);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2021-11-12 00:33:18 +01:00
|
|
|
|
|
|
|
describe('taggedHash', () => {
|
|
|
|
fixtures.taggedHash.forEach(f => {
|
|
|
|
const bytes = Buffer.from(f.hex, 'hex');
|
|
|
|
const expected = Buffer.from(f.result, 'hex');
|
|
|
|
it(`returns ${f.result} for taggedHash "${f.tag}" of ${f.hex}`, () => {
|
|
|
|
const actual = bcrypto.taggedHash(f.tag as TaggedHashPrefix, bytes);
|
|
|
|
assert.strictEqual(actual.toString('hex'), expected.toString('hex'));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2019-09-07 06:42:03 +02:00
|
|
|
});
|