capacitor-secure-storage-plugin 0.7.1 → 0.8.1

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.
@@ -11,7 +11,7 @@ Pod::Spec.new do |s|
11
11
  s.author = package['author']
12
12
  s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
13
13
  s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
14
- s.ios.deployment_target = '12.0'
14
+ s.ios.deployment_target = '13.0'
15
15
  s.dependency 'Capacitor'
16
16
  s.dependency 'SwiftKeychainWrapper'
17
17
  s.swift_version = '5.1'
package/README.md CHANGED
@@ -4,33 +4,39 @@ Capacitor plugin for storing string values securly on iOS and Android.
4
4
 
5
5
  ## How to install
6
6
 
7
- For Capacitor v3
7
+ For Capacitor v4
8
8
 
9
- ```
9
+ ```bash
10
10
  npm install capacitor-secure-storage-plugin
11
11
  ```
12
12
 
13
- For Capacitor v2 - install with fixed version 0.5.1
13
+ For Capacitor v3 - install with fixed version 0.7.1
14
14
 
15
+ ```bash
16
+ npm install capacitor-secure-storage-plugin@0.7.1
15
17
  ```
18
+
19
+ For Capacitor v2 - install with fixed version 0.5.1
20
+
21
+ ```bash
16
22
  npm install capacitor-secure-storage-plugin@0.5.1
17
23
  ```
18
24
 
19
25
  ## Usage
20
26
 
21
- For Capacitor v3
27
+ ### For Capacitor v3 & v4
22
28
 
23
29
  In a component where you want to use this plugin add to or modify imports:
24
30
 
25
- ```
31
+ ```jsx
26
32
  import { SecureStoragePlugin } from 'capacitor-secure-storage-plugin';
27
33
  ```
28
34
 
29
- For Capacitor v2
35
+ ### For Capacitor v2
30
36
 
31
37
  In a component where you want to use this plugin add to or modify imports:
32
38
 
33
- ```
39
+ ```jsx
34
40
  import 'capacitor-secure-storage-plugin';
35
41
  import { Plugins } from '@capacitor/core';
36
42
 
@@ -39,13 +45,13 @@ const { SecureStoragePlugin } = Plugins;
39
45
 
40
46
  First line is needed because of web part of the plugin (current behavior of Capacitor, this may change in future releases).
41
47
 
42
- ### Android
48
+ #### Capacitor V2 - Android
43
49
 
44
50
  In Android with Capacitor v2 you have to register plugins manually in MainActivity class of your app.
45
51
 
