Compute the BLAKE2b-128 hash of the input data and convert it to a numeric Decimal value.

This task follows cryptographic standard hash truncation practices used in:

  • SHA-224: SHA-256 truncated to leftmost 224 bits
  • BLAKE2s-128: BLAKE2s-256 truncated to leftmost 128 bits
  • BLAKE2b-256: BLAKE2b-512 truncated to leftmost 256 bits

Input: String data to hash (can be from a previous task's output)

Returns: A positive Decimal number with 18 decimal places (scale 18)

  • Range: 0.000000000000000000 to 79228162514264.337593543950335 (2^96 - 1, scaled)
  • Example: 17512223723.299011049621773283

1. Compute BLAKE2b-128 hash* (produces 16 bytes / 128 bits)

Input:  "Hello, World!"
Output: 3895c59e4aeb0903396b5be3fbec69fe

2. Truncate to 96 bits (12 bytes)* - keep the most significant bits

KEPT (first 12 bytes):      3895c59e4aeb0903396b5be3
DISCARDED (last 4 bytes): fbec69fe

This follows cryptographic standards where truncation keeps the leftmost/most significant bits.

3. Pad to 16 bytes* for u128 representation

Add 4 zero bytes at the BEGINNING:

000000003895c59e4aeb0903396b5be3
└──┬──┘└──────────┬───────────┘
padding first 12 bytes
(4 bytes) (most significant)

4. Interpret as u128 using big-endian* byte order

Hex:     0x000000003895c59e4aeb0903396b5be3
Decimal: 17512223723299011049621773283

Big-endian is the standard for cryptographic hash representations.

5. Convert to Decimal* with scale 18 (18 decimal places)

Value:  17512223723299011049621773283
Scaled: 17512223723.299011049621773283 (divided by 10^18)

Scale 18 prevents precision loss when the protocol rescales values. Guaranteed to fit in Decimal's 96-bit mantissa (max: 2^96 - 1).


To reproduce this conversion in any programming language:

import hashlib
from decimal import Decimal

# 1. Compute BLAKE2b-128 hash
data = b"Hello, World!"
hash_bytes = hashlib.blake2b(data, digest_size=16).digest()
# Result: b'\x38\x95\xc5\x9e\x4a\xeb\x09\x03\x39\x6b\x5b\xe3\xfb\xec\x69\xfe'

# 2. Keep first 12 bytes (most significant 96 bits)
truncated = hash_bytes[:12]

# 3. Pad with 4 zero bytes at the beginning
padded = b'\x00\x00\x00\x00' + truncated

# 4. Interpret as u128 big-endian
value = int.from_bytes(padded, byteorder='big')
# Result: 17512223723299011049621773283

# 5. Apply scale 18 (divide by 10^18)
result = Decimal(value) / Decimal(10**18)
# Result: Decimal('17512223723.299011049621773283')
const crypto = require('crypto');

1. Compute BLAKE2b-128 hash
const hash = crypto.createHash('blake2b512')
.update('Hello, World!')
.digest()
.slice(0, 16); // Take first 16 bytes for BLAKE2b-128

2. Keep first 12 bytes
const truncated = hash.slice(0, 12);

3. Pad with 4 zero bytes at the beginning
const padded = Buffer.concat([Buffer.alloc(4), truncated]);

4. Interpret as big-endian u128
let value = 0n;
for (let i = 0; i < 16; i++) {
value = (value << 8n) | BigInt(padded[i]);
}
Result: 17512223723299011049621773283n

5. Apply scale 18 (divide by 10^18)
const result = Number(value) / 1e18;
Result: 17512223723.299011 (note: JS loses precision beyond ~15 digits)
use blake2::{Blake2b, Digest};
use blake2::digest::consts::U16;
use rust_decimal::Decimal;

type Blake2b128 = Blake2b;

1. Compute BLAKE2b-128 hash
let mut hasher = Blake2b128::new();
hasher.update(b"Hello, World!");
let hash = hasher.finalize();

2. Keep first 12 bytes and pad at beginning
let mut bytes = [0u8; 16];
bytes[4..16].copy_from_slice(&hash[0..12]);

3. Interpret as big-endian u128
let value = u128::from_be_bytes(bytes);
Result: 17512223723299011049621773283

4. Apply scale 18 (convert with 18 decimal places)
let result = Decimal::from_i128_with_scale(value as i128, 18);
Result: Decimal("17512223723.299011049621773283")

Cryptographic Standard: Follows the same truncation method as SHA-224, BLAKE2s-128, etc. ✅ Preserves Entropy: Keeps the most significant/diverse bits of the hash ✅ Big-Endian: Standard convention for cryptographic hash representations ✅ Fits Decimal Range: 96 bits always fits within Decimal's mantissa (max 2^96-1) ✅ Scale 18: Prevents precision loss when protocol rescales values ✅ Reproducible: Simple algorithm implementable in any programming language ✅ Deterministic: Same input always produces same output


Example: Hash a static string

{
"blake2b128Task": {
"value": "Hello, World!"
}
}

Example: Hash the output from a previous task (e.g., HTTP response)

{
"tasks": [
{
"httpTask": {
"url": "https://example.com/data"
}
},
{
"blake2b128Task": {}
}
]
}

Implements

Constructors

Properties

value: string

Optional value to hash. If not provided or empty, will use the previous task output.

Methods

  • Converts this Blake2b128Task to JSON.

    Returns { [k: string]: any }

    JSON object

  • Decodes a Blake2b128Task message from the specified reader or buffer.

    Parameters

    • reader: Uint8Array<ArrayBufferLike> | Reader

      Reader or buffer to decode from

    • Optionallength: number

      Message length if known beforehand

    Returns Blake2b128Task

    Blake2b128Task

    If the payload is not a reader or valid buffer

    If required fields are missing

  • Decodes a Blake2b128Task message from the specified reader or buffer, length delimited.

    Parameters

    • reader: Uint8Array<ArrayBufferLike> | Reader

      Reader or buffer to decode from

    Returns Blake2b128Task

    Blake2b128Task

    If the payload is not a reader or valid buffer

    If required fields are missing

  • Encodes the specified Blake2b128Task message. Does not implicitly {@apilink oracle_job.OracleJob.Blake2b128Task.verify|verify} messages.

    Parameters

    • message: IBlake2b128Task

      Blake2b128Task message or plain object to encode

    • Optionalwriter: Writer

      Writer to encode to

    Returns Writer

    Writer

  • Encodes the specified Blake2b128Task message, length delimited. Does not implicitly {@apilink oracle_job.OracleJob.Blake2b128Task.verify|verify} messages.

    Parameters

    • message: IBlake2b128Task

      Blake2b128Task message or plain object to encode

    • Optionalwriter: Writer

      Writer to encode to

    Returns Writer

    Writer

  • Creates a Blake2b128Task message from a plain object. Also converts values to their respective internal types.

    Parameters

    • object: { [k: string]: any }

      Plain object

    Returns Blake2b128Task

    Blake2b128Task

  • Gets the default type url for Blake2b128Task

    Parameters

    Returns string

    The default type url

  • Creates a plain object from a Blake2b128Task message. Also converts values to other types if specified.

    Parameters

    • message: Blake2b128Task

      Blake2b128Task

    • Optionaloptions: IConversionOptions

      Conversion options

    Returns { [k: string]: any }

    Plain object

  • Verifies a Blake2b128Task message.

    Parameters

    • message: { [k: string]: any }

      Plain object to verify

    Returns null | string

    null if valid, otherwise the reason why it is not