UNPKG

527 BJavaScriptView Raw
1// Copyright 2017-2022 @polkadot/util-crypto authors & contributors
2// SPDX-License-Identifier: Apache-2.0
3import { assert, u8aToU8a } from '@polkadot/util';
4const SEC_LEN = 64;
5const PUB_LEN = 32;
6const TOT_LEN = SEC_LEN + PUB_LEN;
7export function sr25519PairFromU8a(full) {
8 const fullU8a = u8aToU8a(full);
9 assert(fullU8a.length === TOT_LEN, () => `Expected keypair with ${TOT_LEN} bytes, found ${fullU8a.length}`);
10 return {
11 publicKey: fullU8a.slice(SEC_LEN, TOT_LEN),
12 secretKey: fullU8a.slice(0, SEC_LEN)
13 };
14}
\No newline at end of file