Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Gudahtt committed Jun 24, 2024
1 parent ca683e8 commit 4c98e69
Show file tree
Hide file tree
Showing 19 changed files with 1,177 additions and 6 deletions.
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ This repository contains the following packages [^fn1]:

<!-- start package list -->

- [`@metamask/accounts-controller`](packages/accounts-controller)
- [`@metamask/address-book-controller`](packages/address-book-controller)
- [`@metamask/announcement-controller`](packages/announcement-controller)
- [`@metamask/approval-controller`](packages/approval-controller)
Expand Down Expand Up @@ -42,6 +41,7 @@ This repository contains the following packages [^fn1]:
- [`@metamask/signature-controller`](packages/signature-controller)
- [`@metamask/transaction-controller`](packages/transaction-controller)
- [`@metamask/user-operation-controller`](packages/user-operation-controller)
- [`@metamask/wallet-framework`](packages/wallet-framework)

<!-- end package list -->

Expand All @@ -53,7 +53,6 @@ Or, in graph form [^fn1]:
%%{ init: { 'flowchart': { 'curve': 'bumpX' } } }%%
graph LR;
linkStyle default opacity:0.5
accounts_controller(["@metamask/accounts-controller"]);
address_book_controller(["@metamask/address-book-controller"]);
announcement_controller(["@metamask/announcement-controller"]);
approval_controller(["@metamask/approval-controller"]);
Expand Down Expand Up @@ -87,8 +86,7 @@ linkStyle default opacity:0.5
signature_controller(["@metamask/signature-controller"]);
transaction_controller(["@metamask/transaction-controller"]);
user_operation_controller(["@metamask/user-operation-controller"]);
accounts_controller --> base_controller;
accounts_controller --> keyring_controller;
wallet_framework(["@metamask/wallet-framework"]);
address_book_controller --> base_controller;
address_book_controller --> controller_utils;
announcement_controller --> base_controller;
Expand Down Expand Up @@ -161,11 +159,13 @@ linkStyle default opacity:0.5
signature_controller --> keyring_controller;
signature_controller --> logging_controller;
signature_controller --> message_manager;
transaction_controller --> accounts_controller;
transaction_controller --> approval_controller;
transaction_controller --> base_controller;
transaction_controller --> controller_utils;
transaction_controller --> gas_fee_controller;
transaction_controller --> network_controller;
transaction_controller --> eth_json_rpc_provider;
user_operation_controller --> approval_controller;
user_operation_controller --> base_controller;
user_operation_controller --> controller_utils;
Expand All @@ -174,6 +174,12 @@ linkStyle default opacity:0.5
user_operation_controller --> network_controller;
user_operation_controller --> polling_controller;
user_operation_controller --> transaction_controller;
wallet_framework --> approval_controller;
wallet_framework --> base_controller;
wallet_framework --> controller_utils;
wallet_framework --> json_rpc_engine;
wallet_framework --> keyring_controller;
wallet_framework --> permission_controller;
```

<!-- end dependency graph -->
Expand Down
19 changes: 19 additions & 0 deletions packages/permission-controller/src/PermissionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,18 @@ export type ClearPermissions = {
handler: () => void;
};

/**
* Execute a restricted method.
*
* @deprecated The permission middleware is intended to be the only place this is called. This was
* exposed as an action so that it could be used in a single legacy middleware function that needs
* to come before the permission middleware. Do not call this anywhere else.
*/
export type ExecuteRestructedMethod = {
type: `${typeof controllerName}:executeRestrictedMethod`;
handler: GenericPermissionController['executeRestrictedMethod'];
};

/**
* Gets the endowments for the given subject and permission.
*/
Expand All @@ -352,6 +364,7 @@ export type GetEndowments = {
*/
export type PermissionControllerActions =
| ClearPermissions
| ExecuteRestructedMethod
| GetEndowments
| GetPermissionControllerState
| GetSubjects
Expand Down Expand Up @@ -815,6 +828,12 @@ export class PermissionController<
() => this.clearState(),
);

this.messagingSystem.registerActionHandler(
`${controllerName}:executeRestrictedMethod` as const,
(...args: Parameters<typeof this.executeRestrictedMethod>) =>
this.executeRestrictedMethod(...args),
);

this.messagingSystem.registerActionHandler(
`${controllerName}:getEndowments` as const,
(origin: string, targetName: string, requestData?: unknown) =>
Expand Down
10 changes: 10 additions & 0 deletions packages/wallet-framework/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/core/
20 changes: 20 additions & 0 deletions packages/wallet-framework/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
MIT License

Copyright (c) 2024 MetaMask

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
15 changes: 15 additions & 0 deletions packages/wallet-framework/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# `@metamask/wallet-framework`

A framework for building MetaMask wallets.

## Installation

`yarn add @metamask/wallet-framework`

or

`npm install @metamask/wallet-framework`

## Contributing

This package is part of a monorepo. Instructions for contributing can be found in the [monorepo README](https://github.com/MetaMask/core#readme).
26 changes: 26 additions & 0 deletions packages/wallet-framework/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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,

// An object that configures minimum threshold enforcement for coverage results
coverageThreshold: {
global: {
branches: 100,
functions: 100,
lines: 100,
statements: 100,
},
},
});
70 changes: 70 additions & 0 deletions packages/wallet-framework/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"name": "@metamask/wallet-framework",
"version": "0.0.0",
"description": "A framework for building MetaMask wallets",
"keywords": [
"MetaMask",
"Ethereum"
],
"homepage": "https://github.com/MetaMask/core/tree/main/packages/wallet-framework#readme",
"bugs": {
"url": "https://github.com/MetaMask/core/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/MetaMask/core.git"
},
"license": "MIT",
"sideEffects": false,
"exports": {
".": {
"import": "./dist/index.mjs",
"require": "./dist/index.js",
"types": "./dist/types/index.d.ts"
},
"./package.json": "./package.json"
},
"main": "./dist/index.js",
"types": "./dist/types/index.d.ts",
"files": [
"dist/"
],
"scripts": {
"build": "tsup --config ../../tsup.config.ts --tsconfig ./tsconfig.build.json --clean",
"build:docs": "typedoc",
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/wallet-framework",
"publish:preview": "yarn npm publish --tag preview",
"test": "jest --reporters=jest-silent-reporter",
"test:clean": "jest --clearCache",
"test:verbose": "jest --verbose",
"test:watch": "jest --watch"
},
"dependencies": {
"@metamask/approval-controller": "^7.0.0",
"@metamask/base-controller": "^6.0.0",
"@metamask/controller-utils": "^11.0.0",
"@metamask/eth-json-rpc-middleware": "^12.1.1",
"@metamask/json-rpc-engine": "^9.0.0",
"@metamask/keyring-controller": "^17.1.0",
"@metamask/permission-controller": "^10.0.0",
"@metamask/rpc-errors": "^6.2.1",
"@metamask/utils": "^8.3.0"
},
"devDependencies": {
"@metamask/auto-changelog": "^3.4.4",
"@types/jest": "^27.4.1",
"deepmerge": "^4.2.2",
"jest": "^27.5.1",
"ts-jest": "^27.1.4",
"typedoc": "^0.24.8",
"typedoc-plugin-missing-exports": "^2.0.0",
"typescript": "~4.9.5"
},
"engines": {
"node": "^18.18 || >=20"
},
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org/"
}
}
Loading

0 comments on commit 4c98e69

Please sign in to comment.