-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.js
More file actions
56 lines (36 loc) · 1.85 KB
/
Copy pathtest.js
File metadata and controls
56 lines (36 loc) · 1.85 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
const { initSync, SigningKey, Token, BatchDLEQProof, UnblindedToken } = require('./pkg');
const fs = require('fs')
const wasmBin = fs.readFileSync('./pkg/challenge_bypass_ristretto_bg.wasm')
initSync(wasmBin)
const msg = Buffer.from('test message')
const sKey = SigningKey.random()
const pKey = sKey.public_key()
const token1 = Token.random()
const token2 = Token.random()
if (token1.encode_base64() === token2.encode_base64()) {
console.error('Expected token1 and token2 to be distinct')
process.exit(1)
}
const tokens = token1.encode_base64() + ',' + token2.encode_base64()
const blindedToken1 = token1.blind()
const blindedToken2 = token2.blind()
const blindedTokens = blindedToken1.encode_base64() + ',' + blindedToken2.encode_base64()
const signedToken1 = sKey.sign(blindedToken1)
const signedToken2 = sKey.sign(blindedToken2)
const signedTokens = signedToken1.encode_base64() + ',' + signedToken2.encode_base64()
const proof = BatchDLEQProof.create_from_encoded(blindedTokens, signedTokens, sKey)
const unblindedTokens = proof.verify_and_unblind_from_encoded(tokens, blindedTokens, signedTokens, pKey)
const unblindedToken1 = UnblindedToken.decode_base64(unblindedTokens.split(',')[0])
const clientVerificationKey1 = unblindedToken1.derive_verification_key_sha512()
const verificationSignature1 = clientVerificationKey1.sign_sha512(msg)
const serverUnblindedToken1 = sKey.rederive_unblinded_token(unblindedToken1.preimage())
const serverVerificationKey1 = serverUnblindedToken1.derive_verification_key_sha512()
if (!serverVerificationKey1.verify_sha512(verificationSignature1, msg)) {
console.error('Expected verification signatures to match')
process.exit(1)
}
if (serverVerificationKey1.verify_sha512(verificationSignature1, Buffer.from('asdf'))) {
console.error('Expected verification signatures to NOT match')
process.exit(1)
}
console.log('Success!')