@xylabs/hex 5.0.5 → 5.0.6
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 +8 -0
- package/dist/neutral/address/AddressTransformZod.d.ts.map +1 -0
- package/dist/neutral/address/AddressValidationZod.d.ts +8 -0
- package/dist/neutral/address/AddressValidationZod.d.ts.map +1 -0
- package/dist/neutral/address/address.d.ts +7 -22
- package/dist/neutral/address/address.d.ts.map +1 -1
- package/dist/neutral/address/addressDeprecated.d.ts +18 -0
- package/dist/neutral/address/addressDeprecated.d.ts.map +1 -0
- package/dist/neutral/address/as.d.ts +7 -0
- package/dist/neutral/address/as.d.ts.map +1 -0
- package/dist/neutral/address/index.d.ts +6 -2
- package/dist/neutral/address/index.d.ts.map +1 -1
- package/dist/neutral/address/is.d.ts +6 -0
- package/dist/neutral/address/is.d.ts.map +1 -0
- package/dist/neutral/address/to.d.ts +6 -0
- package/dist/neutral/address/to.d.ts.map +1 -0
- package/dist/neutral/ethAddress.d.ts +4 -0
- package/dist/neutral/ethAddress.d.ts.map +1 -1
- package/dist/neutral/hash/as.d.ts +5 -0
- package/dist/neutral/hash/as.d.ts.map +1 -0
- package/dist/neutral/hash/hash.d.ts +14 -0
- package/dist/neutral/hash/hash.d.ts.map +1 -0
- package/dist/neutral/hash/index.d.ts +4 -0
- package/dist/neutral/hash/index.d.ts.map +1 -0
- package/dist/neutral/hash/is.d.ts +3 -0
- package/dist/neutral/hash/is.d.ts.map +1 -0
- package/dist/neutral/hex/as.d.ts +1 -1
- package/dist/neutral/hex/as.d.ts.map +1 -1
- package/dist/neutral/hex/from/from.d.ts +1 -1
- package/dist/neutral/hex/from/from.d.ts.map +1 -1
- package/dist/neutral/hex/from/fromArrayBuffer.d.ts +1 -1
- package/dist/neutral/hex/from/fromArrayBuffer.d.ts.map +1 -1
- package/dist/neutral/hex/from/fromBigInt.d.ts +1 -1
- package/dist/neutral/hex/from/fromBigInt.d.ts.map +1 -1
- package/dist/neutral/hex/from/fromHexString.d.ts +1 -1
- package/dist/neutral/hex/from/fromHexString.d.ts.map +1 -1
- package/dist/neutral/hex/from/fromNumber.d.ts +1 -1
- package/dist/neutral/hex/from/fromNumber.d.ts.map +1 -1
- package/dist/neutral/hex/{model.d.ts → hex.d.ts} +1 -1
- package/dist/neutral/hex/hex.d.ts.map +1 -0
- package/dist/neutral/hex/index.d.ts +1 -1
- package/dist/neutral/hex/index.d.ts.map +1 -1
- package/dist/neutral/hex/is.d.ts +1 -1
- package/dist/neutral/hex/is.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-internal.d.ts +1 -1
- package/dist/neutral/index-internal.d.ts.map +1 -1
- package/dist/neutral/index-internal.mjs +94 -62
- package/dist/neutral/index-internal.mjs.map +1 -1
- package/dist/neutral/index.mjs +94 -62
- package/dist/neutral/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/address/AddressTransformZod.ts +26 -0
- package/src/address/{AddressZodValidation.ts → AddressValidationZod.ts} +2 -2
- package/src/address/address.ts +6 -76
- package/src/address/addressDeprecated.ts +18 -0
- package/src/address/as.ts +37 -0
- package/src/address/index.ts +6 -2
- package/src/address/is.ts +14 -0
- package/src/address/to.ts +18 -0
- package/src/ethAddress.ts +9 -2
- package/src/hash/as.ts +24 -0
- package/src/hash/hash.ts +23 -0
- package/src/hash/index.ts +3 -0
- package/src/hash/is.ts +6 -0
- package/src/hex/as.ts +1 -1
- package/src/hex/from/from.ts +1 -1
- package/src/hex/from/fromArrayBuffer.ts +1 -1
- package/src/hex/from/fromBigInt.ts +1 -1
- package/src/hex/from/fromHexString.ts +1 -1
- package/src/hex/from/fromNumber.ts +1 -1
- package/src/hex/index.ts +1 -1
- package/src/hex/is.ts +1 -1
- package/src/hex/to.ts +1 -1
- package/src/index-internal.ts +1 -1
- package/src/spec/hash.spec.ts +1 -1
- package/dist/neutral/address/AddressZodTransform.d.ts +0 -5
- package/dist/neutral/address/AddressZodTransform.d.ts.map +0 -1
- package/dist/neutral/address/AddressZodValidation.d.ts +0 -5
- package/dist/neutral/address/AddressZodValidation.d.ts.map +0 -1
- package/dist/neutral/hash.d.ts +0 -17
- package/dist/neutral/hash.d.ts.map +0 -1
- package/dist/neutral/hex/model.d.ts.map +0 -1
- package/src/address/AddressZodTransform.ts +0 -19
- package/src/hash.ts +0 -51
- /package/src/hex/{model.ts → hex.ts} +0 -0
package/src/address/address.ts
CHANGED
|
@@ -1,85 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Brand } from '@xylabs/typeof'
|
|
2
2
|
import z from 'zod'
|
|
3
3
|
|
|
4
|
-
import type {
|
|
5
|
-
import { assertError } from '../assert.ts'
|
|
6
|
-
import type { Hex, HexConfig } from '../hex/index.ts'
|
|
7
|
-
import {
|
|
8
|
-
hexFrom, hexFromHexString, isHex,
|
|
9
|
-
} from '../hex/index.ts'
|
|
4
|
+
import type { Hex } from '../hex/index.ts'
|
|
10
5
|
import { HexRegExMinMax } from '../HexRegEx.ts'
|
|
11
|
-
import { AddressZodTransform } from './AddressZodTransform.ts'
|
|
12
|
-
import { AddressZodValidation } from './AddressZodValidation.ts'
|
|
13
|
-
|
|
14
|
-
// using true instead of unique symbol to avoid conflicts with other versions of library
|
|
15
|
-
export type Address = Hex & {
|
|
16
|
-
readonly __address: true
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const AddressRegEx = HexRegExMinMax(20, 20)
|
|
20
|
-
|
|
21
|
-
export const AddressToStringZod = z.string().regex(AddressRegEx)
|
|
22
|
-
|
|
23
|
-
/** @deprecated use AddressToStringZod */
|
|
24
|
-
export const AddressToStringSchema = AddressToStringZod
|
|
25
|
-
|
|
26
|
-
export const AddressFromStringZod = z.string().toLowerCase().regex(AddressRegEx).transform(v => toAddress(v))
|
|
27
|
-
|
|
28
|
-
/** @deprecated use AddressFromStringZod */
|
|
29
|
-
export const AddressFromStringSchema = AddressFromStringZod
|
|
30
6
|
|
|
31
7
|
export const ZERO_ADDRESS = '0000000000000000000000000000000000000000' as Address
|
|
32
8
|
export const ADDRESS_LENGTH = 40 as const
|
|
33
9
|
|
|
34
|
-
export const
|
|
35
|
-
const { bitLength = 160, prefix = false } = config
|
|
36
|
-
return hexFrom(value, {
|
|
37
|
-
bitLength, prefix, ...config,
|
|
38
|
-
}) as Address
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export const isAddress = (value: unknown, config: HexConfig = {}): value is Address => {
|
|
42
|
-
const { bitLength = 160, prefix = false } = config
|
|
43
|
-
return isHex(value, { bitLength, prefix })
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function asAddress(value: unknown): Address | undefined
|
|
47
|
-
export function asAddress(value: unknown, assert: AssertConfig): Address
|
|
48
|
-
export function asAddress(value: unknown, assert?: AssertConfig): Address | undefined {
|
|
49
|
-
try {
|
|
50
|
-
let stringValue: string | undefined = undefined
|
|
51
|
-
|
|
52
|
-
switch (typeof value) {
|
|
53
|
-
case 'string': {
|
|
54
|
-
stringValue = hexFromHexString(value, { prefix: false })
|
|
55
|
-
break
|
|
56
|
-
}
|
|
57
|
-
default: {
|
|
58
|
-
return isObject(assert) ? assertError(value, assert, `Unsupported type [${typeof value}]`) : undefined
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return isAddress(stringValue) ? stringValue : assertError(value, assert, `Value is not an Address [${value}]`)
|
|
62
|
-
} catch (ex) {
|
|
63
|
-
const error = ex as Error
|
|
64
|
-
return assertError(undefined, assert, error.message)
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/** @alpha */
|
|
69
|
-
export function isAddressV2(value: unknown): value is Address {
|
|
70
|
-
return AddressZodValidation.safeParse(value).success
|
|
71
|
-
}
|
|
10
|
+
export const AddressRegEx = HexRegExMinMax(ADDRESS_LENGTH / 2, ADDRESS_LENGTH / 2)
|
|
72
11
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return assert
|
|
76
|
-
? AddressZodValidation.parse(value)
|
|
77
|
-
: AddressZodValidation.safeParse(value).data
|
|
78
|
-
}
|
|
12
|
+
export const AddressZod = z.string()
|
|
13
|
+
.regex(AddressRegEx, { message: 'Invalid hex format' }) as unknown as z.ZodType<Brand<Hex, { readonly __address: true }>>
|
|
79
14
|
|
|
80
|
-
|
|
81
|
-
export function toAddressV2(value: unknown, assert: boolean = false): Address | undefined {
|
|
82
|
-
return assert
|
|
83
|
-
? AddressZodTransform.parse(value)
|
|
84
|
-
: AddressZodTransform.safeParse(value).data
|
|
85
|
-
}
|
|
15
|
+
export type Address = z.infer<typeof AddressZod>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import z from 'zod'
|
|
2
|
+
|
|
3
|
+
import { AddressRegEx } from './address.ts'
|
|
4
|
+
import { toAddress } from './to.ts'
|
|
5
|
+
|
|
6
|
+
/** @deprecated use AddressZod */
|
|
7
|
+
export const AddressToStringZod = z.string().regex(AddressRegEx)
|
|
8
|
+
|
|
9
|
+
/** @deprecated use AddressZod */
|
|
10
|
+
// eslint-disable-next-line sonarjs/deprecation
|
|
11
|
+
export const AddressToStringSchema = AddressToStringZod
|
|
12
|
+
|
|
13
|
+
/** @deprecated use AddressZod */
|
|
14
|
+
export const AddressFromStringZod = z.string().toLowerCase().regex(AddressRegEx).transform(v => toAddress(v))
|
|
15
|
+
|
|
16
|
+
/** @deprecated use AddressZod */
|
|
17
|
+
// eslint-disable-next-line sonarjs/deprecation
|
|
18
|
+
export const AddressFromStringSchema = AddressFromStringZod
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { isObject } from '@xylabs/typeof'
|
|
2
|
+
|
|
3
|
+
import type { AssertConfig } from '../assert.ts'
|
|
4
|
+
import { assertError } from '../assert.ts'
|
|
5
|
+
import { hexFromHexString } from '../hex/index.ts'
|
|
6
|
+
import type { Address } from './address.ts'
|
|
7
|
+
import { AddressValidationZod } from './AddressValidationZod.ts'
|
|
8
|
+
import { isAddress } from './is.ts'
|
|
9
|
+
|
|
10
|
+
export function asAddress(value: unknown): Address | undefined
|
|
11
|
+
export function asAddress(value: unknown, assert: AssertConfig): Address
|
|
12
|
+
export function asAddress(value: unknown, assert?: AssertConfig): Address | undefined {
|
|
13
|
+
try {
|
|
14
|
+
let stringValue: string | undefined = undefined
|
|
15
|
+
|
|
16
|
+
switch (typeof value) {
|
|
17
|
+
case 'string': {
|
|
18
|
+
stringValue = hexFromHexString(value, { prefix: false })
|
|
19
|
+
break
|
|
20
|
+
}
|
|
21
|
+
default: {
|
|
22
|
+
return isObject(assert) ? assertError(value, assert, `Unsupported type [${typeof value}]`) : undefined
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return isAddress(stringValue) ? stringValue : assertError(value, assert, `Value is not an Address [${value}]`)
|
|
26
|
+
} catch (ex) {
|
|
27
|
+
const error = ex as Error
|
|
28
|
+
return assertError(undefined, assert, error.message)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** @alpha */
|
|
33
|
+
export function asAddressV2(value: unknown, assert: boolean = false): Address | undefined {
|
|
34
|
+
return assert
|
|
35
|
+
? AddressValidationZod.parse(value)
|
|
36
|
+
: AddressValidationZod.safeParse(value).data
|
|
37
|
+
}
|
package/src/address/index.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
export * from './address.ts'
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
2
|
+
export * from './addressDeprecated.ts'
|
|
3
|
+
export * from './AddressTransformZod.ts'
|
|
4
|
+
export * from './AddressValidationZod.ts'
|
|
5
|
+
export * from './as.ts'
|
|
6
|
+
export * from './is.ts'
|
|
7
|
+
export * from './to.ts'
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { HexConfig } from '../hex/index.ts'
|
|
2
|
+
import { isHex } from '../hex/index.ts'
|
|
3
|
+
import type { Address } from './address.ts'
|
|
4
|
+
import { AddressValidationZod } from './AddressValidationZod.ts'
|
|
5
|
+
|
|
6
|
+
export const isAddress = (value: unknown, config: HexConfig = {}): value is Address => {
|
|
7
|
+
const { bitLength = 160, prefix = false } = config
|
|
8
|
+
return isHex(value, { bitLength, prefix })
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** @alpha */
|
|
12
|
+
export function isAddressV2(value: unknown): value is Address {
|
|
13
|
+
return AddressValidationZod.safeParse(value).success
|
|
14
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { HexConfig } from '../hex/index.ts'
|
|
2
|
+
import { hexFrom } from '../hex/index.ts'
|
|
3
|
+
import type { Address } from './address.ts'
|
|
4
|
+
import { AddressTransformZod } from './AddressTransformZod.ts'
|
|
5
|
+
|
|
6
|
+
export const toAddress = (value: string | number | bigint | ArrayBufferLike, config: HexConfig = {}): Address => {
|
|
7
|
+
const { bitLength = 160, prefix = false } = config
|
|
8
|
+
return hexFrom(value, {
|
|
9
|
+
bitLength, prefix, ...config,
|
|
10
|
+
}) as unknown as Address
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** @alpha */
|
|
14
|
+
export function toAddressV2(value: unknown, assert: boolean = false): Address | undefined {
|
|
15
|
+
return assert
|
|
16
|
+
? AddressTransformZod.parse(value)
|
|
17
|
+
: AddressTransformZod.safeParse(value).data
|
|
18
|
+
}
|
package/src/ethAddress.ts
CHANGED
|
@@ -11,8 +11,15 @@ import { HexRegExMinMaxMixedCaseWithPrefix } from './HexRegEx.ts'
|
|
|
11
11
|
|
|
12
12
|
export const EthAddressRegEx = HexRegExMinMaxMixedCaseWithPrefix(20, 20)
|
|
13
13
|
|
|
14
|
-
export const
|
|
15
|
-
|
|
14
|
+
export const EthAddressToStringZod = z.string().regex(EthAddressRegEx)
|
|
15
|
+
|
|
16
|
+
/** @deprecated use EthAddressToStringZod */
|
|
17
|
+
export const EthAddressToStringSchema = EthAddressToStringZod
|
|
18
|
+
|
|
19
|
+
export const EthAddressFromStringZod = z.string().regex(EthAddressRegEx).transform(v => toEthAddress(v))
|
|
20
|
+
|
|
21
|
+
/** @deprecated use EthAddressFromStringZod */
|
|
22
|
+
export const EthAddressFromStringSchema = EthAddressFromStringZod
|
|
16
23
|
|
|
17
24
|
// using true instead of unique symbol to avoid conflicts with other versions of library
|
|
18
25
|
export type EthAddress = Brand<string, { readonly __eth_address: true }>
|
package/src/hash/as.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { isUndefined } from '@xylabs/typeof'
|
|
2
|
+
|
|
3
|
+
import type { AssertConfig } from '../assert.ts'
|
|
4
|
+
import { assertError } from '../assert.ts'
|
|
5
|
+
import { hexFromHexString } from '../hex/index.ts'
|
|
6
|
+
import { type Hash } from './hash.ts'
|
|
7
|
+
import { isHash } from './is.ts'
|
|
8
|
+
|
|
9
|
+
export function asHash(value: unknown): Hash | undefined
|
|
10
|
+
export function asHash(value: unknown, assert: AssertConfig): Hash
|
|
11
|
+
export function asHash(value: unknown, assert?: AssertConfig): Hash | undefined {
|
|
12
|
+
let stringValue: string | undefined = undefined
|
|
13
|
+
|
|
14
|
+
switch (typeof value) {
|
|
15
|
+
case 'string': {
|
|
16
|
+
stringValue = hexFromHexString(value)
|
|
17
|
+
break
|
|
18
|
+
}
|
|
19
|
+
default: {
|
|
20
|
+
return isUndefined(assert) ? undefined : assertError(value, assert, `Unsupported type [${typeof value}]`)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return isHash(stringValue) ? stringValue : assertError(value, assert, `Value is not a Hash [${value}]`)
|
|
24
|
+
}
|
package/src/hash/hash.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Brand } from '@xylabs/typeof'
|
|
2
|
+
import z from 'zod'
|
|
3
|
+
|
|
4
|
+
import type { Hex } from '../hex/index.ts'
|
|
5
|
+
import { HexRegExMinMax } from '../HexRegEx.ts'
|
|
6
|
+
|
|
7
|
+
export const HASH_LENGTH = 32 as const
|
|
8
|
+
|
|
9
|
+
export const HashRegEx = HexRegExMinMax(HASH_LENGTH, HASH_LENGTH)
|
|
10
|
+
|
|
11
|
+
export const ZERO_HASH = '0000000000000000000000000000000000000000000000000000000000000000' as Hash
|
|
12
|
+
|
|
13
|
+
export type HashBitLength = 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096
|
|
14
|
+
export const HashBitLength: HashBitLength[] = [32, 64, 128, 256, 512, 1024, 2048, 4096]
|
|
15
|
+
|
|
16
|
+
export const isHashBitLength = (value: unknown): value is HashBitLength => {
|
|
17
|
+
return typeof value === 'number' && HashBitLength.includes(value as HashBitLength)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const HashZod = z.string()
|
|
21
|
+
.regex(HashRegEx, { message: 'Invalid hex format' }) as unknown as z.ZodType<Brand<Hex, { readonly __hash: true }>>
|
|
22
|
+
|
|
23
|
+
export type Hash = z.infer<typeof HashZod>
|
package/src/hash/is.ts
ADDED
package/src/hex/as.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { AssertConfig } from '../assert.ts'
|
|
2
2
|
import { assertError } from '../assert.ts'
|
|
3
3
|
import { hexFromHexString } from './from/index.ts'
|
|
4
|
+
import type { Hex } from './hex.ts'
|
|
4
5
|
import { isHex } from './is.ts'
|
|
5
|
-
import type { Hex } from './model.ts'
|
|
6
6
|
|
|
7
7
|
export function asHex(value: unknown): Hex | undefined
|
|
8
8
|
export function asHex(value: unknown, assert: AssertConfig): Hex
|
package/src/hex/from/from.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isNumber } from '@xylabs/typeof'
|
|
2
2
|
|
|
3
|
+
import type { Hex, HexConfig } from '../hex.ts'
|
|
3
4
|
import { isHex } from '../is.ts'
|
|
4
|
-
import type { Hex, HexConfig } from '../model.ts'
|
|
5
5
|
import { bitsToNibbles } from '../nibble.ts'
|
|
6
6
|
|
|
7
7
|
export const hexFromHexString = (value: string, config: HexConfig = {}): Hex => {
|
package/src/hex/index.ts
CHANGED
package/src/hex/is.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HexRegEx, HexRegExWithPrefix } from '../HexRegEx.ts'
|
|
2
|
-
import type { Hex, HexConfig } from './
|
|
2
|
+
import type { Hex, HexConfig } from './hex.ts'
|
|
3
3
|
import { bitsToNibbles } from './nibble.ts'
|
|
4
4
|
|
|
5
5
|
export const isHex = (value: unknown, config?: HexConfig): value is Hex => {
|
package/src/hex/to.ts
CHANGED
package/src/index-internal.ts
CHANGED
package/src/spec/hash.spec.ts
CHANGED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import z from 'zod';
|
|
2
|
-
import type { Address } from './address.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
|
|
@@ -1 +0,0 @@
|
|
|
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,cAAc,CAAA;AAG3C,eAAO,MAAM,mBAAmB,iJAWD,CAAA;AAE/B,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAA"}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import z from 'zod';
|
|
2
|
-
import type { Address } from './address.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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AddressZodValidation.d.ts","sourceRoot":"","sources":["../../../src/address/AddressZodValidation.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAA;AAGnB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAG3C,eAAO,MAAM,oBAAoB,yDAGF,CAAA;AAE/B,MAAM,MAAM,wBAAwB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAA"}
|
package/dist/neutral/hash.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { Brand } from '@xylabs/typeof';
|
|
2
|
-
import z from 'zod';
|
|
3
|
-
import type { AssertConfig } from './assert.ts';
|
|
4
|
-
import type { Hex } from './hex/index.ts';
|
|
5
|
-
export declare const HashRegEx: RegExp;
|
|
6
|
-
export declare const ZERO_HASH: Hash;
|
|
7
|
-
export type HashBitLength = 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096;
|
|
8
|
-
export declare const HashBitLength: HashBitLength[];
|
|
9
|
-
export declare const isHashBitLength: (value: unknown) => value is HashBitLength;
|
|
10
|
-
export type Hash = Brand<Hex, {
|
|
11
|
-
readonly __hash: true;
|
|
12
|
-
}>;
|
|
13
|
-
export declare const isHash: (value: unknown, bitLength?: HashBitLength) => value is Hash;
|
|
14
|
-
export declare const HashZod: z.ZodString;
|
|
15
|
-
export declare function asHash(value: unknown): Hash | undefined;
|
|
16
|
-
export declare function asHash(value: unknown, assert: AssertConfig): Hash;
|
|
17
|
-
//# sourceMappingURL=hash.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/hash.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAE3C,OAAO,CAAC,MAAM,KAAK,CAAA;AAEnB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE/C,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAA;AAIzC,eAAO,MAAM,SAAS,QAAyB,CAAA;AAE/C,eAAO,MAAM,SAAS,EAAyE,IAAI,CAAA;AAEnG,MAAM,MAAM,aAAa,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAA;AAC1E,eAAO,MAAM,aAAa,EAAE,aAAa,EAA8C,CAAA;AAEvF,eAAO,MAAM,eAAe,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,aAEzD,CAAA;AAGD,MAAM,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,EAAE;IAAE,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAA;CAAE,CAAC,CAAA;AAExD,eAAO,MAAM,MAAM,GAAI,OAAO,OAAO,EAAE,YAAW,aAAmB,KAAG,KAAK,IAAI,IAEhF,CAAA;AAED,eAAO,MAAM,OAAO,aAKjB,CAAA;AAEH,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,GAAG,SAAS,CAAA;AACxD,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,GAAG,IAAI,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../src/hex/model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,CAAC,MAAM,KAAK,CAAA;AAInB,eAAO,MAAM,MAAM,EACiD,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE;IAAE,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAA;CAAE,CAAC,CAAC,CAAA;AAEjI,MAAM,MAAM,GAAG,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,MAAM,CAAC,CAAA;AAExC,oDAAoD;AACpD,MAAM,WAAW,SAAS;IACxB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import z from 'zod'
|
|
2
|
-
|
|
3
|
-
import type { Address } from './address.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>
|
package/src/hash.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import type { Brand } from '@xylabs/typeof'
|
|
2
|
-
import { isUndefined } from '@xylabs/typeof'
|
|
3
|
-
import z from 'zod'
|
|
4
|
-
|
|
5
|
-
import type { AssertConfig } from './assert.ts'
|
|
6
|
-
import { assertError } from './assert.ts'
|
|
7
|
-
import type { Hex } from './hex/index.ts'
|
|
8
|
-
import { hexFromHexString, isHex } from './hex/index.ts'
|
|
9
|
-
import { HexRegExMinMax } from './HexRegEx.ts'
|
|
10
|
-
|
|
11
|
-
export const HashRegEx = HexRegExMinMax(32, 32)
|
|
12
|
-
|
|
13
|
-
export const ZERO_HASH = '0000000000000000000000000000000000000000000000000000000000000000' as Hash
|
|
14
|
-
|
|
15
|
-
export type HashBitLength = 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096
|
|
16
|
-
export const HashBitLength: HashBitLength[] = [32, 64, 128, 256, 512, 1024, 2048, 4096]
|
|
17
|
-
|
|
18
|
-
export const isHashBitLength = (value: unknown): value is HashBitLength => {
|
|
19
|
-
return typeof value === 'number' && HashBitLength.includes(value as HashBitLength)
|
|
20
|
-
}
|
|
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
|
-
|
|
25
|
-
export const isHash = (value: unknown, bitLength: HashBitLength = 256): value is Hash => {
|
|
26
|
-
return isHex(value, { bitLength })
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export const HashZod = z.string()
|
|
30
|
-
.toLowerCase()
|
|
31
|
-
.regex(HashRegEx, { message: 'Invalid hash format' })
|
|
32
|
-
.refine(
|
|
33
|
-
isHash,
|
|
34
|
-
)
|
|
35
|
-
|
|
36
|
-
export function asHash(value: unknown): Hash | undefined
|
|
37
|
-
export function asHash(value: unknown, assert: AssertConfig): Hash
|
|
38
|
-
export function asHash(value: unknown, assert?: AssertConfig): Hash | undefined {
|
|
39
|
-
let stringValue: string | undefined = undefined
|
|
40
|
-
|
|
41
|
-
switch (typeof value) {
|
|
42
|
-
case 'string': {
|
|
43
|
-
stringValue = hexFromHexString(value)
|
|
44
|
-
break
|
|
45
|
-
}
|
|
46
|
-
default: {
|
|
47
|
-
return isUndefined(assert) ? undefined : assertError(value, assert, `Unsupported type [${typeof value}]`)
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return isHash(stringValue) ? stringValue : assertError(value, assert, `Value is not a Hash [${value}]`)
|
|
51
|
-
}
|
|
File without changes
|