git ssb

0+

wanderer🌟 / js-primea-hypervisor



Tree: 6bd194b9cc65a9636ef49d5e3457cca94318c43a

Files: 6bd194b9cc65a9636ef49d5e3457cca94318c43a / address.js

832 bytesRaw
1const BN = require('bn.js')
2const U256 = require('./u256.js')
3
4module.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 isZero () {
32 return this._value.isZero()
33 }
34
35 equals (address) {
36 return this.toString() === address.toString()
37 }
38}
39

Built with git-ssb-web