2014-04-17 23:31:45 +10:00
|
|
|
var assert = require('assert')
|
2014-04-04 05:10:12 +11:00
|
|
|
var base58check = require('./base58check')
|
2013-02-17 00:39:15 -05:00
|
|
|
|
2014-04-17 23:31:45 +10:00
|
|
|
function Address(hash, version) {
|
2014-04-18 06:48:40 +10:00
|
|
|
assert(Buffer.isBuffer(hash), 'First argument must be a Buffer')
|
|
|
|
assert.strictEqual(hash.length, 20, 'Invalid hash length')
|
|
|
|
assert.strictEqual(version & 0xFF, version, 'Invalid version byte')
|
2013-10-21 14:00:31 -04:00
|
|
|
|
2014-04-17 23:31:45 +10:00
|
|
|
this.hash = hash
|
|
|
|
this.version = version
|
2014-03-25 20:57:19 +01:00
|
|
|
}
|
|
|
|
|
2014-04-20 04:38:33 +10:00
|
|
|
// Import functions
|
2014-04-17 23:31:45 +10:00
|
|
|
Address.fromBase58Check = function(string) {
|
|
|
|
var decode = base58check.decode(string)
|
|
|
|
|
|
|
|
return new Address(decode.payload, decode.version)
|
2014-03-25 20:57:19 +01:00
|
|
|
}
|
2014-04-20 04:38:33 +10:00
|
|
|
Address.prototype.fromString = Address.prototype.fromBase58Check
|
2013-10-07 08:21:00 -04:00
|
|
|
|
2014-04-17 23:31:45 +10:00
|
|
|
// Export functions
|
|
|
|
Address.prototype.toBase58Check = function () {
|
|
|
|
return base58check.encode(this.hash, this.version)
|
2014-03-25 20:57:19 +01:00
|
|
|
}
|
2014-04-17 23:31:45 +10:00
|
|
|
Address.prototype.toString = Address.prototype.toBase58Check
|
2011-05-04 17:02:56 +01:00
|
|
|
|
2014-03-25 20:57:19 +01:00
|
|
|
module.exports = Address
|