@xylabs/eth-address 7.0.7 → 8.0.0

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
@@ -1,347 +1,3 @@
1
- [![logo][]](https://xylabs.com)
2
-
3
1
  # @xylabs/eth-address
4
2
 
5
- [![npm][npm-badge]][npm-link]
6
- [![license][license-badge]][license-link]
7
-
8
- > Base functionality used throughout XY Labs TypeScript/JavaScript libraries
9
-
10
- ## Install
11
-
12
- Using npm:
13
-
14
- ```sh
15
- npm install {{name}}
16
- ```
17
-
18
- Using yarn:
19
-
20
- ```sh
21
- yarn add {{name}}
22
- ```
23
-
24
- Using pnpm:
25
-
26
- ```sh
27
- pnpm add {{name}}
28
- ```
29
-
30
- Using bun:
31
-
32
- ```sh
33
- bun add {{name}}
34
- ```
35
-
36
-
37
- ## License
38
-
39
- See the [LICENSE](LICENSE) file for license rights and limitations (LGPL-3.0-only).
40
-
41
- ## Reference
42
-
43
- ### packages
44
-
45
- ### eth-address
46
-
47
- ### .temp-typedoc
48
-
49
- ### classes
50
-
51
- ### <a id="EthAddressWrapper"></a>EthAddressWrapper
52
-
53
- [**@xylabs/eth-address**](#../README)
54
-
55
- ***
56
-
57
- Wrapper around an Ethereum address providing parsing, formatting, validation, and checksum support.
58
-
59
- ## Constructors
60
-
61
- ### Constructor
62
-
63
- ```ts
64
- protected new EthAddressWrapper(address): EthAddressWrapper;
65
- ```
66
-
67
- ### Parameters
68
-
69
- #### address
70
-
71
- `bigint`
72
-
73
- ### Returns
74
-
75
- `EthAddressWrapper`
76
-
77
- ## Methods
78
-
79
- ### fromString()
80
-
81
- ```ts
82
- static fromString(value?, base?): EthAddressWrapper | undefined;
83
- ```
84
-
85
- ### Parameters
86
-
87
- #### value?
88
-
89
- `string`
90
-
91
- #### base?
92
-
93
- `number` = `16`
94
-
95
- ### Returns
96
-
97
- `EthAddressWrapper` \| `undefined`
98
-
99
- ***
100
-
101
- ### parse()
102
-
103
- ```ts
104
- static parse(value, base?): EthAddressWrapper | undefined;
105
- ```
106
-
107
- ### Parameters
108
-
109
- #### value
110
-
111
- `unknown`
112
-
113
- #### base?
114
-
115
- `number`
116
-
117
- ### Returns
118
-
119
- `EthAddressWrapper` \| `undefined`
120
-
121
- ***
122
-
123
- ### validate()
124
-
125
- ```ts
126
- static validate(address): boolean;
127
- ```
128
-
129
- ### Parameters
130
-
131
- #### address
132
-
133
- `string`
134
-
135
- ### Returns
136
-
137
- `boolean`
138
-
139
- ***
140
-
141
- ### equals()
142
-
143
- ```ts
144
- equals(address?): boolean;
145
- ```
146
-
147
- ### Parameters
148
-
149
- #### address?
150
-
151
- `string` \| `EthAddressWrapper` \| `null`
152
-
153
- ### Returns
154
-
155
- `boolean`
156
-
157
- ***
158
-
159
- ### toBigNumber()
160
-
161
- ```ts
162
- toBigNumber(): bigint;
163
- ```
164
-
165
- ### Returns
166
-
167
- `bigint`
168
-
169
- ***
170
-
171
- ### toHex()
172
-
173
- ```ts
174
- toHex(): string;
175
- ```
176
-
177
- ### Returns
178
-
179
- `string`
180
-
181
- ***
182
-
183
- ### toJSON()
184
-
185
- ```ts
186
- toJSON(): string;
187
- ```
188
-
189
- ### Returns
190
-
191
- `string`
192
-
193
- ***
194
-
195
- ### toLowerCaseString()
196
-
197
- ```ts
198
- toLowerCaseString(): string;
199
- ```
200
-
201
- ### Returns
202
-
203
- `string`
204
-
205
- ***
206
-
207
- ### toShortString()
208
-
209
- ```ts
210
- toShortString(length?): string;
211
- ```
212
-
213
- ### Parameters
214
-
215
- #### length?
216
-
217
- `number` = `2`
218
-
219
- ### Returns
220
-
221
- `string`
222
-
223
- ***
224
-
225
- ### toString()
226
-
227
- ```ts
228
- toString(checksum?, chainId?): string;
229
- ```
230
-
231
- ### Parameters
232
-
233
- #### checksum?
234
-
235
- `boolean`
236
-
237
- #### chainId?
238
-
239
- `string`
240
-
241
- ### Returns
242
-
243
- `string`
244
-
245
- ***
246
-
247
- ### validate()
248
-
249
- ```ts
250
- validate(): boolean;
251
- ```
252
-
253
- ### Returns
254
-
255
- `boolean`
256
-
257
- ### functions
258
-
259
- ### <a id="ellipsize"></a>ellipsize
260
-
261
- [**@xylabs/eth-address**](#../README)
262
-
263
- ***
264
-
265
- ```ts
266
- function ellipsize(value, length?): string;
267
- ```
268
-
269
- Truncates a string to show the first and last `length` characters separated by an ellipsis.
270
-
271
- ## Parameters
272
-
273
- ### value
274
-
275
- `string`
276
-
277
- The string to ellipsize
278
-
279
- ### length?
280
-
281
- `number` = `2`
282
-
283
- Number of characters to keep at each end (default 2)
284
-
285
- ## Returns
286
-
287
- `string`
288
-
289
- The ellipsized string
290
-
291
- ### <a id="isEthAddressWrapper"></a>isEthAddressWrapper
292
-
293
- [**@xylabs/eth-address**](#../README)
294
-
295
- ***
296
-
297
- ```ts
298
- function isEthAddressWrapper(obj): obj is { type: string } & EthAddressWrapper;
299
- ```
300
-
301
- Type guard that checks if the given object is an instance of EthAddressWrapper.
302
-
303
- ## Parameters
304
-
305
- ### obj
306
-
307
- ### type
308
-
309
- `string`
310
-
311
- ## Returns
312
-
313
- `obj is { type: string } & EthAddressWrapper`
314
-
315
- ### <a id="padHex"></a>padHex
316
-
317
- [**@xylabs/eth-address**](#../README)
318
-
319
- ***
320
-
321
- ```ts
322
- function padHex(hex, byteCount?): string;
323
- ```
324
-
325
- ## Parameters
326
-
327
- ### hex
328
-
329
- `string`
330
-
331
- ### byteCount?
332
-
333
- `number` = `0`
334
-
335
- ## Returns
336
-
337
- `string`
338
-
339
- ## Credits
340
-
341
- [Made with 🔥 and ❄️ by XY Labs](https://xylabs.com)
342
-
343
- [npm-badge]: https://img.shields.io/npm/v/@xylabs/eth-address.svg
344
- [npm-link]: https://www.npmjs.com/package/@xylabs/eth-address
345
- [license-badge]: https://img.shields.io/npm/l/@xylabs/eth-address.svg
346
- [license-link]: https://github.com/xylabs/sdk-js/blob/main/LICENSE
347
- [logo]: https://cdn.xy.company/img/brand/XYPersistentCompany_Logo_Icon_Colored.svg
3
+ DEPRECATED — use `@ariestools/eth-address` instead.
@@ -1,4 +1,2 @@
1
- export * from './ellipsize.ts';
2
- export * from './EthAddress.ts';
3
- export * from './padHex.ts';
1
+ export * from '@ariestools/eth-address';
4
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,aAAa,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAA"}
@@ -1,81 +1,3 @@
1
- // src/ellipsize.ts
2
- import {
3
- ellipsize
4
- } from "@xylabs/sdk/ellipsize";
5
-
6
- // src/EthAddress.ts
7
- import { assertEx } from "@xylabs/sdk/assert";
8
- import { ellipsize as ellipsize2 } from "@xylabs/sdk/ellipsize";
9
- import { getAddress } from "ethers";
10
-
11
- // src/padHex.ts
12
- var padHex = (hex, byteCount = 0) => {
13
- let result = hex.length % 2 === 0 ? hex : `0${hex}`;
14
- while (result.length / 2 < byteCount) {
15
- result = `00${result}`;
16
- }
17
- return result;
18
- };
19
-
20
- // src/EthAddress.ts
21
- var isEthAddressWrapper = (obj) => obj instanceof EthAddressWrapper;
22
- var EthAddressWrapper = class _EthAddressWrapper {
23
- address;
24
- constructor(address) {
25
- this.address = address;
26
- }
27
- static fromString(value, base = 16) {
28
- if (value === void 0) {
29
- return;
30
- }
31
- const bi = base === 16 ? BigInt(value.startsWith("0x") ? value : `0x${value}`) : BigInt(value);
32
- return new _EthAddressWrapper(bi);
33
- }
34
- static parse(value, base) {
35
- if (typeof value === "string") {
36
- return this.fromString(value, base);
37
- }
38
- }
39
- static validate(address) {
40
- return /^(0x)?[\da-f]{40}$/i.test(address);
41
- }
42
- equals(address) {
43
- if (address !== null && address !== void 0) {
44
- const inAddress = typeof address === "string" ? assertEx(_EthAddressWrapper.fromString(address), () => "Bad Address") : address;
45
- return this.address === inAddress.address;
46
- }
47
- return false;
48
- }
49
- toBigNumber() {
50
- return this.address;
51
- }
52
- toHex() {
53
- return padHex(this.address.toString(16), 20);
54
- }
55
- toJSON() {
56
- return `0x${this.toHex()}`;
57
- }
58
- toLowerCaseString() {
59
- return this.toString().toLowerCase();
60
- }
61
- toShortString(length = 2) {
62
- return `0x${ellipsize2(this.toHex(), length)}`;
63
- }
64
- toString(checksum, chainId) {
65
- if (checksum === true) {
66
- const strippedAddress = this.toHex();
67
- return getAddress(chainId === void 0 ? `0x${strippedAddress}` : `${chainId}0x${strippedAddress}`);
68
- }
69
- return `0x${this.toHex()}`;
70
- }
71
- validate() {
72
- return _EthAddressWrapper.validate(this.toString());
73
- }
74
- };
75
- export {
76
- EthAddressWrapper,
77
- ellipsize,
78
- isEthAddressWrapper,
79
- padHex
80
- };
1
+ // src/index.ts
2
+ export * from "@ariestools/eth-address";
81
3
  //# sourceMappingURL=index.mjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/ellipsize.ts", "../../src/EthAddress.ts", "../../src/padHex.ts"],
4
- "sourcesContent": ["export {\n /** @deprecated import from @xylabs/sdk-js (or @xylabs/sdk/ellipsize) instead */\n ellipsize,\n} from '@xylabs/sdk/ellipsize'\n", "import { assertEx } from '@xylabs/sdk/assert'\nimport { ellipsize } from '@xylabs/sdk/ellipsize'\nimport { getAddress } from 'ethers'\n\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 return\n }\n const bi = base === 16 ? BigInt(value.startsWith('0x') ? value : `0x${value}`) : BigInt(value)\n return new EthAddressWrapper(bi)\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 === true) {\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.length % 2 === 0 ? hex : `0${hex}`\n\n while (result.length / 2 < byteCount) {\n result = `00${result}`\n }\n\n return result\n}\n\nexport { padHex }\n"],
5
- "mappings": ";AAAA;AAAA,EAEE;AAAA,OACK;;;ACHP,SAAS,gBAAgB;AACzB,SAAS,aAAAA,kBAAiB;AAC1B,SAAS,kBAAkB;;;ACF3B,IAAM,SAAS,CAAC,KAAa,YAAY,MAAM;AAC7C,MAAI,SAAS,IAAI,SAAS,MAAM,IAAI,MAAM,IAAI,GAAG;AAEjD,SAAO,OAAO,SAAS,IAAI,WAAW;AACpC,aAAS,KAAK,MAAM;AAAA,EACtB;AAEA,SAAO;AACT;;;ADDO,IAAM,sBAAsB,CAAC,QAA0B,eAAe;AAGtE,IAAM,oBAAN,MAAM,mBAAkB;AAAA,EACrB;AAAA,EAEE,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AE;AAAA,IACrG;AACA,WAAO,KAAK,KAAK,MAAM,CAAC;AAAA,EAC1B;AAAA,EAEA,WAAW;AACT,WAAO,mBAAkB,SAAS,KAAK,SAAS,CAAC;AAAA,EACnD;AACF;",
6
- "names": ["ellipsize", "ellipsize"]
3
+ "sources": ["../../src/index.ts"],
4
+ "sourcesContent": ["export * from '@ariestools/eth-address'\n"],
5
+ "mappings": ";AAAA,cAAc;",
6
+ "names": []
7
7
  }
package/package.json CHANGED
@@ -1,15 +1,11 @@
1
1
  {
2
2
  "name": "@xylabs/eth-address",
3
- "version": "7.0.7",
4
- "description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
3
+ "version": "8.0.0",
4
+ "description": "DEPRECATED use @ariestools/eth-address. Backward-compatibility re-export shim.",
5
5
  "keywords": [
6
- "eth",
7
- "ethereum",
8
- "address",
9
6
  "xylabs",
10
- "utility",
11
- "typescript",
12
- "esm"
7
+ "deprecated",
8
+ "shim"
13
9
  ],
14
10
  "homepage": "https://xylabs.com",
15
11
  "bugs": {
@@ -43,7 +39,7 @@
43
39
  "README.md"
44
40
  ],
45
41
  "dependencies": {
46
- "@xylabs/sdk": "~7.0.7"
42
+ "@ariestools/eth-address": "~8.0.0"
47
43
  },
48
44
  "devDependencies": {
49
45
  "@opentelemetry/api": "~1.9.1",
@@ -56,8 +52,6 @@
56
52
  "eslint-import-resolver-typescript": "~4.4.5",
57
53
  "ethers": "~6.17.0",
58
54
  "typescript": "~6.0.3",
59
- "vite": "~8.1.3",
60
- "vitest": "~4.1.9",
61
55
  "zod": "~4.4.3"
62
56
  },
63
57
  "peerDependencies": {
@@ -72,5 +66,6 @@
72
66
  },
73
67
  "publishConfig": {
74
68
  "access": "public"
75
- }
69
+ },
70
+ "deprecated": "Use @ariestools/eth-address instead. @xylabs/eth-address is a compatibility shim only and will not receive further updates."
76
71
  }
@@ -1,23 +0,0 @@
1
- /** Type guard that checks if the given object is an instance of EthAddressWrapper. */
2
- export declare const isEthAddressWrapper: (obj: {
3
- type: string;
4
- }) => obj is {
5
- type: string;
6
- } & EthAddressWrapper;
7
- /** Wrapper around an Ethereum address providing parsing, formatting, validation, and checksum support. */
8
- export declare class EthAddressWrapper {
9
- private address;
10
- protected constructor(address: bigint);
11
- static fromString(value?: string, base?: number): EthAddressWrapper | undefined;
12
- static parse(value: unknown, base?: number): EthAddressWrapper | undefined;
13
- static validate(address: string): boolean;
14
- equals(address?: EthAddressWrapper | string | null): boolean;
15
- toBigNumber(): bigint;
16
- toHex(): string;
17
- toJSON(): string;
18
- toLowerCaseString(): string;
19
- toShortString(length?: number): string;
20
- toString(checksum?: boolean, chainId?: string): string;
21
- validate(): boolean;
22
- }
23
- //# sourceMappingURL=EthAddress.d.ts.map
@@ -1 +0,0 @@
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;IAQ3C,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,4 +0,0 @@
1
- export {
2
- /** @deprecated import from @xylabs/sdk-js (or @xylabs/sdk/ellipsize) instead */
3
- ellipsize, } from '@xylabs/sdk/ellipsize';
4
- //# sourceMappingURL=ellipsize.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ellipsize.d.ts","sourceRoot":"","sources":["../../src/ellipsize.ts"],"names":[],"mappings":"AAAA,OAAO;AACL,gFAAgF;AAChF,SAAS,GACV,MAAM,uBAAuB,CAAA"}
@@ -1,3 +0,0 @@
1
- declare const padHex: (hex: string, byteCount?: number) => string;
2
- export { padHex };
3
- //# sourceMappingURL=padHex.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"padHex.d.ts","sourceRoot":"","sources":["../../src/padHex.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,MAAM,GAAI,KAAK,MAAM,EAAE,kBAAa,WAQzC,CAAA;AAED,OAAO,EAAE,MAAM,EAAE,CAAA"}