From b55a38c1d08c1f34df9883165c398b8aa6300b71 Mon Sep 17 00:00:00 2001 From: Michiel de Jong Date: Wed, 29 Jul 2020 14:45:56 +0200 Subject: [PATCH] Export crypto --- src/algorithms/RSASSA-PKCS1-v1_5.js | 7 +------ src/crypto.js | 3 +++ src/index.js | 2 ++ test/cryptoSpec.js | 28 ++++++++++++++++++++++++++++ 4 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 src/crypto.js create mode 100644 test/cryptoSpec.js diff --git a/src/algorithms/RSASSA-PKCS1-v1_5.js b/src/algorithms/RSASSA-PKCS1-v1_5.js index 9e2692a..72193e8 100644 --- a/src/algorithms/RSASSA-PKCS1-v1_5.js +++ b/src/algorithms/RSASSA-PKCS1-v1_5.js @@ -5,14 +5,9 @@ * @ignore */ const base64url = require('base64url') -let crypto = require('isomorphic-webcrypto') +let crypto = require('../crypto') const TextEncoder = require('../text-encoder') -// FIXME: -if (!crypto.subtle && !!crypto.default) { - crypto = crypto.default -} - /** * RSASSA-PKCS1-v1_5 */ diff --git a/src/crypto.js b/src/crypto.js new file mode 100644 index 0000000..bc7fc95 --- /dev/null +++ b/src/crypto.js @@ -0,0 +1,3 @@ +const imported = require('isomorphic-webcrypto') + +module.exports = (imported.default ? imported.default : imported) diff --git a/src/index.js b/src/index.js index 6996f2d..9370cc9 100644 --- a/src/index.js +++ b/src/index.js @@ -1,6 +1,7 @@ /** * @module JSON Object Signing and Encryption (JOSE) */ +const crypto = require('./crypto') const JWA = require('./jose/JWA') const JWK = require('./jose/JWK') const JWKSet = require('./jose/JWKSet') @@ -11,6 +12,7 @@ const JWS = require('./jose/JWS') * Export */ module.exports = { + crypto, JWA, JWK, JWKSet, diff --git a/test/cryptoSpec.js b/test/cryptoSpec.js new file mode 100644 index 0000000..a76e02e --- /dev/null +++ b/test/cryptoSpec.js @@ -0,0 +1,28 @@ +'use strict' + +/** + * Test dependencies + */ +const chai = require('chai') +const chaiAsPromised = require('chai-as-promised') + +/** + * Assertions + */ +chai.should() +chai.use(chaiAsPromised) +let expect = chai.expect + +/** + * Code under test + */ +const Index = require('../src/') + +/** + * Tests + */ +describe('Index', () => { + it('exports crypto', () => { + return Object.keys(Index.crypto).should.deep.equal(['subtle']) + }) +})