Files: 69097f452f01a61429f16530219f9f1dc548b8d3 / deps / address.js
925 bytesRaw
1 | const BN = require('bn.js') |
2 | const U256 = require('./u256.js') |
3 | |
4 | module.exports = class Address extends U256 { |
5 | constructor (value) { |
6 | super(value) |
7 | if (this._value.byteLength() > 20) { |
8 | throw new Error('Invalid address length: ' + this._value.byteLength() + ' for ' + value) |
9 | } |
10 | } |
11 | |
12 | // This assumes Uint8Array in LSB (WASM code) |
13 | static fromMemory (value) { |
14 | return new Address(new BN(value, 16, 'le')) |
15 | } |
16 | |
17 | // This assumes Uint8Array in LSB (WASM code) |
18 | toMemory () { |
19 | return this._value.toBuffer('le', 20) |
20 | } |
21 | |
22 | toBuffer () { |
23 | return super.toBuffer(20) |
24 | } |
25 | |
26 | // Needs to be displayed as a hex always |
27 | toString () { |
28 | return '0x' + this._value.toString('hex', 40) |
29 | } |
30 | |
31 | static zero () { |
32 | return new Address('0x0000000000000000000000000000000000000000') |
33 | } |
34 | |
35 | isZero () { |
36 | return this._value.isZero() |
37 | } |
38 | |
39 | equals (address) { |
40 | return this.toString() === address.toString() |
41 | } |
42 | } |
43 |
Built with git-ssb-web