-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSchnorr_test_API.ts
More file actions
96 lines (85 loc) · 1.93 KB
/
Copy pathSchnorr_test_API.ts
File metadata and controls
96 lines (85 loc) · 1.93 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import axios from "axios";
import bigInt from "big-integer";
import verify from "./Schnorr_web_fns";
interface Group {
generator: Generator;
p: string;
}
interface Generator {
tag: string;
data: {
value: string;
prime: string;
};
}
interface PublicKey {
tag: string;
data: {
value: string;
prime: string;
};
}
interface GetSignature {
r: {
tag: string;
data: {
value: string;
prime: string;
};
};
sigma: Sigma;
}
interface Sigma {
value: string;
prime: string;
}
interface GetSchnorrRes {
group: Group;
message: string;
publicKey: PublicKey;
signature: GetSignature;
hash: {
value: string;
prime: string;
};
}
interface SchnorrVerificationBody {
group: Group;
message: string;
publicKey: PublicKey;
signature: GetSignature;
}
function verifyWithAPI() {
axios
.get<GetSchnorrRes>("https://hash-effect.onrender.com/schnorr/sign")
.then((res) => {
return res.data;
})
.then((input) => {
const P = bigInt(input.group.generator.data.prime, 16);
const Q = bigInt(input.group.p, 16);
const g = bigInt(input.group.generator.data.value);
const y = bigInt(input.publicKey.data.value, 16);
const s = bigInt(input.signature.sigma.value, 16);
const r = bigInt(input.signature.r.data.value, 16);
const hash = bigInt(input.hash.value, 16);
console.log(P);
const message = input.message;
const a = verify(y, s, r, P, g, Q, message, hash);
console.log(a);
const postData: SchnorrVerificationBody = {
group: input.group,
message: input.message,
publicKey: input.publicKey,
signature: input.signature,
};
axios
.post<SchnorrVerificationBody>(
"https://hash-effect.onrender.com/schnorr/verify",
postData
)
.then((resp) => resp.data)
.then((output) => console.log(output));
});
}
verifyWithAPI();