@xylabs/hex 5.0.4 → 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} +4 -5
- 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 +4 -2
- 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 +4 -4
- 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/{model.ts → hex.ts} +3 -6
- 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
|
@@ -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;AAKnB,MAAM,MAAM,GAAG,GAAG,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE;IAAE,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAA;CAAE,CAAC,CAAA;AAEpE,eAAO,MAAM,MAAM,qDAC2D,CAAA;AAE9E,oDAAoD;AACpD,MAAM,WAAW,SAAS;IACxB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB;AAED,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,MAAM,CAAC,CAAA"}
|
|
@@ -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
|
-
}
|