1 | import { u8aToU8a } from '@polkadot/util';
|
2 | import { vrfVerify } from '@polkadot/wasm-crypto';
|
3 | const EMPTY_U8A = new Uint8Array();
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | export 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 | }
|