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

refactor: split keyring-api #24

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
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
48 changes: 48 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ module.exports = {
'@typescript-eslint/naming-convention': 'warn',
},
},
// @metamask/keyring-utils
{
files: ['packages/keyring-utils/src/**/*.ts'],
extends: ['@metamask/eslint-config-typescript'],
parserOptions,
rules: {
// TODO: re-lint everything once the migration is done
'@typescript-eslint/no-explicit-any': 'off',
},
},
// @metamask/keyring-api
{
files: ['packages/keyring-api/src/**/*.ts'],
Expand All @@ -77,6 +87,18 @@ module.exports = {
'jsdoc/newline-after-description': 'off',
},
},
// @metamask/keyring-internal-api
{
files: ['packages/keyring-internal-api/src/**/*.ts'],
extends: ['@metamask/eslint-config-typescript'],
parserOptions,
rules: {
// FIXME: for some reason, it seems eslint is not able to infere those (this
// works on the original repository, so there might be some side-effects now that
// we are building in a monorepo)
'@typescript-eslint/restrict-template-expressions': 'off',
},
},
// @metamask/keyring-eth-hd
{
files: ['packages/keyring-eth-hd/**/*.js'],
Expand Down Expand Up @@ -169,6 +191,32 @@ module.exports = {
'@typescript-eslint/restrict-template-expressions': 'off',
},
},
// @metamask/keyring-snap-sdk
{
files: ['packages/keyring-snap-sdk/src/**/*.test.ts'],
extends: ['@metamask/eslint-config-typescript'],
parserOptions,
rules: {
// FIXME: for some reason, it seems eslint is not able to infere those (this
// works on the original repository, so there might be some side-effects now that
// we are building in a monorepo)
'@typescript-eslint/restrict-template-expressions': 'off',
},
},
// @metamask/keyring-snap-client
{
files: ['packages/keyring-snap-client/src/**/*.ts'],
extends: ['@metamask/eslint-config-typescript'],
parserOptions,
rules: {
// TODO: re-lint everything once the migration is done
'@typescript-eslint/no-explicit-any': 'off',
// FIXME: for some reason, it seems eslint is not able to infere those (this
// works on the original repository, so there might be some side-effects now that
// we are building in a monorepo)
'@typescript-eslint/restrict-template-expressions': 'off',
},
},
],
rules: {
'jsdoc/match-description': [
Expand Down
26 changes: 25 additions & 1 deletion .syncpackrc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,30 @@
"dependencyTypes": ["!local"],
"dependencies": ["@metamask/keyring-api"],
"pinVersion": "workspace:^"
}
},
{
"label": "use workspace version of the keyring-internal-api",
"dependencyTypes": ["!local"],
"dependencies": ["@metamask/keyring-internal-api"],
"pinVersion": "workspace:^"
},
{
"label": "use workspace version of the keyring-snap-sdk",
"dependencyTypes": ["!local"],
"dependencies": ["@metamask/keyring-snap-sdk"],
"pinVersion": "workspace:^"
},
{
"label": "use workspace version of the keyring-snap-client",
"dependencyTypes": ["!local"],
"dependencies": ["@metamask/keyring-snap-client"],
"pinVersion": "workspace:^"
},
{
"label": "use workspace version of the keyring-utils",
"dependencyTypes": ["!local"],
"dependencies": ["@metamask/keyring-utils"],
"pinVersion": "workspace:^"
},
]
}
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ This repository contains the following packages [^fn1]:
- [`@metamask/eth-snap-keyring`](packages/keyring-snap)
- [`@metamask/eth-trezor-keyring`](packages/keyring-eth-trezor)
- [`@metamask/keyring-api`](packages/keyring-api)
- [`@metamask/keyring-internal-api`](packages/keyring-internal-api)
- [`@metamask/keyring-snap-client`](packages/keyring-snap-client)
- [`@metamask/keyring-snap-sdk`](packages/keyring-snap-sdk)
- [`@metamask/keyring-utils`](packages/keyring-utils)

<!-- end package list -->

