Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

index.js 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. var wif = require('../')
  2. var fixtures = require('./fixtures')
  3. var tape = require('tape')
  4. fixtures.valid.forEach(function (f) {
  5. tape('encode/encodeRaw returns ' + f.WIF + ' for ' + f.privateKeyHex.slice(0, 20) + '... (' + f.version + ')', function (t) {
  6. t.plan(1)
  7. var privateKey = new Buffer(f.privateKeyHex, 'hex')
  8. var actual = wif.encode(f.version, privateKey, f.compressed)
  9. t.equal(actual, f.WIF)
  10. })
  11. })
  12. fixtures.valid.forEach(function (f) {
  13. tape('decode/decodeRaw returns ' + f.privateKeyHex.slice(0, 20) + '... (' + f.version + ')' + ' for ' + f.WIF, function (t) {
  14. t.plan(3)
  15. var actual = wif.decode(f.WIF, f.version)
  16. t.equal(actual.version, f.version)
  17. t.equal(actual.privateKey.toString('hex'), f.privateKeyHex)
  18. t.equal(actual.compressed, f.compressed)
  19. })
  20. })
  21. fixtures.invalid.decode.forEach(function (f) {
  22. tape('throws ' + f.exception + ' for ' + f.WIF, function (t) {
  23. t.plan(1)
  24. t.throws(function () {
  25. wif.decode(f.WIF, f.version)
  26. }, new RegExp(f.exception))
  27. })
  28. })
  29. fixtures.valid.forEach(function (f) {
  30. tape('decode/encode for ' + f.WIF, function (t) {
  31. t.plan(1)
  32. var actual = wif.encode(wif.decode(f.WIF, f.version))
  33. t.equal(actual, f.WIF)
  34. })
  35. })