Skip to content

Commit cbb8a5a

Browse files
authored
Merge pull request #22 from Nesopie/feat/hybrid
Add cjs and esm support
2 parents 6945aff + cf65d98 commit cbb8a5a

36 files changed

+2402
-3041
lines changed

.mocharc.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"$schema": "https://json.schemastore.org/mocharc.json",
3+
"require": "tsx"
4+
}

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33

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

6+
**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:
7+
1. Use a polyfill for crypto.getRandomValues()
8+
2. Use the `--experimental-global-webcrypto` flag when running node.js.
9+
3. Pass in a custom rng function to generate random values.
10+
611
## Example
712

813
TypeScript

fixup.cjs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
const updateRequires = (filePath) => {
5+
let content = fs.readFileSync(filePath, 'utf8');
6+
//replace local imports eg. require('./ecpair') to require('ecpair.cjs')
7+
content = content.replace(/require\('\.\/([^']*)'\)/g, "require('./$1.cjs')");
8+
9+
fs.writeFileSync(filePath, content, 'utf8');
10+
};
11+
12+
const processFiles = (dir) => {
13+
fs.readdirSync(dir).forEach((file) => {
14+
const filePath = path.join(dir, file);
15+
if (fs.lstatSync(filePath).isDirectory()) {
16+
processFiles(filePath);
17+
} else if (filePath.endsWith('.cjs')) {
18+
updateRequires(filePath);
19+
}
20+
});
21+
};
22+
23+
const dir = path.join(__dirname, 'src', 'cjs');
24+
processFiles(dir);

0 commit comments

Comments
 (0)