@apeleghq/sha2 0.1.0

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 (253) hide show
  1. package/LICENSE +13 -0
  2. package/README.md +197 -0
  3. package/package.json +651 -0
  4. package/sha224+deserialize+serialize+streaming.cjs +32 -0
  5. package/sha224+deserialize+serialize+streaming.d.cts +29 -0
  6. package/sha224+deserialize+serialize+streaming.d.mts +29 -0
  7. package/sha224+deserialize+serialize+streaming.mjs +33 -0
  8. package/sha224+sha256+deserialize+serialize+streaming.cjs +36 -0
  9. package/sha224+sha256+deserialize+serialize+streaming.d.cts +29 -0
  10. package/sha224+sha256+deserialize+serialize+streaming.d.mts +29 -0
  11. package/sha224+sha256+deserialize+serialize+streaming.mjs +37 -0
  12. package/sha224+sha256+sha384+deserialize+serialize+streaming.cjs +69 -0
  13. package/sha224+sha256+sha384+deserialize+serialize+streaming.d.cts +29 -0
  14. package/sha224+sha256+sha384+deserialize+serialize+streaming.d.mts +29 -0
  15. package/sha224+sha256+sha384+deserialize+serialize+streaming.mjs +69 -0
  16. package/sha224+sha256+sha384+sha512+deserialize+serialize+streaming.cjs +86 -0
  17. package/sha224+sha256+sha384+sha512+deserialize+serialize+streaming.d.cts +29 -0
  18. package/sha224+sha256+sha384+sha512+deserialize+serialize+streaming.d.mts +29 -0
  19. package/sha224+sha256+sha384+sha512+deserialize+serialize+streaming.mjs +86 -0
  20. package/sha224+sha256+sha384+sha512+sha512_256+deserialize+serialize+streaming.cjs +92 -0
  21. package/sha224+sha256+sha384+sha512+sha512_256+deserialize+serialize+streaming.d.cts +29 -0
  22. package/sha224+sha256+sha384+sha512+sha512_256+deserialize+serialize+streaming.d.mts +29 -0
  23. package/sha224+sha256+sha384+sha512+sha512_256+deserialize+serialize+streaming.mjs +92 -0
  24. package/sha224+sha256+sha384+sha512+sha512_256+streaming.cjs +68 -0
  25. package/sha224+sha256+sha384+sha512+sha512_256+streaming.d.cts +29 -0
  26. package/sha224+sha256+sha384+sha512+sha512_256+streaming.d.mts +29 -0
  27. package/sha224+sha256+sha384+sha512+sha512_256+streaming.mjs +68 -0
  28. package/sha224+sha256+sha384+sha512+streaming.cjs +62 -0
  29. package/sha224+sha256+sha384+sha512+streaming.d.cts +29 -0
  30. package/sha224+sha256+sha384+sha512+streaming.d.mts +29 -0
  31. package/sha224+sha256+sha384+sha512+streaming.mjs +62 -0
  32. package/sha224+sha256+sha384+sha512_256+deserialize+serialize+streaming.cjs +84 -0
  33. package/sha224+sha256+sha384+sha512_256+deserialize+serialize+streaming.d.cts +29 -0
  34. package/sha224+sha256+sha384+sha512_256+deserialize+serialize+streaming.d.mts +29 -0
  35. package/sha224+sha256+sha384+sha512_256+deserialize+serialize+streaming.mjs +85 -0
  36. package/sha224+sha256+sha384+sha512_256+streaming.cjs +60 -0
  37. package/sha224+sha256+sha384+sha512_256+streaming.d.cts +29 -0
  38. package/sha224+sha256+sha384+sha512_256+streaming.d.mts +29 -0
  39. package/sha224+sha256+sha384+sha512_256+streaming.mjs +61 -0
  40. package/sha224+sha256+sha384+streaming.cjs +47 -0
  41. package/sha224+sha256+sha384+streaming.d.cts +29 -0
  42. package/sha224+sha256+sha384+streaming.d.mts +29 -0
  43. package/sha224+sha256+sha384+streaming.mjs +48 -0
  44. package/sha224+sha256+sha512+deserialize+serialize+streaming.cjs +69 -0
  45. package/sha224+sha256+sha512+deserialize+serialize+streaming.d.cts +29 -0
  46. package/sha224+sha256+sha512+deserialize+serialize+streaming.d.mts +29 -0
  47. package/sha224+sha256+sha512+deserialize+serialize+streaming.mjs +70 -0
  48. package/sha224+sha256+sha512+sha512_256+deserialize+serialize+streaming.cjs +85 -0
  49. package/sha224+sha256+sha512+sha512_256+deserialize+serialize+streaming.d.cts +29 -0
  50. package/sha224+sha256+sha512+sha512_256+deserialize+serialize+streaming.d.mts +29 -0
  51. package/sha224+sha256+sha512+sha512_256+deserialize+serialize+streaming.mjs +85 -0
  52. package/sha224+sha256+sha512+sha512_256+streaming.cjs +61 -0
  53. package/sha224+sha256+sha512+sha512_256+streaming.d.cts +29 -0
  54. package/sha224+sha256+sha512+sha512_256+streaming.d.mts +29 -0
  55. package/sha224+sha256+sha512+sha512_256+streaming.mjs +61 -0
  56. package/sha224+sha256+sha512+streaming.cjs +48 -0
  57. package/sha224+sha256+sha512+streaming.d.cts +29 -0
  58. package/sha224+sha256+sha512+streaming.d.mts +29 -0
  59. package/sha224+sha256+sha512+streaming.mjs +49 -0
  60. package/sha224+sha256+sha512_256+deserialize+serialize+streaming.cjs +68 -0
  61. package/sha224+sha256+sha512_256+deserialize+serialize+streaming.d.cts +29 -0
  62. package/sha224+sha256+sha512_256+deserialize+serialize+streaming.d.mts +29 -0
  63. package/sha224+sha256+sha512_256+deserialize+serialize+streaming.mjs +68 -0
  64. package/sha224+sha256+sha512_256+streaming.cjs +47 -0
  65. package/sha224+sha256+sha512_256+streaming.d.cts +29 -0
  66. package/sha224+sha256+sha512_256+streaming.d.mts +29 -0
  67. package/sha224+sha256+sha512_256+streaming.mjs +47 -0
  68. package/sha224+sha256+streaming.cjs +25 -0
  69. package/sha224+sha256+streaming.d.cts +29 -0
  70. package/sha224+sha256+streaming.d.mts +29 -0
  71. package/sha224+sha256+streaming.mjs +26 -0
  72. package/sha224+sha384+deserialize+serialize+streaming.cjs +64 -0
  73. package/sha224+sha384+deserialize+serialize+streaming.d.cts +29 -0
  74. package/sha224+sha384+deserialize+serialize+streaming.d.mts +29 -0
  75. package/sha224+sha384+deserialize+serialize+streaming.mjs +64 -0
  76. package/sha224+sha384+sha512+deserialize+serialize+streaming.cjs +81 -0
  77. package/sha224+sha384+sha512+deserialize+serialize+streaming.d.cts +29 -0
  78. package/sha224+sha384+sha512+deserialize+serialize+streaming.d.mts +29 -0
  79. package/sha224+sha384+sha512+deserialize+serialize+streaming.mjs +81 -0
  80. package/sha224+sha384+sha512+sha512_256+deserialize+serialize+streaming.cjs +87 -0
  81. package/sha224+sha384+sha512+sha512_256+deserialize+serialize+streaming.d.cts +29 -0
  82. package/sha224+sha384+sha512+sha512_256+deserialize+serialize+streaming.d.mts +29 -0
  83. package/sha224+sha384+sha512+sha512_256+deserialize+serialize+streaming.mjs +87 -0
  84. package/sha224+sha384+sha512+sha512_256+streaming.cjs +63 -0
  85. package/sha224+sha384+sha512+sha512_256+streaming.d.cts +29 -0
  86. package/sha224+sha384+sha512+sha512_256+streaming.d.mts +29 -0
  87. package/sha224+sha384+sha512+sha512_256+streaming.mjs +64 -0
  88. package/sha224+sha384+sha512+streaming.cjs +57 -0
  89. package/sha224+sha384+sha512+streaming.d.cts +29 -0
  90. package/sha224+sha384+sha512+streaming.d.mts +29 -0
  91. package/sha224+sha384+sha512+streaming.mjs +57 -0
  92. package/sha224+sha384+sha512_256+deserialize+serialize+streaming.cjs +79 -0
  93. package/sha224+sha384+sha512_256+deserialize+serialize+streaming.d.cts +29 -0
  94. package/sha224+sha384+sha512_256+deserialize+serialize+streaming.d.mts +29 -0
  95. package/sha224+sha384+sha512_256+deserialize+serialize+streaming.mjs +80 -0
  96. package/sha224+sha384+sha512_256+streaming.cjs +55 -0
  97. package/sha224+sha384+sha512_256+streaming.d.cts +29 -0
  98. package/sha224+sha384+sha512_256+streaming.d.mts +29 -0
  99. package/sha224+sha384+sha512_256+streaming.mjs +56 -0
  100. package/sha224+sha384+streaming.cjs +44 -0
  101. package/sha224+sha384+streaming.d.cts +29 -0
  102. package/sha224+sha384+streaming.d.mts +29 -0
  103. package/sha224+sha384+streaming.mjs +44 -0
  104. package/sha224+sha512+deserialize+serialize+streaming.cjs +64 -0
  105. package/sha224+sha512+deserialize+serialize+streaming.d.cts +29 -0
  106. package/sha224+sha512+deserialize+serialize+streaming.d.mts +29 -0
  107. package/sha224+sha512+deserialize+serialize+streaming.mjs +65 -0
  108. package/sha224+sha512+sha512_256+deserialize+serialize+streaming.cjs +80 -0
  109. package/sha224+sha512+sha512_256+deserialize+serialize+streaming.d.cts +29 -0
  110. package/sha224+sha512+sha512_256+deserialize+serialize+streaming.d.mts +29 -0
  111. package/sha224+sha512+sha512_256+deserialize+serialize+streaming.mjs +80 -0
  112. package/sha224+sha512+sha512_256+streaming.cjs +56 -0
  113. package/sha224+sha512+sha512_256+streaming.d.cts +29 -0
  114. package/sha224+sha512+sha512_256+streaming.d.mts +29 -0
  115. package/sha224+sha512+sha512_256+streaming.mjs +56 -0
  116. package/sha224+sha512+streaming.cjs +44 -0
  117. package/sha224+sha512+streaming.d.cts +29 -0
  118. package/sha224+sha512+streaming.d.mts +29 -0
  119. package/sha224+sha512+streaming.mjs +45 -0
  120. package/sha224+sha512_256+deserialize+serialize+streaming.cjs +63 -0
  121. package/sha224+sha512_256+deserialize+serialize+streaming.d.cts +29 -0
  122. package/sha224+sha512_256+deserialize+serialize+streaming.d.mts +29 -0
  123. package/sha224+sha512_256+deserialize+serialize+streaming.mjs +63 -0
  124. package/sha224+sha512_256+streaming.cjs +43 -0
  125. package/sha224+sha512_256+streaming.d.cts +29 -0
  126. package/sha224+sha512_256+streaming.d.mts +29 -0
  127. package/sha224+sha512_256+streaming.mjs +43 -0
  128. package/sha224+streaming.cjs +21 -0
  129. package/sha224+streaming.d.cts +29 -0
  130. package/sha224+streaming.d.mts +29 -0
  131. package/sha224+streaming.mjs +21 -0
  132. package/sha256+deserialize+serialize+streaming.cjs +32 -0
  133. package/sha256+deserialize+serialize+streaming.d.cts +29 -0
  134. package/sha256+deserialize+serialize+streaming.d.mts +29 -0
  135. package/sha256+deserialize+serialize+streaming.mjs +33 -0
  136. package/sha256+sha384+deserialize+serialize+streaming.cjs +64 -0
  137. package/sha256+sha384+deserialize+serialize+streaming.d.cts +29 -0
  138. package/sha256+sha384+deserialize+serialize+streaming.d.mts +29 -0
  139. package/sha256+sha384+deserialize+serialize+streaming.mjs +65 -0
  140. package/sha256+sha384+sha512+deserialize+serialize+streaming.cjs +81 -0
  141. package/sha256+sha384+sha512+deserialize+serialize+streaming.d.cts +29 -0
  142. package/sha256+sha384+sha512+deserialize+serialize+streaming.d.mts +29 -0
  143. package/sha256+sha384+sha512+deserialize+serialize+streaming.mjs +81 -0
  144. package/sha256+sha384+sha512+sha512_256+deserialize+serialize+streaming.cjs +87 -0
  145. package/sha256+sha384+sha512+sha512_256+deserialize+serialize+streaming.d.cts +29 -0
  146. package/sha256+sha384+sha512+sha512_256+deserialize+serialize+streaming.d.mts +29 -0
  147. package/sha256+sha384+sha512+sha512_256+deserialize+serialize+streaming.mjs +88 -0
  148. package/sha256+sha384+sha512+sha512_256+streaming.cjs +63 -0
  149. package/sha256+sha384+sha512+sha512_256+streaming.d.cts +29 -0
  150. package/sha256+sha384+sha512+sha512_256+streaming.d.mts +29 -0
  151. package/sha256+sha384+sha512+sha512_256+streaming.mjs +64 -0
  152. package/sha256+sha384+sha512+streaming.cjs +57 -0
  153. package/sha256+sha384+sha512+streaming.d.cts +29 -0
  154. package/sha256+sha384+sha512+streaming.d.mts +29 -0
  155. package/sha256+sha384+sha512+streaming.mjs +57 -0
  156. package/sha256+sha384+sha512_256+deserialize+serialize+streaming.cjs +79 -0
  157. package/sha256+sha384+sha512_256+deserialize+serialize+streaming.d.cts +29 -0
  158. package/sha256+sha384+sha512_256+deserialize+serialize+streaming.d.mts +29 -0
  159. package/sha256+sha384+sha512_256+deserialize+serialize+streaming.mjs +80 -0
  160. package/sha256+sha384+sha512_256+streaming.cjs +55 -0
  161. package/sha256+sha384+sha512_256+streaming.d.cts +29 -0
  162. package/sha256+sha384+sha512_256+streaming.d.mts +29 -0
  163. package/sha256+sha384+sha512_256+streaming.mjs +56 -0
  164. package/sha256+sha384+streaming.cjs +44 -0
  165. package/sha256+sha384+streaming.d.cts +29 -0
  166. package/sha256+sha384+streaming.d.mts +29 -0
  167. package/sha256+sha384+streaming.mjs +44 -0
  168. package/sha256+sha512+deserialize+serialize+streaming.cjs +65 -0
  169. package/sha256+sha512+deserialize+serialize+streaming.d.cts +29 -0
  170. package/sha256+sha512+deserialize+serialize+streaming.d.mts +29 -0
  171. package/sha256+sha512+deserialize+serialize+streaming.mjs +65 -0
  172. package/sha256+sha512+sha512_256+deserialize+serialize+streaming.cjs +80 -0
  173. package/sha256+sha512+sha512_256+deserialize+serialize+streaming.d.cts +29 -0
  174. package/sha256+sha512+sha512_256+deserialize+serialize+streaming.d.mts +29 -0
  175. package/sha256+sha512+sha512_256+deserialize+serialize+streaming.mjs +80 -0
  176. package/sha256+sha512+sha512_256+streaming.cjs +56 -0
  177. package/sha256+sha512+sha512_256+streaming.d.cts +29 -0
  178. package/sha256+sha512+sha512_256+streaming.d.mts +29 -0
  179. package/sha256+sha512+sha512_256+streaming.mjs +56 -0
  180. package/sha256+sha512+streaming.cjs +44 -0
  181. package/sha256+sha512+streaming.d.cts +29 -0
  182. package/sha256+sha512+streaming.d.mts +29 -0
  183. package/sha256+sha512+streaming.mjs +45 -0
  184. package/sha256+sha512_256+deserialize+serialize+streaming.cjs +63 -0
  185. package/sha256+sha512_256+deserialize+serialize+streaming.d.cts +29 -0
  186. package/sha256+sha512_256+deserialize+serialize+streaming.d.mts +29 -0
  187. package/sha256+sha512_256+deserialize+serialize+streaming.mjs +64 -0
  188. package/sha256+sha512_256+streaming.cjs +43 -0
  189. package/sha256+sha512_256+streaming.d.cts +29 -0
  190. package/sha256+sha512_256+streaming.d.mts +29 -0
  191. package/sha256+sha512_256+streaming.mjs +43 -0
  192. package/sha256+streaming.cjs +21 -0
  193. package/sha256+streaming.d.cts +29 -0
  194. package/sha256+streaming.d.mts +29 -0
  195. package/sha256+streaming.mjs +21 -0
  196. package/sha384+deserialize+serialize+streaming.cjs +43 -0
  197. package/sha384+deserialize+serialize+streaming.d.cts +29 -0
  198. package/sha384+deserialize+serialize+streaming.d.mts +29 -0
  199. package/sha384+deserialize+serialize+streaming.mjs +44 -0
  200. package/sha384+sha512+deserialize+serialize+streaming.cjs +60 -0
  201. package/sha384+sha512+deserialize+serialize+streaming.d.cts +29 -0
  202. package/sha384+sha512+deserialize+serialize+streaming.d.mts +29 -0
  203. package/sha384+sha512+deserialize+serialize+streaming.mjs +61 -0
  204. package/sha384+sha512+sha512_256+deserialize+serialize+streaming.cjs +67 -0
  205. package/sha384+sha512+sha512_256+deserialize+serialize+streaming.d.cts +29 -0
  206. package/sha384+sha512+sha512_256+deserialize+serialize+streaming.d.mts +29 -0
  207. package/sha384+sha512+sha512_256+deserialize+serialize+streaming.mjs +67 -0
  208. package/sha384+sha512+sha512_256+streaming.cjs +53 -0
  209. package/sha384+sha512+sha512_256+streaming.d.cts +29 -0
  210. package/sha384+sha512+sha512_256+streaming.d.mts +29 -0
  211. package/sha384+sha512+sha512_256+streaming.mjs +53 -0
  212. package/sha384+sha512+streaming.cjs +46 -0
  213. package/sha384+sha512+streaming.d.cts +29 -0
  214. package/sha384+sha512+streaming.d.mts +29 -0
  215. package/sha384+sha512+streaming.mjs +47 -0
  216. package/sha384+sha512_256+deserialize+serialize+streaming.cjs +59 -0
  217. package/sha384+sha512_256+deserialize+serialize+streaming.d.cts +29 -0
  218. package/sha384+sha512_256+deserialize+serialize+streaming.d.mts +29 -0
  219. package/sha384+sha512_256+deserialize+serialize+streaming.mjs +59 -0
  220. package/sha384+sha512_256+streaming.cjs +45 -0
  221. package/sha384+sha512_256+streaming.d.cts +29 -0
  222. package/sha384+sha512_256+streaming.d.mts +29 -0
  223. package/sha384+sha512_256+streaming.mjs +45 -0
  224. package/sha384+streaming.cjs +33 -0
  225. package/sha384+streaming.d.cts +29 -0
  226. package/sha384+streaming.d.mts +29 -0
  227. package/sha384+streaming.mjs +34 -0
  228. package/sha512+deserialize+serialize+streaming.cjs +44 -0
  229. package/sha512+deserialize+serialize+streaming.d.cts +29 -0
  230. package/sha512+deserialize+serialize+streaming.d.mts +29 -0
  231. package/sha512+deserialize+serialize+streaming.mjs +45 -0
  232. package/sha512+sha512_256+deserialize+serialize+streaming.cjs +59 -0
  233. package/sha512+sha512_256+deserialize+serialize+streaming.d.cts +29 -0
  234. package/sha512+sha512_256+deserialize+serialize+streaming.d.mts +29 -0
  235. package/sha512+sha512_256+deserialize+serialize+streaming.mjs +60 -0
  236. package/sha512+sha512_256+streaming.cjs +45 -0
  237. package/sha512+sha512_256+streaming.d.cts +29 -0
  238. package/sha512+sha512_256+streaming.d.mts +29 -0
  239. package/sha512+sha512_256+streaming.mjs +46 -0
  240. package/sha512+streaming.cjs +34 -0
  241. package/sha512+streaming.d.cts +29 -0
  242. package/sha512+streaming.d.mts +29 -0
  243. package/sha512+streaming.mjs +34 -0
  244. package/sha512_256+deserialize+serialize+streaming.cjs +42 -0
  245. package/sha512_256+deserialize+serialize+streaming.d.cts +29 -0
  246. package/sha512_256+deserialize+serialize+streaming.d.mts +29 -0
  247. package/sha512_256+deserialize+serialize+streaming.mjs +43 -0
  248. package/sha512_256+streaming.cjs +32 -0
  249. package/sha512_256+streaming.d.cts +29 -0
  250. package/sha512_256+streaming.d.mts +29 -0
  251. package/sha512_256+streaming.mjs +33 -0
  252. package/types.d.cts +106 -0
  253. package/types.d.mts +106 -0
