1 | // Copyright 2017-2022 @polkadot/util-crypto authors & contributors
|
2 | // SPDX-License-Identifier: Apache-2.0
|
3 | import { assert, u8aToU8a } from '@polkadot/util';
|
4 | const SEC_LEN = 64;
|
5 | const PUB_LEN = 32;
|
6 | const TOT_LEN = SEC_LEN + PUB_LEN;
|
7 | export 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 |