git ssb

0+

wanderer🌟 / js-primea-hypervisor



Tree: cc2f7e5e75589bab19cc4621f39f35fe4eb262d3

Files: cc2f7e5e75589bab19cc4621f39f35fe4eb262d3 / address.js

526 bytesRaw
1const ethUtils = require('ethereumjs-util')
2
3module.exports = class Address {
4 constructor (value) {
5 if (typeof value !== 'string') {
6 throw new Error('Invalid input to address')
7 }
8
9 if (!ethUtils.isHexPrefixed(value)) {
10 throw new Error('Invalid address format')
11 }
12
13 this._value = new Buffer(ethUtils.stripHexPrefix(value), 'hex')
14
15 if (this._value.length !== 20) {
16 throw new Error('Invalid address length')
17 }
18 }
19
20 toString () {
21 return '0x' + this._value.toString('hex')
22 }
23}
24

Built with git-ssb-web