Skip to content

Commit

Permalink
add shim for crypto module for older node versions
Browse files Browse the repository at this point in the history
  • Loading branch information
samantehrani committed Jan 16, 2025
1 parent 6eddcca commit 33b25f6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"clean:bundle": "rimraf bundles",
"clean": "npm run clean:dist && npm run clean:package && npm run clean:bundle",
"prepublishOnly": "npm run clean && npm run build",
"test": "mocha test/*.ts && echo \"NOW RUN => 'npm run test:web' <= \" ",
"test": "mocha --file test/shims.ts test/*.ts && echo \"NOW RUN => 'npm run test:web' <= \" ",
"test:web": "npm run bundle:web && webpack --config-name web-tests && opener test/web/web.html",
"prettier:check": "prettier --check \"src/**/*.ts\" \"test/**/*.ts\"",
"prettier:write": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
Expand Down
2 changes: 1 addition & 1 deletion test/keys.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { readFileSync, writeFileSync } from "fs";
import { readFileSync } from "fs";
import * as chai from "chai";

import { EllipticCurvePrivateKey, EllipticCurvePublicKey, SECP256k1PrivateKey, SECP256k1PublicKey } from "../src/common/lib/crypto/keys";
Expand Down
9 changes: 9 additions & 0 deletions test/shims.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(function () {
if (!globalThis.crypto) {
try {
globalThis.crypto = require('crypto');
} catch (e) {
console.error('Failed to load crypto module in Node.js:', e);
}
}
})();

0 comments on commit 33b25f6

Please sign in to comment.