diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 000000000..150642c73 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,3 @@ +# Snap packages use older tooling (Prettier v2, different configs). +# Formatting will be aligned in a follow-up. +packages/snaps/ diff --git a/README.md b/README.md index 7cc92fd36..93ff45d74 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,8 @@ This repository contains the following packages [^fn1]: - [`@metamask/keyring-snap-client`](packages/keyring-snap-client) - [`@metamask/keyring-snap-sdk`](packages/keyring-snap-sdk) - [`@metamask/keyring-utils`](packages/keyring-utils) +- [`@metamask/snap-simple-keyring-site`](packages/snaps/simple-keyring/packages/site) +- [`@metamask/snap-simple-keyring-snap`](packages/snaps/simple-keyring/packages/snap) @@ -61,6 +63,8 @@ linkStyle default opacity:0.5 keyring_snap_client(["@metamask/keyring-snap-client"]); keyring_snap_sdk(["@metamask/keyring-snap-sdk"]); keyring_utils(["@metamask/keyring-utils"]); + snap_simple_keyring_site(["@metamask/snap-simple-keyring-site"]); + snap_simple_keyring_snap(["@metamask/snap-simple-keyring-snap"]); account_api --> keyring_api; account_api --> keyring_utils; keyring_api --> keyring_utils; @@ -107,6 +111,10 @@ linkStyle default opacity:0.5 keyring_snap_client --> keyring_utils; keyring_snap_sdk --> keyring_utils; keyring_snap_sdk --> keyring_api; + snap_simple_keyring_site --> keyring_api; + snap_simple_keyring_site --> keyring_snap_client; + snap_simple_keyring_snap --> keyring_api; + snap_simple_keyring_snap --> keyring_snap_sdk; ``` diff --git a/eslint.config.mjs b/eslint.config.mjs index 4d49bdaa8..845c9eddd 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -16,6 +16,9 @@ const config = createConfig([ '**/dist/**', '**/docs/**', '**/coverage/**', + // Snap packages use older tooling (ESLint v8, different configs). + // Linting will be aligned in a follow-up. + 'packages/snaps/**', ], }, diff --git a/package.json b/package.json index 857d9f47e..a6f0f5eac 100644 --- a/package.json +++ b/package.json @@ -8,12 +8,16 @@ "url": "https://github.com/MetaMask/accounts.git" }, "workspaces": [ + "packages/snaps/*/packages/*", + "packages/snaps/*", "packages/*" ], "files": [], "scripts": { "build": "ts-bridge --project tsconfig.build.json", "build:clean": "yarn build --clean", + "build:snaps": "yarn build:snaps:deps && yarn workspaces foreach --all --include '@metamask/snap-simple-keyring' --parallel --verbose run build", + "build:snaps:deps": "yarn workspaces foreach --all --include '@metamask/keyring-utils' --include '@metamask/keyring-api' --include '@metamask/keyring-snap-sdk' --include '@metamask/keyring-snap-client' --topological --verbose run build", "build:docs": "yarn foreach build:docs", "build:only-clean": "rimraf -g 'packages/*/dist'", "build:types": "tsc --build tsconfig.build.json --verbose", @@ -24,7 +28,7 @@ "lint:dependencies:fix": "yarn foreach depcheck && yarn dedupe", "lint:eslint": "yarn build:only-clean && yarn eslint", "lint:fix": "yarn lint:eslint --fix --prune-suppressions && yarn lint:misc --write && yarn constraints --fix && yarn lint:dependencies:fix", - "lint:misc": "oxfmt --ignore-path .gitignore", + "lint:misc": "oxfmt --ignore-path .gitignore --ignore-path .prettierignore", "lint:misc:check": "yarn lint:misc --check", "lint:readme": "yarn readme:update", "prepare:preview": "ts-node --project tsconfig.scripts.json scripts/prepare-preview-builds.ts", diff --git a/packages/snaps/simple-keyring/.depcheckrc.json b/packages/snaps/simple-keyring/.depcheckrc.json new file mode 100644 index 000000000..f2c4bf58c --- /dev/null +++ b/packages/snaps/simple-keyring/.depcheckrc.json @@ -0,0 +1,3 @@ +{ + "ignore-patterns": [".yarn/"] +} diff --git a/packages/snaps/simple-keyring/.eslintrc.js b/packages/snaps/simple-keyring/.eslintrc.js new file mode 100644 index 000000000..962a8b890 --- /dev/null +++ b/packages/snaps/simple-keyring/.eslintrc.js @@ -0,0 +1,44 @@ +module.exports = { + root: true, + + extends: ['@metamask/eslint-config'], + + overrides: [ + { + files: ['*.ts', '*.tsx'], + extends: ['@metamask/eslint-config-typescript'], + rules: { + // This prevents using Node.js and/or browser specific globals. We + // currently use both in our codebase, so this rule is disabled. + 'no-restricted-globals': 'off', + 'spaced-comment': ['error', 'always', { markers: ['/'] }], + }, + }, + + { + files: ['*.js', '*.jsx', '*.cjs'], + extends: ['@metamask/eslint-config-nodejs'], + }, + + { + files: ['*.test.ts', '*.test.js'], + extends: [ + '@metamask/eslint-config-jest', + '@metamask/eslint-config-nodejs', + ], + }, + ], + + rules: { + // This is necessary to run eslint on Windows and not get a thousand CRLF errors + 'prettier/prettier': ['error', { endOfLine: 'auto' }], + }, + + ignorePatterns: [ + '!.eslintrc.js', + '!.prettierrc.js', + 'dist/', + 'docs/', + '.yarn/', + ], +}; diff --git a/packages/snaps/simple-keyring/.gitignore b/packages/snaps/simple-keyring/.gitignore new file mode 100644 index 000000000..a8bc3759a --- /dev/null +++ b/packages/snaps/simple-keyring/.gitignore @@ -0,0 +1,86 @@ +.DS_Store +dist/ +build/ +coverage/ + +# We have to ignore files in the root .gitignore file because it's also used by +# prettier, which doesn't support nested .gitignore files. +/packages/site/.cache/ +/packages/site/public/ + +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Microbundle cache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env +.env.test + +# Stores VSCode versions used for testing VSCode extensions +.vscode-test + +# yarn v3 (w/o zero-install) +# See: https://yarnpkg.com/getting-started/qa#which-files-should-be-gitignored +.pnp.* +.yarn/* +!.yarn/patches +!.yarn/plugins +!.yarn/releases +!.yarn/sdks +!.yarn/versions + +# IntelliJ +.idea/ diff --git a/packages/snaps/simple-keyring/.prettierrc.js b/packages/snaps/simple-keyring/.prettierrc.js new file mode 100644 index 000000000..52d68f711 --- /dev/null +++ b/packages/snaps/simple-keyring/.prettierrc.js @@ -0,0 +1,9 @@ +// All of these are defaults except singleQuote, but we specify them +// for explicitness +module.exports = { + endOfLine: 'auto', + quoteProps: 'as-needed', + singleQuote: true, + tabWidth: 2, + trailingComma: 'all', +}; diff --git a/packages/snaps/simple-keyring/.yarn/patches/@noble-hashes-npm-1.7.1-4106ab26c5.patch b/packages/snaps/simple-keyring/.yarn/patches/@noble-hashes-npm-1.7.1-4106ab26c5.patch new file mode 100644 index 000000000..f512995b7 --- /dev/null +++ b/packages/snaps/simple-keyring/.yarn/patches/@noble-hashes-npm-1.7.1-4106ab26c5.patch @@ -0,0 +1,27 @@ +diff --git a/esm/cryptoNode.js b/esm/cryptoNode.js +index 4f77e8f46c5e242e1e3cb92712dc65e95a8b8eb0..acd05d884061e18adf27d33ba4a1c55e9cc85e7f 100644 +--- a/esm/cryptoNode.js ++++ b/esm/cryptoNode.js +@@ -7,9 +7,19 @@ + */ + // @ts-ignore + import * as nc from 'node:crypto'; +-export const crypto = nc && typeof nc === 'object' && 'webcrypto' in nc +- ? nc.webcrypto +- : nc && typeof nc === 'object' && 'randomBytes' in nc ++// It seems `webpack` is not able to resolve `nc.webcrypto` at build time. Probably because ++// we use `crypto-browserify` under the hood, and this package does not expose `webcrypto`. ++// While this work when using `require` imports, it seems to fail with ESM exports (at least ++// in this case). ++// export const crypto = nc && typeof nc === 'object' && 'webcrypto' in nc ++// ? nc.webcrypto ++// : nc && typeof nc === 'object' && 'randomBytes' in nc ++// ? nc ++// : undefined; ++ ++// We just fallback to the "normal crypto" object to workaround this. ++export const crypto = ++ nc && typeof nc === 'object' && 'randomBytes' in nc + ? nc + : undefined; + //# sourceMappingURL=cryptoNode.js.map diff --git a/packages/snaps/simple-keyring/LICENSE.APACHE2 b/packages/snaps/simple-keyring/LICENSE.APACHE2 new file mode 100644 index 000000000..49966a712 --- /dev/null +++ b/packages/snaps/simple-keyring/LICENSE.APACHE2 @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2022 ConsenSys Software Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/packages/snaps/simple-keyring/LICENSE.MIT0 b/packages/snaps/simple-keyring/LICENSE.MIT0 new file mode 100644 index 000000000..74e1d3df7 --- /dev/null +++ b/packages/snaps/simple-keyring/LICENSE.MIT0 @@ -0,0 +1,16 @@ +MIT No Attribution + +Copyright 2022 ConsenSys Software Inc. + +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. + +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 SOFTWARE. diff --git a/packages/snaps/simple-keyring/README.md b/packages/snaps/simple-keyring/README.md new file mode 100644 index 000000000..85e8cab1e --- /dev/null +++ b/packages/snaps/simple-keyring/README.md @@ -0,0 +1,148 @@ +# Simple Keyring Snap + +This repository contains a simple example of a keyring snap. + +Keyring snaps enable developers to enhance MetaMask by adding new account +types. These accounts are natively supported within the extension, appearing in +MetaMask's UI, and can be used with dapps. + +MetaMask Snaps is a system that allows anyone to safely expand the capabilities +of MetaMask. A _snap_ is a program that we run in an isolated environment that +can customize the wallet experience. + +## Snaps is pre-release software + +To interact with (your) Snaps, you will need to install [MetaMask +Flask](https://metamask.io/flask/), a canary distribution for developers that +provides access to upcoming features. + +## Getting Started + +Clone the template-snap repository [using this +template](https://github.com/MetaMask/template-snap-monorepo/generate) and +setup the development environment: + +```shell +yarn install && yarn start +``` + +## Cloning + +This repository contains GitHub Actions that you may find useful, see +`.github/workflows` and [Releasing & +Publishing](https://github.com/MetaMask/template-snap-monorepo/edit/main/README.md#releasing--publishing) +below for more information. + +If you clone or create this repository outside the MetaMask GitHub +organization, you probably want to run `./scripts/cleanup.sh` to remove some +files that will not work properly outside the MetaMask GitHub organization. + +Note that the `action-publish-release.yml` workflow contains a step that +publishes the frontend of this snap (contained in the `public/` directory) to +GitHub pages. If you do not want to publish the frontend to GitHub pages, +simply remove the step named "Publish to GitHub Pages" in that workflow. + +If you don't wish to use any of the existing GitHub actions in this repository, +simply delete the `.github/workflows` directory. + +## Contributing + +### Testing and Linting + +Run `yarn test` to run the tests once. + +Run `yarn lint` to run the linter, or run `yarn lint:fix` to run the linter and +fix any automatically fixable issues. + +### Releasing & Publishing + +The project follows the same release process as the other libraries in the +MetaMask organization. The GitHub Actions +[`action-create-release-pr`](https://github.com/MetaMask/action-create-release-pr) +and +[`action-publish-release`](https://github.com/MetaMask/action-publish-release) +are used to automate the release process; see those repositories for more +information about how they work. + +1. Choose a release version. + + - The release version should be chosen according to SemVer. Analyze the + changes to see whether they include any breaking changes, new features, or + deprecations, then choose the appropriate SemVer version. See [the SemVer + specification](https://semver.org/) for more information. + +2. If this release is backporting changes onto a previous release, then ensure + there is a major version branch for that version (e.g. `1.x` for a `v1` + backport release). + + - The major version branch should be set to the most recent release with + that major version. For example, when backporting a `v1.0.2` release, + you'd want to ensure there was a `1.x` branch that was set to the `v1.0.1` + tag. + +3. Trigger the + [`workflow_dispatch`](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#workflow_dispatch) + event + [manually](https://docs.github.com/en/actions/managing-workflow-runs/manually-running-a-workflow) + for the `Create Release Pull Request` action to create the release PR. + + - For a backport release, the base branch should be the major version branch + that you ensured existed in step 2. For a normal release, the base branch + should be the main branch for that repository (which should be the default + value). + + - This should trigger the + [`action-create-release-pr`](https://github.com/MetaMask/action-create-release-pr) + workflow to create the release PR. + +4. Update the changelog to move each change entry into the appropriate change + category ([See here](https://keepachangelog.com/en/1.0.0/#types) for the + full list of change categories, and the correct ordering), and edit them to + be more easily understood by users of the package. + + - Generally any changes that don't affect consumers of the package (e.g. + lockfile changes or development environment changes) are omitted. + Exceptions may be made for changes that might be of interest despite not + having an effect upon the published package (e.g. major test improvements, + security improvements, improved documentation, etc.). + + - Try to explain each change in terms that users of the package would + understand (e.g. avoid referencing internal variables/concepts). + + - Consolidate related changes into one change entry if it makes it easier to + explain. + + - Run `yarn auto-changelog validate --rc` to check that the changelog is + correctly formatted. + +5. Review and QA the release. + + - If changes are made to the base branch, the release branch will need to be + updated with these changes and review/QA will need to restart again. As + such, it's probably best to avoid merging other PRs into the base branch + while review is underway. + +6. Squash & Merge the release. + + - This should trigger the + [`action-publish-release`](https://github.com/MetaMask/action-publish-release) + workflow to tag the final release commit and publish the release on + GitHub. + +7. Publish the release on npm. + + - Be very careful to use a clean local environment to publish the release, + and follow exactly the same steps used during CI. + + - Use `npm publish --dry-run` to examine the release contents to ensure the + correct files are included. Compare to previous releases if necessary + (e.g. using `https://unpkg.com/browse/[package name]@[package version]/`). + + - Once you are confident the release contents are correct, publish the + release using `npm publish`. + +## Notes + +- Babel is used for transpiling TypeScript to JavaScript, so when building with + the CLI, `transpilationMode` must be set to `localOnly` (default) or + `localAndDeps`. diff --git a/packages/snaps/simple-keyring/package.json b/packages/snaps/simple-keyring/package.json new file mode 100644 index 000000000..dfe8b0d60 --- /dev/null +++ b/packages/snaps/simple-keyring/package.json @@ -0,0 +1,64 @@ +{ + "name": "@metamask/snap-simple-keyring", + "private": true, + "description": "A simple keyring snap that integrates with MetaMask accounts.", + "keywords": [ + "metamask", + "snap", + "keyring", + "account" + ], + "homepage": "https://github.com/MetaMask/accounts/tree/main/packages/snaps/simple-keyring#readme", + "bugs": { + "url": "https://github.com/MetaMask/accounts/issues" + }, + "license": "(MIT-0 OR Apache-2.0)", + "repository": { + "type": "git", + "url": "https://github.com/MetaMask/accounts.git" + }, + "workspaces": [ + "packages/*" + ], + "scripts": { + "build": "yarn workspaces foreach --worktree --parallel --verbose --no-private run build", + "build:clean": "yarn clean && yarn build", + "clean": "yarn workspaces foreach --worktree --parallel --verbose --no-private run clean", + "lint": "yarn workspaces foreach --worktree --parallel --verbose --interlaced --no-private run lint && yarn lint:dependencies", + "lint:dependencies": "depcheck", + "lint:eslint": "eslint . --cache", + "lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write", + "lint:misc": "prettier --no-error-on-unmatched-pattern --log-level warn \"**/*.json\" \"**/*.md\" \"!packages/**\" --ignore-path ../../.gitignore", + "lint:types": "yarn workspaces foreach --worktree --parallel --verbose --no-private run lint:types", + "since-latest-release": "../../scripts/since-latest-release.sh", + "start": "yarn workspaces foreach --worktree --parallel --interlaced --no-private --jobs unlimited run start", + "test": "yarn workspaces foreach --worktree --parallel --verbose --no-private run test", + "test:verbose": "yarn workspaces foreach --worktree --parallel --verbose --no-private run test:verbose", + "test:watch": "yarn workspaces foreach --worktree --parallel --verbose --no-private run test:watch" + }, + "devDependencies": { + "@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", + "@typescript-eslint/eslint-plugin": "^5.55.0", + "@typescript-eslint/parser": "^5.55.0", + "depcheck": "^1.4.7", + "eslint": "^8.36.0", + "eslint-config-prettier": "^8.7.0", + "eslint-plugin-import": "^2.27.5", + "eslint-plugin-jest": "^27.2.1", + "eslint-plugin-jsdoc": "^40.0.3", + "eslint-plugin-n": "^16.1.0", + "eslint-plugin-prettier": "^4.2.1", + "eslint-plugin-promise": "^6.1.1", + "prettier": "^2.8.4", + "typescript": "^4.9.5" + }, + "engines": { + "node": "^18.18 || >=20" + }, + "installConfig": { + "hoistingLimits": "workspaces" + } +} diff --git a/packages/snaps/simple-keyring/packages/site/.depcheckrc.json b/packages/snaps/simple-keyring/packages/site/.depcheckrc.json new file mode 100644 index 000000000..7baf94785 --- /dev/null +++ b/packages/snaps/simple-keyring/packages/site/.depcheckrc.json @@ -0,0 +1,10 @@ +{ + "ignore-patterns": [".cache/"], + "ignores": [ + "@metamask/auto-changelog", + "@svgr/webpack", + "gatsby-plugin-*", + "react-scripts", + "raw-loader" + ] +} diff --git a/packages/snaps/simple-keyring/packages/site/.env.production b/packages/snaps/simple-keyring/packages/site/.env.production new file mode 100644 index 000000000..e31e26dde --- /dev/null +++ b/packages/snaps/simple-keyring/packages/site/.env.production @@ -0,0 +1 @@ +SNAP_ORIGIN=npm:@metamask/snap-simple-keyring-snap diff --git a/packages/snaps/simple-keyring/packages/site/.eslintrc.js b/packages/snaps/simple-keyring/packages/site/.eslintrc.js new file mode 100644 index 000000000..ca60fe59a --- /dev/null +++ b/packages/snaps/simple-keyring/packages/site/.eslintrc.js @@ -0,0 +1,5 @@ +module.exports = { + extends: ['../../.eslintrc.js'], + + ignorePatterns: ['!.eslintrc.js', '.cache/', 'public/'], +}; diff --git a/packages/snaps/simple-keyring/packages/site/.prettierignore b/packages/snaps/simple-keyring/packages/site/.prettierignore new file mode 100644 index 000000000..6f4cc1469 --- /dev/null +++ b/packages/snaps/simple-keyring/packages/site/.prettierignore @@ -0,0 +1,2 @@ +.cache/ +public/ diff --git a/packages/snaps/simple-keyring/packages/site/CHANGELOG.md b/packages/snaps/simple-keyring/packages/site/CHANGELOG.md new file mode 100644 index 000000000..a748e8845 --- /dev/null +++ b/packages/snaps/simple-keyring/packages/site/CHANGELOG.md @@ -0,0 +1,206 @@ +# 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] + +## [2.1.1] + +### Changed + +- Bump bundled snap version reference from `@metamask/snap-simple-keyring-snap@2.0.1` to `@metamask/snap-simple-keyring-snap@2.1.0` ([#178](https://github.com/MetaMask/snap-simple-keyring/pull/178)) + - The site embeds the snap's `package.json` version at build time, so this republish is required for consumers to install the new snap version through the dapp. + +## [2.0.1] + +### Changed + +- Bump `@metamask/keyring-api` from `^8.1.3` to `^23.1.0` ([#169](https://github.com/MetaMask/snap-simple-keyring/pull/169), [#173](https://github.com/MetaMask/snap-simple-keyring/pull/173)) +- Bump `@metamask/keyring-snap-client` from `^8.0.0` to `^9.0.2` ([#173](https://github.com/MetaMask/snap-simple-keyring/pull/173)) +- Bump `@metamask/providers` from `^13.0.0` to `^19.0.0` ([#173](https://github.com/MetaMask/snap-simple-keyring/pull/173)) +- Use new font Geist ([#172](https://github.com/MetaMask/snap-simple-keyring/pull/172)) + +## [2.0.0] + +### Changed + +- Make @metamask/snap-simple-keyring-site publishable ([#163](https://github.com/MetaMask/snap-simple-keyring/pull/163), [#166](https://github.com/MetaMask/snap-simple-keyring/pull/166)) +- Use new CentraNo1 font ([#160](https://github.com/MetaMask/snap-simple-keyring/pull/160)) +- Bump `crypto-browserify@^3.12.1` + `snaps-*` ([#159](https://github.com/MetaMask/snap-simple-keyring/pull/159)) + +## [1.1.6] + +### Changed + +- Bump `@metamask/keyring-api` from `^1.0.0-rc.1` to `^8.1.3` ([#155](https://github.com/MetaMask/snap-simple-keyring/pull/155)) + - This version is now built slightly differently and is part of the [accounts monorepo](https://github.com/MetaMask/accounts). + +## [1.1.2] + +### Changed + +- Hardcode light mode ([#138](https://github.com/MetaMask/snap-simple-keyring/pull/138)) + +## [1.1.1] + +### Changed + +- Add ID for E2E test ([#130](https://github.com/MetaMask/snap-simple-keyring/pull/130)) + +## [1.1.0] + +### Added + +- Add delete button to account ([#117](https://github.com/MetaMask/snap-simple-keyring/pull/117)). +- Add "Update Account" to companion dapp ([#118](https://github.com/MetaMask/snap-simple-keyring/pull/118)). + +### Changed + +- Add parenthesis around details of the Snap version ([#123](https://github.com/MetaMask/snap-simple-keyring/pull/123)). +- Move "Delete" button into account details ([#121](https://github.com/MetaMask/snap-simple-keyring/pull/121)). +- Move "Delete" button into account details ([#122](https://github.com/MetaMask/snap-simple-keyring/pull/122)). +- Change `packageInfo` to `snapPackageInfo` ([#114](https://github.com/MetaMask/snap-simple-keyring/pull/114)). + +### Fixed + +- Remove cache before building site ([#124](https://github.com/MetaMask/snap-simple-keyring/pull/124)). +- Use `stretch` as default alignment in `AccountRow` ([#120](https://github.com/MetaMask/snap-simple-keyring/pull/120)). +- Use the Snap `package.json` for the update check ([#112](https://github.com/MetaMask/snap-simple-keyring/pull/112)). + +## [1.0.0] + +### Added + +- Add alert banner for users ([#104](https://github.com/MetaMask/snap-simple-keyring/pull/104)). + +## [0.4.0] + +## [0.3.1] + +### Changed + +- Allow Snap to be installed in MetaMask Stable ([#101](https://github.com/MetaMask/snap-simple-keyring/pull/101)). + +## [0.3.0] + +### Changed + +- **BREAKING:** Use `onKeyringRequest` to handle keyring methods ([#97](https://github.com/MetaMask/snap-simple-keyring/pull/97)). + +## [0.2.4] + +### Added + +- Add update button ([#93](https://github.com/MetaMask/snap-simple-keyring/pull/93)). + +### Fixed + +- Fix the list of accounts not being displayed on the first load ([#92](https://github.com/MetaMask/snap-simple-keyring/pull/92)). +- Fix the private key format in the import account placeholder ([#89](https://github.com/MetaMask/snap-simple-keyring/pull/89)). +- Check if the snap is installed before trying to get its state ([#87](https://github.com/MetaMask/snap-simple-keyring/pull/87)). +- Remove `console.log` if snap is not installed ([#88](https://github.com/MetaMask/snap-simple-keyring/pull/88)). + +## [0.2.3] + +### Changed + +- Use text fields in account methods inputs ([#82](https://github.com/MetaMask/snap-simple-keyring/pull/82)). +- Update linting targets ([#85](https://github.com/MetaMask/snap-simple-keyring/pull/85)). +- Update Gatsby to version 5 ([#83](https://github.com/MetaMask/snap-simple-keyring/pull/83)). +- Enable linters and fix errors ([#81](https://github.com/MetaMask/snap-simple-keyring/pull/81)). + +### Fixed + +- Serve self-hosted fonts ([#80](https://github.com/MetaMask/snap-simple-keyring/pull/80)). + +## [0.2.2] + +### Added + +- Let the dapp specifies the Snap version to install ([#72](https://github.com/MetaMask/snap-simple-keyring/pull/72)). +- Add dapp version to header ([#71](https://github.com/MetaMask/snap-simple-keyring/pull/71)). + +### Fixed + +- Disable async-sync toggle if snap is not installed ([#77](https://github.com/MetaMask/snap-simple-keyring/pull/77)). + +## [0.2.1] + +### Changed + +- Align button and request result with action name ([#66](https://github.com/MetaMask/snap-simple-keyring/pull/66)). +- Remove account name and improve some UI components ([#65](https://github.com/MetaMask/snap-simple-keyring/pull/65)). +- Migrate to new `keyring-api` version (0.2.x) ([#64](https://github.com/MetaMask/snap-simple-keyring/pull/64)). +- Polyfill crypto dependency introduced in `metamask-utils` 6.2.0 ([#62](https://github.com/MetaMask/snap-simple-keyring/pull/62)). + +## [0.2.0] + +### Added + +- Support the async approval flow ([#50](https://github.com/MetaMask/snap-simple-keyring/pull/50)). +- Import account ([#58](https://github.com/MetaMask/snap-simple-keyring/pull/58)). + +### Changed + +- Improve UI/UX ([#54](https://github.com/MetaMask/snap-simple-keyring/pull/54)). + +### Fixed + +- Now you don't have to change your `defaultSnapOrigin` ([#59](https://github.com/MetaMask/snap-simple-keyring/pull/59)). + +## [0.1.4] + +### Fixed + +- Fix `rejectRequest` call in site package ([#53](https://github.com/MetaMask/snap-simple-keyring/pull/53)). + +## [0.1.3] + +### Changed + +- No changes in this release. + +## [0.1.2] + +### Changed + +- Update snaps and API dependencies. ([#41](https://github.com/MetaMask/snap-simple-keyring/pull/41)). +- Add IDs for e2e tests. ([#40](https://github.com/MetaMask/snap-simple-keyring/pull/40)). + +## [0.1.1] - 2023-06-23 + +### Changed + +- No changes in this release. + +## [0.1.0] - 2023-06-22 + +### Added + +- Initial release. + +[Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/snap-simple-keyring-site@2.1.1...HEAD +[2.1.1]: https://github.com/MetaMask/accounts/compare/@metamask/snap-simple-keyring-site@2.0.1...@metamask/snap-simple-keyring-site@2.1.1 +[2.0.1]: https://github.com/MetaMask/accounts/compare/@metamask/snap-simple-keyring-site@2.0.0...@metamask/snap-simple-keyring-site@2.0.1 +[2.0.0]: https://github.com/MetaMask/accounts/compare/@metamask/snap-simple-keyring-site@1.1.6...@metamask/snap-simple-keyring-site@2.0.0 +[1.1.6]: https://github.com/MetaMask/accounts/compare/@metamask/snap-simple-keyring-site@1.1.2...@metamask/snap-simple-keyring-site@1.1.6 +[1.1.2]: https://github.com/MetaMask/accounts/compare/@metamask/snap-simple-keyring-site@1.1.1...@metamask/snap-simple-keyring-site@1.1.2 +[1.1.1]: https://github.com/MetaMask/accounts/compare/@metamask/snap-simple-keyring-site@1.1.0...@metamask/snap-simple-keyring-site@1.1.1 +[1.1.0]: https://github.com/MetaMask/accounts/compare/@metamask/snap-simple-keyring-site@1.0.0...@metamask/snap-simple-keyring-site@1.1.0 +[1.0.0]: https://github.com/MetaMask/accounts/compare/@metamask/snap-simple-keyring-site@0.4.0...@metamask/snap-simple-keyring-site@1.0.0 +[0.4.0]: https://github.com/MetaMask/accounts/compare/@metamask/snap-simple-keyring-site@0.3.1...@metamask/snap-simple-keyring-site@0.4.0 +[0.3.1]: https://github.com/MetaMask/accounts/compare/@metamask/snap-simple-keyring-site@0.3.0...@metamask/snap-simple-keyring-site@0.3.1 +[0.3.0]: https://github.com/MetaMask/accounts/compare/@metamask/snap-simple-keyring-site@0.2.4...@metamask/snap-simple-keyring-site@0.3.0 +[0.2.4]: https://github.com/MetaMask/accounts/compare/@metamask/snap-simple-keyring-site@0.2.3...@metamask/snap-simple-keyring-site@0.2.4 +[0.2.3]: https://github.com/MetaMask/accounts/compare/@metamask/snap-simple-keyring-site@0.2.2...@metamask/snap-simple-keyring-site@0.2.3 +[0.2.2]: https://github.com/MetaMask/accounts/compare/@metamask/snap-simple-keyring-site@0.2.1...@metamask/snap-simple-keyring-site@0.2.2 +[0.2.1]: https://github.com/MetaMask/accounts/compare/@metamask/snap-simple-keyring-site@0.2.0...@metamask/snap-simple-keyring-site@0.2.1 +[0.2.0]: https://github.com/MetaMask/accounts/compare/@metamask/snap-simple-keyring-site@0.1.4...@metamask/snap-simple-keyring-site@0.2.0 +[0.1.4]: https://github.com/MetaMask/accounts/compare/@metamask/snap-simple-keyring-site@0.1.3...@metamask/snap-simple-keyring-site@0.1.4 +[0.1.3]: https://github.com/MetaMask/accounts/compare/@metamask/snap-simple-keyring-site@0.1.2...@metamask/snap-simple-keyring-site@0.1.3 +[0.1.2]: https://github.com/MetaMask/accounts/compare/@metamask/snap-simple-keyring-site@0.1.1...@metamask/snap-simple-keyring-site@0.1.2 +[0.1.1]: https://github.com/MetaMask/accounts/compare/@metamask/snap-simple-keyring-site@0.1.0...@metamask/snap-simple-keyring-site@0.1.1 +[0.1.0]: https://github.com/MetaMask/accounts/releases/tag/@metamask/snap-simple-keyring-site@0.1.0 diff --git a/packages/snaps/simple-keyring/packages/site/README.md b/packages/snaps/simple-keyring/packages/site/README.md new file mode 100644 index 000000000..f6f0748ba --- /dev/null +++ b/packages/snaps/simple-keyring/packages/site/README.md @@ -0,0 +1,43 @@ +# TypeScript Example Snap Front-end + +This project was bootstrapped with [Gatsby](https://www.gatsbyjs.com/). + +## Available Scripts + +In the project directory, you can run: + +### `yarn start` + +Runs the app in the development mode.\ +Open [http://localhost:8000](http://localhost:8000) to view it in the browser. + +The page will reload if you make edits.\ +You will also see any lint errors in the console. + +### `yarn build` + +Builds the app for production to the `public` folder.\ +It correctly bundles React in production mode and optimizes the build for the best performance. + +The build is minified and the filenames include the hashes.\ +Your app is ready to be deployed! + +See the section about [deployment](https://www.gatsbyjs.com/docs/how-to/previews-deploys-hosting/) for more information. + +## Environment variables + +Gatsby has built-in support for loading environment variables into the browser and Functions. Loading environment variables into Node.js requires a small code snippet. + +In development, Gatsby will load environment variables from a file named `.env.development`. For builds, it will load from `.env.production`. + +By default you can use the `SNAP_ORIGIN` variable (used in `src/config/snap.ts`) to define a production origin for you snap (eg. `npm:MyPackageName`). If not defined it will defaults to `local:http://localhost:8080`. + +A `.env` file template is available, to use it rename `.env.production.dist` to `.env.production` + +To learn more visit [Gatsby documentation](https://www.gatsbyjs.com/docs/how-to/local-development/environment-variables/) + +## Learn More + +You can learn more in the [Gatsby documentation](https://www.gatsbyjs.com/docs/). + +To learn React, check out the [React documentation](https://reactjs.org/). diff --git a/packages/snaps/simple-keyring/packages/site/fonts/Geist-Bold.woff2 b/packages/snaps/simple-keyring/packages/site/fonts/Geist-Bold.woff2 new file mode 100644 index 000000000..39a964169 Binary files /dev/null and b/packages/snaps/simple-keyring/packages/site/fonts/Geist-Bold.woff2 differ diff --git a/packages/snaps/simple-keyring/packages/site/fonts/Geist-BoldItalic.woff2 b/packages/snaps/simple-keyring/packages/site/fonts/Geist-BoldItalic.woff2 new file mode 100644 index 000000000..b1f55a945 Binary files /dev/null and b/packages/snaps/simple-keyring/packages/site/fonts/Geist-BoldItalic.woff2 differ diff --git a/packages/snaps/simple-keyring/packages/site/fonts/Geist-Medium.woff2 b/packages/snaps/simple-keyring/packages/site/fonts/Geist-Medium.woff2 new file mode 100644 index 000000000..eb368a006 Binary files /dev/null and b/packages/snaps/simple-keyring/packages/site/fonts/Geist-Medium.woff2 differ diff --git a/packages/snaps/simple-keyring/packages/site/fonts/Geist-MediumItalic.woff2 b/packages/snaps/simple-keyring/packages/site/fonts/Geist-MediumItalic.woff2 new file mode 100644 index 000000000..9f6a5bac8 Binary files /dev/null and b/packages/snaps/simple-keyring/packages/site/fonts/Geist-MediumItalic.woff2 differ diff --git a/packages/snaps/simple-keyring/packages/site/fonts/Geist-Regular.woff2 b/packages/snaps/simple-keyring/packages/site/fonts/Geist-Regular.woff2 new file mode 100644 index 000000000..dc080c9c4 Binary files /dev/null and b/packages/snaps/simple-keyring/packages/site/fonts/Geist-Regular.woff2 differ diff --git a/packages/snaps/simple-keyring/packages/site/fonts/Geist-RegularItalic.woff2 b/packages/snaps/simple-keyring/packages/site/fonts/Geist-RegularItalic.woff2 new file mode 100644 index 000000000..e27caa218 Binary files /dev/null and b/packages/snaps/simple-keyring/packages/site/fonts/Geist-RegularItalic.woff2 differ diff --git a/packages/snaps/simple-keyring/packages/site/gatsby-browser.tsx b/packages/snaps/simple-keyring/packages/site/gatsby-browser.tsx new file mode 100644 index 000000000..a9ca68626 --- /dev/null +++ b/packages/snaps/simple-keyring/packages/site/gatsby-browser.tsx @@ -0,0 +1,17 @@ +import type { GatsbyBrowser } from 'gatsby'; +import React, { StrictMode } from 'react'; + +import { App } from './src/App'; +import { Root } from './src/Root'; + +export const wrapRootElement: GatsbyBrowser['wrapRootElement'] = ({ + element, +}) => ( + + {element} + +); + +export const wrapPageElement: GatsbyBrowser['wrapPageElement'] = ({ + element, +}) => {element}; diff --git a/packages/snaps/simple-keyring/packages/site/gatsby-config.ts b/packages/snaps/simple-keyring/packages/site/gatsby-config.ts new file mode 100644 index 000000000..79a7bb850 --- /dev/null +++ b/packages/snaps/simple-keyring/packages/site/gatsby-config.ts @@ -0,0 +1,136 @@ +/* eslint-disable @typescript-eslint/naming-convention */ +import type { GatsbyConfig } from 'gatsby'; + +const config: GatsbyConfig = { + // This is required to make use of the React 17+ JSX transform. + jsxRuntime: 'automatic', + + pathPrefix: process.env.GATSBY_PATH_PREFIX ?? '/', + + plugins: [ + 'gatsby-plugin-svgr', + 'gatsby-plugin-styled-components', + { + resolve: 'gatsby-plugin-manifest', + options: { + name: 'Template Snap', + theme_color: '#6F4CFF', + background_color: '#FFFFFF', + display: 'standalone', + // Pre-built icons avoid sharp (native binary) which can't run its + // install script in the monorepo's isolated node_modules. Regenerate + // from src/assets/logo.svg if the icon changes. + icons: [ + { + src: 'icons/icon-192.png', + sizes: '192x192', + type: 'image/png', + }, + { + src: 'icons/icon-512.png', + sizes: '512x512', + type: 'image/png', + }, + ], + }, + }, + { + // See: + resolve: `gatsby-plugin-webfonts`, + options: { + fonts: { + google: [ + { + family: 'Roboto Mono', + variants: ['400'], + }, + ], + selfHosted: [ + // Common weight name mapping + // + // 100 - Thin (Hairline) + // 200 - Extra Light (Ultra Light) + // 300 - Light + // 400 - Normal (Regular) + // 500 - Medium + // 600 - Semi Bold (Demi Bold) + // 700 - Bold + // 800 - Extra Bold (Ultra Bold) + // 900 - Black (Heavy) + // 950 - Extra Black (Ultra Black) + // + // See: + + // ---------------------------------------------------------------- + // Regular + { + family: 'Geist', + urls: { + woff2: `fonts/Geist-Regular.woff2`, + }, + fontStyle: 'normal', + fontWeight: 400, + }, + + // ---------------------------------------------------------------- + // Regular Italic + { + family: 'Geist', + urls: { + woff2: `fonts/Geist-RegularItalic.woff2`, + }, + fontStyle: 'italic', + fontWeight: 400, + }, + + // ---------------------------------------------------------------- + // Medium + { + family: 'Geist', + urls: { + woff2: `fonts/Geist-Medium.woff2`, + }, + fontStyle: 'normal', + fontWeight: 500, + }, + + // ---------------------------------------------------------------- + // Medium Italic + { + family: 'Geist', + urls: { + woff2: `fonts/Geist-MediumItalic.woff2`, + }, + fontStyle: 'italic', + fontWeight: 500, + }, + + // ---------------------------------------------------------------- + // Bold + { + family: 'Geist', + urls: { + woff2: `fonts/Geist-Bold.woff2`, + }, + fontStyle: 'normal', + fontWeight: 700, + }, + + // ---------------------------------------------------------------- + // Bold Italic + { + family: 'Geist', + urls: { + woff2: `fonts/Geist-BoldItalic.woff2`, + }, + fontStyle: 'italic', + fontWeight: 700, + }, + ], + }, + }, + }, + ], +}; + +export default config; diff --git a/packages/snaps/simple-keyring/packages/site/gatsby-node.js b/packages/snaps/simple-keyring/packages/site/gatsby-node.js new file mode 100644 index 000000000..839d292cf --- /dev/null +++ b/packages/snaps/simple-keyring/packages/site/gatsby-node.js @@ -0,0 +1,26 @@ +const webpack = require('webpack'); + +module.exports.onCreateWebpackConfig = ({ actions }) => { + actions.setWebpackConfig({ + plugins: [ + new webpack.NormalModuleReplacementPlugin(/node:/u, (resource) => { + const mod = resource.request.replace(/^node:/u, ''); + switch (mod) { + case 'crypto': + resource.request = 'crypto'; + break; + default: + throw new Error(`Not found ${mod}`); + } + }), + ], + resolve: { + alias: { + crypto: require.resolve('crypto-browserify'), + }, + fallback: { + crypto: require.resolve('crypto-browserify'), + }, + }, + }); +}; diff --git a/packages/snaps/simple-keyring/packages/site/gatsby-ssr.tsx b/packages/snaps/simple-keyring/packages/site/gatsby-ssr.tsx new file mode 100644 index 000000000..24b259e1b --- /dev/null +++ b/packages/snaps/simple-keyring/packages/site/gatsby-ssr.tsx @@ -0,0 +1,34 @@ +import type { GatsbySSR } from 'gatsby'; +import React, { StrictMode } from 'react'; + +import { App } from './src/App'; +import { Root } from './src/Root'; + +// Inject the favicon manually instead of relying on gatsby-plugin-manifest's +// `icon` option, which uses sharp to resize images. sharp requires a native +// binary that cannot be installed in the monorepo (lavamoat's allow-scripts +// plugin only scans root node_modules, so packages isolated by +// hoistingLimits: "workspaces" are invisible to it). The pre-built PNGs in +// static/icons/ are committed directly and referenced here. +export const onRenderBody: GatsbySSR['onRenderBody'] = ({ + setHeadComponents, +}) => { + setHeadComponents([ + , + ]); +}; + +export const wrapRootElement: GatsbySSR['wrapRootElement'] = ({ element }) => ( + + {element} + +); + +export const wrapPageElement: GatsbySSR['wrapPageElement'] = ({ element }) => ( + {element} +); diff --git a/packages/snaps/simple-keyring/packages/site/package.json b/packages/snaps/simple-keyring/packages/site/package.json new file mode 100644 index 000000000..819037c3c --- /dev/null +++ b/packages/snaps/simple-keyring/packages/site/package.json @@ -0,0 +1,96 @@ +{ + "name": "@metamask/snap-simple-keyring-site", + "version": "2.1.1", + "description": "A snap simple keyring dapp used in MetaMask e2e tests.", + "homepage": "https://github.com/MetaMask/accounts/tree/main/packages/snaps/simple-keyring#readme", + "bugs": { + "url": "https://github.com/MetaMask/accounts/issues" + }, + "license": "(MIT-0 OR Apache-2.0)", + "repository": { + "type": "git", + "url": "https://github.com/MetaMask/accounts.git" + }, + "scripts": { + "build": "rimraf .cache && cross-env GATSBY_TELEMETRY_DISABLED=1 gatsby build --prefix-paths", + "clean": "rimraf public .cache", + "lint": "yarn lint:eslint && yarn lint:misc && yarn lint:deps && yarn lint:types", + "lint:deps": "depcheck", + "lint:eslint": "eslint . --cache --ext js,jsx,ts,tsx", + "lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write", + "lint:misc": "prettier '**/*.json' '**/*.md' '!CHANGELOG.md' --check", + "lint:types": "tsc --noEmit", + "changelog:update": "../../../../../scripts/update-changelog.sh @metamask/snap-simple-keyring-site", + "changelog:validate": "../../../../../scripts/validate-changelog.sh @metamask/snap-simple-keyring-site", + "start": "rimraf .cache && cross-env GATSBY_TELEMETRY_DISABLED=1 gatsby develop" + }, + "files": [ + "public/" + ], + "publishConfig": { + "access": "public" + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + }, + "dependencies": { + "@emotion/react": "^11.11.1", + "@emotion/styled": "^11.11.0", + "@metamask/keyring-api": "^23.1.0", + "@metamask/keyring-snap-client": "^9.0.2", + "@metamask/providers": "^19.0.0", + "@mui/icons-material": "^5.14.0", + "@mui/material": "^5.14.0", + "@types/react-helmet": "^6.1.6", + "crypto-browserify": "^3.12.1", + "react": "^18.2.0", + "react-dom": "^18.2.0", + "react-helmet": "^6.1.0", + "react-icons": "^4.8.0", + "react-is": "^18.2.0", + "semver": "^7.5.4", + "styled-components": "5.3.9", + "webpack": "^5.88.2" + }, + "devDependencies": { + "@metamask/auto-changelog": "^3.3.0", + "@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", + "@svgr/webpack": "^6.5.1", + "@types/react": "^18.0.28", + "@types/styled-components": "^5.1.26", + "@typescript-eslint/eslint-plugin": "^5.55.0", + "@typescript-eslint/parser": "^5.55.0", + "cross-env": "^7.0.3", + "depcheck": "^1.4.6", + "eslint": "^8.36.0", + "eslint-config-prettier": "^8.7.0", + "eslint-plugin-import": "^2.27.5", + "eslint-plugin-jest": "^27.2.1", + "eslint-plugin-jsdoc": "^40.0.3", + "eslint-plugin-n": "^16.1.0", + "eslint-plugin-prettier": "^4.2.1", + "eslint-plugin-promise": "^6.1.1", + "gatsby": "^5.12.4", + "gatsby-plugin-manifest": "^5.12.0", + "gatsby-plugin-styled-components": "^6.12.0", + "gatsby-plugin-svgr": "^3.0.0-beta.0", + "gatsby-plugin-webfonts": "^2.3.2", + "prettier": "^2.8.4", + "raw-loader": "^4.0.2", + "react-scripts": "^5.0.1", + "rimraf": "^4.4.0", + "typescript": "^4.9.5" + } +} diff --git a/packages/snaps/simple-keyring/packages/site/src/App.tsx b/packages/snaps/simple-keyring/packages/site/src/App.tsx new file mode 100644 index 000000000..befe6272a --- /dev/null +++ b/packages/snaps/simple-keyring/packages/site/src/App.tsx @@ -0,0 +1,55 @@ +import type { FunctionComponent, ReactNode } from 'react'; +import React from 'react'; +import { Helmet } from 'react-helmet'; +import styled from 'styled-components'; + +import { Footer, Header, AlertBanner, AlertType } from './components'; +import { GlobalStyle } from './config/theme'; + +const Wrapper = styled.div` + display: flex; + flex-direction: column; + width: 100%; + min-height: 100vh; + max-width: 100vw; +`; + +const BannerWrapper = styled.div` + padding-top: 25px; + padding-left: 5%; + padding-right: 5%; +`; + +export type AppProps = { + children: ReactNode; +}; + +export const App: FunctionComponent = ({ children }) => { + // Make sure we are on a browser, otherwise we can't use window.ethereum. + if (typeof window === 'undefined') { + return null; + } + + return ( + <> + + + SSK - Simple Snap Keyring + + + + + + +
+ {children} +