5 changed files with 6 additions and 85 deletions
@ -1,33 +0,0 @@ |
|||||
'use strict'; |
|
||||
|
|
||||
var Bn = require('./bn'); |
|
||||
var Point = require('./point'); |
|
||||
var Hash = require('./hash'); |
|
||||
var Privkey = require('../privkey'); |
|
||||
var Keypair = require('../keypair'); |
|
||||
|
|
||||
function KDF() { |
|
||||
} |
|
||||
|
|
||||
KDF.buf2keypair = function(buf) { |
|
||||
return KDF.sha256hmac2keypair(buf); |
|
||||
}; |
|
||||
|
|
||||
KDF.sha256hmac2keypair = function(buf) { |
|
||||
var privkey = KDF.sha256hmac2privkey(buf); |
|
||||
var keypair = Keypair().fromPrivkey(privkey); |
|
||||
return keypair; |
|
||||
}; |
|
||||
|
|
||||
KDF.sha256hmac2privkey = function(buf) { |
|
||||
var bn; |
|
||||
var concat = new Buffer([]); |
|
||||
do { |
|
||||
var hash = Hash.sha256hmac(buf, concat); |
|
||||
var bn = Bn.fromBuffer(hash); |
|
||||
concat = Buffer.concat([concat, new Buffer(0)]); |
|
||||
} while(!bn.lt(Point.getN())); |
|
||||
return new Privkey({bn: bn}); |
|
||||
}; |
|
||||
|
|
||||
module.exports = KDF; |
|
@ -1,42 +0,0 @@ |
|||||
'use strict'; |
|
||||
|
|
||||
var should = require('chai').should(); |
|
||||
var bitcore = require('bitcore'); |
|
||||
var KDF = bitcore.KDF; |
|
||||
var Hash = bitcore.Hash; |
|
||||
|
|
||||
describe('KDF', function() { |
|
||||
|
|
||||
describe('#buf2keypair', function() { |
|
||||
|
|
||||
it('should compute these known values', function() { |
|
||||
var buf = Hash.sha256(new Buffer('test')); |
|
||||
var keypair = KDF.buf2keypair(buf); |
|
||||
keypair.privkey.toString().should.equal('KxxVszVMFLGzmxpxR7sMSaWDmqMKLVhKebX5vZbGHyuR8spreQ7V'); |
|
||||
keypair.pubkey.toString().should.equal('03774f761ae89a0d2fda0d532bad62286ae8fcda9bc38c060036296085592a97c1'); |
|
||||
}); |
|
||||
|
|
||||
}); |
|
||||
|
|
||||
describe('#sha256hmac2keypair', function() { |
|
||||
|
|
||||
it('should compute these known values', function() { |
|
||||
var buf = Hash.sha256(new Buffer('test')); |
|
||||
var keypair = KDF.sha256hmac2keypair(buf); |
|
||||
keypair.privkey.toString().should.equal('KxxVszVMFLGzmxpxR7sMSaWDmqMKLVhKebX5vZbGHyuR8spreQ7V'); |
|
||||
keypair.pubkey.toString().should.equal('03774f761ae89a0d2fda0d532bad62286ae8fcda9bc38c060036296085592a97c1'); |
|
||||
}); |
|
||||
|
|
||||
}); |
|
||||
|
|
||||
describe('#sha256hmac2privkey', function() { |
|
||||
|
|
||||
it('should compute this known privkey', function() { |
|
||||
var buf = Hash.sha256(new Buffer('test')); |
|
||||
var privkey = KDF.sha256hmac2privkey(buf); |
|
||||
privkey.toString().should.equal('KxxVszVMFLGzmxpxR7sMSaWDmqMKLVhKebX5vZbGHyuR8spreQ7V'); |
|
||||
}); |
|
||||
|
|
||||
}); |
|
||||
|
|
||||
}); |
|
Loading…
Reference in new issue