@xylabs/hex 3.0.12 → 3.0.14

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 (127) hide show
  1. package/README.md +6 -2
  2. package/dist/browser/hex/from/from.d.cts +1 -3
  3. package/dist/browser/hex/from/from.d.cts.map +1 -1
  4. package/dist/browser/hex/from/from.d.mts +1 -3
  5. package/dist/browser/hex/from/from.d.mts.map +1 -1
  6. package/dist/browser/hex/from/from.d.ts +1 -3
  7. package/dist/browser/hex/from/from.d.ts.map +1 -1
  8. package/dist/browser/hex/from/fromArrayBuffer.d.cts +4 -0
  9. package/dist/browser/hex/from/fromArrayBuffer.d.cts.map +1 -0
  10. package/dist/browser/hex/from/fromArrayBuffer.d.mts +4 -0
  11. package/dist/browser/hex/from/fromArrayBuffer.d.mts.map +1 -0
  12. package/dist/browser/hex/from/fromArrayBuffer.d.ts +4 -0
  13. package/dist/browser/hex/from/fromArrayBuffer.d.ts.map +1 -0
  14. package/dist/browser/hex/from/fromBigInt.d.cts +4 -0
  15. package/dist/browser/hex/from/fromBigInt.d.cts.map +1 -0
  16. package/dist/browser/hex/from/fromBigInt.d.mts +4 -0
  17. package/dist/browser/hex/from/fromBigInt.d.mts.map +1 -0
  18. package/dist/browser/hex/from/fromBigInt.d.ts +4 -0
  19. package/dist/browser/hex/from/fromBigInt.d.ts.map +1 -0
  20. package/dist/browser/hex/from/fromNumber.d.cts +3 -0
  21. package/dist/browser/hex/from/fromNumber.d.cts.map +1 -0
  22. package/dist/browser/hex/from/fromNumber.d.mts +3 -0
  23. package/dist/browser/hex/from/fromNumber.d.mts.map +1 -0
  24. package/dist/browser/hex/from/fromNumber.d.ts +3 -0
  25. package/dist/browser/hex/from/fromNumber.d.ts.map +1 -0
  26. package/dist/browser/hex/from/index.d.cts +3 -0
  27. package/dist/browser/hex/from/index.d.cts.map +1 -1
  28. package/dist/browser/hex/from/index.d.mts +3 -0
  29. package/dist/browser/hex/from/index.d.mts.map +1 -1
  30. package/dist/browser/hex/from/index.d.ts +3 -0
  31. package/dist/browser/hex/from/index.d.ts.map +1 -1
  32. package/dist/browser/hex/index.d.cts +1 -0
  33. package/dist/browser/hex/index.d.cts.map +1 -1
  34. package/dist/browser/hex/index.d.mts +1 -0
  35. package/dist/browser/hex/index.d.mts.map +1 -1
  36. package/dist/browser/hex/index.d.ts +1 -0
  37. package/dist/browser/hex/index.d.ts.map +1 -1
  38. package/dist/browser/hex/legacy.d.cts +0 -2
  39. package/dist/browser/hex/legacy.d.cts.map +1 -1
  40. package/dist/browser/hex/legacy.d.mts +0 -2
  41. package/dist/browser/hex/legacy.d.mts.map +1 -1
  42. package/dist/browser/hex/legacy.d.ts +0 -2
  43. package/dist/browser/hex/legacy.d.ts.map +1 -1
  44. package/dist/browser/hex/model.d.cts +1 -0
  45. package/dist/browser/hex/model.d.cts.map +1 -1
  46. package/dist/browser/hex/model.d.mts +1 -0
  47. package/dist/browser/hex/model.d.mts.map +1 -1
  48. package/dist/browser/hex/model.d.ts +1 -0
  49. package/dist/browser/hex/model.d.ts.map +1 -1
  50. package/dist/browser/hex/to.d.cts +4 -0
  51. package/dist/browser/hex/to.d.cts.map +1 -0
  52. package/dist/browser/hex/to.d.mts +4 -0
  53. package/dist/browser/hex/to.d.mts.map +1 -0
  54. package/dist/browser/hex/to.d.ts +4 -0
  55. package/dist/browser/hex/to.d.ts.map +1 -0
  56. package/dist/browser/index.cjs +12 -3
  57. package/dist/browser/index.cjs.map +1 -1
  58. package/dist/browser/index.js +12 -3
  59. package/dist/browser/index.js.map +1 -1
  60. package/dist/node/hex/from/from.d.cts +1 -3
  61. package/dist/node/hex/from/from.d.cts.map +1 -1
  62. package/dist/node/hex/from/from.d.mts +1 -3
  63. package/dist/node/hex/from/from.d.mts.map +1 -1
  64. package/dist/node/hex/from/from.d.ts +1 -3
  65. package/dist/node/hex/from/from.d.ts.map +1 -1
  66. package/dist/node/hex/from/fromArrayBuffer.d.cts +4 -0
  67. package/dist/node/hex/from/fromArrayBuffer.d.cts.map +1 -0
  68. package/dist/node/hex/from/fromArrayBuffer.d.mts +4 -0
  69. package/dist/node/hex/from/fromArrayBuffer.d.mts.map +1 -0
  70. package/dist/node/hex/from/fromArrayBuffer.d.ts +4 -0
  71. package/dist/node/hex/from/fromArrayBuffer.d.ts.map +1 -0
  72. package/dist/node/hex/from/fromBigInt.d.cts +4 -0
  73. package/dist/node/hex/from/fromBigInt.d.cts.map +1 -0
  74. package/dist/node/hex/from/fromBigInt.d.mts +4 -0
  75. package/dist/node/hex/from/fromBigInt.d.mts.map +1 -0
  76. package/dist/node/hex/from/fromBigInt.d.ts +4 -0
  77. package/dist/node/hex/from/fromBigInt.d.ts.map +1 -0
  78. package/dist/node/hex/from/fromNumber.d.cts +3 -0
  79. package/dist/node/hex/from/fromNumber.d.cts.map +1 -0
  80. package/dist/node/hex/from/fromNumber.d.mts +3 -0
  81. package/dist/node/hex/from/fromNumber.d.mts.map +1 -0
  82. package/dist/node/hex/from/fromNumber.d.ts +3 -0
  83. package/dist/node/hex/from/fromNumber.d.ts.map +1 -0
  84. package/dist/node/hex/from/index.d.cts +3 -0
  85. package/dist/node/hex/from/index.d.cts.map +1 -1
  86. package/dist/node/hex/from/index.d.mts +3 -0
  87. package/dist/node/hex/from/index.d.mts.map +1 -1
  88. package/dist/node/hex/from/index.d.ts +3 -0
  89. package/dist/node/hex/from/index.d.ts.map +1 -1
  90. package/dist/node/hex/index.d.cts +1 -0
  91. package/dist/node/hex/index.d.cts.map +1 -1
  92. package/dist/node/hex/index.d.mts +1 -0
  93. package/dist/node/hex/index.d.mts.map +1 -1
  94. package/dist/node/hex/index.d.ts +1 -0
  95. package/dist/node/hex/index.d.ts.map +1 -1
  96. package/dist/node/hex/legacy.d.cts +0 -2
  97. package/dist/node/hex/legacy.d.cts.map +1 -1
  98. package/dist/node/hex/legacy.d.mts +0 -2
  99. package/dist/node/hex/legacy.d.mts.map +1 -1
  100. package/dist/node/hex/legacy.d.ts +0 -2
  101. package/dist/node/hex/legacy.d.ts.map +1 -1
  102. package/dist/node/hex/model.d.cts +1 -0
  103. package/dist/node/hex/model.d.cts.map +1 -1
  104. package/dist/node/hex/model.d.mts +1 -0
  105. package/dist/node/hex/model.d.mts.map +1 -1
  106. package/dist/node/hex/model.d.ts +1 -0
  107. package/dist/node/hex/model.d.ts.map +1 -1
  108. package/dist/node/hex/to.d.cts +4 -0
  109. package/dist/node/hex/to.d.cts.map +1 -0
  110. package/dist/node/hex/to.d.mts +4 -0
  111. package/dist/node/hex/to.d.mts.map +1 -0
  112. package/dist/node/hex/to.d.ts +4 -0
  113. package/dist/node/hex/to.d.ts.map +1 -0
  114. package/dist/node/index.cjs +12 -3
  115. package/dist/node/index.cjs.map +1 -1
  116. package/dist/node/index.js +12 -3
  117. package/dist/node/index.js.map +1 -1
  118. package/package.json +2 -2
  119. package/src/hex/from/from.ts +10 -18
  120. package/src/hex/from/fromArrayBuffer.ts +13 -0
  121. package/src/hex/from/fromBigInt.ts +16 -0
  122. package/src/hex/from/fromNumber.ts +6 -0
  123. package/src/hex/from/index.ts +3 -0
  124. package/src/hex/index.ts +1 -0
  125. package/src/hex/legacy.ts +0 -5
  126. package/src/hex/model.ts +1 -0
  127. package/src/hex/to.ts +13 -0
