@xylabs/hex 5.0.58 → 5.0.59
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/address/AddressTransformZod.d.ts +5 -2
- package/dist/neutral/address/AddressTransformZod.d.ts.map +1 -1
- package/dist/neutral/address/AddressValidationZod.d.ts +5 -2
- package/dist/neutral/address/AddressValidationZod.d.ts.map +1 -1
- package/dist/neutral/address/address.d.ts +5 -3
- package/dist/neutral/address/address.d.ts.map +1 -1
- package/dist/neutral/address/addressDeprecated.d.ts +10 -2
- package/dist/neutral/address/addressDeprecated.d.ts.map +1 -1
- package/dist/neutral/hash/hash.d.ts +3 -2
- package/dist/neutral/hash/hash.d.ts.map +1 -1
- package/dist/neutral/hash/zod.d.ts +2 -3
- package/dist/neutral/hash/zod.d.ts.map +1 -1
- package/dist/neutral/hex/hex.d.ts +3 -3
- package/dist/neutral/hex/hex.d.ts.map +1 -1
- package/dist/neutral/hex/to.d.ts +1 -1
- package/dist/neutral/hex/to.d.ts.map +1 -1
- package/dist/neutral/index.mjs +36 -37
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/zod.d.ts +2 -2
- package/dist/neutral/zod.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/address/address.ts +6 -4
- package/src/hash/hash.ts +4 -2
- package/src/hex/hex.ts +4 -5
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import * as z from 'zod';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
export declare const AddressTransformZod: z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodBigInt, z.ZodNumber]>, z.ZodTransform<string, string | number | bigint>>, z.ZodTransform<Lowercase<string> & {
|
|
3
|
+
readonly __hex: true;
|
|
4
|
+
} & {
|
|
5
|
+
readonly __address: true;
|
|
6
|
+
}, string>>;
|
|
4
7
|
export type AddressTransformZodType = z.infer<typeof AddressTransformZod>;
|
|
5
8
|
//# sourceMappingURL=AddressTransformZod.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AddressTransformZod.d.ts","sourceRoot":"","sources":["../../../src/address/AddressTransformZod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;
|
|
1
|
+
{"version":3,"file":"AddressTransformZod.d.ts","sourceRoot":"","sources":["../../../src/address/AddressTransformZod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAKxB,eAAO,MAAM,mBAAmB;;;;WAkBD,CAAA;AAE/B,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAA"}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import * as z from 'zod';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
export declare const AddressValidationZod: z.ZodPipe<z.ZodString, z.ZodTransform<Lowercase<string> & {
|
|
3
|
+
readonly __hex: true;
|
|
4
|
+
} & {
|
|
5
|
+
readonly __address: true;
|
|
6
|
+
}, string>>;
|
|
4
7
|
export type AddressValidationZodType = z.infer<typeof AddressValidationZod>;
|
|
5
8
|
//# sourceMappingURL=AddressValidationZod.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AddressValidationZod.d.ts","sourceRoot":"","sources":["../../../src/address/AddressValidationZod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;
|
|
1
|
+
{"version":3,"file":"AddressValidationZod.d.ts","sourceRoot":"","sources":["../../../src/address/AddressValidationZod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAMxB,eAAO,MAAM,oBAAoB;;;;WAGF,CAAA;AAE/B,MAAM,MAAM,wBAAwB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAA"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import type { Brand } from '@xylabs/typeof';
|
|
2
|
+
import * as z from 'zod';
|
|
2
3
|
import { type Hex } from '../hex/index.ts';
|
|
3
4
|
export declare const ZERO_ADDRESS: Address;
|
|
4
5
|
export declare const ADDRESS_LENGTH: 40;
|
|
5
6
|
export declare const AddressRegEx: RegExp;
|
|
6
|
-
|
|
7
|
+
type BrandedAddress = Brand<Hex, {
|
|
7
8
|
readonly __address: true;
|
|
8
9
|
}>;
|
|
9
|
-
export declare const
|
|
10
|
-
export
|
|
10
|
+
export declare const AddressZod: z.ZodPipe<z.ZodString, z.ZodTransform<BrandedAddress, string>>;
|
|
11
|
+
export type Address = z.infer<typeof AddressZod>;
|
|
12
|
+
export {};
|
|
11
13
|
//# sourceMappingURL=address.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../../../src/address/address.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../../../src/address/address.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,iBAAiB,CAAA;AAG1C,eAAO,MAAM,YAAY,EAAiD,OAAO,CAAA;AACjF,eAAO,MAAM,cAAc,EAAG,EAAW,CAAA;AAEzC,eAAO,MAAM,YAAY,QAAyD,CAAA;AAElF,KAAK,cAAc,GAAG,KAAK,CAAC,GAAG,EAAE;IAAE,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAA;CAAE,CAAC,CAAA;AAE9D,eAAO,MAAM,UAAU,gEAAqF,CAAA;AAE5G,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,UAAU,CAAC,CAAA"}
|
|
@@ -4,7 +4,15 @@ export declare const AddressToStringZod: z.ZodString;
|
|
|
4
4
|
/** @deprecated use AddressZod */
|
|
5
5
|
export declare const AddressToStringSchema: z.ZodString;
|
|
6
6
|
/** @deprecated use AddressZod */
|
|
7
|
-
export declare const AddressFromStringZod: z.ZodPipe<z.ZodString, z.ZodTransform<
|
|
7
|
+
export declare const AddressFromStringZod: z.ZodPipe<z.ZodString, z.ZodTransform<Lowercase<string> & {
|
|
8
|
+
readonly __hex: true;
|
|
9
|
+
} & {
|
|
10
|
+
readonly __address: true;
|
|
11
|
+
}, string>>;
|
|
8
12
|
/** @deprecated use AddressZod */
|
|
9
|
-
export declare const AddressFromStringSchema: z.ZodPipe<z.ZodString, z.ZodTransform<
|
|
13
|
+
export declare const AddressFromStringSchema: z.ZodPipe<z.ZodString, z.ZodTransform<Lowercase<string> & {
|
|
14
|
+
readonly __hex: true;
|
|
15
|
+
} & {
|
|
16
|
+
readonly __address: true;
|
|
17
|
+
}, string>>;
|
|
10
18
|
//# sourceMappingURL=addressDeprecated.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addressDeprecated.d.ts","sourceRoot":"","sources":["../../../src/address/addressDeprecated.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAKxB,iCAAiC;AACjC,eAAO,MAAM,kBAAkB,aAAiC,CAAA;AAEhE,iCAAiC;AAEjC,eAAO,MAAM,qBAAqB,aAAqB,CAAA;AAEvD,iCAAiC;AACjC,eAAO,MAAM,oBAAoB,
|
|
1
|
+
{"version":3,"file":"addressDeprecated.d.ts","sourceRoot":"","sources":["../../../src/address/addressDeprecated.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAKxB,iCAAiC;AACjC,eAAO,MAAM,kBAAkB,aAAiC,CAAA;AAEhE,iCAAiC;AAEjC,eAAO,MAAM,qBAAqB,aAAqB,CAAA;AAEvD,iCAAiC;AACjC,eAAO,MAAM,oBAAoB;;;;WAA4E,CAAA;AAE7G,iCAAiC;AAEjC,eAAO,MAAM,uBAAuB;;;;WAAuB,CAAA"}
|
|
@@ -7,8 +7,9 @@ export declare const ZERO_HASH: Hash;
|
|
|
7
7
|
export type HashBitLength = 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096;
|
|
8
8
|
export declare const HashBitLength: HashBitLength[];
|
|
9
9
|
export declare const isHashBitLength: (value: unknown) => value is HashBitLength;
|
|
10
|
-
export type
|
|
10
|
+
export type BrandedHash = Brand<Hex, {
|
|
11
11
|
readonly __hash: true;
|
|
12
12
|
}>;
|
|
13
|
-
export declare const HashZod: z.ZodPipe<z.ZodString, z.ZodTransform<
|
|
13
|
+
export declare const HashZod: z.ZodPipe<z.ZodString, z.ZodTransform<BrandedHash, string>>;
|
|
14
|
+
export type Hash = z.infer<typeof HashZod>;
|
|
14
15
|
//# sourceMappingURL=hash.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../../src/hash/hash.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAA;AAG1C,eAAO,MAAM,WAAW,EAAG,EAAW,CAAA;AAEtC,eAAO,MAAM,SAAS,QAA2C,CAAA;AAEjE,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;AAED,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../../src/hash/hash.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAA;AAG1C,eAAO,MAAM,WAAW,EAAG,EAAW,CAAA;AAEtC,eAAO,MAAM,SAAS,QAA2C,CAAA;AAEjE,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;AAED,MAAM,MAAM,WAAW,GAAG,KAAK,CAAC,GAAG,EAAE;IAAE,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAA;CAAE,CAAC,CAAA;AAE/D,eAAO,MAAM,OAAO,6DACuE,CAAA;AAE3F,MAAM,MAAM,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,OAAO,CAAC,CAAA"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as z from 'zod';
|
|
2
|
-
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const JsonToHashZod: z.ZodPipe<z.ZodString, z.ZodTransform<Hash, string>>;
|
|
2
|
+
export declare const HashToJsonZod: z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<import("./hash.ts").BrandedHash, string>>, z.ZodTransform<string, import("./hash.ts").BrandedHash>>;
|
|
3
|
+
export declare const JsonToHashZod: z.ZodPipe<z.ZodString, z.ZodTransform<import("./hash.ts").BrandedHash, string>>;
|
|
5
4
|
//# sourceMappingURL=zod.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zod.d.ts","sourceRoot":"","sources":["../../../src/hash/zod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;
|
|
1
|
+
{"version":3,"file":"zod.d.ts","sourceRoot":"","sources":["../../../src/hash/zod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAMxB,eAAO,MAAM,aAAa,qJAAoC,CAAA;AAC9D,eAAO,MAAM,aAAa,iFAAmD,CAAA"}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { Brand } from '@xylabs/typeof';
|
|
2
2
|
import * as z from 'zod';
|
|
3
|
-
export type
|
|
3
|
+
export type BrandedHex = Brand<Lowercase<string>, {
|
|
4
4
|
readonly __hex: true;
|
|
5
5
|
}>;
|
|
6
|
-
export declare const
|
|
7
|
-
export declare const HexZod: z.ZodPipe<z.ZodString, z.ZodTransform<Hex, string>>;
|
|
6
|
+
export declare const HexZod: z.ZodPipe<z.ZodString, z.ZodTransform<BrandedHex, string>>;
|
|
8
7
|
/** Configuration of validation and output format */
|
|
9
8
|
export interface HexConfig {
|
|
10
9
|
bitLength?: number;
|
|
11
10
|
byteSize?: number;
|
|
12
11
|
prefix?: boolean;
|
|
13
12
|
}
|
|
13
|
+
export type Hex = z.infer<typeof HexZod>;
|
|
14
14
|
//# sourceMappingURL=hex.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hex.d.ts","sourceRoot":"","sources":["../../../src/hex/hex.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAIxB,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"hex.d.ts","sourceRoot":"","sources":["../../../src/hex/hex.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAIxB,MAAM,MAAM,UAAU,GAAG,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE;IAAE,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAA;CAAE,CAAC,CAAA;AAE3E,eAAO,MAAM,MAAM,4DAAoG,CAAA;AAEvH,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,GAAG,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,MAAM,CAAC,CAAA"}
|
package/dist/neutral/hex/to.d.ts
CHANGED
|
@@ -4,5 +4,5 @@ export declare const toHex: (
|
|
|
4
4
|
/** Supported types are string, number, bigint, and ArrayBuffer */
|
|
5
5
|
value: string | number | bigint | ArrayBufferLike,
|
|
6
6
|
/** Configuration of output format and validation */
|
|
7
|
-
config?: HexConfig) => import("./hex.ts").
|
|
7
|
+
config?: HexConfig) => import("./hex.ts").BrandedHex;
|
|
8
8
|
//# sourceMappingURL=to.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to.d.ts","sourceRoot":"","sources":["../../../src/hex/to.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAEzC,uEAAuE;AACvE,eAAO,MAAM,KAAK;AAChB,kEAAkE;AAClE,OAAO,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,eAAe;AACjD,oDAAoD;AACpD,SAAQ,SAAc,
|
|
1
|
+
{"version":3,"file":"to.d.ts","sourceRoot":"","sources":["../../../src/hex/to.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAEzC,uEAAuE;AACvE,eAAO,MAAM,KAAK;AAChB,kEAAkE;AAClE,OAAO,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,eAAe;AACjD,oDAAoD;AACpD,SAAQ,SAAc,kCAIvB,CAAA"}
|
package/dist/neutral/index.mjs
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
// src/hex/from/fromHexString.ts
|
|
5
|
-
import { isNumber } from "@xylabs/typeof";
|
|
1
|
+
// src/address/address.ts
|
|
2
|
+
import * as z from "zod";
|
|
6
3
|
|
|
7
4
|
// src/HexRegEx.ts
|
|
8
5
|
var HexRegExMinMax = (minBytes = 0, maxBytes = Number.MAX_SAFE_INTEGER / 2) => {
|
|
@@ -14,6 +11,21 @@ var HexRegExMinMaxMixedCaseWithPrefix = (minBytes = 0, maxBytes = Number.MAX_SAF
|
|
|
14
11
|
var HexRegEx = /^[0-9a-f]+$/;
|
|
15
12
|
var HexRegExWithPrefix = /^0x[0-9a-f]+$/;
|
|
16
13
|
|
|
14
|
+
// src/address/address.ts
|
|
15
|
+
var ZERO_ADDRESS = "0000000000000000000000000000000000000000";
|
|
16
|
+
var ADDRESS_LENGTH = 40;
|
|
17
|
+
var AddressRegEx = HexRegExMinMax(ADDRESS_LENGTH / 2, ADDRESS_LENGTH / 2);
|
|
18
|
+
var AddressZod = z.string().regex(AddressRegEx).transform((v) => v);
|
|
19
|
+
|
|
20
|
+
// src/address/addressDeprecated.ts
|
|
21
|
+
import * as z5 from "zod";
|
|
22
|
+
|
|
23
|
+
// src/hex/as.ts
|
|
24
|
+
import { assertError } from "@xylabs/error";
|
|
25
|
+
|
|
26
|
+
// src/hex/from/fromHexString.ts
|
|
27
|
+
import { isNumber } from "@xylabs/typeof";
|
|
28
|
+
|
|
17
29
|
// src/hex/nibble.ts
|
|
18
30
|
var bitsToNibbles = (value) => {
|
|
19
31
|
const nibbles = value >> 2;
|
|
@@ -104,9 +116,8 @@ function asHex(value, assert) {
|
|
|
104
116
|
}
|
|
105
117
|
|
|
106
118
|
// src/hex/hex.ts
|
|
107
|
-
import * as
|
|
108
|
-
var
|
|
109
|
-
var HexZod = UntypedHexZod.transform((val) => val);
|
|
119
|
+
import * as z2 from "zod";
|
|
120
|
+
var HexZod = z2.string().regex(HexRegEx, { message: "Invalid hex format" }).transform((val) => val);
|
|
110
121
|
|
|
111
122
|
// src/hex/isHexZero.ts
|
|
112
123
|
import { isString } from "@xylabs/typeof";
|
|
@@ -125,25 +136,15 @@ var toHex = (value, config = {}) => {
|
|
|
125
136
|
return hexFrom(value, { prefix, ...config });
|
|
126
137
|
};
|
|
127
138
|
|
|
128
|
-
// src/address/address.ts
|
|
129
|
-
var ZERO_ADDRESS = "0000000000000000000000000000000000000000";
|
|
130
|
-
var ADDRESS_LENGTH = 40;
|
|
131
|
-
var AddressRegEx = HexRegExMinMax(ADDRESS_LENGTH / 2, ADDRESS_LENGTH / 2);
|
|
132
|
-
var UnTypedAddressZod = UntypedHexZod.regex(AddressRegEx);
|
|
133
|
-
var AddressZod = UnTypedAddressZod.transform((v) => v);
|
|
134
|
-
|
|
135
|
-
// src/address/addressDeprecated.ts
|
|
136
|
-
import * as z4 from "zod";
|
|
137
|
-
|
|
138
139
|
// src/address/AddressTransformZod.ts
|
|
139
|
-
import * as
|
|
140
|
+
import * as z4 from "zod";
|
|
140
141
|
|
|
141
142
|
// src/address/AddressValidationZod.ts
|
|
142
|
-
import * as
|
|
143
|
-
var AddressValidationZod =
|
|
143
|
+
import * as z3 from "zod";
|
|
144
|
+
var AddressValidationZod = 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);
|
|
144
145
|
|
|
145
146
|
// src/address/AddressTransformZod.ts
|
|
146
|
-
var AddressTransformZod =
|
|
147
|
+
var AddressTransformZod = z4.union([z4.string(), z4.bigint(), z4.number()]).transform((value) => {
|
|
147
148
|
switch (typeof value) {
|
|
148
149
|
case "bigint": {
|
|
149
150
|
return value.toString(16).padStart(ADDRESS_LENGTH, "0");
|
|
@@ -174,9 +175,9 @@ function toAddressV2(value, assert = false) {
|
|
|
174
175
|
}
|
|
175
176
|
|
|
176
177
|
// src/address/addressDeprecated.ts
|
|
177
|
-
var AddressToStringZod =
|
|
178
|
+
var AddressToStringZod = z5.string().regex(AddressRegEx);
|
|
178
179
|
var AddressToStringSchema = AddressToStringZod;
|
|
179
|
-
var AddressFromStringZod =
|
|
180
|
+
var AddressFromStringZod = z5.string().toLowerCase().regex(AddressRegEx).transform((v) => toAddress(v));
|
|
180
181
|
var AddressFromStringSchema = AddressFromStringZod;
|
|
181
182
|
|
|
182
183
|
// src/address/as.ts
|
|
@@ -217,11 +218,11 @@ function asAddressV2(value, assert = false) {
|
|
|
217
218
|
|
|
218
219
|
// src/ethAddress.ts
|
|
219
220
|
import { assertError as assertError3 } from "@xylabs/error";
|
|
220
|
-
import * as
|
|
221
|
+
import * as z6 from "zod";
|
|
221
222
|
var EthAddressRegEx = HexRegExMinMaxMixedCaseWithPrefix(20, 20);
|
|
222
|
-
var EthAddressToStringZod =
|
|
223
|
+
var EthAddressToStringZod = z6.string().regex(EthAddressRegEx);
|
|
223
224
|
var EthAddressToStringSchema = EthAddressToStringZod;
|
|
224
|
-
var EthAddressFromStringZod =
|
|
225
|
+
var EthAddressFromStringZod = z6.string().regex(EthAddressRegEx).transform((v) => toEthAddress(v));
|
|
225
226
|
var EthAddressFromStringSchema = EthAddressFromStringZod;
|
|
226
227
|
var ETH_ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
227
228
|
var toEthAddress = (value, config = {}) => {
|
|
@@ -237,7 +238,7 @@ var isEthAddress = (value, config = {}) => {
|
|
|
237
238
|
const loweredValue = typeof value === "string" ? value.toLowerCase() : value;
|
|
238
239
|
return isHex(loweredValue, { bitLength, prefix });
|
|
239
240
|
};
|
|
240
|
-
var EthAddressZod =
|
|
241
|
+
var EthAddressZod = z6.string().regex(EthAddressRegEx, { message: "Invalid address format" }).refine(
|
|
241
242
|
isEthAddress
|
|
242
243
|
);
|
|
243
244
|
function asEthAddress(value, assert) {
|
|
@@ -286,7 +287,7 @@ function asHash(value, assert) {
|
|
|
286
287
|
}
|
|
287
288
|
|
|
288
289
|
// src/hash/hash.ts
|
|
289
|
-
import * as
|
|
290
|
+
import * as z7 from "zod";
|
|
290
291
|
var HASH_LENGTH = 32;
|
|
291
292
|
var HashRegEx = HexRegExMinMax(HASH_LENGTH, HASH_LENGTH);
|
|
292
293
|
var ZERO_HASH = "0000000000000000000000000000000000000000000000000000000000000000";
|
|
@@ -294,12 +295,12 @@ var HashBitLength = [32, 64, 128, 256, 512, 1024, 2048, 4096];
|
|
|
294
295
|
var isHashBitLength = (value) => {
|
|
295
296
|
return typeof value === "number" && HashBitLength.includes(value);
|
|
296
297
|
};
|
|
297
|
-
var HashZod =
|
|
298
|
+
var HashZod = z7.string().regex(HashRegEx, { message: "Invalid hex format" }).transform((val) => val);
|
|
298
299
|
|
|
299
300
|
// src/hash/zod.ts
|
|
300
|
-
import * as
|
|
301
|
+
import * as z8 from "zod";
|
|
301
302
|
var HashToJsonZod = HashZod.transform((v) => v);
|
|
302
|
-
var JsonToHashZod =
|
|
303
|
+
var JsonToHashZod = z8.string().transform((v) => asHash(v, true));
|
|
303
304
|
|
|
304
305
|
// src/hexToBigInt.ts
|
|
305
306
|
function hexToBigInt(hex) {
|
|
@@ -307,9 +308,9 @@ function hexToBigInt(hex) {
|
|
|
307
308
|
}
|
|
308
309
|
|
|
309
310
|
// src/zod.ts
|
|
310
|
-
import * as
|
|
311
|
-
var BigIntToJsonZod =
|
|
312
|
-
var JsonToBigIntZod =
|
|
311
|
+
import * as z9 from "zod";
|
|
312
|
+
var BigIntToJsonZod = z9.bigint().nonnegative().transform((x) => toHex(x));
|
|
313
|
+
var JsonToBigIntZod = z9.string().transform((x) => toHex(x)).transform((x) => hexToBigInt(x));
|
|
313
314
|
export {
|
|
314
315
|
ADDRESS_LENGTH,
|
|
315
316
|
AddressFromStringSchema,
|
|
@@ -340,8 +341,6 @@ export {
|
|
|
340
341
|
HexZod,
|
|
341
342
|
JsonToBigIntZod,
|
|
342
343
|
JsonToHashZod,
|
|
343
|
-
UnTypedAddressZod,
|
|
344
|
-
UntypedHexZod,
|
|
345
344
|
ZERO_ADDRESS,
|
|
346
345
|
ZERO_HASH,
|
|
347
346
|
asAddress,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hex/as.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/hex.ts","../../src/hex/isHexZero.ts","../../src/hex/legacy.ts","../../src/hex/to.ts","../../src/address/address.ts","../../src/address/addressDeprecated.ts","../../src/address/AddressTransformZod.ts","../../src/address/AddressValidationZod.ts","../../src/address/to.ts","../../src/address/as.ts","../../src/address/is.ts","../../src/ethAddress.ts","../../src/hash/as.ts","../../src/hash/is.ts","../../src/hash/hash.ts","../../src/hash/zod.ts","../../src/hexToBigInt.ts","../../src/zod.ts"],"sourcesContent":["import type { AssertConfig } from '@xylabs/error'\nimport { assertError } from '@xylabs/error'\n\nimport { hexFromHexString } from './from/index.ts'\nimport type { Hex } from './hex.ts'\nimport { isHex } from './is.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 { isNumber } from '@xylabs/typeof'\n\nimport type { Hex, HexConfig } from '../hex.ts'\nimport { isHex } from '../is.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 './hex.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 '../hex.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 '../hex.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 '../hex.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 '../hex.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 { Brand } from '@xylabs/typeof'\nimport * as z from 'zod'\n\nimport { HexRegEx } from '../HexRegEx.ts'\n\nexport type Hex = Brand<Lowercase<string>, { readonly __hex: true }>\n\nexport const UntypedHexZod = z.string()\n .regex(HexRegEx, { message: 'Invalid hex format' })\n\nexport const HexZod = UntypedHexZod.transform(val => val as Hex)\n\n/** Configuration of validation and output format */\nexport interface HexConfig {\n bitLength?: number\n byteSize?: number\n prefix?: boolean\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 { hexFrom } from './from/index.ts'\nimport type { HexConfig } from './hex.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 type { Brand } from '@xylabs/typeof'\n\nimport { type Hex, UntypedHexZod } from '../hex/index.ts'\nimport { HexRegExMinMax } from '../HexRegEx.ts'\n\nexport const ZERO_ADDRESS = '0000000000000000000000000000000000000000' as Address\nexport const ADDRESS_LENGTH = 40 as const\n\nexport const AddressRegEx = HexRegExMinMax(ADDRESS_LENGTH / 2, ADDRESS_LENGTH / 2)\n\nexport type Address = Brand<Hex, { readonly __address: true }>\n\nexport const UnTypedAddressZod = UntypedHexZod.regex(AddressRegEx)\nexport const AddressZod = UnTypedAddressZod.transform<Address>(v => v as Address)\n","import * as z from 'zod'\n\nimport { AddressRegEx } from './address.ts'\nimport { toAddress } from './to.ts'\n\n/** @deprecated use AddressZod */\nexport const AddressToStringZod = z.string().regex(AddressRegEx)\n\n/** @deprecated use AddressZod */\n// eslint-disable-next-line sonarjs/deprecation\nexport const AddressToStringSchema = AddressToStringZod\n\n/** @deprecated use AddressZod */\nexport const AddressFromStringZod = z.string().toLowerCase().regex(AddressRegEx).transform(v => toAddress(v))\n\n/** @deprecated use AddressZod */\n// eslint-disable-next-line sonarjs/deprecation\nexport const AddressFromStringSchema = AddressFromStringZod\n","import * as z from 'zod'\n\nimport { type Address, ADDRESS_LENGTH } from './address.ts'\nimport { AddressValidationZod } from './AddressValidationZod.ts'\n\nexport const AddressTransformZod = z.union([z.string(), z.bigint(), z.number()])\n .transform((value) => {\n switch (typeof value) {\n case 'bigint': {\n return value.toString(16).padStart(ADDRESS_LENGTH, '0')\n }\n case 'string': {\n if (value.startsWith('0x')) {\n return value.slice(2)\n }\n return value\n }\n case 'number': {\n return BigInt(value).toString(16).padStart(ADDRESS_LENGTH, '0')\n }\n }\n })\n .refine(x => AddressValidationZod.safeParse(x).data)\n .transform(x => x as Address)\n\nexport type AddressTransformZodType = z.infer<typeof AddressTransformZod>\n","import * as z from 'zod'\n\nimport { HexZod } from '../hex/index.ts'\nimport type { Address } from './address.ts'\nimport { ADDRESS_LENGTH } from './address.ts'\n\nexport const AddressValidationZod = 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 AddressValidationZodType = z.infer<typeof AddressValidationZod>\n","import type { HexConfig } from '../hex/index.ts'\nimport { hexFrom } from '../hex/index.ts'\nimport type { Address } from './address.ts'\nimport { AddressTransformZod } from './AddressTransformZod.ts'\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 unknown as Address\n}\n\n/** @alpha */\nexport function toAddressV2(value: unknown, assert: boolean = false): Address | undefined {\n return assert\n ? AddressTransformZod.parse(value)\n : AddressTransformZod.safeParse(value).data\n}\n","import type { AssertConfig } from '@xylabs/error'\nimport { assertError } from '@xylabs/error'\nimport { isObject } from '@xylabs/typeof'\n\nimport { hexFromHexString } from '../hex/index.ts'\nimport type { Address } from './address.ts'\nimport { AddressValidationZod } from './AddressValidationZod.ts'\nimport { isAddress } from './is.ts'\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\n/** @alpha */\nexport function asAddressV2(value: unknown, assert: boolean = false): Address | undefined {\n return assert\n ? AddressValidationZod.parse(value)\n : AddressValidationZod.safeParse(value).data\n}\n","import type { HexConfig } from '../hex/index.ts'\nimport { isHex } from '../hex/index.ts'\nimport type { Address } from './address.ts'\nimport { AddressValidationZod } from './AddressValidationZod.ts'\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\n/** @alpha */\nexport function isAddressV2(value: unknown): value is Address {\n return AddressValidationZod.safeParse(value).success\n}\n","import type { AssertConfig } from '@xylabs/error'\nimport { assertError } from '@xylabs/error'\nimport type { Brand } from '@xylabs/typeof'\nimport * as z from 'zod'\n\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 EthAddressToStringZod = z.string().regex(EthAddressRegEx)\n\n/** @deprecated use EthAddressToStringZod */\nexport const EthAddressToStringSchema = EthAddressToStringZod\n\nexport const EthAddressFromStringZod = z.string().regex(EthAddressRegEx).transform(v => toEthAddress(v))\n\n/** @deprecated use EthAddressFromStringZod */\nexport const EthAddressFromStringSchema = EthAddressFromStringZod\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 const loweredValue = typeof value === 'string' ? value.toLowerCase() : value\n return isHex(loweredValue, { 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, byteSize: 4 })\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 { AssertConfig } from '@xylabs/error'\nimport { assertError } from '@xylabs/error'\nimport { isUndefined } from '@xylabs/typeof'\n\nimport { hexFromHexString } from '../hex/index.ts'\nimport { type Hash } from './hash.ts'\nimport { isHash } from './is.ts'\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 { isHex } from '../hex/index.ts'\nimport type { Hash, HashBitLength } from './hash.ts'\n\nexport const isHash = (value: unknown, bitLength: HashBitLength = 256): value is Hash => {\n return isHex(value, { bitLength })\n}\n","import type { Brand } from '@xylabs/typeof'\nimport * as z from 'zod'\n\nimport type { Hex } from '../hex/index.ts'\nimport { HexRegExMinMax } from '../HexRegEx.ts'\n\nexport const HASH_LENGTH = 32 as const\n\nexport const HashRegEx = HexRegExMinMax(HASH_LENGTH, HASH_LENGTH)\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\nexport type Hash = Brand<Hex, { readonly __hash: true }>\n\nexport const HashZod = z.string()\n .regex(HashRegEx, { message: 'Invalid hex format' }).transform(val => val as Hash)\n","import * as z from 'zod'\n\nimport { asHash } from './as.ts'\nimport type { Hash } from './hash.ts'\nimport { HashZod } from './hash.ts'\n\nexport const HashToJsonZod = HashZod.transform<string>(v => v)\nexport const JsonToHashZod = z.string().transform<Hash>(v => asHash(v, true))\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","import * as z from 'zod'\n\nimport { toHex } from './hex/index.ts'\nimport { hexToBigInt } from './hexToBigInt.ts'\n\nexport const BigIntToJsonZod = z.bigint().nonnegative().transform(x => toHex(x))\nexport const JsonToBigIntZod = z.string().transform(x => toHex(x)).transform(x => hexToBigInt(x))\n"],"mappings":";AACA,SAAS,mBAAmB;;;ACD5B,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;AAGpG,SAAO,QAAQ,SAAS,mBAAmB,KAAK,KAAK,IAAI,SAAS,KAAK,KAAK;AAC9E;;;AHTO,IAAM,mBAAmB,CAAC,OAAe,SAAoB,CAAC,MAAW;AAC9E,QAAM;AAAA,IACJ,SAAS;AAAA,IAAO,WAAW;AAAA,IAAG;AAAA,EAChC,IAAI;AACJ,QAAM,iBAAiB,cAAc,QAAQ;AAC7C,QAAM,YAAY,MAAM,WAAW,IAAI,IAAI,MAAM,MAAM,CAAC,IAAI,OAAO,YAAY;AAC/E,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AAO,KAAK,GAAG;AAAA,IAC1G;AAAA,EACF;AACA,SAAO,OAAO,WAAW,IAAI,cAAcA,aAAY,OAAO,QAAQ,wBAAwB,KAAK,GAAG;AACxG;;;AEtBA,YAAYC,QAAO;AAKZ,IAAM,cAAc;AAEpB,IAAM,YAAY,eAAe,aAAa,WAAW;AAEzD,IAAM,YAAY;AAGlB,IAAM,gBAAiC,CAAC,IAAI,IAAI,KAAK,KAAK,KAAK,MAAM,MAAM,IAAI;AAE/E,IAAM,kBAAkB,CAAC,UAA2C;AACzE,SAAO,OAAO,UAAU,YAAY,cAAc,SAAS,KAAsB;AACnF;AAIO,IAAM,UAAY,UAAO,EAC7B,MAAM,WAAW,EAAE,SAAS,qBAAqB,CAAC,EAAE,UAAU,SAAO,GAAW;;;ACtBnF,YAAYC,QAAO;AAMZ,IAAM,gBAAgB,QAAQ,UAAkB,OAAK,CAAC;AACtD,IAAM,gBAAkB,UAAO,EAAE,UAAgB,OAAK,OAAO,GAAG,IAAI,CAAC;;;ACLrE,SAAS,YAAY,KAAkB;AAC5C,SAAO,OAAO,iBAAiB,KAAK,EAAE,QAAQ,KAAK,CAAC,CAAC;AACvD;;;ACJA,YAAYC,QAAO;AAKZ,IAAM,kBAAoB,UAAO,EAAE,YAAY,EAAE,UAAU,OAAK,MAAM,CAAC,CAAC;AACxE,IAAM,kBAAoB,UAAO,EAAE,UAAU,OAAK,MAAM,CAAC,CAAC,EAAE,UAAU,OAAK,YAAY,CAAC,CAAC;","names":["z","z","z","assertError","assertError","assertError","z","assertError","assertError","assertError","z","z","z"]}
|
|
1
|
+
{"version":3,"sources":["../../src/address/address.ts","../../src/HexRegEx.ts","../../src/address/addressDeprecated.ts","../../src/hex/as.ts","../../src/hex/from/fromHexString.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/hex.ts","../../src/hex/isHexZero.ts","../../src/hex/legacy.ts","../../src/hex/to.ts","../../src/address/AddressTransformZod.ts","../../src/address/AddressValidationZod.ts","../../src/address/to.ts","../../src/address/as.ts","../../src/address/is.ts","../../src/ethAddress.ts","../../src/hash/as.ts","../../src/hash/is.ts","../../src/hash/hash.ts","../../src/hash/zod.ts","../../src/hexToBigInt.ts","../../src/zod.ts"],"sourcesContent":["import type { Brand } from '@xylabs/typeof'\nimport * as z from 'zod'\n\nimport { type Hex } from '../hex/index.ts'\nimport { HexRegExMinMax } from '../HexRegEx.ts'\n\nexport const ZERO_ADDRESS = '0000000000000000000000000000000000000000' as Address\nexport const ADDRESS_LENGTH = 40 as const\n\nexport const AddressRegEx = HexRegExMinMax(ADDRESS_LENGTH / 2, ADDRESS_LENGTH / 2)\n\ntype BrandedAddress = Brand<Hex, { readonly __address: true }>\n\nexport const AddressZod = z.string().regex(AddressRegEx).transform<BrandedAddress>(v => v as BrandedAddress)\n\nexport type Address = z.infer<typeof AddressZod>\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","import * as z from 'zod'\n\nimport { AddressRegEx } from './address.ts'\nimport { toAddress } from './to.ts'\n\n/** @deprecated use AddressZod */\nexport const AddressToStringZod = z.string().regex(AddressRegEx)\n\n/** @deprecated use AddressZod */\n// eslint-disable-next-line sonarjs/deprecation\nexport const AddressToStringSchema = AddressToStringZod\n\n/** @deprecated use AddressZod */\nexport const AddressFromStringZod = z.string().toLowerCase().regex(AddressRegEx).transform(v => toAddress(v))\n\n/** @deprecated use AddressZod */\n// eslint-disable-next-line sonarjs/deprecation\nexport const AddressFromStringSchema = AddressFromStringZod\n","import type { AssertConfig } from '@xylabs/error'\nimport { assertError } from '@xylabs/error'\n\nimport { hexFromHexString } from './from/index.ts'\nimport type { Hex } from './hex.ts'\nimport { isHex } from './is.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 { isNumber } from '@xylabs/typeof'\n\nimport type { Hex, HexConfig } from '../hex.ts'\nimport { isHex } from '../is.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","// 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 './hex.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 '../hex.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 '../hex.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 '../hex.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 '../hex.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 { Brand } from '@xylabs/typeof'\nimport * as z from 'zod'\n\nimport { HexRegEx } from '../HexRegEx.ts'\n\nexport type BrandedHex = Brand<Lowercase<string>, { readonly __hex: true }>\n\nexport const HexZod = z.string().regex(HexRegEx, { message: 'Invalid hex format' }).transform(val => val as BrandedHex)\n\n/** Configuration of validation and output format */\nexport interface HexConfig {\n bitLength?: number\n byteSize?: number\n prefix?: boolean\n}\n\nexport type Hex = z.infer<typeof HexZod>\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 { hexFrom } from './from/index.ts'\nimport type { HexConfig } from './hex.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 * as z from 'zod'\n\nimport { type Address, ADDRESS_LENGTH } from './address.ts'\nimport { AddressValidationZod } from './AddressValidationZod.ts'\n\nexport const AddressTransformZod = z.union([z.string(), z.bigint(), z.number()])\n .transform((value) => {\n switch (typeof value) {\n case 'bigint': {\n return value.toString(16).padStart(ADDRESS_LENGTH, '0')\n }\n case 'string': {\n if (value.startsWith('0x')) {\n return value.slice(2)\n }\n return value\n }\n case 'number': {\n return BigInt(value).toString(16).padStart(ADDRESS_LENGTH, '0')\n }\n }\n })\n .refine(x => AddressValidationZod.safeParse(x).data)\n .transform(x => x as Address)\n\nexport type AddressTransformZodType = z.infer<typeof AddressTransformZod>\n","import * as z from 'zod'\n\nimport { HexZod } from '../hex/index.ts'\nimport type { Address } from './address.ts'\nimport { ADDRESS_LENGTH } from './address.ts'\n\nexport const AddressValidationZod = 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 AddressValidationZodType = z.infer<typeof AddressValidationZod>\n","import type { HexConfig } from '../hex/index.ts'\nimport { hexFrom } from '../hex/index.ts'\nimport type { Address } from './address.ts'\nimport { AddressTransformZod } from './AddressTransformZod.ts'\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 unknown as Address\n}\n\n/** @alpha */\nexport function toAddressV2(value: unknown, assert: boolean = false): Address | undefined {\n return assert\n ? AddressTransformZod.parse(value)\n : AddressTransformZod.safeParse(value).data\n}\n","import type { AssertConfig } from '@xylabs/error'\nimport { assertError } from '@xylabs/error'\nimport { isObject } from '@xylabs/typeof'\n\nimport { hexFromHexString } from '../hex/index.ts'\nimport type { Address } from './address.ts'\nimport { AddressValidationZod } from './AddressValidationZod.ts'\nimport { isAddress } from './is.ts'\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\n/** @alpha */\nexport function asAddressV2(value: unknown, assert: boolean = false): Address | undefined {\n return assert\n ? AddressValidationZod.parse(value)\n : AddressValidationZod.safeParse(value).data\n}\n","import type { HexConfig } from '../hex/index.ts'\nimport { isHex } from '../hex/index.ts'\nimport type { Address } from './address.ts'\nimport { AddressValidationZod } from './AddressValidationZod.ts'\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\n/** @alpha */\nexport function isAddressV2(value: unknown): value is Address {\n return AddressValidationZod.safeParse(value).success\n}\n","import type { AssertConfig } from '@xylabs/error'\nimport { assertError } from '@xylabs/error'\nimport type { Brand } from '@xylabs/typeof'\nimport * as z from 'zod'\n\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 EthAddressToStringZod = z.string().regex(EthAddressRegEx)\n\n/** @deprecated use EthAddressToStringZod */\nexport const EthAddressToStringSchema = EthAddressToStringZod\n\nexport const EthAddressFromStringZod = z.string().regex(EthAddressRegEx).transform(v => toEthAddress(v))\n\n/** @deprecated use EthAddressFromStringZod */\nexport const EthAddressFromStringSchema = EthAddressFromStringZod\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 const loweredValue = typeof value === 'string' ? value.toLowerCase() : value\n return isHex(loweredValue, { 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, byteSize: 4 })\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 { AssertConfig } from '@xylabs/error'\nimport { assertError } from '@xylabs/error'\nimport { isUndefined } from '@xylabs/typeof'\n\nimport { hexFromHexString } from '../hex/index.ts'\nimport { type Hash } from './hash.ts'\nimport { isHash } from './is.ts'\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 { isHex } from '../hex/index.ts'\nimport type { Hash, HashBitLength } from './hash.ts'\n\nexport const isHash = (value: unknown, bitLength: HashBitLength = 256): value is Hash => {\n return isHex(value, { bitLength })\n}\n","import type { Brand } from '@xylabs/typeof'\nimport * as z from 'zod'\n\nimport type { Hex } from '../hex/index.ts'\nimport { HexRegExMinMax } from '../HexRegEx.ts'\n\nexport const HASH_LENGTH = 32 as const\n\nexport const HashRegEx = HexRegExMinMax(HASH_LENGTH, HASH_LENGTH)\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\nexport type BrandedHash = Brand<Hex, { readonly __hash: true }>\n\nexport const HashZod = z.string()\n .regex(HashRegEx, { message: 'Invalid hex format' }).transform(val => val as BrandedHash)\n\nexport type Hash = z.infer<typeof HashZod>\n","import * as z from 'zod'\n\nimport { asHash } from './as.ts'\nimport type { Hash } from './hash.ts'\nimport { HashZod } from './hash.ts'\n\nexport const HashToJsonZod = HashZod.transform<string>(v => v)\nexport const JsonToHashZod = z.string().transform<Hash>(v => asHash(v, true))\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","import * as z from 'zod'\n\nimport { toHex } from './hex/index.ts'\nimport { hexToBigInt } from './hexToBigInt.ts'\n\nexport const BigIntToJsonZod = z.bigint().nonnegative().transform(x => toHex(x))\nexport const JsonToBigIntZod = z.string().transform(x => toHex(x)).transform(x => hexToBigInt(x))\n"],"mappings":";AACA,YAAY,OAAO;;;ACDZ,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;;;ADH3B,IAAM,eAAe;AACrB,IAAM,iB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BAAgB,QAAQ,UAAkB,OAAK,CAAC;AACtD,IAAM,gBAAkB,UAAO,EAAE,UAAgB,OAAK,OAAO,GAAG,IAAI,CAAC;;;ACLrE,SAAS,YAAY,KAAkB;AAC5C,SAAO,OAAO,iBAAiB,KAAK,EAAE,QAAQ,KAAK,CAAC,CAAC;AACvD;;;ACJA,YAAYC,QAAO;AAKZ,IAAM,kBAAoB,UAAO,EAAE,YAAY,EAAE,UAAU,OAAK,MAAM,CAAC,CAAC;AACxE,IAAM,kBAAoB,UAAO,EAAE,UAAU,OAAK,MAAM,CAAC,CAAC,EAAE,UAAU,OAAK,YAAY,CAAC,CAAC;","names":["z","z","z","z","assertError","assertError","assertError","z","assertError","assertError","assertError","z","z","z"]}
|
package/dist/neutral/zod.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import * as z from 'zod';
|
|
2
|
-
export declare const BigIntToJsonZod: z.ZodPipe<z.ZodBigInt, z.ZodTransform<import("./hex/hex.ts").
|
|
3
|
-
export declare const JsonToBigIntZod: z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<import("./hex/hex.ts").
|
|
2
|
+
export declare const BigIntToJsonZod: z.ZodPipe<z.ZodBigInt, z.ZodTransform<import("./hex/hex.ts").BrandedHex, bigint>>;
|
|
3
|
+
export declare const JsonToBigIntZod: z.ZodPipe<z.ZodPipe<z.ZodString, z.ZodTransform<import("./hex/hex.ts").BrandedHex, string>>, z.ZodTransform<bigint, import("./hex/hex.ts").BrandedHex>>;
|
|
4
4
|
//# sourceMappingURL=zod.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zod.d.ts","sourceRoot":"","sources":["../../src/zod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAKxB,eAAO,MAAM,eAAe,
|
|
1
|
+
{"version":3,"file":"zod.d.ts","sourceRoot":"","sources":["../../src/zod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAKxB,eAAO,MAAM,eAAe,mFAAoD,CAAA;AAChF,eAAO,MAAM,eAAe,yJAAqE,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xylabs/hex",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.59",
|
|
4
4
|
"description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"hex",
|
|
@@ -45,13 +45,13 @@
|
|
|
45
45
|
"!**/*.test.*"
|
|
46
46
|
],
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@xylabs/error": "~5.0.
|
|
49
|
-
"@xylabs/typeof": "~5.0.
|
|
48
|
+
"@xylabs/error": "~5.0.59",
|
|
49
|
+
"@xylabs/typeof": "~5.0.59"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@xylabs/ts-scripts-yarn3": "~7.2.32",
|
|
53
53
|
"@xylabs/tsconfig": "~7.2.32",
|
|
54
|
-
"@xylabs/vitest-extended": "~5.0.
|
|
54
|
+
"@xylabs/vitest-extended": "~5.0.59",
|
|
55
55
|
"typescript": "~5.9.3",
|
|
56
56
|
"vitest": "~4.0.16",
|
|
57
57
|
"zod": "^4.2.1"
|
package/src/address/address.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Brand } from '@xylabs/typeof'
|
|
2
|
+
import * as z from 'zod'
|
|
2
3
|
|
|
3
|
-
import { type Hex
|
|
4
|
+
import { type Hex } from '../hex/index.ts'
|
|
4
5
|
import { HexRegExMinMax } from '../HexRegEx.ts'
|
|
5
6
|
|
|
6
7
|
export const ZERO_ADDRESS = '0000000000000000000000000000000000000000' as Address
|
|
@@ -8,7 +9,8 @@ export const ADDRESS_LENGTH = 40 as const
|
|
|
8
9
|
|
|
9
10
|
export const AddressRegEx = HexRegExMinMax(ADDRESS_LENGTH / 2, ADDRESS_LENGTH / 2)
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
type BrandedAddress = Brand<Hex, { readonly __address: true }>
|
|
12
13
|
|
|
13
|
-
export const
|
|
14
|
-
|
|
14
|
+
export const AddressZod = z.string().regex(AddressRegEx).transform<BrandedAddress>(v => v as BrandedAddress)
|
|
15
|
+
|
|
16
|
+
export type Address = z.infer<typeof AddressZod>
|
package/src/hash/hash.ts
CHANGED
|
@@ -17,7 +17,9 @@ export const isHashBitLength = (value: unknown): value is HashBitLength => {
|
|
|
17
17
|
return typeof value === 'number' && HashBitLength.includes(value as HashBitLength)
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
export type
|
|
20
|
+
export type BrandedHash = Brand<Hex, { readonly __hash: true }>
|
|
21
21
|
|
|
22
22
|
export const HashZod = z.string()
|
|
23
|
-
.regex(HashRegEx, { message: 'Invalid hex format' }).transform(val => val as
|
|
23
|
+
.regex(HashRegEx, { message: 'Invalid hex format' }).transform(val => val as BrandedHash)
|
|
24
|
+
|
|
25
|
+
export type Hash = z.infer<typeof HashZod>
|
package/src/hex/hex.ts
CHANGED
|
@@ -3,12 +3,9 @@ import * as z from 'zod'
|
|
|
3
3
|
|
|
4
4
|
import { HexRegEx } from '../HexRegEx.ts'
|
|
5
5
|
|
|
6
|
-
export type
|
|
6
|
+
export type BrandedHex = Brand<Lowercase<string>, { readonly __hex: true }>
|
|
7
7
|
|
|
8
|
-
export const
|
|
9
|
-
.regex(HexRegEx, { message: 'Invalid hex format' })
|
|
10
|
-
|
|
11
|
-
export const HexZod = UntypedHexZod.transform(val => val as Hex)
|
|
8
|
+
export const HexZod = z.string().regex(HexRegEx, { message: 'Invalid hex format' }).transform(val => val as BrandedHex)
|
|
12
9
|
|
|
13
10
|
/** Configuration of validation and output format */
|
|
14
11
|
export interface HexConfig {
|
|
@@ -16,3 +13,5 @@ export interface HexConfig {
|
|
|
16
13
|
byteSize?: number
|
|
17
14
|
prefix?: boolean
|
|
18
15
|
}
|
|
16
|
+
|
|
17
|
+
export type Hex = z.infer<typeof HexZod>
|