diff --git a/.gitignore b/.gitignore index 51d1cd386b..189eba3f0d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ node_modules/ packages/*/node_modules +packages/*/lib._esm .package_node_modules/ obsolete/ .DS_Store diff --git a/misc/admin/lib/build.js b/misc/admin/lib/build.js index 92f29d5d50..a003d48bd8 100644 --- a/misc/admin/lib/build.js +++ b/misc/admin/lib/build.js @@ -17,20 +17,6 @@ function setupConfig(outDir, moduleType, targetType) { if (info._ethers_nobuild) { return; } - if (targetType === "es2015") { - if (info["browser.esm"]) { - info.browser = info["browser.esm"]; - } - } - else if (targetType === "es5") { - if (info["browser.umd"]) { - info.browser = info["browser.umd"]; - } - } - else { - throw new Error("unsupported target"); - } - utils_1.saveJson(filename, info, true); let path = path_1.resolve("packages", dirname, "tsconfig.json"); let content = utils_1.loadJson(path); content.compilerOptions.outDir = outDir; @@ -39,7 +25,7 @@ function setupConfig(outDir, moduleType, targetType) { } function setupBuild(buildModule) { if (buildModule) { - setupConfig("./lib.esm/", "es2015", "es2015"); + setupConfig("./lib._esm/", "es2015", "es2015"); } else { setupConfig("./lib/", "commonjs", "es5"); diff --git a/misc/admin/lib/cmds/bundle-testcases.d.ts b/misc/admin/lib/cmds/bundle-testcases.d.ts new file mode 100644 index 0000000000..cb0ff5c3b5 --- /dev/null +++ b/misc/admin/lib/cmds/bundle-testcases.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/misc/admin/lib/cmds/bundle-testcases.js b/misc/admin/lib/cmds/bundle-testcases.js new file mode 100644 index 0000000000..0f0bf9923d --- /dev/null +++ b/misc/admin/lib/cmds/bundle-testcases.js @@ -0,0 +1,62 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +/** bundle-testcases + * + * This sript converts all the testase data (including needed + * text files) into a single JSON file. + * + * All gzip files (mostly .json.gz) are decompressed and recompressed + * using deflate, so a much more simple deflate library can be used. + */ +const fs_1 = __importDefault(require("fs")); +const path_1 = require("path"); +const zlib_1 = __importDefault(require("zlib")); +const log_1 = require("../log"); +const path_2 = require("../path"); +const config = { + dirs: [ + "./input/easyseed-bip39", + "./testcases", + "./input/wordlists" + ] +}; +(function () { + return __awaiter(this, void 0, void 0, function* () { + console.log(log_1.colorify.bold(`Bundling Testcase Data...`)); + const data = { "_": JSON.stringify({ name: "browser-fs", config: config }) }; + config.dirs.forEach((dirname) => { + let fulldirname = path_2.resolve("packages/testcases", dirname); + fs_1.default.readdirSync(fulldirname).forEach((filename) => { + const key = path_1.join(dirname, filename); + const content = fs_1.default.readFileSync(path_1.join(fulldirname, filename)); + if (filename.split(".").pop() === "gz") { + const contentData = zlib_1.default.gunzipSync(content); + data[key] = String(contentData.length) + "," + zlib_1.default.deflateRawSync(contentData).toString("base64"); + } + else { + data[key] = content.toString("base64"); + } + console.log(` - Added ${key} (${data[key].length} bytes)`); + }); + }); + // We write it out to all needed places + fs_1.default.writeFileSync(path_2.resolve("packages/testcases/lib/browser-data.json"), JSON.stringify(data)); + fs_1.default.writeFileSync(path_2.resolve("packages/testcases/lib._esm/browser-data.json"), JSON.stringify(data)); + fs_1.default.writeFileSync(path_2.resolve("packages/testcases/lib.esm/browser-data.json"), JSON.stringify(data)); + // Write it to the TypeScript source last, in case it is running it will + // be regenerated overwriting the above files, but with identical content + fs_1.default.writeFileSync(path_2.resolve("packages/testcases/src.ts/browser-data.json"), JSON.stringify(data)); + }); +})(); diff --git a/misc/admin/lib/cmds/esm-alias.d.ts b/misc/admin/lib/cmds/esm-alias.d.ts new file mode 100644 index 0000000000..cb0ff5c3b5 --- /dev/null +++ b/misc/admin/lib/cmds/esm-alias.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/misc/admin/lib/cmds/esm-alias.js b/misc/admin/lib/cmds/esm-alias.js new file mode 100644 index 0000000000..0abb586c84 --- /dev/null +++ b/misc/admin/lib/cmds/esm-alias.js @@ -0,0 +1,131 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const fs_1 = __importDefault(require("fs")); +const path_1 = require("path"); +const depgraph_1 = require("../depgraph"); +const path_2 = require("../path"); +const utils_1 = require("../utils"); +const log_1 = require("../log"); +function diff(a, b) { + return (Buffer.compare(fs_1.default.readFileSync(a), fs_1.default.readFileSync(b)) !== 0); +} +function alias(name) { + return __awaiter(this, void 0, void 0, function* () { + console.log(` Aliasing: ${name}`); + const baseDir = path_2.resolve("packages", name); + const info = utils_1.loadJson(path_2.resolve(baseDir, "package.json")); + const replacements = info["_ethers.alias"] || {}; + const skip = Object.keys(replacements).reduce((accum, key) => { + const replace = replacements[key]; + accum[replace] = true; + accum[replace + ".map"] = true; + accum[replace.replace(/\.js$/, ".d.ts")] = true; + return accum; + }, ({})); + const transforms = []; + const recurse = function (input, output) { + fs_1.default.readdirSync(path_1.join(baseDir, input)).forEach((filename) => { + const stat = fs_1.default.statSync(path_1.join(baseDir, input, filename)); + if (stat.isDirectory()) { + recurse(path_1.join(input, filename), path_1.join(output, filename)); + return; + } + if (skip[filename]) { + return; + } + let inputFilename = filename; + let transform = null; + if (filename.match(/\.js(on)?$/)) { + // JavaScript; swap in any replacement + // e.g. (filename = geturl.js) => (inputFilename = browser-geturl.js) + // + transform (//# sourceMappingURL=browser-geturl.js.map) to + // (//# sourceMappingURL=geturl.js.map) + const replace = replacements[filename]; + // Skip! + if (replace === "") { + return; + } + if (replace) { + inputFilename = replace; + transform = function (content) { + content = content.replace(/(\/\/# sourceMappingURL=)(.*)$/g, (all, prefix, mapFilename) => { + return prefix + filename + ".map"; + }); + return content; + }; + } + } + else if (filename.match(/\.d\.ts$/)) { + // TypeScript definietion file + // e.g. (filename = geturl.d.ts) => diff(geturl.d.ts, browser-geturl.d.ts) + // We do not need to swap anything out, but we need to ensure + // the definition of the node and browser are identical + const replace = replacements[filename.replace(/\.d\.ts$/i, ".js")]; + // Skip! + if (replace === "") { + return; + } + if (replace) { + inputFilename = replace.replace(/\.js$/i, ".d.ts"); + if (diff(path_1.join(baseDir, input, filename), path_1.join(baseDir, input, inputFilename))) { + console.log(`Warning: TypeScript Definition files differ: ${filename} != ${inputFilename}`); + } + } + } + else if (filename.match(/\.map$/)) { + // Map files; swap in the replacement + // e.g. (filename = geturl.js.map) => (inputFilename = browser-geturl.js.map) + // + transform the map JSON to reference "geturl.js" + // We need to swap in the replacement and update its data + const replace = replacements[filename.replace(/\.js.map$/i, ".js")]; + // Skip! + if (replace === "") { + return; + } + if (replace) { + inputFilename = replace + ".map"; + transform = function (content) { + const data = JSON.parse(content); + data["file"] = filename.replace(/\.js\.map$/, ".js"); + return JSON.stringify(data); + }; + } + } + transforms.push({ input: path_1.join(input, inputFilename), output: path_1.join(output, filename), transform }); + }); + }; + recurse("lib._esm", "lib.esm"); + transforms.forEach(({ input, output, transform }) => { + const sourceFile = path_1.join(baseDir, input); + let content = fs_1.default.readFileSync(sourceFile).toString(); + if (transform) { + content = transform(content); + } + const targetFile = path_1.join(baseDir, output); + const targetDir = path_1.dirname(targetFile); + utils_1.mkdir(targetDir); + fs_1.default.writeFileSync(targetFile, content); + }); + }); +} +(function () { + return __awaiter(this, void 0, void 0, function* () { + console.log(log_1.colorify.bold(`Aliasing Node ESM to Browser ESM...`)); + const dirnames = depgraph_1.getOrdered(true); + for (let i = 0; i < dirnames.length; i++) { + yield alias(dirnames[i]); + } + }); +})(); diff --git a/misc/admin/src.ts/build.ts b/misc/admin/src.ts/build.ts index f8ecd0c0e6..18ca63797e 100644 --- a/misc/admin/src.ts/build.ts +++ b/misc/admin/src.ts/build.ts @@ -18,19 +18,6 @@ function setupConfig(outDir: string, moduleType: string, targetType: string) { if (info._ethers_nobuild) { return; } - if (targetType === "es2015") { - if (info["browser.esm"]) { - info.browser = info["browser.esm"]; - } - } else if (targetType === "es5") { - if (info["browser.umd"]) { - info.browser = info["browser.umd"]; - } - } else { - throw new Error("unsupported target"); - } - saveJson(filename, info, true); - let path = resolve("packages", dirname, "tsconfig.json"); let content = loadJson(path); content.compilerOptions.outDir = outDir; @@ -40,7 +27,7 @@ function setupConfig(outDir: string, moduleType: string, targetType: string) { export function setupBuild(buildModule: boolean): void { if (buildModule) { - setupConfig("./lib.esm/", "es2015", "es2015"); + setupConfig("./lib._esm/", "es2015", "es2015"); } else { setupConfig("./lib/", "commonjs", "es5"); } diff --git a/misc/admin/src.ts/cmds/bundle-testcases.ts b/misc/admin/src.ts/cmds/bundle-testcases.ts new file mode 100644 index 0000000000..f48bef0962 --- /dev/null +++ b/misc/admin/src.ts/cmds/bundle-testcases.ts @@ -0,0 +1,56 @@ +"use strict"; + +/** bundle-testcases + * + * This sript converts all the testase data (including needed + * text files) into a single JSON file. + * + * All gzip files (mostly .json.gz) are decompressed and recompressed + * using deflate, so a much more simple deflate library can be used. + */ + + +import fs from "fs"; +import { join } from "path"; +import zlib from "zlib"; + +import { colorify } from "../log"; +import { resolve } from "../path"; + +const config = { + dirs: [ + "./input/easyseed-bip39", + "./testcases", + "./input/wordlists" + ] +}; + +(async function() { + console.log(colorify.bold(`Bundling Testcase Data...`)); + + const data: Record = { "_": JSON.stringify({ name: "browser-fs", config: config }) }; + + config.dirs.forEach((dirname) => { + let fulldirname = resolve("packages/testcases", dirname); + fs.readdirSync(fulldirname).forEach((filename) => { + const key = join(dirname, filename); + const content = fs.readFileSync(join(fulldirname, filename)); + if (filename.split(".").pop() === "gz") { + const contentData = zlib.gunzipSync(content); + data[key] = String(contentData.length) + "," + zlib.deflateRawSync(contentData).toString("base64"); + } else { + data[key] = content.toString("base64"); + } + console.log(` - Added ${ key } (${ data[key].length } bytes)`); + }); + }); + + // We write it out to all needed places + fs.writeFileSync(resolve("packages/testcases/lib/browser-data.json"), JSON.stringify(data)); + fs.writeFileSync(resolve("packages/testcases/lib._esm/browser-data.json"), JSON.stringify(data)); + fs.writeFileSync(resolve("packages/testcases/lib.esm/browser-data.json"), JSON.stringify(data)); + + // Write it to the TypeScript source last, in case it is running it will + // be regenerated overwriting the above files, but with identical content + fs.writeFileSync(resolve("packages/testcases/src.ts/browser-data.json"), JSON.stringify(data)); +})(); diff --git a/misc/admin/src.ts/cmds/esm-alias.ts b/misc/admin/src.ts/cmds/esm-alias.ts new file mode 100644 index 0000000000..c0246ea68a --- /dev/null +++ b/misc/admin/src.ts/cmds/esm-alias.ts @@ -0,0 +1,123 @@ +import fs from "fs"; +import { dirname, join } from "path"; + +import { getOrdered } from "../depgraph"; +import { resolve } from "../path"; +import { loadJson, mkdir } from "../utils"; +import { colorify } from "../log"; + +function diff(a: string, b: string): boolean { + return (Buffer.compare(fs.readFileSync(a), fs.readFileSync(b)) !== 0); +} + +async function alias(name: string): Promise { + console.log(` Aliasing: ${ name }`); + + const baseDir = resolve("packages", name); + + const info = loadJson(resolve(baseDir, "package.json")); + const replacements: Record = info["_ethers.alias"] || { }; + const skip = Object.keys(replacements).reduce((accum, key) => { + const replace = replacements[key]; + accum[replace] = true; + accum[replace + ".map"] = true; + accum[replace.replace(/\.js$/, ".d.ts")] = true; + return accum; + }, >({ })); + + const transforms: Array<{ input: string, output: string, transform?: (content: string) => string }> = [ ]; + const recurse = function(input: string, output: string) { + fs.readdirSync(join(baseDir, input)).forEach((filename) => { + const stat = fs.statSync(join(baseDir, input, filename)); + if (stat.isDirectory()) { + recurse(join(input, filename), join(output, filename)); + return; + } + if (skip[filename]) { return; } + + let inputFilename = filename; + let transform: (content: string) => string = null; + + if (filename.match(/\.js(on)?$/)) { + // JavaScript; swap in any replacement + // e.g. (filename = geturl.js) => (inputFilename = browser-geturl.js) + // + transform (//# sourceMappingURL=browser-geturl.js.map) to + // (//# sourceMappingURL=geturl.js.map) + const replace = replacements[filename]; + + // Skip! + if (replace === "") { return; } + + if (replace) { + inputFilename = replace; + transform = function(content: string) { + content = content.replace(/(\/\/# sourceMappingURL=)(.*)$/g, (all, prefix, mapFilename) => { + return prefix + filename + ".map"; + }); + return content; + } + } + + } else if (filename.match(/\.d\.ts$/)) { + // TypeScript definietion file + // e.g. (filename = geturl.d.ts) => diff(geturl.d.ts, browser-geturl.d.ts) + // We do not need to swap anything out, but we need to ensure + // the definition of the node and browser are identical + const replace = replacements[filename.replace(/\.d\.ts$/i, ".js")]; + + // Skip! + if (replace === "") { return; } + + if (replace) { + inputFilename = replace.replace(/\.js$/i, ".d.ts"); + if (diff(join(baseDir, input, filename), join(baseDir, input, inputFilename))) { + console.log(`Warning: TypeScript Definition files differ: ${ filename } != ${ inputFilename }`); + } + } + + } else if (filename.match(/\.map$/)) { + // Map files; swap in the replacement + // e.g. (filename = geturl.js.map) => (inputFilename = browser-geturl.js.map) + // + transform the map JSON to reference "geturl.js" + // We need to swap in the replacement and update its data + const replace = replacements[filename.replace(/\.js.map$/i, ".js")]; + + // Skip! + if (replace === "") { return; } + + if (replace) { + inputFilename = replace + ".map"; + transform = function(content: string) { + const data = JSON.parse(content); + data["file"] = filename.replace(/\.js\.map$/, ".js"); + return JSON.stringify(data); + } + } + } + + transforms.push({ input: join(input, inputFilename), output: join(output, filename), transform }); + }); + }; + recurse("lib._esm", "lib.esm"); + + transforms.forEach(({ input, output, transform }) => { + const sourceFile = join(baseDir, input); + let content = fs.readFileSync(sourceFile).toString(); + + if (transform) { content = transform(content); } + + const targetFile = join(baseDir, output); + const targetDir = dirname(targetFile); + mkdir(targetDir); + + fs.writeFileSync(targetFile, content); + }); +} + +(async function() { + console.log(colorify.bold(`Aliasing Node ESM to Browser ESM...`)); + const dirnames = getOrdered(true); + for (let i = 0; i < dirnames.length; i++) { + await alias(dirnames[i]); + } +})(); diff --git a/package.json b/package.json index 9f0fc93cf9..0e345be43a 100644 --- a/package.json +++ b/package.json @@ -15,42 +15,43 @@ "build": "tsc --build ./tsconfig.project.json", "_build-cjs": "node ./misc/admin/lib/cmds/echo 'Building CommonJS libraries...' && node ./misc/admin/lib/cmds/set-build-option cjs && npm run build", "_build-esm": "node ./misc/admin/lib/cmds/echo 'Building ES modules libraries...' && node ./misc/admin/lib/cmds/set-build-option esm && npm run build", - "clean": "node ./misc/admin/lib/cmds/echo 'Cleaning all build files...' && rm -rf packages/*/lib packages/*/lib.esm packages/*/node_modules packages/*/dist/*.js packages/*/tsconfig.tsbuildinfo node_modules .package_node_modules package-lock.json", - "_test-esm-dist": "rollup -c rollup-tests.config.js --configModule", - "_test-umd-dist": "rollup -c rollup-tests.config.js", + "clean": "node ./misc/admin/lib/cmds/echo 'Cleaning all build files...' && rm -rf packages/*/lib packages/*/lib._esm packages/*/lib.esm packages/*/node_modules packages/*/dist/*.js packages/*/tsconfig.tsbuildinfo node_modules .package_node_modules package-lock.json", + "_test-dist": "node ./misc/admin/lib/cmds/bundle-testcases && rollup -c rollup-tests.config.js", "_test-browser-umd": "karma start --single-run --browsers HeadlessLittleLiar karma-umd.conf.js", "_test-browser-esm": "karma start --single-run --browsers HeadlessLittleLiar karma-esm.conf.js", - "test-browser-umd": "npm run _test-umd-dist && npm run _test-browser-umd", - "test-browser-esm": "npm run _test-esm-dist && npm run _test-browser-esm", + "test-browser-umd": "npm run _test-dist && npm run _test-browser-umd", + "test-browser-esm": "npm run _test-dist && npm run _test-browser-esm", "test-coverage": "nyc --report-dir=output --reporter=lcov --reporter=text mocha --reporter ./packages/tests/reporter-keepalive ./packages/tests/lib/test-*.js | tee output/summary.txt", "test-node": "mocha --no-colors --reporter ./packages/tests/reporter ./packages/tests/lib/test-*.js", - "test-react": "npm run _test-umd-dist && npm run build-dist-shims && pushd misc/ReactNativeTestApp && ./run-tests.sh && popd", + "test-react": "npm run _test-dist && npm run build-dist-shims && pushd misc/ReactNativeTestApp && ./run-tests.sh && popd", "test": "npm run build-all && npm run test-node", "build-docs": "flatworm docs.wrm docs", "serve-docs": "node ./misc/admin/lib/cmds/serve-docs.js", "upload-docs": " node ./admin/cmds/upload-docs.js", "spell-check": "node ./misc/admin/lib/cmds/spell-check.js", - "build-dist-ancillary": "node ./misc/admin/lib/cmds/set-build-option esm && rollup -c rollup-ancillary.config.js", - "build-dist-shims": "browserify ./packages/shims/src/index.js -o ./packages/shims/dist/index.js && uglifyjs --compress --mangle --output ./packages/shims/dist/index.min.js -- ./packages/shims/dist/index.js", - "build-dist-umd": "node ./misc/admin/lib/cmds/set-build-option cjs browser-lang-all && rollup -c && mv ./packages/ethers/dist/ethers.umd.min.js ./packages/ethers/dist/ethers-all.umd.min.js && node ./misc/admin/lib/cmds/set-build-option cjs && rollup -c", - "build-dist-esm": "node ./misc/admin/lib/cmds/set-build-option esm browser-lang-all && rollup -c --configModule && mv ./packages/ethers/dist/ethers.esm.min.js ./packages/ethers/dist/ethers-all.esm.min.js && node ./misc/admin/lib/cmds/set-build-option esm && rollup -c --configModule", - "_build-dist": "node ./misc/admin/lib/cmds/echo 'Building dist files...' && npm run build-dist-shims && npm run build-dist-esm && npm run build-dist-ancillary && npm run build-dist-umd", + "_reset-build": "node ./misc/admin/lib/cmds/set-build-option cjs", + "_esm-alias": "node ./misc/admin/lib/cmds/echo 'Bundling ESM elliptic (lib._esm/browser-elliptic.js)...' && rollup -c rollup-pre-alias.config.js && node misc/admin/lib/cmds/esm-alias", + "build-libs": "node ./misc/admin/lib/cmds/update-exports.js && node ./misc/admin/lib/cmds/bundle-testcases && npm run _build-cjs && npm run _build-esm && npm _reset-build && node packages/asm/generate.js && npm run _esm-alias && chmod 755 packages/*/lib/bin/*.js", + "build-dist-shims": "rollup -c rollup-shims.config.js && uglifyjs --compress --mangle --output ./packages/shims/dist/index.min.js -- ./packages/shims/dist/index.js", + "build-dist-libs": "rollup -c rollup-dist.config.js && uglifyjs packages/ethers/dist/ethers.umd.js --output packages/ethers/dist/ethers.umd.min.js --source-map 'content=packages/ethers/dist/ethers.umd.js.map' && uglifyjs packages/ethers/dist/ethers.esm.js --output packages/ethers/dist/ethers.esm.min.js --source-map 'content=packages/ethers/dist/ethers.esm.js.map'", + "_build-dist": "node ./misc/admin/lib/cmds/echo 'Building dist files...' && npm run build-dist-libs && npm run build-dist-shims", "build-dist": "node ./misc/admin/lib/cmds/npm-skip-node8.js || npm run _build-dist", - "build-libs": "node ./misc/admin/lib/cmds/update-exports.js && npm run _build-cjs && npm run _build-esm && node ./misc/admin/lib/cmds/set-build-option cjs && node packages/asm/generate.js && chmod 755 packages/*/lib/bin/*.js", "build-all": "npm run build-libs && npm run build-dist", "update-versions": "npm run clean && npm install && npm run spell-check && npm run build-all && node ./misc/admin/lib/cmds/bump-versions && npm run build-all && node ./misc/admin/lib/cmds/update-hashes && node ./misc/admin/lib/cmds/update-changelog", "publish-all": "node ./misc/admin/lib/cmds/publish", "TODO-sync-github": "node ./admin/cmds/cache-github" }, "devDependencies": { - "@erquhart/rollup-plugin-node-builtins": "2.1.5", + "@rollup/plugin-commonjs": "15.1.0", + "@rollup/plugin-json": "4.1.0", + "@rollup/plugin-node-resolve": "9.0.0", + "@rollup/plugin-replace": "2.3.3", "@types/assert": "^1.4.1", "@types/mocha": "^5.2.0", "@types/node": "^12.7.4", "@types/semver": "^7.3.4", "aes-js": "3.0.0", "aws-sdk": "2.137.0", - "browserify": "16.2.3", "diff": "4.0.1", "flatworm": "0.0.2-beta.5", "jison": "^0.4.18", @@ -61,23 +62,21 @@ "mocha": "^7.1.1", "nyc": "15.1.0", "rollup": "1.20.1", - "rollup-plugin-commonjs": "10.0.2", - "rollup-plugin-json": "4.0.0", - "rollup-plugin-node-globals": "1.4.0", - "rollup-plugin-node-resolve": "5.2.0", - "rollup-plugin-terser": "^7.0.0", - "rollup-pluginutils": "2.8.1", + "rollup-plugin-node-polyfills": "0.2.1", + "rollup-plugin-sourcemaps": "0.6.3", "scrypt-js": "3.0.1", "semver": "^5.6.0", "typescript": "3.8.3", - "uglify-es": "3.3.9" + "uglify-es": "3.3.9", + "webpack": "^4.44.2", + "webpack-cli": "4.1.0" }, "dependencies": { "@babel/parser": "7.8.4", "@babel/types": "7.8.3", - "@ledgerhq/hw-app-eth": "5.3.0", - "@ledgerhq/hw-transport": "5.3.0", - "@ledgerhq/hw-transport-u2f": "5.3.0", + "@ledgerhq/hw-app-eth": "5.27.2", + "@ledgerhq/hw-transport": "5.26.0", + "@ledgerhq/hw-transport-u2f": "5.26.0", "@types/mocha": "^5.2.0", "aes-js": "3.0.0", "bech32": "1.1.4", @@ -90,6 +89,7 @@ "scrypt-js": "3.0.1", "solc": "0.7.1", "solidity-parser-antlr": "^0.3.2", + "tiny-inflate": "1.0.3", "ws": "7.2.3" } } diff --git a/packages/abi/.npmignore b/packages/abi/.npmignore index e7beba2762..b7be998f17 100644 --- a/packages/abi/.npmignore +++ b/packages/abi/.npmignore @@ -1,4 +1,4 @@ .DS_Store tsconfig.json -src.ts/ +lib._esm tsconfig.tsbuildinfo diff --git a/packages/abi/package.json b/packages/abi/package.json index 5d80882589..c90960945d 100644 --- a/packages/abi/package.json +++ b/packages/abi/package.json @@ -19,7 +19,7 @@ ], "license": "MIT", "main": "./lib/index.js", - "module": "./lib.esm/index.js", + "module": "./lib.module/index.js", "name": "@ethersproject/abi", "publishConfig": { "access": "public" diff --git a/packages/abstract-provider/.npmignore b/packages/abstract-provider/.npmignore index e7beba2762..b7be998f17 100644 --- a/packages/abstract-provider/.npmignore +++ b/packages/abstract-provider/.npmignore @@ -1,4 +1,4 @@ .DS_Store tsconfig.json -src.ts/ +lib._esm tsconfig.tsbuildinfo diff --git a/packages/abstract-provider/package.json b/packages/abstract-provider/package.json index 47006ae073..42655941dd 100644 --- a/packages/abstract-provider/package.json +++ b/packages/abstract-provider/package.json @@ -17,7 +17,7 @@ ], "license": "MIT", "main": "./lib/index.js", - "module": "./lib.esm/index.js", + "module": "./lib.module/index.js", "name": "@ethersproject/abstract-provider", "publishConfig": { "access": "public" @@ -29,6 +29,7 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, + "sideEffects": false, "tarballHash": "0x87fdc7d7ee69d8c228c0e6946be702acd027a832b5a3deaa5b60e3c9f7110e58", "types": "./lib/index.d.ts", "version": "5.0.5" diff --git a/packages/abstract-signer/.npmignore b/packages/abstract-signer/.npmignore index e7beba2762..b7be998f17 100644 --- a/packages/abstract-signer/.npmignore +++ b/packages/abstract-signer/.npmignore @@ -1,4 +1,4 @@ .DS_Store tsconfig.json -src.ts/ +lib._esm tsconfig.tsbuildinfo diff --git a/packages/abstract-signer/package.json b/packages/abstract-signer/package.json index a1386aa074..3012f1a666 100644 --- a/packages/abstract-signer/package.json +++ b/packages/abstract-signer/package.json @@ -15,7 +15,7 @@ ], "license": "MIT", "main": "./lib/index.js", - "module": "./lib.esm/index.js", + "module": "./lib.module/index.js", "name": "@ethersproject/abstract-signer", "publishConfig": { "access": "public" @@ -27,6 +27,7 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, + "sideEffects": false, "tarballHash": "0x722fb4b5e18bb70cda3c2fbd250d96bacdbe7d358c4c426a73d262fc1f751845", "types": "./lib/index.d.ts", "version": "5.0.7" diff --git a/packages/address/.npmignore b/packages/address/.npmignore index e7beba2762..b7be998f17 100644 --- a/packages/address/.npmignore +++ b/packages/address/.npmignore @@ -1,4 +1,4 @@ .DS_Store tsconfig.json -src.ts/ +lib._esm tsconfig.tsbuildinfo diff --git a/packages/address/package.json b/packages/address/package.json index b0c9eb5c65..fd6bf5a22c 100644 --- a/packages/address/package.json +++ b/packages/address/package.json @@ -5,8 +5,7 @@ "@ethersproject/bytes": "^5.0.4", "@ethersproject/keccak256": "^5.0.3", "@ethersproject/logger": "^5.0.5", - "@ethersproject/rlp": "^5.0.3", - "bn.js": "^4.4.0" + "@ethersproject/rlp": "^5.0.3" }, "description": "Utilities for handling Ethereum Addresses for ethers.", "ethereum": "donations.ethers.eth", @@ -16,7 +15,7 @@ ], "license": "MIT", "main": "./lib/index.js", - "module": "./lib.esm/index.js", + "module": "./lib.module/index.js", "name": "@ethersproject/address", "publishConfig": { "access": "public" @@ -28,6 +27,7 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, + "sideEffects": false, "tarballHash": "0xd6263c8653bc6784fed703b8a30075630c544e3861f43ed5b49ab56ffb5d4808", "types": "./lib/index.d.ts", "version": "5.0.5" diff --git a/packages/address/src.ts/index.ts b/packages/address/src.ts/index.ts index bba8a810cd..661d70ecf5 100644 --- a/packages/address/src.ts/index.ts +++ b/packages/address/src.ts/index.ts @@ -1,10 +1,7 @@ "use strict"; -// We use this for base 36 maths -import { BN } from "bn.js"; - import { arrayify, BytesLike, concat, hexDataLength, hexDataSlice, isHexString, stripZeros } from "@ethersproject/bytes"; -import { BigNumber, BigNumberish } from "@ethersproject/bignumber"; +import { BigNumber, BigNumberish, _base16To36, _base36To16 } from "@ethersproject/bignumber"; import { keccak256 } from "@ethersproject/keccak256"; import { encode } from "@ethersproject/rlp"; @@ -104,7 +101,7 @@ export function getAddress(address: string): string { logger.throwArgumentError("bad icap checksum", "address", address); } - result = (new BN(address.substring(4), 36)).toString(16); + result = _base36To16(address.substring(4)); while (result.length < 40) { result = "0" + result; } result = getChecksumAddress("0x" + result); @@ -124,7 +121,7 @@ export function isAddress(address: string): boolean { } export function getIcapAddress(address: string): string { - let base36 = (new BN(getAddress(address).substring(2), 16)).toString(36).toUpperCase(); + let base36 = _base16To36(getAddress(address).substring(2)).toUpperCase(); while (base36.length < 30) { base36 = "0" + base36; } return "XE" + ibanChecksum("XE00" + base36) + base36; } diff --git a/packages/asm/.npmignore b/packages/asm/.npmignore index e7beba2762..b7be998f17 100644 --- a/packages/asm/.npmignore +++ b/packages/asm/.npmignore @@ -1,4 +1,4 @@ .DS_Store tsconfig.json -src.ts/ +lib._esm tsconfig.tsbuildinfo diff --git a/packages/asm/generate.js b/packages/asm/generate.js index 43086d66e6..612d9df620 100644 --- a/packages/asm/generate.js +++ b/packages/asm/generate.js @@ -11,4 +11,12 @@ const parser = new jison.Parser(grammar); const parserSource = parser.generate({ moduleName: "parser" }); +const esmSuffix = ` + +// Added By ../generate.js +const parse = exports.parse; +export { parse, parser } +`; + fs.writeFileSync(resolve(__dirname, "./lib/_parser.js"), parserSource); +fs.writeFileSync(resolve(__dirname, "./lib._esm/_parser.js"), parserSource + esmSuffix); diff --git a/packages/asm/package.json b/packages/asm/package.json index 29282de571..d34a7e63ea 100644 --- a/packages/asm/package.json +++ b/packages/asm/package.json @@ -12,7 +12,7 @@ ], "license": "MIT", "main": "./lib/index.js", - "module": "./lib.esm/index.js", + "module": "./lib.module/index.js", "name": "@ethersproject/asm", "publishConfig": { "access": "public" diff --git a/packages/base64/.npmignore b/packages/base64/.npmignore index e7beba2762..b7be998f17 100644 --- a/packages/base64/.npmignore +++ b/packages/base64/.npmignore @@ -1,4 +1,4 @@ .DS_Store tsconfig.json -src.ts/ +lib._esm tsconfig.tsbuildinfo diff --git a/packages/base64/package.json b/packages/base64/package.json index 3687a3ba62..037dd51b80 100644 --- a/packages/base64/package.json +++ b/packages/base64/package.json @@ -1,4 +1,7 @@ { + "_ethers.alias": { + "base64.js": "browser-base64.js" + }, "author": "Richard Moore ", "browser": "./lib/browser.js", "browser.esm": "./lib.esm/browser.js", @@ -14,7 +17,7 @@ ], "license": "MIT", "main": "./lib/index.js", - "module": "./lib.esm/index.js", + "module": "./lib.module/index.js", "name": "@ethersproject/base64", "publishConfig": { "access": "public" @@ -26,6 +29,7 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, + "sideEffects": false, "tarballHash": "0xf9edd66aa5131bf0bca2ea188265e0e333d781e4b0ef5e92090a7cef8556cb30", "types": "./lib/index.d.ts", "version": "5.0.4" diff --git a/packages/base64/src.ts/base64.ts b/packages/base64/src.ts/base64.ts new file mode 100644 index 0000000000..c6f84a0cc2 --- /dev/null +++ b/packages/base64/src.ts/base64.ts @@ -0,0 +1,12 @@ +"use strict"; + +import { arrayify, BytesLike } from "@ethersproject/bytes"; + + +export function decode(textData: string): Uint8Array { + return arrayify(new Uint8Array(Buffer.from(textData, "base64"))); +}; + +export function encode(data: BytesLike): string { + return Buffer.from(arrayify(data)).toString("base64"); +} diff --git a/packages/base64/src.ts/browser.ts b/packages/base64/src.ts/browser-base64.ts similarity index 100% rename from packages/base64/src.ts/browser.ts rename to packages/base64/src.ts/browser-base64.ts diff --git a/packages/base64/src.ts/index.ts b/packages/base64/src.ts/index.ts index c6f84a0cc2..5abfcec429 100644 --- a/packages/base64/src.ts/index.ts +++ b/packages/base64/src.ts/index.ts @@ -1,12 +1,3 @@ "use strict"; -import { arrayify, BytesLike } from "@ethersproject/bytes"; - - -export function decode(textData: string): Uint8Array { - return arrayify(new Uint8Array(Buffer.from(textData, "base64"))); -}; - -export function encode(data: BytesLike): string { - return Buffer.from(arrayify(data)).toString("base64"); -} +export { decode, encode } from "./base64"; diff --git a/packages/basex/.npmignore b/packages/basex/.npmignore index e7beba2762..b7be998f17 100644 --- a/packages/basex/.npmignore +++ b/packages/basex/.npmignore @@ -1,4 +1,4 @@ .DS_Store tsconfig.json -src.ts/ +lib._esm tsconfig.tsbuildinfo diff --git a/packages/basex/package.json b/packages/basex/package.json index ea5bdb3bd9..88ef7a44f5 100644 --- a/packages/basex/package.json +++ b/packages/basex/package.json @@ -12,7 +12,7 @@ ], "license": "MIT", "main": "./lib/index.js", - "module": "./lib.esm/index.js", + "module": "./lib.module/index.js", "name": "@ethersproject/basex", "publishConfig": { "access": "public" @@ -24,6 +24,7 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, + "sideEffects": false, "tarballHash": "0x680c45cf36dc0bc442c80238ff9fbfc482b7ac0486c24559c349277f395e0fa9", "types": "./lib/index.d.ts", "version": "5.0.4" diff --git a/packages/bignumber/.npmignore b/packages/bignumber/.npmignore index e7beba2762..b7be998f17 100644 --- a/packages/bignumber/.npmignore +++ b/packages/bignumber/.npmignore @@ -1,4 +1,4 @@ .DS_Store tsconfig.json -src.ts/ +lib._esm tsconfig.tsbuildinfo diff --git a/packages/bignumber/package.json b/packages/bignumber/package.json index b1e6d78fbf..15df04998b 100644 --- a/packages/bignumber/package.json +++ b/packages/bignumber/package.json @@ -26,6 +26,7 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, + "sideEffects": false, "tarballHash": "0x13de0d9c0138d0d056ed658b8f8744fab45fcdf4b52dcd9456bfd7285a4288ce", "types": "./lib/index.d.ts", "version": "5.0.8" diff --git a/packages/bignumber/src.ts/bignumber.ts b/packages/bignumber/src.ts/bignumber.ts index 285eb1ea1c..7ea760f388 100644 --- a/packages/bignumber/src.ts/bignumber.ts +++ b/packages/bignumber/src.ts/bignumber.ts @@ -8,7 +8,8 @@ * */ -import { BN } from "bn.js"; +import _BN from "bn.js"; +import BN = _BN.BN; import { Bytes, Hexable, hexlify, isBytes, isHexString } from "@ethersproject/bytes"; @@ -334,3 +335,13 @@ function throwFault(fault: string, operation: string, value?: any): never { return logger.throwError(fault, Logger.errors.NUMERIC_FAULT, params); } + +// value should have no prefix +export function _base36To16(value: string): string { + return (new BN(value, 36)).toString(16); +} + +// value should have no prefix +export function _base16To36(value: string): string { + return (new BN(value, 16)).toString(36); +} diff --git a/packages/bignumber/src.ts/index.ts b/packages/bignumber/src.ts/index.ts index 1c8551bc58..b089018af0 100644 --- a/packages/bignumber/src.ts/index.ts +++ b/packages/bignumber/src.ts/index.ts @@ -1,2 +1,5 @@ export { BigNumber, BigNumberish } from "./bignumber"; export { formatFixed, FixedFormat, FixedNumber, parseFixed } from "./fixednumber"; + +// Internal methods used by address +export { _base16To36, _base36To16 } from "./bignumber"; diff --git a/packages/bytes/.npmignore b/packages/bytes/.npmignore index e7beba2762..b7be998f17 100644 --- a/packages/bytes/.npmignore +++ b/packages/bytes/.npmignore @@ -1,4 +1,4 @@ .DS_Store tsconfig.json -src.ts/ +lib._esm tsconfig.tsbuildinfo diff --git a/packages/bytes/package.json b/packages/bytes/package.json index 2d829be792..7436e74507 100644 --- a/packages/bytes/package.json +++ b/packages/bytes/package.json @@ -11,7 +11,7 @@ ], "license": "MIT", "main": "./lib/index.js", - "module": "./lib.esm/index.js", + "module": "./lib.module/index.js", "name": "@ethersproject/bytes", "publishConfig": { "access": "public" @@ -25,6 +25,7 @@ "build": "tsc -p ./tsconfig.json", "test": "echo \"Error: no test specified\" && exit 1" }, + "sideEffects": false, "tarballHash": "0x132538d3d8927299393c28ac01243ebc0e7ea34f5af1feadf23b364745f7c130", "types": "./lib/index.d.ts", "version": "5.0.5" diff --git a/packages/cli/.npmignore b/packages/cli/.npmignore index e7beba2762..b7be998f17 100644 --- a/packages/cli/.npmignore +++ b/packages/cli/.npmignore @@ -1,4 +1,4 @@ .DS_Store tsconfig.json -src.ts/ +lib._esm tsconfig.tsbuildinfo diff --git a/packages/constants/.npmignore b/packages/constants/.npmignore index e7beba2762..b7be998f17 100644 --- a/packages/constants/.npmignore +++ b/packages/constants/.npmignore @@ -1,4 +1,4 @@ .DS_Store tsconfig.json -src.ts/ +lib._esm tsconfig.tsbuildinfo diff --git a/packages/constants/package.json b/packages/constants/package.json index b7e4ba5c3a..989f177158 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -23,6 +23,7 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, + "sideEffects": false, "tarballHash": "0x638edaa4b45c46158073ede9fda2c54d6c60a2f11485e693021c484076970130", "types": "./lib/index.d.ts", "version": "5.0.5" diff --git a/packages/constants/src.ts/addresses.ts b/packages/constants/src.ts/addresses.ts new file mode 100644 index 0000000000..89a66bb37d --- /dev/null +++ b/packages/constants/src.ts/addresses.ts @@ -0,0 +1,2 @@ +export const AddressZero = "0x0000000000000000000000000000000000000000"; + diff --git a/packages/constants/src.ts/bignumbers.ts b/packages/constants/src.ts/bignumbers.ts new file mode 100644 index 0000000000..3e827626e6 --- /dev/null +++ b/packages/constants/src.ts/bignumbers.ts @@ -0,0 +1,17 @@ +import { BigNumber } from "@ethersproject/bignumber"; + +const NegativeOne: BigNumber = (/*#__PURE__*/BigNumber.from(-1)); +const Zero: BigNumber = (/*#__PURE__*/BigNumber.from(0)); +const One: BigNumber = (/*#__PURE__*/BigNumber.from(1)); +const Two: BigNumber = (/*#__PURE__*/BigNumber.from(2)); +const WeiPerEther: BigNumber = (/*#__PURE__*/BigNumber.from("1000000000000000000")); +const MaxUint256: BigNumber = (/*#__PURE__*/BigNumber.from("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")); + +export { + NegativeOne, + Zero, + One, + Two, + WeiPerEther, + MaxUint256 +}; diff --git a/packages/constants/src.ts/hashes.ts b/packages/constants/src.ts/hashes.ts new file mode 100644 index 0000000000..d8c1eedaf0 --- /dev/null +++ b/packages/constants/src.ts/hashes.ts @@ -0,0 +1,2 @@ +export const HashZero = "0x0000000000000000000000000000000000000000000000000000000000000000"; + diff --git a/packages/constants/src.ts/index.ts b/packages/constants/src.ts/index.ts index 56a9accc74..ba301df170 100644 --- a/packages/constants/src.ts/index.ts +++ b/packages/constants/src.ts/index.ts @@ -1,30 +1,14 @@ "use strict"; -import { BigNumber } from "@ethersproject/bignumber"; - -const AddressZero = "0x0000000000000000000000000000000000000000"; -const HashZero = "0x0000000000000000000000000000000000000000000000000000000000000000"; - -// NFKC (composed) // (decomposed) -const EtherSymbol = "\u039e"; // "\uD835\uDF63"; - -const NegativeOne: BigNumber = BigNumber.from(-1); -const Zero: BigNumber = BigNumber.from(0); -const One: BigNumber = BigNumber.from(1); -const Two: BigNumber = BigNumber.from(2); -const WeiPerEther: BigNumber = BigNumber.from("1000000000000000000"); -const MaxUint256: BigNumber = BigNumber.from("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); - +export { AddressZero } from "./addresses"; export { - AddressZero, - HashZero, - - EtherSymbol, - NegativeOne, Zero, One, Two, WeiPerEther, MaxUint256 -}; +} from "./bignumbers"; +export { HashZero } from "./hashes"; +export { EtherSymbol } from "./strings"; + diff --git a/packages/constants/src.ts/strings.ts b/packages/constants/src.ts/strings.ts new file mode 100644 index 0000000000..bf87422c00 --- /dev/null +++ b/packages/constants/src.ts/strings.ts @@ -0,0 +1,2 @@ +// NFKC (composed) // (decomposed) +export const EtherSymbol = "\u039e"; // "\uD835\uDF63"; diff --git a/packages/contracts/.npmignore b/packages/contracts/.npmignore index e7beba2762..b7be998f17 100644 --- a/packages/contracts/.npmignore +++ b/packages/contracts/.npmignore @@ -1,4 +1,4 @@ .DS_Store tsconfig.json -src.ts/ +lib._esm tsconfig.tsbuildinfo diff --git a/packages/contracts/package.json b/packages/contracts/package.json index 4781ebfdf4..9e98298585 100644 --- a/packages/contracts/package.json +++ b/packages/contracts/package.json @@ -31,6 +31,7 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, + "sideEffects": false, "tarballHash": "0x82fb83236d1d58cf1e61bbb0b5cb6c268733ce68facdc1d247aa11527808fd20", "types": "./lib/index.d.ts", "version": "5.0.5" diff --git a/packages/ethers/.npmignore b/packages/ethers/.npmignore index e7beba2762..b7be998f17 100644 --- a/packages/ethers/.npmignore +++ b/packages/ethers/.npmignore @@ -1,4 +1,4 @@ .DS_Store tsconfig.json -src.ts/ +lib._esm tsconfig.tsbuildinfo diff --git a/packages/ethers/package.json b/packages/ethers/package.json index eca84582bb..a5b4bc95de 100644 --- a/packages/ethers/package.json +++ b/packages/ethers/package.json @@ -1,6 +1,6 @@ { "author": "Richard Moore ", - "browser": "./dist/ethers.umd.js", + "browser-old": "./dist/ethers.umd.js", "dependencies": { "@ethersproject/abi": "5.0.7", "@ethersproject/abstract-provider": "5.0.5", @@ -41,7 +41,8 @@ ], "license": "MIT", "main": "./lib/index.js", - "module": "./dist/ethers.esm.js", + "module": "./lib.esm/index.js", + "module-old": "./dist/ethers.esm.js", "name": "ethers", "repository": { "type": "git", @@ -50,6 +51,7 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, + "sideEffects": false, "tarballHash": "0xf093f00a83d38639d15610b1b52db1512c582d817c0fab52d2e1f0049e748d03", "types": "./lib/index.d.ts", "version": "5.0.19" diff --git a/packages/experimental/.npmignore b/packages/experimental/.npmignore index e7beba2762..b7be998f17 100644 --- a/packages/experimental/.npmignore +++ b/packages/experimental/.npmignore @@ -1,4 +1,4 @@ .DS_Store tsconfig.json -src.ts/ +lib._esm tsconfig.tsbuildinfo diff --git a/packages/experimental/package.json b/packages/experimental/package.json index a53d473425..c929ab034f 100644 --- a/packages/experimental/package.json +++ b/packages/experimental/package.json @@ -13,7 +13,7 @@ ], "license": "MIT", "main": "./lib/index.js", - "module": "./lib.esm/index.js", + "module": "./lib.module/index.js", "name": "@ethersproject/experimental", "publishConfig": { "access": "public" @@ -25,6 +25,7 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, + "sideEffects": false, "tarballHash": "0xe8978b5a1dbec971509704f95cd3ec691693759e40b602977ee2ee4dcaf189b0", "types": "./lib/index.d.ts", "version": "5.0.5" diff --git a/packages/experimental/src.ts/brain-wallet.ts b/packages/experimental/src.ts/brain-wallet.ts index 1494a3d44d..fd9fbade89 100644 --- a/packages/experimental/src.ts/brain-wallet.ts +++ b/packages/experimental/src.ts/brain-wallet.ts @@ -2,7 +2,7 @@ import { ethers } from "ethers"; -import { scrypt } from "scrypt-js"; +import scrypt from "scrypt-js"; import { version } from "./_version"; @@ -34,7 +34,7 @@ export class BrainWallet extends ethers.Wallet { passwordBytes = ethers.utils.arrayify(password); } - return scrypt(passwordBytes, usernameBytes, (1 << 18), 8, 1, 32, progressCallback).then((key: Uint8Array) => { + return scrypt.scrypt(passwordBytes, usernameBytes, (1 << 18), 8, 1, 32, progressCallback).then((key: Uint8Array) => { if (legacy) { return new BrainWallet(key); diff --git a/packages/hardware-wallets/.npmignore b/packages/hardware-wallets/.npmignore index e7beba2762..b7be998f17 100644 --- a/packages/hardware-wallets/.npmignore +++ b/packages/hardware-wallets/.npmignore @@ -1,4 +1,4 @@ .DS_Store tsconfig.json -src.ts/ +lib._esm tsconfig.tsbuildinfo diff --git a/packages/hardware-wallets/package.json b/packages/hardware-wallets/package.json index ef4028e7a9..22a6f5fb35 100644 --- a/packages/hardware-wallets/package.json +++ b/packages/hardware-wallets/package.json @@ -1,4 +1,7 @@ { + "_ethers.alias": { + "ledger-transport.js": "browser-ledger-transport.js" + }, "author": "Richard Moore ", "browser": { "./lib/ledger-transport.js": "./lib/browser-ledger-transport.js", @@ -13,9 +16,9 @@ "ethers": "./lib/browser-ethers.js" }, "dependencies": { - "@ledgerhq/hw-app-eth": "5.3.0", - "@ledgerhq/hw-transport": "5.3.0", - "@ledgerhq/hw-transport-u2f": "5.3.0", + "@ledgerhq/hw-app-eth": "5.27.2", + "@ledgerhq/hw-transport": "5.26.0", + "@ledgerhq/hw-transport-u2f": "5.26.0", "ethers": "^5.0.13" }, "description": "Hardware Wallet support for ethers.", @@ -27,10 +30,10 @@ ], "license": "MIT", "main": "./lib/index.js", - "module": "./lib.esm/index.js", + "module": "./lib.module/index.js", "name": "@ethersproject/hardware-wallets", "optionalDependencies": { - "@ledgerhq/hw-transport-node-hid": "5.3.0" + "@ledgerhq/hw-transport-node-hid": "5.26.0" }, "publishConfig": { "access": "public" diff --git a/packages/hash/.npmignore b/packages/hash/.npmignore index e7beba2762..b7be998f17 100644 --- a/packages/hash/.npmignore +++ b/packages/hash/.npmignore @@ -1,4 +1,4 @@ .DS_Store tsconfig.json -src.ts/ +lib._esm tsconfig.tsbuildinfo diff --git a/packages/hash/package.json b/packages/hash/package.json index 5a2753f43e..550430e2ca 100644 --- a/packages/hash/package.json +++ b/packages/hash/package.json @@ -30,6 +30,7 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, + "sideEffects": false, "tarballHash": "0xd3ced44284f7527cca27da2835c7eaeb117480dc6d459415ece6a672679cd538", "types": "./lib/index.d.ts", "version": "5.0.6" diff --git a/packages/hdnode/.npmignore b/packages/hdnode/.npmignore index e7beba2762..b7be998f17 100644 --- a/packages/hdnode/.npmignore +++ b/packages/hdnode/.npmignore @@ -1,4 +1,4 @@ .DS_Store tsconfig.json -src.ts/ +lib._esm tsconfig.tsbuildinfo diff --git a/packages/hdnode/package.json b/packages/hdnode/package.json index 1185b3cb53..eed37ce978 100644 --- a/packages/hdnode/package.json +++ b/packages/hdnode/package.json @@ -22,7 +22,7 @@ ], "license": "MIT", "main": "./lib/index.js", - "module": "./lib.esm/index.js", + "module": "./lib.module/index.js", "name": "@ethersproject/hdnode", "publishConfig": { "access": "public" @@ -34,6 +34,7 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, + "sideEffects": false, "tarballHash": "0xc198bf952694f69869fa084578b644c4bc0541a0aaf803da3fb026cace875659", "types": "./lib/index.d.ts", "version": "5.0.5" diff --git a/packages/json-wallets/.npmignore b/packages/json-wallets/.npmignore index e7beba2762..b7be998f17 100644 --- a/packages/json-wallets/.npmignore +++ b/packages/json-wallets/.npmignore @@ -1,4 +1,4 @@ .DS_Store tsconfig.json -src.ts/ +lib._esm tsconfig.tsbuildinfo diff --git a/packages/json-wallets/package.json b/packages/json-wallets/package.json index c8e6b737cb..331440ee34 100644 --- a/packages/json-wallets/package.json +++ b/packages/json-wallets/package.json @@ -23,7 +23,7 @@ ], "license": "MIT", "main": "./lib/index.js", - "module": "./lib.esm/index.js", + "module": "./lib.module/index.js", "name": "@ethersproject/json-wallets", "publishConfig": { "access": "public" @@ -35,6 +35,7 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, + "sideEffects": false, "tarballHash": "0xb4a979c5e6fd6dff4caf32dd6f891e9301a8c3855b5674ea32ce4c8c3267b942", "types": "./lib/index.d.ts", "version": "5.0.7" diff --git a/packages/json-wallets/src.ts/keystore.ts b/packages/json-wallets/src.ts/keystore.ts index 490d165ee4..41ea2989ed 100644 --- a/packages/json-wallets/src.ts/keystore.ts +++ b/packages/json-wallets/src.ts/keystore.ts @@ -1,7 +1,7 @@ "use strict"; import aes from "aes-js"; -import * as scrypt from "scrypt-js"; +import scrypt from "scrypt-js"; import { ExternallyOwnedAccount } from "@ethersproject/abstract-signer"; import { getAddress } from "@ethersproject/address"; diff --git a/packages/keccak256/.npmignore b/packages/keccak256/.npmignore index e7beba2762..b7be998f17 100644 --- a/packages/keccak256/.npmignore +++ b/packages/keccak256/.npmignore @@ -1,4 +1,4 @@ .DS_Store tsconfig.json -src.ts/ +lib._esm tsconfig.tsbuildinfo diff --git a/packages/keccak256/package.json b/packages/keccak256/package.json index 7f0e931ff0..ce670d0f0d 100644 --- a/packages/keccak256/package.json +++ b/packages/keccak256/package.json @@ -12,7 +12,7 @@ ], "license": "MIT", "main": "./lib/index.js", - "module": "./lib.esm/index.js", + "module": "./lib.module/index.js", "name": "@ethersproject/keccak256", "publishConfig": { "access": "public" @@ -24,6 +24,7 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, + "sideEffects": false, "tarballHash": "0xa15a28050c6b479c3488697aa5fdc3dec0a74248fbfc8978aac8312c211d2cca", "types": "./lib/index.d.ts", "version": "5.0.4" diff --git a/packages/logger/.npmignore b/packages/logger/.npmignore index e7beba2762..b7be998f17 100644 --- a/packages/logger/.npmignore +++ b/packages/logger/.npmignore @@ -1,4 +1,4 @@ .DS_Store tsconfig.json -src.ts/ +lib._esm tsconfig.tsbuildinfo diff --git a/packages/logger/package.json b/packages/logger/package.json index 6a33db1203..42c53dd457 100644 --- a/packages/logger/package.json +++ b/packages/logger/package.json @@ -8,7 +8,7 @@ ], "license": "MIT", "main": "./lib/index.js", - "module": "./lib.esm/index.js", + "module": "./lib.module/index.js", "name": "@ethersproject/logger", "publishConfig": { "access": "public" @@ -20,6 +20,7 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, + "sideEffects": false, "tarballHash": "0xf9537798be6f9a5bf14202fe9222696f1340c305b68b14831fdb8d975c53de7d", "types": "./lib/index.d.ts", "version": "5.0.6" diff --git a/packages/logger/src.ts/index.ts b/packages/logger/src.ts/index.ts index 7edc77263e..2cb6c70ddf 100644 --- a/packages/logger/src.ts/index.ts +++ b/packages/logger/src.ts/index.ts @@ -336,4 +336,8 @@ export class Logger { } _logLevel = level; } + + static from(version: string): Logger { + return new Logger(version); + } } diff --git a/packages/networks/.npmignore b/packages/networks/.npmignore index e7beba2762..b7be998f17 100644 --- a/packages/networks/.npmignore +++ b/packages/networks/.npmignore @@ -1,4 +1,4 @@ .DS_Store tsconfig.json -src.ts/ +lib._esm tsconfig.tsbuildinfo diff --git a/packages/networks/package.json b/packages/networks/package.json index 83bfc9123e..45fd1e6134 100644 --- a/packages/networks/package.json +++ b/packages/networks/package.json @@ -11,7 +11,7 @@ ], "license": "MIT", "main": "./lib/index.js", - "module": "./lib.esm/index.js", + "module": "./lib.module/index.js", "name": "@ethersproject/networks", "publishConfig": { "access": "public" @@ -23,6 +23,7 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, + "sideEffects": false, "tarballHash": "0xedc2324ccf327f94bdd5488dc6b791873ff73f49022fd98fbb26da79fb304e85", "types": "./lib/index.d.ts", "version": "5.0.4" diff --git a/packages/pbkdf2/.npmignore b/packages/pbkdf2/.npmignore index e7beba2762..b7be998f17 100644 --- a/packages/pbkdf2/.npmignore +++ b/packages/pbkdf2/.npmignore @@ -1,4 +1,4 @@ .DS_Store tsconfig.json -src.ts/ +lib._esm tsconfig.tsbuildinfo diff --git a/packages/pbkdf2/package.json b/packages/pbkdf2/package.json index 606c33858c..05bcfe4cdd 100644 --- a/packages/pbkdf2/package.json +++ b/packages/pbkdf2/package.json @@ -1,8 +1,17 @@ { + "_ethers.alias": { + "pbkdf2.js": "browser-pbkdf2.js" + }, "author": "Richard Moore ", - "browser": "./lib/browser.js", - "browser.esm": "./lib.esm/browser.js", - "browser.umd": "./lib/browser.js", + "browser": { + "./lib/pbkdf2": "./lib/browser-pbkdf2.js" + }, + "browser.esm": { + "./lib.esm/pbkdf2": "./lib.esm/browser-pbkdf2.js" + }, + "browser.umd": { + "./lib/pbkdf2": "./lib/browser-pbkdf2.js" + }, "dependencies": { "@ethersproject/bytes": "^5.0.4", "@ethersproject/sha2": "^5.0.3" @@ -16,7 +25,7 @@ ], "license": "MIT", "main": "./lib/index.js", - "module": "./lib.esm/index.js", + "module": "./lib.module/index.js", "name": "@ethersproject/pbkdf2", "publishConfig": { "access": "public" @@ -28,6 +37,7 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, + "sideEffects": false, "tarballHash": "0xdc38ff486e5c21e43a6da0dbdb35a5fc32ae529fdee17d7ce8d207863bbfce7e", "types": "./lib/index.d.ts", "version": "5.0.4" diff --git a/packages/pbkdf2/src.ts/browser.ts b/packages/pbkdf2/src.ts/browser-pbkdf2.ts similarity index 85% rename from packages/pbkdf2/src.ts/browser.ts rename to packages/pbkdf2/src.ts/browser-pbkdf2.ts index 41a5bd39dc..9203fb8860 100644 --- a/packages/pbkdf2/src.ts/browser.ts +++ b/packages/pbkdf2/src.ts/browser-pbkdf2.ts @@ -3,7 +3,7 @@ import { arrayify, BytesLike, hexlify } from "@ethersproject/bytes"; import { computeHmac, SupportedAlgorithm } from "@ethersproject/sha2"; -export function pbkdf2(password: BytesLike, salt: BytesLike, iterations: number, keylen: number, hashAlgorithm: SupportedAlgorithm): string { +export function pbkdf2(password: BytesLike, salt: BytesLike, iterations: number, keylen: number, hashAlgorithm: string): string { password = arrayify(password); salt = arrayify(salt); let hLen; @@ -24,7 +24,7 @@ export function pbkdf2(password: BytesLike, salt: BytesLike, iterations: number, block1[salt.length + 3] = i & 0xff; //let U = createHmac(password).update(block1).digest(); - let U = arrayify(computeHmac(hashAlgorithm, password, block1)); + let U = arrayify(computeHmac(hashAlgorithm, password, block1)); if (!hLen) { hLen = U.length @@ -39,7 +39,7 @@ export function pbkdf2(password: BytesLike, salt: BytesLike, iterations: number, for (let j = 1; j < iterations; j++) { //U = createHmac(password).update(U).digest(); - U = arrayify(computeHmac(hashAlgorithm, password, U)); + U = arrayify(computeHmac(hashAlgorithm, password, U)); for (let k = 0; k < hLen; k++) T[k] ^= U[k] } diff --git a/packages/pbkdf2/src.ts/index.ts b/packages/pbkdf2/src.ts/index.ts index b67190e35b..a19a781c30 100644 --- a/packages/pbkdf2/src.ts/index.ts +++ b/packages/pbkdf2/src.ts/index.ts @@ -1,14 +1,2 @@ -"use strict"; -import { pbkdf2Sync as _pbkdf2 } from "crypto"; - -import { arrayify, BytesLike, hexlify } from "@ethersproject/bytes"; - - -function bufferify(value: BytesLike): Buffer { - return Buffer.from(arrayify(value)); -} - -export function pbkdf2(password: BytesLike, salt: BytesLike, iterations: number, keylen: number, hashAlgorithm: string): string { - return hexlify(_pbkdf2(bufferify(password), bufferify(salt), iterations, keylen, hashAlgorithm)); -} +export { pbkdf2 } from "./pbkdf2"; diff --git a/packages/pbkdf2/src.ts/pbkdf2.ts b/packages/pbkdf2/src.ts/pbkdf2.ts new file mode 100644 index 0000000000..b67190e35b --- /dev/null +++ b/packages/pbkdf2/src.ts/pbkdf2.ts @@ -0,0 +1,14 @@ +"use strict"; + +import { pbkdf2Sync as _pbkdf2 } from "crypto"; + +import { arrayify, BytesLike, hexlify } from "@ethersproject/bytes"; + + +function bufferify(value: BytesLike): Buffer { + return Buffer.from(arrayify(value)); +} + +export function pbkdf2(password: BytesLike, salt: BytesLike, iterations: number, keylen: number, hashAlgorithm: string): string { + return hexlify(_pbkdf2(bufferify(password), bufferify(salt), iterations, keylen, hashAlgorithm)); +} diff --git a/packages/properties/.npmignore b/packages/properties/.npmignore index e7beba2762..b7be998f17 100644 --- a/packages/properties/.npmignore +++ b/packages/properties/.npmignore @@ -1,4 +1,4 @@ .DS_Store tsconfig.json -src.ts/ +lib._esm tsconfig.tsbuildinfo diff --git a/packages/properties/package.json b/packages/properties/package.json index ff7d978c05..cfd99977d8 100644 --- a/packages/properties/package.json +++ b/packages/properties/package.json @@ -11,7 +11,7 @@ ], "license": "MIT", "main": "./lib/index.js", - "module": "./lib.esm/index.js", + "module": "./lib.module/index.js", "name": "@ethersproject/properties", "publishConfig": { "access": "public" @@ -25,6 +25,7 @@ "build": "tsc -p ./tsconfig.json", "test": "echo \"Error: no test specified\" && exit 1" }, + "sideEffects": false, "tarballHash": "0x1150770f21e18d2b616708ecba357485be3227a8d474ff40edf9ed2603af62b4", "types": "./lib/index.d.ts", "version": "5.0.4" diff --git a/packages/providers/.npmignore b/packages/providers/.npmignore index e7beba2762..b7be998f17 100644 --- a/packages/providers/.npmignore +++ b/packages/providers/.npmignore @@ -1,4 +1,4 @@ .DS_Store tsconfig.json -src.ts/ +lib._esm tsconfig.tsbuildinfo diff --git a/packages/providers/package.json b/packages/providers/package.json index 7e868bd823..39802ea488 100644 --- a/packages/providers/package.json +++ b/packages/providers/package.json @@ -1,4 +1,11 @@ { + "_ethers.alias": { + "browser-net.d.ts": "", + "browser-net.js": "", + "browser-net.js.map": "", + "ipc-provider.js": "browser-ipc-provider.js", + "ws.js": "browser-ws.js" + }, "author": "Richard Moore ", "browser": { "./lib/ipc-provider": "./lib/browser-ipc-provider.js", @@ -8,7 +15,7 @@ "browser.esm": { "./lib.esm/ipc-provider": "./lib.esm/browser-ipc-provider.js", "net": "./lib.esm/browser-net.js", - "ws": "./lib/browser-ws.js" + "ws": "./lib.esm/browser-ws.js" }, "browser.umd": { "./lib/ipc-provider": "./lib/browser-ipc-provider.js", @@ -44,7 +51,7 @@ ], "license": "MIT", "main": "./lib/index.js", - "module": "./lib.esm/index.js", + "module": "./lib.module/index.js", "name": "@ethersproject/providers", "publishConfig": { "access": "public" @@ -56,6 +63,7 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, + "sideEffects": false, "tarballHash": "0x75f5062536d763196c0bb7681f1de3c93f6d747b799f525295039df8c9c46503", "types": "./lib/index.d.ts", "version": "5.0.14" diff --git a/packages/providers/src.ts/base-provider.ts b/packages/providers/src.ts/base-provider.ts index 502af7a40c..ed7c37206a 100644 --- a/packages/providers/src.ts/base-provider.ts +++ b/packages/providers/src.ts/base-provider.ts @@ -16,7 +16,7 @@ import { sha256 } from "@ethersproject/sha2"; import { toUtf8Bytes, toUtf8String } from "@ethersproject/strings"; import { poll } from "@ethersproject/web"; -import { encode, toWords } from "bech32"; +import bech32 from "bech32"; import { Logger } from "@ethersproject/logger"; import { version } from "./_version"; @@ -318,9 +318,9 @@ export class Resolver implements EnsResolver { } if (version >= 0 && bytes.length === 2 + length && length >= 1 && length <= 75) { - const words = toWords(bytes.slice(2)); + const words = bech32.toWords(bytes.slice(2)); words.unshift(version); - return encode(coinInfo.prefix, words); + return bech32.encode(coinInfo.prefix, words); } } diff --git a/packages/providers/src.ts/browser-ipc-provider.ts b/packages/providers/src.ts/browser-ipc-provider.ts index 1cb691a64b..1759a560ea 100644 --- a/packages/providers/src.ts/browser-ipc-provider.ts +++ b/packages/providers/src.ts/browser-ipc-provider.ts @@ -1,3 +1,7 @@ "use strict"; -module.exports.IpcProvider = null; +const IpcProvider: any = null; + +export { + IpcProvider +}; diff --git a/packages/providers/src.ts/browser-net.ts b/packages/providers/src.ts/browser-net.ts index bd540cc7d6..a347d85a8a 100644 --- a/packages/providers/src.ts/browser-net.ts +++ b/packages/providers/src.ts/browser-net.ts @@ -1,3 +1,3 @@ "use strict"; -module.exports = { } +export function connect() { } diff --git a/packages/providers/src.ts/browser-ws.ts b/packages/providers/src.ts/browser-ws.ts index 9b8e04027f..3f6f8db8dd 100644 --- a/packages/providers/src.ts/browser-ws.ts +++ b/packages/providers/src.ts/browser-ws.ts @@ -16,5 +16,6 @@ try { }); } } - -module.exports = WS; +//export default WS; +//module.exports = WS; +export { WS as WebSocket }; diff --git a/packages/providers/src.ts/ipc-provider.ts b/packages/providers/src.ts/ipc-provider.ts index 878549aab8..c011ee8c5b 100644 --- a/packages/providers/src.ts/ipc-provider.ts +++ b/packages/providers/src.ts/ipc-provider.ts @@ -1,6 +1,6 @@ "use strict"; -import net from "net"; +import { connect } from "net"; import { defineReadOnly } from "@ethersproject/properties"; import { Networkish } from "@ethersproject/networks"; @@ -45,7 +45,7 @@ export class IpcProvider extends JsonRpcProvider { return new Promise((resolve, reject) => { let response = Buffer.alloc(0); - let stream = net.connect(this.path); + let stream = connect(this.path); stream.on("data", (data) => { response = Buffer.concat([ response, data ]); diff --git a/packages/providers/src.ts/websocket-provider.ts b/packages/providers/src.ts/websocket-provider.ts index 167a487c8a..cfa82391c0 100644 --- a/packages/providers/src.ts/websocket-provider.ts +++ b/packages/providers/src.ts/websocket-provider.ts @@ -1,13 +1,12 @@ "use strict"; -import WebSocket from "ws"; - import { BigNumber } from "@ethersproject/bignumber"; import { Network, Networkish } from "@ethersproject/networks"; import { defineReadOnly } from "@ethersproject/properties"; import { Event } from "./base-provider"; import { JsonRpcProvider } from "./json-rpc-provider"; +import { WebSocket } from "./ws"; import { Logger } from "@ethersproject/logger"; import { version } from "./_version"; diff --git a/packages/providers/src.ts/ws.ts b/packages/providers/src.ts/ws.ts new file mode 100644 index 0000000000..b3b7a2ed64 --- /dev/null +++ b/packages/providers/src.ts/ws.ts @@ -0,0 +1,3 @@ +import WebSocket from "ws"; + +export { WebSocket } diff --git a/packages/random/.npmignore b/packages/random/.npmignore index e7beba2762..b7be998f17 100644 --- a/packages/random/.npmignore +++ b/packages/random/.npmignore @@ -1,4 +1,4 @@ .DS_Store tsconfig.json -src.ts/ +lib._esm tsconfig.tsbuildinfo diff --git a/packages/random/package.json b/packages/random/package.json index 4ee57c88c7..f6cf20d9ec 100644 --- a/packages/random/package.json +++ b/packages/random/package.json @@ -1,8 +1,17 @@ { + "_ethers.alias": { + "random.js": "browser-random.js" + }, "author": "Richard Moore ", - "browser": "./lib/browser.js", - "browser.esm": "./lib.esm/browser.js", - "browser.umd": "./lib/browser.js", + "browser": { + "./lib/random": "./lib/browser-random.js" + }, + "browser.esm": { + "./lib/random": "./lib.esm/browser-random.js" + }, + "browser.umd": { + "./lib/random": "./lib/browser-random.js" + }, "dependencies": { "@ethersproject/bytes": "^5.0.4", "@ethersproject/logger": "^5.0.5" @@ -16,7 +25,7 @@ ], "license": "MIT", "main": "./lib/index.js", - "module": "./lib.esm/index.js", + "module": "./lib.module/index.js", "name": "@ethersproject/random", "publishConfig": { "access": "public" @@ -28,6 +37,7 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, + "sideEffects": false, "tarballHash": "0x075d32afd4747ad55567bb9ff2da736a10911e202c04e9c61ba879688c82442a", "types": "./lib/index.d.ts", "version": "5.0.4" diff --git a/packages/random/src.ts/browser.ts b/packages/random/src.ts/browser-random.ts similarity index 96% rename from packages/random/src.ts/browser.ts rename to packages/random/src.ts/browser-random.ts index 2499c1332d..0d74b9cbd8 100644 --- a/packages/random/src.ts/browser.ts +++ b/packages/random/src.ts/browser-random.ts @@ -6,8 +6,6 @@ import { Logger } from "@ethersproject/logger"; import { version } from "./_version"; const logger = new Logger(version); -export { shuffled } from "./shuffle"; - let anyGlobal: any = null; try { anyGlobal = (window as any); diff --git a/packages/random/src.ts/index.ts b/packages/random/src.ts/index.ts index 1f3b84a1e5..fb11db4d0c 100644 --- a/packages/random/src.ts/index.ts +++ b/packages/random/src.ts/index.ts @@ -1,12 +1,4 @@ "use strict"; -import { randomBytes as _randomBytes } from "crypto"; - -import { arrayify } from "@ethersproject/bytes"; - +export { randomBytes } from "./random"; export { shuffled } from "./shuffle"; - -export function randomBytes(length: number): Uint8Array { - return arrayify(_randomBytes(length)); -} - diff --git a/packages/random/src.ts/random.ts b/packages/random/src.ts/random.ts new file mode 100644 index 0000000000..1f7dca08f1 --- /dev/null +++ b/packages/random/src.ts/random.ts @@ -0,0 +1,7 @@ +import { randomBytes as _randomBytes } from "crypto"; + +import { arrayify } from "@ethersproject/bytes"; + +export function randomBytes(length: number): Uint8Array { + return arrayify(_randomBytes(length)); +} diff --git a/packages/rlp/.npmignore b/packages/rlp/.npmignore index e7beba2762..b7be998f17 100644 --- a/packages/rlp/.npmignore +++ b/packages/rlp/.npmignore @@ -1,4 +1,4 @@ .DS_Store tsconfig.json -src.ts/ +lib._esm tsconfig.tsbuildinfo diff --git a/packages/rlp/package.json b/packages/rlp/package.json index 1b422d6e53..35050224a6 100644 --- a/packages/rlp/package.json +++ b/packages/rlp/package.json @@ -13,7 +13,7 @@ ], "license": "MIT", "main": "./lib/index.js", - "module": "./lib.esm/index.js", + "module": "./lib.module/index.js", "name": "@ethersproject/rlp", "publishConfig": { "access": "public" @@ -25,6 +25,7 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, + "sideEffects": false, "tarballHash": "0x2a870663cf91328de26e8b3e5cb1ac3004eefa78ffbdad7b08b61c2685c3f018", "types": "./lib/index.d.ts", "version": "5.0.4" diff --git a/packages/sha2/.npmignore b/packages/sha2/.npmignore index e7beba2762..b7be998f17 100644 --- a/packages/sha2/.npmignore +++ b/packages/sha2/.npmignore @@ -1,4 +1,4 @@ .DS_Store tsconfig.json -src.ts/ +lib._esm tsconfig.tsbuildinfo diff --git a/packages/sha2/package.json b/packages/sha2/package.json index 3318332f26..51b808d424 100644 --- a/packages/sha2/package.json +++ b/packages/sha2/package.json @@ -1,8 +1,17 @@ { + "_ethers.alias": { + "sha2.js": "browser-sha2.js" + }, "author": "Richard Moore ", - "browser": "./lib/browser.js", - "browser.esm": "./lib/browser.js", - "browser.umd": "./lib/browser.js", + "browser": { + "./lib/sha2": "./lib/browser-sha2.js" + }, + "browser.esm": { + "./lib.esm/sha2": "./lib.esm/browser-sha2.js" + }, + "browser.umd": { + "./lib/sha2": "./lib/browser-sha2.js" + }, "dependencies": { "@ethersproject/bytes": "^5.0.4", "@ethersproject/logger": "^5.0.5", @@ -16,7 +25,7 @@ ], "license": "MIT", "main": "./lib/index.js", - "module": "./lib.esm/index.js", + "module": "./lib.module/index.js", "name": "@ethersproject/sha2", "publishConfig": { "access": "public" @@ -28,6 +37,7 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, + "sideEffects": false, "tarballHash": "0x7553e7409c1b5deee5301531eeb988b1acef161fb638c31a753f42bbab42b200", "types": "./lib/index.d.ts", "version": "5.0.4" diff --git a/packages/sha2/src.ts/browser.ts b/packages/sha2/src.ts/browser-sha2.ts similarity index 90% rename from packages/sha2/src.ts/browser.ts rename to packages/sha2/src.ts/browser-sha2.ts index fba6525056..f72ac950e3 100644 --- a/packages/sha2/src.ts/browser.ts +++ b/packages/sha2/src.ts/browser-sha2.ts @@ -1,15 +1,16 @@ "use strict"; -import * as hash from "hash.js"; +import hash from "hash.js"; +//const _ripemd160 = _hash.ripemd160; import { arrayify, BytesLike } from "@ethersproject/bytes"; +import { SupportedAlgorithm } from "./types"; + import { Logger } from "@ethersproject/logger"; import { version } from "./_version"; const logger = new Logger(version); -export enum SupportedAlgorithm { sha256 = "sha256", sha512 = "sha512" }; - export function ripemd160(data: BytesLike): string { return "0x" + (hash.ripemd160().update(arrayify(data)).digest("hex")); } @@ -22,7 +23,6 @@ export function sha512(data: BytesLike): string { return "0x" + (hash.sha512().update(arrayify(data)).digest("hex")); } - export function computeHmac(algorithm: SupportedAlgorithm, key: BytesLike, data: BytesLike): string { if (!SupportedAlgorithm[algorithm]) { logger.throwError("unsupported algorithm " + algorithm, Logger.errors.UNSUPPORTED_OPERATION, { diff --git a/packages/sha2/src.ts/index.ts b/packages/sha2/src.ts/index.ts index 21aac5d82b..ac50daa8aa 100644 --- a/packages/sha2/src.ts/index.ts +++ b/packages/sha2/src.ts/index.ts @@ -1,38 +1,14 @@ -"use strict"; +import { computeHmac, ripemd160, sha256, sha512 } from "./sha2"; -import { createHash, createHmac } from 'crypto'; +import { SupportedAlgorithm } from "./types"; -import { arrayify, BytesLike } from '@ethersproject/bytes'; +export { + computeHmac, -import { Logger } from "@ethersproject/logger"; -import { version } from "./_version"; -const logger = new Logger(version); + ripemd160, -export enum SupportedAlgorithm { sha256 = "sha256", sha512 = "sha512" }; + sha256, + sha512, - -export function ripemd160(data: BytesLike): string { - return "0x" + createHash("ripemd160").update(Buffer.from(arrayify(data))).digest("hex") -} - -export function sha256(data: BytesLike): string { - return "0x" + createHash("sha256").update(Buffer.from(arrayify(data))).digest("hex") -} - -export function sha512(data: BytesLike): string { - return "0x" + createHash("sha512").update(Buffer.from(arrayify(data))).digest("hex") + SupportedAlgorithm } - - -export function computeHmac(algorithm: SupportedAlgorithm, key: BytesLike, data: BytesLike): string { - /* istanbul ignore if */ - if (!SupportedAlgorithm[algorithm]) { - logger.throwError("unsupported algorithm - " + algorithm, Logger.errors.UNSUPPORTED_OPERATION, { - operation: "computeHmac", - algorithm: algorithm - }); - } - - return "0x" + createHmac(algorithm, Buffer.from(arrayify(key))).update(Buffer.from(arrayify(data))).digest("hex"); -} - diff --git a/packages/sha2/src.ts/sha2.ts b/packages/sha2/src.ts/sha2.ts new file mode 100644 index 0000000000..71a202a50f --- /dev/null +++ b/packages/sha2/src.ts/sha2.ts @@ -0,0 +1,36 @@ +"use strict"; + +import { createHash, createHmac } from "crypto"; + +import { arrayify, BytesLike } from "@ethersproject/bytes"; + +import { SupportedAlgorithm } from "./types"; + +import { Logger } from "@ethersproject/logger"; +import { version } from "./_version"; +const logger = new Logger(version); + +export function ripemd160(data: BytesLike): string { + return "0x" + createHash("ripemd160").update(Buffer.from(arrayify(data))).digest("hex") +} + +export function sha256(data: BytesLike): string { + return "0x" + createHash("sha256").update(Buffer.from(arrayify(data))).digest("hex") +} + +export function sha512(data: BytesLike): string { + return "0x" + createHash("sha512").update(Buffer.from(arrayify(data))).digest("hex") +} + +export function computeHmac(algorithm: SupportedAlgorithm, key: BytesLike, data: BytesLike): string { + /* istanbul ignore if */ + if (!SupportedAlgorithm[algorithm]) { + logger.throwError("unsupported algorithm - " + algorithm, Logger.errors.UNSUPPORTED_OPERATION, { + operation: "computeHmac", + algorithm: algorithm + }); + } + + return "0x" + createHmac(algorithm, Buffer.from(arrayify(key))).update(Buffer.from(arrayify(data))).digest("hex"); +} + diff --git a/packages/sha2/src.ts/types.ts b/packages/sha2/src.ts/types.ts new file mode 100644 index 0000000000..7560be8aab --- /dev/null +++ b/packages/sha2/src.ts/types.ts @@ -0,0 +1,2 @@ +export enum SupportedAlgorithm { sha256 = "sha256", sha512 = "sha512" }; + diff --git a/packages/signing-key/.npmignore b/packages/signing-key/.npmignore index e7beba2762..b7be998f17 100644 --- a/packages/signing-key/.npmignore +++ b/packages/signing-key/.npmignore @@ -1,4 +1,4 @@ .DS_Store tsconfig.json -src.ts/ +lib._esm tsconfig.tsbuildinfo diff --git a/packages/signing-key/package.json b/packages/signing-key/package.json index 3662d0219f..4533daf906 100644 --- a/packages/signing-key/package.json +++ b/packages/signing-key/package.json @@ -14,7 +14,7 @@ ], "license": "MIT", "main": "./lib/index.js", - "module": "./lib.esm/index.js", + "module": "./lib.module/index.js", "name": "@ethersproject/signing-key", "publishConfig": { "access": "public" @@ -26,6 +26,7 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, + "sideEffects": false, "tarballHash": "0x7cdf71e1b21bab0612477150eae44b06dd82783fe23faa75e0e216c75b93d73c", "types": "./lib/index.d.ts", "version": "5.0.5" diff --git a/packages/signing-key/src.ts/elliptic.ts b/packages/signing-key/src.ts/elliptic.ts new file mode 100644 index 0000000000..2c08ede81e --- /dev/null +++ b/packages/signing-key/src.ts/elliptic.ts @@ -0,0 +1,4 @@ +import _ec from "elliptic"; +import EC = _ec.ec; + +export { EC } diff --git a/packages/signing-key/src.ts/index.ts b/packages/signing-key/src.ts/index.ts index 602d49f7c6..737a40ec13 100644 --- a/packages/signing-key/src.ts/index.ts +++ b/packages/signing-key/src.ts/index.ts @@ -1,6 +1,6 @@ "use strict"; -import { ec as EC } from "elliptic"; +import { EC } from "./elliptic"; import { arrayify, BytesLike, hexlify, hexZeroPad, Signature, SignatureLike, splitSignature } from "@ethersproject/bytes"; import { defineReadOnly } from "@ethersproject/properties"; diff --git a/packages/solidity/.npmignore b/packages/solidity/.npmignore index e7beba2762..b7be998f17 100644 --- a/packages/solidity/.npmignore +++ b/packages/solidity/.npmignore @@ -1,4 +1,4 @@ .DS_Store tsconfig.json -src.ts/ +lib._esm tsconfig.tsbuildinfo diff --git a/packages/solidity/package.json b/packages/solidity/package.json index a9378b66ad..fdd608c40e 100644 --- a/packages/solidity/package.json +++ b/packages/solidity/package.json @@ -15,7 +15,7 @@ ], "license": "MIT", "main": "./lib/index.js", - "module": "./lib.esm/index.js", + "module": "./lib.module/index.js", "name": "@ethersproject/solidity", "publishConfig": { "access": "public" @@ -27,6 +27,7 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, + "sideEffects": false, "tarballHash": "0x112e6ec1297898adabbae7b963a260230addc7b84bd22da84be60419de8f10b2", "types": "./lib/index.d.ts", "version": "5.0.5" diff --git a/packages/strings/.npmignore b/packages/strings/.npmignore index e7beba2762..b7be998f17 100644 --- a/packages/strings/.npmignore +++ b/packages/strings/.npmignore @@ -1,4 +1,4 @@ .DS_Store tsconfig.json -src.ts/ +lib._esm tsconfig.tsbuildinfo diff --git a/packages/strings/package.json b/packages/strings/package.json index bce6082702..b472a14a7c 100644 --- a/packages/strings/package.json +++ b/packages/strings/package.json @@ -27,6 +27,7 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, + "sideEffects": false, "tarballHash": "0x0bb95a9555010137f1bfc3c427ce6750e00bfa6aa98f36c3cf94979b635fda6d", "types": "./lib/index.d.ts", "version": "5.0.5" diff --git a/packages/testcases/.npmignore b/packages/testcases/.npmignore index a3d473f49a..39c4e2a371 100644 --- a/packages/testcases/.npmignore +++ b/packages/testcases/.npmignore @@ -1,6 +1,6 @@ .DS_Store tsconfig.json -src.ts/ -input/ +lib._esm tsconfig.tsbuildinfo +input/ generation/ diff --git a/packages/testcases/src.ts/browser-fs.json b/packages/testcases/browser-fs.json similarity index 62% rename from packages/testcases/src.ts/browser-fs.json rename to packages/testcases/browser-fs.json index 8bf22653ff..ed6bc1ce9a 100644 --- a/packages/testcases/src.ts/browser-fs.json +++ b/packages/testcases/browser-fs.json @@ -1 +1 @@ -{ "dirs": [ "./input/easyseed-bip39", "./testcases", "./input/wordlists" ] } +{ "dirs": [ "./input/easyseed-bip39", "./testcases", "./input/wordlists" ], "content": "__CONTENT__" } diff --git a/packages/testcases/package.json b/packages/testcases/package.json index 0d83baf42b..637481df8e 100644 --- a/packages/testcases/package.json +++ b/packages/testcases/package.json @@ -8,10 +8,19 @@ "ethereumjs-tx": "^1.3.5", "ethereumjs-util": "^5.2.0" }, + "_ethers.alias": { + "disk-utils.js": "browser-disk-utils.js" + }, "author": "Richard Moore ", - "browser": "./lib/browser.js", - "browser.esm": "./lib.esm/browser.js", - "browser.umd": "./lib/browser.js", + "browser": { + "./lib/disk-utils:": "./lib/browser-disk-utils.js" + }, + "browser.esm": { + "./lib.esm/disk-utils:": "./lib.esm/browser-disk-utils.js" + }, + "browser.umd": { + "./lib/disk-utils:": "./lib/browser-disk-utils.js" + }, "dependencies": { "@ethersproject/bignumber": "^5.0.7", "@ethersproject/bytes": "^5.0.4", @@ -28,7 +37,7 @@ ], "license": "MIT", "main": "./lib/index.js", - "module": "./lib.esm/index.js", + "module": "./lib.module/index.js", "name": "@ethersproject/testcases", "publishConfig": { "access": "public" diff --git a/packages/testcases/src.ts/browser-disk-utils.ts b/packages/testcases/src.ts/browser-disk-utils.ts new file mode 100644 index 0000000000..8c3e422547 --- /dev/null +++ b/packages/testcases/src.ts/browser-disk-utils.ts @@ -0,0 +1,41 @@ +'use strict'; + +import inflate from "tiny-inflate"; + +import { ethers } from "ethers"; + +// This file is populated by the rollup-pre-alias.config.js +import data from "./browser-data.json"; + +export function saveTests(tag: string, data: any) { + throw new Error("browser does not support writing testcases"); +} + +const Cache: { [ filename: string ]: any } = { }; +export function loadTests(tag: string): any { + let filename = 'testcases/' + tag + ".json.gz"; + if (Cache[filename] == null) { + console.log(`Loading Test Case: ${ filename }`); + try { + let fileData: string = (data)[filename]; + const comps = fileData.split(","); + const size = parseInt(comps[0]), compressedData = ethers.utils.base64.decode(comps[1]); + const uncompressedData = new Uint8Array(size); + inflate(compressedData, uncompressedData); + Cache[filename] = JSON.parse(ethers.utils.toUtf8String(uncompressedData)); + } catch (error) { + console.log("ERROR", error); + throw error; + } + } + return Cache[filename]; +} + +export function loadData(filename: string): Uint8Array { + // Strip any leading relative paths (e.g. "./foo" => "foo") + filename = filename.replace(/^[^a-z0-9_]/i, ""); + console.log(`Loading Data File: ${ filename }`); + //filename = path.join(filename); + return ethers.utils.base64.decode((data)[filename]); +} + diff --git a/packages/testcases/src.ts/browser.ts b/packages/testcases/src.ts/browser.ts deleted file mode 100644 index 44302ba641..0000000000 --- a/packages/testcases/src.ts/browser.ts +++ /dev/null @@ -1,31 +0,0 @@ -'use strict'; - -import path from 'path'; - -import zlib from "browserify-zlib"; - -import { randomBytes, randomHexString, randomNumber } from "./random"; -export { randomBytes, randomHexString, randomNumber }; - -import * as _data from "./browser-fs.json"; - -// TypeScript, rollup and friends don't play nice with this JSON -const _anyData: any = _data; -const data = _anyData["default"] ? _anyData["default"]: _anyData; - -const Cache: { [ filename: string ]: any } = { }; -export function loadTests(tag: string): any { - let filename = 'testcases/' + tag + ".json.gz"; - if (Cache[filename] == null) { - console.log("loading:", filename); - Cache[filename] = JSON.parse(zlib.gunzipSync(new Buffer((data)[filename], "base64")).toString()); - } - return Cache[filename]; -} - -export function loadData(filename: string): Buffer { - // Strip any leading relative paths (e.g. "./foo" => "foo") - filename = path.join(filename); - console.log("loading:", filename); - return new Buffer((data)[filename], "base64"); -} diff --git a/packages/testcases/src.ts/disk-utils.ts b/packages/testcases/src.ts/disk-utils.ts new file mode 100644 index 0000000000..e7feecd472 --- /dev/null +++ b/packages/testcases/src.ts/disk-utils.ts @@ -0,0 +1,21 @@ +import fs from 'fs'; +import path from 'path'; +import zlib from 'browserify-zlib'; + +export function saveTests(tag: string, data: any) { + //let filename = path.resolve(__dirname, 'testcases', tag + '.json.gz'); + let filename = path.resolve(__dirname, '../testcases', tag + '.json.gz'); + + fs.writeFileSync(filename, zlib.gzipSync(JSON.stringify(data, undefined, ' ') + '\n')); + + console.log('Save testcase: ' + filename); +} + +export function loadTests(tag: string): T { + let filename = path.resolve(__dirname, '../testcases', tag + '.json.gz'); + return JSON.parse(zlib.gunzipSync(fs.readFileSync(filename)).toString()); +} + +export function loadData(filename: string): Buffer { + return fs.readFileSync(path.resolve(__dirname, filename)); +} diff --git a/packages/testcases/src.ts/index.ts b/packages/testcases/src.ts/index.ts index 2243a6e101..9447a7e610 100644 --- a/packages/testcases/src.ts/index.ts +++ b/packages/testcases/src.ts/index.ts @@ -1,8 +1,6 @@ 'use strict'; -import fs from 'fs'; -import path from 'path'; -import zlib from 'browserify-zlib'; +export { loadData, loadTests, saveTests } from "./disk-utils"; import { randomBytes, randomHexString, randomNumber } from "./random"; export { randomBytes, randomHexString, randomNumber }; @@ -10,21 +8,3 @@ export { randomBytes, randomHexString, randomNumber }; import * as TestCase from "./testcases"; export { TestCase }; -export function saveTests(tag: string, data: any) { - //let filename = path.resolve(__dirname, 'testcases', tag + '.json.gz'); - let filename = path.resolve(__dirname, '../testcases', tag + '.json.gz'); - - fs.writeFileSync(filename, zlib.gzipSync(JSON.stringify(data, undefined, ' ') + '\n')); - - console.log('Save testcase: ' + filename); -} - -export function loadTests(tag: string): T { - let filename = path.resolve(__dirname, '../testcases', tag + '.json.gz'); - return JSON.parse(zlib.gunzipSync(fs.readFileSync(filename)).toString()); -} - -export function loadData(filename: string): Buffer { - return fs.readFileSync(path.resolve(__dirname, filename)); -} - diff --git a/packages/tests/.npmignore b/packages/tests/.npmignore index ac87c459d5..348a3dbe33 100644 --- a/packages/tests/.npmignore +++ b/packages/tests/.npmignore @@ -1,5 +1,5 @@ .DS_Store tsconfig.json -src.ts/ dist/ +lib._esm tsconfig.tsbuildinfo diff --git a/packages/tests/src.ts/test-utils.ts b/packages/tests/src.ts/test-utils.ts index 469ac9fb2b..3c7ce6d632 100644 --- a/packages/tests/src.ts/test-utils.ts +++ b/packages/tests/src.ts/test-utils.ts @@ -484,7 +484,7 @@ describe('Test UTF-8 coder', function() { let str2 = ethers.utils.toUtf8String(bytes); let escaped = JSON.parse(ethers.utils._toEscapedUtf8String(bytes)); - assert.ok(Buffer.from(str).equals(Buffer.from(bytes)), 'bytes not generated correctly - ' + bytes) +// assert.ok(Buffer.from(str).equals(Buffer.from(bytes)), 'bytes not generated correctly - ' + bytes) assert.equal(str2, str, 'conversion not reflexive - ' + bytes); assert.equal(escaped, str, 'conversion not reflexive - ' + bytes); } @@ -504,7 +504,7 @@ describe('Test Bytes32String coder', function() { function getHex(value: string): string { - return "0x" + Buffer.from(value).toString("hex"); + return ethers.utils.hexlify(ethers.utils.toUtf8Bytes(value)); } describe("Test nameprep", function() { diff --git a/packages/tests/src.ts/test-wordlists.ts b/packages/tests/src.ts/test-wordlists.ts index 24572861de..0b201c6004 100644 --- a/packages/tests/src.ts/test-wordlists.ts +++ b/packages/tests/src.ts/test-wordlists.ts @@ -8,7 +8,6 @@ import { loadTests, TestCase } from "@ethersproject/testcases"; function checkWordlist(content: string, wordlist: ethers.Wordlist): void { let words = content.split('\n'); - it('matches wordlists for ' + wordlist.locale, function() { for (let i = 0; i < 2048; i++) { let actual = wordlist.getWord(i); @@ -37,6 +36,7 @@ describe('Check Wordlists', function() { let tests: Array = loadTests("wordlists"); tests.forEach((test) => { let wordlist = (<{ [ locale: string ]: ethers.Wordlist }>(ethers.wordlists))[test.locale]; + if (wordlist == null) { return; } checkWordlist(test.content, wordlist); }); }); diff --git a/packages/transactions/.npmignore b/packages/transactions/.npmignore index e7beba2762..b7be998f17 100644 --- a/packages/transactions/.npmignore +++ b/packages/transactions/.npmignore @@ -1,4 +1,4 @@ .DS_Store tsconfig.json -src.ts/ +lib._esm tsconfig.tsbuildinfo diff --git a/packages/transactions/package.json b/packages/transactions/package.json index 259ce44231..81dfb0b7e4 100644 --- a/packages/transactions/package.json +++ b/packages/transactions/package.json @@ -19,7 +19,7 @@ ], "license": "MIT", "main": "./lib/index.js", - "module": "./lib.esm/index.js", + "module": "./lib.module/index.js", "name": "@ethersproject/transactions", "publishConfig": { "access": "public" @@ -31,6 +31,7 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, + "sideEffects": false, "tarballHash": "0x892a42c68798431329aabf5c14b72f357c85b8f0a86439c9f158becf66f7c600", "types": "./lib/index.d.ts", "version": "5.0.6" diff --git a/packages/units/.npmignore b/packages/units/.npmignore index e7beba2762..b7be998f17 100644 --- a/packages/units/.npmignore +++ b/packages/units/.npmignore @@ -1,4 +1,4 @@ .DS_Store tsconfig.json -src.ts/ +lib._esm tsconfig.tsbuildinfo diff --git a/packages/units/package.json b/packages/units/package.json index b8f60682f2..d81dbde0ba 100644 --- a/packages/units/package.json +++ b/packages/units/package.json @@ -15,7 +15,7 @@ ], "license": "MIT", "main": "./lib/index.js", - "module": "./lib.esm/index.js", + "module": "./lib.module/index.js", "name": "@ethersproject/units", "publishConfig": { "access": "public" @@ -27,6 +27,7 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, + "sideEffects": false, "tarballHash": "0xc3a7f3afe0b5e162e36bb100dd05933de763fc0772581103a6b59e3d2c487c9c", "types": "./lib/index.d.ts", "version": "5.0.6" diff --git a/packages/wallet/.npmignore b/packages/wallet/.npmignore index e7beba2762..b7be998f17 100644 --- a/packages/wallet/.npmignore +++ b/packages/wallet/.npmignore @@ -1,4 +1,4 @@ .DS_Store tsconfig.json -src.ts/ +lib._esm tsconfig.tsbuildinfo diff --git a/packages/wallet/package.json b/packages/wallet/package.json index 389af71e67..64588521a8 100644 --- a/packages/wallet/package.json +++ b/packages/wallet/package.json @@ -25,7 +25,7 @@ ], "license": "MIT", "main": "./lib/index.js", - "module": "./lib.esm/index.js", + "module": "./lib.module/index.js", "name": "@ethersproject/wallet", "publishConfig": { "access": "public" @@ -37,6 +37,7 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, + "sideEffects": false, "tarballHash": "0xfb6daa970e4ca698f8d4d47c5f5b0ae099c7da00cfe5dd2f06a6636e24a89d0e", "types": "./lib/index.d.ts", "version": "5.0.7" diff --git a/packages/wallet/src.ts/index.ts b/packages/wallet/src.ts/index.ts index 0b477b2f06..2b9cb76f69 100644 --- a/packages/wallet/src.ts/index.ts +++ b/packages/wallet/src.ts/index.ts @@ -128,7 +128,8 @@ export class Wallet extends Signer implements ExternallyOwnedAccount, TypedDataS const populated = await _TypedDataEncoder.resolveNames(domain, types, value, (name: string) => { if (this.provider == null) { logger.throwError("cannot resolve ENS names without a provider", Logger.errors.UNSUPPORTED_OPERATION, { - operation: "resolveName" + operation: "resolveName", + value: name }); } return this.provider.resolveName(name); diff --git a/packages/web/.npmignore b/packages/web/.npmignore index e7beba2762..b7be998f17 100644 --- a/packages/web/.npmignore +++ b/packages/web/.npmignore @@ -1,4 +1,4 @@ .DS_Store tsconfig.json -src.ts/ +lib._esm tsconfig.tsbuildinfo diff --git a/packages/web/package.json b/packages/web/package.json index 344fe290f7..a8d2d12261 100644 --- a/packages/web/package.json +++ b/packages/web/package.json @@ -1,4 +1,7 @@ { + "_ethers.alias": { + "geturl.js": "browser-geturl.js" + }, "author": "Richard Moore ", "browser": { "./lib/geturl": "./lib/browser-geturl.js" @@ -24,7 +27,7 @@ ], "license": "MIT", "main": "./lib/index.js", - "module": "./lib.esm/index.js", + "module": "./lib.module/index.js", "name": "@ethersproject/web", "publishConfig": { "access": "public" @@ -36,6 +39,7 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, + "sideEffects": false, "tarballHash": "0xffb63ec25a04effef1c5201b55770f2636a338339be2a7b770cc5e8914a6d56b", "types": "./lib/index.d.ts", "version": "5.0.9" diff --git a/packages/wordlists/.npmignore b/packages/wordlists/.npmignore index e7beba2762..b7be998f17 100644 --- a/packages/wordlists/.npmignore +++ b/packages/wordlists/.npmignore @@ -1,4 +1,4 @@ .DS_Store tsconfig.json -src.ts/ +lib._esm tsconfig.tsbuildinfo diff --git a/packages/wordlists/package.json b/packages/wordlists/package.json index 5dee79c1e9..be9a1496cd 100644 --- a/packages/wordlists/package.json +++ b/packages/wordlists/package.json @@ -1,8 +1,17 @@ { + "_ethers.alias": { + "wordlists.js": "browser-wordlists.js" + }, "author": "Richard Moore ", - "browser": "./lib/browser.js", - "browser.esm": "./lib.esm/browser.js", - "browser.umd": "./lib/browser.js", + "browser": { + "./lib/wordlists": "./lib/browser-wordlists.js" + }, + "browser.esm": { + "./lib.esm/wordlists": "./lib.esm/browser-wordlists.js" + }, + "browser.umd": { + "./lib/wordlists": "./lib/browser-wordlists.js" + }, "dependencies": { "@ethersproject/bytes": "^5.0.4", "@ethersproject/hash": "^5.0.4", @@ -18,7 +27,7 @@ ], "license": "MIT", "main": "./lib/index.js", - "module": "./lib.esm/index.js", + "module": "./lib.module/index.js", "name": "@ethersproject/wordlists", "publishConfig": { "access": "public" @@ -30,6 +39,7 @@ "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, + "sideEffects": false, "tarballHash": "0x8f19c86a1036f6ba944c3d17e549fb6e819e522933bbb86e5f0a6b87adf1655a", "types": "./lib/index.d.ts", "version": "5.0.5" diff --git a/packages/wordlists/src.ts/browser.ts b/packages/wordlists/src.ts/browser-wordlists.ts similarity index 63% rename from packages/wordlists/src.ts/browser.ts rename to packages/wordlists/src.ts/browser-wordlists.ts index 80efa93e5a..25409bc28f 100644 --- a/packages/wordlists/src.ts/browser.ts +++ b/packages/wordlists/src.ts/browser-wordlists.ts @@ -3,14 +3,12 @@ // Wordlists // See: https://github.com/bitcoin/bips/blob/master/bip-0039/bip-0039-wordlists.md +// Browser; only include English by default import { Wordlist } from "./wordlist"; import { langEn as en } from "./lang-en"; -const wordlists: { en: Wordlist } = { en: en }; - -export { - Wordlist, - wordlists +export const wordlists: { [ locale: string ]: Wordlist } = { + en: en } diff --git a/packages/wordlists/src.ts/index.ts b/packages/wordlists/src.ts/index.ts index 9fd6c4d1aa..1cd0443a7a 100644 --- a/packages/wordlists/src.ts/index.ts +++ b/packages/wordlists/src.ts/index.ts @@ -5,27 +5,7 @@ import { logger, Wordlist } from "./wordlist"; -import { langCz as cz } from "./lang-cz"; -import { langEn as en } from "./lang-en"; -import { langEs as es } from "./lang-es"; -import { langFr as fr } from "./lang-fr"; -import { langJa as ja } from "./lang-ja"; -import { langKo as ko } from "./lang-ko"; -import { langIt as it } from "./lang-it"; -import { langZhCn as zh_cn, langZhTw as zh_tw } from "./lang-zh"; - -const wordlists: { [ locale: string ]: Wordlist } = { - cz: cz, - en: en, - es: es, - fr: fr, - it: it, - ja: ja, - ko: ko, - zh: zh_cn, - zh_cn: zh_cn, - zh_tw: zh_tw -}; +import { wordlists } from "./wordlists"; export { logger, diff --git a/packages/wordlists/src.ts/wordlists.ts b/packages/wordlists/src.ts/wordlists.ts new file mode 100644 index 0000000000..3ab0393c6b --- /dev/null +++ b/packages/wordlists/src.ts/wordlists.ts @@ -0,0 +1,25 @@ +import { Wordlist } from "./wordlist"; + +import { langCz as cz } from "./lang-cz"; +import { langEn as en } from "./lang-en"; +import { langEs as es } from "./lang-es"; +import { langFr as fr } from "./lang-fr"; +import { langJa as ja } from "./lang-ja"; +import { langKo as ko } from "./lang-ko"; +import { langIt as it } from "./lang-it"; +import { langZhCn as zh_cn, langZhTw as zh_tw } from "./lang-zh"; + +export const wordlists: { [ locale: string ]: Wordlist } = { + cz: cz, + en: en, + es: es, + fr: fr, + it: it, + ja: ja, + ko: ko, + zh: zh_cn, + zh_cn: zh_cn, + zh_tw: zh_tw +}; + + diff --git a/rollup-dist.config.js b/rollup-dist.config.js new file mode 100644 index 0000000000..399625a3ff --- /dev/null +++ b/rollup-dist.config.js @@ -0,0 +1,156 @@ +"use strict"; + +// This files has a lot of overlap with rollup-pre-alias.config.js +// - should we pull some of this functionality out? + +import commonjs from '@rollup/plugin-commonjs'; +import resolveNode from "@rollup/plugin-node-resolve"; +import replace from "@rollup/plugin-replace"; + +import sourcemaps from 'rollup-plugin-sourcemaps'; + +// We only need this for its version (we inject it into a require) +import elliptic from "elliptic"; + +function addUtilsReplace(plugins) { + + // Remove the buffer check from BN.js + plugins.push(replace({ + "require('buffer')": "/*RicMoo:ethers:require(buffer)*/(null)", + include: "**/lib/bn.js", + delimiters: [ '', '' ] + })); + + // Remove the util from inhjerits (forces browser inherits) + plugins.push(replace({ + "require('util')": "/*RicMoo:ethers:require(util)*/(null)", + include: "**/inherits/inherits.js", + delimiters: [ '', '' ] + })); + + return plugins; +} + +function addEllipticReplace(plugins) { + + // Replace the package.json in elliptic + plugins.push(replace({ + "require('../package.json')": `/*RicMoo:ethers*/{ version: "${ elliptic.version }" }`, + include: "**/lib/elliptic.js", + delimiters: [ '', '' ] + })); + + // Nuke a bunch of requires we don't need in elliptic + const thrower = "(function() { throw new Error('unsupported'); })"; + const crash = "(null).crash()"; + [ + { name: "./edwards", filename: "curve/index.js" }, + { name: "./mont", filename: "curve/index.js" }, + { name: "./elliptic/eddsa", filename: "lib/elliptic.js" }, + { name: "brorand", filename: "ec/index.js", text: thrower }, + { name: "brorand", filename: "lib/elliptic.js", text: thrower }, + { name: "./precomputed/secp256k1", filename: "elliptic/curves.js", text: crash }, + ].forEach(({ name, filename, text }) => { + if (text == null) { text = "(null)"; } + const replacement = { + include: `**/${ filename }`, + delimiters: [ '', '' ] + }; + replacement[`require('${ name }')`] = `/*RicMoo:ethers:require(${ name })*/${ text }`, + plugins.push(replace(replacement)); + }); + + return plugins; +} + +function getUmdConfig() { + const plugins = [ ]; + + plugins.push(sourcemaps()); + + addUtilsReplace(plugins); + addEllipticReplace(plugins); + + plugins.push(resolveNode({ + mainFields: [ "browser", "main" ] + })); + plugins.push(commonjs({ })); + + return { + input: `packages/ethers/lib/index.js`, + output: { + file: `packages/ethers/dist/ethers.umd.js`, + format: "umd", + name: "ethers", + sourcemap: true + }, + context: "window", + treeshake: false, + plugins + }; +} + +function getEsmConfig() { + const plugins = [ ]; + + plugins.push(sourcemaps()); + + addUtilsReplace(plugins); + + // Note: We do not need to replace the elliptic problems because they + // were addressed when aliasing (in rollup-pre-alias.config.js) + + plugins.push(resolveNode({ })); + plugins.push(commonjs({ })); + + return { + input: `packages/ethers/lib.esm/index.js`, + output: { + file: `packages/ethers/dist/ethers.esm.js`, + format: "esm", + sourcemap: true + }, + context: "window", + treeshake: false, + plugins + }; +} + +/* +function getConfig() { + const plugins = [ ]; + + // Remove the buffer check from BN.js + plugins.push(replace({ + "require('buffer')": "/ * RicMoo:ethers * /(null)", + include: "* * / lib/bn.js", + delimiters: [ '', '' ] + })); + plugins.push(resolveNode({ + preferBuiltins: true + })); + plugins.push(commonjs({ })); + + return { + input: `packages/ethers/lib.esm/index.js`, + output: { + file: `packages/ethers/dist/test-esm.js`, + //preserveModules: true, + format: "esm", + //name: `ethers`, + sourcemap: true, + exports: "named" + }, + context: "window", + treeshake: false, + //external, + plugins + }; +} +*/ +const configs = [ +// getEsmConfig(), + getUmdConfig() +]; + +export default configs; diff --git a/rollup-pre-alias.config.js b/rollup-pre-alias.config.js new file mode 100644 index 0000000000..f13b70d2b1 --- /dev/null +++ b/rollup-pre-alias.config.js @@ -0,0 +1,84 @@ +"use strict"; + +import fs from "fs"; +import path from "path"; + +import commonjs from '@rollup/plugin-commonjs'; +import resolveNode from "@rollup/plugin-node-resolve"; +import replace from "@rollup/plugin-replace"; + +// We only need this for its version (we inject it into a require) +import elliptic from "elliptic"; + +function getSigningKeyConfig() { + + const plugins = [ ]; + + // Remove the buffer check from BN.js + plugins.push(replace({ + "require('buffer')": "/*RicMoo:ethers*/(null)", + include: "**/lib/bn.js", + delimiters: [ '', '' ] + })); + + // Replace the package.json in elliptic + plugins.push(replace({ + "require('../package.json')": `/*RicMoo:ethers*/{ version: "${ elliptic.version }" }`, + include: "**/lib/elliptic.js", + delimiters: [ '', '' ] + })); + + // Nuke a bunch of requires we don't need in elliptic + const thrower = "(function() { throw new Error('unsupported'); })"; + const crash = "(null).crash()"; + [ + { name: "./edwards", filename: "curve/index.js" }, + { name: "./mont", filename: "curve/index.js" }, + { name: "./elliptic/eddsa", filename: "lib/elliptic.js" }, + { name: "brorand", filename: "ec/index.js", text: thrower }, + { name: "brorand", filename: "lib/elliptic.js", text: thrower }, + { name: "./precomputed/secp256k1", filename: "elliptic/curves.js", text: crash }, + ].forEach(({ name, filename, text }) => { + if (text == null) { text = "(null)"; } + const replacement = { + include: `**/${ filename }`, + delimiters: [ '', '' ] + }; + replacement[`require('${ name }')`] = `/*RicMoo:ethers:require(${ name })*/${ text }`, + plugins.push(replace(replacement)); + }); + + // Keep @ethersproject imports, merge anything else + plugins.push(resolveNode({ + //resolveOnly: ((name === "ethers") ? []: [ /^(?!(@ethersproject|ethers))/ ]), + resolveOnly: [ /^(?!(@ethersproject|ethers|bn\.js|hash\.js))/ ], + mainFields: [ "module", "browser", "main" ], + preferBuiltins: false + })); + + // Our CommonJS dependencies that are not rollup-friendly + plugins.push(commonjs({ })); + + // Write out a dummy TypeScript definition + const typeDef = "//This file generated by rollup-pre-alias.config.js; do NOT modify\ndeclare const EC: any;\nexport { EC };" + fs.writeFileSync(path.resolve(__dirname, "packages/signing-key/lib._esm/browser-elliptic.d.ts"), typeDef); + + return { + input: `packages/signing-key/lib._esm/elliptic.js`, + output: { + file: `packages/signing-key/lib._esm/browser-elliptic.js`, + format: "esm", + sourcemap: true, + exports: "named" + }, + context: "window", + treeshake: false, + plugins + }; +} + +const configs = [ + getSigningKeyConfig() +]; + +export default configs; diff --git a/rollup-shims.config.js b/rollup-shims.config.js new file mode 100644 index 0000000000..8a4fd96946 --- /dev/null +++ b/rollup-shims.config.js @@ -0,0 +1,22 @@ +"use strict"; + +import commonjs from '@rollup/plugin-commonjs'; +import resolveNode from "@rollup/plugin-node-resolve"; + +const plugins = [ + resolveNode(), + commonjs() +]; + +export default { + input: "packages/shims/src/index.js", + output: { + file: `packages/shims/dist/index.js`, + format: "umd", + name: `_ethers_shims`, + exports: "named" + }, + context: "window", + treeshake: false, + plugins +}; diff --git a/rollup-tests.config.js b/rollup-tests.config.js index f7470bfff2..8305ec73cf 100644 --- a/rollup-tests.config.js +++ b/rollup-tests.config.js @@ -1,79 +1,33 @@ "use strict"; -import path from "path" -import fs from "fs"; +import commonjs from '@rollup/plugin-commonjs'; +//import inject from '@rollup/plugin-inject'; +import resolveNode from "@rollup/plugin-node-resolve"; -import builtins from '@erquhart/rollup-plugin-node-builtins'; -import resolve from 'rollup-plugin-node-resolve'; -import commonjs from 'rollup-plugin-commonjs'; -import json from 'rollup-plugin-json'; -import _globals from "rollup-plugin-node-globals"; +import nodePolyfills from "rollup-plugin-node-polyfills"; -const undef = "module.exports = undefined;"; -const empty = "module.exports = {};"; - -import { createFilter } from 'rollup-pluginutils'; - -function replacer(libPath, options = {}) { - const filter = createFilter(options.include, options.exclude); - - return { - name: "file-replacer", - resolveId(id, importee) { - if (id == "ethers") { - return path.resolve(importee.match(/^(.*\/packages\/)/)[1], `./tests/${ libPath }/browser-ethers.js`); - } - //return null; - }, - transform(code, id) { - if (id.match(/\/browser-fs\.json$/)) { - const config = JSON.parse(code); - const data = { "_": { name: "browser-fs", config: config } }; - config.dirs.forEach((dirname) => { - let fulldirname = path.resolve(path.dirname(id), "..", dirname); - fs.readdirSync(fulldirname).forEach((filename) => { - const key = path.join(dirname, filename); - const content = fs.readFileSync(path.resolve(fulldirname, filename)); - data[key] = content.toString("base64"); - console.log(`Added ${ key } (${ content.length } bytes)`); - }); - }); - - return { - code: JSON.stringify(data), - map: { mappings: '' } - }; - } - - return null; - } - }; -} - -export default commandLineArgs => { - let buildModule = commandLineArgs.configModule; - - let input = "./packages/tests/lib/index.js" - let format = "umd"; - let mainFields = [ "browser", "main" ]; - let libPath = "lib"; - - if (buildModule) { - input = "./packages/tests/lib.esm/index.js"; - format = "esm"; - mainFields = [ "browser", "module", "main" ]; - libPath = "lib.esm"; - } +import json from "@rollup/plugin-json"; +function getConfig(format, input, mainFields) { const plugins = [ - replacer(libPath), json(), - commonjs({ }), - builtins(), - resolve({ - mainFields: mainFields + /* + inject({ + modules: { + Buffer: [ "buffer", "Buffer" ], + }, + include: "* * /test-utils.js" + }), + */ + commonjs({ + }), + nodePolyfills({ + assert: true + }), + resolveNode({ + mainFields, + //preferBuiltins: true }), - _globals(), ]; return { @@ -88,3 +42,11 @@ export default commandLineArgs => { plugins: plugins }; } + +const configs = [ + getConfig("umd", "./packages/tests/lib/index.js", [ "_browser-all", "browser", "main" ]), + getConfig("esm", "./packages/tests/lib.esm/index.js", undefined), +]; + +export default configs; + diff --git a/rollup.config.js b/rollup.config.js deleted file mode 100644 index c2d7855102..0000000000 --- a/rollup.config.js +++ /dev/null @@ -1,146 +0,0 @@ -"use strict"; - -import path from "path"; - -import resolve from 'rollup-plugin-node-resolve'; -import commonjs from 'rollup-plugin-commonjs'; -import json from 'rollup-plugin-json'; - -import { terser } from "rollup-plugin-terser"; - -import { createFilter } from 'rollup-pluginutils'; - -function Replacer(basePath, options = {}) { - const filter = createFilter(options.include, options.exclude); - const suffixes = Object.keys(options.replace); - const pathUp = path.resolve(basePath, ".."); - return { - name: "file-replacer", - transform(code, id) { - /* - console.log("------"); - console.log("NAME", id, id.match("node-resolve:empty.js$")); - console.log(code); - console.log("------"); - */ - - if (!filter(id)) { return null; } - - for (let i = 0; i < suffixes.length; i++) { - const suffix = suffixes[i]; - if (id.match(new RegExp(suffix))) { - const newCode = options.replace[suffix]; - //console.log(`Replace: ${ id.substring(pathUp.length + 1) } (${ code.length } => ${ newCode.length })`); - return { - code: newCode, - map: { mappings: '' } - }; - } - - } - - if (id.substring(0, basePath.length) !== basePath) { - //console.log(`Keep: ${ id.substring(pathUp.length + 1) }`); - } - - return null; - } - }; -} - -const undef = "module.exports = undefined;"; -const empty = "module.exports = {};"; -const brorand = "module.exports = function(length) { var result = new Uint8Array(length); (global.crypto || global.msCrypto).getRandomValues(result); return result; }"; - -const ellipticPackage = (function() { - const ellipticPackage = require('./node_modules/elliptic/package.json'); - return JSON.stringify({ version: ellipticPackage.version }); -})(); - -function getConfig(minify, buildModule, testing) { - let input = "packages/ethers/lib/index.js" - let output = [ "umd" ]; - let format = "umd"; - let mainFields = [ "browser", "main" ]; - - if (buildModule) { - input = "packages/ethers/lib.esm/index.js"; - output = [ "esm" ]; - format = "esm"; - mainFields = [ "browser", "module", "main" ]; - } - - const replacer = Replacer(path.resolve("packages"), { - replace: { - // Remove the precomputed secp256k1 points - "elliptic/lib/elliptic/precomputed/secp256k1.js$": undef, - - // Remove curves we don't care about - "elliptic/curve/edwards.js$": empty, - "elliptic/curve/mont.js$": empty, - "elliptic/lib/elliptic/eddsa/.*$": empty, - - // We only use the version from this JSON package - "elliptic/package.json$" : ellipticPackage, - - // Remove unneeded hashing algorithms - "hash.js/lib/hash/sha/1.js$": empty, - "hash.js/lib/hash/sha/224.js$": empty, - "hash.js/lib/hash/sha/384.js$": empty, - - // Swap out borland for the random bytes we already have - "brorand/index.js$": brorand, - } - }); - - const plugins = [ - replacer, - json(), - resolve({ - mainFields: mainFields, - preferBuiltins: false - }), - commonjs({ - namedExports: { - "bn.js": [ "BN" ], - "hash.js": [ "hmac", "ripemd160", "sha256", "sha512" ], - "elliptic": [ "ec" ], - "scrypt-js": [ "scrypt", "syncScrypt" ], - }, - }), - ]; - - if (minify) { - output.push("min"); - plugins.push(terser()); - } - - const outputFile = [ - "packages", - (testing ? "tests": "ethers"), - ("/dist/ethers." + output.join(".") + ".js") - ].join("/"); - - return { - input: input, - output: { - file: outputFile, - format: format, - name: "ethers", - exports: "named" - }, - context: "window", - treeshake: false, - plugins: plugins - }; -} - -export default commandLineArgs => { - const testing = commandLineArgs.configTest; - const buildModule = commandLineArgs.configModule; - - return [ - getConfig(false, buildModule, testing), - getConfig(true, buildModule, testing), - ]; -}