-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
142 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
export * from './navigation'; | ||
export * from './generate-keys'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { createMutation, useQueryClient, createQuery } from '@tanstack/svelte-query'; | ||
import { generateKeys } from '$lib/services'; | ||
import type { GeneratedKeys } from '$types'; | ||
import { queryKey } from './query-keys'; | ||
|
||
export function useGeneratedKeys() { | ||
const queryClient = useQueryClient(); | ||
|
||
const generateKeysMutation = createMutation({ | ||
mutationFn: (passphrase: string) => generateKeys(passphrase), | ||
onSuccess: (data) => { | ||
queryClient.setQueryData([queryKey], data); | ||
} | ||
}); | ||
|
||
const generatedKeysQuery = createQuery<GeneratedKeys>({ | ||
queryKey: [queryKey] | ||
}); | ||
return { generateKeysMutation, generatedKeysQuery }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './app-queries'; | ||
export * from './query-keys'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const queryKey = 'generatedKeys'; |
2 changes: 1 addition & 1 deletion
2
src/lib/helpers/generate-keys.ts → src/lib/services/generate-keys.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './generate-keys'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
export type SetPassphrase = 'set' | 'confirm'; | ||
|
||
export type GeneratedKeys = { | ||
master: Uint8Array; | ||
device: Uint8Array; | ||
revocation: Uint8Array; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
<script> | ||
import '../app.css'; | ||
import { QueryClient, QueryClientProvider } from '@tanstack/svelte-query'; | ||
const queryClient = new QueryClient(); | ||
</script> | ||
|
||
<slot /> | ||
<QueryClientProvider client={queryClient}> | ||
<slot /> | ||
</QueryClientProvider> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<script lang="ts"> | ||
import { getContext, onMount } from 'svelte'; | ||
import { passphrase } from '$stores'; | ||
import JSZip from 'jszip'; | ||
import fileSaver from 'file-saver'; | ||
import type { Writable } from 'svelte/store'; | ||
import { goto } from '$app/navigation'; | ||
import Button from '$components/Button.svelte'; | ||
import { useGeneratedKeys } from '$queries'; | ||
import Title from '$components/Title.svelte'; | ||
import AppParagraph from '$components/AppParagraph.svelte'; | ||
const passphraseStore = getContext<Writable<string>>(passphrase); | ||
const { generatedKeysQuery } = useGeneratedKeys(); | ||
onMount(() => { | ||
if ($passphraseStore === '') { | ||
goto('/setup/start'); | ||
} | ||
}); | ||
async function download(): Promise<void> { | ||
const { saveAs } = fileSaver; | ||
const files = [ | ||
{ name: 'master.txt', data: new TextDecoder().decode($generatedKeysQuery.data?.master) }, | ||
{ name: 'device.txt', data: new TextDecoder().decode($generatedKeysQuery.data?.device) }, | ||
{ | ||
name: 'revocation.txt', | ||
data: new TextDecoder().decode($generatedKeysQuery.data?.revocation) | ||
} | ||
]; | ||
const zip = new JSZip(); | ||
files.forEach((file) => zip.file(file.name, file.data)); | ||
const content = await zip.generateAsync({ type: 'blob' }); | ||
saveAs(content, 'keys.zip'); | ||
} | ||
</script> | ||
|
||
<img src="/img/check.svg" alt="check" class="w-12 my-4" /> | ||
|
||
<Title>Save Seed Files and Keys</Title> | ||
<AppParagraph | ||
extraProps="mx-auto text-center max-w-md" | ||
text="All done, please save your files. Remember to back them up an external drive you store in a secure location." | ||
/> | ||
|
||
<img src="/img/padlock.svg" alt="Padlock" class="my-6" /> | ||
<Button label="Save" onClick={download} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,44 @@ | ||
<script lang="ts"> | ||
import { getContext, onMount } from 'svelte'; | ||
import { passphrase } from '$stores'; | ||
import JSZip from 'jszip'; | ||
import fileSaver from 'file-saver'; | ||
import type { Writable } from 'svelte/store'; | ||
import { goto } from '$app/navigation'; | ||
import AppParagraph from '$components/AppParagraph.svelte'; | ||
import Title from '$components/Title.svelte'; | ||
import Button from '$components/Button.svelte'; | ||
import { generateKeys } from '$helpers/generate-keys'; | ||
import { useGeneratedKeys } from '$queries'; | ||
const passphraseStore = getContext<Writable<string>>(passphrase); | ||
const { generateKeysMutation } = useGeneratedKeys(); | ||
onMount(() => { | ||
if ($passphraseStore === '') { | ||
goto('/setup/start'); | ||
} | ||
}); | ||
async function download(): Promise<void> { | ||
const { saveAs } = fileSaver; | ||
const { master, device, revocation } = await generateKeys($passphraseStore); | ||
const files = [ | ||
{ name: 'master.txt', data: new TextDecoder().decode(master) }, | ||
{ name: 'device.txt', data: new TextDecoder().decode(device) }, | ||
{ name: 'revocation.txt', data: new TextDecoder().decode(revocation) } | ||
]; | ||
const zip = new JSZip(); | ||
files.forEach((file) => zip.file(file.name, file.data)); | ||
const content = await zip.generateAsync({ type: 'blob' }); | ||
saveAs(content, 'keys.zip'); | ||
function generate() { | ||
$generateKeysMutation.mutate($passphraseStore, { | ||
onSuccess: () => goto('/setup/download') | ||
}); | ||
} | ||
</script> | ||
|
||
<img src="/img/download.svg" alt="Download" class="w-12 my-4" /> | ||
<Title>Generate Seed & Key files</Title> | ||
<AppParagraph | ||
extraProps="mx-auto text-center max-w-md" | ||
text="Click the button below to generate and save your seed and key files. Please save this on your external hard drive or USB drive." | ||
/> | ||
<p class="text-secondary text-base font-bold text-center mt-4">Context:</p> | ||
<AppParagraph | ||
extraProps="mx-auto text-center" | ||
text="Remember, you will need BOTH the seed and your passphrase to restore any keys that are created from this seed. Remember to store your drives in save places like a safe, you can also save copies of this on digital drives" | ||
/> | ||
<img src="/img/padlock.svg" alt="Padlock" class="my-6" /> | ||
<Button label="Generate" onClick={download} /> | ||
{#if $generateKeysMutation.isPending} | ||
<span>Loading</span> | ||
{:else} | ||
<img src="/img/download.svg" alt="Download" class="w-12 my-4" /> | ||
<Title>Generate Seed & Key files</Title> | ||
<AppParagraph | ||
extraProps="mx-auto text-center max-w-md" | ||
text="Click the button below to generate and save your seed and key files. Please save this on your external hard drive or USB drive." | ||
/> | ||
<p class="text-secondary text-base font-bold text-center mt-4">Context:</p> | ||
<AppParagraph | ||
extraProps="mx-auto text-center" | ||
text="Remember, you will need BOTH the seed and your passphrase to restore any keys that are created from this seed. Remember to store your drives in save places like a safe, you can also save copies of this on digital drives" | ||
/> | ||
<img src="/img/padlock.svg" alt="Padlock" class="my-6" /> | ||
<Button label="Generate" onClick={generate} /> | ||
{/if} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters