Skip to content

Commit

Permalink
Merge pull request #22 from Nesopie/feat/hybrid
Browse files Browse the repository at this point in the history
Add cjs and esm support
  • Loading branch information
junderw authored Sep 8, 2024
2 parents 6945aff + cf65d98 commit cbb8a5a
Show file tree
Hide file tree
Showing 36 changed files with 2,402 additions and 3,041 deletions.
4 changes: 4 additions & 0 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"$schema": "https://json.schemastore.org/mocharc.json",
"require": "tsx"
}
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

A library for managing SECP256k1 keypairs written in TypeScript with transpiled JavaScript committed to git.

**Note** `ECPair`.makeRandom() uses the `crypto.getRandomValues` if there is no custom `rng` function provided. This API currently 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.

## Example

TypeScript
Expand Down
24 changes: 24 additions & 0 deletions fixup.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const fs = require('fs');
const path = require('path');

const updateRequires = (filePath) => {
let content = fs.readFileSync(filePath, 'utf8');
//replace local imports eg. require('./ecpair') to require('ecpair.cjs')
content = content.replace(/require\('\.\/([^']*)'\)/g, "require('./$1.cjs')");

fs.writeFileSync(filePath, content, 'utf8');
};

const processFiles = (dir) => {
fs.readdirSync(dir).forEach((file) => {
const filePath = path.join(dir, file);
if (fs.lstatSync(filePath).isDirectory()) {
processFiles(filePath);
} else if (filePath.endsWith('.cjs')) {
updateRequires(filePath);
}
});
};

const dir = path.join(__dirname, 'src', 'cjs');
processFiles(dir);
Loading

0 comments on commit cbb8a5a

Please sign in to comment.