1 import type { Address, Api, DecryptedKey, KeyGenConfig, KeyTransparencyVerify } from '../interfaces';
2 import { createAddressKeyLegacy, createAddressKeyV2 } from './add';
3 import { getHasMigratedAddressKeys } from './keyMigration';
5 type OnUpdateCallback = (ID: string, update: { status: 'loading' | 'error' | 'ok'; result?: string }) => void;
7 interface MissingKeysSelfProcessArguments {
9 userKeys: DecryptedKey[];
10 keyGenConfig: KeyGenConfig;
12 addressesToGenerate: Address[];
14 onUpdate: OnUpdateCallback;
15 keyTransparencyVerify: KeyTransparencyVerify;
18 export const missingKeysSelfProcess = ({
26 keyTransparencyVerify,
27 }: MissingKeysSelfProcessArguments) => {
28 const hasMigratedAddressKeys = getHasMigratedAddressKeys(addresses);
31 addressesToGenerate.map(async (address) => {
33 onUpdate(address.ID, { status: 'loading' });
35 if (hasMigratedAddressKeys) {
36 await createAddressKeyV2({
42 keyTransparencyVerify,
45 await createAddressKeyLegacy({
51 keyTransparencyVerify,
55 onUpdate(address.ID, { status: 'ok' });
57 onUpdate(address.ID, { status: 'error', result: e.message });