mirror of
https://github.com/Discreetly/frontend.git
synced 2026-01-09 12:58:03 -05:00
checkpoint identity restoration updated to encrypted stores
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { identityExists } from '$lib/stores';
|
||||
import { configStore, identityExists } from '$lib/stores';
|
||||
import { getIdentityBackup } from '$lib/utils/';
|
||||
|
||||
$: id = getIdentityBackup();
|
||||
@@ -8,6 +8,7 @@
|
||||
let revealIdentity = false;
|
||||
|
||||
function reveal() {
|
||||
$configStore.signUpStatus.identityBackedUp = true;
|
||||
id = getIdentityBackup();
|
||||
if (id === undefined || id === null) {
|
||||
id = 'No Identity Backup Found';
|
||||
@@ -27,7 +28,11 @@
|
||||
|
||||
<div class="m-2 sm:m-3 flex flex-col gap-4">
|
||||
{#if $identityExists == 'safe' || $identityExists == 'unsafe'}
|
||||
<a class="btn variant-ghost-success" href={encodedIdentity} download="Discreetly_Identity.json"
|
||||
<a
|
||||
class="btn variant-ghost-success"
|
||||
href={encodedIdentity}
|
||||
download="Discreetly_Identity.json"
|
||||
on:click={() => ($configStore.signUpStatus.identityBackedUp = true)}
|
||||
>Download Identity Backup as JSON</a
|
||||
>
|
||||
{#if !revealIdentity}
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
lockStateStore
|
||||
} from '../stores';
|
||||
import { Identity } from '@semaphore-protocol/identity';
|
||||
import type { IdentityStoreI } from '$lib/types';
|
||||
import { IdentityStoreE, type IdentityStoreI } from '$lib/types';
|
||||
|
||||
export function createIdentity(regenerate = false): 'created' | 'exists' | 'unsafe' | 'error' {
|
||||
const identityStatus = get(identityExists);
|
||||
@@ -24,6 +24,10 @@ export function createIdentity(regenerate = false): 'created' | 'exists' | 'unsa
|
||||
try {
|
||||
identityKeyStore.set(identity);
|
||||
if (get(identityExists) === 'safe') {
|
||||
configStore.update((state) => {
|
||||
state.identityStore = IdentityStoreE.localStorageEncrypted;
|
||||
return state;
|
||||
});
|
||||
alertQueue.enqueue('Identity Created! Congrats on your new journey');
|
||||
return 'created';
|
||||
} else {
|
||||
@@ -43,6 +47,10 @@ export function createIdentity(regenerate = false): 'created' | 'exists' | 'unsa
|
||||
'For your security please set a password with /password or click on the lock in the corner'
|
||||
);
|
||||
identityStore.set(identity);
|
||||
configStore.update((state) => {
|
||||
state.identityStore = IdentityStoreE.localStorage;
|
||||
return state;
|
||||
});
|
||||
return 'unsafe';
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { alertQueue, identityKeyStore, keyStore } from '$lib/stores';
|
||||
import { alertQueue, identityKeyStore, lockStateStore } from '$lib/stores';
|
||||
import { FileDropzone } from '@skeletonlabs/skeleton';
|
||||
import { poseidon2 } from 'poseidon-lite/poseidon2';
|
||||
import { poseidon1 } from 'poseidon-lite/poseidon1';
|
||||
@@ -8,7 +8,6 @@
|
||||
|
||||
function restoreBackup(backup: any) {
|
||||
console.debug('Attempting restore of identity from backup file...');
|
||||
console.debug(backup);
|
||||
let id;
|
||||
try {
|
||||
id = JSON.parse(backup);
|
||||
@@ -43,15 +42,19 @@
|
||||
alertQueue.enqueue('Commitment does not match commitment backup');
|
||||
}
|
||||
console.log('Restoring identity from backup file...');
|
||||
if ($keyStore !== undefined || $keyStore !== null) {
|
||||
if ($lockStateStore == 'unlocked') {
|
||||
$identityKeyStore = id;
|
||||
} else {
|
||||
alertQueue.enqueue('Please set a password or unlock before restoring your identity');
|
||||
}
|
||||
alertQueue.enqueue(
|
||||
`Identity restored from backup file with identity commitment:
|
||||
alertQueue.enqueue(
|
||||
`Identity restored from backup file with identity commitment:
|
||||
${$identityKeyStore._commitment}`
|
||||
);
|
||||
);
|
||||
} else if ($lockStateStore == 'locked') {
|
||||
alertQueue.enqueue('Please 🔑 UNLOCK before restoring your identity');
|
||||
} else {
|
||||
alertQueue.enqueue(
|
||||
'Please set a password using the padlock icon before restoring your identity'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function onChangeHandler(e: Event): void {
|
||||
|
||||
Reference in New Issue
Block a user