UNPKG

@stellot/crypto

Version:

Crypto libraries for front and backend

37 lines (36 loc) 1.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const index_1 = require("./index"); const utils_1 = require("./utils"); class VoterSession { constructor(P, R, a, b) { this.a = a || utils_1.randomScalar(); this.b = b || utils_1.randomScalar(); this.P = index_1.ed25519.decodePoint(P); this.R = index_1.ed25519.decodePoint(R) .add(index_1.ed25519.curve.g.mul(this.a).add(this.P.mul(this.b))); } challenge(message) { return index_1.ed25519 .hashInt(index_1.ed25519.encodePoint(this.R), index_1.ed25519.encodePoint(this.P), message) .add(this.b) .umod(index_1.ed25519.curve.n); } proof() { return { a: this.a, b: this.b }; } signature(s) { const S = s.add(this.a).umod(index_1.ed25519.curve.n); const signature = index_1.ed25519.encodePoint(this.R).concat(index_1.ed25519.encodeInt(S)); return signature; } toJSON() { return { a: this.a, b: this.b, P: index_1.ed25519.encodePoint(this.P), R: index_1.ed25519.encodePoint(this.R), }; } } exports.default = VoterSession;