@xylabs/hex 3.5.0 → 3.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/address.d.cts +1 -1
- package/dist/browser/address.d.cts.map +1 -1
- package/dist/browser/address.d.mts +1 -1
- package/dist/browser/address.d.mts.map +1 -1
- package/dist/browser/address.d.ts +1 -1
- package/dist/browser/address.d.ts.map +1 -1
- package/dist/browser/hash.d.cts +1 -1
- package/dist/browser/hash.d.cts.map +1 -1
- package/dist/browser/hash.d.mts +1 -1
- package/dist/browser/hash.d.mts.map +1 -1
- package/dist/browser/hash.d.ts +1 -1
- package/dist/browser/hash.d.ts.map +1 -1
- package/dist/browser/hex/from/from.d.cts +0 -1
- package/dist/browser/hex/from/from.d.cts.map +1 -1
- package/dist/browser/hex/from/from.d.mts +0 -1
- package/dist/browser/hex/from/from.d.mts.map +1 -1
- package/dist/browser/hex/from/from.d.ts +0 -1
- package/dist/browser/hex/from/from.d.ts.map +1 -1
- package/dist/browser/hex/from/fromArrayBuffer.d.cts +0 -1
- package/dist/browser/hex/from/fromArrayBuffer.d.cts.map +1 -1
- package/dist/browser/hex/from/fromArrayBuffer.d.mts +0 -1
- package/dist/browser/hex/from/fromArrayBuffer.d.mts.map +1 -1
- package/dist/browser/hex/from/fromArrayBuffer.d.ts +0 -1
- package/dist/browser/hex/from/fromArrayBuffer.d.ts.map +1 -1
- package/dist/browser/hex/from/fromBigInt.d.cts +0 -1
- package/dist/browser/hex/from/fromBigInt.d.cts.map +1 -1
- package/dist/browser/hex/from/fromBigInt.d.mts +0 -1
- package/dist/browser/hex/from/fromBigInt.d.mts.map +1 -1
- package/dist/browser/hex/from/fromBigInt.d.ts +0 -1
- package/dist/browser/hex/from/fromBigInt.d.ts.map +1 -1
- package/dist/browser/hex/is.d.cts +2 -2
- package/dist/browser/hex/is.d.cts.map +1 -1
- package/dist/browser/hex/is.d.mts +2 -2
- package/dist/browser/hex/is.d.mts.map +1 -1
- package/dist/browser/hex/is.d.ts +2 -2
- package/dist/browser/hex/is.d.ts.map +1 -1
- package/dist/browser/hex/model.d.cts +0 -1
- package/dist/browser/hex/model.d.cts.map +1 -1
- package/dist/browser/hex/model.d.mts +0 -1
- package/dist/browser/hex/model.d.mts.map +1 -1
- package/dist/browser/hex/model.d.ts +0 -1
- package/dist/browser/hex/model.d.ts.map +1 -1
- package/dist/browser/hex/to.d.cts +0 -1
- package/dist/browser/hex/to.d.cts.map +1 -1
- package/dist/browser/hex/to.d.mts +0 -1
- package/dist/browser/hex/to.d.mts.map +1 -1
- package/dist/browser/hex/to.d.ts +0 -1
- package/dist/browser/hex/to.d.ts.map +1 -1
- package/dist/browser/index.cjs +3 -6
- package/dist/browser/index.cjs.map +1 -1
- package/dist/browser/index.js +3 -6
- package/dist/browser/index.js.map +1 -1
- package/dist/neutral/address.d.cts +1 -1
- package/dist/neutral/address.d.cts.map +1 -1
- package/dist/neutral/address.d.mts +1 -1
- package/dist/neutral/address.d.mts.map +1 -1
- package/dist/neutral/address.d.ts +1 -1
- package/dist/neutral/address.d.ts.map +1 -1
- package/dist/neutral/hash.d.cts +1 -1
- package/dist/neutral/hash.d.cts.map +1 -1
- package/dist/neutral/hash.d.mts +1 -1
- package/dist/neutral/hash.d.mts.map +1 -1
- package/dist/neutral/hash.d.ts +1 -1
- package/dist/neutral/hash.d.ts.map +1 -1
- package/dist/neutral/hex/from/from.d.cts +0 -1
- package/dist/neutral/hex/from/from.d.cts.map +1 -1
- package/dist/neutral/hex/from/from.d.mts +0 -1
- package/dist/neutral/hex/from/from.d.mts.map +1 -1
- package/dist/neutral/hex/from/from.d.ts +0 -1
- package/dist/neutral/hex/from/from.d.ts.map +1 -1
- package/dist/neutral/hex/from/fromArrayBuffer.d.cts +0 -1
- package/dist/neutral/hex/from/fromArrayBuffer.d.cts.map +1 -1
- package/dist/neutral/hex/from/fromArrayBuffer.d.mts +0 -1
- package/dist/neutral/hex/from/fromArrayBuffer.d.mts.map +1 -1
- package/dist/neutral/hex/from/fromArrayBuffer.d.ts +0 -1
- package/dist/neutral/hex/from/fromArrayBuffer.d.ts.map +1 -1
- package/dist/neutral/hex/from/fromBigInt.d.cts +0 -1
- package/dist/neutral/hex/from/fromBigInt.d.cts.map +1 -1
- package/dist/neutral/hex/from/fromBigInt.d.mts +0 -1
- package/dist/neutral/hex/from/fromBigInt.d.mts.map +1 -1
- package/dist/neutral/hex/from/fromBigInt.d.ts +0 -1
- package/dist/neutral/hex/from/fromBigInt.d.ts.map +1 -1
- package/dist/neutral/hex/is.d.cts +2 -2
- package/dist/neutral/hex/is.d.cts.map +1 -1
- package/dist/neutral/hex/is.d.mts +2 -2
- package/dist/neutral/hex/is.d.mts.map +1 -1
- package/dist/neutral/hex/is.d.ts +2 -2
- package/dist/neutral/hex/is.d.ts.map +1 -1
- package/dist/neutral/hex/model.d.cts +0 -1
- package/dist/neutral/hex/model.d.cts.map +1 -1
- package/dist/neutral/hex/model.d.mts +0 -1
- package/dist/neutral/hex/model.d.mts.map +1 -1
- package/dist/neutral/hex/model.d.ts +0 -1
- package/dist/neutral/hex/model.d.ts.map +1 -1
- package/dist/neutral/hex/to.d.cts +0 -1
- package/dist/neutral/hex/to.d.cts.map +1 -1
- package/dist/neutral/hex/to.d.mts +0 -1
- package/dist/neutral/hex/to.d.mts.map +1 -1
- package/dist/neutral/hex/to.d.ts +0 -1
- package/dist/neutral/hex/to.d.ts.map +1 -1
- package/dist/neutral/index.cjs +3 -6
- package/dist/neutral/index.cjs.map +1 -1
- package/dist/neutral/index.js +3 -6
- package/dist/neutral/index.js.map +1 -1
- package/dist/node/address.d.cts +1 -1
- package/dist/node/address.d.cts.map +1 -1
- package/dist/node/address.d.mts +1 -1
- package/dist/node/address.d.mts.map +1 -1
- package/dist/node/address.d.ts +1 -1
- package/dist/node/address.d.ts.map +1 -1
- package/dist/node/hash.d.cts +1 -1
- package/dist/node/hash.d.cts.map +1 -1
- package/dist/node/hash.d.mts +1 -1
- package/dist/node/hash.d.mts.map +1 -1
- package/dist/node/hash.d.ts +1 -1
- package/dist/node/hash.d.ts.map +1 -1
- package/dist/node/hex/from/from.d.cts +0 -1
- package/dist/node/hex/from/from.d.cts.map +1 -1
- package/dist/node/hex/from/from.d.mts +0 -1
- package/dist/node/hex/from/from.d.mts.map +1 -1
- package/dist/node/hex/from/from.d.ts +0 -1
- package/dist/node/hex/from/from.d.ts.map +1 -1
- package/dist/node/hex/from/fromArrayBuffer.d.cts +0 -1
- package/dist/node/hex/from/fromArrayBuffer.d.cts.map +1 -1
- package/dist/node/hex/from/fromArrayBuffer.d.mts +0 -1
- package/dist/node/hex/from/fromArrayBuffer.d.mts.map +1 -1
- package/dist/node/hex/from/fromArrayBuffer.d.ts +0 -1
- package/dist/node/hex/from/fromArrayBuffer.d.ts.map +1 -1
- package/dist/node/hex/from/fromBigInt.d.cts +0 -1
- package/dist/node/hex/from/fromBigInt.d.cts.map +1 -1
- package/dist/node/hex/from/fromBigInt.d.mts +0 -1
- package/dist/node/hex/from/fromBigInt.d.mts.map +1 -1
- package/dist/node/hex/from/fromBigInt.d.ts +0 -1
- package/dist/node/hex/from/fromBigInt.d.ts.map +1 -1
- package/dist/node/hex/is.d.cts +2 -2
- package/dist/node/hex/is.d.cts.map +1 -1
- package/dist/node/hex/is.d.mts +2 -2
- package/dist/node/hex/is.d.mts.map +1 -1
- package/dist/node/hex/is.d.ts +2 -2
- package/dist/node/hex/is.d.ts.map +1 -1
- package/dist/node/hex/model.d.cts +0 -1
- package/dist/node/hex/model.d.cts.map +1 -1
- package/dist/node/hex/model.d.mts +0 -1
- package/dist/node/hex/model.d.mts.map +1 -1
- package/dist/node/hex/model.d.ts +0 -1
- package/dist/node/hex/model.d.ts.map +1 -1
- package/dist/node/hex/to.d.cts +0 -1
- package/dist/node/hex/to.d.cts.map +1 -1
- package/dist/node/hex/to.d.mts +0 -1
- package/dist/node/hex/to.d.mts.map +1 -1
- package/dist/node/hex/to.d.ts +0 -1
- package/dist/node/hex/to.d.ts.map +1 -1
- package/dist/node/index.cjs +3 -6
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.js +3 -6
- package/dist/node/index.js.map +1 -1
- package/package.json +5 -5
|
@@ -2,7 +2,7 @@ import { AssertConfig } from './assert';
|
|
|
2
2
|
import { Hex, HexConfig } from './hex';
|
|
3
3
|
export type Address = Exclude<Hex, 'reserved-address-value'>;
|
|
4
4
|
export declare const toAddress: (value: unknown, config?: HexConfig) => Lowercase<string>;
|
|
5
|
-
export declare const isAddress: (value: unknown, config?: HexConfig) => value is
|
|
5
|
+
export declare const isAddress: (value: unknown, config?: HexConfig) => value is Address;
|
|
6
6
|
export declare function asAddress(value: unknown): Address | undefined;
|
|
7
7
|
export declare function asAddress(value: unknown, assert: AssertConfig): Address;
|
|
8
8
|
//# sourceMappingURL=address.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../../src/address.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAe,MAAM,UAAU,CAAA;AACpD,OAAO,EAAE,GAAG,EAAE,SAAS,EAAoC,MAAM,OAAO,CAAA;AAExE,MAAM,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,EAAE,wBAAwB,CAAC,CAAA;AAE5D,eAAO,MAAM,SAAS,UAAW,OAAO,WAAU,SAAS,sBAG1D,CAAA;AAED,eAAO,MAAM,SAAS,UAAW,OAAO,WAAU,SAAS
|
|
1
|
+
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../../src/address.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAe,MAAM,UAAU,CAAA;AACpD,OAAO,EAAE,GAAG,EAAE,SAAS,EAAoC,MAAM,OAAO,CAAA;AAExE,MAAM,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,EAAE,wBAAwB,CAAC,CAAA;AAE5D,eAAO,MAAM,SAAS,UAAW,OAAO,WAAU,SAAS,sBAG1D,CAAA;AAED,eAAO,MAAM,SAAS,UAAW,OAAO,WAAU,SAAS,KAAQ,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"}
|
|
@@ -2,7 +2,7 @@ import { AssertConfig } from './assert';
|
|
|
2
2
|
import { Hex, HexConfig } from './hex';
|
|
3
3
|
export type Address = Exclude<Hex, 'reserved-address-value'>;
|
|
4
4
|
export declare const toAddress: (value: unknown, config?: HexConfig) => Lowercase<string>;
|
|
5
|
-
export declare const isAddress: (value: unknown, config?: HexConfig) => value is
|
|
5
|
+
export declare const isAddress: (value: unknown, config?: HexConfig) => value is Address;
|
|
6
6
|
export declare function asAddress(value: unknown): Address | undefined;
|
|
7
7
|
export declare function asAddress(value: unknown, assert: AssertConfig): Address;
|
|
8
8
|
//# sourceMappingURL=address.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../../src/address.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAe,MAAM,UAAU,CAAA;AACpD,OAAO,EAAE,GAAG,EAAE,SAAS,EAAoC,MAAM,OAAO,CAAA;AAExE,MAAM,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,EAAE,wBAAwB,CAAC,CAAA;AAE5D,eAAO,MAAM,SAAS,UAAW,OAAO,WAAU,SAAS,sBAG1D,CAAA;AAED,eAAO,MAAM,SAAS,UAAW,OAAO,WAAU,SAAS
|
|
1
|
+
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../../src/address.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAe,MAAM,UAAU,CAAA;AACpD,OAAO,EAAE,GAAG,EAAE,SAAS,EAAoC,MAAM,OAAO,CAAA;AAExE,MAAM,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,EAAE,wBAAwB,CAAC,CAAA;AAE5D,eAAO,MAAM,SAAS,UAAW,OAAO,WAAU,SAAS,sBAG1D,CAAA;AAED,eAAO,MAAM,SAAS,UAAW,OAAO,WAAU,SAAS,KAAQ,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"}
|
|
@@ -2,7 +2,7 @@ import { AssertConfig } from './assert';
|
|
|
2
2
|
import { Hex, HexConfig } from './hex';
|
|
3
3
|
export type Address = Exclude<Hex, 'reserved-address-value'>;
|
|
4
4
|
export declare const toAddress: (value: unknown, config?: HexConfig) => Lowercase<string>;
|
|
5
|
-
export declare const isAddress: (value: unknown, config?: HexConfig) => value is
|
|
5
|
+
export declare const isAddress: (value: unknown, config?: HexConfig) => value is Address;
|
|
6
6
|
export declare function asAddress(value: unknown): Address | undefined;
|
|
7
7
|
export declare function asAddress(value: unknown, assert: AssertConfig): Address;
|
|
8
8
|
//# sourceMappingURL=address.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../../src/address.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAe,MAAM,UAAU,CAAA;AACpD,OAAO,EAAE,GAAG,EAAE,SAAS,EAAoC,MAAM,OAAO,CAAA;AAExE,MAAM,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,EAAE,wBAAwB,CAAC,CAAA;AAE5D,eAAO,MAAM,SAAS,UAAW,OAAO,WAAU,SAAS,sBAG1D,CAAA;AAED,eAAO,MAAM,SAAS,UAAW,OAAO,WAAU,SAAS
|
|
1
|
+
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../../src/address.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAe,MAAM,UAAU,CAAA;AACpD,OAAO,EAAE,GAAG,EAAE,SAAS,EAAoC,MAAM,OAAO,CAAA;AAExE,MAAM,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,EAAE,wBAAwB,CAAC,CAAA;AAE5D,eAAO,MAAM,SAAS,UAAW,OAAO,WAAU,SAAS,sBAG1D,CAAA;AAED,eAAO,MAAM,SAAS,UAAW,OAAO,WAAU,SAAS,KAAQ,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"}
|
package/dist/browser/hash.d.cts
CHANGED
|
@@ -4,7 +4,7 @@ export type HashBitLength = 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096;
|
|
|
4
4
|
export declare const HashBitLength: HashBitLength[];
|
|
5
5
|
export declare const isHashBitLength: (value: unknown) => value is HashBitLength;
|
|
6
6
|
export type Hash = Exclude<Hex, 'reserved-hash-value'>;
|
|
7
|
-
export declare const isHash: (value: unknown, bitLength?: HashBitLength) => value is
|
|
7
|
+
export declare const isHash: (value: unknown, bitLength?: HashBitLength) => value is Hash;
|
|
8
8
|
export declare function asHash(value: unknown): Hash | undefined;
|
|
9
9
|
export declare function asHash(value: unknown, assert: AssertConfig): Hash;
|
|
10
10
|
//# sourceMappingURL=hash.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/hash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAe,MAAM,UAAU,CAAA;AACpD,OAAO,EAAE,GAAG,EAA2B,MAAM,OAAO,CAAA;AAEpD,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,UAAW,OAAO,
|
|
1
|
+
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/hash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAe,MAAM,UAAU,CAAA;AACpD,OAAO,EAAE,GAAG,EAA2B,MAAM,OAAO,CAAA;AAEpD,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,UAAW,OAAO,KAAG,KAAK,IAAI,aAEzD,CAAA;AAED,MAAM,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,EAAE,qBAAqB,CAAC,CAAA;AACtD,eAAO,MAAM,MAAM,UAAW,OAAO,cAAa,aAAa,KAAS,KAAK,IAAI,IAEhF,CAAA;AAED,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"}
|
package/dist/browser/hash.d.mts
CHANGED
|
@@ -4,7 +4,7 @@ export type HashBitLength = 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096;
|
|
|
4
4
|
export declare const HashBitLength: HashBitLength[];
|
|
5
5
|
export declare const isHashBitLength: (value: unknown) => value is HashBitLength;
|
|
6
6
|
export type Hash = Exclude<Hex, 'reserved-hash-value'>;
|
|
7
|
-
export declare const isHash: (value: unknown, bitLength?: HashBitLength) => value is
|
|
7
|
+
export declare const isHash: (value: unknown, bitLength?: HashBitLength) => value is Hash;
|
|
8
8
|
export declare function asHash(value: unknown): Hash | undefined;
|
|
9
9
|
export declare function asHash(value: unknown, assert: AssertConfig): Hash;
|
|
10
10
|
//# sourceMappingURL=hash.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/hash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAe,MAAM,UAAU,CAAA;AACpD,OAAO,EAAE,GAAG,EAA2B,MAAM,OAAO,CAAA;AAEpD,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,UAAW,OAAO,
|
|
1
|
+
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/hash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAe,MAAM,UAAU,CAAA;AACpD,OAAO,EAAE,GAAG,EAA2B,MAAM,OAAO,CAAA;AAEpD,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,UAAW,OAAO,KAAG,KAAK,IAAI,aAEzD,CAAA;AAED,MAAM,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,EAAE,qBAAqB,CAAC,CAAA;AACtD,eAAO,MAAM,MAAM,UAAW,OAAO,cAAa,aAAa,KAAS,KAAK,IAAI,IAEhF,CAAA;AAED,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"}
|
package/dist/browser/hash.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export type HashBitLength = 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096;
|
|
|
4
4
|
export declare const HashBitLength: HashBitLength[];
|
|
5
5
|
export declare const isHashBitLength: (value: unknown) => value is HashBitLength;
|
|
6
6
|
export type Hash = Exclude<Hex, 'reserved-hash-value'>;
|
|
7
|
-
export declare const isHash: (value: unknown, bitLength?: HashBitLength) => value is
|
|
7
|
+
export declare const isHash: (value: unknown, bitLength?: HashBitLength) => value is Hash;
|
|
8
8
|
export declare function asHash(value: unknown): Hash | undefined;
|
|
9
9
|
export declare function asHash(value: unknown, assert: AssertConfig): Hash;
|
|
10
10
|
//# sourceMappingURL=hash.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/hash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAe,MAAM,UAAU,CAAA;AACpD,OAAO,EAAE,GAAG,EAA2B,MAAM,OAAO,CAAA;AAEpD,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,UAAW,OAAO,
|
|
1
|
+
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/hash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAe,MAAM,UAAU,CAAA;AACpD,OAAO,EAAE,GAAG,EAA2B,MAAM,OAAO,CAAA;AAEpD,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,UAAW,OAAO,KAAG,KAAK,IAAI,aAEzD,CAAA;AAED,MAAM,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,EAAE,qBAAqB,CAAC,CAAA;AACtD,eAAO,MAAM,MAAM,UAAW,OAAO,cAAa,aAAa,KAAS,KAAK,IAAI,IAEhF,CAAA;AAED,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,GAAG,SAAS,CAAA;AACxD,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,GAAG,IAAI,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"from.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/from.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"from.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/from.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAOzC,eAAO,MAAM,OAAO,UAEX,OAAO,WAEL,SAAS,KACjB,GAsBF,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"from.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/from.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"from.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/from.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAOzC,eAAO,MAAM,OAAO,UAEX,OAAO,WAEL,SAAS,KACjB,GAsBF,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"from.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/from.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"from.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/from.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAOzC,eAAO,MAAM,OAAO,UAEX,OAAO,WAEL,SAAS,KACjB,GAsBF,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fromArrayBuffer.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/fromArrayBuffer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"fromArrayBuffer.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/fromArrayBuffer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAIzC,eAAO,MAAM,kBAAkB,WAErB,WAAW,WAEV,SAAS,KACjB,GAGF,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fromArrayBuffer.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/fromArrayBuffer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"fromArrayBuffer.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/fromArrayBuffer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAIzC,eAAO,MAAM,kBAAkB,WAErB,WAAW,WAEV,SAAS,KACjB,GAGF,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fromArrayBuffer.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/fromArrayBuffer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"fromArrayBuffer.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/fromArrayBuffer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAIzC,eAAO,MAAM,kBAAkB,WAErB,WAAW,WAEV,SAAS,KACjB,GAGF,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fromBigInt.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/fromBigInt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"fromBigInt.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/fromBigInt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAKzC,eAAO,MAAM,aAAa,UAEjB,MAAM,WAEL,SAAS,KAChB,GAKF,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fromBigInt.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/fromBigInt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"fromBigInt.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/fromBigInt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAKzC,eAAO,MAAM,aAAa,UAEjB,MAAM,WAEL,SAAS,KAChB,GAKF,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fromBigInt.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/fromBigInt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"fromBigInt.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/fromBigInt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAKzC,eAAO,MAAM,aAAa,UAEjB,MAAM,WAEL,SAAS,KAChB,GAKF,CAAA"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { HexConfig } from './model';
|
|
2
|
-
export declare const isHex: (value: unknown, config?: HexConfig) => value is
|
|
1
|
+
import { Hex, HexConfig } from './model';
|
|
2
|
+
export declare const isHex: (value: unknown, config?: HexConfig) => value is Hex;
|
|
3
3
|
//# sourceMappingURL=is.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is.d.ts","sourceRoot":"","sources":["../../../src/hex/is.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"is.d.ts","sourceRoot":"","sources":["../../../src/hex/is.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAIxC,eAAO,MAAM,KAAK,UAAW,OAAO,WAAW,SAAS,KAAG,KAAK,IAAI,GAWnE,CAAA"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { HexConfig } from './model';
|
|
2
|
-
export declare const isHex: (value: unknown, config?: HexConfig) => value is
|
|
1
|
+
import { Hex, HexConfig } from './model';
|
|
2
|
+
export declare const isHex: (value: unknown, config?: HexConfig) => value is Hex;
|
|
3
3
|
//# sourceMappingURL=is.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is.d.ts","sourceRoot":"","sources":["../../../src/hex/is.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"is.d.ts","sourceRoot":"","sources":["../../../src/hex/is.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAIxC,eAAO,MAAM,KAAK,UAAW,OAAO,WAAW,SAAS,KAAG,KAAK,IAAI,GAWnE,CAAA"}
|
package/dist/browser/hex/is.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { HexConfig } from './model';
|
|
2
|
-
export declare const isHex: (value: unknown, config?: HexConfig) => value is
|
|
1
|
+
import { Hex, HexConfig } from './model';
|
|
2
|
+
export declare const isHex: (value: unknown, config?: HexConfig) => value is Hex;
|
|
3
3
|
//# sourceMappingURL=is.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is.d.ts","sourceRoot":"","sources":["../../../src/hex/is.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"is.d.ts","sourceRoot":"","sources":["../../../src/hex/is.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAIxC,eAAO,MAAM,KAAK,UAAW,OAAO,WAAW,SAAS,KAAG,KAAK,IAAI,GAWnE,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../src/hex/model.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,GAAG,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,oBAAoB,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../src/hex/model.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,GAAG,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,oBAAoB,CAAC,CAAA;AAGlE,MAAM,WAAW,SAAS;IACxB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../src/hex/model.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,GAAG,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,oBAAoB,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../src/hex/model.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,GAAG,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,oBAAoB,CAAC,CAAA;AAGlE,MAAM,WAAW,SAAS;IACxB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../src/hex/model.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,GAAG,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,oBAAoB,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../src/hex/model.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,GAAG,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,oBAAoB,CAAC,CAAA;AAGlE,MAAM,WAAW,SAAS;IACxB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to.d.ts","sourceRoot":"","sources":["../../../src/hex/to.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"to.d.ts","sourceRoot":"","sources":["../../../src/hex/to.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAGnC,eAAO,MAAM,KAAK,UAET,OAAO,WAEN,SAAS,sBAIlB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to.d.ts","sourceRoot":"","sources":["../../../src/hex/to.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"to.d.ts","sourceRoot":"","sources":["../../../src/hex/to.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAGnC,eAAO,MAAM,KAAK,UAET,OAAO,WAEN,SAAS,sBAIlB,CAAA"}
|
package/dist/browser/hex/to.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to.d.ts","sourceRoot":"","sources":["../../../src/hex/to.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"to.d.ts","sourceRoot":"","sources":["../../../src/hex/to.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAGnC,eAAO,MAAM,KAAK,UAET,OAAO,WAEN,SAAS,sBAIlB,CAAA"}
|
package/dist/browser/index.cjs
CHANGED
|
@@ -61,8 +61,7 @@ var import_arraybuffer = require("@xylabs/arraybuffer");
|
|
|
61
61
|
// src/hex/nibble.ts
|
|
62
62
|
var bitsToNibbles = (value) => {
|
|
63
63
|
const nibbles = value >> 2;
|
|
64
|
-
if (value !== nibbles << 2)
|
|
65
|
-
throw new Error("Bits for nibbles must multiple of 4");
|
|
64
|
+
if (value !== nibbles << 2) throw new Error("Bits for nibbles must multiple of 4");
|
|
66
65
|
return nibbles;
|
|
67
66
|
};
|
|
68
67
|
var nibblesToBits = (value) => {
|
|
@@ -75,11 +74,9 @@ var hexRegexWithPrefix = /0x[\da-f]+$/i;
|
|
|
75
74
|
|
|
76
75
|
// src/hex/is.ts
|
|
77
76
|
var isHex = (value, config) => {
|
|
78
|
-
if (typeof value !== "string")
|
|
79
|
-
return false;
|
|
77
|
+
if (typeof value !== "string") return false;
|
|
80
78
|
const valueCharLength = config?.prefix ? value.length - 2 : value.length;
|
|
81
|
-
if (config?.bitLength !== void 0 && valueCharLength !== bitsToNibbles(config?.bitLength))
|
|
82
|
-
return false;
|
|
79
|
+
if (config?.bitLength !== void 0 && valueCharLength !== bitsToNibbles(config?.bitLength)) return false;
|
|
83
80
|
return config?.prefix ? hexRegexWithPrefix.test(value) : hexRegex.test(value);
|
|
84
81
|
};
|
|
85
82
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts","../../src/assert.ts","../../src/hex/from/from.ts","../../src/hex/nibble.ts","../../src/hex/regex.ts","../../src/hex/is.ts","../../src/hex/from/fromHexString.ts","../../src/hex/from/fromArrayBuffer.ts","../../src/hex/from/fromBigInt.ts","../../src/hex/from/fromNumber.ts","../../src/hex/as.ts","../../src/hex/isHexZero.ts","../../src/hex/legacy.ts","../../src/hex/to.ts","../../src/address.ts","../../src/hash.ts"],"sourcesContent":["export * from './address'\nexport * from './hash'\nexport * from './hex'\n","export type 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 (assert) {\n const assertString =\n typeof assert === 'string' ? assert\n : typeof assert === 'boolean' ? defaultMessage\n : assert(value, defaultMessage)\n if (assertString) {\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 { isArrayBuffer } from '@xylabs/arraybuffer'\n\nimport { Hex, HexConfig } from '../model'\nimport { hexFromArrayBuffer } from './fromArrayBuffer'\nimport { hexFromBigInt } from './fromBigInt'\nimport { hexFromHexString } from './fromHexString'\nimport { hexFromNumber } from './fromNumber'\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: unknown,\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 if (isArrayBuffer(value)) {\n return hexFromArrayBuffer(value, config)\n } else {\n throw new Error('Invalid type: object !== ArrayBuffer')\n }\n }\n default: {\n throw new Error(`Invalid type: ${typeof value}`)\n }\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 { Hex, HexConfig } from './model'\nimport { bitsToNibbles } from './nibble'\nimport { hexRegex, hexRegexWithPrefix } from './regex'\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 { isHex } from '../is'\nimport { Hex, HexConfig } from '../model'\nimport { bitsToNibbles } from '../nibble'\n\nexport const hexFromHexString = (value: string, config: HexConfig = {}): Hex => {\n const { prefix = false, byteSize = 8 } = config\n const nibbleBoundary = bitsToNibbles(byteSize)\n const unPadded = (value.startsWith('0x') ? value.slice(2) : value).toLowerCase()\n if (isHex(unPadded)) {\n const padded = unPadded.padStart(unPadded.length + (unPadded.length % nibbleBoundary), '0')\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","import { Hex, HexConfig } from '../model'\nimport { hexFromHexString } from './fromHexString'\n\n/** Convert an ArrayBuffer to a hex string */\nexport const hexFromArrayBuffer = (\n /** The buffer to be converted */\n buffer: ArrayBuffer,\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 { Hex, HexConfig } from '../model'\nimport { bitsToNibbles } from '../nibble'\nimport { hexFromHexString } from './fromHexString'\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 { bitLength } = config\n const unPadded = value.toString(16)\n const padded = bitLength === undefined ? unPadded : unPadded.padStart(bitsToNibbles(bitLength), '0')\n return hexFromHexString(padded, config)\n}\n","import { Hex, HexConfig } from '../model'\nimport { hexFromBigInt } from './fromBigInt'\n\nexport const hexFromNumber = (value: number, config?: HexConfig): Hex => {\n return hexFromBigInt(BigInt(value), config)\n}\n","import { AssertConfig, assertError } from '../assert'\nimport { hexFromHexString } from './from'\nimport { isHex } from './is'\nimport { Hex } from './model'\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 { hexFromHexString } from './from'\n\nexport const isHexZero = (value?: string) => {\n return value ? BigInt(hexFromHexString(value, { prefix: true })) === 0n : undefined\n}\n","export const toHexLegacy = (buffer: ArrayBuffer) => {\n return [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, '0')).join('')\n}\n","import { hexFrom } from './from'\nimport { HexConfig } from './model'\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: unknown,\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 { AssertConfig, assertError } from './assert'\nimport { Hex, HexConfig, hexFrom, hexFromHexString, isHex } from './hex'\n\nexport type Address = Exclude<Hex, 'reserved-address-value'>\n\nexport const toAddress = (value: unknown, config: HexConfig = {}) => {\n const { bitLength = 160, prefix = false } = config\n return hexFrom(value, { bitLength, prefix, ...config })\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 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 { AssertConfig, assertError } from './assert'\nimport { Hex, hexFromHexString, isHex } from './hex'\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 = Exclude<Hex, 'reserved-hash-value'>\nexport const isHash = (value: unknown, bitLength: HashBitLength = 256): value is Hash => {\n return isHex(value, { bitLength })\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 assert ? assertError(value, assert, `Unsupported type [${typeof value}]`) : undefined\n }\n }\n return isHash(stringValue) ? stringValue : assertError(value, assert, `Value is not a Hash [${value}]`)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACIO,IAAM,cAAc,CAAC,OAAgB,QAAkC,mBAA2B;AACvG,MAAI,QAAQ;AACV,UAAM,eACJ,OAAO,WAAW,WAAW,SAC3B,OAAO,WAAW,YAAY,iBAC9B,OAAO,OAAO,cAAc;AAChC,QAAI,cAAc;AAChB,YAAM,IAAI,MAAM,iBAAiB,OAAO,iBAAiB,YAAY;AAAA,IACvE;AAAA,EACF;AAEA,SAAO;AACT;;;AChBA,yBAA8B;;;ACCvB,IAAM,gBAAgB,CAAC,UAA0B;AACtD,QAAM,UAAU,SAAS;AACzB,MAAI,UAAU,WAAW;AAAG,UAAM,IAAI,MAAM,qCAAqC;AACjF,SAAO;AACT;AAGO,IAAM,gBAAgB,CAAC,UAA0B;AACtD,SAAO,SAAS;AAClB;;;ACVO,IAAM,WAAW;AACjB,IAAM,qBAAqB;;;ACG3B,IAAM,QAAQ,CAAC,OAAgB,WAAqC;AAEzE,MAAI,OAAO,UAAU;AAAU,WAAO;AAEtC,QAAM,kBAAkB,QAAQ,SAAS,MAAM,SAAS,IAAI,MAAM;AAGlE,MAAI,QA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IAAI;AAAA,IACrF;AAAA,EACF;AACA,SAAO,OAAO,WAAW,IAAI,cAAc,YAAY,OAAO,QAAQ,wBAAwB,KAAK,GAAG;AACxG;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts","../../src/assert.ts","../../src/hex/from/from.ts","../../src/hex/nibble.ts","../../src/hex/regex.ts","../../src/hex/is.ts","../../src/hex/from/fromHexString.ts","../../src/hex/from/fromArrayBuffer.ts","../../src/hex/from/fromBigInt.ts","../../src/hex/from/fromNumber.ts","../../src/hex/as.ts","../../src/hex/isHexZero.ts","../../src/hex/legacy.ts","../../src/hex/to.ts","../../src/address.ts","../../src/hash.ts"],"sourcesContent":["export * from './address'\nexport * from './hash'\nexport * from './hex'\n","export type 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 (assert) {\n const assertString =\n typeof assert === 'string' ? assert\n : typeof assert === 'boolean' ? defaultMessage\n : assert(value, defaultMessage)\n if (assertString) {\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 { isArrayBuffer } from '@xylabs/arraybuffer'\n\nimport { Hex, HexConfig } from '../model'\nimport { hexFromArrayBuffer } from './fromArrayBuffer'\nimport { hexFromBigInt } from './fromBigInt'\nimport { hexFromHexString } from './fromHexString'\nimport { hexFromNumber } from './fromNumber'\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: unknown,\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 if (isArrayBuffer(value)) {\n return hexFromArrayBuffer(value, config)\n } else {\n throw new Error('Invalid type: object !== ArrayBuffer')\n }\n }\n default: {\n throw new Error(`Invalid type: ${typeof value}`)\n }\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 { Hex, HexConfig } from './model'\nimport { bitsToNibbles } from './nibble'\nimport { hexRegex, hexRegexWithPrefix } from './regex'\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 { isHex } from '../is'\nimport { Hex, HexConfig } from '../model'\nimport { bitsToNibbles } from '../nibble'\n\nexport const hexFromHexString = (value: string, config: HexConfig = {}): Hex => {\n const { prefix = false, byteSize = 8 } = config\n const nibbleBoundary = bitsToNibbles(byteSize)\n const unPadded = (value.startsWith('0x') ? value.slice(2) : value).toLowerCase()\n if (isHex(unPadded)) {\n const padded = unPadded.padStart(unPadded.length + (unPadded.length % nibbleBoundary), '0')\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","import { Hex, HexConfig } from '../model'\nimport { hexFromHexString } from './fromHexString'\n\n/** Convert an ArrayBuffer to a hex string */\nexport const hexFromArrayBuffer = (\n /** The buffer to be converted */\n buffer: ArrayBuffer,\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 { Hex, HexConfig } from '../model'\nimport { bitsToNibbles } from '../nibble'\nimport { hexFromHexString } from './fromHexString'\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 { bitLength } = config\n const unPadded = value.toString(16)\n const padded = bitLength === undefined ? unPadded : unPadded.padStart(bitsToNibbles(bitLength), '0')\n return hexFromHexString(padded, config)\n}\n","import { Hex, HexConfig } from '../model'\nimport { hexFromBigInt } from './fromBigInt'\n\nexport const hexFromNumber = (value: number, config?: HexConfig): Hex => {\n return hexFromBigInt(BigInt(value), config)\n}\n","import { AssertConfig, assertError } from '../assert'\nimport { hexFromHexString } from './from'\nimport { isHex } from './is'\nimport { Hex } from './model'\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 { hexFromHexString } from './from'\n\nexport const isHexZero = (value?: string) => {\n return value ? BigInt(hexFromHexString(value, { prefix: true })) === 0n : undefined\n}\n","export const toHexLegacy = (buffer: ArrayBuffer) => {\n return [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, '0')).join('')\n}\n","import { hexFrom } from './from'\nimport { HexConfig } from './model'\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: unknown,\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 { AssertConfig, assertError } from './assert'\nimport { Hex, HexConfig, hexFrom, hexFromHexString, isHex } from './hex'\n\nexport type Address = Exclude<Hex, 'reserved-address-value'>\n\nexport const toAddress = (value: unknown, config: HexConfig = {}) => {\n const { bitLength = 160, prefix = false } = config\n return hexFrom(value, { bitLength, prefix, ...config })\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 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 { AssertConfig, assertError } from './assert'\nimport { Hex, hexFromHexString, isHex } from './hex'\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 = Exclude<Hex, 'reserved-hash-value'>\nexport const isHash = (value: unknown, bitLength: HashBitLength = 256): value is Hash => {\n return isHex(value, { bitLength })\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 assert ? assertError(value, assert, `Unsupported type [${typeof value}]`) : undefined\n }\n }\n return isHash(stringValue) ? stringValue : ass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tC,YAAQ,OAAO,OAAO;AAAA,MACpB,KAAK,UAAU;AACb,sBAAc,iBAAiB,OAAO,EAAE,QAAQ,MAAM,CAAC;AACvD;AAAA,MACF;AAAA,MACA,SAAS;AACP,eAAO,SAAS,YAAY,OAAO,QAAQ,qBAAqB,OAAO,KAAK,GAAG,IAAI;AAAA,MACrF;AAAA,IACF;AACA,WAAO,UAAU,WAAW,IAAI,cAAc,YAAY,OAAO,QAAQ,4BAA4B,KAAK,GAAG;AAAA,EAC/G,SAAS,IAAI;AACX,UAAM,QAAQ;AACd,WAAO,YAAY,QAAW,QAAQ,MAAM,OAAO;AAAA,EACrD;AACF;;;AC/BO,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;AAGO,IAAM,SAAS,CAAC,OAAgB,YAA2B,QAAuB;AACvF,SAAO,MAAM,OAAO,EAAE,UAAU,CAAC;AACnC;AAIO,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,aAAO,SAAS,YAAY,OAAO,QAAQ,qBAAqB,OAAO,KAAK,GAAG,IAAI;AAAA,IACrF;AAAA,EACF;AACA,SAAO,OAAO,WAAW,IAAI,cAAc,YAAY,OAAO,QAAQ,wBAAwB,KAAK,GAAG;AACxG;","names":[]}
|
package/dist/browser/index.js
CHANGED
|
@@ -15,8 +15,7 @@ import { isArrayBuffer } from "@xylabs/arraybuffer";
|
|
|
15
15
|
// src/hex/nibble.ts
|
|
16
16
|
var bitsToNibbles = (value) => {
|
|
17
17
|
const nibbles = value >> 2;
|
|
18
|
-
if (value !== nibbles << 2)
|
|
19
|
-
throw new Error("Bits for nibbles must multiple of 4");
|
|
18
|
+
if (value !== nibbles << 2) throw new Error("Bits for nibbles must multiple of 4");
|
|
20
19
|
return nibbles;
|
|
21
20
|
};
|
|
22
21
|
var nibblesToBits = (value) => {
|
|
@@ -29,11 +28,9 @@ var hexRegexWithPrefix = /0x[\da-f]+$/i;
|
|
|
29
28
|
|
|
30
29
|
// src/hex/is.ts
|
|
31
30
|
var isHex = (value, config) => {
|
|
32
|
-
if (typeof value !== "string")
|
|
33
|
-
return false;
|
|
31
|
+
if (typeof value !== "string") return false;
|
|
34
32
|
const valueCharLength = config?.prefix ? value.length - 2 : value.length;
|
|
35
|
-
if (config?.bitLength !== void 0 && valueCharLength !== bitsToNibbles(config?.bitLength))
|
|
36
|
-
return false;
|
|
33
|
+
if (config?.bitLength !== void 0 && valueCharLength !== bitsToNibbles(config?.bitLength)) return false;
|
|
37
34
|
return config?.prefix ? hexRegexWithPrefix.test(value) : hexRegex.test(value);
|
|
38
35
|
};
|
|
39
36
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/assert.ts","../../src/hex/from/from.ts","../../src/hex/nibble.ts","../../src/hex/regex.ts","../../src/hex/is.ts","../../src/hex/from/fromHexString.ts","../../src/hex/from/fromArrayBuffer.ts","../../src/hex/from/fromBigInt.ts","../../src/hex/from/fromNumber.ts","../../src/hex/as.ts","../../src/hex/isHexZero.ts","../../src/hex/legacy.ts","../../src/hex/to.ts","../../src/address.ts","../../src/hash.ts"],"sourcesContent":["export type 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 (assert) {\n const assertString =\n typeof assert === 'string' ? assert\n : typeof assert === 'boolean' ? defaultMessage\n : assert(value, defaultMessage)\n if (assertString) {\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 { isArrayBuffer } from '@xylabs/arraybuffer'\n\nimport { Hex, HexConfig } from '../model'\nimport { hexFromArrayBuffer } from './fromArrayBuffer'\nimport { hexFromBigInt } from './fromBigInt'\nimport { hexFromHexString } from './fromHexString'\nimport { hexFromNumber } from './fromNumber'\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: unknown,\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 if (isArrayBuffer(value)) {\n return hexFromArrayBuffer(value, config)\n } else {\n throw new Error('Invalid type: object !== ArrayBuffer')\n }\n }\n default: {\n throw new Error(`Invalid type: ${typeof value}`)\n }\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 { Hex, HexConfig } from './model'\nimport { bitsToNibbles } from './nibble'\nimport { hexRegex, hexRegexWithPrefix } from './regex'\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 { isHex } from '../is'\nimport { Hex, HexConfig } from '../model'\nimport { bitsToNibbles } from '../nibble'\n\nexport const hexFromHexString = (value: string, config: HexConfig = {}): Hex => {\n const { prefix = false, byteSize = 8 } = config\n const nibbleBoundary = bitsToNibbles(byteSize)\n const unPadded = (value.startsWith('0x') ? value.slice(2) : value).toLowerCase()\n if (isHex(unPadded)) {\n const padded = unPadded.padStart(unPadded.length + (unPadded.length % nibbleBoundary), '0')\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","import { Hex, HexConfig } from '../model'\nimport { hexFromHexString } from './fromHexString'\n\n/** Convert an ArrayBuffer to a hex string */\nexport const hexFromArrayBuffer = (\n /** The buffer to be converted */\n buffer: ArrayBuffer,\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 { Hex, HexConfig } from '../model'\nimport { bitsToNibbles } from '../nibble'\nimport { hexFromHexString } from './fromHexString'\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 { bitLength } = config\n const unPadded = value.toString(16)\n const padded = bitLength === undefined ? unPadded : unPadded.padStart(bitsToNibbles(bitLength), '0')\n return hexFromHexString(padded, config)\n}\n","import { Hex, HexConfig } from '../model'\nimport { hexFromBigInt } from './fromBigInt'\n\nexport const hexFromNumber = (value: number, config?: HexConfig): Hex => {\n return hexFromBigInt(BigInt(value), config)\n}\n","import { AssertConfig, assertError } from '../assert'\nimport { hexFromHexString } from './from'\nimport { isHex } from './is'\nimport { Hex } from './model'\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 { hexFromHexString } from './from'\n\nexport const isHexZero = (value?: string) => {\n return value ? BigInt(hexFromHexString(value, { prefix: true })) === 0n : undefined\n}\n","export const toHexLegacy = (buffer: ArrayBuffer) => {\n return [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, '0')).join('')\n}\n","import { hexFrom } from './from'\nimport { HexConfig } from './model'\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: unknown,\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 { AssertConfig, assertError } from './assert'\nimport { Hex, HexConfig, hexFrom, hexFromHexString, isHex } from './hex'\n\nexport type Address = Exclude<Hex, 'reserved-address-value'>\n\nexport const toAddress = (value: unknown, config: HexConfig = {}) => {\n const { bitLength = 160, prefix = false } = config\n return hexFrom(value, { bitLength, prefix, ...config })\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 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 { AssertConfig, assertError } from './assert'\nimport { Hex, hexFromHexString, isHex } from './hex'\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 = Exclude<Hex, 'reserved-hash-value'>\nexport const isHash = (value: unknown, bitLength: HashBitLength = 256): value is Hash => {\n return isHex(value, { bitLength })\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 assert ? assertError(value, assert, `Unsupported type [${typeof value}]`) : undefined\n }\n }\n return isHash(stringValue) ? stringValue : assertError(value, assert, `Value is not a Hash [${value}]`)\n}\n"],"mappings":";AAIO,IAAM,cAAc,CAAC,OAAgB,QAAkC,mBAA2B;AACvG,MAAI,QAAQ;AACV,UAAM,eACJ,OAAO,WAAW,WAAW,SAC3B,OAAO,WAAW,YAAY,iBAC9B,OAAO,OAAO,cAAc;AAChC,QAAI,cAAc;AAChB,YAAM,IAAI,MAAM,iBAAiB,OAAO,iBAAiB,YAAY;AAAA,IACvE;AAAA,EACF;AAEA,SAAO;AACT;;;AChBA,SAAS,qBAAqB;;;ACCvB,IAAM,gBAAgB,CAAC,UAA0B;AACtD,QAAM,UAAU,SAAS;AACzB,MAAI,UAAU,WAAW;AAAG,UAAM,IAAI,MAAM,qCAAqC;AACjF,SAAO;AACT;AAGO,IAAM,gBAAgB,CAAC,UAA0B;AACtD,SAAO,SAAS;AAClB;;;ACVO,IAAM,WAAW;AACjB,IAAM,qBAAqB;;;ACG3B,IAAM,QAAQ,CAAC,OAAgB,WAAqC;AAEzE,MAAI,OAAO,UAAU;AAAU,WAAO;AAEtC,QAAM,kBAAkB,QAAQ,SAAS,MAAM,SAAS,IAAI,MAAM;AAGlE,MAAI,QAAQ,cAAc,UAAa,oBAAoB,cAAc,QAAQ,SAAS;AAA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W,IAAI,cAAc,YAAY,OAAO,QAAQ,wBAAwB,KAAK,GAAG;AACxG;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/assert.ts","../../src/hex/from/from.ts","../../src/hex/nibble.ts","../../src/hex/regex.ts","../../src/hex/is.ts","../../src/hex/from/fromHexString.ts","../../src/hex/from/fromArrayBuffer.ts","../../src/hex/from/fromBigInt.ts","../../src/hex/from/fromNumber.ts","../../src/hex/as.ts","../../src/hex/isHexZero.ts","../../src/hex/legacy.ts","../../src/hex/to.ts","../../src/address.ts","../../src/hash.ts"],"sourcesContent":["export type 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 (assert) {\n const assertString =\n typeof assert === 'string' ? assert\n : typeof assert === 'boolean' ? defaultMessage\n : assert(value, defaultMessage)\n if (assertString) {\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 { isArrayBuffer } from '@xylabs/arraybuffer'\n\nimport { Hex, HexConfig } from '../model'\nimport { hexFromArrayBuffer } from './fromArrayBuffer'\nimport { hexFromBigInt } from './fromBigInt'\nimport { hexFromHexString } from './fromHexString'\nimport { hexFromNumber } from './fromNumber'\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: unknown,\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 if (isArrayBuffer(value)) {\n return hexFromArrayBuffer(value, config)\n } else {\n throw new Error('Invalid type: object !== ArrayBuffer')\n }\n }\n default: {\n throw new Error(`Invalid type: ${typeof value}`)\n }\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 { Hex, HexConfig } from './model'\nimport { bitsToNibbles } from './nibble'\nimport { hexRegex, hexRegexWithPrefix } from './regex'\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 { isHex } from '../is'\nimport { Hex, HexConfig } from '../model'\nimport { bitsToNibbles } from '../nibble'\n\nexport const hexFromHexString = (value: string, config: HexConfig = {}): Hex => {\n const { prefix = false, byteSize = 8 } = config\n const nibbleBoundary = bitsToNibbles(byteSize)\n const unPadded = (value.startsWith('0x') ? value.slice(2) : value).toLowerCase()\n if (isHex(unPadded)) {\n const padded = unPadded.padStart(unPadded.length + (unPadded.length % nibbleBoundary), '0')\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","import { Hex, HexConfig } from '../model'\nimport { hexFromHexString } from './fromHexString'\n\n/** Convert an ArrayBuffer to a hex string */\nexport const hexFromArrayBuffer = (\n /** The buffer to be converted */\n buffer: ArrayBuffer,\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 { Hex, HexConfig } from '../model'\nimport { bitsToNibbles } from '../nibble'\nimport { hexFromHexString } from './fromHexString'\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 { bitLength } = config\n const unPadded = value.toString(16)\n const padded = bitLength === undefined ? unPadded : unPadded.padStart(bitsToNibbles(bitLength), '0')\n return hexFromHexString(padded, config)\n}\n","import { Hex, HexConfig } from '../model'\nimport { hexFromBigInt } from './fromBigInt'\n\nexport const hexFromNumber = (value: number, config?: HexConfig): Hex => {\n return hexFromBigInt(BigInt(value), config)\n}\n","import { AssertConfig, assertError } from '../assert'\nimport { hexFromHexString } from './from'\nimport { isHex } from './is'\nimport { Hex } from './model'\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 { hexFromHexString } from './from'\n\nexport const isHexZero = (value?: string) => {\n return value ? BigInt(hexFromHexString(value, { prefix: true })) === 0n : undefined\n}\n","export const toHexLegacy = (buffer: ArrayBuffer) => {\n return [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, '0')).join('')\n}\n","import { hexFrom } from './from'\nimport { HexConfig } from './model'\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: unknown,\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 { AssertConfig, assertError } from './assert'\nimport { Hex, HexConfig, hexFrom, hexFromHexString, isHex } from './hex'\n\nexport type Address = Exclude<Hex, 'reserved-address-value'>\n\nexport const toAddress = (value: unknown, config: HexConfig = {}) => {\n const { bitLength = 160, prefix = false } = config\n return hexFrom(value, { bitLength, prefix, ...config })\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 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 { AssertConfig, assertError } from './assert'\nimport { Hex, hexFromHexString, isHex } from './hex'\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 = Exclude<Hex, 'reserved-hash-value'>\nexport const isHash = (value: unknown, bitLength: HashBitLength = 256): value is Hash => {\n return isHex(value, { bitLength })\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 assert ? assertError(value, assert, `Unsupported type [${typeof value}]`) : undefined\n }\n }\n return isHash(stringValue) ? stringValue : assertError(value, assert, `Value is not a Hash [${value}]`)\n}\n"],"mappings":";AAIO,IAAM,cAAc,CAAC,OAAgB,QAAkC,mBAA2B;AACv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AAO,QAAQ,4BAA4B,KAAK,GAAG;AAAA,EAC/G,SAAS,IAAI;AACX,UAAM,QAAQ;AACd,WAAO,YAAY,QAAW,QAAQ,MAAM,OAAO;AAAA,EACrD;AACF;;;AC/BO,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;AAGO,IAAM,SAAS,CAAC,OAAgB,YAA2B,QAAuB;AACvF,SAAO,MAAM,OAAO,EAAE,UAAU,CAAC;AACnC;AAIO,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,aAAO,SAAS,YAAY,OAAO,QAAQ,qBAAqB,OAAO,KAAK,GAAG,IAAI;AAAA,IACrF;AAAA,EACF;AACA,SAAO,OAAO,WAAW,IAAI,cAAc,YAAY,OAAO,QAAQ,wBAAwB,KAAK,GAAG;AACxG;","names":[]}
|
|
@@ -2,7 +2,7 @@ import { AssertConfig } from './assert';
|
|
|
2
2
|
import { Hex, HexConfig } from './hex';
|
|
3
3
|
export type Address = Exclude<Hex, 'reserved-address-value'>;
|
|
4
4
|
export declare const toAddress: (value: unknown, config?: HexConfig) => Lowercase<string>;
|
|
5
|
-
export declare const isAddress: (value: unknown, config?: HexConfig) => value is
|
|
5
|
+
export declare const isAddress: (value: unknown, config?: HexConfig) => value is Address;
|
|
6
6
|
export declare function asAddress(value: unknown): Address | undefined;
|
|
7
7
|
export declare function asAddress(value: unknown, assert: AssertConfig): Address;
|
|
8
8
|
//# sourceMappingURL=address.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../../src/address.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAe,MAAM,UAAU,CAAA;AACpD,OAAO,EAAE,GAAG,EAAE,SAAS,EAAoC,MAAM,OAAO,CAAA;AAExE,MAAM,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,EAAE,wBAAwB,CAAC,CAAA;AAE5D,eAAO,MAAM,SAAS,UAAW,OAAO,WAAU,SAAS,sBAG1D,CAAA;AAED,eAAO,MAAM,SAAS,UAAW,OAAO,WAAU,SAAS
|
|
1
|
+
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../../src/address.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAe,MAAM,UAAU,CAAA;AACpD,OAAO,EAAE,GAAG,EAAE,SAAS,EAAoC,MAAM,OAAO,CAAA;AAExE,MAAM,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,EAAE,wBAAwB,CAAC,CAAA;AAE5D,eAAO,MAAM,SAAS,UAAW,OAAO,WAAU,SAAS,sBAG1D,CAAA;AAED,eAAO,MAAM,SAAS,UAAW,OAAO,WAAU,SAAS,KAAQ,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"}
|
|
@@ -2,7 +2,7 @@ import { AssertConfig } from './assert';
|
|
|
2
2
|
import { Hex, HexConfig } from './hex';
|
|
3
3
|
export type Address = Exclude<Hex, 'reserved-address-value'>;
|
|
4
4
|
export declare const toAddress: (value: unknown, config?: HexConfig) => Lowercase<string>;
|
|
5
|
-
export declare const isAddress: (value: unknown, config?: HexConfig) => value is
|
|
5
|
+
export declare const isAddress: (value: unknown, config?: HexConfig) => value is Address;
|
|
6
6
|
export declare function asAddress(value: unknown): Address | undefined;
|
|
7
7
|
export declare function asAddress(value: unknown, assert: AssertConfig): Address;
|
|
8
8
|
//# sourceMappingURL=address.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../../src/address.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAe,MAAM,UAAU,CAAA;AACpD,OAAO,EAAE,GAAG,EAAE,SAAS,EAAoC,MAAM,OAAO,CAAA;AAExE,MAAM,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,EAAE,wBAAwB,CAAC,CAAA;AAE5D,eAAO,MAAM,SAAS,UAAW,OAAO,WAAU,SAAS,sBAG1D,CAAA;AAED,eAAO,MAAM,SAAS,UAAW,OAAO,WAAU,SAAS
|
|
1
|
+
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../../src/address.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAe,MAAM,UAAU,CAAA;AACpD,OAAO,EAAE,GAAG,EAAE,SAAS,EAAoC,MAAM,OAAO,CAAA;AAExE,MAAM,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,EAAE,wBAAwB,CAAC,CAAA;AAE5D,eAAO,MAAM,SAAS,UAAW,OAAO,WAAU,SAAS,sBAG1D,CAAA;AAED,eAAO,MAAM,SAAS,UAAW,OAAO,WAAU,SAAS,KAAQ,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"}
|
|
@@ -2,7 +2,7 @@ import { AssertConfig } from './assert';
|
|
|
2
2
|
import { Hex, HexConfig } from './hex';
|
|
3
3
|
export type Address = Exclude<Hex, 'reserved-address-value'>;
|
|
4
4
|
export declare const toAddress: (value: unknown, config?: HexConfig) => Lowercase<string>;
|
|
5
|
-
export declare const isAddress: (value: unknown, config?: HexConfig) => value is
|
|
5
|
+
export declare const isAddress: (value: unknown, config?: HexConfig) => value is Address;
|
|
6
6
|
export declare function asAddress(value: unknown): Address | undefined;
|
|
7
7
|
export declare function asAddress(value: unknown, assert: AssertConfig): Address;
|
|
8
8
|
//# sourceMappingURL=address.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../../src/address.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAe,MAAM,UAAU,CAAA;AACpD,OAAO,EAAE,GAAG,EAAE,SAAS,EAAoC,MAAM,OAAO,CAAA;AAExE,MAAM,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,EAAE,wBAAwB,CAAC,CAAA;AAE5D,eAAO,MAAM,SAAS,UAAW,OAAO,WAAU,SAAS,sBAG1D,CAAA;AAED,eAAO,MAAM,SAAS,UAAW,OAAO,WAAU,SAAS
|
|
1
|
+
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../../src/address.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAe,MAAM,UAAU,CAAA;AACpD,OAAO,EAAE,GAAG,EAAE,SAAS,EAAoC,MAAM,OAAO,CAAA;AAExE,MAAM,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,EAAE,wBAAwB,CAAC,CAAA;AAE5D,eAAO,MAAM,SAAS,UAAW,OAAO,WAAU,SAAS,sBAG1D,CAAA;AAED,eAAO,MAAM,SAAS,UAAW,OAAO,WAAU,SAAS,KAAQ,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"}
|
package/dist/neutral/hash.d.cts
CHANGED
|
@@ -4,7 +4,7 @@ export type HashBitLength = 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096;
|
|
|
4
4
|
export declare const HashBitLength: HashBitLength[];
|
|
5
5
|
export declare const isHashBitLength: (value: unknown) => value is HashBitLength;
|
|
6
6
|
export type Hash = Exclude<Hex, 'reserved-hash-value'>;
|
|
7
|
-
export declare const isHash: (value: unknown, bitLength?: HashBitLength) => value is
|
|
7
|
+
export declare const isHash: (value: unknown, bitLength?: HashBitLength) => value is Hash;
|
|
8
8
|
export declare function asHash(value: unknown): Hash | undefined;
|
|
9
9
|
export declare function asHash(value: unknown, assert: AssertConfig): Hash;
|
|
10
10
|
//# sourceMappingURL=hash.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/hash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAe,MAAM,UAAU,CAAA;AACpD,OAAO,EAAE,GAAG,EAA2B,MAAM,OAAO,CAAA;AAEpD,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,UAAW,OAAO,
|
|
1
|
+
{"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/hash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAe,MAAM,UAAU,CAAA;AACpD,OAAO,EAAE,GAAG,EAA2B,MAAM,OAAO,CAAA;AAEpD,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,UAAW,OAAO,KAAG,KAAK,IAAI,aAEzD,CAAA;AAED,MAAM,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,EAAE,qBAAqB,CAAC,CAAA;AACtD,eAAO,MAAM,MAAM,UAAW,OAAO,cAAa,aAAa,KAAS,KAAK,IAAI,IAEhF,CAAA;AAED,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"}
|