Use ES6 modules for exports
This commit is contained in:
parent
e1d85ba682
commit
10c49be91d
|
@ -126,7 +126,7 @@ function pack() {
|
|||
return new Uint8Array(buffer);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
wrap: wrap,
|
||||
unwrap: unwrap
|
||||
export default {
|
||||
wrap,
|
||||
unwrap
|
||||
};
|
||||
|
|
|
@ -48,7 +48,7 @@ function decode(msg) {
|
|||
throw new Error('Invalid padding');
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
encode: encode,
|
||||
decode: decode
|
||||
export default {
|
||||
encode,
|
||||
decode
|
||||
};
|
||||
|
|
|
@ -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
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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, {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue
Block a user