@xylabs/hex 2.15.1 → 3.0.1

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 (84) hide show
  1. package/dist/browser/address.d.cts +2 -2
  2. package/dist/browser/address.d.cts.map +1 -1
  3. package/dist/browser/address.d.mts +2 -2
  4. package/dist/browser/address.d.mts.map +1 -1
  5. package/dist/browser/address.d.ts +2 -2
  6. package/dist/browser/address.d.ts.map +1 -1
  7. package/dist/browser/hash.d.cts +1 -1
  8. package/dist/browser/hash.d.cts.map +1 -1
  9. package/dist/browser/hash.d.mts +1 -1
  10. package/dist/browser/hash.d.mts.map +1 -1
  11. package/dist/browser/hash.d.ts +1 -1
  12. package/dist/browser/hash.d.ts.map +1 -1
  13. package/dist/browser/hex/from/from.d.cts +5 -5
  14. package/dist/browser/hex/from/from.d.cts.map +1 -1
  15. package/dist/browser/hex/from/from.d.mts +5 -5
  16. package/dist/browser/hex/from/from.d.mts.map +1 -1
  17. package/dist/browser/hex/from/from.d.ts +5 -5
  18. package/dist/browser/hex/from/from.d.ts.map +1 -1
  19. package/dist/browser/hex/from/fromHexString.d.cts +2 -2
  20. package/dist/browser/hex/from/fromHexString.d.cts.map +1 -1
  21. package/dist/browser/hex/from/fromHexString.d.mts +2 -2
  22. package/dist/browser/hex/from/fromHexString.d.mts.map +1 -1
  23. package/dist/browser/hex/from/fromHexString.d.ts +2 -2
  24. package/dist/browser/hex/from/fromHexString.d.ts.map +1 -1
  25. package/dist/browser/hex/is.d.cts +1 -1
  26. package/dist/browser/hex/is.d.cts.map +1 -1
  27. package/dist/browser/hex/is.d.mts +1 -1
  28. package/dist/browser/hex/is.d.mts.map +1 -1
  29. package/dist/browser/hex/is.d.ts +1 -1
  30. package/dist/browser/hex/is.d.ts.map +1 -1
  31. package/dist/browser/hex/model.d.cts +1 -1
  32. package/dist/browser/hex/model.d.cts.map +1 -1
  33. package/dist/browser/hex/model.d.mts +1 -1
  34. package/dist/browser/hex/model.d.mts.map +1 -1
  35. package/dist/browser/hex/model.d.ts +1 -1
  36. package/dist/browser/hex/model.d.ts.map +1 -1
  37. package/dist/browser/index.cjs +1 -1
  38. package/dist/browser/index.cjs.map +1 -1
  39. package/dist/browser/index.js +1 -1
  40. package/dist/browser/index.js.map +1 -1
  41. package/dist/node/address.d.cts +2 -2
  42. package/dist/node/address.d.cts.map +1 -1
  43. package/dist/node/address.d.mts +2 -2
  44. package/dist/node/address.d.mts.map +1 -1
  45. package/dist/node/address.d.ts +2 -2
  46. package/dist/node/address.d.ts.map +1 -1
  47. package/dist/node/hash.d.cts +1 -1
  48. package/dist/node/hash.d.cts.map +1 -1
  49. package/dist/node/hash.d.mts +1 -1
  50. package/dist/node/hash.d.mts.map +1 -1
  51. package/dist/node/hash.d.ts +1 -1
  52. package/dist/node/hash.d.ts.map +1 -1
  53. package/dist/node/hex/from/from.d.cts +5 -5
  54. package/dist/node/hex/from/from.d.cts.map +1 -1
  55. package/dist/node/hex/from/from.d.mts +5 -5
  56. package/dist/node/hex/from/from.d.mts.map +1 -1
  57. package/dist/node/hex/from/from.d.ts +5 -5
  58. package/dist/node/hex/from/from.d.ts.map +1 -1
  59. package/dist/node/hex/from/fromHexString.d.cts +2 -2
  60. package/dist/node/hex/from/fromHexString.d.cts.map +1 -1
  61. package/dist/node/hex/from/fromHexString.d.mts +2 -2
  62. package/dist/node/hex/from/fromHexString.d.mts.map +1 -1
  63. package/dist/node/hex/from/fromHexString.d.ts +2 -2
  64. package/dist/node/hex/from/fromHexString.d.ts.map +1 -1
  65. package/dist/node/hex/is.d.cts +1 -1
  66. package/dist/node/hex/is.d.cts.map +1 -1
  67. package/dist/node/hex/is.d.mts +1 -1
  68. package/dist/node/hex/is.d.mts.map +1 -1
  69. package/dist/node/hex/is.d.ts +1 -1
  70. package/dist/node/hex/is.d.ts.map +1 -1
  71. package/dist/node/hex/model.d.cts +1 -1
  72. package/dist/node/hex/model.d.cts.map +1 -1
  73. package/dist/node/hex/model.d.mts +1 -1
  74. package/dist/node/hex/model.d.mts.map +1 -1
  75. package/dist/node/hex/model.d.ts +1 -1
  76. package/dist/node/hex/model.d.ts.map +1 -1
  77. package/dist/node/index.cjs +1 -1
  78. package/dist/node/index.cjs.map +1 -1
  79. package/dist/node/index.js +1 -1
  80. package/dist/node/index.js.map +1 -1
  81. package/package.json +2 -2
  82. package/src/hex/from/from.ts +5 -5
  83. package/src/hex/from/fromHexString.ts +3 -3
  84. package/src/hex/model.ts +1 -1
@@ -1,8 +1,8 @@
1
1
  import { AssertConfig } from './assert';
2
2
  import { Hex, HexConfig } from './hex';
3
3
  export type Address = Hex;
4
- export declare const toAddress: (value: unknown, config?: HexConfig) => string;
5
- export declare const isAddress: (value: unknown, bitLength?: number) => value is string;
4
+ export declare const toAddress: (value: unknown, config?: HexConfig) => Lowercase<string>;
5
+ export declare const isAddress: (value: unknown, bitLength?: number) => value is Lowercase<string>;
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,GAAG,CAAA;AAEzB,eAAO,MAAM,SAAS,UAAW,OAAO,WAAU,SAAS,WAG1D,CAAA;AAED,eAAO,MAAM,SAAS,UAAW,OAAO,wCAEvC,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"}
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,GAAG,CAAA;AAEzB,eAAO,MAAM,SAAS,UAAW,OAAO,WAAU,SAAS,sBAG1D,CAAA;AAED,eAAO,MAAM,SAAS,UAAW,OAAO,mDAEvC,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"}
@@ -1,8 +1,8 @@
1
1
  import { AssertConfig } from './assert';
2
2
  import { Hex, HexConfig } from './hex';
3
3
  export type Address = Hex;
4
- export declare const toAddress: (value: unknown, config?: HexConfig) => string;
5
- export declare const isAddress: (value: unknown, bitLength?: number) => value is string;
4
+ export declare const toAddress: (value: unknown, config?: HexConfig) => Lowercase<string>;
5
+ export declare const isAddress: (value: unknown, bitLength?: number) => value is Lowercase<string>;
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,GAAG,CAAA;AAEzB,eAAO,MAAM,SAAS,UAAW,OAAO,WAAU,SAAS,WAG1D,CAAA;AAED,eAAO,MAAM,SAAS,UAAW,OAAO,wCAEvC,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"}
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,GAAG,CAAA;AAEzB,eAAO,MAAM,SAAS,UAAW,OAAO,WAAU,SAAS,sBAG1D,CAAA;AAED,eAAO,MAAM,SAAS,UAAW,OAAO,mDAEvC,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"}
@@ -1,8 +1,8 @@
1
1
  import { AssertConfig } from './assert';
2
2
  import { Hex, HexConfig } from './hex';
3
3
  export type Address = Hex;
