UNPKG

556 BJavaScriptView Raw
1import { isU8a, u8aToU8a } from '@polkadot/util';
2import { sr25519DerivePublicSoft } from '@polkadot/wasm-crypto';
3export function sr25519DerivePublic(publicKey, chainCode) {
4 const publicKeyU8a = u8aToU8a(publicKey);
5 if (!isU8a(chainCode) || chainCode.length !== 32) {
6 throw new Error('Invalid chainCode passed to derive');
7 }
8 else if (publicKeyU8a.length !== 32) {
9 throw new Error(`Invalid publicKey, received ${publicKeyU8a.length} bytes, expected 32`);
10 }
11 return sr25519DerivePublicSoft(publicKeyU8a, chainCode);
12}