-
Notifications
You must be signed in to change notification settings - Fork 0
/
js-and-wasm.test.mjs
36 lines (29 loc) · 1.03 KB
/
js-and-wasm.test.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import test from "node:test";
import * as libMlsagJs from "./lib-mlsag-js/ringct.mjs";
import assert from "node:assert";
import {
LSAG_Signature,
LSAG_Verify,
generatePrivateKey,
getPublicKeyFromPrivateKey,
} from "./lib-mlsag-wasm/index.mjs";
for (const keyLen of [3, 4, 5]) {
for (const index of new Array(keyLen).fill(0).map((_, i) => i)) {
test(`wasm sign, js check keyLen=${keyLen} index=${index}`, () => {
const keyLen = 4;
const index = 2;
const message = generatePrivateKey();
const privateKeys = new Array(keyLen)
.fill(0)
.map(() => generatePrivateKey());
const publicKeys = privateKeys.map((key) =>
getPublicKeyFromPrivateKey(key)
);
const sig = LSAG_Signature(message, privateKeys[index], publicKeys);
const result = libMlsagJs.LSAG_Verify(message, publicKeys, sig);
assert.strictEqual(result, true);
assert.ok(LSAG_Verify(message, publicKeys, sig));
assert.ok(!LSAG_Verify(new Uint8Array(32).fill(0), publicKeys, sig));
});
}
}