-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(wasm): Import/export account #893
Merged
Merged
Changes from 32 commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
ee77490
import ui
Flemmli97 f7ccdfb
add export to profile settings
Flemmli97 8c93a9f
finishing up account import
Flemmli97 74eb74f
typo
Flemmli97 f13fe55
Merge branch 'dev' into import/export_account
Flemmli97 dde7368
Merge branch 'dev' into import/export_account
stavares843 53c0bd8
Merge branch 'dev' into import/export_account
stavares843 aedbfa0
Merge branch 'dev' into import/export_account
stavares843 ef69fd5
Merge branch 'dev' into import/export_account
stavares843 b5a9f25
Merge branch 'dev' into import/export_account
stavares843 84e2546
Merge branch 'dev' into import/export_account
stavares843 93e1ddf
clear tesseract instance when going back
Flemmli97 7679900
change file extension
Flemmli97 b2dad02
remove log
Flemmli97 8ff7704
Merge branch 'dev' into import/export_account
Flemmli97 76dc2fa
Merge branch 'dev' into import/export_account
stavares843 73ee657
Merge branch 'dev' into import/export_account
Flemmli97 bfd7abd
Merge branch 'dev' into import/export_account
stavares843 74c11d6
Merge branch 'dev' into import/export_account
stavares843 31b5755
Merge branch 'dev' into import/export_account
stavares843 b3b4c65
reorder clearing
Flemmli97 6a7954c
Merge branch 'dev' into import/export_account
phillsatellite 762d90f
Merge branch 'dev' into import/export_account
luisecm 9435604
Merge branch 'dev' into import/export_account
Flemmli97 7676fac
Merge branch 'dev' into import/export_account
Flemmli97 0a75a36
Merge branch 'dev' into import/export_account
stavares843 c0eb324
Merge branch 'dev' into import/export_account
phillsatellite d7753f3
Merge branch 'dev' into import/export_account
stavares843 a6cf9e9
Merge branch 'dev' into import/export_account
phillsatellite 01313ab
Merge branch 'dev' into import/export_account
phillsatellite 9de6b2e
update wasm and remote export
Flemmli97 9a12fdc
Merge branch 'dev' into import/export_account
luisecm 6e9e5c6
update version
Flemmli97 5bb37d0
await on auth result
Flemmli97 e1b5000
disable capitalization for seed input
Flemmli97 fa75adb
Merge branch 'dev' into import/export_account
dariusc93 0cbe0f1
Merge branch 'dev' into import/export_account
luisecm 14232b8
fix buttons on mobile
stavares843 5b4dd37
allow paste spreading
Flemmli97 bdd940c
Merge branch 'dev' into import/export_account
stavares843 a99572b
Merge branch 'dev' into import/export_account
Flemmli97 4a8e489
Merge branch 'dev' into import/export_account
luisecm e162b73
Merge branch 'dev' into import/export_account
dariusc93 cfbf45a
Update src/lib/wasm/WarpStore.ts
Flemmli97 31b21d1
Merge branch 'dev' into import/export_account
stavares843 587b81e
Merge branch 'dev' into import/export_account
stavares843 d142bb7
Merge branch 'dev' into import/export_account
luisecm 4820fe2
Merge branch 'dev' into import/export_account
stavares843 438235d
Merge branch 'dev' into import/export_account
stavares843 7d1894e
file filter to import
Flemmli97 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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,177 @@ | ||
<script lang="ts"> | ||
import { Icon, Button, Title, Text } from "$lib/elements" | ||
import { Appearance, Shape } from "$lib/enums" | ||
import { _ } from "svelte-i18n" | ||
import { Identity, WarpInstance } from "warp-wasm" | ||
import { MultipassStoreInstance } from "$lib/wasm/MultipassStore" | ||
import { OrderedPhrase } from "$lib/components" | ||
import FileInput from "$lib/elements/Input/FileInput.svelte" | ||
import { TesseractStoreInstance } from "$lib/wasm/TesseractStore" | ||
import { RelayStore } from "$lib/state/wasm/relays" | ||
import { WarpStore } from "$lib/wasm/WarpStore" | ||
import { get } from "svelte/store" | ||
import { LoginPage } from "." | ||
import Unlock from "./Unlock.svelte" | ||
import { AuthStore } from "$lib/state/auth" | ||
import { Store } from "$lib/state/Store" | ||
import { ToastMessage } from "$lib/state/ui/toast" | ||
|
||
export let page: LoginPage | ||
export let onImport: (identity: Identity) => void | ||
|
||
let loading = false | ||
|
||
let passphrase: string[] = new Array(12).fill("") | ||
|
||
let passphraseUpload: FileInput | ||
let accountUpload: FileInput | ||
|
||
let failed: string = "" | ||
let pin = "" | ||
|
||
// We cache it here to not init the warp instances in all stores since its not ready at this time | ||
let warp: WarpInstance | ||
|
||
async function setupTesseract(pinInput: string) { | ||
await TesseractStoreInstance.initTesseract() | ||
let tesseract = await TesseractStoreInstance.getTesseract() | ||
if (TesseractStoreInstance.exists()) { | ||
tesseract.clear() | ||
} | ||
let result = await TesseractStoreInstance.unlock(pinInput) | ||
let failed = false | ||
result.onFailure(_ => { | ||
failed = true | ||
console.log("Failed to unlock tesseract") | ||
}) | ||
if (failed) return | ||
let addresses = Object.values(get(RelayStore.state)) | ||
.filter(r => r.active) | ||
.map(r => r.address) | ||
warp = await WarpStore.createIpfs(addresses) | ||
pin = pinInput | ||
} | ||
|
||
async function readPassphrase(files: File[]) { | ||
let file = files[0] | ||
let content = await file.text() | ||
// Allow splitting by new lines and/or whitespace | ||
passphrase = content.split("\n").join(" ").split(" ") | ||
} | ||
|
||
async function importAccount(files?: File[]) { | ||
loading = true | ||
let memory: Uint8Array | undefined = undefined | ||
if (files) { | ||
memory = new Uint8Array(await files[0].arrayBuffer()) | ||
} | ||
let res = await MultipassStoreInstance.importAccount(passphrase.join(" "), { to: memory, multipassBox: warp.multipass }) | ||
res.onSuccess(identity => { | ||
if (identity) { | ||
AuthStore.setStoredPin(pin) | ||
WarpStore.updateWarpInstance(warp) | ||
onImport(identity) | ||
} else { | ||
Store.addToastNotification(new ToastMessage($_("pages.auth.import.fail.null"), "", 2)) | ||
} | ||
}) | ||
res.onFailure(err => { | ||
Store.addToastNotification(new ToastMessage($_("pages.auth.import.fail"), err, 2)) | ||
failed = err | ||
}) | ||
loading = false | ||
} | ||
</script> | ||
|
||
{#if pin.length == 0} | ||
<Unlock | ||
create={true} | ||
importing={true} | ||
on:pin={async e => { | ||
await setupTesseract(e.detail.pin) | ||
e.detail.done() | ||
}} /> | ||
{:else} | ||
<div class="account-import"> | ||
<div class="header"> | ||
<Title hook="title-import-account">{$_("pages.auth.import.title")}</Title> | ||
<Text hook="text-import-account-secondary" muted>{$_("pages.auth.import.description")}</Text> | ||
</div> | ||
{#each passphrase as word, i} | ||
<OrderedPhrase number={i + 1} bind:word={word} editable loading={loading} /> | ||
{/each} | ||
<Button | ||
hook="upload-passphrase" | ||
on:click={() => { | ||
passphraseUpload.click() | ||
}} | ||
text={$_("pages.auth.import.passphrase")}> | ||
<Icon icon={Shape.Details} /> | ||
</Button> | ||
<div class="import-button-group"> | ||
<Button | ||
hook="button-import-account-go-back" | ||
loading={loading} | ||
text={$_("controls.go_back")} | ||
appearance={Appearance.Alt} | ||
on:click={() => { | ||
page = LoginPage.EntryPoint | ||
TesseractStoreInstance.clearTesseract() | ||
}}> | ||
<Icon icon={Shape.ArrowLeft} /> | ||
</Button> | ||
<Button | ||
hook="import-account-file" | ||
loading={loading} | ||
disabled={passphrase.find(s => s.length === 0) !== undefined} | ||
on:click={() => { | ||
accountUpload.click() | ||
}} | ||
text={$_("pages.auth.import.file")}> | ||
<Icon icon={Shape.Document} /> | ||
</Button> | ||
<Button | ||
hook="import-account" | ||
loading={loading} | ||
disabled={passphrase.find(s => s.length === 0) !== undefined} | ||
on:click={() => { | ||
importAccount() | ||
}} | ||
text={$_("pages.auth.import.remote")}> | ||
<Icon icon={Shape.Globe} /> | ||
</Button> | ||
<FileInput | ||
bind:this={passphraseUpload} | ||
hidden | ||
on:select={e => { | ||
readPassphrase(e.detail) | ||
}} /> | ||
<FileInput | ||
bind:this={accountUpload} | ||
hidden | ||
on:select={e => { | ||
importAccount(e.detail) | ||
}} /> | ||
</div> | ||
</div> | ||
{/if} | ||
|
||
<style lang="scss"> | ||
.account-import { | ||
align-self: center; | ||
align-content: center; | ||
justify-content: center; | ||
display: inline-flex; | ||
flex-direction: row; | ||
gap: var(--gap); | ||
padding: var(--padding); | ||
max-width: var(--max-component-width); | ||
flex-wrap: wrap; | ||
flex: 1; | ||
.import-button-group { | ||
width: 100%; | ||
display: flex; | ||
justify-content: center; | ||
} | ||
} | ||
</style> |
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
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wouldnt it be best to use
get(this.multipassWritable)
altogether?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is because atm during import a temp warp instance is created
i guess we could just remove using the stored instance though since that atm is never used? thoughts?