@xylabs/eth-address 2.9.3 → 2.10.1
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/dist/{types/EthAddress.d.ts → index.d.mts} +9 -4
- package/dist/index.d.ts +26 -0
- package/dist/index.js +113 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +83 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +31 -18
- package/tsup.config.ts +16 -0
- package/dist/cjs/EthAddress.js +0 -60
- package/dist/cjs/EthAddress.js.map +0 -1
- package/dist/cjs/ellipsize.js +0 -10
- package/dist/cjs/ellipsize.js.map +0 -1
- package/dist/cjs/index.js +0 -7
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/padHex.js +0 -17
- package/dist/cjs/padHex.js.map +0 -1
- package/dist/docs.json +0 -1086
- package/dist/esm/EthAddress.js +0 -56
- package/dist/esm/EthAddress.js.map +0 -1
- package/dist/esm/ellipsize.js +0 -6
- package/dist/esm/ellipsize.js.map +0 -1
- package/dist/esm/index.js +0 -4
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/padHex.js +0 -14
- package/dist/esm/padHex.js.map +0 -1
- package/dist/types/EthAddress.d.ts.map +0 -1
- package/dist/types/ellipsize.d.ts +0 -2
- package/dist/types/ellipsize.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -4
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/padHex.d.ts +0 -3
- package/dist/types/padHex.d.ts.map +0 -1
- package/docs/assets/highlight.css +0 -50
- package/docs/assets/main.js +0 -58
- package/docs/assets/search.js +0 -1
- package/docs/assets/style.css +0 -1367
- package/docs/classes/EthAddress.html +0 -221
- package/docs/functions/ellipsize.html +0 -55
- package/docs/functions/isEthAddress.html +0 -56
- package/docs/functions/padHex.html +0 -55
- package/docs/index.html +0 -85
- package/docs/modules.html +0 -51
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
/// <reference types="bn.js" />
|
|
2
1
|
import { BigNumber } from '@xylabs/bignumber';
|
|
3
|
-
|
|
2
|
+
|
|
3
|
+
declare const ellipsize: (value: string, length?: number) => string;
|
|
4
|
+
|
|
5
|
+
declare const isEthAddress: (obj: {
|
|
4
6
|
type: string;
|
|
5
7
|
}) => boolean;
|
|
6
|
-
|
|
8
|
+
declare class EthAddress {
|
|
7
9
|
static type: string;
|
|
8
10
|
type: string;
|
|
9
11
|
private address;
|
|
@@ -18,4 +20,7 @@ export declare class EthAddress {
|
|
|
18
20
|
toShortString(length?: number): string;
|
|
19
21
|
toString(): string;
|
|
20
22
|
}
|
|
21
|
-
|
|
23
|
+
|
|
24
|
+
declare const padHex: (hex: string, byteCount?: number) => string;
|
|
25
|
+
|
|
26
|
+
export { EthAddress, ellipsize, isEthAddress, padHex };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
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 };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
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);
|
|
19
|
+
|
|
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);
|
|
29
|
+
|
|
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}`;
|
|
35
|
+
};
|
|
36
|
+
|
|
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}`;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
53
|
+
};
|
|
54
|
+
|
|
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);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
static parse(value, base) {
|
|
71
|
+
if (typeof value === "string") {
|
|
72
|
+
return this.fromString(value, base);
|
|
73
|
+
}
|
|
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);
|
|
84
|
+
}
|
|
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
|
|
@@ -0,0 +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":[]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
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
|
+
};
|
|
7
|
+
|
|
8
|
+
// src/EthAddress.ts
|
|
9
|
+
import { assertEx } from "@xylabs/assert";
|
|
10
|
+
import { BigNumber } from "@xylabs/bignumber";
|
|
11
|
+
|
|
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}`;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
|
|
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);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
static parse(value, base) {
|
|
42
|
+
if (typeof value === "string") {
|
|
43
|
+
return this.fromString(value, base);
|
|
44
|
+
}
|
|
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);
|
|
55
|
+
}
|
|
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
|
|
@@ -0,0 +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":[]}
|
package/package.json
CHANGED
|
@@ -14,28 +14,39 @@
|
|
|
14
14
|
"packages/**/*"
|
|
15
15
|
],
|
|
16
16
|
"description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
|
|
17
|
-
"browser": "dist/esm/index.js",
|
|
18
|
-
"main": "dist/cjs/index.js",
|
|
19
|
-
"module": "dist/esm/index.js",
|
|
20
17
|
"docs": "dist/docs.json",
|
|
21
|
-
"types": "dist/
|
|
18
|
+
"types": "dist/index.d.ts",
|
|
22
19
|
"exports": {
|
|
23
20
|
".": {
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
21
|
+
"require": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"default": "./dist/index.js"
|
|
27
24
|
},
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
}
|
|
32
|
-
"default": "./dist/esm/index.js"
|
|
25
|
+
"import": {
|
|
26
|
+
"types": "./dist/index.d.mts",
|
|
27
|
+
"default": "./dist/index.mjs"
|
|
28
|
+
}
|
|
33
29
|
},
|
|
34
30
|
"./dist/docs.json": {
|
|
35
31
|
"default": "./dist/docs.json"
|
|
36
32
|
},
|
|
33
|
+
"./cjs": {
|
|
34
|
+
"default": "./dist/index.js"
|
|
35
|
+
},
|
|
36
|
+
"./docs": {
|
|
37
|
+
"default": "./dist/docs.json"
|
|
38
|
+
},
|
|
39
|
+
"./esm": {
|
|
40
|
+
"default": "./dist/index.mjs"
|
|
41
|
+
},
|
|
37
42
|
"./package.json": "./package.json"
|
|
38
43
|
},
|
|
44
|
+
"main": "dist/index.js",
|
|
45
|
+
"module": "dist/index.mjs",
|
|
46
|
+
"scripts": {
|
|
47
|
+
"package-compile": "tsup && publint",
|
|
48
|
+
"package-recompile": "tsup && publint"
|
|
49
|
+
},
|
|
39
50
|
"homepage": "https://xylabs.com",
|
|
40
51
|
"keywords": [
|
|
41
52
|
"xylabs",
|
|
@@ -44,13 +55,15 @@
|
|
|
44
55
|
"esm"
|
|
45
56
|
],
|
|
46
57
|
"dependencies": {
|
|
47
|
-
"@xylabs/assert": "
|
|
48
|
-
"@xylabs/bignumber": "
|
|
58
|
+
"@xylabs/assert": "~2.10.1",
|
|
59
|
+
"@xylabs/bignumber": "~2.10.1"
|
|
49
60
|
},
|
|
50
61
|
"devDependencies": {
|
|
51
|
-
"@xylabs/
|
|
52
|
-
"@xylabs/
|
|
53
|
-
"
|
|
62
|
+
"@xylabs/ts-scripts-yarn3": "^2.19.5",
|
|
63
|
+
"@xylabs/tsconfig": "^2.19.5",
|
|
64
|
+
"@xylabs/tsconfig-jest": "^2.19.5",
|
|
65
|
+
"publint": "^0.2.2",
|
|
66
|
+
"tsup": "^7.2.0"
|
|
54
67
|
},
|
|
55
68
|
"publishConfig": {
|
|
56
69
|
"access": "public"
|
|
@@ -60,6 +73,6 @@
|
|
|
60
73
|
"url": "https://github.com/xylabs/sdk-js.git"
|
|
61
74
|
},
|
|
62
75
|
"sideEffects": false,
|
|
63
|
-
"version": "2.
|
|
76
|
+
"version": "2.10.1",
|
|
64
77
|
"packageManager": "yarn@3.3.1"
|
|
65
78
|
}
|
package/tsup.config.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
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: true,
|
|
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
|
+
})
|
package/dist/cjs/EthAddress.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EthAddress = exports.isEthAddress = void 0;
|
|
4
|
-
const assert_1 = require("@xylabs/assert");
|
|
5
|
-
const bignumber_1 = require("@xylabs/bignumber");
|
|
6
|
-
const ellipsize_1 = require("./ellipsize");
|
|
7
|
-
const padHex_1 = require("./padHex");
|
|
8
|
-
const isEthAddress = (obj) => (obj === null || obj === void 0 ? void 0 : obj.type) === EthAddress.type;
|
|
9
|
-
exports.isEthAddress = isEthAddress;
|
|
10
|
-
class EthAddress {
|
|
11
|
-
constructor(address) {
|
|
12
|
-
this.type = EthAddress.type;
|
|
13
|
-
this.address = address;
|
|
14
|
-
}
|
|
15
|
-
static fromString(value, base = 16) {
|
|
16
|
-
if (value) {
|
|
17
|
-
const bn = new bignumber_1.BigNumber(value.startsWith('0x') ? value.substring(2) : value, base);
|
|
18
|
-
return new EthAddress(bn);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
static parse(value, base) {
|
|
22
|
-
if (typeof value === 'string') {
|
|
23
|
-
return this.fromString(value, base);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
equals(address) {
|
|
27
|
-
if (address) {
|
|
28
|
-
let inAddress;
|
|
29
|
-
if (typeof address === 'string') {
|
|
30
|
-
inAddress = (0, assert_1.assertEx)(EthAddress.fromString(address), 'Bad Address');
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
inAddress = address;
|
|
34
|
-
}
|
|
35
|
-
return this.address.eq(inAddress.address);
|
|
36
|
-
}
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
toBigNumber() {
|
|
40
|
-
return this.address;
|
|
41
|
-
}
|
|
42
|
-
toHex() {
|
|
43
|
-
return (0, padHex_1.padHex)(this.address.toString(16), 20);
|
|
44
|
-
}
|
|
45
|
-
toJSON() {
|
|
46
|
-
return `0x${this.toHex()}`;
|
|
47
|
-
}
|
|
48
|
-
toLowerCaseString() {
|
|
49
|
-
return this.toString().toLowerCase();
|
|
50
|
-
}
|
|
51
|
-
toShortString(length = 2) {
|
|
52
|
-
return `0x${(0, ellipsize_1.ellipsize)(this.toHex(), length)}`;
|
|
53
|
-
}
|
|
54
|
-
toString() {
|
|
55
|
-
return `0x${this.toHex()}`;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
exports.EthAddress = EthAddress;
|
|
59
|
-
EthAddress.type = 'EthAddress';
|
|
60
|
-
//# sourceMappingURL=EthAddress.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EthAddress.js","sourceRoot":"","sources":["../../src/EthAddress.ts"],"names":[],"mappings":";;;AAAA,2CAAyC;AACzC,iDAA6C;AAE7C,2CAAuC;AACvC,qCAAiC;AAE1B,MAAM,YAAY,GAAG,CAAC,GAAqB,EAAE,EAAE,CAAC,CAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,IAAI,MAAK,UAAU,CAAC,IAAI,CAAA;AAAvE,QAAA,YAAY,gBAA2D;AAEpF,MAAa,UAAU;IAOrB,YAAoB,OAAkB;QAJ/B,SAAI,GAAG,UAAU,CAAC,IAAI,CAAA;QAK3B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;IAED,MAAM,CAAC,UAAU,CAAC,KAAc,EAAE,IAAI,GAAG,EAAE;QACzC,IAAI,KAAK,EAAE;YACT,MAAM,EAAE,GAAG,IAAI,qBAAS,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;YACnF,OAAO,IAAI,UAAU,CAAC,EAAE,CAAC,CAAA;SAC1B;IACH,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,KAAc,EAAE,IAAa;QACxC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC7B,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;SACpC;IACH,CAAC;IAEM,MAAM,CAAC,OAAoC;QAChD,IAAI,OAAO,EAAE;YACX,IAAI,SAAqB,CAAA;YACzB,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;gBAC/B,SAAS,GAAG,IAAA,iBAAQ,EAAC,UAAU,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,aAAa,CAAC,CAAA;aACpE;iBAAM;gBACL,SAAS,GAAG,OAAO,CAAA;aACpB;YACD,OAAO,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;SAC1C;QACD,OAAO,KAAK,CAAA;IACd,CAAC;IAEM,WAAW;QAChB,OAAO,IAAI,CAAC,OAAO,CAAA;IACrB,CAAC;IAEM,KAAK;QACV,OAAO,IAAA,eAAM,EAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAA;IAC9C,CAAC;IAEM,MAAM;QACX,OAAO,KAAK,IAAI,CAAC,KAAK,EAAE,EAAE,CAAA;IAC5B,CAAC;IAEM,iBAAiB;QACtB,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC,WAAW,EAAE,CAAA;IACtC,CAAC;IAEM,aAAa,CAAC,MAAM,GAAG,CAAC;QAC7B,OAAO,KAAK,IAAA,qBAAS,EAAC,IAAI,CAAC,KAAK,EAAE,EAAE,MAAM,CAAC,EAAE,CAAA;IAC/C,CAAC;IAEM,QAAQ;QACb,OAAO,KAAK,IAAI,CAAC,KAAK,EAAE,EAAE,CAAA;IAC5B,CAAC;;AA3DH,gCA4DC;AA3DQ,eAAI,GAAG,YAAY,CAAA"}
|
package/dist/cjs/ellipsize.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ellipsize = void 0;
|
|
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
|
-
};
|
|
9
|
-
exports.ellipsize = ellipsize;
|
|
10
|
-
//# sourceMappingURL=ellipsize.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ellipsize.js","sourceRoot":"","sources":["../../src/ellipsize.ts"],"names":[],"mappings":";;;AAAO,MAAM,SAAS,GAAG,CAAC,KAAa,EAAE,MAAM,GAAG,CAAC,EAAE,EAAE;IACrD,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,CAAA;IACpC,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;IAC9D,OAAO,GAAG,KAAK,MAAM,KAAK,EAAE,CAAA;AAC9B,CAAC,CAAA;AAJY,QAAA,SAAS,aAIrB"}
|
package/dist/cjs/index.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./ellipsize"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./EthAddress"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./padHex"), exports);
|
|
7
|
-
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,sDAA2B;AAC3B,uDAA4B;AAC5B,mDAAwB"}
|
package/dist/cjs/padHex.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.padHex = void 0;
|
|
4
|
-
const padHex = (hex, byteCount) => {
|
|
5
|
-
let result = hex;
|
|
6
|
-
if (hex.length % 2 !== 0) {
|
|
7
|
-
result = `0${hex}`;
|
|
8
|
-
}
|
|
9
|
-
if (byteCount) {
|
|
10
|
-
while (result.length / 2 < byteCount) {
|
|
11
|
-
result = `00${result}`;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
return result;
|
|
15
|
-
};
|
|
16
|
-
exports.padHex = padHex;
|
|
17
|
-
//# sourceMappingURL=padHex.js.map
|
package/dist/cjs/padHex.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"padHex.js","sourceRoot":"","sources":["../../src/padHex.ts"],"names":[],"mappings":";;;AAAA,MAAM,MAAM,GAAG,CAAC,GAAW,EAAE,SAAkB,EAAE,EAAE;IACjD,IAAI,MAAM,GAAG,GAAG,CAAA;IAChB,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,EAAE;QACxB,MAAM,GAAG,IAAI,GAAG,EAAE,CAAA;KACnB;IACD,IAAI,SAAS,EAAE;QACb,OAAO,MAAM,CAAC,MAAM,GAAG,CAAC,GAAG,SAAS,EAAE;YACpC,MAAM,GAAG,KAAK,MAAM,EAAE,CAAA;SACvB;KACF;IACD,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AAEQ,wBAAM"}
|