-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
67 lines (63 loc) · 2.42 KB
/
Copy pathutils.js
File metadata and controls
67 lines (63 loc) · 2.42 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
import { YiviCore } from '@privacybydesign/yivi-core'
import { YiviClient } from '@privacybydesign/yivi-client'
import { YiviPopup } from '@privacybydesign/yivi-popup'
import '@privacybydesign/yivi-css'
export const KeySorts = {
Encryption: 'key',
Signing: 'sign/key',
}
export const PKG_URL = 'https://main.postguard.ihub.ru.nl/pkg'
export async function fetchKey(
sort,
keyRequest,
timestamp = undefined,
signingKeyRequest = undefined
) {
const session = {
url: PKG_URL,
start: {
url: (o) => `${o.url}/v2/request/start`,
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(keyRequest),
},
result: {
url: (o, { sessionToken }) => `${o.url}/v2/request/jwt/${sessionToken}`,
parseResponse: (r) => {
return r
.text()
.then((jwt) =>
fetch(
`${PKG_URL}/v2/irma/${sort}${
timestamp ? '/' + timestamp.toString() : ''
}`,
{
method: sort === KeySorts.Encryption ? 'GET' : 'POST',
headers: {
Authorization: `Bearer ${jwt}`,
'Content-Type': 'application/json',
},
...(signingKeyRequest && {
body: JSON.stringify({ ...signingKeyRequest }),
}),
}
)
)
.then((r) => r.json())
.then((json) => {
if (json.status !== 'DONE' || json.proofStatus !== 'VALID')
throw new Error(
`key fetch failed: status=${json.status} proofStatus=${json.proofStatus}`
)
return sort === KeySorts.Encryption
? json.key
: { pubSignKey: json.pubSignKey, privSignKey: json.privSignKey }
})
},
},
}
const yivi = new YiviCore({ debugging: false, session })
yivi.use(YiviClient)
yivi.use(YiviPopup)
return yivi.start()
}