@xylabs/hex 4.0.2 → 4.0.4

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.
Files changed (43) hide show
  1. package/dist/neutral/address.d.ts +8 -0
  2. package/dist/neutral/address.d.ts.map +1 -0
  3. package/dist/neutral/assert.d.ts +4 -0
  4. package/dist/neutral/assert.d.ts.map +1 -0
  5. package/dist/neutral/hash.d.ts +10 -0
  6. package/dist/neutral/hash.d.ts.map +1 -0
  7. package/dist/neutral/hex/as.d.ts +5 -0
  8. package/dist/neutral/hex/as.d.ts.map +1 -0
  9. package/dist/neutral/hex/from/from.d.ts +3 -0
  10. package/dist/neutral/hex/from/from.d.ts.map +1 -0
  11. package/dist/neutral/hex/from/fromArrayBuffer.d.ts +3 -0
  12. package/dist/neutral/hex/from/fromArrayBuffer.d.ts.map +1 -0
  13. package/dist/neutral/hex/from/fromBigInt.d.ts +3 -0
  14. package/dist/neutral/hex/from/fromBigInt.d.ts.map +1 -0
  15. package/dist/neutral/hex/from/fromHexString.d.ts +3 -0
  16. package/dist/neutral/hex/from/fromHexString.d.ts.map +1 -0
  17. package/dist/neutral/hex/from/fromNumber.d.ts +3 -0
  18. package/dist/neutral/hex/from/fromNumber.d.ts.map +1 -0
  19. package/dist/neutral/hex/from/index.d.ts +6 -0
  20. package/dist/neutral/hex/from/index.d.ts.map +1 -0
  21. package/dist/neutral/hex/index.d.ts +10 -0
  22. package/dist/neutral/hex/index.d.ts.map +1 -0
  23. package/dist/neutral/hex/is.d.ts +3 -0
  24. package/dist/neutral/hex/is.d.ts.map +1 -0
  25. package/dist/neutral/hex/isHexZero.d.ts +2 -0
  26. package/dist/neutral/hex/isHexZero.d.ts.map +1 -0
  27. package/dist/neutral/hex/legacy.d.ts +2 -0
  28. package/dist/neutral/hex/legacy.d.ts.map +1 -0
  29. package/dist/neutral/hex/model.d.ts +7 -0
  30. package/dist/neutral/hex/model.d.ts.map +1 -0
  31. package/dist/neutral/hex/nibble.d.ts +3 -0
  32. package/dist/neutral/hex/nibble.d.ts.map +1 -0
  33. package/dist/neutral/hex/regex.d.ts +3 -0
  34. package/dist/neutral/hex/regex.d.ts.map +1 -0
  35. package/dist/neutral/hex/to.d.ts +3 -0
  36. package/dist/neutral/hex/to.d.ts.map +1 -0
  37. package/dist/neutral/index.d.ts +4 -52
  38. package/dist/neutral/index.d.ts.map +1 -0
  39. package/dist/neutral/index.mjs +5 -1
  40. package/dist/neutral/index.mjs.map +1 -1
  41. package/package.json +28 -28
  42. package/src/address.ts +6 -2
  43. package/xy.config.ts +1 -3
