This repository was archived by the owner on Jul 17, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSecureStorageProxy.js
More file actions
66 lines (56 loc) · 1.54 KB
/
Copy pathSecureStorageProxy.js
File metadata and controls
66 lines (56 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
cordova.define("airgap-secure-storage.SecureStorageProxy", function(require, exports, module) {
/**
* Warn users about unsecure implementation of browser platform
* @param {*} handler
*/
const warn = function (handler) {
console.warn('Browser storage is not securely implemented in airgap-secure-storage. Only use for testing / debugging!')
return handler
}
/**
* Gets a specific key from localStorage
* @param {*} key
*/
const getItem = function (args) {
const alias = args[0]
const isParanoia = args[1]
const key = args[2]
try {
return Promise.resolve(JSON.parse(localStorage.getValue(alias + '_' + key)))
} catch (error) {
return Promise.reject(error)
}
}
/**
* Sets a specific value for a given key in localStorage
* @param {*} key
* @param {*} value
*/
const setItem = function (args) {
const alias = args[0]
const key = args[2]
const value = args[3]
try {
localStorage.setItem(alias + '_' + key, value)
return Promise.resolve()
} catch (error) {
return Promise.reject(error)
}
}
const initialize = function () {
console.log('initialize is done!')
return Promise.resolve()
}
const removeAll = function () {
localStorage.clear()
return Promise.resolve()
}
module.exports = {
initialize: warn(initialize),
getItem: warn(getItem),
setItem: warn(setItem),
removeAll: warn(removeAll),
destroy: warn(removeAll)
};
require('cordova/exec/proxy').add('SecureStorage', module.exports)
});