Skip to content

Commit d590164

Browse files
fix(extension): avoid undefined form field passed to Buffer (#1592)
1 parent 12f88e6 commit d590164

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

apps/browser-extension-wallet/src/features/dapp/components/SignData.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { Layout } from './Layout';
1010
import { useViewsFlowContext } from '@providers/ViewFlowProvider';
1111
import styles from './SignTransaction.module.scss';
1212
import { WalletType } from '@cardano-sdk/web-extension';
13+
import { createPassphrase } from '@lib/wallet-api-ui';
1314

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

2627
const onConfirm = useCallback(async () => {
2728
setIsLoading(true);
28-
const passphrase = Buffer.from(password.value, 'utf8');
29+
const passphrase = createPassphrase(password);
2930
try {
3031
await request.sign(passphrase, { willRetryOnFailure: true });
3132
setValidPassword(true);

apps/browser-extension-wallet/src/features/dapp/components/SignTransaction.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import styles from './SignTransaction.module.scss';
1212
import { useAnalyticsContext } from '@providers';
1313
import { TX_CREATION_TYPE_KEY, TxCreationType } from '@providers/AnalyticsProvider/analyticsTracker';
1414
import { WalletType } from '@cardano-sdk/web-extension';
15+
import { createPassphrase } from '@lib/wallet-api-ui';
1516

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

38-
const passphrase = Buffer.from(password.value, 'utf8');
39+
const passphrase = createPassphrase(password);
3940
try {
4041
await request.sign(passphrase, { willRetryOnFailure: true });
4142
setValidPassword(true);

apps/browser-extension-wallet/src/lib/wallet-api-ui.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export const withSignTxConfirmation = async <T>(action: () => Promise<T>, passwo
9494
* @param {Partial<Password>} password The password object to be encoded.
9595
* @returns {Buffer} A Buffer containing the UTF-8 encoded password.
9696
*/
97-
const createPassphrase = (password: Partial<Password>): Buffer => Buffer.from(password.value || '', 'utf8');
97+
export const createPassphrase = (password: Partial<Password>): Buffer => Buffer.from(password.value || '', 'utf8');
9898

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

0 commit comments

Comments
 (0)