Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/main_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
12 changes: 11 additions & 1 deletion fixup.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,26 @@ 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);
if (fs.lstatSync(filePath).isDirectory()) {
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);
11 changes: 11 additions & 0 deletions src/cjs/ecpair.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down
17 changes: 14 additions & 3 deletions src/esm/ecpair.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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 = {};
Expand Down
2 changes: 1 addition & 1 deletion src/esm/index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { ECPairFactory as default, ECPairFactory, networks } from './ecpair';
export { ECPairFactory as default, ECPairFactory, networks } from './ecpair.js';
4 changes: 2 additions & 2 deletions test/ecpair.spec.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion ts_src/ecpair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down