use bn.toBuffer.

This commit is contained in:
Christopher Jeffrey 2016-03-21 21:57:20 -07:00
parent 304bd9f786
commit 43923e3201
8 changed files with 14 additions and 10 deletions

View File

@ -252,7 +252,7 @@ ChainBlock.prototype.toRaw = function toRaw() {
p.writeU32(this.bits);
p.writeU32(this.nonce);
p.writeU32(this.height);
p.writeBytes(new Buffer(this.chainwork.toArray('le', 32)));
p.writeBytes(this.chainwork.toBuffer('le', 32));
return p.render();
};

View File

@ -37,7 +37,7 @@ ec.generatePrivateKey = function generatePrivateKey() {
} while (!secp256k1.privateKeyVerify(priv));
} else {
key = ec.elliptic.genKeyPair();
priv = new Buffer(key.getPrivate().toArray('be', 32));
priv = key.getPrivate().toBuffer('be', 32);
}
return priv;

View File

@ -579,10 +579,10 @@ HDPrivateKey.prototype.derive = function derive(index, hardened) {
leftPart = new bn(hash.slice(0, 32));
chainCode = hash.slice(32, 64);
privateKey = new Buffer(leftPart
privateKey = leftPart
.add(new bn(this.privateKey))
.mod(ec.elliptic.curve.n)
.toArray('be', 32));
.toBuffer('be', 32);
if (!this.fingerPrint) {
this.fingerPrint = utils.ripesha(this.publicKey)

View File

@ -226,7 +226,7 @@ Miner.prototype.createBlock = function createBlock() {
// of ours. This isn't really
// necessary nowdays due to bip34
// (used above).
new Buffer(utils.nonce().toArray()),
utils.nonce().toBuffer(),
// Let the world know this little
// miner succeeded.
new Buffer(this.coinbaseFlags || 'mined by bcoin', 'ascii')
@ -276,7 +276,7 @@ Miner.prototype.updateCoinbase = function updateCoinbase(block) {
if (!block)
block = this.block;
coinbase.inputs[0].script[1] = new Buffer(block.extraNonce.toArray());
coinbase.inputs[0].script[1] = block.extraNonce.toBuffer();
coinbase.outputs[0].value = reward.add(this.fee);
};

View File

@ -38,8 +38,6 @@ function Output(options, tx) {
// Numbers, do not allow negative values.
assert(typeof value !== 'number');
assert(!this.value.isNeg());
assert(this.value.bitLength() <= 63);
assert(!(this.value.toArray('be', 8)[0] & 0x80));
}
Output.prototype.__defineGetter__('type', function() {

View File

@ -1188,7 +1188,7 @@ Script.array = function(value) {
if (value.cmpn(0) === 0)
return new Buffer([]);
return new Buffer(value.toArray('le'));
return value.toBuffer('le');
};
Script.prototype.removeData = function removeData(data) {

View File

@ -1912,3 +1912,9 @@ SyncBatch.prototype.clear = function clear() {
};
utils.SyncBatch = SyncBatch;
if (utils.isBrowser) {
bn.prototype.toBuffer = function toBuffer(order, size) {
return new Buffer(this.toArray(order, size));
};
}

View File

@ -209,7 +209,7 @@ function createBody(name, items) {
} else if (item instanceof bcoin.coin) {
p.writeU8(8);
p.writeVarBytes(item.toExtended());
} else if (item instanceof bn)
} else if (item instanceof bn) {
p.writeU8(9);
p.writeVarBytes(item.toBuffer());
} else if (Buffer.isBuffer(item)) {