Skip to content

Commit

Permalink
feat(core): only re-create bran if missing in the secure storage
Browse files Browse the repository at this point in the history
  • Loading branch information
iFergal committed Apr 29, 2024
1 parent 2eaa159 commit 627b56e
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/core/agent/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
Tier,
} from "signify-ts";
import { Storage } from "@ionic/storage";
import { DataType } from "@aparajita/capacitor-secure-storage";
import {
ConnectionService,
CredentialService,
Expand Down Expand Up @@ -156,12 +157,20 @@ class Agent {
}

private async getBran(): Promise<string> {
let bran;
let bran: DataType | null;
try {
bran = await SecureStorage.get(KeyStoreKeys.SIGNIFY_BRAN);
} catch (error) {
bran = randomPasscode();
await SecureStorage.set(KeyStoreKeys.SIGNIFY_BRAN, bran);
if (
error instanceof Error &&
error.message ===
`${SecureStorage.KEY_NOT_FOUND} ${KeyStoreKeys.SIGNIFY_BRAN}`
) {
bran = randomPasscode();
await SecureStorage.set(KeyStoreKeys.SIGNIFY_BRAN, bran);
} else {
throw error;
}
}
return bran as string;
}
Expand Down

0 comments on commit 627b56e

Please sign in to comment.