Expand All @@ -34,8 +38,19 @@ linkStyle default opacity:0.5
eth_ledger_bridge_keyring(["@metamask/eth-ledger-bridge-keyring"]);
eth_simple_keyring(["@metamask/eth-simple-keyring"]);
eth_trezor_keyring(["@metamask/eth-trezor-keyring"]);
keyring_internal_api(["@metamask/keyring-internal-api"]);
eth_snap_keyring(["@metamask/eth-snap-keyring"]);
keyring_snap_client(["@metamask/keyring-snap-client"]);
keyring_snap_sdk(["@metamask/keyring-snap-sdk"]);
keyring_utils(["@metamask/keyring-utils"]);
keyring_api --> keyring_utils;
keyring_internal_api --> keyring_api;
eth_snap_keyring --> keyring_api;
eth_snap_keyring --> keyring_snap_client;
eth_snap_keyring --> keyring_snap_sdk;
keyring_snap_client --> keyring_api;
keyring_snap_client --> keyring_snap_sdk;
keyring_snap_sdk --> keyring_api;
```

<!-- end dependency graph -->
Expand Down
10 changes: 3 additions & 7 deletions packages/keyring-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,17 @@
"test:watch": "jest --watch"
},
"dependencies": {
"@metamask/snaps-sdk": "^6.7.0",
"@metamask/keyring-utils": "workspace:^",
"@metamask/superstruct": "^3.1.0",
"@metamask/utils": "^9.2.1",
"@types/uuid": "^9.0.8",
"bech32": "^2.0.0",
"uuid": "^9.0.1",
"webextension-polyfill": "^0.12.0"
"uuid": "^9.0.1"
},
"devDependencies": {
"@lavamoat/allow-scripts": "^3.2.1",
"@lavamoat/preinstall-always-fail": "^2.1.0",
"@metamask/auto-changelog": "^3.4.4",
"@metamask/keyring-utils": "workspace:^",
"@metamask/providers": "^18.1.0",
"@ts-bridge/cli": "^0.6.0",
"@types/jest": "^29.5.12",
Expand All @@ -73,9 +72,6 @@
"typedoc": "^0.25.13",
"typescript": "~5.6.3"
},
"peerDependencies": {
"@metamask/providers": "^18.1.0"
},
"engines": {
"node": "^18.18 || >=20"
},
Expand Down
4 changes: 1 addition & 3 deletions packages/keyring-api/src/api/account.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { object, UuidStruct } from '@metamask/keyring-utils';
import type { Infer } from '@metamask/superstruct';
import { array, enums, record, string } from '@metamask/superstruct';
import { JsonStruct } from '@metamask/utils';

import { object } from '../superstruct';
import { UuidStruct } from '../utils';

/**
* Supported Ethereum account types.
*/
Expand Down
4 changes: 1 addition & 3 deletions packages/keyring-api/src/api/balance.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { object, StringNumberStruct } from '@metamask/keyring-utils';
import type { Infer } from '@metamask/superstruct';
import { string } from '@metamask/superstruct';

import { object } from '../superstruct';
import { StringNumberStruct } from '../utils';

export const BalanceStruct = object({
amount: StringNumberStruct,
unit: string(),
Expand Down
3 changes: 1 addition & 2 deletions packages/keyring-api/src/api/caip.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { definePattern } from '@metamask/keyring-utils';
import { is, type Infer } from '@metamask/superstruct';

import { definePattern } from '../superstruct';

const CAIP_ASSET_TYPE_REGEX =
/^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32}))\/(?<assetNamespace>[-a-z0-9]{3,8}):(?<assetReference>[-.%a-zA-Z0-9]{1,128})$/u;

Expand Down
4 changes: 1 addition & 3 deletions packages/keyring-api/src/api/request.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { exactOptional, object, UuidStruct } from '@metamask/keyring-utils';
import type { Infer } from '@metamask/superstruct';
import { array, record, string, union } from '@metamask/superstruct';
import { JsonStruct } from '@metamask/utils';

import { exactOptional, object } from '../superstruct';
import { UuidStruct } from '../utils';

export const KeyringRequestStruct = object({
/**
* Keyring request ID (UUIDv4).
Expand Down
3 changes: 1 addition & 2 deletions packages/keyring-api/src/api/response.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { exactOptional, object } from '@metamask/keyring-utils';
import type { Infer } from '@metamask/superstruct';
import { literal, string, union } from '@metamask/superstruct';
import { JsonStruct } from '@metamask/utils';

import { exactOptional, object } from '../superstruct';

export const KeyringResponseStruct = union([
object({
/**
Expand Down
30 changes: 0 additions & 30 deletions packages/keyring-api/src/eth/types.test.ts

This file was deleted.

13 changes: 0 additions & 13 deletions packages/keyring-api/src/events.ts

This file was deleted.

11 changes: 0 additions & 11 deletions packages/keyring-api/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,2 @@
export * from './api';
export * from './btc';
export type * from './contexts';
export * from './eth';
export * from './sol';
export * from './events';
export * from './internal';
export * from './JsonRpcRequest';
export * from './KeyringClient';
export * from './KeyringSnapRpcClient';
export * from './rpc-handler';
export * from './snap-utils';
export * from './superstruct';
19 changes: 0 additions & 19 deletions packages/keyring-api/src/utils/types.test.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/keyring-api/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// checking for all *.d.ts files
"skipLibCheck": true
},
"references": [{ "path": "../keyring-utils/tsconfig.build.json" }],
"include": ["./src/**/*.ts"],
"exclude": ["./src/**/*.test.ts", "./src/**/*.test-d.ts"]
}
10 changes: 10 additions & 0 deletions packages/keyring-internal-api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

[Unreleased]: https://github.com/MetaMask/accounts/
15 changes: 15 additions & 0 deletions packages/keyring-internal-api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# MetaMask Keyring Internal API

Keyring internal API that holds internal types and implementations.

## Installation

`yarn add @metamask/keyring-internal-api`

or

`npm install @metamask/keyring-internal-api`

## Contributing

This package is part of a monorepo. Instructions for contributing can be found in the [monorepo README](https://github.com/MetaMask/accounts#readme).
28 changes: 28 additions & 0 deletions packages/keyring-internal-api/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* For a detailed explanation regarding each configuration property and type check, visit:
* https://jestjs.io/docs/configuration
*/

const merge = require('deepmerge');
const path = require('path');

const baseConfig = require('../../jest.config.packages');

const displayName = path.basename(__dirname);

module.exports = merge(baseConfig, {
// The display name when running multiple projects
displayName,

coveragePathIgnorePatterns: ['./src/tests'],

// An object that configures minimum threshold enforcement for coverage results
coverageThreshold: {
global: {
branches: 100,
functions: 87.5,
lines: 94.69,
statements: 94.69

Check failure on line 25 in packages/keyring-internal-api/jest.config.js

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (18.x)

Insert `,`

Check failure on line 25 in packages/keyring-internal-api/jest.config.js

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (20.x)

Insert `,`
},
},
});
Loading
Loading