Skip to content

Commit

Permalink
bn: use toArrayLike instead of toBuffer.
Browse files Browse the repository at this point in the history
  • Loading branch information
chjj committed Aug 16, 2017
1 parent f9eca70 commit d277d55
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/blockchain/chainentry.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ ChainEntry.prototype.toRaw = function toRaw() {
bw.writeU32(this.bits);
bw.writeU32(this.nonce);
bw.writeU32(this.height);
bw.writeBytes(this.chainwork.toBuffer('le', 32));
bw.writeBytes(this.chainwork.toArrayLike(Buffer, 'le', 32));

return bw.render();
};
Expand Down
4 changes: 2 additions & 2 deletions lib/crypto/rsa-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ rsa.decrypt = function decrypt(N, D, m) {
.toRed(BN.red(N))
.redPow(D)
.fromRed()
.toBuffer('be');
.toArrayLike(Buffer, 'be');
};

/**
Expand All @@ -156,7 +156,7 @@ rsa.encrypt = function encrypt(N, e, m) {
.toRed(BN.red(N))
.redPow(e)
.fromRed()
.toBuffer('be');
.toArrayLike(Buffer, 'be');
};

/*
Expand Down
2 changes: 1 addition & 1 deletion lib/crypto/schnorr.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const schnorr = exports;
*/

schnorr.hash = function hash(msg, r) {
const R = r.toBuffer('be', 32);
const R = r.toArrayLike(Buffer, 'be', 32);
const B = POOL64;

R.copy(B, 0);
Expand Down
10 changes: 5 additions & 5 deletions lib/crypto/secp256k1-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ ec.binding = false;

ec.generatePrivateKey = function generatePrivateKey() {
const key = secp256k1.genKeyPair();
return key.getPrivate().toBuffer('be', 32);
return key.getPrivate().toArrayLike(Buffer, 'be', 32);
};

/**
Expand Down Expand Up @@ -82,7 +82,7 @@ ec.privateKeyTweakAdd = function privateKeyTweakAdd(privateKey, tweak) {
const key = new BN(tweak)
.add(new BN(privateKey))
.mod(curve.n)
.toBuffer('be', 32);
.toArrayLike(Buffer, 'be', 32);

// Only a 1 in 2^127 chance of happening.
if (!ec.privateKeyVerify(key))
Expand Down Expand Up @@ -123,7 +123,7 @@ ec.publicKeyTweakAdd = function publicKeyTweakAdd(publicKey, tweak, compress) {
ec.ecdh = function ecdh(pub, priv) {
priv = secp256k1.keyPair({ priv: priv });
pub = secp256k1.keyPair({ pub: pub });
return priv.derive(pub.getPublic()).toBuffer('be', 32);
return priv.derive(pub.getPublic()).toArrayLike(Buffer, 'be', 32);
};

/**
Expand Down Expand Up @@ -243,8 +243,8 @@ ec.fromDER = function fromDER(raw) {
const sig = new Signature(raw);
const out = Buffer.allocUnsafe(64);

sig.r.toBuffer('be', 32).copy(out, 0);
sig.s.toBuffer('be', 32).copy(out, 32);
sig.r.toArrayLike(Buffer, 'be', 32).copy(out, 0);
sig.s.toArrayLike(Buffer, 'be', 32).copy(out, 32);

return out;
};
Expand Down
2 changes: 1 addition & 1 deletion lib/mining/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ common.getTarget = function getTarget(bits) {
if (target.cmpn(0) === 0)
throw new Error('Target is zero.');

return target.toBuffer('le', 32);
return target.toArrayLike(Buffer, 'le', 32);
};

/**
Expand Down

0 comments on commit d277d55

Please sign in to comment.