Skip to content
Merged
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
10 changes: 4 additions & 6 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module.exports = {
root: true,

parserOptions: {
sourceType: 'module',
},
Expand All @@ -8,20 +9,17 @@ module.exports = {

overrides: [
{
files: ['**/*.js'],
files: ['*.js'],
extends: ['@metamask/eslint-config-nodejs'],
},

{
files: ['**/*.{ts,tsx}'],
files: ['*.ts', '*.tsx'],
extends: ['@metamask/eslint-config-typescript'],
rules: {
'@typescript-eslint/consistent-type-definitions': ['error', 'type'],
},
},

{
files: ['**/*.test.ts', '**/*.test.js'],
files: ['*.test.ts', '*.test.js'],
extends: ['@metamask/eslint-config-jest'],
rules: {
'@typescript-eslint/no-shadow': [
Expand Down
5 changes: 4 additions & 1 deletion .prettierrc.js → .prettierrc.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// All of these are defaults except singleQuote, but we specify them
// for explicitness
module.exports = {
const config = {
quoteProps: 'as-needed',
singleQuote: true,
tabWidth: 2,
trailingComma: 'all',
plugins: ['prettier-plugin-packagejson'],
};

export default config;
8 changes: 8 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
enableScripts: false

enableTelemetry: 0

logFilters:
- code: YN0004
level: discard

nodeLinker: node-modules

plugins:
Expand Down
70 changes: 70 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import base, { createConfig } from '@metamask/eslint-config';
import browser from '@metamask/eslint-config-browser';
import jest from '@metamask/eslint-config-jest';
import nodejs from '@metamask/eslint-config-nodejs';
import typescript from '@metamask/eslint-config-typescript';

const config = createConfig([
{
ignores: [
'**/build/',
'**/.cache/',
'**/dist/',
'**/docs/',
'**/public/',
'packages/site',
'.yarn/',
],
},

{
extends: base,

languageOptions: {
sourceType: 'module',
parserOptions: {
tsconfigRootDir: import.meta.dirname,
project: ['./tsconfig.json'],
},
},

settings: {
'import-x/extensions': ['.js', '.mjs'],
},
},

{
files: ['**/*.ts', '**/*.tsx'],
extends: typescript,

rules: {
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-shadow': ['error', { allow: ['Text'] }],
},
},

{
files: ['**/*.js', '**/*.cjs', 'packages/onchaintrust-snap/snap.config.ts'],
extends: nodejs,

languageOptions: {
sourceType: 'script',
},
},

{
files: ['**/*.test.ts', '**/*.test.tsx', '**/*.test.js'],
extends: [jest, nodejs],

rules: {
'@typescript-eslint/unbound-method': 'off',
},
},

{
files: ['packages/site/src/**'],
extends: [browser],
},
]);

export default config;
48 changes: 32 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,51 @@
],
"scripts": {
"build": "yarn workspaces foreach --parallel --topological --verbose run build",
"install-chrome": "./scripts/install-chrome.sh",
"lint": "yarn lint:eslint && yarn lint:misc --check",
"lint:eslint": "eslint . --cache --ext js,ts",
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write",
"lint:misc": "prettier '**/*.json' '**/*.md' '!**/CHANGELOG.md' '**/*.yml' --ignore-path .gitignore",
"start": "yarn workspaces foreach --parallel --interlaced --verbose run start",
"test": "cd packages/onchaintrust-snap && yarn test"
},
"resolutions": {
"cookie": "^0.7.1",
"path-to-regexp@0.1.10": "^0.1.12",
"sharp": "^0.33.5",
"socket.io": "^4.8.1",
"ws": "^8.17.1"
},
"devDependencies": {
"@metamask/eslint-config": "^10.0.0",
"@metamask/eslint-config-jest": "^12.1.0",
"@metamask/eslint-config-nodejs": "^12.1.0",
"@metamask/eslint-config-typescript": "^10.0.0",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"eslint": "^8.56.0",
"@lavamoat/allow-scripts": "^3.3.4",
"@lavamoat/preinstall-always-fail": "^2.0.0",
"@metamask/eslint-config": "^14.0.0",
"@metamask/eslint-config-browser": "^14.0.0",
"@metamask/eslint-config-jest": "^14.0.0",
"@metamask/eslint-config-nodejs": "^14.0.0",
"@metamask/eslint-config-typescript": "^14.0.0",
"eslint": "^9.11.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^27.9.0",
"eslint-plugin-jsdoc": "^41.1.2",
"eslint-plugin-n": "^16.6.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "5.1.3",
"prettier": "3.2.5",
"eslint-import-resolver-typescript": "^3.6.3",
"eslint-plugin-import-x": "^4.3.0",
"eslint-plugin-jest": "^28.8.3",
"eslint-plugin-jsdoc": "^50.2.4",
"eslint-plugin-n": "^17.10.3",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-promise": "^7.1.0",
"prettier": "^3.3.3",
"prettier-plugin-packagejson": "^2.4.11",
"typescript": "^4.9.5"
"typescript": "^5.7.3",
"typescript-eslint": "^8.6.0"
},
"packageManager": "yarn@3.2.1",
"engines": {
"node": ">=22.12.0"
},
"lavamoat": {
"allowScripts": {
"@lavamoat/preinstall-always-fail": false,
"sharp": true,
"eslint-plugin-import-x>unrs-resolver": false
}
}
}
5 changes: 0 additions & 5 deletions packages/onchaintrust-snap/.eslintrc.js

This file was deleted.

32 changes: 10 additions & 22 deletions packages/onchaintrust-snap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,47 +14,35 @@
"snap.manifest.json"
],
"scripts": {
"allow-scripts": "yarn workspace root allow-scripts",
"build": "mm-snap build",
"build:clean": "yarn clean && yarn build",
"clean": "rimraf dist",
"lint": "yarn lint:eslint && yarn lint:misc --check",
"lint:eslint": "eslint . --cache --ext js,ts",
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write",
"lint:misc": "prettier '**/*.json' '**/*.md' '!CHANGELOG.md' --ignore-path .gitignore",
"lint:misc": "prettier '**/*.json' '**/*.md' '**/*.yml' '!.yarnrc.yml' --ignore-path ../../.gitignore --no-error-on-unmatched-pattern",
"prepublishOnly": "mm-snap manifest",
"serve": "mm-snap serve",
"start": "mm-snap watch",
"test": "jest"
},
"dependencies": {
"@metamask/snaps-sdk": "^9.3.0",
"@metamask/snaps-sdk": "9.2.0",
"buffer": "^6.0.3"
},
"devDependencies": {
"@jest/globals": "^29.7.0",
"@lavamoat/allow-scripts": "^3.0.2",
"@metamask/auto-changelog": "^3.4.4",
"@metamask/eslint-config": "^10.0.0",
"@metamask/eslint-config-jest": "^12.1.0",
"@metamask/eslint-config-nodejs": "^12.1.0",
"@metamask/eslint-config-typescript": "^10.0.0",
"@metamask/snaps-cli": "^5.1.0",
"@metamask/snaps-jest": "^6.0.0",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^27.9.0",
"eslint-plugin-jsdoc": "^41.1.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "5.1.3",
"@metamask/snaps-cli": "^6.0.0",
"@metamask/snaps-jest": "^9.4.0",
"@types/react": "18.2.4",
"@types/react-dom": "18.2.4",
"eslint": "^9.11.0",
"jest": "^29.7.0",
"prettier": "3.2.5",
"prettier-plugin-packagejson": "^2.4.11",
"rimraf": "^5.0.5",
"through2": "^4.0.2",
"ts-jest": "^29.1.2",
"typescript": "^4.9.5"
"typescript": "~5.7.3"
},
"packageManager": "yarn@3.2.1",
"engines": {
Expand Down
3 changes: 1 addition & 2 deletions packages/onchaintrust-snap/snap.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { resolve } from 'path';
import type { SnapConfig } from '@metamask/snaps-cli';
import { resolve } from 'path';

const config: SnapConfig = {
bundler: 'webpack',
input: resolve(__dirname, 'src/index.ts'),
server: {
port: 8080,
Expand Down
3 changes: 2 additions & 1 deletion packages/onchaintrust-snap/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/OnChainTrust/onchaintrust-snap.git"
},
"source": {
"shasum": "BsGTFG9MMvp7I6EK6Snrrw1WUOfbNAY2yPsRQjo2Wvw=",
"shasum": "6pJhRJ84FitXm061wGS4cOa4lWD0bXFtVgIq5VlZTP4=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand All @@ -23,5 +23,6 @@
},
"endowment:network-access": {}
},
"platformVersion": "9.2.0",
"manifestVersion": "0.1"
}
64 changes: 19 additions & 45 deletions packages/onchaintrust-snap/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,36 @@
import { installSnap } from '@metamask/snaps-jest';
import { heading, panel, text, SeverityLevel } from '@metamask/snaps-sdk';
import { heading, panel, text } from '@metamask/snaps-sdk';

describe('onTransaction handler tests', () => {
let recipientAddress = '0xdac83f876ae50433a20363845f43042d8d81b1aa'; // A random address

/**
* Sets up the test environment for the onTransaction handler.
*
* @returns The sendTransaction function.
*/
async function setupTestEnvironment() {
const { sendTransaction: localSendTransaction } = await installSnap();

return { sendTransaction: localSendTransaction };
}

let sendTransaction: (transaction: any) => Promise<any>;

describe('when no information is found for the address', () => {
beforeEach(async () => {
const setup = await setupTestEnvironment();
sendTransaction = setup.sendTransaction;
});

it('should display UI components correctly', async () => {
const response = await sendTransaction({
const { onTransaction } = await installSnap();
const recipientAddress = '0xdac83f876ae50433a20363845f43042d8d81b1aa';
const response = await onTransaction({
to: recipientAddress,
origin: 'https://example.com',
});

expect(response).toRender(
const screen = response.getInterface();

expect(screen).toRender(
panel([text('⚠️ No information found for this address')]),
);
});
});

describe('when address is verified', () => {
beforeEach(async () => {
recipientAddress = '0x00000000000000000000000000000000f0cacc1a';

const setup = await setupTestEnvironment();
sendTransaction = setup.sendTransaction;
});

it('should display UI components correctly', async () => {
const response = await sendTransaction({
const { onTransaction } = await installSnap();
const recipientAddress = '0x00000000000000000000000000000000f0cacc1a';
const response = await onTransaction({
to: recipientAddress,
origin: 'https://example.com',
});

expect(response).toRender(
const screen = response.getInterface();

expect(screen).toRender(
panel([
text('✅ Verified address'),
heading('Example Corp LTD'),
Expand All @@ -62,31 +43,24 @@ describe('onTransaction handler tests', () => {
});

describe('when address is malicious', () => {
beforeEach(async () => {
recipientAddress = '0x00000000000000000000000000000000f00dbabe';

const setup = await setupTestEnvironment();
sendTransaction = setup.sendTransaction;
});

it('should display UI components correctly', async () => {
const response = await sendTransaction({
const { onTransaction } = await installSnap();
const recipientAddress = '0x00000000000000000000000000000000f00dbabe';
const response = await onTransaction({
to: recipientAddress,
origin: 'https://example.com',
});

expect(response).toRender(
const screen = response.getInterface();

expect(screen).toRender(
panel([
heading('Security Alert: Potentially Unsafe Action Detected!'),
text(
'🚫 STOP: Your transaction is directed towards an address that has been flagged for suspicious activity. Engaging with this address may result in the loss of your digital assets or compromise your personal security.',
),
]),
);

expect(response.response.result.severity).toBe(
'critical' as SeverityLevel,
);
});
});
});
Loading
Loading