From 10c49be91da12a02bf4b5112e51ef366acb6e593 Mon Sep 17 00:00:00 2001 From: BafS Date: Tue, 20 Feb 2018 18:27:05 +0100 Subject: [PATCH] Use ES6 modules for exports --- src/crypto/aes_kw.js | 6 +++--- src/crypto/pkcs5.js | 6 +++--- src/crypto/public_key/elliptic/curves.js | 7 ++++--- src/crypto/public_key/elliptic/ecdh.js | 6 +++--- src/crypto/public_key/elliptic/ecdsa.js | 6 +++--- src/crypto/public_key/elliptic/eddsa.js | 6 +++--- src/type/ecdh_symkey.js | 4 ++-- src/type/kdf_params.js | 4 ++-- src/type/oid.js | 4 ++-- 9 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/crypto/aes_kw.js b/src/crypto/aes_kw.js index edf72994..73a69f36 100644 --- a/src/crypto/aes_kw.js +++ b/src/crypto/aes_kw.js @@ -126,7 +126,7 @@ function pack() { return new Uint8Array(buffer); } -module.exports = { - wrap: wrap, - unwrap: unwrap +export default { + wrap, + unwrap }; diff --git a/src/crypto/pkcs5.js b/src/crypto/pkcs5.js index f7e166a4..57d070e6 100644 --- a/src/crypto/pkcs5.js +++ b/src/crypto/pkcs5.js @@ -48,7 +48,7 @@ function decode(msg) { throw new Error('Invalid padding'); } -module.exports = { - encode: encode, - decode: decode +export default { + encode, + decode }; diff --git a/src/crypto/public_key/elliptic/curves.js b/src/crypto/public_key/elliptic/curves.js index 15a3ea8e..cdaaed70 100644 --- a/src/crypto/public_key/elliptic/curves.js +++ b/src/crypto/public_key/elliptic/curves.js @@ -202,9 +202,10 @@ function getPreferredHashAlgo(oid) { return curves[enums.write(enums.curve, oid.toHex())].hash; } -// TODO convert to export default {...} -module.exports = { - Curve, curves, webCurves, nodeCurves, get, generate, getPreferredHashAlgo +export default Curve; + +export { + curves, webCurves, nodeCurves, get, generate, getPreferredHashAlgo }; diff --git a/src/crypto/public_key/elliptic/ecdh.js b/src/crypto/public_key/elliptic/ecdh.js index 8bdd1ba5..14217b1a 100644 --- a/src/crypto/public_key/elliptic/ecdh.js +++ b/src/crypto/public_key/elliptic/ecdh.js @@ -30,7 +30,7 @@ */ import BN from 'bn.js'; -import curves from './curves'; +import { get as curvesGet } from './curves'; import aes_kw from '../../aes_kw'; import cipher from '../../cipher'; import hash from '../../hash'; @@ -74,7 +74,7 @@ function kdf(hash_algo, X, length, param) { */ async function encrypt(oid, cipher_algo, hash_algo, m, Q, fingerprint) { fingerprint = util.hex2Uint8Array(fingerprint); - const curve = curves.get(oid); + const curve = curvesGet(oid); const param = buildEcdhParam(enums.publicKey.ecdh, oid, cipher_algo, hash_algo, fingerprint); cipher_algo = enums.read(enums.symmetric, cipher_algo); const v = await curve.genKeyPair(); @@ -102,7 +102,7 @@ async function encrypt(oid, cipher_algo, hash_algo, m, Q, fingerprint) { */ async function decrypt(oid, cipher_algo, hash_algo, V, C, d, fingerprint) { fingerprint = util.hex2Uint8Array(fingerprint); - const curve = curves.get(oid); + const curve = curvesGet(oid); const param = buildEcdhParam(enums.publicKey.ecdh, oid, cipher_algo, hash_algo, fingerprint); cipher_algo = enums.read(enums.symmetric, cipher_algo); V = curve.keyFromPublic(V); diff --git a/src/crypto/public_key/elliptic/ecdsa.js b/src/crypto/public_key/elliptic/ecdsa.js index c94ebf45..948ffe59 100644 --- a/src/crypto/public_key/elliptic/ecdsa.js +++ b/src/crypto/public_key/elliptic/ecdsa.js @@ -26,7 +26,7 @@ import util from '../../../util'; import hash from '../../hash'; -import curves from './curves'; +import { get as curvesGet } from './curves'; /** * Sign a message using the provided key @@ -37,7 +37,7 @@ import curves from './curves'; * @return {{r: BN, s: BN}} Signature of the message */ async function sign(oid, hash_algo, m, d) { - const curve = curves.get(oid); + const curve = curvesGet(oid); const key = curve.keyFromPrivate(d); return key.sign(m, hash_algo); } @@ -52,7 +52,7 @@ async function sign(oid, hash_algo, m, d) { * @return {Boolean} */ async function verify(oid, hash_algo, signature, m, Q) { - const curve = curves.get(oid); + const curve = curvesGet(oid); const key = curve.keyFromPublic(Q); return key.verify(m, signature, hash_algo); } diff --git a/src/crypto/public_key/elliptic/eddsa.js b/src/crypto/public_key/elliptic/eddsa.js index 9282e327..a0fc467d 100644 --- a/src/crypto/public_key/elliptic/eddsa.js +++ b/src/crypto/public_key/elliptic/eddsa.js @@ -26,7 +26,7 @@ import BN from 'bn.js'; import hash from '../../hash'; -import curves from './curves'; +import { get as curvesGet } from './curves'; /** * Sign a message using the provided key @@ -37,7 +37,7 @@ import curves from './curves'; * @return {{R: Array, S: Array}} Signature of the message */ async function sign(oid, hash_algo, m, d) { - const curve = curves.get(oid); + const curve = curvesGet(oid); const key = curve.keyFromSecret(d.toArray('be', 32)); const signature = await key.sign(m, hash_algo); // EdDSA signature params are returned in little-endian format @@ -54,7 +54,7 @@ async function sign(oid, hash_algo, m, d) { * @return {Boolean} */ async function verify(oid, hash_algo, signature, m, Q) { - const curve = curves.get(oid); + const curve = curvesGet(oid); const key = curve.keyFromPublic(Q.toArray('be', 33)); // EdDSA signature params are expected in little-endian format return key.verify(m, { diff --git a/src/type/ecdh_symkey.js b/src/type/ecdh_symkey.js index ec38430d..1044a459 100644 --- a/src/type/ecdh_symkey.js +++ b/src/type/ecdh_symkey.js @@ -24,8 +24,6 @@ import util from '../util'; -module.exports = ECDHSymmetricKey; - /** * @constructor */ @@ -63,3 +61,5 @@ ECDHSymmetricKey.prototype.read = function (input) { ECDHSymmetricKey.prototype.write = function () { return util.concatUint8Array([new Uint8Array([this.data.length]), this.data]); }; + +export default ECDHSymmetricKey; diff --git a/src/type/kdf_params.js b/src/type/kdf_params.js index 30bcf469..82598702 100644 --- a/src/type/kdf_params.js +++ b/src/type/kdf_params.js @@ -24,8 +24,6 @@ import enums from '../enums.js'; -module.exports = KDFParams; - /** * @constructor * @param {enums.hash} hash Hash algorithm @@ -66,3 +64,5 @@ KDFParams.prototype.write = function () { KDFParams.fromClone = function (clone) { return new KDFParams(clone.hash, clone.cipher); }; + +export default KDFParams; diff --git a/src/type/oid.js b/src/type/oid.js index 88c75e25..23e80d40 100644 --- a/src/type/oid.js +++ b/src/type/oid.js @@ -25,8 +25,6 @@ import util from '../util.js'; -module.exports = OID; - /** * @constructor */ @@ -79,3 +77,5 @@ OID.fromClone = function (clone) { const oid = new OID(clone.oid); return oid; }; + +export default OID;