-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtest.mjs
78 lines (62 loc) · 2.37 KB
/
test.mjs
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
import {
HandleLogin,
HandleRegistration,
Login,
Registration,
ServerSetup,
set_panic_hook,
} from 'opaque-wasm'
const password = 'test123'
const email = '[email protected]'
async function run() {
console.log('--- STARTING ---')
set_panic_hook()
// Server configuration; this must be saved.
let server_setup = new ServerSetup()
// Save and reload the ServerSetup for demonstration
const server_setup_export = server_setup.serialize()
server_setup = ServerSetup.deserialize(server_setup_export)
// User registration
const client_registration = new Registration()
const registration_request = client_registration.start(password)
console.log('--- registration request ---', registration_request)
const serverRegistration = new HandleRegistration(server_setup)
const registration_response = serverRegistration.start(
email,
registration_request
)
console.log('-- registration response --', registration_response)
const registration_record = client_registration.finish(
password,
registration_response
)
console.log('-- registration upload --', registration_record)
const password_file = serverRegistration.finish(registration_record)
console.log('-- password_file --', password_file)
const registration_export_key = client_registration.getExportKey()
// User Login
const client_login = new Login()
const login_request = client_login.start(password)
console.log('login_request', login_request)
const server_login1 = new HandleLogin(server_setup)
const login_response = server_login1.start(
password_file,
email,
login_request
)
console.log('login_response', login_response)
// Serialize login handler state and persist it outside of the server
// to preserve statlessness across request handlers
const login_state = server_login1.serialize()
server_login1.free()
console.log('login_state', login_state)
const login_final = client_login.finish(password, login_response)
console.log('client login final', login_final)
console.log('client session key', client_login.getSessionKey())
const server_login2 = HandleLogin.deserialize(login_state, server_setup)
const server_finish = server_login2.finish(login_final)
console.log('server session key', server_finish)
console.log('registration export key', registration_export_key)
console.log('login export key', client_login.getExportKey())
}
run()