UNPKG

782 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 { vrfVerify } from '@polkadot/wasm-crypto';
5const EMPTY_U8A = new Uint8Array();
6/**
7 * @name sr25519VrfVerify
8 * @description Verify with sr25519 vrf verification
9 */
10
11export function sr25519VrfVerify(message, signOutput, publicKey, context = EMPTY_U8A, extra = EMPTY_U8A) {
12 const publicKeyU8a = u8aToU8a(publicKey);
13 const proofU8a = u8aToU8a(signOutput);
14 assert(publicKeyU8a.length === 32, 'Invalid publicKey, expected 32-bytes');
15 assert(proofU8a.length === 96, 'Invalid vrfSign output, expected 96 bytes');
16 return vrfVerify(publicKeyU8a, u8aToU8a(context), u8aToU8a(message), u8aToU8a(extra), proofU8a);
17}
\No newline at end of file