@xylabs/hex 5.0.1 → 5.0.2
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/neutral/Brand.d.ts +3 -3
- package/dist/neutral/Brand.d.ts.map +1 -1
- package/dist/neutral/ethAddress.d.ts +1 -1
- package/dist/neutral/ethAddress.d.ts.map +1 -1
- package/dist/neutral/hash.d.ts +1 -1
- package/dist/neutral/hash.d.ts.map +1 -1
- package/dist/neutral/hex/model.d.ts +1 -1
- package/dist/neutral/hex/model.d.ts.map +1 -1
- package/dist/neutral/index-internal.d.ts +8 -0
- package/dist/neutral/index-internal.d.ts.map +1 -0
- package/dist/neutral/index-internal.mjs +330 -0
- package/dist/neutral/index-internal.mjs.map +1 -0
- package/dist/neutral/index.d.ts +1 -7
- package/dist/neutral/index.d.ts.map +1 -1
- package/dist/neutral/index.mjs.map +1 -1
- package/package.json +8 -3
- package/src/Brand.ts +4 -1
- package/src/ethAddress.ts +1 -1
- package/src/hash.ts +1 -1
- package/src/hex/model.ts +1 -1
- package/src/index-internal.ts +7 -0
- package/src/index.ts +1 -7
package/dist/neutral/Brand.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type { Brand as TypeOfBrand } from '@xylabs/typeof';
|
|
2
|
+
/** @deprecated use from @xylabs/typeof instead */
|
|
3
|
+
export type Brand<T, B> = TypeOfBrand<T, B>;
|
|
4
4
|
//# sourceMappingURL=Brand.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Brand.d.ts","sourceRoot":"","sources":["../../src/Brand.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"Brand.d.ts","sourceRoot":"","sources":["../../src/Brand.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,IAAI,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAE1D,kDAAkD;AAClD,MAAM,MAAM,KAAK,CAAC,CAAC,EAAE,CAAC,IAAI,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import type { Brand } from '@xylabs/typeof';
|
|
1
2
|
import z from 'zod';
|
|
2
3
|
import type { AssertConfig } from './assert.ts';
|
|
3
|
-
import type { Brand } from './Brand.ts';
|
|
4
4
|
import type { HexConfig } from './hex/index.ts';
|
|
5
5
|
export declare const EthAddressRegEx: RegExp;
|
|
6
6
|
export declare const EthAddressToStringSchema: z.ZodString;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ethAddress.d.ts","sourceRoot":"","sources":["../../src/ethAddress.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"ethAddress.d.ts","sourceRoot":"","sources":["../../src/ethAddress.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,CAAC,MAAM,KAAK,CAAA;AAEnB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAM/C,eAAO,MAAM,eAAe,QAA4C,CAAA;AAExE,eAAO,MAAM,wBAAwB,aAAoC,CAAA;AACzE,eAAO,MAAM,0BAA0B,4DAAoE,CAAA;AAG3G,MAAM,MAAM,UAAU,GAAG,KAAK,CAAC,MAAM,EAAE;IAAE,QAAQ,CAAC,aAAa,EAAE,IAAI,CAAA;CAAE,CAAC,CAAA;AAExE,eAAO,MAAM,gBAAgB,EAAmD,UAAU,CAAA;AAE1F,eAAO,MAAM,YAAY,GAAI,OAAO,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,eAAe,EAAE,SAAQ,SAAc,KAAG,UAKxG,CAAA;AAED,eAAO,MAAM,YAAY,GAAI,OAAO,OAAO,EAAE,SAAQ,SAAc,KAAG,KAAK,IAAI,UAG9E,CAAA;AAED,eAAO,MAAM,aAAa,aAIvB,CAAA;AAEH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,GAAG,SAAS,CAAA;AACpE,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,GAAG,UAAU,CAAA"}
|
package/dist/neutral/hash.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import type { Brand } from '@xylabs/typeof';
|
|
1
2
|
import z from 'zod';
|
|
2
3
|
import type { AssertConfig } from './assert.ts';
|
|
3
|
-
import type { Brand } from './Brand.ts';
|
|
4
4
|
import type { Hex } from './hex/index.ts';
|
|
5
5
|
export declare const HashRegEx: RegExp;
|
|
6
6
|
export declare const ZERO_HASH: Hash;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/hash.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/hash.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAE3C,OAAO,CAAC,MAAM,KAAK,CAAA;AAEnB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE/C,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAA;AAIzC,eAAO,MAAM,SAAS,QAAyB,CAAA;AAE/C,eAAO,MAAM,SAAS,EAAyE,IAAI,CAAA;AAEnG,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,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,aAEzD,CAAA;AAGD,MAAM,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,EAAE;IAAE,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAA;CAAE,CAAC,CAAA;AAExD,eAAO,MAAM,MAAM,GAAI,OAAO,OAAO,EAAE,YAAW,aAAmB,KAAG,KAAK,IAAI,IAEhF,CAAA;AAED,eAAO,MAAM,OAAO,aAKjB,CAAA;AAEH,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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../src/hex/model.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../src/hex/model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,CAAC,MAAM,KAAK,CAAA;AAKnB,MAAM,MAAM,GAAG,GAAG,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE;IAAE,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAA;CAAE,CAAC,CAAA;AAEpE,eAAO,MAAM,MAAM,qDAC2D,CAAA;AAE9E,oDAAoD;AACpD,MAAM,WAAW,SAAS;IACxB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB;AAED,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,MAAM,CAAC,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './address/index.ts';
|
|
2
|
+
export * from './assert.ts';
|
|
3
|
+
export * from './ethAddress.ts';
|
|
4
|
+
export * from './hash.ts';
|
|
5
|
+
export * from './hex/index.ts';
|
|
6
|
+
export * from './HexRegEx.ts';
|
|
7
|
+
export * from './hexToBigInt.ts';
|
|
8
|
+
//# sourceMappingURL=index-internal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-internal.d.ts","sourceRoot":"","sources":["../../src/index-internal.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,WAAW,CAAA;AACzB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA"}
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
// src/address/address.ts
|
|
2
|
+
import { isObject } from "@xylabs/typeof";
|
|
3
|
+
import z2 from "zod";
|
|
4
|
+
|
|
5
|
+
// src/assert.ts
|
|
6
|
+
import { isString, isUndefined } from "@xylabs/typeof";
|
|
7
|
+
var assertError = (value, assert, defaultMessage) => {
|
|
8
|
+
if (!isUndefined(assert)) {
|
|
9
|
+
const assertString = typeof assert === "string" ? assert : typeof assert === "boolean" ? defaultMessage : assert(value, defaultMessage);
|
|
10
|
+
if (isString(assertString) || assertString === true) {
|
|
11
|
+
throw new Error(assertString === true ? defaultMessage : assertString);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return void 0;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// src/hex/from/fromHexString.ts
|
|
18
|
+
import { isNumber } from "@xylabs/typeof";
|
|
19
|
+
|
|
20
|
+
// src/HexRegEx.ts
|
|
21
|
+
var HexRegExMinMax = (minBytes = 0, maxBytes = Number.MAX_SAFE_INTEGER / 2) => {
|
|
22
|
+
return new RegExp(`^[a-f0-9]{${minBytes * 2},${maxBytes * 2}}$`);
|
|
23
|
+
};
|
|
24
|
+
var HexRegExMinMaxMixedCaseWithPrefix = (minBytes = 0, maxBytes = Number.MAX_SAFE_INTEGER / 2) => {
|
|
25
|
+
return new RegExp(`^0x[a-fA-F0-9]{${minBytes * 2},${maxBytes * 2}}$`);
|
|
26
|
+
};
|
|
27
|
+
var HexRegEx = /^[0-9a-f]+$/;
|
|
28
|
+
var HexRegExWithPrefix = /^0x[0-9a-f]+$/;
|
|
29
|
+
|
|
30
|
+
// src/hex/nibble.ts
|
|
31
|
+
var bitsToNibbles = (value) => {
|
|
32
|
+
const nibbles = value >> 2;
|
|
33
|
+
if (value !== nibbles << 2) throw new Error("Bits for nibbles must multiple of 4");
|
|
34
|
+
return nibbles;
|
|
35
|
+
};
|
|
36
|
+
var nibblesToBits = (value) => {
|
|
37
|
+
return value << 2;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// src/hex/is.ts
|
|
41
|
+
var isHex = (value, config) => {
|
|
42
|
+
if (typeof value !== "string") return false;
|
|
43
|
+
const valueCharLength = config?.prefix ? value.length - 2 : value.length;
|
|
44
|
+
if (config?.bitLength !== void 0 && valueCharLength !== bitsToNibbles(config?.bitLength)) return false;
|
|
45
|
+
return config?.prefix ? HexRegExWithPrefix.test(value) : HexRegEx.test(value);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// src/hex/from/fromHexString.ts
|
|
49
|
+
var hexFromHexString = (value, config = {}) => {
|
|
50
|
+
const {
|
|
51
|
+
prefix = false,
|
|
52
|
+
byteSize = 8,
|
|
53
|
+
bitLength
|
|
54
|
+
} = config;
|
|
55
|
+
const nibbleBoundary = bitsToNibbles(byteSize);
|
|
56
|
+
const unEvened = (value.startsWith("0x") ? value.slice(2) : value).toLowerCase();
|
|
57
|
+
if (isHex(unEvened)) {
|
|
58
|
+
const evenCharacters = unEvened.padStart(unEvened.length + unEvened.length % nibbleBoundary, "0");
|
|
59
|
+
const padded = isNumber(bitLength) ? evenCharacters.padStart(bitLength / 4, "0") : evenCharacters;
|
|
60
|
+
return (prefix ? `0x${padded}` : padded).toLowerCase();
|
|
61
|
+
} else {
|
|
62
|
+
throw new Error("Received string is not a value hex");
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// src/hex/from/fromArrayBuffer.ts
|
|
67
|
+
var hexFromArrayBuffer = (buffer, config) => {
|
|
68
|
+
const unPadded = [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, "0")).join("");
|
|
69
|
+
return hexFromHexString(unPadded, config);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// src/hex/from/fromBigInt.ts
|
|
73
|
+
var hexFromBigInt = (value, config = {}) => {
|
|
74
|
+
const unPadded = value.toString(16);
|
|
75
|
+
return hexFromHexString(unPadded, config);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// src/hex/from/fromNumber.ts
|
|
79
|
+
var hexFromNumber = (value, config) => {
|
|
80
|
+
return hexFromBigInt(BigInt(value), config);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
// src/hex/from/from.ts
|
|
84
|
+
var hexFrom = (value, config) => {
|
|
85
|
+
switch (typeof value) {
|
|
86
|
+
case "string": {
|
|
87
|
+
return hexFromHexString(value, config);
|
|
88
|
+
}
|
|
89
|
+
case "bigint": {
|
|
90
|
+
return hexFromBigInt(value, config);
|
|
91
|
+
}
|
|
92
|
+
case "number": {
|
|
93
|
+
return hexFromNumber(value, config);
|
|
94
|
+
}
|
|
95
|
+
case "object": {
|
|
96
|
+
return hexFromArrayBuffer(value, config);
|
|
97
|
+
}
|
|
98
|
+
default: {
|
|
99
|
+
throw new Error(`Invalid type: ${typeof value}`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
// src/hex/as.ts
|
|
105
|
+
function asHex(value, assert) {
|
|
106
|
+
let stringValue = void 0;
|
|
107
|
+
switch (typeof value) {
|
|
108
|
+
case "string": {
|
|
109
|
+
stringValue = hexFromHexString(value);
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
default: {
|
|
113
|
+
return assertError(value, assert, `Unsupported type [${typeof value}]`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return isHex(stringValue) ? stringValue : assertError(value, assert, `Value is not Hex [${value}]`);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// src/hex/isHexZero.ts
|
|
120
|
+
import { isString as isString2 } from "@xylabs/typeof";
|
|
121
|
+
var isHexZero = (value) => {
|
|
122
|
+
return isString2(value) ? BigInt(hexFromHexString(value, { prefix: true })) === 0n : void 0;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
// src/hex/legacy.ts
|
|
126
|
+
var toHexLegacy = (buffer) => {
|
|
127
|
+
return [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, "0")).join("");
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
// src/hex/model.ts
|
|
131
|
+
import z from "zod";
|
|
132
|
+
var HexZod = z.string().regex(HexRegEx, { message: "Invalid hex format" }).transform((x) => x);
|
|
133
|
+
|
|
134
|
+
// src/hex/to.ts
|
|
135
|
+
var toHex = (value, config = {}) => {
|
|
136
|
+
const { prefix = false } = config;
|
|
137
|
+
return hexFrom(value, { prefix, ...config });
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
// src/address/address.ts
|
|
141
|
+
var AddressRegEx = HexRegExMinMax(20, 20);
|
|
142
|
+
var AddressToStringZod = z2.string().regex(AddressRegEx);
|
|
143
|
+
var AddressToStringSchema = AddressToStringZod;
|
|
144
|
+
var AddressFromStringZod = z2.string().toLowerCase().regex(AddressRegEx).transform((v) => toAddress(v));
|
|
145
|
+
var AddressFromStringSchema = AddressFromStringZod;
|
|
146
|
+
var ZERO_ADDRESS = "0000000000000000000000000000000000000000";
|
|
147
|
+
var ADDRESS_LENGTH = 40;
|
|
148
|
+
var toAddress = (value, config = {}) => {
|
|
149
|
+
const { bitLength = 160, prefix = false } = config;
|
|
150
|
+
return hexFrom(value, {
|
|
151
|
+
bitLength,
|
|
152
|
+
prefix,
|
|
153
|
+
...config
|
|
154
|
+
});
|
|
155
|
+
};
|
|
156
|
+
var isAddress = (value, config = {}) => {
|
|
157
|
+
const { bitLength = 160, prefix = false } = config;
|
|
158
|
+
return isHex(value, { bitLength, prefix });
|
|
159
|
+
};
|
|
160
|
+
function asAddress(value, assert) {
|
|
161
|
+
try {
|
|
162
|
+
let stringValue = void 0;
|
|
163
|
+
switch (typeof value) {
|
|
164
|
+
case "string": {
|
|
165
|
+
stringValue = hexFromHexString(value, { prefix: false });
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
default: {
|
|
169
|
+
return isObject(assert) ? assertError(value, assert, `Unsupported type [${typeof value}]`) : void 0;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return isAddress(stringValue) ? stringValue : assertError(value, assert, `Value is not an Address [${value}]`);
|
|
173
|
+
} catch (ex) {
|
|
174
|
+
const error = ex;
|
|
175
|
+
return assertError(void 0, assert, error.message);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// src/address/AddressZodTransform.ts
|
|
180
|
+
import z4 from "zod";
|
|
181
|
+
|
|
182
|
+
// src/address/AddressZodValidation.ts
|
|
183
|
+
import z3 from "zod";
|
|
184
|
+
var AddressZodValidation = z3.string().refine((x) => HexZod.safeParse(x)).refine((x) => x.length === ADDRESS_LENGTH, { error: (e) => new Error(`Address must have 40 characters [${e.input}]`) }).transform((v) => v);
|
|
185
|
+
|
|
186
|
+
// src/address/AddressZodTransform.ts
|
|
187
|
+
var AddressZodTransform = z4.union([z4.string(), z4.bigint()]).transform((value) => {
|
|
188
|
+
if (typeof value === "bigint") {
|
|
189
|
+
return value.toString(16).padStart(40, "0");
|
|
190
|
+
}
|
|
191
|
+
if (value.startsWith("0x")) {
|
|
192
|
+
return value.slice(2);
|
|
193
|
+
}
|
|
194
|
+
return value;
|
|
195
|
+
}).refine((x) => AddressZodValidation.safeParse(x).data).transform((x) => x);
|
|
196
|
+
|
|
197
|
+
// src/address/AddressNamespace.ts
|
|
198
|
+
var Address;
|
|
199
|
+
((Address2) => {
|
|
200
|
+
Address2.identify = (value) => AddressZodValidation.safeParse(value).success;
|
|
201
|
+
Address2.cast = (value, assert = false) => assert ? AddressZodValidation.parse(value) : AddressZodValidation.safeParse(value).data;
|
|
202
|
+
Address2.from = (value, assert = false) => assert ? AddressZodTransform.parse(value) : AddressZodTransform.safeParse(value).data;
|
|
203
|
+
Address2.toString = (value) => value;
|
|
204
|
+
})(Address || (Address = {}));
|
|
205
|
+
|
|
206
|
+
// src/ethAddress.ts
|
|
207
|
+
import z5 from "zod";
|
|
208
|
+
var EthAddressRegEx = HexRegExMinMaxMixedCaseWithPrefix(20, 20);
|
|
209
|
+
var EthAddressToStringSchema = z5.string().regex(EthAddressRegEx);
|
|
210
|
+
var EthAddressFromStringSchema = z5.string().regex(EthAddressRegEx).transform((v) => toEthAddress(v));
|
|
211
|
+
var ETH_ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
212
|
+
var toEthAddress = (value, config = {}) => {
|
|
213
|
+
const { bitLength = 160, prefix = false } = config;
|
|
214
|
+
return `0x${hexFrom(value, {
|
|
215
|
+
bitLength,
|
|
216
|
+
prefix,
|
|
217
|
+
...config
|
|
218
|
+
})}`;
|
|
219
|
+
};
|
|
220
|
+
var isEthAddress = (value, config = {}) => {
|
|
221
|
+
const { bitLength = 160, prefix = true } = config;
|
|
222
|
+
return isHex(value, { bitLength, prefix });
|
|
223
|
+
};
|
|
224
|
+
var EthAddressZod = z5.string().regex(EthAddressRegEx, { message: "Invalid address format" }).refine(
|
|
225
|
+
isEthAddress
|
|
226
|
+
);
|
|
227
|
+
function asEthAddress(value, assert) {
|
|
228
|
+
try {
|
|
229
|
+
let stringValue = void 0;
|
|
230
|
+
switch (typeof value) {
|
|
231
|
+
case "string": {
|
|
232
|
+
stringValue = hexFromHexString(value, { prefix: true });
|
|
233
|
+
break;
|
|
234
|
+
}
|
|
235
|
+
default: {
|
|
236
|
+
if (value !== void 0) {
|
|
237
|
+
return assertError(value, assert, `Unsupported type [${typeof value}]`);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return isEthAddress(stringValue) ? stringValue : assertError(value, assert, `Value is not an EthAddress [${value}]`);
|
|
242
|
+
} catch (ex) {
|
|
243
|
+
const error = ex;
|
|
244
|
+
return assertError(void 0, assert, error.message);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// src/hash.ts
|
|
249
|
+
import { isUndefined as isUndefined2 } from "@xylabs/typeof";
|
|
250
|
+
import z6 from "zod";
|
|
251
|
+
var HashRegEx = HexRegExMinMax(32, 32);
|
|
252
|
+
var ZERO_HASH = "0000000000000000000000000000000000000000000000000000000000000000";
|
|
253
|
+
var HashBitLength = [32, 64, 128, 256, 512, 1024, 2048, 4096];
|
|
254
|
+
var isHashBitLength = (value) => {
|
|
255
|
+
return typeof value === "number" && HashBitLength.includes(value);
|
|
256
|
+
};
|
|
257
|
+
var isHash = (value, bitLength = 256) => {
|
|
258
|
+
return isHex(value, { bitLength });
|
|
259
|
+
};
|
|
260
|
+
var HashZod = z6.string().toLowerCase().regex(HashRegEx, { message: "Invalid hash format" }).refine(
|
|
261
|
+
isHash
|
|
262
|
+
);
|
|
263
|
+
function asHash(value, assert) {
|
|
264
|
+
let stringValue = void 0;
|
|
265
|
+
switch (typeof value) {
|
|
266
|
+
case "string": {
|
|
267
|
+
stringValue = hexFromHexString(value);
|
|
268
|
+
break;
|
|
269
|
+
}
|
|
270
|
+
default: {
|
|
271
|
+
return isUndefined2(assert) ? void 0 : assertError(value, assert, `Unsupported type [${typeof value}]`);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
return isHash(stringValue) ? stringValue : assertError(value, assert, `Value is not a Hash [${value}]`);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// src/hexToBigInt.ts
|
|
278
|
+
function hexToBigInt(hex) {
|
|
279
|
+
return BigInt(hexFromHexString(hex, { prefix: true }));
|
|
280
|
+
}
|
|
281
|
+
export {
|
|
282
|
+
ADDRESS_LENGTH,
|
|
283
|
+
Address,
|
|
284
|
+
AddressFromStringSchema,
|
|
285
|
+
AddressFromStringZod,
|
|
286
|
+
AddressRegEx,
|
|
287
|
+
AddressToStringSchema,
|
|
288
|
+
AddressToStringZod,
|
|
289
|
+
AddressZodTransform,
|
|
290
|
+
AddressZodValidation,
|
|
291
|
+
ETH_ZERO_ADDRESS,
|
|
292
|
+
EthAddressFromStringSchema,
|
|
293
|
+
EthAddressRegEx,
|
|
294
|
+
EthAddressToStringSchema,
|
|
295
|
+
EthAddressZod,
|
|
296
|
+
HashBitLength,
|
|
297
|
+
HashRegEx,
|
|
298
|
+
HashZod,
|
|
299
|
+
HexRegEx,
|
|
300
|
+
HexRegExMinMax,
|
|
301
|
+
HexRegExMinMaxMixedCaseWithPrefix,
|
|
302
|
+
HexRegExWithPrefix,
|
|
303
|
+
HexZod,
|
|
304
|
+
ZERO_ADDRESS,
|
|
305
|
+
ZERO_HASH,
|
|
306
|
+
asAddress,
|
|
307
|
+
asEthAddress,
|
|
308
|
+
asHash,
|
|
309
|
+
asHex,
|
|
310
|
+
assertError,
|
|
311
|
+
bitsToNibbles,
|
|
312
|
+
hexFrom,
|
|
313
|
+
hexFromArrayBuffer,
|
|
314
|
+
hexFromBigInt,
|
|
315
|
+
hexFromHexString,
|
|
316
|
+
hexFromNumber,
|
|
317
|
+
hexToBigInt,
|
|
318
|
+
isAddress,
|
|
319
|
+
isEthAddress,
|
|
320
|
+
isHash,
|
|
321
|
+
isHashBitLength,
|
|
322
|
+
isHex,
|
|
323
|
+
isHexZero,
|
|
324
|
+
nibblesToBits,
|
|
325
|
+
toAddress,
|
|
326
|
+
toEthAddress,
|
|
327
|
+
toHex,
|
|
328
|
+
toHexLegacy
|
|
329
|
+
};
|
|
330
|
+
//# sourceMappingURL=index-internal.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/address/address.ts","../../src/assert.ts","../../src/hex/from/fromHexString.ts","../../src/HexRegEx.ts","../../src/hex/nibble.ts","../../src/hex/is.ts","../../src/hex/from/fromArrayBuffer.ts","../../src/hex/from/fromBigInt.ts","../../src/hex/from/fromNumber.ts","../../src/hex/from/from.ts","../../src/hex/as.ts","../../src/hex/isHexZero.ts","../../src/hex/legacy.ts","../../src/hex/model.ts","../../src/hex/to.ts","../../src/address/AddressZodTransform.ts","../../src/address/AddressZodValidation.ts","../../src/address/AddressNamespace.ts","../../src/ethAddress.ts","../../src/hash.ts","../../src/hexToBigInt.ts"],"sourcesContent":["import { isObject } from '@xylabs/typeof'\nimport z from 'zod'\n\nimport type { AssertConfig } from '../assert.ts'\nimport { assertError } from '../assert.ts'\nimport type { HexConfig } from '../hex/index.ts'\nimport {\n hexFrom, hexFromHexString, isHex,\n} from '../hex/index.ts'\nimport { HexRegExMinMax } from '../HexRegEx.ts'\nimport type { Address } from './AddressNamespace.ts'\n\nexport const AddressRegEx = HexRegExMinMax(20, 20)\n\nexport const AddressToStringZod = z.string().regex(AddressRegEx)\n\n/** @deprecated use AddressToStringZod */\nexport const AddressToStringSchema = AddressToStringZod\n\nexport const AddressFromStringZod = z.string().toLowerCase().regex(AddressRegEx).transform(v => toAddress(v))\n\n/** @deprecated use AddressFromStringZod */\nexport const AddressFromStringSchema = AddressFromStringZod\n\nexport const ZERO_ADDRESS = '0000000000000000000000000000000000000000' as Address\nexport const ADDRESS_LENGTH = 40 as const\n\nexport const toAddress = (value: string | number | bigint | ArrayBufferLike, config: HexConfig = {}): Address => {\n const { bitLength = 160, prefix = false } = config\n return hexFrom(value, {\n bitLength, prefix, ...config,\n }) as Address\n}\n\nexport const isAddress = (value: unknown, config: HexConfig = {}): value is Address => {\n const { bitLength = 160, prefix = false } = config\n return isHex(value, { bitLength, prefix })\n}\n\nexport function asAddress(value: unknown): Address | undefined\nexport function asAddress(value: unknown, assert: AssertConfig): Address\nexport function asAddress(value: unknown, assert?: AssertConfig): Address | undefined {\n try {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value, { prefix: false })\n break\n }\n default: {\n return isObject(assert) ? assertError(value, assert, `Unsupported type [${typeof value}]`) : undefined\n }\n }\n return isAddress(stringValue) ? stringValue : assertError(value, assert, `Value is not an Address [${value}]`)\n } catch (ex) {\n const error = ex as Error\n return assertError(undefined, assert, error.message)\n }\n}\n","import { isString, isUndefined } from '@xylabs/typeof'\n\ntype 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 (!isUndefined(assert)) {\n const assertString\n = typeof assert === 'string'\n ? assert\n : typeof assert === 'boolean'\n ? defaultMessage\n : assert(value, defaultMessage)\n if (isString(assertString) || assertString === true) {\n throw new Error(assertString === true ? defaultMessage : assertString)\n }\n }\n // eslint-disable-next-line unicorn/no-useless-undefined\n return undefined\n}\n","import { isNumber } from '@xylabs/typeof'\n\nimport { isHex } from '../is.ts'\nimport type { Hex, HexConfig } from '../model.ts'\nimport { bitsToNibbles } from '../nibble.ts'\n\nexport const hexFromHexString = (value: string, config: HexConfig = {}): Hex => {\n const {\n prefix = false, byteSize = 8, bitLength,\n } = config\n const nibbleBoundary = bitsToNibbles(byteSize)\n const unEvened = (value.startsWith('0x') ? value.slice(2) : value).toLowerCase()\n if (isHex(unEvened)) {\n const evenCharacters = unEvened.padStart(unEvened.length + (unEvened.length % nibbleBoundary), '0')\n const padded = isNumber(bitLength) ? evenCharacters.padStart(bitLength / 4, '0') : evenCharacters\n return (prefix ? `0x${padded}` : padded).toLowerCase() as Hex\n } else {\n throw new Error('Received string is not a value hex')\n }\n}\n","export const HexRegExMinMax = (minBytes = 0, maxBytes: number = (Number.MAX_SAFE_INTEGER / 2)) => {\n return new RegExp(`^[a-f0-9]{${minBytes * 2},${maxBytes * 2}}$`)\n}\n\nexport const HexRegExMinMaxMixedCaseWithPrefix = (minBytes = 0, maxBytes: number = (Number.MAX_SAFE_INTEGER / 2)) => {\n return new RegExp(`^0x[a-fA-F0-9]{${minBytes * 2},${maxBytes * 2}}$`)\n}\n\nexport const HexRegEx = /^[0-9a-f]+$/\nexport const HexRegExWithPrefix = /^0x[0-9a-f]+$/\n","// determine the number of nibbles for a given number of bits\nexport const bitsToNibbles = (value: number): number => {\n const nibbles = value >> 2\n if (value !== nibbles << 2) throw new Error('Bits for nibbles must multiple of 4')\n return nibbles\n}\n\n// determine the number of nibbles for a given number of bits\nexport const nibblesToBits = (value: number): number => {\n return value << 2\n}\n","import { HexRegEx, HexRegExWithPrefix } from '../HexRegEx.ts'\nimport type { Hex, HexConfig } from './model.ts'\nimport { bitsToNibbles } from './nibble.ts'\n\nexport const isHex = (value: unknown, config?: HexConfig): value is Hex => {\n // Is it a string?\n if (typeof value !== 'string') return false\n\n const valueCharLength = config?.prefix ? value.length - 2 : value.length\n\n // If a bitLength specified, does it conform?\n if (config?.bitLength !== undefined && valueCharLength !== bitsToNibbles(config?.bitLength)) return false\n\n // Does it only has hex values?\n return config?.prefix ? HexRegExWithPrefix.test(value) : HexRegEx.test(value)\n}\n","import type { Hex, HexConfig } from '../model.ts'\nimport { hexFromHexString } from './fromHexString.ts'\n\n/** Convert an ArrayBuffer to a hex string */\nexport const hexFromArrayBuffer = (\n /** The buffer to be converted */\n buffer: ArrayBufferLike,\n /** Configuration of output format and validation */\n config?: HexConfig,\n): Hex => {\n const unPadded = [...new Uint8Array(buffer)].map(x => x.toString(16).padStart(2, '0')).join('')\n return hexFromHexString(unPadded, config)\n}\n","import type { Hex, HexConfig } from '../model.ts'\nimport { hexFromHexString } from './fromHexString.ts'\n\n/** Convert a bigint to a hex string */\nexport const hexFromBigInt = (\n /** The bigint to be converted */\n value: bigint,\n /** Configuration of output format and validation */\n config: HexConfig = {},\n): Hex => {\n const unPadded = value.toString(16)\n return hexFromHexString(unPadded, config)\n}\n","import type { Hex, HexConfig } from '../model.ts'\nimport { hexFromBigInt } from './fromBigInt.ts'\n\nexport const hexFromNumber = (value: number, config?: HexConfig): Hex => {\n return hexFromBigInt(BigInt(value), config)\n}\n","import type { Hex, HexConfig } from '../model.ts'\nimport { hexFromArrayBuffer } from './fromArrayBuffer.ts'\nimport { hexFromBigInt } from './fromBigInt.ts'\nimport { hexFromHexString } from './fromHexString.ts'\nimport { hexFromNumber } from './fromNumber.ts'\n\n/** Takes unknown value and tries our best to convert it to a hex string */\nexport const hexFrom = (\n /** Supported types are string, number, bigint, and ArrayBuffer */\n value: string | number | bigint | ArrayBufferLike,\n /** Configuration of output format and validation */\n config?: HexConfig,\n): Hex => {\n switch (typeof value) {\n case 'string': {\n return hexFromHexString(value, config)\n }\n case 'bigint': {\n return hexFromBigInt(value, config)\n }\n case 'number': {\n return hexFromNumber(value, config)\n }\n case 'object': {\n return hexFromArrayBuffer(value, config)\n }\n default: {\n throw new Error(`Invalid type: ${typeof value}`)\n }\n }\n}\n","import type { AssertConfig } from '../assert.ts'\nimport { assertError } from '../assert.ts'\nimport { hexFromHexString } from './from/index.ts'\nimport { isHex } from './is.ts'\nimport type { Hex } from './model.ts'\n\nexport function asHex(value: unknown): Hex | undefined\nexport function asHex(value: unknown, assert: AssertConfig): Hex\nexport function asHex(value: unknown, assert?: AssertConfig): Hex | undefined {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value)\n break\n }\n default: {\n return assertError(value, assert, `Unsupported type [${typeof value}]`)\n }\n }\n\n return isHex(stringValue) ? stringValue : assertError(value, assert, `Value is not Hex [${value}]`)\n}\n","import { isString } from '@xylabs/typeof'\n\nimport { hexFromHexString } from './from/index.ts'\n\nexport const isHexZero = (value?: string) => {\n return isString(value) ? BigInt(hexFromHexString(value, { prefix: true })) === 0n : undefined\n}\n","export const toHexLegacy = (buffer: ArrayBuffer) => {\n return [...new Uint8Array(buffer)].map(x => x.toString(16).padStart(2, '0')).join('')\n}\n","import type { Brand } from '@xylabs/typeof'\nimport z from 'zod'\n\nimport { HexRegEx } from '../HexRegEx.ts'\n\n// using true instead of unique symbol to avoid conflicts with other versions of library\nexport type Hex = Brand<Lowercase<string>, { readonly __hex: true }>\n\nexport const HexZod = z.string()\n .regex(HexRegEx, { message: 'Invalid hex format' }).transform(x => x as Hex)\n\n/** Configuration of validation and output format */\nexport interface HexConfig {\n bitLength?: number\n byteSize?: number\n prefix?: boolean\n}\n\nexport type HexZodType = z.infer<typeof HexZod>\n","import { hexFrom } from './from/index.ts'\nimport type { HexConfig } from './model.ts'\n\n/** takes any value and tries our best to convert it to a hex string */\nexport const toHex = (\n /** Supported types are string, number, bigint, and ArrayBuffer */\n value: string | number | bigint | ArrayBufferLike,\n /** Configuration of output format and validation */\n config: HexConfig = {},\n) => {\n const { prefix = false } = config\n return hexFrom(value, { prefix, ...config })\n}\n","import z from 'zod'\n\nimport type { Address } from './AddressNamespace.ts'\nimport { AddressZodValidation } from './AddressZodValidation.ts'\n\nexport const AddressZodTransform = z.union([z.string(), z.bigint()])\n .transform((value) => {\n if (typeof value === 'bigint') {\n return value.toString(16).padStart(40, '0')\n }\n if (value.startsWith('0x')) {\n return value.slice(2)\n }\n return value\n })\n .refine(x => AddressZodValidation.safeParse(x).data)\n .transform(x => x as Address)\n\nexport type AddressZodTransformType = z.infer<typeof AddressZodTransform>\n","import z from 'zod'\n\nimport { HexZod } from '../hex/index.ts'\nimport { ADDRESS_LENGTH } from './address.ts'\nimport type { Address } from './AddressNamespace.ts'\n\nexport const AddressZodValidation = z.string()\n .refine(x => HexZod.safeParse(x))\n .refine(x => x.length === ADDRESS_LENGTH, { error: e => new Error(`Address must have 40 characters [${e.input}]`) })\n .transform(v => v as Address)\n\nexport type AddressZodValidationType = z.infer<typeof AddressZodValidation>\n","import type { Hex } from '../hex/index.ts'\nimport { AddressZodTransform } from './AddressZodTransform.ts'\nimport { AddressZodValidation } from './AddressZodValidation.ts'\n\n// using true instead of unique symbol to avoid conflicts with other versions of library\nexport type Address = Hex & { readonly __address: true }\n\n// eslint-disable-next-line @typescript-eslint/no-namespace\nexport namespace Address {\n export const identify = (value: unknown): value is Address => AddressZodValidation.safeParse(value).success\n export const cast = (value: unknown, assert: boolean = false): Address | undefined => assert\n ? AddressZodValidation.parse(value)\n : AddressZodValidation.safeParse(value).data\n export const from = (value: unknown, assert: boolean = false): Address | undefined => assert\n ? AddressZodTransform.parse(value)\n : AddressZodTransform.safeParse(value).data\n export const toString = (value: Address): string => value as string\n}\n","import type { Brand } from '@xylabs/typeof'\nimport z from 'zod'\n\nimport type { AssertConfig } from './assert.ts'\nimport { assertError } from './assert.ts'\nimport type { HexConfig } from './hex/index.ts'\nimport {\n hexFrom, hexFromHexString, isHex,\n} from './hex/index.ts'\nimport { HexRegExMinMaxMixedCaseWithPrefix } from './HexRegEx.ts'\n\nexport const EthAddressRegEx = HexRegExMinMaxMixedCaseWithPrefix(20, 20)\n\nexport const EthAddressToStringSchema = z.string().regex(EthAddressRegEx)\nexport const EthAddressFromStringSchema = z.string().regex(EthAddressRegEx).transform(v => toEthAddress(v))\n\n// using true instead of unique symbol to avoid conflicts with other versions of library\nexport type EthAddress = Brand<string, { readonly __eth_address: true }>\n\nexport const ETH_ZERO_ADDRESS = '0x0000000000000000000000000000000000000000' as EthAddress\n\nexport const toEthAddress = (value: string | number | bigint | ArrayBufferLike, config: HexConfig = {}): EthAddress => {\n const { bitLength = 160, prefix = false } = config\n return `0x${hexFrom(value, {\n bitLength, prefix, ...config,\n })}` as EthAddress\n}\n\nexport const isEthAddress = (value: unknown, config: HexConfig = {}): value is EthAddress => {\n const { bitLength = 160, prefix = true } = config\n return isHex(value, { bitLength, prefix })\n}\n\nexport const EthAddressZod = z.string()\n .regex(EthAddressRegEx, { message: 'Invalid address format' })\n .refine(\n isEthAddress,\n )\n\nexport function asEthAddress(value: unknown): EthAddress | undefined\nexport function asEthAddress(value: unknown, assert: AssertConfig): EthAddress\nexport function asEthAddress(value: unknown, assert?: AssertConfig): EthAddress | undefined {\n try {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value, { prefix: true })\n break\n }\n default: {\n if (value !== undefined) {\n return assertError(value, assert, `Unsupported type [${typeof value}]`)\n }\n }\n }\n return isEthAddress(stringValue) ? stringValue : assertError(value, assert, `Value is not an EthAddress [${value}]`)\n } catch (ex) {\n const error = ex as Error\n return assertError(undefined, assert, error.message)\n }\n}\n","import type { Brand } from '@xylabs/typeof'\nimport { isUndefined } from '@xylabs/typeof'\nimport z from 'zod'\n\nimport type { AssertConfig } from './assert.ts'\nimport { assertError } from './assert.ts'\nimport type { Hex } from './hex/index.ts'\nimport { hexFromHexString, isHex } from './hex/index.ts'\nimport { HexRegExMinMax } from './HexRegEx.ts'\n\nexport const HashRegEx = HexRegExMinMax(32, 32)\n\nexport const ZERO_HASH = '0000000000000000000000000000000000000000000000000000000000000000' as Hash\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\n// using true instead of unique symbol to avoid conflicts with other versions of library\nexport type Hash = Brand<Hex, { readonly __hash: true }>\n\nexport const isHash = (value: unknown, bitLength: HashBitLength = 256): value is Hash => {\n return isHex(value, { bitLength })\n}\n\nexport const HashZod = z.string()\n .toLowerCase()\n .regex(HashRegEx, { message: 'Invalid hash format' })\n .refine(\n isHash,\n )\n\nexport function asHash(value: unknown): Hash | undefined\nexport function asHash(value: unknown, assert: AssertConfig): Hash\nexport function asHash(value: unknown, assert?: AssertConfig): Hash | undefined {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value)\n break\n }\n default: {\n return isUndefined(assert) ? undefined : assertError(value, assert, `Unsupported type [${typeof value}]`)\n }\n }\n return isHash(stringValue) ? stringValue : assertError(value, assert, `Value is not a Hash [${value}]`)\n}\n","import { type Hex, hexFromHexString } from './hex/index.ts'\n\nexport function hexToBigInt(hex: Hex): bigint {\n return BigInt(hexFromHexString(hex, { prefix: true }))\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AACzB,OAAOA,QAAO;;;ACDd,SAAS,UAAU,mBAAmB;AAM/B,IAAM,cAAc,CAAC,OAAgB,QAAkC,mBAA2B;AACvG,MAAI,CAAC,YAAY,MAAM,GAAG;AACxB,UAAM,eACF,OAAO,WAAW,WAChB,SACA,OAAO,WAAW,YAChB,iBACA,OAAO,OAAO,cAAc;AACpC,QAAI,SAAS,YAAY,KAAK,iBAAiB,MAAM;AACnD,YAAM,IAAI,MAAM,iBAAiB,OAAO,iBAAiB,YAAY;AAAA,IACvE;AAAA,EACF;AAEA,SAAO;AACT;;;ACpBA,SAAS,gBAAgB;;;ACAlB,IAAM,iBAAiB,CAAC,WAAW,GAAG,WAAoB,OAAO,mBAAmB,MAAO;AAChG,SAAO,IAAI,OAAO,aAAa,WAAW,CAAC,IAAI,WAAW,CAAC,IAAI;AACjE;AAEO,IAAM,oCAAoC,CAAC,WAAW,GAAG,WAAoB,OAAO,mBAAmB,MAAO;AACnH,SAAO,IAAI,OAAO,kBAAkB,WAAW,CAAC,IAAI,WAAW,CAAC,IAAI;AACtE;AAEO,IAAM,WAAW;AACjB,IAAM,qBAAqB;;;ACR3B,IAAM,gBAAgB,CAAC,UAA0B;AACtD,QAAM,UAAU,SAAS;AACzB,MAAI,UAAU,WAAW,EAAG,OAAM,IAAI,MAAM,qCAAqC;AACjF,SAAO;AACT;AAGO,IAAM,gBAAgB,CAAC,UAA0B;AACtD,SAAO,SAAS;AAClB;;;ACNO,IAAM,QAAQ,CAAC,OAAgB,WAAqC;AAEzE,MAAI,OAAO,UAAU,SAAU,QAAO;AAEtC,QAAM,kBAAkB,QAAQ,SAAS,MAAM,SAAS,IAAI,MAAM;AAGlE,MAAI,QAAQ,cAAc,UAAa,oBAAoB,cAAc,Q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Y,EACZ,MAAM,WAAW,EAAE,SAAS,sBAAsB,CAAC,EACnD;AAAA,EACC;AACF;AAIK,SAAS,OAAO,OAAgB,QAAyC;AAC9E,MAAI,cAAkC;AAEtC,UAAQ,OAAO,OAAO;AAAA,IACpB,KAAK,UAAU;AACb,oBAAc,iBAAiB,KAAK;AACpC;AAAA,IACF;AAAA,IACA,SAAS;AACP,aAAOC,aAAY,MAAM,IAAI,SAAY,YAAY,OAAO,QAAQ,qBAAqB,OAAO,KAAK,GAAG;AAAA,IAC1G;AAAA,EACF;AACA,SAAO,OAAO,WAAW,IAAI,cAAc,YAAY,OAAO,QAAQ,wBAAwB,KAAK,GAAG;AACxG;;;AChDO,SAAS,YAAY,KAAkB;AAC5C,SAAO,OAAO,iBAAiB,KAAK,EAAE,QAAQ,KAAK,CAAC,CAAC;AACvD;","names":["z","isString","isString","z","z","z","z","z","Address","z","z","isUndefined","z","z","isUndefined"]}
|
package/dist/neutral/index.d.ts
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
export * from './address/index.ts';
|
|
2
|
-
export * from './assert.ts';
|
|
3
1
|
export * from './Brand.ts';
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './hash.ts';
|
|
6
|
-
export * from './hex/index.ts';
|
|
7
|
-
export * from './HexRegEx.ts';
|
|
8
|
-
export * from './hexToBigInt.ts';
|
|
2
|
+
export * from './index-internal.ts';
|
|
9
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,qBAAqB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/address/address.ts","../../src/assert.ts","../../src/hex/from/fromHexString.ts","../../src/HexRegEx.ts","../../src/hex/nibble.ts","../../src/hex/is.ts","../../src/hex/from/fromArrayBuffer.ts","../../src/hex/from/fromBigInt.ts","../../src/hex/from/fromNumber.ts","../../src/hex/from/from.ts","../../src/hex/as.ts","../../src/hex/isHexZero.ts","../../src/hex/legacy.ts","../../src/hex/model.ts","../../src/hex/to.ts","../../src/address/AddressZodTransform.ts","../../src/address/AddressZodValidation.ts","../../src/address/AddressNamespace.ts","../../src/ethAddress.ts","../../src/hash.ts","../../src/hexToBigInt.ts"],"sourcesContent":["import { isObject } from '@xylabs/typeof'\nimport z from 'zod'\n\nimport type { AssertConfig } from '../assert.ts'\nimport { assertError } from '../assert.ts'\nimport type { HexConfig } from '../hex/index.ts'\nimport {\n hexFrom, hexFromHexString, isHex,\n} from '../hex/index.ts'\nimport { HexRegExMinMax } from '../HexRegEx.ts'\nimport type { Address } from './AddressNamespace.ts'\n\nexport const AddressRegEx = HexRegExMinMax(20, 20)\n\nexport const AddressToStringZod = z.string().regex(AddressRegEx)\n\n/** @deprecated use AddressToStringZod */\nexport const AddressToStringSchema = AddressToStringZod\n\nexport const AddressFromStringZod = z.string().toLowerCase().regex(AddressRegEx).transform(v => toAddress(v))\n\n/** @deprecated use AddressFromStringZod */\nexport const AddressFromStringSchema = AddressFromStringZod\n\nexport const ZERO_ADDRESS = '0000000000000000000000000000000000000000' as Address\nexport const ADDRESS_LENGTH = 40 as const\n\nexport const toAddress = (value: string | number | bigint | ArrayBufferLike, config: HexConfig = {}): Address => {\n const { bitLength = 160, prefix = false } = config\n return hexFrom(value, {\n bitLength, prefix, ...config,\n }) as Address\n}\n\nexport const isAddress = (value: unknown, config: HexConfig = {}): value is Address => {\n const { bitLength = 160, prefix = false } = config\n return isHex(value, { bitLength, prefix })\n}\n\nexport function asAddress(value: unknown): Address | undefined\nexport function asAddress(value: unknown, assert: AssertConfig): Address\nexport function asAddress(value: unknown, assert?: AssertConfig): Address | undefined {\n try {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value, { prefix: false })\n break\n }\n default: {\n return isObject(assert) ? assertError(value, assert, `Unsupported type [${typeof value}]`) : undefined\n }\n }\n return isAddress(stringValue) ? stringValue : assertError(value, assert, `Value is not an Address [${value}]`)\n } catch (ex) {\n const error = ex as Error\n return assertError(undefined, assert, error.message)\n }\n}\n","import { isString, isUndefined } from '@xylabs/typeof'\n\ntype 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 (!isUndefined(assert)) {\n const assertString\n = typeof assert === 'string'\n ? assert\n : typeof assert === 'boolean'\n ? defaultMessage\n : assert(value, defaultMessage)\n if (isString(assertString) || assertString === true) {\n throw new Error(assertString === true ? defaultMessage : assertString)\n }\n }\n // eslint-disable-next-line unicorn/no-useless-undefined\n return undefined\n}\n","import { isNumber } from '@xylabs/typeof'\n\nimport { isHex } from '../is.ts'\nimport type { Hex, HexConfig } from '../model.ts'\nimport { bitsToNibbles } from '../nibble.ts'\n\nexport const hexFromHexString = (value: string, config: HexConfig = {}): Hex => {\n const {\n prefix = false, byteSize = 8, bitLength,\n } = config\n const nibbleBoundary = bitsToNibbles(byteSize)\n const unEvened = (value.startsWith('0x') ? value.slice(2) : value).toLowerCase()\n if (isHex(unEvened)) {\n const evenCharacters = unEvened.padStart(unEvened.length + (unEvened.length % nibbleBoundary), '0')\n const padded = isNumber(bitLength) ? evenCharacters.padStart(bitLength / 4, '0') : evenCharacters\n return (prefix ? `0x${padded}` : padded).toLowerCase() as Hex\n } else {\n throw new Error('Received string is not a value hex')\n }\n}\n","export const HexRegExMinMax = (minBytes = 0, maxBytes: number = (Number.MAX_SAFE_INTEGER / 2)) => {\n return new RegExp(`^[a-f0-9]{${minBytes * 2},${maxBytes * 2}}$`)\n}\n\nexport const HexRegExMinMaxMixedCaseWithPrefix = (minBytes = 0, maxBytes: number = (Number.MAX_SAFE_INTEGER / 2)) => {\n return new RegExp(`^0x[a-fA-F0-9]{${minBytes * 2},${maxBytes * 2}}$`)\n}\n\nexport const HexRegEx = /^[0-9a-f]+$/\nexport const HexRegExWithPrefix = /^0x[0-9a-f]+$/\n","// determine the number of nibbles for a given number of bits\nexport const bitsToNibbles = (value: number): number => {\n const nibbles = value >> 2\n if (value !== nibbles << 2) throw new Error('Bits for nibbles must multiple of 4')\n return nibbles\n}\n\n// determine the number of nibbles for a given number of bits\nexport const nibblesToBits = (value: number): number => {\n return value << 2\n}\n","import { HexRegEx, HexRegExWithPrefix } from '../HexRegEx.ts'\nimport type { Hex, HexConfig } from './model.ts'\nimport { bitsToNibbles } from './nibble.ts'\n\nexport const isHex = (value: unknown, config?: HexConfig): value is Hex => {\n // Is it a string?\n if (typeof value !== 'string') return false\n\n const valueCharLength = config?.prefix ? value.length - 2 : value.length\n\n // If a bitLength specified, does it conform?\n if (config?.bitLength !== undefined && valueCharLength !== bitsToNibbles(config?.bitLength)) return false\n\n // Does it only has hex values?\n return config?.prefix ? HexRegExWithPrefix.test(value) : HexRegEx.test(value)\n}\n","import type { Hex, HexConfig } from '../model.ts'\nimport { hexFromHexString } from './fromHexString.ts'\n\n/** Convert an ArrayBuffer to a hex string */\nexport const hexFromArrayBuffer = (\n /** The buffer to be converted */\n buffer: ArrayBufferLike,\n /** Configuration of output format and validation */\n config?: HexConfig,\n): Hex => {\n const unPadded = [...new Uint8Array(buffer)].map(x => x.toString(16).padStart(2, '0')).join('')\n return hexFromHexString(unPadded, config)\n}\n","import type { Hex, HexConfig } from '../model.ts'\nimport { hexFromHexString } from './fromHexString.ts'\n\n/** Convert a bigint to a hex string */\nexport const hexFromBigInt = (\n /** The bigint to be converted */\n value: bigint,\n /** Configuration of output format and validation */\n config: HexConfig = {},\n): Hex => {\n const unPadded = value.toString(16)\n return hexFromHexString(unPadded, config)\n}\n","import type { Hex, HexConfig } from '../model.ts'\nimport { hexFromBigInt } from './fromBigInt.ts'\n\nexport const hexFromNumber = (value: number, config?: HexConfig): Hex => {\n return hexFromBigInt(BigInt(value), config)\n}\n","import type { Hex, HexConfig } from '../model.ts'\nimport { hexFromArrayBuffer } from './fromArrayBuffer.ts'\nimport { hexFromBigInt } from './fromBigInt.ts'\nimport { hexFromHexString } from './fromHexString.ts'\nimport { hexFromNumber } from './fromNumber.ts'\n\n/** Takes unknown value and tries our best to convert it to a hex string */\nexport const hexFrom = (\n /** Supported types are string, number, bigint, and ArrayBuffer */\n value: string | number | bigint | ArrayBufferLike,\n /** Configuration of output format and validation */\n config?: HexConfig,\n): Hex => {\n switch (typeof value) {\n case 'string': {\n return hexFromHexString(value, config)\n }\n case 'bigint': {\n return hexFromBigInt(value, config)\n }\n case 'number': {\n return hexFromNumber(value, config)\n }\n case 'object': {\n return hexFromArrayBuffer(value, config)\n }\n default: {\n throw new Error(`Invalid type: ${typeof value}`)\n }\n }\n}\n","import type { AssertConfig } from '../assert.ts'\nimport { assertError } from '../assert.ts'\nimport { hexFromHexString } from './from/index.ts'\nimport { isHex } from './is.ts'\nimport type { Hex } from './model.ts'\n\nexport function asHex(value: unknown): Hex | undefined\nexport function asHex(value: unknown, assert: AssertConfig): Hex\nexport function asHex(value: unknown, assert?: AssertConfig): Hex | undefined {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value)\n break\n }\n default: {\n return assertError(value, assert, `Unsupported type [${typeof value}]`)\n }\n }\n\n return isHex(stringValue) ? stringValue : assertError(value, assert, `Value is not Hex [${value}]`)\n}\n","import { isString } from '@xylabs/typeof'\n\nimport { hexFromHexString } from './from/index.ts'\n\nexport const isHexZero = (value?: string) => {\n return isString(value) ? BigInt(hexFromHexString(value, { prefix: true })) === 0n : undefined\n}\n","export const toHexLegacy = (buffer: ArrayBuffer) => {\n return [...new Uint8Array(buffer)].map(x => x.toString(16).padStart(2, '0')).join('')\n}\n","import z from 'zod'\n\nimport type { Brand } from '../Brand.ts'\nimport { HexRegEx } from '../HexRegEx.ts'\n\n// using true instead of unique symbol to avoid conflicts with other versions of library\nexport type Hex = Brand<Lowercase<string>, { readonly __hex: true }>\n\nexport const HexZod = z.string()\n .regex(HexRegEx, { message: 'Invalid hex format' }).transform(x => x as Hex)\n\n/** Configuration of validation and output format */\nexport interface HexConfig {\n bitLength?: number\n byteSize?: number\n prefix?: boolean\n}\n\nexport type HexZodType = z.infer<typeof HexZod>\n","import { hexFrom } from './from/index.ts'\nimport type { HexConfig } from './model.ts'\n\n/** takes any value and tries our best to convert it to a hex string */\nexport const toHex = (\n /** Supported types are string, number, bigint, and ArrayBuffer */\n value: string | number | bigint | ArrayBufferLike,\n /** Configuration of output format and validation */\n config: HexConfig = {},\n) => {\n const { prefix = false } = config\n return hexFrom(value, { prefix, ...config })\n}\n","import z from 'zod'\n\nimport type { Address } from './AddressNamespace.ts'\nimport { AddressZodValidation } from './AddressZodValidation.ts'\n\nexport const AddressZodTransform = z.union([z.string(), z.bigint()])\n .transform((value) => {\n if (typeof value === 'bigint') {\n return value.toString(16).padStart(40, '0')\n }\n if (value.startsWith('0x')) {\n return value.slice(2)\n }\n return value\n })\n .refine(x => AddressZodValidation.safeParse(x).data)\n .transform(x => x as Address)\n\nexport type AddressZodTransformType = z.infer<typeof AddressZodTransform>\n","import z from 'zod'\n\nimport { HexZod } from '../hex/index.ts'\nimport { ADDRESS_LENGTH } from './address.ts'\nimport type { Address } from './AddressNamespace.ts'\n\nexport const AddressZodValidation = z.string()\n .refine(x => HexZod.safeParse(x))\n .refine(x => x.length === ADDRESS_LENGTH, { error: e => new Error(`Address must have 40 characters [${e.input}]`) })\n .transform(v => v as Address)\n\nexport type AddressZodValidationType = z.infer<typeof AddressZodValidation>\n","import type { Hex } from '../hex/index.ts'\nimport { AddressZodTransform } from './AddressZodTransform.ts'\nimport { AddressZodValidation } from './AddressZodValidation.ts'\n\n// using true instead of unique symbol to avoid conflicts with other versions of library\nexport type Address = Hex & { readonly __address: true }\n\n// eslint-disable-next-line @typescript-eslint/no-namespace\nexport namespace Address {\n export const identify = (value: unknown): value is Address => AddressZodValidation.safeParse(value).success\n export const cast = (value: unknown, assert: boolean = false): Address | undefined => assert\n ? AddressZodValidation.parse(value)\n : AddressZodValidation.safeParse(value).data\n export const from = (value: unknown, assert: boolean = false): Address | undefined => assert\n ? AddressZodTransform.parse(value)\n : AddressZodTransform.safeParse(value).data\n export const toString = (value: Address): string => value as string\n}\n","import z from 'zod'\n\nimport type { AssertConfig } from './assert.ts'\nimport { assertError } from './assert.ts'\nimport type { Brand } from './Brand.ts'\nimport type { HexConfig } from './hex/index.ts'\nimport {\n hexFrom, hexFromHexString, isHex,\n} from './hex/index.ts'\nimport { HexRegExMinMaxMixedCaseWithPrefix } from './HexRegEx.ts'\n\nexport const EthAddressRegEx = HexRegExMinMaxMixedCaseWithPrefix(20, 20)\n\nexport const EthAddressToStringSchema = z.string().regex(EthAddressRegEx)\nexport const EthAddressFromStringSchema = z.string().regex(EthAddressRegEx).transform(v => toEthAddress(v))\n\n// using true instead of unique symbol to avoid conflicts with other versions of library\nexport type EthAddress = Brand<string, { readonly __eth_address: true }>\n\nexport const ETH_ZERO_ADDRESS = '0x0000000000000000000000000000000000000000' as EthAddress\n\nexport const toEthAddress = (value: string | number | bigint | ArrayBufferLike, config: HexConfig = {}): EthAddress => {\n const { bitLength = 160, prefix = false } = config\n return `0x${hexFrom(value, {\n bitLength, prefix, ...config,\n })}` as EthAddress\n}\n\nexport const isEthAddress = (value: unknown, config: HexConfig = {}): value is EthAddress => {\n const { bitLength = 160, prefix = true } = config\n return isHex(value, { bitLength, prefix })\n}\n\nexport const EthAddressZod = z.string()\n .regex(EthAddressRegEx, { message: 'Invalid address format' })\n .refine(\n isEthAddress,\n )\n\nexport function asEthAddress(value: unknown): EthAddress | undefined\nexport function asEthAddress(value: unknown, assert: AssertConfig): EthAddress\nexport function asEthAddress(value: unknown, assert?: AssertConfig): EthAddress | undefined {\n try {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value, { prefix: true })\n break\n }\n default: {\n if (value !== undefined) {\n return assertError(value, assert, `Unsupported type [${typeof value}]`)\n }\n }\n }\n return isEthAddress(stringValue) ? stringValue : assertError(value, assert, `Value is not an EthAddress [${value}]`)\n } catch (ex) {\n const error = ex as Error\n return assertError(undefined, assert, error.message)\n }\n}\n","import { isUndefined } from '@xylabs/typeof'\nimport z from 'zod'\n\nimport type { AssertConfig } from './assert.ts'\nimport { assertError } from './assert.ts'\nimport type { Brand } from './Brand.ts'\nimport type { Hex } from './hex/index.ts'\nimport { hexFromHexString, isHex } from './hex/index.ts'\nimport { HexRegExMinMax } from './HexRegEx.ts'\n\nexport const HashRegEx = HexRegExMinMax(32, 32)\n\nexport const ZERO_HASH = '0000000000000000000000000000000000000000000000000000000000000000' as Hash\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\n// using true instead of unique symbol to avoid conflicts with other versions of library\nexport type Hash = Brand<Hex, { readonly __hash: true }>\n\nexport const isHash = (value: unknown, bitLength: HashBitLength = 256): value is Hash => {\n return isHex(value, { bitLength })\n}\n\nexport const HashZod = z.string()\n .toLowerCase()\n .regex(HashRegEx, { message: 'Invalid hash format' })\n .refine(\n isHash,\n )\n\nexport function asHash(value: unknown): Hash | undefined\nexport function asHash(value: unknown, assert: AssertConfig): Hash\nexport function asHash(value: unknown, assert?: AssertConfig): Hash | undefined {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value)\n break\n }\n default: {\n return isUndefined(assert) ? undefined : assertError(value, assert, `Unsupported type [${typeof value}]`)\n }\n }\n return isHash(stringValue) ? stringValue : assertError(value, assert, `Value is not a Hash [${value}]`)\n}\n","import { type Hex, hexFromHexString } from './hex/index.ts'\n\nexport function hexToBigInt(hex: Hex): bigint {\n return BigInt(hexFromHexString(hex, { prefix: true }))\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AACzB,OAAOA,QAAO;;;ACDd,SAAS,UAAU,mBAAmB;AAM/B,IAAM,cAAc,CAAC,OAAgB,QAAkC,mBAA2B;AACvG,MAAI,CAAC,YAAY,MAAM,GAAG;AACxB,UAAM,eACF,OAAO,WAAW,WAChB,SACA,OAAO,WAAW,YAChB,iBACA,OAAO,OAAO,cAAc;AACpC,QAAI,SAAS,YAAY,KAAK,iBAAiB,MAAM;AACnD,YAAM,IAAI,MAAM,iBAAiB,OAAO,iBAAiB,YAAY;AAAA,IACvE;AAAA,EACF;AAEA,SAAO;AACT;;;ACpBA,SAAS,gBAAgB;;;ACAlB,IAAM,iBAAiB,CAAC,WAAW,GAAG,WAAoB,OAAO,mBAAmB,MAAO;AAChG,SAAO,IAAI,OAAO,aAAa,WAAW,CAAC,IAAI,WAAW,CAAC,IAAI;AACjE;AAEO,IAAM,oCAAoC,CAAC,WAAW,GAAG,WAAoB,OAAO,mBAAmB,MAAO;AACnH,SAAO,IAAI,OAAO,kBAAkB,WAAW,CAAC,IAAI,WAAW,CAAC,IAAI;AACtE;AAEO,IAAM,WAAW;AACjB,IAAM,qBAAqB;;;ACR3B,IAAM,gBAAgB,CAAC,UAA0B;AACtD,QAAM,UAAU,SAAS;AACzB,MAAI,UAAU,WAAW,EAAG,OAAM,IAAI,MAAM,qCAAqC;AACjF,SAAO;AACT;AAGO,IAAM,gBAAgB,CAAC,UAA0B;AACtD,SAAO,SAAS;AAClB;;;ACNO,IAAM,QAAQ,CAAC,OAAgB,WAAqC;AAEzE,MAAI,OAAO,UAAU,SAAU,QAAO;AAEtC,QAAM,kBAAkB,QAAQ,SAAS,MAAM,SAAS,IAAI,MAAM;AAGlE,MAAI,QAAQ,cAAc,UAAa,oBAAoB,cAAc,QAAQ,SAAS,EAAG,QAAO;AA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AAS,sBAAsB,CAAC,EACnD;AAAA,EACC;AACF;AAIK,SAAS,OAAO,OAAgB,QAAyC;AAC9E,MAAI,cAAkC;AAEtC,UAAQ,OAAO,OAAO;AAAA,IACpB,KAAK,UAAU;AACb,oBAAc,iBAAiB,KAAK;AACpC;AAAA,IACF;AAAA,IACA,SAAS;AACP,aAAOC,aAAY,MAAM,IAAI,SAAY,YAAY,OAAO,QAAQ,qBAAqB,OAAO,KAAK,GAAG;AAAA,IAC1G;AAAA,EACF;AACA,SAAO,OAAO,WAAW,IAAI,cAAc,YAAY,OAAO,QAAQ,wBAAwB,KAAK,GAAG;AACxG;;;AChDO,SAAS,YAAY,KAAkB;AAC5C,SAAO,OAAO,iBAAiB,KAAK,EAAE,QAAQ,KAAK,CAAC,CAAC;AACvD;","names":["z","isString","isString","z","z","z","z","z","Address","z","z","isUndefined","z","z","isUndefined"]}
|
|
1
|
+
{"version":3,"sources":["../../src/address/address.ts","../../src/assert.ts","../../src/hex/from/fromHexString.ts","../../src/HexRegEx.ts","../../src/hex/nibble.ts","../../src/hex/is.ts","../../src/hex/from/fromArrayBuffer.ts","../../src/hex/from/fromBigInt.ts","../../src/hex/from/fromNumber.ts","../../src/hex/from/from.ts","../../src/hex/as.ts","../../src/hex/isHexZero.ts","../../src/hex/legacy.ts","../../src/hex/model.ts","../../src/hex/to.ts","../../src/address/AddressZodTransform.ts","../../src/address/AddressZodValidation.ts","../../src/address/AddressNamespace.ts","../../src/ethAddress.ts","../../src/hash.ts","../../src/hexToBigInt.ts"],"sourcesContent":["import { isObject } from '@xylabs/typeof'\nimport z from 'zod'\n\nimport type { AssertConfig } from '../assert.ts'\nimport { assertError } from '../assert.ts'\nimport type { HexConfig } from '../hex/index.ts'\nimport {\n hexFrom, hexFromHexString, isHex,\n} from '../hex/index.ts'\nimport { HexRegExMinMax } from '../HexRegEx.ts'\nimport type { Address } from './AddressNamespace.ts'\n\nexport const AddressRegEx = HexRegExMinMax(20, 20)\n\nexport const AddressToStringZod = z.string().regex(AddressRegEx)\n\n/** @deprecated use AddressToStringZod */\nexport const AddressToStringSchema = AddressToStringZod\n\nexport const AddressFromStringZod = z.string().toLowerCase().regex(AddressRegEx).transform(v => toAddress(v))\n\n/** @deprecated use AddressFromStringZod */\nexport const AddressFromStringSchema = AddressFromStringZod\n\nexport const ZERO_ADDRESS = '0000000000000000000000000000000000000000' as Address\nexport const ADDRESS_LENGTH = 40 as const\n\nexport const toAddress = (value: string | number | bigint | ArrayBufferLike, config: HexConfig = {}): Address => {\n const { bitLength = 160, prefix = false } = config\n return hexFrom(value, {\n bitLength, prefix, ...config,\n }) as Address\n}\n\nexport const isAddress = (value: unknown, config: HexConfig = {}): value is Address => {\n const { bitLength = 160, prefix = false } = config\n return isHex(value, { bitLength, prefix })\n}\n\nexport function asAddress(value: unknown): Address | undefined\nexport function asAddress(value: unknown, assert: AssertConfig): Address\nexport function asAddress(value: unknown, assert?: AssertConfig): Address | undefined {\n try {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value, { prefix: false })\n break\n }\n default: {\n return isObject(assert) ? assertError(value, assert, `Unsupported type [${typeof value}]`) : undefined\n }\n }\n return isAddress(stringValue) ? stringValue : assertError(value, assert, `Value is not an Address [${value}]`)\n } catch (ex) {\n const error = ex as Error\n return assertError(undefined, assert, error.message)\n }\n}\n","import { isString, isUndefined } from '@xylabs/typeof'\n\ntype 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 (!isUndefined(assert)) {\n const assertString\n = typeof assert === 'string'\n ? assert\n : typeof assert === 'boolean'\n ? defaultMessage\n : assert(value, defaultMessage)\n if (isString(assertString) || assertString === true) {\n throw new Error(assertString === true ? defaultMessage : assertString)\n }\n }\n // eslint-disable-next-line unicorn/no-useless-undefined\n return undefined\n}\n","import { isNumber } from '@xylabs/typeof'\n\nimport { isHex } from '../is.ts'\nimport type { Hex, HexConfig } from '../model.ts'\nimport { bitsToNibbles } from '../nibble.ts'\n\nexport const hexFromHexString = (value: string, config: HexConfig = {}): Hex => {\n const {\n prefix = false, byteSize = 8, bitLength,\n } = config\n const nibbleBoundary = bitsToNibbles(byteSize)\n const unEvened = (value.startsWith('0x') ? value.slice(2) : value).toLowerCase()\n if (isHex(unEvened)) {\n const evenCharacters = unEvened.padStart(unEvened.length + (unEvened.length % nibbleBoundary), '0')\n const padded = isNumber(bitLength) ? evenCharacters.padStart(bitLength / 4, '0') : evenCharacters\n return (prefix ? `0x${padded}` : padded).toLowerCase() as Hex\n } else {\n throw new Error('Received string is not a value hex')\n }\n}\n","export const HexRegExMinMax = (minBytes = 0, maxBytes: number = (Number.MAX_SAFE_INTEGER / 2)) => {\n return new RegExp(`^[a-f0-9]{${minBytes * 2},${maxBytes * 2}}$`)\n}\n\nexport const HexRegExMinMaxMixedCaseWithPrefix = (minBytes = 0, maxBytes: number = (Number.MAX_SAFE_INTEGER / 2)) => {\n return new RegExp(`^0x[a-fA-F0-9]{${minBytes * 2},${maxBytes * 2}}$`)\n}\n\nexport const HexRegEx = /^[0-9a-f]+$/\nexport const HexRegExWithPrefix = /^0x[0-9a-f]+$/\n","// determine the number of nibbles for a given number of bits\nexport const bitsToNibbles = (value: number): number => {\n const nibbles = value >> 2\n if (value !== nibbles << 2) throw new Error('Bits for nibbles must multiple of 4')\n return nibbles\n}\n\n// determine the number of nibbles for a given number of bits\nexport const nibblesToBits = (value: number): number => {\n return value << 2\n}\n","import { HexRegEx, HexRegExWithPrefix } from '../HexRegEx.ts'\nimport type { Hex, HexConfig } from './model.ts'\nimport { bitsToNibbles } from './nibble.ts'\n\nexport const isHex = (value: unknown, config?: HexConfig): value is Hex => {\n // Is it a string?\n if (typeof value !== 'string') return false\n\n const valueCharLength = config?.prefix ? value.length - 2 : value.length\n\n // If a bitLength specified, does it conform?\n if (config?.bitLength !== undefined && valueCharLength !== bitsToNibbles(config?.bitLength)) return false\n\n // Does it only has hex values?\n return config?.prefix ? HexRegExWithPrefix.test(value) : HexRegEx.test(value)\n}\n","import type { Hex, HexConfig } from '../model.ts'\nimport { hexFromHexString } from './fromHexString.ts'\n\n/** Convert an ArrayBuffer to a hex string */\nexport const hexFromArrayBuffer = (\n /** The buffer to be converted */\n buffer: ArrayBufferLike,\n /** Configuration of output format and validation */\n config?: HexConfig,\n): Hex => {\n const unPadded = [...new Uint8Array(buffer)].map(x => x.toString(16).padStart(2, '0')).join('')\n return hexFromHexString(unPadded, config)\n}\n","import type { Hex, HexConfig } from '../model.ts'\nimport { hexFromHexString } from './fromHexString.ts'\n\n/** Convert a bigint to a hex string */\nexport const hexFromBigInt = (\n /** The bigint to be converted */\n value: bigint,\n /** Configuration of output format and validation */\n config: HexConfig = {},\n): Hex => {\n const unPadded = value.toString(16)\n return hexFromHexString(unPadded, config)\n}\n","import type { Hex, HexConfig } from '../model.ts'\nimport { hexFromBigInt } from './fromBigInt.ts'\n\nexport const hexFromNumber = (value: number, config?: HexConfig): Hex => {\n return hexFromBigInt(BigInt(value), config)\n}\n","import type { Hex, HexConfig } from '../model.ts'\nimport { hexFromArrayBuffer } from './fromArrayBuffer.ts'\nimport { hexFromBigInt } from './fromBigInt.ts'\nimport { hexFromHexString } from './fromHexString.ts'\nimport { hexFromNumber } from './fromNumber.ts'\n\n/** Takes unknown value and tries our best to convert it to a hex string */\nexport const hexFrom = (\n /** Supported types are string, number, bigint, and ArrayBuffer */\n value: string | number | bigint | ArrayBufferLike,\n /** Configuration of output format and validation */\n config?: HexConfig,\n): Hex => {\n switch (typeof value) {\n case 'string': {\n return hexFromHexString(value, config)\n }\n case 'bigint': {\n return hexFromBigInt(value, config)\n }\n case 'number': {\n return hexFromNumber(value, config)\n }\n case 'object': {\n return hexFromArrayBuffer(value, config)\n }\n default: {\n throw new Error(`Invalid type: ${typeof value}`)\n }\n }\n}\n","import type { AssertConfig } from '../assert.ts'\nimport { assertError } from '../assert.ts'\nimport { hexFromHexString } from './from/index.ts'\nimport { isHex } from './is.ts'\nimport type { Hex } from './model.ts'\n\nexport function asHex(value: unknown): Hex | undefined\nexport function asHex(value: unknown, assert: AssertConfig): Hex\nexport function asHex(value: unknown, assert?: AssertConfig): Hex | undefined {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value)\n break\n }\n default: {\n return assertError(value, assert, `Unsupported type [${typeof value}]`)\n }\n }\n\n return isHex(stringValue) ? stringValue : assertError(value, assert, `Value is not Hex [${value}]`)\n}\n","import { isString } from '@xylabs/typeof'\n\nimport { hexFromHexString } from './from/index.ts'\n\nexport const isHexZero = (value?: string) => {\n return isString(value) ? BigInt(hexFromHexString(value, { prefix: true })) === 0n : undefined\n}\n","export const toHexLegacy = (buffer: ArrayBuffer) => {\n return [...new Uint8Array(buffer)].map(x => x.toString(16).padStart(2, '0')).join('')\n}\n","import type { Brand } from '@xylabs/typeof'\nimport z from 'zod'\n\nimport { HexRegEx } from '../HexRegEx.ts'\n\n// using true instead of unique symbol to avoid conflicts with other versions of library\nexport type Hex = Brand<Lowercase<string>, { readonly __hex: true }>\n\nexport const HexZod = z.string()\n .regex(HexRegEx, { message: 'Invalid hex format' }).transform(x => x as Hex)\n\n/** Configuration of validation and output format */\nexport interface HexConfig {\n bitLength?: number\n byteSize?: number\n prefix?: boolean\n}\n\nexport type HexZodType = z.infer<typeof HexZod>\n","import { hexFrom } from './from/index.ts'\nimport type { HexConfig } from './model.ts'\n\n/** takes any value and tries our best to convert it to a hex string */\nexport const toHex = (\n /** Supported types are string, number, bigint, and ArrayBuffer */\n value: string | number | bigint | ArrayBufferLike,\n /** Configuration of output format and validation */\n config: HexConfig = {},\n) => {\n const { prefix = false } = config\n return hexFrom(value, { prefix, ...config })\n}\n","import z from 'zod'\n\nimport type { Address } from './AddressNamespace.ts'\nimport { AddressZodValidation } from './AddressZodValidation.ts'\n\nexport const AddressZodTransform = z.union([z.string(), z.bigint()])\n .transform((value) => {\n if (typeof value === 'bigint') {\n return value.toString(16).padStart(40, '0')\n }\n if (value.startsWith('0x')) {\n return value.slice(2)\n }\n return value\n })\n .refine(x => AddressZodValidation.safeParse(x).data)\n .transform(x => x as Address)\n\nexport type AddressZodTransformType = z.infer<typeof AddressZodTransform>\n","import z from 'zod'\n\nimport { HexZod } from '../hex/index.ts'\nimport { ADDRESS_LENGTH } from './address.ts'\nimport type { Address } from './AddressNamespace.ts'\n\nexport const AddressZodValidation = z.string()\n .refine(x => HexZod.safeParse(x))\n .refine(x => x.length === ADDRESS_LENGTH, { error: e => new Error(`Address must have 40 characters [${e.input}]`) })\n .transform(v => v as Address)\n\nexport type AddressZodValidationType = z.infer<typeof AddressZodValidation>\n","import type { Hex } from '../hex/index.ts'\nimport { AddressZodTransform } from './AddressZodTransform.ts'\nimport { AddressZodValidation } from './AddressZodValidation.ts'\n\n// using true instead of unique symbol to avoid conflicts with other versions of library\nexport type Address = Hex & { readonly __address: true }\n\n// eslint-disable-next-line @typescript-eslint/no-namespace\nexport namespace Address {\n export const identify = (value: unknown): value is Address => AddressZodValidation.safeParse(value).success\n export const cast = (value: unknown, assert: boolean = false): Address | undefined => assert\n ? AddressZodValidation.parse(value)\n : AddressZodValidation.safeParse(value).data\n export const from = (value: unknown, assert: boolean = false): Address | undefined => assert\n ? AddressZodTransform.parse(value)\n : AddressZodTransform.safeParse(value).data\n export const toString = (value: Address): string => value as string\n}\n","import type { Brand } from '@xylabs/typeof'\nimport z from 'zod'\n\nimport type { AssertConfig } from './assert.ts'\nimport { assertError } from './assert.ts'\nimport type { HexConfig } from './hex/index.ts'\nimport {\n hexFrom, hexFromHexString, isHex,\n} from './hex/index.ts'\nimport { HexRegExMinMaxMixedCaseWithPrefix } from './HexRegEx.ts'\n\nexport const EthAddressRegEx = HexRegExMinMaxMixedCaseWithPrefix(20, 20)\n\nexport const EthAddressToStringSchema = z.string().regex(EthAddressRegEx)\nexport const EthAddressFromStringSchema = z.string().regex(EthAddressRegEx).transform(v => toEthAddress(v))\n\n// using true instead of unique symbol to avoid conflicts with other versions of library\nexport type EthAddress = Brand<string, { readonly __eth_address: true }>\n\nexport const ETH_ZERO_ADDRESS = '0x0000000000000000000000000000000000000000' as EthAddress\n\nexport const toEthAddress = (value: string | number | bigint | ArrayBufferLike, config: HexConfig = {}): EthAddress => {\n const { bitLength = 160, prefix = false } = config\n return `0x${hexFrom(value, {\n bitLength, prefix, ...config,\n })}` as EthAddress\n}\n\nexport const isEthAddress = (value: unknown, config: HexConfig = {}): value is EthAddress => {\n const { bitLength = 160, prefix = true } = config\n return isHex(value, { bitLength, prefix })\n}\n\nexport const EthAddressZod = z.string()\n .regex(EthAddressRegEx, { message: 'Invalid address format' })\n .refine(\n isEthAddress,\n )\n\nexport function asEthAddress(value: unknown): EthAddress | undefined\nexport function asEthAddress(value: unknown, assert: AssertConfig): EthAddress\nexport function asEthAddress(value: unknown, assert?: AssertConfig): EthAddress | undefined {\n try {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value, { prefix: true })\n break\n }\n default: {\n if (value !== undefined) {\n return assertError(value, assert, `Unsupported type [${typeof value}]`)\n }\n }\n }\n return isEthAddress(stringValue) ? stringValue : assertError(value, assert, `Value is not an EthAddress [${value}]`)\n } catch (ex) {\n const error = ex as Error\n return assertError(undefined, assert, error.message)\n }\n}\n","import type { Brand } from '@xylabs/typeof'\nimport { isUndefined } from '@xylabs/typeof'\nimport z from 'zod'\n\nimport type { AssertConfig } from './assert.ts'\nimport { assertError } from './assert.ts'\nimport type { Hex } from './hex/index.ts'\nimport { hexFromHexString, isHex } from './hex/index.ts'\nimport { HexRegExMinMax } from './HexRegEx.ts'\n\nexport const HashRegEx = HexRegExMinMax(32, 32)\n\nexport const ZERO_HASH = '0000000000000000000000000000000000000000000000000000000000000000' as Hash\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\n// using true instead of unique symbol to avoid conflicts with other versions of library\nexport type Hash = Brand<Hex, { readonly __hash: true }>\n\nexport const isHash = (value: unknown, bitLength: HashBitLength = 256): value is Hash => {\n return isHex(value, { bitLength })\n}\n\nexport const HashZod = z.string()\n .toLowerCase()\n .regex(HashRegEx, { message: 'Invalid hash format' })\n .refine(\n isHash,\n )\n\nexport function asHash(value: unknown): Hash | undefined\nexport function asHash(value: unknown, assert: AssertConfig): Hash\nexport function asHash(value: unknown, assert?: AssertConfig): Hash | undefined {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value)\n break\n }\n default: {\n return isUndefined(assert) ? undefined : assertError(value, assert, `Unsupported type [${typeof value}]`)\n }\n }\n return isHash(stringValue) ? stringValue : assertError(value, assert, `Value is not a Hash [${value}]`)\n}\n","import { type Hex, hexFromHexString } from './hex/index.ts'\n\nexport function hexToBigInt(hex: Hex): bigint {\n return BigInt(hexFromHexString(hex, { prefix: true }))\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AACzB,OAAOA,QAAO;;;ACDd,SAAS,UAAU,mBAAmB;AAM/B,IAAM,cAAc,CAAC,OAAgB,QAAkC,mBAA2B;AACvG,MAAI,CAAC,YAAY,MAAM,GAAG;AACxB,UAAM,eACF,OAAO,WAAW,WAChB,SACA,OAAO,WAAW,YAChB,iBACA,OAAO,OAAO,cAAc;AACpC,QAAI,SAAS,YAAY,KAAK,iBAAiB,MAAM;AACnD,YAAM,IAAI,MAAM,iBAAiB,OAAO,iBAAiB,YAAY;AAAA,IACvE;AAAA,EACF;AAEA,SAAO;AACT;;;ACpBA,SAAS,gBAAgB;;;ACAlB,IAAM,iBAAiB,CAAC,WAAW,GAAG,WAAoB,OAAO,mBAAmB,MAAO;AAChG,SAAO,IAAI,OAAO,aAA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
|
|
2
2
|
"name": "@xylabs/hex",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.2",
|
|
4
4
|
"description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"hex",
|
|
@@ -32,6 +32,11 @@
|
|
|
32
32
|
"source": "./src/index.ts",
|
|
33
33
|
"default": "./dist/neutral/index.mjs"
|
|
34
34
|
},
|
|
35
|
+
"./internal": {
|
|
36
|
+
"types": "./dist/neutral/index-internal.d.ts",
|
|
37
|
+
"source": "./src/index-internal.ts",
|
|
38
|
+
"default": "./dist/neutral/index-internal.mjs"
|
|
39
|
+
},
|
|
35
40
|
"./package.json": "./package.json"
|
|
36
41
|
},
|
|
37
42
|
"module": "./dist/neutral/index.mjs",
|
|
@@ -42,14 +47,14 @@
|
|
|
42
47
|
"src"
|
|
43
48
|
],
|
|
44
49
|
"dependencies": {
|
|
45
|
-
"@xylabs/typeof": "~5.0.
|
|
50
|
+
"@xylabs/typeof": "~5.0.2",
|
|
46
51
|
"zod": "~4.0.14",
|
|
47
52
|
"zod-to-json-schema": "~3.24.6"
|
|
48
53
|
},
|
|
49
54
|
"devDependencies": {
|
|
50
55
|
"@xylabs/ts-scripts-yarn3": "~7.0.3",
|
|
51
56
|
"@xylabs/tsconfig": "~7.0.3",
|
|
52
|
-
"@xylabs/vitest-extended": "~5.0.
|
|
57
|
+
"@xylabs/vitest-extended": "~5.0.2",
|
|
53
58
|
"typescript": "~5.9.2",
|
|
54
59
|
"vitest": "~3.2.4"
|
|
55
60
|
},
|
package/src/Brand.ts
CHANGED
package/src/ethAddress.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import type { Brand } from '@xylabs/typeof'
|
|
1
2
|
import z from 'zod'
|
|
2
3
|
|
|
3
4
|
import type { AssertConfig } from './assert.ts'
|
|
4
5
|
import { assertError } from './assert.ts'
|
|
5
|
-
import type { Brand } from './Brand.ts'
|
|
6
6
|
import type { HexConfig } from './hex/index.ts'
|
|
7
7
|
import {
|
|
8
8
|
hexFrom, hexFromHexString, isHex,
|
package/src/hash.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import type { Brand } from '@xylabs/typeof'
|
|
1
2
|
import { isUndefined } from '@xylabs/typeof'
|
|
2
3
|
import z from 'zod'
|
|
3
4
|
|
|
4
5
|
import type { AssertConfig } from './assert.ts'
|
|
5
6
|
import { assertError } from './assert.ts'
|
|
6
|
-
import type { Brand } from './Brand.ts'
|
|
7
7
|
import type { Hex } from './hex/index.ts'
|
|
8
8
|
import { hexFromHexString, isHex } from './hex/index.ts'
|
|
9
9
|
import { HexRegExMinMax } from './HexRegEx.ts'
|
package/src/hex/model.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,8 +1,2 @@
|
|
|
1
|
-
export * from './address/index.ts'
|
|
2
|
-
export * from './assert.ts'
|
|
3
1
|
export * from './Brand.ts'
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './hash.ts'
|
|
6
|
-
export * from './hex/index.ts'
|
|
7
|
-
export * from './HexRegEx.ts'
|
|
8
|
-
export * from './hexToBigInt.ts'
|
|
2
|
+
export * from './index-internal.ts'
|