merkle-reference
Version:
This is a TS library implementing [merkle reference] specification.
27 lines (21 loc) • 572 B
JavaScript
import * as Tag from './tag.js'
const memory = new Float64Array(1)
export const tag = Tag.for('merkle-structure:float/double-precision')
/**
* @param {number} value
*/
export const toBytes = (value) => doublePrecisionFloat(value)
/**
* Encodes given float as a double precision float.
*
* @param {number} value
*/
export const doublePrecisionFloat = (value) => {
memory[0] = value
return new Uint8Array(memory.buffer.slice(0))
}
/**
* @param {number} value
* @return {import('./tree.js').Branch}
*/
export const toTree = (value) => [tag, toBytes(value)]