Skip to content

Commit

Permalink
Rm password in the service
Browse files Browse the repository at this point in the history
  • Loading branch information
katspaugh committed May 27, 2024
1 parent 6914af4 commit 4db77cf
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ import { asError } from '@/services/exceptions/utils'
import useSocialWallet from '@/hooks/wallets/mpc/useSocialWallet'

enum ExportFieldNames {
password = 'password',
pk = 'pk',
}

type ExportFormData = {
[ExportFieldNames.password]: string
[ExportFieldNames.pk]: string | undefined
}

Expand All @@ -30,21 +28,18 @@ const ExportMPCAccountModal = ({ onClose, open }: { onClose: () => void; open: b
const [showPassword, setShowPassword] = useState(false)
const formMethods = useForm<ExportFormData>({
mode: 'all',
defaultValues: {
[ExportFieldNames.password]: '',
},
})
const { register, formState, handleSubmit, setValue, watch, reset } = formMethods

const exportedKey = watch(ExportFieldNames.pk)

const onSubmit = async (data: ExportFormData) => {
const onSubmit = async () => {
if (!socialWalletService) {
return
}
try {
setError(undefined)
const pk = await socialWalletService.exportSignerKey(data[ExportFieldNames.password])
const pk = await socialWalletService.exportSignerKey()
trackEvent(MPC_WALLET_EVENTS.EXPORT_PK_SUCCESS)
setValue(ExportFieldNames.pk, pk)
} catch (err) {
Expand Down
8 changes: 2 additions & 6 deletions src/services/mpc/SocialWalletService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,12 @@ class SocialWalletService implements ISocialWalletService {
return this.mpcCoreKit.status === COREKIT_STATUS.LOGGED_IN
}

async exportSignerKey(password: string): Promise<string> {
async exportSignerKey(): Promise<string> {
try {
if (this.securityQuestionRecovery.isEnabled()) {
// Only export PK if recovery works
await this.securityQuestionRecovery.recoverWithPassword(password)
}
const exportedPK = await this.mpcCoreKit?._UNSAFE_exportTssKey()
return exportedPK
} catch (err) {
throw new Error('Error exporting account. Make sure the password is correct.')
throw new Error('Error exporting account. ' + (err as Error).message)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/services/mpc/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface ISocialWalletService {
*
* @param password recovery password
*/
exportSignerKey(password: string): Promise<string>
exportSignerKey(): Promise<string>

/**
* Returns true if MFA is enabled
Expand Down

0 comments on commit 4db77cf

Please sign in to comment.