package/README.md CHANGED
@@ -8,7 +8,7 @@
8
8
  [![npm-license-badge][]](LICENSE)
9
9
  [![socket-badge][]][socket-link]
10
10
 
11
- > XY Labs generalized Javascript library
11
+ > XY Labs Hex Helpers
12
12
 
13
13
  ## Table of Contents
14
14
 
@@ -20,7 +20,11 @@
20
20
 
21
21
  ## Description
22
22
 
23
- Common Javascript code that is used throughout XYO projects that use React.
23
+ Various Hex helper functions for conversion and formatting
24
+
25
+ ### Hex
26
+
27
+ hexFrom - Convert unknown type to hex string
24
28
 
25
29
  ## Install
26
30
 
@@ -1,6 +1,4 @@
1
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;
2
+ /** Takes unknown value and tries our best to convert it to a hex string */
5
3
  export declare const hexFrom: (value: unknown, config?: HexConfig) => Hex;
6
4
  //# 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,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
+ {"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;AAMzC,2EAA2E;AAC3E,eAAO,MAAM,OAAO,UAEX,OAAO,WAEL,SAAS,KACjB,GAsBF,CAAA"}
@@ -1,6 +1,4 @@
1
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;
2
+ /** Takes unknown value and tries our best to convert it to a hex string */
5
3
  export declare const hexFrom: (value: unknown, config?: HexConfig) => Hex;
6
4
  //# 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,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
+ {"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;AAMzC,2EAA2E;AAC3E,eAAO,MAAM,OAAO,UAEX,OAAO,WAEL,SAAS,KACjB,GAsBF,CAAA"}
@@ -1,6 +1,4 @@
1
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;
2
+ /** Takes unknown value and tries our best to convert it to a hex string */
5
3
  export declare const hexFrom: (value: unknown, config?: HexConfig) => Hex;
6
4
  //# 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,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
+ {"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;AAMzC,2EAA2E;AAC3E,eAAO,MAAM,OAAO,UAEX,OAAO,WAEL,SAAS,KACjB,GAsBF,CAAA"}
@@ -0,0 +1,4 @@
1
+ import { Hex, HexConfig } from '../model';
2
+ /** Convert an ArrayBuffer to a hex string */
3
+ export declare const hexFromArrayBuffer: (buffer: ArrayBuffer, config?: HexConfig) => Hex;
4
+ //# sourceMappingURL=fromArrayBuffer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fromArrayBuffer.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/fromArrayBuffer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAGzC,6CAA6C;AAC7C,eAAO,MAAM,kBAAkB,WAErB,WAAW,WAEV,SAAS,KACjB,GAGF,CAAA"}
@@ -0,0 +1,4 @@
1
+ import { Hex, HexConfig } from '../model';
2
+ /** Convert an ArrayBuffer to a hex string */
3
+ export declare const hexFromArrayBuffer: (buffer: ArrayBuffer, config?: HexConfig) => Hex;
4
+ //# sourceMappingURL=fromArrayBuffer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fromArrayBuffer.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/fromArrayBuffer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAGzC,6CAA6C;AAC7C,eAAO,MAAM,kBAAkB,WAErB,WAAW,WAEV,SAAS,KACjB,GAGF,CAAA"}
@@ -0,0 +1,4 @@
1
+ import { Hex, HexConfig } from '../model';
2
+ /** Convert an ArrayBuffer to a hex string */
3
+ export declare const hexFromArrayBuffer: (buffer: ArrayBuffer, config?: HexConfig) => Hex;
4
+ //# sourceMappingURL=fromArrayBuffer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fromArrayBuffer.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/fromArrayBuffer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAGzC,6CAA6C;AAC7C,eAAO,MAAM,kBAAkB,WAErB,WAAW,WAEV,SAAS,KACjB,GAGF,CAAA"}
@@ -0,0 +1,4 @@
1
+ import { Hex, HexConfig } from '../model';
2
+ /** Convert a bigint to a hex string */
3
+ export declare const hexFromBigInt: (value: bigint, config?: HexConfig) => Hex;
4
+ //# sourceMappingURL=fromBigInt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fromBigInt.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/fromBigInt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAIzC,uCAAuC;AACvC,eAAO,MAAM,aAAa,UAEjB,MAAM,WAEL,SAAS,KAChB,GAKF,CAAA"}
@@ -0,0 +1,4 @@
1
+ import { Hex, HexConfig } from '../model';
2
+ /** Convert a bigint to a hex string */
3
+ export declare const hexFromBigInt: (value: bigint, config?: HexConfig) => Hex;
4
+ //# sourceMappingURL=fromBigInt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fromBigInt.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/fromBigInt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAIzC,uCAAuC;AACvC,eAAO,MAAM,aAAa,UAEjB,MAAM,WAEL,SAAS,KAChB,GAKF,CAAA"}
@@ -0,0 +1,4 @@
1
+ import { Hex, HexConfig } from '../model';
2
+ /** Convert a bigint to a hex string */
3
+ export declare const hexFromBigInt: (value: bigint, config?: HexConfig) => Hex;
4
+ //# sourceMappingURL=fromBigInt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fromBigInt.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/fromBigInt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAIzC,uCAAuC;AACvC,eAAO,MAAM,aAAa,UAEjB,MAAM,WAEL,SAAS,KAChB,GAKF,CAAA"}
@@ -0,0 +1,3 @@
1
+ import { Hex, HexConfig } from '../model';
2
+ export declare const hexFromNumber: (value: number, config?: HexConfig) => Hex;
3
+ //# sourceMappingURL=fromNumber.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fromNumber.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/fromNumber.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAGzC,eAAO,MAAM,aAAa,UAAW,MAAM,WAAW,SAAS,KAAG,GAEjE,CAAA"}
@@ -0,0 +1,3 @@
1
+ import { Hex, HexConfig } from '../model';
2
+ export declare const hexFromNumber: (value: number, config?: HexConfig) => Hex;
3
+ //# sourceMappingURL=fromNumber.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fromNumber.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/fromNumber.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAGzC,eAAO,MAAM,aAAa,UAAW,MAAM,WAAW,SAAS,KAAG,GAEjE,CAAA"}
@@ -0,0 +1,3 @@
1
+ import { Hex, HexConfig } from '../model';
2
+ export declare const hexFromNumber: (value: number, config?: HexConfig) => Hex;
3
+ //# sourceMappingURL=fromNumber.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fromNumber.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/fromNumber.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAGzC,eAAO,MAAM,aAAa,UAAW,MAAM,WAAW,SAAS,KAAG,GAEjE,CAAA"}
@@ -1,3 +1,6 @@
1
1
  export * from './from';
