-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspartan-dark.js
46 lines (40 loc) · 1.05 KB
/
spartan-dark.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
44
45
46
// COMPLETED
"use strict";
const { utils } = require("spartan-gold");
/* Basecoin for zk-spartan-cash.
Holds following info:
cm = coin commitment (hash)
v = value of coin
sn = coin serial no.
r = trapdoor generated for the coin. Also, the witness that the spender has to prove that
they know the value of without revealing r
*/
class SpartanDark {
constructor(addrPK, v, hashedV, rho, r, s, cm, k) {
this.cm = Buffer.from(cm);
this.v = v;
// also storing hash of value coz circuit standards
this.hashedV = Buffer.from(hashedV);
this.rho = Buffer.from(rho);
this.r = Buffer.from(r);
(this.s = Buffer.from(s)), (this.addrPK = addrPK);
this.k = k;
}
toBuffer() {
let byteV = [];
byteV[1] = this.v & 255;
byteV[0] = (this.v >> 8) & 255;
let mintedCoinData = [
this.addrPK,
this.cm,
this.hashedV,
this.k,
this.r,
this.rho,
this.s,
Buffer.from(byteV)
];
return Buffer.concat(mintedCoinData);
}
}
module.exports.SpartanDark = SpartanDark;