Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build!: build packages with ts-bridge #40

Merged
merged 7 commits into from
Nov 15, 2024
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
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const parserOptions = {
tsconfigRootDir: __dirname,
project: ['./tsconfig.packages.json'],
sourceType: 'module',
};

module.exports = {
Expand Down Expand Up @@ -79,6 +80,7 @@ module.exports = {
// @metamask/keyring-eth-hd
{
files: ['packages/keyring-eth-hd/**/*.js'],
excludedFiles: ['packages/keyring-eth-hd/jest.config.js'],
extends: ['@metamask/eslint-config-nodejs'],
parserOptions,
rules: {
Expand Down
11 changes: 3 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,9 @@
"packages/*"
],
"scripts": {
"build": "yarn run build:source && yarn run build:types",
"build:clean": "rimraf dist 'packages/*/dist' && yarn build:force",
"build": "ts-bridge --project tsconfig.build.json",
"build:clean": "yarn build --clean",
"build:docs": "yarn workspaces foreach --all --no-private --parallel --interlaced --verbose run build:docs",
"build:force": "yarn run build:source:force && yarn run build:types",
"build:source": "yarn workspaces foreach --all --no-private --parallel --interlaced --verbose run build",
"build:source:force": "yarn workspaces foreach --all --no-private --parallel --interlaced --verbose run build:force",
"build:types": "tsc --build tsconfig.build.json --verbose",
"build:watch": "yarn run build --watch",
"lint": "yarn lint:eslint && yarn lint:misc --check && yarn constraints && yarn lint:dependencies",
"lint:dependencies": "depcheck && yarn dedupe --check && syncpack list-mismatches",
"lint:dependencies:fix": "depcheck && yarn dedupe && syncpack fix-mismatches",
Expand Down Expand Up @@ -51,6 +46,7 @@
"@metamask/eslint-config-nodejs": "^13.0.0",
"@metamask/eslint-config-typescript": "^13.0.0",
"@npmcli/package-json": "^5.0.0",
"@ts-bridge/cli": "^0.6.0",
"@types/jest": "^29.5.12",
"@types/node": "^20.12.12",
"@typescript-eslint/eslint-plugin": "^8.5.0",
Expand All @@ -70,7 +66,6 @@
"jest-silent-reporter": "^0.5.0",
"prettier": "^2.8.8",
"prettier-plugin-packagejson": "^2.5.2",
"rimraf": "^5.0.10",
"syncpack": "^13.0.0",
"ts-jest": "^29.0.5",
"ts-node": "^10.9.2",
Expand Down
23 changes: 17 additions & 6 deletions packages/keyring-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,27 @@
"type": "git",
"url": "https://github.com/MetaMask/keyring-api.git"
},
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
},
"require": {
"types": "./dist/index.d.cts",
"default": "./dist/index.cjs"
}
}
},
"main": "./dist/index.cjs",
"types": "./dist/index.d.cts",
"files": [
"dist/"
],
"scripts": {
"build": "tsc --build tsconfig.build.json",
"build:clean": "rimraf dist && yarn build",
"build": "ts-bridge --project tsconfig.build.json --no-references",
"build:clean": "yarn build --clean",
"build:docs": "typedoc",
"build:force": "tsc --build tsconfig.build.json --force",
"changelog:update": "../../scripts/update-changelog.sh @metamask/keyring-api",
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/keyring-api",
"publish:preview": "yarn npm publish --tag preview",
Expand All @@ -48,14 +59,14 @@
"@lavamoat/preinstall-always-fail": "^2.1.0",
"@metamask/auto-changelog": "^3.4.4",
"@metamask/providers": "^18.1.0",
"@ts-bridge/cli": "^0.6.0",
"@types/jest": "^29.5.12",
"@types/node": "^20.12.12",
"@types/webextension-polyfill": "^0.12.1",
"deepmerge": "^4.2.2",
"depcheck": "^1.4.7",
"jest": "^29.5.0",
"jest-it-up": "^3.1.0",
"rimraf": "^5.0.10",
"ts-jest": "^29.0.5",
"ts-node": "^10.9.2",
"tsd": "^0.31.0",
Expand Down
3 changes: 3 additions & 0 deletions packages/keyring-eth-hd/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ module.exports = merge(baseConfig, {
// The display name when running multiple projects
displayName,

// A preset that is used as a base for Jest's configuration
preset: 'ts-jest/presets/js-with-ts',

// An array of regexp pattern strings used to skip coverage collection
coveragePathIgnorePatterns: ['./test'],

Expand Down
25 changes: 21 additions & 4 deletions packages/keyring-eth-hd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,27 @@
},
"license": "ISC",
"author": "Dan Finlay",
"main": "index.js",
"exports": {
".": {
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
},
"require": {
"types": "./dist/index.d.cts",
"default": "./dist/index.cjs"
}
}
},
"main": "./dist/index.cjs",
"types": "./dist/index.d.cts",
"files": [
"dist/"
],
"scripts": {
"build": "",
"build:clean": "",
"build:force": "",
"build": "ts-bridge --project tsconfig.build.json --no-references",
"build:clean": "yarn build --clean",
"build:docs": "typedoc",
"changelog:update": "../../scripts/update-changelog.sh @metamask/eth-hd-keyring",
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/eth-hd-keyring",
"publish:preview": "yarn npm publish --tag preview",
Expand All @@ -41,6 +57,7 @@
"@metamask/auto-changelog": "^3.4.4",
"@metamask/bip39": "^4.0.0",
"@metamask/eth-hd-keyring": "4.0.1",
"@ts-bridge/cli": "^0.6.0",
"@types/jest": "^29.5.12",
"deepmerge": "^4.2.2",
"jest": "^29.5.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
const {
import {
privateToPublic,
publicToAddress,
ecsign,
arrToBufArr,
bufferToHex,
} = require('@ethereumjs/util');
const {
} from '@ethereumjs/util';
import {
concatSig,
decrypt,
getEncryptionPublicKey,
normalize,
personalSign,
signTypedData,
SignTypedDataVersion,
} = require('@metamask/eth-sig-util');
const bip39 = require('@metamask/scure-bip39');
const { wordlist } = require('@metamask/scure-bip39/dist/wordlists/english');
const { assertIsHexString, remove0x } = require('@metamask/utils');
const { HDKey } = require('ethereum-cryptography/hdkey');
const { keccak256 } = require('ethereum-cryptography/keccak');
const { bytesToHex } = require('ethereum-cryptography/utils');
} from '@metamask/eth-sig-util';
import {
generateMnemonic,
// eslint-disable-next-line n/no-sync
mnemonicToSeedSync,
validateMnemonic,
} from '@metamask/scure-bip39';
import { wordlist } from '@metamask/scure-bip39/dist/wordlists/english';
import { assertIsHexString, remove0x } from '@metamask/utils';
import { HDKey } from 'ethereum-cryptography/hdkey';
import { keccak256 } from 'ethereum-cryptography/keccak';
import { bytesToHex } from 'ethereum-cryptography/utils';

// Options:
const hdPathString = `m/44'/60'/0'/0`;
Expand All @@ -34,7 +39,7 @@ class HdKeyring {
}

generateRandomMnemonic() {
this._initFromMnemonic(bip39.generateMnemonic(wordlist));
this._initFromMnemonic(generateMnemonic(wordlist));
}

_uint8ArrayToString(mnemonic) {
Expand Down Expand Up @@ -287,15 +292,15 @@ class HdKeyring {
this.mnemonic = this._mnemonicToUint8Array(mnemonic);

// validate before initializing
const isValid = bip39.validateMnemonic(this.mnemonic, wordlist);
const isValid = validateMnemonic(this.mnemonic, wordlist);
if (!isValid) {
throw new Error(
'Eth-Hd-Keyring: Invalid secret recovery phrase provided',
);
}

// eslint-disable-next-line n/no-sync
const seed = bip39.mnemonicToSeedSync(this.mnemonic, wordlist);
const seed = mnemonicToSeedSync(this.mnemonic, wordlist);
this.hdWallet = HDKey.fromMasterSeed(seed);
this.root = this.hdWallet.derive(this.hdPath);
}
Expand All @@ -309,4 +314,4 @@ class HdKeyring {
}

HdKeyring.type = type;
module.exports = HdKeyring;
export default HdKeyring;
23 changes: 10 additions & 13 deletions packages/keyring-eth-hd/test/index.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
const {
TransactionFactory,
Transaction: EthereumTx,
} = require('@ethereumjs/tx');
const {
import { TransactionFactory, Transaction as EthereumTx } from '@ethereumjs/tx';
import {
isValidAddress,
bufferToHex,
toBuffer,
ecrecover,
pubToAddress,
} = require('@ethereumjs/util');
const oldMMForkBIP39 = require('@metamask/bip39');
const OldHdKeyring = require('@metamask/eth-hd-keyring');
const {
} from '@ethereumjs/util';
import * as oldMMForkBIP39 from '@metamask/bip39';
import OldHdKeyring from '@metamask/eth-hd-keyring';
import {
normalize,
personalSign,
recoverPersonalSignature,
recoverTypedSignature,
signTypedData,
SignTypedDataVersion,
encrypt,
} = require('@metamask/eth-sig-util');
const { wordlist } = require('@metamask/scure-bip39/dist/wordlists/english');
const { keccak256 } = require('ethereum-cryptography/keccak');
} from '@metamask/eth-sig-util';
import { wordlist } from '@metamask/scure-bip39/dist/wordlists/english';
import { keccak256 } from 'ethereum-cryptography/keccak';

const HdKeyring = require('..');
import HdKeyring from '../src';

// Sample account:
const privKeyHex =
Expand Down
12 changes: 12 additions & 0 deletions packages/keyring-eth-hd/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "../../tsconfig.packages.build.json",
"compilerOptions": {
"allowJs": true,
"baseUrl": "./",
"outDir": "dist",
"rootDir": "src",
"exactOptionalPropertyTypes": false
},
"include": ["./src/**/*.ts", "./src/**/*.js"],
"exclude": ["./src/**/*.test.ts"]
}
11 changes: 11 additions & 0 deletions packages/keyring-eth-hd/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../../tsconfig.packages.json",
"compilerOptions": {
"allowJs": true,
"baseUrl": "./",
"exactOptionalPropertyTypes": false,
"target": "es2017"
},
"include": ["./src"],
"exclude": ["./dist/**/*"]
}
23 changes: 17 additions & 6 deletions packages/keyring-eth-ledger-bridge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,27 @@
},
"license": "ISC",
"author": "Bruno Barbieri",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
".": {
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
},
"require": {
"types": "./dist/index.d.cts",
"default": "./dist/index.cjs"
}
}
},
"main": "./dist/index.cjs",
"types": "./dist/index.d.cts",
"files": [
"dist/"
],
"scripts": {
"build": "tsc --build tsconfig.build.json",
"build:clean": "rimraf dist && yarn build",
"build": "ts-bridge --project tsconfig.build.json --no-references",
"build:clean": "yarn build --clean",
"build:docs": "typedoc",
"build:force": "tsc --build tsconfig.build.json --force",
"changelog:update": "../../scripts/update-changelog.sh @metamask/eth-ledger-bridge-keyring",
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/eth-ledger-bridge-keyring",
"publish:preview": "yarn npm publish --tag preview",
Expand All @@ -52,6 +63,7 @@
"@ledgerhq/types-devices": "^6.25.3",
"@metamask/auto-changelog": "^3.4.4",
"@metamask/utils": "^9.2.1",
"@ts-bridge/cli": "^0.6.0",
"@types/ethereumjs-tx": "^1.0.1",
"@types/hdkey": "^2.0.1",
"@types/jest": "^29.5.12",
Expand All @@ -62,7 +74,6 @@
"ethereumjs-tx": "^1.3.7",
"jest": "^29.5.0",
"jest-it-up": "^3.1.0",
"rimraf": "^5.0.10",
"ts-jest": "^29.0.5",
"ts-node": "^10.9.2",
"typedoc": "^0.25.13",
Expand Down
22 changes: 17 additions & 5 deletions packages/keyring-eth-simple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,27 @@
"type": "git",
"url": "https://github.com/MetaMask/eth-simple-keyring.git"
},
"main": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
".": {
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
},
"require": {
"types": "./dist/index.d.cts",
"default": "./dist/index.cjs"
}
}
},
"main": "./dist/index.cjs",
"types": "./dist/index.d.cts",
"files": [
"dist/"
],
"scripts": {
"build": "tsc --build tsconfig.build.json",
"build:clean": "rimraf dist && yarn build",
"build": "ts-bridge --project tsconfig.build.json --no-references",
"build:clean": "yarn build --clean",
"build:docs": "typedoc",
"build:force": "tsc --build tsconfig.build.json --force",
"changelog:update": "../../scripts/update-changelog.sh @metamask/eth-simple-keyring",
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/eth-simple-keyring",
"publish:preview": "yarn npm publish --tag preview",
Expand All @@ -44,6 +55,7 @@
"@lavamoat/allow-scripts": "^3.2.1",
"@lavamoat/preinstall-always-fail": "^2.1.0",
"@metamask/auto-changelog": "^3.4.4",
"@ts-bridge/cli": "^0.6.0",
"@types/ethereumjs-tx": "^1.0.1",
"@types/jest": "^29.5.12",
"@types/node": "^20.12.12",
Expand Down
Loading