aboutsummaryrefslogtreecommitdiffstats
path: root/packages/utils/src/address_utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/utils/src/address_utils.ts')
-rw-r--r--packages/utils/src/address_utils.ts9
1 files changed, 7 insertions, 2 deletions
diff --git a/packages/utils/src/address_utils.ts b/packages/utils/src/address_utils.ts
index e25bde249..1fc960408 100644
--- a/packages/utils/src/address_utils.ts
+++ b/packages/utils/src/address_utils.ts
@@ -1,7 +1,10 @@
+import { addHexPrefix, stripHexPrefix } from 'ethereumjs-util';
import * as jsSHA3 from 'js-sha3';
+import * as _ from 'lodash';
const BASIC_ADDRESS_REGEX = /^(0x)?[0-9a-f]{40}$/i;
const SAME_CASE_ADDRESS_REGEX = /^(0x)?([0-9a-f]{40}|[0-9A-F]{40})$/;
+const ADDRESS_LENGTH = 40;
export const addressUtils = {
isChecksumAddress(address: string): boolean {
@@ -9,8 +12,7 @@ export const addressUtils = {
const unprefixedAddress = address.replace('0x', '');
const addressHash = jsSHA3.keccak256(unprefixedAddress.toLowerCase());
- const addressLength = 40;
- for (let i = 0; i < addressLength; i++) {
+ for (let i = 0; i < ADDRESS_LENGTH; i++) {
// The nth letter should be uppercase if the nth digit of casemap is 1
const hexBase = 16;
const lowercaseRange = 7;
@@ -38,4 +40,7 @@ export const addressUtils = {
return isValidChecksummedAddress;
}
},
+ padZeros(address: string): string {
+ return addHexPrefix(_.padStart(stripHexPrefix(address), ADDRESS_LENGTH, '0'));
+ },
};