diff options
author | Sebastian <sebasjm@gmail.com> | 2023-12-27 15:59:46 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2023-12-27 15:59:46 -0300 |
commit | 4e6631071e1f69db697334cccba77e09f393507e (patch) | |
tree | 0d81bf73d5bb10fe56d123046626be9da3662582 /packages/aml-backoffice-ui/src/hooks | |
parent | 8fb8506b274c07440895c8412586b3745aa8fa1b (diff) |
use seed from exchange
Diffstat (limited to 'packages/aml-backoffice-ui/src/hooks')
-rw-r--r-- | packages/aml-backoffice-ui/src/hooks/useOfficer.ts | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/packages/aml-backoffice-ui/src/hooks/useOfficer.ts b/packages/aml-backoffice-ui/src/hooks/useOfficer.ts index 64cf79cc9..fe989f3eb 100644 --- a/packages/aml-backoffice-ui/src/hooks/useOfficer.ts +++ b/packages/aml-backoffice-ui/src/hooks/useOfficer.ts @@ -20,6 +20,7 @@ import { useMemoryStorage, } from "@gnu-taler/web-util/browser"; import { useMemo } from "preact/hooks"; +import { useExchangeApiContext, useMaybeExchangeApiContext } from "../context/config.js"; export interface Officer { account: LockedAccount; @@ -35,9 +36,9 @@ type OfficerAccountString = { export const codecForOfficerAccount = (): Codec<OfficerAccountString> => buildCodecForObject<OfficerAccountString>() - .property("id", codecForString()) // FIXME - .property("strKey", codecForString()) // FIXME - .build("OfficerAccount"); + .property("id", codecForString()) // FIXME + .property("strKey", codecForString()) // FIXME + .build("OfficerAccount"); export const codecForOfficer = (): Codec<Officer> => buildCodecForObject<Officer>() @@ -68,6 +69,7 @@ const DEV_ACCOUNT_KEY = buildStorageKey("account-dev", codecForOfficerAccount()) const ACCOUNT_KEY = "account"; export function useOfficer(): OfficerState { + const exchangeContext = useMaybeExchangeApiContext(); // dev account, is save when reloaded. const accountStorage = useLocalStorage(DEV_ACCOUNT_KEY); const account = useMemo(() => { @@ -78,19 +80,24 @@ export function useOfficer(): OfficerState { } }, [accountStorage.value]) - + // const accountStorage = useMemoryStorage<OfficerAccount>(ACCOUNT_KEY); // const account = accountStorage.value; - const officerStorage = useLocalStorage(OFFICER_KEY); + const officerStorage = useLocalStorage(OFFICER_KEY); const officer = officerStorage.value; - if (officer === undefined) { return { state: "not-found", create: async (pwd: string) => { - const { id, safe, signingKey } = await createNewOfficerAccount(pwd); + if (!exchangeContext) return; + const req = await fetch(new URL("seed", exchangeContext.api.baseUrl).href) + const b = await req.blob() + const ar = await b.arrayBuffer() + const uintar = new Uint8Array(ar) + + const { id, safe, signingKey } = await createNewOfficerAccount(pwd, uintar); officerStorage.update({ account: safe, when: AbsoluteTime.now(), @@ -98,7 +105,7 @@ export function useOfficer(): OfficerState { // accountStorage.update({ id, signingKey }); const strKey = encodeCrock(signingKey) - accountStorage.update({id, strKey }) + accountStorage.update({ id, strKey }) }, }; } @@ -112,7 +119,7 @@ export function useOfficer(): OfficerState { tryUnlock: async (pwd: string) => { const ac = await unlockOfficerAccount(officer.account, pwd); // accountStorage.update(ac); - accountStorage.update({id: ac.id, strKey: encodeCrock(ac.signingKey)}) + accountStorage.update({ id: ac.id, strKey: encodeCrock(ac.signingKey) }) }, }; } |