@onekeyfe/react-native-keychain-module 1.1.19 → 1.1.20
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/KeychainModule.podspec
CHANGED
package/ios/KeychainModule.swift
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import NitroModules
|
|
2
2
|
|
|
3
3
|
class KeychainModule: HybridKeychainModuleSpec {
|
|
4
|
-
|
|
4
|
+
|
|
5
5
|
private let moduleCore = KeychainModuleCore()
|
|
6
|
-
|
|
6
|
+
|
|
7
7
|
public func setItem(params: SetItemParams) throws -> Promise<Void> {
|
|
8
|
-
let typedParams = params
|
|
9
8
|
do {
|
|
10
|
-
try moduleCore.setItem(params:
|
|
9
|
+
try moduleCore.setItem(params: params)
|
|
11
10
|
return Promise.resolved(withResult: Void())
|
|
12
11
|
} catch let error as KeychainModuleError {
|
|
13
12
|
switch error {
|
|
@@ -22,11 +21,10 @@ class KeychainModule: HybridKeychainModuleSpec {
|
|
|
22
21
|
return Promise.rejected(withError: NSError(domain: "keychain_set_error", code: -1000, userInfo: [NSLocalizedDescriptionKey: "Failed to set keychain item", NSUnderlyingErrorKey: error]))
|
|
23
22
|
}
|
|
24
23
|
}
|
|
25
|
-
|
|
24
|
+
|
|
26
25
|
public func getItem(params : GetItemParams) throws -> Promise<Variant_NullType_GetItemResult> {
|
|
27
|
-
let typedParams = params
|
|
28
26
|
do {
|
|
29
|
-
if let result = try moduleCore.getItem(params:
|
|
27
|
+
if let result = try moduleCore.getItem(params: params) {
|
|
30
28
|
return Promise.resolved(withResult: Variant_NullType_GetItemResult.second(result))
|
|
31
29
|
} else {
|
|
32
30
|
return Promise.resolved(withResult: Variant_NullType_GetItemResult.first(NullType.null))
|
|
@@ -42,11 +40,10 @@ class KeychainModule: HybridKeychainModuleSpec {
|
|
|
42
40
|
return Promise.rejected(withError: NSError(domain: "keychain_get_error", code: -1000, userInfo: [NSLocalizedDescriptionKey: "Failed to get keychain item", NSUnderlyingErrorKey: error]))
|
|
43
41
|
}
|
|
44
42
|
}
|
|
45
|
-
|
|
43
|
+
|
|
46
44
|
public func removeItem(params: RemoveItemParams) throws -> Promise<Void> {
|
|
47
|
-
let typedParams = params
|
|
48
45
|
do {
|
|
49
|
-
try moduleCore.removeItem(params:
|
|
46
|
+
try moduleCore.removeItem(params: params)
|
|
50
47
|
return Promise.resolved(withResult: Void())
|
|
51
48
|
} catch let error as KeychainModuleError {
|
|
52
49
|
switch error {
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
import Foundation
|
|
10
10
|
import Security
|
|
11
|
+
import ReactNativeNativeLogger
|
|
11
12
|
|
|
12
13
|
// MARK: - Constants
|
|
13
14
|
|
|
@@ -33,6 +34,7 @@ class KeychainModuleCore {
|
|
|
33
34
|
|
|
34
35
|
func setItem(params: SetItemParams) throws {
|
|
35
36
|
guard let valueData = params.value.data(using: .utf8) else {
|
|
37
|
+
OneKeyLog.error("Keychain", "setItem: failed to encode value")
|
|
36
38
|
throw KeychainModuleError.encodingFailed
|
|
37
39
|
}
|
|
38
40
|
|
|
@@ -64,8 +66,10 @@ class KeychainModuleCore {
|
|
|
64
66
|
let status = SecItemAdd(query as CFDictionary, nil)
|
|
65
67
|
|
|
66
68
|
guard status == errSecSuccess else {
|
|
69
|
+
OneKeyLog.error("Keychain", "setItem: failed, OSStatus: \(status)")
|
|
67
70
|
throw KeychainModuleError.operationFailed(status)
|
|
68
71
|
}
|
|
72
|
+
OneKeyLog.info("Keychain", "setItem: success")
|
|
69
73
|
}
|
|
70
74
|
|
|
71
75
|
// MARK: - Get Item
|
|
@@ -86,12 +90,15 @@ class KeychainModuleCore {
|
|
|
86
90
|
if status == errSecSuccess {
|
|
87
91
|
if let valueData = result as? Data,
|
|
88
92
|
let value = String(data: valueData, encoding: .utf8) {
|
|
93
|
+
OneKeyLog.debug("Keychain", "getItem: found")
|
|
89
94
|
return GetItemResult(key: params.key, value: value)
|
|
90
95
|
}
|
|
91
96
|
return nil
|
|
92
97
|
} else if status == errSecItemNotFound {
|
|
98
|
+
OneKeyLog.debug("Keychain", "getItem: not found")
|
|
93
99
|
return nil
|
|
94
100
|
} else {
|
|
101
|
+
OneKeyLog.error("Keychain", "getItem: failed, OSStatus: \(status)")
|
|
95
102
|
throw KeychainModuleError.operationFailed(status)
|
|
96
103
|
}
|
|
97
104
|
}
|
|
@@ -110,8 +117,10 @@ class KeychainModuleCore {
|
|
|
110
117
|
|
|
111
118
|
// Both success and item not found are acceptable for delete
|
|
112
119
|
guard status == errSecSuccess || status == errSecItemNotFound else {
|
|
120
|
+
OneKeyLog.error("Keychain", "removeItem: failed, OSStatus: \(status)")
|
|
113
121
|
throw KeychainModuleError.operationFailed(status)
|
|
114
122
|
}
|
|
123
|
+
OneKeyLog.info("Keychain", "removeItem: success")
|
|
115
124
|
}
|
|
116
125
|
|
|
117
126
|
// MARK: - Check Item Existence
|
|
@@ -126,6 +135,7 @@ class KeychainModuleCore {
|
|
|
126
135
|
]
|
|
127
136
|
|
|
128
137
|
let status = SecItemCopyMatching(query as CFDictionary, nil)
|
|
138
|
+
OneKeyLog.debug("Keychain", "hasItem: \(status == errSecSuccess)")
|
|
129
139
|
return status == errSecSuccess
|
|
130
140
|
}
|
|
131
141
|
|
|
@@ -169,6 +179,8 @@ class KeychainModuleCore {
|
|
|
169
179
|
// Common error codes:
|
|
170
180
|
// errSecMissingEntitlement (-34018): Missing iCloud Keychain entitlement
|
|
171
181
|
// errSecNotAvailable (-25291): iCloud Keychain not available/signed out
|
|
172
|
-
|
|
182
|
+
let enabled = addStatus == errSecSuccess
|
|
183
|
+
OneKeyLog.info("Keychain", "iCloud sync check result: \(enabled)")
|
|
184
|
+
return enabled
|
|
173
185
|
}
|
|
174
186
|
}
|