diff --git a/.github/workflows/main_ci.yml b/.github/workflows/main_ci.yml index be16be1..9be5d43 100644 --- a/.github/workflows/main_ci.yml +++ b/.github/workflows/main_ci.yml @@ -13,7 +13,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-node@v4 with: - node-version: 18 + node-version: 20 registry-url: https://registry.npmjs.org/ - run: npm ci - run: npm run unit @@ -23,7 +23,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-node@v4 with: - node-version: 18 + node-version: 20 registry-url: https://registry.npmjs.org/ - run: npm ci - run: npm run coverage @@ -33,7 +33,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-node@v4 with: - node-version: 18 + node-version: 20 registry-url: https://registry.npmjs.org/ - run: npm ci - run: npm run format:ci @@ -43,7 +43,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-node@v4 with: - node-version: 18 + node-version: 20 registry-url: https://registry.npmjs.org/ - run: npm ci - run: npm run gitdiff:ci @@ -53,7 +53,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-node@v4 with: - node-version: 18 + node-version: 20 registry-url: https://registry.npmjs.org/ - run: npm ci - run: npm run lint @@ -63,7 +63,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-node@v4 with: - node-version: 18 + node-version: 20 registry-url: https://registry.npmjs.org/ - run: npm ci - run: npm run lint:tests diff --git a/fixup.cjs b/fixup.cjs index a776270..91b1830 100755 --- a/fixup.cjs +++ b/fixup.cjs @@ -9,6 +9,14 @@ const updateRequires = (filePath) => { fs.writeFileSync(filePath, content, 'utf8'); }; +const updateImports = (filePath) => { + let content = fs.readFileSync(filePath, 'utf8'); + //replace local imports eg. from './types'; to from './types.js'; + content = content.replace(/from '\.\/([^']*)'/g, "from './$1.js'"); + + fs.writeFileSync(filePath, content, 'utf8'); +}; + const processFiles = (dir) => { fs.readdirSync(dir).forEach((file) => { const filePath = path.join(dir, file); @@ -16,9 +24,11 @@ const processFiles = (dir) => { processFiles(filePath); } else if (filePath.endsWith('.cjs')) { updateRequires(filePath); + } else if (filePath.endsWith('.js')) { + updateImports(filePath); } }); }; -const dir = path.join(__dirname, 'src', 'cjs'); +const dir = path.join(__dirname, 'src'); processFiles(dir); diff --git a/src/cjs/ecpair.cjs b/src/cjs/ecpair.cjs index 4315477..b27d44a 100644 --- a/src/cjs/ecpair.cjs +++ b/src/cjs/ecpair.cjs @@ -115,6 +115,17 @@ function ECPairFactory(ecc) { network: network, }); } + /** + * Generates a random ECPairInterface. + * + * Uses `crypto.getRandomValues` under the hood for options.rng function, which is still an experimental feature as of Node.js 18.19.0. To work around this you can do one of the following: + * 1. Use a polyfill for crypto.getRandomValues() + * 2. Use the `--experimental-global-webcrypto` flag when running node.js. + * 3. Pass in a custom rng function to generate random values. + * + * @param {ECPairOptions} options - Options for the ECPairInterface. + * @return {ECPairInterface} A random ECPairInterface. + */ function makeRandom(options) { v.parse(ECPairOptionsSchema, options); if (options === undefined) options = {}; diff --git a/src/esm/ecpair.js b/src/esm/ecpair.js index 1eb5751..54faab8 100644 --- a/src/esm/ecpair.js +++ b/src/esm/ecpair.js @@ -1,7 +1,7 @@ -import * as networks from './networks'; -import * as types from './types'; +import * as networks from './networks.js'; +import * as types from './types.js'; import * as wif from 'wif'; -import { testEcc } from './testecc'; +import { testEcc } from './testecc.js'; export { networks }; import * as v from 'valibot'; import * as tools from 'uint8array-tools'; @@ -67,6 +67,17 @@ export function ECPairFactory(ecc) { network: network, }); } + /** + * Generates a random ECPairInterface. + * + * Uses `crypto.getRandomValues` under the hood for options.rng function, which is still an experimental feature as of Node.js 18.19.0. To work around this you can do one of the following: + * 1. Use a polyfill for crypto.getRandomValues() + * 2. Use the `--experimental-global-webcrypto` flag when running node.js. + * 3. Pass in a custom rng function to generate random values. + * + * @param {ECPairOptions} options - Options for the ECPairInterface. + * @return {ECPairInterface} A random ECPairInterface. + */ function makeRandom(options) { v.parse(ECPairOptionsSchema, options); if (options === undefined) options = {}; diff --git a/src/esm/index.js b/src/esm/index.js index ad66e7b..d0e793d 100644 --- a/src/esm/index.js +++ b/src/esm/index.js @@ -1 +1 @@ -export { ECPairFactory as default, ECPairFactory, networks } from './ecpair'; +export { ECPairFactory as default, ECPairFactory, networks } from './ecpair.js'; diff --git a/test/ecpair.spec.ts b/test/ecpair.spec.ts index c2c7ad9..e03231a 100644 --- a/test/ecpair.spec.ts +++ b/test/ecpair.spec.ts @@ -1,8 +1,8 @@ import * as assert from 'assert'; import { createHash } from 'crypto'; import { beforeEach, describe, it } from 'mocha'; -import { ECPairFactory, networks as NETWORKS } from 'ecpair'; -import type { ECPairInterface, TinySecp256k1Interface } from 'ecpair'; +import { ECPairFactory, networks as NETWORKS } from '..'; +import type { ECPairInterface, TinySecp256k1Interface } from '..'; import fixtures from './fixtures/ecpair.json'; import * as tinysecp from 'tiny-secp256k1'; import * as tools from 'uint8array-tools'; diff --git a/ts_src/ecpair.ts b/ts_src/ecpair.ts index 8fcc519..2cd9902 100644 --- a/ts_src/ecpair.ts +++ b/ts_src/ecpair.ts @@ -157,7 +157,7 @@ export function ECPairFactory(ecc: TinySecp256k1Interface): ECPairAPI { /** * Generates a random ECPairInterface. - * + * * Uses `crypto.getRandomValues` under the hood for options.rng function, which is still an experimental feature as of Node.js 18.19.0. To work around this you can do one of the following: * 1. Use a polyfill for crypto.getRandomValues() * 2. Use the `--experimental-global-webcrypto` flag when running node.js.