ECPair: remove use of assert

This commit is contained in:
Daniel Cousens 2015-08-11 17:03:10 +10:00
parent 254b670427
commit 8f821f4768

View file

@ -1,4 +1,3 @@
var assert = require('assert')
var bs58check = require('bs58check') var bs58check = require('bs58check')
var bcrypto = require('./crypto') var bcrypto = require('./crypto')
var ecdsa = require('./ecdsa') var ecdsa = require('./ecdsa')
@ -63,7 +62,7 @@ ECPair.fromWIF = function (string, networks) {
var compressed var compressed
if (payload.length === 34) { if (payload.length === 34) {
assert.strictEqual(payload[33], 0x01, 'Invalid compression flag') if (payload[33] !== 0x01) throw new Error('Invalid compression flag')
// truncate the version/compression bytes // truncate the version/compression bytes
payload = payload.slice(1, -1) payload = payload.slice(1, -1)
@ -71,7 +70,7 @@ ECPair.fromWIF = function (string, networks) {
// no compression flag // no compression flag
} else { } else {
assert.equal(payload.length, 33, 'Invalid WIF payload length') if (payload.length !== 33) throw new Error('Invalid WIF payload length')
// Truncate the version byte // Truncate the version byte
payload = payload.slice(1) payload = payload.slice(1)
@ -115,7 +114,7 @@ ECPair.makeRandom = function (options) {
} }
ECPair.prototype.toWIF = function () { ECPair.prototype.toWIF = function () {
assert(this.d, 'Missing private key') if (!this.d) throw new Error('Missing private key')
var bufferLen = this.compressed ? 34 : 33 var bufferLen = this.compressed ? 34 : 33
var buffer = new Buffer(bufferLen) var buffer = new Buffer(bufferLen)
@ -146,7 +145,7 @@ ECPair.prototype.getPublicKeyBuffer = function () {
} }
ECPair.prototype.sign = function (hash) { ECPair.prototype.sign = function (hash) {
assert(this.d, 'Missing private key') if (!this.d) throw new Error('Missing private key')
return ecdsa.sign(ECPair.curve, hash, this.d) return ecdsa.sign(ECPair.curve, hash, this.d)
} }