-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathdemo.js
86 lines (73 loc) · 1.77 KB
/
demo.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
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
const BlindSignature = require('./rsablind');
// const BlindSignature = require('./rsablind2'); // Other implimentation
const Bob = {
key: BlindSignature.keyGeneration({ b: 512 }),
blinded: null,
unblinded: null,
message: null,
};
const Alice = {
message: 'Hello Chaum!',
N: null,
E: null,
r: null,
signed: null,
unblinded: null,
};
// Alice wants Bob to sign a message without revealing it's contents.
// Bob can later verify he did sign the message
console.log('Message:', Alice.message);
// Alice gets N and E variables from Bob's key
Alice.N = Bob.key.keyPair.n.toString();
Alice.E = Bob.key.keyPair.e.toString();
// N, E
const { blinded, r } = BlindSignature.blind({
message: Alice.message,
N: Alice.N,
E: Alice.E,
}); // Alice blinds message
Alice.r = r;
// Alice sends blinded to Bob
Bob.blinded = blinded;
// N, D (P, Q)
const signed = BlindSignature.sign({
blinded: Bob.blinded,
key: Bob.key,
}); // Bob signs blinded message
// Bob sends signed to Alice
Alice.signed = signed;
// N
const unblinded = BlindSignature.unblind({
signed: Alice.signed,
N: Alice.N,
r: Alice.r,
}); // Alice unblinds
Alice.unblinded = unblinded;
// Alice verifies
// N, E
const result = BlindSignature.verify({
unblinded: Alice.unblinded,
N: Alice.N,
E: Alice.E,
message: Alice.message,
});
if (result) {
console.log('Alice: Signatures verify!');
} else {
console.log('Alice: Invalid signature');
}
// Alice sends Bob unblinded signature and original message
Bob.unblinded = Alice.unblinded;
Bob.message = Alice.message;
// Bob verifies
// N, D
const result2 = BlindSignature.verify2({
unblinded: Bob.unblinded,
key: Bob.key,
message: Bob.message,
});
if (result2) {
console.log('Bob: Signatures verify!');
} else {
console.log('Bob: Invalid signature');
}