Skip to content

Commit e227a54

Browse files
committedMar 3, 2014
Set VER_ACCOUNT_ID on address returned by keypair
Just a decent default, client code can still set_version before base58 encoding.
1 parent 7a88165 commit e227a54

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed
 

‎src/js/ripple/keypair.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ var sjcl = require('./utils').sjcl;
22

33
var UInt160 = require('./uint160').UInt160;
44
var UInt256 = require('./uint256').UInt256;
5+
var Base = require('./base').Base;
56

67
function KeyPair() {
78
this._curve = sjcl.ecc.curves['c256'];
@@ -82,7 +83,9 @@ KeyPair.prototype.get_address = function () {
8283

8384
var hash = SHA256_RIPEMD160(bits);
8485

85-
return UInt160.from_bits(hash);
86+
var address = UInt160.from_bits(hash);
87+
address.set_version(Base.VER_ACCOUNT_ID);
88+
return address;
8689
};
8790

8891
KeyPair.prototype.sign = function (hash) {

‎test/keypair-test.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var assert = require('assert');
2+
var utils = require('./testutils');
3+
var Seed = utils.load_module('seed').Seed;
4+
var config = require('./testutils').get_config();
5+
6+
describe('KeyPair', function() {
7+
it('can generate an address', function () {
8+
var seed = Seed.from_json("masterpassphrase");
9+
var address = seed.get_key().get_address();
10+
assert.strictEqual(address.to_json(), 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
11+
});
12+
});
13+
14+
// vim:sw=2:sts=2:ts=8:et

0 commit comments

Comments
 (0)
Please sign in to comment.