git ssb

0+

wanderer🌟 / js-primea-hypervisor



Tree: 32b7b1fd8462def6fab396fe9167b7cdd31fa3fd

Files: 32b7b1fd8462def6fab396fe9167b7cdd31fa3fd / address.js

727 bytesRaw
1const ethUtils = require('ethereumjs-util')
2
3module.exports = class Address {
4 constructor (value) {
5 // Special case: duplicate
6 if (value instanceof Address) {
7 this._value = new Buffer(value._value)
8 return
9 }
10
11 if (typeof value !== 'string') {
12 throw new Error('Invalid input to address')
13 }
14
15 if (!ethUtils.isHexPrefixed(value)) {
16 throw new Error('Invalid address format')
17 }
18
19 this._value = new Buffer(ethUtils.stripHexPrefix(value), 'hex')
20
21 if (this._value.length !== 20) {
22 throw new Error('Invalid address length')
23 }
24 }
25
26 toString () {
27 return '0x' + this._value.toString('hex')
28 }
29
30 isZero () {
31 return this._value.equals(ethUtils.zeros(20))
32 }
33}
34

Built with git-ssb-web