@@ -40,7 +40,11 @@ import type {
4040 QrSyncControllerGetStateAction ,
4141 QrSyncControllerMarkProvisioningFailedAction ,
4242} from '../controller-types' ;
43- import { QrSyncProvisioningStatuses , QrSyncSecretTypes } from '../constants' ;
43+ import {
44+ QrSyncProvisioningStatuses ,
45+ QrSyncSecretTypes ,
46+ type QrSyncSyncFlow ,
47+ } from '../constants' ;
4448import type {
4549 QrSyncAccountGroup ,
4650 QrSyncProvisioningMetadata ,
@@ -54,7 +58,6 @@ import {
5458 QrSyncSurfaces ,
5559 QrSyncTelemetrySources ,
5660 reportQrSyncFailure ,
57- type QrSyncSyncFlow ,
5861} from '../qrSyncTelemetry' ;
5962
6063const SERVICE_NAME = 'QrSyncProvisioningService' as const ;
@@ -133,50 +136,65 @@ export class QrSyncProvisioningService {
133136 ) : Promise < void > {
134137 for ( const secret of secrets ) {
135138 try {
136- if ( secret . type === QrSyncSecretTypes . MNEMONIC ) {
137- const entropySource = await this . #importMnemonicToVault( secret . value ) ;
138- this . #messenger. call (
139- 'QrSyncController:enrichProvisioningEntry' ,
140- secret . index ,
141- { entropySource } ,
142- ) ;
143- } else if ( secret . type === QrSyncSecretTypes . PRIVATE_KEY ) {
144- const accountAddress = await this . #importPrivateKeyToVault(
145- secret . value ,
146- ) ;
147-
148- if ( accountAddress ) {
149- this . #messenger. call (
150- 'QrSyncController:enrichProvisioningEntry' ,
151- secret . index ,
152- { accountAddress } ,
153- ) ;
154- }
155- } else {
156- const syncFlow = this . #getSessionSyncFlow( ) ;
157- reportQrSyncFailure (
158- new Error ( 'QrSyncProvisioningService: Unknown secret type' ) ,
159- {
160- surface : QrSyncSurfaces . IMPORT ,
161- operation : QrSyncOperations . IMPORT_SECRETS_UNKNOWN_TYPE ,
162- source : QrSyncTelemetrySources . PROVISIONING_IMPORT_SECRETS ,
163- ...( syncFlow ? { syncFlow } : { } ) ,
164- extras : { secretType : String ( secret . type ) } ,
165- } ,
166- ) ;
167- }
139+ await this . #importSingleSecretToVault( secret ) ;
168140 } catch ( error ) {
169- const syncFlow = this . #getSessionSyncFlow( ) ;
170- reportQrSyncFailure ( error , {
171- surface : QrSyncSurfaces . IMPORT ,
172- operation : QrSyncOperations . IMPORT_SECRETS_TO_VAULT ,
173- source : QrSyncTelemetrySources . PROVISIONING_IMPORT_SECRETS ,
174- ...( syncFlow ? { syncFlow } : { } ) ,
175- } ) ;
141+ this . #reportImportSecretsFailure(
142+ error ,
143+ QrSyncOperations . IMPORT_SECRETS_TO_VAULT ,
144+ ) ;
176145 }
177146 }
178147 }
179148
149+ async #importSingleSecretToVault(
150+ secret : QrSyncSecretImportEntry ,
151+ ) : Promise < void > {
152+ if ( secret . type === QrSyncSecretTypes . MNEMONIC ) {
153+ const entropySource = await this . #importMnemonicToVault( secret . value ) ;
154+ this . #messenger. call (
155+ 'QrSyncController:enrichProvisioningEntry' ,
156+ secret . index ,
157+ { entropySource } ,
158+ ) ;
159+ return ;
160+ }
161+
162+ if ( secret . type === QrSyncSecretTypes . PRIVATE_KEY ) {
163+ const accountAddress = await this . #importPrivateKeyToVault( secret . value ) ;
164+ if ( accountAddress ) {
165+ this . #messenger. call (
166+ 'QrSyncController:enrichProvisioningEntry' ,
167+ secret . index ,
168+ { accountAddress } ,
169+ ) ;
170+ }
171+ return ;
172+ }
173+
174+ this . #reportImportSecretsFailure(
175+ new Error ( 'QrSyncProvisioningService: Unknown secret type' ) ,
176+ QrSyncOperations . IMPORT_SECRETS_UNKNOWN_TYPE ,
177+ { secretType : String ( secret . type ) } ,
178+ ) ;
179+ }
180+
181+ #reportImportSecretsFailure(
182+ error : unknown ,
183+ operation :
184+ | typeof QrSyncOperations . IMPORT_SECRETS_TO_VAULT
185+ | typeof QrSyncOperations . IMPORT_SECRETS_UNKNOWN_TYPE ,
186+ extras ?: Record < string , unknown > ,
187+ ) : void {
188+ const syncFlow = this . #getSessionSyncFlow( ) ;
189+ reportQrSyncFailure ( error , {
190+ surface : QrSyncSurfaces . IMPORT ,
191+ operation,
192+ source : QrSyncTelemetrySources . PROVISIONING_IMPORT_SECRETS ,
193+ ...( syncFlow ? { syncFlow } : { } ) ,
194+ ...( extras ? { extras } : { } ) ,
195+ } ) ;
196+ }
197+
180198 async #importMnemonicToVault( seed : string ) : Promise < EntropySourceId > {
181199 const mnemonic = mnemonicPhraseToBytes ( seed ) ;
182200
0 commit comments