@xylabs/eth-address 5.0.80 → 5.0.81

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
@@ -23,44 +23,46 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
23
23
 
24
24
  ## Classes
25
25
 
26
- - [EthAddress](#classes/EthAddress)
26
+ - [EthAddressWrapper](#classes/EthAddressWrapper)
27
27
 
28
28
  ## Functions
29
29
 
30
- - [isEthAddress](#functions/isEthAddress)
30
+ - [isEthAddressWrapper](#functions/isEthAddressWrapper)
31
31
  - [ellipsize](#functions/ellipsize)
32
32
  - [padHex](#functions/padHex)
33
33
 
34
34
  ### classes
35
35
 
36
- ### <a id="EthAddress"></a>EthAddress
36
+ ### <a id="EthAddressWrapper"></a>EthAddressWrapper
37
37
 
38
38
  [**@xylabs/eth-address**](#../README)
39
39
 
40
40
  ***
41
41
 
42
- ## Properties
42
+ ## Constructors
43
43
 
44
- ### type
44
+ ### Constructor
45
45
 
46
46
  ```ts
47
- readonly static type: "EthAddress" = 'EthAddress';
47
+ protected new EthAddressWrapper(address): EthAddressWrapper;
48
48
  ```
49
49
 
50
- ***
50
+ ### Parameters
51
51
 
52
- ### type
52
+ #### address
53
53
 
54
- ```ts
55
- type: string = EthAddress.type;
56
- ```
54
+ `bigint`
55
+
56
+ ### Returns
57
+
58
+ `EthAddressWrapper`
57
59
 
58
60
  ## Methods
59
61
 
60
62
  ### fromString()
61
63
 
62
64
  ```ts
63
- static fromString(value?, base?): undefined | EthAddress;
65
+ static fromString(value?, base?): EthAddressWrapper | undefined;
64
66
  ```
65
67
 
66
68
  ### Parameters
@@ -75,14 +77,14 @@ static fromString(value?, base?): undefined | EthAddress;
75
77
 
76
78
  ### Returns
77
79
 
78
- `undefined` \| `EthAddress`
80
+ `EthAddressWrapper` \| `undefined`
79
81
 
80
82
  ***
81
83
 
82
84
  ### parse()
83
85
 
84
86
  ```ts
85
- static parse(value, base?): undefined | EthAddress;
87
+ static parse(value, base?): EthAddressWrapper | undefined;
86
88
  ```
87
89
 
88
90
  ### Parameters
@@ -97,7 +99,7 @@ static parse(value, base?): undefined | EthAddress;
97
99
 
98
100
  ### Returns
99
101
 
100
- `undefined` \| `EthAddress`
102
+ `EthAddressWrapper` \| `undefined`
101
103
 
102
104
  ***
103
105
 
@@ -129,7 +131,7 @@ equals(address?): boolean;
129
131
 
130
132
  #### address?
131
133
 
132
- `null` | `string` | `EthAddress`
134
+ `string` | `EthAddressWrapper` | `null`
133
135
 
134
136
  ### Returns
135
137
 
@@ -188,12 +190,12 @@ toLowerCaseString(): string;
188
190
  ### toShortString()
189
191
 
190
192
  ```ts
191
- toShortString(length): string;
193
+ toShortString(length?): string;
192
194
  ```
193
195
 
194
196
  ### Parameters
195
197
 
196
- #### length
198
+ #### length?
197
199
 
198
200
  `number` = `2`
199
201
 
@@ -244,7 +246,7 @@ validate(): boolean;
244
246
  ***
245
247
 
246
248
  ```ts
247
- function ellipsize(value, length): string;
249
+ function ellipsize(value, length?): string;
248
250
  ```
249
251
 
250
252
  ## Parameters
@@ -253,7 +255,7 @@ function ellipsize(value, length): string;
253
255
 
254
256
  `string`
255
257
 
256
- ### length
258
+ ### length?
257
259
 
258
260
  `number` = `2`
259
261
 
@@ -261,14 +263,14 @@ function ellipsize(value, length): string;
261
263
 
262
264
  `string`
263
265
 
264
- ### <a id="isEthAddress"></a>isEthAddress
266
+ ### <a id="isEthAddressWrapper"></a>isEthAddressWrapper
265
267
 
266
268
  [**@xylabs/eth-address**](#../README)
267
269
 
268
270
  ***
269
271
 
270
272
  ```ts
271
- function isEthAddress(obj): boolean;
273
+ function isEthAddressWrapper(obj): obj is { type: string } & EthAddressWrapper;
272
274
  ```
273
275
 
274
276
  ## Parameters
@@ -281,7 +283,7 @@ function isEthAddress(obj): boolean;
281
283
 
282
284
  ## Returns
283
285
 
284
- `boolean`
286
+ `obj is { type: string } & EthAddressWrapper`
285
287
 
286
288
  ### <a id="padHex"></a>padHex
287
289
 
@@ -290,7 +292,7 @@ function isEthAddress(obj): boolean;
290
292
  ***
291
293
 
292
294
  ```ts
293
- function padHex(hex, byteCount): string;
295
+ function padHex(hex, byteCount?): string;
294
296
  ```
295
297
 
296
298
  ## Parameters
@@ -299,7 +301,7 @@ function padHex(hex, byteCount): string;
299
301
 
300
302
  `string`
301
303
 
302
- ### byteCount
304
+ ### byteCount?
303
305
 
304
306
  `number` = `0`
305
307
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xylabs/eth-address",
3
- "version": "5.0.80",
3
+ "version": "5.0.81",
4
4
  "description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
5
5
  "keywords": [
6
6
  "eth",
@@ -31,28 +31,25 @@
31
31
  "exports": {
32
32
  ".": {
33
33
  "types": "./dist/neutral/index.d.ts",
34
- "source": "./src/index.ts",
35
34
  "default": "./dist/neutral/index.mjs"
36
35
  },
37
36
  "./package.json": "./package.json"
38
37
  },
39
38
  "module": "./dist/neutral/index.mjs",
40
- "source": "./src/index.ts",
41
39
  "types": "./dist/neutral/index.d.ts",
42
40
  "files": [
43
41
  "dist",
44
- "src",
45
42
  "!**/*.bench.*",
46
43
  "!**/*.spec.*",
47
44
  "!**/*.test.*"
48
45
  ],
49
46
  "dependencies": {
50
- "@xylabs/assert": "~5.0.80",
47
+ "@xylabs/assert": "~5.0.81",
51
48
  "ethers": "^6.16.0"
52
49
  },
53
50
  "devDependencies": {
54
- "@xylabs/ts-scripts-yarn3": "~7.3.2",
55
- "@xylabs/tsconfig": "~7.3.2",
51
+ "@xylabs/ts-scripts-yarn3": "~7.4.11",
52
+ "@xylabs/tsconfig": "~7.4.11",
56
53
  "typescript": "~5.9.3",
57
54
  "vitest": "~4.0.18"
58
55
  },
package/src/EthAddress.ts DELETED
@@ -1,72 +0,0 @@
1
- import { assertEx } from '@xylabs/assert'
2
- import { getAddress } from 'ethers'
3
-
4
- import { ellipsize } from './ellipsize.ts'
5
- import { padHex } from './padHex.ts'
6
-
7
- export const isEthAddressWrapper = (obj: { type: string }) => obj instanceof EthAddressWrapper
8
-
9
- export class EthAddressWrapper {
10
- private address: bigint
11
-
12
- protected constructor(address: bigint) {
13
- this.address = address
14
- }
15
-
16
- static fromString(value?: string, base = 16) {
17
- if (value !== undefined) {
18
- const bi = base === 16 ? BigInt(value.startsWith('0x') ? value : `0x${value}`) : BigInt(value)
19
- return new EthAddressWrapper(bi)
20
- }
21
- }
22
-
23
- static parse(value: unknown, base?: number) {
24
- if (typeof value === 'string') {
25
- return this.fromString(value, base)
26
- }
27
- }
28
-
29
- static validate(address: string) {
30
- return /^(0x)?[\da-f]{40}$/i.test(address)
31
- }
32
-
33
- equals(address?: EthAddressWrapper | string | null): boolean {
34
- if (address !== null && address !== undefined) {
35
- const inAddress = typeof address === 'string' ? assertEx(EthAddressWrapper.fromString(address), () => 'Bad Address') : address
36
- return this.address === inAddress.address
37
- }
38
- return false
39
- }
40
-
41
- toBigNumber() {
42
- return this.address
43
- }
44
-
45
- toHex() {
46
- return padHex(this.address.toString(16), 20)
47
- }
48
-
49
- toJSON(): string {
50
- return `0x${this.toHex()}`
51
- }
52
-
53
- toLowerCaseString() {
54
- return this.toString().toLowerCase()
55
- }
56
-
57
- toShortString(length = 2) {
58
- return `0x${ellipsize(this.toHex(), length)}`
59
- }
60
-
61
- toString(checksum?: boolean, chainId?: string) {
62
- if (checksum) {
63
- const strippedAddress = this.toHex()
64
- return getAddress(chainId === undefined ? `0x${strippedAddress}` : `${chainId}0x${strippedAddress}`)
65
- }
66
- return `0x${this.toHex()}`
67
- }
68
-
69
- validate() {
70
- return EthAddressWrapper.validate(this.toString())
71
- }
72
- }
package/src/ellipsize.ts DELETED
@@ -1,5 +0,0 @@
1
- export const ellipsize = (value: string, length = 2) => {
2
- const part1 = value.slice(0, length)
3
- const part2 = value.slice(value.length - length)
4
- return `${part1}...${part2}`
5
- }
package/src/index.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from './ellipsize.ts'
2
- export * from './EthAddress.ts'
3
- export * from './padHex.ts'
package/src/padHex.ts DELETED
@@ -1,14 +0,0 @@
1
- const padHex = (hex: string, byteCount = 0) => {
2
- let result = hex
3
- if (hex.length % 2 !== 0) {
4
- result = `0${hex}`
5
- }
6
-
7
- while (result.length / 2 < byteCount) {
8
- result = `00${result}`
9
- }
10
-
11
- return result
12
- }
13
-
14
- export { padHex }