diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..b58b603
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,5 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
new file mode 100644
index 0000000..a57e45d
--- /dev/null
+++ b/.idea/codeStyles/Project.xml
@@ -0,0 +1,64 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
new file mode 100644
index 0000000..79ee123
--- /dev/null
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/ecpair.iml b/.idea/ecpair.iml
new file mode 100644
index 0000000..24643cc
--- /dev/null
+++ b/.idea/ecpair.iml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
new file mode 100644
index 0000000..df7825d
--- /dev/null
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..e7d2a89
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/prettier.xml b/.idea/prettier.xml
new file mode 100644
index 0000000..b0c1c68
--- /dev/null
+++ b/.idea/prettier.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/fixup.cjs b/fixup.cjs
index a776270..1a3028f 100755
--- a/fixup.cjs
+++ b/fixup.cjs
@@ -1,10 +1,14 @@
const fs = require('fs');
const path = require('path');
-const updateRequires = (filePath) => {
+const updateRequireStatements = (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')");
+
+ // Replace require('./something.js') with require('./something.cjs')
+ content = content.replace(/require\('\.\/([^']*)\.js'\)/g, "require('./$1.cjs')");
+
+ // Replace import/export in .d.ts files
+ content = content.replace(/from '\.\/([^']*)\.js'/g, "from './$1.cjs'");
fs.writeFileSync(filePath, content, 'utf8');
};
@@ -12,10 +16,20 @@ const updateRequires = (filePath) => {
const processFiles = (dir) => {
fs.readdirSync(dir).forEach((file) => {
const filePath = path.join(dir, file);
+ const newPath = filePath.replace('.js', '.cjs');
+
if (fs.lstatSync(filePath).isDirectory()) {
processFiles(filePath);
- } else if (filePath.endsWith('.cjs')) {
- updateRequires(filePath);
+ } else if (path.extname(file) === '.js') {
+ // Rename the .js file to .cjs
+ updateRequireStatements(filePath);
+
+ fs.renameSync(filePath, newPath);
+ }
+
+ // Update .d.ts files to replace .js references with .cjs
+ if (path.extname(file) === '.ts') {
+ updateRequireStatements(filePath);
}
});
};
diff --git a/package-lock.json b/package-lock.json
index 58057fa..d655fd5 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "ecpair",
- "version": "3.0.0-rc.0",
+ "version": "3.0.1-rc.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "ecpair",
- "version": "3.0.0-rc.0",
+ "version": "3.0.1-rc.0",
"license": "MIT",
"dependencies": {
"uint8array-tools": "^0.0.8",
@@ -24,8 +24,8 @@
"rimraf": "^2.6.3",
"tiny-secp256k1": "^2.2.3",
"tslint": "^6.1.3",
- "tsx": "^4.16.5",
- "typescript": "^5.0.4"
+ "tsx": "^4.19.1",
+ "typescript": "^5.6.3"
},
"engines": {
"node": ">=18.0.0"
@@ -2180,10 +2180,11 @@
}
},
"node_modules/tsx": {
- "version": "4.19.0",
- "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.19.0.tgz",
- "integrity": "sha512-bV30kM7bsLZKZIOCHeMNVMJ32/LuJzLVajkQI/qf92J2Qr08ueLQvW00PUZGiuLPP760UINwupgUj8qrSCPUKg==",
+ "version": "4.19.1",
+ "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.19.1.tgz",
+ "integrity": "sha512-0flMz1lh74BR4wOvBjuh9olbnwqCPc35OOlfyzHba0Dc+QNUeWX/Gq2YTbnwcWPO3BMd8fkzRVrHcsR+a7z7rA==",
"dev": true,
+ "license": "MIT",
"dependencies": {
"esbuild": "~0.23.0",
"get-tsconfig": "^4.7.5"
@@ -2199,10 +2200,11 @@
}
},
"node_modules/typescript": {
- "version": "5.5.4",
- "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.4.tgz",
- "integrity": "sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==",
+ "version": "5.6.3",
+ "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.6.3.tgz",
+ "integrity": "sha512-hjcS1mhfuyi4WW8IWtjP7brDrG2cuDZukyrYrSauoXGNgx0S7zceP07adYkJycEr56BOUTNPzbInooiN3fn1qw==",
"devOptional": true,
+ "license": "Apache-2.0",
"bin": {
"tsc": "bin/tsc",
"tsserver": "bin/tsserver"
diff --git a/package.json b/package.json
index 1961086..2956ddb 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "ecpair",
- "version": "3.0.0-rc.0",
+ "version": "3.0.1-rc.0",
"description": "Client-side Bitcoin JavaScript library ECPair",
"type": "module",
"main": "src/cjs/index.cjs",
@@ -25,8 +25,7 @@
],
"scripts": {
"audit": "NPM_AUDIT_IGNORE_DEV=1 NPM_AUDIT_IGNORE_LEVEL=low npm-audit-whitelister .npm-audit-whitelister.json",
- "build": "npm run clean && tsc -p ./tsconfig.json && tsc -p tsconfig.cjs.json && npm run formatjs",
- "postbuild": "find src/cjs -type f -name \"*.js\" -exec bash -c 'mv \"$0\" \"${0%.js}.cjs\"' {} \\; && chmod +x ./fixup.cjs && node fixup.cjs",
+ "build": "npm run clean && tsc -p ./tsconfig.json && tsc -p tsconfig.cjs.json && npm run formatjs && node fixup.cjs",
"clean": "rimraf src",
"clean:jstests": "rimraf 'test/**/*.js'",
"coverage-report": "npm run build && npm run nobuild:coverage-report",
@@ -34,17 +33,18 @@
"coverage": "npm run build && npm run nobuild:coverage",
"format": "npm run prettier -- --write",
"formatjs": "npm run prettierjs -- --write",
- "format:ci": "npm run prettier -- --check && npm run prettierjs -- --check",
+ "format:ci": "npm run prettier -- --check && npm run prettiercjs -- --check && npm run prettierjs -- --check",
"gitdiff:ci": "npm run build && git diff --exit-code",
"lint": "tslint -p tsconfig.json -c tslint.json",
"lint:tests": "tslint -p test/tsconfig.json -c tslint.json",
"mocha:ts": "mocha --recursive",
"nobuild:coverage-report": "c8 report --reporter=lcov",
"nobuild:coverage-html": "c8 report --reporter=html",
- "nobuild:coverage": "c8 --check-coverage --exclude='**/*.cjs' --branches 90 --functions 90 --lines 90 npm run unit",
+ "nobuild:coverage": "c8 --check-coverage --exclude='**/*.js' --branches 90 --functions 90 --lines 90 npm run unit",
"nobuild:unit": "npm run mocha:ts -- 'test/*.ts'",
"prettier": "prettier \"ts_src/**/*.ts\" \"test/**/*.ts\" --ignore-path ./.prettierignore",
"prettierjs": "prettier \"src/**/*.js\" --ignore-path ./.prettierignore",
+ "prettiercjs": "prettier \"src/**/*.cjs\" --ignore-path ./.prettierignore",
"test": "npm run build && npm run format:ci && npm run lint && npm run nobuild:coverage",
"unit": "npm run build && npm run nobuild:unit"
},
@@ -71,8 +71,8 @@
"rimraf": "^2.6.3",
"tiny-secp256k1": "^2.2.3",
"tslint": "^6.1.3",
- "tsx": "^4.16.5",
- "typescript": "^5.0.4"
+ "tsx": "^4.19.1",
+ "typescript": "^5.6.3"
},
"license": "MIT"
}
diff --git a/src/cjs/ecpair.cjs b/src/cjs/ecpair.cjs
index 4315477..987e8c6 100644
--- a/src/cjs/ecpair.cjs
+++ b/src/cjs/ecpair.cjs
@@ -50,7 +50,7 @@ const networks = __importStar(require('./networks.cjs'));
exports.networks = networks;
const types = __importStar(require('./types.cjs'));
const wif = __importStar(require('wif'));
-const testecc_1 = require('./testecc.cjs');
+const testecc_js_1 = require('./testecc.cjs');
const v = __importStar(require('valibot'));
const tools = __importStar(require('uint8array-tools'));
const ECPairOptionsSchema = v.optional(
@@ -65,8 +65,7 @@ const ECPairOptionsSchema = v.optional(
return (arg) => {
const parsedArg = v.parse(v.optional(v.number()), arg);
const returnedValue = func(parsedArg);
- const parsedReturn = v.parse(v.instance(Uint8Array), returnedValue);
- return parsedReturn;
+ return v.parse(v.instance(Uint8Array), returnedValue);
};
}),
),
@@ -76,7 +75,7 @@ const ECPairOptionsSchema = v.optional(
const toXOnly = (pubKey) =>
pubKey.length === 32 ? pubKey : pubKey.subarray(1, 33);
function ECPairFactory(ecc) {
- (0, testecc_1.testEcc)(ecc);
+ (0, testecc_js_1.testEcc)(ecc);
function isPoint(maybePoint) {
return ecc.isPoint(maybePoint);
}
@@ -115,6 +114,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 = {};
@@ -128,11 +138,6 @@ function ECPairFactory(ecc) {
return fromPrivateKey(d, options);
}
class ECPair {
- __D;
- __Q;
- compressed;
- network;
- lowR;
constructor(__D, __Q, options) {
this.__D = __D;
this.__Q = __Q;
diff --git a/src/cjs/ecpair.d.ts b/src/cjs/ecpair.d.ts
index 8e933f6..0a6951d 100644
--- a/src/cjs/ecpair.d.ts
+++ b/src/cjs/ecpair.d.ts
@@ -1,7 +1,7 @@
-import { Network } from './networks';
-import * as networks from './networks';
-export { networks };
+import * as networks from './networks.cjs';
+import { Network } from './networks.cjs';
import * as v from 'valibot';
+export { networks };
declare const ECPairOptionsSchema: v.OptionalSchema, never>;
readonly network: v.OptionalSchema;
export declare const bitcoin: Network;
export declare const testnet: Network;
diff --git a/src/cjs/testecc.d.ts b/src/cjs/testecc.d.ts
index bff8d27..2552366 100644
--- a/src/cjs/testecc.d.ts
+++ b/src/cjs/testecc.d.ts
@@ -1,2 +1,2 @@
-import { TinySecp256k1Interface } from './ecpair';
+import { TinySecp256k1Interface } from './ecpair.cjs';
export declare function testEcc(ecc: TinySecp256k1Interface): void;
diff --git a/src/esm/ecpair.js b/src/esm/ecpair.js
index 1eb5751..65cc0d6 100644
--- a/src/esm/ecpair.js
+++ b/src/esm/ecpair.js
@@ -1,10 +1,10 @@
-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';
-export { networks };
+import { testEcc } from './testecc.js';
import * as v from 'valibot';
import * as tools from 'uint8array-tools';
+export { networks };
const ECPairOptionsSchema = v.optional(
v.object({
compressed: v.optional(v.boolean()),
@@ -17,8 +17,7 @@ const ECPairOptionsSchema = v.optional(
return (arg) => {
const parsedArg = v.parse(v.optional(v.number()), arg);
const returnedValue = func(parsedArg);
- const parsedReturn = v.parse(v.instance(Uint8Array), returnedValue);
- return parsedReturn;
+ return v.parse(v.instance(Uint8Array), returnedValue);
};
}),
),
@@ -67,6 +66,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/tsconfig.json b/test/tsconfig.json
index ec4d5a1..7b54e91 100644
--- a/test/tsconfig.json
+++ b/test/tsconfig.json
@@ -10,7 +10,6 @@
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
- },
+ },
"include": ["**/*.spec.ts"]
}
-
\ No newline at end of file
diff --git a/ts_src/ecpair.ts b/ts_src/ecpair.ts
index 8fcc519..81618b7 100644
--- a/ts_src/ecpair.ts
+++ b/ts_src/ecpair.ts
@@ -1,12 +1,13 @@
-import { Network } from './networks';
-import * as networks from './networks';
-import * as types from './types';
+import * as networks from './networks.js';
+import { Network } from './networks.js';
+import * as types from './types.js';
import * as wif from 'wif';
-import { testEcc } from './testecc';
-export { networks };
+import { testEcc } from './testecc.js';
import * as v from 'valibot';
import * as tools from 'uint8array-tools';
+export { networks };
+
const ECPairOptionsSchema = v.optional(
v.object({
compressed: v.optional(v.boolean()),
@@ -19,8 +20,7 @@ const ECPairOptionsSchema = v.optional(
return (arg?: number) => {
const parsedArg = v.parse(v.optional(v.number()), arg);
const returnedValue = func(parsedArg);
- const parsedReturn = v.parse(v.instance(Uint8Array), returnedValue);
- return parsedReturn;
+ return v.parse(v.instance(Uint8Array), returnedValue);
};
}),
),
@@ -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.
diff --git a/ts_src/index.ts b/ts_src/index.ts
index 20a7401..0f04708 100644
--- a/ts_src/index.ts
+++ b/ts_src/index.ts
@@ -7,4 +7,4 @@ export {
type ECPairInterface,
type TinySecp256k1Interface,
networks,
-} from './ecpair';
+} from './ecpair.js';
diff --git a/ts_src/networks.ts b/ts_src/networks.ts
index 5d26aa4..eefaba0 100644
--- a/ts_src/networks.ts
+++ b/ts_src/networks.ts
@@ -1,6 +1,6 @@
// https://en.bitcoin.it/wiki/List_of_address_prefixes
import * as v from 'valibot';
-import { NetworkSchema } from './types';
+import { NetworkSchema } from './types.js';
export type Network = v.InferOutput;
diff --git a/ts_src/testecc.ts b/ts_src/testecc.ts
index 04f82c0..a4fb365 100644
--- a/ts_src/testecc.ts
+++ b/ts_src/testecc.ts
@@ -1,4 +1,4 @@
-import { TinySecp256k1Interface } from './ecpair';
+import { TinySecp256k1Interface } from './ecpair.js';
const h = (hex: string): Buffer => Buffer.from(hex, 'hex');
diff --git a/tsconfig.cjs.json b/tsconfig.cjs.json
index 15e4b30..b21c32b 100644
--- a/tsconfig.cjs.json
+++ b/tsconfig.cjs.json
@@ -3,8 +3,9 @@
"compilerOptions": {
"declaration": true,
"emitDeclarationOnly": false,
+ "target": "ES6",
"esModuleInterop": true,
"outDir": "src/cjs",
- "module": "commonjs"
+ "module": "CommonJS"
}
}