-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
88 lines (82 loc) · 2.83 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Open Sesame</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="./style.css" rel="stylesheet">
<script src="https://unpkg.com/[email protected]"></script>
<script type="module">
import * as v from './src/vanilla-plus'
async function getCredentials () {
const salt = v.at('input[name=salt]').get('value')
const accountId = v.at('input[name=account-id]').get('value')
const challenge = v.at('#random-challenge').text()
const enc = new TextEncoder()
const credz = await navigator.credentials.get({ publicKey: {
challenge: enc.encode([salt, challenge].join(''))
} })
console.log('😱', credz)
}
async function createCredentials () {
const salt = v.at('input[name=salt]').get('value')
const accountId = v.at('input[name=account-id]').get('value')
const challenge = v.at('#random-challenge').text()
console.log(salt, accountId, challenge)
const enc = new TextEncoder()
try {
const credz = await navigator.credentials.create({
publicKey: {
challenge: enc.encode([salt, challenge].join('')),
rp: { name: 'Open Sesame Inc.'},
user: {
id: enc.encode(accountId),
name: 'Alice',
displayName: 'Alice'
},
pubKeyCredParams: [ {type: "public-key", alg: -7} ]
}
})
console.log('🚀', credz)
} catch (err) { console.error('‼️', err) }
}
v.at('input[name=salt]').set('value', crypto.randomUUID())
v.at('input[name=account-id]').set('value', crypto.randomUUID())
v.on('click').at('#create-credentials').perform(createCredentials)
v.on('click').at('#get-credentials').perform(getCredentials)
</script>
</head>
<body>
<form hx-get="/api/random-challenge"
hx-target="#random-challenge"
hx-swap="innerHTML">
<input type="hidden" name="salt">
<input type="hidden" name="account-id">
<input type="submit" value="1. Get a random challenge">
</form>
<p class="panel">
<i class="fas fa-door-open"></i>
<span id="random-challenge"></span>
</p>
<button id="get-credentials">
2. Try to get existing credentials
</button>
<button id="create-credentials">
3. Create credentials via browser api
</button>
<div class="panel">
<p>
<i class="fas fa-key"></i>
<span id="public-key"></span>
</p>
<p>
<i class="fas fa-passport"></i>
<span id="credential-id"></span>
</p>
<p>
<i class="fas fa-door-closed"></i>
<span id="signed-challenge-key"></span>
</p>
</div>
</body>
</html>