package/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright ยฉ 2026 Apeleg Limited. All right reserved.
2
+
3
+ Permission to use, copy, modify, and distribute this software for any purpose
4
+ with or without fee is hereby granted, provided that the above copyright notice
5
+ and this permission notice appear in all copies.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
9
+ FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
11
+ OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
12
+ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
13
+ THIS SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,197 @@
1
+ # WASM SHA-2 (Rust โ†’ WebAssembly)
2
+
3
+ ![NPM Downloads](https://img.shields.io/npm/dw/@apeleghq/sha2?style=flat-square)
4
+
5
+ A WebAssembly build of Rust SHA-2 implementations, exposed to
6
+ JavaScript/TypeScript. The package provides streaming and one-shot hashers for
7
+ SHA-224, SHA-256, SHA-384, SHA-512 and SHA-512/256 (variant availability depends
8
+ on build features). A TypeScript declaration (`.d.ts`) file is included for a
9
+ typed API.
10
+
11
+ ---
12
+
13
+ ## ๐Ÿš€ Features
14
+
15
+ - Streaming and one-shot hashing APIs.
16
+ - Zero runtime dependencies โ€” pure traspiled WASM + light JS glue.
17
+ - Small, efficient heap sharing between JS and transpiled WASM.
18
+ - Optional serialisation/deserialisation of internal state.
19
+ - TypeScript definitions included.
20
+
21
+ ## โš™๏ธ Installation
22
+
23
+ Install from npm or yarn:
24
+
25
+ ```sh
26
+ npm install @apeleghq/sha2
27
+ ```
28
+
29
+ or
30
+
31
+ ```sh
32
+ yarn add @apeleghq/sha2
33
+ ```
34
+
35
+ ## ๐Ÿ“ฆ Package contents
36
+
37
+ - Compiled WebAssembly module (.wasm)
38
+ - JS/ESM glue to load the module
39
+ - TypeScript declaration file (.d.ts) โ€” the API described below
40
+ - README, LICENSE, tests
41
+
42
+ ## ๐Ÿ”Œ API Overview
43
+
44
+ The module exports a single async default function that initialises the WASM module and returns factories for the enabled SHA-2 variants.
45
+
46
+ Signature (from the .d.ts):
47
+
48
+ - Default export: `async function (): Promise<Sha2Factories<...>>`
49
+
50
+ Returned object contains one property per enabled algorithm (examples: `sha256`, `sha512`, etc.). Each property is a constructor/factory function with these behaviours:
51
+
52
+ Hash instance methods:
53
+ - `update(data: ArrayBuffer | ArrayBufferView, scrub?: boolean): void`
54
+ - `finalize(scrub?: boolean): ArrayBuffer`
55
+ - `reset(): void`
56
+ - `digest(data: ArrayBuffer | ArrayBufferView, scrub?: boolean): ArrayBuffer` โ€”
57
+ one-shot convenience (throws if instance is streaming)
58
+
59
+ Optional (when serialize feature enabled):
60
+ - `serialize(scrub?: boolean): ArrayBuffer`
61
+
62
+ Constructors may also accept a serialized state to resume:
63
+ - `constructor(serializedData?: ArrayBuffer | ArrayBufferView | null, scrub?: boolean)`
64
+
65
+ See the bundled `.d.ts` for exact types.
66
+
67
+ ## ๐Ÿ“š Usage
68
+
69
+ Basic one-shot hashing (example):
70
+
71
+ ```javascript
72
+ import sha2 from '@apeleghq/sha2';
73
+
74
+ const factories = await sha2();
75
+ const hasher = factories.sha256();
76
+ const digest = hasher.digest(new Uint8Array([1,2,3]));
77
+ // `digest` is an ArrayBuffer containing the raw hash bytes
78
+ ```
79
+
80
+ Streaming example:
81
+
82
+ ```javascript
83
+ import sha2 from '@apeleghq/sha2';
84
+
85
+ const factories = await sha2();
86
+ const h = factories.sha512();
87
+ h.update(new Uint8Array(chunk1));
88
+ h.update(new Uint8Array(chunk2));
89
+ const result = h.finalize(); // ArrayBuffer
90
+ h.reset(); // reuse
91
+ ```
92
+
93
+ Serialisation / resuming:
94
+
95
+ ```javascript
96
+ import sha2 from '@apeleghq/sha2';
97
+
98
+ const factories = await sha2();
99
+ const h = factories.sha256();
100
+ h.update(part1);
101
+ const state = h.serialize(); // ArrayBuffer
102
+ // ...persist or transfer state...
103
+ const resumed = factories.sha256(state);
104
+ resumed.update(part2);
105
+ const digest = resumed.finalize();
106
+ ```
107
+
108
+ Notes:
109
+ - All methods accept `ArrayBuffer` or any `ArrayBufferView` (`Uint8Array`,
110
+ `DataView`, etc.).
111
+ - The optional `scrub` boolean (when present) indicates whether internal buffers
112
+ should be zeroed after use to reduce memory-resident sensitive data.
113
+
114
+ ### Exports
115
+
116
+ Apart from the main export at the root (`@apeleghq/sha2`), there are additional
117
+ exports based on specific build-time features. This enables selecting just those
118
+ features that are needed to reduce bundle size.
119
+
120
+ #### Example
121
+
122
+
123
+ ```javascript
124
+ // Just some
125
+ import sha2_ษ‘ from '@apeleghq/sha2/sha256+sha384+streaming';
126
+ import sha2_ฮฒ from '@apeleghq/sha2/sha384+deserialize+serialize+streaming';
127
+
128
+ const factories_ษ‘ = await sha2_ษ‘();
129
+ const h1 = factories_ษ‘.sha256(); // โœ… This works
130
+ const h2 = factories_ษ‘.sha384(); // โœ… This works
131
+
132
+ const h3 = factories_ษ‘.sha512(); // โŒ This doesn't work --- no `sha512` feature
133
+ // โŒ This doesn't work --- no `deserialize` feature
134
+ const h4 = factories_ษ‘.sha384(previouslyExportedState);
135
+ h2.serialize(); // โŒ This doesn't work --- no `serialize` feature
136
+
137
+ const factories_ฮฒ = await sha2_ฮฒ();
138
+ const h5 = factories_ฮฒ.sha256(); // โŒ This doesn't work --- no `sha256` feature
139
+ // โŒ This doesn't work --- no `sha256` feature
140
+ const h6 = factories_ฮฒ.sha256(previouslyExportedState);
141
+
142
+ const h7 = factories_ฮฒ.sha384(); // โœ… This works
143
+ const h8 = factories_ฮฒ.sha384(previouslyExportedState); // โœ… This works
144
+ h7.serialize(); // โœ… This works
145
+ ```
146
+
147
+ ## โœ… Recommended usage
148
+
149
+ - Call the default export once at startup and reuse the returned factories.
150
+ - For repeated hashing of many inputs, create and reuse instances or reset
151
+ instances to avoid repeated allocations.
152
+ - Use the TypeScript definitions included for full type safety.
153
+
154
+ ## ๐Ÿงช Example: Node + ESM
155
+
156
+ package.json:
157
+ ```json
158
+ {
159
+ "type": "module"
160
+ }
161
+ ```
162
+
163
+ app.js:
164
+ ```javascript
165
+ import sha2 from '@apeleghq/sha2';
166
+
167
+ const factories = await sha2();
168
+ const h = factories.sha256();
169
+ const digest = h.digest(new TextEncoder().encode('hello'));
170
+ console.log(Buffer.from(digest).toString('hex'));
171
+ ```
172
+
173
+ ## โš™๏ธ Build features
174
+
175
+ Build-time feature flags (available via `import.meta.features` in the bundling
176
+ environment) control which algorithms and optional capabilities are compiled in:
177
+
178
+ - `sha224`, `sha256`, `sha384`, `sha512`, `sha512_256`
179
+ - `serialize`, `deserialize` โ€” enables `serialize`/`deserialize` APIs
180
+ (for importing and exporting the hasher state)
181
+
182
+ The TypeScript declaration mirrors which factories are present according to the
183
+ build features.
184
+
185
+ ## ๐Ÿ“ฆ Distribution targets
186
+
187
+ - ESM (recommended)
188
+ - Node.js and browser-compatible WASM + light JS loader included
189
+
190
+ ## ๐Ÿค Contributing
191
+
192
+ Contributions welcome. Open issues or pull requests in the repository.
193
+
194
+ ## ๐Ÿ“œ License
195
+
196
+ This project is released under the ISC license. See the `LICENSE` file for
197
+ details.