diff --git a/index.js b/index.js index a9ba432d..073d1c9b 100644 --- a/index.js +++ b/index.js @@ -8,7 +8,7 @@ import junk from 'junk' import joinIterator from 'join-async-iterator' import parallel from 'run-parallel' import queueMicrotask from 'queue-microtask' -import sha1 from 'simple-sha1' +import { sha1 } from 'uint8-util' import 'fast-readable-async-iterator' import getFiles from './get-files.js' // browser exclude diff --git a/package.json b/package.json index 0128a7a3..83c223a1 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "piece-length": "^2.0.1", "queue-microtask": "^1.2.3", "run-parallel": "^1.2.0", - "simple-sha1": "^3.1.0" + "uint8-util": "^1.0.1" }, "devDependencies": { "@webtorrent/semantic-release-config": "1.0.8", diff --git a/test/browser/basic.js b/test/browser/basic.js index 5371c011..edf93a8a 100644 --- a/test/browser/basic.js +++ b/test/browser/basic.js @@ -4,7 +4,7 @@ import fixtures from 'webtorrent-fixtures' import fs from 'fs' import parseTorrent from 'parse-torrent' import path from 'path' -import sha1 from 'simple-sha1' +import { sha1 } from 'uint8-util' import test from 'tape' import createTorrent from '../../index.js' @@ -71,7 +71,9 @@ test('create single file torrent', t => { ]) window.parsedTorrent = parsedTorrent - t.equals(sha1.sync(parsedTorrent.infoBuffer), 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36') + sha1(parsedTorrent.infoBuffer, hash => { + t.equals(hash, 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36') + }) }) }) @@ -117,7 +119,8 @@ test('create multi file torrent', t => { t.deepEquals(parsedTorrent.pieces, [ '1f74648e50a6a6708ec54ab327a163d5536b7ced' ]) - - t.equals(sha1.sync(parsedTorrent.infoBuffer), '80562f38656b385ea78959010e51a2cc9db41ea0') + sha1(parsedTorrent.infoBuffer, hash => { + t.equals(hash, '80562f38656b385ea78959010e51a2cc9db41ea0') + }) }) }) diff --git a/test/browser/directory.js b/test/browser/directory.js index d2a1e979..d409e831 100644 --- a/test/browser/directory.js +++ b/test/browser/directory.js @@ -3,7 +3,7 @@ import fs from 'fs' import parseTorrent from 'parse-torrent' import path from 'path' -import sha1 from 'simple-sha1' +import { sha1 } from 'uint8-util' import test from 'tape' import createTorrent from '../../index.js' diff --git a/test/buffer.js b/test/buffer.js index ccb9be0a..57ae8abd 100644 --- a/test/buffer.js +++ b/test/buffer.js @@ -1,7 +1,7 @@ import createTorrent from '../index.js' import parseTorrent from 'parse-torrent' import path from 'path' -import sha1 from 'simple-sha1' +import { sha1 } from 'uint8-util' import test from 'tape' test('create nested torrent with array of buffers', t => { @@ -42,6 +42,8 @@ test('create nested torrent with array of buffers', t => { t.deepEquals(parsedTorrent.pieces, [ '5bf1fd927dfb8679496a2e6cf00cbe50c1c87145' ]) - t.equals(sha1.sync(parsedTorrent.infoBuffer), '8fa3c08e640db9576156b21f31353402456a0208') + sha1(parsedTorrent.infoBuffer, hash => { + t.equals(hash, '8fa3c08e640db9576156b21f31353402456a0208') + }) }) }) diff --git a/test/fs.js b/test/fs.js index 4c28aebe..bfd35b77 100644 --- a/test/fs.js +++ b/test/fs.js @@ -1,7 +1,7 @@ import fixtures from 'webtorrent-fixtures' import parseTorrent from 'parse-torrent' import path from 'path' -import sha1 from 'simple-sha1' +import { sha1 } from 'uint8-util' import test from 'tape' import createTorrent from '../index.js' @@ -54,7 +54,9 @@ test('create single file torrent', t => { 'c698de9b0dad92980906c026d8c1408fa08fe4ec' ]) - t.equals(sha1.sync(parsedTorrent.infoBuffer), 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36') + sha1(parsedTorrent.infoBuffer, hash => { + t.equals(hash, 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36') + }) }) }) @@ -112,7 +114,9 @@ test('create multi file torrent', t => { t.deepEquals(parsedTorrent.pieces, [ '1f74648e50a6a6708ec54ab327a163d5536b7ced' ]) - t.equals(sha1.sync(parsedTorrent.infoBuffer), '80562f38656b385ea78959010e51a2cc9db41ea0') + sha1(parsedTorrent.infoBuffer, hash => { + t.equals(hash, '80562f38656b385ea78959010e51a2cc9db41ea0') + }) }) }) @@ -165,8 +169,9 @@ test('create multi file torrent with nested directories', t => { t.deepEquals(parsedTorrent.pieces, [ '47972f2befaee58b6f3860cd39bd56cb33a488f0' ]) - - t.equals(sha1.sync(parsedTorrent.infoBuffer), '427887e9c03e123f9c8458b1947090edf1c75baa') + sha1(parsedTorrent.infoBuffer, hash => { + t.equals(hash, '427887e9c03e123f9c8458b1947090edf1c75baa') + }) }) }) @@ -225,6 +230,8 @@ test('create multi file torrent with array of paths', t => { t.deepEquals(parsedTorrent.pieces, [ '1c4e1ba6da4d771ff82025d7cf76e8c368c6c3dd' ]) - t.equals(sha1.sync(parsedTorrent.infoBuffer), 'df25a2959378892f6ddaf4a2d7e75174e09878bb') + sha1(parsedTorrent.infoBuffer, hash => { + t.equals(hash, 'df25a2959378892f6ddaf4a2d7e75174e09878bb') + }) }) }) diff --git a/test/mixed.js b/test/mixed.js index b3b620fa..e555731b 100644 --- a/test/mixed.js +++ b/test/mixed.js @@ -2,7 +2,7 @@ import fixtures from 'webtorrent-fixtures' import fs from 'fs' import parseTorrent from 'parse-torrent' import path from 'path' -import sha1 from 'simple-sha1' +import { sha1 } from 'uint8-util' import test from 'tape' import createTorrent from '../index.js' @@ -65,6 +65,8 @@ test('create multi file torrent with array of mixed types', t => { t.deepEquals(parsedTorrent.pieces, [ '9ad893bb9aeca601a0fab4ba85bd4a4c18b630e3' ]) - t.equals(sha1.sync(parsedTorrent.infoBuffer), 'bad3f8ea0d1d8a55c18a039dd464f1078f83dba2') + sha1(parsedTorrent.infoBuffer, hash => { + t.equals(hash, 'bad3f8ea0d1d8a55c18a039dd464f1078f83dba2') + }) }) }) diff --git a/test/source.js b/test/source.js index 9888f0f5..85dfbc1c 100644 --- a/test/source.js +++ b/test/source.js @@ -1,7 +1,7 @@ import { join } from 'path' import fixtures from 'webtorrent-fixtures' import parseTorrent from 'parse-torrent' -import sha1 from 'simple-sha1' +import { sha1 } from 'uint8-util' import test from 'tape' import createTorrent from '../index.js' @@ -36,8 +36,9 @@ test('verify info-hash without no source set (default)', t => { t.equal(parsedTorrent.pieceLength, 262144) t.deepEquals(parsedTorrent.pieces, ['799c11e348d39f1704022b8354502e2f81f3c037']) - - t.equals(sha1.sync(parsedTorrent.infoBuffer), 'b4dfce1f956f720c928535ded617d07696a819ef', 'mktorrent hash with no source') + sha1(parsedTorrent.infoBuffer, hash => { + t.equals(hash, 'b4dfce1f956f720c928535ded617d07696a819ef', 'mktorrent hash with no source') + }) }) }) @@ -72,7 +73,8 @@ test('verify info-hash an additional source attribute set on the info dict (a wa t.equal(parsedTorrent.pieceLength, 262144) t.deepEquals(parsedTorrent.pieces, ['799c11e348d39f1704022b8354502e2f81f3c037']) - - t.equals(sha1.sync(parsedTorrent.infoBuffer), 'a9499b56289356a3d5b8636387deb83709b8fa42', 'mktorrent run with -s SOURCE') + sha1(parsedTorrent.infoBuffer, hash => { + t.equals(hash, 'a9499b56289356a3d5b8636387deb83709b8fa42', 'mktorrent run with -s SOURCE') + }) }) }) diff --git a/test/stream.js b/test/stream.js index d8449957..a897b0bd 100644 --- a/test/stream.js +++ b/test/stream.js @@ -2,7 +2,7 @@ import fixtures from 'webtorrent-fixtures' import fs from 'fs' import parseTorrent from 'parse-torrent' import path from 'path' -import sha1 from 'simple-sha1' +import { sha1 } from 'uint8-util' import test from 'tape' import createTorrent from '../index.js' @@ -57,8 +57,9 @@ test('create single file torrent from a stream', t => { '56dcc242d03293e9446cf5e457d8eb3d9588fd90', 'c698de9b0dad92980906c026d8c1408fa08fe4ec' ]) - - t.equals(sha1.sync(parsedTorrent.infoBuffer), 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36') + sha1(parsedTorrent.infoBuffer, hash => { + t.equals(hash, 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36') + }) }) }) @@ -111,7 +112,9 @@ test('create multi file torrent with streams', t => { t.deepEquals(parsedTorrent.pieces, [ '1f74648e50a6a6708ec54ab327a163d5536b7ced' ]) - t.equals(sha1.sync(parsedTorrent.infoBuffer), '80562f38656b385ea78959010e51a2cc9db41ea0') + sha1(parsedTorrent.infoBuffer, hash => { + t.equals(hash, '80562f38656b385ea78959010e51a2cc9db41ea0') + }) }) })