Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix IE msCrypto.subtle usage #242

Merged
merged 4 commits into from
Oct 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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