fork-openpgpjs/src/lightweight_helper.js
Ilya Chesnokov 08b7725b8c Create lightweight build that can lazily load indutny/elliptic if needed (#956)
This PR adds four config options to configure whether and how to load
indutny/elliptic: use_indutny_elliptic, external_indutny_elliptic,
indutny_elliptic_path and indutny_elliptic_fetch_options.

Also:

- Use tweetnacl.js instead of indutny/elliptic for curve25519 key generation

- Don't initialize indutny's curve25519, improving performance when using that curve

- Verify NIST signatures using Web Crypto instead of indutny/elliptic when not streaming

- Move KeyPair.sign/verify to ecdsa.js

- Move KeyPair.derive to ecdh.js

- Move keyFromPrivate and keyFromPublic to a new indutnyKey.js file
2019-10-25 16:07:57 +02:00

27 lines
683 B
JavaScript

/**
* Load script from path
* @param {String} path
*/
export const loadScript = path => {
if (typeof importScripts !== 'undefined') {
return importScripts(path);
}
return new Promise((resolve, reject) => {
const script = document.createElement('script');
script.src = path;
script.onload = () => resolve();
script.onerror = e => reject(new Error(e.message));
document.head.appendChild(script);
});
};
/**
* Download script from path
* @param {String} path fetch path
* @param {Object} options fetch options
*/
export const dl = async function(path, options) {
const response = await fetch(path, options);
return response.arrayBuffer();
};