2
+ export * from './fromArrayBuffer';
3
+ export * from './fromBigInt';
2
4
  export * from './fromHexString';
5
+ export * from './fromNumber';
3
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA;AACtB,cAAc,iBAAiB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA;AACtB,cAAc,mBAAmB,CAAA;AACjC,cAAc,cAAc,CAAA;AAC5B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,cAAc,CAAA"}
@@ -1,3 +1,6 @@
1
1
  export * from './from';
2
+ export * from './fromArrayBuffer';
3
+ export * from './fromBigInt';
2
4
  export * from './fromHexString';
5
+ export * from './fromNumber';
3
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA;AACtB,cAAc,iBAAiB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA;AACtB,cAAc,mBAAmB,CAAA;AACjC,cAAc,cAAc,CAAA;AAC5B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,cAAc,CAAA"}
@@ -1,3 +1,6 @@
1
1
  export * from './from';
2
+ export * from './fromArrayBuffer';
3
+ export * from './fromBigInt';
2
4
  export * from './fromHexString';
5
+ export * from './fromNumber';
3
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA;AACtB,cAAc,iBAAiB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/hex/from/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA;AACtB,cAAc,mBAAmB,CAAA;AACjC,cAAc,cAAc,CAAA;AAC5B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,cAAc,CAAA"}
@@ -6,4 +6,5 @@ export * from './legacy';
6
6
  export * from './model';
7
7
  export * from './nibble';
8
8
  export * from './regex';
9
+ export * from './to';
9
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hex/index.ts"],"names":[],"mappings":"AAAA,cAAc,MAAM,CAAA;AACpB,cAAc,QAAQ,CAAA;AACtB,cAAc,MAAM,CAAA;AACpB,cAAc,aAAa,CAAA;AAC3B,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hex/index.ts"],"names":[],"mappings":"AAAA,cAAc,MAAM,CAAA;AACpB,cAAc,QAAQ,CAAA;AACtB,cAAc,MAAM,CAAA;AACpB,cAAc,aAAa,CAAA;AAC3B,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,MAAM,CAAA"}
@@ -6,4 +6,5 @@ export * from './legacy';
6
6
  export * from './model';
7
7
  export * from './nibble';
8
8
  export * from './regex';
9
+ export * from './to';
9
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hex/index.ts"],"names":[],"mappings":"AAAA,cAAc,MAAM,CAAA;AACpB,cAAc,QAAQ,CAAA;AACtB,cAAc,MAAM,CAAA;AACpB,cAAc,aAAa,CAAA;AAC3B,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hex/index.ts"],"names":[],"mappings":"AAAA,cAAc,MAAM,CAAA;AACpB,cAAc,QAAQ,CAAA;AACtB,cAAc,MAAM,CAAA;AACpB,cAAc,aAAa,CAAA;AAC3B,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,MAAM,CAAA"}
@@ -6,4 +6,5 @@ export * from './legacy';
6
6
  export * from './model';
7
7
  export * from './nibble';
8
8
  export * from './regex';
9
+ export * from './to';
9
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hex/index.ts"],"names":[],"mappings":"AAAA,cAAc,MAAM,CAAA;AACpB,cAAc,QAAQ,CAAA;AACtB,cAAc,MAAM,CAAA;AACpB,cAAc,aAAa,CAAA;AAC3B,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hex/index.ts"],"names":[],"mappings":"AAAA,cAAc,MAAM,CAAA;AACpB,cAAc,QAAQ,CAAA;AACtB,cAAc,MAAM,CAAA;AACpB,cAAc,aAAa,CAAA;AAC3B,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,MAAM,CAAA"}
@@ -1,4 +1,2 @@
1
1
  export declare const toHexLegacy: (buffer: ArrayBuffer) => string;
2
- /** @deprecated use toHexLegacy instead */
3
- export declare const toHex: (buffer: ArrayBuffer) => string;
4
2
  //# sourceMappingURL=legacy.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"legacy.d.ts","sourceRoot":"","sources":["../../../src/hex/legacy.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,WAAY,WAAW,WAE9C,CAAA;AAED,0CAA0C;AAC1C,eAAO,MAAM,KAAK,WAAY,WAAW,WAExC,CAAA"}