46
- https://capacitorjs.com/docs/v2/plugins/android#export-to-capacitor
52
+ [How to register plugins for Capacitor V2](https://capacitorjs.com/docs/v2/plugins/android#export-to-capacitor)
47
53
 
48
- ```
54
+ ```ts
49
55
  import com.whitestein.securestorage.SecureStoragePlugin;
50
56
 
51
57
  ...
@@ -67,23 +73,68 @@ public class MainActivity extends BridgeActivity {
67
73
 
68
74
  ## Methods
69
75
 
70
- - **get**(options: { key: string }): Promise<{ value: string }>
71
- - if item with specified key does not exist, throws an Error
76
+ ```ts
72
77
 
73
- * **keys**(): Promise<{ value: string[] }>
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
78
+ get(options: { key: string }): Promise<{ value: string }>
80
79
 
81
- - **getPlatform**(): Promise<{ value: string }>
82
- - returns which implementation is used - one of 'web', 'ios' or 'android'
80
+ ```
83
81
 
84
- ## Example
82
+ > **Note**
83
+ > if item with specified key does not exist, throws an Error
84
+
85
+ ---
86
+
87
+ ```ts
88
+
89
+ set(options: { key: string; value: string }): Promise<{ value: boolean }>
90
+
91
+ ```
92
+
93
+ > **Note**
94
+ > return true in case of success otherwise throws an error
95
+
96
+ ---
97
+
98
+ ```ts
99
+
100
+ remove(options: { key: string }): Promise<{ value: boolean }>
101
+
102
+ ```
85
103
 
104
+ > **Note**
105
+ > return true in case of success otherwise throws an error
106
+
107
+ ---
108
+
109
+ ```ts
110
+ keys(): Promise<{ value: string[] }>
86
111
  ```
112
+
113
+ ---
114
+
115
+ ```ts
116
+
117
+ clear(): Promise<{ value: boolean }>
118
+
119
+ ```
120
+
121
+ > **Note**
122
+ > return true in case of success otherwise throws an error
123
+
124
+ ---
125
+
126
+ ```ts
127
+
128
+ getPlatform(): Promise<{ value: string }>
129
+
130
+ ```
131
+
132
+ > **Note**
133
+ > return returns which implementation is used - one of 'web', 'ios' or 'android'
134
+
135
+ ## Example
136
+
137
+ ```ts
87
138
  const key = 'username';
88
139
  const value = 'hellokitty2';
89
140
 
@@ -91,7 +142,7 @@ SecureStoragePlugin.set({ key, value })
91
142
  .then(success => console.log(success))
92
143
  ```
93
144
 
94
- ```
145
+ ```ts
95
146
  const key = 'username';
96
147
  SecureStoragePlugin.get({ key })
97
148
  .then(value => {
@@ -102,7 +153,7 @@ SecureStoragePlugin.get({ key })
102
153
  });
103
154
  ```
104
155
 
105
- ```
156
+ ```ts
106
157
  async getUsername(key: string) {
107
158
  return await SecureStoragePlugin.get({ key });
108
159
  }
@@ -114,17 +165,15 @@ async getUsername(key: string) {
114
165
 
115
166
  This plugin uses SwiftKeychainWrapper under the hood for iOS.
116
167
 
117
- ##### Warning
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.
168
+ > **Warning**
169
+ > 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
170
 
121
171
  ### Android
122
172
 
123
173
  On Android it is implemented by AndroidKeyStore and SharedPreferences. Source: [Apriorit](https://www.apriorit.com/dev-blog/432-using-androidkeystore)
124
174
 
125
- ##### Warning
126
-
127
- For Android API < 18 values are stored as simple base64 encoded strings.
175
+ > **Warning**
176
+ > For Android API < 18 values are stored as simple base64 encoded strings.
128
177
 
129
178
  ### Web
130
179
 
@@ -1,27 +1,27 @@
1
1
  ext {
2
- junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.1'
3
- androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.2.0'
4
- androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.2'
5
- androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.3.0'
2
+ junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
3
+ androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.4.2'
4
+ androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.3'
5
+ androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.4.0'
6
6
  }
7
7
 
8
8
  buildscript {
9
9
  repositories {
10
10
  google()
11
- jcenter()
11
+ mavenCentral()
12
12
  }
13
13
  dependencies {
14
- classpath 'com.android.tools.build:gradle:4.2.1'
14
+ classpath 'com.android.tools.build:gradle:7.2.1'
15
15
  }
16
16
  }
17
17
 
18
18
  apply plugin: 'com.android.library'
19
19
 
20
20
  android {
21
- compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 30
21
+ compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 32
22
22
  defaultConfig {
23
- minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 21
24
- targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 30
23
+ minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 22
24
+ targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 32
25
25
  versionCode 1
26
26
  versionName "1.0"
27
27
  testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -36,22 +36,21 @@ android {
36
36
  abortOnError false
37
37
  }
38
38
  compileOptions {
39
- sourceCompatibility JavaVersion.VERSION_1_8
40
- targetCompatibility JavaVersion.VERSION_1_8
39
+ sourceCompatibility JavaVersion.VERSION_11
40
+ targetCompatibility JavaVersion.VERSION_11
41
41
  }
42
42
  }
43
43
 
44
44
  repositories {
45
45
  google()
46
46
  mavenCentral()
47
- jcenter()
48
47
  }
49
48
 
50
49
 
51
50
  dependencies {
52
- implementation fileTree(dir: 'libs', include: ['*.jar'])
53
- implementation project(':capacitor-android')
51
+ implementation fileTree(include: ['*.jar'], dir: 'libs')
54
52
  implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
53
+ implementation project(':capacitor-android')
55
54
  testImplementation "junit:junit:$junitVersion"
56
55
  androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
57
56
  androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
@@ -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
- let clearSuccessful: Bool = keychainwrapper.removeAllKeys()
98
- if(clearSuccessful) {
88
+ if(keys.count == 0) {
99
89
  call.resolve([
100
- "value": clearSuccessful
90
+ "value": true
101
91
  ])
102
92
  }
103
- else {
104
- call.reject("error")
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.7.1",
3
+ "version": "0.8.1",
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,10 @@
44
44
  "prepublishOnly": "npm run build"
45
45
  },
46
46
  "devDependencies": {
47
- "@capacitor/android": "^3.0.0",
48
- "@capacitor/core": "^3.0.0",
49
- "@capacitor/docgen": "^0.0.18",
50
- "@capacitor/ios": "^3.0.0",
47
+ "@capacitor/android": "^4.4.0",
48
+ "@capacitor/core": "^4.4.0",
49
+ "@capacitor/docgen": "^0.2.0",
50
+ "@capacitor/ios": "^4.4.0",
51
51
  "@ionic/eslint-config": "^0.3.0",
52
52
  "@ionic/prettier-config": "^1.0.1",
53
53
  "@ionic/swiftlint-config": "^1.1.2",
@@ -60,7 +60,7 @@
60
60
  "typescript": "~4.0.3"
61
61
  },
62
62
  "peerDependencies": {
63
- "@capacitor/core": "^3.0.0"
63
+ "@capacitor/core": "^4.4.0"
64
64
  },
65
65
  "prettier": "@ionic/prettier-config",
66
66
  "swiftlint": "@ionic/swiftlint-config",