-
Notifications
You must be signed in to change notification settings - Fork 0
/
schnorr.js
43 lines (35 loc) · 1.32 KB
/
schnorr.js
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
37
38
39
40
41
42
43
const zenwrap = require('zenwrap')
const scripts = require('./crypto/lua-scripts.js')
async function run(script, data, keys, seed) {
// console.log(`SCRIPT «${script}»`)
return await zenwrap(script, keys, data, {verbose: 0, rngseed: seed})
}
async function random (seed) {
let trace = await run(scripts.random, null, null, seed)
return trace[0].json.random
}
async function keypair (seed) {
let trace = await run(scripts.keypair, null, null, seed)
return trace[0].json
}
async function sign ({private, public}, message, seed) {
let data = {private, public, message}
let trace = await run(scripts.signature, data, null, seed)
return trace[0].json
}
async function verify ({s, R}, public, message) {
let data = {s, R, public, message}
let trace = await run(scripts.verify, data, null)
return trace[0].json.valid
}
async function signAdaptor ({private, public}, t, T, message, seed) {
let data = {private, public, t, T, message}
let trace = await run(scripts.signatureAdaptor, data, null, seed)
return trace[0].json
}
async function verifyAdaptor ({ss, R, T}, public, message) {
let data = {ss, R, T, public, message}
let trace = await run(scripts.verifyAdaptor, data, null)
return trace[0].json
}
module.exports = { random, keypair, sign, verify, signAdaptor, verifyAdaptor }