Skip to content

Commit

Permalink
Fix IE msCrypto.subtle usage (#242)
Browse files Browse the repository at this point in the history
* Fix IE subtle

* rename

* Update __tests__/utils.test.ts

Co-Authored-By: Josh Cunningham <[email protected]>

* Update __tests__/utils.test.ts

Co-Authored-By: Josh Cunningham <[email protected]>
  • Loading branch information
Luís Rudge and joshcanhelp authored Oct 14, 2019
1 parent 78075fe commit 38c732c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 7 additions & 0 deletions __tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,13 @@ describe('utils', () => {
const theSubtle = getCryptoSubtle();
expect(theSubtle).toBe('window');
});
it('should use msCrypto.subtle when available', () => {
(<any>global).crypto = undefined;
(<any>global).msCrypto = { subtle: 'ms' };

const cryptoSubtle = getCryptoSubtle();
expect(cryptoSubtle).toBe('ms');
});
});
describe('validateCrypto', () => {
it('should throw error if crypto is unavailable', () => {
Expand Down
3 changes: 2 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,9 @@ export const getCrypto = () => {
};

export const getCryptoSubtle = () => {
const crypto = getCrypto();
//safari 10.x uses webkitSubtle
return window.crypto.subtle || (<any>window.crypto).webkitSubtle;
return crypto.subtle || (<any>crypto).webkitSubtle;
};

export const validateCrypto = () => {
Expand Down

0 comments on commit 38c732c

Please sign in to comment.