@xylabs/eth-address 5.0.82 → 5.0.84
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -39,6 +39,8 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
|
|
|
39
39
|
|
|
40
40
|
***
|
|
41
41
|
|
|
42
|
+
Wrapper around an Ethereum address providing parsing, formatting, validation, and checksum support.
|
|
43
|
+
|
|
42
44
|
## Constructors
|
|
43
45
|
|
|
44
46
|
### Constructor
|
|
@@ -249,20 +251,28 @@ validate(): boolean;
|
|
|
249
251
|
function ellipsize(value, length?): string;
|
|
250
252
|
```
|
|
251
253
|
|
|
254
|
+
Truncates a string to show the first and last `length` characters separated by an ellipsis.
|
|
255
|
+
|
|
252
256
|
## Parameters
|
|
253
257
|
|
|
254
258
|
### value
|
|
255
259
|
|
|
256
260
|
`string`
|
|
257
261
|
|
|
262
|
+
The string to ellipsize
|
|
263
|
+
|
|
258
264
|
### length?
|
|
259
265
|
|
|
260
266
|
`number` = `2`
|
|
261
267
|
|
|
268
|
+
Number of characters to keep at each end (default 2)
|
|
269
|
+
|
|
262
270
|
## Returns
|
|
263
271
|
|
|
264
272
|
`string`
|
|
265
273
|
|
|
274
|
+
The ellipsized string
|
|
275
|
+
|
|
266
276
|
### <a id="isEthAddressWrapper"></a>isEthAddressWrapper
|
|
267
277
|
|
|
268
278
|
[**@xylabs/eth-address**](#../README)
|
|
@@ -273,6 +283,8 @@ function ellipsize(value, length?): string;
|
|
|
273
283
|
function isEthAddressWrapper(obj): obj is { type: string } & EthAddressWrapper;
|
|
274
284
|
```
|
|
275
285
|
|
|
286
|
+
Type guard that checks if the given object is an instance of EthAddressWrapper.
|
|
287
|
+
|
|
276
288
|
## Parameters
|
|
277
289
|
|
|
278
290
|
### obj
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
/** Type guard that checks if the given object is an instance of EthAddressWrapper. */
|
|
1
2
|
export declare const isEthAddressWrapper: (obj: {
|
|
2
3
|
type: string;
|
|
3
4
|
}) => obj is {
|
|
4
5
|
type: string;
|
|
5
6
|
} & EthAddressWrapper;
|
|
7
|
+
/** Wrapper around an Ethereum address providing parsing, formatting, validation, and checksum support. */
|
|
6
8
|
export declare class EthAddressWrapper {
|
|
7
9
|
private address;
|
|
8
10
|
protected constructor(address: bigint);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EthAddress.d.ts","sourceRoot":"","sources":["../../src/EthAddress.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,mBAAmB,GAAI,KAAK;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE;UAAR,MAAM;qBAAuC,CAAA;AAE9F,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,OAAO,CAAQ;IAEvB,SAAS,aAAa,OAAO,EAAE,MAAM;IAIrC,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,IAAI,SAAK;IAO3C,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,MAAM;IAM1C,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM;IAI/B,MAAM,CAAC,OAAO,CAAC,EAAE,iBAAiB,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO;IAQ5D,WAAW;IAIX,KAAK;IAIL,MAAM,IAAI,MAAM;IAIhB,iBAAiB;IAIjB,aAAa,CAAC,MAAM,SAAI;IAIxB,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM;IAQ7C,QAAQ;CAGT"}
|
|
1
|
+
{"version":3,"file":"EthAddress.d.ts","sourceRoot":"","sources":["../../src/EthAddress.ts"],"names":[],"mappings":"AAMA,sFAAsF;AACtF,eAAO,MAAM,mBAAmB,GAAI,KAAK;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE;UAAR,MAAM;qBAAuC,CAAA;AAE9F,0GAA0G;AAC1G,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,OAAO,CAAQ;IAEvB,SAAS,aAAa,OAAO,EAAE,MAAM;IAIrC,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,IAAI,SAAK;IAO3C,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,MAAM;IAM1C,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM;IAI/B,MAAM,CAAC,OAAO,CAAC,EAAE,iBAAiB,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO;IAQ5D,WAAW;IAIX,KAAK;IAIL,MAAM,IAAI,MAAM;IAIhB,iBAAiB;IAIjB,aAAa,CAAC,MAAM,SAAI;IAIxB,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM;IAQ7C,QAAQ;CAGT"}
|
|
@@ -1,2 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Truncates a string to show the first and last `length` characters separated by an ellipsis.
|
|
3
|
+
* @param value - The string to ellipsize
|
|
4
|
+
* @param length - Number of characters to keep at each end (default 2)
|
|
5
|
+
* @returns The ellipsized string
|
|
6
|
+
*/
|
|
1
7
|
export declare const ellipsize: (value: string, length?: number) => string;
|
|
2
8
|
//# sourceMappingURL=ellipsize.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ellipsize.d.ts","sourceRoot":"","sources":["../../src/ellipsize.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,GAAI,OAAO,MAAM,EAAE,eAAU,WAIlD,CAAA"}
|
|
1
|
+
{"version":3,"file":"ellipsize.d.ts","sourceRoot":"","sources":["../../src/ellipsize.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,SAAS,GAAI,OAAO,MAAM,EAAE,eAAU,WAIlD,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/ellipsize.ts","../../src/EthAddress.ts","../../src/padHex.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../src/ellipsize.ts","../../src/EthAddress.ts","../../src/padHex.ts"],"sourcesContent":["/**\n * Truncates a string to show the first and last `length` characters separated by an ellipsis.\n * @param value - The string to ellipsize\n * @param length - Number of characters to keep at each end (default 2)\n * @returns The ellipsized string\n */\nexport const ellipsize = (value: string, length = 2) => {\n const part1 = value.slice(0, length)\n const part2 = value.slice(value.length - length)\n return `${part1}...${part2}`\n}\n","import { assertEx } from '@xylabs/assert'\nimport { getAddress } from 'ethers'\n\nimport { ellipsize } from './ellipsize.ts'\nimport { padHex } from './padHex.ts'\n\n/** Type guard that checks if the given object is an instance of EthAddressWrapper. */\nexport const isEthAddressWrapper = (obj: { type: string }) => obj instanceof EthAddressWrapper\n\n/** Wrapper around an Ethereum address providing parsing, formatting, validation, and checksum support. */\nexport class EthAddressWrapper {\n private address: bigint\n\n protected constructor(address: bigint) {\n this.address = address\n }\n\n static fromString(value?: string, base = 16) {\n if (value !== undefined) {\n const bi = base === 16 ? BigInt(value.startsWith('0x') ? value : `0x${value}`) : BigInt(value)\n return new EthAddressWrapper(bi)\n }\n }\n\n static parse(value: unknown, base?: number) {\n if (typeof value === 'string') {\n return this.fromString(value, base)\n }\n }\n\n static validate(address: string) {\n return /^(0x)?[\\da-f]{40}$/i.test(address)\n }\n\n equals(address?: EthAddressWrapper | string | null): boolean {\n if (address !== null && address !== undefined) {\n const inAddress = typeof address === 'string' ? assertEx(EthAddressWrapper.fromString(address), () => 'Bad Address') : address\n return this.address === inAddress.address\n }\n return false\n }\n\n toBigNumber() {\n return this.address\n }\n\n toHex() {\n return padHex(this.address.toString(16), 20)\n }\n\n toJSON(): string {\n return `0x${this.toHex()}`\n }\n\n toLowerCaseString() {\n return this.toString().toLowerCase()\n }\n\n toShortString(length = 2) {\n return `0x${ellipsize(this.toHex(), length)}`\n }\n\n toString(checksum?: boolean, chainId?: string) {\n if (checksum) {\n const strippedAddress = this.toHex()\n return getAddress(chainId === undefined ? `0x${strippedAddress}` : `${chainId}0x${strippedAddress}`)\n }\n return `0x${this.toHex()}`\n }\n\n validate() {\n return EthAddressWrapper.validate(this.toString())\n }\n}\n","const padHex = (hex: string, byteCount = 0) => {\n let result = hex\n if (hex.length % 2 !== 0) {\n result = `0${hex}`\n }\n\n while (result.length / 2 < byteCount) {\n result = `00${result}`\n }\n\n return result\n}\n\nexport { padHex }\n"],"mappings":";AAMO,IAAM,YAAY,CAAC,OAAe,SAAS,MAAM;AACtD,QAAM,QAAQ,MAAM,MAAM,GAAG,MAAM;AACnC,QAAM,QAAQ,MAAM,MAAM,MAAM,SAAS,MAAM;AAC/C,SAAO,GAAG,KAAK,MAAM,KAAK;AAC5B;;;ACVA,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;;;ACD3B,IAAM,SAAS,CAAC,KAAa,YAAY,MAAM;AAC7C,MAAI,SAAS;AACb,MAAI,IAAI,SAAS,MAAM,GAAG;AACxB,aAAS,IAAI,GAAG;AAAA,EAClB;AAEA,SAAO,OAAO,SAAS,IAAI,WAAW;AACpC,aAAS,KAAK,MAAM;AAAA,EACtB;AAEA,SAAO;AACT;;;ADJO,IAAM,sBAAsB,CAAC,QAA0B,eAAe;AAGtE,IAAM,oBAAN,MAAM,mBAAkB;AAAA,EACrB;AAAA,EAEE,YAAY,SAAiB;AACrC,SAAK,UAAU;AAAA,EACjB;AAAA,EAEA,OAAO,WAAW,OAAgB,OAAO,IAAI;AAC3C,QAAI,UAAU,QAAW;AACvB,YAAM,KAAK,SAAS,KAAK,OAAO,MAAM,WAAW,IAAI,IAAI,QAAQ,KAAK,KAAK,EAAE,IAAI,OAAO,KAAK;AAC7F,aAAO,IAAI,mBAAkB,EAAE;AAAA,IACjC;AAAA,EACF;AAAA,EAEA,OAAO,MAAM,OAAgB,MAAe;AAC1C,QAAI,OAAO,UAAU,UAAU;AAC7B,aAAO,KAAK,WAAW,OAAO,IAAI;AAAA,IACpC;AAAA,EACF;AAAA,EAEA,OAAO,SAAS,SAAiB;AAC/B,WAAO,sBAAsB,KAAK,OAAO;AAAA,EAC3C;AAAA,EAEA,OAAO,SAAsD;AAC3D,QAAI,YAAY,QAAQ,YAAY,QAAW;AAC7C,YAAM,YAAY,OAAO,YAAY,WAAW,SAAS,mBAAkB,WAAW,OAAO,GAAG,MAAM,aAAa,IAAI;AACvH,aAAO,KAAK,YAAY,UAAU;AAAA,IACpC;AACA,WAAO;AAAA,EACT;AAAA,EAEA,cAAc;AACZ,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,QAAQ;AACN,WAAO,OAAO,KAAK,QAAQ,SAAS,EAAE,GAAG,EAAE;AAAA,EAC7C;AAAA,EAEA,SAAiB;AACf,WAAO,KAAK,KAAK,MAAM,CAAC;AAAA,EAC1B;AAAA,EAEA,oBAAoB;AAClB,WAAO,KAAK,SAAS,EAAE,YAAY;AAAA,EACrC;AAAA,EAEA,cAAc,SAAS,GAAG;AACxB,WAAO,KAAK,UAAU,KAAK,MAAM,GAAG,MAAM,CAAC;AAAA,EAC7C;AAAA,EAEA,SAAS,UAAoB,SAAkB;AAC7C,QAAI,UAAU;AACZ,YAAM,kBAAkB,KAAK,MAAM;AACnC,aAAO,WAAW,YAAY,SAAY,KAAK,eAAe,KAAK,GAAG,OAAO,KAAK,eAAe,EAAE;AAAA,IACrG;AACA,WAAO,KAAK,KAAK,MAAM,CAAC;AAAA,EAC1B;AAAA,EAEA,WAAW;AACT,WAAO,mBAAkB,SAAS,KAAK,SAAS,CAAC;AAAA,EACnD;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xylabs/eth-address",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.84",
|
|
4
4
|
"description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eth",
|
|
@@ -44,12 +44,12 @@
|
|
|
44
44
|
"!**/*.test.*"
|
|
45
45
|
],
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@xylabs/assert": "~5.0.
|
|
47
|
+
"@xylabs/assert": "~5.0.84",
|
|
48
48
|
"ethers": "^6.16.0"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@xylabs/ts-scripts-yarn3": "~7.4.
|
|
52
|
-
"@xylabs/tsconfig": "~7.4.
|
|
51
|
+
"@xylabs/ts-scripts-yarn3": "~7.4.13",
|
|
52
|
+
"@xylabs/tsconfig": "~7.4.13",
|
|
53
53
|
"typescript": "~5.9.3",
|
|
54
54
|
"vitest": "~4.0.18"
|
|
55
55
|
},
|