QubicTypeScript

k12

Computes a KangarooTwelve (K12) hash of arbitrary input bytes, returning a Uint8Array of the requested output length.

Qubic uses KangarooTwelve (K12) as its hash function. K12 is derived from the Keccak sponge construction — the same family as SHA-3 — but uses a reduced round count (12 rounds instead of 24) and adds tree hashing for parallelism. Do not confuse K12 with Ethereum's keccak256: they share a common ancestor but produce completely different outputs.

Signature

K12(input: Uint8Array, outputLength?: number): Uint8Array

Purpose

Computes a K12 hash of arbitrary input bytes.

import { K12 } from "@qubic.org/crypto"

const input = new TextEncoder().encode("hello qubic")
const hash = K12(input)         // Uint8Array, 32 bytes (default)
const longHash = K12(input, 64) // Uint8Array, 64 bytes

Parameters

NameTypeDefaultDescription
inputUint8ArrayBytes to hash
outputLengthnumber32Number of output bytes to produce

Returns

Uint8Array of length outputLength.

K12 vs SHA-3

Both originate from the Keccak sponge construction but differ in their parameters:

K12SHA-3
Round functionKeccak-p[1600, 12]Keccak-p[1600, 24]
Tree hashingYesNo
Customization stringYesNo
Standardized byIETF (RFC 8702)NIST (FIPS 202)

Never substitute SHA-3 or keccak256 for K12 in Qubic computations — the outputs differ.

Most SDK consumers never call K12 directly. It runs internally inside publicKeyFromSeed, signTransaction, computeTransactionHash, and verifyTransactionSignature. Call it directly when building a custom transaction type outside the SDK, verifying a message hash against a known value, or computing a checksum over raw Qubic binary data.

On this page