Skip to content

Commit

Permalink
fix(extension): avoid undefined form field passed to Buffer (#1592)
Browse files Browse the repository at this point in the history
  • Loading branch information
mirceahasegan committed Dec 16, 2024
1 parent 046f094 commit 7b37772
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Layout } from './Layout';
import { useViewsFlowContext } from '@providers/ViewFlowProvider';
import styles from './SignTransaction.module.scss';
import { WalletType } from '@cardano-sdk/web-extension';
import { createPassphrase } from '@lib/wallet-api-ui';

export const SignData = (): React.ReactElement => {
const { t } = useTranslation();
Expand All @@ -25,7 +26,7 @@ export const SignData = (): React.ReactElement => {

const onConfirm = useCallback(async () => {
setIsLoading(true);
const passphrase = Buffer.from(password.value, 'utf8');
const passphrase = createPassphrase(password);
try {
await request.sign(passphrase, { willRetryOnFailure: true });
setValidPassword(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import styles from './SignTransaction.module.scss';
import { useAnalyticsContext } from '@providers';
import { TX_CREATION_TYPE_KEY, TxCreationType } from '@providers/AnalyticsProvider/analyticsTracker';
import { WalletType } from '@cardano-sdk/web-extension';
import { createPassphrase } from '@lib/wallet-api-ui';

export const SignTransaction = (): React.ReactElement => {
const { t } = useTranslation();
Expand All @@ -35,7 +36,7 @@ export const SignTransaction = (): React.ReactElement => {
[TX_CREATION_TYPE_KEY]: TxCreationType.External
});

const passphrase = Buffer.from(password.value, 'utf8');
const passphrase = createPassphrase(password);
try {
await request.sign(passphrase, { willRetryOnFailure: true });
setValidPassword(true);
Expand Down
2 changes: 1 addition & 1 deletion apps/browser-extension-wallet/src/lib/wallet-api-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const withSignTxConfirmation = async <T>(action: () => Promise<T>, passwo
* @param {Partial<Password>} password The password object to be encoded.
* @returns {Buffer} A Buffer containing the UTF-8 encoded password.
*/
const createPassphrase = (password: Partial<Password>): Buffer => Buffer.from(password.value || '', 'utf8');
export const createPassphrase = (password: Partial<Password>): Buffer => Buffer.from(password.value || '', 'utf8');

/**
* Handles the process of signing data with confirmation, supporting both in-memory and hardware wallets.
Expand Down

0 comments on commit 7b37772

Please sign in to comment.