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
1 change: 1 addition & 0 deletions .github/workflows/lint-build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ jobs:
matrix:
node-version: [24.x]
script:
- lint:tsc
- lint:eslint
- lint:misc:check
- constraints
Expand Down
13 changes: 7 additions & 6 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,14 @@ The monorepo uses a hierarchical configuration approach for different tools. For

#### TypeScript

- `tsconfig.base.json` defines shared development-specific TypeScript settings for all other config files.
- `tsconfig.build.json` defines shared build-specific TypeScript settings for all other config files.
- `tsconfig.packages.json` defines shared development-specific TypeScript settings for all directories in `packages/`.
- `tsconfig.packages.build.json` defines shared build-specific TypeScript settings for all directories in `packages/`.
- `tsconfig.base.json` defines shared compiler defaults for all other config files.
- `tsconfig.json` defines TypeScript settings for repository scripts and editor features.
- `tsconfig.packages.json` defines shared source, editor, and type-checking settings for all packages.
- `tsconfig.scripts.json` defines shared TypeScript settings for directories in `scripts/`.
- `packages/**/tsconfig.json` (and `scripts/create-package/package-template/tsconfig.json`) defines TypeScript settings for each package that are meant to be used by code editors and lint tasks.
- `packages/**/tsconfig.build.json` (and `scripts/create-package/package-template/tsconfig.build.json`) defines TypeScript settings for each package that are used to produce a build.
- The root `lint:tsc` script checks repository scripts with `tsconfig.json`, then checks each
workspace package configuration directly. It does not build Snap bundles with `tsc`.
- `packages/**/tsconfig.json` (and `scripts/create-package/package-template/tsconfig.json`) defines TypeScript settings for each package that are meant to be used by code editors and type checking.
- Library packages and the package template also have `tsconfig.build.json` files for `ts-bridge` declaration builds. Snap packages do not have build configs because `mm-snap` builds their bundles.
- `scripts/create-package/tsconfig.json` customizes TypeScript settings for the `create-package` tool.

