@xylabs/eth-address 2.10.17 → 2.11.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.
@@ -0,0 +1,20 @@
1
+ import { BigNumber } from '@xylabs/bignumber';
2
+ export declare const isEthAddress: (obj: {
3
+ type: string;
4
+ }) => boolean;
5
+ export declare class EthAddress {
6
+ static type: string;
7
+ type: string;
8
+ private address;
9
+ private constructor();
10
+ static fromString(value?: string, base?: number): EthAddress | undefined;
11
+ static parse(value: unknown, base?: number): EthAddress | undefined;
12
+ equals(address?: EthAddress | string | null): boolean;
13
+ toBigNumber(): BigNumber;
14
+ toHex(): string;
15
+ toJSON(): string;
16
+ toLowerCaseString(): string;
17
+ toShortString(length?: number): string;
18
+ toString(): string;
19
+ }
20
+ //# sourceMappingURL=EthAddress.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EthAddress.d.ts","sourceRoot":"","sources":["../src/EthAddress.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAK7C,eAAO,MAAM,YAAY,QAAS;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,YAAkC,CAAA;AAEpF,qBAAa,UAAU;IACrB,MAAM,CAAC,IAAI,SAAe;IAE1B,IAAI,SAAkB;IAEtB,OAAO,CAAC,OAAO,CAAW;IAE1B,OAAO;IAIP,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,OAAO,CAAC,EAAE,UAAU,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO;IAarD,WAAW;IAIX,KAAK;IAIL,MAAM,IAAI,MAAM;IAIhB,iBAAiB;IAIjB,aAAa,CAAC,MAAM,SAAI;IAIxB,QAAQ;CAGT"}
@@ -0,0 +1,2 @@
1
+ export declare const ellipsize: (value: string, length?: number) => string;
2
+ //# sourceMappingURL=ellipsize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ellipsize.d.ts","sourceRoot":"","sources":["../src/ellipsize.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,UAAW,MAAM,4BAItC,CAAA"}
package/dist/index.d.mts CHANGED
@@ -1,26 +1,4 @@
1
- import { BigNumber } from '@xylabs/bignumber';
2
-
3
- declare const ellipsize: (value: string, length?: number) => string;
4
-
5
- declare const isEthAddress: (obj: {
6
- type: string;
7
- }) => boolean;
8
- declare class EthAddress {
9
- static type: string;
10
- type: string;
11
- private address;
12
- private constructor();
13
- static fromString(value?: string, base?: number): EthAddress | undefined;
14
- static parse(value: unknown, base?: number): EthAddress | undefined;
15
- equals(address?: EthAddress | string | null): boolean;
16
- toBigNumber(): BigNumber;
17
- toHex(): string;
18
- toJSON(): string;
19
- toLowerCaseString(): string;
20
- toShortString(length?: number): string;
21
- toString(): string;
22
- }
23
-
24
- declare const padHex: (hex: string, byteCount?: number) => string;
25
-
26
- export { EthAddress, ellipsize, isEthAddress, padHex };
1
+ export * from './ellipsize';
2
+ export * from './EthAddress';
3
+ export * from './padHex';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,UAAU,CAAA"}
package/dist/index.d.ts CHANGED
@@ -1,26 +1,4 @@
1
- import { BigNumber } from '@xylabs/bignumber';
2
-
3
- declare const ellipsize: (value: string, length?: number) => string;
4
-
5
- declare const isEthAddress: (obj: {
6
- type: string;
7
- }) => boolean;
8
- declare class EthAddress {
9
- static type: string;
10
- type: string;
11
- private address;
12
- private constructor();
13
- static fromString(value?: string, base?: number): EthAddress | undefined;
14
- static parse(value: unknown, base?: number): EthAddress | undefined;
15
- equals(address?: EthAddress | string | null): boolean;
16
- toBigNumber(): BigNumber;
17
- toHex(): string;
18
- toJSON(): string;
19
- toLowerCaseString(): string;
20
- toShortString(length?: number): string;
21
- toString(): string;
22
- }
23
-
24
- declare const padHex: (hex: string, byteCount?: number) => string;
25
-
26
- export { EthAddress, ellipsize, isEthAddress, padHex };
1
+ export * from './ellipsize';
2
+ export * from './EthAddress';
3
+ export * from './padHex';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,UAAU,CAAA"}
package/dist/index.js CHANGED
@@ -1,113 +1,81 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ 'use strict';
19
2
 
