UNPKG

532 BJavaScriptView Raw
1import { compactAddLength, isU8a, stringToU8a, u8aConcat } from '@polkadot/util';
2import { blake2AsU8a } from '../blake2/asU8a.js';
3const HDKD = compactAddLength(stringToU8a('Secp256k1HDKD'));
4export function secp256k1DeriveHard(seed, chainCode) {
5 if (!isU8a(chainCode) || chainCode.length !== 32) {
6 throw new Error('Invalid chainCode passed to derive');
7 }
8 // NOTE This is specific to the Substrate HDD derivation, so always use the blake2 hasher
9 return blake2AsU8a(u8aConcat(HDKD, seed, chainCode), 256);
10}