UNPKG

820 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 { sr25519Verify as wasmVerify } from '@polkadot/wasm-crypto';
6
7/**
8 * @name sr25519Verify
9 * @description Verifies the signature of `message`, using the supplied pair
10 */
11export function sr25519Verify(message, signature, publicKey) {
12 const publicKeyU8a = u8aToU8a(publicKey);
13 const signatureU8a = u8aToU8a(signature);
14 if (publicKeyU8a.length !== 32) {
15 throw new Error(`Invalid publicKey, received ${publicKeyU8a.length} bytes, expected 32`);
16 } else if (signatureU8a.length !== 64) {
17 throw new Error(`Invalid signature, received ${signatureU8a.length} bytes, expected 64`);
18 }
19 return wasmVerify(signatureU8a, u8aToU8a(message), publicKeyU8a);
20}
\No newline at end of file