git ssb

0+

wanderer🌟 / js-primea-hypervisor



Tree: 7ffc2533d01f9b747d1e93544fa339e5573f9b12

Files: 7ffc2533d01f9b747d1e93544fa339e5573f9b12 / 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