@neoskop/ethereal-secrets-client
Advanced tools
Comparing version 1.4.0 to 1.4.1
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.EtherealSecretsClient = void 0; | ||
var sjcl_1 = require("sjcl"); | ||
@@ -16,4 +17,4 @@ var request = require("superagent"); | ||
} | ||
else if (this._agent === null) { | ||
this._agent = superagent_1.agent(); | ||
else { | ||
this._agent = (0, superagent_1.agent)(); | ||
} | ||
@@ -51,3 +52,3 @@ } | ||
try { | ||
var clearText = sjcl_1.decrypt(keys_1.localKey, res.body.data); | ||
var clearText = (0, sjcl_1.decrypt)(keys_1.localKey, res.body.data); | ||
var result = { | ||
@@ -86,3 +87,3 @@ clearText: clearText, | ||
var secret = this.generateLocalSecret(); | ||
var cipherText = sjcl_1.encrypt(secret, clearText); | ||
var cipherText = (0, sjcl_1.encrypt)(secret, clearText); | ||
return this._agent | ||
@@ -120,6 +121,6 @@ .post(this._endpoint) | ||
var randomValues = new Uint8Array(32); | ||
if (window === null || window === void 0 ? void 0 : window.crypto) { | ||
window.crypto.getRandomValues(randomValues); | ||
if (typeof crypto !== 'undefined') { | ||
crypto.getRandomValues(randomValues); | ||
} | ||
else if (window && window['msCrypto']) { | ||
else if (typeof window !== 'undefined' && window['msCrypto']) { | ||
window['msCrypto'].getRandomValues(randomValues); | ||
@@ -130,5 +131,3 @@ } | ||
} | ||
// Workaround, since Buffer is no global JS element | ||
return randomValues.reduce(function (prev, i) { return prev + ((i < 16 ? '0' : '') + i.toString(16)); }, ''); | ||
// return Buffer.from(randomValues.buffer).toString('hex'); | ||
}; | ||
@@ -138,3 +137,3 @@ EtherealSecretsClient.prototype.decryptCipherText = function (cipherText) { | ||
try { | ||
var clearText = sjcl_1.decrypt(secret, cipherText); | ||
var clearText = (0, sjcl_1.decrypt)(secret, cipherText); | ||
return Promise.resolve(clearText); | ||
@@ -149,3 +148,3 @@ } | ||
return this.retrieveRemoteSecret().then(function (secret) { | ||
var cipherText = sjcl_1.encrypt(secret, value); | ||
var cipherText = (0, sjcl_1.encrypt)(secret, value); | ||
return Promise.resolve(cipherText.toString()); | ||
@@ -152,0 +151,0 @@ }); |
@@ -6,9 +6,11 @@ "use strict"; | ||
var chaiAsPromised = require("chai-as-promised"); | ||
var webcrypto_1 = require("@peculiar/webcrypto"); | ||
before(function (done) { | ||
chai.should(); | ||
chai.use(chaiAsPromised); | ||
var nodeLocalStorage = require('node-localstorage'); | ||
var LocalStorage = nodeLocalStorage.LocalStorage; | ||
global['localStorage'] = new LocalStorage('./tmp/localstorage'); | ||
global['sessionStorage'] = new LocalStorage('./tmp/sessionstorage'); | ||
// let nodeLocalStorage = require('node-localstorage'); | ||
// let LocalStorage = nodeLocalStorage.LocalStorage; | ||
// global['localStorage'] = new LocalStorage('./tmp/localstorage'); | ||
// global['sessionStorage'] = new LocalStorage('./tmp/sessionstorage'); | ||
global.crypto = new webcrypto_1.Crypto(); | ||
done(); | ||
@@ -18,4 +20,6 @@ }); | ||
if (config === void 0) { config = {}; } | ||
var defaultConfig = { endpoint: 'http://server:8080' }; | ||
Object.getOwnPropertyNames(config).map(function (key) { | ||
var defaultConfig = { | ||
endpoint: 'http://server:8080', | ||
}; | ||
Object.getOwnPropertyNames(config).forEach(function (key) { | ||
if (config.hasOwnProperty(key)) { | ||
@@ -30,7 +34,10 @@ defaultConfig[key] = config[key]; | ||
var sut = createClient({ storage: localStorage }); | ||
return sut.getLocal('foo' + Math.random().toString(36).substring(7)).should.eventually.be.fulfilled.and.to.be.null; | ||
return sut.getLocal('foo' + Math.random().toString(36).substring(7)).should | ||
.eventually.be.fulfilled.and.to.be.null; | ||
}); | ||
it('should save to local storage if requested', function () { | ||
var sut = createClient({ storage: localStorage }); | ||
return sut.saveLocal('foo', 'bar').should.eventually.be.fulfilled.and.then(function () { | ||
return sut | ||
.saveLocal('foo', 'bar') | ||
.should.eventually.be.fulfilled.and.then(function () { | ||
return chai.expect(localStorage.getItem('foo')).to.not.be.null; | ||
@@ -41,3 +48,5 @@ }); | ||
var sut = createClient(); | ||
return sut.saveLocal('foo', 'bar').should.eventually.be.fulfilled.and.then(function () { | ||
return sut | ||
.saveLocal('foo', 'bar') | ||
.should.eventually.be.fulfilled.and.then(function () { | ||
return chai.expect(sessionStorage.getItem('foo')).to.not.be.null; | ||
@@ -48,3 +57,5 @@ }); | ||
var sut = createClient(); | ||
return sut.saveLocal('foo', 'bar').should.eventually.be.fulfilled.and.then(function () { | ||
return sut | ||
.saveLocal('foo', 'bar') | ||
.should.eventually.be.fulfilled.and.then(function () { | ||
return chai.expect(sessionStorage.getItem('foo')).to.not.contain('bar'); | ||
@@ -55,4 +66,10 @@ }); | ||
var sut = createClient(); | ||
return sut.saveLocal('foo', 'bar').should.eventually.be.fulfilled.and.then(function () { | ||
return sut.getLocal('foo').should.eventually.be.fulfilled.and.then(function (value) { return value.should.equal('bar'); }); | ||
return sut | ||
.saveLocal('foo', 'bar') | ||
.should.eventually.be.fulfilled.and.then(function () { | ||
return sut | ||
.getLocal('foo') | ||
.should.eventually.be.fulfilled.and.then(function (value) { | ||
return value.should.equal('bar'); | ||
}); | ||
}); | ||
@@ -62,6 +79,12 @@ }); | ||
var sut = createClient({ | ||
cacheKey: true | ||
cacheKey: true, | ||
}); | ||
return sut.saveLocal('foo', 'bar').should.eventually.be.fulfilled.and.then(function () { | ||
return sut.getLocal('foo').should.eventually.be.fulfilled.and.then(function (value) { return value.should.equal('bar'); }); | ||
return sut | ||
.saveLocal('foo', 'bar') | ||
.should.eventually.be.fulfilled.and.then(function () { | ||
return sut | ||
.getLocal('foo') | ||
.should.eventually.be.fulfilled.and.then(function (value) { | ||
return value.should.equal('bar'); | ||
}); | ||
}); | ||
@@ -71,6 +94,10 @@ }); | ||
var sut = createClient(); | ||
return sut.saveRemote('foo').should.eventually.be.fulfilled.and.then(function (result) { | ||
return sut | ||
.saveRemote('foo') | ||
.should.eventually.be.fulfilled.and.then(function (result) { | ||
return Promise.all([ | ||
chai.expect(result.fragmentIdentifier).should.not.be.empty, | ||
chai.expect(result.fragmentIdentifier).to.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12};[0-9a-f]{64}$/) | ||
chai | ||
.expect(result.fragmentIdentifier) | ||
.to.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12};[0-9a-f]{64}$/), | ||
]); | ||
@@ -81,4 +108,8 @@ }); | ||
var sut = createClient(); | ||
return sut.saveRemote('foo').should.eventually.be.fulfilled.and.then(function (result) { | ||
return sut.getRemote(result.fragmentIdentifier).should.eventually.be.fulfilled.and.then(function (result) { | ||
return sut | ||
.saveRemote('foo') | ||
.should.eventually.be.fulfilled.and.then(function (result) { | ||
return sut | ||
.getRemote(result.fragmentIdentifier) | ||
.should.eventually.be.fulfilled.and.then(function (result) { | ||
return result.clearText.should.equal('foo'); | ||
@@ -90,13 +121,20 @@ }); | ||
var sut = createClient(); | ||
return sut.getRemote('invalididentifier').should.eventually.be.rejectedWith('invalid'); | ||
return sut | ||
.getRemote('invalididentifier') | ||
.should.eventually.be.rejectedWith('invalid'); | ||
}); | ||
it('should reject unknown fragment identifier', function () { | ||
var sut = createClient(); | ||
return sut.getRemote('decafbad-dead-dead-dead-decafbadadad;decafbaddecafbaddecafbaddecafbaddecafbaddecafbaddecafbaddecafbad').should.eventually.be.rejectedWith('Not Found'); | ||
return sut | ||
.getRemote('decafbad-dead-dead-dead-decafbadadad;decafbaddecafbaddecafbaddecafbaddecafbaddecafbaddecafbaddecafbad') | ||
.should.eventually.be.rejectedWith('Not Found'); | ||
}); | ||
it('should not return data when the data was deleted beforehand', function () { | ||
var sut = createClient(); | ||
return sut.saveRemote('foo').should.eventually.be.fulfilled.and.then(function (result) { | ||
return sut | ||
.saveRemote('foo') | ||
.should.eventually.be.fulfilled.and.then(function (result) { | ||
return sut.removeRemote(result.fragmentIdentifier).then(function () { | ||
return sut.getRemote(result.fragmentIdentifier).should.eventually.be.rejected; | ||
return sut.getRemote(result.fragmentIdentifier).should.eventually.be | ||
.rejected; | ||
}); | ||
@@ -103,0 +141,0 @@ }); |
{ | ||
"name": "@neoskop/ethereal-secrets-client", | ||
"version": "1.4.0", | ||
"version": "1.4.1", | ||
"main": "dist/index.js", | ||
@@ -15,22 +15,26 @@ "typings": "dist/index.d.ts", | ||
"build": "npm run clean; npm run tsc", | ||
"start": "mocha -w --inspect=0.0.0.0:9229 --require ts-node/register src/test/*.ts", | ||
"test": "nyc --reporter=text mocha --require ts-node/register src/test/*.ts" | ||
"start": "mocha -w --inspect=0.0.0.0:9229 -r ts-node/register -r jsdom-global -r mock-local-storage src/test/*.ts", | ||
"test": "nyc --reporter=text mocha -r ts-node/register -r jsdom-global -r mock-local-storage src/test/*.ts" | ||
}, | ||
"devDependencies": { | ||
"@types/bluebird": "3.5.30", | ||
"@types/chai": "4.2.11", | ||
"@types/chai-as-promised": "7.1.2", | ||
"@types/mocha": "7.0.2", | ||
"@peculiar/webcrypto": "1.4.0", | ||
"@types/bluebird": "3.5.36", | ||
"@types/chai": "4.3.1", | ||
"@types/chai-as-promised": "7.1.5", | ||
"@types/mocha": "9.1.1", | ||
"@types/sjcl": "1.0.30", | ||
"@types/superagent": "4.1.7", | ||
"chai": "4.2.0", | ||
"@types/superagent": "4.1.15", | ||
"chai": "4.3.6", | ||
"chai-as-promised": "7.1.1", | ||
"concurrently": "5.1.0", | ||
"mocha": "7.1.1", | ||
"node-localstorage": "2.1.6", | ||
"nyc": "15.0.1", | ||
"prettier": "2.4.1", | ||
"concurrently": "7.2.0", | ||
"jsdom": "19.0.0", | ||
"jsdom-global": "3.0.2", | ||
"mocha": "10.0.0", | ||
"mock-local-storage": "1.1.22", | ||
"node-localstorage": "2.2.1", | ||
"nyc": "15.1.0", | ||
"prettier": "2.6.2", | ||
"rimraf": "3.0.2", | ||
"ts-node": "8.8.2", | ||
"typescript": "3.8.3" | ||
"ts-node": "10.7.0", | ||
"typescript": "4.6.4" | ||
}, | ||
@@ -40,3 +44,3 @@ "dependencies": { | ||
"sjcl": "1.0.8", | ||
"superagent": "5.2.2" | ||
"superagent": "7.1.3" | ||
}, | ||
@@ -43,0 +47,0 @@ "nyc": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
25464
336
20
+ Addedasap@2.0.6(transitive)
+ Addeddezalgo@1.0.4(transitive)
+ Addedform-data@4.0.1(transitive)
+ Addedformidable@2.1.2(transitive)
+ Addedhexoid@1.0.0(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedsemver@7.6.3(transitive)
+ Addedsuperagent@7.1.3(transitive)
+ Addedwrappy@1.0.2(transitive)
- Removedform-data@3.0.2(transitive)
- Removedformidable@1.2.6(transitive)
- Removedsemver@6.3.1(transitive)
- Removedsuperagent@5.2.2(transitive)
Updatedsuperagent@7.1.3