@xylabs/eth-address 2.11.18 → 2.11.20

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,79 @@
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
+ var EthAddress_exports = {};
20
+ __export(EthAddress_exports, {
21
+ EthAddress: () => EthAddress,
22
+ isEthAddress: () => isEthAddress
23
+ });
24
+ module.exports = __toCommonJS(EthAddress_exports);
25
+ var import_assert = require("@xylabs/assert");
26
+ var import_bignumber = require("@xylabs/bignumber");
27
+ var import_ellipsize = require("./ellipsize");
28
+ var import_padHex = require("./padHex");
29
+ const isEthAddress = (obj) => obj?.type === EthAddress.type;
30
+ class EthAddress {
31
+ static type = "EthAddress";
32
+ type = EthAddress.type;
33
+ address;
34
+ constructor(address) {
35
+ this.address = address;
36
+ }
37
+ static fromString(value, base = 16) {
38
+ if (value) {
39
+ const bn = new import_bignumber.BigNumber(value.startsWith("0x") ? value.substring(2) : value, base);
40
+ return new EthAddress(bn);
41
+ }
42
+ }
43
+ static parse(value, base) {
44
+ if (typeof value === "string") {
45
+ return this.fromString(value, base);
46
+ }
47
+ }
48
+ equals(address) {
49
+ if (address) {
50
+ let inAddress;
51
+ if (typeof address === "string") {
52
+ inAddress = (0, import_assert.assertEx)(EthAddress.fromString(address), "Bad Address");
53
+ } else {
54
+ inAddress = address;
55
+ }
56
+ return this.address.eq(inAddress.address);
57
+ }
58
+ return false;
59
+ }
60
+ toBigNumber() {
61
+ return this.address;
62
+ }
63
+ toHex() {
64
+ return (0, import_padHex.padHex)(this.address.toString(16), 20);
65
+ }
66
+ toJSON() {
67
+ return `0x${this.toHex()}`;
68
+ }
69
+ toLowerCaseString() {
70
+ return this.toString().toLowerCase();
71
+ }
72
+ toShortString(length = 2) {
73
+ return `0x${(0, import_ellipsize.ellipsize)(this.toHex(), length)}`;
74
+ }
75
+ toString() {
76
+ return `0x${this.toHex()}`;
77
+ }
78
+ }
79
+ //# sourceMappingURL=EthAddress.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/EthAddress.ts"],"sourcesContent":["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 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 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 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() {\n return `0x${this.toHex()}`\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAyB;AACzB,uBAA0B;AAE1B,uBAA0B;AAC1B,oBAAuB;AAEhB,MAAM,eAAe,CAAC,QAA0B,KAAK,SAAS,WAAW;AAEzE,MAAM,WAAW;AAAA,EACtB,OAAO,OAAO;AAAA,EAEd,OAAO,WAAW;AAAA,EAEV;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,WAAW,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,EAEA,OAAO,SAA+C;AACpD,QAAI,SAAS;AACX,UAAI;AACJ,UAAI,OAAO,YAAY,UAAU;AAC/B,wBAAY,wBAAS,WAAW,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,EAEA,cAAc;AACZ,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,QAAQ;AACN,eAAO,sBAAO,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,SAAK,4BAAU,KAAK,MAAM,GAAG,MAAM,CAAC;AAAA,EAC7C;AAAA,EAEA,WAAW;AACT,WAAO,KAAK,KAAK,MAAM,CAAC;AAAA,EAC1B;AACF;","names":[]}
@@ -0,0 +1,29 @@
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
+ var ellipsize_exports = {};
20
+ __export(ellipsize_exports, {
21
+ ellipsize: () => ellipsize
22
+ });
23
+ module.exports = __toCommonJS(ellipsize_exports);
24
+ const ellipsize = (value, length = 2) => {
25
+ const part1 = value.slice(0, length);
26
+ const part2 = value.slice(value.length - length, value.length);
27
+ return `${part1}...${part2}`;
28
+ };
29
+ //# sourceMappingURL=ellipsize.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/ellipsize.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"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,MAAM,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;","names":[]}
@@ -0,0 +1,21 @@
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 __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+ var src_exports = {};
17
+ module.exports = __toCommonJS(src_exports);
18
+ __reExport(src_exports, require("./ellipsize"), module.exports);
19
+ __reExport(src_exports, require("./EthAddress"), module.exports);
20
+ __reExport(src_exports, require("./padHex"), module.exports);
21
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './ellipsize'\nexport * from './EthAddress'\nexport * from './padHex'\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAc,wBAAd;AACA,wBAAc,yBADd;AAEA,wBAAc,qBAFd;","names":[]}
@@ -0,0 +1,36 @@
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
+ var padHex_exports = {};
20
+ __export(padHex_exports, {
21
+ padHex: () => padHex
22
+ });
23
+ module.exports = __toCommonJS(padHex_exports);
24
+ const padHex = (hex, byteCount) => {
25
+ let result = hex;
26
+ if (hex.length % 2 !== 0) {
27
+ result = `0${hex}`;
28
+ }
29
+ if (byteCount) {
30
+ while (result.length / 2 < byteCount) {
31
+ result = `00${result}`;
32
+ }
33
+ }
34
+ return result;
35
+ };
36
+ //# sourceMappingURL=padHex.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/padHex.ts"],"sourcesContent":["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,MAAM,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;","names":[]}
package/package.json CHANGED
@@ -42,13 +42,13 @@
42
42
  "esm"
43
43
  ],
44
44
  "dependencies": {
45
- "@xylabs/assert": "~2.11.18",
46
- "@xylabs/bignumber": "~2.11.18"
45
+ "@xylabs/assert": "~2.11.20",
46
+ "@xylabs/bignumber": "~2.11.20"
47
47
  },
48
48
  "devDependencies": {
49
- "@xylabs/ts-scripts-yarn3": "^3.0.65",
50
- "@xylabs/tsconfig": "^3.0.65",
51
- "@xylabs/tsconfig-jest": "^3.0.65",
49
+ "@xylabs/ts-scripts-yarn3": "^3.0.68",
50
+ "@xylabs/tsconfig": "^3.0.68",
51
+ "@xylabs/tsconfig-jest": "^3.0.68",
52
52
  "typescript": "^5.2.2"
53
53
  },
54
54
  "publishConfig": {
@@ -59,6 +59,6 @@
59
59
  "url": "https://github.com/xylabs/sdk-js.git"
60
60
  },
61
61
  "sideEffects": false,
62
- "version": "2.11.18",
62
+ "version": "2.11.20",
63
63
  "packageManager": "yarn@3.3.1"
64
64
  }