-
Notifications
You must be signed in to change notification settings - Fork 6
/
InitDialog.svelte
298 lines (270 loc) · 10.3 KB
/
InitDialog.svelte
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
<script lang="ts">
import Dialog, {Title, Content, Actions} from '@smui/dialog';
import Button, {Label} from '@smui/button';
import Textfield, {Input} from '@smui/textfield';
import HelperText from '@smui/textfield/helper-text/index';
import FloatingLabel from '@smui/floating-label';
import LineRipple from '@smui/line-ripple';
import { mutation, getClient } from "svelte-apollo";
import { AGENT_SERVICE_STATUS, INITIALIZE_AGENT, LOCK_AGENT, QUIT, UNLOCK_AGENT } from './graphql_queries';
import LinkExtern from './LinkExtern.svelte'
const QGL_CLIENT = getClient()
const GQL_INITIALIZE_AGENT = mutation(INITIALIZE_AGENT)
const GQL_LOCK_AGENT = mutation(LOCK_AGENT)
const GQL_UNLOCK_AGENT = mutation(UNLOCK_AGENT)
const GQL_QUIT = mutation(QUIT)
function check() {
QGL_CLIENT.query({ query: AGENT_SERVICE_STATUS }).then( result => {
console.log("check:", result)
if(!result.data.agent.isInitialized) {
initDialog.open()
} else {
initDialog.close()
if(!result.data.agent.isUnlocked) {
did = result.data.agent.did
unlockDialog.open()
} else {
unlockDialog.close()
}
}
})
}
let initDialog;
let didElementDialog;
let didKeyDialog;
let unlockDialog;
let did;
let didDocument;
let keystore;
let passphrase
let passphrase2
let passphraseError
let unlockError
function submitDID() {
GQL_INITIALIZE_AGENT({
variables: {
did,
didDocument: JSON.stringify(didDocument),
keystore,
passphrase
}
}).then(() => check())
}
function submitKeyDID() {
if(passphrase !== passphrase2) {
passphraseError = "Passphrases don't match!"
setTimeout(didKeyDialog.open, 10)
return
}
GQL_LOCK_AGENT({
variables: { passphrase }
})
}
function resolveDID() {
console.log("resolve:", did)
fetch(`https://resolver.identity.foundation/1.0/identifiers/${did}`)
.then(response => response.json())
.then(data => didDocument = data);
}
function unlockKeystore() {
GQL_UNLOCK_AGENT({ variables: { passphrase }}).then((result) => {
console.log("unlock response:", result)
unlockError = result.data.unlockAgent.error
passphrase = ""
if(result.data.unlockAgent.isUnlocked) {
unlockDialog.close()
} else {
unlockDialog.open()
}
})
}
function quit() {
GQL_QUIT({})
}
function importKeystore() {
initDialog.close()
didElementDialog.open()
}
async function createKeys() {
GQL_INITIALIZE_AGENT({
variables: {}
}).then(result => {
console.log(result)
// @ts-ignore
did = result.data?.initializeAgent?.did
initDialog.close()
didKeyDialog.open()
})
}
check()
</script>
<Dialog
bind:this={initDialog}
aria-labelledby="dialog-title"
aria-describedby="dialog-content"
scrimClickAction=""
escapeKeyAction=""
>
<Title id="dialog-title">Setup Agent Identity</Title>
<Content id="dialog-content">
<h1>Welcome to Perspectivism</h1>
<div>
Perspectivism is agent-centric and built around <LinkExtern url="https://w3c.github.io/did-core/">DIDs (Decentralized Identifier)</LinkExtern>
as the agent representation.
This means it does not add its own siloed user handling / login, but in principle can work with any decentralized/sovereign
identitiy platform that implements DID (like <LinkExtern url="https://www.uport.me/">uPort</LinkExtern>, <LinkExtern url="https://sovrin.org/">sovrin</LinkExtern>, a DID document on your own webserver, etc.).
</div>
<div>
If you don't know what this means, it's safe to choose to create a new and ephemeral DID with only locally stored keys.
</div>
<div>
But if you want to use Perspectivism with your already existing DID, you can also import the according keystore
and have Perspectivism sign all expressions under your existing identity.
</div>
</Content>
<Actions>
<Button variant="outlined" on:click={importKeystore}>
<Label>Import existing DID & keystore</Label>
</Button>
<Button variant="raised" on:click={createKeys}>
<Label>Create new ephemeral DID & keys</Label>
</Button>
</Actions>
</Dialog>
<Dialog bind:this={didKeyDialog}
scrimClickAction=""
escapeKeyAction=""
>
<Title id="dialog-title">Create new keystore</Title>
<Content>
<h1>Create new Keystore</h1>
<div>
<div>Your freshly created DID is:</div>
<span class="did">{did}</span>
</div>
<div>
<div>
Please enter a new passphrase to lock your keystore with:
</div>
<Textfield fullwidth lineRipple={false} label="Keystore">
<Input bind:value={passphrase} id="input-did" type="password" aria-controls="unlock-helper-text" aria-describedby="unlock-helper-text" />
<FloatingLabel for="input-did">Passphrase</FloatingLabel>
<LineRipple />
</Textfield>
<HelperText id="unlock-helper-text">Please enter the passphrase for you keystore</HelperText>
{#if unlockError}
<p>
<div class="error">{unlockError}</div>
{/if}
<Textfield fullwidth lineRipple={false} label="Keystore">
<Input bind:value={passphrase2} id="input-did" type="password" aria-controls="unlock-helper-text" aria-describedby="unlock-helper-text" />
<FloatingLabel for="input-did">Passphrase again</FloatingLabel>
<LineRipple />
</Textfield>
<HelperText id="unlock-helper-text">Please re-enter the same passphrase to be sure</HelperText>
{#if passphraseError}
<p>
<div class="error">{passphraseError}</div>
{/if}
</div>
</Content>
<Actions>
<Button on:click={quit}>
<Label>Quit</Label>
</Button>
<Button variant="raised" on:click={submitKeyDID}>
<Label>Finish</Label>
</Button>
</Actions>
</Dialog>
<Dialog
bind:this={didElementDialog}
aria-labelledby="dialog-title"
aria-describedby="dialog-content"
scrimClickAction=""
escapeKeyAction=""
>
<Title id="dialog-title">Import DID keystore</Title>
<Content id="dialog-content">
<h1>Import DID & Keystore</h1>
<div>
Currently, the only supported keystore format is the one used and exported by <LinkExtern url="https://element-did.com">https://element-did.com</LinkExtern>.
</div>
<div>
If have another DID provider you want to use with Perspectivism, please <LinkExtern url="https://github.com/lucksus/perspectivism/issues/new">create a ticket and let us know!</LinkExtern>
</div>
<div>
DID:
<Textfield fullwidth lineRipple={false} label="DID">
<Input bind:value={did} id="input-did" aria-controls="did-helper-text" aria-describedby="did-helper-text" />
<FloatingLabel for="input-did">DID handle</FloatingLabel>
<LineRipple />
</Textfield>
<HelperText id="did-helper-text">Please paste here your already existing DID (e.g.: did:github:lucksus)</HelperText>
<HelperText id="keystore-helper-text">Keystore (locked)</HelperText>
<br>
DID document:Please paste here your locked/encrypted keystore string
</div>
<div>
Keystore:
<Textfield fullwidth lineRipple={false} label="Keystore">
<Input bind:value={keystore} id="input-keystore" aria-controls="keystore-helper-text" aria-describedby="keystore-helper-text" />
<FloatingLabel for="input-keystore">Locked keystore string</FloatingLabel>
<LineRipple />
</Textfield>
<HelperText id="keystore-helper-text">Please paste here your locked/encrypted keystore string</HelperText>
<br>
Passphrase:
<Textfield fullwidth lineRipple={false} label="Passphrase">
<Input bind:value={passphrase} id="input-keystore" type="password" aria-controls="keystore-helper-text" aria-describedby="keystore-helper-text" />
<FloatingLabel for="input-keystore">Passphrase</FloatingLabel>
<LineRipple />
</Textfield>
<HelperText id="keystore-helper-text">Passphrase for above entered keystore cipher</HelperText>
</div>
</Content>
<Actions>
<Button on:click={quit}>
<Label>Quit</Label>
</Button>
<Button on:click={submitDID}>
<Label>Submit</Label>
</Button>
</Actions>
</Dialog>
<Dialog bind:this={unlockDialog}
scrimClickAction=""
escapeKeyAction=""
>
<Title id="dialog-title">Unlock Agent Keystore</Title>
<Content>
<span class="did">{did}</span>
<Textfield fullwidth lineRipple={false} label="Keystore">
<Input bind:value={passphrase} id="input-did" type="password" aria-controls="unlock-helper-text" aria-describedby="unlock-helper-text" />
<FloatingLabel for="input-did">Passphrase</FloatingLabel>
<LineRipple />
</Textfield>
<HelperText id="unlock-helper-text">Please enter the passphrase for you keystore</HelperText>
{#if unlockError}
<p>
<div class="error">{unlockError}</div>
{/if}
</Content>
<Actions>
<Button on:click={quit}>
<Label>Quit</Label>
</Button>
<Button variant="raised" on:click={unlockKeystore}>
<Label>Unlock</Label>
</Button>
</Actions>
</Dialog>
<style>
.error {
color: red;
}
.did {
max-width: 512px;
word-wrap: break-word;
}
</style>