1
+ {"version":3,"file":"legacy.d.ts","sourceRoot":"","sources":["../../../src/hex/legacy.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,WAAY,WAAW,WAE9C,CAAA"}
@@ -1,4 +1,2 @@
1
1
  export declare const toHexLegacy: (buffer: ArrayBuffer) => string;
2
- /** @deprecated use toHexLegacy instead */
3
- export declare const toHex: (buffer: ArrayBuffer) => string;
4
2
  //# sourceMappingURL=legacy.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"legacy.d.ts","sourceRoot":"","sources":["../../../src/hex/legacy.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,WAAY,WAAW,WAE9C,CAAA;AAED,0CAA0C;AAC1C,eAAO,MAAM,KAAK,WAAY,WAAW,WAExC,CAAA"}
1
+ {"version":3,"file":"legacy.d.ts","sourceRoot":"","sources":["../../../src/hex/legacy.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,WAAY,WAAW,WAE9C,CAAA"}
@@ -1,4 +1,2 @@
1
1
  export declare const toHexLegacy: (buffer: ArrayBuffer) => string;
2
- /** @deprecated use toHexLegacy instead */
3
- export declare const toHex: (buffer: ArrayBuffer) => string;
4
2
  //# sourceMappingURL=legacy.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"legacy.d.ts","sourceRoot":"","sources":["../../../src/hex/legacy.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,WAAY,WAAW,WAE9C,CAAA;AAED,0CAA0C;AAC1C,eAAO,MAAM,KAAK,WAAY,WAAW,WAExC,CAAA"}
1
+ {"version":3,"file":"legacy.d.ts","sourceRoot":"","sources":["../../../src/hex/legacy.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,WAAY,WAAW,WAE9C,CAAA"}
@@ -1,4 +1,5 @@
1
1
  export type Hex = Exclude<Lowercase<string>, 'reserved-hex-value'>;
2
+ /** Configuration of validation and output format */
2
3
  export interface HexConfig {
3
4
  bitLength?: number;
4
5
  byteSize?: number;
@@ -1 +1 @@
1
- {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../src/hex/model.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,GAAG,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,oBAAoB,CAAC,CAAA;AAElE,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":"AACA,MAAM,MAAM,GAAG,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,oBAAoB,CAAC,CAAA;AAElE,oDAAoD;AACpD,MAAM,WAAW,SAAS;IACxB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB"}
@@ -1,4 +1,5 @@
1
1
  export type Hex = Exclude<Lowercase<string>, 'reserved-hex-value'>;
2
+ /** Configuration of validation and output format */
2
3
  export interface HexConfig {
3
4
  bitLength?: number;
4
5
  byteSize?: number;
@@ -1 +1 @@
1
- {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../src/hex/model.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,GAAG,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,oBAAoB,CAAC,CAAA;AAElE,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":"AACA,MAAM,MAAM,GAAG,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,oBAAoB,CAAC,CAAA;AAElE,oDAAoD;AACpD,MAAM,WAAW,SAAS;IACxB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB"}
@@ -1,4 +1,5 @@
1
1
  export type Hex = Exclude<Lowercase<string>, 'reserved-hex-value'>;
2
+ /** Configuration of validation and output format */
2
3
  export interface HexConfig {
3
4
  bitLength?: number;
4
5
  byteSize?: number;
@@ -1 +1 @@
1
- {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../src/hex/model.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,GAAG,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,oBAAoB,CAAC,CAAA;AAElE,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":"AACA,MAAM,MAAM,GAAG,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,oBAAoB,CAAC,CAAA;AAElE,oDAAoD;AACpD,MAAM,WAAW,SAAS;IACxB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB"}
@@ -0,0 +1,4 @@
1
+ import { HexConfig } from './model';
2
+ /** takes any value and tries our best to convert it to a hex string */
3
+ export declare const toHex: (value: unknown, config?: HexConfig) => Lowercase<string>;
4
+ //# sourceMappingURL=to.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"to.d.ts","sourceRoot":"","sources":["../../../src/hex/to.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAEnC,uEAAuE;AACvE,eAAO,MAAM,KAAK,UAET,OAAO,WAEN,SAAS,sBAIlB,CAAA"}
@@ -0,0 +1,4 @@
1
+ import { HexConfig } from './model';
2
+ /** takes any value and tries our best to convert it to a hex string */
3
+ export declare const toHex: (value: unknown, config?: HexConfig) => Lowercase<string>;
4
+ //# sourceMappingURL=to.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"to.d.ts","sourceRoot":"","sources":["../../../src/hex/to.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAEnC,uEAAuE;AACvE,eAAO,MAAM,KAAK,UAET,OAAO,WAEN,SAAS,sBAIlB,CAAA"}
@@ -0,0 +1,4 @@
1
+ import { HexConfig } from './model';
2
+ /** takes any value and tries our best to convert it to a hex string */
3
+ export declare const toHex: (value: unknown, config?: HexConfig) => Lowercase<string>;
4
+ //# sourceMappingURL=to.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"to.d.ts","sourceRoot":"","sources":["../../../src/hex/to.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAEnC,uEAAuE;AACvE,eAAO,MAAM,KAAK,UAET,OAAO,WAEN,SAAS,sBAIlB,CAAA"}
@@ -96,20 +96,26 @@ var hexFromHexString = (value, config = {}) => {
96
96
  }
97
97
  };
98
98
 
99
- // src/hex/from/from.ts
99
+ // src/hex/from/fromArrayBuffer.ts
100
100
  var hexFromArrayBuffer = (buffer, config) => {
101
101
  const unPadded = [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, "0")).join("");
102
102
  return hexFromHexString(unPadded, config);
103
103
  };
104
+
105
+ // src/hex/from/fromBigInt.ts
104
106
  var hexFromBigInt = (value, config = {}) => {
105
107
  const { bitLength } = config;
106
108
  const unPadded = value.toString(16);
107
109
  const padded = bitLength === void 0 ? unPadded : unPadded.padStart(bitsToNibbles(bitLength), "0");
108
110
  return hexFromHexString(padded, config);
109
111
  };
112
+
113
+ // src/hex/from/fromNumber.ts
110
114
  var hexFromNumber = (value, config) => {
111
115
  return hexFromBigInt(BigInt(value), config);
112
116
  };
117
+
118
+ // src/hex/from/from.ts
113
119
  var hexFrom = (value, config) => {
114
120
  switch (typeof value) {
115
121
  case "string": {
@@ -158,8 +164,11 @@ var isHexZero = (value) => {
158
164
  var toHexLegacy = (buffer) => {
159
165
  return [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, "0")).join("");
160
166
  };
161
- var toHex = (buffer) => {
162
- return toHexLegacy(buffer);
167
+
168
+ // src/hex/to.ts
169
+ var toHex = (value, config = {}) => {
170
+ const { prefix = false } = config;
171
+ return hexFrom(value, { prefix, ...config });
163
172
  };
164
173
 
165
174
  // src/address.ts
@@ -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 { 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 = Exclude<Hex, 'reserved-address-value'>\n\nexport const toAddress = (value: unknown, config: HexConfig = {}) => {\n const { bitLength = 160, prefix = false } = config\n return hexFrom(value, { bitLength, prefix, ...config })\n}\n\nexport const isAddress = (value: unknown, config: HexConfig = {}): value is Address => {\n const { bitLength = 160, prefix = false } = config\n return isHex(value, { bitLength, prefix })\n}\n\nexport function asAddress(value: unknown): Address | undefined\nexport function asAddress(value: unknown, assert: AssertConfig): Address\nexport function asAddress(value: unknown, assert?: AssertConfig): Address | undefined {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value, { prefix: false })\n break\n }\n default: {\n return assert ? assertError(value, assert, `Unsupported type [${typeof value}]`) : undefined\n }\n }\n return isAddress(stringValue) ? stringValue : assertError(value, assert, `Value is not an Address [${value}]`)\n}\n","import { AssertConfig, assertError } from './assert'\nimport { Hex, hexFromHexString, isHex } from './hex'\n\nexport type HashBitLength = 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096\nexport const HashBitLength: HashBitLength[] = [32, 64, 128, 256, 512, 1024, 2048, 4096]\n\nexport const isHashBitLength = (value: unknown): value is HashBitLength => {\n return typeof value === 'number' && HashBitLength.includes(value as HashBitLength)\n}\n\nexport type Hash = Exclude<Hex, 'reserved-hash-value'>\nexport const isHash = (value: unknown, bitLength: HashBitLength = 256): value is Hash => {\n return isHex(value, { bitLength })\n}\n\nexport function asHash(value: unknown): Hash | undefined\nexport function asHash(value: unknown, assert: AssertConfig): Hash\nexport function asHash(value: unknown, assert?: AssertConfig): Hash | undefined {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value)\n break\n }\n default: {\n return assert ? assertError(value, assert, `Unsupported type [${typeof value}]`) : undefined\n }\n }\n return isH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AAQ,MAAM,CAAC;AACvD;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;;;AC1BO,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/index.ts","../../src/assert.ts","../../src/hex/from/from.ts","../../src/hex/nibble.ts","../../src/hex/regex.ts","../../src/hex/is.ts","../../src/hex/from/fromHexString.ts","../../src/hex/from/fromArrayBuffer.ts","../../src/hex/from/fromBigInt.ts","../../src/hex/from/fromNumber.ts","../../src/hex/as.ts","../../src/hex/isHexZero.ts","../../src/hex/legacy.ts","../../src/hex/to.ts","../../src/address.ts","../../src/hash.ts"],"sourcesContent":["export * from './address'\nexport * from './hash'\nexport * from './hex'\n","export type AssertCallback = (value: unknown, message: string) => string | boolean\n\nexport type AssertConfig = string | AssertCallback | boolean\n\nexport const assertError = (value: unknown, assert: AssertConfig | undefined, defaultMessage: string) => {\n if (assert) {\n const assertString =\n typeof assert === 'string' ? assert\n : typeof assert === 'boolean' ? defaultMessage\n : assert(value, defaultMessage)\n if (assertString) {\n throw new Error(assertString === true ? defaultMessage : assertString)\n }\n }\n // eslint-disable-next-line unicorn/no-useless-undefined\n return undefined\n}\n","import { isArrayBuffer } from '@xylabs/arraybuffer'\n\nimport { Hex, HexConfig } from '../model'\nimport { hexFromArrayBuffer } from './fromArrayBuffer'\nimport { hexFromBigInt } from './fromBigInt'\nimport { hexFromHexString } from './fromHexString'\nimport { hexFromNumber } from './fromNumber'\n\n/** Takes unknown value and tries our best to convert it to a hex string */\nexport const hexFrom = (\n /** Supported types are string, number, bigint, and ArrayBuffer */\n value: unknown,\n /** Configuration of output format and validation */\n config?: HexConfig,\n): Hex => {\n switch (typeof value) {\n case 'string': {\n return hexFromHexString(value, config)\n }\n case 'bigint': {\n return hexFromBigInt(value, config)\n }\n case 'number': {\n return hexFromNumber(value, config)\n }\n case 'object': {\n if (isArrayBuffer(value)) {\n return hexFromArrayBuffer(value, config)\n } else {\n throw new Error('Invalid type: object !== ArrayBuffer')\n }\n }\n default: {\n throw new Error(`Invalid type: ${typeof value}`)\n }\n }\n}\n","//determine the number of nibbles for a given number of bits\nexport const bitsToNibbles = (value: number): number => {\n const nibbles = value >> 2\n if (value !== nibbles << 2) throw new Error('Bits for nibbles must multiple of 4')\n return nibbles\n}\n\n//determine the number of nibbles for a given number of bits\nexport const nibblesToBits = (value: number): number => {\n return value << 2\n}\n","export const hexRegex = /^[\\da-f]+$/i\nexport const hexRegexWithPrefix = /0x[\\da-f]+$/i\n","import { Hex, HexConfig } from './model'\nimport { bitsToNibbles } from './nibble'\nimport { hexRegex, hexRegexWithPrefix } from './regex'\n\nexport const isHex = (value: unknown, config?: HexConfig): value is Hex => {\n //Is it a string?\n if (typeof value !== 'string') return false\n\n const valueCharLength = config?.prefix ? value.length - 2 : value.length\n\n //If a bitLength specified, does it conform?\n if (config?.bitLength !== undefined && valueCharLength !== bitsToNibbles(config?.bitLength)) return false\n\n //Does it only has hex values?\n return config?.prefix ? hexRegexWithPrefix.test(value) : hexRegex.test(value)\n}\n","import { isHex } from '../is'\nimport { Hex, HexConfig } from '../model'\nimport { bitsToNibbles } from '../nibble'\n\nexport const hexFromHexString = (value: string, config: HexConfig = {}): Hex => {\n const { prefix = false, byteSize = 8 } = config\n const nibbleBoundary = bitsToNibbles(byteSize)\n const unPadded = (value.startsWith('0x') ? value.slice(2) : value).toLowerCase()\n if (isHex(unPadded)) {\n const padded = unPadded.padStart(unPadded.length + (unPadded.length % nibbleBoundary), '0')\n return (prefix ? `0x${padded}` : padded).toLowerCase() as Hex\n } else {\n throw new Error('Received string is not a value hex')\n }\n}\n","import { Hex, HexConfig } from '../model'\nimport { hexFromHexString } from './fromHexString'\n\n/** Convert an ArrayBuffer to a hex string */\nexport const hexFromArrayBuffer = (\n /** The buffer to be converted */\n buffer: ArrayBuffer,\n /** Configuration of output format and validation */\n config?: HexConfig,\n): Hex => {\n const unPadded = [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, '0')).join('')\n return hexFromHexString(unPadded, config)\n}\n","import { Hex, HexConfig } from '../model'\nimport { bitsToNibbles } from '../nibble'\nimport { hexFromHexString } from './fromHexString'\n\n/** Convert a bigint to a hex string */\nexport const hexFromBigInt = (\n /** The bigint to be converted */\n value: bigint,\n /** Configuration of output format and validation */\n config: HexConfig = {},\n): Hex => {\n const { bitLength } = config\n const unPadded = value.toString(16)\n const padded = bitLength === undefined ? unPadded : unPadded.padStart(bitsToNibbles(bitLength), '0')\n return hexFromHexString(padded, config)\n}\n","import { Hex, HexConfig } from '../model'\nimport { hexFromBigInt } from './fromBigInt'\n\nexport const hexFromNumber = (value: number, config?: HexConfig): Hex => {\n return hexFromBigInt(BigInt(value), config)\n}\n","import { AssertConfig, assertError } from '../assert'\nimport { hexFromHexString } from './from'\nimport { isHex } from './is'\nimport { Hex } from './model'\n\nexport function asHex(value: unknown): Hex | undefined\nexport function asHex(value: unknown, assert: AssertConfig): Hex\nexport function asHex(value: unknown, assert?: AssertConfig): Hex | undefined {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value)\n break\n }\n default: {\n return assertError(value, assert, `Unsupported type [${typeof value}]`)\n }\n }\n\n return isHex(stringValue) ? stringValue : assertError(value, assert, `Value is not Hex [${value}]`)\n}\n","import { hexFromHexString } from './from'\n\nexport const isHexZero = (value?: string) => {\n return value ? BigInt(hexFromHexString(value, { prefix: true })) === 0n : undefined\n}\n","export const toHexLegacy = (buffer: ArrayBuffer) => {\n return [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, '0')).join('')\n}\n","import { hexFrom } from './from'\nimport { HexConfig } from './model'\n\n/** takes any value and tries our best to convert it to a hex string */\nexport const toHex = (\n /** Supported types are string, number, bigint, and ArrayBuffer */\n value: unknown,\n /** Configuration of output format and validation */\n config: HexConfig = {},\n) => {\n const { prefix = false } = config\n return hexFrom(value, { prefix, ...config })\n}\n","import { AssertConfig, assertError } from './assert'\nimport { Hex, HexConfig, hexFrom, hexFromHexString, isHex } from './hex'\n\nexport type Address = Exclude<Hex, 'reserved-address-value'>\n\nexport const toAddress = (value: unknown, config: HexConfig = {}) => {\n const { bitLength = 160, prefix = false } = config\n return hexFrom(value, { bitLength, prefix, ...config })\n}\n\nexport const isAddress = (value: unknown, config: HexConfig = {}): value is Address => {\n const { bitLength = 160, prefix = false } = config\n return isHex(value, { bitLength, prefix })\n}\n\nexport function asAddress(value: unknown): Address | undefined\nexport function asAddress(value: unknown, assert: AssertConfig): Address\nexport function asAddress(value: unknown, assert?: AssertConfig): Address | undefined {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value, { prefix: false })\n break\n }\n default: {\n return assert ? assertError(value, assert, `Unsupported type [${typeof value}]`) : undefined\n }\n }\n return isAddress(stringValue) ? stringValue : assertError(value, assert, `Value is not an Address [${value}]`)\n}\n","import { AssertConfig, assertError } from './assert'\nimport { Hex, hexFromHexString, isHex } from './hex'\n\nexport type HashBitLength = 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096\nexport const HashBitLength: HashBitLength[] = [32, 64, 128, 256, 512, 1024, 2048, 4096]\n\nexport const isHashBitLength = (value: unknown): value is HashBitLength => {\n return typeof value === 'number' && HashBitLength.includes(value as HashBitLength)\n}\n\nexport type Hash = Exclude<Hex, 'reserved-hash-value'>\nexport const isHash = (value: unknown, bitLength: HashBitLength = 256): value is Hash => {\n return isHex(value, { bitLength })\n}\n\nexport function asHash(value: unknown): Hash | undefined\nexport function asHash(value: unknown, assert: AssertConfig): Hash\nexport function asHash(value: unknown, assert?: AssertConfig): Hash | undefined {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value)\n break\n }\n default: {\n return assert ? assertError(value, assert, `Unsupported type [${typeof value}]`) : undefined\n }\n }\n return isHash(stringValue) ? stringValue : assertError(value, assert, `Value is not a Hash [${value}]`)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACIO,IAAM,cAAc,CAAC,OAAgB,QAAkC,mBAA2B;AACvG,MAAI,QAAQ;AACV,UAAM,eACJ,OAAO,WAAW,WAAW,SAC3B,OAAO,WAAW,YAAY,iBAC9B,OAAO,OAAO,cAAc;AAChC,QAAI,cAAc;AAChB,YAAM,IAAI,MAAM,iBAAiB,OAAO,iBAAiB,YAAY;AAAA,IACvE;AAAA,EACF;AAEA,SAAO;AACT;;;AChBA,yBAA8B;;;ACCvB,IAAM,gBAAgB,CAAC,UAA0B;AACtD,QAAM,UAAU,SAAS;AACzB,MAAI,UAAU,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B,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":[]}
@@ -50,20 +50,26 @@ var hexFromHexString = (value, config = {}) => {
50
50
  }
51
51
  };
52
52
 
53
- // src/hex/from/from.ts
53
+ // src/hex/from/fromArrayBuffer.ts
54
54
  var hexFromArrayBuffer = (buffer, config) => {
55
55
  const unPadded = [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, "0")).join("");
56
56
  return hexFromHexString(unPadded, config);
57
57
  };
58
+
59
+ // src/hex/from/fromBigInt.ts
58
60
  var hexFromBigInt = (value, config = {}) => {
59
61
  const { bitLength } = config;
60
62
  const unPadded = value.toString(16);
61
63
  const padded = bitLength === void 0 ? unPadded : unPadded.padStart(bitsToNibbles(bitLength), "0");
62
64
  return hexFromHexString(padded, config);
63
65
  };
66
+
67
+ // src/hex/from/fromNumber.ts
64
68
  var hexFromNumber = (value, config) => {
65
69
  return hexFromBigInt(BigInt(value), config);
66
70
  };
71
+
72
+ // src/hex/from/from.ts
67
73
  var hexFrom = (value, config) => {
68
74
  switch (typeof value) {
69
75
  case "string": {
@@ -112,8 +118,11 @@ var isHexZero = (value) => {
112
118
  var toHexLegacy = (buffer) => {
113
119
  return [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, "0")).join("");
114
120
  };
115
- var toHex = (buffer) => {
116
- return toHexLegacy(buffer);
121
+
122
+ // src/hex/to.ts
123
+ var toHex = (value, config = {}) => {
124
+ const { prefix = false } = config;
125
+ return hexFrom(value, { prefix, ...config });
117
126
  };
118
127
 
119
128
  // src/address.ts
@@ -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 { 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 = Exclude<Hex, 'reserved-address-value'>\n\nexport const toAddress = (value: unknown, config: HexConfig = {}) => {\n const { bitLength = 160, prefix = false } = config\n return hexFrom(value, { bitLength, prefix, ...config })\n}\n\nexport const isAddress = (value: unknown, config: HexConfig = {}): value is Address => {\n const { bitLength = 160, prefix = false } = config\n return isHex(value, { bitLength, prefix })\n}\n\nexport function asAddress(value: unknown): Address | undefined\nexport function asAddress(value: unknown, assert: AssertConfig): Address\nexport function asAddress(value: unknown, assert?: AssertConfig): Address | undefined {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value, { prefix: false })\n break\n }\n default: {\n return assert ? assertError(value, assert, `Unsupported type [${typeof value}]`) : undefined\n }\n }\n return isAddress(stringValue) ? stringValue : assertError(value, assert, `Value is not an Address [${value}]`)\n}\n","import { AssertConfig, assertError } from './assert'\nimport { Hex, hexFromHexString, isHex } from './hex'\n\nexport type HashBitLength = 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096\nexport const HashBitLength: HashBitLength[] = [32, 64, 128, 256, 512, 1024, 2048, 4096]\n\nexport const isHashBitLength = (value: unknown): value is HashBitLength => {\n return typeof value === 'number' && HashBitLength.includes(value as HashBitLength)\n}\n\nexport type Hash = Exclude<Hex, 'reserved-hash-value'>\nexport const isHash = (value: unknown, bitLength: HashBitLength = 256): value is Hash => {\n return isHex(value, { bitLength })\n}\n\nexport function asHash(value: unknown): Hash | undefined\nexport function asHash(value: unknown, assert: AssertConfig): Hash\nexport function asHash(value: unknown, assert?: AssertConfig): Hash | undefined {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value)\n break\n }\n default: {\n return assert ? assertError(value, assert, `Unsupported type [${typeof value}]`) : undefined\n }\n }\n return isHash(stringValue) ? stringValue : assertError(value, assert, `Value is not a Hash [${value}]`)\n}\n"],"mappings":";AAIO,IAAM,cAAc,CAAC,OAAgB,QAAkC,mBAA2B;AACvG,MAAI,QAAQ;AACV,UAAM,eACJ,OAAO,WAAW,WAAW,SAC3B,OAAO,WAAW,YAAY,iBAC9B,OAAO,OAAO,cAAc;AAChC,QAAI,cAAc;AAChB,YAAM,IAAI,MAAM,iBAAiB,OAAO,iBAAiB,YAAY;AAAA,IACvE;AAAA,EACF;AAEA,SAAO;AACT;;;AChBA,SAAS,qBAAqB;;;ACCvB,IAAM,gBAAgB,CAAC,UAA0B;AACtD,QAAM,UAAU,SAAS;AACzB,MAAI,UAAU,WAAW;AAAG,UAAM,IAAI,MAAM,qCAAqC;AACjF,SAAO;AACT;AAGO,IAAM,gBAAgB,CAAC,UAA0B;AACtD,SAAO,SAAS;AAClB;;;ACVO,IAAM,WAAW;AACjB,IAAM,qBAAqB;;;ACG3B,IAAM,QAAQ,CAAC,OAAgB,WAAqC;AAEzE,MAAI,OAAO,UAAU;AAAU,WAAO;AAEtC,QAAM,kBAAkB,QAAQ,SAAS,MAAM,SAAS,IAAI,MAAM;AAGlE,MAAI,QAAQ,cAAc,UAAa,oBAAoB,cAAc,QAAQ,SAAS;AAAG,WAAO;AAGpG,SAAO,QAAQ,SAAS,mBAAmB,KAAK,KAAK,IAAI,SAAS,KAAK,KAAK;AAC9E;;;ACXO,IAAM,mBAAm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,EAAE,WAAW,OAAO,CAAC;AAC3C;AAIO,SAAS,UAAU,OAAgB,QAA4C;AACpF,MAAI,cAAkC;AAEtC,UAAQ,OAAO,OAAO;AAAA,IACpB,KAAK,UAAU;AACb,oBAAc,iBAAiB,OAAO,EAAE,QAAQ,MAAM,CAAC;AACvD;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;;;AC1BO,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/from/fromArrayBuffer.ts","../../src/hex/from/fromBigInt.ts","../../src/hex/from/fromNumber.ts","../../src/hex/as.ts","../../src/hex/isHexZero.ts","../../src/hex/legacy.ts","../../src/hex/to.ts","../../src/address.ts","../../src/hash.ts"],"sourcesContent":["export type AssertCallback = (value: unknown, message: string) => string | boolean\n\nexport type AssertConfig = string | AssertCallback | boolean\n\nexport const assertError = (value: unknown, assert: AssertConfig | undefined, defaultMessage: string) => {\n if (assert) {\n const assertString =\n typeof assert === 'string' ? assert\n : typeof assert === 'boolean' ? defaultMessage\n : assert(value, defaultMessage)\n if (assertString) {\n throw new Error(assertString === true ? defaultMessage : assertString)\n }\n }\n // eslint-disable-next-line unicorn/no-useless-undefined\n return undefined\n}\n","import { isArrayBuffer } from '@xylabs/arraybuffer'\n\nimport { Hex, HexConfig } from '../model'\nimport { hexFromArrayBuffer } from './fromArrayBuffer'\nimport { hexFromBigInt } from './fromBigInt'\nimport { hexFromHexString } from './fromHexString'\nimport { hexFromNumber } from './fromNumber'\n\n/** Takes unknown value and tries our best to convert it to a hex string */\nexport const hexFrom = (\n /** Supported types are string, number, bigint, and ArrayBuffer */\n value: unknown,\n /** Configuration of output format and validation */\n config?: HexConfig,\n): Hex => {\n switch (typeof value) {\n case 'string': {\n return hexFromHexString(value, config)\n }\n case 'bigint': {\n return hexFromBigInt(value, config)\n }\n case 'number': {\n return hexFromNumber(value, config)\n }\n case 'object': {\n if (isArrayBuffer(value)) {\n return hexFromArrayBuffer(value, config)\n } else {\n throw new Error('Invalid type: object !== ArrayBuffer')\n }\n }\n default: {\n throw new Error(`Invalid type: ${typeof value}`)\n }\n }\n}\n","//determine the number of nibbles for a given number of bits\nexport const bitsToNibbles = (value: number): number => {\n const nibbles = value >> 2\n if (value !== nibbles << 2) throw new Error('Bits for nibbles must multiple of 4')\n return nibbles\n}\n\n//determine the number of nibbles for a given number of bits\nexport const nibblesToBits = (value: number): number => {\n return value << 2\n}\n","export const hexRegex = /^[\\da-f]+$/i\nexport const hexRegexWithPrefix = /0x[\\da-f]+$/i\n","import { Hex, HexConfig } from './model'\nimport { bitsToNibbles } from './nibble'\nimport { hexRegex, hexRegexWithPrefix } from './regex'\n\nexport const isHex = (value: unknown, config?: HexConfig): value is Hex => {\n //Is it a string?\n if (typeof value !== 'string') return false\n\n const valueCharLength = config?.prefix ? value.length - 2 : value.length\n\n //If a bitLength specified, does it conform?\n if (config?.bitLength !== undefined && valueCharLength !== bitsToNibbles(config?.bitLength)) return false\n\n //Does it only has hex values?\n return config?.prefix ? hexRegexWithPrefix.test(value) : hexRegex.test(value)\n}\n","import { isHex } from '../is'\nimport { Hex, HexConfig } from '../model'\nimport { bitsToNibbles } from '../nibble'\n\nexport const hexFromHexString = (value: string, config: HexConfig = {}): Hex => {\n const { prefix = false, byteSize = 8 } = config\n const nibbleBoundary = bitsToNibbles(byteSize)\n const unPadded = (value.startsWith('0x') ? value.slice(2) : value).toLowerCase()\n if (isHex(unPadded)) {\n const padded = unPadded.padStart(unPadded.length + (unPadded.length % nibbleBoundary), '0')\n return (prefix ? `0x${padded}` : padded).toLowerCase() as Hex\n } else {\n throw new Error('Received string is not a value hex')\n }\n}\n","import { Hex, HexConfig } from '../model'\nimport { hexFromHexString } from './fromHexString'\n\n/** Convert an ArrayBuffer to a hex string */\nexport const hexFromArrayBuffer = (\n /** The buffer to be converted */\n buffer: ArrayBuffer,\n /** Configuration of output format and validation */\n config?: HexConfig,\n): Hex => {\n const unPadded = [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, '0')).join('')\n return hexFromHexString(unPadded, config)\n}\n","import { Hex, HexConfig } from '../model'\nimport { bitsToNibbles } from '../nibble'\nimport { hexFromHexString } from './fromHexString'\n\n/** Convert a bigint to a hex string */\nexport const hexFromBigInt = (\n /** The bigint to be converted */\n value: bigint,\n /** Configuration of output format and validation */\n config: HexConfig = {},\n): Hex => {\n const { bitLength } = config\n const unPadded = value.toString(16)\n const padded = bitLength === undefined ? unPadded : unPadded.padStart(bitsToNibbles(bitLength), '0')\n return hexFromHexString(padded, config)\n}\n","import { Hex, HexConfig } from '../model'\nimport { hexFromBigInt } from './fromBigInt'\n\nexport const hexFromNumber = (value: number, config?: HexConfig): Hex => {\n return hexFromBigInt(BigInt(value), config)\n}\n","import { AssertConfig, assertError } from '../assert'\nimport { hexFromHexString } from './from'\nimport { isHex } from './is'\nimport { Hex } from './model'\n\nexport function asHex(value: unknown): Hex | undefined\nexport function asHex(value: unknown, assert: AssertConfig): Hex\nexport function asHex(value: unknown, assert?: AssertConfig): Hex | undefined {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value)\n break\n }\n default: {\n return assertError(value, assert, `Unsupported type [${typeof value}]`)\n }\n }\n\n return isHex(stringValue) ? stringValue : assertError(value, assert, `Value is not Hex [${value}]`)\n}\n","import { hexFromHexString } from './from'\n\nexport const isHexZero = (value?: string) => {\n return value ? BigInt(hexFromHexString(value, { prefix: true })) === 0n : undefined\n}\n","export const toHexLegacy = (buffer: ArrayBuffer) => {\n return [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, '0')).join('')\n}\n","import { hexFrom } from './from'\nimport { HexConfig } from './model'\n\n/** takes any value and tries our best to convert it to a hex string */\nexport const toHex = (\n /** Supported types are string, number, bigint, and ArrayBuffer */\n value: unknown,\n /** Configuration of output format and validation */\n config: HexConfig = {},\n) => {\n const { prefix = false } = config\n return hexFrom(value, { prefix, ...config })\n}\n","import { AssertConfig, assertError } from './assert'\nimport { Hex, HexConfig, hexFrom, hexFromHexString, isHex } from './hex'\n\nexport type Address = Exclude<Hex, 'reserved-address-value'>\n\nexport const toAddress = (value: unknown, config: HexConfig = {}) => {\n const { bitLength = 160, prefix = false } = config\n return hexFrom(value, { bitLength, prefix, ...config })\n}\n\nexport const isAddress = (value: unknown, config: HexConfig = {}): value is Address => {\n const { bitLength = 160, prefix = false } = config\n return isHex(value, { bitLength, prefix })\n}\n\nexport function asAddress(value: unknown): Address | undefined\nexport function asAddress(value: unknown, assert: AssertConfig): Address\nexport function asAddress(value: unknown, assert?: AssertConfig): Address | undefined {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value, { prefix: false })\n break\n }\n default: {\n return assert ? assertError(value, assert, `Unsupported type [${typeof value}]`) : undefined\n }\n }\n return isAddress(stringValue) ? stringValue : assertError(value, assert, `Value is not an Address [${value}]`)\n}\n","import { AssertConfig, assertError } from './assert'\nimport { Hex, hexFromHexString, isHex } from './hex'\n\nexport type HashBitLength = 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096\nexport const HashBitLength: HashBitLength[] = [32, 64, 128, 256, 512, 1024, 2048, 4096]\n\nexport const isHashBitLength = (value: unknown): value is HashBitLength => {\n return typeof value === 'number' && HashBitLength.includes(value as HashBitLength)\n}\n\nexport type Hash = Exclude<Hex, 'reserved-hash-value'>\nexport const isHash = (value: unknown, bitLength: HashBitLength = 256): value is Hash => {\n return isHex(value, { bitLength })\n}\n\nexport function asHash(value: unknown): Hash | undefined\nexport function asHash(value: unknown, assert: AssertConfig): Hash\nexport function asHash(value: unknown, assert?: AssertConfig): Hash | undefined {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value)\n break\n }\n default: {\n return assert ? assertError(value, assert, `Unsupported type [${typeof value}]`) : undefined\n }\n }\n return isHash(stringValue) ? stringValue : assertError(value, assert, `Value is not a Hash [${value}]`)\n}\n"],"mappings":";AAIO,IAAM,cAAc,CAAC,OAAgB,QAAkC,mBAA2B;AACvG,MAAI,QAAQ;AACV,UAAM,eACJ,OAAO,WAAW,WAAW,SAC3B,OAAO,WAAW,YAAY,iBAC9B,OAAO,OAAO,cAAc;AAChC,QAAI,cAAc;AAChB,YAAM,IAAI,MAAM,iBAAiB,OAAO,iBAAiB,YAAY;AAAA,IACvE;AAAA,EACF;AAEA,SAAO;AACT;;;AChBA,SAAS,qBAAqB;;;ACCvB,IAAM,gBAAgB,CAAC,UAA0B;AACtD,QAAM,UAAU,SAAS;AACzB,MAAI,UAAU,WAAW;AAAG,UAAM,IAAI,MAAM,qCAAqC;AACjF,SA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O,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,6 +1,4 @@
1
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;
2
+ /** Takes unknown value and tries our best to convert it to a hex string */
5
3
  export declare const hexFrom: (value: unknown, config?: HexConfig) => Hex;
6
4
  //# 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,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
+ {"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;AAMzC,2EAA2E;AAC3E,eAAO,MAAM,OAAO,UAEX,OAAO,WAEL,SAAS,KACjB,GAsBF,CAAA"}
@@ -1,6 +1,4 @@
1
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;
2
+ /** Takes unknown value and tries our best to convert it to a hex string */
5
3
  export declare const hexFrom: (value: unknown, config?: HexConfig) => Hex;
6
4
  //# 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,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
+ {"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;AAMzC,2EAA2E;AAC3E,eAAO,MAAM,OAAO,UAEX,OAAO,WAEL,SAAS,KACjB,GAsBF,CAAA"}