UNPKG

717 BJavaScriptView Raw
1// Copyright 2017-2023 @polkadot/util-crypto authors & contributors
2// SPDX-License-Identifier: Apache-2.0
3
4import { u8aToU8a } from '@polkadot/util';
5import { sr25519Sign as wasmSign } from '@polkadot/wasm-crypto';
6
7/**
8 * @name sr25519Sign
9 * @description Returns message signature of `message`, using the supplied pair
10 */
11export function sr25519Sign(message, {
12 publicKey,
13 secretKey
14}) {
15 if ((publicKey == null ? void 0 : publicKey.length) !== 32) {
16 throw new Error('Expected a valid publicKey, 32-bytes');
17 } else if ((secretKey == null ? void 0 : secretKey.length) !== 64) {
18 throw new Error('Expected a valid secretKey, 64-bytes');
19 }
20 return wasmSign(publicKey, secretKey, u8aToU8a(message));
21}
\No newline at end of file