Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 0 additions & 54 deletions oxlint-suppressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,6 @@
"count": 1
}
},
"packages/bitcoin-wallet-snap/src/handlers/HandlerMiddleware.ts": {
"typescript/no-unsafe-argument": {
"count": 1
}
},
"packages/bitcoin-wallet-snap/src/handlers/KeyringHandler.test.ts": {
"id-length": {
"count": 1
Expand Down Expand Up @@ -121,26 +116,11 @@
"count": 1
}
},
"packages/bitcoin-wallet-snap/src/handlers/RpcHandler.ts": {
"typescript/no-unsafe-assignment": {
"count": 1
}
},
"packages/bitcoin-wallet-snap/src/handlers/UserInputHandler.test.ts": {
"typescript/no-unnecessary-type-assertion": {
"count": 2
}
},
"packages/bitcoin-wallet-snap/src/handlers/UserInputHandler.ts": {
"internal-snaps/no-in-operator": {
"count": 1
}
},
"packages/bitcoin-wallet-snap/src/handlers/caip.ts": {
"typescript/no-unsafe-return": {
"count": 1
}
},
"packages/bitcoin-wallet-snap/src/handlers/mappings.test.ts": {
"typescript/explicit-function-return-type": {
"count": 3
Expand All @@ -155,11 +135,6 @@
"count": 9
}
},
"packages/bitcoin-wallet-snap/src/handlers/mappings.ts": {
"typescript/no-unnecessary-type-assertion": {
"count": 1
}
},
"packages/bitcoin-wallet-snap/src/handlers/validation.test.ts": {
"typescript/explicit-function-return-type": {
"count": 2
Expand Down Expand Up @@ -288,35 +263,6 @@
"count": 4
}
},
"packages/bitcoin-wallet-snap/src/use-cases/AccountUseCases.test.ts": {
"no-throw-literal": {
"count": 2
},
"typescript/no-unnecessary-type-assertion": {
"count": 1
}
},
"packages/bitcoin-wallet-snap/src/use-cases/AccountUseCases.ts": {
"typescript/no-unsafe-assignment": {
"count": 1
}
},
"packages/bitcoin-wallet-snap/src/use-cases/SendFlowUseCases.test.ts": {
"typescript/explicit-function-return-type": {
"count": 1
},
"typescript/no-explicit-any": {
"count": 5
},
"typescript/no-unsafe-argument": {
"count": 3
}
},
"packages/bitcoin-wallet-snap/src/utils/format-btc.test.ts": {
"jsdoc/check-tag-names": {
"count": 1
}
},
"packages/snap-networks-utils/src/services/analytics/AnalyticsService.test.ts": {
"typescript/no-unsafe-member-access": {
"count": 5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
SnapError,
getErrorMessage,
} from '@metamask/snaps-sdk';
import type { Json } from '@metamask/utils';
import { StructError } from 'superstruct';

import type { Translator, Logger, SnapClient } from '../entities';
Expand Down Expand Up @@ -109,9 +110,12 @@ export class HandlerMiddleware {
} else {
if (error instanceof StructError) {
const errMsg = messages['error.0']?.message ?? 'Invalid format';
// `StructError` declares an `any` index signature, so the payload is
// narrowed to the type accepted by the error wrapper.
const structData = error.data as Record<string, Json> | undefined;
throw new InvalidInputError(
`${errMsg}: ${error.message}`,
error.data,
structData,
);
}
// Unknown error type — wrap in SnapError to preserve the original
Expand Down
6 changes: 3 additions & 3 deletions packages/bitcoin-wallet-snap/src/handlers/RpcHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -585,9 +585,9 @@ export class RpcHandler {
const accountsById = new Map(
allAccounts.map((account) => [account.id.toLowerCase(), account]),
);
const results: SignProofOfOwnershipBatchResponse['results'] = new Array(
items.length,
);
const results: SignProofOfOwnershipBatchResponse['results'] = new Array<
SignProofOfOwnershipBatchResponse['results'][number]
>(items.length);
const signingRequestMetadata: {
index: number;
accountId: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
Json,
UserInputEvent,
} from '@metamask/snaps-sdk';
import { hasProperty } from '@metamask/utils';

import type { ReviewTransactionContext, SendFormContext } from '../entities';
import {
Expand Down Expand Up @@ -71,6 +72,6 @@ export class UserInputHandler {
}

#hasValue(event: UserInputEvent): event is InputChangeEvent {
return 'value' in event;
return hasProperty(event, 'value');
}
}
10 changes: 8 additions & 2 deletions packages/bitcoin-wallet-snap/src/handlers/caip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@ const reverseMapping = <
To extends string | number | symbol,
>(
map: Record<From, To>,
): Record<To, From> =>
Object.fromEntries(Object.entries(map).map(([from, to]) => [to, from]));
): Record<To, From> => {
const reversed = {} as Record<To, From>;
// `Object.keys` widens the keys of a `Record` to `string`, hence the cast.
for (const from of Object.keys(map) as From[]) {
reversed[map[from]] = from;
}
return reversed;
};

export const scopeToNetwork: Record<BtcScope, Network> = {
[BtcScope.Mainnet]: 'bitcoin',
Expand Down
2 changes: 1 addition & 1 deletion packages/bitcoin-wallet-snap/src/handlers/mappings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export type Utxo = {
*/
export function mapToKeyringAccount(account: BitcoinAccount): KeyringAccount {
return {
type: addressTypeToCaip[account.addressType] as KeyringAccount['type'],
type: addressTypeToCaip[account.addressType],
scopes: [networkToScope[account.network]],
id: account.id,
address: account.publicAddress.toString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1671,9 +1671,11 @@ describe('AccountUseCases', () => {
});

it('includes non-Error cause in ValidationError message', async () => {
// Deliberately not an `Error`: exercises the message-extraction path.
const nonErrorCause = { message: 'InsufficientFunds', code: 11 };
mockTxBuilder.finish.mockImplementation(() => {
// eslint-disable-next-line @typescript-eslint/only-throw-error
throw { message: 'InsufficientFunds', code: 11 };
throw nonErrorCause;
});

await expect(
Expand All @@ -1684,9 +1686,11 @@ describe('AccountUseCases', () => {
});

it('uses unknown cause when error has no message', async () => {
// Deliberately not an `Error`: exercises the fallback message path.
const causeWithoutMessage = 42;
mockTxBuilder.finish.mockImplementation(() => {
// eslint-disable-next-line @typescript-eslint/only-throw-error
throw 42;
throw causeWithoutMessage;
});

await expect(
Expand Down Expand Up @@ -2621,7 +2625,7 @@ describe('AccountUseCases', () => {
segments: string[],
): Promise<RealSlip10Node> {
const derivationPath: [BIP39Node, ...BIP32Node[]] = [
mnemonicPhraseToBytes(mnemonic) as BIP39Node,
mnemonicPhraseToBytes(mnemonic),
...segments.map((segment) => `bip32:${segment}` as BIP32Node),
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -854,9 +854,8 @@ export class AccountUseCases {
async signProofOfOwnershipMessages(
requests: SignProofOfOwnershipMessageBatchRequest[],
): Promise<SignProofOfOwnershipMessageBatchResult[]> {
const results: SignProofOfOwnershipMessageBatchResult[] = new Array(
requests.length,
);
const results: SignProofOfOwnershipMessageBatchResult[] =
new Array<SignProofOfOwnershipMessageBatchResult>(requests.length);
const requestsByParentPath = new Map<
string,
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type {
Balance,
FeeEstimates,
Network,
ScriptBuf,
Transaction,
} from '@metamask/bitcoindevkit';
import { Psbt, Address, Amount } from '@metamask/bitcoindevkit';
Expand Down Expand Up @@ -812,7 +814,7 @@ describe('SendFlowUseCases', () => {

it('sets account from state on Account', async () => {
const accountId = 'myAccount2';
mockAccount.publicAddress.toString = () => 'myAddress2';
mockAccount.publicAddress.toString = (): string => 'myAddress2';
mockAccountRepository.get.mockResolvedValue({
...mockAccount,
id: accountId,
Expand Down Expand Up @@ -1105,11 +1107,11 @@ describe('SendFlowUseCases', () => {
mockSnapClient.displayUserPrompt.mockResolvedValue(true);
mockAccountUseCases.signPsbt.mockResolvedValue({
psbt: mockSignedPsbt,
} as any);
} as unknown as Awaited<ReturnType<AccountUseCases['signPsbt']>>);
(Psbt.from_string as Mock).mockReturnValue(mockSignedPsbt);
mockRatesClient.spotPrices.mockResolvedValue({
price: { value: 50000, currency: 'usd' },
} as any);
} as unknown as SpotPrice);
});

it('builds and confirms a regular send transaction', async () => {
Expand Down Expand Up @@ -1149,7 +1151,7 @@ describe('SendFlowUseCases', () => {
});

it('marks the recipient as isMine when the address belongs to the account', async () => {
const recipientScript = {} as any;
const recipientScript = mock<ScriptBuf>();
(Address.from_string as Mock).mockReturnValue({
script_pubkey: recipientScript,
});
Expand Down Expand Up @@ -1186,7 +1188,7 @@ describe('SendFlowUseCases', () => {
balanceAmount.to_sat.mockReturnValue(BigInt(10000));
mockAccount.balance = {
trusted_spendable: balanceAmount,
} as any;
} as unknown as Balance;

await useCases.confirmSendFlow(mockAccount, amount, toAddress);

Expand Down Expand Up @@ -1325,7 +1327,7 @@ describe('SendFlowUseCases', () => {
it('handles missing exchange rate gracefully', async () => {
mockRatesClient.spotPrices.mockResolvedValue({
price: undefined,
} as any);
} as unknown as SpotPrice);

await useCases.confirmSendFlow(mockAccount, amount, toAddress);

Expand Down
4 changes: 1 addition & 3 deletions packages/bitcoin-wallet-snap/src/utils/format-btc.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/**
* @vitest-environment node
*/
// @vitest-environment node

import { BalanceStruct } from '@metamask/keyring-api';
import { assert } from '@metamask/superstruct';
Expand Down
Loading