UNPKG

736 BJavaScriptView Raw
1import { u8aToU8a } from '@polkadot/util';
2import { sr25519Verify as wasmVerify } from '@polkadot/wasm-crypto';
3/**
4 * @name sr25519Verify
5 * @description Verifies the signature of `message`, using the supplied pair
6 */
7export function sr25519Verify(message, signature, publicKey) {
8 const publicKeyU8a = u8aToU8a(publicKey);
9 const signatureU8a = u8aToU8a(signature);
10 if (publicKeyU8a.length !== 32) {
11 throw new Error(`Invalid publicKey, received ${publicKeyU8a.length} bytes, expected 32`);
12 }
13 else if (signatureU8a.length !== 64) {
14 throw new Error(`Invalid signature, received ${signatureU8a.length} bytes, expected 64`);
15 }
16 return wasmVerify(signatureU8a, u8aToU8a(message), publicKeyU8a);
17}