Use ES6 modules for exports
This commit is contained in:
parent
e1d85ba682
commit
10c49be91d
|
@ -126,7 +126,7 @@ function pack() {
|
||||||
return new Uint8Array(buffer);
|
return new Uint8Array(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
wrap: wrap,
|
wrap,
|
||||||
unwrap: unwrap
|
unwrap
|
||||||
};
|
};
|
||||||
|
|
|
@ -48,7 +48,7 @@ function decode(msg) {
|
||||||
throw new Error('Invalid padding');
|
throw new Error('Invalid padding');
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
encode: encode,
|
encode,
|
||||||
decode: decode
|
decode
|
||||||
};
|
};
|
||||||
|
|
|
@ -202,9 +202,10 @@ function getPreferredHashAlgo(oid) {
|
||||||
return curves[enums.write(enums.curve, oid.toHex())].hash;
|
return curves[enums.write(enums.curve, oid.toHex())].hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO convert to export default {...}
|
export default Curve;
|
||||||
module.exports = {
|
|
||||||
Curve, curves, webCurves, nodeCurves, get, generate, getPreferredHashAlgo
|
export {
|
||||||
|
curves, webCurves, nodeCurves, get, generate, getPreferredHashAlgo
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import BN from 'bn.js';
|
import BN from 'bn.js';
|
||||||
import curves from './curves';
|
import { get as curvesGet } from './curves';
|
||||||
import aes_kw from '../../aes_kw';
|
import aes_kw from '../../aes_kw';
|
||||||
import cipher from '../../cipher';
|
import cipher from '../../cipher';
|
||||||
import hash from '../../hash';
|
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) {
|
async function encrypt(oid, cipher_algo, hash_algo, m, Q, fingerprint) {
|
||||||
fingerprint = util.hex2Uint8Array(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);
|
const param = buildEcdhParam(enums.publicKey.ecdh, oid, cipher_algo, hash_algo, fingerprint);
|
||||||
cipher_algo = enums.read(enums.symmetric, cipher_algo);
|
cipher_algo = enums.read(enums.symmetric, cipher_algo);
|
||||||
const v = await curve.genKeyPair();
|
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) {
|
async function decrypt(oid, cipher_algo, hash_algo, V, C, d, fingerprint) {
|
||||||
fingerprint = util.hex2Uint8Array(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);
|
const param = buildEcdhParam(enums.publicKey.ecdh, oid, cipher_algo, hash_algo, fingerprint);
|
||||||
cipher_algo = enums.read(enums.symmetric, cipher_algo);
|
cipher_algo = enums.read(enums.symmetric, cipher_algo);
|
||||||
V = curve.keyFromPublic(V);
|
V = curve.keyFromPublic(V);
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
|
|
||||||
import util from '../../../util';
|
import util from '../../../util';
|
||||||
import hash from '../../hash';
|
import hash from '../../hash';
|
||||||
import curves from './curves';
|
import { get as curvesGet } from './curves';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sign a message using the provided key
|
* Sign a message using the provided key
|
||||||
|
@ -37,7 +37,7 @@ import curves from './curves';
|
||||||
* @return {{r: BN, s: BN}} Signature of the message
|
* @return {{r: BN, s: BN}} Signature of the message
|
||||||
*/
|
*/
|
||||||
async function sign(oid, hash_algo, m, d) {
|
async function sign(oid, hash_algo, m, d) {
|
||||||
const curve = curves.get(oid);
|
const curve = curvesGet(oid);
|
||||||
const key = curve.keyFromPrivate(d);
|
const key = curve.keyFromPrivate(d);
|
||||||
return key.sign(m, hash_algo);
|
return key.sign(m, hash_algo);
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ async function sign(oid, hash_algo, m, d) {
|
||||||
* @return {Boolean}
|
* @return {Boolean}
|
||||||
*/
|
*/
|
||||||
async function verify(oid, hash_algo, signature, m, Q) {
|
async function verify(oid, hash_algo, signature, m, Q) {
|
||||||
const curve = curves.get(oid);
|
const curve = curvesGet(oid);
|
||||||
const key = curve.keyFromPublic(Q);
|
const key = curve.keyFromPublic(Q);
|
||||||
return key.verify(m, signature, hash_algo);
|
return key.verify(m, signature, hash_algo);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
|
|
||||||
import BN from 'bn.js';
|
import BN from 'bn.js';
|
||||||
import hash from '../../hash';
|
import hash from '../../hash';
|
||||||
import curves from './curves';
|
import { get as curvesGet } from './curves';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sign a message using the provided key
|
* Sign a message using the provided key
|
||||||
|
@ -37,7 +37,7 @@ import curves from './curves';
|
||||||
* @return {{R: Array, S: Array}} Signature of the message
|
* @return {{R: Array, S: Array}} Signature of the message
|
||||||
*/
|
*/
|
||||||
async function sign(oid, hash_algo, m, d) {
|
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 key = curve.keyFromSecret(d.toArray('be', 32));
|
||||||
const signature = await key.sign(m, hash_algo);
|
const signature = await key.sign(m, hash_algo);
|
||||||
// EdDSA signature params are returned in little-endian format
|
// EdDSA signature params are returned in little-endian format
|
||||||
|
@ -54,7 +54,7 @@ async function sign(oid, hash_algo, m, d) {
|
||||||
* @return {Boolean}
|
* @return {Boolean}
|
||||||
*/
|
*/
|
||||||
async function verify(oid, hash_algo, signature, m, Q) {
|
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));
|
const key = curve.keyFromPublic(Q.toArray('be', 33));
|
||||||
// EdDSA signature params are expected in little-endian format
|
// EdDSA signature params are expected in little-endian format
|
||||||
return key.verify(m, {
|
return key.verify(m, {
|
||||||
|
|
|
@ -24,8 +24,6 @@
|
||||||
|
|
||||||
import util from '../util';
|
import util from '../util';
|
||||||
|
|
||||||
module.exports = ECDHSymmetricKey;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
|
@ -63,3 +61,5 @@ ECDHSymmetricKey.prototype.read = function (input) {
|
||||||
ECDHSymmetricKey.prototype.write = function () {
|
ECDHSymmetricKey.prototype.write = function () {
|
||||||
return util.concatUint8Array([new Uint8Array([this.data.length]), this.data]);
|
return util.concatUint8Array([new Uint8Array([this.data.length]), this.data]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export default ECDHSymmetricKey;
|
||||||
|
|
|
@ -24,8 +24,6 @@
|
||||||
|
|
||||||
import enums from '../enums.js';
|
import enums from '../enums.js';
|
||||||
|
|
||||||
module.exports = KDFParams;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
* @param {enums.hash} hash Hash algorithm
|
* @param {enums.hash} hash Hash algorithm
|
||||||
|
@ -66,3 +64,5 @@ KDFParams.prototype.write = function () {
|
||||||
KDFParams.fromClone = function (clone) {
|
KDFParams.fromClone = function (clone) {
|
||||||
return new KDFParams(clone.hash, clone.cipher);
|
return new KDFParams(clone.hash, clone.cipher);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export default KDFParams;
|
||||||
|
|
|
@ -25,8 +25,6 @@
|
||||||
|
|
||||||
import util from '../util.js';
|
import util from '../util.js';
|
||||||
|
|
||||||
module.exports = OID;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
|
@ -79,3 +77,5 @@ OID.fromClone = function (clone) {
|
||||||
const oid = new OID(clone.oid);
|
const oid = new OID(clone.oid);
|
||||||
return oid;
|
return oid;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export default OID;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user