Skip to content

Commit

Permalink
chore: update lint tools versions + use ts 5 (#55)
Browse files Browse the repository at this point in the history
Updating `eslint` and other similar packages.

---------

Co-authored-by: Daniel Rocha <[email protected]>
  • Loading branch information
ccharly and danroc authored Oct 1, 2024
1 parent c843ccf commit cb10ee6
Show file tree
Hide file tree
Showing 52 changed files with 869 additions and 1,222 deletions.
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'],

// 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": "[email protected]",
"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}`: {
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
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
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

0 comments on commit cb10ee6

Please sign in to comment.