From f24b11599852d18351e7762008707cba50ca3b17 Mon Sep 17 00:00:00 2001 From: ivanovSPvirtru <41641307+ivanovSPvirtru@users.noreply.github.com> Date: Thu, 25 Aug 2022 16:56:48 +0300 Subject: [PATCH] Fixed crypto import and isNodeStream function (#79) * Fixed crypto import and isNodeStream function * The same version * fix globalThis.crypto * return ts-ignore --- lib/facade/FileClient.ts | 2 +- lib/src/index.node.ts | 2 +- lib/src/nanotdf-crypto/getCryptoLib.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/facade/FileClient.ts b/lib/facade/FileClient.ts index 27c80386..da95fe33 100644 --- a/lib/facade/FileClient.ts +++ b/lib/facade/FileClient.ts @@ -14,7 +14,7 @@ interface FileClientConfig { } function isNodeStream(source: InputSource): source is NodeJS.ReadableStream { - return Object.prototype.hasOwnProperty.call(source, 'pipe'); + return typeof (source as NodeJS.ReadableStream)?.pipe === 'function'; } export class FileClient { diff --git a/lib/src/index.node.ts b/lib/src/index.node.ts index 0b27c603..b6a99a37 100644 --- a/lib/src/index.node.ts +++ b/lib/src/index.node.ts @@ -1,6 +1,6 @@ import { NanoTDFClient, NanoTDFDatasetClient, AuthProviders, version, clientType } from './index'; import fetch from 'node-fetch'; -import crypto from 'crypto'; +import { webcrypto as crypto } from 'node:crypto'; globalThis.crypto = crypto as unknown as Crypto; globalThis.fetch = fetch as typeof globalThis.fetch; diff --git a/lib/src/nanotdf-crypto/getCryptoLib.ts b/lib/src/nanotdf-crypto/getCryptoLib.ts index de5e079b..9a01aad8 100644 --- a/lib/src/nanotdf-crypto/getCryptoLib.ts +++ b/lib/src/nanotdf-crypto/getCryptoLib.ts @@ -11,5 +11,5 @@ export default function getCryptoLib(): SubtleCrypto { return subtleCrypto; } - return globalThis.crypto.webcrypto.subtle; + return globalThis.crypto.subtle; }