Use ES6 modules for exports

This commit is contained in:
BafS 2018-02-20 18:27:05 +01:00 committed by Mahrud Sayrafi
parent e1d85ba682
commit 10c49be91d
No known key found for this signature in database
GPG Key ID: C24071B956C3245F
9 changed files with 25 additions and 24 deletions

View File

@ -126,7 +126,7 @@ function pack() {
return new Uint8Array(buffer);
}
module.exports = {
wrap: wrap,
unwrap: unwrap
export default {
wrap,
unwrap
};

View File

@ -48,7 +48,7 @@ function decode(msg) {
throw new Error('Invalid padding');
}
module.exports = {
encode: encode,
decode: decode
export default {
encode,
decode
};

View File

@ -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
};

View File

@ -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);

View File

@ -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);
}

View File

@ -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, {

View File

@ -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;

View File

@ -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;

View File

@ -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;