From 38c732cd437453efbdc18ba9f5dd7dc94f6c8753 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Rudge?= Date: Mon, 14 Oct 2019 15:10:10 -0300 Subject: [PATCH] Fix IE msCrypto.subtle usage (#242) * Fix IE subtle * rename * Update __tests__/utils.test.ts Co-Authored-By: Josh Cunningham * Update __tests__/utils.test.ts Co-Authored-By: Josh Cunningham --- __tests__/utils.test.ts | 7 +++++++ src/utils.ts | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/__tests__/utils.test.ts b/__tests__/utils.test.ts index c08aa63d7..c16217d76 100644 --- a/__tests__/utils.test.ts +++ b/__tests__/utils.test.ts @@ -527,6 +527,13 @@ describe('utils', () => { const theSubtle = getCryptoSubtle(); expect(theSubtle).toBe('window'); }); + it('should use msCrypto.subtle when available', () => { + (global).crypto = undefined; + (global).msCrypto = { subtle: 'ms' }; + + const cryptoSubtle = getCryptoSubtle(); + expect(cryptoSubtle).toBe('ms'); + }); }); describe('validateCrypto', () => { it('should throw error if crypto is unavailable', () => { diff --git a/src/utils.ts b/src/utils.ts index 8943ae802..c5bc434cd 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -183,8 +183,9 @@ export const getCrypto = () => { }; export const getCryptoSubtle = () => { + const crypto = getCrypto(); //safari 10.x uses webkitSubtle - return window.crypto.subtle || (window.crypto).webkitSubtle; + return crypto.subtle || (crypto).webkitSubtle; }; export const validateCrypto = () => {