bitcoinjs-lib/test/crypto.spec.ts

34 lines
1.1 KiB
TypeScript
Raw Permalink Normal View History

import * as assert from 'assert';
import { describe, it } from 'mocha';
import { crypto as bcrypto, TaggedHashPrefix } from '..';
import * as fixtures from './fixtures/crypto.json';
2014-04-08 15:39:22 +02:00
describe('crypto', () => {
['hash160', 'hash256', 'ripemd160', 'sha1', 'sha256'].forEach(algorithm => {
describe(algorithm, () => {
fixtures.hashes.forEach(f => {
const fn = (bcrypto as any)[algorithm];
const expected = (f as any)[algorithm];
2014-09-20 03:20:55 +02:00
it('returns ' + expected + ' for ' + f.hex, () => {
const data = Buffer.from(f.hex, 'hex');
const actual = fn(data).toString('hex');
2014-09-20 03:20:55 +02:00
assert.strictEqual(actual, expected);
});
});
});
});
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'));
});
});
});
});