20
- // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
23
- EthAddress: () => EthAddress,
24
- ellipsize: () => ellipsize,
25
- isEthAddress: () => isEthAddress,
26
- padHex: () => padHex
27
- });
28
- module.exports = __toCommonJS(src_exports);
3
+ var assert = require('@xylabs/assert');
4
+ var bignumber = require('@xylabs/bignumber');
29
5
 
30
- // src/ellipsize.ts
31
- var ellipsize = (value, length = 2) => {
32
- const part1 = value.slice(0, length);
33
- const part2 = value.slice(value.length - length, value.length);
34
- return `${part1}...${part2}`;
6
+ const ellipsize = (value, length = 2) => {
7
+ const part1 = value.slice(0, length);
8
+ const part2 = value.slice(value.length - length, value.length);
9
+ return `${part1}...${part2}`;
35
10
  };
36
11
 
37
- // src/EthAddress.ts
38
- var import_assert = require("@xylabs/assert");
39
- var import_bignumber = require("@xylabs/bignumber");
40
-
41
- // src/padHex.ts
42
- var padHex = (hex, byteCount) => {
43
- let result = hex;
44
- if (hex.length % 2 !== 0) {
45
- result = `0${hex}`;
46
- }
47
- if (byteCount) {
48
- while (result.length / 2 < byteCount) {
49
- result = `00${result}`;
12
+ const padHex = (hex, byteCount) => {
13
+ let result = hex;
14
+ if (hex.length % 2 !== 0) {
15
+ result = `0${hex}`;
16
+ }
17
+ if (byteCount) {
18
+ while (result.length / 2 < byteCount) {
19
+ result = `00${result}`;
20
+ }
50
21
  }
51
- }
52
- return result;
22
+ return result;
53
23
  };
54
24
 
55
- // src/EthAddress.ts
56
- var isEthAddress = (obj) => obj?.type === EthAddress.type;
57
- var EthAddress = class _EthAddress {
58
- static type = "EthAddress";
59
- type = _EthAddress.type;
60
- address;
61
- constructor(address) {
62
- this.address = address;
63
- }
64
- static fromString(value, base = 16) {
65
- if (value) {
66
- const bn = new import_bignumber.BigNumber(value.startsWith("0x") ? value.substring(2) : value, base);
67
- return new _EthAddress(bn);
25
+ const isEthAddress = (obj) => obj?.type === EthAddress.type;
26
+ class EthAddress {
27
+ static type = 'EthAddress';
28
+ type = EthAddress.type;
29
+ address;
30
+ constructor(address) {
31
+ this.address = address;
68
32
  }
69
- }
70
- static parse(value, base) {
71
- if (typeof value === "string") {
72
- return this.fromString(value, base);
33
+ static fromString(value, base = 16) {
34
+ if (value) {
35
+ const bn = new bignumber.BigNumber(value.startsWith('0x') ? value.substring(2) : value, base);
36
+ return new EthAddress(bn);
37
+ }
73
38
  }
74
- }
75
- equals(address) {
76
- if (address) {
77
- let inAddress;
78
- if (typeof address === "string") {
79
- inAddress = (0, import_assert.assertEx)(_EthAddress.fromString(address), "Bad Address");
80
- } else {
81
- inAddress = address;
82
- }
83
- return this.address.eq(inAddress.address);
39
+ static parse(value, base) {
40
+ if (typeof value === 'string') {
41
+ return this.fromString(value, base);
42
+ }
84
43
  }
85
- return false;
86
- }
87
- toBigNumber() {
88
- return this.address;
89
- }
90
- toHex() {
91
- return padHex(this.address.toString(16), 20);
92
- }
93
- toJSON() {
94
- return `0x${this.toHex()}`;
95
- }
96
- toLowerCaseString() {
97
- return this.toString().toLowerCase();
98
- }
99
- toShortString(length = 2) {
100
- return `0x${ellipsize(this.toHex(), length)}`;
101
- }
102
- toString() {
103
- return `0x${this.toHex()}`;
104
- }
105
- };
106
- // Annotate the CommonJS export names for ESM import in node:
107
- 0 && (module.exports = {
108
- EthAddress,
109
- ellipsize,
110
- isEthAddress,
111
- padHex
112
- });
113
- //# sourceMappingURL=index.js.map
44
+ equals(address) {
45
+ if (address) {
46
+ let inAddress;
47
+ if (typeof address === 'string') {
48
+ inAddress = assert.assertEx(EthAddress.fromString(address), 'Bad Address');
49
+ }
50
+ else {
51
+ inAddress = address;
52
+ }
53
+ return this.address.eq(inAddress.address);
54
+ }
55
+ return false;
56
+ }
57
+ toBigNumber() {
58
+ return this.address;
59
+ }
60
+ toHex() {
61
+ return padHex(this.address.toString(16), 20);
62
+ }
63
+ toJSON() {
64
+ return `0x${this.toHex()}`;
65
+ }
66
+ toLowerCaseString() {
67
+ return this.toString().toLowerCase();
68
+ }
69
+ toShortString(length = 2) {
70
+ return `0x${ellipsize(this.toHex(), length)}`;
71
+ }
72
+ toString() {
73
+ return `0x${this.toHex()}`;
74
+ }
75
+ }
76
+
77
+ exports.EthAddress = EthAddress;
78
+ exports.ellipsize = ellipsize;
79
+ exports.isEthAddress = isEthAddress;
80
+ exports.padHex = padHex;
81
+ //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/ellipsize.ts","../src/EthAddress.ts","../src/padHex.ts"],"sourcesContent":["export * from './ellipsize'\nexport * from './EthAddress'\nexport * from './padHex'\n","export const ellipsize = (value: string, length = 2) => {\n const part1 = value.slice(0, length)\n const part2 = value.slice(value.length - length, value.length)\n return `${part1}...${part2}`\n}\n","import { assertEx } from '@xylabs/assert'\nimport { BigNumber } from '@xylabs/bignumber'\n\nimport { ellipsize } from './ellipsize'\nimport { padHex } from './padHex'\n\nexport const isEthAddress = (obj: { type: string }) => obj?.type === EthAddress.type\n\nexport class EthAddress {\n static type = 'EthAddress'\n\n public type = EthAddress.type\n\n private address: BigNumber\n\n private constructor(address: BigNumber) {\n this.address = address\n }\n\n static fromString(value?: string, base = 16) {\n if (value) {\n const bn = new BigNumber(value.startsWith('0x') ? value.substring(2) : value, base)\n return new EthAddress(bn)\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 public equals(address?: EthAddress | string | null): boolean {\n if (address) {\n let inAddress: EthAddress\n if (typeof address === 'string') {\n inAddress = assertEx(EthAddress.fromString(address), 'Bad Address')\n } else {\n inAddress = address\n }\n return this.address.eq(inAddress.address)\n }\n return false\n }\n\n public toBigNumber() {\n return this.address\n }\n\n public toHex() {\n return padHex(this.address.toString(16), 20)\n }\n\n public toJSON(): string {\n return `0x${this.toHex()}`\n }\n\n public toLowerCaseString() {\n return this.toString().toLowerCase()\n }\n\n public toShortString(length = 2) {\n return `0x${ellipsize(this.toHex(), length)}`\n }\n\n public toString() {\n return `0x${this.toHex()}`\n }\n}\n","const padHex = (hex: string, byteCount?: number) => {\n let result = hex\n if (hex.length % 2 !== 0) {\n result = `0${hex}`\n }\n if (byteCount) {\n while (result.length / 2 < byteCount) {\n result = `00${result}`\n }\n }\n return result\n}\n\nexport { padHex }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,YAAY,CAAC,OAAe,SAAS,MAAM;AACtD,QAAM,QAAQ,MAAM,MAAM,GAAG,MAAM;AACnC,QAAM,QAAQ,MAAM,MAAM,MAAM,SAAS,QAAQ,MAAM,MAAM;AAC7D,SAAO,GAAG,KAAK,MAAM,KAAK;AAC5B;;;ACJA,oBAAyB;AACzB,uBAA0B;;;ACD1B,IAAM,SAAS,CAAC,KAAa,cAAuB;AAClD,MAAI,SAAS;AACb,MAAI,IAAI,SAAS,MAAM,GAAG;AACxB,aAAS,IAAI,GAAG;AAAA,EAClB;AACA,MAAI,WAAW;AACb,WAAO,OAAO,SAAS,IAAI,WAAW;AACpC,eAAS,KAAK,MAAM;AAAA,IACtB;AAAA,EACF;AACA,SAAO;AACT;;;ADLO,IAAM,eAAe,CAAC,QAA0B,KAAK,SAAS,WAAW;AAEzE,IAAM,aAAN,MAAM,YAAW;AAAA,EACtB,OAAO,OAAO;AAAA,EAEP,OAAO,YAAW;AAAA,EAEjB;AAAA,EAEA,YAAY,SAAoB;AACtC,SAAK,UAAU;AAAA,EACjB;AAAA,EAEA,OAAO,WAAW,OAAgB,OAAO,IAAI;AAC3C,QAAI,OAAO;AACT,YAAM,KAAK,IAAI,2BAAU,MAAM,WAAW,IAAI,IAAI,MAAM,UAAU,CAAC,IAAI,OAAO,IAAI;AAClF,aAAO,IAAI,YAAW,EAAE;AAAA,IAC1B;AAAA,EACF;AAAA,EAEA,OAAO,MAAM,OAAgB,MAAe;AAC1C,QAAI,OAAO,UAAU,UAAU;AAC7B,aAAO,KAAK,WAAW,OAAO,IAAI;AAAA,IACpC;AAAA,EACF;AAAA,EAEO,OAAO,SAA+C;AAC3D,QAAI,SAAS;AACX,UAAI;AACJ,UAAI,OAAO,YAAY,UAAU;AAC/B,wBAAY,wBAAS,YAAW,WAAW,OAAO,GAAG,aAAa;AAAA,MACpE,OAAO;AACL,oBAAY;AAAA,MACd;AACA,aAAO,KAAK,QAAQ,GAAG,UAAU,OAAO;AAAA,IAC1C;AACA,WAAO;AAAA,EACT;AAAA,EAEO,cAAc;AACnB,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,QAAQ;AACb,WAAO,OAAO,KAAK,QAAQ,SAAS,EAAE,GAAG,EAAE;AAAA,EAC7C;AAAA,EAEO,SAAiB;AACtB,WAAO,KAAK,KAAK,MAAM,CAAC;AAAA,EAC1B;AAAA,EAEO,oBAAoB;AACzB,WAAO,KAAK,SAAS,EAAE,YAAY;AAAA,EACrC;AAAA,EAEO,cAAc,SAAS,GAAG;AAC/B,WAAO,KAAK,UAAU,KAAK,MAAM,GAAG,MAAM,CAAC;AAAA,EAC7C;AAAA,EAEO,WAAW;AAChB,WAAO,KAAK,KAAK,MAAM,CAAC;AAAA,EAC1B;AACF;","names":[]}
1
+ {"version":3,"file":"index.js","sources":["../src/ellipsize.ts","../src/padHex.ts","../src/EthAddress.ts"],"sourcesContent":[null,null,null],"names":["BigNumber"],"mappings":";;;;;AAAA,MAAA,SAAa,GAAA,CAAA,KAAoB,EAAA,MAAA,GAAA,CAAA;;;;;;ACAjC,MAAA,SAAY,CAAA,GAAA,EAAA,cAA6B;AAazC,IAAO,IAAA,MAAQ,GAAE,GAAA,CAAA;;;;;;;;;;;;ACLjB,MAAA,YAAuB,GAAA,CAAA,GAAA,KAAA,GAAA,EAAA,IAAA,KAAA,UAAA,CAAA,KAAA;AACf,gBAAoB,CAAA;AAE1B,IAAA,OAAsB,IAAA,GAAA,YAAA,CAAA;IAEtB,IAAO,GAAA,UAAmB,CAAA,IAAA,CAAA;IAE1B,OAAO,CAAA;IAIP,mBAAkB,EAAA;QAOZ,IAAM,CAAA,OAAM,GAAA,QAAS;KAMrB;IAaN,OAAW,UAAA,CAAA,KAAA,EAAA,IAAA,GAAA,EAAA,EAAA;QAIN,IAAA,KAAA,EAAA;AAIL,kBAAgB,EAAA,GAAA,IAAAA,mBAAA,CAAA,KAAA,CAAA,UAAA,CAAA,IAAA,CAAA,GAAA,KAAA,CAAA,SAAA,CAAA,CAAA,CAAA,GAAA,KAAA,EAAA,IAAA,CAAA,CAAA;YAIC,OAAA,IAAA,UAAA,CAAA,EAAA,CAAA,CAAA;SAIJ;KAIL;AAGT,IAAA,OAAA,KAAA,CAAA,KAAA,EAAA,IAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/dist/index.mjs CHANGED
@@ -1,83 +1,76 @@
1
- // src/ellipsize.ts
2
- var ellipsize = (value, length = 2) => {
3
- const part1 = value.slice(0, length);
4
- const part2 = value.slice(value.length - length, value.length);
5
- return `${part1}...${part2}`;
6
- };
1
+ import { assertEx } from '@xylabs/assert';
2
+ import { BigNumber } from '@xylabs/bignumber';
7
3
 
8
- // src/EthAddress.ts
9
- import { assertEx } from "@xylabs/assert";
10
- import { BigNumber } from "@xylabs/bignumber";
4
+ const ellipsize = (value, length = 2) => {
5
+ const part1 = value.slice(0, length);
6
+ const part2 = value.slice(value.length - length, value.length);
7
+ return `${part1}...${part2}`;
8
+ };
11
9
 
12
- // src/padHex.ts
13
- var padHex = (hex, byteCount) => {
14
- let result = hex;
15
- if (hex.length % 2 !== 0) {
16
- result = `0${hex}`;
17
- }
18
- if (byteCount) {
19
- while (result.length / 2 < byteCount) {
20
- result = `00${result}`;
10
+ const padHex = (hex, byteCount) => {
11
+ let result = hex;
12
+ if (hex.length % 2 !== 0) {
13
+ result = `0${hex}`;
21
14
  }
22
- }
23
- return result;
15
+ if (byteCount) {
16
+ while (result.length / 2 < byteCount) {
17
+ result = `00${result}`;
18
+ }
19
+ }
20
+ return result;
24
21
  };
25
22
 
26
- // src/EthAddress.ts
27
- var isEthAddress = (obj) => obj?.type === EthAddress.type;
28
- var EthAddress = class _EthAddress {
29
- static type = "EthAddress";
30
- type = _EthAddress.type;
31
- address;
32
- constructor(address) {
33
- this.address = address;
34
- }
35
- static fromString(value, base = 16) {
36
- if (value) {
37
- const bn = new BigNumber(value.startsWith("0x") ? value.substring(2) : value, base);
38
- return new _EthAddress(bn);
23
+ const isEthAddress = (obj) => obj?.type === EthAddress.type;
24
+ class EthAddress {
25
+ static type = 'EthAddress';
26
+ type = EthAddress.type;
27
+ address;
28
+ constructor(address) {
29
+ this.address = address;
39
30
  }
40
- }
41
- static parse(value, base) {
42
- if (typeof value === "string") {
43
- return this.fromString(value, base);
31
+ static fromString(value, base = 16) {
32
+ if (value) {
33
+ const bn = new BigNumber(value.startsWith('0x') ? value.substring(2) : value, base);
34
+ return new EthAddress(bn);
35
+ }
44
36
  }
45
- }
46
- equals(address) {
47
- if (address) {
48
- let inAddress;
49
- if (typeof address === "string") {
50
- inAddress = assertEx(_EthAddress.fromString(address), "Bad Address");
51
- } else {
52
- inAddress = address;
53
- }
54
- return this.address.eq(inAddress.address);
37
+ static parse(value, base) {
38
+ if (typeof value === 'string') {
39
+ return this.fromString(value, base);
40
+ }
55
41
  }
56
- return false;
57
- }
58
- toBigNumber() {
59
- return this.address;
60
- }
61
- toHex() {
62
- return padHex(this.address.toString(16), 20);
63
- }
64
- toJSON() {
65
- return `0x${this.toHex()}`;
66
- }
67
- toLowerCaseString() {
68
- return this.toString().toLowerCase();
69
- }
70
- toShortString(length = 2) {
71
- return `0x${ellipsize(this.toHex(), length)}`;
72
- }
73
- toString() {
74
- return `0x${this.toHex()}`;
75
- }
76
- };
77
- export {
78
- EthAddress,
79
- ellipsize,
80
- isEthAddress,
81
- padHex
82
- };
83
- //# sourceMappingURL=index.mjs.map
42
+ equals(address) {
43
+ if (address) {
44
+ let inAddress;
45
+ if (typeof address === 'string') {
46
+ inAddress = assertEx(EthAddress.fromString(address), 'Bad Address');
47
+ }
48
+ else {
49
+ inAddress = address;
50
+ }
51
+ return this.address.eq(inAddress.address);
52
+ }
53
+ return false;
54
+ }
55
+ toBigNumber() {
56
+ return this.address;
57
+ }
58
+ toHex() {
59
+ return padHex(this.address.toString(16), 20);
60
+ }
61
+ toJSON() {
62
+ return `0x${this.toHex()}`;
63
+ }
64
+ toLowerCaseString() {
65
+ return this.toString().toLowerCase();
66
+ }
67
+ toShortString(length = 2) {
68
+ return `0x${ellipsize(this.toHex(), length)}`;
69
+ }
70
+ toString() {
71
+ return `0x${this.toHex()}`;
72
+ }
73
+ }
74
+
75
+ export { EthAddress, ellipsize, isEthAddress, padHex };
76
+ //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/ellipsize.ts","../src/EthAddress.ts","../src/padHex.ts"],"sourcesContent":["export const ellipsize = (value: string, length = 2) => {\n const part1 = value.slice(0, length)\n const part2 = value.slice(value.length - length, value.length)\n return `${part1}...${part2}`\n}\n","import { assertEx } from '@xylabs/assert'\nimport { BigNumber } from '@xylabs/bignumber'\n\nimport { ellipsize } from './ellipsize'\nimport { padHex } from './padHex'\n\nexport const isEthAddress = (obj: { type: string }) => obj?.type === EthAddress.type\n\nexport class EthAddress {\n static type = 'EthAddress'\n\n public type = EthAddress.type\n\n private address: BigNumber\n\n private constructor(address: BigNumber) {\n this.address = address\n }\n\n static fromString(value?: string, base = 16) {\n if (value) {\n const bn = new BigNumber(value.startsWith('0x') ? value.substring(2) : value, base)\n return new EthAddress(bn)\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 public equals(address?: EthAddress | string | null): boolean {\n if (address) {\n let inAddress: EthAddress\n if (typeof address === 'string') {\n inAddress = assertEx(EthAddress.fromString(address), 'Bad Address')\n } else {\n inAddress = address\n }\n return this.address.eq(inAddress.address)\n }\n return false\n }\n\n public toBigNumber() {\n return this.address\n }\n\n public toHex() {\n return padHex(this.address.toString(16), 20)\n }\n\n public toJSON(): string {\n return `0x${this.toHex()}`\n }\n\n public toLowerCaseString() {\n return this.toString().toLowerCase()\n }\n\n public toShortString(length = 2) {\n return `0x${ellipsize(this.toHex(), length)}`\n }\n\n public toString() {\n return `0x${this.toHex()}`\n }\n}\n","const padHex = (hex: string, byteCount?: number) => {\n let result = hex\n if (hex.length % 2 !== 0) {\n result = `0${hex}`\n }\n if (byteCount) {\n while (result.length / 2 < byteCount) {\n result = `00${result}`\n }\n }\n return result\n}\n\nexport { padHex }\n"],"mappings":";AAAO,IAAM,YAAY,CAAC,OAAe,SAAS,MAAM;AACtD,QAAM,QAAQ,MAAM,MAAM,GAAG,MAAM;AACnC,QAAM,QAAQ,MAAM,MAAM,MAAM,SAAS,QAAQ,MAAM,MAAM;AAC7D,SAAO,GAAG,KAAK,MAAM,KAAK;AAC5B;;;ACJA,SAAS,gBAAgB;AACzB,SAAS,iBAAiB;;;ACD1B,IAAM,SAAS,CAAC,KAAa,cAAuB;AAClD,MAAI,SAAS;AACb,MAAI,IAAI,SAAS,MAAM,GAAG;AACxB,aAAS,IAAI,GAAG;AAAA,EAClB;AACA,MAAI,WAAW;AACb,WAAO,OAAO,SAAS,IAAI,WAAW;AACpC,eAAS,KAAK,MAAM;AAAA,IACtB;AAAA,EACF;AACA,SAAO;AACT;;;ADLO,IAAM,eAAe,CAAC,QAA0B,KAAK,SAAS,WAAW;AAEzE,IAAM,aAAN,MAAM,YAAW;AAAA,EACtB,OAAO,OAAO;AAAA,EAEP,OAAO,YAAW;AAAA,EAEjB;AAAA,EAEA,YAAY,SAAoB;AACtC,SAAK,UAAU;AAAA,EACjB;AAAA,EAEA,OAAO,WAAW,OAAgB,OAAO,IAAI;AAC3C,QAAI,OAAO;AACT,YAAM,KAAK,IAAI,UAAU,MAAM,WAAW,IAAI,IAAI,MAAM,UAAU,CAAC,IAAI,OAAO,IAAI;AAClF,aAAO,IAAI,YAAW,EAAE;AAAA,IAC1B;AAAA,EACF;AAAA,EAEA,OAAO,MAAM,OAAgB,MAAe;AAC1C,QAAI,OAAO,UAAU,UAAU;AAC7B,aAAO,KAAK,WAAW,OAAO,IAAI;AAAA,IACpC;AAAA,EACF;AAAA,EAEO,OAAO,SAA+C;AAC3D,QAAI,SAAS;AACX,UAAI;AACJ,UAAI,OAAO,YAAY,UAAU;AAC/B,oBAAY,SAAS,YAAW,WAAW,OAAO,GAAG,aAAa;AAAA,MACpE,OAAO;AACL,oBAAY;AAAA,MACd;AACA,aAAO,KAAK,QAAQ,GAAG,UAAU,OAAO;AAAA,IAC1C;AACA,WAAO;AAAA,EACT;AAAA,EAEO,cAAc;AACnB,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,QAAQ;AACb,WAAO,OAAO,KAAK,QAAQ,SAAS,EAAE,GAAG,EAAE;AAAA,EAC7C;AAAA,EAEO,SAAiB;AACtB,WAAO,KAAK,KAAK,MAAM,CAAC;AAAA,EAC1B;AAAA,EAEO,oBAAoB;AACzB,WAAO,KAAK,SAAS,EAAE,YAAY;AAAA,EACrC;AAAA,EAEO,cAAc,SAAS,GAAG;AAC/B,WAAO,KAAK,UAAU,KAAK,MAAM,GAAG,MAAM,CAAC;AAAA,EAC7C;AAAA,EAEO,WAAW;AAChB,WAAO,KAAK,KAAK,MAAM,CAAC;AAAA,EAC1B;AACF;","names":[]}
1
+ {"version":3,"file":"index.mjs","sources":["../src/ellipsize.ts","../src/padHex.ts","../src/EthAddress.ts"],"sourcesContent":[null,null,null],"names":[],"mappings":";;;AAAA,MAAA,SAAa,GAAA,CAAA,KAAoB,EAAA,MAAA,GAAA,CAAA;;;;;;ACAjC,MAAA,SAAY,CAAA,GAAA,EAAA,cAA6B;AAazC,IAAO,IAAA,MAAQ,GAAE,GAAA,CAAA;;;;;;;;;;;;ACLjB,MAAA,YAAuB,GAAA,CAAA,GAAA,KAAA,GAAA,EAAA,IAAA,KAAA,UAAA,CAAA,KAAA;AACf,gBAAoB,CAAA;AAE1B,IAAA,OAAsB,IAAA,GAAA,YAAA,CAAA;IAEtB,IAAO,GAAA,UAAmB,CAAA,IAAA,CAAA;IAE1B,OAAO,CAAA;IAIP,mBAAkB,EAAA;QAOZ,IAAM,CAAA,OAAM,GAAA,QAAS;KAMrB;IAaN,OAAW,UAAA,CAAA,KAAA,EAAA,IAAA,GAAA,EAAA,EAAA;QAIN,IAAA,KAAA,EAAA;AAIL,kBAAgB,EAAA,GAAA,IAAA,SAAA,CAAA,KAAA,CAAA,UAAA,CAAA,IAAA,CAAA,GAAA,KAAA,CAAA,SAAA,CAAA,CAAA,CAAA,GAAA,KAAA,EAAA,IAAA,CAAA,CAAA;YAIC,OAAA,IAAA,UAAA,CAAA,EAAA,CAAA,CAAA;SAIJ;KAIL;AAGT,IAAA,OAAA,KAAA,CAAA,KAAA,EAAA,IAAA,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,3 @@
1
+ declare const padHex: (hex: string, byteCount?: number) => string;
2
+ export { padHex };
3
+ //# sourceMappingURL=padHex.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"padHex.d.ts","sourceRoot":"","sources":["../src/padHex.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,MAAM,QAAS,MAAM,cAAc,MAAM,WAW9C,CAAA;AAED,OAAO,EAAE,MAAM,EAAE,CAAA"}
package/package.json CHANGED
@@ -43,10 +43,6 @@
43
43
  },
44
44
  "main": "dist/index.js",
45
45
  "module": "dist/index.mjs",
46
- "scripts": {
47
- "package-compile": "tsup && publint",
48
- "package-recompile": "tsup && publint"
49
- },
50
46
  "homepage": "https://xylabs.com",
51
47
  "keywords": [
52
48
  "xylabs",
@@ -55,15 +51,13 @@
55
51
  "esm"
56
52
  ],
57
53
  "dependencies": {
58
- "@xylabs/assert": "~2.10.17",
59
- "@xylabs/bignumber": "~2.10.17"
54
+ "@xylabs/assert": "~2.11.0",
55
+ "@xylabs/bignumber": "~2.11.0"
60
56
  },
61
57
  "devDependencies": {
62
- "@xylabs/ts-scripts-yarn3": "^2.19.12",
63
- "@xylabs/tsconfig": "^2.19.12",
64
- "@xylabs/tsconfig-jest": "^2.19.12",
65
- "publint": "^0.2.2",
66
- "tsup": "^7.2.0"
58
+ "@xylabs/ts-scripts-yarn3": "^3.0.0-rc.15",
59
+ "@xylabs/tsconfig": "^3.0.0-rc.15",
60
+ "@xylabs/tsconfig-jest": "^3.0.0-rc.15"
67
61
  },
68
62
  "publishConfig": {
69
63
  "access": "public"
@@ -73,6 +67,6 @@
73
67
  "url": "https://github.com/xylabs/sdk-js.git"
74
68
  },
75
69
  "sideEffects": false,
76
- "version": "2.10.17",
70
+ "version": "2.11.0",
77
71
  "packageManager": "yarn@3.3.1"
78
72
  }
package/src/EthAddress.ts CHANGED
@@ -9,7 +9,7 @@ export const isEthAddress = (obj: { type: string }) => obj?.type === EthAddress.
9
9
  export class EthAddress {
10
10
  static type = 'EthAddress'
11
11
 
12
- public type = EthAddress.type
12
+ type = EthAddress.type
13
13
 
14
14
  private address: BigNumber
15
15
 
@@ -30,7 +30,7 @@ export class EthAddress {
30
30
  }
31
31
  }
32
32
 
33
- public equals(address?: EthAddress | string | null): boolean {
33
+ equals(address?: EthAddress | string | null): boolean {
34
34
  if (address) {
35
35
  let inAddress: EthAddress
36
36
  if (typeof address === 'string') {
@@ -43,27 +43,27 @@ export class EthAddress {
43
43
  return false
44
44
  }
45
45
 
46
- public toBigNumber() {
46
+ toBigNumber() {
47
47
  return this.address
48
48
  }
49
49
 
50
- public toHex() {
50
+ toHex() {
51
51
  return padHex(this.address.toString(16), 20)
52
52
  }
53
53
 
54
- public toJSON(): string {
54
+ toJSON(): string {
55
55
  return `0x${this.toHex()}`
56
56
  }
57
57
 
58
- public toLowerCaseString() {
58
+ toLowerCaseString() {
59
59
  return this.toString().toLowerCase()
60
60
  }
61
61
 
62
- public toShortString(length = 2) {
62
+ toShortString(length = 2) {
63
63
  return `0x${ellipsize(this.toHex(), length)}`
64
64
  }
65
65
 
66
- public toString() {
66
+ toString() {
67
67
  return `0x${this.toHex()}`
68
68
  }
69
69
  }
package/tsup.config.ts DELETED
@@ -1,16 +0,0 @@
1
- import { defineConfig } from 'tsup'
2
-
3
- // eslint-disable-next-line import/no-default-export
4
- export default defineConfig({
5
- bundle: true,
6
- cjsInterop: true,
7
- clean: false,
8
- dts: {
9
- entry: ['src/index.ts'],
10
- },
11
- entry: ['src/index.ts'],
12
- format: ['cjs', 'esm'],
13
- sourcemap: true,
14
- splitting: false,
15
- tsconfig: 'tsconfig.build.json',
16
- })