Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update lint tools versions + use ts 5 #55

Merged
merged 24 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
9e3dd15
chore: update eslint (^8.55.0) + align @metamask/eslint-config-* (^13…
ccharly Sep 17, 2024
a743d76
chore: update rimraf (^5.0.10) + prettier-plugin-packagejson (^2.5.2)
ccharly Sep 17, 2024
4eae793
refactor(keyring-api): fix new eslint errors
ccharly Sep 17, 2024
0575f0e
refactor(keyring-eth-hd): fix new eslint errors
ccharly Sep 17, 2024
64d25e1
refactor(keyring-eth-ledger-bridge): fix new eslint errors
ccharly Sep 26, 2024
4e66c6e
refactor(keyring-eth-trezor): fix new eslint errors
ccharly Sep 27, 2024
aae45b7
refactor(keyring-snap-bridge): fix new eslint errors
ccharly Sep 27, 2024
1c35590
chore: fix more linting errors
danroc Sep 27, 2024
b31ba85
refactor(keyring-eth-trezor): fix new eslint errors
ccharly Sep 27, 2024
bf8f086
chore: fix more linting errors
danroc Sep 27, 2024
d6f7572
chore: fix more linting errors
danroc Sep 27, 2024
59b1046
chore(deps): align versions of `rimraf`
danroc Sep 27, 2024
e32dcb0
chore: update `yarn.lock`
danroc Sep 27, 2024
5a8cc28
chore(deps): update `eslint-plugin-jest`
danroc Sep 27, 2024
10e55ef
chore: rename `expectSync` to `noPending`
danroc Sep 27, 2024
79a7804
chore(deps-dev): bump 'typescript' to 5.4.5
danroc Sep 27, 2024
3aab831
chore: comment unused 'setup.ts' file
danroc Sep 27, 2024
8d8a883
chore: update `expectSync` -> `noPending`
danroc Sep 27, 2024
6f9a4a8
chore(eslint): disable false positive
danroc Sep 30, 2024
54eb2a9
chore: switch `#validateRedirectUrl` back to a sync method
danroc Sep 30, 2024
006878f
refactor(keyring-eth-ledger-bridge): export AccountPage{,Entry}
ccharly Oct 1, 2024
f916f75
refactor(keyring-eth-trezor): export AccountPage{,Entry}
ccharly Oct 1, 2024
0ebf5a7
chore(keyring-eth-ledger-bridge): add more comments
ccharly Oct 1, 2024
fff0e11
refactor(keyring-eth-simple): rename import './simple-keyring' to '.'
ccharly Oct 1, 2024
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
2 changes: 1 addition & 1 deletion jest.config.packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ module.exports = {
// runner: "jest-runner",

// The paths to modules that run some code to configure or set up the testing environment before each test
setupFiles: ['../../tests/setup.ts'],
// setupFiles: ['../../tests/setup.ts'],
gantunesr marked this conversation as resolved.
Show resolved Hide resolved

// A list of paths to modules that run some code to configure or set up the testing framework before each test
// setupFilesAfterEnv: ['../../tests/setupAfterEnv/index.ts'],
Expand Down
30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,36 +48,36 @@
"@lavamoat/allow-scripts": "^3.2.1",
"@lavamoat/preinstall-always-fail": "^2.1.0",
"@metamask/create-release-branch": "^3.0.1",
"@metamask/eslint-config": "^12.2.0",
"@metamask/eslint-config-jest": "^12.1.0",
"@metamask/eslint-config-nodejs": "^12.1.0",
"@metamask/eslint-config-typescript": "^12.1.0",
"@metamask/eslint-config": "^13.0.0",
"@metamask/eslint-config-jest": "^13.0.0",
"@metamask/eslint-config-nodejs": "^13.0.0",
"@metamask/eslint-config-typescript": "^13.0.0",
"@npmcli/package-json": "^5.0.0",
"@types/jest": "^29.5.12",
"@types/node": "^20.12.12",
"@typescript-eslint/eslint-plugin": "^5.43.0",
"@typescript-eslint/parser": "^5.43.0",
"@typescript-eslint/eslint-plugin": "^8.5.0",
"@typescript-eslint/parser": "^8.5.0",
"depcheck": "^1.4.7",
"eslint": "^8.44.0",
"eslint": "^8.55.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-import": "~2.26.0",
"eslint-plugin-jest": "^27.2.2",
"eslint-plugin-jsdoc": "^39.9.1",
"eslint-plugin-n": "^15.7.0",
"eslint-plugin-import-x": "^0.5.3",
"eslint-plugin-jest": "^27.9.0",
"eslint-plugin-jsdoc": "^47.0.2",
"eslint-plugin-n": "^16.6.2",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-promise": "^6.6.0",
"execa": "^5.0.0",
"jest": "^29.5.0",
"jest-it-up": "^3.1.0",
"jest-silent-reporter": "^0.5.0",
"prettier": "^2.8.8",
"prettier-plugin-packagejson": "^2.3.0",
"rimraf": "^5.0.7",
"prettier-plugin-packagejson": "^2.5.2",
"rimraf": "^5.0.10",
"syncpack": "^13.0.0",
"ts-jest": "^29.0.5",
"ts-node": "^10.9.2",
"typedoc": "^0.25.13",
"typescript": "~4.8.4"
"typescript": "~5.4.5"
},
"packageManager": "yarn@4.5.0",
"engines": {
Expand Down
4 changes: 2 additions & 2 deletions packages/keyring-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@
"depcheck": "^1.4.7",
"jest": "^29.5.0",
"jest-it-up": "^3.1.0",
"rimraf": "^5.0.7",
"rimraf": "^5.0.10",
"ts-jest": "^29.0.5",
"ts-node": "^10.9.2",
"tsd": "^0.31.0",
"typedoc": "^0.25.13",
"typescript": "~4.8.4"
"typescript": "~5.4.5"
},
"peerDependencies": {
"@metamask/providers": "^17.2.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/keyring-api/src/KeyringClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export type Sender = {
};

export class KeyringClient implements Keyring {
#sender: Sender;
readonly #sender: Sender;

/**
* Create a new instance of `KeyringClient`.
Expand Down
4 changes: 2 additions & 2 deletions packages/keyring-api/src/KeyringSnapRpcClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import { KeyringClient } from './KeyringClient';
* to a snap through the snap JSON-RPC API.
*/
export class SnapRpcSender implements Sender {
#origin: string;
readonly #origin: string;

#provider: MetaMaskInpageProvider;
readonly #provider: MetaMaskInpageProvider;

/**
* Create a new instance of `SnapRpcSender`.
Expand Down
2 changes: 1 addition & 1 deletion packages/keyring-api/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ export * from './account';
export * from './balance';
export * from './caip';
export * from './export';
export * from './keyring';
export type * from './keyring';
export * from './request';
export * from './response';
2 changes: 1 addition & 1 deletion packages/keyring-api/src/btc/types.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { BtcP2wpkhAccount } from './types';
import type { KeyringAccount } from '../api';
import type { Extends } from '../utils';
import { expectTrue } from '../utils';
import type { BtcP2wpkhAccount } from './types';

// `BtcP2wpkhAccount` extends `KeyringAccount`
expectTrue<Extends<BtcP2wpkhAccount, KeyringAccount>>();
1 change: 1 addition & 0 deletions packages/keyring-api/src/eth/erc4337/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { EthAddressStruct, EthBytesStruct, EthUint256Struct } from '../types';

/**
* Struct of a UserOperation as defined by ERC-4337.
*
* @see https://eips.ethereum.org/EIPS/eip-4337#definitions
*/
export const EthUserOperationStruct = object({
Expand Down
4 changes: 2 additions & 2 deletions packages/keyring-api/src/eth/types.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { expectAssignable, expectNotAssignable } from 'tsd';

import type { EthEoaAccount, EthErc4337Account } from './types';
import { EthMethod } from './types';
import type { KeyringAccount } from '../api';
import { EthAccountType } from '../api';
import type { Extends } from '../utils';
import { expectTrue } from '../utils';
import type { EthEoaAccount, EthErc4337Account } from './types';
import { EthMethod } from './types';

const id = '606a7759-b0fb-48e4-9874-bab62ff8e7eb';
const address = '0x000';
Expand Down
2 changes: 1 addition & 1 deletion packages/keyring-api/src/eth/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BtcAccountType, EthAccountType } from '../api';
import { isEvmAccountType } from './utils';
import { BtcAccountType, EthAccountType } from '../api';

describe('isEvmAccountType', () => {
it.each([
Expand Down
2 changes: 1 addition & 1 deletion packages/keyring-api/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export * from './api';
export * from './btc';
export * from './contexts';
export type * from './contexts';
export * from './eth';
export * from './events';
export * from './internal';
Expand Down
2 changes: 1 addition & 1 deletion packages/keyring-api/src/internal/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from '@metamask/superstruct';
import { JsonStruct } from '@metamask/utils';

import { KeyringRpcMethod } from './rpc';
import {
BalanceStruct,
CaipAssetTypeStruct,
Expand All @@ -19,7 +20,6 @@ import {
} from '../api';
import { object } from '../superstruct';
import { UuidStruct } from '../utils';
import { KeyringRpcMethod } from './rpc';

const CommonHeader = {
jsonrpc: literal('2.0'),
Expand Down
2 changes: 1 addition & 1 deletion packages/keyring-api/src/internal/eth/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './EthKeyring';
export type * from './EthKeyring';
4 changes: 2 additions & 2 deletions packages/keyring-api/src/internal/events.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { is } from '@metamask/superstruct';

import { EthAccountType } from '../api';
import { KeyringEvent } from '../events';
import {
AccountCreatedEventStruct,
AccountDeletedEventStruct,
AccountUpdatedEventStruct,
RequestApprovedEventStruct,
RequestRejectedEventStruct,
} from './events';
import { EthAccountType } from '../api';
import { KeyringEvent } from '../events';

describe('events', () => {
describe('AccountCreatedEventStruct', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/keyring-api/src/internal/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from './api';
export * from './eth';
export type * from './eth';
export * from './events';
export * from './rpc';
export * from './types';
35 changes: 12 additions & 23 deletions packages/keyring-api/src/internal/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,20 @@ export const InternalAccountMetadataStruct = object({
}),
});

/**
* Creates an `InternalAccount` from an existing account `superstruct` object.
*
* @param accountStruct - An account `superstruct` object.
* @returns The `InternalAccount` associated to `accountStruct`.
*/
function asInternalAccountStruct<Account, AccountSchema>(
accountStruct: Struct<Account, AccountSchema>,
) {
return object({
...accountStruct.schema,
...InternalAccountMetadataStruct.schema,
});
}

export const InternalEthEoaAccountStruct =
asInternalAccountStruct(EthEoaAccountStruct);
export const InternalEthEoaAccountStruct = object({
...EthEoaAccountStruct.schema,
...InternalAccountMetadataStruct.schema,
});

export const InternalEthErc4337AccountStruct = asInternalAccountStruct(
EthErc4337AccountStruct,
);
export const InternalEthErc4337AccountStruct = object({
...EthErc4337AccountStruct.schema,
...InternalAccountMetadataStruct.schema,
});

export const InternalBtcP2wpkhAccountStruct = asInternalAccountStruct(
BtcP2wpkhAccountStruct,
);
export const InternalBtcP2wpkhAccountStruct = object({
...BtcP2wpkhAccountStruct.schema,
...InternalAccountMetadataStruct.schema,
});

export type InternalEthEoaAccount = Infer<typeof InternalEthEoaAccountStruct>;

Expand Down
26 changes: 13 additions & 13 deletions packages/keyring-api/src/rpc-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,22 @@ async function dispatchRequest(
assert(request, JsonRpcRequestStruct);

switch (request.method) {
case KeyringRpcMethod.ListAccounts: {
case `${KeyringRpcMethod.ListAccounts}`: {
gantunesr marked this conversation as resolved.
Show resolved Hide resolved
assert(request, ListAccountsRequestStruct);
return keyring.listAccounts();
}

case KeyringRpcMethod.GetAccount: {
case `${KeyringRpcMethod.GetAccount}`: {
assert(request, GetAccountRequestStruct);
return keyring.getAccount(request.params.id);
}

case KeyringRpcMethod.CreateAccount: {
case `${KeyringRpcMethod.CreateAccount}`: {
assert(request, CreateAccountRequestStruct);
return keyring.createAccount(request.params.options);
}

case KeyringRpcMethod.GetAccountBalances: {
case `${KeyringRpcMethod.GetAccountBalances}`: {
if (keyring.getAccountBalances === undefined) {
throw new MethodNotSupportedError(request.method);
}
Expand All @@ -73,62 +73,62 @@ async function dispatchRequest(
);
}

case KeyringRpcMethod.FilterAccountChains: {
case `${KeyringRpcMethod.FilterAccountChains}`: {
assert(request, FilterAccountChainsStruct);
return keyring.filterAccountChains(
request.params.id,
request.params.chains,
);
}

case KeyringRpcMethod.UpdateAccount: {
case `${KeyringRpcMethod.UpdateAccount}`: {
assert(request, UpdateAccountRequestStruct);
return keyring.updateAccount(request.params.account);
}

case KeyringRpcMethod.DeleteAccount: {
case `${KeyringRpcMethod.DeleteAccount}`: {
assert(request, DeleteAccountRequestStruct);
return keyring.deleteAccount(request.params.id);
}

case KeyringRpcMethod.ExportAccount: {
case `${KeyringRpcMethod.ExportAccount}`: {
if (keyring.exportAccount === undefined) {
throw new MethodNotSupportedError(request.method);
}
assert(request, ExportAccountRequestStruct);
return keyring.exportAccount(request.params.id);
}

case KeyringRpcMethod.ListRequests: {
case `${KeyringRpcMethod.ListRequests}`: {
if (keyring.listRequests === undefined) {
throw new MethodNotSupportedError(request.method);
}
assert(request, ListRequestsRequestStruct);
return keyring.listRequests();
}

case KeyringRpcMethod.GetRequest: {
case `${KeyringRpcMethod.GetRequest}`: {
if (keyring.getRequest === undefined) {
throw new MethodNotSupportedError(request.method);
}
assert(request, GetRequestRequestStruct);
return keyring.getRequest(request.params.id);
}

case KeyringRpcMethod.SubmitRequest: {
case `${KeyringRpcMethod.SubmitRequest}`: {
assert(request, SubmitRequestRequestStruct);
return keyring.submitRequest(request.params);
}

case KeyringRpcMethod.ApproveRequest: {
case `${KeyringRpcMethod.ApproveRequest}`: {
if (keyring.approveRequest === undefined) {
throw new MethodNotSupportedError(request.method);
}
assert(request, ApproveRequestRequestStruct);
return keyring.approveRequest(request.params.id, request.params.data);
}

case KeyringRpcMethod.RejectRequest: {
case `${KeyringRpcMethod.RejectRequest}`: {
if (keyring.rejectRequest === undefined) {
throw new MethodNotSupportedError(request.method);
}
Expand Down
1 change: 1 addition & 0 deletions packages/keyring-api/src/superstruct.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { expectAssignable, expectNotAssignable } from 'tsd';

import { exactOptional, object } from '.';

// eslint-disable-next-line @typescript-eslint/no-unused-vars
gantunesr marked this conversation as resolved.
Show resolved Hide resolved
const exactOptionalObject = object({
a: number(),
b: optional(string()),
Expand Down
1 change: 1 addition & 0 deletions packages/keyring-api/src/superstruct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type {
Simplify,
} from '@metamask/superstruct';

// eslint-disable-next-line @typescript-eslint/no-unused-vars
gantunesr marked this conversation as resolved.
Show resolved Hide resolved
declare const ExactOptionalSymbol: unique symbol;

export type ExactOptionalTag = {
Expand Down
2 changes: 1 addition & 1 deletion packages/keyring-api/src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const UrlStruct = define<string>('Url', (value: unknown) => {
try {
const url = new URL(value as string);
return url.protocol === 'http:' || url.protocol === 'https:';
} catch (_) {
} catch {
return false;
}
});
Expand Down
10 changes: 5 additions & 5 deletions packages/keyring-eth-hd/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
const { HDKey } = require('ethereum-cryptography/hdkey');
const { keccak256 } = require('ethereum-cryptography/keccak');
const { bytesToHex } = require('ethereum-cryptography/utils');
const {
privateToPublic,
publicToAddress,
ecsign,
arrToBufArr,
bufferToHex,
} = require('@ethereumjs/util');
const bip39 = require('@metamask/scure-bip39');
const { wordlist } = require('@metamask/scure-bip39/dist/wordlists/english');
const {
concatSig,
decrypt,
Expand All @@ -19,7 +14,12 @@ const {
signTypedData,
SignTypedDataVersion,
} = require('@metamask/eth-sig-util');
const bip39 = require('@metamask/scure-bip39');
const { wordlist } = require('@metamask/scure-bip39/dist/wordlists/english');
const { assertIsHexString, remove0x } = require('@metamask/utils');
const { HDKey } = require('ethereum-cryptography/hdkey');
const { keccak256 } = require('ethereum-cryptography/keccak');
const { bytesToHex } = require('ethereum-cryptography/utils');

// Options:
const hdPathString = `m/44'/60'/0'/0`;
Expand Down
Loading