#### Jest
Expand Down
5 changes: 1 addition & 4 deletions eslint-suppressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,6 @@
}
},
"packages/solana-wallet-snap/src/core/handlers/onKeyringRequest/Keyring.ts": {
"@typescript-eslint/no-base-to-string": {
"count": 1
},
"@typescript-eslint/no-explicit-any": {
"count": 10
},
Expand All @@ -258,7 +255,7 @@
"count": 1
},
"@typescript-eslint/restrict-template-expressions": {
"count": 2
"count": 1
},
"no-restricted-syntax": {
"count": 1
Expand Down
2 changes: 1 addition & 1 deletion jest.config.packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ module.exports = {

// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
// Here we ensure that Jest resolves `@metamask/*` imports to the uncompiled source code for packages that live in this repo.
// NOTE: This must be synchronized with the `paths` option in `tsconfig.base.json`.
// NOTE: This must be synchronized with the `paths` option in `tsconfig.packages.json`.
moduleNameMapper: {
'^@metamask/json-rpc-engine/v2$': [
'<rootDir>/../json-rpc-engine/src/v2/index.ts',
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
"changelog:validate": "yarn workspaces foreach --all --no-private --parallel --interlaced --verbose run changelog:validate",
"create-release-branch": "create-release-branch --formatter oxfmt",
"create-package": "tsx scripts/create-package",
"lint": "yarn lint:eslint && echo && yarn lint:misc --check && yarn constraints && yarn lint:dependencies && yarn readme-content:check",
"lint": "yarn lint:tsc && yarn lint:eslint && echo && yarn lint:misc --check && yarn constraints && yarn lint:dependencies && yarn readme-content:check",
"lint:dependencies": "depcheck && yarn dedupe --check",
"lint:dependencies:fix": "depcheck && yarn dedupe",
"lint:eslint": "yarn eslint",
"lint:fix": "yarn lint:eslint --fix --prune-suppressions && echo && yarn lint:misc --write && yarn constraints --fix && yarn lint:dependencies:fix && yarn readme-content:update",
"lint:misc": "oxfmt --ignore-path .gitignore",
"lint:misc:check": "yarn lint:misc --check",
"lint:tsc": "tsc --project tsconfig.json && yarn workspaces foreach --all exec tsc --project tsconfig.json --noEmit",
"prepack": "./scripts/prepack.sh",
"readme-content:check": "tsx scripts/update-readme-content.ts --check",
"readme-content:update": "tsx scripts/update-readme-content.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/bitcoin-wallet-snap/jest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const config = {
coverageThreshold: {
global: {
branches: 65.5,
functions: 62.64,
functions: 61.63,
lines: 75.29,
statements: 74.57,
},
Expand Down
3 changes: 3 additions & 0 deletions packages/bitcoin-wallet-snap/snap.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ dotenv();

const config: SnapConfig = {
input: resolve(__dirname, 'src/index.ts'),
typescript: {
enabled: true,
},
server: {
port: 8080,
},
Expand Down
2 changes: 1 addition & 1 deletion packages/bitcoin-wallet-snap/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/internal-snaps.git"
},
"source": {
"shasum": "ZEMZtj4BZq+pj3bzb81K1Vk5WQuqMA0NArfIhrIppds=",
"shasum": "N40X9yuzuO3nWtRwrVRhAMQC1+XOcB3Ay3sxYrg2YFA=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/bitcoin-wallet-snap/src/handlers/CronHandler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getSelectedAccounts } from '@metamask/keyring-snap-sdk';
import { InFlightCoalescer } from '@metamask/snap-networks-utils/dedupe';
import { InFlightCoalescer } from '@metamask/snap-networks-utils';
import type { JsonRpcRequest, SnapsProvider } from '@metamask/snaps-sdk';
import { array, assert, object, string } from 'superstruct';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
xpriv_to_descriptor,
xpub_to_descriptor,
} from '@metamask/bitcoindevkit';
import type { BIP32Node } from '@metamask/key-tree';
import { SLIP10Node } from '@metamask/key-tree';
import { v4 } from 'uuid';

Expand Down Expand Up @@ -271,7 +272,7 @@ export class BdkAccountRepository implements BitcoinAccountRepository {
const parentNode = parentNodes.get(parentKey) as SLIP10Node;
const childSegment = derivationPath[derivationPath.length - 1] as string;
const childNode = (
await parentNode.derive([`bip32:${childSegment}`])
await parentNode.derive([`bip32:${childSegment}` as BIP32Node])
).neuter();

accounts.push(
Expand Down
16 changes: 11 additions & 5 deletions packages/bitcoin-wallet-snap/tsconfig.json

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed these to match the other Snaps

Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,25 @@
"extends": "../../tsconfig.packages.json",
"compilerOptions": {
"baseUrl": "./",
"lib": ["ES2021", "DOM"],
"resolveJsonModule": true /* lets us import JSON modules from within TypeScript modules. */,
"jsx": "react-jsx",
"jsxImportSource": "@metamask/snaps-sdk",
"resolveJsonModule": true,
"exactOptionalPropertyTypes": false,
"forceConsistentCasingInFileNames": true,
"noErrorTruncation": true,
"noUncheckedIndexedAccess": true,
"skipLibCheck": true,
"module": "ESNext",
"lib": ["ES2023", "DOM"],
"target": "es2023",
"module": "preserve",
"moduleResolution": "bundler",
"types": ["jest"]
},
"references": [{ "path": "../snap-networks-utils" }],
"include": ["**/*.ts", "**/*.tsx", "locales/*.json"]
"include": [
"**/*.ts",
"**/*.tsx",
"locales/*.json",
"snap.manifest.json",
"src/**/*.json"
]
}
3 changes: 3 additions & 0 deletions packages/sample-snap/snap.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { resolve } from 'path';
const config: SnapConfig = {
// eslint-disable-next-line no-restricted-globals
input: resolve(__dirname, 'src/index.tsx'),
typescript: {
enabled: true,
},
server: {
port: 8080,
},
Expand Down
2 changes: 1 addition & 1 deletion packages/sample-snap/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/internal-snaps.git"
},
"source": {
"shasum": "7jzuMWjDr1T5dgRV5M6B8ZtNPxPBNmGV2JGWgkvtTdA=",
"shasum": "Sno6Wef4OjbtlPw43N9uwVEHYoNlIjEiAgdEIjqVd4c=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
1 change: 1 addition & 0 deletions packages/snap-networks-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export {
isSnapRpcError,
normalizeError,
} from './utils/errors';
export { InFlightCoalescer } from './utils/dedupe/InFlightCoalescer';
export type {
CreateSnapErrorHandlingOptions,
CreateTrackErrorOptions,
Expand Down
12 changes: 10 additions & 2 deletions packages/snap-networks-utils/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
{
"extends": "../../tsconfig.packages.build.json",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This package is the only exception so let's not have that root file

"extends": "./tsconfig.json",
"compilerOptions": {
"baseUrl": "./",
"composite": true,
"declaration": true,
"declarationMap": true,
"emitDeclarationOnly": true,
"inlineSources": true,
"noEmit": false,
"sourceMap": true,
"outDir": "./dist",
"rootDir": "./src"
},
"references": [],
"include": ["../../types", "./src"]
"include": ["../../types", "./src"],
"exclude": ["**/*.test.ts", "**/tests", "**/jest.config.ts"]
}
1 change: 0 additions & 1 deletion packages/snap-networks-utils/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@
"skipLibCheck": true,
"types": ["jest"]
},
"references": [],
"include": ["../../types", "./src"]
}
3 changes: 3 additions & 0 deletions packages/solana-wallet-snap/snap.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ const environment = {

const config: SnapConfig = {
input: resolve(__dirname, 'src/index.ts'),
typescript: {
enabled: true,
},
server: {
port: 8080,
},
Expand Down
2 changes: 1 addition & 1 deletion packages/solana-wallet-snap/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/internal-snaps.git"
},
"source": {
"shasum": "RP8K+BdAavCCQ3ZxXRx/CgH4ipA4Y2K/yCmqQTgHB8w=",
"shasum": "f67A1dy0bXl9jvoMuZ4heLBBs+m6bwaU20/WT30COeU=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,9 @@ export const ValidationResponseStruct = object({
valid: boolean(),
errors: array(
object({
code: enums(Object.values(SendErrorCodes)),
code: enums(
Object.values(SendErrorCodes) as [SendErrorCodes, ...SendErrorCodes[]],
),
}),
),
});
Expand All @@ -423,7 +425,7 @@ export const ComputeFeeRequestStruct = object({

export const ComputeFeeResponseStruct = array(
object({
type: enums(Object.values(FeeType)),
type: enums(Object.values(FeeType) as [FeeType, ...FeeType[]]),
asset: AssetStruct,
}),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import bs58 from 'bs58';

import type { AssetEntity } from '../../../entities';
import { asStrictKeyringAccount } from '../../../entities';
import type { Caip10Address } from '../../constants/solana';
import { KnownCaip19Id, Network } from '../../constants/solana';
import type {
AssetsService,
Expand Down Expand Up @@ -414,7 +415,7 @@ describe('SolanaKeyring', () => {
jsonrpc: '2.0',
...MOCK_SIGN_AND_SEND_TRANSACTION_REQUEST,
} as unknown as JsonRpcRequest;
const mockResolvedAddress = `${mockScope}:resolved-address`;
const mockResolvedAddress: Caip10Address = `${mockScope}:resolved-address`;

jest
.spyOn(mockWalletService, 'resolveAccountAddress')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import type {
ExportedAccount,
KeyringSnapRpc,
} from '@metamask/keyring-api/v2';
import { UuidStruct } from '@metamask/snap-networks-utils';
import type { Logger } from '@metamask/snap-networks-utils';
import { UuidStruct } from '@metamask/snap-networks-utils';
import type { CaipAssetType, JsonRpcRequest } from '@metamask/snaps-sdk';
import {
InvalidParamsError,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const CommaSeparatedListOfStringsStruct = coerce(

const EnvStruct = object({
ENVIRONMENT: enums(['local', 'test', 'production']),
LOG_LEVEL: enums(Object.values(LogLevel)),
LOG_LEVEL: enums(Object.values(LogLevel) as [LogLevel, ...LogLevel[]]),
RPC_URL_MAINNET_LIST: CommaSeparatedListOfUrlsStruct,
RPC_URL_DEVNET_LIST: CommaSeparatedListOfUrlsStruct,
RPC_URL_TESTNET_LIST: CommaSeparatedListOfUrlsStruct,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export class TransactionScanService {
symbol:
'symbol' in asset.asset ? asset.asset.symbol : asset.asset_type,
name: 'name' in asset.asset ? asset.asset.name : asset.asset_type,
logo: 'logo' in asset.asset ? asset.asset.logo : null,
logo: ('logo' in asset.asset ? asset.asset.logo : null) ?? null,
value: asset.in?.value ?? asset.out?.value ?? null,
price: asset.in?.usd_price ?? asset.out?.usd_price ?? null,
}),
Expand All @@ -230,7 +230,9 @@ export class TransactionScanService {
type:
'type' in result.error_details ? result.error_details.type : null,
code:
'code' in result.error_details ? result.error_details.code : null,
('code' in result.error_details
? result.error_details.code
: null) ?? null,
}
: null,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ import { Base58Struct, Base64Struct } from '../../validation/structs';
* @see https://github.com/anza-xyz/wallet-standard/tree/master/packages/core/features/src
*/

export const ScopeStringStruct = enums(Object.values(Network));
export const ScopeStringStruct = enums(
Object.values(Network) as [Network, ...Network[]],
);

// Sanitizing structs that transform values during validation
const SanitizedSolanaAddressStruct = coerce(
Expand Down
8 changes: 6 additions & 2 deletions packages/solana-wallet-snap/src/core/validation/structs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,13 @@ export const GetAccounBalancesResponseStruct = record(

export const ListAccountAssetsResponseStruct = array(CaipAssetTypeStruct);

export const SubmitRequestMethodStruct = enums(Object.values(SolMethod));
export const SubmitRequestMethodStruct = enums(
Object.values(SolMethod) as [SolMethod, ...SolMethod[]],
);

export const NetworkStruct = enums(Object.values(Network));
export const NetworkStruct = enums(
Object.values(Network) as [Network, ...Network[]],
);

export const Curenc = enums([
'btc',
Expand Down
22 changes: 10 additions & 12 deletions packages/solana-wallet-snap/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,14 @@ BigNumber.config({ EXPONENTIAL_AT: 16 });
* @param args - The request handler args as object.
* @param args.origin - The origin of the request, e.g., the website that
* invoked the snap.
* @param args.originMetadata - Metadata reported by the requesting origin.
* @param args.request - A validated JSON-RPC request object.
* @returns A promise that resolves to the result of the RPC request.
* @throws If the request method is not valid for this snap.
*/
export const onRpcRequest: OnRpcRequestHandler = async ({
origin,
originMetadata,
request,
}) => {
logger.log('[🔄 onRpcRequest]', request.method, request);
Expand All @@ -84,7 +86,7 @@ export const onRpcRequest: OnRpcRequestHandler = async ({
}

const result = await withCatchAndThrowSnapError(async () =>
handler({ origin, request }),
handler({ origin, originMetadata, request }),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we wanna to support support originMetadata now ?

as they are optional from the keyring API bump PR

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah from what I saw I think it complained when I didn't add it

);

return result ?? null;
Expand Down Expand Up @@ -179,13 +181,12 @@ export const onCronjob: OnCronjobHandler = async ({ request }) => {
_logger.log(request.method, request);

const { method } = request;
assert(
method,
enums([
...Object.values(CronjobMethod),
...Object.values(ScheduleBackgroundEventMethod),
]),
);
const validMethods = [
...Object.values(CronjobMethod),
...Object.values(ScheduleBackgroundEventMethod),
];

assert(method, enums(validMethods as [string, ...string[]]));

const result = await withCatchAndThrowSnapError(async () => {
_logger.log('Running cronjob', { method });
Expand All @@ -197,10 +198,7 @@ export const onCronjob: OnCronjobHandler = async ({ request }) => {

if (!handler) {
throw new MethodNotFoundError(
`Cronjob / ScheduleBackgroundEvent method ${String(method)} not found. Available methods: ${[
...Object.values(CronjobMethod),
...Object.values(ScheduleBackgroundEventMethod),
].join(',')}`,
`Cronjob / ScheduleBackgroundEvent method ${method} not found. Available methods: ${validMethods.toString()}`,
) as unknown as Error;
}
return handler({ request });
Expand Down
Loading