@webcrypto/storage
Advanced tools
Comparing version 2.0.3 to 3.0.0
@@ -20,3 +20,4 @@ "use strict"; | ||
constructor(baseKeyOrConfig, dbName, storeName, salt, encryptIterations) { | ||
this.internalConfig = init((baseKeyOrConfig === null || baseKeyOrConfig === void 0 ? void 0 : baseKeyOrConfig.hasOwnProperty('baseKey')) ? baseKeyOrConfig | ||
this.internalConfig = init((baseKeyOrConfig === null || baseKeyOrConfig === void 0 ? void 0 : baseKeyOrConfig.hasOwnProperty('baseKey')) | ||
? baseKeyOrConfig | ||
: { | ||
@@ -40,4 +41,4 @@ baseKey: baseKeyOrConfig, | ||
this.internalConfig, | ||
tools_1.generateHash(key), | ||
tools_1.generateHash(key + '-nonce'), | ||
(0, tools_1.generateHash)(key), | ||
(0, tools_1.generateHash)(key + '-nonce'), | ||
]); | ||
@@ -48,8 +49,8 @@ const cryptoValue = yield store.get(storeName, hashKey); | ||
const [cryptoKey, nonce] = yield all([ | ||
tools_1.deriveCryptKey(baseKey, salt, encryptIterations), | ||
(0, tools_1.deriveCryptKey)(baseKey, salt, encryptIterations), | ||
store.get(storeName, hashNonce), | ||
]); | ||
try { | ||
const value = yield tools_1.decryptValue(cryptoValue, cryptoKey, nonce); | ||
return tools_1.decode(value); | ||
const value = yield (0, tools_1.decryptValue)(cryptoValue, cryptoKey, nonce); | ||
return (0, tools_1.decode)(value); | ||
} | ||
@@ -72,7 +73,7 @@ catch (error) { | ||
this.internalConfig, | ||
tools_1.generateHash(key), | ||
tools_1.generateHash(key + '-nonce'), | ||
(0, tools_1.generateHash)(key), | ||
(0, tools_1.generateHash)(key + '-nonce'), | ||
]); | ||
const cryptoKey = yield tools_1.deriveCryptKey(baseKey, salt, encryptIterations); | ||
const [cryptoValue, nonce] = yield tools_1.encryptValue(value, cryptoKey); | ||
const cryptoKey = yield (0, tools_1.deriveCryptKey)(baseKey, salt, encryptIterations); | ||
const [cryptoValue, nonce] = yield (0, tools_1.encryptValue)(value, cryptoKey); | ||
yield all([store.put(storeName, cryptoValue, hashKey), store.put(storeName, nonce, hashNonce)]); | ||
@@ -114,4 +115,4 @@ }); | ||
this.internalConfig, | ||
tools_1.generateHash(key), | ||
tools_1.generateHash(key + '-nonce'), | ||
(0, tools_1.generateHash)(key), | ||
(0, tools_1.generateHash)(key + '-nonce'), | ||
]); | ||
@@ -131,3 +132,3 @@ yield all([store.delete(storeName, hashKey), store.delete(storeName, hashNonce)]); | ||
store.close(); | ||
yield idb_1.deleteDB(store.name); | ||
yield (0, idb_1.deleteDB)(store.name); | ||
}); | ||
@@ -156,8 +157,8 @@ } | ||
const [dbHashName, storeHashName, cryptoBaseKey] = yield all([ | ||
tools_1.generateHash(dbName), | ||
tools_1.generateHash(storeName), | ||
baseKey instanceof CryptoKey ? baseKey : tools_1.generateBaseCryptoKey(baseKey), | ||
(0, tools_1.generateHash)(dbName), | ||
(0, tools_1.generateHash)(storeName), | ||
baseKey instanceof CryptoKey ? baseKey : (0, tools_1.generateBaseCryptoKey)(baseKey), | ||
]); | ||
const decodedStorageName = tools_1.decode(storeHashName); | ||
const store = idb_1.openDB(tools_1.decode(dbHashName), 1, { | ||
const decodedStorageName = (0, tools_1.decode)(storeHashName); | ||
const store = (0, idb_1.openDB)((0, tools_1.decode)(dbHashName), 1, { | ||
upgrade(db) { | ||
@@ -179,3 +180,3 @@ db.createObjectStore(decodedStorageName); | ||
const verifySalt = (storePromise, storeName, salt) => __awaiter(void 0, void 0, void 0, function* () { | ||
const [hash, store] = yield all([tools_1.generateHash('salt'), storePromise]); | ||
const [hash, store] = yield all([(0, tools_1.generateHash)('salt'), storePromise]); | ||
const existingSalt = yield store.get(storeName, hash); | ||
@@ -191,3 +192,3 @@ if (existingSalt && (!salt || existingSalt === salt)) { | ||
const persistSalt = (saltHash, store, storeName, currentSalt) => __awaiter(void 0, void 0, void 0, function* () { | ||
const salt = currentSalt !== null && currentSalt !== void 0 ? currentSalt : tools_1.generateSalt(); | ||
const salt = currentSalt !== null && currentSalt !== void 0 ? currentSalt : (0, tools_1.generateSalt)(); | ||
yield store.put(storeName, salt, saltHash); | ||
@@ -194,0 +195,0 @@ return salt; |
@@ -89,4 +89,7 @@ 'use strict'; | ||
var isJwkKey = !isTypedArray(rawKey) && typeof rawKey === 'object'; | ||
return Promise.resolve(getCryptoObject().subtle.importKey(isJwkKey ? 'jwk' : format, typeof rawKey === 'string' ? encode(rawKey) : rawKey, algorithm, false, // the original value will not be extractable | ||
keyUsages)); | ||
return Promise.resolve(isJwkKey | ||
? getCryptoObject().subtle.importKey('jwk', rawKey, algorithm, false, // the original value will not be extractable | ||
keyUsages) | ||
: getCryptoObject().subtle.importKey(format, typeof rawKey === 'string' ? encode(rawKey) : rawKey, algorithm, false, // the original value will not be extractable | ||
keyUsages)); | ||
} | ||
@@ -132,3 +135,6 @@ function deriveCryptKey(cryptoBaseKey, deriveAlgorithmOrSalt, algorithmForOrIterations, keyUsages) { | ||
if (algorithm === void 0) { algorithm = { name: 'AES-GCM', iv: generateNonce() }; } | ||
return Promise.resolve(getCryptoObject().subtle.encrypt(algorithm, cryptoKey, encode(data))).then(function (cryptoValue) { return [cryptoValue, algorithm.iv || null]; }); | ||
return Promise.resolve(getCryptoObject().subtle.encrypt(algorithm, cryptoKey, encode(data))).then(function (cryptoValue) { return [ | ||
cryptoValue, | ||
typeof algorithm === 'object' && 'iv' in algorithm ? algorithm.iv : null, | ||
]; }); | ||
} | ||
@@ -464,6 +470,11 @@ /** | ||
target = target.index(args.shift()); | ||
const returnVal = await target[targetFuncName](...args); | ||
if (isWrite) | ||
await tx.done; | ||
return returnVal; | ||
// Must reject if op rejects. | ||
// If it's a write operation, must reject if tx.done rejects. | ||
// Must reject with op rejection first. | ||
// Must resolve with op value. | ||
// Must handle both promises (no unhandled rejections) | ||
return (await Promise.all([ | ||
target[targetFuncName](...args), | ||
isWrite && tx.done, | ||
]))[0]; | ||
}; | ||
@@ -484,3 +495,4 @@ cachedMethods.set(prop, method); | ||
function CryptoStorage(baseKeyOrConfig, dbName, storeName, salt, encryptIterations) { | ||
this.internalConfig = init((baseKeyOrConfig === null || baseKeyOrConfig === void 0 ? void 0 : baseKeyOrConfig.hasOwnProperty('baseKey')) ? baseKeyOrConfig | ||
this.internalConfig = init((baseKeyOrConfig === null || baseKeyOrConfig === void 0 ? void 0 : baseKeyOrConfig.hasOwnProperty('baseKey')) | ||
? baseKeyOrConfig | ||
: { | ||
@@ -487,0 +499,0 @@ baseKey: baseKeyOrConfig, |
@@ -1,6 +0,5 @@ | ||
import { TypedArray } from '@webcrypto/tools'; | ||
/** | ||
* Default input data formats to be encrypted and stored. | ||
*/ | ||
export declare type InputData = string | TypedArray; | ||
export declare type InputData = string | BufferSource; | ||
/** | ||
@@ -25,3 +24,3 @@ * Configuration used to initialize the Crypto Storage. | ||
*/ | ||
salt?: TypedArray; | ||
salt?: BufferSource; | ||
/** | ||
@@ -60,3 +59,3 @@ * Custom iteration cycles to encrypt the stored data. | ||
*/ | ||
constructor(baseKey: InputData | CryptoKey, dbName?: string, storeName?: string, salt?: TypedArray, encryptIterations?: number); | ||
constructor(baseKey: InputData | CryptoKey, dbName?: string, storeName?: string, salt?: BufferSource, encryptIterations?: number); | ||
/** | ||
@@ -63,0 +62,0 @@ * Loads and decrypt the stored data that match the given key. |
@@ -57,4 +57,7 @@ /*! ***************************************************************************** | ||
var isJwkKey = !isTypedArray(rawKey) && typeof rawKey === 'object'; | ||
return Promise.resolve(getCryptoObject().subtle.importKey(isJwkKey ? 'jwk' : format, typeof rawKey === 'string' ? encode(rawKey) : rawKey, algorithm, false, // the original value will not be extractable | ||
keyUsages)); | ||
return Promise.resolve(isJwkKey | ||
? getCryptoObject().subtle.importKey('jwk', rawKey, algorithm, false, // the original value will not be extractable | ||
keyUsages) | ||
: getCryptoObject().subtle.importKey(format, typeof rawKey === 'string' ? encode(rawKey) : rawKey, algorithm, false, // the original value will not be extractable | ||
keyUsages)); | ||
} | ||
@@ -100,3 +103,6 @@ function deriveCryptKey(cryptoBaseKey, deriveAlgorithmOrSalt, algorithmForOrIterations, keyUsages) { | ||
if (algorithm === void 0) { algorithm = { name: 'AES-GCM', iv: generateNonce() }; } | ||
return Promise.resolve(getCryptoObject().subtle.encrypt(algorithm, cryptoKey, encode(data))).then(function (cryptoValue) { return [cryptoValue, algorithm.iv || null]; }); | ||
return Promise.resolve(getCryptoObject().subtle.encrypt(algorithm, cryptoKey, encode(data))).then(function (cryptoValue) { return [ | ||
cryptoValue, | ||
typeof algorithm === 'object' && 'iv' in algorithm ? algorithm.iv : null, | ||
]; }); | ||
} | ||
@@ -432,6 +438,11 @@ /** | ||
target = target.index(args.shift()); | ||
const returnVal = await target[targetFuncName](...args); | ||
if (isWrite) | ||
await tx.done; | ||
return returnVal; | ||
// Must reject if op rejects. | ||
// If it's a write operation, must reject if tx.done rejects. | ||
// Must reject with op rejection first. | ||
// Must resolve with op value. | ||
// Must handle both promises (no unhandled rejections) | ||
return (await Promise.all([ | ||
target[targetFuncName](...args), | ||
isWrite && tx.done, | ||
]))[0]; | ||
}; | ||
@@ -452,3 +463,4 @@ cachedMethods.set(prop, method); | ||
constructor(baseKeyOrConfig, dbName, storeName, salt, encryptIterations) { | ||
this.internalConfig = init((baseKeyOrConfig === null || baseKeyOrConfig === void 0 ? void 0 : baseKeyOrConfig.hasOwnProperty('baseKey')) ? baseKeyOrConfig | ||
this.internalConfig = init((baseKeyOrConfig === null || baseKeyOrConfig === void 0 ? void 0 : baseKeyOrConfig.hasOwnProperty('baseKey')) | ||
? baseKeyOrConfig | ||
: { | ||
@@ -455,0 +467,0 @@ baseKey: baseKeyOrConfig, |
@@ -85,4 +85,7 @@ /*! ***************************************************************************** | ||
var isJwkKey = !isTypedArray(rawKey) && typeof rawKey === 'object'; | ||
return Promise.resolve(getCryptoObject().subtle.importKey(isJwkKey ? 'jwk' : format, typeof rawKey === 'string' ? encode(rawKey) : rawKey, algorithm, false, // the original value will not be extractable | ||
keyUsages)); | ||
return Promise.resolve(isJwkKey | ||
? getCryptoObject().subtle.importKey('jwk', rawKey, algorithm, false, // the original value will not be extractable | ||
keyUsages) | ||
: getCryptoObject().subtle.importKey(format, typeof rawKey === 'string' ? encode(rawKey) : rawKey, algorithm, false, // the original value will not be extractable | ||
keyUsages)); | ||
} | ||
@@ -128,3 +131,6 @@ function deriveCryptKey(cryptoBaseKey, deriveAlgorithmOrSalt, algorithmForOrIterations, keyUsages) { | ||
if (algorithm === void 0) { algorithm = { name: 'AES-GCM', iv: generateNonce() }; } | ||
return Promise.resolve(getCryptoObject().subtle.encrypt(algorithm, cryptoKey, encode(data))).then(function (cryptoValue) { return [cryptoValue, algorithm.iv || null]; }); | ||
return Promise.resolve(getCryptoObject().subtle.encrypt(algorithm, cryptoKey, encode(data))).then(function (cryptoValue) { return [ | ||
cryptoValue, | ||
typeof algorithm === 'object' && 'iv' in algorithm ? algorithm.iv : null, | ||
]; }); | ||
} | ||
@@ -460,6 +466,11 @@ /** | ||
target = target.index(args.shift()); | ||
const returnVal = await target[targetFuncName](...args); | ||
if (isWrite) | ||
await tx.done; | ||
return returnVal; | ||
// Must reject if op rejects. | ||
// If it's a write operation, must reject if tx.done rejects. | ||
// Must reject with op rejection first. | ||
// Must resolve with op value. | ||
// Must handle both promises (no unhandled rejections) | ||
return (await Promise.all([ | ||
target[targetFuncName](...args), | ||
isWrite && tx.done, | ||
]))[0]; | ||
}; | ||
@@ -480,3 +491,4 @@ cachedMethods.set(prop, method); | ||
function CryptoStorage(baseKeyOrConfig, dbName, storeName, salt, encryptIterations) { | ||
this.internalConfig = init((baseKeyOrConfig === null || baseKeyOrConfig === void 0 ? void 0 : baseKeyOrConfig.hasOwnProperty('baseKey')) ? baseKeyOrConfig | ||
this.internalConfig = init((baseKeyOrConfig === null || baseKeyOrConfig === void 0 ? void 0 : baseKeyOrConfig.hasOwnProperty('baseKey')) | ||
? baseKeyOrConfig | ||
: { | ||
@@ -483,0 +495,0 @@ baseKey: baseKeyOrConfig, |
@@ -91,4 +91,7 @@ (function (global, factory) { | ||
var isJwkKey = !isTypedArray(rawKey) && typeof rawKey === 'object'; | ||
return Promise.resolve(getCryptoObject().subtle.importKey(isJwkKey ? 'jwk' : format, typeof rawKey === 'string' ? encode(rawKey) : rawKey, algorithm, false, // the original value will not be extractable | ||
keyUsages)); | ||
return Promise.resolve(isJwkKey | ||
? getCryptoObject().subtle.importKey('jwk', rawKey, algorithm, false, // the original value will not be extractable | ||
keyUsages) | ||
: getCryptoObject().subtle.importKey(format, typeof rawKey === 'string' ? encode(rawKey) : rawKey, algorithm, false, // the original value will not be extractable | ||
keyUsages)); | ||
} | ||
@@ -134,3 +137,6 @@ function deriveCryptKey(cryptoBaseKey, deriveAlgorithmOrSalt, algorithmForOrIterations, keyUsages) { | ||
if (algorithm === void 0) { algorithm = { name: 'AES-GCM', iv: generateNonce() }; } | ||
return Promise.resolve(getCryptoObject().subtle.encrypt(algorithm, cryptoKey, encode(data))).then(function (cryptoValue) { return [cryptoValue, algorithm.iv || null]; }); | ||
return Promise.resolve(getCryptoObject().subtle.encrypt(algorithm, cryptoKey, encode(data))).then(function (cryptoValue) { return [ | ||
cryptoValue, | ||
typeof algorithm === 'object' && 'iv' in algorithm ? algorithm.iv : null, | ||
]; }); | ||
} | ||
@@ -466,6 +472,11 @@ /** | ||
target = target.index(args.shift()); | ||
const returnVal = await target[targetFuncName](...args); | ||
if (isWrite) | ||
await tx.done; | ||
return returnVal; | ||
// Must reject if op rejects. | ||
// If it's a write operation, must reject if tx.done rejects. | ||
// Must reject with op rejection first. | ||
// Must resolve with op value. | ||
// Must handle both promises (no unhandled rejections) | ||
return (await Promise.all([ | ||
target[targetFuncName](...args), | ||
isWrite && tx.done, | ||
]))[0]; | ||
}; | ||
@@ -486,3 +497,4 @@ cachedMethods.set(prop, method); | ||
function CryptoStorage(baseKeyOrConfig, dbName, storeName, salt, encryptIterations) { | ||
this.internalConfig = init((baseKeyOrConfig === null || baseKeyOrConfig === void 0 ? void 0 : baseKeyOrConfig.hasOwnProperty('baseKey')) ? baseKeyOrConfig | ||
this.internalConfig = init((baseKeyOrConfig === null || baseKeyOrConfig === void 0 ? void 0 : baseKeyOrConfig.hasOwnProperty('baseKey')) | ||
? baseKeyOrConfig | ||
: { | ||
@@ -489,0 +501,0 @@ baseKey: baseKeyOrConfig, |
{ | ||
"name": "@webcrypto/storage", | ||
"version": "2.0.3", | ||
"version": "3.0.0", | ||
"private": false, | ||
@@ -115,4 +115,4 @@ "description": "A set of tools to facilitate and give good defaults for use of the native Web Crypto API.", | ||
"dependencies": { | ||
"@webcrypto/tools": "^1.2.1", | ||
"idb": "^5.0.8" | ||
"@webcrypto/tools": "^2.0.0", | ||
"idb": "^6.1.5" | ||
}, | ||
@@ -126,3 +126,3 @@ "devDependencies": { | ||
"@types/lodash.camelcase": "^4.3.6", | ||
"@types/node": "^12.20.46", | ||
"@types/node": "^17.0.18", | ||
"@types/rollup-plugin-json": "^3.0.3", | ||
@@ -137,10 +137,10 @@ "browserify": "^16.5.2", | ||
"husky": "^4.3.8", | ||
"jasmine-core": "^3.99.0", | ||
"karma": "^5.2.3", | ||
"jasmine-core": "^4.0.0", | ||
"karma": "^6.3.16", | ||
"karma-chrome-launcher": "^3.1.0", | ||
"karma-cli": "^2.0.0", | ||
"karma-jasmine": "^3.3.1", | ||
"karma-jasmine": "^4.0.1", | ||
"karma-mocha-reporter": "^2.2.5", | ||
"karma-typescript": "^5.5.3", | ||
"lint-staged": "^10.5.4", | ||
"lint-staged": "^12.3.4", | ||
"lodash.camelcase": "^4.3.0", | ||
@@ -155,3 +155,3 @@ "npm-run-all": "^4.1.5", | ||
"rollup-plugin-sourcemaps": "^0.6.3", | ||
"rollup-plugin-typescript2": "^0.27.3", | ||
"rollup-plugin-typescript2": "^0.31.2", | ||
"semantic-release": "^17.4.7", | ||
@@ -166,4 +166,4 @@ "shelljs": "^0.8.5", | ||
"typedoc": "^0.22.11", | ||
"typescript": "^4.0.8" | ||
"typescript": "^4.5.5" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
335171
3147
+ Added@webcrypto/tools@2.0.0(transitive)
+ Addedidb@6.1.5(transitive)
- Removed@webcrypto/tools@1.2.1(transitive)
- Removedidb@5.0.8(transitive)
Updated@webcrypto/tools@^2.0.0
Updatedidb@^6.1.5