forked from tauri-apps/tauri-plugin-stronghold
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.svelte
59 lines (49 loc) · 1.74 KB
/
App.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
<script lang="ts">
import { Stronghold, Location } from 'tauri-plugin-stronghold-api'
const stronghold = new Stronghold('./example.stronghold', 'password')
const store = stronghold.getStore('exampleStoreVault', [])
const vault = stronghold.getVault('exampleVault', [])
const location = Location.generic('vault', 'record')
stronghold.onStatusChange(status => {
_updateResponse('got new stronghold status: ' + status.snapshot.status)
})
let response = '';
let record;
function _updateResponse(returnValue) {
response += (typeof returnValue === 'string' ? returnValue : JSON.stringify(returnValue)) + '<br>'
}
_runProcedures().then(() => _updateResponse('procedures finished')).catch(e => _updateResponse('error running procedures: ' + e))
async function _runProcedures() {
const seedLocation = Location.generic('vault', 'seed')
await vault.generateBIP39(seedLocation)
const privateKeyLocation = Location.generic('vault', 'derived')
await vault.deriveSLIP10([0, 0, 0], 'Seed', seedLocation, privateKeyLocation)
const publicKey = await vault.getPublicKey(privateKeyLocation)
_updateResponse('got public key ' + publicKey)
const message = 'Tauri + Stronghold!'
const signature = await vault.sign(privateKeyLocation, message)
_updateResponse(`Signed "${message}" and got sig "${signature}"`)
}
async function save() {
await store.insert(location, record)
await stronghold.save()
}
function read() {
store.get(location)
.then(_updateResponse)
.catch(_updateResponse)
}
</script>
<style>
html {
background: #fff;
}
</style>
<div>
<input placeholder="The value to store" bind:value={record}>
<button on:click="{save}">Store</button>
</div>
<div>
<button on:click="{read}">Read</button>
<div>{@html response}</div>
</div>