@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.
- package/LICENSE +13 -0
- package/README.md +197 -0
- package/package.json +651 -0
- package/sha224+deserialize+serialize+streaming.cjs +32 -0
- package/sha224+deserialize+serialize+streaming.d.cts +29 -0
- package/sha224+deserialize+serialize+streaming.d.mts +29 -0
- package/sha224+deserialize+serialize+streaming.mjs +33 -0
- package/sha224+sha256+deserialize+serialize+streaming.cjs +36 -0
- package/sha224+sha256+deserialize+serialize+streaming.d.cts +29 -0
- package/sha224+sha256+deserialize+serialize+streaming.d.mts +29 -0
- package/sha224+sha256+deserialize+serialize+streaming.mjs +37 -0
- package/sha224+sha256+sha384+deserialize+serialize+streaming.cjs +69 -0
- package/sha224+sha256+sha384+deserialize+serialize+streaming.d.cts +29 -0
- package/sha224+sha256+sha384+deserialize+serialize+streaming.d.mts +29 -0
- package/sha224+sha256+sha384+deserialize+serialize+streaming.mjs +69 -0
- package/sha224+sha256+sha384+sha512+deserialize+serialize+streaming.cjs +86 -0
- package/sha224+sha256+sha384+sha512+deserialize+serialize+streaming.d.cts +29 -0
- package/sha224+sha256+sha384+sha512+deserialize+serialize+streaming.d.mts +29 -0
- package/sha224+sha256+sha384+sha512+deserialize+serialize+streaming.mjs +86 -0
- package/sha224+sha256+sha384+sha512+sha512_256+deserialize+serialize+streaming.cjs +92 -0
- package/sha224+sha256+sha384+sha512+sha512_256+deserialize+serialize+streaming.d.cts +29 -0
- package/sha224+sha256+sha384+sha512+sha512_256+deserialize+serialize+streaming.d.mts +29 -0
- package/sha224+sha256+sha384+sha512+sha512_256+deserialize+serialize+streaming.mjs +92 -0
- package/sha224+sha256+sha384+sha512+sha512_256+streaming.cjs +68 -0
- package/sha224+sha256+sha384+sha512+sha512_256+streaming.d.cts +29 -0
- package/sha224+sha256+sha384+sha512+sha512_256+streaming.d.mts +29 -0
- package/sha224+sha256+sha384+sha512+sha512_256+streaming.mjs +68 -0
- package/sha224+sha256+sha384+sha512+streaming.cjs +62 -0
- package/sha224+sha256+sha384+sha512+streaming.d.cts +29 -0
- package/sha224+sha256+sha384+sha512+streaming.d.mts +29 -0
- package/sha224+sha256+sha384+sha512+streaming.mjs +62 -0
- package/sha224+sha256+sha384+sha512_256+deserialize+serialize+streaming.cjs +84 -0
- package/sha224+sha256+sha384+sha512_256+deserialize+serialize+streaming.d.cts +29 -0
- package/sha224+sha256+sha384+sha512_256+deserialize+serialize+streaming.d.mts +29 -0
- package/sha224+sha256+sha384+sha512_256+deserialize+serialize+streaming.mjs +85 -0
- package/sha224+sha256+sha384+sha512_256+streaming.cjs +60 -0
- package/sha224+sha256+sha384+sha512_256+streaming.d.cts +29 -0
- package/sha224+sha256+sha384+sha512_256+streaming.d.mts +29 -0
- package/sha224+sha256+sha384+sha512_256+streaming.mjs +61 -0
- package/sha224+sha256+sha384+streaming.cjs +47 -0
- package/sha224+sha256+sha384+streaming.d.cts +29 -0
- package/sha224+sha256+sha384+streaming.d.mts +29 -0
- package/sha224+sha256+sha384+streaming.mjs +48 -0
- package/sha224+sha256+sha512+deserialize+serialize+streaming.cjs +69 -0
- package/sha224+sha256+sha512+deserialize+serialize+streaming.d.cts +29 -0
- package/sha224+sha256+sha512+deserialize+serialize+streaming.d.mts +29 -0
- package/sha224+sha256+sha512+deserialize+serialize+streaming.mjs +70 -0
- package/sha224+sha256+sha512+sha512_256+deserialize+serialize+streaming.cjs +85 -0
- package/sha224+sha256+sha512+sha512_256+deserialize+serialize+streaming.d.cts +29 -0
- package/sha224+sha256+sha512+sha512_256+deserialize+serialize+streaming.d.mts +29 -0
- package/sha224+sha256+sha512+sha512_256+deserialize+serialize+streaming.mjs +85 -0
- package/sha224+sha256+sha512+sha512_256+streaming.cjs +61 -0
- package/sha224+sha256+sha512+sha512_256+streaming.d.cts +29 -0
- package/sha224+sha256+sha512+sha512_256+streaming.d.mts +29 -0
- package/sha224+sha256+sha512+sha512_256+streaming.mjs +61 -0
- package/sha224+sha256+sha512+streaming.cjs +48 -0
- package/sha224+sha256+sha512+streaming.d.cts +29 -0
- package/sha224+sha256+sha512+streaming.d.mts +29 -0
- package/sha224+sha256+sha512+streaming.mjs +49 -0
- package/sha224+sha256+sha512_256+deserialize+serialize+streaming.cjs +68 -0
- package/sha224+sha256+sha512_256+deserialize+serialize+streaming.d.cts +29 -0
- package/sha224+sha256+sha512_256+deserialize+serialize+streaming.d.mts +29 -0
- package/sha224+sha256+sha512_256+deserialize+serialize+streaming.mjs +68 -0
- package/sha224+sha256+sha512_256+streaming.cjs +47 -0
- package/sha224+sha256+sha512_256+streaming.d.cts +29 -0
- package/sha224+sha256+sha512_256+streaming.d.mts +29 -0
- package/sha224+sha256+sha512_256+streaming.mjs +47 -0
- package/sha224+sha256+streaming.cjs +25 -0
- package/sha224+sha256+streaming.d.cts +29 -0
- package/sha224+sha256+streaming.d.mts +29 -0
- package/sha224+sha256+streaming.mjs +26 -0
- package/sha224+sha384+deserialize+serialize+streaming.cjs +64 -0
- package/sha224+sha384+deserialize+serialize+streaming.d.cts +29 -0
- package/sha224+sha384+deserialize+serialize+streaming.d.mts +29 -0
- package/sha224+sha384+deserialize+serialize+streaming.mjs +64 -0
- package/sha224+sha384+sha512+deserialize+serialize+streaming.cjs +81 -0
- package/sha224+sha384+sha512+deserialize+serialize+streaming.d.cts +29 -0
- package/sha224+sha384+sha512+deserialize+serialize+streaming.d.mts +29 -0
- package/sha224+sha384+sha512+deserialize+serialize+streaming.mjs +81 -0
- package/sha224+sha384+sha512+sha512_256+deserialize+serialize+streaming.cjs +87 -0
- package/sha224+sha384+sha512+sha512_256+deserialize+serialize+streaming.d.cts +29 -0
- package/sha224+sha384+sha512+sha512_256+deserialize+serialize+streaming.d.mts +29 -0
- package/sha224+sha384+sha512+sha512_256+deserialize+serialize+streaming.mjs +87 -0
- package/sha224+sha384+sha512+sha512_256+streaming.cjs +63 -0
- package/sha224+sha384+sha512+sha512_256+streaming.d.cts +29 -0
- package/sha224+sha384+sha512+sha512_256+streaming.d.mts +29 -0
- package/sha224+sha384+sha512+sha512_256+streaming.mjs +64 -0
- package/sha224+sha384+sha512+streaming.cjs +57 -0
- package/sha224+sha384+sha512+streaming.d.cts +29 -0
- package/sha224+sha384+sha512+streaming.d.mts +29 -0
- package/sha224+sha384+sha512+streaming.mjs +57 -0
- package/sha224+sha384+sha512_256+deserialize+serialize+streaming.cjs +79 -0
- package/sha224+sha384+sha512_256+deserialize+serialize+streaming.d.cts +29 -0
- package/sha224+sha384+sha512_256+deserialize+serialize+streaming.d.mts +29 -0
- package/sha224+sha384+sha512_256+deserialize+serialize+streaming.mjs +80 -0
- package/sha224+sha384+sha512_256+streaming.cjs +55 -0
- package/sha224+sha384+sha512_256+streaming.d.cts +29 -0
- package/sha224+sha384+sha512_256+streaming.d.mts +29 -0
- package/sha224+sha384+sha512_256+streaming.mjs +56 -0
- package/sha224+sha384+streaming.cjs +44 -0
- package/sha224+sha384+streaming.d.cts +29 -0
- package/sha224+sha384+streaming.d.mts +29 -0
- package/sha224+sha384+streaming.mjs +44 -0
- package/sha224+sha512+deserialize+serialize+streaming.cjs +64 -0
- package/sha224+sha512+deserialize+serialize+streaming.d.cts +29 -0
- package/sha224+sha512+deserialize+serialize+streaming.d.mts +29 -0
- package/sha224+sha512+deserialize+serialize+streaming.mjs +65 -0
- package/sha224+sha512+sha512_256+deserialize+serialize+streaming.cjs +80 -0
- package/sha224+sha512+sha512_256+deserialize+serialize+streaming.d.cts +29 -0
- package/sha224+sha512+sha512_256+deserialize+serialize+streaming.d.mts +29 -0
- package/sha224+sha512+sha512_256+deserialize+serialize+streaming.mjs +80 -0
- package/sha224+sha512+sha512_256+streaming.cjs +56 -0
- package/sha224+sha512+sha512_256+streaming.d.cts +29 -0
- package/sha224+sha512+sha512_256+streaming.d.mts +29 -0
- package/sha224+sha512+sha512_256+streaming.mjs +56 -0
- package/sha224+sha512+streaming.cjs +44 -0
- package/sha224+sha512+streaming.d.cts +29 -0
- package/sha224+sha512+streaming.d.mts +29 -0
- package/sha224+sha512+streaming.mjs +45 -0
- package/sha224+sha512_256+deserialize+serialize+streaming.cjs +63 -0
- package/sha224+sha512_256+deserialize+serialize+streaming.d.cts +29 -0
- package/sha224+sha512_256+deserialize+serialize+streaming.d.mts +29 -0
- package/sha224+sha512_256+deserialize+serialize+streaming.mjs +63 -0
- package/sha224+sha512_256+streaming.cjs +43 -0
- package/sha224+sha512_256+streaming.d.cts +29 -0
- package/sha224+sha512_256+streaming.d.mts +29 -0
- package/sha224+sha512_256+streaming.mjs +43 -0
- package/sha224+streaming.cjs +21 -0
- package/sha224+streaming.d.cts +29 -0
- package/sha224+streaming.d.mts +29 -0
- package/sha224+streaming.mjs +21 -0
- package/sha256+deserialize+serialize+streaming.cjs +32 -0
- package/sha256+deserialize+serialize+streaming.d.cts +29 -0
- package/sha256+deserialize+serialize+streaming.d.mts +29 -0
- package/sha256+deserialize+serialize+streaming.mjs +33 -0
- package/sha256+sha384+deserialize+serialize+streaming.cjs +64 -0
- package/sha256+sha384+deserialize+serialize+streaming.d.cts +29 -0
- package/sha256+sha384+deserialize+serialize+streaming.d.mts +29 -0
- package/sha256+sha384+deserialize+serialize+streaming.mjs +65 -0
- package/sha256+sha384+sha512+deserialize+serialize+streaming.cjs +81 -0
- package/sha256+sha384+sha512+deserialize+serialize+streaming.d.cts +29 -0
- package/sha256+sha384+sha512+deserialize+serialize+streaming.d.mts +29 -0
- package/sha256+sha384+sha512+deserialize+serialize+streaming.mjs +81 -0
- package/sha256+sha384+sha512+sha512_256+deserialize+serialize+streaming.cjs +87 -0
- package/sha256+sha384+sha512+sha512_256+deserialize+serialize+streaming.d.cts +29 -0
- package/sha256+sha384+sha512+sha512_256+deserialize+serialize+streaming.d.mts +29 -0
- package/sha256+sha384+sha512+sha512_256+deserialize+serialize+streaming.mjs +88 -0
- package/sha256+sha384+sha512+sha512_256+streaming.cjs +63 -0
- package/sha256+sha384+sha512+sha512_256+streaming.d.cts +29 -0
- package/sha256+sha384+sha512+sha512_256+streaming.d.mts +29 -0
- package/sha256+sha384+sha512+sha512_256+streaming.mjs +64 -0
- package/sha256+sha384+sha512+streaming.cjs +57 -0
- package/sha256+sha384+sha512+streaming.d.cts +29 -0
- package/sha256+sha384+sha512+streaming.d.mts +29 -0
- package/sha256+sha384+sha512+streaming.mjs +57 -0
- package/sha256+sha384+sha512_256+deserialize+serialize+streaming.cjs +79 -0
- package/sha256+sha384+sha512_256+deserialize+serialize+streaming.d.cts +29 -0
- package/sha256+sha384+sha512_256+deserialize+serialize+streaming.d.mts +29 -0
- package/sha256+sha384+sha512_256+deserialize+serialize+streaming.mjs +80 -0
- package/sha256+sha384+sha512_256+streaming.cjs +55 -0
- package/sha256+sha384+sha512_256+streaming.d.cts +29 -0
- package/sha256+sha384+sha512_256+streaming.d.mts +29 -0
- package/sha256+sha384+sha512_256+streaming.mjs +56 -0
- package/sha256+sha384+streaming.cjs +44 -0
- package/sha256+sha384+streaming.d.cts +29 -0
- package/sha256+sha384+streaming.d.mts +29 -0
- package/sha256+sha384+streaming.mjs +44 -0
- package/sha256+sha512+deserialize+serialize+streaming.cjs +65 -0
- package/sha256+sha512+deserialize+serialize+streaming.d.cts +29 -0
- package/sha256+sha512+deserialize+serialize+streaming.d.mts +29 -0
- package/sha256+sha512+deserialize+serialize+streaming.mjs +65 -0
- package/sha256+sha512+sha512_256+deserialize+serialize+streaming.cjs +80 -0
- package/sha256+sha512+sha512_256+deserialize+serialize+streaming.d.cts +29 -0
- package/sha256+sha512+sha512_256+deserialize+serialize+streaming.d.mts +29 -0
- package/sha256+sha512+sha512_256+deserialize+serialize+streaming.mjs +80 -0
- package/sha256+sha512+sha512_256+streaming.cjs +56 -0
- package/sha256+sha512+sha512_256+streaming.d.cts +29 -0
- package/sha256+sha512+sha512_256+streaming.d.mts +29 -0
- package/sha256+sha512+sha512_256+streaming.mjs +56 -0
- package/sha256+sha512+streaming.cjs +44 -0
- package/sha256+sha512+streaming.d.cts +29 -0
- package/sha256+sha512+streaming.d.mts +29 -0
- package/sha256+sha512+streaming.mjs +45 -0
- package/sha256+sha512_256+deserialize+serialize+streaming.cjs +63 -0
- package/sha256+sha512_256+deserialize+serialize+streaming.d.cts +29 -0
- package/sha256+sha512_256+deserialize+serialize+streaming.d.mts +29 -0
- package/sha256+sha512_256+deserialize+serialize+streaming.mjs +64 -0
- package/sha256+sha512_256+streaming.cjs +43 -0
- package/sha256+sha512_256+streaming.d.cts +29 -0
- package/sha256+sha512_256+streaming.d.mts +29 -0
- package/sha256+sha512_256+streaming.mjs +43 -0
- package/sha256+streaming.cjs +21 -0
- package/sha256+streaming.d.cts +29 -0
- package/sha256+streaming.d.mts +29 -0
- package/sha256+streaming.mjs +21 -0
- package/sha384+deserialize+serialize+streaming.cjs +43 -0
- package/sha384+deserialize+serialize+streaming.d.cts +29 -0
- package/sha384+deserialize+serialize+streaming.d.mts +29 -0
- package/sha384+deserialize+serialize+streaming.mjs +44 -0
- package/sha384+sha512+deserialize+serialize+streaming.cjs +60 -0
- package/sha384+sha512+deserialize+serialize+streaming.d.cts +29 -0
- package/sha384+sha512+deserialize+serialize+streaming.d.mts +29 -0
- package/sha384+sha512+deserialize+serialize+streaming.mjs +61 -0
- package/sha384+sha512+sha512_256+deserialize+serialize+streaming.cjs +67 -0
- package/sha384+sha512+sha512_256+deserialize+serialize+streaming.d.cts +29 -0
- package/sha384+sha512+sha512_256+deserialize+serialize+streaming.d.mts +29 -0
- package/sha384+sha512+sha512_256+deserialize+serialize+streaming.mjs +67 -0
- package/sha384+sha512+sha512_256+streaming.cjs +53 -0
- package/sha384+sha512+sha512_256+streaming.d.cts +29 -0
- package/sha384+sha512+sha512_256+streaming.d.mts +29 -0
- package/sha384+sha512+sha512_256+streaming.mjs +53 -0
- package/sha384+sha512+streaming.cjs +46 -0
- package/sha384+sha512+streaming.d.cts +29 -0
- package/sha384+sha512+streaming.d.mts +29 -0
- package/sha384+sha512+streaming.mjs +47 -0
- package/sha384+sha512_256+deserialize+serialize+streaming.cjs +59 -0
- package/sha384+sha512_256+deserialize+serialize+streaming.d.cts +29 -0
- package/sha384+sha512_256+deserialize+serialize+streaming.d.mts +29 -0
- package/sha384+sha512_256+deserialize+serialize+streaming.mjs +59 -0
- package/sha384+sha512_256+streaming.cjs +45 -0
- package/sha384+sha512_256+streaming.d.cts +29 -0
- package/sha384+sha512_256+streaming.d.mts +29 -0
- package/sha384+sha512_256+streaming.mjs +45 -0
- package/sha384+streaming.cjs +33 -0
- package/sha384+streaming.d.cts +29 -0
- package/sha384+streaming.d.mts +29 -0
- package/sha384+streaming.mjs +34 -0
- package/sha512+deserialize+serialize+streaming.cjs +44 -0
- package/sha512+deserialize+serialize+streaming.d.cts +29 -0
- package/sha512+deserialize+serialize+streaming.d.mts +29 -0
- package/sha512+deserialize+serialize+streaming.mjs +45 -0
- package/sha512+sha512_256+deserialize+serialize+streaming.cjs +59 -0
- package/sha512+sha512_256+deserialize+serialize+streaming.d.cts +29 -0
- package/sha512+sha512_256+deserialize+serialize+streaming.d.mts +29 -0
- package/sha512+sha512_256+deserialize+serialize+streaming.mjs +60 -0
- package/sha512+sha512_256+streaming.cjs +45 -0
- package/sha512+sha512_256+streaming.d.cts +29 -0
- package/sha512+sha512_256+streaming.d.mts +29 -0
- package/sha512+sha512_256+streaming.mjs +46 -0
- package/sha512+streaming.cjs +34 -0
- package/sha512+streaming.d.cts +29 -0
- package/sha512+streaming.d.mts +29 -0
- package/sha512+streaming.mjs +34 -0
- package/sha512_256+deserialize+serialize+streaming.cjs +42 -0
- package/sha512_256+deserialize+serialize+streaming.d.cts +29 -0
- package/sha512_256+deserialize+serialize+streaming.d.mts +29 -0
- package/sha512_256+deserialize+serialize+streaming.mjs +43 -0
- package/sha512_256+streaming.cjs +32 -0
- package/sha512_256+streaming.d.cts +29 -0
- package/sha512_256+streaming.d.mts +29 -0
- package/sha512_256+streaming.mjs +33 -0
- package/types.d.cts +106 -0
- 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
|
+

|
|
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.
|