4
- export declare const toAddress: (value: unknown, config?: HexConfig) => string;
5
- export declare const isAddress: (value: unknown, bitLength?: number) => value is string;
4
+ export declare const toAddress: (value: unknown, config?: HexConfig) => Lowercase<string>;
5
+ export declare const isAddress: (value: unknown, bitLength?: number) => value is Lowercase<string>;
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,GAAG,CAAA;AAEzB,eAAO,MAAM,SAAS,UAAW,OAAO,WAAU,SAAS,WAG1D,CAAA;AAED,eAAO,MAAM,SAAS,UAAW,OAAO,wCAEvC,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"}
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,GAAG,CAAA;AAEzB,eAAO,MAAM,SAAS,UAAW,OAAO,WAAU,SAAS,sBAG1D,CAAA;AAED,eAAO,MAAM,SAAS,UAAW,OAAO,mDAEvC,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"}
@@ -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 = Hex;
7
- export declare const isHash: (value: unknown, bitLength?: HashBitLength) => value is string;
7
+ export declare const isHash: (value: unknown, bitLength?: HashBitLength) => value is Lowercase<string>;
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,EA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 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 = Hex;
7
- export declare const isHash: (value: unknown, bitLength?: HashBitLength) => value is string;
7
+ export declare const isHash: (value: unknown, bitLength?: HashBitLength) => value is Lowercase<string>;
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,2BAE7C,CAAA;AAED,MAAM,MAAM,IAAI,GAAG,GAAG,CAAA;AACtB,eAAO,MAAM,MAAM,UAAW,OAAO,cAAa,aAAa,oBAE9D,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
+ {"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,2BAE7C,CAAA;AAED,MAAM,MAAM,IAAI,GAAG,GAAG,CAAA;AACtB,eAAO,MAAM,MAAM,UAAW,OAAO,cAAa,aAAa,+BAE9D,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"}
@@ -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 = Hex;
7
- export declare const isHash: (value: unknown, bitLength?: HashBitLength) => value is string;
7
+ export declare const isHash: (value: unknown, bitLength?: HashBitLength) => value is Lowercase<string>;
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,2BAE7C,CAAA;AAED,MAAM,MAAM,IAAI,GAAG,GAAG,CAAA;AACtB,eAAO,MAAM,MAAM,UAAW,OAAO,cAAa,aAAa,oBAE9D,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
+ {"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,2BAE7C,CAAA;AAED,MAAM,MAAM,IAAI,GAAG,GAAG,CAAA;AACtB,eAAO,MAAM,MAAM,UAAW,OAAO,cAAa,aAAa,+BAE9D,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,6 +1,6 @@
1
- import { HexConfig } from '../model';
2
- export declare const hexFromArrayBuffer: (buffer: ArrayBuffer, config?: HexConfig) => string;
3
- export declare const hexFromBigInt: (value: bigint, config?: HexConfig) => string;
4
- export declare const hexFromNumber: (value: number, config?: HexConfig) => string;
5
- export declare const hexFrom: (value: unknown, config?: HexConfig) => string;
1
+ import { Hex, HexConfig } from '../model';
2
+ export declare const hexFromArrayBuffer: (buffer: ArrayBuffer, config?: HexConfig) => Hex;
3
+ export declare const hexFromBigInt: (value: bigint, config?: HexConfig) => Hex;
4
+ export declare const hexFromNumber: (value: number, config?: HexConfig) => Hex;
5
+ export declare const hexFrom: (value: unknown, config?: HexConfig) => Hex;
6
6
  //# sourceMappingURL=from.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"from.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/from.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAIpC,eAAO,MAAM,kBAAkB,WAAY,WAAW,WAAW,SAAS,KAAG,MAG5E,CAAA;AAED,eAAO,MAAM,aAAa,UAAW,MAAM,WAAU,SAAS,KAAQ,MAKrE,CAAA;AAED,eAAO,MAAM,aAAa,UAAW,MAAM,WAAW,SAAS,KAAG,MAEjE,CAAA;AAED,eAAO,MAAM,OAAO,UAAW,OAAO,WAAW,SAAS,KAAG,MAsB5D,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;AAIzC,eAAO,MAAM,kBAAkB,WAAY,WAAW,WAAW,SAAS,KAAG,GAG5E,CAAA;AAED,eAAO,MAAM,aAAa,UAAW,MAAM,WAAU,SAAS,KAAQ,GAKrE,CAAA;AAED,eAAO,MAAM,aAAa,UAAW,MAAM,WAAW,SAAS,KAAG,GAEjE,CAAA;AAED,eAAO,MAAM,OAAO,UAAW,OAAO,WAAW,SAAS,KAAG,GAsB5D,CAAA"}
@@ -1,6 +1,6 @@
1
- import { HexConfig } from '../model';
2
- export declare const hexFromArrayBuffer: (buffer: ArrayBuffer, config?: HexConfig) => string;
3
- export declare const hexFromBigInt: (value: bigint, config?: HexConfig) => string;
4
- export declare const hexFromNumber: (value: number, config?: HexConfig) => string;
5
- export declare const hexFrom: (value: unknown, config?: HexConfig) => string;
1
+ import { Hex, HexConfig } from '../model';
2
+ export declare const hexFromArrayBuffer: (buffer: ArrayBuffer, config?: HexConfig) => Hex;
3
+ export declare const hexFromBigInt: (value: bigint, config?: HexConfig) => Hex;
4
+ export declare const hexFromNumber: (value: number, config?: HexConfig) => Hex;
5
+ export declare const hexFrom: (value: unknown, config?: HexConfig) => Hex;
6
6
  //# sourceMappingURL=from.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"from.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/from.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAIpC,eAAO,MAAM,kBAAkB,WAAY,WAAW,WAAW,SAAS,KAAG,MAG5E,CAAA;AAED,eAAO,MAAM,aAAa,UAAW,MAAM,WAAU,SAAS,KAAQ,MAKrE,CAAA;AAED,eAAO,MAAM,aAAa,UAAW,MAAM,WAAW,SAAS,KAAG,MAEjE,CAAA;AAED,eAAO,MAAM,OAAO,UAAW,OAAO,WAAW,SAAS,KAAG,MAsB5D,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;AAIzC,eAAO,MAAM,kBAAkB,WAAY,WAAW,WAAW,SAAS,KAAG,GAG5E,CAAA;AAED,eAAO,MAAM,aAAa,UAAW,MAAM,WAAU,SAAS,KAAQ,GAKrE,CAAA;AAED,eAAO,MAAM,aAAa,UAAW,MAAM,WAAW,SAAS,KAAG,GAEjE,CAAA;AAED,eAAO,MAAM,OAAO,UAAW,OAAO,WAAW,SAAS,KAAG,GAsB5D,CAAA"}
@@ -1,6 +1,6 @@
1
- import { HexConfig } from '../model';
2
- export declare const hexFromArrayBuffer: (buffer: ArrayBuffer, config?: HexConfig) => string;
3
- export declare const hexFromBigInt: (value: bigint, config?: HexConfig) => string;
4
- export declare const hexFromNumber: (value: number, config?: HexConfig) => string;
5
- export declare const hexFrom: (value: unknown, config?: HexConfig) => string;
1
+ import { Hex, HexConfig } from '../model';
2
+ export declare const hexFromArrayBuffer: (buffer: ArrayBuffer, config?: HexConfig) => Hex;
3
+ export declare const hexFromBigInt: (value: bigint, config?: HexConfig) => Hex;
4
+ export declare const hexFromNumber: (value: number, config?: HexConfig) => Hex;
5
+ export declare const hexFrom: (value: unknown, config?: HexConfig) => Hex;
6
6
  //# sourceMappingURL=from.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"from.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/from.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAIpC,eAAO,MAAM,kBAAkB,WAAY,WAAW,WAAW,SAAS,KAAG,MAG5E,CAAA;AAED,eAAO,MAAM,aAAa,UAAW,MAAM,WAAU,SAAS,KAAQ,MAKrE,CAAA;AAED,eAAO,MAAM,aAAa,UAAW,MAAM,WAAW,SAAS,KAAG,MAEjE,CAAA;AAED,eAAO,MAAM,OAAO,UAAW,OAAO,WAAW,SAAS,KAAG,MAsB5D,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;AAIzC,eAAO,MAAM,kBAAkB,WAAY,WAAW,WAAW,SAAS,KAAG,GAG5E,CAAA;AAED,eAAO,MAAM,aAAa,UAAW,MAAM,WAAU,SAAS,KAAQ,GAKrE,CAAA;AAED,eAAO,MAAM,aAAa,UAAW,MAAM,WAAW,SAAS,KAAG,GAEjE,CAAA;AAED,eAAO,MAAM,OAAO,UAAW,OAAO,WAAW,SAAS,KAAG,GAsB5D,CAAA"}
@@ -1,3 +1,3 @@
1
- import { HexConfig } from '../model';
2
- export declare const hexFromHexString: (value: string, config?: HexConfig) => string;
1
+ import { Hex, HexConfig } from '../model';
2
+ export declare const hexFromHexString: (value: string, config?: HexConfig) => Hex;
3
3
  //# sourceMappingURL=fromHexString.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fromHexString.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/fromHexString.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAGpC,eAAO,MAAM,gBAAgB,UAAW,MAAM,WAAU,SAAS,KAAQ,MAUxE,CAAA"}
1
+ {"version":3,"file":"fromHexString.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/fromHexString.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAGzC,eAAO,MAAM,gBAAgB,UAAW,MAAM,WAAU,SAAS,KAAQ,GAUxE,CAAA"}
@@ -1,3 +1,3 @@
1
- import { HexConfig } from '../model';
2
- export declare const hexFromHexString: (value: string, config?: HexConfig) => string;
1
+ import { Hex, HexConfig } from '../model';
2
+ export declare const hexFromHexString: (value: string, config?: HexConfig) => Hex;
3
3
  //# sourceMappingURL=fromHexString.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fromHexString.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/fromHexString.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAGpC,eAAO,MAAM,gBAAgB,UAAW,MAAM,WAAU,SAAS,KAAQ,MAUxE,CAAA"}
1
+ {"version":3,"file":"fromHexString.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/fromHexString.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAGzC,eAAO,MAAM,gBAAgB,UAAW,MAAM,WAAU,SAAS,KAAQ,GAUxE,CAAA"}
@@ -1,3 +1,3 @@
1
- import { HexConfig } from '../model';
2
- export declare const hexFromHexString: (value: string, config?: HexConfig) => string;
1
+ import { Hex, HexConfig } from '../model';
2
+ export declare const hexFromHexString: (value: string, config?: HexConfig) => Hex;
3
3
  //# sourceMappingURL=fromHexString.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fromHexString.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/fromHexString.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAGpC,eAAO,MAAM,gBAAgB,UAAW,MAAM,WAAU,SAAS,KAAQ,MAUxE,CAAA"}
1
+ {"version":3,"file":"fromHexString.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/fromHexString.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAGzC,eAAO,MAAM,gBAAgB,UAAW,MAAM,WAAU,SAAS,KAAQ,GAUxE,CAAA"}
@@ -1,3 +1,3 @@
1
1
  import { HexConfig } from './model';
2
- export declare const isHex: (value: unknown, config?: HexConfig) => value is string;
2
+ export declare const isHex: (value: unknown, config?: HexConfig) => value is Lowercase<string>;
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,EAAO,SAAS,EAAE,MAAM,SAAS,CAAA;AAIxC,eAAO,MAAM,KAAK,UAAW,OAAO,WAAW,SAAS,oBAWvD,CAAA"}
1
+ {"version":3,"file":"is.d.ts","sourceRoot":"","sources":["../../../src/hex/is.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,SAAS,EAAE,MAAM,SAAS,CAAA;AAIxC,eAAO,MAAM,KAAK,UAAW,OAAO,WAAW,SAAS,+BAWvD,CAAA"}
@@ -1,3 +1,3 @@
1
1
  import { HexConfig } from './model';
2
- export declare const isHex: (value: unknown, config?: HexConfig) => value is string;
2
+ export declare const isHex: (value: unknown, config?: HexConfig) => value is Lowercase<string>;
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,EAAO,SAAS,EAAE,MAAM,SAAS,CAAA;AAIxC,eAAO,MAAM,KAAK,UAAW,OAAO,WAAW,SAAS,oBAWvD,CAAA"}
1
+ {"version":3,"file":"is.d.ts","sourceRoot":"","sources":["../../../src/hex/is.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,SAAS,EAAE,MAAM,SAAS,CAAA;AAIxC,eAAO,MAAM,KAAK,UAAW,OAAO,WAAW,SAAS,+BAWvD,CAAA"}
@@ -1,3 +1,3 @@
1
1
  import { HexConfig } from './model';
2
- export declare const isHex: (value: unknown, config?: HexConfig) => value is string;
2
+ export declare const isHex: (value: unknown, config?: HexConfig) => value is Lowercase<string>;
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,EAAO,SAAS,EAAE,MAAM,SAAS,CAAA;AAIxC,eAAO,MAAM,KAAK,UAAW,OAAO,WAAW,SAAS,oBAWvD,CAAA"}
1
+ {"version":3,"file":"is.d.ts","sourceRoot":"","sources":["../../../src/hex/is.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,SAAS,EAAE,MAAM,SAAS,CAAA;AAIxC,eAAO,MAAM,KAAK,UAAW,OAAO,WAAW,SAAS,+BAWvD,CAAA"}
@@ -1,4 +1,4 @@
1
- export type Hex = string;
1
+ export type Hex = Lowercase<string>;
2
2
  export interface HexConfig {
3
3
  bitLength?: number;
4
4
  byteSize?: number;
@@ -1 +1 @@
1
- {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../src/hex/model.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,GAAG,GAAG,MAAM,CAAA;AAExB,MAAM,WAAW,SAAS;IACxB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB"}
1
+ {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../src/hex/model.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,GAAG,GAAG,SAAS,CAAC,MAAM,CAAC,CAAA;AAEnC,MAAM,WAAW,SAAS;IACxB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB"}
@@ -1,4 +1,4 @@
1
- export type Hex = string;
1
+ export type Hex = Lowercase<string>;
2
2
  export interface HexConfig {
3
3
  bitLength?: number;
4
4
  byteSize?: number;
@@ -1 +1 @@
1
- {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../src/hex/model.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,GAAG,GAAG,MAAM,CAAA;AAExB,MAAM,WAAW,SAAS;IACxB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB"}
1
+ {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../src/hex/model.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,GAAG,GAAG,SAAS,CAAC,MAAM,CAAC,CAAA;AAEnC,MAAM,WAAW,SAAS;IACxB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB"}
@@ -1,4 +1,4 @@
1
- export type Hex = string;
1
+ export type Hex = Lowercase<string>;
2
2
  export interface HexConfig {
3
3
  bitLength?: number;
4
4
  byteSize?: number;
@@ -1 +1 @@
1
- {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../src/hex/model.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,GAAG,GAAG,MAAM,CAAA;AAExB,MAAM,WAAW,SAAS;IACxB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB"}
1
+ {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../src/hex/model.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,GAAG,GAAG,SAAS,CAAC,MAAM,CAAC,CAAA;AAEnC,MAAM,WAAW,SAAS;IACxB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB"}
@@ -90,7 +90,7 @@ var hexFromHexString = (value, config = {}) => {
90
90
  const unPadded = (value.startsWith("0x") ? value.slice(2) : value).toLowerCase();
91
91
  if (isHex(unPadded)) {
92
92
  const padded = unPadded.padStart(unPadded.length + unPadded.length % nibbleBoundary, "0");
93
- return prefix ? `0x${padded}` : padded;
93
+ return (prefix ? `0x${padded}` : padded).toLowerCase();
94
94
  } else {
95
95
  throw new Error("Received string is not a value hex");
96
96
  }
@@ -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/as.ts","../../src/hex/isHexZero.ts","../../src/hex/legacy.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 { HexConfig } from '../model'\nimport { bitsToNibbles } from '../nibble'\nimport { hexFromHexString } from './fromHexString'\n\nexport const hexFromArrayBuffer = (buffer: ArrayBuffer, config?: HexConfig): string => {\n const unPadded = [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, '0')).join('')\n return hexFromHexString(unPadded, config)\n}\n\nexport const hexFromBigInt = (value: bigint, config: HexConfig = {}): string => {\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\nexport const hexFromNumber = (value: number, config?: HexConfig): string => {\n return hexFromBigInt(BigInt(value), config)\n}\n\nexport const hexFrom = (value: unknown, config?: HexConfig): string => {\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 { HexConfig } from '../model'\nimport { bitsToNibbles } from '../nibble'\n\nexport const hexFromHexString = (value: string, config: HexConfig = {}): string => {\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\n } else {\n throw new Error('Received string is not a value hex')\n }\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\n/** @deprecated use toHexLegacy instead */\nexport const toHex = (buffer: ArrayBuffer) => {\n return toHexLegacy(buffer)\n}\n","import { AssertConfig, assertError } from './assert'\nimport { Hex, HexConfig, hexFrom, hexFromHexString, isHex } from './hex'\n\nexport type Address = Hex\n\nexport const toAddress = (value: unknown, config: HexConfig = {}) => {\n const { bitLength = 160, prefix = true } = config\n return hexFrom(value, { bitLength, prefix, ...config })\n}\n\nexport const isAddress = (value: unknown, bitLength = 160): value is Address => {\n return isHex(value, { bitLength, prefix: true })\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 let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value, { prefix: true })\n break\n }\n default: {\n 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}\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 = Hex\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,e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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":[]}
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/as.ts","../../src/hex/isHexZero.ts","../../src/hex/legacy.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 { bitsToNibbles } from '../nibble'\nimport { hexFromHexString } from './fromHexString'\n\nexport const hexFromArrayBuffer = (buffer: ArrayBuffer, config?: HexConfig): Hex => {\n const unPadded = [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, '0')).join('')\n return hexFromHexString(unPadded, config)\n}\n\nexport const hexFromBigInt = (value: bigint, config: HexConfig = {}): 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\nexport const hexFromNumber = (value: number, config?: HexConfig): Hex => {\n return hexFromBigInt(BigInt(value), config)\n}\n\nexport const hexFrom = (value: unknown, config?: HexConfig): 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 { 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\n/** @deprecated use toHexLegacy instead */\nexport const toHex = (buffer: ArrayBuffer) => {\n return toHexLegacy(buffer)\n}\n","import { AssertConfig, assertError } from './assert'\nimport { Hex, HexConfig, hexFrom, hexFromHexString, isHex } from './hex'\n\nexport type Address = Hex\n\nexport const toAddress = (value: unknown, config: HexConfig = {}) => {\n const { bitLength = 160, prefix = true } = config\n return hexFrom(value, { bitLength, prefix, ...config })\n}\n\nexport const isAddress = (value: unknown, bitLength = 160): value is Address => {\n return isHex(value, { bitLength, prefix: true })\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 let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value, { prefix: true })\n break\n }\n default: {\n 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}\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 = Hex\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,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AI,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":[]}
@@ -44,7 +44,7 @@ var hexFromHexString = (value, config = {}) => {
44
44
  const unPadded = (value.startsWith("0x") ? value.slice(2) : value).toLowerCase();
45
45
  if (isHex(unPadded)) {
46
46
  const padded = unPadded.padStart(unPadded.length + unPadded.length % nibbleBoundary, "0");
47
- return prefix ? `0x${padded}` : padded;
47
+ return (prefix ? `0x${padded}` : padded).toLowerCase();
48
48
  } else {
49
49
  throw new Error("Received string is not a value hex");
50
50
  }
@@ -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/as.ts","../../src/hex/isHexZero.ts","../../src/hex/legacy.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 { HexConfig } from '../model'\nimport { bitsToNibbles } from '../nibble'\nimport { hexFromHexString } from './fromHexString'\n\nexport const hexFromArrayBuffer = (buffer: ArrayBuffer, config?: HexConfig): string => {\n const unPadded = [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, '0')).join('')\n return hexFromHexString(unPadded, config)\n}\n\nexport const hexFromBigInt = (value: bigint, config: HexConfig = {}): string => {\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\nexport const hexFromNumber = (value: number, config?: HexConfig): string => {\n return hexFromBigInt(BigInt(value), config)\n}\n\nexport const hexFrom = (value: unknown, config?: HexConfig): string => {\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 { HexConfig } from '../model'\nimport { bitsToNibbles } from '../nibble'\n\nexport const hexFromHexString = (value: string, config: HexConfig = {}): string => {\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\n } else {\n throw new Error('Received string is not a value hex')\n }\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\n/** @deprecated use toHexLegacy instead */\nexport const toHex = (buffer: ArrayBuffer) => {\n return toHexLegacy(buffer)\n}\n","import { AssertConfig, assertError } from './assert'\nimport { Hex, HexConfig, hexFrom, hexFromHexString, isHex } from './hex'\n\nexport type Address = Hex\n\nexport const toAddress = (value: unknown, config: HexConfig = {}) => {\n const { bitLength = 160, prefix = true } = config\n return hexFrom(value, { bitLength, prefix, ...config })\n}\n\nexport const isAddress = (value: unknown, bitLength = 160): value is Address => {\n return isHex(value, { bitLength, prefix: true })\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 let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value, { prefix: true })\n break\n }\n default: {\n 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}\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 = Hex\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,MA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P,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/from/from.ts","../../src/hex/nibble.ts","../../src/hex/regex.ts","../../src/hex/is.ts","../../src/hex/from/fromHexString.ts","../../src/hex/as.ts","../../src/hex/isHexZero.ts","../../src/hex/legacy.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 { bitsToNibbles } from '../nibble'\nimport { hexFromHexString } from './fromHexString'\n\nexport const hexFromArrayBuffer = (buffer: ArrayBuffer, config?: HexConfig): Hex => {\n const unPadded = [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, '0')).join('')\n return hexFromHexString(unPadded, config)\n}\n\nexport const hexFromBigInt = (value: bigint, config: HexConfig = {}): 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\nexport const hexFromNumber = (value: number, config?: HexConfig): Hex => {\n return hexFromBigInt(BigInt(value), config)\n}\n\nexport const hexFrom = (value: unknown, config?: HexConfig): 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 { 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\n/** @deprecated use toHexLegacy instead */\nexport const toHex = (buffer: ArrayBuffer) => {\n return toHexLegacy(buffer)\n}\n","import { AssertConfig, assertError } from './assert'\nimport { Hex, HexConfig, hexFrom, hexFromHexString, isHex } from './hex'\n\nexport type Address = Hex\n\nexport const toAddress = (value: unknown, config: HexConfig = {}) => {\n const { bitLength = 160, prefix = true } = config\n return hexFrom(value, { bitLength, prefix, ...config })\n}\n\nexport const isAddress = (value: unknown, bitLength = 160): value is Address => {\n return isHex(value, { bitLength, prefix: true })\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 let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value, { prefix: true })\n break\n }\n default: {\n 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}\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 = Hex\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;AAAG,WAAO;AAGp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,YAAY,QAA0B;AAC9E,SAAO,MAAM,OAAO,EAAE,WAAW,QAAQ,KAAK,CAAC;AACjD;AAIO,SAAS,UAAU,OAAgB,QAA4C;AACpF,MAAI,cAAkC;AAEtC,UAAQ,OAAO,OAAO;AAAA,IACpB,KAAK,UAAU;AACb,oBAAc,iBAAiB,OAAO,EAAE,QAAQ,KAAK,CAAC;AACtD;AAAA,IACF;AAAA,IACA,SAAS;AACP,aAAO,SAAS,YAAY,OAAO,QAAQ,qBAAqB,OAAO,KAAK,GAAG,IAAI;AAAA,IACrF;AAAA,EACF;AACA,SAAO,UAAU,WAAW,IAAI,cAAc,YAAY,OAAO,QAAQ,4BAA4B,KAAK,GAAG;AAC/G;;;ACzBO,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":[]}
@@ -1,8 +1,8 @@
1
1
  import { AssertConfig } from './assert';
2
2
  import { Hex, HexConfig } from './hex';
3
3
  export type Address = Hex;
4
- export declare const toAddress: (value: unknown, config?: HexConfig) => string;
5
- export declare const isAddress: (value: unknown, bitLength?: number) => value is string;
4
+ export declare const toAddress: (value: unknown, config?: HexConfig) => Lowercase<string>;
5
+ export declare const isAddress: (value: unknown, bitLength?: number) => value is Lowercase<string>;
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,GAAG,CAAA;AAEzB,eAAO,MAAM,SAAS,UAAW,OAAO,WAAU,SAAS,WAG1D,CAAA;AAED,eAAO,MAAM,SAAS,UAAW,OAAO,wCAEvC,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"}
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,GAAG,CAAA;AAEzB,eAAO,MAAM,SAAS,UAAW,OAAO,WAAU,SAAS,sBAG1D,CAAA;AAED,eAAO,MAAM,SAAS,UAAW,OAAO,mDAEvC,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"}
@@ -1,8 +1,8 @@
1
1
  import { AssertConfig } from './assert';
2
2
  import { Hex, HexConfig } from './hex';
3
3
  export type Address = Hex;
4
- export declare const toAddress: (value: unknown, config?: HexConfig) => string;
5
- export declare const isAddress: (value: unknown, bitLength?: number) => value is string;
4
+ export declare const toAddress: (value: unknown, config?: HexConfig) => Lowercase<string>;
5
+ export declare const isAddress: (value: unknown, bitLength?: number) => value is Lowercase<string>;
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,GAAG,CAAA;AAEzB,eAAO,MAAM,SAAS,UAAW,OAAO,WAAU,SAAS,WAG1D,CAAA;AAED,eAAO,MAAM,SAAS,UAAW,OAAO,wCAEvC,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"}
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,GAAG,CAAA;AAEzB,eAAO,MAAM,SAAS,UAAW,OAAO,WAAU,SAAS,sBAG1D,CAAA;AAED,eAAO,MAAM,SAAS,UAAW,OAAO,mDAEvC,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"}
@@ -1,8 +1,8 @@
1
1
  import { AssertConfig } from './assert';
2
2
  import { Hex, HexConfig } from './hex';
3
3
  export type Address = Hex;
4
- export declare const toAddress: (value: unknown, config?: HexConfig) => string;
5
- export declare const isAddress: (value: unknown, bitLength?: number) => value is string;
4
+ export declare const toAddress: (value: unknown, config?: HexConfig) => Lowercase<string>;
5
+ export declare const isAddress: (value: unknown, bitLength?: number) => value is Lowercase<string>;
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,GAAG,CAAA;AAEzB,eAAO,MAAM,SAAS,UAAW,OAAO,WAAU,SAAS,WAG1D,CAAA;AAED,eAAO,MAAM,SAAS,UAAW,OAAO,wCAEvC,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"}
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,GAAG,CAAA;AAEzB,eAAO,MAAM,SAAS,UAAW,OAAO,WAAU,SAAS,sBAG1D,CAAA;AAED,eAAO,MAAM,SAAS,UAAW,OAAO,mDAEvC,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"}
@@ -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 = Hex;
7
- export declare const isHash: (value: unknown, bitLength?: HashBitLength) => value is string;
7
+ export declare const isHash: (value: unknown, bitLength?: HashBitLength) => value is Lowercase<string>;
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,2BAE7C,CAAA;AAED,MAAM,MAAM,IAAI,GAAG,GAAG,CAAA;AACtB,eAAO,MAAM,MAAM,UAAW,OAAO,cAAa,aAAa,oBAE9D,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
+ {"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,2BAE7C,CAAA;AAED,MAAM,MAAM,IAAI,GAAG,GAAG,CAAA;AACtB,eAAO,MAAM,MAAM,UAAW,OAAO,cAAa,aAAa,+BAE9D,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"}
@@ -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 = Hex;
7
- export declare const isHash: (value: unknown, bitLength?: HashBitLength) => value is string;
7
+ export declare const isHash: (value: unknown, bitLength?: HashBitLength) => value is Lowercase<string>;
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,MA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| 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 = Hex;
7
- export declare const isHash: (value: unknown, bitLength?: HashBitLength) => value is string;
7
+ export declare const isHash: (value: unknown, bitLength?: HashBitLength) => value is Lowercase<string>;
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,2BAE7C,CAAA;AAED,MAAM,MAAM,IAAI,GAAG,GAAG,CAAA;AACtB,eAAO,MAAM,MAAM,UAAW,OAAO,cAAa,aAAa,oBAE9D,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
+ {"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,2BAE7C,CAAA;AAED,MAAM,MAAM,IAAI,GAAG,GAAG,CAAA;AACtB,eAAO,MAAM,MAAM,UAAW,OAAO,cAAa,aAAa,+BAE9D,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,6 +1,6 @@
1
- import { HexConfig } from '../model';
2
- export declare const hexFromArrayBuffer: (buffer: ArrayBuffer, config?: HexConfig) => string;
3
- export declare const hexFromBigInt: (value: bigint, config?: HexConfig) => string;
4
- export declare const hexFromNumber: (value: number, config?: HexConfig) => string;
5
- export declare const hexFrom: (value: unknown, config?: HexConfig) => string;
1
+ import { Hex, HexConfig } from '../model';
2
+ export declare const hexFromArrayBuffer: (buffer: ArrayBuffer, config?: HexConfig) => Hex;
3
+ export declare const hexFromBigInt: (value: bigint, config?: HexConfig) => Hex;
4
+ export declare const hexFromNumber: (value: number, config?: HexConfig) => Hex;
5
+ export declare const hexFrom: (value: unknown, config?: HexConfig) => Hex;
6
6
  //# sourceMappingURL=from.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"from.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/from.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAIpC,eAAO,MAAM,kBAAkB,WAAY,WAAW,WAAW,SAAS,KAAG,MAG5E,CAAA;AAED,eAAO,MAAM,aAAa,UAAW,MAAM,WAAU,SAAS,KAAQ,MAKrE,CAAA;AAED,eAAO,MAAM,aAAa,UAAW,MAAM,WAAW,SAAS,KAAG,MAEjE,CAAA;AAED,eAAO,MAAM,OAAO,UAAW,OAAO,WAAW,SAAS,KAAG,MAsB5D,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;AAIzC,eAAO,MAAM,kBAAkB,WAAY,WAAW,WAAW,SAAS,KAAG,GAG5E,CAAA;AAED,eAAO,MAAM,aAAa,UAAW,MAAM,WAAU,SAAS,KAAQ,GAKrE,CAAA;AAED,eAAO,MAAM,aAAa,UAAW,MAAM,WAAW,SAAS,KAAG,GAEjE,CAAA;AAED,eAAO,MAAM,OAAO,UAAW,OAAO,WAAW,SAAS,KAAG,GAsB5D,CAAA"}
@@ -1,6 +1,6 @@
1
- import { HexConfig } from '../model';
2
- export declare const hexFromArrayBuffer: (buffer: ArrayBuffer, config?: HexConfig) => string;
3
- export declare const hexFromBigInt: (value: bigint, config?: HexConfig) => string;
4
- export declare const hexFromNumber: (value: number, config?: HexConfig) => string;
5
- export declare const hexFrom: (value: unknown, config?: HexConfig) => string;
1
+ import { Hex, HexConfig } from '../model';
2
+ export declare const hexFromArrayBuffer: (buffer: ArrayBuffer, config?: HexConfig) => Hex;
3
+ export declare const hexFromBigInt: (value: bigint, config?: HexConfig) => Hex;
4
+ export declare const hexFromNumber: (value: number, config?: HexConfig) => Hex;
5
+ export declare const hexFrom: (value: unknown, config?: HexConfig) => Hex;
6
6
  //# sourceMappingURL=from.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"from.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/from.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAIpC,eAAO,MAAM,kBAAkB,WAAY,WAAW,WAAW,SAAS,KAAG,MAG5E,CAAA;AAED,eAAO,MAAM,aAAa,UAAW,MAAM,WAAU,SAAS,KAAQ,MAKrE,CAAA;AAED,eAAO,MAAM,aAAa,UAAW,MAAM,WAAW,SAAS,KAAG,MAEjE,CAAA;AAED,eAAO,MAAM,OAAO,UAAW,OAAO,WAAW,SAAS,KAAG,MAsB5D,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;AAIzC,eAAO,MAAM,kBAAkB,WAAY,WAAW,WAAW,SAAS,KAAG,GAG5E,CAAA;AAED,eAAO,MAAM,aAAa,UAAW,MAAM,WAAU,SAAS,KAAQ,GAKrE,CAAA;AAED,eAAO,MAAM,aAAa,UAAW,MAAM,WAAW,SAAS,KAAG,GAEjE,CAAA;AAED,eAAO,MAAM,OAAO,UAAW,OAAO,WAAW,SAAS,KAAG,GAsB5D,CAAA"}
@@ -1,6 +1,6 @@
1
- import { HexConfig } from '../model';
2
- export declare const hexFromArrayBuffer: (buffer: ArrayBuffer, config?: HexConfig) => string;
3
- export declare const hexFromBigInt: (value: bigint, config?: HexConfig) => string;
4
- export declare const hexFromNumber: (value: number, config?: HexConfig) => string;
5
- export declare const hexFrom: (value: unknown, config?: HexConfig) => string;
1
+ import { Hex, HexConfig } from '../model';
2
+ export declare const hexFromArrayBuffer: (buffer: ArrayBuffer, config?: HexConfig) => Hex;
3
+ export declare const hexFromBigInt: (value: bigint, config?: HexConfig) => Hex;
4
+ export declare const hexFromNumber: (value: number, config?: HexConfig) => Hex;
5
+ export declare const hexFrom: (value: unknown, config?: HexConfig) => Hex;
6
6
  //# sourceMappingURL=from.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"from.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/from.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAIpC,eAAO,MAAM,kBAAkB,WAAY,WAAW,WAAW,SAAS,KAAG,MAG5E,CAAA;AAED,eAAO,MAAM,aAAa,UAAW,MAAM,WAAU,SAAS,KAAQ,MAKrE,CAAA;AAED,eAAO,MAAM,aAAa,UAAW,MAAM,WAAW,SAAS,KAAG,MAEjE,CAAA;AAED,eAAO,MAAM,OAAO,UAAW,OAAO,WAAW,SAAS,KAAG,MAsB5D,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;AAIzC,eAAO,MAAM,kBAAkB,WAAY,WAAW,WAAW,SAAS,KAAG,GAG5E,CAAA;AAED,eAAO,MAAM,aAAa,UAAW,MAAM,WAAU,SAAS,KAAQ,GAKrE,CAAA;AAED,eAAO,MAAM,aAAa,UAAW,MAAM,WAAW,SAAS,KAAG,GAEjE,CAAA;AAED,eAAO,MAAM,OAAO,UAAW,OAAO,WAAW,SAAS,KAAG,GAsB5D,CAAA"}
@@ -1,3 +1,3 @@
1
- import { HexConfig } from '../model';
2
- export declare const hexFromHexString: (value: string, config?: HexConfig) => string;
1
+ import { Hex, HexConfig } from '../model';
2
+ export declare const hexFromHexString: (value: string, config?: HexConfig) => Hex;
3
3
  //# sourceMappingURL=fromHexString.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fromHexString.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/fromHexString.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAGpC,eAAO,MAAM,gBAAgB,UAAW,MAAM,WAAU,SAAS,KAAQ,MAUxE,CAAA"}
1
+ {"version":3,"file":"fromHexString.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/fromHexString.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAGzC,eAAO,MAAM,gBAAgB,UAAW,MAAM,WAAU,SAAS,KAAQ,GAUxE,CAAA"}
@@ -1,3 +1,3 @@
1
- import { HexConfig } from '../model';
2
- export declare const hexFromHexString: (value: string, config?: HexConfig) => string;
1
+ import { Hex, HexConfig } from '../model';
2
+ export declare const hexFromHexString: (value: string, config?: HexConfig) => Hex;
3
3
  //# sourceMappingURL=fromHexString.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fromHexString.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/fromHexString.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAGpC,eAAO,MAAM,gBAAgB,UAAW,MAAM,WAAU,SAAS,KAAQ,MAUxE,CAAA"}
1
+ {"version":3,"file":"fromHexString.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/fromHexString.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAGzC,eAAO,MAAM,gBAAgB,UAAW,MAAM,WAAU,SAAS,KAAQ,GAUxE,CAAA"}
@@ -1,3 +1,3 @@
1
- import { HexConfig } from '../model';
2
- export declare const hexFromHexString: (value: string, config?: HexConfig) => string;
1
+ import { Hex, HexConfig } from '../model';
2
+ export declare const hexFromHexString: (value: string, config?: HexConfig) => Hex;
3
3
  //# sourceMappingURL=fromHexString.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fromHexString.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/fromHexString.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAGpC,eAAO,MAAM,gBAAgB,UAAW,MAAM,WAAU,SAAS,KAAQ,MAUxE,CAAA"}
1
+ {"version":3,"file":"fromHexString.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/fromHexString.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAGzC,eAAO,MAAM,gBAAgB,UAAW,MAAM,WAAU,SAAS,KAAQ,GAUxE,CAAA"}
@@ -1,3 +1,3 @@
1
1
  import { HexConfig } from './model';
2
- export declare const isHex: (value: unknown, config?: HexConfig) => value is string;
2
+ export declare const isHex: (value: unknown, config?: HexConfig) => value is Lowercase<string>;
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,EAAO,SAAS,EAAE,MAAM,SAAS,CAAA;AAIxC,eAAO,MAAM,KAAK,UAAW,OAAO,WAAW,SAAS,oBAWvD,CAAA"}
1
+ {"version":3,"file":"is.d.ts","sourceRoot":"","sources":["../../../src/hex/is.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,SAAS,EAAE,MAAM,SAAS,CAAA;AAIxC,eAAO,MAAM,KAAK,UAAW,OAAO,WAAW,SAAS,+BAWvD,CAAA"}
@@ -1,3 +1,3 @@
1
1
  import { HexConfig } from './model';
2
- export declare const isHex: (value: unknown, config?: HexConfig) => value is string;
2
+ export declare const isHex: (value: unknown, config?: HexConfig) => value is Lowercase<string>;
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,EAAO,SAAS,EAAE,MAAM,SAAS,CAAA;AAIxC,eAAO,MAAM,KAAK,UAAW,OAAO,WAAW,SAAS,oBAWvD,CAAA"}
1
+ {"version":3,"file":"is.d.ts","sourceRoot":"","sources":["../../../src/hex/is.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,SAAS,EAAE,MAAM,SAAS,CAAA;AAIxC,eAAO,MAAM,KAAK,UAAW,OAAO,WAAW,SAAS,+BAWvD,CAAA"}
@@ -1,3 +1,3 @@
1
1
  import { HexConfig } from './model';
2
- export declare const isHex: (value: unknown, config?: HexConfig) => value is string;
2
+ export declare const isHex: (value: unknown, config?: HexConfig) => value is Lowercase<string>;
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,EAAO,SAAS,EAAE,MAAM,SAAS,CAAA;AAIxC,eAAO,MAAM,KAAK,UAAW,OAAO,WAAW,SAAS,oBAWvD,CAAA"}
1
+ {"version":3,"file":"is.d.ts","sourceRoot":"","sources":["../../../src/hex/is.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,SAAS,EAAE,MAAM,SAAS,CAAA;AAIxC,eAAO,MAAM,KAAK,UAAW,OAAO,WAAW,SAAS,+BAWvD,CAAA"}
@@ -1,4 +1,4 @@
1
- export type Hex = string;
1
+ export type Hex = Lowercase<string>;
2
2
  export interface HexConfig {
3
3
  bitLength?: number;
4
4
  byteSize?: number;
@@ -1 +1 @@
1
- {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../src/hex/model.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,GAAG,GAAG,MAAM,CAAA;AAExB,MAAM,WAAW,SAAS;IACxB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB"}
1
+ {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../src/hex/model.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,GAAG,GAAG,SAAS,CAAC,MAAM,CAAC,CAAA;AAEnC,MAAM,WAAW,SAAS;IACxB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB"}
@@ -1,4 +1,4 @@
1
- export type Hex = string;
1
+ export type Hex = Lowercase<string>;
2
2
  export interface HexConfig {
3
3
  bitLength?: number;
4
4
  byteSize?: number;
@@ -1 +1 @@
1
- {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../src/hex/model.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,GAAG,GAAG,MAAM,CAAA;AAExB,MAAM,WAAW,SAAS;IACxB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB"}
1
+ {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../src/hex/model.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,GAAG,GAAG,SAAS,CAAC,MAAM,CAAC,CAAA;AAEnC,MAAM,WAAW,SAAS;IACxB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB"}
@@ -1,4 +1,4 @@
1
- export type Hex = string;
1
+ export type Hex = Lowercase<string>;
2
2
  export interface HexConfig {
3
3
  bitLength?: number;
4
4
  byteSize?: number;
@@ -1 +1 @@
1
- {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../src/hex/model.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,GAAG,GAAG,MAAM,CAAA;AAExB,MAAM,WAAW,SAAS;IACxB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB"}
1
+ {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../src/hex/model.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,GAAG,GAAG,SAAS,CAAC,MAAM,CAAC,CAAA;AAEnC,MAAM,WAAW,SAAS;IACxB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB"}
@@ -90,7 +90,7 @@ var hexFromHexString = (value, config = {}) => {
90
90
  const unPadded = (value.startsWith("0x") ? value.slice(2) : value).toLowerCase();
91
91
  if (isHex(unPadded)) {
92
92
  const padded = unPadded.padStart(unPadded.length + unPadded.length % nibbleBoundary, "0");
93
- return prefix ? `0x${padded}` : padded;
93
+ return (prefix ? `0x${padded}` : padded).toLowerCase();
94
94
  } else {
95
95
  throw new Error("Received string is not a value hex");
96
96
  }
@@ -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/as.ts","../../src/hex/isHexZero.ts","../../src/hex/legacy.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 { HexConfig } from '../model'\nimport { bitsToNibbles } from '../nibble'\nimport { hexFromHexString } from './fromHexString'\n\nexport const hexFromArrayBuffer = (buffer: ArrayBuffer, config?: HexConfig): string => {\n const unPadded = [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, '0')).join('')\n return hexFromHexString(unPadded, config)\n}\n\nexport const hexFromBigInt = (value: bigint, config: HexConfig = {}): string => {\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\nexport const hexFromNumber = (value: number, config?: HexConfig): string => {\n return hexFromBigInt(BigInt(value), config)\n}\n\nexport const hexFrom = (value: unknown, config?: HexConfig): string => {\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 { HexConfig } from '../model'\nimport { bitsToNibbles } from '../nibble'\n\nexport const hexFromHexString = (value: string, config: HexConfig = {}): string => {\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\n } else {\n throw new Error('Received string is not a value hex')\n }\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\n/** @deprecated use toHexLegacy instead */\nexport const toHex = (buffer: ArrayBuffer) => {\n return toHexLegacy(buffer)\n}\n","import { AssertConfig, assertError } from './assert'\nimport { Hex, HexConfig, hexFrom, hexFromHexString, isHex } from './hex'\n\nexport type Address = Hex\n\nexport const toAddress = (value: unknown, config: HexConfig = {}) => {\n const { bitLength = 160, prefix = true } = config\n return hexFrom(value, { bitLength, prefix, ...config })\n}\n\nexport const isAddress = (value: unknown, bitLength = 160): value is Address => {\n return isHex(value, { bitLength, prefix: true })\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 let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value, { prefix: true })\n break\n }\n default: {\n 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}\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 = Hex\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,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.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/as.ts","../../src/hex/isHexZero.ts","../../src/hex/legacy.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 { bitsToNibbles } from '../nibble'\nimport { hexFromHexString } from './fromHexString'\n\nexport const hexFromArrayBuffer = (buffer: ArrayBuffer, config?: HexConfig): Hex => {\n const unPadded = [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, '0')).join('')\n return hexFromHexString(unPadded, config)\n}\n\nexport const hexFromBigInt = (value: bigint, config: HexConfig = {}): 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\nexport const hexFromNumber = (value: number, config?: HexConfig): Hex => {\n return hexFromBigInt(BigInt(value), config)\n}\n\nexport const hexFrom = (value: unknown, config?: HexConfig): 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 { 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\n/** @deprecated use toHexLegacy instead */\nexport const toHex = (buffer: ArrayBuffer) => {\n return toHexLegacy(buffer)\n}\n","import { AssertConfig, assertError } from './assert'\nimport { Hex, HexConfig, hexFrom, hexFromHexString, isHex } from './hex'\n\nexport type Address = Hex\n\nexport const toAddress = (value: unknown, config: HexConfig = {}) => {\n const { bitLength = 160, prefix = true } = config\n return hexFrom(value, { bitLength, prefix, ...config })\n}\n\nexport const isAddress = (value: unknown, bitLength = 160): value is Address => {\n return isHex(value, { bitLength, prefix: true })\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 let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value, { prefix: true })\n break\n }\n default: {\n 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}\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 = Hex\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,mBAAkB,iCAAQ,UAAS,MAAM,SAAS,IAAI,MAAM;AAGlE,OAAI,iCAAQ,eAAc,UAAa,oBAAoB,cAAc,iCAAQ,SAAS;AAAG,WAAO;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,OAAgB,YAAY,QAA0B;AAC9E,SAAO,MAAM,OAAO,EAAE,WAAW,QAAQ,KAAK,CAAC;AACjD;AAIO,SAAS,UAAU,OAAgB,QAA4C;AACpF,MAAI,cAAkC;AAEtC,UAAQ,OAAO,OAAO;AAAA,IACpB,KAAK,UAAU;AACb,oBAAc,iBAAiB,OAAO,EAAE,QAAQ,KAAK,CAAC;AACtD;AAAA,IACF;AAAA,IACA,SAAS;AACP,aAAO,SAAS,YAAY,OAAO,QAAQ,qBAAqB,OAAO,KAAK,GAAG,IAAI;AAAA,IACrF;AAAA,EACF;AACA,SAAO,UAAU,WAAW,IAAI,cAAc,YAAY,OAAO,QAAQ,4BAA4B,KAAK,GAAG;AAC/G;;;ACzBO,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":[]}
@@ -44,7 +44,7 @@ var hexFromHexString = (value, config = {}) => {
44
44
  const unPadded = (value.startsWith("0x") ? value.slice(2) : value).toLowerCase();
45
45
  if (isHex(unPadded)) {
46
46
  const padded = unPadded.padStart(unPadded.length + unPadded.length % nibbleBoundary, "0");
47
- return prefix ? `0x${padded}` : padded;
47
+ return (prefix ? `0x${padded}` : padded).toLowerCase();
48
48
  } else {
49
49
  throw new Error("Received string is not a value hex");
50
50
  }
@@ -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/as.ts","../../src/hex/isHexZero.ts","../../src/hex/legacy.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 { HexConfig } from '../model'\nimport { bitsToNibbles } from '../nibble'\nimport { hexFromHexString } from './fromHexString'\n\nexport const hexFromArrayBuffer = (buffer: ArrayBuffer, config?: HexConfig): string => {\n const unPadded = [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, '0')).join('')\n return hexFromHexString(unPadded, config)\n}\n\nexport const hexFromBigInt = (value: bigint, config: HexConfig = {}): string => {\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\nexport const hexFromNumber = (value: number, config?: HexConfig): string => {\n return hexFromBigInt(BigInt(value), config)\n}\n\nexport const hexFrom = (value: unknown, config?: HexConfig): string => {\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 { HexConfig } from '../model'\nimport { bitsToNibbles } from '../nibble'\n\nexport const hexFromHexString = (value: string, config: HexConfig = {}): string => {\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\n } else {\n throw new Error('Received string is not a value hex')\n }\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\n/** @deprecated use toHexLegacy instead */\nexport const toHex = (buffer: ArrayBuffer) => {\n return toHexLegacy(buffer)\n}\n","import { AssertConfig, assertError } from './assert'\nimport { Hex, HexConfig, hexFrom, hexFromHexString, isHex } from './hex'\n\nexport type Address = Hex\n\nexport const toAddress = (value: unknown, config: HexConfig = {}) => {\n const { bitLength = 160, prefix = true } = config\n return hexFrom(value, { bitLength, prefix, ...config })\n}\n\nexport const isAddress = (value: unknown, bitLength = 160): value is Address => {\n return isHex(value, { bitLength, prefix: true })\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 let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value, { prefix: true })\n break\n }\n default: {\n 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}\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 = Hex\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,mBAAkB,iCAAQ,UAAS,MAAM,SAAS,IAAI,MAAM;AAGlE,OAAI,iCAAQ,eAAc,UAAa,oBAAoB,cAAc,iCAAQ,SAAS;AAAG,WAAO;AAGpG,UAAO,iCAAQ,UAAS,mBAAmB,KAAK,KAAK,IAAI,SAAS,KAAK,KAAK;AAC9E;;;ACXO,IAAM,mBAAmB,C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pF,MAAI,cAAkC;AAEtC,UAAQ,OAAO,OAAO;AAAA,IACpB,KAAK,UAAU;AACb,oBAAc,iBAAiB,OAAO,EAAE,QAAQ,KAAK,CAAC;AACtD;AAAA,IACF;AAAA,IACA,SAAS;AACP,aAAO,SAAS,YAAY,OAAO,QAAQ,qBAAqB,OAAO,KAAK,GAAG,IAAI;AAAA,IACrF;AAAA,EACF;AACA,SAAO,UAAU,WAAW,IAAI,cAAc,YAAY,OAAO,QAAQ,4BAA4B,KAAK,GAAG;AAC/G;;;ACzBO,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":[]}
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/as.ts","../../src/hex/isHexZero.ts","../../src/hex/legacy.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 { bitsToNibbles } from '../nibble'\nimport { hexFromHexString } from './fromHexString'\n\nexport const hexFromArrayBuffer = (buffer: ArrayBuffer, config?: HexConfig): Hex => {\n const unPadded = [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, '0')).join('')\n return hexFromHexString(unPadded, config)\n}\n\nexport const hexFromBigInt = (value: bigint, config: HexConfig = {}): 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\nexport const hexFromNumber = (value: number, config?: HexConfig): Hex => {\n return hexFromBigInt(BigInt(value), config)\n}\n\nexport const hexFrom = (value: unknown, config?: HexConfig): 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 { 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\n/** @deprecated use toHexLegacy instead */\nexport const toHex = (buffer: ArrayBuffer) => {\n return toHexLegacy(buffer)\n}\n","import { AssertConfig, assertError } from './assert'\nimport { Hex, HexConfig, hexFrom, hexFromHexString, isHex } from './hex'\n\nexport type Address = Hex\n\nexport const toAddress = (value: unknown, config: HexConfig = {}) => {\n const { bitLength = 160, prefix = true } = config\n return hexFrom(value, { bitLength, prefix, ...config })\n}\n\nexport const isAddress = (value: unknown, bitLength = 160): value is Address => {\n return isHex(value, { bitLength, prefix: true })\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 let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value, { prefix: true })\n break\n }\n default: {\n 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}\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 = Hex\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}]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,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
@@ -39,7 +39,7 @@
39
39
  "esm"
40
40
  ],
41
41
  "dependencies": {
42
- "@xylabs/arraybuffer": "~2.15.1"
42
+ "@xylabs/arraybuffer": "~3.0.1"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@xylabs/ts-scripts-yarn3": "^3.4.1",
@@ -57,6 +57,6 @@
57
57
  "url": "https://github.com/xylabs/sdk-js.git"
58
58
  },
59
59
  "sideEffects": false,
60
- "version": "2.15.1",
60
+ "version": "3.0.1",
61
61
  "type": "module"
62
62
  }
@@ -1,26 +1,26 @@
1
1
  import { isArrayBuffer } from '@xylabs/arraybuffer'
2
2
 
3
- import { HexConfig } from '../model'
3
+ import { Hex, HexConfig } from '../model'
4
4
  import { bitsToNibbles } from '../nibble'
5
5
  import { hexFromHexString } from './fromHexString'
6
6
 
7
- export const hexFromArrayBuffer = (buffer: ArrayBuffer, config?: HexConfig): string => {
7
+ export const hexFromArrayBuffer = (buffer: ArrayBuffer, config?: HexConfig): Hex => {
8
8
  const unPadded = [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, '0')).join('')
9
9
  return hexFromHexString(unPadded, config)
10
10
  }
11
11
 
12
- export const hexFromBigInt = (value: bigint, config: HexConfig = {}): string => {
12
+ export const hexFromBigInt = (value: bigint, config: HexConfig = {}): Hex => {
13
13
  const { bitLength } = config
14
14
  const unPadded = value.toString(16)
15
15
  const padded = bitLength === undefined ? unPadded : unPadded.padStart(bitsToNibbles(bitLength), '0')
16
16
  return hexFromHexString(padded, config)
17
17
  }
18
18
 
19
- export const hexFromNumber = (value: number, config?: HexConfig): string => {
19
+ export const hexFromNumber = (value: number, config?: HexConfig): Hex => {
20
20
  return hexFromBigInt(BigInt(value), config)
21
21
  }
22
22
 
23
- export const hexFrom = (value: unknown, config?: HexConfig): string => {
23
+ export const hexFrom = (value: unknown, config?: HexConfig): Hex => {
24
24
  switch (typeof value) {
25
25
  case 'string': {
26
26
  return hexFromHexString(value, config)
@@ -1,14 +1,14 @@
1
1
  import { isHex } from '../is'
2
- import { HexConfig } from '../model'
2
+ import { Hex, HexConfig } from '../model'
3
3
  import { bitsToNibbles } from '../nibble'
4
4
 
5
- export const hexFromHexString = (value: string, config: HexConfig = {}): string => {
5
+ export const hexFromHexString = (value: string, config: HexConfig = {}): Hex => {
6
6
  const { prefix = false, byteSize = 8 } = config
7
7
  const nibbleBoundary = bitsToNibbles(byteSize)
8
8
  const unPadded = (value.startsWith('0x') ? value.slice(2) : value).toLowerCase()
9
9
  if (isHex(unPadded)) {
10
10
  const padded = unPadded.padStart(unPadded.length + (unPadded.length % nibbleBoundary), '0')
11
- return prefix ? `0x${padded}` : padded
11
+ return (prefix ? `0x${padded}` : padded).toLowerCase() as Hex
12
12
  } else {
13
13
  throw new Error('Received string is not a value hex')
14
14
  }
package/src/hex/model.ts CHANGED
@@ -1,4 +1,4 @@
1
- export type Hex = string
1
+ export type Hex = Lowercase<string>
2
2
 
3
3
  export interface HexConfig {
4
4
  bitLength?: number