@xylabs/eth-address 2.10.18 → 2.11.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/EthAddress.d.ts +20 -0
- package/dist/EthAddress.d.ts.map +1 -0
- package/dist/EthAddress.js +62 -0
- package/dist/EthAddress.js.map +1 -0
- package/dist/EthAddress.mjs +59 -0
- package/dist/EthAddress.mjs.map +1 -0
- package/dist/ellipsize.d.ts +2 -0
- package/dist/ellipsize.d.ts.map +1 -0
- package/dist/ellipsize.js +10 -0
- package/dist/ellipsize.js.map +1 -0
- package/dist/ellipsize.mjs +8 -0
- package/dist/ellipsize.mjs.map +1 -0
- package/dist/index.d.mts +4 -26
- package/dist/index.d.mts.map +1 -0
- package/dist/index.d.ts +4 -26
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -109
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +6 -83
- package/dist/index.mjs.map +1 -1
- package/dist/padHex.d.ts +3 -0
- package/dist/padHex.d.ts.map +1 -0
- package/dist/padHex.js +17 -0
- package/dist/padHex.js.map +1 -0
- package/dist/padHex.mjs +15 -0
- package/dist/padHex.mjs.map +1 -0
- package/package.json +6 -12
- package/src/EthAddress.ts +8 -8
- package/tsup.config.ts +0 -16
|
@@ -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,62 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ellipsize = require('./ellipsize.js');
|
|
4
|
+
var assert = require('@xylabs/assert');
|
|
5
|
+
var bignumber = require('@xylabs/bignumber');
|
|
6
|
+
var padHex = require('./padHex.js');
|
|
7
|
+
|
|
8
|
+
const isEthAddress = (obj) => obj?.type === EthAddress.type;
|
|
9
|
+
class EthAddress {
|
|
10
|
+
static type = 'EthAddress';
|
|
11
|
+
type = EthAddress.type;
|
|
12
|
+
address;
|
|
13
|
+
constructor(address) {
|
|
14
|
+
this.address = address;
|
|
15
|
+
}
|
|
16
|
+
static fromString(value, base = 16) {
|
|
17
|
+
if (value) {
|
|
18
|
+
const bn = new bignumber.BigNumber(value.startsWith('0x') ? value.substring(2) : value, base);
|
|
19
|
+
return new EthAddress(bn);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
static parse(value, base) {
|
|
23
|
+
if (typeof value === 'string') {
|
|
24
|
+
return this.fromString(value, base);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
equals(address) {
|
|
28
|
+
if (address) {
|
|
29
|
+
let inAddress;
|
|
30
|
+
if (typeof address === 'string') {
|
|
31
|
+
inAddress = assert.assertEx(EthAddress.fromString(address), 'Bad Address');
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
inAddress = address;
|
|
35
|
+
}
|
|
36
|
+
return this.address.eq(inAddress.address);
|
|
37
|
+
}
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
toBigNumber() {
|
|
41
|
+
return this.address;
|
|
42
|
+
}
|
|
43
|
+
toHex() {
|
|
44
|
+
return padHex.padHex(this.address.toString(16), 20);
|
|
45
|
+
}
|
|
46
|
+
toJSON() {
|
|
47
|
+
return `0x${this.toHex()}`;
|
|
48
|
+
}
|
|
49
|
+
toLowerCaseString() {
|
|
50
|
+
return this.toString().toLowerCase();
|
|
51
|
+
}
|
|
52
|
+
toShortString(length = 2) {
|
|
53
|
+
return `0x${ellipsize.ellipsize(this.toHex(), length)}`;
|
|
54
|
+
}
|
|
55
|
+
toString() {
|
|
56
|
+
return `0x${this.toHex()}`;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
exports.EthAddress = EthAddress;
|
|
61
|
+
exports.isEthAddress = isEthAddress;
|
|
62
|
+
//# sourceMappingURL=EthAddress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EthAddress.js","sources":["../src/EthAddress.ts"],"sourcesContent":[null],"names":["BigNumber"],"mappings":";;;;;;;AAQA,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { ellipsize } from './ellipsize.mjs';
|
|
2
|
+
import { assertEx } from '@xylabs/assert';
|
|
3
|
+
import { BigNumber } from '@xylabs/bignumber';
|
|
4
|
+
import { padHex } from './padHex.mjs';
|
|
5
|
+
|
|
6
|
+
const isEthAddress = (obj) => obj?.type === EthAddress.type;
|
|
7
|
+
class EthAddress {
|
|
8
|
+
static type = 'EthAddress';
|
|
9
|
+
type = EthAddress.type;
|
|
10
|
+
address;
|
|
11
|
+
constructor(address) {
|
|
12
|
+
this.address = address;
|
|
13
|
+
}
|
|
14
|
+
static fromString(value, base = 16) {
|
|
15
|
+
if (value) {
|
|
16
|
+
const bn = new BigNumber(value.startsWith('0x') ? value.substring(2) : value, base);
|
|
17
|
+
return new EthAddress(bn);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
static parse(value, base) {
|
|
21
|
+
if (typeof value === 'string') {
|
|
22
|
+
return this.fromString(value, base);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
equals(address) {
|
|
26
|
+
if (address) {
|
|
27
|
+
let inAddress;
|
|
28
|
+
if (typeof address === 'string') {
|
|
29
|
+
inAddress = assertEx(EthAddress.fromString(address), 'Bad Address');
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
inAddress = address;
|
|
33
|
+
}
|
|
34
|
+
return this.address.eq(inAddress.address);
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
toBigNumber() {
|
|
39
|
+
return this.address;
|
|
40
|
+
}
|
|
41
|
+
toHex() {
|
|
42
|
+
return padHex(this.address.toString(16), 20);
|
|
43
|
+
}
|
|
44
|
+
toJSON() {
|
|
45
|
+
return `0x${this.toHex()}`;
|
|
46
|
+
}
|
|
47
|
+
toLowerCaseString() {
|
|
48
|
+
return this.toString().toLowerCase();
|
|
49
|
+
}
|
|
50
|
+
toShortString(length = 2) {
|
|
51
|
+
return `0x${ellipsize(this.toHex(), length)}`;
|
|
52
|
+
}
|
|
53
|
+
toString() {
|
|
54
|
+
return `0x${this.toHex()}`;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export { EthAddress, isEthAddress };
|
|
59
|
+
//# sourceMappingURL=EthAddress.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EthAddress.mjs","sources":["../src/EthAddress.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AAQA,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 @@
|
|
|
1
|
+
{"version":3,"file":"ellipsize.d.ts","sourceRoot":"","sources":["../src/ellipsize.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,UAAW,MAAM,4BAItC,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const ellipsize = (value, length = 2) => {
|
|
4
|
+
const part1 = value.slice(0, length);
|
|
5
|
+
const part2 = value.slice(value.length - length, value.length);
|
|
6
|
+
return `${part1}...${part2}`;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
exports.ellipsize = ellipsize;
|
|
10
|
+
//# sourceMappingURL=ellipsize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ellipsize.js","sources":["../src/ellipsize.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAAA,MAAA,SAAa,GAAA,CAAA,KAAoB,EAAA,MAAA,GAAA,CAAA;;;;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ellipsize.mjs","sources":["../src/ellipsize.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAA,MAAA,SAAa,GAAA,CAAA,KAAoB,EAAA,MAAA,GAAA,CAAA;;;;;;;;"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,26 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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,15 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
21
|
-
var
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
isEthAddress: () => isEthAddress,
|
|
26
|
-
padHex: () => padHex
|
|
27
|
-
});
|
|
28
|
-
module.exports = __toCommonJS(src_exports);
|
|
3
|
+
var ellipsize = require('./ellipsize.js');
|
|
4
|
+
var EthAddress = require('./EthAddress.js');
|
|
5
|
+
var padHex = require('./padHex.js');
|
|
6
|
+
require('@xylabs/assert');
|
|
7
|
+
require('@xylabs/bignumber');
|
|
29
8
|
|
|
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
9
|
|
|
37
|
-
// src/EthAddress.ts
|
|
38
|
-
var import_assert = require("@xylabs/assert");
|
|
39
|
-
var import_bignumber = require("@xylabs/bignumber");
|
|
40
10
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
|
11
|
+
exports.ellipsize = ellipsize.ellipsize;
|
|
12
|
+
exports.EthAddress = EthAddress.EthAddress;
|
|
13
|
+
exports.isEthAddress = EthAddress.isEthAddress;
|
|
14
|
+
exports.padHex = padHex.padHex;
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,83 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
|
1
|
+
export { ellipsize } from './ellipsize.mjs';
|
|
2
|
+
export { EthAddress, isEthAddress } from './EthAddress.mjs';
|
|
3
|
+
export { padHex } from './padHex.mjs';
|
|
4
|
+
import '@xylabs/assert';
|
|
5
|
+
import '@xylabs/bignumber';
|
|
6
|
+
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
package/dist/padHex.d.ts
ADDED
|
@@ -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/dist/padHex.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const padHex = (hex, byteCount) => {
|
|
4
|
+
let result = hex;
|
|
5
|
+
if (hex.length % 2 !== 0) {
|
|
6
|
+
result = `0${hex}`;
|
|
7
|
+
}
|
|
8
|
+
if (byteCount) {
|
|
9
|
+
while (result.length / 2 < byteCount) {
|
|
10
|
+
result = `00${result}`;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return result;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
exports.padHex = padHex;
|
|
17
|
+
//# sourceMappingURL=padHex.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"padHex.js","sources":["../src/padHex.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAAA,MAAA,SAAY,CAAA,GAAA,EAAA,cAA6B;AAazC,IAAO,IAAA,MAAQ,GAAE,GAAA,CAAA;;;;;;;;;;;;;;"}
|
package/dist/padHex.mjs
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const padHex = (hex, byteCount) => {
|
|
2
|
+
let result = hex;
|
|
3
|
+
if (hex.length % 2 !== 0) {
|
|
4
|
+
result = `0${hex}`;
|
|
5
|
+
}
|
|
6
|
+
if (byteCount) {
|
|
7
|
+
while (result.length / 2 < byteCount) {
|
|
8
|
+
result = `00${result}`;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return result;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export { padHex };
|
|
15
|
+
//# sourceMappingURL=padHex.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"padHex.mjs","sources":["../src/padHex.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAA,MAAA,SAAY,CAAA,GAAA,EAAA,cAA6B;AAazC,IAAO,IAAA,MAAQ,GAAE,GAAA,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.
|
|
59
|
-
"@xylabs/bignumber": "~2.
|
|
54
|
+
"@xylabs/assert": "~2.11.1",
|
|
55
|
+
"@xylabs/bignumber": "~2.11.1"
|
|
60
56
|
},
|
|
61
57
|
"devDependencies": {
|
|
62
|
-
"@xylabs/ts-scripts-yarn3": "^
|
|
63
|
-
"@xylabs/tsconfig": "^
|
|
64
|
-
"@xylabs/tsconfig-jest": "^
|
|
65
|
-
"publint": "^0.2.2",
|
|
66
|
-
"tsup": "^7.2.0"
|
|
58
|
+
"@xylabs/ts-scripts-yarn3": "^3.0.0-rc.16",
|
|
59
|
+
"@xylabs/tsconfig": "^3.0.0-rc.16",
|
|
60
|
+
"@xylabs/tsconfig-jest": "^3.0.0-rc.16"
|
|
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.
|
|
70
|
+
"version": "2.11.1",
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
46
|
+
toBigNumber() {
|
|
47
47
|
return this.address
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
toHex() {
|
|
51
51
|
return padHex(this.address.toString(16), 20)
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
toJSON(): string {
|
|
55
55
|
return `0x${this.toHex()}`
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
toLowerCaseString() {
|
|
59
59
|
return this.toString().toLowerCase()
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
|
|
62
|
+
toShortString(length = 2) {
|
|
63
63
|
return `0x${ellipsize(this.toHex(), length)}`
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
|
|
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
|
-
})
|