@xylabs/eth-address
Advanced tools
Comparing version 2.11.0 to 2.11.1
'use strict'; | ||
var assert = require('@xylabs/assert'); | ||
var bignumber = require('@xylabs/bignumber'); | ||
var ellipsize = require('./ellipsize.js'); | ||
var EthAddress = require('./EthAddress.js'); | ||
var padHex = require('./padHex.js'); | ||
require('@xylabs/assert'); | ||
require('@xylabs/bignumber'); | ||
const ellipsize = (value, length = 2) => { | ||
const part1 = value.slice(0, length); | ||
const part2 = value.slice(value.length - length, value.length); | ||
return `${part1}...${part2}`; | ||
}; | ||
const padHex = (hex, byteCount) => { | ||
let result = hex; | ||
if (hex.length % 2 !== 0) { | ||
result = `0${hex}`; | ||
} | ||
if (byteCount) { | ||
while (result.length / 2 < byteCount) { | ||
result = `00${result}`; | ||
} | ||
} | ||
return result; | ||
}; | ||
const isEthAddress = (obj) => obj?.type === EthAddress.type; | ||
class EthAddress { | ||
static type = 'EthAddress'; | ||
type = EthAddress.type; | ||
address; | ||
constructor(address) { | ||
this.address = address; | ||
} | ||
static fromString(value, base = 16) { | ||
if (value) { | ||
const bn = new bignumber.BigNumber(value.startsWith('0x') ? value.substring(2) : value, base); | ||
return new EthAddress(bn); | ||
} | ||
} | ||
static parse(value, base) { | ||
if (typeof value === 'string') { | ||
return this.fromString(value, base); | ||
} | ||
} | ||
equals(address) { | ||
if (address) { | ||
let inAddress; | ||
if (typeof address === 'string') { | ||
inAddress = assert.assertEx(EthAddress.fromString(address), 'Bad Address'); | ||
} | ||
else { | ||
inAddress = address; | ||
} | ||
return this.address.eq(inAddress.address); | ||
} | ||
return false; | ||
} | ||
toBigNumber() { | ||
return this.address; | ||
} | ||
toHex() { | ||
return padHex(this.address.toString(16), 20); | ||
} | ||
toJSON() { | ||
return `0x${this.toHex()}`; | ||
} | ||
toLowerCaseString() { | ||
return this.toString().toLowerCase(); | ||
} | ||
toShortString(length = 2) { | ||
return `0x${ellipsize(this.toHex(), length)}`; | ||
} | ||
toString() { | ||
return `0x${this.toHex()}`; | ||
} | ||
} | ||
exports.EthAddress = EthAddress; | ||
exports.ellipsize = ellipsize; | ||
exports.isEthAddress = isEthAddress; | ||
exports.padHex = padHex; | ||
exports.ellipsize = ellipsize.ellipsize; | ||
exports.EthAddress = EthAddress.EthAddress; | ||
exports.isEthAddress = EthAddress.isEthAddress; | ||
exports.padHex = padHex.padHex; | ||
//# sourceMappingURL=index.js.map |
@@ -54,9 +54,9 @@ { | ||
"dependencies": { | ||
"@xylabs/assert": "~2.11.0", | ||
"@xylabs/bignumber": "~2.11.0" | ||
"@xylabs/assert": "~2.11.1", | ||
"@xylabs/bignumber": "~2.11.1" | ||
}, | ||
"devDependencies": { | ||
"@xylabs/ts-scripts-yarn3": "^3.0.0-rc.15", | ||
"@xylabs/tsconfig": "^3.0.0-rc.15", | ||
"@xylabs/tsconfig-jest": "^3.0.0-rc.15" | ||
"@xylabs/ts-scripts-yarn3": "^3.0.0-rc.16", | ||
"@xylabs/tsconfig": "^3.0.0-rc.16", | ||
"@xylabs/tsconfig-jest": "^3.0.0-rc.16" | ||
}, | ||
@@ -71,4 +71,4 @@ "publishConfig": { | ||
"sideEffects": false, | ||
"version": "2.11.0", | ||
"version": "2.11.1", | ||
"packageManager": "yarn@3.3.1" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23561
33
277
1
Updated@xylabs/assert@~2.11.1
Updated@xylabs/bignumber@~2.11.1