UNPKG

740 BJavaScriptView Raw
1import { u8aToU8a } from '@polkadot/util';
2import { vrfVerify } from '@polkadot/wasm-crypto';
3const EMPTY_U8A = new Uint8Array();
4/**
5 * @name sr25519VrfVerify
6 * @description Verify with sr25519 vrf verification
7 */
8export function sr25519VrfVerify(message, signOutput, publicKey, context = EMPTY_U8A, extra = EMPTY_U8A) {
9 const publicKeyU8a = u8aToU8a(publicKey);
10 const proofU8a = u8aToU8a(signOutput);
11 if (publicKeyU8a.length !== 32) {
12 throw new Error('Invalid publicKey, expected 32-bytes');
13 }
14 else if (proofU8a.length !== 96) {
15 throw new Error('Invalid vrfSign output, expected 96 bytes');
16 }
17 return vrfVerify(publicKeyU8a, u8aToU8a(context), u8aToU8a(message), u8aToU8a(extra), proofU8a);
18}