Browse Source

add address validation convenience function

patch-2
Ryan X. Charles 10 years ago
parent
commit
6b7592d67b
  1. 6
      lib/address.js
  2. 8
      test/test.address.js

6
lib/address.js

@ -10,6 +10,12 @@ function Address(obj) {
this.set(obj); this.set(obj);
}; };
Address.validate = function(addrstr) {
var address = new Address().fromString(addrstr);
address.validate();
return this;
};
Address.prototype.set = function(obj) { Address.prototype.set = function(obj) {
this.hashbuf = obj.hashbuf || this.hashbuf || null; this.hashbuf = obj.hashbuf || this.hashbuf || null;
this.networkstr = obj.networkstr || this.networkstr || 'mainnet'; this.networkstr = obj.networkstr || this.networkstr || 'mainnet';

8
test/test.address.js

@ -12,6 +12,14 @@ describe('Address', function() {
should.exist(address); should.exist(address);
}); });
describe('@validate', function() {
it('should validate this valid address string', function() {
should.exist(Address.validate(str))
});
});
describe('#fromPubkey', function() { describe('#fromPubkey', function() {
it('should make this address from a compressed pubkey', function() { it('should make this address from a compressed pubkey', function() {

Loading…
Cancel
Save