2018-09-18 23:23:58 +00:00
|
|
|
import { browserName } from './utils';
|
|
|
|
|
2018-07-31 18:29:26 +00:00
|
|
|
async function checkCrypto() {
|
|
|
|
try {
|
|
|
|
const key = await crypto.subtle.generateKey(
|
|
|
|
{
|
|
|
|
name: 'AES-GCM',
|
|
|
|
length: 128
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
['encrypt', 'decrypt']
|
|
|
|
);
|
2018-07-31 22:10:12 +00:00
|
|
|
await crypto.subtle.exportKey('raw', key);
|
2018-07-31 18:29:26 +00:00
|
|
|
await crypto.subtle.encrypt(
|
|
|
|
{
|
|
|
|
name: 'AES-GCM',
|
|
|
|
iv: crypto.getRandomValues(new Uint8Array(12)),
|
|
|
|
tagLength: 128
|
|
|
|
},
|
|
|
|
key,
|
|
|
|
new ArrayBuffer(8)
|
|
|
|
);
|
|
|
|
await crypto.subtle.importKey(
|
|
|
|
'raw',
|
|
|
|
crypto.getRandomValues(new Uint8Array(16)),
|
|
|
|
'PBKDF2',
|
|
|
|
false,
|
|
|
|
['deriveKey']
|
|
|
|
);
|
|
|
|
await crypto.subtle.importKey(
|
|
|
|
'raw',
|
|
|
|
crypto.getRandomValues(new Uint8Array(16)),
|
|
|
|
'HKDF',
|
|
|
|
false,
|
|
|
|
['deriveKey']
|
|
|
|
);
|
|
|
|
return true;
|
|
|
|
} catch (err) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkStreams() {
|
|
|
|
try {
|
|
|
|
new ReadableStream({
|
|
|
|
pull() {}
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
} catch (e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function polyfillStreams() {
|
|
|
|
try {
|
|
|
|
require('@mattiasbuelens/web-streams-polyfill');
|
|
|
|
return true;
|
|
|
|
} catch (e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default async function capabilities() {
|
|
|
|
const crypto = await checkCrypto();
|
|
|
|
const nativeStreams = checkStreams();
|
|
|
|
const polyStreams = nativeStreams ? false : polyfillStreams();
|
2018-09-17 19:05:03 +00:00
|
|
|
let account = false;
|
|
|
|
try {
|
|
|
|
account = !!localStorage;
|
|
|
|
} catch (e) {
|
|
|
|
// nevermind
|
|
|
|
}
|
2018-07-31 18:29:26 +00:00
|
|
|
|
|
|
|
return {
|
2018-09-17 19:05:03 +00:00
|
|
|
account,
|
2018-07-31 18:29:26 +00:00
|
|
|
crypto,
|
|
|
|
streamUpload: nativeStreams || polyStreams,
|
|
|
|
streamDownload:
|
|
|
|
nativeStreams &&
|
|
|
|
'serviceWorker' in navigator &&
|
2018-09-18 23:23:58 +00:00
|
|
|
browserName() !== 'safari',
|
2018-07-31 18:29:26 +00:00
|
|
|
multifile: nativeStreams || polyStreams
|
|
|
|
};
|
|
|
|
}
|