mirror of
https://github.com/pezkuwichain/pezkuwi-common.git
synced 2026-05-30 02:21:05 +00:00
Initial rebrand: @polkadot -> @pezkuwi (14 packages)
- Package namespace: @polkadot/* -> @pezkuwi/* - Repository: polkadot-js/common -> pezkuwichain/pezkuwi-common - Author: Pezkuwi Team <team@pezkuwichain.io> Core packages: - @pezkuwi/util (utilities) - @pezkuwi/util-crypto (crypto primitives) - @pezkuwi/keyring (account management) - @pezkuwi/networks (chain metadata) - @pezkuwi/hw-ledger (Ledger hardware wallet) - @pezkuwi/x-* (10 polyfill packages) Total: 14 packages Upstream: polkadot-js/common v14.0.1
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
// Copyright 2017-2025 @polkadot/util-crypto authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { blake2b as blake2bJs } from '@noble/hashes/blake2b';
|
||||
|
||||
import { hasBigInt, u8aToU8a } from '@pezkuwi/util';
|
||||
import { blake2b, isReady } from '@pezkuwi/wasm-crypto';
|
||||
|
||||
import { createAsHex } from '../helpers.js';
|
||||
|
||||
/**
|
||||
* @name blake2AsU8a
|
||||
* @summary Creates a blake2b u8a from the input.
|
||||
* @description
|
||||
* From a `Uint8Array` input, create the blake2b and return the result as a u8a with the specified `bitLength`.
|
||||
* @example
|
||||
* <BR>
|
||||
*
|
||||
* ```javascript
|
||||
* import { blake2AsU8a } from '@pezkuwi/util-crypto';
|
||||
*
|
||||
* blake2AsU8a('abc'); // => [0xba, 0x80, 0xa5, 0x3f, 0x98, 0x1c, 0x4d, 0x0d]
|
||||
* ```
|
||||
*/
|
||||
export function blake2AsU8a (data: string | Uint8Array, bitLength: 64 | 128 | 256 | 384 | 512 = 256, key?: Uint8Array | null, onlyJs?: boolean): Uint8Array {
|
||||
const byteLength = Math.ceil(bitLength / 8);
|
||||
const u8a = u8aToU8a(data);
|
||||
|
||||
return !hasBigInt || (!onlyJs && isReady())
|
||||
? blake2b(u8a, u8aToU8a(key), byteLength)
|
||||
: key
|
||||
? blake2bJs(u8a, { dkLen: byteLength, key })
|
||||
: blake2bJs(u8a, { dkLen: byteLength });
|
||||
}
|
||||
|
||||
/**
|
||||
* @name blake2AsHex
|
||||
* @description Creates a blake2b hex from the input.
|
||||
*/
|
||||
export const blake2AsHex = /*#__PURE__*/ createAsHex(blake2AsU8a);
|
||||
Reference in New Issue
Block a user