@xylabs/hex 4.15.3 → 5.0.0
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 +4 -0
- package/dist/neutral/Brand.d.ts.map +1 -0
- package/dist/neutral/{HexRegExMinMax.d.ts → HexRegEx.d.ts} +3 -1
- package/dist/neutral/HexRegEx.d.ts.map +1 -0
- package/dist/neutral/address/AddressNamespace.d.ts +11 -0
- package/dist/neutral/address/AddressNamespace.d.ts.map +1 -0
- package/dist/neutral/address/AddressZodTransform.d.ts +5 -0
- package/dist/neutral/address/AddressZodTransform.d.ts.map +1 -0
- package/dist/neutral/address/AddressZodValidation.d.ts +5 -0
- package/dist/neutral/address/AddressZodValidation.d.ts.map +1 -0
- package/dist/neutral/address/address.d.ts +18 -0
- package/dist/neutral/address/address.d.ts.map +1 -0
- package/dist/neutral/address/index.d.ts +5 -0
- package/dist/neutral/address/index.d.ts.map +1 -0
- package/dist/neutral/ethAddress.d.ts +6 -5
- package/dist/neutral/ethAddress.d.ts.map +1 -1
- package/dist/neutral/hash.d.ts +5 -4
- package/dist/neutral/hash.d.ts.map +1 -1
- package/dist/neutral/hex/index.d.ts +0 -1
- package/dist/neutral/hex/index.d.ts.map +1 -1
- package/dist/neutral/hex/is.d.ts.map +1 -1
- package/dist/neutral/hex/model.d.ts +6 -5
- package/dist/neutral/hex/model.d.ts.map +1 -1
- package/dist/neutral/index.d.ts +3 -1
- package/dist/neutral/index.d.ts.map +1 -1
- package/dist/neutral/index.mjs +61 -35
- package/dist/neutral/index.mjs.map +1 -1
- package/package.json +6 -6
- package/src/Brand.ts +1 -0
- package/src/{HexRegExMinMax.ts → HexRegEx.ts} +3 -0
- package/src/address/AddressNamespace.ts +18 -0
- package/src/address/AddressZodTransform.ts +19 -0
- package/src/address/AddressZodValidation.ts +12 -0
- package/src/{address.ts → address/address.ts} +15 -15
- package/src/address/index.ts +4 -0
- package/src/ethAddress.ts +4 -2
- package/src/hash.ts +5 -2
- package/src/hex/index.ts +0 -1
- package/src/hex/is.ts +2 -2
- package/src/hex/model.ts +7 -11
- package/src/index.ts +3 -1
- package/src/spec/address.spec.ts +51 -1
- package/dist/neutral/HexRegExMinMax.d.ts.map +0 -1
- package/dist/neutral/address.d.ts +0 -16
- package/dist/neutral/address.d.ts.map +0 -1
- package/dist/neutral/hex/regex.d.ts +0 -3
- package/dist/neutral/hex/regex.d.ts.map +0 -1
- package/src/hex/regex.ts +0 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Brand.d.ts","sourceRoot":"","sources":["../../src/Brand.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,KAAK,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,CAAA"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export declare const HexRegExMinMax: (minBytes?: number, maxBytes?: number) => RegExp;
|
|
2
2
|
export declare const HexRegExMinMaxMixedCaseWithPrefix: (minBytes?: number, maxBytes?: number) => RegExp;
|
|
3
|
-
|
|
3
|
+
export declare const HexRegEx: RegExp;
|
|
4
|
+
export declare const HexRegExWithPrefix: RegExp;
|
|
5
|
+
//# sourceMappingURL=HexRegEx.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HexRegEx.d.ts","sourceRoot":"","sources":["../../src/HexRegEx.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,GAAI,iBAAY,EAAE,WAAU,MAAsC,WAE5F,CAAA;AAED,eAAO,MAAM,iCAAiC,GAAI,iBAAY,EAAE,WAAU,MAAsC,WAE/G,CAAA;AAED,eAAO,MAAM,QAAQ,QAAgB,CAAA;AACrC,eAAO,MAAM,kBAAkB,QAAkB,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Hex } from '../hex/index.ts';
|
|
2
|
+
export type Address = Hex & {
|
|
3
|
+
readonly __address: true;
|
|
4
|
+
};
|
|
5
|
+
export declare namespace Address {
|
|
6
|
+
const identify: (value: unknown) => value is Address;
|
|
7
|
+
const cast: (value: unknown, assert?: boolean) => Address | undefined;
|
|
8
|
+
const from: (value: unknown, assert?: boolean) => Address | undefined;
|
|
9
|
+
const toString: (value: Address) => string;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=AddressNamespace.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AddressNamespace.d.ts","sourceRoot":"","sources":["../../../src/address/AddressNamespace.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAA;AAK1C,MAAM,MAAM,OAAO,GAAG,GAAG,GAAG;IAAE,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAA;CAAE,CAAA;AAGxD,yBAAiB,OAAO,CAAC;IAChB,MAAM,QAAQ,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,OAAwD,CAAA;IACpG,MAAM,IAAI,GAAI,OAAO,OAAO,EAAE,SAAQ,OAAe,KAAG,OAAO,GAAG,SAE3B,CAAA;IACvC,MAAM,IAAI,GAAI,OAAO,OAAO,EAAE,SAAQ,OAAe,KAAG,OAAO,GAAG,SAE5B,CAAA;IACtC,MAAM,QAAQ,GAAI,OAAO,OAAO,KAAG,MAAyB,CAAA;CACpE"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import z from 'zod';
|
|
2
|
+
import type { Address } from './AddressNamespace.ts';
|
|
3
|
+
export declare const AddressZodTransform: z.ZodPipe<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodBigInt]>, z.ZodTransform<string, string | bigint>>, z.ZodTransform<Address, string>>;
|
|
4
|
+
export type AddressZodTransformType = z.infer<typeof AddressZodTransform>;
|
|
5
|
+
//# sourceMappingURL=AddressZodTransform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AddressZodTransform.d.ts","sourceRoot":"","sources":["../../../src/address/AddressZodTransform.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAA;AAEnB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AAGpD,eAAO,MAAM,mBAAmB,iJAWD,CAAA;AAE/B,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAA"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import z from 'zod';
|
|
2
|
+
import type { Address } from './AddressNamespace.ts';
|
|
3
|
+
export declare const AddressZodValidation: z.ZodPipe<z.ZodString, z.ZodTransform<Address, string>>;
|
|
4
|
+
export type AddressZodValidationType = z.infer<typeof AddressZodValidation>;
|
|
5
|
+
//# sourceMappingURL=AddressZodValidation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AddressZodValidation.d.ts","sourceRoot":"","sources":["../../../src/address/AddressZodValidation.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAA;AAInB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AAEpD,eAAO,MAAM,oBAAoB,yDAGF,CAAA;AAE/B,MAAM,MAAM,wBAAwB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import z from 'zod';
|
|
2
|
+
import type { AssertConfig } from '../assert.ts';
|
|
3
|
+
import type { HexConfig } from '../hex/index.ts';
|
|
4
|
+
import type { Address } from './AddressNamespace.ts';
|
|
5
|
+
export declare const AddressRegEx: RegExp;
|
|
6
|
+
export declare const AddressToStringZod: z.ZodString;
|
|
7
|
+
/** @deprecated use AddressToStringZod */
|
|
8
|
+
export declare const AddressToStringSchema: z.ZodString;
|
|
9
|
+
export declare const AddressFromStringZod: z.ZodPipe<z.ZodString, z.ZodTransform<Address, string>>;
|
|
10
|
+
/** @deprecated use AddressFromStringZod */
|
|
11
|
+
export declare const AddressFromStringSchema: z.ZodPipe<z.ZodString, z.ZodTransform<Address, string>>;
|
|
12
|
+
export declare const ZERO_ADDRESS: Address;
|
|
13
|
+
export declare const ADDRESS_LENGTH: 40;
|
|
14
|
+
export declare const toAddress: (value: string | number | bigint | ArrayBufferLike, config?: HexConfig) => Address;
|
|
15
|
+
export declare const isAddress: (value: unknown, config?: HexConfig) => value is Address;
|
|
16
|
+
export declare function asAddress(value: unknown): Address | undefined;
|
|
17
|
+
export declare function asAddress(value: unknown, assert: AssertConfig): Address;
|
|
18
|
+
//# sourceMappingURL=address.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../../../src/address/address.ts"],"names":[],"mappings":"AACA,OAAO,CAAC,MAAM,KAAK,CAAA;AAEnB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAEhD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAKhD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AAEpD,eAAO,MAAM,YAAY,QAAyB,CAAA;AAElD,eAAO,MAAM,kBAAkB,aAAiC,CAAA;AAEhE,yCAAyC;AACzC,eAAO,MAAM,qBAAqB,aAAqB,CAAA;AAEvD,eAAO,MAAM,oBAAoB,yDAA4E,CAAA;AAE7G,2CAA2C;AAC3C,eAAO,MAAM,uBAAuB,yDAAuB,CAAA;AAE3D,eAAO,MAAM,YAAY,EAAiD,OAAO,CAAA;AACjF,eAAO,MAAM,cAAc,EAAG,EAAW,CAAA;AAEzC,eAAO,MAAM,SAAS,GAAI,OAAO,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,eAAe,EAAE,SAAQ,SAAc,KAAG,OAKrG,CAAA;AAED,eAAO,MAAM,SAAS,GAAI,OAAO,OAAO,EAAE,SAAQ,SAAc,KAAG,KAAK,IAAI,OAG3E,CAAA;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,GAAG,SAAS,CAAA;AAC9D,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,GAAG,OAAO,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/address/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,uBAAuB,CAAA;AACrC,cAAc,0BAA0B,CAAA;AACxC,cAAc,2BAA2B,CAAA"}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import z from 'zod';
|
|
2
2
|
import type { AssertConfig } from './assert.ts';
|
|
3
|
+
import type { Brand } from './Brand.ts';
|
|
3
4
|
import type { HexConfig } from './hex/index.ts';
|
|
4
5
|
export declare const EthAddressRegEx: RegExp;
|
|
5
6
|
export declare const EthAddressToStringSchema: z.ZodString;
|
|
6
|
-
export declare const EthAddressFromStringSchema: z.
|
|
7
|
-
export type EthAddress = string
|
|
8
|
-
readonly __eth_address:
|
|
9
|
-
}
|
|
7
|
+
export declare const EthAddressFromStringSchema: z.ZodPipe<z.ZodString, z.ZodTransform<EthAddress, string>>;
|
|
8
|
+
export type EthAddress = Brand<string, {
|
|
9
|
+
readonly __eth_address: true;
|
|
10
|
+
}>;
|
|
10
11
|
export declare const ETH_ZERO_ADDRESS: EthAddress;
|
|
11
12
|
export declare const toEthAddress: (value: string | number | bigint | ArrayBufferLike, config?: HexConfig) => EthAddress;
|
|
12
13
|
export declare const isEthAddress: (value: unknown, config?: HexConfig) => value is EthAddress;
|
|
13
|
-
export declare const EthAddressZod: z.
|
|
14
|
+
export declare const EthAddressZod: z.ZodString;
|
|
14
15
|
export declare function asEthAddress(value: unknown): EthAddress | undefined;
|
|
15
16
|
export declare function asEthAddress(value: unknown, assert: AssertConfig): EthAddress;
|
|
16
17
|
//# sourceMappingURL=ethAddress.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ethAddress.d.ts","sourceRoot":"","sources":["../../src/ethAddress.ts"],"names":[],"mappings":"AAAA,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
|
|
1
|
+
{"version":3,"file":"ethAddress.d.ts","sourceRoot":"","sources":["../../src/ethAddress.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAA;AAEnB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE/C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AACvC,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,16 +1,17 @@
|
|
|
1
1
|
import z from 'zod';
|
|
2
2
|
import type { AssertConfig } from './assert.ts';
|
|
3
|
+
import type { Brand } from './Brand.ts';
|
|
3
4
|
import type { Hex } from './hex/index.ts';
|
|
4
5
|
export declare const HashRegEx: RegExp;
|
|
5
6
|
export declare const ZERO_HASH: Hash;
|
|
6
7
|
export type HashBitLength = 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096;
|
|
7
8
|
export declare const HashBitLength: HashBitLength[];
|
|
8
9
|
export declare const isHashBitLength: (value: unknown) => value is HashBitLength;
|
|
9
|
-
export type Hash = Hex
|
|
10
|
-
readonly __hash:
|
|
11
|
-
}
|
|
10
|
+
export type Hash = Brand<Hex, {
|
|
11
|
+
readonly __hash: true;
|
|
12
|
+
}>;
|
|
12
13
|
export declare const isHash: (value: unknown, bitLength?: HashBitLength) => value is Hash;
|
|
13
|
-
export declare const HashZod: z.
|
|
14
|
+
export declare const HashZod: z.ZodString;
|
|
14
15
|
export declare function asHash(value: unknown): Hash | undefined;
|
|
15
16
|
export declare function asHash(value: unknown, assert: AssertConfig): Hash;
|
|
16
17
|
//# sourceMappingURL=hash.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/hash.ts"],"names":[],"mappings":"AACA,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,EA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AK,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,GAAG,IAAI,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hex/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,SAAS,CAAA;AACvB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hex/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,SAAS,CAAA;AACvB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,SAAS,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is.d.ts","sourceRoot":"","sources":["../../../src/hex/is.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"is.d.ts","sourceRoot":"","sources":["../../../src/hex/is.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAGhD,eAAO,MAAM,KAAK,GAAI,OAAO,OAAO,EAAE,SAAS,SAAS,KAAG,KAAK,IAAI,GAWnE,CAAA"}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import z from 'zod';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export declare const HexZod: z.
|
|
2
|
+
import type { Brand } from '../Brand.ts';
|
|
3
|
+
export type Hex = Brand<Lowercase<string>, {
|
|
4
|
+
readonly __hex: true;
|
|
5
|
+
}>;
|
|
6
|
+
export declare const HexZod: z.ZodPipe<z.ZodString, z.ZodTransform<Hex, string>>;
|
|
7
7
|
/** Configuration of validation and output format */
|
|
8
8
|
export interface HexConfig {
|
|
9
9
|
bitLength?: number;
|
|
10
10
|
byteSize?: number;
|
|
11
11
|
prefix?: boolean;
|
|
12
12
|
}
|
|
13
|
+
export type HexZodType = z.infer<typeof HexZod>;
|
|
13
14
|
//# sourceMappingURL=model.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../src/hex/model.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAA;
|
|
1
|
+
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../src/hex/model.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAA;AAEnB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAIxC,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"}
|
package/dist/neutral/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
export * from './address.ts';
|
|
1
|
+
export * from './address/index.ts';
|
|
2
2
|
export * from './assert.ts';
|
|
3
|
+
export * from './Brand.ts';
|
|
3
4
|
export * from './ethAddress.ts';
|
|
4
5
|
export * from './hash.ts';
|
|
5
6
|
export * from './hex/index.ts';
|
|
7
|
+
export * from './HexRegEx.ts';
|
|
6
8
|
export * from './hexToBigInt.ts';
|
|
7
9
|
//# 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,oBAAoB,CAAA;AAClC,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,WAAW,CAAA;AACzB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA"}
|
package/dist/neutral/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// src/address.ts
|
|
1
|
+
// src/address/address.ts
|
|
2
2
|
import { isObject } from "@xylabs/typeof";
|
|
3
3
|
import z2 from "zod";
|
|
4
4
|
|
|
@@ -17,6 +17,16 @@ var assertError = (value, assert, defaultMessage) => {
|
|
|
17
17
|
// src/hex/from/fromHexString.ts
|
|
18
18
|
import { isNumber } from "@xylabs/typeof";
|
|
19
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
|
+
|
|
20
30
|
// src/hex/nibble.ts
|
|
21
31
|
var bitsToNibbles = (value) => {
|
|
22
32
|
const nibbles = value >> 2;
|
|
@@ -27,16 +37,12 @@ var nibblesToBits = (value) => {
|
|
|
27
37
|
return value << 2;
|
|
28
38
|
};
|
|
29
39
|
|
|
30
|
-
// src/hex/regex.ts
|
|
31
|
-
var hexRegex = /^[\da-f]+$/i;
|
|
32
|
-
var hexRegexWithPrefix = /0x[\da-f]+$/i;
|
|
33
|
-
|
|
34
40
|
// src/hex/is.ts
|
|
35
41
|
var isHex = (value, config) => {
|
|
36
42
|
if (typeof value !== "string") return false;
|
|
37
43
|
const valueCharLength = config?.prefix ? value.length - 2 : value.length;
|
|
38
44
|
if (config?.bitLength !== void 0 && valueCharLength !== bitsToNibbles(config?.bitLength)) return false;
|
|
39
|
-
return config?.prefix ?
|
|
45
|
+
return config?.prefix ? HexRegExWithPrefix.test(value) : HexRegEx.test(value);
|
|
40
46
|
};
|
|
41
47
|
|
|
42
48
|
// src/hex/from/fromHexString.ts
|
|
@@ -123,20 +129,7 @@ var toHexLegacy = (buffer) => {
|
|
|
123
129
|
|
|
124
130
|
// src/hex/model.ts
|
|
125
131
|
import z from "zod";
|
|
126
|
-
|
|
127
|
-
// src/HexRegExMinMax.ts
|
|
128
|
-
var HexRegExMinMax = (minBytes = 0, maxBytes = Number.MAX_SAFE_INTEGER / 2) => {
|
|
129
|
-
return new RegExp(`^[a-f0-9]{${minBytes * 2},${maxBytes * 2}}$`);
|
|
130
|
-
};
|
|
131
|
-
var HexRegExMinMaxMixedCaseWithPrefix = (minBytes = 0, maxBytes = Number.MAX_SAFE_INTEGER / 2) => {
|
|
132
|
-
return new RegExp(`^0x[a-fA-F0-9]{${minBytes * 2},${maxBytes * 2}}$`);
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
// src/hex/model.ts
|
|
136
|
-
var HexRegEx = HexRegExMinMax(1, Number.MAX_SAFE_INTEGER);
|
|
137
|
-
var HexZod = z.string().toLowerCase().regex(HexRegEx, { message: "Invalid hex format" }).refine(
|
|
138
|
-
isHex
|
|
139
|
-
);
|
|
132
|
+
var HexZod = z.string().regex(HexRegEx, { message: "Invalid hex format" }).transform((x) => x);
|
|
140
133
|
|
|
141
134
|
// src/hex/to.ts
|
|
142
135
|
var toHex = (value, config = {}) => {
|
|
@@ -144,11 +137,14 @@ var toHex = (value, config = {}) => {
|
|
|
144
137
|
return hexFrom(value, { prefix, ...config });
|
|
145
138
|
};
|
|
146
139
|
|
|
147
|
-
// src/address.ts
|
|
140
|
+
// src/address/address.ts
|
|
148
141
|
var AddressRegEx = HexRegExMinMax(20, 20);
|
|
149
|
-
var
|
|
150
|
-
var
|
|
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;
|
|
151
146
|
var ZERO_ADDRESS = "0000000000000000000000000000000000000000";
|
|
147
|
+
var ADDRESS_LENGTH = 40;
|
|
152
148
|
var toAddress = (value, config = {}) => {
|
|
153
149
|
const { bitLength = 160, prefix = false } = config;
|
|
154
150
|
return hexFrom(value, {
|
|
@@ -161,9 +157,6 @@ var isAddress = (value, config = {}) => {
|
|
|
161
157
|
const { bitLength = 160, prefix = false } = config;
|
|
162
158
|
return isHex(value, { bitLength, prefix });
|
|
163
159
|
};
|
|
164
|
-
var AddressZod = z2.string().toLowerCase().regex(AddressRegEx, { message: "Invalid address format" }).refine(
|
|
165
|
-
isAddress
|
|
166
|
-
);
|
|
167
160
|
function asAddress(value, assert) {
|
|
168
161
|
try {
|
|
169
162
|
let stringValue = void 0;
|
|
@@ -183,11 +176,38 @@ function asAddress(value, assert) {
|
|
|
183
176
|
}
|
|
184
177
|
}
|
|
185
178
|
|
|
186
|
-
// src/
|
|
179
|
+
// src/address/AddressZodTransform.ts
|
|
180
|
+
import z4 from "zod";
|
|
181
|
+
|
|
182
|
+
// src/address/AddressZodValidation.ts
|
|
187
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";
|
|
188
208
|
var EthAddressRegEx = HexRegExMinMaxMixedCaseWithPrefix(20, 20);
|
|
189
|
-
var EthAddressToStringSchema =
|
|
190
|
-
var EthAddressFromStringSchema =
|
|
209
|
+
var EthAddressToStringSchema = z5.string().regex(EthAddressRegEx);
|
|
210
|
+
var EthAddressFromStringSchema = z5.string().regex(EthAddressRegEx).transform((v) => toEthAddress(v));
|
|
191
211
|
var ETH_ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
192
212
|
var toEthAddress = (value, config = {}) => {
|
|
193
213
|
const { bitLength = 160, prefix = false } = config;
|
|
@@ -201,7 +221,7 @@ var isEthAddress = (value, config = {}) => {
|
|
|
201
221
|
const { bitLength = 160, prefix = true } = config;
|
|
202
222
|
return isHex(value, { bitLength, prefix });
|
|
203
223
|
};
|
|
204
|
-
var EthAddressZod =
|
|
224
|
+
var EthAddressZod = z5.string().regex(EthAddressRegEx, { message: "Invalid address format" }).refine(
|
|
205
225
|
isEthAddress
|
|
206
226
|
);
|
|
207
227
|
function asEthAddress(value, assert) {
|
|
@@ -227,7 +247,7 @@ function asEthAddress(value, assert) {
|
|
|
227
247
|
|
|
228
248
|
// src/hash.ts
|
|
229
249
|
import { isUndefined as isUndefined2 } from "@xylabs/typeof";
|
|
230
|
-
import
|
|
250
|
+
import z6 from "zod";
|
|
231
251
|
var HashRegEx = HexRegExMinMax(32, 32);
|
|
232
252
|
var ZERO_HASH = "0000000000000000000000000000000000000000000000000000000000000000";
|
|
233
253
|
var HashBitLength = [32, 64, 128, 256, 512, 1024, 2048, 4096];
|
|
@@ -237,7 +257,7 @@ var isHashBitLength = (value) => {
|
|
|
237
257
|
var isHash = (value, bitLength = 256) => {
|
|
238
258
|
return isHex(value, { bitLength });
|
|
239
259
|
};
|
|
240
|
-
var HashZod =
|
|
260
|
+
var HashZod = z6.string().toLowerCase().regex(HashRegEx, { message: "Invalid hash format" }).refine(
|
|
241
261
|
isHash
|
|
242
262
|
);
|
|
243
263
|
function asHash(value, assert) {
|
|
@@ -259,10 +279,15 @@ function hexToBigInt(hex) {
|
|
|
259
279
|
return BigInt(hexFromHexString(hex, { prefix: true }));
|
|
260
280
|
}
|
|
261
281
|
export {
|
|
282
|
+
ADDRESS_LENGTH,
|
|
283
|
+
Address,
|
|
262
284
|
AddressFromStringSchema,
|
|
285
|
+
AddressFromStringZod,
|
|
263
286
|
AddressRegEx,
|
|
264
287
|
AddressToStringSchema,
|
|
265
|
-
|
|
288
|
+
AddressToStringZod,
|
|
289
|
+
AddressZodTransform,
|
|
290
|
+
AddressZodValidation,
|
|
266
291
|
ETH_ZERO_ADDRESS,
|
|
267
292
|
EthAddressFromStringSchema,
|
|
268
293
|
EthAddressRegEx,
|
|
@@ -272,6 +297,9 @@ export {
|
|
|
272
297
|
HashRegEx,
|
|
273
298
|
HashZod,
|
|
274
299
|
HexRegEx,
|
|
300
|
+
HexRegExMinMax,
|
|
301
|
+
HexRegExMinMaxMixedCaseWithPrefix,
|
|
302
|
+
HexRegExWithPrefix,
|
|
275
303
|
HexZod,
|
|
276
304
|
ZERO_ADDRESS,
|
|
277
305
|
ZERO_HASH,
|
|
@@ -286,8 +314,6 @@ export {
|
|
|
286
314
|
hexFromBigInt,
|
|
287
315
|
hexFromHexString,
|
|
288
316
|
hexFromNumber,
|
|
289
|
-
hexRegex,
|
|
290
|
-
hexRegexWithPrefix,
|
|
291
317
|
hexToBigInt,
|
|
292
318
|
isAddress,
|
|
293
319
|
isEthAddress,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/address.ts","../../src/assert.ts","../../src/hex/from/fromHexString.ts","../../src/hex/nibble.ts","../../src/hex/regex.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/HexRegExMinMax.ts","../../src/hex/to.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 { Hex, HexConfig } from './hex/index.ts'\nimport {\n hexFrom, hexFromHexString, isHex,\n} from './hex/index.ts'\nimport { HexRegExMinMax } from './HexRegExMinMax.ts'\n\nexport const AddressRegEx = HexRegExMinMax(20, 20)\n\nexport const AddressToStringSchema = z.string().toLowerCase().regex(AddressRegEx)\nexport const AddressFromStringSchema = z.string().toLowerCase().regex(AddressRegEx).transform(v => toAddress(v))\n\nexport type Address = Hex & { readonly __address: unique symbol }\n\nexport const ZERO_ADDRESS = '0000000000000000000000000000000000000000' as Address\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 const AddressZod = z.string()\n .toLowerCase()\n .regex(AddressRegEx, { message: 'Invalid address format' })\n .refine(\n isAddress,\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","// 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","export const hexRegex = /^[\\da-f]+$/i\nexport const hexRegexWithPrefix = /0x[\\da-f]+$/i\n","import type { Hex, HexConfig } from './model.ts'\nimport { bitsToNibbles } from './nibble.ts'\nimport { hexRegex, hexRegexWithPrefix } from './regex.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 { HexRegExMinMax } from '../HexRegExMinMax.ts'\nimport { isHex } from './is.ts'\n\n// we use Exclude to intentionally make the type not equal to string\nexport type Hex = Lowercase<string> & { readonly __hex: unique symbol }\n\nexport const HexRegEx = HexRegExMinMax(1, Number.MAX_SAFE_INTEGER)\n\nexport const HexZod = z.string()\n .toLowerCase()\n .regex(HexRegEx, { message: 'Invalid hex format' })\n .refine(\n isHex,\n )\n\n/** Configuration of validation and output format */\nexport interface HexConfig {\n bitLength?: number\n byteSize?: number\n prefix?: boolean\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","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 { 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 './HexRegExMinMax.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\nexport type EthAddress = string & { readonly __eth_address: unique symbol }\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 { Hex } from './hex/index.ts'\nimport { hexFromHexString, isHex } from './hex/index.ts'\nimport { HexRegExMinMax } from './HexRegExMinMax.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\nexport type Hash = Hex & { readonly __hash: unique symbol }\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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B,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;;;AC7CO,SAAS,YAAY,KAAkB;AAC5C,SAAO,OAAO,iBAAiB,KAAK,EAAE,QAAQ,KAAK,CAAC,CAAC;AACvD;","names":["z","isString","isString","z","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 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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ACrD;AACF;;;AC7DA,SAAS,eAAAC,oBAAmB;AAC5B,OAAOC,QAAO;AASP,IAAM,YAAY,eAAe,IAAI,EAAE;AAEvC,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;AAKO,IAAM,SAAS,CAAC,OAAgB,YAA2B,QAAuB;AACvF,SAAO,MAAM,OAAO,EAAE,UAAU,CAAC;AACnC;AAEO,IAAM,UAAUC,GAAE,OAAO,EAC7B,YAAY,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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xylabs/hex",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"hex",
|
|
@@ -42,14 +42,14 @@
|
|
|
42
42
|
"src"
|
|
43
43
|
],
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@xylabs/typeof": "^
|
|
46
|
-
"zod": "^
|
|
45
|
+
"@xylabs/typeof": "^5.0.0",
|
|
46
|
+
"zod": "^4.0.13",
|
|
47
47
|
"zod-to-json-schema": "^3.24.6"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@xylabs/ts-scripts-yarn3": "^7.0.
|
|
51
|
-
"@xylabs/tsconfig": "^7.0.
|
|
52
|
-
"@xylabs/vitest-extended": "^
|
|
50
|
+
"@xylabs/ts-scripts-yarn3": "^7.0.2",
|
|
51
|
+
"@xylabs/tsconfig": "^7.0.2",
|
|
52
|
+
"@xylabs/vitest-extended": "^5.0.0",
|
|
53
53
|
"typescript": "^5.8.3",
|
|
54
54
|
"vitest": "^3.2.4"
|
|
55
55
|
},
|
package/src/Brand.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type Brand<T, B> = T & { [K in keyof B]: B[K] }
|
|
@@ -5,3 +5,6 @@ export const HexRegExMinMax = (minBytes = 0, maxBytes: number = (Number.MAX_SAFE
|
|
|
5
5
|
export const HexRegExMinMaxMixedCaseWithPrefix = (minBytes = 0, maxBytes: number = (Number.MAX_SAFE_INTEGER / 2)) => {
|
|
6
6
|
return new RegExp(`^0x[a-fA-F0-9]{${minBytes * 2},${maxBytes * 2}}$`)
|
|
7
7
|
}
|
|
8
|
+
|
|
9
|
+
export const HexRegEx = /^[0-9a-f]+$/
|
|
10
|
+
export const HexRegExWithPrefix = /^0x[0-9a-f]+$/
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Hex } from '../hex/index.ts'
|
|
2
|
+
import { AddressZodTransform } from './AddressZodTransform.ts'
|
|
3
|
+
import { AddressZodValidation } from './AddressZodValidation.ts'
|
|
4
|
+
|
|
5
|
+
// using true instead of unique symbol to avoid conflicts with other versions of library
|
|
6
|
+
export type Address = Hex & { readonly __address: true }
|
|
7
|
+
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
9
|
+
export namespace Address {
|
|
10
|
+
export const identify = (value: unknown): value is Address => AddressZodValidation.safeParse(value).success
|
|
11
|
+
export const cast = (value: unknown, assert: boolean = false): Address | undefined => assert
|
|
12
|
+
? AddressZodValidation.parse(value)
|
|
13
|
+
: AddressZodValidation.safeParse(value).data
|
|
14
|
+
export const from = (value: unknown, assert: boolean = false): Address | undefined => assert
|
|
15
|
+
? AddressZodTransform.parse(value)
|
|
16
|
+
: AddressZodTransform.safeParse(value).data
|
|
17
|
+
export const toString = (value: Address): string => value as string
|
|
18
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import z from 'zod'
|
|
2
|
+
|
|
3
|
+
import type { Address } from './AddressNamespace.ts'
|
|
4
|
+
import { AddressZodValidation } from './AddressZodValidation.ts'
|
|
5
|
+
|
|
6
|
+
export const AddressZodTransform = z.union([z.string(), z.bigint()])
|
|
7
|
+
.transform((value) => {
|
|
8
|
+
if (typeof value === 'bigint') {
|
|
9
|
+
return value.toString(16).padStart(40, '0')
|
|
10
|
+
}
|
|
11
|
+
if (value.startsWith('0x')) {
|
|
12
|
+
return value.slice(2)
|
|
13
|
+
}
|
|
14
|
+
return value
|
|
15
|
+
})
|
|
16
|
+
.refine(x => AddressZodValidation.safeParse(x).data)
|
|
17
|
+
.transform(x => x as Address)
|
|
18
|
+
|
|
19
|
+
export type AddressZodTransformType = z.infer<typeof AddressZodTransform>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import z from 'zod'
|
|
2
|
+
|
|
3
|
+
import { HexZod } from '../hex/index.ts'
|
|
4
|
+
import { ADDRESS_LENGTH } from './address.ts'
|
|
5
|
+
import type { Address } from './AddressNamespace.ts'
|
|
6
|
+
|
|
7
|
+
export const AddressZodValidation = z.string()
|
|
8
|
+
.refine(x => HexZod.safeParse(x))
|
|
9
|
+
.refine(x => x.length === ADDRESS_LENGTH, { error: e => new Error(`Address must have 40 characters [${e.input}]`) })
|
|
10
|
+
.transform(v => v as Address)
|
|
11
|
+
|
|
12
|
+
export type AddressZodValidationType = z.infer<typeof AddressZodValidation>
|
|
@@ -1,22 +1,29 @@
|
|
|
1
1
|
import { isObject } from '@xylabs/typeof'
|
|
2
2
|
import z from 'zod'
|
|
3
3
|
|
|
4
|
-
import type { AssertConfig } from '
|
|
5
|
-
import { assertError } from '
|
|
6
|
-
import type {
|
|
4
|
+
import type { AssertConfig } from '../assert.ts'
|
|
5
|
+
import { assertError } from '../assert.ts'
|
|
6
|
+
import type { HexConfig } from '../hex/index.ts'
|
|
7
7
|
import {
|
|
8
8
|
hexFrom, hexFromHexString, isHex,
|
|
9
|
-
} from '
|
|
10
|
-
import { HexRegExMinMax } from '
|
|
9
|
+
} from '../hex/index.ts'
|
|
10
|
+
import { HexRegExMinMax } from '../HexRegEx.ts'
|
|
11
|
+
import type { Address } from './AddressNamespace.ts'
|
|
11
12
|
|
|
12
13
|
export const AddressRegEx = HexRegExMinMax(20, 20)
|
|
13
14
|
|
|
14
|
-
export const
|
|
15
|
-
export const AddressFromStringSchema = z.string().toLowerCase().regex(AddressRegEx).transform(v => toAddress(v))
|
|
15
|
+
export const AddressToStringZod = z.string().regex(AddressRegEx)
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
/** @deprecated use AddressToStringZod */
|
|
18
|
+
export const AddressToStringSchema = AddressToStringZod
|
|
19
|
+
|
|
20
|
+
export const AddressFromStringZod = z.string().toLowerCase().regex(AddressRegEx).transform(v => toAddress(v))
|
|
21
|
+
|
|
22
|
+
/** @deprecated use AddressFromStringZod */
|
|
23
|
+
export const AddressFromStringSchema = AddressFromStringZod
|
|
18
24
|
|
|
19
25
|
export const ZERO_ADDRESS = '0000000000000000000000000000000000000000' as Address
|
|
26
|
+
export const ADDRESS_LENGTH = 40 as const
|
|
20
27
|
|
|
21
28
|
export const toAddress = (value: string | number | bigint | ArrayBufferLike, config: HexConfig = {}): Address => {
|
|
22
29
|
const { bitLength = 160, prefix = false } = config
|
|
@@ -30,13 +37,6 @@ export const isAddress = (value: unknown, config: HexConfig = {}): value is Addr
|
|
|
30
37
|
return isHex(value, { bitLength, prefix })
|
|
31
38
|
}
|
|
32
39
|
|
|
33
|
-
export const AddressZod = z.string()
|
|
34
|
-
.toLowerCase()
|
|
35
|
-
.regex(AddressRegEx, { message: 'Invalid address format' })
|
|
36
|
-
.refine(
|
|
37
|
-
isAddress,
|
|
38
|
-
)
|
|
39
|
-
|
|
40
40
|
export function asAddress(value: unknown): Address | undefined
|
|
41
41
|
export function asAddress(value: unknown, assert: AssertConfig): Address
|
|
42
42
|
export function asAddress(value: unknown, assert?: AssertConfig): Address | undefined {
|
package/src/ethAddress.ts
CHANGED
|
@@ -2,18 +2,20 @@ import z from 'zod'
|
|
|
2
2
|
|
|
3
3
|
import type { AssertConfig } from './assert.ts'
|
|
4
4
|
import { assertError } from './assert.ts'
|
|
5
|
+
import type { Brand } from './Brand.ts'
|
|
5
6
|
import type { HexConfig } from './hex/index.ts'
|
|
6
7
|
import {
|
|
7
8
|
hexFrom, hexFromHexString, isHex,
|
|
8
9
|
} from './hex/index.ts'
|
|
9
|
-
import { HexRegExMinMaxMixedCaseWithPrefix } from './
|
|
10
|
+
import { HexRegExMinMaxMixedCaseWithPrefix } from './HexRegEx.ts'
|
|
10
11
|
|
|
11
12
|
export const EthAddressRegEx = HexRegExMinMaxMixedCaseWithPrefix(20, 20)
|
|
12
13
|
|
|
13
14
|
export const EthAddressToStringSchema = z.string().regex(EthAddressRegEx)
|
|
14
15
|
export const EthAddressFromStringSchema = z.string().regex(EthAddressRegEx).transform(v => toEthAddress(v))
|
|
15
16
|
|
|
16
|
-
|
|
17
|
+
// using true instead of unique symbol to avoid conflicts with other versions of library
|
|
18
|
+
export type EthAddress = Brand<string, { readonly __eth_address: true }>
|
|
17
19
|
|
|
18
20
|
export const ETH_ZERO_ADDRESS = '0x0000000000000000000000000000000000000000' as EthAddress
|
|
19
21
|
|
package/src/hash.ts
CHANGED
|
@@ -3,9 +3,10 @@ import z from 'zod'
|
|
|
3
3
|
|
|
4
4
|
import type { AssertConfig } from './assert.ts'
|
|
5
5
|
import { assertError } from './assert.ts'
|
|
6
|
+
import type { Brand } from './Brand.ts'
|
|
6
7
|
import type { Hex } from './hex/index.ts'
|
|
7
8
|
import { hexFromHexString, isHex } from './hex/index.ts'
|
|
8
|
-
import { HexRegExMinMax } from './
|
|
9
|
+
import { HexRegExMinMax } from './HexRegEx.ts'
|
|
9
10
|
|
|
10
11
|
export const HashRegEx = HexRegExMinMax(32, 32)
|
|
11
12
|
|
|
@@ -18,7 +19,9 @@ export const isHashBitLength = (value: unknown): value is HashBitLength => {
|
|
|
18
19
|
return typeof value === 'number' && HashBitLength.includes(value as HashBitLength)
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
|
|
22
|
+
// using true instead of unique symbol to avoid conflicts with other versions of library
|
|
23
|
+
export type Hash = Brand<Hex, { readonly __hash: true }>
|
|
24
|
+
|
|
22
25
|
export const isHash = (value: unknown, bitLength: HashBitLength = 256): value is Hash => {
|
|
23
26
|
return isHex(value, { bitLength })
|
|
24
27
|
}
|
package/src/hex/index.ts
CHANGED
package/src/hex/is.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { HexRegEx, HexRegExWithPrefix } from '../HexRegEx.ts'
|
|
1
2
|
import type { Hex, HexConfig } from './model.ts'
|
|
2
3
|
import { bitsToNibbles } from './nibble.ts'
|
|
3
|
-
import { hexRegex, hexRegexWithPrefix } from './regex.ts'
|
|
4
4
|
|
|
5
5
|
export const isHex = (value: unknown, config?: HexConfig): value is Hex => {
|
|
6
6
|
// Is it a string?
|
|
@@ -12,5 +12,5 @@ export const isHex = (value: unknown, config?: HexConfig): value is Hex => {
|
|
|
12
12
|
if (config?.bitLength !== undefined && valueCharLength !== bitsToNibbles(config?.bitLength)) return false
|
|
13
13
|
|
|
14
14
|
// Does it only has hex values?
|
|
15
|
-
return config?.prefix ?
|
|
15
|
+
return config?.prefix ? HexRegExWithPrefix.test(value) : HexRegEx.test(value)
|
|
16
16
|
}
|
package/src/hex/model.ts
CHANGED
|
@@ -1,19 +1,13 @@
|
|
|
1
1
|
import z from 'zod'
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import type { Brand } from '../Brand.ts'
|
|
4
|
+
import { HexRegEx } from '../HexRegEx.ts'
|
|
5
5
|
|
|
6
|
-
//
|
|
7
|
-
export type Hex = Lowercase<string
|
|
8
|
-
|
|
9
|
-
export const HexRegEx = HexRegExMinMax(1, Number.MAX_SAFE_INTEGER)
|
|
6
|
+
// using true instead of unique symbol to avoid conflicts with other versions of library
|
|
7
|
+
export type Hex = Brand<Lowercase<string>, { readonly __hex: true }>
|
|
10
8
|
|
|
11
9
|
export const HexZod = z.string()
|
|
12
|
-
.
|
|
13
|
-
.regex(HexRegEx, { message: 'Invalid hex format' })
|
|
14
|
-
.refine(
|
|
15
|
-
isHex,
|
|
16
|
-
)
|
|
10
|
+
.regex(HexRegEx, { message: 'Invalid hex format' }).transform(x => x as Hex)
|
|
17
11
|
|
|
18
12
|
/** Configuration of validation and output format */
|
|
19
13
|
export interface HexConfig {
|
|
@@ -21,3 +15,5 @@ export interface HexConfig {
|
|
|
21
15
|
byteSize?: number
|
|
22
16
|
prefix?: boolean
|
|
23
17
|
}
|
|
18
|
+
|
|
19
|
+
export type HexZodType = z.infer<typeof HexZod>
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
export * from './address.ts'
|
|
1
|
+
export * from './address/index.ts'
|
|
2
2
|
export * from './assert.ts'
|
|
3
|
+
export * from './Brand.ts'
|
|
3
4
|
export * from './ethAddress.ts'
|
|
4
5
|
export * from './hash.ts'
|
|
5
6
|
export * from './hex/index.ts'
|
|
7
|
+
export * from './HexRegEx.ts'
|
|
6
8
|
export * from './hexToBigInt.ts'
|
package/src/spec/address.spec.ts
CHANGED
|
@@ -4,7 +4,9 @@ import {
|
|
|
4
4
|
describe, expect, test,
|
|
5
5
|
} from 'vitest'
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
Address, asAddress, isAddress,
|
|
9
|
+
} from '../address/index.ts'
|
|
8
10
|
|
|
9
11
|
describe('address', () => {
|
|
10
12
|
test('isAddress', () => {
|
|
@@ -23,3 +25,51 @@ describe('address', () => {
|
|
|
23
25
|
expect(asAddress('000000000000000000000000000000000000000a', true)).toBe('000000000000000000000000000000000000000a')
|
|
24
26
|
})
|
|
25
27
|
})
|
|
28
|
+
|
|
29
|
+
describe('address [zod]', () => {
|
|
30
|
+
test('identify', () => {
|
|
31
|
+
expect(Address.identify(true)).toBeFalse()
|
|
32
|
+
expect(Address.identify({})).toBeFalse()
|
|
33
|
+
expect(Address.identify('NotHex')).toBeFalse()
|
|
34
|
+
expect(Address.identify('deadbeef')).toBeFalse()
|
|
35
|
+
expect(Address.identify('0xdeadbeef')).toBeFalse()
|
|
36
|
+
expect(Address.identify('deadbeefdeadbeefdeadbeefdeadbeefdeadbeef')).toBeTrue()
|
|
37
|
+
expect(Address.identify('0xdeadbeefdeadbeefdeadxxxxdeadbeefdeadbeef')).toBeFalse()
|
|
38
|
+
})
|
|
39
|
+
test('cast', () => {
|
|
40
|
+
expect(Address.cast('0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef')).toBe(undefined)
|
|
41
|
+
expect(Address.cast('deadbeefdeadbeefdeadbeefdeadbeefdeadbeef')).toBe('deadbeefdeadbeefdeadbeefdeadbeefdeadbeef')
|
|
42
|
+
expect(Address.cast('0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef', false)).toBe(undefined)
|
|
43
|
+
expect(Address.cast('000000000000000000000000000000000000000a', true)).toBe('000000000000000000000000000000000000000a')
|
|
44
|
+
expect(Address.cast('0x000000000000000000000000000000000000000a', false)).toBe(undefined)
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
test('from', () => {
|
|
48
|
+
expect(Address.from('0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef')).toBe('deadbeefdeadbeefdeadbeefdeadbeefdeadbeef')
|
|
49
|
+
expect(Address.from('deadbeefdeadbeefdeadbeefdeadbeefdeadbeef')).toBe('deadbeefdeadbeefdeadbeefdeadbeefdeadbeef')
|
|
50
|
+
expect(Address.from('0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef', true)).toBe('deadbeefdeadbeefdeadbeefdeadbeefdeadbeef')
|
|
51
|
+
expect(Address.from('000000000000000000000000000000000000000a', true)).toBe('000000000000000000000000000000000000000a')
|
|
52
|
+
expect(Address.from('0x000000000000000000000000000000000000000a', true)).toBe('000000000000000000000000000000000000000a')
|
|
53
|
+
expect(Address.from(10n, true)).toBe('000000000000000000000000000000000000000a')
|
|
54
|
+
expect(Address.from(
|
|
55
|
+
1_234_567_890_123_456_789_012_345_678_901_234_567_890_123_456_789_012_345_678_901_234_567_890n,
|
|
56
|
+
false,
|
|
57
|
+
)).toBe(undefined)
|
|
58
|
+
expect(Address.from(
|
|
59
|
+
1_234_567_890_123_456_789_012_345_678_901_234_567n,
|
|
60
|
+
true,
|
|
61
|
+
)).toBe('0000000000edc4e57e669eb52d3a8e6e7c9f4b87')
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
test('from [assert]', () => {
|
|
65
|
+
try {
|
|
66
|
+
Address.from(
|
|
67
|
+
1_234_567_890_123_456_789_012_345_678_901_234_567_890_123_456_789_012_345_678_901_234_567_890n,
|
|
68
|
+
true,
|
|
69
|
+
)
|
|
70
|
+
expect(false).toBeTrue() // should not reach here
|
|
71
|
+
} catch (error) {
|
|
72
|
+
expect(error).toBeInstanceOf(Error)
|
|
73
|
+
}
|
|
74
|
+
})
|
|
75
|
+
})
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"HexRegExMinMax.d.ts","sourceRoot":"","sources":["../../src/HexRegExMinMax.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,GAAI,iBAAY,EAAE,WAAU,MAAsC,WAE5F,CAAA;AAED,eAAO,MAAM,iCAAiC,GAAI,iBAAY,EAAE,WAAU,MAAsC,WAE/G,CAAA"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import z from 'zod';
|
|
2
|
-
import type { AssertConfig } from './assert.ts';
|
|
3
|
-
import type { Hex, HexConfig } from './hex/index.ts';
|
|
4
|
-
export declare const AddressRegEx: RegExp;
|
|
5
|
-
export declare const AddressToStringSchema: z.ZodString;
|
|
6
|
-
export declare const AddressFromStringSchema: z.ZodEffects<z.ZodString, Address, string>;
|
|
7
|
-
export type Address = Hex & {
|
|
8
|
-
readonly __address: unique symbol;
|
|
9
|
-
};
|
|
10
|
-
export declare const ZERO_ADDRESS: Address;
|
|
11
|
-
export declare const toAddress: (value: string | number | bigint | ArrayBufferLike, config?: HexConfig) => Address;
|
|
12
|
-
export declare const isAddress: (value: unknown, config?: HexConfig) => value is Address;
|
|
13
|
-
export declare const AddressZod: z.ZodEffects<z.ZodString, Address, string>;
|
|
14
|
-
export declare function asAddress(value: unknown): Address | undefined;
|
|
15
|
-
export declare function asAddress(value: unknown, assert: AssertConfig): Address;
|
|
16
|
-
//# sourceMappingURL=address.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../../src/address.ts"],"names":[],"mappings":"AACA,OAAO,CAAC,MAAM,KAAK,CAAA;AAEnB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE/C,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAMpD,eAAO,MAAM,YAAY,QAAyB,CAAA;AAElD,eAAO,MAAM,qBAAqB,aAA+C,CAAA;AACjF,eAAO,MAAM,uBAAuB,4CAA4E,CAAA;AAEhH,MAAM,MAAM,OAAO,GAAG,GAAG,GAAG;IAAE,QAAQ,CAAC,SAAS,EAAE,OAAO,MAAM,CAAA;CAAE,CAAA;AAEjE,eAAO,MAAM,YAAY,EAAiD,OAAO,CAAA;AAEjF,eAAO,MAAM,SAAS,GAAI,OAAO,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,eAAe,EAAE,SAAQ,SAAc,KAAG,OAKrG,CAAA;AAED,eAAO,MAAM,SAAS,GAAI,OAAO,OAAO,EAAE,SAAQ,SAAc,KAAG,KAAK,IAAI,OAG3E,CAAA;AAED,eAAO,MAAM,UAAU,4CAKpB,CAAA;AAEH,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,GAAG,SAAS,CAAA;AAC9D,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,GAAG,OAAO,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"regex.d.ts","sourceRoot":"","sources":["../../../src/hex/regex.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,QAAQ,QAAgB,CAAA;AACrC,eAAO,MAAM,kBAAkB,QAAiB,CAAA"}
|
package/src/hex/regex.ts
DELETED