mirror of
https://github.com/UneBaguette/blake3.wasm.git
synced 2026-08-21 00:00:15 +02:00
chore: fix indentation and update README.md
- Make readme clearer
This commit is contained in:
@@ -35,7 +35,7 @@ blake3.deriveKey('my context', key);
|
|||||||
|
|
||||||
// Conctruct for Streaming
|
// Conctruct for Streaming
|
||||||
{
|
{
|
||||||
using h = new blake3.Hasher();
|
const h = new blake3.Hasher();
|
||||||
h.update(data.slice(0, 5));
|
h.update(data.slice(0, 5));
|
||||||
h.update(data.slice(5));
|
h.update(data.slice(5));
|
||||||
h.finalize();
|
h.finalize();
|
||||||
@@ -45,23 +45,19 @@ blake3.deriveKey('my context', key);
|
|||||||
|
|
||||||
// Streaming
|
// Streaming
|
||||||
// Keyed (MAC mode)
|
// Keyed (MAC mode)
|
||||||
{
|
const mac = blake3.Hasher.newKeyed(key);
|
||||||
using mac = blake3.Hasher.newKeyed(key);
|
mac.update(data);
|
||||||
mac.update(data);
|
mac.finalize();
|
||||||
mac.finalize();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Streaming
|
// Streaming
|
||||||
// Key derivation mode
|
// Key derivation mode
|
||||||
{
|
const kdf = blake3.Hasher.newDeriveKey('my app v1 :: subkey');
|
||||||
using kdf = blake3.Hasher.newDeriveKey('my app v1 :: subkey');
|
kdf.update(key);
|
||||||
kdf.update(key);
|
kdf.finalize();
|
||||||
kdf.finalize();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Batch hashing without re-allocating
|
// Batch hashing without re-allocating
|
||||||
{
|
{
|
||||||
using h = new blake3.Hasher();
|
const h = new blake3.Hasher();
|
||||||
h.update(chunk1);
|
h.update(chunk1);
|
||||||
const first = h.finalizeAndReset();
|
const first = h.finalizeAndReset();
|
||||||
h.update(chunk2);
|
h.update(chunk2);
|
||||||
@@ -73,48 +69,6 @@ blake3.deriveKey('my context', key);
|
|||||||
|
|
||||||
```ts
|
```ts
|
||||||
import { hash, hashXof, keyedHash, deriveKey, Hasher } from 'blake3-wasm-rs';
|
import { hash, hashXof, keyedHash, deriveKey, Hasher } from 'blake3-wasm-rs';
|
||||||
|
|
||||||
const data = new TextEncoder().encode('hello world');
|
|
||||||
const key = new Uint8Array(32).fill(1);
|
|
||||||
|
|
||||||
// One-shot hashing
|
|
||||||
hash(data);
|
|
||||||
hashXof(data, 64); // variable output length
|
|
||||||
keyedHash(data, key); // key must be exactly 32 bytes
|
|
||||||
deriveKey('my context', key);
|
|
||||||
|
|
||||||
// Streaming
|
|
||||||
{
|
|
||||||
using h = new Hasher();
|
|
||||||
h.update(data.slice(0, 5));
|
|
||||||
h.update(data.slice(5));
|
|
||||||
h.finalize();
|
|
||||||
h.finalizeXof(64);
|
|
||||||
h.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Keyed (MAC mode)
|
|
||||||
{
|
|
||||||
using mac = Hasher.newKeyed(key);
|
|
||||||
mac.update(data);
|
|
||||||
mac.finalize();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Key derivation mode
|
|
||||||
{
|
|
||||||
using kdf = Hasher.newDeriveKey('my app v1 :: subkey');
|
|
||||||
kdf.update(key);
|
|
||||||
kdf.finalize();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Batch hashing without re-allocating
|
|
||||||
{
|
|
||||||
using h = new Hasher();
|
|
||||||
h.update(chunk1);
|
|
||||||
const first = h.finalizeAndReset();
|
|
||||||
h.update(chunk2);
|
|
||||||
const second = h.finalizeAndReset();
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## API
|
## API
|
||||||
|
|||||||
Vendored
-1
@@ -1,5 +1,4 @@
|
|||||||
// SPDX-License-Identifier: MIT OR Apache-2.0
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||||||
// Copyright 2026 Thomas <[email protected]>
|
// Copyright 2026 Thomas <[email protected]>
|
||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
|
|
||||||
export { Hasher, deriveKey, hash, hashXof, keyedHash } from './bundler/blake3_wasm_rs';
|
export { Hasher, deriveKey, hash, hashXof, keyedHash } from './bundler/blake3_wasm_rs';
|
||||||
Reference in New Issue
Block a user