1 import { ADDRESS_STATUS, MEMBER_PRIVATE } from '../constants';
2 import type { Address, Api, DecryptedKey, KeyTransparencyVerify, UserModel as tsUserModel } from '../interfaces';
3 import { createAddressKeyLegacy, createAddressKeyV2 } from './add';
4 import { getHasMigratedAddressKeys } from './keyMigration';
6 export const getAddressesWithKeysToGenerate = (user: tsUserModel, addresses: Address[]) => {
7 // If signed in as subuser, or not a private user
8 if (!user || !addresses || user.OrganizationPrivateKey || user.Private !== MEMBER_PRIVATE.UNREADABLE) {
11 // Any enabled address without keys
12 return addresses.filter(({ Status, Keys = [] }) => {
13 return Status === ADDRESS_STATUS.STATUS_ENABLED && !Keys.length;
17 interface GenerateAllPrivateMemberKeys {
19 addressesToGenerate: Address[];
20 userKeys: DecryptedKey[];
23 keyTransparencyVerify: KeyTransparencyVerify;
26 export const generateAllPrivateMemberKeys = async ({
32 keyTransparencyVerify,
33 }: GenerateAllPrivateMemberKeys) => {
35 throw new Error('Password required to generate keys');
38 if (getHasMigratedAddressKeys(addresses)) {
40 addressesToGenerate.map((address) => {
41 return createAddressKeyV2({
46 keyTransparencyVerify,
53 addressesToGenerate.map((address) => {
54 return createAddressKeyLegacy({
57 passphrase: keyPassword,
59 keyTransparencyVerify,