capacitor-secure-storage-plugin 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -4,33 +4,45 @@ Capacitor plugin for storing string values securly on iOS and Android.
|
|
|
4
4
|
|
|
5
5
|
## How to install
|
|
6
6
|
|
|
7
|
-
For Capacitor
|
|
7
|
+
For Capacitor v5
|
|
8
8
|
|
|
9
|
-
```
|
|
9
|
+
```bash
|
|
10
10
|
npm install capacitor-secure-storage-plugin
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
For Capacitor
|
|
13
|
+
For Capacitor v4 - install with fixed version 0.8.1
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install capacitor-secure-storage-plugin@0.8.1
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
For Capacitor v3 - install with fixed version 0.7.1
|
|
14
20
|
|
|
21
|
+
```bash
|
|
22
|
+
npm install capacitor-secure-storage-plugin@0.7.1
|
|
15
23
|
```
|
|
24
|
+
|
|
25
|
+
For Capacitor v2 - install with fixed version 0.5.1
|
|
26
|
+
|
|
27
|
+
```bash
|
|
16
28
|
npm install capacitor-secure-storage-plugin@0.5.1
|
|
17
29
|
```
|
|
18
30
|
|
|
19
31
|
## Usage
|
|
20
32
|
|
|
21
|
-
For Capacitor v3
|
|
33
|
+
### For Capacitor v3 & v4
|
|
22
34
|
|
|
23
35
|
In a component where you want to use this plugin add to or modify imports:
|
|
24
36
|
|
|
25
|
-
```
|
|
37
|
+
```jsx
|
|
26
38
|
import { SecureStoragePlugin } from 'capacitor-secure-storage-plugin';
|
|
27
39
|
```
|
|
28
40
|
|
|
29
|
-
For Capacitor v2
|
|
41
|
+
### For Capacitor v2
|
|
30
42
|
|
|
31
43
|
In a component where you want to use this plugin add to or modify imports:
|
|
32
44
|
|
|
33
|
-
```
|
|
45
|
+
```jsx
|
|
34
46
|
import 'capacitor-secure-storage-plugin';
|
|
35
47
|
import { Plugins } from '@capacitor/core';
|
|
36
48
|
|
|
@@ -39,13 +51,13 @@ const { SecureStoragePlugin } = Plugins;
|
|
|
39
51
|
|
|
40
52
|
First line is needed because of web part of the plugin (current behavior of Capacitor, this may change in future releases).
|
|
41
53
|
|
|
42
|
-
|
|
54
|
+
#### Capacitor V2 - Android
|
|
43
55
|
|
|
44
56
|
In Android with Capacitor v2 you have to register plugins manually in MainActivity class of your app.
|
|
45
57
|
|
|
46
|
-
https://capacitorjs.com/docs/v2/plugins/android#export-to-capacitor
|
|
58
|
+
[How to register plugins for Capacitor V2](https://capacitorjs.com/docs/v2/plugins/android#export-to-capacitor)
|
|
47
59
|
|
|
48
|
-
```
|
|
60
|
+
```ts
|
|
49
61
|
import com.whitestein.securestorage.SecureStoragePlugin;
|
|
50
62
|
|
|
51
63
|
...
|
|
@@ -67,31 +79,75 @@ public class MainActivity extends BridgeActivity {
|
|
|
67
79
|
|
|
68
80
|
## Methods
|
|
69
81
|
|
|
70
|
-
|
|
71
|
-
- if item with specified key does not exist, throws an Error
|
|
82
|
+
```ts
|
|
72
83
|
|
|
73
|
-
|
|
74
|
-
* **set**(options: { key: string; value: string }): Promise<{ value: boolean }>
|
|
75
|
-
- return true in case of success otherwise throws an error
|
|
76
|
-
* **remove**(options: { key: string }): Promise<{ value: boolean }>
|
|
77
|
-
- return true in case of success otherwise throws an error
|
|
78
|
-
* **clear**(): Promise<{ value: boolean }>
|
|
79
|
-
- return true in case of success otherwise throws an error
|
|
84
|
+
get(options: { key: string }): Promise<{ value: string }>
|
|
80
85
|
|
|
81
|
-
|
|
82
|
-
- returns which implementation is used - one of 'web', 'ios' or 'android'
|
|
86
|
+
```
|
|
83
87
|
|
|
84
|
-
|
|
88
|
+
> **Note**
|
|
89
|
+
> if item with specified key does not exist, throws an Error
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
|
|
95
|
+
set(options: { key: string; value: string }): Promise<{ value: boolean }>
|
|
96
|
+
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
> **Note**
|
|
100
|
+
> return true in case of success otherwise throws an error
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
|
|
106
|
+
remove(options: { key: string }): Promise<{ value: boolean }>
|
|
85
107
|
|
|
86
108
|
```
|
|
109
|
+
|
|
110
|
+
> **Note**
|
|
111
|
+
> return true in case of success otherwise throws an error
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
keys(): Promise<{ value: string[] }>
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
```ts
|
|
122
|
+
|
|
123
|
+
clear(): Promise<{ value: boolean }>
|
|
124
|
+
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
> **Note**
|
|
128
|
+
> return true in case of success otherwise throws an error
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
```ts
|
|
133
|
+
|
|
134
|
+
getPlatform(): Promise<{ value: string }>
|
|
135
|
+
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
> **Note**
|
|
139
|
+
> return returns which implementation is used - one of 'web', 'ios' or 'android'
|
|
140
|
+
|
|
141
|
+
## Example
|
|
142
|
+
|
|
143
|
+
```ts
|
|
87
144
|
const key = 'username';
|
|
88
145
|
const value = 'hellokitty2';
|
|
89
146
|
|
|
90
|
-
SecureStoragePlugin.set({ key, value })
|
|
91
|
-
.then(success => console.log(success))
|
|
147
|
+
SecureStoragePlugin.set({ key, value }).then(success => console.log(success));
|
|
92
148
|
```
|
|
93
149
|
|
|
94
|
-
```
|
|
150
|
+
```ts
|
|
95
151
|
const key = 'username';
|
|
96
152
|
SecureStoragePlugin.get({ key })
|
|
97
153
|
.then(value => {
|
|
@@ -102,7 +158,7 @@ SecureStoragePlugin.get({ key })
|
|
|
102
158
|
});
|
|
103
159
|
```
|
|
104
160
|
|
|
105
|
-
```
|
|
161
|
+
```ts
|
|
106
162
|
async getUsername(key: string) {
|
|
107
163
|
return await SecureStoragePlugin.get({ key });
|
|
108
164
|
}
|
|
@@ -114,17 +170,15 @@ async getUsername(key: string) {
|
|
|
114
170
|
|
|
115
171
|
This plugin uses SwiftKeychainWrapper under the hood for iOS.
|
|
116
172
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
Up to version v0.4.0 there was standard keychain used. Since v0.5.0 there is separate keychain wrapper, so keys() method returns only keys set in v0.5.0 or higher version.
|
|
173
|
+
> **Warning**
|
|
174
|
+
> Up to version v0.4.0 there was standard keychain used. Since v0.5.0 there is separate keychain wrapper, so keys() method returns only keys set in v0.5.0 or higher version.
|
|
120
175
|
|
|
121
176
|
### Android
|
|
122
177
|
|
|
123
178
|
On Android it is implemented by AndroidKeyStore and SharedPreferences. Source: [Apriorit](https://www.apriorit.com/dev-blog/432-using-androidkeystore)
|
|
124
179
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
For Android API < 18 values are stored as simple base64 encoded strings.
|
|
180
|
+
> **Warning**
|
|
181
|
+
> For Android API < 18 values are stored as simple base64 encoded strings.
|
|
128
182
|
|
|
129
183
|
### Web
|
|
130
184
|
|
package/android/build.gradle
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
ext {
|
|
2
2
|
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
|
|
3
|
-
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.
|
|
4
|
-
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.
|
|
5
|
-
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.
|
|
3
|
+
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.6.1'
|
|
4
|
+
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.5'
|
|
5
|
+
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.5.1'
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
buildscript {
|
|
@@ -11,17 +11,18 @@ buildscript {
|
|
|
11
11
|
mavenCentral()
|
|
12
12
|
}
|
|
13
13
|
dependencies {
|
|
14
|
-
classpath 'com.android.tools.build:gradle:
|
|
14
|
+
classpath 'com.android.tools.build:gradle:8.0.0'
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
apply plugin: 'com.android.library'
|
|
19
19
|
|
|
20
20
|
android {
|
|
21
|
-
|
|
21
|
+
namespace "com.whitestein.securestorage"
|
|
22
|
+
compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 33
|
|
22
23
|
defaultConfig {
|
|
23
24
|
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 22
|
|
24
|
-
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion :
|
|
25
|
+
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 33
|
|
25
26
|
versionCode 1
|
|
26
27
|
versionName "1.0"
|
|
27
28
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
@@ -36,8 +37,8 @@ android {
|
|
|
36
37
|
abortOnError false
|
|
37
38
|
}
|
|
38
39
|
compileOptions {
|
|
39
|
-
sourceCompatibility JavaVersion.
|
|
40
|
-
targetCompatibility JavaVersion.
|
|
40
|
+
sourceCompatibility JavaVersion.VERSION_17
|
|
41
|
+
targetCompatibility JavaVersion.VERSION_17
|
|
41
42
|
}
|
|
42
43
|
}
|
|
43
44
|
|
|
@@ -84,24 +84,32 @@ public class SecureStoragePlugin: CAPPlugin {
|
|
|
84
84
|
@objc func clear(_ call: CAPPluginCall) {
|
|
85
85
|
let keys = keychainwrapper.allKeys();
|
|
86
86
|
// cleanup standard keychain wrapper keys
|
|
87
|
-
for key in keys {
|
|
88
|
-
let hasValueStandard = KeychainWrapper.standard.hasValue(forKey: key)
|
|
89
|
-
if (hasValueStandard) {
|
|
90
|
-
let removeStandardSuccessful = KeychainWrapper.standard.removeObject(forKey: key)
|
|
91
|
-
if (!removeStandardSuccessful) {
|
|
92
|
-
call.reject("error")
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
87
|
|
|
97
|
-
|
|
98
|
-
if(clearSuccessful) {
|
|
88
|
+
if(keys.count == 0) {
|
|
99
89
|
call.resolve([
|
|
100
|
-
"value":
|
|
90
|
+
"value": true
|
|
101
91
|
])
|
|
102
92
|
}
|
|
103
|
-
else {
|
|
104
|
-
|
|
93
|
+
else {
|
|
94
|
+
for key in keys {
|
|
95
|
+
let hasValueStandard = KeychainWrapper.standard.hasValue(forKey: key)
|
|
96
|
+
if (hasValueStandard) {
|
|
97
|
+
let removeStandardSuccessful = KeychainWrapper.standard.removeObject(forKey: key)
|
|
98
|
+
if (!removeStandardSuccessful) {
|
|
99
|
+
call.reject("error")
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
let clearSuccessful: Bool = keychainwrapper.removeAllKeys()
|
|
105
|
+
if(clearSuccessful) {
|
|
106
|
+
call.resolve([
|
|
107
|
+
"value": clearSuccessful
|
|
108
|
+
])
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
call.reject("error")
|
|
112
|
+
}
|
|
105
113
|
}
|
|
106
114
|
}
|
|
107
115
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "capacitor-secure-storage-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Securely store secrets such as usernames, passwords, tokens, certificates or other sensitive information (strings) on iOS & Android",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -44,10 +44,11 @@
|
|
|
44
44
|
"prepublishOnly": "npm run build"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@capacitor/android": "^
|
|
48
|
-
"@capacitor/
|
|
47
|
+
"@capacitor/android": "^5.0.0",
|
|
48
|
+
"@capacitor/cli": "^5.0.0",
|
|
49
|
+
"@capacitor/core": "^5.0.0",
|
|
49
50
|
"@capacitor/docgen": "^0.2.0",
|
|
50
|
-
"@capacitor/ios": "^
|
|
51
|
+
"@capacitor/ios": "^5.0.0",
|
|
51
52
|
"@ionic/eslint-config": "^0.3.0",
|
|
52
53
|
"@ionic/prettier-config": "^1.0.1",
|
|
53
54
|
"@ionic/swiftlint-config": "^1.1.2",
|
|
@@ -60,7 +61,7 @@
|
|
|
60
61
|
"typescript": "~4.0.3"
|
|
61
62
|
},
|
|
62
63
|
"peerDependencies": {
|
|
63
|
-
"@capacitor/core": "^
|
|
64
|
+
"@capacitor/core": "^5.0.0"
|
|
64
65
|
},
|
|
65
66
|
"prettier": "@ionic/prettier-config",
|
|
66
67
|
"swiftlint": "@ionic/swiftlint-config",
|