UNPKG

565 BJavaScriptView Raw
1import { u8aToU8a } from '@polkadot/util';
2import { sr25519Sign as wasmSign } from '@polkadot/wasm-crypto';
3/**
4 * @name sr25519Sign
5 * @description Returns message signature of `message`, using the supplied pair
6 */
7export function sr25519Sign(message, { publicKey, secretKey }) {
8 if (publicKey?.length !== 32) {
9 throw new Error('Expected a valid publicKey, 32-bytes');
10 }
11 else if (secretKey?.length !== 64) {
12 throw new Error('Expected a valid secretKey, 64-bytes');
13 }
14 return wasmSign(publicKey, secretKey, u8aToU8a(message));
15}