canonical BN notation
This commit is contained in:
parent
5f21059bf8
commit
0eeba8eadb
10
lib/bip32.js
10
lib/bip32.js
|
@ -5,7 +5,7 @@ var Pubkey = require('./pubkey');
|
||||||
var Privkey = require('./privkey');
|
var Privkey = require('./privkey');
|
||||||
var Point = require('./point');
|
var Point = require('./point');
|
||||||
var Random = require('./random');
|
var Random = require('./random');
|
||||||
var bn = require('./bn');
|
var BN = require('./bn');
|
||||||
var constants = require('./constants');
|
var constants = require('./constants');
|
||||||
|
|
||||||
var BIP32 = function BIP32(obj) {
|
var BIP32 = function BIP32(obj) {
|
||||||
|
@ -72,7 +72,7 @@ BIP32.prototype.fromSeed = function(bytes, networkstr) {
|
||||||
this.chaincode = hash.slice(32, 64);
|
this.chaincode = hash.slice(32, 64);
|
||||||
this.version = constants[networkstr].bip32privkey;
|
this.version = constants[networkstr].bip32privkey;
|
||||||
this.keypair = new Keypair();
|
this.keypair = new Keypair();
|
||||||
this.keypair.privkey = new Privkey({bn: bn.fromBuffer(hash.slice(0, 32))});
|
this.keypair.privkey = new Privkey({bn: BN().fromBuffer(hash.slice(0, 32))});
|
||||||
this.keypair.privkey2pubkey();
|
this.keypair.privkey2pubkey();
|
||||||
this.hasprivkey = true;
|
this.hasprivkey = true;
|
||||||
this.pubkeyhash = Hash.sha256ripemd160(this.keypair.pubkey.toBuffer());
|
this.pubkeyhash = Hash.sha256ripemd160(this.keypair.pubkey.toBuffer());
|
||||||
|
@ -106,7 +106,7 @@ BIP32.prototype.initFromBytes = function(bytes) {
|
||||||
|
|
||||||
if (isPrivate && keyBytes[0] == 0) {
|
if (isPrivate && keyBytes[0] == 0) {
|
||||||
this.keypair = new Keypair();
|
this.keypair = new Keypair();
|
||||||
this.keypair.privkey = new Privkey({bn: bn.fromBuffer(keyBytes.slice(1, 33))});
|
this.keypair.privkey = new Privkey({bn: BN().fromBuffer(keyBytes.slice(1, 33))});
|
||||||
this.keypair.privkey2pubkey();
|
this.keypair.privkey2pubkey();
|
||||||
this.pubkeyhash = Hash.sha256ripemd160(this.keypair.pubkey.toBuffer());
|
this.pubkeyhash = Hash.sha256ripemd160(this.keypair.pubkey.toBuffer());
|
||||||
this.hasprivkey = true;
|
this.hasprivkey = true;
|
||||||
|
@ -263,7 +263,7 @@ BIP32.prototype.deriveChild = function(i) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var hash = Hash.sha512hmac(data, this.chaincode);
|
var hash = Hash.sha512hmac(data, this.chaincode);
|
||||||
var il = bn.fromBuffer(hash.slice(0, 32), {size: 32});
|
var il = BN().fromBuffer(hash.slice(0, 32), {size: 32});
|
||||||
var ir = hash.slice(32, 64);
|
var ir = hash.slice(32, 64);
|
||||||
|
|
||||||
// ki = IL + kpar (mod n).
|
// ki = IL + kpar (mod n).
|
||||||
|
@ -280,7 +280,7 @@ BIP32.prototype.deriveChild = function(i) {
|
||||||
} else {
|
} else {
|
||||||
var data = Buffer.concat([this.keypair.pubkey.toBuffer(), ib]);
|
var data = Buffer.concat([this.keypair.pubkey.toBuffer(), ib]);
|
||||||
var hash = Hash.sha512hmac(data, this.chaincode);
|
var hash = Hash.sha512hmac(data, this.chaincode);
|
||||||
var il = bn(hash.slice(0, 32));
|
var il = BN().fromBuffer(hash.slice(0, 32));
|
||||||
var ir = hash.slice(32, 64);
|
var ir = hash.slice(32, 64);
|
||||||
|
|
||||||
// Ki = (IL + kpar)*G = IL*G + Kpar
|
// Ki = (IL + kpar)*G = IL*G + Kpar
|
||||||
|
|
Loading…
Reference in New Issue