From 33b25f631feb79f0a902ea387d63064dcf54db43 Mon Sep 17 00:00:00 2001 From: Saam Tehrani Date: Thu, 16 Jan 2025 02:00:51 -0700 Subject: [PATCH] add shim for crypto module for older node versions --- package.json | 2 +- test/keys.ts | 2 +- test/shims.ts | 9 +++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 test/shims.ts diff --git a/package.json b/package.json index 7affdaf..c6e9062 100644 --- a/package.json +++ b/package.json @@ -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\"", diff --git a/test/keys.ts b/test/keys.ts index 9d300bb..d0e47fd 100644 --- a/test/keys.ts +++ b/test/keys.ts @@ -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"; diff --git a/test/shims.ts b/test/shims.ts new file mode 100644 index 0000000..f16e3a6 --- /dev/null +++ b/test/shims.ts @@ -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); + } + } +})();