UNPKG

790 BJavaScriptView Raw
1// Copyright 2017-2022 @polkadot/util-crypto authors & contributors
2// SPDX-License-Identifier: Apache-2.0
3import { assert, u8aToU8a } from '@polkadot/util';
4import { sr25519Verify as wasmVerify } from '@polkadot/wasm-crypto';
5/**
6 * @name sr25519Verify
7 * @description Verifies the signature of `message`, using the supplied pair
8 */
9
10export function sr25519Verify(message, signature, publicKey) {
11 const publicKeyU8a = u8aToU8a(publicKey);
12 const signatureU8a = u8aToU8a(signature);
13 assert(publicKeyU8a.length === 32, () => `Invalid publicKey, received ${publicKeyU8a.length} bytes, expected 32`);
14 assert(signatureU8a.length === 64, () => `Invalid signature, received ${signatureU8a.length} bytes, expected 64`);
15 return wasmVerify(signatureU8a, u8aToU8a(message), publicKeyU8a);
16}
\No newline at end of file