@@ -0,0 +1,8 @@
1
+ import type { AssertConfig } from './assert.ts';
2
+ import type { Hex, HexConfig } from './hex/index.ts';
3
+ export type Address = Exclude<Hex, 'reserved-address-value'>;
4
+ export declare const toAddress: (value: string | number | bigint | ArrayBuffer, config?: HexConfig) => Lowercase<string>;
5
+ export declare const isAddress: (value: unknown, config?: HexConfig) => value is Address;
6
+ export declare function asAddress(value: unknown): Address | undefined;
7
+ export declare function asAddress(value: unknown, assert: AssertConfig): Address;
8
+ //# sourceMappingURL=address.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../../src/address.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE/C,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAKpD,MAAM,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,EAAE,wBAAwB,CAAC,CAAA;AAE5D,eAAO,MAAM,SAAS,UAAW,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,WAAW,WAAU,SAAS,sBAKzF,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"}
@@ -0,0 +1,4 @@
1
+ export type AssertCallback = (value: unknown, message: string) => string | boolean;
2
+ export type AssertConfig = string | AssertCallback | boolean;
3
+ export declare const assertError: (value: unknown, assert: AssertConfig | undefined, defaultMessage: string) => undefined;
4
+ //# sourceMappingURL=assert.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../src/assert.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,KAAK,MAAM,GAAG,OAAO,CAAA;AAElF,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,cAAc,GAAG,OAAO,CAAA;AAE5D,eAAO,MAAM,WAAW,UAAW,OAAO,UAAU,YAAY,GAAG,SAAS,kBAAkB,MAAM,cAcnG,CAAA"}
@@ -0,0 +1,10 @@
1
+ import type { AssertConfig } from './assert.ts';
2
+ import type { Hex } from './hex/index.ts';
3
+ export type HashBitLength = 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096;
4
+ export declare const HashBitLength: HashBitLength[];
5
+ export declare const isHashBitLength: (value: unknown) => value is HashBitLength;
6
+ export type Hash = Exclude<Hex, 'reserved-hash-value'>;
7
+ export declare const isHash: (value: unknown, bitLength?: HashBitLength) => value is Hash;
8
+ export declare function asHash(value: unknown): Hash | undefined;
9
+ export declare function asHash(value: unknown, assert: AssertConfig): Hash;
10
+ //# sourceMappingURL=hash.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/hash.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE/C,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAA;AAGzC,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"}
@@ -0,0 +1,5 @@
1
+ import type { AssertConfig } from '../assert.ts';
2
+ import type { Hex } from './model.ts';
3
+ export declare function asHex(value: unknown): Hex | undefined;
4
+ export declare function asHex(value: unknown, assert: AssertConfig): Hex;
5
+ //# sourceMappingURL=as.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"as.d.ts","sourceRoot":"","sources":["../../../src/hex/as.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAIhD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,YAAY,CAAA;AAErC,wBAAgB,KAAK,CAAC,KAAK,EAAE,OAAO,GAAG,GAAG,GAAG,SAAS,CAAA;AACtD,wBAAgB,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,GAAG,GAAG,CAAA"}
@@ -0,0 +1,3 @@
1
+ import type { Hex, HexConfig } from '../model.ts';
2
+ export declare const hexFrom: (value: string | number | bigint | ArrayBuffer, config?: HexConfig) => Hex;
3
+ //# sourceMappingURL=from.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"from.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/from.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAOjD,eAAO,MAAM,OAAO,UAEX,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,WAAW,WAEpC,SAAS,KACjB,GAkBF,CAAA"}
@@ -0,0 +1,3 @@
1
+ import type { Hex, HexConfig } from '../model.ts';
2
+ export declare const hexFromArrayBuffer: (buffer: ArrayBuffer, config?: HexConfig) => Hex;
3
+ //# sourceMappingURL=fromArrayBuffer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fromArrayBuffer.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/fromArrayBuffer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAIjD,eAAO,MAAM,kBAAkB,WAErB,WAAW,WAEV,SAAS,KACjB,GAGF,CAAA"}
@@ -0,0 +1,3 @@
1
+ import type { Hex, HexConfig } from '../model.ts';
2
+ export declare const hexFromBigInt: (value: bigint, config?: HexConfig) => Hex;
3
+ //# sourceMappingURL=fromBigInt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fromBigInt.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/fromBigInt.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAKjD,eAAO,MAAM,aAAa,UAEjB,MAAM,WAEL,SAAS,KAChB,GAKF,CAAA"}
@@ -0,0 +1,3 @@
1
+ import type { Hex, HexConfig } from '../model.ts';
2
+ export declare const hexFromHexString: (value: string, config?: HexConfig) => Hex;
3
+ //# sourceMappingURL=fromHexString.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fromHexString.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/fromHexString.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAGjD,eAAO,MAAM,gBAAgB,UAAW,MAAM,WAAU,SAAS,KAAQ,GAUxE,CAAA"}
@@ -0,0 +1,3 @@
1
+ import type { Hex, HexConfig } from '../model.ts';
2
+ export declare const hexFromNumber: (value: number, config?: HexConfig) => Hex;
3
+ //# sourceMappingURL=fromNumber.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fromNumber.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/fromNumber.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAGjD,eAAO,MAAM,aAAa,UAAW,MAAM,WAAW,SAAS,KAAG,GAEjE,CAAA"}
@@ -0,0 +1,6 @@
1
+ export * from './from.ts';
2
+ export * from './fromArrayBuffer.ts';
3
+ export * from './fromBigInt.ts';
4
+ export * from './fromHexString.ts';
5
+ export * from './fromNumber.ts';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,sBAAsB,CAAA;AACpC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,oBAAoB,CAAA;AAClC,cAAc,iBAAiB,CAAA"}
@@ -0,0 +1,10 @@
1
+ export * from './as.ts';
2
+ export * from './from/index.ts';
3
+ export * from './is.ts';
4
+ export * from './isHexZero.ts';
5
+ export * from './legacy.ts';
6
+ export * from './model.ts';
7
+ export * from './nibble.ts';
8
+ export * from './regex.ts';
9
+ export * from './to.ts';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hex/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,SAAS,CAAA;AACvB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,SAAS,CAAA"}
@@ -0,0 +1,3 @@
1
+ import type { Hex, HexConfig } from './model.ts';
2
+ export declare const isHex: (value: unknown, config?: HexConfig) => value is Hex;
3
+ //# sourceMappingURL=is.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is.d.ts","sourceRoot":"","sources":["../../../src/hex/is.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAIhD,eAAO,MAAM,KAAK,UAAW,OAAO,WAAW,SAAS,KAAG,KAAK,IAAI,GAWnE,CAAA"}
@@ -0,0 +1,2 @@
1
+ export declare const isHexZero: (value?: string) => boolean | undefined;
2
+ //# sourceMappingURL=isHexZero.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isHexZero.d.ts","sourceRoot":"","sources":["../../../src/hex/isHexZero.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,SAAS,WAAY,MAAM,wBAEvC,CAAA"}
@@ -0,0 +1,2 @@
1
+ export declare const toHexLegacy: (buffer: ArrayBuffer) => string;
2
+ //# sourceMappingURL=legacy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"legacy.d.ts","sourceRoot":"","sources":["../../../src/hex/legacy.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,WAAY,WAAW,WAE9C,CAAA"}
@@ -0,0 +1,7 @@
1
+ export type Hex = Exclude<Lowercase<string>, 'reserved-hex-value'>;
2
+ export interface HexConfig {
3
+ bitLength?: number;
4
+ byteSize?: number;
5
+ prefix?: boolean;
6
+ }
7
+ //# sourceMappingURL=model.d.ts.map
@@ -0,0 +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;AAGlE,MAAM,WAAW,SAAS;IACxB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB"}
@@ -0,0 +1,3 @@
1
+ export declare const bitsToNibbles: (value: number) => number;
2
+ export declare const nibblesToBits: (value: number) => number;
3
+ //# sourceMappingURL=nibble.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nibble.d.ts","sourceRoot":"","sources":["../../../src/hex/nibble.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,aAAa,UAAW,MAAM,KAAG,MAI7C,CAAA;AAGD,eAAO,MAAM,aAAa,UAAW,MAAM,KAAG,MAE7C,CAAA"}
@@ -0,0 +1,3 @@
1
+ export declare const hexRegex: RegExp;
2
+ export declare const hexRegexWithPrefix: RegExp;
3
+ //# sourceMappingURL=regex.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"regex.d.ts","sourceRoot":"","sources":["../../../src/hex/regex.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,QAAQ,QAAgB,CAAA;AACrC,eAAO,MAAM,kBAAkB,QAAiB,CAAA"}
@@ -0,0 +1,3 @@
1
+ import type { HexConfig } from './model.ts';
2
+ export declare const toHex: (value: string | number | bigint | ArrayBuffer, config?: HexConfig) => Lowercase<string>;
3
+ //# sourceMappingURL=to.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"to.d.ts","sourceRoot":"","sources":["../../../src/hex/to.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAG3C,eAAO,MAAM,KAAK,UAET,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,WAAW,WAErC,SAAS,sBAIlB,CAAA"}
@@ -1,52 +1,4 @@
1
- type AssertCallback = (value: unknown, message: string) => string | boolean;
2
- type AssertConfig = string | AssertCallback | boolean;
3
-
4
- type Hex = Exclude<Lowercase<string>, 'reserved-hex-value'>;
5
- interface HexConfig {
6
- bitLength?: number;
7
- byteSize?: number;
8
- prefix?: boolean;
9
- }
10
-
11
- declare function asHex(value: unknown): Hex | undefined;
12
- declare function asHex(value: unknown, assert: AssertConfig): Hex;
13
-
14
- declare const hexFrom: (value: string | number | bigint | ArrayBuffer, config?: HexConfig) => Hex;
15
-
16
- declare const hexFromArrayBuffer: (buffer: ArrayBuffer, config?: HexConfig) => Hex;
17
-
18
- declare const hexFromBigInt: (value: bigint, config?: HexConfig) => Hex;
19
-
20
- declare const hexFromHexString: (value: string, config?: HexConfig) => Hex;
21
-
22
- declare const hexFromNumber: (value: number, config?: HexConfig) => Hex;
23
-
24
- declare const isHex: (value: unknown, config?: HexConfig) => value is Hex;
25
-
26
- declare const isHexZero: (value?: string) => boolean | undefined;
27
-
28
- declare const toHexLegacy: (buffer: ArrayBuffer) => string;
29
-
30
- declare const bitsToNibbles: (value: number) => number;
31
- declare const nibblesToBits: (value: number) => number;
32
-
33
- declare const hexRegex: RegExp;
34
- declare const hexRegexWithPrefix: RegExp;
35
-
36
- declare const toHex: (value: string | number | bigint | ArrayBuffer, config?: HexConfig) => Lowercase<string>;
37
-
38
- type Address = Exclude<Hex, 'reserved-address-value'>;
39
- declare const toAddress: (value: string | number | bigint | ArrayBuffer, config?: HexConfig) => Lowercase<string>;
40
- declare const isAddress: (value: unknown, config?: HexConfig) => value is Address;
41
- declare function asAddress(value: unknown): Address | undefined;
42
- declare function asAddress(value: unknown, assert: AssertConfig): Address;
43
-
44
- type HashBitLength = 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096;
45
- declare const HashBitLength: HashBitLength[];
46
- declare const isHashBitLength: (value: unknown) => value is HashBitLength;
47
- type Hash = Exclude<Hex, 'reserved-hash-value'>;
48
- declare const isHash: (value: unknown, bitLength?: HashBitLength) => value is Hash;
49
- declare function asHash(value: unknown): Hash | undefined;
50
- declare function asHash(value: unknown, assert: AssertConfig): Hash;
51
-
52
- export { type Address, type Hash, HashBitLength, type Hex, type HexConfig, asAddress, asHash, asHex, bitsToNibbles, hexFrom, hexFromArrayBuffer, hexFromBigInt, hexFromHexString, hexFromNumber, hexRegex, hexRegexWithPrefix, isAddress, isHash, isHashBitLength, isHex, isHexZero, nibblesToBits, toAddress, toHex, toHexLegacy };
1
+ export * from './address.ts';
2
+ export * from './hash.ts';
3
+ export * from './hex/index.ts';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,WAAW,CAAA;AACzB,cAAc,gBAAgB,CAAA"}
@@ -118,7 +118,11 @@ var toHex = (value, config = {}) => {
118
118
  // src/address.ts
119
119
  var toAddress = (value, config = {}) => {
120
120
  const { bitLength = 160, prefix = false } = config;
121
- return hexFrom(value, { bitLength, prefix, ...config });
121
+ return hexFrom(value, {
122
+ bitLength,
123
+ prefix,
124
+ ...config
125
+ });
122
126
  };
123
127
  var isAddress = (value, config = {}) => {
124
128
  const { bitLength = 160, prefix = false } = config;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/assert.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/from/from.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'\n ? assert\n : typeof assert === 'boolean'\n ? 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","// determine the number of nibbles for a given number of bits\nexport const bitsToNibbles = (value: number): number => {\n const nibbles = value >> 2\n if (value !== nibbles << 2) throw new Error('Bits for nibbles must multiple of 4')\n return nibbles\n}\n\n// determine the number of nibbles for a given number of bits\nexport const nibblesToBits = (value: number): number => {\n return value << 2\n}\n","export const hexRegex = /^[\\da-f]+$/i\nexport const hexRegexWithPrefix = /0x[\\da-f]+$/i\n","import type { Hex, HexConfig } from './model.ts'\nimport { bitsToNibbles } from './nibble.ts'\nimport { hexRegex, hexRegexWithPrefix } from './regex.ts'\n\nexport const isHex = (value: unknown, config?: HexConfig): value is Hex => {\n // Is it a string?\n if (typeof value !== 'string') return false\n\n const valueCharLength = config?.prefix ? value.length - 2 : value.length\n\n // If a bitLength specified, does it conform?\n if (config?.bitLength !== undefined && valueCharLength !== bitsToNibbles(config?.bitLength)) return false\n\n // Does it only has hex values?\n return config?.prefix ? hexRegexWithPrefix.test(value) : hexRegex.test(value)\n}\n","import { isHex } from '../is.ts'\nimport type { Hex, HexConfig } from '../model.ts'\nimport { bitsToNibbles } from '../nibble.ts'\n\nexport const hexFromHexString = (value: string, config: HexConfig = {}): Hex => {\n const { 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 type { Hex, HexConfig } from '../model.ts'\nimport { hexFromHexString } from './fromHexString.ts'\n\n/** Convert an ArrayBuffer to a hex string */\nexport const hexFromArrayBuffer = (\n /** The buffer to be converted */\n buffer: 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 type { Hex, HexConfig } from '../model.ts'\nimport { bitsToNibbles } from '../nibble.ts'\nimport { hexFromHexString } from './fromHexString.ts'\n\n/** Convert a bigint to a hex string */\nexport const hexFromBigInt = (\n /** The bigint to be converted */\n value: bigint,\n /** Configuration of output format and validation */\n config: HexConfig = {},\n): Hex => {\n const { 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 type { Hex, HexConfig } from '../model.ts'\nimport { hexFromBigInt } from './fromBigInt.ts'\n\nexport const hexFromNumber = (value: number, config?: HexConfig): Hex => {\n return hexFromBigInt(BigInt(value), config)\n}\n","import type { Hex, HexConfig } from '../model.ts'\nimport { hexFromArrayBuffer } from './fromArrayBuffer.ts'\nimport { hexFromBigInt } from './fromBigInt.ts'\nimport { hexFromHexString } from './fromHexString.ts'\nimport { hexFromNumber } from './fromNumber.ts'\n\n/** Takes unknown value and tries our best to convert it to a hex string */\nexport const hexFrom = (\n /** Supported types are string, number, bigint, and ArrayBuffer */\n value: string | number | bigint | ArrayBuffer,\n /** Configuration of output format and validation */\n config?: HexConfig,\n): Hex => {\n switch (typeof value) {\n case 'string': {\n return hexFromHexString(value, config)\n }\n case 'bigint': {\n return hexFromBigInt(value, config)\n }\n case 'number': {\n return hexFromNumber(value, config)\n }\n case 'object': {\n return hexFromArrayBuffer(value, config)\n }\n default: {\n throw new Error(`Invalid type: ${typeof value}`)\n }\n }\n}\n","import type { AssertConfig } from '../assert.ts'\nimport { assertError } from '../assert.ts'\nimport { hexFromHexString } from './from/index.ts'\nimport { isHex } from './is.ts'\nimport type { Hex } from './model.ts'\n\nexport function asHex(value: unknown): Hex | undefined\nexport function asHex(value: unknown, assert: AssertConfig): Hex\nexport function asHex(value: unknown, assert?: AssertConfig): Hex | undefined {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value)\n break\n }\n default: {\n return assertError(value, assert, `Unsupported type [${typeof value}]`)\n }\n }\n\n return isHex(stringValue) ? stringValue : assertError(value, assert, `Value is not Hex [${value}]`)\n}\n","import { hexFromHexString } from './from/index.ts'\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/index.ts'\nimport type { HexConfig } from './model.ts'\n\n/** takes any value and tries our best to convert it to a hex string */\nexport const toHex = (\n /** Supported types are string, number, bigint, and ArrayBuffer */\n value: string | number | bigint | ArrayBuffer,\n /** Configuration of output format and validation */\n config: HexConfig = {},\n) => {\n const { prefix = false } = config\n return hexFrom(value, { prefix, ...config })\n}\n","import type { AssertConfig } from './assert.ts'\nimport { assertError } from './assert.ts'\nimport type { Hex, HexConfig } from './hex/index.ts'\nimport { hexFrom, hexFromHexString, isHex } from './hex/index.ts'\n\nexport type Address = Exclude<Hex, 'reserved-address-value'>\n\nexport const toAddress = (value: string | number | bigint | ArrayBuffer, 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 type { AssertConfig } from './assert.ts'\nimport { assertError } from './assert.ts'\nimport type { Hex } from './hex/index.ts'\nimport { hexFromHexString, isHex } from './hex/index.ts'\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,eACF,OAAO,WAAW,WAChB,SACA,OAAO,WAAW,YAChB,iBACA,OAAO,OAAO,cAAc;AACpC,QAAI,cAAc;AAChB,YAAM,IAAI,MAAM,iBAAiB,OAAO,iBAAiB,YAAY;AAAA,IACvE;AAAA,EACF;AAEA,SAAO;AACT;;;ACjBO,IAAM,gBAAgB,CAAC,UAA0B;AACtD,QAAM,UAAU,SAAS;AACzB,MAAI,UAAU,WAAW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,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":[]}
1
+ {"version":3,"sources":["../../src/assert.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/from/from.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'\n ? assert\n : typeof assert === 'boolean'\n ? 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","// determine the number of nibbles for a given number of bits\nexport const bitsToNibbles = (value: number): number => {\n const nibbles = value >> 2\n if (value !== nibbles << 2) throw new Error('Bits for nibbles must multiple of 4')\n return nibbles\n}\n\n// determine the number of nibbles for a given number of bits\nexport const nibblesToBits = (value: number): number => {\n return value << 2\n}\n","export const hexRegex = /^[\\da-f]+$/i\nexport const hexRegexWithPrefix = /0x[\\da-f]+$/i\n","import type { Hex, HexConfig } from './model.ts'\nimport { bitsToNibbles } from './nibble.ts'\nimport { hexRegex, hexRegexWithPrefix } from './regex.ts'\n\nexport const isHex = (value: unknown, config?: HexConfig): value is Hex => {\n // Is it a string?\n if (typeof value !== 'string') return false\n\n const valueCharLength = config?.prefix ? value.length - 2 : value.length\n\n // If a bitLength specified, does it conform?\n if (config?.bitLength !== undefined && valueCharLength !== bitsToNibbles(config?.bitLength)) return false\n\n // Does it only has hex values?\n return config?.prefix ? hexRegexWithPrefix.test(value) : hexRegex.test(value)\n}\n","import { isHex } from '../is.ts'\nimport type { Hex, HexConfig } from '../model.ts'\nimport { bitsToNibbles } from '../nibble.ts'\n\nexport const hexFromHexString = (value: string, config: HexConfig = {}): Hex => {\n const { 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 type { Hex, HexConfig } from '../model.ts'\nimport { hexFromHexString } from './fromHexString.ts'\n\n/** Convert an ArrayBuffer to a hex string */\nexport const hexFromArrayBuffer = (\n /** The buffer to be converted */\n buffer: 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 type { Hex, HexConfig } from '../model.ts'\nimport { bitsToNibbles } from '../nibble.ts'\nimport { hexFromHexString } from './fromHexString.ts'\n\n/** Convert a bigint to a hex string */\nexport const hexFromBigInt = (\n /** The bigint to be converted */\n value: bigint,\n /** Configuration of output format and validation */\n config: HexConfig = {},\n): Hex => {\n const { 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 type { Hex, HexConfig } from '../model.ts'\nimport { hexFromBigInt } from './fromBigInt.ts'\n\nexport const hexFromNumber = (value: number, config?: HexConfig): Hex => {\n return hexFromBigInt(BigInt(value), config)\n}\n","import type { Hex, HexConfig } from '../model.ts'\nimport { hexFromArrayBuffer } from './fromArrayBuffer.ts'\nimport { hexFromBigInt } from './fromBigInt.ts'\nimport { hexFromHexString } from './fromHexString.ts'\nimport { hexFromNumber } from './fromNumber.ts'\n\n/** Takes unknown value and tries our best to convert it to a hex string */\nexport const hexFrom = (\n /** Supported types are string, number, bigint, and ArrayBuffer */\n value: string | number | bigint | ArrayBuffer,\n /** Configuration of output format and validation */\n config?: HexConfig,\n): Hex => {\n switch (typeof value) {\n case 'string': {\n return hexFromHexString(value, config)\n }\n case 'bigint': {\n return hexFromBigInt(value, config)\n }\n case 'number': {\n return hexFromNumber(value, config)\n }\n case 'object': {\n return hexFromArrayBuffer(value, config)\n }\n default: {\n throw new Error(`Invalid type: ${typeof value}`)\n }\n }\n}\n","import type { AssertConfig } from '../assert.ts'\nimport { assertError } from '../assert.ts'\nimport { hexFromHexString } from './from/index.ts'\nimport { isHex } from './is.ts'\nimport type { Hex } from './model.ts'\n\nexport function asHex(value: unknown): Hex | undefined\nexport function asHex(value: unknown, assert: AssertConfig): Hex\nexport function asHex(value: unknown, assert?: AssertConfig): Hex | undefined {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value)\n break\n }\n default: {\n return assertError(value, assert, `Unsupported type [${typeof value}]`)\n }\n }\n\n return isHex(stringValue) ? stringValue : assertError(value, assert, `Value is not Hex [${value}]`)\n}\n","import { hexFromHexString } from './from/index.ts'\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/index.ts'\nimport type { HexConfig } from './model.ts'\n\n/** takes any value and tries our best to convert it to a hex string */\nexport const toHex = (\n /** Supported types are string, number, bigint, and ArrayBuffer */\n value: string | number | bigint | ArrayBuffer,\n /** Configuration of output format and validation */\n config: HexConfig = {},\n) => {\n const { prefix = false } = config\n return hexFrom(value, { prefix, ...config })\n}\n","import type { AssertConfig } from './assert.ts'\nimport { assertError } from './assert.ts'\nimport type { Hex, HexConfig } from './hex/index.ts'\nimport {\n hexFrom, hexFromHexString, isHex,\n} from './hex/index.ts'\n\nexport type Address = Exclude<Hex, 'reserved-address-value'>\n\nexport const toAddress = (value: string | number | bigint | ArrayBuffer, config: HexConfig = {}) => {\n const { bitLength = 160, prefix = false } = config\n return hexFrom(value, {\n bitLength, prefix, ...config,\n })\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 type { AssertConfig } from './assert.ts'\nimport { assertError } from './assert.ts'\nimport type { Hex } from './hex/index.ts'\nimport { hexFromHexString, isHex } from './hex/index.ts'\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,eACF,OAAO,WAAW,WAChB,SACA,OAAO,WAAW,YAChB,iBACA,OAAO,OAAO,cAAc;AACpC,QAAI,cAAc;AAChB,YAAM,IAAI,MAAM,iBAAiB,OAAO,iBAAiB,YAAY;AAAA,IACvE;AAAA,EACF;AAEA,SAAO;AACT;;;ACjBO,IAAM,gBAAgB,CAAC,UAA0B;AACtD,QAAM,UAAU,SAAS;AACzB,MAAI,UAAU,WAAW,EAAG,OAAM,IAAI,MAAM,qCAAqC;AACjF,SAAO;AACT;AAGO,IAAM,gBAAgB,CAAC,UAA0B;AACtD,SAAO,SAAS;AAClB;;;ACVO,IAAM,WAAW;AACjB,IAAM,qBAAqB;;;ACG3B,IAAM,QAAQ,CAAC,OAAgB,WAAqC;AAEzE,MAAI,OAAO,UAAU,SAAU,QAAO;AAEtC,QAAM,kBAAkB,QAAQ,SAAS,MAAM,SAAS,IAAI,MAAM;AAGlE,MAAI,QAAQ,cAAc,UAAa,oBAAoB,cAAc,QAAQ,SAAS,EAAG,QAAO;AAGpG,SAAO,QAAQ,SAAS,mBAAmB,KAAK,KAAK,IAAI,SAAS,KAAK,KAAK;AAC9E;;;ACXO,IAAM,mBAAmB,CAAC,OAAe,SAAoB,CAAC,MAAW;AAC9E,QAAM,EAAE,SAAS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U,OAAgB,QAA4C;AACpF,MAAI;AACF,QAAI,cAAkC;AAEtC,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;;;ACnCO,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/package.json CHANGED
@@ -1,19 +1,31 @@
1
1
  {
2
- "license": "LGPL-3.0-only",
3
2
  "name": "@xylabs/hex",
3
+ "version": "4.0.4",
4
+ "description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
5
+ "keywords": [
6
+ "hex",
7
+ "xylabs",
8
+ "utility",
9
+ "typescript",
10
+ "esm"
11
+ ],
12
+ "homepage": "https://xylabs.com",
13
+ "bugs": {
14
+ "url": "git+https://github.com/xylabs/sdk-js/issues",
15
+ "email": "support@xylabs.com"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/xylabs/sdk-js.git"
20
+ },
21
+ "license": "LGPL-3.0-only",
4
22
  "author": {
5
- "email": "support@xylabs.com",
6
23
  "name": "XY Labs Development Team",
7
- "url": "https://xylabs.com"
8
- },
9
- "bugs": {
10
24
  "email": "support@xylabs.com",
11
- "url": "git+https://github.com/xylabs/sdk-js/issues"
25
+ "url": "https://xylabs.com"
12
26
  },
13
- "workspaces": [
14
- "packages/**/*"
15
- ],
16
- "description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
27
+ "sideEffects": false,
28
+ "type": "module",
17
29
  "exports": {
18
30
  ".": {
19
31
  "types": "./dist/neutral/index.d.ts",
@@ -21,19 +33,14 @@
21
33
  },
22
34
  "./package.json": "./package.json"
23
35
  },
24
- "types": "./dist/neutral/index.d.ts",
25
36
  "module": "./dist/neutral/index.mjs",
26
- "homepage": "https://xylabs.com",
27
- "keywords": [
28
- "hex",
29
- "xylabs",
30
- "utility",
31
- "typescript",
32
- "esm"
37
+ "types": "./dist/neutral/index.d.ts",
38
+ "workspaces": [
39
+ "packages/**/*"
33
40
  ],
34
41
  "devDependencies": {
35
- "@xylabs/ts-scripts-yarn3": "^4.0.0-rc.15",
36
- "@xylabs/tsconfig": "^4.0.0-rc.15",
42
+ "@xylabs/ts-scripts-yarn3": "^4.0.7",
43
+ "@xylabs/tsconfig": "^4.0.7",
37
44
  "typescript": "^5.5.4"
38
45
  },
39
46
  "engines": {
@@ -41,12 +48,5 @@
41
48
  },
42
49
  "publishConfig": {
43
50
  "access": "public"
44
- },
45
- "repository": {
46
- "type": "git",
47
- "url": "git+https://github.com/xylabs/sdk-js.git"
48
- },
49
- "sideEffects": false,
50
- "version": "4.0.2",
51
- "type": "module"
51
+ }
52
52
  }
package/src/address.ts CHANGED
@@ -1,13 +1,17 @@
1
1
  import type { AssertConfig } from './assert.ts'
2
2
  import { assertError } from './assert.ts'
3
3
  import type { Hex, HexConfig } from './hex/index.ts'
4
- import { hexFrom, hexFromHexString, isHex } from './hex/index.ts'
4
+ import {
5
+ hexFrom, hexFromHexString, isHex,
6
+ } from './hex/index.ts'
5
7
 
6
8
  export type Address = Exclude<Hex, 'reserved-address-value'>
7
9
 
8
10
  export const toAddress = (value: string | number | bigint | ArrayBuffer, config: HexConfig = {}) => {
9
11
  const { bitLength = 160, prefix = false } = config
10
- return hexFrom(value, { bitLength, prefix, ...config })
12
+ return hexFrom(value, {
13
+ bitLength, prefix, ...config,
14
+ })
11
15
  }
12
16
 
13
17
  export const isAddress = (value: unknown, config: HexConfig = {}): value is Address => {
package/xy.config.ts CHANGED
@@ -2,9 +2,7 @@ import type { XyTsupConfig } from '@xylabs/ts-scripts-yarn3'
2
2
  const config: XyTsupConfig = {
3
3
  compile: {
4
4
  browser: {},
5
- neutral: {
6
- src: true,
7
- },
5
+ neutral: { src: true },
8
6
  node: {},
9
7
  },
10
8
  }