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