UNPKG

543 BJavaScriptView Raw
1import { u8aConcatStrict } from '../u8a/index.js';
2import { compactToU8a } from './toU8a.js';
3/**
4 * @name compactAddLength
5 * @description Adds a length prefix to the input value
6 * @example
7 * <BR>
8 *
9 * ```javascript
10 * import { compactAddLength } from '@polkadot/util';
11 *
12 * console.log(compactAddLength(new Uint8Array([0xde, 0xad, 0xbe, 0xef]))); // Uint8Array([4 << 2, 0xde, 0xad, 0xbe, 0xef])
13 * ```
14 */
15export function compactAddLength(input) {
16 return u8aConcatStrict([
17 compactToU8a(input.length),
18 input
19 ]);
20}