@xylabs/hex 2.13.10
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/LICENSE +165 -0
- package/README.md +69 -0
- package/dist/browser/address.d.cts +9 -0
- package/dist/browser/address.d.cts.map +1 -0
- package/dist/browser/address.d.mts +9 -0
- package/dist/browser/address.d.mts.map +1 -0
- package/dist/browser/address.d.ts +9 -0
- package/dist/browser/address.d.ts.map +1 -0
- package/dist/browser/assert.d.cts +4 -0
- package/dist/browser/assert.d.cts.map +1 -0
- package/dist/browser/assert.d.mts +4 -0
- package/dist/browser/assert.d.mts.map +1 -0
- package/dist/browser/assert.d.ts +4 -0
- package/dist/browser/assert.d.ts.map +1 -0
- package/dist/browser/hash.d.cts +13 -0
- package/dist/browser/hash.d.cts.map +1 -0
- package/dist/browser/hash.d.mts +13 -0
- package/dist/browser/hash.d.mts.map +1 -0
- package/dist/browser/hash.d.ts +13 -0
- package/dist/browser/hash.d.ts.map +1 -0
- package/dist/browser/hex.d.cts +14 -0
- package/dist/browser/hex.d.cts.map +1 -0
- package/dist/browser/hex.d.mts +14 -0
- package/dist/browser/hex.d.mts.map +1 -0
- package/dist/browser/hex.d.ts +14 -0
- package/dist/browser/hex.d.ts.map +1 -0
- package/dist/browser/index.cjs +153 -0
- package/dist/browser/index.cjs.map +1 -0
- package/dist/browser/index.d.cts +4 -0
- package/dist/browser/index.d.cts.map +1 -0
- package/dist/browser/index.d.mts +4 -0
- package/dist/browser/index.d.mts.map +1 -0
- package/dist/browser/index.d.ts +4 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.js +130 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/node/address.d.cts +9 -0
- package/dist/node/address.d.cts.map +1 -0
- package/dist/node/address.d.mts +9 -0
- package/dist/node/address.d.mts.map +1 -0
- package/dist/node/address.d.ts +9 -0
- package/dist/node/address.d.ts.map +1 -0
- package/dist/node/assert.d.cts +4 -0
- package/dist/node/assert.d.cts.map +1 -0
- package/dist/node/assert.d.mts +4 -0
- package/dist/node/assert.d.mts.map +1 -0
- package/dist/node/assert.d.ts +4 -0
- package/dist/node/assert.d.ts.map +1 -0
- package/dist/node/hash.d.cts +13 -0
- package/dist/node/hash.d.cts.map +1 -0
- package/dist/node/hash.d.mts +13 -0
- package/dist/node/hash.d.mts.map +1 -0
- package/dist/node/hash.d.ts +13 -0
- package/dist/node/hash.d.ts.map +1 -0
- package/dist/node/hex.d.cts +14 -0
- package/dist/node/hex.d.cts.map +1 -0
- package/dist/node/hex.d.mts +14 -0
- package/dist/node/hex.d.mts.map +1 -0
- package/dist/node/hex.d.ts +14 -0
- package/dist/node/hex.d.ts.map +1 -0
- package/dist/node/index.cjs +172 -0
- package/dist/node/index.cjs.map +1 -0
- package/dist/node/index.d.cts +4 -0
- package/dist/node/index.d.cts.map +1 -0
- package/dist/node/index.d.mts +4 -0
- package/dist/node/index.d.mts.map +1 -0
- package/dist/node/index.d.ts +4 -0
- package/dist/node/index.d.ts.map +1 -0
- package/dist/node/index.js +130 -0
- package/dist/node/index.js.map +1 -0
- package/package.json +56 -0
- package/src/address.ts +33 -0
- package/src/assert.ts +13 -0
- package/src/hash.ts +37 -0
- package/src/hex.ts +80 -0
- package/src/index.ts +3 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
|
2
|
+
Version 3, 29 June 2007
|
|
3
|
+
|
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
|
6
|
+
of this license document, but changing it is not allowed.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
This version of the GNU Lesser General Public License incorporates
|
|
10
|
+
the terms and conditions of version 3 of the GNU General Public
|
|
11
|
+
License, supplemented by the additional permissions listed below.
|
|
12
|
+
|
|
13
|
+
0. Additional Definitions.
|
|
14
|
+
|
|
15
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
|
16
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
|
17
|
+
General Public License.
|
|
18
|
+
|
|
19
|
+
"The Library" refers to a covered work governed by this License,
|
|
20
|
+
other than an Application or a Combined Work as defined below.
|
|
21
|
+
|
|
22
|
+
An "Application" is any work that makes use of an interface provided
|
|
23
|
+
by the Library, but which is not otherwise based on the Library.
|
|
24
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
|
25
|
+
of using an interface provided by the Library.
|
|
26
|
+
|
|
27
|
+
A "Combined Work" is a work produced by combining or linking an
|
|
28
|
+
Application with the Library. The particular version of the Library
|
|
29
|
+
with which the Combined Work was made is also called the "Linked
|
|
30
|
+
Version".
|
|
31
|
+
|
|
32
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
|
33
|
+
Corresponding Source for the Combined Work, excluding any source code
|
|
34
|
+
for portions of the Combined Work that, considered in isolation, are
|
|
35
|
+
based on the Application, and not on the Linked Version.
|
|
36
|
+
|
|
37
|
+
The "Corresponding Application Code" for a Combined Work means the
|
|
38
|
+
object code and/or source code for the Application, including any data
|
|
39
|
+
and utility programs needed for reproducing the Combined Work from the
|
|
40
|
+
Application, but excluding the System Libraries of the Combined Work.
|
|
41
|
+
|
|
42
|
+
1. Exception to Section 3 of the GNU GPL.
|
|
43
|
+
|
|
44
|
+
You may convey a covered work under sections 3 and 4 of this License
|
|
45
|
+
without being bound by section 3 of the GNU GPL.
|
|
46
|
+
|
|
47
|
+
2. Conveying Modified Versions.
|
|
48
|
+
|
|
49
|
+
If you modify a copy of the Library, and, in your modifications, a
|
|
50
|
+
facility refers to a function or data to be supplied by an Application
|
|
51
|
+
that uses the facility (other than as an argument passed when the
|
|
52
|
+
facility is invoked), then you may convey a copy of the modified
|
|
53
|
+
version:
|
|
54
|
+
|
|
55
|
+
a) under this License, provided that you make a good faith effort to
|
|
56
|
+
ensure that, in the event an Application does not supply the
|
|
57
|
+
function or data, the facility still operates, and performs
|
|
58
|
+
whatever part of its purpose remains meaningful, or
|
|
59
|
+
|
|
60
|
+
b) under the GNU GPL, with none of the additional permissions of
|
|
61
|
+
this License applicable to that copy.
|
|
62
|
+
|
|
63
|
+
3. Object Code Incorporating Material from Library Header Files.
|
|
64
|
+
|
|
65
|
+
The object code form of an Application may incorporate material from
|
|
66
|
+
a header file that is part of the Library. You may convey such object
|
|
67
|
+
code under terms of your choice, provided that, if the incorporated
|
|
68
|
+
material is not limited to numerical parameters, data structure
|
|
69
|
+
layouts and accessors, or small macros, inline functions and templates
|
|
70
|
+
(ten or fewer lines in length), you do both of the following:
|
|
71
|
+
|
|
72
|
+
a) Give prominent notice with each copy of the object code that the
|
|
73
|
+
Library is used in it and that the Library and its use are
|
|
74
|
+
covered by this License.
|
|
75
|
+
|
|
76
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
|
77
|
+
document.
|
|
78
|
+
|
|
79
|
+
4. Combined Works.
|
|
80
|
+
|
|
81
|
+
You may convey a Combined Work under terms of your choice that,
|
|
82
|
+
taken together, effectively do not restrict modification of the
|
|
83
|
+
portions of the Library contained in the Combined Work and reverse
|
|
84
|
+
engineering for debugging such modifications, if you also do each of
|
|
85
|
+
the following:
|
|
86
|
+
|
|
87
|
+
a) Give prominent notice with each copy of the Combined Work that
|
|
88
|
+
the Library is used in it and that the Library and its use are
|
|
89
|
+
covered by this License.
|
|
90
|
+
|
|
91
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
|
92
|
+
document.
|
|
93
|
+
|
|
94
|
+
c) For a Combined Work that displays copyright notices during
|
|
95
|
+
execution, include the copyright notice for the Library among
|
|
96
|
+
these notices, as well as a reference directing the user to the
|
|
97
|
+
copies of the GNU GPL and this license document.
|
|
98
|
+
|
|
99
|
+
d) Do one of the following:
|
|
100
|
+
|
|
101
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
|
102
|
+
License, and the Corresponding Application Code in a form
|
|
103
|
+
suitable for, and under terms that permit, the user to
|
|
104
|
+
recombine or relink the Application with a modified version of
|
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
|
107
|
+
Corresponding Source.
|
|
108
|
+
|
|
109
|
+
1) Use a suitable shared library mechanism for linking with the
|
|
110
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
|
111
|
+
a copy of the Library already present on the user's computer
|
|
112
|
+
system, and (b) will operate properly with a modified version
|
|
113
|
+
of the Library that is interface-compatible with the Linked
|
|
114
|
+
Version.
|
|
115
|
+
|
|
116
|
+
e) Provide Installation Information, but only if you would otherwise
|
|
117
|
+
be required to provide such information under section 6 of the
|
|
118
|
+
GNU GPL, and only to the extent that such information is
|
|
119
|
+
necessary to install and execute a modified version of the
|
|
120
|
+
Combined Work produced by recombining or relinking the
|
|
121
|
+
Application with a modified version of the Linked Version. (If
|
|
122
|
+
you use option 4d0, the Installation Information must accompany
|
|
123
|
+
the Minimal Corresponding Source and Corresponding Application
|
|
124
|
+
Code. If you use option 4d1, you must provide the Installation
|
|
125
|
+
Information in the manner specified by section 6 of the GNU GPL
|
|
126
|
+
for conveying Corresponding Source.)
|
|
127
|
+
|
|
128
|
+
5. Combined Libraries.
|
|
129
|
+
|
|
130
|
+
You may place library facilities that are a work based on the
|
|
131
|
+
Library side by side in a single library together with other library
|
|
132
|
+
facilities that are not Applications and are not covered by this
|
|
133
|
+
License, and convey such a combined library under terms of your
|
|
134
|
+
choice, if you do both of the following:
|
|
135
|
+
|
|
136
|
+
a) Accompany the combined library with a copy of the same work based
|
|
137
|
+
on the Library, uncombined with any other library facilities,
|
|
138
|
+
conveyed under the terms of this License.
|
|
139
|
+
|
|
140
|
+
b) Give prominent notice with the combined library that part of it
|
|
141
|
+
is a work based on the Library, and explaining where to find the
|
|
142
|
+
accompanying uncombined form of the same work.
|
|
143
|
+
|
|
144
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
|
145
|
+
|
|
146
|
+
The Free Software Foundation may publish revised and/or new versions
|
|
147
|
+
of the GNU Lesser General Public License from time to time. Such new
|
|
148
|
+
versions will be similar in spirit to the present version, but may
|
|
149
|
+
differ in detail to address new problems or concerns.
|
|
150
|
+
|
|
151
|
+
Each version is given a distinguishing version number. If the
|
|
152
|
+
Library as you received it specifies that a certain numbered version
|
|
153
|
+
of the GNU Lesser General Public License "or any later version"
|
|
154
|
+
applies to it, you have the option of following the terms and
|
|
155
|
+
conditions either of that published version or of any later version
|
|
156
|
+
published by the Free Software Foundation. If the Library as you
|
|
157
|
+
received it does not specify a version number of the GNU Lesser
|
|
158
|
+
General Public License, you may choose any version of the GNU Lesser
|
|
159
|
+
General Public License ever published by the Free Software Foundation.
|
|
160
|
+
|
|
161
|
+
If the Library as you received it specifies that a proxy can decide
|
|
162
|
+
whether future versions of the GNU Lesser General Public License shall
|
|
163
|
+
apply, that proxy's public statement of acceptance of any version is
|
|
164
|
+
permanent authorization for you to choose that version for the
|
|
165
|
+
Library.
|
package/README.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
[![logo][]](https://xylabs.com)
|
|
2
|
+
|
|
3
|
+
# @xylabs/hex
|
|
4
|
+
|
|
5
|
+
[![npm-badge][]][npm-link]
|
|
6
|
+
[![npm-downloads-badge][]][npm-link]
|
|
7
|
+
[![jsdelivr-badge][]][jsdelivr-link]
|
|
8
|
+
[![npm-license-badge][]](LICENSE)
|
|
9
|
+
[![socket-badge][]][socket-link]
|
|
10
|
+
|
|
11
|
+
> XY Labs generalized Javascript library
|
|
12
|
+
|
|
13
|
+
## Table of Contents
|
|
14
|
+
|
|
15
|
+
- [Description](#description)
|
|
16
|
+
- [Install](#install)
|
|
17
|
+
- [Maintainers](#maintainers)
|
|
18
|
+
- [License](#license)
|
|
19
|
+
- [Credits](#credits)
|
|
20
|
+
|
|
21
|
+
## Description
|
|
22
|
+
|
|
23
|
+
Common Javascript code that is used throughout XYO projects that use React.
|
|
24
|
+
|
|
25
|
+
## Install
|
|
26
|
+
|
|
27
|
+
Using npm:
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
npm i --save @xylabs/hex
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Using yarn:
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
yarn add @xylabs/hex
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Documentation
|
|
40
|
+
[Developer Reference](https://xylabs.github.io/sdk-js)
|
|
41
|
+
|
|
42
|
+
## Maintainers
|
|
43
|
+
|
|
44
|
+
- [Arie Trouw](https://github.com/arietrouw) ([arietrouw.com](https://arietrouw.com))
|
|
45
|
+
- [Joel Carter](https://github.com/JoelBCarter)
|
|
46
|
+
- [Matt Jones](https://github.com/jonesmac)
|
|
47
|
+
- [Jordan Trouw](https://github.com/jordantrouw)
|
|
48
|
+
|
|
49
|
+
## License
|
|
50
|
+
|
|
51
|
+
See the [LICENSE](LICENSE) file for license details
|
|
52
|
+
|
|
53
|
+
## Credits
|
|
54
|
+
|
|
55
|
+
[Made with 🔥and ❄️ by XY Labs](https://xylabs.com)
|
|
56
|
+
|
|
57
|
+
[logo]: https://cdn.xy.company/img/brand/XYPersistentCompany_Logo_Icon_Colored.svg
|
|
58
|
+
|
|
59
|
+
[npm-badge]: https://img.shields.io/npm/v/@xylabs/hex.svg
|
|
60
|
+
[npm-link]: https://www.npmjs.com/package/@xylabs/hex
|
|
61
|
+
|
|
62
|
+
[npm-downloads-badge]: https://img.shields.io/npm/dw/@xylabs/hex
|
|
63
|
+
[npm-license-badge]: https://img.shields.io/npm/l/@xylabs/hex
|
|
64
|
+
|
|
65
|
+
[jsdelivr-badge]: https://data.jsdelivr.com/v1/package/npm/@xylabs/hex/badge
|
|
66
|
+
[jsdelivr-link]: https://www.jsdelivr.com/package/npm/@xylabs/hex
|
|
67
|
+
|
|
68
|
+
[socket-badge]: https://socket.dev/api/badge/npm/package/@xylabs/hex
|
|
69
|
+
[socket-link]: https://socket.dev/npm/package/@xylabs/hex
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AssertConfig } from './assert';
|
|
2
|
+
export declare const addressRegex: RegExp;
|
|
3
|
+
export type Address = string;
|
|
4
|
+
export declare const isAddress: (value: unknown, bitLength?: number) => value is string;
|
|
5
|
+
export declare function asAddress(value: unknown): Address | undefined;
|
|
6
|
+
export declare function asAddress(value: unknown, assert: AssertConfig): Address;
|
|
7
|
+
export declare function asAddress(value: unknown, bitLength: number): Address | undefined;
|
|
8
|
+
export declare function asAddress(value: unknown, bitLength: number, assert: AssertConfig): Address;
|
|
9
|
+
//# sourceMappingURL=address.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../../src/address.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAe,MAAM,UAAU,CAAA;AAGpD,eAAO,MAAM,YAAY,QAAiB,CAAA;AAE1C,MAAM,MAAM,OAAO,GAAG,MAAM,CAAA;AAE5B,eAAO,MAAM,SAAS,UAAW,OAAO,wCAavC,CAAA;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,GAAG,SAAS,CAAA;AAC9D,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,GAAG,OAAO,CAAA;AACxE,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAAA;AACjF,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,GAAG,OAAO,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AssertConfig } from './assert';
|
|
2
|
+
export declare const addressRegex: RegExp;
|
|
3
|
+
export type Address = string;
|
|
4
|
+
export declare const isAddress: (value: unknown, bitLength?: number) => value is string;
|
|
5
|
+
export declare function asAddress(value: unknown): Address | undefined;
|
|
6
|
+
export declare function asAddress(value: unknown, assert: AssertConfig): Address;
|
|
7
|
+
export declare function asAddress(value: unknown, bitLength: number): Address | undefined;
|
|
8
|
+
export declare function asAddress(value: unknown, bitLength: number, assert: AssertConfig): Address;
|
|
9
|
+
//# sourceMappingURL=address.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../../src/address.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAe,MAAM,UAAU,CAAA;AAGpD,eAAO,MAAM,YAAY,QAAiB,CAAA;AAE1C,MAAM,MAAM,OAAO,GAAG,MAAM,CAAA;AAE5B,eAAO,MAAM,SAAS,UAAW,OAAO,wCAavC,CAAA;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,GAAG,SAAS,CAAA;AAC9D,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,GAAG,OAAO,CAAA;AACxE,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAAA;AACjF,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,GAAG,OAAO,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AssertConfig } from './assert';
|
|
2
|
+
export declare const addressRegex: RegExp;
|
|
3
|
+
export type Address = string;
|
|
4
|
+
export declare const isAddress: (value: unknown, bitLength?: number) => value is string;
|
|
5
|
+
export declare function asAddress(value: unknown): Address | undefined;
|
|
6
|
+
export declare function asAddress(value: unknown, assert: AssertConfig): Address;
|
|
7
|
+
export declare function asAddress(value: unknown, bitLength: number): Address | undefined;
|
|
8
|
+
export declare function asAddress(value: unknown, bitLength: number, assert: AssertConfig): Address;
|
|
9
|
+
//# sourceMappingURL=address.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../../src/address.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAe,MAAM,UAAU,CAAA;AAGpD,eAAO,MAAM,YAAY,QAAiB,CAAA;AAE1C,MAAM,MAAM,OAAO,GAAG,MAAM,CAAA;AAE5B,eAAO,MAAM,SAAS,UAAW,OAAO,wCAavC,CAAA;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,GAAG,SAAS,CAAA;AAC9D,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,GAAG,OAAO,CAAA;AACxE,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAAA;AACjF,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,GAAG,OAAO,CAAA"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type AssertCallback = (value: unknown, message: string) => string | boolean;
|
|
2
|
+
export type AssertConfig = string | AssertCallback | boolean;
|
|
3
|
+
export declare const assertError: (value: unknown, assert: AssertConfig | undefined, defaultMessage: string) => undefined;
|
|
4
|
+
//# sourceMappingURL=assert.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../src/assert.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,KAAK,MAAM,GAAG,OAAO,CAAA;AAElF,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,cAAc,GAAG,OAAO,CAAA;AAE5D,eAAO,MAAM,WAAW,UAAW,OAAO,UAAU,YAAY,GAAG,SAAS,kBAAkB,MAAM,cAQnG,CAAA"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type AssertCallback = (value: unknown, message: string) => string | boolean;
|
|
2
|
+
export type AssertConfig = string | AssertCallback | boolean;
|
|
3
|
+
export declare const assertError: (value: unknown, assert: AssertConfig | undefined, defaultMessage: string) => undefined;
|
|
4
|
+
//# sourceMappingURL=assert.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../src/assert.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,KAAK,MAAM,GAAG,OAAO,CAAA;AAElF,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,cAAc,GAAG,OAAO,CAAA;AAE5D,eAAO,MAAM,WAAW,UAAW,OAAO,UAAU,YAAY,GAAG,SAAS,kBAAkB,MAAM,cAQnG,CAAA"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type AssertCallback = (value: unknown, message: string) => string | boolean;
|
|
2
|
+
export type AssertConfig = string | AssertCallback | boolean;
|
|
3
|
+
export declare const assertError: (value: unknown, assert: AssertConfig | undefined, defaultMessage: string) => undefined;
|
|
4
|
+
//# sourceMappingURL=assert.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../src/assert.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,KAAK,MAAM,GAAG,OAAO,CAAA;AAElF,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,cAAc,GAAG,OAAO,CAAA;AAE5D,eAAO,MAAM,WAAW,UAAW,OAAO,UAAU,YAAY,GAAG,SAAS,kBAAkB,MAAM,cAQnG,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AssertConfig } from './assert';
|
|
2
|
+
import { Hex } from './hex';
|
|
3
|
+
export type HashBitLength = 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096;
|
|
4
|
+
export declare const HashBitLength: HashBitLength[];
|
|
5
|
+
export declare const isHashBitLength: (value: unknown) => value is HashBitLength;
|
|
6
|
+
export type Hash = Hex;
|
|
7
|
+
export declare const isHash: (value: unknown, bitLength?: HashBitLength) => value is string;
|
|
8
|
+
export declare const toHex: (buffer: ArrayBuffer) => string;
|
|
9
|
+
export declare function asHash(value: unknown): Hash | undefined;
|
|
10
|
+
export declare function asHash(value: unknown, assert: AssertConfig): Hash;
|
|
11
|
+
export declare function asHash(value: unknown, bitLength?: HashBitLength): Hash | undefined;
|
|
12
|
+
export declare function asHash(value: unknown, bitLength: HashBitLength | undefined, assert: AssertConfig): Hash;
|
|
13
|
+
//# sourceMappingURL=hash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/hash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAe,MAAM,UAAU,CAAA;AACpD,OAAO,EAAS,GAAG,EAAuB,MAAM,OAAO,CAAA;AAEvD,MAAM,MAAM,aAAa,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAA;AAC1E,eAAO,MAAM,aAAa,EAAE,aAAa,EAA8C,CAAA;AAEvF,eAAO,MAAM,eAAe,UAAW,OAAO,2BAE7C,CAAA;AAED,MAAM,MAAM,IAAI,GAAG,GAAG,CAAA;AACtB,eAAO,MAAM,MAAM,UAAW,OAAO,cAAa,aAAa,oBAS9D,CAAA;AAED,eAAO,MAAM,KAAK,WAAY,WAAW,WAExC,CAAA;AAED,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,GAAG,SAAS,CAAA;AACxD,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,GAAG,IAAI,CAAA;AAClE,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,CAAC,EAAE,aAAa,GAAG,IAAI,GAAG,SAAS,CAAA;AACnF,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,aAAa,GAAG,SAAS,EAAE,MAAM,EAAE,YAAY,GAAG,IAAI,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AssertConfig } from './assert';
|
|
2
|
+
import { Hex } from './hex';
|
|
3
|
+
export type HashBitLength = 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096;
|
|
4
|
+
export declare const HashBitLength: HashBitLength[];
|
|
5
|
+
export declare const isHashBitLength: (value: unknown) => value is HashBitLength;
|
|
6
|
+
export type Hash = Hex;
|
|
7
|
+
export declare const isHash: (value: unknown, bitLength?: HashBitLength) => value is string;
|
|
8
|
+
export declare const toHex: (buffer: ArrayBuffer) => string;
|
|
9
|
+
export declare function asHash(value: unknown): Hash | undefined;
|
|
10
|
+
export declare function asHash(value: unknown, assert: AssertConfig): Hash;
|
|
11
|
+
export declare function asHash(value: unknown, bitLength?: HashBitLength): Hash | undefined;
|
|
12
|
+
export declare function asHash(value: unknown, bitLength: HashBitLength | undefined, assert: AssertConfig): Hash;
|
|
13
|
+
//# sourceMappingURL=hash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/hash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAe,MAAM,UAAU,CAAA;AACpD,OAAO,EAAS,GAAG,EAAuB,MAAM,OAAO,CAAA;AAEvD,MAAM,MAAM,aAAa,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAA;AAC1E,eAAO,MAAM,aAAa,EAAE,aAAa,EAA8C,CAAA;AAEvF,eAAO,MAAM,eAAe,UAAW,OAAO,2BAE7C,CAAA;AAED,MAAM,MAAM,IAAI,GAAG,GAAG,CAAA;AACtB,eAAO,MAAM,MAAM,UAAW,OAAO,cAAa,aAAa,oBAS9D,CAAA;AAED,eAAO,MAAM,KAAK,WAAY,WAAW,WAExC,CAAA;AAED,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,GAAG,SAAS,CAAA;AACxD,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,GAAG,IAAI,CAAA;AAClE,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,CAAC,EAAE,aAAa,GAAG,IAAI,GAAG,SAAS,CAAA;AACnF,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,aAAa,GAAG,SAAS,EAAE,MAAM,EAAE,YAAY,GAAG,IAAI,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AssertConfig } from './assert';
|
|
2
|
+
import { Hex } from './hex';
|
|
3
|
+
export type HashBitLength = 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096;
|
|
4
|
+
export declare const HashBitLength: HashBitLength[];
|
|
5
|
+
export declare const isHashBitLength: (value: unknown) => value is HashBitLength;
|
|
6
|
+
export type Hash = Hex;
|
|
7
|
+
export declare const isHash: (value: unknown, bitLength?: HashBitLength) => value is string;
|
|
8
|
+
export declare const toHex: (buffer: ArrayBuffer) => string;
|
|
9
|
+
export declare function asHash(value: unknown): Hash | undefined;
|
|
10
|
+
export declare function asHash(value: unknown, assert: AssertConfig): Hash;
|
|
11
|
+
export declare function asHash(value: unknown, bitLength?: HashBitLength): Hash | undefined;
|
|
12
|
+
export declare function asHash(value: unknown, bitLength: HashBitLength | undefined, assert: AssertConfig): Hash;
|
|
13
|
+
//# sourceMappingURL=hash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/hash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAe,MAAM,UAAU,CAAA;AACpD,OAAO,EAAS,GAAG,EAAuB,MAAM,OAAO,CAAA;AAEvD,MAAM,MAAM,aAAa,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAA;AAC1E,eAAO,MAAM,aAAa,EAAE,aAAa,EAA8C,CAAA;AAEvF,eAAO,MAAM,eAAe,UAAW,OAAO,2BAE7C,CAAA;AAED,MAAM,MAAM,IAAI,GAAG,GAAG,CAAA;AACtB,eAAO,MAAM,MAAM,UAAW,OAAO,cAAa,aAAa,oBAS9D,CAAA;AAED,eAAO,MAAM,KAAK,WAAY,WAAW,WAExC,CAAA;AAED,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,GAAG,SAAS,CAAA;AACxD,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,GAAG,IAAI,CAAA;AAClE,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,CAAC,EAAE,aAAa,GAAG,IAAI,GAAG,SAAS,CAAA;AACnF,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,aAAa,GAAG,SAAS,EAAE,MAAM,EAAE,YAAY,GAAG,IAAI,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AssertConfig } from './assert';
|
|
2
|
+
export declare const hexRegex: RegExp;
|
|
3
|
+
export declare const hexRegexWithPrefix: RegExp;
|
|
4
|
+
export type Hex = string;
|
|
5
|
+
export declare const hexFrom: (buffer: ArrayBuffer) => string;
|
|
6
|
+
export declare const bitsToOctets: (value: number) => number;
|
|
7
|
+
export declare const octetsToBits: (value: number) => number;
|
|
8
|
+
export declare const isRoundOctet: (value: number) => boolean;
|
|
9
|
+
export declare const isHex: (value: unknown, bitLength?: number) => value is string;
|
|
10
|
+
export declare function asHex(value: unknown): Hex | undefined;
|
|
11
|
+
export declare function asHex(value: unknown, bitLength?: number): Hex | undefined;
|
|
12
|
+
export declare function asHex(value: unknown, assert: AssertConfig): Hex;
|
|
13
|
+
export declare function asHex(value: unknown, bitLength: number | undefined, assert?: AssertConfig): Hex;
|
|
14
|
+
//# sourceMappingURL=hex.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hex.d.ts","sourceRoot":"","sources":["../../src/hex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAe,MAAM,UAAU,CAAA;AAEpD,eAAO,MAAM,QAAQ,QAAiB,CAAA;AACtC,eAAO,MAAM,kBAAkB,QAAkB,CAAA;AAEjD,MAAM,MAAM,GAAG,GAAG,MAAM,CAAA;AAExB,eAAO,MAAM,OAAO,WAAY,WAAW,WAE1C,CAAA;AAGD,eAAO,MAAM,YAAY,UAAW,MAAM,KAAG,MAI5C,CAAA;AAGD,eAAO,MAAM,YAAY,UAAW,MAAM,KAAG,MAE5C,CAAA;AAGD,eAAO,MAAM,YAAY,UAAW,MAAM,YAEzC,CAAA;AAED,eAAO,MAAM,KAAK,UAAW,OAAO,cAAc,MAAM,oBASvD,CAAA;AAED,wBAAgB,KAAK,CAAC,KAAK,EAAE,OAAO,GAAG,GAAG,GAAG,SAAS,CAAA;AACtD,wBAAgB,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,GAAG,GAAG,SAAS,CAAA;AAC1E,wBAAgB,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,GAAG,GAAG,CAAA;AAChE,wBAAgB,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,GAAG,SAAS,EAAE,MAAM,CAAC,EAAE,YAAY,GAAG,GAAG,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AssertConfig } from './assert';
|
|
2
|
+
export declare const hexRegex: RegExp;
|
|
3
|
+
export declare const hexRegexWithPrefix: RegExp;
|
|
4
|
+
export type Hex = string;
|
|
5
|
+
export declare const hexFrom: (buffer: ArrayBuffer) => string;
|
|
6
|
+
export declare const bitsToOctets: (value: number) => number;
|
|
7
|
+
export declare const octetsToBits: (value: number) => number;
|
|
8
|
+
export declare const isRoundOctet: (value: number) => boolean;
|
|
9
|
+
export declare const isHex: (value: unknown, bitLength?: number) => value is string;
|
|
10
|
+
export declare function asHex(value: unknown): Hex | undefined;
|
|
11
|
+
export declare function asHex(value: unknown, bitLength?: number): Hex | undefined;
|
|
12
|
+
export declare function asHex(value: unknown, assert: AssertConfig): Hex;
|
|
13
|
+
export declare function asHex(value: unknown, bitLength: number | undefined, assert?: AssertConfig): Hex;
|
|
14
|
+
//# sourceMappingURL=hex.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hex.d.ts","sourceRoot":"","sources":["../../src/hex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAe,MAAM,UAAU,CAAA;AAEpD,eAAO,MAAM,QAAQ,QAAiB,CAAA;AACtC,eAAO,MAAM,kBAAkB,QAAkB,CAAA;AAEjD,MAAM,MAAM,GAAG,GAAG,MAAM,CAAA;AAExB,eAAO,MAAM,OAAO,WAAY,WAAW,WAE1C,CAAA;AAGD,eAAO,MAAM,YAAY,UAAW,MAAM,KAAG,MAI5C,CAAA;AAGD,eAAO,MAAM,YAAY,UAAW,MAAM,KAAG,MAE5C,CAAA;AAGD,eAAO,MAAM,YAAY,UAAW,MAAM,YAEzC,CAAA;AAED,eAAO,MAAM,KAAK,UAAW,OAAO,cAAc,MAAM,oBASvD,CAAA;AAED,wBAAgB,KAAK,CAAC,KAAK,EAAE,OAAO,GAAG,GAAG,GAAG,SAAS,CAAA;AACtD,wBAAgB,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,GAAG,GAAG,SAAS,CAAA;AAC1E,wBAAgB,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,GAAG,GAAG,CAAA;AAChE,wBAAgB,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,GAAG,SAAS,EAAE,MAAM,CAAC,EAAE,YAAY,GAAG,GAAG,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AssertConfig } from './assert';
|
|
2
|
+
export declare const hexRegex: RegExp;
|
|
3
|
+
export declare const hexRegexWithPrefix: RegExp;
|
|
4
|
+
export type Hex = string;
|
|
5
|
+
export declare const hexFrom: (buffer: ArrayBuffer) => string;
|
|
6
|
+
export declare const bitsToOctets: (value: number) => number;
|
|
7
|
+
export declare const octetsToBits: (value: number) => number;
|
|
8
|
+
export declare const isRoundOctet: (value: number) => boolean;
|
|
9
|
+
export declare const isHex: (value: unknown, bitLength?: number) => value is string;
|
|
10
|
+
export declare function asHex(value: unknown): Hex | undefined;
|
|
11
|
+
export declare function asHex(value: unknown, bitLength?: number): Hex | undefined;
|
|
12
|
+
export declare function asHex(value: unknown, assert: AssertConfig): Hex;
|
|
13
|
+
export declare function asHex(value: unknown, bitLength: number | undefined, assert?: AssertConfig): Hex;
|
|
14
|
+
//# sourceMappingURL=hex.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hex.d.ts","sourceRoot":"","sources":["../../src/hex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAe,MAAM,UAAU,CAAA;AAEpD,eAAO,MAAM,QAAQ,QAAiB,CAAA;AACtC,eAAO,MAAM,kBAAkB,QAAkB,CAAA;AAEjD,MAAM,MAAM,GAAG,GAAG,MAAM,CAAA;AAExB,eAAO,MAAM,OAAO,WAAY,WAAW,WAE1C,CAAA;AAGD,eAAO,MAAM,YAAY,UAAW,MAAM,KAAG,MAI5C,CAAA;AAGD,eAAO,MAAM,YAAY,UAAW,MAAM,KAAG,MAE5C,CAAA;AAGD,eAAO,MAAM,YAAY,UAAW,MAAM,YAEzC,CAAA;AAED,eAAO,MAAM,KAAK,UAAW,OAAO,cAAc,MAAM,oBASvD,CAAA;AAED,wBAAgB,KAAK,CAAC,KAAK,EAAE,OAAO,GAAG,GAAG,GAAG,SAAS,CAAA;AACtD,wBAAgB,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,GAAG,GAAG,SAAS,CAAA;AAC1E,wBAAgB,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,GAAG,GAAG,CAAA;AAChE,wBAAgB,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,GAAG,SAAS,EAAE,MAAM,CAAC,EAAE,YAAY,GAAG,GAAG,CAAA"}
|
|
@@ -0,0 +1,153 @@
|
|
|
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
|
+
HashBitLength: () => HashBitLength,
|
|
24
|
+
addressRegex: () => addressRegex,
|
|
25
|
+
asAddress: () => asAddress,
|
|
26
|
+
asHash: () => asHash,
|
|
27
|
+
asHex: () => asHex,
|
|
28
|
+
bitsToOctets: () => bitsToOctets,
|
|
29
|
+
hexFrom: () => hexFrom,
|
|
30
|
+
hexRegex: () => hexRegex,
|
|
31
|
+
hexRegexWithPrefix: () => hexRegexWithPrefix,
|
|
32
|
+
isAddress: () => isAddress,
|
|
33
|
+
isHash: () => isHash,
|
|
34
|
+
isHashBitLength: () => isHashBitLength,
|
|
35
|
+
isHex: () => isHex,
|
|
36
|
+
isRoundOctet: () => isRoundOctet,
|
|
37
|
+
octetsToBits: () => octetsToBits,
|
|
38
|
+
toHex: () => toHex
|
|
39
|
+
});
|
|
40
|
+
module.exports = __toCommonJS(src_exports);
|
|
41
|
+
|
|
42
|
+
// src/assert.ts
|
|
43
|
+
var assertError = (value, assert, defaultMessage) => {
|
|
44
|
+
if (assert) {
|
|
45
|
+
const assertString = typeof assert === "string" ? assert : typeof assert === "boolean" ? defaultMessage : assert(value, defaultMessage);
|
|
46
|
+
if (assertString) {
|
|
47
|
+
throw Error(assertString === true ? defaultMessage : assertString);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return void 0;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// src/hex.ts
|
|
54
|
+
var hexRegex = /^[0-9a-f]+$/i;
|
|
55
|
+
var hexRegexWithPrefix = /0x[0-9a-f]+$/i;
|
|
56
|
+
var hexFrom = (buffer) => {
|
|
57
|
+
return [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, "0")).join("");
|
|
58
|
+
};
|
|
59
|
+
var bitsToOctets = (value) => {
|
|
60
|
+
const octets = value >> 2;
|
|
61
|
+
if (value !== octets << 2)
|
|
62
|
+
throw Error("Bits for octets must multiple of 8");
|
|
63
|
+
return octets;
|
|
64
|
+
};
|
|
65
|
+
var octetsToBits = (value) => {
|
|
66
|
+
return value << 2;
|
|
67
|
+
};
|
|
68
|
+
var isRoundOctet = (value) => {
|
|
69
|
+
return value >> 2 << 2 === value;
|
|
70
|
+
};
|
|
71
|
+
var isHex = (value, bitLength) => {
|
|
72
|
+
if (typeof value !== "string")
|
|
73
|
+
return false;
|
|
74
|
+
if (bitLength !== void 0 && value.length !== bitsToOctets(bitLength))
|
|
75
|
+
return false;
|
|
76
|
+
return hexRegex.test(value);
|
|
77
|
+
};
|
|
78
|
+
function asHex(value, assertOrBitLength, assertOnly) {
|
|
79
|
+
const bitLength = typeof assertOrBitLength === "number" ? assertOrBitLength : void 0;
|
|
80
|
+
const assert = typeof assertOrBitLength !== "number" ? assertOrBitLength : assertOnly;
|
|
81
|
+
let stringValue = void 0;
|
|
82
|
+
switch (typeof value) {
|
|
83
|
+
case "string":
|
|
84
|
+
stringValue = hexRegexWithPrefix.test(value) ? value.substring(2) : value;
|
|
85
|
+
break;
|
|
86
|
+
case "number":
|
|
87
|
+
if (value === Math.floor(value)) {
|
|
88
|
+
stringValue = value.toString(16);
|
|
89
|
+
} else {
|
|
90
|
+
return assertError(value, assert, "Numbers must be whole");
|
|
91
|
+
}
|
|
92
|
+
break;
|
|
93
|
+
case "bigint":
|
|
94
|
+
stringValue = value.toString(16);
|
|
95
|
+
break;
|
|
96
|
+
case "object":
|
|
97
|
+
if (value instanceof ArrayBuffer) {
|
|
98
|
+
stringValue = hexFrom(value);
|
|
99
|
+
}
|
|
100
|
+
break;
|
|
101
|
+
default:
|
|
102
|
+
return assertError(value, assert, `Unsupported type [${typeof value}]`);
|
|
103
|
+
}
|
|
104
|
+
if (stringValue && bitLength) {
|
|
105
|
+
stringValue = stringValue.padStart(bitsToOctets(bitLength), "0");
|
|
106
|
+
}
|
|
107
|
+
return isHex(stringValue, bitLength) ? stringValue.toLowerCase() : assertError(value, assert, "Unable to convert to Hash");
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// src/address.ts
|
|
111
|
+
var addressRegex = /0x[0-9a-f]+/i;
|
|
112
|
+
var isAddress = (value, bitLength = 160) => {
|
|
113
|
+
if (typeof value !== "string")
|
|
114
|
+
return false;
|
|
115
|
+
if (!addressRegex.test(value))
|
|
116
|
+
return false;
|
|
117
|
+
const valueHex = value.substring(2);
|
|
118
|
+
if (bitLength !== void 0 && valueHex.length !== bitsToOctets(bitLength))
|
|
119
|
+
return false;
|
|
120
|
+
return isHex(valueHex, bitLength);
|
|
121
|
+
};
|
|
122
|
+
function asAddress(value, assertOrBitLength, assertOnly) {
|
|
123
|
+
const bitLength = typeof assertOrBitLength === "number" ? assertOrBitLength : 160;
|
|
124
|
+
const assert = typeof assertOrBitLength !== "number" ? assertOrBitLength : assertOnly;
|
|
125
|
+
const result = `0x${asHex(value, bitLength, assert)}`;
|
|
126
|
+
return isAddress(result, bitLength) ? result : assertError(value, assert, "Resulting value is not an Address");
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// src/hash.ts
|
|
130
|
+
var HashBitLength = [32, 64, 128, 256, 512, 1024, 2048, 4096];
|
|
131
|
+
var isHashBitLength = (value) => {
|
|
132
|
+
return typeof value === "number" && HashBitLength.includes(value);
|
|
133
|
+
};
|
|
134
|
+
var isHash = (value, bitLength = 256) => {
|
|
135
|
+
if (!isHex(value, bitLength))
|
|
136
|
+
return false;
|
|
137
|
+
const hex = asHex(value, bitLength);
|
|
138
|
+
if (!hex)
|
|
139
|
+
return false;
|
|
140
|
+
if (!isHashBitLength(octetsToBits(hex.length)))
|
|
141
|
+
return false;
|
|
142
|
+
return true;
|
|
143
|
+
};
|
|
144
|
+
var toHex = (buffer) => {
|
|
145
|
+
return [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, "0")).join("");
|
|
146
|
+
};
|
|
147
|
+
function asHash(value, assertOrBitLength, assertOnly) {
|
|
148
|
+
const bitLength = typeof assertOrBitLength === "number" ? assertOrBitLength : 256;
|
|
149
|
+
const assert = typeof assertOrBitLength !== "number" ? assertOrBitLength : assertOnly;
|
|
150
|
+
const result = asHex(value, bitLength, assert);
|
|
151
|
+
return isHash(result, bitLength) ? result : assertError(value, assert, "Resulting value is not a Hash");
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/assert.ts","../../src/hex.ts","../../src/address.ts","../../src/hash.ts"],"sourcesContent":["export * from './address'\nexport * from './hash'\nexport * from './hex'\n","export type AssertCallback = (value: unknown, message: string) => string | boolean\n\nexport type AssertConfig = string | AssertCallback | boolean\n\nexport const assertError = (value: unknown, assert: AssertConfig | undefined, defaultMessage: string) => {\n if (assert) {\n const assertString = typeof assert === 'string' ? assert : typeof assert === 'boolean' ? defaultMessage : assert(value, defaultMessage)\n if (assertString) {\n throw Error(assertString === true ? defaultMessage : assertString)\n }\n }\n return undefined\n}\n","import { AssertConfig, assertError } from './assert'\n\nexport const hexRegex = /^[0-9a-f]+$/i\nexport const hexRegexWithPrefix = /0x[0-9a-f]+$/i\n\nexport type Hex = string\n\nexport const hexFrom = (buffer: ArrayBuffer) => {\n return [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, '0')).join('')\n}\n\n//determine the number of octets for a given number of bits\nexport const bitsToOctets = (value: number): number => {\n const octets = value >> 2\n if (value !== octets << 2) throw Error('Bits for octets must multiple of 8')\n return octets\n}\n\n//determine the number of octets for a given number of bits\nexport const octetsToBits = (value: number): number => {\n return value << 2\n}\n\n//are the number of bit a round octet (factor of 8)?\nexport const isRoundOctet = (value: number) => {\n return (value >> 2) << 2 === value\n}\n\nexport const isHex = (value: unknown, bitLength?: number): value is Hex => {\n //Is it a string?\n if (typeof value !== 'string') return false\n\n //If a bitLength specified, does it conform?\n if (bitLength !== undefined && value.length !== bitsToOctets(bitLength)) return false\n\n //Does it only has hex values?\n return hexRegex.test(value)\n}\n\nexport function asHex(value: unknown): Hex | undefined\nexport function asHex(value: unknown, bitLength?: number): Hex | undefined\nexport function asHex(value: unknown, assert: AssertConfig): Hex\nexport function asHex(value: unknown, bitLength: number | undefined, assert?: AssertConfig): Hex\nexport function asHex(value: unknown, assertOrBitLength?: AssertConfig | number, assertOnly?: AssertConfig): Hex | undefined {\n const bitLength = typeof assertOrBitLength === 'number' ? assertOrBitLength : undefined\n const assert = typeof assertOrBitLength !== 'number' ? assertOrBitLength : assertOnly\n\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string':\n //remove the leading 0x if it is there\n stringValue = hexRegexWithPrefix.test(value) ? value.substring(2) : value\n break\n case 'number':\n if (value === Math.floor(value)) {\n stringValue = value.toString(16)\n } else {\n return assertError(value, assert, 'Numbers must be whole')\n }\n break\n case 'bigint':\n stringValue = value.toString(16)\n break\n case 'object':\n if (value instanceof ArrayBuffer) {\n stringValue = hexFrom(value)\n }\n break\n default:\n return assertError(value, assert, `Unsupported type [${typeof value}]`)\n }\n\n //make it conform to the bit length if shorter\n if (stringValue && bitLength) {\n stringValue = stringValue.padStart(bitsToOctets(bitLength), '0')\n }\n\n return isHex(stringValue, bitLength) ? stringValue.toLowerCase() : assertError(value, assert, 'Unable to convert to Hash')\n}\n","import { AssertConfig, assertError } from './assert'\nimport { asHex, bitsToOctets, isHex } from './hex'\n\nexport const addressRegex = /0x[0-9a-f]+/i\n\nexport type Address = string\n\nexport const isAddress = (value: unknown, bitLength = 160): value is Address => {\n //Is it a string?\n if (typeof value !== 'string') return false\n\n //Does it only has hex values and leading 0x?\n if (!addressRegex.test(value)) return false\n\n const valueHex = value.substring(2)\n\n //If a bitLength specified, does it conform?\n if (bitLength !== undefined && valueHex.length !== bitsToOctets(bitLength)) return false\n\n return isHex(valueHex, bitLength)\n}\n\nexport function asAddress(value: unknown): Address | undefined\nexport function asAddress(value: unknown, assert: AssertConfig): Address\nexport function asAddress(value: unknown, bitLength: number): Address | undefined\nexport function asAddress(value: unknown, bitLength: number, assert: AssertConfig): Address\nexport function asAddress(value: unknown, assertOrBitLength?: AssertConfig | number, assertOnly?: AssertConfig): Address | undefined {\n const bitLength = typeof assertOrBitLength === 'number' ? assertOrBitLength : 160\n const assert = typeof assertOrBitLength !== 'number' ? assertOrBitLength : assertOnly\n\n const result = `0x${asHex(value, bitLength, assert)}`\n return isAddress(result, bitLength) ? result : assertError(value, assert, 'Resulting value is not an Address')\n}\n","import { AssertConfig, assertError } from './assert'\nimport { asHex, Hex, isHex, octetsToBits } from './hex'\n\nexport type HashBitLength = 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096\nexport const HashBitLength: HashBitLength[] = [32, 64, 128, 256, 512, 1024, 2048, 4096]\n\nexport const isHashBitLength = (value: unknown): value is HashBitLength => {\n return typeof value === 'number' && HashBitLength.includes(value as HashBitLength)\n}\n\nexport type Hash = Hex\nexport const isHash = (value: unknown, bitLength: HashBitLength = 256): value is Hash => {\n if (!isHex(value, bitLength)) return false\n\n const hex = asHex(value, bitLength)\n if (!hex) return false\n\n if (!isHashBitLength(octetsToBits(hex.length))) return false\n\n return true\n}\n\nexport const toHex = (buffer: ArrayBuffer) => {\n return [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, '0')).join('')\n}\n\nexport function asHash(value: unknown): Hash | undefined\nexport function asHash(value: unknown, assert: AssertConfig): Hash\nexport function asHash(value: unknown, bitLength?: HashBitLength): Hash | undefined\nexport function asHash(value: unknown, bitLength: HashBitLength | undefined, assert: AssertConfig): Hash\nexport function asHash(value: unknown, assertOrBitLength?: AssertConfig | HashBitLength, assertOnly?: AssertConfig): Hash | undefined {\n const bitLength: HashBitLength = typeof assertOrBitLength === 'number' ? assertOrBitLength : 256\n const assert = typeof assertOrBitLength !== 'number' ? assertOrBitLength : assertOnly\n\n const result = asHex(value, bitLength, assert)\n return isHash(result, bitLength) ? result : assertError(value, assert, 'Resulting value is not a Hash')\n}\n"],"mappings":"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","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,QAAQ,CAAA;AACtB,cAAc,OAAO,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,QAAQ,CAAA;AACtB,cAAc,OAAO,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,QAAQ,CAAA;AACtB,cAAc,OAAO,CAAA"}
|