Merge pull request #374 from maraoz/add/problematic-example
fix eckey.cc to handle private keys starting with 0 correctly
This commit is contained in:
commit
8fb098e5dd
26939
browser/bundle.js
26939
browser/bundle.js
File diff suppressed because one or more lines are too long
|
@ -45,7 +45,6 @@ var base58 = {
|
|||
if(str.length == 0) return zerobuf;
|
||||
var answer = bignum(0);
|
||||
for(var i=0; i<str.length; i++) {
|
||||
answer.mul(58)
|
||||
answer = answer.mul(58);
|
||||
answer = answer.add(ALPHABET_INV[str[i]]);
|
||||
};
|
||||
|
|
|
@ -220,7 +220,7 @@ Key::GetPrivate(Local<String> property, const AccessorInfo& info)
|
|||
return scope.Close(Null());
|
||||
}
|
||||
|
||||
unsigned char *priv = (unsigned char *)malloc(32);
|
||||
unsigned char *priv = (unsigned char *)calloc(32, 1);
|
||||
|
||||
int n = BN_bn2bin(bn, &priv[32 - priv_size]);
|
||||
|
||||
|
@ -291,14 +291,14 @@ Key::GetPublic(Local<String> property, const AccessorInfo& info)
|
|||
int pub_size = i2o_ECPublicKey(key->ec, NULL);
|
||||
if (!pub_size) {
|
||||
// TODO: ERROR: "Error from i2o_ECPublicKey(key->ec, NULL)"
|
||||
return scope.Close(Null());
|
||||
return VException("Error from i2o_ECPublicKey(key->ec, NULL)");
|
||||
}
|
||||
unsigned char *pub_begin, *pub_end;
|
||||
pub_begin = pub_end = (unsigned char *)malloc(pub_size);
|
||||
|
||||
if (i2o_ECPublicKey(key->ec, &pub_end) != pub_size) {
|
||||
// TODO: ERROR: "Error from i2o_ECPublicKey(key->ec, &pub)"
|
||||
return scope.Close(Null());
|
||||
return VException("Error from i2o_ECPublicKey(key->ec, &pub)");
|
||||
}
|
||||
Buffer *pub_buf = Buffer::New(pub_size);
|
||||
memcpy(Buffer::Data(pub_buf), pub_begin, pub_size);
|
||||
|
|
|
@ -306,4 +306,21 @@ describe('HierarchicalKey', function() {
|
|||
});
|
||||
});
|
||||
|
||||
describe('derivation in linux', function() {
|
||||
it('should not be non-deterministic', function(){
|
||||
var hp = 'm/45\'';
|
||||
var sp = 'm/45';
|
||||
|
||||
var hk = new HierarchicalKey('tprv8ZgxMBicQKsPdSF1avR6mXyDj5Uv1XY2UyUHSDpAXQ5TvPN7prGeDppjy4562rBB9gMMAhRfFdJrNDpQ4t69kkqHNEEen3PX1zBJqSehJDH');
|
||||
//hk.derive(sp).extendedPrivateKeyString().should.equal(
|
||||
// 'tprv8cSDV3fVD6wqGoLKykTPhRwWLiwD6WBHvYHYkFvp8PJvApm7HCfY9HH9P6Q6iPaCGNsU3LEqh7iJMN7478TqjkLFnf71f9zBXXd7XoiL7dw');
|
||||
//hk.derive(sp).extendedPrivateKeyString().should.equal(hk.derive(sp).extendedPrivateKeyString());
|
||||
var epk1 = hk.derive(hp).extendedPrivateKeyString();
|
||||
var epk2 = hk.derive(hp).extendedPrivateKeyString();
|
||||
epk1.should.equal(epk2);
|
||||
//hk.derive(hp).extendedPrivateKeyString().should.equal(
|
||||
// 'tprv8cSDV3fdYmUoTNGu4xRTm6qh3DPrNxPZzukM5FPdWoa9m22ALFJVGbjnU7J4TC5t3MJp293GtZWssAPuV1PNWGjXavQTnXy9xW6Lee2X6rd');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -163,4 +163,17 @@ describe('Key', function() {
|
|||
});
|
||||
});
|
||||
|
||||
describe('bug in linux', function() {
|
||||
it('should assign private key starting with 0 properly', function(){
|
||||
var key = new Key();
|
||||
var hex = '000000000000000019fd3ee484410966c7a1f8098069d1f2a3846b409fbb0e76';
|
||||
var pk = new Buffer(hex, 'hex');
|
||||
pk.toString('hex').should.equal(hex);
|
||||
key.private = pk;
|
||||
key.private.toString('hex').should.equal(hex);
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue